From 38db4b4c0397ce599d5c50859d8431fbbdff284c Mon Sep 17 00:00:00 2001 From: Jiwon Kim Date: Wed, 6 Jul 2016 12:48:56 -0700 Subject: [PATCH] elm_entry: remove unnecessary text clearing in text_set Summary: When text_set is called for entry, it sets to empty text before calling _entry_text_append(). but, _entry_text_append() has 'set' parameter. Therefore text is set in that function, and clearing is not needed. It can fix "changed" smart callback is invoked multipe times when a short text is set to entry. In addition, if text length is larger than ELM_ENTRY_CHUNK_SIZE, set text directly as amount of chunk size and idler will append about remain text. @fix Test Plan: 1. elementary_test -to "entry5" 2. click "set 10000" button 2-1. changed message should be printed 1 time 3. click "set 10001" button 3-1. changed message should be printed 2 times Reviewers: tasn, Hermet, id213sin, cedric Reviewed By: cedric Subscribers: woohyun, cedric, jpeg Differential Revision: https://phab.enlightenment.org/D4134 Signed-off-by: Cedric BAIL --- src/bin/elementary/test_entry.c | 64 +++++++++++++++++++++++++++++++++++++++++ src/lib/elementary/elm_entry.c | 18 ++++++++++-- 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/src/bin/elementary/test_entry.c b/src/bin/elementary/test_entry.c index b94c525..4b1a020 100644 --- a/src/bin/elementary/test_entry.c +++ b/src/bin/elementary/test_entry.c @@ -1811,10 +1811,45 @@ test_entry4(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_in evas_object_show(win); } +static void +_entry_changed_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, + void *event_info EINA_UNUSED) +{ + printf("entry is changed\n"); +} + +#define ELM_ENTRY_CHUNK_SIZE 10000 +static void +my_ent_set_chunk(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + Evas_Object *en = data; + char *buf = calloc((ELM_ENTRY_CHUNK_SIZE + 1), sizeof(char)); + int i; + for (i = 0; i < ELM_ENTRY_CHUNK_SIZE; i++) + buf[i] = '1'; + + printf("set %d length of text\n", ELM_ENTRY_CHUNK_SIZE); + elm_entry_entry_set(en, buf); +} + +static void +my_ent_set_long(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + Evas_Object *en = data; + char *buf = calloc((ELM_ENTRY_CHUNK_SIZE + 2), sizeof(char)); + int i; + for (i = 0; i < (ELM_ENTRY_CHUNK_SIZE + 1); i++) + buf[i] = '1'; + + printf("set %d length of text\n", ELM_ENTRY_CHUNK_SIZE + 1); + elm_entry_entry_set(en, buf); +} + void test_entry5(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { Evas_Object *win, *bx, *bx2, *bt, *en; + char buf[10]; win = elm_win_util_standard_add("entry5", "Entry 5"); elm_win_autodel_set(win, EINA_TRUE); @@ -1840,6 +1875,7 @@ test_entry5(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_in "good testing to see if entry widgets work as advertised." ); evas_object_smart_callback_add(en, "anchor,clicked", scrolled_anchor_test, en); + evas_object_smart_callback_add(en, "changed", _entry_changed_cb, NULL); elm_box_pack_end(bx, en); evas_object_show(en); @@ -2073,6 +2109,34 @@ test_entry5(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_in elm_box_pack_end(bx, bx2); evas_object_show(bx2); + bx2 = elm_box_add(win); + elm_box_horizontal_set(bx2, EINA_TRUE); + evas_object_size_hint_weight_set(bx2, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(bx2, EVAS_HINT_FILL, EVAS_HINT_FILL); + + bt = elm_button_add(win); + snprintf(buf, 10, "set %d", ELM_ENTRY_CHUNK_SIZE); + elm_object_text_set(bt, buf); + evas_object_smart_callback_add(bt, "clicked", my_ent_set_chunk, en); + evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0); + elm_box_pack_end(bx2, bt); + elm_object_focus_allow_set(bt, EINA_FALSE); + evas_object_show(bt); + + bt = elm_button_add(win); + snprintf(buf, 10, "set %d", ELM_ENTRY_CHUNK_SIZE + 1); + elm_object_text_set(bt, buf); + evas_object_smart_callback_add(bt, "clicked", my_ent_set_long, en); + evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0); + elm_box_pack_end(bx2, bt); + elm_object_focus_allow_set(bt, EINA_FALSE); + evas_object_show(bt); + + elm_box_pack_end(bx, bx2); + evas_object_show(bx2); + evas_object_resize(win, 320, 480); elm_object_focus_set(win, EINA_TRUE); diff --git a/src/lib/elementary/elm_entry.c b/src/lib/elementary/elm_entry.c index 160a3bf..abc89c9 100644 --- a/src/lib/elementary/elm_entry.c +++ b/src/lib/elementary/elm_entry.c @@ -3134,6 +3134,22 @@ _entry_text_append(Evas_Object* obj, const char* entry, Eina_Bool set) memcpy(sd->append_text_left, entry, len + 1); sd->append_text_position = 0; sd->append_text_len = len; + /* Set text directly as amount of chunk size + * and append remain text to idler */ + if (set) + { + char tmp; + tmp = sd->append_text_left[ELM_ENTRY_CHUNK_SIZE]; + sd->append_text_left[ELM_ENTRY_CHUNK_SIZE] = '\0'; + + if (edje_object_part_text_set(sd->entry_edje, "elm.text", + sd->append_text_left)) + sd->append_text_position = ELM_ENTRY_CHUNK_SIZE; + else + edje_object_part_text_set(sd->entry_edje, "elm.text", ""); + + sd->append_text_left[ELM_ENTRY_CHUNK_SIZE] = tmp; + } sd->append_text_idler = ecore_idler_add(_text_append_idler, obj); } else @@ -3188,8 +3204,6 @@ _elm_entry_elm_layout_text_set(Eo *obj, Elm_Entry_Data *sd, const char *part, co sd->append_text_left = NULL; } - /* Need to clear the entry first */ - edje_object_part_text_set(sd->entry_edje, "elm.text", ""); _entry_text_append(obj, entry, EINA_TRUE); if (len > 0) -- 2.7.4