Add get_offset_at_point for elm_entry.
authorKarol Furmaniak <k.furmaniak@samsung.com>
Tue, 10 Dec 2013 12:58:10 +0000 (13:58 +0100)
committerKarol Furmaniak <k.furmaniak@samsung.com>
Tue, 10 Dec 2013 12:58:10 +0000 (13:58 +0100)
eail/ChangeLog
eail/eail/eail_entry.c

index 3c7eac2..c4a7634 100644 (file)
        get_text_after_offset, get_text_at_offset, get_text_before_offset,
        get_offset_at_point
 
- 2013-11-29 Karol Furmaniak
+2013-11-29 Karol Furmaniak
+
+       * Fix get_text_before/at/after_offset for elm_popup
+
+2013-12-03 Karol Furmaniak
 
-       * Fix get_text_before/at/after_offset for elm_popup
+       * Add get_offset_at_point for elm_entry.
 
index 13e89f1..7898594 100644 (file)
@@ -707,6 +707,65 @@ eail_entry_get_character_extents(AtkText *text,
     }
 }
 
+/*
+ * @brief Gets the offset of the character located at coordinates
+ * x and y. x and y are interpreted as being relative to the
+ *  screen or this widget's window depending on coords.
+ *
+ * @param text AtkText instance
+ * @param x screen x-position of character
+ * @param y screen y-position of character
+ * @param coords specify whether coordinates are relative to the
+ * screen or widget window
+ *
+ * @returns the offset to the character which is located at the
+ * specified x and y coordinates.
+ */
+static gint
+eail_entry_get_offset_at_point(AtkText *text,
+                               gint x,
+                               gint y,
+                               AtkCoordType coords)
+{
+   Eina_Bool result = EINA_FALSE;
+   Evas_Object *textblock = NULL;
+   Evas_Textblock_Cursor *cur = NULL;
+   gint offset = -1;
+
+   Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
+
+   if (!widget) return offset;
+
+   if (coords == ATK_XY_SCREEN)
+   {
+      int ee_x, ee_y;
+      Ecore_Evas *ee= ecore_evas_ecore_evas_get(evas_object_evas_get(widget));
+
+      ecore_evas_geometry_get(ee, &ee_x, &ee_y, NULL, NULL);
+      x -= ee_x;
+      y -= ee_y;
+    }
+
+   textblock = elm_entry_textblock_get(widget);
+   if (!textblock) return offset;
+
+   cur = evas_object_textblock_cursor_new(textblock);
+   if (!cur) return offset;
+
+   result = evas_textblock_cursor_char_coord_set(cur, x, y);
+
+   if (result == EINA_FALSE)
+   {
+      evas_textblock_cursor_free(cur);
+      return offset;
+   }
+
+   offset = evas_textblock_cursor_pos_get(cur);
+   evas_textblock_cursor_free(cur);
+
+   return offset;
+}
+
 /**
  * @brief Initializes AtkTextIface interface
  *
@@ -731,6 +790,7 @@ atk_text_interface_init(AtkTextIface *iface)
    iface->get_text_at_offset = eail_entry_get_text_at_offset;
    iface->get_text_before_offset = eail_entry_get_text_before_offset;
    iface->get_character_extents = eail_entry_get_character_extents;
+   iface->get_offset_at_point = eail_entry_get_offset_at_point;
 }
 
 /*