[gnome-shell] [StBoxLayout] Add st_box_layout_remove_all, st_box_layout_destroy_children



commit bf7b1662373501e6b1b5a3c117080f6656c0d354
Author: Colin Walters <walters verbum org>
Date:   Tue Nov 10 14:25:41 2009 -0500

    [StBoxLayout] Add st_box_layout_remove_all, st_box_layout_destroy_children
    
    In a variety of places we're using boxes as data-modeling displays,
    and in doing so we often want to either remove the children or
    explictly destroy them.
    
    Now ideally Gjs would support callbacks, and this would make using
    the for_each functions possible, but even then these functions
    are more efficient and shorter to type, at least.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=600734

 src/st/st-box-layout.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 src/st/st-box-layout.h |    4 ++++
 2 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/src/st/st-box-layout.c b/src/st/st-box-layout.c
index 12b1508..d0371d8 100644
--- a/src/st/st-box-layout.c
+++ b/src/st/st-box-layout.c
@@ -1338,3 +1338,50 @@ st_box_layout_get_pack_start (StBoxLayout *box)
 
   return box->priv->is_pack_start;
 }
+
+static void
+st_box_layout_internal_remove_all (StBoxLayout *self,
+                                   gboolean     destroy)
+{
+  StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (self)->priv;
+  ClutterActor *child;
+
+  while (priv->children)
+    {
+      child = priv->children->data;
+
+      g_object_ref (child);
+      priv->children = g_list_delete_link (priv->children, priv->children);
+      clutter_actor_unparent (child);
+      g_signal_emit_by_name (self, "actor-removed", child);
+      if (destroy)
+        clutter_actor_destroy (child);
+      g_object_unref (child);
+    }
+
+  clutter_actor_queue_relayout ((ClutterActor*) self);
+}
+
+/**
+ * st_box_layout_remove_all:
+ * @self:
+ *
+ * Efficiently unparent all children currently in this box.
+ */
+void
+st_box_layout_remove_all (StBoxLayout *self)
+{
+  st_box_layout_internal_remove_all (self, FALSE);
+}
+
+/**
+ * st_box_layout_destroy_children:
+ * @self:
+ *
+ * Efficiently unparent and destroy all children currently in this box.
+ */
+void
+st_box_layout_destroy_children (StBoxLayout *self)
+{
+  st_box_layout_internal_remove_all (self, TRUE);
+}
diff --git a/src/st/st-box-layout.h b/src/st/st-box-layout.h
index 30954a2..b57143b 100644
--- a/src/st/st-box-layout.h
+++ b/src/st/st-box-layout.h
@@ -89,6 +89,10 @@ void     st_box_layout_set_pack_start (StBoxLayout *box,
                                        gboolean     pack_start);
 gboolean st_box_layout_get_pack_start (StBoxLayout *box);
 
+void     st_box_layout_remove_all     (StBoxLayout *box);
+
+void     st_box_layout_destroy_children (StBoxLayout *box);
+
 G_END_DECLS
 
 #endif /* _ST_BOX_LAYOUT_H */



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