diff --git a/ChangeLog b/ChangeLog index da95d22829..674f65df8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2013-04-13 Jihoon Kim * Ecore_IMF: Add ecore_imf_input_panel_hide () API + * Ecore_IMF: Add ecore_imf_context_input_panel_event_callback_call, clear API 2013-04-10 Rafael Antognolli diff --git a/NEWS b/NEWS index 8b0a81bba9..f49c5a2faf 100644 --- a/NEWS +++ b/NEWS @@ -93,6 +93,7 @@ Additions: * ecore_imf: - Add ecore_imf_context_input_panel_layout_variation_set/get API - Add ecore_imf_input_panel_hide API + - Add ecore_imf_context_input_panel_event_callback_call, clear API * Add edje_object_part_text_input_panel_layout_variation_set/get API * Evil: - Add mkdtemp. diff --git a/src/lib/ecore_imf/Ecore_IMF.h b/src/lib/ecore_imf/Ecore_IMF.h index 2eb81fdfbd..7e740c7d60 100644 --- a/src/lib/ecore_imf/Ecore_IMF.h +++ b/src/lib/ecore_imf/Ecore_IMF.h @@ -1474,6 +1474,28 @@ EAPI void ecore_imf_context_input_panel_event_callback_ */ EAPI void ecore_imf_context_input_panel_event_callback_del(Ecore_IMF_Context *ctx, Ecore_IMF_Input_Panel_Event type, void (*func) (void *data, Ecore_IMF_Context *ctx, int value)); +/** + * Call a given input panel callback on the context @p ctx. + * + * @param ctx Ecore_IMF_Context. + * @param type The type of event that will trigger the callback + * @param value the event value + * @ingroup Ecore_IMF_Context_Group + * @since 1.8.0 + */ +EAPI void ecore_imf_context_input_panel_event_callback_call(Ecore_IMF_Context *ctx, Ecore_IMF_Input_Panel_Event type, int value); + +/** + * Delete all input panel callback on the context @p ctx. + * + * Delete all input panel callback to be registered by ecore_imf_context_input_panel_event_callback_add() + * + * @param ctx Ecore_IMF_Context. + * @ingroup Ecore_IMF_Context_Group + * @since 1.8.0 + */ +EAPI void ecore_imf_context_input_panel_event_callback_clear(Ecore_IMF_Context *ctx); + /** * Get the current language locale of the input panel. * diff --git a/src/lib/ecore_imf/ecore_imf_context.c b/src/lib/ecore_imf/ecore_imf_context.c index 7c8318e547..f1e88211c7 100644 --- a/src/lib/ecore_imf/ecore_imf_context.c +++ b/src/lib/ecore_imf/ecore_imf_context.c @@ -190,6 +190,12 @@ ecore_imf_context_del(Ecore_IMF_Context *ctx) free(fn); } + if (ctx->input_panel_callbacks) + { + EINA_LIST_FREE(ctx->input_panel_callbacks, fn) + free(fn); + } + ECORE_MAGIC_SET(ctx, ECORE_MAGIC_NONE); free(ctx); } @@ -268,7 +274,6 @@ ecore_imf_context_hide(Ecore_IMF_Context *ctx) return; } - show_req_ctx = NULL; if (ctx->klass->hide) ctx->klass->hide(ctx); } @@ -792,7 +797,6 @@ ecore_imf_context_input_panel_hide(Ecore_IMF_Context *ctx) return; } - show_req_ctx = NULL; if (ctx->klass->hide) ctx->klass->hide(ctx); } @@ -1060,6 +1064,8 @@ ecore_imf_context_input_panel_event_callback_add(Ecore_IMF_Context *ctx, void (*func) (void *data, Ecore_IMF_Context *ctx, int value), const void *data) { + Ecore_IMF_Input_Panel_Callback_Node *fn = NULL; + if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT)) { ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT, @@ -1067,8 +1073,16 @@ ecore_imf_context_input_panel_event_callback_add(Ecore_IMF_Context *ctx, return; } - if (ctx->klass->input_panel_event_callback_add) - ctx->klass->input_panel_event_callback_add(ctx, type, func, (void *)data); + if (!func) return; + + fn = calloc(1, sizeof (Ecore_IMF_Input_Panel_Callback_Node)); + if (!fn) return; + + fn->func = func; + fn->data = data; + fn->type = type; + + ctx->input_panel_callbacks = eina_list_append(ctx->input_panel_callbacks, fn); } EAPI void @@ -1076,6 +1090,10 @@ ecore_imf_context_input_panel_event_callback_del(Ecore_IMF_Context *ctx, Ecore_IMF_Input_Panel_Event type, void (*func) (void *data, Ecore_IMF_Context *ctx, int value)) { + Eina_List *l = NULL; + Eina_List *l_next = NULL; + Ecore_IMF_Input_Panel_Callback_Node *fn = NULL; + if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT)) { ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT, @@ -1083,8 +1101,70 @@ ecore_imf_context_input_panel_event_callback_del(Ecore_IMF_Context *ctx, return; } - if (ctx->klass->input_panel_event_callback_del) - ctx->klass->input_panel_event_callback_del(ctx, type, func); + if (!func) return; + if (!ctx->input_panel_callbacks) return; + + EINA_LIST_FOREACH_SAFE(ctx->input_panel_callbacks, l, l_next, fn) + { + if ((fn) && (fn->func == func) && (fn->type == type)) + { + free(fn); + ctx->input_panel_callbacks = eina_list_remove_list(ctx->input_panel_callbacks, l); + return; + } + } +} + +EAPI void +ecore_imf_context_input_panel_event_callback_call(Ecore_IMF_Context *ctx, Ecore_IMF_Input_Panel_Event type, int value) +{ + Ecore_IMF_Input_Panel_Callback_Node *fn = NULL; + Eina_List *l = NULL; + + if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT)) + { + ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT, + "ecore_imf_context_input_panel_event_callback_call"); + return; + } + + EINA_LIST_FOREACH(ctx->input_panel_callbacks, l, fn) + { + if ((fn) && (fn->type == type) && (fn->func)) + { + fn->func(fn->data, ctx, value); + if (type == ECORE_IMF_INPUT_PANEL_STATE_EVENT && + value == ECORE_IMF_INPUT_PANEL_STATE_HIDE && + show_req_ctx == ctx) + show_req_ctx = NULL; + } + } +} + +EAPI void +ecore_imf_context_input_panel_event_callback_clear(Ecore_IMF_Context *ctx) +{ + Ecore_IMF_Input_Panel_Callback_Node *fn = NULL; + Eina_List *l = NULL; + + if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT)) + { + ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT, + "ecore_imf_context_input_panel_event_callback_clear"); + return; + } + + for (l = ctx->input_panel_callbacks; l;) + { + fn = (Ecore_IMF_Input_Panel_Callback_Node *)l->data; + + if (fn) + { + ctx->input_panel_callbacks = eina_list_remove(ctx->input_panel_callbacks, fn); + free (fn); + } + l = l->next; + } } EAPI void diff --git a/src/lib/ecore_imf/ecore_imf_private.h b/src/lib/ecore_imf/ecore_imf_private.h index 7452bd784f..b63500afec 100644 --- a/src/lib/ecore_imf/ecore_imf_private.h +++ b/src/lib/ecore_imf/ecore_imf_private.h @@ -36,6 +36,7 @@ extern int _ecore_imf_log_dom; typedef struct _Ecore_IMF_Module Ecore_IMF_Module; typedef struct _Ecore_IMF_Func_Node Ecore_IMF_Func_Node; +typedef struct _Ecore_IMF_Input_Panel_Callback_Node Ecore_IMF_Input_Panel_Callback_Node; struct _Ecore_IMF_Context { @@ -49,6 +50,7 @@ struct _Ecore_IMF_Context Eina_Bool (*retrieve_surrounding_func)(void *data, Ecore_IMF_Context *ctx, char **text, int *cursor_pos); void *retrieve_surrounding_data; Eina_List *callbacks; + Eina_List *input_panel_callbacks; Ecore_IMF_Autocapital_Type autocapital_type; Ecore_IMF_Input_Panel_Layout input_panel_layout; Ecore_IMF_Input_Panel_Lang input_panel_lang; @@ -74,6 +76,13 @@ struct _Ecore_IMF_Func_Node Ecore_IMF_Callback_Type type; }; +struct _Ecore_IMF_Input_Panel_Callback_Node +{ + void (*func) (); + const void *data; + Ecore_IMF_Input_Panel_Event type; +}; + void ecore_imf_module_init(void); void ecore_imf_module_shutdown(void); Eina_List *ecore_imf_module_available_get(void);