Commit 2f724569 authored by Matthias Clasen's avatar Matthias Clasen

Add gtk_text_view_get_cursor_locations

In GTK 3.0 it's no longer possible to e.g. pop up something
at a text view's cursor (this wasn't exactly possible before
either without including gtktextlayout, but this is a quite
special need anyway).
parent ba02ae72
......@@ -3448,6 +3448,7 @@ gtk_text_view_move_mark_onscreen
......@@ -2855,6 +2855,7 @@ gtk_text_view_get_accepts_tab
......@@ -452,8 +452,6 @@ static void gtk_text_view_target_list_notify (GtkTextBuffer *buffer,
static void gtk_text_view_paste_done_handler (GtkTextBuffer *buffer,
GtkClipboard *clipboard,
gpointer data);
static void gtk_text_view_get_cursor_location (GtkTextView *text_view,
GdkRectangle *pos);
static void gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
GtkTextIter *cursor,
gint *x,
......@@ -1620,6 +1618,61 @@ gtk_text_view_get_buffer (GtkTextView *text_view)
return get_buffer (text_view);
* gtk_text_view_get_cursor_locations:
* @text_view: a #GtkTextView
* @iter: (allow-none): a #GtkTextIter
* @strong: (out) (allow-none): location to store the strong
* cursor position (may be %NULL)
* @weak: (out) (allow-none): location to store the weak
* cursor position (may be %NULL)
* Given an @iter within a text layout, determine the positions of the
* strong and weak cursors if the insertion point is at that
* iterator. The position of each cursor is stored as a zero-width
* rectangle. The strong cursor location is the location where
* characters of the directionality equal to the base direction of the
* paragraph are inserted. The weak cursor location is the location
* where characters of the directionality opposite to the base
* direction of the paragraph are inserted.
* If @iter is %NULL, the actual cursor position is used.
* Note that if @iter happens to be the actual cursor position, and
* there is currently an IM preedit sequence being entered, the
* returned locations will be adjusted to account for the preedit
* cursor's offset within the preedit sequence.
* The rectangle position is in buffer coordinates; use
* gtk_text_view_buffer_to_window_coords() to convert these
* coordinates to coordinates for one of the windows in the text view.
* Since: 3.0
gtk_text_view_get_cursor_locations (GtkTextView *text_view,
const GtkTextIter *iter,
GdkRectangle *strong,
GdkRectangle *weak)
GtkTextIter insert;
g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
g_return_if_fail (iter == NULL ||
gtk_text_iter_get_buffer (iter) == get_buffer (text_view));
gtk_text_view_ensure_layout (text_view);
if (iter)
insert = *iter;
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
gtk_text_buffer_get_insert (get_buffer (text_view)));
gtk_text_layout_get_cursor_locations (text_view->priv->layout, &insert,
strong, weak);
* gtk_text_view_get_iter_at_location:
* @text_view: a #GtkTextView
......@@ -2119,7 +2172,7 @@ gtk_text_view_update_im_spot_location (GtkTextView *text_view)
if (text_view->priv->layout == NULL)
gtk_text_view_get_cursor_location (text_view, &area);
gtk_text_view_get_cursor_locations (text_view, NULL, &area, NULL);
area.x -= text_view->priv->xoffset;
area.y -= text_view->priv->yoffset;
......@@ -7882,18 +7935,6 @@ gtk_text_view_target_list_notify (GtkTextBuffer *buffer,
gtk_target_list_unref (view_list);
static void
gtk_text_view_get_cursor_location (GtkTextView *text_view,
GdkRectangle *pos)
GtkTextIter insert;
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
gtk_text_buffer_get_insert (get_buffer (text_view)));
gtk_text_layout_get_cursor_locations (text_view->priv->layout, &insert, pos, NULL);
static void
gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
GtkTextIter *cursor,
......@@ -7944,7 +7985,7 @@ gtk_text_view_set_virtual_cursor_pos (GtkTextView *text_view,
if (x == -1 || y == -1)
gtk_text_view_get_cursor_location (text_view, &pos);
gtk_text_view_get_cursor_locations (text_view, NULL, &pos, NULL);
text_view->priv->virtual_cursor_x = (x == -1) ? pos.x : x;
text_view->priv->virtual_cursor_y = (y == -1) ? pos.y + pos.height / 2 : y;
......@@ -149,6 +149,10 @@ void gtk_text_view_set_cursor_visible (GtkTextView *text_view,
gboolean setting);
gboolean gtk_text_view_get_cursor_visible (GtkTextView *text_view);
void gtk_text_view_get_cursor_locations (GtkTextView *text_view,
const GtkTextIter *iter,
GdkRectangle *strong,
GdkRectangle *weak);
void gtk_text_view_get_iter_location (GtkTextView *text_view,
const GtkTextIter *iter,
GdkRectangle *location);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment