2010-06-18 04:11:26 +00:00
|
|
|
/* gtksizerequest.c
|
2010-04-20 22:53:54 +00:00
|
|
|
* Copyright (C) 2007-2010 Openismus GmbH
|
2009-12-02 08:48:42 +00:00
|
|
|
*
|
2010-04-20 22:53:54 +00:00
|
|
|
* Authors:
|
2009-12-02 08:48:42 +00:00
|
|
|
* Mathias Hasselmann <mathias@openismus.com>
|
2010-04-20 22:53:54 +00:00
|
|
|
* Tristan Van Berkom <tristan.van.berkom@gmail.com>
|
2009-12-02 08:48:42 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2010-10-19 17:14:46 +00:00
|
|
|
|
2010-06-18 04:11:26 +00:00
|
|
|
#include "gtksizerequest.h"
|
2010-10-19 17:14:46 +00:00
|
|
|
|
2010-09-18 23:57:32 +00:00
|
|
|
#include "gtkdebug.h"
|
2009-12-02 08:48:42 +00:00
|
|
|
#include "gtkintl.h"
|
2010-10-19 17:14:46 +00:00
|
|
|
#include "gtkprivate.h"
|
|
|
|
#include "gtksizegroup-private.h"
|
|
|
|
#include "gtkwidgetprivate.h"
|
2009-12-02 08:48:42 +00:00
|
|
|
|
2010-04-13 02:21:46 +00:00
|
|
|
/* looks for a cached size request for this for_size. If not
|
2010-04-24 01:52:55 +00:00
|
|
|
* found, returns the oldest entry so it can be overwritten
|
2010-04-21 05:32:55 +00:00
|
|
|
*
|
2010-04-24 01:52:55 +00:00
|
|
|
* Note that this caching code was directly derived from
|
2010-04-21 05:32:55 +00:00
|
|
|
* the Clutter toolkit.
|
|
|
|
*/
|
2010-04-13 02:21:46 +00:00
|
|
|
static gboolean
|
2010-09-21 03:52:49 +00:00
|
|
|
get_cached_size (SizeRequestCache *cache,
|
|
|
|
GtkSizeGroupMode orientation,
|
|
|
|
gint for_size,
|
|
|
|
SizeRequest **result)
|
2009-12-02 08:48:42 +00:00
|
|
|
{
|
2010-09-21 03:52:49 +00:00
|
|
|
guint i, n_sizes;
|
|
|
|
SizeRequest *cached_sizes;
|
2009-12-02 08:48:42 +00:00
|
|
|
|
2010-09-21 03:52:49 +00:00
|
|
|
if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
|
|
|
|
{
|
|
|
|
cached_sizes = cache->widths;
|
|
|
|
n_sizes = cache->cached_widths;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cached_sizes = cache->heights;
|
|
|
|
n_sizes = cache->cached_widths;
|
|
|
|
}
|
2009-12-02 08:48:42 +00:00
|
|
|
|
2010-09-21 03:52:49 +00:00
|
|
|
/* Search for an already cached size */
|
|
|
|
for (i = 0; i < n_sizes; i++)
|
2010-04-13 02:21:46 +00:00
|
|
|
{
|
2010-09-21 03:52:49 +00:00
|
|
|
if (cached_sizes[i].for_size == for_size)
|
|
|
|
{
|
|
|
|
*result = &cached_sizes[i];
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
2010-04-11 02:32:55 +00:00
|
|
|
|
2010-09-21 03:52:49 +00:00
|
|
|
/* If not found, pull a new size from the cache, the returned size cache
|
|
|
|
* will immediately be used to cache the new computed size so we go ahead
|
|
|
|
* and increment the last_cached_width/height right away */
|
|
|
|
if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
|
|
|
|
{
|
|
|
|
if (cache->cached_widths < GTK_SIZE_REQUEST_CACHED_SIZES)
|
|
|
|
{
|
|
|
|
cache->cached_widths++;
|
|
|
|
cache->last_cached_width = cache->cached_widths - 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (++cache->last_cached_width == GTK_SIZE_REQUEST_CACHED_SIZES)
|
|
|
|
cache->last_cached_width = 0;
|
|
|
|
}
|
2010-04-13 02:21:46 +00:00
|
|
|
|
2010-09-21 03:52:49 +00:00
|
|
|
*result = &cache->widths[cache->last_cached_width];
|
|
|
|
}
|
|
|
|
else /* GTK_SIZE_GROUP_VERTICAL */
|
|
|
|
{
|
|
|
|
if (cache->cached_heights < GTK_SIZE_REQUEST_CACHED_SIZES)
|
|
|
|
{
|
|
|
|
cache->cached_heights++;
|
|
|
|
cache->last_cached_height = cache->cached_heights - 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (++cache->last_cached_height == GTK_SIZE_REQUEST_CACHED_SIZES)
|
|
|
|
cache->last_cached_height = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*result = &cache->heights[cache->last_cached_height];
|
2010-04-13 02:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-04-11 02:32:55 +00:00
|
|
|
|
2010-04-17 05:51:10 +00:00
|
|
|
static void
|
2010-09-07 22:25:47 +00:00
|
|
|
do_size_request (GtkWidget *widget,
|
|
|
|
GtkRequisition *requisition)
|
2010-04-17 05:51:10 +00:00
|
|
|
{
|
2010-09-07 22:25:47 +00:00
|
|
|
/* Now we dont bother caching the deprecated "size-request" returns,
|
|
|
|
* just unconditionally invoke here just in case we run into legacy stuff */
|
|
|
|
gtk_widget_ensure_style (widget);
|
|
|
|
g_signal_emit_by_name (widget, "size-request", requisition);
|
2010-04-17 05:51:10 +00:00
|
|
|
}
|
|
|
|
|
2010-09-05 06:48:36 +00:00
|
|
|
#ifndef G_DISABLE_CHECKS
|
|
|
|
static GQuark recursion_check_quark = 0;
|
|
|
|
#endif /* G_DISABLE_CHECKS */
|
|
|
|
|
|
|
|
static void
|
2010-10-26 14:53:46 +00:00
|
|
|
push_recursion_check (GtkWidget *widget,
|
2010-09-05 06:48:36 +00:00
|
|
|
GtkSizeGroupMode orientation,
|
|
|
|
gint for_size)
|
|
|
|
{
|
|
|
|
#ifndef G_DISABLE_CHECKS
|
|
|
|
const char *previous_method;
|
|
|
|
const char *method;
|
|
|
|
|
|
|
|
if (recursion_check_quark == 0)
|
|
|
|
recursion_check_quark = g_quark_from_static_string ("gtk-size-request-in-progress");
|
|
|
|
|
2010-10-26 14:53:46 +00:00
|
|
|
previous_method = g_object_get_qdata (G_OBJECT (widget), recursion_check_quark);
|
2010-09-05 06:48:36 +00:00
|
|
|
|
|
|
|
if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
|
|
|
|
{
|
|
|
|
method = for_size < 0 ? "get_width" : "get_width_for_height";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
method = for_size < 0 ? "get_height" : "get_height_for_width";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (previous_method != NULL)
|
|
|
|
{
|
2010-09-21 14:35:17 +00:00
|
|
|
g_warning ("%s %p: widget tried to gtk_widget_%s inside "
|
|
|
|
" GtkWidget ::%s implementation. "
|
|
|
|
"Should just invoke GTK_WIDGET_GET_CLASS(widget)->%s "
|
|
|
|
"directly rather than using gtk_widget_%s",
|
2010-10-26 14:53:46 +00:00
|
|
|
G_OBJECT_TYPE_NAME (widget), widget,
|
2010-09-05 06:48:36 +00:00
|
|
|
method, previous_method,
|
|
|
|
method, method);
|
|
|
|
}
|
|
|
|
|
2010-10-26 14:53:46 +00:00
|
|
|
g_object_set_qdata (G_OBJECT (widget), recursion_check_quark, (char*) method);
|
2010-09-05 06:48:36 +00:00
|
|
|
#endif /* G_DISABLE_CHECKS */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-26 14:53:46 +00:00
|
|
|
pop_recursion_check (GtkWidget *widget,
|
2010-09-05 06:48:36 +00:00
|
|
|
GtkSizeGroupMode orientation)
|
|
|
|
{
|
|
|
|
#ifndef G_DISABLE_CHECKS
|
2010-10-26 14:53:46 +00:00
|
|
|
g_object_set_qdata (G_OBJECT (widget), recursion_check_quark, NULL);
|
2010-09-05 06:48:36 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-04-17 05:51:10 +00:00
|
|
|
static void
|
2010-10-26 14:53:46 +00:00
|
|
|
compute_size_for_orientation (GtkWidget *widget,
|
2010-04-24 01:52:55 +00:00
|
|
|
GtkSizeGroupMode orientation,
|
|
|
|
gint for_size,
|
|
|
|
gint *minimum_size,
|
|
|
|
gint *natural_size)
|
2010-04-17 05:51:10 +00:00
|
|
|
{
|
2010-06-18 04:11:26 +00:00
|
|
|
SizeRequestCache *cache;
|
|
|
|
SizeRequest *cached_size;
|
|
|
|
gboolean found_in_cache = FALSE;
|
2010-09-05 16:19:14 +00:00
|
|
|
int adjusted_min, adjusted_natural;
|
2010-04-17 05:51:10 +00:00
|
|
|
|
2010-10-26 14:53:46 +00:00
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
2010-04-17 05:51:10 +00:00
|
|
|
g_return_if_fail (minimum_size != NULL || natural_size != NULL);
|
|
|
|
|
2010-09-09 06:02:56 +00:00
|
|
|
cache = _gtk_widget_peek_request_cache (widget);
|
2010-04-17 05:51:10 +00:00
|
|
|
|
|
|
|
if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
|
|
|
|
{
|
2010-06-18 04:11:26 +00:00
|
|
|
cached_size = &cache->widths[0];
|
2010-04-24 01:52:55 +00:00
|
|
|
|
2010-09-18 23:57:32 +00:00
|
|
|
if (!_gtk_widget_get_width_request_needed (widget))
|
2010-09-21 03:52:49 +00:00
|
|
|
found_in_cache = get_cached_size (cache, orientation, for_size, &cached_size);
|
2010-04-20 00:41:23 +00:00
|
|
|
else
|
2010-04-24 01:52:55 +00:00
|
|
|
{
|
2010-09-09 06:02:56 +00:00
|
|
|
memset (cache->widths, 0, GTK_SIZE_REQUEST_CACHED_SIZES * sizeof (SizeRequest));
|
2010-09-21 03:52:49 +00:00
|
|
|
cache->cached_widths = 1;
|
|
|
|
cache->last_cached_width = 0;
|
2010-04-24 01:52:55 +00:00
|
|
|
}
|
2010-04-17 05:51:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-18 04:11:26 +00:00
|
|
|
cached_size = &cache->heights[0];
|
2010-04-24 01:52:55 +00:00
|
|
|
|
2010-09-18 23:57:32 +00:00
|
|
|
if (!_gtk_widget_get_height_request_needed (widget))
|
2010-09-21 03:52:49 +00:00
|
|
|
found_in_cache = get_cached_size (cache, orientation, for_size, &cached_size);
|
2010-04-20 00:41:23 +00:00
|
|
|
else
|
2010-04-24 01:52:55 +00:00
|
|
|
{
|
2010-09-09 06:02:56 +00:00
|
|
|
memset (cache->heights, 0, GTK_SIZE_REQUEST_CACHED_SIZES * sizeof (SizeRequest));
|
2010-09-21 03:52:49 +00:00
|
|
|
cache->cached_heights = 1;
|
|
|
|
cache->last_cached_height = 0;
|
2010-04-24 01:52:55 +00:00
|
|
|
}
|
2010-04-17 05:51:10 +00:00
|
|
|
}
|
2010-04-28 14:04:21 +00:00
|
|
|
|
2010-04-17 05:51:10 +00:00
|
|
|
if (!found_in_cache)
|
|
|
|
{
|
2010-09-07 22:25:47 +00:00
|
|
|
GtkRequisition requisition = { 0, 0 };
|
2010-04-17 05:51:10 +00:00
|
|
|
gint min_size = 0, nat_size = 0;
|
2010-09-14 05:52:59 +00:00
|
|
|
gint requisition_size;
|
2010-04-17 05:51:10 +00:00
|
|
|
|
|
|
|
/* Unconditional size request runs but is often unhandled. */
|
2010-09-07 22:25:47 +00:00
|
|
|
do_size_request (widget, &requisition);
|
2010-04-17 05:51:10 +00:00
|
|
|
|
|
|
|
if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
|
2010-04-24 01:52:55 +00:00
|
|
|
{
|
2010-09-07 22:25:47 +00:00
|
|
|
requisition_size = requisition.width;
|
2010-04-24 01:52:55 +00:00
|
|
|
|
|
|
|
if (for_size < 0)
|
2010-10-22 15:04:46 +00:00
|
|
|
{
|
2010-10-26 14:53:46 +00:00
|
|
|
push_recursion_check (widget, orientation, for_size);
|
|
|
|
GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_size, &nat_size);
|
|
|
|
pop_recursion_check (widget, orientation);
|
2010-10-22 15:04:46 +00:00
|
|
|
}
|
2010-04-24 01:52:55 +00:00
|
|
|
else
|
2010-10-22 15:04:46 +00:00
|
|
|
{
|
|
|
|
int ignored_position = 0;
|
|
|
|
int natural_height;
|
|
|
|
|
|
|
|
/* Pull the base natural height from the cache as it's needed to adjust
|
|
|
|
* the proposed 'for_size' */
|
|
|
|
gtk_widget_get_preferred_height (widget, NULL, &natural_height);
|
|
|
|
|
|
|
|
/* convert for_size to unadjusted height (for_size is a proposed allocation) */
|
2010-10-26 14:53:46 +00:00
|
|
|
GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
|
|
|
|
GTK_ORIENTATION_VERTICAL,
|
|
|
|
&natural_height,
|
|
|
|
&ignored_position,
|
|
|
|
&for_size);
|
|
|
|
|
|
|
|
push_recursion_check (widget, orientation, for_size);
|
|
|
|
GTK_WIDGET_GET_CLASS (widget)->get_preferred_width_for_height (widget, for_size,
|
2010-10-22 15:04:46 +00:00
|
|
|
&min_size, &nat_size);
|
2010-10-26 14:53:46 +00:00
|
|
|
pop_recursion_check (widget, orientation);
|
2010-10-22 15:04:46 +00:00
|
|
|
}
|
2010-04-24 01:52:55 +00:00
|
|
|
}
|
2010-04-17 05:51:10 +00:00
|
|
|
else
|
2010-04-24 01:52:55 +00:00
|
|
|
{
|
2010-09-07 22:25:47 +00:00
|
|
|
requisition_size = requisition.height;
|
2010-04-17 05:51:10 +00:00
|
|
|
|
2010-04-24 01:52:55 +00:00
|
|
|
if (for_size < 0)
|
2010-10-22 15:04:46 +00:00
|
|
|
{
|
2010-10-26 14:53:46 +00:00
|
|
|
push_recursion_check (widget, orientation, for_size);
|
|
|
|
GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, &min_size, &nat_size);
|
|
|
|
pop_recursion_check (widget, orientation);
|
2010-10-22 15:04:46 +00:00
|
|
|
}
|
2010-04-24 01:52:55 +00:00
|
|
|
else
|
2010-10-22 15:04:46 +00:00
|
|
|
{
|
|
|
|
int ignored_position = 0;
|
|
|
|
int natural_width;
|
|
|
|
|
|
|
|
/* Pull the base natural width from the cache as it's needed to adjust
|
|
|
|
* the proposed 'for_size' */
|
|
|
|
gtk_widget_get_preferred_width (widget, NULL, &natural_width);
|
|
|
|
|
|
|
|
/* convert for_size to unadjusted width (for_size is a proposed allocation) */
|
2010-10-26 14:53:46 +00:00
|
|
|
GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
|
|
|
|
GTK_ORIENTATION_HORIZONTAL,
|
|
|
|
&natural_width,
|
|
|
|
&ignored_position,
|
|
|
|
&for_size);
|
|
|
|
|
|
|
|
push_recursion_check (widget, orientation, for_size);
|
|
|
|
GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget, for_size,
|
2010-10-22 15:04:46 +00:00
|
|
|
&min_size, &nat_size);
|
2010-10-26 14:53:46 +00:00
|
|
|
pop_recursion_check (widget, orientation);
|
2010-10-22 15:04:46 +00:00
|
|
|
}
|
2010-04-24 01:52:55 +00:00
|
|
|
}
|
2010-04-17 05:51:10 +00:00
|
|
|
|
2010-09-06 01:46:22 +00:00
|
|
|
if (min_size > nat_size)
|
|
|
|
{
|
|
|
|
g_warning ("%s %p reported min size %d and natural size %d; natural size must be >= min size",
|
2010-10-26 14:53:46 +00:00
|
|
|
G_OBJECT_TYPE_NAME (widget), widget, min_size, nat_size);
|
2010-09-06 01:46:22 +00:00
|
|
|
}
|
|
|
|
|
2010-09-07 22:25:47 +00:00
|
|
|
/* Support for dangling "size-request" signal implementations on
|
|
|
|
* legacy widgets
|
2010-04-17 05:51:10 +00:00
|
|
|
*/
|
|
|
|
min_size = MAX (min_size, requisition_size);
|
|
|
|
nat_size = MAX (nat_size, requisition_size);
|
|
|
|
|
|
|
|
cached_size->minimum_size = min_size;
|
|
|
|
cached_size->natural_size = nat_size;
|
|
|
|
cached_size->for_size = for_size;
|
|
|
|
|
|
|
|
if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
|
2010-09-18 23:57:32 +00:00
|
|
|
_gtk_widget_set_width_request_needed (widget, FALSE);
|
2010-04-17 05:51:10 +00:00
|
|
|
else
|
2010-09-18 23:57:32 +00:00
|
|
|
_gtk_widget_set_height_request_needed (widget, FALSE);
|
2010-04-17 05:51:10 +00:00
|
|
|
|
2010-09-05 16:19:14 +00:00
|
|
|
adjusted_min = cached_size->minimum_size;
|
|
|
|
adjusted_natural = cached_size->natural_size;
|
2010-10-26 14:53:46 +00:00
|
|
|
GTK_WIDGET_GET_CLASS (widget)->adjust_size_request (widget,
|
|
|
|
orientation == GTK_SIZE_GROUP_HORIZONTAL ?
|
|
|
|
GTK_ORIENTATION_HORIZONTAL :
|
|
|
|
GTK_ORIENTATION_VERTICAL,
|
|
|
|
&adjusted_min,
|
|
|
|
&adjusted_natural);
|
2010-09-05 16:19:14 +00:00
|
|
|
|
|
|
|
if (adjusted_min < cached_size->minimum_size ||
|
|
|
|
adjusted_natural < cached_size->natural_size)
|
|
|
|
{
|
|
|
|
g_warning ("%s %p adjusted size %s min %d natural %d must not decrease below min %d natural %d",
|
2010-10-26 14:53:46 +00:00
|
|
|
G_OBJECT_TYPE_NAME (widget), widget,
|
2010-09-05 16:19:14 +00:00
|
|
|
orientation == GTK_SIZE_GROUP_VERTICAL ? "vertical" : "horizontal",
|
|
|
|
adjusted_min, adjusted_natural,
|
|
|
|
cached_size->minimum_size, cached_size->natural_size);
|
|
|
|
/* don't use the adjustment */
|
|
|
|
}
|
|
|
|
else if (adjusted_min > adjusted_natural)
|
|
|
|
{
|
|
|
|
g_warning ("%s %p adjusted size %s min %d natural %d original min %d natural %d has min greater than natural",
|
2010-10-26 14:53:46 +00:00
|
|
|
G_OBJECT_TYPE_NAME (widget), widget,
|
2010-09-05 16:19:14 +00:00
|
|
|
orientation == GTK_SIZE_GROUP_VERTICAL ? "vertical" : "horizontal",
|
|
|
|
adjusted_min, adjusted_natural,
|
|
|
|
cached_size->minimum_size, cached_size->natural_size);
|
|
|
|
/* don't use the adjustment */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* adjustment looks good */
|
|
|
|
cached_size->minimum_size = adjusted_min;
|
|
|
|
cached_size->natural_size = adjusted_natural;
|
|
|
|
}
|
|
|
|
|
2010-09-14 05:52:59 +00:00
|
|
|
/* Update size-groups with our request and update our cached requests
|
|
|
|
* with the size-group values in a single pass.
|
2010-04-17 05:51:10 +00:00
|
|
|
*/
|
2010-10-26 14:53:46 +00:00
|
|
|
_gtk_size_group_bump_requisition (widget,
|
|
|
|
orientation,
|
2010-09-14 05:52:59 +00:00
|
|
|
&cached_size->minimum_size,
|
|
|
|
&cached_size->natural_size);
|
2010-04-17 05:51:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (minimum_size)
|
|
|
|
*minimum_size = cached_size->minimum_size;
|
2010-04-28 14:04:21 +00:00
|
|
|
|
2010-04-17 05:51:10 +00:00
|
|
|
if (natural_size)
|
|
|
|
*natural_size = cached_size->natural_size;
|
|
|
|
|
|
|
|
g_assert (cached_size->minimum_size <= cached_size->natural_size);
|
|
|
|
|
2010-06-18 04:11:26 +00:00
|
|
|
GTK_NOTE (SIZE_REQUEST,
|
2010-04-24 01:52:55 +00:00
|
|
|
g_print ("[%p] %s\t%s: %d is minimum %d and natural: %d (hit cache: %s)\n",
|
2010-10-26 14:53:46 +00:00
|
|
|
widget, G_OBJECT_TYPE_NAME (widget),
|
2010-04-24 01:52:55 +00:00
|
|
|
orientation == GTK_SIZE_GROUP_HORIZONTAL ?
|
|
|
|
"width for height" : "height for width" ,
|
|
|
|
for_size,
|
|
|
|
cached_size->minimum_size,
|
|
|
|
cached_size->natural_size,
|
|
|
|
found_in_cache ? "yes" : "no"));
|
2010-04-17 05:51:10 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-04-11 02:32:55 +00:00
|
|
|
/**
|
2010-09-27 06:11:27 +00:00
|
|
|
* gtk_widget_get_request_mode:
|
2010-09-21 14:35:17 +00:00
|
|
|
* @widget: a #GtkWidget instance
|
2010-04-11 02:32:55 +00:00
|
|
|
*
|
|
|
|
* Gets whether the widget prefers a height-for-width layout
|
2010-04-24 01:52:55 +00:00
|
|
|
* or a width-for-height layout.
|
|
|
|
*
|
|
|
|
* <note><para>#GtkBin widgets generally propagate the preference of
|
|
|
|
* their child, container widgets need to request something either in
|
|
|
|
* context of their children or in context of their allocation
|
|
|
|
* capabilities.</para></note>
|
2010-04-11 02:32:55 +00:00
|
|
|
*
|
2010-08-05 16:45:48 +00:00
|
|
|
* Returns: The #GtkSizeRequestMode preferred by @widget.
|
2010-04-11 02:32:55 +00:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
2010-06-18 04:11:26 +00:00
|
|
|
GtkSizeRequestMode
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_request_mode (GtkWidget *widget)
|
2010-04-11 02:32:55 +00:00
|
|
|
{
|
2010-09-21 14:35:17 +00:00
|
|
|
GtkWidgetClass *klass;
|
2010-04-11 02:32:55 +00:00
|
|
|
|
2010-09-21 14:35:17 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (widget), GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH);
|
2010-04-11 02:32:55 +00:00
|
|
|
|
2010-09-21 14:35:17 +00:00
|
|
|
klass = GTK_WIDGET_GET_CLASS (widget);
|
|
|
|
if (klass->get_request_mode)
|
|
|
|
return klass->get_request_mode (widget);
|
2010-04-11 02:32:55 +00:00
|
|
|
|
|
|
|
/* By default widgets are height-for-width. */
|
2010-06-18 04:11:26 +00:00
|
|
|
return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
|
2010-04-11 02:32:55 +00:00
|
|
|
}
|
|
|
|
|
2010-04-13 02:21:46 +00:00
|
|
|
/**
|
2010-09-21 14:35:17 +00:00
|
|
|
* gtk_widget_get_preferred_width:
|
|
|
|
* @widget: a #GtkWidget instance
|
2010-05-12 22:53:43 +00:00
|
|
|
* @minimum_width: (out) (allow-none): location to store the minimum width, or %NULL
|
|
|
|
* @natural_width: (out) (allow-none): location to store the natural width, or %NULL
|
2010-04-13 02:21:46 +00:00
|
|
|
*
|
2010-04-24 01:52:55 +00:00
|
|
|
* Retrieves a widget's initial minimum and natural width.
|
2010-04-21 05:32:55 +00:00
|
|
|
*
|
2010-04-24 01:52:55 +00:00
|
|
|
* <note><para>This call is specific to height-for-width
|
|
|
|
* requests.</para></note>
|
2010-04-13 02:21:46 +00:00
|
|
|
*
|
2010-09-15 22:37:20 +00:00
|
|
|
* The returned request will be modified by the
|
|
|
|
* GtkWidgetClass::adjust_size_request virtual method and by any
|
|
|
|
* #GtkSizeGroup that have been applied. That is, the returned request
|
|
|
|
* is the one that should be used for layout, not necessarily the one
|
|
|
|
* returned by the widget itself.
|
|
|
|
*
|
2010-04-13 02:21:46 +00:00
|
|
|
* Since: 3.0
|
|
|
|
*/
|
|
|
|
void
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *minimum_width,
|
|
|
|
gint *natural_width)
|
2010-04-13 02:21:46 +00:00
|
|
|
{
|
2010-06-18 04:11:26 +00:00
|
|
|
compute_size_for_orientation (widget, GTK_SIZE_GROUP_HORIZONTAL,
|
2010-04-24 01:52:55 +00:00
|
|
|
-1, minimum_width, natural_width);
|
2010-04-13 02:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-09-21 14:35:17 +00:00
|
|
|
* gtk_widget_get_preferred_height:
|
|
|
|
* @widget: a #GtkWidget instance
|
2010-05-12 22:53:43 +00:00
|
|
|
* @minimum_height: (out) (allow-none): location to store the minimum height, or %NULL
|
|
|
|
* @natural_height: (out) (allow-none): location to store the natural height, or %NULL
|
2010-04-13 02:21:46 +00:00
|
|
|
*
|
2010-04-24 01:52:55 +00:00
|
|
|
* Retrieves a widget's initial minimum and natural height.
|
2010-04-13 02:21:46 +00:00
|
|
|
*
|
2010-05-01 03:21:58 +00:00
|
|
|
* <note><para>This call is specific to width-for-height requests.</para></note>
|
2010-04-21 05:32:55 +00:00
|
|
|
*
|
2010-09-15 22:37:20 +00:00
|
|
|
* The returned request will be modified by the
|
|
|
|
* GtkWidgetClass::adjust_size_request virtual method and by any
|
|
|
|
* #GtkSizeGroup that have been applied. That is, the returned request
|
|
|
|
* is the one that should be used for layout, not necessarily the one
|
|
|
|
* returned by the widget itself.
|
|
|
|
*
|
2010-04-13 02:21:46 +00:00
|
|
|
* Since: 3.0
|
|
|
|
*/
|
|
|
|
void
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_height (GtkWidget *widget,
|
|
|
|
gint *minimum_height,
|
|
|
|
gint *natural_height)
|
2010-04-13 02:21:46 +00:00
|
|
|
{
|
2010-06-18 04:11:26 +00:00
|
|
|
compute_size_for_orientation (widget, GTK_SIZE_GROUP_VERTICAL,
|
2010-04-24 01:52:55 +00:00
|
|
|
-1, minimum_height, natural_height);
|
2010-04-13 02:21:46 +00:00
|
|
|
}
|
|
|
|
|
2010-04-11 02:32:55 +00:00
|
|
|
|
|
|
|
|
2009-12-02 08:48:42 +00:00
|
|
|
/**
|
2010-09-21 14:35:17 +00:00
|
|
|
* gtk_widget_get_preferred_width_for_height:
|
|
|
|
* @widget: a #GtkWidget instance
|
2010-05-01 03:21:58 +00:00
|
|
|
* @height: the height which is available for allocation
|
2010-05-12 22:53:43 +00:00
|
|
|
* @minimum_width: (out) (allow-none): location for storing the minimum width, or %NULL
|
|
|
|
* @natural_width: (out) (allow-none): location for storing the natural width, or %NULL
|
2009-12-02 08:48:42 +00:00
|
|
|
*
|
2010-08-05 16:45:48 +00:00
|
|
|
* Retrieves a widget's minimum and natural width if it would be given
|
2010-04-06 06:47:20 +00:00
|
|
|
* the specified @height.
|
2009-12-02 08:48:42 +00:00
|
|
|
*
|
2010-09-15 22:37:20 +00:00
|
|
|
* The returned request will be modified by the
|
|
|
|
* GtkWidgetClass::adjust_size_request virtual method and by any
|
|
|
|
* #GtkSizeGroup that have been applied. That is, the returned request
|
|
|
|
* is the one that should be used for layout, not necessarily the one
|
|
|
|
* returned by the widget itself.
|
|
|
|
*
|
2010-04-06 06:47:20 +00:00
|
|
|
* Since: 3.0
|
2009-12-02 08:48:42 +00:00
|
|
|
*/
|
|
|
|
void
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_width_for_height (GtkWidget *widget,
|
|
|
|
gint height,
|
|
|
|
gint *minimum_width,
|
|
|
|
gint *natural_width)
|
2009-12-02 08:48:42 +00:00
|
|
|
{
|
2010-06-18 04:11:26 +00:00
|
|
|
compute_size_for_orientation (widget, GTK_SIZE_GROUP_HORIZONTAL,
|
2010-04-24 01:52:55 +00:00
|
|
|
height, minimum_width, natural_width);
|
2009-12-02 08:48:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-09-21 14:35:17 +00:00
|
|
|
* gtk_widget_get_preferred_height_for_width:
|
|
|
|
* @widget: a #GtkWidget instance
|
2010-05-01 03:21:58 +00:00
|
|
|
* @width: the width which is available for allocation
|
2010-05-12 22:53:43 +00:00
|
|
|
* @minimum_height: (out) (allow-none): location for storing the minimum height, or %NULL
|
|
|
|
* @natural_height: (out) (allow-none): location for storing the natural height, or %NULL
|
2009-12-02 08:48:42 +00:00
|
|
|
*
|
2010-08-05 16:45:48 +00:00
|
|
|
* Retrieves a widget's minimum and natural height if it would be given
|
2010-04-06 06:47:20 +00:00
|
|
|
* the specified @width.
|
2009-12-02 08:48:42 +00:00
|
|
|
*
|
2010-09-15 22:37:20 +00:00
|
|
|
* The returned request will be modified by the
|
|
|
|
* GtkWidgetClass::adjust_size_request virtual method and by any
|
|
|
|
* #GtkSizeGroup that have been applied. That is, the returned request
|
|
|
|
* is the one that should be used for layout, not necessarily the one
|
|
|
|
* returned by the widget itself.
|
|
|
|
*
|
2010-04-06 06:47:20 +00:00
|
|
|
* Since: 3.0
|
2009-12-02 08:48:42 +00:00
|
|
|
*/
|
|
|
|
void
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_height_for_width (GtkWidget *widget,
|
|
|
|
gint width,
|
|
|
|
gint *minimum_height,
|
|
|
|
gint *natural_height)
|
2009-12-02 08:48:42 +00:00
|
|
|
{
|
2010-06-18 04:11:26 +00:00
|
|
|
compute_size_for_orientation (widget, GTK_SIZE_GROUP_VERTICAL,
|
2010-04-24 01:52:55 +00:00
|
|
|
width, minimum_height, natural_height);
|
2009-12-02 08:48:42 +00:00
|
|
|
}
|
|
|
|
|
2010-04-13 02:21:46 +00:00
|
|
|
/**
|
2010-09-21 14:35:17 +00:00
|
|
|
* gtk_widget_get_preferred_size:
|
|
|
|
* @widget: a #GtkWidget instance
|
2010-05-12 22:53:43 +00:00
|
|
|
* @minimum_size: (out) (allow-none): location for storing the minimum size, or %NULL
|
|
|
|
* @natural_size: (out) (allow-none): location for storing the natural size, or %NULL
|
2010-04-13 02:21:46 +00:00
|
|
|
*
|
2010-04-24 01:52:55 +00:00
|
|
|
* Retrieves the minimum and natural size of a widget taking
|
2010-04-13 02:21:46 +00:00
|
|
|
* into account the widget's preference for height-for-width management.
|
|
|
|
*
|
2010-04-24 01:52:55 +00:00
|
|
|
* This is used to retrieve a suitable size by container widgets which do
|
2010-10-08 14:10:42 +00:00
|
|
|
* not impose any restrictions on the child placement. It can be used
|
|
|
|
* to deduce toplevel window and menu sizes as well as child widgets in
|
|
|
|
* free form containers such as GtkLayout.
|
|
|
|
*
|
|
|
|
* <note><para>Handle with care, note that the natural height of a height-for-width
|
|
|
|
* widget will generally be a smaller size than the minimum height, since the required
|
|
|
|
* height for the natural width is generally smaller than the required height for
|
|
|
|
* the minimum width.</para></note>
|
2010-04-13 02:21:46 +00:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
|
|
|
void
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_size (GtkWidget *widget,
|
|
|
|
GtkRequisition *minimum_size,
|
|
|
|
GtkRequisition *natural_size)
|
2010-04-13 02:21:46 +00:00
|
|
|
{
|
|
|
|
gint min_width, nat_width;
|
|
|
|
gint min_height, nat_height;
|
|
|
|
|
2010-09-21 14:35:17 +00:00
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
2010-04-13 02:21:46 +00:00
|
|
|
|
2010-09-21 14:35:17 +00:00
|
|
|
if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
|
2010-04-13 02:21:46 +00:00
|
|
|
{
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_width (widget, &min_width, &nat_width);
|
2010-06-18 04:11:26 +00:00
|
|
|
|
|
|
|
if (minimum_size)
|
|
|
|
{
|
|
|
|
minimum_size->width = min_width;
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_height_for_width (widget, min_width,
|
|
|
|
&minimum_size->height, NULL);
|
2010-06-18 04:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (natural_size)
|
|
|
|
{
|
|
|
|
natural_size->width = nat_width;
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_height_for_width (widget, nat_width,
|
|
|
|
NULL, &natural_size->height);
|
2010-06-18 04:11:26 +00:00
|
|
|
}
|
2010-04-13 02:21:46 +00:00
|
|
|
}
|
2010-08-05 16:45:48 +00:00
|
|
|
else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
|
2010-04-13 02:21:46 +00:00
|
|
|
{
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_height (widget, &min_height, &nat_height);
|
2010-06-18 04:11:26 +00:00
|
|
|
|
|
|
|
if (minimum_size)
|
|
|
|
{
|
|
|
|
minimum_size->height = min_height;
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_width_for_height (widget, min_height,
|
|
|
|
&minimum_size->width, NULL);
|
2010-06-18 04:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (natural_size)
|
|
|
|
{
|
|
|
|
natural_size->height = nat_height;
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_width_for_height (widget, nat_height,
|
|
|
|
NULL, &natural_size->width);
|
2010-06-18 04:11:26 +00:00
|
|
|
}
|
2010-04-13 02:21:46 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-05 16:45:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
static gint
|
|
|
|
compare_gap (gconstpointer p1,
|
|
|
|
gconstpointer p2,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkRequestedSize *sizes = data;
|
|
|
|
const guint *c1 = p1;
|
|
|
|
const guint *c2 = p2;
|
|
|
|
|
|
|
|
const gint d1 = MAX (sizes[*c1].natural_size -
|
|
|
|
sizes[*c1].minimum_size,
|
|
|
|
0);
|
|
|
|
const gint d2 = MAX (sizes[*c2].natural_size -
|
|
|
|
sizes[*c2].minimum_size,
|
|
|
|
0);
|
|
|
|
|
|
|
|
gint delta = (d2 - d1);
|
|
|
|
|
|
|
|
if (0 == delta)
|
|
|
|
delta = (*c2 - *c1);
|
|
|
|
|
|
|
|
return delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_distribute_natural_allocation:
|
|
|
|
* @extra_space: Extra space to redistribute among children after subtracting
|
|
|
|
* minimum sizes and any child padding from the overall allocation
|
|
|
|
* @n_requested_sizes: Number of requests to fit into the allocation
|
|
|
|
* @sizes: An array of structs with a client pointer and a minimum/natural size
|
|
|
|
* in the orientation of the allocation.
|
|
|
|
*
|
|
|
|
* Distributes @extra_space to child @sizes by bringing up smaller
|
|
|
|
* children up to natural size first.
|
|
|
|
*
|
|
|
|
* The remaining space will be added to the @minimum_size member of the
|
|
|
|
* GtkRequestedSize struct. If all sizes reach their natural size then
|
|
|
|
* the remaining space is returned.
|
|
|
|
*
|
|
|
|
* Returns: The remainder of @extra_space after redistributing space
|
|
|
|
* to @sizes.
|
|
|
|
*/
|
|
|
|
gint
|
|
|
|
gtk_distribute_natural_allocation (gint extra_space,
|
|
|
|
guint n_requested_sizes,
|
|
|
|
GtkRequestedSize *sizes)
|
|
|
|
{
|
2010-09-22 04:57:35 +00:00
|
|
|
guint *spreading;
|
2010-08-05 16:45:48 +00:00
|
|
|
gint i;
|
|
|
|
|
2010-08-18 23:31:53 +00:00
|
|
|
g_return_val_if_fail (extra_space >= 0, 0);
|
|
|
|
|
2010-09-22 04:57:35 +00:00
|
|
|
spreading = g_newa (guint, n_requested_sizes);
|
|
|
|
|
2010-08-05 16:45:48 +00:00
|
|
|
for (i = 0; i < n_requested_sizes; i++)
|
|
|
|
spreading[i] = i;
|
|
|
|
|
|
|
|
/* Distribute the container's extra space c_gap. We want to assign
|
|
|
|
* this space such that the sum of extra space assigned to children
|
|
|
|
* (c^i_gap) is equal to c_cap. The case that there's not enough
|
|
|
|
* space for all children to take their natural size needs some
|
|
|
|
* attention. The goals we want to achieve are:
|
|
|
|
*
|
|
|
|
* a) Maximize number of children taking their natural size.
|
|
|
|
* b) The allocated size of children should be a continuous
|
|
|
|
* function of c_gap. That is, increasing the container size by
|
|
|
|
* one pixel should never make drastic changes in the distribution.
|
|
|
|
* c) If child i takes its natural size and child j doesn't,
|
|
|
|
* child j should have received at least as much gap as child i.
|
|
|
|
*
|
|
|
|
* The following code distributes the additional space by following
|
|
|
|
* these rules.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Sort descending by gap and position. */
|
|
|
|
g_qsort_with_data (spreading,
|
|
|
|
n_requested_sizes, sizeof (guint),
|
|
|
|
compare_gap, sizes);
|
|
|
|
|
|
|
|
/* Distribute available space.
|
|
|
|
* This master piece of a loop was conceived by Behdad Esfahbod.
|
|
|
|
*/
|
|
|
|
for (i = n_requested_sizes - 1; extra_space > 0 && i >= 0; --i)
|
|
|
|
{
|
|
|
|
/* Divide remaining space by number of remaining children.
|
|
|
|
* Sort order and reducing remaining space by assigned space
|
|
|
|
* ensures that space is distributed equally.
|
|
|
|
*/
|
|
|
|
gint glue = (extra_space + i) / (i + 1);
|
|
|
|
gint gap = sizes[(spreading[i])].natural_size
|
|
|
|
- sizes[(spreading[i])].minimum_size;
|
|
|
|
|
|
|
|
gint extra = MIN (glue, gap);
|
|
|
|
|
|
|
|
sizes[spreading[i]].minimum_size += extra;
|
|
|
|
|
|
|
|
extra_space -= extra;
|
|
|
|
}
|
|
|
|
|
|
|
|
return extra_space;
|
|
|
|
}
|
|
|
|
|