sizerequest: Restructure code

Make the compute_size_request() function take into account size groups
itself instead of doing a weird "bump_requisition" call.
This commit is contained in:
Benjamin Otte 2012-11-04 16:10:20 +01:00
parent 7501f9770f
commit 7f870abf17
2 changed files with 58 additions and 93 deletions

View File

@ -326,78 +326,9 @@ get_vfunc_name (GtkSizeGroupMode orientation,
return for_size < 0 ? "get_preferred_height" : "get_preferred_height_for_width"; return for_size < 0 ? "get_preferred_height" : "get_preferred_height_for_width";
} }
/**
* _gtk_size_group_bump_requisition:
* @widget: a #GtkWidget
* @mode: either %GTK_SIZE_GROUP_HORIZONTAL or %GTK_SIZE_GROUP_VERTICAL, depending
* on the dimension in which to bump the size.
* @for_size: Size to request minimum and natural size for
* @minimum: a pointer to the widget's minimum size
* @natural: a pointer to the widget's natural size
*
* Refreshes the sizegroup while returning the groups requested
* value in the dimension @mode.
*
* This function is used both to update sizegroup minimum and natural size
* information and widget minimum and natural sizes in multiple passes from
* the size request apis.
*/
static void static void
gtk_size_group_bump_requisition (GtkWidget *widget, gtk_widget_query_size_for_orientation (GtkWidget *widget,
GtkSizeGroupMode mode,
gint for_size,
gint *minimum,
gint *natural)
{
GHashTable *widgets;
GHashTableIter iter;
gpointer key;
gint min_result = 0, nat_result = 0;
if (!_gtk_widget_get_sizegroups (widget))
return;
widgets = _gtk_size_group_get_widget_peers (widget, mode);
g_hash_table_foreach (widgets, (GHFunc) g_object_ref, NULL);
g_hash_table_iter_init (&iter, widgets);
while (g_hash_table_iter_next (&iter, &key, NULL))
{
GtkWidget *tmp_widget = key;
gint min_dimension, nat_dimension;
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_hash_table_foreach (widgets, (GHFunc) g_object_unref, NULL);
g_hash_table_destroy (widgets);
*minimum = min_result;
*natural = nat_result;
}
/* This is the main function that checks for a cached size and
* possibly queries the widget class to compute the size if it's
* not cached. If the for_size here is -1, then get_preferred_width()
* or get_preferred_height() will be used.
*/
void
_gtk_widget_compute_size_for_orientation (GtkWidget *widget,
GtkSizeGroupMode orientation, GtkSizeGroupMode orientation,
gboolean ignore_size_groups,
gint for_size, gint for_size,
gint *minimum_size, gint *minimum_size,
gint *natural_size) gint *natural_size)
@ -536,13 +467,6 @@ _gtk_widget_compute_size_for_orientation (GtkWidget *widget,
nat_size = cached_size->natural_size; nat_size = cached_size->natural_size;
} }
if (!ignore_size_groups)
gtk_size_group_bump_requisition (widget,
orientation,
for_size,
&min_size,
&nat_size);
if (minimum_size) if (minimum_size)
*minimum_size = min_size; *minimum_size = min_size;
@ -552,16 +476,62 @@ _gtk_widget_compute_size_for_orientation (GtkWidget *widget,
g_assert (min_size <= nat_size); g_assert (min_size <= nat_size);
GTK_NOTE (SIZE_REQUEST, GTK_NOTE (SIZE_REQUEST,
g_print ("[%p] %s\t%s: %d is minimum %d and natural: %d (hit cache: %s, ignore size groups: %s)\n", g_print ("[%p] %s\t%s: %d is minimum %d and natural: %d (hit cache: %s)\n",
widget, G_OBJECT_TYPE_NAME (widget), widget, G_OBJECT_TYPE_NAME (widget),
orientation == GTK_SIZE_GROUP_HORIZONTAL ? orientation == GTK_SIZE_GROUP_HORIZONTAL ?
"width for height" : "height for width" , "width for height" : "height for width" ,
for_size, min_size, nat_size, for_size, min_size, nat_size,
found_in_cache ? "yes" : "no", found_in_cache ? "yes" : "no"));
ignore_size_groups ? "yes" : "no"));
} }
/* This is the main function that checks for a cached size and
* possibly queries the widget class to compute the size if it's
* not cached. If the for_size here is -1, then get_preferred_width()
* or get_preferred_height() will be used.
*/
void
_gtk_widget_compute_size_for_orientation (GtkWidget *widget,
GtkSizeGroupMode mode,
gint for_size,
gint *minimum,
gint *natural)
{
GHashTable *widgets;
GHashTableIter iter;
gpointer key;
gint min_result = 0, nat_result = 0;
if (G_LIKELY (!_gtk_widget_get_sizegroups (widget)))
{
gtk_widget_query_size_for_orientation (widget, mode, for_size, minimum, natural);
return;
}
widgets = _gtk_size_group_get_widget_peers (widget, mode);
g_hash_table_foreach (widgets, (GHFunc) g_object_ref, NULL);
g_hash_table_iter_init (&iter, widgets);
while (g_hash_table_iter_next (&iter, &key, NULL))
{
GtkWidget *tmp_widget = key;
gint min_dimension, nat_dimension;
gtk_widget_query_size_for_orientation (tmp_widget, mode, for_size, &min_dimension, &nat_dimension);
min_result = MAX (min_result, min_dimension);
nat_result = MAX (nat_result, nat_dimension);
}
g_hash_table_foreach (widgets, (GHFunc) g_object_unref, NULL);
g_hash_table_destroy (widgets);
*minimum = min_result;
*natural = nat_result;
}
/** /**
* gtk_widget_get_request_mode: * gtk_widget_get_request_mode:
* @widget: a #GtkWidget instance * @widget: a #GtkWidget instance
@ -615,7 +585,6 @@ gtk_widget_get_preferred_width (GtkWidget *widget,
_gtk_widget_compute_size_for_orientation (widget, _gtk_widget_compute_size_for_orientation (widget,
GTK_SIZE_GROUP_HORIZONTAL, GTK_SIZE_GROUP_HORIZONTAL,
FALSE,
-1, -1,
minimum_width, minimum_width,
natural_width); natural_width);
@ -650,7 +619,6 @@ gtk_widget_get_preferred_height (GtkWidget *widget,
_gtk_widget_compute_size_for_orientation (widget, _gtk_widget_compute_size_for_orientation (widget,
GTK_SIZE_GROUP_VERTICAL, GTK_SIZE_GROUP_VERTICAL,
FALSE,
-1, -1,
minimum_height, minimum_height,
natural_height); natural_height);
@ -688,7 +656,6 @@ gtk_widget_get_preferred_width_for_height (GtkWidget *widget,
_gtk_widget_compute_size_for_orientation (widget, _gtk_widget_compute_size_for_orientation (widget,
GTK_SIZE_GROUP_HORIZONTAL, GTK_SIZE_GROUP_HORIZONTAL,
FALSE,
height, height,
minimum_width, minimum_width,
natural_width); natural_width);
@ -724,7 +691,6 @@ gtk_widget_get_preferred_height_for_width (GtkWidget *widget,
_gtk_widget_compute_size_for_orientation (widget, _gtk_widget_compute_size_for_orientation (widget,
GTK_SIZE_GROUP_VERTICAL, GTK_SIZE_GROUP_VERTICAL,
FALSE,
width, width,
minimum_height, minimum_height,
natural_height); natural_height);

View File

@ -108,7 +108,6 @@ void _gtk_widget_restore_size_request (GtkWidget *widget,
int old_height); int old_height);
void _gtk_widget_compute_size_for_orientation (GtkWidget *widget, void _gtk_widget_compute_size_for_orientation (GtkWidget *widget,
GtkSizeGroupMode orientation, GtkSizeGroupMode orientation,
gboolean ignore_size_groups,
gint for_size, gint for_size,
gint *minimum_size, gint *minimum_size,
gint *natural_size); gint *natural_size);