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) {
527 g_permission_allowed = false;
528 g_checked_privilege = true;
529 LOGE("inputmethod_cynara_initialize () == false");
530 return IME_ERROR_PERMISSION_DENIED;
533 snprintf(uid, 16, "%d", getuid());
534 if (check_privilege(uid, IME_PRIVILEGE) == false) {
535 LOGE("check_privilege(uid, IME_PRIVILEGE) == false. uid : %s", uid);
536 ret = IME_ERROR_PERMISSION_DENIED;
539 g_permission_allowed = (ret == IME_ERROR_NONE);
540 g_checked_privilege = true;
542 inputmethod_cynara_finish();
548 bool g_from_dotnet = false;
549 EXPORT_API int ime_set_dotnet_flag(bool set)
551 ime_error_e retVal = IME_ERROR_NONE;
553 retVal = _check_privilege();
554 if (retVal != IME_ERROR_NONE) return retVal;
562 EXPORT_API int ime_run(ime_callback_s *basic_cb, void *user_data)
564 ime_error_e retVal = IME_ERROR_NONE;
567 LOGE("inputmethod main loop is already running.");
568 return IME_ERROR_OPERATION_FAILED;
572 LOGE("basic callbacks pointer is null.");
573 return IME_ERROR_INVALID_PARAMETER;
576 retVal = _check_privilege();
577 if (retVal != IME_ERROR_NONE) return retVal;
579 g_basic_callback = *basic_cb;
581 if (!g_basic_callback.create || !g_basic_callback.terminate ||
582 !g_basic_callback.show || !g_basic_callback.hide) {
583 LOGE("mandatory callback functions are not set");
584 memset(&g_basic_callback, 0, sizeof(ime_callback_s));
585 memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
586 return IME_ERROR_NO_CALLBACK_FUNCTION;
589 g_user_data = user_data;
593 LOGD("ime_run is called from dotnet");
594 return IME_ERROR_NONE;
600 LOGW("exception is thrown from g_core.run()\n");
603 memset(&g_basic_callback, 0, sizeof(ime_callback_s));
604 memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
608 return IME_ERROR_NONE;
611 EXPORT_API int ime_event_set_focus_in_cb(ime_focus_in_cb callback_func, void *user_data)
613 ime_error_e retVal = IME_ERROR_NONE;
615 if (!callback_func) {
616 LOGW("IME_ERROR_INVALID_PARAMETER");
617 return IME_ERROR_INVALID_PARAMETER;
620 retVal = _check_privilege();
621 if (retVal != IME_ERROR_NONE) return retVal;
623 g_event_callback.focus_in = callback_func;
624 g_event_callback.focus_in_user_data = user_data;
626 return IME_ERROR_NONE;
629 EXPORT_API int ime_event_set_focus_out_cb(ime_focus_out_cb callback_func, void *user_data)
631 ime_error_e retVal = IME_ERROR_NONE;
633 if (!callback_func) {
634 LOGW("IME_ERROR_INVALID_PARAMETER");
635 return IME_ERROR_INVALID_PARAMETER;
638 retVal = _check_privilege();
639 if (retVal != IME_ERROR_NONE) return retVal;
641 g_event_callback.focus_out = callback_func;
642 g_event_callback.focus_out_user_data = user_data;
644 return IME_ERROR_NONE;
647 EXPORT_API int ime_event_set_surrounding_text_updated_cb(ime_surrounding_text_updated_cb callback_func, void *user_data)
649 ime_error_e retVal = IME_ERROR_NONE;
651 if (!callback_func) {
652 LOGW("IME_ERROR_INVALID_PARAMETER");
653 return IME_ERROR_INVALID_PARAMETER;
656 retVal = _check_privilege();
657 if (retVal != IME_ERROR_NONE) return retVal;
659 g_event_callback.surrounding_text_updated = callback_func;
660 g_event_callback.surrounding_text_updated_user_data = user_data;
662 return IME_ERROR_NONE;
665 EXPORT_API int ime_event_set_input_context_reset_cb(ime_input_context_reset_cb callback_func, void *user_data)
667 ime_error_e retVal = IME_ERROR_NONE;
669 if (!callback_func) {
670 LOGW("IME_ERROR_INVALID_PARAMETER");
671 return IME_ERROR_INVALID_PARAMETER;
674 retVal = _check_privilege();
675 if (retVal != IME_ERROR_NONE) return retVal;
677 g_event_callback.input_context_reset = callback_func;
678 g_event_callback.input_context_reset_user_data = user_data;
680 return IME_ERROR_NONE;
683 EXPORT_API int ime_event_set_cursor_position_updated_cb(ime_cursor_position_updated_cb callback_func, void *user_data)
685 ime_error_e retVal = IME_ERROR_NONE;
687 if (!callback_func) {
688 LOGW("IME_ERROR_INVALID_PARAMETER");
689 return IME_ERROR_INVALID_PARAMETER;
692 retVal = _check_privilege();
693 if (retVal != IME_ERROR_NONE) return retVal;
695 g_event_callback.cursor_position_updated = callback_func;
696 g_event_callback.cursor_position_updated_user_data = user_data;
698 return IME_ERROR_NONE;
701 EXPORT_API int ime_event_set_language_requested_cb(ime_language_requested_cb callback_func, void *user_data)
703 ime_error_e retVal = IME_ERROR_NONE;
705 if (!callback_func) {
706 LOGW("IME_ERROR_INVALID_PARAMETER");
707 return IME_ERROR_INVALID_PARAMETER;
710 retVal = _check_privilege();
711 if (retVal != IME_ERROR_NONE) return retVal;
713 g_event_callback.language_requested = callback_func;
714 g_event_callback.language_requested_user_data = user_data;
716 return IME_ERROR_NONE;
719 EXPORT_API int ime_event_set_language_set_cb(ime_language_set_cb callback_func, void *user_data)
721 ime_error_e retVal = IME_ERROR_NONE;
723 if (!callback_func) {
724 LOGW("IME_ERROR_INVALID_PARAMETER");
725 return IME_ERROR_INVALID_PARAMETER;
728 retVal = _check_privilege();
729 if (retVal != IME_ERROR_NONE) return retVal;
731 g_event_callback.language_set = callback_func;
732 g_event_callback.language_set_user_data = user_data;
734 return IME_ERROR_NONE;
737 EXPORT_API int ime_event_set_imdata_set_cb(ime_imdata_set_cb callback_func, void *user_data)
739 ime_error_e retVal = IME_ERROR_NONE;
741 if (!callback_func) {
742 LOGW("IME_ERROR_INVALID_PARAMETER");
743 return IME_ERROR_INVALID_PARAMETER;
746 retVal = _check_privilege();
747 if (retVal != IME_ERROR_NONE) return retVal;
749 g_event_callback.imdata_set = callback_func;
750 g_event_callback.imdata_set_user_data = user_data;
752 return IME_ERROR_NONE;
755 EXPORT_API int ime_event_set_imdata_requested_cb(ime_imdata_requested_cb callback_func, void *user_data)
757 ime_error_e retVal = IME_ERROR_NONE;
759 if (!callback_func) {
760 LOGW("IME_ERROR_INVALID_PARAMETER");
761 return IME_ERROR_INVALID_PARAMETER;
764 retVal = _check_privilege();
765 if (retVal != IME_ERROR_NONE) return retVal;
767 g_event_callback.imdata_requested = callback_func;
768 g_event_callback.imdata_requested_user_data = user_data;
770 return IME_ERROR_NONE;
773 EXPORT_API int ime_event_set_layout_set_cb(ime_layout_set_cb callback_func, void *user_data)
775 ime_error_e retVal = IME_ERROR_NONE;
777 if (!callback_func) {
778 LOGW("IME_ERROR_INVALID_PARAMETER");
779 return IME_ERROR_INVALID_PARAMETER;
782 retVal = _check_privilege();
783 if (retVal != IME_ERROR_NONE) return retVal;
785 g_event_callback.layout_set = callback_func;
786 g_event_callback.layout_set_user_data = user_data;
788 return IME_ERROR_NONE;
791 EXPORT_API int ime_event_set_return_key_type_set_cb(ime_return_key_type_set_cb callback_func, void *user_data)
793 ime_error_e retVal = IME_ERROR_NONE;
795 if (!callback_func) {
796 LOGW("IME_ERROR_INVALID_PARAMETER");
797 return IME_ERROR_INVALID_PARAMETER;
800 retVal = _check_privilege();
801 if (retVal != IME_ERROR_NONE) return retVal;
803 g_event_callback.return_key_type_set = callback_func;
804 g_event_callback.return_key_type_set_user_data = user_data;
806 return IME_ERROR_NONE;
809 EXPORT_API int ime_event_set_return_key_state_set_cb(ime_return_key_state_set_cb callback_func, void *user_data)
811 ime_error_e retVal = IME_ERROR_NONE;
813 if (!callback_func) {
814 LOGW("IME_ERROR_INVALID_PARAMETER");
815 return IME_ERROR_INVALID_PARAMETER;
818 retVal = _check_privilege();
819 if (retVal != IME_ERROR_NONE) return retVal;
821 g_event_callback.return_key_state_set = callback_func;
822 g_event_callback.return_key_state_set_user_data = user_data;
824 return IME_ERROR_NONE;
827 EXPORT_API int ime_event_set_geometry_requested_cb(ime_geometry_requested_cb callback_func, void *user_data)
829 ime_error_e retVal = IME_ERROR_NONE;
831 if (!callback_func) {
832 LOGW("IME_ERROR_INVALID_PARAMETER");
833 return IME_ERROR_INVALID_PARAMETER;
836 retVal = _check_privilege();
837 if (retVal != IME_ERROR_NONE) return retVal;
839 g_event_callback.geometry_requested = callback_func;
840 g_event_callback.geometry_requested_user_data = user_data;
842 return IME_ERROR_NONE;
845 EXPORT_API int ime_event_set_process_key_event_cb(ime_process_key_event_cb callback_func, void *user_data)
847 ime_error_e retVal = IME_ERROR_NONE;
849 if (!callback_func) {
850 LOGW("IME_ERROR_INVALID_PARAMETER");
851 return IME_ERROR_INVALID_PARAMETER;
854 retVal = _check_privilege();
855 if (retVal != IME_ERROR_NONE) return retVal;
857 g_event_callback.process_key_event = callback_func;
858 g_event_callback.process_key_event_user_data = user_data;
860 return IME_ERROR_NONE;
863 EXPORT_API int ime_event_set_process_key_event_with_keycode_cb(ime_process_key_event_with_keycode_cb callback_func, void *user_data)
865 ime_error_e retVal = IME_ERROR_NONE;
867 if (!callback_func) {
868 LOGW("IME_ERROR_INVALID_PARAMETER");
869 return IME_ERROR_INVALID_PARAMETER;
872 retVal = _check_privilege();
873 if (retVal != IME_ERROR_NONE) return retVal;
875 g_event_callback.process_key_event_with_keycode = callback_func;
876 g_event_callback.process_key_event_with_keycode_user_data = user_data;
878 return IME_ERROR_NONE;
881 EXPORT_API int ime_event_set_display_language_changed_cb(ime_display_language_changed_cb callback_func, void *user_data)
883 ime_error_e retVal = IME_ERROR_NONE;
885 if (!callback_func) {
886 LOGW("IME_ERROR_INVALID_PARAMETER");
887 return IME_ERROR_INVALID_PARAMETER;
890 retVal = _check_privilege();
891 if (retVal != IME_ERROR_NONE) return retVal;
893 g_event_callback.display_language_changed = callback_func;
894 g_event_callback.display_language_changed_user_data = user_data;
896 return IME_ERROR_NONE;
899 EXPORT_API int ime_event_set_rotation_degree_changed_cb(ime_rotation_degree_changed_cb callback_func, void *user_data)
901 ime_error_e retVal = IME_ERROR_NONE;
903 if (!callback_func) {
904 LOGW("IME_ERROR_INVALID_PARAMETER");
905 return IME_ERROR_INVALID_PARAMETER;
908 retVal = _check_privilege();
909 if (retVal != IME_ERROR_NONE) return retVal;
911 g_event_callback.rotation_degree_changed = callback_func;
912 g_event_callback.rotation_degree_changed_user_data = user_data;
914 return IME_ERROR_NONE;
917 EXPORT_API int ime_event_set_accessibility_state_changed_cb(ime_accessibility_state_changed_cb callback_func, void *user_data)
919 ime_error_e retVal = IME_ERROR_NONE;
921 if (!callback_func) {
922 LOGW("IME_ERROR_INVALID_PARAMETER");
923 return IME_ERROR_INVALID_PARAMETER;
926 retVal = _check_privilege();
927 if (retVal != IME_ERROR_NONE) return retVal;
929 g_event_callback.accessibility_state_changed = callback_func;
930 g_event_callback.accessibility_state_changed_user_data = user_data;
932 return IME_ERROR_NONE;
935 EXPORT_API int ime_event_set_option_window_created_cb(ime_option_window_created_cb callback_func, void *user_data)
937 ime_error_e retVal = IME_ERROR_NONE;
939 if (!callback_func) {
940 LOGW("IME_ERROR_INVALID_PARAMETER");
941 return IME_ERROR_INVALID_PARAMETER;
944 retVal = _check_privilege();
945 if (retVal != IME_ERROR_NONE) return retVal;
947 g_event_callback.option_window_created = callback_func;
948 g_event_callback.option_window_created_user_data = user_data;
950 return IME_ERROR_NONE;
953 EXPORT_API int ime_event_set_option_window_destroyed_cb(ime_option_window_destroyed_cb callback_func, void *user_data)
955 ime_error_e retVal = IME_ERROR_NONE;
957 if (!callback_func) {
958 LOGW("IME_ERROR_INVALID_PARAMETER");
959 return IME_ERROR_INVALID_PARAMETER;
962 retVal = _check_privilege();
963 if (retVal != IME_ERROR_NONE) return retVal;
965 g_event_callback.option_window_destroyed = callback_func;
966 g_event_callback.option_window_destroyed_user_data = user_data;
968 return IME_ERROR_NONE;
972 EXPORT_API int ime_event_set_caps_mode_changed_cb(ime_caps_mode_changed_cb callback_func, void *user_data)
974 ime_error_e retVal = IME_ERROR_NONE;
976 if (!callback_func) {
977 LOGW("IME_ERROR_INVALID_PARAMETER");
978 return IME_ERROR_INVALID_PARAMETER;
981 retVal = _check_privilege();
982 if (retVal != IME_ERROR_NONE) return retVal;
984 g_event_callback.caps_mode_changed = callback_func;
985 g_event_callback.caps_mode_changed_user_data = user_data;
987 return IME_ERROR_NONE;
990 EXPORT_API int ime_event_set_candidate_show_cb(ime_candidate_show_cb callback_func, void *user_data)
992 ime_error_e retVal = IME_ERROR_NONE;
994 if (!callback_func) {
995 LOGW("IME_ERROR_INVALID_PARAMETER");
996 return IME_ERROR_INVALID_PARAMETER;
999 retVal = _check_privilege();
1000 if (retVal != IME_ERROR_NONE) return retVal;
1002 g_event_callback.candidate_show = callback_func;
1003 g_event_callback.candidate_show_user_data = user_data;
1005 return IME_ERROR_NONE;
1008 EXPORT_API int ime_event_set_candidate_hide_cb(ime_candidate_hide_cb callback_func, void *user_data)
1010 ime_error_e retVal = IME_ERROR_NONE;
1012 if (!callback_func) {
1013 LOGW("IME_ERROR_INVALID_PARAMETER");
1014 return IME_ERROR_INVALID_PARAMETER;
1017 retVal = _check_privilege();
1018 if (retVal != IME_ERROR_NONE) return retVal;
1020 g_event_callback.candidate_hide = callback_func;
1021 g_event_callback.candidate_hide_user_data = user_data;
1023 return IME_ERROR_NONE;
1026 EXPORT_API int ime_event_set_lookup_table_changed_cb(ime_lookup_table_changed_cb callback_func, void *user_data)
1028 ime_error_e retVal = IME_ERROR_NONE;
1030 if (!callback_func) {
1031 LOGW("IME_ERROR_INVALID_PARAMETER");
1032 return IME_ERROR_INVALID_PARAMETER;
1035 retVal = _check_privilege();
1036 if (retVal != IME_ERROR_NONE) return retVal;
1038 g_event_callback.lookup_table_changed = callback_func;
1039 g_event_callback.lookup_table_changed_user_data = user_data;
1041 return IME_ERROR_NONE;
1045 EXPORT_API int ime_send_key_event(ime_key_code_e keycode, ime_key_mask_e keymask, bool forward_key)
1047 ime_error_e retVal = IME_ERROR_NONE;
1050 LOGW("IME_ERROR_NOT_RUNNING");
1051 return IME_ERROR_NOT_RUNNING;
1054 retVal = _check_privilege();
1055 if (retVal != IME_ERROR_NONE) return retVal;
1058 g_core.forward_key_event(-1, NULL, (sclu32)keycode, (sclu16)keymask);
1060 g_core.send_key_event(-1, NULL, (sclu32)keycode, (sclu16)keymask);
1062 return IME_ERROR_NONE;
1065 EXPORT_API int ime_commit_string(const char *str)
1067 ime_error_e retVal = IME_ERROR_NONE;
1070 LOGW("IME_ERROR_INVALID_PARAMETER");
1071 return IME_ERROR_INVALID_PARAMETER;
1075 LOGW("IME_ERROR_NOT_RUNNING");
1076 return IME_ERROR_NOT_RUNNING;
1079 retVal = _check_privilege();
1080 if (retVal != IME_ERROR_NONE) return retVal;
1082 SECURE_LOGI("commit string : %s", str);
1083 g_core.commit_string(-1, NULL, str);
1085 return IME_ERROR_NONE;
1088 EXPORT_API int ime_show_preedit_string(void)
1090 ime_error_e retVal = IME_ERROR_NONE;
1093 LOGW("IME_ERROR_NOT_RUNNING");
1094 return IME_ERROR_NOT_RUNNING;
1097 retVal = _check_privilege();
1098 if (retVal != IME_ERROR_NONE) return retVal;
1100 g_core.show_preedit_string(-1, NULL);
1102 return IME_ERROR_NONE;
1105 EXPORT_API int ime_hide_preedit_string(void)
1107 ime_error_e retVal = IME_ERROR_NONE;
1110 LOGW("IME_ERROR_NOT_RUNNING");
1111 return IME_ERROR_NOT_RUNNING;
1114 retVal = _check_privilege();
1115 if (retVal != IME_ERROR_NONE) return retVal;
1117 g_core.hide_preedit_string(-1, NULL);
1119 return IME_ERROR_NONE;
1122 EXPORT_API int ime_update_preedit_string(const char *str, Eina_List *attrs)
1124 ime_error_e retVal = IME_ERROR_NONE;
1127 LOGW("IME_ERROR_INVALID_PARAMETER");
1128 return IME_ERROR_INVALID_PARAMETER;
1132 LOGW("IME_ERROR_NOT_RUNNING");
1133 return IME_ERROR_NOT_RUNNING;
1136 retVal = _check_privilege();
1137 if (retVal != IME_ERROR_NONE) return retVal;
1139 scim::AttributeList attrv;
1141 ime_preedit_attribute *attr = NULL;
1144 EINA_LIST_FREE(attrs, data) {
1145 attr = (ime_preedit_attribute *)data;
1147 attrv.push_back(scim::Attribute(attr->start, attr->length, (scim::AttributeType)attr->type, attr->value));
1153 SECURE_LOGI("preedit string : '%s'", str);
1154 g_core.update_preedit_string(-1, NULL, str, attrv);
1156 return IME_ERROR_NONE;
1159 EXPORT_API int ime_request_surrounding_text(int maxlen_before, int maxlen_after)
1161 ime_error_e retVal = IME_ERROR_NONE;
1163 if (!g_event_callback.surrounding_text_updated) {
1164 LOGW("IME_ERROR_NO_CALLBACK_FUNCTION");
1165 return IME_ERROR_NO_CALLBACK_FUNCTION;
1169 LOGW("IME_ERROR_NOT_RUNNING");
1170 return IME_ERROR_NOT_RUNNING;
1173 retVal = _check_privilege();
1174 if (retVal != IME_ERROR_NONE) return retVal;
1176 g_core.get_surrounding_text(NULL, maxlen_before, maxlen_after);
1178 return IME_ERROR_NONE;
1181 EXPORT_API int ime_delete_surrounding_text(int offset, int len)
1183 ime_error_e retVal = IME_ERROR_NONE;
1186 LOGW("IME_ERROR_INVALID_PARAMETER");
1187 return IME_ERROR_INVALID_PARAMETER;
1191 LOGW("IME_ERROR_NOT_RUNNING");
1192 return IME_ERROR_NOT_RUNNING;
1195 retVal = _check_privilege();
1196 if (retVal != IME_ERROR_NONE) return retVal;
1198 LOGI("offset: %d, len : %d", offset, len);
1199 g_core.delete_surrounding_text(offset, len);
1201 return IME_ERROR_NONE;
1204 EXPORT_API int ime_get_surrounding_text(int maxlen_before, int maxlen_after, char **text, int *cursor_pos)
1206 ime_error_e retVal = IME_ERROR_NONE;
1208 if (!text || !cursor_pos) {
1209 LOGW("IME_ERROR_INVALID_PARAMETER");
1210 return IME_ERROR_INVALID_PARAMETER;
1214 LOGW("IME_ERROR_NOT_RUNNING");
1215 return IME_ERROR_NOT_RUNNING;
1218 retVal = _check_privilege();
1219 if (retVal != IME_ERROR_NONE) return retVal;
1223 int ret = g_core.get_surrounding_text(maxlen_before, maxlen_after, text, cursor);
1225 LOGW("IME_ERROR_OUR_OF_MEMORY");
1226 return IME_ERROR_OUT_OF_MEMORY;
1230 *cursor_pos = cursor;
1232 return IME_ERROR_NONE;
1235 EXPORT_API int ime_set_selection(int start, int end)
1237 ime_error_e retVal = IME_ERROR_NONE;
1240 LOGW("IME_ERROR_INVALID_PARAMETER");
1241 return IME_ERROR_INVALID_PARAMETER;
1245 LOGW("IME_ERROR_NOT_RUNNING");
1246 return IME_ERROR_NOT_RUNNING;
1249 retVal = _check_privilege();
1250 if (retVal != IME_ERROR_NONE) return retVal;
1252 LOGI("start: %d, end : %d", start, end);
1253 g_core.set_selection(start, end);
1255 return IME_ERROR_NONE;
1258 EXPORT_API int ime_get_selected_text(char **text)
1260 ime_error_e retVal = IME_ERROR_NONE;
1263 LOGW("IME_ERROR_INVALID_PARAMETER");
1264 return IME_ERROR_INVALID_PARAMETER;
1268 LOGW("IME_ERROR_NOT_RUNNING");
1269 return IME_ERROR_NOT_RUNNING;
1272 retVal = _check_privilege();
1273 if (retVal != IME_ERROR_NONE) return retVal;
1275 g_core.get_selection_text(text);
1277 return IME_ERROR_NONE;
1280 EXPORT_API Evas_Object* ime_get_main_window(void)
1282 ime_error_e retVal = IME_ERROR_NONE;
1284 Evas_Object *win = NULL;
1286 retVal = _check_privilege();
1287 if (retVal != IME_ERROR_NONE) {
1288 LOGE("_check_privilege returned %d.", retVal);
1289 set_last_result(retVal);
1294 set_last_result(IME_ERROR_NOT_RUNNING);
1295 LOGW("IME_ERROR_NOT_RUNNING");
1299 win = static_cast<Evas_Object*>(g_core.get_main_window());
1301 set_last_result(IME_ERROR_NONE);
1303 set_last_result(IME_ERROR_OPERATION_FAILED);
1304 LOGW("IME_ERROR_OPERATION_FAILED");
1310 EXPORT_API int ime_set_size(int portrait_width, int portrait_height, int landscape_width, int landscape_height)
1312 ime_error_e retVal = IME_ERROR_NONE;
1314 SclSize portrait_size, landscape_size;
1316 if (portrait_width < 1 || portrait_height < 1 || landscape_width < 1 || landscape_height < 1) {
1317 LOGW("IME_ERROR_INVALID_PARAMETER");
1318 return IME_ERROR_INVALID_PARAMETER;
1322 LOGW("IME_ERROR_NOT_RUNNING");
1323 return IME_ERROR_NOT_RUNNING;
1326 retVal = _check_privilege();
1327 if (retVal != IME_ERROR_NONE) return retVal;
1329 portrait_size.width = portrait_width;
1330 portrait_size.height = portrait_height;
1332 landscape_size.width = landscape_width;
1333 landscape_size.height = landscape_height;
1335 g_core.set_keyboard_size_hints(portrait_size, landscape_size);
1337 return IME_ERROR_NONE;
1340 EXPORT_API int ime_create_option_window(void)
1342 ime_error_e retVal = IME_ERROR_NONE;
1344 if (!g_event_callback.option_window_created || !g_event_callback.option_window_destroyed) {
1345 LOGW("ime_create_option_window_cb() and ime_destroy_option_window_cb() callback functions are not set.");
1346 return IME_ERROR_NO_CALLBACK_FUNCTION;
1350 LOGW("IME_ERROR_NOT_RUNNING");
1351 return IME_ERROR_NOT_RUNNING;
1354 retVal = _check_privilege();
1355 if (retVal != IME_ERROR_NONE) return retVal;
1357 if (g_core.create_option_window()) {
1358 return IME_ERROR_NONE;
1360 LOGW("IME_ERROR_OPERATION_FAILED");
1361 return IME_ERROR_OPERATION_FAILED;
1365 EXPORT_API int ime_destroy_option_window(Evas_Object *window)
1367 ime_error_e retVal = IME_ERROR_NONE;
1369 if (!g_event_callback.option_window_created || !g_event_callback.option_window_destroyed) {
1370 LOGW("ime_create_option_window_cb() and ime_destroy_option_window_cb() callback functions are not set.");
1371 return IME_ERROR_NO_CALLBACK_FUNCTION;
1375 LOGW("Window pointer is null.");
1376 return IME_ERROR_INVALID_PARAMETER;
1380 LOGW("IME_ERROR_NOT_RUNNING");
1381 return IME_ERROR_NOT_RUNNING;
1384 retVal = _check_privilege();
1385 if (retVal != IME_ERROR_NONE) return retVal;
1387 g_core.destroy_option_window(window);
1389 return IME_ERROR_NONE;
1393 EXPORT_API int ime_set_imengine(const char *engine_id)
1395 ime_error_e retVal = IME_ERROR_NONE;
1398 LOGW("IME_ERROR_INVALID_PARAMETER");
1399 return IME_ERROR_INVALID_PARAMETER;
1402 retVal = _check_privilege();
1403 if (retVal != IME_ERROR_NONE) return retVal;
1405 g_core.set_keyboard_ise_by_uuid(engine_id);
1407 return IME_ERROR_NONE;
1410 EXPORT_API int ime_flush_imengine(void)
1412 ime_error_e retVal = IME_ERROR_NONE;
1415 LOGW("IME_ERROR_NOT_RUNNING");
1416 return IME_ERROR_NOT_RUNNING;
1419 retVal = _check_privilege();
1420 if (retVal != IME_ERROR_NONE) return retVal;
1422 g_core.flush_keyboard_ise();
1424 return IME_ERROR_NONE;
1427 EXPORT_API int ime_send_imengine_event(int command, unsigned int value)
1429 ime_error_e retVal = IME_ERROR_NONE;
1432 LOGW("IME_ERROR_NOT_RUNNING");
1433 return IME_ERROR_NOT_RUNNING;
1436 retVal = _check_privilege();
1437 if (retVal != IME_ERROR_NONE) return retVal;
1439 g_core.send_imengine_event(-1, NULL, command, value);
1441 return IME_ERROR_NONE;
1444 EXPORT_API int ime_reset_imengine(void)
1446 ime_error_e retVal = IME_ERROR_NONE;
1449 LOGW("IME_ERROR_NOT_RUNNING");
1450 return IME_ERROR_NOT_RUNNING;
1453 retVal = _check_privilege();
1454 if (retVal != IME_ERROR_NONE) return retVal;
1456 g_core.reset_keyboard_ise();
1458 return IME_ERROR_NONE;
1461 EXPORT_API int ime_update_input_context(unsigned int type, unsigned int value)
1463 ime_error_e retVal = IME_ERROR_NONE;
1466 LOGW("IME_ERROR_NOT_RUNNING");
1467 return IME_ERROR_NOT_RUNNING;
1470 retVal = _check_privilege();
1471 if (retVal != IME_ERROR_NONE) return retVal;
1473 g_core.update_input_context(type, value);
1475 return IME_ERROR_NONE;
1479 EXPORT_API int ime_request_hide(void)
1481 ime_error_e retVal = IME_ERROR_NONE;
1484 LOGW("IME_ERROR_NOT_RUNNING");
1485 return IME_ERROR_NOT_RUNNING;
1488 retVal = _check_privilege();
1489 if (retVal != IME_ERROR_NONE) return retVal;
1491 g_core.request_ise_hide();
1493 return IME_ERROR_NONE;
1497 EXPORT_API int ime_initialize(void)
1499 ime_error_e retVal = IME_ERROR_NONE;
1501 retVal = _check_privilege();
1502 if (retVal != IME_ERROR_NONE) return retVal;
1510 EXPORT_API int ime_prepare(void)
1512 ime_error_e retVal = IME_ERROR_NONE;
1515 LOGE("inputmethod main loop is already running.");
1516 return IME_ERROR_OPERATION_FAILED;
1519 retVal = _check_privilege();
1520 if (retVal != IME_ERROR_NONE) return retVal;
1529 EXPORT_API int ime_finalize(void)
1531 ime_error_e retVal = IME_ERROR_NONE;
1533 retVal = _check_privilege();
1534 if (retVal != IME_ERROR_NONE) return retVal;
1538 memset(&g_basic_callback, 0, sizeof(ime_callback_s));
1539 memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
1545 EXPORT_API int ime_select_candidate(unsigned int index)
1547 ime_error_e retVal = IME_ERROR_NONE;
1550 LOGW("IME_ERROR_NOT_RUNNING");
1551 return IME_ERROR_NOT_RUNNING;
1554 retVal = _check_privilege();
1555 if (retVal != IME_ERROR_NONE) return retVal;
1557 g_core.select_candidate(index);
1559 return IME_ERROR_NONE;
1563 EXPORT_API int ime_send_private_command(const char *command)
1565 ime_error_e retVal = IME_ERROR_NONE;
1568 LOGW("IME_ERROR_INVALID_PARAMETER");
1569 return IME_ERROR_INVALID_PARAMETER;
1573 LOGW("IME_ERROR_NOT_RUNNING");
1574 return IME_ERROR_NOT_RUNNING;
1577 retVal = _check_privilege();
1578 if (retVal != IME_ERROR_NONE) return retVal;
1580 g_core.send_private_command(command);
1582 return IME_ERROR_NONE;
1585 EXPORT_API int ime_commit_content(const char *content, const char *description, const char *mime_type)
1587 ime_error_e retVal = IME_ERROR_NONE;
1589 if (!content || !description || !mime_type) {
1590 LOGW("IME_ERROR_INVALID_PARAMETER");
1591 return IME_ERROR_INVALID_PARAMETER;
1594 retVal = _check_privilege();
1595 if (retVal != IME_ERROR_NONE) return retVal;
1598 LOGW("IME_ERROR_NOT_RUNNING");
1599 return IME_ERROR_NOT_RUNNING;
1602 LOGI("content : '%s', description : '%s', mime_type : '%s'", content, description, mime_type);
1603 g_core.commit_content(content, description, mime_type);
1605 return IME_ERROR_NONE;
1608 EXPORT_API int ime_context_get_layout(ime_context_h context, Ecore_IMF_Input_Panel_Layout *layout)
1610 ime_error_e retVal = IME_ERROR_NONE;
1612 if (!context || !layout) {
1613 LOGW("IME_ERROR_INVALID_PARAMETER");
1614 return IME_ERROR_INVALID_PARAMETER;
1617 retVal = _check_privilege();
1618 if (retVal != IME_ERROR_NONE) return retVal;
1621 LOGW("IME_ERROR_NOT_RUNNING");
1622 return IME_ERROR_NOT_RUNNING;
1625 *layout = context->layout;
1627 return IME_ERROR_NONE;
1630 EXPORT_API int ime_context_get_layout_variation(ime_context_h context, ime_layout_variation_e *layout_variation)
1632 ime_error_e retVal = IME_ERROR_NONE;
1634 if (!context || !layout_variation) {
1635 LOGW("IME_ERROR_INVALID_PARAMETER");
1636 return IME_ERROR_INVALID_PARAMETER;
1639 retVal = _check_privilege();
1640 if (retVal != IME_ERROR_NONE) return retVal;
1643 LOGW("IME_ERROR_NOT_RUNNING");
1644 return IME_ERROR_NOT_RUNNING;
1647 *layout_variation = static_cast<ime_layout_variation_e>(context->layout_variation);
1649 return IME_ERROR_NONE;
1652 EXPORT_API int ime_context_get_cursor_position(ime_context_h context, int *cursor_pos)
1654 ime_error_e retVal = IME_ERROR_NONE;
1656 if (!context || !cursor_pos) {
1657 LOGW("IME_ERROR_INVALID_PARAMETER");
1658 return IME_ERROR_INVALID_PARAMETER;
1661 retVal = _check_privilege();
1662 if (retVal != IME_ERROR_NONE) return retVal;
1665 LOGW("IME_ERROR_NOT_RUNNING");
1666 return IME_ERROR_NOT_RUNNING;
1669 *cursor_pos = context->cursor_pos;
1671 return IME_ERROR_NONE;
1674 EXPORT_API int ime_context_get_autocapital_type(ime_context_h context, Ecore_IMF_Autocapital_Type *autocapital_type)
1676 ime_error_e retVal = IME_ERROR_NONE;
1678 if (!context || !autocapital_type) {
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;
1691 *autocapital_type = context->autocapital_type;
1693 return IME_ERROR_NONE;
1696 EXPORT_API int ime_context_get_return_key_type(ime_context_h context, Ecore_IMF_Input_Panel_Return_Key_Type *return_key_type)
1698 ime_error_e retVal = IME_ERROR_NONE;
1700 if (!context || !return_key_type) {
1701 LOGW("IME_ERROR_INVALID_PARAMETER");
1702 return IME_ERROR_INVALID_PARAMETER;
1705 retVal = _check_privilege();
1706 if (retVal != IME_ERROR_NONE) return retVal;
1709 LOGW("IME_ERROR_NOT_RUNNING");
1710 return IME_ERROR_NOT_RUNNING;
1713 *return_key_type = context->return_key_type;
1715 return IME_ERROR_NONE;
1718 EXPORT_API int ime_context_get_return_key_state(ime_context_h context, bool *return_key_state)
1720 ime_error_e retVal = IME_ERROR_NONE;
1722 if (!context || !return_key_state) {
1723 LOGW("IME_ERROR_INVALID_PARAMETER");
1724 return IME_ERROR_INVALID_PARAMETER;
1727 retVal = _check_privilege();
1728 if (retVal != IME_ERROR_NONE) return retVal;
1731 LOGW("IME_ERROR_NOT_RUNNING");
1732 return IME_ERROR_NOT_RUNNING;
1735 *return_key_state = static_cast<bool>(context->return_key_disabled);
1737 return IME_ERROR_NONE;
1740 EXPORT_API int ime_context_get_prediction_mode(ime_context_h context, bool *prediction_mode)
1742 ime_error_e retVal = IME_ERROR_NONE;
1744 if (!context || !prediction_mode) {
1745 LOGW("IME_ERROR_INVALID_PARAMETER");
1746 return IME_ERROR_INVALID_PARAMETER;
1749 retVal = _check_privilege();
1750 if (retVal != IME_ERROR_NONE) return retVal;
1753 LOGW("IME_ERROR_NOT_RUNNING");
1754 return IME_ERROR_NOT_RUNNING;
1757 *prediction_mode = static_cast<bool>(context->prediction_allow);
1759 return IME_ERROR_NONE;
1762 EXPORT_API int ime_context_get_password_mode(ime_context_h context, bool *password_mode)
1764 ime_error_e retVal = IME_ERROR_NONE;
1766 if (!context || !password_mode) {
1767 LOGW("IME_ERROR_INVALID_PARAMETER");
1768 return IME_ERROR_INVALID_PARAMETER;
1771 retVal = _check_privilege();
1772 if (retVal != IME_ERROR_NONE) return retVal;
1775 LOGW("IME_ERROR_NOT_RUNNING");
1776 return IME_ERROR_NOT_RUNNING;
1779 *password_mode = static_cast<bool>(context->password_mode);
1781 return IME_ERROR_NONE;
1784 EXPORT_API int ime_context_get_input_hint(ime_context_h context, Ecore_IMF_Input_Hints *input_hint)
1786 ime_error_e retVal = IME_ERROR_NONE;
1788 if (!context || !input_hint) {
1789 LOGW("IME_ERROR_INVALID_PARAMETER");
1790 return IME_ERROR_INVALID_PARAMETER;
1793 retVal = _check_privilege();
1794 if (retVal != IME_ERROR_NONE) return retVal;
1797 LOGW("IME_ERROR_NOT_RUNNING");
1798 return IME_ERROR_NOT_RUNNING;
1801 *input_hint = context->input_hint;
1803 return IME_ERROR_NONE;
1806 EXPORT_API int ime_context_get_bidi_direction(ime_context_h context, Ecore_IMF_BiDi_Direction *bidi)
1808 ime_error_e retVal = IME_ERROR_NONE;
1810 if (!context || !bidi) {
1811 LOGW("IME_ERROR_INVALID_PARAMETER");
1812 return IME_ERROR_INVALID_PARAMETER;
1815 retVal = _check_privilege();
1816 if (retVal != IME_ERROR_NONE) return retVal;
1819 LOGW("IME_ERROR_NOT_RUNNING");
1820 return IME_ERROR_NOT_RUNNING;
1823 *bidi = context->bidi_direction;
1825 return IME_ERROR_NONE;
1828 EXPORT_API int ime_context_get_language(ime_context_h context, Ecore_IMF_Input_Panel_Lang *language)
1830 ime_error_e retVal = IME_ERROR_NONE;
1832 if (!context || !language) {
1833 LOGW("IME_ERROR_INVALID_PARAMETER");
1834 return IME_ERROR_INVALID_PARAMETER;
1837 retVal = _check_privilege();
1838 if (retVal != IME_ERROR_NONE) return retVal;
1841 LOGW("IME_ERROR_NOT_RUNNING");
1842 return IME_ERROR_NOT_RUNNING;
1845 *language = context->language;
1847 return IME_ERROR_NONE;
1851 EXPORT_API int ime_context_get_caps_mode(ime_context_h context, bool *caps_mode)
1853 ime_error_e retVal = IME_ERROR_NONE;
1855 if (!context || !caps_mode) {
1856 LOGW("IME_ERROR_INVALID_PARAMETER");
1857 return IME_ERROR_INVALID_PARAMETER;
1860 retVal = _check_privilege();
1861 if (retVal != IME_ERROR_NONE) return retVal;
1864 LOGW("IME_ERROR_NOT_RUNNING");
1865 return IME_ERROR_NOT_RUNNING;
1868 *caps_mode = static_cast<bool>(context->caps_mode);
1870 return IME_ERROR_NONE;
1874 EXPORT_API int ime_device_info_get_name(ime_device_info_h dev_info, char **dev_name)
1876 ime_error_e retVal = IME_ERROR_NONE;
1878 if (!dev_info || !dev_name) {
1879 LOGW("IME_ERROR_INVALID_PARAMETER");
1880 return IME_ERROR_INVALID_PARAMETER;
1883 retVal = _check_privilege();
1884 if (retVal != IME_ERROR_NONE) return retVal;
1887 LOGW("IME_ERROR_NOT_RUNNING");
1888 return IME_ERROR_NOT_RUNNING;
1891 if (!dev_info->dev_name)
1892 *dev_name = strdup("");
1894 *dev_name = strdup(dev_info->dev_name);
1896 return IME_ERROR_NONE;
1899 EXPORT_API int ime_device_info_get_class(ime_device_info_h dev_info, Ecore_IMF_Device_Class *dev_class)
1901 ime_error_e retVal = IME_ERROR_NONE;
1903 if (!dev_info || !dev_class) {
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_NOT_RUNNING");
1913 return IME_ERROR_NOT_RUNNING;
1916 *dev_class = dev_info->dev_class;
1918 return IME_ERROR_NONE;
1921 EXPORT_API int ime_device_info_get_subclass(ime_device_info_h dev_info, Ecore_IMF_Device_Subclass *dev_subclass)
1923 ime_error_e retVal = IME_ERROR_NONE;
1925 if (!dev_info || !dev_subclass) {
1926 LOGW("IME_ERROR_INVALID_PARAMETER");
1927 return IME_ERROR_INVALID_PARAMETER;
1930 retVal = _check_privilege();
1931 if (retVal != IME_ERROR_NONE) return retVal;
1934 LOGW("IME_ERROR_NOT_RUNNING");
1935 return IME_ERROR_NOT_RUNNING;
1938 *dev_subclass = dev_info->dev_subclass;
1940 return IME_ERROR_NONE;
1944 EXPORT_API int ime_event_set_process_input_device_event_cb(ime_process_input_device_event_cb callback_func, void *user_data)
1946 ime_error_e retVal = IME_ERROR_NONE;
1948 if (!callback_func) {
1949 LOGW("IME_ERROR_INVALID_PARAMETER");
1950 return IME_ERROR_INVALID_PARAMETER;
1953 retVal = _check_privilege();
1954 if (retVal != IME_ERROR_NONE) return retVal;
1956 g_event_callback.process_input_device_event = callback_func;
1957 g_event_callback.process_input_device_event_user_data = user_data;
1959 return IME_ERROR_NONE;
1962 EXPORT_API int ime_event_unset_process_input_device_event_cb(void)
1964 ime_error_e retVal = IME_ERROR_NONE;
1966 retVal = _check_privilege();
1967 if (retVal != IME_ERROR_NONE) return retVal;
1969 g_event_callback.process_input_device_event = NULL;
1970 g_event_callback.process_input_device_event_user_data = NULL;
1972 return IME_ERROR_NONE;
1975 /* Functions for Rotary input device event */
1976 EXPORT_API int ime_input_device_rotary_get_direction(ime_input_device_event_h event_handle, ime_input_device_rotary_direction_e *direction)
1978 ime_error_e retVal = IME_ERROR_NONE;
1980 if (!event_handle || !direction) {
1981 LOGW("IME_ERROR_INVALID_PARAMETER");
1982 return IME_ERROR_INVALID_PARAMETER;
1985 ime_device_event_s *device_event = static_cast<ime_device_event_s*>(event_handle);
1986 if (device_event->device_type != IME_INPUT_DEVICE_TYPE_ROTARY) {
1987 LOGW("IME_ERROR_INVALID_PARAMETER");
1988 return IME_ERROR_INVALID_PARAMETER;
1991 retVal = _check_privilege();
1992 if (retVal != IME_ERROR_NONE) return retVal;
1995 LOGW("IME_ERROR_OPERATION_FAILED");
1996 return IME_ERROR_OPERATION_FAILED;
1999 Ecore_Event_Detent_Rotate *rotary_device_event =
2000 static_cast<Ecore_Event_Detent_Rotate*>(device_event->event_data);
2001 if (rotary_device_event) {
2002 if (rotary_device_event->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) {
2003 *direction = IME_INPUT_DEVICE_ROTARY_DIRECTION_CLOCKWISE;
2004 } else if (rotary_device_event->direction == ECORE_DETENT_DIRECTION_COUNTER_CLOCKWISE) {
2005 *direction = IME_INPUT_DEVICE_ROTARY_DIRECTION_COUNTER_CLOCKWISE;
2009 return IME_ERROR_NONE;
2013 EXPORT_API int ime_event_set_prediction_hint_set_cb(ime_prediction_hint_set_cb callback_func, void *user_data)
2015 ime_error_e retVal = IME_ERROR_NONE;
2017 if (!callback_func) {
2018 LOGW("IME_ERROR_INVALID_PARAMETER");
2019 return IME_ERROR_INVALID_PARAMETER;
2022 retVal = _check_privilege();
2023 if (retVal != IME_ERROR_NONE) return retVal;
2025 g_event_callback.prediction_hint_set = callback_func;
2026 g_event_callback.prediction_hint_set_user_data = user_data;
2028 return IME_ERROR_NONE;
2031 EXPORT_API int ime_event_set_mime_type_set_request_cb(ime_mime_type_set_request_cb callback_func, void *user_data)
2033 ime_error_e retVal = IME_ERROR_NONE;
2035 if (!callback_func) {
2036 LOGW("IME_ERROR_INVALID_PARAMETER");
2037 return IME_ERROR_INVALID_PARAMETER;
2040 retVal = _check_privilege();
2041 if (retVal != IME_ERROR_NONE) return retVal;
2043 g_event_callback.mime_type_set = callback_func;
2044 g_event_callback.mime_type_set_user_data = user_data;
2046 return IME_ERROR_NONE;
2049 EXPORT_API int ime_set_floating_mode(bool floating_mode)
2051 ime_error_e retVal = IME_ERROR_NONE;
2053 retVal = _check_privilege();
2054 if (retVal != IME_ERROR_NONE) return retVal;
2057 LOGW("IME_ERROR_NOT_RUNNING");
2058 return IME_ERROR_NOT_RUNNING;
2061 g_core.set_floating_mode(floating_mode);
2063 return IME_ERROR_NONE;
2066 EXPORT_API int ime_set_floating_drag_start(void)
2068 ime_error_e retVal = IME_ERROR_NONE;
2070 retVal = _check_privilege();
2071 if (retVal != IME_ERROR_NONE) return retVal;
2074 LOGW("IME_ERROR_NOT_RUNNING");
2075 return IME_ERROR_NOT_RUNNING;
2078 g_core.set_floating_drag_enabled(true);
2080 return IME_ERROR_NONE;
2083 EXPORT_API int ime_set_floating_drag_end(void)
2085 ime_error_e retVal = IME_ERROR_NONE;
2087 retVal = _check_privilege();
2088 if (retVal != IME_ERROR_NONE) return retVal;
2091 LOGW("IME_ERROR_NOT_RUNNING");
2092 return IME_ERROR_NOT_RUNNING;
2095 g_core.set_floating_drag_enabled(false);
2097 return IME_ERROR_NONE;
2101 EXPORT_API int ime_set_window_creation_defer_flag(bool flag)
2103 ime_error_e retVal = IME_ERROR_NONE;
2105 retVal = _check_privilege();
2106 if (retVal != IME_ERROR_NONE) return retVal;
2108 g_core.set_window_creation_defer_flag(flag);
2110 return IME_ERROR_NONE;
2114 EXPORT_API int ime_event_set_prediction_hint_data_set_cb(ime_prediction_hint_data_set_cb callback_func, void *user_data)
2116 ime_error_e retVal = IME_ERROR_NONE;
2118 if (!callback_func) {
2119 LOGW("IME_ERROR_INVALID_PARAMETER");
2120 return IME_ERROR_INVALID_PARAMETER;
2123 retVal = _check_privilege();
2124 if (retVal != IME_ERROR_NONE) return retVal;
2126 g_event_callback.prediction_hint_data_set = callback_func;
2127 g_event_callback.prediction_hint_data_set_user_data = user_data;
2129 return IME_ERROR_NONE;
2133 EXPORT_API int ime_event_set_optimization_hint_set_cb(ime_optimization_hint_set_cb callback_func, void *user_data)
2136 ime_error_e retVal = IME_ERROR_NONE;
2138 if (!callback_func) {
2139 LOGW("IME_ERROR_INVALID_PARAMETER");
2140 return IME_ERROR_INVALID_PARAMETER;
2144 retVal = _check_privilege();
2145 if (retVal != IME_ERROR_NONE) return retVal;
2148 g_event_callback.optimization_hint_set = callback_func;
2149 g_event_callback.optimization_hint_set_user_data = user_data;
2151 return IME_ERROR_NONE;
2155 EXPORT_API int ime_update_input_panel_event(ime_event_type_e type, unsigned int value)
2157 ime_error_e retVal = IME_ERROR_NONE;
2159 if (type < IME_EVENT_TYPE_LANGUAGE || type > IME_EVENT_TYPE_GEOMETRY) {
2160 LOGW("IME_ERROR_INVALID_PARAMETER");
2161 return IME_ERROR_INVALID_PARAMETER;
2165 LOGW("IME_ERROR_NOT_RUNNING");
2166 return IME_ERROR_NOT_RUNNING;
2169 retVal = _check_privilege();
2170 if (retVal != IME_ERROR_NONE) return retVal;
2172 g_core.update_input_context((sclu32)type, value);
2174 return IME_ERROR_NONE;
2177 EXPORT_API int ime_set_candidate_visibility_state(bool visible)
2179 ime_error_e retVal = IME_ERROR_NONE;
2182 LOGW("IME_ERROR_NOT_RUNNING");
2183 return IME_ERROR_NOT_RUNNING;
2186 retVal = _check_privilege();
2187 if (retVal != IME_ERROR_NONE) return retVal;
2190 g_core.show_candidate_string();
2192 g_core.hide_candidate_string();
2194 return IME_ERROR_NONE;