[gtk/matthiasc/for-master: 8/9] stack: Add a :use-underline property



commit cb056a1e8fff050300870b5dce66550793e64cc9
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Apr 30 19:17:34 2020 -0400

    stack: Add a :use-underline property
    
    Add GtkStackPage:use-underline, and use it when
    constructing labels in the stack switcher.

 gtk/gtkstack.c         | 25 +++++++++++++++++++++++--
 gtk/gtkstackswitcher.c |  8 ++++++--
 2 files changed, 29 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c
index d2f455af65..a0d8253edc 100644
--- a/gtk/gtkstack.c
+++ b/gtk/gtkstack.c
@@ -184,6 +184,7 @@ enum
   CHILD_PROP_ICON_NAME,
   CHILD_PROP_NEEDS_ATTENTION,
   CHILD_PROP_VISIBLE,
+  CHILD_PROP_USE_UNDERLINE,
   LAST_CHILD_PROP
 };
 
@@ -195,9 +196,10 @@ struct _GtkStackPage
   char *name;
   char *title;
   char *icon_name;
-  gboolean needs_attention;
-  gboolean visible;
   GtkWidget *last_focus;
+  guint needs_attention : 1;
+  guint visible         : 1;
+  guint use_underline   : 1;
 };
 
 typedef struct _GtkStackPageClass GtkStackPageClass;
@@ -268,6 +270,10 @@ gtk_stack_page_get_property (GObject      *object,
       g_value_set_boolean (value, gtk_stack_page_get_visible (info));
       break;
 
+    case CHILD_PROP_USE_UNDERLINE:
+      g_value_set_boolean (value, info->use_underline);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -348,6 +354,14 @@ gtk_stack_page_set_property (GObject      *object,
       gtk_stack_page_set_visible (info, g_value_get_boolean (value));
       break;
 
+    case CHILD_PROP_USE_UNDERLINE:
+      if (info->use_underline != g_value_get_boolean (value))
+        {
+          info->use_underline = g_value_get_boolean (value);
+          g_object_notify_by_pspec (object, pspec);
+        }
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -412,6 +426,13 @@ gtk_stack_page_class_init (GtkStackPageClass *class)
                          TRUE,
                          GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
+  stack_child_props[CHILD_PROP_USE_UNDERLINE] =
+    g_param_spec_boolean ("use-underline",
+                         P_("Use underline"),
+                         P_("If set, an underline in the title indicates the next character should be used 
for the mnemonic accelerator key"),
+                         FALSE,
+                         GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
   g_object_class_install_properties (object_class, LAST_CHILD_PROP, stack_child_props);
 }
 
diff --git a/gtk/gtkstackswitcher.c b/gtk/gtkstackswitcher.c
index 3098ffc38c..4d9064260e 100644
--- a/gtk/gtkstackswitcher.c
+++ b/gtk/gtkstackswitcher.c
@@ -123,7 +123,8 @@ on_button_toggled (GtkWidget        *button,
 static void
 rebuild_child (GtkWidget   *self,
                const gchar *icon_name,
-               const gchar *title)
+               const gchar *title,
+               gboolean     use_underline)
 {
   GtkWidget *button_child;
 
@@ -145,6 +146,7 @@ rebuild_child (GtkWidget   *self,
   else if (title != NULL)
     {
       button_child = gtk_label_new (title);
+      gtk_label_set_use_underline (GTK_LABEL (button_child), use_underline);
 
       gtk_widget_set_tooltip_text (GTK_WIDGET (self), NULL);
 
@@ -168,15 +170,17 @@ update_button (GtkStackSwitcher *self,
   gchar *icon_name;
   gboolean needs_attention;
   gboolean visible;
+  gboolean use_underline;
 
   g_object_get (page,
                 "title", &title,
                 "icon-name", &icon_name,
                 "needs-attention", &needs_attention,
                 "visible", &visible,
+                "use-underline", &use_underline,
                 NULL);
 
-  rebuild_child (button, icon_name, title);
+  rebuild_child (button, icon_name, title, use_underline);
 
   gtk_widget_set_visible (button, visible && (title != NULL || icon_name != NULL));
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]