From b01d3c9e1b223ac8e4af84f69b28c7ff9641d2c3 Mon Sep 17 00:00:00 2001 From: Youngbok Shin Date: Fri, 12 Feb 2016 20:18:05 +0900 Subject: [PATCH] entry: add elm_entry_select_region_get() API Summary: Already, there is a way to set a selection region: elm_entry_select_region_set() The get() API also useful and there is needs for this inside of elm_entry.c. Add the API and replace codes in atspi_text_selection_get with the API. @feature Test Plan: 1. Run "elementary_test -to entry3" 2. Make a selection on text. 3. Press "Sel" button. Reviewers: tasn, herdsman, cedric, woohyun, Jaehyun, Hermet Subscribers: Hermet Differential Revision: https://phab.enlightenment.org/D3639 --- legacy/elementary/src/bin/test_entry.c | 9 +++++++++ legacy/elementary/src/lib/elm_entry.c | 21 +++++++++++++++++---- legacy/elementary/src/lib/elm_entry.eo | 6 ++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/legacy/elementary/src/bin/test_entry.c b/legacy/elementary/src/bin/test_entry.c index b679f3a..f79505e 100644 --- a/legacy/elementary/src/bin/test_entry.c +++ b/legacy/elementary/src/bin/test_entry.c @@ -35,6 +35,9 @@ my_entry_bt_3(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UN { Evas_Object *en = data; const char *s = elm_entry_selection_get(en); + int start = 0, end = 0; + elm_entry_select_region_get(en, &start, &end); + printf("SELECTION REGION: %d - %d\n", start, end); printf("SELECTION:\n"); if (s) printf("%s\n", s); printf("SELECTION PLAIN UTF8:\n"); @@ -256,6 +259,9 @@ my_scrolled_entry_bt_3(void *data, Evas_Object *obj EINA_UNUSED, void *event_inf { Evas_Object *en = data; const char *s = elm_entry_selection_get(en); + int start = 0, end = 0; + elm_entry_select_region_get(en, &start, &end); + printf("SELECTION REGION: %d - %d\n", start, end); printf("SELECTION:\n"); if (s) printf("%s\n", s); printf("SELECTION PLAIN UTF8:\n"); @@ -685,6 +691,9 @@ my_ent_bt_sel(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UN { Evas_Object *en = data; const char *s = elm_entry_selection_get(en); + int start = 0, end = 0; + elm_entry_select_region_get(en, &start, &end); + printf("SELECTION REGION: %d - %d\n", start, end); printf("SELECTION:\n"); if (s) printf("%s\n", s); printf("SELECTION PLAIN UTF8:\n"); diff --git a/legacy/elementary/src/lib/elm_entry.c b/legacy/elementary/src/lib/elm_entry.c index b6df9c8..70cc5ae 100644 --- a/legacy/elementary/src/lib/elm_entry.c +++ b/legacy/elementary/src/lib/elm_entry.c @@ -4176,6 +4176,22 @@ _elm_entry_select_region_set(Eo *obj EINA_UNUSED, Elm_Entry_Data *sd, int start, edje_object_part_text_select_extend(sd->entry_edje, "elm.text"); } +EOLIAN static void +_elm_entry_select_region_get(Eo *obj, Elm_Entry_Data *sd, int *start, int *end) +{ + if (!elm_entry_selection_get(obj)) + { + if (start) *start = -1; + if (end) *end = -1; + return; + } + + if (start) + *start = edje_object_part_text_cursor_pos_get(sd->entry_edje, "elm.text", EDJE_CURSOR_SELECTION_BEGIN); + if (end) + *end = edje_object_part_text_cursor_pos_get(sd->entry_edje, "elm.text", EDJE_CURSOR_SELECTION_END); +} + EOLIAN static Eina_Bool _elm_entry_cursor_geometry_get(Eo *obj EINA_UNUSED, Elm_Entry_Data *sd, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h) { @@ -5428,12 +5444,9 @@ _elm_entry_elm_interface_atspi_text_selections_count_get(Eo *obj, Elm_Entry_Data EOLIAN static void _elm_entry_elm_interface_atspi_text_selection_get(Eo *obj, Elm_Entry_Data *_pd EINA_UNUSED, int selection_number, int *start_offset, int *end_offset) { - *start_offset = *end_offset = -1; - if (!elm_entry_selection_get(obj)) return; if (selection_number != 0) return; - *start_offset = edje_object_part_text_cursor_pos_get(_pd->entry_edje, "elm.text", EDJE_CURSOR_SELECTION_BEGIN); - *end_offset = edje_object_part_text_cursor_pos_get(_pd->entry_edje, "elm.text", EDJE_CURSOR_SELECTION_END); + eo_do(obj, elm_obj_entry_select_region_get(start_offset, end_offset)); } EOLIAN static Eina_Bool diff --git a/legacy/elementary/src/lib/elm_entry.eo b/legacy/elementary/src/lib/elm_entry.eo index 1609cb3..166c6c7 100644 --- a/legacy/elementary/src/lib/elm_entry.eo +++ b/legacy/elementary/src/lib/elm_entry.eo @@ -493,6 +493,12 @@ class Elm.Entry (Elm.Layout, Elm.Interface_Scrollable, Evas.Clickable_Interface, @since 1.9 ]] } + get { + [[Get the current position of the selection cursors in the entry. + + @since 1.18 + ]] + } values { start: int; [[The starting position.]] end: int; [[The end position.]] -- 2.7.4