Fix issue: Disappearance of the page "(2/3)" in Emoticon layout
[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_INPUT_MODE_CHANGE) {
710         SclNotiInputModeChangeDesc *desc = static_cast<SclNotiInputModeChangeDesc*>(etc_info);
711         if (desc && g_ui) {
712             set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
713
714             if (strcmp(g_ui->get_input_mode(), "STT_3X4") == 0 &&
715                 strcmp(desc->input_mode, "STT_3X4") != 0) {
716                 ise_hide_stt_mode();
717             }
718             if (strcmp(g_ui->get_input_mode(), "STT_3X4") != 0 &&
719                 strcmp(desc->input_mode, "STT_3X4") == 0) {
720                 ise_show_stt_mode(NATIVE_WINDOW_CAST(ime_get_main_window()));
721             }
722         }
723     }
724
725     return ret;
726 }
727
728 void ise_destory_guideline_popup()
729 {
730     if (_guide_popup_window != NULL) {
731         evas_object_del(_guide_popup_window);
732         _guide_popup_window = NULL;
733     }
734 }
735
736 void _guideline_popup_dismissed_cb(void *data, Evas_Object *obj, void *event_info)
737 {
738     evas_object_smart_callback_del(obj, "dismissed", _guideline_popup_dismissed_cb);
739     evas_object_del(obj);
740     obj = NULL;
741
742     if (_guide_popup_window != NULL) {
743         evas_object_del(_guide_popup_window);
744         _guide_popup_window = NULL;
745     }
746
747     g_config_values.first_guideset = TRUE;
748     write_ise_config_values();
749 }
750
751 Evas_Object *open_message_popup(Evas_Object *parentWnd)
752 {
753     static Evas_Object *msg_window = NULL;
754     if (msg_window) {
755         evas_object_del(msg_window);
756         msg_window = NULL;
757     }
758     msg_window = elm_win_add(parentWnd, "MCFMessagePopup", ELM_WIN_UTILITY);
759     if (msg_window) {
760         int w, h;
761         elm_win_borderless_set(msg_window, EINA_TRUE);
762         elm_win_alpha_set(msg_window, EINA_TRUE);
763         elm_win_title_set(msg_window, "ISF Popup");
764         elm_win_screen_size_get(msg_window, NULL, NULL, &w, &h);
765         elm_win_prop_focus_skip_set(msg_window, TRUE);
766         int rots[4] = {0, 90, 180, 270};
767         elm_win_wm_rotation_available_rotations_set(msg_window, rots, 4);
768         evas_object_resize(msg_window, w, h);
769     }
770
771     int rots[4] = { 0, 90, 180, 270 };
772     elm_win_wm_rotation_available_rotations_set(msg_window, rots, 4);
773     evas_object_show(msg_window);
774     return msg_window;
775 }
776
777 void ise_show_help_popup(sclulong keyEvent)
778 {
779     char buf[2048] = {0, };
780     int font_size = 40;
781     sclint scr_w = 0;
782     sclint scr_h = 0;
783     SclRectangle rectangle = {0};
784
785     if (g_ui) {
786         g_ui->get_screen_resolution(&scr_w, &scr_h);
787
788         if (keyEvent == MVK_space) {
789             g_ui->get_button_geometry("SPACE_KEY", &rectangle);
790         } else {
791             g_ui->get_button_geometry("CM_KEY", &rectangle);
792         }
793     }
794
795     _guide_popup_window = open_message_popup(NATIVE_WINDOW_CAST(ime_get_main_window()));
796
797     Elm_Theme *theme = elm_theme_new();
798     elm_theme_ref_set(theme, NULL);
799     elm_theme_extension_add(theme, EDJ_FILE);
800
801     Evas_Object *ctxpopup = elm_ctxpopup_add(_guide_popup_window);
802     elm_object_theme_set(ctxpopup, theme);
803
804     int rotation = elm_win_rotation_get(NATIVE_WINDOW_CAST(ime_get_main_window()));
805     if (rotation == 0 || rotation == 180) {
806         elm_object_style_set(ctxpopup, "customised_guideline_popup");
807     } else {
808         elm_object_style_set(ctxpopup, "customised_guideline_popup_landscape");
809     }
810
811     evas_object_smart_callback_add(ctxpopup, "dismissed", _guideline_popup_dismissed_cb, (void *)keyEvent);
812     elm_ctxpopup_direction_priority_set(ctxpopup, ELM_CTXPOPUP_DIRECTION_UP,
813                           ELM_CTXPOPUP_DIRECTION_UNKNOWN,
814                           ELM_CTXPOPUP_DIRECTION_UNKNOWN,
815                           ELM_CTXPOPUP_DIRECTION_UNKNOWN);
816
817     Evas_Object* text = elm_label_add(ctxpopup);
818
819     if (keyEvent == MVK_space) {
820         snprintf(buf, sizeof(buf), "<font_style=Regular font_size=%d align=left wrap=mixed color=#000000>%s</>", font_size,
821             dgettext(PACKAGE, "IDS_IME_BODY_SWIPE_THE_SPACE_BAR_LEFT_OR_RIGHT_TO_CHANGE_BETWEEN_LANGUAGES"));
822     } else {
823         snprintf(buf, sizeof(buf), "<font_style=Regular font_size=%d align=left wrap=mixed color=#000000>%s</>", font_size,
824                dgettext(PACKAGE, "IDS_IME_BODY_TAP_AND_HOLD_THIS_KEY_TO_SEE_THE_SYMBOL_LIST_SELECT_ONE_TO_USE_IT_AS_A_SHORTCUT"));
825     }
826     elm_object_text_set(text, buf);
827     elm_object_content_set(ctxpopup, text);
828     Evas_Coord x, y, w, h;
829     evas_object_geometry_get(NATIVE_WINDOW_CAST(ime_get_main_window()), &x, &y, &w, &h);
830
831     if (rotation == 0 || rotation == 180) {
832         elm_label_wrap_width_set(text, (scr_w * 4) / 5);
833         evas_object_size_hint_min_set(ctxpopup, ELM_SCALE_SIZE(scr_w), ELM_SCALE_SIZE(50));
834         evas_object_size_hint_max_set(ctxpopup, ELM_SCALE_SIZE(scr_w), ELM_SCALE_SIZE(600));
835         evas_object_move(ctxpopup, rectangle.x + rectangle.width / 2,
836                     (scr_h - h) + rectangle.y - ELM_SCALE_SIZE(5));
837     } else {
838         elm_label_wrap_width_set(text, (scr_h * 4) / 5);
839         evas_object_size_hint_min_set(ctxpopup, ELM_SCALE_SIZE(scr_h), ELM_SCALE_SIZE(50));
840         evas_object_size_hint_max_set(ctxpopup, ELM_SCALE_SIZE(scr_h), ELM_SCALE_SIZE(600));
841         evas_object_move(ctxpopup, rectangle.x + rectangle.width / 2,
842                 (scr_w - h)+ rectangle.y - ELM_SCALE_SIZE(5));
843     }
844     elm_label_line_wrap_set(text, ELM_WRAP_MIXED);
845     evas_object_show(text);
846
847     evas_object_layer_set(_guide_popup_window, EVAS_LAYER_MAX);
848     evas_object_show(_guide_popup_window);
849     evas_object_layer_set(ctxpopup, EVAS_LAYER_MAX);
850     evas_object_show(ctxpopup);
851 }
852
853 SCLEventReturnType CUIEventCallback::on_event_drag_state_changed(SclUIEventDesc event_desc)
854 {
855     if (event_desc.event_type == EVENT_TYPE_MOVE) {
856         if (event_desc.key_event == MVK_space) {
857             SclRectangle rectangle = {0};
858             g_ui->get_button_geometry("SPACE_KEY", &rectangle);
859             ise_show_space_flick_language_change_popup(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
860         }
861     } else if (event_desc.event_type == EVENT_TYPE_RELEASE) {
862         if (event_desc.key_event == MVK_space) {
863             ise_destroy_space_flick_language_change_popup();
864         }
865
866         if (g_floating_mode)
867             ime_set_floating_drag_end();
868     } else if (event_desc.event_type == EVENT_TYPE_PRESS) {
869 #ifdef _MOBILE
870         if ((!g_config_values.first_guideset) && (event_desc.key_type == KEY_TYPE_MODECHANGE)) {
871             ise_show_help_popup(event_desc.key_event);
872             return SCL_EVENT_PASS_ON;
873         }
874 #endif
875         if (g_floating_mode && event_desc.mouse_current_point.y <= FLOATING_TITLE_BAR_HEIGHT
876             && event_desc.mouse_current_point.y >= 0)
877             ime_set_floating_drag_start();
878     }
879     return SCL_EVENT_PASS_ON;
880 }
881
882 static void launch_option()
883 {
884     app_control_h app_control;
885     int ret = app_control_create(&app_control);
886     if (ret != APP_CONTROL_ERROR_NONE) {
887         LOGW("app_control_create returned %d\n", ret);
888         return;
889     }
890
891     ret = app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
892     if (ret != APP_CONTROL_ERROR_NONE) {
893         LOGW("app_control_set_operation returned %d\n", ret);
894         goto end;
895     }
896
897     ret = app_control_set_app_id(app_control, "org.tizen.ise-default-setting");
898     if (ret != APP_CONTROL_ERROR_NONE) {
899         LOGW("app_control_set_app_id returned %d\n", ret);
900         goto end;
901     }
902
903     ret = app_control_send_launch_request(app_control, NULL, NULL);
904     if (ret != APP_CONTROL_ERROR_NONE) {
905         goto end;
906     }
907
908 end:
909     if (app_control)
910         app_control_destroy(app_control);
911 }
912
913 SCLEventReturnType CUIEventCallback::on_event_key_clicked(SclUIEventDesc event_desc)
914 {
915     SCLEventReturnType ret = SCL_EVENT_PASS_ON;
916
917     if (event_desc.key_modifier == KEY_MODIFIER_MULTITAP_START) {
918         if (!g_keyboard_state.multitap_value.empty()) {
919             ise_send_string(g_keyboard_state.multitap_value.c_str());
920         }
921         ise_update_preedit_string(event_desc.key_value);
922         g_keyboard_state.multitap_value = event_desc.key_value;
923     } else if (event_desc.key_modifier == KEY_MODIFIER_MULTITAP_REPEAT) {
924         ise_update_preedit_string(event_desc.key_value);
925         g_keyboard_state.multitap_value = event_desc.key_value;
926     } else {
927         _reset_multitap_state();
928     }
929     g_keyboard_state.prev_modifier = event_desc.key_modifier;
930
931     if (g_ui) {
932         switch (event_desc.key_type) {
933         case KEY_TYPE_STRING: {
934             if (event_desc.key_modifier != KEY_MODIFIER_MULTITAP_START &&
935                 event_desc.key_modifier != KEY_MODIFIER_MULTITAP_REPEAT) {
936                     if (event_desc.key_event) {
937                         ise_forward_key_event(event_desc.key_event);
938                     } else {
939                         ise_send_string(event_desc.key_value);
940                     }
941             }
942             if (!g_popup_opened) {
943                 const sclchar *input_mode = g_ui->get_input_mode();
944                 if (input_mode && ((0 == strcmp(input_mode, "SYM_QTY_1")) || (0 == strcmp(input_mode, "SYM_QTY_2")))) {
945                     update_recent_used_punctuation(event_desc.key_value);
946                 }
947             } else if (g_punctuation_popup_opened) {
948                 update_recent_used_punctuation(event_desc.key_value);
949                 g_punctuation_popup_opened = FALSE;
950                 g_popup_opened = FALSE;
951             }
952             break;
953         }
954         case KEY_TYPE_CHAR: {
955                 sclboolean need_forward = FALSE;
956                 // FIXME : Should decide when to forward key events
957                 const sclchar *input_mode = g_ui->get_input_mode();
958                 if (input_mode) {
959                     if (strcmp(input_mode, "SYM_QTY_1") == 0 ||
960                             strcmp(input_mode, "SYM_QTY_2") == 0 ||
961                             strcmp(input_mode, "PHONE_3X4") == 0 ||
962                             strcmp(input_mode, "IPv6_3X4_123") == 0 ||
963                             strcmp(input_mode, "IPv6_3X4_ABC") == 0 ||
964                             strcmp(input_mode, "NUMONLY_3X4") == 0 ||
965                             strcmp(input_mode, "NUMONLY_3X4_SIG") == 0 ||
966                             strcmp(input_mode, "NUMONLY_3X4_DEC") == 0 ||
967                             strcmp(input_mode, "NUMONLY_3X4_SIGDEC") == 0 ||
968                             strcmp(input_mode, "DATETIME_3X4") == 0) {
969                         need_forward = TRUE;
970                     }
971                 }
972                 if (input_mode && strcmp (input_mode, "NUMONLY_3X4_SIGDEC") == 0 &&
973                     strcmp(event_desc.key_value, ".") == 0) {
974                     ime_update_preedit_string(_sig_dec[_click_count%SIG_DEC_SIZE], NULL);
975                     ime_show_preedit_string();
976                     delete_commit_timer();
977                     _commit_timer = ecore_timer_add(1.0, commit_timeout, NULL);
978                     _click_count++;
979                 } else if (event_desc.key_event) {
980                     commit_timeout(NULL);
981                     if (need_forward) {
982                         ise_forward_key_event(event_desc.key_event);
983                     } else {
984                         if (_cm_popup_opened) {
985                             static sclchar current_cm_symbol[2] = {'\0'};
986                             sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
987                                 const_cast<sclchar*>(" "),
988                                 const_cast<sclchar*>(" "),
989                                 const_cast<sclchar*>(" ")};
990                             if (event_desc.key_value) {
991                                 current_cm_symbol[0] = event_desc.key_value[0];
992                                 current_cm_symbol[1] = '\0';
993                             }
994                             g_ui->set_private_key("CM_KEY",
995                                     const_cast<sclchar*>(current_cm_symbol),
996                                     imagelabel, NULL, 0,
997                                     const_cast<sclchar*>(current_cm_symbol), TRUE);
998
999                             _cm_popup_opened = FALSE;
1000                             _current_cm_key_id = -1;
1001                         }
1002                         ise_send_event(event_desc.key_event, KEY_MASK_NULL);
1003                     }
1004                 }
1005                 if (input_mode) {
1006                     if ((strcmp(input_mode, "SYM_QTY_1") == 0) || (0 == strcmp(input_mode, "SYM_QTY_2"))) {
1007                         update_recent_used_punctuation(event_desc.key_value);
1008                     }
1009                 }
1010                 break;
1011             }
1012         case KEY_TYPE_CONTROL: {
1013                 commit_timeout(NULL);
1014
1015                 const char *long_shift = "LongShift";
1016                 const char *caps_lock = "CapsLock";
1017                 const char *delete_all = "DeleteAll";
1018                 const char *hide_panel = "Hide";
1019                 if (strncmp(event_desc.key_value, long_shift, strlen(long_shift)) == 0) {
1020                     LOGD("shift key is longpress\n");
1021                     g_ui->set_shift_state(SCL_SHIFT_STATE_ON);
1022                     g_need_send_shift_event = TRUE;
1023                     //ise_send_event (MVK_Shift_Lock, KEY_MASK_NULL);
1024                 } else if (strncmp(event_desc.key_value, caps_lock, strlen(caps_lock)) == 0) {
1025                     if (g_ui->get_shift_state() != SCL_SHIFT_STATE_LOCK) {
1026                         g_ui->set_shift_state(SCL_SHIFT_STATE_LOCK);
1027                         ise_send_event(MVK_Shift_Lock, KEY_MASK_NULL);
1028                     } else {
1029                         g_ui->set_shift_state(SCL_SHIFT_STATE_OFF);
1030                         ise_send_event(MVK_Shift_Off, KEY_MASK_NULL);
1031                     }
1032                     //g_need_send_shift_event = TRUE;
1033                 } else if (strncmp(event_desc.key_value, delete_all, strlen(delete_all)) == 0) {
1034                     ime_delete_surrounding_text((INT_MAX / 2) * -1, INT_MAX);
1035                 } else if (strncmp(event_desc.key_value, hide_panel, strlen(hide_panel)) == 0) {
1036                     ise_hide();
1037                     ime_request_hide();
1038                 } else if (event_desc.key_event) {
1039                     ise_send_event(event_desc.key_event, KEY_MASK_NULL);
1040                     if (event_desc.key_event == MVK_Shift_L) {
1041                         g_need_send_shift_event = TRUE;
1042                     }
1043                 }
1044                 break;
1045            }
1046         case KEY_TYPE_MODECHANGE:
1047 #ifdef _MOBILE
1048             if (!g_config_values.first_guideset) {
1049                break;
1050             }
1051 #endif
1052             if (strcmp(event_desc.key_value, USER_VOICE_LANGUAGE) == 0) {
1053                 if (!g_setting_window_open_status) {
1054                     ise_hide_stt_mode();
1055 #ifdef _WEARABLE
1056                     hide_indicator_window();
1057 #endif
1058                     create_setting_window();
1059                 }
1060             } else if (strcmp(event_desc.key_value, USER_KEYSTRING_VOICE) == 0) {
1061                 g_keyboard_state.layout = ISE_LAYOUT_STYLE_VOICE;
1062                 g_ui->set_input_mode("STT_3X4");
1063
1064             } else if (strcmp(event_desc.key_value, USER_KEYSTRING_OPTION) == 0) {
1065                 launch_option();
1066
1067                 ret = SCL_EVENT_DONE;
1068             } else if (strcmp(event_desc.key_value, USER_KEYSTRING_CLIPBOARD) == 0) {
1069                 show_cbhm();
1070
1071                 ret = SCL_EVENT_DONE;
1072             } else if (strcmp(event_desc.key_value, USER_KEYSTRING_FLOATING) == 0) {
1073                 if (g_floating_mode)
1074                     g_config_values.floating_mode = false;
1075                 else
1076                     g_config_values.floating_mode = true;
1077                 write_ise_config_values();
1078
1079                 ret = SCL_EVENT_DONE;
1080             } else if (on_input_mode_changed(event_desc.key_value, event_desc.key_event, event_desc.key_type)) {
1081                 ret = SCL_EVENT_DONE;
1082             }
1083             if (_cm_popup_opened) {
1084                 if (strcmp(event_desc.key_value, USER_KEYSTRING_EMOTICON) == 0 ||
1085                     strcmp(event_desc.key_value, USER_KEYSTRING_VOICE) == 0 ||
1086                     strcmp(event_desc.key_value, USER_KEYSTRING_FLOATING) == 0) {
1087                     scluint id = ise_get_cm_key_id(event_desc.key_value);
1088                     if (id != _current_cm_key_id) {
1089                         _current_cm_key_id = id;
1090                         ise_set_cm_private_key(_current_cm_key_id);
1091                     }
1092                 }
1093                 _cm_popup_opened = FALSE;
1094             }
1095             if (strlen(event_desc.key_value) == 1) {
1096                 const char allowed_chars_in_modechange[] = {
1097                     ',', '?', '!', '`', '~'
1098                 };
1099                 const int allowed_chars_in_modechange_num =
1100                     sizeof(allowed_chars_in_modechange) / sizeof(char);
1101                 for (unsigned int loop = 0;loop < sizeof(allowed_chars_in_modechange_num);loop++) {
1102                     if (*(event_desc.key_value) == allowed_chars_in_modechange[loop]) {
1103                         ise_send_string(event_desc.key_value);
1104                     }
1105                 }
1106             }
1107             break;
1108         case KEY_TYPE_USER:
1109             if (strcmp(event_desc.key_value, USER_KEYSTRING_OPTION) == 0) {
1110                 //open_option_window(NULL, ROTATION_TO_DEGREE(g_ui->get_rotation()));
1111                 launch_option();
1112
1113                 ret = SCL_EVENT_DONE;
1114             } else if (strcmp(event_desc.key_value, USER_KEYSTRING_CLIPBOARD) == 0) {
1115                 show_cbhm();
1116                 ret = SCL_EVENT_DONE;
1117             } else if (strcmp(event_desc.key_value, "Cancel") == 0) {
1118                 ret = SCL_EVENT_DONE;
1119                 if (strcmp(g_ui->get_input_mode(), "STT_3X4") == 0 ) {
1120                     g_keyboard_state.need_reset = TRUE;
1121                     voice_result_string_flush();
1122                     ise_set_layout(g_keyboard_state.layout, g_keyboard_state.layout_variation);
1123                     if (g_keyboard_state.visible_state)
1124                         ise_show(g_keyboard_state.ic);
1125                 }
1126                 ise_send_event(IME_KEY_Cancel, KEY_MASK_NULL);
1127                 ime_request_hide();
1128             }  else if (strcmp(event_desc.key_value, "Done") == 0) {
1129                 ret = SCL_EVENT_DONE;
1130                 ise_send_event(IME_KEY_Return, KEY_MASK_NULL);
1131                 ime_request_hide();
1132             }  else {
1133                 const sclchar *input_mode = g_ui->get_input_mode();
1134                 if ((NULL != input_mode) && (!strcmp(input_mode, "EMOTICON_LAYOUT"))) {
1135                     if (is_emoticon_show()) {
1136                         ise_destroy_emoticon_layout();
1137                     }
1138 #ifdef _WEARABLE
1139                     emoticon_group_t group_id = EMOTICON_GROUP_1;
1140                     if (current_emoticon_group < EMOTICON_GROUP_3)
1141                         group_id = (emoticon_group_t)(current_emoticon_group + 1);
1142
1143                     const int BUF_LEN = 16;
1144                     char buf[BUF_LEN] = {0};
1145                     snprintf(buf, BUF_LEN, "%d/3", group_id);
1146                     g_ui->set_private_key("EMOTICON_GROUP_ID", buf, NULL, NULL, 0, const_cast<sclchar*>("EMOTICON_GROUP_NEXT"), TRUE);
1147 #else
1148                     emoticon_group_t group_id = ise_get_emoticon_group_id(event_desc.key_value);
1149 #endif
1150                     if ((group_id >= 0) && (group_id < MAX_EMOTICON_GROUP)) {
1151                         SCLRotation rotation = g_ui->get_rotation();
1152                         ise_show_emoticon_layout(group_id, ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
1153                     }
1154                 }
1155             }
1156             if (_cm_popup_opened) {
1157                 if (strcmp(event_desc.key_value, USER_KEYSTRING_OPTION) == 0 ||
1158                     strcmp(event_desc.key_value, USER_KEYSTRING_CLIPBOARD) == 0) {
1159                     scluint id = ise_get_cm_key_id(event_desc.key_value);
1160                     if (id != _current_cm_key_id) {
1161                         _current_cm_key_id = id;
1162                         ise_set_cm_private_key(_current_cm_key_id);
1163                     }
1164                 }
1165                 _cm_popup_opened = FALSE;
1166             }
1167             break;
1168         default:
1169             break;
1170         }
1171     }
1172
1173     return ret;
1174 }
1175
1176 void
1177 ise_set_layout(sclu32 layout, sclu32 layout_variation)
1178 {
1179     /* Check if the layoutIdx is in the valid range */
1180     if (layout < ISE_LAYOUT_STYLE_MAX) {
1181         if (g_keyboard_state.layout != layout ||
1182             g_keyboard_state.layout_variation != layout_variation) {
1183             g_keyboard_state.need_reset = TRUE;
1184         }
1185         g_keyboard_state.layout = layout;
1186         g_keyboard_state.layout_variation = layout_variation;
1187         LOGD("layout:%d, variation:%d\n", g_keyboard_state.layout, g_keyboard_state.layout_variation);
1188     }
1189 }
1190
1191 void
1192 ise_reset_context()
1193 {
1194     LOGD("");
1195     _reset_multitap_state(true);
1196     _language_manager.reset_language(g_config_values.selected_language.c_str());
1197 }
1198
1199 void
1200 ise_reset_input_context()
1201 {
1202     LOGD("");
1203     _reset_multitap_state(true);
1204     g_keyboard_state.disable_force_latin = FALSE;
1205     _language_manager.reset_language(g_config_values.selected_language.c_str());
1206 }
1207
1208 void
1209 ise_focus_in(int ic)
1210 {
1211     LOGD("ic : %x , %x , g_ic : %x , %x, g_focused_ic : %x , %x\n", ic, check_ic_temporary(ic),
1212             g_keyboard_state.ic, check_ic_temporary(g_keyboard_state.ic),
1213             g_keyboard_state.focused_ic, check_ic_temporary(g_keyboard_state.focused_ic));
1214     if (check_ic_temporary(g_keyboard_state.ic) && !check_ic_temporary(ic)) {
1215         g_keyboard_state.ic = ic;
1216     }
1217     g_keyboard_state.focused_ic = ic;
1218 }
1219
1220 static void save_autofill_data()
1221 {
1222     char *text = NULL;
1223     int cursor;
1224
1225     if (g_autofill_hint == 0)
1226         return;
1227
1228     ime_get_surrounding_text(-1, -1, &text, &cursor);
1229     SECURE_LOGD("surrounding text : %s\n", text);
1230     if (!text) return;
1231
1232     autofill_save_string((Ecore_IMF_Input_Hints)g_autofill_hint, text);
1233
1234     free(text);
1235 }
1236
1237 void
1238 ise_focus_out(int ic)
1239 {
1240     g_keyboard_state.focused_ic = 0;
1241     _reset_multitap_state(true);
1242
1243     save_autofill_data();
1244 }
1245
1246 bool ise_is_guideline_popup_enable_layout(void)
1247 {
1248     bool ret;
1249     switch (_context_layout)
1250     {
1251         case ISE_LAYOUT_STYLE_PHONENUMBER:
1252         case ISE_LAYOUT_STYLE_IP:
1253         case ISE_LAYOUT_STYLE_MONTH:
1254         case ISE_LAYOUT_STYLE_NUMBERONLY:
1255         case ISE_LAYOUT_STYLE_HEX:
1256         case ISE_LAYOUT_STYLE_TERMINAL:
1257         case ISE_LAYOUT_STYLE_DATETIME:
1258         case ISE_LAYOUT_STYLE_PASSWORD:
1259             ret = false;
1260             break;
1261         default:
1262             ret = true;
1263             break;
1264     }
1265     return ret;
1266 }
1267
1268 #ifdef _MOBILE
1269 static Eina_Bool popup_guideline_timer_cb(void *data)
1270 {
1271     if ((!g_config_values.first_guidechange) && (_language_manager.get_enabled_languages_num() > 1)) {
1272         ise_show_help_popup(MVK_space);
1273         g_config_values.first_guidechange = TRUE;
1274         write_ise_config_values();
1275     }
1276
1277     guideline_timer = NULL;
1278     return ECORE_CALLBACK_CANCEL;
1279 }
1280 #endif
1281
1282 #if EXIT_ISE_ON_HIDE
1283 static Eina_Bool exit_timer_cb(void *data)
1284 {
1285     if (exit_timer) ecore_timer_del(exit_timer);
1286     exit_timer = NULL;
1287     elm_exit();
1288     return ECORE_CALLBACK_CANCEL;
1289 }
1290 #endif
1291
1292 void
1293 ise_show(int ic)
1294 {
1295 #if EXIT_ISE_ON_HIDE
1296     if (exit_timer) ecore_timer_del(exit_timer);
1297     exit_timer = NULL;
1298 #endif
1299 #ifdef _WEARABLE
1300     /*
1301      *Clear the personalized data
1302      */
1303     if (g_config_values.dataclear){
1304         ime_send_key_event(IME_KEY_Clear, IME_KEY_MASK_CONTROL, false);
1305         g_config_values.dataclear = FALSE;
1306     }
1307 #endif
1308     sclboolean reset_inputmode = FALSE;
1309     g_popup_opened = FALSE;
1310     g_input_panel_show = true;
1311
1312     if (g_ui) {
1313         read_ise_config_values();
1314
1315         _language_manager.set_enabled_languages(g_config_values.enabled_languages);
1316
1317         LOGD("ic : %x , %x , g_ic : %x , %x, g_focused_ic : %x , %x\n", ic, check_ic_temporary(ic),
1318                 g_keyboard_state.ic, check_ic_temporary(g_keyboard_state.ic),
1319                 g_keyboard_state.focused_ic, check_ic_temporary(g_keyboard_state.focused_ic));
1320
1321         if (check_ic_temporary(ic) && !check_ic_temporary(g_keyboard_state.focused_ic)) {
1322             ic = g_keyboard_state.focused_ic;
1323         }
1324
1325         if (!check_ic_temporary(ic) && check_ic_temporary(g_keyboard_state.focused_ic)) {
1326             g_keyboard_state.focused_ic = ic;
1327         }
1328
1329         if (ic == g_keyboard_state.focused_ic) {
1330             if (g_keyboard_state.layout == ISE_LAYOUT_STYLE_PHONENUMBER ||
1331                     g_keyboard_state.layout == ISE_LAYOUT_STYLE_IP ||
1332                     g_keyboard_state.layout == ISE_LAYOUT_STYLE_MONTH ||
1333                     g_keyboard_state.layout == ISE_LAYOUT_STYLE_NUMBERONLY) {
1334                 ime_set_imengine(DEFAULT_KEYBOARD_ISE_UUID);
1335             }
1336         }
1337
1338         /* Reset input mode if the input context value has changed */
1339         if (ic != g_keyboard_state.ic) {
1340             /* Do not reset input mode if STT's setting window was opened */
1341             if (g_setting_window_open_status && strcmp(g_ui->get_input_mode(), "STT_3X4") == 0) {
1342                 LOGD("Setting window was opened while using STT, skip resetting input mode");
1343             } else {
1344                 reset_inputmode = TRUE;
1345             }
1346         }
1347
1348         g_keyboard_state.ic = ic;
1349         /* Reset input mode if the current language is not the selected language */
1350         const sclchar * cur_lang = _language_manager.get_current_language();
1351         if (cur_lang) {
1352             if (g_config_values.selected_language.compare(cur_lang) != 0) {
1353                 reset_inputmode = TRUE;
1354             }
1355         }
1356
1357         /* No matter what, just reset the inputmode if it needs to */
1358         if (g_keyboard_state.need_reset) {
1359             /* Do not reset input mode if STT's setting window was opened */
1360             if (g_setting_window_open_status && strcmp(g_ui->get_input_mode(), "STT_3X4") == 0) {
1361                 LOGD("Setting window was opened while using STT, skip resetting input mode");
1362             } else {
1363                 reset_inputmode = TRUE;
1364             }
1365         }
1366         g_keyboard_state.need_reset = FALSE;
1367
1368         /* If the current layout requires latin language and current our language is not latin, enable the primary latin */
1369         sclboolean force_primary_latin = FALSE;
1370         LANGUAGE_INFO *info = _language_manager.get_language_info(g_config_values.selected_language.c_str());
1371         if (info) {
1372             if (g_ise_default_values[g_keyboard_state.layout].force_latin && !(info->is_latin_language)) {
1373                 if (!g_keyboard_state.disable_force_latin) {
1374                     force_primary_latin = TRUE;
1375                 }
1376             }
1377         }
1378         if (force_primary_latin) {
1379             /* If there is enabled latin-based language, select it */
1380             sclboolean selected = FALSE;
1381             for (scluint loop = 0;!selected && loop < _language_manager.get_languages_num();loop++) {
1382                 LANGUAGE_INFO *info = _language_manager.get_language_info(loop);
1383                 if (info) {
1384                     if (info->enabled && info->is_latin_language) {
1385                         selected = _language_manager.select_language(info->name.c_str());
1386                         if (selected) force_primary_latin = FALSE;
1387                     }
1388                 }
1389             }
1390             if (!selected) {
1391                 _language_manager.set_language_enabled_temporarily(PRIMARY_LATIN_LANGUAGE, TRUE);
1392             }
1393         }
1394
1395         if (reset_inputmode) {
1396             ise_reset_context();
1397
1398             bool filename_layout = false;
1399
1400             /* Turn the shift state off if we need to reset our input mode, only when auto-capitalization is not set  */
1401             if (!(g_keyboard_state.caps_mode)) {
1402                 g_ui->set_shift_state(SCL_SHIFT_STATE_OFF);
1403             }
1404             if (g_keyboard_state.layout < ISE_LAYOUT_STYLE_MAX) {
1405                 sclu32 layout_index = g_keyboard_state.layout;
1406                 if (g_keyboard_state.layout == ISE_LAYOUT_STYLE_NUMBERONLY &&
1407                     g_keyboard_state.layout_variation > 0 &&
1408                     g_keyboard_state.layout_variation < ISE_LAYOUT_NUMBERONLY_VARIATION_MAX) {
1409                     layout_index = ISE_LAYOUT_STYLE_NUMBERONLY_SIG + g_keyboard_state.layout_variation - 1;
1410                 } else if (g_keyboard_state.layout == ISE_LAYOUT_STYLE_PASSWORD && g_keyboard_state.layout_variation > 0) {
1411                     layout_index = ISE_LAYOUT_STYLE_PASSWD_3X4;
1412                 }
1413
1414                 if (g_keyboard_state.layout == ISE_LAYOUT_STYLE_NORMAL &&
1415                     g_keyboard_state.layout_variation == ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL_VARIATION_FILENAME)
1416                     filename_layout = true;
1417                 else
1418                     filename_layout = false;
1419
1420                 g_ui->enable_button("exclamation", !filename_layout);
1421                 g_ui->enable_button("question", !filename_layout);
1422                 g_ui->enable_button("divide", !filename_layout);
1423                 g_ui->enable_button("multiply", !filename_layout);
1424                 g_ui->enable_button("colon", !filename_layout);
1425                 g_ui->enable_button("quotation", !filename_layout);
1426
1427                 g_ui->enable_button("CM_KEY", !access("/home", X_OK));
1428
1429                 LOGD("new layout index : %d\n", layout_index);
1430                 /* If this layout requires specific input mode, set it */
1431                 if (strlen(g_ise_default_values[layout_index].input_mode) > 0) {
1432                     g_ui->set_input_mode(g_ise_default_values[layout_index].input_mode);
1433                     set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
1434                 } else {
1435                     if (force_primary_latin) {
1436                         _language_manager.select_language(PRIMARY_LATIN_LANGUAGE, TRUE);
1437                     } else {
1438                         if (!(_language_manager.select_language(g_config_values.selected_language.c_str()))) {
1439                             _language_manager.select_language(PRIMARY_LATIN_LANGUAGE);
1440                         }
1441                     }
1442                 }
1443                 g_ui->set_cur_sublayout(g_ise_default_values[layout_index].sublayout_name);
1444                 if (is_emoticon_show()) {
1445                     ise_destroy_emoticon_layout();
1446                 }
1447
1448                 if (g_keyboard_state.layout == ISE_LAYOUT_STYLE_EMOTICON) {
1449                     ise_init_emoticon_list();
1450 #ifdef _WEARABLE
1451                     current_emoticon_group = EMOTICON_GROUP_1;
1452 #else
1453                     if (emoticon_list_recent.size() == 0)
1454                         current_emoticon_group = EMOTICON_GROUP_1;
1455                     else
1456                         current_emoticon_group = EMOTICON_GROUP_RECENTLY_USED;
1457 #endif
1458                     SCLRotation rotation = g_ui->get_rotation();
1459                     ise_show_emoticon_layout(current_emoticon_group, ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
1460                 }
1461             }
1462         }
1463
1464         if (info) {
1465             if (info->accepts_caps_mode) {
1466                 // FIXME this if condition means the AC is off
1467                 if (g_keyboard_state.layout != ISE_LAYOUT_STYLE_NORMAL) {
1468                     g_ui->set_autocapital_shift_state(TRUE);
1469                     g_ui->set_shift_state(SCL_SHIFT_STATE_OFF);
1470                 } else {
1471                     ise_send_event(MVK_Shift_Enable, KEY_MASK_NULL);
1472                     // Auto Capital is supported only in normal layout
1473                     if (g_keyboard_state.caps_mode) {
1474                         g_ui->set_autocapital_shift_state(FALSE);
1475                     }
1476                 }
1477             } else {
1478                 g_ui->set_autocapital_shift_state(TRUE);
1479                 ise_send_event(MVK_Shift_Disable, KEY_MASK_NULL);
1480                 g_ui->set_shift_state(SCL_SHIFT_STATE_OFF);
1481             }
1482         } else {
1483             g_ui->set_autocapital_shift_state(TRUE);
1484         }
1485
1486         // Update CM key button
1487         if (_current_cm_key_id < CM_KEY_LIST_SIZE) {
1488             if (strcmp(_cm_key_list[_current_cm_key_id], USER_KEYSTRING_EMOTICON) == 0) {
1489                 if (ise_is_emoticons_disabled())
1490                     ise_set_cm_private_key(ise_get_cm_key_id(USER_KEYSTRING_OPTION));
1491                 else
1492                     ise_set_cm_private_key(_current_cm_key_id);
1493             }
1494         }
1495
1496         // Update space key button
1497         ise_update_space_key();
1498
1499         g_ui->show();
1500         g_ui->disable_input_events(FALSE);
1501 #ifdef _IVI
1502         g_ui->enable_button("CM_KEY", false);
1503 #endif
1504
1505 #ifdef _MOBILE
1506         if (ise_is_guideline_popup_enable_layout()) {
1507             guideline_timer = ecore_timer_add(0.1, popup_guideline_timer_cb, NULL);
1508         }
1509 #endif
1510
1511         // Update IME size
1512         if (g_config_values.floating_mode != g_floating_mode)
1513             g_floating_mode = g_config_values.floating_mode;
1514
1515         if (g_candidate && g_candidate->get_visible())
1516             set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
1517         else
1518             set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
1519     }
1520
1521     g_keyboard_state.visible_state = TRUE;
1522
1523 #ifdef _WEARABLE
1524     int dot_num = 5;
1525     switch (_context_layout) {
1526         case ISE_LAYOUT_STYLE_PHONENUMBER:
1527         case ISE_LAYOUT_STYLE_IP:
1528         case ISE_LAYOUT_STYLE_MONTH:
1529         case ISE_LAYOUT_STYLE_NUMBERONLY:
1530         case ISE_LAYOUT_STYLE_DATETIME:
1531         case ISE_LAYOUT_STYLE_TERMINAL:
1532             dot_num = 0;
1533             break;
1534         case ISE_LAYOUT_STYLE_EMAIL:
1535         case ISE_LAYOUT_STYLE_URL:
1536             dot_num = 4;
1537             break;
1538         case ISE_LAYOUT_STYLE_PASSWORD:
1539             if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD &&
1540                 _context_layout_variation == ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD_VARIATION_NUMBERONLY)
1541                 dot_num = 0;
1542             else
1543                 dot_num = 3;
1544             break;
1545         default:
1546             dot_num = 5;
1547     }
1548
1549     if (dot_num > 0) {
1550         sclint width = 0;
1551         sclint height = 0;
1552         if (g_ui)
1553             g_ui->get_screen_resolution(&width, &height);
1554
1555         create_indicator_window(width, height);
1556         destroy_indicator_dots();
1557
1558         int focus_dot = 0;
1559         switch (g_keyboard_state.layout) {
1560             case ISE_LAYOUT_STYLE_NUMBER:
1561                 focus_dot = 1;
1562                 break;
1563             case ISE_LAYOUT_STYLE_HEX:
1564                 focus_dot = 2;
1565                 break;
1566             case ISE_LAYOUT_STYLE_EMOTICON:
1567                 focus_dot = 3;
1568                 break;
1569             case ISE_LAYOUT_STYLE_VOICE:
1570                 if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
1571                     _context_layout == ISE_LAYOUT_STYLE_URL)
1572                     focus_dot = 3;
1573                 else
1574                     focus_dot = 4;
1575                 break;
1576             default:
1577                 break;
1578         }
1579
1580         create_indicator_dots(dot_num, focus_dot);
1581         show_indicator_window();
1582     } else {
1583         hide_indicator_window();
1584     }
1585 #endif
1586
1587     if (g_setting_window_open_status) {
1588         ise_show_stt_mode(NATIVE_WINDOW_CAST(ime_get_main_window()));
1589     }
1590     g_setting_window_open_status = FALSE;
1591
1592     if (g_keyboard_state.layout == ISE_LAYOUT_STYLE_VOICE) {
1593         ise_show_stt_mode(NATIVE_WINDOW_CAST(ime_get_main_window()));
1594     }
1595 }
1596
1597 /**
1598  * Sets screen rotation
1599  */
1600 void
1601 ise_set_screen_rotation(int degree)
1602 {
1603     if (g_ui) {
1604         g_ui->set_rotation(DEGREE_TO_SCLROTATION(degree));
1605     }
1606
1607     if (g_candidate) {
1608         g_candidate->rotate(degree);
1609         if (g_softcandidate_show) {
1610             g_candidate->update(g_softcandidate_string);
1611         }
1612     }
1613 }
1614
1615 void
1616 ise_set_accessibility_state(bool state)
1617 {
1618     if (g_ui) {
1619         g_ui->enable_tts(state);
1620     }
1621 }
1622
1623 void
1624 ise_hide()
1625 {
1626     if (g_ui) {
1627         /* There's no need to update screen when hiding */
1628         g_ui->set_update_pending(TRUE);
1629         g_ui->disable_input_events(TRUE);
1630         g_ui->hide();
1631     }
1632     _language_manager.reset_language(g_config_values.selected_language.c_str());
1633
1634     _click_count = 0;
1635     delete_commit_timer();
1636     ise_destory_guideline_popup();
1637
1638     g_keyboard_state.visible_state = FALSE;
1639
1640     _reset_shift_state();
1641     _reset_multitap_state(true);
1642
1643     /* If we were in STT mode, try to reset input mode on our next show event */
1644     if (g_ui && strcmp(g_ui->get_input_mode(), "STT_3X4") == 0 ) {
1645         g_keyboard_state.need_reset = TRUE;
1646         ise_hide_stt_mode();
1647     }
1648
1649     g_input_panel_show = false;
1650     if (g_softcandidate_show && g_candidate)
1651         set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
1652 #ifdef _WEARABLE
1653     hide_indicator_window();
1654 #endif
1655 #if EXIT_ISE_ON_HIDE
1656     if (exit_timer) ecore_timer_del(exit_timer);
1657     exit_timer = ecore_timer_add(1.0, exit_timer_cb, NULL);
1658 #endif
1659 }
1660
1661 static void ise_keypad_mode_changed_cb(const char *key, void *user_data)
1662 {
1663     read_ise_keypad_mode();
1664 }
1665
1666 static void ise_enabled_languages_changed_cb(const char *key, void *user_data)
1667 {
1668     read_ise_enabled_languages();
1669 }
1670
1671 static void ise_selected_language_changed_cb(const char *key, void *user_data)
1672 {
1673     read_ise_selected_language();
1674 }
1675
1676 static void ise_autocapital_mode_changed_cb(const char *key, void *user_data)
1677 {
1678     read_ise_autocapital_mode();
1679 }
1680
1681 static void ise_autopunctuate_mode_changed_cb(const char *key, void *user_data)
1682 {
1683     read_ise_autopunctuation_mode();
1684 }
1685
1686 static void ise_sound_mode_changed_cb(const char *key, void *user_data)
1687 {
1688     read_ise_sound_mode();
1689
1690     g_ui->enable_sound(g_config_values.sound_on);
1691 }
1692
1693 static void ise_vibration_mode_changed_cb(const char *key, void *user_data)
1694 {
1695     read_ise_vibration_mode();
1696
1697     g_ui->enable_vibration(g_config_values.vibration_on);
1698 }
1699
1700 static void ise_character_preview_mode_changed_cb(const char *key, void *user_data)
1701 {
1702     read_ise_character_preview_mode();
1703
1704     g_ui->enable_magnifier(g_config_values.preview_on);
1705 }
1706
1707 static void ise_setting_guide_popup_changed_cb(const char *key, void *user_data)
1708 {
1709     read_ise_setting_guide_popup_mode();
1710 }
1711
1712 static void ise_language_guide_popup_changed_cb(const char *key, void *user_data)
1713 {
1714     read_ise_language_guide_popup_mode();
1715 }
1716
1717 static void ise_floating_mode_changed_cb(const char *key, void *user_data)
1718 {
1719     read_ise_floating_mode();
1720     g_floating_mode = g_config_values.floating_mode;
1721
1722     ime_set_floating_mode(g_floating_mode);
1723     if (g_candidate && g_floating_mode != g_candidate->get_floating_mode()) {
1724         delete_softcandidate_hide_timer();
1725         delete g_candidate;
1726         g_candidate = NULL;
1727
1728         create_softcandidate();
1729         if (g_candidate && g_candidate->get_visible()) {
1730             g_softcandidate_show = true;
1731             g_candidate->show();
1732             set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
1733             return;
1734         }
1735     }
1736     set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
1737 }
1738
1739 void
1740 ise_create()
1741 {
1742     LOGD("");
1743
1744     if (!g_ui) {
1745         g_ui = new CSCLUI;
1746     }
1747
1748     bindtextdomain(PACKAGE, LOCALEDIR);
1749     textdomain(PACKAGE);
1750
1751     /* Set scl_parser_type
1752      * default type is text xml
1753      * use command: export sclres_type="sclres_binary" to enable use binary resource
1754      * please make sure there is sclresource.bin in resource folder
1755      * Or you can use `xml2binary $resource_dir` to generate the sclresource.bin
1756      * xml2binary is in the libscl-ui-devel package
1757      */
1758     SCLParserType scl_parser_type = SCL_PARSER_TYPE_XML;
1759     char* sclres_type = getenv("sclres_type");
1760     if (sclres_type != NULL && 0 == strcmp("sclres_binary", sclres_type)) {
1761         scl_parser_type = SCL_PARSER_TYPE_BINARY_XML;
1762     } else {
1763         scl_parser_type = SCL_PARSER_TYPE_XML;
1764     }
1765
1766     if (g_ui) {
1767         if (ime_get_main_window()) {
1768             g_ise_created = true;
1769
1770             sclboolean succeeded = FALSE;
1771
1772             const sclchar *entry_path = MAIN_ENTRY_XML_PATH;
1773             int nwidth  = 0;
1774             int nheight = 0;
1775             CSCLUtils *utils = CSCLUtils::get_instance();
1776             if (utils) {
1777                 utils->get_screen_resolution(&nwidth, &nheight);
1778             }
1779             _language_manager.set_resource_file_path(entry_path);
1780             const sclchar *resource_file_path = _language_manager.get_resource_file_path();
1781
1782             if (resource_file_path) {
1783                 if (strlen(resource_file_path) > 0) {
1784                     succeeded = g_ui->init(ime_get_main_window(), scl_parser_type, resource_file_path);
1785                 }
1786             }
1787             if (!succeeded) {
1788                 g_ui->init(ime_get_main_window(), scl_parser_type, MAIN_ENTRY_XML_PATH);
1789             }
1790
1791             g_ui->set_longkey_duration(elm_config_longpress_timeout_get() * 1000);
1792
1793             /* Default ISE callback */
1794             g_ui->set_ui_event_callback(&callback);
1795
1796             /* Accumulated customized ISE callbacks, depending on the input modes */
1797             for (scluint loop = 0;loop < _language_manager.get_languages_num();loop++) {
1798                 LANGUAGE_INFO *language = _language_manager.get_language_info(loop);
1799                 if (language) {
1800                     for (scluint inner_loop = 0;inner_loop < language->input_modes.size();inner_loop++) {
1801                         INPUT_MODE_INFO &info = language->input_modes.at(inner_loop);
1802                         LOGD("Registering callback for input mode %s : %p\n", info.name.c_str(), language->callback);
1803                         g_ui->set_ui_event_callback(language->callback, info.name.c_str());
1804                     }
1805                 }
1806             }
1807
1808             read_ise_config_values();
1809             _language_manager.set_enabled_languages(g_config_values.enabled_languages);
1810             _language_manager.select_language(g_config_values.selected_language.c_str());
1811             vconf_set_bool(VCONFKEY_AUTOCAPITAL_ALLOW_BOOL, g_config_values.auto_capitalise);
1812             vconf_set_bool(VCONFKEY_AUTOPERIOD_ALLOW_BOOL, g_config_values.auto_punctuate);
1813             g_ui->enable_sound(g_config_values.sound_on);
1814             g_ui->enable_vibration(g_config_values.vibration_on);
1815             g_ui->enable_magnifier(g_config_values.preview_on);
1816 #ifdef _TV
1817             g_ui->enable_highlight_ui(TRUE);
1818 #endif
1819             g_floating_mode = g_config_values.floating_mode;
1820             ime_set_floating_mode(g_floating_mode);
1821         }
1822
1823         set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
1824
1825         bool exist = false;
1826
1827         preference_is_existing(ISE_CONFIG_KEYPAD_MODE, &exist);
1828         if (!exist)
1829             write_ise_config_values();
1830
1831         if (preference_set_changed_cb(ISE_CONFIG_KEYPAD_MODE, ise_keypad_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1832             LOGW("Faild to set ise_keypad_mode_changed_cb()");
1833         if (preference_set_changed_cb(ISE_CONFIG_ENABLED_LANGUAGES, ise_enabled_languages_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1834             LOGW("Faild to set ise_enabled_languages_changed_cb()");
1835         if (preference_set_changed_cb(ISE_CONFIG_SELECTED_LANGUAGE, ise_selected_language_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1836             LOGW("Faild to set ise_selected_language_changed_cb()");
1837         if (preference_set_changed_cb(ISE_CONFIG_AUTO_CAPITALISE, ise_autocapital_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1838             LOGW("Faild to set ise_autocapital_mode_changed_cb()");
1839         if (preference_set_changed_cb(ISE_CONFIG_AUTO_PUNCTUATE, ise_autopunctuate_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1840             LOGW("Faild to set ise_autopunctuate_mode_changed_cb()");
1841         if (preference_set_changed_cb(ISE_CONFIG_SOUND_ON, ise_sound_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1842             LOGW("Faild to set ise_sound_mode_changed_cb()");
1843         if (preference_set_changed_cb(ISE_CONFIG_VIBRATION_ON, ise_vibration_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1844             LOGW("Faild to set ise_vibration_mode_changed_cb()");
1845         if (preference_set_changed_cb(ISE_CONFIG_PREVIEW_ON, ise_character_preview_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1846             LOGW("Faild to set ise_character_preview_mode_changed_cb()");
1847         if (preference_set_changed_cb(ISE_CONFIG_FIRST_GUIDELINE_POPUP_FOR_SETTING, ise_setting_guide_popup_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1848             LOGW("Faild to set ise_setting_guide_popup_changed_cb()");
1849         if (preference_set_changed_cb(ISE_CONFIG_FIRST_GUIDELINE_POPUP_FOR_LANGUAGE_CHANGE, ise_language_guide_popup_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1850             LOGW("Faild to set ise_language_guide_popup_changed_cb()");
1851         if (preference_set_changed_cb(ISE_CONFIG_FLOATING_MODE, ise_floating_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1852             LOGW("Faild to set ise_floating_mode_changed_cb()");
1853     }
1854     init_recent_used_punctuation();
1855 }
1856
1857 void
1858 ise_destroy()
1859 {
1860     ise_hide_stt_mode();
1861
1862     if (g_ui) {
1863         LOGD("calling g_ui->fini()\n");
1864         g_ui->fini();
1865         LOGD("deleting g_ui\n");
1866         delete g_ui;
1867         g_ui = NULL;
1868     }
1869
1870     if (g_candidate) {
1871         delete g_candidate;
1872         g_candidate = NULL;
1873     }
1874
1875 #ifdef _WEARABLE
1876     destroy_indicator_window();
1877 #endif
1878
1879     /* This is necessary. If this is not called, 3rd party IME might have auto period input regardless its settings */
1880     vconf_set_bool(VCONFKEY_AUTOPERIOD_ALLOW_BOOL, false);
1881
1882 #if EXIT_ISE_ON_HIDE
1883     if (exit_timer) ecore_timer_del(exit_timer);
1884     exit_timer = NULL;
1885 #endif
1886 }
1887
1888 void
1889 ise_app_candidate_show()
1890 {
1891     LOGD("Enter\n");
1892     delete_softcandidate_hide_timer();
1893
1894     create_softcandidate();
1895
1896     g_softcandidate_show = true;
1897     if (g_candidate) {
1898         g_candidate->show();
1899         set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
1900     }
1901 }
1902
1903 void
1904 ise_app_candidate_hide()
1905 {
1906     LOGD("Enter\n");
1907
1908     if (!g_candidate || !g_softcandidate_show) {
1909         LOGD("No candidate\n");
1910         return;
1911     }
1912
1913     if (g_ic_smartreply != -1 || g_autofill_exist)
1914         return;
1915
1916     add_softcandidate_hide_timer();
1917 }
1918
1919 // when it is the time to auto_cap, the
1920 // ise_set_caps_mode is called.
1921 // -------------------------------------------------------
1922 // For example: [How are you. Fine.], the
1923 // auto-capital process is as below:
1924 // Note: "["<--this is the beginning,
1925 // "|"<--this is the cursor position
1926 // 1) call ise_set_caps_mode, auto_cap = on
1927 //    input: "H",
1928 //    result: [H|
1929 // 2) call ise_set_caps_mode, auto_cap = off
1930 //    input: "o"
1931 //    result: [Ho|
1932 // 3) input: "w are you. "
1933 //    result: [How are you. |
1934 // 4) call ise_set_caps_mode, auto_cap = on
1935 //    input: "F"
1936 //    result: [How are you. F
1937 // 5) input: "ine."
1938 //    result: [How are you. Fine.|
1939 // --------------------------------------------------------
1940 // If we want to change the auto_cap, eg,
1941 // if we want to input [How Are you.]
1942 // Note the "Are" is not use auto-capital rule.
1943 // we should use:
1944 //    ise_send_event(MVK_Shift_On, SclCoreKeyMask_Null);
1945 // when we are want to input "A"
1946 // following input still has the auto_cap rule.
1947 void
1948 ise_set_caps_mode(unsigned int mode)
1949 {
1950     LOGD("caps_mode : %d\n", mode);
1951     if (mode) {
1952         g_keyboard_state.caps_mode = TRUE;
1953     } else {
1954         g_keyboard_state.caps_mode = FALSE;
1955     }
1956     g_caps_mode_pending = false;
1957     const sclchar * cur_lang = _language_manager.get_current_language();
1958     if (cur_lang) {
1959         LANGUAGE_INFO *info = _language_manager.get_language_info(cur_lang);
1960         if (info) {
1961             if (info->accepts_caps_mode) {
1962                 /* If we are inputting multitap character, do not manipulate shift mode */
1963                 if (g_keyboard_state.prev_modifier != KEY_MODIFIER_MULTITAP_START &&
1964                     g_keyboard_state.prev_modifier != KEY_MODIFIER_MULTITAP_REPEAT) {
1965                     set_caps_mode(g_keyboard_state.caps_mode);
1966                 } else {
1967                     g_caps_mode_pending = true;
1968                     LOGD("Currently composing multitap string, skipping caps request");
1969                 }
1970             }
1971         }
1972     }
1973 }
1974
1975 void
1976 ise_update_cursor_position(int position)
1977 {
1978     LOGD("cursor position : %d\n", position);
1979     if (g_ui && g_keyboard_state.layout == ISE_LAYOUT_STYLE_URL) {
1980 #ifndef _TV
1981         if (position > 0) {
1982             g_ui->set_string_substitution("www.", ".com");
1983         } else {
1984             g_ui->unset_string_substitution("www.");
1985         }
1986 #endif
1987     }
1988 }
1989
1990 void ise_set_return_key_type(unsigned int type)
1991 {
1992     const int BUF_LEN = 256;
1993     char buf[BUF_LEN] = {0};
1994
1995     if (!g_ui) return;
1996
1997     LOGD("return key type : %d\n", type);
1998     switch (type)
1999     {
2000     case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE:
2001         snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_DONE);
2002         break;
2003     case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_GO:
2004         snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_GO);
2005         break;
2006     case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_JOIN:
2007         snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_JOIN);
2008         break;
2009     case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_LOGIN:
2010         snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_LOGIN);
2011         break;
2012     case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_NEXT:
2013         snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_NEXT);
2014         break;
2015     case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEARCH:
2016         snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_SEARCH);
2017         break;
2018     case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEND:
2019         snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_SEND);
2020         break;
2021     case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SIGNIN:
2022         snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_SIGNIN);
2023         break;
2024     case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT:
2025         break;
2026     default:
2027         LOGW("Unknown return key type : %d\n", type);
2028         type = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT;
2029         break;
2030     }
2031
2032     if (type == ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT) {
2033         g_ui->unset_private_key("Enter");
2034     } else {
2035 #ifdef _WEARABLE
2036         if (type == ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEARCH) {
2037             sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
2038                 const_cast<sclchar*>("w_sip_3x4_btn_ic_search.png"),
2039                 const_cast<sclchar*>("w_sip_3x4_btn_ic_search_p.png"),
2040                 const_cast<sclchar*>("w_sip_3x4_btn_ic_search_d.png")};
2041             g_ui->set_private_key("Enter", const_cast<sclchar*>(""), imagelabel, NULL, 0, const_cast<sclchar*>("Enter"), TRUE);
2042             return;
2043         }
2044 #endif
2045
2046         static sclchar *imagelabel[SCL_BUTTON_STATE_MAX] = {
2047             const_cast<sclchar*>(" "), const_cast<sclchar*>(" "), const_cast<sclchar*>(" ")
2048         };
2049
2050         g_ui->set_private_key("Enter", buf, imagelabel, NULL, 0, const_cast<sclchar*>("Enter"), TRUE);
2051         LOGD("return key lable : %s\n", buf);
2052     }
2053 }
2054
2055 void ise_set_return_key_disable(unsigned int disabled)
2056 {
2057     LOGD("enable : %d\n", !disabled);
2058 #ifdef _TV
2059     if (g_ui)
2060         g_ui->enable_button("Done", !disabled);
2061 #else
2062     if (g_ui)
2063         g_ui->enable_button("Enter", !disabled);
2064 #endif
2065 }
2066
2067 void ise_get_language_locale(char **locale)
2068 {
2069     LANGUAGE_INFO *info = _language_manager.get_current_language_info();
2070     if (info) {
2071         if (!(info->locale_string.empty())) {
2072             *locale = strdup(info->locale_string.c_str());
2073         }
2074     }
2075 }
2076
2077 void ise_update_table(const vector<string> &vec_str)
2078 {
2079     if (!g_candidate || !g_softcandidate_show)
2080         create_softcandidate();
2081
2082     if (g_candidate) {
2083         g_candidate->update(vec_str);
2084     }
2085 }
2086
2087 void ise_process_key_event(scim::KeyEvent& key, sclu32 &ret)
2088 {
2089     Eina_Bool back_key_pressed = EINA_FALSE;
2090     Eina_Bool back_key_released = EINA_FALSE;
2091
2092     if (key.get_key_string().compare("XF86Back") == 0) {
2093         back_key_pressed = EINA_TRUE;
2094     } else if (key.get_key_string().compare("KeyRelease+XF86Back") == 0) {
2095         back_key_released = EINA_TRUE;
2096     }
2097
2098     if (back_key_pressed || back_key_released) {
2099         if (g_popup_opened == TRUE) {
2100             if (back_key_released) {
2101                 g_ui->close_all_popups();
2102                 g_popup_opened = FALSE;
2103             }
2104             ret = 1;
2105             return;
2106         }
2107     }
2108
2109     ret = 0;
2110 #ifdef _TV
2111     if (g_candidate) {
2112         if (!g_candidate->soft_candidate_flag()) {
2113             if (g_ui) {
2114                 if (key.dev_name.compare("ime") != 0) {
2115                     ret = (sclu32)g_ui->process_key_event(key.get_key_string().c_str());
2116                 }
2117             }
2118         }
2119         if (!ret) {
2120             ret = g_candidate->soft_candidate_handle_key_event(key.get_key_string().c_str());
2121         }
2122     } else {
2123         if (g_ui) {
2124             /* Process this key event if it was not generated by ime */
2125             if (key.dev_name.compare("ime") != 0) {
2126                 ret = (sclu32)g_ui->process_key_event(key.get_key_string().c_str());
2127             }
2128         }
2129     }
2130 #else
2131     if (g_ui) {
2132         /* Process this key event if it was not generated by ime */
2133         if (key.dev_name.compare("ime") != 0) {
2134             ret = (sclu32)g_ui->process_key_event(key.get_key_string().c_str());
2135         }
2136     }
2137 #endif
2138 }
2139
2140 static void init_recent_used_punctuation()
2141 {
2142     if (g_recent_used_punctuation.empty())
2143     {
2144         g_recent_used_punctuation.push_back("#");
2145         g_recent_used_punctuation.push_back("$");
2146         g_recent_used_punctuation.push_back("%");
2147         g_recent_used_punctuation.push_back("^");
2148         g_recent_used_punctuation.push_back("&");
2149     }
2150 }
2151
2152 static void update_recent_used_punctuation(const char * key_value)
2153 {
2154     if (NULL == key_value)
2155     {
2156         return;
2157     }
2158     for (int i = 0; i < 10; ++i)
2159     {
2160         char buf[5] = {0};
2161         snprintf(buf, sizeof(buf), "%d", i);
2162         if (strcmp(key_value, buf) == 0)
2163         {
2164             return;
2165         }
2166     }
2167     string strKey = string(key_value);
2168     for (int i = 0; i < MAX_DEFAULT_PUNCTUATION; ++i)
2169     {
2170         if (0 == strKey.compare(g_default_punctuation[i].c_str()))
2171         {
2172             return;
2173         }
2174     }
2175     vector<string>::iterator iter = g_recent_used_punctuation.begin();
2176     for (; iter != g_recent_used_punctuation.end(); ++iter)
2177     {
2178         if (0 == strKey.compare(iter->c_str()))
2179         {
2180             break;
2181         }
2182     }
2183     if (iter != g_recent_used_punctuation.end())
2184     {
2185         g_recent_used_punctuation.erase(iter);
2186     }
2187     g_recent_used_punctuation.push_back(strKey);
2188     if (g_recent_used_punctuation.size() > MAX_DEFAULT_PUNCTUATION-1)
2189     {
2190         g_recent_used_punctuation.erase(g_recent_used_punctuation.begin());
2191     }
2192 }
2193
2194 static void set_ime_size(bool floating_mode, ISE_CANDIDATE_REQUEST candidate_req)
2195 {
2196     if (!g_ui)
2197         return;
2198
2199     SclSize size_portrait = g_ui->get_input_mode_size(g_ui->get_input_mode(), DISPLAYMODE_PORTRAIT);
2200     SclSize size_landscape = g_ui->get_input_mode_size(g_ui->get_input_mode(), DISPLAYMODE_LANDSCAPE);
2201
2202     if (floating_mode) {
2203         size_portrait.width *= FLOATING_SCALE_RATE;
2204         size_portrait.height *= FLOATING_SCALE_RATE;
2205         size_landscape.width *= FLOATING_SCALE_RATE;
2206         size_landscape.height *= FLOATING_SCALE_RATE;
2207         switch (candidate_req) {
2208             case ISE_CANDIDATE_REQ_NONE:
2209                 if (g_candidate && g_candidate->get_visible()) {
2210                     g_ui->set_custom_starting_coordinates(0, FLOATING_TITLE_BAR_HEIGHT + g_candidate->get_height());
2211                     size_portrait.height += g_candidate->get_height();
2212                     size_landscape.height += g_candidate->get_height();
2213                 } else {
2214                     g_ui->set_custom_starting_coordinates(0, FLOATING_TITLE_BAR_HEIGHT);
2215                 }
2216                 break;
2217             case ISE_CANDIDATE_REQ_SHOW:
2218                 g_ui->set_custom_starting_coordinates(0, FLOATING_TITLE_BAR_HEIGHT + g_candidate->get_height());
2219                 if (g_input_panel_show || g_candidate_more_view) {
2220                     size_portrait.height += g_candidate->get_height();
2221                     size_landscape.height += g_candidate->get_height();
2222                 } else {
2223                     size_portrait.height = g_candidate->get_height();
2224                     size_landscape.height = g_candidate->get_height();
2225                 }
2226                 break;
2227             case ISE_CANDIDATE_REQ_HIDE:
2228                 g_ui->set_custom_starting_coordinates(0, FLOATING_TITLE_BAR_HEIGHT);
2229                 break;
2230             default: break;
2231         }
2232
2233         if (g_ui->get_custom_scale_rate_x() != FLOATING_SCALE_RATE || g_ui->get_custom_scale_rate_y() != FLOATING_SCALE_RATE)
2234             g_ui->set_custom_scale_rate(FLOATING_SCALE_RATE, FLOATING_SCALE_RATE);
2235
2236         ime_set_size(size_portrait.width, size_portrait.height + FLOATING_TITLE_BAR_HEIGHT,
2237             size_landscape.width, size_landscape.height + FLOATING_TITLE_BAR_HEIGHT);
2238
2239 #ifdef _MOBILE
2240         ise_destroy_move_handler();
2241         int rotation = elm_win_rotation_get(NATIVE_WINDOW_CAST(ime_get_main_window()));
2242         int handler_width = (rotation == 0 || rotation == 180) ? size_portrait.width : size_landscape.width;
2243         ise_show_move_handler(handler_width, FLOATING_TITLE_BAR_HEIGHT);
2244 #endif
2245     } else {
2246         switch (candidate_req) {
2247             case ISE_CANDIDATE_REQ_NONE:
2248                 if (g_candidate && g_candidate->get_visible()) {
2249                     g_ui->set_custom_starting_coordinates(0, g_candidate->get_height());
2250                     size_portrait.height += g_candidate->get_height();
2251                     size_landscape.height += g_candidate->get_height();
2252                 } else {
2253                     g_ui->set_custom_starting_coordinates(0, 0);
2254                 }
2255                 break;
2256             case ISE_CANDIDATE_REQ_SHOW:
2257                 g_ui->set_custom_starting_coordinates(0, g_candidate->get_height());
2258                 if (g_input_panel_show || g_candidate_more_view) {
2259                     size_portrait.height += g_candidate->get_height();
2260                     size_landscape.height += g_candidate->get_height();
2261                 } else {
2262                     size_portrait.height = g_candidate->get_height();
2263                     size_landscape.height = g_candidate->get_height();
2264                 }
2265                 break;
2266             case ISE_CANDIDATE_REQ_HIDE:
2267                 g_ui->set_custom_starting_coordinates(0, 0);
2268                 break;
2269             default: break;
2270         }
2271
2272         if (g_ui->get_custom_scale_rate_x() != 1.0 || g_ui->get_custom_scale_rate_y() != 1.0)
2273             g_ui->set_custom_scale_rate(1.0, 1.0);
2274
2275         ime_set_size(size_portrait.width, size_portrait.height, size_landscape.width, size_landscape.height);
2276
2277 #ifdef _MOBILE
2278         ise_destroy_move_handler();
2279 #endif
2280     }
2281 }
2282
2283 static void ime_app_create_cb(void *user_data)
2284 {
2285 #if !(DEFER_ISE_CREATION)
2286     ise_create();
2287 #endif
2288     elm_app_name_set(PACKAGE);
2289
2290 #ifdef HAVE_CBHM
2291     cbhm_open_service(&cbhm_handle);
2292 #endif
2293 }
2294
2295 static void ime_app_exit_cb(void *user_data)
2296 {
2297     ise_hide();
2298     ise_destroy();
2299
2300 #ifdef HAVE_CBHM
2301     cbhm_close_service(cbhm_handle);
2302     cbhm_handle = NULL;
2303 #endif
2304 }
2305
2306 static void show_autofill_data(Ecore_IMF_Input_Hints input_hints)
2307 {
2308     g_autofill_exist = false;
2309     char *text = autofill_get_string(input_hints);
2310
2311     if (text) {
2312         g_autofill_string = string(text);
2313         free(text);
2314     } else {
2315         g_autofill_string = string("");
2316     }
2317     SECURE_LOGD("autofill string : %s", g_autofill_string.c_str());
2318
2319     if (g_autofill_string.length() > 0) {
2320         g_autofill_exist = true;
2321
2322         ise_app_candidate_show();
2323         update_candidate_table();
2324     }
2325 }
2326
2327 static void ime_app_show_cb(int ic, ime_context_h ime_ctx, void *user_data)
2328 {
2329     Ise_Context iseContext;
2330     bool return_key_state, prediction_allow, password_mode, caps_mode;
2331     ime_layout_variation_e layout_variation;
2332
2333     if (!g_ise_created)
2334         ise_create();
2335
2336     ime_context_get_layout(ime_ctx, &iseContext.layout);
2337
2338     ime_context_get_layout_variation(ime_ctx, &layout_variation);
2339     iseContext.layout_variation =  (int)layout_variation;
2340
2341     ime_context_get_cursor_position(ime_ctx, &iseContext.cursor_pos);
2342     ime_context_get_autocapital_type(ime_ctx, &iseContext.autocapital_type);
2343     ime_context_get_return_key_type(ime_ctx, &iseContext.return_key_type);
2344     ime_context_get_return_key_state(ime_ctx, &return_key_state);
2345
2346     ime_context_get_prediction_mode(ime_ctx, &prediction_allow);
2347     iseContext.prediction_allow = prediction_allow;
2348
2349     ime_context_get_password_mode(ime_ctx, &password_mode);
2350     iseContext.password_mode = password_mode;
2351
2352     ime_context_get_input_hint(ime_ctx, &iseContext.input_hint);
2353     ime_context_get_bidi_direction(ime_ctx, &iseContext.bidi_direction);
2354     ime_context_get_language(ime_ctx, &iseContext.language);
2355     ime_context_get_caps_mode(ime_ctx, &caps_mode);
2356     iseContext.caps_mode = caps_mode;
2357
2358     iseContext.return_key_disabled = return_key_state;
2359
2360     g_ic = ic;
2361
2362     g_autofill_hint = iseContext.input_hint & ECORE_IMF_INPUT_HINT_AUTOFILL_MASK;
2363
2364     LOGD("input hint : %x, autofill hint : %x\n", iseContext.input_hint, g_autofill_hint);
2365
2366     if (g_autofill_hint == 0) {
2367         switch (iseContext.layout) {
2368             case ECORE_IMF_INPUT_PANEL_LAYOUT_EMAIL:
2369                 g_autofill_hint = ECORE_IMF_INPUT_HINT_AUTOFILL_EMAIL_ADDRESS;
2370                 break;
2371             case ECORE_IMF_INPUT_PANEL_LAYOUT_PHONENUMBER:
2372                 g_autofill_hint = ECORE_IMF_INPUT_HINT_AUTOFILL_PHONE;
2373                 break;
2374             default:
2375                 break;
2376         }
2377     }
2378
2379     // show autofill data
2380     show_autofill_data((Ecore_IMF_Input_Hints)g_autofill_hint);
2381
2382     //g_ise_common->set_keyboard_ise_by_uuid(KEYBD_ISE_UUID);
2383
2384     /* Don't update screen until all the information is correctly set */
2385     if (g_ui)
2386         g_ui->set_update_pending(TRUE);
2387
2388     ise_reset_context(); // reset ISE
2389
2390     /*if (context.language == ECORE_IMF_INPUT_PANEL_LANG_ALPHABET) {
2391         ise_explictly_set_language(PRIMARY_LATIN_LANGUAGE_INDEX);
2392     }*/
2393
2394     _context_layout = iseContext.layout;
2395     _context_layout_variation = iseContext.layout_variation;
2396     ise_set_layout(iseContext.layout, iseContext.layout_variation);
2397
2398     ise_set_return_key_type(iseContext.return_key_type);
2399     ise_set_return_key_disable(iseContext.return_key_disabled);
2400
2401     ise_set_caps_mode(iseContext.caps_mode);
2402     ise_update_cursor_position(iseContext.cursor_pos);
2403
2404     ise_show(ic);
2405
2406     /* Now we update the whole screen */
2407     if (g_ui)
2408         g_ui->set_update_pending(FALSE);
2409 }
2410
2411 static void ime_app_hide_cb(int ic, void *user_data)
2412 {
2413     LOGD("Enter\n");
2414     ise_hide();
2415 #ifdef HAVE_CBHM
2416     g_set_mime_type = FALSE;
2417 #endif
2418     g_ic_smartreply = -1;
2419 }
2420
2421 static void ime_app_return_key_type_set_cb(Ecore_IMF_Input_Panel_Return_Key_Type type, void *user_data)
2422 {
2423     LOGD("return key type : %d\n", type);
2424     ise_set_return_key_type(type);
2425
2426     if (g_keyboard_state.visible_state)
2427         ise_show(g_keyboard_state.ic);
2428 }
2429
2430 static void ime_app_return_key_state_set_cb(bool disabled, void *user_data)
2431 {
2432     LOGD("return key disabled : %d\n", disabled);
2433     ise_set_return_key_disable(disabled);
2434 }
2435
2436 static void ime_app_input_context_reset_cb(void *user_data)
2437 {
2438     ise_reset_input_context();
2439 }
2440
2441 static void ime_app_cursor_position_updated_cb(int cursor_pos, void *user_data)
2442 {
2443     LOGD("cursor position : %d\n", cursor_pos);
2444     ise_update_cursor_position(cursor_pos);
2445 }
2446
2447 static void ime_app_language_requested_cb(void *user_data, char **lang_code)
2448 {
2449     ise_get_language_locale(lang_code);
2450 }
2451
2452 static void ime_app_surrounding_text_updated_cb(int context_id, const char *text, int cursor_pos, void *user_data)
2453 {
2454     SECURE_LOGD("surrounding text:%s, cursor=%d\n", text, cursor_pos);
2455     ime_delete_surrounding_text(-cursor_pos, strlen(text));
2456 }
2457
2458 static void ime_app_focus_in_cb(int context_id, void *user_data)
2459 {
2460     LOGD("Enter\n");
2461     ise_focus_in(context_id);
2462     if (!g_smartreply_reply_exist && g_softcandidate_show) {
2463         if (g_candidate) {
2464             ise_app_candidate_hide();
2465             g_candidate->hide();
2466         }
2467     }
2468 }
2469
2470 static void ime_app_focus_out_cb(int context_id, void *user_data)
2471 {
2472     LOGD("Enter\n");
2473     ise_focus_out(context_id);
2474     g_imdata_state = 0;
2475 #ifdef HAVE_CBHM
2476     g_set_mime_type = FALSE;
2477 #endif
2478     g_smartreply_reply_exist = false;
2479     g_smartreply_size = 0;
2480     input_smartreply_deinit();
2481     g_ic_smartreply = -1;
2482
2483     g_autofill_exist = false;
2484     g_autofill_hint = 0;
2485
2486     g_app_id = string("");
2487     g_resource_id = string("");
2488
2489     g_autofill_string = string("");
2490     g_smartreply_strings.clear();
2491     g_lookup_table_strings.clear();
2492     g_softcandidate_string.clear();
2493 }
2494
2495 static void ime_app_layout_set_cb(Ecore_IMF_Input_Panel_Layout layout, void *user_data)
2496 {
2497     LOGD("layout=%d\n", layout);
2498     /* Check if the layoutIdx is in the valid range */
2499     if ((ISE_LAYOUT)layout < ISE_LAYOUT_STYLE_MAX) {
2500         if (g_keyboard_state.layout != layout) {
2501             g_keyboard_state.need_reset = TRUE;
2502         }
2503         g_keyboard_state.layout = layout;
2504         _context_layout = layout;
2505         _context_layout_variation = 0;
2506     }
2507     if (g_keyboard_state.visible_state)
2508         ise_show(g_keyboard_state.ic);
2509 }
2510
2511 static void ime_app_rotation_degree_changed_cb(int degree, void *user_data)
2512 {
2513     ise_set_screen_rotation(degree);
2514
2515     LOGD("degree=%d\n", degree);
2516 #ifdef _MOBILE
2517     if (g_floating_mode) {
2518         int handler_width;
2519         ise_destroy_move_handler();
2520         if (degree == 0 || degree == 180) {
2521             SclSize size_portrait = g_ui->get_input_mode_size(g_ui->get_input_mode(), DISPLAYMODE_PORTRAIT);
2522             handler_width = size_portrait.width * FLOATING_SCALE_RATE;
2523         } else {
2524             SclSize size_landscape = g_ui->get_input_mode_size(g_ui->get_input_mode(), DISPLAYMODE_LANDSCAPE);
2525             handler_width = size_landscape.width * FLOATING_SCALE_RATE;
2526         }
2527         ise_show_move_handler(handler_width, FLOATING_TITLE_BAR_HEIGHT);
2528     }
2529 #endif
2530     if (is_emoticon_show()) {
2531         ise_destroy_emoticon_layout();
2532     }
2533     if (g_keyboard_state.layout == ISE_LAYOUT_STYLE_VOICE) {
2534         ise_hide_stt_mode();
2535     }
2536     if (g_keyboard_state.layout == ISE_LAYOUT_STYLE_EMOTICON) {
2537         ise_show_emoticon_layout(current_emoticon_group, degree, false, ime_get_main_window());
2538     } else if (g_ui) {
2539         const sclchar *input_mode = g_ui->get_input_mode();
2540         if (input_mode) {
2541             if (!(strcmp(input_mode, "EMOTICON_LAYOUT")))
2542                 ise_show_emoticon_layout(current_emoticon_group, degree, false, ime_get_main_window());
2543             else if (!(strcmp(input_mode, "STT_3X4")))
2544                 ise_show_stt_mode(NATIVE_WINDOW_CAST(ime_get_main_window()));
2545         }
2546     }
2547 }
2548
2549 static void ime_app_accessibility_state_changed_cb(bool state, void *user_data)
2550 {
2551     LOGD("state=%d\n", state);
2552     ise_set_accessibility_state(state);
2553 }
2554
2555 static void ime_app_imdata_set_cb(void *data, unsigned int data_length, void *user_data)
2556 {
2557     LOGD("Enter\n");
2558     g_imdata_state = 0;
2559     size_t _len = data_length;
2560     set_ise_imdata((sclchar *)data, _len);
2561 }
2562
2563 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)
2564 {
2565     scim::KeyEvent key(keycode, keymask);
2566     unsigned int ret;
2567     char *dev_name = NULL;
2568     Ecore_IMF_Device_Class dev_class;
2569     Ecore_IMF_Device_Subclass dev_subclass;
2570
2571     if (ime_device_info_get_name(dev_info, &dev_name) == IME_ERROR_NONE) {
2572         key.dev_name = dev_name;
2573     }
2574
2575     if (ime_device_info_get_class(dev_info, &dev_class) == IME_ERROR_NONE) {
2576         key.dev_class = dev_class;
2577     }
2578
2579     if (ime_device_info_get_subclass(dev_info, &dev_subclass) == IME_ERROR_NONE) {
2580         key.dev_subclass = dev_subclass;
2581     }
2582
2583     if (g_keyboard_state.visible_state)
2584         ise_process_key_event(key, ret);
2585     else
2586         ret = FALSE;
2587
2588     if (dev_name)
2589         free(dev_name);
2590
2591     return ret;
2592 }
2593
2594 static void ime_app_caps_mode_changed_cb(int mode, void *user_data)
2595 {
2596     ise_set_caps_mode(mode);
2597 }
2598
2599 static void ime_app_candidate_show_cb(int context_id, void *user_data)
2600 {
2601     ise_app_candidate_show();
2602 }
2603
2604 static void ime_app_candidate_hide_cb(int context_id, void *user_data)
2605 {
2606     ise_app_candidate_hide();
2607 }
2608
2609 static void ime_app_lookup_table_changed_cb(Eina_List *list, void *user_data)
2610 {
2611     vector<string> candidate_strings;
2612     char *candidate;
2613     void *data;
2614     Eina_List *l;
2615
2616     g_lookup_table_strings.clear();
2617
2618     if (list) {
2619         EINA_LIST_FOREACH(list, l, data) {
2620             candidate = (char *)data;
2621             if (candidate) {
2622                 g_lookup_table_strings.push_back(string(candidate));
2623                 candidate_strings.push_back(string(candidate));
2624             }
2625         }
2626     }
2627
2628     if (g_smartreply_reply_exist) {
2629         if (candidate_strings[0] == "#" && candidate_strings[1] == "$") {
2630             char *text = NULL;
2631             int cursor;
2632             ime_get_surrounding_text(0, 0, &text, &cursor);
2633             if (text)
2634                 free(text);
2635
2636             if (cursor == 0)
2637                 return;
2638         }
2639     }
2640
2641     update_candidate_table();
2642 }
2643
2644 #ifdef _WEARABLE
2645 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)
2646 {
2647     if (device_type == IME_INPUT_DEVICE_TYPE_ROTARY) {
2648         ime_input_device_rotary_direction_e direction;
2649         if (IME_ERROR_NONE == ime_input_device_rotary_get_direction(device_event, &direction)) {
2650             sclu32 new_layout = g_keyboard_state.layout;
2651             if (direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_CLOCKWISE) {
2652                 LOGD("CLOCKWISE\n");
2653                 switch (g_keyboard_state.layout) {
2654                     case ISE_LAYOUT_STYLE_NORMAL:
2655                     case ISE_LAYOUT_STYLE_EMAIL:
2656                     case ISE_LAYOUT_STYLE_URL:
2657                     case ISE_LAYOUT_STYLE_PASSWORD:
2658                         if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD &&
2659                             _context_layout_variation == ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD_VARIATION_NUMBERONLY)
2660                             ;   // PASSWORD NUMBER ONLY, do nothing
2661                         else
2662                             new_layout = ISE_LAYOUT_STYLE_NUMBER;
2663                         break;
2664                     case ISE_LAYOUT_STYLE_NUMBER:
2665                         new_layout = ISE_LAYOUT_STYLE_HEX;
2666                         break;
2667                     case ISE_LAYOUT_STYLE_HEX:
2668                         if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
2669                             _context_layout == ISE_LAYOUT_STYLE_URL)
2670                             new_layout = ISE_LAYOUT_STYLE_VOICE;
2671                         else if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD)
2672                             new_layout = _context_layout;
2673                         else
2674                             new_layout = ISE_LAYOUT_STYLE_EMOTICON;
2675                         break;
2676                     case ISE_LAYOUT_STYLE_EMOTICON:
2677                         if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
2678                             _context_layout == ISE_LAYOUT_STYLE_URL ||
2679                             _context_layout == ISE_LAYOUT_STYLE_PASSWORD)
2680                             new_layout = _context_layout;
2681                         else
2682                             new_layout = ISE_LAYOUT_STYLE_VOICE;
2683                         break;
2684                     case ISE_LAYOUT_STYLE_VOICE:
2685                         new_layout = ISE_LAYOUT_STYLE_NORMAL;
2686                         break;
2687                     default:
2688                         ;
2689                 }
2690             } else if (direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_COUNTER_CLOCKWISE) {
2691                 LOGD("COUNTER_CLOCKWISE\n");
2692                 switch (g_keyboard_state.layout) {
2693                     case ISE_LAYOUT_STYLE_NORMAL:
2694                     case ISE_LAYOUT_STYLE_EMAIL:
2695                     case ISE_LAYOUT_STYLE_URL:
2696                     case ISE_LAYOUT_STYLE_PASSWORD:
2697                         if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD &&
2698                             _context_layout_variation == ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD_VARIATION_NUMBERONLY)
2699                             ;   // PASSWORD NUMBER ONLY, do nothing
2700                         else if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD)
2701                             new_layout = ISE_LAYOUT_STYLE_HEX;
2702                         else
2703                             new_layout = ISE_LAYOUT_STYLE_VOICE;
2704                         break;
2705                     case ISE_LAYOUT_STYLE_NUMBER:
2706                         if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
2707                             _context_layout == ISE_LAYOUT_STYLE_URL ||
2708                             _context_layout == ISE_LAYOUT_STYLE_PASSWORD)
2709                             new_layout = _context_layout;
2710                         else
2711                             new_layout = ISE_LAYOUT_STYLE_NORMAL;
2712                         break;
2713                     case ISE_LAYOUT_STYLE_HEX:
2714                         new_layout = ISE_LAYOUT_STYLE_NUMBER;
2715                         break;
2716                     case ISE_LAYOUT_STYLE_EMOTICON:
2717                         new_layout = ISE_LAYOUT_STYLE_HEX;
2718                         break;
2719                     case ISE_LAYOUT_STYLE_VOICE:
2720                         if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
2721                             _context_layout == ISE_LAYOUT_STYLE_URL)
2722                             new_layout = ISE_LAYOUT_STYLE_HEX;
2723                         else
2724                             new_layout = ISE_LAYOUT_STYLE_EMOTICON;
2725                         break;
2726                     default:
2727                         ;
2728                 }
2729             }
2730             if (new_layout != g_keyboard_state.layout && new_layout < ISE_LAYOUT_STYLE_MAX) {
2731                 g_keyboard_state.need_reset = TRUE;
2732                 g_keyboard_state.layout = new_layout;
2733
2734                 if (g_keyboard_state.visible_state) {
2735                     _reset_multitap_state();
2736                     _language_manager.reset_language(g_config_values.selected_language.c_str());
2737                     ise_show(g_keyboard_state.ic);
2738                 }
2739             }
2740         }
2741     }
2742 }
2743 #endif
2744
2745 static void ime_app_prediction_hint_set_cb(const char *prediction_hint, void *user_data)
2746 {
2747     char *sender = (char *)"mms";
2748     char *caller_id = (char *)"mms";
2749     char *hint = (char *)prediction_hint;
2750
2751     if (!prediction_hint) return;
2752     SECURE_LOGD("prediction hint : %s\n", prediction_hint);
2753
2754     if (strlen(prediction_hint) > 0) {
2755         input_smartreply_init(caller_id, sender, hint);
2756         input_smartreply_set_notify(_input_smartreply_notify_cb, NULL);
2757
2758         if (input_smartreply_is_enabled()) {
2759             g_smartreply_size = 0;
2760             g_smartreply_reply_exist = false;
2761
2762             input_smartreply_get_reply_async();
2763         }
2764     }
2765 }
2766
2767 static void ime_app_mime_type_set_request_cb(const char *mime_types, void *user_data)
2768 {
2769     LOGD("mime type : %s\n", mime_types);
2770
2771 #ifdef HAVE_CBHM
2772     g_set_mime_type = TRUE;
2773     cbhm_sel_type = 0;
2774     string str(mime_types), text_key = "text/", image_key = "image/";
2775
2776     if (str.find(text_key) != string::npos)
2777         cbhm_sel_type |= CBHM_SEL_TYPE_TEXT;
2778
2779     if (str.find(image_key) != string::npos)
2780         cbhm_sel_type |= CBHM_SEL_TYPE_IMAGE;
2781
2782     LOGD("cbhm_sel_type=0x%x", cbhm_sel_type);
2783 #endif
2784 }
2785
2786 static void ime_app_prediction_hint_data_set_cb(const char *key, const char *value, void *user_data)
2787 {
2788     SECURE_LOGD("key : %s, value : %s\n", key, value);
2789
2790     if (string(key) == "appid")
2791         g_app_id = string(value ? value : "");
2792     else if (string(key) == "res_id")
2793         g_resource_id = string(value ? value : "");
2794 }
2795
2796 #ifdef __cplusplus
2797 extern "C"{
2798 #endif
2799 EXPORTED void ime_app_main(int argc, char **argv)
2800 {
2801     ime_callback_s basic_callback = {
2802         ime_app_create_cb,
2803         ime_app_exit_cb,
2804         ime_app_show_cb,
2805         ime_app_hide_cb
2806     };
2807
2808     ime_event_set_focus_in_cb(ime_app_focus_in_cb, NULL);
2809     ime_event_set_focus_out_cb(ime_app_focus_out_cb, NULL);
2810     ime_event_set_rotation_degree_changed_cb(ime_app_rotation_degree_changed_cb, NULL);
2811     ime_event_set_accessibility_state_changed_cb(ime_app_accessibility_state_changed_cb, NULL);
2812     ime_event_set_layout_set_cb(ime_app_layout_set_cb, NULL);
2813     ime_event_set_caps_mode_changed_cb(ime_app_caps_mode_changed_cb, NULL);
2814     ime_event_set_cursor_position_updated_cb(ime_app_cursor_position_updated_cb, NULL);
2815     ime_event_set_surrounding_text_updated_cb(ime_app_surrounding_text_updated_cb, NULL);
2816     ime_event_set_return_key_type_set_cb(ime_app_return_key_type_set_cb, NULL);
2817     ime_event_set_return_key_state_set_cb(ime_app_return_key_state_set_cb, NULL);
2818     ime_event_set_imdata_set_cb(ime_app_imdata_set_cb, NULL);
2819     ime_event_set_process_key_event_cb(ime_app_process_key_event_cb, NULL);
2820
2821     ime_event_set_candidate_show_cb(ime_app_candidate_show_cb, NULL);
2822     ime_event_set_candidate_hide_cb(ime_app_candidate_hide_cb, NULL);
2823     ime_event_set_lookup_table_changed_cb(ime_app_lookup_table_changed_cb, NULL);
2824
2825 #ifdef _WEARABLE
2826     ime_event_set_process_input_device_event_cb(ime_app_process_input_device_event_cb, NULL);
2827 #endif
2828
2829     ime_event_set_input_context_reset_cb(ime_app_input_context_reset_cb, NULL);
2830     ime_event_set_language_requested_cb(ime_app_language_requested_cb, NULL);
2831
2832     ime_event_set_prediction_hint_set_cb(ime_app_prediction_hint_set_cb, NULL);
2833     ime_event_set_mime_type_set_request_cb(ime_app_mime_type_set_request_cb, NULL);
2834     ime_event_set_prediction_hint_data_set_cb(ime_app_prediction_hint_data_set_cb, NULL);
2835
2836 #if DEFER_ISE_CREATION
2837     ime_set_window_creation_defer_flag(TRUE);
2838 #endif
2839
2840     ime_run(&basic_callback, NULL);
2841 }
2842 #ifdef __cplusplus
2843 }
2844 #endif
2845
2846 EXPORTED int main(int argc, char *argv[])
2847 {
2848     ime_app_main(argc, argv);
2849
2850     return 0;
2851 }