1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * Copyright (C) 2005 Takuro Ashie
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "scim_anthy_kana.h"
23 #include "scim_anthy_factory.h"
24 #include "scim_anthy_imengine.h"
25 #include "scim_anthy_default_tables.h"
26 #include "scim_anthy_utils.h"
28 using namespace scim_anthy;
31 has_voiced_consonant (String str)
33 VoicedConsonantRule *table = scim_anthy_voiced_consonant_table;
35 for (unsigned int i = 0; table[i].string; i++) {
36 if (!strcmp (str.c_str (), table[i].string) &&
37 table[i].voiced && *table[i].voiced)
47 has_half_voiced_consonant (String str)
49 VoicedConsonantRule *table = scim_anthy_voiced_consonant_table;
51 for (unsigned int i = 0; table[i].string; i++) {
52 if (!strcmp (str.c_str (), table[i].string) &&
53 table[i].half_voiced && *table[i].half_voiced)
63 to_voiced_consonant (String str)
65 VoicedConsonantRule *table = scim_anthy_voiced_consonant_table;
67 for (unsigned int i = 0; table[i].string; i++) {
68 if (!strcmp (str.c_str (), table[i].string))
69 return String (table[i].voiced);
76 to_half_voiced_consonant (String str)
78 VoicedConsonantRule *table = scim_anthy_voiced_consonant_table;
80 for (unsigned int i = 0; table[i].string; i++) {
81 if (!strcmp (str.c_str (), table[i].string))
82 return String (table[i].half_voiced);
88 KanaConvertor::KanaConvertor (AnthyInstance &anthy)
93 KanaConvertor::~KanaConvertor ()
98 KanaConvertor::can_append (const KeyEvent & key,
101 // ignore key release.
102 if (key.is_key_release ())
105 // ignore short cut keys of apllication.
106 if (key.mask & SCIM_KEY_ControlMask ||
107 key.mask & SCIM_KEY_AltMask)
112 if (key.code == SCIM_KEY_overline ||
113 (key.code >= SCIM_KEY_kana_fullstop &&
114 key.code <= SCIM_KEY_semivoicedsound))
120 if (key.code == SCIM_KEY_KP_Equal ||
121 (key.code >= SCIM_KEY_KP_Multiply &&
122 key.code <= SCIM_KEY_KP_9))
132 KanaConvertor::append (const KeyEvent & key,
134 WideString & pending,
137 KeyCodeToCharRule *table = scim_anthy_keypad_table;
139 // handle keypad code
140 if (key.code == SCIM_KEY_KP_Equal ||
141 (key.code >= SCIM_KEY_KP_Multiply &&
142 key.code <= SCIM_KEY_KP_9))
144 String ten_key_type = m_anthy.get_factory()->m_ten_key_type;
146 for (unsigned int i = 0; table[i].code; i++) {
147 if (table[i].code == key.code) {
148 if (ten_key_type == "Wide")
149 util_convert_to_wide (result, table[i].kana);
151 result = utf8_mbstowcs (table[i].kana);
159 table = scim_anthy_kana_table;
161 // handle voiced sound
162 if (key.code == SCIM_KEY_voicedsound &&
163 !m_pending.empty () && has_voiced_consonant (m_pending))
165 result = utf8_mbstowcs (to_voiced_consonant (m_pending));
166 raw = key.get_ascii_code ();
167 m_pending = String ();
171 // handle semi voiced sound
172 if (key.code == SCIM_KEY_semivoicedsound &&
173 !m_pending.empty () && has_half_voiced_consonant (m_pending))
175 result = utf8_mbstowcs (to_half_voiced_consonant (m_pending));
176 raw = key.get_ascii_code ();
177 m_pending = String ();
182 for (unsigned int i = 0; table[i].code; i++) {
183 if (table[i].code == key.code) {
184 bool retval = m_pending.empty () ? false : true;
186 if (has_voiced_consonant (table[i].kana)) {
187 result = WideString ();
188 pending = utf8_mbstowcs (table[i].kana);
189 m_pending = table[i].kana;
191 result = utf8_mbstowcs (table[i].kana);
192 m_pending = String ();
194 raw = key.get_ascii_code ();
201 s += key.get_ascii_code ();
204 return append (raw, result, pending);
208 KanaConvertor::append (const String & str,
210 WideString & pending)
212 result = utf8_mbstowcs (str);
213 m_pending = String ();
219 KanaConvertor::clear (void)
221 m_pending = String ();
225 KanaConvertor::is_pending (void)
227 return !m_pending.empty ();
231 KanaConvertor::get_pending (void)
233 return WideString (utf8_mbstowcs (m_pending));
237 KanaConvertor::flush_pending (void)
239 return WideString ();
243 KanaConvertor::reset_pending (const WideString &result, const String &raw)
245 m_pending = String ();
246 if (has_voiced_consonant (utf8_wcstombs (result)))
247 m_pending = utf8_wcstombs (result);
250 vi:ts=4:nowrap:ai:expandtab