2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include <privilege_checker_private.h>
25 #include "inputmethod_private.h"
26 #include <inputmethod.h>
27 #include "inputmethod_internal.h"
34 #define LOG_TAG "INPUTMETHOD"
38 class CCoreEventCallback : public ISCLCoreEventCallback
41 void on_run(int argc, char **argv);
43 void on_update_cursor_position(sclint ic, const sclchar *ic_uuid, sclint cursor_pos);
44 void on_update_surrounding_text(sclint ic, const sclchar *text, sclint cursor);
45 void on_focus_out(sclint ic, const sclchar *ic_uuid);
46 void on_focus_in(sclint ic, const sclchar *ic_uuid);
47 void on_ise_show(sclint ic, const int degree, Ise_Context &context);
48 void on_ise_hide(sclint ic, const sclchar *ic_uuid);
49 void on_get_geometry(sclu32 *pos_x, sclu32 *pos_y, sclu32 *width, sclu32 *height);
50 void on_set_language(Ecore_IMF_Input_Panel_Lang language);
51 void on_set_imdata(sclchar *buf, sclu32 len);
52 void on_get_imdata(sclchar **buf, sclu32 *len);
53 void on_get_language_locale(sclint ic, sclchar **locale);
54 void on_set_return_key_type(Ecore_IMF_Input_Panel_Return_Key_Type type);
55 void on_set_return_key_disable(sclu32 disabled);
56 void on_set_layout(sclu32 layout);
57 void on_reset_input_context(sclint ic, const sclchar *uuid);
58 void on_process_key_event(scim::KeyEvent &key, sclu32 *ret);
59 void on_set_display_language(const sclchar *language);
60 void on_set_rotation_degree(sclint degree);
61 void on_set_accessibility_state(sclboolean state);
62 void on_create_option_window(sclwindow window, SCLOptionWindowType type);
63 void on_destroy_option_window(sclwindow window);
64 void on_check_option_window_availability(sclboolean *ret);
65 void on_set_caps_mode(sclu32 mode);
66 void on_candidate_show(sclint ic, const sclchar *ic_uuid);
67 void on_candidate_hide(sclint ic, const sclchar *ic_uuid);
68 void on_update_lookup_table(SclCandidateTable &table);
69 void on_process_input_device_event(sclu32 &type, sclchar *data, size_t &len, sclu32 *ret);
70 void on_set_prediction_hint(const sclchar *prediction_hint);
71 void on_set_mime_type(const sclchar *mime_type);
72 void on_set_prediction_hint_data(const sclchar *key, const sclchar *value);
73 void on_set_optimization_hint(sclu32 hint);
78 ime_focus_in_cb focus_in; /**< Called when an edit field has focus */
79 ime_focus_out_cb focus_out; /**< Called when an edit field loses focus */
80 ime_surrounding_text_updated_cb surrounding_text_updated; /**< Called when an edit field responds to a request with the surrounding text */
81 ime_input_context_reset_cb input_context_reset; /**< Called to reset the input context of an edit field */
82 ime_cursor_position_updated_cb cursor_position_updated; /**< Called when the position of the cursor in an edit field changes */
83 ime_language_requested_cb language_requested; /**< Called when an edit field requests the language from the input panel */
84 ime_language_set_cb language_set; /**< Called to set the preferred language to the input panel */
85 ime_imdata_set_cb imdata_set; /**< Called to set the application specific data to deliver to the input panel */
86 ime_imdata_requested_cb imdata_requested; /**< Called when an associated text input UI control requests the application specific data from the input panel */
87 ime_layout_set_cb layout_set; /**< Called when an edit field requests the input panel to set its layout */
88 ime_return_key_type_set_cb return_key_type_set; /**< Called when an edit field requests the input panel to set the "return" key label */
89 ime_return_key_state_set_cb return_key_state_set; /**< Called when an edit field requests the input panel to enable or disable the "return" key state */
90 ime_geometry_requested_cb geometry_requested; /**< Called when an edit field requests the position and size from the input panel */
91 ime_process_key_event_cb process_key_event; /**< Called when the key event is received from the external keyboard devices */
92 ime_display_language_changed_cb display_language_changed; /**< Called when the system display language is changed */
93 ime_rotation_degree_changed_cb rotation_degree_changed; /**< Called when the device is rotated */
94 ime_accessibility_state_changed_cb accessibility_state_changed; /**< Called when Accessibility in Settings application is on or off */
95 ime_option_window_created_cb option_window_created; /**< Called to create the option window */
96 ime_option_window_destroyed_cb option_window_destroyed; /**< Called to destroy the option window */
97 ime_caps_mode_changed_cb caps_mode_changed;
98 ime_candidate_show_cb candidate_show;
99 ime_candidate_hide_cb candidate_hide;
100 ime_lookup_table_changed_cb lookup_table_changed;
101 ime_process_input_device_event_cb process_input_device_event; /**< Called when the event is received from the unconventional input devices */
102 ime_prediction_hint_set_cb prediction_hint_set;
103 ime_mime_type_set_request_cb mime_type_set;
104 ime_prediction_hint_data_set_cb prediction_hint_data_set;
105 ime_optimization_hint_set_cb optimization_hint_set;
106 void *focus_in_user_data;
107 void *focus_out_user_data;
108 void *surrounding_text_updated_user_data;
109 void *input_context_reset_user_data;
110 void *cursor_position_updated_user_data;
111 void *language_requested_user_data;
112 void *language_set_user_data;
113 void *imdata_set_user_data;
114 void *imdata_requested_user_data;
115 void *layout_set_user_data;
116 void *return_key_type_set_user_data;
117 void *return_key_state_set_user_data;
118 void *geometry_requested_user_data;
119 void *process_key_event_user_data;
120 void *display_language_changed_user_data;
121 void *rotation_degree_changed_user_data;
122 void *accessibility_state_changed_user_data;
123 void *option_window_created_user_data;
124 void *option_window_destroyed_user_data;
125 void *caps_mode_changed_user_data;
126 void *candidate_show_user_data;
127 void *candidate_hide_user_data;
128 void *lookup_table_changed_user_data;
129 void *process_input_device_event_user_data;
130 void *prediction_hint_set_user_data;
131 void *mime_type_set_user_data;
132 void *prediction_hint_data_set_user_data;
133 void *optimization_hint_set_user_data;
134 } ime_event_callback_s;
137 ime_input_device_type_e device_type;
139 } ime_device_event_s;
141 static ime_callback_s g_basic_callback = {NULL};
142 static ime_event_callback_s g_event_callback = {NULL};
143 static void *g_user_data = NULL;
144 static bool g_running = false;
146 static CCoreEventCallback g_core_event_callback;
147 CSCLCore g_core(&g_core_event_callback);
150 extern void ime_app_main(int argc, char **argv);
154 void CCoreEventCallback::on_init()
156 if (g_basic_callback.create) {
157 g_basic_callback.create(g_user_data);
161 void CCoreEventCallback::on_run(int argc, char **argv)
164 ime_app_main(argc, argv);
167 void CCoreEventCallback::on_exit()
170 if (g_basic_callback.terminate) {
171 g_basic_callback.terminate(g_user_data);
175 void CCoreEventCallback::on_update_cursor_position(sclint ic, const sclchar *ic_uuid, sclint cursor_pos)
177 if (g_event_callback.cursor_position_updated) {
178 g_event_callback.cursor_position_updated(cursor_pos, g_event_callback.cursor_position_updated_user_data);
182 void CCoreEventCallback::on_update_surrounding_text(sclint ic, const sclchar *text, sclint cursor)
184 if (g_event_callback.surrounding_text_updated) {
185 g_event_callback.surrounding_text_updated(ic, text, cursor, g_event_callback.surrounding_text_updated_user_data);
189 void CCoreEventCallback::on_focus_out(sclint ic, const sclchar *ic_uuid)
191 if (g_event_callback.focus_out) {
192 g_event_callback.focus_out(ic, g_event_callback.focus_out_user_data);
196 void CCoreEventCallback::on_focus_in(sclint ic, const sclchar *ic_uuid)
198 if (g_event_callback.focus_in) {
199 g_event_callback.focus_in(ic, g_event_callback.focus_in_user_data);
203 void CCoreEventCallback::on_ise_show(sclint ic, const int degree, Ise_Context &context)
205 if (g_basic_callback.show) {
206 struct _ime_context input_context;
208 memset(&input_context, 0, sizeof(struct _ime_context));
209 input_context.layout = context.layout;
210 input_context.layout_variation = context.layout_variation;
211 input_context.cursor_pos = context.cursor_pos;
212 input_context.autocapital_type = context.autocapital_type;
213 input_context.return_key_type = context.return_key_type;
214 input_context.return_key_disabled = context.return_key_disabled;
215 input_context.prediction_allow = context.prediction_allow;
216 input_context.password_mode = context.password_mode;
217 input_context.imdata_size = context.imdata_size;
218 input_context.input_hint = context.input_hint;
219 input_context.bidi_direction = context.bidi_direction;
220 input_context.language = context.language;
221 input_context.client_window = context.client_window;
222 input_context.caps_mode = context.caps_mode;
224 g_basic_callback.show(ic, static_cast<ime_context_h>(&input_context), g_user_data);
228 void CCoreEventCallback::on_ise_hide(sclint ic, const sclchar *ic_uuid)
230 if (g_basic_callback.hide) {
231 g_basic_callback.hide(ic, g_user_data);
235 void CCoreEventCallback::on_get_geometry(sclu32 *pos_x, sclu32 *pos_y, sclu32 *width, sclu32 *height)
237 int geometry_pos_x = 0;
238 int geometry_pos_y = 0;
239 int geometry_width = 0;
240 int geometry_height = 0;
242 if (g_event_callback.geometry_requested) {
243 g_event_callback.geometry_requested(g_event_callback.geometry_requested_user_data, &geometry_pos_x, &geometry_pos_y, &geometry_width, &geometry_height);
247 *pos_x = geometry_pos_x;
250 *pos_y = geometry_pos_y;
253 *width = geometry_width;
256 *height = geometry_height;
259 void CCoreEventCallback::on_set_language(Ecore_IMF_Input_Panel_Lang language)
261 if (g_event_callback.language_set) {
262 g_event_callback.language_set(language, g_event_callback.language_set_user_data);
266 void CCoreEventCallback::on_set_imdata(sclchar *buf, sclu32 len)
268 if (g_event_callback.imdata_set) {
269 g_event_callback.imdata_set((void *)buf, len, g_event_callback.imdata_set_user_data);
273 void CCoreEventCallback::on_get_imdata(sclchar **buf, sclu32 *len)
275 if (g_event_callback.imdata_requested) {
276 g_event_callback.imdata_requested(g_event_callback.imdata_set_user_data, (void **)buf, len);
280 void CCoreEventCallback::on_get_language_locale(sclint ic, sclchar **locale)
282 if (g_event_callback.language_requested) {
283 g_event_callback.language_requested(g_event_callback.language_requested_user_data, locale);
287 void CCoreEventCallback::on_set_return_key_type(Ecore_IMF_Input_Panel_Return_Key_Type type)
289 if (g_event_callback.return_key_type_set) {
290 g_event_callback.return_key_type_set(type, g_event_callback.return_key_type_set_user_data);
294 void CCoreEventCallback::on_set_return_key_disable(sclu32 disabled)
296 bool return_key_disabled = !!disabled;
298 if (g_event_callback.return_key_state_set) {
299 g_event_callback.return_key_state_set(return_key_disabled, g_event_callback.return_key_state_set_user_data);
303 void CCoreEventCallback::on_set_layout(sclu32 layout)
305 if (g_event_callback.layout_set) {
306 g_event_callback.layout_set(static_cast<Ecore_IMF_Input_Panel_Layout>(layout), g_event_callback.layout_set_user_data);
310 void CCoreEventCallback::on_reset_input_context(sclint ic, const sclchar *uuid)
312 if (g_event_callback.input_context_reset) {
313 g_event_callback.input_context_reset(g_event_callback.input_context_reset_user_data);
317 void CCoreEventCallback::on_process_key_event(scim::KeyEvent &key, sclu32 *ret)
319 if (g_event_callback.process_key_event) {
320 struct _ime_device_info dev_info = {key.dev_name.c_str(),
321 static_cast<Ecore_IMF_Device_Class>(key.dev_class), static_cast<Ecore_IMF_Device_Subclass>(key.dev_subclass)};
322 bool processed = g_event_callback.process_key_event(static_cast<ime_key_code_e>(key.code), static_cast<ime_key_mask_e>(key.mask),
323 static_cast<ime_device_info_h>(&dev_info), g_event_callback.process_key_event_user_data);
338 void CCoreEventCallback::on_set_display_language(const sclchar *language)
340 if (g_event_callback.display_language_changed) {
341 g_event_callback.display_language_changed(language, g_event_callback.display_language_changed_user_data);
345 void CCoreEventCallback::on_set_rotation_degree(sclint degree)
347 if (g_event_callback.rotation_degree_changed) {
348 g_event_callback.rotation_degree_changed(degree, g_event_callback.rotation_degree_changed_user_data);
352 void CCoreEventCallback::on_set_accessibility_state(sclboolean state)
354 if (g_event_callback.accessibility_state_changed) {
355 g_event_callback.accessibility_state_changed(state, g_event_callback.accessibility_state_changed_user_data);
359 void CCoreEventCallback::on_create_option_window(sclwindow window, SCLOptionWindowType type)
361 if (g_event_callback.option_window_created) {
362 g_event_callback.option_window_created(static_cast<Evas_Object*>(window), static_cast<ime_option_window_type_e>(type), g_event_callback.option_window_created_user_data);
366 void CCoreEventCallback::on_destroy_option_window(sclwindow window)
368 if (g_event_callback.option_window_destroyed) {
369 g_event_callback.option_window_destroyed(static_cast<Evas_Object*>(window), g_event_callback.option_window_destroyed_user_data);
373 void CCoreEventCallback::on_check_option_window_availability(sclboolean *ret)
376 if (g_event_callback.option_window_created) // Instead of each 3rd party keyboard, inputmethod will reply the availability of the option (setting).
383 void CCoreEventCallback::on_set_caps_mode(sclu32 mode)
385 if (g_event_callback.caps_mode_changed) {
386 g_event_callback.caps_mode_changed(mode, g_event_callback.caps_mode_changed_user_data);
390 void CCoreEventCallback::on_candidate_show(sclint ic, const sclchar *ic_uuid)
392 if (g_event_callback.candidate_show) {
393 g_event_callback.candidate_show(ic, g_event_callback.candidate_show_user_data);
397 void CCoreEventCallback::on_candidate_hide(sclint ic, const sclchar *ic_uuid)
399 if (g_event_callback.candidate_hide) {
400 g_event_callback.candidate_hide(ic, g_event_callback.candidate_hide_user_data);
404 void CCoreEventCallback::on_update_lookup_table(SclCandidateTable &table)
406 Eina_List *string_list = NULL;
408 if (g_event_callback.lookup_table_changed) {
409 vector<string>::iterator iter = table.candidate.begin();
410 for (; iter != table.candidate.end(); ++iter) {
411 string_list = eina_list_append(string_list, iter->c_str());
414 g_event_callback.lookup_table_changed(string_list, g_event_callback.lookup_table_changed_user_data);
418 void CCoreEventCallback::on_process_input_device_event(sclu32 &type, sclchar *data, size_t &len, sclu32 *ret)
422 ime_input_device_type_e device_type;
423 } ime_device_type_conv_table;
425 ime_device_type_conv_table conv_table[] = {
426 { ECORE_EVENT_DETENT_ROTATE , IME_INPUT_DEVICE_TYPE_ROTARY },
429 ime_input_device_type_e device_type = IME_INPUT_DEVICE_TYPE_UNKNOWN;
430 for (unsigned int loop = 0; loop < sizeof(conv_table) / sizeof(ime_device_type_conv_table); loop++) {
431 if ((unsigned int)(conv_table[loop].ecore_event_id) == type) {
432 device_type = conv_table[loop].device_type;
436 if (g_event_callback.process_input_device_event) {
437 ime_device_event_s device_event;
438 device_event.device_type = device_type;
439 device_event.event_data = static_cast<void*>(data);
440 void *input_data = static_cast<void*>(&device_event);
441 void *user_data = g_event_callback.process_input_device_event_user_data;
443 g_event_callback.process_input_device_event(device_type, input_data, user_data);
455 void CCoreEventCallback::on_set_prediction_hint(const sclchar *prediction_hint)
457 if (g_event_callback.prediction_hint_set) {
458 g_event_callback.prediction_hint_set(prediction_hint, g_event_callback.prediction_hint_set_user_data);
462 void CCoreEventCallback::on_set_mime_type(const sclchar *mime_type)
464 if (g_event_callback.mime_type_set) {
465 g_event_callback.mime_type_set(mime_type, g_event_callback.mime_type_set_user_data);
469 void CCoreEventCallback::on_set_prediction_hint_data(const sclchar *key, const sclchar *value)
471 if (g_event_callback.prediction_hint_data_set) {
472 g_event_callback.prediction_hint_data_set(key, value, g_event_callback.prediction_hint_data_set_user_data);
476 void CCoreEventCallback::on_set_optimization_hint(sclu32 hint)
478 if (g_event_callback.optimization_hint_set) {
479 g_event_callback.optimization_hint_set((ime_optimization_hint_e)hint, g_event_callback.optimization_hint_set_user_data);
484 ime_error_e _check_privilege()
487 ime_error_e ret = IME_ERROR_NONE;
489 if (inputmethod_cynara_initialize() == false) {
490 LOGE("inputmethod_cynara_initialize () == false");
491 return IME_ERROR_PERMISSION_DENIED;
494 snprintf(uid, 16, "%d", getuid());
495 if (check_privilege(uid, IME_PRIVILEGE) == false) {
496 LOGE("check_privilege(uid, IME_PRIVILEGE) == false. uid : %s", uid);
497 ret = IME_ERROR_PERMISSION_DENIED;
500 inputmethod_cynara_finish();
506 bool g_from_dotnet = false;
507 EXPORT_API int ime_set_dotnet_flag(bool set)
509 ime_error_e retVal = IME_ERROR_NONE;
511 retVal = _check_privilege();
512 if (retVal != IME_ERROR_NONE) return retVal;
520 EXPORT_API int ime_run(ime_callback_s *basic_cb, void *user_data)
522 ime_error_e retVal = IME_ERROR_NONE;
525 LOGE("inputmethod main loop is already running.");
526 return IME_ERROR_OPERATION_FAILED;
530 LOGE("basic callbacks pointer is null.");
531 return IME_ERROR_INVALID_PARAMETER;
534 retVal = _check_privilege();
535 if (retVal != IME_ERROR_NONE) return retVal;
537 g_basic_callback = *basic_cb;
539 if (!g_basic_callback.create || !g_basic_callback.terminate ||
540 !g_basic_callback.show || !g_basic_callback.hide) {
541 LOGE("mandatory callback funtions are not set");
542 memset(&g_basic_callback, 0, sizeof(ime_callback_s));
543 memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
544 return IME_ERROR_NO_CALLBACK_FUNCTION;
547 g_user_data = user_data;
551 LOGD("ime_run is called from dotnet");
552 return IME_ERROR_NONE;
558 LOGW("exception is thrown from g_core.run()\n");
561 memset(&g_basic_callback, 0, sizeof(ime_callback_s));
562 memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
566 return IME_ERROR_NONE;
569 EXPORT_API int ime_event_set_focus_in_cb(ime_focus_in_cb callback_func, void *user_data)
571 ime_error_e retVal = IME_ERROR_NONE;
573 if (!callback_func) {
574 LOGW("IME_ERROR_INVALID_PARAMETER");
575 return IME_ERROR_INVALID_PARAMETER;
578 retVal = _check_privilege();
579 if (retVal != IME_ERROR_NONE) return retVal;
581 g_event_callback.focus_in = callback_func;
582 g_event_callback.focus_in_user_data = user_data;
584 return IME_ERROR_NONE;
587 EXPORT_API int ime_event_set_focus_out_cb(ime_focus_out_cb callback_func, void *user_data)
589 ime_error_e retVal = IME_ERROR_NONE;
591 if (!callback_func) {
592 LOGW("IME_ERROR_INVALID_PARAMETER");
593 return IME_ERROR_INVALID_PARAMETER;
596 retVal = _check_privilege();
597 if (retVal != IME_ERROR_NONE) return retVal;
599 g_event_callback.focus_out = callback_func;
600 g_event_callback.focus_out_user_data = user_data;
602 return IME_ERROR_NONE;
605 EXPORT_API int ime_event_set_surrounding_text_updated_cb(ime_surrounding_text_updated_cb callback_func, void *user_data)
607 ime_error_e retVal = IME_ERROR_NONE;
609 if (!callback_func) {
610 LOGW("IME_ERROR_INVALID_PARAMETER");
611 return IME_ERROR_INVALID_PARAMETER;
614 retVal = _check_privilege();
615 if (retVal != IME_ERROR_NONE) return retVal;
617 g_event_callback.surrounding_text_updated = callback_func;
618 g_event_callback.surrounding_text_updated_user_data = user_data;
620 return IME_ERROR_NONE;
623 EXPORT_API int ime_event_set_input_context_reset_cb(ime_input_context_reset_cb callback_func, void *user_data)
625 ime_error_e retVal = IME_ERROR_NONE;
627 if (!callback_func) {
628 LOGW("IME_ERROR_INVALID_PARAMETER");
629 return IME_ERROR_INVALID_PARAMETER;
632 retVal = _check_privilege();
633 if (retVal != IME_ERROR_NONE) return retVal;
635 g_event_callback.input_context_reset = callback_func;
636 g_event_callback.input_context_reset_user_data = user_data;
638 return IME_ERROR_NONE;
641 EXPORT_API int ime_event_set_cursor_position_updated_cb(ime_cursor_position_updated_cb callback_func, void *user_data)
643 ime_error_e retVal = IME_ERROR_NONE;
645 if (!callback_func) {
646 LOGW("IME_ERROR_INVALID_PARAMETER");
647 return IME_ERROR_INVALID_PARAMETER;
650 retVal = _check_privilege();
651 if (retVal != IME_ERROR_NONE) return retVal;
653 g_event_callback.cursor_position_updated = callback_func;
654 g_event_callback.cursor_position_updated_user_data = user_data;
656 return IME_ERROR_NONE;
659 EXPORT_API int ime_event_set_language_requested_cb(ime_language_requested_cb callback_func, void *user_data)
661 ime_error_e retVal = IME_ERROR_NONE;
663 if (!callback_func) {
664 LOGW("IME_ERROR_INVALID_PARAMETER");
665 return IME_ERROR_INVALID_PARAMETER;
668 retVal = _check_privilege();
669 if (retVal != IME_ERROR_NONE) return retVal;
671 g_event_callback.language_requested = callback_func;
672 g_event_callback.language_requested_user_data = user_data;
674 return IME_ERROR_NONE;
677 EXPORT_API int ime_event_set_language_set_cb(ime_language_set_cb callback_func, void *user_data)
679 ime_error_e retVal = IME_ERROR_NONE;
681 if (!callback_func) {
682 LOGW("IME_ERROR_INVALID_PARAMETER");
683 return IME_ERROR_INVALID_PARAMETER;
686 retVal = _check_privilege();
687 if (retVal != IME_ERROR_NONE) return retVal;
689 g_event_callback.language_set = callback_func;
690 g_event_callback.language_set_user_data = user_data;
692 return IME_ERROR_NONE;
695 EXPORT_API int ime_event_set_imdata_set_cb(ime_imdata_set_cb callback_func, void *user_data)
697 ime_error_e retVal = IME_ERROR_NONE;
699 if (!callback_func) {
700 LOGW("IME_ERROR_INVALID_PARAMETER");
701 return IME_ERROR_INVALID_PARAMETER;
704 retVal = _check_privilege();
705 if (retVal != IME_ERROR_NONE) return retVal;
707 g_event_callback.imdata_set = callback_func;
708 g_event_callback.imdata_set_user_data = user_data;
710 return IME_ERROR_NONE;
713 EXPORT_API int ime_event_set_imdata_requested_cb(ime_imdata_requested_cb callback_func, void *user_data)
715 ime_error_e retVal = IME_ERROR_NONE;
717 if (!callback_func) {
718 LOGW("IME_ERROR_INVALID_PARAMETER");
719 return IME_ERROR_INVALID_PARAMETER;
722 retVal = _check_privilege();
723 if (retVal != IME_ERROR_NONE) return retVal;
725 g_event_callback.imdata_requested = callback_func;
726 g_event_callback.imdata_requested_user_data = user_data;
728 return IME_ERROR_NONE;
731 EXPORT_API int ime_event_set_layout_set_cb(ime_layout_set_cb callback_func, void *user_data)
733 ime_error_e retVal = IME_ERROR_NONE;
735 if (!callback_func) {
736 LOGW("IME_ERROR_INVALID_PARAMETER");
737 return IME_ERROR_INVALID_PARAMETER;
740 retVal = _check_privilege();
741 if (retVal != IME_ERROR_NONE) return retVal;
743 g_event_callback.layout_set = callback_func;
744 g_event_callback.layout_set_user_data = user_data;
746 return IME_ERROR_NONE;
749 EXPORT_API int ime_event_set_return_key_type_set_cb(ime_return_key_type_set_cb callback_func, void *user_data)
751 ime_error_e retVal = IME_ERROR_NONE;
753 if (!callback_func) {
754 LOGW("IME_ERROR_INVALID_PARAMETER");
755 return IME_ERROR_INVALID_PARAMETER;
758 retVal = _check_privilege();
759 if (retVal != IME_ERROR_NONE) return retVal;
761 g_event_callback.return_key_type_set = callback_func;
762 g_event_callback.return_key_type_set_user_data = user_data;
764 return IME_ERROR_NONE;
767 EXPORT_API int ime_event_set_return_key_state_set_cb(ime_return_key_state_set_cb callback_func, void *user_data)
769 ime_error_e retVal = IME_ERROR_NONE;
771 if (!callback_func) {
772 LOGW("IME_ERROR_INVALID_PARAMETER");
773 return IME_ERROR_INVALID_PARAMETER;
776 retVal = _check_privilege();
777 if (retVal != IME_ERROR_NONE) return retVal;
779 g_event_callback.return_key_state_set = callback_func;
780 g_event_callback.return_key_state_set_user_data = user_data;
782 return IME_ERROR_NONE;
785 EXPORT_API int ime_event_set_geometry_requested_cb(ime_geometry_requested_cb callback_func, void *user_data)
787 ime_error_e retVal = IME_ERROR_NONE;
789 if (!callback_func) {
790 LOGW("IME_ERROR_INVALID_PARAMETER");
791 return IME_ERROR_INVALID_PARAMETER;
794 retVal = _check_privilege();
795 if (retVal != IME_ERROR_NONE) return retVal;
797 g_event_callback.geometry_requested = callback_func;
798 g_event_callback.geometry_requested_user_data = user_data;
800 return IME_ERROR_NONE;
803 EXPORT_API int ime_event_set_process_key_event_cb(ime_process_key_event_cb callback_func, void *user_data)
805 ime_error_e retVal = IME_ERROR_NONE;
807 if (!callback_func) {
808 LOGW("IME_ERROR_INVALID_PARAMETER");
809 return IME_ERROR_INVALID_PARAMETER;
812 retVal = _check_privilege();
813 if (retVal != IME_ERROR_NONE) return retVal;
815 g_event_callback.process_key_event = callback_func;
816 g_event_callback.process_key_event_user_data = user_data;
818 return IME_ERROR_NONE;
821 EXPORT_API int ime_event_set_display_language_changed_cb(ime_display_language_changed_cb callback_func, void *user_data)
823 ime_error_e retVal = IME_ERROR_NONE;
825 if (!callback_func) {
826 LOGW("IME_ERROR_INVALID_PARAMETER");
827 return IME_ERROR_INVALID_PARAMETER;
830 retVal = _check_privilege();
831 if (retVal != IME_ERROR_NONE) return retVal;
833 g_event_callback.display_language_changed = callback_func;
834 g_event_callback.display_language_changed_user_data = user_data;
836 return IME_ERROR_NONE;
839 EXPORT_API int ime_event_set_rotation_degree_changed_cb(ime_rotation_degree_changed_cb callback_func, void *user_data)
841 ime_error_e retVal = IME_ERROR_NONE;
843 if (!callback_func) {
844 LOGW("IME_ERROR_INVALID_PARAMETER");
845 return IME_ERROR_INVALID_PARAMETER;
848 retVal = _check_privilege();
849 if (retVal != IME_ERROR_NONE) return retVal;
851 g_event_callback.rotation_degree_changed = callback_func;
852 g_event_callback.rotation_degree_changed_user_data = user_data;
854 return IME_ERROR_NONE;
857 EXPORT_API int ime_event_set_accessibility_state_changed_cb(ime_accessibility_state_changed_cb callback_func, void *user_data)
859 ime_error_e retVal = IME_ERROR_NONE;
861 if (!callback_func) {
862 LOGW("IME_ERROR_INVALID_PARAMETER");
863 return IME_ERROR_INVALID_PARAMETER;
866 retVal = _check_privilege();
867 if (retVal != IME_ERROR_NONE) return retVal;
869 g_event_callback.accessibility_state_changed = callback_func;
870 g_event_callback.accessibility_state_changed_user_data = user_data;
872 return IME_ERROR_NONE;
875 EXPORT_API int ime_event_set_option_window_created_cb(ime_option_window_created_cb callback_func, void *user_data)
877 ime_error_e retVal = IME_ERROR_NONE;
879 if (!callback_func) {
880 LOGW("IME_ERROR_INVALID_PARAMETER");
881 return IME_ERROR_INVALID_PARAMETER;
884 retVal = _check_privilege();
885 if (retVal != IME_ERROR_NONE) return retVal;
887 g_event_callback.option_window_created = callback_func;
888 g_event_callback.option_window_created_user_data = user_data;
890 return IME_ERROR_NONE;
893 EXPORT_API int ime_event_set_option_window_destroyed_cb(ime_option_window_destroyed_cb callback_func, void *user_data)
895 ime_error_e retVal = IME_ERROR_NONE;
897 if (!callback_func) {
898 LOGW("IME_ERROR_INVALID_PARAMETER");
899 return IME_ERROR_INVALID_PARAMETER;
902 retVal = _check_privilege();
903 if (retVal != IME_ERROR_NONE) return retVal;
905 g_event_callback.option_window_destroyed = callback_func;
906 g_event_callback.option_window_destroyed_user_data = user_data;
908 return IME_ERROR_NONE;
912 EXPORT_API int ime_event_set_caps_mode_changed_cb(ime_caps_mode_changed_cb callback_func, void *user_data)
914 ime_error_e retVal = IME_ERROR_NONE;
916 if (!callback_func) {
917 LOGW("IME_ERROR_INVALID_PARAMETER");
918 return IME_ERROR_INVALID_PARAMETER;
921 retVal = _check_privilege();
922 if (retVal != IME_ERROR_NONE) return retVal;
924 g_event_callback.caps_mode_changed = callback_func;
925 g_event_callback.caps_mode_changed_user_data = user_data;
927 return IME_ERROR_NONE;
930 EXPORT_API int ime_event_set_candidate_show_cb(ime_candidate_show_cb callback_func, void *user_data)
932 ime_error_e retVal = IME_ERROR_NONE;
934 if (!callback_func) {
935 LOGW("IME_ERROR_INVALID_PARAMETER");
936 return IME_ERROR_INVALID_PARAMETER;
939 retVal = _check_privilege();
940 if (retVal != IME_ERROR_NONE) return retVal;
942 g_event_callback.candidate_show = callback_func;
943 g_event_callback.candidate_show_user_data = user_data;
945 return IME_ERROR_NONE;
948 EXPORT_API int ime_event_set_candidate_hide_cb(ime_candidate_hide_cb callback_func, void *user_data)
950 ime_error_e retVal = IME_ERROR_NONE;
952 if (!callback_func) {
953 LOGW("IME_ERROR_INVALID_PARAMETER");
954 return IME_ERROR_INVALID_PARAMETER;
957 retVal = _check_privilege();
958 if (retVal != IME_ERROR_NONE) return retVal;
960 g_event_callback.candidate_hide = callback_func;
961 g_event_callback.candidate_hide_user_data = user_data;
963 return IME_ERROR_NONE;
966 EXPORT_API int ime_event_set_lookup_table_changed_cb(ime_lookup_table_changed_cb callback_func, void *user_data)
968 ime_error_e retVal = IME_ERROR_NONE;
970 if (!callback_func) {
971 LOGW("IME_ERROR_INVALID_PARAMETER");
972 return IME_ERROR_INVALID_PARAMETER;
975 retVal = _check_privilege();
976 if (retVal != IME_ERROR_NONE) return retVal;
978 g_event_callback.lookup_table_changed = callback_func;
979 g_event_callback.lookup_table_changed_user_data = user_data;
981 return IME_ERROR_NONE;
985 EXPORT_API int ime_send_key_event(ime_key_code_e keycode, ime_key_mask_e keymask, bool forward_key)
987 ime_error_e retVal = IME_ERROR_NONE;
990 LOGW("IME_ERROR_NOT_RUNNING");
991 return IME_ERROR_NOT_RUNNING;
994 retVal = _check_privilege();
995 if (retVal != IME_ERROR_NONE) return retVal;
998 g_core.forward_key_event(-1, NULL, (sclu32)keycode, (sclu16)keymask);
1000 g_core.send_key_event(-1, NULL, (sclu32)keycode, (sclu16)keymask);
1002 return IME_ERROR_NONE;
1005 EXPORT_API int ime_commit_string(const char *str)
1007 ime_error_e retVal = IME_ERROR_NONE;
1010 LOGW("IME_ERROR_INVALID_PARAMETER");
1011 return IME_ERROR_INVALID_PARAMETER;
1015 LOGW("IME_ERROR_NOT_RUNNING");
1016 return IME_ERROR_NOT_RUNNING;
1019 retVal = _check_privilege();
1020 if (retVal != IME_ERROR_NONE) return retVal;
1022 g_core.commit_string(-1, NULL, str);
1024 return IME_ERROR_NONE;
1027 EXPORT_API int ime_show_preedit_string(void)
1029 ime_error_e retVal = IME_ERROR_NONE;
1032 LOGW("IME_ERROR_NOT_RUNNING");
1033 return IME_ERROR_NOT_RUNNING;
1036 retVal = _check_privilege();
1037 if (retVal != IME_ERROR_NONE) return retVal;
1039 g_core.show_preedit_string(-1, NULL);
1041 return IME_ERROR_NONE;
1044 EXPORT_API int ime_hide_preedit_string(void)
1046 ime_error_e retVal = IME_ERROR_NONE;
1049 LOGW("IME_ERROR_NOT_RUNNING");
1050 return IME_ERROR_NOT_RUNNING;
1053 retVal = _check_privilege();
1054 if (retVal != IME_ERROR_NONE) return retVal;
1056 g_core.hide_preedit_string(-1, NULL);
1058 return IME_ERROR_NONE;
1061 EXPORT_API int ime_update_preedit_string(const char *str, Eina_List *attrs)
1063 ime_error_e retVal = IME_ERROR_NONE;
1066 LOGW("IME_ERROR_INVALID_PARAMETER");
1067 return IME_ERROR_INVALID_PARAMETER;
1071 LOGW("IME_ERROR_NOT_RUNNING");
1072 return IME_ERROR_NOT_RUNNING;
1075 retVal = _check_privilege();
1076 if (retVal != IME_ERROR_NONE) return retVal;
1078 scim::AttributeList attrv;
1080 ime_preedit_attribute *attr = NULL;
1083 EINA_LIST_FREE(attrs, data) {
1084 attr = (ime_preedit_attribute *)data;
1086 attrv.push_back(scim::Attribute(attr->start, attr->length, (scim::AttributeType)attr->type, attr->value));
1092 g_core.update_preedit_string(-1, NULL, str, attrv);
1094 return IME_ERROR_NONE;
1097 EXPORT_API int ime_request_surrounding_text(int maxlen_before, int maxlen_after)
1099 ime_error_e retVal = IME_ERROR_NONE;
1101 if (!g_event_callback.surrounding_text_updated) {
1102 LOGW("IME_ERROR_NO_CALLBACK_FUNCTION");
1103 return IME_ERROR_NO_CALLBACK_FUNCTION;
1107 LOGW("IME_ERROR_NOT_RUNNING");
1108 return IME_ERROR_NOT_RUNNING;
1111 retVal = _check_privilege();
1112 if (retVal != IME_ERROR_NONE) return retVal;
1114 g_core.get_surrounding_text(NULL, maxlen_before, maxlen_after);
1116 return IME_ERROR_NONE;
1119 EXPORT_API int ime_delete_surrounding_text(int offset, int len)
1121 ime_error_e retVal = IME_ERROR_NONE;
1124 LOGW("IME_ERROR_INVALID_PARAMETER");
1125 return IME_ERROR_INVALID_PARAMETER;
1129 LOGW("IME_ERROR_NOT_RUNNING");
1130 return IME_ERROR_NOT_RUNNING;
1133 retVal = _check_privilege();
1134 if (retVal != IME_ERROR_NONE) return retVal;
1136 g_core.delete_surrounding_text(offset, len);
1138 return IME_ERROR_NONE;
1141 EXPORT_API int ime_get_surrounding_text(int maxlen_before, int maxlen_after, char **text, int *cursor_pos)
1143 ime_error_e retVal = IME_ERROR_NONE;
1145 if (!text || !cursor_pos) {
1146 LOGW("IME_ERROR_INVALID_PARAMETER");
1147 return IME_ERROR_INVALID_PARAMETER;
1151 LOGW("IME_ERROR_NOT_RUNNING");
1152 return IME_ERROR_NOT_RUNNING;
1155 retVal = _check_privilege();
1156 if (retVal != IME_ERROR_NONE) return retVal;
1160 int ret = g_core.get_surrounding_text(maxlen_before, maxlen_after, text, cursor);
1162 LOGW("IME_ERROR_OUR_OF_MEMORY");
1163 return IME_ERROR_OUT_OF_MEMORY;
1167 *cursor_pos = cursor;
1169 return IME_ERROR_NONE;
1172 EXPORT_API int ime_set_selection(int start, int end)
1174 ime_error_e retVal = IME_ERROR_NONE;
1177 LOGW("IME_ERROR_INVALID_PARAMETER");
1178 return IME_ERROR_INVALID_PARAMETER;
1182 LOGW("IME_ERROR_NOT_RUNNING");
1183 return IME_ERROR_NOT_RUNNING;
1186 retVal = _check_privilege();
1187 if (retVal != IME_ERROR_NONE) return retVal;
1189 g_core.set_selection(start, end);
1191 return IME_ERROR_NONE;
1194 EXPORT_API int ime_get_selected_text(char **text)
1196 ime_error_e retVal = IME_ERROR_NONE;
1199 LOGW("IME_ERROR_INVALID_PARAMETER");
1200 return IME_ERROR_INVALID_PARAMETER;
1204 LOGW("IME_ERROR_NOT_RUNNING");
1205 return IME_ERROR_NOT_RUNNING;
1208 retVal = _check_privilege();
1209 if (retVal != IME_ERROR_NONE) return retVal;
1211 g_core.get_selection_text(text);
1213 return IME_ERROR_NONE;
1216 EXPORT_API Evas_Object* ime_get_main_window(void)
1218 ime_error_e retVal = IME_ERROR_NONE;
1220 Evas_Object *win = NULL;
1222 retVal = _check_privilege();
1223 if (retVal != IME_ERROR_NONE) {
1224 LOGE("_check_privilege returned %d.", retVal);
1225 set_last_result(retVal);
1230 set_last_result(IME_ERROR_NOT_RUNNING);
1231 LOGW("IME_ERROR_NOT_RUNNING");
1235 win = static_cast<Evas_Object*>(g_core.get_main_window());
1237 set_last_result(IME_ERROR_NONE);
1239 set_last_result(IME_ERROR_OPERATION_FAILED);
1240 LOGW("IME_ERROR_OPERATION_FAILED");
1246 EXPORT_API int ime_set_size(int portrait_width, int portrait_height, int landscape_width, int landscape_height)
1248 ime_error_e retVal = IME_ERROR_NONE;
1250 SclSize portrait_size, landscape_size;
1252 if (portrait_width < 1 || portrait_height < 1 || landscape_width < 1 || landscape_height < 1) {
1253 LOGW("IME_ERROR_INVALID_PARAMETER");
1254 return IME_ERROR_INVALID_PARAMETER;
1258 LOGW("IME_ERROR_NOT_RUNNING");
1259 return IME_ERROR_NOT_RUNNING;
1262 retVal = _check_privilege();
1263 if (retVal != IME_ERROR_NONE) return retVal;
1265 portrait_size.width = portrait_width;
1266 portrait_size.height = portrait_height;
1268 landscape_size.width = landscape_width;
1269 landscape_size.height = landscape_height;
1271 g_core.set_keyboard_size_hints(portrait_size, landscape_size);
1273 return IME_ERROR_NONE;
1276 EXPORT_API int ime_create_option_window(void)
1278 ime_error_e retVal = IME_ERROR_NONE;
1280 if (!g_event_callback.option_window_created || !g_event_callback.option_window_destroyed) {
1281 LOGW("ime_create_option_window_cb() and ime_destroy_option_window_cb() callback functions are not set.");
1282 return IME_ERROR_NO_CALLBACK_FUNCTION;
1286 LOGW("IME_ERROR_NOT_RUNNING");
1287 return IME_ERROR_NOT_RUNNING;
1290 retVal = _check_privilege();
1291 if (retVal != IME_ERROR_NONE) return retVal;
1293 if (g_core.create_option_window()) {
1294 return IME_ERROR_NONE;
1296 LOGW("IME_ERROR_OPERATION_FAILED");
1297 return IME_ERROR_OPERATION_FAILED;
1301 EXPORT_API int ime_destroy_option_window(Evas_Object *window)
1303 ime_error_e retVal = IME_ERROR_NONE;
1305 if (!g_event_callback.option_window_created || !g_event_callback.option_window_destroyed) {
1306 LOGW("ime_create_option_window_cb() and ime_destroy_option_window_cb() callback functions are not set.");
1307 return IME_ERROR_NO_CALLBACK_FUNCTION;
1311 LOGW("Window pointer is null.");
1312 return IME_ERROR_INVALID_PARAMETER;
1316 LOGW("IME_ERROR_NOT_RUNNING");
1317 return IME_ERROR_NOT_RUNNING;
1320 retVal = _check_privilege();
1321 if (retVal != IME_ERROR_NONE) return retVal;
1323 g_core.destroy_option_window(window);
1325 return IME_ERROR_NONE;
1329 EXPORT_API int ime_set_imengine(const char *engine_id)
1331 ime_error_e retVal = IME_ERROR_NONE;
1334 LOGW("IME_ERROR_INVALID_PARAMETER");
1335 return IME_ERROR_INVALID_PARAMETER;
1338 retVal = _check_privilege();
1339 if (retVal != IME_ERROR_NONE) return retVal;
1341 g_core.set_keyboard_ise_by_uuid(engine_id);
1343 return IME_ERROR_NONE;
1346 EXPORT_API int ime_flush_imengine()
1348 ime_error_e retVal = IME_ERROR_NONE;
1351 LOGW("IME_ERROR_NOT_RUNNING");
1352 return IME_ERROR_NOT_RUNNING;
1355 retVal = _check_privilege();
1356 if (retVal != IME_ERROR_NONE) return retVal;
1358 g_core.flush_keyboard_ise();
1360 return IME_ERROR_NONE;
1363 EXPORT_API int ime_reset_imengine()
1365 ime_error_e retVal = IME_ERROR_NONE;
1368 LOGW("IME_ERROR_NOT_RUNNING");
1369 return IME_ERROR_NOT_RUNNING;
1372 retVal = _check_privilege();
1373 if (retVal != IME_ERROR_NONE) return retVal;
1375 g_core.reset_keyboard_ise();
1377 return IME_ERROR_NONE;
1380 EXPORT_API int ime_update_input_context(unsigned int type, unsigned int value)
1382 ime_error_e retVal = IME_ERROR_NONE;
1385 LOGW("IME_ERROR_NOT_RUNNING");
1386 return IME_ERROR_NOT_RUNNING;
1389 retVal = _check_privilege();
1390 if (retVal != IME_ERROR_NONE) return retVal;
1392 g_core.update_input_context(type, value);
1394 return IME_ERROR_NONE;
1398 EXPORT_API int ime_request_hide(void)
1400 ime_error_e retVal = IME_ERROR_NONE;
1403 LOGW("IME_ERROR_NOT_RUNNING");
1404 return IME_ERROR_NOT_RUNNING;
1407 retVal = _check_privilege();
1408 if (retVal != IME_ERROR_NONE) return retVal;
1410 g_core.request_ise_hide();
1412 return IME_ERROR_NONE;
1416 EXPORT_API int ime_initialize()
1418 ime_error_e retVal = IME_ERROR_NONE;
1420 retVal = _check_privilege();
1421 if (retVal != IME_ERROR_NONE) return retVal;
1429 EXPORT_API int ime_prepare()
1431 ime_error_e retVal = IME_ERROR_NONE;
1434 LOGE("inputmethod main loop is already running.");
1435 return IME_ERROR_OPERATION_FAILED;
1438 retVal = _check_privilege();
1439 if (retVal != IME_ERROR_NONE) return retVal;
1448 EXPORT_API int ime_finalize()
1450 ime_error_e retVal = IME_ERROR_NONE;
1452 retVal = _check_privilege();
1453 if (retVal != IME_ERROR_NONE) return retVal;
1457 memset(&g_basic_callback, 0, sizeof(ime_callback_s));
1458 memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
1464 EXPORT_API int ime_select_candidate(unsigned int index)
1466 ime_error_e retVal = IME_ERROR_NONE;
1469 LOGW("IME_ERROR_NOT_RUNNING");
1470 return IME_ERROR_NOT_RUNNING;
1473 retVal = _check_privilege();
1474 if (retVal != IME_ERROR_NONE) return retVal;
1476 g_core.select_candidate(index);
1478 return IME_ERROR_NONE;
1482 EXPORT_API int ime_send_private_command(const char *command)
1484 ime_error_e retVal = IME_ERROR_NONE;
1487 LOGW("IME_ERROR_INVALID_PARAMETER");
1488 return IME_ERROR_INVALID_PARAMETER;
1492 LOGW("IME_ERROR_NOT_RUNNING");
1493 return IME_ERROR_NOT_RUNNING;
1496 retVal = _check_privilege();
1497 if (retVal != IME_ERROR_NONE) return retVal;
1499 g_core.send_private_command(command);
1501 return IME_ERROR_NONE;
1504 EXPORT_API int ime_commit_content(const char *content, const char *description, const char *mime_type)
1506 ime_error_e retVal = IME_ERROR_NONE;
1508 if (!content || !description || !mime_type) {
1509 LOGW("IME_ERROR_INVALID_PARAMETER");
1510 return IME_ERROR_INVALID_PARAMETER;
1513 retVal = _check_privilege();
1514 if (retVal != IME_ERROR_NONE) return retVal;
1517 LOGW("IME_ERROR_NOT_RUNNING");
1518 return IME_ERROR_NOT_RUNNING;
1521 g_core.commit_content(content, description, mime_type);
1523 return IME_ERROR_NONE;
1526 EXPORT_API int ime_context_get_layout(ime_context_h context, Ecore_IMF_Input_Panel_Layout *layout)
1528 ime_error_e retVal = IME_ERROR_NONE;
1530 if (!context || !layout) {
1531 LOGW("IME_ERROR_INVALID_PARAMETER");
1532 return IME_ERROR_INVALID_PARAMETER;
1535 retVal = _check_privilege();
1536 if (retVal != IME_ERROR_NONE) return retVal;
1539 LOGW("IME_ERROR_NOT_RUNNING");
1540 return IME_ERROR_NOT_RUNNING;
1543 *layout = context->layout;
1545 return IME_ERROR_NONE;
1548 EXPORT_API int ime_context_get_layout_variation(ime_context_h context, ime_layout_variation_e *layout_variation)
1550 ime_error_e retVal = IME_ERROR_NONE;
1552 if (!context || !layout_variation) {
1553 LOGW("IME_ERROR_INVALID_PARAMETER");
1554 return IME_ERROR_INVALID_PARAMETER;
1557 retVal = _check_privilege();
1558 if (retVal != IME_ERROR_NONE) return retVal;
1561 LOGW("IME_ERROR_NOT_RUNNING");
1562 return IME_ERROR_NOT_RUNNING;
1565 *layout_variation = static_cast<ime_layout_variation_e>(context->layout_variation);
1567 return IME_ERROR_NONE;
1570 EXPORT_API int ime_context_get_cursor_position(ime_context_h context, int *cursor_pos)
1572 ime_error_e retVal = IME_ERROR_NONE;
1574 if (!context || !cursor_pos) {
1575 LOGW("IME_ERROR_INVALID_PARAMETER");
1576 return IME_ERROR_INVALID_PARAMETER;
1579 retVal = _check_privilege();
1580 if (retVal != IME_ERROR_NONE) return retVal;
1583 LOGW("IME_ERROR_NOT_RUNNING");
1584 return IME_ERROR_NOT_RUNNING;
1587 *cursor_pos = context->cursor_pos;
1589 return IME_ERROR_NONE;
1592 EXPORT_API int ime_context_get_autocapital_type(ime_context_h context, Ecore_IMF_Autocapital_Type *autocapital_type)
1594 ime_error_e retVal = IME_ERROR_NONE;
1596 if (!context || !autocapital_type) {
1597 LOGW("IME_ERROR_INVALID_PARAMETER");
1598 return IME_ERROR_INVALID_PARAMETER;
1601 retVal = _check_privilege();
1602 if (retVal != IME_ERROR_NONE) return retVal;
1605 LOGW("IME_ERROR_NOT_RUNNING");
1606 return IME_ERROR_NOT_RUNNING;
1609 *autocapital_type = context->autocapital_type;
1611 return IME_ERROR_NONE;
1614 EXPORT_API int ime_context_get_return_key_type(ime_context_h context, Ecore_IMF_Input_Panel_Return_Key_Type *return_key_type)
1616 ime_error_e retVal = IME_ERROR_NONE;
1618 if (!context || !return_key_type) {
1619 LOGW("IME_ERROR_INVALID_PARAMETER");
1620 return IME_ERROR_INVALID_PARAMETER;
1623 retVal = _check_privilege();
1624 if (retVal != IME_ERROR_NONE) return retVal;
1627 LOGW("IME_ERROR_NOT_RUNNING");
1628 return IME_ERROR_NOT_RUNNING;
1631 *return_key_type = context->return_key_type;
1633 return IME_ERROR_NONE;
1636 EXPORT_API int ime_context_get_return_key_state(ime_context_h context, bool *return_key_state)
1638 ime_error_e retVal = IME_ERROR_NONE;
1640 if (!context || !return_key_state) {
1641 LOGW("IME_ERROR_INVALID_PARAMETER");
1642 return IME_ERROR_INVALID_PARAMETER;
1645 retVal = _check_privilege();
1646 if (retVal != IME_ERROR_NONE) return retVal;
1649 LOGW("IME_ERROR_NOT_RUNNING");
1650 return IME_ERROR_NOT_RUNNING;
1653 *return_key_state = static_cast<bool>(context->return_key_disabled);
1655 return IME_ERROR_NONE;
1658 EXPORT_API int ime_context_get_prediction_mode(ime_context_h context, bool *prediction_mode)
1660 ime_error_e retVal = IME_ERROR_NONE;
1662 if (!context || !prediction_mode) {
1663 LOGW("IME_ERROR_INVALID_PARAMETER");
1664 return IME_ERROR_INVALID_PARAMETER;
1667 retVal = _check_privilege();
1668 if (retVal != IME_ERROR_NONE) return retVal;
1671 LOGW("IME_ERROR_NOT_RUNNING");
1672 return IME_ERROR_NOT_RUNNING;
1675 *prediction_mode = static_cast<bool>(context->prediction_allow);
1677 return IME_ERROR_NONE;
1680 EXPORT_API int ime_context_get_password_mode(ime_context_h context, bool *password_mode)
1682 ime_error_e retVal = IME_ERROR_NONE;
1684 if (!context || !password_mode) {
1685 LOGW("IME_ERROR_INVALID_PARAMETER");
1686 return IME_ERROR_INVALID_PARAMETER;
1689 retVal = _check_privilege();
1690 if (retVal != IME_ERROR_NONE) return retVal;
1693 LOGW("IME_ERROR_NOT_RUNNING");
1694 return IME_ERROR_NOT_RUNNING;
1697 *password_mode = static_cast<bool>(context->password_mode);
1699 return IME_ERROR_NONE;
1702 EXPORT_API int ime_context_get_input_hint(ime_context_h context, Ecore_IMF_Input_Hints *input_hint)
1704 ime_error_e retVal = IME_ERROR_NONE;
1706 if (!context || !input_hint) {
1707 LOGW("IME_ERROR_INVALID_PARAMETER");
1708 return IME_ERROR_INVALID_PARAMETER;
1711 retVal = _check_privilege();
1712 if (retVal != IME_ERROR_NONE) return retVal;
1715 LOGW("IME_ERROR_NOT_RUNNING");
1716 return IME_ERROR_NOT_RUNNING;
1719 *input_hint = context->input_hint;
1721 return IME_ERROR_NONE;
1724 EXPORT_API int ime_context_get_bidi_direction(ime_context_h context, Ecore_IMF_BiDi_Direction *bidi)
1726 ime_error_e retVal = IME_ERROR_NONE;
1728 if (!context || !bidi) {
1729 LOGW("IME_ERROR_INVALID_PARAMETER");
1730 return IME_ERROR_INVALID_PARAMETER;
1733 retVal = _check_privilege();
1734 if (retVal != IME_ERROR_NONE) return retVal;
1737 LOGW("IME_ERROR_NOT_RUNNING");
1738 return IME_ERROR_NOT_RUNNING;
1741 *bidi = context->bidi_direction;
1743 return IME_ERROR_NONE;
1746 EXPORT_API int ime_context_get_language(ime_context_h context, Ecore_IMF_Input_Panel_Lang *language)
1748 ime_error_e retVal = IME_ERROR_NONE;
1750 if (!context || !language) {
1751 LOGW("IME_ERROR_INVALID_PARAMETER");
1752 return IME_ERROR_INVALID_PARAMETER;
1755 retVal = _check_privilege();
1756 if (retVal != IME_ERROR_NONE) return retVal;
1759 LOGW("IME_ERROR_NOT_RUNNING");
1760 return IME_ERROR_NOT_RUNNING;
1763 *language = context->language;
1765 return IME_ERROR_NONE;
1769 EXPORT_API int ime_context_get_caps_mode(ime_context_h context, bool *caps_mode)
1771 ime_error_e retVal = IME_ERROR_NONE;
1773 if (!context || !caps_mode) {
1774 LOGW("IME_ERROR_INVALID_PARAMETER");
1775 return IME_ERROR_INVALID_PARAMETER;
1778 retVal = _check_privilege();
1779 if (retVal != IME_ERROR_NONE) return retVal;
1782 LOGW("IME_ERROR_NOT_RUNNING");
1783 return IME_ERROR_NOT_RUNNING;
1786 *caps_mode = static_cast<bool>(context->caps_mode);
1788 return IME_ERROR_NONE;
1792 EXPORT_API int ime_device_info_get_name(ime_device_info_h dev_info, char **dev_name)
1794 ime_error_e retVal = IME_ERROR_NONE;
1796 if (!dev_info || !dev_name) {
1797 LOGW("IME_ERROR_INVALID_PARAMETER");
1798 return IME_ERROR_INVALID_PARAMETER;
1801 retVal = _check_privilege();
1802 if (retVal != IME_ERROR_NONE) return retVal;
1805 LOGW("IME_ERROR_NOT_RUNNING");
1806 return IME_ERROR_NOT_RUNNING;
1809 if (!dev_info->dev_name)
1810 *dev_name = strdup("");
1812 *dev_name = strdup(dev_info->dev_name);
1814 return IME_ERROR_NONE;
1817 EXPORT_API int ime_device_info_get_class(ime_device_info_h dev_info, Ecore_IMF_Device_Class *dev_class)
1819 ime_error_e retVal = IME_ERROR_NONE;
1821 if (!dev_info || !dev_class) {
1822 LOGW("IME_ERROR_INVALID_PARAMETER");
1823 return IME_ERROR_INVALID_PARAMETER;
1826 retVal = _check_privilege();
1827 if (retVal != IME_ERROR_NONE) return retVal;
1830 LOGW("IME_ERROR_NOT_RUNNING");
1831 return IME_ERROR_NOT_RUNNING;
1834 *dev_class = dev_info->dev_class;
1836 return IME_ERROR_NONE;
1839 EXPORT_API int ime_device_info_get_subclass(ime_device_info_h dev_info, Ecore_IMF_Device_Subclass *dev_subclass)
1841 ime_error_e retVal = IME_ERROR_NONE;
1843 if (!dev_info || !dev_subclass) {
1844 LOGW("IME_ERROR_INVALID_PARAMETER");
1845 return IME_ERROR_INVALID_PARAMETER;
1848 retVal = _check_privilege();
1849 if (retVal != IME_ERROR_NONE) return retVal;
1852 LOGW("IME_ERROR_NOT_RUNNING");
1853 return IME_ERROR_NOT_RUNNING;
1856 *dev_subclass = dev_info->dev_subclass;
1858 return IME_ERROR_NONE;
1861 EXPORT_API int ime_event_set_process_input_device_event_cb(ime_process_input_device_event_cb callback_func, void *user_data)
1863 ime_error_e retVal = IME_ERROR_NONE;
1865 if (!callback_func) {
1866 LOGW("IME_ERROR_INVALID_PARAMETER");
1867 return IME_ERROR_INVALID_PARAMETER;
1870 retVal = _check_privilege();
1871 if (retVal != IME_ERROR_NONE) return retVal;
1873 g_event_callback.process_input_device_event = callback_func;
1874 g_event_callback.process_input_device_event_user_data = user_data;
1876 return IME_ERROR_NONE;
1879 EXPORT_API int ime_event_unset_process_input_device_event_cb(void)
1881 ime_error_e retVal = IME_ERROR_NONE;
1883 retVal = _check_privilege();
1884 if (retVal != IME_ERROR_NONE) return retVal;
1886 g_event_callback.process_input_device_event = NULL;
1887 g_event_callback.process_input_device_event_user_data = NULL;
1889 return IME_ERROR_NONE;
1892 /* Functions for Rotary input device event */
1893 EXPORT_API int ime_input_device_rotary_get_direction(ime_input_device_event_h event_handle, ime_input_device_rotary_direction_e *direction)
1895 ime_error_e retVal = IME_ERROR_NONE;
1897 if (!event_handle || !direction) {
1898 LOGW("IME_ERROR_INVALID_PARAMETER");
1899 return IME_ERROR_INVALID_PARAMETER;
1902 ime_device_event_s *device_event = static_cast<ime_device_event_s*>(event_handle);
1903 if (device_event->device_type != IME_INPUT_DEVICE_TYPE_ROTARY) {
1904 LOGW("IME_ERROR_INVALID_PARAMETER");
1905 return IME_ERROR_INVALID_PARAMETER;
1908 retVal = _check_privilege();
1909 if (retVal != IME_ERROR_NONE) return retVal;
1912 LOGW("IME_ERROR_OPERATION_FAILED");
1913 return IME_ERROR_OPERATION_FAILED;
1916 Ecore_Event_Detent_Rotate *rotary_device_event =
1917 static_cast<Ecore_Event_Detent_Rotate*>(device_event->event_data);
1918 if (rotary_device_event) {
1919 if (rotary_device_event->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) {
1920 *direction = IME_INPUT_DEVICE_ROTARY_DIRECTION_CLOCKWISE;
1921 } else if (rotary_device_event->direction == ECORE_DETENT_DIRECTION_COUNTER_CLOCKWISE) {
1922 *direction = IME_INPUT_DEVICE_ROTARY_DIRECTION_COUNTER_CLOCKWISE;
1926 return IME_ERROR_NONE;
1929 EXPORT_API int ime_event_set_prediction_hint_set_cb(ime_prediction_hint_set_cb callback_func, void *user_data)
1931 ime_error_e retVal = IME_ERROR_NONE;
1933 if (!callback_func) {
1934 LOGW("IME_ERROR_INVALID_PARAMETER");
1935 return IME_ERROR_INVALID_PARAMETER;
1938 retVal = _check_privilege();
1939 if (retVal != IME_ERROR_NONE) return retVal;
1941 g_event_callback.prediction_hint_set = callback_func;
1942 g_event_callback.prediction_hint_set_user_data = user_data;
1944 return IME_ERROR_NONE;
1947 EXPORT_API int ime_event_set_mime_type_set_request_cb(ime_mime_type_set_request_cb callback_func, void *user_data)
1949 ime_error_e retVal = IME_ERROR_NONE;
1951 if (!callback_func) {
1952 LOGW("IME_ERROR_INVALID_PARAMETER");
1953 return IME_ERROR_INVALID_PARAMETER;
1956 retVal = _check_privilege();
1957 if (retVal != IME_ERROR_NONE) return retVal;
1959 g_event_callback.mime_type_set = callback_func;
1960 g_event_callback.mime_type_set_user_data = user_data;
1962 return IME_ERROR_NONE;
1965 EXPORT_API int ime_set_floating_mode(bool floating_mode)
1967 ime_error_e retVal = IME_ERROR_NONE;
1969 retVal = _check_privilege();
1970 if (retVal != IME_ERROR_NONE) return retVal;
1973 LOGW("IME_ERROR_NOT_RUNNING");
1974 return IME_ERROR_NOT_RUNNING;
1977 g_core.set_floating_mode(floating_mode);
1979 return IME_ERROR_NONE;
1982 EXPORT_API int ime_set_floating_drag_start(void)
1984 ime_error_e retVal = IME_ERROR_NONE;
1986 retVal = _check_privilege();
1987 if (retVal != IME_ERROR_NONE) return retVal;
1990 LOGW("IME_ERROR_NOT_RUNNING");
1991 return IME_ERROR_NOT_RUNNING;
1994 g_core.set_floating_drag_enabled(true);
1996 return IME_ERROR_NONE;
1999 EXPORT_API int ime_set_floating_drag_end(void)
2001 ime_error_e retVal = IME_ERROR_NONE;
2003 retVal = _check_privilege();
2004 if (retVal != IME_ERROR_NONE) return retVal;
2007 LOGW("IME_ERROR_NOT_RUNNING");
2008 return IME_ERROR_NOT_RUNNING;
2011 g_core.set_floating_drag_enabled(false);
2013 return IME_ERROR_NONE;
2017 EXPORT_API int ime_set_window_creation_defer_flag(bool flag)
2019 ime_error_e retVal = IME_ERROR_NONE;
2021 retVal = _check_privilege();
2022 if (retVal != IME_ERROR_NONE) return retVal;
2024 g_core.set_window_creation_defer_flag(flag);
2026 return IME_ERROR_NONE;
2030 EXPORT_API int ime_event_set_prediction_hint_data_set_cb(ime_prediction_hint_data_set_cb callback_func, void *user_data)
2032 ime_error_e retVal = IME_ERROR_NONE;
2034 if (!callback_func) {
2035 LOGW("IME_ERROR_INVALID_PARAMETER");
2036 return IME_ERROR_INVALID_PARAMETER;
2039 retVal = _check_privilege();
2040 if (retVal != IME_ERROR_NONE) return retVal;
2042 g_event_callback.prediction_hint_data_set = callback_func;
2043 g_event_callback.prediction_hint_data_set_user_data = user_data;
2045 return IME_ERROR_NONE;
2049 EXPORT_API int ime_event_set_optimization_hint_set_cb(ime_optimization_hint_set_cb callback_func, void *user_data)
2052 ime_error_e retVal = IME_ERROR_NONE;
2054 if (!callback_func) {
2055 LOGW("IME_ERROR_INVALID_PARAMETER");
2056 return IME_ERROR_INVALID_PARAMETER;
2060 retVal = _check_privilege();
2061 if (retVal != IME_ERROR_NONE) return retVal;
2064 g_event_callback.optimization_hint_set = callback_func;
2065 g_event_callback.optimization_hint_set_user_data = user_data;
2067 return IME_ERROR_NONE;
2071 EXPORT_API int ime_update_input_panel_event(ime_event_type_e type, unsigned int value)
2073 ime_error_e retVal = IME_ERROR_NONE;
2075 if (type < IME_EVENT_TYPE_LANGUAGE && type > IME_EVENT_TYPE_GEOMETRY) {
2076 LOGW("IME_ERROR_INVALID_PARAMETER");
2077 return IME_ERROR_INVALID_PARAMETER;
2081 LOGW("IME_ERROR_NOT_RUNNING");
2082 return IME_ERROR_NOT_RUNNING;
2085 retVal = _check_privilege();
2086 if (retVal != IME_ERROR_NONE) return retVal;
2088 g_core.update_input_context((sclu32)type, value);
2090 return IME_ERROR_NONE;