diff --git a/src/lib/ecore_imf/Ecore_IMF.h b/src/lib/ecore_imf/Ecore_IMF.h index 92c1bc6eac..0fc821da2f 100644 --- a/src/lib/ecore_imf/Ecore_IMF.h +++ b/src/lib/ecore_imf/Ecore_IMF.h @@ -1987,6 +1987,49 @@ 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); +/** + * @ingroup Ecore_IMF_Context_Group + * @brief Sets the prediction hint data at the specified key + * + * @since 1.21.0 + * + * @param[in] ctx An #Ecore_IMF_Context + * @param key The key of the prediction hint + * @param data The data to replace + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise + * + * This function modifies the data of @p key with @p data in the hash associated @p + * ctx. If no entry is found, @p data is added to the hash associated @p ctx with the + * key @p key. On success this function returns EINA_TRUE, + * otherwise it returns @c EINA_FALSE. + */ +EAPI Eina_Bool ecore_imf_context_prediction_hint_hash_set(Ecore_IMF_Context *ctx, const char *key, const char *value); + +/** + * @ingroup Ecore_IMF_Context_Group + * @brief Removes the prediction hint data identified by a key + * + * @since 1.21.0 + * + * @param[in] ctx An #Ecore_IMF_Context + * @param key The key of the prediction hint + * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise + * + * This function removes the entry identified by @p key from the hash associated @p ctx. + */ +EAPI Eina_Bool ecore_imf_context_prediction_hint_hash_del(Ecore_IMF_Context *ctx, const char *key); + +/** + * @ingroup Ecore_IMF_Context_Group + * @brief Gets the hash table of prediction hint data + * + * @since 1.21.0 + * + * @param[in] ctx An #Ecore_IMF_Context + * @return The prediction hint hash table + */ +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 1b34e0c01f..a04708fa8d 100644 --- a/src/lib/ecore_imf/ecore_imf_context.c +++ b/src/lib/ecore_imf/ecore_imf_context.c @@ -224,6 +224,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); } @@ -1460,4 +1463,62 @@ 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); -} \ No newline at end of file +} + +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 611db426e7..22d2942109 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;