[gtk+/treeview-refactor] Make GtkTreeView tell the column about expand space instead of just assigning column->width.



commit b39521dcf79f4a5e69c709bdbf0a3de5f4fb6428
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Mon Nov 29 18:04:47 2010 +0900

    Make GtkTreeView tell the column about expand space instead of just assigning column->width.
    
    Also modified the api to open up the way for treeview to tell the column
    about how much of its size is really used to render the area.

 gtk/gtktreeprivate.h    |    3 ++-
 gtk/gtktreeview.c       |   17 +++++++++++------
 gtk/gtktreeviewcolumn.c |    7 +++++--
 3 files changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtktreeprivate.h b/gtk/gtktreeprivate.h
index 43fb638..8e11e18 100644
--- a/gtk/gtktreeprivate.h
+++ b/gtk/gtktreeprivate.h
@@ -419,7 +419,8 @@ 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                width,
+					     int                internal_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 5c4c073..84948aa 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -2360,6 +2360,7 @@ gtk_tree_view_size_allocate_columns (GtkWidget *widget,
        list = (rtl ? list->prev : list->next)) 
     {
       gint real_requested_width = 0;
+      gint internal_column_width = 0;
       gint old_width, column_width;
 
       column = list->data;
@@ -2387,7 +2388,6 @@ gtk_tree_view_size_allocate_columns (GtkWidget *widget,
       real_requested_width = gtk_tree_view_get_real_requested_width_from_column (tree_view, column);
 
       allocation.x = width;
-      _gtk_tree_view_column_set_width (column, real_requested_width);
 
       if (gtk_tree_view_column_get_expand (column))
 	{
@@ -2395,11 +2395,11 @@ gtk_tree_view_size_allocate_columns (GtkWidget *widget,
 	    {
 	      /* We add the remander to the last column as
 	       * */
-	      column->width += extra;
+	      real_requested_width += extra;
 	    }
 	  else
 	    {
-	      column->width += extra_per_column;
+	      real_requested_width += extra_per_column;
 	      extra -= extra_per_column;
 	      number_of_expand_columns --;
 	    }
@@ -2407,16 +2407,21 @@ gtk_tree_view_size_allocate_columns (GtkWidget *widget,
       else if (number_of_expand_columns == 0 &&
 	       list == last_column)
 	{
-	  column->width += extra;
+	  real_requested_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)
-	column->width += extra_for_last;
+	real_requested_width += extra_for_last;
 
-      g_object_notify (G_OBJECT (column), "width");
+      /* 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 */;
+
+      _gtk_tree_view_column_set_width (column, real_requested_width, internal_column_width);
 
       column_width = gtk_tree_view_column_get_width (column);
       allocation.width = column_width;
diff --git a/gtk/gtktreeviewcolumn.c b/gtk/gtktreeviewcolumn.c
index ae37547..363082c 100644
--- a/gtk/gtktreeviewcolumn.c
+++ b/gtk/gtktreeviewcolumn.c
@@ -1729,12 +1729,15 @@ gtk_tree_view_column_get_width (GtkTreeViewColumn *tree_column)
 
 void
 _gtk_tree_view_column_set_width (GtkTreeViewColumn *tree_column,
-                                 int                width)
+                                 int                width,
+				 int                internal_width)
 {
   g_return_if_fail (GTK_IS_TREE_VIEW_COLUMN (tree_column));
 
-  gtk_cell_area_context_allocate (tree_column->cell_area_context, width, -1);
+  gtk_cell_area_context_allocate (tree_column->cell_area_context, internal_width, -1);
   tree_column->width = width;
+
+  g_object_notify (G_OBJECT (tree_column), "width");
 }
 
 /**



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