Add get_offset_at_point for elm_multibuttonentry.
authorKarol Furmaniak <k.furmaniak@samsung.com>
Thu, 12 Dec 2013 10:13:07 +0000 (11:13 +0100)
committerKarol Furmaniak <k.furmaniak@samsung.com>
Thu, 12 Dec 2013 10:13:07 +0000 (11:13 +0100)
eail/eail/eail_multibuttonentry.c

index 820e80f..af667b3 100644 (file)
@@ -304,6 +304,69 @@ eail_multibuttonentry_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_multibuttonentry_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 *entry = NULL;
+   Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(text));
+
+   if (!widget) return offset;
+
+   entry = elm_multibuttonentry_entry_get(widget);
+
+   if (!entry) return offset;
+
+   if (coords == ATK_XY_SCREEN)
+   {
+      int ee_x, ee_y;
+      Ecore_Evas *ee= ecore_evas_ecore_evas_get(evas_object_evas_get(entry));
+
+      ecore_evas_geometry_get(ee, &ee_x, &ee_y, NULL, NULL);
+      x -= ee_x;
+      y -= ee_y;
+    }
+
+   textblock = elm_entry_textblock_get(entry);
+   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 Adds a selection bounded by the specified offsets
  *
@@ -703,6 +766,7 @@ atk_text_interface_init(AtkTextIface *iface)
    iface->get_text_before_offset = eail_multibuttonentry_get_text_before_offset;
    iface->get_run_attributes = eail_multibuttonentry_get_run_attributes;
    iface->get_default_attributes = eail_multibuttonentry_get_default_attributes;
+   iface->get_offset_at_point = eail_multibuttonentry_get_offset_at_point;
 }
 
 /**