summaryrefslogtreecommitdiff
path: root/gtk/gtkmenubutton.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-03-27 22:28:49 -0400
committerMatthias Clasen <mclasen@redhat.com>2020-03-28 00:08:12 -0400
commitba25e08e7b3fdf7a660cc378726689ac6687f188 (patch)
treee730602979e3531df57b815a3e7f7dcaeb1dfe4b /gtk/gtkmenubutton.c
parentbc2c341d604f5f4b387de7e04fdf243fa85082e1 (diff)
downloadgtk+-ba25e08e7b3fdf7a660cc378726689ac6687f188.tar.gz
menubutton: Add a use-underline property
This is necessary since apps no longer have direct access to the label. Closes: https://gitlab.gnome.org/GNOME/gtk/-/issues/2489
Diffstat (limited to 'gtk/gtkmenubutton.c')
-rw-r--r--gtk/gtkmenubutton.c57
1 files changed, 55 insertions, 2 deletions
diff --git a/gtk/gtkmenubutton.c b/gtk/gtkmenubutton.c
index 77f0f5198e..14a5ff0afd 100644
--- a/gtk/gtkmenubutton.c
+++ b/gtk/gtkmenubutton.c
@@ -153,6 +153,7 @@ struct _GtkMenuButtonPrivate
gpointer create_popup_user_data;
GDestroyNotify create_popup_destroy_notify;
+ GtkWidget *label_widget;
GtkWidget *align_widget;
GtkWidget *arrow_widget;
GtkArrowType arrow_type;
@@ -167,6 +168,7 @@ enum
PROP_POPOVER,
PROP_ICON_NAME,
PROP_LABEL,
+ PROP_USE_UNDERLINE,
PROP_RELIEF,
LAST_PROP
};
@@ -205,6 +207,9 @@ gtk_menu_button_set_property (GObject *object,
case PROP_LABEL:
gtk_menu_button_set_label (self, g_value_get_string (value));
break;
+ case PROP_USE_UNDERLINE:
+ gtk_menu_button_set_use_underline (self, g_value_get_boolean (value));
+ break;
case PROP_RELIEF:
gtk_menu_button_set_relief (self, g_value_get_enum (value));
break;
@@ -241,6 +246,9 @@ gtk_menu_button_get_property (GObject *object,
case PROP_LABEL:
g_value_set_string (value, gtk_menu_button_get_label (GTK_MENU_BUTTON (object)));
break;
+ case PROP_USE_UNDERLINE:
+ g_value_set_boolean (value, gtk_menu_button_get_use_underline (GTK_MENU_BUTTON (object)));
+ break;
case PROP_RELIEF:
g_value_set_enum (value, gtk_menu_button_get_relief (GTK_MENU_BUTTON (object)));
break;
@@ -415,6 +423,13 @@ gtk_menu_button_class_init (GtkMenuButtonClass *klass)
NULL,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+ menu_button_props[PROP_USE_UNDERLINE] =
+ g_param_spec_boolean ("use-underline",
+ P_("Use underline"),
+ P_("If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key"),
+ FALSE,
+ GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+
menu_button_props[PROP_RELIEF] =
g_param_spec_enum ("relief",
P_("Border relief"),
@@ -896,6 +911,8 @@ gtk_menu_button_set_label (GtkMenuButton *menu_button,
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
GtkWidget *child;
GtkWidget *box;
+ GtkWidget *label_widget;
+ GtkWidget *image;
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
@@ -904,9 +921,17 @@ gtk_menu_button_set_label (GtkMenuButton *menu_button,
gtk_container_remove (GTK_CONTAINER (priv->button), child);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
- gtk_container_add (GTK_CONTAINER (box), gtk_label_new (label));
- gtk_container_add (GTK_CONTAINER (box), gtk_image_new_from_icon_name ("pan-down-symbolic"));
+ label_widget = gtk_label_new (label);
+ g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
+ gtk_label_set_xalign (GTK_LABEL (label_widget), 0);
+ gtk_label_set_use_underline (GTK_LABEL (label_widget),
+ gtk_button_get_use_underline (GTK_BUTTON (priv->button)));
+ gtk_widget_set_hexpand (label_widget, TRUE);
+ image = gtk_image_new_from_icon_name ("pan-down-symbolic");
+ gtk_container_add (GTK_CONTAINER (box), label_widget);
+ gtk_container_add (GTK_CONTAINER (box), image);
gtk_container_add (GTK_CONTAINER (priv->button), box);
+ priv->label_widget = label_widget;
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_LABEL]);
}
@@ -1067,3 +1092,31 @@ gtk_menu_button_set_create_popup_func (GtkMenuButton *menu_button
update_sensitivity (menu_button);
}
+
+void
+gtk_menu_button_set_use_underline (GtkMenuButton *menu_button,
+ gboolean use_underline)
+{
+ GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
+
+ g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
+
+ if (gtk_button_get_use_underline (GTK_BUTTON (priv->button)) == use_underline)
+ return;
+
+ gtk_button_set_use_underline (GTK_BUTTON (priv->button), use_underline);
+ if (priv->label_widget)
+ gtk_label_set_use_underline (GTK_LABEL (priv->label_widget), use_underline);
+
+ g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_USE_UNDERLINE]);
+}
+
+gboolean
+gtk_menu_button_get_use_underline (GtkMenuButton *menu_button)
+{
+ GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
+
+ g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), FALSE);
+
+ return gtk_button_get_use_underline (GTK_BUTTON (priv->button));
+}