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(sclu32 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(sclu32 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_process_key_event_with_keycode(scim::KeyEvent &key, sclu32 *ret, sclu32 keycode);
60 void on_set_display_language(const sclchar *language);
61 void on_set_rotation_degree(sclint degree);
62 void on_set_accessibility_state(sclboolean state);
63 void on_create_option_window(sclwindow window, SCLOptionWindowType type);
64 void on_destroy_option_window(sclwindow window);
65 void on_check_option_window_availability(sclboolean *ret);
66 void on_set_caps_mode(sclu32 mode);
67 void on_candidate_show(sclint ic, const sclchar *ic_uuid);
68 void on_candidate_hide(sclint ic, const sclchar *ic_uuid);
69 void on_update_lookup_table(SclCandidateTable &table);
70 void on_process_input_device_event(sclu32 &type, sclchar *data, size_t &len, sclu32 *ret);
71 void on_set_prediction_hint(const sclchar *prediction_hint);
72 void on_set_mime_type(const sclchar *mime_type);
73 void on_set_prediction_hint_data(const sclchar *key, const sclchar *value);
74 void on_set_optimization_hint(sclu32 hint);
79 ime_focus_in_cb focus_in; /**< Called when an edit field has focus */
80 ime_focus_out_cb focus_out; /**< Called when an edit field loses focus */
81 ime_surrounding_text_updated_cb surrounding_text_updated; /**< Called when an edit field responds to a request with the surrounding text */
82 ime_input_context_reset_cb input_context_reset; /**< Called to reset the input context of an edit field */
83 ime_cursor_position_updated_cb cursor_position_updated; /**< Called when the position of the cursor in an edit field changes */
84 ime_language_requested_cb language_requested; /**< Called when an edit field requests the language from the input panel */
85 ime_language_set_cb language_set; /**< Called to set the preferred language to the input panel */
86 ime_imdata_set_cb imdata_set; /**< Called to set the application specific data to deliver to the input panel */
87 ime_imdata_requested_cb imdata_requested; /**< Called when an associated text input UI control requests the application specific data from the input panel */
88 ime_layout_set_cb layout_set; /**< Called when an edit field requests the input panel to set its layout */
89 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 */
90 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 */
91 ime_geometry_requested_cb geometry_requested; /**< Called when an edit field requests the position and size from the input panel */
92 ime_process_key_event_cb process_key_event; /**< Called when the key event is received from the external keyboard devices */
93 ime_process_key_event_with_keycode_cb process_key_event_with_keycode; /**< Called when the key event is received from the external keyboard devices */
94 ime_display_language_changed_cb display_language_changed; /**< Called when the system display language is changed */
95 ime_rotation_degree_changed_cb rotation_degree_changed; /**< Called when the device is rotated */
96 ime_accessibility_state_changed_cb accessibility_state_changed; /**< Called when Accessibility in Settings application is on or off */
97 ime_option_window_created_cb option_window_created; /**< Called to create the option window */
98 ime_option_window_destroyed_cb option_window_destroyed; /**< Called to destroy the option window */
99 ime_caps_mode_changed_cb caps_mode_changed;
100 ime_candidate_show_cb candidate_show;
101 ime_candidate_hide_cb candidate_hide;
102 ime_lookup_table_changed_cb lookup_table_changed;
103 ime_process_input_device_event_cb process_input_device_event; /**< Called when the event is received from the unconventional input devices */
104 ime_prediction_hint_set_cb prediction_hint_set;
105 ime_mime_type_set_request_cb mime_type_set;
106 ime_prediction_hint_data_set_cb prediction_hint_data_set;
107 ime_optimization_hint_set_cb optimization_hint_set;
108 void *focus_in_user_data;
109 void *focus_out_user_data;
110 void *surrounding_text_updated_user_data;
111 void *input_context_reset_user_data;
112 void *cursor_position_updated_user_data;
113 void *language_requested_user_data;
114 void *language_set_user_data;
115 void *imdata_set_user_data;
116 void *imdata_requested_user_data;
117 void *layout_set_user_data;
118 void *return_key_type_set_user_data;
119 void *return_key_state_set_user_data;
120 void *geometry_requested_user_data;
121 void *process_key_event_user_data;
122 void *process_key_event_with_keycode_user_data;
123 void *display_language_changed_user_data;
124 void *rotation_degree_changed_user_data;
125 void *accessibility_state_changed_user_data;
126 void *option_window_created_user_data;
127 void *option_window_destroyed_user_data;
128 void *caps_mode_changed_user_data;
129 void *candidate_show_user_data;
130 void *candidate_hide_user_data;
131 void *lookup_table_changed_user_data;
132 void *process_input_device_event_user_data;
133 void *prediction_hint_set_user_data;
134 void *mime_type_set_user_data;
135 void *prediction_hint_data_set_user_data;
136 void *optimization_hint_set_user_data;
137 } ime_event_callback_s;
140 ime_input_device_type_e device_type;
142 } ime_device_event_s;
144 static ime_callback_s g_basic_callback = {NULL};
145 static ime_event_callback_s g_event_callback = {NULL};
146 static void *g_user_data = NULL;
147 static bool g_running = false;
149 static CCoreEventCallback g_core_event_callback;
150 CSCLCore g_core(&g_core_event_callback);
152 static bool g_checked_privilege = false;
153 static bool g_permission_allowed = false;
156 extern void ime_app_main(int argc, char **argv);
160 void CCoreEventCallback::on_init()
162 if (g_basic_callback.create) {
163 g_basic_callback.create(g_user_data);
167 void CCoreEventCallback::on_run(int argc, char **argv)
170 ime_app_main(argc, argv);
173 void CCoreEventCallback::on_exit()
176 if (g_basic_callback.terminate) {
177 g_basic_callback.terminate(g_user_data);
181 void CCoreEventCallback::on_update_cursor_position(sclint ic, const sclchar *ic_uuid, sclint cursor_pos)
183 if (g_event_callback.cursor_position_updated) {
184 g_event_callback.cursor_position_updated(cursor_pos, g_event_callback.cursor_position_updated_user_data);
188 void CCoreEventCallback::on_update_surrounding_text(sclint ic, const sclchar *text, sclint cursor)
190 if (g_event_callback.surrounding_text_updated) {
191 g_event_callback.surrounding_text_updated(ic, text, cursor, g_event_callback.surrounding_text_updated_user_data);
195 void CCoreEventCallback::on_focus_out(sclint ic, const sclchar *ic_uuid)
197 if (g_event_callback.focus_out) {
198 g_event_callback.focus_out(ic, g_event_callback.focus_out_user_data);
202 void CCoreEventCallback::on_focus_in(sclint ic, const sclchar *ic_uuid)
204 if (g_event_callback.focus_in) {
205 g_event_callback.focus_in(ic, g_event_callback.focus_in_user_data);
209 void CCoreEventCallback::on_ise_show(sclint ic, const int degree, Ise_Context &context)
211 if (g_basic_callback.show) {
212 struct _ime_context input_context;
214 memset(&input_context, 0, sizeof(struct _ime_context));
215 input_context.layout = context.layout;
216 input_context.layout_variation = context.layout_variation;
217 input_context.cursor_pos = context.cursor_pos;
218 input_context.autocapital_type = context.autocapital_type;
219 input_context.return_key_type = context.return_key_type;
220 input_context.return_key_disabled = context.return_key_disabled;
221 input_context.prediction_allow = context.prediction_allow;
222 input_context.password_mode = context.password_mode;
223 input_context.imdata_size = context.imdata_size;
224 input_context.input_hint = context.input_hint;
225 input_context.bidi_direction = context.bidi_direction;
226 input_context.language = context.language;
227 input_context.client_window = context.client_window;
228 input_context.caps_mode = context.caps_mode;
230 g_basic_callback.show(ic, static_cast<ime_context_h>(&input_context), g_user_data);
234 void CCoreEventCallback::on_ise_hide(sclint ic, const sclchar *ic_uuid)
236 if (g_basic_callback.hide) {
237 g_basic_callback.hide(ic, g_user_data);
241 void CCoreEventCallback::on_get_geometry(sclu32 *pos_x, sclu32 *pos_y, sclu32 *width, sclu32 *height)
243 int geometry_pos_x = 0;
244 int geometry_pos_y = 0;
245 int geometry_width = 0;
246 int geometry_height = 0;
248 if (g_event_callback.geometry_requested) {
249 g_event_callback.geometry_requested(g_event_callback.geometry_requested_user_data, &geometry_pos_x, &geometry_pos_y, &geometry_width, &geometry_height);
253 *pos_x = geometry_pos_x;
256 *pos_y = geometry_pos_y;
259 *width = geometry_width;
262 *height = geometry_height;
265 void CCoreEventCallback::on_set_language(sclu32 language)
267 if (g_event_callback.language_set) {
268 g_event_callback.language_set((Ecore_IMF_Input_Panel_Lang)language, g_event_callback.language_set_user_data);
272 void CCoreEventCallback::on_set_imdata(sclchar *buf, sclu32 len)
274 if (g_event_callback.imdata_set) {
275 g_event_callback.imdata_set((void *)buf, len, g_event_callback.imdata_set_user_data);
279 void CCoreEventCallback::on_get_imdata(sclchar **buf, sclu32 *len)
281 if (g_event_callback.imdata_requested) {
282 g_event_callback.imdata_requested(g_event_callback.imdata_set_user_data, (void **)buf, len);
286 void CCoreEventCallback::on_get_language_locale(sclint ic, sclchar **locale)
288 if (g_event_callback.language_requested) {
289 g_event_callback.language_requested(g_event_callback.language_requested_user_data, locale);
293 void CCoreEventCallback::on_set_return_key_type(sclu32 type)
295 if (g_event_callback.return_key_type_set) {
296 g_event_callback.return_key_type_set((Ecore_IMF_Input_Panel_Return_Key_Type)type, g_event_callback.return_key_type_set_user_data);
300 void CCoreEventCallback::on_set_return_key_disable(sclu32 disabled)
302 bool return_key_disabled = !!disabled;
304 if (g_event_callback.return_key_state_set) {
305 g_event_callback.return_key_state_set(return_key_disabled, g_event_callback.return_key_state_set_user_data);
309 void CCoreEventCallback::on_set_layout(sclu32 layout)
311 if (g_event_callback.layout_set) {
312 g_event_callback.layout_set(static_cast<Ecore_IMF_Input_Panel_Layout>(layout), g_event_callback.layout_set_user_data);
316 void CCoreEventCallback::on_reset_input_context(sclint ic, const sclchar *uuid)
318 if (g_event_callback.input_context_reset) {
319 g_event_callback.input_context_reset(g_event_callback.input_context_reset_user_data);
323 void CCoreEventCallback::on_process_key_event(scim::KeyEvent &key, sclu32 *ret)
325 if (g_event_callback.process_key_event) {
326 struct _ime_device_info dev_info = {key.dev_name.c_str(),
327 static_cast<Ecore_IMF_Device_Class>(key.dev_class), static_cast<Ecore_IMF_Device_Subclass>(key.dev_subclass)};
328 bool processed = g_event_callback.process_key_event(static_cast<ime_key_code_e>(key.code), static_cast<ime_key_mask_e>(key.mask),
329 static_cast<ime_device_info_h>(&dev_info), g_event_callback.process_key_event_user_data);
344 void CCoreEventCallback::on_process_key_event_with_keycode(scim::KeyEvent &key, sclu32 *ret, sclu32 keycode)
346 if (g_event_callback.process_key_event_with_keycode) {
347 struct _ime_device_info dev_info = {key.dev_name.c_str(),
348 static_cast<Ecore_IMF_Device_Class>(key.dev_class), static_cast<Ecore_IMF_Device_Subclass>(key.dev_subclass)};
349 bool processed = g_event_callback.process_key_event_with_keycode(keycode, static_cast<ime_key_code_e>(key.code), static_cast<ime_key_mask_e>(key.mask),
350 static_cast<ime_device_info_h>(&dev_info), g_event_callback.process_key_event_user_data);
365 void CCoreEventCallback::on_set_display_language(const sclchar *language)
367 if (g_event_callback.display_language_changed) {
368 g_event_callback.display_language_changed(language, g_event_callback.display_language_changed_user_data);
372 void CCoreEventCallback::on_set_rotation_degree(sclint degree)
374 if (g_event_callback.rotation_degree_changed) {
375 g_event_callback.rotation_degree_changed(degree, g_event_callback.rotation_degree_changed_user_data);
379 void CCoreEventCallback::on_set_accessibility_state(sclboolean state)
381 if (g_event_callback.accessibility_state_changed) {
382 g_event_callback.accessibility_state_changed(state, g_event_callback.accessibility_state_changed_user_data);
386 void CCoreEventCallback::on_create_option_window(sclwindow window, SCLOptionWindowType type)
388 if (g_event_callback.option_window_created) {
389 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);
393 void CCoreEventCallback::on_destroy_option_window(sclwindow window)
395 if (g_event_callback.option_window_destroyed) {
396 g_event_callback.option_window_destroyed(static_cast<Evas_Object*>(window), g_event_callback.option_window_destroyed_user_data);
400 void CCoreEventCallback::on_check_option_window_availability(sclboolean *ret)
403 if (g_event_callback.option_window_created) // Instead of each 3rd party keyboard, inputmethod will reply the availability of the option (setting).
410 void CCoreEventCallback::on_set_caps_mode(sclu32 mode)
412 if (g_event_callback.caps_mode_changed) {
413 g_event_callback.caps_mode_changed(mode, g_event_callback.caps_mode_changed_user_data);
417 void CCoreEventCallback::on_candidate_show(sclint ic, const sclchar *ic_uuid)
419 if (g_event_callback.candidate_show) {
420 g_event_callback.candidate_show(ic, g_event_callback.candidate_show_user_data);
424 void CCoreEventCallback::on_candidate_hide(sclint ic, const sclchar *ic_uuid)
426 if (g_event_callback.candidate_hide) {
427 g_event_callback.candidate_hide(ic, g_event_callback.candidate_hide_user_data);
431 void CCoreEventCallback::on_update_lookup_table(SclCandidateTable &table)
433 Eina_List *string_list = NULL;
435 if (g_event_callback.lookup_table_changed) {
436 vector<string>::iterator iter = table.candidate.begin();
437 for (; iter != table.candidate.end(); ++iter) {
438 string_list = eina_list_append(string_list, iter->c_str());
441 g_event_callback.lookup_table_changed(string_list, g_event_callback.lookup_table_changed_user_data);
445 void CCoreEventCallback::on_process_input_device_event(sclu32 &type, sclchar *data, size_t &len, sclu32 *ret)
449 ime_input_device_type_e device_type;
450 } ime_device_type_conv_table;
452 ime_device_type_conv_table conv_table[] = {
453 { ECORE_EVENT_DETENT_ROTATE , IME_INPUT_DEVICE_TYPE_ROTARY },
456 ime_input_device_type_e device_type = IME_INPUT_DEVICE_TYPE_UNKNOWN;
457 for (unsigned int loop = 0; loop < sizeof(conv_table) / sizeof(ime_device_type_conv_table); loop++) {
458 if ((unsigned int)(conv_table[loop].ecore_event_id) == type) {
459 device_type = conv_table[loop].device_type;
463 if (g_event_callback.process_input_device_event) {
464 ime_device_event_s device_event;
465 device_event.device_type = device_type;
466 device_event.event_data = static_cast<void*>(data);
467 void *input_data = static_cast<void*>(&device_event);
468 void *user_data = g_event_callback.process_input_device_event_user_data;
470 g_event_callback.process_input_device_event(device_type, input_data, user_data);
482 void CCoreEventCallback::on_set_prediction_hint(const sclchar *prediction_hint)
484 if (g_event_callback.prediction_hint_set) {
485 g_event_callback.prediction_hint_set(prediction_hint, g_event_callback.prediction_hint_set_user_data);
489 void CCoreEventCallback::on_set_mime_type(const sclchar *mime_type)
491 if (g_event_callback.mime_type_set) {
492 g_event_callback.mime_type_set(mime_type, g_event_callback.mime_type_set_user_data);
496 void CCoreEventCallback::on_set_prediction_hint_data(const sclchar *key, const sclchar *value)
498 if (g_event_callback.prediction_hint_data_set) {
499 g_event_callback.prediction_hint_data_set(key, value, g_event_callback.prediction_hint_data_set_user_data);
503 void CCoreEventCallback::on_set_optimization_hint(sclu32 hint)
505 if (g_event_callback.optimization_hint_set) {
506 g_event_callback.optimization_hint_set((ime_optimization_hint_e)hint, g_event_callback.optimization_hint_set_user_data);
510 void ime_privilege_cache_init()
512 g_permission_allowed = false;
513 g_checked_privilege = false;
517 ime_error_e _check_privilege()
520 ime_error_e ret = IME_ERROR_NONE;
522 if (g_checked_privilege) {
523 return g_permission_allowed ? IME_ERROR_NONE : IME_ERROR_PERMISSION_DENIED;
526 if (inputmethod_cynara_initialize() == false) {
528 g_permission_allowed = false;
529 g_checked_privilege = true;
530 LOGE("inputmethod_cynara_initialize () == false");
532 return IME_ERROR_PERMISSION_DENIED;
535 snprintf(uid, 16, "%d", getuid());
536 if (check_privilege(uid, IME_PRIVILEGE) == false) {
537 LOGE("check_privilege(uid, IME_PRIVILEGE) == false. uid : %s", uid); //LCOV_EXCL_LINE
538 ret = IME_ERROR_PERMISSION_DENIED;
541 g_permission_allowed = (ret == IME_ERROR_NONE);
542 g_checked_privilege = true;
544 inputmethod_cynara_finish();
550 bool g_from_dotnet = false;
551 EXPORT_API int ime_set_dotnet_flag(bool set)
553 ime_error_e retVal = IME_ERROR_NONE;
555 retVal = _check_privilege();
556 if (retVal != IME_ERROR_NONE) return retVal;
564 EXPORT_API int ime_run(ime_callback_s *basic_cb, void *user_data)
566 ime_error_e retVal = IME_ERROR_NONE;
570 LOGE("inputmethod main loop is already running.");
571 return IME_ERROR_OPERATION_FAILED;
576 LOGE("basic callbacks pointer is null.");
577 return IME_ERROR_INVALID_PARAMETER;
580 retVal = _check_privilege();
581 if (retVal != IME_ERROR_NONE) return retVal;
583 g_basic_callback = *basic_cb;
585 if (!g_basic_callback.create || !g_basic_callback.terminate ||
586 !g_basic_callback.show || !g_basic_callback.hide) {
587 LOGE("mandatory callback functions are not set");
588 memset(&g_basic_callback, 0, sizeof(ime_callback_s));
589 memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
590 return IME_ERROR_NO_CALLBACK_FUNCTION;
594 g_user_data = user_data;
598 LOGD("ime_run is called from dotnet");
599 return IME_ERROR_NONE;
605 LOGW("exception is thrown from g_core.run()\n");
608 memset(&g_basic_callback, 0, sizeof(ime_callback_s));
609 memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
613 return IME_ERROR_NONE;
617 EXPORT_API int ime_event_set_focus_in_cb(ime_focus_in_cb callback_func, void *user_data)
619 ime_error_e retVal = IME_ERROR_NONE;
621 if (!callback_func) {
622 LOGW("IME_ERROR_INVALID_PARAMETER");
623 return IME_ERROR_INVALID_PARAMETER;
626 retVal = _check_privilege();
627 if (retVal != IME_ERROR_NONE) return retVal;
629 g_event_callback.focus_in = callback_func;
630 g_event_callback.focus_in_user_data = user_data;
632 return IME_ERROR_NONE;
635 EXPORT_API int ime_event_set_focus_out_cb(ime_focus_out_cb callback_func, void *user_data)
637 ime_error_e retVal = IME_ERROR_NONE;
639 if (!callback_func) {
640 LOGW("IME_ERROR_INVALID_PARAMETER");
641 return IME_ERROR_INVALID_PARAMETER;
644 retVal = _check_privilege();
645 if (retVal != IME_ERROR_NONE) return retVal;
647 g_event_callback.focus_out = callback_func;
648 g_event_callback.focus_out_user_data = user_data;
650 return IME_ERROR_NONE;
653 EXPORT_API int ime_event_set_surrounding_text_updated_cb(ime_surrounding_text_updated_cb callback_func, void *user_data)
655 ime_error_e retVal = IME_ERROR_NONE;
657 if (!callback_func) {
658 LOGW("IME_ERROR_INVALID_PARAMETER");
659 return IME_ERROR_INVALID_PARAMETER;
662 retVal = _check_privilege();
663 if (retVal != IME_ERROR_NONE) return retVal;
665 g_event_callback.surrounding_text_updated = callback_func;
666 g_event_callback.surrounding_text_updated_user_data = user_data;
668 return IME_ERROR_NONE;
671 EXPORT_API int ime_event_set_input_context_reset_cb(ime_input_context_reset_cb callback_func, void *user_data)
673 ime_error_e retVal = IME_ERROR_NONE;
675 if (!callback_func) {
676 LOGW("IME_ERROR_INVALID_PARAMETER");
677 return IME_ERROR_INVALID_PARAMETER;
680 retVal = _check_privilege();
681 if (retVal != IME_ERROR_NONE) return retVal;
683 g_event_callback.input_context_reset = callback_func;
684 g_event_callback.input_context_reset_user_data = user_data;
686 return IME_ERROR_NONE;
689 EXPORT_API int ime_event_set_cursor_position_updated_cb(ime_cursor_position_updated_cb callback_func, void *user_data)
691 ime_error_e retVal = IME_ERROR_NONE;
693 if (!callback_func) {
694 LOGW("IME_ERROR_INVALID_PARAMETER");
695 return IME_ERROR_INVALID_PARAMETER;
698 retVal = _check_privilege();
699 if (retVal != IME_ERROR_NONE) return retVal;
701 g_event_callback.cursor_position_updated = callback_func;
702 g_event_callback.cursor_position_updated_user_data = user_data;
704 return IME_ERROR_NONE;
707 EXPORT_API int ime_event_set_language_requested_cb(ime_language_requested_cb callback_func, void *user_data)
709 ime_error_e retVal = IME_ERROR_NONE;
711 if (!callback_func) {
712 LOGW("IME_ERROR_INVALID_PARAMETER");
713 return IME_ERROR_INVALID_PARAMETER;
716 retVal = _check_privilege();
717 if (retVal != IME_ERROR_NONE) return retVal;
719 g_event_callback.language_requested = callback_func;
720 g_event_callback.language_requested_user_data = user_data;
722 return IME_ERROR_NONE;
725 EXPORT_API int ime_event_set_language_set_cb(ime_language_set_cb callback_func, void *user_data)
727 ime_error_e retVal = IME_ERROR_NONE;
729 if (!callback_func) {
730 LOGW("IME_ERROR_INVALID_PARAMETER");
731 return IME_ERROR_INVALID_PARAMETER;
734 retVal = _check_privilege();
735 if (retVal != IME_ERROR_NONE) return retVal;
737 g_event_callback.language_set = callback_func;
738 g_event_callback.language_set_user_data = user_data;
740 return IME_ERROR_NONE;
743 EXPORT_API int ime_event_set_imdata_set_cb(ime_imdata_set_cb callback_func, void *user_data)
745 ime_error_e retVal = IME_ERROR_NONE;
747 if (!callback_func) {
748 LOGW("IME_ERROR_INVALID_PARAMETER");
749 return IME_ERROR_INVALID_PARAMETER;
752 retVal = _check_privilege();
753 if (retVal != IME_ERROR_NONE) return retVal;
755 g_event_callback.imdata_set = callback_func;
756 g_event_callback.imdata_set_user_data = user_data;
758 return IME_ERROR_NONE;
761 EXPORT_API int ime_event_set_imdata_requested_cb(ime_imdata_requested_cb callback_func, void *user_data)
763 ime_error_e retVal = IME_ERROR_NONE;
765 if (!callback_func) {
766 LOGW("IME_ERROR_INVALID_PARAMETER");
767 return IME_ERROR_INVALID_PARAMETER;
770 retVal = _check_privilege();
771 if (retVal != IME_ERROR_NONE) return retVal;
773 g_event_callback.imdata_requested = callback_func;
774 g_event_callback.imdata_requested_user_data = user_data;
776 return IME_ERROR_NONE;
779 EXPORT_API int ime_event_set_layout_set_cb(ime_layout_set_cb callback_func, void *user_data)
781 ime_error_e retVal = IME_ERROR_NONE;
783 if (!callback_func) {
784 LOGW("IME_ERROR_INVALID_PARAMETER");
785 return IME_ERROR_INVALID_PARAMETER;
788 retVal = _check_privilege();
789 if (retVal != IME_ERROR_NONE) return retVal;
791 g_event_callback.layout_set = callback_func;
792 g_event_callback.layout_set_user_data = user_data;
794 return IME_ERROR_NONE;
797 EXPORT_API int ime_event_set_return_key_type_set_cb(ime_return_key_type_set_cb callback_func, void *user_data)
799 ime_error_e retVal = IME_ERROR_NONE;
801 if (!callback_func) {
802 LOGW("IME_ERROR_INVALID_PARAMETER");
803 return IME_ERROR_INVALID_PARAMETER;
806 retVal = _check_privilege();
807 if (retVal != IME_ERROR_NONE) return retVal;
809 g_event_callback.return_key_type_set = callback_func;
810 g_event_callback.return_key_type_set_user_data = user_data;
812 return IME_ERROR_NONE;
815 EXPORT_API int ime_event_set_return_key_state_set_cb(ime_return_key_state_set_cb callback_func, void *user_data)
817 ime_error_e retVal = IME_ERROR_NONE;
819 if (!callback_func) {
820 LOGW("IME_ERROR_INVALID_PARAMETER");
821 return IME_ERROR_INVALID_PARAMETER;
824 retVal = _check_privilege();
825 if (retVal != IME_ERROR_NONE) return retVal;
827 g_event_callback.return_key_state_set = callback_func;
828 g_event_callback.return_key_state_set_user_data = user_data;
830 return IME_ERROR_NONE;
833 EXPORT_API int ime_event_set_geometry_requested_cb(ime_geometry_requested_cb callback_func, void *user_data)
835 ime_error_e retVal = IME_ERROR_NONE;
837 if (!callback_func) {
838 LOGW("IME_ERROR_INVALID_PARAMETER");
839 return IME_ERROR_INVALID_PARAMETER;
842 retVal = _check_privilege();
843 if (retVal != IME_ERROR_NONE) return retVal;
845 g_event_callback.geometry_requested = callback_func;
846 g_event_callback.geometry_requested_user_data = user_data;
848 return IME_ERROR_NONE;
851 EXPORT_API int ime_event_set_process_key_event_cb(ime_process_key_event_cb callback_func, void *user_data)
853 ime_error_e retVal = IME_ERROR_NONE;
855 if (!callback_func) {
856 LOGW("IME_ERROR_INVALID_PARAMETER");
857 return IME_ERROR_INVALID_PARAMETER;
860 retVal = _check_privilege();
861 if (retVal != IME_ERROR_NONE) return retVal;
863 g_event_callback.process_key_event = callback_func;
864 g_event_callback.process_key_event_user_data = user_data;
866 return IME_ERROR_NONE;
869 EXPORT_API int ime_event_set_process_key_event_with_keycode_cb(ime_process_key_event_with_keycode_cb callback_func, void *user_data)
871 ime_error_e retVal = IME_ERROR_NONE;
873 if (!callback_func) {
874 LOGW("IME_ERROR_INVALID_PARAMETER");
875 return IME_ERROR_INVALID_PARAMETER;
878 retVal = _check_privilege();
879 if (retVal != IME_ERROR_NONE) return retVal;
881 g_event_callback.process_key_event_with_keycode = callback_func;
882 g_event_callback.process_key_event_with_keycode_user_data = user_data;
884 return IME_ERROR_NONE;
887 EXPORT_API int ime_event_set_display_language_changed_cb(ime_display_language_changed_cb callback_func, void *user_data)
889 ime_error_e retVal = IME_ERROR_NONE;
891 if (!callback_func) {
892 LOGW("IME_ERROR_INVALID_PARAMETER");
893 return IME_ERROR_INVALID_PARAMETER;
896 retVal = _check_privilege();
897 if (retVal != IME_ERROR_NONE) return retVal;
899 g_event_callback.display_language_changed = callback_func;
900 g_event_callback.display_language_changed_user_data = user_data;
902 return IME_ERROR_NONE;
905 EXPORT_API int ime_event_set_rotation_degree_changed_cb(ime_rotation_degree_changed_cb callback_func, void *user_data)
907 ime_error_e retVal = IME_ERROR_NONE;
909 if (!callback_func) {
910 LOGW("IME_ERROR_INVALID_PARAMETER");
911 return IME_ERROR_INVALID_PARAMETER;
914 retVal = _check_privilege();
915 if (retVal != IME_ERROR_NONE) return retVal;
917 g_event_callback.rotation_degree_changed = callback_func;
918 g_event_callback.rotation_degree_changed_user_data = user_data;
920 return IME_ERROR_NONE;
923 EXPORT_API int ime_event_set_accessibility_state_changed_cb(ime_accessibility_state_changed_cb callback_func, void *user_data)
925 ime_error_e retVal = IME_ERROR_NONE;
927 if (!callback_func) {
928 LOGW("IME_ERROR_INVALID_PARAMETER");
929 return IME_ERROR_INVALID_PARAMETER;
932 retVal = _check_privilege();
933 if (retVal != IME_ERROR_NONE) return retVal;
935 g_event_callback.accessibility_state_changed = callback_func;
936 g_event_callback.accessibility_state_changed_user_data = user_data;
938 return IME_ERROR_NONE;
941 EXPORT_API int ime_event_set_option_window_created_cb(ime_option_window_created_cb callback_func, void *user_data)
943 ime_error_e retVal = IME_ERROR_NONE;
945 if (!callback_func) {
946 LOGW("IME_ERROR_INVALID_PARAMETER");
947 return IME_ERROR_INVALID_PARAMETER;
950 retVal = _check_privilege();
951 if (retVal != IME_ERROR_NONE) return retVal;
953 g_event_callback.option_window_created = callback_func;
954 g_event_callback.option_window_created_user_data = user_data;
956 return IME_ERROR_NONE;
959 EXPORT_API int ime_event_set_option_window_destroyed_cb(ime_option_window_destroyed_cb callback_func, void *user_data)
961 ime_error_e retVal = IME_ERROR_NONE;
963 if (!callback_func) {
964 LOGW("IME_ERROR_INVALID_PARAMETER");
965 return IME_ERROR_INVALID_PARAMETER;
968 retVal = _check_privilege();
969 if (retVal != IME_ERROR_NONE) return retVal;
971 g_event_callback.option_window_destroyed = callback_func;
972 g_event_callback.option_window_destroyed_user_data = user_data;
974 return IME_ERROR_NONE;
978 EXPORT_API int ime_event_set_caps_mode_changed_cb(ime_caps_mode_changed_cb callback_func, void *user_data)
980 ime_error_e retVal = IME_ERROR_NONE;
982 if (!callback_func) {
983 LOGW("IME_ERROR_INVALID_PARAMETER");
984 return IME_ERROR_INVALID_PARAMETER;
987 retVal = _check_privilege();
988 if (retVal != IME_ERROR_NONE) return retVal;
990 g_event_callback.caps_mode_changed = callback_func;
991 g_event_callback.caps_mode_changed_user_data = user_data;
993 return IME_ERROR_NONE;
996 EXPORT_API int ime_event_set_candidate_show_cb(ime_candidate_show_cb callback_func, void *user_data)
998 ime_error_e retVal = IME_ERROR_NONE;
1000 if (!callback_func) {
1001 LOGW("IME_ERROR_INVALID_PARAMETER");
1002 return IME_ERROR_INVALID_PARAMETER;
1005 retVal = _check_privilege();
1006 if (retVal != IME_ERROR_NONE) return retVal;
1008 g_event_callback.candidate_show = callback_func;
1009 g_event_callback.candidate_show_user_data = user_data;
1011 return IME_ERROR_NONE;
1014 EXPORT_API int ime_event_set_candidate_hide_cb(ime_candidate_hide_cb callback_func, void *user_data)
1016 ime_error_e retVal = IME_ERROR_NONE;
1018 if (!callback_func) {
1019 LOGW("IME_ERROR_INVALID_PARAMETER");
1020 return IME_ERROR_INVALID_PARAMETER;
1023 retVal = _check_privilege();
1024 if (retVal != IME_ERROR_NONE) return retVal;
1026 g_event_callback.candidate_hide = callback_func;
1027 g_event_callback.candidate_hide_user_data = user_data;
1029 return IME_ERROR_NONE;
1032 EXPORT_API int ime_event_set_lookup_table_changed_cb(ime_lookup_table_changed_cb callback_func, void *user_data)
1034 ime_error_e retVal = IME_ERROR_NONE;
1036 if (!callback_func) {
1037 LOGW("IME_ERROR_INVALID_PARAMETER");
1038 return IME_ERROR_INVALID_PARAMETER;
1041 retVal = _check_privilege();
1042 if (retVal != IME_ERROR_NONE) return retVal;
1044 g_event_callback.lookup_table_changed = callback_func;
1045 g_event_callback.lookup_table_changed_user_data = user_data;
1047 return IME_ERROR_NONE;
1051 EXPORT_API int ime_send_key_event(ime_key_code_e keycode, ime_key_mask_e keymask, bool forward_key)
1053 ime_error_e retVal = IME_ERROR_NONE;
1056 LOGW("IME_ERROR_NOT_RUNNING");
1057 return IME_ERROR_NOT_RUNNING;
1061 retVal = _check_privilege();
1062 if (retVal != IME_ERROR_NONE) return retVal;
1065 g_core.forward_key_event(-1, NULL, (sclu32)keycode, (sclu16)keymask);
1067 g_core.send_key_event(-1, NULL, (sclu32)keycode, (sclu16)keymask);
1070 return IME_ERROR_NONE;
1073 EXPORT_API int ime_commit_string(const char *str)
1075 ime_error_e retVal = IME_ERROR_NONE;
1078 LOGW("IME_ERROR_INVALID_PARAMETER");
1079 return IME_ERROR_INVALID_PARAMETER;
1083 LOGW("IME_ERROR_NOT_RUNNING");
1084 return IME_ERROR_NOT_RUNNING;
1088 retVal = _check_privilege();
1089 if (retVal != IME_ERROR_NONE) return retVal;
1091 SECURE_LOGI("commit string : %s", str);
1092 g_core.commit_string(-1, NULL, str);
1094 return IME_ERROR_NONE;
1098 EXPORT_API int ime_show_preedit_string(void)
1100 ime_error_e retVal = IME_ERROR_NONE;
1103 LOGW("IME_ERROR_NOT_RUNNING");
1104 return IME_ERROR_NOT_RUNNING;
1108 retVal = _check_privilege();
1109 if (retVal != IME_ERROR_NONE) return retVal;
1111 g_core.show_preedit_string(-1, NULL);
1113 return IME_ERROR_NONE;
1117 EXPORT_API int ime_hide_preedit_string(void)
1119 ime_error_e retVal = IME_ERROR_NONE;
1122 LOGW("IME_ERROR_NOT_RUNNING");
1123 return IME_ERROR_NOT_RUNNING;
1127 retVal = _check_privilege();
1128 if (retVal != IME_ERROR_NONE) return retVal;
1130 g_core.hide_preedit_string(-1, NULL);
1132 return IME_ERROR_NONE;
1136 EXPORT_API int ime_update_preedit_string(const char *str, Eina_List *attrs)
1138 ime_error_e retVal = IME_ERROR_NONE;
1141 LOGW("IME_ERROR_INVALID_PARAMETER");
1142 return IME_ERROR_INVALID_PARAMETER;
1146 LOGW("IME_ERROR_NOT_RUNNING");
1147 return IME_ERROR_NOT_RUNNING;
1151 retVal = _check_privilege();
1152 if (retVal != IME_ERROR_NONE) return retVal;
1154 scim::AttributeList attrv;
1156 ime_preedit_attribute *attr = NULL;
1159 EINA_LIST_FREE(attrs, data) {
1160 attr = (ime_preedit_attribute *)data;
1162 attrv.push_back(scim::Attribute(attr->start, attr->length, (scim::AttributeType)attr->type, attr->value));
1168 SECURE_LOGI("preedit string : '%s'", str);
1169 g_core.update_preedit_string(-1, NULL, str, attrv);
1171 return IME_ERROR_NONE;
1175 EXPORT_API int ime_request_surrounding_text(int maxlen_before, int maxlen_after)
1177 ime_error_e retVal = IME_ERROR_NONE;
1179 if (!g_event_callback.surrounding_text_updated) {
1180 LOGW("IME_ERROR_NO_CALLBACK_FUNCTION");
1181 return IME_ERROR_NO_CALLBACK_FUNCTION;
1185 LOGW("IME_ERROR_NOT_RUNNING");
1186 return IME_ERROR_NOT_RUNNING;
1190 retVal = _check_privilege();
1191 if (retVal != IME_ERROR_NONE) return retVal;
1193 g_core.get_surrounding_text(NULL, maxlen_before, maxlen_after);
1195 return IME_ERROR_NONE;
1199 EXPORT_API int ime_delete_surrounding_text(int offset, int len)
1201 ime_error_e retVal = IME_ERROR_NONE;
1204 LOGW("IME_ERROR_INVALID_PARAMETER");
1205 return IME_ERROR_INVALID_PARAMETER;
1209 LOGW("IME_ERROR_NOT_RUNNING");
1210 return IME_ERROR_NOT_RUNNING;
1214 retVal = _check_privilege();
1215 if (retVal != IME_ERROR_NONE) return retVal;
1217 LOGI("offset: %d, len : %d", offset, len);
1218 g_core.delete_surrounding_text(offset, len);
1220 return IME_ERROR_NONE;
1224 EXPORT_API int ime_get_surrounding_text(int maxlen_before, int maxlen_after, char **text, int *cursor_pos)
1226 ime_error_e retVal = IME_ERROR_NONE;
1228 if (!text || !cursor_pos) {
1229 LOGW("IME_ERROR_INVALID_PARAMETER");
1230 return IME_ERROR_INVALID_PARAMETER;
1234 LOGW("IME_ERROR_NOT_RUNNING");
1235 return IME_ERROR_NOT_RUNNING;
1239 retVal = _check_privilege();
1240 if (retVal != IME_ERROR_NONE) return retVal;
1244 int ret = g_core.get_surrounding_text(maxlen_before, maxlen_after, text, cursor);
1246 LOGW("IME_ERROR_OUR_OF_MEMORY");
1247 return IME_ERROR_OUT_OF_MEMORY;
1251 *cursor_pos = cursor;
1253 return IME_ERROR_NONE;
1257 EXPORT_API int ime_set_selection(int start, int end)
1259 ime_error_e retVal = IME_ERROR_NONE;
1262 LOGW("IME_ERROR_INVALID_PARAMETER");
1263 return IME_ERROR_INVALID_PARAMETER;
1267 LOGW("IME_ERROR_NOT_RUNNING");
1268 return IME_ERROR_NOT_RUNNING;
1272 retVal = _check_privilege();
1273 if (retVal != IME_ERROR_NONE) return retVal;
1275 LOGI("start: %d, end : %d", start, end);
1276 g_core.set_selection(start, end);
1278 return IME_ERROR_NONE;
1282 EXPORT_API int ime_get_selected_text(char **text)
1284 ime_error_e retVal = IME_ERROR_NONE;
1287 LOGW("IME_ERROR_INVALID_PARAMETER");
1288 return IME_ERROR_INVALID_PARAMETER;
1292 LOGW("IME_ERROR_NOT_RUNNING");
1293 return IME_ERROR_NOT_RUNNING;
1297 retVal = _check_privilege();
1298 if (retVal != IME_ERROR_NONE) return retVal;
1300 g_core.get_selection_text(text);
1302 return IME_ERROR_NONE;
1306 EXPORT_API Evas_Object* ime_get_main_window(void)
1308 ime_error_e retVal = IME_ERROR_NONE;
1310 Evas_Object *win = NULL;
1312 retVal = _check_privilege();
1313 if (retVal != IME_ERROR_NONE) {
1315 LOGE("_check_privilege returned %d.", retVal);
1316 set_last_result(retVal);
1322 set_last_result(IME_ERROR_NOT_RUNNING);
1323 LOGW("IME_ERROR_NOT_RUNNING");
1328 win = static_cast<Evas_Object*>(g_core.get_main_window());
1330 set_last_result(IME_ERROR_NONE);
1332 set_last_result(IME_ERROR_OPERATION_FAILED);
1333 LOGW("IME_ERROR_OPERATION_FAILED");
1340 EXPORT_API int ime_set_size(int portrait_width, int portrait_height, int landscape_width, int landscape_height)
1342 ime_error_e retVal = IME_ERROR_NONE;
1344 SclSize portrait_size, landscape_size;
1346 if (portrait_width < 1 || portrait_height < 1 || landscape_width < 1 || landscape_height < 1) {
1347 LOGW("IME_ERROR_INVALID_PARAMETER");
1348 return IME_ERROR_INVALID_PARAMETER;
1352 LOGW("IME_ERROR_NOT_RUNNING");
1353 return IME_ERROR_NOT_RUNNING;
1357 retVal = _check_privilege();
1358 if (retVal != IME_ERROR_NONE) return retVal;
1360 portrait_size.width = portrait_width;
1361 portrait_size.height = portrait_height;
1363 landscape_size.width = landscape_width;
1364 landscape_size.height = landscape_height;
1366 g_core.set_keyboard_size_hints(portrait_size, landscape_size);
1368 return IME_ERROR_NONE;
1372 EXPORT_API int ime_create_option_window(void)
1374 ime_error_e retVal = IME_ERROR_NONE;
1376 if (!g_event_callback.option_window_created || !g_event_callback.option_window_destroyed) {
1377 LOGW("ime_create_option_window_cb() and ime_destroy_option_window_cb() callback functions are not set.");
1378 return IME_ERROR_NO_CALLBACK_FUNCTION;
1382 LOGW("IME_ERROR_NOT_RUNNING");
1383 return IME_ERROR_NOT_RUNNING;
1387 retVal = _check_privilege();
1388 if (retVal != IME_ERROR_NONE) return retVal;
1390 if (g_core.create_option_window()) {
1391 return IME_ERROR_NONE;
1393 LOGW("IME_ERROR_OPERATION_FAILED");
1394 return IME_ERROR_OPERATION_FAILED;
1399 EXPORT_API int ime_destroy_option_window(Evas_Object *window)
1401 ime_error_e retVal = IME_ERROR_NONE;
1403 if (!g_event_callback.option_window_created || !g_event_callback.option_window_destroyed) {
1404 LOGW("ime_create_option_window_cb() and ime_destroy_option_window_cb() callback functions are not set.");
1405 return IME_ERROR_NO_CALLBACK_FUNCTION;
1409 LOGW("Window pointer is null.");
1410 return IME_ERROR_INVALID_PARAMETER;
1414 LOGW("IME_ERROR_NOT_RUNNING");
1415 return IME_ERROR_NOT_RUNNING;
1419 retVal = _check_privilege();
1420 if (retVal != IME_ERROR_NONE) return retVal;
1422 g_core.destroy_option_window(window);
1424 return IME_ERROR_NONE;
1429 EXPORT_API int ime_set_imengine(const char *engine_id)
1431 ime_error_e retVal = IME_ERROR_NONE;
1434 LOGW("IME_ERROR_INVALID_PARAMETER");
1435 return IME_ERROR_INVALID_PARAMETER;
1438 retVal = _check_privilege();
1439 if (retVal != IME_ERROR_NONE) return retVal;
1441 g_core.set_keyboard_ise_by_uuid(engine_id);
1443 return IME_ERROR_NONE;
1446 EXPORT_API int ime_flush_imengine(void)
1448 ime_error_e retVal = IME_ERROR_NONE;
1451 LOGW("IME_ERROR_NOT_RUNNING");
1452 return IME_ERROR_NOT_RUNNING;
1455 retVal = _check_privilege();
1456 if (retVal != IME_ERROR_NONE) return retVal;
1458 g_core.flush_keyboard_ise();
1460 return IME_ERROR_NONE;
1463 EXPORT_API int ime_send_imengine_event(int command, unsigned int value)
1465 ime_error_e retVal = IME_ERROR_NONE;
1468 LOGW("IME_ERROR_NOT_RUNNING");
1469 return IME_ERROR_NOT_RUNNING;
1472 retVal = _check_privilege();
1473 if (retVal != IME_ERROR_NONE) return retVal;
1475 g_core.send_imengine_event(-1, NULL, command, value);
1477 return IME_ERROR_NONE;
1480 EXPORT_API int ime_reset_imengine(void)
1482 ime_error_e retVal = IME_ERROR_NONE;
1485 LOGW("IME_ERROR_NOT_RUNNING");
1486 return IME_ERROR_NOT_RUNNING;
1489 retVal = _check_privilege();
1490 if (retVal != IME_ERROR_NONE) return retVal;
1492 g_core.reset_keyboard_ise();
1494 return IME_ERROR_NONE;
1497 EXPORT_API int ime_update_input_context(unsigned int type, unsigned int value)
1499 ime_error_e retVal = IME_ERROR_NONE;
1502 LOGW("IME_ERROR_NOT_RUNNING");
1503 return IME_ERROR_NOT_RUNNING;
1506 retVal = _check_privilege();
1507 if (retVal != IME_ERROR_NONE) return retVal;
1509 g_core.update_input_context(type, value);
1511 return IME_ERROR_NONE;
1515 EXPORT_API int ime_request_hide(void)
1517 ime_error_e retVal = IME_ERROR_NONE;
1520 LOGW("IME_ERROR_NOT_RUNNING");
1521 return IME_ERROR_NOT_RUNNING;
1525 retVal = _check_privilege();
1526 if (retVal != IME_ERROR_NONE) return retVal;
1528 g_core.request_ise_hide();
1530 return IME_ERROR_NONE;
1535 EXPORT_API int ime_initialize(void)
1537 ime_error_e retVal = IME_ERROR_NONE;
1539 retVal = _check_privilege();
1540 if (retVal != IME_ERROR_NONE) return retVal;
1548 EXPORT_API int ime_prepare(void)
1550 ime_error_e retVal = IME_ERROR_NONE;
1553 LOGE("inputmethod main loop is already running.");
1554 return IME_ERROR_OPERATION_FAILED;
1557 retVal = _check_privilege();
1558 if (retVal != IME_ERROR_NONE) return retVal;
1567 EXPORT_API int ime_finalize(void)
1569 ime_error_e retVal = IME_ERROR_NONE;
1571 retVal = _check_privilege();
1572 if (retVal != IME_ERROR_NONE) return retVal;
1576 memset(&g_basic_callback, 0, sizeof(ime_callback_s));
1577 memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
1583 EXPORT_API int ime_select_candidate(unsigned int index)
1585 ime_error_e retVal = IME_ERROR_NONE;
1588 LOGW("IME_ERROR_NOT_RUNNING");
1589 return IME_ERROR_NOT_RUNNING;
1592 retVal = _check_privilege();
1593 if (retVal != IME_ERROR_NONE) return retVal;
1595 g_core.select_candidate(index);
1597 return IME_ERROR_NONE;
1601 EXPORT_API int ime_send_private_command(const char *command)
1603 ime_error_e retVal = IME_ERROR_NONE;
1606 LOGW("IME_ERROR_INVALID_PARAMETER");
1607 return IME_ERROR_INVALID_PARAMETER;
1611 LOGW("IME_ERROR_NOT_RUNNING");
1612 return IME_ERROR_NOT_RUNNING;
1616 retVal = _check_privilege();
1617 if (retVal != IME_ERROR_NONE) return retVal;
1619 g_core.send_private_command(command);
1621 return IME_ERROR_NONE;
1625 EXPORT_API int ime_commit_content(const char *content, const char *description, const char *mime_type)
1627 ime_error_e retVal = IME_ERROR_NONE;
1629 if (!content || !description || !mime_type) {
1630 LOGW("IME_ERROR_INVALID_PARAMETER");
1631 return IME_ERROR_INVALID_PARAMETER;
1634 retVal = _check_privilege();
1635 if (retVal != IME_ERROR_NONE) return retVal;
1638 LOGW("IME_ERROR_NOT_RUNNING");
1639 return IME_ERROR_NOT_RUNNING;
1643 LOGI("content : '%s', description : '%s', mime_type : '%s'", content, description, mime_type);
1644 g_core.commit_content(content, description, mime_type);
1646 return IME_ERROR_NONE;
1650 EXPORT_API int ime_context_get_layout(ime_context_h context, Ecore_IMF_Input_Panel_Layout *layout)
1652 ime_error_e retVal = IME_ERROR_NONE;
1654 if (!context || !layout) {
1655 LOGW("IME_ERROR_INVALID_PARAMETER");
1656 return IME_ERROR_INVALID_PARAMETER;
1659 retVal = _check_privilege();
1660 if (retVal != IME_ERROR_NONE) return retVal;
1663 LOGW("IME_ERROR_NOT_RUNNING");
1664 return IME_ERROR_NOT_RUNNING;
1668 *layout = context->layout;
1670 return IME_ERROR_NONE;
1674 EXPORT_API int ime_context_get_layout_variation(ime_context_h context, ime_layout_variation_e *layout_variation)
1676 ime_error_e retVal = IME_ERROR_NONE;
1678 if (!context || !layout_variation) {
1679 LOGW("IME_ERROR_INVALID_PARAMETER");
1680 return IME_ERROR_INVALID_PARAMETER;
1683 retVal = _check_privilege();
1684 if (retVal != IME_ERROR_NONE) return retVal;
1687 LOGW("IME_ERROR_NOT_RUNNING");
1688 return IME_ERROR_NOT_RUNNING;
1692 *layout_variation = static_cast<ime_layout_variation_e>(context->layout_variation);
1694 return IME_ERROR_NONE;
1698 EXPORT_API int ime_context_get_cursor_position(ime_context_h context, int *cursor_pos)
1700 ime_error_e retVal = IME_ERROR_NONE;
1702 if (!context || !cursor_pos) {
1703 LOGW("IME_ERROR_INVALID_PARAMETER");
1704 return IME_ERROR_INVALID_PARAMETER;
1707 retVal = _check_privilege();
1708 if (retVal != IME_ERROR_NONE) return retVal;
1711 LOGW("IME_ERROR_NOT_RUNNING");
1712 return IME_ERROR_NOT_RUNNING;
1716 *cursor_pos = context->cursor_pos;
1718 return IME_ERROR_NONE;
1722 EXPORT_API int ime_context_get_autocapital_type(ime_context_h context, Ecore_IMF_Autocapital_Type *autocapital_type)
1724 ime_error_e retVal = IME_ERROR_NONE;
1726 if (!context || !autocapital_type) {
1727 LOGW("IME_ERROR_INVALID_PARAMETER");
1728 return IME_ERROR_INVALID_PARAMETER;
1731 retVal = _check_privilege();
1732 if (retVal != IME_ERROR_NONE) return retVal;
1735 LOGW("IME_ERROR_NOT_RUNNING");
1736 return IME_ERROR_NOT_RUNNING;
1740 *autocapital_type = context->autocapital_type;
1742 return IME_ERROR_NONE;
1746 EXPORT_API int ime_context_get_return_key_type(ime_context_h context, Ecore_IMF_Input_Panel_Return_Key_Type *return_key_type)
1748 ime_error_e retVal = IME_ERROR_NONE;
1750 if (!context || !return_key_type) {
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;
1764 *return_key_type = context->return_key_type;
1766 return IME_ERROR_NONE;
1770 EXPORT_API int ime_context_get_return_key_state(ime_context_h context, bool *return_key_state)
1772 ime_error_e retVal = IME_ERROR_NONE;
1774 if (!context || !return_key_state) {
1775 LOGW("IME_ERROR_INVALID_PARAMETER");
1776 return IME_ERROR_INVALID_PARAMETER;
1779 retVal = _check_privilege();
1780 if (retVal != IME_ERROR_NONE) return retVal;
1783 LOGW("IME_ERROR_NOT_RUNNING");
1784 return IME_ERROR_NOT_RUNNING;
1788 *return_key_state = static_cast<bool>(context->return_key_disabled);
1790 return IME_ERROR_NONE;
1794 EXPORT_API int ime_context_get_prediction_mode(ime_context_h context, bool *prediction_mode)
1796 ime_error_e retVal = IME_ERROR_NONE;
1798 if (!context || !prediction_mode) {
1799 LOGW("IME_ERROR_INVALID_PARAMETER");
1800 return IME_ERROR_INVALID_PARAMETER;
1803 retVal = _check_privilege();
1804 if (retVal != IME_ERROR_NONE) return retVal;
1807 LOGW("IME_ERROR_NOT_RUNNING");
1808 return IME_ERROR_NOT_RUNNING;
1812 *prediction_mode = static_cast<bool>(context->prediction_allow);
1814 return IME_ERROR_NONE;
1818 EXPORT_API int ime_context_get_password_mode(ime_context_h context, bool *password_mode)
1820 ime_error_e retVal = IME_ERROR_NONE;
1822 if (!context || !password_mode) {
1823 LOGW("IME_ERROR_INVALID_PARAMETER");
1824 return IME_ERROR_INVALID_PARAMETER;
1827 retVal = _check_privilege();
1828 if (retVal != IME_ERROR_NONE) return retVal;
1831 LOGW("IME_ERROR_NOT_RUNNING");
1832 return IME_ERROR_NOT_RUNNING;
1836 *password_mode = static_cast<bool>(context->password_mode);
1838 return IME_ERROR_NONE;
1842 EXPORT_API int ime_context_get_input_hint(ime_context_h context, Ecore_IMF_Input_Hints *input_hint)
1844 ime_error_e retVal = IME_ERROR_NONE;
1846 if (!context || !input_hint) {
1847 LOGW("IME_ERROR_INVALID_PARAMETER");
1848 return IME_ERROR_INVALID_PARAMETER;
1851 retVal = _check_privilege();
1852 if (retVal != IME_ERROR_NONE) return retVal;
1855 LOGW("IME_ERROR_NOT_RUNNING");
1856 return IME_ERROR_NOT_RUNNING;
1860 *input_hint = context->input_hint;
1862 return IME_ERROR_NONE;
1866 EXPORT_API int ime_context_get_bidi_direction(ime_context_h context, Ecore_IMF_BiDi_Direction *bidi)
1868 ime_error_e retVal = IME_ERROR_NONE;
1870 if (!context || !bidi) {
1871 LOGW("IME_ERROR_INVALID_PARAMETER");
1872 return IME_ERROR_INVALID_PARAMETER;
1875 retVal = _check_privilege();
1876 if (retVal != IME_ERROR_NONE) return retVal;
1879 LOGW("IME_ERROR_NOT_RUNNING");
1880 return IME_ERROR_NOT_RUNNING;
1884 *bidi = context->bidi_direction;
1886 return IME_ERROR_NONE;
1890 EXPORT_API int ime_context_get_language(ime_context_h context, Ecore_IMF_Input_Panel_Lang *language)
1892 ime_error_e retVal = IME_ERROR_NONE;
1894 if (!context || !language) {
1895 LOGW("IME_ERROR_INVALID_PARAMETER");
1896 return IME_ERROR_INVALID_PARAMETER;
1899 retVal = _check_privilege();
1900 if (retVal != IME_ERROR_NONE) return retVal;
1903 LOGW("IME_ERROR_NOT_RUNNING");
1904 return IME_ERROR_NOT_RUNNING;
1908 *language = context->language;
1910 return IME_ERROR_NONE;
1915 EXPORT_API int ime_context_get_caps_mode(ime_context_h context, bool *caps_mode)
1917 ime_error_e retVal = IME_ERROR_NONE;
1919 if (!context || !caps_mode) {
1920 LOGW("IME_ERROR_INVALID_PARAMETER");
1921 return IME_ERROR_INVALID_PARAMETER;
1924 retVal = _check_privilege();
1925 if (retVal != IME_ERROR_NONE) return retVal;
1928 LOGW("IME_ERROR_NOT_RUNNING");
1929 return IME_ERROR_NOT_RUNNING;
1932 *caps_mode = static_cast<bool>(context->caps_mode);
1934 return IME_ERROR_NONE;
1938 EXPORT_API int ime_device_info_get_name(ime_device_info_h dev_info, char **dev_name)
1940 ime_error_e retVal = IME_ERROR_NONE;
1942 if (!dev_info || !dev_name) {
1943 LOGW("IME_ERROR_INVALID_PARAMETER");
1944 return IME_ERROR_INVALID_PARAMETER;
1947 retVal = _check_privilege();
1948 if (retVal != IME_ERROR_NONE) return retVal;
1951 LOGW("IME_ERROR_NOT_RUNNING");
1952 return IME_ERROR_NOT_RUNNING;
1956 if (!dev_info->dev_name)
1957 *dev_name = strdup("");
1959 *dev_name = strdup(dev_info->dev_name);
1961 return IME_ERROR_NONE;
1965 EXPORT_API int ime_device_info_get_class(ime_device_info_h dev_info, Ecore_IMF_Device_Class *dev_class)
1967 ime_error_e retVal = IME_ERROR_NONE;
1969 if (!dev_info || !dev_class) {
1970 LOGW("IME_ERROR_INVALID_PARAMETER");
1971 return IME_ERROR_INVALID_PARAMETER;
1974 retVal = _check_privilege();
1975 if (retVal != IME_ERROR_NONE) return retVal;
1978 LOGW("IME_ERROR_NOT_RUNNING");
1979 return IME_ERROR_NOT_RUNNING;
1983 *dev_class = dev_info->dev_class;
1985 return IME_ERROR_NONE;
1989 EXPORT_API int ime_device_info_get_subclass(ime_device_info_h dev_info, Ecore_IMF_Device_Subclass *dev_subclass)
1991 ime_error_e retVal = IME_ERROR_NONE;
1993 if (!dev_info || !dev_subclass) {
1994 LOGW("IME_ERROR_INVALID_PARAMETER");
1995 return IME_ERROR_INVALID_PARAMETER;
1998 retVal = _check_privilege();
1999 if (retVal != IME_ERROR_NONE) return retVal;
2002 LOGW("IME_ERROR_NOT_RUNNING");
2003 return IME_ERROR_NOT_RUNNING;
2007 *dev_subclass = dev_info->dev_subclass;
2009 return IME_ERROR_NONE;
2014 EXPORT_API int ime_event_set_process_input_device_event_cb(ime_process_input_device_event_cb callback_func, void *user_data)
2016 ime_error_e retVal = IME_ERROR_NONE;
2018 if (!callback_func) {
2019 LOGW("IME_ERROR_INVALID_PARAMETER");
2020 return IME_ERROR_INVALID_PARAMETER;
2023 retVal = _check_privilege();
2024 if (retVal != IME_ERROR_NONE) return retVal;
2026 g_event_callback.process_input_device_event = callback_func;
2027 g_event_callback.process_input_device_event_user_data = user_data;
2029 return IME_ERROR_NONE;
2032 EXPORT_API int ime_event_unset_process_input_device_event_cb(void)
2034 ime_error_e retVal = IME_ERROR_NONE;
2036 retVal = _check_privilege();
2037 if (retVal != IME_ERROR_NONE) return retVal;
2039 g_event_callback.process_input_device_event = NULL;
2040 g_event_callback.process_input_device_event_user_data = NULL;
2042 return IME_ERROR_NONE;
2045 /* Functions for Rotary input device event */
2046 EXPORT_API int ime_input_device_rotary_get_direction(ime_input_device_event_h event_handle, ime_input_device_rotary_direction_e *direction)
2048 ime_error_e retVal = IME_ERROR_NONE;
2050 if (!event_handle || !direction) {
2051 LOGW("IME_ERROR_INVALID_PARAMETER");
2052 return IME_ERROR_INVALID_PARAMETER;
2055 ime_device_event_s *device_event = static_cast<ime_device_event_s*>(event_handle);
2056 if (device_event->device_type != IME_INPUT_DEVICE_TYPE_ROTARY) {
2057 LOGW("IME_ERROR_INVALID_PARAMETER");
2058 return IME_ERROR_INVALID_PARAMETER;
2061 retVal = _check_privilege();
2062 if (retVal != IME_ERROR_NONE) return retVal;
2065 LOGW("IME_ERROR_OPERATION_FAILED");
2066 return IME_ERROR_OPERATION_FAILED;
2070 Ecore_Event_Detent_Rotate *rotary_device_event =
2071 static_cast<Ecore_Event_Detent_Rotate*>(device_event->event_data);
2072 if (rotary_device_event) {
2073 if (rotary_device_event->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) {
2074 *direction = IME_INPUT_DEVICE_ROTARY_DIRECTION_CLOCKWISE;
2075 } else if (rotary_device_event->direction == ECORE_DETENT_DIRECTION_COUNTER_CLOCKWISE) {
2076 *direction = IME_INPUT_DEVICE_ROTARY_DIRECTION_COUNTER_CLOCKWISE;
2080 return IME_ERROR_NONE;
2085 EXPORT_API int ime_event_set_prediction_hint_set_cb(ime_prediction_hint_set_cb callback_func, void *user_data)
2087 ime_error_e retVal = IME_ERROR_NONE;
2089 if (!callback_func) {
2090 LOGW("IME_ERROR_INVALID_PARAMETER");
2091 return IME_ERROR_INVALID_PARAMETER;
2094 retVal = _check_privilege();
2095 if (retVal != IME_ERROR_NONE) return retVal;
2097 g_event_callback.prediction_hint_set = callback_func;
2098 g_event_callback.prediction_hint_set_user_data = user_data;
2100 return IME_ERROR_NONE;
2103 EXPORT_API int ime_event_set_mime_type_set_request_cb(ime_mime_type_set_request_cb callback_func, void *user_data)
2105 ime_error_e retVal = IME_ERROR_NONE;
2107 if (!callback_func) {
2108 LOGW("IME_ERROR_INVALID_PARAMETER");
2109 return IME_ERROR_INVALID_PARAMETER;
2112 retVal = _check_privilege();
2113 if (retVal != IME_ERROR_NONE) return retVal;
2115 g_event_callback.mime_type_set = callback_func;
2116 g_event_callback.mime_type_set_user_data = user_data;
2118 return IME_ERROR_NONE;
2121 EXPORT_API int ime_set_floating_mode(bool floating_mode)
2123 ime_error_e retVal = IME_ERROR_NONE;
2125 retVal = _check_privilege();
2126 if (retVal != IME_ERROR_NONE) return retVal;
2129 LOGW("IME_ERROR_NOT_RUNNING");
2130 return IME_ERROR_NOT_RUNNING;
2134 g_core.set_floating_mode(floating_mode);
2136 return IME_ERROR_NONE;
2140 EXPORT_API int ime_set_floating_drag_start(void)
2142 ime_error_e retVal = IME_ERROR_NONE;
2144 retVal = _check_privilege();
2145 if (retVal != IME_ERROR_NONE) return retVal;
2148 LOGW("IME_ERROR_NOT_RUNNING");
2149 return IME_ERROR_NOT_RUNNING;
2153 g_core.set_floating_drag_enabled(true);
2155 return IME_ERROR_NONE;
2159 EXPORT_API int ime_set_floating_drag_end(void)
2161 ime_error_e retVal = IME_ERROR_NONE;
2163 retVal = _check_privilege();
2164 if (retVal != IME_ERROR_NONE) return retVal;
2167 LOGW("IME_ERROR_NOT_RUNNING");
2168 return IME_ERROR_NOT_RUNNING;
2172 g_core.set_floating_drag_enabled(false);
2174 return IME_ERROR_NONE;
2179 EXPORT_API int ime_set_window_creation_defer_flag(bool flag)
2181 ime_error_e retVal = IME_ERROR_NONE;
2183 retVal = _check_privilege();
2184 if (retVal != IME_ERROR_NONE) return retVal;
2186 g_core.set_window_creation_defer_flag(flag);
2188 return IME_ERROR_NONE;
2192 EXPORT_API int ime_event_set_prediction_hint_data_set_cb(ime_prediction_hint_data_set_cb callback_func, void *user_data)
2194 ime_error_e retVal = IME_ERROR_NONE;
2196 if (!callback_func) {
2197 LOGW("IME_ERROR_INVALID_PARAMETER");
2198 return IME_ERROR_INVALID_PARAMETER;
2201 retVal = _check_privilege();
2202 if (retVal != IME_ERROR_NONE) return retVal;
2204 g_event_callback.prediction_hint_data_set = callback_func;
2205 g_event_callback.prediction_hint_data_set_user_data = user_data;
2207 return IME_ERROR_NONE;
2211 EXPORT_API int ime_event_set_optimization_hint_set_cb(ime_optimization_hint_set_cb callback_func, void *user_data)
2214 ime_error_e retVal = IME_ERROR_NONE;
2216 if (!callback_func) {
2217 LOGW("IME_ERROR_INVALID_PARAMETER");
2218 return IME_ERROR_INVALID_PARAMETER;
2222 retVal = _check_privilege();
2223 if (retVal != IME_ERROR_NONE) return retVal;
2226 g_event_callback.optimization_hint_set = callback_func;
2227 g_event_callback.optimization_hint_set_user_data = user_data;
2229 return IME_ERROR_NONE;
2233 EXPORT_API int ime_update_input_panel_event(ime_event_type_e type, unsigned int value)
2235 ime_error_e retVal = IME_ERROR_NONE;
2237 if (type < IME_EVENT_TYPE_LANGUAGE || type > IME_EVENT_TYPE_GEOMETRY) {
2238 LOGW("IME_ERROR_INVALID_PARAMETER");
2239 return IME_ERROR_INVALID_PARAMETER;
2243 LOGW("IME_ERROR_NOT_RUNNING");
2244 return IME_ERROR_NOT_RUNNING;
2248 retVal = _check_privilege();
2249 if (retVal != IME_ERROR_NONE) return retVal;
2251 g_core.update_input_context((sclu32)type, value);
2253 return IME_ERROR_NONE;
2257 EXPORT_API int ime_set_candidate_visibility_state(bool visible)
2259 ime_error_e retVal = IME_ERROR_NONE;
2262 LOGW("IME_ERROR_NOT_RUNNING");
2263 return IME_ERROR_NOT_RUNNING;
2267 retVal = _check_privilege();
2268 if (retVal != IME_ERROR_NONE) return retVal;
2271 g_core.show_candidate_string();
2273 g_core.hide_candidate_string();
2275 return IME_ERROR_NONE;