[layout] Set a back pointer to Box inside the layout
authorEmmanuele Bassi <ebassi@linux.intel.com>
Wed, 16 Sep 2009 14:48:28 +0000 (15:48 +0100)
committerEmmanuele Bassi <ebassi@linux.intel.com>
Wed, 14 Oct 2009 10:31:29 +0000 (11:31 +0100)
Use the LayoutManager API to set a back pointer to the Box actor
inside the LayoutManager used by the box.

This also allows us to replace the LayoutManager on a Box, since
the LayoutManager will be able to replace all the metadata if
needed.

clutter/clutter-box.c
clutter/clutter-box.h
doc/reference/clutter/clutter-sections.txt

index 3c4bac8..f51070b 100644 (file)
@@ -289,17 +289,21 @@ on_layout_changed (ClutterLayoutManager *manager,
   clutter_actor_queue_relayout (self);
 }
 
-static void
+static inline void
 set_layout_manager (ClutterBox           *self,
                     ClutterLayoutManager *manager)
 {
   ClutterBoxPrivate *priv = self->priv;
 
+  if (priv->manager == manager)
+    return;
+
   if (priv->manager != NULL)
     {
       if (priv->changed_id != 0)
         g_signal_handler_disconnect (priv->manager, priv->changed_id);
 
+      clutter_layout_manager_set_container (priv->manager, NULL);
       g_object_unref (priv->manager);
 
       priv->manager = NULL;
@@ -309,11 +313,18 @@ set_layout_manager (ClutterBox           *self,
   if (manager != NULL)
     {
       priv->manager = g_object_ref_sink (manager);
+      clutter_layout_manager_set_container (manager,
+                                            CLUTTER_CONTAINER (self));
+
       priv->changed_id =
         g_signal_connect (priv->manager, "layout-changed",
                           G_CALLBACK (on_layout_changed),
                           self);
     }
+
+  clutter_actor_queue_relayout (CLUTTER_ACTOR (self));
+
+  g_object_notify (G_OBJECT (self), "layout-manager");
 }
 
 static void
@@ -391,7 +402,7 @@ clutter_box_class_init (ClutterBoxClass *klass)
                                "The layout manager used by the box",
                                CLUTTER_TYPE_LAYOUT_MANAGER,
                                CLUTTER_PARAM_READWRITE |
-                               G_PARAM_CONSTRUCT_ONLY);
+                               G_PARAM_CONSTRUCT);
   g_object_class_install_property (gobject_class,
                                    PROP_LAYOUT_MANAGER,
                                    pspec);
@@ -425,6 +436,28 @@ clutter_box_new (ClutterLayoutManager *manager)
 }
 
 /**
+ * clutter_box_set_layout_manager:
+ * @box: a #ClutterBox
+ * @manager: a #ClutterLayoutManager
+ *
+ * Sets the #ClutterLayoutManager for @box
+ *
+ * A #ClutterLayoutManager is a delegate object that controls the
+ * layout of the children of @box
+ *
+ * Since: 1.2
+ */
+void
+clutter_box_set_layout_manager (ClutterBox *box,
+                                ClutterLayoutManager *manager)
+{
+  g_return_if_fail (CLUTTER_IS_BOX (box));
+  g_return_if_fail (manager == NULL || CLUTTER_IS_LAYOUT_MANAGER (manager));
+
+  set_layout_manager (box, manager);
+}
+
+/**
  * clutter_box_get_layout_manager:
  * @box: a #ClutterBox
  *
index 9b8ad19..4e9ea12 100644 (file)
@@ -38,6 +38,8 @@ GType clutter_box_get_type (void) G_GNUC_CONST;
 
 ClutterActor *        clutter_box_new                (ClutterLayoutManager *manager);
 
+void                  clutter_box_set_layout_manager (ClutterBox           *box,
+                                                      ClutterLayoutManager *manger);
 ClutterLayoutManager *clutter_box_get_layout_manager (ClutterBox           *box);
 
 void                  clutter_box_pack               (ClutterBox           *box,
index 21d9c51..0b08233 100644 (file)
@@ -1806,6 +1806,7 @@ clutter_bin_layout_get_type
 ClutterBox
 ClutterBoxClass
 clutter_box_new
+clutter_box_set_layout_manager
 clutter_box_get_layout_manager
 clutter_box_pack
 clutter_box_packv