Fix typos
[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(Ecore_IMF_Input_Panel_Lang language);
51     void on_set_imdata(sclchar *buf, sclu32 len);
52     void on_get_imdata(sclchar **buf, sclu32 *len);
53     void on_get_language_locale(sclint ic, sclchar **locale);
54     void on_set_return_key_type(Ecore_IMF_Input_Panel_Return_Key_Type type);
55     void on_set_return_key_disable(sclu32 disabled);
56     void on_set_layout(sclu32 layout);
57     void on_reset_input_context(sclint ic, const sclchar *uuid);
58     void on_process_key_event(scim::KeyEvent &key, sclu32 *ret);
59     void on_process_key_event_with_keycode(scim::KeyEvent &key, sclu32 *ret, sclu32 keycode);
60     void on_set_display_language(const sclchar *language);
61     void on_set_rotation_degree(sclint degree);
62     void on_set_accessibility_state(sclboolean state);
63     void on_create_option_window(sclwindow window, SCLOptionWindowType type);
64     void on_destroy_option_window(sclwindow window);
65     void on_check_option_window_availability(sclboolean *ret);
66     void on_set_caps_mode(sclu32 mode);
67     void on_candidate_show(sclint ic, const sclchar *ic_uuid);
68     void on_candidate_hide(sclint ic, const sclchar *ic_uuid);
69     void on_update_lookup_table(SclCandidateTable &table);
70     void on_process_input_device_event(sclu32 &type, sclchar *data, size_t &len, sclu32 *ret);
71     void on_set_prediction_hint(const sclchar *prediction_hint);
72     void on_set_mime_type(const sclchar *mime_type);
73     void on_set_prediction_hint_data(const sclchar *key, const sclchar *value);
74     void on_set_optimization_hint(sclu32 hint);
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 extern "C" {
153     extern void ime_app_main(int argc, char **argv);
154 }
155
156 //LCOV_EXCL_START
157 void CCoreEventCallback::on_init()
158 {
159     if (g_basic_callback.create) {
160         g_basic_callback.create(g_user_data);
161     }
162 }
163
164 void CCoreEventCallback::on_run(int argc, char **argv)
165 {
166     LOGD("on_run");
167     ime_app_main(argc, argv);
168 }
169
170 void CCoreEventCallback::on_exit()
171 {
172     LOGD("on_exit");
173     if (g_basic_callback.terminate) {
174         g_basic_callback.terminate(g_user_data);
175     }
176 }
177
178 void CCoreEventCallback::on_update_cursor_position(sclint ic, const sclchar *ic_uuid, sclint cursor_pos)
179 {
180     if (g_event_callback.cursor_position_updated) {
181         g_event_callback.cursor_position_updated(cursor_pos, g_event_callback.cursor_position_updated_user_data);
182     }
183 }
184
185 void CCoreEventCallback::on_update_surrounding_text(sclint ic, const sclchar *text, sclint cursor)
186 {
187     if (g_event_callback.surrounding_text_updated) {
188         g_event_callback.surrounding_text_updated(ic, text, cursor, g_event_callback.surrounding_text_updated_user_data);
189     }
190 }
191
192 void CCoreEventCallback::on_focus_out(sclint ic, const sclchar *ic_uuid)
193 {
194     if (g_event_callback.focus_out) {
195         g_event_callback.focus_out(ic, g_event_callback.focus_out_user_data);
196     }
197 }
198
199 void CCoreEventCallback::on_focus_in(sclint ic, const sclchar *ic_uuid)
200 {
201     if (g_event_callback.focus_in) {
202         g_event_callback.focus_in(ic, g_event_callback.focus_in_user_data);
203     }
204 }
205
206 void CCoreEventCallback::on_ise_show(sclint ic, const int degree, Ise_Context &context)
207 {
208     if (g_basic_callback.show) {
209         struct _ime_context input_context;
210
211         memset(&input_context, 0, sizeof(struct _ime_context));
212         input_context.layout = context.layout;
213         input_context.layout_variation = context.layout_variation;
214         input_context.cursor_pos = context.cursor_pos;
215         input_context.autocapital_type = context.autocapital_type;
216         input_context.return_key_type = context.return_key_type;
217         input_context.return_key_disabled = context.return_key_disabled;
218         input_context.prediction_allow = context.prediction_allow;
219         input_context.password_mode = context.password_mode;
220         input_context.imdata_size = context.imdata_size;
221         input_context.input_hint = context.input_hint;
222         input_context.bidi_direction = context.bidi_direction;
223         input_context.language = context.language;
224         input_context.client_window = context.client_window;
225         input_context.caps_mode = context.caps_mode;
226
227         g_basic_callback.show(ic, static_cast<ime_context_h>(&input_context), g_user_data);
228     }
229 }
230
231 void CCoreEventCallback::on_ise_hide(sclint ic, const sclchar *ic_uuid)
232 {
233     if (g_basic_callback.hide) {
234         g_basic_callback.hide(ic, g_user_data);
235     }
236 }
237
238 void CCoreEventCallback::on_get_geometry(sclu32 *pos_x, sclu32 *pos_y, sclu32 *width, sclu32 *height)
239 {
240     int geometry_pos_x = 0;
241     int geometry_pos_y = 0;
242     int geometry_width = 0;
243     int geometry_height = 0;
244
245     if (g_event_callback.geometry_requested) {
246         g_event_callback.geometry_requested(g_event_callback.geometry_requested_user_data, &geometry_pos_x, &geometry_pos_y, &geometry_width, &geometry_height);
247     }
248
249     if (pos_x)
250         *pos_x = geometry_pos_x;
251
252     if (pos_y)
253         *pos_y = geometry_pos_y;
254
255     if (width)
256         *width = geometry_width;
257
258     if (height)
259         *height = geometry_height;
260 }
261
262 void CCoreEventCallback::on_set_language(Ecore_IMF_Input_Panel_Lang language)
263 {
264     if (g_event_callback.language_set) {
265         g_event_callback.language_set(language, g_event_callback.language_set_user_data);
266     }
267 }
268
269 void CCoreEventCallback::on_set_imdata(sclchar *buf, sclu32 len)
270 {
271     if (g_event_callback.imdata_set) {
272         g_event_callback.imdata_set((void *)buf, len, g_event_callback.imdata_set_user_data);
273     }
274 }
275
276 void CCoreEventCallback::on_get_imdata(sclchar **buf, sclu32 *len)
277 {
278     if (g_event_callback.imdata_requested) {
279         g_event_callback.imdata_requested(g_event_callback.imdata_set_user_data, (void **)buf, len);
280     }
281 }
282
283 void CCoreEventCallback::on_get_language_locale(sclint ic, sclchar **locale)
284 {
285     if (g_event_callback.language_requested) {
286         g_event_callback.language_requested(g_event_callback.language_requested_user_data, locale);
287     }
288 }
289
290 void CCoreEventCallback::on_set_return_key_type(Ecore_IMF_Input_Panel_Return_Key_Type type)
291 {
292     if (g_event_callback.return_key_type_set) {
293         g_event_callback.return_key_type_set(type, g_event_callback.return_key_type_set_user_data);
294     }
295 }
296
297 void CCoreEventCallback::on_set_return_key_disable(sclu32 disabled)
298 {
299     bool return_key_disabled = !!disabled;
300
301     if (g_event_callback.return_key_state_set) {
302         g_event_callback.return_key_state_set(return_key_disabled, g_event_callback.return_key_state_set_user_data);
303     }
304 }
305
306 void CCoreEventCallback::on_set_layout(sclu32 layout)
307 {
308     if (g_event_callback.layout_set) {
309         g_event_callback.layout_set(static_cast<Ecore_IMF_Input_Panel_Layout>(layout), g_event_callback.layout_set_user_data);
310     }
311 }
312
313 void CCoreEventCallback::on_reset_input_context(sclint ic, const sclchar *uuid)
314 {
315     if (g_event_callback.input_context_reset) {
316         g_event_callback.input_context_reset(g_event_callback.input_context_reset_user_data);
317     }
318 }
319
320 void CCoreEventCallback::on_process_key_event(scim::KeyEvent &key, sclu32 *ret)
321 {
322     if (g_event_callback.process_key_event) {
323         struct _ime_device_info dev_info = {key.dev_name.c_str(),
324             static_cast<Ecore_IMF_Device_Class>(key.dev_class), static_cast<Ecore_IMF_Device_Subclass>(key.dev_subclass)};
325         bool processed = g_event_callback.process_key_event(static_cast<ime_key_code_e>(key.code), static_cast<ime_key_mask_e>(key.mask),
326             static_cast<ime_device_info_h>(&dev_info), g_event_callback.process_key_event_user_data);
327
328         if (ret) {
329             if (processed)
330                 *ret = 1;
331             else
332                 *ret = 0;
333         }
334     } else {
335         if (ret) {
336             *ret = 0;
337         }
338     }
339 }
340
341 void CCoreEventCallback::on_process_key_event_with_keycode(scim::KeyEvent &key, sclu32 *ret, sclu32 keycode)
342 {
343     if (g_event_callback.process_key_event_with_keycode) {
344         struct _ime_device_info dev_info = {key.dev_name.c_str(),
345             static_cast<Ecore_IMF_Device_Class>(key.dev_class), static_cast<Ecore_IMF_Device_Subclass>(key.dev_subclass)};
346         bool processed = g_event_callback.process_key_event_with_keycode(keycode, static_cast<ime_key_code_e>(key.code), static_cast<ime_key_mask_e>(key.mask),
347                 static_cast<ime_device_info_h>(&dev_info), g_event_callback.process_key_event_user_data);
348
349         if (ret) {
350             if (processed)
351                 *ret = 1;
352             else
353                 *ret = 0;
354         }
355     } else {
356         if (ret) {
357             *ret = 0;
358         }
359     }
360 }
361
362 void CCoreEventCallback::on_set_display_language(const sclchar *language)
363 {
364     if (g_event_callback.display_language_changed) {
365         g_event_callback.display_language_changed(language, g_event_callback.display_language_changed_user_data);
366     }
367 }
368
369 void CCoreEventCallback::on_set_rotation_degree(sclint degree)
370 {
371     if (g_event_callback.rotation_degree_changed) {
372         g_event_callback.rotation_degree_changed(degree, g_event_callback.rotation_degree_changed_user_data);
373     }
374 }
375
376 void CCoreEventCallback::on_set_accessibility_state(sclboolean state)
377 {
378     if (g_event_callback.accessibility_state_changed) {
379         g_event_callback.accessibility_state_changed(state, g_event_callback.accessibility_state_changed_user_data);
380     }
381 }
382
383 void CCoreEventCallback::on_create_option_window(sclwindow window, SCLOptionWindowType type)
384 {
385     if (g_event_callback.option_window_created) {
386         g_event_callback.option_window_created(static_cast<Evas_Object*>(window), static_cast<ime_option_window_type_e>(type), g_event_callback.option_window_created_user_data);
387     }
388 }
389
390 void CCoreEventCallback::on_destroy_option_window(sclwindow window)
391 {
392     if (g_event_callback.option_window_destroyed) {
393         g_event_callback.option_window_destroyed(static_cast<Evas_Object*>(window), g_event_callback.option_window_destroyed_user_data);
394     }
395 }
396
397 void CCoreEventCallback::on_check_option_window_availability(sclboolean *ret)
398 {
399     if (ret) {
400         if (g_event_callback.option_window_created) // Instead of each 3rd party keyboard, inputmethod will reply the availability of the option (setting).
401             *ret = true;
402         else
403             *ret = false;
404     }
405 }
406
407 void CCoreEventCallback::on_set_caps_mode(sclu32 mode)
408 {
409     if (g_event_callback.caps_mode_changed) {
410         g_event_callback.caps_mode_changed(mode, g_event_callback.caps_mode_changed_user_data);
411     }
412 }
413
414 void CCoreEventCallback::on_candidate_show(sclint ic, const sclchar *ic_uuid)
415 {
416     if (g_event_callback.candidate_show) {
417         g_event_callback.candidate_show(ic, g_event_callback.candidate_show_user_data);
418     }
419 }
420
421 void CCoreEventCallback::on_candidate_hide(sclint ic, const sclchar *ic_uuid)
422 {
423     if (g_event_callback.candidate_hide) {
424         g_event_callback.candidate_hide(ic, g_event_callback.candidate_hide_user_data);
425     }
426 }
427
428 void CCoreEventCallback::on_update_lookup_table(SclCandidateTable &table)
429 {
430     Eina_List *string_list = NULL;
431
432     if (g_event_callback.lookup_table_changed) {
433         vector<string>::iterator iter = table.candidate.begin();
434         for (; iter != table.candidate.end(); ++iter) {
435             string_list = eina_list_append(string_list, iter->c_str());
436         }
437
438         g_event_callback.lookup_table_changed(string_list, g_event_callback.lookup_table_changed_user_data);
439     }
440 }
441
442 void CCoreEventCallback::on_process_input_device_event(sclu32 &type, sclchar *data, size_t &len, sclu32 *ret)
443 {
444     typedef struct {
445         int ecore_event_id;
446         ime_input_device_type_e device_type;
447     } ime_device_type_conv_table;
448
449     ime_device_type_conv_table conv_table[] = {
450         { ECORE_EVENT_DETENT_ROTATE , IME_INPUT_DEVICE_TYPE_ROTARY },
451     };
452
453     ime_input_device_type_e device_type = IME_INPUT_DEVICE_TYPE_UNKNOWN;
454     for (unsigned int loop = 0; loop < sizeof(conv_table) / sizeof(ime_device_type_conv_table); loop++) {
455         if ((unsigned int)(conv_table[loop].ecore_event_id) == type) {
456             device_type = conv_table[loop].device_type;
457         }
458     }
459
460     if (g_event_callback.process_input_device_event) {
461         ime_device_event_s device_event;
462         device_event.device_type = device_type;
463         device_event.event_data = static_cast<void*>(data);
464         void *input_data = static_cast<void*>(&device_event);
465         void *user_data = g_event_callback.process_input_device_event_user_data;
466
467         g_event_callback.process_input_device_event(device_type, input_data, user_data);
468
469         if (ret) {
470             *ret = 1;
471         }
472     } else {
473         if (ret) {
474             *ret = 0;
475         }
476     }
477 }
478
479 void CCoreEventCallback::on_set_prediction_hint(const sclchar *prediction_hint)
480 {
481     if (g_event_callback.prediction_hint_set) {
482         g_event_callback.prediction_hint_set(prediction_hint, g_event_callback.prediction_hint_set_user_data);
483     }
484 }
485
486 void CCoreEventCallback::on_set_mime_type(const sclchar *mime_type)
487 {
488     if (g_event_callback.mime_type_set) {
489         g_event_callback.mime_type_set(mime_type, g_event_callback.mime_type_set_user_data);
490     }
491 }
492
493 void CCoreEventCallback::on_set_prediction_hint_data(const sclchar *key, const sclchar *value)
494 {
495     if (g_event_callback.prediction_hint_data_set) {
496         g_event_callback.prediction_hint_data_set(key, value, g_event_callback.prediction_hint_data_set_user_data);
497     }
498 }
499
500 void CCoreEventCallback::on_set_optimization_hint(sclu32 hint)
501 {
502     if (g_event_callback.optimization_hint_set) {
503         g_event_callback.optimization_hint_set((ime_optimization_hint_e)hint, g_event_callback.optimization_hint_set_user_data);
504     }
505 }
506 //LCOV_EXCL_STOP
507
508 ime_error_e _check_privilege()
509 {
510     char uid[16];
511     ime_error_e ret = IME_ERROR_NONE;
512
513     if (inputmethod_cynara_initialize() == false) {
514         LOGE("inputmethod_cynara_initialize () == false");
515         return IME_ERROR_PERMISSION_DENIED;
516     }
517
518     snprintf(uid, 16, "%d", getuid());
519     if (check_privilege(uid, IME_PRIVILEGE) == false) {
520         LOGE("check_privilege(uid, IME_PRIVILEGE) == false. uid : %s", uid);
521         ret = IME_ERROR_PERMISSION_DENIED;
522     }
523
524     inputmethod_cynara_finish();
525
526     return ret;
527 }
528
529 //LCOV_EXCL_START
530 bool g_from_dotnet = false;
531 EXPORT_API int ime_set_dotnet_flag(bool set)
532 {
533     ime_error_e retVal = IME_ERROR_NONE;
534
535     retVal = _check_privilege();
536     if (retVal != IME_ERROR_NONE) return retVal;
537
538     g_from_dotnet = set;
539
540     return retVal;
541 }
542 //LCOV_EXCL_STOP
543
544 EXPORT_API int ime_run(ime_callback_s *basic_cb, void *user_data)
545 {
546     ime_error_e retVal = IME_ERROR_NONE;
547
548     if (g_running) {
549         LOGE("inputmethod main loop is already running.");
550         return IME_ERROR_OPERATION_FAILED;
551     }
552
553     if (!basic_cb) {
554         LOGE("basic callbacks pointer is null.");
555         return IME_ERROR_INVALID_PARAMETER;
556     }
557
558     retVal = _check_privilege();
559     if (retVal != IME_ERROR_NONE) return retVal;
560
561     g_basic_callback = *basic_cb;
562
563     if (!g_basic_callback.create || !g_basic_callback.terminate ||
564         !g_basic_callback.show || !g_basic_callback.hide) {
565         LOGE("mandatory callback functions are not set");
566         memset(&g_basic_callback, 0, sizeof(ime_callback_s));
567         memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
568         return IME_ERROR_NO_CALLBACK_FUNCTION;
569     }
570
571     g_user_data = user_data;
572     g_running = true;
573
574     if (g_from_dotnet) {
575         LOGD("ime_run is called from dotnet");
576         return IME_ERROR_NONE;
577     }
578
579     try {
580         g_core.run();
581     } catch (...) {
582         LOGW("exception is thrown from g_core.run()\n");
583     }
584
585     memset(&g_basic_callback, 0, sizeof(ime_callback_s));
586     memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
587     g_user_data = NULL;
588     g_running = false;
589
590     return IME_ERROR_NONE;
591 }
592
593 EXPORT_API int ime_event_set_focus_in_cb(ime_focus_in_cb callback_func, void *user_data)
594 {
595     ime_error_e retVal = IME_ERROR_NONE;
596
597     if (!callback_func) {
598         LOGW("IME_ERROR_INVALID_PARAMETER");
599         return IME_ERROR_INVALID_PARAMETER;
600     }
601
602     retVal = _check_privilege();
603     if (retVal != IME_ERROR_NONE) return retVal;
604
605     g_event_callback.focus_in = callback_func;
606     g_event_callback.focus_in_user_data = user_data;
607
608     return IME_ERROR_NONE;
609 }
610
611 EXPORT_API int ime_event_set_focus_out_cb(ime_focus_out_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_out = callback_func;
624     g_event_callback.focus_out_user_data = user_data;
625
626     return IME_ERROR_NONE;
627 }
628
629 EXPORT_API int ime_event_set_surrounding_text_updated_cb(ime_surrounding_text_updated_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.surrounding_text_updated = callback_func;
642     g_event_callback.surrounding_text_updated_user_data = user_data;
643
644     return IME_ERROR_NONE;
645 }
646
647 EXPORT_API int ime_event_set_input_context_reset_cb(ime_input_context_reset_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.input_context_reset = callback_func;
660     g_event_callback.input_context_reset_user_data = user_data;
661
662     return IME_ERROR_NONE;
663 }
664
665 EXPORT_API int ime_event_set_cursor_position_updated_cb(ime_cursor_position_updated_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.cursor_position_updated = callback_func;
678     g_event_callback.cursor_position_updated_user_data = user_data;
679
680     return IME_ERROR_NONE;
681 }
682
683 EXPORT_API int ime_event_set_language_requested_cb(ime_language_requested_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.language_requested = callback_func;
696     g_event_callback.language_requested_user_data = user_data;
697
698     return IME_ERROR_NONE;
699 }
700
701 EXPORT_API int ime_event_set_language_set_cb(ime_language_set_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_set = callback_func;
714     g_event_callback.language_set_user_data = user_data;
715
716     return IME_ERROR_NONE;
717 }
718
719 EXPORT_API int ime_event_set_imdata_set_cb(ime_imdata_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.imdata_set = callback_func;
732     g_event_callback.imdata_set_user_data = user_data;
733
734     return IME_ERROR_NONE;
735 }
736
737 EXPORT_API int ime_event_set_imdata_requested_cb(ime_imdata_requested_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_requested = callback_func;
750     g_event_callback.imdata_requested_user_data = user_data;
751
752     return IME_ERROR_NONE;
753 }
754
755 EXPORT_API int ime_event_set_layout_set_cb(ime_layout_set_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.layout_set = callback_func;
768     g_event_callback.layout_set_user_data = user_data;
769
770     return IME_ERROR_NONE;
771 }
772
773 EXPORT_API int ime_event_set_return_key_type_set_cb(ime_return_key_type_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.return_key_type_set = callback_func;
786     g_event_callback.return_key_type_set_user_data = user_data;
787
788     return IME_ERROR_NONE;
789 }
790
791 EXPORT_API int ime_event_set_return_key_state_set_cb(ime_return_key_state_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_state_set = callback_func;
804     g_event_callback.return_key_state_set_user_data = user_data;
805
806     return IME_ERROR_NONE;
807 }
808
809 EXPORT_API int ime_event_set_geometry_requested_cb(ime_geometry_requested_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.geometry_requested = callback_func;
822     g_event_callback.geometry_requested_user_data = user_data;
823
824     return IME_ERROR_NONE;
825 }
826
827 EXPORT_API int ime_event_set_process_key_event_cb(ime_process_key_event_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.process_key_event = callback_func;
840     g_event_callback.process_key_event_user_data = user_data;
841
842     return IME_ERROR_NONE;
843 }
844
845 EXPORT_API int ime_event_set_process_key_event_with_keycode_cb(ime_process_key_event_with_keycode_cb callback_func, void *user_data)
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_with_keycode = callback_func;
858     g_event_callback.process_key_event_with_keycode_user_data = user_data;
859
860     return IME_ERROR_NONE;
861 }
862
863 EXPORT_API int ime_event_set_display_language_changed_cb(ime_display_language_changed_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.display_language_changed = callback_func;
876     g_event_callback.display_language_changed_user_data = user_data;
877
878     return IME_ERROR_NONE;
879 }
880
881 EXPORT_API int ime_event_set_rotation_degree_changed_cb(ime_rotation_degree_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.rotation_degree_changed = callback_func;
894     g_event_callback.rotation_degree_changed_user_data = user_data;
895
896     return IME_ERROR_NONE;
897 }
898
899 EXPORT_API int ime_event_set_accessibility_state_changed_cb(ime_accessibility_state_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.accessibility_state_changed = callback_func;
912     g_event_callback.accessibility_state_changed_user_data = user_data;
913
914     return IME_ERROR_NONE;
915 }
916
917 EXPORT_API int ime_event_set_option_window_created_cb(ime_option_window_created_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.option_window_created = callback_func;
930     g_event_callback.option_window_created_user_data = user_data;
931
932     return IME_ERROR_NONE;
933 }
934
935 EXPORT_API int ime_event_set_option_window_destroyed_cb(ime_option_window_destroyed_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_destroyed = callback_func;
948     g_event_callback.option_window_destroyed_user_data = user_data;
949
950     return IME_ERROR_NONE;
951 }
952
953 //LCOV_EXCL_START
954 EXPORT_API int ime_event_set_caps_mode_changed_cb(ime_caps_mode_changed_cb callback_func, void *user_data)
955 {
956     ime_error_e retVal = IME_ERROR_NONE;
957
958     if (!callback_func) {
959         LOGW("IME_ERROR_INVALID_PARAMETER");
960         return IME_ERROR_INVALID_PARAMETER;
961     }
962
963     retVal = _check_privilege();
964     if (retVal != IME_ERROR_NONE) return retVal;
965
966     g_event_callback.caps_mode_changed = callback_func;
967     g_event_callback.caps_mode_changed_user_data = user_data;
968
969     return IME_ERROR_NONE;
970 }
971
972 EXPORT_API int ime_event_set_candidate_show_cb(ime_candidate_show_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.candidate_show = callback_func;
985     g_event_callback.candidate_show_user_data = user_data;
986
987     return IME_ERROR_NONE;
988 }
989
990 EXPORT_API int ime_event_set_candidate_hide_cb(ime_candidate_hide_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_hide = callback_func;
1003     g_event_callback.candidate_hide_user_data = user_data;
1004
1005     return IME_ERROR_NONE;
1006 }
1007
1008 EXPORT_API int ime_event_set_lookup_table_changed_cb(ime_lookup_table_changed_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.lookup_table_changed = callback_func;
1021     g_event_callback.lookup_table_changed_user_data = user_data;
1022
1023     return IME_ERROR_NONE;
1024 }
1025 //LCOV_EXCL_STOP
1026
1027 EXPORT_API int ime_send_key_event(ime_key_code_e keycode, ime_key_mask_e keymask, bool forward_key)
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     if (forward_key)
1040         g_core.forward_key_event(-1, NULL, (sclu32)keycode, (sclu16)keymask);
1041     else
1042         g_core.send_key_event(-1, NULL, (sclu32)keycode, (sclu16)keymask);
1043
1044     return IME_ERROR_NONE;
1045 }
1046
1047 EXPORT_API int ime_commit_string(const char *str)
1048 {
1049     ime_error_e retVal = IME_ERROR_NONE;
1050
1051     if (!str) {
1052         LOGW("IME_ERROR_INVALID_PARAMETER");
1053         return IME_ERROR_INVALID_PARAMETER;
1054     }
1055
1056     if (!g_running) {
1057         LOGW("IME_ERROR_NOT_RUNNING");
1058         return IME_ERROR_NOT_RUNNING;
1059     }
1060
1061     retVal = _check_privilege();
1062     if (retVal != IME_ERROR_NONE) return retVal;
1063
1064     g_core.commit_string(-1, NULL, str);
1065
1066     return IME_ERROR_NONE;
1067 }
1068
1069 EXPORT_API int ime_show_preedit_string(void)
1070 {
1071     ime_error_e retVal = IME_ERROR_NONE;
1072
1073     if (!g_running) {
1074         LOGW("IME_ERROR_NOT_RUNNING");
1075         return IME_ERROR_NOT_RUNNING;
1076     }
1077
1078     retVal = _check_privilege();
1079     if (retVal != IME_ERROR_NONE) return retVal;
1080
1081     g_core.show_preedit_string(-1, NULL);
1082
1083     return IME_ERROR_NONE;
1084 }
1085
1086 EXPORT_API int ime_hide_preedit_string(void)
1087 {
1088     ime_error_e retVal = IME_ERROR_NONE;
1089
1090     if (!g_running) {
1091         LOGW("IME_ERROR_NOT_RUNNING");
1092         return IME_ERROR_NOT_RUNNING;
1093     }
1094
1095     retVal = _check_privilege();
1096     if (retVal != IME_ERROR_NONE) return retVal;
1097
1098     g_core.hide_preedit_string(-1, NULL);
1099
1100     return IME_ERROR_NONE;
1101 }
1102
1103 EXPORT_API int ime_update_preedit_string(const char *str, Eina_List *attrs)
1104 {
1105     ime_error_e retVal = IME_ERROR_NONE;
1106
1107     if (!str) {
1108         LOGW("IME_ERROR_INVALID_PARAMETER");
1109         return IME_ERROR_INVALID_PARAMETER;
1110     }
1111
1112     if (!g_running) {
1113         LOGW("IME_ERROR_NOT_RUNNING");
1114         return IME_ERROR_NOT_RUNNING;
1115     }
1116
1117     retVal = _check_privilege();
1118     if (retVal != IME_ERROR_NONE) return retVal;
1119
1120     scim::AttributeList attrv;
1121     void *data = NULL;
1122     ime_preedit_attribute *attr = NULL;
1123
1124     if (attrs) {
1125         EINA_LIST_FREE(attrs, data) {
1126             attr = (ime_preedit_attribute *)data;
1127             if (attr) {
1128                 attrv.push_back(scim::Attribute(attr->start, attr->length, (scim::AttributeType)attr->type, attr->value));
1129                 free(attr);
1130             }
1131         }
1132     }
1133
1134     g_core.update_preedit_string(-1, NULL, str, attrv);
1135
1136     return IME_ERROR_NONE;
1137 }
1138
1139 EXPORT_API int ime_request_surrounding_text(int maxlen_before, int maxlen_after)
1140 {
1141     ime_error_e retVal = IME_ERROR_NONE;
1142
1143     if (!g_event_callback.surrounding_text_updated) {
1144         LOGW("IME_ERROR_NO_CALLBACK_FUNCTION");
1145         return IME_ERROR_NO_CALLBACK_FUNCTION;
1146     }
1147
1148     if (!g_running) {
1149         LOGW("IME_ERROR_NOT_RUNNING");
1150         return IME_ERROR_NOT_RUNNING;
1151     }
1152
1153     retVal = _check_privilege();
1154     if (retVal != IME_ERROR_NONE) return retVal;
1155
1156     g_core.get_surrounding_text(NULL, maxlen_before, maxlen_after);
1157
1158     return IME_ERROR_NONE;
1159 }
1160
1161 EXPORT_API int ime_delete_surrounding_text(int offset, int len)
1162 {
1163     ime_error_e retVal = IME_ERROR_NONE;
1164
1165     if (len <= 0) {
1166         LOGW("IME_ERROR_INVALID_PARAMETER");
1167         return IME_ERROR_INVALID_PARAMETER;
1168     }
1169
1170     if (!g_running) {
1171         LOGW("IME_ERROR_NOT_RUNNING");
1172         return IME_ERROR_NOT_RUNNING;
1173     }
1174
1175     retVal = _check_privilege();
1176     if (retVal != IME_ERROR_NONE) return retVal;
1177
1178     g_core.delete_surrounding_text(offset, len);
1179
1180     return IME_ERROR_NONE;
1181 }
1182
1183 EXPORT_API int ime_get_surrounding_text(int maxlen_before, int maxlen_after, char **text, int *cursor_pos)
1184 {
1185     ime_error_e retVal = IME_ERROR_NONE;
1186
1187     if (!text || !cursor_pos) {
1188         LOGW("IME_ERROR_INVALID_PARAMETER");
1189         return IME_ERROR_INVALID_PARAMETER;
1190     }
1191
1192     if (!g_running) {
1193         LOGW("IME_ERROR_NOT_RUNNING");
1194         return IME_ERROR_NOT_RUNNING;
1195     }
1196
1197     retVal = _check_privilege();
1198     if (retVal != IME_ERROR_NONE) return retVal;
1199
1200     int cursor = 0;
1201
1202     int ret = g_core.get_surrounding_text(maxlen_before, maxlen_after, text, cursor);
1203     if (ret == -1) {
1204         LOGW("IME_ERROR_OUR_OF_MEMORY");
1205         return IME_ERROR_OUT_OF_MEMORY;
1206     }
1207
1208     if (cursor_pos)
1209         *cursor_pos = cursor;
1210
1211     return IME_ERROR_NONE;
1212 }
1213
1214 EXPORT_API int ime_set_selection(int start, int end)
1215 {
1216     ime_error_e retVal = IME_ERROR_NONE;
1217
1218     if (start < 0) {
1219         LOGW("IME_ERROR_INVALID_PARAMETER");
1220         return IME_ERROR_INVALID_PARAMETER;
1221     }
1222
1223     if (!g_running) {
1224         LOGW("IME_ERROR_NOT_RUNNING");
1225         return IME_ERROR_NOT_RUNNING;
1226     }
1227
1228     retVal = _check_privilege();
1229     if (retVal != IME_ERROR_NONE) return retVal;
1230
1231     g_core.set_selection(start, end);
1232
1233     return IME_ERROR_NONE;
1234 }
1235
1236 EXPORT_API int ime_get_selected_text(char **text)
1237 {
1238     ime_error_e retVal = IME_ERROR_NONE;
1239
1240     if (!text) {
1241         LOGW("IME_ERROR_INVALID_PARAMETER");
1242         return IME_ERROR_INVALID_PARAMETER;
1243     }
1244
1245     if (!g_running) {
1246         LOGW("IME_ERROR_NOT_RUNNING");
1247         return IME_ERROR_NOT_RUNNING;
1248     }
1249
1250     retVal = _check_privilege();
1251     if (retVal != IME_ERROR_NONE) return retVal;
1252
1253     g_core.get_selection_text(text);
1254
1255     return IME_ERROR_NONE;
1256 }
1257
1258 EXPORT_API Evas_Object* ime_get_main_window(void)
1259 {
1260     ime_error_e retVal = IME_ERROR_NONE;
1261
1262     Evas_Object *win = NULL;
1263
1264     retVal = _check_privilege();
1265     if (retVal != IME_ERROR_NONE) {
1266         LOGE("_check_privilege returned %d.", retVal);
1267         set_last_result(retVal);
1268         return NULL;
1269     }
1270
1271     if (!g_running) {
1272         set_last_result(IME_ERROR_NOT_RUNNING);
1273         LOGW("IME_ERROR_NOT_RUNNING");
1274         return NULL;
1275     }
1276
1277     win = static_cast<Evas_Object*>(g_core.get_main_window());
1278     if (win) {
1279         set_last_result(IME_ERROR_NONE);
1280     } else {
1281         set_last_result(IME_ERROR_OPERATION_FAILED);
1282         LOGW("IME_ERROR_OPERATION_FAILED");
1283     }
1284
1285     return win;
1286 }
1287
1288 EXPORT_API int ime_set_size(int portrait_width, int portrait_height, int landscape_width, int landscape_height)
1289 {
1290     ime_error_e retVal = IME_ERROR_NONE;
1291
1292     SclSize portrait_size, landscape_size;
1293
1294     if (portrait_width < 1 || portrait_height < 1 || landscape_width < 1 || landscape_height < 1) {
1295         LOGW("IME_ERROR_INVALID_PARAMETER");
1296         return IME_ERROR_INVALID_PARAMETER;
1297     }
1298
1299     if (!g_running) {
1300         LOGW("IME_ERROR_NOT_RUNNING");
1301         return IME_ERROR_NOT_RUNNING;
1302     }
1303
1304     retVal = _check_privilege();
1305     if (retVal != IME_ERROR_NONE) return retVal;
1306
1307     portrait_size.width = portrait_width;
1308     portrait_size.height = portrait_height;
1309
1310     landscape_size.width = landscape_width;
1311     landscape_size.height = landscape_height;
1312
1313     g_core.set_keyboard_size_hints(portrait_size, landscape_size);
1314
1315     return IME_ERROR_NONE;
1316 }
1317
1318 EXPORT_API int ime_create_option_window(void)
1319 {
1320     ime_error_e retVal = IME_ERROR_NONE;
1321
1322     if (!g_event_callback.option_window_created || !g_event_callback.option_window_destroyed) {
1323         LOGW("ime_create_option_window_cb() and ime_destroy_option_window_cb() callback functions are not set.");
1324         return IME_ERROR_NO_CALLBACK_FUNCTION;
1325     }
1326
1327     if (!g_running) {
1328         LOGW("IME_ERROR_NOT_RUNNING");
1329         return IME_ERROR_NOT_RUNNING;
1330     }
1331
1332     retVal = _check_privilege();
1333     if (retVal != IME_ERROR_NONE) return retVal;
1334
1335     if (g_core.create_option_window()) {
1336         return IME_ERROR_NONE;
1337     } else {
1338         LOGW("IME_ERROR_OPERATION_FAILED");
1339         return IME_ERROR_OPERATION_FAILED;
1340     }
1341 }
1342
1343 EXPORT_API int ime_destroy_option_window(Evas_Object *window)
1344 {
1345     ime_error_e retVal = IME_ERROR_NONE;
1346
1347     if (!g_event_callback.option_window_created || !g_event_callback.option_window_destroyed) {
1348         LOGW("ime_create_option_window_cb() and ime_destroy_option_window_cb() callback functions are not set.");
1349         return IME_ERROR_NO_CALLBACK_FUNCTION;
1350     }
1351
1352     if (!window) {
1353         LOGW("Window pointer is null.");
1354         return IME_ERROR_INVALID_PARAMETER;
1355     }
1356
1357     if (!g_running) {
1358         LOGW("IME_ERROR_NOT_RUNNING");
1359         return IME_ERROR_NOT_RUNNING;
1360     }
1361
1362     retVal = _check_privilege();
1363     if (retVal != IME_ERROR_NONE) return retVal;
1364
1365     g_core.destroy_option_window(window);
1366
1367     return IME_ERROR_NONE;
1368 }
1369
1370 //LCOV_EXCL_START
1371 EXPORT_API int ime_set_imengine(const char *engine_id)
1372 {
1373     ime_error_e retVal = IME_ERROR_NONE;
1374
1375     if (!engine_id) {
1376         LOGW("IME_ERROR_INVALID_PARAMETER");
1377         return IME_ERROR_INVALID_PARAMETER;
1378     }
1379
1380     retVal = _check_privilege();
1381     if (retVal != IME_ERROR_NONE) return retVal;
1382
1383     g_core.set_keyboard_ise_by_uuid(engine_id);
1384
1385     return IME_ERROR_NONE;
1386 }
1387
1388 EXPORT_API int ime_flush_imengine(void)
1389 {
1390     ime_error_e retVal = IME_ERROR_NONE;
1391
1392     if (!g_running) {
1393         LOGW("IME_ERROR_NOT_RUNNING");
1394         return IME_ERROR_NOT_RUNNING;
1395     }
1396
1397     retVal = _check_privilege();
1398     if (retVal != IME_ERROR_NONE) return retVal;
1399
1400     g_core.flush_keyboard_ise();
1401
1402     return IME_ERROR_NONE;
1403 }
1404
1405 EXPORT_API int ime_send_imengine_event(int command, unsigned int value)
1406 {
1407     ime_error_e retVal = IME_ERROR_NONE;
1408
1409     if (!g_running) {
1410         LOGW("IME_ERROR_NOT_RUNNING");
1411         return IME_ERROR_NOT_RUNNING;
1412     }
1413
1414     retVal = _check_privilege();
1415     if (retVal != IME_ERROR_NONE) return retVal;
1416
1417     g_core.send_imengine_event(-1, NULL, command, value);
1418
1419     return IME_ERROR_NONE;
1420 }
1421
1422 EXPORT_API int ime_reset_imengine(void)
1423 {
1424     ime_error_e retVal = IME_ERROR_NONE;
1425
1426     if (!g_running) {
1427         LOGW("IME_ERROR_NOT_RUNNING");
1428         return IME_ERROR_NOT_RUNNING;
1429     }
1430
1431     retVal = _check_privilege();
1432     if (retVal != IME_ERROR_NONE) return retVal;
1433
1434     g_core.reset_keyboard_ise();
1435
1436     return IME_ERROR_NONE;
1437 }
1438
1439 EXPORT_API int ime_update_input_context(unsigned int type, unsigned int value)
1440 {
1441     ime_error_e retVal = IME_ERROR_NONE;
1442
1443     if (!g_running) {
1444         LOGW("IME_ERROR_NOT_RUNNING");
1445         return IME_ERROR_NOT_RUNNING;
1446     }
1447
1448     retVal = _check_privilege();
1449     if (retVal != IME_ERROR_NONE) return retVal;
1450
1451     g_core.update_input_context(type, value);
1452
1453     return IME_ERROR_NONE;
1454 }
1455 //LCOV_EXCL_STOP
1456
1457 EXPORT_API int ime_request_hide(void)
1458 {
1459     ime_error_e retVal = IME_ERROR_NONE;
1460
1461     if (!g_running) {
1462         LOGW("IME_ERROR_NOT_RUNNING");
1463         return IME_ERROR_NOT_RUNNING;
1464     }
1465
1466     retVal = _check_privilege();
1467     if (retVal != IME_ERROR_NONE) return retVal;
1468
1469     g_core.request_ise_hide();
1470
1471     return IME_ERROR_NONE;
1472 }
1473
1474 //LCOV_EXCL_START
1475 EXPORT_API int ime_initialize(void)
1476 {
1477     ime_error_e retVal = IME_ERROR_NONE;
1478
1479     retVal = _check_privilege();
1480     if (retVal != IME_ERROR_NONE) return retVal;
1481
1482     g_core.init();
1483     g_running = false;
1484
1485     return retVal;
1486 }
1487
1488 EXPORT_API int ime_prepare(void)
1489 {
1490     ime_error_e retVal = IME_ERROR_NONE;
1491
1492     if (g_running) {
1493         LOGE("inputmethod main loop is already running.");
1494         return IME_ERROR_OPERATION_FAILED;
1495     }
1496
1497     retVal = _check_privilege();
1498     if (retVal != IME_ERROR_NONE) return retVal;
1499
1500     g_core.prepare();
1501
1502     g_running = true;
1503
1504     return retVal;
1505 }
1506
1507 EXPORT_API int ime_finalize(void)
1508 {
1509     ime_error_e retVal = IME_ERROR_NONE;
1510
1511     retVal = _check_privilege();
1512     if (retVal != IME_ERROR_NONE) return retVal;
1513
1514     g_core.fini();
1515     g_running = false;
1516     memset(&g_basic_callback, 0, sizeof(ime_callback_s));
1517     memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
1518     g_user_data = NULL;
1519
1520     return retVal;
1521 }
1522
1523 EXPORT_API int ime_select_candidate(unsigned int index)
1524 {
1525     ime_error_e retVal = IME_ERROR_NONE;
1526
1527     if (!g_running) {
1528         LOGW("IME_ERROR_NOT_RUNNING");
1529         return IME_ERROR_NOT_RUNNING;
1530     }
1531
1532     retVal = _check_privilege();
1533     if (retVal != IME_ERROR_NONE) return retVal;
1534
1535     g_core.select_candidate(index);
1536
1537     return IME_ERROR_NONE;
1538 }
1539 //LCOV_EXCL_STOP
1540
1541 EXPORT_API int ime_send_private_command(const char *command)
1542 {
1543     ime_error_e retVal = IME_ERROR_NONE;
1544
1545     if (!command) {
1546         LOGW("IME_ERROR_INVALID_PARAMETER");
1547         return IME_ERROR_INVALID_PARAMETER;
1548     }
1549
1550     if (!g_running) {
1551         LOGW("IME_ERROR_NOT_RUNNING");
1552         return IME_ERROR_NOT_RUNNING;
1553     }
1554
1555     retVal = _check_privilege();
1556     if (retVal != IME_ERROR_NONE) return retVal;
1557
1558     g_core.send_private_command(command);
1559
1560     return IME_ERROR_NONE;
1561 }
1562
1563 EXPORT_API int ime_commit_content(const char *content, const char *description, const char *mime_type)
1564 {
1565     ime_error_e retVal = IME_ERROR_NONE;
1566
1567     if (!content || !description || !mime_type) {
1568         LOGW("IME_ERROR_INVALID_PARAMETER");
1569         return IME_ERROR_INVALID_PARAMETER;
1570     }
1571
1572     retVal = _check_privilege();
1573     if (retVal != IME_ERROR_NONE) return retVal;
1574
1575     if (!g_running) {
1576         LOGW("IME_ERROR_NOT_RUNNING");
1577         return IME_ERROR_NOT_RUNNING;
1578     }
1579
1580     g_core.commit_content(content, description, mime_type);
1581
1582     return IME_ERROR_NONE;
1583 }
1584
1585 EXPORT_API int ime_context_get_layout(ime_context_h context, Ecore_IMF_Input_Panel_Layout *layout)
1586 {
1587     ime_error_e retVal = IME_ERROR_NONE;
1588
1589     if (!context || !layout) {
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     *layout = context->layout;
1603
1604     return IME_ERROR_NONE;
1605 }
1606
1607 EXPORT_API int ime_context_get_layout_variation(ime_context_h context, ime_layout_variation_e *layout_variation)
1608 {
1609     ime_error_e retVal = IME_ERROR_NONE;
1610
1611     if (!context || !layout_variation) {
1612         LOGW("IME_ERROR_INVALID_PARAMETER");
1613         return IME_ERROR_INVALID_PARAMETER;
1614     }
1615
1616     retVal = _check_privilege();
1617     if (retVal != IME_ERROR_NONE) return retVal;
1618
1619     if (!g_running) {
1620         LOGW("IME_ERROR_NOT_RUNNING");
1621         return IME_ERROR_NOT_RUNNING;
1622     }
1623
1624     *layout_variation = static_cast<ime_layout_variation_e>(context->layout_variation);
1625
1626     return IME_ERROR_NONE;
1627 }
1628
1629 EXPORT_API int ime_context_get_cursor_position(ime_context_h context, int *cursor_pos)
1630 {
1631     ime_error_e retVal = IME_ERROR_NONE;
1632
1633     if (!context || !cursor_pos) {
1634         LOGW("IME_ERROR_INVALID_PARAMETER");
1635         return IME_ERROR_INVALID_PARAMETER;
1636     }
1637
1638     retVal = _check_privilege();
1639     if (retVal != IME_ERROR_NONE) return retVal;
1640
1641     if (!g_running) {
1642         LOGW("IME_ERROR_NOT_RUNNING");
1643         return IME_ERROR_NOT_RUNNING;
1644     }
1645
1646     *cursor_pos = context->cursor_pos;
1647
1648     return IME_ERROR_NONE;
1649 }
1650
1651 EXPORT_API int ime_context_get_autocapital_type(ime_context_h context, Ecore_IMF_Autocapital_Type *autocapital_type)
1652 {
1653     ime_error_e retVal = IME_ERROR_NONE;
1654
1655     if (!context || !autocapital_type) {
1656         LOGW("IME_ERROR_INVALID_PARAMETER");
1657         return IME_ERROR_INVALID_PARAMETER;
1658     }
1659
1660     retVal = _check_privilege();
1661     if (retVal != IME_ERROR_NONE) return retVal;
1662
1663     if (!g_running) {
1664         LOGW("IME_ERROR_NOT_RUNNING");
1665         return IME_ERROR_NOT_RUNNING;
1666     }
1667
1668     *autocapital_type = context->autocapital_type;
1669
1670     return IME_ERROR_NONE;
1671 }
1672
1673 EXPORT_API int ime_context_get_return_key_type(ime_context_h context, Ecore_IMF_Input_Panel_Return_Key_Type *return_key_type)
1674 {
1675     ime_error_e retVal = IME_ERROR_NONE;
1676
1677     if (!context || !return_key_type) {
1678         LOGW("IME_ERROR_INVALID_PARAMETER");
1679         return IME_ERROR_INVALID_PARAMETER;
1680     }
1681
1682     retVal = _check_privilege();
1683     if (retVal != IME_ERROR_NONE) return retVal;
1684
1685     if (!g_running) {
1686         LOGW("IME_ERROR_NOT_RUNNING");
1687         return IME_ERROR_NOT_RUNNING;
1688     }
1689
1690     *return_key_type = context->return_key_type;
1691
1692     return IME_ERROR_NONE;
1693 }
1694
1695 EXPORT_API int ime_context_get_return_key_state(ime_context_h context, bool *return_key_state)
1696 {
1697     ime_error_e retVal = IME_ERROR_NONE;
1698
1699     if (!context || !return_key_state) {
1700         LOGW("IME_ERROR_INVALID_PARAMETER");
1701         return IME_ERROR_INVALID_PARAMETER;
1702     }
1703
1704     retVal = _check_privilege();
1705     if (retVal != IME_ERROR_NONE) return retVal;
1706
1707     if (!g_running) {
1708         LOGW("IME_ERROR_NOT_RUNNING");
1709         return IME_ERROR_NOT_RUNNING;
1710     }
1711
1712     *return_key_state = static_cast<bool>(context->return_key_disabled);
1713
1714     return IME_ERROR_NONE;
1715 }
1716
1717 EXPORT_API int ime_context_get_prediction_mode(ime_context_h context, bool *prediction_mode)
1718 {
1719     ime_error_e retVal = IME_ERROR_NONE;
1720
1721     if (!context || !prediction_mode) {
1722         LOGW("IME_ERROR_INVALID_PARAMETER");
1723         return IME_ERROR_INVALID_PARAMETER;
1724     }
1725
1726     retVal = _check_privilege();
1727     if (retVal != IME_ERROR_NONE) return retVal;
1728
1729     if (!g_running) {
1730         LOGW("IME_ERROR_NOT_RUNNING");
1731         return IME_ERROR_NOT_RUNNING;
1732     }
1733
1734     *prediction_mode = static_cast<bool>(context->prediction_allow);
1735
1736     return IME_ERROR_NONE;
1737 }
1738
1739 EXPORT_API int ime_context_get_password_mode(ime_context_h context, bool *password_mode)
1740 {
1741     ime_error_e retVal = IME_ERROR_NONE;
1742
1743     if (!context || !password_mode) {
1744         LOGW("IME_ERROR_INVALID_PARAMETER");
1745         return IME_ERROR_INVALID_PARAMETER;
1746     }
1747
1748     retVal = _check_privilege();
1749     if (retVal != IME_ERROR_NONE) return retVal;
1750
1751     if (!g_running) {
1752         LOGW("IME_ERROR_NOT_RUNNING");
1753         return IME_ERROR_NOT_RUNNING;
1754     }
1755
1756     *password_mode = static_cast<bool>(context->password_mode);
1757
1758     return IME_ERROR_NONE;
1759 }
1760
1761 EXPORT_API int ime_context_get_input_hint(ime_context_h context, Ecore_IMF_Input_Hints *input_hint)
1762 {
1763     ime_error_e retVal = IME_ERROR_NONE;
1764
1765     if (!context || !input_hint) {
1766         LOGW("IME_ERROR_INVALID_PARAMETER");
1767         return IME_ERROR_INVALID_PARAMETER;
1768     }
1769
1770     retVal = _check_privilege();
1771     if (retVal != IME_ERROR_NONE) return retVal;
1772
1773     if (!g_running) {
1774         LOGW("IME_ERROR_NOT_RUNNING");
1775         return IME_ERROR_NOT_RUNNING;
1776     }
1777
1778     *input_hint = context->input_hint;
1779
1780     return IME_ERROR_NONE;
1781 }
1782
1783 EXPORT_API int ime_context_get_bidi_direction(ime_context_h context, Ecore_IMF_BiDi_Direction *bidi)
1784 {
1785     ime_error_e retVal = IME_ERROR_NONE;
1786
1787     if (!context || !bidi) {
1788         LOGW("IME_ERROR_INVALID_PARAMETER");
1789         return IME_ERROR_INVALID_PARAMETER;
1790     }
1791
1792     retVal = _check_privilege();
1793     if (retVal != IME_ERROR_NONE) return retVal;
1794
1795     if (!g_running) {
1796         LOGW("IME_ERROR_NOT_RUNNING");
1797         return IME_ERROR_NOT_RUNNING;
1798     }
1799
1800     *bidi = context->bidi_direction;
1801
1802     return IME_ERROR_NONE;
1803 }
1804
1805 EXPORT_API int ime_context_get_language(ime_context_h context, Ecore_IMF_Input_Panel_Lang *language)
1806 {
1807     ime_error_e retVal = IME_ERROR_NONE;
1808
1809     if (!context || !language) {
1810         LOGW("IME_ERROR_INVALID_PARAMETER");
1811         return IME_ERROR_INVALID_PARAMETER;
1812     }
1813
1814     retVal = _check_privilege();
1815     if (retVal != IME_ERROR_NONE) return retVal;
1816
1817     if (!g_running) {
1818         LOGW("IME_ERROR_NOT_RUNNING");
1819         return IME_ERROR_NOT_RUNNING;
1820     }
1821
1822     *language = context->language;
1823
1824     return IME_ERROR_NONE;
1825 }
1826
1827 //LCOV_EXCL_START
1828 EXPORT_API int ime_context_get_caps_mode(ime_context_h context, bool *caps_mode)
1829 {
1830     ime_error_e retVal = IME_ERROR_NONE;
1831
1832     if (!context || !caps_mode) {
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     *caps_mode = static_cast<bool>(context->caps_mode);
1846
1847     return IME_ERROR_NONE;
1848 }
1849 //LCOV_EXCL_STOP
1850
1851 EXPORT_API int ime_device_info_get_name(ime_device_info_h dev_info, char **dev_name)
1852 {
1853     ime_error_e retVal = IME_ERROR_NONE;
1854
1855     if (!dev_info || !dev_name) {
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     if (!dev_info->dev_name)
1869         *dev_name = strdup("");
1870     else
1871         *dev_name = strdup(dev_info->dev_name);
1872
1873     return IME_ERROR_NONE;
1874 }
1875
1876 EXPORT_API int ime_device_info_get_class(ime_device_info_h dev_info, Ecore_IMF_Device_Class *dev_class)
1877 {
1878     ime_error_e retVal = IME_ERROR_NONE;
1879
1880     if (!dev_info || !dev_class) {
1881         LOGW("IME_ERROR_INVALID_PARAMETER");
1882         return IME_ERROR_INVALID_PARAMETER;
1883     }
1884
1885     retVal = _check_privilege();
1886     if (retVal != IME_ERROR_NONE) return retVal;
1887
1888     if (!g_running) {
1889         LOGW("IME_ERROR_NOT_RUNNING");
1890         return IME_ERROR_NOT_RUNNING;
1891     }
1892
1893     *dev_class = dev_info->dev_class;
1894
1895     return IME_ERROR_NONE;
1896 }
1897
1898 EXPORT_API int ime_device_info_get_subclass(ime_device_info_h dev_info, Ecore_IMF_Device_Subclass *dev_subclass)
1899 {
1900     ime_error_e retVal = IME_ERROR_NONE;
1901
1902     if (!dev_info || !dev_subclass) {
1903         LOGW("IME_ERROR_INVALID_PARAMETER");
1904         return IME_ERROR_INVALID_PARAMETER;
1905     }
1906
1907     retVal = _check_privilege();
1908     if (retVal != IME_ERROR_NONE) return retVal;
1909
1910     if (!g_running) {
1911         LOGW("IME_ERROR_NOT_RUNNING");
1912         return IME_ERROR_NOT_RUNNING;
1913     }
1914
1915     *dev_subclass = dev_info->dev_subclass;
1916
1917     return IME_ERROR_NONE;
1918 }
1919
1920 //LCOV_EXCL_START
1921 EXPORT_API int ime_event_set_process_input_device_event_cb(ime_process_input_device_event_cb callback_func, void *user_data)
1922 {
1923     ime_error_e retVal = IME_ERROR_NONE;
1924
1925     if (!callback_func) {
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     g_event_callback.process_input_device_event = callback_func;
1934     g_event_callback.process_input_device_event_user_data = user_data;
1935
1936     return IME_ERROR_NONE;
1937 }
1938
1939 EXPORT_API int ime_event_unset_process_input_device_event_cb(void)
1940 {
1941     ime_error_e retVal = IME_ERROR_NONE;
1942
1943     retVal = _check_privilege();
1944     if (retVal != IME_ERROR_NONE) return retVal;
1945
1946     g_event_callback.process_input_device_event = NULL;
1947     g_event_callback.process_input_device_event_user_data = NULL;
1948
1949     return IME_ERROR_NONE;
1950 }
1951
1952 /* Functions for Rotary input device event */
1953 EXPORT_API int ime_input_device_rotary_get_direction(ime_input_device_event_h event_handle, ime_input_device_rotary_direction_e *direction)
1954 {
1955     ime_error_e retVal = IME_ERROR_NONE;
1956
1957     if (!event_handle || !direction) {
1958         LOGW("IME_ERROR_INVALID_PARAMETER");
1959         return IME_ERROR_INVALID_PARAMETER;
1960     }
1961
1962     ime_device_event_s *device_event = static_cast<ime_device_event_s*>(event_handle);
1963     if (device_event->device_type != IME_INPUT_DEVICE_TYPE_ROTARY) {
1964         LOGW("IME_ERROR_INVALID_PARAMETER");
1965         return IME_ERROR_INVALID_PARAMETER;
1966     }
1967
1968     retVal = _check_privilege();
1969     if (retVal != IME_ERROR_NONE) return retVal;
1970
1971     if (!g_running) {
1972         LOGW("IME_ERROR_OPERATION_FAILED");
1973         return IME_ERROR_OPERATION_FAILED;
1974     }
1975
1976     Ecore_Event_Detent_Rotate *rotary_device_event =
1977         static_cast<Ecore_Event_Detent_Rotate*>(device_event->event_data);
1978     if (rotary_device_event) {
1979         if (rotary_device_event->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) {
1980             *direction = IME_INPUT_DEVICE_ROTARY_DIRECTION_CLOCKWISE;
1981         } else if (rotary_device_event->direction == ECORE_DETENT_DIRECTION_COUNTER_CLOCKWISE) {
1982             *direction = IME_INPUT_DEVICE_ROTARY_DIRECTION_COUNTER_CLOCKWISE;
1983         }
1984     }
1985
1986     return IME_ERROR_NONE;
1987 }
1988 //LCOV_EXCL_STOP
1989
1990 EXPORT_API int ime_event_set_prediction_hint_set_cb(ime_prediction_hint_set_cb callback_func, void *user_data)
1991 {
1992     ime_error_e retVal = IME_ERROR_NONE;
1993
1994     if (!callback_func) {
1995         LOGW("IME_ERROR_INVALID_PARAMETER");
1996         return IME_ERROR_INVALID_PARAMETER;
1997     }
1998
1999     retVal = _check_privilege();
2000     if (retVal != IME_ERROR_NONE) return retVal;
2001
2002     g_event_callback.prediction_hint_set = callback_func;
2003     g_event_callback.prediction_hint_set_user_data = user_data;
2004
2005     return IME_ERROR_NONE;
2006 }
2007
2008 EXPORT_API int ime_event_set_mime_type_set_request_cb(ime_mime_type_set_request_cb callback_func, void *user_data)
2009 {
2010     ime_error_e retVal = IME_ERROR_NONE;
2011
2012     if (!callback_func) {
2013         LOGW("IME_ERROR_INVALID_PARAMETER");
2014         return IME_ERROR_INVALID_PARAMETER;
2015     }
2016
2017     retVal = _check_privilege();
2018     if (retVal != IME_ERROR_NONE) return retVal;
2019
2020     g_event_callback.mime_type_set = callback_func;
2021     g_event_callback.mime_type_set_user_data = user_data;
2022
2023     return IME_ERROR_NONE;
2024 }
2025
2026 EXPORT_API int ime_set_floating_mode(bool floating_mode)
2027 {
2028     ime_error_e retVal = IME_ERROR_NONE;
2029
2030     retVal = _check_privilege();
2031     if (retVal != IME_ERROR_NONE) return retVal;
2032
2033     if (!g_running) {
2034         LOGW("IME_ERROR_NOT_RUNNING");
2035         return IME_ERROR_NOT_RUNNING;
2036     }
2037
2038     g_core.set_floating_mode(floating_mode);
2039
2040     return IME_ERROR_NONE;
2041 }
2042
2043 EXPORT_API int ime_set_floating_drag_start(void)
2044 {
2045     ime_error_e retVal = IME_ERROR_NONE;
2046
2047     retVal = _check_privilege();
2048     if (retVal != IME_ERROR_NONE) return retVal;
2049
2050     if (!g_running) {
2051         LOGW("IME_ERROR_NOT_RUNNING");
2052         return IME_ERROR_NOT_RUNNING;
2053     }
2054
2055     g_core.set_floating_drag_enabled(true);
2056
2057     return IME_ERROR_NONE;
2058 }
2059
2060 EXPORT_API int ime_set_floating_drag_end(void)
2061 {
2062     ime_error_e retVal = IME_ERROR_NONE;
2063
2064     retVal = _check_privilege();
2065     if (retVal != IME_ERROR_NONE) return retVal;
2066
2067     if (!g_running) {
2068         LOGW("IME_ERROR_NOT_RUNNING");
2069         return IME_ERROR_NOT_RUNNING;
2070     }
2071
2072     g_core.set_floating_drag_enabled(false);
2073
2074     return IME_ERROR_NONE;
2075 }
2076
2077 //LCOV_EXCL_START
2078 EXPORT_API int ime_set_window_creation_defer_flag(bool flag)
2079 {
2080     ime_error_e retVal = IME_ERROR_NONE;
2081
2082     retVal = _check_privilege();
2083     if (retVal != IME_ERROR_NONE) return retVal;
2084
2085     g_core.set_window_creation_defer_flag(flag);
2086
2087     return IME_ERROR_NONE;
2088 }
2089 //LCOV_EXCL_STOP
2090
2091 EXPORT_API int ime_event_set_prediction_hint_data_set_cb(ime_prediction_hint_data_set_cb callback_func, void *user_data)
2092 {
2093     ime_error_e retVal = IME_ERROR_NONE;
2094
2095     if (!callback_func) {
2096         LOGW("IME_ERROR_INVALID_PARAMETER");
2097         return IME_ERROR_INVALID_PARAMETER;
2098     }
2099
2100     retVal = _check_privilege();
2101     if (retVal != IME_ERROR_NONE) return retVal;
2102
2103     g_event_callback.prediction_hint_data_set = callback_func;
2104     g_event_callback.prediction_hint_data_set_user_data = user_data;
2105
2106     return IME_ERROR_NONE;
2107 }
2108
2109 //LCOV_EXCL_START
2110 EXPORT_API int ime_event_set_optimization_hint_set_cb(ime_optimization_hint_set_cb callback_func, void *user_data)
2111 {
2112     LOGD("");
2113     ime_error_e retVal = IME_ERROR_NONE;
2114
2115     if (!callback_func) {
2116         LOGW("IME_ERROR_INVALID_PARAMETER");
2117         return IME_ERROR_INVALID_PARAMETER;
2118     }
2119
2120     LOGD("");
2121     retVal = _check_privilege();
2122     if (retVal != IME_ERROR_NONE) return retVal;
2123
2124     LOGD("");
2125     g_event_callback.optimization_hint_set = callback_func;
2126     g_event_callback.optimization_hint_set_user_data = user_data;
2127
2128     return IME_ERROR_NONE;
2129 }
2130 //LCOV_EXCL_STOP
2131
2132 EXPORT_API int ime_update_input_panel_event(ime_event_type_e type, unsigned int value)
2133 {
2134     ime_error_e retVal = IME_ERROR_NONE;
2135
2136     if (type < IME_EVENT_TYPE_LANGUAGE || type > IME_EVENT_TYPE_GEOMETRY) {
2137         LOGW("IME_ERROR_INVALID_PARAMETER");
2138         return IME_ERROR_INVALID_PARAMETER;
2139     }
2140
2141     if (!g_running) {
2142         LOGW("IME_ERROR_NOT_RUNNING");
2143         return IME_ERROR_NOT_RUNNING;
2144     }
2145
2146     retVal = _check_privilege();
2147     if (retVal != IME_ERROR_NONE) return retVal;
2148
2149     g_core.update_input_context((sclu32)type, value);
2150
2151     return IME_ERROR_NONE;
2152 }
2153
2154 EXPORT_API int ime_set_candidate_visibility_state(bool visible)
2155 {
2156     ime_error_e retVal = IME_ERROR_NONE;
2157
2158     if (!g_running) {
2159         LOGW("IME_ERROR_NOT_RUNNING");
2160         return IME_ERROR_NOT_RUNNING;
2161     }
2162
2163     retVal = _check_privilege();
2164     if (retVal != IME_ERROR_NONE) return retVal;
2165
2166     if (visible)
2167         g_core.show_candidate_string();
2168     else
2169         g_core.hide_candidate_string();
2170
2171     return IME_ERROR_NONE;
2172 }