[gtk/wip/matthiasc/box3] Redo using reorder_child



commit 1ea403caf049252cda2c46c9fa4d2419c6457cba
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jan 22 22:15:50 2019 -0500

    Redo using reorder_child
    
    Replace new insertion api with a sibling-based
    reorder_child. Update all callers.

 gtk/gtkactionbar.c          | 10 ++++++----
 gtk/gtkassistant.c          | 16 ++++++----------
 gtk/gtkbbox.c               | 10 +---------
 gtk/gtkbox.c                | 35 ++++++++++++-----------------------
 gtk/gtkbox.h                | 16 +++-------------
 gtk/gtkcolorchooserwidget.c |  3 ++-
 gtk/gtkcombobox.c           |  8 ++++++--
 gtk/gtkfilechooserwidget.c  | 11 +++++------
 gtk/gtkheaderbar.c          |  5 ++---
 gtk/gtkmenusectionbox.c     | 16 +++++++++++-----
 gtk/gtkmodelmenuitem.c      |  3 ++-
 gtk/gtknotebook.c           | 20 +++++++++++---------
 gtk/gtkscalebutton.c        | 14 ++++----------
 gtk/gtkspinbutton.c         | 14 ++++----------
 gtk/gtkstackswitcher.c      |  7 ++-----
 gtk/gtktreeviewcolumn.c     |  7 ++-----
 16 files changed, 79 insertions(+), 116 deletions(-)
---
diff --git a/gtk/gtkactionbar.c b/gtk/gtkactionbar.c
index 4782ba2b24..4a6aee147b 100644
--- a/gtk/gtkactionbar.c
+++ b/gtk/gtkactionbar.c
@@ -184,7 +184,8 @@ gtk_action_bar_set_child_property (GtkContainer *container,
             {
               g_object_ref (child);
               gtk_container_remove (GTK_CONTAINER (priv->start_box), child);
-              gtk_box_prepend (GTK_BOX (priv->end_box), child);
+              gtk_container_add (GTK_CONTAINER (priv->end_box), child);
+              gtk_box_reorder_child (GTK_BOX (priv->end_box), child, gtk_widget_get_first_child 
(priv->end_box));
               g_object_unref (child);
             }
         }
@@ -194,7 +195,7 @@ gtk_action_bar_set_child_property (GtkContainer *container,
             {
               g_object_ref (child);
               gtk_container_remove (GTK_CONTAINER (priv->end_box), child);
-              gtk_box_append (GTK_BOX (priv->start_box), child);
+              gtk_container_add (GTK_CONTAINER (priv->start_box), child);
               g_object_unref (child);
             }
         }
