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