2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include <privilege_checker_private.h>
25 #include "inputmethod_private.h"
26 #include <inputmethod.h>
27 #include "inputmethod_internal.h"
34 #define LOG_TAG "INPUTMETHOD"
38 class CCoreEventCallback : public ISCLCoreEventCallback
41 void on_run(int argc, char **argv);
43 void on_update_cursor_position(sclint ic, const sclchar *ic_uuid, sclint cursor_pos);
44 void on_update_surrounding_text(sclint ic, const sclchar *text, sclint cursor);
45 void on_focus_out(sclint ic, const sclchar *ic_uuid);
46 void on_focus_in(sclint ic, const sclchar *ic_uuid);
47 void on_ise_show(sclint ic, const int degree, Ise_Context &context);
48 void on_ise_hide(sclint ic, const sclchar *ic_uuid);
49 void on_get_geometry(sclu32 *pos_x, sclu32 *pos_y, sclu32 *width, sclu32 *height);
50 void on_set_language(Ecore_IMF_Input_Panel_Lang language);
51 void on_set_imdata(sclchar *buf, sclu32 len);
52 void on_get_imdata(sclchar **buf, sclu32 *len);
53 void on_get_language_locale(sclint ic, sclchar **locale);
54 void on_set_return_key_type(Ecore_IMF_Input_Panel_Return_Key_Type type);
55 void on_set_return_key_disable(sclu32 disabled);
56 void on_set_layout(sclu32 layout);
57 void on_reset_input_context(sclint ic, const sclchar *uuid);
58 void on_process_key_event(scim::KeyEvent &key, sclu32 *ret);
59 void on_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);
153 extern void ime_app_main(int argc, char **argv);
157 void CCoreEventCallback::on_init()
159 if (g_basic_callback.create) {
160 g_basic_callback.create(g_user_data);
164 void CCoreEventCallback::on_run(int argc, char **argv)
167 ime_app_main(argc, argv);
170 void CCoreEventCallback::on_exit()
173 if (g_basic_callback.terminate) {
174 g_basic_callback.terminate(g_user_data);
178 void CCoreEventCallback::on_update_cursor_position(sclint ic, const sclchar *ic_uuid, sclint cursor_pos)
180 if (g_event_callback.cursor_position_updated) {
181 g_event_callback.cursor_position_updated(cursor_pos, g_event_callback.cursor_position_updated_user_data);
185 void CCoreEventCallback::on_update_surrounding_text(sclint ic, const sclchar *text, sclint cursor)
187 if (g_event_callback.surrounding_text_updated) {
188 g_event_callback.surrounding_text_updated(ic, text, cursor, g_event_callback.surrounding_text_updated_user_data);
192 void CCoreEventCallback::on_focus_out(sclint ic, const sclchar *ic_uuid)
194 if (g_event_callback.focus_out) {
195 g_event_callback.focus_out(ic, g_event_callback.focus_out_user_data);
199 void CCoreEventCallback::on_focus_in(sclint ic, const sclchar *ic_uuid)
201 if (g_event_callback.focus_in) {
202 g_event_callback.focus_in(ic, g_event_callback.focus_in_user_data);
206 void CCoreEventCallback::on_ise_show(sclint ic, const int degree, Ise_Context &context)
208 if (g_basic_callback.show) {
209 struct _ime_context input_context;
211 memset(&input_context, 0, sizeof(struct _ime_context));
212 input_context.layout = context.layout;
213 input_context.layout_variation = context.layout_variation;
214 input_context.cursor_pos = context.cursor_pos;
215 input_context.autocapital_type = context.autocapital_type;
216 input_context.return_key_type = context.return_key_type;
217 input_context.return_key_disabled = context.return_key_disabled;
218 input_context.prediction_allow = context.prediction_allow;
219 input_context.password_mode = context.password_mode;
220 input_context.imdata_size = context.imdata_size;
221 input_context.input_hint = context.input_hint;
222 input_context.bidi_direction = context.bidi_direction;
223 input_context.language = context.language;
224 input_context.client_window = context.client_window;
225 input_context.caps_mode = context.caps_mode;
227 g_basic_callback.show(ic, static_cast<ime_context_h>(&input_context), g_user_data);
231 void CCoreEventCallback::on_ise_hide(sclint ic, const sclchar *ic_uuid)
233 if (g_basic_callback.hide) {
234 g_basic_callback.hide(ic, g_user_data);
238 void CCoreEventCallback::on_get_geometry(sclu32 *pos_x, sclu32 *pos_y, sclu32 *width, sclu32 *height)
240 int geometry_pos_x = 0;
241 int geometry_pos_y = 0;
242 int geometry_width = 0;
243 int geometry_height = 0;
245 if (g_event_callback.geometry_requested) {
246 g_event_callback.geometry_requested(g_event_callback.geometry_requested_user_data, &geometry_pos_x, &geometry_pos_y, &geometry_width, &geometry_height);
250 *pos_x = geometry_pos_x;
253 *pos_y = geometry_pos_y;
256 *width = geometry_width;
259 *height = geometry_height;
262 void CCoreEventCallback::on_set_language(Ecore_IMF_Input_Panel_Lang language)
264 if (g_event_callback.language_set) {
265 g_event_callback.language_set(language, g_event_callback.language_set_user_data);
269 void CCoreEventCallback::on_set_imdata(sclchar *buf, sclu32 len)
271 if (g_event_callback.imdata_set) {
272 g_event_callback.imdata_set((void *)buf, len, g_event_callback.imdata_set_user_data);
276 void CCoreEventCallback::on_get_imdata(sclchar **buf, sclu32 *len)
278 if (g_event_callback.imdata_requested) {
279 g_event_callback.imdata_requested(g_event_callback.imdata_set_user_data, (void **)buf, len);
283 void CCoreEventCallback::on_get_language_locale(sclint ic, sclchar **locale)
285 if (g_event_callback.language_requested) {
286 g_event_callback.language_requested(g_event_callback.language_requested_user_data, locale);
290 void CCoreEventCallback::on_set_return_key_type(Ecore_IMF_Input_Panel_Return_Key_Type type)
292 if (g_event_callback.return_key_type_set) {
293 g_event_callback.return_key_type_set(type, g_event_callback.return_key_type_set_user_data);
297 void CCoreEventCallback::on_set_return_key_disable(sclu32 disabled)
299 bool return_key_disabled = !!disabled;
301 if (g_event_callback.return_key_state_set) {
302 g_event_callback.return_key_state_set(return_key_disabled, g_event_callback.return_key_state_set_user_data);
306 void CCoreEventCallback::on_set_layout(sclu32 layout)
308 if (g_event_callback.layout_set) {
309 g_event_callback.layout_set(static_cast<Ecore_IMF_Input_Panel_Layout>(layout), g_event_callback.layout_set_user_data);
313 void CCoreEventCallback::on_reset_input_context(sclint ic, const sclchar *uuid)
315 if (g_event_callback.input_context_reset) {
316 g_event_callback.input_context_reset(g_event_callback.input_context_reset_user_data);
320 void CCoreEventCallback::on_process_key_event(scim::KeyEvent &key, sclu32 *ret)
322 if (g_event_callback.process_key_event) {
323 struct _ime_device_info dev_info = {key.dev_name.c_str(),
324 static_cast<Ecore_IMF_Device_Class>(key.dev_class), static_cast<Ecore_IMF_Device_Subclass>(key.dev_subclass)};
325 bool processed = g_event_callback.process_key_event(static_cast<ime_key_code_e>(key.code), static_cast<ime_key_mask_e>(key.mask),
326 static_cast<ime_device_info_h>(&dev_info), g_event_callback.process_key_event_user_data);
341 void CCoreEventCallback::on_process_key_event_with_keycode(scim::KeyEvent &key, sclu32 *ret, sclu32 keycode)
343 if (g_event_callback.process_key_event_with_keycode) {
344 struct _ime_device_info dev_info = {key.dev_name.c_str(),
345 static_cast<Ecore_IMF_Device_Class>(key.dev_class), static_cast<Ecore_IMF_Device_Subclass>(key.dev_subclass)};
346 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),
347 static_cast<ime_device_info_h>(&dev_info), g_event_callback.process_key_event_user_data);
362 void CCoreEventCallback::on_set_display_language(const sclchar *language)
364 if (g_event_callback.display_language_changed) {
365 g_event_callback.display_language_changed(language, g_event_callback.display_language_changed_user_data);
369 void CCoreEventCallback::on_set_rotation_degree(sclint degree)
371 if (g_event_callback.rotation_degree_changed) {
372 g_event_callback.rotation_degree_changed(degree, g_event_callback.rotation_degree_changed_user_data);
376 void CCoreEventCallback::on_set_accessibility_state(sclboolean state)
378 if (g_event_callback.accessibility_state_changed) {
379 g_event_callback.accessibility_state_changed(state, g_event_callback.accessibility_state_changed_user_data);
383 void CCoreEventCallback::on_create_option_window(sclwindow window, SCLOptionWindowType type)
385 if (g_event_callback.option_window_created) {
386 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);
390 void CCoreEventCallback::on_destroy_option_window(sclwindow window)
392 if (g_event_callback.option_window_destroyed) {
393 g_event_callback.option_window_destroyed(static_cast<Evas_Object*>(window), g_event_callback.option_window_destroyed_user_data);
397 void CCoreEventCallback::on_check_option_window_availability(sclboolean *ret)
400 if (g_event_callback.option_window_created) // Instead of each 3rd party keyboard, inputmethod will reply the availability of the option (setting).
407 void CCoreEventCallback::on_set_caps_mode(sclu32 mode)
409 if (g_event_callback.caps_mode_changed) {
410 g_event_callback.caps_mode_changed(mode, g_event_callback.caps_mode_changed_user_data);
414 void CCoreEventCallback::on_candidate_show(sclint ic, const sclchar *ic_uuid)
416 if (g_event_callback.candidate_show) {
417 g_event_callback.candidate_show(ic, g_event_callback.candidate_show_user_data);
421 void CCoreEventCallback::on_candidate_hide(sclint ic, const sclchar *ic_uuid)
423 if (g_event_callback.candidate_hide) {
424 g_event_callback.candidate_hide(ic, g_event_callback.candidate_hide_user_data);
428 void CCoreEventCallback::on_update_lookup_table(SclCandidateTable &table)
430 Eina_List *string_list = NULL;
432 if (g_event_callback.lookup_table_changed) {
433 vector<string>::iterator iter = table.candidate.begin();
434 for (; iter != table.candidate.end(); ++iter) {
435 string_list = eina_list_append(string_list, iter->c_str());
438 g_event_callback.lookup_table_changed(string_list, g_event_callback.lookup_table_changed_user_data);
442 void CCoreEventCallback::on_process_input_device_event(sclu32 &type, sclchar *data, size_t &len, sclu32 *ret)
446 ime_input_device_type_e device_type;
447 } ime_device_type_conv_table;
449 ime_device_type_conv_table conv_table[] = {
450 { ECORE_EVENT_DETENT_ROTATE , IME_INPUT_DEVICE_TYPE_ROTARY },
453 ime_input_device_type_e device_type = IME_INPUT_DEVICE_TYPE_UNKNOWN;
454 for (unsigned int loop = 0; loop < sizeof(conv_table) / sizeof(ime_device_type_conv_table); loop++) {
455 if ((unsigned int)(conv_table[loop].ecore_event_id) == type) {
456 device_type = conv_table[loop].device_type;
460 if (g_event_callback.process_input_device_event) {
461 ime_device_event_s device_event;
462 device_event.device_type = device_type;
463 device_event.event_data = static_cast<void*>(data);
464 void *input_data = static_cast<void*>(&device_event);
465 void *user_data = g_event_callback.process_input_device_event_user_data;
467 g_event_callback.process_input_device_event(device_type, input_data, user_data);
479 void CCoreEventCallback::on_set_prediction_hint(const sclchar *prediction_hint)
481 if (g_event_callback.prediction_hint_set) {
482 g_event_callback.prediction_hint_set(prediction_hint, g_event_callback.prediction_hint_set_user_data);
486 void CCoreEventCallback::on_set_mime_type(const sclchar *mime_type)
488 if (g_event_callback.mime_type_set) {
489 g_event_callback.mime_type_set(mime_type, g_event_callback.mime_type_set_user_data);
493 void CCoreEventCallback::on_set_prediction_hint_data(const sclchar *key, const sclchar *value)
495 if (g_event_callback.prediction_hint_data_set) {
496 g_event_callback.prediction_hint_data_set(key, value, g_event_callback.prediction_hint_data_set_user_data);
500 void CCoreEventCallback::on_set_optimization_hint(sclu32 hint)
502 if (g_event_callback.optimization_hint_set) {
503 g_event_callback.optimization_hint_set((ime_optimization_hint_e)hint, g_event_callback.optimization_hint_set_user_data);
508 ime_error_e _check_privilege()
511 ime_error_e ret = IME_ERROR_NONE;
513 if (inputmethod_cynara_initialize() == false) {
514 LOGE("inputmethod_cynara_initialize () == false");
515 return IME_ERROR_PERMISSION_DENIED;
518 snprintf(uid, 16, "%d", getuid());
519 if (check_privilege(uid, IME_PRIVILEGE) == false) {
520 LOGE("check_privilege(uid, IME_PRIVILEGE) == false. uid : %s", uid);
521 ret = IME_ERROR_PERMISSION_DENIED;
524 inputmethod_cynara_finish();
530 bool g_from_dotnet = false;
531 EXPORT_API int ime_set_dotnet_flag(bool set)
533 ime_error_e retVal = IME_ERROR_NONE;
535 retVal = _check_privilege();
536 if (retVal != IME_ERROR_NONE) return retVal;
544 EXPORT_API int ime_run(ime_callback_s *basic_cb, void *user_data)
546 ime_error_e retVal = IME_ERROR_NONE;
549 LOGE("inputmethod main loop is already running.");
550 return IME_ERROR_OPERATION_FAILED;
554 LOGE("basic callbacks pointer is null.");
555 return IME_ERROR_INVALID_PARAMETER;
558 retVal = _check_privilege();
559 if (retVal != IME_ERROR_NONE) return retVal;
561 g_basic_callback = *basic_cb;
563 if (!g_basic_callback.create || !g_basic_callback.terminate ||
564 !g_basic_callback.show || !g_basic_callback.hide) {
565 LOGE("mandatory callback functions are not set");
566 memset(&g_basic_callback, 0, sizeof(ime_callback_s));
567 memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
568 return IME_ERROR_NO_CALLBACK_FUNCTION;
571 g_user_data = user_data;
575 LOGD("ime_run is called from dotnet");
576 return IME_ERROR_NONE;
582 LOGW("exception is thrown from g_core.run()\n");
585 memset(&g_basic_callback, 0, sizeof(ime_callback_s));
586 memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
590 return IME_ERROR_NONE;
593 EXPORT_API int ime_event_set_focus_in_cb(ime_focus_in_cb callback_func, void *user_data)
595 ime_error_e retVal = IME_ERROR_NONE;
597 if (!callback_func) {
598 LOGW("IME_ERROR_INVALID_PARAMETER");
599 return IME_ERROR_INVALID_PARAMETER;
602 retVal = _check_privilege();
603 if (retVal != IME_ERROR_NONE) return retVal;
605 g_event_callback.focus_in = callback_func;
606 g_event_callback.focus_in_user_data = user_data;
608 return IME_ERROR_NONE;
611 EXPORT_API int ime_event_set_focus_out_cb(ime_focus_out_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_out = callback_func;
624 g_event_callback.focus_out_user_data = user_data;
626 return IME_ERROR_NONE;
629 EXPORT_API int ime_event_set_surrounding_text_updated_cb(ime_surrounding_text_updated_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.surrounding_text_updated = callback_func;
642 g_event_callback.surrounding_text_updated_user_data = user_data;
644 return IME_ERROR_NONE;
647 EXPORT_API int ime_event_set_input_context_reset_cb(ime_input_context_reset_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.input_context_reset = callback_func;
660 g_event_callback.input_context_reset_user_data = user_data;
662 return IME_ERROR_NONE;
665 EXPORT_API int ime_event_set_cursor_position_updated_cb(ime_cursor_position_updated_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.cursor_position_updated = callback_func;
678 g_event_callback.cursor_position_updated_user_data = user_data;
680 return IME_ERROR_NONE;
683 EXPORT_API int ime_event_set_language_requested_cb(ime_language_requested_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.language_requested = callback_func;
696 g_event_callback.language_requested_user_data = user_data;
698 return IME_ERROR_NONE;
701 EXPORT_API int ime_event_set_language_set_cb(ime_language_set_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_set = callback_func;
714 g_event_callback.language_set_user_data = user_data;
716 return IME_ERROR_NONE;
719 EXPORT_API int ime_event_set_imdata_set_cb(ime_imdata_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.imdata_set = callback_func;
732 g_event_callback.imdata_set_user_data = user_data;
734 return IME_ERROR_NONE;
737 EXPORT_API int ime_event_set_imdata_requested_cb(ime_imdata_requested_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_requested = callback_func;
750 g_event_callback.imdata_requested_user_data = user_data;
752 return IME_ERROR_NONE;
755 EXPORT_API int ime_event_set_layout_set_cb(ime_layout_set_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.layout_set = callback_func;
768 g_event_callback.layout_set_user_data = user_data;
770 return IME_ERROR_NONE;
773 EXPORT_API int ime_event_set_return_key_type_set_cb(ime_return_key_type_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.return_key_type_set = callback_func;
786 g_event_callback.return_key_type_set_user_data = user_data;
788 return IME_ERROR_NONE;
791 EXPORT_API int ime_event_set_return_key_state_set_cb(ime_return_key_state_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_state_set = callback_func;
804 g_event_callback.return_key_state_set_user_data = user_data;
806 return IME_ERROR_NONE;
809 EXPORT_API int ime_event_set_geometry_requested_cb(ime_geometry_requested_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.geometry_requested = callback_func;
822 g_event_callback.geometry_requested_user_data = user_data;
824 return IME_ERROR_NONE;
827 EXPORT_API int ime_event_set_process_key_event_cb(ime_process_key_event_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.process_key_event = callback_func;
840 g_event_callback.process_key_event_user_data = user_data;
842 return IME_ERROR_NONE;
845 EXPORT_API int ime_event_set_process_key_event_with_keycode_cb(ime_process_key_event_with_keycode_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_with_keycode = callback_func;
858 g_event_callback.process_key_event_with_keycode_user_data = user_data;
860 return IME_ERROR_NONE;
863 EXPORT_API int ime_event_set_display_language_changed_cb(ime_display_language_changed_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.display_language_changed = callback_func;
876 g_event_callback.display_language_changed_user_data = user_data;
878 return IME_ERROR_NONE;
881 EXPORT_API int ime_event_set_rotation_degree_changed_cb(ime_rotation_degree_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.rotation_degree_changed = callback_func;
894 g_event_callback.rotation_degree_changed_user_data = user_data;
896 return IME_ERROR_NONE;
899 EXPORT_API int ime_event_set_accessibility_state_changed_cb(ime_accessibility_state_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.accessibility_state_changed = callback_func;
912 g_event_callback.accessibility_state_changed_user_data = user_data;
914 return IME_ERROR_NONE;
917 EXPORT_API int ime_event_set_option_window_created_cb(ime_option_window_created_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.option_window_created = callback_func;
930 g_event_callback.option_window_created_user_data = user_data;
932 return IME_ERROR_NONE;
935 EXPORT_API int ime_event_set_option_window_destroyed_cb(ime_option_window_destroyed_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_destroyed = callback_func;
948 g_event_callback.option_window_destroyed_user_data = user_data;
950 return IME_ERROR_NONE;
954 EXPORT_API int ime_event_set_caps_mode_changed_cb(ime_caps_mode_changed_cb callback_func, void *user_data)
956 ime_error_e retVal = IME_ERROR_NONE;
958 if (!callback_func) {
959 LOGW("IME_ERROR_INVALID_PARAMETER");
960 return IME_ERROR_INVALID_PARAMETER;
963 retVal = _check_privilege();
964 if (retVal != IME_ERROR_NONE) return retVal;
966 g_event_callback.caps_mode_changed = callback_func;
967 g_event_callback.caps_mode_changed_user_data = user_data;
969 return IME_ERROR_NONE;
972 EXPORT_API int ime_event_set_candidate_show_cb(ime_candidate_show_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.candidate_show = callback_func;
985 g_event_callback.candidate_show_user_data = user_data;
987 return IME_ERROR_NONE;
990 EXPORT_API int ime_event_set_candidate_hide_cb(ime_candidate_hide_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_hide = callback_func;
1003 g_event_callback.candidate_hide_user_data = user_data;
1005 return IME_ERROR_NONE;
1008 EXPORT_API int ime_event_set_lookup_table_changed_cb(ime_lookup_table_changed_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.lookup_table_changed = callback_func;
1021 g_event_callback.lookup_table_changed_user_data = user_data;
1023 return IME_ERROR_NONE;
1027 EXPORT_API int ime_send_key_event(ime_key_code_e keycode, ime_key_mask_e keymask, bool forward_key)
1029 ime_error_e retVal = IME_ERROR_NONE;
1032 LOGW("IME_ERROR_NOT_RUNNING");
1033 return IME_ERROR_NOT_RUNNING;
1036 retVal = _check_privilege();
1037 if (retVal != IME_ERROR_NONE) return retVal;
1040 g_core.forward_key_event(-1, NULL, (sclu32)keycode, (sclu16)keymask);
1042 g_core.send_key_event(-1, NULL, (sclu32)keycode, (sclu16)keymask);
1044 return IME_ERROR_NONE;
1047 EXPORT_API int ime_commit_string(const char *str)
1049 ime_error_e retVal = IME_ERROR_NONE;
1052 LOGW("IME_ERROR_INVALID_PARAMETER");
1053 return IME_ERROR_INVALID_PARAMETER;
1057 LOGW("IME_ERROR_NOT_RUNNING");
1058 return IME_ERROR_NOT_RUNNING;
1061 retVal = _check_privilege();
1062 if (retVal != IME_ERROR_NONE) return retVal;
1064 g_core.commit_string(-1, NULL, str);
1066 return IME_ERROR_NONE;
1069 EXPORT_API int ime_show_preedit_string(void)
1071 ime_error_e retVal = IME_ERROR_NONE;
1074 LOGW("IME_ERROR_NOT_RUNNING");
1075 return IME_ERROR_NOT_RUNNING;
1078 retVal = _check_privilege();
1079 if (retVal != IME_ERROR_NONE) return retVal;
1081 g_core.show_preedit_string(-1, NULL);
1083 return IME_ERROR_NONE;
1086 EXPORT_API int ime_hide_preedit_string(void)
1088 ime_error_e retVal = IME_ERROR_NONE;
1091 LOGW("IME_ERROR_NOT_RUNNING");
1092 return IME_ERROR_NOT_RUNNING;
1095 retVal = _check_privilege();
1096 if (retVal != IME_ERROR_NONE) return retVal;
1098 g_core.hide_preedit_string(-1, NULL);
1100 return IME_ERROR_NONE;
1103 EXPORT_API int ime_update_preedit_string(const char *str, Eina_List *attrs)
1105 ime_error_e retVal = IME_ERROR_NONE;
1108 LOGW("IME_ERROR_INVALID_PARAMETER");
1109 return IME_ERROR_INVALID_PARAMETER;
1113 LOGW("IME_ERROR_NOT_RUNNING");
1114 return IME_ERROR_NOT_RUNNING;
1117 retVal = _check_privilege();
1118 if (retVal != IME_ERROR_NONE) return retVal;
1120 scim::AttributeList attrv;
1122 ime_preedit_attribute *attr = NULL;
1125 EINA_LIST_FREE(attrs, data) {
1126 attr = (ime_preedit_attribute *)data;
1128 attrv.push_back(scim::Attribute(attr->start, attr->length, (scim::AttributeType)attr->type, attr->value));
1134 g_core.update_preedit_string(-1, NULL, str, attrv);
1136 return IME_ERROR_NONE;
1139 EXPORT_API int ime_request_surrounding_text(int maxlen_before, int maxlen_after)
1141 ime_error_e retVal = IME_ERROR_NONE;
1143 if (!g_event_callback.surrounding_text_updated) {
1144 LOGW("IME_ERROR_NO_CALLBACK_FUNCTION");
1145 return IME_ERROR_NO_CALLBACK_FUNCTION;
1149 LOGW("IME_ERROR_NOT_RUNNING");
1150 return IME_ERROR_NOT_RUNNING;
1153 retVal = _check_privilege();
1154 if (retVal != IME_ERROR_NONE) return retVal;
1156 g_core.get_surrounding_text(NULL, maxlen_before, maxlen_after);
1158 return IME_ERROR_NONE;
1161 EXPORT_API int ime_delete_surrounding_text(int offset, int len)
1163 ime_error_e retVal = IME_ERROR_NONE;
1166 LOGW("IME_ERROR_INVALID_PARAMETER");
1167 return IME_ERROR_INVALID_PARAMETER;
1171 LOGW("IME_ERROR_NOT_RUNNING");
1172 return IME_ERROR_NOT_RUNNING;
1175 retVal = _check_privilege();
1176 if (retVal != IME_ERROR_NONE) return retVal;
1178 g_core.delete_surrounding_text(offset, len);
1180 return IME_ERROR_NONE;
1183 EXPORT_API int ime_get_surrounding_text(int maxlen_before, int maxlen_after, char **text, int *cursor_pos)
1185 ime_error_e retVal = IME_ERROR_NONE;
1187 if (!text || !cursor_pos) {
1188 LOGW("IME_ERROR_INVALID_PARAMETER");
1189 return IME_ERROR_INVALID_PARAMETER;
1193 LOGW("IME_ERROR_NOT_RUNNING");
1194 return IME_ERROR_NOT_RUNNING;
1197 retVal = _check_privilege();
1198 if (retVal != IME_ERROR_NONE) return retVal;
1202 int ret = g_core.get_surrounding_text(maxlen_before, maxlen_after, text, cursor);
1204 LOGW("IME_ERROR_OUR_OF_MEMORY");
1205 return IME_ERROR_OUT_OF_MEMORY;
1209 *cursor_pos = cursor;
1211 return IME_ERROR_NONE;
1214 EXPORT_API int ime_set_selection(int start, int end)
1216 ime_error_e retVal = IME_ERROR_NONE;
1219 LOGW("IME_ERROR_INVALID_PARAMETER");
1220 return IME_ERROR_INVALID_PARAMETER;
1224 LOGW("IME_ERROR_NOT_RUNNING");
1225 return IME_ERROR_NOT_RUNNING;
1228 retVal = _check_privilege();
1229 if (retVal != IME_ERROR_NONE) return retVal;
1231 g_core.set_selection(start, end);
1233 return IME_ERROR_NONE;
1236 EXPORT_API int ime_get_selected_text(char **text)
1238 ime_error_e retVal = IME_ERROR_NONE;
1241 LOGW("IME_ERROR_INVALID_PARAMETER");
1242 return IME_ERROR_INVALID_PARAMETER;
1246 LOGW("IME_ERROR_NOT_RUNNING");
1247 return IME_ERROR_NOT_RUNNING;
1250 retVal = _check_privilege();
1251 if (retVal != IME_ERROR_NONE) return retVal;
1253 g_core.get_selection_text(text);
1255 return IME_ERROR_NONE;
1258 EXPORT_API Evas_Object* ime_get_main_window(void)
1260 ime_error_e retVal = IME_ERROR_NONE;
1262 Evas_Object *win = NULL;
1264 retVal = _check_privilege();
1265 if (retVal != IME_ERROR_NONE) {
1266 LOGE("_check_privilege returned %d.", retVal);
1267 set_last_result(retVal);
1272 set_last_result(IME_ERROR_NOT_RUNNING);
1273 LOGW("IME_ERROR_NOT_RUNNING");
1277 win = static_cast<Evas_Object*>(g_core.get_main_window());
1279 set_last_result(IME_ERROR_NONE);
1281 set_last_result(IME_ERROR_OPERATION_FAILED);
1282 LOGW("IME_ERROR_OPERATION_FAILED");
1288 EXPORT_API int ime_set_size(int portrait_width, int portrait_height, int landscape_width, int landscape_height)
1290 ime_error_e retVal = IME_ERROR_NONE;
1292 SclSize portrait_size, landscape_size;
1294 if (portrait_width < 1 || portrait_height < 1 || landscape_width < 1 || landscape_height < 1) {
1295 LOGW("IME_ERROR_INVALID_PARAMETER");
1296 return IME_ERROR_INVALID_PARAMETER;
1300 LOGW("IME_ERROR_NOT_RUNNING");
1301 return IME_ERROR_NOT_RUNNING;
1304 retVal = _check_privilege();
1305 if (retVal != IME_ERROR_NONE) return retVal;
1307 portrait_size.width = portrait_width;
1308 portrait_size.height = portrait_height;
1310 landscape_size.width = landscape_width;
1311 landscape_size.height = landscape_height;
1313 g_core.set_keyboard_size_hints(portrait_size, landscape_size);
1315 return IME_ERROR_NONE;
1318 EXPORT_API int ime_create_option_window(void)
1320 ime_error_e retVal = IME_ERROR_NONE;
1322 if (!g_event_callback.option_window_created || !g_event_callback.option_window_destroyed) {
1323 LOGW("ime_create_option_window_cb() and ime_destroy_option_window_cb() callback functions are not set.");
1324 return IME_ERROR_NO_CALLBACK_FUNCTION;
1328 LOGW("IME_ERROR_NOT_RUNNING");
1329 return IME_ERROR_NOT_RUNNING;
1332 retVal = _check_privilege();
1333 if (retVal != IME_ERROR_NONE) return retVal;
1335 if (g_core.create_option_window()) {
1336 return IME_ERROR_NONE;
1338 LOGW("IME_ERROR_OPERATION_FAILED");
1339 return IME_ERROR_OPERATION_FAILED;
1343 EXPORT_API int ime_destroy_option_window(Evas_Object *window)
1345 ime_error_e retVal = IME_ERROR_NONE;
1347 if (!g_event_callback.option_window_created || !g_event_callback.option_window_destroyed) {
1348 LOGW("ime_create_option_window_cb() and ime_destroy_option_window_cb() callback functions are not set.");
1349 return IME_ERROR_NO_CALLBACK_FUNCTION;
1353 LOGW("Window pointer is null.");
1354 return IME_ERROR_INVALID_PARAMETER;
1358 LOGW("IME_ERROR_NOT_RUNNING");
1359 return IME_ERROR_NOT_RUNNING;
1362 retVal = _check_privilege();
1363 if (retVal != IME_ERROR_NONE) return retVal;
1365 g_core.destroy_option_window(window);
1367 return IME_ERROR_NONE;
1371 EXPORT_API int ime_set_imengine(const char *engine_id)
1373 ime_error_e retVal = IME_ERROR_NONE;
1376 LOGW("IME_ERROR_INVALID_PARAMETER");
1377 return IME_ERROR_INVALID_PARAMETER;
1380 retVal = _check_privilege();
1381 if (retVal != IME_ERROR_NONE) return retVal;
1383 g_core.set_keyboard_ise_by_uuid(engine_id);
1385 return IME_ERROR_NONE;
1388 EXPORT_API int ime_flush_imengine(void)
1390 ime_error_e retVal = IME_ERROR_NONE;
1393 LOGW("IME_ERROR_NOT_RUNNING");
1394 return IME_ERROR_NOT_RUNNING;
1397 retVal = _check_privilege();
1398 if (retVal != IME_ERROR_NONE) return retVal;
1400 g_core.flush_keyboard_ise();
1402 return IME_ERROR_NONE;
1405 EXPORT_API int ime_send_imengine_event(int command, unsigned int value)
1407 ime_error_e retVal = IME_ERROR_NONE;
1410 LOGW("IME_ERROR_NOT_RUNNING");
1411 return IME_ERROR_NOT_RUNNING;
1414 retVal = _check_privilege();
1415 if (retVal != IME_ERROR_NONE) return retVal;
1417 g_core.send_imengine_event(-1, NULL, command, value);
1419 return IME_ERROR_NONE;
1422 EXPORT_API int ime_reset_imengine(void)
1424 ime_error_e retVal = IME_ERROR_NONE;
1427 LOGW("IME_ERROR_NOT_RUNNING");
1428 return IME_ERROR_NOT_RUNNING;
1431 retVal = _check_privilege();
1432 if (retVal != IME_ERROR_NONE) return retVal;
1434 g_core.reset_keyboard_ise();
1436 return IME_ERROR_NONE;
1439 EXPORT_API int ime_update_input_context(unsigned int type, unsigned int value)
1441 ime_error_e retVal = IME_ERROR_NONE;
1444 LOGW("IME_ERROR_NOT_RUNNING");
1445 return IME_ERROR_NOT_RUNNING;
1448 retVal = _check_privilege();
1449 if (retVal != IME_ERROR_NONE) return retVal;
1451 g_core.update_input_context(type, value);
1453 return IME_ERROR_NONE;
1457 EXPORT_API int ime_request_hide(void)
1459 ime_error_e retVal = IME_ERROR_NONE;
1462 LOGW("IME_ERROR_NOT_RUNNING");
1463 return IME_ERROR_NOT_RUNNING;
1466 retVal = _check_privilege();
1467 if (retVal != IME_ERROR_NONE) return retVal;
1469 g_core.request_ise_hide();
1471 return IME_ERROR_NONE;
1475 EXPORT_API int ime_initialize(void)
1477 ime_error_e retVal = IME_ERROR_NONE;
1479 retVal = _check_privilege();
1480 if (retVal != IME_ERROR_NONE) return retVal;
1488 EXPORT_API int ime_prepare(void)
1490 ime_error_e retVal = IME_ERROR_NONE;
1493 LOGE("inputmethod main loop is already running.");
1494 return IME_ERROR_OPERATION_FAILED;
1497 retVal = _check_privilege();
1498 if (retVal != IME_ERROR_NONE) return retVal;
1507 EXPORT_API int ime_finalize(void)
1509 ime_error_e retVal = IME_ERROR_NONE;
1511 retVal = _check_privilege();
1512 if (retVal != IME_ERROR_NONE) return retVal;
1516 memset(&g_basic_callback, 0, sizeof(ime_callback_s));
1517 memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
1523 EXPORT_API int ime_select_candidate(unsigned int index)
1525 ime_error_e retVal = IME_ERROR_NONE;
1528 LOGW("IME_ERROR_NOT_RUNNING");
1529 return IME_ERROR_NOT_RUNNING;
1532 retVal = _check_privilege();
1533 if (retVal != IME_ERROR_NONE) return retVal;
1535 g_core.select_candidate(index);
1537 return IME_ERROR_NONE;
1541 EXPORT_API int ime_send_private_command(const char *command)
1543 ime_error_e retVal = IME_ERROR_NONE;
1546 LOGW("IME_ERROR_INVALID_PARAMETER");
1547 return IME_ERROR_INVALID_PARAMETER;
1551 LOGW("IME_ERROR_NOT_RUNNING");
1552 return IME_ERROR_NOT_RUNNING;
1555 retVal = _check_privilege();
1556 if (retVal != IME_ERROR_NONE) return retVal;
1558 g_core.send_private_command(command);
1560 return IME_ERROR_NONE;
1563 EXPORT_API int ime_commit_content(const char *content, const char *description, const char *mime_type)
1565 ime_error_e retVal = IME_ERROR_NONE;
1567 if (!content || !description || !mime_type) {
1568 LOGW("IME_ERROR_INVALID_PARAMETER");
1569 return IME_ERROR_INVALID_PARAMETER;
1572 retVal = _check_privilege();
1573 if (retVal != IME_ERROR_NONE) return retVal;
1576 LOGW("IME_ERROR_NOT_RUNNING");
1577 return IME_ERROR_NOT_RUNNING;
1580 g_core.commit_content(content, description, mime_type);
1582 return IME_ERROR_NONE;
1585 EXPORT_API int ime_context_get_layout(ime_context_h context, Ecore_IMF_Input_Panel_Layout *layout)
1587 ime_error_e retVal = IME_ERROR_NONE;
1589 if (!context || !layout) {
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 *layout = context->layout;
1604 return IME_ERROR_NONE;
1607 EXPORT_API int ime_context_get_layout_variation(ime_context_h context, ime_layout_variation_e *layout_variation)
1609 ime_error_e retVal = IME_ERROR_NONE;
1611 if (!context || !layout_variation) {
1612 LOGW("IME_ERROR_INVALID_PARAMETER");
1613 return IME_ERROR_INVALID_PARAMETER;
1616 retVal = _check_privilege();
1617 if (retVal != IME_ERROR_NONE) return retVal;
1620 LOGW("IME_ERROR_NOT_RUNNING");
1621 return IME_ERROR_NOT_RUNNING;
1624 *layout_variation = static_cast<ime_layout_variation_e>(context->layout_variation);
1626 return IME_ERROR_NONE;
1629 EXPORT_API int ime_context_get_cursor_position(ime_context_h context, int *cursor_pos)
1631 ime_error_e retVal = IME_ERROR_NONE;
1633 if (!context || !cursor_pos) {
1634 LOGW("IME_ERROR_INVALID_PARAMETER");
1635 return IME_ERROR_INVALID_PARAMETER;
1638 retVal = _check_privilege();
1639 if (retVal != IME_ERROR_NONE) return retVal;
1642 LOGW("IME_ERROR_NOT_RUNNING");
1643 return IME_ERROR_NOT_RUNNING;
1646 *cursor_pos = context->cursor_pos;
1648 return IME_ERROR_NONE;
1651 EXPORT_API int ime_context_get_autocapital_type(ime_context_h context, Ecore_IMF_Autocapital_Type *autocapital_type)
1653 ime_error_e retVal = IME_ERROR_NONE;
1655 if (!context || !autocapital_type) {
1656 LOGW("IME_ERROR_INVALID_PARAMETER");
1657 return IME_ERROR_INVALID_PARAMETER;
1660 retVal = _check_privilege();
1661 if (retVal != IME_ERROR_NONE) return retVal;
1664 LOGW("IME_ERROR_NOT_RUNNING");
1665 return IME_ERROR_NOT_RUNNING;
1668 *autocapital_type = context->autocapital_type;
1670 return IME_ERROR_NONE;
1673 EXPORT_API int ime_context_get_return_key_type(ime_context_h context, Ecore_IMF_Input_Panel_Return_Key_Type *return_key_type)
1675 ime_error_e retVal = IME_ERROR_NONE;
1677 if (!context || !return_key_type) {
1678 LOGW("IME_ERROR_INVALID_PARAMETER");
1679 return IME_ERROR_INVALID_PARAMETER;
1682 retVal = _check_privilege();
1683 if (retVal != IME_ERROR_NONE) return retVal;
1686 LOGW("IME_ERROR_NOT_RUNNING");
1687 return IME_ERROR_NOT_RUNNING;
1690 *return_key_type = context->return_key_type;
1692 return IME_ERROR_NONE;
1695 EXPORT_API int ime_context_get_return_key_state(ime_context_h context, bool *return_key_state)
1697 ime_error_e retVal = IME_ERROR_NONE;
1699 if (!context || !return_key_state) {
1700 LOGW("IME_ERROR_INVALID_PARAMETER");
1701 return IME_ERROR_INVALID_PARAMETER;
1704 retVal = _check_privilege();
1705 if (retVal != IME_ERROR_NONE) return retVal;
1708 LOGW("IME_ERROR_NOT_RUNNING");
1709 return IME_ERROR_NOT_RUNNING;
1712 *return_key_state = static_cast<bool>(context->return_key_disabled);
1714 return IME_ERROR_NONE;
1717 EXPORT_API int ime_context_get_prediction_mode(ime_context_h context, bool *prediction_mode)
1719 ime_error_e retVal = IME_ERROR_NONE;
1721 if (!context || !prediction_mode) {
1722 LOGW("IME_ERROR_INVALID_PARAMETER");
1723 return IME_ERROR_INVALID_PARAMETER;
1726 retVal = _check_privilege();
1727 if (retVal != IME_ERROR_NONE) return retVal;
1730 LOGW("IME_ERROR_NOT_RUNNING");
1731 return IME_ERROR_NOT_RUNNING;
1734 *prediction_mode = static_cast<bool>(context->prediction_allow);
1736 return IME_ERROR_NONE;
1739 EXPORT_API int ime_context_get_password_mode(ime_context_h context, bool *password_mode)
1741 ime_error_e retVal = IME_ERROR_NONE;
1743 if (!context || !password_mode) {
1744 LOGW("IME_ERROR_INVALID_PARAMETER");
1745 return IME_ERROR_INVALID_PARAMETER;
1748 retVal = _check_privilege();
1749 if (retVal != IME_ERROR_NONE) return retVal;
1752 LOGW("IME_ERROR_NOT_RUNNING");
1753 return IME_ERROR_NOT_RUNNING;
1756 *password_mode = static_cast<bool>(context->password_mode);
1758 return IME_ERROR_NONE;
1761 EXPORT_API int ime_context_get_input_hint(ime_context_h context, Ecore_IMF_Input_Hints *input_hint)
1763 ime_error_e retVal = IME_ERROR_NONE;
1765 if (!context || !input_hint) {
1766 LOGW("IME_ERROR_INVALID_PARAMETER");
1767 return IME_ERROR_INVALID_PARAMETER;
1770 retVal = _check_privilege();
1771 if (retVal != IME_ERROR_NONE) return retVal;
1774 LOGW("IME_ERROR_NOT_RUNNING");
1775 return IME_ERROR_NOT_RUNNING;
1778 *input_hint = context->input_hint;
1780 return IME_ERROR_NONE;
1783 EXPORT_API int ime_context_get_bidi_direction(ime_context_h context, Ecore_IMF_BiDi_Direction *bidi)
1785 ime_error_e retVal = IME_ERROR_NONE;
1787 if (!context || !bidi) {
1788 LOGW("IME_ERROR_INVALID_PARAMETER");
1789 return IME_ERROR_INVALID_PARAMETER;
1792 retVal = _check_privilege();
1793 if (retVal != IME_ERROR_NONE) return retVal;
1796 LOGW("IME_ERROR_NOT_RUNNING");
1797 return IME_ERROR_NOT_RUNNING;
1800 *bidi = context->bidi_direction;
1802 return IME_ERROR_NONE;
1805 EXPORT_API int ime_context_get_language(ime_context_h context, Ecore_IMF_Input_Panel_Lang *language)
1807 ime_error_e retVal = IME_ERROR_NONE;
1809 if (!context || !language) {
1810 LOGW("IME_ERROR_INVALID_PARAMETER");
1811 return IME_ERROR_INVALID_PARAMETER;
1814 retVal = _check_privilege();
1815 if (retVal != IME_ERROR_NONE) return retVal;
1818 LOGW("IME_ERROR_NOT_RUNNING");
1819 return IME_ERROR_NOT_RUNNING;
1822 *language = context->language;
1824 return IME_ERROR_NONE;
1828 EXPORT_API int ime_context_get_caps_mode(ime_context_h context, bool *caps_mode)
1830 ime_error_e retVal = IME_ERROR_NONE;
1832 if (!context || !caps_mode) {
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 *caps_mode = static_cast<bool>(context->caps_mode);
1847 return IME_ERROR_NONE;
1851 EXPORT_API int ime_device_info_get_name(ime_device_info_h dev_info, char **dev_name)
1853 ime_error_e retVal = IME_ERROR_NONE;
1855 if (!dev_info || !dev_name) {
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 if (!dev_info->dev_name)
1869 *dev_name = strdup("");
1871 *dev_name = strdup(dev_info->dev_name);
1873 return IME_ERROR_NONE;
1876 EXPORT_API int ime_device_info_get_class(ime_device_info_h dev_info, Ecore_IMF_Device_Class *dev_class)
1878 ime_error_e retVal = IME_ERROR_NONE;
1880 if (!dev_info || !dev_class) {
1881 LOGW("IME_ERROR_INVALID_PARAMETER");
1882 return IME_ERROR_INVALID_PARAMETER;
1885 retVal = _check_privilege();
1886 if (retVal != IME_ERROR_NONE) return retVal;
1889 LOGW("IME_ERROR_NOT_RUNNING");
1890 return IME_ERROR_NOT_RUNNING;
1893 *dev_class = dev_info->dev_class;
1895 return IME_ERROR_NONE;
1898 EXPORT_API int ime_device_info_get_subclass(ime_device_info_h dev_info, Ecore_IMF_Device_Subclass *dev_subclass)
1900 ime_error_e retVal = IME_ERROR_NONE;
1902 if (!dev_info || !dev_subclass) {
1903 LOGW("IME_ERROR_INVALID_PARAMETER");
1904 return IME_ERROR_INVALID_PARAMETER;
1907 retVal = _check_privilege();
1908 if (retVal != IME_ERROR_NONE) return retVal;
1911 LOGW("IME_ERROR_NOT_RUNNING");
1912 return IME_ERROR_NOT_RUNNING;
1915 *dev_subclass = dev_info->dev_subclass;
1917 return IME_ERROR_NONE;
1921 EXPORT_API int ime_event_set_process_input_device_event_cb(ime_process_input_device_event_cb callback_func, void *user_data)
1923 ime_error_e retVal = IME_ERROR_NONE;
1925 if (!callback_func) {
1926 LOGW("IME_ERROR_INVALID_PARAMETER");
1927 return IME_ERROR_INVALID_PARAMETER;
1930 retVal = _check_privilege();
1931 if (retVal != IME_ERROR_NONE) return retVal;
1933 g_event_callback.process_input_device_event = callback_func;
1934 g_event_callback.process_input_device_event_user_data = user_data;
1936 return IME_ERROR_NONE;
1939 EXPORT_API int ime_event_unset_process_input_device_event_cb(void)
1941 ime_error_e retVal = IME_ERROR_NONE;
1943 retVal = _check_privilege();
1944 if (retVal != IME_ERROR_NONE) return retVal;
1946 g_event_callback.process_input_device_event = NULL;
1947 g_event_callback.process_input_device_event_user_data = NULL;
1949 return IME_ERROR_NONE;
1952 /* Functions for Rotary input device event */
1953 EXPORT_API int ime_input_device_rotary_get_direction(ime_input_device_event_h event_handle, ime_input_device_rotary_direction_e *direction)
1955 ime_error_e retVal = IME_ERROR_NONE;
1957 if (!event_handle || !direction) {
1958 LOGW("IME_ERROR_INVALID_PARAMETER");
1959 return IME_ERROR_INVALID_PARAMETER;
1962 ime_device_event_s *device_event = static_cast<ime_device_event_s*>(event_handle);
1963 if (device_event->device_type != IME_INPUT_DEVICE_TYPE_ROTARY) {
1964 LOGW("IME_ERROR_INVALID_PARAMETER");
1965 return IME_ERROR_INVALID_PARAMETER;
1968 retVal = _check_privilege();
1969 if (retVal != IME_ERROR_NONE) return retVal;
1972 LOGW("IME_ERROR_OPERATION_FAILED");
1973 return IME_ERROR_OPERATION_FAILED;
1976 Ecore_Event_Detent_Rotate *rotary_device_event =
1977 static_cast<Ecore_Event_Detent_Rotate*>(device_event->event_data);
1978 if (rotary_device_event) {
1979 if (rotary_device_event->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) {
1980 *direction = IME_INPUT_DEVICE_ROTARY_DIRECTION_CLOCKWISE;
1981 } else if (rotary_device_event->direction == ECORE_DETENT_DIRECTION_COUNTER_CLOCKWISE) {
1982 *direction = IME_INPUT_DEVICE_ROTARY_DIRECTION_COUNTER_CLOCKWISE;
1986 return IME_ERROR_NONE;
1990 EXPORT_API int ime_event_set_prediction_hint_set_cb(ime_prediction_hint_set_cb callback_func, void *user_data)
1992 ime_error_e retVal = IME_ERROR_NONE;
1994 if (!callback_func) {
1995 LOGW("IME_ERROR_INVALID_PARAMETER");
1996 return IME_ERROR_INVALID_PARAMETER;
1999 retVal = _check_privilege();
2000 if (retVal != IME_ERROR_NONE) return retVal;
2002 g_event_callback.prediction_hint_set = callback_func;
2003 g_event_callback.prediction_hint_set_user_data = user_data;
2005 return IME_ERROR_NONE;
2008 EXPORT_API int ime_event_set_mime_type_set_request_cb(ime_mime_type_set_request_cb callback_func, void *user_data)
2010 ime_error_e retVal = IME_ERROR_NONE;
2012 if (!callback_func) {
2013 LOGW("IME_ERROR_INVALID_PARAMETER");
2014 return IME_ERROR_INVALID_PARAMETER;
2017 retVal = _check_privilege();
2018 if (retVal != IME_ERROR_NONE) return retVal;
2020 g_event_callback.mime_type_set = callback_func;
2021 g_event_callback.mime_type_set_user_data = user_data;
2023 return IME_ERROR_NONE;
2026 EXPORT_API int ime_set_floating_mode(bool floating_mode)
2028 ime_error_e retVal = IME_ERROR_NONE;
2030 retVal = _check_privilege();
2031 if (retVal != IME_ERROR_NONE) return retVal;
2034 LOGW("IME_ERROR_NOT_RUNNING");
2035 return IME_ERROR_NOT_RUNNING;
2038 g_core.set_floating_mode(floating_mode);
2040 return IME_ERROR_NONE;
2043 EXPORT_API int ime_set_floating_drag_start(void)
2045 ime_error_e retVal = IME_ERROR_NONE;
2047 retVal = _check_privilege();
2048 if (retVal != IME_ERROR_NONE) return retVal;
2051 LOGW("IME_ERROR_NOT_RUNNING");
2052 return IME_ERROR_NOT_RUNNING;
2055 g_core.set_floating_drag_enabled(true);
2057 return IME_ERROR_NONE;
2060 EXPORT_API int ime_set_floating_drag_end(void)
2062 ime_error_e retVal = IME_ERROR_NONE;
2064 retVal = _check_privilege();
2065 if (retVal != IME_ERROR_NONE) return retVal;
2068 LOGW("IME_ERROR_NOT_RUNNING");
2069 return IME_ERROR_NOT_RUNNING;
2072 g_core.set_floating_drag_enabled(false);
2074 return IME_ERROR_NONE;
2078 EXPORT_API int ime_set_window_creation_defer_flag(bool flag)
2080 ime_error_e retVal = IME_ERROR_NONE;
2082 retVal = _check_privilege();
2083 if (retVal != IME_ERROR_NONE) return retVal;
2085 g_core.set_window_creation_defer_flag(flag);
2087 return IME_ERROR_NONE;
2091 EXPORT_API int ime_event_set_prediction_hint_data_set_cb(ime_prediction_hint_data_set_cb callback_func, void *user_data)
2093 ime_error_e retVal = IME_ERROR_NONE;
2095 if (!callback_func) {
2096 LOGW("IME_ERROR_INVALID_PARAMETER");
2097 return IME_ERROR_INVALID_PARAMETER;
2100 retVal = _check_privilege();
2101 if (retVal != IME_ERROR_NONE) return retVal;
2103 g_event_callback.prediction_hint_data_set = callback_func;
2104 g_event_callback.prediction_hint_data_set_user_data = user_data;
2106 return IME_ERROR_NONE;
2110 EXPORT_API int ime_event_set_optimization_hint_set_cb(ime_optimization_hint_set_cb callback_func, void *user_data)
2113 ime_error_e retVal = IME_ERROR_NONE;
2115 if (!callback_func) {
2116 LOGW("IME_ERROR_INVALID_PARAMETER");
2117 return IME_ERROR_INVALID_PARAMETER;
2121 retVal = _check_privilege();
2122 if (retVal != IME_ERROR_NONE) return retVal;
2125 g_event_callback.optimization_hint_set = callback_func;
2126 g_event_callback.optimization_hint_set_user_data = user_data;
2128 return IME_ERROR_NONE;
2132 EXPORT_API int ime_update_input_panel_event(ime_event_type_e type, unsigned int value)
2134 ime_error_e retVal = IME_ERROR_NONE;
2136 if (type < IME_EVENT_TYPE_LANGUAGE || type > IME_EVENT_TYPE_GEOMETRY) {
2137 LOGW("IME_ERROR_INVALID_PARAMETER");
2138 return IME_ERROR_INVALID_PARAMETER;
2142 LOGW("IME_ERROR_NOT_RUNNING");
2143 return IME_ERROR_NOT_RUNNING;
2146 retVal = _check_privilege();
2147 if (retVal != IME_ERROR_NONE) return retVal;
2149 g_core.update_input_context((sclu32)type, value);
2151 return IME_ERROR_NONE;
2154 EXPORT_API int ime_set_candidate_visibility_state(bool visible)
2156 ime_error_e retVal = IME_ERROR_NONE;
2159 LOGW("IME_ERROR_NOT_RUNNING");
2160 return IME_ERROR_NOT_RUNNING;
2163 retVal = _check_privilege();
2164 if (retVal != IME_ERROR_NONE) return retVal;
2167 g_core.show_candidate_string();
2169 g_core.hide_candidate_string();
2171 return IME_ERROR_NONE;