[glade] Add GtkBox center-widget support



commit 6f8f3372d3ebcec39bdfeeb3da384f2a5ccc7ef1
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Oct 13 12:55:56 2014 -0400

    Add GtkBox center-widget support
    
    In 3.12, GtkBox gained support for a centered child. With this
    patch, glade supports this too.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=738473

 plugins/gtk+/glade-gtk-box.c |   85 +++++++++++++++++++++++++++++++++++++++++-
 plugins/gtk+/gtk+.xml.in     |   10 +++++
 2 files changed, 93 insertions(+), 2 deletions(-)
---
diff --git a/plugins/gtk+/glade-gtk-box.c b/plugins/gtk+/glade-gtk-box.c
index 00c02ce..c29ec75 100644
--- a/plugins/gtk+/glade-gtk-box.c
+++ b/plugins/gtk+/glade-gtk-box.c
@@ -56,11 +56,21 @@ glade_gtk_box_create_editable (GladeWidgetAdaptor * adaptor,
   return GWA_GET_CLASS (GTK_TYPE_CONTAINER)->create_editable (adaptor, type);
 }
 
+static void
+glade_gtk_box_parse_finished (GladeProject * project, GObject * object)
+{
+  GladeWidget *gbox;
+
+  gbox = glade_widget_get_from_gobject (object);
+  glade_widget_property_set (gbox, "use-center-child", gtk_box_get_center_widget (GTK_BOX (object)) != NULL);
+}
+
 void
 glade_gtk_box_post_create (GladeWidgetAdaptor * adaptor,
                            GObject * container, GladeCreateReason reason)
 {
   GladeWidget *gwidget = glade_widget_get_from_gobject (container);
+  GladeProject *project = glade_widget_get_project (gwidget);
 
   /* Implement drag in GtkBox but not resize.
    */
@@ -75,6 +85,12 @@ glade_gtk_box_post_create (GladeWidgetAdaptor * adaptor,
   g_signal_connect (G_OBJECT (gwidget), "configure-end",
                     G_CALLBACK (glade_gtk_box_configure_end), container);
 
+  if (reason == GLADE_CREATE_LOAD)
+    {
+      g_signal_connect (project, "parse-finished",
+                        G_CALLBACK (glade_gtk_box_parse_finished),
+                        container);
+    }
 }
 
 static gint
@@ -92,6 +108,11 @@ sort_box_children (GtkWidget * widget_a, GtkWidget * widget_b, GtkWidget *box)
   if (box != gtk_widget_get_parent (widget_b))
     return 1;
 
+  if (gtk_box_get_center_widget (GTK_BOX (box)) == widget_a)
+    return -1;
+  if (gtk_box_get_center_widget (GTK_BOX (box)) == widget_b)
+    return -1;
+
   /* XXX Sometimes the packing "position" property doesnt exist here, why ?
    */
   if (gwidget_a)
@@ -226,6 +247,8 @@ glade_gtk_box_get_num_children (GObject *box)
 {
   GList *children = gtk_container_get_children (GTK_CONTAINER (box));
   gint retval = g_list_length (children);
+  if (gtk_box_get_center_widget (GTK_BOX (box)) != NULL)
+    retval -= 1;
   g_list_free (children);
   return retval;
 }
@@ -234,7 +257,12 @@ void
 glade_gtk_box_get_property (GladeWidgetAdaptor * adaptor,
                             GObject * object, const gchar * id, GValue * value)
 {
-  if (!strcmp (id, "size"))
+  if (!strcmp (id, "use-center-child"))
+    {
+      g_value_reset (value);
+      g_value_set_boolean (value, gtk_box_get_center_widget (GTK_BOX (object)) != NULL);
+    }
+  else if (!strcmp (id, "size"))
     {
       g_value_reset (value);
       g_value_set_int (value, glade_gtk_box_get_num_children (object));
@@ -258,6 +286,9 @@ glade_gtk_box_get_first_blank (GtkBox * box)
     {
       GtkWidget *widget = child->data;
 
+      if (widget == gtk_box_get_center_widget (GTK_BOX (box)))
+        continue;
+
       if ((gwidget = glade_widget_get_from_gobject (widget)) != NULL)
         {
           gint gwidget_position = 0;
@@ -292,6 +323,7 @@ glade_gtk_box_set_size (GObject * object, const GValue * value)
     return;
 
   children = gtk_container_get_children (GTK_CONTAINER (box));
+  children = g_list_remove (children, gtk_box_get_center_widget (GTK_BOX (box)));
 
   old_size = g_list_length (children);
   new_size = g_value_get_int (value);
@@ -344,7 +376,23 @@ glade_gtk_box_set_property (GladeWidgetAdaptor * adaptor,
                             GObject * object,
                             const gchar * id, const GValue * value)
 {
-  if (!strcmp (id, "size"))
+  if (!strcmp (id, "use-center-child"))
+    {
+      GtkWidget *child;
+
+      if (g_value_get_boolean (value))
+        {
+          child = gtk_box_get_center_widget (GTK_BOX (object));
+          if (!child)
+            child = glade_placeholder_new ();
+          g_object_set_data (G_OBJECT (child), "special-child-type", "center");
+        }
+      else
+        child = NULL;
+      gtk_box_set_center_widget (GTK_BOX (object), child);
+    }
+
+  else if (!strcmp (id, "size"))
     glade_gtk_box_set_size (object, value);
   else
     GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor, object, id,
@@ -359,6 +407,7 @@ glade_gtk_box_verify_size (GObject *object, const GValue *value)
   gint new_size = g_value_get_int (value);
   
   children = gtk_container_get_children (GTK_CONTAINER (object));
+  children = g_list_remove (children, gtk_box_get_center_widget (GTK_BOX (object)));
   old_size = g_list_length (children);
 
   for (child = g_list_last (children);
@@ -420,12 +469,20 @@ glade_gtk_box_add_child (GladeWidgetAdaptor * adaptor,
 {
   GladeWidget *gbox, *gchild;
   gint num_children;
+  gchar *special_child_type;
 
   g_return_if_fail (GTK_IS_BOX (object));
   g_return_if_fail (GTK_IS_WIDGET (child));
 
   gbox = glade_widget_get_from_gobject (object);
 
+  special_child_type = g_object_get_data (child, "special-child-type");
+  if (special_child_type && !strcmp (special_child_type, "center"))
+    {
+      gtk_box_set_center_widget (GTK_BOX (object), GTK_WIDGET (child));
+       return;
+    }
+
   /*
      Try to remove the last placeholder if any, this way GtkBox`s size 
      will not be changed.
@@ -477,12 +534,24 @@ glade_gtk_box_remove_child (GladeWidgetAdaptor * adaptor,
 {
   GladeWidget *gbox;
   gint size;
+  gchar *special_child_type;
 
   g_return_if_fail (GTK_IS_BOX (object));
   g_return_if_fail (GTK_IS_WIDGET (child));
 
   gbox = glade_widget_get_from_gobject (object);
 
+  special_child_type = g_object_get_data (child, "special-child-type");
+  if (special_child_type && !strcmp (special_child_type, "center"))
+    {
+      GtkWidget *w;
+
+      w = glade_placeholder_new ();
+      g_object_set_data (G_OBJECT (w), "special-child-type", "center");
+      gtk_box_set_center_widget (GTK_BOX (object), w);
+      return;
+    }
+
   gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child));
 
   if (glade_widget_superuser () == FALSE)
@@ -503,6 +572,18 @@ glade_gtk_box_replace_child (GladeWidgetAdaptor * adaptor,
   GladeWidget *gchild;
   GladeWidget *gbox;
 
+  gchar *special_child_type;
+
+  special_child_type =
+      g_object_get_data (G_OBJECT (current), "special-child-type");
+
+  if (special_child_type && !strcmp (special_child_type, "center"))
+    {
+      g_object_set_data (G_OBJECT (new_widget), "special-child-type", "center");
+      gtk_box_set_center_widget (GTK_BOX (container), GTK_WIDGET (new_widget));
+      return;
+    }
+
   g_object_ref (G_OBJECT (current));
 
   GWA_GET_CLASS (GTK_TYPE_CONTAINER)->replace_child (adaptor,
diff --git a/plugins/gtk+/gtk+.xml.in b/plugins/gtk+/gtk+.xml.in
index 4e9ee37..81bc429 100644
--- a/plugins/gtk+/gtk+.xml.in
+++ b/plugins/gtk+/gtk+.xml.in
@@ -627,6 +627,7 @@
         <replace-child-function>glade_gtk_box_replace_child</replace-child-function>
         <child-set-property-function>glade_gtk_box_set_child_property</child-set-property-function>
         <child-action-activate-function>glade_gtk_box_child_action_activate</child-action-activate-function>
+        <special-child-type>type</special-child-type>
         
         <packing-actions>
           <action id="insert_before" _name="Insert Before" stock="list-add"/>
@@ -655,6 +656,11 @@
               <value id="GTK_BASELINE_POSITION_BOTTOM" _name="Bottom"/>
             </displayable-values>
           </property>
+          <property visible="True" save="False" id="use-center-child" since="3.12" default="FALSE" 
name="Center Child">
+            <parameter-spec>
+              <type>GParamBoolean</type>
+            </parameter-spec>
+          </property>
         </properties>
         
         <packing-properties>
@@ -1805,6 +1811,7 @@
           <property id="orientation" disabled="True"/>
           <property id="spacing" disabled="True"/>
           <property id="baseline-position" disabled="True"/>
+          <property id="use-center-child" disabled="True"/>
           
           <!-- GtkFileChooser properties are custom-layout, handled in GladeFileChooserEditor -->
           <property id="extra-widget" parentless-widget="True" custom-layout="True"/>
@@ -1875,6 +1882,7 @@
           <property id="orientation" disabled="True"/>
           <property id="spacing" disabled="True"/>
           <property id="baseline-position" disabled="True"/>
+          <property id="use-center-child" disabled="True"/>
           
           <!-- GtkFileChooser properties are custom-layout, handled in GladeFileChooserEditor -->
           <property id="extra-widget" parentless-widget="True" custom-layout="True"/>
@@ -3103,6 +3111,7 @@
           <property id="orientation" disabled="True"/>
           <property id="spacing" disabled="True"/>
           <property id="baseline-position" disabled="True"/>
+          <property id="use-center-child" disabled="True"/>
           
           <!-- Claim the GladeFontChooserEditor properties -->
           <property id="font" custom-layout="True"/>
@@ -3204,6 +3213,7 @@
           <property id="orientation" disabled="True"/>
           <property id="spacing" disabled="True"/>
           <property id="baseline-position" disabled="True"/>
+          <property id="use-center-child" disabled="True"/>
           
           <!-- Claim the GladeRecentChooserEditor properties  -->
           <property id="recent-manager" custom-layout="True"/>


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