aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/modules/immodules/scim/scim_imcontext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ecore/src/modules/immodules/scim/scim_imcontext.cpp')
-rw-r--r--libraries/ecore/src/modules/immodules/scim/scim_imcontext.cpp2895
1 files changed, 0 insertions, 2895 deletions
diff --git a/libraries/ecore/src/modules/immodules/scim/scim_imcontext.cpp b/libraries/ecore/src/modules/immodules/scim/scim_imcontext.cpp
deleted file mode 100644
index eb9b5c9..0000000
--- a/libraries/ecore/src/modules/immodules/scim/scim_imcontext.cpp
+++ /dev/null
@@ -1,2895 +0,0 @@
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#define Uses_SCIM_DEBUG
6#define Uses_SCIM_BACKEND
7#define Uses_SCIM_IMENGINE_MODULE
8#define Uses_SCIM_HOTKEY
9#define Uses_SCIM_PANEL_CLIENT
10
11#include <sys/types.h>
12#include <sys/wait.h>
13#include <sys/time.h>
14#include <sys/times.h>
15#include <unistd.h>
16#include <pthread.h>
17#include <Ecore_Evas.h>
18#include <Ecore_X.h>
19#include <Ecore.h>
20#include <Evas.h>
21
22#include <X11/Xlib.h>
23#include <X11/keysym.h>
24#include <X11/Xutil.h>
25
26#include <scim.h>
27#include "scim_imcontext.h"
28
29using namespace scim;
30
31struct _EcoreIMFContextISFImpl
32{
33 EcoreIMFContextISF *parent;
34 IMEngineInstancePointer si;
35 Ecore_X_Window client_window;
36 Evas *client_canvas;
37 Ecore_IMF_Input_Mode input_mode;
38 WideString preedit_string;
39 AttributeList preedit_attrlist;
40 Ecore_IMF_Autocapital_Type autocapital_type;
41 int preedit_caret;
42 int cursor_x;
43 int cursor_y;
44 int cursor_pos;
45 bool use_preedit;
46 bool is_on;
47 bool shared_si;
48 bool preedit_started;
49 bool preedit_updating;
50 bool need_commit_preedit;
51 bool uppercase;
52 bool prediction_allow;
53
54 EcoreIMFContextISFImpl *next;
55};
56
57/* Input Context handling functions. */
58static EcoreIMFContextISFImpl *new_ic_impl (EcoreIMFContextISF *parent);
59static void delete_ic_impl (EcoreIMFContextISFImpl *impl);
60static void delete_all_ic_impl (void);
61
62static EcoreIMFContextISF *find_ic (int id);
63
64
65/* private functions */
66static void panel_slot_reload_config (int context);
67static void panel_slot_exit (int context);
68static void panel_slot_update_lookup_table_page_size(int context,
69 int page_size);
70static void panel_slot_lookup_table_page_up (int context);
71static void panel_slot_lookup_table_page_down (int context);
72static void panel_slot_trigger_property (int context,
73 const String &property);
74static void panel_slot_process_helper_event (int context,
75 const String &target_uuid,
76 const String &helper_uuid,
77 const Transaction &trans);
78static void panel_slot_move_preedit_caret (int context,
79 int caret_pos);
80static void panel_slot_select_candidate (int context,
81 int cand_index);
82static void panel_slot_process_key_event (int context,
83 const KeyEvent &key);
84static void panel_slot_commit_string (int context,
85 const WideString &wstr);
86static void panel_slot_forward_key_event (int context,
87 const KeyEvent &key);
88static void panel_slot_request_help (int context);
89static void panel_slot_request_factory_menu (int context);
90static void panel_slot_change_factory (int context,
91 const String &uuid);
92
93static void panel_req_focus_in (EcoreIMFContextISF *ic);
94static void panel_req_update_factory_info (EcoreIMFContextISF *ic);
95static void panel_req_update_spot_location (EcoreIMFContextISF *ic);
96static void panel_req_show_help (EcoreIMFContextISF *ic);
97static void panel_req_show_factory_menu (EcoreIMFContextISF *ic);
98
99/* Panel iochannel handler*/
100static bool panel_initialize (void);
101static void panel_finalize (void);
102static Eina_Bool panel_iochannel_handler (void *data,
103 Ecore_Fd_Handler *fd_handler);
104
105/* utility functions */
106static bool filter_hotkeys (EcoreIMFContextISF *ic,
107 const KeyEvent &key);
108static void turn_on_ic (EcoreIMFContextISF *ic);
109static void turn_off_ic (EcoreIMFContextISF *ic);
110static void set_ic_capabilities (EcoreIMFContextISF *ic);
111
112static void initialize (void);
113static void finalize (void);
114
115static void open_next_factory (EcoreIMFContextISF *ic);
116static void open_previous_factory (EcoreIMFContextISF *ic);
117static void open_specific_factory (EcoreIMFContextISF *ic,
118 const String &uuid);
119static void initialize_modifier_bits (Display *display);
120static unsigned int scim_x11_keymask_scim_to_x11 (Display *display, uint16 scimkeymask);
121static XKeyEvent createKeyEvent (Display *display, Window &win,
122 Window &winRoot, bool press,
123 int keycode, int modifiers);
124static void _x_send_key_event (const KeyEvent &key);
125
126static void attach_instance (const IMEngineInstancePointer &si);
127
128/* slot functions */
129static void slot_show_preedit_string (IMEngineInstanceBase *si);
130static void slot_show_aux_string (IMEngineInstanceBase *si);
131static void slot_show_lookup_table (IMEngineInstanceBase *si);
132
133static void slot_hide_preedit_string (IMEngineInstanceBase *si);
134static void slot_hide_aux_string (IMEngineInstanceBase *si);
135static void slot_hide_lookup_table (IMEngineInstanceBase *si);
136
137static void slot_update_preedit_caret (IMEngineInstanceBase *si,
138 int caret);
139static void slot_update_preedit_string (IMEngineInstanceBase *si,
140 const WideString &str,
141 const AttributeList &attrs);
142static void slot_update_aux_string (IMEngineInstanceBase *si,
143 const WideString &str,
144 const AttributeList &attrs);
145static void slot_commit_string (IMEngineInstanceBase *si,
146 const WideString &str);
147static void slot_forward_key_event (IMEngineInstanceBase *si,
148 const KeyEvent &key);
149static void slot_update_lookup_table (IMEngineInstanceBase *si,
150 const LookupTable &table);
151
152static void slot_register_properties (IMEngineInstanceBase *si,
153 const PropertyList &properties);
154static void slot_update_property (IMEngineInstanceBase *si,
155 const Property &property);
156static void slot_beep (IMEngineInstanceBase *si);
157static void slot_start_helper (IMEngineInstanceBase *si,
158 const String &helper_uuid);
159static void slot_stop_helper (IMEngineInstanceBase *si,
160 const String &helper_uuid);
161static void slot_send_helper_event (IMEngineInstanceBase *si,
162 const String &helper_uuid,
163 const Transaction &trans);
164static bool slot_get_surrounding_text (IMEngineInstanceBase *si,
165 WideString &text,
166 int &cursor,
167 int maxlen_before,
168 int maxlen_after);
169static bool slot_delete_surrounding_text (IMEngineInstanceBase *si,
170 int offset,
171 int len);
172
173static void reload_config_callback (const ConfigPointer &config);
174
175static void fallback_commit_string_cb (IMEngineInstanceBase *si,
176 const WideString &str);
177
178static void caps_mode_check (Ecore_IMF_Context *ctx, Eina_Bool force);
179
180/* Local variables declaration */
181static String _language;
182static EcoreIMFContextISFImpl *_used_ic_impl_list = 0;
183static EcoreIMFContextISFImpl *_free_ic_impl_list = 0;
184static EcoreIMFContextISF *_ic_list = 0;
185
186static KeyboardLayout _keyboard_layout = SCIM_KEYBOARD_Default;
187static int _valid_key_mask = SCIM_KEY_AllMasks;
188
189static FrontEndHotkeyMatcher _frontend_hotkey_matcher;
190static IMEngineHotkeyMatcher _imengine_hotkey_matcher;
191
192static IMEngineInstancePointer _default_instance;
193
194static ConfigModule *_config_module = 0;
195static ConfigPointer _config;
196static BackEndPointer _backend;
197
198static EcoreIMFContextISF *_focused_ic = 0;
199
200static bool _scim_initialized = false;
201
202static int _instance_count = 0;
203static int _context_count = 0;
204
205static IMEngineFactoryPointer _fallback_factory;
206static IMEngineInstancePointer _fallback_instance;
207static PanelClient _panel_client;
208
209static Ecore_Fd_Handler *_panel_iochannel_read_handler = 0;
210static Ecore_Fd_Handler *_panel_iochannel_err_handler = 0;
211
212static Ecore_X_Window _client_window = 0;
213
214static bool _on_the_spot = true;
215static bool _shared_input_method = false;
216
217static Eina_Bool autocap_allow = EINA_FALSE;
218
219static Display *__current_display = 0;
220static int __current_alt_mask = Mod1Mask;
221static int __current_meta_mask = 0;
222static int __current_super_mask = 0;
223static int __current_hyper_mask = 0;
224static int __current_numlock_mask = Mod2Mask;
225
226// A hack to shutdown the immodule cleanly even if im_module_exit() is not called when exiting.
227class FinalizeHandler
228{
229public:
230 FinalizeHandler()
231 {
232 SCIM_DEBUG_FRONTEND(1) << "FinalizeHandler::FinalizeHandler()\n";
233 }
234 ~FinalizeHandler()
235 {
236 SCIM_DEBUG_FRONTEND(1) << "FinalizeHandler::~FinalizeHandler()\n";
237 isf_imf_context_shutdown();
238 }
239};
240
241static FinalizeHandler _finalize_handler;
242
243static unsigned int
244utf8_offset_to_index(const char *str, int offset)
245{
246 int index = 0;
247 int i;
248 for (i = 0; i < offset; i++)
249 {
250 eina_unicode_utf8_get_next(str, &index);
251 }
252
253 return index;
254}
255
256static unsigned int
257get_time(void)
258{
259 unsigned int tint;
260 struct timeval tv;
261 struct timezone tz; /* is not used since ages */
262 gettimeofday(&tv, &tz);
263 tint = tv.tv_sec * 1000;
264 tint = tint / 1000 * 1000;
265 tint = tint + tv.tv_usec / 1000;
266 return tint;
267}
268
269/* Function Implementations */
270static EcoreIMFContextISFImpl *
271new_ic_impl(EcoreIMFContextISF *parent)
272{
273 EcoreIMFContextISFImpl *impl = NULL;
274
275 if (_free_ic_impl_list != NULL)
276 {
277 impl = _free_ic_impl_list;
278 _free_ic_impl_list = _free_ic_impl_list->next;
279 }
280 else
281 {
282 impl = new EcoreIMFContextISFImpl;
283 if (impl == NULL)
284 return NULL;
285 }
286
287 impl->uppercase = false;
288 impl->autocapital_type = ECORE_IMF_AUTOCAPITAL_TYPE_NONE;
289 impl->next = _used_ic_impl_list;
290 _used_ic_impl_list = impl;
291
292 impl->parent = parent;
293
294 return impl;
295}
296
297static void
298delete_ic_impl(EcoreIMFContextISFImpl *impl)
299{
300 EcoreIMFContextISFImpl *rec = _used_ic_impl_list, *last = 0;
301
302 for (; rec != 0; last = rec, rec = rec->next)
303 {
304 if (rec == impl)
305 {
306 if (last != 0)
307 last->next = rec->next;
308 else
309 _used_ic_impl_list = rec->next;
310
311 rec->next = _free_ic_impl_list;
312 _free_ic_impl_list = rec;
313
314 rec->parent = 0;
315 rec->si.reset();
316 rec->client_window = 0;
317 rec->preedit_string = WideString();
318 rec->preedit_attrlist.clear();
319
320 return;
321 }
322 }
323}
324
325static void
326delete_all_ic_impl(void)
327{
328 EcoreIMFContextISFImpl *it = _used_ic_impl_list;
329
330 while (it != 0)
331 {
332 _used_ic_impl_list = it->next;
333 delete it;
334 it = _used_ic_impl_list;
335 }
336
337 it = _free_ic_impl_list;
338 while (it != 0)
339 {
340 _free_ic_impl_list = it->next;
341 delete it;
342 it = _free_ic_impl_list;
343 }
344}
345
346static EcoreIMFContextISF *
347find_ic(int id)
348{
349 EcoreIMFContextISFImpl *rec = _used_ic_impl_list;
350
351 while (rec != 0)
352 {
353 if (rec->parent && rec->parent->id == id)
354 return rec->parent;
355 rec = rec->next;
356 }
357
358 return 0;
359}
360
361static Eina_Bool
362analyze_surrounding_text(Ecore_IMF_Context *ctx)
363{
364 char *plain_str = NULL;
365 char *markup_str = NULL;
366 const char *puncs[] = {". ", "! ", "? "};
367 Eina_Bool ret = EINA_FALSE;
368 int cursor_pos = 0;
369 int i = 0;
370 Eina_Unicode *tail = NULL;
371 Eina_Unicode *ustr = NULL;
372 const int punc_num = sizeof(puncs) / sizeof(puncs[0]);
373 Eina_Unicode *uni_puncs[punc_num];
374 EcoreIMFContextISF *context_scim;
375
376 if (!ctx) return EINA_FALSE;
377 context_scim = (EcoreIMFContextISF *)ecore_imf_context_data_get(ctx);
378 if (!context_scim || !context_scim->impl) return EINA_FALSE;
379
380 switch (context_scim->impl->autocapital_type)
381 {
382 case ECORE_IMF_AUTOCAPITAL_TYPE_NONE:
383 return EINA_FALSE;
384 case ECORE_IMF_AUTOCAPITAL_TYPE_ALLCHARACTER:
385 return EINA_TRUE;
386 default:
387 break;
388 }
389
390 for (i = 0; i < punc_num; i++)
391 uni_puncs[i] = eina_unicode_utf8_to_unicode(puncs[i], NULL);
392
393 ecore_imf_context_surrounding_get(ctx, &markup_str, &cursor_pos);
394 if (!markup_str) goto done;
395
396 if (cursor_pos == 0)
397 {
398 ret = EINA_TRUE;
399 goto done;
400 }
401
402 // Convert into plain string
403 plain_str = evas_textblock_text_markup_to_utf8(NULL, markup_str);
404 if (!plain_str) goto done;
405
406 // Convert string from utf8 to unicode
407 ustr = eina_unicode_utf8_to_unicode(plain_str, NULL);
408 if (!ustr) goto done;
409
410 if (cursor_pos >= 1)
411 {
412 if (context_scim->impl->autocapital_type == ECORE_IMF_AUTOCAPITAL_TYPE_WORD)
413 {
414 if (ustr[cursor_pos-1] == ' ')
415 {
416 ret = EINA_TRUE;
417 goto done;
418 }
419 }
420
421 // Check paragraph separator <PS> and carrage return <br>
422 if ((ustr[cursor_pos-1] == 0x2029) || (ustr[cursor_pos-1] == '\n'))
423 {
424 ret = EINA_TRUE;
425 goto done;
426 }
427 }
428
429 // check punctuation
430 if (cursor_pos >= 2)
431 {
432 tail = eina_unicode_strndup(ustr+cursor_pos-2, 2);
433
434 if (tail)
435 {
436 for (i = 0; i < punc_num; i++)
437 {
438 if (!eina_unicode_strcmp(tail, uni_puncs[i]))
439 {
440 ret = EINA_TRUE;
441 break;
442 }
443 }
444 free(tail);
445 tail = NULL;
446 }
447 }
448
449done:
450 if (ustr) free(ustr);
451 if (markup_str) free(markup_str);
452 if (plain_str) free(plain_str);
453
454 for (i = 0; i < punc_num; i++)
455 if (uni_puncs[i]) free(uni_puncs[i]);
456
457 return ret;
458}
459
460static void
461caps_mode_check(Ecore_IMF_Context *ctx, Eina_Bool force)
462{
463 Eina_Bool uppercase;
464 EcoreIMFContextISF *context_scim;
465
466 if (!ctx) return;
467 context_scim = (EcoreIMFContextISF *)ecore_imf_context_data_get(ctx);
468
469 if (autocap_allow == EINA_FALSE)
470 return;
471
472 // Check autocapital type
473 if (!context_scim || !context_scim->impl)
474 return;
475
476 if (analyze_surrounding_text(ctx))
477 uppercase = EINA_TRUE;
478 else
479 uppercase = EINA_FALSE;
480
481 if (force)
482 context_scim->impl->uppercase = uppercase;
483 else
484 if (context_scim->impl->uppercase != uppercase)
485 context_scim->impl->uppercase = uppercase;
486}
487
488static void
489feed_key_event(Evas *evas, const char *str, Eina_Bool fake)
490{
491 char key_string[128] = {0};
492 unsigned int timestamp = 0;
493
494 if (!fake)
495 timestamp = get_time();
496
497 if (strncmp(str, "KeyRelease+", 11) == 0)
498 {
499 strncpy(key_string, str + 11, strlen(str)-11);
500 evas_event_feed_key_up(evas, key_string, key_string, NULL, NULL, timestamp, NULL);
501 SCIM_DEBUG_FRONTEND(1) << " evas_event_feed_key_up()...\n";
502 }
503 else
504 {
505 strncpy(key_string, str, strlen(str));
506 evas_event_feed_key_down(evas, key_string, key_string, NULL, NULL, timestamp, NULL);
507 SCIM_DEBUG_FRONTEND(1) << " evas_event_feed_key_down()...\n";
508 }
509}
510
511static void
512window_to_screen_geometry_get(Ecore_X_Window client_win, int *x, int *y)
513{
514 Ecore_X_Window root_window, win;
515 int win_x, win_y;
516 int sum_x = 0, sum_y = 0;
517
518 root_window = ecore_x_window_root_get(client_win);
519 win = client_win;
520
521 while (root_window != win)
522 {
523 ecore_x_window_geometry_get(win, &win_x, &win_y, NULL, NULL);
524 sum_x += win_x;
525 sum_y += win_y;
526 win = ecore_x_window_parent_get(win);
527 }
528
529 if (x)
530 *x = sum_x;
531 if (y)
532 *y = sum_y;
533}
534
535/* Public functions */
536/**
537 * isf_imf_context_new
538 *
539 * This function will be called by Ecore IMF.
540 * Create a instance of type EcoreIMFContextISF.
541 *
542 * Return value: A pointer to the newly created EcoreIMFContextISF instance
543 */
544EAPI EcoreIMFContextISF *
545isf_imf_context_new(void)
546{
547 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
548 char *env;
549
550 EcoreIMFContextISF *context_scim = new EcoreIMFContextISF;
551 if (context_scim == NULL)
552 {
553 std::cerr << "memory allocation failed in " << __FUNCTION__ << "\n";
554 return NULL;
555 }
556
557 context_scim->id = _context_count++;
558
559 if (!_scim_initialized)
560 {
561 initialize();
562 _scim_initialized = true;
563 }
564
565 env = getenv("ECORE_IMF_AUTOCAPITAL_ALLOW");
566 if (env)
567 autocap_allow = !!atoi(env);
568
569 return context_scim;
570}
571
572/**
573 * isf_imf_shutdown
574 *
575 * It will be called when the scim im module is unloaded by ecore. It will do some
576 * cleanup job.
577 */
578EAPI void
579isf_imf_context_shutdown(void)
580{
581 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
582
583 if (_scim_initialized)
584 {
585 _scim_initialized = false;
586 finalize();
587 }
588}
589
590EAPI void
591isf_imf_context_add(Ecore_IMF_Context *ctx)
592{
593 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
594
595 EcoreIMFContextISF *context_scim = (EcoreIMFContextISF*)ecore_imf_context_data_get(ctx);
596
597 if (!context_scim) return;
598
599 context_scim->impl = NULL;
600
601 if (_backend.null())
602 return;
603
604 IMEngineInstancePointer si;
605
606 // Use the default instance if "shared input method" mode is enabled.
607 if (_shared_input_method && !_default_instance.null())
608 {
609 si = _default_instance;
610 SCIM_DEBUG_FRONTEND(2) << "use default instance: " << si->get_id() << " " << si->get_factory_uuid() << "\n";
611 }
612
613 // Not in "shared input method" mode, or no default instance, create an instance.
614 if (si.null())
615 {
616 IMEngineFactoryPointer factory = _backend->get_default_factory(_language, "UTF-8");
617 if (factory.null()) return;
618 si = factory->create_instance("UTF-8", _instance_count++);
619 if (si.null()) return;
620 attach_instance(si);
621 SCIM_DEBUG_FRONTEND(2) << "create new instance: " << si->get_id() << " " << si->get_factory_uuid() << "\n";
622 }
623
624 // If "shared input method" mode is enabled, and there is no default instance,
625 // then store this instance as default one.
626 if (_shared_input_method && _default_instance.null())
627 {
628 SCIM_DEBUG_FRONTEND(2) << "update default instance.\n";
629 _default_instance = si;
630 }
631
632 context_scim->ctx = ctx;
633 context_scim->impl = new_ic_impl(context_scim);
634 if (context_scim->impl == NULL)
635 {
636 std::cerr << "memory allocation failed in " << __FUNCTION__ << "\n";
637 return;
638 }
639
640 context_scim->impl->si = si;
641 context_scim->impl->client_window = 0;
642 context_scim->impl->client_canvas = NULL;
643 context_scim->impl->preedit_caret = 0;
644 context_scim->impl->cursor_x = 0;
645 context_scim->impl->cursor_y = 0;
646 context_scim->impl->cursor_pos = -1;
647 context_scim->impl->is_on = false;
648 context_scim->impl->shared_si = _shared_input_method;
649 context_scim->impl->use_preedit = _on_the_spot;
650 context_scim->impl->preedit_started = false;
651 context_scim->impl->preedit_updating = false;
652 context_scim->impl->need_commit_preedit = false;
653
654 if (!_ic_list)
655 context_scim->next = NULL;
656 else
657 context_scim->next = _ic_list;
658 _ic_list = context_scim;
659
660 if (_shared_input_method)
661 context_scim->impl->is_on = _config->read(String(SCIM_CONFIG_FRONTEND_IM_OPENED_BY_DEFAULT), context_scim->impl->is_on);
662
663 _panel_client.prepare(context_scim->id);
664 _panel_client.register_input_context(context_scim->id, si->get_factory_uuid());
665 set_ic_capabilities(context_scim);
666 _panel_client.send();
667
668 SCIM_DEBUG_FRONTEND(2) << "input context created: id = " << context_scim->id << "\n";
669}
670
671EAPI void
672isf_imf_context_del(Ecore_IMF_Context *ctx)
673{
674 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
675
676 if (!_ic_list) return;
677
678 EcoreIMFContextISF *context_scim = (EcoreIMFContextISF*)ecore_imf_context_data_get(ctx);
679
680 if (context_scim)
681 {
682 if (context_scim->id != _ic_list->id)
683 {
684 EcoreIMFContextISF * pre = _ic_list;
685 EcoreIMFContextISF * cur = _ic_list->next;
686 while (cur != NULL)
687 {
688 if (cur->id == context_scim->id)
689 {
690 pre->next = cur->next;
691 break;
692 }
693 pre = cur;
694 cur = cur->next;
695 }
696 }
697 else
698 _ic_list = _ic_list->next;
699 }
700
701 if (context_scim && context_scim->impl)
702 {
703 _panel_client.prepare(context_scim->id);
704
705 if (context_scim == _focused_ic)
706 context_scim->impl->si->focus_out();
707
708 // Delete the instance.
709 EcoreIMFContextISF *old_focused = _focused_ic;
710 _focused_ic = context_scim;
711 context_scim->impl->si.reset();
712 _focused_ic = old_focused;
713
714 if (context_scim == _focused_ic)
715 {
716 _panel_client.turn_off(context_scim->id);
717 _panel_client.focus_out(context_scim->id);
718 }
719
720 _panel_client.remove_input_context(context_scim->id);
721 _panel_client.send();
722
723 if (context_scim->impl->client_window)
724 isf_imf_context_client_window_set(ctx, NULL);
725
726 if (context_scim->impl)
727 {
728 delete_ic_impl(context_scim->impl);
729 context_scim->impl = 0;
730 }
731 }
732
733 if (context_scim == _focused_ic)
734 _focused_ic = 0;
735
736 if (context_scim)
737 {
738 delete context_scim;
739 context_scim = 0;
740 }
741}
742
743/**
744 * isf_imf_context_client_canvas_set
745 * @ctx: a #Ecore_IMF_Context
746 * @canvas: the client canvas
747 *
748 * This function will be called by Ecore IMF.
749 *
750 * Set the client canvas for the Input Method Context; this is the canvas
751 * in which the input appears.
752 *
753 * The canvas type can be determined by using the context canvas type.
754 * Actually only canvas with type "evas" (Evas *) is supported. This canvas
755 * may be used in order to correctly position status windows, and may also
756 * be used for purposes internal to the Input Method Context.
757 */
758EAPI void
759isf_imf_context_client_canvas_set(Ecore_IMF_Context *ctx, void *canvas)
760{
761 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
762
763 EcoreIMFContextISF *context_scim = (EcoreIMFContextISF *)ecore_imf_context_data_get(ctx);
764
765 if (context_scim && context_scim->impl && context_scim->impl->client_canvas != (Evas*) canvas)
766 context_scim->impl->client_canvas = (Evas*)canvas;
767}
768
769/**
770 * isf_imf_context_client_window_set
771 * @ctx: a #Ecore_IMF_Context
772 * @window: the client window
773 *
774 * This function will be called by Ecore IMF.
775 *
776 * Set the client window for the Input Method Context; this is the Ecore_X_Window
777 * when using X11, Ecore_Win32_Window when using Win32, etc.
778 *
779 * This window is used in order to correctly position status windows,
780 * and may also be used for purposes internal to the Input Method Context.
781 */
782EAPI void
783isf_imf_context_client_window_set(Ecore_IMF_Context *ctx, void *window)
784{
785 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
786
787 EcoreIMFContextISF *context_scim = (EcoreIMFContextISF *)ecore_imf_context_data_get(ctx);
788
789 if (context_scim && context_scim->impl && context_scim->impl->client_window != (Ecore_X_Window)((Ecore_Window)window))
790 {
791 context_scim->impl->client_window = (Ecore_X_Window)((Ecore_Window)window);
792
793 if ((context_scim->impl->client_window != 0) &&
794 (context_scim->impl->client_window != _client_window))
795 _client_window = context_scim->impl->client_window;
796 }
797}
798
799/**
800 * isf_imf_context_reset
801 * @ctx: a #Ecore_IMF_Context
802 *
803 * This function will be called by Ecore IMF.
804 *
805 * Notify the Input Method Context that a change such as a change in cursor
806 * position has been made. This will typically cause the Input Method Context
807 * to clear the preedit state.
808 */
809EAPI void
810isf_imf_context_reset(Ecore_IMF_Context *ctx)
811{
812 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
813
814 EcoreIMFContextISF *context_scim = (EcoreIMFContextISF *)ecore_imf_context_data_get(ctx);
815
816 if (context_scim && context_scim->impl && context_scim == _focused_ic)
817 {
818 WideString wstr = context_scim->impl->preedit_string;
819
820 _panel_client.prepare(context_scim->id);
821 context_scim->impl->si->reset();
822 _panel_client.send();
823
824 if (context_scim->impl->need_commit_preedit)
825 {
826 if (wstr.length())
827 {
828 ecore_imf_context_commit_event_add(context_scim->ctx, utf8_wcstombs(wstr).c_str());
829 ecore_imf_context_event_callback_call(context_scim->ctx, ECORE_IMF_CALLBACK_COMMIT, (void *)utf8_wcstombs(wstr).c_str());
830 }
831 _panel_client.prepare(context_scim->id);
832 _panel_client.send();
833 }
834 }
835}
836
837/**
838 * isf_imf_context_focus_in
839 * @ctx: a #Ecore_IMF_Context
840 *
841 * This function will be called by Ecore IMF.
842 *
843 * Notify the Input Method Context that the widget to which its correspond has gained focus.
844 */
845EAPI void
846isf_imf_context_focus_in(Ecore_IMF_Context *ctx)
847{
848 EcoreIMFContextISF *context_scim = (EcoreIMFContextISF *)ecore_imf_context_data_get(ctx);
849
850 if (!context_scim)
851 return;
852
853 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__<< "(" << context_scim->id << ")...\n";
854
855 if (_focused_ic)
856 {
857 if (_focused_ic == context_scim)
858 {
859 SCIM_DEBUG_FRONTEND(1) << "It's already focused.\n";
860 return;
861 }
862 SCIM_DEBUG_FRONTEND(1) << "Focus out previous IC first: " << _focused_ic->id << "\n";
863 if (_focused_ic->ctx)
864 isf_imf_context_focus_out(_focused_ic->ctx);
865 }
866
867 bool need_cap = false;
868 bool need_reset = false;
869 bool need_reg = false;
870
871 if (context_scim && context_scim->impl)
872 {
873 _focused_ic = context_scim;
874 _panel_client.prepare(context_scim->id);
875
876 // Handle the "Shared Input Method" mode.
877 if (_shared_input_method)
878 {
879 SCIM_DEBUG_FRONTEND(2) << "shared input method.\n";
880 IMEngineFactoryPointer factory = _backend->get_default_factory(_language, "UTF-8");
881 if (!factory.null())
882 {
883 if (_default_instance.null() || _default_instance->get_factory_uuid() != factory->get_uuid())
884 {
885 _default_instance = factory->create_instance("UTF-8", _default_instance.null() ? _instance_count++ : _default_instance->get_id());
886 attach_instance(_default_instance);
887 SCIM_DEBUG_FRONTEND(2) << "create new default instance: " << _default_instance->get_id() << " " << _default_instance->get_factory_uuid() << "\n";
888 }
889
890 context_scim->impl->shared_si = true;
891 context_scim->impl->si = _default_instance;
892
893 context_scim->impl->is_on = _config->read(String(SCIM_CONFIG_FRONTEND_IM_OPENED_BY_DEFAULT), context_scim->impl->is_on);
894 context_scim->impl->preedit_string.clear();
895 context_scim->impl->preedit_attrlist.clear();
896 context_scim->impl->preedit_caret = 0;
897 context_scim->impl->preedit_started = false;
898 need_cap = true;
899 need_reset = true;
900 need_reg = true;
901 }
902 }
903 else if (context_scim->impl->shared_si)
904 {
905 SCIM_DEBUG_FRONTEND(2) << "exit shared input method.\n";
906 IMEngineFactoryPointer factory = _backend->get_default_factory(_language, "UTF-8");
907 if (!factory.null())
908 {
909 context_scim->impl->si = factory->create_instance("UTF-8", _instance_count++);
910 context_scim->impl->preedit_string.clear();
911 context_scim->impl->preedit_attrlist.clear();
912 context_scim->impl->preedit_caret = 0;
913 context_scim->impl->preedit_started = false;
914 attach_instance(context_scim->impl->si);
915 need_cap = true;
916 need_reg = true;
917 context_scim->impl->shared_si = false;
918 SCIM_DEBUG_FRONTEND(2) << "create new instance: " << context_scim->impl->si->get_id() << " " << context_scim->impl->si->get_factory_uuid() << "\n";
919 }
920 }
921
922 context_scim->impl->si->set_frontend_data(static_cast <void*>(context_scim));
923
924 if (need_reg) _panel_client.register_input_context(context_scim->id, context_scim->impl->si->get_factory_uuid());
925 if (need_cap) set_ic_capabilities(context_scim);
926 if (need_reset) context_scim->impl->si->reset();
927
928 panel_req_focus_in(context_scim);
929 panel_req_update_spot_location(context_scim);
930 panel_req_update_factory_info(context_scim);
931
932 if (context_scim->impl->is_on)
933 {
934 _panel_client.turn_on(context_scim->id);
935 _panel_client.hide_preedit_string(context_scim->id);
936 _panel_client.hide_aux_string(context_scim->id);
937 _panel_client.hide_lookup_table(context_scim->id);
938 context_scim->impl->si->focus_in();
939 }
940 else
941 {
942 _panel_client.turn_off(context_scim->id);
943 }
944
945 _panel_client.send();
946 }
947
948 if (ecore_imf_context_input_panel_enabled_get(ctx))
949 ecore_imf_context_input_panel_show(ctx);
950}
951
952/**
953 * isf_imf_context_focus_out
954 * @ctx: a #Ecore_IMF_Context
955 *
956 * This function will be called by Ecore IMF.
957 *
958 * Notify the Input Method Context that the widget to which its correspond has lost focus.
959 */
960EAPI void
961isf_imf_context_focus_out(Ecore_IMF_Context *ctx)
962{
963 EcoreIMFContextISF *context_scim = (EcoreIMFContextISF *)ecore_imf_context_data_get(ctx);
964
965 if (!context_scim) return;
966
967 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "(" << context_scim->id << ")...\n";
968
969 if (context_scim && context_scim->impl && context_scim == _focused_ic)
970 {
971 WideString wstr = context_scim->impl->preedit_string;
972
973 if (context_scim->impl->need_commit_preedit)
974 {
975 if (wstr.length())
976 {
977 ecore_imf_context_commit_event_add(context_scim->ctx, utf8_wcstombs(wstr).c_str());
978 ecore_imf_context_event_callback_call(context_scim->ctx, ECORE_IMF_CALLBACK_COMMIT, (void *)utf8_wcstombs(wstr).c_str());
979 }
980 _panel_client.prepare(context_scim->id);
981 _panel_client.send();
982 }
983
984 _panel_client.prepare(context_scim->id);
985 context_scim->impl->si->focus_out();
986 context_scim->impl->si->reset();
987 _panel_client.turn_off(context_scim->id);
988 _panel_client.focus_out(context_scim->id);
989 _panel_client.send();
990 _focused_ic = 0;
991 }
992
993 if (ecore_imf_context_input_panel_enabled_get(ctx))
994 ecore_imf_context_input_panel_hide(ctx);
995}
996
997/**
998 * isf_imf_context_cursor_location_set
999 * @ctx: a #Ecore_IMF_Context
1000 * @x: x position of New cursor.
1001 * @y: y position of New cursor.
1002 * @w: the width of New cursor.
1003 * @h: the height of New cursor.
1004 *
1005 * This function will be called by Ecore IMF.
1006 *
1007 * Notify the Input Method Context that a change in the cursor location has been made.
1008 */
1009EAPI void
1010isf_imf_context_cursor_location_set(Ecore_IMF_Context *ctx, int cx, int cy, int cw, int ch)
1011{
1012 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1013
1014 EcoreIMFContextISF *context_scim = (EcoreIMFContextISF *)ecore_imf_context_data_get(ctx);
1015 Ecore_Evas *ee;
1016 int canvas_x, canvas_y;
1017
1018 if (cw == 0 && ch == 0)
1019 return;
1020
1021 if (context_scim && context_scim->impl && context_scim == _focused_ic)
1022 {
1023 // Don't update spot location while updating preedit string.
1024 if (context_scim->impl->preedit_updating)
1025 return;
1026
1027 if (context_scim->impl->client_canvas)
1028 {
1029 ee = ecore_evas_ecore_evas_get(context_scim->impl->client_canvas);
1030 if (!ee) return;
1031
1032 ecore_evas_geometry_get(ee, &canvas_x, &canvas_y, NULL, NULL);
1033 }
1034 else
1035 {
1036 if (context_scim->impl->client_window)
1037 window_to_screen_geometry_get(context_scim->impl->client_window, &canvas_x, &canvas_y);
1038 else
1039 return;
1040 }
1041
1042 if (context_scim->impl->cursor_x != canvas_x + cx || context_scim->impl->cursor_y != canvas_y + cy + ch)
1043 {
1044 context_scim->impl->cursor_x = canvas_x + cx;
1045 context_scim->impl->cursor_y = canvas_y + cy + ch;
1046 _panel_client.prepare(context_scim->id);
1047 panel_req_update_spot_location(context_scim);
1048 _panel_client.send();
1049 SCIM_DEBUG_FRONTEND(2) << "new cursor location = " << context_scim->impl->cursor_x << "," << context_scim->impl->cursor_y << "\n";
1050 }
1051 }
1052}
1053
1054/**
1055 * isf_imf_context_use_preedit_set
1056 * @ctx: a #Ecore_IMF_Context
1057 * @use_preedit: Whether the IM context should use the preedit string.
1058 *
1059 * This function will be called by Ecore IMF.
1060 *
1061 * Set whether the IM context should use the preedit string to display feedback.
1062 * If is 0 (default is 1), then the IM context may use some other method to
1063 * display feedback, such as displaying it in a child of the root window.
1064 */
1065EAPI void
1066isf_imf_context_use_preedit_set(Ecore_IMF_Context* ctx, Eina_Bool use_preedit)
1067{
1068 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " = " << (use_preedit ? "true" : "false") << "...\n";
1069
1070 EcoreIMFContextISF *context_scim = (EcoreIMFContextISF*)ecore_imf_context_data_get(ctx);
1071
1072 if (!_on_the_spot) return;
1073
1074 if (context_scim && context_scim->impl)
1075 {
1076 bool old = context_scim->impl->use_preedit;
1077 context_scim->impl->use_preedit = use_preedit;
1078 if (context_scim == _focused_ic)
1079 {
1080 _panel_client.prepare(context_scim->id);
1081
1082 if (old != use_preedit)
1083 set_ic_capabilities(context_scim);
1084
1085 if (context_scim->impl->preedit_string.length())
1086 slot_show_preedit_string(context_scim->impl->si);
1087
1088 _panel_client.send();
1089 }
1090 }
1091}
1092
1093EAPI void
1094isf_imf_context_preedit_string_with_attributes_get(Ecore_IMF_Context *ctx, char** str, Eina_List **attrs, int *cursor_pos)
1095{
1096 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1097
1098 EcoreIMFContextISF *context_scim = (EcoreIMFContextISF*)ecore_imf_context_data_get(ctx);
1099
1100 if (context_scim && context_scim->impl && context_scim->impl->is_on)
1101 {
1102 String mbs = utf8_wcstombs(context_scim->impl->preedit_string);
1103
1104 if (str)
1105 {
1106 if (mbs.length())
1107 *str = strdup(mbs.c_str());
1108 else
1109 *str = strdup("");
1110 }
1111
1112 if (cursor_pos)
1113 {
1114 *cursor_pos = context_scim->impl->preedit_caret;
1115 }
1116
1117 if (attrs)
1118 {
1119 if (mbs.length())
1120 {
1121 int start_index, end_index;
1122 int wlen = context_scim->impl->preedit_string.length();
1123
1124 Ecore_IMF_Preedit_Attr *attr = NULL;
1125 AttributeList::const_iterator i;
1126 bool *attrs_flag = new bool [mbs.length()];
1127 memset(attrs_flag, 0, mbs.length() *sizeof(bool));
1128
1129 for (i = context_scim->impl->preedit_attrlist.begin();
1130 i != context_scim->impl->preedit_attrlist.end(); ++i)
1131 {
1132 start_index = i->get_start();
1133 end_index = i->get_end();
1134
1135 if (end_index <= wlen && start_index < end_index && i->get_type() != SCIM_ATTR_DECORATE_NONE)
1136 {
1137 start_index = utf8_offset_to_index(mbs.c_str(), i->get_start());
1138 end_index = utf8_offset_to_index(mbs.c_str(), i->get_end());
1139
1140 if (i->get_type() == SCIM_ATTR_DECORATE)
1141 {
1142 attr = (Ecore_IMF_Preedit_Attr *)calloc(1, sizeof(Ecore_IMF_Preedit_Attr));
1143 if (attr == NULL)
1144 continue;
1145 attr->start_index = start_index;
1146 attr->end_index = end_index;
1147
1148 if (i->get_value() == SCIM_ATTR_DECORATE_UNDERLINE)
1149 {
1150 attr->preedit_type = ECORE_IMF_PREEDIT_TYPE_SUB1;
1151 *attrs = eina_list_append(*attrs, (void *)attr);
1152 }
1153 else if (i->get_value() == SCIM_ATTR_DECORATE_REVERSE)
1154 {
1155 attr->preedit_type = ECORE_IMF_PREEDIT_TYPE_SUB2;
1156 *attrs = eina_list_append(*attrs, (void *)attr);
1157 }
1158 else if (i->get_value() == SCIM_ATTR_DECORATE_HIGHLIGHT)
1159 {
1160 attr->preedit_type = ECORE_IMF_PREEDIT_TYPE_SUB3;
1161 *attrs = eina_list_append(*attrs, (void *)attr);
1162 }
1163 else
1164 {
1165 free(attr);
1166 }
1167
1168 switch(i->get_value())
1169 {
1170 case SCIM_ATTR_DECORATE_UNDERLINE:
1171 case SCIM_ATTR_DECORATE_REVERSE:
1172 case SCIM_ATTR_DECORATE_HIGHLIGHT:
1173 // Record which character has attribute.
1174 for (int pos = start_index; pos < end_index; ++pos)
1175 attrs_flag [pos] = 1;
1176 break;
1177 default:
1178 break;
1179 }
1180 }
1181 else if (i->get_type() == SCIM_ATTR_FOREGROUND)
1182 {
1183 SCIM_DEBUG_FRONTEND(4) << "SCIM_ATTR_FOREGROUND\n";
1184 }
1185 else if (i->get_type() == SCIM_ATTR_BACKGROUND)
1186 {
1187 SCIM_DEBUG_FRONTEND(4) << "SCIM_ATTR_BACKGROUND\n";
1188 }
1189 }
1190 }
1191
1192 // Add underline for all characters which don't have attribute.
1193 for (unsigned int pos = 0; pos < mbs.length(); ++pos)
1194 {
1195 if (!attrs_flag [pos])
1196 {
1197 int begin_pos = pos;
1198
1199 while (pos < mbs.length() && !attrs_flag[pos])
1200 ++pos;
1201
1202 // use REVERSE style as default
1203 attr = (Ecore_IMF_Preedit_Attr *)calloc(1, sizeof(Ecore_IMF_Preedit_Attr));
1204 if (attr == NULL)
1205 continue;
1206 attr->preedit_type = ECORE_IMF_PREEDIT_TYPE_SUB2;
1207 attr->start_index = begin_pos;
1208 attr->end_index = pos;
1209 *attrs = eina_list_append(*attrs, (void *)attr);
1210 }
1211 }
1212
1213 delete [] attrs_flag;
1214 }
1215 }
1216 }
1217 else
1218 {
1219 if (str)
1220 *str = strdup("");
1221
1222 if (cursor_pos)
1223 *cursor_pos = 0;
1224
1225 if (attrs)
1226 *attrs = NULL;
1227 }
1228}
1229
1230/**
1231 * isf_imf_context_preedit_string_get
1232 * @ctx: a #Ecore_IMF_Context
1233 * @str: the preedit string
1234 * @cursor_pos: the cursor position
1235 *
1236 * This function will be called by Ecore IMF.
1237 *
1238 * To get the preedit string of the input method.
1239 */
1240EAPI void
1241isf_imf_context_preedit_string_get(Ecore_IMF_Context *ctx, char** str, int *cursor_pos)
1242{
1243 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1244
1245 EcoreIMFContextISF *context_scim = (EcoreIMFContextISF*)ecore_imf_context_data_get(ctx);
1246
1247 if (context_scim && context_scim->impl && context_scim->impl->is_on)
1248 {
1249 String mbs = utf8_wcstombs(context_scim->impl->preedit_string);
1250
1251 if (str)
1252 {
1253 if (mbs.length())
1254 *str = strdup(mbs.c_str());
1255 else
1256 *str = strdup("");
1257 }
1258
1259 if (cursor_pos)
1260 *cursor_pos = context_scim->impl->preedit_caret;
1261 }
1262 else
1263 {
1264 if (str)
1265 *str = strdup("");
1266
1267 if (cursor_pos)
1268 *cursor_pos = 0;
1269 }
1270}
1271
1272/**
1273 * isf_imf_context_cursor_position_set
1274 * @ctx: a #Ecore_IMF_Context
1275 * @cursor_pos: New cursor position in characters.
1276 *
1277 * This function will be called by Ecore IMF.
1278 *
1279 * Notify the Input Method Context that a change in the cursor position has been made.
1280 */
1281EAPI void
1282isf_imf_context_cursor_position_set(Ecore_IMF_Context *ctx, int cursor_pos)
1283{
1284 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1285
1286 EcoreIMFContextISF *context_scim = (EcoreIMFContextISF *)ecore_imf_context_data_get(ctx);
1287
1288 if (context_scim && context_scim->impl && context_scim == _focused_ic)
1289 {
1290 // Don't update spot location while updating preedit string.
1291 if (context_scim->impl->preedit_updating)
1292 return;
1293
1294 if (context_scim->impl->cursor_pos != cursor_pos)
1295 {
1296 context_scim->impl->cursor_pos = cursor_pos;
1297 caps_mode_check(ctx, EINA_FALSE);
1298 }
1299 }
1300}
1301
1302/**
1303 * isf_imf_context_input_mode_set
1304 * @ctx: a #Ecore_IMF_Context
1305 * @input_mode: the input mode
1306 *
1307 * This function will be called by Ecore IMF.
1308 *
1309 * To set the input mode of input method. The definition of Ecore_IMF_Input_Mode
1310 * is in Ecore_IMF.h.
1311 */
1312EAPI void
1313isf_imf_context_input_mode_set(Ecore_IMF_Context *ctx, Ecore_IMF_Input_Mode input_mode)
1314{
1315 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1316
1317 EcoreIMFContextISF *context_scim = (EcoreIMFContextISF*)ecore_imf_context_data_get(ctx);
1318 if (context_scim && context_scim->impl)
1319 context_scim->impl->input_mode = input_mode;
1320}
1321
1322/**
1323 * isf_imf_context_prediction_allow_set
1324 * @ctx: a #Ecore_IMF_Context
1325 * @use_prediction: Whether the IM context should use the prediction.
1326 *
1327 * This function will be called by Ecore IMF.
1328 *
1329 * Set whether the IM context should use the prediction.
1330 */
1331EAPI void
1332isf_imf_context_prediction_allow_set(Ecore_IMF_Context* ctx, Eina_Bool prediction)
1333{
1334 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " = " << (prediction ? "true" : "false") << "...\n";
1335
1336 EcoreIMFContextISF *context_scim = (EcoreIMFContextISF *)ecore_imf_context_data_get(ctx);
1337
1338 if (context_scim && context_scim->impl && context_scim->impl->prediction_allow != prediction)
1339 context_scim->impl->prediction_allow = prediction;
1340}
1341
1342EAPI void
1343isf_imf_context_autocapital_type_set(Ecore_IMF_Context* ctx, Ecore_IMF_Autocapital_Type autocapital_type)
1344{
1345 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " = " << autocapital_type << "...\n";
1346
1347 EcoreIMFContextISF *context_scim = (EcoreIMFContextISF *)ecore_imf_context_data_get(ctx);
1348
1349 if (context_scim && context_scim->impl && context_scim->impl->autocapital_type != autocapital_type)
1350 context_scim->impl->autocapital_type = autocapital_type;
1351}
1352
1353/**
1354 * isf_imf_context_filter_event
1355 * @ctx: a #Ecore_IMF_Context
1356 * @type: The type of event defined by Ecore_IMF_Event_Type.
1357 * @event: The event itself.
1358 * Return value: %TRUE if the input method handled the key event.
1359 *
1360 * This function will be called by Ecore IMF.
1361 *
1362 * Allow an Ecore Input Context to internally handle an event. If this function
1363 * returns 1, then no further processing should be done for this event. Input
1364 * methods must be able to accept all types of events (simply returning 0 if
1365 * the event was not handled), but there is no obligation of any events to be
1366 * submitted to this function.
1367 */
1368
1369EAPI Eina_Bool
1370isf_imf_context_filter_event(Ecore_IMF_Context *ctx, Ecore_IMF_Event_Type type, Ecore_IMF_Event *event)
1371{
1372 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1373
1374 EcoreIMFContextISF *ic = (EcoreIMFContextISF*)ecore_imf_context_data_get(ctx);
1375 Eina_Bool ret = EINA_FALSE;
1376
1377 if (ic == NULL || ic->impl == NULL)
1378 return ret;
1379
1380 KeyEvent key;
1381
1382 if (type == ECORE_IMF_EVENT_KEY_DOWN)
1383 {
1384 Ecore_IMF_Event_Key_Down *ev = (Ecore_IMF_Event_Key_Down *)event;
1385 scim_string_to_key(key, ev->key);
1386 if (ev->modifiers & ECORE_IMF_KEYBOARD_MODIFIER_SHIFT) key.mask |=SCIM_KEY_ShiftMask;
1387 if (ev->modifiers & ECORE_IMF_KEYBOARD_MODIFIER_CTRL) key.mask |=SCIM_KEY_ControlMask;
1388 if (ev->modifiers & ECORE_IMF_KEYBOARD_MODIFIER_ALT) key.mask |=SCIM_KEY_AltMask;
1389 if (ev->locks & ECORE_IMF_KEYBOARD_LOCK_CAPS) key.mask |=SCIM_KEY_CapsLockMask;
1390 if (ev->locks & ECORE_IMF_KEYBOARD_LOCK_NUM) key.mask |=SCIM_KEY_NumLockMask;
1391 }
1392 else if (type == ECORE_IMF_EVENT_KEY_UP)
1393 {
1394 Ecore_IMF_Event_Key_Up *ev = (Ecore_IMF_Event_Key_Up *)event;
1395 scim_string_to_key(key, ev->key);
1396 key.mask = SCIM_KEY_ReleaseMask;
1397 if (ev->modifiers & ECORE_IMF_KEYBOARD_MODIFIER_SHIFT) key.mask |=SCIM_KEY_ShiftMask;
1398 if (ev->modifiers & ECORE_IMF_KEYBOARD_MODIFIER_CTRL) key.mask |=SCIM_KEY_ControlMask;
1399 if (ev->modifiers & ECORE_IMF_KEYBOARD_MODIFIER_ALT) key.mask |=SCIM_KEY_AltMask;
1400 if (ev->locks & ECORE_IMF_KEYBOARD_LOCK_CAPS) key.mask |=SCIM_KEY_CapsLockMask;
1401 if (ev->locks & ECORE_IMF_KEYBOARD_LOCK_NUM) key.mask |=SCIM_KEY_NumLockMask;
1402 }
1403 else
1404 {
1405 return ret;
1406 }
1407
1408 key.mask &= _valid_key_mask;
1409
1410 _panel_client.prepare(ic->id);
1411
1412 ret = EINA_TRUE;
1413 if (!filter_hotkeys(ic, key))
1414 {
1415 if (!_focused_ic || !_focused_ic->impl->is_on ||
1416 !_focused_ic->impl->si->process_key_event(key))
1417 ret = EINA_FALSE;
1418 }
1419
1420 _panel_client.send();
1421
1422 return ret;
1423}
1424
1425EAPI void
1426isf_imf_context_input_panel_show(Ecore_IMF_Context *ctx)
1427{
1428 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1429
1430 EcoreIMFContextISF *ic = (EcoreIMFContextISF*)ecore_imf_context_data_get(ctx);
1431 if (ic == NULL || ic->impl == NULL)
1432 return;
1433
1434 ecore_x_e_virtual_keyboard_state_set
1435 (ic->impl->client_window, ECORE_X_VIRTUAL_KEYBOARD_STATE_ON);
1436}
1437
1438EAPI void
1439isf_imf_context_input_panel_hide(Ecore_IMF_Context *ctx)
1440{
1441 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1442
1443 EcoreIMFContextISF *ic = (EcoreIMFContextISF*)ecore_imf_context_data_get(ctx);
1444 if (ic == NULL || ic->impl == NULL)
1445 return;
1446
1447 ecore_x_e_virtual_keyboard_state_set
1448 (ic->impl->client_window, ECORE_X_VIRTUAL_KEYBOARD_STATE_OFF);
1449}
1450
1451/* Panel Slot functions */
1452static void
1453panel_slot_reload_config(int context __UNUSED__)
1454{
1455 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1456 _config->reload();
1457}
1458
1459static void
1460panel_slot_exit(int /* context */)
1461{
1462 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1463
1464 finalize();
1465}
1466
1467static void
1468panel_slot_update_lookup_table_page_size(int context, int page_size)
1469{
1470 EcoreIMFContextISF *ic = find_ic(context);
1471 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " context=" << context << " page_size=" << page_size << " ic=" << ic << "\n";
1472 if (ic && ic->impl)
1473 {
1474 _panel_client.prepare(ic->id);
1475 ic->impl->si->update_lookup_table_page_size(page_size);
1476 _panel_client.send();
1477 }
1478}
1479
1480static void
1481panel_slot_lookup_table_page_up(int context)
1482{
1483 EcoreIMFContextISF *ic = find_ic(context);
1484 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " context=" << context << " ic=" << ic << "\n";
1485 if (ic && ic->impl)
1486 {
1487 _panel_client.prepare(ic->id);
1488 ic->impl->si->lookup_table_page_up();
1489 _panel_client.send();
1490 }
1491}
1492
1493static void
1494panel_slot_lookup_table_page_down(int context)
1495{
1496 EcoreIMFContextISF *ic = find_ic(context);
1497 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " context=" << context << " ic=" << ic << "\n";
1498 if (ic && ic->impl)
1499 {
1500 _panel_client.prepare(ic->id);
1501 ic->impl->si->lookup_table_page_down();
1502 _panel_client.send();
1503 }
1504}
1505
1506static void
1507panel_slot_trigger_property(int context, const String &property)
1508{
1509 EcoreIMFContextISF *ic = find_ic(context);
1510 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " context=" << context << " property=" << property << " ic=" << ic << "\n";
1511 if (ic && ic->impl)
1512 {
1513 _panel_client.prepare(ic->id);
1514 ic->impl->si->trigger_property(property);
1515 _panel_client.send();
1516 }
1517}
1518
1519static void
1520panel_slot_process_helper_event(int context, const String &target_uuid, const String &helper_uuid, const Transaction &trans)
1521{
1522 EcoreIMFContextISF *ic = find_ic(context);
1523 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " context=" << context << " target=" << target_uuid
1524 << " helper=" << helper_uuid << " ic=" << ic << " ic->impl=" << (ic ? ic->impl : 0) << " ic-uuid="
1525 << ((ic && ic->impl) ? ic->impl->si->get_factory_uuid() : "" ) << "\n";
1526 if (ic && ic->impl && ic->impl->si->get_factory_uuid() == target_uuid)
1527 {
1528 _panel_client.prepare(ic->id);
1529 SCIM_DEBUG_FRONTEND(2) << "call process_helper_event\n";
1530 ic->impl->si->process_helper_event(helper_uuid, trans);
1531 _panel_client.send();
1532 }
1533}
1534
1535static void
1536panel_slot_move_preedit_caret(int context, int caret_pos)
1537{
1538 EcoreIMFContextISF *ic = find_ic(context);
1539 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " context=" << context << " caret=" << caret_pos << " ic=" << ic << "\n";
1540 if (ic && ic->impl)
1541 {
1542 _panel_client.prepare(ic->id);
1543 ic->impl->si->move_preedit_caret(caret_pos);
1544 _panel_client.send();
1545 }
1546}
1547
1548static void
1549panel_slot_select_candidate(int context, int cand_index)
1550{
1551 EcoreIMFContextISF *ic = find_ic(context);
1552 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " context=" << context << " candidate=" << cand_index << " ic=" << ic << "\n";
1553 if (ic && ic->impl)
1554 {
1555 _panel_client.prepare(ic->id);
1556 ic->impl->si->select_candidate(cand_index);
1557 _panel_client.send();
1558 }
1559}
1560
1561static void
1562panel_slot_process_key_event(int context, const KeyEvent &key)
1563{
1564 EcoreIMFContextISF *ic = find_ic(context);
1565 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " context=" << context << " key=" << key.get_key_string() << " ic=" << ic << "\n";
1566
1567 if (key.is_key_press())
1568 ecore_x_test_fake_key_press(key.get_key_string().c_str());
1569}
1570
1571static void
1572panel_slot_commit_string(int context, const WideString &wstr)
1573{
1574 EcoreIMFContextISF *ic = find_ic(context);
1575 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " context=" << context << " str=" << utf8_wcstombs(wstr) << " ic=" << ic << "\n";
1576
1577 if (ic && ic->impl)
1578 {
1579 if (_focused_ic != ic)
1580 return;
1581
1582 ecore_imf_context_commit_event_add(ic->ctx, utf8_wcstombs(wstr).c_str());
1583 ecore_imf_context_event_callback_call(ic->ctx, ECORE_IMF_CALLBACK_COMMIT, (void *)utf8_wcstombs(wstr).c_str());
1584 }
1585}
1586
1587static void
1588panel_slot_forward_key_event(int context, const KeyEvent &key)
1589{
1590 EcoreIMFContextISF *ic = find_ic(context);
1591 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " context=" << context << " key=" << key.get_key_string() << " ic=" << ic << "\n";
1592
1593 if (ic && ic->impl && ic->impl->client_canvas)
1594 feed_key_event(ic->impl->client_canvas, key.get_key_string().c_str(), EINA_TRUE);
1595}
1596
1597static void
1598panel_slot_request_help(int context)
1599{
1600 EcoreIMFContextISF *ic = find_ic(context);
1601 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " context=" << context << " ic=" << ic << "\n";
1602
1603 if (ic && ic->impl)
1604 {
1605 _panel_client.prepare(ic->id);
1606 panel_req_show_help(ic);
1607 _panel_client.send();
1608 }
1609}
1610
1611static void
1612panel_slot_request_factory_menu(int context)
1613{
1614 EcoreIMFContextISF *ic = find_ic(context);
1615 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " context=" << context << " ic=" << ic << "\n";
1616
1617 if (ic && ic->impl)
1618 {
1619 _panel_client.prepare(ic->id);
1620 panel_req_show_factory_menu(ic);
1621 _panel_client.send();
1622 }
1623}
1624
1625static void
1626panel_slot_change_factory(int context, const String &uuid)
1627{
1628 EcoreIMFContextISF *ic = find_ic(context);
1629 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " context=" << context << " factory=" << uuid << " ic=" << ic << "\n";
1630
1631 if (ic && ic->impl)
1632 {
1633 ic->impl->si->reset();
1634 _panel_client.prepare(ic->id);
1635 open_specific_factory(ic, uuid);
1636 _panel_client.send();
1637 }
1638}
1639
1640/* Panel Requestion functions. */
1641static void
1642panel_req_show_help(EcoreIMFContextISF *ic)
1643{
1644 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1645
1646 String help;
1647
1648 help = String("Smart Common Input Method platform ") +
1649 //String(SCIM_VERSION) +
1650 String("\n(C) 2002-2005 James Su <suzhe@tsinghua.org.cn>\n\n");
1651
1652 if (ic && ic->impl)
1653 {
1654 IMEngineFactoryPointer sf = _backend->get_factory(ic->impl->si->get_factory_uuid());
1655 if (sf)
1656 {
1657 help += utf8_wcstombs(sf->get_name());
1658 help += String(":\n\n");
1659
1660 help += utf8_wcstombs(sf->get_help());
1661 help += String("\n\n");
1662
1663 help += utf8_wcstombs(sf->get_credits());
1664 }
1665 _panel_client.show_help(ic->id, help);
1666 }
1667}
1668
1669static void
1670panel_req_show_factory_menu(EcoreIMFContextISF *ic)
1671{
1672 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1673
1674 std::vector<IMEngineFactoryPointer> factories;
1675 std::vector <PanelFactoryInfo> menu;
1676
1677 _backend->get_factories_for_encoding(factories, "UTF-8");
1678
1679 for (size_t i = 0; i < factories.size(); ++ i)
1680 {
1681 menu.push_back(PanelFactoryInfo(
1682 factories [i]->get_uuid(),
1683 utf8_wcstombs(factories [i]->get_name()),
1684 factories [i]->get_language(),
1685 factories [i]->get_icon_file()));
1686 }
1687
1688 if (menu.size())
1689 _panel_client.show_factory_menu(ic->id, menu);
1690}
1691
1692static void
1693panel_req_update_factory_info(EcoreIMFContextISF *ic)
1694{
1695 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1696
1697 if (ic && ic->impl && ic == _focused_ic)
1698 {
1699 PanelFactoryInfo info;
1700 if (ic->impl->is_on)
1701 {
1702 IMEngineFactoryPointer sf = _backend->get_factory(ic->impl->si->get_factory_uuid());
1703 if (sf)
1704 info = PanelFactoryInfo(sf->get_uuid(), utf8_wcstombs(sf->get_name()), sf->get_language(), sf->get_icon_file());
1705 }
1706 else
1707 {
1708 info = PanelFactoryInfo(String(""), String("English/Keyboard"), String("C"), "");
1709 }
1710 _panel_client.update_factory_info(ic->id, info);
1711 }
1712}
1713
1714static void
1715panel_req_focus_in(EcoreIMFContextISF *ic)
1716{
1717 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1718
1719 _panel_client.focus_in(ic->id, ic->impl->si->get_factory_uuid());
1720}
1721
1722static void
1723panel_req_update_spot_location(EcoreIMFContextISF *ic)
1724{
1725 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1726
1727 _panel_client.update_spot_location(ic->id, ic->impl->cursor_x, ic->impl->cursor_y);
1728}
1729
1730static bool
1731filter_hotkeys(EcoreIMFContextISF *ic, const KeyEvent &key)
1732{
1733 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1734
1735 bool ret = false;
1736
1737 _frontend_hotkey_matcher.push_key_event(key);
1738 _imengine_hotkey_matcher.push_key_event(key);
1739
1740 FrontEndHotkeyAction hotkey_action = _frontend_hotkey_matcher.get_match_result();
1741
1742 if (hotkey_action == SCIM_FRONTEND_HOTKEY_TRIGGER)
1743 {
1744 if (!ic->impl->is_on)
1745 turn_on_ic(ic);
1746 else
1747 turn_off_ic(ic);
1748 ret = true;
1749 }
1750 else if (hotkey_action == SCIM_FRONTEND_HOTKEY_ON)
1751 {
1752 if (!ic->impl->is_on)
1753 turn_on_ic(ic);
1754 ret = true;
1755 }
1756 else if (hotkey_action == SCIM_FRONTEND_HOTKEY_OFF)
1757 {
1758 if (ic->impl->is_on)
1759 turn_off_ic(ic);
1760 ret = true;
1761 }
1762 else if (hotkey_action == SCIM_FRONTEND_HOTKEY_NEXT_FACTORY)
1763 {
1764 open_next_factory(ic);
1765 ret = true;
1766 }
1767 else if (hotkey_action == SCIM_FRONTEND_HOTKEY_PREVIOUS_FACTORY)
1768 {
1769 open_previous_factory(ic);
1770 ret = true;
1771 }
1772 else if (hotkey_action == SCIM_FRONTEND_HOTKEY_SHOW_FACTORY_MENU)
1773 {
1774 panel_req_show_factory_menu(ic);
1775 ret = true;
1776 }
1777 else if (_imengine_hotkey_matcher.is_matched())
1778 {
1779 String sfid = _imengine_hotkey_matcher.get_match_result();
1780 open_specific_factory(ic, sfid);
1781 ret = true;
1782 }
1783 return ret;
1784}
1785
1786static bool
1787panel_initialize(void)
1788{
1789 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1790
1791 String display_name;
1792 {
1793 const char *p = getenv("DISPLAY");
1794 if (p) display_name = String(p);
1795 }
1796
1797 if (_panel_client.open_connection(_config->get_name(), display_name) >= 0)
1798 {
1799 int fd = _panel_client.get_connection_number();
1800
1801 _panel_iochannel_read_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, panel_iochannel_handler, NULL, NULL, NULL);
1802
1803 SCIM_DEBUG_FRONTEND(2) << " Panel FD= " << fd << "\n";
1804
1805 return true;
1806 }
1807 std::cerr << "panel_initialize() failed!!!\n";
1808 return false;
1809}
1810
1811static void
1812panel_finalize(void)
1813{
1814 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1815
1816 _panel_client.close_connection();
1817
1818 if (_panel_iochannel_read_handler)
1819 {
1820 ecore_main_fd_handler_del(_panel_iochannel_read_handler);
1821 _panel_iochannel_read_handler = 0;
1822 }
1823
1824 if (_panel_iochannel_err_handler)
1825 {
1826 ecore_main_fd_handler_del(_panel_iochannel_err_handler);
1827 _panel_iochannel_err_handler = 0;
1828 }
1829}
1830
1831static Eina_Bool
1832panel_iochannel_handler(void *data __UNUSED__, Ecore_Fd_Handler *fd_handler)
1833{
1834 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1835
1836 if (fd_handler == _panel_iochannel_read_handler)
1837 {
1838 if (!_panel_client.filter_event())
1839 {
1840 panel_finalize();
1841 panel_initialize();
1842 return ECORE_CALLBACK_CANCEL;
1843 }
1844 }
1845 else if (fd_handler == _panel_iochannel_err_handler)
1846 {
1847 panel_finalize();
1848 panel_initialize();
1849 return ECORE_CALLBACK_CANCEL;
1850 }
1851 return ECORE_CALLBACK_RENEW;
1852}
1853
1854static void
1855turn_on_ic(EcoreIMFContextISF *ic)
1856{
1857 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1858
1859 if (ic && ic->impl && !ic->impl->is_on)
1860 {
1861 ic->impl->is_on = true;
1862
1863 if (ic == _focused_ic)
1864 {
1865 panel_req_focus_in(ic);
1866 panel_req_update_spot_location(ic);
1867 panel_req_update_factory_info(ic);
1868 _panel_client.turn_on(ic->id);
1869 _panel_client.hide_preedit_string(ic->id);
1870 _panel_client.hide_aux_string(ic->id);
1871 _panel_client.hide_lookup_table(ic->id);
1872 ic->impl->si->focus_in();
1873 }
1874
1875 //Record the IC on/off status
1876 if (_shared_input_method)
1877 _config->write(String(SCIM_CONFIG_FRONTEND_IM_OPENED_BY_DEFAULT), true);
1878
1879 if (ic->impl->use_preedit && ic->impl->preedit_string.length())
1880 {
1881 ecore_imf_context_preedit_start_event_add(ic->ctx);
1882 ecore_imf_context_event_callback_call(ic->ctx, ECORE_IMF_CALLBACK_PREEDIT_START, NULL);
1883 ecore_imf_context_preedit_changed_event_add(ic->ctx);
1884 ecore_imf_context_event_callback_call(ic->ctx, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, NULL);
1885 ic->impl->preedit_started = true;
1886 }
1887 }
1888}
1889
1890static void
1891turn_off_ic(EcoreIMFContextISF *ic)
1892{
1893 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1894
1895 if (ic && ic->impl && ic->impl->is_on)
1896 {
1897 ic->impl->is_on = false;
1898
1899 if (ic == _focused_ic)
1900 {
1901 ic->impl->si->focus_out();
1902
1903 panel_req_update_factory_info(ic);
1904 _panel_client.turn_off(ic->id);
1905 }
1906
1907 //Record the IC on/off status
1908 if (_shared_input_method)
1909 _config->write(String(SCIM_CONFIG_FRONTEND_IM_OPENED_BY_DEFAULT), false);
1910
1911 if (ic->impl->use_preedit && ic->impl->preedit_string.length())
1912 {
1913 ecore_imf_context_preedit_changed_event_add(ic->ctx);
1914 ecore_imf_context_event_callback_call(ic->ctx, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, NULL);
1915 ecore_imf_context_preedit_end_event_add(ic->ctx);
1916 ecore_imf_context_event_callback_call(ic->ctx, ECORE_IMF_CALLBACK_PREEDIT_END, NULL);
1917 ic->impl->preedit_started = false;
1918 }
1919 }
1920}
1921
1922static void
1923set_ic_capabilities(EcoreIMFContextISF *ic)
1924{
1925 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1926
1927 if (ic && ic->impl)
1928 {
1929 unsigned int cap = SCIM_CLIENT_CAP_ALL_CAPABILITIES;
1930
1931 if (!_on_the_spot || !ic->impl->use_preedit)
1932 cap -= SCIM_CLIENT_CAP_ONTHESPOT_PREEDIT;
1933
1934 ic->impl->si->update_client_capabilities(cap);
1935 }
1936}
1937
1938static bool
1939check_socket_frontend(void)
1940{
1941 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
1942
1943 SocketAddress address;
1944 SocketClient client;
1945
1946 uint32 magic;
1947
1948 address.set_address(scim_get_default_socket_frontend_address());
1949
1950 if (!client.connect(address))
1951 return false;
1952
1953 if (!scim_socket_open_connection(magic,
1954 String("ConnectionTester"),
1955 String("SocketFrontEnd"),
1956 client,
1957 1000))
1958 return false;
1959
1960 return true;
1961}
1962
1963void
1964initialize(void)
1965{
1966 std::vector<String> config_list;
1967 std::vector<String> engine_list;
1968 std::vector<String> load_engine_list;
1969
1970 std::vector<String>::iterator it;
1971
1972 bool manual = false;
1973
1974 bool socket = true;
1975
1976 String config_module_name = "simple";
1977
1978 printf("Initializing Ecore SCIM IMModule...\n");
1979
1980 SCIM_DEBUG_FRONTEND(1) << "Initializing Ecore SCIM IMModule...\n";
1981
1982 // Get system language.
1983 _language = scim_get_locale_language(scim_get_current_locale());
1984
1985 if (socket)
1986 {
1987 // If no Socket FrontEnd is running, then launch one.
1988 // And set manual to false.
1989 bool check_result = check_socket_frontend();
1990 if (!check_result)
1991 {
1992 std::cerr << "Launching a SCIM daemon with Socket FrontEnd...\n";
1993 //get modules list
1994 scim_get_imengine_module_list(engine_list);
1995
1996 for (it = engine_list.begin(); it != engine_list.end(); it++)
1997 {
1998 if (*it != "socket")
1999 load_engine_list.push_back(*it);
2000 }
2001
2002 const char *new_argv [] = { "--no-stay", 0 };
2003 scim_launch(true,
2004 config_module_name,
2005 (load_engine_list.size() ? scim_combine_string_list(load_engine_list, ',') : "none"),
2006 "socket",
2007 (char **)new_argv);
2008 manual = false;
2009 }
2010
2011 // If there is one Socket FrontEnd running and it's not manual mode,
2012 // then just use this Socket Frontend.
2013 if (!manual)
2014 {
2015 for (int i = 0; i < 200; ++i)
2016 {
2017 if (check_result)
2018 {
2019 config_module_name = "socket";
2020 load_engine_list.clear();
2021 load_engine_list.push_back("socket");
2022 break;
2023 }
2024 scim_usleep(50000);
2025 check_result = check_socket_frontend();
2026 }
2027 }
2028 }
2029
2030 if (config_module_name != "dummy")
2031 {
2032 //load config module
2033 SCIM_DEBUG_FRONTEND(1) << "Loading Config module: " << config_module_name << "...\n";
2034 _config_module = new ConfigModule(config_module_name);
2035
2036 //create config instance
2037 if (_config_module != NULL && _config_module->valid())
2038 _config = _config_module->create_config();
2039 }
2040
2041 if (_config.null())
2042 {
2043 SCIM_DEBUG_FRONTEND(1) << "Config module cannot be loaded, using dummy Config.\n";
2044
2045 if (_config_module) delete _config_module;
2046 _config_module = NULL;
2047
2048 _config = new DummyConfig();
2049 config_module_name = "dummy";
2050 }
2051
2052 reload_config_callback(_config);
2053 _config->signal_connect_reload(slot(reload_config_callback));
2054
2055 // create backend
2056 _backend = new CommonBackEnd(_config, load_engine_list.size() ? load_engine_list : engine_list);
2057
2058 if (_backend.null())
2059 std::cerr << "Cannot create BackEnd Object!\n";
2060 else
2061 _fallback_factory = _backend->get_factory(SCIM_COMPOSE_KEY_FACTORY_UUID);
2062
2063 if (_fallback_factory.null())
2064 _fallback_factory = new DummyIMEngineFactory();
2065
2066 _fallback_instance = _fallback_factory->create_instance(String("UTF-8"), 0);
2067 _fallback_instance->signal_connect_commit_string(slot(fallback_commit_string_cb));
2068
2069 // Attach Panel Client signal.
2070 _panel_client.signal_connect_reload_config (slot(panel_slot_reload_config));
2071 _panel_client.signal_connect_exit (slot(panel_slot_exit));
2072 _panel_client.signal_connect_update_lookup_table_page_size(slot(panel_slot_update_lookup_table_page_size));
2073 _panel_client.signal_connect_lookup_table_page_up (slot(panel_slot_lookup_table_page_up));
2074 _panel_client.signal_connect_lookup_table_page_down (slot(panel_slot_lookup_table_page_down));
2075 _panel_client.signal_connect_trigger_property (slot(panel_slot_trigger_property));
2076 _panel_client.signal_connect_process_helper_event (slot(panel_slot_process_helper_event));
2077 _panel_client.signal_connect_move_preedit_caret (slot(panel_slot_move_preedit_caret));
2078 _panel_client.signal_connect_select_candidate (slot(panel_slot_select_candidate));
2079 _panel_client.signal_connect_process_key_event (slot(panel_slot_process_key_event));
2080 _panel_client.signal_connect_commit_string (slot(panel_slot_commit_string));
2081 _panel_client.signal_connect_forward_key_event (slot(panel_slot_forward_key_event));
2082 _panel_client.signal_connect_request_help (slot(panel_slot_request_help));
2083 _panel_client.signal_connect_request_factory_menu (slot(panel_slot_request_factory_menu));
2084 _panel_client.signal_connect_change_factory (slot(panel_slot_change_factory));
2085
2086 if (!panel_initialize())
2087 std::cerr << "Ecore IM Module: Cannot connect to Panel!\n";
2088}
2089
2090static void
2091finalize(void)
2092{
2093 SCIM_DEBUG_FRONTEND(1) << "Finalizing Ecore ISF IMModule...\n";
2094
2095 // Reset this first so that the shared instance could be released correctly afterwards.
2096 _default_instance.reset();
2097
2098 SCIM_DEBUG_FRONTEND(2) << "Finalize all IC partially.\n";
2099 while (_used_ic_impl_list)
2100 {
2101 // In case in "shared input method" mode,
2102 // all contexts share only one instance,
2103 // so we need point the reference pointer correctly before finalizing.
2104 _used_ic_impl_list->si->set_frontend_data(static_cast <void*>(_used_ic_impl_list->parent));
2105 isf_imf_context_del(_used_ic_impl_list->parent->ctx);
2106 }
2107
2108 delete_all_ic_impl();
2109
2110 _fallback_instance.reset();
2111 _fallback_factory.reset();
2112
2113 SCIM_DEBUG_FRONTEND(2) << " Releasing BackEnd...\n";
2114 _backend.reset();
2115
2116 SCIM_DEBUG_FRONTEND(2) << " Releasing Config...\n";
2117 _config.reset();
2118
2119 if (_config_module)
2120 {
2121 SCIM_DEBUG_FRONTEND(2) << " Deleting _config_module...\n";
2122 delete _config_module;
2123 _config_module = 0;
2124 }
2125
2126 _focused_ic = NULL;
2127 _ic_list = NULL;
2128
2129 _scim_initialized = false;
2130
2131 panel_finalize();
2132}
2133
2134static void
2135open_next_factory(EcoreIMFContextISF *ic)
2136{
2137 SCIM_DEBUG_FRONTEND(2) << __FUNCTION__ << " context=" << ic->id << "\n";
2138 IMEngineFactoryPointer sf = _backend->get_next_factory("", "UTF-8", ic->impl->si->get_factory_uuid());
2139
2140 if (!sf.null())
2141 {
2142 turn_off_ic(ic);
2143 ic->impl->si = sf->create_instance("UTF-8", ic->impl->si->get_id());
2144 ic->impl->si->set_frontend_data(static_cast <void*>(ic));
2145 ic->impl->preedit_string = WideString();
2146 ic->impl->preedit_caret = 0;
2147 attach_instance(ic->impl->si);
2148 _backend->set_default_factory(_language, sf->get_uuid());
2149 _panel_client.register_input_context(ic->id, sf->get_uuid());
2150 set_ic_capabilities(ic);
2151 turn_on_ic(ic);
2152
2153 if (_shared_input_method)
2154 {
2155 _default_instance = ic->impl->si;
2156 ic->impl->shared_si = true;
2157 }
2158 }
2159}
2160
2161static void
2162open_previous_factory(EcoreIMFContextISF *ic)
2163{
2164 if (ic == NULL)
2165 return;
2166
2167 SCIM_DEBUG_FRONTEND(2) << __FUNCTION__ << " context=" << ic->id << "\n";
2168 IMEngineFactoryPointer sf = _backend->get_previous_factory("", "UTF-8", ic->impl->si->get_factory_uuid());
2169
2170 if (!sf.null())
2171 {
2172 turn_off_ic(ic);
2173 ic->impl->si = sf->create_instance("UTF-8", ic->impl->si->get_id());
2174 ic->impl->si->set_frontend_data(static_cast <void*>(ic));
2175 ic->impl->preedit_string = WideString();
2176 ic->impl->preedit_caret = 0;
2177 attach_instance(ic->impl->si);
2178 _backend->set_default_factory(_language, sf->get_uuid());
2179 _panel_client.register_input_context(ic->id, sf->get_uuid());
2180 set_ic_capabilities(ic);
2181 turn_on_ic(ic);
2182
2183 if (_shared_input_method)
2184 {
2185 _default_instance = ic->impl->si;
2186 ic->impl->shared_si = true;
2187 }
2188 }
2189}
2190
2191static void
2192open_specific_factory(EcoreIMFContextISF *ic,
2193 const String &uuid)
2194{
2195 if (ic == NULL)
2196 return;
2197
2198 SCIM_DEBUG_FRONTEND(2) << __FUNCTION__ << " context=" << ic->id << "\n";
2199
2200 // The same input method is selected, just turn on the IC.
2201 if (ic->impl->si->get_factory_uuid() == uuid)
2202 {
2203 turn_on_ic(ic);
2204 return;
2205 }
2206
2207 IMEngineFactoryPointer sf = _backend->get_factory(uuid);
2208
2209 if (uuid.length() && !sf.null())
2210 {
2211 turn_off_ic(ic);
2212 ic->impl->si = sf->create_instance("UTF-8", ic->impl->si->get_id());
2213 ic->impl->si->set_frontend_data(static_cast <void*>(ic));
2214 ic->impl->preedit_string = WideString();
2215 ic->impl->preedit_caret = 0;
2216 attach_instance(ic->impl->si);
2217 _backend->set_default_factory(_language, sf->get_uuid());
2218 _panel_client.register_input_context(ic->id, sf->get_uuid());
2219 set_ic_capabilities(ic);
2220 turn_on_ic(ic);
2221
2222 if (_shared_input_method)
2223 {
2224 _default_instance = ic->impl->si;
2225 ic->impl->shared_si = true;
2226 }
2227 }
2228 else
2229 {
2230 // turn_off_ic comment out panel_req_update_factory_info()
2231 turn_off_ic(ic);
2232 if (ic && ic->impl->is_on)
2233 {
2234 ic->impl->is_on = false;
2235
2236 if (ic == _focused_ic)
2237 {
2238 ic->impl->si->focus_out();
2239
2240 panel_req_update_factory_info(ic);
2241 _panel_client.turn_off(ic->id);
2242 }
2243
2244 //Record the IC on/off status
2245 if (_shared_input_method)
2246 _config->write(String(SCIM_CONFIG_FRONTEND_IM_OPENED_BY_DEFAULT), false);
2247
2248 if (ic->impl->use_preedit && ic->impl->preedit_string.length())
2249 {
2250 ecore_imf_context_preedit_changed_event_add(ic->ctx);
2251 ecore_imf_context_event_callback_call(ic->ctx, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, NULL);
2252 ecore_imf_context_preedit_end_event_add(ic->ctx);
2253 ecore_imf_context_event_callback_call(ic->ctx, ECORE_IMF_CALLBACK_PREEDIT_END, NULL);
2254 ic->impl->preedit_started = false;
2255 }
2256 }
2257 }
2258}
2259
2260static void initialize_modifier_bits(Display *display)
2261{
2262 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2263
2264 if (__current_display == display)
2265 return;
2266
2267 __current_display = display;
2268
2269 if (display == 0)
2270 {
2271 __current_alt_mask = Mod1Mask;
2272 __current_meta_mask = ShiftMask | Mod1Mask;
2273 __current_super_mask = 0;
2274 __current_hyper_mask = 0;
2275 __current_numlock_mask = Mod2Mask;
2276 return;
2277 }
2278
2279 XModifierKeymap *mods = NULL;
2280
2281 ::KeyCode ctrl_l = XKeysymToKeycode(display, XK_Control_L);
2282 ::KeyCode ctrl_r = XKeysymToKeycode(display, XK_Control_R);
2283 ::KeyCode meta_l = XKeysymToKeycode(display, XK_Meta_L);
2284 ::KeyCode meta_r = XKeysymToKeycode(display, XK_Meta_R);
2285 ::KeyCode alt_l = XKeysymToKeycode(display, XK_Alt_L);
2286 ::KeyCode alt_r = XKeysymToKeycode(display, XK_Alt_R);
2287 ::KeyCode super_l = XKeysymToKeycode(display, XK_Super_L);
2288 ::KeyCode super_r = XKeysymToKeycode(display, XK_Super_R);
2289 ::KeyCode hyper_l = XKeysymToKeycode(display, XK_Hyper_L);
2290 ::KeyCode hyper_r = XKeysymToKeycode(display, XK_Hyper_R);
2291 ::KeyCode numlock = XKeysymToKeycode(display, XK_Num_Lock);
2292
2293 int i, j;
2294
2295 mods = XGetModifierMapping(display);
2296 if (mods == NULL)
2297 return;
2298
2299 __current_alt_mask = 0;
2300 __current_meta_mask = 0;
2301 __current_super_mask = 0;
2302 __current_hyper_mask = 0;
2303 __current_numlock_mask = 0;
2304
2305 /* We skip the first three sets for Shift, Lock, and Control. The
2306 remaining sets are for Mod1, Mod2, Mod3, Mod4, and Mod5. */
2307 for (i = 3; i < 8; i++)
2308 {
2309 for (j = 0; j < mods->max_keypermod; j++)
2310 {
2311 ::KeyCode code = mods->modifiermap [i * mods->max_keypermod + j];
2312 if (! code) continue;
2313 if (code == alt_l || code == alt_r)
2314 __current_alt_mask |= (1 << i);
2315 else if (code == meta_l || code == meta_r)
2316 __current_meta_mask |= (1 << i);
2317 else if (code == super_l || code == super_r)
2318 __current_super_mask |= (1 << i);
2319 else if (code == hyper_l || code == hyper_r)
2320 __current_hyper_mask |= (1 << i);
2321 else if (code == numlock)
2322 __current_numlock_mask |= (1 << i);
2323 }
2324 }
2325
2326 /* Check whether there is a combine keys mapped to Meta */
2327 if (__current_meta_mask == 0)
2328 {
2329 char buf [32];
2330 XKeyEvent xkey;
2331 KeySym keysym_l, keysym_r;
2332
2333 xkey.type = KeyPress;
2334 xkey.display = display;
2335 xkey.serial = 0L;
2336 xkey.send_event = False;
2337 xkey.x = xkey.y = xkey.x_root = xkey.y_root = 0;
2338 xkey.time = 0;
2339 xkey.same_screen = False;
2340 xkey.subwindow = None;
2341 xkey.window = None;
2342 xkey.root = DefaultRootWindow(display);
2343 xkey.state = ShiftMask;
2344
2345 xkey.keycode = meta_l;
2346 XLookupString(&xkey, buf, 32, &keysym_l, 0);
2347 xkey.keycode = meta_r;
2348 XLookupString(&xkey, buf, 32, &keysym_r, 0);
2349
2350 if ((meta_l == alt_l && keysym_l == XK_Meta_L) || (meta_r == alt_r && keysym_r == XK_Meta_R))
2351 __current_meta_mask = ShiftMask + __current_alt_mask;
2352 else if ((meta_l == ctrl_l && keysym_l == XK_Meta_L) || (meta_r == ctrl_r && keysym_r == XK_Meta_R))
2353 __current_meta_mask = ShiftMask + ControlMask;
2354 }
2355
2356 XFreeModifiermap(mods);
2357}
2358
2359static unsigned int scim_x11_keymask_scim_to_x11(Display *display, uint16 scimkeymask)
2360{
2361 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2362
2363 unsigned int state = 0;
2364
2365 initialize_modifier_bits(display);
2366
2367 if (scimkeymask & SCIM_KEY_ShiftMask) state |= ShiftMask;
2368 if (scimkeymask & SCIM_KEY_CapsLockMask) state |= LockMask;
2369 if (scimkeymask & SCIM_KEY_ControlMask) state |= ControlMask;
2370 if (scimkeymask & SCIM_KEY_AltMask) state |= __current_alt_mask;
2371 if (scimkeymask & SCIM_KEY_MetaMask) state |= __current_meta_mask;
2372 if (scimkeymask & SCIM_KEY_SuperMask) state |= __current_super_mask;
2373 if (scimkeymask & SCIM_KEY_HyperMask) state |= __current_hyper_mask;
2374 if (scimkeymask & SCIM_KEY_NumLockMask) state |= __current_numlock_mask;
2375
2376 return state;
2377}
2378
2379static XKeyEvent createKeyEvent(Display *display, Window &win,
2380 Window &winRoot, bool press,
2381 int keycode, int modifiers)
2382{
2383 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2384
2385 XKeyEvent event;
2386
2387 event.display = display;
2388 event.window = win;
2389 event.root = winRoot;
2390 event.subwindow = None;
2391 event.time = CurrentTime;
2392 event.x = 1;
2393 event.y = 1;
2394 event.x_root = 1;
2395 event.y_root = 1;
2396 event.same_screen = EINA_TRUE;
2397 event.state = modifiers;
2398 event.keycode = XKeysymToKeycode(display, keycode);
2399 if (press)
2400 event.type = KeyPress;
2401 else
2402 event.type = KeyRelease;
2403 event.send_event = EINA_FALSE;
2404 event.serial = 0;
2405
2406 return event;
2407}
2408
2409static void _x_send_key_event(const KeyEvent &key)
2410{
2411 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2412
2413 // Obtain the X11 display.
2414 Display *display = XOpenDisplay(NULL);
2415 if (display == NULL)
2416 {
2417 std::cerr << "XOpenDisplay failed\n";
2418 return;
2419 }
2420
2421 // Get the root window for the current display.
2422 Window winRoot = 0;
2423
2424 // Find the window which has the current keyboard focus.
2425 Window winFocus = 0;
2426 int revert = RevertToParent;
2427
2428 XGetInputFocus(display, &winFocus, &revert);
2429
2430 // Send a fake key press event to the window.
2431 XSelectInput(display, winFocus, FocusChangeMask|KeyPressMask|KeyReleaseMask);
2432 XMapWindow(display, winFocus);
2433
2434 unsigned int modifier = scim_x11_keymask_scim_to_x11(display, key.mask);
2435 XKeyEvent event;
2436 if (key.is_key_press())
2437 {
2438 event = createKeyEvent(display, winFocus, winRoot, true, key.code, modifier);
2439 XSendEvent(event.display, event.window, True, KeyPressMask, (XEvent *)&event);
2440 }
2441 else
2442 {
2443 event = createKeyEvent(display, winFocus, winRoot, false, key.code, modifier);
2444 XSendEvent(event.display, event.window, True, KeyReleaseMask, (XEvent *)&event);
2445 }
2446
2447 XCloseDisplay(display);
2448}
2449
2450static void
2451attach_instance(const IMEngineInstancePointer &si)
2452{
2453 si->signal_connect_show_preedit_string(
2454 slot(slot_show_preedit_string));
2455 si->signal_connect_show_aux_string(
2456 slot(slot_show_aux_string));
2457 si->signal_connect_show_lookup_table(
2458 slot(slot_show_lookup_table));
2459
2460 si->signal_connect_hide_preedit_string(
2461 slot(slot_hide_preedit_string));
2462 si->signal_connect_hide_aux_string(
2463 slot(slot_hide_aux_string));
2464 si->signal_connect_hide_lookup_table(
2465 slot(slot_hide_lookup_table));
2466
2467 si->signal_connect_update_preedit_caret(
2468 slot(slot_update_preedit_caret));
2469 si->signal_connect_update_preedit_string(
2470 slot(slot_update_preedit_string));
2471 si->signal_connect_update_aux_string(
2472 slot(slot_update_aux_string));
2473 si->signal_connect_update_lookup_table(
2474 slot(slot_update_lookup_table));
2475
2476 si->signal_connect_commit_string(
2477 slot(slot_commit_string));
2478
2479 si->signal_connect_forward_key_event(
2480 slot(slot_forward_key_event));
2481
2482 si->signal_connect_register_properties(
2483 slot(slot_register_properties));
2484
2485 si->signal_connect_update_property(
2486 slot(slot_update_property));
2487
2488 si->signal_connect_beep(
2489 slot(slot_beep));
2490
2491 si->signal_connect_start_helper(
2492 slot(slot_start_helper));
2493
2494 si->signal_connect_stop_helper(
2495 slot(slot_stop_helper));
2496
2497 si->signal_connect_send_helper_event(
2498 slot(slot_send_helper_event));
2499
2500 si->signal_connect_get_surrounding_text(
2501 slot(slot_get_surrounding_text));
2502
2503 si->signal_connect_delete_surrounding_text(
2504 slot(slot_delete_surrounding_text));
2505}
2506
2507// Implementation of slot functions
2508static void
2509slot_show_preedit_string(IMEngineInstanceBase *si)
2510{
2511 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2512
2513 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2514
2515 if (ic && ic->impl && _focused_ic == ic)
2516 {
2517 if (ic->impl->use_preedit)
2518 {
2519 if (!ic->impl->preedit_started)
2520 {
2521 ecore_imf_context_preedit_start_event_add(_focused_ic->ctx);
2522 ecore_imf_context_event_callback_call(_focused_ic->ctx, ECORE_IMF_CALLBACK_PREEDIT_START, NULL);
2523 ic->impl->preedit_started = true;
2524 }
2525 }
2526 else
2527 _panel_client.show_preedit_string(ic->id);
2528 }
2529}
2530
2531static void
2532slot_show_aux_string(IMEngineInstanceBase *si)
2533{
2534 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2535
2536 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2537
2538 if (ic && ic->impl && _focused_ic == ic)
2539 _panel_client.show_aux_string(ic->id);
2540}
2541
2542static void
2543slot_show_lookup_table(IMEngineInstanceBase *si)
2544{
2545 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2546
2547 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2548
2549 if (ic && ic->impl && _focused_ic == ic)
2550 _panel_client.show_lookup_table(ic->id);
2551}
2552
2553static void
2554slot_hide_preedit_string(IMEngineInstanceBase *si)
2555{
2556 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2557
2558 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2559
2560 if (ic && ic->impl && _focused_ic == ic)
2561 {
2562 bool emit = false;
2563 if (ic->impl->preedit_string.length())
2564 {
2565 ic->impl->preedit_string = WideString();
2566 ic->impl->preedit_caret = 0;
2567 ic->impl->preedit_attrlist.clear();
2568 emit = true;
2569 }
2570 if (ic->impl->use_preedit)
2571 {
2572 if (emit)
2573 {
2574 ecore_imf_context_preedit_changed_event_add(ic->ctx);
2575 ecore_imf_context_event_callback_call(ic->ctx, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, NULL);
2576 }
2577 if (ic->impl->preedit_started)
2578 {
2579 ecore_imf_context_preedit_end_event_add(ic->ctx);
2580 ecore_imf_context_event_callback_call(ic->ctx, ECORE_IMF_CALLBACK_PREEDIT_END, NULL);
2581 ic->impl->preedit_started = false;
2582 }
2583 }
2584 else
2585 _panel_client.hide_preedit_string(ic->id);
2586 }
2587}
2588
2589static void
2590slot_hide_aux_string(IMEngineInstanceBase *si)
2591{
2592 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2593
2594 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2595
2596 if (ic && ic->impl && _focused_ic == ic)
2597 _panel_client.hide_aux_string(ic->id);
2598}
2599
2600static void
2601slot_hide_lookup_table(IMEngineInstanceBase *si)
2602{
2603 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2604
2605 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2606
2607 if (ic && ic->impl && _focused_ic == ic)
2608 _panel_client.hide_lookup_table(ic->id);
2609}
2610
2611static void
2612slot_update_preedit_caret(IMEngineInstanceBase *si, int caret)
2613{
2614 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2615
2616 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2617
2618 if (ic && ic->impl && _focused_ic == ic && ic->impl->preedit_caret != caret)
2619 {
2620 ic->impl->preedit_caret = caret;
2621 if (ic->impl->use_preedit)
2622 {
2623 if (!ic->impl->preedit_started)
2624 {
2625 ecore_imf_context_preedit_start_event_add(ic->ctx);
2626 ecore_imf_context_event_callback_call(ic->ctx, ECORE_IMF_CALLBACK_PREEDIT_START, NULL);
2627 ic->impl->preedit_started = true;
2628 }
2629 ecore_imf_context_preedit_changed_event_add(ic->ctx);
2630 ecore_imf_context_event_callback_call(ic->ctx, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, NULL);
2631 }
2632 else
2633 _panel_client.update_preedit_caret(ic->id, caret);
2634 }
2635}
2636
2637static void
2638slot_update_preedit_string(IMEngineInstanceBase *si,
2639 const WideString & str,
2640 const AttributeList & attrs)
2641{
2642 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2643
2644 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2645
2646 if (ic && ic->impl && _focused_ic == ic && (ic->impl->preedit_string != str || str.length()))
2647 {
2648 ic->impl->preedit_string = str;
2649 ic->impl->preedit_attrlist = attrs;
2650 if (ic->impl->use_preedit)
2651 {
2652 if (!ic->impl->preedit_started)
2653 {
2654 ecore_imf_context_preedit_start_event_add(_focused_ic->ctx);
2655 ecore_imf_context_event_callback_call(_focused_ic->ctx, ECORE_IMF_CALLBACK_PREEDIT_START, NULL);
2656 ic->impl->preedit_started = true;
2657 }
2658 ic->impl->preedit_caret = str.length();
2659 ic->impl->preedit_updating = true;
2660 ecore_imf_context_preedit_changed_event_add(ic->ctx);
2661 ecore_imf_context_event_callback_call(ic->ctx, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, NULL);
2662 ic->impl->preedit_updating = false;
2663 }
2664 else
2665 {
2666 _panel_client.update_preedit_string(ic->id, str, attrs);
2667 }
2668 }
2669}
2670
2671static void
2672slot_update_aux_string(IMEngineInstanceBase *si,
2673 const WideString & str,
2674 const AttributeList & attrs)
2675{
2676 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2677
2678 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2679
2680 if (ic && ic->impl && _focused_ic == ic)
2681 _panel_client.update_aux_string(ic->id, str, attrs);
2682}
2683
2684static void
2685slot_commit_string(IMEngineInstanceBase *si,
2686 const WideString & str)
2687{
2688 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2689
2690 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2691
2692 if (ic && ic->ctx)
2693 {
2694 ecore_imf_context_commit_event_add(ic->ctx, utf8_wcstombs(str).c_str());
2695 ecore_imf_context_event_callback_call(ic->ctx, ECORE_IMF_CALLBACK_COMMIT, (void *)utf8_wcstombs(str).c_str());
2696 }
2697}
2698
2699static void
2700slot_forward_key_event(IMEngineInstanceBase *si,
2701 const KeyEvent & key)
2702{
2703 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2704
2705 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2706
2707 if (ic && _focused_ic == ic)
2708 {
2709 if (!_fallback_instance->process_key_event(key))
2710 _x_send_key_event(key);
2711 }
2712}
2713
2714static void
2715slot_update_lookup_table(IMEngineInstanceBase *si,
2716 const LookupTable & table)
2717{
2718 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2719
2720 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2721
2722 if (ic && ic->impl && _focused_ic == ic)
2723 _panel_client.update_lookup_table(ic->id, table);
2724}
2725
2726static void
2727slot_register_properties(IMEngineInstanceBase *si,
2728 const PropertyList & properties)
2729{
2730 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2731
2732 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2733
2734 if (ic && ic->impl && _focused_ic == ic)
2735 _panel_client.register_properties(ic->id, properties);
2736}
2737
2738static void
2739slot_update_property(IMEngineInstanceBase *si,
2740 const Property & property)
2741{
2742 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2743
2744 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2745
2746 if (ic && ic->impl && _focused_ic == ic)
2747 _panel_client.update_property(ic->id, property);
2748}
2749
2750static void
2751slot_beep(IMEngineInstanceBase *si __UNUSED__)
2752{
2753 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2754}
2755
2756static void
2757slot_start_helper(IMEngineInstanceBase *si,
2758 const String &helper_uuid)
2759{
2760 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2761
2762 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " helper= " << helper_uuid << " context="
2763 << (ic ? ic->id : -1) << " ic=" << ic
2764 << " ic-uuid=" << ((ic ) ? ic->impl->si->get_factory_uuid() : "") << "...\n";
2765
2766 if (ic && ic->impl)
2767 _panel_client.start_helper(ic->id, helper_uuid);
2768}
2769
2770static void
2771slot_stop_helper(IMEngineInstanceBase *si,
2772 const String &helper_uuid)
2773{
2774 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2775
2776 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " helper= " << helper_uuid << " context=" << (ic ? ic->id : -1) << " ic=" << ic << "...\n";
2777
2778 if (ic && ic->impl)
2779 _panel_client.stop_helper(ic->id, helper_uuid);
2780}
2781
2782static void
2783slot_send_helper_event(IMEngineInstanceBase *si,
2784 const String &helper_uuid,
2785 const Transaction &trans)
2786{
2787 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2788
2789 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << " helper= " << helper_uuid << " context="
2790 << (ic ? ic->id : -1) << " ic=" << ic
2791 << " ic-uuid=" << ((ic) ? ic->impl->si->get_factory_uuid() : "") << "...\n";
2792
2793 if (ic && ic->impl)
2794 _panel_client.send_helper_event(ic->id, helper_uuid, trans);
2795}
2796
2797static bool
2798slot_get_surrounding_text(IMEngineInstanceBase *si,
2799 WideString &text,
2800 int &cursor,
2801 int maxlen_before,
2802 int maxlen_after)
2803{
2804 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2805
2806 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2807
2808 if (ic && ic->impl && _focused_ic == ic)
2809 {
2810 char *surrounding = NULL;
2811 int cursor_index;
2812 if (ecore_imf_context_surrounding_get(_focused_ic->ctx, &surrounding, &cursor_index))
2813 {
2814 SCIM_DEBUG_FRONTEND(2) << "Surrounding text: " << surrounding <<"\n";
2815 SCIM_DEBUG_FRONTEND(2) << "Cursor Index : " << cursor_index <<"\n";
2816 WideString before(utf8_mbstowcs(String(surrounding, surrounding + cursor_index)));
2817 WideString after(utf8_mbstowcs(String(surrounding + cursor_index)));
2818 if (maxlen_before > 0 && ((unsigned int)maxlen_before) < before.length())
2819 before = WideString(before.begin() + (before.length() - maxlen_before), before.end());
2820 else if (maxlen_before == 0) before = WideString();
2821 if (maxlen_after > 0 && ((unsigned int)maxlen_after) < after.length())
2822 after = WideString(after.begin(), after.begin() + maxlen_after);
2823 else if (maxlen_after == 0) after = WideString();
2824 text = before + after;
2825 cursor = before.length();
2826 return true;
2827 }
2828 }
2829 return false;
2830}
2831
2832static bool
2833slot_delete_surrounding_text(IMEngineInstanceBase *si,
2834 int offset,
2835 int len)
2836{
2837 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2838
2839 EcoreIMFContextISF *ic = static_cast<EcoreIMFContextISF *>(si->get_frontend_data());
2840
2841 if (ic && ic->impl && _focused_ic == ic)
2842 {
2843 Ecore_IMF_Event_Delete_Surrounding ev;
2844 ev.ctx = _focused_ic->ctx;
2845 ev.n_chars = len;
2846 ev.offset = offset;
2847 ecore_imf_context_delete_surrounding_event_add(_focused_ic->ctx, offset, len);
2848 ecore_imf_context_event_callback_call(_focused_ic->ctx, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, &ev);
2849 return true;
2850 }
2851 return false;
2852}
2853
2854static void
2855reload_config_callback(const ConfigPointer &config)
2856{
2857 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2858
2859 _frontend_hotkey_matcher.load_hotkeys(config);
2860 _imengine_hotkey_matcher.load_hotkeys(config);
2861
2862 KeyEvent key;
2863
2864 scim_string_to_key(key,
2865 config->read(String(SCIM_CONFIG_HOTKEYS_FRONTEND_VALID_KEY_MASK),
2866 String("Shift+Control+Alt+Lock")));
2867
2868 _valid_key_mask = (key.mask > 0)?(key.mask):0xFFFF;
2869 _valid_key_mask |= SCIM_KEY_ReleaseMask;
2870 // Special treatment for two backslash keys on jp106 keyboard.
2871 _valid_key_mask |= SCIM_KEY_QuirkKanaRoMask;
2872
2873 _on_the_spot = config->read(String(SCIM_CONFIG_FRONTEND_ON_THE_SPOT), _on_the_spot);
2874 _shared_input_method = config->read(String(SCIM_CONFIG_FRONTEND_SHARED_INPUT_METHOD), _shared_input_method);
2875
2876 // Get keyboard layout setting
2877 // Flush the global config first, in order to load the new configs from disk.
2878 scim_global_config_flush();
2879
2880 _keyboard_layout = scim_get_default_keyboard_layout();
2881}
2882
2883static void
2884fallback_commit_string_cb(IMEngineInstanceBase *si __UNUSED__,
2885 const WideString &str)
2886{
2887 SCIM_DEBUG_FRONTEND(1) << __FUNCTION__ << "...\n";
2888
2889 if (_focused_ic && _focused_ic->impl)
2890 {
2891 ecore_imf_context_commit_event_add(_focused_ic->ctx, utf8_wcstombs(str).c_str());
2892 ecore_imf_context_event_callback_call(_focused_ic->ctx, ECORE_IMF_CALLBACK_COMMIT, (void *)utf8_wcstombs(str).c_str());
2893 }
2894}
2895