[gtk+/icon-view-refactor: 11/11] Restored the old GtkIconView guess for wrap-width/width size of text cell



commit 8e930572eb5f1151ea624b02bda9c266e0dcc402
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Tue Dec 14 15:37:42 2010 +0900

    Restored the old GtkIconView guess for wrap-width/width size of text cell
    
    GtkIconView sets the minimum width of the text cell to be at least 50
    pixels and otherwise twice the width of the first pixbuf cell found
    in the icon list.

 gtk/gtkiconview.c |   35 +++++++++++++++++++++++++++++++----
 1 files changed, 31 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c
index 6302869..922bd3e 100644
--- a/gtk/gtkiconview.c
+++ b/gtk/gtkiconview.c
@@ -1162,6 +1162,8 @@ gtk_icon_view_dispose (GObject *object)
 
   if (priv->cell_area)
     {
+      gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
+
       g_signal_handler_disconnect (priv->cell_area, priv->add_editable_id);
       g_signal_handler_disconnect (priv->cell_area, priv->remove_editable_id);
       priv->add_editable_id = 0;
@@ -1352,8 +1354,6 @@ gtk_icon_view_destroy (GtkWidget *widget)
 {
   GtkIconView *icon_view = GTK_ICON_VIEW (widget);
 
-  gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
-
   gtk_icon_view_set_model (icon_view, NULL);
 
   if (icon_view->priv->layout_idle_id != 0)
@@ -2770,6 +2770,31 @@ gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
 }
 
 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 void
 gtk_icon_view_layout (GtkIconView *icon_view)
 {
   GtkAllocation allocation;
@@ -2793,8 +2818,10 @@ gtk_icon_view_layout (GtkIconView *icon_view)
 
   item_width = icon_view->priv->item_width;
 
-  /* Update the context widths for any invalidated
-   * items */
+  /* Update the wrap width for the text cell before going and requesting sizes */
+  adjust_wrap_width (icon_view);
+
+  /* Update the context widths for any invalidated items */
   gtk_icon_view_cache_widths (icon_view);
 
   /* Fetch the new item width if needed */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]