[gtk+] GtkTextView: Fix scrolling of added children



commit 664fe89f6e35c18f8be8954f4de62a17625d5e30
Author: Alexander Larsson <alexl redhat com>
Date:   Wed Jan 8 15:26:15 2014 +0100

    GtkTextView: Fix scrolling of added children
    
    The behaviour of gtk_text_view_add_child_in_window() used to be
    quite broken. It scrolled with the window during scrolling, then
    jumped to the absolute position when the widget resized. Furthermore,
    in 3.10 we broke the first feature, making it always be fixed.
    
    The "proper" way to handle this is to always follow scrolling. This
    is what the only user so far (gedit) wants, and if you want some
    kind of overlay you should use GtkOverlay instead.
    
    So, this changes the behaviour to something that is internally consistent
    and works. I.e. all added widgets scroll with the textview as needed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711826

 gtk/gtktextview.c |   41 ++++++++++++++++++++++++++++++++---------
 1 files changed, 32 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index a2030c9..b32a24a 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -3683,6 +3683,15 @@ gtk_text_view_allocate_children (GtkTextView *text_view)
           allocation.x = child->x;
           allocation.y = child->y;
 
+          if (child->type == GTK_TEXT_WINDOW_TEXT ||
+              child->type == GTK_TEXT_WINDOW_LEFT ||
+              child->type == GTK_TEXT_WINDOW_RIGHT)
+            allocation.y -= text_view->priv->yoffset;
+          if (child->type == GTK_TEXT_WINDOW_TEXT ||
+              child->type == GTK_TEXT_WINDOW_TOP ||
+              child->type == GTK_TEXT_WINDOW_BOTTOM)
+            allocation.x -= text_view->priv->xoffset;
+
           gtk_widget_get_preferred_size (child->widget, &child_req, NULL);
 
           allocation.width = child_req.width;
@@ -8159,10 +8168,28 @@ gtk_text_view_value_changed (GtkAdjustment *adjustment,
       while (tmp_list != NULL)
         {
           GtkTextViewChild *child = tmp_list->data;
-          
+          gint child_dx = 0, child_dy = 0;
+
           if (child->anchor)
-            adjust_allocation (child->widget, dx, dy);
-          
+            {
+              child_dx = dx;
+              child_dy = dy;
+            }
+          else
+            {
+              if (child->type == GTK_TEXT_WINDOW_TEXT ||
+                  child->type == GTK_TEXT_WINDOW_LEFT ||
+                  child->type == GTK_TEXT_WINDOW_RIGHT)
+                child_dy = dy;
+              if (child->type == GTK_TEXT_WINDOW_TEXT ||
+                  child->type == GTK_TEXT_WINDOW_TOP ||
+                  child->type == GTK_TEXT_WINDOW_BOTTOM)
+                child_dx = dx;
+            }
+
+          if (child_dx != 0 || child_dy != 0)
+            adjust_allocation (child->widget, child_dx, child_dy);
+
           tmp_list = g_slist_next (tmp_list);
         }
     }
@@ -10070,15 +10097,11 @@ gtk_text_view_add_child_at_anchor (GtkTextView          *text_view,
  *
  * The window must have nonzero size (see
  * gtk_text_view_set_border_window_size()). Note that the child
- * coordinates are given relative to the #GdkWindow in question, and
- * that these coordinates have no sane relationship to scrolling. When
+ * coordinates are given relative to scrolling. When
  * placing a child in #GTK_TEXT_WINDOW_WIDGET, scrolling is
  * irrelevant, the child floats above all scrollable areas. But when
  * placing a child in one of the scrollable windows (border windows or
- * text window), you'll need to compute the child's correct position
- * in buffer coordinates any time scrolling occurs or buffer changes
- * occur, and then call gtk_text_view_move_child() to update the
- * child's position.
+ * text window) it will move with the scrolling as needed.
  */
 void
 gtk_text_view_add_child_in_window (GtkTextView       *text_view,


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