2 * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <sys/types.h>
25 #include <Ecore_IMF.h>
26 #include <Elementary.h>
29 #include <inputmethod.h>
30 #include <inputmethod_internal.h>
31 #include <app_control.h>
32 #include <app_preference.h>
33 #include <ode/internal-encryption.h>
34 #include <notification.h>
35 #include "clipboard.h"
40 #include "languages.h"
41 #include "candidate-factory.h"
42 #include "ise-emoticon-mode.h"
43 #include "ise-emoticon-list.h"
44 #include "ise-stt-mode.h"
45 #include "ise-stt-option.h"
46 #include "ise-language-change.h"
47 #include "ise-tutorial-mode.h"
48 #include "modeindicator.h"
49 #include "w-input-smartreply.h"
50 #include "ise-floating-mode.h"
52 #include "ise-sticker-mode.h"
53 #include "ise-nmt-mode.h"
55 #include "guidepopup.h"
57 #define EXIT_ISE_ON_HIDE 0
58 #define DEFER_ISE_CREATION 0
60 #define CANDIDATE_WINDOW_HEIGHT 84
65 static CSCLUI *g_ui = NULL;
66 CSCLUI* get_ui() { return g_ui; }
68 static int g_imdata_state = 0;
70 static sclboolean g_need_send_shift_event = FALSE;
72 extern void set_ise_imdata(const char * buf, size_t &len);
73 static void init_recent_used_punctuation();
74 static void update_recent_used_punctuation(const char *key_value);
75 static void set_ime_size(bool floating_mode, ISE_CANDIDATE_REQUEST candidate_req);
76 static sclboolean g_punctuation_popup_opened = FALSE;
77 static sclboolean g_popup_opened = FALSE;
78 static vector<string> g_recent_used_punctuation;
79 static const int MAX_DEFAULT_PUNCTUATION = 6;
80 static string g_default_punctuation[MAX_DEFAULT_PUNCTUATION] = {"-", "@", "'", "!", "?", ","};
81 static string g_current_punctuation[MAX_DEFAULT_PUNCTUATION-1] = {"RCENT1", "RCENT2", "RCENT3", "RCENT4", "RCENT5"};
82 static vector<string> g_softcandidate_string;
83 static bool g_input_panel_show = false;
84 static bool g_caps_mode_pending = false;
85 static bool g_floating_mode = false;
86 static bool g_candidate_more_view = false;
87 static bool g_ise_created = false;
89 static vector<string> g_lookup_table_strings;
90 static vector<string> g_smartreply_strings;
92 static Ecore_Timer *exit_timer = NULL;
95 #define SOFT_CANDIDATE_DELETE_TIME (100.0/1000)
96 static Ecore_Timer *g_softcandidate_hide_timer = NULL;
99 static int g_ic_smartreply = -1;
101 static KEYBOARD_STATE g_keyboard_state = {
104 ISE_LAYOUT_STYLE_NORMAL,
115 KEYBOARD_STATE* get_keyboard_state() {
116 return &g_keyboard_state;
119 #define ISE_LAYOUT_NUMBERONLY_VARIATION_MAX 4
120 /*static const sclchar *_ise_numberonly_variation_name[ISE_LAYOUT_NUMBERONLY_VARIATION_MAX] = {
121 "DEFAULT", "SIG", "DEC", "SIGDEC"
124 #define SIG_DEC_SIZE 2
125 static scluint _click_count = 0;
126 static const char *_sig_dec[SIG_DEC_SIZE] = {".", "-"};
127 static scluint _sig_dec_event[SIG_DEC_SIZE] = {'.', '-'};
128 static Ecore_Timer *_commit_timer = NULL;
130 static sclu32 _context_layout = ISE_LAYOUT_STYLE_NORMAL;
131 static sclu32 _context_layout_variation = 0;
133 static Candidate *g_candidate = NULL;
134 Candidate* get_candidate() {
138 static ISELanguageManager _language_manager;
140 class CandidateEventListener: public EventListener
143 void on_event(const EventDesc &desc)
145 CSCLUI *ui = get_ui();
146 const MultiEventDesc &multidesc = dynamic_cast<const MultiEventDesc &>(desc);
147 LANGUAGE_INFO *info = _language_manager.get_language_info(_language_manager.get_current_language());
149 unsigned int smartreply_size = input_smartreply_get_reply_num();
151 switch (multidesc.type) {
152 case MultiEventDesc::CANDIDATE_ITEM_MOUSE_DOWN:
153 if (ime_autofill_get_exist()) {
154 if (multidesc.index == 0) {
155 string autofill_string = ime_autofill_get_string();
156 ise_send_string(autofill_string.c_str());
157 } else if (multidesc.index < (int)smartreply_size + 1) {
158 ise_send_string(g_softcandidate_string[multidesc.index].c_str());
159 ise_update_table(g_smartreply_strings);
161 if (info && info->load_in_ime)
162 ime_select_candidate(multidesc.index - smartreply_size - 1);
164 engine_loader_select_candidate(multidesc.index - smartreply_size - 1);
167 if (multidesc.index < (int)smartreply_size) {
168 ise_send_string(g_softcandidate_string[multidesc.index].c_str());
169 ise_update_table(g_smartreply_strings);
172 if (info && info->load_in_ime)
173 ime_select_candidate(multidesc.index - smartreply_size);
175 engine_loader_select_candidate(multidesc.index - smartreply_size);
179 case MultiEventDesc::CANDIDATE_MORE_VIEW_SHOW:
180 // when more parts shows, click on the candidate will
181 // not affect the key click event
182 g_candidate_more_view = true;
183 if (!g_input_panel_show)
184 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
186 ui->disable_input_events(TRUE);
188 case MultiEventDesc::CANDIDATE_MORE_VIEW_HIDE:
189 g_candidate_more_view = false;
190 if (!g_input_panel_show)
191 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
193 ui->disable_input_events(FALSE);
199 static CandidateEventListener g_candidate_event_listener;
201 #define MVK_Shift_L 0xffe1
202 #define MVK_Caps_Lock 0xffe5
203 #define MVK_Shift_Off 0xffe1
204 #define MVK_Shift_On 0xffe2
205 #define MVK_Shift_Lock 0xffe6
206 #define MVK_Shift_Enable 0x9fe7
207 #define MVK_Shift_Disable 0x9fe8
208 #define MVK_space 0x020
209 #define MVK_Done 0xff0d
211 #define CM_KEY_LIST_SIZE 7
212 #define MULTITAP_TIMEOUT 3.0
213 #define USER_KEYSTRING_OPTION "OPTION"
214 #define USER_KEYSTRING_EMOTICON "EMOTICON_LAYOUT"
215 #define USER_KEYSTRING_CLIPBOARD "CLIPBOARD"
216 #define USER_KEYSTRING_VOICE "STT_3X4"
217 #define USER_KEYSTRING_FLOATING "FLOATING"
218 #define USER_KEYSTRING_STICKER "STICKER_LAYOUT"
219 #define USER_KEYSTRING_TRANSLATION "TRANSLATION_LAYOUT"
221 #define USER_VOICE_LANGUAGE "LANGUAGE"
223 static sclboolean _cm_popup_opened = FALSE;
224 static const char *_cm_key_list[CM_KEY_LIST_SIZE] = {USER_KEYSTRING_OPTION, USER_KEYSTRING_EMOTICON, USER_KEYSTRING_CLIPBOARD,
225 USER_KEYSTRING_VOICE, USER_KEYSTRING_FLOATING, USER_KEYSTRING_STICKER, USER_KEYSTRING_TRANSLATION};
226 static scluint _current_cm_key_id = 0;
229 * This callback class will receive all response events from SCL
230 * So you should perform desired tasks in this class.
232 class CUIEventCallback : public ISCLUIEventCallback
235 Ecore_Timer* word_timer = NULL;
236 static Eina_Bool _multi_tap_timer_cb(void *data)
239 ise_send_event(MVK_Done, KEY_MASK_NULL);
240 return ECORE_CALLBACK_CANCEL;
242 SCLEventReturnType on_event_key_clicked(SclUIEventDesc event_desc);
243 SCLEventReturnType on_event_drag_state_changed(SclUIEventDesc event_desc);
244 SCLEventReturnType on_event_notification(SCLUINotiType noti_type, SclNotiDesc *etc_info);
247 static CUIEventCallback callback;
249 int ise_get_imdata_state()
251 return g_imdata_state;
254 void ise_set_imdata_state(int state)
256 g_imdata_state = state;
259 static void update_candidate_table()
261 g_softcandidate_string.clear();
262 vector<string>::iterator iter;
264 g_smartreply_strings.clear();
265 input_smartreply_deinit();
266 g_ic_smartreply = -1;
268 // add autofill string
269 if (ime_autofill_get_exist())
270 g_softcandidate_string.push_back(ime_autofill_get_string());
272 // add lookup table string(s)
273 iter = g_lookup_table_strings.begin();
274 for (; iter != g_lookup_table_strings.end(); ++iter)
276 g_softcandidate_string.push_back(string(iter->c_str()));
279 ise_update_table(g_softcandidate_string);
282 static void _input_smartreply_notify_cb(void *user_data)
284 g_smartreply_strings.clear();
285 char *candidate = NULL;
287 if (input_smartreply_is_enabled()) {
288 /* Append newly added smartreply list */
289 int len = input_smartreply_get_reply_num();
291 for (int i = 0; i < len; i++) {
293 char *reply = (char *)"";
294 reply = input_smartreply_get_nth_item(i, &type);
297 SECURE_LOGD("SmartReply = [%d] %s", i, reply);
300 g_smartreply_strings.push_back(string(candidate));
305 g_ic_smartreply = g_ic;
307 ise_app_candidate_show();
308 g_softcandidate_string = g_smartreply_strings;
309 ise_update_table(g_softcandidate_string);
315 check_ic_temporary(int ic)
317 if ((ic & 0xFFFF) == 0) {
323 static void _reset_shift_state(void)
325 CSCLUI *ui = get_ui();
327 /* Reset all shift state variables */
328 SCLShiftState old_shift_state = ui->get_shift_state();
329 SCLShiftState new_shift_state = SCL_SHIFT_STATE_OFF;
330 if (old_shift_state != new_shift_state) {
331 g_need_send_shift_event = true;
332 ui->set_shift_state(new_shift_state);
334 LOGD("Shift state changed from (%d) to (%d)\n", (int)old_shift_state, (int)new_shift_state);
338 static void set_caps_mode(sclboolean mode) {
339 CSCLUI *ui = get_ui();
340 LOGD("mode : %d\n", mode);
342 if (ui->get_shift_state() != SCL_SHIFT_STATE_LOCK) {
343 ui->set_shift_state(mode ? SCL_SHIFT_STATE_ON : SCL_SHIFT_STATE_OFF);
344 ui->set_autocapital_shift_state(!mode);
346 bool load_in_ime = false;
347 const sclchar *cur_lang = _language_manager.get_current_language();
349 LANGUAGE_INFO *info = _language_manager.get_language_info(cur_lang);
351 load_in_ime = info->load_in_ime;
355 ime_send_imengine_event(mode ? MVK_Shift_On : MVK_Shift_Off, 0);
357 engine_loader_send_imengine_event(mode ? MVK_Shift_On : MVK_Shift_Off, 0);
362 static void _reset_multitap_state(bool skip_commit = false)
364 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
365 if (!keyboard_state) return;
367 LOGD("keyboard_state.prev_modifier : %d", keyboard_state->prev_modifier);
368 if (keyboard_state->prev_modifier == KEY_MODIFIER_MULTITAP_START ||
369 keyboard_state->prev_modifier == KEY_MODIFIER_MULTITAP_REPEAT) {
371 ise_send_string(keyboard_state->multitap_value.c_str());
373 ise_update_preedit_string("");
375 keyboard_state->multitap_value = "";
376 keyboard_state->prev_modifier = KEY_MODIFIER_NONE;
377 if (g_caps_mode_pending) {
378 g_caps_mode_pending = false;
379 set_caps_mode(keyboard_state->caps_mode);
383 static void ise_set_cm_private_key(scluint cm_key_id)
385 CSCLUI *ui = get_ui();
386 if (cm_key_id >= CM_KEY_LIST_SIZE || ui == NULL) {
387 LOGE("cm_key_id=%d\n", cm_key_id);
391 if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_EMOTICON) == 0) {
392 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
393 const_cast<sclchar*>("icon/54x54/icon_emotion_nor.png"),
394 const_cast<sclchar*>("icon/54x54/icon_emotion_press.png"),
395 const_cast<sclchar*>("icon/54x54/icon_emotion_dim.png")};
396 ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_EMOTICON), TRUE);
397 } else if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_OPTION) == 0) {
398 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
399 const_cast<sclchar*>("icon/54x54/icon_setting_nor.png"),
400 const_cast<sclchar*>("icon/54x54/icon_setting_press.png"),
401 const_cast<sclchar*>("icon/54x54/icon_setting_dim.png")};
402 ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_OPTION), TRUE);
403 } else if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_CLIPBOARD) == 0) {
404 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
405 const_cast<sclchar*>("icon/54x54/icon_clipboard_nor.png"),
406 const_cast<sclchar*>("icon/54x54/icon_clipboard_press.png"),
407 const_cast<sclchar*>("icon/54x54/icon_clipboard_dim.png")};
408 ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_CLIPBOARD), TRUE);
409 } else if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_VOICE) == 0) {
410 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
411 const_cast<sclchar*>("icon/54x54/icon_mic_nor.png"),
412 const_cast<sclchar*>("icon/54x54/icon_mic_press.png"),
413 const_cast<sclchar*>("icon/54x54/icon_mic_dim.png")};
414 ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_VOICE), TRUE);
415 } else if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_FLOATING) == 0) {
416 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
417 const_cast<sclchar*>("icon/54x54/icon_floating_keypad_nor.png"),
418 const_cast<sclchar*>("icon/54x54/icon_floating_keypad_press.png"),
419 const_cast<sclchar*>("icon/54x54/icon_floating_keypad_dim.png")};
420 ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_FLOATING), TRUE);
421 } else if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_TRANSLATION) == 0) {
422 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
423 const_cast<sclchar*>("icon/54x54/icon_translation_nor.png"),
424 const_cast<sclchar*>("icon/54x54/icon_translation_press.png"),
425 const_cast<sclchar*>("icon/54x54/icon_translation_dim.png")};
426 ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_TRANSLATION), TRUE);
427 } else if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_STICKER) == 0) {
428 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
429 const_cast<sclchar*>("icon/54x54/icon_sticker_nor.png"),
430 const_cast<sclchar*>("icon/54x54/icon_sticker_press.png"),
431 const_cast<sclchar*>("icon/54x54/icon_sticker_dim.png")};
432 ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_STICKER), TRUE);
436 static void ise_update_space_key(void)
438 CSCLUI *ui = get_ui();
444 scluint num = _language_manager.get_enabled_languages_num();
445 LOGD("language number: %d\n", num);
447 LANGUAGE_INFO *info = _language_manager.get_language_info(_language_manager.get_current_language());
448 if (info && info->enabled) {
450 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
451 const_cast<sclchar*>("w_sip_3x4_btn_ic_space_no_arrow.png"),
452 const_cast<sclchar*>("w_sip_3x4_btn_ic_space_no_arrow.png"),
453 const_cast<sclchar*>("w_sip_3x4_btn_ic_space_no_arrow.png")};
454 ui->set_private_key("SPACE_KEY", const_cast<sclchar*>(info->display_name.c_str()), imagelabel, NULL, 0, const_cast<sclchar*>("Space"), TRUE);
456 ui->enable_button("SPACE_ARROW_LEFT", false);
457 ui->enable_button("SPACE_ARROW_RIGHT", false);
462 ui->unset_private_key("SPACE_KEY");
464 ui->enable_button("SPACE_ARROW_LEFT", true);
465 ui->enable_button("SPACE_ARROW_RIGHT", true);
470 static scluint ise_get_cm_key_id(const sclchar *key_value)
472 for (int i = 0; i < CM_KEY_LIST_SIZE; ++i) {
473 if (0 == strcmp (key_value, _cm_key_list[i]))
479 static bool ise_is_emoticons_disabled(void)
483 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
484 if (!keyboard_state) return ret;
486 sclu32 current_layout = keyboard_state->layout;
487 LOGD("layout=%d\n", current_layout);
489 if ((current_layout == ISE_LAYOUT_STYLE_NORMAL) ||
490 (current_layout == ISE_LAYOUT_STYLE_NUMBER) ||
491 (current_layout == ISE_LAYOUT_STYLE_EMOTICON))
494 if (g_imdata_state & IMDATA_ACTION_DISABLE_EMOTICONS)
500 static Eina_Bool softcandidate_hide_timer_callback(void *data)
503 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_HIDE);
505 Candidate *candidate = get_candidate();
509 return ECORE_CALLBACK_CANCEL;
512 static void delete_softcandidate_hide_timer(void)
514 if (g_softcandidate_hide_timer) {
515 ecore_timer_del(g_softcandidate_hide_timer);
516 g_softcandidate_hide_timer = NULL;
520 static void add_softcandidate_hide_timer(void)
522 delete_softcandidate_hide_timer();
523 g_softcandidate_hide_timer = ecore_timer_add(SOFT_CANDIDATE_DELETE_TIME, softcandidate_hide_timer_callback, NULL);
526 static void create_softcandidate(void)
529 g_candidate = CandidateFactory::make_candidate(CANDIDATE_MULTILINE, ime_get_main_window());
531 g_candidate->add_event_listener(&g_candidate_event_listener);
537 * Send the given string to input framework
540 ise_send_string(const sclchar *key_value)
543 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
544 if (keyboard_state && !check_ic_temporary(keyboard_state->ic)) {
545 ic = keyboard_state->ic;
547 ime_commit_string(key_value);
548 LOGD("ic : %x, %s\n", ic, key_value);
552 * Send the preedit string to input framework
555 ise_update_preedit_string(const sclchar *str, const sclboolean underline)
558 Eina_List *attr_list = NULL;
559 ime_preedit_attribute *preedit_attr;
561 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
562 if (keyboard_state && !check_ic_temporary(keyboard_state->ic)) {
563 ic = keyboard_state->ic;
566 /* Count UTF-8 string length */
568 const sclchar *s = str;
569 while (*s) len += (*s++ & 0xc0) != 0x80;
571 preedit_attr = (ime_preedit_attribute *)calloc(1, sizeof(ime_preedit_attribute));
573 preedit_attr->start = 0;
574 preedit_attr->length = len;
575 preedit_attr->type = IME_ATTR_FONTSTYLE;
576 preedit_attr->value = IME_ATTR_FONTSTYLE_UNDERLINE;
577 attr_list = eina_list_append(attr_list, (void *)preedit_attr);
580 ime_update_preedit_string(str, attr_list);
582 ime_update_preedit_string(str, NULL);
584 LOGD("ic : %x, %s\n", ic, str);
588 * Send the given event to input framework
591 ise_send_event(sclulong key_event, sclulong key_mask)
594 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
595 if (keyboard_state && !check_ic_temporary(keyboard_state->ic)) {
596 ic = keyboard_state->ic;
598 ime_send_key_event((ime_key_code_e)key_event, IME_KEY_MASK_PRESSED, false);
599 ime_send_key_event((ime_key_code_e)key_event, IME_KEY_MASK_RELEASED, false);
601 LOGD("ic : %x, %lx\n", (unsigned int)ic, key_event);
605 * Forward the given event to input framework
608 ise_forward_key_event(sclulong key_event)
611 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
612 if (!check_ic_temporary(keyboard_state->ic)) {
613 ic = keyboard_state->ic;
615 ime_send_key_event((ime_key_code_e)key_event, IME_KEY_MASK_PRESSED, true);
616 ime_send_key_event((ime_key_code_e)key_event, IME_KEY_MASK_RELEASED, true);
618 LOGD("ic : %x, %lx\n", (unsigned int)ic, key_event);
622 * @brief Delete commit timer.
626 static void delete_commit_timer(void)
628 if (_commit_timer != NULL) {
629 ecore_timer_del(_commit_timer);
630 _commit_timer = NULL;
635 * @brief Callback function for commit timer.
637 * @param data Data to pass when it is called.
639 * @return ECORE_CALLBACK_CANCEL
641 static Eina_Bool commit_timeout(void *data)
643 if (_commit_timer != NULL) {
644 ime_hide_preedit_string();
645 ise_forward_key_event(_sig_dec_event[(_click_count-1)%SIG_DEC_SIZE]);
648 _commit_timer = NULL;
649 return ECORE_CALLBACK_CANCEL;
653 on_input_mode_changed(const sclchar *key_value, sclulong key_event, sclint key_type)
655 sclboolean ret = FALSE;
657 CSCLUI *ui = get_ui();
658 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
659 if (ui && keyboard_state) {
661 SECURE_LOGD("key_value : %s\n", key_value);
662 if (strcmp(key_value, "CUR_LANG") == 0) {
663 keyboard_state->disable_force_latin = TRUE;
664 ret = _language_manager.select_current_language();
666 if (strcmp(key_value, "NEXT_LANG") == 0) {
667 keyboard_state->disable_force_latin = TRUE;
668 ret = _language_manager.select_next_language();
672 const sclchar *cur_lang = _language_manager.get_current_language();
674 LANGUAGE_INFO *info = _language_manager.get_language_info(cur_lang);
676 if (info->accepts_caps_mode) {
677 if (info->load_in_ime)
678 ime_send_imengine_event(MVK_Shift_Enable, 0);
680 engine_loader_send_imengine_event(MVK_Shift_Enable, 0);
682 set_caps_mode(keyboard_state->caps_mode);
684 if (info->load_in_ime)
685 ime_send_imengine_event(MVK_Shift_Disable, 0);
687 engine_loader_send_imengine_event(MVK_Shift_Disable, 0);
689 ui->set_shift_state(SCL_SHIFT_STATE_OFF);
694 if (ise_sticker_is_show())
695 ise_sticker_destroy_layout();
697 if (ise_emoticon_is_show()) {
698 ise_emoticon_destroy_layout();
701 if (ise_nmt_is_show()) {
702 ise_nmt_destroy_layout();
706 if (!strcmp(key_value, USER_KEYSTRING_EMOTICON)) {
707 ise_emoticon_init_list();
709 ise_emoticon_set_current_group(EMOTICON_GROUP_1);
711 if (ise_emoticon_get_recent_list_size() == 0)
712 ise_emoticon_set_current_group(EMOTICON_GROUP_1);
714 ise_emoticon_set_current_group(EMOTICON_GROUP_RECENTLY_USED);
716 SCLRotation rotation = ui->get_rotation();
717 ise_emoticon_show_layout(ise_emoticon_get_current_group(), ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
719 else if (!strcmp(key_value, USER_KEYSTRING_TRANSLATION)) {
721 SCLRotation rotation = ui->get_rotation();
722 ise_nmt_show_layout(ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
730 SCLEventReturnType CUIEventCallback::on_event_notification(SCLUINotiType noti_type, SclNotiDesc *etc_info)
732 CSCLUI *ui = get_ui();
733 SCLEventReturnType ret = SCL_EVENT_PASS_ON;
734 LOGD("noti type: %d, g_need_send_shift_event: %d\n", noti_type, g_need_send_shift_event);
736 if (noti_type == SCL_UINOTITYPE_SHIFT_STATE_CHANGE) {
737 if (g_need_send_shift_event) {
738 const sclchar *cur_lang = _language_manager.get_current_language();
740 LANGUAGE_INFO *info = _language_manager.get_language_info(cur_lang);
741 SclNotiShiftStateChangeDesc *desc = static_cast<SclNotiShiftStateChangeDesc*>(etc_info);
743 if (info->accepts_caps_mode) {
744 LOGD("shift state: %d\n", desc->shift_state);
745 if (desc->shift_state == SCL_SHIFT_STATE_OFF) {
746 if (info->load_in_ime)
747 ime_send_imengine_event(MVK_Shift_Off, 0);
749 engine_loader_send_imengine_event(MVK_Shift_Off, 0);
750 } else if (desc->shift_state == SCL_SHIFT_STATE_ON) {
751 if (info->load_in_ime)
752 ime_send_imengine_event(MVK_Shift_On, 0);
754 engine_loader_send_imengine_event(MVK_Shift_On, 0);
755 } else if (desc->shift_state == SCL_SHIFT_STATE_LOCK) {
756 if (info->load_in_ime)
757 ime_send_imengine_event(MVK_Shift_Lock, 0);
759 engine_loader_send_imengine_event(MVK_Shift_Lock, 0);
761 ret = SCL_EVENT_PASS_ON;
765 g_need_send_shift_event = FALSE;
767 } else if (noti_type == SCL_UINOTITYPE_POPUP_OPENING) {
768 vector<string>::reverse_iterator iter = g_recent_used_punctuation.rbegin();
770 for (; iter != g_recent_used_punctuation.rend(); ++iter)
773 ui->set_string_substitution(g_current_punctuation[punc_pos].c_str(), iter->c_str());
776 SclNotiPopupOpeningDesc *openingDesc = (SclNotiPopupOpeningDesc *)etc_info;
777 if (ui && 0 == strcmp(openingDesc->input_mode, "CM_POPUP")) {
778 if (!ise_sticker_check_sticker_exists())
779 ui->enable_button("STICKER_KEY", EINA_FALSE);
781 if (nmt_is_disabled())
782 ui->enable_button("TRANSLATION_KEY", false);
784 ui->enable_button("TRANSLATION_KEY", true);
786 if (ise_is_emoticons_disabled())
787 ui->enable_button("EMOTICON_KEY", false);
789 ui->enable_button("EMOTICON_KEY", true);
791 } else if (noti_type == SCL_UINOTITYPE_POPUP_OPENED) {
792 g_popup_opened = TRUE;
793 SclNotiPopupOpenedDesc *openedDesc = (SclNotiPopupOpenedDesc *)etc_info;
794 if (0 == strcmp(openedDesc->input_mode, "PUNCTUATION_POPUP")) {
795 g_punctuation_popup_opened = TRUE;
796 } else if (0 == strcmp(openedDesc->input_mode, "CM_POPUP")) {
797 _cm_popup_opened = TRUE;
799 } else if (noti_type == SCL_UINOTITYPE_POPUP_CLOSED) {
800 g_popup_opened = FALSE;
801 SclNotiPopupClosedDesc *closedDesc = (SclNotiPopupClosedDesc *)etc_info;
802 if (closedDesc && closedDesc->input_mode) {
803 if (0 == strcmp(closedDesc->input_mode, "PUNCTUATION_POPUP")) {
804 g_punctuation_popup_opened = FALSE;
805 } else if (0 == strcmp(closedDesc->input_mode, "CM_POPUP")) {
806 _cm_popup_opened = FALSE;
809 } else if (noti_type == SCL_UINOTITYPE_INPUT_MODE_CHANGE) {
810 SclNotiInputModeChangeDesc *desc = static_cast<SclNotiInputModeChangeDesc*>(etc_info);
812 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
814 const char *input_mode = ui->get_input_mode();
816 if (strcmp(input_mode, "STT_3X4") == 0 &&
817 strcmp(desc->input_mode, "STT_3X4") != 0) {
820 if (strcmp(input_mode, "STT_3X4") != 0 &&
821 strcmp(desc->input_mode, "STT_3X4") == 0) {
822 ise_show_stt_mode(NATIVE_WINDOW_CAST(ime_get_main_window()));
831 bool get_landscape_device(int degree)
835 bool landscape_device = false;
837 CSCLUI *ui = get_ui();
838 if (!ui) return false;
840 ui->get_screen_resolution(&width, &height);
842 if (degree == 0 || degree == 180) {
844 landscape_device = true;
848 landscape_device = true;
851 return landscape_device;
854 SCLEventReturnType CUIEventCallback::on_event_drag_state_changed(SclUIEventDesc event_desc)
856 SECURE_LOGD("button %s is clicked\n", event_desc.key_value);
857 if (event_desc.event_type == EVENT_TYPE_MOVE) {
858 if (event_desc.key_event == MVK_space) {
859 SclRectangle rectangle = {0};
860 CSCLUI *ui = get_ui();
861 if (ui) ui->get_button_geometry("SPACE_KEY", &rectangle);
862 ise_show_space_flick_language_change_popup(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
864 } else if (event_desc.event_type == EVENT_TYPE_RELEASE) {
865 if (event_desc.key_event == MVK_space) {
866 ise_destroy_space_flick_language_change_popup();
870 ime_set_floating_drag_end();
871 } else if (event_desc.event_type == EVENT_TYPE_PRESS) {
872 #if defined(_MOBILE) || defined(_COMMON)
873 CONFIG_VALUES *config_values = get_config_values();
875 if (config_values && (!config_values->first_guideset) && event_desc.key_value && (strncmp(event_desc.key_value, "OPTION", strlen(event_desc.key_value)) == 0)) {
876 ise_show_help_popup(event_desc.key_event, NATIVE_WINDOW_CAST(ime_get_main_window()));//show help popup in on_event_drag_state_changed other than on_event_key_clicked for fixing help popup show delay issue
877 LOGD("setting popup show\n");
878 return SCL_EVENT_PASS_ON;
880 ise_destroy_popup_setting();//destroy popup manually in case of abnormal situation
883 if (g_floating_mode && event_desc.mouse_current_point.y <= FLOATING_TITLE_BAR_HEIGHT
884 && event_desc.mouse_current_point.y >= 0)
885 ime_set_floating_drag_start();
887 return SCL_EVENT_PASS_ON;
890 static void launch_option()
892 app_control_h app_control;
893 int ret = app_control_create(&app_control);
894 if (ret != APP_CONTROL_ERROR_NONE) {
895 LOGW("app_control_create returned %d\n", ret);
899 ret = app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
900 if (ret != APP_CONTROL_ERROR_NONE) {
901 LOGW("app_control_set_operation returned %d\n", ret);
905 ret = app_control_set_app_id(app_control, "org.tizen.ise-default-setting");
906 if (ret != APP_CONTROL_ERROR_NONE) {
907 LOGW("app_control_set_app_id returned %d\n", ret);
911 app_control_add_extra_data(app_control, "caller", "ise-default");
912 app_control_set_launch_mode(app_control, APP_CONTROL_LAUNCH_MODE_GROUP);
914 ret = app_control_send_launch_request(app_control, NULL, NULL);
915 if (ret != APP_CONTROL_ERROR_NONE) {
921 app_control_destroy(app_control);
924 SCLEventReturnType CUIEventCallback::on_event_key_clicked(SclUIEventDesc event_desc)
926 SCLEventReturnType ret = SCL_EVENT_PASS_ON;
927 if (word_timer != NULL) {
928 ecore_timer_del(word_timer);
932 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
933 if (!keyboard_state) return ret;
935 if (event_desc.key_modifier == KEY_MODIFIER_MULTITAP_START) {
936 if (!keyboard_state->multitap_value.empty()) {
937 ise_send_string(keyboard_state->multitap_value.c_str());
939 ise_update_preedit_string(event_desc.key_value);
940 keyboard_state->multitap_value = event_desc.key_value;
941 } else if (event_desc.key_modifier == KEY_MODIFIER_MULTITAP_REPEAT) {
942 ise_update_preedit_string(event_desc.key_value);
943 keyboard_state->multitap_value = event_desc.key_value;
945 _reset_multitap_state();
947 keyboard_state->prev_modifier = event_desc.key_modifier;
949 CSCLUI *ui = get_ui();
951 switch (event_desc.key_type) {
952 case KEY_TYPE_STRING: {
953 if (event_desc.key_modifier != KEY_MODIFIER_MULTITAP_START &&
954 event_desc.key_modifier != KEY_MODIFIER_MULTITAP_REPEAT) {
955 if (event_desc.key_event) {
956 ise_forward_key_event(event_desc.key_event);
958 ise_send_string(event_desc.key_value);
961 if (!g_popup_opened) {
962 const sclchar *input_mode = ui->get_input_mode();
963 if (input_mode && ((0 == strcmp(input_mode, "SYM_QTY_1")) || (0 == strcmp(input_mode, "SYM_QTY_2")))) {
964 update_recent_used_punctuation(event_desc.key_value);
966 } else if (g_punctuation_popup_opened) {
967 update_recent_used_punctuation(event_desc.key_value);
971 case KEY_TYPE_CHAR: {
972 sclboolean need_forward = FALSE;
973 // FIXME : Should decide when to forward key events
974 const sclchar *input_mode = ui->get_input_mode();
976 if (strcmp(input_mode, "SYM_QTY_1") == 0 ||
977 strcmp(input_mode, "SYM_QTY_2") == 0 ||
978 strcmp(input_mode, "PHONE_3X4") == 0 ||
979 strcmp(input_mode, "IPv6_3X4_123") == 0 ||
980 strcmp(input_mode, "IPv6_3X4_ABC") == 0 ||
981 strcmp(input_mode, "NUMONLY_3X4") == 0 ||
982 strcmp(input_mode, "NUMONLY_3X4_SIG") == 0 ||
983 strcmp(input_mode, "NUMONLY_3X4_DEC") == 0 ||
984 strcmp(input_mode, "NUMONLY_3X4_SIGDEC") == 0 ||
985 strcmp(input_mode, "DATETIME_3X4") == 0) {
989 if (input_mode && strcmp (input_mode, "NUMONLY_3X4_SIGDEC") == 0 &&
990 strcmp(event_desc.key_value, ".") == 0) {
991 ime_update_preedit_string(_sig_dec[_click_count%SIG_DEC_SIZE], NULL);
992 ime_show_preedit_string();
993 delete_commit_timer();
994 _commit_timer = ecore_timer_add(1.0, commit_timeout, NULL);
996 } else if (event_desc.key_event) {
997 commit_timeout(NULL);
999 ise_forward_key_event(event_desc.key_event);
1001 if (_cm_popup_opened) {
1002 static sclchar current_cm_symbol[2] = {'\0'};
1003 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
1004 const_cast<sclchar*>(" "),
1005 const_cast<sclchar*>(" "),
1006 const_cast<sclchar*>(" ")};
1007 if (event_desc.key_value) {
1008 current_cm_symbol[0] = event_desc.key_value[0];
1009 current_cm_symbol[1] = '\0';
1011 ui->set_private_key("CM_KEY",
1012 const_cast<sclchar*>(current_cm_symbol),
1013 imagelabel, NULL, 0,
1014 const_cast<sclchar*>(current_cm_symbol), TRUE);
1016 _cm_popup_opened = FALSE;
1017 _current_cm_key_id = -1;
1022 *change the keyboard mode of GLM from QWERTY to KEYPAD
1023 *ensure the Number keypad won't be affected
1026 if (keyboard_state->layout == ISE_LAYOUT_STYLE_NUMBER) {
1027 ime_send_key_event(IME_KEY_Print, IME_KEY_MASK_CONTROL, false);
1029 Candidate *candidate = get_candidate();
1030 if (word_timer == NULL && (!candidate || !candidate->get_visible())) {
1031 word_timer = ecore_timer_add(MULTITAP_TIMEOUT, _multi_tap_timer_cb, NULL);
1033 ime_send_key_event(IME_KEY_Select, IME_KEY_MASK_CONTROL, false);
1036 ise_send_event(event_desc.key_event, KEY_MASK_NULL);
1040 if ((strcmp(input_mode, "SYM_QTY_1") == 0) || (0 == strcmp(input_mode, "SYM_QTY_2"))) {
1041 update_recent_used_punctuation(event_desc.key_value);
1046 case KEY_TYPE_CONTROL: {
1047 commit_timeout(NULL);
1049 const char *long_shift = "LongShift";
1050 const char *caps_lock = "CapsLock";
1051 const char *delete_all = "DeleteAll";
1052 const char *hide_panel = "Hide";
1053 if (strncmp(event_desc.key_value, long_shift, strlen(long_shift)) == 0) {
1054 LOGD("shift key is longpress\n");
1055 ui->set_shift_state(SCL_SHIFT_STATE_ON);
1056 g_need_send_shift_event = TRUE;
1057 //ise_send_event (MVK_Shift_Lock, KEY_MASK_NULL);
1058 } else if (strncmp(event_desc.key_value, caps_lock, strlen(caps_lock)) == 0) {
1059 bool load_in_ime = false;
1060 const sclchar *cur_lang = _language_manager.get_current_language();
1062 LANGUAGE_INFO *info = _language_manager.get_language_info(cur_lang);
1064 load_in_ime = info->load_in_ime;
1067 if (ui->get_shift_state() != SCL_SHIFT_STATE_LOCK) {
1068 ui->set_shift_state(SCL_SHIFT_STATE_LOCK);
1070 ime_send_imengine_event(MVK_Shift_Lock, 0);
1072 engine_loader_send_imengine_event(MVK_Shift_Lock, 0);
1074 ui->set_shift_state(SCL_SHIFT_STATE_OFF);
1076 ime_send_imengine_event(MVK_Shift_Off, 0);
1078 engine_loader_send_imengine_event(MVK_Shift_Off, 0);
1080 //g_need_send_shift_event = TRUE;
1081 } else if (strncmp(event_desc.key_value, delete_all, strlen(delete_all)) == 0) {
1082 ime_delete_surrounding_text((INT_MAX / 2) * -1, INT_MAX);
1083 } else if (strncmp(event_desc.key_value, hide_panel, strlen(hide_panel)) == 0) {
1086 } else if (event_desc.key_event) {
1087 if (keyboard_state->layout == ISE_LAYOUT_STYLE_VOICE) {
1091 if (event_desc.key_event == MVK_Done) {
1093 //commit the preedit string first
1094 ise_send_event(event_desc.key_event, KEY_MASK_NULL);
1097 ise_send_event(event_desc.key_event, KEY_MASK_NULL);
1098 if (event_desc.key_event == MVK_Shift_L) {
1099 g_need_send_shift_event = TRUE;
1104 case KEY_TYPE_MODECHANGE:
1105 #if defined(_MOBILE) || defined(_COMMON)
1106 if (guide_popup_get_visible()) {//popup is showing
1110 if (strcmp(event_desc.key_value, USER_VOICE_LANGUAGE) == 0) {
1111 if (!get_setting_window_open_status()) {
1112 ise_hide_stt_mode();
1114 hide_indicator_window();
1116 create_setting_window();
1118 } else if (strcmp(event_desc.key_value, USER_KEYSTRING_VOICE) == 0) {
1119 keyboard_state->layout = ISE_LAYOUT_STYLE_VOICE;
1120 ui->set_input_mode("STT_3X4");
1122 } else if (strcmp(event_desc.key_value, USER_KEYSTRING_OPTION) == 0) {
1125 ret = SCL_EVENT_DONE;
1126 } else if (strcmp(event_desc.key_value, USER_KEYSTRING_CLIPBOARD) == 0) {
1129 ret = SCL_EVENT_DONE;
1130 } else if (strcmp(event_desc.key_value, USER_KEYSTRING_FLOATING) == 0) {
1131 CONFIG_VALUES *config_values = get_config_values();
1133 if (g_floating_mode) {
1134 if (config_values) {
1135 config_values->floating_mode = false;
1138 if (config_values) {
1139 config_values->floating_mode = true;
1142 write_ise_config_values();
1144 ret = SCL_EVENT_DONE;
1145 } else if (strcmp(event_desc.key_value, USER_KEYSTRING_STICKER) == 0) {
1146 SCLRotation rotation = ui->get_rotation();
1147 ise_sticker_show_layout(STICKER_GROUP_RECENTLY_USED, ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
1148 } else if (strcmp(event_desc.key_value, USER_KEYSTRING_TRANSLATION) == 0) {
1149 if (ise_sticker_is_show())
1150 ise_sticker_destroy_layout();
1152 SCLRotation rotation = ui->get_rotation();
1153 ise_nmt_show_layout(ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
1154 } else if (on_input_mode_changed(event_desc.key_value, event_desc.key_event, event_desc.key_type)) {
1155 ret = SCL_EVENT_DONE;
1157 if (_cm_popup_opened) {
1158 if (strcmp(event_desc.key_value, USER_KEYSTRING_EMOTICON) == 0 ||
1159 strcmp(event_desc.key_value, USER_KEYSTRING_VOICE) == 0 ||
1160 strcmp(event_desc.key_value, USER_KEYSTRING_FLOATING) == 0 ||
1161 strcmp(event_desc.key_value, USER_KEYSTRING_STICKER) == 0 ||
1162 strcmp(event_desc.key_value, USER_KEYSTRING_TRANSLATION) == 0) {
1163 scluint id = ise_get_cm_key_id(event_desc.key_value);
1164 if (id != _current_cm_key_id) {
1165 _current_cm_key_id = id;
1166 ise_set_cm_private_key(_current_cm_key_id);
1169 _cm_popup_opened = FALSE;
1171 if (strlen(event_desc.key_value) == 1) {
1172 const char allowed_chars_in_modechange[] = {
1173 ',', '?', '!', '`', '~', '@', '-'
1175 const int allowed_chars_in_modechange_num =
1176 sizeof(allowed_chars_in_modechange) / sizeof(char);
1177 for (unsigned int loop = 0;loop < sizeof(allowed_chars_in_modechange_num);loop++) {
1178 if (*(event_desc.key_value) == allowed_chars_in_modechange[loop]) {
1179 ise_send_string(event_desc.key_value);
1185 if (strcmp(event_desc.key_value, USER_KEYSTRING_OPTION) == 0) {
1186 //open_option_window(NULL, ROTATION_TO_DEGREE(ui->get_rotation()));
1189 ret = SCL_EVENT_DONE;
1190 } else if (strcmp(event_desc.key_value, USER_KEYSTRING_CLIPBOARD) == 0) {
1192 ret = SCL_EVENT_DONE;
1193 } else if (strcmp(event_desc.key_value, "Cancel") == 0) {
1194 ret = SCL_EVENT_DONE;
1195 const sclchar *input_mode = ui->get_input_mode();
1196 if (input_mode && strcmp(input_mode, "STT_3X4") == 0 ) {
1197 keyboard_state->need_reset = TRUE;
1198 voice_result_string_flush();
1199 ise_set_layout(keyboard_state->layout, keyboard_state->layout_variation);
1200 if (keyboard_state->visible_state)
1201 ise_show(keyboard_state->ic);
1204 ise_send_event(IME_KEY_Cancel, KEY_MASK_NULL);
1207 } else if (strcmp(event_desc.key_value, "Done") == 0) {
1209 ret = SCL_EVENT_DONE;
1210 ise_send_event(IME_KEY_Return, KEY_MASK_NULL);
1213 } else if (strcmp(event_desc.key_value, "Translate") == 0) {
1214 ise_nmt_translate();
1216 const sclchar *input_mode = ui->get_input_mode();
1217 if ((NULL != input_mode) && (!strcmp(input_mode, "EMOTICON_LAYOUT"))) {
1218 if (ise_emoticon_is_show()) {
1219 ise_emoticon_destroy_layout();
1222 emoticon_group_t group_id = EMOTICON_GROUP_1;
1223 if (ise_emoticon_get_current_group() < EMOTICON_GROUP_3)
1224 group_id = (emoticon_group_t)(ise_emoticon_get_current_group() + 1);
1226 ise_set_emoticon_label(group_id);
1228 emoticon_group_t group_id = ise_emoticon_get_group_id(event_desc.key_value);
1230 if ((group_id >= 0) && (group_id < MAX_EMOTICON_GROUP)) {
1231 SCLRotation rotation = ui->get_rotation();
1232 ise_emoticon_show_layout(group_id, ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
1236 if (input_mode && (!strcmp(input_mode, "STICKER_LAYOUT"))) {
1237 if (ise_sticker_is_show())
1238 ise_sticker_change_group(ise_sticker_get_group_id(event_desc.key_value));
1241 if (_cm_popup_opened) {
1242 if (strcmp(event_desc.key_value, USER_KEYSTRING_OPTION) == 0 ||
1243 strcmp(event_desc.key_value, USER_KEYSTRING_CLIPBOARD) == 0 ||
1244 strcmp(event_desc.key_value, USER_KEYSTRING_STICKER) == 0 ||
1245 strcmp(event_desc.key_value, USER_KEYSTRING_TRANSLATION) == 0) {
1246 scluint id = ise_get_cm_key_id(event_desc.key_value);
1247 if (id != _current_cm_key_id) {
1248 _current_cm_key_id = id;
1249 ise_set_cm_private_key(_current_cm_key_id);
1252 _cm_popup_opened = FALSE;
1264 ise_set_layout(sclu32 layout, sclu32 layout_variation)
1266 /* Check if the layoutIdx is in the valid range */
1267 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1268 if (layout < ISE_LAYOUT_STYLE_MAX) {
1269 if (keyboard_state->layout != layout ||
1270 keyboard_state->layout_variation != layout_variation) {
1271 keyboard_state->need_reset = TRUE;
1273 keyboard_state->layout = layout;
1274 keyboard_state->layout_variation = layout_variation;
1275 LOGD("layout:%d, variation:%d\n", keyboard_state->layout, keyboard_state->layout_variation);
1283 _reset_multitap_state(true);
1284 CONFIG_VALUES *config_values = get_config_values();
1285 if (config_values) {
1286 _language_manager.reset_language(config_values->selected_language.c_str());
1291 ise_reset_input_context()
1294 _reset_multitap_state(true);
1295 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1296 if (keyboard_state) keyboard_state->disable_force_latin = FALSE;
1297 CONFIG_VALUES *config_values = get_config_values();
1298 if (config_values) {
1299 _language_manager.reset_language(config_values->selected_language.c_str());
1304 ise_focus_in(int ic)
1306 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1307 if (!keyboard_state) return;
1309 LOGD("ic : %x , %x , g_ic : %x , %x, g_focused_ic : %x , %x\n", ic, check_ic_temporary(ic),
1310 keyboard_state->ic, check_ic_temporary(keyboard_state->ic),
1311 keyboard_state->focused_ic, check_ic_temporary(keyboard_state->focused_ic));
1312 if (check_ic_temporary(keyboard_state->ic) && !check_ic_temporary(ic)) {
1313 keyboard_state->ic = ic;
1315 keyboard_state->focused_ic = ic;
1318 static void save_autofill_data()
1323 if (ime_autofill_get_hint() == 0)
1326 ime_get_surrounding_text(-1, -1, &text, &cursor);
1327 SECURE_LOGD("surrounding text : %s\n", text);
1330 ime_autofill_save_string(text);
1336 ise_focus_out(int ic)
1338 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1339 if (keyboard_state) keyboard_state->focused_ic = 0;
1340 _reset_multitap_state(true);
1342 save_autofill_data();
1345 bool ise_is_guideline_popup_enable_layout(void)
1348 switch (_context_layout)
1350 case ISE_LAYOUT_STYLE_PHONENUMBER:
1351 case ISE_LAYOUT_STYLE_IP:
1352 case ISE_LAYOUT_STYLE_MONTH:
1353 case ISE_LAYOUT_STYLE_NUMBERONLY:
1354 case ISE_LAYOUT_STYLE_HEX:
1355 case ISE_LAYOUT_STYLE_TERMINAL:
1356 case ISE_LAYOUT_STYLE_DATETIME:
1357 case ISE_LAYOUT_STYLE_PASSWORD:
1367 #if EXIT_ISE_ON_HIDE
1368 static Eina_Bool exit_timer_cb(void *data)
1370 if (exit_timer) ecore_timer_del(exit_timer);
1373 return ECORE_CALLBACK_CANCEL;
1380 CONFIG_VALUES *config_values = get_config_values();
1381 #if EXIT_ISE_ON_HIDE
1382 if (exit_timer) ecore_timer_del(exit_timer);
1385 sclboolean reset_inputmode = FALSE;
1386 g_input_panel_show = true;
1388 CSCLUI *ui = get_ui();
1389 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1390 if (ui && keyboard_state) {
1391 read_ise_config_values();
1393 if (config_values) {
1394 _language_manager.set_enabled_languages(config_values->enabled_languages);
1396 const sclchar *cur_lang = _language_manager.get_current_language();
1399 ise_check_wearable_candidate();
1401 *Clear the personalized data
1403 if (config_values && config_values->dataclear) {
1404 ime_send_key_event(IME_KEY_Clear, IME_KEY_MASK_CONTROL, false);
1405 config_values->dataclear = FALSE;
1408 LOGD("ic : %x , %x , g_ic : %x , %x, g_focused_ic : %x , %x\n", ic, check_ic_temporary(ic),
1409 keyboard_state->ic, check_ic_temporary(keyboard_state->ic),
1410 keyboard_state->focused_ic, check_ic_temporary(keyboard_state->focused_ic));
1412 if (check_ic_temporary(ic) && !check_ic_temporary(keyboard_state->focused_ic)) {
1413 ic = keyboard_state->focused_ic;
1416 if (!check_ic_temporary(ic) && check_ic_temporary(keyboard_state->focused_ic)) {
1417 keyboard_state->focused_ic = ic;
1420 if (ic == keyboard_state->focused_ic) {
1421 switch (keyboard_state->layout)
1423 case ISE_LAYOUT_STYLE_PHONENUMBER:
1424 case ISE_LAYOUT_STYLE_IP:
1425 case ISE_LAYOUT_STYLE_MONTH:
1426 case ISE_LAYOUT_STYLE_NUMBERONLY:
1427 ime_set_imengine(DEFAULT_KEYBOARD_ISE_UUID);
1434 const char *input_mode = ui->get_input_mode();
1436 /* Reset input mode if the input context value has changed */
1437 if (ic != keyboard_state->ic) {
1438 /* Do not reset input mode if STT's setting window was opened */
1439 if (get_setting_window_open_status() && input_mode && strcmp(input_mode, "STT_3X4") == 0) {
1440 LOGD("Setting window was opened while using STT, skip resetting input mode");
1442 reset_inputmode = TRUE;
1446 keyboard_state->ic = ic;
1447 /* Reset input mode if the current language is not the selected language */
1449 if (config_values && config_values->selected_language.compare(cur_lang) != 0) {
1450 reset_inputmode = TRUE;
1454 /* No matter what, just reset the inputmode if it needs to */
1455 if (keyboard_state->need_reset) {
1456 /* Do not reset input mode if STT's setting window was opened */
1457 if (get_setting_window_open_status() && input_mode && strcmp(input_mode, "STT_3X4") == 0) {
1458 LOGD("Setting window was opened while using STT, skip resetting input mode");
1460 reset_inputmode = TRUE;
1463 keyboard_state->need_reset = FALSE;
1465 /* If the current layout requires latin language and current our language is not latin, enable the primary latin */
1466 sclboolean force_primary_latin = FALSE;
1467 LANGUAGE_INFO *info =
1468 (config_values ? _language_manager.get_language_info(config_values->selected_language.c_str()) : NULL);
1470 if (!info->is_latin_language) {
1471 if (!keyboard_state->disable_force_latin) {
1472 if (g_ise_default_values[keyboard_state->layout].force_latin) {
1473 force_primary_latin = TRUE;
1476 if (keyboard_state->prefer_latin) {
1477 force_primary_latin = TRUE;
1484 if (force_primary_latin) {
1485 /* If there is enabled latin-based language, select it */
1486 sclboolean selected = FALSE;
1487 for (scluint loop = 0;!selected && loop < _language_manager.get_languages_num();loop++) {
1488 LANGUAGE_INFO *info = _language_manager.get_language_info(loop);
1490 if (info->enabled && info->is_latin_language) {
1491 selected = _language_manager.select_language(info->name.c_str());
1492 if (selected) force_primary_latin = FALSE;
1497 _language_manager.set_language_enabled_temporarily(PRIMARY_LATIN_LANGUAGE, TRUE);
1501 if (reset_inputmode) {
1502 ise_reset_context();
1504 bool filename_layout = false;
1506 /* Turn the shift state off if we need to reset our input mode, only when auto-capitalization is not set */
1507 if (!(keyboard_state->caps_mode)) {
1508 ui->set_shift_state(SCL_SHIFT_STATE_OFF);
1510 if (keyboard_state->layout < ISE_LAYOUT_STYLE_MAX) {
1511 sclu32 layout_index = keyboard_state->layout;
1512 if (keyboard_state->layout == ISE_LAYOUT_STYLE_NUMBERONLY &&
1513 keyboard_state->layout_variation > 0 &&
1514 keyboard_state->layout_variation < ISE_LAYOUT_NUMBERONLY_VARIATION_MAX) {
1515 layout_index = ISE_LAYOUT_STYLE_NUMBERONLY_SIG + keyboard_state->layout_variation - 1;
1516 } else if (keyboard_state->layout == ISE_LAYOUT_STYLE_PASSWORD && keyboard_state->layout_variation > 0) {
1517 layout_index = ISE_LAYOUT_STYLE_PASSWD_3X4;
1520 if (keyboard_state->layout == ISE_LAYOUT_STYLE_NORMAL &&
1521 keyboard_state->layout_variation == ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL_VARIATION_FILENAME)
1522 filename_layout = true;
1524 filename_layout = false;
1526 ui->enable_button("exclamation", !filename_layout);
1527 ui->enable_button("question", !filename_layout);
1528 ui->enable_button("divide", !filename_layout);
1529 ui->enable_button("multiply", !filename_layout);
1530 ui->enable_button("colon", !filename_layout);
1531 ui->enable_button("quotation", !filename_layout);
1533 ui->enable_button("CM_KEY", !access("/home", X_OK));
1535 LOGD("new layout index : %d\n", layout_index);
1536 /* If this layout requires specific input mode, set it */
1537 if (strlen(g_ise_default_values[layout_index].input_mode) > 0) {
1538 ui->set_input_mode(g_ise_default_values[layout_index].input_mode);
1539 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
1541 if (force_primary_latin) {
1542 _language_manager.select_language(PRIMARY_LATIN_LANGUAGE, TRUE);
1543 } else if (config_values) {
1544 if (!(_language_manager.select_language(config_values->selected_language.c_str()))) {
1545 _language_manager.select_language(PRIMARY_LATIN_LANGUAGE);
1549 ui->set_cur_sublayout(g_ise_default_values[layout_index].sublayout_name);
1550 if (ise_emoticon_is_show()) {
1551 ise_emoticon_destroy_layout();
1554 if (keyboard_state->layout == ISE_LAYOUT_STYLE_EMOTICON) {
1555 ise_emoticon_init_list();
1557 ise_emoticon_set_current_group(EMOTICON_GROUP_1);
1558 ise_set_emoticon_label(1);
1560 if (ise_emoticon_get_recent_list_size() == 0)
1561 ise_emoticon_set_current_group(EMOTICON_GROUP_1);
1563 ise_emoticon_set_current_group(EMOTICON_GROUP_RECENTLY_USED);
1565 SCLRotation rotation = ui->get_rotation();
1566 ise_emoticon_show_layout(ise_emoticon_get_current_group(), ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
1569 if (ise_sticker_is_show())
1570 ise_sticker_destroy_layout();
1572 if (ise_nmt_is_show())
1573 ise_nmt_destroy_layout();
1578 if (info->accepts_caps_mode) {
1579 // FIXME this if condition means the AC is off
1580 if (keyboard_state->layout != ISE_LAYOUT_STYLE_NORMAL) {
1581 ui->set_autocapital_shift_state(TRUE);
1582 ui->set_shift_state(SCL_SHIFT_STATE_OFF);
1584 ise_send_event(MVK_Shift_Enable, KEY_MASK_NULL);
1585 // Auto Capital is supported only in normal layout
1586 if (keyboard_state->caps_mode) {
1587 ui->set_autocapital_shift_state(FALSE);
1591 ui->set_autocapital_shift_state(TRUE);
1592 ise_send_event(MVK_Shift_Disable, KEY_MASK_NULL);
1593 ui->set_shift_state(SCL_SHIFT_STATE_OFF);
1596 ui->set_autocapital_shift_state(TRUE);
1599 // Update CM key button
1600 if (_current_cm_key_id < CM_KEY_LIST_SIZE) {
1601 if (strcmp(_cm_key_list[_current_cm_key_id], USER_KEYSTRING_EMOTICON) == 0) {
1602 if (ise_is_emoticons_disabled())
1603 ise_set_cm_private_key(ise_get_cm_key_id(USER_KEYSTRING_OPTION));
1605 ise_set_cm_private_key(_current_cm_key_id);
1609 // Update space key button
1610 ise_update_space_key();
1613 ui->disable_input_events(FALSE);
1615 ui->enable_button("CM_KEY", false);
1618 #if defined(_MOBILE) || defined(_COMMON)
1619 if (ise_is_guideline_popup_enable_layout()) {
1620 if ((config_values && config_values->first_guidechange) && (_language_manager.get_enabled_languages_num() > 1)) {
1621 ise_show_help_popup(MVK_space, NATIVE_WINDOW_CAST(ime_get_main_window()));
1622 LOGD("space popup show\n");
1624 ise_destroy_popup_space();
1630 if (config_values && config_values->floating_mode != g_floating_mode)
1631 g_floating_mode = config_values->floating_mode;
1633 Candidate *candidate = get_candidate();
1634 if (candidate && candidate->get_visible())
1635 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
1637 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
1640 keyboard_state->visible_state = TRUE;
1644 switch (_context_layout) {
1645 case ISE_LAYOUT_STYLE_PHONENUMBER:
1646 case ISE_LAYOUT_STYLE_IP:
1647 case ISE_LAYOUT_STYLE_MONTH:
1648 case ISE_LAYOUT_STYLE_NUMBERONLY:
1649 case ISE_LAYOUT_STYLE_DATETIME:
1650 case ISE_LAYOUT_STYLE_TERMINAL:
1653 case ISE_LAYOUT_STYLE_EMAIL:
1654 case ISE_LAYOUT_STYLE_URL:
1657 case ISE_LAYOUT_STYLE_PASSWORD:
1658 if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD &&
1659 _context_layout_variation == ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD_VARIATION_NUMBERONLY)
1672 ui->get_screen_resolution(&width, &height);
1674 create_indicator_window(width, height);
1675 destroy_indicator_dots();
1678 switch (keyboard_state->layout) {
1679 case ISE_LAYOUT_STYLE_NUMBER:
1682 case ISE_LAYOUT_STYLE_HEX:
1685 case ISE_LAYOUT_STYLE_EMOTICON:
1688 case ISE_LAYOUT_STYLE_VOICE:
1689 if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
1690 _context_layout == ISE_LAYOUT_STYLE_URL)
1699 create_indicator_dots(dot_num, focus_dot);
1700 show_indicator_window();
1702 hide_indicator_window();
1704 if (keyboard_state->layout == ISE_LAYOUT_STYLE_NORMAL && config_values && config_values->number_tutorial_enable) {
1705 ise_show_tutorial_mode_popup(keyboard_state->layout);
1706 config_values->number_tutorial_enable = false;
1707 write_ise_config_values();
1711 if (get_setting_window_open_status()) {
1712 ise_show_stt_mode(NATIVE_WINDOW_CAST(ime_get_main_window()));
1714 set_setting_window_open_status(FALSE);
1716 if (keyboard_state->layout == ISE_LAYOUT_STYLE_VOICE) {
1717 ise_show_stt_mode(NATIVE_WINDOW_CAST(ime_get_main_window()));
1722 * Sets screen rotation
1725 ise_set_screen_rotation(int degree)
1727 CSCLUI *ui = get_ui();
1729 ui->set_rotation(DEGREE_TO_SCLROTATION(degree));
1732 Candidate *candidate = get_candidate();
1734 candidate->rotate(degree);
1735 if (candidate->get_visible()) {
1736 candidate->update(g_softcandidate_string);
1742 ise_set_accessibility_state(bool state)
1744 CSCLUI *ui = get_ui();
1746 ui->enable_tts(state);
1753 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1754 CSCLUI *ui = get_ui();
1756 /* There's no need to update screen when hiding */
1757 ui->set_update_pending(TRUE);
1758 ui->disable_input_events(TRUE);
1761 CONFIG_VALUES *config_values = get_config_values();
1762 if (config_values) {
1763 _language_manager.reset_language(config_values->selected_language.c_str());
1767 delete_commit_timer();
1768 ise_destroy_popup_space();
1769 ise_destroy_popup_setting();
1771 if (keyboard_state) keyboard_state->visible_state = FALSE;
1773 _reset_shift_state();
1774 _reset_multitap_state(true);
1776 /* If we were in STT mode, try to reset input mode on our next show event */
1777 if (ui && keyboard_state) {
1778 const char *inputmode = ui->get_input_mode();
1779 if (inputmode && strcmp(inputmode, "STT_3X4") == 0 ) {
1780 keyboard_state->need_reset = TRUE;
1781 ise_hide_stt_mode();
1785 g_input_panel_show = false;
1786 Candidate *candidate = get_candidate();
1787 if (candidate && candidate->get_visible())
1788 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
1790 hide_indicator_window();
1791 if (check_is_tutorial_show()) {
1792 ise_destroy_tutorial_mode_popup();
1795 #if EXIT_ISE_ON_HIDE
1796 if (exit_timer) ecore_timer_del(exit_timer);
1797 exit_timer = ecore_timer_add(1.0, exit_timer_cb, NULL);
1801 static void ise_keypad_mode_changed_cb(const char *key, void *user_data)
1803 read_ise_keypad_mode();
1806 static void ise_enabled_languages_changed_cb(const char *key, void *user_data)
1808 read_ise_enabled_languages();
1811 static void ise_selected_language_changed_cb(const char *key, void *user_data)
1813 read_ise_selected_language();
1816 static void ise_autocapital_mode_changed_cb(const char *key, void *user_data)
1818 read_ise_autocapital_mode();
1821 static void ise_autopunctuate_mode_changed_cb(const char *key, void *user_data)
1823 read_ise_autopunctuation_mode();
1826 static void ise_sound_mode_changed_cb(const char *key, void *user_data)
1828 read_ise_sound_mode();
1830 CONFIG_VALUES *config_values = get_config_values();
1831 CSCLUI *ui = get_ui();
1832 if (config_values && ui) {
1833 ui->enable_sound(config_values->sound_on);
1837 static void ise_vibration_mode_changed_cb(const char *key, void *user_data)
1839 read_ise_vibration_mode();
1841 CONFIG_VALUES *config_values = get_config_values();
1842 CSCLUI *ui = get_ui();
1843 if (config_values && ui) {
1844 ui->enable_vibration(config_values->vibration_on);
1848 static void ise_character_preview_mode_changed_cb(const char *key, void *user_data)
1850 read_ise_character_preview_mode();
1852 CONFIG_VALUES *config_values = get_config_values();
1853 CSCLUI *ui = get_ui();
1854 if (config_values && ui) {
1855 ui->enable_magnifier(config_values->preview_on);
1859 static void ise_setting_guide_popup_changed_cb(const char *key, void *user_data)
1861 read_ise_setting_guide_popup_mode();
1864 static void ise_language_guide_popup_changed_cb(const char *key, void *user_data)
1866 read_ise_language_guide_popup_mode();
1869 static void ise_floating_mode_changed_cb(const char *key, void *user_data)
1871 read_ise_floating_mode();
1872 CONFIG_VALUES *config_values = get_config_values();
1873 if (config_values) {
1874 g_floating_mode = config_values->floating_mode;
1877 ime_set_floating_mode(g_floating_mode);
1878 if (g_candidate && g_floating_mode != g_candidate->get_floating_mode()) {
1879 delete_softcandidate_hide_timer();
1883 create_softcandidate();
1884 if (g_candidate && g_candidate->get_visible()) {
1885 g_candidate->show();
1886 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
1890 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
1893 static void register_preference_changed_callback(void)
1895 if (preference_set_changed_cb(ISE_CONFIG_KEYPAD_MODE, ise_keypad_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1896 LOGW("Failed to set ise_keypad_mode_changed_cb()");
1898 if (preference_set_changed_cb(ISE_CONFIG_ENABLED_LANGUAGES, ise_enabled_languages_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1899 LOGW("Failed to set ise_enabled_languages_changed_cb()");
1901 if (preference_set_changed_cb(ISE_CONFIG_SELECTED_LANGUAGE, ise_selected_language_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1902 LOGW("Failed to set ise_selected_language_changed_cb()");
1904 if (preference_set_changed_cb(ISE_CONFIG_AUTO_CAPITALISE, ise_autocapital_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1905 LOGW("Failed to set ise_autocapital_mode_changed_cb()");
1907 if (preference_set_changed_cb(ISE_CONFIG_AUTO_PUNCTUATE, ise_autopunctuate_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1908 LOGW("Failed to set ise_autopunctuate_mode_changed_cb()");
1910 if (preference_set_changed_cb(ISE_CONFIG_SOUND_ON, ise_sound_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1911 LOGW("Failed to set ise_sound_mode_changed_cb()");
1913 if (preference_set_changed_cb(ISE_CONFIG_VIBRATION_ON, ise_vibration_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1914 LOGW("Failed to set ise_vibration_mode_changed_cb()");
1916 if (preference_set_changed_cb(ISE_CONFIG_PREVIEW_ON, ise_character_preview_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1917 LOGW("Failed to set ise_character_preview_mode_changed_cb()");
1919 if (preference_set_changed_cb(ISE_CONFIG_FIRST_GUIDELINE_POPUP_FOR_SETTING, ise_setting_guide_popup_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1920 LOGW("Failed to set ise_setting_guide_popup_changed_cb()");
1922 if (preference_set_changed_cb(ISE_CONFIG_FIRST_GUIDELINE_POPUP_FOR_LANGUAGE_CHANGE, ise_language_guide_popup_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1923 LOGW("Failed to set ise_language_guide_popup_changed_cb()");
1925 if (preference_set_changed_cb(ISE_CONFIG_FLOATING_MODE, ise_floating_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1926 LOGW("Failed to set ise_floating_mode_changed_cb()");
1929 static void ise_mount_changed_cb(void *user_data)
1931 register_preference_changed_callback();
1939 CONFIG_VALUES *config_values = get_config_values();
1945 bindtextdomain(PACKAGE, LOCALEDIR);
1946 textdomain(PACKAGE);
1948 /* Set scl_parser_type
1949 * default type is text xml
1950 * use command: export sclres_type="sclres_binary" to enable use binary resource
1951 * please make sure there is sclresource.bin in resource folder
1952 * Or you can use `xml2binary $resource_dir` to generate the sclresource.bin
1953 * xml2binary is in the libscl-ui-devel package
1955 SCLParserType scl_parser_type = SCL_PARSER_TYPE_XML;
1956 char* sclres_type = getenv("sclres_type");
1957 if (sclres_type != NULL && 0 == strcmp("sclres_binary", sclres_type)) {
1958 scl_parser_type = SCL_PARSER_TYPE_BINARY_XML;
1960 scl_parser_type = SCL_PARSER_TYPE_XML;
1964 if (ime_get_main_window()) {
1965 g_ise_created = true;
1967 sclboolean succeeded = FALSE;
1969 const sclchar *entry_path = MAIN_ENTRY_XML_PATH;
1972 CSCLUtils *utils = CSCLUtils::get_instance();
1974 utils->get_screen_resolution(&nwidth, &nheight);
1976 _language_manager.set_resource_file_path(entry_path);
1977 const sclchar *resource_file_path = _language_manager.get_resource_file_path();
1979 if (resource_file_path) {
1980 if (strlen(resource_file_path) > 0) {
1981 succeeded = g_ui->init(ime_get_main_window(), scl_parser_type, resource_file_path);
1985 g_ui->init(ime_get_main_window(), scl_parser_type, MAIN_ENTRY_XML_PATH);
1988 g_ui->set_longkey_duration(elm_config_longpress_timeout_get() * 1000);
1990 /* Default ISE callback */
1991 g_ui->set_ui_event_callback(&callback);
1993 /* Accumulated customized ISE callbacks, depending on the input modes */
1994 for (scluint loop = 0;loop < _language_manager.get_languages_num();loop++) {
1995 LANGUAGE_INFO *language = _language_manager.get_language_info(loop);
1997 for (scluint inner_loop = 0;inner_loop < language->input_modes.size();inner_loop++) {
1998 INPUT_MODE_INFO &info = language->input_modes.at(inner_loop);
1999 LOGD("Registering callback for input mode %s : %p\n", info.name.c_str(), language->callback);
2000 g_ui->set_ui_event_callback(language->callback, info.name.c_str());
2005 read_ise_config_values();
2006 if (access(ISE_CONFIG_FILE_PATH, F_OK) == 0 && !config_values->init_flag)
2007 read_ise_config_file();
2009 if (config_values) {
2010 _language_manager.set_enabled_languages(config_values->enabled_languages);
2011 _language_manager.select_language(config_values->selected_language.c_str());
2012 vconf_set_bool(VCONFKEY_AUTOCAPITAL_ALLOW_BOOL, config_values->auto_capitalise);
2013 vconf_set_bool(VCONFKEY_AUTOPERIOD_ALLOW_BOOL, config_values->auto_punctuate);
2014 g_ui->enable_sound(config_values->sound_on);
2015 g_ui->enable_vibration(config_values->vibration_on);
2016 g_ui->enable_magnifier(config_values->preview_on);
2017 g_floating_mode = config_values->floating_mode;
2020 g_ui->enable_highlight_ui(TRUE);
2022 ime_set_floating_mode(g_floating_mode);
2025 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
2029 preference_is_existing(ISE_CONFIG_KEYPAD_MODE, &exist);
2031 write_ise_config_values();
2034 if (ode_internal_encryption_get_state(&state) == ODE_ERROR_NONE) {
2035 if (state == ODE_STATE_ENCRYPTED) {
2036 if (ode_internal_encryption_set_mount_event_cb(ise_mount_changed_cb, NULL) != ODE_ERROR_NONE)
2037 LOGW("Failed to set mount_event_cb()");
2038 } else if (state == ODE_STATE_UNENCRYPTED) {
2039 register_preference_changed_callback();
2042 LOGW("Failed to get encryption_state");
2045 init_recent_used_punctuation();
2051 ise_hide_stt_mode();
2053 CSCLUI *ui = get_ui();
2055 LOGD("calling ui->fini()\n");
2057 LOGD("deleting ui\n");
2068 destroy_indicator_window();
2071 /* This is necessary. If this is not called, 3rd party IME might have auto period input regardless its settings */
2072 vconf_set_bool(VCONFKEY_AUTOPERIOD_ALLOW_BOOL, false);
2074 #if EXIT_ISE_ON_HIDE
2075 if (exit_timer) ecore_timer_del(exit_timer);
2081 ise_app_candidate_show()
2087 if (!g_candidate->get_visible())
2091 delete_softcandidate_hide_timer();
2093 create_softcandidate();
2095 Candidate *candidate = get_candidate();
2098 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
2103 ise_app_candidate_hide()
2107 Candidate *candidate = get_candidate();
2108 if (!candidate || !candidate->get_visible()) {
2109 LOGD("No candidate\n");
2113 if (g_ic_smartreply != -1 || ime_autofill_get_exist())
2116 add_softcandidate_hide_timer();
2120 void ise_check_wearable_candidate()
2122 CONFIG_VALUES *config_values = get_config_values();
2123 if (!config_values) return;
2125 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2126 if (!keyboard_state) return;
2128 if (!config_values->prediction_on) {
2129 ise_app_candidate_hide();
2130 } else if (keyboard_state->layout == ISE_LAYOUT_STYLE_PHONENUMBER ||
2131 keyboard_state->layout == ISE_LAYOUT_STYLE_VOICE ||
2132 keyboard_state->layout == ISE_LAYOUT_STYLE_IP ||
2133 keyboard_state->layout == ISE_LAYOUT_STYLE_MONTH ||
2134 keyboard_state->layout == ISE_LAYOUT_STYLE_NUMBERONLY ||
2135 keyboard_state->layout == ISE_LAYOUT_STYLE_PASSWD_3X4||
2136 keyboard_state->layout == ISE_LAYOUT_STYLE_PASSWORD) {
2137 ise_app_candidate_hide();
2139 ise_app_candidate_show();
2143 void ise_set_emoticon_label(int group_id)
2145 const int BUF_LEN = 16;
2146 char buf[BUF_LEN] = {0};
2147 snprintf(buf, BUF_LEN, "%d/3", group_id);
2148 CSCLUI *ui = get_ui();
2149 if (ui) ui->set_private_key("EMOTICON_GROUP_ID", buf, NULL, NULL, 0, const_cast<sclchar*>("EMOTICON_GROUP_NEXT"), TRUE);
2153 // when it is the time to auto_cap, the
2154 // ise_set_caps_mode is called.
2155 // -------------------------------------------------------
2156 // For example: [How are you. Fine.], the
2157 // auto-capital process is as below:
2158 // Note: "["<--this is the beginning,
2159 // "|"<--this is the cursor position
2160 // 1) call ise_set_caps_mode, auto_cap = on
2163 // 2) call ise_set_caps_mode, auto_cap = off
2166 // 3) input: "w are you. "
2167 // result: [How are you. |
2168 // 4) call ise_set_caps_mode, auto_cap = on
2170 // result: [How are you. F
2172 // result: [How are you. Fine.|
2173 // --------------------------------------------------------
2174 // If we want to change the auto_cap, eg,
2175 // if we want to input [How Are you.]
2176 // Note the "Are" is not use auto-capital rule.
2178 // ise_send_event(MVK_Shift_On, SclCoreKeyMask_Null);
2179 // when we are want to input "A"
2180 // following input still has the auto_cap rule.
2182 ise_set_caps_mode(unsigned int mode)
2184 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2185 if (!keyboard_state) return;
2187 LOGD("caps_mode : %d\n", mode);
2189 keyboard_state->caps_mode = TRUE;
2191 keyboard_state->caps_mode = FALSE;
2193 g_caps_mode_pending = false;
2194 const sclchar *cur_lang = _language_manager.get_current_language();
2196 LANGUAGE_INFO *info = _language_manager.get_language_info(cur_lang);
2198 if (info->accepts_caps_mode) {
2199 /* If we are inputting multitap character, do not manipulate shift mode */
2200 if (keyboard_state->prev_modifier != KEY_MODIFIER_MULTITAP_START &&
2201 keyboard_state->prev_modifier != KEY_MODIFIER_MULTITAP_REPEAT) {
2202 set_caps_mode(keyboard_state->caps_mode);
2204 g_caps_mode_pending = true;
2205 LOGD("Currently composing multitap string, skipping caps request");
2213 ise_update_cursor_position(int position)
2215 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2216 if (!keyboard_state) return;
2218 LOGD("cursor position : %d\n", position);
2219 CSCLUI *ui = get_ui();
2220 if (ui && keyboard_state->layout == ISE_LAYOUT_STYLE_URL) {
2223 ui->set_string_substitution("www.", ".com");
2225 ui->unset_string_substitution("www.");
2231 void ise_set_return_key_type(unsigned int type)
2233 const int BUF_LEN = 256;
2234 char buf[BUF_LEN] = {0};
2236 CSCLUI *ui = get_ui();
2239 LOGD("return key type : %d\n", type);
2242 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE:
2243 snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_DONE);
2245 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_GO:
2246 snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_GO);
2248 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_JOIN:
2249 snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_JOIN);
2251 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_LOGIN:
2252 snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_LOGIN);
2254 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_NEXT:
2255 snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_NEXT);
2257 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEARCH:
2258 snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_SEARCH);
2260 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEND:
2261 snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_SEND);
2263 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SIGNIN:
2264 snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_SIGNIN);
2266 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT:
2269 LOGW("Unknown return key type : %d\n", type);
2270 type = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT;
2274 if (type == ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT) {
2275 ui->unset_private_key("Enter");
2277 ui->unset_private_key("Done");
2281 if (type == ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEARCH) {
2282 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
2283 const_cast<sclchar*>("w_sip_3x4_btn_ic_search.png"),
2284 const_cast<sclchar*>("w_sip_3x4_btn_ic_search_p.png"),
2285 const_cast<sclchar*>("w_sip_3x4_btn_ic_search_d.png")};
2286 ui->set_private_key("Enter", const_cast<sclchar*>(""), imagelabel, NULL, 0, const_cast<sclchar*>("Enter"), TRUE);
2292 ui->set_private_key("Done", buf, NULL, NULL, 0, const_cast<sclchar*>("Done"), TRUE);
2294 static sclchar *imagelabel[SCL_BUTTON_STATE_MAX] = {
2295 const_cast<sclchar*>(" "), const_cast<sclchar*>(" "), const_cast<sclchar*>(" ")
2298 ui->set_private_key("Enter", buf, imagelabel, NULL, 0, const_cast<sclchar*>("Enter"), TRUE);
2300 LOGD("return key label : %s\n", buf);
2304 void ise_set_return_key_disable(unsigned int disabled)
2306 CSCLUI *ui = get_ui();
2307 LOGD("enable : %d\n", !disabled);
2310 ui->enable_button("Done", !disabled);
2313 ui->enable_button("Enter", !disabled);
2317 void ise_get_language_locale(char **locale)
2319 LANGUAGE_INFO *info = _language_manager.get_current_language_info();
2321 if (!(info->locale_string.empty())) {
2322 *locale = strdup(info->locale_string.c_str());
2327 void ise_update_table(const vector<string> &vec_str)
2329 Candidate *candidate = get_candidate();
2330 if (!candidate || !candidate->get_visible()) {
2331 create_softcandidate();
2334 candidate = get_candidate();
2336 candidate->update(vec_str);
2340 void ise_process_key_event(scim::KeyEvent& key, sclu32 &ret)
2342 Eina_Bool back_key_pressed = EINA_FALSE;
2343 Eina_Bool back_key_released = EINA_FALSE;
2345 if (key.get_key_string().compare("XF86Back") == 0) {
2346 back_key_pressed = EINA_TRUE;
2347 } else if (key.get_key_string().compare("KeyRelease+XF86Back") == 0) {
2348 back_key_released = EINA_TRUE;
2351 if (back_key_pressed || back_key_released) {
2352 if (g_popup_opened == TRUE) {
2353 if (back_key_released) {
2354 CSCLUI *ui = get_ui();
2355 if (ui) ui->close_all_popups();
2363 CSCLUI *ui = get_ui();
2365 Candidate *candidate = get_candidate();
2367 if (!candidate->soft_candidate_flag()) {
2369 if (key.dev_name.compare("ime") != 0) {
2370 ret = (sclu32)ui->process_key_event(key.get_key_string().c_str());
2375 ret = candidate->soft_candidate_handle_key_event(key.get_key_string().c_str());
2379 /* Process this key event if it was not generated by ime */
2380 if (key.dev_name.compare("ime") != 0) {
2381 ret = (sclu32)ui->process_key_event(key.get_key_string().c_str());
2387 /* Process this key event if it was not generated by ime */
2388 if (key.dev_name.compare("ime") != 0) {
2389 ret = (sclu32)ui->process_key_event(key.get_key_string().c_str());
2395 static void init_recent_used_punctuation()
2397 if (g_recent_used_punctuation.empty())
2399 g_recent_used_punctuation.push_back("#");
2400 g_recent_used_punctuation.push_back("$");
2401 g_recent_used_punctuation.push_back("%");
2402 g_recent_used_punctuation.push_back("^");
2403 g_recent_used_punctuation.push_back("&");
2407 static void update_recent_used_punctuation(const char * key_value)
2409 if (NULL == key_value)
2413 for (int i = 0; i < 10; ++i)
2416 snprintf(buf, sizeof(buf), "%d", i);
2417 if (strcmp(key_value, buf) == 0)
2422 string strKey = string(key_value);
2423 for (int i = 0; i < MAX_DEFAULT_PUNCTUATION; ++i)
2425 if (0 == strKey.compare(g_default_punctuation[i].c_str()))
2430 vector<string>::iterator iter = g_recent_used_punctuation.begin();
2431 for (; iter != g_recent_used_punctuation.end(); ++iter)
2433 if (0 == strKey.compare(iter->c_str()))
2438 if (iter != g_recent_used_punctuation.end())
2440 g_recent_used_punctuation.erase(iter);
2442 g_recent_used_punctuation.push_back(strKey);
2443 if (g_recent_used_punctuation.size() > MAX_DEFAULT_PUNCTUATION-1)
2445 g_recent_used_punctuation.erase(g_recent_used_punctuation.begin());
2449 static void set_ime_size(bool floating_mode, ISE_CANDIDATE_REQUEST candidate_req)
2451 CSCLUI *ui = get_ui();
2455 Candidate *candidate = get_candidate();
2457 const char *input_mode = ui->get_input_mode();
2461 SclSize size_portrait = ui->get_input_mode_size(input_mode, DISPLAYMODE_PORTRAIT);
2462 SclSize size_landscape = ui->get_input_mode_size(input_mode, DISPLAYMODE_LANDSCAPE);
2464 if (floating_mode) {
2465 size_portrait.width *= FLOATING_SCALE_RATE;
2466 size_portrait.height *= FLOATING_SCALE_RATE;
2467 size_landscape.width *= FLOATING_SCALE_RATE;
2468 size_landscape.height *= FLOATING_SCALE_RATE;
2469 switch (candidate_req) {
2470 case ISE_CANDIDATE_REQ_NONE:
2471 if (candidate && candidate->get_visible()) {
2472 ui->set_custom_starting_coordinates(0, FLOATING_TITLE_BAR_HEIGHT + candidate->get_height());
2473 size_portrait.height += candidate->get_height();
2474 size_landscape.height += candidate->get_height();
2476 ui->set_custom_starting_coordinates(0, FLOATING_TITLE_BAR_HEIGHT);
2479 case ISE_CANDIDATE_REQ_SHOW:
2481 ui->set_custom_starting_coordinates(0, FLOATING_TITLE_BAR_HEIGHT + candidate->get_height());
2482 if (g_input_panel_show || g_candidate_more_view) {
2483 size_portrait.height += candidate->get_height();
2484 size_landscape.height += candidate->get_height();
2486 size_portrait.height = candidate->get_height();
2487 size_landscape.height = candidate->get_height();
2491 case ISE_CANDIDATE_REQ_HIDE:
2492 ui->set_custom_starting_coordinates(0, FLOATING_TITLE_BAR_HEIGHT);
2497 if (ui->get_custom_scale_rate_x() != FLOATING_SCALE_RATE || ui->get_custom_scale_rate_y() != FLOATING_SCALE_RATE)
2498 ui->set_custom_scale_rate(FLOATING_SCALE_RATE, FLOATING_SCALE_RATE);
2500 ime_set_size(size_portrait.width, size_portrait.height + FLOATING_TITLE_BAR_HEIGHT,
2501 size_landscape.width, size_landscape.height + FLOATING_TITLE_BAR_HEIGHT);
2503 #if defined(_MOBILE) || defined(_COMMON)
2504 ise_destroy_move_handler();
2505 int rotation = elm_win_rotation_get(NATIVE_WINDOW_CAST(ime_get_main_window()));
2506 int handler_width = (rotation == 0 || rotation == 180) ? size_portrait.width : size_landscape.width;
2507 ise_show_move_handler(handler_width, FLOATING_TITLE_BAR_HEIGHT);
2510 switch (candidate_req) {
2511 case ISE_CANDIDATE_REQ_NONE:
2512 if (candidate && candidate->get_visible()) {
2513 ui->set_custom_starting_coordinates(0, candidate->get_height());
2514 size_portrait.height += candidate->get_height();
2515 size_landscape.height += candidate->get_height();
2517 ui->set_custom_starting_coordinates(0, 0);
2520 case ISE_CANDIDATE_REQ_SHOW:
2522 ui->set_custom_starting_coordinates(0, candidate->get_height());
2523 if (g_input_panel_show || g_candidate_more_view) {
2524 size_portrait.height += candidate->get_height();
2525 size_landscape.height += candidate->get_height();
2527 size_portrait.height = candidate->get_height();
2528 size_landscape.height = candidate->get_height();
2532 case ISE_CANDIDATE_REQ_HIDE:
2533 ui->set_custom_starting_coordinates(0, 0);
2538 if (ui->get_custom_scale_rate_x() != 1.0 || ui->get_custom_scale_rate_y() != 1.0)
2539 ui->set_custom_scale_rate(1.0, 1.0);
2541 ime_set_size(size_portrait.width, size_portrait.height, size_landscape.width, size_landscape.height);
2543 #if defined(_MOBILE) || defined(_COMMON)
2544 ise_destroy_move_handler();
2549 static void ime_app_create_cb(void *user_data)
2551 if (!engine_loader_dbus_init(NULL))
2552 LOGE("Failed to initialize dbus");
2554 #if !(DEFER_ISE_CREATION)
2557 elm_app_name_set(PACKAGE);
2559 char *elm_scale = getenv("ELM_SCALE");
2560 LOGD("ELM_SCALE : %s", elm_scale);
2563 elm_app_base_scale_set(atof(elm_scale));
2570 static void ime_app_exit_cb(void *user_data)
2575 if (!engine_loader_dbus_shutdown())
2576 LOGE("Failed to finalize dbus");
2578 clipboard_shutdown();
2583 static void show_autofill_data()
2585 ime_autofill_set_exist(false);
2586 string autofill_string = ime_autofill_get_string();
2588 SECURE_LOGD("autofill string : %s", autofill_string.c_str());
2590 if (!autofill_string.empty()) {
2591 ime_autofill_set_exist(true);
2593 ise_app_candidate_show();
2594 update_candidate_table();
2598 static void ime_app_show_cb(int ic, ime_context_h ime_ctx, void *user_data)
2600 Ise_Context iseContext;
2601 bool return_key_state, prediction_allow, password_mode, caps_mode;
2602 ime_layout_variation_e layout_variation;
2607 ime_context_get_layout(ime_ctx, &iseContext.layout);
2609 ime_context_get_layout_variation(ime_ctx, &layout_variation);
2610 iseContext.layout_variation = (int)layout_variation;
2612 ime_context_get_cursor_position(ime_ctx, &iseContext.cursor_pos);
2613 ime_context_get_autocapital_type(ime_ctx, &iseContext.autocapital_type);
2614 ime_context_get_return_key_type(ime_ctx, &iseContext.return_key_type);
2615 ime_context_get_return_key_state(ime_ctx, &return_key_state);
2617 ime_context_get_prediction_mode(ime_ctx, &prediction_allow);
2618 iseContext.prediction_allow = prediction_allow;
2620 ime_context_get_password_mode(ime_ctx, &password_mode);
2621 iseContext.password_mode = password_mode;
2623 ime_context_get_input_hint(ime_ctx, &iseContext.input_hint);
2624 ime_context_get_bidi_direction(ime_ctx, &iseContext.bidi_direction);
2625 ime_context_get_language(ime_ctx, &iseContext.language);
2626 ime_context_get_caps_mode(ime_ctx, &caps_mode);
2627 iseContext.caps_mode = caps_mode;
2629 iseContext.return_key_disabled = return_key_state;
2631 engine_loader_set_input_hint((uint32_t)iseContext.input_hint);
2632 engine_loader_update_bidi_direction((uint32_t)iseContext.bidi_direction);
2636 ime_autofill_set_hint(iseContext.input_hint & ECORE_IMF_INPUT_HINT_AUTOFILL_MASK);
2638 LOGD("input hint : %x, autofill hint : %x\n", iseContext.input_hint, ime_autofill_get_hint());
2640 // show autofill data
2641 show_autofill_data();
2643 //g_ise_common->set_keyboard_ise_by_uuid(KEYBD_ISE_UUID);
2645 /* Don't update screen until all the information is correctly set */
2646 CSCLUI *ui = get_ui();
2648 ui->set_update_pending(TRUE);
2650 ise_reset_context(); // reset ISE
2652 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2654 if (iseContext.language == ECORE_IMF_INPUT_PANEL_LANG_ALPHABET) {
2655 LOGD("prefer latin");
2657 keyboard_state->prefer_latin = TRUE;
2660 LOGD("prefer automatic");
2662 keyboard_state->prefer_latin = FALSE;
2665 _context_layout = iseContext.layout;
2666 _context_layout_variation = iseContext.layout_variation;
2667 ise_set_layout(iseContext.layout, iseContext.layout_variation);
2669 ise_set_return_key_type(iseContext.return_key_type);
2670 ise_set_return_key_disable(iseContext.return_key_disabled);
2672 ise_set_caps_mode(iseContext.caps_mode);
2673 ise_update_cursor_position(iseContext.cursor_pos);
2677 /* Now we update the whole screen */
2679 ui->set_update_pending(FALSE);
2682 static void ime_app_hide_cb(int ic, void *user_data)
2687 clipboard_set_mime_type(false);
2689 g_ic_smartreply = -1;
2692 static void ime_app_return_key_type_set_cb(Ecore_IMF_Input_Panel_Return_Key_Type type, void *user_data)
2694 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2695 if (!keyboard_state) return;
2697 LOGD("return key type : %d\n", type);
2698 ise_set_return_key_type(type);
2700 if (keyboard_state->visible_state)
2701 ise_show(keyboard_state->ic);
2704 static void ime_app_return_key_state_set_cb(bool disabled, void *user_data)
2706 LOGD("return key disabled : %d\n", disabled);
2707 ise_set_return_key_disable(disabled);
2710 static void ime_app_language_set_cb(Ecore_IMF_Input_Panel_Lang language, void *user_data)
2712 LOGD("language : %d\n", language);
2714 // if (language == ECORE_IMF_INPUT_PANEL_LANG_ALPHABET) {
2715 // ise_explictly_set_language(PRIMARY_LATIN_LANGUAGE_INDEX);
2719 static void ime_app_input_context_reset_cb(void *user_data)
2721 ise_reset_input_context();
2722 engine_loader_reset_input_context();
2725 static void ime_app_cursor_position_updated_cb(int cursor_pos, void *user_data)
2727 LOGD("cursor position : %d\n", cursor_pos);
2728 ise_update_cursor_position(cursor_pos);
2729 engine_loader_update_cursor_position(cursor_pos);
2732 static void ime_app_language_requested_cb(void *user_data, char **lang_code)
2734 ise_get_language_locale(lang_code);
2737 static void ime_app_surrounding_text_updated_cb(int context_id, const char *text, int cursor_pos, void *user_data)
2739 SECURE_LOGD("surrounding text:%s, cursor=%d\n", text, cursor_pos);
2740 ime_delete_surrounding_text(-cursor_pos, strlen(text));
2743 static void ime_app_focus_in_cb(int context_id, void *user_data)
2746 ise_focus_in(context_id);
2747 Candidate *candidate = get_candidate();
2748 if (input_smartreply_get_reply_num() == 0) {
2749 if (candidate && candidate->get_visible()) {
2750 ise_app_candidate_hide();
2755 engine_loader_focus_in();
2758 static void ime_app_focus_out_cb(int context_id, void *user_data)
2761 ise_focus_out(context_id);
2763 clipboard_set_mime_type(false);
2764 input_smartreply_deinit();
2765 g_ic_smartreply = -1;
2767 ime_autofill_set_exist(false);
2768 ime_autofill_set_hint(0);
2769 ime_autofill_set_app_id("");
2770 ime_autofill_set_resource_id("");
2772 g_smartreply_strings.clear();
2773 g_lookup_table_strings.clear();
2774 g_softcandidate_string.clear();
2776 engine_loader_focus_out();
2779 static void ime_app_layout_set_cb(Ecore_IMF_Input_Panel_Layout layout, void *user_data)
2781 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2782 if (!keyboard_state) return;
2784 LOGD("layout=%d\n", layout);
2785 /* Check if the layoutIdx is in the valid range */
2786 if (static_cast<int>(layout) < static_cast<int>(ISE_LAYOUT_STYLE_MAX)) {
2787 if (keyboard_state->layout != layout) {
2788 keyboard_state->need_reset = TRUE;
2790 keyboard_state->layout = layout;
2791 _context_layout = layout;
2792 _context_layout_variation = 0;
2794 if (keyboard_state->visible_state)
2795 ise_show(keyboard_state->ic);
2797 engine_loader_set_layout(static_cast<uint32_t>(layout));
2800 static void ime_app_input_hint_set_cb(Ecore_IMF_Input_Hints input_hint, void *user_data)
2802 LOGD("input hint=%u\n", input_hint);
2805 static void ime_app_rotation_degree_changed_cb(int degree, void *user_data)
2807 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2808 if (!keyboard_state) return;
2810 CSCLUI *ui = get_ui();
2811 ise_set_screen_rotation(degree);
2813 LOGD("degree=%d\n", degree);
2814 #if defined(_MOBILE) || defined(_COMMON)
2815 if (ui && g_floating_mode) {
2817 ise_destroy_move_handler();
2818 if (degree == 0 || degree == 180) {
2819 SclSize size_portrait = ui->get_input_mode_size(ui->get_input_mode(), DISPLAYMODE_PORTRAIT);
2820 handler_width = size_portrait.width * FLOATING_SCALE_RATE;
2822 SclSize size_landscape = ui->get_input_mode_size(ui->get_input_mode(), DISPLAYMODE_LANDSCAPE);
2823 handler_width = size_landscape.width * FLOATING_SCALE_RATE;
2825 ise_show_move_handler(handler_width, FLOATING_TITLE_BAR_HEIGHT);
2828 if (ise_emoticon_is_show()) {
2829 ise_emoticon_destroy_layout();
2831 if (keyboard_state->layout == ISE_LAYOUT_STYLE_VOICE) {
2832 ise_hide_stt_mode();
2834 if (keyboard_state->layout == ISE_LAYOUT_STYLE_EMOTICON) {
2835 ise_emoticon_show_layout(ise_emoticon_get_current_group(), degree, false, ime_get_main_window());
2837 const sclchar *input_mode = ui->get_input_mode();
2839 if (!(strcmp(input_mode, "EMOTICON_LAYOUT")))
2840 ise_emoticon_show_layout(ise_emoticon_get_current_group(), degree, false, ime_get_main_window());
2841 else if (!(strcmp(input_mode, "STT_3X4")))
2842 ise_show_stt_mode(NATIVE_WINDOW_CAST(ime_get_main_window()));
2847 static void ime_app_accessibility_state_changed_cb(bool state, void *user_data)
2849 LOGD("state=%d\n", state);
2850 ise_set_accessibility_state(state);
2853 static void ime_app_imdata_set_cb(void *data, unsigned int data_length, void *user_data)
2857 size_t _len = data_length;
2858 set_ise_imdata((sclchar *)data, _len);
2859 engine_loader_set_imdata((const char*)data, (uint32_t)data_length);
2862 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)
2864 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2865 if (!keyboard_state) return FALSE;
2867 scim::KeyEvent key(keycode, keymask);
2869 char *dev_name = NULL;
2870 Ecore_IMF_Device_Class dev_class;
2871 Ecore_IMF_Device_Subclass dev_subclass;
2873 if (ime_device_info_get_name(dev_info, &dev_name) == IME_ERROR_NONE) {
2874 key.dev_name = dev_name;
2877 if (ime_device_info_get_class(dev_info, &dev_class) == IME_ERROR_NONE) {
2878 key.dev_class = dev_class;
2881 if (ime_device_info_get_subclass(dev_info, &dev_subclass) == IME_ERROR_NONE) {
2882 key.dev_subclass = dev_subclass;
2885 if (keyboard_state->visible_state) {
2886 ise_process_key_event(key, ret);
2888 if (key.code == IME_KEY_space && (key.mask & IME_KEY_MASK_SHIFT)) {
2889 if (key.mask & IME_KEY_MASK_RELEASED) {
2890 if (_language_manager.select_next_language()) {
2891 LANGUAGE_INFO *info = _language_manager.get_language_info(_language_manager.get_current_language());
2893 notification_status_message_post(info->display_name.c_str());
2896 LOGE("Failed to change language");
2912 static void ime_app_process_key_event_with_imengine_cb(scim::KeyEvent &key, uint32_t serial, void *user_data)
2914 LANGUAGE_INFO *info = _language_manager.get_language_info(_language_manager.get_current_language());
2915 if (info && info->need_surrounding_text)
2916 engine_loader_process_key_event(key, serial, true);
2918 engine_loader_process_key_event(key, serial, false);
2921 static void ime_app_caps_mode_changed_cb(int mode, void *user_data)
2923 ise_set_caps_mode(mode);
2926 static void ime_app_candidate_show_cb(int context_id, void *user_data)
2929 ise_check_wearable_candidate();
2931 ise_app_candidate_show();
2935 static void ime_app_candidate_hide_cb(int context_id, void *user_data)
2938 ise_check_wearable_candidate();
2940 ise_app_candidate_hide();
2944 static void ime_app_lookup_table_changed_cb(Eina_List *list, void *user_data)
2946 vector<string> candidate_strings;
2951 g_lookup_table_strings.clear();
2954 EINA_LIST_FOREACH(list, l, data) {
2955 candidate = (char *)data;
2957 g_lookup_table_strings.push_back(string(candidate));
2958 candidate_strings.push_back(string(candidate));
2963 if (input_smartreply_get_reply_num() > 0) {
2964 if (candidate_strings[0] == "#" && candidate_strings[1] == "$") {
2967 ime_get_surrounding_text(0, 0, &text, &cursor);
2976 update_candidate_table();
2980 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)
2982 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2983 if (!keyboard_state) return;
2985 if (device_type == IME_INPUT_DEVICE_TYPE_ROTARY) {
2986 ime_input_device_rotary_direction_e direction;
2987 if (IME_ERROR_NONE == ime_input_device_rotary_get_direction(device_event, &direction)) {
2988 sclu32 new_layout = keyboard_state->layout;
2989 if (direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_CLOCKWISE) {
2990 LOGD("CLOCKWISE\n");
2991 switch (keyboard_state->layout) {
2992 case ISE_LAYOUT_STYLE_NORMAL:
2993 case ISE_LAYOUT_STYLE_EMAIL:
2994 case ISE_LAYOUT_STYLE_URL:
2995 case ISE_LAYOUT_STYLE_PASSWORD:
2996 if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD &&
2997 _context_layout_variation == ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD_VARIATION_NUMBERONLY)
2998 ; // PASSWORD NUMBER ONLY, do nothing
3000 new_layout = ISE_LAYOUT_STYLE_NUMBER;
3002 case ISE_LAYOUT_STYLE_NUMBER:
3003 new_layout = ISE_LAYOUT_STYLE_HEX;
3005 case ISE_LAYOUT_STYLE_HEX:
3006 if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
3007 _context_layout == ISE_LAYOUT_STYLE_URL)
3008 new_layout = ISE_LAYOUT_STYLE_VOICE;
3009 else if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD)
3010 new_layout = _context_layout;
3012 new_layout = ISE_LAYOUT_STYLE_EMOTICON;
3014 case ISE_LAYOUT_STYLE_EMOTICON:
3015 if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
3016 _context_layout == ISE_LAYOUT_STYLE_URL ||
3017 _context_layout == ISE_LAYOUT_STYLE_PASSWORD)
3018 new_layout = _context_layout;
3020 new_layout = ISE_LAYOUT_STYLE_VOICE;
3022 case ISE_LAYOUT_STYLE_VOICE:
3023 new_layout = ISE_LAYOUT_STYLE_NORMAL;
3028 } else if (direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_COUNTER_CLOCKWISE) {
3029 LOGD("COUNTER_CLOCKWISE\n");
3030 switch (keyboard_state->layout) {
3031 case ISE_LAYOUT_STYLE_NORMAL:
3032 case ISE_LAYOUT_STYLE_EMAIL:
3033 case ISE_LAYOUT_STYLE_URL:
3034 case ISE_LAYOUT_STYLE_PASSWORD:
3035 if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD &&
3036 _context_layout_variation == ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD_VARIATION_NUMBERONLY)
3037 ; // PASSWORD NUMBER ONLY, do nothing
3038 else if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD)
3039 new_layout = ISE_LAYOUT_STYLE_HEX;
3041 new_layout = ISE_LAYOUT_STYLE_VOICE;
3043 case ISE_LAYOUT_STYLE_NUMBER:
3044 if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
3045 _context_layout == ISE_LAYOUT_STYLE_URL ||
3046 _context_layout == ISE_LAYOUT_STYLE_PASSWORD)
3047 new_layout = _context_layout;
3049 new_layout = ISE_LAYOUT_STYLE_NORMAL;
3051 case ISE_LAYOUT_STYLE_HEX:
3052 new_layout = ISE_LAYOUT_STYLE_NUMBER;
3054 case ISE_LAYOUT_STYLE_EMOTICON:
3055 new_layout = ISE_LAYOUT_STYLE_HEX;
3057 case ISE_LAYOUT_STYLE_VOICE:
3058 if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
3059 _context_layout == ISE_LAYOUT_STYLE_URL)
3060 new_layout = ISE_LAYOUT_STYLE_HEX;
3062 new_layout = ISE_LAYOUT_STYLE_EMOTICON;
3069 CONFIG_VALUES *config_values = get_config_values();
3070 if (check_is_tutorial_show() && config_values) {
3071 read_ise_config_values();
3072 if ((direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_COUNTER_CLOCKWISE && !config_values->number_tutorial_enable && !config_values->symbol_tutorial_enable) ||
3073 (direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_CLOCKWISE && config_values->symbol_tutorial_enable)) {
3074 new_layout = keyboard_state->layout;
3075 } else if (direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_COUNTER_CLOCKWISE && config_values->symbol_tutorial_enable) {
3076 ise_destroy_tutorial_mode_popup();
3077 config_values->symbol_tutorial_enable = false;
3078 write_ise_config_values();
3079 } else if (direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_CLOCKWISE && !config_values->number_tutorial_enable) {
3080 ise_destroy_tutorial_mode_popup();
3081 new_layout = ISE_LAYOUT_STYLE_NUMBER;
3082 if (!config_values->symbol_tutorial_enable) {
3083 ise_show_tutorial_mode_popup(new_layout);
3084 config_values->symbol_tutorial_enable = true;
3085 write_ise_config_values();
3090 if (new_layout != keyboard_state->layout && new_layout < ISE_LAYOUT_STYLE_MAX) {
3091 keyboard_state->need_reset = TRUE;
3092 keyboard_state->layout = new_layout;
3094 if (keyboard_state->visible_state) {
3095 _reset_multitap_state();
3096 if (config_values) {
3097 _language_manager.reset_language(config_values->selected_language.c_str());
3099 ise_show(keyboard_state->ic);
3107 static void ime_app_prediction_hint_set_cb(const char *prediction_hint, void *user_data)
3109 char *sender = (char *)"mms";
3110 char *caller_id = (char *)"mms";
3111 char *hint = (char *)prediction_hint;
3113 if (!prediction_hint) return;
3114 SECURE_LOGD("prediction hint : %s\n", prediction_hint);
3116 if (strlen(prediction_hint) > 0) {
3117 input_smartreply_init(caller_id, sender, hint);
3118 input_smartreply_set_notify(_input_smartreply_notify_cb, NULL);
3120 if (input_smartreply_is_enabled()) {
3121 input_smartreply_get_reply_async();
3126 static void ime_app_mime_type_set_request_cb(const char *mime_types, void *user_data)
3128 LOGD("mime type : %s\n", mime_types);
3130 clipboard_set_mime_type(true);
3131 clipboard_init_sel_type();
3133 string str(mime_types), text_key = "text/", image_key = "image/";
3135 if (str.find(text_key) != string::npos)
3136 clipboard_add_sel_type(CLIPBOARD_SEL_TEXT);
3138 if (str.find(image_key) != string::npos)
3139 clipboard_add_sel_type(CLIPBOARD_SEL_IMAGE);
3142 static void ime_app_prediction_hint_data_set_cb(const char *key, const char *value, void *user_data)
3144 SECURE_LOGD("key : %s, value : %s\n", key, value);
3146 if (string(key) == "appid")
3147 ime_autofill_set_app_id(value);
3148 else if (string(key) == "res_id")
3149 ime_autofill_set_resource_id(value);
3152 static void ime_app_autocapital_type_set_cb(uint32_t type, void *user_data)
3154 LOGD("autocapital type : %u\n", type);
3155 engine_loader_set_autocapital_type(type);
3158 static void ime_app_prediction_allow_set_cb(uint32_t prediction_allow, void *user_data)
3160 LOGD("prediction allow : %u\n", prediction_allow);
3161 engine_loader_set_prediction_allow(prediction_allow);
3164 static void ime_app_trigger_property_set_cb(const char *property, void *user_data)
3166 LOGD("trigger property : %s\n", property);
3167 engine_loader_trigger_property(property);
3170 static void ime_app_candidate_more_window_show_cb(void *user_data)
3173 engine_loader_show_candidate_more_window();
3176 static void ime_app_candidate_more_window_hide_cb(void *user_data)
3179 engine_loader_hide_candidate_more_window();
3182 static void ime_app_aux_select_cb(uint32_t item, void *user_data)
3184 LOGD("aux select : %u\n", item);
3185 engine_loader_select_aux(item);
3188 static void ime_app_candidate_select_cb(uint32_t item, void *user_data)
3190 LOGD("candidate select : %u\n", item);
3191 engine_loader_select_candidate(item);
3194 static void ime_app_candidate_table_page_up_cb(void *user_data)
3197 engine_loader_candidate_table_page_up();
3200 static void ime_app_candidate_table_page_down_cb(void *user_data)
3203 engine_loader_candidate_table_page_down();
3206 static void ime_app_candidate_table_page_size_chaned_cb(uint32_t size, void *user_data)
3208 LOGD("candidate page size : %u\n", size);
3209 engine_loader_change_candidate_page_size(size);
3212 static void ime_app_candidate_item_layout_set_cb(vector<uint32_t> item, void *user_data)
3214 LOGD("item layout size : %zu", item.size());
3215 engine_loader_set_candidate_item_layout(item);
3218 static void ime_app_displayed_candidate_number_chaned_cb(uint32_t page_num, void *user_data)
3220 LOGD("candidate number changed : %u\n", page_num);
3221 engine_loader_change_candidate_number(page_num);
3224 static void ime_app_candidate_item_long_pressed_cb(uint32_t index, void *user_data)
3226 LOGD("candidate item : %u\n", index);
3227 engine_loader_long_press_candidate_item(index);
3233 EXPORTED void ime_app_main(int argc, char **argv)
3235 ime_callback_s basic_callback = {
3242 ime_event_set_focus_in_cb(ime_app_focus_in_cb, NULL);
3243 ime_event_set_focus_out_cb(ime_app_focus_out_cb, NULL);
3244 ime_event_set_rotation_degree_changed_cb(ime_app_rotation_degree_changed_cb, NULL);
3245 ime_event_set_accessibility_state_changed_cb(ime_app_accessibility_state_changed_cb, NULL);
3246 ime_event_set_layout_set_cb(ime_app_layout_set_cb, NULL);
3247 ime_event_set_caps_mode_changed_cb(ime_app_caps_mode_changed_cb, NULL);
3248 ime_event_set_cursor_position_updated_cb(ime_app_cursor_position_updated_cb, NULL);
3249 ime_event_set_surrounding_text_updated_cb(ime_app_surrounding_text_updated_cb, NULL);
3250 ime_event_set_return_key_type_set_cb(ime_app_return_key_type_set_cb, NULL);
3251 ime_event_set_return_key_state_set_cb(ime_app_return_key_state_set_cb, NULL);
3252 ime_event_set_language_set_cb(ime_app_language_set_cb, NULL);
3253 ime_event_set_imdata_set_cb(ime_app_imdata_set_cb, NULL);
3254 ime_event_set_process_key_event_cb(ime_app_process_key_event_cb, NULL);
3255 ime_event_set_process_key_event_with_imengine_cb(ime_app_process_key_event_with_imengine_cb, NULL);
3256 ime_event_set_input_hint_set_cb(ime_app_input_hint_set_cb, NULL);
3258 ime_event_set_candidate_show_cb(ime_app_candidate_show_cb, NULL);
3259 ime_event_set_candidate_hide_cb(ime_app_candidate_hide_cb, NULL);
3260 ime_event_set_lookup_table_changed_cb(ime_app_lookup_table_changed_cb, NULL);
3263 ime_event_set_process_input_device_event_cb(ime_app_process_input_device_event_cb, NULL);
3266 ime_event_set_input_context_reset_cb(ime_app_input_context_reset_cb, NULL);
3267 ime_event_set_language_requested_cb(ime_app_language_requested_cb, NULL);
3269 ime_event_set_prediction_hint_set_cb(ime_app_prediction_hint_set_cb, NULL);
3270 ime_event_set_mime_type_set_request_cb(ime_app_mime_type_set_request_cb, NULL);
3271 ime_event_set_prediction_hint_data_set_cb(ime_app_prediction_hint_data_set_cb, NULL);
3273 ime_event_set_autocapital_type_set_cb(ime_app_autocapital_type_set_cb, NULL);
3274 ime_event_set_prediction_allow_set_cb(ime_app_prediction_allow_set_cb, NULL);
3275 ime_event_set_trigger_property_set_cb(ime_app_trigger_property_set_cb, NULL);
3276 ime_event_set_candidate_more_window_show_cb(ime_app_candidate_more_window_show_cb, NULL);
3277 ime_event_set_candidate_more_window_hide_cb(ime_app_candidate_more_window_hide_cb, NULL);
3278 ime_event_set_aux_select_cb(ime_app_aux_select_cb, NULL);
3279 ime_event_set_candidate_select_cb(ime_app_candidate_select_cb, NULL);
3280 ime_event_set_candidate_table_page_up_cb(ime_app_candidate_table_page_up_cb, NULL);
3281 ime_event_set_candidate_table_page_down_cb(ime_app_candidate_table_page_down_cb, NULL);
3282 ime_event_set_candidate_table_page_size_chaned_cb(ime_app_candidate_table_page_size_chaned_cb, NULL);
3283 ime_event_set_candidate_item_layout_set_cb(ime_app_candidate_item_layout_set_cb, NULL);
3284 ime_event_set_displayed_candidate_number_chaned_cb(ime_app_displayed_candidate_number_chaned_cb, NULL);
3285 ime_event_set_candidate_item_long_pressed_cb(ime_app_candidate_item_long_pressed_cb, NULL);
3287 #if DEFER_ISE_CREATION
3288 ime_set_window_creation_defer_flag(TRUE);
3291 ime_run(&basic_callback, NULL);
3297 EXPORTED int main(int argc, char *argv[])
3299 ime_app_main(argc, argv);