From dd6931d1ba5d0b9700c65e6b357ba824843dfb71 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sat, 3 Nov 2012 18:57:50 +0100 Subject: [PATCH] sizegroup: Use _gtk_widget_compute_size_for_orientation() With this function now available, we can do size computation in 2 ways: (1) Compute size with size groups (2) Compute size without size groups And have (1) use (2) instead of setting flags on widgets. This patch does exactly that. --- gtk/gtksizegroup.c | 95 ++++++++++++++---------------------------- gtk/gtkwidget.c | 14 ------- gtk/gtkwidgetprivate.h | 3 -- 3 files changed, 32 insertions(+), 80 deletions(-) diff --git a/gtk/gtksizegroup.c b/gtk/gtksizegroup.c index b9e2ac36a3..d1295d0727 100644 --- a/gtk/gtksizegroup.c +++ b/gtk/gtksizegroup.c @@ -627,61 +627,6 @@ gtk_size_group_get_widgets (GtkSizeGroup *size_group) return size_group->priv->widgets; } -static void -compute_dimension (GtkWidget *widget, - GtkSizeGroupMode mode, - gint for_size, - gint *minimum, /* in-out */ - gint *natural) /* in-out */ -{ - GSList *widgets; - GSList *tmp_list; - gint min_result = 0, nat_result = 0; - - widgets = widget_get_size_group_peers (widget, mode); - - g_slist_foreach (widgets, (GFunc)g_object_ref, NULL); - - for (tmp_list = widgets; tmp_list; tmp_list = tmp_list->next) - { - GtkWidget *tmp_widget = tmp_list->data; - gint min_dimension, nat_dimension; - - if (tmp_widget == widget) - { - min_dimension = *minimum; - nat_dimension = *natural; - } - else - { - if (mode == GTK_SIZE_GROUP_HORIZONTAL) - { - if (for_size < 0) - gtk_widget_get_preferred_width (tmp_widget, &min_dimension, &nat_dimension); - else - gtk_widget_get_preferred_width_for_height (tmp_widget, for_size, &min_dimension, &nat_dimension); - } - else - { - if (for_size < 0) - gtk_widget_get_preferred_height (tmp_widget, &min_dimension, &nat_dimension); - else - gtk_widget_get_preferred_height_for_width (tmp_widget, for_size, &min_dimension, &nat_dimension); - } - } - - min_result = MAX (min_result, min_dimension); - nat_result = MAX (nat_result, nat_dimension); - } - - g_slist_foreach (widgets, (GFunc)g_object_unref, NULL); - - g_slist_free (widgets); - - *minimum = min_result; - *natural = nat_result; -} - /** * _gtk_size_group_bump_requisition: * @widget: a #GtkWidget @@ -705,20 +650,44 @@ _gtk_size_group_bump_requisition (GtkWidget *widget, gint *minimum, gint *natural) { - if (!_gtk_widget_get_sizegroup_bumping (widget)) + GSList *widgets; + GSList *tmp_list; + gint min_result = 0, nat_result = 0; + + if (!_gtk_widget_get_sizegroups (widget)) + return; + + widgets = widget_get_size_group_peers (widget, mode); + + g_slist_foreach (widgets, (GFunc)g_object_ref, NULL); + + for (tmp_list = widgets; tmp_list; tmp_list = tmp_list->next) { - /* Avoid recursion here */ - _gtk_widget_set_sizegroup_bumping (widget, TRUE); + GtkWidget *tmp_widget = tmp_list->data; + gint min_dimension, nat_dimension; - if (_gtk_widget_get_sizegroups (widget)) - compute_dimension (widget, mode, for_size, minimum, natural); + if (tmp_widget == widget) + { + min_dimension = *minimum; + nat_dimension = *natural; + } + else + { + _gtk_widget_compute_size_for_orientation (tmp_widget, mode, TRUE, for_size, &min_dimension, &nat_dimension); + } - _gtk_widget_set_sizegroup_bumping (widget, FALSE); + min_result = MAX (min_result, min_dimension); + nat_result = MAX (nat_result, nat_dimension); } + + g_slist_foreach (widgets, (GFunc)g_object_unref, NULL); + + g_slist_free (widgets); + + *minimum = min_result; + *natural = nat_result; } - - /** * _gtk_size_group_queue_resize: * @widget: a #GtkWidget diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 2f4dc0871c..73b8da3859 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -357,7 +357,6 @@ struct _GtkWidgetPrivate /* SizeGroup related flags */ guint sizegroup_visited : 1; - guint sizegroup_bumping : 1; guint have_size_groups : 1; /* The widget's name. If the widget does not have a name @@ -13831,19 +13830,6 @@ _gtk_widget_set_sizegroup_visited (GtkWidget *widget, widget->priv->sizegroup_visited = visited; } -gboolean -_gtk_widget_get_sizegroup_bumping (GtkWidget *widget) -{ - return widget->priv->sizegroup_bumping; -} - -void -_gtk_widget_set_sizegroup_bumping (GtkWidget *widget, - gboolean bumping) -{ - widget->priv->sizegroup_bumping = bumping; -} - void _gtk_widget_add_sizegroup (GtkWidget *widget, gpointer group) diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h index a568ed020b..4ee04e33cd 100644 --- a/gtk/gtkwidgetprivate.h +++ b/gtk/gtkwidgetprivate.h @@ -90,9 +90,6 @@ void _gtk_widget_set_height_request_needed (GtkWidget *widget, gboolean _gtk_widget_get_sizegroup_visited (GtkWidget *widget); void _gtk_widget_set_sizegroup_visited (GtkWidget *widget, gboolean visited); -gboolean _gtk_widget_get_sizegroup_bumping (GtkWidget *widget); -void _gtk_widget_set_sizegroup_bumping (GtkWidget *widget, - gboolean bumping); void _gtk_widget_add_sizegroup (GtkWidget *widget, gpointer group); void _gtk_widget_remove_sizegroup (GtkWidget *widget,