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.
This commit is contained in:
Benjamin Otte 2012-11-03 18:57:50 +01:00
parent c3148a81d2
commit dd6931d1ba
3 changed files with 32 additions and 80 deletions

View File

@ -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);
_gtk_widget_set_sizegroup_bumping (widget, FALSE);
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);
}
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

View File

@ -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)

View File

@ -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,