1 /******************************************************************
2 
3          Copyright 1994, 1995 by Sun Microsystems, Inc.
4          Copyright 1993, 1994 by Hewlett-Packard Company
5 
6 Permission to use, copy, modify, distribute, and sell this software
7 and its documentation for any purpose is hereby granted without fee,
8 provided that the above copyright notice appear in all copies and
9 that both that copyright notice and this permission notice appear
10 in supporting documentation, and that the name of Sun Microsystems, Inc.
11 and Hewlett-Packard not be used in advertising or publicity pertaining to
12 distribution of the software without specific, written prior permission.
13 Sun Microsystems, Inc. and Hewlett-Packard make no representations about
14 the suitability of this software for any purpose.  It is provided "as is"
15 without express or implied warranty.
16 
17 SUN MICROSYSTEMS INC. AND HEWLETT-PACKARD COMPANY DISCLAIMS ALL
18 WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
20 SUN MICROSYSTEMS, INC. AND HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY
21 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
22 RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
23 CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
24 IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 
26   Author: Hidetoshi Tajima(tajima@Eng.Sun.COM) Sun Microsystems, Inc.
27 
28     This version tidied and debugged by Steve Underwood May 1999
29 
30 ******************************************************************/
31 
32 #ifndef _Xi18n_h
33 #define _Xi18n_h
34 #include <X11/Xlib.h>
35 #include <X11/Xfuncs.h>
36 #include <X11/Xos.h>
37 #include "XimProto.h"
38 
39 /*
40  * Minor Protocol Number for Extension Protocol
41  */
42 #define XIM_EXTENSION				128
43 #define XIM_EXT_SET_EVENT_MASK			(0x30)
44 #define	XIM_EXT_FORWARD_KEYEVENT		(0x32)
45 #define	XIM_EXT_MOVE				(0x33)
46 #define COMMON_EXTENSIONS_NUM   		3
47 
48 #include <stdlib.h>
49 #include "IMdkit.h"
50 
51 /* XI18N Valid Attribute Name Definition */
52 #define ExtForwardKeyEvent	"extForwardKeyEvent"
53 #define ExtMove			"extMove"
54 #define ExtSetEventMask		"extSetEventMask"
55 
56 /*
57  * Padding macro
58  */
59 #define	IMPAD(length) ((4 - ((length)%4))%4)
60 
61 /*
62  * Target Atom for Transport Connection
63  */
64 #define LOCALES		"LOCALES"
65 #define TRANSPORT	"TRANSPORT"
66 
67 #define I18N_OPEN	0
68 #define I18N_SET	1
69 #define I18N_GET	2
70 
71 typedef struct
72 {
73     char        *transportname;
74     int         namelen;
75     Bool        (*checkAddr) ();
76 } TransportSW;
77 
78 typedef struct _XIMPending
79 {
80     unsigned    char *p;
81     struct _XIMPending *next;
82 } XIMPending;
83 
84 typedef struct _XimProtoHdr
85 {
86     CARD8	major_opcode;
87     CARD8	minor_opcode;
88     CARD16	length;
89 } XimProtoHdr;
90 
91 typedef struct
92 {
93     CARD16	attribute_id;
94     CARD16	type;
95     CARD16	length;
96     char	*name;
97 } XIMAttr;
98 
99 typedef struct
100 {
101     CARD16	attribute_id;
102     CARD16	type;
103     CARD16	length;
104     char	*name;
105 } XICAttr;
106 
107 typedef struct
108 {
109     int		attribute_id;
110     CARD16	name_length;
111     char	*name;
112     int		value_length;
113     void	*value;
114     int		type;
115 } XIMAttribute;
116 
117 typedef struct
118 {
119     int		attribute_id;
120     CARD16	name_length;
121     char	*name;
122     int		value_length;
123     void	*value;
124     int		type;
125 } XICAttribute;
126 
127 typedef struct
128 {
129     int		length;
130     char	*name;
131 } XIMStr;
132 
133 typedef struct
134 {
135     CARD16	major_opcode;
136     CARD16	minor_opcode;
137     CARD16	length;
138     char	*name;
139 } XIMExt;
140 
141 typedef struct _Xi18nClient
142 {
143     int		connect_id;
144     CARD8	byte_order;
145     /*
146        '?': initial value
147        'B': for Big-Endian
148        'l': for little-endian
149      */
150     int		sync;
151     XIMPending  *pending;
152     void *trans_rec;		/* contains transport specific data  */
153     struct _Xi18nClient *next;
154 } Xi18nClient;
155 
156 typedef struct _Xi18nCore *Xi18n;
157 
158 /*
159  * Callback Struct for XIM Protocol
160  */
161 typedef struct
162 {
163     int		major_code;
164     int		minor_code;
165     CARD16	connect_id;
166 } IMAnyStruct;
167 
168 typedef struct
169 {
170     int		major_code;
171     int		minor_code;
172     CARD16	connect_id;
173     CARD8	byte_order;
174     CARD16	major_version;
175     CARD16	minor_version;
176 } IMConnectStruct;
177 
178 typedef struct
179 {
180     int		major_code;
181     int		minor_code;
182     CARD16	connect_id;
183 } IMDisConnectStruct;
184 
185 typedef struct
186 {
187     int		major_code;
188     int		minor_code;
189     CARD16	connect_id;
190     XIMStr	lang;
191 } IMOpenStruct;
192 
193 typedef struct
194 {
195     int		major_code;
196     int		minor_code;
197     CARD16	connect_id;
198 } IMCloseStruct;
199 
200 typedef struct
201 {
202     int		major_code;
203     int		minor_code;
204     CARD16	connect_id;
205     CARD16	number;
206     XIMStr	*extension;
207 } IMQueryExtensionStruct;
208 
209 typedef struct
210 {
211     int		major_code;
212     int		minor_code;
213     CARD16	connect_id;
214     CARD16	number;
215     char	**im_attr_list;
216 } IMGetIMValuesStruct;
217 
218 typedef struct
219 {
220     int		major_code;
221     int		minor_code;
222     CARD16	connect_id;
223     CARD16	icid;
224     CARD16	preedit_attr_num;
225     CARD16	status_attr_num;
226     CARD16	ic_attr_num;
227     XICAttribute *preedit_attr;
228     XICAttribute *status_attr;
229     XICAttribute *ic_attr;
230 } IMChangeICStruct;
231 
232 typedef struct
233 {
234     int		major_code;
235     int		minor_code;
236     CARD16	connect_id;
237     CARD16	icid;
238 } IMDestroyICStruct;
239 
240 typedef struct
241 {
242     int		major_code;
243     int		minor_code;
244     CARD16	connect_id;
245     CARD16	icid;
246     CARD16	length;
247     char	*commit_string;
248 } IMResetICStruct;
249 
250 typedef struct
251 {
252     int		major_code;
253     int		minor_code;
254     CARD16	connect_id;
255     CARD16	icid;
256 } IMChangeFocusStruct;
257 
258 typedef struct
259 {
260     int		major_code;
261     int		minor_code;
262     CARD16	connect_id;
263     CARD16	icid;
264     BITMASK16	sync_bit;
265     CARD16	serial_number;
266     XEvent	event;
267 } IMForwardEventStruct;
268 
269 typedef struct
270 {
271     int		major_code;
272     int		minor_code;
273     CARD16	connect_id;
274     CARD16	icid;
275     CARD16	flag;
276     KeySym	keysym;
277     char	*commit_string;
278 } IMCommitStruct;
279 
280 typedef struct
281 {
282     int		major_code;
283     int		minor_code;
284     CARD16	connect_id;
285     CARD16	icid;
286     CARD32	flag;
287     CARD32	key_index;
288     CARD32	event_mask;
289 } IMTriggerNotifyStruct;
290 
291 typedef struct
292 {
293     int		major_code;
294     int		minor_code;
295     CARD16	connect_id;
296     CARD16	encoding_number;
297     XIMStr	*encoding;	/* name information */
298     CARD16	encoding_info_number;
299     XIMStr	*encodinginfo;	/* detailed information */
300     CARD16	category;	/* #0 for name, #1 for detail */
301     INT16	enc_index;	/* index of the encoding determined */
302 } IMEncodingNegotiationStruct;
303 
304 typedef struct
305 {
306     int		major_code;
307     int		minor_code;
308     CARD16	connect_id;
309     CARD16	icid;
310     CARD32	flag;
311     CARD32	forward_event_mask;
312     CARD32	sync_event_mask;
313 } IMSetEventMaskStruct;
314 
315 typedef struct
316 {
317     int		major_code;
318     int		minor_code;
319     CARD16	connect_id;
320     CARD16	icid;
321     CARD32	filter_event_mask;
322     CARD32	intercept_event_mask;
323     CARD32	select_event_mask;
324     CARD32	forward_event_mask;
325     CARD32	sync_event_mask;
326 } IMExtSetEventMaskStruct;
327 
328 typedef struct
329 {
330     int		major_code;
331     int		minor_code;
332     CARD16	connect_id;
333     CARD16	icid;
334     CARD16	x;
335     CARD16	y;
336 } IMMoveStruct;
337 
338 typedef struct
339 {
340     int		major_code;
341     int		minor_code;
342     CARD16	connect_id;
343     CARD16	icid;
344     BITMASK16	flag;
345     CARD16	error_code;
346     CARD16	str_length;
347     CARD16	error_type;
348     char	*error_detail;
349 } IMErrorStruct;
350 
351 typedef struct
352 {
353     int		major_code;
354     int		minor_code;
355     CARD16	connect_id;
356     CARD16	icid;
357 } IMPreeditStateStruct;
358 
359 /* Callbacks */
360 typedef struct
361 {
362     int		major_code;
363     int		minor_code;
364     CARD16	connect_id;
365     CARD16	icid;
366 } IMGeometryCBStruct;
367 
368 typedef struct
369 {
370     int		major_code;
371     int		minor_code;
372     CARD16	connect_id;
373     CARD16	icid;
374     union
375     {
376 	int return_value;			/* PreeditStart */
377 	XIMPreeditDrawCallbackStruct draw;	/* PreeditDraw */
378 	XIMPreeditCaretCallbackStruct caret; 	/* PreeditCaret */
379     } todo;
380 } IMPreeditCBStruct;
381 
382 typedef struct
383 {
384     int		major_code;
385     int		minor_code;
386     CARD16	connect_id;
387     CARD16	icid;
388     union
389     {
390 	XIMStatusDrawCallbackStruct draw;	/* StatusDraw */
391     } todo;
392 } IMStatusCBStruct;
393 
394 typedef struct
395 {
396     int		major_code;
397     int		minor_code;
398     CARD16	connect_id;
399     CARD16	icid;
400     XIMStringConversionCallbackStruct strconv;
401 } IMStrConvCBStruct;
402 
403 typedef struct
404 {
405     int		major_code;
406     int		minor_code;
407     CARD16	connect_id;
408     CARD16	icid;
409 } IMSyncXlibStruct;
410 
411 typedef union _IMProtocol
412 {
413     int	major_code;
414     IMAnyStruct any;
415     IMConnectStruct imconnect;
416     IMDisConnectStruct imdisconnect;
417     IMOpenStruct imopen;
418     IMCloseStruct imclose;
419     IMQueryExtensionStruct queryext;
420     IMGetIMValuesStruct getim;
421     IMEncodingNegotiationStruct encodingnego;
422     IMExtSetEventMaskStruct extsetevent;
423     IMMoveStruct extmove;
424     IMSetEventMaskStruct setevent;
425     IMChangeICStruct changeic;
426     IMDestroyICStruct destroyic;
427     IMResetICStruct resetic;
428     IMChangeFocusStruct changefocus;
429     IMCommitStruct commitstring;
430     IMForwardEventStruct forwardevent;
431     IMTriggerNotifyStruct triggernotify;
432     IMPreeditStateStruct preedit_state;
433     IMErrorStruct imerror;
434     IMGeometryCBStruct geometry_callback;
435     IMPreeditCBStruct preedit_callback;
436     IMStatusCBStruct status_callback;
437     IMStrConvCBStruct strconv_callback;
438     IMSyncXlibStruct sync_xlib;
439     long pad[32];
440 } IMProtocol;
441 
442 typedef int (*IMProtoHandler) (XIMS, IMProtocol*);
443 
444 #define DEFAULT_FILTER_MASK	(KeyPressMask)
445 
446 /* Xi18nAddressRec structure */
447 typedef struct _Xi18nAddressRec
448 {
449     Display	*dpy;
450     CARD8	im_byteOrder;	/* byte order 'B' or 'l' */
451     /* IM Values */
452     long	imvalue_mask;
453     Window	im_window;	/* IMServerWindow */
454     char	*im_name;	/* IMServerName */
455     char	*im_locale;	/* IMLocale */
456     char	*im_addr;	/* IMServerTransport */
457     XIMStyles	input_styles;	/* IMInputStyles */
458     XIMTriggerKeys on_keys;	/* IMOnKeysList */
459     XIMTriggerKeys off_keys;	/* IMOffKeysList */
460     XIMEncodings encoding_list; /* IMEncodingList */
461     IMProtoHandler improto;	/* IMProtocolHander */
462     long	filterevent_mask; /* IMFilterEventMask */
463     /* XIM_SERVERS target Atoms */
464     Atom	selection;
465     Atom	Localename;
466     Atom	Transportname;
467     /* XIM/XIC Attr */
468     int		im_attr_num;
469     XIMAttr	*xim_attr;
470     int		ic_attr_num;
471     XICAttr	*xic_attr;
472     CARD16	preeditAttr_id;
473     CARD16	statusAttr_id;
474     CARD16	separatorAttr_id;
475     /* XIMExtension List */
476     int		ext_num;
477     XIMExt	extension[COMMON_EXTENSIONS_NUM];
478     /* transport specific connection address */
479     void	*connect_addr;
480     /* actual data is defined:
481        XSpecRec in Xi18nX.h for X-based connection.
482        TransSpecRec in Xi18nTr.h for Socket-based connection.
483      */
484     /* clients table */
485     Xi18nClient *clients;
486     Xi18nClient *free_clients;
487 } Xi18nAddressRec;
488 
489 typedef struct _Xi18nMethodsRec
490 {
491     Bool (*begin) (XIMS);
492     Bool (*end) (XIMS);
493     Bool (*send) (XIMS, CARD16, unsigned char*, long);
494     Bool (*wait) (XIMS, CARD16, CARD8, CARD8);
495     Bool (*disconnect) (XIMS, CARD16);
496 } Xi18nMethodsRec;
497 
498 typedef struct _Xi18nCore
499 {
500     Xi18nAddressRec address;
501     Xi18nMethodsRec methods;
502 } Xi18nCore;
503 
504 #endif
505 
506