10 #include <ecore_private.h>
12 #include "Ecore_IMF.h"
13 #include "ecore_imf_private.h"
16 * @defgroup Ecore_IMF_Context_Group Ecore Input Method Context Functions
18 * Functions that operate on Ecore Input Method Context objects.
22 * Get the list of the available Input Method Context ids.
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.
27 * @return Return an Eina_List of strings;
28 * on failure it returns NULL.
29 * @ingroup Ecore_IMF_Context_Group
32 ecore_imf_context_available_ids_get(void)
34 return ecore_imf_module_context_ids_get();
38 ecore_imf_context_available_ids_by_canvas_type_get(const char *canvas_type)
40 return ecore_imf_module_context_ids_by_canvas_type_get(canvas_type);
44 * Match @locale against @against.
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
52 _ecore_imf_context_match_locale(const char *locale, const char *against, int against_len)
54 if (strcmp(against, "*") == 0)
57 if (strcasecmp(locale, against) == 0)
60 if (strncasecmp(locale, against, 2) == 0)
61 return (against_len == 2) ? 3 : 2;
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
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
76 ecore_imf_context_default_id_get(void)
78 return ecore_imf_context_default_id_by_canvas_type_get(NULL);
82 ecore_imf_context_default_id_by_canvas_type_get(const char *canvas_type)
86 Ecore_IMF_Module *module;
89 int best_goodness = 0;
91 id = getenv("ECORE_IMF_MODULE");
94 if (strcmp(id, "none") == 0) return NULL;
95 if (ecore_imf_module_get(id)) return id;
98 modules = ecore_imf_module_available_get();
99 if (!modules) return NULL;
101 locale = setlocale(LC_CTYPE, NULL);
102 if (!locale) return NULL;
104 locale = strdup(locale);
106 tmp = strchr(locale, '.');
107 if (tmp) *tmp = '\0';
108 tmp = strchr(locale, '@');
109 if (tmp) *tmp = '\0';
113 EINA_LIST_FREE(modules, module)
116 strcmp(module->info->canvas_type, canvas_type) == 0)
119 const char *p = module->info->default_locales;
122 const char *q = strchr(p, ':');
123 int goodness = _ecore_imf_context_match_locale(locale, p, q ? (size_t)(q - p) : strlen (p));
125 if (goodness > best_goodness)
127 id = module->info->id;
128 best_goodness = goodness;
131 p = q ? q + 1 : NULL;
140 * Retrieve the info for the Input Method Context with @p id.
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
147 EAPI const Ecore_IMF_Context_Info *
148 ecore_imf_context_info_by_id_get(const char *id)
150 Ecore_IMF_Module *module;
152 if (!id) return NULL;
153 module = ecore_imf_module_get(id);
154 if (!module) return NULL;
159 * Create a new Input Method Context defined by the given id.
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
166 EAPI Ecore_IMF_Context *
167 ecore_imf_context_add(const char *id)
169 Ecore_IMF_Context *ctx;
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);
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);
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);
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);
191 /* default input_mode is ECORE_IMF_INPUT_MODE_FULL, so let's make sure it's
192 * set on the immodule */
193 ecore_imf_context_input_mode_set(ctx, ECORE_IMF_INPUT_MODE_FULL);
198 * Retrieve the info for the given Input Method Context.
200 * @param ctx An #Ecore_IMF_Context.
201 * @return Return a #Ecore_IMF_Context_Info for the given Input Method Context;
202 * on failure it returns NULL.
203 * @ingroup Ecore_IMF_Context_Group
205 EAPI const Ecore_IMF_Context_Info *
206 ecore_imf_context_info_get(Ecore_IMF_Context *ctx)
208 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
210 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
211 "ecore_imf_context_info_get");
214 return ctx->module->info;
218 * Delete the given Input Method Context and free its memory.
220 * @param ctx An #Ecore_IMF_Context.
221 * @ingroup Ecore_IMF_Context_Group
224 ecore_imf_context_del(Ecore_IMF_Context *ctx)
226 Ecore_IMF_Func_Node *fn;
228 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
230 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
231 "ecore_imf_context_del");
234 if (ctx->klass->del) ctx->klass->del(ctx);
238 EINA_LIST_FREE(ctx->callbacks, fn)
242 ECORE_MAGIC_SET(ctx, ECORE_MAGIC_NONE);
247 * Set the client window for the Input Method Context; this is the
248 * Ecore_X_Window when using X11, Ecore_Win32_Window when using Win32, etc.
249 * This window is used in order to correctly position status windows, and may
250 * also be used for purposes internal to the Input Method Context.
252 * @param ctx An #Ecore_IMF_Context.
253 * @param window The client window. This may be NULL to indicate
254 * that the previous client window no longer exists.
255 * @ingroup Ecore_IMF_Context_Group
258 ecore_imf_context_client_window_set(Ecore_IMF_Context *ctx, void *window)
260 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
262 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
263 "ecore_imf_context_client_window_set");
266 if (ctx->klass->client_window_set) ctx->klass->client_window_set(ctx, window);
267 ctx->window = window;
271 * Get the client window of the Input Method Context
273 * See @ref ecore_imf_context_client_window_set for more details.
275 * @param ctx An #Ecore_IMF_Context.
276 * @return Return the client window.
277 * @ingroup Ecore_IMF_Context_Group
281 ecore_imf_context_client_window_get(Ecore_IMF_Context *ctx)
283 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
285 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
286 "ecore_imf_context_client_window_get");
293 * Set the client canvas for the Input Method Context; this is the
294 * canvas in which the input appears.
295 * The canvas type can be determined by using the context canvas type.
296 * Actually only canvas with type "evas" (Evas *) is supported.
297 * This canvas may be used in order to correctly position status windows, and may
298 * also be used for purposes internal to the Input Method Context.
300 * @param ctx An #Ecore_IMF_Context.
301 * @param canvas The client canvas. This may be NULL to indicate
302 * that the previous client canvas no longer exists.
303 * @ingroup Ecore_IMF_Context_Group
306 ecore_imf_context_client_canvas_set(Ecore_IMF_Context *ctx, void *canvas)
308 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
310 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
311 "ecore_imf_context_client_canvas_set");
314 if (ctx->klass->client_canvas_set) ctx->klass->client_canvas_set(ctx, canvas);
315 ctx->client_canvas = canvas;
319 * Get the client canvas of the Input Method Context.
321 * See @ref ecore_imf_context_client_canvas_set for more details.
323 * @param ctx An #Ecore_IMF_Context.
324 * @return Return the client canvas.
325 * @ingroup Ecore_IMF_Context_Group
329 ecore_imf_context_client_canvas_get(Ecore_IMF_Context *ctx)
331 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
333 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
334 "ecore_imf_context_client_canvas_get");
337 return ctx->client_canvas;
341 * Ask the Input Method Context to show itself.
343 * @param ctx An #Ecore_IMF_Context.
344 * @ingroup Ecore_IMF_Context_Group
347 ecore_imf_context_show(Ecore_IMF_Context *ctx)
349 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
351 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
352 "ecore_imf_context_show");
355 if (ctx->klass->show) ctx->klass->show(ctx);
359 * Ask the Input Method Context to hide itself.
361 * @param ctx An #Ecore_IMF_Context.
362 * @ingroup Ecore_IMF_Context_Group
365 ecore_imf_context_hide(Ecore_IMF_Context *ctx)
367 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
369 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
370 "ecore_imf_context_hide");
373 if (ctx->klass->hide) ctx->klass->hide(ctx);
377 * Retrieve the current preedit string and cursor position
378 * for the Input Method Context.
380 * @param ctx An #Ecore_IMF_Context.
381 * @param str Location to store the retrieved string. The
382 * string retrieved must be freed with free().
383 * @param cursor_pos Location to store position of cursor (in characters)
384 * within the preedit string.
385 * @ingroup Ecore_IMF_Context_Group
388 ecore_imf_context_preedit_string_get(Ecore_IMF_Context *ctx, char **str, int *cursor_pos)
390 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
392 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
393 "ecore_imf_context_preedit_string_get");
396 if (ctx->klass->preedit_string_get)
397 ctx->klass->preedit_string_get(ctx, str, cursor_pos);
400 if (str) *str = strdup("");
401 if (cursor_pos) *cursor_pos = 0;
406 * Retrieve the current preedit string, atrributes and
407 * cursor position for the Input Method Context.
409 * @param ctx An #Ecore_IMF_Context.
410 * @param str Location to store the retrieved string. The
411 * string retrieved must be freed with free().
412 * @param attrs an Eina_List of attributes
413 * @param cursor_pos Location to store position of cursor (in characters)
414 * within the preedit string.
415 * @ingroup Ecore_IMF_Context_Group
419 ecore_imf_context_preedit_string_with_attributes_get(Ecore_IMF_Context *ctx, char **str, Eina_List **attrs, int *cursor_pos)
421 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
423 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
424 "ecore_imf_context_preedit_string_with_attributes_get");
427 if (ctx->klass->preedit_string_with_attributes_get)
428 ctx->klass->preedit_string_with_attributes_get(ctx, str, attrs, cursor_pos);
431 if (str) *str = strdup("");
432 if (attrs) *attrs = NULL;
433 if (cursor_pos) *cursor_pos = 0;
438 * Notify the Input Method Context that the widget to which its
439 * correspond has gained focus.
441 * @param ctx An #Ecore_IMF_Context.
442 * @ingroup Ecore_IMF_Context_Group
445 ecore_imf_context_focus_in(Ecore_IMF_Context *ctx)
447 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
449 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
450 "ecore_imf_context_focus_in");
453 if (ctx->klass->focus_in) ctx->klass->focus_in(ctx);
457 * Notify the Input Method Context that the widget to which its
458 * correspond has lost focus.
460 * @param ctx An #Ecore_IMF_Context.
461 * @ingroup Ecore_IMF_Context_Group
464 ecore_imf_context_focus_out(Ecore_IMF_Context *ctx)
466 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
468 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
469 "ecore_imf_context_focus_out");
472 if (ctx->klass->focus_out) ctx->klass->focus_out(ctx);
476 * Notify the Input Method Context that a change such as a
477 * change in cursor position has been made. This will typically
478 * cause the Input Method Context to clear the preedit state.
480 * @param ctx An #Ecore_IMF_Context.
481 * @ingroup Ecore_IMF_Context_Group
484 ecore_imf_context_reset(Ecore_IMF_Context *ctx)
486 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
488 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
489 "ecore_imf_context_reset");
492 if (ctx->klass->reset) ctx->klass->reset(ctx);
496 * Notify the Input Method Context that a change in the cursor
497 * position has been made.
499 * @param ctx An #Ecore_IMF_Context.
500 * @param cursor_pos New cursor position in characters.
501 * @ingroup Ecore_IMF_Context_Group
504 ecore_imf_context_cursor_position_set(Ecore_IMF_Context *ctx, int cursor_pos)
506 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
508 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
509 "ecore_imf_context_cursor_position_set");
512 if (ctx->klass->cursor_position_set) ctx->klass->cursor_position_set(ctx, cursor_pos);
516 * Notify the Input Method Context that a change in the cursor
517 * location has been made. The location is relative to the canvas.
519 * @param ctx An #Ecore_IMF_Context.
520 * @param x cursor x position.
521 * @param x cursor y position.
522 * @param w cursor width.
523 * @param h cursor height.
524 * @ingroup Ecore_IMF_Context_Group
528 ecore_imf_context_cursor_location_set(Ecore_IMF_Context *ctx, int x, int y, int w, int h)
530 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
532 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
533 "ecore_imf_context_cursor_location_set");
536 if (ctx->klass->cursor_location_set) ctx->klass->cursor_location_set(ctx, x, y, w, h);
540 * Set whether the IM context should use the preedit string
541 * to display feedback. If @c use_preedit is EINA_FALSE (default
542 * is EINA_TRUE), then the IM context may use some other method to display
543 * feedback, such as displaying it in a child of the root window.
545 * @param ctx An #Ecore_IMF_Context.
546 * @param use_preedit Whether the IM context should use the preedit string.
547 * @ingroup Ecore_IMF_Context_Group
550 ecore_imf_context_use_preedit_set(Ecore_IMF_Context *ctx, Eina_Bool use_preedit)
552 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
554 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
555 "ecore_imf_context_use_preedit_set");
558 if (ctx->klass->use_preedit_set) ctx->klass->use_preedit_set(ctx, use_preedit);
562 * Set whether the IM context should allow to use the text prediction.
563 * If @c prediction is EINA_FALSE (default is EINA_TRUE), then the IM context will not display the text prediction window.
565 * @param ctx An #Ecore_IMF_Context.
566 * @param prediction Whether the IM context should allow to use the text prediction.
567 * @ingroup Ecore_IMF_Context_Group
571 ecore_imf_context_prediction_allow_set(Ecore_IMF_Context *ctx, Eina_Bool prediction)
573 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
575 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
576 "ecore_imf_context_prediction_allow_set");
580 ctx->allow_prediction = prediction;
582 if (ctx->klass->prediction_allow_set)
583 ctx->klass->prediction_allow_set(ctx, prediction);
587 * Get whether the IM context should allow to use the text prediction.
589 * @param ctx An #Ecore_IMF_Context.
590 * @return EINA_TRUE if it allows to use the text prediction, otherwise EINA_FALSE.
591 * @ingroup Ecore_IMF_Context_Group
595 ecore_imf_context_prediction_allow_get(Ecore_IMF_Context *ctx)
597 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
599 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
600 "ecore_imf_context_prediction_allow_get");
604 return ctx->allow_prediction;
608 * Set the autocapitalization type on the immodule.
610 * @param ctx An #Ecore_IMF_Context.
611 * @param autocapital_type the autocapitalization type.
612 * @ingroup Ecore_IMF_Context_Group
616 ecore_imf_context_autocapital_type_set(Ecore_IMF_Context *ctx, Ecore_IMF_Autocapital_Type autocapital_type)
618 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
620 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
621 "ecore_imf_context_autocapital_type_set");
625 ctx->autocapital_type = autocapital_type;
627 if (ctx->klass->autocapital_type_set) ctx->klass->autocapital_type_set(ctx, autocapital_type);
631 * Get the autocapitalization type.
633 * @param ctx An #Ecore_IMF_Context.
634 * @return The autocapital type being used by @p ctx.
635 * @ingroup Ecore_IMF_Context_Group
638 EAPI Ecore_IMF_Autocapital_Type
639 ecore_imf_context_autocapital_type_get(Ecore_IMF_Context *ctx)
641 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
643 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
644 "ecore_imf_context_autocapital_allow_get");
645 return ECORE_IMF_AUTOCAPITAL_TYPE_NONE;
648 return ctx->autocapital_type;
652 * Set the callback to be used on get_surrounding request.
654 * This callback will be called when the Input Method Context
655 * module requests the surrounding context.
657 * @param ctx An #Ecore_IMF_Context.
658 * @param func The callback to be called.
659 * @param data The data pointer to be passed to @p func
660 * @ingroup Ecore_IMF_Context_Group
663 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)
665 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
667 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
668 "ecore_imf_context_retrieve_surrounding_callback_set");
672 ctx->retrieve_surrounding_func = func;
673 ctx->retrieve_surrounding_data = (void *) data;
677 * Set the input mode used by the Ecore Input Context.
679 * The input mode can be one of the input modes defined in
680 * #Ecore_IMF_Input_Mode. The default input mode is
681 * ECORE_IMF_INPUT_MODE_FULL.
683 * @param ctx An #Ecore_IMF_Context.
684 * @param input_mode The input mode to be used by @p ctx.
685 * @ingroup Ecore_IMF_Context_Group
688 ecore_imf_context_input_mode_set(Ecore_IMF_Context *ctx, Ecore_IMF_Input_Mode input_mode)
690 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
692 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
693 "ecore_imf_context_input_mode_set");
696 if (ctx->klass->input_mode_set) ctx->klass->input_mode_set(ctx, input_mode);
697 ctx->input_mode = input_mode;
701 * Get the input mode being used by the Ecore Input Context.
703 * See @ref ecore_imf_context_input_mode_set for more details.
705 * @param ctx An #Ecore_IMF_Context.
706 * @return The input mode being used by @p ctx.
707 * @ingroup Ecore_IMF_Context_Group
709 EAPI Ecore_IMF_Input_Mode
710 ecore_imf_context_input_mode_get(Ecore_IMF_Context *ctx)
712 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
714 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
715 "ecore_imf_context_input_mode_set");
718 return ctx->input_mode;
722 * Allow an Ecore Input Context to internally handle an event.
723 * If this function returns EINA_TRUE, then no further processing
724 * should be done for this event.
726 * Input methods must be able to accept all types of events (simply
727 * returning EINA_FALSE if the event was not handled), but there is no
728 * obligation of any events to be submitted to this function.
730 * @param ctx An #Ecore_IMF_Context.
731 * @param type The type of event defined by #Ecore_IMF_Event_Type.
732 * @param event The event itself.
733 * @return EINA_TRUE if the event was handled; otherwise EINA_FALSE.
734 * @ingroup Ecore_IMF_Context_Group
737 ecore_imf_context_filter_event(Ecore_IMF_Context *ctx, Ecore_IMF_Event_Type type, Ecore_IMF_Event *event)
739 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
741 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
742 "ecore_imf_context_filter_event");
745 if (ctx->klass->filter_event) return ctx->klass->filter_event(ctx, type, event);
750 * @defgroup Ecore_IMF_Context_Module_Group Ecore Input Method Context Module Functions
752 * Functions that should be used by Ecore Input Method Context modules.
756 * Creates a new Input Method Context with klass specified by @p ctxc.
758 * This method should be used by modules implementing the Input
759 * Method Context interface.
761 * @param ctxc An #Ecore_IMF_Context_Class.
762 * @return A new #Ecore_IMF_Context; on failure it returns NULL.
763 * @ingroup Ecore_IMF_Context_Module_Group
765 EAPI Ecore_IMF_Context *
766 ecore_imf_context_new(const Ecore_IMF_Context_Class *ctxc)
768 Ecore_IMF_Context *ctx;
770 if (!ctxc) return NULL;
771 ctx = calloc(1, sizeof(Ecore_IMF_Context));
772 if (!ctx) return NULL;
773 ECORE_MAGIC_SET(ctx, ECORE_MAGIC_CONTEXT);
776 ctx->retrieve_surrounding_func = NULL;
777 ctx->retrieve_surrounding_data = NULL;
782 * Set the Input Method Context specific data.
784 * Note that this method should be used by modules to set
785 * the Input Method Context specific data and it's not meant to
786 * be used by applications to store application specific data.
788 * @param ctx An #Ecore_IMF_Context.
789 * @param data The Input Method Context specific data.
790 * @return A new #Ecore_IMF_Context; on failure it returns NULL.
791 * @ingroup Ecore_IMF_Context_Module_Group
794 ecore_imf_context_data_set(Ecore_IMF_Context *ctx, void *data)
796 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
798 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
799 "ecore_imf_context_data_set");
806 * Get the Input Method Context specific data.
808 * See @ref ecore_imf_context_data_set for more details.
810 * @param ctx An #Ecore_IMF_Context.
811 * @return The Input Method Context specific data.
812 * @ingroup Ecore_IMF_Context_Module_Group
814 EAPI void *ecore_imf_context_data_get(Ecore_IMF_Context *ctx)
816 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
818 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
819 "ecore_imf_context_data_get");
826 * Retrieve context around insertion point.
828 * This function is implemented by calling the
829 * Ecore_IMF_Context::retrieve_surrounding_func (
830 * set using #ecore_imf_context_retrieve_surrounding_callback_set).
832 * There is no obligation for a widget to respond to the
833 * ::retrieve_surrounding_func, so input methods must be prepared
834 * to function without context.
836 * @param ctx An #Ecore_IMF_Context.
837 * @param text Location to store a UTF-8 encoded string of text
838 * holding context around the insertion point.
839 * If the function returns EINA_TRUE, then you must free
840 * the result stored in this location with free().
841 * @param cursor_pos Location to store the position in characters of
842 * the insertion cursor within @text.
843 * @return EINA_TRUE if surrounding text was provided; otherwise EINA_FALSE.
844 * @ingroup Ecore_IMF_Context_Module_Group
847 ecore_imf_context_surrounding_get(Ecore_IMF_Context *ctx, char **text, int *cursor_pos)
849 int result = EINA_FALSE;
851 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
853 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
854 "ecore_imf_context_surrounding_get");
858 if (ctx->retrieve_surrounding_func)
860 result = ctx->retrieve_surrounding_func(ctx->retrieve_surrounding_data, ctx, text, cursor_pos);
863 if (text) *text = NULL;
864 if (cursor_pos) *cursor_pos = 0;
871 _ecore_imf_event_free_preedit(void *data __UNUSED__, void *event)
877 * Adds ECORE_IMF_EVENT_PREEDIT_START to the event queue.
879 * ECORE_IMF_EVENT_PREEDIT_START should be added when a new preedit sequence starts.
881 * @param ctx An #Ecore_IMF_Context.
882 * @ingroup Ecore_IMF_Context_Module_Group
885 ecore_imf_context_preedit_start_event_add(Ecore_IMF_Context *ctx)
887 Ecore_IMF_Event_Commit *ev;
889 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
891 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
892 "ecore_imf_context_preedit_start_event_add");
896 ev = malloc(sizeof(Ecore_IMF_Event_Preedit_Start));
898 ecore_event_add(ECORE_IMF_EVENT_PREEDIT_START,
899 ev, _ecore_imf_event_free_preedit, NULL);
903 * Adds ECORE_IMF_EVENT_PREEDIT_END to the event queue.
905 * ECORE_IMF_EVENT_PREEDIT_END should be added when a new preedit sequence has been completed or canceled.
907 * @param ctx An #Ecore_IMF_Context.
908 * @ingroup Ecore_IMF_Context_Module_Group
911 ecore_imf_context_preedit_end_event_add(Ecore_IMF_Context *ctx)
913 Ecore_IMF_Event_Commit *ev;
915 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
917 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
918 "ecore_imf_context_preedit_end_event_add");
922 ev = malloc(sizeof(Ecore_IMF_Event_Preedit_End));
924 ecore_event_add(ECORE_IMF_EVENT_PREEDIT_END,
925 ev, _ecore_imf_event_free_preedit, NULL);
929 * Adds ECORE_IMF_EVENT_PREEDIT_CHANGED to the event queue.
931 * @param ctx An #Ecore_IMF_Context.
932 * @ingroup Ecore_IMF_Context_Module_Group
935 ecore_imf_context_preedit_changed_event_add(Ecore_IMF_Context *ctx)
937 Ecore_IMF_Event_Commit *ev;
939 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
941 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
942 "ecore_imf_context_preedit_changed_event_add");
946 ev = malloc(sizeof(Ecore_IMF_Event_Preedit_Changed));
948 ecore_event_add(ECORE_IMF_EVENT_PREEDIT_CHANGED,
949 ev, _ecore_imf_event_free_preedit, NULL);
953 _ecore_imf_event_free_commit(void *data __UNUSED__, void *event)
955 Ecore_IMF_Event_Commit *ev;
958 if (ev->str) free(ev->str);
963 * Adds ECORE_IMF_EVENT_COMMIT to the event queue.
965 * @param ctx An #Ecore_IMF_Context.
966 * @param str The committed string.
967 * @ingroup Ecore_IMF_Context_Module_Group
970 ecore_imf_context_commit_event_add(Ecore_IMF_Context *ctx, const char *str)
972 Ecore_IMF_Event_Commit *ev;
974 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
976 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
977 "ecore_imf_context_commit_event_add");
981 ev = malloc(sizeof(Ecore_IMF_Event_Commit));
983 ev->str = str ? strdup(str) : NULL;
984 ecore_event_add(ECORE_IMF_EVENT_COMMIT,
985 ev, _ecore_imf_event_free_commit, NULL);
990 _ecore_imf_event_free_delete_surrounding(void *data __UNUSED__, void *event)
996 * Adds ECORE_IMF_EVENT_DELETE_SURROUNDING to the event queue.
998 * Asks the widget that the input context is attached to to delete characters around the cursor position
999 * by adding the ECORE_IMF_EVENT_DELETE_SURROUNDING to the event queue.
1000 * Note that offset and n_chars are in characters not in bytes.
1002 * @param ctx An #Ecore_IMF_Context.
1003 * @param offset The start offset of surrounding to be deleted.
1004 * @param n_chars The number of characters to be deleted.
1005 * @ingroup Ecore_IMF_Context_Module_Group
1008 ecore_imf_context_delete_surrounding_event_add(Ecore_IMF_Context *ctx, int offset, int n_chars)
1010 Ecore_IMF_Event_Delete_Surrounding *ev;
1012 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1014 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1015 "ecore_imf_context_delete_surrounding_event_add");
1019 ev = malloc(sizeof(Ecore_IMF_Event_Delete_Surrounding));
1021 ev->offset = offset;
1022 ev->n_chars = n_chars;
1023 ecore_event_add(ECORE_IMF_EVENT_DELETE_SURROUNDING,
1024 ev, _ecore_imf_event_free_delete_surrounding, NULL);
1028 * Add (register) a callback function to a given context event.
1030 * This function adds a function callback to the context @p ctx when the
1031 * event of type @p type occurs on it. The function pointer is @p
1034 * The event type @p type to trigger the function may be one of
1035 * #ECORE_IMF_CALLBACK_PREEDIT_START, #ECORE_IMF_CALLBACK_PREEDIT_END,
1036 * #ECORE_IMF_CALLBACK_PREEDIT_CHANGED, #ECORE_IMF_CALLBACK_COMMIT and
1037 * #ECORE_IMF_CALLBACK_DELETE_SURROUNDING.
1039 * @param ctx Ecore_IMF_Context to attach a callback to.
1040 * @param type The type of event that will trigger the callback
1041 * @param func The (callback) function to be called when the event is
1043 * @param data The data pointer to be passed to @p func
1044 * @ingroup Ecore_IMF_Context_Module_Group
1048 ecore_imf_context_event_callback_add(Ecore_IMF_Context *ctx, Ecore_IMF_Callback_Type type, Ecore_IMF_Event_Cb func, const void *data)
1050 Ecore_IMF_Func_Node *fn = NULL;
1052 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1054 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1055 "ecore_imf_context_event_callback_add");
1061 fn = calloc(1, sizeof (Ecore_IMF_Func_Node));
1068 ctx->callbacks = eina_list_append(ctx->callbacks, fn);
1072 * Delete (unregister) a callback function registered to a given
1075 * This function removes a function callback from the context @p ctx when the
1076 * event of type @p type occurs on it. The function pointer is @p
1079 * @see ecore_imf_context_event_callback_add() for more details
1081 * @param ctx Ecore_IMF_Context to remove a callback from.
1082 * @param type The type of event that was trigerring the callback
1083 * @param func The (callback) function that was to be called when the event was triggered
1084 * @return the data pointer
1085 * @ingroup Ecore_IMF_Context_Module_Group
1089 ecore_imf_context_event_callback_del(Ecore_IMF_Context *ctx, Ecore_IMF_Callback_Type type, Ecore_IMF_Event_Cb func)
1091 Eina_List *l = NULL;
1092 Eina_List *l_next = NULL;
1093 Ecore_IMF_Func_Node *fn = NULL;
1095 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1097 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1098 "ecore_imf_context_event_callback_del");
1102 if (!func) return NULL;
1103 if (!ctx->callbacks) return NULL;
1105 EINA_LIST_FOREACH_SAFE(ctx->callbacks, l, l_next, fn)
1107 if ((fn) && (fn->func == func) && (fn->type == type))
1109 void *tmp = fn->data;
1111 ctx->callbacks = eina_list_remove_list(ctx->callbacks, l);
1119 * Call a given callback on the context @p ctx.
1121 * ecore_imf_context_preedit_start_event_add, ecore_imf_context_preedit_end_event_add,
1122 * ecore_imf_context_preedit_changed_event_add, ecore_imf_context_commit_event_add and
1123 * ecore_imf_context_delete_surrounding_event_add APIs are asynchronous
1124 * because those API adds each event to the event queue.
1126 * This API provides the way to call each callback function immediately.
1128 * @param ctx Ecore_IMF_Context.
1129 * @param type The type of event that will trigger the callback
1130 * @param event_info The pointer to event specific struct or information to
1131 * pass to the callback functions registered on this event
1132 * @ingroup Ecore_IMF_Context_Module_Group
1136 ecore_imf_context_event_callback_call(Ecore_IMF_Context *ctx, Ecore_IMF_Callback_Type type, void *event_info)
1138 Ecore_IMF_Func_Node *fn = NULL;
1139 Eina_List *l = NULL;
1141 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1143 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1144 "ecore_imf_context_event_callback_call");
1148 EINA_LIST_FOREACH(ctx->callbacks, l, fn)
1150 if ((fn) && (fn->type == type) && (fn->func))
1151 fn->func(fn->data, ctx, event_info);
1156 * Ask the Input Method Context to show the control panel of using Input Method.
1158 * @param ctx An #Ecore_IMF_Context.
1159 * @ingroup Ecore_IMF_Context_IMControl_Group
1163 ecore_imf_context_control_panel_show (Ecore_IMF_Context *ctx)
1165 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1167 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1168 "ecore_imf_context_control_panel_show");
1172 if (ctx->klass->control_panel_show) ctx->klass->control_panel_show(ctx);
1176 * Ask the Input Method Context to hide the control panel of using Input Method.
1178 * @param ctx An #Ecore_IMF_Context.
1179 * @ingroup Ecore_IMF_Context_IMControl_Group
1183 ecore_imf_context_control_panel_hide (Ecore_IMF_Context *ctx)
1185 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1187 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1188 "ecore_imf_context_control_panel_hide");
1192 if (ctx->klass->control_panel_hide) ctx->klass->control_panel_hide(ctx);
1196 * Ask the Input Method Context to show the input panel (virtual keyboard).
1198 * @param ctx An #Ecore_IMF_Context.
1199 * @ingroup Ecore_IMF_Context_IMControl_Group
1203 ecore_imf_context_input_panel_show(Ecore_IMF_Context *ctx)
1205 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1207 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1208 "ecore_imf_context_input_panel_show");
1212 if (ctx->klass->show) ctx->klass->show(ctx);
1216 * Ask the Input Method Context to hide the input panel.
1218 * @param ctx An #Ecore_IMF_Context.
1219 * @ingroup Ecore_IMF_Context_IMControl_Group
1223 ecore_imf_context_input_panel_hide(Ecore_IMF_Context *ctx)
1225 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1227 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1228 "ecore_imf_context_input_panel_hide");
1232 if (ctx->klass->hide) ctx->klass->hide(ctx);
1236 * Set the layout of the input panel.
1238 * @param ctx An #Ecore_IMF_Context.
1239 * @param layout see #ECORE_IMF_INPUT_PANEL_LAYOUT
1240 * @ingroup Ecore_IMF_Context_IMControl_Group
1244 ecore_imf_context_input_panel_layout_set (Ecore_IMF_Context *ctx, Ecore_IMF_Input_Panel_Layout layout)
1246 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1248 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1249 "ecore_imf_context_input_panel_layout_set");
1253 if (ctx->klass->input_panel_layout_set)
1254 ctx->klass->input_panel_layout_set(ctx, layout);
1256 ctx->input_panel_layout = layout;
1260 * Get the layout of the current active input panel.
1262 * @param ctx An #Ecore_IMF_Context.
1263 * @return layout see #Ecore_IMF_Input_Panel_Layout
1264 * @ingroup Ecore_IMF_Context_IMControl_Group
1267 EAPI Ecore_IMF_Input_Panel_Layout
1268 ecore_imf_context_input_panel_layout_get (Ecore_IMF_Context *ctx)
1270 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1272 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1273 "ecore_imf_context_input_panel_layout_get");
1274 return ECORE_IMF_INPUT_PANEL_LAYOUT_INVALID;
1277 if (ctx->klass->input_panel_layout_get)
1279 return ctx->input_panel_layout;
1282 return ECORE_IMF_INPUT_PANEL_LAYOUT_INVALID;
1286 * Set the language of the input panel.
1287 * This API can be used when you want to show the English keyboard.
1289 * @param ctx An #Ecore_IMF_Context.
1290 * @param lang the language to be set to the input panel.
1291 * @ingroup Ecore_IMF_Context_IMControl_Group
1295 ecore_imf_context_input_panel_language_set (Ecore_IMF_Context *ctx, Ecore_IMF_Input_Panel_Lang lang)
1297 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1299 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1300 "ecore_imf_context_input_panel_language_set");
1304 if (ctx->klass->input_panel_language_set) ctx->klass->input_panel_language_set(ctx, lang);
1305 ctx->input_panel_lang = lang;
1309 * Get the language of the input panel.
1311 * See @ref ecore_imf_context_input_panel_language_set for more details.
1313 * @param ctx An #Ecore_IMF_Context.
1314 * @return Ecore_IMF_Input_Panel_Lang
1315 * @ingroup Ecore_IMF_Context_IMControl_Group
1318 EAPI Ecore_IMF_Input_Panel_Lang
1319 ecore_imf_context_input_panel_language_get (Ecore_IMF_Context *ctx)
1321 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1323 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1324 "ecore_imf_context_input_panel_language_get");
1325 return ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC;
1328 return ctx->input_panel_lang;
1332 * Set whether the Input Method Context should request to show the input panel automatically
1333 * when the widget has focus.
1335 * @param ctx An #Ecore_IMF_Context.
1336 * @param enabled If true, the input panel will be shown when the widget is clicked or has focus.
1337 * @ingroup Ecore_IMF_Context_Group
1341 ecore_imf_context_input_panel_enabled_set (Ecore_IMF_Context *ctx,
1344 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1346 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1347 "ecore_imf_context_input_panel_enabled_set");
1351 ctx->input_panel_enabled = enabled;
1355 * Get whether the Input Method Context requests to show the input panel automatically.
1357 * @param ctx An #Ecore_IMF_Context.
1358 * @return Return the attribute to show the input panel automatically
1359 * @ingroup Ecore_IMF_Context_Group
1363 ecore_imf_context_input_panel_enabled_get (Ecore_IMF_Context *ctx)
1365 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1367 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1368 "ecore_imf_context_input_panel_enabled_get");
1372 return ctx->input_panel_enabled;