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