Add ecore_imf_context_selection_get API to allow Input Method to get the selected text.

This commit is contained in:
Jihoon Kim 2014-01-23 10:44:00 +09:00
parent 1c2da046dc
commit fa165f0902
3 changed files with 75 additions and 0 deletions

View File

@ -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.
*

View File

@ -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)
{

View File

@ -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;