[gtk/kill-containers: 45/76] Stop using container api for GtkStack



commit 686eb4c37c92f6b472f4f30f2772ec90f6d69868
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu May 7 15:55:10 2020 -0400

    Stop using container api for GtkStack

 gtk/gtkmenusectionbox.c   | 16 +++++-----------
 gtk/gtknotebook.c         |  4 ++--
 gtk/gtkpopovermenu.c      |  2 +-
 gtk/gtkshortcutssection.c | 42 +++++++++++++++++-------------------------
 gtk/gtkshortcutswindow.c  | 34 ++++++++++++++++++----------------
 gtk/gtktreepopover.c      | 19 +++++++++----------
 6 files changed, 52 insertions(+), 65 deletions(-)
---
diff --git a/gtk/gtkmenusectionbox.c b/gtk/gtkmenusectionbox.c
index 6a36ae7510..072b3287ca 100644
--- a/gtk/gtkmenusectionbox.c
+++ b/gtk/gtkmenusectionbox.c
@@ -226,7 +226,7 @@ gtk_menu_section_box_remove_func (gint     position,
       stack = gtk_widget_get_ancestor (GTK_WIDGET (box->toplevel), GTK_TYPE_STACK);
       subbox = gtk_stack_get_child_by_name (GTK_STACK (stack), gtk_menu_tracker_item_get_label (item));
       if (subbox != NULL)
-        gtk_container_remove (GTK_CONTAINER (stack), subbox);
+        gtk_stack_remove (GTK_STACK (stack), subbox);
     }
 
   gtk_container_remove (GTK_CONTAINER (box->item_box),
@@ -476,18 +476,14 @@ update_popover_position_cb (GObject    *source,
 {
   GtkPopover *popover = GTK_POPOVER (source);
   GtkMenuSectionBox *box = GTK_MENU_SECTION_BOX (user_data);
+  GtkWidget *w;
 
   GtkPositionType new_pos = gtk_popover_get_position (popover);
 
-  GList *children = gtk_container_get_children (GTK_CONTAINER (gtk_widget_get_parent (GTK_WIDGET (box))));
-  GList *l;
-
-  for (l = children;
-       l != NULL;
-       l = l->next)
+  for (w = gtk_widget_get_first_child (gtk_widget_get_parent (GTK_WIDGET (box)));
+       w != NULL;
+       w = gtk_widget_get_next_sibling (w))
     {
-      GtkWidget *w = l->data;
-
       if (new_pos == GTK_POS_BOTTOM)
         gtk_widget_set_valign (w, GTK_ALIGN_START);
       else if (new_pos == GTK_POS_TOP)
@@ -495,8 +491,6 @@ update_popover_position_cb (GObject    *source,
       else
         gtk_widget_set_valign (w, GTK_ALIGN_CENTER);
     }
-
-  g_list_free (children);
 }
 
 void
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index c0b128408a..ae3038cb71 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -4002,7 +4002,7 @@ gtk_notebook_insert_notebook_page (GtkNotebook *notebook,
   if (notebook->menu)
     gtk_notebook_menu_item_create (notebook, page);
 
-  gtk_container_add (GTK_CONTAINER (notebook->stack_widget), page->child);
+  gtk_stack_add_named (GTK_STACK (notebook->stack_widget), page->child, NULL);
 
   if (page->tab_label)
     {
@@ -4219,7 +4219,7 @@ gtk_notebook_real_remove (GtkNotebook *notebook,
       gtk_widget_get_visible (GTK_WIDGET (notebook)))
     need_resize = TRUE;
 
-  gtk_container_remove (GTK_CONTAINER (notebook->stack_widget), page->child);
+  gtk_stack_remove (GTK_STACK (notebook->stack_widget), page->child);
 
   tab_label = page->tab_label;
   if (tab_label)
diff --git a/gtk/gtkpopovermenu.c b/gtk/gtkpopovermenu.c
index eacd370f6b..d7655ff35b 100644
--- a/gtk/gtkpopovermenu.c
+++ b/gtk/gtkpopovermenu.c
@@ -685,7 +685,7 @@ gtk_popover_menu_set_menu_model (GtkPopoverMenu *popover,
 
       stack = gtk_popover_get_child (GTK_POPOVER (popover));
       while ((child = gtk_widget_get_first_child (stack)))
-        gtk_container_remove (GTK_CONTAINER (stack), child);
+        gtk_stack_remove (GTK_STACK (stack), child);
 
       if (model)
         gtk_menu_section_box_new_toplevel (popover, model, popover->flags);
diff --git a/gtk/gtkshortcutssection.c b/gtk/gtkshortcutssection.c
index 4df299fe1f..73d09a9021 100644
--- a/gtk/gtkshortcutssection.c
+++ b/gtk/gtkshortcutssection.c
@@ -488,28 +488,21 @@ static void
 gtk_shortcuts_section_add_group (GtkShortcutsSection *self,
                                  GtkShortcutsGroup   *group)
 {
-  GList *children;
   GtkWidget *page, *column;
 
-  children = gtk_container_get_children (GTK_CONTAINER (self->stack));
-  if (children)
-    page = g_list_last (children)->data;
-  else
+  page = gtk_widget_get_last_child (GTK_WIDGET (self->stack));
+  if (page == NULL)
     {
       page = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 22);
       gtk_stack_add_named (self->stack, page, "1");
     }
-  g_list_free (children);
 
-  children = gtk_container_get_children (GTK_CONTAINER (page));
-  if (children)
-    column = g_list_last (children)->data;
-  else
+  column = gtk_widget_get_last_child (page);
+  if (column == NULL)
     {
       column = gtk_box_new (GTK_ORIENTATION_VERTICAL, 22);
       gtk_container_add (GTK_CONTAINER (page), column);
     }
-  g_list_free (children);
 
   gtk_container_add (GTK_CONTAINER (column), GTK_WIDGET (group));
   self->groups = g_list_append (self->groups, group);
@@ -565,8 +558,8 @@ gtk_shortcuts_section_filter_groups (GtkShortcutsSection *self)
 static void
 gtk_shortcuts_section_reflow_groups (GtkShortcutsSection *self)
 {
+  GtkWidget *page, *column;
   GList *pages, *p;
-  GList *columns, *c;
   GList *groups, *g;
   GList *children;
   guint n_rows;
@@ -576,22 +569,23 @@ gtk_shortcuts_section_reflow_groups (GtkShortcutsSection *self)
 
   /* collect all groups from the current pages */
   groups = NULL;
-  pages = gtk_container_get_children (GTK_CONTAINER (self->stack));
-  for (p = pages; p; p = p->next)
+  for (page = gtk_widget_get_first_child (GTK_WIDGET (self->stack));
+       page != NULL;
+       page = gtk_widget_get_next_sibling (page))
     {
-      columns = gtk_container_get_children (GTK_CONTAINER (p->data));
-      for (c = columns; c; c = c->next)
+      for (column = gtk_widget_get_first_child (page);
+           column != NULL;
+           column = gtk_widget_get_next_sibling (column))
         {
-          children = gtk_container_get_children (GTK_CONTAINER (c->data));
+          children = gtk_container_get_children (GTK_CONTAINER (column));
           groups = g_list_concat (groups, children);
         }
-      g_list_free (columns);
     }
-  g_list_free (pages);
 
   /* create new pages */
   current_page = NULL;
   current_column = NULL;
+
   pages = NULL;
   n_rows = 0;
   n_columns = 0;
@@ -623,8 +617,6 @@ gtk_shortcuts_section_reflow_groups (GtkShortcutsSection *self)
 
           if (n_columns % 2 == 0)
             {
-              GtkWidget *page;
-
               page = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 22);
 
               pages = g_list_append (pages, page);
@@ -712,14 +704,14 @@ gtk_shortcuts_section_reflow_groups (GtkShortcutsSection *self)
     }
 
   /* replace the current pages with the new pages */
-  children = gtk_container_get_children (GTK_CONTAINER (self->stack));
-  g_list_free_full (children, (GDestroyNotify)gtk_widget_destroy);
+  while ((page = gtk_widget_get_first_child (GTK_WIDGET (self->stack))))
+    gtk_stack_remove (self->stack, page);
 
   for (p = pages, n_pages = 0; p; p = p->next, n_pages++)
     {
-      GtkWidget *page = p->data;
-      gchar *title;
+      char *title;
 
+      page = p->data;
       title = g_strdup_printf ("_%u", n_pages + 1);
       gtk_stack_add_titled (self->stack, page, title, title);
       g_free (title);
diff --git a/gtk/gtkshortcutswindow.c b/gtk/gtkshortcutswindow.c
index 93d3b40bff..68ce8b8c70 100644
--- a/gtk/gtkshortcutswindow.c
+++ b/gtk/gtkshortcutswindow.c
@@ -160,17 +160,21 @@ static GParamSpec *properties[LAST_PROP];
 static guint signals[LAST_SIGNAL];
 
 
-static gint
-number_of_children (GtkContainer *container)
+static gboolean
+more_than_three_children (GtkWidget *widget)
 {
-  GList *children;
-  gint n;
+  GtkWidget *child;
+  int i;
 
-  children = gtk_container_get_children (container);
-  n = g_list_length (children);
-  g_list_free (children);
+  for (child = gtk_widget_get_first_child (widget), i = 0;
+       child != NULL;
+       child = gtk_widget_get_next_sibling (child), i++)
+    {
+      if (i == 3)
+        return TRUE;
+    }
 
-  return n;
+  return FALSE;
 }
 
 static void
@@ -183,9 +187,9 @@ update_title_stack (GtkShortcutsWindow *self)
 
   if (GTK_IS_SHORTCUTS_SECTION (visible_child))
     {
-      if (number_of_children (GTK_CONTAINER (priv->stack)) > 3)
+      if (more_than_three_children (GTK_WIDGET (priv->stack)))
         {
-          gchar *title;
+          char *title;
 
           gtk_stack_set_visible_child_name (priv->title_stack, "sections");
           g_object_get (visible_child, "title", &title, NULL);
@@ -402,20 +406,18 @@ gtk_shortcuts_window_set_view_name (GtkShortcutsWindow *self,
                                     const gchar        *view_name)
 {
   GtkShortcutsWindowPrivate *priv = gtk_shortcuts_window_get_instance_private (self);
-  GList *sections, *l;
+  GtkWidget *section;
 
   g_free (priv->view_name);
   priv->view_name = g_strdup (view_name);
 
-  sections = gtk_container_get_children (GTK_CONTAINER (priv->stack));
-  for (l = sections; l; l = l->next)
+  for (section = gtk_widget_get_first_child (GTK_WIDGET (priv->stack));
+       section != NULL;
+       section = gtk_widget_get_next_sibling (section))
     {
-      GtkShortcutsSection *section = l->data;
-
       if (GTK_IS_SHORTCUTS_SECTION (section))
         g_object_set (section, "view-name", priv->view_name, NULL);
     }
-  g_list_free (sections);
 }
 
 static void
diff --git a/gtk/gtktreepopover.c b/gtk/gtktreepopover.c
index c60ec32aa0..7bfbec827d 100644
--- a/gtk/gtktreepopover.c
+++ b/gtk/gtktreepopover.c
@@ -466,15 +466,14 @@ gtk_tree_popover_get_path_item (GtkTreePopover *popover,
 {
   GtkWidget *stack = gtk_popover_get_child (GTK_POPOVER (popover));
   GtkWidget *item = NULL;
-  GList *children, *l;
-
-  children = gtk_container_get_children (GTK_CONTAINER (stack));
+  GtkWidget *stackchild;
+  GtkWidget *child;
 
-  for (l = children; !item && l; l = l->next)
+  for (stackchild = gtk_widget_get_first_child (stack);
+       stackchild != NULL;
+       stackchild = gtk_widget_get_next_sibling (stackchild))
     {
-      GtkWidget *child;
-
-      for (child = gtk_widget_get_first_child (GTK_WIDGET (l->data));
+      for (child = gtk_widget_get_first_child (stackchild);
            !item && child;
            child = gtk_widget_get_next_sibling (child))
         {
@@ -510,8 +509,6 @@ gtk_tree_popover_get_path_item (GtkTreePopover *popover,
         }
     }
 
-  g_list_free (children);
-
   return item;
 }
 
@@ -732,9 +729,11 @@ static void
 rebuild_menu (GtkTreePopover *popover)
 {
   GtkWidget *stack;
+  GtkWidget *child;
 
   stack = gtk_popover_get_child (GTK_POPOVER (popover));
-  gtk_container_foreach (GTK_CONTAINER (stack), (GtkCallback) gtk_widget_destroy, NULL);
+  while ((child = gtk_widget_get_first_child (stack)))
+    gtk_widget_destroy (child);
 
   if (popover->model)
     gtk_tree_popover_populate (popover);


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