summaryrefslogtreecommitdiff
path: root/gtk/gtktextview.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2003-06-05 23:04:49 +0000
committerOwen Taylor <otaylor@src.gnome.org>2003-06-05 23:04:49 +0000
commit6bbdea92f7d888b4e6d212655d97756545b514fa (patch)
treeec9ec3b649200ddad6517abdd0967431dd4e8559 /gtk/gtktextview.c
parent4d5b395f2c8b8ad765727114397f1291c13195dd (diff)
downloadgdk-pixbuf-6bbdea92f7d888b4e6d212655d97756545b514fa.tar.gz
#80023, Yao Zhang, TOKUNAGA Hiroyuki
Thu Jun 5 16:12:54 2003 Owen Taylor <otaylor@redhat.com> #80023, Yao Zhang, TOKUNAGA Hiroyuki * gtk/gtktextlayout.c (gtk_text_layout_get_cursor_locations): Account for the preedit cursor offset if the iter passed in is at the same place as the insertion cursor. * gtk/gtktextview.c (gtk_text_view_get_cursor_location): Encapsulate getting the insertion cursor location. * gtk/gtktextview.c (gtk_text_view_update_im_spot_location): Pass the real y/height to the IM context. Take text_view->x/yoffset into account.
Diffstat (limited to 'gtk/gtktextview.c')
-rw-r--r--gtk/gtktextview.c52
1 files changed, 30 insertions, 22 deletions
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index d28c2a78c..fe241675e 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -301,6 +301,8 @@ static void gtk_text_view_mark_set_handler (GtkTextBuffer *buffer,
const GtkTextIter *location,
GtkTextMark *mark,
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,
gint *x,
gint *y);
@@ -1723,16 +1725,19 @@ static void
gtk_text_view_update_im_spot_location (GtkTextView *text_view)
{
GdkRectangle area;
- gint cursor_x_pos, cursor_y_pos;
if (text_view->layout == NULL)
return;
- gtk_text_view_get_virtual_cursor_pos (text_view, &cursor_x_pos, &cursor_y_pos);
+ gtk_text_view_get_cursor_location (text_view, &area);
- area.x = cursor_x_pos;
- area.y = cursor_y_pos;
- area.width = area.height = 0;
+ area.x -= text_view->xoffset;
+ area.y -= text_view->yoffset;
+
+ /* Width returned by Pango indicates direction of cursor,
+ * by it's sign more than the size of cursor.
+ */
+ area.width = 0;
gtk_im_context_set_cursor_location (text_view->im_context, &area);
}
@@ -6352,27 +6357,35 @@ gtk_text_view_mark_set_handler (GtkTextBuffer *buffer,
}
static void
-gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
- gint *x,
- gint *y)
+gtk_text_view_get_cursor_location (GtkTextView *text_view,
+ GdkRectangle *pos)
{
- GdkRectangle strong_pos;
GtkTextIter insert;
-
+
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
gtk_text_buffer_get_mark (get_buffer (text_view),
"insert"));
+ gtk_text_layout_get_cursor_locations (text_view->layout, &insert, pos, NULL);
+}
+
+static void
+gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
+ gint *x,
+ gint *y)
+{
+ GdkRectangle pos;
+
if ((x && text_view->virtual_cursor_x == -1) ||
(y && text_view->virtual_cursor_y == -1))
- gtk_text_layout_get_cursor_locations (text_view->layout, &insert, &strong_pos, NULL);
+ gtk_text_view_get_cursor_location (text_view, &pos);
if (x)
{
if (text_view->virtual_cursor_x != -1)
*x = text_view->virtual_cursor_x;
else
- *x = strong_pos.x;
+ *x = pos.x;
}
if (y)
@@ -6380,7 +6393,7 @@ gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
if (text_view->virtual_cursor_x != -1)
*y = text_view->virtual_cursor_y;
else
- *y = strong_pos.y + strong_pos.height / 2;
+ *y = pos.y + pos.height / 2;
}
}
@@ -6389,18 +6402,13 @@ gtk_text_view_set_virtual_cursor_pos (GtkTextView *text_view,
gint x,
gint y)
{
- GdkRectangle strong_pos;
- GtkTextIter insert;
-
- gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
- gtk_text_buffer_get_mark (get_buffer (text_view),
- "insert"));
+ GdkRectangle pos;
if (x == -1 || y == -1)
- gtk_text_layout_get_cursor_locations (text_view->layout, &insert, &strong_pos, NULL);
+ gtk_text_view_get_cursor_location (text_view, &pos);
- text_view->virtual_cursor_x = (x == -1) ? strong_pos.x : x;
- text_view->virtual_cursor_y = (y == -1) ? strong_pos.y + strong_pos.height / 2 : y;
+ text_view->virtual_cursor_x = (x == -1) ? pos.x : x;
+ text_view->virtual_cursor_y = (y == -1) ? pos.y + pos.height / 2 : y;
}
/* Quick hack of a popup menu