[gtk/new-style-menu: 6/48] model button: Add a role for titles



commit fc6010be3785a9c1bde2f2bdef9353f989c257b7
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jun 5 21:22:01 2019 +0000

    model button: Add a role for titles
    
    This gets us out of using direct presentational
    markup like 'inverted' and 'centered' and will
    make it easier to play with different layout.
    
    Use the new role when creating popover
    menus from models.

 gtk/gtkmenusectionbox.c |  3 +--
 gtk/gtkmodelbutton.c    | 43 ++++++++++++++++++++++++++++++-------------
 gtk/gtkmodelbutton.h    |  4 +++-
 3 files changed, 34 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkmenusectionbox.c b/gtk/gtkmenusectionbox.c
index 7439345373..ee1dd1b553 100644
--- a/gtk/gtkmenusectionbox.c
+++ b/gtk/gtkmenusectionbox.c
@@ -454,8 +454,7 @@ gtk_menu_section_box_new_submenu (GtkMenuTrackerItem *item,
 
   button = g_object_new (GTK_TYPE_MODEL_BUTTON,
                          "menu-name", name,
-                         "inverted", TRUE,
-                         "centered", TRUE,
+                         "role", GTK_BUTTON_ROLE_TITLE,
                          NULL);
 
   g_object_bind_property (item, "label", button, "text", G_BINDING_SYNC_CREATE);
diff --git a/gtk/gtkmodelbutton.c b/gtk/gtkmodelbutton.c
index 25dbbe6748..6de73b6e05 100644
--- a/gtk/gtkmodelbutton.c
+++ b/gtk/gtkmodelbutton.c
@@ -196,13 +196,15 @@ gtk_model_button_update_state (GtkModelButton *button)
 {
   GtkStateFlags state;
   GtkStateFlags indicator_state;
-  GtkCssImageBuiltinType image_type = GTK_CSS_IMAGE_BUILTIN_NONE;
+  GtkCssImageBuiltinType image_type;
 
   state = gtk_widget_get_state_flags (GTK_WIDGET (button));
   indicator_state = state;
+  image_type = GTK_CSS_IMAGE_BUILTIN_NONE;
 
-  if (button->role == GTK_BUTTON_ROLE_CHECK)
+  switch (button->role)
     {
+    case GTK_BUTTON_ROLE_CHECK:
       if (button->active && !button->menu_name)
         {
           indicator_state |= GTK_STATE_FLAG_CHECKED;
@@ -212,9 +214,9 @@ gtk_model_button_update_state (GtkModelButton *button)
         {
           indicator_state &= ~GTK_STATE_FLAG_CHECKED;
         }
-    }
-  if (button->role == GTK_BUTTON_ROLE_RADIO)
-    {
+      break;
+
+    case GTK_BUTTON_ROLE_RADIO:
       if (button->active && !button->menu_name)
         {
           indicator_state |= GTK_STATE_FLAG_CHECKED;
@@ -224,14 +226,28 @@ gtk_model_button_update_state (GtkModelButton *button)
         {
           indicator_state &= ~GTK_STATE_FLAG_CHECKED;
         }
-    }
+      break;
 
-  if (button->menu_name)
-    {
-      if (indicator_is_left (GTK_WIDGET (button)))
-        image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_LEFT;
-      else
-        image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_RIGHT;
+    case GTK_BUTTON_ROLE_TITLE:
+      g_object_set (button,
+                    "inverted", TRUE,
+                    "centered", TRUE,
+                    NULL);
+      /* fall through */
+
+    case GTK_BUTTON_ROLE_NORMAL:
+      if (button->menu_name != NULL)
+        {
+          if (indicator_is_left (GTK_WIDGET (button)))
+            image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_LEFT;
+          else
+            image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_RIGHT;
+        }
+
+      break;
+
+    default:
+      g_assert_not_reached ();
     }
 
   gtk_icon_set_image (GTK_ICON (button->indicator_widget), image_type);
@@ -305,6 +321,7 @@ update_node_name (GtkModelButton *button)
   switch (button->role)
     {
     case GTK_BUTTON_ROLE_NORMAL:
+    case GTK_BUTTON_ROLE_TITLE:
       a11y_role = ATK_ROLE_PUSH_BUTTON;
       if (button->menu_name)
         {
@@ -353,8 +370,8 @@ gtk_model_button_set_role (GtkModelButton *button,
   button->role = role;
 
   update_node_name (button);
-
   gtk_model_button_update_state (button);
+
   gtk_widget_queue_draw (GTK_WIDGET (button));
   g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_ROLE]);
 }
diff --git a/gtk/gtkmodelbutton.h b/gtk/gtkmodelbutton.h
index c5590460a0..dde881da08 100644
--- a/gtk/gtkmodelbutton.h
+++ b/gtk/gtkmodelbutton.h
@@ -41,13 +41,15 @@ typedef struct _GtkModelButton        GtkModelButton;
  * @GTK_BUTTON_ROLE_NORMAL: A plain button
  * @GTK_BUTTON_ROLE_CHECK: A check button
  * @GTK_BUTTON_ROLE_RADIO: A radio button
+ * @GTK_BUTTON_ROLE_TITLE: The title for a submenu
  *
  * The role specifies the desired appearance of a #GtkModelButton.
  */
 typedef enum {
   GTK_BUTTON_ROLE_NORMAL,
   GTK_BUTTON_ROLE_CHECK,
-  GTK_BUTTON_ROLE_RADIO
+  GTK_BUTTON_ROLE_RADIO,
+  GTK_BUTTON_ROLE_TITLE
 } GtkButtonRole;
 
 GDK_AVAILABLE_IN_ALL


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