diff options
-rw-r--r-- | ChangeLog | 19 | ||||
-rw-r--r-- | gtk/gtkaccellabel.c | 8 | ||||
-rw-r--r-- | gtk/gtklabel.c | 77 | ||||
-rw-r--r-- | gtk/gtkmenushell.c | 10 | ||||
-rw-r--r-- | gtk/gtksettings.c | 38 | ||||
-rw-r--r-- | gtk/gtkwindow.c | 24 |
6 files changed, 166 insertions, 10 deletions
@@ -1,5 +1,24 @@ 2007-02-05 Michael Natterer <mitch@imendio.com> + * gtk/gtksettings.c: add new boolean settings gtk-enable-accels + and gtk-enable-mnemonics which enable/disable accelerators and + mnemonics (bug #72375, based on a patch from Tommi Komulainen). + + * gtk/gtkwindow.c (gtk_window_activate_key) + * gtk/gtkmenushell.c (gtk_menu_shell_key_press): don't invoke them + if the resp. setting is FALSE. + + * gtk/gtkaccellabel.c (gtk_accel_label_refetch) + * gtk/gtklabel.c (gtk_label_set_pattern_internal): don't display + them if the setting is FALSE. + + * gtk/gtklabel.c: added signal connection to the screen's settings + object and traverse all widgets on the screen when the setting + changes. It's slightly ugly to also update GtkAccelLabels here, + but less ugly than connecting and traversing all widgets twice. + +2007-02-05 Michael Natterer <mitch@imendio.com> + * gtk/gtktextbuffer.h (enum GtkTextBufferTargetInfo): changed values from G_MAXUINT-0, -1, -2 to -1, -2, -3 so we stay within ansi C enum value limits. Fixes bug #46757. diff --git a/gtk/gtkaccellabel.c b/gtk/gtkaccellabel.c index 5ea999499a..6a7bf1eda5 100644 --- a/gtk/gtkaccellabel.c +++ b/gtk/gtkaccellabel.c @@ -664,6 +664,8 @@ _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass, gboolean gtk_accel_label_refetch (GtkAccelLabel *accel_label) { + gboolean enable_accels; + g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), FALSE); if (accel_label->accel_string) @@ -672,7 +674,11 @@ gtk_accel_label_refetch (GtkAccelLabel *accel_label) accel_label->accel_string = NULL; } - if (accel_label->accel_closure) + g_object_get (gtk_widget_get_settings (GTK_WIDGET (accel_label)), + "gtk-enable-accels", &enable_accels, + NULL); + + if (enable_accels && accel_label->accel_closure) { GtkAccelKey *key = gtk_accel_group_find (accel_label->accel_group, find_accel, accel_label->accel_closure); diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index 9cee21d10a..aa2ef089bf 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -27,6 +27,7 @@ #include <math.h> #include <string.h> #include "gtklabel.h" +#include "gtkaccellabel.h" #include "gtkdnd.h" #include "gtkmain.h" #include "gtkmarshalers.h" @@ -969,12 +970,76 @@ gtk_label_hierarchy_changed (GtkWidget *widget, } static void +label_shortcut_setting_apply (GtkLabel *label) +{ + gtk_label_recalculate (label); + if (GTK_IS_ACCEL_LABEL (label)) + gtk_accel_label_refetch (GTK_ACCEL_LABEL (label)); +} + +static void +label_shortcut_setting_traverse_container (GtkWidget *widget, + gpointer data) +{ + if (GTK_IS_LABEL (widget)) + label_shortcut_setting_apply (GTK_LABEL (widget)); + else if (GTK_IS_CONTAINER (widget)) + gtk_container_forall (GTK_CONTAINER (widget), + label_shortcut_setting_traverse_container, data); +} + +static void +label_shortcut_setting_changed (GtkSettings *settings) +{ + GList *list, *l; + + list = gtk_window_list_toplevels (); + + for (l = list; l ; l = l->next) + { + GtkWidget *widget = l->data; + + if (gtk_widget_get_settings (widget) == settings) + gtk_container_forall (GTK_CONTAINER (widget), + label_shortcut_setting_traverse_container, NULL); + } + + g_list_free (list); +} + +static void gtk_label_screen_changed (GtkWidget *widget, GdkScreen *old_screen) { - gtk_label_clear_layout (GTK_LABEL (widget)); + GtkSettings *settings; + gboolean shortcuts_connected; + + if (!gtk_widget_has_screen (widget)) + return; + + settings = gtk_widget_get_settings (widget); + + shortcuts_connected = + GPOINTER_TO_INT (g_object_get_data (G_OBJECT (settings), + "gtk-label-shortcuts-connected")); + + if (! shortcuts_connected) + { + g_signal_connect (settings, "notify::gtk-enable-mnemonics", + G_CALLBACK (label_shortcut_setting_changed), + NULL); + g_signal_connect (settings, "notify::gtk-enable-accels", + G_CALLBACK (label_shortcut_setting_changed), + NULL); + + g_object_set_data (G_OBJECT (settings), "gtk-label-shortcuts-connected", + GINT_TO_POINTER (TRUE)); + } + + label_shortcut_setting_apply (GTK_LABEL (widget)); } + static void label_mnemonic_widget_weak_notify (gpointer data, GObject *where_the_object_was) @@ -1461,9 +1526,15 @@ gtk_label_set_pattern_internal (GtkLabel *label, const gchar *pattern) { PangoAttrList *attrs; + gboolean enable_mnemonics; + g_return_if_fail (GTK_IS_LABEL (label)); - - if (pattern) + + g_object_get (gtk_widget_get_settings (GTK_WIDGET (label)), + "gtk-enable-mnemonics", &enable_mnemonics, + NULL); + + if (enable_mnemonics && pattern) attrs = gtk_label_pattern_to_attrs (label, pattern); else attrs = NULL; diff --git a/gtk/gtkmenushell.c b/gtk/gtkmenushell.c index 153620af39..5e7862018c 100644 --- a/gtk/gtkmenushell.c +++ b/gtk/gtkmenushell.c @@ -685,6 +685,7 @@ gtk_menu_shell_key_press (GtkWidget *widget, GdkEventKey *event) { GtkMenuShell *menu_shell; + gboolean enable_mnemonics; g_return_val_if_fail (GTK_IS_MENU_SHELL (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); @@ -697,7 +698,14 @@ gtk_menu_shell_key_press (GtkWidget *widget, if (gtk_bindings_activate_event (GTK_OBJECT (widget), event)) return TRUE; - return gtk_menu_shell_activate_mnemonic (menu_shell, event); + g_object_get (gtk_widget_get_settings (widget), + "gtk-enable-mnemonics", &enable_mnemonics, + NULL); + + if (enable_mnemonics) + return gtk_menu_shell_activate_mnemonic (menu_shell, event); + + return FALSE; } static gint diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c index 191b98827f..fb7858fbe5 100644 --- a/gtk/gtksettings.c +++ b/gtk/gtksettings.c @@ -100,7 +100,9 @@ enum { PROP_COLOR_HASH, PROP_FILE_CHOOSER_BACKEND, PROP_PRINT_BACKENDS, - PROP_PRINT_PREVIEW_COMMAND + PROP_PRINT_PREVIEW_COMMAND, + PROP_ENABLE_MNEMONICS, + PROP_ENABLE_ACCELS }; @@ -676,6 +678,40 @@ gtk_settings_class_init (GtkSettingsClass *class) GTK_PARAM_READWRITE), NULL); g_assert (result == PROP_PRINT_PREVIEW_COMMAND); + + /** + * GtkSettings:gtk-enable-mnemonics: + * + * Whether labels and menu items should have visible mnemonics which + * can be activated. + * + * Since: 2.12 + */ + result = settings_install_property_parser (class, + g_param_spec_boolean ("gtk-enable-mnemonics", + P_("Enable Mnemonics"), + P_("Whether labels should have mnemonics"), + TRUE, + GTK_PARAM_READWRITE), + NULL); + g_assert (result == PROP_ENABLE_MNEMONICS); + + /** + * GtkSettings:gtk-enable-accels: + * + * Whether menu items should have visible accelerators which can be + * activated. + * + * Since: 2.12 + */ + result = settings_install_property_parser (class, + g_param_spec_boolean ("gtk-enable-accels", + P_("Enable Accelerators"), + P_("Whether menu items should have accelerators"), + TRUE, + GTK_PARAM_READWRITE), + NULL); + g_assert (result == PROP_ENABLE_ACCELS); } static void diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index f72bd21be4..3766f38e18 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -7698,13 +7698,29 @@ gtk_window_activate_key (GtkWindow *window, if (found_entry) { + gboolean enable_mnemonics; + gboolean enable_accels; + + g_object_get (gtk_widget_get_settings (GTK_WIDGET (window)), + "gtk-enable-mnemonics", &enable_mnemonics, + "gtk-enable-accels", &enable_accels, + NULL); + if (found_entry->is_mnemonic) - return gtk_window_mnemonic_activate (window, found_entry->keyval, found_entry->modifiers); + { + if (enable_mnemonics) + return gtk_window_mnemonic_activate (window, found_entry->keyval, + found_entry->modifiers); + } else - return gtk_accel_groups_activate (G_OBJECT (window), found_entry->keyval, found_entry->modifiers); + { + if (enable_accels) + return gtk_accel_groups_activate (G_OBJECT (window), found_entry->keyval, + found_entry->modifiers); + } } - else - return FALSE; + + return FALSE; } static void |