From 7b9742f22e3d25a942d2e6e0f219d35049b28785 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 15 Sep 2017 16:18:15 +0900 Subject: [PATCH] ecore_imf: Add prediction hint hash APIs Change-Id: Id012fd172d3b15bfa3e9ea10c22216db10ba23b5 Signed-off-by: Jihoon Kim --- src/lib/ecore_imf/Ecore_IMF.h | 6 ++++ src/lib/ecore_imf/ecore_imf_context.c | 61 +++++++++++++++++++++++++++++++++++ src/lib/ecore_imf/ecore_imf_private.h | 1 + 3 files changed, 68 insertions(+) diff --git a/src/lib/ecore_imf/Ecore_IMF.h b/src/lib/ecore_imf/Ecore_IMF.h index 3fd5512..66b3f19 100644 --- a/src/lib/ecore_imf/Ecore_IMF.h +++ b/src/lib/ecore_imf/Ecore_IMF.h @@ -1991,6 +1991,12 @@ EAPI void ecore_imf_context_mime_type_accept_set(Ecore_I */ EAPI void ecore_imf_context_input_panel_position_set(Ecore_IMF_Context *ctx, int x, int y); +EAPI Eina_Bool ecore_imf_context_prediction_hint_hash_set(Ecore_IMF_Context *ctx, const char *key, const char *value); + +EAPI Eina_Bool ecore_imf_context_prediction_hint_hash_del(Ecore_IMF_Context *ctx, const char *key); + +EAPI const Eina_Hash *ecore_imf_context_prediction_hint_hash_get(Ecore_IMF_Context *ctx); + /* The following entry points must be exported by each input method module */ diff --git a/src/lib/ecore_imf/ecore_imf_context.c b/src/lib/ecore_imf/ecore_imf_context.c index e07ed7a..bbedd7d 100644 --- a/src/lib/ecore_imf/ecore_imf_context.c +++ b/src/lib/ecore_imf/ecore_imf_context.c @@ -226,6 +226,9 @@ ecore_imf_context_del(Ecore_IMF_Context *ctx) free(fn); } + if (ctx->prediction_hint_hash) + eina_hash_free(ctx->prediction_hint_hash); + ECORE_MAGIC_SET(ctx, ECORE_MAGIC_NONE); free(ctx); } @@ -1463,3 +1466,61 @@ ecore_imf_context_input_panel_position_set(Ecore_IMF_Context *ctx, int x, int y) if (ctx->klass->input_panel_position_set) ctx->klass->input_panel_position_set(ctx, x, y); } + +static void +_prediction_hint_hash_free_cb(void *data) +{ + free(data); +} + +EAPI Eina_Bool +ecore_imf_context_prediction_hint_hash_set(Ecore_IMF_Context *ctx, const char *key, const char *value) +{ + if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT)) + { + ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT, + "ecore_imf_context_prediction_hint_hash_set"); + return EINA_FALSE; + } + + if (!ctx->prediction_hint_hash) + ctx->prediction_hint_hash = eina_hash_string_superfast_new(_prediction_hint_hash_free_cb); + + if (!ctx->prediction_hint_hash) + return EINA_FALSE; + + char *old_value = eina_hash_set(ctx->prediction_hint_hash, key, value ? strdup(value) : strdup("")); + if (old_value) + free(old_value); + + return EINA_TRUE; +} + +EAPI Eina_Bool +ecore_imf_context_prediction_hint_hash_del(Ecore_IMF_Context *ctx, const char *key) +{ + if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT)) + { + ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT, + "ecore_imf_context_prediction_hint_hash_del"); + return EINA_FALSE; + } + + if (!ctx->prediction_hint_hash) + return EINA_FALSE; + + return eina_hash_del(ctx->prediction_hint_hash, key, NULL); +} + +EAPI const Eina_Hash * +ecore_imf_context_prediction_hint_hash_get(Ecore_IMF_Context *ctx) +{ + if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT)) + { + ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT, + "ecore_imf_context_prediction_hint_hash_get"); + return NULL; + } + + return ctx->prediction_hint_hash; +} diff --git a/src/lib/ecore_imf/ecore_imf_private.h b/src/lib/ecore_imf/ecore_imf_private.h index 611db42..22d2942 100644 --- a/src/lib/ecore_imf/ecore_imf_private.h +++ b/src/lib/ecore_imf/ecore_imf_private.h @@ -60,6 +60,7 @@ struct _Ecore_IMF_Context int input_panel_layout_variation; Eina_Bool (*retrieve_selection_func)(void *data, Ecore_IMF_Context *ctx, char **text); void *retrieve_selection_data; + Eina_Hash *prediction_hint_hash; Eina_Bool allow_prediction : 1; Eina_Bool input_panel_enabled : 1; Eina_Bool input_panel_return_key_disabled : 1; -- 2.7.4