[egg-list-box/flow-box-enhancements] Add an insert function



commit 44d564ad65a1c798fcc4283c9b2d0320eccb0f27
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Sep 22 14:59:09 2013 -0400

    Add an insert function
    
    Similar to what GtkListBox has.

 egg-flow-box.c |   72 +++++++++++++++++++++++++++++++++----------------------
 egg-flow-box.h |    4 +++
 2 files changed, 47 insertions(+), 29 deletions(-)
---
diff --git a/egg-flow-box.c b/egg-flow-box.c
index 8c7abef..6efbbda 100644
--- a/egg-flow-box.c
+++ b/egg-flow-box.c
@@ -1053,7 +1053,6 @@ egg_flow_box_size_allocate (GtkWidget     *widget,
            !g_sequence_iter_is_end (iter);
            i++)
         {
-
           iter = get_largest_size_for_line_in_opposing_orientation (box,
                                                                     priv->orientation,
                                                                     iter,
@@ -1282,34 +1281,7 @@ static void
 egg_flow_box_add (GtkContainer *container,
                   GtkWidget    *child)
 {
-  EggFlowBox *box = EGG_FLOW_BOX (container);
-  EggFlowBoxPrivate *priv = box->priv;
-  EggFlowBoxChild *info;
-  EggFlowBoxChildPrivate *child_priv;
-  GSequenceIter *iter = NULL;
-
-  g_return_if_fail (EGG_IS_FLOW_BOX (box));
-  g_return_if_fail (GTK_IS_WIDGET (child));
-
-  if (EGG_IS_FLOW_BOX_CHILD (child))
-    info = EGG_FLOW_BOX_CHILD (child);
-  else
-    {
-      info = EGG_FLOW_BOX_CHILD (egg_flow_box_child_new ());
-      gtk_widget_show (GTK_WIDGET (info));
-      gtk_container_add (GTK_CONTAINER (info), child);
-    }
-
-  if (priv->sort_func != NULL)
-    iter = g_sequence_insert_sorted (priv->children, info,
-                                     (GCompareDataFunc)egg_flow_box_sort, box);
-  else
-    iter = g_sequence_append (priv->children, info);
-
-  child_priv = egg_flow_box_child_get_instance_private (info);
-  child_priv->iter = iter;
-  gtk_widget_set_parent (GTK_WIDGET (info), GTK_WIDGET (box));
-  egg_flow_box_apply_filter (box, info);
+  egg_flow_box_insert (EGG_FLOW_BOX (container), child, -1);
 }
 
 static void
@@ -4069,3 +4041,45 @@ egg_flow_box_child_changed (EggFlowBoxChild *child)
   egg_flow_box_apply_filter (box, child);
 }
 
+void
+egg_flow_box_insert (EggFlowBox *box,
+                     GtkWidget  *child,
+                     gint        position)
+{
+  EggFlowBoxPrivate *priv = box->priv;
+  EggFlowBoxChild *info;
+  EggFlowBoxChildPrivate *child_priv;
+  GSequenceIter *iter = NULL;
+
+  g_return_if_fail (EGG_IS_FLOW_BOX (box));
+  g_return_if_fail (GTK_IS_WIDGET (child));
+
+  if (EGG_IS_FLOW_BOX_CHILD (child))
+    info = EGG_FLOW_BOX_CHILD (child);
+  else
+    {
+      info = EGG_FLOW_BOX_CHILD (egg_flow_box_child_new ());
+      gtk_widget_show (GTK_WIDGET (info));
+      gtk_container_add (GTK_CONTAINER (info), child);
+    }
+
+  if (priv->sort_func != NULL)
+    iter = g_sequence_insert_sorted (priv->children, info,
+                                     (GCompareDataFunc)egg_flow_box_sort, box);
+  else if (position == 0)
+    iter = g_sequence_prepend (priv->children, info);
+  else if (position == -1)
+    iter = g_sequence_append (priv->children, info);
+  else
+    {
+      GSequenceIter *pos;
+      pos = g_sequence_get_iter_at_pos (priv->children, position);
+      iter = g_sequence_insert_before (pos, info);
+    }
+
+  child_priv = egg_flow_box_child_get_instance_private (info);
+  child_priv->iter = iter;
+  gtk_widget_set_parent (GTK_WIDGET (info), GTK_WIDGET (box));
+  egg_flow_box_apply_filter (box, info);
+}
+
diff --git a/egg-flow-box.h b/egg-flow-box.h
index 56b03d8..2eb10dd 100644
--- a/egg-flow-box.h
+++ b/egg-flow-box.h
@@ -153,6 +153,10 @@ gboolean              egg_flow_box_get_activate_on_single_click (EggFlowBox
 void                  egg_flow_box_set_activate_on_single_click (EggFlowBox        *box,
                                                                  gboolean           single);
 
+void                  egg_flow_box_insert                       (EggFlowBox        *box,
+                                                                 GtkWidget         *child,
+                                                                 gint               position);
+
 GList                *egg_flow_box_get_selected_children        (EggFlowBox        *box);
 void                  egg_flow_box_selected_foreach             (EggFlowBox        *box,
                                                                  EggFlowBoxForeachFunc func,


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