[gtk+] textview: Mind the lateral windows when setting handles/popovers positions



commit 3693045566793cb926d828cf4836a030ec550e1a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Mar 17 17:42:07 2014 +0100

    textview: Mind the lateral windows when setting handles/popovers positions
    
    If a textview had lateral windows that might displace the text window, the
    handles and popovers would appear displaced. Those lateral windows aren't
    affected by RTL/LTR settings, so just checking for left/top is ok here.

 gtk/gtktextview.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index d71e9f4..6dffa38 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -4588,6 +4588,32 @@ emit_event_on_tags (GtkWidget   *widget,
 }
 
 static void
+_text_window_to_widget_coords (GtkTextView *text_view,
+                               gint        *x,
+                               gint        *y)
+{
+  GtkTextViewPrivate *priv = text_view->priv;
+
+  if (priv->top_window)
+    (*y) += priv->top_window->requisition.height;
+  if (priv->left_window)
+    (*x) += priv->left_window->requisition.width;
+}
+
+static void
+_widget_to_text_window_coords (GtkTextView *text_view,
+                               gint        *x,
+                               gint        *y)
+{
+  GtkTextViewPrivate *priv = text_view->priv;
+
+  if (priv->top_window)
+    (*y) -= priv->top_window->requisition.height;
+  if (priv->left_window)
+    (*x) -= priv->left_window->requisition.width;
+}
+
+static void
 gtk_text_view_set_handle_position (GtkTextView           *text_view,
                                    GtkTextIter           *iter,
                                    GtkTextHandlePosition  pos)
@@ -4617,6 +4643,8 @@ gtk_text_view_set_handle_position (GtkTextView           *text_view,
 
       rect.x = CLAMP (x, 0, SCREEN_WIDTH (text_view));
       rect.y = CLAMP (y, 0, SCREEN_HEIGHT (text_view));
+      _text_window_to_widget_coords (text_view, &rect.x, &rect.y);
+
       _gtk_text_handle_set_position (priv->text_handle, pos, &rect);
     }
 }
@@ -4639,6 +4667,7 @@ gtk_text_view_show_magnifier (GtkTextView *text_view,
   rect.x = x;
   rect.y = y;
   rect.width = rect.height = 1;
+  _text_window_to_widget_coords (text_view, &rect.x, &rect.y);
 
   _gtk_magnifier_set_coords (GTK_MAGNIFIER (priv->magnifier), x, y);
   gtk_popover_set_pointing_to (GTK_POPOVER (priv->magnifier_popover),
@@ -4665,6 +4694,8 @@ gtk_text_view_handle_dragged (GtkTextHandle         *handle,
   buffer = get_buffer (text_view);
   mode = _gtk_text_handle_get_mode (handle);
 
+  _widget_to_text_window_coords (text_view, &x, &y);
+
   gtk_text_view_selection_bubble_popup_unset (text_view);
   gtk_text_layout_get_iter_at_pixel (priv->layout, &iter,
                                      x + priv->xoffset,
@@ -9008,6 +9039,8 @@ bubble_targets_received (GtkClipboard     *clipboard,
   rect.x -= priv->xoffset;
   rect.y -= priv->yoffset;
 
+  _text_window_to_widget_coords (text_view, &rect.x, &rect.y);
+
   gtk_popover_set_pointing_to (GTK_POPOVER (priv->selection_bubble), &rect);
   gtk_widget_show (priv->selection_bubble);
 


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