[gtk/kill-containers: 20/33] Avoid container api on grids
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/kill-containers: 20/33] Avoid container api on grids
- Date: Fri, 8 May 2020 05:08:13 +0000 (UTC)
commit 5237ddf7bbfda055206a99b0d442d48136470a0b
Author: Matthias Clasen <mclasen redhat com>
Date: Thu May 7 14:23:36 2020 -0400
Avoid container api on grids
GtkContainer is going away.
gtk/gtkcolorchooserwidget.c | 38 ++++++++++++++++-----------------
gtk/gtkplacesview.c | 6 +++---
gtk/gtkprintunixdialog.c | 35 ++++++++++++++++--------------
tests/testgrid.c | 6 +++---
tests/testoverlaystyleclass.c | 2 +-
testsuite/gtk/propertylookuplistmodel.c | 1 +
6 files changed, 45 insertions(+), 43 deletions(-)
---
diff --git a/gtk/gtkcolorchooserwidget.c b/gtk/gtkcolorchooserwidget.c
index 5dbb3b1aa4..ebfe4d8dc9 100644
--- a/gtk/gtkcolorchooserwidget.c
+++ b/gtk/gtkcolorchooserwidget.c
@@ -210,9 +210,8 @@ static void
gtk_color_chooser_widget_set_use_alpha (GtkColorChooserWidget *cc,
gboolean use_alpha)
{
- GList *children, *l;
GList *palettes, *p;
- GtkWidget *swatch;
+ GtkWidget *child;
GtkWidget *grid;
if (cc->use_alpha == use_alpha)
@@ -226,16 +225,13 @@ gtk_color_chooser_widget_set_use_alpha (GtkColorChooserWidget *cc,
{
grid = p->data;
- if (!GTK_IS_CONTAINER (grid))
- continue;
-
- children = gtk_container_get_children (GTK_CONTAINER (grid));
- for (l = children; l; l = l->next)
+ for (child = gtk_widget_get_first_child (grid);
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
{
- swatch = l->data;
- gtk_color_swatch_set_use_alpha (GTK_COLOR_SWATCH (swatch), use_alpha);
+ if (GTK_IS_COLOR_SWATCH (child))
+ gtk_color_swatch_set_use_alpha (GTK_COLOR_SWATCH (child), use_alpha);
}
- g_list_free (children);
}
g_list_free (palettes);
@@ -306,7 +302,12 @@ remove_palette (GtkColorChooserWidget *cc)
gtk_widget_get_parent (GTK_WIDGET (cc->current)) != cc->custom)
cc->current = NULL;
- children = gtk_container_get_children (GTK_CONTAINER (cc->palette));
+ children = NULL;
+ for (widget = gtk_widget_get_first_child (cc->palette);
+ widget != NULL;
+ widget = gtk_widget_get_next_sibling (widget))
+ children = g_list_prepend (children, widget);
+
for (l = children; l; l = l->next)
{
widget = l->data;
@@ -818,9 +819,8 @@ gtk_color_chooser_widget_set_rgba (GtkColorChooser *chooser,
const GdkRGBA *color)
{
GtkColorChooserWidget *cc = GTK_COLOR_CHOOSER_WIDGET (chooser);
- GList *children, *l;
GList *palettes, *p;
- GtkColorSwatch *swatch;
+ GtkWidget *swatch;
GtkWidget *w;
GdkRGBA c;
@@ -831,22 +831,20 @@ gtk_color_chooser_widget_set_rgba (GtkColorChooser *chooser,
if (!GTK_IS_GRID (w) && !GTK_IS_BOX (w))
continue;
- children = gtk_container_get_children (GTK_CONTAINER (w));
- for (l = children; l; l = l->next)
+ for (swatch = gtk_widget_get_first_child (w);
+ swatch != NULL;
+ swatch = gtk_widget_get_next_sibling (swatch))
{
- swatch = l->data;
- gtk_color_swatch_get_rgba (swatch, &c);
+ gtk_color_swatch_get_rgba (GTK_COLOR_SWATCH (swatch), &c);
if (!cc->use_alpha)
c.alpha = color->alpha;
if (gdk_rgba_equal (color, &c))
{
- select_swatch (cc, swatch);
- g_list_free (children);
+ select_swatch (cc, GTK_COLOR_SWATCH (swatch));
g_list_free (palettes);
return;
}
}
- g_list_free (children);
}
g_list_free (palettes);
diff --git a/gtk/gtkplacesview.c b/gtk/gtkplacesview.c
index 6d32dc3b48..789465e72d 100644
--- a/gtk/gtkplacesview.c
+++ b/gtk/gtkplacesview.c
@@ -587,7 +587,7 @@ populate_servers (GtkPlacesView *view)
gtk_widget_set_hexpand (label, TRUE);
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
- gtk_container_add (GTK_CONTAINER (grid), label);
+ gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
/* the uri itself */
label = gtk_label_new (uris[i]);
@@ -595,7 +595,7 @@ populate_servers (GtkPlacesView *view)
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
gtk_widget_add_css_class (label, "dim-label");
- gtk_container_add (GTK_CONTAINER (grid), label);
+ gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
/* remove button */
button = gtk_button_new_from_icon_name ("window-close-symbolic");
@@ -605,7 +605,7 @@ populate_servers (GtkPlacesView *view)
gtk_widget_add_css_class (button, "sidebar-button");
gtk_grid_attach (GTK_GRID (grid), button, 1, 0, 1, 2);
- gtk_container_add (GTK_CONTAINER (row), grid);
+ gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), grid);
gtk_container_add (GTK_CONTAINER (view->recent_servers_listbox), row);
/* custom data */
diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c
index 90ba3c5f50..3cac6af97b 100644
--- a/gtk/gtkprintunixdialog.c
+++ b/gtk/gtkprintunixdialog.c
@@ -1291,13 +1291,13 @@ wrap_in_frame (const gchar *label,
g_free (bold_text);
frame = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
- gtk_frame_set_child (GTK_FRAME (frame), label_widget);
+ gtk_container_add (GTK_CONTAINER (frame), label_widget);
gtk_widget_set_margin_start (child, 12);
gtk_widget_set_halign (child, GTK_ALIGN_FILL);
gtk_widget_set_valign (child, GTK_ALIGN_FILL);
- gtk_frame_set_child (GTK_FRAME (frame), child);
+ gtk_container_add (GTK_CONTAINER (frame), child);
gtk_widget_show (frame);
@@ -1355,14 +1355,16 @@ static gint
grid_rows (GtkGrid *table)
{
gint t0, t1, l, t, w, h;
- GList *children, *c;
+ GtkWidget *c;
+ gboolean first;
- children = gtk_container_get_children (GTK_CONTAINER (table));
t0 = t1 = 0;
- for (c = children; c; c = c->next)
+ for (c = gtk_widget_get_first_child (GTK_WIDGET (table)), first = TRUE;
+ c != NULL;
+ c = gtk_widget_get_next_sibling (GTK_WIDGET (c)), first = FALSE)
{
- gtk_grid_query_child (table, c->data, &l, &t, &w, &h);
- if (c == children)
+ gtk_grid_query_child (table, c, &l, &t, &w, &h);
+ if (first)
{
t0 = t;
t1 = t + h;
@@ -1375,7 +1377,6 @@ grid_rows (GtkGrid *table)
t1 = t + h;
}
}
- g_list_free (children);
return t1 - t0;
}
@@ -1946,17 +1947,19 @@ extension_point_clear_children (GtkContainer *container)
static void
clear_per_printer_ui (GtkPrintUnixDialog *dialog)
{
+ GtkWidget *child;
+
if (dialog->finishing_table == NULL)
return;
- gtk_container_foreach (GTK_CONTAINER (dialog->finishing_table),
- (GtkCallback)gtk_widget_destroy, NULL);
- gtk_container_foreach (GTK_CONTAINER (dialog->image_quality_table),
- (GtkCallback)gtk_widget_destroy, NULL);
- gtk_container_foreach (GTK_CONTAINER (dialog->color_table),
- (GtkCallback)gtk_widget_destroy, NULL);
- gtk_container_foreach (GTK_CONTAINER (dialog->advanced_vbox),
- (GtkCallback)gtk_widget_destroy, NULL);
+ while ((child = gtk_widget_get_first_child (dialog->finishing_table)))
+ gtk_grid_remove (GTK_GRID (dialog->finishing_table), child);
+ while ((child = gtk_widget_get_first_child (dialog->image_quality_table)))
+ gtk_grid_remove (GTK_GRID (dialog->image_quality_table), child);
+ while ((child = gtk_widget_get_first_child (dialog->color_table)))
+ gtk_grid_remove (GTK_GRID (dialog->color_table), child);
+ while ((child = gtk_widget_get_first_child (dialog->advanced_vbox)))
+ gtk_container_remove (GTK_CONTAINER (dialog->advanced_vbox), child);
extension_point_clear_children (GTK_CONTAINER (dialog->extension_point));
}
diff --git a/tests/testgrid.c b/tests/testgrid.c
index 2c614a73b5..713e0ca9c0 100644
--- a/tests/testgrid.c
+++ b/tests/testgrid.c
@@ -62,11 +62,11 @@ simple_grid (void)
gtk_grid_set_column_spacing (GTK_GRID (grid), 5);
gtk_grid_set_row_spacing (GTK_GRID (grid), 5);
test1 = test_widget ("1", "red");
- gtk_container_add (GTK_CONTAINER (grid), test1);
+ gtk_grid_attach (GTK_GRID (grid), test1, 0, 0, 1, 1);
test2 = test_widget ("2", "green");
- gtk_container_add (GTK_CONTAINER (grid), test2);
+ gtk_grid_attach (GTK_GRID (grid), test2, 1, 0, 1, 1);
test3 = test_widget ("3", "blue");
- gtk_container_add (GTK_CONTAINER (grid), test3);
+ gtk_grid_attach (GTK_GRID (grid), test3, 2, 0, 1, 1);
test4 = test_widget ("4", "green");
gtk_grid_attach (GTK_GRID (grid), test4, 0, 1, 1, 1);
gtk_widget_set_vexpand (test4, TRUE);
diff --git a/tests/testoverlaystyleclass.c b/tests/testoverlaystyleclass.c
index 37a8e08c33..e0de538221 100644
--- a/tests/testoverlaystyleclass.c
+++ b/tests/testoverlaystyleclass.c
@@ -50,7 +50,7 @@ main (int argc, char *argv[])
label = gtk_label_new ("Out of overlay");
gtk_widget_set_hexpand (label, TRUE);
gtk_widget_set_vexpand (label, TRUE);
- gtk_container_add (GTK_CONTAINER (grid), label);
+ gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
overlay = gtk_overlay_new ();
sw = gtk_scrolled_window_new (NULL, NULL);
diff --git a/testsuite/gtk/propertylookuplistmodel.c b/testsuite/gtk/propertylookuplistmodel.c
index 13c129feff..a5cbd1da4e 100644
--- a/testsuite/gtk/propertylookuplistmodel.c
+++ b/testsuite/gtk/propertylookuplistmodel.c
@@ -118,6 +118,7 @@ create_widget_tree (void)
gtk_container_add (GTK_CONTAINER (box), grid);
label = gtk_label_new ("Hello World");
+ gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
gtk_container_add (GTK_CONTAINER (grid), label);
return label;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]