ecore_imf: Add prediction hint hash APIs

Change-Id: Id012fd172d3b15bfa3e9ea10c22216db10ba23b5
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
This commit is contained in:
Jihoon Kim 2017-09-15 16:18:15 +09:00
parent 9e8bd48e70
commit 4262c33bfc
3 changed files with 106 additions and 1 deletions

View File

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

View File

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

View File

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