[gtk/kill-containers: 26/55] Stop using container api on GtkFlowBox



commit 3bff7d3a372ac10bd987c3340ff0175b745ee079
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu May 7 23:24:58 2020 -0400

    Stop using container api on GtkFlowBox
    
    GtkContainer is going away.

 demos/gtk-demo/flowbox.c        |  2 +-
 gtk/a11y/gtkflowboxaccessible.c | 24 ++++++++++++++----------
 tests/testflowbox.c             | 21 +++++++--------------
 3 files changed, 22 insertions(+), 25 deletions(-)
---
diff --git a/demos/gtk-demo/flowbox.c b/demos/gtk-demo/flowbox.c
index 8340923be5..25bfe36258 100644
--- a/demos/gtk-demo/flowbox.c
+++ b/demos/gtk-demo/flowbox.c
@@ -737,7 +737,7 @@ do_flowbox (GtkWidget *do_widget)
       gtk_window_set_child (GTK_WINDOW (window), scrolled);
 
       for (i = 0; colors[i]; i++)
-        gtk_container_add (GTK_CONTAINER (flowbox), color_swatch_new (colors[i]));
+        gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), color_swatch_new (colors[i]), -1);
     }
 
   if (!gtk_widget_get_visible (window))
diff --git a/gtk/a11y/gtkflowboxaccessible.c b/gtk/a11y/gtkflowboxaccessible.c
index d32a7f2db0..5f03bf5087 100644
--- a/gtk/a11y/gtkflowboxaccessible.c
+++ b/gtk/a11y/gtkflowboxaccessible.c
@@ -69,21 +69,23 @@ gtk_flow_box_accessible_add_selection (AtkSelection *selection,
                                        gint          idx)
 {
   GtkWidget *box;
-  GList *children;
   GtkWidget *child;
+  int pos;
 
   box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
   if (box == NULL)
     return FALSE;
 
-  children = gtk_container_get_children (GTK_CONTAINER (box));
-  child = g_list_nth_data (children, idx);
-  g_list_free (children);
-  if (child)
+  for (child = gtk_widget_get_first_child (box), pos = 0;
+       child != NULL && pos < idx;
+       child = gtk_widget_get_next_sibling (child), pos++) ;
+
+  if (child && pos == idx)
     {
       gtk_flow_box_select_child (GTK_FLOW_BOX (box), GTK_FLOW_BOX_CHILD (child));
       return TRUE;
     }
+
   return FALSE;
 }
 
@@ -92,21 +94,23 @@ gtk_flow_box_accessible_remove_selection (AtkSelection *selection,
                                           gint          idx)
 {
   GtkWidget *box;
-  GList *children;
   GtkWidget *child;
+  int pos;
 
   box = gtk_accessible_get_widget (GTK_ACCESSIBLE (selection));
   if (box == NULL)
     return FALSE;
 
-  children = gtk_container_get_children (GTK_CONTAINER (box));
-  child = g_list_nth_data (children, idx);
-  g_list_free (children);
-  if (child)
+  for (child = gtk_widget_get_first_child (box), pos = 0;
+       child != NULL && pos < idx;
+       child = gtk_widget_get_next_sibling (child), pos++) ;
+
+  if (child && pos == idx)
     {
       gtk_flow_box_unselect_child (GTK_FLOW_BOX (box), GTK_FLOW_BOX_CHILD (child));
       return TRUE;
     }
+
   return FALSE;
 }
 
diff --git a/tests/testflowbox.c b/tests/testflowbox.c
index 84a1603b39..972392909f 100644
--- a/tests/testflowbox.c
+++ b/tests/testflowbox.c
@@ -52,7 +52,7 @@ populate_flowbox_simple (GtkFlowBox *flowbox)
       gtk_frame_set_child (GTK_FRAME (frame), widget);
 
       g_object_set_data_full (G_OBJECT (frame), "id", (gpointer)g_strdup (text), g_free);
-      gtk_container_add (GTK_CONTAINER (flowbox), frame);
+      gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), frame, -1);
 
       g_free (text);
     }
@@ -100,7 +100,7 @@ populate_flowbox_focus (GtkFlowBox *flowbox)
       if (i % 5 == 0)
         gtk_container_add (GTK_CONTAINER (box), gtk_switch_new ());
 
-      gtk_container_add (GTK_CONTAINER (flowbox), frame);
+      gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), frame, -1);
       if (!sensitive)
         gtk_widget_set_sensitive (gtk_widget_get_parent (frame), FALSE);
     }
@@ -115,7 +115,7 @@ populate_flowbox_buttons (GtkFlowBox *flowbox)
   for (i = 0; i < 50; i++)
     {
       widget = gtk_button_new_with_label ("Button");
-      gtk_container_add (GTK_CONTAINER (flowbox), widget);
+      gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), widget, -1);
       widget = gtk_widget_get_parent (widget);
       gtk_widget_set_can_focus (widget, FALSE);
     }
@@ -148,7 +148,7 @@ populate_flowbox_wrappy (GtkFlowBox *flowbox)
       gtk_label_set_width_chars (GTK_LABEL (widget), 10);
       g_object_set_data_full (G_OBJECT (frame), "id", (gpointer)g_strdup (strings[i]), g_free);
 
-      gtk_container_add (GTK_CONTAINER (flowbox), frame);
+      gtk_flow_box_insert (GTK_FLOW_BOX (flowbox), frame, -1);
     }
 }
 
@@ -185,17 +185,10 @@ populate_flowbox_images (GtkFlowBox *flowbox)
 static void
 populate_items (GtkFlowBox *flowbox)
 {
-  GList *children, *l;
-
-  /* Remove all children first */
-  children = gtk_container_get_children (GTK_CONTAINER (flowbox));
-  for (l = children; l; l = l->next)
-    {
-      GtkWidget *child = l->data;
+  GtkWidget *child;
 
-      gtk_container_remove (GTK_CONTAINER (flowbox), child);
-    }
-  g_list_free (children);
+  while ((child = gtk_widget_get_first_child (GTK_WIDGET (flowbox))))
+    gtk_flow_box_remove (flowbox, child);
 
   if (items_type == SIMPLE_ITEMS)
     populate_flowbox_simple (flowbox);


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