[glade/internal-children: 6/7] Misc fixes and cleanups



commit 7dca3dc8522ce31ba625b558d850ceea67a66305
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date:   Thu Mar 10 19:57:56 2011 -0300

    Misc fixes and cleanups

 gladeui/glade-widget-adaptor.c |  133 +++++++++++++++++++++++++++++++---------
 gladeui/glade-widget-adaptor.h |    3 +-
 gladeui/glade-widget.c         |    5 +-
 plugins/gtk+/glade-gtk.c       |   76 +++--------------------
 plugins/gtk+/gtk+.xml.in       |   51 ++++++++++------
 5 files changed, 150 insertions(+), 118 deletions(-)
---
diff --git a/gladeui/glade-widget-adaptor.c b/gladeui/glade-widget-adaptor.c
index 12195e2..dc15b9b 100644
--- a/gladeui/glade-widget-adaptor.c
+++ b/gladeui/glade-widget-adaptor.c
@@ -287,9 +287,58 @@ glade_widget_adaptor_get_parent_adaptor (GladeWidgetAdaptor * adaptor)
 gboolean
 glade_widget_adaptor_has_internal_children (GladeWidgetAdaptor *adaptor)
 {
+  g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), FALSE);
   return adaptor->priv->internal_children != NULL;
 }
 
+static void
+gwa_get_internal_children (GladeWidgetAdaptor *adaptor,
+                           GObject *container,
+                           GList **children,
+                           GList *list)
+{
+  GList *l;
+  
+  for (l = list; l; l = g_list_next (l))
+    {
+      GladeInternalChild *internal = l->data;
+      GObject *child;
+
+      child = glade_widget_adaptor_get_internal_child (adaptor,
+                                                       container,
+                                                       internal->name);
+
+      if (child)
+        {
+          GtkWidget *parent;
+
+          /* Only return a widget if is not packed into a wrapped object */
+          if (GTK_IS_WIDGET (child) == FALSE ||
+              ((parent = gtk_widget_get_parent (GTK_WIDGET (child))) && 
+              glade_widget_get_from_gobject (parent) == NULL))
+            *children = g_list_prepend (*children, child);
+
+          if (internal->children)
+            gwa_get_internal_children (adaptor, container, children, internal->children);
+        }
+    }
+}
+
+GList *
+glade_widget_adaptor_get_internal_children (GladeWidgetAdaptor *adaptor,
+                                            GObject            *container)
+{
+  GList *children;
+  
+  g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL);
+
+  children = NULL;
+
+  gwa_get_internal_children (adaptor, container, &children, adaptor->priv->internal_children);
+
+  return children;
+}
+
 static gint
 gwa_signal_comp (gpointer a, gpointer b)
 {
@@ -538,6 +587,17 @@ gwa_inherit_signals (GladeWidgetAdaptor * adaptor)
     }
 }
 
+static GladeInternalChild *
+gwa_internal_children_new (gchar *name, gboolean anarchist)
+{
+  GladeInternalChild *data = g_slice_new0 (GladeInternalChild);
+
+  data->name = g_strdup (name);
+  data->anarchist = anarchist;
+
+  return data;
+}
+
 static GList *
 gwa_internal_children_clone (GList *children)
 {
@@ -545,19 +605,16 @@ gwa_internal_children_clone (GList *children)
   
   for (l = children; l; l = g_list_next (l))
     {
-      GladeInternalChild *data = g_new0 (GladeInternalChild, 1);
-      GladeInternalChild *child = l->data;
-
-      data->name = g_strdup (child->name);
-      data->anarchist = child->anarchist;
+      GladeInternalChild *data, *child = l->data;
 
+      data = gwa_internal_children_new (child->name, child->anarchist);
       retval = g_list_prepend (retval, data);
 
       if (child->children)
         data->children = gwa_internal_children_clone (child->children);
     }
 
-  return retval;
+  return g_list_reverse (retval);
 }
 
 static GObject *
@@ -647,9 +704,7 @@ glade_widget_adaptor_constructor (GType type,
 
   /* Copy parent internal children */
   if (parent_adaptor && parent_adaptor->priv->internal_children)
-    {
-      adaptor->priv->internal_children = gwa_internal_children_clone (parent_adaptor->priv->internal_children);
-    }
+    adaptor->priv->internal_children = gwa_internal_children_clone (parent_adaptor->priv->internal_children);
 
   return ret_obj;
 }
@@ -682,7 +737,19 @@ gwa_glade_internal_child_free (GladeInternalChild *child)
       g_list_free (child->children);
     }
   
