[gtk+/touch-selection-improvements: 5/9] textview: Show magnifier on top of current line



commit 99253de818f27ef8de4e4e3a01e9f6e8ea484c4c
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Nov 20 13:52:13 2014 +0100

    textview: Show magnifier on top of current line
    
    The X coordinate is dependent on touch position, but Y is stepped.

 gtk/gtktextview.c |   32 ++++++++++++++++++--------------
 1 files changed, 18 insertions(+), 14 deletions(-)
---
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 59fb2e1..bfedfb7 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -4676,8 +4676,8 @@ gtk_text_view_set_handle_position (GtkTextView           *text_view,
 
 static void
 gtk_text_view_show_magnifier (GtkTextView *text_view,
-                              gint         x,
-                              gint         y)
+                              GtkTextIter *iter,
+                              gint         x)
 {
   cairo_rectangle_int_t rect;
   GtkTextViewPrivate *priv;
@@ -4686,22 +4686,19 @@ gtk_text_view_show_magnifier (GtkTextView *text_view,
   _gtk_text_view_ensure_magnifier (text_view);
   gtk_widget_get_allocation (GTK_WIDGET (text_view), &allocation);
 
-#define RECT_WIDTH 40
-
   priv = text_view->priv;
-  x = CLAMP (x, 0, allocation.width);
-  y = CLAMP (y, 0, allocation.height);
-  rect.x = x - (RECT_WIDTH / 2);
-  rect.y = y - (RECT_WIDTH / 2);
-  rect.width = rect.height = RECT_WIDTH;
+  gtk_text_view_get_iter_location (text_view, iter,
+                                   (GdkRectangle *) &rect);
+  gtk_text_view_buffer_to_window_coords (text_view, GTK_TEXT_WINDOW_TEXT,
+                                         rect.x, rect.y, &rect.x, &rect.y);
   _text_window_to_widget_coords (text_view, &rect.x, &rect.y);
+  rect.x = x;
 
-  _gtk_magnifier_set_coords (GTK_MAGNIFIER (priv->magnifier), x, y);
+  _gtk_magnifier_set_coords (GTK_MAGNIFIER (priv->magnifier),
+                             rect.x, rect.y + rect.height / 2);
   gtk_popover_set_pointing_to (GTK_POPOVER (priv->magnifier_popover),
                                &rect);
   gtk_widget_show (priv->magnifier_popover);
-
-#undef RECT_WIDTH
 }
 
 static void
@@ -4791,7 +4788,10 @@ gtk_text_view_handle_dragged (GtkTextHandle         *handle,
                                             gtk_text_buffer_get_selection_bound (buffer));
     }
 
-  gtk_text_view_show_magnifier (text_view, x, y);
+  if (_gtk_text_handle_get_is_dragged (priv->text_handle, cursor_pos))
+    gtk_text_view_show_magnifier (text_view, &cursor, x);
+  else
+    gtk_text_view_show_magnifier (text_view, &bound, x);
 }
 
 static void
@@ -6996,6 +6996,7 @@ gtk_text_view_drag_gesture_update (GtkGestureDrag *gesture,
   const GdkEvent *event;
   SelectionData *data;
   GdkDevice *device;
+  GtkTextIter cursor;
 
   data = g_object_get_qdata (G_OBJECT (gesture), quark_text_selection_data);
   sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
@@ -7003,6 +7004,9 @@ gtk_text_view_drag_gesture_update (GtkGestureDrag *gesture,
   drag_gesture_get_text_window_coords (gesture, text_view,
                                        &start_x, &start_y, &x, &y);
 
+  get_iter_from_gesture (text_view, text_view->priv->drag_gesture,
+                         &cursor, NULL, NULL);
+
   if (!data)
     {
       /* If no data is attached, the initial press happened within the current
@@ -7085,7 +7089,7 @@ gtk_text_view_drag_gesture_update (GtkGestureDrag *gesture,
     {
       _gtk_text_view_ensure_text_handles (text_view);
       gtk_text_view_update_handles (text_view, GTK_TEXT_HANDLE_MODE_SELECTION);
-      gtk_text_view_show_magnifier (text_view, x, y);
+      gtk_text_view_show_magnifier (text_view, &cursor, x);
     }
 }
 


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