[clutter/wip/apocalypses/apocalypse-1: 65/92] actor: Add remove_all_children()



commit 073109c91b410b86a2f954fb2f031c9280825e24
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Mon Dec 19 18:01:04 2011 +0000

    actor: Add remove_all_children()
    
    A simple method for removing all children of an actor in one fell swoop.

 clutter/clutter-actor.c           |   50 +++++++++++++++++++++++++++++++++---
 clutter/clutter-actor.h           |    1 +
 tests/conform/test-actor-graph.c  |   28 ++++++++++++++++++++
 tests/conform/test-conform-main.c |    3 +-
 4 files changed, 76 insertions(+), 6 deletions(-)
---
diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c
index 5ce9692..9ce90c9 100644
--- a/clutter/clutter-actor.c
+++ b/clutter/clutter-actor.c
@@ -9686,7 +9686,8 @@ clutter_actor_add_child_internal (ClutterActor             *self,
  * This function will take into consideration the #ClutterActor:depth
  * of @child, and will keep the list of children sorted.
  *
- * This function will emit the #ClutterContainer::actor-added signal.
+ * This function will emit the #ClutterContainer::actor-added signal
+ * on @self.
  *
  * Since: 1.10
  */
@@ -9721,7 +9722,8 @@ clutter_actor_add_child (ClutterActor *self,
  * This function will not take into consideration the #ClutterActor:depth
  * of @child.
  *
- * This function will emit the #ClutterContainer::actor-added signal.
+ * This function will emit the #ClutterContainer::actor-added signal
+ * on @self.
  *
  * Since: 1.10
  */
@@ -9758,7 +9760,8 @@ clutter_actor_insert_child_at_index (ClutterActor *self,
  * This function will not take into consideration the #ClutterActor:depth
  * of @child.
  *
- * This function will emit the #ClutterContainer::actor-added signal.
+ * This function will emit the #ClutterContainer::actor-added signal
+ * on @self.
  *
  * Since: 1.10
  */
@@ -9799,7 +9802,8 @@ clutter_actor_insert_child_above (ClutterActor *self,
  * This function will not take into consideration the #ClutterActor:depth
  * of @child.
  *
- * This function will emit the #ClutterContainer::actor-added signal.
+ * This function will emit the #ClutterContainer::actor-added signal
+ * on @self.
  *
  * Since: 1.10
  */
@@ -10026,7 +10030,7 @@ clutter_actor_remove_child_internal (ClutterActor *self,
  * function.
  *
  * This function will emit the #ClutterContainer::actor-removed
- * signal.
+ * signal on @self.
  *
  * Since: 1.10
  */
@@ -10043,6 +10047,42 @@ clutter_actor_remove_child (ClutterActor *self,
   clutter_actor_remove_child_internal (self, child, TRUE, TRUE);
 }
 
+/**
+ * clutter_actor_remove_all_children:
+ * @self: a #ClutterActor
+ *
+ * Removes all children of @self.
+ *
+ * This function releases the reference added by inserting a child actor
+ * in the list of children of @self.
+ *
+ * Since: 1.10
+ */
+void
+clutter_actor_remove_all_children (ClutterActor *self)
+{
+  ClutterActor *iter;
+
+  g_return_if_fail (CLUTTER_IS_ACTOR (self));
+
+  if (self->priv->n_children == 0)
+    return;
+
+  iter = self->priv->first_child;
+  while (iter != NULL)
+    {
+      ClutterActor *next = iter->priv->next_sibling;
+
+      clutter_actor_remove_child_internal (self, iter, TRUE, TRUE);
+
+      iter = next;
+    }
+
+  g_assert (self->priv->first_child == NULL);
+  g_assert (self->priv->last_child == NULL);
+  g_assert (self->priv->n_children == 0);
+}
+
 typedef struct _InsertBetweenData {
   ClutterActor *prev_sibling;
   ClutterActor *next_sibling;
diff --git a/clutter/clutter-actor.h b/clutter/clutter-actor.h
index feb1f64..7ca0a9b 100644
--- a/clutter/clutter-actor.h
+++ b/clutter/clutter-actor.h
@@ -466,6 +466,7 @@ void                  clutter_actor_replace_child             (ClutterActor
                                                                ClutterActor          *new_child);
 void                  clutter_actor_remove_child              (ClutterActor          *self,
                                                                ClutterActor          *child);
+void                  clutter_actor_remove_all_children       (ClutterActor          *self);
 GList *               clutter_actor_get_children              (ClutterActor          *self);
 gint                  clutter_actor_get_n_children            (ClutterActor          *self);
 ClutterActor *        clutter_actor_get_child_at_index        (ClutterActor          *self,
diff --git a/tests/conform/test-actor-graph.c b/tests/conform/test-actor-graph.c
index d1b4b86..fcf55de 100644
--- a/tests/conform/test-actor-graph.c
+++ b/tests/conform/test-actor-graph.c
@@ -311,3 +311,31 @@ actor_replace_child (TestConformSimpleFixture *fixture,
   clutter_actor_destroy (actor);
   g_object_unref (actor);
 }
+
+void
+actor_remove_all (TestConformSimpleFixture *fixture,
+                  gconstpointer dummy)
+{
+  ClutterActor *actor = clutter_actor_new ();
+
+  g_object_ref_sink (actor);
+
+  clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR,
+                                                "name", "foo",
+                                                NULL));
+  clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR,
+                                                "name", "bar",
+                                                NULL));
+  clutter_actor_add_child (actor, g_object_new (CLUTTER_TYPE_ACTOR,
+                                                "name", "baz",
+                                                NULL));
+
+  g_assert_cmpint (clutter_actor_get_n_children (actor), ==, 3);
+
+  clutter_actor_remove_all_children (actor);
+
+  g_assert_cmpint (clutter_actor_get_n_children (actor), ==, 0);
+
+  clutter_actor_destroy (actor);
+  g_object_unref (actor);
+}
diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c
index 9ce1e54..a643133 100644
--- a/tests/conform/test-conform-main.c
+++ b/tests/conform/test-conform-main.c
@@ -130,10 +130,11 @@ main (int argc, char **argv)
 
   TEST_CONFORM_SIMPLE ("/actor", actor_add_child);
   TEST_CONFORM_SIMPLE ("/actor", actor_insert_child);
-  TEST_CONFORM_SIMPLE ("/actor", actor_remove_child);
   TEST_CONFORM_SIMPLE ("/actor", actor_raise_child);
   TEST_CONFORM_SIMPLE ("/actor", actor_lower_child);
   TEST_CONFORM_SIMPLE ("/actor", actor_replace_child);
+  TEST_CONFORM_SIMPLE ("/actor", actor_remove_child);
+  TEST_CONFORM_SIMPLE ("/actor", actor_remove_all);
   TEST_CONFORM_SIMPLE ("/actor", actor_destruction);
   TEST_CONFORM_SIMPLE ("/actor", actor_anchors);
   TEST_CONFORM_SIMPLE ("/actor", actor_picking);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]