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.
This commit is contained in:
Matthias Clasen 2011-04-16 13:57:05 -04:00
parent c8c1075cfe
commit deb271d355
3 changed files with 73 additions and 27 deletions

View File

@ -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,

View File

@ -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:

View File

@ -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);
}
/**