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 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
228 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
229 "ecore_imf_context_del");
232 if (ctx->klass->del) ctx->klass->del(ctx);
233 ECORE_MAGIC_SET(ctx, ECORE_MAGIC_NONE);
238 * Set the client window for the Input Method Context; this is the
239 * Ecore_X_Window when using X11, Ecore_Win32_Window when using Win32, etc.
240 * This window is used in order to correctly position status windows, and may
241 * also be used for purposes internal to the Input Method Context.
243 * @param ctx An #Ecore_IMF_Context.
244 * @param window The client window. This may be NULL to indicate
245 * that the previous client window no longer exists.
246 * @ingroup Ecore_IMF_Context_Group
249 ecore_imf_context_client_window_set(Ecore_IMF_Context *ctx, void *window)
251 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
253 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
254 "ecore_imf_context_client_window_set");
257 if (ctx->klass->client_window_set) ctx->klass->client_window_set(ctx, window);
258 ctx->window = window;
262 * Get the client window of the Input Method Context
264 * See @ref ecore_imf_context_client_window_set for more details.
266 * @param ctx An #Ecore_IMF_Context.
267 * @return Return the client window.
268 * @ingroup Ecore_IMF_Context_Group
272 ecore_imf_context_client_window_get(Ecore_IMF_Context *ctx)
274 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
276 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
277 "ecore_imf_context_client_window_get");
284 * Set the client canvas for the Input Method Context; this is the
285 * canvas in which the input appears.
286 * The canvas type can be determined by using the context canvas type.
287 * Actually only canvas with type "evas" (Evas *) is supported.
288 * This canvas may be used in order to correctly position status windows, and may
289 * also be used for purposes internal to the Input Method Context.
291 * @param ctx An #Ecore_IMF_Context.
292 * @param canvas The client canvas. This may be NULL to indicate
293 * that the previous client canvas no longer exists.
294 * @ingroup Ecore_IMF_Context_Group
297 ecore_imf_context_client_canvas_set(Ecore_IMF_Context *ctx, void *canvas)
299 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
301 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
302 "ecore_imf_context_client_canvas_set");
305 if (ctx->klass->client_canvas_set) ctx->klass->client_canvas_set(ctx, canvas);
306 ctx->client_canvas = canvas;
310 * Get the client canvas of the Input Method Context.
312 * See @ref ecore_imf_context_client_canvas_set for more details.
314 * @param ctx An #Ecore_IMF_Context.
315 * @return Return the client canvas.
316 * @ingroup Ecore_IMF_Context_Group
320 ecore_imf_context_client_canvas_get(Ecore_IMF_Context *ctx)
322 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
324 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
325 "ecore_imf_context_client_canvas_get");
328 return ctx->client_canvas;
332 * Ask the Input Method Context to show itself.
334 * @param ctx An #Ecore_IMF_Context.
335 * @ingroup Ecore_IMF_Context_Group
338 ecore_imf_context_show(Ecore_IMF_Context *ctx)
340 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
342 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
343 "ecore_imf_context_show");
346 if (ctx->klass->show) ctx->klass->show(ctx);
350 * Ask the Input Method Context to hide itself.
352 * @param ctx An #Ecore_IMF_Context.
353 * @ingroup Ecore_IMF_Context_Group
356 ecore_imf_context_hide(Ecore_IMF_Context *ctx)
358 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
360 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
361 "ecore_imf_context_hide");
364 if (ctx->klass->hide) ctx->klass->hide(ctx);
368 * Retrieve the current preedit string and cursor position
369 * for the Input Method Context.
371 * @param ctx An #Ecore_IMF_Context.
372 * @param str Location to store the retrieved string. The
373 * string retrieved must be freed with free().
374 * @param cursor_pos Location to store position of cursor (in characters)
375 * within the preedit string.
376 * @ingroup Ecore_IMF_Context_Group
379 ecore_imf_context_preedit_string_get(Ecore_IMF_Context *ctx, char **str, int *cursor_pos)
381 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
383 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
384 "ecore_imf_context_preedit_string_get");
387 if (ctx->klass->preedit_string_get)
388 ctx->klass->preedit_string_get(ctx, str, cursor_pos);
391 if (str) *str = strdup("");
392 if (cursor_pos) *cursor_pos = 0;
397 * Retrieve the current preedit string, atrributes and
398 * cursor position for the Input Method Context.
400 * @param ctx An #Ecore_IMF_Context.
401 * @param str Location to store the retrieved string. The
402 * string retrieved must be freed with free().
403 * @param attrs an Eina_List of attributes
404 * @param cursor_pos Location to store position of cursor (in characters)
405 * within the preedit string.
406 * @ingroup Ecore_IMF_Context_Group
410 ecore_imf_context_preedit_string_with_attributes_get(Ecore_IMF_Context *ctx, char **str, Eina_List **attrs, int *cursor_pos)
412 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
414 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
415 "ecore_imf_context_preedit_string_with_attributes_get");
418 if (ctx->klass->preedit_string_with_attributes_get)
419 ctx->klass->preedit_string_with_attributes_get(ctx, str, attrs, cursor_pos);
422 if (str) *str = strdup("");
423 if (attrs) *attrs = NULL;
424 if (cursor_pos) *cursor_pos = 0;
429 * Notify the Input Method Context that the widget to which its
430 * correspond has gained focus.
432 * @param ctx An #Ecore_IMF_Context.
433 * @ingroup Ecore_IMF_Context_Group
436 ecore_imf_context_focus_in(Ecore_IMF_Context *ctx)
438 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
440 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
441 "ecore_imf_context_focus_in");
444 if (ctx->klass->focus_in) ctx->klass->focus_in(ctx);
448 * Notify the Input Method Context that the widget to which its
449 * correspond has lost focus.
451 * @param ctx An #Ecore_IMF_Context.
452 * @ingroup Ecore_IMF_Context_Group
455 ecore_imf_context_focus_out(Ecore_IMF_Context *ctx)
457 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
459 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
460 "ecore_imf_context_focus_out");
463 if (ctx->klass->focus_out) ctx->klass->focus_out(ctx);
467 * Notify the Input Method Context that a change such as a
468 * change in cursor position has been made. This will typically
469 * cause the Input Method Context to clear the preedit state.
471 * @param ctx An #Ecore_IMF_Context.
472 * @ingroup Ecore_IMF_Context_Group
475 ecore_imf_context_reset(Ecore_IMF_Context *ctx)
477 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
479 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
480 "ecore_imf_context_reset");
483 if (ctx->klass->reset) ctx->klass->reset(ctx);
487 * Notify the Input Method Context that a change in the cursor
488 * position has been made.
490 * @param ctx An #Ecore_IMF_Context.
491 * @param cursor_pos New cursor position in characters.
492 * @ingroup Ecore_IMF_Context_Group
495 ecore_imf_context_cursor_position_set(Ecore_IMF_Context *ctx, int cursor_pos)
497 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
499 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
500 "ecore_imf_context_cursor_position_set");
503 if (ctx->klass->cursor_position_set) ctx->klass->cursor_position_set(ctx, cursor_pos);
507 * Notify the Input Method Context that a change in the cursor
508 * location has been made. The location is relative to the canvas.
510 * @param ctx An #Ecore_IMF_Context.
511 * @param x cursor x position.
512 * @param x cursor y position.
513 * @param w cursor width.
514 * @param h cursor height.
515 * @ingroup Ecore_IMF_Context_Group
519 ecore_imf_context_cursor_location_set(Ecore_IMF_Context *ctx, int x, int y, int w, int h)
521 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
523 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
524 "ecore_imf_context_cursor_location_set");
527 if (ctx->klass->cursor_location_set) ctx->klass->cursor_location_set(ctx, x, y, w, h);
531 * Set whether the IM context should use the preedit string
532 * to display feedback. If @c use_preedit is EINA_FALSE (default
533 * is EINA_TRUE), then the IM context may use some other method to display
534 * feedback, such as displaying it in a child of the root window.
536 * @param ctx An #Ecore_IMF_Context.
537 * @param use_preedit Whether the IM context should use the preedit string.
538 * @ingroup Ecore_IMF_Context_Group
541 ecore_imf_context_use_preedit_set(Ecore_IMF_Context *ctx, Eina_Bool use_preedit)
543 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
545 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
546 "ecore_imf_context_use_preedit_set");
549 if (ctx->klass->use_preedit_set) ctx->klass->use_preedit_set(ctx, use_preedit);
553 * Set whether the IM context should allow to use the text prediction.
554 * If @c prediction is EINA_FALSE (default is EINA_TRUE), then the IM context will not display the text prediction window.
556 * @param ctx An #Ecore_IMF_Context.
557 * @param prediction Whether the IM context should allow to use the text prediction.
558 * @ingroup Ecore_IMF_Context_Group
562 ecore_imf_context_prediction_allow_set(Ecore_IMF_Context *ctx, Eina_Bool prediction)
564 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
566 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
567 "ecore_imf_context_prediction_allow_set");
571 ctx->allow_prediction = prediction;
573 if (ctx->klass->prediction_allow_set)
574 ctx->klass->prediction_allow_set(ctx, prediction);
578 * Get whether the IM context should allow to use the text prediction.
580 * @param ctx An #Ecore_IMF_Context.
581 * @return EINA_TRUE if it allows to use the text prediction, otherwise EINA_FALSE.
582 * @ingroup Ecore_IMF_Context_Group
586 ecore_imf_context_prediction_allow_get(Ecore_IMF_Context *ctx)
588 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
590 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
591 "ecore_imf_context_prediction_allow_get");
595 return ctx->allow_prediction;
599 * Set the autocapitalization type on the immodule.
601 * @param ctx An #Ecore_IMF_Context.
602 * @param autocapital_type the autocapitalization type.
603 * @ingroup Ecore_IMF_Context_Group
607 ecore_imf_context_autocapital_type_set(Ecore_IMF_Context *ctx, Ecore_IMF_Autocapital_Type autocapital_type)
609 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
611 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
612 "ecore_imf_context_autocapital_type_set");
616 ctx->autocapital_type = autocapital_type;
618 if (ctx->klass->autocapital_type_set) ctx->klass->autocapital_type_set(ctx, autocapital_type);
622 * Get the autocapitalization type.
624 * @param ctx An #Ecore_IMF_Context.
625 * @return The autocapital type being used by @p ctx.
626 * @ingroup Ecore_IMF_Context_Group
629 EAPI Ecore_IMF_Autocapital_Type
630 ecore_imf_context_autocapital_type_get(Ecore_IMF_Context *ctx)
632 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
634 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
635 "ecore_imf_context_autocapital_allow_get");
636 return ECORE_IMF_AUTOCAPITAL_TYPE_NONE;
639 return ctx->autocapital_type;
643 * Set the callback to be used on get_surrounding request.
645 * This callback will be called when the Input Method Context
646 * module requests the surrounding context.
648 * @param ctx An #Ecore_IMF_Context.
649 * @param func The callback to be called.
650 * @param data The data pointer to be passed to @p func
651 * @ingroup Ecore_IMF_Context_Group
654 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)
656 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
658 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
659 "ecore_imf_context_retrieve_surrounding_callback_set");
663 ctx->retrieve_surrounding_func = func;
664 ctx->retrieve_surrounding_data = (void *) data;
668 * Set the input mode used by the Ecore Input Context.
670 * The input mode can be one of the input modes defined in
671 * #Ecore_IMF_Input_Mode. The default input mode is
672 * ECORE_IMF_INPUT_MODE_FULL.
674 * @param ctx An #Ecore_IMF_Context.
675 * @param input_mode The input mode to be used by @p ctx.
676 * @ingroup Ecore_IMF_Context_Group
679 ecore_imf_context_input_mode_set(Ecore_IMF_Context *ctx, Ecore_IMF_Input_Mode input_mode)
681 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
683 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
684 "ecore_imf_context_input_mode_set");
687 if (ctx->klass->input_mode_set) ctx->klass->input_mode_set(ctx, input_mode);
688 ctx->input_mode = input_mode;
692 * Get the input mode being used by the Ecore Input Context.
694 * See @ref ecore_imf_context_input_mode_set for more details.
696 * @param ctx An #Ecore_IMF_Context.
697 * @return The input mode being used by @p ctx.
698 * @ingroup Ecore_IMF_Context_Group
700 EAPI Ecore_IMF_Input_Mode
701 ecore_imf_context_input_mode_get(Ecore_IMF_Context *ctx)
703 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
705 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
706 "ecore_imf_context_input_mode_set");
709 return ctx->input_mode;
713 * Allow an Ecore Input Context to internally handle an event.
714 * If this function returns EINA_TRUE, then no further processing
715 * should be done for this event.
717 * Input methods must be able to accept all types of events (simply
718 * returning EINA_FALSE if the event was not handled), but there is no
719 * obligation of any events to be submitted to this function.
721 * @param ctx An #Ecore_IMF_Context.
722 * @param type The type of event defined by #Ecore_IMF_Event_Type.
723 * @param event The event itself.
724 * @return EINA_TRUE if the event was handled; otherwise EINA_FALSE.
725 * @ingroup Ecore_IMF_Context_Group
728 ecore_imf_context_filter_event(Ecore_IMF_Context *ctx, Ecore_IMF_Event_Type type, Ecore_IMF_Event *event)
730 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
732 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
733 "ecore_imf_context_filter_event");
736 if (ctx->klass->filter_event) return ctx->klass->filter_event(ctx, type, event);
741 * @defgroup Ecore_IMF_Context_Module_Group Ecore Input Method Context Module Functions
743 * Functions that should be used by Ecore Input Method Context modules.
747 * Creates a new Input Method Context with klass specified by @p ctxc.
749 * This method should be used by modules implementing the Input
750 * Method Context interface.
752 * @param ctxc An #Ecore_IMF_Context_Class.
753 * @return A new #Ecore_IMF_Context; on failure it returns NULL.
754 * @ingroup Ecore_IMF_Context_Module_Group
756 EAPI Ecore_IMF_Context *
757 ecore_imf_context_new(const Ecore_IMF_Context_Class *ctxc)
759 Ecore_IMF_Context *ctx;
761 if (!ctxc) return NULL;
762 ctx = calloc(1, sizeof(Ecore_IMF_Context));
763 if (!ctx) return NULL;
764 ECORE_MAGIC_SET(ctx, ECORE_MAGIC_CONTEXT);
767 ctx->retrieve_surrounding_func = NULL;
768 ctx->retrieve_surrounding_data = NULL;
773 * Set the Input Method Context specific data.
775 * Note that this method should be used by modules to set
776 * the Input Method Context specific data and it's not meant to
777 * be used by applications to store application specific data.
779 * @param ctx An #Ecore_IMF_Context.
780 * @param data The Input Method Context specific data.
781 * @return A new #Ecore_IMF_Context; on failure it returns NULL.
782 * @ingroup Ecore_IMF_Context_Module_Group
785 ecore_imf_context_data_set(Ecore_IMF_Context *ctx, void *data)
787 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
789 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
790 "ecore_imf_context_data_set");
797 * Get the Input Method Context specific data.
799 * See @ref ecore_imf_context_data_set for more details.
801 * @param ctx An #Ecore_IMF_Context.
802 * @return The Input Method Context specific data.
803 * @ingroup Ecore_IMF_Context_Module_Group
805 EAPI void *ecore_imf_context_data_get(Ecore_IMF_Context *ctx)
807 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
809 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
810 "ecore_imf_context_data_get");
817 * Retrieve context around insertion point.
819 * This function is implemented by calling the
820 * Ecore_IMF_Context::retrieve_surrounding_func (
821 * set using #ecore_imf_context_retrieve_surrounding_callback_set).
823 * There is no obligation for a widget to respond to the
824 * ::retrieve_surrounding_func, so input methods must be prepared
825 * to function without context.
827 * @param ctx An #Ecore_IMF_Context.
828 * @param text Location to store a UTF-8 encoded string of text
829 * holding context around the insertion point.
830 * If the function returns EINA_TRUE, then you must free
831 * the result stored in this location with free().
832 * @param cursor_pos Location to store the position in characters of
833 * the insertion cursor within @text.
834 * @return EINA_TRUE if surrounding text was provided; otherwise EINA_FALSE.
835 * @ingroup Ecore_IMF_Context_Module_Group
838 ecore_imf_context_surrounding_get(Ecore_IMF_Context *ctx, char **text, int *cursor_pos)
840 int result = EINA_FALSE;
842 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
844 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
845 "ecore_imf_context_surrounding_get");
849 if (ctx->retrieve_surrounding_func)
851 result = ctx->retrieve_surrounding_func(ctx->retrieve_surrounding_data, ctx, text, cursor_pos);
854 if (text) *text = NULL;
855 if (cursor_pos) *cursor_pos = 0;
862 _ecore_imf_event_free_preedit(void *data __UNUSED__, void *event)
868 * Adds ECORE_IMF_EVENT_PREEDIT_START to the event queue.
870 * ECORE_IMF_EVENT_PREEDIT_START should be added when a new preedit sequence starts.
872 * @param ctx An #Ecore_IMF_Context.
873 * @ingroup Ecore_IMF_Context_Module_Group
876 ecore_imf_context_preedit_start_event_add(Ecore_IMF_Context *ctx)
878 Ecore_IMF_Event_Commit *ev;
880 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
882 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
883 "ecore_imf_context_preedit_start_event_add");
887 ev = malloc(sizeof(Ecore_IMF_Event_Preedit_Start));
889 ecore_event_add(ECORE_IMF_EVENT_PREEDIT_START,
890 ev, _ecore_imf_event_free_preedit, NULL);
894 * Adds ECORE_IMF_EVENT_PREEDIT_END to the event queue.
896 * ECORE_IMF_EVENT_PREEDIT_END should be added when a new preedit sequence has been completed or canceled.
898 * @param ctx An #Ecore_IMF_Context.
899 * @ingroup Ecore_IMF_Context_Module_Group
902 ecore_imf_context_preedit_end_event_add(Ecore_IMF_Context *ctx)
904 Ecore_IMF_Event_Commit *ev;
906 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
908 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
909 "ecore_imf_context_preedit_end_event_add");
913 ev = malloc(sizeof(Ecore_IMF_Event_Preedit_End));
915 ecore_event_add(ECORE_IMF_EVENT_PREEDIT_END,
916 ev, _ecore_imf_event_free_preedit, NULL);
920 * Adds ECORE_IMF_EVENT_PREEDIT_CHANGED to the event queue.
922 * @param ctx An #Ecore_IMF_Context.
923 * @ingroup Ecore_IMF_Context_Module_Group
926 ecore_imf_context_preedit_changed_event_add(Ecore_IMF_Context *ctx)
928 Ecore_IMF_Event_Commit *ev;
930 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
932 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
933 "ecore_imf_context_preedit_changed_event_add");
937 ev = malloc(sizeof(Ecore_IMF_Event_Preedit_Changed));
939 ecore_event_add(ECORE_IMF_EVENT_PREEDIT_CHANGED,
940 ev, _ecore_imf_event_free_preedit, NULL);
944 _ecore_imf_event_free_commit(void *data __UNUSED__, void *event)
946 Ecore_IMF_Event_Commit *ev;
949 if (ev->str) free(ev->str);
954 * Adds ECORE_IMF_EVENT_COMMIT to the event queue.
956 * @param ctx An #Ecore_IMF_Context.
957 * @param str The committed string.
958 * @ingroup Ecore_IMF_Context_Module_Group
961 ecore_imf_context_commit_event_add(Ecore_IMF_Context *ctx, const char *str)
963 Ecore_IMF_Event_Commit *ev;
965 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
967 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
968 "ecore_imf_context_commit_event_add");
972 ev = malloc(sizeof(Ecore_IMF_Event_Commit));
974 ev->str = str ? strdup(str) : NULL;
975 ecore_event_add(ECORE_IMF_EVENT_COMMIT,
976 ev, _ecore_imf_event_free_commit, NULL);
981 _ecore_imf_event_free_delete_surrounding(void *data __UNUSED__, void *event)
987 * Adds ECORE_IMF_EVENT_DELETE_SURROUNDING to the event queue.
989 * Asks the widget that the input context is attached to to delete characters around the cursor position
990 * by adding the ECORE_IMF_EVENT_DELETE_SURROUNDING to the event queue.
991 * Note that offset and n_chars are in characters not in bytes.
993 * @param ctx An #Ecore_IMF_Context.
994 * @param offset The start offset of surrounding to be deleted.
995 * @param n_chars The number of characters to be deleted.
996 * @ingroup Ecore_IMF_Context_Module_Group
999 ecore_imf_context_delete_surrounding_event_add(Ecore_IMF_Context *ctx, int offset, int n_chars)
1001 Ecore_IMF_Event_Delete_Surrounding *ev;
1003 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1005 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1006 "ecore_imf_context_delete_surrounding_event_add");
1010 ev = malloc(sizeof(Ecore_IMF_Event_Delete_Surrounding));
1012 ev->offset = offset;
1013 ev->n_chars = n_chars;
1014 ecore_event_add(ECORE_IMF_EVENT_DELETE_SURROUNDING,
1015 ev, _ecore_imf_event_free_delete_surrounding, NULL);
1019 * Ask the Input Method Context to show the control panel of using Input Method.
1021 * @param ctx An #Ecore_IMF_Context.
1022 * @ingroup Ecore_IMF_Context_IMControl_Group
1026 ecore_imf_context_control_panel_show (Ecore_IMF_Context *ctx)
1028 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1030 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1031 "ecore_imf_context_control_panel_show");
1035 if (ctx->klass->control_panel_show) ctx->klass->control_panel_show(ctx);
1039 * Ask the Input Method Context to hide the control panel of using Input Method.
1041 * @param ctx An #Ecore_IMF_Context.
1042 * @ingroup Ecore_IMF_Context_IMControl_Group
1046 ecore_imf_context_control_panel_hide (Ecore_IMF_Context *ctx)
1048 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1050 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1051 "ecore_imf_context_control_panel_hide");
1055 if (ctx->klass->control_panel_hide) ctx->klass->control_panel_hide(ctx);
1059 * Ask the Input Method Context to show the input panel (virtual keyboard).
1061 * @param ctx An #Ecore_IMF_Context.
1062 * @ingroup Ecore_IMF_Context_IMControl_Group
1066 ecore_imf_context_input_panel_show(Ecore_IMF_Context *ctx)
1068 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1070 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1071 "ecore_imf_context_input_panel_show");
1075 if (ctx->klass->show) ctx->klass->show(ctx);
1079 * Ask the Input Method Context to hide the input panel.
1081 * @param ctx An #Ecore_IMF_Context.
1082 * @ingroup Ecore_IMF_Context_IMControl_Group
1086 ecore_imf_context_input_panel_hide(Ecore_IMF_Context *ctx)
1088 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1090 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1091 "ecore_imf_context_input_panel_hide");
1095 if (ctx->klass->hide) ctx->klass->hide(ctx);
1099 * Set the layout of the input panel.
1101 * @param ctx An #Ecore_IMF_Context.
1102 * @param layout see #ECORE_IMF_INPUT_PANEL_LAYOUT
1103 * @ingroup Ecore_IMF_Context_IMControl_Group
1107 ecore_imf_context_input_panel_layout_set (Ecore_IMF_Context *ctx, Ecore_IMF_Input_Panel_Layout layout)
1109 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1111 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1112 "ecore_imf_context_input_panel_layout_set");
1116 if (ctx->klass->input_panel_layout_set)
1117 ctx->klass->input_panel_layout_set(ctx, layout);
1119 ctx->input_panel_layout = layout;
1123 * Get the layout of the current active input panel.
1125 * @param ctx An #Ecore_IMF_Context.
1126 * @return layout see #Ecore_IMF_Input_Panel_Layout
1127 * @ingroup Ecore_IMF_Context_IMControl_Group
1130 EAPI Ecore_IMF_Input_Panel_Layout
1131 ecore_imf_context_input_panel_layout_get (Ecore_IMF_Context *ctx)
1133 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1135 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1136 "ecore_imf_context_input_panel_layout_get");
1137 return ECORE_IMF_INPUT_PANEL_LAYOUT_INVALID;
1140 if (ctx->klass->input_panel_layout_get)
1142 return ctx->input_panel_layout;
1145 return ECORE_IMF_INPUT_PANEL_LAYOUT_INVALID;
1149 * Set the language of the input panel.
1150 * This API can be used when you want to show the English keyboard.
1152 * @param ctx An #Ecore_IMF_Context.
1153 * @param lang the language to be set to the input panel.
1154 * @ingroup Ecore_IMF_Context_IMControl_Group
1158 ecore_imf_context_input_panel_language_set (Ecore_IMF_Context *ctx, Ecore_IMF_Input_Panel_Lang lang)
1160 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1162 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1163 "ecore_imf_context_input_panel_language_set");
1167 if (ctx->klass->input_panel_language_set) ctx->klass->input_panel_language_set(ctx, lang);
1168 ctx->input_panel_lang = lang;
1172 * Get the language of the input panel.
1174 * See @ref ecore_imf_context_input_panel_language_set for more details.
1176 * @param ctx An #Ecore_IMF_Context.
1177 * @return Ecore_IMF_Input_Panel_Lang
1178 * @ingroup Ecore_IMF_Context_IMControl_Group
1181 EAPI Ecore_IMF_Input_Panel_Lang
1182 ecore_imf_context_input_panel_language_get (Ecore_IMF_Context *ctx)
1184 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1186 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1187 "ecore_imf_context_input_panel_language_get");
1188 return ECORE_IMF_INPUT_PANEL_LANG_AUTOMATIC;
1191 return ctx->input_panel_lang;
1195 * Set whether the Input Method Context should request to show the input panel automatically
1196 * when the widget has focus.
1198 * @param ctx An #Ecore_IMF_Context.
1199 * @param enabled If true, the input panel will be shown when the widget is clicked or has focus.
1200 * @ingroup Ecore_IMF_Context_Group
1204 ecore_imf_context_input_panel_enabled_set (Ecore_IMF_Context *ctx,
1207 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1209 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1210 "ecore_imf_context_input_panel_enabled_set");
1214 ctx->input_panel_enabled = enabled;
1218 * Get whether the Input Method Context requests to show the input panel automatically.
1220 * @param ctx An #Ecore_IMF_Context.
1221 * @return Return the attribute to show the input panel automatically
1222 * @ingroup Ecore_IMF_Context_Group
1226 ecore_imf_context_input_panel_enabled_get (Ecore_IMF_Context *ctx)
1228 if (!ECORE_MAGIC_CHECK(ctx, ECORE_MAGIC_CONTEXT))
1230 ECORE_MAGIC_FAIL(ctx, ECORE_MAGIC_CONTEXT,
1231 "ecore_imf_context_input_panel_enabled_get");
1235 return ctx->input_panel_enabled;