Commit 624ec0fb authored by Matthias Clasen's avatar Matthias Clasen

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
parent 8d7bab7d
......@@ -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);
......
......@@ -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);
}
}
......
......@@ -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);
......
......@@ -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,
......
......@@ -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",
......
......@@ -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))
......
......@@ -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);
......
......@@ -258,12 +258,23 @@ 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:
*
......
......@@ -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),
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment