[gtk+] Kill gtk_tree_view_size_request



commit d0e0e489423e424075e7db400a079f533c656c4d
Author: John Lindgren <john lindgren aol com>
Date:   Tue Dec 18 00:47:07 2012 -0500

    Kill gtk_tree_view_size_request
    
    Splits up size_request() so that the height calculations are only done
    when get_preferred_height() is called and the width calculations are
    only done when get_preferred_width() is called.  Since
    get_preferred_width() does not change the treeview->priv->width value,
    treeview->priv->prev_width will always be equal to it and can therefore
    be removed.  The only place where prev_width was used is a block in
    gtk_tree_view_size_allocate().  This block seems to be adjusting the
    horizontal scrollbar to account for treeview->priv->width having been
    changed in size_request() and should no longer be necessary.  A similar
    block immediately above it seems to already account for the width change
    in size_allocate().
    
    https://bugzilla.gnome.org/show_bug.cgi?id=691751

 gtk/gtktreeview.c |   94 ++++++++++++++---------------------------------------
 1 files changed, 25 insertions(+), 69 deletions(-)
---
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index 688a558..5f6cfea 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -386,8 +386,6 @@ struct _GtkTreeViewPrivate
   gint x_drag;
 
   /* Non-interactive Header Resizing, expand flag support */
-  gint prev_width;
-
   gint last_extra_space;
   gint last_extra_space_per_column;
   gint last_number_of_expand_columns;
@@ -585,9 +583,6 @@ static void     gtk_tree_view_get_preferred_width  (GtkWidget        *widget,
 static void     gtk_tree_view_get_preferred_height (GtkWidget        *widget,
 						    gint             *minimum,
 						    gint             *natural);
-static void     gtk_tree_view_size_request         (GtkWidget        *widget,
-						    GtkRequisition   *requisition,
-                                                    gboolean          may_validate);
 static void     gtk_tree_view_size_allocate        (GtkWidget        *widget,
 						    GtkAllocation    *allocation);
 static gboolean gtk_tree_view_draw                 (GtkWidget        *widget,
@@ -2368,9 +2363,9 @@ gtk_tree_view_unrealize (GtkWidget *widget)
   GTK_WIDGET_CLASS (gtk_tree_view_parent_class)->unrealize (widget);
 }
 
-/* GtkWidget::size_request helper */
+/* GtkWidget::get_preferred_height helper */
 static void
-gtk_tree_view_size_request_columns (GtkTreeView *tree_view)
+gtk_tree_view_update_height (GtkTreeView *tree_view)
 {
   GList *list;
 
@@ -2388,76 +2383,39 @@ gtk_tree_view_size_request_columns (GtkTreeView *tree_view)
       gtk_widget_get_preferred_size (button, &requisition, NULL);
       tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
     }
-}
 
+  if (tree_view->priv->tree == NULL)
+    tree_view->priv->height = 0;
+  else
+    tree_view->priv->height = tree_view->priv->tree->root->offset;
+}
 
-/* Called only by ::size_request */
 static void
-gtk_tree_view_update_size (GtkTreeView *tree_view)
+gtk_tree_view_get_preferred_width (GtkWidget *widget,
+				   gint      *minimum,
+				   gint      *natural)
 {
+  GtkTreeView *tree_view = GTK_TREE_VIEW (widget);
   GList *list;
   GtkTreeViewColumn *column;
-  gint i;
-
-  if (tree_view->priv->model == NULL)
-    {
-      tree_view->priv->width = 0;
-      tree_view->priv->prev_width = 0;                   
-      tree_view->priv->height = 0;
-      return;
-    }
+  gint width = 0;
 
-  tree_view->priv->prev_width = tree_view->priv->width;  
-  tree_view->priv->width = 0;
+  /* we validate some rows initially just to make sure we have some size.
+   * In practice, with a lot of static lists, this should get a good width.
+   */
+  do_validate_rows (tree_view, FALSE);
 
   /* keep this in sync with size_allocate below */
-  for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
+  for (list = tree_view->priv->columns; list; list = list->next)
     {
       column = list->data;
       if (!gtk_tree_view_column_get_visible (column))
 	continue;
 
-      tree_view->priv->width += _gtk_tree_view_column_request_width (column);
-    }
-
-  if (tree_view->priv->tree == NULL)
-    tree_view->priv->height = 0;
-  else
-    tree_view->priv->height = tree_view->priv->tree->root->offset;
-}
-
-static void
-gtk_tree_view_size_request (GtkWidget      *widget,
-			    GtkRequisition *requisition,
-                            gboolean        may_validate)
-{
-  GtkTreeView *tree_view = GTK_TREE_VIEW (widget);
-
-  if (may_validate)
-    {
-      /* we validate some rows initially just to make sure we have some size.
-       * In practice, with a lot of static lists, this should get a good width.
-       */
-      do_validate_rows (tree_view, FALSE);
+      width += _gtk_tree_view_column_request_width (column);
     }
 
-  gtk_tree_view_size_request_columns (tree_view);
-  gtk_tree_view_update_size (GTK_TREE_VIEW (widget));
-
-  requisition->width = tree_view->priv->width;
-  requisition->height = tree_view->priv->height + gtk_tree_view_get_effective_header_height (tree_view);
-}
-
-static void
-gtk_tree_view_get_preferred_width (GtkWidget *widget,
-				   gint      *minimum,
-				   gint      *natural)
-{
-  GtkRequisition requisition;
-
-  gtk_tree_view_size_request (widget, &requisition, TRUE);
-
-  *minimum = *natural = requisition.width;
+  *minimum = *natural = width;
 }
 
 static void
@@ -2465,11 +2423,14 @@ gtk_tree_view_get_preferred_height (GtkWidget *widget,
 				    gint      *minimum,
 				    gint      *natural)
 {
-  GtkRequisition requisition;
+  GtkTreeView *tree_view = GTK_TREE_VIEW (widget);
+  gint height;
+
+  gtk_tree_view_update_height (tree_view);
 
-  gtk_tree_view_size_request (widget, &requisition, TRUE);
+  height = tree_view->priv->height + gtk_tree_view_get_effective_header_height (tree_view);
 
-  *minimum = *natural = requisition.height;
+  *minimum = *natural = height;
 }
 
 static int
@@ -2723,11 +2684,6 @@ gtk_tree_view_size_allocate (GtkWidget     *widget,
                                                0,
                                                tree_view->priv->width - allocation->width));
 	    }
-	  else
-            gtk_adjustment_set_value (tree_view->priv->hadjustment,
-                                      CLAMP (tree_view->priv->width - (tree_view->priv->prev_width - gtk_adjustment_get_value (tree_view->priv->hadjustment)),
-                                             0,
-                                             tree_view->priv->width - allocation->width));
 	}
       else
         {



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