Fix get_offset_at_point for elm_popup.
authorKarol Furmaniak <k.furmaniak@samsung.com>
Thu, 19 Dec 2013 12:55:50 +0000 (13:55 +0100)
committerKarol Furmaniak <k.furmaniak@samsung.com>
Thu, 19 Dec 2013 12:55:50 +0000 (13:55 +0100)
eail/eail/eail_popup.c

index 52064b1..2da531f 100644 (file)
@@ -698,6 +698,65 @@ eail_popup_get_text_before_offset(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_popup_get_offset_at_point(AtkText *text,
+                               gint x,
+                               gint y,
+                               AtkCoordType coords)
+{
+   const Evas_Object *textblock;
+
+   Eina_Bool result = EINA_FALSE;
+   Evas_Textblock_Cursor *cur = NULL;
+   gint offset = -1;
+   Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
+
+   if (!widget) return offset;
+
+   textblock = _eail_get_textblock(text);
+   if (!textblock) return offset;
+
+   cur = evas_object_textblock_cursor_new(textblock);
+   if (!cur) 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;
+    }
+
+   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 Initializer for AtkTextIface interface class
  *
  * Defines callbacks for AtkTextIface.
@@ -716,4 +775,5 @@ atk_text_interface_init(AtkTextIface *iface)
     iface->get_text_after_offset = eail_popup_get_text_after_offset;
     iface->get_text_at_offset = eail_popup_get_text_at_offset;
     iface->get_text_before_offset = eail_popup_get_text_before_offset;
+    iface->get_offset_at_point = eail_popup_get_offset_at_point;
 }