From fa165f09022d2d002ed0ccdf05cc7ee00735c4a3 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 23 Jan 2014 10:44:00 +0900 Subject: [PATCH] Add ecore_imf_context_selection_get API to allow Input Method to get the selected text. --- src/lib/ecore_imf/Ecore_IMF.h | 36 ++++++++++++++++++++++++++++++++++ src/lib/ecore_imf/ecore_imf_context.c | 37 +++++++++++++++++++++++++++++++++++ src/lib/ecore_imf/ecore_imf_private.h | 2 ++ 3 files changed, 75 insertions(+) diff --git a/src/lib/ecore_imf/Ecore_IMF.h b/src/lib/ecore_imf/Ecore_IMF.h index ee1c249..2d96a22 100644 --- a/src/lib/ecore_imf/Ecore_IMF.h +++ b/src/lib/ecore_imf/Ecore_IMF.h @@ -908,6 +908,20 @@ EAPI void ecore_imf_context_use_preedit_set(Ecore_IMF_C EAPI void ecore_imf_context_retrieve_surrounding_callback_set(Ecore_IMF_Context *ctx, Eina_Bool (*func)(void *data, Ecore_IMF_Context *ctx, char **text, int *cursor_pos), const void *data); /** + * Set the callback to be used on selection_get request. + * + * This callback will be called when the Input Method Context + * module requests the selection context. + * + * @param ctx An #Ecore_IMF_Context. + * @param func The callback to be called. + * @param data The data pointer to be passed to @p func + * @ingroup Ecore_IMF_Context_Group + * @since 1.9.0 + */ +EAPI void ecore_imf_context_retrieve_selection_callback_set(Ecore_IMF_Context *ctx, Eina_Bool (*func)(void *data, Ecore_IMF_Context *ctx, char **text), const void *data); + +/** * Set the input mode used by the Ecore Input Context. * * The input mode can be one of the input modes defined in @@ -1044,6 +1058,28 @@ EAPI void *ecore_imf_context_data_get(Ecore_IMF_Context EAPI Eina_Bool ecore_imf_context_surrounding_get(Ecore_IMF_Context *ctx, char **text, int *cursor_pos); /** + * Retrieve the selected text. + * + * This function is implemented by calling the + * Ecore_IMF_Context::retrieve_selection_func ( + * set using #ecore_imf_context_retrieve_selection_callback_set). + * + * There is no obligation for a widget to respond to the + * retrieve_surrounding_func, so input methods must be prepared + * to function without context. + * + * @param ctx An #Ecore_IMF_Context. + * @param text Location to store a UTF-8 encoded string of the selected text. + * If the function returns @c EINA_TRUE, then you must free + * the result stored in this location with free(). + * @return @c EINA_TRUE if selected text was provided; otherwise + * @c EINA_FALSE. + * @ingroup Ecore_IMF_Context_Module_Group + * @since 1.9.0 + */ +EAPI Eina_Bool ecore_imf_context_selection_get(Ecore_IMF_Context *ctx, char **text); + +/** * Adds ECORE_IMF_EVENT_PREEDIT_START to the event queue. * * ECORE_IMF_EVENT_PREEDIT_START should be added when a new preedit sequence starts. diff --git a/src/lib/ecore_imf/ecore_imf_context.c b/src/lib/ecore_imf/ecore_imf_context.c index 63c41c8..7b554e6 100644 --- a/src/lib/ecore_imf/ecore_imf_context.c +++ b/src/lib/ecore_imf/ecore_imf_context.c @@ -462,6 +462,20 @@ ecore_imf_context_retrieve_surrounding_callback_set(Ecore_IMF_Context *ctx, Eina } EAPI void +ecore_imf_context_retrieve_selection_callback_set(Ecore_IMF_Context *ctx, Eina_Bool (*func)(void *data, Ecore_IMF_Context *ctx, char **text), const void *data) +{ + if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT)) + { + ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT, + "ecore_imf_context_retrieve_selection_callback_set"); + return; + } + + ctx->retrieve_selection_func = func; + ctx->retrieve_selection_data = (void *) data; +} + +EAPI void ecore_imf_context_input_mode_set(Ecore_IMF_Context *ctx, Ecore_IMF_Input_Mode input_mode) { if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT)) @@ -563,6 +577,29 @@ ecore_imf_context_surrounding_get(Ecore_IMF_Context *ctx, char **text, int *curs return result; } +EAPI Eina_Bool +ecore_imf_context_selection_get(Ecore_IMF_Context *ctx, char **text) +{ + Eina_Bool result = EINA_FALSE; + + if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT)) + { + ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT, + "ecore_imf_context_selection_get"); + return EINA_FALSE; + } + + if (ctx->retrieve_selection_func) + { + result = ctx->retrieve_selection_func(ctx->retrieve_selection_data, ctx, text); + if (!result) + { + if (text) *text = NULL; + } + } + return result; +} + static void _ecore_imf_event_free_preedit(void *data EINA_UNUSED, void *event) { diff --git a/src/lib/ecore_imf/ecore_imf_private.h b/src/lib/ecore_imf/ecore_imf_private.h index 81d71c9..d6bf257 100644 --- a/src/lib/ecore_imf/ecore_imf_private.h +++ b/src/lib/ecore_imf/ecore_imf_private.h @@ -56,6 +56,8 @@ struct _Ecore_IMF_Context Ecore_IMF_Input_Panel_Lang input_panel_lang; Ecore_IMF_Input_Panel_Return_Key_Type input_panel_return_key_type; int input_panel_layout_variation; + Eina_Bool (*retrieve_selection_func)(void *data, Ecore_IMF_Context *ctx, char **text); + void *retrieve_selection_data; Eina_Bool allow_prediction : 1; Eina_Bool input_panel_enabled : 1; Eina_Bool input_panel_return_key_disabled : 1; -- 2.7.4