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