diff --git a/src/lib/ecore_imf/Ecore_IMF.h b/src/lib/ecore_imf/Ecore_IMF.h index ee1c24919d..2d96a22ab0 100644 --- a/src/lib/ecore_imf/Ecore_IMF.h +++ b/src/lib/ecore_imf/Ecore_IMF.h @@ -907,6 +907,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. * @@ -1043,6 +1057,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. * diff --git a/src/lib/ecore_imf/ecore_imf_context.c b/src/lib/ecore_imf/ecore_imf_context.c index 63c41c8d02..7b554e6b53 100644 --- a/src/lib/ecore_imf/ecore_imf_context.c +++ b/src/lib/ecore_imf/ecore_imf_context.c @@ -461,6 +461,20 @@ ecore_imf_context_retrieve_surrounding_callback_set(Ecore_IMF_Context *ctx, Eina ctx->retrieve_surrounding_data = (void *) data; } +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) { @@ -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 81d71c9263..d6bf257efc 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;