[gtk/kill-containers: 7/49] Avoid container api on grids
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/kill-containers: 7/49] Avoid container api on grids
- Date: Tue, 12 May 2020 01:57:32 +0000 (UTC)
commit 0829f56ec29391aba392658f15166ecc028840fa
Author: Matthias Clasen <mclasen redhat com>
Date: Thu May 7 14:23:36 2020 -0400
Avoid container api on grids
GtkContainer is going away.
demos/gtk-demo/font_features.c | 2 +-
gtk/gtkcolorchooserwidget.c | 38 ++++++++++++++++-----------------
gtk/gtkfontchooserwidget.c | 6 +++---
gtk/gtkplacesview.c | 6 +++---
gtk/gtkprintunixdialog.c | 19 +++++++++--------
tests/testgrid.c | 6 +++---
tests/testoverlaystyleclass.c | 2 +-
testsuite/gtk/propertylookuplistmodel.c | 4 ++--
8 files changed, 41 insertions(+), 42 deletions(-)
---
diff --git a/demos/gtk-demo/font_features.c b/demos/gtk-demo/font_features.c
index 818164d5f3..07f343e70e 100644
--- a/demos/gtk-demo/font_features.c
+++ b/demos/gtk-demo/font_features.c
@@ -1038,7 +1038,7 @@ update_font_variations (void)
child = gtk_widget_get_first_child (variations_grid);
while ((child = gtk_widget_get_first_child (variations_grid)))
- gtk_container_remove (GTK_CONTAINER (variations_grid), child);
+ gtk_grid_remove (GTK_GRID (variations_grid), child);
instance_combo = NULL;
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/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index ab0a890671..0bd544d4d1 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -839,9 +839,9 @@ axis_remove (gpointer key,
GtkFontChooserWidget *fontchooser = data;
Axis *a = value;
- gtk_container_remove (GTK_CONTAINER (fontchooser->axis_grid), a->label);
- gtk_container_remove (GTK_CONTAINER (fontchooser->axis_grid), a->scale);
- gtk_container_remove (GTK_CONTAINER (fontchooser->axis_grid), a->spin);
+ gtk_grid_remove (GTK_GRID (fontchooser->axis_grid), a->label);
+ gtk_grid_remove (GTK_GRID (fontchooser->axis_grid), a->scale);
+ gtk_grid_remove (GTK_GRID (fontchooser->axis_grid), a->spin);
}
static void
diff --git a/gtk/gtkplacesview.c b/gtk/gtkplacesview.c
index 6ea06f65bb..fa4ac5201a 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 a4a6db0559..2dbb63fcef 100644
--- a/gtk/gtkprintunixdialog.c
+++ b/gtk/gtkprintunixdialog.c
@@ -1367,14 +1367,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;
@@ -1387,7 +1389,6 @@ grid_rows (GtkGrid *table)
t1 = t + h;
}
}
- g_list_free (children);
return t1 - t0;
}
@@ -1947,11 +1948,11 @@ clear_per_printer_ui (GtkPrintUnixDialog *dialog)
return;
while ((child = gtk_widget_get_first_child (dialog->finishing_table)))
- gtk_container_remove (GTK_CONTAINER (dialog->finishing_table), child);
+ gtk_grid_remove (GTK_GRID (dialog->finishing_table), child);
while ((child = gtk_widget_get_first_child (dialog->image_quality_table)))
- gtk_container_remove (GTK_CONTAINER (dialog->image_quality_table), child);
+ gtk_grid_remove (GTK_GRID (dialog->image_quality_table), child);
while ((child = gtk_widget_get_first_child (dialog->color_table)))
- gtk_container_remove (GTK_CONTAINER (dialog->color_table), child);
+ 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);
while ((child = gtk_widget_get_first_child (dialog->extension_point)))
diff --git a/tests/testgrid.c b/tests/testgrid.c
index 641f1de541..2369a7249e 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 d835295af5..a79d07cfe2 100644
--- a/testsuite/gtk/propertylookuplistmodel.c
+++ b/testsuite/gtk/propertylookuplistmodel.c
@@ -118,7 +118,7 @@ create_widget_tree (void)
gtk_container_add (GTK_CONTAINER (box), grid);
label = gtk_label_new ("Hello World");
- gtk_container_add (GTK_CONTAINER (grid), label);
+ gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
return label;
}
@@ -214,7 +214,7 @@ test_change_property (void)
assert_model (model, "GtkLabel GtkGrid GtkBox GtkWindow");
assert_changes (model, "0+4");
- gtk_container_remove (GTK_CONTAINER (parent), widget);
+ gtk_grid_remove (GTK_GRID (parent), widget);
assert_model (model, "GtkLabel");
assert_changes (model, "1-3");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]