From 4e8d8bbc15f26e95adfd59469306b7098f9fd491 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 14 Sep 2009 11:28:34 +0100 Subject: [PATCH] [layout] Update Box * Use ::layout-changed to queue a relayout when the layout changes * Destroy the Box children when destroying the Box * Allow getting the layout manager from the Box --- clutter/clutter-box.c | 72 ++++++++++++++++++++++++++++++++++++++++--- clutter/clutter-box.h | 4 ++- 2 files changed, 70 insertions(+), 6 deletions(-) diff --git a/clutter/clutter-box.c b/clutter/clutter-box.c index f3c0648ab..394c78886 100644 --- a/clutter/clutter-box.c +++ b/clutter/clutter-box.c @@ -24,6 +24,8 @@ struct _ClutterBoxPrivate ClutterLayoutManager *manager; GList *children; + + guint changed_id; }; enum @@ -257,16 +259,58 @@ clutter_box_real_allocate (ClutterActor *actor, } static void -clutter_box_dispose (GObject *gobject) +clutter_box_destroy (ClutterActor *actor) { - ClutterBoxPrivate *priv = CLUTTER_BOX (gobject)->priv; + ClutterBoxPrivate *priv = CLUTTER_BOX (actor)->priv; + GList *l; + + for (l = priv->children; l != NULL; l = l->next) + clutter_actor_destroy (l->data); + + CLUTTER_ACTOR_CLASS (clutter_box_parent_class)->destroy (actor); +} + +static void +on_layout_changed (ClutterLayoutManager *manager, + ClutterActor *self) +{ + clutter_actor_queue_relayout (self); +} + +static void +set_layout_manager (ClutterBox *self, + ClutterLayoutManager *manager) +{ + ClutterBoxPrivate *priv = self->priv; if (priv->manager != NULL) { + if (priv->changed_id != 0) + g_signal_handler_disconnect (priv->manager, priv->changed_id); + g_object_unref (priv->manager); + priv->manager = NULL; + priv->changed_id = 0; } + if (manager != NULL) + { + priv->manager = g_object_ref_sink (manager); + priv->changed_id = + g_signal_connect (priv->manager, "layout-changed", + G_CALLBACK (on_layout_changed), + self); + } +} + +static void +clutter_box_dispose (GObject *gobject) +{ + ClutterBox *self = CLUTTER_BOX (gobject); + + set_layout_manager (self, NULL); + G_OBJECT_CLASS (clutter_box_parent_class)->dispose (gobject); } @@ -276,13 +320,12 @@ clutter_box_set_property (GObject *gobject, const GValue *value, GParamSpec *pspec) { - ClutterBoxPrivate *priv = CLUTTER_BOX (gobject)->priv; + ClutterBox *self = CLUTTER_BOX (gobject); switch (prop_id) { case PROP_LAYOUT_MANAGER: - priv->manager = g_value_get_object (value); - g_object_ref_sink (priv->manager); + set_layout_manager (self, g_value_get_object (value)); break; default: @@ -325,6 +368,7 @@ clutter_box_class_init (ClutterBoxClass *klass) actor_class->allocate = clutter_box_real_allocate; actor_class->paint = clutter_box_real_paint; actor_class->pick = clutter_box_real_pick; + actor_class->destroy = clutter_box_destroy; gobject_class->set_property = clutter_box_set_property; gobject_class->get_property = clutter_box_get_property; @@ -367,3 +411,21 @@ clutter_box_new (ClutterLayoutManager *manager) "layout-manager", manager, NULL); } + +/** + * clutter_box_get_layout_manager: + * @box: a #ClutterBox + * + * Retrieves the #ClutterLayoutManager instance used by @box + * + * Return value: a #ClutterLayoutManager + * + * Since: 1.2 + */ +ClutterLayoutManager * +clutter_box_get_layout_manager (ClutterBox *box) +{ + g_return_val_if_fail (CLUTTER_IS_BOX (box), NULL); + + return box->priv->manager; +} diff --git a/clutter/clutter-box.h b/clutter/clutter-box.h index 6793ee265..40d359c89 100644 --- a/clutter/clutter-box.h +++ b/clutter/clutter-box.h @@ -36,7 +36,9 @@ struct _ClutterBoxClass GType clutter_box_get_type (void) G_GNUC_CONST; -ClutterActor *clutter_box_new (ClutterLayoutManager *manager); +ClutterActor * clutter_box_new (ClutterLayoutManager *manager); + +ClutterLayoutManager *clutter_box_get_layout_manager (ClutterBox *box); G_END_DECLS