@@ -407,7 +408,7 @@ gtk_action_bar_pack_start (GtkActionBar *action_bar,
 {
   GtkActionBarPrivate *priv = gtk_action_bar_get_instance_private (action_bar);
 
-  gtk_box_append (GTK_BOX (priv->start_box), child);
+  gtk_container_add (GTK_CONTAINER (priv->start_box), child);
 }
 
 /**
@@ -424,7 +425,8 @@ gtk_action_bar_pack_end (GtkActionBar *action_bar,
 {
   GtkActionBarPrivate *priv = gtk_action_bar_get_instance_private (action_bar);
 
-  gtk_box_prepend (GTK_BOX (priv->end_box), child);
+  gtk_container_add (GTK_CONTAINER (priv->end_box), child);
+  gtk_box_reorder_child (GTK_BOX (priv->end_box), child, gtk_widget_get_first_child (priv->end_box));
 }
 
 /**
diff --git a/gtk/gtkassistant.c b/gtk/gtkassistant.c
index 9b3189524f..c37f4e7da6 100644
--- a/gtk/gtkassistant.c
+++ b/gtk/gtkassistant.c
@@ -1125,13 +1125,7 @@ gtk_assistant_init (GtkAssistant *assistant)
       buttons = gtk_container_get_children (GTK_CONTAINER (priv->action_area));
 
       for (l = buttons; l; l = l->next)
-        {
-          GtkWidget *child = l->data;
-          g_object_ref (child);
-          gtk_container_remove (GTK_CONTAINER (priv->action_area), child);
-          gtk_box_prepend (GTK_BOX (priv->action_area), child);
-          g_object_unref (child);
-        }
+        gtk_box_reorder_child (GTK_BOX (priv->action_area), GTK_WIDGET (l->data), NULL);
 
       g_list_free (buttons);
     }
@@ -1699,12 +1693,14 @@ gtk_assistant_insert_page (GtkAssistant *assistant,
     {
       int i;
       sibling = gtk_widget_get_first_child (priv->sidebar);
-      for (i = 1; i < 2 * position; i++)
+      for (i = 0; i < 2 * position; i++)
         sibling = gtk_widget_get_next_sibling (sibling);
     }
 
-  gtk_box_insert_after (GTK_BOX (priv->sidebar), page_info->regular_title, sibling);
-  gtk_box_insert_after (GTK_BOX (priv->sidebar), page_info->current_title,  page_info->regular_title);
+  gtk_container_add (GTK_CONTAINER (priv->sidebar), page_info->regular_title);
+  gtk_container_add (GTK_CONTAINER (priv->sidebar), page_info->current_title);
+  gtk_box_reorder_child (GTK_BOX (priv->sidebar), page_info->regular_title, sibling);
+  gtk_box_reorder_child (GTK_BOX (priv->sidebar), page_info->current_title, sibling);
 
   box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
   gtk_widget_show (box);
diff --git a/gtk/gtkbbox.c b/gtk/gtkbbox.c
index 1107638888..31e4926ff6 100644
--- a/gtk/gtkbbox.c
+++ b/gtk/gtkbbox.c
@@ -386,15 +386,7 @@ gtk_button_box_set_child_secondary (GtkButtonBox *widget,
   gtk_widget_child_notify (child, "secondary");
 
   if (bbox->priv->layout_style == GTK_BUTTONBOX_EXPAND)
-    {
-      g_object_ref (child);
-      gtk_container_remove (GTK_CONTAINER (bbox), child);
-      if (is_secondary)
-        gtk_box_prepend (GTK_CONTAINER (bbox), child);
-      else
-        gtk_box_append (GTK_CONTAINER (bbox), child);
-      g_object_unref (child);
-    }
+    gtk_box_reorder_child (GTK_BOX (bbox), child, is_secondary ? gtk_widget_get_first_child (GTK_WIDGET 
(bbox)) : NULL);
 
   if (gtk_widget_get_visible (GTK_WIDGET (widget)) &&
       gtk_widget_get_visible (child))
diff --git a/gtk/gtkbox.c b/gtk/gtkbox.c
index b59e244ae4..5c7cb64f0a 100644
--- a/gtk/gtkbox.c
+++ b/gtk/gtkbox.c
@@ -45,6 +45,9 @@
  * minimally placed between all children in the GtkBox. Note that
  * spacing is added between the children.
  *
+ * Use gtk_box_reorder_child() to move a GtkBox child to a different
+ * place in the box.
+ *
  * # CSS nodes
  *
  * GtkBox uses a single CSS node with name box.
@@ -1094,31 +1097,17 @@ _gtk_box_get_children (GtkBox *box)
 }
 
 void
-gtk_box_prepend (GtkBox    *box,
-                 GtkWidget *child)
-{
-  gtk_widget_insert_after (child, GTK_WIDGET (box), NULL);
-}
-
-void
-gtk_box_append (GtkBox    *box,
-                GtkWidget *child)
-{
-  gtk_widget_insert_before (child, GTK_WIDGET (box), NULL);
-}
-
-void
-gtk_box_insert_before (GtkBox    *box,
+gtk_box_reorder_child (GtkBox    *box,
                        GtkWidget *child,
                        GtkWidget *sibling)
 {
-  gtk_widget_insert_before (child, GTK_WIDGET (box), sibling);
-}
+  GtkWidget *widget = GTK_WIDGET (box);
 
-void
-gtk_box_insert_after (GtkBox    *box,
-                      GtkWidget *child,
-                      GtkWidget *sibling)
-{
-  gtk_widget_insert_after (child, GTK_WIDGET (box), sibling);
+  if (child == sibling)
+    return;
+
+  gtk_widget_insert_before (child, widget, sibling);
+  gtk_css_node_insert_before (gtk_widget_get_css_node (widget),
+                              gtk_widget_get_css_node (child),
+                              sibling ? gtk_widget_get_css_node (sibling) : NULL);
 }
diff --git a/gtk/gtkbox.h b/gtk/gtkbox.h
index c746ab64bf..911015e219 100644
--- a/gtk/gtkbox.h
+++ b/gtk/gtkbox.h
@@ -92,19 +92,9 @@ GDK_AVAILABLE_IN_ALL
 GtkBaselinePosition gtk_box_get_baseline_position (GtkBox         *box);
 
 GDK_AVAILABLE_IN_ALL
-void        gtk_box_prepend             (GtkBox         *box,
-                                         GtkWidget      *child);
-GDK_AVAILABLE_IN_ALL
-void        gtk_box_append              (GtkBox         *box,
-                                         GtkWidget      *child);
-GDK_AVAILABLE_IN_ALL
-void        gtk_box_insert_before       (GtkBox         *box,
-                                         GtkWidget      *child,
-                                         GtkWidget      *sibling);
-GDK_AVAILABLE_IN_ALL
-void        gtk_box_insert_after        (GtkBox         *box,
-                                         GtkWidget      *child,
-                                         GtkWidget      *sibling);
+void        gtk_box_reorder_child (GtkBox         *box,
+                                   GtkWidget      *child,
+                                   GtkWidget      *sibling);
 
 
 G_END_DECLS
diff --git a/gtk/gtkcolorchooserwidget.c b/gtk/gtkcolorchooserwidget.c
index e028d96ade..e6b0290a61 100644
--- a/gtk/gtkcolorchooserwidget.c
+++ b/gtk/gtkcolorchooserwidget.c
@@ -745,7 +745,8 @@ add_custom_color (GtkColorChooserWidget *cc,
   gtk_color_swatch_set_can_drop (GTK_COLOR_SWATCH (p), TRUE);
   connect_custom_signals (p, cc);
 
-  gtk_box_insert_after (GTK_BOX (cc->priv->custom), p, gtk_widget_get_first_child (cc->priv->custom));
+  gtk_container_add (GTK_CONTAINER (cc->priv->custom), p);
+  gtk_box_reorder_child (GTK_BOX (cc->priv->custom), p, gtk_widget_get_next_sibling 
(gtk_widget_get_first_child (cc->priv->custom)));
   gtk_widget_show (p);
 
   select_swatch (cc, GTK_COLOR_SWATCH (p));
diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c
index e9e705f872..c5342beac6 100644
--- a/gtk/gtkcombobox.c
+++ b/gtk/gtkcombobox.c
@@ -1151,12 +1151,15 @@ gtk_combo_box_create_child (GtkComboBox *combo_box)
     }
   else
     {
+      GtkWidget *parent; 
       child = gtk_cell_view_new_with_context (priv->area, NULL);
       priv->cell_view = child;
       gtk_widget_set_hexpand (child, TRUE);
       gtk_cell_view_set_fit_model (GTK_CELL_VIEW (priv->cell_view), TRUE);
       gtk_cell_view_set_model (GTK_CELL_VIEW (priv->cell_view), priv->model);
-      gtk_box_prepend (GTK_BOX (gtk_widget_get_parent (priv->arrow)), priv->cell_view);
+      parent = gtk_widget_get_parent (priv->arrow);
+      gtk_container_add (GTK_CONTAINER (parent), priv->cell_view);
+      gtk_box_reorder_child (GTK_BOX (parent), priv->cell_view, gtk_widget_get_first_child (parent));
       _gtk_bin_set_child (GTK_BIN (combo_box), priv->cell_view);
     }
 }
@@ -1191,7 +1194,8 @@ gtk_combo_box_add (GtkContainer *container,
     }
 
   gtk_widget_set_hexpand (widget, TRUE);
-  gtk_box_prepend (GTK_BOX (priv->box), widget);
+  gtk_container_add (GTK_CONTAINER (priv->box), widget);
+  gtk_box_reorder_child (GTK_BOX (priv->box), widget, gtk_widget_get_first_child (priv->box));
   _gtk_bin_set_child (GTK_BIN (container), widget);
 
   if (priv->has_entry)
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index b7babfbf78..5ee15f7c8f 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -916,7 +916,8 @@ update_preview_widget_visibility (GtkFileChooserWidget *impl)
       if (!priv->preview_label)
         {
           priv->preview_label = gtk_label_new (priv->preview_display_name);
-          gtk_box_prepend (GTK_BOX (priv->preview_box), priv->preview_label);
+          gtk_container_add (GTK_CONTAINER (priv->preview_box), priv->preview_label);
+          gtk_box_reorder_child (GTK_BOX (priv->preview_box), priv->preview_label, 
gtk_widget_get_first_child (priv->preview_box));
           gtk_label_set_ellipsize (GTK_LABEL (priv->preview_label), PANGO_ELLIPSIZE_MIDDLE);
           gtk_widget_show (priv->preview_label);
         }
@@ -956,10 +957,7 @@ set_preview_widget (GtkFileChooserWidget *impl,
   if (priv->preview_widget)
     {
       gtk_widget_show (priv->preview_widget);
-      if (priv->use_preview_label && priv->preview_label)
-        gtk_box_insert_after (GTK_BOX (priv->preview_box), priv->preview_widget, priv->preview_label);
-      else
-        gtk_box_prepend (GTK_BOX (priv->preview_box), priv->preview_widget);
+      gtk_container_add (GTK_CONTAINER (priv->preview_box), priv->preview_widget);
     }
 
   update_preview_widget_visibility (impl);
@@ -2606,7 +2604,8 @@ save_widgets_create (GtkFileChooserWidget *impl)
   gtk_label_set_mnemonic_widget (GTK_LABEL (widget), priv->location_entry);
 
   priv->save_widgets = vbox;
-  gtk_box_prepend (GTK_BOX (priv->box), priv->save_widgets);
+  gtk_container_add (GTK_CONTAINER (priv->box), priv->save_widgets);
+  gtk_box_reorder_child (GTK_BOX (priv->box), priv->save_widgets, gtk_widget_get_first_child (priv->box));
   gtk_widget_show (priv->save_widgets);
 }
 
diff --git a/gtk/gtkheaderbar.c b/gtk/gtkheaderbar.c
index 4a61a6e9c7..3070b56f5b 100644
--- a/gtk/gtkheaderbar.c
+++ b/gtk/gtkheaderbar.c
@@ -468,10 +468,9 @@ _gtk_header_bar_update_window_buttons (GtkHeaderBar *bar)
               continue;
             }
 
+          gtk_container_add (GTK_CONTAINER (box), separator);
           if (i == 1)
-            gtk_box_prepend (GTK_BOX (box), separator);
-          else
-            gtk_box_append (GTK_BOX (box), separator);
+            gtk_box_reorder_child (GTK_BOX (box), separator, gtk_widget_get_first_child (box));
 
           if (i == 0)
             gtk_style_context_add_class (gtk_widget_get_style_context (box), GTK_STYLE_CLASS_LEFT);
diff --git a/gtk/gtkmenusectionbox.c b/gtk/gtkmenusectionbox.c
index 98d2b71843..a24e8cc64d 100644
--- a/gtk/gtkmenusectionbox.c
+++ b/gtk/gtkmenusectionbox.c
@@ -134,7 +134,10 @@ gtk_menu_section_box_sync_separators (GtkMenuSectionBox *box,
     return;
 
   if (should_have_separator)
-    gtk_box_prepend (GTK_BOX (box), box->separator);
+    {
+      gtk_container_add (GTK_CONTAINER (box), box->separator);
+      gtk_box_reorder_child (GTK_BOX (box), box->separator, gtk_widget_get_first_child (GTK_WIDGET (box)));
+    }
   else
     gtk_container_remove (GTK_CONTAINER (box), box->separator);
 }
@@ -329,15 +332,17 @@ gtk_menu_section_box_insert_func (GtkMenuTrackerItem *item,
   g_object_set_data_full (G_OBJECT (widget), "GtkMenuTrackerItem", g_object_ref (item), g_object_unref);
 
   gtk_widget_set_halign (widget, GTK_ALIGN_FILL);
+  gtk_container_add (GTK_CONTAINER (box->item_box), widget);
+
   if (position == 0)
-    gtk_box_prepend (GTK_BOX (box->item_box), widget);
+    gtk_box_reorder_child (GTK_BOX (box->item_box), widget, gtk_widget_get_first_child (GTK_WIDGET 
(box->item_box)));
   else
     {
       GtkWidget *sibling = gtk_widget_get_first_child (GTK_WIDGET (box->item_box));
       int i;
-      for (i = 1; i < position; i++)
+      for (i = 0; i < position; i++)
         sibling = gtk_widget_get_next_sibling (sibling);
-      gtk_box_insert_after (GTK_BOX (box->item_box), widget, sibling);
+      gtk_box_reorder_child (GTK_BOX (box->item_box), widget, sibling);
     }
 
   gtk_menu_section_box_schedule_separator_sync (box);
@@ -462,7 +467,8 @@ gtk_menu_section_box_new_submenu (GtkMenuTrackerItem *item,
   g_object_set_data (G_OBJECT (button), "focus", focus);
   g_object_set_data (G_OBJECT (focus), "focus", button);
 
-  gtk_box_prepend (GTK_BOX (box), button);
+  gtk_container_add (GTK_CONTAINER (box), button);
+  gtk_box_reorder_child (GTK_BOX (box), button, gtk_widget_get_first_child (GTK_WIDGET (box)));
 
   g_signal_connect (focus, "clicked", G_CALLBACK (open_submenu), item);
   g_signal_connect (button, "clicked", G_CALLBACK (close_submenu), item);
diff --git a/gtk/gtkmodelmenuitem.c b/gtk/gtkmodelmenuitem.c
index ef927fa8d2..ca300d2150 100644
--- a/gtk/gtkmodelmenuitem.c
+++ b/gtk/gtkmodelmenuitem.c
@@ -191,7 +191,8 @@ gtk_model_menu_item_set_icon (GtkModelMenuItem *item,
 
       image = gtk_image_new_from_gicon (icon);
       gtk_image_set_pixel_size (GTK_IMAGE (image), 16);
-      gtk_box_prepend (GTK_BOX (child), image);
+      gtk_container_add (GTK_CONTAINER (child), image);
+      gtk_box_reorder_child (GTK_BOX (child), image, gtk_widget_get_first_child (child));
     }
 
   g_object_notify (G_OBJECT (item), "icon");
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 3d50a98f4d..f2d59620b8 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -6198,8 +6198,6 @@ gtk_notebook_update_tab_pos (GtkNotebook *notebook)
                                         tab_pos_names[i]);
     }
 
-  g_object_ref (priv->header_widget);
-  gtk_container_remove (GTK_CONTAINER (priv->box), priv->header_widget);
   switch (tab_pos)
     {
     case GTK_POS_TOP:
@@ -6207,7 +6205,8 @@ gtk_notebook_update_tab_pos (GtkNotebook *notebook)
       gtk_widget_set_vexpand (priv->tabs_widget, FALSE);
       gtk_widget_set_hexpand (priv->header_widget, TRUE);
       gtk_widget_set_vexpand (priv->header_widget, FALSE);
-      gtk_box_prepend (GTK_BOX (priv->box), priv->header_widget);
+      if (priv->show_tabs)
+        gtk_box_reorder_child (GTK_BOX (priv->box), priv->header_widget, gtk_widget_get_first_child 
(priv->box));
 
       gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->box), GTK_ORIENTATION_VERTICAL);
       gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->header_widget), GTK_ORIENTATION_HORIZONTAL);
@@ -6218,7 +6217,8 @@ gtk_notebook_update_tab_pos (GtkNotebook *notebook)
       gtk_widget_set_vexpand (priv->tabs_widget, FALSE);
       gtk_widget_set_hexpand (priv->header_widget, TRUE);
       gtk_widget_set_vexpand (priv->header_widget, FALSE);
-      gtk_box_append (GTK_BOX (priv->box), priv->header_widget);
+      if (priv->show_tabs)
+        gtk_box_reorder_child (GTK_BOX (priv->box), priv->header_widget, NULL);
 
       gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->box), GTK_ORIENTATION_VERTICAL);
       gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->header_widget), GTK_ORIENTATION_HORIZONTAL);
@@ -6229,7 +6229,8 @@ gtk_notebook_update_tab_pos (GtkNotebook *notebook)
       gtk_widget_set_vexpand (priv->tabs_widget, TRUE);
       gtk_widget_set_hexpand (priv->header_widget, FALSE);
       gtk_widget_set_vexpand (priv->header_widget, TRUE);
-      gtk_box_prepend (GTK_BOX (priv->box), priv->header_widget);
+      if (priv->show_tabs)
+        gtk_box_reorder_child (GTK_BOX (priv->box), priv->header_widget, gtk_widget_get_first_child 
(priv->box));
 
       gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->box), GTK_ORIENTATION_HORIZONTAL);
       gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->header_widget), GTK_ORIENTATION_VERTICAL);
@@ -6240,7 +6241,8 @@ gtk_notebook_update_tab_pos (GtkNotebook *notebook)
       gtk_widget_set_vexpand (priv->tabs_widget, TRUE);
       gtk_widget_set_hexpand (priv->header_widget, FALSE);
       gtk_widget_set_vexpand (priv->header_widget, TRUE);
-      gtk_box_append (GTK_BOX (priv->box), priv->header_widget);
+      if (priv->show_tabs)
+        gtk_box_reorder_child (GTK_BOX (priv->box), priv->header_widget, NULL);
 
       gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->box), GTK_ORIENTATION_HORIZONTAL);
       gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->header_widget), GTK_ORIENTATION_VERTICAL);
@@ -6249,7 +6251,6 @@ gtk_notebook_update_tab_pos (GtkNotebook *notebook)
       g_assert_not_reached ();
       break;
     }
-  g_object_unref (priv->header_widget);
 }
 
 /**
@@ -7148,10 +7149,11 @@ gtk_notebook_set_action_widget (GtkNotebook *notebook,
 
   if (widget)
     {
+      gtk_container_add (GTK_CONTAINER (priv->header_widget), widget);
       if (pack_type == GTK_PACK_START)
-        gtk_box_prepend (GTK_BOX (priv->header_widget), widget);
+        gtk_box_reorder_child (GTK_BOX (priv->header_widget), widget, gtk_widget_get_first_child 
(priv->header_widget));
       else
-        gtk_box_append (GTK_BOX (priv->header_widget), widget);
+        gtk_box_reorder_child (GTK_BOX (priv->header_widget), widget, NULL);
       gtk_widget_set_child_visible (widget, priv->show_tabs);
     }
 
diff --git a/gtk/gtkscalebutton.c b/gtk/gtkscalebutton.c
index 924cf9715f..343e4712cc 100644
--- a/gtk/gtkscalebutton.c
+++ b/gtk/gtkscalebutton.c
@@ -725,22 +725,16 @@ apply_orientation (GtkScaleButton *button,
       priv->applied_orientation = orientation;
       gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->box), orientation);
 
-      g_object_ref (priv->minus_button);
-      g_object_ref (priv->plus_button);
-      gtk_container_remove (GTK_CONTAINER (priv->box), priv->minus_button);
-      gtk_container_remove (GTK_CONTAINER (priv->box), priv->plus_button);
       if (orientation == GTK_ORIENTATION_HORIZONTAL)
         {
-          gtk_box_insert_after (GTK_BOX (priv->box), priv->minus_button, priv->scale);
-          gtk_box_insert_after (GTK_BOX (priv->box), priv->plus_button, priv->minus_button);
+          gtk_box_reorder_child (GTK_BOX (priv->box), priv->minus_button, NULL);
+          gtk_box_reorder_child (GTK_BOX (priv->box), priv->plus_button, NULL);
         }
       else
         {
-          gtk_box_insert_after (GTK_BOX (priv->box), priv->minus_button, priv->scale);
-          gtk_box_insert_before (GTK_BOX (priv->box), priv->plus_button, priv->scale);
+          gtk_box_reorder_child (GTK_BOX (priv->box), priv->scale, NULL);
+          gtk_box_reorder_child (GTK_BOX (priv->box), priv->minus_button, NULL);
         }
-      g_object_unref (priv->plus_button);
-      g_object_unref (priv->minus_button);
 
       gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->scale), orientation);
 
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index 27c58406e1..084aa676eb 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -1037,24 +1037,18 @@ gtk_spin_button_set_orientation (GtkSpinButton  *spin,
            gtk_entry_get_alignment (entry) == 0.5)
     gtk_entry_set_alignment (entry, 0.0);
 
-  g_object_ref (priv->up_button);
-  g_object_ref (priv->down_button);
-  gtk_container_remove (GTK_CONTAINER (priv->box), priv->up_button);
-  gtk_container_remove (GTK_CONTAINER (priv->box), priv->down_button);
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
     {
       /* Current orientation of the box is vertical! */
-      gtk_box_insert_after (GTK_BOX (priv->box), priv->up_button, priv->entry);
-      gtk_box_insert_after (GTK_BOX (priv->box), priv->down_button, priv->up_button);
+      gtk_box_reorder_child (GTK_BOX (priv->box), priv->down_button, NULL);
+      gtk_box_reorder_child (GTK_BOX (priv->box), priv->up_button, NULL);
     }
   else
     {
       /* Current orientation of the box is horizontal! */
-      gtk_box_insert_before (GTK_BOX (priv->box), priv->up_button, priv->entry);
-      gtk_box_insert_after (GTK_BOX (priv->box), priv->down_button, priv->entry);
+      gtk_box_reorder_child (GTK_BOX (priv->box), priv->entry, NULL);
+      gtk_box_reorder_child (GTK_BOX (priv->box), priv->down_button, NULL);
     }
