box-layout: Support replacing layout manager

There is nothing preventing callers from replacing the internal
layout manager, and as long as the replacement is a (or derives
from) ClutterBoxLayout, everything should work fine except for
losing a bit of automatic property mapping - and the latter is
easily fixable by moving the setup out of the constructor.

https://bugzilla.gnome.org/show_bug.cgi?id=708472
This commit is contained in:
Florian Müllner 2015-10-04 03:06:34 +02:00
parent 207c847762
commit 508e751ffd

View File

@ -562,6 +562,24 @@ layout_notify (GObject *object,
g_object_notify (self, prop_name); g_object_notify (self, prop_name);
} }
static void
on_layout_manager_notify (GObject *object,
GParamSpec *pspec,
gpointer user_data)
{
ClutterActor *actor = CLUTTER_ACTOR (object);
ClutterLayoutManager *layout = clutter_actor_get_layout_manager (actor);
g_warn_if_fail (CLUTTER_IS_BOX_LAYOUT (layout));
if (layout == NULL)
return;
g_signal_connect_swapped (layout, "layout-changed",
G_CALLBACK (clutter_actor_queue_relayout), actor);
g_signal_connect (layout, "notify", G_CALLBACK (layout_notify), object);
}
static void static void
st_box_layout_class_init (StBoxLayoutClass *klass) st_box_layout_class_init (StBoxLayoutClass *klass)
{ {
@ -614,14 +632,11 @@ st_box_layout_class_init (StBoxLayoutClass *klass)
static void static void
st_box_layout_init (StBoxLayout *self) st_box_layout_init (StBoxLayout *self)
{ {
ClutterLayoutManager *layout;
self->priv = BOX_LAYOUT_PRIVATE (self); self->priv = BOX_LAYOUT_PRIVATE (self);
layout = clutter_box_layout_new ();
g_signal_connect_swapped (layout, "layout-changed", g_signal_connect (self, "notify::layout-manager",
G_CALLBACK (clutter_actor_queue_relayout), self); G_CALLBACK (on_layout_manager_notify), NULL);
g_signal_connect (layout, "notify", G_CALLBACK (layout_notify), self); clutter_actor_set_layout_manager (CLUTTER_ACTOR (self), clutter_box_layout_new ());
clutter_actor_set_layout_manager (CLUTTER_ACTOR (self), layout);
} }
/** /**