[caribou: 18/23] Implement set_cursor_location, off by a few pixels



commit e8ee7789378b430bcf59b233557a1a3ef314aa38
Author: Nohemi Fernandez <nf68 cornell edu>
Date:   Mon Aug 8 14:00:43 2011 -0500

    Implement set_cursor_location, off by a few pixels

 modules/gtk3/caribou-gtk-module.vala |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/modules/gtk3/caribou-gtk-module.vala b/modules/gtk3/caribou-gtk-module.vala
index f74404a..add5a79 100644
--- a/modules/gtk3/caribou-gtk-module.vala
+++ b/modules/gtk3/caribou-gtk-module.vala
@@ -13,6 +13,7 @@ namespace Caribou {
         private GLib.HashTable<Gtk.Window, bool> windows;
         private Keyboard keyboard;
         private Gdk.Display display;
+        private Atk.TextRectangle cursor_rect;
 
         public GtkModule () {
             windows = new GLib.HashTable<Gtk.Window, bool> (null, null);
@@ -83,13 +84,24 @@ namespace Caribou {
                 (widget is Gtk.TextView &&
                  ((Gtk.TextView) widget).get_editable ())) {
                 Gdk.Window current_window = widget.get_window ();
+                Atk.Object object = widget.get_accessible ();
                 int x = 0, y = 0, w = 0, h = 0;
-                if (current_window != null)
-                    get_origin_geometry (current_window, out x, out y, out w, out h);
+                int caret_offset = 0;
+
+                if (object is Atk.Text) {
+                    caret_offset = ((Atk.Text) object).get_caret_offset ();
+                    ((Atk.Text) object).get_range_extents (0, caret_offset, Atk.CoordType.SCREEN, cursor_rect);
+
+                    x = cursor_rect.x; y  = cursor_rect.y; w = cursor_rect.width; h = cursor_rect.height;
+                }
+                else {
+                    if (current_window != null)
+                        get_origin_geometry (current_window, out x, out y, out w, out h);
+                }
 
                 try {
                     keyboard.show (timestamp);
-                    keyboard.set_entry_location (x, y, w, h);
+                    keyboard.set_cursor_location (x, y, w, h);
                 } catch (IOError e) {
                     stderr.printf ("%s\n", e.message);
                 }



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