[gtk+] Bug 480065 - wrong tree collapsed (or expanded) after having scrolled



commit f223577a88730a03686935e6d319006595480bd2
Author: Kristian Rietveld <kris gtk org>
Date:   Thu Nov 26 21:05:01 2009 +0100

    Bug 480065 -  wrong tree collapsed (or expanded) after having scrolled
    
    Commit again after revert.
    
    Store (x, y) of last motion event.  From
    gtk_tree_view_adjustment_changed(), call prelight_or_select() so that
    the prelight is recalculated.  We do the same from
    gtk_tree_view_size_allocate() for the case that clicking on an expander
    shows new rows that resize the column(s) left of the expander.  This
    means that the expander is moved horizontally, in such a case the
    prelight also has to be reconsidered.

 gtk/gtktreeprivate.h |    3 +++
 gtk/gtktreeview.c    |   41 +++++++++++++++++++++++++++++++++++++++--
 2 files changed, 42 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtktreeprivate.h b/gtk/gtktreeprivate.h
index d9d9c3b..dd0cf8d 100644
--- a/gtk/gtktreeprivate.h
+++ b/gtk/gtktreeprivate.h
@@ -140,6 +140,9 @@ struct _GtkTreeViewPrivate
   gint press_start_x;
   gint press_start_y;
 
+  gint event_last_x;
+  gint event_last_y;
+
   guint last_button_time;
   gint last_button_x;
   gint last_button_y;
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index 7c2e00a..560f35c 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -390,6 +390,9 @@ static void     remove_expand_collapse_timeout               (GtkTreeView
 static void     cancel_arrow_animation                       (GtkTreeView        *tree_view);
 static gboolean do_expand_collapse                           (GtkTreeView        *tree_view);
 static void     gtk_tree_view_stop_rubber_band               (GtkTreeView        *tree_view);
+static void     update_prelight                              (GtkTreeView        *tree_view,
+                                                              int                 x,
+                                                              int                 y);
 
 /* interactive search */
 static void     gtk_tree_view_ensure_interactive_directory (GtkTreeView *tree_view);
@@ -2438,6 +2441,11 @@ gtk_tree_view_size_allocate (GtkWidget     *widget,
       /* This little hack only works if we have an LTR locale, and no column has the  */
       if (width_changed)
 	{
+          if (tree_view->priv->tree)
+            update_prelight (tree_view,
+                             tree_view->priv->event_last_x,
+                             tree_view->priv->event_last_y);
+
 	  if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
 	      ! has_expand_column)
 	    invalidate_last_column (tree_view);
@@ -3257,6 +3265,26 @@ prelight_or_select (GtkTreeView *tree_view,
 }
 
 static void
+update_prelight (GtkTreeView *tree_view,
+                 gint         x,
+                 gint         y)
+{
+  int new_y;
+  GtkRBTree *tree;
+  GtkRBNode *node;
+
+  new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y);
+  if (new_y < 0)
+    new_y = 0;
+
+  _gtk_rbtree_find_offset (tree_view->priv->tree,
+                           new_y, &tree, &node);
+
+  if (node)
+    prelight_or_select (tree_view, tree, node, x, y);
+}
+
+static void
 ensure_unprelighted (GtkTreeView *tree_view)
 {
   do_prelight (tree_view,
@@ -4067,6 +4095,9 @@ gtk_tree_view_motion_bin_window (GtkWidget      *widget,
       (tree_view->priv->button_pressed_node != node))
     node = NULL;
 
+  tree_view->priv->event_last_x = event->x;
+  tree_view->priv->event_last_y = event->y;
+
   prelight_or_select (tree_view, tree, node, event->x, event->y);
 
   return TRUE;
@@ -10492,9 +10523,15 @@ gtk_tree_view_adjustment_changed (GtkAdjustment *adjustment,
 		       - tree_view->priv->hadjustment->value,
 		       0);
       dy = tree_view->priv->dy - (int) tree_view->priv->vadjustment->value;
-      if (dy && tree_view->priv->edited_column)
+      if (dy)
 	{
-	  if (GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
+          if (tree_view->priv->tree)
+            update_prelight (tree_view,
+                             tree_view->priv->event_last_x,
+                             tree_view->priv->event_last_y - dy);
+
+	  if (tree_view->priv->edited_column &&
+              GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
 	    {
 	      GList *list;
 	      GtkWidget *widget;



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