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