actor: Fix child insertion issues

The insert_child_at_index, insert_below and insert_above messed up the
first and last child pointers in various cases. This commit fixes all
the instances of first and last child pointers being stale or set to
NULL.
This commit is contained in:
Emmanuele Bassi 2011-12-18 20:57:02 +00:00
parent 7e377b5aee
commit 813eef4325

View File

@ -9429,6 +9429,9 @@ insert_child_at_index (ClutterActor *self,
child->priv->next_sibling = tmp; child->priv->next_sibling = tmp;
self->priv->first_child = child; self->priv->first_child = child;
if (self->priv->last_child == NULL)
self->priv->last_child = child;
} }
else if (index < 0) else if (index < 0)
{ {
@ -9441,6 +9444,9 @@ insert_child_at_index (ClutterActor *self,
child->priv->next_sibling = NULL; child->priv->next_sibling = NULL;
self->priv->last_child = child; self->priv->last_child = child;
if (self->priv->first_child == NULL)
self->priv->first_child = child;
} }
else else
{ {
@ -9483,13 +9489,26 @@ insert_child_above (ClutterActor *self,
sibling = self->priv->last_child; sibling = self->priv->last_child;
child->priv->prev_sibling = sibling; child->priv->prev_sibling = sibling;
child->priv->next_sibling = NULL;
if (sibling != NULL) if (sibling != NULL)
sibling->priv->next_sibling = child; {
ClutterActor *tmp = sibling->priv->next_sibling;
if (self->priv->last_child == sibling) child->priv->next_sibling = tmp;
if (tmp != NULL)
tmp->priv->prev_sibling = child;
sibling->priv->next_sibling = child;
}
else
child->priv->next_sibling = NULL;
if (self->priv->last_child == NULL || self->priv->last_child == sibling)
self->priv->last_child = child; self->priv->last_child = child;
if (self->priv->first_child == NULL)
self->priv->first_child = sibling != NULL ? sibling : child;
} }
static void static void
@ -9502,14 +9521,27 @@ insert_child_below (ClutterActor *self,
if (sibling == NULL) if (sibling == NULL)
sibling = self->priv->first_child; sibling = self->priv->first_child;
child->priv->prev_sibling = NULL;
child->priv->next_sibling = sibling; child->priv->next_sibling = sibling;
if (sibling != NULL) if (sibling != NULL)
sibling->priv->prev_sibling = child; {
ClutterActor *tmp = sibling->priv->prev_sibling;
if (self->priv->first_child == sibling) child->priv->prev_sibling = tmp;
if (tmp != NULL)
tmp->priv->next_sibling = child;
sibling->priv->prev_sibling = child;
}
else
child->priv->prev_sibling = NULL;
if (self->priv->first_child == NULL || self->priv->first_child == sibling)
self->priv->first_child = child; self->priv->first_child = child;
if (self->priv->last_child == NULL)
self->priv->last_child = sibling != NULL ? sibling : child;
} }
typedef void (* ClutterActorAddChildFunc) (ClutterActor *parent, typedef void (* ClutterActorAddChildFunc) (ClutterActor *parent,
@ -9680,7 +9712,6 @@ clutter_actor_insert_child_at_index (ClutterActor *self,
g_return_if_fail (CLUTTER_IS_ACTOR (child)); g_return_if_fail (CLUTTER_IS_ACTOR (child));
g_return_if_fail (self != child); g_return_if_fail (self != child);
g_return_if_fail (child->priv->parent == NULL); g_return_if_fail (child->priv->parent == NULL);
g_return_if_fail (index_ < self->priv->n_children);
clutter_actor_add_child_internal (self, child, clutter_actor_add_child_internal (self, child,
insert_child_at_index, insert_child_at_index,