Hello,

There has been no way to set or get the cursor position of entry in the
elementary.
In this patch includes elm_entry_cursor_pos_set/get and
elm_scrolled_entry_cursor_pos_set/get APIs.

Would you please review thist patch?

Index: ChangeLog
===================================================================
--- ChangeLog   (revision 57314)
+++ ChangeLog   (working copy)
@@ -37,3 +37,7 @@
 
        * fix signal comming from box/table item to include their
        index or name correctly.
+
+2011-02-25  Jihoon Kim
+
+       * Add edje_object_part_text_cursor_pos_{set,get} API
Index: src/lib/edje_private.h
===================================================================
--- src/lib/edje_private.h      (revision 57314)
+++ src/lib/edje_private.h      (working copy)
@@ -1776,6 +1776,8 @@ Eina_Bool _edje_entry_cursor_coord_set(Edje_Real_P
 Eina_Bool _edje_entry_cursor_is_format_get(Edje_Real_Part *rp, Edje_Cursor 
cur);
 Eina_Bool _edje_entry_cursor_is_visible_format_get(Edje_Real_Part *rp, 
Edje_Cursor cur);
 const char *_edje_entry_cursor_content_get(Edje_Real_Part *rp, Edje_Cursor 
cur);
+void _edje_entry_cursor_pos_set(Edje_Real_Part *rp, Edje_Cursor cur, int pos);
+int _edje_entry_cursor_pos_get(Edje_Real_Part *rp, Edje_Cursor cur);
     
 void _edje_external_init();
 void _edje_external_shutdown();
Index: src/lib/edje_util.c
===================================================================
--- src/lib/edje_util.c (revision 57314)
+++ src/lib/edje_util.c (working copy)
@@ -2214,6 +2214,55 @@ edje_object_part_text_cursor_content_get(const Eva
 }
 
 /**
+ * @brief Sets the cursor position to the given value
+ *
+ * @param obj A valid Evas_Object handle
+ * @param part The part name
+ * @param cur The cursor to move
+ * @param pos the position of the cursor
+ */
+EAPI void
+edje_object_part_text_cursor_pos_set(const Evas_Object *obj, const char *part, 
Edje_Cursor cur, int pos)
+{
+   Edje *ed;
+   Edje_Real_Part *rp;
+
+   ed = _edje_fetch(obj);
+   if ((!ed) || (!part)) return;
+   rp = _edje_real_part_recursive_get(ed, part);
+   if (!rp) return;
+   if (rp->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE)
+     {
+        _edje_entry_cursor_pos_set(rp, cur, pos);
+     }
+}
+
+/**
+ * @brief Retrieves the current position of the cursor
+ *
+ * @param obj A valid Evas_Object handle
+ * @param part The part name
+ * @param cur The cursor to get the position
+ * @return The cursor position
+ */
+EAPI int
+edje_object_part_text_cursor_pos_get(const Evas_Object *obj, const char *part, 
Edje_Cursor cur)
+{
+   Edje *ed;
+   Edje_Real_Part *rp;
+
+   ed = _edje_fetch(obj);
+   if ((!ed) || (!part)) return 0;
+   rp = _edje_real_part_recursive_get(ed, part);
+   if (!rp) return 0;
+   if (rp->part->entry_mode > EDJE_ENTRY_EDIT_MODE_NONE)
+     {
+        return _edje_entry_cursor_pos_get(rp, cur);
+     }
+   return 0;
+}
+
+/**
  * Add a filter function for newly inserted text.
  *
  * Whenever text is inserted (not the same as set) into the given @p part,
Index: src/lib/Edje.h
===================================================================
--- src/lib/Edje.h      (revision 57314)
+++ src/lib/Edje.h      (working copy)
@@ -608,6 +608,8 @@ typedef Evas_Object *(*Edje_Item_Provider_Cb)   (v
    EAPI Eina_Bool        edje_object_part_text_cursor_is_format_get        
(const Evas_Object *obj, const char *part, Edje_Cursor cur);
    EAPI Eina_Bool        
edje_object_part_text_cursor_is_visible_format_get(const Evas_Object *obj, 
const char *part, Edje_Cursor cur);
    EAPI const char      *edje_object_part_text_cursor_content_get          
(const Evas_Object *obj, const char *part, Edje_Cursor cur);
+   EAPI void             edje_object_part_text_cursor_pos_set              
(const Evas_Object *obj, const char *part, Edje_Cursor cur, int pos);
+   EAPI int              edje_object_part_text_cursor_pos_get              
(const Evas_Object *obj, const char *part, Edje_Cursor cur);
 
    EAPI void             edje_object_text_insert_filter_callback_add       
(Evas_Object *obj, const char *part, Edje_Text_Filter_Cb func, void *data);
    EAPI void            *edje_object_text_insert_filter_callback_del       
(Evas_Object *obj, const char *part, Edje_Text_Filter_Cb func);
Index: src/lib/edje_entry.c
===================================================================
--- src/lib/edje_entry.c        (revision 57314)
+++ src/lib/edje_entry.c        (working copy)
@@ -2603,7 +2603,38 @@ _edje_entry_cursor_content_get(Edje_Real_Part *rp,
    return s;
 }
 
+void
+_edje_entry_cursor_pos_set(Edje_Real_Part *rp, Edje_Cursor cur, int pos)
+{
+   Entry *en = rp->entry_data;
+   Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
+   if (!c) return;
+   evas_textblock_cursor_pos_set(c, pos);
+   _curs_update_from_curs(c, rp->object, rp->entry_data);
+   _sel_update(c, rp->object, rp->entry_data);
+
 #ifdef HAVE_ECORE_IMF
+   if (en->imf_context)
+     {
+        ecore_imf_context_reset(en->imf_context);
+        ecore_imf_context_cursor_position_set(en->imf_context,
+                                              
evas_textblock_cursor_pos_get(en->cursor));
+     }
+#endif
+
+   _edje_emit(rp->edje, "cursor,changed", rp->part->name);
+   _edje_entry_real_part_configure(rp);
+}
+
+int
+_edje_entry_cursor_pos_get(Edje_Real_Part *rp, Edje_Cursor cur)
+{
+   Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
+   if (!c) return 0;
+   return evas_textblock_cursor_pos_get(c);
+}
+
+#ifdef HAVE_ECORE_IMF
 static Eina_Bool
 _edje_entry_imf_retrieve_surrounding_cb(void *data, Ecore_IMF_Context *ctx 
__UNUSED__, char **text, int *cursor_pos)
 {
Index: src/lib/elm_entry.c
===================================================================
--- src/lib/elm_entry.c (revision 57316)
+++ src/lib/elm_entry.c (working copy)
@@ -2212,6 +2212,40 @@ elm_entry_cursor_content_get(const Evas_Object *ob
 }
 
 /**
+ * Sets the cursor position in the entry to the given value
+ *
+ * @param obj The entry object
+ * @param pos The position of the cursor
+ *
+ * @ingroup Entry
+ */
+EAPI void
+elm_entry_cursor_pos_set(const Evas_Object *obj, int pos)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, 
pos);
+}
+
+/**
+ * Retrieves the current position of the cursor in the entry
+ *
+ * @param obj The entry object
+ * @return The cursor position
+ *
+ * @ingroup Entry
+ */
+EAPI int
+elm_entry_cursor_pos_get(const Evas_Object *obj)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) 0;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return 0;
+   return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", 
EDJE_CURSOR_MAIN);
+}
+
+/**
  * This executes a "cut" action on the selected text in the entry.
  *
  * @param obj The entry object
Index: src/lib/elc_scrolled_entry.c
===================================================================
--- src/lib/elc_scrolled_entry.c        (revision 57316)
+++ src/lib/elc_scrolled_entry.c        (working copy)
@@ -1151,6 +1151,40 @@ elm_scrolled_entry_cursor_content_get(const Evas_O
 }
 
 /**
+ * Sets the cursor position in the scrolled entry to the given value
+ *
+ * @param obj The scrolled entry object
+ * @param pos the position of the cursor
+ *
+ * @ingroup Scrolled_Entry
+ */
+EAPI void
+elm_scrolled_entry_cursor_pos_set(const Evas_Object *obj, int pos)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   elm_entry_cursor_pos_set(wd->entry, pos);
+}
+
+/**
+ * Retrieves the current position of the cursor in the scrolled entry
+ *
+ * @param obj The entry object
+ * @return the cursor position
+ *
+ * @ingroup Scrolled_Entry
+ */
+EAPI int
+elm_scrolled_entry_cursor_pos_get(const Evas_Object *obj)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) 0;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return 0;
+   return elm_entry_cursor_pos_get(wd->entry);
+}
+
+/**
  * This executes a "cut" action on the selected text in the scrolled entry.
  *
  * @param obj The scrolled entry object
Index: src/lib/Elementary.h.in
===================================================================
--- src/lib/Elementary.h.in     (revision 57316)
+++ src/lib/Elementary.h.in     (working copy)
@@ -1224,6 +1224,8 @@ extern "C" {
    EAPI Eina_Bool    elm_entry_cursor_is_visible_format_get(const Evas_Object 
*obj) EINA_ARG_NONNULL(1);
    EAPI const char  *elm_entry_cursor_content_get(const Evas_Object *obj) 
EINA_ARG_NONNULL(1);
    EAPI Eina_Bool    elm_entry_cursor_geometry_get(const Evas_Object *obj, 
Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h) EINA_ARG_NONNULL(1);
+   EAPI void         elm_entry_cursor_pos_set(const Evas_Object *obj, int pos) 
EINA_ARG_NONNULL(1);
+   EAPI int          elm_entry_cursor_pos_get(const Evas_Object *obj) 
EINA_ARG_NONNULL(1);
    EAPI void         elm_entry_selection_cut(Evas_Object *obj) 
EINA_ARG_NONNULL(1);
    EAPI void         elm_entry_selection_copy(Evas_Object *obj) 
EINA_ARG_NONNULL(1);
    EAPI void         elm_entry_selection_paste(Evas_Object *obj) 
EINA_ARG_NONNULL(1);
@@ -2240,6 +2242,8 @@ extern "C" {
    EAPI Eina_Bool    elm_scrolled_entry_cursor_is_format_get(const Evas_Object 
*obj) EINA_ARG_NONNULL(1);
    EAPI Eina_Bool    elm_scrolled_entry_cursor_is_visible_format_get(const 
Evas_Object *obj) EINA_ARG_NONNULL(1);
    EAPI const char  *elm_scrolled_entry_cursor_content_get(const Evas_Object 
*obj) EINA_ARG_NONNULL(1);
+   EAPI void         elm_scrolled_entry_cursor_pos_set(const Evas_Object *obj, 
int pos) EINA_ARG_NONNULL(1);
+   EAPI int          elm_scrolled_entry_cursor_pos_get(const Evas_Object *obj) 
EINA_ARG_NONNULL(1);
    EAPI void         elm_scrolled_entry_selection_cut(Evas_Object *obj) 
EINA_ARG_NONNULL(1);
    EAPI void         elm_scrolled_entry_selection_copy(Evas_Object *obj) 
EINA_ARG_NONNULL(1);
    EAPI void         elm_scrolled_entry_selection_paste(Evas_Object *obj) 
EINA_ARG_NONNULL(1);
------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev 
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to