[gtk+/wip/baedert/children: 17/44] widget: Iterate over child widgets instead of gtk_container_forall
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/baedert/children: 17/44] widget: Iterate over child widgets instead of gtk_container_forall
- Date: Wed, 30 Nov 2016 20:02:19 +0000 (UTC)
commit c2f830b29f1abac9a1dd38d9e51758e262feabdd
Author: Timm Bäder <mail baedert org>
Date: Mon Nov 21 17:04:20 2016 +0100
widget: Iterate over child widgets instead of gtk_container_forall
gtk/gtkwidget.c | 178 +++++++++++++++++++++++++++++++++----------------------
1 files changed, 106 insertions(+), 72 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index c26dbc9..654be1d 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -4486,14 +4486,6 @@ typedef struct {
} DeviceEnableData;
static void
-device_enable_foreach (GtkWidget *widget,
- gpointer user_data)
-{
- DeviceEnableData *data = user_data;
- gtk_widget_set_device_enabled_internal (widget, data->device, TRUE, data->enabled);
-}
-
-static void
device_enable_foreach_window (gpointer win,
gpointer user_data)
{
@@ -4545,8 +4537,19 @@ gtk_widget_set_device_enabled_internal (GtkWidget *widget,
g_list_foreach (window_list, device_enable_foreach_window, &data);
}
- if (recurse && GTK_IS_CONTAINER (widget))
- gtk_container_forall (GTK_CONTAINER (widget), device_enable_foreach, &data);
+ if (recurse)
+ {
+ GtkWidget *child;
+ for (child = gtk_widget_get_first_child (widget);
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ gtk_widget_set_device_enabled_internal (child,
+ device,
+ TRUE,
+ enabled);
+ }
+ }
}
static void
@@ -8609,6 +8612,7 @@ gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
gpointer client_data)
{
GtkWidgetPrivate *priv = widget->priv;
+ GtkWidget *child;
HierarchyChangedInfo *info = client_data;
gboolean new_anchored = _gtk_widget_is_toplevel (widget) ||
(priv->parent && priv->parent->priv->anchored);
@@ -8633,10 +8637,12 @@ gtk_widget_propagate_hierarchy_changed_recurse (GtkWidget *widget,
g_signal_emit (widget, widget_signals[HIERARCHY_CHANGED], 0, info->previous_toplevel);
do_screen_change (widget, info->previous_screen, info->new_screen);
- if (GTK_IS_CONTAINER (widget))
- gtk_container_forall (GTK_CONTAINER (widget),
- gtk_widget_propagate_hierarchy_changed_recurse,
- client_data);
+ for (child = gtk_widget_get_first_child (widget);
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ gtk_widget_propagate_hierarchy_changed_recurse (child, client_data);
+ }
g_object_unref (widget);
}
@@ -8685,15 +8691,18 @@ gtk_widget_propagate_screen_changed_recurse (GtkWidget *widget,
gpointer client_data)
{
HierarchyChangedInfo *info = client_data;
+ GtkWidget *child;
g_object_ref (widget);
do_screen_change (widget, info->previous_screen, info->new_screen);
- if (GTK_IS_CONTAINER (widget))
- gtk_container_forall (GTK_CONTAINER (widget),
- gtk_widget_propagate_screen_changed_recurse,
- client_data);
+ for (child = gtk_widget_get_first_child (widget);
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ gtk_widget_propagate_screen_changed_recurse (child, client_data);
+ }
g_object_unref (widget);
}
@@ -8725,14 +8734,17 @@ _gtk_widget_propagate_screen_changed (GtkWidget *widget,
}
static void
-reset_style_recurse (GtkWidget *widget, gpointer data)
+reset_style_recurse (GtkWidget *widget)
{
+ GtkWidget *child;
_gtk_widget_invalidate_style_context (widget, GTK_CSS_CHANGE_ANY);
- if (GTK_IS_CONTAINER (widget))
- gtk_container_forall (GTK_CONTAINER (widget),
- reset_style_recurse,
- NULL);
+ for (child = gtk_widget_get_first_child (widget);
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ reset_style_recurse (child);
+ }
}
/**
@@ -8751,7 +8763,7 @@ gtk_widget_reset_style (GtkWidget *widget)
{
g_return_if_fail (GTK_IS_WIDGET (widget));
- reset_style_recurse (widget, NULL);
+ reset_style_recurse (widget);
g_list_foreach (widget->priv->attached_windows,
(GFunc) reset_style_recurse, NULL);
@@ -8903,8 +8915,7 @@ gtk_widget_push_verify_invariants (GtkWidget *widget)
}
static void
-gtk_widget_verify_child_invariants (GtkWidget *widget,
- gpointer client_data)
+gtk_widget_verify_child_invariants (GtkWidget *widget)
{
/* We don't recurse further; this is a one-level check. */
gtk_widget_verify_invariants (widget);
@@ -8919,21 +8930,22 @@ gtk_widget_pop_verify_invariants (GtkWidget *widget)
if (widget->priv->verifying_invariants_count == 0)
{
+ GtkWidget *child;
gtk_widget_verify_invariants (widget);
- if (GTK_IS_CONTAINER (widget))
+ /* Check one level of children, because our
+ * push_verify_invariants() will have prevented some of the
+ * checks. This does not recurse because if recursion is
+ * needed, it will happen naturally as each child has a
+ * push/pop on that child. For example if we're recursively
+ * mapping children, we'll push/pop on each child as we map
+ * it.
+ */
+ for (child = gtk_widget_get_first_child (widget);
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
{
- /* Check one level of children, because our
- * push_verify_invariants() will have prevented some of the
- * checks. This does not recurse because if recursion is
- * needed, it will happen naturally as each child has a
- * push/pop on that child. For example if we're recursively
- * mapping children, we'll push/pop on each child as we map
- * it.
- */
- gtk_container_forall (GTK_CONTAINER (widget),
- gtk_widget_verify_child_invariants,
- NULL);
+ gtk_widget_verify_child_invariants (child);
}
}
}
@@ -9101,17 +9113,21 @@ gtk_widget_get_font_options (GtkWidget *widget)
}
static void
-gtk_widget_set_font_map_recurse (GtkWidget *widget, gpointer data)
+gtk_widget_set_font_map_recurse (GtkWidget *widget)
{
+ GtkWidget *child;
+
if (g_object_get_qdata (G_OBJECT (widget), quark_font_map))
return;
gtk_widget_update_pango_context (widget);
- if (GTK_IS_CONTAINER (widget))
- gtk_container_forall (GTK_CONTAINER (widget),
- gtk_widget_set_font_map_recurse,
- data);
+ for (child = gtk_widget_get_first_child (widget);
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ gtk_widget_set_font_map_recurse (child);
+ }
}
/**
@@ -9130,6 +9146,7 @@ gtk_widget_set_font_map (GtkWidget *widget,
PangoFontMap *font_map)
{
PangoFontMap *map;
+ GtkWidget *child;
g_return_if_fail (GTK_IS_WIDGET (widget));
@@ -9143,10 +9160,13 @@ gtk_widget_set_font_map (GtkWidget *widget,
g_object_unref);
gtk_widget_update_pango_context (widget);
- if (GTK_IS_CONTAINER (widget))
- gtk_container_forall (GTK_CONTAINER (widget),
- gtk_widget_set_font_map_recurse,
- NULL);
+
+ for (child = gtk_widget_get_first_child (widget);
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ gtk_widget_set_font_map_recurse (child);
+ }
}
/**
@@ -9456,6 +9476,7 @@ void
_gtk_widget_scale_changed (GtkWidget *widget)
{
GtkWidgetPrivate *priv;
+ GtkWidget *child;
g_return_if_fail (GTK_IS_WIDGET (widget));
@@ -9468,10 +9489,12 @@ _gtk_widget_scale_changed (GtkWidget *widget)
gtk_widget_queue_draw (widget);
- if (GTK_IS_CONTAINER (widget))
- gtk_container_forall (GTK_CONTAINER (widget),
- (GtkCallback) _gtk_widget_scale_changed,
- NULL);
+ for (child = gtk_widget_get_first_child (widget);
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ _gtk_widget_scale_changed (child);
+ }
}
/**
@@ -10344,16 +10367,19 @@ static void
gtk_widget_set_default_direction_recurse (GtkWidget *widget, gpointer data)
{
GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
+ GtkWidget *child;
g_object_ref (widget);
if (widget->priv->direction == GTK_TEXT_DIR_NONE)
gtk_widget_emit_direction_changed (widget, old_dir);
- if (GTK_IS_CONTAINER (widget))
- gtk_container_forall (GTK_CONTAINER (widget),
- gtk_widget_set_default_direction_recurse,
- data);
+ for (child = gtk_widget_get_first_child (widget);
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ gtk_widget_set_default_direction_recurse (child, data);
+ }
g_object_unref (widget);
}
@@ -10758,6 +10784,7 @@ static void
gtk_widget_real_unrealize (GtkWidget *widget)
{
GtkWidgetPrivate *priv = widget->priv;
+ GtkWidget *child;
g_assert (!widget->priv->mapped);
@@ -10767,10 +10794,12 @@ gtk_widget_real_unrealize (GtkWidget *widget)
* (for example, gdk_ic_destroy () with destroyed window causes crash.)
*/
- if (GTK_IS_CONTAINER (widget))
- gtk_container_forall (GTK_CONTAINER (widget),
- (GtkCallback) gtk_widget_unrealize,
- NULL);
+ for (child = gtk_widget_get_first_child (widget);
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ gtk_widget_unrealize (child);
+ }
if (_gtk_widget_get_has_window (widget))
{
@@ -11171,6 +11200,8 @@ gtk_widget_propagate_state (GtkWidget *widget,
{
GtkWidgetPrivate *priv = widget->priv;
GtkStateFlags new_flags, old_flags = priv->state_flags;
+ GtkStateData child_data;
+ GtkWidget *child;
priv->state_flags |= data->flags_to_set;
priv->state_flags &= ~(data->flags_to_unset);
@@ -11242,17 +11273,16 @@ gtk_widget_propagate_state (GtkWidget *widget,
if (!gtk_widget_is_sensitive (widget))
gtk_widget_reset_controllers (widget);
- if (GTK_IS_CONTAINER (widget))
- {
- GtkStateData child_data;
- /* Make sure to only propagate the right states further */
- child_data.flags_to_set = data->flags_to_set & GTK_STATE_FLAGS_DO_PROPAGATE;
- child_data.flags_to_unset = data->flags_to_unset & GTK_STATE_FLAGS_DO_PROPAGATE;
+ /* Make sure to only propagate the right states further */
+ child_data.flags_to_set = data->flags_to_set & GTK_STATE_FLAGS_DO_PROPAGATE;
+ child_data.flags_to_unset = data->flags_to_unset & GTK_STATE_FLAGS_DO_PROPAGATE;
- gtk_container_forall (GTK_CONTAINER (widget),
- (GtkCallback) gtk_widget_propagate_state,
- &child_data);
+ for (child = gtk_widget_get_first_child (widget);
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ gtk_widget_propagate_state (child, &child_data);
}
g_object_unref (widget);
@@ -14470,12 +14500,16 @@ gtk_widget_ensure_allocate (GtkWidget *widget)
}
else if (priv->alloc_needed_on_child)
{
+ GtkWidget *child;
+
priv->alloc_needed_on_child = FALSE;
- if (GTK_IS_CONTAINER (widget))
- gtk_container_forall (GTK_CONTAINER (widget),
- (GtkCallback) gtk_widget_ensure_allocate,
- NULL);
+ for (child = gtk_widget_get_first_child (widget);
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ gtk_widget_ensure_allocate (child);
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]