2 * Copyright (c) 2014 - 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.
18 #include "sclconnection-isf.h"
19 #include "sclcoreimpl.h"
20 #include <Elementary.h>
24 #include "legacy_support/websocket.h"
25 extern CWebHelperAgentWebSocket g_websocket;
30 static scim::ConfigPointer _scim_config(0);
32 /* Slot functions for calling appropriate callback functions */
33 static void slot_exit(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
34 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
36 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
38 callback->on_ise_hide(ic, ic_uuid.c_str());
43 agent->update_ise_exit();
50 static void slot_attach_input_context(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
51 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
53 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
55 callback->on_attach_input_context(ic, ic_uuid.c_str());
60 static void slot_detach_input_context(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
61 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
63 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
65 callback->on_detach_input_context(ic, ic_uuid.c_str());
70 static void slot_reload_config(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
71 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
73 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
75 callback->on_reload_config(ic, ic_uuid.c_str());
80 static void slot_update_screen(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, int screen_number) {
81 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
83 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
85 //callback->on_update_screen(ic, ic_uuid.c_str(), screen_number);
90 static void slot_update_spot_location(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, int x, int y) {
91 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
93 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
95 callback->on_update_spot_location(ic, ic_uuid.c_str(), x, y);
100 static void slot_update_cursor_position(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, int cursor_pos) {
101 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
103 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
105 callback->on_update_cursor_position(ic, ic_uuid.c_str(), cursor_pos);
107 g_websocket.on_update_cursor_position(ic, cursor_pos);
113 static void slot_update_surrounding_text(const scim::HelperAgent *agent, int ic, const scim::String &text, int cursor) {
114 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
116 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
118 callback->on_update_surrounding_text(ic, text.c_str(), cursor);
120 g_websocket.on_update_surrounding_text(ic, text.c_str(), cursor);
126 static void slot_trigger_property(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, const scim::String &property) {
127 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
129 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
131 callback->on_trigger_property(property.c_str());
136 static void slot_focus_out(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
137 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
139 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
141 callback->on_focus_out(ic, ic_uuid.c_str());
143 g_websocket.on_focus_out(ic);
149 static void slot_focus_in(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
150 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
152 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
154 callback->on_focus_in(ic, ic_uuid.c_str());
156 g_websocket.on_focus_in(ic);
162 static void slot_ise_show(const scim::HelperAgent *agent, int ic, char *buf, size_t &len) {
163 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
165 /* Make sure the appropriate keyboard ise was selected -> is this really necessary? */
166 //impl->set_keyboard_ise_by_uuid(impl->get_keyboard_ise_uuid().c_str());
168 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
170 /* Check if effect is enabled */
171 Ise_Context ise_context;
172 memset(&ise_context, 0x00, sizeof(ise_context));
174 if (len >= sizeof(Ise_Context)) {
175 memcpy(&ise_context, buf, sizeof(ise_context));
177 if (ise_context.imdata_size > 0) {
178 char imdata[1024] = {0};
179 memcpy((void *)imdata, buf + sizeof(ise_context), ise_context.imdata_size);
180 callback->on_set_imdata(imdata, ise_context.imdata_size);
183 if (len > (sizeof(Ise_Context) + ise_context.imdata_size))
184 callback->on_set_mime_type(buf + sizeof(ise_context) + ise_context.imdata_size);
186 LOGD("\n-=-= WARNING - buf %p len %zu size %zu\n", buf, len, sizeof(ise_context));
188 CSCLCoreUI* ui = impl->get_core_ui();
190 ui->process_keyboard_ui_state_change(KEYBOARD_UI_STATE_WILL_SHOW);
192 callback->on_ise_show(ic, impl->get_screen_rotation_degree(), ise_context);
196 ui->get_keyboard_size(&portrait, &landscape);
197 /* If the ime_set_size() API is not called and IME is shown, the app can not receive the keyboard window's geometry from ISF.
198 And the ime_set_size() API is not called unless the IME size changes.
200 ui->update_keyboard_geometry(portrait, landscape);
201 ui->process_keyboard_ui_state_change(KEYBOARD_UI_STATE_DID_SHOW);
203 LOGW("Failed to get core UI");
206 g_websocket.on_set_layout(ise_context.layout);
207 g_websocket.on_update_cursor_position(ic, ise_context.cursor_pos);
208 g_websocket.on_show(ic);
214 static void slot_ise_hide(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
215 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
217 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
219 CSCLCoreUI* ui = impl->get_core_ui();
221 ui->process_keyboard_ui_state_change(KEYBOARD_UI_STATE_WILL_HIDE);
223 callback->on_ise_hide(ic, ic_uuid.c_str());
225 ui->process_keyboard_ui_state_change(KEYBOARD_UI_STATE_DID_HIDE);
229 g_websocket.on_hide(ic);
235 static void slot_get_geometry(const scim::HelperAgent *agent, struct scim::rectinfo &info) {
236 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
238 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
240 callback->on_get_geometry(&(info.pos_x), &(info.pos_y), &(info.width), &(info.height));
245 static void slot_set_mode(const scim::HelperAgent *agent, scim::uint32 &mode) {
246 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
248 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
250 callback->on_set_mode(mode);
255 static void slot_set_language(const scim::HelperAgent *agent, scim::uint32 &language) {
256 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
258 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
260 callback->on_set_language(language);
262 g_websocket.on_set_language(language);
268 static void slot_set_imdata(const scim::HelperAgent *agent, char *buf, size_t &len) {
269 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
271 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
273 scl32 _len = static_cast<scl32>(reinterpret_cast<size_t>(len) & 0xffffffff);
274 callback->on_set_imdata(buf, _len);
276 g_websocket.on_set_imdata(buf, len);
282 static void slot_get_imdata(const scim::HelperAgent *, char **buf, size_t &len) {
283 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
285 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
288 callback->on_get_imdata(buf, &_len);
290 g_websocket.on_get_imdata(buf, &_len);
297 static void slot_get_language_locale(const scim::HelperAgent *, int ic, char **locale) {
298 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
300 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
302 callback->on_get_language_locale(ic, locale);
307 static void slot_set_return_key_type(const scim::HelperAgent *agent, scim::uint32 &type) {
308 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
310 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
312 callback->on_set_return_key_type(type);
314 g_websocket.on_set_return_key_type(type);
320 static void slot_get_return_key_type(const scim::HelperAgent *agent, scim::uint32 &type) {
321 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
323 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
325 callback->on_get_return_key_type(&type);
327 g_websocket.on_get_return_key_type(&type);
333 static void slot_set_return_key_disable(const scim::HelperAgent *agent, scim::uint32 &disabled) {
334 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
336 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
338 callback->on_set_return_key_disable(disabled);
340 g_websocket.on_set_return_key_disable(disabled);
346 static void slot_get_return_key_disable(const scim::HelperAgent *agent, scim::uint32 &disabled) {
347 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
349 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
351 callback->on_get_return_key_disable(&disabled);
353 g_websocket.on_get_return_key_disable(&disabled);
359 static void slot_set_layout(const scim::HelperAgent *agent, scim::uint32 &layout) {
360 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
362 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
364 callback->on_set_layout(layout);
366 g_websocket.on_set_layout(layout);
372 static void slot_get_layout(const scim::HelperAgent *agent, scim::uint32 &layout) {
373 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
375 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
377 callback->on_get_layout(&layout);
379 g_websocket.on_get_layout(&layout);
385 static void slot_set_caps_mode(const scim::HelperAgent *agent, scim::uint32 &mode) {
386 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
388 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
390 callback->on_set_caps_mode(mode);
395 static void slot_reset_input_context(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
396 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
398 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
400 callback->on_reset_input_context(ic, uuid.c_str());
402 g_websocket.on_reset_input_context(ic);
408 static void slot_update_candidate_geometry(const scim::HelperAgent *agent, int ic, const scim::String &uuid, const scim::rectinfo &info) {
409 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
411 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
413 callback->on_update_candidate_geometry(ic, uuid.c_str(), info.pos_x, info.pos_y, info.width, info.height);
417 static void slot_update_keyboard_ise(const scim::HelperAgent *agent, int ic, const scim::String &uuid,
418 const scim::String &ise_name, const scim::String &ise_uuid) {
419 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
421 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
423 callback->on_update_keyboard_ise(ic, uuid.c_str(), ise_name.c_str(), ise_uuid.c_str());
428 static void slot_candidate_more_window_show(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
429 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
431 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
433 callback->on_candidate_more_window_show(ic, uuid.c_str());
438 static void slot_candidate_more_window_hide(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
439 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
441 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
443 callback->on_candidate_more_window_hide(ic, uuid.c_str());
448 static void slot_select_aux(const scim::HelperAgent *agent, int ic, const scim::String &uuid, int index) {
449 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
451 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
453 callback->on_select_aux(ic, uuid.c_str(), index);
458 static void slot_select_candidate(const scim::HelperAgent *agent, int ic, const scim::String &uuid, int index) {
459 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
461 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
463 callback->on_select_candidate(ic, uuid.c_str(), index);
468 static void slot_candidate_table_page_up(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
469 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
471 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
473 callback->on_candidate_table_page_up(ic, uuid.c_str());
478 static void slot_candidate_table_page_down(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
479 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
481 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
483 callback->on_candidate_table_page_down(ic, uuid.c_str());
488 static void slot_update_candidate_table_page_size(const scim::HelperAgent *, int ic, const scim::String &uuid, int page_size) {
489 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
491 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
493 callback->on_update_candidate_table_page_size(ic, uuid.c_str(), page_size);
498 static void slot_update_candidate_item_layout(const scim::HelperAgent *agent, const std::vector<scim::uint32> &item) {
499 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
501 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
503 callback->on_update_candidate_item_layout(item);
508 static void slot_update_displayed_candidate_number(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, int size) {
509 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
511 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
513 callback->on_update_displayed_candidate_number((sclu32)size);
518 static void slot_longpress_candidate(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, int index) {
519 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
521 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
523 callback->on_longpress_candidate((sclu32)index);
528 static void slot_update_lookup_table(const scim::HelperAgent *, scim::LookupTable &table) {
529 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
531 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
533 SclCandidateTable lookup_table;
534 lookup_table.page_size = table.get_page_size();
535 lookup_table.current_page_start = table.get_current_page_start();
536 lookup_table.cursor_pos = table.get_cursor_pos();
537 lookup_table.cursor_visible = table.is_cursor_visible();
538 lookup_table.page_size_fixed = table.is_page_size_fixed();
539 lookup_table.candidate_labels.clear();
540 for (int page_index = 0;page_index < lookup_table.page_size;page_index++) {
541 scim::WideString label = table.get_candidate_label(page_index);
542 lookup_table.candidate_labels.push_back(scim::utf8_wcstombs(label).c_str());
545 int nCandidateSize = table.get_current_page_size();
546 for (int index = 0; index < nCandidateSize; ++index) {
547 scim::WideString candidate_str = table.get_candidate_in_current_page(index);
548 lookup_table.candidate.push_back(scim::utf8_wcstombs(candidate_str).c_str());
551 callback->on_update_lookup_table(lookup_table);
553 std::vector<scim::WideString> labels;
554 for (unsigned int loop = 0;loop < lookup_table.candidate_labels.size();loop++) {
555 labels.push_back(scim::utf8_mbstowcs(lookup_table.candidate_labels.at(loop).c_str()));
557 table.set_candidate_labels(labels);
562 static void slot_select_associate(const scim::HelperAgent *agent, int ic, const scim::String &uuid, int index) {
563 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
565 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
567 callback->on_select_associate(ic, uuid.c_str(), index);
572 static void slot_associate_table_page_up(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
573 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
575 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
577 callback->on_associate_table_page_up(ic, uuid.c_str());
582 static void slot_associate_table_page_down(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
583 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
585 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
587 callback->on_associate_table_page_down(ic, uuid.c_str());
592 static void slot_update_associate_table_page_size(const scim::HelperAgent *, int ic, const scim::String &uuid, int page_size) {
593 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
595 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
597 callback->on_update_associate_table_page_size(ic, uuid.c_str(), page_size);
602 static void slot_show_ise_option_window(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
603 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
605 CSCLCoreUI *core_ui = impl->get_core_ui();
607 LOGD("slot_show_ise_option_window() called!!!\n");
608 core_ui->create_option_window(OPTION_WINDOW_TYPE_SETTING_APPLICATION);
613 static void slot_resume_ise_option_window(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
614 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
616 CSCLCoreUI *core_ui = impl->get_core_ui();
618 LOGD("slot_resume_ise_option_window() called!!!\n");
619 core_ui->show_option_window(OPTION_WINDOW_TYPE_SETTING_APPLICATION);
624 static void slot_check_ise_option_window(const scim::HelperAgent *agent, sclu32 &avail) {
625 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
627 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
629 callback->on_check_option_window_availability(reinterpret_cast<sclboolean *>(&avail));
634 static void slot_process_key_event(const scim::HelperAgent *agent, scim::KeyEvent &key, scim::uint32 &ret) {
635 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
637 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
639 callback->on_process_key_event(key, &ret);
640 #ifdef WEBSOCKETweb_ret
641 g_websocket.on_process_key_event(key.code, key.mask, key.layout, &ret);
647 static void slot_process_key_event_with_keycode(const scim::HelperAgent *agent, scim::KeyEvent &key, scim::uint32 &ret, scim::uint32 keycode) {
648 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
650 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
652 callback->on_process_key_event_with_keycode(key, &ret, keycode);
657 static void slot_candidate_show(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
658 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
660 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
662 callback->on_candidate_show(ic, ic_uuid.c_str());
667 static void slot_candidate_hide(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
668 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
670 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
672 callback->on_candidate_hide(ic, ic_uuid.c_str());
677 static void slot_process_input_device_event(const scim::HelperAgent *agent, scim::uint32 &type, char *data, size_t &len, scim::uint32 &ret) {
678 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
680 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
682 /* Input Device Event callback is available in versions after 1.1 */
683 if (check_interface_version(callback, 1, 1)) {
684 callback->on_process_input_device_event(type, data, len, &ret);
690 static void slot_set_prediction_hint(const scim::HelperAgent *agent, const scim::String &prediction_hint) {
691 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
693 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
695 callback->on_set_prediction_hint(prediction_hint.c_str());
700 static void slot_set_mime_type(const scim::HelperAgent *agent, const scim::String &mime_type) {
701 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
703 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
705 callback->on_set_mime_type(mime_type.c_str());
710 static void slot_set_prediction_hint_data(const scim::HelperAgent *agent, int ic, const scim::String &key, const scim::String &value) {
711 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
713 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
715 SECURE_LOGD("key : %s, value : %s\n", key.c_str(), value.c_str());
716 callback->on_set_prediction_hint_data(key.c_str(), value.c_str());
721 static void slot_set_optimization_hint(const scim::HelperAgent *agent, scim::uint32 &hint) {
722 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
724 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
726 SECURE_LOGD("hint : %d\n", hint);
727 callback->on_set_optimization_hint(hint);
732 static void slot_process_key_event_with_imengine(const scim::HelperAgent *agent, scim::KeyEvent &key, scim::uint32 &ret) {
733 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
735 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
737 callback->on_process_key_event_with_imengine(key, &ret);
742 static void slot_set_autocapital_type(const scim::HelperAgent *agent, scim::uint32 &type) {
743 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
745 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
747 callback->on_set_autocapital_type(type);
752 static void slot_set_prediction_allow(const scim::HelperAgent *agent, scim::uint32 &prediction_allow) {
753 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
755 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
757 callback->on_set_prediction_allow(prediction_allow);
762 /* Internal input handler function */
763 Eina_Bool input_handler(void *data, Ecore_Fd_Handler *fd_handler)
765 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
767 scim::HelperAgent *agent = static_cast<scim::HelperAgent*>(data);
769 if (agent->has_pending_event()) {
770 if (!(agent->filter_event())) {
771 LOGD("helper_agent.filter_event() failed!!!\n");
776 LOGD("helper_agent.has_pending_event() failed!!!\n");
783 return ECORE_CALLBACK_RENEW;
786 CSCLConnectionISF::CSCLConnectionISF()
788 m_initialized = FALSE;
791 m_backend_identifier = "ISF";
794 CSCLConnectionISF::~CSCLConnectionISF()
798 sclboolean CSCLConnectionISF::init()
802 if (!m_initialized) {
803 m_helper_agent.signal_connect_exit(scim::slot(slot_exit));
804 m_helper_agent.signal_connect_attach_input_context(scim::slot(slot_attach_input_context));
805 m_helper_agent.signal_connect_detach_input_context(scim::slot(slot_detach_input_context));
806 m_helper_agent.signal_connect_reload_config(scim::slot(slot_reload_config));
807 m_helper_agent.signal_connect_update_screen(scim::slot(slot_update_screen));
808 m_helper_agent.signal_connect_update_spot_location(scim::slot(slot_update_spot_location));
809 m_helper_agent.signal_connect_update_cursor_position(scim::slot(slot_update_cursor_position));
810 m_helper_agent.signal_connect_update_surrounding_text(scim::slot(slot_update_surrounding_text));
811 m_helper_agent.signal_connect_trigger_property(scim::slot(slot_trigger_property));
812 //m_helper_agent.signal_connect_process_imengine_event (slot (slot_process_imengine_event));
813 m_helper_agent.signal_connect_focus_out(scim::slot(slot_focus_out));
814 m_helper_agent.signal_connect_focus_in(scim::slot(slot_focus_in));
815 m_helper_agent.signal_connect_ise_show(scim::slot(slot_ise_show));
816 m_helper_agent.signal_connect_ise_hide(scim::slot(slot_ise_hide));
817 m_helper_agent.signal_connect_get_geometry(scim::slot(slot_get_geometry));
818 m_helper_agent.signal_connect_set_mode(scim::slot(slot_set_mode));
819 m_helper_agent.signal_connect_set_language(scim::slot(slot_set_language));
820 m_helper_agent.signal_connect_set_imdata(scim::slot(slot_set_imdata));
821 m_helper_agent.signal_connect_get_imdata(scim::slot(slot_get_imdata));
822 m_helper_agent.signal_connect_get_language_locale(scim::slot(slot_get_language_locale));
823 m_helper_agent.signal_connect_set_return_key_type(scim::slot(slot_set_return_key_type));
824 m_helper_agent.signal_connect_get_return_key_type(scim::slot(slot_get_return_key_type));
825 m_helper_agent.signal_connect_set_return_key_disable(scim::slot(slot_set_return_key_disable));
826 m_helper_agent.signal_connect_get_return_key_disable(scim::slot(slot_get_return_key_disable));
827 m_helper_agent.signal_connect_get_layout(scim::slot(slot_get_layout));
828 m_helper_agent.signal_connect_set_layout(scim::slot(slot_set_layout));
829 m_helper_agent.signal_connect_set_caps_mode(scim::slot(slot_set_caps_mode));
830 m_helper_agent.signal_connect_reset_input_context(scim::slot(slot_reset_input_context));
831 m_helper_agent.signal_connect_update_candidate_geometry(scim::slot(slot_update_candidate_geometry));
832 m_helper_agent.signal_connect_update_keyboard_ise(scim::slot(slot_update_keyboard_ise));
833 //m_helper_agent.signal_connect_update_keyboard_ise_list (slot (slot_update_keyboard_ise_list));
834 m_helper_agent.signal_connect_candidate_more_window_show(scim::slot(slot_candidate_more_window_show));
835 m_helper_agent.signal_connect_candidate_more_window_hide(scim::slot(slot_candidate_more_window_hide));
836 m_helper_agent.signal_connect_select_aux(scim::slot(slot_select_aux));
837 m_helper_agent.signal_connect_select_candidate(scim::slot(slot_select_candidate));
838 m_helper_agent.signal_connect_candidate_table_page_up(scim::slot(slot_candidate_table_page_up));
839 m_helper_agent.signal_connect_candidate_table_page_down(scim::slot(slot_candidate_table_page_down));
840 m_helper_agent.signal_connect_update_candidate_table_page_size(scim::slot(slot_update_candidate_table_page_size));
841 m_helper_agent.signal_connect_update_candidate_item_layout(scim::slot(slot_update_candidate_item_layout));
842 m_helper_agent.signal_connect_update_displayed_candidate_number(scim::slot(slot_update_displayed_candidate_number));
843 m_helper_agent.signal_connect_longpress_candidate(scim::slot(slot_longpress_candidate));
844 m_helper_agent.signal_connect_update_lookup_table(scim::slot(slot_update_lookup_table));
845 m_helper_agent.signal_connect_select_associate(scim::slot(slot_select_associate));
846 m_helper_agent.signal_connect_associate_table_page_up(scim::slot(slot_associate_table_page_up));
847 m_helper_agent.signal_connect_associate_table_page_down(scim::slot(slot_associate_table_page_down));
848 m_helper_agent.signal_connect_update_associate_table_page_size(scim::slot(slot_update_associate_table_page_size));
849 m_helper_agent.signal_connect_show_option_window(scim::slot(slot_show_ise_option_window));
850 m_helper_agent.signal_connect_resume_option_window(scim::slot(slot_resume_ise_option_window));
851 m_helper_agent.signal_connect_check_option_window(scim::slot(slot_check_ise_option_window));
852 m_helper_agent.signal_connect_process_key_event(scim::slot(slot_process_key_event));
853 m_helper_agent.signal_connect_process_key_event_with_keycode(scim::slot(slot_process_key_event_with_keycode));
854 m_helper_agent.signal_connect_candidate_show(scim::slot(slot_candidate_show));
855 m_helper_agent.signal_connect_candidate_hide(scim::slot(slot_candidate_hide));
856 m_helper_agent.signal_connect_process_input_device_event(scim::slot(slot_process_input_device_event));
857 m_helper_agent.signal_connect_set_prediction_hint(scim::slot(slot_set_prediction_hint));
858 m_helper_agent.signal_connect_set_mime_type(scim::slot(slot_set_mime_type));
859 m_helper_agent.signal_connect_set_prediction_hint_data(scim::slot(slot_set_prediction_hint_data));
860 m_helper_agent.signal_connect_set_optimization_hint(scim::slot(slot_set_optimization_hint));
861 m_helper_agent.signal_connect_process_key_event_with_imengine(scim::slot(slot_process_key_event_with_imengine));
862 m_helper_agent.signal_connect_set_autocapital_type(scim::slot(slot_set_autocapital_type));
863 m_helper_agent.signal_connect_set_prediction_allow(scim::slot(slot_set_prediction_allow));
865 m_initialized = TRUE;
868 if (_scim_config.null()) {
869 scim::ConfigPointer config_pointer = scim::ConfigBase::get(true, "socket");
870 if (config_pointer.null()) {
871 config_pointer = new scim::DummyConfig();
873 _scim_config = config_pointer;
879 void CSCLConnectionISF::fini()
881 if (!_scim_config.null()) {
882 _scim_config.reset();
884 scim::ConfigBase::set(0);
886 m_initialized = FALSE;
889 void CSCLConnectionISF::open_connection(const sclchar *display)
892 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
894 sclchar *uuid = impl->get_uuid();
896 m_helper_info.uuid = uuid;
900 m_helper_agent.open_connection(m_helper_info, display);
901 int fd = m_helper_agent.get_connection_number();
905 Evas_Object *main_window = NULL;
906 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
908 main_window = NATIVE_WINDOW_CAST(impl->get_main_window());
911 Ecore_X_Window xwindow = elm_win_xwindow_get(main_window);
913 snprintf(xid, 255, "%d", xwindow);
914 scim::Property prop(xid, "XID", "", "");
915 scim::PropertyList props;
916 props.push_back(prop);
917 m_helper_agent.register_properties(props);
920 m_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, input_handler, &m_helper_agent, NULL, NULL);
925 void CSCLConnectionISF::close_connection()
929 ecore_main_fd_handler_del(m_fd_handler);
932 m_helper_agent.update_ise_exit();
933 m_helper_agent.close_connection();
937 void CSCLConnectionISF::config_reload()
940 m_helper_agent.reload_config();
944 sclboolean CSCLConnectionISF::config_read_int(const sclchar *name, sclint &value)
946 sclboolean ret = FALSE;
947 if (m_initialized && _scim_config) {
948 value = _scim_config->read(name, value);
954 sclboolean CSCLConnectionISF::config_read_string(const sclchar *name, std::string &value)
956 sclboolean ret = FALSE;
957 if (m_initialized && _scim_config) {
958 value = _scim_config->read(name, value);
964 sclboolean CSCLConnectionISF::config_write_int(const sclchar *name, sclint value)
966 sclboolean ret = FALSE;
967 if (m_initialized && _scim_config) {
968 _scim_config->write(name, value);
974 sclboolean CSCLConnectionISF::config_write_string(const sclchar *name, const std::string value)
976 sclboolean ret = FALSE;
977 if (m_initialized && _scim_config) {
978 _scim_config->write(name, value);
984 sclboolean CSCLConnectionISF::config_erase(const sclchar *name)
986 sclboolean ret = FALSE;
987 if (m_initialized && _scim_config) {
988 _scim_config->erase(name);
994 sclboolean CSCLConnectionISF::config_flush(void)
996 sclboolean ret = FALSE;
997 if (m_initialized && _scim_config) {
998 _scim_config->flush();
1004 void CSCLConnectionISF::send_imengine_event(sclint ic, const sclchar *ic_uuid, const sclint command, const sclu32 value)
1006 if (m_initialized) {
1009 uuid = scim::String(ic_uuid);
1011 scim::Transaction trans;
1012 trans.put_command(command);
1013 trans.put_data(value);
1014 m_helper_agent.send_imengine_event(ic, uuid, trans);
1018 void CSCLConnectionISF::reset_keyboard_ise()
1020 if (m_initialized) {
1021 m_helper_agent.reset_keyboard_ise();
1025 void CSCLConnectionISF::flush_keyboard_ise()
1027 if (m_initialized) {
1028 m_helper_agent.flush_keyboard_ise();
1032 void CSCLConnectionISF::send_key_event(sclint ic, const sclchar *ic_uuid, sclu32 keycode, sclu16 keymask)
1034 if (m_initialized) {
1037 uuid = scim::String(ic_uuid);
1039 scim::KeyEvent event;
1040 event.code = keycode;
1041 event.mask = keymask;
1042 m_helper_agent.send_key_event(ic, uuid, event);
1046 void CSCLConnectionISF::forward_key_event(sclint ic, const sclchar *ic_uuid, sclu32 keycode, sclu16 keymask)
1048 if (m_initialized) {
1051 uuid = scim::String(ic_uuid);
1053 scim::KeyEvent event;
1054 event.code = keycode;
1055 event.mask = keymask;
1056 m_helper_agent.forward_key_event(ic, uuid, event);
1060 void CSCLConnectionISF::commit_string(sclint ic, const sclchar *ic_uuid, const sclchar *str)
1062 if (m_initialized) {
1065 uuid = scim::String(ic_uuid);
1067 m_helper_agent.commit_string(ic, uuid, scim::utf8_mbstowcs(str));
1071 void CSCLConnectionISF::select_candidate(int index)
1073 if (m_initialized) {
1074 m_helper_agent.select_candidate(index);
1078 void CSCLConnectionISF::show_preedit_string(sclint ic, const sclchar *ic_uuid)
1080 if (m_initialized) {
1083 uuid = scim::String(ic_uuid);
1085 m_helper_agent.show_preedit_string(ic, uuid);
1089 void CSCLConnectionISF::show_aux_string(void)
1091 if (m_initialized) {
1092 m_helper_agent.show_aux_string();
1096 void CSCLConnectionISF::show_candidate_string(void)
1098 if (m_initialized) {
1099 m_helper_agent.show_candidate_string();
1103 void CSCLConnectionISF::show_associate_string(void)
1105 if (m_initialized) {
1106 m_helper_agent.show_associate_string();
1110 void CSCLConnectionISF::hide_preedit_string(sclint ic, const sclchar *ic_uuid)
1112 if (m_initialized) {
1115 uuid = scim::String(ic_uuid);
1117 m_helper_agent.hide_preedit_string(ic, uuid);
1121 void CSCLConnectionISF::hide_aux_string(void)
1123 if (m_initialized) {
1124 m_helper_agent.hide_aux_string();
1128 void CSCLConnectionISF::hide_candidate_string(void)
1130 if (m_initialized) {
1131 m_helper_agent.hide_candidate_string();
1135 void CSCLConnectionISF::hide_associate_string(void)
1137 if (m_initialized) {
1138 m_helper_agent.hide_associate_string();
1142 void CSCLConnectionISF::update_preedit_string(sclint ic, const sclchar *ic_uuid, const sclchar *str)
1144 if (m_initialized) {
1145 scim::AttributeList list;
1148 uuid = scim::String(ic_uuid);
1150 m_helper_agent.update_preedit_string(ic, uuid, scim::utf8_mbstowcs(str), list);
1152 if (str && strlen(str) > 0) {
1153 show_preedit_string(ic, ic_uuid);
1155 hide_preedit_string(ic, ic_uuid);
1160 void CSCLConnectionISF::update_preedit_string(sclint ic, const sclchar *ic_uuid, const sclchar *str, const scim::AttributeList &attrs)
1162 if (m_initialized) {
1165 uuid = scim::String(ic_uuid);
1167 m_helper_agent.update_preedit_string(ic, uuid, scim::utf8_mbstowcs(str), attrs);
1169 if (str && strlen(str) > 0) {
1170 show_preedit_string(ic, ic_uuid);
1172 hide_preedit_string(ic, ic_uuid);
1177 void CSCLConnectionISF::update_preedit_caret(sclint caret)
1179 if (m_initialized) {
1180 m_helper_agent.update_preedit_caret(caret);
1184 void CSCLConnectionISF::update_aux_string(const sclchar *str)
1186 if (m_initialized) {
1187 scim::AttributeList list;
1188 m_helper_agent.update_aux_string(scim::String(str), list);
1192 void CSCLConnectionISF::update_input_context(sclu32 type, sclu32 value)
1194 if (m_initialized) {
1195 m_helper_agent.update_input_context(type, value);
1199 void CSCLConnectionISF::update_geometry(sclint x, sclint y, sclint width, sclint height)
1201 if (m_initialized) {
1202 m_helper_agent.update_geometry(x, y, width, height);
1206 void CSCLConnectionISF::get_surrounding_text(const sclchar *ic_uuid, sclint maxlen_before, sclint maxlen_after) const
1208 if (m_initialized) {
1211 uuid = scim::String(ic_uuid);
1213 m_helper_agent.get_surrounding_text(uuid, maxlen_before, maxlen_after);
1217 sclint CSCLConnectionISF::get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor)
1219 if (m_initialized) {
1220 scim::String surrounding_text;
1221 m_helper_agent.get_surrounding_text(maxlen_before, maxlen_after, surrounding_text, cursor);
1224 *text = strdup(surrounding_text.c_str());
1225 if (*text == NULL) {
1233 void CSCLConnectionISF::delete_surrounding_text(sclint offset, sclint len) const
1235 if (m_initialized) {
1236 m_helper_agent.delete_surrounding_text(offset, len);
1240 void CSCLConnectionISF::set_candidate_position(sclint left, sclint top)
1242 if (m_initialized) {
1243 m_helper_agent.set_candidate_position(left, top);
1247 void CSCLConnectionISF::enable_soft_candidate(sclboolean enable)
1249 if (m_initialized) {
1251 m_helper_agent.set_candidate_style(scim::ONE_LINE_CANDIDATE, scim::SOFT_CANDIDATE_WINDOW);
1253 m_helper_agent.set_candidate_style(scim::ONE_LINE_CANDIDATE, scim::FIXED_CANDIDATE_WINDOW);
1257 void CSCLConnectionISF::candidate_hide(void)
1259 if (m_initialized) {
1260 m_helper_agent.candidate_hide();
1264 void CSCLConnectionISF::set_keyboard_ise_by_uuid(const sclchar *uuid)
1266 if (m_initialized) {
1267 m_helper_agent.set_keyboard_ise_by_uuid(uuid);
1271 void CSCLConnectionISF::get_keyboard_ise(const sclchar *uuid)
1273 if (m_initialized) {
1274 m_helper_agent.get_keyboard_ise(uuid);
1278 void CSCLConnectionISF::set_selection(sclint start, sclint end)
1280 if (m_initialized) {
1281 m_helper_agent.set_selection(start, end);
1285 void CSCLConnectionISF::send_private_command(const sclchar *command)
1287 Eina_Bool tc_command = EINA_FALSE;
1288 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
1289 ISCLCoreEventCallback *callback = NULL;
1291 callback = impl->get_core_event_callback();
1293 if (command && callback) {
1294 if (strcmp(command, "tizen::tc::test") == 0) {
1295 static Ise_Context context;
1296 static SclCandidateTable table;
1297 static scim::KeyEvent key;
1301 callback->on_attach_input_context(0, "");
1302 callback->on_detach_input_context(0, "");
1303 callback->on_reload_config(0, "");
1304 callback->on_update_spot_location(0, "", 0, 0);
1305 callback->on_update_cursor_position(0, "", 0);
1306 callback->on_update_surrounding_text(0, NULL, 0);
1307 callback->on_focus_out(0, "");
1308 callback->on_focus_in(0, "");
1309 callback->on_ise_show(0, 0, context);
1310 callback->on_ise_hide(0, "");
1311 callback->on_get_geometry(NULL, NULL, NULL, NULL);
1312 callback->on_set_mode(0);
1313 callback->on_set_language(0);
1314 callback->on_set_imdata(NULL, 0);
1315 callback->on_get_imdata(NULL, NULL);
1316 callback->on_get_language_locale(0, NULL);
1317 callback->on_set_return_key_type(0);
1318 callback->on_get_return_key_type(NULL);
1319 callback->on_set_return_key_disable(0);
1320 callback->on_get_return_key_disable(NULL);
1321 callback->on_set_layout(0);
1322 callback->on_get_layout(NULL);
1323 callback->on_set_caps_mode(0);
1324 callback->on_reset_input_context(0, NULL);
1325 callback->on_update_candidate_geometry(0, NULL, 0, 0, 0, 0);
1326 callback->on_update_keyboard_ise(0, NULL, NULL, NULL);
1327 callback->on_candidate_more_window_show(0, NULL);
1328 callback->on_candidate_more_window_hide(0, NULL);
1329 callback->on_select_aux(0, NULL, 0);
1330 callback->on_select_candidate(0, NULL, 0);
1331 callback->on_candidate_table_page_up(0, NULL);
1332 callback->on_candidate_table_page_down(0, NULL);
1333 callback->on_update_lookup_table(table);
1334 callback->on_update_candidate_table_page_size(0, NULL, 0);
1335 callback->on_select_associate(0, NULL, 0);
1336 callback->on_associate_table_page_up(0, NULL);
1337 callback->on_associate_table_page_down(0, NULL);
1338 callback->on_update_associate_table_page_size(0, NULL, 0);
1339 callback->on_process_key_event(key, NULL);
1340 callback->on_process_key_event_with_keycode(key, NULL, 0);
1341 callback->on_process_key_event_with_imengine(key, NULL);
1343 callback->on_set_display_language(NULL);
1344 callback->on_set_rotation_degree(0);
1345 callback->on_set_accessibility_state(FALSE);
1347 callback->on_create_option_window(SCLWINDOW_INVALID, OPTION_WINDOW_TYPE_NORMAL);
1348 callback->on_destroy_option_window(SCLWINDOW_INVALID);
1349 callback->on_check_option_window_availability(NULL);
1351 callback->on_candidate_show(0, "");
1352 callback->on_candidate_hide(0, "");
1354 callback->on_process_input_device_event(type, NULL, len, NULL);
1356 callback->on_set_prediction_hint(NULL);
1357 callback->on_set_mime_type(NULL);
1359 tc_command = EINA_TRUE;
1363 if (m_initialized && command && !tc_command) {
1364 m_helper_agent.send_private_command(command);
1368 void CSCLConnectionISF::get_selection_text(sclchar **text)
1370 if (m_initialized) {
1371 scim::String selection_text;
1372 m_helper_agent.get_selection_text(selection_text);
1375 *text = strdup(selection_text.c_str());
1379 void CSCLConnectionISF::request_ise_hide()
1381 if (m_initialized) {
1382 m_helper_agent.request_ise_hide();
1386 void CSCLConnectionISF::commit_content(const sclchar *content, const sclchar *description, const sclchar *mime_types)
1388 if (m_initialized) {
1389 m_helper_agent.commit_content(content, description, mime_types);
1393 void CSCLConnectionISF::update_preedit_string_with_commit(const sclchar *preedit, const sclchar *commit, const scim::AttributeList &attrs, sclint caret)
1395 if (m_initialized) {
1396 m_helper_agent.update_preedit_string(-1, "", scim::utf8_mbstowcs(scim::String(preedit)), scim::utf8_mbstowcs(scim::String(commit)), attrs, caret);
1400 void CSCLConnectionISF::recapture_string(sclint offset, sclint len, const sclchar *preedit, const sclchar *commit, const scim::AttributeList &attrs)
1402 if (m_initialized) {
1403 m_helper_agent.recapture_string(-1, "", offset, len, scim::utf8_mbstowcs(scim::String(preedit)), scim::utf8_mbstowcs(scim::String(commit)), attrs);
1407 void CSCLConnectionISF::update_lookup_table(const scim::LookupTable &table)
1409 if (m_initialized) {
1410 m_helper_agent.update_candidate_string(table);
1414 void CSCLConnectionISF::register_properties(const scim::PropertyList &properties)
1416 if (m_initialized) {
1417 m_helper_agent.register_properties(properties);
1421 void CSCLConnectionISF::update_property(const scim::Property &property)
1423 if (m_initialized) {
1424 m_helper_agent.update_property(property);
1428 void CSCLConnectionISF::expand_candidate(void)
1430 if (m_initialized) {
1431 m_helper_agent.expand_candidate();
1435 void CSCLConnectionISF::contract_candidate(void)
1437 if (m_initialized) {
1438 m_helper_agent.contract_candidate();
1442 void CSCLConnectionISF::set_candidate_style(scim::ISF_CANDIDATE_PORTRAIT_LINE_T portrait_line, scim::ISF_CANDIDATE_MODE_T mode)
1444 if (m_initialized) {
1445 m_helper_agent.set_candidate_style(portrait_line, mode);
1449 void CSCLConnectionISF::set_engine_loader_flag(sclboolean flag)
1451 if (m_initialized) {
1452 m_helper_agent.set_engine_loader_flag(flag);
1458 EXAPI void scim_module_init(void) {
1461 EXAPI void scim_module_exit(void) {
1464 EXAPI void scim_helper_module_run_helper(const scim::String &uuid, const scim::ConfigPointer &config, const scim::String &display) {
1465 _scim_config = config;
1466 CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
1468 impl->on_run(uuid.c_str(), display.c_str());