[gtk/kill-containers: 56/76] Don't use container api on GtkListBox
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/kill-containers: 56/76] Don't use container api on GtkListBox
- Date: Sat, 9 May 2020 04:44:09 +0000 (UTC)
commit 96de8be04cfb8fd65f4e8c4cad6062fa02a6a00d
Author: Matthias Clasen <mclasen redhat com>
Date: Fri May 8 02:19:18 2020 -0400
Don't use container api on GtkListBox
demos/gtk-demo/css_blendmodes.c | 7 ++-
demos/gtk-demo/css_multiplebgs.c | 6 +--
demos/gtk-demo/css_pixbufs.c | 6 +--
demos/gtk-demo/css_shadows.c | 6 +--
demos/gtk-demo/dnd.c | 4 +-
demos/gtk-demo/listbox.c | 2 +-
demos/gtk-demo/shortcut_triggers.c | 2 +-
docs/tools/widgets.c | 8 +--
gtk/gtkplacessidebar.c | 104 ++++++++++++++++++-------------------
gtk/gtkplacesview.c | 46 ++++++++--------
gtk/gtkshortcutswindow.c | 2 +-
gtk/gtksidebarrow.c | 4 +-
gtk/gtkstacksidebar.c | 4 +-
gtk/inspector/general.c | 6 ++-
gtk/inspector/size-groups.c | 2 +-
tests/testclipboard2.c | 4 +-
tests/testgtk.c | 2 +-
tests/testlist.c | 14 ++---
tests/testlist2.c | 2 +-
tests/testscrolledge.c | 10 ++--
tests/testscrolledwindow.c | 14 ++---
tests/testselectionmode.c | 23 ++++++--
testsuite/gtk/listbox.c | 41 ++++++---------
23 files changed, 158 insertions(+), 161 deletions(-)
---
diff --git a/demos/gtk-demo/css_blendmodes.c b/demos/gtk-demo/css_blendmodes.c
index 86fc0ecc91..3db6a105c2 100644
--- a/demos/gtk-demo/css_blendmodes.c
+++ b/demos/gtk-demo/css_blendmodes.c
@@ -79,7 +79,7 @@ setup_listbox (GtkBuilder *builder,
normal_row = NULL;
listbox = gtk_list_box_new ();
- gtk_container_add (GTK_CONTAINER (WID ("scrolledwindow")), listbox);
+ gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (WID ("scrolledwindow")), listbox);
g_signal_connect (listbox, "row-activated", G_CALLBACK (row_activated), provider);
@@ -95,9 +95,8 @@ setup_listbox (GtkBuilder *builder,
"xalign", 0.0,
NULL);
- gtk_container_add (GTK_CONTAINER (row), label);
-
- gtk_container_add (GTK_CONTAINER (listbox), row);
+ gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), label);
+ gtk_list_box_insert (GTK_LIST_BOX (listbox), row, -1);
/* The first selected row is "normal" */
if (g_strcmp0 (blend_modes[i].id, "normal") == 0)
diff --git a/demos/gtk-demo/css_multiplebgs.c b/demos/gtk-demo/css_multiplebgs.c
index 5e29060d85..01e6fd3808 100644
--- a/demos/gtk-demo/css_multiplebgs.c
+++ b/demos/gtk-demo/css_multiplebgs.c
@@ -115,7 +115,7 @@ do_css_multiplebgs (GtkWidget *do_widget)
/* Need a filler so we get a handle */
child = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_container_add (GTK_CONTAINER (paned), child);
+ gtk_paned_set_start_child (GTK_PANED (paned), child);
text = gtk_text_buffer_new (NULL);
gtk_text_buffer_create_tag (text,
@@ -130,9 +130,9 @@ do_css_multiplebgs (GtkWidget *do_widget)
provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
container = gtk_scrolled_window_new (NULL, NULL);
- gtk_container_add (GTK_CONTAINER (paned), container);
+ gtk_paned_set_end_child (GTK_PANED (paned), container);
child = gtk_text_view_new_with_buffer (text);
- gtk_container_add (GTK_CONTAINER (container), child);
+ gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (container), child);
g_signal_connect (text,
"changed",
G_CALLBACK (css_text_changed),
diff --git a/demos/gtk-demo/css_pixbufs.c b/demos/gtk-demo/css_pixbufs.c
index 9d88ef76fa..65fd66ba92 100644
--- a/demos/gtk-demo/css_pixbufs.c
+++ b/demos/gtk-demo/css_pixbufs.c
@@ -84,7 +84,7 @@ do_css_pixbufs (GtkWidget *do_widget)
/* Need a filler so we get a handle */
child = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_container_add (GTK_CONTAINER (paned), child);
+ gtk_paned_set_start_child (GTK_PANED (paned), child);
text = gtk_text_buffer_new (NULL);
gtk_text_buffer_create_tag (text,
@@ -99,9 +99,9 @@ do_css_pixbufs (GtkWidget *do_widget)
provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
container = gtk_scrolled_window_new (NULL, NULL);
- gtk_container_add (GTK_CONTAINER (paned), container);
+ gtk_paned_set_end_child (GTK_PANED (paned), container);
child = gtk_text_view_new_with_buffer (text);
- gtk_container_add (GTK_CONTAINER (container), child);
+ gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (container), child);
g_signal_connect (text, "changed",
G_CALLBACK (css_text_changed), provider);
diff --git a/demos/gtk-demo/css_shadows.c b/demos/gtk-demo/css_shadows.c
index de21cfae29..7cc2e9afb3 100644
--- a/demos/gtk-demo/css_shadows.c
+++ b/demos/gtk-demo/css_shadows.c
@@ -102,7 +102,7 @@ do_css_shadows (GtkWidget *do_widget)
gtk_window_set_child (GTK_WINDOW (window), paned);
child = create_toolbar ();
- gtk_container_add (GTK_CONTAINER (paned), child);
+ gtk_paned_set_start_child (GTK_PANED (paned), child);
text = gtk_text_buffer_new (NULL);
gtk_text_buffer_create_tag (text,
@@ -117,9 +117,9 @@ do_css_shadows (GtkWidget *do_widget)
provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
container = gtk_scrolled_window_new (NULL, NULL);
- gtk_container_add (GTK_CONTAINER (paned), container);
+ gtk_paned_set_end_child (GTK_PANED (paned), container);
child = gtk_text_view_new_with_buffer (text);
- gtk_container_add (GTK_CONTAINER (container), child);
+ gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (container), child);
g_signal_connect (text, "changed",
G_CALLBACK (css_text_changed), provider);
diff --git a/demos/gtk-demo/dnd.c b/demos/gtk-demo/dnd.c
index 30bae48e17..76f1f92a40 100644
--- a/demos/gtk-demo/dnd.c
+++ b/demos/gtk-demo/dnd.c
@@ -119,7 +119,7 @@ new_item_cb (GtkWidget *button, gpointer data)
GtkWidget *item;
item = canvas_item_new (pos_x, pos_y);
- gtk_container_add (GTK_CONTAINER (canvas), item);
+ gtk_fixed_put (GTK_FIXED (canvas), item, 0, 0);
apply_transform (item);
gtk_popover_popdown (GTK_POPOVER (gtk_widget_get_ancestor (button, GTK_TYPE_POPOVER)));
@@ -459,7 +459,7 @@ do_dnd (GtkWidget *do_widget)
GtkWidget *item;
item = canvas_item_new (x, y);
- gtk_container_add (GTK_CONTAINER (canvas), item);
+ gtk_fixed_put (GTK_FIXED (canvas), item, 0, 0);
apply_transform (item);
x += 150;
diff --git a/demos/gtk-demo/listbox.c b/demos/gtk-demo/listbox.c
index fe9c3e2fd3..1e88ade3dd 100644
--- a/demos/gtk-demo/listbox.c
+++ b/demos/gtk-demo/listbox.c
@@ -382,7 +382,7 @@ do_listbox (GtkWidget *do_widget)
message = gtk_message_new (lines[i]);
row = gtk_message_row_new (message);
gtk_widget_show (GTK_WIDGET (row));
- gtk_container_add (GTK_CONTAINER (listbox), GTK_WIDGET (row));
+ gtk_list_box_insert (GTK_LIST_BOX (listbox), GTK_WIDGET (row), -1);
}
g_strfreev (lines);
diff --git a/demos/gtk-demo/shortcut_triggers.c b/demos/gtk-demo/shortcut_triggers.c
index 509a7f5514..cfe2bff5fa 100644
--- a/demos/gtk-demo/shortcut_triggers.c
+++ b/demos/gtk-demo/shortcut_triggers.c
@@ -73,7 +73,7 @@ do_shortcut_triggers (GtkWidget *do_widget)
GtkWidget *row;
row = gtk_label_new (shortcuts[i].description);
- gtk_container_add (GTK_CONTAINER (list), row);
+ gtk_list_box_insert (GTK_LIST_BOX (list), row, -1);
controller = gtk_shortcut_controller_new ();
gtk_shortcut_controller_set_scope (GTK_SHORTCUT_CONTROLLER (controller),
GTK_SHORTCUT_SCOPE_GLOBAL);
diff --git a/docs/tools/widgets.c b/docs/tools/widgets.c
index 3415b2b730..2a1858e978 100644
--- a/docs/tools/widgets.c
+++ b/docs/tools/widgets.c
@@ -1265,7 +1265,7 @@ create_list_box (void)
gtk_widget_set_hexpand (button, TRUE);
gtk_widget_set_halign (button, GTK_ALIGN_CENTER);
gtk_container_add (GTK_CONTAINER (row), button);
- gtk_container_add (GTK_CONTAINER (list), row);
+ gtk_list_box_insert (GTK_LIST_BOX (list), row, -1);
row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
gtk_container_add (GTK_CONTAINER (row), gtk_label_new ("Line One"));
button = gtk_check_button_new ();
@@ -1273,7 +1273,7 @@ create_list_box (void)
gtk_widget_set_hexpand (button, TRUE);
gtk_widget_set_halign (button, GTK_ALIGN_END);
gtk_container_add (GTK_CONTAINER (row), button);
- gtk_container_add (GTK_CONTAINER (list), row);
+ gtk_list_box_insert (GTK_LIST_BOX (list), row, -1);
gtk_list_box_select_row (GTK_LIST_BOX (list), GTK_LIST_BOX_ROW (gtk_widget_get_parent (row)));
row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
gtk_container_add (GTK_CONTAINER (row), gtk_label_new ("Line Two"));
@@ -1281,14 +1281,14 @@ create_list_box (void)
gtk_widget_set_hexpand (button, TRUE);
gtk_widget_set_halign (button, GTK_ALIGN_END);
gtk_container_add (GTK_CONTAINER (row), button);
- gtk_container_add (GTK_CONTAINER (list), row);
+ gtk_list_box_insert (GTK_LIST_BOX (list), row, -1);
row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
gtk_container_add (GTK_CONTAINER (row), gtk_label_new ("Line Three"));
button = gtk_entry_new ();
gtk_widget_set_hexpand (button, TRUE);
gtk_widget_set_halign (button, GTK_ALIGN_END);
gtk_container_add (GTK_CONTAINER (row), button);
- gtk_container_add (GTK_CONTAINER (list), row);
+ gtk_list_box_insert (GTK_LIST_BOX (list), row, -1);
gtk_container_add (GTK_CONTAINER (widget), list);
diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c
index 06712a79e2..0b43e070f3 100644
--- a/gtk/gtkplacessidebar.c
+++ b/gtk/gtkplacessidebar.c
@@ -479,7 +479,7 @@ add_place (GtkPlacesSidebar *sidebar,
G_CALLBACK (on_row_dragged), row);
gtk_widget_add_controller (row, GTK_EVENT_CONTROLLER (gesture));
- gtk_container_add (GTK_CONTAINER (sidebar->list_box), GTK_WIDGET (row));
+ gtk_list_box_insert (GTK_LIST_BOX (sidebar->list_box), GTK_WIDGET (row), -1);
return row;
}
@@ -687,15 +687,17 @@ file_is_shown (GtkPlacesSidebar *sidebar,
GFile *file)
{
gchar *uri;
- GList *rows;
- GList *l;
+ GtkWidget *row;
gboolean found = FALSE;
- rows = gtk_container_get_children (GTK_CONTAINER (sidebar->list_box));
- l = rows;
- while (l != NULL && !found)
+ for (row = gtk_widget_get_first_child (GTK_WIDGET (sidebar->list_box));
+ row != NULL && !found;
+ row = gtk_widget_get_next_sibling (row))
{
- g_object_get (l->data, "uri", &uri, NULL);
+ if (!GTK_IS_LIST_BOX_ROW (row))
+ continue;
+
+ g_object_get (row, "uri", &uri, NULL);
if (uri)
{
GFile *other;
@@ -704,11 +706,8 @@ file_is_shown (GtkPlacesSidebar *sidebar,
g_object_unref (other);
g_free (uri);
}
- l = l->next;
}
- g_list_free (rows);
-
return found;
}
@@ -979,7 +978,7 @@ update_places (GtkPlacesSidebar *sidebar)
gchar *tooltip;
GList *network_mounts, *network_volumes;
GIcon *new_bookmark_icon;
- GList *children;
+ GtkWidget *child;
#ifdef HAVE_CLOUDPROVIDERS
GList *cloud_providers;
GList *cloud_providers_accounts;
@@ -1002,10 +1001,8 @@ update_places (GtkPlacesSidebar *sidebar)
/* Reset drag state, just in case we update the places while dragging or
* ending a drag */
stop_drop_feedback (sidebar);
- children = gtk_container_get_children (GTK_CONTAINER (sidebar->list_box));
- for (l = children; l; l = l->next)
- gtk_container_remove (GTK_CONTAINER (sidebar->list_box), l->data);
- g_list_free (children);
+ while ((child = gtk_widget_get_first_child (GTK_WIDGET (sidebar->list_box))))
+ gtk_list_box_remove (GTK_LIST_BOX (sidebar->list_box), child);
network_mounts = network_volumes = NULL;
@@ -1575,19 +1572,21 @@ static void
update_possible_drop_targets (GtkPlacesSidebar *sidebar,
const GValue *value)
{
- GList *rows;
- GList *l;
- gboolean sensitive;
-
- rows = gtk_container_get_children (GTK_CONTAINER (sidebar->list_box));
+ GtkWidget *row;
- for (l = rows; l != NULL; l = l->next)
+ for (row = gtk_widget_get_first_child (GTK_WIDGET (sidebar->list_box));
+ row != NULL;
+ row = gtk_widget_get_next_sibling (row))
{
- sensitive = value == NULL || check_valid_drop_target (sidebar, GTK_SIDEBAR_ROW (l->data), value);
- gtk_widget_set_sensitive (GTK_WIDGET (l->data), sensitive);
- }
+ gboolean sensitive;
+
+ if (!GTK_IS_LIST_BOX_ROW (row))
+ continue;
- g_list_free (rows);
+ sensitive = value == NULL ||
+ check_valid_drop_target (sidebar, GTK_SIDEBAR_ROW (row), value);
+ gtk_widget_set_sensitive (row, sensitive);
+ }
}
static void
@@ -1626,7 +1625,7 @@ stop_drop_feedback (GtkPlacesSidebar *sidebar)
if (sidebar->row_placeholder != NULL)
{
if (gtk_widget_get_parent (sidebar->row_placeholder) != NULL)
- gtk_container_remove (GTK_CONTAINER (sidebar), sidebar->row_placeholder);
+ gtk_list_box_remove (GTK_LIST_BOX (sidebar), sidebar->row_placeholder);
sidebar->row_placeholder = NULL;
}
@@ -1683,10 +1682,7 @@ drag_motion_callback (GtkDropTarget *target,
}
if (gtk_widget_get_parent (sidebar->row_placeholder) != NULL)
- {
- gtk_container_remove (GTK_CONTAINER (sidebar->list_box),
- sidebar->row_placeholder);
- }
+ gtk_list_box_remove (GTK_LIST_BOX (sidebar->list_box), sidebar->row_placeholder);
if (row != NULL)
{
@@ -2201,8 +2197,7 @@ rename_entry_changed (GtkEntry *entry,
gchar *uri;
const gchar *new_name;
gboolean found = FALSE;
- GList *rows;
- GList *l;
+ GtkWidget *row;
new_name = gtk_editable_get_text (GTK_EDITABLE (sidebar->rename_entry));
@@ -2213,10 +2208,14 @@ rename_entry_changed (GtkEntry *entry,
return;
}
- rows = gtk_container_get_children (GTK_CONTAINER (sidebar->list_box));
- for (l = rows; l && !found; l = l->next)
+ for (row = gtk_widget_get_first_child (GTK_WIDGET (sidebar->list_box));
+ row != NULL && !found;
+ row = gtk_widget_get_next_sibling (row))
{
- g_object_get (l->data,
+ if (!GTK_IS_LIST_BOX_ROW (row))
+ continue;
+
+ g_object_get (row,
"place-type", &type,
"uri", &uri,
"label", &name,
@@ -2230,7 +2229,6 @@ rename_entry_changed (GtkEntry *entry,
g_free (uri);
g_free (name);
}
- g_list_free (rows);
gtk_widget_set_sensitive (sidebar->rename_button, !found);
gtk_label_set_label (GTK_LABEL (sidebar->rename_error),
@@ -4470,8 +4468,7 @@ void
gtk_places_sidebar_set_location (GtkPlacesSidebar *sidebar,
GFile *location)
{
- GList *children;
- GList *child;
+ GtkWidget *row;
gchar *row_uri;
gchar *uri;
gboolean found = FALSE;
@@ -4491,14 +4488,18 @@ gtk_places_sidebar_set_location (GtkPlacesSidebar *sidebar,
uri = g_file_get_uri (location);
- children = gtk_container_get_children (GTK_CONTAINER (sidebar->list_box));
- for (child = children; child != NULL && !found; child = child->next)
+ for (row = gtk_widget_get_first_child (GTK_WIDGET (sidebar->list_box));
+ row != NULL && !found;
+ row = gtk_widget_get_next_sibling (row))
{
- g_object_get (child->data, "uri", &row_uri, NULL);
+ if (!GTK_IS_LIST_BOX_ROW (row))
+ continue;
+
+ g_object_get (row, "uri", &row_uri, NULL);
if (row_uri != NULL && g_strcmp0 (row_uri, uri) == 0)
{
gtk_list_box_select_row (GTK_LIST_BOX (sidebar->list_box),
- GTK_LIST_BOX_ROW (child->data));
+ GTK_LIST_BOX_ROW (row));
found = TRUE;
}
@@ -4506,7 +4507,6 @@ gtk_places_sidebar_set_location (GtkPlacesSidebar *sidebar,
}
g_free (uri);
- g_list_free (children);
out:
g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_LOCATION]);
@@ -4898,24 +4898,25 @@ GFile *
gtk_places_sidebar_get_nth_bookmark (GtkPlacesSidebar *sidebar,
gint n)
{
- GList *rows;
- GList *l;
+ GtkWidget *row;
int k;
GFile *file;
g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), NULL);
file = NULL;
- rows = gtk_container_get_children (GTK_CONTAINER (sidebar->list_box));
- l = rows;
-
k = 0;
- while (l != NULL)
+ for (row = gtk_widget_get_first_child (GTK_WIDGET (sidebar->list_box));
+ row != NULL;
+ row = gtk_widget_get_next_sibling (row))
{
GtkPlacesSidebarPlaceType place_type;
gchar *uri;
- g_object_get (l->data,
+ if (!GTK_IS_LIST_BOX_ROW (row))
+ continue;
+
+ g_object_get (row,
"place-type", &place_type,
"uri", &uri,
NULL);
@@ -4930,11 +4931,8 @@ gtk_places_sidebar_get_nth_bookmark (GtkPlacesSidebar *sidebar,
k++;
}
g_free (uri);
- l = l->next;
}
- g_list_free (rows);
-
return file;
}
diff --git a/gtk/gtkplacesview.c b/gtk/gtkplacesview.c
index 444fdb8722..00c6315219 100644
--- a/gtk/gtkplacesview.c
+++ b/gtk/gtkplacesview.c
@@ -526,7 +526,7 @@ static void
populate_servers (GtkPlacesView *view)
{
GBookmarkFile *server_list;
- GList *children;
+ GtkWidget *child;
gchar **uris;
gsize num_uris;
gint i;
@@ -548,8 +548,8 @@ populate_servers (GtkPlacesView *view)
}
/* clear previous items */
- children = gtk_container_get_children (GTK_CONTAINER (view->recent_servers_listbox));
- g_list_free_full (children, (GDestroyNotify) gtk_widget_destroy);
+ while ((child = gtk_widget_get_first_child (GTK_WIDGET (view->recent_servers_listbox))))
+ gtk_list_box_remove (GTK_LIST_BOX (view->listbox), child);
gtk_list_store_clear (view->completion_store);
@@ -606,7 +606,7 @@ populate_servers (GtkPlacesView *view)
gtk_grid_attach (GTK_GRID (grid), button, 1, 0, 1, 2);
gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), grid);
- gtk_container_add (GTK_CONTAINER (view->recent_servers_listbox), row);
+ gtk_list_box_insert (GTK_LIST_BOX (view->recent_servers_listbox), row, -1);
/* custom data */
data = g_new0 (RemoveServerData, 1);
@@ -631,27 +631,24 @@ populate_servers (GtkPlacesView *view)
static void
update_view_mode (GtkPlacesView *view)
{
- GList *children;
- GList *l;
+ GtkWidget *child;
gboolean show_listbox;
show_listbox = FALSE;
/* drives */
- children = gtk_container_get_children (GTK_CONTAINER (view->listbox));
-
- for (l = children; l; l = l->next)
+ for (child = gtk_widget_get_first_child (GTK_WIDGET (view->listbox));
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
{
/* GtkListBox filter rows by changing their GtkWidget::child-visible property */
- if (gtk_widget_get_child_visible (l->data))
+ if (gtk_widget_get_child_visible (child))
{
show_listbox = TRUE;
break;
}
}
- g_list_free (children);
-
if (!show_listbox &&
view->search_query &&
view->search_query[0] != '\0')
@@ -698,7 +695,7 @@ insert_row (GtkPlacesView *view,
gtk_places_view_row_set_path_size_group (GTK_PLACES_VIEW_ROW (row), view->path_size_group);
gtk_places_view_row_set_space_size_group (GTK_PLACES_VIEW_ROW (row), view->space_size_group);
- gtk_container_add (GTK_CONTAINER (view->listbox), row);
+ gtk_list_box_insert (GTK_LIST_BOX (view->listbox), row, -1);
}
static void
@@ -838,23 +835,21 @@ add_file (GtkPlacesView *view,
static gboolean
has_networks (GtkPlacesView *view)
{
- GList *l;
- GList *children;
+ GtkWidget *child;
gboolean has_network = FALSE;
- children = gtk_container_get_children (GTK_CONTAINER (view->listbox));
- for (l = children; l != NULL; l = l->next)
+ for (child = gtk_widget_get_first_child (GTK_WIDGET (view->listbox));
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
{
- if (GPOINTER_TO_INT (g_object_get_data (l->data, "is-network")) == TRUE &&
- g_object_get_data (l->data, "is-placeholder") == NULL)
+ if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (child), "is-network")) &&
+ g_object_get_data (G_OBJECT (child), "is-placeholder") == NULL)
{
has_network = TRUE;
break;
}
}
- g_list_free (children);
-
return has_network;
}
@@ -879,7 +874,7 @@ update_network_state (GtkPlacesView *view)
/* mark the row as placeholder, so it always goes first */
g_object_set_data (G_OBJECT (view->network_placeholder),
"is-placeholder", GINT_TO_POINTER (TRUE));
- gtk_container_add (GTK_CONTAINER (view->listbox), view->network_placeholder);
+ gtk_list_box_insert (GTK_LIST_BOX (view->listbox), view->network_placeholder, -1);
}
if (gtk_places_view_get_fetching_networks (view))
@@ -1084,7 +1079,7 @@ fetch_networks (GtkPlacesView *view)
static void
update_places (GtkPlacesView *view)
{
- GList *children;
+ GtkWidget *child;
GList *mounts;
GList *volumes;
GList *drives;
@@ -1093,8 +1088,9 @@ update_places (GtkPlacesView *view)
GFile *file;
/* Clear all previously added items */
- children = gtk_container_get_children (GTK_CONTAINER (view->listbox));
- g_list_free_full (children, (GDestroyNotify) gtk_widget_destroy);
+ while ((child = gtk_widget_get_first_child (GTK_WIDGET (view->listbox))))
+ gtk_list_box_remove (GTK_LIST_BOX (view->listbox), child);
+
view->network_placeholder = NULL;
/* Inform clients that we started loading */
gtk_places_view_set_loading (view, TRUE);
diff --git a/gtk/gtkshortcutswindow.c b/gtk/gtkshortcutswindow.c
index 68ce8b8c70..1e87a8a732 100644
--- a/gtk/gtkshortcutswindow.c
+++ b/gtk/gtkshortcutswindow.c
@@ -370,7 +370,7 @@ gtk_shortcuts_window_add_section (GtkShortcutsWindow *self,
NULL);
g_object_set_data (G_OBJECT (section), "gtk-shortcuts-title", label);
gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), GTK_WIDGET (label));
- gtk_container_add (GTK_CONTAINER (priv->list_box), GTK_WIDGET (row));
+ gtk_list_box_insert (GTK_LIST_BOX (priv->list_box), GTK_WIDGET (row), -1);
update_title_stack (self);
diff --git a/gtk/gtksidebarrow.c b/gtk/gtksidebarrow.c
index 8e1f5aa392..0a2749a122 100644
--- a/gtk/gtksidebarrow.c
+++ b/gtk/gtksidebarrow.c
@@ -347,9 +347,7 @@ gtk_sidebar_row_set_property (GObject *object,
g_clear_object (&self->mount);
g_clear_object (&self->cloud_provider_account);
- gtk_container_foreach (GTK_CONTAINER (self),
- (GtkCallback) gtk_widget_destroy,
- NULL);
+ gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (self), NULL);
gtk_widget_add_css_class (GTK_WIDGET (self), "sidebar-placeholder-row");
}
diff --git a/gtk/gtkstacksidebar.c b/gtk/gtkstacksidebar.c
index b28ad7c17a..dfecc33c22 100644
--- a/gtk/gtkstacksidebar.c
+++ b/gtk/gtkstacksidebar.c
@@ -236,7 +236,7 @@ add_child (guint position,
page = g_list_model_get_item (G_LIST_MODEL (self->pages), position);
update_row (self, page, row);
- gtk_container_add (GTK_CONTAINER (self->list), row);
+ gtk_list_box_insert (GTK_LIST_BOX (self->list), row, -1);
g_object_set_data (G_OBJECT (row), "child-index", GUINT_TO_POINTER (position));
if (gtk_selection_model_is_selected (self->pages, position))
@@ -270,7 +270,7 @@ clear_sidebar (GtkStackSidebar *self)
g_hash_table_iter_init (&iter, self->rows);
while (g_hash_table_iter_next (&iter, (gpointer *)&page, (gpointer *)&row))
{
- gtk_container_remove (GTK_CONTAINER (self->list), row);
+ gtk_list_box_remove (GTK_LIST_BOX (self->list), row);
g_hash_table_iter_remove (&iter);
g_signal_handlers_disconnect_by_func (page, on_page_updated, self);
}
diff --git a/gtk/inspector/general.c b/gtk/inspector/general.c
index 5bffd5b1b7..8edbd56538 100644
--- a/gtk/inspector/general.c
+++ b/gtk/inspector/general.c
@@ -523,7 +523,11 @@ populate_display (GdkDisplay *display, GtkInspectorGeneral *gen)
gtk_widget_show (gen->priv->display_composited);
list = GTK_LIST_BOX (gen->priv->display_box);
- children = gtk_container_get_children (GTK_CONTAINER (list));
+ children = NULL;
+ for (child = gtk_widget_get_first_child (GTK_WIDGET (list));
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ children = g_list_prepend (children, child);
for (l = children; l; l = l->next)
{
child = l->data;
diff --git a/gtk/inspector/size-groups.c b/gtk/inspector/size-groups.c
index dd39b8293b..03f1db6502 100644
--- a/gtk/inspector/size-groups.c
+++ b/gtk/inspector/size-groups.c
@@ -215,7 +215,7 @@ add_widget (GtkInspectorSizeGroups *sl,
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_widget_set_valign (label, GTK_ALIGN_BASELINE);
gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), label);
- gtk_container_add (GTK_CONTAINER (listbox), row);
+ gtk_list_box_insert (listbox, row, -1);
}
static void
diff --git a/tests/testclipboard2.c b/tests/testclipboard2.c
index 7c93c302df..a7d61be95b 100644
--- a/tests/testclipboard2.c
+++ b/tests/testclipboard2.c
@@ -207,7 +207,7 @@ format_list_add_row (GtkWidget *list,
gtk_container_add (GTK_CONTAINER (box), gtk_label_new (format_name));
gdk_content_formats_unref (formats);
- gtk_container_add (GTK_CONTAINER (list), box);
+ gtk_list_box_insert (GTK_LIST_BOX (list), box, -1);
}
static void
@@ -222,7 +222,7 @@ clipboard_formats_change_cb (GdkClipboard *clipboard,
gsize i, n;
while ((row = GTK_WIDGET (gtk_list_box_get_row_at_index (GTK_LIST_BOX (list), 0))))
- gtk_container_remove (GTK_CONTAINER (list), row);
+ gtk_list_box_remove (GTK_LIST_BOX (list), row);
formats = gdk_clipboard_get_formats (clipboard);
diff --git a/tests/testgtk.c b/tests/testgtk.c
index 0f0e5ab494..cd900e2406 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -1562,7 +1562,7 @@ create_listbox (GtkWidget *widget)
gint value = g_random_int_range (0, 10000);
label = gtk_label_new (g_strdup_printf ("Value %u", value));
gtk_widget_show (label);
- gtk_container_add (GTK_CONTAINER (list), label);
+ gtk_list_box_insert (GTK_LIST_BOX (list), label, -1);
g_object_set_data (G_OBJECT (gtk_widget_get_parent (label)), "value", GINT_TO_POINTER (value));
}
diff --git a/tests/testlist.c b/tests/testlist.c
index c382097a11..6fe9566342 100644
--- a/tests/testlist.c
+++ b/tests/testlist.c
@@ -200,7 +200,7 @@ add_clicked_cb (GtkButton *button,
static int new_button_nr = 1;
new_row = row_new( g_strdup_printf ("blah2 new %d", new_button_nr), new_button_nr);
- gtk_container_add (GTK_CONTAINER (list), new_row);
+ gtk_list_box_insert (GTK_LIST_BOX (list), new_row, -1);
new_button_nr++;
}
@@ -297,13 +297,13 @@ main (int argc, char *argv[])
g_signal_connect (list, "row-selected", G_CALLBACK (row_selected_cb), NULL);
row = row_new ("blah4", 4);
- gtk_container_add (GTK_CONTAINER (list), row);
+ gtk_list_box_insert (GTK_LIST_BOX (list), row, -1);
row3 = row = row_new ("blah3", 3);
- gtk_container_add (GTK_CONTAINER (list), row);
+ gtk_list_box_insert (GTK_LIST_BOX (list), row, -1);
row = row_new ("blah1", 1);
- gtk_container_add (GTK_CONTAINER (list), row);
+ gtk_list_box_insert (GTK_LIST_BOX (list), row, -1);
row = row_new ("blah2", 2);
- gtk_container_add (GTK_CONTAINER (list), row);
+ gtk_list_box_insert (GTK_LIST_BOX (list), row, -1);
row = row_new (NULL, 0);
row_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
@@ -318,14 +318,14 @@ main (int argc, char *argv[])
check = gtk_check_button_new ();
gtk_container_add (GTK_CONTAINER (row_vbox), check);
gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), row_vbox);
- gtk_container_add (GTK_CONTAINER (list), row);
+ gtk_list_box_insert (GTK_LIST_BOX (list), row, -1);
row = row_new (NULL, 0);
button = gtk_button_new_with_label ("focusable row");
gtk_widget_set_hexpand (button, FALSE);
gtk_widget_set_halign (button, GTK_ALIGN_START);
gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), button);
- gtk_container_add (GTK_CONTAINER (list), row);
+ gtk_list_box_insert (GTK_LIST_BOX (list), row, -1);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (hbox), vbox);
diff --git a/tests/testlist2.c b/tests/testlist2.c
index 6b176a0fea..dc1ea21cc1 100644
--- a/tests/testlist2.c
+++ b/tests/testlist2.c
@@ -8,7 +8,7 @@ row_unrevealed (GObject *revealer, GParamSpec *pspec, gpointer data)
row = gtk_widget_get_parent (GTK_WIDGET (revealer));
list = gtk_widget_get_parent (row);
- gtk_container_remove (GTK_CONTAINER (list), row);
+ gtk_list_box_remove (GTK_LIST_BOX (list), row);
}
static void
diff --git a/tests/testscrolledge.c b/tests/testscrolledge.c
index 16d8ac7664..150d6fa936 100644
--- a/tests/testscrolledge.c
+++ b/tests/testscrolledge.c
@@ -27,11 +27,11 @@ populate_list (GtkListBox *list)
gchar *text;
GtkWidget *row, *label;
gint n;
- GList *l;
+ GtkWidget *child;
- l = gtk_container_get_children (GTK_CONTAINER (list));
- n = g_list_length (l);
- g_list_free (l);
+ for (child = gtk_widget_get_first_child (GTK_WIDGET (list)), n = 0;
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child), n++) ;
for (i = 1; i <= 50; i++)
{
@@ -46,7 +46,7 @@ populate_list (GtkListBox *list)
gtk_widget_set_margin_bottom (label, 10);
gtk_widget_set_halign (label, GTK_ALIGN_START);
gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), label);
- gtk_container_add (GTK_CONTAINER (list), row);
+ gtk_list_box_insert (GTK_LIST_BOX (list), row, -1);
}
}
diff --git a/tests/testscrolledwindow.c b/tests/testscrolledwindow.c
index 36aa92c5e9..24844ce91c 100644
--- a/tests/testscrolledwindow.c
+++ b/tests/testscrolledwindow.c
@@ -58,23 +58,19 @@ add_row (GtkButton *button,
GtkWidget *row;
row = g_object_new (GTK_TYPE_LIST_BOX_ROW, NULL);
- gtk_container_add (GTK_CONTAINER (row), gtk_label_new ("test"));
- gtk_container_add (GTK_CONTAINER (listbox), row);
+ gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), gtk_label_new ("test"));
+ gtk_list_box_insert (GTK_LIST_BOX (listbox), row, -1);
}
static void
remove_row (GtkButton *button,
GtkListBox *listbox)
{
- GList *children, *last;
-
- children = gtk_container_get_children (GTK_CONTAINER (listbox));
- last = g_list_last (children);
+ GtkWidget *last;
+ last = gtk_widget_get_last_child (GTK_WIDGET (listbox));
if (last)
- gtk_container_remove (GTK_CONTAINER (listbox), last->data);
-
- g_list_free (children);
+ gtk_list_box_remove (GTK_LIST_BOX (listbox), last);
}
static void
diff --git a/tests/testselectionmode.c b/tests/testselectionmode.c
index 1d400e76f9..7875d44d10 100644
--- a/tests/testselectionmode.c
+++ b/tests/testselectionmode.c
@@ -42,7 +42,7 @@ selectable_row_add (SelectableRow *row, GtkWidget *child)
}
static void
-update_selectable (GtkWidget *widget, gpointer data)
+update_selectable (GtkWidget *widget)
{
SelectableRow *row = (SelectableRow *)widget;
GtkListBox *list;
@@ -56,7 +56,7 @@ update_selectable (GtkWidget *widget, gpointer data)
}
static void
-update_selected (GtkWidget *widget, gpointer data)
+update_selected (GtkWidget *widget)
{
SelectableRow *row = (SelectableRow *)widget;
@@ -106,6 +106,7 @@ selection_mode_enter (GtkButton *button, GtkBuilder *builder)
GtkWidget *cancelbutton;
GtkWidget *selectbutton;
GtkWidget *titlestack;
+ GtkWidget *child;
header = GTK_WIDGET (gtk_builder_get_object (builder, "header"));
list = GTK_WIDGET (gtk_builder_get_object (builder, "list"));
@@ -123,7 +124,10 @@ selection_mode_enter (GtkButton *button, GtkBuilder *builder)
gtk_list_box_set_activate_on_single_click (GTK_LIST_BOX (list), FALSE);
gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_MULTIPLE);
- gtk_container_forall (GTK_CONTAINER (list), update_selectable, NULL);
+ for (child = gtk_widget_get_first_child (list);
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ update_selectable (child);
}
static void
@@ -135,6 +139,7 @@ selection_mode_leave (GtkButton *button, GtkBuilder *builder)
GtkWidget *cancelbutton;
GtkWidget *selectbutton;
GtkWidget *titlestack;
+ GtkWidget *child;
header = GTK_WIDGET (gtk_builder_get_object (builder, "header"));
list = GTK_WIDGET (gtk_builder_get_object (builder, "list"));
@@ -152,7 +157,10 @@ selection_mode_leave (GtkButton *button, GtkBuilder *builder)
gtk_list_box_set_activate_on_single_click (GTK_LIST_BOX (list), TRUE);
gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE);
- gtk_container_forall (GTK_CONTAINER (list), update_selectable, NULL);
+ for (child = gtk_widget_get_first_child (list);
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ update_selectable (child);
}
static void
@@ -170,7 +178,12 @@ select_none (GAction *action, GVariant *param, GtkWidget *list)
static void
selected_rows_changed (GtkListBox *list)
{
- gtk_container_forall (GTK_CONTAINER (list), update_selected, NULL);
+ GtkWidget *child;
+
+ for (child = gtk_widget_get_first_child (GTK_WIDGET (list));
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ update_selected (child);
}
int
diff --git a/testsuite/gtk/listbox.c b/testsuite/gtk/listbox.c
index 49e3e996bf..c36c855faa 100644
--- a/testsuite/gtk/listbox.c
+++ b/testsuite/gtk/listbox.c
@@ -23,22 +23,19 @@ sort_list (GtkListBoxRow *row1,
static void
check_sorted (GtkListBox *list)
{
- GList *children;
GtkWidget *row, *label;
gint n1, n2;
- GList *l;
n2 = n1 = 0;
- children = gtk_container_get_children (GTK_CONTAINER (list));
- for (l = children; l; l = l->next)
+ for (row = gtk_widget_get_first_child (GTK_WIDGET (list));
+ row != NULL;
+ row = gtk_widget_get_next_sibling (row))
{
- row = l->data;
n1 = n2;
label = gtk_list_box_row_get_child (GTK_LIST_BOX_ROW (row));
n2 = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (label), "data"));
g_assert_cmpint (n1, <=, n2);
}
- g_list_free (children);
}
static void
@@ -62,7 +59,7 @@ test_sort (void)
label = gtk_label_new (s);
g_object_set_data (G_OBJECT (label), "data", GINT_TO_POINTER (r));
g_free (s);
- gtk_container_add (GTK_CONTAINER (list), label);
+ gtk_list_box_insert (GTK_LIST_BOX (list), label, -1);
}
count = 0;
@@ -121,7 +118,7 @@ test_selection (void)
label = gtk_label_new (s);
g_object_set_data (G_OBJECT (label), "data", GINT_TO_POINTER (i));
g_free (s);
- gtk_container_add (GTK_CONTAINER (list), label);
+ gtk_list_box_insert (GTK_LIST_BOX (list), label, -1);
}
count = 0;
@@ -145,7 +142,7 @@ test_selection (void)
g_assert (row2 == row);
gtk_list_box_set_selection_mode (list, GTK_SELECTION_BROWSE);
- gtk_container_remove (GTK_CONTAINER (list), GTK_WIDGET (row));
+ gtk_list_box_remove (GTK_LIST_BOX (list), GTK_WIDGET (row));
g_assert (callback_row == NULL);
g_assert_cmpint (count, ==, 4);
row2 = gtk_list_box_get_selected_row (list);
@@ -211,7 +208,7 @@ test_multi_selection (void)
label = gtk_label_new (s);
g_object_set_data (G_OBJECT (label), "data", GINT_TO_POINTER (i));
g_free (s);
- gtk_container_add (GTK_CONTAINER (list), label);
+ gtk_list_box_insert (GTK_LIST_BOX (list), label, -1);
}
count = 0;
@@ -283,19 +280,17 @@ filter_func (GtkListBoxRow *row,
static void
check_filtered (GtkListBox *list)
{
- GList *children, *l;
gint count;
GtkWidget *row;
count = 0;
- children = gtk_container_get_children (GTK_CONTAINER (list));
- for (l = children; l; l = l->next)
+ for (row = gtk_widget_get_first_child (GTK_WIDGET (list));
+ row != NULL;
+ row = gtk_widget_get_next_sibling (row))
{
- row = l->data;
if (gtk_widget_get_child_visible (row))
count++;
}
- g_list_free (children);
g_assert_cmpint (count, ==, 50);
}
@@ -322,7 +317,7 @@ test_filter (void)
label = gtk_label_new (s);
g_object_set_data (G_OBJECT (label), "data", GINT_TO_POINTER (i));
g_free (s);
- gtk_container_add (GTK_CONTAINER (list), label);
+ gtk_list_box_insert (GTK_LIST_BOX (list), label, -1);
}
count = 0;
@@ -374,19 +369,17 @@ header_func (GtkListBoxRow *row,
static void
check_headers (GtkListBox *list)
{
- GList *children, *l;
gint count;
- GtkListBoxRow *row;
+ GtkWidget *row;
count = 0;
- children = gtk_container_get_children (GTK_CONTAINER (list));
- for (l = children; l; l = l->next)
+ for (row = gtk_widget_get_first_child (GTK_WIDGET (list));
+ row != NULL;
+ row = gtk_widget_get_next_sibling (row))
{
- row = l->data;
- if (gtk_list_box_row_get_header (row) != NULL)
+ if (gtk_list_box_row_get_header (GTK_LIST_BOX_ROW (row)) != NULL)
count++;
}
- g_list_free (children);
g_assert_cmpint (count, ==, 50);
}
@@ -413,7 +406,7 @@ test_header (void)
label = gtk_label_new (s);
g_object_set_data (G_OBJECT (label), "data", GINT_TO_POINTER (i));
g_free (s);
- gtk_container_add (GTK_CONTAINER (list), label);
+ gtk_list_box_insert (GTK_LIST_BOX (list), label, -1);
}
count = 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]