Revert "Support language changes using H/W keyboard"
[platform/core/uifw/ise-default.git] / src / ise.cpp
1 /*
2  * Copyright (c) 2012 - 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
18 #include <stdlib.h>
19 #include <sys/types.h>
20 #include <unistd.h>
21 #include <sys/stat.h>
22 #include <fcntl.h>
23 #include <vconf.h>
24 #include <Ecore.h>
25 #include <Ecore_IMF.h>
26 #include <Elementary.h>
27 #include <sclui.h>
28 #include <sclutils.h>
29 #include <inputmethod.h>
30 #include <inputmethod_internal.h>
31 #include <app_control.h>
32 #include <app_preference.h>
33 #include <ode/internal-encryption.h>
34 #include "clipboard.h"
35 #include "autofill.h"
36 #include "ise.h"
37 #include "utils.h"
38 #include "option.h"
39 #include "languages.h"
40 #include "candidate-factory.h"
41 #include "ise-emoticon-mode.h"
42 #include "ise-emoticon-list.h"
43 #include "ise-stt-mode.h"
44 #include "ise-stt-option.h"
45 #include "ise-language-change.h"
46 #include "ise-tutorial-mode.h"
47 #include "modeindicator.h"
48 #include "w-input-smartreply.h"
49 #include "ise-floating-mode.h"
50 #include "ise-dbus.h"
51 #include "ise-sticker-mode.h"
52 #include "ise-nmt-mode.h"
53 #include "nmt.h"
54
55 #define EDJ_FILE                        RESDIR"/edje/" PROFILE_NAME"/customised_ctxpopup.edj"
56
57 #define EXIT_ISE_ON_HIDE 0
58 #define DEFER_ISE_CREATION 0
59
60 #define CANDIDATE_WINDOW_HEIGHT 84
61 using namespace scl;
62 #include <vector>
63 using namespace std;
64
65 static CSCLUI *g_ui = NULL;
66 CSCLUI* get_ui() { return g_ui; }
67
68 static int g_imdata_state = 0;
69
70 static sclboolean g_need_send_shift_event = FALSE;
71
72 extern void set_ise_imdata(const char * buf, size_t &len);
73 static void init_recent_used_punctuation();
74 static void update_recent_used_punctuation(const char *key_value);
75 static void set_ime_size(bool floating_mode, ISE_CANDIDATE_REQUEST candidate_req);
76 static sclboolean g_punctuation_popup_opened = FALSE;
77 static sclboolean g_popup_opened = FALSE;
78 static vector<string> g_recent_used_punctuation;
79 static const int MAX_DEFAULT_PUNCTUATION = 6;
80 static string g_default_punctuation[MAX_DEFAULT_PUNCTUATION] = {"-", "@", "'", "!", "?", ","};
81 static string g_current_punctuation[MAX_DEFAULT_PUNCTUATION-1] = {"RCENT1", "RCENT2", "RCENT3", "RCENT4", "RCENT5"};
82 static vector<string> g_softcandidate_string;
83 static bool g_input_panel_show = false;
84 static bool g_caps_mode_pending = false;
85 static bool g_floating_mode = false;
86 static bool g_candidate_more_view = false;
87 static bool g_ise_created = false;
88
89 static vector<string> g_lookup_table_strings;
90 static vector<string> g_smartreply_strings;
91 #if EXIT_ISE_ON_HIDE
92 static Ecore_Timer *exit_timer = NULL;
93 #endif
94
95 #define SOFT_CANDIDATE_DELETE_TIME (100.0/1000)
96 static Ecore_Timer *g_softcandidate_hide_timer = NULL;
97
98 static int g_ic = 0;
99 static int g_ic_smartreply = -1;
100
101 static KEYBOARD_STATE g_keyboard_state = {
102     0,
103     0,
104     ISE_LAYOUT_STYLE_NORMAL,
105     0,
106     FALSE,
107     TRUE,
108     FALSE,
109     "",
110     KEY_MODIFIER_NONE,
111     FALSE,
112     FALSE
113 };
114
115 KEYBOARD_STATE* get_keyboard_state() {
116     return &g_keyboard_state;
117 }
118
119 #define ISE_LAYOUT_NUMBERONLY_VARIATION_MAX 4
120 /*static const sclchar *_ise_numberonly_variation_name[ISE_LAYOUT_NUMBERONLY_VARIATION_MAX] = {
121     "DEFAULT", "SIG", "DEC", "SIGDEC"
122 };*/
123
124 #define SIG_DEC_SIZE        2
125 static scluint              _click_count = 0;
126 static const char          *_sig_dec[SIG_DEC_SIZE] = {".", "-"};
127 static scluint              _sig_dec_event[SIG_DEC_SIZE] = {'.', '-'};
128 static Ecore_Timer         *_commit_timer = NULL;
129
130 static sclu32               _context_layout = ISE_LAYOUT_STYLE_NORMAL;
131 static sclu32               _context_layout_variation = 0;
132
133 static Candidate           *g_candidate = NULL;
134 Candidate* get_candidate() {
135     return g_candidate;
136 }
137
138 static ISELanguageManager _language_manager;
139
140 class CandidateEventListener: public EventListener
141 {
142     public:
143         void on_event(const EventDesc &desc)
144         {
145             CSCLUI *ui = get_ui();
146             const MultiEventDesc &multidesc = dynamic_cast<const MultiEventDesc &>(desc);
147             LANGUAGE_INFO *info = _language_manager.get_language_info(_language_manager.get_current_language());
148
149             unsigned int smartreply_size = input_smartreply_get_reply_num();
150
151             switch (multidesc.type) {
152                 case MultiEventDesc::CANDIDATE_ITEM_MOUSE_DOWN:
153                     if (ime_autofill_get_exist()) {
154                         if (multidesc.index == 0) {
155                             string autofill_string = ime_autofill_get_string();
156                             ise_send_string(autofill_string.c_str());
157                         } else if (multidesc.index < (int)smartreply_size + 1) {
158                             ise_send_string(g_softcandidate_string[multidesc.index].c_str());
159                             ise_update_table(g_smartreply_strings);
160                         } else {
161                             if (info && info->load_in_ime)
162                                 ime_select_candidate(multidesc.index - smartreply_size - 1);
163                             else
164                                 engine_loader_select_candidate(multidesc.index - smartreply_size - 1);
165                         }
166                     } else {
167                         if (multidesc.index < (int)smartreply_size) {
168                             ise_send_string(g_softcandidate_string[multidesc.index].c_str());
169                             ise_update_table(g_smartreply_strings);
170                         }
171                         else {
172                             if (info && info->load_in_ime)
173                                 ime_select_candidate(multidesc.index - smartreply_size);
174                             else
175                                 engine_loader_select_candidate(multidesc.index - smartreply_size);
176                         }
177                     }
178                     break;
179                 case MultiEventDesc::CANDIDATE_MORE_VIEW_SHOW:
180                     // when more parts shows, click on the candidate will
181                     // not affect the key click event
182                     g_candidate_more_view = true;
183                     if (!g_input_panel_show)
184                         set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
185                     if (ui)
186                         ui->disable_input_events(TRUE);
187                     break;
188                 case MultiEventDesc::CANDIDATE_MORE_VIEW_HIDE:
189                     g_candidate_more_view = false;
190                     if (!g_input_panel_show)
191                         set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
192                     if (ui)
193                         ui->disable_input_events(FALSE);
194                     break;
195                 default: break;
196             }
197         }
198 };
199 static CandidateEventListener g_candidate_event_listener;
200
201 #define MVK_Shift_L 0xffe1
202 #define MVK_Caps_Lock 0xffe5
203 #define MVK_Shift_Off 0xffe1
204 #define MVK_Shift_On 0xffe2
205 #define MVK_Shift_Lock 0xffe6
206 #define MVK_Shift_Enable 0x9fe7
207 #define MVK_Shift_Disable 0x9fe8
208 #define MVK_space 0x020
209 #define MVK_Done 0xff0d
210
211 #define CM_KEY_LIST_SIZE         7
212 #define MULTITAP_TIMEOUT         3.0
213 #define USER_KEYSTRING_OPTION    "OPTION"
214 #define USER_KEYSTRING_EMOTICON  "EMOTICON_LAYOUT"
215 #define USER_KEYSTRING_CLIPBOARD "CLIPBOARD"
216 #define USER_KEYSTRING_VOICE     "STT_3X4"
217 #define USER_KEYSTRING_FLOATING  "FLOATING"
218 #define USER_KEYSTRING_STICKER   "STICKER_LAYOUT"
219 #define USER_KEYSTRING_TRANSLATION "TRANSLATION_LAYOUT"
220
221 #define USER_VOICE_LANGUAGE     "LANGUAGE"
222
223 static sclboolean           _cm_popup_opened = FALSE;
224 static const char          *_cm_key_list[CM_KEY_LIST_SIZE] = {USER_KEYSTRING_OPTION, USER_KEYSTRING_EMOTICON, USER_KEYSTRING_CLIPBOARD,
225                                                               USER_KEYSTRING_VOICE, USER_KEYSTRING_FLOATING, USER_KEYSTRING_STICKER, USER_KEYSTRING_TRANSLATION};
226 static scluint              _current_cm_key_id = 0;
227 static Evas_Object* _guide_popup_setting = NULL;
228 static Evas_Object* _guide_popup_space = NULL;
229
230 /*
231  * This callback class will receive all response events from SCL
232  * So you should perform desired tasks in this class.
233  */
234 class CUIEventCallback : public ISCLUIEventCallback
235 {
236 public :
237     Ecore_Timer* word_timer = NULL;
238     static Eina_Bool _multi_tap_timer_cb(void *data)
239     {
240         LOGD("Time Out");
241         ise_send_event(MVK_Done, KEY_MASK_NULL);
242         return ECORE_CALLBACK_CANCEL;
243     }
244     SCLEventReturnType on_event_key_clicked(SclUIEventDesc event_desc);
245     SCLEventReturnType on_event_drag_state_changed(SclUIEventDesc event_desc);
246     SCLEventReturnType on_event_notification(SCLUINotiType noti_type, SclNotiDesc *etc_info);
247 };
248
249 static CUIEventCallback callback;
250
251 int ise_get_imdata_state()
252 {
253     return g_imdata_state;
254 }
255
256 void ise_set_imdata_state(int state)
257 {
258     g_imdata_state = state;
259 }
260
261 static void update_candidate_table()
262 {
263     g_softcandidate_string.clear();
264     vector<string>::iterator iter;
265
266     g_smartreply_strings.clear();
267     input_smartreply_deinit();
268     g_ic_smartreply = -1;
269
270     // add autofill string
271     if (ime_autofill_get_exist())
272         g_softcandidate_string.push_back(ime_autofill_get_string());
273
274     // add lookup table string(s)
275     iter = g_lookup_table_strings.begin();
276     for (; iter != g_lookup_table_strings.end(); ++iter)
277     {
278         g_softcandidate_string.push_back(string(iter->c_str()));
279     }
280
281     ise_update_table(g_softcandidate_string);
282 }
283
284 static void _input_smartreply_notify_cb(void *user_data)
285 {
286     g_smartreply_strings.clear();
287     char *candidate = NULL;
288
289     if (input_smartreply_is_enabled()) {
290         /* Append newly added smartreply list */
291         int len = input_smartreply_get_reply_num();
292         if (len > 0) {
293             for (int i = 0; i < len; i++) {
294                 int type;
295                 char *reply = (char *)"";
296                 reply = input_smartreply_get_nth_item(i, &type);
297                 if (reply == NULL)
298                     continue;
299                 SECURE_LOGD("SmartReply = [%d] %s", i, reply);
300                 candidate = reply;
301                 if (candidate) {
302                     g_smartreply_strings.push_back(string(candidate));
303                     free(candidate);
304                     candidate = NULL;
305                 }
306             }
307             g_ic_smartreply = g_ic;
308
309             ise_app_candidate_show();
310             g_softcandidate_string = g_smartreply_strings;
311             ise_update_table(g_softcandidate_string);
312         }
313     }
314 }
315
316 sclboolean
317 check_ic_temporary(int ic)
318 {
319     if ((ic & 0xFFFF) == 0) {
320         return TRUE;
321     }
322     return FALSE;
323 }
324
325 static void _reset_shift_state(void)
326 {
327     CSCLUI *ui = get_ui();
328     if (ui) {
329         /* Reset all shift state variables */
330         SCLShiftState old_shift_state = ui->get_shift_state();
331         SCLShiftState new_shift_state = SCL_SHIFT_STATE_OFF;
332         if (old_shift_state != new_shift_state) {
333             g_need_send_shift_event = true;
334             ui->set_shift_state(new_shift_state);
335         }
336         LOGD("Shift state changed from (%d) to (%d)\n", (int)old_shift_state, (int)new_shift_state);
337     }
338 }
339
340 static void set_caps_mode(sclboolean mode) {
341     CSCLUI *ui = get_ui();
342     LOGD("mode : %d\n", mode);
343     if (ui) {
344         if (ui->get_shift_state() != SCL_SHIFT_STATE_LOCK) {
345             ui->set_shift_state(mode ? SCL_SHIFT_STATE_ON : SCL_SHIFT_STATE_OFF);
346             ui->set_autocapital_shift_state(!mode);
347
348             bool load_in_ime = false;
349             const sclchar *cur_lang = _language_manager.get_current_language();
350             if (cur_lang) {
351                 LANGUAGE_INFO *info = _language_manager.get_language_info(cur_lang);
352                 if (info)
353                     load_in_ime = info->load_in_ime;
354             }
355
356             if (load_in_ime)
357                 ime_send_imengine_event(mode ? MVK_Shift_On : MVK_Shift_Off, 0);
358             else
359                 engine_loader_send_imengine_event(mode ? MVK_Shift_On : MVK_Shift_Off, 0);
360         }
361     }
362 }
363
364 static void _reset_multitap_state(bool skip_commit = false)
365 {
366     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
367     if (!keyboard_state) return;
368
369     LOGD("keyboard_state.prev_modifier : %d", keyboard_state->prev_modifier);
370     if (keyboard_state->prev_modifier == KEY_MODIFIER_MULTITAP_START ||
371         keyboard_state->prev_modifier == KEY_MODIFIER_MULTITAP_REPEAT) {
372         if (!skip_commit) {
373             ise_send_string(keyboard_state->multitap_value.c_str());
374         }
375         ise_update_preedit_string("");
376     }
377     keyboard_state->multitap_value = "";
378     keyboard_state->prev_modifier = KEY_MODIFIER_NONE;
379     if (g_caps_mode_pending) {
380         g_caps_mode_pending = false;
381         set_caps_mode(keyboard_state->caps_mode);
382     }
383 }
384
385 static void ise_set_cm_private_key(scluint cm_key_id)
386 {
387     CSCLUI *ui = get_ui();
388     if (cm_key_id >= CM_KEY_LIST_SIZE || ui == NULL) {
389         LOGE("cm_key_id=%d\n", cm_key_id);
390         return;
391     }
392
393     if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_EMOTICON) == 0) {
394         sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
395             const_cast<sclchar*>("icon/54x54/icon_emotion_nor.png"),
396             const_cast<sclchar*>("icon/54x54/icon_emotion_press.png"),
397             const_cast<sclchar*>("icon/54x54/icon_emotion_dim.png")};
398         ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_EMOTICON), TRUE);
399     } else if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_OPTION) == 0) {
400         sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
401             const_cast<sclchar*>("icon/54x54/icon_setting_nor.png"),
402             const_cast<sclchar*>("icon/54x54/icon_setting_press.png"),
403             const_cast<sclchar*>("icon/54x54/icon_setting_dim.png")};
404         ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_OPTION), TRUE);
405     } else if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_CLIPBOARD) == 0) {
406         sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
407             const_cast<sclchar*>("icon/54x54/icon_clipboard_nor.png"),
408             const_cast<sclchar*>("icon/54x54/icon_clipboard_press.png"),
409             const_cast<sclchar*>("icon/54x54/icon_clipboard_dim.png")};
410         ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_CLIPBOARD), TRUE);
411     } else if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_VOICE) == 0) {
412         sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
413             const_cast<sclchar*>("icon/54x54/icon_mic_nor.png"),
414             const_cast<sclchar*>("icon/54x54/icon_mic_press.png"),
415             const_cast<sclchar*>("icon/54x54/icon_mic_dim.png")};
416         ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_VOICE), TRUE);
417     } else if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_FLOATING) == 0) {
418         sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
419             const_cast<sclchar*>("icon/54x54/icon_floating_keypad_nor.png"),
420             const_cast<sclchar*>("icon/54x54/icon_floating_keypad_press.png"),
421             const_cast<sclchar*>("icon/54x54/icon_floating_keypad_dim.png")};
422         ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_FLOATING), TRUE);
423     } else if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_TRANSLATION) == 0) {
424         sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
425             const_cast<sclchar*>("icon/54x54/icon_translation_nor.png"),
426             const_cast<sclchar*>("icon/54x54/icon_translation_press.png"),
427             const_cast<sclchar*>("icon/54x54/icon_translation_dim.png")};
428         ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_TRANSLATION), TRUE);
429     } else if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_STICKER) == 0) {
430         sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
431             const_cast<sclchar*>("icon/54x54/icon_sticker_nor.png"),
432             const_cast<sclchar*>("icon/54x54/icon_sticker_press.png"),
433             const_cast<sclchar*>("icon/54x54/icon_sticker_dim.png")};
434         ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_STICKER), TRUE);
435     }
436 }
437
438 static void ise_update_space_key(void)
439 {
440     CSCLUI *ui = get_ui();
441     if (ui == NULL) {
442         LOGE("ui = NULL\n");
443         return;
444     }
445
446     scluint num = _language_manager.get_enabled_languages_num();
447     LOGD("language number: %d\n", num);
448     if (num <= 1) {
449         LANGUAGE_INFO *info = _language_manager.get_language_info(_language_manager.get_current_language());
450         if (info && info->enabled) {
451 #ifdef _WEARABLE
452             sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
453                 const_cast<sclchar*>("w_sip_3x4_btn_ic_space_no_arrow.png"),
454                 const_cast<sclchar*>("w_sip_3x4_btn_ic_space_no_arrow.png"),
455                 const_cast<sclchar*>("w_sip_3x4_btn_ic_space_no_arrow.png")};
456             ui->set_private_key("SPACE_KEY", const_cast<sclchar*>(info->display_name.c_str()), imagelabel, NULL, 0, const_cast<sclchar*>("Space"), TRUE);
457 #else
458             ui->enable_button("SPACE_ARROW_LEFT", false);
459             ui->enable_button("SPACE_ARROW_RIGHT", false);
460 #endif
461         }
462     } else {
463 #ifdef _WEARABLE
464         ui->unset_private_key("SPACE_KEY");
465 #else
466         ui->enable_button("SPACE_ARROW_LEFT", true);
467         ui->enable_button("SPACE_ARROW_RIGHT", true);
468 #endif
469     }
470 }
471
472 static scluint ise_get_cm_key_id(const sclchar *key_value)
473 {
474     for (int i = 0; i < CM_KEY_LIST_SIZE; ++i) {
475         if (0 == strcmp (key_value, _cm_key_list[i]))
476             return i;
477     }
478     return 0;
479 }
480
481 static bool ise_is_emoticons_disabled(void)
482 {
483     bool ret = true;
484
485     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
486     if (!keyboard_state) return ret;
487
488     sclu32 current_layout = keyboard_state->layout;
489     LOGD("layout=%d\n", current_layout);
490
491     if ((current_layout == ISE_LAYOUT_STYLE_NORMAL) ||
492         (current_layout == ISE_LAYOUT_STYLE_NUMBER) ||
493         (current_layout == ISE_LAYOUT_STYLE_EMOTICON))
494         ret = false;
495
496     if (g_imdata_state & IMDATA_ACTION_DISABLE_EMOTICONS)
497         ret = true;
498
499     return ret;
500 }
501
502 static Eina_Bool softcandidate_hide_timer_callback(void *data)
503 {
504     LOGD("Enter\n");
505     set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_HIDE);
506
507     Candidate *candidate = get_candidate();
508     if (candidate) {
509         candidate->hide();
510     }
511     return ECORE_CALLBACK_CANCEL;
512 }
513
514 static void delete_softcandidate_hide_timer(void)
515 {
516     if (g_softcandidate_hide_timer) {
517         ecore_timer_del(g_softcandidate_hide_timer);
518         g_softcandidate_hide_timer = NULL;
519     }
520 }
521
522 static void add_softcandidate_hide_timer(void)
523 {
524     delete_softcandidate_hide_timer();
525     g_softcandidate_hide_timer = ecore_timer_add(SOFT_CANDIDATE_DELETE_TIME, softcandidate_hide_timer_callback, NULL);
526 }
527
528 static void create_softcandidate(void)
529 {
530     if (!g_candidate) {
531         g_candidate = CandidateFactory::make_candidate(CANDIDATE_MULTILINE, ime_get_main_window());
532         if (g_candidate) {
533             g_candidate->add_event_listener(&g_candidate_event_listener);
534         }
535     }
536 }
537
538 /**
539  * Send the given string to input framework
540  */
541 void
542 ise_send_string(const sclchar *key_value)
543 {
544     int ic = -1;
545     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
546     if (keyboard_state && !check_ic_temporary(keyboard_state->ic)) {
547         ic = keyboard_state->ic;
548     }
549     ime_commit_string(key_value);
550     LOGD("ic : %x, %s\n", ic, key_value);
551 }
552
553 /**
554 * Send the preedit string to input framework
555 */
556 void
557 ise_update_preedit_string(const sclchar *str, const sclboolean underline)
558 {
559     int ic = -1;
560     Eina_List *attr_list = NULL;
561     ime_preedit_attribute *preedit_attr;
562
563     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
564     if (keyboard_state && !check_ic_temporary(keyboard_state->ic)) {
565         ic = keyboard_state->ic;
566     }
567     if (underline) {
568         /* Count UTF-8 string length */
569         int len = 0;
570         const sclchar *s = str;
571         while (*s) len += (*s++ & 0xc0) != 0x80;
572
573         preedit_attr = (ime_preedit_attribute *)calloc(1, sizeof(ime_preedit_attribute));
574         if (preedit_attr) {
575             preedit_attr->start = 0;
576             preedit_attr->length = len;
577             preedit_attr->type = IME_ATTR_FONTSTYLE;
578             preedit_attr->value = IME_ATTR_FONTSTYLE_UNDERLINE;
579             attr_list = eina_list_append(attr_list, (void *)preedit_attr);
580         }
581
582         ime_update_preedit_string(str, attr_list);
583     } else {
584         ime_update_preedit_string(str, NULL);
585     }
586     LOGD("ic : %x, %s\n", ic, str);
587 }
588
589 /**
590 * Send the given event to input framework
591 */
592 void
593 ise_send_event(sclulong key_event, sclulong key_mask)
594 {
595     int ic = -1;
596     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
597     if (keyboard_state && !check_ic_temporary(keyboard_state->ic)) {
598         ic = keyboard_state->ic;
599     }
600     ime_send_key_event((ime_key_code_e)key_event, IME_KEY_MASK_PRESSED, false);
601     ime_send_key_event((ime_key_code_e)key_event, IME_KEY_MASK_RELEASED, false);
602
603     LOGD("ic : %x, %lx\n", (unsigned int)ic, key_event);
604 }
605
606 /**
607 * Forward the given event to input framework
608 */
609 void
610 ise_forward_key_event(sclulong key_event)
611 {
612     int ic = -1;
613     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
614     if (!check_ic_temporary(keyboard_state->ic)) {
615         ic = keyboard_state->ic;
616     }
617     ime_send_key_event((ime_key_code_e)key_event, IME_KEY_MASK_PRESSED, true);
618     ime_send_key_event((ime_key_code_e)key_event, IME_KEY_MASK_RELEASED, true);
619
620     LOGD("ic : %x, %lx\n", (unsigned int)ic, key_event);
621 }
622
623 /**
624  * @brief Delete commit timer.
625  *
626  * @return void
627  */
628 static void delete_commit_timer(void)
629 {
630     if (_commit_timer != NULL) {
631         ecore_timer_del(_commit_timer);
632         _commit_timer = NULL;
633     }
634 }
635
636 /**
637  * @brief Callback function for commit timer.
638  *
639  * @param data Data to pass when it is called.
640  *
641  * @return ECORE_CALLBACK_CANCEL
642  */
643 static Eina_Bool commit_timeout(void *data)
644 {
645     if (_commit_timer != NULL) {
646         ime_hide_preedit_string();
647         ise_forward_key_event(_sig_dec_event[(_click_count-1)%SIG_DEC_SIZE]);
648         _click_count = 0;
649     }
650     _commit_timer = NULL;
651     return ECORE_CALLBACK_CANCEL;
652 }
653
654 static sclboolean
655 on_input_mode_changed(const sclchar *key_value, sclulong key_event, sclint key_type)
656 {
657     sclboolean ret = FALSE;
658
659     CSCLUI *ui = get_ui();
660     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
661     if (ui && keyboard_state) {
662         if (key_value) {
663             SECURE_LOGD("key_value : %s\n", key_value);
664             if (strcmp(key_value, "CUR_LANG") == 0) {
665                 keyboard_state->disable_force_latin = TRUE;
666                 ret = _language_manager.select_current_language();
667             }
668             if (strcmp(key_value, "NEXT_LANG") == 0) {
669                 keyboard_state->disable_force_latin = TRUE;
670                 ret = _language_manager.select_next_language();
671             }
672         }
673
674         const sclchar *cur_lang = _language_manager.get_current_language();
675         if (cur_lang) {
676             LANGUAGE_INFO *info = _language_manager.get_language_info(cur_lang);
677             if (info) {
678                 if (info->accepts_caps_mode) {
679                     if (info->load_in_ime)
680                         ime_send_imengine_event(MVK_Shift_Enable, 0);
681                     else
682                         engine_loader_send_imengine_event(MVK_Shift_Enable, 0);
683
684                     set_caps_mode(keyboard_state->caps_mode);
685                 } else {
686                     if (info->load_in_ime)
687                         ime_send_imengine_event(MVK_Shift_Disable, 0);
688                     else
689                         engine_loader_send_imengine_event(MVK_Shift_Disable, 0);
690
691                     ui->set_shift_state(SCL_SHIFT_STATE_OFF);
692                 }
693             }
694         }
695
696         if (ise_sticker_is_show())
697             ise_sticker_destroy_layout();
698
699         if (ise_emoticon_is_show()) {
700             ise_emoticon_destroy_layout();
701         }
702
703         if (ise_nmt_is_show()) {
704             ise_nmt_destroy_layout();
705         }
706
707         if (key_value) {
708             if (!strcmp(key_value, USER_KEYSTRING_EMOTICON)) {
709                 ise_emoticon_init_list();
710 #ifdef _WEARABLE
711                     ise_emoticon_set_current_group(EMOTICON_GROUP_1);
712 #else
713                 if (ise_emoticon_get_recent_list_size() == 0)
714                     ise_emoticon_set_current_group(EMOTICON_GROUP_1);
715                 else
716                     ise_emoticon_set_current_group(EMOTICON_GROUP_RECENTLY_USED);
717 #endif
718                 SCLRotation rotation = ui->get_rotation();
719                 ise_emoticon_show_layout(ise_emoticon_get_current_group(), ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
720             }
721             else if (!strcmp(key_value, USER_KEYSTRING_TRANSLATION)) {
722                 LOGD("");
723                 SCLRotation rotation = ui->get_rotation();
724                 ise_nmt_show_layout(ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
725             }
726         }
727     }
728
729     return ret;
730 }
731
732 SCLEventReturnType CUIEventCallback::on_event_notification(SCLUINotiType noti_type, SclNotiDesc *etc_info)
733 {
734     CSCLUI *ui = get_ui();
735     SCLEventReturnType ret = SCL_EVENT_PASS_ON;
736     LOGD("noti type: %d, g_need_send_shift_event: %d\n", noti_type, g_need_send_shift_event);
737
738     if (noti_type == SCL_UINOTITYPE_SHIFT_STATE_CHANGE) {
739         if (g_need_send_shift_event) {
740             const sclchar *cur_lang = _language_manager.get_current_language();
741             if (cur_lang) {
742                 LANGUAGE_INFO *info = _language_manager.get_language_info(cur_lang);
743                 SclNotiShiftStateChangeDesc *desc = static_cast<SclNotiShiftStateChangeDesc*>(etc_info);
744                 if (info && desc) {
745                     if (info->accepts_caps_mode) {
746                         LOGD("shift state: %d\n", desc->shift_state);
747                         if (desc->shift_state == SCL_SHIFT_STATE_OFF) {
748                             if (info->load_in_ime)
749                                 ime_send_imengine_event(MVK_Shift_Off, 0);
750                             else
751                                 engine_loader_send_imengine_event(MVK_Shift_Off, 0);
752                         } else if (desc->shift_state == SCL_SHIFT_STATE_ON) {
753                             if (info->load_in_ime)
754                                 ime_send_imengine_event(MVK_Shift_On, 0);
755                             else
756                                 engine_loader_send_imengine_event(MVK_Shift_On, 0);
757                         } else if (desc->shift_state == SCL_SHIFT_STATE_LOCK) {
758                             if (info->load_in_ime)
759                                 ime_send_imengine_event(MVK_Shift_Lock, 0);
760                             else
761                                 engine_loader_send_imengine_event(MVK_Shift_Lock, 0);
762                         }
763                         ret = SCL_EVENT_PASS_ON;
764                     }
765                 }
766             }
767             g_need_send_shift_event = FALSE;
768         }
769     } else if (noti_type == SCL_UINOTITYPE_POPUP_OPENING) {
770         vector<string>::reverse_iterator iter = g_recent_used_punctuation.rbegin();
771         int punc_pos = 0;
772         for (; iter != g_recent_used_punctuation.rend(); ++iter)
773         {
774             if (ui)
775                 ui->set_string_substitution(g_current_punctuation[punc_pos].c_str(), iter->c_str());
776             punc_pos++;
777         }
778         SclNotiPopupOpeningDesc *openingDesc = (SclNotiPopupOpeningDesc *)etc_info;
779         if (ui && 0 == strcmp(openingDesc->input_mode, "CM_POPUP")) {
780             if (!ise_sticker_check_sticker_exists())
781                 ui->enable_button("STICKER_KEY", EINA_FALSE);
782
783             if (nmt_is_disabled())
784                 ui->enable_button("TRANSLATION_KEY", false);
785             else
786                 ui->enable_button("TRANSLATION_KEY", true);
787
788             if (ise_is_emoticons_disabled())
789                 ui->enable_button("EMOTICON_KEY", false);
790             else
791                 ui->enable_button("EMOTICON_KEY", true);
792         }
793     } else if (noti_type == SCL_UINOTITYPE_POPUP_OPENED) {
794         g_popup_opened = TRUE;
795         SclNotiPopupOpenedDesc *openedDesc = (SclNotiPopupOpenedDesc *)etc_info;
796         if (0 == strcmp(openedDesc->input_mode, "PUNCTUATION_POPUP")) {
797             g_punctuation_popup_opened = TRUE;
798         } else if (0 == strcmp(openedDesc->input_mode, "CM_POPUP")) {
799             _cm_popup_opened = TRUE;
800         }
801     } else if (noti_type == SCL_UINOTITYPE_POPUP_CLOSED) {
802         g_popup_opened = FALSE;
803         SclNotiPopupClosedDesc *closedDesc = (SclNotiPopupClosedDesc *)etc_info;
804         if (closedDesc && closedDesc->input_mode) {
805             if (0 == strcmp(closedDesc->input_mode, "PUNCTUATION_POPUP")) {
806                 g_punctuation_popup_opened = FALSE;
807             } else if (0 == strcmp(closedDesc->input_mode, "CM_POPUP")) {
808                 _cm_popup_opened = FALSE;
809             }
810         }
811     } else if (noti_type == SCL_UINOTITYPE_INPUT_MODE_CHANGE) {
812         SclNotiInputModeChangeDesc *desc = static_cast<SclNotiInputModeChangeDesc*>(etc_info);
813         if (desc && ui) {
814             set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
815
816             const char *input_mode = ui->get_input_mode();
817             if (input_mode) {
818                 if (strcmp(input_mode, "STT_3X4") == 0 &&
819                         strcmp(desc->input_mode, "STT_3X4") != 0) {
820                     ise_hide_stt_mode();
821                 }
822                 if (strcmp(input_mode, "STT_3X4") != 0 &&
823                         strcmp(desc->input_mode, "STT_3X4") == 0) {
824                     ise_show_stt_mode(NATIVE_WINDOW_CAST(ime_get_main_window()));
825                 }
826             }
827         }
828     }
829
830     return ret;
831 }
832
833 void ise_destroy_popup_setting()
834 {
835     if (_guide_popup_setting != NULL) {
836         LOGD("destroy setting popup iter\n");
837         evas_object_del(_guide_popup_setting);
838         _guide_popup_setting = NULL;
839         CONFIG_VALUES *config_values = get_config_values();
840         if (config_values) {
841             config_values->first_guideset = TRUE;
842         }
843         write_ise_config_values();
844     }
845 }
846
847 void ise_destroy_popup_space()
848 {
849     if (_guide_popup_space != NULL) {
850         LOGD("destroy space popup iter\n");
851         evas_object_del(_guide_popup_space);
852         _guide_popup_setting = NULL;
853         CONFIG_VALUES *config_values = get_config_values();
854         if (config_values) {
855             config_values->first_guidechange = TRUE;
856         }
857         write_ise_config_values();
858     }
859 }
860
861 Evas_Object *open_message_popup(Evas_Object *parentWnd)
862 {
863     static Evas_Object *msg_window = NULL;
864     if (msg_window) {
865         evas_object_del(msg_window);
866         msg_window = NULL;
867     }
868     msg_window = elm_win_add(parentWnd, "MCFMessagePopup", ELM_WIN_UTILITY);
869     if (msg_window) {
870         int w, h;
871         elm_win_borderless_set(msg_window, EINA_TRUE);
872         elm_win_alpha_set(msg_window, EINA_TRUE);
873         elm_win_title_set(msg_window, "ISF Popup");
874         elm_win_screen_size_get(msg_window, NULL, NULL, &w, &h);
875         elm_win_prop_focus_skip_set(msg_window, TRUE);
876         int rots[4] = {0, 90, 180, 270};
877         elm_win_wm_rotation_available_rotations_set(msg_window, rots, 4);
878         evas_object_resize(msg_window, w, h);
879     }
880
881     int rots[4] = { 0, 90, 180, 270 };
882     elm_win_wm_rotation_available_rotations_set(msg_window, rots, 4);
883     evas_object_show(msg_window);
884     return msg_window;
885 }
886
887 void _guideline_popup_setting_cb(void *data, Evas_Object *obj, void *event_info)
888 {
889     evas_object_smart_callback_del(obj, "dismissed", _guideline_popup_setting_cb);
890     evas_object_del(obj);
891     obj = NULL;
892     ise_destroy_popup_setting();
893     CONFIG_VALUES *config_values = get_config_values();
894     if (config_values) {
895         config_values->first_guideset = TRUE;
896     }
897     write_ise_config_values();
898 }
899
900 void _guideline_popup_space_cb(void *data, Evas_Object *obj, void *event_info)
901 {
902     evas_object_smart_callback_del(obj, "dismissed", _guideline_popup_space_cb);
903     evas_object_del(obj);
904     obj = NULL;
905     ise_destroy_popup_space();
906     CONFIG_VALUES *config_values = get_config_values();
907     if (config_values) {
908         config_values->first_guidechange = TRUE;
909     }
910     write_ise_config_values();
911 }
912
913 bool get_landscape_device(int degree)
914 {
915     sclint width = 0;
916     sclint height = 0;
917     bool landscape_device = false;
918
919     CSCLUI *ui = get_ui();
920     if (!ui) return false;
921
922     ui->get_screen_resolution(&width, &height);
923
924     if (degree == 0 || degree == 180) {
925         if (width > height)
926             landscape_device = true;
927     }
928     else {
929         if (width < height)
930             landscape_device = true;
931     }
932
933     return landscape_device;
934 }
935
936 void ise_show_help_popup(sclulong keyEvent)
937 {
938     char buf[2048] = {0, };
939     int font_size = 40;
940     sclint scr_w = 0;
941     sclint scr_h = 0;
942     SclRectangle rectangle = {0};
943     Evas_Object *ctxpopup = NULL;
944     Elm_Theme *theme = NULL;
945
946     CSCLUI *ui = get_ui();
947     if (ui) {
948         ui->get_screen_resolution(&scr_w, &scr_h);
949
950         if (keyEvent == MVK_space) {
951             CONFIG_VALUES *config_values = get_config_values();
952             if (config_values) {
953                 config_values->first_guidechange = TRUE;
954             }
955             write_ise_config_values();
956             ui->get_button_geometry("SPACE_KEY", &rectangle);
957             _guide_popup_space = open_message_popup(NATIVE_WINDOW_CAST(ime_get_main_window()));
958
959             theme = elm_theme_new();
960             elm_theme_ref_set(theme, NULL);
961             elm_theme_extension_add(theme, EDJ_FILE);
962
963             ctxpopup = elm_ctxpopup_add(_guide_popup_space);
964             elm_object_theme_set(ctxpopup, theme);
965             evas_object_smart_callback_add(ctxpopup, "dismissed", _guideline_popup_space_cb, (void *)keyEvent);
966         } else {
967             CONFIG_VALUES *config_values = get_config_values();
968             if (config_values) {
969                 config_values->first_guideset = TRUE;
970             }
971             write_ise_config_values();
972             ui->get_button_geometry("CM_KEY", &rectangle);
973             _guide_popup_setting = open_message_popup(NATIVE_WINDOW_CAST(ime_get_main_window()));
974             theme = elm_theme_new();
975             elm_theme_ref_set(theme, NULL);
976             elm_theme_extension_add(theme, EDJ_FILE);
977             ctxpopup = elm_ctxpopup_add(_guide_popup_setting);
978             elm_object_theme_set(ctxpopup, theme);
979             evas_object_smart_callback_add(ctxpopup, "dismissed", _guideline_popup_setting_cb, (void *)keyEvent);
980         }
981     }
982
983     int rotation = elm_win_rotation_get(NATIVE_WINDOW_CAST(ime_get_main_window()));
984     bool landscape_device = get_landscape_device(rotation);
985     if (rotation == 0 || rotation == 180) {
986         elm_object_style_set(ctxpopup, landscape_device ? "customised_guideline_popup_landscape" : "customised_guideline_popup");
987     } else {
988         elm_object_style_set(ctxpopup, landscape_device ?  "customised_guideline_popup" : "customised_guideline_popup_landscape");
989     }
990
991     elm_ctxpopup_direction_priority_set(ctxpopup, ELM_CTXPOPUP_DIRECTION_UP,
992                           ELM_CTXPOPUP_DIRECTION_UNKNOWN,
993                           ELM_CTXPOPUP_DIRECTION_UNKNOWN,
994                           ELM_CTXPOPUP_DIRECTION_UNKNOWN);
995
996     Evas_Object* text = elm_label_add(ctxpopup);
997
998     if (keyEvent == MVK_space) {
999         snprintf(buf, sizeof(buf), "<font_style=Regular font_size=%d align=left wrap=mixed color=#000000>%s</>", font_size,
1000             dgettext(PACKAGE, "IDS_IME_BODY_SWIPE_THE_SPACE_BAR_LEFT_OR_RIGHT_TO_CHANGE_BETWEEN_LANGUAGES"));
1001     } else {
1002         snprintf(buf, sizeof(buf), "<font_style=Regular font_size=%d align=left wrap=mixed color=#000000>%s</>", font_size,
1003                dgettext(PACKAGE, "IDS_IME_BODY_TAP_AND_HOLD_THIS_KEY_TO_SEE_THE_SYMBOL_LIST_SELECT_ONE_TO_USE_IT_AS_A_SHORTCUT"));
1004     }
1005     elm_object_text_set(text, buf);
1006     elm_object_content_set(ctxpopup, text);
1007     Evas_Coord x, y, w, h;
1008     evas_object_geometry_get(NATIVE_WINDOW_CAST(ime_get_main_window()), &x, &y, &w, &h);
1009
1010     if (rotation == 0 || rotation == 180) {
1011         elm_label_wrap_width_set(text, (scr_w * 4) / 5);
1012         evas_object_size_hint_min_set(ctxpopup, ELM_SCALE_SIZE(scr_w), ELM_SCALE_SIZE(50));
1013         evas_object_size_hint_max_set(ctxpopup, ELM_SCALE_SIZE(scr_w), ELM_SCALE_SIZE(600));
1014         evas_object_move(ctxpopup, rectangle.x + rectangle.width / 2,
1015                     (scr_h - h) + rectangle.y - ELM_SCALE_SIZE(5));
1016     } else {
1017         elm_label_wrap_width_set(text, (scr_h * 4) / 5);
1018         evas_object_size_hint_min_set(ctxpopup, ELM_SCALE_SIZE(scr_h), ELM_SCALE_SIZE(50));
1019         evas_object_size_hint_max_set(ctxpopup, ELM_SCALE_SIZE(scr_h), ELM_SCALE_SIZE(600));
1020         evas_object_move(ctxpopup, rectangle.x + rectangle.width / 2,
1021                 (scr_w - h)+ rectangle.y - ELM_SCALE_SIZE(5));
1022     }
1023     elm_label_line_wrap_set(text, ELM_WRAP_MIXED);
1024     evas_object_show(text);
1025
1026     if (keyEvent == MVK_space) {
1027         evas_object_layer_set(_guide_popup_space, EVAS_LAYER_MAX);
1028         evas_object_show(_guide_popup_space);
1029     } else {
1030         evas_object_layer_set(_guide_popup_setting, EVAS_LAYER_MAX);
1031         evas_object_show(_guide_popup_setting);
1032     }
1033
1034     evas_object_layer_set(ctxpopup, EVAS_LAYER_MAX);
1035     evas_object_show(ctxpopup);
1036 }
1037
1038 SCLEventReturnType CUIEventCallback::on_event_drag_state_changed(SclUIEventDesc event_desc)
1039 {
1040     SECURE_LOGD("button %s is clicked\n", event_desc.key_value);
1041     if (event_desc.event_type == EVENT_TYPE_MOVE) {
1042         if (event_desc.key_event == MVK_space) {
1043             SclRectangle rectangle = {0};
1044             CSCLUI *ui = get_ui();
1045             if (ui) ui->get_button_geometry("SPACE_KEY", &rectangle);
1046             ise_show_space_flick_language_change_popup(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
1047         }
1048     } else if (event_desc.event_type == EVENT_TYPE_RELEASE) {
1049         if (event_desc.key_event == MVK_space) {
1050             ise_destroy_space_flick_language_change_popup();
1051         }
1052
1053         if (g_floating_mode)
1054             ime_set_floating_drag_end();
1055     } else if (event_desc.event_type == EVENT_TYPE_PRESS) {
1056 #if defined(_MOBILE) || defined(_COMMON)
1057         CONFIG_VALUES *config_values = get_config_values();
1058
1059         if (config_values && (!config_values->first_guideset) && event_desc.key_value && (strncmp(event_desc.key_value, "OPTION", strlen(event_desc.key_value)) == 0)) {
1060             ise_show_help_popup(event_desc.key_event);//show help popup in on_event_drag_state_changed other than on_event_key_clicked for fixing help popup show delay issue
1061             LOGD("setting popup show\n");
1062             return SCL_EVENT_PASS_ON;
1063         } else {
1064             ise_destroy_popup_setting();//destroy popup manually in case of abnormal situation
1065         }
1066 #endif
1067         if (g_floating_mode && event_desc.mouse_current_point.y <= FLOATING_TITLE_BAR_HEIGHT
1068             && event_desc.mouse_current_point.y >= 0)
1069             ime_set_floating_drag_start();
1070     }
1071     return SCL_EVENT_PASS_ON;
1072 }
1073
1074 static void launch_option()
1075 {
1076     app_control_h app_control;
1077     int ret = app_control_create(&app_control);
1078     if (ret != APP_CONTROL_ERROR_NONE) {
1079         LOGW("app_control_create returned %d\n", ret);
1080         return;
1081     }
1082
1083     ret = app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
1084     if (ret != APP_CONTROL_ERROR_NONE) {
1085         LOGW("app_control_set_operation returned %d\n", ret);
1086         goto end;
1087     }
1088
1089     ret = app_control_set_app_id(app_control, "org.tizen.ise-default-setting");
1090     if (ret != APP_CONTROL_ERROR_NONE) {
1091         LOGW("app_control_set_app_id returned %d\n", ret);
1092         goto end;
1093     }
1094
1095     app_control_add_extra_data(app_control, "caller", "ise-default");
1096     app_control_set_launch_mode(app_control, APP_CONTROL_LAUNCH_MODE_GROUP);
1097
1098     ret = app_control_send_launch_request(app_control, NULL, NULL);
1099     if (ret != APP_CONTROL_ERROR_NONE) {
1100         goto end;
1101     }
1102
1103 end:
1104     if (app_control)
1105         app_control_destroy(app_control);
1106 }
1107
1108 SCLEventReturnType CUIEventCallback::on_event_key_clicked(SclUIEventDesc event_desc)
1109 {
1110     SCLEventReturnType ret = SCL_EVENT_PASS_ON;
1111     if (word_timer != NULL) {
1112         ecore_timer_del(word_timer);
1113         word_timer = NULL;
1114     }
1115
1116     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1117     if (!keyboard_state) return ret;
1118
1119     if (event_desc.key_modifier == KEY_MODIFIER_MULTITAP_START) {
1120         if (!keyboard_state->multitap_value.empty()) {
1121             ise_send_string(keyboard_state->multitap_value.c_str());
1122         }
1123         ise_update_preedit_string(event_desc.key_value);
1124         keyboard_state->multitap_value = event_desc.key_value;
1125     } else if (event_desc.key_modifier == KEY_MODIFIER_MULTITAP_REPEAT) {
1126         ise_update_preedit_string(event_desc.key_value);
1127         keyboard_state->multitap_value = event_desc.key_value;
1128     } else {
1129         _reset_multitap_state();
1130     }
1131     keyboard_state->prev_modifier = event_desc.key_modifier;
1132
1133     CSCLUI *ui = get_ui();
1134     if (ui) {
1135         switch (event_desc.key_type) {
1136         case KEY_TYPE_STRING: {
1137             if (event_desc.key_modifier != KEY_MODIFIER_MULTITAP_START &&
1138                 event_desc.key_modifier != KEY_MODIFIER_MULTITAP_REPEAT) {
1139                     if (event_desc.key_event) {
1140                         ise_forward_key_event(event_desc.key_event);
1141                     } else {
1142                         ise_send_string(event_desc.key_value);
1143                     }
1144             }
1145             if (!g_popup_opened) {
1146                 const sclchar *input_mode = ui->get_input_mode();
1147                 if (input_mode && ((0 == strcmp(input_mode, "SYM_QTY_1")) || (0 == strcmp(input_mode, "SYM_QTY_2")))) {
1148                     update_recent_used_punctuation(event_desc.key_value);
1149                 }
1150             } else if (g_punctuation_popup_opened) {
1151                 update_recent_used_punctuation(event_desc.key_value);
1152             }
1153             break;
1154         }
1155         case KEY_TYPE_CHAR: {
1156                 sclboolean need_forward = FALSE;
1157                 // FIXME : Should decide when to forward key events
1158                 const sclchar *input_mode = ui->get_input_mode();
1159                 if (input_mode) {
1160                     if (strcmp(input_mode, "SYM_QTY_1") == 0 ||
1161                             strcmp(input_mode, "SYM_QTY_2") == 0 ||
1162                             strcmp(input_mode, "PHONE_3X4") == 0 ||
1163                             strcmp(input_mode, "IPv6_3X4_123") == 0 ||
1164                             strcmp(input_mode, "IPv6_3X4_ABC") == 0 ||
1165                             strcmp(input_mode, "NUMONLY_3X4") == 0 ||
1166                             strcmp(input_mode, "NUMONLY_3X4_SIG") == 0 ||
1167                             strcmp(input_mode, "NUMONLY_3X4_DEC") == 0 ||
1168                             strcmp(input_mode, "NUMONLY_3X4_SIGDEC") == 0 ||
1169                             strcmp(input_mode, "DATETIME_3X4") == 0) {
1170                         need_forward = TRUE;
1171                     }
1172                 }
1173                 if (input_mode && strcmp (input_mode, "NUMONLY_3X4_SIGDEC") == 0 &&
1174                     strcmp(event_desc.key_value, ".") == 0) {
1175                     ime_update_preedit_string(_sig_dec[_click_count%SIG_DEC_SIZE], NULL);
1176                     ime_show_preedit_string();
1177                     delete_commit_timer();
1178                     _commit_timer = ecore_timer_add(1.0, commit_timeout, NULL);
1179                     _click_count++;
1180                 } else if (event_desc.key_event) {
1181                     commit_timeout(NULL);
1182                     if (need_forward) {
1183                         ise_forward_key_event(event_desc.key_event);
1184                     } else {
1185                         if (_cm_popup_opened) {
1186                             static sclchar current_cm_symbol[2] = {'\0'};
1187                             sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
1188                                 const_cast<sclchar*>(" "),
1189                                 const_cast<sclchar*>(" "),
1190                                 const_cast<sclchar*>(" ")};
1191                             if (event_desc.key_value) {
1192                                 current_cm_symbol[0] = event_desc.key_value[0];
1193                                 current_cm_symbol[1] = '\0';
1194                             }
1195                             ui->set_private_key("CM_KEY",
1196                                     const_cast<sclchar*>(current_cm_symbol),
1197                                     imagelabel, NULL, 0,
1198                                     const_cast<sclchar*>(current_cm_symbol), TRUE);
1199
1200                             _cm_popup_opened = FALSE;
1201                             _current_cm_key_id = -1;
1202                         }
1203 #ifdef _WEARABLE
1204                         /*
1205                         *
1206                         *change the keyboard mode of GLM from QWERTY to KEYPAD
1207                         *ensure the Number keypad won't be affected
1208                         *
1209                         */
1210                         if (keyboard_state->layout == ISE_LAYOUT_STYLE_NUMBER) {
1211                             ime_send_key_event(IME_KEY_Print, IME_KEY_MASK_CONTROL, false);
1212                         } else {
1213                             Candidate *candidate = get_candidate();
1214                             if (word_timer == NULL && (!candidate || !candidate->get_visible())) {
1215                                 word_timer = ecore_timer_add(MULTITAP_TIMEOUT, _multi_tap_timer_cb, NULL);
1216                             }
1217                             ime_send_key_event(IME_KEY_Select, IME_KEY_MASK_CONTROL, false);
1218                         }
1219 #endif
1220                         ise_send_event(event_desc.key_event, KEY_MASK_NULL);
1221                     }
1222                 }
1223                 if (input_mode) {
1224                     if ((strcmp(input_mode, "SYM_QTY_1") == 0) || (0 == strcmp(input_mode, "SYM_QTY_2"))) {
1225                         update_recent_used_punctuation(event_desc.key_value);
1226                     }
1227                 }
1228                 break;
1229             }
1230         case KEY_TYPE_CONTROL: {
1231                 commit_timeout(NULL);
1232
1233                 const char *long_shift = "LongShift";
1234                 const char *caps_lock = "CapsLock";
1235                 const char *delete_all = "DeleteAll";
1236                 const char *hide_panel = "Hide";
1237                 if (strncmp(event_desc.key_value, long_shift, strlen(long_shift)) == 0) {
1238                     LOGD("shift key is longpress\n");
1239                     ui->set_shift_state(SCL_SHIFT_STATE_ON);
1240                     g_need_send_shift_event = TRUE;
1241                     //ise_send_event (MVK_Shift_Lock, KEY_MASK_NULL);
1242                 } else if (strncmp(event_desc.key_value, caps_lock, strlen(caps_lock)) == 0) {
1243                     bool load_in_ime = false;
1244                     const sclchar *cur_lang = _language_manager.get_current_language();
1245                     if (cur_lang) {
1246                         LANGUAGE_INFO *info = _language_manager.get_language_info(cur_lang);
1247                         if (info)
1248                             load_in_ime = info->load_in_ime;
1249                     }
1250
1251                     if (ui->get_shift_state() != SCL_SHIFT_STATE_LOCK) {
1252                         ui->set_shift_state(SCL_SHIFT_STATE_LOCK);
1253                         if (load_in_ime)
1254                             ime_send_imengine_event(MVK_Shift_Lock, 0);
1255                         else
1256                             engine_loader_send_imengine_event(MVK_Shift_Lock, 0);
1257                     } else {
1258                         ui->set_shift_state(SCL_SHIFT_STATE_OFF);
1259                         if (load_in_ime)
1260                             ime_send_imengine_event(MVK_Shift_Off, 0);
1261                         else
1262                             engine_loader_send_imengine_event(MVK_Shift_Off, 0);
1263                     }
1264                     //g_need_send_shift_event = TRUE;
1265                 } else if (strncmp(event_desc.key_value, delete_all, strlen(delete_all)) == 0) {
1266                     ime_delete_surrounding_text((INT_MAX / 2) * -1, INT_MAX);
1267                 } else if (strncmp(event_desc.key_value, hide_panel, strlen(hide_panel)) == 0) {
1268                     ise_hide();
1269                     ime_request_hide();
1270                 } else if (event_desc.key_event) {
1271                     if (keyboard_state->layout == ISE_LAYOUT_STYLE_VOICE) {
1272                         ise_stt_stop();
1273                     }
1274 #ifdef _WEARABLE
1275                     if (event_desc.key_event == MVK_Done) {
1276                         LOGD("ENTER");
1277                         //commit the preedit string first
1278                         ise_send_event(event_desc.key_event, KEY_MASK_NULL);
1279                     }
1280 #endif
1281                     ise_send_event(event_desc.key_event, KEY_MASK_NULL);
1282                     if (event_desc.key_event == MVK_Shift_L) {
1283                         g_need_send_shift_event = TRUE;
1284                     }
1285                 }
1286                 break;
1287            }
1288         case KEY_TYPE_MODECHANGE:
1289 #if defined(_MOBILE) || defined(_COMMON)
1290             if (_guide_popup_setting != NULL) {//popup is showing
1291                 break;
1292             }
1293 #endif
1294             if (strcmp(event_desc.key_value, USER_VOICE_LANGUAGE) == 0) {
1295                 if (!get_setting_window_open_status()) {
1296                     ise_hide_stt_mode();
1297 #ifdef _WEARABLE
1298                     hide_indicator_window();
1299 #endif
1300                     create_setting_window();
1301                 }
1302             } else if (strcmp(event_desc.key_value, USER_KEYSTRING_VOICE) == 0) {
1303                 keyboard_state->layout = ISE_LAYOUT_STYLE_VOICE;
1304                 ui->set_input_mode("STT_3X4");
1305
1306             } else if (strcmp(event_desc.key_value, USER_KEYSTRING_OPTION) == 0) {
1307                 launch_option();
1308
1309                 ret = SCL_EVENT_DONE;
1310             } else if (strcmp(event_desc.key_value, USER_KEYSTRING_CLIPBOARD) == 0) {
1311                 clipboard_show();
1312
1313                 ret = SCL_EVENT_DONE;
1314             } else if (strcmp(event_desc.key_value, USER_KEYSTRING_FLOATING) == 0) {
1315                 CONFIG_VALUES *config_values = get_config_values();
1316
1317                 if (g_floating_mode) {
1318                     if (config_values) {
1319                         config_values->floating_mode = false;
1320                     }
1321                 } else {
1322                     if (config_values) {
1323                         config_values->floating_mode = true;
1324                     }
1325                 }
1326                 write_ise_config_values();
1327
1328                 ret = SCL_EVENT_DONE;
1329             } else if (strcmp(event_desc.key_value, USER_KEYSTRING_STICKER) == 0) {
1330                 SCLRotation rotation = ui->get_rotation();
1331                 ise_sticker_show_layout(STICKER_GROUP_RECENTLY_USED, ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
1332             } else if (strcmp(event_desc.key_value, USER_KEYSTRING_TRANSLATION) == 0) {
1333                 if (ise_sticker_is_show())
1334                     ise_sticker_destroy_layout();
1335
1336                 SCLRotation rotation = ui->get_rotation();
1337                 ise_nmt_show_layout(ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
1338             } else if (on_input_mode_changed(event_desc.key_value, event_desc.key_event, event_desc.key_type)) {
1339                 ret = SCL_EVENT_DONE;
1340             }
1341             if (_cm_popup_opened) {
1342                 if (strcmp(event_desc.key_value, USER_KEYSTRING_EMOTICON) == 0 ||
1343                     strcmp(event_desc.key_value, USER_KEYSTRING_VOICE) == 0 ||
1344                     strcmp(event_desc.key_value, USER_KEYSTRING_FLOATING) == 0 ||
1345                     strcmp(event_desc.key_value, USER_KEYSTRING_STICKER) == 0 ||
1346                     strcmp(event_desc.key_value, USER_KEYSTRING_TRANSLATION) == 0) {
1347                     scluint id = ise_get_cm_key_id(event_desc.key_value);
1348                     if (id != _current_cm_key_id) {
1349                         _current_cm_key_id = id;
1350                         ise_set_cm_private_key(_current_cm_key_id);
1351                     }
1352                 }
1353                 _cm_popup_opened = FALSE;
1354             }
1355             if (strlen(event_desc.key_value) == 1) {
1356                 const char allowed_chars_in_modechange[] = {
1357                     ',', '?', '!', '`', '~', '@', '-'
1358                 };
1359                 const int allowed_chars_in_modechange_num =
1360                     sizeof(allowed_chars_in_modechange) / sizeof(char);
1361                 for (unsigned int loop = 0;loop < sizeof(allowed_chars_in_modechange_num);loop++) {
1362                     if (*(event_desc.key_value) == allowed_chars_in_modechange[loop]) {
1363                         ise_send_string(event_desc.key_value);
1364                     }
1365                 }
1366             }
1367             break;
1368         case KEY_TYPE_USER:
1369             if (strcmp(event_desc.key_value, USER_KEYSTRING_OPTION) == 0) {
1370                 //open_option_window(NULL, ROTATION_TO_DEGREE(ui->get_rotation()));
1371                 launch_option();
1372
1373                 ret = SCL_EVENT_DONE;
1374             } else if (strcmp(event_desc.key_value, USER_KEYSTRING_CLIPBOARD) == 0) {
1375                 clipboard_show();
1376                 ret = SCL_EVENT_DONE;
1377             } else if (strcmp(event_desc.key_value, "Cancel") == 0) {
1378                 ret = SCL_EVENT_DONE;
1379                 const sclchar *input_mode = ui->get_input_mode();
1380                 if (input_mode && strcmp(input_mode, "STT_3X4") == 0 ) {
1381                     keyboard_state->need_reset = TRUE;
1382                     voice_result_string_flush();
1383                     ise_set_layout(keyboard_state->layout, keyboard_state->layout_variation);
1384                     if (keyboard_state->visible_state)
1385                         ise_show(keyboard_state->ic);
1386                 }
1387 #ifdef _TV
1388                 ise_send_event(IME_KEY_Cancel, KEY_MASK_NULL);
1389                 ime_request_hide();
1390 #endif
1391             }  else if (strcmp(event_desc.key_value, "Done") == 0) {
1392 #ifdef _TV
1393                 ret = SCL_EVENT_DONE;
1394                 ise_send_event(IME_KEY_Return, KEY_MASK_NULL);
1395                 ime_request_hide();
1396 #endif
1397             } else if (strcmp(event_desc.key_value, "Translate") == 0) {
1398                 ise_nmt_translate();
1399             }  else {
1400                 const sclchar *input_mode = ui->get_input_mode();
1401                 if ((NULL != input_mode) && (!strcmp(input_mode, "EMOTICON_LAYOUT"))) {
1402                     if (ise_emoticon_is_show()) {
1403                         ise_emoticon_destroy_layout();
1404                     }
1405 #ifdef _WEARABLE
1406                     emoticon_group_t group_id = EMOTICON_GROUP_1;
1407                     if (ise_emoticon_get_current_group() < EMOTICON_GROUP_3)
1408                         group_id = (emoticon_group_t)(ise_emoticon_get_current_group() + 1);
1409
1410                     ise_set_emoticon_label(group_id);
1411 #else
1412                     emoticon_group_t group_id = ise_emoticon_get_group_id(event_desc.key_value);
1413 #endif
1414                     if ((group_id >= 0) && (group_id < MAX_EMOTICON_GROUP)) {
1415                         SCLRotation rotation = ui->get_rotation();
1416                         ise_emoticon_show_layout(group_id, ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
1417                     }
1418                 }
1419
1420                 if (input_mode && (!strcmp(input_mode, "STICKER_LAYOUT"))) {
1421                     if (ise_sticker_is_show())
1422                         ise_sticker_change_group(ise_sticker_get_group_id(event_desc.key_value));
1423                 }
1424             }
1425             if (_cm_popup_opened) {
1426                 if (strcmp(event_desc.key_value, USER_KEYSTRING_OPTION) == 0 ||
1427                     strcmp(event_desc.key_value, USER_KEYSTRING_CLIPBOARD) == 0 ||
1428                     strcmp(event_desc.key_value, USER_KEYSTRING_STICKER) == 0 ||
1429                     strcmp(event_desc.key_value, USER_KEYSTRING_TRANSLATION) == 0) {
1430                     scluint id = ise_get_cm_key_id(event_desc.key_value);
1431                     if (id != _current_cm_key_id) {
1432                         _current_cm_key_id = id;
1433                         ise_set_cm_private_key(_current_cm_key_id);
1434                     }
1435                 }
1436                 _cm_popup_opened = FALSE;
1437             }
1438             break;
1439         default:
1440             break;
1441         }
1442     }
1443
1444     return ret;
1445 }
1446
1447 void
1448 ise_set_layout(sclu32 layout, sclu32 layout_variation)
1449 {
1450     /* Check if the layoutIdx is in the valid range */
1451     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1452     if (layout < ISE_LAYOUT_STYLE_MAX) {
1453         if (keyboard_state->layout != layout ||
1454             keyboard_state->layout_variation != layout_variation) {
1455             keyboard_state->need_reset = TRUE;
1456         }
1457         keyboard_state->layout = layout;
1458         keyboard_state->layout_variation = layout_variation;
1459         LOGD("layout:%d, variation:%d\n", keyboard_state->layout, keyboard_state->layout_variation);
1460     }
1461 }
1462
1463 void
1464 ise_reset_context()
1465 {
1466     LOGD("");
1467     _reset_multitap_state(true);
1468     CONFIG_VALUES *config_values = get_config_values();
1469     if (config_values) {
1470         _language_manager.reset_language(config_values->selected_language.c_str());
1471     }
1472 }
1473
1474 void
1475 ise_reset_input_context()
1476 {
1477     LOGD("");
1478     _reset_multitap_state(true);
1479     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1480     if (keyboard_state) keyboard_state->disable_force_latin = FALSE;
1481     CONFIG_VALUES *config_values = get_config_values();
1482     if (config_values) {
1483         _language_manager.reset_language(config_values->selected_language.c_str());
1484     }
1485 }
1486
1487 void
1488 ise_focus_in(int ic)
1489 {
1490     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1491     if (!keyboard_state) return;
1492
1493     LOGD("ic : %x , %x , g_ic : %x , %x, g_focused_ic : %x , %x\n", ic, check_ic_temporary(ic),
1494             keyboard_state->ic, check_ic_temporary(keyboard_state->ic),
1495             keyboard_state->focused_ic, check_ic_temporary(keyboard_state->focused_ic));
1496     if (check_ic_temporary(keyboard_state->ic) && !check_ic_temporary(ic)) {
1497         keyboard_state->ic = ic;
1498     }
1499     keyboard_state->focused_ic = ic;
1500 }
1501
1502 static void save_autofill_data()
1503 {
1504     char *text = NULL;
1505     int cursor;
1506
1507     if (ime_autofill_get_hint() == 0)
1508         return;
1509
1510     ime_get_surrounding_text(-1, -1, &text, &cursor);
1511     SECURE_LOGD("surrounding text : %s\n", text);
1512     if (!text) return;
1513
1514     ime_autofill_save_string(text);
1515
1516     free(text);
1517 }
1518
1519 void
1520 ise_focus_out(int ic)
1521 {
1522     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1523     if (keyboard_state) keyboard_state->focused_ic = 0;
1524     _reset_multitap_state(true);
1525
1526     save_autofill_data();
1527 }
1528
1529 bool ise_is_guideline_popup_enable_layout(void)
1530 {
1531     bool ret;
1532     switch (_context_layout)
1533     {
1534         case ISE_LAYOUT_STYLE_PHONENUMBER:
1535         case ISE_LAYOUT_STYLE_IP:
1536         case ISE_LAYOUT_STYLE_MONTH:
1537         case ISE_LAYOUT_STYLE_NUMBERONLY:
1538         case ISE_LAYOUT_STYLE_HEX:
1539         case ISE_LAYOUT_STYLE_TERMINAL:
1540         case ISE_LAYOUT_STYLE_DATETIME:
1541         case ISE_LAYOUT_STYLE_PASSWORD:
1542             ret = false;
1543             break;
1544         default:
1545             ret = true;
1546             break;
1547     }
1548     return ret;
1549 }
1550
1551 #if EXIT_ISE_ON_HIDE
1552 static Eina_Bool exit_timer_cb(void *data)
1553 {
1554     if (exit_timer) ecore_timer_del(exit_timer);
1555     exit_timer = NULL;
1556     elm_exit();
1557     return ECORE_CALLBACK_CANCEL;
1558 }
1559 #endif
1560
1561 void
1562 ise_show(int ic)
1563 {
1564     CONFIG_VALUES *config_values = get_config_values();
1565 #if EXIT_ISE_ON_HIDE
1566     if (exit_timer) ecore_timer_del(exit_timer);
1567     exit_timer = NULL;
1568 #endif
1569     sclboolean reset_inputmode = FALSE;
1570     g_input_panel_show = true;
1571
1572     CSCLUI *ui = get_ui();
1573     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1574     if (ui && keyboard_state) {
1575         read_ise_config_values();
1576
1577         if (config_values) {
1578             _language_manager.set_enabled_languages(config_values->enabled_languages);
1579         }
1580         const sclchar *cur_lang = _language_manager.get_current_language();
1581
1582 #ifdef _WEARABLE
1583         ise_check_wearable_candidate();
1584         /*
1585          *Clear the personalized data
1586          */
1587         if (config_values && config_values->dataclear) {
1588             ime_send_key_event(IME_KEY_Clear, IME_KEY_MASK_CONTROL, false);
1589             config_values->dataclear = FALSE;
1590         }
1591 #endif
1592         LOGD("ic : %x , %x , g_ic : %x , %x, g_focused_ic : %x , %x\n", ic, check_ic_temporary(ic),
1593                 keyboard_state->ic, check_ic_temporary(keyboard_state->ic),
1594                 keyboard_state->focused_ic, check_ic_temporary(keyboard_state->focused_ic));
1595
1596         if (check_ic_temporary(ic) && !check_ic_temporary(keyboard_state->focused_ic)) {
1597             ic = keyboard_state->focused_ic;
1598         }
1599
1600         if (!check_ic_temporary(ic) && check_ic_temporary(keyboard_state->focused_ic)) {
1601             keyboard_state->focused_ic = ic;
1602         }
1603
1604         if (ic == keyboard_state->focused_ic) {
1605             switch (keyboard_state->layout)
1606             {
1607                 case ISE_LAYOUT_STYLE_PHONENUMBER:
1608                 case ISE_LAYOUT_STYLE_IP:
1609                 case ISE_LAYOUT_STYLE_MONTH:
1610                 case ISE_LAYOUT_STYLE_NUMBERONLY:
1611                     ime_set_imengine(DEFAULT_KEYBOARD_ISE_UUID);
1612                     break;
1613                 default:
1614                     break;
1615             }
1616         }
1617
1618         const char *input_mode = ui->get_input_mode();
1619
1620         /* Reset input mode if the input context value has changed */
1621         if (ic != keyboard_state->ic) {
1622             /* Do not reset input mode if STT's setting window was opened */
1623             if (get_setting_window_open_status() && input_mode && strcmp(input_mode, "STT_3X4") == 0) {
1624                 LOGD("Setting window was opened while using STT, skip resetting input mode");
1625             } else {
1626                 reset_inputmode = TRUE;
1627             }
1628         }
1629
1630         keyboard_state->ic = ic;
1631         /* Reset input mode if the current language is not the selected language */
1632         if (cur_lang) {
1633             if (config_values && config_values->selected_language.compare(cur_lang) != 0) {
1634                 reset_inputmode = TRUE;
1635             }
1636         }
1637
1638         /* No matter what, just reset the inputmode if it needs to */
1639         if (keyboard_state->need_reset) {
1640             /* Do not reset input mode if STT's setting window was opened */
1641             if (get_setting_window_open_status() && input_mode && strcmp(input_mode, "STT_3X4") == 0) {
1642                 LOGD("Setting window was opened while using STT, skip resetting input mode");
1643             } else {
1644                 reset_inputmode = TRUE;
1645             }
1646         }
1647         keyboard_state->need_reset = FALSE;
1648
1649         /* If the current layout requires latin language and current our language is not latin, enable the primary latin */
1650         sclboolean force_primary_latin = FALSE;
1651         LANGUAGE_INFO *info =
1652             (config_values ? _language_manager.get_language_info(config_values->selected_language.c_str()) : NULL);
1653         if (info) {
1654             if (!info->is_latin_language) {
1655                 if (!keyboard_state->disable_force_latin) {
1656                     if (g_ise_default_values[keyboard_state->layout].force_latin) {
1657                         force_primary_latin = TRUE;
1658                     }
1659                     else {
1660                         if (keyboard_state->prefer_latin) {
1661                             force_primary_latin = TRUE;
1662                         }
1663                     }
1664                 }
1665             }
1666         }
1667
1668         if (force_primary_latin) {
1669             /* If there is enabled latin-based language, select it */
1670             sclboolean selected = FALSE;
1671             for (scluint loop = 0;!selected && loop < _language_manager.get_languages_num();loop++) {
1672                 LANGUAGE_INFO *info = _language_manager.get_language_info(loop);
1673                 if (info) {
1674                     if (info->enabled && info->is_latin_language) {
1675                         selected = _language_manager.select_language(info->name.c_str());
1676                         if (selected) force_primary_latin = FALSE;
1677                     }
1678                 }
1679             }
1680             if (!selected) {
1681                 _language_manager.set_language_enabled_temporarily(PRIMARY_LATIN_LANGUAGE, TRUE);
1682             }
1683         }
1684
1685         if (reset_inputmode) {
1686             ise_reset_context();
1687
1688             bool filename_layout = false;
1689
1690             /* Turn the shift state off if we need to reset our input mode, only when auto-capitalization is not set  */
1691             if (!(keyboard_state->caps_mode)) {
1692                 ui->set_shift_state(SCL_SHIFT_STATE_OFF);
1693             }
1694             if (keyboard_state->layout < ISE_LAYOUT_STYLE_MAX) {
1695                 sclu32 layout_index = keyboard_state->layout;
1696                 if (keyboard_state->layout == ISE_LAYOUT_STYLE_NUMBERONLY &&
1697                     keyboard_state->layout_variation > 0 &&
1698                     keyboard_state->layout_variation < ISE_LAYOUT_NUMBERONLY_VARIATION_MAX) {
1699                     layout_index = ISE_LAYOUT_STYLE_NUMBERONLY_SIG + keyboard_state->layout_variation - 1;
1700                 } else if (keyboard_state->layout == ISE_LAYOUT_STYLE_PASSWORD && keyboard_state->layout_variation > 0) {
1701                     layout_index = ISE_LAYOUT_STYLE_PASSWD_3X4;
1702                 }
1703
1704                 if (keyboard_state->layout == ISE_LAYOUT_STYLE_NORMAL &&
1705                     keyboard_state->layout_variation == ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL_VARIATION_FILENAME)
1706                     filename_layout = true;
1707                 else
1708                     filename_layout = false;
1709
1710                 ui->enable_button("exclamation", !filename_layout);
1711                 ui->enable_button("question", !filename_layout);
1712                 ui->enable_button("divide", !filename_layout);
1713                 ui->enable_button("multiply", !filename_layout);
1714                 ui->enable_button("colon", !filename_layout);
1715                 ui->enable_button("quotation", !filename_layout);
1716
1717                 ui->enable_button("CM_KEY", !access("/home", X_OK));
1718
1719                 LOGD("new layout index : %d\n", layout_index);
1720                 /* If this layout requires specific input mode, set it */
1721                 if (strlen(g_ise_default_values[layout_index].input_mode) > 0) {
1722                     ui->set_input_mode(g_ise_default_values[layout_index].input_mode);
1723                     set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
1724                 } else {
1725                     if (force_primary_latin) {
1726                         _language_manager.select_language(PRIMARY_LATIN_LANGUAGE, TRUE);
1727                     } else if (config_values) {
1728                         if (!(_language_manager.select_language(config_values->selected_language.c_str()))) {
1729                             _language_manager.select_language(PRIMARY_LATIN_LANGUAGE);
1730                         }
1731                     }
1732                 }
1733                 ui->set_cur_sublayout(g_ise_default_values[layout_index].sublayout_name);
1734                 if (ise_emoticon_is_show()) {
1735                     ise_emoticon_destroy_layout();
1736                 }
1737
1738                 if (keyboard_state->layout == ISE_LAYOUT_STYLE_EMOTICON) {
1739                     ise_emoticon_init_list();
1740 #ifdef _WEARABLE
1741                     ise_emoticon_set_current_group(EMOTICON_GROUP_1);
1742                     ise_set_emoticon_label(1);
1743 #else
1744                     if (ise_emoticon_get_recent_list_size() == 0)
1745                         ise_emoticon_set_current_group(EMOTICON_GROUP_1);
1746                     else
1747                         ise_emoticon_set_current_group(EMOTICON_GROUP_RECENTLY_USED);
1748 #endif
1749                     SCLRotation rotation = ui->get_rotation();
1750                     ise_emoticon_show_layout(ise_emoticon_get_current_group(), ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
1751                 }
1752
1753                 if (ise_sticker_is_show())
1754                     ise_sticker_destroy_layout();
1755
1756                 if (ise_nmt_is_show())
1757                     ise_nmt_destroy_layout();
1758             }
1759         }
1760
1761         if (info) {
1762             if (info->accepts_caps_mode) {
1763                 // FIXME this if condition means the AC is off
1764                 if (keyboard_state->layout != ISE_LAYOUT_STYLE_NORMAL) {
1765                     ui->set_autocapital_shift_state(TRUE);
1766                     ui->set_shift_state(SCL_SHIFT_STATE_OFF);
1767                 } else {
1768                     ise_send_event(MVK_Shift_Enable, KEY_MASK_NULL);
1769                     // Auto Capital is supported only in normal layout
1770                     if (keyboard_state->caps_mode) {
1771                         ui->set_autocapital_shift_state(FALSE);
1772                     }
1773                 }
1774             } else {
1775                 ui->set_autocapital_shift_state(TRUE);
1776                 ise_send_event(MVK_Shift_Disable, KEY_MASK_NULL);
1777                 ui->set_shift_state(SCL_SHIFT_STATE_OFF);
1778             }
1779         } else {
1780             ui->set_autocapital_shift_state(TRUE);
1781         }
1782
1783         // Update CM key button
1784         if (_current_cm_key_id < CM_KEY_LIST_SIZE) {
1785             if (strcmp(_cm_key_list[_current_cm_key_id], USER_KEYSTRING_EMOTICON) == 0) {
1786                 if (ise_is_emoticons_disabled())
1787                     ise_set_cm_private_key(ise_get_cm_key_id(USER_KEYSTRING_OPTION));
1788                 else
1789                     ise_set_cm_private_key(_current_cm_key_id);
1790             }
1791         }
1792
1793         // Update space key button
1794         ise_update_space_key();
1795
1796         ui->show();
1797         ui->disable_input_events(FALSE);
1798 #ifdef _IVI
1799         ui->enable_button("CM_KEY", false);
1800 #endif
1801
1802 #if defined(_MOBILE) || defined(_COMMON)
1803         if (ise_is_guideline_popup_enable_layout()) {
1804             if ((config_values && config_values->first_guidechange) && (_language_manager.get_enabled_languages_num() > 1)) {
1805                 ise_show_help_popup(MVK_space);
1806                 LOGD("space popup show\n");
1807             } else {
1808                 ise_destroy_popup_space();
1809             }
1810         }
1811 #endif
1812
1813         // Update IME size
1814         if (config_values && config_values->floating_mode != g_floating_mode)
1815             g_floating_mode = config_values->floating_mode;
1816
1817         Candidate *candidate = get_candidate();
1818         if (candidate && candidate->get_visible())
1819             set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
1820         else
1821             set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
1822     }
1823
1824     keyboard_state->visible_state = TRUE;
1825
1826 #ifdef _WEARABLE
1827     int dot_num = 5;
1828     switch (_context_layout) {
1829         case ISE_LAYOUT_STYLE_PHONENUMBER:
1830         case ISE_LAYOUT_STYLE_IP:
1831         case ISE_LAYOUT_STYLE_MONTH:
1832         case ISE_LAYOUT_STYLE_NUMBERONLY:
1833         case ISE_LAYOUT_STYLE_DATETIME:
1834         case ISE_LAYOUT_STYLE_TERMINAL:
1835             dot_num = 0;
1836             break;
1837         case ISE_LAYOUT_STYLE_EMAIL:
1838         case ISE_LAYOUT_STYLE_URL:
1839             dot_num = 4;
1840             break;
1841         case ISE_LAYOUT_STYLE_PASSWORD:
1842             if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD &&
1843                 _context_layout_variation == ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD_VARIATION_NUMBERONLY)
1844                 dot_num = 0;
1845             else
1846                 dot_num = 3;
1847             break;
1848         default:
1849             dot_num = 5;
1850     }
1851
1852     if (dot_num > 0) {
1853         sclint width = 0;
1854         sclint height = 0;
1855         if (ui)
1856             ui->get_screen_resolution(&width, &height);
1857
1858         create_indicator_window(width, height);
1859         destroy_indicator_dots();
1860
1861         int focus_dot = 0;
1862         switch (keyboard_state->layout) {
1863             case ISE_LAYOUT_STYLE_NUMBER:
1864                 focus_dot = 1;
1865                 break;
1866             case ISE_LAYOUT_STYLE_HEX:
1867                 focus_dot = 2;
1868                 break;
1869             case ISE_LAYOUT_STYLE_EMOTICON:
1870                 focus_dot = 3;
1871                 break;
1872             case ISE_LAYOUT_STYLE_VOICE:
1873                 if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
1874                     _context_layout == ISE_LAYOUT_STYLE_URL)
1875                     focus_dot = 3;
1876                 else
1877                     focus_dot = 4;
1878                 break;
1879             default:
1880                 break;
1881         }
1882
1883         create_indicator_dots(dot_num, focus_dot);
1884         show_indicator_window();
1885     } else {
1886         hide_indicator_window();
1887     }
1888     if (keyboard_state->layout == ISE_LAYOUT_STYLE_NORMAL && config_values && config_values->number_tutorial_enable) {
1889         ise_show_tutorial_mode_popup(keyboard_state->layout);
1890         config_values->number_tutorial_enable = false;
1891         write_ise_config_values();
1892     }
1893 #endif
1894
1895     if (get_setting_window_open_status()) {
1896         ise_show_stt_mode(NATIVE_WINDOW_CAST(ime_get_main_window()));
1897     }
1898     set_setting_window_open_status(FALSE);
1899
1900     if (keyboard_state->layout == ISE_LAYOUT_STYLE_VOICE) {
1901         ise_show_stt_mode(NATIVE_WINDOW_CAST(ime_get_main_window()));
1902     }
1903 }
1904
1905 /**
1906  * Sets screen rotation
1907  */
1908 void
1909 ise_set_screen_rotation(int degree)
1910 {
1911     CSCLUI *ui = get_ui();
1912     if (ui) {
1913         ui->set_rotation(DEGREE_TO_SCLROTATION(degree));
1914     }
1915
1916     Candidate *candidate = get_candidate();
1917     if (candidate) {
1918         candidate->rotate(degree);
1919         if (candidate->get_visible()) {
1920             candidate->update(g_softcandidate_string);
1921         }
1922     }
1923 }
1924
1925 void
1926 ise_set_accessibility_state(bool state)
1927 {
1928     CSCLUI *ui = get_ui();
1929     if (ui) {
1930         ui->enable_tts(state);
1931     }
1932 }
1933
1934 void
1935 ise_hide()
1936 {
1937     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1938     CSCLUI *ui = get_ui();
1939     if (ui) {
1940         /* There's no need to update screen when hiding */
1941         ui->set_update_pending(TRUE);
1942         ui->disable_input_events(TRUE);
1943         ui->hide();
1944     }
1945     CONFIG_VALUES *config_values = get_config_values();
1946     if (config_values) {
1947         _language_manager.reset_language(config_values->selected_language.c_str());
1948     }
1949
1950     _click_count = 0;
1951     delete_commit_timer();
1952     ise_destroy_popup_space();
1953     ise_destroy_popup_setting();
1954
1955     if (keyboard_state) keyboard_state->visible_state = FALSE;
1956
1957     _reset_shift_state();
1958     _reset_multitap_state(true);
1959
1960     /* If we were in STT mode, try to reset input mode on our next show event */
1961     if (ui && keyboard_state) {
1962         const char *inputmode = ui->get_input_mode();
1963         if (inputmode && strcmp(inputmode, "STT_3X4") == 0 ) {
1964             keyboard_state->need_reset = TRUE;
1965             ise_hide_stt_mode();
1966         }
1967     }
1968
1969     g_input_panel_show = false;
1970     Candidate *candidate = get_candidate();
1971     if (candidate && candidate->get_visible())
1972         set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
1973 #ifdef _WEARABLE
1974     hide_indicator_window();
1975     if (check_is_tutorial_show()) {
1976         ise_destroy_tutorial_mode_popup();
1977     }
1978 #endif
1979 #if EXIT_ISE_ON_HIDE
1980     if (exit_timer) ecore_timer_del(exit_timer);
1981     exit_timer = ecore_timer_add(1.0, exit_timer_cb, NULL);
1982 #endif
1983 }
1984
1985 static void ise_keypad_mode_changed_cb(const char *key, void *user_data)
1986 {
1987     read_ise_keypad_mode();
1988 }
1989
1990 static void ise_enabled_languages_changed_cb(const char *key, void *user_data)
1991 {
1992     read_ise_enabled_languages();
1993 }
1994
1995 static void ise_selected_language_changed_cb(const char *key, void *user_data)
1996 {
1997     read_ise_selected_language();
1998 }
1999
2000 static void ise_autocapital_mode_changed_cb(const char *key, void *user_data)
2001 {
2002     read_ise_autocapital_mode();
2003 }
2004
2005 static void ise_autopunctuate_mode_changed_cb(const char *key, void *user_data)
2006 {
2007     read_ise_autopunctuation_mode();
2008 }
2009
2010 static void ise_sound_mode_changed_cb(const char *key, void *user_data)
2011 {
2012     read_ise_sound_mode();
2013
2014     CONFIG_VALUES *config_values = get_config_values();
2015     CSCLUI *ui = get_ui();
2016     if (config_values && ui) {
2017         ui->enable_sound(config_values->sound_on);
2018     }
2019 }
2020
2021 static void ise_vibration_mode_changed_cb(const char *key, void *user_data)
2022 {
2023     read_ise_vibration_mode();
2024
2025     CONFIG_VALUES *config_values = get_config_values();
2026     CSCLUI *ui = get_ui();
2027     if (config_values && ui) {
2028         ui->enable_vibration(config_values->vibration_on);
2029     }
2030 }
2031
2032 static void ise_character_preview_mode_changed_cb(const char *key, void *user_data)
2033 {
2034     read_ise_character_preview_mode();
2035
2036     CONFIG_VALUES *config_values = get_config_values();
2037     CSCLUI *ui = get_ui();
2038     if (config_values && ui) {
2039         ui->enable_magnifier(config_values->preview_on);
2040     }
2041 }
2042
2043 static void ise_setting_guide_popup_changed_cb(const char *key, void *user_data)
2044 {
2045     read_ise_setting_guide_popup_mode();
2046 }
2047
2048 static void ise_language_guide_popup_changed_cb(const char *key, void *user_data)
2049 {
2050     read_ise_language_guide_popup_mode();
2051 }
2052
2053 static void ise_floating_mode_changed_cb(const char *key, void *user_data)
2054 {
2055     read_ise_floating_mode();
2056     CONFIG_VALUES *config_values = get_config_values();
2057     if (config_values) {
2058         g_floating_mode = config_values->floating_mode;
2059     }
2060
2061     ime_set_floating_mode(g_floating_mode);
2062     if (g_candidate && g_floating_mode != g_candidate->get_floating_mode()) {
2063         delete_softcandidate_hide_timer();
2064         delete g_candidate;
2065         g_candidate = NULL;
2066
2067         create_softcandidate();
2068         if (g_candidate && g_candidate->get_visible()) {
2069             g_candidate->show();
2070             set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
2071             return;
2072         }
2073     }
2074     set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
2075 }
2076
2077 static void register_preference_changed_callback(void)
2078 {
2079     if (preference_set_changed_cb(ISE_CONFIG_KEYPAD_MODE, ise_keypad_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
2080         LOGW("Failed to set ise_keypad_mode_changed_cb()");
2081
2082     if (preference_set_changed_cb(ISE_CONFIG_ENABLED_LANGUAGES, ise_enabled_languages_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
2083         LOGW("Failed to set ise_enabled_languages_changed_cb()");
2084
2085     if (preference_set_changed_cb(ISE_CONFIG_SELECTED_LANGUAGE, ise_selected_language_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
2086         LOGW("Failed to set ise_selected_language_changed_cb()");
2087
2088     if (preference_set_changed_cb(ISE_CONFIG_AUTO_CAPITALISE, ise_autocapital_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
2089         LOGW("Failed to set ise_autocapital_mode_changed_cb()");
2090
2091     if (preference_set_changed_cb(ISE_CONFIG_AUTO_PUNCTUATE, ise_autopunctuate_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
2092         LOGW("Failed to set ise_autopunctuate_mode_changed_cb()");
2093
2094     if (preference_set_changed_cb(ISE_CONFIG_SOUND_ON, ise_sound_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
2095         LOGW("Failed to set ise_sound_mode_changed_cb()");
2096
2097     if (preference_set_changed_cb(ISE_CONFIG_VIBRATION_ON, ise_vibration_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
2098         LOGW("Failed to set ise_vibration_mode_changed_cb()");
2099
2100     if (preference_set_changed_cb(ISE_CONFIG_PREVIEW_ON, ise_character_preview_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
2101         LOGW("Failed to set ise_character_preview_mode_changed_cb()");
2102
2103     if (preference_set_changed_cb(ISE_CONFIG_FIRST_GUIDELINE_POPUP_FOR_SETTING, ise_setting_guide_popup_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
2104         LOGW("Failed to set ise_setting_guide_popup_changed_cb()");
2105
2106     if (preference_set_changed_cb(ISE_CONFIG_FIRST_GUIDELINE_POPUP_FOR_LANGUAGE_CHANGE, ise_language_guide_popup_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
2107         LOGW("Failed to set ise_language_guide_popup_changed_cb()");
2108
2109     if (preference_set_changed_cb(ISE_CONFIG_FLOATING_MODE, ise_floating_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
2110         LOGW("Failed to set ise_floating_mode_changed_cb()");
2111 }
2112
2113 static void ise_mount_changed_cb(void *user_data)
2114 {
2115     register_preference_changed_callback();
2116 }
2117
2118 void
2119 ise_create()
2120 {
2121     LOGD("");
2122
2123     CONFIG_VALUES *config_values = get_config_values();
2124
2125     if (!g_ui) {
2126         g_ui = new CSCLUI;
2127     }
2128
2129     bindtextdomain(PACKAGE, LOCALEDIR);
2130     textdomain(PACKAGE);
2131
2132     /* Set scl_parser_type
2133      * default type is text xml
2134      * use command: export sclres_type="sclres_binary" to enable use binary resource
2135      * please make sure there is sclresource.bin in resource folder
2136      * Or you can use `xml2binary $resource_dir` to generate the sclresource.bin
2137      * xml2binary is in the libscl-ui-devel package
2138      */
2139     SCLParserType scl_parser_type = SCL_PARSER_TYPE_XML;
2140     char* sclres_type = getenv("sclres_type");
2141     if (sclres_type != NULL && 0 == strcmp("sclres_binary", sclres_type)) {
2142         scl_parser_type = SCL_PARSER_TYPE_BINARY_XML;
2143     } else {
2144         scl_parser_type = SCL_PARSER_TYPE_XML;
2145     }
2146
2147     if (g_ui) {
2148         if (ime_get_main_window()) {
2149             g_ise_created = true;
2150
2151             sclboolean succeeded = FALSE;
2152
2153             const sclchar *entry_path = MAIN_ENTRY_XML_PATH;
2154             int nwidth  = 0;
2155             int nheight = 0;
2156             CSCLUtils *utils = CSCLUtils::get_instance();
2157             if (utils) {
2158                 utils->get_screen_resolution(&nwidth, &nheight);
2159             }
2160             _language_manager.set_resource_file_path(entry_path);
2161             const sclchar *resource_file_path = _language_manager.get_resource_file_path();
2162
2163             if (resource_file_path) {
2164                 if (strlen(resource_file_path) > 0) {
2165                     succeeded = g_ui->init(ime_get_main_window(), scl_parser_type, resource_file_path);
2166                 }
2167             }
2168             if (!succeeded) {
2169                 g_ui->init(ime_get_main_window(), scl_parser_type, MAIN_ENTRY_XML_PATH);
2170             }
2171
2172             g_ui->set_longkey_duration(elm_config_longpress_timeout_get() * 1000);
2173
2174             /* Default ISE callback */
2175             g_ui->set_ui_event_callback(&callback);
2176
2177             /* Accumulated customized ISE callbacks, depending on the input modes */
2178             for (scluint loop = 0;loop < _language_manager.get_languages_num();loop++) {
2179                 LANGUAGE_INFO *language = _language_manager.get_language_info(loop);
2180                 if (language) {
2181                     for (scluint inner_loop = 0;inner_loop < language->input_modes.size();inner_loop++) {
2182                         INPUT_MODE_INFO &info = language->input_modes.at(inner_loop);
2183                         LOGD("Registering callback for input mode %s : %p\n", info.name.c_str(), language->callback);
2184                         g_ui->set_ui_event_callback(language->callback, info.name.c_str());
2185                     }
2186                 }
2187             }
2188
2189             read_ise_config_values();
2190             if (access(ISE_CONFIG_FILE_PATH, F_OK) == 0 && !config_values->init_flag)
2191                 read_ise_config_file();
2192
2193             if (config_values) {
2194                 _language_manager.set_enabled_languages(config_values->enabled_languages);
2195                 _language_manager.select_language(config_values->selected_language.c_str());
2196                 vconf_set_bool(VCONFKEY_AUTOCAPITAL_ALLOW_BOOL, config_values->auto_capitalise);
2197                 vconf_set_bool(VCONFKEY_AUTOPERIOD_ALLOW_BOOL, config_values->auto_punctuate);
2198                 g_ui->enable_sound(config_values->sound_on);
2199                 g_ui->enable_vibration(config_values->vibration_on);
2200                 g_ui->enable_magnifier(config_values->preview_on);
2201                 g_floating_mode = config_values->floating_mode;
2202             }
2203 #ifdef _TV
2204             g_ui->enable_highlight_ui(TRUE);
2205 #endif
2206             ime_set_floating_mode(g_floating_mode);
2207         }
2208
2209         set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
2210
2211         bool exist = false;
2212
2213         preference_is_existing(ISE_CONFIG_KEYPAD_MODE, &exist);
2214         if (!exist)
2215             write_ise_config_values();
2216
2217         int state;
2218         if (ode_internal_encryption_get_state(&state) == ODE_ERROR_NONE) {
2219             if (state == ODE_STATE_ENCRYPTED) {
2220                 if (ode_internal_encryption_set_mount_event_cb(ise_mount_changed_cb, NULL) != ODE_ERROR_NONE)
2221                     LOGW("Failed to set mount_event_cb()");
2222             } else if (state == ODE_STATE_UNENCRYPTED) {
2223                 register_preference_changed_callback();
2224             }
2225         } else {
2226             LOGW("Failed to get encryption_state");
2227         }
2228     }
2229     init_recent_used_punctuation();
2230 }
2231
2232 void
2233 ise_destroy()
2234 {
2235     ise_hide_stt_mode();
2236
2237     CSCLUI *ui = get_ui();
2238     if (ui) {
2239         LOGD("calling ui->fini()\n");
2240         ui->fini();
2241         LOGD("deleting ui\n");
2242         delete ui;
2243         ui = NULL;
2244     }
2245
2246     if (g_candidate) {
2247         delete g_candidate;
2248         g_candidate = NULL;
2249     }
2250
2251 #ifdef _WEARABLE
2252     destroy_indicator_window();
2253 #endif
2254
2255     /* This is necessary. If this is not called, 3rd party IME might have auto period input regardless its settings */
2256     vconf_set_bool(VCONFKEY_AUTOPERIOD_ALLOW_BOOL, false);
2257
2258 #if EXIT_ISE_ON_HIDE
2259     if (exit_timer) ecore_timer_del(exit_timer);
2260     exit_timer = NULL;
2261 #endif
2262 }
2263
2264 void
2265 ise_app_candidate_show()
2266 {
2267 #ifdef _WEARABLE
2268     if (!g_candidate)
2269         return;
2270
2271     if (!g_candidate->get_visible())
2272         return;
2273 #endif
2274     LOGD("Enter\n");
2275     delete_softcandidate_hide_timer();
2276
2277     create_softcandidate();
2278
2279     Candidate *candidate = get_candidate();
2280     if (candidate) {
2281         candidate->show();
2282         set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
2283     }
2284 }
2285
2286 void
2287 ise_app_candidate_hide()
2288 {
2289     LOGD("Enter\n");
2290
2291     Candidate *candidate = get_candidate();
2292     if (!candidate || !candidate->get_visible()) {
2293         LOGD("No candidate\n");
2294         return;
2295     }
2296
2297     if (g_ic_smartreply != -1 || ime_autofill_get_exist())
2298         return;
2299
2300     add_softcandidate_hide_timer();
2301 }
2302
2303 #ifdef _WEARABLE
2304 void ise_check_wearable_candidate()
2305 {
2306     CONFIG_VALUES *config_values = get_config_values();
2307     if (!config_values) return;
2308
2309     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2310     if (!keyboard_state) return;
2311
2312     if (!config_values->prediction_on) {
2313         ise_app_candidate_hide();
2314     } else if (keyboard_state->layout == ISE_LAYOUT_STYLE_PHONENUMBER ||
2315                   keyboard_state->layout == ISE_LAYOUT_STYLE_VOICE ||
2316                   keyboard_state->layout == ISE_LAYOUT_STYLE_IP ||
2317                   keyboard_state->layout == ISE_LAYOUT_STYLE_MONTH ||
2318                   keyboard_state->layout == ISE_LAYOUT_STYLE_NUMBERONLY ||
2319                   keyboard_state->layout == ISE_LAYOUT_STYLE_PASSWD_3X4||
2320                   keyboard_state->layout == ISE_LAYOUT_STYLE_PASSWORD) {
2321         ise_app_candidate_hide();
2322     } else {
2323         ise_app_candidate_show();
2324     }
2325 }
2326
2327 void ise_set_emoticon_label(int group_id)
2328 {
2329     const int BUF_LEN = 16;
2330     char buf[BUF_LEN] = {0};
2331     snprintf(buf, BUF_LEN, "%d/3", group_id);
2332     CSCLUI *ui = get_ui();
2333     if (ui) ui->set_private_key("EMOTICON_GROUP_ID", buf, NULL, NULL, 0, const_cast<sclchar*>("EMOTICON_GROUP_NEXT"), TRUE);
2334 }
2335 #endif
2336
2337 // when it is the time to auto_cap, the
2338 // ise_set_caps_mode is called.
2339 // -------------------------------------------------------
2340 // For example: [How are you. Fine.], the
2341 // auto-capital process is as below:
2342 // Note: "["<--this is the beginning,
2343 // "|"<--this is the cursor position
2344 // 1) call ise_set_caps_mode, auto_cap = on
2345 //    input: "H",
2346 //    result: [H|
2347 // 2) call ise_set_caps_mode, auto_cap = off
2348 //    input: "o"
2349 //    result: [Ho|
2350 // 3) input: "w are you. "
2351 //    result: [How are you. |
2352 // 4) call ise_set_caps_mode, auto_cap = on
2353 //    input: "F"
2354 //    result: [How are you. F
2355 // 5) input: "ine."
2356 //    result: [How are you. Fine.|
2357 // --------------------------------------------------------
2358 // If we want to change the auto_cap, eg,
2359 // if we want to input [How Are you.]
2360 // Note the "Are" is not use auto-capital rule.
2361 // we should use:
2362 //    ise_send_event(MVK_Shift_On, SclCoreKeyMask_Null);
2363 // when we are want to input "A"
2364 // following input still has the auto_cap rule.
2365 void
2366 ise_set_caps_mode(unsigned int mode)
2367 {
2368     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2369     if (!keyboard_state) return;
2370
2371     LOGD("caps_mode : %d\n", mode);
2372     if (mode) {
2373         keyboard_state->caps_mode = TRUE;
2374     } else {
2375         keyboard_state->caps_mode = FALSE;
2376     }
2377     g_caps_mode_pending = false;
2378     const sclchar *cur_lang = _language_manager.get_current_language();
2379     if (cur_lang) {
2380         LANGUAGE_INFO *info = _language_manager.get_language_info(cur_lang);
2381         if (info) {
2382             if (info->accepts_caps_mode) {
2383                 /* If we are inputting multitap character, do not manipulate shift mode */
2384                 if (keyboard_state->prev_modifier != KEY_MODIFIER_MULTITAP_START &&
2385                     keyboard_state->prev_modifier != KEY_MODIFIER_MULTITAP_REPEAT) {
2386                     set_caps_mode(keyboard_state->caps_mode);
2387                 } else {
2388                     g_caps_mode_pending = true;
2389                     LOGD("Currently composing multitap string, skipping caps request");
2390                 }
2391             }
2392         }
2393     }
2394 }
2395
2396 void
2397 ise_update_cursor_position(int position)
2398 {
2399     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2400     if (!keyboard_state) return;
2401
2402     LOGD("cursor position : %d\n", position);
2403     CSCLUI *ui = get_ui();
2404     if (ui && keyboard_state->layout == ISE_LAYOUT_STYLE_URL) {
2405 #ifndef _TV
2406         if (position > 0) {
2407             ui->set_string_substitution("www.", ".com");
2408         } else {
2409             ui->unset_string_substitution("www.");
2410         }
2411 #endif
2412     }
2413 }
2414
2415 void ise_set_return_key_type(unsigned int type)
2416 {
2417     const int BUF_LEN = 256;
2418     char buf[BUF_LEN] = {0};
2419
2420     CSCLUI *ui = get_ui();
2421     if (!ui) return;
2422
2423     LOGD("return key type : %d\n", type);
2424     switch (type)
2425     {
2426     case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE:
2427         snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_DONE);
2428         break;
2429     case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_GO:
2430         snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_GO);
2431         break;
2432     case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_JOIN:
2433         snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_JOIN);
2434         break;
2435     case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_LOGIN:
2436         snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_LOGIN);
2437         break;
2438     case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_NEXT:
2439         snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_NEXT);
2440         break;
2441     case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEARCH:
2442         snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_SEARCH);
2443         break;
2444     case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEND:
2445         snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_SEND);
2446         break;
2447     case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SIGNIN:
2448         snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_SIGNIN);
2449         break;
2450     case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT:
2451         break;
2452     default:
2453         LOGW("Unknown return key type : %d\n", type);
2454         type = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT;
2455         break;
2456     }
2457
2458     if (type == ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT) {
2459         ui->unset_private_key("Enter");
2460 #ifdef _TV
2461         ui->unset_private_key("Done");
2462 #endif
2463     } else {
2464 #ifdef _WEARABLE
2465         if (type == ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEARCH) {
2466             sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
2467                 const_cast<sclchar*>("w_sip_3x4_btn_ic_search.png"),
2468                 const_cast<sclchar*>("w_sip_3x4_btn_ic_search_p.png"),
2469                 const_cast<sclchar*>("w_sip_3x4_btn_ic_search_d.png")};
2470             ui->set_private_key("Enter", const_cast<sclchar*>(""), imagelabel, NULL, 0, const_cast<sclchar*>("Enter"), TRUE);
2471             return;
2472         }
2473 #endif
2474
2475 #ifdef _TV
2476         ui->set_private_key("Done", buf, NULL, NULL, 0, const_cast<sclchar*>("Done"), TRUE);
2477 #else
2478         static sclchar *imagelabel[SCL_BUTTON_STATE_MAX] = {
2479             const_cast<sclchar*>(" "), const_cast<sclchar*>(" "), const_cast<sclchar*>(" ")
2480         };
2481
2482         ui->set_private_key("Enter", buf, imagelabel, NULL, 0, const_cast<sclchar*>("Enter"), TRUE);
2483 #endif
2484         LOGD("return key label : %s\n", buf);
2485     }
2486 }
2487
2488 void ise_set_return_key_disable(unsigned int disabled)
2489 {
2490     CSCLUI *ui = get_ui();
2491     LOGD("enable : %d\n", !disabled);
2492 #ifdef _TV
2493     if (ui)
2494         ui->enable_button("Done", !disabled);
2495 #else
2496     if (ui)
2497         ui->enable_button("Enter", !disabled);
2498 #endif
2499 }
2500
2501 void ise_get_language_locale(char **locale)
2502 {
2503     LANGUAGE_INFO *info = _language_manager.get_current_language_info();
2504     if (info) {
2505         if (!(info->locale_string.empty())) {
2506             *locale = strdup(info->locale_string.c_str());
2507         }
2508     }
2509 }
2510
2511 void ise_update_table(const vector<string> &vec_str)
2512 {
2513     Candidate *candidate = get_candidate();
2514     if (!candidate || !candidate->get_visible()) {
2515         create_softcandidate();
2516     }
2517
2518     candidate = get_candidate();
2519     if (candidate) {
2520         candidate->update(vec_str);
2521     }
2522 }
2523
2524 void ise_process_key_event(scim::KeyEvent& key, sclu32 &ret)
2525 {
2526     Eina_Bool back_key_pressed = EINA_FALSE;
2527     Eina_Bool back_key_released = EINA_FALSE;
2528
2529     if (key.get_key_string().compare("XF86Back") == 0) {
2530         back_key_pressed = EINA_TRUE;
2531     } else if (key.get_key_string().compare("KeyRelease+XF86Back") == 0) {
2532         back_key_released = EINA_TRUE;
2533     }
2534
2535     if (back_key_pressed || back_key_released) {
2536         if (g_popup_opened == TRUE) {
2537             if (back_key_released) {
2538                 CSCLUI *ui = get_ui();
2539                 if (ui) ui->close_all_popups();
2540             }
2541             ret = 1;
2542             return;
2543         }
2544     }
2545
2546     ret = 0;
2547     CSCLUI *ui = get_ui();
2548 #ifdef _TV
2549     Candidate *candidate = get_candidate();
2550     if (candidate) {
2551         if (!candidate->soft_candidate_flag()) {
2552             if (ui) {
2553                 if (key.dev_name.compare("ime") != 0) {
2554                     ret = (sclu32)ui->process_key_event(key.get_key_string().c_str());
2555                 }
2556             }
2557         }
2558         if (!ret) {
2559             ret = candidate->soft_candidate_handle_key_event(key.get_key_string().c_str());
2560         }
2561     } else {
2562         if (ui) {
2563             /* Process this key event if it was not generated by ime */
2564             if (key.dev_name.compare("ime") != 0) {
2565                 ret = (sclu32)ui->process_key_event(key.get_key_string().c_str());
2566             }
2567         }
2568     }
2569 #else
2570     if (ui) {
2571         /* Process this key event if it was not generated by ime */
2572         if (key.dev_name.compare("ime") != 0) {
2573             ret = (sclu32)ui->process_key_event(key.get_key_string().c_str());
2574         }
2575     }
2576 #endif
2577 }
2578
2579 static void init_recent_used_punctuation()
2580 {
2581     if (g_recent_used_punctuation.empty())
2582     {
2583         g_recent_used_punctuation.push_back("#");
2584         g_recent_used_punctuation.push_back("$");
2585         g_recent_used_punctuation.push_back("%");
2586         g_recent_used_punctuation.push_back("^");
2587         g_recent_used_punctuation.push_back("&");
2588     }
2589 }
2590
2591 static void update_recent_used_punctuation(const char * key_value)
2592 {
2593     if (NULL == key_value)
2594     {
2595         return;
2596     }
2597     for (int i = 0; i < 10; ++i)
2598     {
2599         char buf[5] = {0};
2600         snprintf(buf, sizeof(buf), "%d", i);
2601         if (strcmp(key_value, buf) == 0)
2602         {
2603             return;
2604         }
2605     }
2606     string strKey = string(key_value);
2607     for (int i = 0; i < MAX_DEFAULT_PUNCTUATION; ++i)
2608     {
2609         if (0 == strKey.compare(g_default_punctuation[i].c_str()))
2610         {
2611             return;
2612         }
2613     }
2614     vector<string>::iterator iter = g_recent_used_punctuation.begin();
2615     for (; iter != g_recent_used_punctuation.end(); ++iter)
2616     {
2617         if (0 == strKey.compare(iter->c_str()))
2618         {
2619             break;
2620         }
2621     }
2622     if (iter != g_recent_used_punctuation.end())
2623     {
2624         g_recent_used_punctuation.erase(iter);
2625     }
2626     g_recent_used_punctuation.push_back(strKey);
2627     if (g_recent_used_punctuation.size() > MAX_DEFAULT_PUNCTUATION-1)
2628     {
2629         g_recent_used_punctuation.erase(g_recent_used_punctuation.begin());
2630     }
2631 }
2632
2633 static void set_ime_size(bool floating_mode, ISE_CANDIDATE_REQUEST candidate_req)
2634 {
2635     CSCLUI *ui = get_ui();
2636     if (!ui)
2637         return;
2638
2639     Candidate *candidate = get_candidate();
2640
2641     const char *input_mode = ui->get_input_mode();
2642     if (!input_mode)
2643         return;
2644
2645     SclSize size_portrait = ui->get_input_mode_size(input_mode, DISPLAYMODE_PORTRAIT);
2646     SclSize size_landscape = ui->get_input_mode_size(input_mode, DISPLAYMODE_LANDSCAPE);
2647
2648     if (floating_mode) {
2649         size_portrait.width *= FLOATING_SCALE_RATE;
2650         size_portrait.height *= FLOATING_SCALE_RATE;
2651         size_landscape.width *= FLOATING_SCALE_RATE;
2652         size_landscape.height *= FLOATING_SCALE_RATE;
2653         switch (candidate_req) {
2654             case ISE_CANDIDATE_REQ_NONE:
2655                 if (candidate && candidate->get_visible()) {
2656                     ui->set_custom_starting_coordinates(0, FLOATING_TITLE_BAR_HEIGHT + candidate->get_height());
2657                     size_portrait.height += candidate->get_height();
2658                     size_landscape.height += candidate->get_height();
2659                 } else {
2660                     ui->set_custom_starting_coordinates(0, FLOATING_TITLE_BAR_HEIGHT);
2661                 }
2662                 break;
2663             case ISE_CANDIDATE_REQ_SHOW:
2664                 if (candidate) {
2665                     ui->set_custom_starting_coordinates(0, FLOATING_TITLE_BAR_HEIGHT + candidate->get_height());
2666                     if (g_input_panel_show || g_candidate_more_view) {
2667                         size_portrait.height += candidate->get_height();
2668                         size_landscape.height += candidate->get_height();
2669                     } else {
2670                         size_portrait.height = candidate->get_height();
2671                         size_landscape.height = candidate->get_height();
2672                     }
2673                 }
2674                 break;
2675             case ISE_CANDIDATE_REQ_HIDE:
2676                 ui->set_custom_starting_coordinates(0, FLOATING_TITLE_BAR_HEIGHT);
2677                 break;
2678             default: break;
2679         }
2680
2681         if (ui->get_custom_scale_rate_x() != FLOATING_SCALE_RATE || ui->get_custom_scale_rate_y() != FLOATING_SCALE_RATE)
2682             ui->set_custom_scale_rate(FLOATING_SCALE_RATE, FLOATING_SCALE_RATE);
2683
2684         ime_set_size(size_portrait.width, size_portrait.height + FLOATING_TITLE_BAR_HEIGHT,
2685             size_landscape.width, size_landscape.height + FLOATING_TITLE_BAR_HEIGHT);
2686
2687 #if defined(_MOBILE) || defined(_COMMON)
2688         ise_destroy_move_handler();
2689         int rotation = elm_win_rotation_get(NATIVE_WINDOW_CAST(ime_get_main_window()));
2690         int handler_width = (rotation == 0 || rotation == 180) ? size_portrait.width : size_landscape.width;
2691         ise_show_move_handler(handler_width, FLOATING_TITLE_BAR_HEIGHT);
2692 #endif
2693     } else {
2694         switch (candidate_req) {
2695             case ISE_CANDIDATE_REQ_NONE:
2696                 if (candidate && candidate->get_visible()) {
2697                     ui->set_custom_starting_coordinates(0, candidate->get_height());
2698                     size_portrait.height += candidate->get_height();
2699                     size_landscape.height += candidate->get_height();
2700                 } else {
2701                     ui->set_custom_starting_coordinates(0, 0);
2702                 }
2703                 break;
2704             case ISE_CANDIDATE_REQ_SHOW:
2705                 if (candidate) {
2706                     ui->set_custom_starting_coordinates(0, candidate->get_height());
2707                     if (g_input_panel_show || g_candidate_more_view) {
2708                         size_portrait.height += candidate->get_height();
2709                         size_landscape.height += candidate->get_height();
2710                     } else {
2711                         size_portrait.height = candidate->get_height();
2712                         size_landscape.height = candidate->get_height();
2713                     }
2714                 }
2715                 break;
2716             case ISE_CANDIDATE_REQ_HIDE:
2717                 ui->set_custom_starting_coordinates(0, 0);
2718                 break;
2719             default: break;
2720         }
2721
2722         if (ui->get_custom_scale_rate_x() != 1.0 || ui->get_custom_scale_rate_y() != 1.0)
2723             ui->set_custom_scale_rate(1.0, 1.0);
2724
2725         ime_set_size(size_portrait.width, size_portrait.height, size_landscape.width, size_landscape.height);
2726
2727 #if defined(_MOBILE) || defined(_COMMON)
2728         ise_destroy_move_handler();
2729 #endif
2730     }
2731 }
2732
2733 static void ime_app_create_cb(void *user_data)
2734 {
2735     if (!engine_loader_dbus_init(NULL))
2736         LOGE("Failed to initialize dbus");
2737
2738 #if !(DEFER_ISE_CREATION)
2739     ise_create();
2740 #endif
2741     elm_app_name_set(PACKAGE);
2742
2743     char *elm_scale = getenv("ELM_SCALE");
2744     LOGD("ELM_SCALE : %s", elm_scale);
2745
2746     if (elm_scale)
2747         elm_app_base_scale_set(atof(elm_scale));
2748
2749     clipboard_init();
2750
2751     nmt_init();
2752 }
2753
2754 static void ime_app_exit_cb(void *user_data)
2755 {
2756     ise_hide();
2757     ise_destroy();
2758
2759     if (!engine_loader_dbus_shutdown())
2760         LOGE("Failed to finalize dbus");
2761
2762     clipboard_shutdown();
2763
2764     nmt_shutdown();
2765 }
2766
2767 static void show_autofill_data()
2768 {
2769     ime_autofill_set_exist(false);
2770     string autofill_string = ime_autofill_get_string();
2771
2772     SECURE_LOGD("autofill string : %s", autofill_string.c_str());
2773
2774     if (!autofill_string.empty()) {
2775         ime_autofill_set_exist(true);
2776
2777         ise_app_candidate_show();
2778         update_candidate_table();
2779     }
2780 }
2781
2782 static void ime_app_show_cb(int ic, ime_context_h ime_ctx, void *user_data)
2783 {
2784     Ise_Context iseContext;
2785     bool return_key_state, prediction_allow, password_mode, caps_mode;
2786     ime_layout_variation_e layout_variation;
2787
2788     if (!g_ise_created)
2789         ise_create();
2790
2791     ime_context_get_layout(ime_ctx, &iseContext.layout);
2792
2793     ime_context_get_layout_variation(ime_ctx, &layout_variation);
2794     iseContext.layout_variation =  (int)layout_variation;
2795
2796     ime_context_get_cursor_position(ime_ctx, &iseContext.cursor_pos);
2797     ime_context_get_autocapital_type(ime_ctx, &iseContext.autocapital_type);
2798     ime_context_get_return_key_type(ime_ctx, &iseContext.return_key_type);
2799     ime_context_get_return_key_state(ime_ctx, &return_key_state);
2800
2801     ime_context_get_prediction_mode(ime_ctx, &prediction_allow);
2802     iseContext.prediction_allow = prediction_allow;
2803
2804     ime_context_get_password_mode(ime_ctx, &password_mode);
2805     iseContext.password_mode = password_mode;
2806
2807     ime_context_get_input_hint(ime_ctx, &iseContext.input_hint);
2808     ime_context_get_bidi_direction(ime_ctx, &iseContext.bidi_direction);
2809     ime_context_get_language(ime_ctx, &iseContext.language);
2810     ime_context_get_caps_mode(ime_ctx, &caps_mode);
2811     iseContext.caps_mode = caps_mode;
2812
2813     iseContext.return_key_disabled = return_key_state;
2814
2815     engine_loader_set_input_hint((uint32_t)iseContext.input_hint);
2816     engine_loader_update_bidi_direction((uint32_t)iseContext.bidi_direction);
2817
2818     g_ic = ic;
2819
2820     ime_autofill_set_hint(iseContext.input_hint & ECORE_IMF_INPUT_HINT_AUTOFILL_MASK);
2821
2822     LOGD("input hint : %x, autofill hint : %x\n", iseContext.input_hint, ime_autofill_get_hint());
2823
2824     // show autofill data
2825     show_autofill_data();
2826
2827     //g_ise_common->set_keyboard_ise_by_uuid(KEYBD_ISE_UUID);
2828
2829     /* Don't update screen until all the information is correctly set */
2830     CSCLUI *ui = get_ui();
2831     if (ui)
2832         ui->set_update_pending(TRUE);
2833
2834     ise_reset_context(); // reset ISE
2835
2836     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2837
2838     if (iseContext.language == ECORE_IMF_INPUT_PANEL_LANG_ALPHABET) {
2839         LOGD("prefer latin");
2840         if (keyboard_state)
2841             keyboard_state->prefer_latin = TRUE;
2842     }
2843     else {
2844         LOGD("prefer automatic");
2845         if (keyboard_state)
2846             keyboard_state->prefer_latin = FALSE;
2847     }
2848
2849     _context_layout = iseContext.layout;
2850     _context_layout_variation = iseContext.layout_variation;
2851     ise_set_layout(iseContext.layout, iseContext.layout_variation);
2852
2853     ise_set_return_key_type(iseContext.return_key_type);
2854     ise_set_return_key_disable(iseContext.return_key_disabled);
2855
2856     ise_set_caps_mode(iseContext.caps_mode);
2857     ise_update_cursor_position(iseContext.cursor_pos);
2858
2859     ise_show(ic);
2860
2861     /* Now we update the whole screen */
2862     if (ui)
2863         ui->set_update_pending(FALSE);
2864 }
2865
2866 static void ime_app_hide_cb(int ic, void *user_data)
2867 {
2868     LOGD("Enter\n");
2869     ise_hide();
2870
2871     clipboard_set_mime_type(false);
2872
2873     g_ic_smartreply = -1;
2874 }
2875
2876 static void ime_app_return_key_type_set_cb(Ecore_IMF_Input_Panel_Return_Key_Type type, void *user_data)
2877 {
2878     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2879     if (!keyboard_state) return;
2880
2881     LOGD("return key type : %d\n", type);
2882     ise_set_return_key_type(type);
2883
2884     if (keyboard_state->visible_state)
2885         ise_show(keyboard_state->ic);
2886 }
2887
2888 static void ime_app_return_key_state_set_cb(bool disabled, void *user_data)
2889 {
2890     LOGD("return key disabled : %d\n", disabled);
2891     ise_set_return_key_disable(disabled);
2892 }
2893
2894 static void ime_app_language_set_cb(Ecore_IMF_Input_Panel_Lang language, void *user_data)
2895 {
2896     LOGD("language : %d\n", language);
2897
2898     // if (language == ECORE_IMF_INPUT_PANEL_LANG_ALPHABET) {
2899     //     ise_explictly_set_language(PRIMARY_LATIN_LANGUAGE_INDEX);
2900     // }
2901 }
2902
2903 static void ime_app_input_context_reset_cb(void *user_data)
2904 {
2905     ise_reset_input_context();
2906     engine_loader_reset_input_context();
2907 }
2908
2909 static void ime_app_cursor_position_updated_cb(int cursor_pos, void *user_data)
2910 {
2911     LOGD("cursor position : %d\n", cursor_pos);
2912     ise_update_cursor_position(cursor_pos);
2913     engine_loader_update_cursor_position(cursor_pos);
2914 }
2915
2916 static void ime_app_language_requested_cb(void *user_data, char **lang_code)
2917 {
2918     ise_get_language_locale(lang_code);
2919 }
2920
2921 static void ime_app_surrounding_text_updated_cb(int context_id, const char *text, int cursor_pos, void *user_data)
2922 {
2923     SECURE_LOGD("surrounding text:%s, cursor=%d\n", text, cursor_pos);
2924     ime_delete_surrounding_text(-cursor_pos, strlen(text));
2925 }
2926
2927 static void ime_app_focus_in_cb(int context_id, void *user_data)
2928 {
2929     LOGD("Enter\n");
2930     ise_focus_in(context_id);
2931     Candidate *candidate = get_candidate();
2932     if (input_smartreply_get_reply_num() == 0) {
2933         if (candidate && candidate->get_visible()) {
2934             ise_app_candidate_hide();
2935             candidate->hide();
2936         }
2937     }
2938
2939     engine_loader_focus_in();
2940 }
2941
2942 static void ime_app_focus_out_cb(int context_id, void *user_data)
2943 {
2944     LOGD("Enter\n");
2945     ise_focus_out(context_id);
2946     g_imdata_state = 0;
2947     clipboard_set_mime_type(false);
2948     input_smartreply_deinit();
2949     g_ic_smartreply = -1;
2950
2951     ime_autofill_set_exist(false);
2952     ime_autofill_set_hint(0);
2953     ime_autofill_set_app_id("");
2954     ime_autofill_set_resource_id("");
2955
2956     g_smartreply_strings.clear();
2957     g_lookup_table_strings.clear();
2958     g_softcandidate_string.clear();
2959
2960     engine_loader_focus_out();
2961 }
2962
2963 static void ime_app_layout_set_cb(Ecore_IMF_Input_Panel_Layout layout, void *user_data)
2964 {
2965     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2966     if (!keyboard_state) return;
2967
2968     LOGD("layout=%d\n", layout);
2969     /* Check if the layoutIdx is in the valid range */
2970     if (static_cast<int>(layout) < static_cast<int>(ISE_LAYOUT_STYLE_MAX)) {
2971         if (keyboard_state->layout != layout) {
2972             keyboard_state->need_reset = TRUE;
2973         }
2974         keyboard_state->layout = layout;
2975         _context_layout = layout;
2976         _context_layout_variation = 0;
2977     }
2978     if (keyboard_state->visible_state)
2979         ise_show(keyboard_state->ic);
2980
2981     engine_loader_set_layout(static_cast<uint32_t>(layout));
2982 }
2983
2984 static void ime_app_input_hint_set_cb(Ecore_IMF_Input_Hints input_hint, void *user_data)
2985 {
2986     LOGD("input hint=%u\n", input_hint);
2987 }
2988
2989 static void ime_app_rotation_degree_changed_cb(int degree, void *user_data)
2990 {
2991     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2992     if (!keyboard_state) return;
2993
2994     CSCLUI *ui = get_ui();
2995     ise_set_screen_rotation(degree);
2996
2997     LOGD("degree=%d\n", degree);
2998 #if defined(_MOBILE) || defined(_COMMON)
2999     if (ui && g_floating_mode) {
3000         int handler_width;
3001         ise_destroy_move_handler();
3002         if (degree == 0 || degree == 180) {
3003             SclSize size_portrait = ui->get_input_mode_size(ui->get_input_mode(), DISPLAYMODE_PORTRAIT);
3004             handler_width = size_portrait.width * FLOATING_SCALE_RATE;
3005         } else {
3006             SclSize size_landscape = ui->get_input_mode_size(ui->get_input_mode(), DISPLAYMODE_LANDSCAPE);
3007             handler_width = size_landscape.width * FLOATING_SCALE_RATE;
3008         }
3009         ise_show_move_handler(handler_width, FLOATING_TITLE_BAR_HEIGHT);
3010     }
3011 #endif
3012     if (ise_emoticon_is_show()) {
3013         ise_emoticon_destroy_layout();
3014     }
3015     if (keyboard_state->layout == ISE_LAYOUT_STYLE_VOICE) {
3016         ise_hide_stt_mode();
3017     }
3018     if (keyboard_state->layout == ISE_LAYOUT_STYLE_EMOTICON) {
3019         ise_emoticon_show_layout(ise_emoticon_get_current_group(), degree, false, ime_get_main_window());
3020     } else if (ui) {
3021         const sclchar *input_mode = ui->get_input_mode();
3022         if (input_mode) {
3023             if (!(strcmp(input_mode, "EMOTICON_LAYOUT")))
3024                 ise_emoticon_show_layout(ise_emoticon_get_current_group(), degree, false, ime_get_main_window());
3025             else if (!(strcmp(input_mode, "STT_3X4")))
3026                 ise_show_stt_mode(NATIVE_WINDOW_CAST(ime_get_main_window()));
3027         }
3028     }
3029 }
3030
3031 static void ime_app_accessibility_state_changed_cb(bool state, void *user_data)
3032 {
3033     LOGD("state=%d\n", state);
3034     ise_set_accessibility_state(state);
3035 }
3036
3037 static void ime_app_imdata_set_cb(void *data, unsigned int data_length, void *user_data)
3038 {
3039     LOGD("Enter\n");
3040     g_imdata_state = 0;
3041     size_t _len = data_length;
3042     set_ise_imdata((sclchar *)data, _len);
3043     engine_loader_set_imdata((const char*)data, (uint32_t)data_length);
3044 }
3045
3046 static bool ime_app_process_key_event_cb(ime_key_code_e keycode, ime_key_mask_e keymask, ime_device_info_h dev_info, void *user_data)
3047 {
3048     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
3049     if (!keyboard_state) return FALSE;
3050
3051     scim::KeyEvent key(keycode, keymask);
3052     unsigned int ret;
3053     char *dev_name = NULL;
3054     Ecore_IMF_Device_Class dev_class;
3055     Ecore_IMF_Device_Subclass dev_subclass;
3056
3057     if (ime_device_info_get_name(dev_info, &dev_name) == IME_ERROR_NONE) {
3058         key.dev_name = dev_name;
3059     }
3060
3061     if (ime_device_info_get_class(dev_info, &dev_class) == IME_ERROR_NONE) {
3062         key.dev_class = dev_class;
3063     }
3064
3065     if (ime_device_info_get_subclass(dev_info, &dev_subclass) == IME_ERROR_NONE) {
3066         key.dev_subclass = dev_subclass;
3067     }
3068
3069     if (keyboard_state->visible_state)
3070         ise_process_key_event(key, ret);
3071     else
3072         ret = FALSE;
3073
3074     if (dev_name)
3075         free(dev_name);
3076
3077     return ret;
3078 }
3079
3080 static void ime_app_process_key_event_with_imengine_cb(scim::KeyEvent &key, uint32_t serial, void *user_data)
3081 {
3082     LANGUAGE_INFO *info = _language_manager.get_language_info(_language_manager.get_current_language());
3083     if (info && info->need_surrounding_text)
3084         engine_loader_process_key_event(key, serial, true);
3085     else
3086         engine_loader_process_key_event(key, serial, false);
3087 }
3088
3089 static void ime_app_caps_mode_changed_cb(int mode, void *user_data)
3090 {
3091     ise_set_caps_mode(mode);
3092 }
3093
3094 static void ime_app_candidate_show_cb(int context_id, void *user_data)
3095 {
3096 #ifdef _WEARABLE
3097     ise_check_wearable_candidate();
3098 #else
3099     ise_app_candidate_show();
3100 #endif
3101 }
3102
3103 static void ime_app_candidate_hide_cb(int context_id, void *user_data)
3104 {
3105 #ifdef _WEARABLE
3106     ise_check_wearable_candidate();
3107 #else
3108     ise_app_candidate_hide();
3109 #endif
3110 }
3111
3112 static void ime_app_lookup_table_changed_cb(Eina_List *list, void *user_data)
3113 {
3114     vector<string> candidate_strings;
3115     char *candidate;
3116     void *data;
3117     Eina_List *l;
3118
3119     g_lookup_table_strings.clear();
3120
3121     if (list) {
3122         EINA_LIST_FOREACH(list, l, data) {
3123             candidate = (char *)data;
3124             if (candidate) {
3125                 g_lookup_table_strings.push_back(string(candidate));
3126                 candidate_strings.push_back(string(candidate));
3127             }
3128         }
3129     }
3130
3131     if (input_smartreply_get_reply_num() > 0) {
3132         if (candidate_strings[0] == "#" && candidate_strings[1] == "$") {
3133             char *text = NULL;
3134             int cursor;
3135             ime_get_surrounding_text(0, 0, &text, &cursor);
3136             if (text)
3137                 free(text);
3138
3139             if (cursor == 0)
3140                 return;
3141         }
3142     }
3143
3144     update_candidate_table();
3145 }
3146
3147 #ifdef _WEARABLE
3148 static void ime_app_process_input_device_event_cb(ime_input_device_type_e device_type, ime_input_device_event_h device_event, void *user_data)
3149 {
3150     KEYBOARD_STATE *keyboard_state = get_keyboard_state();
3151     if (!keyboard_state) return;
3152
3153     if (device_type == IME_INPUT_DEVICE_TYPE_ROTARY) {
3154         ime_input_device_rotary_direction_e direction;
3155         if (IME_ERROR_NONE == ime_input_device_rotary_get_direction(device_event, &direction)) {
3156             sclu32 new_layout = keyboard_state->layout;
3157             if (direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_CLOCKWISE) {
3158                 LOGD("CLOCKWISE\n");
3159                 switch (keyboard_state->layout) {
3160                     case ISE_LAYOUT_STYLE_NORMAL:
3161                     case ISE_LAYOUT_STYLE_EMAIL:
3162                     case ISE_LAYOUT_STYLE_URL:
3163                     case ISE_LAYOUT_STYLE_PASSWORD:
3164                         if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD &&
3165                             _context_layout_variation == ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD_VARIATION_NUMBERONLY)
3166                             ;   // PASSWORD NUMBER ONLY, do nothing
3167                         else
3168                             new_layout = ISE_LAYOUT_STYLE_NUMBER;
3169                         break;
3170                     case ISE_LAYOUT_STYLE_NUMBER:
3171                         new_layout = ISE_LAYOUT_STYLE_HEX;
3172                         break;
3173                     case ISE_LAYOUT_STYLE_HEX:
3174                         if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
3175                             _context_layout == ISE_LAYOUT_STYLE_URL)
3176                             new_layout = ISE_LAYOUT_STYLE_VOICE;
3177                         else if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD)
3178                             new_layout = _context_layout;
3179                         else
3180                             new_layout = ISE_LAYOUT_STYLE_EMOTICON;
3181                         break;
3182                     case ISE_LAYOUT_STYLE_EMOTICON:
3183                         if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
3184                             _context_layout == ISE_LAYOUT_STYLE_URL ||
3185                             _context_layout == ISE_LAYOUT_STYLE_PASSWORD)
3186                             new_layout = _context_layout;
3187                         else
3188                             new_layout = ISE_LAYOUT_STYLE_VOICE;
3189                         break;
3190                     case ISE_LAYOUT_STYLE_VOICE:
3191                         new_layout = ISE_LAYOUT_STYLE_NORMAL;
3192                         break;
3193                     default:
3194                         ;
3195                 }
3196             } else if (direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_COUNTER_CLOCKWISE) {
3197                 LOGD("COUNTER_CLOCKWISE\n");
3198                 switch (keyboard_state->layout) {
3199                     case ISE_LAYOUT_STYLE_NORMAL:
3200                     case ISE_LAYOUT_STYLE_EMAIL:
3201                     case ISE_LAYOUT_STYLE_URL:
3202                     case ISE_LAYOUT_STYLE_PASSWORD:
3203                         if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD &&
3204                             _context_layout_variation == ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD_VARIATION_NUMBERONLY)
3205                             ;   // PASSWORD NUMBER ONLY, do nothing
3206                         else if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD)
3207                             new_layout = ISE_LAYOUT_STYLE_HEX;
3208                         else
3209                             new_layout = ISE_LAYOUT_STYLE_VOICE;
3210                         break;
3211                     case ISE_LAYOUT_STYLE_NUMBER:
3212                         if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
3213                             _context_layout == ISE_LAYOUT_STYLE_URL ||
3214                             _context_layout == ISE_LAYOUT_STYLE_PASSWORD)
3215                             new_layout = _context_layout;
3216                         else
3217                             new_layout = ISE_LAYOUT_STYLE_NORMAL;
3218                         break;
3219                     case ISE_LAYOUT_STYLE_HEX:
3220                         new_layout = ISE_LAYOUT_STYLE_NUMBER;
3221                         break;
3222                     case ISE_LAYOUT_STYLE_EMOTICON:
3223                         new_layout = ISE_LAYOUT_STYLE_HEX;
3224                         break;
3225                     case ISE_LAYOUT_STYLE_VOICE:
3226                         if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
3227                             _context_layout == ISE_LAYOUT_STYLE_URL)
3228                             new_layout = ISE_LAYOUT_STYLE_HEX;
3229                         else
3230                             new_layout = ISE_LAYOUT_STYLE_EMOTICON;
3231                         break;
3232                     default:
3233                         ;
3234                 }
3235             }
3236
3237             CONFIG_VALUES *config_values = get_config_values();
3238             if (check_is_tutorial_show() && config_values) {
3239                 read_ise_config_values();
3240                 if ((direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_COUNTER_CLOCKWISE && !config_values->number_tutorial_enable && !config_values->symbol_tutorial_enable) ||
3241                     (direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_CLOCKWISE && config_values->symbol_tutorial_enable)) {
3242                     new_layout = keyboard_state->layout;
3243                 } else if (direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_COUNTER_CLOCKWISE && config_values->symbol_tutorial_enable) {
3244                     ise_destroy_tutorial_mode_popup();
3245                     config_values->symbol_tutorial_enable = false;
3246                      write_ise_config_values();
3247                 } else if (direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_CLOCKWISE && !config_values->number_tutorial_enable) {
3248                     ise_destroy_tutorial_mode_popup();
3249                     new_layout = ISE_LAYOUT_STYLE_NUMBER;
3250                     if (!config_values->symbol_tutorial_enable) {
3251                         ise_show_tutorial_mode_popup(new_layout);
3252                         config_values->symbol_tutorial_enable = true;
3253                          write_ise_config_values();
3254                     }
3255                 }
3256             }
3257
3258             if (new_layout != keyboard_state->layout && new_layout < ISE_LAYOUT_STYLE_MAX) {
3259                 keyboard_state->need_reset = TRUE;
3260                 keyboard_state->layout = new_layout;
3261
3262                 if (keyboard_state->visible_state) {
3263                     _reset_multitap_state();
3264                     if (config_values) {
3265                         _language_manager.reset_language(config_values->selected_language.c_str());
3266                     }
3267                     ise_show(keyboard_state->ic);
3268                 }
3269             }
3270         }
3271     }
3272 }
3273 #endif
3274
3275 static void ime_app_prediction_hint_set_cb(const char *prediction_hint, void *user_data)
3276 {
3277     char *sender = (char *)"mms";
3278     char *caller_id = (char *)"mms";
3279     char *hint = (char *)prediction_hint;
3280
3281     if (!prediction_hint) return;
3282     SECURE_LOGD("prediction hint : %s\n", prediction_hint);
3283
3284     if (strlen(prediction_hint) > 0) {
3285         input_smartreply_init(caller_id, sender, hint);
3286         input_smartreply_set_notify(_input_smartreply_notify_cb, NULL);
3287
3288         if (input_smartreply_is_enabled()) {
3289             input_smartreply_get_reply_async();
3290         }
3291     }
3292 }
3293
3294 static void ime_app_mime_type_set_request_cb(const char *mime_types, void *user_data)
3295 {
3296     LOGD("mime type : %s\n", mime_types);
3297
3298     clipboard_set_mime_type(true);
3299     clipboard_init_sel_type();
3300
3301     string str(mime_types), text_key = "text/", image_key = "image/";
3302
3303     if (str.find(text_key) != string::npos)
3304         clipboard_add_sel_type(CLIPBOARD_SEL_TEXT);
3305
3306     if (str.find(image_key) != string::npos)
3307         clipboard_add_sel_type(CLIPBOARD_SEL_IMAGE);
3308 }
3309
3310 static void ime_app_prediction_hint_data_set_cb(const char *key, const char *value, void *user_data)
3311 {
3312     SECURE_LOGD("key : %s, value : %s\n", key, value);
3313
3314     if (string(key) == "appid")
3315         ime_autofill_set_app_id(value);
3316     else if (string(key) == "res_id")
3317         ime_autofill_set_resource_id(value);
3318 }
3319
3320 static void ime_app_autocapital_type_set_cb(uint32_t type, void *user_data)
3321 {
3322     LOGD("autocapital type : %u\n", type);
3323     engine_loader_set_autocapital_type(type);
3324 }
3325
3326 static void ime_app_prediction_allow_set_cb(uint32_t prediction_allow, void *user_data)
3327 {
3328     LOGD("prediction allow : %u\n", prediction_allow);
3329     engine_loader_set_prediction_allow(prediction_allow);
3330 }
3331
3332 static void ime_app_trigger_property_set_cb(const char *property, void *user_data)
3333 {
3334     LOGD("trigger property : %s\n", property);
3335     engine_loader_trigger_property(property);
3336 }
3337
3338 static void ime_app_candidate_more_window_show_cb(void *user_data)
3339 {
3340     LOGD("");
3341     engine_loader_show_candidate_more_window();
3342 }
3343
3344 static void ime_app_candidate_more_window_hide_cb(void *user_data)
3345 {
3346     LOGD("");
3347     engine_loader_hide_candidate_more_window();
3348 }
3349
3350 static void ime_app_aux_select_cb(uint32_t item, void *user_data)
3351 {
3352     LOGD("aux select : %u\n", item);
3353     engine_loader_select_aux(item);
3354 }
3355
3356 static void ime_app_candidate_select_cb(uint32_t item, void *user_data)
3357 {
3358     LOGD("candidate select : %u\n", item);
3359     engine_loader_select_candidate(item);
3360 }
3361
3362 static void ime_app_candidate_table_page_up_cb(void *user_data)
3363 {
3364     LOGD("");
3365     engine_loader_candidate_table_page_up();
3366 }
3367
3368 static void ime_app_candidate_table_page_down_cb(void *user_data)
3369 {
3370     LOGD("");
3371     engine_loader_candidate_table_page_down();
3372 }
3373
3374 static void ime_app_candidate_table_page_size_chaned_cb(uint32_t size, void *user_data)
3375 {
3376     LOGD("candidate page size : %u\n", size);
3377     engine_loader_change_candidate_page_size(size);
3378 }
3379
3380 static void ime_app_candidate_item_layout_set_cb(vector<uint32_t> item, void *user_data)
3381 {
3382     LOGD("item layout size : %zu", item.size());
3383     engine_loader_set_candidate_item_layout(item);
3384 }
3385
3386 static void ime_app_displayed_candidate_number_chaned_cb(uint32_t page_num, void *user_data)
3387 {
3388     LOGD("candidate number changed : %u\n", page_num);
3389     engine_loader_change_candidate_number(page_num);
3390 }
3391
3392 static void ime_app_candidate_item_long_pressed_cb(uint32_t index, void *user_data)
3393 {
3394     LOGD("candidate item : %u\n", index);
3395     engine_loader_long_press_candidate_item(index);
3396 }
3397
3398 #ifdef __cplusplus
3399 extern "C"{
3400 #endif
3401 EXPORTED void ime_app_main(int argc, char **argv)
3402 {
3403     ime_callback_s basic_callback = {
3404         ime_app_create_cb,
3405         ime_app_exit_cb,
3406         ime_app_show_cb,
3407         ime_app_hide_cb
3408     };
3409
3410     ime_event_set_focus_in_cb(ime_app_focus_in_cb, NULL);
3411     ime_event_set_focus_out_cb(ime_app_focus_out_cb, NULL);
3412     ime_event_set_rotation_degree_changed_cb(ime_app_rotation_degree_changed_cb, NULL);
3413     ime_event_set_accessibility_state_changed_cb(ime_app_accessibility_state_changed_cb, NULL);
3414     ime_event_set_layout_set_cb(ime_app_layout_set_cb, NULL);
3415     ime_event_set_caps_mode_changed_cb(ime_app_caps_mode_changed_cb, NULL);
3416     ime_event_set_cursor_position_updated_cb(ime_app_cursor_position_updated_cb, NULL);
3417     ime_event_set_surrounding_text_updated_cb(ime_app_surrounding_text_updated_cb, NULL);
3418     ime_event_set_return_key_type_set_cb(ime_app_return_key_type_set_cb, NULL);
3419     ime_event_set_return_key_state_set_cb(ime_app_return_key_state_set_cb, NULL);
3420     ime_event_set_language_set_cb(ime_app_language_set_cb, NULL);
3421     ime_event_set_imdata_set_cb(ime_app_imdata_set_cb, NULL);
3422     ime_event_set_process_key_event_cb(ime_app_process_key_event_cb, NULL);
3423     ime_event_set_process_key_event_with_imengine_cb(ime_app_process_key_event_with_imengine_cb, NULL);
3424     ime_event_set_input_hint_set_cb(ime_app_input_hint_set_cb, NULL);
3425
3426     ime_event_set_candidate_show_cb(ime_app_candidate_show_cb, NULL);
3427     ime_event_set_candidate_hide_cb(ime_app_candidate_hide_cb, NULL);
3428     ime_event_set_lookup_table_changed_cb(ime_app_lookup_table_changed_cb, NULL);
3429
3430 #ifdef _WEARABLE
3431     ime_event_set_process_input_device_event_cb(ime_app_process_input_device_event_cb, NULL);
3432 #endif
3433
3434     ime_event_set_input_context_reset_cb(ime_app_input_context_reset_cb, NULL);
3435     ime_event_set_language_requested_cb(ime_app_language_requested_cb, NULL);
3436
3437     ime_event_set_prediction_hint_set_cb(ime_app_prediction_hint_set_cb, NULL);
3438     ime_event_set_mime_type_set_request_cb(ime_app_mime_type_set_request_cb, NULL);
3439     ime_event_set_prediction_hint_data_set_cb(ime_app_prediction_hint_data_set_cb, NULL);
3440
3441     ime_event_set_autocapital_type_set_cb(ime_app_autocapital_type_set_cb, NULL);
3442     ime_event_set_prediction_allow_set_cb(ime_app_prediction_allow_set_cb, NULL);
3443     ime_event_set_trigger_property_set_cb(ime_app_trigger_property_set_cb, NULL);
3444     ime_event_set_candidate_more_window_show_cb(ime_app_candidate_more_window_show_cb, NULL);
3445     ime_event_set_candidate_more_window_hide_cb(ime_app_candidate_more_window_hide_cb, NULL);
3446     ime_event_set_aux_select_cb(ime_app_aux_select_cb, NULL);
3447     ime_event_set_candidate_select_cb(ime_app_candidate_select_cb, NULL);
3448     ime_event_set_candidate_table_page_up_cb(ime_app_candidate_table_page_up_cb, NULL);
3449     ime_event_set_candidate_table_page_down_cb(ime_app_candidate_table_page_down_cb, NULL);
3450     ime_event_set_candidate_table_page_size_chaned_cb(ime_app_candidate_table_page_size_chaned_cb, NULL);
3451     ime_event_set_candidate_item_layout_set_cb(ime_app_candidate_item_layout_set_cb, NULL);
3452     ime_event_set_displayed_candidate_number_chaned_cb(ime_app_displayed_candidate_number_chaned_cb, NULL);
3453     ime_event_set_candidate_item_long_pressed_cb(ime_app_candidate_item_long_pressed_cb, NULL);
3454
3455 #if DEFER_ISE_CREATION
3456     ime_set_window_creation_defer_flag(TRUE);
3457 #endif
3458
3459     ime_run(&basic_callback, NULL);
3460 }
3461 #ifdef __cplusplus
3462 }
3463 #endif
3464
3465 EXPORTED int main(int argc, char *argv[])
3466 {
3467     ime_app_main(argc, argv);
3468
3469     return 0;
3470 }