1 /* vim:set et ts=4 sts=4:
3 * ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus
5 * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "PYFallbackEditor.h"
22 #include "PYHalfFullConverter.h"
23 #include "PYPinyinProperties.h"
28 FallbackEditor::processPunctForSimplifiedChinese (guint keyval, guint keycode, guint modifiers)
32 commit ("·"); return TRUE;
34 commit ("~"); return TRUE;
36 commit ("!"); return TRUE;
40 commit ("¥"); return TRUE;
43 commit ("……"); return TRUE;
47 commit ("("); return TRUE;
49 commit (")"); return TRUE;
52 commit ("——"); return TRUE;
56 commit ("【"); return TRUE;
58 commit ("】"); return TRUE;
60 commit ("『"); return TRUE;
62 commit ("』"); return TRUE;
64 commit ("、"); return TRUE;
67 commit (";"); return TRUE;
69 commit (":"); return TRUE;
71 commit (m_quote ? "‘" : "’");
75 commit (m_double_quote ? "“" : "”");
76 m_double_quote = !m_double_quote;
79 commit (","); return TRUE;
81 if (m_prev_committed_char >= '0' && m_prev_committed_char <= '9')
87 commit ("《"); return TRUE;
89 commit ("》"); return TRUE;
92 commit ("?"); return TRUE;
98 FallbackEditor::processPunctForTraditionalChinese (guint keyval, guint keycode, guint modifiers)
102 commit ("~"); return TRUE;
104 commit ("!"); return TRUE;
108 commit ("¥"); return TRUE;
111 commit ("……"); return TRUE;
115 commit ("("); return TRUE;
117 commit (")"); return TRUE;
120 commit ("——"); return TRUE;
124 commit ("「"); return TRUE;
126 commit ("」"); return TRUE;
128 commit ("『"); return TRUE;
130 commit ("』"); return TRUE;
132 commit ("、"); return TRUE;
135 commit (";"); return TRUE;
137 commit (":"); return TRUE;
139 commit (m_quote ? "‘" : "’");
143 commit (m_double_quote ? "“" : "”");
144 m_double_quote = !m_double_quote;
147 commit (","); return TRUE;
149 if (m_prev_committed_char >= '0' && m_prev_committed_char <= '9')
155 commit (","); return TRUE;
157 commit ("。"); return TRUE;
159 commit ("?"); return TRUE;
165 FallbackEditor::processPunct (guint keyval, guint keycode, guint modifiers)
167 guint cmshm_modifiers = cmshm_filter (modifiers);
169 if (G_UNLIKELY (keyval == IBUS_period && cmshm_modifiers == IBUS_CONTROL_MASK)) {
170 m_props.toggleModeFullPunct ();
174 /* check ctrl, alt, hyper, supper masks */
175 if (cmshm_modifiers != 0)
179 if (G_UNLIKELY (!m_props.modeChinese ())) {
180 if (G_UNLIKELY (m_props.modeFull ()))
181 commit (HalfFullConverter::toFull (keyval));
188 if (m_props.modeFullPunct ()) {
189 if (m_props.modeSimp ()) {
190 if (processPunctForSimplifiedChinese (keyval, keycode, modifiers))
194 if (processPunctForTraditionalChinese (keyval, keycode, modifiers))
198 commit (m_props.modeFull () ? HalfFullConverter::toFull (keyval) : keyval);
204 FallbackEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers)
206 gboolean retval = FALSE;
208 modifiers &= (IBUS_SHIFT_MASK |
217 case IBUS_KP_0 ... IBUS_KP_9:
218 keyval = keyval - IBUS_KP_0 + IBUS_0;
219 case IBUS_0 ... IBUS_9:
221 case IBUS_a ... IBUS_z:
222 case IBUS_A ... IBUS_Z:
223 if (modifiers == 0) {
224 commit (m_props.modeFull () ? HalfFullConverter::toFull (keyval) : keyval);
229 case IBUS_exclam ... IBUS_slash:
230 case IBUS_colon ... IBUS_at:
231 case IBUS_bracketleft ... IBUS_quoteleft:
232 case IBUS_braceleft ... IBUS_asciitilde:
233 retval = processPunct (keyval, keycode, modifiers);
236 retval = processPunct ('=', keycode, modifiers);
238 case IBUS_KP_Multiply:
239 retval = processPunct ('*', keycode, modifiers);
242 retval = processPunct ('+', keycode, modifiers);
245 case IBUS_KP_Separator:
246 retval = processPunct (IBUS_separator, keycode, modifiers);
249 case IBUS_KP_Subtract:
250 retval = processPunct ('-', keycode, modifiers);
252 case IBUS_KP_Decimal:
253 retval = processPunct ('.', keycode, modifiers);
256 retval = processPunct ('/', keycode, modifiers);
262 if (modifiers == 0) {
263 commit (m_props.modeFull () ? " " : " ");
275 FallbackEditor::reset (void) {
277 m_double_quote = TRUE;
278 m_prev_committed_char = 0;