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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
/* vim:set et ts=4 sts=4:
*
* ibus-pinyin - The Chinese PinYin engine for IBus
*
* Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <cstring>
#include "PYEngine.h"
#include "PYPPinyinEngine.h"
#include "PYPBopomofoEngine.h"
namespace PY {
/* code of engine class of GObject */
#define IBUS_PINYIN_ENGINE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), IBUS_TYPE_PINYIN_ENGINE, IBusPinyinEngine))
#define IBUS_PINYIN_ENGINE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), IBUS_TYPE_PINYIN_ENGINE, IBusPinyinEngineClass))
#define IBUS_IS_PINYIN_ENGINE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), IBUS_TYPE_PINYIN_ENGINE))
#define IBUS_IS_PINYIN_ENGINE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), IBUS_TYPE_PINYIN_ENGINE))
#define IBUS_PINYIN_ENGINE_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), IBUS_TYPE_PINYIN_ENGINE, IBusPinyinEngineClass))
typedef struct _IBusPinyinEngine IBusPinyinEngine;
typedef struct _IBusPinyinEngineClass IBusPinyinEngineClass;
struct _IBusPinyinEngine {
IBusEngine parent;
/* members */
Engine *engine;
};
struct _IBusPinyinEngineClass {
IBusEngineClass parent;
};
/* functions prototype */
static void ibus_pinyin_engine_class_init (IBusPinyinEngineClass *klass);
static void ibus_pinyin_engine_init (IBusPinyinEngine *pinyin);
static GObject* ibus_pinyin_engine_constructor (GType type,
guint n_construct_params,
GObjectConstructParam *construct_params);
static void ibus_pinyin_engine_destroy (IBusPinyinEngine *pinyin);
static gboolean ibus_pinyin_engine_process_key_event
(IBusEngine *engine,
guint keyval,
guint keycode,
guint modifiers);
static void ibus_pinyin_engine_focus_in (IBusEngine *engine);
static void ibus_pinyin_engine_focus_out (IBusEngine *engine);
static void ibus_pinyin_engine_reset (IBusEngine *engine);
static void ibus_pinyin_engine_enable (IBusEngine *engine);
static void ibus_pinyin_engine_disable (IBusEngine *engine);
#if 0
static void ibus_engine_set_cursor_location (IBusEngine *engine,
gint x,
gint y,
gint w,
gint h);
static void ibus_pinyin_engine_set_capabilities
(IBusEngine *engine,
guint caps);
#endif
static void ibus_pinyin_engine_page_up (IBusEngine *engine);
static void ibus_pinyin_engine_page_down (IBusEngine *engine);
static void ibus_pinyin_engine_cursor_up (IBusEngine *engine);
static void ibus_pinyin_engine_cursor_down (IBusEngine *engine);
static void ibus_pinyin_engine_property_activate
(IBusEngine *engine,
const gchar *prop_name,
guint prop_state);
static void ibus_pinyin_engine_candidate_clicked
(IBusEngine *engine,
guint index,
guint button,
guint state);
#if 0
static void ibus_pinyin_engine_property_show (IBusEngine *engine,
const gchar *prop_name);
static void ibus_pinyin_engine_property_hide (IBusEngine *engine,
const gchar *prop_name);
#endif
G_DEFINE_TYPE (IBusPinyinEngine, ibus_pinyin_engine, IBUS_TYPE_ENGINE)
static void
ibus_pinyin_engine_class_init (IBusPinyinEngineClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass);
IBusEngineClass *engine_class = IBUS_ENGINE_CLASS (klass);
object_class->constructor = ibus_pinyin_engine_constructor;
ibus_object_class->destroy = (IBusObjectDestroyFunc) ibus_pinyin_engine_destroy;
engine_class->process_key_event = ibus_pinyin_engine_process_key_event;
engine_class->reset = ibus_pinyin_engine_reset;
engine_class->enable = ibus_pinyin_engine_enable;
engine_class->disable = ibus_pinyin_engine_disable;
engine_class->focus_in = ibus_pinyin_engine_focus_in;
engine_class->focus_out = ibus_pinyin_engine_focus_out;
engine_class->page_up = ibus_pinyin_engine_page_up;
engine_class->page_down = ibus_pinyin_engine_page_down;
engine_class->cursor_up = ibus_pinyin_engine_cursor_up;
engine_class->cursor_down = ibus_pinyin_engine_cursor_down;
engine_class->property_activate = ibus_pinyin_engine_property_activate;
engine_class->candidate_clicked = ibus_pinyin_engine_candidate_clicked;
}
static void
ibus_pinyin_engine_init (IBusPinyinEngine *pinyin)
{
if (g_object_is_floating (pinyin))
g_object_ref_sink (pinyin); // make engine sink
}
static GObject*
ibus_pinyin_engine_constructor (GType type,
guint n_construct_params,
GObjectConstructParam *construct_params)
{
IBusPinyinEngine *engine;
const gchar *name;
engine = (IBusPinyinEngine *) G_OBJECT_CLASS (ibus_pinyin_engine_parent_class)->constructor (
type,
n_construct_params,
construct_params);
name = ibus_engine_get_name ((IBusEngine *) engine);
if (name) {
#ifdef IBUS_BUILD_LIBPINYIN
if (std::strcmp (name, "libpinyin") == 0 ||
std::strcmp (name, "libpinyin-debug") == 0) {
engine->engine = new LibPinyinPinyinEngine (IBUS_ENGINE (engine));
}
if (std::strcmp (name, "libbopomofo") == 0 ||
std::strcmp (name, "libbopomofo-debug") == 0 ) {
engine->engine = new LibPinyinBopomofoEngine (IBUS_ENGINE (engine));
}
#endif
} else {
engine->engine = new LibPinyinPinyinEngine (IBUS_ENGINE (engine));
}
return (GObject *) engine;
}
static void
ibus_pinyin_engine_destroy (IBusPinyinEngine *pinyin)
{
delete pinyin->engine;
((IBusObjectClass *) ibus_pinyin_engine_parent_class)->destroy ((IBusObject *)pinyin);
}
static gboolean
ibus_pinyin_engine_process_key_event (IBusEngine *engine,
guint keyval,
guint keycode,
guint modifiers)
{
IBusPinyinEngine *pinyin = (IBusPinyinEngine *) engine;
return pinyin->engine->processKeyEvent (keyval, keycode, modifiers);
}
static void
ibus_pinyin_engine_property_activate (IBusEngine *engine,
const gchar *prop_name,
guint prop_state)
{
IBusPinyinEngine *pinyin = (IBusPinyinEngine *) engine;
pinyin->engine->propertyActivate (prop_name, prop_state);
}
static void
ibus_pinyin_engine_candidate_clicked (IBusEngine *engine,
guint index,
guint button,
guint state)
{
IBusPinyinEngine *pinyin = (IBusPinyinEngine *) engine;
pinyin->engine->candidateClicked (index, button, state);
}
#define FUNCTION(name, Name) \
static void \
ibus_pinyin_engine_##name (IBusEngine *engine) \
{ \
IBusPinyinEngine *pinyin = (IBusPinyinEngine *) engine; \
pinyin->engine->Name (); \
((IBusEngineClass *) ibus_pinyin_engine_parent_class) \
->name (engine); \
}
FUNCTION(focus_in, focusIn)
FUNCTION(focus_out, focusOut)
FUNCTION(reset, reset)
FUNCTION(enable, enable)
FUNCTION(disable, disable)
FUNCTION(page_up, pageUp)
FUNCTION(page_down, pageDown)
FUNCTION(cursor_up, cursorUp)
FUNCTION(cursor_down, cursorDown)
#undef FUNCTION
Engine::~Engine (void)
{
}
};
|