[gtk+/treeview-refactor-staging: 4/10] Changed _gtk_tree_view_column_set_width for _gtk_tree_view_column_allocate



commit 34c9b31aeda8b94036bcc89a63cc2c845b0cbae1
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Wed Dec 1 12:23:02 2010 +0900

    Changed _gtk_tree_view_column_set_width for _gtk_tree_view_column_allocate
    
    Now the GtkTreeViewColumn takes care of move/resizing its window and
    allocating its button (except for the special case of current drag_column
    where the column doesnt actually get reallocated).

 gtk/gtktreeprivate.h    |    8 +++++---
 gtk/gtktreeview.c       |   34 +++++++---------------------------
 gtk/gtktreeviewcolumn.c |   28 ++++++++++++++++++++++++----
 3 files changed, 36 insertions(+), 34 deletions(-)
---
diff --git a/gtk/gtktreeprivate.h b/gtk/gtktreeprivate.h
index 3277680..b033ec3 100644
--- a/gtk/gtktreeprivate.h
+++ b/gtk/gtktreeprivate.h
@@ -103,11 +103,13 @@ gboolean          _gtk_tree_selection_row_is_selectable  (GtkTreeSelection *sele
 
 void _gtk_tree_view_column_realize_button   (GtkTreeViewColumn *column);
 void _gtk_tree_view_column_unrealize_button (GtkTreeViewColumn *column);
+ 
 void _gtk_tree_view_column_set_tree_view    (GtkTreeViewColumn *column,
 					     GtkTreeView       *tree_view);
-void _gtk_tree_view_column_set_width        (GtkTreeViewColumn *column,
-                                             int                width,
-					     int                internal_width);
+void _gtk_tree_view_column_allocate         (GtkTreeViewColumn *tree_column,
+					     int                x_offset,
+					     int                width,
+					     int                cell_width);
 void _gtk_tree_view_column_unset_model      (GtkTreeViewColumn *column,
 					     GtkTreeModel      *old_model);
 void _gtk_tree_view_column_unset_tree_view  (GtkTreeViewColumn *column);
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index bc72795..52afee8 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -2631,7 +2631,6 @@ gtk_tree_view_size_allocate_columns (GtkWidget *widget,
   GtkTreeView *tree_view;
   GList *list, *first_column, *last_column;
   GtkTreeViewColumn *column;
-  GtkAllocation allocation;
   GtkAllocation widget_allocation;
   gint width = 0;
   gint extra, extra_per_column, extra_for_last;
@@ -2657,9 +2656,6 @@ gtk_tree_view_size_allocate_columns (GtkWidget *widget,
        first_column = first_column->next)
     ;
 
-  allocation.y = 0;
-  allocation.height = tree_view->priv->header_height;
-
   rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
 
   /* find out how many extra space and expandable columns we have */
@@ -2719,7 +2715,6 @@ gtk_tree_view_size_allocate_columns (GtkWidget *widget,
     {
       GtkWidget *button;
       GdkWindow *window;
-      gint real_requested_width = 0;
       gint internal_column_width = 0;
       gint old_width, column_width;
 
@@ -2747,9 +2742,7 @@ gtk_tree_view_size_allocate_columns (GtkWidget *widget,
 	  continue;
 	}
 
-      real_requested_width = gtk_tree_view_get_real_requested_width_from_column (tree_view, column);
-
-      allocation.x = width;
+      column_width = gtk_tree_view_get_real_requested_width_from_column (tree_view, column);
 
       if (gtk_tree_view_column_get_expand (column))
 	{
@@ -2757,11 +2750,11 @@ gtk_tree_view_size_allocate_columns (GtkWidget *widget,
 	    {
 	      /* We add the remander to the last column as
 	       * */
-	      real_requested_width += extra;
+	      column_width += extra;
 	    }
 	  else
 	    {
-	      real_requested_width += extra_per_column;
+	      column_width += extra_per_column;
 	      extra -= extra_per_column;
 	      number_of_expand_columns --;
 	    }
@@ -2769,39 +2762,26 @@ gtk_tree_view_size_allocate_columns (GtkWidget *widget,
       else if (number_of_expand_columns == 0 &&
 	       list == last_column)
 	{
-	  real_requested_width += extra;
+	  column_width += extra;
 	}
 
       /* In addition to expand, the last column can get even more
        * extra space so all available space is filled up.
        */
       if (extra_for_last > 0 && list == last_column)
-	real_requested_width += extra_for_last;
+	column_width += extra_for_last;
 
       /* XXX This needs to account the real allocated space for
        * the internal GtkCellArea
        */
-      internal_column_width = real_requested_width /* - all the stuff treeview adds around the area */;
+      internal_column_width = column_width /* - all the stuff treeview adds around the area */;
 
-      _gtk_tree_view_column_set_width (column, real_requested_width, internal_column_width);
+      _gtk_tree_view_column_allocate (column, width, column_width, internal_column_width);
 
-      column_width = gtk_tree_view_column_get_width (column);
-      allocation.width = column_width;
       width += column_width;
 
       if (column_width > old_width)
         column_changed = TRUE;
-
-      button = gtk_tree_view_column_get_button (column);
-      window = _gtk_tree_view_column_get_window (column);
-
-      gtk_widget_size_allocate (button, &allocation);
-
-      if (window)
-	gdk_window_move_resize (window,
-                                allocation.x + (rtl ? 0 : allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
-				allocation.y,
-                                TREE_VIEW_DRAG_WIDTH, allocation.height);
     }
 
   /* We change the width here.  The user might have been resizing columns,
diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c
index 218fac8..cc3df59 100644
--- a/gtk/gtktreeviewcolumn.c
+++ b/gtk/gtktreeviewcolumn.c
@@ -1841,19 +1841,39 @@ gtk_tree_view_column_get_width (GtkTreeViewColumn *tree_column)
 }
 
 void
-_gtk_tree_view_column_set_width (GtkTreeViewColumn *tree_column,
-                                 int                width,
-				 int                internal_width)
+_gtk_tree_view_column_allocate (GtkTreeViewColumn *tree_column,
+				int                x_offset,
+				int                width,
+				int                cell_width)
 {
   GtkTreeViewColumnPrivate *priv;
+  GtkAllocation             allocation;
+  gboolean                  rtl;
 
   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
 
   priv = tree_column->priv;
 
-  gtk_cell_area_context_allocate (priv->cell_area_context, internal_width, -1);
   priv->width = width;
 
+  gtk_cell_area_context_allocate (priv->cell_area_context, cell_width, -1);
+
+  allocation.x      = x_offset;
+  allocation.y      = 0;
+  allocation.width  = width;
+  allocation.height = _gtk_tree_view_get_header_height (GTK_TREE_VIEW (priv->tree_view));
+
+  gtk_widget_size_allocate (priv->button, &allocation);
+
+  if (priv->window)
+    {
+      rtl = (gtk_widget_get_direction (priv->tree_view) == GTK_TEXT_DIR_RTL);
+      gdk_window_move_resize (priv->window,
+			      allocation.x + (rtl ? 0 : allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
+			      allocation.y,
+			      TREE_VIEW_DRAG_WIDTH, allocation.height);
+    }
+
   g_object_notify (G_OBJECT (tree_column), "width");
 }
 



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