[gtk+] Added minimum size parameter to GtkWidgetClass->adjust_size_allocation.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Added minimum size parameter to GtkWidgetClass->adjust_size_allocation.
- Date: Tue, 7 Dec 2010 14:43:59 +0000 (UTC)
commit fc5cabba90393246886c8122851646ec979b19fa
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Tue Dec 7 23:45:48 2010 +0900
Added minimum size parameter to GtkWidgetClass->adjust_size_allocation.
This allows us to add a check before executing
->get_preferred_height_for_width() to ensure we always
request for at least the minimum required size (and lets
us remove the warning in gtkcontainer.c telling implementors
to do this check manually from thier container implementations).
gtk/gtkcontainer.c | 33 +++++----------------------------
gtk/gtksizerequest.c | 24 +++++++++++++++---------
gtk/gtkwidget.c | 18 +++++++++++++-----
gtk/gtkwidget.h | 1 +
4 files changed, 34 insertions(+), 42 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 5433766..a512037 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -144,32 +144,6 @@
* }
* ]]></programlisting>
*
- * Furthermore, in order to ensure correct height-for-width requests it is important
- * to check the input width against the real required minimum width. This can
- * easily be achieved as follows:
- *
- * <programlisting><![CDATA[
- * static void
- * foo_container_get_preferred_height_for_width (GtkWidget *widget, gint for_width,
- * gint *min_height, gint *nat_height)
- * {
- * if (i_am_in_height_for_width_mode)
- * {
- * gint min_width;
- *
- * GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_width, NULL);
- *
- * for_width = MAX (min_width, for_width);
- *
- * execute_real_height_for_width_request_code (widget, for_width, min_height, nat_height);
- * }
- * else
- * {
- * ... fall back on virtual results as mentioned in the previous example ...
- * }
- * }
- * ]]></programlisting>
- *
* Height for width requests are generally implemented in terms of a virtual allocation
* of widgets in the input orientation. Assuming an height-for-width request mode, a container
* would implement the <function>get_preferred_height_for_width()</function> virtual function by first calling
@@ -327,6 +301,7 @@ static void gtk_container_adjust_size_request (GtkWidget *widget,
gint *natural_size);
static void gtk_container_adjust_size_allocation (GtkWidget *widget,
GtkOrientation orientation,
+ gint *minimum_size,
gint *natural_size,
gint *allocated_pos,
gint *allocated_size);
@@ -1809,6 +1784,7 @@ gtk_container_adjust_size_request (GtkWidget *widget,
static void
gtk_container_adjust_size_allocation (GtkWidget *widget,
GtkOrientation orientation,
+ gint *minimum_size,
gint *natural_size,
gint *allocated_pos,
gint *allocated_size)
@@ -1821,7 +1797,7 @@ gtk_container_adjust_size_allocation (GtkWidget *widget,
if (!GTK_CONTAINER_GET_CLASS (widget)->handle_border_width)
{
parent_class->adjust_size_allocation (widget, orientation,
- natural_size, allocated_pos,
+ minimum_size, natural_size, allocated_pos,
allocated_size);
return;
}
@@ -1845,6 +1821,7 @@ gtk_container_adjust_size_allocation (GtkWidget *widget,
else
{
*allocated_pos += border_width;
+ *minimum_size -= border_width * 2;
*natural_size -= border_width * 2;
}
@@ -1856,7 +1833,7 @@ gtk_container_adjust_size_allocation (GtkWidget *widget,
* and padding values.
*/
parent_class->adjust_size_allocation (widget, orientation,
- natural_size, allocated_pos,
+ minimum_size, natural_size, allocated_pos,
allocated_size);
}
diff --git a/gtk/gtksizerequest.c b/gtk/gtksizerequest.c
index ab24948..c5e49e7 100644
--- a/gtk/gtksizerequest.c
+++ b/gtk/gtksizerequest.c
@@ -217,23 +217,26 @@ compute_size_for_orientation (GtkWidget *widget,
}
else
{
- int ignored_position = 0;
- int natural_height;
+ gint ignored_position = 0;
+ gint minimum_height;
+ gint 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);
+ gtk_widget_get_preferred_height (widget, &minimum_height, &natural_height);
/* convert for_size to unadjusted height (for_size is a proposed allocation) */
GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
GTK_ORIENTATION_VERTICAL,
- &natural_height,
+ &minimum_height,
+ &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,
- &min_size, &nat_size);
+ GTK_WIDGET_GET_CLASS (widget)->get_preferred_width_for_height (widget,
+ MAX (for_size, minimum_height),
+ &min_size, &nat_size);
pop_recursion_check (widget, orientation);
}
}
@@ -248,22 +251,25 @@ compute_size_for_orientation (GtkWidget *widget,
else
{
int ignored_position = 0;
+ int minimum_width;
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);
+ gtk_widget_get_preferred_width (widget, &minimum_width, &natural_width);
/* convert for_size to unadjusted width (for_size is a proposed allocation) */
GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
GTK_ORIENTATION_HORIZONTAL,
+ &minimum_width,
&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,
- &min_size, &nat_size);
+ GTK_WIDGET_GET_CLASS (widget)->get_preferred_height_for_width (widget,
+ MAX (for_size, minimum_width),
+ &min_size, &nat_size);
pop_recursion_check (widget, orientation);
}
}
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index c82b6ea..c685b26 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -641,6 +641,7 @@ static void gtk_widget_real_adjust_size_request (GtkWidget
gint *natural_size);
static void gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
GtkOrientation orientation,
+ gint *minimum_size,
gint *natural_size,
gint *allocated_pos,
gint *allocated_size);
@@ -4636,7 +4637,7 @@ gtk_widget_size_allocate (GtkWidget *widget,
gboolean alloc_needed;
gboolean size_changed;
gboolean position_changed;
- gint natural_width, natural_height;
+ gint natural_width, natural_height, dummy;
gint min_width, min_height;
priv = widget->priv;
@@ -4681,7 +4682,7 @@ gtk_widget_size_allocate (GtkWidget *widget,
* when aligning implicitly.
*/
gtk_widget_get_preferred_width (widget, &min_width, &natural_width);
- gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, NULL, &natural_height);
+ gtk_widget_get_preferred_height_for_width (widget, real_allocation.width, &dummy, &natural_height);
}
else
{
@@ -4690,18 +4691,20 @@ gtk_widget_size_allocate (GtkWidget *widget,
* when aligning implicitly.
*/
gtk_widget_get_preferred_height (widget, &min_height, &natural_height);
- gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, NULL, &natural_width);
+ gtk_widget_get_preferred_width_for_height (widget, real_allocation.height, &dummy, &natural_width);
}
/* Now that we have the right natural height and width, go ahead and remove any margins from the
* allocated sizes and possibly limit them to the natural sizes */
GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
GTK_ORIENTATION_HORIZONTAL,
+ &dummy,
&natural_width,
&adjusted_allocation.x,
&adjusted_allocation.width);
GTK_WIDGET_GET_CLASS (widget)->adjust_size_allocation (widget,
GTK_ORIENTATION_VERTICAL,
+ &dummy,
&natural_height,
&adjusted_allocation.y,
&adjusted_allocation.height);
@@ -5026,10 +5029,12 @@ adjust_for_align(GtkAlign align,
static void
adjust_for_margin(gint start_margin,
gint end_margin,
+ gint *minimum_size,
gint *natural_size,
gint *allocated_pos,
gint *allocated_size)
{
+ *minimum_size -= (start_margin + end_margin);
*natural_size -= (start_margin + end_margin);
*allocated_pos += start_margin;
*allocated_size -= (start_margin + end_margin);
@@ -5038,6 +5043,7 @@ adjust_for_margin(gint start_margin,
static void
gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
GtkOrientation orientation,
+ gint *minimum_size,
gint *natural_size,
gint *allocated_pos,
gint *allocated_size)
@@ -5050,7 +5056,8 @@ gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
{
adjust_for_margin (aux_info->margin.left,
aux_info->margin.right,
- natural_size, allocated_pos, allocated_size);
+ minimum_size, natural_size,
+ allocated_pos, allocated_size);
adjust_for_align (aux_info->halign,
natural_size, allocated_pos, allocated_size);
}
@@ -5058,7 +5065,8 @@ gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
{
adjust_for_margin (aux_info->margin.top,
aux_info->margin.bottom,
- natural_size, allocated_pos, allocated_size);
+ minimum_size, natural_size,
+ allocated_pos, allocated_size);
adjust_for_align (aux_info->valign,
natural_size, allocated_pos, allocated_size);
}
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 04f7772..2a079ea 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -415,6 +415,7 @@ struct _GtkWidgetClass
gint *natural_size);
void (* adjust_size_allocation) (GtkWidget *widget,
GtkOrientation orientation,
+ gint *minimum_size,
gint *natural_size,
gint *allocated_pos,
gint *allocated_size);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]