From 1d7d554348f76645734772b48d83ae63d8ca6de8 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 23 Jan 2014 11:26:52 +0900 Subject: [PATCH] edje: Support to set or retrieve selection of ecore_imf --- src/lib/edje/edje_entry.c | 57 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/lib/edje/edje_entry.c b/src/lib/edje/edje_entry.c index 53494a3858..8a7b741eca 100644 --- a/src/lib/edje/edje_entry.c +++ b/src/lib/edje/edje_entry.c @@ -5,6 +5,8 @@ static Eina_Bool _edje_entry_imf_retrieve_surrounding_cb(void *data, Ecore_IMF_C static void _edje_entry_imf_event_commit_cb(void *data, Ecore_IMF_Context *ctx, void *event_info); static void _edje_entry_imf_event_preedit_changed_cb(void *data, Ecore_IMF_Context *ctx, void *event_info); static void _edje_entry_imf_event_delete_surrounding_cb(void *data, Ecore_IMF_Context *ctx, void *event); +static void _edje_entry_imf_event_selection_set_cb(void *data, Ecore_IMF_Context *ctx, void *event_info); +static Eina_Bool _edje_entry_imf_retrieve_selection_cb(void *data, Ecore_IMF_Context *ctx, char **text); #endif typedef struct _Entry Entry; @@ -2495,9 +2497,11 @@ _edje_entry_real_part_init(Edje *ed, Edje_Real_Part *rp) ecore_imf_context_retrieve_surrounding_callback_set(en->imf_context, _edje_entry_imf_retrieve_surrounding_cb, ed); + ecore_imf_context_retrieve_selection_callback_set(en->imf_context, _edje_entry_imf_retrieve_selection_cb, ed); ecore_imf_context_event_callback_add(en->imf_context, ECORE_IMF_CALLBACK_COMMIT, _edje_entry_imf_event_commit_cb, ed); ecore_imf_context_event_callback_add(en->imf_context, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, _edje_entry_imf_event_delete_surrounding_cb, ed); ecore_imf_context_event_callback_add(en->imf_context, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, _edje_entry_imf_event_preedit_changed_cb, ed); + ecore_imf_context_event_callback_add(en->imf_context, ECORE_IMF_CALLBACK_SELECTION_SET, _edje_entry_imf_event_selection_set_cb, ed); ecore_imf_context_input_mode_set(en->imf_context, rp->part->entry_mode == EDJE_ENTRY_EDIT_MODE_PASSWORD ? ECORE_IMF_INPUT_MODE_INVISIBLE : ECORE_IMF_INPUT_MODE_FULL); @@ -2545,6 +2549,7 @@ _edje_entry_real_part_shutdown(Edje *ed, Edje_Real_Part *rp) ecore_imf_context_event_callback_del(en->imf_context, ECORE_IMF_CALLBACK_COMMIT, _edje_entry_imf_event_commit_cb); ecore_imf_context_event_callback_del(en->imf_context, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, _edje_entry_imf_event_delete_surrounding_cb); ecore_imf_context_event_callback_del(en->imf_context, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, _edje_entry_imf_event_preedit_changed_cb); + ecore_imf_context_event_callback_del(en->imf_context, ECORE_IMF_CALLBACK_SELECTION_SET, _edje_entry_imf_event_selection_set_cb); ecore_imf_context_del(en->imf_context); en->imf_context = NULL; @@ -4189,6 +4194,58 @@ end: evas_textblock_cursor_free(del_start); evas_textblock_cursor_free(del_end); } + +static void +_edje_entry_imf_event_selection_set_cb(void *data, Ecore_IMF_Context *ctx EINA_UNUSED, void *event_info) +{ + Edje *ed = data; + Edje_Real_Part *rp = ed->focused_part; + Entry *en = NULL; + Ecore_IMF_Event_Selection *ev = event_info; + + if ((!rp) || (!ev)) return; + if ((rp->type != EDJE_RP_TYPE_TEXT) || + (!rp->typedata.text)) return; + else + en = rp->typedata.text->entry_data; + if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) || + (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE)) + return; + + evas_textblock_cursor_pos_set(en->cursor, ev->start); + + _sel_start(en->cursor, rp->object, en); + + evas_textblock_cursor_pos_set(en->cursor, ev->end); + + _sel_extend(ed, en->cursor, rp->object, en); +} + +static Eina_Bool +_edje_entry_imf_retrieve_selection_cb(void *data, Ecore_IMF_Context *ctx EINA_UNUSED, char **text) +{ + Edje *ed = data; + Edje_Real_Part *rp = ed->focused_part; + Entry *en = NULL; + + if (!rp) return EINA_FALSE; + if ((rp->type != EDJE_RP_TYPE_TEXT) || + (!rp->typedata.text)) return EINA_FALSE; + else + en = rp->typedata.text->entry_data; + if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) || + (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE)) + return EINA_FALSE; + + if (en->have_selection) + { + if (text) + *text = strdup(_edje_entry_selection_get(rp)); + return EINA_TRUE; + } + else + return EINA_FALSE; +} #endif /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/