iconview: Move wrap width adjustment to size request code

This commit is contained in:
Benjamin Otte 2012-05-08 01:51:51 +02:00
parent f51c9d4154
commit e8eeb39d98

View File

@ -1360,6 +1360,30 @@ gtk_icon_view_get_n_items (GtkIconView *icon_view)
return gtk_tree_model_iter_n_children (priv->model, NULL);
}
static void
adjust_wrap_width (GtkIconView *icon_view)
{
if (icon_view->priv->text_cell)
{
gint wrap_width = 50;
/* Here we go with the same old guess, try the icon size and set double
* the size of the first icon found in the list, naive but works much
* of the time */
if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
{
gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
GTK_WIDGET (icon_view),
&wrap_width, NULL);
wrap_width = MAX (wrap_width * 2, 50);
}
g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
}
}
static void
cell_area_get_preferred_size (GtkIconView *icon_view,
GtkCellAreaContext *context,
@ -1430,6 +1454,8 @@ gtk_icon_view_get_preferred_item_size (GtkIconView *icon_view,
GtkIconViewItem *item = items->data;
_gtk_icon_view_set_cell_data (icon_view, item);
if (items == priv->items)
adjust_wrap_width (icon_view);
cell_area_get_preferred_size (icon_view, context, orientation, for_size, NULL, NULL);
}
@ -2753,31 +2779,6 @@ gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
}
}
static void
adjust_wrap_width (GtkIconView *icon_view)
{
if (icon_view->priv->text_cell)
{
gint wrap_width = 50;
/* Here we go with the same old guess, try the icon size and set double
* the size of the first icon found in the list, naive but works much
* of the time */
if (icon_view->priv->items && icon_view->priv->pixbuf_cell)
{
_gtk_icon_view_set_cell_data (icon_view, icon_view->priv->items->data);
gtk_cell_renderer_get_preferred_width (icon_view->priv->pixbuf_cell,
GTK_WIDGET (icon_view),
&wrap_width, NULL);
wrap_width = MAX (wrap_width * 2, 50);
}
g_object_set (icon_view->priv->text_cell, "wrap-width", wrap_width, NULL);
g_object_set (icon_view->priv->text_cell, "width", wrap_width, NULL);
}
}
static gint
compare_sizes (gconstpointer p1,
gconstpointer p2,
@ -2801,10 +2802,6 @@ gtk_icon_view_layout (GtkIconView *icon_view)
n_items = gtk_icon_view_get_n_items (icon_view);
/* Update the wrap width for the text cell before going and requesting sizes */
if (n_items)
adjust_wrap_width (icon_view);
gtk_icon_view_compute_n_items_for_size (icon_view,
GTK_ORIENTATION_HORIZONTAL,
gtk_widget_get_allocated_width (widget),