diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index eeb4ae6e1c..a268b38069 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -1639,7 +1639,6 @@ _gtk_text_view_ensure_magnifier (GtkTextView *text_view) return; priv->magnifier = _gtk_magnifier_new (GTK_WIDGET (text_view)); - gtk_widget_set_size_request (priv->magnifier, 100, 60); _gtk_magnifier_set_magnification (GTK_MAGNIFIER (priv->magnifier), 2.0); priv->magnifier_popover = gtk_popover_new (GTK_WIDGET (text_view)); gtk_style_context_add_class (gtk_widget_get_style_context (priv->magnifier_popover), @@ -4720,28 +4719,48 @@ gtk_text_view_set_handle_position (GtkTextView *text_view, static void gtk_text_view_show_magnifier (GtkTextView *text_view, GtkTextIter *iter, - gint x) + gint x, + gint y) { cairo_rectangle_int_t rect; GtkTextViewPrivate *priv; GtkAllocation allocation; - - _gtk_text_view_ensure_magnifier (text_view); - gtk_widget_get_allocation (GTK_WIDGET (text_view), &allocation); + GtkRequisition req; priv = text_view->priv; + _gtk_text_view_ensure_magnifier (text_view); + + /* Set size/content depending on iter rect */ gtk_text_view_get_iter_location (text_view, iter, (GdkRectangle *) &rect); + rect.x = x; 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; + req.height = rect.height * + _gtk_magnifier_get_magnification (GTK_MAGNIFIER (priv->magnifier)); + req.width = (req.height * 4) / 3; + gtk_widget_set_size_request (priv->magnifier, req.width, req.height); _gtk_magnifier_set_coords (GTK_MAGNIFIER (priv->magnifier), rect.x, rect.y + rect.height / 2); + +#define RECT_WIDTH 40 + + gtk_widget_get_allocation (GTK_WIDGET (text_view), &allocation); + 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; + _text_window_to_widget_coords (text_view, &rect.x, &rect.y); + gtk_popover_set_pointing_to (GTK_POPOVER (priv->magnifier_popover), &rect); + gtk_widget_show (priv->magnifier_popover); + +#undef RECT_WIDTH } static void @@ -4832,9 +4851,9 @@ gtk_text_view_handle_dragged (GtkTextHandle *handle, } if (_gtk_text_handle_get_is_dragged (priv->text_handle, cursor_pos)) - gtk_text_view_show_magnifier (text_view, &cursor, x); + gtk_text_view_show_magnifier (text_view, &cursor, x, y); else - gtk_text_view_show_magnifier (text_view, &bound, x); + gtk_text_view_show_magnifier (text_view, &bound, x, y); } static void @@ -7219,7 +7238,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, &cursor, x); + gtk_text_view_show_magnifier (text_view, &cursor, x, y); } }