diff options
author | Matthias Clasen <mclasen@redhat.com> | 2013-08-18 10:45:24 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2013-08-18 13:46:48 -0400 |
commit | 624ec0fb7d5329261dd0c4a991c7889a70c61535 (patch) | |
tree | 4d4e31aaf825e5c9965c5f92b3c9a3b8327ba2c0 | |
parent | 8d7bab7d7b902e54f27d7dbe26bca9e21eb45787 (diff) | |
download | gtk+-624ec0fb7d5329261dd0c4a991c7889a70c61535.tar.gz |
Add a style class for context menus
Attached widgets inherit from the style of the widget they are
attached to. This can sometimes have unintended consequences,
like a context menu in the main view of gedit inheriting the font
that is configured for documents, or the context menu of the preview
in the font chooser coming up with humongous font size.
To fix this problem, we introduce a context menu style class
and use it for all menus that are used like that. The theme
can then set a font for this style class.
https://bugzilla.gnome.org/show_bug.cgi?id=697127
-rw-r--r-- | gtk/gtkcolorswatch.c | 3 | ||||
-rw-r--r-- | gtk/gtkentry.c | 41 | ||||
-rw-r--r-- | gtk/gtklabel.c | 2 | ||||
-rw-r--r-- | gtk/gtklinkbutton.c | 8 | ||||
-rw-r--r-- | gtk/gtkmountoperation.c | 2 | ||||
-rw-r--r-- | gtk/gtknotebook.c | 3 | ||||
-rw-r--r-- | gtk/gtkplacessidebar.c | 3 | ||||
-rw-r--r-- | gtk/gtkstylecontext.h | 13 | ||||
-rw-r--r-- | gtk/gtktextview.c | 2 | ||||
-rw-r--r-- | gtk/gtktoolbar.c | 2 | ||||
-rw-r--r-- | gtk/gtkwindow.c | 3 |
11 files changed, 57 insertions, 25 deletions
diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c index a4073fd781..e2017a97a7 100644 --- a/gtk/gtkcolorswatch.c +++ b/gtk/gtkcolorswatch.c @@ -441,6 +441,9 @@ do_popup (GtkWidget *swatch, GtkWidget *item; menu = gtk_menu_new (); + gtk_style_context_add_class (gtk_widget_get_style_context (menu), + GTK_STYLE_CLASS_CONTEXT_MENU); + item = gtk_menu_item_new_with_mnemonic (_("_Customize")); gtk_menu_attach_to_widget (GTK_MENU (menu), swatch, NULL); diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 7df6538976..76bb87409d 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -9225,60 +9225,61 @@ popup_targets_received (GtkClipboard *clipboard, { DisplayMode mode; gboolean clipboard_contains_text; + GtkWidget *menu; GtkWidget *menuitem; clipboard_contains_text = gtk_selection_data_targets_include_text (data); if (info_entry_priv->popup_menu) gtk_widget_destroy (info_entry_priv->popup_menu); - info_entry_priv->popup_menu = gtk_menu_new (); + info_entry_priv->popup_menu = menu = gtk_menu_new (); + gtk_style_context_add_class (gtk_widget_get_style_context (menu), + GTK_STYLE_CLASS_CONTEXT_MENU); - gtk_menu_attach_to_widget (GTK_MENU (info_entry_priv->popup_menu), - GTK_WIDGET (entry), - popup_menu_detach); + gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (entry), popup_menu_detach); mode = gtk_entry_get_display_mode (entry); - append_action_signal (entry, info_entry_priv->popup_menu, _("Cu_t"), "cut-clipboard", + append_action_signal (entry, menu, _("Cu_t"), "cut-clipboard", info_entry_priv->editable && mode == DISPLAY_NORMAL && info_entry_priv->current_pos != info_entry_priv->selection_bound); - append_action_signal (entry, info_entry_priv->popup_menu, _("_Copy"), "copy-clipboard", + append_action_signal (entry, menu, _("_Copy"), "copy-clipboard", mode == DISPLAY_NORMAL && info_entry_priv->current_pos != info_entry_priv->selection_bound); - append_action_signal (entry, info_entry_priv->popup_menu, _("_Paste"), "paste-clipboard", + append_action_signal (entry, menu, _("_Paste"), "paste-clipboard", info_entry_priv->editable && clipboard_contains_text); menuitem = gtk_menu_item_new_with_mnemonic (_("_Delete")); gtk_widget_set_sensitive (menuitem, info_entry_priv->editable && info_entry_priv->current_pos != info_entry_priv->selection_bound); g_signal_connect_swapped (menuitem, "activate", - G_CALLBACK (gtk_entry_delete_cb), entry); + G_CALLBACK (gtk_entry_delete_cb), entry); gtk_widget_show (menuitem); - gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); menuitem = gtk_separator_menu_item_new (); gtk_widget_show (menuitem); - gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); menuitem = gtk_menu_item_new_with_mnemonic (_("Select _All")); gtk_widget_set_sensitive (menuitem, gtk_entry_buffer_get_length (info_entry_priv->buffer) > 0); g_signal_connect_swapped (menuitem, "activate", - G_CALLBACK (gtk_entry_select_all), entry); + G_CALLBACK (gtk_entry_select_all), entry); gtk_widget_show (menuitem); - gtk_menu_shell_append (GTK_MENU_SHELL (info_entry_priv->popup_menu), menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); - g_signal_emit (entry, signals[POPULATE_POPUP], 0, info_entry_priv->popup_menu); + g_signal_emit (entry, signals[POPULATE_POPUP], 0, menu); if (info->device) - gtk_menu_popup_for_device (GTK_MENU (info_entry_priv->popup_menu), - info->device, NULL, NULL, NULL, NULL, NULL, - info->button, info->time); + gtk_menu_popup_for_device (GTK_MENU (menu), + info->device, NULL, NULL, NULL, NULL, NULL, + info->button, info->time); else { - gtk_menu_popup (GTK_MENU (info_entry_priv->popup_menu), NULL, NULL, - popup_position_func, entry, - 0, gtk_get_current_event_time ()); - gtk_menu_shell_select_first (GTK_MENU_SHELL (info_entry_priv->popup_menu), FALSE); + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, + popup_position_func, entry, + 0, gtk_get_current_event_time ()); + gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE); } } diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index f8abece13f..b268c4e92a 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -6204,6 +6204,8 @@ gtk_label_do_popup (GtkLabel *label, gtk_widget_destroy (priv->select_info->popup_menu); priv->select_info->popup_menu = menu = gtk_menu_new (); + gtk_style_context_add_class (gtk_widget_get_style_context (menu), + GTK_STYLE_CLASS_CONTEXT_MENU); gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (label), popup_menu_detach); diff --git a/gtk/gtklinkbutton.c b/gtk/gtklinkbutton.c index 461e37e814..9260b79268 100644 --- a/gtk/gtklinkbutton.c +++ b/gtk/gtklinkbutton.c @@ -480,12 +480,14 @@ gtk_link_button_do_popup (GtkLinkButton *link_button, if (gtk_widget_get_realized (GTK_WIDGET (link_button))) { GtkWidget *menu_item; - + if (priv->popup_menu) gtk_widget_destroy (priv->popup_menu); priv->popup_menu = gtk_menu_new (); - + gtk_style_context_add_class (gtk_widget_get_style_context (priv->popup_menu), + GTK_STYLE_CLASS_CONTEXT_MENU); + gtk_menu_attach_to_widget (GTK_MENU (priv->popup_menu), GTK_WIDGET (link_button), popup_menu_detach); @@ -495,7 +497,7 @@ gtk_link_button_do_popup (GtkLinkButton *link_button, G_CALLBACK (copy_activate_cb), link_button); gtk_widget_show (menu_item); gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menu_item); - + if (button) gtk_menu_popup (GTK_MENU (priv->popup_menu), NULL, NULL, NULL, NULL, diff --git a/gtk/gtkmountoperation.c b/gtk/gtkmountoperation.c index f64d7a1439..65f994c7eb 100644 --- a/gtk/gtkmountoperation.c +++ b/gtk/gtkmountoperation.c @@ -1291,6 +1291,8 @@ do_popup_menu_for_process_tree_view (GtkWidget *widget, popped_up_menu = FALSE; menu = gtk_menu_new (); + gtk_style_context_add_class (gtk_widget_get_style_context (menu), + GTK_STYLE_CLASS_CONTEXT_MENU); item = gtk_menu_item_new_with_mnemonic (_("_End Process")); g_signal_connect (item, "activate", diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c index 48a0580296..bc47cccf39 100644 --- a/gtk/gtknotebook.c +++ b/gtk/gtknotebook.c @@ -7530,6 +7530,9 @@ gtk_notebook_popup_enable (GtkNotebook *notebook) return; priv->menu = gtk_menu_new (); + gtk_style_context_add_class (gtk_widget_get_style_context (priv->menu), + GTK_STYLE_CLASS_CONTEXT_MENU); + for (list = gtk_notebook_search_page (notebook, NULL, STEP_NEXT, FALSE); list; list = gtk_notebook_search_page (notebook, list, STEP_NEXT, FALSE)) diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c index 5a36d13d3d..da6592e3c4 100644 --- a/gtk/gtkplacessidebar.c +++ b/gtk/gtkplacessidebar.c @@ -3097,6 +3097,9 @@ bookmarks_build_popup_menu (GtkPlacesSidebar *sidebar) GFile *file; sidebar->popup_menu = gtk_menu_new (); + gtk_style_context_add_class (gtk_widget_get_style_context (sidebar->popup_menu), + GTK_STYLE_CLASS_CONTEXT_MENU); + gtk_menu_attach_to_widget (GTK_MENU (sidebar->popup_menu), GTK_WIDGET (sidebar), bookmarks_popup_menu_detach_cb); diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h index 53aaae9729..729613c036 100644 --- a/gtk/gtkstylecontext.h +++ b/gtk/gtkstylecontext.h @@ -258,13 +258,24 @@ struct _GtkStyleContextClass /** * GTK_STYLE_CLASS_MENU: * - * A CSS class to match popup menus. + * A CSS class to match menus. * * This is used in #GtkMenu. */ #define GTK_STYLE_CLASS_MENU "menu" /** + * GTK_STYLE_CLASS_CONTEXT_MENU: + * + * A CSS class to match context menus. + * + * This style class is useful when you want to prevent + * a context menu from inheriting e.g. font changes from + * the widget it is attached to. + */ +#define GTK_STYLE_CLASS_CONTEXT_MENU "context-menu" + +/** * GTK_STYLE_CLASS_MENUBAR: * * A CSS class to menubars. diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index 999e9daad1..889aab297f 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -8610,6 +8610,8 @@ popup_targets_received (GtkClipboard *clipboard, gtk_widget_destroy (priv->popup_menu); priv->popup_menu = gtk_menu_new (); + gtk_style_context_add_class (gtk_widget_get_style_context (priv->popup_menu), + GTK_STYLE_CLASS_CONTEXT_MENU); gtk_menu_attach_to_widget (GTK_MENU (priv->popup_menu), GTK_WIDGET (text_view), diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c index ce78fd205b..ac07f3e2fe 100644 --- a/gtk/gtktoolbar.c +++ b/gtk/gtktoolbar.c @@ -1426,7 +1426,7 @@ rebuild_menu (GtkToolbar *toolbar) if (!priv->menu) { - priv->menu = GTK_MENU (gtk_menu_new()); + priv->menu = GTK_MENU (gtk_menu_new ()); gtk_menu_attach_to_widget (priv->menu, GTK_WIDGET (toolbar), menu_detached); diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index e611a70b4d..ec94c8d5ef 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -7848,6 +7848,9 @@ gtk_window_do_popup (GtkWindow *window, gtk_widget_destroy (priv->popup_menu); priv->popup_menu = gtk_menu_new (); + gtk_style_context_add_class (gtk_widget_get_style_context (priv->popup_menu), + GTK_STYLE_CLASS_CONTEXT_MENU); + gtk_menu_attach_to_widget (GTK_MENU (priv->popup_menu), GTK_WIDGET (window), popup_menu_detach); |