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