[gtk/new-style-menu: 7/48] model button: Drop centered, inverted properties



commit 30f6bea25fcd4c612b88ebf53f88252e0f9f38a2
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jun 5 22:31:14 2019 +0000

    model button: Drop centered, inverted properties
    
    These properties were only useful for titles,
    and we have a role for that now.

 gtk/gtkmenusectionbox.c |   2 +-
 gtk/gtkmodelbutton.c    | 161 ++++++++++++++++--------------------------------
 2 files changed, 55 insertions(+), 108 deletions(-)
---
diff --git a/gtk/gtkmenusectionbox.c b/gtk/gtkmenusectionbox.c
index ee1dd1b553..f71108e42a 100644
--- a/gtk/gtkmenusectionbox.c
+++ b/gtk/gtkmenusectionbox.c
@@ -315,7 +315,7 @@ gtk_menu_section_box_insert_func (GtkMenuTrackerItem *item,
       if (box->iconic)
         {
           g_object_bind_property (item, "verb-icon", widget, "icon", G_BINDING_SYNC_CREATE);
-          g_object_set (widget, "iconic", TRUE, "centered", TRUE, NULL);
+          g_object_set (widget, "iconic", TRUE, NULL);
         }
       else
         g_object_bind_property (item, "icon", widget, "icon", G_BINDING_SYNC_CREATE);
diff --git a/gtk/gtkmodelbutton.c b/gtk/gtkmodelbutton.c
index 6de73b6e05..b277eab6aa 100644
--- a/gtk/gtkmodelbutton.c
+++ b/gtk/gtkmodelbutton.c
@@ -174,8 +174,6 @@ enum
   PROP_USE_MARKUP,
   PROP_ACTIVE,
   PROP_MENU_NAME,
-  PROP_INVERTED,
-  PROP_CENTERED,
   PROP_ICONIC,
   LAST_PROPERTY
 };
@@ -191,16 +189,48 @@ indicator_is_left (GtkWidget *widget)
           (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR && button->inverted));
 }
 
+static void
+update_node_ordering (GtkModelButton *button)
+{
+  GtkStyleContext *indicator_context;
+  GtkWidget *child;
+
+  indicator_context = gtk_widget_get_style_context (button->indicator_widget);
+
+  if (indicator_is_left (GTK_WIDGET (button)))
+    {
+      gtk_style_context_add_class (indicator_context, GTK_STYLE_CLASS_LEFT);
+      gtk_style_context_remove_class (indicator_context, GTK_STYLE_CLASS_RIGHT);
+
+      child = gtk_widget_get_first_child (GTK_WIDGET (button));
+      if (child != button->indicator_widget)
+        gtk_widget_insert_before (button->indicator_widget, GTK_WIDGET (button), child);
+    }
+  else
+    {
+      gtk_style_context_add_class (indicator_context, GTK_STYLE_CLASS_RIGHT);
+      gtk_style_context_remove_class (indicator_context, GTK_STYLE_CLASS_LEFT);
+
+      child = gtk_widget_get_first_child (GTK_WIDGET (button));
+      if (child != button->indicator_widget)
+        gtk_widget_insert_after (button->indicator_widget, GTK_WIDGET (button), child);
+    }
+}
+
 static void
 gtk_model_button_update_state (GtkModelButton *button)
 {
   GtkStateFlags state;
   GtkStateFlags indicator_state;
   GtkCssImageBuiltinType image_type;
+  gboolean inverted;
+  gboolean centered;
 
   state = gtk_widget_get_state_flags (GTK_WIDGET (button));
   indicator_state = state;
   image_type = GTK_CSS_IMAGE_BUILTIN_NONE;
+  inverted = FALSE;
+  centered = FALSE;
 
   switch (button->role)
     {
@@ -229,10 +259,8 @@ gtk_model_button_update_state (GtkModelButton *button)
       break;
 
     case GTK_BUTTON_ROLE_TITLE:
-      g_object_set (button,
-                    "inverted", TRUE,
-                    "centered", TRUE,
-                    NULL);
+      inverted = TRUE;
+      centered = TRUE;
       /* fall through */
 
     case GTK_BUTTON_ROLE_NORMAL:
@@ -243,13 +271,28 @@ gtk_model_button_update_state (GtkModelButton *button)
           else
             image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_RIGHT;
         }
-
+      if (!centered)
+        centered = button->iconic;
       break;
 
     default:
       g_assert_not_reached ();
     }
 
+  if (button->inverted != inverted)
+    {
+      button->inverted = inverted;
+      update_node_ordering (button);
+      gtk_widget_queue_draw (GTK_WIDGET (button));
+    }
+
+  if (button->centered != centered)
+    {
+      button->centered = centered;
+      gtk_widget_set_halign (button->box, button->centered ? GTK_ALIGN_CENTER : GTK_ALIGN_FILL);
+      gtk_widget_queue_resize (GTK_WIDGET (button));
+    }
+
   gtk_icon_set_image (GTK_ICON (button->indicator_widget), image_type);
 
   if (button->iconic)
