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