iconview: gtk_icon_view_compute_n_items_for_size bugfix

While working on the "iconview: Don't shrink items" patch I noticed that
gtk_icon_view_compute_n_items_for_size modifies the natural and minimum
item sizes it got from gtk_icon_view_get_preferred_item_size when
calculating the max number of items which will fit, but later on it
checks against these sizes when calculating the item_size, and these
checks expect these values to be unmodified.

This patch fixes this by modifying the natural and minimum values in
advance and doing all computations with modified values.

https://bugzilla.gnome.org/show_bug.cgi?id=677809
This commit is contained in:
Hans de Goede 2012-06-12 17:39:50 +02:00 committed by Benjamin Otte
parent ec755541ab
commit c32a5a80b7

View File

@ -1515,19 +1515,23 @@ gtk_icon_view_compute_n_items_for_size (GtkIconView *icon_view,
gint *max_item_size)
{
GtkIconViewPrivate *priv = icon_view->priv;
int minimum, natural;
int minimum, natural, spacing;
g_return_if_fail (min_item_size == NULL || min_items != NULL);
g_return_if_fail (max_item_size == NULL || max_items != NULL);
gtk_icon_view_get_preferred_item_size (icon_view, orientation, -1, &minimum, &natural);
size -= 2 * priv->margin;
if (orientation == GTK_ORIENTATION_HORIZONTAL)
size += priv->column_spacing;
spacing = priv->column_spacing;
else
size += priv->row_spacing;
spacing = priv->row_spacing;
size -= 2 * priv->margin;
size += spacing;
minimum += spacing;
natural += spacing;
if (priv->columns > 0)
{
if (orientation == GTK_ORIENTATION_HORIZONTAL)
@ -1549,17 +1553,6 @@ gtk_icon_view_compute_n_items_for_size (GtkIconView *icon_view,
}
else
{
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
minimum += priv->column_spacing;
natural += priv->column_spacing;
}
else
{
minimum += priv->row_spacing;
natural += priv->row_spacing;
}
if (max_items)
{
if (size <= minimum)
@ -1580,22 +1573,16 @@ gtk_icon_view_compute_n_items_for_size (GtkIconView *icon_view,
if (min_item_size)
{
*min_item_size = size / *min_items;
if (orientation == GTK_ORIENTATION_HORIZONTAL)
*min_item_size -= priv->column_spacing;
else
*min_item_size -= priv->row_spacing;
*min_item_size = MIN (*min_item_size, natural);
*min_item_size -= spacing;
*min_item_size -= 2 * priv->item_padding;
}
if (max_item_size)
{
*max_item_size = size / *max_items;
if (orientation == GTK_ORIENTATION_HORIZONTAL)
*max_item_size -= priv->column_spacing;
else
*max_item_size -= priv->row_spacing;
*max_item_size = MIN (*max_item_size, natural);
*max_item_size -= spacing;
*max_item_size -= 2 * priv->item_padding;
}
}