#ifndef __GTKUTILS_H #define __GTKUTILS_H /*------------------------------------------------------------------------- * Copyright (c) 1999-2003 Kenneth W. Sodemann (stufflehead@bigfoot.com) *------------------------------------------------------------------------- * gtkutils * * Synopsis: * Some of these utility functions are copied from the code * created by Glade. This code is being placed here so that * I can create UI using Glade, but then split the code out * (something Glade does not currently fully support). * * Other functions and structures are used for passing data * around within a set of widgets. * * $Id: gtkutils.h,v 1.28 2003/12/26 23:20:42 stuffle Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to * Free Software Foundation, Inc. * 59 Temple Place, Suite 330 * Boston, MA 02111-1307 USA * *------------------------------------------------------------------------- */ #include /* * Common dialog spacings as suggested in the HIG. */ #define STD_DLG_BORDER 18 #define STD_BOX_SPACING 6 #define MAIN_VBOX_SPACING 12 #define DTL_BOX_SPACING 6 /*------------------------------------------------------------------------- * There is certain data that we will need to store with each high * level widget (a dialog box for example). These definitions * provide keys for this data. These keys should be used with the * g_object_[gs]et_data functions. * * o TOP_DOG : The "main widget" in a widget set (dialog, * windows, etc) * o MY_PARENT : My "parent", however it is defined by the * application. Sets up a parent/child relationship * between top level widgets. * o MY_DB_CONN : My database connection (for db related apps) * o MY_GCONF_CLIENT : My GConfClient * o TOOLTIPS : The tooltips * *------------------------------------------------------------------------- */ #define TOP_DOG "myself" #define MY_PARENT "my_parent" #define MY_DB_CONN "my_db_conn" #define MY_GCONF_CLIENT "my_gconf_client" #define TOOLTIPS "tooltips" /*------------------------------------------------------------------------- * A note about the dirty lists * * In gtk 1.2, there was no really good way that I knew of to determine * if the contents of an object had been modified. Thus, I added the * dirty_list idea. * * The dirty_list is a list of objects that have a "dirty" flag that * can be set, cleared, and checked. * * With gtk 2.0, the GtkTextBuffer has its own modified flag. However, * the other objects still appear to not have any reasonable way of * determining if they are modified. In a nutshell, here is how PRepS * determines if there is data that needs to be saved: * * 1.) When data entry dialogs are created, any non GtkTextView objects * that we need to check are attached to set_dirty() and added to * the dlg's dirty list. * 2.) For GtkTextView objects, the assocaited buffer is set to * not modified when the buffer is initialized (set to initial * value). * 3.) Each data entry dlg has a function that can be called to determine * if it is dirty. I till check its dirty list plus check any * GtkTextBuffer's that it needs to. * 4.) "List" dialogs (attrib list, project list, etc) will iterate * over their children, calling the function defined in #3 to * determine if any of their child are dirty. * 5.) The main window checks it's children (new pr's and pr update * windows), plus calls the functions defied in #4. *------------------------------------------------------------------------- */ /*------------------------------------------------------------------------- * Function: set_dirty * * Synopsis: * Set the dirty flag for this object. This function most likely * should be connected to whatever signal determines that this object * is now dirty. * * This function does NOT do any before/after comparisons to ensure * that the data actually IS dirty. * * Inputs: * object : the object to set dirty * user_data : unused (here for Gtk compat) * * Outputs: * None. * * Return Value: * None. * *------------------------------------------------------------------------- */ void set_dirty (GObject *object, gpointer user_data); /*------------------------------------------------------------------------- * Function: set_clean * * Synopsis: * Clear the dirty flag for this object. * * Inputs: * object : the object to set clean * user_data : unused (here for Gtk compat) * * Outputs: * None. * * Return Value: * None. * *------------------------------------------------------------------------- */ void set_clean (GObject *object, gpointer user_data); /*------------------------------------------------------------------------- * Function: set_all_clean * * Synopsis: * Clear the dirty flag for all objects in the parent's list of * objects being tracked for clean/dirty status. * * Inputs: * parent : the main object, parent to all the objects to set clean * * Outputs: * None. * * Return Value: * None. * *------------------------------------------------------------------------- */ void set_all_clean (GObject *parent); /*------------------------------------------------------------------------- * Function: add_object_to_dirty_list * * Synopsis: * Some top level objects contain a list of child objects that should * be checked to see if they are dirty. This function adds children * to the list. * * Inputs: * parent : the top level object * object : the object to add * * Outputs: * None. * * Return Value: * None. * *------------------------------------------------------------------------- */ void add_object_to_dirty_list (GObject *parent, GObject *object); /*------------------------------------------------------------------------- * Function: destroy_dirty_list * * Synopsis: * destroy the list of child objects whose dirty status is being * tracked * * Inputs: * parent : the owner of the list * * Outputs: * None. * * Return Value: * None. * *------------------------------------------------------------------------- */ void destroy_dirty_list (GObject *parent); /*------------------------------------------------------------------------- * Function: object_is_dirty * * Synopsis: * Determine if the dirty flag has been set for the object * * Inputs: * object : the object to check * * Outputs: * None. * * Return Value: * TRUE : the object is dirty * FALSE : the object is clean * *------------------------------------------------------------------------- */ gboolean object_is_dirty (GObject *object); /*------------------------------------------------------------------------- * Function: objects_children_are_dirty * * Synopsis: * Called for a parent object. Checks all of the children in the * list of children being tracked, and returns TRUE if it finds * at least one that is dirty. * * Inputs: * parent : the owner of the list * * Outputs: * None. * * Return Value: * TRUE : at least one child is dirty * FALSE : none of the children are dirty * *------------------------------------------------------------------------- */ gboolean objects_children_are_dirty (GObject *parent); /*------------------------------------------------------------------------- * Function: child_dead * * Synopsis: * In the child, link this handler to the "destroy" signal. This * will remove the child from the specified list (saved as object * data in the parent). * * Then, when the parent is destroyed, it can kill all remaining * children by going through the current list. Be sure to block * this handler first, or we could run into problems. * * In order to use this function, the following MUST be true. * o The child must save its parent as object data using * MY_PARENT (defined above) as the key. * o In the parent, the list the child is stored in must be * object data accessed by the list name. * * Inputs: * child_widget : the child widget * list_name : the name of the list (key of object data for list * in the parent widget) * * Outputs: * None. * * Return Value: * None. * *------------------------------------------------------------------------- */ void child_dead (GObject *child_widget, gchar *list_name); /*------------------------------------------------------------------------- * Function: gtkutils_cleanup * * Synopsis: * This module keeps some data hanging around. Clean it up. * Calling funtions from this module after this function has * been called will result in undefined behavior. *------------------------------------------------------------------------- */ void gtkutils_cleanup (void); /* * Starting from here on down, this code is taken almost directly * from the code that Glade produces. */ #define GLADE_HOOKUP_OBJECT(component,widget,name) \ g_object_set_data_full (G_OBJECT (component), name, \ gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref) #define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \ g_object_set_data (G_OBJECT (component), name, widget) /*------------------------------------------------------------------------- * Function: lookup_widget * * Synopsis: * This function returns a widget in a component created by Glade. * Call it with the toplevel widget in the component (i.e. a * window/dialog), or alternatively any widget in the component, * and the name of the widget you want returned. * * Inputs: * widget : pointer to the parent widget * widget_name : the name of the child widget to find * * Outputs: * None. * * Return Value: * A pointer to the widget if found, NULL otherwise. * *------------------------------------------------------------------------- */ GtkWidget *lookup_widget (const GtkWidget *widget, const gchar *widget_name); /*------------------------------------------------------------------------- * Function: lookup_widget * * Synopsis: * Create an image widget from a file * * Inputs: * widget : pointer to the parent widget * filename : the name of the pixmap file * * Outputs: * None. * * Return Value: * A pointer to the widget if found, NULL otherwise. * *------------------------------------------------------------------------- */ GtkWidget *create_pixmap (GtkWidget *widget, const gchar *filename); /*------------------------------------------------------------------------- * Function: add_pixmap_directory * * Synopsis: * Use this function to set the directory containing installed * pixmaps. * * Inputs: * directory : dir to add (as a string). * * Outputs: * None. * * Return Value: * None. * *------------------------------------------------------------------------- */ void add_pixmap_directory (const gchar *directory); #endif