diff options
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/e-dialog-utils.c | 169 | ||||
-rw-r--r-- | e-util/e-dialog-utils.h | 9 | ||||
-rw-r--r-- | e-util/e-dialog-widgets.c | 476 | ||||
-rw-r--r-- | e-util/e-dialog-widgets.h | 25 |
4 files changed, 1 insertions, 678 deletions
diff --git a/e-util/e-dialog-utils.c b/e-util/e-dialog-utils.c index d02a42572b..14f12e2f4c 100644 --- a/e-util/e-dialog-utils.c +++ b/e-util/e-dialog-utils.c @@ -71,178 +71,11 @@ e_notice (gpointer parent, GtkMessageType type, const gchar *format, ...) g_free (str); if (parent) - e_dialog_set_transient_for (GTK_WINDOW (dialog), parent); + gtk_window_set_transient_for (GTK_WINDOW (dialog), parent); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } -/** - * e_notice_with_xid: - * @parent: the dialog's parent window, or %NULL - * @type: the type of dialog (%GTK_MESSAGE_INFO, %GTK_MESSAGE_WARNING, - * or %GTK_MESSAGE_ERROR) - * @format: printf-style format string, followed by arguments - * - * Like e_notice(), but takes a GdkNativeWindow for the parent - * window argument. - **/ -void -e_notice_with_xid (GdkNativeWindow parent, GtkMessageType type, const gchar *format, ...) -{ - GtkWidget *dialog; - va_list args; - gchar *str; - - va_start (args, format); - str = g_strdup_vprintf (format, args); - dialog = gtk_message_dialog_new (NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - type, - GTK_BUTTONS_OK, - "%s", - str); - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - va_end (args); - g_free (str); - - if (parent) - e_dialog_set_transient_for_xid (GTK_WINDOW (dialog), parent); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); -} - - -#ifdef GDK_WINDOWING_X11 -/* Tests whether or not an X Window is being managed by the - * window manager. - */ -static gboolean -window_is_wm_toplevel (Display *display, Window window) -{ - static Atom WM_STATE = None; - unsigned long nitems, after; - guchar *data = NULL; - Atom type = None; - gint format; - - if (!WM_STATE) - WM_STATE = XInternAtom (display, "WM_STATE", False); - - if (XGetWindowProperty (display, window, WM_STATE, 0, 0, False, - AnyPropertyType, &type, &format, - &nitems, &after, &data) == Success) { - if (data) - XFree((gchar *)data); - if (type) - return TRUE; - } - return FALSE; -} - -#endif - -/** - * e_dialog_set_transient_for: - * @dialog: a dialog window - * @parent_widget: the parent for @dialog - * - * This sets the parent for @dialog to be @parent_widget. Unlike - * gtk_window_set_transient_for (), this doesn't need @parent_widget to - * be the actual toplevel, and also works if @parent_widget is - * embedded as a Bonobo control by an out-of-process container. - * @parent_widget must already be realized before calling this - * function, but @dialog does not need to be. - **/ -void -e_dialog_set_transient_for (GtkWindow *dialog, - GtkWidget *parent_widget) -{ - GtkWidget *toplevel; -#ifdef GDK_WINDOWING_X11 - Window parent, root_ret, *children; - guint numchildren; - Display *display; - Status status; -#endif - g_return_if_fail (GTK_IS_WINDOW (dialog)); - g_return_if_fail (GTK_IS_WIDGET (parent_widget)); - - toplevel = gtk_widget_get_toplevel (parent_widget); - if (toplevel == NULL) - return; - - if (!GTK_IS_PLUG (toplevel)) { - gtk_window_set_transient_for (GTK_WINDOW (dialog), - GTK_WINDOW (toplevel)); - return; - } -#ifdef GDK_WINDOWING_X11 - /* Find the top-level windowmanager-managed X Window */ - display = GDK_WINDOW_XDISPLAY (gtk_widget_get_window (parent_widget)); - parent = GDK_WINDOW_XID (gtk_widget_get_window (parent_widget)); - - while (parent && !window_is_wm_toplevel (display, parent)) { - status = XQueryTree (display, parent, &root_ret, - &parent, &children, &numchildren); - if (status != 0) - XFree (children); - } - - e_dialog_set_transient_for_xid (dialog, parent); -#endif -#ifdef GDK_WINDOWING_WIN32 - g_warning ("Not implemented on Win32: e_dialog_set_transient_for () for plug windows"); -#endif -} - -static void -dialog_realized (GtkWindow *dialog, gpointer xid) -{ - e_dialog_set_transient_for_xid (dialog, (GdkNativeWindow)GPOINTER_TO_INT(xid)); -} - -/** - * e_dialog_set_transient_for_xid: - * @dialog: a dialog window - * @xid: the X Window parent - * - * Like e_dialog_set_transient_for (), but use an XID to specify the - * parent window. - **/ -void -e_dialog_set_transient_for_xid (GtkWindow *dialog, - GdkNativeWindow xid) -{ -#ifdef GDK_MULTIHEAD_SAFE - GdkDisplay *display; -#endif - GdkWindow *parent; - - g_return_if_fail (GTK_IS_WINDOW (dialog)); - - if (!GTK_WIDGET_REALIZED (dialog)) { - g_signal_connect (dialog, "realize", - G_CALLBACK (dialog_realized), - GINT_TO_POINTER(xid)); - return; - } - -#ifdef GDK_MULTIHEAD_SAFE - display = gdk_drawable_get_display (GDK_DRAWABLE (gtk_widget_get_window (GTK_WIDGET (dialog)))); - parent = gdk_window_lookup_for_display (display, xid); - if (!parent) - parent = gdk_window_foreign_new_for_display (display, xid); -#else - parent = gdk_window_lookup (xid); - if (!parent) - parent = gdk_window_foreign_new (xid); -#endif - g_return_if_fail (parent != NULL); - - gdk_window_set_transient_for (gtk_widget_get_window (GTK_WIDGET (dialog)), parent); -} - - static void save_ok (GtkWidget *widget, gpointer data) { diff --git a/e-util/e-dialog-utils.h b/e-util/e-dialog-utils.h index 98d85e151d..ba0683bbe9 100644 --- a/e-util/e-dialog-utils.h +++ b/e-util/e-dialog-utils.h @@ -29,15 +29,6 @@ void e_notice (gpointer parent, GtkMessageType type, const gchar *format, ...); -void e_notice_with_xid (GdkNativeWindow parent, - GtkMessageType type, - const gchar *format, - ...); - -void e_dialog_set_transient_for (GtkWindow *dialog, - GtkWidget *parent_widget); -void e_dialog_set_transient_for_xid (GtkWindow *dialog, - GdkNativeWindow xid); gchar *e_file_dialog_save (const gchar *title, const gchar *fname); diff --git a/e-util/e-dialog-widgets.c b/e-util/e-dialog-widgets.c index cdcd52dd26..a847960eb2 100644 --- a/e-util/e-dialog-widgets.c +++ b/e-util/e-dialog-widgets.c @@ -31,51 +31,6 @@ #include "e-dialog-widgets.h" - - -/* A widget, a pointer to the variable it will modify, and extra information */ -typedef struct { - GtkWidget *widget; - gpointer value_var; - gpointer info; -} WidgetHook; - -/* Hook information for a complete dialog */ -typedef struct { - GSList *whooks; -} DialogHooks; - - - -/* Destroy handler for the dialog; frees the dialog hooks */ -static void -dialog_destroy_cb (DialogHooks *hooks, GObject *dialog) -{ - g_slist_free (hooks->whooks); - hooks->whooks = NULL; - - g_free (hooks); - g_object_set_data (dialog, "dialog-hooks", NULL); -} - -/* Ensures that the dialog has the necessary attached data to store the widget - * hook information. - */ -static DialogHooks * -get_dialog_hooks (GtkWidget *dialog) -{ - DialogHooks *hooks; - - hooks = g_object_get_data ((GObject *) dialog, "dialog-hooks"); - if (!hooks) { - hooks = g_new0 (DialogHooks, 1); - g_object_set_data ((GObject *) dialog, "dialog-hooks", hooks); - g_object_weak_ref ((GObject *) dialog, (GWeakNotify) dialog_destroy_cb, hooks); - } - - return hooks; -} - /* Converts an mapped value to the appropriate index in an item group. The * values for the items are provided as a -1-terminated array. */ @@ -110,109 +65,6 @@ index_to_value (const gint *value_map, gint index) return -1; } -/* Hooks a radio button group */ -static void -hook_radio (GtkWidget *dialog, GtkRadioButton *radio, gpointer value_var, gpointer info) -{ - const gint *value_map; - gint *value; - - /* Set the value */ - - value = (gint *) value_var; - value_map = (const gint *) info; - - e_dialog_radio_set (GTK_WIDGET (radio), *value, value_map); -} - -/* Gets the value of a radio button group */ -static void -get_radio_value (GtkRadioButton *radio, gpointer value_var, gpointer info) -{ - gint *value; - const gint *value_map; - - value = (gint *) value_var; - value_map = (const gint *) info; - - *value = e_dialog_radio_get (GTK_WIDGET (radio), value_map); -} - -/* Hooks a toggle button */ -static void -hook_toggle (GtkWidget *dialog, GtkToggleButton *toggle, gpointer value_var, gpointer info) -{ - gboolean *value; - - /* Set the value */ - - value = (gboolean *) value_var; - e_dialog_toggle_set (GTK_WIDGET (toggle), *value); -} - -/* Gets the value of a toggle button */ -static void -get_toggle_value (GtkToggleButton *toggle, gpointer value_var, gpointer info) -{ - gboolean *value; - - value = (gboolean *) value_var; - *value = e_dialog_toggle_get (GTK_WIDGET (toggle)); -} - -/* Hooks a spin button */ -static void -hook_spin_button (GtkWidget *dialog, GtkSpinButton *spin, gpointer value_var, gpointer info) -{ - double *value; - GtkAdjustment *adj; - - /* Set the value */ - - value = (double *) value_var; - e_dialog_spin_set (GTK_WIDGET (spin), *value); - - /* Hook to changed */ - - adj = gtk_spin_button_get_adjustment (spin); -} - -/* Gets the value of a spin button */ -static void -get_spin_button_value (GtkSpinButton *spin, gpointer value_var, gpointer info) -{ - double *value; - - value = (double *) value_var; - *value = e_dialog_spin_get_double (GTK_WIDGET (spin)); -} - -/* Hooks a GtkEditable widget */ -static void -hook_editable (GtkWidget *dialog, GtkEditable *editable, gpointer value_var, gpointer info) -{ - gchar **value; - - /* Set the value */ - - value = (gchar **) value_var; - - e_dialog_editable_set (GTK_WIDGET (editable), *value); -} - -/* Gets the value of a GtkEditable widget */ -static void -get_editable_value (GtkEditable *editable, gpointer value_var, gpointer data) -{ - gchar **value; - - value = (gchar **) value_var; - if (*value) - g_free (*value); - - *value = e_dialog_editable_get (GTK_WIDGET (editable)); -} - /** * e_dialog_editable_set: * @widget: A #GtkEditable widget. @@ -254,195 +106,6 @@ e_dialog_editable_get (GtkWidget *widget) } /** - * e_dialog_radio_set: - * @widget: A #GtkRadioButton in a radio button group. - * @value: Enumerated value. - * @value_map: Map from enumeration values to array indices. - * - * Sets the selected item in a radio group. The specified @widget can be any of - * the #GtkRadioButtons in the group. Each radio button should correspond to an - * enumeration value; the specified @value will be mapped to an integer from - * zero to the number of items in the group minus 1 by using a mapping table - * specified in @value_map. The last element in this table should be -1. Thus - * a table to map three possible interpolation values to integers could be - * specified as { NEAREST_NEIGHBOR, BILINEAR, HYPERBOLIC, -1 }. - **/ -void -e_dialog_radio_set (GtkWidget *widget, gint value, const gint *value_map) -{ - GSList *group, *l; - gint i; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_RADIO_BUTTON (widget)); - g_return_if_fail (value_map != NULL); - - group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget)); - - i = value_to_index (value_map, value); - if (i != -1) { - /* Groups are built by prepending items, so the list ends up in reverse - * order; we need to flip the index around. - */ - i = g_slist_length (group) - i - 1; - - l = g_slist_nth (group, i); - if (!l) - g_message ("e_dialog_radio_set(): could not find index %d in radio group!", i); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (l->data), TRUE); - } else - g_message ("e_dialog_radio_set(): could not find value %d in value map!", value); -} - -/** - * e_dialog_radio_get: - * @widget: A #GtkRadioButton in a radio button group. - * @value_map: Map from enumeration values to array indices. - * - * Queries the selected item in a #GtkRadioButton group. Please read the - * description of e_dialog_radio_set() to see how @value_map maps enumeration - * values to button indices. - * - * Return value: Enumeration value which corresponds to the selected item in the - * radio group. - **/ -gint -e_dialog_radio_get (GtkWidget *widget, const gint *value_map) -{ - GSList *group, *l; - gint i, v; - - g_return_val_if_fail (widget != NULL, -1); - g_return_val_if_fail (GTK_IS_RADIO_BUTTON (widget), -1); - g_return_val_if_fail (value_map != NULL, -1); - - group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget)); - - for (i = 0, l = group; l; l = l->next, i++) { - GtkToggleButton *toggle_button; - - toggle_button = GTK_TOGGLE_BUTTON (l->data); - - if (gtk_toggle_button_get_active (toggle_button)) - break; - } - - g_return_val_if_fail (l != NULL, -1); - - /* Groups are built by prepending items, so the list ends up in reverse - * order; we need to flip the index around. - */ - i = g_slist_length (group) - i - 1; - - v = index_to_value (value_map, i); - if (v == -1) { - g_message ("e_dialog_radio_get(): could not find index %d in value map!", i); - return -1; - } - - return v; -} - -/** - * e_dialog_toggle_set: - * @widget: A #GtkToggleButton. - * @value: Toggle value. - * - * Sets the value of a #GtkToggleButton-derived widget. This should not be used - * for radio buttons; it is more convenient to use use e_dialog_radio_set() - * instead. - **/ -void -e_dialog_toggle_set (GtkWidget *widget, gboolean value) -{ - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_TOGGLE_BUTTON (widget)); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value); -} - -/** - * e_dialog_toggle_get: - * @widget: A #GtkToggleButton. - * - * Queries the value of a #GtkToggleButton-derived widget. This should not be - * used for radio buttons; it is more convenient to use e_dialog_radio_get() - * instead. - * - * Return value: Toggle value. - **/ -gboolean -e_dialog_toggle_get (GtkWidget *widget) -{ - g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (widget), FALSE); - - return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)); -} - -/** - * e_dialog_spin_set: - * @widget: A #GtkSpinButton. - * @value: Numeric value. - * - * Sets the value of a #GtkSpinButton widget. - **/ -void -e_dialog_spin_set (GtkWidget *widget, double value) -{ - GtkAdjustment *adj; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_SPIN_BUTTON (widget)); - - adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget)); - - gtk_adjustment_set_value (adj, value); - g_signal_emit_by_name (adj, "value_changed", 0); -} - -/** - * e_dialog_spin_get_double: - * @widget: A #GtkSpinButton. - * - * Queries the floating-point value of a #GtkSpinButton widget. - * - * Return value: Numeric value. - **/ -gdouble -e_dialog_spin_get_double (GtkWidget *widget) -{ - GtkAdjustment *adj; - - g_return_val_if_fail (widget != NULL, 0.0); - g_return_val_if_fail (GTK_IS_SPIN_BUTTON (widget), 0.0); - - adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget)); - - return gtk_adjustment_get_value (adj); -} - -/** - * e_dialog_spin_get_int: - * @widget: A #GtkSpinButton. - * - * Queries the integer value of a #GtkSpinButton widget. - * - * Return value: Numeric value. - **/ -gint -e_dialog_spin_get_int (GtkWidget *widget) -{ - double value; - - g_return_val_if_fail (widget != NULL, -1); - g_return_val_if_fail (GTK_IS_SPIN_BUTTON (widget), -1); - - value = e_dialog_spin_get_double (widget); - return (gint) floor (value); -} - -/** * e_dialog_combo_box_set: * @widget: A #GtkComboBox. * @value: Enumerated value. @@ -498,142 +161,3 @@ e_dialog_combo_box_get (GtkWidget *widget, const gint *value_map) } return i; } - -/** - * e_dialog_widget_hook_value: - * @dialog: Dialog box in which the @widget lives in. - * @widget: A widget that will control a variable. - * @value_var: Pointer to the variable that the @widget will control. - * @info: NULL for most widgets, or an integer value map array (see - * e_dialog_radio_set() for details). - * - * Hooks a widget from a dialog box to the variable it will modify. Supported - * widgets are: #GtkEditable (gchar *), #GtkRadioButton (int/value_map pair; see - * e_dialog_radio_set() for more information), #GtkTogglebutton (gboolean), - * #GtkSpinButton (double), #GtkOptionMenu (int/value_map pair), and - * #GnomeDateEdit (time_t). - * - * A pointer to the appropriate variable to modify should be passed in @value_var. - * For values that take a value_map array as well, it should be passed in @info. - * - * The widgets within a dialog that are hooked with this function will set their - * respective variables only when e_dialog_get_values() is called. The typical - * use is to call that function in the handler for the "OK" button of a dialog - * box. - * - * Return value: TRUE if the type of the specified @widget is supported, FALSE - * otherwise. - **/ -gboolean -e_dialog_widget_hook_value (GtkWidget *dialog, GtkWidget *widget, - gpointer value_var, gpointer info) -{ - DialogHooks *hooks; - WidgetHook *wh; - - g_return_val_if_fail (dialog != NULL, FALSE); - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); - g_return_val_if_fail (value_var != NULL, FALSE); - - hooks = get_dialog_hooks (dialog); - - /* First check if it is a "group" widget, like a radio button or an - * option menu. Then we check for normal ungrouped widgets. - */ - - if (GTK_IS_RADIO_BUTTON (widget)) - hook_radio (dialog, GTK_RADIO_BUTTON (widget), value_var, info); - else if (GTK_IS_TOGGLE_BUTTON (widget)) - hook_toggle (dialog, GTK_TOGGLE_BUTTON (widget), value_var, info); - else if (GTK_IS_SPIN_BUTTON (widget)) - hook_spin_button (dialog, GTK_SPIN_BUTTON (widget), value_var, info); - else if (GTK_IS_EDITABLE (widget)) - hook_editable (dialog, GTK_EDITABLE (widget), value_var, info); - else - return FALSE; - - wh = g_new (WidgetHook, 1); - wh->widget = widget; - wh->value_var = value_var; - wh->info = info; - - hooks->whooks = g_slist_prepend (hooks->whooks, wh); - - return TRUE; -} - -/** - * e_dialog_get_values: - * @dialog: A dialog box whose widgets have been hooked to the appropriate - * variables with e_dialog_widget_hook_value(). - * - * Makes every widget in a @dialog that was hooked with - * e_dialog_widget_hook_value() apply its value to its corresponding variable. - * The typical usage is to call this function in the handler for the "OK" button - * of a dialog box. - **/ -void -e_dialog_get_values (GtkWidget *dialog) -{ - DialogHooks *hooks; - GSList *l; - - g_return_if_fail (dialog != NULL); - - hooks = get_dialog_hooks (dialog); - - for (l = hooks->whooks; l; l = l->next) { - WidgetHook *wh; - - wh = l->data; - - if (GTK_IS_RADIO_BUTTON (wh->widget)) - get_radio_value (GTK_RADIO_BUTTON (wh->widget), wh->value_var, wh->info); - else if (GTK_IS_TOGGLE_BUTTON (wh->widget)) - get_toggle_value (GTK_TOGGLE_BUTTON (wh->widget), wh->value_var, wh->info); - else if (GTK_IS_SPIN_BUTTON (wh->widget)) - get_spin_button_value (GTK_SPIN_BUTTON (wh->widget), wh->value_var, wh->info); - else if (GTK_IS_EDITABLE (wh->widget)) - get_editable_value (GTK_EDITABLE (wh->widget), wh->value_var, wh->info); - else - g_return_if_reached (); - } -} - -/** - * e_dialog_xml_widget_hook_value: - * @xml: Glade XML description of a dialog box. - * @dialog: Dialog box in which the widget lives in. - * @widget_name: Name of the widget in the Glade XML data. - * @value_var: Pointer to the variable that the widget will control. - * @info: NULL for most widgets, or an integer value map array (see - * e_dialog_radio_set() for details). - * - * Similar to e_dialog_widget_hook_value(), but uses the widget from a #GladeXML - * data structure. - * - * Return value: TRUE if the type of the specified widget is supported, FALSE - * otherwise. - **/ -gboolean -e_dialog_xml_widget_hook_value (GladeXML *xml, GtkWidget *dialog, const gchar *widget_name, - gpointer value_var, gpointer info) -{ - GtkWidget *widget; - - g_return_val_if_fail (xml != NULL, FALSE); - g_return_val_if_fail (GLADE_IS_XML (xml), FALSE); - g_return_val_if_fail (dialog != NULL, FALSE); - g_return_val_if_fail (widget_name != NULL, FALSE); - g_return_val_if_fail (value_var != NULL, FALSE); - - widget = glade_xml_get_widget (xml, widget_name); - if (!widget) { - g_message ("e_dialog_xml_widget_hook_value(): could not find widget `%s' in " - "Glade data!", widget_name); - return FALSE; - } - - return e_dialog_widget_hook_value (dialog, widget, value_var, info); -} diff --git a/e-util/e-dialog-widgets.h b/e-util/e-dialog-widgets.h index ff4a9e0d0d..6e9f798db7 100644 --- a/e-util/e-dialog-widgets.h +++ b/e-util/e-dialog-widgets.h @@ -25,35 +25,10 @@ #ifndef E_DIALOG_WIDGETS_H #define E_DIALOG_WIDGETS_H -#include <time.h> -#include <glade/glade.h> - - - void e_dialog_editable_set (GtkWidget *widget, const gchar *value); gchar *e_dialog_editable_get (GtkWidget *widget); -void e_dialog_radio_set (GtkWidget *widget, gint value, const gint *value_map); -gint e_dialog_radio_get (GtkWidget *widget, const gint *value_map); - -void e_dialog_toggle_set (GtkWidget *widget, gboolean value); -gboolean e_dialog_toggle_get (GtkWidget *widget); - -void e_dialog_spin_set (GtkWidget *widget, double value); -gdouble e_dialog_spin_get_double (GtkWidget *widget); -gint e_dialog_spin_get_int (GtkWidget *widget); - void e_dialog_combo_box_set (GtkWidget *widget, gint value, const gint *value_map); gint e_dialog_combo_box_get (GtkWidget *widget, const gint *value_map); -gboolean e_dialog_widget_hook_value (GtkWidget *dialog, GtkWidget *widget, - gpointer value_var, gpointer info); - -void e_dialog_get_values (GtkWidget *dialog); - -gboolean e_dialog_xml_widget_hook_value (GladeXML *xml, GtkWidget *dialog, const gchar *widget_name, - gpointer value_var, gpointer info); - - - #endif |