11 #include <ecore_private.h>
13 #include "Ecore_IMF.h"
14 #include "ecore_imf_private.h"
17 * @defgroup Ecore_IMF_Context_Group Ecore Input Method Context Functions
19 * Functions that operate on Ecore Input Method Context objects.
23 * Get the list of the available Input Method Context ids.
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.
28 * @return Return an Eina_List of strings;
29 * on failure it returns NULL.
30 * @ingroup Ecore_IMF_Context_Group
33 ecore_imf_context_available_ids_get(void)
35 return ecore_imf_module_context_ids_get();
39 ecore_imf_context_available_ids_by_canvas_type_get(const char *canvas_type)
41 return ecore_imf_module_context_ids_by_canvas_type_get(canvas_type);
45 * Match @locale against @against.
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
53 _ecore_imf_context_match_locale(const char *locale, const char *against, int against_len)
55 if (strcmp(against, "*") == 0)
58 if (strcasecmp(locale, against) == 0)
61 if (strncasecmp(locale, against, 2) == 0)
62 return (against_len == 2) ? 3 : 2;
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
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
77 ecore_imf_context_default_id_get(void)
79 return ecore_imf_context_default_id_by_canvas_type_get(NULL);
83 ecore_imf_context_default_id_by_canvas_type_get(const char *canvas_type)
87 Ecore_IMF_Module *module;
90 int best_goodness = 0;
92 id = getenv("ECORE_IMF_MODULE");
95 if (strcmp(id, "none") == 0) return NULL;
96 if (ecore_imf_module_get(id)) return id;
99 modules = ecore_imf_module_available_get();
100 if (!modules) return NULL;
102 locale = setlocale(LC_CTYPE, NULL);
103 if (!locale) return NULL;
105 locale = strdup(locale);
107 tmp = strchr(locale, '.');
108 if (tmp) *tmp = '\0';
109 tmp = strchr(locale, '@');
110 if (tmp) *tmp = '\0';
114 EINA_LIST_FREE(modules, module)
117 strcmp(module->info->canvas_type, canvas_type) == 0)
120 const char *p = module->info->default_locales;
123 const char *q = strchr(p, ':');
124 int goodness = _ecore_imf_context_match_locale(locale, p, q ? (size_t)(q - p) : strlen (p));
126 if (goodness > best_goodness)
128 id = module->info->id;
129 best_goodness = goodness;
132 p = q ? q + 1 : NULL;
141 * Retrieve the info for the Input Method Context with @p id.
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
148 EAPI const Ecore_IMF_Context_Info *
149 ecore_imf_context_info_by_id_get(const char *id)
151 Ecore_IMF_Module *module;
153 if (!id) return NULL;
154 module = ecore_imf_module_get(id);
155 if (!module) return NULL;
160 * Create a new Input Method Context defined by the given id.
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
167 EAPI Ecore_IMF_Context *
168 ecore_imf_context_add(const char *id)
170 Ecore_IMF_Context *ctx;
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);
186 * Retrieve the info for the given Input Method Context.
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
193 EAPI const Ecore_IMF_Context_Info *
194 ecore_imf_context_info_get(Ecore_IMF_Context *ctx)
196 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
198 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
199 "ecore_imf_context_info_get");
202 return ctx->module->info;
206 * Delete the given Input Method Context and free its memory.
208 * @param ctx An #Ecore_IMF_Context.
209 * @ingroup Ecore_IMF_Context_Group
212 ecore_imf_context_del(Ecore_IMF_Context *ctx)
215 Ecore_IMF_Input_Panel_State state;
217 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
219 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
220 "ecore_imf_context_del");
224 state = ecore_imf_context_input_panel_state_get(ctx);
226 if (state == ECORE_IMF_INPUT_PANEL_STATE_SHOW)
227 ecore_imf_context_input_panel_hide(ctx);
229 if (ctx->klass->del) ctx->klass->del(ctx);
230 ECORE_MAGIC_SET(ctx, ECORE_MAGIC_NONE);
232 EINA_LIST_FREE(ctx->private_key_list, data)
235 EINA_LIST_FREE(ctx->disabled_key_list, data)
238 EINA_LIST_FREE(ctx->callbacks, data)
241 ctx->private_key_list = NULL;
242 ctx->disabled_key_list = NULL;
243 ctx->callbacks = NULL;
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.
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
260 ecore_imf_context_client_window_set(Ecore_IMF_Context *ctx, void *window)
262 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
264 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
265 "ecore_imf_context_client_window_set");
268 if (ctx->klass->client_window_set) ctx->klass->client_window_set(ctx, window);
269 ctx->window = window;
273 ecore_imf_context_client_window_get(Ecore_IMF_Context *ctx)
275 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
277 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
278 "ecore_imf_context_client_window_get");
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.
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
298 ecore_imf_context_client_canvas_set(Ecore_IMF_Context *ctx, void *canvas)
300 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
302 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
303 "ecore_imf_context_client_canvas_set");
306 if (ctx->klass->client_canvas_set) ctx->klass->client_canvas_set(ctx, canvas);
307 ctx->client_canvas = canvas;
311 ecore_imf_context_client_canvas_get(Ecore_IMF_Context *ctx)
313 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
315 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
316 "ecore_imf_context_client_canvas_get");
319 return ctx->client_canvas;
323 * Ask the Input Method Context to show itself.
325 * @param ctx An #Ecore_IMF_Context.
326 * @ingroup Ecore_IMF_Context_Group
328 EINA_DEPRECATED EAPI void
329 ecore_imf_context_show(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_show");
337 if (ctx->klass->show) ctx->klass->show(ctx);
341 * Ask the Input Method Context to hide itself.
343 * @param ctx An #Ecore_IMF_Context.
344 * @ingroup Ecore_IMF_Context_Group
346 EINA_DEPRECATED EAPI void
347 ecore_imf_context_hide(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_hide");
355 if (ctx->klass->hide) ctx->klass->hide(ctx);
359 * Retrieve the current preedit string and cursor position
360 * for the Input Method Context.
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
370 ecore_imf_context_preedit_string_get(Ecore_IMF_Context *ctx, char **str, int *cursor_pos)
372 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
374 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
375 "ecore_imf_context_preedit_string_get");
378 if (ctx->klass->preedit_string_get)
379 ctx->klass->preedit_string_get(ctx, str, cursor_pos);
382 if (str) *str = strdup("");
383 if (cursor_pos) *cursor_pos = 0;
388 ecore_imf_context_preedit_string_with_attributes_get(Ecore_IMF_Context *ctx, char **str, Eina_List **attrs, 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_with_attributes_get");
396 if (ctx->klass->preedit_string_with_attributes_get)
397 ctx->klass->preedit_string_with_attributes_get(ctx, str, attrs, cursor_pos);
400 if (str) *str = strdup("");
401 if (attrs) *attrs = NULL;
402 if (cursor_pos) *cursor_pos = 0;
407 * Notify the Input Method Context that the widget to which its
408 * correspond has gained focus.
410 * @param ctx An #Ecore_IMF_Context.
411 * @ingroup Ecore_IMF_Context_Group
414 ecore_imf_context_focus_in(Ecore_IMF_Context *ctx)
416 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
418 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
419 "ecore_imf_context_focus_in");
422 if (ctx->klass->focus_in) ctx->klass->focus_in(ctx);
426 * Notify the Input Method Context that the widget to which its
427 * correspond has lost focus.
429 * @param ctx An #Ecore_IMF_Context.
430 * @ingroup Ecore_IMF_Context_Group
433 ecore_imf_context_focus_out(Ecore_IMF_Context *ctx)
435 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
437 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
438 "ecore_imf_context_focus_out");
441 if (ctx->klass->focus_out) ctx->klass->focus_out(ctx);
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.
449 * @param ctx An #Ecore_IMF_Context.
450 * @ingroup Ecore_IMF_Context_Group
453 ecore_imf_context_reset(Ecore_IMF_Context *ctx)
455 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
457 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
458 "ecore_imf_context_reset");
461 if (ctx->klass->reset) ctx->klass->reset(ctx);
465 * Notify the Input Method Context that a change in the cursor
466 * position has been made.
468 * @param ctx An #Ecore_IMF_Context.
469 * @param cursor_pos New cursor position in characters.
470 * @ingroup Ecore_IMF_Context_Group
473 ecore_imf_context_cursor_position_set(Ecore_IMF_Context *ctx, int cursor_pos)
475 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
477 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
478 "ecore_imf_context_cursor_position_set");
481 if (ctx->klass->cursor_position_set) ctx->klass->cursor_position_set(ctx, cursor_pos);
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.
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
495 ecore_imf_context_use_preedit_set(Ecore_IMF_Context *ctx, Eina_Bool use_preedit)
497 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
499 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
500 "ecore_imf_context_use_preedit_set");
503 if (ctx->klass->use_preedit_set) ctx->klass->use_preedit_set(ctx, use_preedit);
507 * Set the callback to be used on get_surrounding request.
509 * This callback will be called when the Input Method Context
510 * module requests the surrounding context.
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
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)
520 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
522 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
523 "ecore_imf_context_retrieve_surrounding_callback_set");
527 ctx->retrieve_surrounding_func = func;
528 ctx->retrieve_surrounding_data = (void *) data;
532 * Set the input mode used by the Ecore Input Context.
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.
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
542 EINA_DEPRECATED EAPI void
543 ecore_imf_context_input_mode_set(Ecore_IMF_Context *ctx, Ecore_IMF_Input_Mode input_mode)
545 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
547 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
548 "ecore_imf_context_input_mode_set");
551 if (ctx->klass->input_mode_set) ctx->klass->input_mode_set(ctx, input_mode);
552 ctx->input_mode = input_mode;
556 * Get the input mode being used by the Ecore Input Context.
558 * See @ref ecore_imf_context_input_mode_set for more details.
560 * @param ctx An #Ecore_IMF_Context.
561 * @return The input mode being used by @p ctx.
562 * @ingroup Ecore_IMF_Context_Group
564 EINA_DEPRECATED EAPI Ecore_IMF_Input_Mode
565 ecore_imf_context_input_mode_get(Ecore_IMF_Context *ctx)
567 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
569 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
570 "ecore_imf_context_input_mode_set");
573 return ctx->input_mode;
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.
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.
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
592 ecore_imf_context_filter_event(Ecore_IMF_Context *ctx, Ecore_IMF_Event_Type type, Ecore_IMF_Event *event)
594 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
596 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
597 "ecore_imf_context_filter_event");
600 if (ctx->klass->filter_event) return ctx->klass->filter_event(ctx, type, event);
605 * @defgroup Ecore_IMF_Context_Module_Group Ecore Input Method Context Module Functions
607 * Functions that should be used by Ecore Input Method Context modules.
611 * Creates a new Input Method Context with klass specified by @p ctxc.
613 * This method should be used by modules implementing the Input
614 * Method Context interface.
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
620 EAPI Ecore_IMF_Context *
621 ecore_imf_context_new(const Ecore_IMF_Context_Class *ctxc)
623 Ecore_IMF_Context *ctx;
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);
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;
646 * Set the Input Method Context specific data.
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.
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
658 ecore_imf_context_data_set(Ecore_IMF_Context *ctx, void *data)
660 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
662 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
663 "ecore_imf_context_data_set");
670 * Get the Input Method Context specific data.
672 * See @ref ecore_imf_context_data_set for more details.
674 * @param ctx An #Ecore_IMF_Context.
675 * @return The Input Method Context specific data.
676 * @ingroup Ecore_IMF_Context_Module_Group
678 EAPI void *ecore_imf_context_data_get(Ecore_IMF_Context *ctx)
680 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
682 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
683 "ecore_imf_context_data_get");
690 * Retrieve context around insertion point.
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).
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.
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
711 ecore_imf_context_surrounding_get(Ecore_IMF_Context *ctx, char **text, int *cursor_pos)
713 int result = EINA_FALSE;
715 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
717 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
718 "ecore_imf_context_surrounding_get");
722 if (ctx->retrieve_surrounding_func)
724 result = ctx->retrieve_surrounding_func(ctx->retrieve_surrounding_data, ctx, text, cursor_pos);
727 if (text) *text = NULL;
728 if (cursor_pos) *cursor_pos = 0;
735 _ecore_imf_event_free_preedit(void *data __UNUSED__, void *event)
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.
744 * @param ctx An #Ecore_IMF_Context.
745 * @ingroup Ecore_IMF_Context_Module_Group
748 ecore_imf_context_preedit_start_event_add(Ecore_IMF_Context *ctx)
750 Ecore_IMF_Event_Commit *ev;
752 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
754 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
755 "ecore_imf_context_preedit_start_event_add");
759 ev = malloc(sizeof(Ecore_IMF_Event_Preedit_Start));
761 ecore_event_add(ECORE_IMF_EVENT_PREEDIT_START,
762 ev, _ecore_imf_event_free_preedit, NULL);
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.
769 * @param ctx An #Ecore_IMF_Context.
770 * @ingroup Ecore_IMF_Context_Module_Group
773 ecore_imf_context_preedit_end_event_add(Ecore_IMF_Context *ctx)
775 Ecore_IMF_Event_Commit *ev;
777 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
779 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
780 "ecore_imf_context_preedit_end_event_add");
784 ev = malloc(sizeof(Ecore_IMF_Event_Preedit_End));
786 ecore_event_add(ECORE_IMF_EVENT_PREEDIT_END,
787 ev, _ecore_imf_event_free_preedit, NULL);
791 * Adds ECORE_IMF_EVENT_PREEDIT_CHANGED to the event queue.
793 * @param ctx An #Ecore_IMF_Context.
794 * @ingroup Ecore_IMF_Context_Module_Group
797 ecore_imf_context_preedit_changed_event_add(Ecore_IMF_Context *ctx)
799 Ecore_IMF_Event_Commit *ev;
801 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
803 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
804 "ecore_imf_context_preedit_changed_event_add");
808 ev = malloc(sizeof(Ecore_IMF_Event_Preedit_Changed));
810 ecore_event_add(ECORE_IMF_EVENT_PREEDIT_CHANGED,
811 ev, _ecore_imf_event_free_preedit, NULL);
815 _ecore_imf_event_free_commit(void *data __UNUSED__, void *event)
817 Ecore_IMF_Event_Commit *ev;
820 if (ev->str) free(ev->str);
825 * Adds ECORE_IMF_EVENT_COMMIT to the event queue.
827 * @param ctx An #Ecore_IMF_Context.
828 * @param str The committed string.
829 * @ingroup Ecore_IMF_Context_Module_Group
832 ecore_imf_context_commit_event_add(Ecore_IMF_Context *ctx, const char *str)
834 Ecore_IMF_Event_Commit *ev;
836 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
838 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
839 "ecore_imf_context_commit_event_add");
843 ev = malloc(sizeof(Ecore_IMF_Event_Commit));
845 ev->str = str ? strdup(str) : NULL;
846 ecore_event_add(ECORE_IMF_EVENT_COMMIT,
847 ev, _ecore_imf_event_free_commit, NULL);
852 _ecore_imf_event_free_delete_surrounding(void *data __UNUSED__, void *event)
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.
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
868 ecore_imf_context_delete_surrounding_event_add(Ecore_IMF_Context *ctx, int offset, int n_chars)
870 Ecore_IMF_Event_Delete_Surrounding *ev;
872 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
874 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
875 "ecore_imf_context_delete_surrounding_event_add");
879 ev = malloc(sizeof(Ecore_IMF_Event_Delete_Surrounding));
882 ev->n_chars = n_chars;
883 ecore_event_add(ECORE_IMF_EVENT_DELETE_SURROUNDING,
884 ev, _ecore_imf_event_free_delete_surrounding, NULL);
887 /*** ImControl Related APIs */
889 ecore_imf_context_input_panel_show(Ecore_IMF_Context *ctx)
891 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
893 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_show");
897 if (ctx->klass->show) ctx->klass->show(ctx);
901 ecore_imf_context_input_panel_hide(Ecore_IMF_Context *ctx)
903 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
905 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_hide");
909 if (ctx->klass->hide) ctx->klass->hide(ctx);
913 ecore_imf_context_control_panel_show (Ecore_IMF_Context *ctx)
915 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
917 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_control_panel_show");
921 if (ctx->klass->control_panel_show) ctx->klass->control_panel_show(ctx);
925 ecore_imf_context_control_panel_hide (Ecore_IMF_Context *ctx)
927 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
929 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_control_panel_hide");
933 if (ctx->klass->control_panel_hide) ctx->klass->control_panel_hide(ctx);
937 ecore_imf_context_input_panel_language_set (Ecore_IMF_Context *ctx, Ecore_IMF_Input_Panel_Lang lang)
939 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
941 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_language_set");
945 if (ctx->klass->input_panel_language_set) ctx->klass->input_panel_language_set(ctx, lang);
946 ctx->input_panel_lang = lang;
949 EAPI Ecore_IMF_Input_Panel_Lang
950 ecore_imf_context_input_panel_language_get (Ecore_IMF_Context *ctx)
952 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
954 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_language_get");
955 return ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC;
958 return ctx->input_panel_lang;
962 ecore_imf_context_ise_get_ise_language (Ecore_IMF_Context *ctx, const char* ise_name, char ***langlist)
964 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
966 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_ise_get_ise_language");
972 printf ("input parameters error!!! \n");
976 if (ctx->klass->ise_get_ise_language)
977 return ctx->klass->ise_get_ise_language(ctx, ise_name, langlist);
983 ecore_imf_context_keyboard_language_set (Ecore_IMF_Context *ctx, Ecore_IMF_Keyboard_Lang lang)
985 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
987 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_keyboard_language_set");
990 // if (ctx->klass->ise_set_language) ctx->klass->ise_set_language(ctx, lang);
993 EAPI Ecore_IMF_Keyboard_Lang
994 ecore_imf_context_keyboard_language_get (Ecore_IMF_Context *ctx)
996 Ecore_IMF_Keyboard_Lang lang = ECORE_IMF_KEYBOARD_LANG_NATIVE;
998 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1000 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_keyboard_language_get");
1004 if (ctx->klass->input_panel_language_get)
1005 lang = ctx->klass->input_panel_language_get(ctx);
1011 ecore_imf_context_ise_set_isf_language (Ecore_IMF_Context *ctx, const char* lang)
1013 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1015 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_ise_set_isf_language");
1021 printf ("input parameters error!!! \n");
1025 if (ctx->klass->ise_set_isf_language) ctx->klass->ise_set_isf_language(ctx, lang);
1029 ecore_imf_context_input_panel_imdata_set (Ecore_IMF_Context *ctx, const char * data, int len)
1031 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1033 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_imdata_set");
1037 if (!data || len <=0)
1039 printf ("input parameters error!!! \n");
1043 if (ctx->klass->input_panel_imdata_set) ctx->klass->input_panel_imdata_set(ctx, data, len);
1047 ecore_imf_context_input_panel_imdata_get (Ecore_IMF_Context *ctx, char * data, int *len)
1049 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1051 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_get_imdata");
1057 printf ("input parameters error!!! \n");
1061 if (ctx->klass->input_panel_imdata_get) ctx->klass->input_panel_imdata_get(ctx, data, len);
1065 ecore_imf_context_input_panel_use_effect_set (Ecore_IMF_Context *ctx, Eina_Bool use_effect)
1067 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1069 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_use_effect_set");
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;
1078 ecore_imf_context_input_panel_use_effect_get (Ecore_IMF_Context *ctx)
1080 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1082 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_use_effect_get");
1086 return ctx->use_effect;
1090 ecore_imf_context_input_panel_geometry_get (Ecore_IMF_Context *ctx, int *x, int *y, int *w, int *h)
1092 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1094 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_geometry_get");
1098 if (ctx->klass->input_panel_geometry_get) ctx->klass->input_panel_geometry_get(ctx, x, y, w, h);
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)
1104 Private_Key_Item *key_item;
1106 Eina_Bool exist = EINA_FALSE;
1108 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1110 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_private_key_set");
1114 if (!label && !img_path)
1116 printf ("input parameters error!!! \n");
1120 EINA_LIST_FOREACH(ctx->private_key_list, l, key_item)
1122 if (key_item && key_item->layout_idx == layout_index &&
1123 key_item->key_idx == key_index)
1125 // if exist in the list
1130 strcpy(key_item->data, label);
1135 strcpy(key_item->data, img_path);
1137 key_item->key_value = key_value;
1138 strcpy(key_item->key_string, key_string);
1144 key_item = calloc(1, sizeof(Private_Key_Item));
1145 if (!key_item) return;
1147 key_item->layout_idx = layout_index;
1148 key_item->key_idx = key_index;;
1152 strcpy(key_item->data, label);
1157 strcpy(key_item->data, img_path);
1159 key_item->key_value = key_value;
1163 strcpy(key_item->key_string, key_string);
1166 ctx->private_key_list = eina_list_append(ctx->private_key_list, key_item);
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);
1173 ecore_imf_context_input_panel_private_key_list_get (Ecore_IMF_Context *ctx)
1175 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1177 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_private_key_list_get");
1181 return ctx->private_key_list;
1185 ecore_imf_context_input_panel_key_disabled_set (Ecore_IMF_Context *ctx, int layout_index, int key_index, Eina_Bool disabled)
1187 Disable_Key_Item *key_item;
1189 Eina_Bool exist = EINA_FALSE;
1191 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1193 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_key_disabled_set");
1197 EINA_LIST_FOREACH(ctx->disabled_key_list, l, key_item)
1199 if (key_item && key_item->layout_idx == layout_index && key_item->key_idx == key_index)
1201 key_item->disabled = disabled;
1208 key_item = calloc(1, sizeof(Disable_Key_Item));
1209 if (!key_item) return;
1211 key_item->layout_idx = layout_index;
1212 key_item->key_idx = key_index;;
1213 key_item->disabled = disabled;
1215 ctx->disabled_key_list = eina_list_append(ctx->disabled_key_list, key_item);
1218 // if (ctx->klass->input_panel_key_disabled_set) ctx->klass->input_panel_key_disabled_set(ctx, layout_index, key_index, disabled);
1222 ecore_imf_context_input_panel_key_disabled_list_get (Ecore_IMF_Context *ctx)
1224 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1226 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_key_disabled_list_get");
1230 return ctx->disabled_key_list;
1234 ecore_imf_context_input_panel_event_callback_list_get (Ecore_IMF_Context *ctx)
1236 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1238 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_event_callback_list_get");
1242 return ctx->callbacks;
1246 ecore_imf_context_input_panel_layout_set (Ecore_IMF_Context *ctx, Ecore_IMF_Input_Panel_Layout layout)
1248 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1250 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_layout_set");
1254 if (ctx->klass->input_panel_layout_set) ctx->klass->input_panel_layout_set(ctx, layout);
1255 ctx->input_panel_layout = layout;
1258 EAPI Ecore_IMF_Input_Panel_Layout
1259 ecore_imf_context_input_panel_layout_get (Ecore_IMF_Context *ctx)
1261 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1263 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_layout_get");
1264 return ECORE_IMF_INPUT_PANEL_LAYOUT_INVALID;
1267 if (ctx->klass->input_panel_layout_get)
1269 // ctx->klass->input_panel_layout_get (ctx, &layout);
1270 return ctx->input_panel_layout;
1273 return ECORE_IMF_INPUT_PANEL_LAYOUT_INVALID;
1277 ecore_imf_context_input_panel_reset (Ecore_IMF_Context *ctx)
1279 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1281 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_reset");
1285 if (ctx->klass->input_panel_reset) ctx->klass->input_panel_reset(ctx);
1289 ecore_imf_context_input_panel_orient_set (Ecore_IMF_Context *ctx, Ecore_IMF_Input_Panel_Orient orientation)
1291 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1293 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_orient_set");
1297 if (ctx->klass->input_panel_orient_set) ctx->klass->input_panel_orient_set(ctx, orientation*90);
1298 ctx->input_panel_orient = orientation;
1301 EAPI Ecore_IMF_Input_Panel_Orient
1302 ecore_imf_context_input_panel_orient_get (Ecore_IMF_Context *ctx)
1304 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1306 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_orient_get");
1307 return ECORE_IMF_INPUT_PANEL_ORIENT_NONE;
1310 return ctx->input_panel_orient;
1314 ecore_imf_context_ise_get_active_isename (Ecore_IMF_Context *ctx, char* name)
1316 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1318 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_ise_get_active_isename");
1324 printf ("input parameters error!!! \n");
1328 if (ctx->klass->ise_get_active_isename) ctx->klass->ise_get_active_isename(ctx, name);
1332 ecore_imf_context_ise_set_active_ise_by_name (Ecore_IMF_Context *ctx, const char* name)
1334 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1336 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_ise_set_active_ise_by_name");
1342 printf ("input parameters error!!! \n");
1346 if (ctx->klass->ise_set_active_ise_by_name) ctx->klass->ise_set_active_ise_by_name(ctx, name);
1350 ecore_imf_context_ise_set_active_ise_by_uuid (Ecore_IMF_Context *ctx, const char* uuid)
1352 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1354 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_ise_set_active_ise_by_uuid");
1360 printf ("input parameters error!!! \n");
1364 if (ctx->klass->ise_set_active_ise_by_uuid) ctx->klass->ise_set_active_ise_by_uuid(ctx, uuid);
1368 ecore_imf_context_ise_get_iselist (Ecore_IMF_Context *ctx, char*** iselist)
1370 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1372 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_ise_get_iselist");
1376 if (ctx->klass->ise_get_iselist)
1377 return ctx->klass->ise_get_iselist(ctx, iselist);
1382 EAPI Ecore_IMF_Input_Panel_State
1383 ecore_imf_context_input_panel_state_get (Ecore_IMF_Context *ctx)
1385 Ecore_IMF_Input_Panel_State state = ECORE_IMF_INPUT_PANEL_STATE_INVALID;
1386 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1388 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_state_get");
1389 return ECORE_IMF_INPUT_PANEL_STATE_INVALID;
1392 if (ctx->klass->input_panel_state_get)
1393 state = ctx->klass->input_panel_state_get(ctx);
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)
1401 Ecore_IMF_Input_Panel_Event_Callback *it;
1403 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1405 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_event_callback_add");
1409 if (ctx->klass->input_panel_event_callback_add)
1411 it = calloc(1, sizeof(Ecore_IMF_Input_Panel_Event_Callback));
1418 ctx->callbacks = eina_list_append(ctx->callbacks, it);
1420 ctx->klass->input_panel_event_callback_add(ctx, type, func, data);
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))
1428 Ecore_IMF_Input_Panel_Event_Callback *it;
1430 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1432 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_event_callback_del");
1436 if (ctx->klass->input_panel_event_callback_del)
1438 for (l = ctx->callbacks; l;)
1440 it = (Ecore_IMF_Input_Panel_Event_Callback *)l->data;
1442 if (it && it->func == func && it->type == type)
1444 ctx->callbacks = eina_list_remove(ctx->callbacks, it);
1451 ctx->klass->input_panel_event_callback_del(ctx, type, func);
1456 ecore_imf_context_input_panel_move (Ecore_IMF_Context *ctx, int x, int y)
1458 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1460 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_move");
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;
1470 ecore_imf_context_input_panel_caps_mode_set (Ecore_IMF_Context *ctx, Ecore_IMF_Input_Panel_Caps_Mode mode)
1472 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1474 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,"ecore_imf_context_input_panel_caps_mode_set");
1478 if (ctx->klass->input_panel_caps_mode_set) ctx->klass->input_panel_caps_mode_set(ctx, mode);