-  g_object_unref (priv->up_button);
-  g_object_unref (priv->down_button);
 
   gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->box), priv->orientation);
 
diff --git a/gtk/gtkstackswitcher.c b/gtk/gtkstackswitcher.c
index 0e9e11689f..7e8145077a 100644
--- a/gtk/gtkstackswitcher.c
+++ b/gtk/gtkstackswitcher.c
@@ -235,19 +235,16 @@ on_position_updated (GtkWidget        *widget,
                            "position", &position,
                            NULL);
 
-  g_object_ref (button);
-  gtk_container_remove (GTK_BOX (self), button);
   if (position == 0)
-    gtk_box_prepend (GTK_BOX (self), button);
+    gtk_box_reorder_child (GTK_BOX (self), button, gtk_widget_get_first_child (GTK_WIDGET (self)));
   else
     {
       GtkWidget *sibling = gtk_widget_get_first_child (GTK_WIDGET (self));
       int i;
       for (i = 0; i < position; i++)
         sibling = gtk_widget_get_next_sibling (sibling);
-      gtk_box_insert_before (GTK_BOX (self), button, sibling);
+      gtk_box_reorder_child (GTK_BOX (self), button, sibling);
     }
-  g_object_unref (button);
 }
 
 static void
diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c
index e1f7047840..233aa55037 100644
--- a/gtk/gtktreeviewcolumn.c
+++ b/gtk/gtktreeviewcolumn.c
@@ -963,13 +963,10 @@ gtk_tree_view_column_update_button (GtkTreeViewColumn *tree_column)
    * left otherwise; do this by packing boxes, so flipping text direction will
    * reverse things
    */
-  g_object_ref (arrow);
-  gtk_container_remove (GTK_BOX (hbox), arrow);
   if (priv->xalign <= 0.5)
-    gtk_box_append (GTK_BOX (hbox), arrow);
+    gtk_box_reorder_child (GTK_BOX (hbox), arrow, NULL);
   else
-    gtk_box_prepend (GTK_BOX (hbox), arrow);
-  g_object_unref (arrow);
+    gtk_box_reorder_child (GTK_BOX (hbox), arrow, gtk_widget_get_first_child (hbox));
 
   if (priv->show_sort_indicator
       || (GTK_IS_TREE_SORTABLE (model) && priv->sort_column_id >= 0))


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