[clutter/wip/apocalypses/apocalypse-1: 29/92] actor: Cosmetic fixes to internal add/remove child



commit b8a1c92b5502e82015f92529442df313935ddcd2
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Fri Dec 2 16:16:26 2011 +0000

    actor: Cosmetic fixes to internal add/remove child
    
    Avoid code duplication all over the place.

 clutter/clutter-actor.c |   63 ++++++++++++++++++++++++++++------------------
 1 files changed, 38 insertions(+), 25 deletions(-)
---
diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c
index afcdf36..50e33a5 100644
--- a/clutter/clutter-actor.c
+++ b/clutter/clutter-actor.c
@@ -9133,7 +9133,9 @@ static void
 clutter_actor_add_child_internal (ClutterActor             *self,
                                   ClutterActor             *child,
                                   ClutterActorAddChildFunc  add_func,
-                                  gpointer                  data)
+                                  gpointer                  data,
+                                  gboolean                  create_meta,
+                                  gboolean                  emit_signal)
 {
   ClutterTextDirection text_dir;
 
@@ -9156,6 +9158,9 @@ clutter_actor_add_child_internal (ClutterActor             *self,
       return;
     }
 
+  if (create_meta)
+    clutter_container_create_child_meta (CLUTTER_CONTAINER (self), child);
+
   g_object_ref_sink (child);
   child->priv->parent_actor = self;
 
@@ -9222,6 +9227,9 @@ clutter_actor_add_child_internal (ClutterActor             *self,
     {
       clutter_actor_queue_compute_expand (self);
     }
+
+  if (emit_signal)
+    g_signal_emit_by_name (self, "actor-added", child);
 }
 
 /**
@@ -9250,11 +9258,11 @@ clutter_actor_add_child (ClutterActor *self,
   g_return_if_fail (self != child);
   g_return_if_fail (child->priv->parent_actor == NULL);
 
-  clutter_container_create_child_meta (CLUTTER_CONTAINER (self), child);
   clutter_actor_add_child_internal (self, child,
                                     insert_child_at_depth,
-                                    NULL);
-  g_signal_emit_by_name (self, "actor-added", child);
+                                    NULL,
+                                    TRUE, /* create_meta */
+                                    TRUE  /* emit_signals */);
 }
 
 /**
@@ -9287,11 +9295,11 @@ clutter_actor_insert_child_at_index (ClutterActor *self,
   g_return_if_fail (child->priv->parent_actor == NULL);
   g_return_if_fail (index_ < self->priv->n_children);
 
-  clutter_container_create_child_meta (CLUTTER_CONTAINER (self), child);
   clutter_actor_add_child_internal (self, child,
                                     insert_child_at_index,
-                                    GINT_TO_POINTER (index_));
-  g_signal_emit_by_name (self, "actor-added", child);
+                                    GINT_TO_POINTER (index_),
+                                    TRUE,
+                                    TRUE);
 }
 
 /**
@@ -9328,11 +9336,11 @@ clutter_actor_insert_child_above (ClutterActor *self,
                     (CLUTTER_IS_ACTOR (sibling) &&
                      sibling->priv->parent_actor == self));
 
-  clutter_container_create_child_meta (CLUTTER_CONTAINER (self), child);
   clutter_actor_add_child_internal (self, child,
                                     insert_child_above,
-                                    sibling);
-  g_signal_emit_by_name (self, "actor-added", child);
+                                    sibling,
+                                    TRUE,
+                                    TRUE);
 }
 
 /**
@@ -9369,11 +9377,11 @@ clutter_actor_insert_child_below (ClutterActor *self,
                     (CLUTTER_IS_ACTOR (sibling) &&
                      sibling->priv->parent_actor == self));
 
-  clutter_container_create_child_meta (CLUTTER_CONTAINER (self), child);
   clutter_actor_add_child_internal (self, child,
                                     insert_child_below,
-                                    sibling);
-  g_signal_emit_by_name (self, "actor-added", child);
+                                    sibling,
+                                    TRUE,
+                                    TRUE);
 }
 
 /**
@@ -9403,7 +9411,9 @@ clutter_actor_set_parent (ClutterActor *self,
 
   clutter_actor_add_child_internal (parent, self,
                                     insert_child_at_depth,
-                                    NULL);
+                                    NULL,
+                                    FALSE,
+                                    FALSE);
 }
 
 /**
@@ -9462,10 +9472,15 @@ invalidate_queue_redraw_entry (ClutterActor *self,
 
 static void
 clutter_actor_remove_child_internal (ClutterActor *self,
-                                     ClutterActor *child)
+                                     ClutterActor *child,
+                                     gboolean      destroy_meta,
+                                     gboolean      emit_signal)
 {
   gboolean was_mapped;
 
+  if (destroy_meta)
+    clutter_container_destroy_child_meta (CLUTTER_CONTAINER (self), child);
+
   was_mapped = CLUTTER_ACTOR_IS_MAPPED (child);
 
   /* we need to unrealize *before* we set parent_actor to NULL,
@@ -9521,6 +9536,10 @@ clutter_actor_remove_child_internal (ClutterActor *self,
       clutter_actor_queue_compute_expand (self);
     }
 
+  /* we need to emit the signal before dropping the reference */
+  if (emit_signal)
+    g_signal_emit_by_name (self, "actor-removed", child);
+
   /* remove the reference we acquired in clutter_actor_add_child() */
   g_object_unref (child);
 }
@@ -9552,15 +9571,7 @@ clutter_actor_remove_child (ClutterActor *self,
   g_return_if_fail (child->priv->parent_actor != NULL);
   g_return_if_fail (child->priv->parent_actor == self);
 
-  g_object_ref (child);
-
-  clutter_container_destroy_child_meta (CLUTTER_CONTAINER (self), child);
-
-  clutter_actor_remove_child_internal (self, child);
-
-  g_signal_emit_by_name (self, "actor-removed", child);
-
-  g_object_unref (child);
+  clutter_actor_remove_child_internal (self, child, TRUE, TRUE);
 }
 
 /**
@@ -9589,7 +9600,9 @@ clutter_actor_unparent (ClutterActor *self)
   if (self->priv->parent_actor == NULL)
     return;
 
-  clutter_actor_remove_child_internal (self->priv->parent_actor, self);
+  clutter_actor_remove_child_internal (self->priv->parent_actor, self,
+                                       FALSE,
+                                       FALSE);
 }
 
 /**



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