summaryrefslogtreecommitdiff
path: root/legacy/ecore/src/lib/ecore_imf/ecore_imf_context.c
diff options
context:
space:
mode:
authorJihoon Kim <imfine98@gmail.com>2012-01-18 04:38:04 +0000
committerCarsten Haitzler <raster@rasterman.com>2012-01-18 04:38:04 +0000
commitc652e4e78a89999aaa76769aac8d7f600368ab50 (patch)
tree59c15627a774d61447816b2c4ffa9487941f943e /legacy/ecore/src/lib/ecore_imf/ecore_imf_context.c
parent537bc81acbdef82c74b2887ef3becf90c48c8483 (diff)
From: Jihoon Kim <imfine98@gmail.com>
Long time ago, in http://www.mail-archive.com/enlightenment-devel@lists.sourceforge.net/msg32795.html mail thread and IRC, I talked with about problem of asynchronous event API such as ecore_imf_context_commit_event_add, ecore_imf_context_preedit_changed_event_add, so on. In short, The problem is that key event and text_set APIs are processed immediately, but commit event and preedit changed event is processed asynchronously because those APIs add each event to ecore event queue. To fix these problems, I've decided to create synchronous event APIs such as ecore_imf_context_event_callback_add, del and call. For considering compatibility, sync and async event callback functions are used in xim and scim immodule. SVN revision: 67290
Diffstat (limited to '')
-rw-r--r--legacy/ecore/src/lib/ecore_imf/ecore_imf_context.c137
1 files changed, 137 insertions, 0 deletions
diff --git a/legacy/ecore/src/lib/ecore_imf/ecore_imf_context.c b/legacy/ecore/src/lib/ecore_imf/ecore_imf_context.c
index a96e701a59..b65ee26352 100644
--- a/legacy/ecore/src/lib/ecore_imf/ecore_imf_context.c
+++ b/legacy/ecore/src/lib/ecore_imf/ecore_imf_context.c
@@ -223,6 +223,8 @@ ecore_imf_context_info_get(Ecore_IMF_Context *ctx)
223EAPI void 223EAPI void
224ecore_imf_context_del(Ecore_IMF_Context *ctx) 224ecore_imf_context_del(Ecore_IMF_Context *ctx)
225{ 225{
226 Ecore_IMF_Func_Node *fn;
227
226 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT)) 228 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
227 { 229 {
228 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT, 230 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
@@ -230,6 +232,13 @@ ecore_imf_context_del(Ecore_IMF_Context *ctx)
230 return; 232 return;
231 } 233 }
232 if (ctx->klass->del) ctx->klass->del(ctx); 234 if (ctx->klass->del) ctx->klass->del(ctx);
235
236 if (ctx->callbacks)
237 {
238 EINA_LIST_FREE(ctx->callbacks, fn)
239 free(fn);
240 }
241
233 ECORE_MAGIC_SET(ctx, ECORE_MAGIC_NONE); 242 ECORE_MAGIC_SET(ctx, ECORE_MAGIC_NONE);
234 free(ctx); 243 free(ctx);
235} 244}
@@ -1016,6 +1025,134 @@ ecore_imf_context_delete_surrounding_event_add(Ecore_IMF_Context *ctx, int offse
1016} 1025}
1017 1026
1018/** 1027/**
1028 * Add (register) a callback function to a given context event.
1029 *
1030 * This function adds a function callback to the context @p ctx when the
1031 * event of type @p type occurs on it. The function pointer is @p
1032 * func.
1033 *
1034 * The event type @p type to trigger the function may be one of
1035 * #ECORE_IMF_CALLBACK_PREEDIT_START, #ECORE_IMF_CALLBACK_PREEDIT_END,
1036 * #ECORE_IMF_CALLBACK_PREEDIT_CHANGED, #ECORE_IMF_CALLBACK_COMMIT and
1037 * #ECORE_IMF_CALLBACK_DELETE_SURROUNDING.
1038 *
1039 * @param ctx Ecore_IMF_Context to attach a callback to.
1040 * @param type The type of event that will trigger the callback
1041 * @param func The (callback) function to be called when the event is
1042 * triggered
1043 * @param data The data pointer to be passed to @p func
1044 * @ingroup Ecore_IMF_Context_Module_Group
1045 * @since 1.2.0
1046 */
1047EAPI void
1048ecore_imf_context_event_callback_add(Ecore_IMF_Context *ctx, Ecore_IMF_Callback_Type type, Ecore_IMF_Event_Cb func, const void *data)
1049{
1050 Ecore_IMF_Func_Node *fn = NULL;
1051
1052 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1053 {
1054 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1055 "ecore_imf_context_event_callback_add");
1056 return;
1057 }
1058
1059 if (!func) return;
1060
1061 fn = calloc(1, sizeof (Ecore_IMF_Func_Node));
1062 if (!fn) return;
1063
1064 fn->func = func;
1065 fn->data = data;
1066 fn->type = type;
1067
1068 ctx->callbacks = eina_list_append(ctx->callbacks, fn);
1069}
1070
1071/**
1072 * Delete (unregister) a callback function registered to a given
1073 * context event.
1074 *
1075 * This function removes a function callback from the context @p ctx when the
1076 * event of type @p type occurs on it. The function pointer is @p
1077 * func.
1078 *
1079 * @see ecore_imf_context_event_callback_add() for more details
1080 *
1081 * @param ctx Ecore_IMF_Context to remove a callback from.
1082 * @param type The type of event that was trigerring the callback
1083 * @param func The (callback) function that was to be called when the event was triggered
1084 * @return the data pointer
1085 * @ingroup Ecore_IMF_Context_Module_Group
1086 * @since 1.2.0
1087 */
1088EAPI void *
1089ecore_imf_context_event_callback_del(Ecore_IMF_Context *ctx, Ecore_IMF_Callback_Type type, Ecore_IMF_Event_Cb func)
1090{
1091 Eina_List *l = NULL;
1092 Eina_List *l_next = NULL;
1093 Ecore_IMF_Func_Node *fn = NULL;
1094
1095 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1096 {
1097 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1098 "ecore_imf_context_event_callback_del");
1099 return;
1100 }
1101
1102 if (!func) return NULL;
1103 if (!ctx->callbacks) return NULL;
1104
1105 EINA_LIST_FOREACH_SAFE(ctx->callbacks, l, l_next, fn)
1106 {
1107 if ((fn) && (fn->func == func) && (fn->type == type))
1108 {
1109 void *tmp = fn->data;
1110 free(fn);
1111 ctx->callbacks = eina_list_remove_list(ctx->callbacks, l);
1112 return tmp;
1113 }
1114 }
1115 return NULL;
1116}
1117
1118/**
1119 * Call a given callback on the context @p ctx.
1120 *
1121 * ecore_imf_context_preedit_start_event_add, ecore_imf_context_preedit_end_event_add,
1122 * ecore_imf_context_preedit_changed_event_add, ecore_imf_context_commit_event_add and
1123 * ecore_imf_context_delete_surrounding_event_add APIs are asynchronous
1124 * because those API adds each event to the event queue.
1125 *
1126 * This API provides the way to call each callback function immediately.
1127 *
1128 * @param ctx Ecore_IMF_Context.
1129 * @param type The type of event that will trigger the callback
1130 * @param event_info The pointer to event specific struct or information to
1131 * pass to the callback functions registered on this event
1132 * @ingroup Ecore_IMF_Context_Module_Group
1133 * @since 1.2.0
1134 */
1135EAPI void
1136ecore_imf_context_event_callback_call(Ecore_IMF_Context *ctx, Ecore_IMF_Callback_Type type, void *event_info)
1137{
1138 Ecore_IMF_Func_Node *fn = NULL;
1139 Eina_List *l = NULL;
1140
1141 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1142 {
1143 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1144 "ecore_imf_context_event_callback_call");
1145 return;
1146 }
1147
1148 EINA_LIST_FOREACH(ctx->callbacks, l, fn)
1149 {
1150 if ((fn) && (fn->type == type) && (fn->func))
1151 fn->func(fn->data, ctx, event_info);
1152 }
1153}
1154
1155/**
1019 * Ask the Input Method Context to show the control panel of using Input Method. 1156 * Ask the Input Method Context to show the control panel of using Input Method.
1020 * 1157 *
1021 * @param ctx An #Ecore_IMF_Context. 1158 * @param ctx An #Ecore_IMF_Context.