-  g_free (child);
+  g_slice_free (GladeInternalChild, child);
+}
+
+static void
+gwa_internal_children_free (GladeWidgetAdaptor *adaptor)
+{
+  if (adaptor->priv->internal_children)
+    {
+      g_list_foreach (adaptor->priv->internal_children,
+                      (GFunc) gwa_glade_internal_child_free, NULL);
+      g_list_free (adaptor->priv->internal_children);
+      adaptor->priv->internal_children = NULL;
+    }
 }
 
 static void
@@ -744,12 +811,7 @@ glade_widget_adaptor_finalize (GObject * object)
       g_list_free (adaptor->priv->packing_actions);
     }
 
-  if (adaptor->priv->internal_children)
-    {
-      g_list_foreach (adaptor->priv->internal_children,
-                      (GFunc) gwa_glade_internal_child_free, NULL);
-      g_list_free (adaptor->priv->internal_children);
-    }
+  gwa_internal_children_free (adaptor);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -876,9 +938,9 @@ glade_widget_adaptor_object_construct_object (GladeWidgetAdaptor * adaptor,
 
 
 static GObject *
-glade_widget_adaptor_get_internal_child_impl (GladeWidgetAdaptor *adaptor,
-                                              GObject *object,
-                                              const gchar *name)
+glade_widget_adaptor_object_get_internal_child (GladeWidgetAdaptor *adaptor,
+                                                GObject *object,
+                                                const gchar *name)
 {
   static GtkBuilder *builder = NULL;
   
@@ -1297,7 +1359,7 @@ glade_widget_adaptor_class_init (GladeWidgetAdaptorClass * adaptor_class)
       glade_widget_adaptor_object_construct_object;
   adaptor_class->deep_post_create = NULL;
   adaptor_class->post_create = NULL;
-  adaptor_class->get_internal_child = glade_widget_adaptor_get_internal_child_impl;
+  adaptor_class->get_internal_child = glade_widget_adaptor_object_get_internal_child;
   adaptor_class->verify_property = NULL;
   adaptor_class->set_property = glade_widget_adaptor_object_set_property;
   adaptor_class->get_property = glade_widget_adaptor_object_get_property;
@@ -2262,10 +2324,17 @@ gwa_set_signals_from_node (GladeWidgetAdaptor *adaptor,
     }
 }
 
+static gint
+gwa_internal_child_cmp (gconstpointer a, gconstpointer b)
+{
+  const GladeInternalChild *da = a;
+  return strcmp (da->name, b);
+}
+
 static GList *
 gwa_internal_children_update_from_node (GList *internal_children, GladeXmlNode *node)
 {
-  GList *retval = internal_children;
+  GList *link, *retval = internal_children;
   GladeXmlNode *child, *children;
   
   for (child = glade_xml_node_get_children (node);
@@ -2280,15 +2349,21 @@ gwa_internal_children_update_from_node (GList *internal_children, GladeXmlNode *
       if (!(name = glade_xml_get_property_string_required (child, GLADE_TAG_NAME, NULL)))
         continue;
 
-      data = g_new0 (GladeInternalChild, 1);
-
-      data->name = name;
-      data->anarchist = glade_xml_get_boolean (child, GLADE_TAG_ANARCHIST, FALSE);
-
-      if ((children = glade_xml_search_child (child, GLADE_TAG_INTERNAL_CHILDREN)))
-        data->children = gwa_internal_children_update_from_node (data->children,children);
+      if ((link = g_list_find_custom (retval, name, gwa_internal_child_cmp)))
+        {
+          data = link->data;
+        }
+      else
+        {
+          gboolean anarchist = glade_xml_get_boolean (child, GLADE_TAG_ANARCHIST, FALSE);
+          data = gwa_internal_children_new (name, anarchist);
+          retval = g_list_prepend (retval, data);
+        }
       
-      retval = g_list_prepend (retval, data);
+      if ((children = glade_xml_search_child (child, GLADE_TAG_INTERNAL_CHILDREN)))
+        data->children = gwa_internal_children_update_from_node (data->children, children);
+
+      g_free (name);
     }
   
   return retval;
diff --git a/gladeui/glade-widget-adaptor.h b/gladeui/glade-widget-adaptor.h
index 3e65d52..c609cf9 100644
--- a/gladeui/glade-widget-adaptor.h
+++ b/gladeui/glade-widget-adaptor.h
@@ -844,7 +844,8 @@ GladeSignalClass     *glade_widget_adaptor_get_signal_class   (GladeWidgetAdapto
 GladeWidgetAdaptor   *glade_widget_adaptor_get_parent_adaptor (GladeWidgetAdaptor *adaptor);
 
 gboolean              glade_widget_adaptor_has_internal_children (GladeWidgetAdaptor *adaptor);
-
+GList                *glade_widget_adaptor_get_internal_children (GladeWidgetAdaptor *adaptor,
+                                                                  GObject            *container);
 G_END_DECLS
 
 #endif /* _GLADE_WIDGET_ADAPTOR_H_ */
diff --git a/gladeui/glade-widget.c b/gladeui/glade-widget.c
index 6bcb254..14e2edb 100644
--- a/gladeui/glade-widget.c
+++ b/gladeui/glade-widget.c
@@ -3480,7 +3480,7 @@ glade_widget_set_parent (GladeWidget * widget, GladeWidget * parent)
  *
  * Finds a child widget named @name.
  *
- * Returns: The child of widget or NULL if ti was not found
+ * Returns: The child of widget or NULL if it was not found.
  */
 GladeWidget *
 glade_widget_find_child (GladeWidget *widget, gchar *name)
@@ -3550,6 +3550,7 @@ glade_widget_get_children (GladeWidget * widget)
   return g_list_reverse (real_children);
 }
 
+
 /**
  * glade_widget_get_toplevel:
  * @widget: A #GladeWidget
@@ -3805,7 +3806,7 @@ glade_widget_read (GladeProject * project,
               if (internal)
                 {
                   GObject *child_object =
-                    glade_widget_get_internal_child (parent, internal);
+                      glade_widget_get_internal_child (parent, internal);
 
                   if (!child_object)
                     {
diff --git a/plugins/gtk+/glade-gtk.c b/plugins/gtk+/glade-gtk.c
index 2910339..0204e51 100644
--- a/plugins/gtk+/glade-gtk.c
+++ b/plugins/gtk+/glade-gtk.c
@@ -1233,10 +1233,15 @@ glade_gtk_container_get_child_property (GladeWidgetAdaptor * adaptor,
 }
 
 GList *
-glade_gtk_container_get_children (GladeWidgetAdaptor * adaptor,
-                                  GtkContainer * container)
+glade_gtk_container_get_children (GladeWidgetAdaptor *adaptor,
+                                  GtkContainer *container)
 {
-  return glade_util_container_get_all_children (container);
+  GList *children, *internal_children;
+
+  children = glade_util_container_get_all_children (container);
+  internal_children = glade_widget_adaptor_get_internal_children (adaptor, G_OBJECT (container));
+
+  return g_list_concat (children, internal_children);
 }
 
 GladeEditable *
@@ -3963,71 +3968,6 @@ glade_gtk_dialog_post_create (GladeWidgetAdaptor *adaptor,
     }
 }
 
-GList *
-glade_gtk_dialog_get_children (GladeWidgetAdaptor * adaptor, GtkDialog * dialog)
-{
-  GList *list = NULL;
-
-  g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
-
-  list = glade_util_container_get_all_children (GTK_CONTAINER (dialog));
-
-  if (GTK_IS_COLOR_SELECTION_DIALOG (dialog))
-    {
-      GtkWidget *widget;
-
-      widget = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_OK);
-      if (widget)
-        list = g_list_prepend (list, widget);
-
-      widget = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_CANCEL);
-      if (widget)
-        list = g_list_prepend (list, widget);
-
-      widget = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_HELP);
-      if (widget)
-        list = g_list_prepend (list, widget);
-
-      widget =
-          gtk_color_selection_dialog_get_color_selection
-          (GTK_COLOR_SELECTION_DIALOG (dialog));
-      if (widget)
-        list = g_list_prepend (list, widget);
-    }
-  else if (GTK_IS_FONT_SELECTION_DIALOG (dialog))
-    {
-      GtkWidget *widget;
-
-      widget =
-          gtk_font_selection_dialog_get_ok_button (GTK_FONT_SELECTION_DIALOG
-                                                   (dialog));
-      if (widget)
-        list = g_list_prepend (list, widget);
-
-      widget = gtk_dialog_get_widget_for_response (dialog, GTK_RESPONSE_APPLY);
-      if (widget)
-        list = g_list_prepend (list, widget);
-
-      widget =
-          gtk_font_selection_dialog_get_cancel_button (GTK_FONT_SELECTION_DIALOG
-                                                       (dialog));
-      if (widget)
-        list = g_list_prepend (list, widget);
-
-#if GTK_CHECK_VERSION (2, 24, 0)
-      widget =
-          gtk_font_selection_dialog_get_font_selection
-          (GTK_FONT_SELECTION_DIALOG (dialog));
-#else
-      widget = GTK_FONT_SELECTION_DIALOG (dialog)->fontsel;
-#endif
-
-      if (widget)
-        list = g_list_prepend (list, widget);
-    }
-  return list;
-}
-
 void
 glade_gtk_dialog_read_child (GladeWidgetAdaptor * adaptor,
                              GladeWidget * widget, GladeXmlNode * node)
diff --git a/plugins/gtk+/gtk+.xml.in b/plugins/gtk+/gtk+.xml.in
index 1445706..84b4628 100644
--- a/plugins/gtk+/gtk+.xml.in
+++ b/plugins/gtk+/gtk+.xml.in
@@ -1364,7 +1364,6 @@ embedded in another object</_tooltip>
     <glade-widget-class name="GtkDialog" generic-name="dialog" _title="Dialog Box" 
 			default-width="320" default-height="260">
       <post-create-function>glade_gtk_dialog_post_create</post-create-function>
-      <get-children-function>glade_gtk_dialog_get_children</get-children-function>
       <read-child-function>glade_gtk_dialog_read_child</read-child-function>
       <write-child-function>glade_gtk_dialog_write_child</write-child-function>
 
@@ -1770,6 +1769,15 @@ embedded in another object</_tooltip>
         <object name="content_area"/>
       </internal-children>
       <properties>
+	<property id="message-type">
+  	  <displayable-values>
+	    <value id="GTK_MESSAGE_INFO" _name="Info"/>
+	    <value id="GTK_MESSAGE_WARNING" _name="Warning"/>
+	    <value id="GTK_MESSAGE_QUESTION" _name="Question"/>
+	    <value id="GTK_MESSAGE_ERROR" _name="Error"/>
+	    <value id="GTK_MESSAGE_OTHER" _name="Other"/>
+	  </displayable-values>
+	</property>
         <property id="size" query="True" ignore="True" disabled="True"/>
       </properties>
     </glade-widget-class>
@@ -1865,10 +1873,18 @@ embedded in another object</_tooltip>
 
     <glade-widget-class name="GtkColorSelectionDialog" generic-name="colorselectiondialog" _title="Color Selection Dialog">
       <internal-children>
-        <object name="ok_button"/>
-        <object name="cancel_button"/>
-        <object name="help_button"/>
-        <object name="color_selection"/>
+        <object name="vbox">
+          <internal-children>
+            <object name="color_selection"/>
+            <object name="action_area">
+              <internal-children>
+                <object name="ok_button"/>
+                <object name="cancel_button"/>
+                <object name="help_button"/>
+              </internal-children>
+            </object>
+          </internal-children>
+        </object>
       </internal-children>
       <properties>
         <property id="has-separator"  disabled="True"/>
@@ -1890,10 +1906,18 @@ embedded in another object</_tooltip>
     
     <glade-widget-class name="GtkFontSelectionDialog" generic-name="fontselectiondialog" _title="Font Selection Dialog">
       <internal-children>
-        <object name="ok_button"/>
-        <object name="apply_button"/>
-        <object name="cancel_button"/>
-        <object name="font_selection"/>
+        <object name="vbox">
+          <internal-children>
+            <object name="font_selection"/>
+            <object name="action_area">
+              <internal-children>
+                <object name="ok_button"/>
+                <object name="cancel_button"/>
+                <object name="apply_button"/>
+              </internal-children>
+            </object>
+          </internal-children>
+        </object>
       </internal-children>
       <properties>
         <property id="has-separator"  disabled="True"/>
@@ -1923,15 +1947,6 @@ embedded in another object</_tooltip>
 	<property id="text" translatable="True" since="2.10"/>
 	<property id="use-markup" since="2.10"/>
 
-	<property id="message-type">
-  	  <displayable-values>
-	    <value id="GTK_MESSAGE_INFO" _name="Info"/>
-	    <value id="GTK_MESSAGE_WARNING" _name="Warning"/>
-	    <value id="GTK_MESSAGE_QUESTION" _name="Question"/>
-	    <value id="GTK_MESSAGE_ERROR" _name="Error"/>
-	    <value id="GTK_MESSAGE_OTHER" _name="Other"/>
-	  </displayable-values>
-	</property>
 	<property id="buttons">
   	  <displayable-values>
 	    <value id="GTK_BUTTONS_NONE" _name="None"/>



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