gtk+ r19334 - in branches/gtk-2-12: . docs/reference/gtk/tmpl gtk



Author: johan
Date: Thu Jan 10 10:20:49 2008
New Revision: 19334
URL: http://svn.gnome.org/viewvc/gtk+?rev=19334&view=rev

Log:
2007-01-06  Johan Dahlin  <johan gnome org>

	Merged from trunk:

	* gtkbuilder.c: remove concept of root objects and just refcount
	all objects in the builder.  Fixes #496651.

	* docs/reference/gtk/tmpl/gtkbuildable.sgml: add clarification stating
	that the construct_child function is responsible for returning a
	reference.
	* gtkbuilder.c (_gtk_builder_construct): remove g_object_ref() for
	objects from constructors
	* gtkuimanager.c (gtk_ui_manager_buildable_construct_child): add
	g_object_ref() to this construction function (it's the only
	implementer in GTK)

	Fixes #496645.



Modified:
   branches/gtk-2-12/ChangeLog
   branches/gtk-2-12/docs/reference/gtk/tmpl/gtkbuildable.sgml
   branches/gtk-2-12/gtk/gtkbuilder.c
   branches/gtk-2-12/gtk/gtkuimanager.c

Modified: branches/gtk-2-12/docs/reference/gtk/tmpl/gtkbuildable.sgml
==============================================================================
--- branches/gtk-2-12/docs/reference/gtk/tmpl/gtkbuildable.sgml	(original)
+++ branches/gtk-2-12/docs/reference/gtk/tmpl/gtkbuildable.sgml	Thu Jan 10 10:20:49 2008
@@ -61,7 +61,8 @@
 @construct_child: Constructs a child of a buildable that has been
   specified as "constructor" in the UI definition. #GtkUIManager implements 
   this to reference to a widget created in a &lt;ui&gt; tag which is outside 
-  of the normal GtkBuilder UI definition hierarchy.
+  of the normal GtkBuilder UI definition hierarchy.  A reference to the
+  constructed object is returned and becomes owned by the caller.
 @custom_tag_start: Implement this if the buildable needs to parse 
   content below &lt;child&gt;. To handle an element, the implementation
   must fill in the @parser structure and @user_data and return %TRUE.

Modified: branches/gtk-2-12/gtk/gtkbuilder.c
==============================================================================
--- branches/gtk-2-12/gtk/gtkbuilder.c	(original)
+++ branches/gtk-2-12/gtk/gtkbuilder.c	Thu Jan 10 10:20:49 2008
@@ -67,7 +67,6 @@
   GHashTable *objects;
   GSList *delayed_properties;
   GSList *signals;
-  GSList *root_objects;
   gchar *filename;
 };
 
@@ -114,7 +113,7 @@
                                                GtkBuilderPrivate);
   builder->priv->domain = NULL;
   builder->priv->objects = g_hash_table_new_full (g_str_hash, g_str_equal,
-                                                  g_free, NULL);
+                                                  g_free, g_object_unref);
 }
 
 
@@ -135,9 +134,6 @@
   g_slist_foreach (priv->signals, (GFunc) _free_signal_info, NULL);
   g_slist_free (priv->signals);
   
-  g_slist_foreach (priv->root_objects, (GFunc) g_object_unref, NULL);
-  g_slist_free (priv->root_objects);
-
   G_OBJECT_CLASS (gtk_builder_parent_class)->finalize (object);
 }
 
@@ -406,7 +402,7 @@
       g_assert (obj != NULL);
       if (construct_parameters->len)
         g_warning ("Can't pass in construct-only parameters to %s", info->id);
-
+      g_object_ref (obj);
     }
   else if (info->parent && ((ChildInfo*)info->parent)->internal_child != NULL)
     {
@@ -414,6 +410,7 @@
       obj = gtk_builder_get_internal_child (builder, info, childname);
       if (construct_parameters->len)
         g_warning ("Can't pass in construct-only parameters to %s", childname);
+      g_object_ref (obj);
     }
   else
     {
@@ -421,6 +418,18 @@
                            construct_parameters->len,
                            (GParameter *)construct_parameters->data);
 
+      /* No matter what, make sure we have a reference.
+       *
+       * If it's an initially unowned object, sink it.
+       * If it's not initially unowned then we have the reference already.
+       *
+       * In the case that this is a window it will be sunk already and
+       * this is effectively a call to g_object_ref().  That's what
+       * we want.
+       */
+      if (G_IS_INITIALLY_UNOWNED (obj))
+        g_object_ref_sink (obj);
+
       GTK_NOTE (BUILDER,
                 g_print ("created %s of type %s\n", info->id, info->class_name));
 
@@ -472,15 +481,7 @@
                             g_strdup (info->id),
                             g_free);
 
-
-  if (!info->parent && !GTK_IS_WINDOW (obj))
-    {
-      if (g_object_is_floating (obj))
-	  g_object_ref_sink (obj);
-      
-      builder->priv->root_objects =
-        g_slist_prepend (builder->priv->root_objects, obj);
-    }
+  /* we already own a reference to obj.  put it in the hash table. */
   g_hash_table_insert (builder->priv->objects, g_strdup (info->id), obj);
   
   return obj;

Modified: branches/gtk-2-12/gtk/gtkuimanager.c
==============================================================================
--- branches/gtk-2-12/gtk/gtkuimanager.c	(original)
+++ branches/gtk-2-12/gtk/gtkuimanager.c	Thu Jan 10 10:20:49 2008
@@ -497,7 +497,7 @@
   g_signal_connect (widget, "hierarchy-changed",
 		    G_CALLBACK (child_hierarchy_changed_cb),
 		    GTK_UI_MANAGER (buildable));
-  return G_OBJECT (widget);
+  return g_object_ref (widget);
 }
 
 static void



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