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