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