summaryrefslogtreecommitdiffstats
path: root/src/ZYFallbackEditor.cc
blob: 026e9cd7ab462d16c9d3aab827d16bfaabfbac30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* vim:set et ts=4 sts=4:
 *
 * ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus
 *
 * Copyright (c) 2014 Peng Wu <alexepico@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "ZYFallbackEditor.h"
#include <assert.h>
#include "ZYSymbols.h"
#include "ZYZhuyinProperties.h"

namespace ZY {

inline gboolean
FallbackEditor::processSymbol (guint keyval, guint keycode, guint modifiers)
{
    guint cmshm_modifiers = cmshm_filter (modifiers);

    /* check ctrl, alt, hyper, supper masks */
    if (cmshm_modifiers != 0)
        return FALSE;

    /* English mode */
    if (!m_props.modeChinese ()) {

        /* Punctuation character */
        if (is_full_width_symbol (keyval)) {
            if(G_UNLIKELY (m_props.modeFullWidth ())) {
                String symbol;
                convert_full_width_symbol (keyval, symbol);
                commit (symbol);
            } else {
                commit (keyval);
            }
            return TRUE;
        }

    } else {
        /* Chinese mode, handled by ZhuyinEditor or PinyinEditor. */
        return TRUE;
    }

    return FALSE;
}

gboolean
FallbackEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers)
{
    gboolean retval = FALSE;

    modifiers &= (IBUS_CONTROL_MASK |
                  IBUS_MOD1_MASK |
                  IBUS_SUPER_MASK |
                  IBUS_HYPER_MASK |
                  IBUS_META_MASK);

    switch (keyval) {
        /* numbers */
        case IBUS_KP_0 ... IBUS_KP_9:
            keyval = keyval - IBUS_KP_0 + IBUS_0;
        case IBUS_0 ... IBUS_9:
        /* letters */
        case IBUS_a ... IBUS_z:
        case IBUS_A ... IBUS_Z:
            if (modifiers == 0) {
                retval = processSymbol (keyval, keycode, modifiers);
            }
            break;
        /* punct */
        case IBUS_exclam ... IBUS_slash:
        case IBUS_colon ... IBUS_at:
        case IBUS_bracketleft ... IBUS_quoteleft:
        case IBUS_braceleft ... IBUS_asciitilde:
            retval = processSymbol (keyval, keycode, modifiers);
            break;
        case IBUS_KP_Equal:
            retval = processSymbol ('=', keycode, modifiers);
            break;
        case IBUS_KP_Multiply:
            retval = processSymbol ('*', keycode, modifiers);
            break;
        case IBUS_KP_Add:
            retval = processSymbol ('+', keycode, modifiers);
            break;
        #if 0
        case IBUS_KP_Separator:
            retval = processSymbol (IBUS_separator, keycode, modifiers);
            break;
        #endif
        case IBUS_KP_Subtract:
            retval = processSymbol ('-', keycode, modifiers);
            break;
        case IBUS_KP_Decimal:
            retval = processSymbol ('.', keycode, modifiers);
            break;
        case IBUS_KP_Divide:
            retval = processSymbol ('/', keycode, modifiers);
            break;
        /* space */
        case IBUS_KP_Space:
            keyval = IBUS_space;
        case IBUS_space:
            retval = processSymbol (keyval, keycode, modifiers);
            break;
        /* others */
        default:
            break;
    }

    return retval;
}

void
FallbackEditor::reset (void) {
    m_quote = TRUE;
    m_double_quote = TRUE;
    m_prev_committed_char = 0;
}

};