~ubuntu-branches/ubuntu/maverick/uim/maverick

« back to all changes in this revision

Viewing changes to xim/ximserver.h

  • Committer: Bazaar Package Importer
  • Author(s): Masahito Omote
  • Date: 2006-11-23 15:10:53 UTC
  • mfrom: (3.1.8 edgy)
  • Revision ID: james.westby@ubuntu.com-20061123151053-q42sk1lvks41xpfx
Tags: 1:1.2.1-9
uim-gtk2.0.postinst: Don't call update-gtk-immodules on purge.
(closes: Bug#398530)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 
3
 
  Copyright (c) 2003,2004 uim Project http://uim.freedesktop.org/
 
3
  Copyright (c) 2003-2006 uim Project http://uim.freedesktop.org/
4
4
 
5
5
  All rights reserved.
6
6
 
17
17
     may be used to endorse or promote products derived from this software
18
18
     without specific prior written permission.
19
19
 
20
 
  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 
20
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
21
21
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
22
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
 
  ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 
23
  ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
24
24
  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
25
  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26
26
  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36
36
 
37
37
#include <X11/X.h>
38
38
#include <X11/Xlib.h>
39
 
#include <X11/keysymdef.h>
40
 
#include <stdio.h>
 
39
 
41
40
#include <list>
42
41
#include <vector>
43
42
#include <map>
 
43
 
44
44
#include "uim/uim.h"
45
 
#include "uim/uim-helper.h"
46
 
 
47
 
 
48
 
bool pretrans_register();
49
 
int connection_setup();
50
 
void main_loop();
 
45
#include "compose.h"
 
46
 
51
47
 
52
48
// preedit ornament
53
49
#define PE_NORMAL 0
61
57
    uString s;
62
58
    int stat;
63
59
};
 
60
typedef enum {
 
61
    Caret,
 
62
    Left,
 
63
    Right
 
64
} CandWinPosType;
64
65
 
65
66
// state of preedit.
66
67
// created in the constructor of InputContext, and deleted in the
84
85
// user interfaces
85
86
void init_convdisp();
86
87
void init_modifier_keys();
87
 
 
88
 
// misc
89
 
int pad4(int);
90
 
 
91
 
// debug functions
92
 
void hex_dump(unsigned char *buf, int len);
 
88
#if HAVE_XFT_UTF8_STRING
 
89
void init_default_xftfont();
 
90
void update_default_xftfont();
 
91
#endif
 
92
void reload_uim(int x);
 
93
void check_candwin_pos_type();
93
94
 
94
95
 
95
96
// for command line option
97
98
#define OPT_TRACE 1
98
99
// trace XIM connection
99
100
#define OPT_TRACE_XIM 2
 
101
// use on-demand-synchronous XIM event flow (not safe for Tcl/Tk 8.{3,4})
 
102
#define OPT_ON_DEMAND_SYNC 4
100
103
 
101
104
 
102
105
// byte order
114
117
#define COMMIT_RAW 1
115
118
#define UPDATE_MODE 2
116
119
 
117
 
// do convert from original event, and released within the same function
 
120
// do convert from original event into uim event
118
121
class keyState {
119
122
public:
120
 
    keyState();
 
123
    keyState(class XimIC *);
121
124
    ~keyState();
122
125
    void check_key(class keyEventX *);
 
126
    bool check_compose();
123
127
    int key();
124
128
    int modifier();
 
129
    KeySym xkeysym();
 
130
    int xkeystate();
 
131
    void reset();
125
132
 
126
133
    bool is_push(); // for distinguish from release
127
134
    void print();
128
135
private:
129
 
    int revise_mod(int uim_mod);
130
136
    int mKey;
131
137
    int mModifier;
 
138
    KeySym mXKeySym;
 
139
    int mXKeyState;
132
140
    bool m_bPush;
133
 
    bool mAltOn;
134
 
    bool mMetaOn;
135
 
    bool mHyperOn;
136
 
    bool mSuperOn;
 
141
    int mModState;
 
142
    int mPreModState;
 
143
    Compose *mCompose;
 
144
    XimIC *mIc;
137
145
};
138
146
 
139
147
class XimIC;
151
159
    void focusOut();
152
160
    XimIC *get_ic();
153
161
    XimServer *getServer();
154
 
    bool extra_input(char *s);
 
162
    void extra_input(char *s);
155
163
    void clear_preedit();
156
164
    uString get_preedit_string();
157
165
    void pushback_preedit_string(int attr, const char *str);
164
172
    void update_prop_list(const char *str);
165
173
    void update_prop_label(const char *str);
166
174
    bool hasActiveCandwin();
 
175
    bool isCaretStateShown();
167
176
    const char *get_engine_name();
168
177
    const char *get_locale_name();
169
178
    void changeContext(const char *engine);
 
179
    void customContext(const char *custom, const char *val);
 
180
    void createUimContext(const char *engine);
 
181
    void configuration_changed();
 
182
    void switch_app_global_im(const char *name);
 
183
    void switch_system_global_im(const char *name);
170
184
public:
171
 
    static void commit_cb(void *, const char *);
172
 
    static void clear_cb(void *);
173
 
    static void pushback_cb(void *, int attr, const char *str);
