d379d93c76333ab1bf5d1b5d112f90cda5f14423
[platform/core/api/inputmethod.git] / inputmethod / src / inputmethod.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <vector>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <dlog.h>
22 #include <sclcore.h>
23 #include <unistd.h>
24 #include <privilege_checker_private.h>
25 #include "inputmethod_private.h"
26 #include <inputmethod.h>
27 #include "inputmethod_internal.h"
28
29 using namespace std;
30
31 #ifdef LOG_TAG
32 #undef LOG_TAG
33 #endif
34 #define LOG_TAG "INPUTMETHOD"
35
36 using namespace scl;
37
38 class CCoreEventCallback : public ISCLCoreEventCallback
39 {
40     void on_init();
41     void on_run(int argc, char **argv);
42     void on_exit();
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);
75 };
76
77 typedef struct
78 {
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;
138
139 typedef struct {
140     ime_input_device_type_e device_type;
141     void *event_data;
142 } ime_device_event_s;
143
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;
148
149 static CCoreEventCallback g_core_event_callback;
150 CSCLCore g_core(&g_core_event_callback);
151
152 static bool g_checked_privilege = false;
153 static bool g_permission_allowed = false;
154
155 extern "C" {
156     extern void ime_app_main(int argc, char **argv);
157 }
158
159 //LCOV_EXCL_START
160 void CCoreEventCallback::on_init()
161 {
162     if (g_basic_callback.create) {
163         g_basic_callback.create(g_user_data);
164     }
165 }
166
167 void CCoreEventCallback::on_run(int argc, char **argv)
168 {
169     LOGD("on_run");
170     ime_app_main(argc, argv);
171 }
172
173 void CCoreEventCallback::on_exit()
174 {
175     LOGD("on_exit");
176     if (g_basic_callback.terminate) {
177         g_basic_callback.terminate(g_user_data);
178     }
179 }
180
181 void CCoreEventCallback::on_update_cursor_position(sclint ic, const sclchar *ic_uuid, sclint cursor_pos)
182 {
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);
185     }
186 }
187
188 void CCoreEventCallback::on_update_surrounding_text(sclint ic, const sclchar *text, sclint cursor)
189 {
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);
192     }
193 }
194
195 void CCoreEventCallback::on_focus_out(sclint ic, const sclchar *ic_uuid)
196 {
197     if (g_event_callback.focus_out) {
198         g_event_callback.focus_out(ic, g_event_callback.focus_out_user_data);
199     }
200 }
201
202 void CCoreEventCallback::on_focus_in(sclint ic, const sclchar *ic_uuid)
203 {
204     if (g_event_callback.focus_in) {
205         g_event_callback.focus_in(ic, g_event_callback.focus_in_user_data);
206     }
207 }
208
209 void CCoreEventCallback::on_ise_show(sclint ic, const int degree, Ise_Context &context)
210 {
211     if (g_basic_callback.show) {
212         struct _ime_context input_context;
213
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;
229
230         g_basic_callback.show(ic, static_cast<ime_context_h>(&input_context), g_user_data);
231     }
232 }
233
234 void CCoreEventCallback::on_ise_hide(sclint ic, const sclchar *ic_uuid)
235 {
236     if (g_basic_callback.hide) {
237         g_basic_callback.hide(ic, g_user_data);
238     }
239 }
240
241 void CCoreEventCallback::on_get_geometry(sclu32 *pos_x, sclu32 *pos_y, sclu32 *width, sclu32 *height)
242 {
243     int geometry_pos_x = 0;
244     int geometry_pos_y = 0;
245     int geometry_width = 0;
246     int geometry_height = 0;
247
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);
250     }
251
252     if (pos_x)
253         *pos_x = geometry_pos_x;
254
255     if (pos_y)
256         *pos_y = geometry_pos_y;
257
258     if (width)
259         *width = geometry_width;
260
261     if (height)
262         *height = geometry_height;
263 }
264
265 void CCoreEventCallback::on_set_language(sclu32 language)
266 {
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);
269     }
270 }
271
272 void CCoreEventCallback::on_set_imdata(sclchar *buf, sclu32 len)
273 {
274     if (g_event_callback.imdata_set) {
275         g_event_callback.imdata_set((void *)buf, len, g_event_callback.imdata_set_user_data);
276     }
277 }
278
279 void CCoreEventCallback::on_get_imdata(sclchar **buf, sclu32 *len)
280 {
281     if (g_event_callback.imdata_requested) {
282         g_event_callback.imdata_requested(g_event_callback.imdata_set_user_data, (void **)buf, len);
283     }
284 }
285
286 void CCoreEventCallback::on_get_language_locale(sclint ic, sclchar **locale)
287 {
288     if (g_event_callback.language_requested) {
289         g_event_callback.language_requested(g_event_callback.language_requested_user_data, locale);
290     }
291 }
292
293 void CCoreEventCallback::on_set_return_key_type(sclu32 type)
294 {
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);
297     }
298 }
299
300 void CCoreEventCallback::on_set_return_key_disable(sclu32 disabled)
301 {
302     bool return_key_disabled = !!disabled;
303
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);
306     }
307 }
308
309 void CCoreEventCallback::on_set_layout(sclu32 layout)
310 {
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);
313     }
314 }
315
316 void CCoreEventCallback::on_reset_input_context(sclint ic, const sclchar *uuid)
317 {
318     if (g_event_callback.input_context_reset) {
319         g_event_callback.input_context_reset(g_event_callback.input_context_reset_user_data);
320     }
321 }
322
323 void CCoreEventCallback::on_process_key_event(scim::KeyEvent &key, sclu32 *ret)
324 {
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);
330
331         if (ret) {
332             if (processed)
333                 *ret = 1;
334             else
335                 *ret = 0;
336         }
337     } else {
338         if (ret) {
339             *ret = 0;
340         }
341     }
342 }
343
344 void CCoreEventCallback::on_process_key_event_with_keycode(scim::KeyEvent &key, sclu32 *ret, sclu32 keycode)
345 {
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);
351
352         if (ret) {
353             if (processed)
354                 *ret = 1;
355             else
356                 *ret = 0;
357         }
358     } else {
359         if (ret) {
360             *ret = 0;
361         }
362     }
363 }
364
365 void CCoreEventCallback::on_set_display_language(const sclchar *language)
366 {
367     if (g_event_callback.display_language_changed) {
368         g_event_callback.display_language_changed(language, g_event_callback.display_language_changed_user_data);
369     }
370 }
371
372 void CCoreEventCallback::on_set_rotation_degree(sclint degree)
373 {
374     if (g_event_callback.rotation_degree_changed) {
375         g_event_callback.rotation_degree_changed(degree, g_event_callback.rotation_degree_changed_user_data);
376     }
377 }
378
379 void CCoreEventCallback::on_set_accessibility_state(sclboolean state)
380 {
381     if (g_event_callback.accessibility_state_changed) {
382         g_event_callback.accessibility_state_changed(state, g_event_callback.accessibility_state_changed_user_data);
383     }
384 }
385
386 void CCoreEventCallback::on_create_option_window(sclwindow window, SCLOptionWindowType type)
387 {
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);
390     }
391 }
392
393 void CCoreEventCallback::on_destroy_option_window(sclwindow window)
394 {
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);
397     }
398 }
399
400 void CCoreEventCallback::on_check_option_window_availability(sclboolean *ret)
401 {
402     if (ret) {
403         if (g_event_callback.option_window_created) // Instead of each 3rd party keyboard, inputmethod will reply the availability of the option (setting).
404             *ret = true;
405         else
406             *ret = false;
407     }
408 }
409
410 void CCoreEventCallback::on_set_caps_mode(sclu32 mode)
411 {
412     if (g_event_callback.caps_mode_changed) {
413         g_event_callback.caps_mode_changed(mode, g_event_callback.caps_mode_changed_user_data);
414     }
415 }
416
417 void CCoreEventCallback::on_candidate_show(sclint ic, const sclchar *ic_uuid)
418 {
419     if (g_event_callback.candidate_show) {
420         g_event_callback.candidate_show(ic, g_event_callback.candidate_show_user_data);
421     }
422 }
423
424 void CCoreEventCallback::on_candidate_hide(sclint ic, const sclchar *ic_uuid)
425 {
426     if (g_event_callback.candidate_hide) {
427         g_event_callback.candidate_hide(ic, g_event_callback.candidate_hide_user_data);
428     }
429 }
430
431 void CCoreEventCallback::on_update_lookup_table(SclCandidateTable &table)
432 {
433     Eina_List *string_list = NULL;
434
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());
439         }
440
441         g_event_callback.lookup_table_changed(string_list, g_event_callback.lookup_table_changed_user_data);
442     }
443 }
444
445 void CCoreEventCallback::on_process_input_device_event(sclu32 &type, sclchar *data, size_t &len, sclu32 *ret)
446 {
447     typedef struct {
448         int ecore_event_id;
449         ime_input_device_type_e device_type;
450     } ime_device_type_conv_table;
451
452     ime_device_type_conv_table conv_table[] = {
453         { ECORE_EVENT_DETENT_ROTATE , IME_INPUT_DEVICE_TYPE_ROTARY },
454     };
455
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;
460         }
461     }
462
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;
469
470         g_event_callback.process_input_device_event(device_type, input_data, user_data);
471
472         if (ret) {
473             *ret = 1;
474         }
475     } else {
476         if (ret) {
477             *ret = 0;
478         }
479     }
480 }
481
482 void CCoreEventCallback::on_set_prediction_hint(const sclchar *prediction_hint)
483 {
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);
486     }
487 }
488
489 void CCoreEventCallback::on_set_mime_type(const sclchar *mime_type)
490 {
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);
493     }
494 }
495
496 void CCoreEventCallback::on_set_prediction_hint_data(const sclchar *key, const sclchar *value)
497 {
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);
500     }
501 }
502
503 void CCoreEventCallback::on_set_optimization_hint(sclu32 hint)
504 {
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);
507     }
508 }
509
510 void ime_privilege_cache_init()
511 {
512     g_permission_allowed = false;
513     g_checked_privilege = false;
514 }
515 //LCOV_EXCL_STOP
516
517 ime_error_e _check_privilege()
518 {
519     char uid[16];
520     ime_error_e ret = IME_ERROR_NONE;
521
522     if (g_checked_privilege) {
523         return g_permission_allowed ? IME_ERROR_NONE : IME_ERROR_PERMISSION_DENIED;
524     }
525
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;
531     }
532
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;
537     }
538
539     g_permission_allowed = (ret == IME_ERROR_NONE);
540     g_checked_privilege = true;
541
542     inputmethod_cynara_finish();
543
544     return ret;
545 }
546
547 //LCOV_EXCL_START
548 bool g_from_dotnet = false;
549 EXPORT_API int ime_set_dotnet_flag(bool set)
550 {
551     ime_error_e retVal = IME_ERROR_NONE;
552
553     retVal = _check_privilege();
554     if (retVal != IME_ERROR_NONE) return retVal;
555
556     g_from_dotnet = set;
557
558     return retVal;
559 }
560 //LCOV_EXCL_STOP
561
562 EXPORT_API int ime_run(ime_callback_s *basic_cb, void *user_data)
563 {
564     ime_error_e retVal = IME_ERROR_NONE;
565
566     if (g_running) {
567         LOGE("inputmethod main loop is already running.");
568         return IME_ERROR_OPERATION_FAILED;
569     }
570
571     if (!basic_cb) {
572         LOGE("basic callbacks pointer is null.");
573         return IME_ERROR_INVALID_PARAMETER;
574     }
575
576     retVal = _check_privilege();
577     if (retVal != IME_ERROR_NONE) return retVal;
578
579     g_basic_callback = *basic_cb;
580
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;
587     }
588
589     g_user_data = user_data;
590     g_running = true;
591
592     if (g_from_dotnet) {
593         LOGD("ime_run is called from dotnet");
594         return IME_ERROR_NONE;
595     }
596
597     try {
598         g_core.run();
599     } catch (...) {
600         LOGW("exception is thrown from g_core.run()\n");
601     }
602
603     memset(&g_basic_callback, 0, sizeof(ime_callback_s));
604     memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
605     g_user_data = NULL;
606     g_running = false;
607
608     return IME_ERROR_NONE;
609 }
610
611 EXPORT_API int ime_event_set_focus_in_cb(ime_focus_in_cb callback_func, void *user_data)
612 {
613     ime_error_e retVal = IME_ERROR_NONE;
614
615     if (!callback_func) {
616         LOGW("IME_ERROR_INVALID_PARAMETER");
617         return IME_ERROR_INVALID_PARAMETER;
618     }
619
620     retVal = _check_privilege();
621     if (retVal != IME_ERROR_NONE) return retVal;
622
623     g_event_callback.focus_in = callback_func;
624     g_event_callback.focus_in_user_data = user_data;
625
626     return IME_ERROR_NONE;
627 }
628
629 EXPORT_API int ime_event_set_focus_out_cb(ime_focus_out_cb callback_func, void *user_data)
630 {
631     ime_error_e retVal = IME_ERROR_NONE;
632
633     if (!callback_func) {
634         LOGW("IME_ERROR_INVALID_PARAMETER");
635         return IME_ERROR_INVALID_PARAMETER;
636     }
637
638     retVal = _check_privilege();
639     if (retVal != IME_ERROR_NONE) return retVal;
640
641     g_event_callback.focus_out = callback_func;
642     g_event_callback.focus_out_user_data = user_data;
643
644     return IME_ERROR_NONE;
645 }
646
647 EXPORT_API int ime_event_set_surrounding_text_updated_cb(ime_surrounding_text_updated_cb callback_func, void *user_data)
648 {
649     ime_error_e retVal = IME_ERROR_NONE;
650
651     if (!callback_func) {
652         LOGW("IME_ERROR_INVALID_PARAMETER");
653         return IME_ERROR_INVALID_PARAMETER;
654     }
655
656     retVal = _check_privilege();
657     if (retVal != IME_ERROR_NONE) return retVal;
658
659     g_event_callback.surrounding_text_updated = callback_func;
660     g_event_callback.surrounding_text_updated_user_data = user_data;
661
662     return IME_ERROR_NONE;
663 }
664
665 EXPORT_API int ime_event_set_input_context_reset_cb(ime_input_context_reset_cb callback_func, void *user_data)
666 {
667     ime_error_e retVal = IME_ERROR_NONE;
668
669     if (!callback_func) {
670         LOGW("IME_ERROR_INVALID_PARAMETER");
671         return IME_ERROR_INVALID_PARAMETER;
672     }
673
674     retVal = _check_privilege();
675     if (retVal != IME_ERROR_NONE) return retVal;
676
677     g_event_callback.input_context_reset = callback_func;
678     g_event_callback.input_context_reset_user_data = user_data;
679
680     return IME_ERROR_NONE;
681 }
682
683 EXPORT_API int ime_event_set_cursor_position_updated_cb(ime_cursor_position_updated_cb callback_func, void *user_data)
684 {
685     ime_error_e retVal = IME_ERROR_NONE;
686
687     if (!callback_func) {
688         LOGW("IME_ERROR_INVALID_PARAMETER");
689         return IME_ERROR_INVALID_PARAMETER;
690     }
691
692     retVal = _check_privilege();
693     if (retVal != IME_ERROR_NONE) return retVal;
694
695     g_event_callback.cursor_position_updated = callback_func;
696     g_event_callback.cursor_position_updated_user_data = user_data;
697
698     return IME_ERROR_NONE;
699 }
700
701 EXPORT_API int ime_event_set_language_requested_cb(ime_language_requested_cb callback_func, void *user_data)
702 {
703     ime_error_e retVal = IME_ERROR_NONE;
704
705     if (!callback_func) {
706         LOGW("IME_ERROR_INVALID_PARAMETER");
707         return IME_ERROR_INVALID_PARAMETER;
708     }
709
710     retVal = _check_privilege();
711     if (retVal != IME_ERROR_NONE) return retVal;
712
713     g_event_callback.language_requested = callback_func;
714     g_event_callback.language_requested_user_data = user_data;
715
716     return IME_ERROR_NONE;
717 }
718
719 EXPORT_API int ime_event_set_language_set_cb(ime_language_set_cb callback_func, void *user_data)
720 {
721     ime_error_e retVal = IME_ERROR_NONE;
722
723     if (!callback_func) {
724         LOGW("IME_ERROR_INVALID_PARAMETER");
725         return IME_ERROR_INVALID_PARAMETER;
726     }
727
728     retVal = _check_privilege();
729     if (retVal != IME_ERROR_NONE) return retVal;
730
731     g_event_callback.language_set = callback_func;
732     g_event_callback.language_set_user_data = user_data;
733
734     return IME_ERROR_NONE;
735 }
736
737 EXPORT_API int ime_event_set_imdata_set_cb(ime_imdata_set_cb callback_func, void *user_data)
738 {
739     ime_error_e retVal = IME_ERROR_NONE;
740
741     if (!callback_func) {
742         LOGW("IME_ERROR_INVALID_PARAMETER");
743         return IME_ERROR_INVALID_PARAMETER;
744     }
745
746     retVal = _check_privilege();
747     if (retVal != IME_ERROR_NONE) return retVal;
748
749     g_event_callback.imdata_set = callback_func;
750     g_event_callback.imdata_set_user_data = user_data;
751
752     return IME_ERROR_NONE;
753 }
754
755 EXPORT_API int ime_event_set_imdata_requested_cb(ime_imdata_requested_cb callback_func, void *user_data)
756 {
757     ime_error_e retVal = IME_ERROR_NONE;
758
759     if (!callback_func) {
760         LOGW("IME_ERROR_INVALID_PARAMETER");
761         return IME_ERROR_INVALID_PARAMETER;
762     }
763
764     retVal = _check_privilege();
765     if (retVal != IME_ERROR_NONE) return retVal;
766
767     g_event_callback.imdata_requested = callback_func;
768     g_event_callback.imdata_requested_user_data = user_data;
769
770     return IME_ERROR_NONE;
771 }
772
773 EXPORT_API int ime_event_set_layout_set_cb(ime_layout_set_cb callback_func, void *user_data)
774 {
775     ime_error_e retVal = IME_ERROR_NONE;
776
777     if (!callback_func) {
778         LOGW("IME_ERROR_INVALID_PARAMETER");
779         return IME_ERROR_INVALID_PARAMETER;
780     }
781
782     retVal = _check_privilege();
783     if (retVal != IME_ERROR_NONE) return retVal;
784
785     g_event_callback.layout_set = callback_func;
786     g_event_callback.layout_set_user_data = user_data;
787
788     return IME_ERROR_NONE;
789 }
790
791 EXPORT_API int ime_event_set_return_key_type_set_cb(ime_return_key_type_set_cb callback_func, void *user_data)
792 {
793     ime_error_e retVal = IME_ERROR_NONE;
794
795     if (!callback_func) {
796         LOGW("IME_ERROR_INVALID_PARAMETER");
797         return IME_ERROR_INVALID_PARAMETER;
798     }
799
800     retVal = _check_privilege();
801     if (retVal != IME_ERROR_NONE) return retVal;
802
803     g_event_callback.return_key_type_set = callback_func;
804     g_event_callback.return_key_type_set_user_data = user_data;
805
806     return IME_ERROR_NONE;
807 }
808
809 EXPORT_API int ime_event_set_return_key_state_set_cb(ime_return_key_state_set_cb callback_func, void *user_data)
810 {
811     ime_error_e retVal = IME_ERROR_NONE;
812
813     if (!callback_func) {
814         LOGW("IME_ERROR_INVALID_PARAMETER");
815         return IME_ERROR_INVALID_PARAMETER;
816     }
817
818     retVal = _check_privilege();
819     if (retVal != IME_ERROR_NONE) return retVal;
820
821     g_event_callback.return_key_state_set = callback_func;
822     g_event_callback.return_key_state_set_user_data = user_data;
823
824     return IME_ERROR_NONE;
825 }
826
827 EXPORT_API int ime_event_set_geometry_requested_cb(ime_geometry_requested_cb callback_func, void *user_data)
828 {
829     ime_error_e retVal = IME_ERROR_NONE;
830
831     if (!callback_func) {
832         LOGW("IME_ERROR_INVALID_PARAMETER");
833         return IME_ERROR_INVALID_PARAMETER;
834     }
835
836     retVal = _check_privilege();
837     if (retVal != IME_ERROR_NONE) return retVal;
838
839     g_event_callback.geometry_requested = callback_func;
840     g_event_callback.geometry_requested_user_data = user_data;
841
842     return IME_ERROR_NONE;
843 }
844
845 EXPORT_API int ime_event_set_process_key_event_cb(ime_process_key_event_cb callback_func, void *user_data)
846 {
847     ime_error_e retVal = IME_ERROR_NONE;
848
849     if (!callback_func) {
850         LOGW("IME_ERROR_INVALID_PARAMETER");
851         return IME_ERROR_INVALID_PARAMETER;
852     }
853
854     retVal = _check_privilege();
855     if (retVal != IME_ERROR_NONE) return retVal;
856
857     g_event_callback.process_key_event = callback_func;
858     g_event_callback.process_key_event_user_data = user_data;
859
860     return IME_ERROR_NONE;
861 }
862
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)
864 {
865     ime_error_e retVal = IME_ERROR_NONE;
866
867     if (!callback_func) {
868         LOGW("IME_ERROR_INVALID_PARAMETER");
869         return IME_ERROR_INVALID_PARAMETER;
870     }
871
872     retVal = _check_privilege();
873     if (retVal != IME_ERROR_NONE) return retVal;
874
875     g_event_callback.process_key_event_with_keycode = callback_func;
876     g_event_callback.process_key_event_with_keycode_user_data = user_data;
877
878     return IME_ERROR_NONE;
879 }
880
881 EXPORT_API int ime_event_set_display_language_changed_cb(ime_display_language_changed_cb callback_func, void *user_data)
882 {
883     ime_error_e retVal = IME_ERROR_NONE;
884
885     if (!callback_func) {
886         LOGW("IME_ERROR_INVALID_PARAMETER");
887         return IME_ERROR_INVALID_PARAMETER;
888     }
889
890     retVal = _check_privilege();
891     if (retVal != IME_ERROR_NONE) return retVal;
892
893     g_event_callback.display_language_changed = callback_func;
894     g_event_callback.display_language_changed_user_data = user_data;
895
896     return IME_ERROR_NONE;
897 }
898
899 EXPORT_API int ime_event_set_rotation_degree_changed_cb(ime_rotation_degree_changed_cb callback_func, void *user_data)
900 {
901     ime_error_e retVal = IME_ERROR_NONE;
902
903     if (!callback_func) {
904         LOGW("IME_ERROR_INVALID_PARAMETER");
905         return IME_ERROR_INVALID_PARAMETER;
906     }
907
908     retVal = _check_privilege();
909     if (retVal != IME_ERROR_NONE) return retVal;
910
911     g_event_callback.rotation_degree_changed = callback_func;
912     g_event_callback.rotation_degree_changed_user_data = user_data;
913
914     return IME_ERROR_NONE;
915 }
916
917 EXPORT_API int ime_event_set_accessibility_state_changed_cb(ime_accessibility_state_changed_cb callback_func, void *user_data)
918 {
919     ime_error_e retVal = IME_ERROR_NONE;
920
921     if (!callback_func) {
922         LOGW("IME_ERROR_INVALID_PARAMETER");
923         return IME_ERROR_INVALID_PARAMETER;
924     }
925
926     retVal = _check_privilege();
927     if (retVal != IME_ERROR_NONE) return retVal;
928
929     g_event_callback.accessibility_state_changed = callback_func;
930     g_event_callback.accessibility_state_changed_user_data = user_data;
931
932     return IME_ERROR_NONE;
933 }
934
935 EXPORT_API int ime_event_set_option_window_created_cb(ime_option_window_created_cb callback_func, void *user_data)
936 {
937     ime_error_e retVal = IME_ERROR_NONE;
938
939     if (!callback_func) {
940         LOGW("IME_ERROR_INVALID_PARAMETER");
941         return IME_ERROR_INVALID_PARAMETER;
942     }
943
944     retVal = _check_privilege();
945     if (retVal != IME_ERROR_NONE) return retVal;
946
947     g_event_callback.option_window_created = callback_func;
948     g_event_callback.option_window_created_user_data = user_data;
949
950     return IME_ERROR_NONE;
951 }
952
953 EXPORT_API int ime_event_set_option_window_destroyed_cb(ime_option_window_destroyed_cb callback_func, void *user_data)
954 {
955     ime_error_e retVal = IME_ERROR_NONE;
956
957     if (!callback_func) {
958         LOGW("IME_ERROR_INVALID_PARAMETER");
959         return IME_ERROR_INVALID_PARAMETER;
960     }
961
962     retVal = _check_privilege();
963     if (retVal != IME_ERROR_NONE) return retVal;
964
965     g_event_callback.option_window_destroyed = callback_func;
966     g_event_callback.option_window_destroyed_user_data = user_data;
967
968     return IME_ERROR_NONE;
969 }
970
971 //LCOV_EXCL_START
972 EXPORT_API int ime_event_set_caps_mode_changed_cb(ime_caps_mode_changed_cb callback_func, void *user_data)
973 {
974     ime_error_e retVal = IME_ERROR_NONE;
975
976     if (!callback_func) {
977         LOGW("IME_ERROR_INVALID_PARAMETER");
978         return IME_ERROR_INVALID_PARAMETER;
979     }
980
981     retVal = _check_privilege();
982     if (retVal != IME_ERROR_NONE) return retVal;
983
984     g_event_callback.caps_mode_changed = callback_func;
985     g_event_callback.caps_mode_changed_user_data = user_data;
986
987     return IME_ERROR_NONE;
988 }
989
990 EXPORT_API int ime_event_set_candidate_show_cb(ime_candidate_show_cb callback_func, void *user_data)
991 {
992     ime_error_e retVal = IME_ERROR_NONE;
993
994     if (!callback_func) {
995         LOGW("IME_ERROR_INVALID_PARAMETER");
996         return IME_ERROR_INVALID_PARAMETER;
997     }
998
999     retVal = _check_privilege();
1000     if (retVal != IME_ERROR_NONE) return retVal;
1001
1002     g_event_callback.candidate_show = callback_func;
1003     g_event_callback.candidate_show_user_data = user_data;
1004
1005     return IME_ERROR_NONE;
1006 }
1007
1008 EXPORT_API int ime_event_set_candidate_hide_cb(ime_candidate_hide_cb callback_func, void *user_data)
1009 {
1010     ime_error_e retVal = IME_ERROR_NONE;
1011
1012     if (!callback_func) {
1013         LOGW("IME_ERROR_INVALID_PARAMETER");
1014         return IME_ERROR_INVALID_PARAMETER;
1015     }
1016
1017     retVal = _check_privilege();
1018     if (retVal != IME_ERROR_NONE) return retVal;
1019
1020     g_event_callback.candidate_hide = callback_func;
1021     g_event_callback.candidate_hide_user_data = user_data;
1022
1023     return IME_ERROR_NONE;
1024 }
1025
1026 EXPORT_API int ime_event_set_lookup_table_changed_cb(ime_lookup_table_changed_cb callback_func, void *user_data)
1027 {
1028     ime_error_e retVal = IME_ERROR_NONE;
1029
1030     if (!callback_func) {
1031         LOGW("IME_ERROR_INVALID_PARAMETER");
1032         return IME_ERROR_INVALID_PARAMETER;
1033     }
1034
1035     retVal = _check_privilege();
1036     if (retVal != IME_ERROR_NONE) return retVal;
1037
1038     g_event_callback.lookup_table_changed = callback_func;
1039     g_event_callback.lookup_table_changed_user_data = user_data;
1040
1041     return IME_ERROR_NONE;
1042 }
1043 //LCOV_EXCL_STOP
1044
1045 EXPORT_API int ime_send_key_event(ime_key_code_e keycode, ime_key_mask_e keymask, bool forward_key)
1046 {
1047     ime_error_e retVal = IME_ERROR_NONE;
1048
1049     if (!g_running) {
1050         LOGW("IME_ERROR_NOT_RUNNING");
1051         return IME_ERROR_NOT_RUNNING;
1052     }
1053
1054     retVal = _check_privilege();
1055     if (retVal != IME_ERROR_NONE) return retVal;
1056
1057     if (forward_key)
1058         g_core.forward_key_event(-1, NULL, (sclu32)keycode, (sclu16)keymask);
1059     else
1060         g_core.send_key_event(-1, NULL, (sclu32)keycode, (sclu16)keymask);
1061
1062     return IME_ERROR_NONE;
1063 }
1064
1065 EXPORT_API int ime_commit_string(const char *str)
1066 {
1067     ime_error_e retVal = IME_ERROR_NONE;
1068
1069     if (!str) {
1070         LOGW("IME_ERROR_INVALID_PARAMETER");
1071         return IME_ERROR_INVALID_PARAMETER;
1072     }
1073
1074     if (!g_running) {
1075         LOGW("IME_ERROR_NOT_RUNNING");
1076         return IME_ERROR_NOT_RUNNING;
1077     }
1078
1079     retVal = _check_privilege();
1080     if (retVal != IME_ERROR_NONE) return retVal;
1081
1082     SECURE_LOGI("commit string : %s", str);
1083     g_core.commit_string(-1, NULL, str);
1084
1085     return IME_ERROR_NONE;
1086 }
1087
1088 EXPORT_API int ime_show_preedit_string(void)
1089 {
1090     ime_error_e retVal = IME_ERROR_NONE;
1091
1092     if (!g_running) {
1093         LOGW("IME_ERROR_NOT_RUNNING");
1094         return IME_ERROR_NOT_RUNNING;
1095     }
1096
1097     retVal = _check_privilege();
1098     if (retVal != IME_ERROR_NONE) return retVal;
1099
1100     g_core.show_preedit_string(-1, NULL);
1101
1102     return IME_ERROR_NONE;
1103 }
1104
1105 EXPORT_API int ime_hide_preedit_string(void)
1106 {
1107     ime_error_e retVal = IME_ERROR_NONE;
1108
1109     if (!g_running) {
1110         LOGW("IME_ERROR_NOT_RUNNING");
1111         return IME_ERROR_NOT_RUNNING;
1112     }
1113
1114     retVal = _check_privilege();
1115     if (retVal != IME_ERROR_NONE) return retVal;
1116
1117     g_core.hide_preedit_string(-1, NULL);
1118
1119     return IME_ERROR_NONE;
1120 }
1121
1122 EXPORT_API int ime_update_preedit_string(const char *str, Eina_List *attrs)
1123 {
1124     ime_error_e retVal = IME_ERROR_NONE;
1125
1126     if (!str) {
1127         LOGW("IME_ERROR_INVALID_PARAMETER");
1128         return IME_ERROR_INVALID_PARAMETER;
1129     }
1130
1131     if (!g_running) {
1132         LOGW("IME_ERROR_NOT_RUNNING");
1133         return IME_ERROR_NOT_RUNNING;
1134     }
1135
1136     retVal = _check_privilege();
1137     if (retVal != IME_ERROR_NONE) return retVal;
1138
1139     scim::AttributeList attrv;
1140     void *data = NULL;
1141     ime_preedit_attribute *attr = NULL;
1142
1143     if (attrs) {
1144         EINA_LIST_FREE(attrs, data) {
1145             attr = (ime_preedit_attribute *)data;
1146             if (attr) {
1147                 attrv.push_back(scim::Attribute(attr->start, attr->length, (scim::AttributeType)attr->type, attr->value));
1148                 free(attr);
1149             }
1150         }
1151     }
1152
1153     SECURE_LOGI("preedit string : '%s'", str);
1154     g_core.update_preedit_string(-1, NULL, str, attrv);
1155
1156     return IME_ERROR_NONE;
1157 }
1158
1159 EXPORT_API int ime_request_surrounding_text(int maxlen_before, int maxlen_after)
1160 {
1161     ime_error_e retVal = IME_ERROR_NONE;
1162
1163     if (!g_event_callback.surrounding_text_updated) {
1164         LOGW("IME_ERROR_NO_CALLBACK_FUNCTION");
1165         return IME_ERROR_NO_CALLBACK_FUNCTION;
1166     }
1167
1168     if (!g_running) {
1169         LOGW("IME_ERROR_NOT_RUNNING");
1170         return IME_ERROR_NOT_RUNNING;
1171     }
1172
1173     retVal = _check_privilege();
1174     if (retVal != IME_ERROR_NONE) return retVal;
1175
1176     g_core.get_surrounding_text(NULL, maxlen_before, maxlen_after);
1177
1178     return IME_ERROR_NONE;
1179 }
1180
1181 EXPORT_API int ime_delete_surrounding_text(int offset, int len)
1182 {
1183     ime_error_e retVal = IME_ERROR_NONE;
1184
1185     if (len <= 0) {
1186         LOGW("IME_ERROR_INVALID_PARAMETER");
1187         return IME_ERROR_INVALID_PARAMETER;
1188     }
1189
1190     if (!g_running) {
1191         LOGW("IME_ERROR_NOT_RUNNING");
1192         return IME_ERROR_NOT_RUNNING;
1193     }
1194
1195     retVal = _check_privilege();
1196     if (retVal != IME_ERROR_NONE) return retVal;
1197
1198     LOGI("offset: %d, len : %d", offset, len);
1199     g_core.delete_surrounding_text(offset, len);
1200
1201     return IME_ERROR_NONE;
1202 }
1203
1204 EXPORT_API int ime_get_surrounding_text(int maxlen_before, int maxlen_after, char **text, int *cursor_pos)
1205 {
1206     ime_error_e retVal = IME_ERROR_NONE;
1207
1208     if (!text || !cursor_pos) {
1209         LOGW("IME_ERROR_INVALID_PARAMETER");
1210         return IME_ERROR_INVALID_PARAMETER;
1211     }
1212
1213     if (!g_running) {
1214         LOGW("IME_ERROR_NOT_RUNNING");
1215         return IME_ERROR_NOT_RUNNING;
1216     }
1217
1218     retVal = _check_privilege();
1219     if (retVal != IME_ERROR_NONE) return retVal;
1220
1221     int cursor = 0;
1222
1223     int ret = g_core.get_surrounding_text(maxlen_before, maxlen_after, text, cursor);
1224     if (ret == -1) {
1225         LOGW("IME_ERROR_OUR_OF_MEMORY");
1226         return IME_ERROR_OUT_OF_MEMORY;
1227     }
1228
1229     if (cursor_pos)
1230         *cursor_pos = cursor;
1231
1232     return IME_ERROR_NONE;
1233 }
1234
1235 EXPORT_API int ime_set_selection(int start, int end)
1236 {
1237     ime_error_e retVal = IME_ERROR_NONE;
1238
1239     if (start < 0) {
1240         LOGW("IME_ERROR_INVALID_PARAMETER");
1241         return IME_ERROR_INVALID_PARAMETER;
1242     }
1243
1244     if (!g_running) {
1245         LOGW("IME_ERROR_NOT_RUNNING");
1246         return IME_ERROR_NOT_RUNNING;
1247     }
1248
1249     retVal = _check_privilege();
1250     if (retVal != IME_ERROR_NONE) return retVal;
1251
1252     LOGI("start: %d, end : %d", start, end);
1253     g_core.set_selection(start, end);
1254
1255     return IME_ERROR_NONE;
1256 }
1257
1258 EXPORT_API int ime_get_selected_text(char **text)
1259 {
1260     ime_error_e retVal = IME_ERROR_NONE;
1261
1262     if (!text) {
1263         LOGW("IME_ERROR_INVALID_PARAMETER");
1264         return IME_ERROR_INVALID_PARAMETER;
1265     }
1266
1267     if (!g_running) {
1268         LOGW("IME_ERROR_NOT_RUNNING");
1269         return IME_ERROR_NOT_RUNNING;
1270     }
1271
1272     retVal = _check_privilege();
1273     if (retVal != IME_ERROR_NONE) return retVal;
1274
1275     g_core.get_selection_text(text);
1276
1277     return IME_ERROR_NONE;
1278 }
1279
1280 EXPORT_API Evas_Object* ime_get_main_window(void)
1281 {
1282     ime_error_e retVal = IME_ERROR_NONE;
1283
1284     Evas_Object *win = NULL;
1285
1286     retVal = _check_privilege();
1287     if (retVal != IME_ERROR_NONE) {
1288         LOGE("_check_privilege returned %d.", retVal);
1289         set_last_result(retVal);
1290         return NULL;
1291     }
1292
1293     if (!g_running) {
1294         set_last_result(IME_ERROR_NOT_RUNNING);
1295         LOGW("IME_ERROR_NOT_RUNNING");
1296         return NULL;
1297     }
1298
1299     win = static_cast<Evas_Object*>(g_core.get_main_window());
1300     if (win) {
1301         set_last_result(IME_ERROR_NONE);
1302     } else {
1303         set_last_result(IME_ERROR_OPERATION_FAILED);
1304         LOGW("IME_ERROR_OPERATION_FAILED");
1305     }
1306
1307     return win;
1308 }
1309
1310 EXPORT_API int ime_set_size(int portrait_width, int portrait_height, int landscape_width, int landscape_height)
1311 {
1312     ime_error_e retVal = IME_ERROR_NONE;
1313
1314     SclSize portrait_size, landscape_size;
1315
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;
1319     }
1320
1321     if (!g_running) {
1322         LOGW("IME_ERROR_NOT_RUNNING");
1323         return IME_ERROR_NOT_RUNNING;
1324     }
1325
1326     retVal = _check_privilege();
1327     if (retVal != IME_ERROR_NONE) return retVal;
1328
1329     portrait_size.width = portrait_width;
1330     portrait_size.height = portrait_height;
1331
1332     landscape_size.width = landscape_width;
1333     landscape_size.height = landscape_height;
1334
1335     g_core.set_keyboard_size_hints(portrait_size, landscape_size);
1336
1337     return IME_ERROR_NONE;
1338 }
1339
1340 EXPORT_API int ime_create_option_window(void)
1341 {
1342     ime_error_e retVal = IME_ERROR_NONE;
1343
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;
1347     }
1348
1349     if (!g_running) {
1350         LOGW("IME_ERROR_NOT_RUNNING");
1351         return IME_ERROR_NOT_RUNNING;
1352     }
1353
1354     retVal = _check_privilege();
1355     if (retVal != IME_ERROR_NONE) return retVal;
1356
1357     if (g_core.create_option_window()) {
1358         return IME_ERROR_NONE;
1359     } else {
1360         LOGW("IME_ERROR_OPERATION_FAILED");
1361         return IME_ERROR_OPERATION_FAILED;
1362     }
1363 }
1364
1365 EXPORT_API int ime_destroy_option_window(Evas_Object *window)
1366 {
1367     ime_error_e retVal = IME_ERROR_NONE;
1368
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;
1372     }
1373
1374     if (!window) {
1375         LOGW("Window pointer is null.");
1376         return IME_ERROR_INVALID_PARAMETER;
1377     }
1378
1379     if (!g_running) {
1380         LOGW("IME_ERROR_NOT_RUNNING");
1381         return IME_ERROR_NOT_RUNNING;
1382     }
1383
1384     retVal = _check_privilege();
1385     if (retVal != IME_ERROR_NONE) return retVal;
1386
1387     g_core.destroy_option_window(window);
1388
1389     return IME_ERROR_NONE;
1390 }
1391
1392 //LCOV_EXCL_START
1393 EXPORT_API int ime_set_imengine(const char *engine_id)
1394 {
1395     ime_error_e retVal = IME_ERROR_NONE;
1396
1397     if (!engine_id) {
1398         LOGW("IME_ERROR_INVALID_PARAMETER");
1399         return IME_ERROR_INVALID_PARAMETER;
1400     }
1401
1402     retVal = _check_privilege();
1403     if (retVal != IME_ERROR_NONE) return retVal;
1404
1405     g_core.set_keyboard_ise_by_uuid(engine_id);
1406
1407     return IME_ERROR_NONE;
1408 }
1409
1410 EXPORT_API int ime_flush_imengine(void)
1411 {
1412     ime_error_e retVal = IME_ERROR_NONE;
1413
1414     if (!g_running) {
1415         LOGW("IME_ERROR_NOT_RUNNING");
1416         return IME_ERROR_NOT_RUNNING;
1417     }
1418
1419     retVal = _check_privilege();
1420     if (retVal != IME_ERROR_NONE) return retVal;
1421
1422     g_core.flush_keyboard_ise();
1423
1424     return IME_ERROR_NONE;
1425 }
1426
1427 EXPORT_API int ime_send_imengine_event(int command, unsigned int value)
1428 {
1429     ime_error_e retVal = IME_ERROR_NONE;
1430
1431     if (!g_running) {
1432         LOGW("IME_ERROR_NOT_RUNNING");
1433         return IME_ERROR_NOT_RUNNING;
1434     }
1435
1436     retVal = _check_privilege();
1437     if (retVal != IME_ERROR_NONE) return retVal;
1438
1439     g_core.send_imengine_event(-1, NULL, command, value);
1440
1441     return IME_ERROR_NONE;
1442 }
1443
1444 EXPORT_API int ime_reset_imengine(void)
1445 {
1446     ime_error_e retVal = IME_ERROR_NONE;
1447
1448     if (!g_running) {
1449         LOGW("IME_ERROR_NOT_RUNNING");
1450         return IME_ERROR_NOT_RUNNING;
1451     }
1452
1453     retVal = _check_privilege();
1454     if (retVal != IME_ERROR_NONE) return retVal;
1455
1456     g_core.reset_keyboard_ise();
1457
1458     return IME_ERROR_NONE;
1459 }
1460
1461 EXPORT_API int ime_update_input_context(unsigned int type, unsigned int value)
1462 {
1463     ime_error_e retVal = IME_ERROR_NONE;
1464
1465     if (!g_running) {
1466         LOGW("IME_ERROR_NOT_RUNNING");
1467         return IME_ERROR_NOT_RUNNING;
1468     }
1469
1470     retVal = _check_privilege();
1471     if (retVal != IME_ERROR_NONE) return retVal;
1472
1473     g_core.update_input_context(type, value);
1474
1475     return IME_ERROR_NONE;
1476 }
1477 //LCOV_EXCL_STOP
1478
1479 EXPORT_API int ime_request_hide(void)
1480 {
1481     ime_error_e retVal = IME_ERROR_NONE;
1482
1483     if (!g_running) {
1484         LOGW("IME_ERROR_NOT_RUNNING");
1485         return IME_ERROR_NOT_RUNNING;
1486     }
1487
1488     retVal = _check_privilege();
1489     if (retVal != IME_ERROR_NONE) return retVal;
1490
1491     g_core.request_ise_hide();
1492
1493     return IME_ERROR_NONE;
1494 }
1495
1496 //LCOV_EXCL_START
1497 EXPORT_API int ime_initialize(void)
1498 {
1499     ime_error_e retVal = IME_ERROR_NONE;
1500
1501     retVal = _check_privilege();
1502     if (retVal != IME_ERROR_NONE) return retVal;
1503
1504     g_core.init();
1505     g_running = false;
1506
1507     return retVal;
1508 }
1509
1510 EXPORT_API int ime_prepare(void)
1511 {
1512     ime_error_e retVal = IME_ERROR_NONE;
1513
1514     if (g_running) {
1515         LOGE("inputmethod main loop is already running.");
1516         return IME_ERROR_OPERATION_FAILED;
1517     }
1518
1519     retVal = _check_privilege();
1520     if (retVal != IME_ERROR_NONE) return retVal;
1521
1522     g_core.prepare();
1523
1524     g_running = true;
1525
1526     return retVal;
1527 }
1528
1529 EXPORT_API int ime_finalize(void)
1530 {
1531     ime_error_e retVal = IME_ERROR_NONE;
1532
1533     retVal = _check_privilege();
1534     if (retVal != IME_ERROR_NONE) return retVal;
1535
1536     g_core.fini();
1537     g_running = false;
1538     memset(&g_basic_callback, 0, sizeof(ime_callback_s));
1539     memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
1540     g_user_data = NULL;
1541
1542     return retVal;
1543 }
1544
1545 EXPORT_API int ime_select_candidate(unsigned int index)
1546 {
1547     ime_error_e retVal = IME_ERROR_NONE;
1548
1549     if (!g_running) {
1550         LOGW("IME_ERROR_NOT_RUNNING");
1551         return IME_ERROR_NOT_RUNNING;
1552     }
1553
1554     retVal = _check_privilege();
1555     if (retVal != IME_ERROR_NONE) return retVal;
1556
1557     g_core.select_candidate(index);
1558
1559     return IME_ERROR_NONE;
1560 }
1561 //LCOV_EXCL_STOP
1562
1563 EXPORT_API int ime_send_private_command(const char *command)
1564 {
1565     ime_error_e retVal = IME_ERROR_NONE;
1566
1567     if (!command) {
1568         LOGW("IME_ERROR_INVALID_PARAMETER");
1569         return IME_ERROR_INVALID_PARAMETER;
1570     }
1571
1572     if (!g_running) {
1573         LOGW("IME_ERROR_NOT_RUNNING");
1574         return IME_ERROR_NOT_RUNNING;
1575     }
1576
1577     retVal = _check_privilege();
1578     if (retVal != IME_ERROR_NONE) return retVal;
1579
1580     g_core.send_private_command(command);
1581
1582     return IME_ERROR_NONE;
1583 }
1584
1585 EXPORT_API int ime_commit_content(const char *content, const char *description, const char *mime_type)
1586 {
1587     ime_error_e retVal = IME_ERROR_NONE;
1588
1589     if (!content || !description || !mime_type) {
1590         LOGW("IME_ERROR_INVALID_PARAMETER");
1591         return IME_ERROR_INVALID_PARAMETER;
1592     }
1593
1594     retVal = _check_privilege();
1595     if (retVal != IME_ERROR_NONE) return retVal;
1596
1597     if (!g_running) {
1598         LOGW("IME_ERROR_NOT_RUNNING");
1599         return IME_ERROR_NOT_RUNNING;
1600     }
1601
1602     LOGI("content : '%s', description : '%s', mime_type : '%s'", content, description, mime_type);
1603     g_core.commit_content(content, description, mime_type);
1604
1605     return IME_ERROR_NONE;
1606 }
1607
1608 EXPORT_API int ime_context_get_layout(ime_context_h context, Ecore_IMF_Input_Panel_Layout *layout)
1609 {
1610     ime_error_e retVal = IME_ERROR_NONE;
1611
1612     if (!context || !layout) {
1613         LOGW("IME_ERROR_INVALID_PARAMETER");
1614         return IME_ERROR_INVALID_PARAMETER;
1615     }
1616
1617     retVal = _check_privilege();
1618     if (retVal != IME_ERROR_NONE) return retVal;
1619
1620     if (!g_running) {
1621         LOGW("IME_ERROR_NOT_RUNNING");
1622         return IME_ERROR_NOT_RUNNING;
1623     }
1624
1625     *layout = context->layout;
1626
1627     return IME_ERROR_NONE;
1628 }
1629
1630 EXPORT_API int ime_context_get_layout_variation(ime_context_h context, ime_layout_variation_e *layout_variation)
1631 {
1632     ime_error_e retVal = IME_ERROR_NONE;
1633
1634     if (!context || !layout_variation) {
1635         LOGW("IME_ERROR_INVALID_PARAMETER");
1636         return IME_ERROR_INVALID_PARAMETER;
1637     }
1638
1639     retVal = _check_privilege();
1640     if (retVal != IME_ERROR_NONE) return retVal;
1641
1642     if (!g_running) {
1643         LOGW("IME_ERROR_NOT_RUNNING");
1644         return IME_ERROR_NOT_RUNNING;
1645     }
1646
1647     *layout_variation = static_cast<ime_layout_variation_e>(context->layout_variation);
1648
1649     return IME_ERROR_NONE;
1650 }
1651
1652 EXPORT_API int ime_context_get_cursor_position(ime_context_h context, int *cursor_pos)
1653 {
1654     ime_error_e retVal = IME_ERROR_NONE;
1655
1656     if (!context || !cursor_pos) {
1657         LOGW("IME_ERROR_INVALID_PARAMETER");
1658         return IME_ERROR_INVALID_PARAMETER;
1659     }
1660
1661     retVal = _check_privilege();
1662     if (retVal != IME_ERROR_NONE) return retVal;
1663
1664     if (!g_running) {
1665         LOGW("IME_ERROR_NOT_RUNNING");
1666         return IME_ERROR_NOT_RUNNING;
1667     }
1668
1669     *cursor_pos = context->cursor_pos;
1670
1671     return IME_ERROR_NONE;
1672 }
1673
1674 EXPORT_API int ime_context_get_autocapital_type(ime_context_h context, Ecore_IMF_Autocapital_Type *autocapital_type)
1675 {
1676     ime_error_e retVal = IME_ERROR_NONE;
1677
1678     if (!context || !autocapital_type) {
1679         LOGW("IME_ERROR_INVALID_PARAMETER");
1680         return IME_ERROR_INVALID_PARAMETER;
1681     }
1682
1683     retVal = _check_privilege();
1684     if (retVal != IME_ERROR_NONE) return retVal;
1685
1686     if (!g_running) {
1687         LOGW("IME_ERROR_NOT_RUNNING");
1688         return IME_ERROR_NOT_RUNNING;
1689     }
1690
1691     *autocapital_type = context->autocapital_type;
1692
1693     return IME_ERROR_NONE;
1694 }
1695
1696 EXPORT_API int ime_context_get_return_key_type(ime_context_h context, Ecore_IMF_Input_Panel_Return_Key_Type *return_key_type)
1697 {
1698     ime_error_e retVal = IME_ERROR_NONE;
1699
1700     if (!context || !return_key_type) {
1701         LOGW("IME_ERROR_INVALID_PARAMETER");
1702         return IME_ERROR_INVALID_PARAMETER;
1703     }
1704
1705     retVal = _check_privilege();
1706     if (retVal != IME_ERROR_NONE) return retVal;
1707
1708     if (!g_running) {
1709         LOGW("IME_ERROR_NOT_RUNNING");
1710         return IME_ERROR_NOT_RUNNING;
1711     }
1712
1713     *return_key_type = context->return_key_type;
1714
1715     return IME_ERROR_NONE;
1716 }
1717
1718 EXPORT_API int ime_context_get_return_key_state(ime_context_h context, bool *return_key_state)
1719 {
1720     ime_error_e retVal = IME_ERROR_NONE;
1721
1722     if (!context || !return_key_state) {
1723         LOGW("IME_ERROR_INVALID_PARAMETER");
1724         return IME_ERROR_INVALID_PARAMETER;
1725     }
1726
1727     retVal = _check_privilege();
1728     if (retVal != IME_ERROR_NONE) return retVal;
1729
1730     if (!g_running) {
1731         LOGW("IME_ERROR_NOT_RUNNING");
1732         return IME_ERROR_NOT_RUNNING;
1733     }
1734
1735     *return_key_state = static_cast<bool>(context->return_key_disabled);
1736
1737     return IME_ERROR_NONE;
1738 }
1739
1740 EXPORT_API int ime_context_get_prediction_mode(ime_context_h context, bool *prediction_mode)
1741 {
1742     ime_error_e retVal = IME_ERROR_NONE;
1743
1744     if (!context || !prediction_mode) {
1745         LOGW("IME_ERROR_INVALID_PARAMETER");
1746         return IME_ERROR_INVALID_PARAMETER;
1747     }
1748
1749     retVal = _check_privilege();
1750     if (retVal != IME_ERROR_NONE) return retVal;
1751
1752     if (!g_running) {
1753         LOGW("IME_ERROR_NOT_RUNNING");
1754         return IME_ERROR_NOT_RUNNING;
1755     }
1756
1757     *prediction_mode = static_cast<bool>(context->prediction_allow);
1758
1759     return IME_ERROR_NONE;
1760 }
1761
1762 EXPORT_API int ime_context_get_password_mode(ime_context_h context, bool *password_mode)
1763 {
1764     ime_error_e retVal = IME_ERROR_NONE;
1765
1766     if (!context || !password_mode) {
1767         LOGW("IME_ERROR_INVALID_PARAMETER");
1768         return IME_ERROR_INVALID_PARAMETER;
1769     }
1770
1771     retVal = _check_privilege();
1772     if (retVal != IME_ERROR_NONE) return retVal;
1773
1774     if (!g_running) {
1775         LOGW("IME_ERROR_NOT_RUNNING");
1776         return IME_ERROR_NOT_RUNNING;
1777     }
1778
1779     *password_mode = static_cast<bool>(context->password_mode);
1780
1781     return IME_ERROR_NONE;
1782 }
1783
1784 EXPORT_API int ime_context_get_input_hint(ime_context_h context, Ecore_IMF_Input_Hints *input_hint)
1785 {
1786     ime_error_e retVal = IME_ERROR_NONE;
1787
1788     if (!context || !input_hint) {
1789         LOGW("IME_ERROR_INVALID_PARAMETER");
1790         return IME_ERROR_INVALID_PARAMETER;
1791     }
1792
1793     retVal = _check_privilege();
1794     if (retVal != IME_ERROR_NONE) return retVal;
1795
1796     if (!g_running) {
1797         LOGW("IME_ERROR_NOT_RUNNING");
1798         return IME_ERROR_NOT_RUNNING;
1799     }
1800
1801     *input_hint = context->input_hint;
1802
1803     return IME_ERROR_NONE;
1804 }
1805
1806 EXPORT_API int ime_context_get_bidi_direction(ime_context_h context, Ecore_IMF_BiDi_Direction *bidi)
1807 {
1808     ime_error_e retVal = IME_ERROR_NONE;
1809
1810     if (!context || !bidi) {
1811         LOGW("IME_ERROR_INVALID_PARAMETER");
1812         return IME_ERROR_INVALID_PARAMETER;
1813     }
1814
1815     retVal = _check_privilege();
1816     if (retVal != IME_ERROR_NONE) return retVal;
1817
1818     if (!g_running) {
1819         LOGW("IME_ERROR_NOT_RUNNING");
1820         return IME_ERROR_NOT_RUNNING;
1821     }
1822
1823     *bidi = context->bidi_direction;
1824
1825     return IME_ERROR_NONE;
1826 }
1827
1828 EXPORT_API int ime_context_get_language(ime_context_h context, Ecore_IMF_Input_Panel_Lang *language)
1829 {
1830     ime_error_e retVal = IME_ERROR_NONE;
1831
1832     if (!context || !language) {
1833         LOGW("IME_ERROR_INVALID_PARAMETER");
1834         return IME_ERROR_INVALID_PARAMETER;
1835     }
1836
1837     retVal = _check_privilege();
1838     if (retVal != IME_ERROR_NONE) return retVal;
1839
1840     if (!g_running) {
1841         LOGW("IME_ERROR_NOT_RUNNING");
1842         return IME_ERROR_NOT_RUNNING;
1843     }
1844
1845     *language = context->language;
1846
1847     return IME_ERROR_NONE;
1848 }
1849
1850 //LCOV_EXCL_START
1851 EXPORT_API int ime_context_get_caps_mode(ime_context_h context, bool *caps_mode)
1852 {
1853     ime_error_e retVal = IME_ERROR_NONE;
1854
1855     if (!context || !caps_mode) {
1856         LOGW("IME_ERROR_INVALID_PARAMETER");
1857         return IME_ERROR_INVALID_PARAMETER;
1858     }
1859
1860     retVal = _check_privilege();
1861     if (retVal != IME_ERROR_NONE) return retVal;
1862
1863     if (!g_running) {
1864         LOGW("IME_ERROR_NOT_RUNNING");
1865         return IME_ERROR_NOT_RUNNING;
1866     }
1867
1868     *caps_mode = static_cast<bool>(context->caps_mode);
1869
1870     return IME_ERROR_NONE;
1871 }
1872 //LCOV_EXCL_STOP
1873
1874 EXPORT_API int ime_device_info_get_name(ime_device_info_h dev_info, char **dev_name)
1875 {
1876     ime_error_e retVal = IME_ERROR_NONE;
1877
1878     if (!dev_info || !dev_name) {
1879         LOGW("IME_ERROR_INVALID_PARAMETER");
1880         return IME_ERROR_INVALID_PARAMETER;
1881     }
1882
1883     retVal = _check_privilege();
1884     if (retVal != IME_ERROR_NONE) return retVal;
1885
1886     if (!g_running) {
1887         LOGW("IME_ERROR_NOT_RUNNING");
1888         return IME_ERROR_NOT_RUNNING;
1889     }
1890
1891     if (!dev_info->dev_name)
1892         *dev_name = strdup("");
1893     else
1894         *dev_name = strdup(dev_info->dev_name);
1895
1896     return IME_ERROR_NONE;
1897 }
1898
1899 EXPORT_API int ime_device_info_get_class(ime_device_info_h dev_info, Ecore_IMF_Device_Class *dev_class)
1900 {
1901     ime_error_e retVal = IME_ERROR_NONE;
1902
1903     if (!dev_info || !dev_class) {
1904         LOGW("IME_ERROR_INVALID_PARAMETER");
1905         return IME_ERROR_INVALID_PARAMETER;
1906     }
1907
1908     retVal = _check_privilege();
1909     if (retVal != IME_ERROR_NONE) return retVal;
1910
1911     if (!g_running) {
1912         LOGW("IME_ERROR_NOT_RUNNING");
1913         return IME_ERROR_NOT_RUNNING;
1914     }
1915
1916     *dev_class = dev_info->dev_class;
1917
1918     return IME_ERROR_NONE;
1919 }
1920
1921 EXPORT_API int ime_device_info_get_subclass(ime_device_info_h dev_info, Ecore_IMF_Device_Subclass *dev_subclass)
1922 {
1923     ime_error_e retVal = IME_ERROR_NONE;
1924
1925     if (!dev_info || !dev_subclass) {
1926         LOGW("IME_ERROR_INVALID_PARAMETER");
1927         return IME_ERROR_INVALID_PARAMETER;
1928     }
1929
1930     retVal = _check_privilege();
1931     if (retVal != IME_ERROR_NONE) return retVal;
1932
1933     if (!g_running) {
1934         LOGW("IME_ERROR_NOT_RUNNING");
1935         return IME_ERROR_NOT_RUNNING;
1936     }
1937
1938     *dev_subclass = dev_info->dev_subclass;
1939
1940     return IME_ERROR_NONE;
1941 }
1942
1943 //LCOV_EXCL_START
1944 EXPORT_API int ime_event_set_process_input_device_event_cb(ime_process_input_device_event_cb callback_func, void *user_data)
1945 {
1946     ime_error_e retVal = IME_ERROR_NONE;
1947
1948     if (!callback_func) {
1949         LOGW("IME_ERROR_INVALID_PARAMETER");
1950         return IME_ERROR_INVALID_PARAMETER;
1951     }
1952
1953     retVal = _check_privilege();
1954     if (retVal != IME_ERROR_NONE) return retVal;
1955
1956     g_event_callback.process_input_device_event = callback_func;
1957     g_event_callback.process_input_device_event_user_data = user_data;
1958
1959     return IME_ERROR_NONE;
1960 }
1961
1962 EXPORT_API int ime_event_unset_process_input_device_event_cb(void)
1963 {
1964     ime_error_e retVal = IME_ERROR_NONE;
1965
1966     retVal = _check_privilege();
1967     if (retVal != IME_ERROR_NONE) return retVal;
1968
1969     g_event_callback.process_input_device_event = NULL;
1970     g_event_callback.process_input_device_event_user_data = NULL;
1971
1972     return IME_ERROR_NONE;
1973 }
1974
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)
1977 {
1978     ime_error_e retVal = IME_ERROR_NONE;
1979
1980     if (!event_handle || !direction) {
1981         LOGW("IME_ERROR_INVALID_PARAMETER");
1982         return IME_ERROR_INVALID_PARAMETER;
1983     }
1984
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;
1989     }
1990
1991     retVal = _check_privilege();
1992     if (retVal != IME_ERROR_NONE) return retVal;
1993
1994     if (!g_running) {
1995         LOGW("IME_ERROR_OPERATION_FAILED");
1996         return IME_ERROR_OPERATION_FAILED;
1997     }
1998
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;
2006         }
2007     }
2008
2009     return IME_ERROR_NONE;
2010 }
2011 //LCOV_EXCL_STOP
2012
2013 EXPORT_API int ime_event_set_prediction_hint_set_cb(ime_prediction_hint_set_cb callback_func, void *user_data)
2014 {
2015     ime_error_e retVal = IME_ERROR_NONE;
2016
2017     if (!callback_func) {
2018         LOGW("IME_ERROR_INVALID_PARAMETER");
2019         return IME_ERROR_INVALID_PARAMETER;
2020     }
2021
2022     retVal = _check_privilege();
2023     if (retVal != IME_ERROR_NONE) return retVal;
2024
2025     g_event_callback.prediction_hint_set = callback_func;
2026     g_event_callback.prediction_hint_set_user_data = user_data;
2027
2028     return IME_ERROR_NONE;
2029 }
2030
2031 EXPORT_API int ime_event_set_mime_type_set_request_cb(ime_mime_type_set_request_cb callback_func, void *user_data)
2032 {
2033     ime_error_e retVal = IME_ERROR_NONE;
2034
2035     if (!callback_func) {
2036         LOGW("IME_ERROR_INVALID_PARAMETER");
2037         return IME_ERROR_INVALID_PARAMETER;
2038     }
2039
2040     retVal = _check_privilege();
2041     if (retVal != IME_ERROR_NONE) return retVal;
2042
2043     g_event_callback.mime_type_set = callback_func;
2044     g_event_callback.mime_type_set_user_data = user_data;
2045
2046     return IME_ERROR_NONE;
2047 }
2048
2049 EXPORT_API int ime_set_floating_mode(bool floating_mode)
2050 {
2051     ime_error_e retVal = IME_ERROR_NONE;
2052
2053     retVal = _check_privilege();
2054     if (retVal != IME_ERROR_NONE) return retVal;
2055
2056     if (!g_running) {
2057         LOGW("IME_ERROR_NOT_RUNNING");
2058         return IME_ERROR_NOT_RUNNING;
2059     }
2060
2061     g_core.set_floating_mode(floating_mode);
2062
2063     return IME_ERROR_NONE;
2064 }
2065
2066 EXPORT_API int ime_set_floating_drag_start(void)
2067 {
2068     ime_error_e retVal = IME_ERROR_NONE;
2069
2070     retVal = _check_privilege();
2071     if (retVal != IME_ERROR_NONE) return retVal;
2072
2073     if (!g_running) {
2074         LOGW("IME_ERROR_NOT_RUNNING");
2075         return IME_ERROR_NOT_RUNNING;
2076     }
2077
2078     g_core.set_floating_drag_enabled(true);
2079
2080     return IME_ERROR_NONE;
2081 }
2082
2083 EXPORT_API int ime_set_floating_drag_end(void)
2084 {
2085     ime_error_e retVal = IME_ERROR_NONE;
2086
2087     retVal = _check_privilege();
2088     if (retVal != IME_ERROR_NONE) return retVal;
2089
2090     if (!g_running) {
2091         LOGW("IME_ERROR_NOT_RUNNING");
2092         return IME_ERROR_NOT_RUNNING;
2093     }
2094
2095     g_core.set_floating_drag_enabled(false);
2096
2097     return IME_ERROR_NONE;
2098 }
2099
2100 //LCOV_EXCL_START
2101 EXPORT_API int ime_set_window_creation_defer_flag(bool flag)
2102 {
2103     ime_error_e retVal = IME_ERROR_NONE;
2104
2105     retVal = _check_privilege();
2106     if (retVal != IME_ERROR_NONE) return retVal;
2107
2108     g_core.set_window_creation_defer_flag(flag);
2109
2110     return IME_ERROR_NONE;
2111 }
2112 //LCOV_EXCL_STOP
2113
2114 EXPORT_API int ime_event_set_prediction_hint_data_set_cb(ime_prediction_hint_data_set_cb callback_func, void *user_data)
2115 {
2116     ime_error_e retVal = IME_ERROR_NONE;
2117
2118     if (!callback_func) {
2119         LOGW("IME_ERROR_INVALID_PARAMETER");
2120         return IME_ERROR_INVALID_PARAMETER;
2121     }
2122
2123     retVal = _check_privilege();
2124     if (retVal != IME_ERROR_NONE) return retVal;
2125
2126     g_event_callback.prediction_hint_data_set = callback_func;
2127     g_event_callback.prediction_hint_data_set_user_data = user_data;
2128
2129     return IME_ERROR_NONE;
2130 }
2131
2132 //LCOV_EXCL_START
2133 EXPORT_API int ime_event_set_optimization_hint_set_cb(ime_optimization_hint_set_cb callback_func, void *user_data)
2134 {
2135     LOGD("");
2136     ime_error_e retVal = IME_ERROR_NONE;
2137
2138     if (!callback_func) {
2139         LOGW("IME_ERROR_INVALID_PARAMETER");
2140         return IME_ERROR_INVALID_PARAMETER;
2141     }
2142
2143     LOGD("");
2144     retVal = _check_privilege();
2145     if (retVal != IME_ERROR_NONE) return retVal;
2146
2147     LOGD("");
2148     g_event_callback.optimization_hint_set = callback_func;
2149     g_event_callback.optimization_hint_set_user_data = user_data;
2150
2151     return IME_ERROR_NONE;
2152 }
2153 //LCOV_EXCL_STOP
2154
2155 EXPORT_API int ime_update_input_panel_event(ime_event_type_e type, unsigned int value)
2156 {
2157     ime_error_e retVal = IME_ERROR_NONE;
2158
2159     if (type < IME_EVENT_TYPE_LANGUAGE || type > IME_EVENT_TYPE_GEOMETRY) {
2160         LOGW("IME_ERROR_INVALID_PARAMETER");
2161         return IME_ERROR_INVALID_PARAMETER;
2162     }
2163
2164     if (!g_running) {
2165         LOGW("IME_ERROR_NOT_RUNNING");
2166         return IME_ERROR_NOT_RUNNING;
2167     }
2168
2169     retVal = _check_privilege();
2170     if (retVal != IME_ERROR_NONE) return retVal;
2171
2172     g_core.update_input_context((sclu32)type, value);
2173
2174     return IME_ERROR_NONE;
2175 }
2176
2177 EXPORT_API int ime_set_candidate_visibility_state(bool visible)
2178 {
2179     ime_error_e retVal = IME_ERROR_NONE;
2180
2181     if (!g_running) {
2182         LOGW("IME_ERROR_NOT_RUNNING");
2183         return IME_ERROR_NOT_RUNNING;
2184     }
2185
2186     retVal = _check_privilege();
2187     if (retVal != IME_ERROR_NONE) return retVal;
2188
2189     if (visible)
2190         g_core.show_candidate_string();
2191     else
2192         g_core.hide_candidate_string();
2193
2194     return IME_ERROR_NONE;
2195 }