[gtk/kill-containers: 10/21] box: Add gtk_box_append/prepend/remove



commit 194b13268a70335098525043af81ca3fc2438a7b
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri May 8 12:21:30 2020 -0400

    box: Add gtk_box_append/prepend/remove
    
    Add replacement api for gtk_container_add/remove.

 docs/reference/gtk/gtk4-sections.txt |  3 ++
 gtk/gtkbox.c                         | 69 ++++++++++++++++++++++++++++++++----
 gtk/gtkbox.h                         | 14 ++++++--
 3 files changed, 77 insertions(+), 9 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 833217880d..31d1dc6784 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -223,6 +223,9 @@ gtk_box_get_spacing
 gtk_box_set_spacing
 gtk_box_get_baseline_position
 gtk_box_set_baseline_position
+gtk_box_append
+gtk_box_prepend
+gtk_box_remove
 gtk_box_insert_child_after
 gtk_box_reorder_child_after
 <SUBSECTION Standard>
diff --git a/gtk/gtkbox.c b/gtk/gtkbox.c
index dc3b16abb6..6120565fb7 100644
--- a/gtk/gtkbox.c
+++ b/gtk/gtkbox.c
@@ -34,10 +34,9 @@
  * the #GtkWidget:halign and #GtkWidget:valign properties can be used on
  * the children to influence their allocation.
  *
- * Use repeated calls to gtk_container_add() to pack widgets into a
- * GtkBox from start to end. Use gtk_container_remove() to remove widgets
- * from the GtkBox. gtk_box_insert_child_after() can be used to add a child
- * at a particular position.
+ * Use repeated calls to gtk_box_append() to pack widgets into a GtkBox
+ * from start to end. Use gtk_box_remove() to remove widgets from the GtkBox.
+ * gtk_box_insert_child_after() can be used to add a child at a particular position.
  *
  * Use gtk_box_set_homogeneous() to specify whether or not all children
  * of the GtkBox are forced to get the same amount of space.
@@ -175,8 +174,8 @@ gtk_box_add (GtkContainer *container,
 }
 
 static void
-gtk_box_remove (GtkContainer *container,
-                GtkWidget    *widget)
+gtk_box_real_remove (GtkContainer *container,
+                     GtkWidget    *widget)
 {
   gtk_widget_unparent (widget);
 }
@@ -217,7 +216,7 @@ gtk_box_class_init (GtkBoxClass *class)
   object_class->get_property = gtk_box_get_property;
 
   container_class->add = gtk_box_add;
-  container_class->remove = gtk_box_remove;
+  container_class->remove = gtk_box_real_remove;
   container_class->forall = gtk_box_forall;
   container_class->child_type = gtk_box_child_type;
 
@@ -497,3 +496,59 @@ gtk_box_reorder_child_after (GtkBox    *box,
                              gtk_widget_get_css_node (child),
                              sibling ? gtk_widget_get_css_node (sibling) : NULL);
 }
+
+/**
+ * gtk_box_append:
+ * @box: a #GtkBox
+ * @child: the #GtkWidget to append
+ *
+ * Adds @child as the last child to @box.
+ */
+void
+gtk_box_append (GtkBox    *box,
+                GtkWidget *child)
+{
+  g_return_if_fail (GTK_IS_BOX (box));
+  g_return_if_fail (GTK_IS_WIDGET (child));
+  g_return_if_fail (gtk_widget_get_parent (child) == NULL);
+
+  gtk_widget_insert_before (child, GTK_WIDGET (box), NULL);
+}
+
+/**
+ * gtk_box_prepend:
+ * @box: a #GtkBox
+ * @child: the #GtkWidget to prepend
+ *
+ * Adds @child as the first child to @box.
+ */
+void
+gtk_box_prepend (GtkBox    *box,
+                 GtkWidget *child)
+{
+  g_return_if_fail (GTK_IS_BOX (box));
+  g_return_if_fail (GTK_IS_WIDGET (child));
+  g_return_if_fail (gtk_widget_get_parent (child) == NULL);
+
+  gtk_widget_insert_after (child, GTK_WIDGET (box), NULL);
+}
+
+/**
+ * gtk_box_remove:
+ * @box: a #GtkBox
+ * @child: the child to remove
+ *
+ * Removes a child widget from @box, after it has been
+ * added with gtk_box_append(), gtk_box_prepend(), or
+ * gtk_box_insert_child_after().
+ */
+void
+gtk_box_remove (GtkBox    *box,
+                GtkWidget *child)
+{
+  g_return_if_fail (GTK_IS_BOX (box));
+  g_return_if_fail (GTK_IS_WIDGET (child));
+  g_return_if_fail (gtk_widget_get_parent (child) == (GtkWidget *)box);
+
+  gtk_widget_unparent (child);
+}
diff --git a/gtk/gtkbox.h b/gtk/gtkbox.h
index 55ccb584da..56ed89980d 100644
--- a/gtk/gtkbox.h
+++ b/gtk/gtkbox.h
@@ -8,7 +8,7 @@
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
@@ -83,10 +83,20 @@ GDK_AVAILABLE_IN_ALL
 gint        gtk_box_get_spacing         (GtkBox         *box);
 GDK_AVAILABLE_IN_ALL
 void        gtk_box_set_baseline_position (GtkBox             *box,
-                                          GtkBaselinePosition position);
+                                           GtkBaselinePosition position);
 GDK_AVAILABLE_IN_ALL
 GtkBaselinePosition gtk_box_get_baseline_position (GtkBox         *box);
 
+GDK_AVAILABLE_IN_ALL
+void        gtk_box_append             (GtkBox         *box,
+                                        GtkWidget      *child);
+GDK_AVAILABLE_IN_ALL
+void        gtk_box_prepend            (GtkBox         *box,
+                                        GtkWidget      *child);
+GDK_AVAILABLE_IN_ALL
+void        gtk_box_remove             (GtkBox         *box,
+                                        GtkWidget      *child);
+
 GDK_AVAILABLE_IN_ALL
 void        gtk_box_insert_child_after (GtkBox         *box,
                                         GtkWidget      *child,


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