[St] share common ClutterContainer implementation code
https://bugzilla.gnome.org/show_bug.cgi?id=611647
This commit is contained in:
parent
fbb88da134
commit
f6b4fa6e7e
@ -256,13 +256,7 @@ st_box_container_add_actor (ClutterContainer *container,
|
|||||||
{
|
{
|
||||||
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (container)->priv;
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (container)->priv;
|
||||||
|
|
||||||
clutter_actor_set_parent (actor, CLUTTER_ACTOR (container));
|
_st_container_add_actor (container, actor, &priv->children);
|
||||||
|
|
||||||
priv->children = g_list_append (priv->children, actor);
|
|
||||||
|
|
||||||
clutter_actor_queue_relayout (CLUTTER_ACTOR (container));
|
|
||||||
|
|
||||||
g_signal_emit_by_name (container, "actor-added", actor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -271,28 +265,7 @@ st_box_container_remove_actor (ClutterContainer *container,
|
|||||||
{
|
{
|
||||||
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (container)->priv;
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (container)->priv;
|
||||||
|
|
||||||
GList *item = NULL;
|
_st_container_remove_actor (container, actor, &priv->children);
|
||||||
|
|
||||||
item = g_list_find (priv->children, actor);
|
|
||||||
|
|
||||||
if (item == NULL)
|
|
||||||
{
|
|
||||||
g_warning ("Actor of type '%s' is not a child of container of type '%s'",
|
|
||||||
g_type_name (G_OBJECT_TYPE (actor)),
|
|
||||||
g_type_name (G_OBJECT_TYPE (container)));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_object_ref (actor);
|
|
||||||
|
|
||||||
priv->children = g_list_delete_link (priv->children, item);
|
|
||||||
clutter_actor_unparent (actor);
|
|
||||||
|
|
||||||
g_signal_emit_by_name (container, "actor-removed", actor);
|
|
||||||
|
|
||||||
g_object_unref (actor);
|
|
||||||
|
|
||||||
clutter_actor_queue_relayout ((ClutterActor*) container);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -302,7 +275,8 @@ st_box_container_foreach (ClutterContainer *container,
|
|||||||
{
|
{
|
||||||
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (container)->priv;
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (container)->priv;
|
||||||
|
|
||||||
g_list_foreach (priv->children, (GFunc) callback, callback_data);
|
_st_container_foreach (container, callback, callback_data,
|
||||||
|
&priv->children);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -312,40 +286,7 @@ st_box_container_lower (ClutterContainer *container,
|
|||||||
{
|
{
|
||||||
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (container)->priv;
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (container)->priv;
|
||||||
|
|
||||||
/* copied from clutter/clutter/clutter-group.c */
|
_st_container_lower (container, actor, sibling, &priv->children);
|
||||||
|
|
||||||
priv->children = g_list_remove (priv->children, actor);
|
|
||||||
|
|
||||||
/* Push to bottom */
|
|
||||||
if (!sibling)
|
|
||||||
{
|
|
||||||
GList *last_item;
|
|
||||||
|
|
||||||
last_item = g_list_first (priv->children);
|
|
||||||
|
|
||||||
if (last_item)
|
|
||||||
sibling = last_item->data;
|
|
||||||
|
|
||||||
priv->children = g_list_prepend (priv->children, actor);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gint pos;
|
|
||||||
|
|
||||||
pos = g_list_index (priv->children, sibling);
|
|
||||||
|
|
||||||
priv->children = g_list_insert (priv->children, actor, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* See comment in group_raise for this */
|
|
||||||
if (sibling &&
|
|
||||||
clutter_actor_get_depth (sibling) != clutter_actor_get_depth (actor))
|
|
||||||
{
|
|
||||||
clutter_actor_set_depth (actor, clutter_actor_get_depth (sibling));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CLUTTER_ACTOR_IS_VISIBLE (container))
|
|
||||||
clutter_actor_queue_redraw (CLUTTER_ACTOR (container));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -355,52 +296,15 @@ st_box_container_raise (ClutterContainer *container,
|
|||||||
{
|
{
|
||||||
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (container)->priv;
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (container)->priv;
|
||||||
|
|
||||||
priv->children = g_list_remove (priv->children, actor);
|
_st_container_raise (container, actor, sibling, &priv->children);
|
||||||
|
|
||||||
/* copied from clutter/clutter/clutter-group.c */
|
|
||||||
|
|
||||||
/* Raise at the top */
|
|
||||||
if (!sibling)
|
|
||||||
{
|
|
||||||
GList *last_item;
|
|
||||||
|
|
||||||
last_item = g_list_last (priv->children);
|
|
||||||
|
|
||||||
if (last_item)
|
|
||||||
sibling = last_item->data;
|
|
||||||
|
|
||||||
priv->children = g_list_append (priv->children, actor);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gint pos;
|
|
||||||
|
|
||||||
pos = g_list_index (priv->children, sibling) + 1;
|
|
||||||
|
|
||||||
priv->children = g_list_insert (priv->children, actor, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set Z ordering a value below, this will then call sort
|
|
||||||
* as values are equal ordering shouldn't change but Z
|
|
||||||
* values will be correct.
|
|
||||||
*
|
|
||||||
* FIXME: optimise
|
|
||||||
*/
|
|
||||||
if (sibling &&
|
|
||||||
clutter_actor_get_depth (sibling) != clutter_actor_get_depth (actor))
|
|
||||||
{
|
|
||||||
clutter_actor_set_depth (actor, clutter_actor_get_depth (sibling));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CLUTTER_ACTOR_IS_VISIBLE (container))
|
|
||||||
clutter_actor_queue_redraw (CLUTTER_ACTOR (container));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
st_box_container_sort_depth_order (ClutterContainer *container)
|
st_box_container_sort_depth_order (ClutterContainer *container)
|
||||||
{
|
{
|
||||||
/* XXX: not yet implemented */
|
StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (container)->priv;
|
||||||
g_warning ("%s() not yet implemented", __FUNCTION__);
|
|
||||||
|
_st_container_sort_depth_order (container, &priv->children);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -74,13 +74,7 @@ st_overflow_box_add_actor (ClutterContainer *container,
|
|||||||
{
|
{
|
||||||
StOverflowBoxPrivate *priv = ST_OVERFLOW_BOX (container)->priv;
|
StOverflowBoxPrivate *priv = ST_OVERFLOW_BOX (container)->priv;
|
||||||
|
|
||||||
clutter_actor_set_parent (actor, CLUTTER_ACTOR (container));
|
_st_container_add_actor (container, actor, &priv->children);
|
||||||
|
|
||||||
priv->children = g_list_append (priv->children, actor);
|
|
||||||
|
|
||||||
clutter_actor_queue_relayout (CLUTTER_ACTOR (container));
|
|
||||||
|
|
||||||
g_signal_emit_by_name (container, "actor-added", actor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -89,28 +83,7 @@ st_overflow_box_remove_actor (ClutterContainer *container,
|
|||||||
{
|
{
|
||||||
StOverflowBoxPrivate *priv = ST_OVERFLOW_BOX (container)->priv;
|
StOverflowBoxPrivate *priv = ST_OVERFLOW_BOX (container)->priv;
|
||||||
|
|
||||||
GList *item = NULL;
|
_st_container_remove_actor (container, actor, &priv->children);
|
||||||
|
|
||||||
item = g_list_find (priv->children, actor);
|
|
||||||
|
|
||||||
if (item == NULL)
|
|
||||||
{
|
|
||||||
g_warning ("Actor of type '%s' is not a child of container of type '%s'",
|
|
||||||
g_type_name (G_OBJECT_TYPE (actor)),
|
|
||||||
g_type_name (G_OBJECT_TYPE (container)));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_object_ref (actor);
|
|
||||||
|
|
||||||
priv->children = g_list_delete_link (priv->children, item);
|
|
||||||
clutter_actor_unparent (actor);
|
|
||||||
|
|
||||||
g_signal_emit_by_name (container, "actor-removed", actor);
|
|
||||||
|
|
||||||
g_object_unref (actor);
|
|
||||||
|
|
||||||
clutter_actor_queue_relayout ((ClutterActor*) container);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -120,7 +93,8 @@ st_overflow_box_foreach (ClutterContainer *container,
|
|||||||
{
|
{
|
||||||
StOverflowBoxPrivate *priv = ST_OVERFLOW_BOX (container)->priv;
|
StOverflowBoxPrivate *priv = ST_OVERFLOW_BOX (container)->priv;
|
||||||
|
|
||||||
g_list_foreach (priv->children, (GFunc) callback, callback_data);
|
_st_container_foreach (container, callback, callback_data,
|
||||||
|
&priv->children);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -130,40 +104,7 @@ st_overflow_box_lower (ClutterContainer *container,
|
|||||||
{
|
{
|
||||||
StOverflowBoxPrivate *priv = ST_OVERFLOW_BOX (container)->priv;
|
StOverflowBoxPrivate *priv = ST_OVERFLOW_BOX (container)->priv;
|
||||||
|
|
||||||
/* copied from clutter/clutter/clutter-group.c */
|
_st_container_lower (container, actor, sibling, &priv->children);
|
||||||
|
|
||||||
priv->children = g_list_remove (priv->children, actor);
|
|
||||||
|
|
||||||
/* Push to bottom */
|
|
||||||
if (!sibling)
|
|
||||||
{
|
|
||||||
GList *last_item;
|
|
||||||
|
|
||||||
last_item = g_list_first (priv->children);
|
|
||||||
|
|
||||||
if (last_item)
|
|
||||||
sibling = last_item->data;
|
|
||||||
|
|
||||||
priv->children = g_list_prepend (priv->children, actor);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gint pos;
|
|
||||||
|
|
||||||
pos = g_list_index (priv->children, sibling);
|
|
||||||
|
|
||||||
priv->children = g_list_insert (priv->children, actor, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* See comment in group_raise for this */
|
|
||||||
if (sibling &&
|
|
||||||
clutter_actor_get_depth (sibling) != clutter_actor_get_depth (actor))
|
|
||||||
{
|
|
||||||
clutter_actor_set_depth (actor, clutter_actor_get_depth (sibling));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CLUTTER_ACTOR_IS_VISIBLE (container))
|
|
||||||
clutter_actor_queue_redraw (CLUTTER_ACTOR (container));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -173,52 +114,15 @@ st_overflow_box_raise (ClutterContainer *container,
|
|||||||
{
|
{
|
||||||
StOverflowBoxPrivate *priv = ST_OVERFLOW_BOX (container)->priv;
|
StOverflowBoxPrivate *priv = ST_OVERFLOW_BOX (container)->priv;
|
||||||
|
|
||||||
priv->children = g_list_remove (priv->children, actor);
|
_st_container_raise (container, actor, sibling, &priv->children);
|
||||||
|
|
||||||
/* copied from clutter/clutter/clutter-group.c */
|
|
||||||
|
|
||||||
/* Raise at the top */
|
|
||||||
if (!sibling)
|
|
||||||
{
|
|
||||||
GList *last_item;
|
|
||||||
|
|
||||||
last_item = g_list_last (priv->children);
|
|
||||||
|
|
||||||
if (last_item)
|
|
||||||
sibling = last_item->data;
|
|
||||||
|
|
||||||
priv->children = g_list_append (priv->children, actor);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gint pos;
|
|
||||||
|
|
||||||
pos = g_list_index (priv->children, sibling) + 1;
|
|
||||||
|
|
||||||
priv->children = g_list_insert (priv->children, actor, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set Z ordering a value below, this will then call sort
|
|
||||||
* as values are equal ordering shouldn't change but Z
|
|
||||||
* values will be correct.
|
|
||||||
*
|
|
||||||
* FIXME: optimise
|
|
||||||
*/
|
|
||||||
if (sibling &&
|
|
||||||
clutter_actor_get_depth (sibling) != clutter_actor_get_depth (actor))
|
|
||||||
{
|
|
||||||
clutter_actor_set_depth (actor, clutter_actor_get_depth (sibling));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CLUTTER_ACTOR_IS_VISIBLE (container))
|
|
||||||
clutter_actor_queue_redraw (CLUTTER_ACTOR (container));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
st_overflow_box_sort_depth_order (ClutterContainer *container)
|
st_overflow_box_sort_depth_order (ClutterContainer *container)
|
||||||
{
|
{
|
||||||
/* XXX: not yet implemented */
|
StOverflowBoxPrivate *priv = ST_OVERFLOW_BOX (container)->priv;
|
||||||
g_warning ("%s() not yet implemented", __FUNCTION__);
|
|
||||||
|
_st_container_sort_depth_order (container, &priv->children);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -310,3 +310,231 @@ _st_set_text_from_style (ClutterText *text,
|
|||||||
|
|
||||||
pango_attr_list_unref (attribs);
|
pango_attr_list_unref (attribs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _st_container_add_actor:
|
||||||
|
* @container: a #ClutterContainer
|
||||||
|
* @actor: a #ClutterActor
|
||||||
|
* @children: pointer to @container's list of children
|
||||||
|
*
|
||||||
|
* A basic implementation for clutter_container_add_actor().
|
||||||
|
* Mostly copied from clutter_group_real_add().
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
_st_container_add_actor (ClutterContainer *container,
|
||||||
|
ClutterActor *actor,
|
||||||
|
GList **children)
|
||||||
|
{
|
||||||
|
g_object_ref (actor);
|
||||||
|
|
||||||
|
*children = g_list_append (*children, actor);
|
||||||
|
clutter_actor_set_parent (actor, CLUTTER_ACTOR (container));
|
||||||
|
|
||||||
|
/* queue a relayout, to get the correct positioning inside
|
||||||
|
* the ::actor-added signal handlers
|
||||||
|
*/
|
||||||
|
clutter_actor_queue_relayout (CLUTTER_ACTOR (container));
|
||||||
|
|
||||||
|
g_signal_emit_by_name (container, "actor-added", actor);
|
||||||
|
|
||||||
|
clutter_container_sort_depth_order (container);
|
||||||
|
|
||||||
|
g_object_unref (actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _st_container_remove_actor:
|
||||||
|
* @container: a #ClutterContainer
|
||||||
|
* @actor: a #ClutterActor
|
||||||
|
* @children: pointer to @container's list of children
|
||||||
|
*
|
||||||
|
* A basic implementation for clutter_container_remove_actor().
|
||||||
|
* Mostly copied from clutter_group_real_remove().
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
_st_container_remove_actor (ClutterContainer *container,
|
||||||
|
ClutterActor *actor,
|
||||||
|
GList **children)
|
||||||
|
{
|
||||||
|
g_object_ref (actor);
|
||||||
|
|
||||||
|
*children = g_list_remove (*children, actor);
|
||||||
|
clutter_actor_unparent (actor);
|
||||||
|
|
||||||
|
/* queue a relayout, to get the correct positioning inside
|
||||||
|
* the ::actor-removed signal handlers
|
||||||
|
*/
|
||||||
|
clutter_actor_queue_relayout (CLUTTER_ACTOR (container));
|
||||||
|
|
||||||
|
/* at this point, the actor passed to the "actor-removed" signal
|
||||||
|
* handlers is not parented anymore to the container but since we
|
||||||
|
* are holding a reference on it, it's still valid
|
||||||
|
*/
|
||||||
|
g_signal_emit_by_name (container, "actor-removed", actor);
|
||||||
|
|
||||||
|
if (CLUTTER_ACTOR_IS_VISIBLE (container))
|
||||||
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (container));
|
||||||
|
|
||||||
|
g_object_unref (actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _st_container_raise:
|
||||||
|
* @container: a #ClutterContainer
|
||||||
|
* @callback: callback
|
||||||
|
* @user_data: data for @callback
|
||||||
|
* @children: pointer to @container's list of children
|
||||||
|
*
|
||||||
|
* A basic implementation for clutter_container_foreach().
|
||||||
|
* Mostly copied from clutter_group_real_foreach().
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
_st_container_foreach (ClutterContainer *container,
|
||||||
|
ClutterCallback callback,
|
||||||
|
gpointer user_data,
|
||||||
|
GList **children)
|
||||||
|
{
|
||||||
|
GList *l;
|
||||||
|
|
||||||
|
for (l = *children; l; l = l->next)
|
||||||
|
(* callback) (CLUTTER_ACTOR (l->data), user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _st_container_raise:
|
||||||
|
* @container: a #ClutterContainer
|
||||||
|
* @actor: a #ClutterActor to raise
|
||||||
|
* @sibling: the sibling to raise to, or %NULL to put on top
|
||||||
|
* @children: pointer to @container's list of children
|
||||||
|
*
|
||||||
|
* A basic implementation for clutter_container_raise().
|
||||||
|
* Mostly copied from clutter_group_real_raise().
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
_st_container_raise (ClutterContainer *container,
|
||||||
|
ClutterActor *actor,
|
||||||
|
ClutterActor *sibling,
|
||||||
|
GList **children)
|
||||||
|
{
|
||||||
|
*children = g_list_remove (*children, actor);
|
||||||
|
|
||||||
|
/* Raise at the top */
|
||||||
|
if (!sibling)
|
||||||
|
{
|
||||||
|
GList *last_item;
|
||||||
|
|
||||||
|
last_item = g_list_last (*children);
|
||||||
|
|
||||||
|
if (last_item)
|
||||||
|
sibling = last_item->data;
|
||||||
|
|
||||||
|
*children = g_list_append (*children, actor);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gint pos;
|
||||||
|
|
||||||
|
pos = g_list_index (*children, sibling) + 1;
|
||||||
|
|
||||||
|
*children = g_list_insert (*children, actor, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set Z ordering a value below, this will then call sort
|
||||||
|
* as values are equal ordering shouldn't change but Z
|
||||||
|
* values will be correct.
|
||||||
|
*
|
||||||
|
* FIXME: optimise
|
||||||
|
*/
|
||||||
|
if (sibling &&
|
||||||
|
clutter_actor_get_depth (sibling) != clutter_actor_get_depth (actor))
|
||||||
|
{
|
||||||
|
clutter_actor_set_depth (actor, clutter_actor_get_depth (sibling));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CLUTTER_ACTOR_IS_VISIBLE (container))
|
||||||
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (container));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _st_container_lower:
|
||||||
|
* @container: a #ClutterContainer
|
||||||
|
* @actor: a #ClutterActor to lower
|
||||||
|
* @sibling: the sibling to lower to, or %NULL to put on bottom
|
||||||
|
* @children: pointer to @container's list of children
|
||||||
|
*
|
||||||
|
* A basic implementation for clutter_container_lower().
|
||||||
|
* Mostly copied from clutter_group_real_lower().
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
_st_container_lower (ClutterContainer *container,
|
||||||
|
ClutterActor *actor,
|
||||||
|
ClutterActor *sibling,
|
||||||
|
GList **children)
|
||||||
|
{
|
||||||
|
*children = g_list_remove (*children, actor);
|
||||||
|
|
||||||
|
/* Push to bottom */
|
||||||
|
if (!sibling)
|
||||||
|
{
|
||||||
|
GList *last_item;
|
||||||
|
|
||||||
|
last_item = g_list_first (*children);
|
||||||
|
|
||||||
|
if (last_item)
|
||||||
|
sibling = last_item->data;
|
||||||
|
|
||||||
|
*children = g_list_prepend (*children, actor);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gint pos;
|
||||||
|
|
||||||
|
pos = g_list_index (*children, sibling);
|
||||||
|
|
||||||
|
*children = g_list_insert (*children, actor, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* See comment in _st_container_raise() for this */
|
||||||
|
if (sibling &&
|
||||||
|
clutter_actor_get_depth (sibling) != clutter_actor_get_depth (actor))
|
||||||
|
{
|
||||||
|
clutter_actor_set_depth (actor, clutter_actor_get_depth (sibling));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CLUTTER_ACTOR_IS_VISIBLE (container))
|
||||||
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (container));
|
||||||
|
}
|
||||||
|
|
||||||
|
static gint
|
||||||
|
sort_z_order (gconstpointer a,
|
||||||
|
gconstpointer b)
|
||||||
|
{
|
||||||
|
float depth_a, depth_b;
|
||||||
|
|
||||||
|
depth_a = clutter_actor_get_depth (CLUTTER_ACTOR (a));
|
||||||
|
depth_b = clutter_actor_get_depth (CLUTTER_ACTOR (b));
|
||||||
|
|
||||||
|
if (depth_a < depth_b)
|
||||||
|
return -1;
|
||||||
|
if (depth_a > depth_b)
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* _st_container_sort_depth_order:
|
||||||
|
* @container: a #ClutterContainer
|
||||||
|
* @children: pointer to @container's list of children
|
||||||
|
*
|
||||||
|
* A basic implementation for clutter_container_sort_depth_order().
|
||||||
|
* Mostly copied from clutter_group_real_sort_depth_order().
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
_st_container_sort_depth_order (ClutterContainer *container,
|
||||||
|
GList **children)
|
||||||
|
{
|
||||||
|
*children = g_list_sort (*children, sort_z_order);
|
||||||
|
|
||||||
|
if (CLUTTER_ACTOR_IS_VISIBLE (container))
|
||||||
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (container));
|
||||||
|
}
|
||||||
|
@ -72,4 +72,25 @@ void _st_allocate_fill (StWidget *parent,
|
|||||||
void _st_set_text_from_style (ClutterText *text,
|
void _st_set_text_from_style (ClutterText *text,
|
||||||
StThemeNode *theme_node);
|
StThemeNode *theme_node);
|
||||||
|
|
||||||
|
void _st_container_add_actor (ClutterContainer *container,
|
||||||
|
ClutterActor *actor,
|
||||||
|
GList **children);
|
||||||
|
void _st_container_remove_actor (ClutterContainer *container,
|
||||||
|
ClutterActor *actor,
|
||||||
|
GList **children);
|
||||||
|
void _st_container_foreach (ClutterContainer *container,
|
||||||
|
ClutterCallback callback,
|
||||||
|
gpointer user_data,
|
||||||
|
GList **children);
|
||||||
|
void _st_container_raise (ClutterContainer *container,
|
||||||
|
ClutterActor *actor,
|
||||||
|
ClutterActor *sibling,
|
||||||
|
GList **children);
|
||||||
|
void _st_container_lower (ClutterContainer *container,
|
||||||
|
ClutterActor *actor,
|
||||||
|
ClutterActor *sibling,
|
||||||
|
GList **children);
|
||||||
|
void _st_container_sort_depth_order (ClutterContainer *container,
|
||||||
|
GList **children);
|
||||||
|
|
||||||
#endif /* __ST_PRIVATE_H__ */
|
#endif /* __ST_PRIVATE_H__ */
|
||||||
|
@ -64,7 +64,7 @@ enum
|
|||||||
|
|
||||||
struct _StTablePrivate
|
struct _StTablePrivate
|
||||||
{
|
{
|
||||||
GSList *children;
|
GList *children;
|
||||||
|
|
||||||
gint col_spacing;
|
gint col_spacing;
|
||||||
gint row_spacing;
|
gint row_spacing;
|
||||||
@ -89,11 +89,11 @@ struct _StTablePrivate
|
|||||||
guint homogeneous : 1;
|
guint homogeneous : 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void st_container_iface_init (ClutterContainerIface *iface);
|
static void st_table_container_iface_init (ClutterContainerIface *iface);
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_CODE (StTable, st_table, ST_TYPE_WIDGET,
|
G_DEFINE_TYPE_WITH_CODE (StTable, st_table, ST_TYPE_WIDGET,
|
||||||
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER,
|
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER,
|
||||||
st_container_iface_init));
|
st_table_container_iface_init));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -101,95 +101,72 @@ G_DEFINE_TYPE_WITH_CODE (StTable, st_table, ST_TYPE_WIDGET,
|
|||||||
* ClutterContainer Implementation
|
* ClutterContainer Implementation
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
st_container_add_actor (ClutterContainer *container,
|
st_table_add_actor (ClutterContainer *container,
|
||||||
ClutterActor *actor)
|
ClutterActor *actor)
|
||||||
{
|
{
|
||||||
StTablePrivate *priv = ST_TABLE (container)->priv;
|
StTablePrivate *priv = ST_TABLE (container)->priv;
|
||||||
|
|
||||||
clutter_actor_set_parent (actor, CLUTTER_ACTOR (container));
|
_st_container_add_actor (container, actor, &priv->children);
|
||||||
|
|
||||||
|
|
||||||
priv->children = g_slist_append (priv->children, actor);
|
|
||||||
|
|
||||||
clutter_actor_queue_relayout (CLUTTER_ACTOR (container));
|
|
||||||
|
|
||||||
g_signal_emit_by_name (container, "actor-added", actor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
st_container_remove_actor (ClutterContainer *container,
|
st_table_remove_actor (ClutterContainer *container,
|
||||||
ClutterActor *actor)
|
ClutterActor *actor)
|
||||||
{
|
{
|
||||||
StTablePrivate *priv = ST_TABLE (container)->priv;
|
StTablePrivate *priv = ST_TABLE (container)->priv;
|
||||||
|
|
||||||
GSList *item = NULL;
|
_st_container_remove_actor (container, actor, &priv->children);
|
||||||
|
|
||||||
item = g_slist_find (priv->children, actor);
|
|
||||||
|
|
||||||
if (item == NULL)
|
|
||||||
{
|
|
||||||
g_warning ("Widget of type '%s' is not a child of container of type '%s'",
|
|
||||||
g_type_name (G_OBJECT_TYPE (actor)),
|
|
||||||
g_type_name (G_OBJECT_TYPE (container)));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_object_ref (actor);
|
|
||||||
|
|
||||||
priv->children = g_slist_delete_link (priv->children, item);
|
|
||||||
clutter_actor_unparent (actor);
|
|
||||||
|
|
||||||
clutter_actor_queue_relayout (CLUTTER_ACTOR (container));
|
|
||||||
|
|
||||||
g_signal_emit_by_name (container, "actor-removed", actor);
|
|
||||||
|
|
||||||
g_object_unref (actor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
st_container_foreach (ClutterContainer *container,
|
st_table_foreach (ClutterContainer *container,
|
||||||
ClutterCallback callback,
|
ClutterCallback callback,
|
||||||
gpointer callback_data)
|
gpointer callback_data)
|
||||||
{
|
{
|
||||||
StTablePrivate *priv = ST_TABLE (container)->priv;
|
StTablePrivate *priv = ST_TABLE (container)->priv;
|
||||||
|
|
||||||
g_slist_foreach (priv->children, (GFunc) callback, callback_data);
|
_st_container_foreach (container, callback, callback_data,
|
||||||
|
&priv->children);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
st_container_lower (ClutterContainer *container,
|
st_table_lower (ClutterContainer *container,
|
||||||
ClutterActor *actor,
|
ClutterActor *actor,
|
||||||
ClutterActor *sibling)
|
ClutterActor *sibling)
|
||||||
{
|
{
|
||||||
/* XXX: not yet implemented */
|
StTablePrivate *priv = ST_TABLE (container)->priv;
|
||||||
g_warning ("%s() not yet implemented", __FUNCTION__);
|
|
||||||
|
_st_container_lower (container, actor, sibling, &priv->children);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
st_container_raise (ClutterContainer *container,
|
st_table_raise (ClutterContainer *container,
|
||||||
ClutterActor *actor,
|
ClutterActor *actor,
|
||||||
ClutterActor *sibling)
|
ClutterActor *sibling)
|
||||||
{
|
{
|
||||||
/* XXX: not yet implemented */
|
StTablePrivate *priv = ST_TABLE (container)->priv;
|
||||||
g_warning ("%s() not yet implemented", __FUNCTION__);
|
|
||||||
|
_st_container_raise (container, actor, sibling, &priv->children);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
st_container_sort_depth_order (ClutterContainer *container)
|
st_table_sort_depth_order (ClutterContainer *container)
|
||||||
{
|
{
|
||||||
/* XXX: not yet implemented */
|
StTablePrivate *priv = ST_TABLE (container)->priv;
|
||||||
g_warning ("%s() not yet implemented", __FUNCTION__);
|
|
||||||
|
_st_container_sort_depth_order (container, &priv->children);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
st_container_iface_init (ClutterContainerIface *iface)
|
st_table_container_iface_init (ClutterContainerIface *iface)
|
||||||
{
|
{
|
||||||
iface->add = st_container_add_actor;
|
iface->add = st_table_add_actor;
|
||||||
iface->remove = st_container_remove_actor;
|
iface->remove = st_table_remove_actor;
|
||||||
iface->foreach = st_container_foreach;
|
iface->foreach = st_table_foreach;
|
||||||
iface->lower = st_container_lower;
|
iface->lower = st_table_lower;
|
||||||
iface->raise = st_container_raise;
|
iface->raise = st_table_raise;
|
||||||
iface->sort_depth_order = st_container_sort_depth_order;
|
iface->sort_depth_order = st_table_sort_depth_order;
|
||||||
|
|
||||||
iface->child_meta_type = ST_TYPE_TABLE_CHILD;
|
iface->child_meta_type = ST_TYPE_TABLE_CHILD;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,7 +260,7 @@ st_table_homogeneous_allocate (ClutterActor *self,
|
|||||||
const ClutterActorBox *content_box,
|
const ClutterActorBox *content_box,
|
||||||
gboolean flags)
|
gboolean flags)
|
||||||
{
|
{
|
||||||
GSList *list;
|
GList *list;
|
||||||
gfloat col_width, row_height;
|
gfloat col_width, row_height;
|
||||||
gint row_spacing, col_spacing;
|
gint row_spacing, col_spacing;
|
||||||
StTablePrivate *priv = ST_TABLE (self)->priv;
|
StTablePrivate *priv = ST_TABLE (self)->priv;
|
||||||
@ -299,7 +276,7 @@ st_table_homogeneous_allocate (ClutterActor *self,
|
|||||||
- (row_spacing * (priv->n_rows - 1)))
|
- (row_spacing * (priv->n_rows - 1)))
|
||||||
/ priv->n_rows;
|
/ priv->n_rows;
|
||||||
|
|
||||||
for (list = priv->children; list; list = g_slist_next (list))
|
for (list = priv->children; list; list = list->next)
|
||||||
{
|
{
|
||||||
gint row, col, row_span, col_span;
|
gint row, col, row_span, col_span;
|
||||||
StTableChild *meta;
|
StTableChild *meta;
|
||||||
@ -357,7 +334,7 @@ st_table_calculate_col_widths (StTable *table,
|
|||||||
gboolean *is_expand_col;
|
gboolean *is_expand_col;
|
||||||
gint extra_col_width, n_expanded_cols = 0, expanded_cols = 0;
|
gint extra_col_width, n_expanded_cols = 0, expanded_cols = 0;
|
||||||
gint *pref_widths, *min_widths;
|
gint *pref_widths, *min_widths;
|
||||||
GSList *list;
|
GList *list;
|
||||||
|
|
||||||
g_array_set_size (priv->is_expand_col, 0);
|
g_array_set_size (priv->is_expand_col, 0);
|
||||||
g_array_set_size (priv->is_expand_col, priv->n_cols);
|
g_array_set_size (priv->is_expand_col, priv->n_cols);
|
||||||
@ -371,7 +348,7 @@ st_table_calculate_col_widths (StTable *table,
|
|||||||
g_array_set_size (priv->min_widths, priv->n_cols);
|
g_array_set_size (priv->min_widths, priv->n_cols);
|
||||||
min_widths = (gint *) priv->min_widths->data;
|
min_widths = (gint *) priv->min_widths->data;
|
||||||
|
|
||||||
for (list = priv->children; list; list = g_slist_next (list))
|
for (list = priv->children; list; list = list->next)
|
||||||
{
|
{
|
||||||
gint row, col;
|
gint row, col;
|
||||||
gfloat w_min, w_pref;
|
gfloat w_min, w_pref;
|
||||||
@ -459,7 +436,7 @@ st_table_calculate_row_heights (StTable *table,
|
|||||||
gint * col_widths)
|
gint * col_widths)
|
||||||
{
|
{
|
||||||
StTablePrivate *priv = ST_TABLE (table)->priv;
|
StTablePrivate *priv = ST_TABLE (table)->priv;
|
||||||
GSList *list;
|
GList *list;
|
||||||
gint *is_expand_row, *min_heights, *pref_heights, *row_heights, extra_row_height;
|
gint *is_expand_row, *min_heights, *pref_heights, *row_heights, extra_row_height;
|
||||||
gint i, total_min_height;
|
gint i, total_min_height;
|
||||||
gint expanded_rows = 0;
|
gint expanded_rows = 0;
|
||||||
@ -482,7 +459,7 @@ st_table_calculate_row_heights (StTable *table,
|
|||||||
pref_heights = (gboolean *) priv->pref_heights->data;
|
pref_heights = (gboolean *) priv->pref_heights->data;
|
||||||
|
|
||||||
/* calculate minimum row widths and column heights */
|
/* calculate minimum row widths and column heights */
|
||||||
for (list = priv->children; list; list = g_slist_next (list))
|
for (list = priv->children; list; list = list->next)
|
||||||
{
|
{
|
||||||
gint row, col, cell_width;
|
gint row, col, cell_width;
|
||||||
gfloat h_min, h_pref;
|
gfloat h_min, h_pref;
|
||||||
@ -633,7 +610,7 @@ st_table_preferred_allocate (ClutterActor *self,
|
|||||||
const ClutterActorBox *content_box,
|
const ClutterActorBox *content_box,
|
||||||
gboolean flags)
|
gboolean flags)
|
||||||
{
|
{
|
||||||
GSList *list;
|
GList *list;
|
||||||
gint row_spacing, col_spacing;
|
gint row_spacing, col_spacing;
|
||||||
gint i;
|
gint i;
|
||||||
gint *col_widths, *row_heights;
|
gint *col_widths, *row_heights;
|
||||||
@ -659,7 +636,7 @@ st_table_preferred_allocate (ClutterActor *self,
|
|||||||
ltr = (st_widget_get_direction (ST_WIDGET (self)) == ST_TEXT_DIRECTION_LTR);
|
ltr = (st_widget_get_direction (ST_WIDGET (self)) == ST_TEXT_DIRECTION_LTR);
|
||||||
|
|
||||||
|
|
||||||
for (list = priv->children; list; list = g_slist_next (list))
|
for (list = priv->children; list; list = list->next)
|
||||||
{
|
{
|
||||||
gint row, col, row_span, col_span;
|
gint row, col, row_span, col_span;
|
||||||
gint col_width, row_height;
|
gint col_width, row_height;
|
||||||
@ -803,7 +780,7 @@ st_table_get_preferred_width (ClutterActor *self,
|
|||||||
gfloat total_min_width, total_pref_width;
|
gfloat total_min_width, total_pref_width;
|
||||||
StTablePrivate *priv = ST_TABLE (self)->priv;
|
StTablePrivate *priv = ST_TABLE (self)->priv;
|
||||||
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (self));
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (self));
|
||||||
GSList *list;
|
GList *list;
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
if (priv->n_cols < 1)
|
if (priv->n_cols < 1)
|
||||||
@ -825,7 +802,7 @@ st_table_get_preferred_width (ClutterActor *self,
|
|||||||
pref_widths = (gint *) priv->pref_widths->data;
|
pref_widths = (gint *) priv->pref_widths->data;
|
||||||
|
|
||||||
/* calculate minimum row widths */
|
/* calculate minimum row widths */
|
||||||
for (list = priv->children; list; list = g_slist_next (list))
|
for (list = priv->children; list; list = list->next)
|
||||||
{
|
{
|
||||||
gint col, col_span;
|
gint col, col_span;
|
||||||
gfloat w_min, w_pref;
|
gfloat w_min, w_pref;
|
||||||
@ -878,7 +855,7 @@ st_table_get_preferred_height (ClutterActor *self,
|
|||||||
gfloat total_min_height, total_pref_height;
|
gfloat total_min_height, total_pref_height;
|
||||||
StTablePrivate *priv = ST_TABLE (self)->priv;
|
StTablePrivate *priv = ST_TABLE (self)->priv;
|
||||||
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (self));
|
StThemeNode *theme_node = st_widget_get_theme_node (ST_WIDGET (self));
|
||||||
GSList *list;
|
GList *list;
|
||||||
gint i;
|
gint i;
|
||||||
gint *min_widths;
|
gint *min_widths;
|
||||||
|
|
||||||
@ -906,7 +883,7 @@ st_table_get_preferred_height (ClutterActor *self,
|
|||||||
pref_heights = (gint *) priv->pref_heights->data;
|
pref_heights = (gint *) priv->pref_heights->data;
|
||||||
|
|
||||||
/* calculate minimum row heights */
|
/* calculate minimum row heights */
|
||||||
for (list = priv->children; list; list = g_slist_next (list))
|
for (list = priv->children; list; list = list->next)
|
||||||
{
|
{
|
||||||
gint row, col, col_span, cell_width, row_span;
|
gint row, col, col_span, cell_width, row_span;
|
||||||
gfloat min, pref;
|
gfloat min, pref;
|
||||||
@ -961,12 +938,12 @@ static void
|
|||||||
st_table_paint (ClutterActor *self)
|
st_table_paint (ClutterActor *self)
|
||||||
{
|
{
|
||||||
StTablePrivate *priv = ST_TABLE (self)->priv;
|
StTablePrivate *priv = ST_TABLE (self)->priv;
|
||||||
GSList *list;
|
GList *list;
|
||||||
|
|
||||||
/* make sure the background gets painted first */
|
/* make sure the background gets painted first */
|
||||||
CLUTTER_ACTOR_CLASS (st_table_parent_class)->paint (self);
|
CLUTTER_ACTOR_CLASS (st_table_parent_class)->paint (self);
|
||||||
|
|
||||||
for (list = priv->children; list; list = g_slist_next (list))
|
for (list = priv->children; list; list = list->next)
|
||||||
{
|
{
|
||||||
ClutterActor *child = CLUTTER_ACTOR (list->data);
|
ClutterActor *child = CLUTTER_ACTOR (list->data);
|
||||||
if (CLUTTER_ACTOR_IS_VISIBLE (child))
|
if (CLUTTER_ACTOR_IS_VISIBLE (child))
|
||||||
@ -979,12 +956,12 @@ st_table_pick (ClutterActor *self,
|
|||||||
const ClutterColor *color)
|
const ClutterColor *color)
|
||||||
{
|
{
|
||||||
StTablePrivate *priv = ST_TABLE (self)->priv;
|
StTablePrivate *priv = ST_TABLE (self)->priv;
|
||||||
GSList *list;
|
GList *list;
|
||||||
|
|
||||||
/* Chain up so we get a bounding box painted (if we are reactive) */
|
/* Chain up so we get a bounding box painted (if we are reactive) */
|
||||||
CLUTTER_ACTOR_CLASS (st_table_parent_class)->pick (self, color);
|
CLUTTER_ACTOR_CLASS (st_table_parent_class)->pick (self, color);
|
||||||
|
|
||||||
for (list = priv->children; list; list = g_slist_next (list))
|
for (list = priv->children; list; list = list->next)
|
||||||
{
|
{
|
||||||
if (CLUTTER_ACTOR_IS_VISIBLE (list->data))
|
if (CLUTTER_ACTOR_IS_VISIBLE (list->data))
|
||||||
clutter_actor_paint (CLUTTER_ACTOR (list->data));
|
clutter_actor_paint (CLUTTER_ACTOR (list->data));
|
||||||
@ -995,7 +972,7 @@ static void
|
|||||||
st_table_show_all (ClutterActor *table)
|
st_table_show_all (ClutterActor *table)
|
||||||
{
|
{
|
||||||
StTablePrivate *priv = ST_TABLE (table)->priv;
|
StTablePrivate *priv = ST_TABLE (table)->priv;
|
||||||
GSList *l;
|
GList *l;
|
||||||
|
|
||||||
for (l = priv->children; l; l = l->next)
|
for (l = priv->children; l; l = l->next)
|
||||||
clutter_actor_show_all (CLUTTER_ACTOR (l->data));
|
clutter_actor_show_all (CLUTTER_ACTOR (l->data));
|
||||||
@ -1007,7 +984,7 @@ static void
|
|||||||
st_table_hide_all (ClutterActor *table)
|
st_table_hide_all (ClutterActor *table)
|
||||||
{
|
{
|
||||||
StTablePrivate *priv = ST_TABLE (table)->priv;
|
StTablePrivate *priv = ST_TABLE (table)->priv;
|
||||||
GSList *l;
|
GList *l;
|
||||||
|
|
||||||
clutter_actor_hide (table);
|
clutter_actor_hide (table);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user