1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * Copyright (C) 2004 - 2005 Hiroyuki Ikezoe <poincare@ikezoe.net>
4 * Copyright (C) 2004 - 2005 Takuro Ashie <ashie@homa.ne.jp>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * The original code is scim_uim_imengine.cpp in scim-uim-0.1.3.
23 * Copyright (C) 2004 James Su <suzhe@tsinghua.org.cn>
26 #define Uses_SCIM_UTILITY
27 #define Uses_SCIM_IMENGINE
28 #define Uses_SCIM_LOOKUP_TABLE
29 #define Uses_SCIM_CONFIG_BASE
37 #include <sys/types.h>
40 #include "scim_anthy_factory.h"
41 #include "scim_anthy_imengine.h"
42 #include "scim_anthy_prefs.h"
43 #include "scim_anthy_intl.h"
44 #include "scim_anthy_utils.h"
45 #include "scim_anthy_helper.h"
47 #define SCIM_PROP_PREFIX "/IMEngine/Anthy"
48 #define SCIM_PROP_INPUT_MODE "/IMEngine/Anthy/InputMode"
49 #define SCIM_PROP_INPUT_MODE_HIRAGANA "/IMEngine/Anthy/InputMode/Hiragana"
50 #define SCIM_PROP_INPUT_MODE_KATAKANA "/IMEngine/Anthy/InputMode/Katakana"
51 #define SCIM_PROP_INPUT_MODE_HALF_KATAKANA "/IMEngine/Anthy/InputMode/HalfKatakana"
52 #define SCIM_PROP_INPUT_MODE_LATIN "/IMEngine/Anthy/InputMode/Latin"
53 #define SCIM_PROP_INPUT_MODE_WIDE_LATIN "/IMEngine/Anthy/InputMode/WideLatin"
55 #define SCIM_PROP_CONV_MODE "/IMEngine/Anthy/ConvMode"
56 #define SCIM_PROP_CONV_MODE_MULTI_SEG "/IMEngine/Anthy/ConvMode/MultiSegment"
57 #define SCIM_PROP_CONV_MODE_SINGLE_SEG "/IMEngine/Anthy/ConvMode/SingleSegment"
58 #define SCIM_PROP_CONV_MODE_MULTI_REAL_TIME "/IMEngine/Anthy/ConvMode/MultiRealTime"
59 #define SCIM_PROP_CONV_MODE_SINGLE_REAL_TIME "/IMEngine/Anthy/ConvMode/SingleRealTime"
61 #define SCIM_PROP_TYPING_METHOD "/IMEngine/Anthy/TypingMethod"
62 #define SCIM_PROP_TYPING_METHOD_ROMAJI "/IMEngine/Anthy/TypingMethod/RomaKana"
63 #define SCIM_PROP_TYPING_METHOD_KANA "/IMEngine/Anthy/TypingMethod/Kana"
64 #define SCIM_PROP_TYPING_METHOD_NICOLA "/IMEngine/Anthy/TypingMethod/NICOLA"
66 #define SCIM_PROP_PERIOD_STYLE "/IMEngine/Anthy/PeriodType"
67 #define SCIM_PROP_PERIOD_STYLE_JAPANESE "/IMEngine/Anthy/PeriodType/Japanese"
68 #define SCIM_PROP_PERIOD_STYLE_WIDE_LATIN "/IMEngine/Anthy/PeriodType/WideRatin"
69 #define SCIM_PROP_PERIOD_STYLE_LATIN "/IMEngine/Anthy/PeriodType/Ratin"
70 #define SCIM_PROP_PERIOD_STYLE_WIDE_LATIN_JAPANESE \
71 "/IMEngine/Anthy/PeriodType/WideRatin_Japanese"
73 #define SCIM_PROP_SYMBOL_STYLE "/IMEngine/Anthy/SymbolType"
74 #define SCIM_PROP_SYMBOL_STYLE_JAPANESE "/IMEngine/Anthy/SymbolType/Japanese"
75 #define SCIM_PROP_SYMBOL_STYLE_BRACKET_SLASH "/IMEngine/Anthy/SymbolType/WideBracket_WideSlash"
76 #define SCIM_PROP_SYMBOL_STYLE_CORNER_BRACKET_SLASH \
77 "/IMEngine/Anthy/SymbolType/CornerBracket_WideSlash"
78 #define SCIM_PROP_SYMBOL_STYLE_BRACKET_MIDDLE_DOT \
79 "/IMEngine/Anthy/SymbolType/WideBracket_MiddleDot"
81 #define SCIM_PROP_DICT "/IMEngine/Anthy/Dictionary"
82 #define SCIM_PROP_DICT_ADD_WORD "/IMEngine/Anthy/Dictionary/AddWord"
83 #define SCIM_PROP_DICT_LAUNCH_ADMIN_TOOL "/IMEngine/Anthy/Dictionary/LaunchAdminTool"
85 #define UTF8_BRACKET_CORNER_BEGIN "\xE3\x80\x8C"
86 #define UTF8_BRACKET_CORNER_END "\xE3\x80\x8D"
87 #define UTF8_BRACKET_WIDE_BEGIN "\xEF\xBC\xBB"
88 #define UTF8_BRACKET_WIDE_END "\xEF\xBC\xBD"
89 #define UTF8_MIDDLE_DOT "\xE3\x83\xBB"
90 #define UTF8_SLASH_WIDE "\xEF\xBC\x8F"
92 AnthyInstance::AnthyInstance (AnthyFactory *factory,
93 const String &encoding,
95 : IMEngineInstanceBase (factory, encoding, id),
99 m_preedit_string_visible (false),
100 m_lookup_table_visible (false),
101 m_n_conv_key_pressed (0),
102 m_prev_input_mode (SCIM_ANTHY_MODE_HIRAGANA),
103 m_conv_mode (SCIM_ANTHY_CONVERSION_MULTI_SEGMENT),
104 m_helper_started (false),
107 SCIM_DEBUG_IMENGINE(1) << "Create Anthy Instance : ";
109 reload_config (m_factory->m_config);
110 m_factory->append_config_listener (this);
114 AnthyInstance::~AnthyInstance ()
116 if (m_helper_started)
117 stop_helper (String (SCIM_ANTHY_HELPER_UUID));
119 m_factory->remove_config_listener (this);
124 AnthyInstance::is_nicola_thumb_shift_key (const KeyEvent &key)
126 if (get_typing_method () != SCIM_ANTHY_TYPING_METHOD_NICOLA)
129 if (util_match_key_event (m_factory->m_left_thumb_keys, key, 0xFFFF) ||
130 util_match_key_event (m_factory->m_right_thumb_keys, key, 0xFFFF))
139 AnthyInstance::process_key_event_input (const KeyEvent &key)
141 // prediction while typing
142 if (m_factory->m_predict_on_input && key.is_key_release () &&
143 m_preedit.is_preediting () && !m_preedit.is_converting ())
145 CommonLookupTable table;
146 m_preedit.predict ();
147 m_preedit.get_candidates (table);
148 if (table.number_of_candidates () > 0) {
149 table.show_cursor (false);
150 update_lookup_table (table);
151 show_lookup_table ();
153 hide_lookup_table ();
157 if (!m_preedit.can_process_key_event (key)) {
161 if (m_preedit.is_converting ()) {
162 if (is_realtime_conversion ()) {
164 } else if (!is_nicola_thumb_shift_key (key)) {
165 action_commit (m_factory->m_learn_on_auto_commit);
169 bool need_commit = m_preedit.process_key_event (key);
172 if (is_realtime_conversion () &&
173 get_input_mode () != SCIM_ANTHY_MODE_LATIN &&
174 get_input_mode () != SCIM_ANTHY_MODE_WIDE_LATIN)
176 m_preedit.convert (SCIM_ANTHY_CANDIDATE_DEFAULT,
177 is_single_segment ());
179 action_commit (m_factory->m_learn_on_auto_commit);
181 if (is_realtime_conversion ()) {
182 m_preedit.convert (SCIM_ANTHY_CANDIDATE_DEFAULT,
183 is_single_segment ());
184 m_preedit.select_segment (-1);
186 show_preedit_string ();
187 m_preedit_string_visible = true;
195 AnthyInstance::process_key_event_lookup_keybind (const KeyEvent& key)
197 std::vector<Action>::iterator it;
201 /* try to find a "insert a blank" action to be not stolen a blank key
202 * when entering the pseudo ascii mode.
204 if (get_pseudo_ascii_mode () != 0 &&
205 m_factory->m_romaji_pseudo_ascii_blank_behavior &&
206 m_preedit.is_pseudo_ascii_mode ()) {
207 for (it = m_factory->m_actions.begin();
208 it != m_factory->m_actions.end();
210 if (it->match_action_name ("INSERT_SPACE") &&
211 it->perform (this, key)) {
216 for (it = m_factory->m_actions.begin();
217 it != m_factory->m_actions.end();
220 if (it->perform (this, key)) {
221 m_last_key = KeyEvent ();
226 m_last_key = KeyEvent ();
232 AnthyInstance::process_key_event_latin_mode (const KeyEvent &key)
234 if (key.is_key_release ())
237 if (util_key_is_keypad (key)) {
240 util_keypad_to_string (str, key);
241 if (m_factory->m_ten_key_type == "Wide")
242 util_convert_to_wide (wide, str);
244 wide = utf8_mbstowcs (str);
245 if (wide.length () > 0) {
246 commit_string (wide);
252 // for Multi/Dead key
258 AnthyInstance::process_key_event_wide_latin_mode (const KeyEvent &key)
260 if (key.is_key_release ())
265 util_keypad_to_string (str, key);
266 if (util_key_is_keypad (key) && m_factory->m_ten_key_type == "Half")
267 wide = utf8_mbstowcs (str);
269 util_convert_to_wide (wide, str);
270 if (wide.length () > 0) {
271 commit_string (wide);
279 AnthyInstance::process_key_event (const KeyEvent& key)
281 SCIM_DEBUG_IMENGINE(2) << "process_key_event.\n";
284 // for NICOLA thumb shift key
285 if (get_typing_method () == SCIM_ANTHY_TYPING_METHOD_NICOLA &&
286 is_nicola_thumb_shift_key (key))
288 if (process_key_event_input (key))
292 // lookup user defined key bindings
293 if (process_key_event_lookup_keybind (key))
297 if (m_preedit.get_input_mode () == SCIM_ANTHY_MODE_LATIN)
298 return process_key_event_latin_mode (key);
300 // for wide Latin mode
301 if (m_preedit.get_input_mode () == SCIM_ANTHY_MODE_WIDE_LATIN)
302 return process_key_event_wide_latin_mode (key);
305 if (get_typing_method () != SCIM_ANTHY_TYPING_METHOD_NICOLA ||
306 !is_nicola_thumb_shift_key (key))
308 if (process_key_event_input (key))
312 if (m_preedit.is_preediting ())
319 AnthyInstance::move_preedit_caret (unsigned int pos)
321 m_preedit.set_caret_pos (pos);
322 update_preedit_caret (m_preedit.get_caret_pos());
326 AnthyInstance::select_candidate_no_direct (unsigned int item)
328 SCIM_DEBUG_IMENGINE(2) << "select_candidate_no_direct.\n";
330 if (m_preedit.is_predicting () && !m_preedit.is_converting ())
333 if (!is_selecting_candidates ())
336 // update lookup table
337 m_lookup_table.set_cursor_pos_in_current_page (item);
338 update_lookup_table (m_lookup_table);
341 m_preedit.select_candidate (m_lookup_table.get_cursor_pos ());
345 if (m_factory->m_show_candidates_label)
350 AnthyInstance::select_candidate (unsigned int item)
352 SCIM_DEBUG_IMENGINE(2) << "select_candidate.\n";
354 select_candidate_no_direct (item);
356 if (m_factory->m_close_cand_win_on_select) {
357 unset_lookup_table ();
358 action_select_next_segment();
363 AnthyInstance::update_lookup_table_page_size (unsigned int page_size)
365 SCIM_DEBUG_IMENGINE(2) << "update_lookup_table_page_size.\n";
367 m_lookup_table.set_page_size (page_size);
371 AnthyInstance::lookup_table_page_up ()
373 if (!is_selecting_candidates () ||
374 !m_lookup_table.get_current_page_start ())
379 SCIM_DEBUG_IMENGINE(2) << "lookup_table_page_up.\n";
381 m_lookup_table.page_up ();
383 update_lookup_table (m_lookup_table);
387 AnthyInstance::lookup_table_page_down ()
389 int page_start = m_lookup_table.get_current_page_start ();
390 int page_size = m_lookup_table.get_current_page_size ();
391 int num = m_lookup_table.number_of_candidates ();
393 if (!is_selecting_candidates () || page_start + page_size >= num)
396 SCIM_DEBUG_IMENGINE(2) << "lookup_table_page_down.\n";
398 m_lookup_table.page_down ();
400 update_lookup_table (m_lookup_table);
404 AnthyInstance::reset ()
406 SCIM_DEBUG_IMENGINE(2) <<m_factory->m_behavior_on_focus_out<< "reset..\n";
408 if (m_preedit.is_preediting ()) {
409 if (m_factory->m_behavior_on_focus_out == "Clear")
411 else if (m_factory->m_behavior_on_focus_out == "Commit")
412 action_commit (m_factory->m_learn_on_auto_commit);
414 action_commit (m_factory->m_learn_on_auto_commit);
419 AnthyInstance::flush ()
421 SCIM_DEBUG_IMENGINE(3) << "flush ()\n";
423 m_lookup_table.clear ();
424 unset_lookup_table ();
426 hide_preedit_string ();
427 m_preedit_string_visible = false;
432 AnthyInstance::focus_in ()
434 SCIM_DEBUG_IMENGINE(2) << "focus_in.\n";
436 if (m_preedit_string_visible) {
438 show_preedit_string ();
440 hide_preedit_string ();
443 if (m_lookup_table_visible && is_selecting_candidates ()) {
444 if (m_factory->m_show_candidates_label &&
445 m_lookup_table.number_of_candidates() > 0)
452 update_lookup_table (m_lookup_table);
453 show_lookup_table ();
456 hide_lookup_table ();
459 install_properties ();
461 if (!m_helper_started)
462 start_helper (String (SCIM_ANTHY_HELPER_UUID));
465 send.put_command (SCIM_TRANS_CMD_REQUEST);
466 send.put_command (SCIM_TRANS_CMD_FOCUS_IN);
467 send_helper_event (String (SCIM_ANTHY_HELPER_UUID), send);
471 AnthyInstance::focus_out ()
473 SCIM_DEBUG_IMENGINE(2) << "focus_out.\n";
478 send.put_command (SCIM_TRANS_CMD_REQUEST);
479 send.put_command (SCIM_TRANS_CMD_FOCUS_OUT);
480 send_helper_event (String (SCIM_ANTHY_HELPER_UUID), send);
484 AnthyInstance::set_preedition (void)
486 update_preedit_string (m_preedit.get_string (),
487 m_preedit.get_attribute_list ());
488 update_preedit_caret (m_preedit.get_caret_pos());
492 AnthyInstance::set_aux_string (void)
495 sprintf (buf, _("Candidates (%d/%d)"),
496 m_lookup_table.get_cursor_pos () + 1,
497 m_lookup_table.number_of_candidates ());
498 update_aux_string (utf8_mbstowcs (buf));
502 AnthyInstance::set_lookup_table (void)
504 m_n_conv_key_pressed++;
506 if (!is_selecting_candidates ()) {
507 if (is_realtime_conversion () &&
508 m_preedit.get_selected_segment () < 0)
510 // select latest segment
511 int n = m_preedit.get_nr_segments ();
514 m_preedit.select_segment (n - 1);
517 // prepare candidates
518 m_preedit.get_candidates (m_lookup_table);
520 if (m_lookup_table.number_of_candidates () == 0)
524 update_lookup_table (m_lookup_table);
527 m_preedit.select_candidate (m_lookup_table.get_cursor_pos ());
532 bool beyond_threshold =
533 m_factory->m_n_triggers_to_show_cand_win > 0 &&
534 (int) m_n_conv_key_pressed >= m_factory->m_n_triggers_to_show_cand_win;
536 if (!m_lookup_table_visible &&
537 (m_preedit.is_predicting () || beyond_threshold))
539 show_lookup_table ();
540 m_lookup_table_visible = true;
541 m_n_conv_key_pressed = 0;
543 if (m_factory->m_show_candidates_label) {
547 } else if (!m_lookup_table_visible) {
548 hide_lookup_table ();
553 AnthyInstance::unset_lookup_table (void)
555 m_lookup_table.clear ();
556 hide_lookup_table ();
557 m_lookup_table_visible = false;
558 m_n_conv_key_pressed = 0;
560 update_aux_string (utf8_mbstowcs (""));
565 AnthyInstance::install_properties (void)
567 if (m_properties.size () <= 0) {
570 if (m_factory->m_show_input_mode_label) {
571 prop = Property (SCIM_PROP_INPUT_MODE,
572 "\xE3\x81\x82", String (""), _("Input mode"));
573 m_properties.push_back (prop);
575 prop = Property (SCIM_PROP_INPUT_MODE_HIRAGANA,
576 _("Hiragana"), String (""), _("Hiragana"));
577 m_properties.push_back (prop);
579 prop = Property (SCIM_PROP_INPUT_MODE_KATAKANA,
580 _("Katakana"), String (""), _("Katakana"));
581 m_properties.push_back (prop);
583 prop = Property (SCIM_PROP_INPUT_MODE_HALF_KATAKANA,
584 _("Half width katakana"), String (""),
585 _("Half width katakana"));
586 m_properties.push_back (prop);
588 prop = Property (SCIM_PROP_INPUT_MODE_LATIN,
589 _("Latin"), String (""), _("Direct input"));
590 m_properties.push_back (prop);
592 prop = Property (SCIM_PROP_INPUT_MODE_WIDE_LATIN,
593 _("Wide latin"), String (""), _("Wide latin"));
594 m_properties.push_back (prop);
597 if (m_factory->m_show_typing_method_label) {
598 prop = Property (SCIM_PROP_TYPING_METHOD,
599 "\xEF\xBC\xB2", String (""), _("Typing method"));
600 m_properties.push_back (prop);
602 prop = Property (SCIM_PROP_TYPING_METHOD_ROMAJI,
603 _("Romaji"), String (""), _("Romaji"));
604 m_properties.push_back (prop);
606 prop = Property (SCIM_PROP_TYPING_METHOD_KANA,
607 _("Kana"), String (""), _("Kana"));
608 m_properties.push_back (prop);
610 prop = Property (SCIM_PROP_TYPING_METHOD_NICOLA,
611 _("Thumb shift"), String (""), _("Thumb shift"));
612 m_properties.push_back (prop);
615 if (m_factory->m_show_conv_mode_label) {
616 prop = Property (SCIM_PROP_CONV_MODE,
617 "\xE9\x80\xA3", String (""),
618 _("Conversion mode"));
619 m_properties.push_back (prop);
621 prop = Property (SCIM_PROP_CONV_MODE_MULTI_SEG,
622 _("Multi segment"), String (""),
624 m_properties.push_back (prop);
626 prop = Property (SCIM_PROP_CONV_MODE_SINGLE_SEG,
627 _("Single segment"), String (""),
628 _("Single segment"));
629 m_properties.push_back (prop);
631 prop = Property (SCIM_PROP_CONV_MODE_MULTI_REAL_TIME,
632 _("Convert as you type (Multi segment)"),
634 _("Convert as you type (Multi segment)"));
635 m_properties.push_back (prop);
637 prop = Property (SCIM_PROP_CONV_MODE_SINGLE_REAL_TIME,
638 _("Convert as you type (Single segment)"),
640 _("Convert as you type (Single segment)"));
641 m_properties.push_back (prop);
644 if (m_factory->m_show_period_style_label) {
645 prop = Property (SCIM_PROP_PERIOD_STYLE,
646 "\xE3\x80\x81\xE3\x80\x82", String (""),
648 m_properties.push_back (prop);
650 prop = Property (SCIM_PROP_PERIOD_STYLE_JAPANESE,
651 "\xE3\x80\x81\xE3\x80\x82", String (""),
652 "\xE3\x80\x81\xE3\x80\x82");
653 m_properties.push_back (prop);
655 prop = Property (SCIM_PROP_PERIOD_STYLE_WIDE_LATIN_JAPANESE,
656 "\xEF\xBC\x8C\xE3\x80\x82", String (""),
657 "\xEF\xBC\x8C\xE3\x80\x82");
658 m_properties.push_back (prop);
660 prop = Property (SCIM_PROP_PERIOD_STYLE_WIDE_LATIN,
661 "\xEF\xBC\x8C\xEF\xBC\x8E", String (""),
662 "\xEF\xBC\x8C\xEF\xBC\x8E");
663 m_properties.push_back (prop);
665 prop = Property (SCIM_PROP_PERIOD_STYLE_LATIN,
666 ",.", String (""), ",.");
667 m_properties.push_back (prop);
670 if (m_factory->m_show_symbol_style_label) {
671 prop = Property (SCIM_PROP_SYMBOL_STYLE,
672 UTF8_BRACKET_CORNER_BEGIN
673 UTF8_BRACKET_CORNER_END
677 m_properties.push_back (prop);
679 prop = Property (SCIM_PROP_SYMBOL_STYLE_JAPANESE,
680 UTF8_BRACKET_CORNER_BEGIN
681 UTF8_BRACKET_CORNER_END
684 UTF8_BRACKET_CORNER_BEGIN
685 UTF8_BRACKET_CORNER_END
687 m_properties.push_back (prop);
689 prop = Property (SCIM_PROP_SYMBOL_STYLE_CORNER_BRACKET_SLASH,
690 UTF8_BRACKET_CORNER_BEGIN
691 UTF8_BRACKET_CORNER_END
694 UTF8_BRACKET_CORNER_BEGIN
695 UTF8_BRACKET_CORNER_END
697 m_properties.push_back (prop);
699 prop = Property (SCIM_PROP_SYMBOL_STYLE_BRACKET_MIDDLE_DOT,
700 UTF8_BRACKET_WIDE_BEGIN
701 UTF8_BRACKET_WIDE_END
704 UTF8_BRACKET_WIDE_BEGIN
705 UTF8_BRACKET_WIDE_END
707 m_properties.push_back (prop);
709 prop = Property (SCIM_PROP_SYMBOL_STYLE_BRACKET_SLASH,
710 UTF8_BRACKET_WIDE_BEGIN
711 UTF8_BRACKET_WIDE_END
714 UTF8_BRACKET_WIDE_BEGIN
715 UTF8_BRACKET_WIDE_END
717 m_properties.push_back (prop);
720 if (m_factory->m_show_dict_label) {
721 prop = Property (SCIM_PROP_DICT,
722 String(""), //_("Dictionary"),
723 String (SCIM_ICONDIR "/" "scim-anthy-dict.png"),
724 _("Dictionary menu"));
725 m_properties.push_back (prop);
727 if (m_factory->m_show_dict_admin_label) {
728 prop = Property (SCIM_PROP_DICT_LAUNCH_ADMIN_TOOL,
729 _("Edit the dictionary"),
730 String (SCIM_ICONDIR "/" "scim-anthy-dict.png"),
731 _("Launch the dictionary administration tool."));
732 m_properties.push_back (prop);
735 if (m_factory->m_show_add_word_label) {
736 prop = Property (SCIM_PROP_DICT_ADD_WORD,
738 String (SCIM_ICONDIR "/" "scim-anthy-dict.png"),
739 _("Add a word to the dictionary."));
740 m_properties.push_back (prop);
745 set_input_mode(get_input_mode ());
746 set_conversion_mode (m_conv_mode);
747 set_typing_method (get_typing_method ());
748 set_period_style (m_preedit.get_period_style (),
749 m_preedit.get_comma_style ());
750 set_symbol_style (m_preedit.get_bracket_style (),
751 m_preedit.get_slash_style ());
753 register_properties (m_properties);
757 AnthyInstance::set_input_mode (InputMode mode)
759 const char *label = "";
762 case SCIM_ANTHY_MODE_HIRAGANA:
763 label = "\xE3\x81\x82";
765 case SCIM_ANTHY_MODE_KATAKANA:
766 label = "\xE3\x82\xA2";
768 case SCIM_ANTHY_MODE_HALF_KATAKANA:
769 label = "_\xEF\xBD\xB1";
771 case SCIM_ANTHY_MODE_LATIN:
774 case SCIM_ANTHY_MODE_WIDE_LATIN:
775 label = "\xEF\xBC\xA1";
781 if (label && *label && m_factory->m_show_input_mode_label) {
782 PropertyList::iterator it = std::find (m_properties.begin (),
784 SCIM_PROP_INPUT_MODE);
785 if (it != m_properties.end ()) {
786 it->set_label (label);
787 update_property (*it);
791 if (mode != get_input_mode ()) {
792 m_preedit.set_input_mode (mode);
798 AnthyInstance::set_conversion_mode (ConversionMode mode)
800 const char *label = "";
803 case SCIM_ANTHY_CONVERSION_MULTI_SEGMENT:
804 label = "\xE9\x80\xA3";
806 case SCIM_ANTHY_CONVERSION_SINGLE_SEGMENT:
807 label = "\xE5\x8D\x98";
809 case SCIM_ANTHY_CONVERSION_MULTI_SEGMENT_IMMEDIATE:
810 label = "\xE9\x80\x90 \xE9\x80\xA3";
812 case SCIM_ANTHY_CONVERSION_SINGLE_SEGMENT_IMMEDIATE:
813 label = "\xE9\x80\x90 \xE5\x8D\x98";
819 if (label && *label /*&& m_factory->m_show_input_mode_label*/) {
820 PropertyList::iterator it = std::find (m_properties.begin (),
822 SCIM_PROP_CONV_MODE);
823 if (it != m_properties.end ()) {
824 it->set_label (label);
825 update_property (*it);
833 AnthyInstance::set_typing_method (TypingMethod method)
835 const char *label = "";
838 case SCIM_ANTHY_TYPING_METHOD_ROMAJI:
839 label = "\xEF\xBC\xB2";
841 case SCIM_ANTHY_TYPING_METHOD_KANA:
842 label = "\xE3\x81\x8B";
844 case SCIM_ANTHY_TYPING_METHOD_NICOLA:
845 label = "\xE8\xA6\xAA";
851 if (label && *label && m_factory->m_show_typing_method_label) {
852 PropertyList::iterator it = std::find (m_properties.begin (),
854 SCIM_PROP_TYPING_METHOD);
855 if (it != m_properties.end ()) {
856 it->set_label (label);
857 update_property (*it);
861 if (method != get_typing_method ()) {
862 Key2KanaTable *fundamental_table = NULL;
864 if (method == SCIM_ANTHY_TYPING_METHOD_ROMAJI) {
865 fundamental_table = m_factory->m_custom_romaji_table;
866 } else if (method == SCIM_ANTHY_TYPING_METHOD_KANA) {
867 fundamental_table = m_factory->m_custom_kana_table;
869 m_preedit.set_typing_method (method);
870 m_preedit.set_pseudo_ascii_mode (get_pseudo_ascii_mode ());
875 AnthyInstance::set_period_style (PeriodStyle period,
881 case SCIM_ANTHY_COMMA_JAPANESE:
882 label = "\xE3\x80\x81";
884 case SCIM_ANTHY_COMMA_WIDE:
885 label = "\xEF\xBC\x8C";
887 case SCIM_ANTHY_COMMA_HALF:
895 case SCIM_ANTHY_PERIOD_JAPANESE:
896 label += "\xE3\x80\x82";
898 case SCIM_ANTHY_PERIOD_WIDE:
899 label += "\xEF\xBC\x8E";
901 case SCIM_ANTHY_PERIOD_HALF:
908 if (label.length () > 0) {
909 PropertyList::iterator it = std::find (m_properties.begin (),
911 SCIM_PROP_PERIOD_STYLE);
912 if (it != m_properties.end ()) {
913 it->set_label (label.c_str ());
914 update_property (*it);
918 if (period != m_preedit.get_period_style ())
919 m_preedit.set_period_style (period);
920 if (comma != m_preedit.get_comma_style ())
921 m_preedit.set_comma_style (comma);
925 AnthyInstance::set_symbol_style (BracketStyle bracket,
931 case SCIM_ANTHY_BRACKET_JAPANESE:
932 label = UTF8_BRACKET_CORNER_BEGIN UTF8_BRACKET_CORNER_END;
934 case SCIM_ANTHY_BRACKET_WIDE:
935 label = UTF8_BRACKET_WIDE_BEGIN UTF8_BRACKET_WIDE_END;
942 case SCIM_ANTHY_SLASH_JAPANESE:
943 label += UTF8_MIDDLE_DOT;
945 case SCIM_ANTHY_SLASH_WIDE:
946 label += UTF8_SLASH_WIDE;
952 if (label.length () > 0) {
953 PropertyList::iterator it = std::find (m_properties.begin (),
955 SCIM_PROP_SYMBOL_STYLE);
956 if (it != m_properties.end ()) {
957 it->set_label (label.c_str ());
958 update_property (*it);
962 if (bracket != m_preedit.get_bracket_style ())
963 m_preedit.set_bracket_style (bracket);
964 if (slash != m_preedit.get_slash_style ())
965 m_preedit.set_slash_style (slash);
969 AnthyInstance::is_selecting_candidates (void)
971 if (m_lookup_table.number_of_candidates ())
978 AnthyInstance::action_do_nothing (void)
984 AnthyInstance::action_convert (void)
986 if (!m_preedit.is_preediting ())
989 if (!m_preedit.is_converting ()) {
990 // show conversion string
992 m_preedit.convert (SCIM_ANTHY_CANDIDATE_DEFAULT,
993 is_single_segment ());
1003 AnthyInstance::action_predict (void)
1005 if (!m_preedit.is_preediting ())
1008 if (m_preedit.is_converting ())
1011 if (!m_preedit.is_predicting ())
1012 m_preedit.predict ();
1014 m_preedit.select_candidate (0);
1016 set_lookup_table ();
1017 select_candidate_no_direct (0);
1024 AnthyInstance::action_revert (void)
1026 if (m_preedit.is_reconverting ()) {
1027 m_preedit.revert ();
1028 commit_string (m_preedit.get_string ());
1033 if (!m_preedit.is_preediting ())
1036 if (!m_preedit.is_converting ()) {
1041 if (is_selecting_candidates ()) {
1042 m_lookup_table.clear ();
1043 if (m_lookup_table_visible) {
1044 unset_lookup_table ();
1049 unset_lookup_table ();
1050 m_preedit.revert ();
1057 AnthyInstance::action_cancel_all (void)
1059 if (!m_preedit.is_preediting ())
1067 AnthyInstance::action_commit (bool learn)
1069 if (!m_preedit.is_preediting ())
1072 if (m_preedit.is_converting ()) {
1073 commit_string (m_preedit.get_string ());
1075 m_preedit.commit ();
1077 m_preedit.finish ();
1078 commit_string (m_preedit.get_string ());
1087 AnthyInstance::action_commit_follow_preference (void)
1089 return action_commit (m_factory->m_learn_on_manual_commit);
1093 AnthyInstance::action_commit_reverse_preference (void)
1095 return action_commit (!m_factory->m_learn_on_manual_commit);
1099 AnthyInstance::action_back (void)
1101 if (!m_preedit.is_preediting ())
1104 if (m_preedit.is_converting ()) {
1106 if (!is_realtime_conversion ())
1112 if (m_preedit.get_length () > 0) {
1113 if (is_realtime_conversion ()) {
1114 m_preedit.convert (SCIM_ANTHY_CANDIDATE_DEFAULT,
1115 is_single_segment ());
1116 m_preedit.select_segment (-1);
1127 AnthyInstance::action_delete (void)
1129 if (!m_preedit.is_preediting ())
1132 if (m_preedit.is_converting ()) {
1134 if (!is_realtime_conversion ())
1138 m_preedit.erase (false);
1140 if (m_preedit.get_length () > 0) {
1141 if (is_realtime_conversion ()) {
1142 m_preedit.convert (SCIM_ANTHY_CANDIDATE_DEFAULT,
1143 is_single_segment ());
1144 m_preedit.select_segment (-1);
1155 AnthyInstance::action_insert_space (void)
1158 bool is_wide = false, retval = false;
1160 if (m_preedit.is_preediting () && !m_factory->m_romaji_pseudo_ascii_blank_behavior)
1163 if (m_factory->m_space_type == "FollowMode") {
1164 InputMode mode = get_input_mode ();
1165 if (mode == SCIM_ANTHY_MODE_LATIN ||
1166 mode == SCIM_ANTHY_MODE_HALF_KATAKANA ||
1167 m_preedit.is_pseudo_ascii_mode ())
1173 } else if (m_factory->m_space_type == "Wide") {
1178 str = "\xE3\x80\x80";
1180 } else if (get_typing_method () == SCIM_ANTHY_TYPING_METHOD_NICOLA || // FIXME! it's a ad-hoc solution.
1181 m_preedit.is_pseudo_ascii_mode () ||
1182 (m_last_key.code != SCIM_KEY_space &&
1183 m_last_key.code != SCIM_KEY_KP_Space))
1190 if (m_preedit.is_pseudo_ascii_mode ()) {
1191 m_preedit.append (m_last_key, str);
1192 show_preedit_string ();
1193 m_preedit_string_visible = true;
1196 commit_string (utf8_mbstowcs (str));
1204 AnthyInstance::action_insert_alternative_space (void)
1206 bool is_wide = false;
1208 if (m_preedit.is_preediting ())
1211 if (m_factory->m_space_type == "FollowMode") {
1212 InputMode mode = get_input_mode ();
1213 if (mode == SCIM_ANTHY_MODE_LATIN ||
1214 mode == SCIM_ANTHY_MODE_HALF_KATAKANA)
1220 } else if (m_factory->m_space_type != "Wide") {
1225 commit_string (utf8_mbstowcs ("\xE3\x80\x80"));
1227 } else if (get_typing_method () == SCIM_ANTHY_TYPING_METHOD_NICOLA || // FIXME! it's a ad-hoc solution.
1228 (m_last_key.code != SCIM_KEY_space &&
1229 m_last_key.code != SCIM_KEY_KP_Space))
1231 commit_string (utf8_mbstowcs (" "));
1239 AnthyInstance::action_insert_half_space (void)
1241 if (m_preedit.is_preediting ())
1244 if (m_last_key.code != SCIM_KEY_space &&
1245 m_last_key.code != SCIM_KEY_KP_Space)
1247 commit_string (utf8_mbstowcs (" "));
1255 AnthyInstance::action_insert_wide_space (void)
1257 if (m_preedit.is_preediting ())
1260 commit_string (utf8_mbstowcs ("\xE3\x80\x80"));
1266 AnthyInstance::action_move_caret_backward (void)
1268 if (!m_preedit.is_preediting ())
1270 if (m_preedit.is_converting ())
1273 m_preedit.move_caret(-1);
1280 AnthyInstance::action_move_caret_forward (void)
1282 if (!m_preedit.is_preediting ())
1284 if (m_preedit.is_converting ())
1287 m_preedit.move_caret(1);
1294 AnthyInstance::action_move_caret_first (void)
1296 if (!m_preedit.is_preediting ())
1298 if (m_preedit.is_converting ())
1301 m_preedit.set_caret_pos (0);
1308 AnthyInstance::action_move_caret_last (void)
1310 if (!m_preedit.is_preediting ())
1312 if (m_preedit.is_converting ())
1315 m_preedit.set_caret_pos (m_preedit.get_length ());
1322 AnthyInstance::action_select_prev_segment (void)
1324 if (!m_preedit.is_converting ())
1327 unset_lookup_table ();
1329 int idx = m_preedit.get_selected_segment ();
1331 int n = m_preedit.get_nr_segments ();
1332 if (n <= 0) return false;
1333 m_preedit.select_segment (n - 1);
1335 m_preedit.select_segment (idx - 1);
1343 AnthyInstance::action_select_next_segment (void)
1345 if (!m_preedit.is_converting ())
1348 unset_lookup_table ();
1350 int idx = m_preedit.get_selected_segment ();
1352 m_preedit.select_segment(0);
1354 int n = m_preedit.get_nr_segments ();
1358 m_preedit.select_segment(0);
1360 m_preedit.select_segment(idx + 1);
1368 AnthyInstance::action_select_first_segment (void)
1370 if (!m_preedit.is_converting ())
1373 unset_lookup_table ();
1375 m_preedit.select_segment(0);
1382 AnthyInstance::action_select_last_segment (void)
1384 if (!m_preedit.is_converting ())
1387 int n = m_preedit.get_nr_segments ();
1388 if (n <= 0) return false;
1390 unset_lookup_table ();
1392 m_preedit.select_segment(n - 1);
1399 AnthyInstance::action_shrink_segment (void)
1401 if (!m_preedit.is_converting ())
1404 unset_lookup_table ();
1406 m_preedit.resize_segment (-1);
1413 AnthyInstance::action_expand_segment (void)
1415 if (!m_preedit.is_converting ())
1418 unset_lookup_table ();
1420 m_preedit.resize_segment (1);
1427 AnthyInstance::action_commit_first_segment (void)
1429 if (!m_preedit.is_converting ()) {
1430 if (m_preedit.is_preediting ()) {
1431 return action_commit (m_factory->m_learn_on_manual_commit);
1437 unset_lookup_table ();
1439 commit_string (m_preedit.get_segment_string (0));
1440 if (m_factory->m_learn_on_manual_commit)
1441 m_preedit.commit (0);
1443 m_preedit.clear (0);
1451 AnthyInstance::action_commit_selected_segment (void)
1453 if (!m_preedit.is_converting ()) {
1454 if (m_preedit.is_preediting ()) {
1455 return action_commit (m_factory->m_learn_on_manual_commit);
1461 unset_lookup_table ();
1463 for (int i = 0; i <= m_preedit.get_selected_segment (); i++)
1464 commit_string (m_preedit.get_segment_string (i));
1465 if (m_factory->m_learn_on_manual_commit)
1466 m_preedit.commit (m_preedit.get_selected_segment ());
1468 m_preedit.clear (m_preedit.get_selected_segment ());
1476 AnthyInstance::action_commit_first_segment_reverse_preference (void)
1478 if (!m_preedit.is_converting ()) {
1479 if (m_preedit.is_preediting ()) {
1480 return action_commit (!m_factory->m_learn_on_manual_commit);
1486 unset_lookup_table ();
1488 commit_string (m_preedit.get_segment_string (0));
1489 if (!m_factory->m_learn_on_manual_commit)
1490 m_preedit.commit (0);
1492 m_preedit.clear (0);
1500 AnthyInstance::action_commit_selected_segment_reverse_preference (void)
1502 if (!m_preedit.is_converting ()) {
1503 if (m_preedit.is_preediting ()) {
1504 return action_commit (!m_factory->m_learn_on_manual_commit);
1510 unset_lookup_table ();
1512 for (int i = 0; i <= m_preedit.get_selected_segment (); i++)
1513 commit_string (m_preedit.get_segment_string (i));
1514 if (!m_factory->m_learn_on_manual_commit)
1515 m_preedit.commit (m_preedit.get_selected_segment ());
1517 m_preedit.clear (m_preedit.get_selected_segment ());
1525 AnthyInstance::action_select_next_candidate (void)
1527 if (!m_preedit.is_converting ())
1530 //if (!is_selecting_candidates ())
1531 set_lookup_table ();
1533 int end = m_lookup_table.number_of_candidates () - 1;
1534 if (m_lookup_table.get_cursor_pos () == end) {
1535 m_lookup_table.set_cursor_pos (0);
1537 m_lookup_table.cursor_down ();
1540 int pos_in_page = m_lookup_table.get_cursor_pos_in_current_page ();
1541 select_candidate_no_direct (pos_in_page);
1547 AnthyInstance::action_select_prev_candidate (void)
1549 if (!m_preedit.is_converting ()) return false;
1551 //if (!is_selecting_candidates ())
1552 set_lookup_table ();
1554 int end = m_lookup_table.number_of_candidates () - 1;
1555 if (m_lookup_table.get_cursor_pos () == 0)
1556 m_lookup_table.set_cursor_pos (end);
1558 m_lookup_table.cursor_up ();
1560 int pos_in_page = m_lookup_table.get_cursor_pos_in_current_page ();
1561 select_candidate_no_direct (pos_in_page);
1567 AnthyInstance::action_select_first_candidate (void)
1569 if (!m_preedit.is_converting ()) return false;
1570 if (!is_selecting_candidates ()) return false;
1572 m_lookup_table.set_cursor_pos (0);
1574 int pos_in_page = m_lookup_table.get_cursor_pos_in_current_page ();
1575 select_candidate_no_direct (pos_in_page);
1581 AnthyInstance::action_select_last_candidate (void)
1583 if (!m_preedit.is_converting ()) return false;
1584 if (!is_selecting_candidates ()) return false;
1586 int end = m_lookup_table.number_of_candidates () - 1;
1587 m_lookup_table.set_cursor_pos (end);
1589 int pos_in_page = m_lookup_table.get_cursor_pos_in_current_page ();
1590 select_candidate_no_direct (pos_in_page);
1596 AnthyInstance::action_candidates_page_up(void)
1598 if (!m_preedit.is_converting ()) return false;
1599 if (!is_selecting_candidates ()) return false;
1600 if (!m_lookup_table_visible) return false;
1602 m_lookup_table.page_up ();
1604 int pos_in_page = m_lookup_table.get_cursor_pos_in_current_page ();
1605 select_candidate_no_direct (pos_in_page);
1611 AnthyInstance::action_candidates_page_down (void)
1613 if (!m_preedit.is_converting ()) return false;
1614 if (!is_selecting_candidates ()) return false;
1615 if (!m_lookup_table_visible) return false;
1617 m_lookup_table.page_down ();
1619 int pos_in_page = m_lookup_table.get_cursor_pos_in_current_page ();
1620 select_candidate_no_direct (pos_in_page);
1626 AnthyInstance::action_select_candidate (unsigned int i)
1628 // FIXME! m_lookup_table_visible should be set as true also on predicting
1629 if (!m_lookup_table_visible && !m_preedit.is_predicting ())
1632 if (m_preedit.is_predicting () && !m_preedit.is_converting () &&
1633 m_factory->m_use_direct_key_on_predict)
1635 CommonLookupTable table;
1636 m_preedit.get_candidates (table);
1637 if (i < table.number_of_candidates ()) {
1638 select_candidate (i);
1641 } else if (m_preedit.is_converting () && is_selecting_candidates ()) {
1642 select_candidate (i);
1650 AnthyInstance::action_select_candidate_1 (void)
1652 return action_select_candidate (0);
1656 AnthyInstance::action_select_candidate_2 (void)
1658 return action_select_candidate (1);
1662 AnthyInstance::action_select_candidate_3 (void)
1664 return action_select_candidate (2);
1668 AnthyInstance::action_select_candidate_4 (void)
1670 return action_select_candidate (3);
1674 AnthyInstance::action_select_candidate_5 (void)
1676 return action_select_candidate (4);
1680 AnthyInstance::action_select_candidate_6 (void)
1682 return action_select_candidate (5);
1686 AnthyInstance::action_select_candidate_7 (void)
1688 return action_select_candidate (6);
1693 AnthyInstance::action_select_candidate_8 (void)
1695 return action_select_candidate (7);
1699 AnthyInstance::action_select_candidate_9 (void)
1701 return action_select_candidate (8);
1705 AnthyInstance::action_select_candidate_10 (void)
1707 return action_select_candidate (9);
1711 AnthyInstance::action_circle_input_mode (void)
1713 InputMode mode = get_input_mode ();
1716 case SCIM_ANTHY_MODE_HIRAGANA:
1717 mode = SCIM_ANTHY_MODE_KATAKANA;
1719 case SCIM_ANTHY_MODE_KATAKANA:
1720 mode = SCIM_ANTHY_MODE_HALF_KATAKANA;
1722 case SCIM_ANTHY_MODE_HALF_KATAKANA:
1723 mode = SCIM_ANTHY_MODE_LATIN;
1725 case SCIM_ANTHY_MODE_LATIN:
1726 mode = SCIM_ANTHY_MODE_WIDE_LATIN;
1728 case SCIM_ANTHY_MODE_WIDE_LATIN:
1729 mode = SCIM_ANTHY_MODE_HIRAGANA;
1732 mode = SCIM_ANTHY_MODE_HIRAGANA;
1736 set_input_mode (mode);
1742 AnthyInstance::action_circle_typing_method (void)
1744 TypingMethod method;
1746 method = get_typing_method ();
1747 if (method == SCIM_ANTHY_TYPING_METHOD_NICOLA)
1748 method = SCIM_ANTHY_TYPING_METHOD_ROMAJI;
1749 else if (method == SCIM_ANTHY_TYPING_METHOD_KANA)
1750 method = SCIM_ANTHY_TYPING_METHOD_NICOLA;
1752 method = SCIM_ANTHY_TYPING_METHOD_KANA;
1754 set_typing_method (method);
1760 AnthyInstance::action_circle_kana_mode (void)
1764 if (get_input_mode () == SCIM_ANTHY_MODE_LATIN ||
1765 get_input_mode () == SCIM_ANTHY_MODE_WIDE_LATIN)
1767 mode = SCIM_ANTHY_MODE_HIRAGANA;
1769 switch (get_input_mode ()) {
1770 case SCIM_ANTHY_MODE_HIRAGANA:
1771 mode = SCIM_ANTHY_MODE_KATAKANA;
1773 case SCIM_ANTHY_MODE_KATAKANA:
1774 mode = SCIM_ANTHY_MODE_HALF_KATAKANA;
1776 case SCIM_ANTHY_MODE_HALF_KATAKANA:
1778 mode = SCIM_ANTHY_MODE_HIRAGANA;
1783 set_input_mode (mode);
1789 AnthyInstance::action_on_off (void)
1791 if (get_input_mode () == SCIM_ANTHY_MODE_LATIN ||
1792 get_input_mode () == SCIM_ANTHY_MODE_WIDE_LATIN)
1794 set_input_mode (m_prev_input_mode);
1795 m_preedit.set_input_mode (m_prev_input_mode);
1797 m_prev_input_mode = get_input_mode ();
1798 set_input_mode (SCIM_ANTHY_MODE_LATIN);
1799 m_preedit.set_input_mode (SCIM_ANTHY_MODE_LATIN);
1806 AnthyInstance::action_latin_mode (void)
1808 set_input_mode (SCIM_ANTHY_MODE_LATIN);
1813 AnthyInstance::action_wide_latin_mode (void)
1815 set_input_mode (SCIM_ANTHY_MODE_WIDE_LATIN);
1820 AnthyInstance::action_hiragana_mode (void)
1822 set_input_mode (SCIM_ANTHY_MODE_HIRAGANA);
1827 AnthyInstance::action_katakana_mode (void)
1829 set_input_mode (SCIM_ANTHY_MODE_KATAKANA);
1834 AnthyInstance::action_half_katakana_mode (void)
1836 set_input_mode (SCIM_ANTHY_MODE_HALF_KATAKANA);
1841 AnthyInstance::action_cancel_pseudo_ascii_mode (void)
1843 if (!m_preedit.is_preediting ())
1845 if (!m_preedit.is_pseudo_ascii_mode ())
1848 m_preedit.reset_pseudo_ascii_mode ();
1854 AnthyInstance::convert_kana (CandidateType type)
1856 if (!m_preedit.is_preediting ())
1859 if (m_preedit.is_reconverting ())
1862 unset_lookup_table ();
1864 if (m_preedit.is_converting ()) {
1865 int idx = m_preedit.get_selected_segment ();
1868 m_preedit.finish ();
1869 m_preedit.convert (type, true);
1871 m_preedit.select_candidate (type);
1874 m_preedit.finish ();
1875 m_preedit.convert (type, true);
1884 AnthyInstance::action_convert_to_hiragana (void)
1886 return convert_kana (SCIM_ANTHY_CANDIDATE_HIRAGANA);
1890 AnthyInstance::action_convert_to_katakana (void)
1892 return convert_kana (SCIM_ANTHY_CANDIDATE_KATAKANA);
1896 AnthyInstance::action_convert_to_half (void)
1898 return convert_kana (SCIM_ANTHY_CANDIDATE_HALF);
1902 AnthyInstance::action_convert_to_half_katakana (void)
1904 return convert_kana (SCIM_ANTHY_CANDIDATE_HALF_KATAKANA);
1908 AnthyInstance::action_convert_to_latin (void)
1910 return convert_kana (SCIM_ANTHY_CANDIDATE_LATIN);
1914 AnthyInstance::action_convert_to_wide_latin (void)
1916 return convert_kana (SCIM_ANTHY_CANDIDATE_WIDE_LATIN);
1920 AnthyInstance::action_convert_char_type_forward (void)
1922 if (!m_preedit.is_preediting ())
1925 unset_lookup_table ();
1927 if (m_preedit.is_converting ()) {
1928 int idx = m_preedit.get_selected_segment ();
1931 m_preedit.finish ();
1932 m_preedit.convert (SCIM_ANTHY_CANDIDATE_HIRAGANA, true);
1934 int cand = m_preedit.get_selected_candidate ();
1937 case SCIM_ANTHY_CANDIDATE_HIRAGANA:
1938 m_preedit.select_candidate (SCIM_ANTHY_CANDIDATE_KATAKANA);
1940 case SCIM_ANTHY_CANDIDATE_KATAKANA:
1941 m_preedit.select_candidate (SCIM_ANTHY_CANDIDATE_HALF_KATAKANA);
1943 case SCIM_ANTHY_CANDIDATE_HALF_KATAKANA:
1944 m_preedit.select_candidate (SCIM_ANTHY_CANDIDATE_WIDE_LATIN);
1946 case SCIM_ANTHY_CANDIDATE_WIDE_LATIN:
1947 m_preedit.select_candidate (SCIM_ANTHY_CANDIDATE_LATIN);
1949 case SCIM_ANTHY_CANDIDATE_LATIN:
1950 m_preedit.select_candidate (SCIM_ANTHY_CANDIDATE_HIRAGANA);
1953 m_preedit.select_candidate (SCIM_ANTHY_CANDIDATE_HIRAGANA);
1958 m_preedit.finish ();
1959 m_preedit.convert (SCIM_ANTHY_CANDIDATE_HIRAGANA, true);
1968 AnthyInstance::action_convert_char_type_backward (void)
1970 if (!m_preedit.is_preediting ())
1973 unset_lookup_table ();
1975 if (m_preedit.is_converting ()) {
1976 int idx = m_preedit.get_selected_segment ();
1979 m_preedit.finish ();
1980 m_preedit.convert (SCIM_ANTHY_CANDIDATE_HIRAGANA, true);
1982 int cand = m_preedit.get_selected_candidate ();
1985 case SCIM_ANTHY_CANDIDATE_HIRAGANA:
1986 m_preedit.select_candidate (SCIM_ANTHY_CANDIDATE_LATIN);
1988 case SCIM_ANTHY_CANDIDATE_KATAKANA:
1989 m_preedit.select_candidate (SCIM_ANTHY_CANDIDATE_HIRAGANA);
1991 case SCIM_ANTHY_CANDIDATE_HALF_KATAKANA:
1992 m_preedit.select_candidate (SCIM_ANTHY_CANDIDATE_KATAKANA);
1994 case SCIM_ANTHY_CANDIDATE_WIDE_LATIN:
1995 m_preedit.select_candidate (SCIM_ANTHY_CANDIDATE_HALF_KATAKANA);
1997 case SCIM_ANTHY_CANDIDATE_LATIN:
1998 m_preedit.select_candidate (SCIM_ANTHY_CANDIDATE_WIDE_LATIN);
2001 m_preedit.select_candidate (SCIM_ANTHY_CANDIDATE_HIRAGANA);
2006 m_preedit.finish ();
2007 m_preedit.convert (SCIM_ANTHY_CANDIDATE_HIRAGANA, true);
2016 AnthyInstance::action_reconvert (void)
2018 if (m_preedit.is_preediting ())
2022 send.put_command (SCIM_ANTHY_TRANS_CMD_GET_SELECTION);
2023 send_helper_event (String (SCIM_ANTHY_HELPER_UUID), send);
2029 AnthyInstance::action_add_word (void)
2031 util_launch_program (m_factory->m_add_word_command.c_str ());
2037 AnthyInstance::action_launch_dict_admin_tool (void)
2039 util_launch_program (m_factory->m_dict_admin_command.c_str ());
2046 AnthyInstance::action_regist_word (void)
2052 AnthyInstance::get_factory (void)
2058 AnthyInstance::get_typing_method (void)
2060 return m_preedit.get_typing_method ();
2064 AnthyInstance::get_input_mode (void)
2066 return m_preedit.get_input_mode ();
2070 AnthyInstance::timeout_add (uint32 time_msec, timeout_func timeout_fn,
2071 void *data, delete_func delete_fn)
2073 uint32 id = ++m_timeout_id_seq;
2074 m_closures[id] = TimeoutClosure (time_msec, timeout_fn, data, delete_fn);
2076 * FIXME! Obsoleted closures should be removed at somewhere.
2077 * Currenly only NICOLA related timer uses this feature and it will be
2078 * removed each time on key press event so memory leaks doesn't exist.
2082 send.put_command (SCIM_ANTHY_TRANS_CMD_TIMEOUT_ADD);
2084 send.put_data (time_msec);
2085 send_helper_event (String (SCIM_ANTHY_HELPER_UUID), send);
2091 AnthyInstance::timeout_remove (uint32 id)
2093 if (m_closures.find (id) == m_closures.end ())
2096 m_closures.erase (id);
2099 send.put_command (SCIM_ANTHY_TRANS_CMD_TIMEOUT_REMOVE);
2101 send_helper_event (String (SCIM_ANTHY_HELPER_UUID), send);
2105 AnthyInstance::trigger_property (const String &property)
2107 String anthy_prop = property.substr (property.find_last_of ('/') + 1);
2109 SCIM_DEBUG_IMENGINE(2)
2110 << "trigger_property : " << property << " - " << anthy_prop << "\n";
2113 if (property == SCIM_PROP_INPUT_MODE_HIRAGANA) {
2114 set_input_mode (SCIM_ANTHY_MODE_HIRAGANA);
2115 } else if (property == SCIM_PROP_INPUT_MODE_KATAKANA) {
2116 set_input_mode (SCIM_ANTHY_MODE_KATAKANA);
2117 } else if (property == SCIM_PROP_INPUT_MODE_HALF_KATAKANA) {
2118 set_input_mode (SCIM_ANTHY_MODE_HALF_KATAKANA);
2119 } else if (property == SCIM_PROP_INPUT_MODE_LATIN) {
2120 set_input_mode (SCIM_ANTHY_MODE_LATIN);
2121 } else if (property == SCIM_PROP_INPUT_MODE_WIDE_LATIN) {
2122 set_input_mode (SCIM_ANTHY_MODE_WIDE_LATIN);
2125 } else if (property == SCIM_PROP_CONV_MODE_MULTI_SEG) {
2126 set_conversion_mode (SCIM_ANTHY_CONVERSION_MULTI_SEGMENT);
2127 } else if (property == SCIM_PROP_CONV_MODE_SINGLE_SEG) {
2128 set_conversion_mode (SCIM_ANTHY_CONVERSION_SINGLE_SEGMENT);
2129 } else if (property == SCIM_PROP_CONV_MODE_MULTI_REAL_TIME) {
2130 set_conversion_mode (SCIM_ANTHY_CONVERSION_MULTI_SEGMENT_IMMEDIATE);
2131 } else if (property == SCIM_PROP_CONV_MODE_SINGLE_REAL_TIME) {
2132 set_conversion_mode (SCIM_ANTHY_CONVERSION_SINGLE_SEGMENT_IMMEDIATE);
2135 } else if (property == SCIM_PROP_TYPING_METHOD_ROMAJI) {
2136 set_typing_method (SCIM_ANTHY_TYPING_METHOD_ROMAJI);
2137 } else if (property == SCIM_PROP_TYPING_METHOD_KANA) {
2138 set_typing_method (SCIM_ANTHY_TYPING_METHOD_KANA);
2139 } else if (property == SCIM_PROP_TYPING_METHOD_NICOLA) {
2140 set_typing_method (SCIM_ANTHY_TYPING_METHOD_NICOLA);
2143 } else if (property == SCIM_PROP_PERIOD_STYLE_JAPANESE) {
2144 set_period_style (SCIM_ANTHY_PERIOD_JAPANESE,
2145 SCIM_ANTHY_COMMA_JAPANESE);
2146 } else if (property == SCIM_PROP_PERIOD_STYLE_WIDE_LATIN_JAPANESE) {
2147 set_period_style (SCIM_ANTHY_PERIOD_JAPANESE,
2148 SCIM_ANTHY_COMMA_WIDE);
2149 } else if (property == SCIM_PROP_PERIOD_STYLE_WIDE_LATIN) {
2150 set_period_style (SCIM_ANTHY_PERIOD_WIDE,
2151 SCIM_ANTHY_COMMA_WIDE);
2152 } else if (property == SCIM_PROP_PERIOD_STYLE_LATIN) {
2153 set_period_style (SCIM_ANTHY_PERIOD_HALF,
2154 SCIM_ANTHY_COMMA_HALF);
2157 } else if (property == SCIM_PROP_SYMBOL_STYLE_JAPANESE) {
2158 set_symbol_style (SCIM_ANTHY_BRACKET_JAPANESE,
2159 SCIM_ANTHY_SLASH_JAPANESE);
2160 } else if (property == SCIM_PROP_SYMBOL_STYLE_CORNER_BRACKET_SLASH) {
2161 set_symbol_style (SCIM_ANTHY_BRACKET_JAPANESE,
2162 SCIM_ANTHY_SLASH_WIDE);
2163 } else if (property == SCIM_PROP_SYMBOL_STYLE_BRACKET_MIDDLE_DOT) {
2164 set_symbol_style (SCIM_ANTHY_BRACKET_WIDE,
2165 SCIM_ANTHY_SLASH_JAPANESE);
2166 } else if (property == SCIM_PROP_SYMBOL_STYLE_BRACKET_SLASH) {
2167 set_symbol_style (SCIM_ANTHY_BRACKET_WIDE,
2168 SCIM_ANTHY_SLASH_WIDE);
2171 } else if (property == SCIM_PROP_DICT_ADD_WORD) {
2173 } else if (property == SCIM_PROP_DICT_LAUNCH_ADMIN_TOOL) {
2174 action_launch_dict_admin_tool ();
2179 AnthyInstance::process_helper_event (const String &helper_uuid,
2180 const Transaction &recv)
2182 TransactionReader reader (recv);
2185 if (helper_uuid != SCIM_ANTHY_HELPER_UUID)
2188 if (!reader.get_command (cmd))
2192 case SCIM_ANTHY_TRANS_CMD_GET_SELECTION:
2194 // For reconversion feature, but this code is ad-hoc solution.
2196 WideString selection, surround;
2197 if (!reader.get_data (selection) || selection.empty ())
2201 unsigned int len = selection.length ();
2202 if (!get_surrounding_text (surround, cursor, len, len))
2204 // We expect application to delete selection text.
2205 m_preedit.convert(selection);
2211 // This code will conflict if same string exists at both before and
2213 if (surround.length () - cursor >= len &&
2214 surround.substr (cursor, len) == selection)
2216 delete_surrounding_text (0, len);
2217 m_preedit.convert (selection);
2219 set_lookup_table ();
2220 } else if (cursor >= (int) len &&
2221 surround.substr (cursor - len, len) == selection)
2223 delete_surrounding_text (0 - len, len);
2224 m_preedit.convert (selection);
2226 set_lookup_table ();
2231 case SCIM_ANTHY_TRANS_CMD_TIMEOUT_NOTIFY:
2234 if (reader.get_data (id) &&
2235 m_closures.find (id) != m_closures.end ())
2237 m_closures[id].close ();
2238 m_closures.erase (id);
2248 AnthyInstance::reload_config (const ConfigPointer &config)
2250 // set romaji settings
2251 m_preedit.set_symbol_width (m_factory->m_romaji_half_symbol);
2252 m_preedit.set_number_width (m_factory->m_romaji_half_number);
2255 if (m_on_init || !m_factory->m_show_input_mode_label) {
2256 if (m_factory->m_input_mode == "Hiragana")
2257 m_preedit.set_input_mode (SCIM_ANTHY_MODE_HIRAGANA);
2258 else if (m_factory->m_input_mode == "Katakana")
2259 m_preedit.set_input_mode (SCIM_ANTHY_MODE_KATAKANA);
2260 else if (m_factory->m_input_mode == "HalfKatakana")
2261 m_preedit.set_input_mode (SCIM_ANTHY_MODE_HALF_KATAKANA);
2262 else if (m_factory->m_input_mode == "Latin")
2263 m_preedit.set_input_mode (SCIM_ANTHY_MODE_LATIN);
2264 else if (m_factory->m_input_mode == "WideLatin")
2265 m_preedit.set_input_mode (SCIM_ANTHY_MODE_WIDE_LATIN);
2268 // set typing method and pseudo ASCII mode
2269 if (m_on_init || !m_factory->m_show_typing_method_label) {
2270 if (m_factory->m_typing_method == "NICOLA") {
2271 m_preedit.set_typing_method (SCIM_ANTHY_TYPING_METHOD_NICOLA);
2272 } else if (m_factory->m_typing_method == "Kana") {
2273 m_preedit.set_typing_method (SCIM_ANTHY_TYPING_METHOD_KANA);
2275 m_preedit.set_typing_method (SCIM_ANTHY_TYPING_METHOD_ROMAJI);
2277 m_preedit.set_pseudo_ascii_mode (get_pseudo_ascii_mode ());
2279 m_preedit.set_typing_method (get_typing_method ());
2280 m_preedit.set_pseudo_ascii_mode (get_pseudo_ascii_mode ());
2283 // set conversion mode
2284 if (m_on_init || !m_factory->m_show_conv_mode_label) {
2285 if (m_factory->m_conversion_mode == "MultiSeg")
2286 m_conv_mode = SCIM_ANTHY_CONVERSION_MULTI_SEGMENT;
2287 else if (m_factory->m_conversion_mode == "SingleSeg")
2288 m_conv_mode = SCIM_ANTHY_CONVERSION_SINGLE_SEGMENT;
2289 else if (m_factory->m_conversion_mode == "CAYT_MultiSeg")
2290 m_conv_mode = SCIM_ANTHY_CONVERSION_MULTI_SEGMENT_IMMEDIATE;
2291 else if (m_factory->m_conversion_mode == "CAYT_SingleSeg")
2292 m_conv_mode = SCIM_ANTHY_CONVERSION_SINGLE_SEGMENT_IMMEDIATE;
2296 if (m_on_init || !m_factory->m_show_period_style_label) {
2297 if (m_factory->m_period_style == "WideLatin") {
2298 m_preedit.set_comma_style (SCIM_ANTHY_COMMA_WIDE);
2299 m_preedit.set_period_style (SCIM_ANTHY_PERIOD_WIDE);
2300 } else if (m_factory->m_period_style == "Latin") {
2301 m_preedit.set_comma_style (SCIM_ANTHY_COMMA_HALF);
2302 m_preedit.set_period_style (SCIM_ANTHY_PERIOD_HALF);
2303 } else if (m_factory->m_period_style == "Japanese") {
2304 m_preedit.set_comma_style (SCIM_ANTHY_COMMA_JAPANESE);
2305 m_preedit.set_period_style (SCIM_ANTHY_PERIOD_JAPANESE);
2306 } else if (m_factory->m_period_style == "WideLatin_Japanese") {
2307 m_preedit.set_comma_style (SCIM_ANTHY_COMMA_WIDE);
2308 m_preedit.set_period_style (SCIM_ANTHY_PERIOD_JAPANESE);
2310 m_preedit.set_comma_style (SCIM_ANTHY_COMMA_JAPANESE);
2311 m_preedit.set_period_style (SCIM_ANTHY_PERIOD_JAPANESE);
2316 if (m_on_init || !m_factory->m_show_symbol_style_label) {
2317 if (m_factory->m_symbol_style == "Japanese") {
2318 m_preedit.set_bracket_style (SCIM_ANTHY_BRACKET_JAPANESE);
2319 m_preedit.set_slash_style (SCIM_ANTHY_SLASH_JAPANESE);
2320 } else if (m_factory->m_symbol_style == "WideBracket_WideSlash") {
2321 m_preedit.set_bracket_style (SCIM_ANTHY_BRACKET_WIDE);
2322 m_preedit.set_slash_style (SCIM_ANTHY_SLASH_WIDE);
2323 } else if (m_factory->m_symbol_style == "CornerBracket_WideSlash") {
2324 m_preedit.set_bracket_style (SCIM_ANTHY_BRACKET_JAPANESE);
2325 m_preedit.set_slash_style (SCIM_ANTHY_SLASH_WIDE);
2326 } else if (m_factory->m_symbol_style == "WideBracket_MiddleDot") {
2327 m_preedit.set_bracket_style (SCIM_ANTHY_BRACKET_WIDE);
2328 m_preedit.set_slash_style (SCIM_ANTHY_SLASH_JAPANESE);
2330 m_preedit.set_bracket_style (SCIM_ANTHY_BRACKET_JAPANESE);
2331 m_preedit.set_slash_style (SCIM_ANTHY_SLASH_JAPANESE);
2336 if (m_factory->m_cand_win_page_size > 0)
2337 m_lookup_table.set_page_size (m_factory->m_cand_win_page_size);
2339 m_lookup_table.set_page_size (SCIM_ANTHY_CONFIG_CAND_WIN_PAGE_SIZE_DEFAULT);
2342 m_properties.clear ();
2343 install_properties ();
2346 m_preedit.set_dict_encoding (m_factory->m_dict_encoding);
2350 AnthyInstance::is_single_segment (void)
2352 if (m_conv_mode == SCIM_ANTHY_CONVERSION_SINGLE_SEGMENT ||
2353 m_conv_mode == SCIM_ANTHY_CONVERSION_SINGLE_SEGMENT_IMMEDIATE)
2360 AnthyInstance::is_realtime_conversion (void)
2362 if (m_conv_mode == SCIM_ANTHY_CONVERSION_MULTI_SEGMENT_IMMEDIATE ||
2363 m_conv_mode == SCIM_ANTHY_CONVERSION_SINGLE_SEGMENT_IMMEDIATE)
2370 AnthyInstance::get_pseudo_ascii_mode (void)
2373 TypingMethod m = get_typing_method ();
2375 if (m == SCIM_ANTHY_TYPING_METHOD_ROMAJI) {
2376 if (m_factory->m_romaji_pseudo_ascii_mode)
2377 retval |= SCIM_ANTHY_PSEUDO_ASCII_TRIGGERED_CAPITALIZED;
2384 vi:ts=4:nowrap:ai:expandtab