actor: Add remove_all_children()
authorEmmanuele Bassi <ebassi@linux.intel.com>
Mon, 19 Dec 2011 18:01:04 +0000 (18:01 +0000)
committerEmmanuele Bassi <ebassi@gnome.org>
Mon, 16 Jan 2012 23:37:11 +0000 (23:37 +0000)
A simple method for removing all children of an actor in one fell swoop.

clutter/clutter-actor.c
clutter/clutter-actor.h
tests/conform/test-actor-graph.c
tests/conform/test-conform-main.c

index a77b41f..3fedacb 100644 (file)
@@ -9679,7 +9679,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
  */
@@ -9714,7 +9715,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
  */
@@ -9751,7 +9753,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
  */
@@ -9792,7 +9795,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
  */
@@ -10019,7 +10023,7 @@ clutter_actor_remove_child_internal (ClutterActor *self,
  * function.
  *
  * This function will emit the #ClutterContainer::actor-removed
- * signal.
+ * signal on @self.
  *
  * Since: 1.10
  */
@@ -10036,6 +10040,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;
index feb1f64..7ca0a9b 100644 (file)
@@ -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,
index d1b4b86..fcf55de 100644 (file)
@@ -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);
+}
index 9ce1e54..a643133 100644 (file)
@@ -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);