Hi all,
There are several problems with the current support for resizable
columns in GtkTreeView, which I have written some patches to fix:
* There is no way to set distinct minimum and natural widths for a
GtkTreeViewColumn. I propose that the "fixed-width" property be
interpreted as the natural width of the column rather than the minimum
width (we already have the "min-width" property for that).
* Column resizing is implemented using a hidden "resized-width" property
that is not visible to applications. Hence, user changes to column size
are lost every time the application is closed. I propose to get rid of
the "resized-width" property and instead modify the "fixed-width" and
"expand" properties to get the desired column size. Applications can
then preserve user-set column sizes by saving and restoring these two
properties.
* The code that currently handles the "resized-width" property is
convoluted and causes unexpected results when the size of the entire
treeview is changed (see [1]). After my patches, the code is simpler
and behaves as expected (see [2]).
Please look over the attached patches and comment.
John Lindgren
[1] screencast before (ogv): https://www.box.com/s/gz23ksylzjp046dn8ah5
[2] screencast after (ogv): https://www.box.com/s/c6zhov1igiqss7x97k5r
>From 9c8ee6c3a1977a9341455e6e5c18aff9d99e1e46 Mon Sep 17 00:00:00 2001
From: John Lindgren
Date: Tue, 18 Dec 2012 00:23:27 -0500
Subject: [PATCH 1/6] Remove extraneous size request
---
gtk/gtktreeview.c | 25 +
1 file changed, 1 insertion(+), 24 deletions(-)
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index b1528da..1e64582 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -715,7 +715,7 @@ static gboolean validate_row (GtkTreeView *tree_view,
static void validate_visible_area(GtkTreeView *tree_view);
static gboolean validate_rows_handler(GtkTreeView *tree_view);
static gboolean do_validate_rows (GtkTreeView *tree_view,
- gboolean size_request);
+ gboolean queue_resize);
static gboolean validate_rows(GtkTreeView *tree_view);
static gboolean presize_handler_callback (gpointer data);
static void install_presize_handler (GtkTreeView *tree_view);
@@ -6701,35 +6701,12 @@ do_validate_rows (GtkTreeView *tree_view, gboolean queue_resize)
done:
if (validated_area)
{
- GtkRequisition requisition;
-
- /* We temporarily guess a size, under the assumption that it will be the
- * same when we get our next size_allocate. If we don't do this, we'll be
- * in an inconsistent state when we call top_row_to_dy. */
-
- /* FIXME: This is called from size_request, for some reason it is not infinitely
- * recursing, we cannot call gtk_widget_get_preferred_size() here because that's
- * not allowed (from inside ->get_preferred_width/height() implementations, one
- * should call the vfuncs directly). However what is desired here is the full
- * size including any margins and limited by any alignment (i.e. after
- * GtkWidget:adjust_size_request() is called).
- *
- * Currently bypassing this but the real solution is to not update the scroll adjustments
- * untill we've recieved an allocation (never update scroll adjustments from size-requests).
- */
- gtk_tree_view_size_request (GTK_WIDGET (tree_view), &requisition, FALSE);
-
/* If rows above the current position have changed height, this has
* affected the current view and thus needs a redraw.
*/
if (y != -1 && y < gtk_adjustment_get_value (tree_view->priv->vadjustment))
gtk_widget_queue_draw (GTK_WIDGET (tree_view));
- gtk_adjustment_set_upper (tree_view->priv->hadjustment,
-MAX (gtk_adjustment_get_upper (tree_view->priv->hadjustment), requisition.width));
- gtk_adjustment_set_upper (tree_view->priv->vadjustment,
-MAX (gtk_adjustment_get_upper (tree_view->priv->vadjustment), requisition.height));
-
if (queue_resize)
gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
}
--
1.8.0.2
>From ad8dc277807d359536026ad27cee8b83512fb1b3 Mon Sep 17 00:00:00 2001
From: John Lindgren
Date: Tue, 18 Dec 2012 00:47:07 -0500
Subject: [PATCH 2/6] Kill gtk_tree_view_size_request
---
gtk/gtktreeview.c | 94 +++
1 file changed, 25 insertions(+), 69 deletions(-)
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index 1e64582..f4776bf 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -385,8 +385,6 @@ struct _GtkTreeViewPrivate
gint x_drag;
/* Non-interactive Header Resizing, expand flag support */
- gint pre