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