diff options
author | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2010-04-20 01:24:51 -0400 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2010-04-20 01:24:51 -0400 |
commit | 0330658a7f9f2b721a40b647f449612d7fb83125 (patch) | |
tree | 65e13837ece8d367043accdb186335620ad3674f | |
parent | 3a9ab87489d7396acfec49ce611e85cf9003f9fe (diff) | |
download | gtk+-0330658a7f9f2b721a40b647f449612d7fb83125.tar.gz |
Added request_natural argument to get_desired_size()
Currently get_desired_size() is more of an emulation of
gtk_widget_size_request() for the minimum size as it bases the
contextual request on the minimum preferred size; this argument
lets you do the request with the natural preferred size as well.
-rw-r--r-- | gtk/gtkextendedlayout.c | 30 | ||||
-rw-r--r-- | gtk/gtkextendedlayout.h | 1 |
2 files changed, 24 insertions, 7 deletions
diff --git a/gtk/gtkextendedlayout.c b/gtk/gtkextendedlayout.c index d63e265c62..72c9ff0a6e 100644 --- a/gtk/gtkextendedlayout.c +++ b/gtk/gtkextendedlayout.c @@ -44,8 +44,8 @@ typedef struct typedef struct { DesiredSize desired_widths[N_CACHED_SIZES]; DesiredSize desired_heights[N_CACHED_SIZES]; - guint cached_width_age; - guint cached_height_age; + guint8 cached_width_age; + guint8 cached_height_age; } ExtendedLayoutCache; static GQuark quark_cache = 0; @@ -74,7 +74,7 @@ gtk_extended_layout_get_type (void) /* looks for a cached size request for this for_size. If not * found, returns the oldest entry so it can be overwritten */ static gboolean -get_cached_desired_size (gfloat for_size, +get_cached_desired_size (gint for_size, DesiredSize *cached_sizes, DesiredSize **result) { @@ -168,7 +168,10 @@ compute_size_for_orientation (GtkExtendedLayout *layout, if (GTK_WIDGET_WIDTH_REQUEST_NEEDED (layout) == FALSE) found_in_cache = get_cached_desired_size (for_size, cache->desired_widths, &cached_size); else - memset (cache->desired_widths, 0x0, N_CACHED_SIZES * sizeof (DesiredSize)); + { + memset (cache->desired_widths, 0x0, N_CACHED_SIZES * sizeof (DesiredSize)); + cache->cached_width_age = 1; + } } else { @@ -177,7 +180,10 @@ compute_size_for_orientation (GtkExtendedLayout *layout, if (GTK_WIDGET_HEIGHT_REQUEST_NEEDED (layout) == FALSE) found_in_cache = get_cached_desired_size (for_size, cache->desired_heights, &cached_size); else - memset (cache->desired_heights, 0x0, N_CACHED_SIZES * sizeof (DesiredSize)); + { + memset (cache->desired_heights, 0x0, N_CACHED_SIZES * sizeof (DesiredSize)); + cache->cached_height_age = 1; + } } if (!found_in_cache) @@ -379,12 +385,17 @@ gtk_extended_layout_get_height_for_width (GtkExtendedLayout *layout, * gtk_extended_layout_get_desired_size: * @layout: a #GtkExtendedLayout instance * @width: the size which is available for allocation + * @request_natural: Whether to base the contextual request off of the + * base natural or the base minimum * @minimum_size: location for storing the minimum size, or %NULL * @natural_size: location for storing the natural size, or %NULL * * Retreives the minimum and natural size of a widget taking * into account the widget's preference for height-for-width management. * + * If request_natural is specified, the non-contextual natural value will + * be used to make the contextual request; otherwise the minimum will be used. + * * This is used to retreive a suitable size by container widgets whom dont * impose any restrictions on the child placement, examples of these are * #GtkWindow and #GtkScrolledWindow. @@ -393,6 +404,7 @@ gtk_extended_layout_get_height_for_width (GtkExtendedLayout *layout, */ void gtk_extended_layout_get_desired_size (GtkExtendedLayout *layout, + gboolean request_natural, GtkRequisition *minimum_size, GtkRequisition *natural_size) { @@ -404,12 +416,16 @@ gtk_extended_layout_get_desired_size (GtkExtendedLayout *layout, if (gtk_extended_layout_is_height_for_width (layout)) { gtk_extended_layout_get_desired_width (layout, &min_width, &nat_width); - gtk_extended_layout_get_height_for_width (layout, min_width, &min_height, &nat_height); + gtk_extended_layout_get_height_for_width (layout, + request_natural ? nat_width : min_width, + &min_height, &nat_height); } else { gtk_extended_layout_get_desired_height (layout, &min_height, &nat_height); - gtk_extended_layout_get_width_for_height (layout, min_height, &min_width, &nat_width); + gtk_extended_layout_get_width_for_height (layout, + request_natural ? nat_height : min_height, + &min_width, &nat_width); } if (minimum_size) diff --git a/gtk/gtkextendedlayout.h b/gtk/gtkextendedlayout.h index 65faa9e282..c3fdc0a0b9 100644 --- a/gtk/gtkextendedlayout.h +++ b/gtk/gtkextendedlayout.h @@ -78,6 +78,7 @@ void gtk_extended_layout_get_height_for_width (GtkExtendedLayout *layout, gint *natural_height); void gtk_extended_layout_get_desired_size (GtkExtendedLayout *layout, + gboolean request_natural, GtkRequisition *minimum_size, GtkRequisition *natural_size); |