ecedcfb0e6a64f9c811ca75fb3aba0bf5573a2f5
[profile/ivi/ecore.git] / src / lib / ecore_imf / ecore_imf_context.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <locale.h>
9
10 #include <Ecore.h>
11 #include <ecore_private.h>
12
13 #include "Ecore_IMF.h"
14 #include "ecore_imf_private.h"
15
16 /**
17  * @defgroup Ecore_IMF_Context_Group Ecore Input Method Context Functions
18  *
19  * Functions that operate on Ecore Input Method Context objects.
20  */
21
22 /**
23  * Get the list of the available Input Method Context ids.
24  *
25  * Note that the caller is responsible for freeing the Eina_List
26  * when finished with it. There is no need to finish the list strings.
27  *
28  * @return Return an Eina_List of strings;
29  *         on failure it returns NULL.
30  * @ingroup Ecore_IMF_Context_Group
31  */
32 EAPI Eina_List *
33 ecore_imf_context_available_ids_get(void)
34 {
35    return ecore_imf_module_context_ids_get();
36 }
37
38 EAPI Eina_List *
39 ecore_imf_context_available_ids_by_canvas_type_get(const char *canvas_type)
40 {
41    return ecore_imf_module_context_ids_by_canvas_type_get(canvas_type);
42 }
43
44 /*
45  * Match @locale against @against.
46  *
47  * 'en_US' against 'en_US'       => 4
48  * 'en_US' against 'en'          => 3
49  * 'en', 'en_UK' against 'en_US' => 2
50  *  all locales, against '*'     => 1
51  */
52 static int
53 _ecore_imf_context_match_locale(const char *locale, const char *against, int against_len)
54 {
55   if (strcmp(against, "*") == 0)
56     return 1;
57
58   if (strcasecmp(locale, against) == 0)
59     return 4;
60
61   if (strncasecmp(locale, against, 2) == 0)
62     return (against_len == 2) ? 3 : 2;
63
64   return 0;
65 }
66
67 /**
68  * Get the id of the default Input Method Context.
69  * The id may to used to create a new instance of an Input Method
70  * Context object.
71  *
72  * @return Return a string containing the id of the default Input
73  *         Method Context; on failure it returns NULL.
74  * @ingroup Ecore_IMF_Context_Group
75  */
76 EAPI const char *
77 ecore_imf_context_default_id_get(void)
78 {
79    return ecore_imf_context_default_id_by_canvas_type_get(NULL);
80 }
81
82 EAPI const char *
83 ecore_imf_context_default_id_by_canvas_type_get(const char *canvas_type)
84 {
85    const char *id;
86    Eina_List *modules;
87    Ecore_IMF_Module *module;
88    char *locale;
89    char *tmp;
90    int best_goodness = 0;
91
92    id = getenv("ECORE_IMF_MODULE");
93    if (id)
94      {
95         if (strcmp(id, "none") == 0) return NULL;
96         if (ecore_imf_module_get(id)) return id;
97      }
98
99    modules = ecore_imf_module_available_get();
100    if (!modules) return NULL;
101
102    locale = setlocale(LC_CTYPE, NULL);
103    if (!locale) return NULL;
104
105    locale = strdup(locale);
106
107    tmp = strchr(locale, '.');
108    if (tmp) *tmp = '\0';
109    tmp = strchr(locale, '@');
110    if (tmp) *tmp = '\0';
111
112    id = NULL;
113
114    EINA_LIST_FREE(modules, module)
115      {
116         if (canvas_type &&
117             strcmp(module->info->canvas_type, canvas_type) == 0)
118           continue;
119
120         const char *p = module->info->default_locales;
121         while (p)
122           {
123              const char *q = strchr(p, ':');
124              int goodness = _ecore_imf_context_match_locale(locale, p, q ? (size_t)(q - p) : strlen (p));
125
126               if (goodness > best_goodness)
127                 {
128                    id = module->info->id;
129                    best_goodness = goodness;
130                 }
131
132               p = q ? q + 1 : NULL;
133           }
134      }
135
136    free(locale);
137    return id;
138 }
139
140 /**
141  * Retrieve the info for the Input Method Context with @p id.
142  *
143  * @param id The Input Method Context id to query for.
144  * @return Return a #Ecore_IMF_Context_Info for the Input Method Context with @p id;
145  *         on failure it returns NULL.
146  * @ingroup Ecore_IMF_Context_Group
147  */
148 EAPI const Ecore_IMF_Context_Info *
149 ecore_imf_context_info_by_id_get(const char *id)
150 {
151    Ecore_IMF_Module *module;
152
153    if (!id) return NULL;
154    module = ecore_imf_module_get(id);
155    if (!module) return NULL;
156    return module->info;
157 }
158
159 /**
160  * Create a new Input Method Context defined by the given id.
161  *
162  * @param id The Input Method Context id.
163  * @return A newly allocated Input Method Context;
164  *         on failure it returns NULL.
165  * @ingroup Ecore_IMF_Context_Group
166  */
167 EAPI Ecore_IMF_Context *
168 ecore_imf_context_add(const char *id)
169 {
170    Ecore_IMF_Context *ctx;
171
172    if (!id) return NULL;
173    ctx = ecore_imf_module_context_create(id);
174    if (!ctx || !ctx->klass) return NULL;
175    if (ctx->klass->add) ctx->klass->add(ctx);
176    /* default use_preedit is EINA_TRUE, so let's make sure it's
177     * set on the immodule */
178    ecore_imf_context_use_preedit_set(ctx, EINA_TRUE);
179    /* default input_mode is ECORE_IMF_INPUT_MODE_FULL, so let's make sure it's
180     * set on the immodule */
181    ecore_imf_context_input_mode_set(ctx, ECORE_IMF_INPUT_MODE_FULL);
182    return ctx;
183 }
184
185 /**
186  * Retrieve the info for the given Input Method Context.
187  *
188  * @param ctx An #Ecore_IMF_Context.
189  * @return Return a #Ecore_IMF_Context_Info for the given Input Method Context;
190  *         on failure it returns NULL.
191  * @ingroup Ecore_IMF_Context_Group
192  */
193 EAPI const Ecore_IMF_Context_Info *
194 ecore_imf_context_info_get(Ecore_IMF_Context *ctx)
195 {
196    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
197      {
198         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
199                          "ecore_imf_context_info_get");
200         return NULL;
201      }
202    return ctx->module->info;
203 }
204
205 /**
206  * Delete the given Input Method Context and free its memory.
207  *
208  * @param ctx An #Ecore_IMF_Context.
209  * @ingroup Ecore_IMF_Context_Group
210  */
211 EAPI void
212 ecore_imf_context_del(Ecore_IMF_Context *ctx)
213 {
214    void *data;
215    Ecore_IMF_Input_Panel_State state;
216
217    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
218      {
219         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
220                          "ecore_imf_context_del");
221         return;
222      }
223
224    state = ecore_imf_context_input_panel_state_get(ctx);
225
226    if (state == ECORE_IMF_INPUT_PANEL_STATE_SHOW)
227        ecore_imf_context_input_panel_hide(ctx);
228
229    if (ctx->klass->del) ctx->klass->del(ctx);
230    ECORE_MAGIC_SET(ctx, ECORE_MAGIC_NONE);
231
232    EINA_LIST_FREE(ctx->private_key_list, data)
233       free(data);
234
235    EINA_LIST_FREE(ctx->disabled_key_list, data)
236       free(data);
237
238    EINA_LIST_FREE(ctx->callbacks, data)
239       free(data);
240
241    ctx->private_key_list = NULL;
242    ctx->disabled_key_list = NULL;
243    ctx->callbacks = NULL;
244
245    free(ctx);
246 }
247
248 /**
249  * Set the client window for the Input Method Context; this is the
250  * Ecore_X_Window when using X11, Ecore_Win32_Window when using Win32, etc.
251  * This window is used in order to correctly position status windows, and may
252  * also be used for purposes internal to the Input Method Context.
253  *
254  * @param ctx An #Ecore_IMF_Context.
255  * @param window The client window. This may be NULL to indicate
256  *               that the previous client window no longer exists.
257  * @ingroup Ecore_IMF_Context_Group
258  */
259 EAPI void
260 ecore_imf_context_client_window_set(Ecore_IMF_Context *ctx, void *window)
261 {
262    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
263      {
264         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
265                          "ecore_imf_context_client_window_set");
266         return;
267      }
268    if (ctx->klass->client_window_set) ctx->klass->client_window_set(ctx, window);
269    ctx->window = window;
270 }
271
272 EAPI void*
273 ecore_imf_context_client_window_get(Ecore_IMF_Context *ctx)
274 {
275    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
276      {
277         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
278                          "ecore_imf_context_client_window_get");
279         return NULL;
280      }
281    return ctx->window;
282 }
283
284 /**
285  * Set the client canvas for the Input Method Context; this is the
286  * canvas in which the input appears.
287  * The canvas type can be determined by using the context canvas type.
288  * Actually only canvas with type "evas" (Evas *) is supported.
289  * This canvas may be used in order to correctly position status windows, and may
290  * also be used for purposes internal to the Input Method Context.
291  *
292  * @param ctx An #Ecore_IMF_Context.
293  * @param canvas The client canvas. This may be NULL to indicate
294  *               that the previous client canvas no longer exists.
295  * @ingroup Ecore_IMF_Context_Group
296  */
297 EAPI void
298 ecore_imf_context_client_canvas_set(Ecore_IMF_Context *ctx, void *canvas)
299 {
300    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
301      {
302         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
303                          "ecore_imf_context_client_canvas_set");
304         return;
305      }
306    if (ctx->klass->client_canvas_set) ctx->klass->client_canvas_set(ctx, canvas);
307    ctx->client_canvas = canvas;
308 }
309
310 EAPI void*
311 ecore_imf_context_client_canvas_get(Ecore_IMF_Context *ctx)
312 {
313    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
314      {
315         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
316                          "ecore_imf_context_client_canvas_get");
317         return NULL;
318      }
319    return ctx->client_canvas;
320 }
321
322 /**
323  * Ask the Input Method Context to show itself.
324  *
325  * @param ctx An #Ecore_IMF_Context.
326  * @ingroup Ecore_IMF_Context_Group
327  */
328 EINA_DEPRECATED EAPI void
329 ecore_imf_context_show(Ecore_IMF_Context *ctx)
330 {
331    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
332      {
333         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
334                          "ecore_imf_context_show");
335         return;
336      }
337    if (ctx->klass->show) ctx->klass->show(ctx);
338 }
339
340 /**
341  * Ask the Input Method Context to hide itself.
342  *
343  * @param ctx An #Ecore_IMF_Context.
344  * @ingroup Ecore_IMF_Context_Group
345  */
346 EINA_DEPRECATED EAPI void
347 ecore_imf_context_hide(Ecore_IMF_Context *ctx)
348 {
349    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
350      {
351         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
352                          "ecore_imf_context_hide");
353         return;
354      }
355    if (ctx->klass->hide) ctx->klass->hide(ctx);
356 }
357
358 /**
359  * Retrieve the current preedit string and cursor position
360  * for the Input Method Context.
361  *
362  * @param ctx An #Ecore_IMF_Context.
363  * @param str Location to store the retrieved string. The
364  *            string retrieved must be freed with free().
365  * @param cursor_pos Location to store position of cursor (in characters)
366  *                   within the preedit string.
367  * @ingroup Ecore_IMF_Context_Group
368  */
369 EAPI void
370 ecore_imf_context_preedit_string_get(Ecore_IMF_Context *ctx, char **str, int *cursor_pos)
371 {
372    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
373      {
374         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
375                          "ecore_imf_context_preedit_string_get");
376         return;
377      }
378    if (ctx->klass->preedit_string_get)
379      ctx->klass->preedit_string_get(ctx, str, cursor_pos);
380    else
381      {
382         if (str) *str = strdup("");
383         if (cursor_pos) *cursor_pos = 0;
384      }
385 }
386
387 EAPI void
388 ecore_imf_context_preedit_string_with_attributes_get(Ecore_IMF_Context *ctx, char **str, Eina_List **attrs, int *cursor_pos)
389 {
390    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
391      {
392         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
393                          "ecore_imf_context_preedit_string_with_attributes_get");
394         return;
395      }
396    if (ctx->klass->preedit_string_with_attributes_get)
397      ctx->klass->preedit_string_with_attributes_get(ctx, str, attrs, cursor_pos);
398    else
399      {
400         if (str) *str = strdup("");
401         if (attrs) *attrs = NULL;
402         if (cursor_pos) *cursor_pos = 0;
403      }
404 }
405
406 /**
407  * Notify the Input Method Context that the widget to which its
408  * correspond has gained focus.
409  *
410  * @param ctx An #Ecore_IMF_Context.
411  * @ingroup Ecore_IMF_Context_Group
412  */
413 EAPI void
414 ecore_imf_context_focus_in(Ecore_IMF_Context *ctx)
415 {
416    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
417      {
418         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
419                          "ecore_imf_context_focus_in");
420         return;
421      }
422    if (ctx->klass->focus_in) ctx->klass->focus_in(ctx);
423 }
424
425 /**
426  * Notify the Input Method Context that the widget to which its
427  * correspond has lost focus.
428  *
429  * @param ctx An #Ecore_IMF_Context.
430  * @ingroup Ecore_IMF_Context_Group
431  */
432 EAPI void
433 ecore_imf_context_focus_out(Ecore_IMF_Context *ctx)
434 {
435    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
436      {
437         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
438                          "ecore_imf_context_focus_out");
439         return;
440      }
441    if (ctx->klass->focus_out) ctx->klass->focus_out(ctx);
442 }
443
444 /**
445  * Notify the Input Method Context that a change such as a
446  * change in cursor position has been made. This will typically
447  * cause the Input Method Context to clear the preedit state.
448  *
449  * @param ctx An #Ecore_IMF_Context.
450  * @ingroup Ecore_IMF_Context_Group
451  */
452 EAPI void
453 ecore_imf_context_reset(Ecore_IMF_Context *ctx)
454 {
455    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
456      {
457         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
458                          "ecore_imf_context_reset");
459         return;
460      }
461    if (ctx->klass->reset) ctx->klass->reset(ctx);
462 }
463
464 /**
465  * Notify the Input Method Context that a change in the cursor
466  * position has been made.
467  *
468  * @param ctx An #Ecore_IMF_Context.
469  * @param cursor_pos New cursor position in characters.
470  * @ingroup Ecore_IMF_Context_Group
471  */
472 EAPI void
473 ecore_imf_context_cursor_position_set(Ecore_IMF_Context *ctx, int cursor_pos)
474 {
475    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
476      {
477         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
478                          "ecore_imf_context_cursor_position_set");
479         return;
480      }
481    if (ctx->klass->cursor_position_set) ctx->klass->cursor_position_set(ctx, cursor_pos);
482 }
483
484 /**
485  * Set whether the IM context should use the preedit string
486  * to display feedback. If @use_preedit is EINA_FALSE (default
487  * is EINA_TRUE), then the IM context may use some other method to display
488  * feedback, such as displaying it in a child of the root window.
489  *
490  * @param ctx An #Ecore_IMF_Context.
491  * @param use_preedit Whether the IM context should use the preedit string.
492  * @ingroup Ecore_IMF_Context_Group
493  */
494 EAPI void
495 ecore_imf_context_use_preedit_set(Ecore_IMF_Context *ctx, Eina_Bool use_preedit)
496 {
497    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
498      {
499         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
500                          "ecore_imf_context_use_preedit_set");
501         return;
502      }
503    if (ctx->klass->use_preedit_set) ctx->klass->use_preedit_set(ctx, use_preedit);
504 }
505
506 /**
507  * Set the callback to be used on get_surrounding request.
508  *
509  * This callback will be called when the Input Method Context
510  * module requests the surrounding context.
511  *
512  * @param ctx An #Ecore_IMF_Context.
513  * @param func The callback to be called.
514  * @param data The data pointer to be passed to @p func
515  * @ingroup Ecore_IMF_Context_Group
516  */
517 EAPI void
518 ecore_imf_context_retrieve_surrounding_callback_set(Ecore_IMF_Context *ctx, Eina_Bool (*func)(void *data, Ecore_IMF_Context *ctx, char **text, int *cursor_pos), const void *data)
519 {
520    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
521      {
522         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
523                          "ecore_imf_context_retrieve_surrounding_callback_set");
524         return;
525      }
526
527    ctx->retrieve_surrounding_func = func;
528    ctx->retrieve_surrounding_data = (void *) data;
529 }
530
531 /**
532  * Set the input mode used by the Ecore Input Context.
533  *
534  * The input mode can be one of the input modes defined in
535  * #Ecore_IMF_Input_Mode. The default input mode is
536  * ECORE_IMF_INPUT_MODE_FULL.
537  *
538  * @param ctx An #Ecore_IMF_Context.
539  * @param input_mode The input mode to be used by @p ctx.
540  * @ingroup Ecore_IMF_Context_Group
541  */
542 EINA_DEPRECATED EAPI void
543 ecore_imf_context_input_mode_set(Ecore_IMF_Context *ctx, Ecore_IMF_Input_Mode input_mode)
544 {
545    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
546      {
547         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
548                          "ecore_imf_context_input_mode_set");
549         return;
550      }
551    if (ctx->klass->input_mode_set) ctx->klass->input_mode_set(ctx, input_mode);
552    ctx->input_mode = input_mode;
553 }
554
555 /**
556  * Get the input mode being used by the Ecore Input Context.
557  *
558  * See @ref ecore_imf_context_input_mode_set for more details.
559  *
560  * @param ctx An #Ecore_IMF_Context.
561  * @return The input mode being used by @p ctx.
562  * @ingroup Ecore_IMF_Context_Group
563  */
564 EINA_DEPRECATED EAPI Ecore_IMF_Input_Mode
565 ecore_imf_context_input_mode_get(Ecore_IMF_Context *ctx)
566 {
567    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
568      {
569         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
570                          "ecore_imf_context_input_mode_set");
571         return 0;
572      }
573    return ctx->input_mode;
574 }
575
576 /**
577  * Allow an Ecore Input Context to internally handle an event.
578  * If this function returns EINA_TRUE, then no further processing
579  * should be done for this event.
580  *
581  * Input methods must be able to accept all types of events (simply
582  * returning EINA_FALSE if the event was not handled), but there is no
583  * obligation of any events to be submitted to this function.
584  *
585  * @param ctx An #Ecore_IMF_Context.
586  * @param type The type of event defined by #Ecore_IMF_Event_Type.
587  * @param event The event itself.
588  * @return EINA_TRUE if the event was handled; otherwise EINA_FALSE.
589  * @ingroup Ecore_IMF_Context_Group
590  */
591 EAPI Eina_Bool
592 ecore_imf_context_filter_event(Ecore_IMF_Context *ctx, Ecore_IMF_Event_Type type, Ecore_IMF_Event *event)
593 {
594    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
595      {
596         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
597                          "ecore_imf_context_filter_event");
598         return EINA_FALSE;
599      }
600    if (ctx->klass->filter_event) return ctx->klass->filter_event(ctx, type, event);
601    return EINA_FALSE;
602 }
603
604 /**
605  * @defgroup Ecore_IMF_Context_Module_Group Ecore Input Method Context Module Functions
606  *
607  * Functions that should be used by Ecore Input Method Context modules.
608  */
609
610 /**
611  * Creates a new Input Method Context with klass specified by @p ctxc.
612  *
613  * This method should be used by modules implementing the Input
614  * Method Context interface.
615  *
616  * @param ctxc An #Ecore_IMF_Context_Class.
617  * @return A new #Ecore_IMF_Context; on failure it returns NULL.
618  * @ingroup Ecore_IMF_Context_Module_Group
619  */
620 EAPI Ecore_IMF_Context *
621 ecore_imf_context_new(const Ecore_IMF_Context_Class *ctxc)
622 {
623    Ecore_IMF_Context *ctx;
624
625    if (!ctxc) return NULL;
626    ctx = calloc(1, sizeof(Ecore_IMF_Context));
627    if (!ctx) return NULL;
628    ECORE_MAGIC_SET(ctx, ECORE_MAGIC_CONTEXT);
629    ctx->klass = ctxc;
630    ctx->data = NULL;
631    ctx->retrieve_surrounding_func = NULL;
632    ctx->retrieve_surrounding_data = NULL;
633    ctx->input_panel_x = 0;
634    ctx->input_panel_y = 0;
635    ctx->input_panel_layout = ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL;
636    ctx->input_panel_orient = ECORE_IMF_INPUT_PANEL_ORIENT_NONE;
637    ctx->use_effect = EINA_TRUE;
638    ctx->disabled_key_list = NULL;
639    ctx->private_key_list = NULL;
640    ctx->callbacks = NULL;
641
642    return ctx;
643 }
644
645 /**
646  * Set the Input Method Context specific data.
647  *
648  * Note that this method should be used by modules to set
649  * the Input Method Context specific data and it's not meant to
650  * be used by applications to store application specific data.
651  *
652  * @param ctx An #Ecore_IMF_Context.
653  * @param data The Input Method Context specific data.
654  * @return A new #Ecore_IMF_Context; on failure it returns NULL.
655  * @ingroup Ecore_IMF_Context_Module_Group
656  */
657 EAPI void
658 ecore_imf_context_data_set(Ecore_IMF_Context *ctx, void *data)
659 {
660    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
661      {
662         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
663                          "ecore_imf_context_data_set");
664         return;
665      }
666    ctx->data = data;
667 }
668
669 /**
670  * Get the Input Method Context specific data.
671  *
672  * See @ref ecore_imf_context_data_set for more details.
673  *
674  * @param ctx An #Ecore_IMF_Context.
675  * @return The Input Method Context specific data.
676  * @ingroup Ecore_IMF_Context_Module_Group
677  */
678 EAPI void *ecore_imf_context_data_get(Ecore_IMF_Context *ctx)
679 {
680    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
681      {
682         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
683                          "ecore_imf_context_data_get");
684         return NULL;
685      }
686    return ctx->data;
687 }
688
689 /**
690  * Retrieve context around insertion point.
691  *
692  * This function is implemented by calling the
693  * Ecore_IMF_Context::retrieve_surrounding_func (
694  * set using #ecore_imf_context_retrieve_surrounding_callback_set).
695  *
696  * There is no obligation for a widget to respond to the
697  * ::retrieve_surrounding_func, so input methods must be prepared
698  * to function without context.
699  *
700  * @param ctx An #Ecore_IMF_Context.
701  * @param text Location to store a UTF-8 encoded string of text
702  *             holding context around the insertion point.
703  *             If the function returns EINA_TRUE, then you must free
704  *             the result stored in this location with free().
705  * @param cursor_pos Location to store the position in characters of
706  *                   the insertion cursor within @text.
707  * @return EINA_TRUE if surrounding text was provided; otherwise EINA_FALSE.
708  * @ingroup Ecore_IMF_Context_Module_Group
709  */
710 EAPI Eina_Bool
711 ecore_imf_context_surrounding_get(Ecore_IMF_Context *ctx, char **text, int *cursor_pos)
712 {
713    int result = EINA_FALSE;
714
715    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
716      {
717         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
718                          "ecore_imf_context_surrounding_get");
719         return EINA_FALSE;
720      }
721
722    if (ctx->retrieve_surrounding_func)
723      {
724         result = ctx->retrieve_surrounding_func(ctx->retrieve_surrounding_data, ctx, text, cursor_pos);
725         if (!result)
726           {
727              if (text) *text = NULL;
728              if (cursor_pos) *cursor_pos = 0;
729           }
730      }
731    return result;
732 }
733
734 static void
735 _ecore_imf_event_free_preedit(void *data __UNUSED__, void *event)
736 {
737    free(event);
738 }
739
740 /**
741  * Adds ECORE_IMF_EVENT_PREEDIT_START to the event queue.
742  * ECORE_IMF_EVENT_PREEDIT_START should be added when a new preedit sequence starts.
743  *
744  * @param ctx An #Ecore_IMF_Context.
745  * @ingroup Ecore_IMF_Context_Module_Group
746  */
747 EAPI void
748 ecore_imf_context_preedit_start_event_add(Ecore_IMF_Context *ctx)
749 {
750    Ecore_IMF_Event_Commit *ev;
751
752    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
753      {
754         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
755                          "ecore_imf_context_preedit_start_event_add");
756         return;
757      }
758
759    ev = malloc(sizeof(Ecore_IMF_Event_Preedit_Start));
760    ev->ctx = ctx;
761    ecore_event_add(ECORE_IMF_EVENT_PREEDIT_START,
762                    ev, _ecore_imf_event_free_preedit, NULL);
763 }
764
765 /**
766  * Adds ECORE_IMF_EVENT_PREEDIT_END to the event queue.
767  * ECORE_IMF_EVENT_PREEDIT_END should be added when a new preedit sequence has been completed or canceled.
768  *
769  * @param ctx An #Ecore_IMF_Context.
770  * @ingroup Ecore_IMF_Context_Module_Group
771  */
772 EAPI void
773 ecore_imf_context_preedit_end_event_add(Ecore_IMF_Context *ctx)
774 {
775    Ecore_IMF_Event_Commit *ev;
776
777    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
778      {
779         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
780                          "ecore_imf_context_preedit_end_event_add");
781         return;
782      }
783
784    ev = malloc(sizeof(Ecore_IMF_Event_Preedit_End));
785    ev->ctx = ctx;
786    ecore_event_add(ECORE_IMF_EVENT_PREEDIT_END,
787                    ev, _ecore_imf_event_free_preedit, NULL);
788 }
789
790 /**
791  * Adds ECORE_IMF_EVENT_PREEDIT_CHANGED to the event queue.
792  *
793  * @param ctx An #Ecore_IMF_Context.
794  * @ingroup Ecore_IMF_Context_Module_Group
795  */
796 EAPI void
797 ecore_imf_context_preedit_changed_event_add(Ecore_IMF_Context *ctx)
798 {
799    Ecore_IMF_Event_Commit *ev;
800
801    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
802      {
803         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
804                          "ecore_imf_context_preedit_changed_event_add");
805         return;
806      }
807
808    ev = malloc(sizeof(Ecore_IMF_Event_Preedit_Changed));
809    ev->ctx = ctx;
810    ecore_event_add(ECORE_IMF_EVENT_PREEDIT_CHANGED,
811                    ev, _ecore_imf_event_free_preedit, NULL);
812 }
813
814 static void
815 _ecore_imf_event_free_commit(void *data __UNUSED__, void *event)
816 {
817    Ecore_IMF_Event_Commit *ev;
818
819    ev = event;
820    if (ev->str) free(ev->str);
821    free(ev);
822 }
823
824 /**
825  * Adds ECORE_IMF_EVENT_COMMIT to the event queue.
826  *
827  * @param ctx An #Ecore_IMF_Context.
828  * @param str The committed string.
829  * @ingroup Ecore_IMF_Context_Module_Group
830  */
831 EAPI void
832 ecore_imf_context_commit_event_add(Ecore_IMF_Context *ctx, const char *str)
833 {
834    Ecore_IMF_Event_Commit *ev;
835
836    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
837      {
838         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
839                          "ecore_imf_context_commit_event_add");
840         return;
841      }
842
843    ev = malloc(sizeof(Ecore_IMF_Event_Commit));
844    ev->ctx = ctx;
845    ev->str = str ? strdup(str) : NULL;
846    ecore_event_add(ECORE_IMF_EVENT_COMMIT,
847                    ev, _ecore_imf_event_free_commit, NULL);
848
849 }
850
851 static void
852 _ecore_imf_event_free_delete_surrounding(void *data __UNUSED__, void *event)
853 {
854    free(event);
855 }
856
857 /**
858  * Asks the widget that the input context is attached to to delete characters around the cursor position 
859  * by adding the ECORE_IMF_EVENT_DELETE_SURROUNDING to the event queue. 
860  * Note that offset and n_chars are in characters not in bytes.
861  *
862  * @param ctx An #Ecore_IMF_Context.
863  * @param offset The start offset of surrounding to be deleted.
864  * @param n_chars The number of characters to be deleted.
865  * @ingroup Ecore_IMF_Context_Module_Group
866  */
867 EAPI void
868 ecore_imf_context_delete_surrounding_event_add(Ecore_IMF_Context *ctx, int offset, int n_chars)
869 {
870    Ecore_IMF_Event_Delete_Surrounding *ev;
871
872    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
873      {
874         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
875                          "ecore_imf_context_delete_surrounding_event_add");
876         return;
877      }
878
879    ev = malloc(sizeof(Ecore_IMF_Event_Delete_Surrounding));
880    ev->ctx = ctx;
881    ev->offset = offset;
882    ev->n_chars = n_chars;
883    ecore_event_add(ECORE_IMF_EVENT_DELETE_SURROUNDING,
884                    ev, _ecore_imf_event_free_delete_surrounding, NULL);
885 }
886
887 /*** ImControl Related APIs */
888 EAPI void
889 ecore_imf_context_input_panel_show(Ecore_IMF_Context *ctx)
890 {
891    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
892      {
893         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_show");
894         return;
895      }
896
897    if (ctx->klass->show) ctx->klass->show(ctx);
898 }
899
900 EAPI void
901 ecore_imf_context_input_panel_hide(Ecore_IMF_Context *ctx)
902 {
903    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
904      {
905         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_hide");
906         return;
907      }
908
909    if (ctx->klass->hide) ctx->klass->hide(ctx);
910 }
911
912 EAPI void
913 ecore_imf_context_control_panel_show (Ecore_IMF_Context *ctx)
914 {
915    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
916      {
917         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_control_panel_show");
918         return;
919      }
920
921    if (ctx->klass->control_panel_show) ctx->klass->control_panel_show(ctx);
922 }
923
924 EAPI void
925 ecore_imf_context_control_panel_hide (Ecore_IMF_Context *ctx)
926 {
927    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
928      {
929         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_control_panel_hide");
930         return;
931      }
932
933    if (ctx->klass->control_panel_hide) ctx->klass->control_panel_hide(ctx);
934 }
935
936 EAPI void
937 ecore_imf_context_input_panel_language_set (Ecore_IMF_Context *ctx, Ecore_IMF_Input_Panel_Lang lang)
938 {
939    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
940      {
941         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_language_set");
942         return;
943      }
944
945    if (ctx->klass->input_panel_language_set) ctx->klass->input_panel_language_set(ctx, lang);
946    ctx->input_panel_lang = lang;
947 }
948
949 EAPI Ecore_IMF_Input_Panel_Lang
950 ecore_imf_context_input_panel_language_get (Ecore_IMF_Context *ctx)
951 {
952    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
953      {
954         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_language_get");
955         return ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC;
956      }
957
958    return ctx->input_panel_lang;
959 }
960
961 EAPI int
962 ecore_imf_context_ise_get_ise_language (Ecore_IMF_Context *ctx, const char* ise_name, char ***langlist)
963 {
964    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
965      {
966         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_ise_get_ise_language");
967         return -1;
968      }
969
970    if (!ise_name)
971      {
972         printf ("input parameters error!!! \n");
973         return -1;
974      }
975
976    if (ctx->klass->ise_get_ise_language)
977        return ctx->klass->ise_get_ise_language(ctx, ise_name, langlist);
978    else
979       return -1;
980 }
981
982 EAPI void
983 ecore_imf_context_keyboard_language_set (Ecore_IMF_Context *ctx, Ecore_IMF_Keyboard_Lang lang)
984 {
985    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
986      {
987         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_keyboard_language_set");
988         return;
989      }
990 //   if (ctx->klass->ise_set_language) ctx->klass->ise_set_language(ctx, lang);
991 }
992
993 EAPI Ecore_IMF_Keyboard_Lang
994 ecore_imf_context_keyboard_language_get (Ecore_IMF_Context *ctx)
995 {
996    Ecore_IMF_Keyboard_Lang lang = ECORE_IMF_KEYBOARD_LANG_NATIVE;
997
998    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
999      {
1000         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_keyboard_language_get");
1001         return lang;
1002      }
1003 /*
1004    if (ctx->klass->input_panel_language_get) 
1005      lang = ctx->klass->input_panel_language_get(ctx);
1006 */
1007    return lang;
1008 }
1009
1010 EAPI void
1011 ecore_imf_context_ise_set_isf_language (Ecore_IMF_Context *ctx, const char* lang)
1012 {
1013    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1014      {
1015         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_ise_set_isf_language");
1016         return;
1017      }
1018
1019    if (!lang)
1020      {
1021         printf ("input parameters error!!! \n");
1022         return;
1023      }
1024
1025    if (ctx->klass->ise_set_isf_language) ctx->klass->ise_set_isf_language(ctx, lang);
1026 }
1027
1028 EAPI void
1029 ecore_imf_context_input_panel_imdata_set (Ecore_IMF_Context *ctx, const char * data, int len)
1030 {
1031    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1032      {
1033         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_imdata_set");
1034         return;
1035      }
1036
1037    if (!data || len <=0)
1038      {
1039         printf ("input parameters error!!! \n");
1040         return;
1041      }
1042
1043    if (ctx->klass->input_panel_imdata_set) ctx->klass->input_panel_imdata_set(ctx, data, len);
1044 }
1045
1046 EAPI void
1047 ecore_imf_context_input_panel_imdata_get (Ecore_IMF_Context *ctx, char * data, int *len)
1048 {
1049    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1050      {
1051         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_get_imdata");
1052         return;
1053      }
1054
1055    if (!data)
1056      {
1057         printf ("input parameters error!!! \n");
1058         return;
1059      }
1060
1061    if (ctx->klass->input_panel_imdata_get) ctx->klass->input_panel_imdata_get(ctx, data, len);
1062 }
1063
1064 EAPI void
1065 ecore_imf_context_input_panel_use_effect_set (Ecore_IMF_Context *ctx, Eina_Bool use_effect)
1066 {
1067    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1068      {
1069         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_use_effect_set");
1070         return;
1071      }
1072
1073    if (ctx->klass->input_panel_use_effect_set) ctx->klass->input_panel_use_effect_set(ctx, use_effect);
1074    ctx->use_effect = use_effect;
1075 }
1076
1077 EAPI Eina_Bool
1078 ecore_imf_context_input_panel_use_effect_get (Ecore_IMF_Context *ctx)
1079 {
1080    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1081      {
1082         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_use_effect_get");
1083         return EINA_TRUE;
1084      }
1085
1086    return ctx->use_effect;
1087 }
1088
1089 EAPI void
1090 ecore_imf_context_input_panel_geometry_get (Ecore_IMF_Context *ctx, int *x, int *y, int *w, int *h)
1091 {
1092    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1093      {
1094         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_geometry_get");
1095         return;
1096      }
1097
1098    if (ctx->klass->input_panel_geometry_get) ctx->klass->input_panel_geometry_get(ctx, x, y, w, h);
1099 }
1100
1101 EAPI void
1102 ecore_imf_context_input_panel_private_key_set (Ecore_IMF_Context *ctx, int layout_index, int key_index, const char *img_path, const char* label, int key_value, const char* key_string)
1103 {
1104    Private_Key_Item *key_item;
1105    Eina_List *l;
1106    Eina_Bool exist = EINA_FALSE;
1107
1108    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1109      {
1110         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_private_key_set");
1111         return;
1112      }
1113
1114    if (!label && !img_path)
1115      {
1116         printf ("input parameters error!!! \n");
1117         return;
1118      }
1119
1120    EINA_LIST_FOREACH(ctx->private_key_list, l, key_item)
1121      {
1122         if (key_item && key_item->layout_idx == layout_index && 
1123             key_item->key_idx == key_index)
1124           {
1125              // if exist in the list
1126              exist = EINA_TRUE;
1127              if (label)
1128                {
1129                   key_item->type = 0;
1130                   strcpy(key_item->data, label);
1131                }
1132              else
1133                {
1134                   key_item->type = 1;
1135                   strcpy(key_item->data, img_path);
1136                }
1137              key_item->key_value = key_value;
1138              strcpy(key_item->key_string, key_string);
1139           }
1140      }
1141
1142    if (!exist)
1143      {
1144         key_item = calloc(1, sizeof(Private_Key_Item));
1145         if (!key_item) return;
1146
1147         key_item->layout_idx = layout_index;
1148         key_item->key_idx = key_index;;
1149         if (label)
1150           {
1151              key_item->type = 0;
1152              strcpy(key_item->data, label);
1153           }
1154         else
1155           {
1156              key_item->type = 1;
1157              strcpy(key_item->data, img_path);
1158           }
1159         key_item->key_value = key_value;
1160
1161         if (key_string)
1162           {
1163              strcpy(key_item->key_string, key_string);
1164           }
1165
1166         ctx->private_key_list = eina_list_append(ctx->private_key_list, key_item);
1167      }
1168
1169 //   if (ctx->klass->input_panel_private_key_set) ctx->klass->input_panel_private_key_set(ctx, layout_index, key_index, img_path, label, value);
1170 }
1171
1172 EAPI Eina_List *
1173 ecore_imf_context_input_panel_private_key_list_get  (Ecore_IMF_Context *ctx)
1174 {
1175    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1176      {
1177         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_private_key_list_get");
1178         return NULL;
1179      }
1180
1181    return ctx->private_key_list;
1182 }
1183
1184 EAPI void
1185 ecore_imf_context_input_panel_key_disabled_set (Ecore_IMF_Context *ctx, int layout_index, int key_index, Eina_Bool disabled)
1186 {
1187    Disable_Key_Item *key_item;
1188    Eina_List *l;
1189    Eina_Bool exist = EINA_FALSE;
1190
1191    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1192      {
1193         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_key_disabled_set");
1194         return;
1195      }
1196
1197    EINA_LIST_FOREACH(ctx->disabled_key_list, l, key_item)
1198      {
1199         if (key_item && key_item->layout_idx == layout_index && key_item->key_idx == key_index)
1200           {
1201              key_item->disabled = disabled;
1202              exist = EINA_TRUE;
1203           }
1204      }
1205
1206    if (!exist)
1207      {
1208         key_item = calloc(1, sizeof(Disable_Key_Item));
1209         if (!key_item) return;
1210
1211         key_item->layout_idx = layout_index;
1212         key_item->key_idx = key_index;;
1213         key_item->disabled = disabled;
1214
1215         ctx->disabled_key_list = eina_list_append(ctx->disabled_key_list, key_item);
1216      }
1217
1218 //   if (ctx->klass->input_panel_key_disabled_set) ctx->klass->input_panel_key_disabled_set(ctx, layout_index, key_index, disabled);
1219 }
1220
1221 EAPI Eina_List *
1222 ecore_imf_context_input_panel_key_disabled_list_get (Ecore_IMF_Context *ctx)
1223 {
1224    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1225      {
1226         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_key_disabled_list_get");
1227         return NULL;
1228      }
1229
1230    return ctx->disabled_key_list;
1231 }
1232
1233 EAPI Eina_List *
1234 ecore_imf_context_input_panel_event_callback_list_get (Ecore_IMF_Context *ctx)
1235 {
1236    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1237      {
1238         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_event_callback_list_get");
1239         return NULL;
1240      }
1241
1242    return ctx->callbacks;
1243 }
1244
1245 EAPI void
1246 ecore_imf_context_input_panel_layout_set (Ecore_IMF_Context *ctx, Ecore_IMF_Input_Panel_Layout layout)
1247 {
1248    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1249      {
1250         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_layout_set");
1251         return;
1252      }
1253
1254    if (ctx->klass->input_panel_layout_set) ctx->klass->input_panel_layout_set(ctx, layout);
1255    ctx->input_panel_layout = layout;
1256 }
1257
1258 EAPI Ecore_IMF_Input_Panel_Layout
1259 ecore_imf_context_input_panel_layout_get  (Ecore_IMF_Context *ctx)
1260 {
1261    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1262      {
1263         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_layout_get");
1264         return ECORE_IMF_INPUT_PANEL_LAYOUT_INVALID;
1265      }
1266
1267    if (ctx->klass->input_panel_layout_get)
1268      {
1269         //      ctx->klass->input_panel_layout_get (ctx, &layout);
1270         return ctx->input_panel_layout;
1271      }
1272    else
1273      return ECORE_IMF_INPUT_PANEL_LAYOUT_INVALID;
1274 }
1275
1276 EAPI void
1277 ecore_imf_context_input_panel_reset (Ecore_IMF_Context *ctx)
1278 {
1279    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1280      {
1281         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_reset");
1282         return;
1283      }
1284
1285    if (ctx->klass->input_panel_reset) ctx->klass->input_panel_reset(ctx);
1286 }
1287
1288 EAPI void
1289 ecore_imf_context_input_panel_orient_set (Ecore_IMF_Context *ctx, Ecore_IMF_Input_Panel_Orient orientation)
1290 {
1291    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1292      {
1293         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_orient_set");
1294         return;
1295      }
1296
1297    if (ctx->klass->input_panel_orient_set) ctx->klass->input_panel_orient_set(ctx, orientation*90);
1298    ctx->input_panel_orient = orientation;
1299 }
1300
1301 EAPI Ecore_IMF_Input_Panel_Orient
1302 ecore_imf_context_input_panel_orient_get (Ecore_IMF_Context *ctx)
1303 {
1304    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1305      {
1306         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_orient_get");
1307         return ECORE_IMF_INPUT_PANEL_ORIENT_NONE;
1308      }
1309
1310    return ctx->input_panel_orient;
1311 }
1312
1313 EAPI void
1314 ecore_imf_context_ise_get_active_isename (Ecore_IMF_Context *ctx, char* name)
1315 {
1316    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1317      {
1318         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_ise_get_active_isename");
1319         return;
1320      }
1321
1322    if (!name)
1323      {
1324         printf ("input parameters error!!! \n");
1325         return;
1326      }
1327
1328    if (ctx->klass->ise_get_active_isename) ctx->klass->ise_get_active_isename(ctx, name);
1329 }
1330
1331 EAPI void
1332 ecore_imf_context_ise_set_active_ise_by_name (Ecore_IMF_Context *ctx, const char* name)
1333 {
1334    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1335      {
1336         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_ise_set_active_ise_by_name");
1337         return;
1338      }
1339
1340    if (!name)
1341      {
1342         printf ("input parameters error!!! \n");
1343         return;
1344      }
1345
1346    if (ctx->klass->ise_set_active_ise_by_name) ctx->klass->ise_set_active_ise_by_name(ctx, name);
1347 }
1348
1349 EAPI void
1350 ecore_imf_context_ise_set_active_ise_by_uuid (Ecore_IMF_Context *ctx, const char* uuid)
1351 {
1352    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1353      {
1354         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_ise_set_active_ise_by_uuid");
1355         return;
1356      }
1357
1358    if (!uuid)
1359      {
1360         printf ("input parameters error!!! \n");
1361         return;
1362      }
1363
1364    if (ctx->klass->ise_set_active_ise_by_uuid) ctx->klass->ise_set_active_ise_by_uuid(ctx, uuid);
1365 }
1366
1367 EAPI int
1368 ecore_imf_context_ise_get_iselist (Ecore_IMF_Context *ctx,  char*** iselist)
1369 {
1370    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1371      {
1372         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_ise_get_iselist");
1373         return -1;
1374      }
1375
1376    if (ctx->klass->ise_get_iselist)
1377       return ctx->klass->ise_get_iselist(ctx, iselist);
1378    else
1379       return -1;
1380 }
1381
1382 EAPI Ecore_IMF_Input_Panel_State
1383 ecore_imf_context_input_panel_state_get (Ecore_IMF_Context *ctx)
1384 {
1385    Ecore_IMF_Input_Panel_State state = ECORE_IMF_INPUT_PANEL_STATE_INVALID;
1386    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1387      {
1388         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_state_get");
1389         return ECORE_IMF_INPUT_PANEL_STATE_INVALID;
1390      }
1391
1392    if (ctx->klass->input_panel_state_get)
1393       state = ctx->klass->input_panel_state_get(ctx);
1394
1395    return state;
1396 }
1397
1398 EAPI void
1399 ecore_imf_context_input_panel_event_callback_add (Ecore_IMF_Context *ctx, Ecore_IMF_Input_Panel_Event type, void (*func) (void *data, Ecore_IMF_Context *ctx, int value), const void *data)
1400 {
1401    Ecore_IMF_Input_Panel_Event_Callback *it;
1402
1403    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1404      {
1405         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_event_callback_add");
1406         return;
1407      }
1408
1409    if (ctx->klass->input_panel_event_callback_add)
1410      {
1411         it = calloc(1, sizeof(Ecore_IMF_Input_Panel_Event_Callback));
1412         if (!it) return;
1413
1414         it->func = func;
1415         it->data = data;;
1416         it->type = type;
1417
1418         ctx->callbacks = eina_list_append(ctx->callbacks, it);
1419
1420         ctx->klass->input_panel_event_callback_add(ctx, type, func, data);
1421      }
1422 }
1423
1424 EAPI void
1425 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))
1426 {
1427    Eina_List *l;
1428    Ecore_IMF_Input_Panel_Event_Callback *it;
1429
1430    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1431      {
1432         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_event_callback_del");
1433         return;
1434      }
1435
1436    if (ctx->klass->input_panel_event_callback_del)
1437      {
1438         for (l = ctx->callbacks; l;)
1439           {
1440              it = (Ecore_IMF_Input_Panel_Event_Callback *)l->data;
1441
1442              if (it && it->func == func && it->type == type)
1443                {
1444                   ctx->callbacks = eina_list_remove(ctx->callbacks, it);
1445                   free(it);
1446                   break;
1447                }
1448              l = l->next;
1449           }
1450
1451         ctx->klass->input_panel_event_callback_del(ctx, type, func);
1452      }
1453 }
1454
1455 EAPI void
1456 ecore_imf_context_input_panel_move (Ecore_IMF_Context *ctx, int x, int y)
1457 {
1458    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1459      {
1460         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_move");
1461         return;
1462      }
1463
1464    if (ctx->klass->input_panel_move) ctx->klass->input_panel_move(ctx, x, y);
1465    ctx->input_panel_x = x;
1466    ctx->input_panel_y = y;
1467 }
1468
1469 EAPI void
1470 ecore_imf_context_input_panel_caps_mode_set (Ecore_IMF_Context *ctx, Ecore_IMF_Input_Panel_Caps_Mode mode)
1471 {
1472    if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1473      {
1474         ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_caps_mode_set");
1475         return;
1476      }
1477
1478    if (ctx->klass->input_panel_caps_mode_set) ctx->klass->input_panel_caps_mode_set(ctx, mode);
1479 }