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 void on_event_string_key(CSCLUI *ui, SclUIEventDesc event_desc);
248 void on_event_control_key(CSCLUI *ui, SclUIEventDesc event_desc, KEYBOARD_STATE *keyboard_state);
249 void on_event_character_key(CSCLUI *ui, SclUIEventDesc event_desc, KEYBOARD_STATE *keyboard_state);
250 void on_event_modechange_key(CSCLUI *ui, SclUIEventDesc event_desc, KEYBOARD_STATE *keyboard_state, SCLEventReturnType &ret);
251 void process_user_key(CSCLUI *ui, SclUIEventDesc event_desc, KEYBOARD_STATE *keyboard_state, SCLEventReturnType &ret);
254 static CUIEventCallback callback;
256 int ise_get_imdata_state()
258 return g_imdata_state;
261 void ise_set_imdata_state(int state)
263 g_imdata_state = state;
266 static void update_candidate_table()
268 g_softcandidate_string.clear();
269 vector<string>::iterator iter;
271 g_smartreply_strings.clear();
272 input_smartreply_deinit();
273 g_ic_smartreply = -1;
275 // add autofill string
276 if (ime_autofill_get_exist())
277 g_softcandidate_string.push_back(ime_autofill_get_string());
279 // add lookup table string(s)
280 iter = g_lookup_table_strings.begin();
281 for (; iter != g_lookup_table_strings.end(); ++iter)
283 g_softcandidate_string.push_back(string(iter->c_str()));
286 ise_update_table(g_softcandidate_string);
289 static void _input_smartreply_notify_cb(void *user_data)
291 g_smartreply_strings.clear();
292 char *candidate = NULL;
294 if (input_smartreply_is_enabled()) {
295 /* Append newly added smartreply list */
296 int len = input_smartreply_get_reply_num();
298 for (int i = 0; i < len; i++) {
300 char *reply = (char *)"";
301 reply = input_smartreply_get_nth_item(i, &type);
304 SECURE_LOGD("SmartReply = [%d] %s", i, reply);
307 g_smartreply_strings.push_back(string(candidate));
312 g_ic_smartreply = g_ic;
314 ise_app_candidate_show();
315 g_softcandidate_string = g_smartreply_strings;
316 ise_update_table(g_softcandidate_string);
322 check_ic_temporary(int ic)
324 if ((ic & 0xFFFF) == 0) {
330 static void _reset_shift_state(void)
332 CSCLUI *ui = get_ui();
334 /* Reset all shift state variables */
335 SCLShiftState old_shift_state = ui->get_shift_state();
336 SCLShiftState new_shift_state = SCL_SHIFT_STATE_OFF;
337 if (old_shift_state != new_shift_state) {
338 g_need_send_shift_event = true;
339 ui->set_shift_state(new_shift_state);
341 LOGD("Shift state changed from (%d) to (%d)\n", (int)old_shift_state, (int)new_shift_state);
345 static void set_caps_mode(sclboolean mode) {
346 CSCLUI *ui = get_ui();
347 LOGD("mode : %d\n", mode);
349 if (ui->get_shift_state() != SCL_SHIFT_STATE_LOCK) {
350 ui->set_shift_state(mode ? SCL_SHIFT_STATE_ON : SCL_SHIFT_STATE_OFF);
351 ui->set_autocapital_shift_state(!mode);
353 bool load_in_ime = false;
354 const sclchar *cur_lang = _language_manager.get_current_language();
356 LANGUAGE_INFO *info = _language_manager.get_language_info(cur_lang);
358 load_in_ime = info->load_in_ime;
362 ime_send_imengine_event(mode ? MVK_Shift_On : MVK_Shift_Off, 0);
364 engine_loader_send_imengine_event(mode ? MVK_Shift_On : MVK_Shift_Off, 0);
369 static void _reset_multitap_state(bool skip_commit = false)
371 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
372 if (!keyboard_state) return;
374 LOGD("keyboard_state.prev_modifier : %d", keyboard_state->prev_modifier);
375 if (keyboard_state->prev_modifier == KEY_MODIFIER_MULTITAP_START ||
376 keyboard_state->prev_modifier == KEY_MODIFIER_MULTITAP_REPEAT) {
378 ise_send_string(keyboard_state->multitap_value.c_str());
380 ise_update_preedit_string("");
382 keyboard_state->multitap_value = "";
383 keyboard_state->prev_modifier = KEY_MODIFIER_NONE;
384 if (g_caps_mode_pending) {
385 g_caps_mode_pending = false;
386 set_caps_mode(keyboard_state->caps_mode);
390 static void ise_set_cm_private_key(scluint cm_key_id)
392 CSCLUI *ui = get_ui();
393 if (cm_key_id >= CM_KEY_LIST_SIZE || ui == NULL) {
394 LOGE("cm_key_id=%d\n", cm_key_id);
398 if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_EMOTICON) == 0) {
399 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
400 const_cast<sclchar*>("icon/54x54/icon_emotion_nor.png"),
401 const_cast<sclchar*>("icon/54x54/icon_emotion_press.png"),
402 const_cast<sclchar*>("icon/54x54/icon_emotion_dim.png")};
403 ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_EMOTICON), TRUE);
404 } else if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_OPTION) == 0) {
405 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
406 const_cast<sclchar*>("icon/54x54/icon_setting_nor.png"),
407 const_cast<sclchar*>("icon/54x54/icon_setting_press.png"),
408 const_cast<sclchar*>("icon/54x54/icon_setting_dim.png")};
409 ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_OPTION), TRUE);
410 } else if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_CLIPBOARD) == 0) {
411 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
412 const_cast<sclchar*>("icon/54x54/icon_clipboard_nor.png"),
413 const_cast<sclchar*>("icon/54x54/icon_clipboard_press.png"),
414 const_cast<sclchar*>("icon/54x54/icon_clipboard_dim.png")};
415 ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_CLIPBOARD), TRUE);
416 } else if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_VOICE) == 0) {
417 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
418 const_cast<sclchar*>("icon/54x54/icon_mic_nor.png"),
419 const_cast<sclchar*>("icon/54x54/icon_mic_press.png"),
420 const_cast<sclchar*>("icon/54x54/icon_mic_dim.png")};
421 ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_VOICE), TRUE);
422 } else if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_FLOATING) == 0) {
423 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
424 const_cast<sclchar*>("icon/54x54/icon_floating_keypad_nor.png"),
425 const_cast<sclchar*>("icon/54x54/icon_floating_keypad_press.png"),
426 const_cast<sclchar*>("icon/54x54/icon_floating_keypad_dim.png")};
427 ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_FLOATING), TRUE);
428 } else if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_TRANSLATION) == 0) {
429 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
430 const_cast<sclchar*>("icon/54x54/icon_translation_nor.png"),
431 const_cast<sclchar*>("icon/54x54/icon_translation_press.png"),
432 const_cast<sclchar*>("icon/54x54/icon_translation_dim.png")};
433 ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_TRANSLATION), TRUE);
434 } else if (strcmp(_cm_key_list[cm_key_id], USER_KEYSTRING_STICKER) == 0) {
435 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
436 const_cast<sclchar*>("icon/54x54/icon_sticker_nor.png"),
437 const_cast<sclchar*>("icon/54x54/icon_sticker_press.png"),
438 const_cast<sclchar*>("icon/54x54/icon_sticker_dim.png")};
439 ui->set_private_key("CM_KEY", const_cast<sclchar*>(" "), imagelabel, NULL, 0, const_cast<sclchar*>(USER_KEYSTRING_STICKER), TRUE);
443 static void ise_update_space_key(void)
445 CSCLUI *ui = get_ui();
451 scluint num = _language_manager.get_enabled_languages_num();
452 LOGD("language number: %d\n", num);
454 LANGUAGE_INFO *info = _language_manager.get_language_info(_language_manager.get_current_language());
455 if (info && info->enabled) {
457 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
458 const_cast<sclchar*>("w_sip_3x4_btn_ic_space_no_arrow.png"),
459 const_cast<sclchar*>("w_sip_3x4_btn_ic_space_no_arrow.png"),
460 const_cast<sclchar*>("w_sip_3x4_btn_ic_space_no_arrow.png")};
461 ui->set_private_key("SPACE_KEY", const_cast<sclchar*>(info->display_name.c_str()), imagelabel, NULL, 0, const_cast<sclchar*>("Space"), TRUE);
463 ui->enable_button("SPACE_ARROW_LEFT", false);
464 ui->enable_button("SPACE_ARROW_RIGHT", false);
469 ui->unset_private_key("SPACE_KEY");
471 ui->enable_button("SPACE_ARROW_LEFT", true);
472 ui->enable_button("SPACE_ARROW_RIGHT", true);
477 static scluint ise_get_cm_key_id(const sclchar *key_value)
479 for (int i = 0; i < CM_KEY_LIST_SIZE; ++i) {
480 if (0 == strcmp (key_value, _cm_key_list[i]))
486 static bool ise_is_emoticons_disabled(void)
490 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
491 if (!keyboard_state) return ret;
493 sclu32 current_layout = keyboard_state->layout;
494 LOGD("layout=%d\n", current_layout);
496 if ((current_layout == ISE_LAYOUT_STYLE_NORMAL) ||
497 (current_layout == ISE_LAYOUT_STYLE_NUMBER) ||
498 (current_layout == ISE_LAYOUT_STYLE_EMOTICON))
501 if (g_imdata_state & IMDATA_ACTION_DISABLE_EMOTICONS)
507 static Eina_Bool softcandidate_hide_timer_callback(void *data)
510 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_HIDE);
512 Candidate *candidate = get_candidate();
516 return ECORE_CALLBACK_CANCEL;
519 static void delete_softcandidate_hide_timer(void)
521 if (g_softcandidate_hide_timer) {
522 ecore_timer_del(g_softcandidate_hide_timer);
523 g_softcandidate_hide_timer = NULL;
527 static void add_softcandidate_hide_timer(void)
529 delete_softcandidate_hide_timer();
530 g_softcandidate_hide_timer = ecore_timer_add(SOFT_CANDIDATE_DELETE_TIME, softcandidate_hide_timer_callback, NULL);
533 static void create_softcandidate(void)
536 g_candidate = CandidateFactory::make_candidate(CANDIDATE_MULTILINE, ime_get_main_window());
538 g_candidate->add_event_listener(&g_candidate_event_listener);
544 * Send the given string to input framework
547 ise_send_string(const sclchar *key_value)
550 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
551 if (keyboard_state && !check_ic_temporary(keyboard_state->ic)) {
552 ic = keyboard_state->ic;
554 ime_commit_string(key_value);
555 LOGD("ic : %x, %s\n", ic, key_value);
559 * Send the preedit string to input framework
562 ise_update_preedit_string(const sclchar *str, const sclboolean underline)
565 Eina_List *attr_list = NULL;
566 ime_preedit_attribute *preedit_attr;
568 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
569 if (keyboard_state && !check_ic_temporary(keyboard_state->ic)) {
570 ic = keyboard_state->ic;
573 /* Count UTF-8 string length */
575 const sclchar *s = str;
576 while (*s) len += (*s++ & 0xc0) != 0x80;
578 preedit_attr = (ime_preedit_attribute *)calloc(1, sizeof(ime_preedit_attribute));
580 preedit_attr->start = 0;
581 preedit_attr->length = len;
582 preedit_attr->type = IME_ATTR_FONTSTYLE;
583 preedit_attr->value = IME_ATTR_FONTSTYLE_UNDERLINE;
584 attr_list = eina_list_append(attr_list, (void *)preedit_attr);
587 ime_update_preedit_string(str, attr_list);
589 ime_update_preedit_string(str, NULL);
591 LOGD("ic : %x, %s\n", ic, str);
595 * Send the given event to input framework
598 ise_send_event(sclulong key_event, sclulong key_mask)
601 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
602 if (keyboard_state && !check_ic_temporary(keyboard_state->ic)) {
603 ic = keyboard_state->ic;
605 ime_send_key_event((ime_key_code_e)key_event, IME_KEY_MASK_PRESSED, false);
606 ime_send_key_event((ime_key_code_e)key_event, IME_KEY_MASK_RELEASED, false);
608 LOGD("ic : %x, %lx\n", (unsigned int)ic, key_event);
612 * Forward the given event to input framework
615 ise_forward_key_event(sclulong key_event)
618 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
619 if (!check_ic_temporary(keyboard_state->ic)) {
620 ic = keyboard_state->ic;
622 ime_send_key_event((ime_key_code_e)key_event, IME_KEY_MASK_PRESSED, true);
623 ime_send_key_event((ime_key_code_e)key_event, IME_KEY_MASK_RELEASED, true);
625 LOGD("ic : %x, %lx\n", (unsigned int)ic, key_event);
629 * @brief Delete commit timer.
633 static void delete_commit_timer(void)
635 if (_commit_timer != NULL) {
636 ecore_timer_del(_commit_timer);
637 _commit_timer = NULL;
642 * @brief Callback function for commit timer.
644 * @param data Data to pass when it is called.
646 * @return ECORE_CALLBACK_CANCEL
648 static Eina_Bool commit_timeout(void *data)
650 if (_commit_timer != NULL) {
651 ime_hide_preedit_string();
652 ise_forward_key_event(_sig_dec_event[(_click_count-1)%SIG_DEC_SIZE]);
655 _commit_timer = NULL;
656 return ECORE_CALLBACK_CANCEL;
660 on_input_mode_changed(const sclchar *key_value, sclulong key_event, sclint key_type)
662 sclboolean ret = FALSE;
664 CSCLUI *ui = get_ui();
665 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
666 if (ui && keyboard_state) {
668 SECURE_LOGD("key_value : %s\n", key_value);
669 if (strcmp(key_value, "CUR_LANG") == 0) {
670 keyboard_state->disable_force_latin = TRUE;
671 ret = _language_manager.select_current_language();
673 if (strcmp(key_value, "NEXT_LANG") == 0) {
674 keyboard_state->disable_force_latin = TRUE;
675 ret = _language_manager.select_next_language();
679 const sclchar *cur_lang = _language_manager.get_current_language();
681 LANGUAGE_INFO *info = _language_manager.get_language_info(cur_lang);
683 if (info->accepts_caps_mode) {
684 if (info->load_in_ime)
685 ime_send_imengine_event(MVK_Shift_Enable, 0);
687 engine_loader_send_imengine_event(MVK_Shift_Enable, 0);
689 set_caps_mode(keyboard_state->caps_mode);
691 if (info->load_in_ime)
692 ime_send_imengine_event(MVK_Shift_Disable, 0);
694 engine_loader_send_imengine_event(MVK_Shift_Disable, 0);
696 ui->set_shift_state(SCL_SHIFT_STATE_OFF);
701 if (ise_sticker_is_show())
702 ise_sticker_destroy_layout();
704 if (ise_emoticon_is_show()) {
705 ise_emoticon_destroy_layout();
708 if (ise_nmt_is_show()) {
709 ise_nmt_destroy_layout();
713 if (!strcmp(key_value, USER_KEYSTRING_EMOTICON)) {
714 ise_emoticon_init_list();
716 ise_emoticon_set_current_group(EMOTICON_GROUP_1);
718 if (ise_emoticon_get_recent_list_size() == 0)
719 ise_emoticon_set_current_group(EMOTICON_GROUP_1);
721 ise_emoticon_set_current_group(EMOTICON_GROUP_RECENTLY_USED);
723 SCLRotation rotation = ui->get_rotation();
724 ise_emoticon_show_layout(ise_emoticon_get_current_group(), ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
726 else if (!strcmp(key_value, USER_KEYSTRING_TRANSLATION)) {
728 SCLRotation rotation = ui->get_rotation();
729 ise_nmt_show_layout(ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
737 SCLEventReturnType CUIEventCallback::on_event_notification(SCLUINotiType noti_type, SclNotiDesc *etc_info)
739 CSCLUI *ui = get_ui();
740 SCLEventReturnType ret = SCL_EVENT_PASS_ON;
741 LOGD("noti type: %d, g_need_send_shift_event: %d\n", noti_type, g_need_send_shift_event);
743 if (noti_type == SCL_UINOTITYPE_SHIFT_STATE_CHANGE) {
744 if (g_need_send_shift_event) {
745 const sclchar *cur_lang = _language_manager.get_current_language();
747 LANGUAGE_INFO *info = _language_manager.get_language_info(cur_lang);
748 SclNotiShiftStateChangeDesc *desc = static_cast<SclNotiShiftStateChangeDesc*>(etc_info);
750 if (info->accepts_caps_mode) {
751 LOGD("shift state: %d\n", desc->shift_state);
752 if (desc->shift_state == SCL_SHIFT_STATE_OFF) {
753 if (info->load_in_ime)
754 ime_send_imengine_event(MVK_Shift_Off, 0);
756 engine_loader_send_imengine_event(MVK_Shift_Off, 0);
757 } else if (desc->shift_state == SCL_SHIFT_STATE_ON) {
758 if (info->load_in_ime)
759 ime_send_imengine_event(MVK_Shift_On, 0);
761 engine_loader_send_imengine_event(MVK_Shift_On, 0);
762 } else if (desc->shift_state == SCL_SHIFT_STATE_LOCK) {
763 if (info->load_in_ime)
764 ime_send_imengine_event(MVK_Shift_Lock, 0);
766 engine_loader_send_imengine_event(MVK_Shift_Lock, 0);
768 ret = SCL_EVENT_PASS_ON;
772 g_need_send_shift_event = FALSE;
774 } else if (noti_type == SCL_UINOTITYPE_POPUP_OPENING) {
775 vector<string>::reverse_iterator iter = g_recent_used_punctuation.rbegin();
777 for (; iter != g_recent_used_punctuation.rend(); ++iter)
780 ui->set_string_substitution(g_current_punctuation[punc_pos].c_str(), iter->c_str());
783 SclNotiPopupOpeningDesc *openingDesc = (SclNotiPopupOpeningDesc *)etc_info;
784 if (ui && 0 == strcmp(openingDesc->input_mode, "CM_POPUP")) {
785 if (!ise_sticker_check_sticker_exists())
786 ui->enable_button("STICKER_KEY", EINA_FALSE);
788 if (nmt_is_disabled())
789 ui->enable_button("TRANSLATION_KEY", false);
791 ui->enable_button("TRANSLATION_KEY", true);
793 if (ise_is_emoticons_disabled())
794 ui->enable_button("EMOTICON_KEY", false);
796 ui->enable_button("EMOTICON_KEY", true);
798 } else if (noti_type == SCL_UINOTITYPE_POPUP_OPENED) {
799 g_popup_opened = TRUE;
800 SclNotiPopupOpenedDesc *openedDesc = (SclNotiPopupOpenedDesc *)etc_info;
801 if (0 == strcmp(openedDesc->input_mode, "PUNCTUATION_POPUP")) {
802 g_punctuation_popup_opened = TRUE;
803 } else if (0 == strcmp(openedDesc->input_mode, "CM_POPUP")) {
804 _cm_popup_opened = TRUE;
806 } else if (noti_type == SCL_UINOTITYPE_POPUP_CLOSED) {
807 g_popup_opened = FALSE;
808 SclNotiPopupClosedDesc *closedDesc = (SclNotiPopupClosedDesc *)etc_info;
809 if (closedDesc && closedDesc->input_mode) {
810 if (0 == strcmp(closedDesc->input_mode, "PUNCTUATION_POPUP")) {
811 g_punctuation_popup_opened = FALSE;
812 } else if (0 == strcmp(closedDesc->input_mode, "CM_POPUP")) {
813 _cm_popup_opened = FALSE;
816 } else if (noti_type == SCL_UINOTITYPE_INPUT_MODE_CHANGE) {
817 SclNotiInputModeChangeDesc *desc = static_cast<SclNotiInputModeChangeDesc*>(etc_info);
819 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
821 const char *input_mode = ui->get_input_mode();
823 if (strcmp(input_mode, "STT_3X4") == 0 &&
824 strcmp(desc->input_mode, "STT_3X4") != 0) {
827 if (strcmp(input_mode, "STT_3X4") != 0 &&
828 strcmp(desc->input_mode, "STT_3X4") == 0) {
829 ise_show_stt_mode(NATIVE_WINDOW_CAST(ime_get_main_window()));
838 bool get_landscape_device(int degree)
842 bool landscape_device = false;
844 CSCLUI *ui = get_ui();
845 if (!ui) return false;
847 ui->get_screen_resolution(&width, &height);
849 if (degree == 0 || degree == 180) {
851 landscape_device = true;
855 landscape_device = true;
858 return landscape_device;
861 SCLEventReturnType CUIEventCallback::on_event_drag_state_changed(SclUIEventDesc event_desc)
863 SECURE_LOGD("button %s is clicked\n", event_desc.key_value);
864 if (event_desc.event_type == EVENT_TYPE_MOVE) {
865 if (event_desc.key_event == MVK_space) {
866 SclRectangle rectangle = {0};
867 CSCLUI *ui = get_ui();
868 if (ui) ui->get_button_geometry("SPACE_KEY", &rectangle);
869 ise_show_space_flick_language_change_popup(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
871 } else if (event_desc.event_type == EVENT_TYPE_RELEASE) {
872 if (event_desc.key_event == MVK_space) {
873 ise_destroy_space_flick_language_change_popup();
877 ime_set_floating_drag_end();
878 } else if (event_desc.event_type == EVENT_TYPE_PRESS) {
879 #if defined(_MOBILE) || defined(_COMMON)
880 CONFIG_VALUES *config_values = get_config_values();
882 if (config_values && (!config_values->first_guideset) && event_desc.key_value && (strncmp(event_desc.key_value, "OPTION", strlen(event_desc.key_value)) == 0)) {
883 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
884 LOGD("setting popup show\n");
885 return SCL_EVENT_PASS_ON;
887 ise_destroy_popup_setting();//destroy popup manually in case of abnormal situation
890 if (g_floating_mode && event_desc.mouse_current_point.y <= FLOATING_TITLE_BAR_HEIGHT
891 && event_desc.mouse_current_point.y >= 0)
892 ime_set_floating_drag_start();
894 return SCL_EVENT_PASS_ON;
897 static void launch_option()
899 app_control_h app_control;
900 int ret = app_control_create(&app_control);
901 if (ret != APP_CONTROL_ERROR_NONE) {
902 LOGW("app_control_create returned %d\n", ret);
906 ret = app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
907 if (ret != APP_CONTROL_ERROR_NONE) {
908 LOGW("app_control_set_operation returned %d\n", ret);
912 ret = app_control_set_app_id(app_control, "org.tizen.ise-default-setting");
913 if (ret != APP_CONTROL_ERROR_NONE) {
914 LOGW("app_control_set_app_id returned %d\n", ret);
918 app_control_add_extra_data(app_control, "caller", "ise-default");
919 app_control_set_launch_mode(app_control, APP_CONTROL_LAUNCH_MODE_GROUP);
921 ret = app_control_send_launch_request(app_control, NULL, NULL);
922 if (ret != APP_CONTROL_ERROR_NONE) {
928 app_control_destroy(app_control);
931 void CUIEventCallback::on_event_string_key(CSCLUI *ui, SclUIEventDesc event_desc)
933 if (event_desc.key_modifier != KEY_MODIFIER_MULTITAP_START &&
934 event_desc.key_modifier != KEY_MODIFIER_MULTITAP_REPEAT) {
935 if (event_desc.key_event) {
936 ise_forward_key_event(event_desc.key_event);
938 ise_send_string(event_desc.key_value);
942 if (!g_popup_opened) {
943 const sclchar *input_mode = ui->get_input_mode();
944 if (input_mode && ((0 == strcmp(input_mode, "SYM_QTY_1")) || (0 == strcmp(input_mode, "SYM_QTY_2")))) {
945 update_recent_used_punctuation(event_desc.key_value);
947 } else if (g_punctuation_popup_opened) {
948 update_recent_used_punctuation(event_desc.key_value);
952 void CUIEventCallback::on_event_control_key(CSCLUI *ui, SclUIEventDesc event_desc, KEYBOARD_STATE *keyboard_state)
954 commit_timeout(NULL);
956 const char *long_shift = "LongShift";
957 const char *caps_lock = "CapsLock";
958 const char *delete_all = "DeleteAll";
959 const char *hide_panel = "Hide";
961 if (strncmp(event_desc.key_value, long_shift, strlen(long_shift)) == 0) {
962 LOGD("shift key is longpress\n");
963 ui->set_shift_state(SCL_SHIFT_STATE_ON);
964 g_need_send_shift_event = TRUE;
965 //ise_send_event (MVK_Shift_Lock, KEY_MASK_NULL);
966 } else if (strncmp(event_desc.key_value, caps_lock, strlen(caps_lock)) == 0) {
967 bool load_in_ime = false;
968 const sclchar *cur_lang = _language_manager.get_current_language();
970 LANGUAGE_INFO *info = _language_manager.get_language_info(cur_lang);
972 load_in_ime = info->load_in_ime;
975 if (ui->get_shift_state() != SCL_SHIFT_STATE_LOCK) {
976 ui->set_shift_state(SCL_SHIFT_STATE_LOCK);
978 ime_send_imengine_event(MVK_Shift_Lock, 0);
980 engine_loader_send_imengine_event(MVK_Shift_Lock, 0);
982 ui->set_shift_state(SCL_SHIFT_STATE_OFF);
984 ime_send_imengine_event(MVK_Shift_Off, 0);
986 engine_loader_send_imengine_event(MVK_Shift_Off, 0);
988 //g_need_send_shift_event = TRUE;
989 } else if (strncmp(event_desc.key_value, delete_all, strlen(delete_all)) == 0) {
990 ime_delete_surrounding_text((INT_MAX / 2) * -1, INT_MAX);
991 } else if (strncmp(event_desc.key_value, hide_panel, strlen(hide_panel)) == 0) {
994 } else if (event_desc.key_event) {
995 if (keyboard_state->layout == ISE_LAYOUT_STYLE_VOICE) {
999 if (event_desc.key_event == MVK_Done) {
1001 //commit the preedit string first
1002 ise_send_event(event_desc.key_event, KEY_MASK_NULL);
1005 ise_send_event(event_desc.key_event, KEY_MASK_NULL);
1006 if (event_desc.key_event == MVK_Shift_L) {
1007 g_need_send_shift_event = TRUE;
1012 void CUIEventCallback::on_event_character_key(CSCLUI *ui, SclUIEventDesc event_desc, KEYBOARD_STATE *keyboard_state)
1014 sclboolean need_forward = FALSE;
1015 // FIXME : Should decide when to forward key events
1016 const sclchar *input_mode = ui->get_input_mode();
1018 if (strcmp(input_mode, "SYM_QTY_1") == 0 ||
1019 strcmp(input_mode, "SYM_QTY_2") == 0 ||
1020 strcmp(input_mode, "PHONE_3X4") == 0 ||
1021 strcmp(input_mode, "IPv6_3X4_123") == 0 ||
1022 strcmp(input_mode, "IPv6_3X4_ABC") == 0 ||
1023 strcmp(input_mode, "NUMONLY_3X4") == 0 ||
1024 strcmp(input_mode, "NUMONLY_3X4_SIG") == 0 ||
1025 strcmp(input_mode, "NUMONLY_3X4_DEC") == 0 ||
1026 strcmp(input_mode, "NUMONLY_3X4_SIGDEC") == 0 ||
1027 strcmp(input_mode, "DATETIME_3X4") == 0) {
1028 need_forward = TRUE;
1031 if (input_mode && strcmp (input_mode, "NUMONLY_3X4_SIGDEC") == 0 &&
1032 strcmp(event_desc.key_value, ".") == 0) {
1033 ime_update_preedit_string(_sig_dec[_click_count%SIG_DEC_SIZE], NULL);
1034 ime_show_preedit_string();
1035 delete_commit_timer();
1036 _commit_timer = ecore_timer_add(1.0, commit_timeout, NULL);
1038 } else if (event_desc.key_event) {
1039 commit_timeout(NULL);
1041 ise_forward_key_event(event_desc.key_event);
1043 if (_cm_popup_opened) {
1044 static sclchar current_cm_symbol[2] = {'\0'};
1045 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
1046 const_cast<sclchar*>(" "),
1047 const_cast<sclchar*>(" "),
1048 const_cast<sclchar*>(" ")};
1049 if (event_desc.key_value) {
1050 current_cm_symbol[0] = event_desc.key_value[0];
1051 current_cm_symbol[1] = '\0';
1053 ui->set_private_key("CM_KEY",
1054 const_cast<sclchar*>(current_cm_symbol),
1055 imagelabel, NULL, 0,
1056 const_cast<sclchar*>(current_cm_symbol), TRUE);
1058 _cm_popup_opened = FALSE;
1059 _current_cm_key_id = -1;
1063 * change the keyboard mode of GLM from QWERTY to KEYPAD
1064 * ensure the Number keypad won't be affected
1066 if (keyboard_state->layout == ISE_LAYOUT_STYLE_NUMBER) {
1067 ime_send_key_event(IME_KEY_Print, IME_KEY_MASK_CONTROL, false);
1069 Candidate *candidate = get_candidate();
1070 if (word_timer == NULL && (!candidate || !candidate->get_visible())) {
1071 word_timer = ecore_timer_add(MULTITAP_TIMEOUT, _multi_tap_timer_cb, NULL);
1073 ime_send_key_event(IME_KEY_Select, IME_KEY_MASK_CONTROL, false);
1076 ise_send_event(event_desc.key_event, KEY_MASK_NULL);
1081 if ((strcmp(input_mode, "SYM_QTY_1") == 0) || (0 == strcmp(input_mode, "SYM_QTY_2"))) {
1082 update_recent_used_punctuation(event_desc.key_value);
1087 void CUIEventCallback::on_event_modechange_key(CSCLUI *ui, SclUIEventDesc event_desc, KEYBOARD_STATE *keyboard_state, SCLEventReturnType &ret)
1089 #if defined(_MOBILE) || defined(_COMMON)
1090 if (guide_popup_get_visible()) {//popup is showing
1095 if (strcmp(event_desc.key_value, USER_VOICE_LANGUAGE) == 0) {
1096 if (!get_setting_window_open_status()) {
1097 ise_hide_stt_mode();
1099 hide_indicator_window();
1101 create_setting_window();
1103 } else if (strcmp(event_desc.key_value, USER_KEYSTRING_VOICE) == 0) {
1104 keyboard_state->layout = ISE_LAYOUT_STYLE_VOICE;
1105 ui->set_input_mode("STT_3X4");
1107 } else if (strcmp(event_desc.key_value, USER_KEYSTRING_OPTION) == 0) {
1110 ret = SCL_EVENT_DONE;
1111 } else if (strcmp(event_desc.key_value, USER_KEYSTRING_CLIPBOARD) == 0) {
1114 ret = SCL_EVENT_DONE;
1115 } else if (strcmp(event_desc.key_value, USER_KEYSTRING_FLOATING) == 0) {
1116 CONFIG_VALUES *config_values = get_config_values();
1118 if (g_floating_mode) {
1119 if (config_values) {
1120 config_values->floating_mode = false;
1123 if (config_values) {
1124 config_values->floating_mode = true;
1127 write_ise_config_values();
1129 ret = SCL_EVENT_DONE;
1130 } else if (strcmp(event_desc.key_value, USER_KEYSTRING_STICKER) == 0) {
1131 SCLRotation rotation = ui->get_rotation();
1132 ise_sticker_show_layout(STICKER_GROUP_RECENTLY_USED, ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
1133 } else if (strcmp(event_desc.key_value, USER_KEYSTRING_TRANSLATION) == 0) {
1134 if (ise_sticker_is_show())
1135 ise_sticker_destroy_layout();
1137 SCLRotation rotation = ui->get_rotation();
1138 ise_nmt_show_layout(ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
1139 } else if (on_input_mode_changed(event_desc.key_value, event_desc.key_event, event_desc.key_type)) {
1140 ret = SCL_EVENT_DONE;
1143 if (_cm_popup_opened) {
1144 if (strcmp(event_desc.key_value, USER_KEYSTRING_EMOTICON) == 0 ||
1145 strcmp(event_desc.key_value, USER_KEYSTRING_VOICE) == 0 ||
1146 strcmp(event_desc.key_value, USER_KEYSTRING_FLOATING) == 0 ||
1147 strcmp(event_desc.key_value, USER_KEYSTRING_STICKER) == 0 ||
1148 strcmp(event_desc.key_value, USER_KEYSTRING_TRANSLATION) == 0) {
1149 scluint id = ise_get_cm_key_id(event_desc.key_value);
1150 if (id != _current_cm_key_id) {
1151 _current_cm_key_id = id;
1152 ise_set_cm_private_key(_current_cm_key_id);
1155 _cm_popup_opened = FALSE;
1158 if (strlen(event_desc.key_value) == 1) {
1159 const char allowed_chars_in_modechange[] = {
1160 ',', '?', '!', '`', '~', '@', '-'
1162 const int allowed_chars_in_modechange_num =
1163 sizeof(allowed_chars_in_modechange) / sizeof(char);
1164 for (unsigned int loop = 0;loop < sizeof(allowed_chars_in_modechange_num);loop++) {
1165 if (*(event_desc.key_value) == allowed_chars_in_modechange[loop]) {
1166 ise_send_string(event_desc.key_value);
1172 void CUIEventCallback::process_user_key(CSCLUI *ui, SclUIEventDesc event_desc, KEYBOARD_STATE *keyboard_state, SCLEventReturnType &ret)
1174 if (strcmp(event_desc.key_value, USER_KEYSTRING_OPTION) == 0) {
1175 //open_option_window(NULL, ROTATION_TO_DEGREE(ui->get_rotation()));
1178 ret = SCL_EVENT_DONE;
1179 } else if (strcmp(event_desc.key_value, USER_KEYSTRING_CLIPBOARD) == 0) {
1181 ret = SCL_EVENT_DONE;
1182 } else if (strcmp(event_desc.key_value, "Cancel") == 0) {
1183 ret = SCL_EVENT_DONE;
1184 const sclchar *input_mode = ui->get_input_mode();
1185 if (input_mode && strcmp(input_mode, "STT_3X4") == 0 ) {
1186 keyboard_state->need_reset = TRUE;
1187 voice_result_string_flush();
1188 ise_set_layout(keyboard_state->layout, keyboard_state->layout_variation);
1189 if (keyboard_state->visible_state)
1190 ise_show(keyboard_state->ic);
1193 ise_send_event(IME_KEY_Cancel, KEY_MASK_NULL);
1196 } else if (strcmp(event_desc.key_value, "Done") == 0) {
1198 ret = SCL_EVENT_DONE;
1199 ise_send_event(IME_KEY_Return, KEY_MASK_NULL);
1202 } else if (strcmp(event_desc.key_value, "Translate") == 0) {
1203 ise_nmt_translate();
1205 const sclchar *input_mode = ui->get_input_mode();
1206 if ((NULL != input_mode) && (!strcmp(input_mode, "EMOTICON_LAYOUT"))) {
1207 if (ise_emoticon_is_show()) {
1208 ise_emoticon_destroy_layout();
1211 emoticon_group_t group_id = EMOTICON_GROUP_1;
1212 if (ise_emoticon_get_current_group() < EMOTICON_GROUP_3)
1213 group_id = (emoticon_group_t)(ise_emoticon_get_current_group() + 1);
1215 ise_set_emoticon_label(group_id);
1217 emoticon_group_t group_id = ise_emoticon_get_group_id(event_desc.key_value);
1219 if ((group_id >= 0) && (group_id < MAX_EMOTICON_GROUP)) {
1220 SCLRotation rotation = ui->get_rotation();
1221 ise_emoticon_show_layout(group_id, ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
1225 if (input_mode && (!strcmp(input_mode, "STICKER_LAYOUT"))) {
1226 if (ise_sticker_is_show())
1227 ise_sticker_change_group(ise_sticker_get_group_id(event_desc.key_value));
1231 if (_cm_popup_opened) {
1232 if (strcmp(event_desc.key_value, USER_KEYSTRING_OPTION) == 0 ||
1233 strcmp(event_desc.key_value, USER_KEYSTRING_CLIPBOARD) == 0 ||
1234 strcmp(event_desc.key_value, USER_KEYSTRING_STICKER) == 0 ||
1235 strcmp(event_desc.key_value, USER_KEYSTRING_TRANSLATION) == 0) {
1236 scluint id = ise_get_cm_key_id(event_desc.key_value);
1237 if (id != _current_cm_key_id) {
1238 _current_cm_key_id = id;
1239 ise_set_cm_private_key(_current_cm_key_id);
1242 _cm_popup_opened = FALSE;
1246 SCLEventReturnType CUIEventCallback::on_event_key_clicked(SclUIEventDesc event_desc)
1248 SCLEventReturnType ret = SCL_EVENT_PASS_ON;
1249 if (word_timer != NULL) {
1250 ecore_timer_del(word_timer);
1254 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1255 if (!keyboard_state) return ret;
1257 if (event_desc.key_modifier == KEY_MODIFIER_MULTITAP_START) {
1258 if (!keyboard_state->multitap_value.empty()) {
1259 ise_send_string(keyboard_state->multitap_value.c_str());
1261 ise_update_preedit_string(event_desc.key_value);
1262 keyboard_state->multitap_value = event_desc.key_value;
1263 } else if (event_desc.key_modifier == KEY_MODIFIER_MULTITAP_REPEAT) {
1264 ise_update_preedit_string(event_desc.key_value);
1265 keyboard_state->multitap_value = event_desc.key_value;
1267 _reset_multitap_state();
1269 keyboard_state->prev_modifier = event_desc.key_modifier;
1271 CSCLUI *ui = get_ui();
1273 switch (event_desc.key_type) {
1274 case KEY_TYPE_STRING:
1275 on_event_string_key(ui, event_desc);
1278 on_event_character_key(ui, event_desc, keyboard_state);
1280 case KEY_TYPE_CONTROL:
1281 on_event_control_key(ui, event_desc, keyboard_state);
1283 case KEY_TYPE_MODECHANGE:
1284 on_event_modechange_key(ui, event_desc, keyboard_state, ret);
1287 process_user_key(ui, event_desc, keyboard_state, ret);
1298 ise_set_layout(sclu32 layout, sclu32 layout_variation)
1300 /* Check if the layoutIdx is in the valid range */
1301 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1302 if (layout < ISE_LAYOUT_STYLE_MAX) {
1303 if (keyboard_state->layout != layout ||
1304 keyboard_state->layout_variation != layout_variation) {
1305 keyboard_state->need_reset = TRUE;
1307 keyboard_state->layout = layout;
1308 keyboard_state->layout_variation = layout_variation;
1309 LOGD("layout:%d, variation:%d\n", keyboard_state->layout, keyboard_state->layout_variation);
1317 _reset_multitap_state(true);
1318 CONFIG_VALUES *config_values = get_config_values();
1319 if (config_values) {
1320 _language_manager.reset_language(config_values->selected_language.c_str());
1325 ise_reset_input_context()
1328 _reset_multitap_state(true);
1329 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1330 if (keyboard_state) keyboard_state->disable_force_latin = FALSE;
1331 CONFIG_VALUES *config_values = get_config_values();
1332 if (config_values) {
1333 _language_manager.reset_language(config_values->selected_language.c_str());
1338 ise_focus_in(int ic)
1340 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1341 if (!keyboard_state) return;
1343 LOGD("ic : %x , %x , g_ic : %x , %x, g_focused_ic : %x , %x\n", ic, check_ic_temporary(ic),
1344 keyboard_state->ic, check_ic_temporary(keyboard_state->ic),
1345 keyboard_state->focused_ic, check_ic_temporary(keyboard_state->focused_ic));
1346 if (check_ic_temporary(keyboard_state->ic) && !check_ic_temporary(ic)) {
1347 keyboard_state->ic = ic;
1349 keyboard_state->focused_ic = ic;
1352 static void save_autofill_data()
1357 if (ime_autofill_get_hint() == 0)
1360 ime_get_surrounding_text(-1, -1, &text, &cursor);
1361 SECURE_LOGD("surrounding text : %s\n", text);
1364 ime_autofill_save_string(text);
1370 ise_focus_out(int ic)
1372 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1373 if (keyboard_state) keyboard_state->focused_ic = 0;
1374 _reset_multitap_state(true);
1376 save_autofill_data();
1379 bool ise_is_guideline_popup_enable_layout(void)
1382 switch (_context_layout)
1384 case ISE_LAYOUT_STYLE_PHONENUMBER:
1385 case ISE_LAYOUT_STYLE_IP:
1386 case ISE_LAYOUT_STYLE_MONTH:
1387 case ISE_LAYOUT_STYLE_NUMBERONLY:
1388 case ISE_LAYOUT_STYLE_HEX:
1389 case ISE_LAYOUT_STYLE_TERMINAL:
1390 case ISE_LAYOUT_STYLE_DATETIME:
1391 case ISE_LAYOUT_STYLE_PASSWORD:
1401 #if EXIT_ISE_ON_HIDE
1402 static Eina_Bool exit_timer_cb(void *data)
1404 if (exit_timer) ecore_timer_del(exit_timer);
1407 return ECORE_CALLBACK_CANCEL;
1414 CONFIG_VALUES *config_values = get_config_values();
1415 #if EXIT_ISE_ON_HIDE
1416 if (exit_timer) ecore_timer_del(exit_timer);
1419 sclboolean reset_inputmode = FALSE;
1420 g_input_panel_show = true;
1422 CSCLUI *ui = get_ui();
1423 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1424 if (ui && keyboard_state) {
1425 read_ise_config_values();
1427 if (config_values) {
1428 _language_manager.set_enabled_languages(config_values->enabled_languages);
1430 const sclchar *cur_lang = _language_manager.get_current_language();
1433 ise_check_wearable_candidate();
1435 *Clear the personalized data
1437 if (config_values && config_values->dataclear) {
1438 ime_send_key_event(IME_KEY_Clear, IME_KEY_MASK_CONTROL, false);
1439 config_values->dataclear = FALSE;
1442 LOGD("ic : %x , %x , g_ic : %x , %x, g_focused_ic : %x , %x\n", ic, check_ic_temporary(ic),
1443 keyboard_state->ic, check_ic_temporary(keyboard_state->ic),
1444 keyboard_state->focused_ic, check_ic_temporary(keyboard_state->focused_ic));
1446 if (check_ic_temporary(ic) && !check_ic_temporary(keyboard_state->focused_ic)) {
1447 ic = keyboard_state->focused_ic;
1450 if (!check_ic_temporary(ic) && check_ic_temporary(keyboard_state->focused_ic)) {
1451 keyboard_state->focused_ic = ic;
1454 if (ic == keyboard_state->focused_ic) {
1455 switch (keyboard_state->layout)
1457 case ISE_LAYOUT_STYLE_PHONENUMBER:
1458 case ISE_LAYOUT_STYLE_IP:
1459 case ISE_LAYOUT_STYLE_MONTH:
1460 case ISE_LAYOUT_STYLE_NUMBERONLY:
1461 ime_set_imengine(DEFAULT_KEYBOARD_ISE_UUID);
1468 const char *input_mode = ui->get_input_mode();
1470 /* Reset input mode if the input context value has changed */
1471 if (ic != keyboard_state->ic) {
1472 /* Do not reset input mode if STT's setting window was opened */
1473 if (get_setting_window_open_status() && input_mode && strcmp(input_mode, "STT_3X4") == 0) {
1474 LOGD("Setting window was opened while using STT, skip resetting input mode");
1476 reset_inputmode = TRUE;
1480 keyboard_state->ic = ic;
1481 /* Reset input mode if the current language is not the selected language */
1483 if (config_values && config_values->selected_language.compare(cur_lang) != 0) {
1484 reset_inputmode = TRUE;
1488 /* No matter what, just reset the inputmode if it needs to */
1489 if (keyboard_state->need_reset) {
1490 /* Do not reset input mode if STT's setting window was opened */
1491 if (get_setting_window_open_status() && input_mode && strcmp(input_mode, "STT_3X4") == 0) {
1492 LOGD("Setting window was opened while using STT, skip resetting input mode");
1494 reset_inputmode = TRUE;
1497 keyboard_state->need_reset = FALSE;
1499 /* If the current layout requires latin language and current our language is not latin, enable the primary latin */
1500 sclboolean force_primary_latin = FALSE;
1501 LANGUAGE_INFO *info =
1502 (config_values ? _language_manager.get_language_info(config_values->selected_language.c_str()) : NULL);
1504 if (!info->is_latin_language) {
1505 if (!keyboard_state->disable_force_latin) {
1506 if (g_ise_default_values[keyboard_state->layout].force_latin) {
1507 force_primary_latin = TRUE;
1510 if (keyboard_state->prefer_latin) {
1511 force_primary_latin = TRUE;
1518 if (force_primary_latin) {
1519 /* If there is enabled latin-based language, select it */
1520 sclboolean selected = FALSE;
1521 for (scluint loop = 0;!selected && loop < _language_manager.get_languages_num();loop++) {
1522 LANGUAGE_INFO *info = _language_manager.get_language_info(loop);
1524 if (info->enabled && info->is_latin_language) {
1525 selected = _language_manager.select_language(info->name.c_str());
1526 if (selected) force_primary_latin = FALSE;
1531 _language_manager.set_language_enabled_temporarily(PRIMARY_LATIN_LANGUAGE, TRUE);
1535 if (reset_inputmode) {
1536 ise_reset_context();
1538 bool filename_layout = false;
1540 /* Turn the shift state off if we need to reset our input mode, only when auto-capitalization is not set */
1541 if (!(keyboard_state->caps_mode)) {
1542 ui->set_shift_state(SCL_SHIFT_STATE_OFF);
1544 if (keyboard_state->layout < ISE_LAYOUT_STYLE_MAX) {
1545 sclu32 layout_index = keyboard_state->layout;
1546 if (keyboard_state->layout == ISE_LAYOUT_STYLE_NUMBERONLY &&
1547 keyboard_state->layout_variation > 0 &&
1548 keyboard_state->layout_variation < ISE_LAYOUT_NUMBERONLY_VARIATION_MAX) {
1549 layout_index = ISE_LAYOUT_STYLE_NUMBERONLY_SIG + keyboard_state->layout_variation - 1;
1550 } else if (keyboard_state->layout == ISE_LAYOUT_STYLE_PASSWORD && keyboard_state->layout_variation > 0) {
1551 layout_index = ISE_LAYOUT_STYLE_PASSWD_3X4;
1554 if (keyboard_state->layout == ISE_LAYOUT_STYLE_NORMAL &&
1555 keyboard_state->layout_variation == ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL_VARIATION_FILENAME)
1556 filename_layout = true;
1558 filename_layout = false;
1560 ui->enable_button("exclamation", !filename_layout);
1561 ui->enable_button("question", !filename_layout);
1562 ui->enable_button("divide", !filename_layout);
1563 ui->enable_button("multiply", !filename_layout);
1564 ui->enable_button("colon", !filename_layout);
1565 ui->enable_button("quotation", !filename_layout);
1567 ui->enable_button("CM_KEY", !access("/home", X_OK));
1569 LOGD("new layout index : %d\n", layout_index);
1570 /* If this layout requires specific input mode, set it */
1571 if (strlen(g_ise_default_values[layout_index].input_mode) > 0) {
1572 ui->set_input_mode(g_ise_default_values[layout_index].input_mode);
1573 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
1575 if (force_primary_latin) {
1576 _language_manager.select_language(PRIMARY_LATIN_LANGUAGE, TRUE);
1577 } else if (config_values) {
1578 if (!(_language_manager.select_language(config_values->selected_language.c_str()))) {
1579 _language_manager.select_language(PRIMARY_LATIN_LANGUAGE);
1583 ui->set_cur_sublayout(g_ise_default_values[layout_index].sublayout_name);
1584 if (ise_emoticon_is_show()) {
1585 ise_emoticon_destroy_layout();
1588 if (keyboard_state->layout == ISE_LAYOUT_STYLE_EMOTICON) {
1589 ise_emoticon_init_list();
1591 ise_emoticon_set_current_group(EMOTICON_GROUP_1);
1592 ise_set_emoticon_label(1);
1594 if (ise_emoticon_get_recent_list_size() == 0)
1595 ise_emoticon_set_current_group(EMOTICON_GROUP_1);
1597 ise_emoticon_set_current_group(EMOTICON_GROUP_RECENTLY_USED);
1599 SCLRotation rotation = ui->get_rotation();
1600 ise_emoticon_show_layout(ise_emoticon_get_current_group(), ROTATION_TO_DEGREE(rotation), false, ime_get_main_window());
1603 if (ise_sticker_is_show())
1604 ise_sticker_destroy_layout();
1606 if (ise_nmt_is_show())
1607 ise_nmt_destroy_layout();
1612 if (info->accepts_caps_mode) {
1613 // FIXME this if condition means the AC is off
1614 if (keyboard_state->layout != ISE_LAYOUT_STYLE_NORMAL) {
1615 ui->set_autocapital_shift_state(TRUE);
1616 ui->set_shift_state(SCL_SHIFT_STATE_OFF);
1618 ise_send_event(MVK_Shift_Enable, KEY_MASK_NULL);
1619 // Auto Capital is supported only in normal layout
1620 if (keyboard_state->caps_mode) {
1621 ui->set_autocapital_shift_state(FALSE);
1625 ui->set_autocapital_shift_state(TRUE);
1626 ise_send_event(MVK_Shift_Disable, KEY_MASK_NULL);
1627 ui->set_shift_state(SCL_SHIFT_STATE_OFF);
1630 ui->set_autocapital_shift_state(TRUE);
1633 // Update CM key button
1634 if (_current_cm_key_id < CM_KEY_LIST_SIZE) {
1635 if (strcmp(_cm_key_list[_current_cm_key_id], USER_KEYSTRING_EMOTICON) == 0) {
1636 if (ise_is_emoticons_disabled())
1637 ise_set_cm_private_key(ise_get_cm_key_id(USER_KEYSTRING_OPTION));
1639 ise_set_cm_private_key(_current_cm_key_id);
1643 // Update space key button
1644 ise_update_space_key();
1647 ui->disable_input_events(FALSE);
1649 ui->enable_button("CM_KEY", false);
1652 #if defined(_MOBILE) || defined(_COMMON)
1653 if (ise_is_guideline_popup_enable_layout()) {
1654 if ((config_values && config_values->first_guidechange) && (_language_manager.get_enabled_languages_num() > 1)) {
1655 ise_show_help_popup(MVK_space, NATIVE_WINDOW_CAST(ime_get_main_window()));
1656 LOGD("space popup show\n");
1658 ise_destroy_popup_space();
1664 if (config_values && config_values->floating_mode != g_floating_mode)
1665 g_floating_mode = config_values->floating_mode;
1667 Candidate *candidate = get_candidate();
1668 if (candidate && candidate->get_visible())
1669 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
1671 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
1674 keyboard_state->visible_state = TRUE;
1678 switch (_context_layout) {
1679 case ISE_LAYOUT_STYLE_PHONENUMBER:
1680 case ISE_LAYOUT_STYLE_IP:
1681 case ISE_LAYOUT_STYLE_MONTH:
1682 case ISE_LAYOUT_STYLE_NUMBERONLY:
1683 case ISE_LAYOUT_STYLE_DATETIME:
1684 case ISE_LAYOUT_STYLE_TERMINAL:
1687 case ISE_LAYOUT_STYLE_EMAIL:
1688 case ISE_LAYOUT_STYLE_URL:
1691 case ISE_LAYOUT_STYLE_PASSWORD:
1692 if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD &&
1693 _context_layout_variation == ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD_VARIATION_NUMBERONLY)
1706 ui->get_screen_resolution(&width, &height);
1708 create_indicator_window(width, height);
1709 destroy_indicator_dots();
1712 switch (keyboard_state->layout) {
1713 case ISE_LAYOUT_STYLE_NUMBER:
1716 case ISE_LAYOUT_STYLE_HEX:
1719 case ISE_LAYOUT_STYLE_EMOTICON:
1722 case ISE_LAYOUT_STYLE_VOICE:
1723 if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
1724 _context_layout == ISE_LAYOUT_STYLE_URL)
1733 create_indicator_dots(dot_num, focus_dot);
1734 show_indicator_window();
1736 hide_indicator_window();
1738 if (keyboard_state->layout == ISE_LAYOUT_STYLE_NORMAL && config_values && config_values->number_tutorial_enable) {
1739 ise_show_tutorial_mode_popup(keyboard_state->layout);
1740 config_values->number_tutorial_enable = false;
1741 write_ise_config_values();
1745 if (get_setting_window_open_status()) {
1746 ise_show_stt_mode(NATIVE_WINDOW_CAST(ime_get_main_window()));
1748 set_setting_window_open_status(FALSE);
1750 if (keyboard_state->layout == ISE_LAYOUT_STYLE_VOICE) {
1751 ise_show_stt_mode(NATIVE_WINDOW_CAST(ime_get_main_window()));
1756 * Sets screen rotation
1759 ise_set_screen_rotation(int degree)
1761 CSCLUI *ui = get_ui();
1763 ui->set_rotation(DEGREE_TO_SCLROTATION(degree));
1766 Candidate *candidate = get_candidate();
1768 candidate->rotate(degree);
1769 if (candidate->get_visible()) {
1770 candidate->update(g_softcandidate_string);
1776 ise_set_accessibility_state(bool state)
1778 CSCLUI *ui = get_ui();
1780 ui->enable_tts(state);
1787 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
1788 CSCLUI *ui = get_ui();
1790 /* There's no need to update screen when hiding */
1791 ui->set_update_pending(TRUE);
1792 ui->disable_input_events(TRUE);
1795 CONFIG_VALUES *config_values = get_config_values();
1796 if (config_values) {
1797 _language_manager.reset_language(config_values->selected_language.c_str());
1801 delete_commit_timer();
1802 ise_destroy_popup_space();
1803 ise_destroy_popup_setting();
1805 if (keyboard_state) keyboard_state->visible_state = FALSE;
1807 _reset_shift_state();
1808 _reset_multitap_state(true);
1810 /* If we were in STT mode, try to reset input mode on our next show event */
1811 if (ui && keyboard_state) {
1812 const char *inputmode = ui->get_input_mode();
1813 if (inputmode && strcmp(inputmode, "STT_3X4") == 0 ) {
1814 keyboard_state->need_reset = TRUE;
1815 ise_hide_stt_mode();
1819 g_input_panel_show = false;
1820 Candidate *candidate = get_candidate();
1821 if (candidate && candidate->get_visible())
1822 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
1824 hide_indicator_window();
1825 if (check_is_tutorial_show()) {
1826 ise_destroy_tutorial_mode_popup();
1829 #if EXIT_ISE_ON_HIDE
1830 if (exit_timer) ecore_timer_del(exit_timer);
1831 exit_timer = ecore_timer_add(1.0, exit_timer_cb, NULL);
1835 static void ise_keypad_mode_changed_cb(const char *key, void *user_data)
1837 read_ise_keypad_mode();
1840 static void ise_enabled_languages_changed_cb(const char *key, void *user_data)
1842 read_ise_enabled_languages();
1845 static void ise_selected_language_changed_cb(const char *key, void *user_data)
1847 read_ise_selected_language();
1850 static void ise_autocapital_mode_changed_cb(const char *key, void *user_data)
1852 read_ise_autocapital_mode();
1855 static void ise_autopunctuate_mode_changed_cb(const char *key, void *user_data)
1857 read_ise_autopunctuation_mode();
1860 static void ise_sound_mode_changed_cb(const char *key, void *user_data)
1862 read_ise_sound_mode();
1864 CONFIG_VALUES *config_values = get_config_values();
1865 CSCLUI *ui = get_ui();
1866 if (config_values && ui) {
1867 ui->enable_sound(config_values->sound_on);
1871 static void ise_vibration_mode_changed_cb(const char *key, void *user_data)
1873 read_ise_vibration_mode();
1875 CONFIG_VALUES *config_values = get_config_values();
1876 CSCLUI *ui = get_ui();
1877 if (config_values && ui) {
1878 ui->enable_vibration(config_values->vibration_on);
1882 static void ise_character_preview_mode_changed_cb(const char *key, void *user_data)
1884 read_ise_character_preview_mode();
1886 CONFIG_VALUES *config_values = get_config_values();
1887 CSCLUI *ui = get_ui();
1888 if (config_values && ui) {
1889 ui->enable_magnifier(config_values->preview_on);
1893 static void ise_setting_guide_popup_changed_cb(const char *key, void *user_data)
1895 read_ise_setting_guide_popup_mode();
1898 static void ise_language_guide_popup_changed_cb(const char *key, void *user_data)
1900 read_ise_language_guide_popup_mode();
1903 static void ise_floating_mode_changed_cb(const char *key, void *user_data)
1905 read_ise_floating_mode();
1906 CONFIG_VALUES *config_values = get_config_values();
1907 if (config_values) {
1908 g_floating_mode = config_values->floating_mode;
1911 ime_set_floating_mode(g_floating_mode);
1912 if (g_candidate && g_floating_mode != g_candidate->get_floating_mode()) {
1913 delete_softcandidate_hide_timer();
1917 create_softcandidate();
1918 if (g_candidate && g_candidate->get_visible()) {
1919 g_candidate->show();
1920 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
1924 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
1927 static void register_preference_changed_callback(void)
1929 if (preference_set_changed_cb(ISE_CONFIG_KEYPAD_MODE, ise_keypad_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1930 LOGW("Failed to set ise_keypad_mode_changed_cb()");
1932 if (preference_set_changed_cb(ISE_CONFIG_ENABLED_LANGUAGES, ise_enabled_languages_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1933 LOGW("Failed to set ise_enabled_languages_changed_cb()");
1935 if (preference_set_changed_cb(ISE_CONFIG_SELECTED_LANGUAGE, ise_selected_language_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1936 LOGW("Failed to set ise_selected_language_changed_cb()");
1938 if (preference_set_changed_cb(ISE_CONFIG_AUTO_CAPITALISE, ise_autocapital_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1939 LOGW("Failed to set ise_autocapital_mode_changed_cb()");
1941 if (preference_set_changed_cb(ISE_CONFIG_AUTO_PUNCTUATE, ise_autopunctuate_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1942 LOGW("Failed to set ise_autopunctuate_mode_changed_cb()");
1944 if (preference_set_changed_cb(ISE_CONFIG_SOUND_ON, ise_sound_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1945 LOGW("Failed to set ise_sound_mode_changed_cb()");
1947 if (preference_set_changed_cb(ISE_CONFIG_VIBRATION_ON, ise_vibration_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1948 LOGW("Failed to set ise_vibration_mode_changed_cb()");
1950 if (preference_set_changed_cb(ISE_CONFIG_PREVIEW_ON, ise_character_preview_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1951 LOGW("Failed to set ise_character_preview_mode_changed_cb()");
1953 if (preference_set_changed_cb(ISE_CONFIG_FIRST_GUIDELINE_POPUP_FOR_SETTING, ise_setting_guide_popup_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1954 LOGW("Failed to set ise_setting_guide_popup_changed_cb()");
1956 if (preference_set_changed_cb(ISE_CONFIG_FIRST_GUIDELINE_POPUP_FOR_LANGUAGE_CHANGE, ise_language_guide_popup_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1957 LOGW("Failed to set ise_language_guide_popup_changed_cb()");
1959 if (preference_set_changed_cb(ISE_CONFIG_FLOATING_MODE, ise_floating_mode_changed_cb, NULL) != PREFERENCE_ERROR_NONE)
1960 LOGW("Failed to set ise_floating_mode_changed_cb()");
1963 static void ise_mount_changed_cb(void *user_data)
1965 register_preference_changed_callback();
1973 CONFIG_VALUES *config_values = get_config_values();
1979 bindtextdomain(PACKAGE, LOCALEDIR);
1980 textdomain(PACKAGE);
1982 /* Set scl_parser_type
1983 * default type is text xml
1984 * use command: export sclres_type="sclres_binary" to enable use binary resource
1985 * please make sure there is sclresource.bin in resource folder
1986 * Or you can use `xml2binary $resource_dir` to generate the sclresource.bin
1987 * xml2binary is in the libscl-ui-devel package
1989 SCLParserType scl_parser_type = SCL_PARSER_TYPE_XML;
1990 char* sclres_type = getenv("sclres_type");
1991 if (sclres_type != NULL && 0 == strcmp("sclres_binary", sclres_type)) {
1992 scl_parser_type = SCL_PARSER_TYPE_BINARY_XML;
1994 scl_parser_type = SCL_PARSER_TYPE_XML;
1998 if (ime_get_main_window()) {
1999 g_ise_created = true;
2001 sclboolean succeeded = FALSE;
2003 const sclchar *entry_path = MAIN_ENTRY_XML_PATH;
2004 _language_manager.set_resource_file_path(entry_path);
2005 const sclchar *resource_file_path = _language_manager.get_resource_file_path();
2007 if (resource_file_path) {
2008 if (strlen(resource_file_path) > 0) {
2009 succeeded = g_ui->init(ime_get_main_window(), scl_parser_type, resource_file_path);
2013 g_ui->init(ime_get_main_window(), scl_parser_type, MAIN_ENTRY_XML_PATH);
2016 g_ui->set_longkey_duration(elm_config_longpress_timeout_get() * 1000);
2018 /* Default ISE callback */
2019 g_ui->set_ui_event_callback(&callback);
2021 /* Accumulated customized ISE callbacks, depending on the input modes */
2022 for (scluint loop = 0;loop < _language_manager.get_languages_num();loop++) {
2023 LANGUAGE_INFO *language = _language_manager.get_language_info(loop);
2025 for (scluint inner_loop = 0;inner_loop < language->input_modes.size();inner_loop++) {
2026 INPUT_MODE_INFO &info = language->input_modes.at(inner_loop);
2027 LOGD("Registering callback for input mode %s : %p\n", info.name.c_str(), language->callback);
2028 g_ui->set_ui_event_callback(language->callback, info.name.c_str());
2033 read_ise_config_values();
2034 if (access(ISE_CONFIG_FILE_PATH, F_OK) == 0 && !config_values->init_flag)
2035 read_ise_config_file();
2037 if (config_values) {
2038 _language_manager.set_enabled_languages(config_values->enabled_languages);
2039 _language_manager.select_language(config_values->selected_language.c_str());
2040 vconf_set_bool(VCONFKEY_AUTOCAPITAL_ALLOW_BOOL, config_values->auto_capitalise);
2041 vconf_set_bool(VCONFKEY_AUTOPERIOD_ALLOW_BOOL, config_values->auto_punctuate);
2042 g_ui->enable_sound(config_values->sound_on);
2043 g_ui->enable_vibration(config_values->vibration_on);
2044 g_ui->enable_magnifier(config_values->preview_on);
2045 g_floating_mode = config_values->floating_mode;
2048 g_ui->enable_highlight_ui(TRUE);
2050 ime_set_floating_mode(g_floating_mode);
2053 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_NONE);
2057 preference_is_existing(ISE_CONFIG_KEYPAD_MODE, &exist);
2059 write_ise_config_values();
2062 if (ode_internal_encryption_get_state(&state) == ODE_ERROR_NONE) {
2063 if (state == ODE_STATE_ENCRYPTED) {
2064 if (ode_internal_encryption_set_mount_event_cb(ise_mount_changed_cb, NULL) != ODE_ERROR_NONE)
2065 LOGW("Failed to set mount_event_cb()");
2066 } else if (state == ODE_STATE_UNENCRYPTED) {
2067 register_preference_changed_callback();
2070 LOGW("Failed to get encryption_state");
2073 init_recent_used_punctuation();
2079 ise_hide_stt_mode();
2081 CSCLUI *ui = get_ui();
2083 LOGD("calling ui->fini()\n");
2085 LOGD("deleting ui\n");
2097 destroy_indicator_window();
2100 /* This is necessary. If this is not called, 3rd party IME might have auto period input regardless its settings */
2101 vconf_set_bool(VCONFKEY_AUTOPERIOD_ALLOW_BOOL, false);
2103 #if EXIT_ISE_ON_HIDE
2104 if (exit_timer) ecore_timer_del(exit_timer);
2110 ise_app_candidate_show()
2116 if (!g_candidate->get_visible())
2120 delete_softcandidate_hide_timer();
2122 create_softcandidate();
2124 Candidate *candidate = get_candidate();
2127 set_ime_size(g_floating_mode, ISE_CANDIDATE_REQ_SHOW);
2132 ise_app_candidate_hide()
2136 Candidate *candidate = get_candidate();
2137 if (!candidate || !candidate->get_visible()) {
2138 LOGD("No candidate\n");
2142 if (g_ic_smartreply != -1 || ime_autofill_get_exist())
2145 add_softcandidate_hide_timer();
2149 void ise_check_wearable_candidate()
2151 CONFIG_VALUES *config_values = get_config_values();
2152 if (!config_values) return;
2154 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2155 if (!keyboard_state) return;
2157 if (!config_values->prediction_on) {
2158 ise_app_candidate_hide();
2159 } else if (keyboard_state->layout == ISE_LAYOUT_STYLE_PHONENUMBER ||
2160 keyboard_state->layout == ISE_LAYOUT_STYLE_VOICE ||
2161 keyboard_state->layout == ISE_LAYOUT_STYLE_IP ||
2162 keyboard_state->layout == ISE_LAYOUT_STYLE_MONTH ||
2163 keyboard_state->layout == ISE_LAYOUT_STYLE_NUMBERONLY ||
2164 keyboard_state->layout == ISE_LAYOUT_STYLE_PASSWD_3X4||
2165 keyboard_state->layout == ISE_LAYOUT_STYLE_PASSWORD) {
2166 ise_app_candidate_hide();
2168 ise_app_candidate_show();
2172 void ise_set_emoticon_label(int group_id)
2174 const int BUF_LEN = 16;
2175 char buf[BUF_LEN] = {0};
2176 snprintf(buf, BUF_LEN, "%d/3", group_id);
2177 CSCLUI *ui = get_ui();
2178 if (ui) ui->set_private_key("EMOTICON_GROUP_ID", buf, NULL, NULL, 0, const_cast<sclchar*>("EMOTICON_GROUP_NEXT"), TRUE);
2182 // when it is the time to auto_cap, the
2183 // ise_set_caps_mode is called.
2184 // -------------------------------------------------------
2185 // For example: [How are you. Fine.], the
2186 // auto-capital process is as below:
2187 // Note: "["<--this is the beginning,
2188 // "|"<--this is the cursor position
2189 // 1) call ise_set_caps_mode, auto_cap = on
2192 // 2) call ise_set_caps_mode, auto_cap = off
2195 // 3) input: "w are you. "
2196 // result: [How are you. |
2197 // 4) call ise_set_caps_mode, auto_cap = on
2199 // result: [How are you. F
2201 // result: [How are you. Fine.|
2202 // --------------------------------------------------------
2203 // If we want to change the auto_cap, eg,
2204 // if we want to input [How Are you.]
2205 // Note the "Are" is not use auto-capital rule.
2207 // ise_send_event(MVK_Shift_On, SclCoreKeyMask_Null);
2208 // when we are want to input "A"
2209 // following input still has the auto_cap rule.
2211 ise_set_caps_mode(unsigned int mode)
2213 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2214 if (!keyboard_state) return;
2216 LOGD("caps_mode : %d\n", mode);
2218 keyboard_state->caps_mode = TRUE;
2220 keyboard_state->caps_mode = FALSE;
2222 g_caps_mode_pending = false;
2223 const sclchar *cur_lang = _language_manager.get_current_language();
2225 LANGUAGE_INFO *info = _language_manager.get_language_info(cur_lang);
2227 if (info->accepts_caps_mode) {
2228 /* If we are inputting multitap character, do not manipulate shift mode */
2229 if (keyboard_state->prev_modifier != KEY_MODIFIER_MULTITAP_START &&
2230 keyboard_state->prev_modifier != KEY_MODIFIER_MULTITAP_REPEAT) {
2231 set_caps_mode(keyboard_state->caps_mode);
2233 g_caps_mode_pending = true;
2234 LOGD("Currently composing multitap string, skipping caps request");
2242 ise_update_cursor_position(int position)
2244 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2245 if (!keyboard_state) return;
2247 LOGD("cursor position : %d\n", position);
2248 CSCLUI *ui = get_ui();
2249 if (ui && keyboard_state->layout == ISE_LAYOUT_STYLE_URL) {
2252 ui->set_string_substitution("www.", ".com");
2254 ui->unset_string_substitution("www.");
2260 void ise_set_return_key_type(unsigned int type)
2262 const int BUF_LEN = 256;
2263 char buf[BUF_LEN] = {0};
2265 CSCLUI *ui = get_ui();
2268 LOGD("return key type : %d\n", type);
2271 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE:
2272 snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_DONE);
2274 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_GO:
2275 snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_GO);
2277 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_JOIN:
2278 snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_JOIN);
2280 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_LOGIN:
2281 snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_LOGIN);
2283 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_NEXT:
2284 snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_NEXT);
2286 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEARCH:
2287 snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_SEARCH);
2289 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEND:
2290 snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_SEND);
2292 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SIGNIN:
2293 snprintf(buf, BUF_LEN, ISE_RETURN_KEY_LABEL_SIGNIN);
2295 case ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT:
2298 LOGW("Unknown return key type : %d\n", type);
2299 type = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT;
2303 if (type == ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT) {
2304 ui->unset_private_key("Enter");
2306 ui->unset_private_key("Done");
2310 if (type == ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_SEARCH) {
2311 sclchar* imagelabel[SCL_BUTTON_STATE_MAX] = {
2312 const_cast<sclchar*>("w_sip_3x4_btn_ic_search.png"),
2313 const_cast<sclchar*>("w_sip_3x4_btn_ic_search_p.png"),
2314 const_cast<sclchar*>("w_sip_3x4_btn_ic_search_d.png")};
2315 ui->set_private_key("Enter", const_cast<sclchar*>(""), imagelabel, NULL, 0, const_cast<sclchar*>("Enter"), TRUE);
2321 ui->set_private_key("Done", buf, NULL, NULL, 0, const_cast<sclchar*>("Done"), TRUE);
2323 static sclchar *imagelabel[SCL_BUTTON_STATE_MAX] = {
2324 const_cast<sclchar*>(" "), const_cast<sclchar*>(" "), const_cast<sclchar*>(" ")
2327 ui->set_private_key("Enter", buf, imagelabel, NULL, 0, const_cast<sclchar*>("Enter"), TRUE);
2329 LOGD("return key label : %s\n", buf);
2333 void ise_set_return_key_disable(unsigned int disabled)
2335 CSCLUI *ui = get_ui();
2336 LOGD("enable : %d\n", !disabled);
2339 ui->enable_button("Done", !disabled);
2342 ui->enable_button("Enter", !disabled);
2346 void ise_get_language_locale(char **locale)
2348 LANGUAGE_INFO *info = _language_manager.get_current_language_info();
2350 if (!(info->locale_string.empty())) {
2351 *locale = strdup(info->locale_string.c_str());
2356 void ise_update_table(const vector<string> &vec_str)
2358 Candidate *candidate = get_candidate();
2359 if (!candidate || !candidate->get_visible()) {
2360 create_softcandidate();
2363 candidate = get_candidate();
2365 candidate->update(vec_str);
2369 void ise_process_key_event(scim::KeyEvent& key, sclu32 &ret)
2371 Eina_Bool back_key_pressed = EINA_FALSE;
2372 Eina_Bool back_key_released = EINA_FALSE;
2374 if (key.get_key_string().compare("XF86Back") == 0) {
2375 back_key_pressed = EINA_TRUE;
2376 } else if (key.get_key_string().compare("KeyRelease+XF86Back") == 0) {
2377 back_key_released = EINA_TRUE;
2380 if (back_key_pressed || back_key_released) {
2381 if (g_popup_opened == TRUE) {
2382 if (back_key_released) {
2383 CSCLUI *ui = get_ui();
2384 if (ui) ui->close_all_popups();
2392 CSCLUI *ui = get_ui();
2394 Candidate *candidate = get_candidate();
2396 if (!candidate->soft_candidate_flag()) {
2398 if (key.dev_name.compare("ime") != 0) {
2399 ret = (sclu32)ui->process_key_event(key.get_key_string().c_str());
2404 ret = candidate->soft_candidate_handle_key_event(key.get_key_string().c_str());
2408 /* Process this key event if it was not generated by ime */
2409 if (key.dev_name.compare("ime") != 0) {
2410 ret = (sclu32)ui->process_key_event(key.get_key_string().c_str());
2416 /* Process this key event if it was not generated by ime */
2417 if (key.dev_name.compare("ime") != 0) {
2418 ret = (sclu32)ui->process_key_event(key.get_key_string().c_str());
2424 static void init_recent_used_punctuation()
2426 if (g_recent_used_punctuation.empty())
2428 g_recent_used_punctuation.push_back("#");
2429 g_recent_used_punctuation.push_back("$");
2430 g_recent_used_punctuation.push_back("%");
2431 g_recent_used_punctuation.push_back("^");
2432 g_recent_used_punctuation.push_back("&");
2436 static void update_recent_used_punctuation(const char * key_value)
2438 if (NULL == key_value)
2442 for (int i = 0; i < 10; ++i)
2445 snprintf(buf, sizeof(buf), "%d", i);
2446 if (strcmp(key_value, buf) == 0)
2451 string strKey = string(key_value);
2452 for (int i = 0; i < MAX_DEFAULT_PUNCTUATION; ++i)
2454 if (0 == strKey.compare(g_default_punctuation[i].c_str()))
2459 vector<string>::iterator iter = g_recent_used_punctuation.begin();
2460 for (; iter != g_recent_used_punctuation.end(); ++iter)
2462 if (0 == strKey.compare(iter->c_str()))
2467 if (iter != g_recent_used_punctuation.end())
2469 g_recent_used_punctuation.erase(iter);
2471 g_recent_used_punctuation.push_back(strKey);
2472 if (g_recent_used_punctuation.size() > MAX_DEFAULT_PUNCTUATION-1)
2474 g_recent_used_punctuation.erase(g_recent_used_punctuation.begin());
2478 static void set_ime_size(bool floating_mode, ISE_CANDIDATE_REQUEST candidate_req)
2480 CSCLUI *ui = get_ui();
2484 Candidate *candidate = get_candidate();
2486 const char *input_mode = ui->get_input_mode();
2490 SclSize size_portrait = ui->get_input_mode_size(input_mode, DISPLAYMODE_PORTRAIT);
2491 SclSize size_landscape = ui->get_input_mode_size(input_mode, DISPLAYMODE_LANDSCAPE);
2493 if (floating_mode) {
2494 size_portrait.width *= FLOATING_SCALE_RATE;
2495 size_portrait.height *= FLOATING_SCALE_RATE;
2496 size_landscape.width *= FLOATING_SCALE_RATE;
2497 size_landscape.height *= FLOATING_SCALE_RATE;
2498 switch (candidate_req) {
2499 case ISE_CANDIDATE_REQ_NONE:
2500 if (candidate && candidate->get_visible()) {
2501 ui->set_custom_starting_coordinates(0, FLOATING_TITLE_BAR_HEIGHT + candidate->get_height());
2502 size_portrait.height += candidate->get_height();
2503 size_landscape.height += candidate->get_height();
2505 ui->set_custom_starting_coordinates(0, FLOATING_TITLE_BAR_HEIGHT);
2508 case ISE_CANDIDATE_REQ_SHOW:
2510 ui->set_custom_starting_coordinates(0, FLOATING_TITLE_BAR_HEIGHT + candidate->get_height());
2511 if (g_input_panel_show || g_candidate_more_view) {
2512 size_portrait.height += candidate->get_height();
2513 size_landscape.height += candidate->get_height();
2515 size_portrait.height = candidate->get_height();
2516 size_landscape.height = candidate->get_height();
2520 case ISE_CANDIDATE_REQ_HIDE:
2521 ui->set_custom_starting_coordinates(0, FLOATING_TITLE_BAR_HEIGHT);
2526 if (ui->get_custom_scale_rate_x() != FLOATING_SCALE_RATE || ui->get_custom_scale_rate_y() != FLOATING_SCALE_RATE)
2527 ui->set_custom_scale_rate(FLOATING_SCALE_RATE, FLOATING_SCALE_RATE);
2529 ime_set_size(size_portrait.width, size_portrait.height + FLOATING_TITLE_BAR_HEIGHT,
2530 size_landscape.width, size_landscape.height + FLOATING_TITLE_BAR_HEIGHT);
2532 #if defined(_MOBILE) || defined(_COMMON)
2533 ise_destroy_move_handler();
2534 int rotation = elm_win_rotation_get(NATIVE_WINDOW_CAST(ime_get_main_window()));
2535 int handler_width = (rotation == 0 || rotation == 180) ? size_portrait.width : size_landscape.width;
2536 ise_show_move_handler(handler_width, FLOATING_TITLE_BAR_HEIGHT);
2539 switch (candidate_req) {
2540 case ISE_CANDIDATE_REQ_NONE:
2541 if (candidate && candidate->get_visible()) {
2542 ui->set_custom_starting_coordinates(0, candidate->get_height());
2543 size_portrait.height += candidate->get_height();
2544 size_landscape.height += candidate->get_height();
2546 ui->set_custom_starting_coordinates(0, 0);
2549 case ISE_CANDIDATE_REQ_SHOW:
2551 ui->set_custom_starting_coordinates(0, candidate->get_height());
2552 if (g_input_panel_show || g_candidate_more_view) {
2553 size_portrait.height += candidate->get_height();
2554 size_landscape.height += candidate->get_height();
2556 size_portrait.height = candidate->get_height();
2557 size_landscape.height = candidate->get_height();
2561 case ISE_CANDIDATE_REQ_HIDE:
2562 ui->set_custom_starting_coordinates(0, 0);
2567 if (ui->get_custom_scale_rate_x() != 1.0 || ui->get_custom_scale_rate_y() != 1.0)
2568 ui->set_custom_scale_rate(1.0, 1.0);
2570 ime_set_size(size_portrait.width, size_portrait.height, size_landscape.width, size_landscape.height);
2572 #if defined(_MOBILE) || defined(_COMMON)
2573 ise_destroy_move_handler();
2578 static void ime_app_create_cb(void *user_data)
2580 if (!engine_loader_dbus_init(NULL))
2581 LOGE("Failed to initialize dbus");
2583 #if !(DEFER_ISE_CREATION)
2586 elm_app_name_set(PACKAGE);
2588 char *elm_scale = getenv("ELM_SCALE");
2589 LOGD("ELM_SCALE : %s", elm_scale);
2592 elm_app_base_scale_set(atof(elm_scale));
2599 static void ime_app_exit_cb(void *user_data)
2604 if (!engine_loader_dbus_shutdown())
2605 LOGE("Failed to finalize dbus");
2607 clipboard_shutdown();
2612 static void show_autofill_data()
2614 ime_autofill_set_exist(false);
2615 string autofill_string = ime_autofill_get_string();
2617 SECURE_LOGD("autofill string : %s", autofill_string.c_str());
2619 if (!autofill_string.empty()) {
2620 ime_autofill_set_exist(true);
2622 ise_app_candidate_show();
2623 update_candidate_table();
2627 static void ime_app_show_cb(int ic, ime_context_h ime_ctx, void *user_data)
2629 Ise_Context iseContext;
2630 bool return_key_state, prediction_allow, password_mode, caps_mode;
2631 ime_layout_variation_e layout_variation;
2636 ime_context_get_layout(ime_ctx, &iseContext.layout);
2638 ime_context_get_layout_variation(ime_ctx, &layout_variation);
2639 iseContext.layout_variation = (int)layout_variation;
2641 ime_context_get_cursor_position(ime_ctx, &iseContext.cursor_pos);
2642 ime_context_get_autocapital_type(ime_ctx, &iseContext.autocapital_type);
2643 ime_context_get_return_key_type(ime_ctx, &iseContext.return_key_type);
2644 ime_context_get_return_key_state(ime_ctx, &return_key_state);
2646 ime_context_get_prediction_mode(ime_ctx, &prediction_allow);
2647 iseContext.prediction_allow = prediction_allow;
2649 ime_context_get_password_mode(ime_ctx, &password_mode);
2650 iseContext.password_mode = password_mode;
2652 ime_context_get_input_hint(ime_ctx, &iseContext.input_hint);
2653 ime_context_get_bidi_direction(ime_ctx, &iseContext.bidi_direction);
2654 ime_context_get_language(ime_ctx, &iseContext.language);
2655 ime_context_get_caps_mode(ime_ctx, &caps_mode);
2656 iseContext.caps_mode = caps_mode;
2658 iseContext.return_key_disabled = return_key_state;
2660 engine_loader_set_input_hint((uint32_t)iseContext.input_hint);
2661 engine_loader_update_bidi_direction((uint32_t)iseContext.bidi_direction);
2665 ime_autofill_set_hint(iseContext.input_hint & ECORE_IMF_INPUT_HINT_AUTOFILL_MASK);
2667 LOGD("input hint : %x, autofill hint : %x\n", iseContext.input_hint, ime_autofill_get_hint());
2669 // show autofill data
2670 show_autofill_data();
2672 //g_ise_common->set_keyboard_ise_by_uuid(KEYBD_ISE_UUID);
2674 /* Don't update screen until all the information is correctly set */
2675 CSCLUI *ui = get_ui();
2677 ui->set_update_pending(TRUE);
2679 ise_reset_context(); // reset ISE
2681 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2683 if (iseContext.language == ECORE_IMF_INPUT_PANEL_LANG_ALPHABET) {
2684 LOGD("prefer latin");
2686 keyboard_state->prefer_latin = TRUE;
2689 LOGD("prefer automatic");
2691 keyboard_state->prefer_latin = FALSE;
2694 _context_layout = iseContext.layout;
2695 _context_layout_variation = iseContext.layout_variation;
2696 ise_set_layout(iseContext.layout, iseContext.layout_variation);
2698 ise_set_return_key_type(iseContext.return_key_type);
2699 ise_set_return_key_disable(iseContext.return_key_disabled);
2701 ise_set_caps_mode(iseContext.caps_mode);
2702 ise_update_cursor_position(iseContext.cursor_pos);
2706 /* Now we update the whole screen */
2708 ui->set_update_pending(FALSE);
2711 static void ime_app_hide_cb(int ic, void *user_data)
2716 clipboard_set_mime_type(false);
2718 g_ic_smartreply = -1;
2721 static void ime_app_return_key_type_set_cb(Ecore_IMF_Input_Panel_Return_Key_Type type, void *user_data)
2723 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2724 if (!keyboard_state) return;
2726 LOGD("return key type : %d\n", type);
2727 ise_set_return_key_type(type);
2729 if (keyboard_state->visible_state)
2730 ise_show(keyboard_state->ic);
2733 static void ime_app_return_key_state_set_cb(bool disabled, void *user_data)
2735 LOGD("return key disabled : %d\n", disabled);
2736 ise_set_return_key_disable(disabled);
2739 static void ime_app_language_set_cb(Ecore_IMF_Input_Panel_Lang language, void *user_data)
2741 LOGD("language : %d\n", language);
2743 // if (language == ECORE_IMF_INPUT_PANEL_LANG_ALPHABET) {
2744 // ise_explictly_set_language(PRIMARY_LATIN_LANGUAGE_INDEX);
2748 static void ime_app_input_context_reset_cb(void *user_data)
2750 ise_reset_input_context();
2751 engine_loader_reset_input_context();
2754 static void ime_app_cursor_position_updated_cb(int cursor_pos, void *user_data)
2756 LOGD("cursor position : %d\n", cursor_pos);
2757 ise_update_cursor_position(cursor_pos);
2758 engine_loader_update_cursor_position(cursor_pos);
2761 static void ime_app_language_requested_cb(void *user_data, char **lang_code)
2763 ise_get_language_locale(lang_code);
2766 static void ime_app_surrounding_text_updated_cb(int context_id, const char *text, int cursor_pos, void *user_data)
2768 SECURE_LOGD("surrounding text:%s, cursor=%d\n", text, cursor_pos);
2769 ime_delete_surrounding_text(-cursor_pos, strlen(text));
2772 static void ime_app_focus_in_cb(int context_id, void *user_data)
2775 ise_focus_in(context_id);
2776 Candidate *candidate = get_candidate();
2777 if (input_smartreply_get_reply_num() == 0) {
2778 if (candidate && candidate->get_visible()) {
2779 ise_app_candidate_hide();
2784 engine_loader_focus_in();
2787 static void ime_app_focus_out_cb(int context_id, void *user_data)
2790 ise_focus_out(context_id);
2792 clipboard_set_mime_type(false);
2793 input_smartreply_deinit();
2794 g_ic_smartreply = -1;
2796 ime_autofill_set_exist(false);
2797 ime_autofill_set_hint(0);
2798 ime_autofill_set_app_id("");
2799 ime_autofill_set_resource_id("");
2801 g_smartreply_strings.clear();
2802 g_lookup_table_strings.clear();
2803 g_softcandidate_string.clear();
2805 engine_loader_focus_out();
2808 static void ime_app_layout_set_cb(Ecore_IMF_Input_Panel_Layout layout, void *user_data)
2810 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2811 if (!keyboard_state) return;
2813 LOGD("layout=%d\n", layout);
2814 /* Check if the layoutIdx is in the valid range */
2815 if (static_cast<int>(layout) < static_cast<int>(ISE_LAYOUT_STYLE_MAX)) {
2816 if (keyboard_state->layout != layout) {
2817 keyboard_state->need_reset = TRUE;
2819 keyboard_state->layout = layout;
2820 _context_layout = layout;
2821 _context_layout_variation = 0;
2823 if (keyboard_state->visible_state)
2824 ise_show(keyboard_state->ic);
2826 engine_loader_set_layout(static_cast<uint32_t>(layout));
2829 static void ime_app_input_hint_set_cb(Ecore_IMF_Input_Hints input_hint, void *user_data)
2831 LOGD("input hint=%u\n", input_hint);
2834 static void ime_app_rotation_degree_changed_cb(int degree, void *user_data)
2836 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2837 if (!keyboard_state) return;
2839 CSCLUI *ui = get_ui();
2840 ise_set_screen_rotation(degree);
2842 LOGD("degree=%d\n", degree);
2843 #if defined(_MOBILE) || defined(_COMMON)
2844 if (ui && g_floating_mode) {
2846 ise_destroy_move_handler();
2847 if (degree == 0 || degree == 180) {
2848 SclSize size_portrait = ui->get_input_mode_size(ui->get_input_mode(), DISPLAYMODE_PORTRAIT);
2849 handler_width = size_portrait.width * FLOATING_SCALE_RATE;
2851 SclSize size_landscape = ui->get_input_mode_size(ui->get_input_mode(), DISPLAYMODE_LANDSCAPE);
2852 handler_width = size_landscape.width * FLOATING_SCALE_RATE;
2854 ise_show_move_handler(handler_width, FLOATING_TITLE_BAR_HEIGHT);
2857 if (ise_emoticon_is_show()) {
2858 ise_emoticon_destroy_layout();
2860 if (keyboard_state->layout == ISE_LAYOUT_STYLE_VOICE) {
2861 ise_hide_stt_mode();
2863 if (keyboard_state->layout == ISE_LAYOUT_STYLE_EMOTICON) {
2864 ise_emoticon_show_layout(ise_emoticon_get_current_group(), degree, false, ime_get_main_window());
2866 const sclchar *input_mode = ui->get_input_mode();
2868 if (!(strcmp(input_mode, "EMOTICON_LAYOUT")))
2869 ise_emoticon_show_layout(ise_emoticon_get_current_group(), degree, false, ime_get_main_window());
2870 else if (!(strcmp(input_mode, "STT_3X4")))
2871 ise_show_stt_mode(NATIVE_WINDOW_CAST(ime_get_main_window()));
2876 static void ime_app_accessibility_state_changed_cb(bool state, void *user_data)
2878 LOGD("state=%d\n", state);
2879 ise_set_accessibility_state(state);
2882 static void ime_app_imdata_set_cb(void *data, unsigned int data_length, void *user_data)
2886 size_t _len = data_length;
2887 set_ise_imdata((sclchar *)data, _len);
2888 engine_loader_set_imdata((const char*)data, (uint32_t)data_length);
2891 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)
2893 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
2894 if (!keyboard_state) return FALSE;
2896 scim::KeyEvent key(keycode, keymask);
2898 char *dev_name = NULL;
2899 Ecore_IMF_Device_Class dev_class;
2900 Ecore_IMF_Device_Subclass dev_subclass;
2902 if (ime_device_info_get_name(dev_info, &dev_name) == IME_ERROR_NONE) {
2903 key.dev_name = dev_name;
2906 if (ime_device_info_get_class(dev_info, &dev_class) == IME_ERROR_NONE) {
2907 key.dev_class = dev_class;
2910 if (ime_device_info_get_subclass(dev_info, &dev_subclass) == IME_ERROR_NONE) {
2911 key.dev_subclass = dev_subclass;
2914 if (keyboard_state->visible_state) {
2915 ise_process_key_event(key, ret);
2917 if (key.code == IME_KEY_space && (key.mask & IME_KEY_MASK_SHIFT)) {
2918 if (key.mask & IME_KEY_MASK_RELEASED) {
2919 if (_language_manager.select_next_language()) {
2920 LANGUAGE_INFO *info = _language_manager.get_language_info(_language_manager.get_current_language());
2922 notification_status_message_post(info->display_name.c_str());
2925 LOGE("Failed to change language");
2941 static void ime_app_process_key_event_with_imengine_cb(scim::KeyEvent &key, uint32_t serial, void *user_data)
2943 LANGUAGE_INFO *info = _language_manager.get_language_info(_language_manager.get_current_language());
2944 if (info && info->need_surrounding_text)
2945 engine_loader_process_key_event(key, serial, true);
2947 engine_loader_process_key_event(key, serial, false);
2950 static void ime_app_caps_mode_changed_cb(int mode, void *user_data)
2952 ise_set_caps_mode(mode);
2955 static void ime_app_candidate_show_cb(int context_id, void *user_data)
2958 ise_check_wearable_candidate();
2960 ise_app_candidate_show();
2964 static void ime_app_candidate_hide_cb(int context_id, void *user_data)
2967 ise_check_wearable_candidate();
2969 ise_app_candidate_hide();
2973 static void ime_app_lookup_table_changed_cb(Eina_List *list, void *user_data)
2975 vector<string> candidate_strings;
2980 g_lookup_table_strings.clear();
2983 EINA_LIST_FOREACH(list, l, data) {
2984 candidate = (char *)data;
2986 g_lookup_table_strings.push_back(string(candidate));
2987 candidate_strings.push_back(string(candidate));
2992 if (input_smartreply_get_reply_num() > 0) {
2993 if (candidate_strings[0] == "#" && candidate_strings[1] == "$") {
2996 ime_get_surrounding_text(0, 0, &text, &cursor);
3005 update_candidate_table();
3009 static sclu32 get_rotate_layout(ime_input_device_rotary_direction_e direction)
3011 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
3012 if (!keyboard_state) return ISE_LAYOUT_STYLE_NORMAL;
3014 sclu32 new_layout = keyboard_state->layout;
3016 if (direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_CLOCKWISE) {
3017 LOGD("CLOCKWISE\n");
3018 switch (keyboard_state->layout) {
3019 case ISE_LAYOUT_STYLE_NORMAL:
3020 case ISE_LAYOUT_STYLE_EMAIL:
3021 case ISE_LAYOUT_STYLE_URL:
3022 case ISE_LAYOUT_STYLE_PASSWORD:
3023 if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD &&
3024 _context_layout_variation == ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD_VARIATION_NUMBERONLY)
3025 ; // PASSWORD NUMBER ONLY, do nothing
3027 new_layout = ISE_LAYOUT_STYLE_NUMBER;
3029 case ISE_LAYOUT_STYLE_NUMBER:
3030 new_layout = ISE_LAYOUT_STYLE_HEX;
3032 case ISE_LAYOUT_STYLE_HEX:
3033 if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
3034 _context_layout == ISE_LAYOUT_STYLE_URL)
3035 new_layout = ISE_LAYOUT_STYLE_VOICE;
3036 else if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD)
3037 new_layout = _context_layout;
3039 new_layout = ISE_LAYOUT_STYLE_EMOTICON;
3041 case ISE_LAYOUT_STYLE_EMOTICON:
3042 if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
3043 _context_layout == ISE_LAYOUT_STYLE_URL ||
3044 _context_layout == ISE_LAYOUT_STYLE_PASSWORD)
3045 new_layout = _context_layout;
3047 new_layout = ISE_LAYOUT_STYLE_VOICE;
3049 case ISE_LAYOUT_STYLE_VOICE:
3050 new_layout = ISE_LAYOUT_STYLE_NORMAL;
3055 } else if (direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_COUNTER_CLOCKWISE) {
3056 LOGD("COUNTER_CLOCKWISE\n");
3057 switch (keyboard_state->layout) {
3058 case ISE_LAYOUT_STYLE_NORMAL:
3059 case ISE_LAYOUT_STYLE_EMAIL:
3060 case ISE_LAYOUT_STYLE_URL:
3061 case ISE_LAYOUT_STYLE_PASSWORD:
3062 if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD &&
3063 _context_layout_variation == ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD_VARIATION_NUMBERONLY)
3064 ; // PASSWORD NUMBER ONLY, do nothing
3065 else if (_context_layout == ISE_LAYOUT_STYLE_PASSWORD)
3066 new_layout = ISE_LAYOUT_STYLE_HEX;
3068 new_layout = ISE_LAYOUT_STYLE_VOICE;
3070 case ISE_LAYOUT_STYLE_NUMBER:
3071 if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
3072 _context_layout == ISE_LAYOUT_STYLE_URL ||
3073 _context_layout == ISE_LAYOUT_STYLE_PASSWORD)
3074 new_layout = _context_layout;
3076 new_layout = ISE_LAYOUT_STYLE_NORMAL;
3078 case ISE_LAYOUT_STYLE_HEX:
3079 new_layout = ISE_LAYOUT_STYLE_NUMBER;
3081 case ISE_LAYOUT_STYLE_EMOTICON:
3082 new_layout = ISE_LAYOUT_STYLE_HEX;
3084 case ISE_LAYOUT_STYLE_VOICE:
3085 if (_context_layout == ISE_LAYOUT_STYLE_EMAIL ||
3086 _context_layout == ISE_LAYOUT_STYLE_URL)
3087 new_layout = ISE_LAYOUT_STYLE_HEX;
3089 new_layout = ISE_LAYOUT_STYLE_EMOTICON;
3099 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)
3101 KEYBOARD_STATE *keyboard_state = get_keyboard_state();
3102 if (!keyboard_state) return;
3103 if (device_type != IME_INPUT_DEVICE_TYPE_ROTARY) return;
3105 ime_input_device_rotary_direction_e direction;
3106 if (IME_ERROR_NONE != ime_input_device_rotary_get_direction(device_event, &direction)) return;
3108 sclu32 new_layout = get_rotate_layout(direction);
3110 CONFIG_VALUES *config_values = get_config_values();
3111 if (check_is_tutorial_show() && config_values) {
3112 read_ise_config_values();
3113 if ((direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_COUNTER_CLOCKWISE && !config_values->number_tutorial_enable && !config_values->symbol_tutorial_enable) ||
3114 (direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_CLOCKWISE && config_values->symbol_tutorial_enable)) {
3115 new_layout = keyboard_state->layout;
3116 } else if (direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_COUNTER_CLOCKWISE && config_values->symbol_tutorial_enable) {
3117 ise_destroy_tutorial_mode_popup();
3118 config_values->symbol_tutorial_enable = false;
3119 write_ise_config_values();
3120 } else if (direction == IME_INPUT_DEVICE_ROTARY_DIRECTION_CLOCKWISE && !config_values->number_tutorial_enable) {
3121 ise_destroy_tutorial_mode_popup();
3122 new_layout = ISE_LAYOUT_STYLE_NUMBER;
3123 if (!config_values->symbol_tutorial_enable) {
3124 ise_show_tutorial_mode_popup(new_layout);
3125 config_values->symbol_tutorial_enable = true;
3126 write_ise_config_values();
3131 if (new_layout != keyboard_state->layout && new_layout < ISE_LAYOUT_STYLE_MAX) {
3132 keyboard_state->need_reset = TRUE;
3133 keyboard_state->layout = new_layout;
3135 if (keyboard_state->visible_state) {
3136 _reset_multitap_state();
3137 if (config_values) {
3138 _language_manager.reset_language(config_values->selected_language.c_str());
3140 ise_show(keyboard_state->ic);
3146 static void ime_app_prediction_hint_set_cb(const char *prediction_hint, void *user_data)
3148 char *sender = (char *)"mms";
3149 char *caller_id = (char *)"mms";
3150 char *hint = (char *)prediction_hint;
3152 if (!prediction_hint) return;
3153 SECURE_LOGD("prediction hint : %s\n", prediction_hint);
3155 if (strlen(prediction_hint) > 0) {
3156 input_smartreply_init(caller_id, sender, hint);
3157 input_smartreply_set_notify(_input_smartreply_notify_cb, NULL);
3159 if (input_smartreply_is_enabled()) {
3160 input_smartreply_get_reply_async();
3165 static void ime_app_mime_type_set_request_cb(const char *mime_types, void *user_data)
3167 LOGD("mime type : %s\n", mime_types);
3169 clipboard_set_mime_type(true);
3170 clipboard_init_sel_type();
3172 string str(mime_types), text_key = "text/", image_key = "image/";
3174 if (str.find(text_key) != string::npos)
3175 clipboard_add_sel_type(CLIPBOARD_SEL_TEXT);
3177 if (str.find(image_key) != string::npos)
3178 clipboard_add_sel_type(CLIPBOARD_SEL_IMAGE);
3181 static void ime_app_prediction_hint_data_set_cb(const char *key, const char *value, void *user_data)
3183 SECURE_LOGD("key : %s, value : %s\n", key, value);
3185 if (string(key) == "appid")
3186 ime_autofill_set_app_id(value);
3187 else if (string(key) == "res_id")
3188 ime_autofill_set_resource_id(value);
3191 static void ime_app_autocapital_type_set_cb(uint32_t type, void *user_data)
3193 LOGD("autocapital type : %u\n", type);
3194 engine_loader_set_autocapital_type(type);
3197 static void ime_app_prediction_allow_set_cb(uint32_t prediction_allow, void *user_data)
3199 LOGD("prediction allow : %u\n", prediction_allow);
3200 engine_loader_set_prediction_allow(prediction_allow);
3203 static void ime_app_trigger_property_set_cb(const char *property, void *user_data)
3205 LOGD("trigger property : %s\n", property);
3206 engine_loader_trigger_property(property);
3209 static void ime_app_candidate_more_window_show_cb(void *user_data)
3212 engine_loader_show_candidate_more_window();
3215 static void ime_app_candidate_more_window_hide_cb(void *user_data)
3218 engine_loader_hide_candidate_more_window();
3221 static void ime_app_aux_select_cb(uint32_t item, void *user_data)
3223 LOGD("aux select : %u\n", item);
3224 engine_loader_select_aux(item);
3227 static void ime_app_candidate_select_cb(uint32_t item, void *user_data)
3229 LOGD("candidate select : %u\n", item);
3230 engine_loader_select_candidate(item);
3233 static void ime_app_candidate_table_page_up_cb(void *user_data)
3236 engine_loader_candidate_table_page_up();
3239 static void ime_app_candidate_table_page_down_cb(void *user_data)
3242 engine_loader_candidate_table_page_down();
3245 static void ime_app_candidate_table_page_size_chaned_cb(uint32_t size, void *user_data)
3247 LOGD("candidate page size : %u\n", size);
3248 engine_loader_change_candidate_page_size(size);
3251 static void ime_app_candidate_item_layout_set_cb(vector<uint32_t> item, void *user_data)
3253 LOGD("item layout size : %zu", item.size());
3254 engine_loader_set_candidate_item_layout(item);
3257 static void ime_app_displayed_candidate_number_chaned_cb(uint32_t page_num, void *user_data)
3259 LOGD("candidate number changed : %u\n", page_num);
3260 engine_loader_change_candidate_number(page_num);
3263 static void ime_app_candidate_item_long_pressed_cb(uint32_t index, void *user_data)
3265 LOGD("candidate item : %u\n", index);
3266 engine_loader_long_press_candidate_item(index);
3272 EXPORTED void ime_app_main(int argc, char **argv)
3274 ime_callback_s basic_callback = {
3281 ime_event_set_focus_in_cb(ime_app_focus_in_cb, NULL);
3282 ime_event_set_focus_out_cb(ime_app_focus_out_cb, NULL);
3283 ime_event_set_rotation_degree_changed_cb(ime_app_rotation_degree_changed_cb, NULL);
3284 ime_event_set_accessibility_state_changed_cb(ime_app_accessibility_state_changed_cb, NULL);
3285 ime_event_set_layout_set_cb(ime_app_layout_set_cb, NULL);
3286 ime_event_set_caps_mode_changed_cb(ime_app_caps_mode_changed_cb, NULL);
3287 ime_event_set_cursor_position_updated_cb(ime_app_cursor_position_updated_cb, NULL);
3288 ime_event_set_surrounding_text_updated_cb(ime_app_surrounding_text_updated_cb, NULL);
3289 ime_event_set_return_key_type_set_cb(ime_app_return_key_type_set_cb, NULL);
3290 ime_event_set_return_key_state_set_cb(ime_app_return_key_state_set_cb, NULL);
3291 ime_event_set_language_set_cb(ime_app_language_set_cb, NULL);
3292 ime_event_set_imdata_set_cb(ime_app_imdata_set_cb, NULL);
3293 ime_event_set_process_key_event_cb(ime_app_process_key_event_cb, NULL);
3294 ime_event_set_process_key_event_with_imengine_cb(ime_app_process_key_event_with_imengine_cb, NULL);
3295 ime_event_set_input_hint_set_cb(ime_app_input_hint_set_cb, NULL);
3297 ime_event_set_candidate_show_cb(ime_app_candidate_show_cb, NULL);
3298 ime_event_set_candidate_hide_cb(ime_app_candidate_hide_cb, NULL);
3299 ime_event_set_lookup_table_changed_cb(ime_app_lookup_table_changed_cb, NULL);
3302 ime_event_set_process_input_device_event_cb(ime_app_process_input_device_event_cb, NULL);
3305 ime_event_set_input_context_reset_cb(ime_app_input_context_reset_cb, NULL);
3306 ime_event_set_language_requested_cb(ime_app_language_requested_cb, NULL);
3308 ime_event_set_prediction_hint_set_cb(ime_app_prediction_hint_set_cb, NULL);
3309 ime_event_set_mime_type_set_request_cb(ime_app_mime_type_set_request_cb, NULL);
3310 ime_event_set_prediction_hint_data_set_cb(ime_app_prediction_hint_data_set_cb, NULL);
3312 ime_event_set_autocapital_type_set_cb(ime_app_autocapital_type_set_cb, NULL);
3313 ime_event_set_prediction_allow_set_cb(ime_app_prediction_allow_set_cb, NULL);
3314 ime_event_set_trigger_property_set_cb(ime_app_trigger_property_set_cb, NULL);
3315 ime_event_set_candidate_more_window_show_cb(ime_app_candidate_more_window_show_cb, NULL);
3316 ime_event_set_candidate_more_window_hide_cb(ime_app_candidate_more_window_hide_cb, NULL);
3317 ime_event_set_aux_select_cb(ime_app_aux_select_cb, NULL);
3318 ime_event_set_candidate_select_cb(ime_app_candidate_select_cb, NULL);
3319 ime_event_set_candidate_table_page_up_cb(ime_app_candidate_table_page_up_cb, NULL);
3320 ime_event_set_candidate_table_page_down_cb(ime_app_candidate_table_page_down_cb, NULL);
3321 ime_event_set_candidate_table_page_size_chaned_cb(ime_app_candidate_table_page_size_chaned_cb, NULL);
3322 ime_event_set_candidate_item_layout_set_cb(ime_app_candidate_item_layout_set_cb, NULL);
3323 ime_event_set_displayed_candidate_number_chaned_cb(ime_app_displayed_candidate_number_chaned_cb, NULL);
3324 ime_event_set_candidate_item_long_pressed_cb(ime_app_candidate_item_long_pressed_cb, NULL);
3326 #if DEFER_ISE_CREATION
3327 ime_set_window_creation_defer_flag(TRUE);
3330 ime_run(&basic_callback, NULL);
3336 EXPORTED int main(int argc, char *argv[])
3338 ime_app_main(argc, argv);