174
 
    static void update_cb(void *);
 
185
    static void commit_cb(void *ptr, const char *str);
 
186
    static void clear_cb(void *ptr);
 
187
    static void pushback_cb(void *ptr, int attr, const char *str);
 
188
    static void update_cb(void *ptr);
175
189
    static void candidate_activate_cb(void *ptr, int nr, int index);
176
190
    static void candidate_select_cb(void *ptr, int index);
177
191
    static void candidate_shift_page_cb(void *ptr, int direction);
178
192
    static void candidate_deactivate_cb(void *ptr);
179
193
    static void update_prop_list_cb(void *ptr, const char *str);
180
194
    static void update_prop_label_cb(void *ptr, const char *str);
 
195
    static void configuration_changed_cb(void *ptr);
 
196
    static void switch_app_global_im_cb(void *ptr, const char *name);
 
197
    static void switch_system_global_im_cb(void *ptr, const char *name);
181
198
    static InputContext *focusedContext();
182
199
    static void deletefocusedContext();
183
 
protected:
 
200
private:
184
201
    void commit_string(char *);
 
202
    void clear_pe_stat();
 
203
    void review_im(const char *engine);
 
204
    char *get_caret_state_label_from_prop_list(const char *str);
 
205
 
185
206
    XimIC *mXic;
186
207
    XimServer *mServer;
187
208
    pe_stat *m_pe;
188
209
    Convdisp *mConvdisp;
189
210
    uim_context mUc;
190
 
private:
191
 
    uim_context createUimContext(const char *engine);
192
 
    static InputContext *mFocusedContext;
193
211
    bool mCandwinActive;
194
212
    int mDisplayLimit;
195
213
    int mNumPage;
198
216
    std::vector<const char *> active_candidates;
199
217
    char *mEngineName;
200
218
    char *mLocaleName;
 
219
    bool mCaretStateShown;
 
220
private:
 
221
    static InputContext *mFocusedContext;
201
222
};
202
223
 
203
224
class Locale {
204
225
public:
205
 
    virtual char *uStringToCtext(uString *us, const char *encoding) = 0;
 
226
    virtual ~Locale();
 
227
    virtual char *uStringToCtext(uString *us) = 0;
 
228
    virtual char *utf8_to_native_str(char *str) = 0;
206
229
    virtual bool supportOverTheSpot();
207
 
    virtual void set_localename_from_im_lang(const char *im_lang) = 0;
208
 
private:
209
 
    char *mLocaleName;
210
230
};
211
231
 
212
 
Locale *createLocale(const char *im_lang);
 
232
Locale *createLocale(const char *encoding);
213
233
const char *compose_localenames_from_im_lang(const char *im_lang);
214
234
bool is_locale_included(const char *locales, const char *locale);
215
235
// Sring returned by get_first_locale() is allocated with strdup().
216
 
char *get_first_locale(const char *locales);
 
236
char *get_prefered_locale(const char *locales);
217
237
const char *find_localename_from_encoding(const char *encoding);
218
 
char *utf8_to_native_str(char *utf8, const char *encoding);
219
238
int utf8_mbtowc(uchar *wc, const unsigned char *src, int src_len);
220
239
int utf8_wctomb(unsigned char *dest, uchar wc); // dest must have size 6
 
240
int mb_string_to_utf8(char *utf8, const char *str, int to_len, const char *enc);
221
241
 
222
242
class XimServer {
223
243
public:
224
 
    XimServer(Locale *lc, const char *name, const char *lang);
 
244
    XimServer(const char *name, const char *lang);
225
245
    ~XimServer() {};
226
246
    InputContext *createContext(XimIC *, const char *engine);
227
247
    void deleteContext(InputContext *);
230
250
    void setupNewConnection(XClientMessageEvent *ev);
231
251
    char *uStringToCtext(uString *js, const char *encoding);
232
252
    void strToUstring(uString *d, const char *s);
233
 
    struct input_style *getInputStyles();
234
253
    const char *getIMName();
235
254
    const char *getIMLang();
236
255
    void set_im(const char *name);
237
256
    void changeContext(const char *engine);
238
 
    Locale *getLocale();
 
257
    void customContext(const char *custom, const char *val);
 
258
    void reloadConfigs();
 
259
    std::list<InputContext *> ic_list;
239
260
public:
240
261
    static XimServer *findServer(Window w);
241
262
    static Display *gDpy;
242
263
    static std::map<Window, XimServer *> gServerMap;
 
264
    static CandWinPosType gCandWinPosType;
243
265
private:
244
 
    Locale *mLocale;
245
266
    Window mSelectionWin;
246
267
    Atom mServerAtom;
247
268
    char *mIMName;
248
269
    const char *mIMLang;
249
 
    std::list<InputContext *> ic_list;
250
270
};
251
271
 
252
272
struct UIMInfo {
253
 
    const char *lang;
254
 
    const char *name;
255
 
    Locale *locale;
256
 
    const char *desc;
 
273
    char *lang;
 
274
    char *name;
 
275
    char *desc;
257
276
};
 
277
extern std::list<UIMInfo> uim_info;
258
278
 
259
279
const char *get_im_lang_from_engine(const char *engine);
260
280