@@ -260,34 +303,6 @@ gtk_model_button_update_state (GtkModelButton *button)
   gtk_widget_set_state_flags (button->indicator_widget, indicator_state, TRUE);
 }
 
-static void
-update_node_ordering (GtkModelButton *button)
-{
-  GtkStyleContext *indicator_context;
-  GtkWidget *child;
-
-  indicator_context = gtk_widget_get_style_context (button->indicator_widget);
-
-  if (indicator_is_left (GTK_WIDGET (button)))
-    {
-      gtk_style_context_add_class (indicator_context, GTK_STYLE_CLASS_LEFT);
-      gtk_style_context_remove_class (indicator_context, GTK_STYLE_CLASS_RIGHT);
-
-      child = gtk_widget_get_first_child (GTK_WIDGET (button));
-      if (child != button->indicator_widget)
-        gtk_widget_insert_before (button->indicator_widget, GTK_WIDGET (button), child);
-    }
-  else
-    {
-      gtk_style_context_add_class (indicator_context, GTK_STYLE_CLASS_RIGHT);
-      gtk_style_context_remove_class (indicator_context, GTK_STYLE_CLASS_LEFT);
-
-      child = gtk_widget_get_first_child (GTK_WIDGET (button));
-      if (child != button->indicator_widget)
-        gtk_widget_insert_after (button->indicator_widget, GTK_WIDGET (button), child);
-    }
-}
-
 static void
 gtk_model_button_state_flags_changed (GtkWidget     *widget,
                                       GtkStateFlags  previous_flags)
@@ -450,35 +465,6 @@ gtk_model_button_set_menu_name (GtkModelButton *button,
   g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_MENU_NAME]);
 }
 
-static void
-gtk_model_button_set_inverted (GtkModelButton *button,
-                               gboolean        inverted)
-{
-  inverted = !!inverted;
-  if (button->inverted == inverted)
-    return;
-
-  button->inverted = inverted;
-  gtk_model_button_update_state (button);
-  update_node_ordering (button);
-  gtk_widget_queue_resize (GTK_WIDGET (button));
-  g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_INVERTED]);
-}
-
-static void
-gtk_model_button_set_centered (GtkModelButton *button,
-                               gboolean        centered)
-{
-  centered = !!centered;
-  if (button->centered == centered)
-    return;
-
-  button->centered = centered;
-  gtk_widget_set_halign (button->box, button->centered ? GTK_ALIGN_CENTER : GTK_ALIGN_FILL);
-  gtk_widget_queue_draw (GTK_WIDGET (button));
-  g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_CENTERED]);
-}
-
 static void
 gtk_model_button_set_iconic (GtkModelButton *button,
                              gboolean        iconic)
@@ -513,6 +499,10 @@ gtk_model_button_set_iconic (GtkModelButton *button,
                               button->menu_name == NULL);
     }
 
+  button->centered = iconic;
+
+  gtk_widget_set_halign (button->box, button->centered ? GTK_ALIGN_CENTER : GTK_ALIGN_FILL);
+
   update_visibility (button);
   gtk_widget_queue_resize (GTK_WIDGET (button));
   g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_ICONIC]);
@@ -552,14 +542,6 @@ gtk_model_button_get_property (GObject    *object,
       g_value_set_string (value, button->menu_name);
       break;
 
-    case PROP_INVERTED:
-      g_value_set_boolean (value, button->inverted);
-      break;
-
-    case PROP_CENTERED:
-      g_value_set_boolean (value, button->centered);
-      break;
-
     case PROP_ICONIC:
       g_value_set_boolean (value, button->iconic);
       break;
@@ -604,14 +586,6 @@ gtk_model_button_set_property (GObject      *object,
       gtk_model_button_set_menu_name (button, g_value_get_string (value));
       break;
 
-    case PROP_INVERTED:
-      gtk_model_button_set_inverted (button, g_value_get_boolean (value));
-      break;
-
-    case PROP_CENTERED:
-      gtk_model_button_set_centered (button, g_value_get_boolean (value));
-      break;
-
     case PROP_ICONIC:
       gtk_model_button_set_iconic (button, g_value_get_boolean (value));
       break;
@@ -1015,33 +989,6 @@ gtk_model_button_class_init (GtkModelButtonClass *class)
                          NULL,
                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
 
-  /**
-   * GtkModelButton:inverted:
-   *
-   * Whether to show the submenu indicator at the opposite side than normal.
-   * This property should be set for model buttons that 'go back' to a parent
-   * menu.
-   */
-  properties[PROP_INVERTED] =
-    g_param_spec_boolean ("inverted",
-                          P_("Inverted"),
-                          P_("Whether the menu is a parent"),
-                          FALSE,
-                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
-
-  /**
-   * GtkModelButton:centered:
-   *
-   * Whether to render the button contents centered instead of left-aligned.
-   * This property should be set for title-like items.
-   */
-  properties[PROP_CENTERED] =
-    g_param_spec_boolean ("centered",
-                          P_("Centered"),
-                          P_("Whether to center the contents"),
-                          FALSE,
-                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
-
   /**
    * GtkModelButton:iconic:
    *


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