[layout] Set a back pointer to Box inside the layout

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.
This commit is contained in:
Emmanuele Bassi 2009-09-16 15:48:28 +01:00
parent 22bb243ec2
commit 755896664f
3 changed files with 38 additions and 2 deletions

View File

@ -289,17 +289,21 @@ on_layout_changed (ClutterLayoutManager *manager,
clutter_actor_queue_relayout (self); clutter_actor_queue_relayout (self);
} }
static void static inline void
set_layout_manager (ClutterBox *self, set_layout_manager (ClutterBox *self,
ClutterLayoutManager *manager) ClutterLayoutManager *manager)
{ {
ClutterBoxPrivate *priv = self->priv; ClutterBoxPrivate *priv = self->priv;
if (priv->manager == manager)
return;
if (priv->manager != NULL) if (priv->manager != NULL)
{ {
if (priv->changed_id != 0) if (priv->changed_id != 0)
g_signal_handler_disconnect (priv->manager, priv->changed_id); g_signal_handler_disconnect (priv->manager, priv->changed_id);
clutter_layout_manager_set_container (priv->manager, NULL);
g_object_unref (priv->manager); g_object_unref (priv->manager);
priv->manager = NULL; priv->manager = NULL;
@ -309,11 +313,18 @@ set_layout_manager (ClutterBox *self,
if (manager != NULL) if (manager != NULL)
{ {
priv->manager = g_object_ref_sink (manager); priv->manager = g_object_ref_sink (manager);
clutter_layout_manager_set_container (manager,
CLUTTER_CONTAINER (self));
priv->changed_id = priv->changed_id =
g_signal_connect (priv->manager, "layout-changed", g_signal_connect (priv->manager, "layout-changed",
G_CALLBACK (on_layout_changed), G_CALLBACK (on_layout_changed),
self); self);
} }
clutter_actor_queue_relayout (CLUTTER_ACTOR (self));
g_object_notify (G_OBJECT (self), "layout-manager");
} }
static void static void
@ -391,7 +402,7 @@ clutter_box_class_init (ClutterBoxClass *klass)
"The layout manager used by the box", "The layout manager used by the box",
CLUTTER_TYPE_LAYOUT_MANAGER, CLUTTER_TYPE_LAYOUT_MANAGER,
CLUTTER_PARAM_READWRITE | CLUTTER_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY); G_PARAM_CONSTRUCT);
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_LAYOUT_MANAGER, PROP_LAYOUT_MANAGER,
pspec); pspec);
@ -424,6 +435,28 @@ clutter_box_new (ClutterLayoutManager *manager)
NULL); NULL);
} }
/**
* 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: * clutter_box_get_layout_manager:
* @box: a #ClutterBox * @box: a #ClutterBox

View File

@ -38,6 +38,8 @@ GType clutter_box_get_type (void) G_GNUC_CONST;
ClutterActor * clutter_box_new (ClutterLayoutManager *manager); ClutterActor * clutter_box_new (ClutterLayoutManager *manager);
void clutter_box_set_layout_manager (ClutterBox *box,
ClutterLayoutManager *manger);
ClutterLayoutManager *clutter_box_get_layout_manager (ClutterBox *box); ClutterLayoutManager *clutter_box_get_layout_manager (ClutterBox *box);
void clutter_box_pack (ClutterBox *box, void clutter_box_pack (ClutterBox *box,

View File

@ -1806,6 +1806,7 @@ clutter_bin_layout_get_type
ClutterBox ClutterBox
ClutterBoxClass ClutterBoxClass
clutter_box_new clutter_box_new
clutter_box_set_layout_manager
clutter_box_get_layout_manager clutter_box_get_layout_manager
clutter_box_pack clutter_box_pack
clutter_box_packv clutter_box_packv