diff options
author | Christopher Davis <christopherdavis@gnome.org> | 2021-09-29 14:26:49 -0700 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2023-04-02 19:46:02 -0400 |
commit | 49e56fc7b322196b3dc42f09f436596085672cb9 (patch) | |
tree | a0ae65f88c1d227e17624195d2ea7d20ff994ec9 | |
parent | 9b2a49b7b57cc42a611a0de84206712ff3efd005 (diff) | |
download | gtk+-49e56fc7b322196b3dc42f09f436596085672cb9.tar.gz |
gtklistbox: Add remove_all()
Adds a function to remove all children from
a GtkListBox. This way app developers don't need to
implement this themselves.
-rw-r--r-- | gtk/gtklistbox.c | 30 | ||||
-rw-r--r-- | gtk/gtklistbox.h | 3 |
2 files changed, 29 insertions, 4 deletions
diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c index 18dad80889..8d2c0d0a95 100644 --- a/gtk/gtklistbox.c +++ b/gtk/gtklistbox.c @@ -433,10 +433,7 @@ gtk_list_box_set_property (GObject *obj, static void gtk_list_box_dispose (GObject *object) { - GtkWidget *child; - - while ((child = gtk_widget_get_first_child (GTK_WIDGET (object)))) - gtk_list_box_remove (GTK_LIST_BOX (object), child); + gtk_list_box_remove_all (GTK_LIST_BOX (object)); G_OBJECT_CLASS (gtk_list_box_parent_class)->dispose (object); } @@ -2422,6 +2419,31 @@ gtk_list_box_remove (GtkListBox *box, } } +/** + * gtk_list_box_remove_all: + * @box: a `GtkListBox` + * + * Removes all rows from @box. + * + * This function does nothing if @box is backed by a model. + * + * Since: 4.12 + */ +void +gtk_list_box_remove_all (GtkListBox *box) +{ + GtkWidget *widget = GTK_WIDGET (box); + GtkWidget *child; + + g_return_if_fail (GTK_IS_LIST_BOX (box)); + + if (box->bound_model) + return; + + while ((child = gtk_widget_get_first_child (widget)) != NULL) + gtk_list_box_remove (box, child); +} + static void gtk_list_box_compute_expand (GtkWidget *widget, gboolean *hexpand_p, diff --git a/gtk/gtklistbox.h b/gtk/gtklistbox.h index 1a2dec8cd9..71d42e1ee2 100644 --- a/gtk/gtklistbox.h +++ b/gtk/gtklistbox.h @@ -180,6 +180,9 @@ void gtk_list_box_insert (GtkListBox GDK_AVAILABLE_IN_ALL void gtk_list_box_remove (GtkListBox *box, GtkWidget *child); +GDK_AVAILABLE_IN_4_12 +void gtk_list_box_remove_all (GtkListBox *box); + GDK_AVAILABLE_IN_ALL GtkListBoxRow* gtk_list_box_get_selected_row (GtkListBox *box); GDK_AVAILABLE_IN_ALL |