[gtk+] Add gtk_container_child_notify



commit deb271d35519124509103ccc4c217bb31bf4fe65
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Apr 16 13:57:05 2011 -0400

    Add gtk_container_child_notify
    
    This is a variant of gtk_widget_child_notify() that takes an
    explicit container, instead of relying on widget->parent to
    be the correct container to use.

 gtk/gtkcontainer.c |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkcontainer.h |    6 ++++-
 gtk/gtkwidget.c    |   32 +++++---------------------
 3 files changed, 73 insertions(+), 27 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 2a1438a..4b6c584 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -764,6 +764,68 @@ gtk_container_child_type (GtkContainer *container)
 }
 
 /* --- GtkContainer child property mechanism --- */
+
+/**
+ * gtk_container_child_notify:
+ * @container: the #GtkContainer
+ * @widget: the child widget
+ * @child_property: the name of a chld property installed on
+ *     the class of @container
+ *
+ * Emits a #GtkWidget::child-notify signal for the
+ * <link linkend="child-properties">child property</link>
+ * @child_property on widget.
+ *
+ * This is an analogue of g_object_notify() for child properties.
+ *
+ * Also see gtk_widget_child_notify().
+ *
+ * Since: 3.2
+ */
+void
+gtk_container_child_notify (GtkContainer *container,
+                            GtkWidget    *widget,
+                            const gchar  *child_property)
+{
+  GObject *obj;
+  GParamSpec *pspec;
+
+  g_return_if_fail (GTK_IS_CONTAINER (container));
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (child_property != NULL);
+
+  obj = G_OBJECT (widget);
+
+  if (obj->ref_count == 0)
+    return;
+
+  g_object_ref (obj);
+
+  pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
+                                    child_property,
+                                    G_OBJECT_TYPE (container),
+                                    TRUE);
+
+  if (pspec == NULL)
+    {
+      g_warning ("%s: container class `%s' has no child property named `%s'",
+                 G_STRLOC,
+                 G_OBJECT_TYPE_NAME (container),
+                 child_property);
+    }
+  else
+    {
+      GObjectNotifyQueue *nqueue;
+
+      nqueue = g_object_notify_queue_freeze (obj, _gtk_widget_child_property_notify_context);
+
+      g_object_notify_queue_add (obj, nqueue, pspec);
+      g_object_notify_queue_thaw (obj, nqueue);
+    }
+
+  g_object_unref (obj);
+}
+
 static inline void
 container_get_child_property (GtkContainer *container,
                               GtkWidget    *child,
diff --git a/gtk/gtkcontainer.h b/gtk/gtkcontainer.h
index b21e2d8..a19d90f 100644
--- a/gtk/gtkcontainer.h
+++ b/gtk/gtkcontainer.h
@@ -195,7 +195,11 @@ void	     gtk_container_child_set_property		(GtkContainer	   *container,
 void	     gtk_container_child_get_property		(GtkContainer	   *container,
 							 GtkWidget	   *child,
 							 const gchar	   *property_name,
-							 GValue		   *value);
+	                                                 GValue		   *value);
+
+void gtk_container_child_notify (GtkContainer *container,
+                                 GtkWidget    *child,
+                                 const gchar  *property_name);
 
 /**
  * GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID:
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 575c959..db2b824 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -3587,37 +3587,17 @@ gtk_widget_freeze_child_notify (GtkWidget *widget)
  * on @widget.
  *
  * This is the analogue of g_object_notify() for child properties.
- **/
+ *
+ * Also see gtk_container_child_notify().
+ */
 void
 gtk_widget_child_notify (GtkWidget    *widget,
-			 const gchar  *child_property)
+                         const gchar  *child_property)
 {
-  GtkWidgetPrivate *priv = widget->priv;
-  GParamSpec *pspec;
-
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-  g_return_if_fail (child_property != NULL);
-  if (!G_OBJECT (widget)->ref_count || !priv->parent)
+  if (widget->priv->parent == NULL)
     return;
 
-  g_object_ref (widget);
-  pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
-				    child_property,
-				    G_OBJECT_TYPE (priv->parent),
-				    TRUE);
-  if (!pspec)
-    g_warning ("%s: container class `%s' has no child property named `%s'",
-	       G_STRLOC,
-	       G_OBJECT_TYPE_NAME (priv->parent),
-	       child_property);
-  else
-    {
-      GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
-
-      g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
-      g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
-    }
-  g_object_unref (widget);
+  gtk_container_child_notify (GTK_CONTAINER (widget->priv->parent), widget, child_property);
 }
 
 /**



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