* }
* ]]></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
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);
static void
gtk_container_adjust_size_allocation (GtkWidget *widget,
GtkOrientation orientation,
+ gint *minimum_size,
gint *natural_size,
gint *allocated_pos,
gint *allocated_size)
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;
}
else
{
*allocated_pos += border_width;
+ *minimum_size -= border_width * 2;
*natural_size -= border_width * 2;
}
* and padding values.
*/
parent_class->adjust_size_allocation (widget, orientation,
- natural_size, allocated_pos,
+ minimum_size, natural_size, allocated_pos,
allocated_size);
}
}
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);
}
}
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);
}
}
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);
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;
* 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
{
* 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);
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);
static void
gtk_widget_real_adjust_size_allocation (GtkWidget *widget,
GtkOrientation orientation,
+ gint *minimum_size,
gint *natural_size,
gint *allocated_pos,
gint *allocated_size)
{
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);
}
{
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);
}
gint *natural_size);
void (* adjust_size_allocation) (GtkWidget *widget,
GtkOrientation orientation,
+ gint *minimum_size,
gint *natural_size,
gint *allocated_pos,
gint *allocated_size);