1/*
2 * Copyright (c) 1991, 1992, Oracle and/or its affiliates.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23/******************************************************************
24
25           Copyright 1992, 1993, 1994 by FUJITSU LIMITED
26           Copyright 1993, 1994       by Sony Corporation
27
28Permission to use, copy, modify, distribute, and sell this software and
29its documentation for any purpose is hereby granted without fee, provided
30that the above copyright notice appear in all copies and that both that
31copyright notice and this permission notice appear in supporting
32documentation, and that the name of FUJITSU LIMITED and Sony Corporation
33not be used in advertising or publicity pertaining to distribution of the
34software without specific, written prior permission.  FUJITSU LIMITED and
35Sony Corporation makes no representations about the suitability of this
36software for any purpose.  It is provided "as is" without express or
37implied warranty.
38
39FUJITSU LIMITED AND SONY CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
40TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
41FITNESS, IN NO EVENT SHALL FUJITSU LIMITED OR SONY CORPORATION BE LIABLE
42FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
43RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
44NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
45USE OR PERFORMANCE OF THIS SOFTWARE.
46
47  Author: Hideki Hiura (hhiura@Sun.COM) Sun Microsystems, Inc.
48          Takashi Fujiwara     FUJITSU LIMITED
49                                 fujiwara@a80.tech.yk.fujitsu.co.jp
50	  Makoto Wakamatsu     Sony Corporation
51                                 makoto@sm.sony.co.jp
52	  Hiroyuki Miyamoto    Digital Equipment Corporation
53                                 miyamoto@jrd.dec.com
54
55******************************************************************/
56
57#ifndef _XIMINTP_H
58#define _XIMINTP_H
59
60#include "XimProto.h"
61#include "XlcPublic.h"
62
63/*
64 * for protocol layer callback function
65 */
66typedef Bool (*XimProtoIntrProc)(
67	Xim, INT16, XPointer, XPointer
68);
69typedef struct _XimProtoIntrRec {
70    XimProtoIntrProc		 func;
71    CARD16			 major_code;
72    CARD16			 minor_code;
73    XPointer			 call_data;
74    struct _XimProtoIntrRec	*next;
75} XimProtoIntrRec;
76
77/*
78 * for transport layer methods
79 */
80typedef Bool (*XimTransConnectProc)(
81	 Xim
82);
83typedef Bool (*XimTransShutdownProc)(
84	 Xim
85);
86typedef Bool (*XimTransWriteProc)(
87	 Xim, INT16, XPointer
88);
89typedef Bool (*XimTransReadProc)(
90	 Xim, XPointer, int, int *
91);
92typedef void (*XimTransFlushProc)(
93	 Xim
94);
95typedef Bool (*XimTransRegDispatcher)(
96	 Xim, Bool (*)(Xim, INT16, XPointer, XPointer), XPointer
97);
98typedef Bool (*XimTransCallDispatcher)(
99	 Xim, INT16, XPointer
100);
101
102/*
103 * private part of IM
104 */
105typedef struct _XimProtoPrivateRec {
106    /* The first fields are identical with XimCommonPrivateRec. */
107    XlcConv			 ctom_conv;
108    XlcConv			 ctow_conv;
109    XlcConv			 ctoutf8_conv;
110    XlcConv			 cstomb_conv;
111    XlcConv			 cstowc_conv;
112    XlcConv			 cstoutf8_conv;
113    XlcConv			 ucstoc_conv;
114    XlcConv			 ucstoutf8_conv;
115
116    Window			 im_window;
117    XIMID			 imid;
118    CARD16			 unused;
119    XIMStyles			*default_styles;
120    CARD32			*im_onkeylist;
121    CARD32			*im_offkeylist;
122    BITMASK32			 flag;
123
124    BITMASK32			 registed_filter_event;
125    EVENTMASK			 forward_event_mask;
126    EVENTMASK			 synchronous_event_mask;
127
128    XimProtoIntrRec		*intrproto;
129    XIMResourceList		 im_inner_resources;
130    unsigned int		 im_num_inner_resources;
131    XIMResourceList		 ic_inner_resources;
132    unsigned int		 ic_num_inner_resources;
133    char			*hold_data;
134    int				 hold_data_len;
135    char			*locale_name;
136    CARD16			 protocol_major_version;
137    CARD16			 protocol_minor_version;
138    XrmQuark			*saved_imvalues;
139    int				 num_saved_imvalues;
140
141    /*
142     * transport specific
143     */
144    XimTransConnectProc		 connect;
145    XimTransShutdownProc	 shutdown;
146    XimTransWriteProc		 write;
147    XimTransReadProc		 read;
148    XimTransFlushProc		 flush;
149    XimTransRegDispatcher	 register_dispatcher;
150    XimTransCallDispatcher	 call_dispatcher;
151    XPointer			 spec;
152
153    unsigned long		 fabricated_serial;
154    Time			 fabricated_time;
155    Bool			 enable_fabricated_order;
156} XimProtoPrivateRec;
157
158/*
159 * bit mask for the flag of XIMPrivateRec
160 */
161#define SERVER_CONNECTED	(1L)
162#define	DYNAMIC_EVENT_FLOW	(1L << 1)
163#define	USE_AUTHORIZATION_FUNC	(1L << 2)
164#ifdef XIM_CONNECTABLE
165#define DELAYBINDABLE		(1L << 3)
166#define RECONNECTABLE		(1L << 4)
167#endif /* XIM_CONNECTABLE */
168#define FABRICATED		(1L << 5)
169#define NEED_SYNC_REPLY		(1L << 6)
170
171/*
172 * macro for the flag of XIMPrivateRec
173 */
174#define IS_SERVER_CONNECTED(im) \
175		((((Xim)im))->private.proto.flag & SERVER_CONNECTED)
176#define MARK_SERVER_CONNECTED(im) \
177		((((Xim)im))->private.proto.flag |= SERVER_CONNECTED)
178#define UNMARK_SERVER_CONNECTED(im) \
179		((((Xim)im))->private.proto.flag &= ~SERVER_CONNECTED)
180
181#define	IS_DYNAMIC_EVENT_FLOW(im) \
182		(((Xim)im)->private.proto.flag & DYNAMIC_EVENT_FLOW)
183#define	MARK_DYNAMIC_EVENT_FLOW(im) \
184		(((Xim)im)->private.proto.flag |= DYNAMIC_EVENT_FLOW)
185
186#define	IS_USE_AUTHORIZATION_FUNC(im) \
187		(((Xim)im)->private.proto.flag & USE_AUTHORIZATION_FUNC)
188#define	MARK_USE_AUTHORIZATION_FUNC(im) \
189		(((Xim)im)->private.proto.flag |= USE_AUTHORIZATION_FUNC)
190
191#ifdef XIM_CONNECTABLE
192#define IS_DELAYBINDABLE(im) \
193		(((Xim)im)->private.proto.flag & DELAYBINDABLE)
194#define MARK_DELAYBINDABLE(im) \
195		(((Xim)im)->private.proto.flag |= DELAYBINDABLE)
196
197#define IS_RECONNECTABLE(im) \
198		(((Xim)im)->private.proto.flag & RECONNECTABLE)
199#define MARK_RECONNECTABLE(im) \
200		(((Xim)im)->private.proto.flag |= RECONNECTABLE)
201
202#define IS_CONNECTABLE(im) \
203    (((Xim)im)->private.proto.flag & (DELAYBINDABLE|RECONNECTABLE))
204#define UNMAKE_CONNECTABLE(im) \
205    (((Xim)im)->private.proto.flag &= ~(DELAYBINDABLE|RECONNECTABLE))
206#endif /* XIM_CONNECTABLE */
207
208#define IS_FABRICATED(im) \
209		(((Xim)im)->private.proto.flag & FABRICATED)
210#define MARK_FABRICATED(im) \
211		(((Xim)im)->private.proto.flag |= FABRICATED)
212#define UNMARK_FABRICATED(im) \
213		(((Xim)im)->private.proto.flag &= ~FABRICATED)
214
215#define IS_NEED_SYNC_REPLY(im) \
216		(((Xim)im)->private.proto.flag & NEED_SYNC_REPLY)
217#define MARK_NEED_SYNC_REPLY(im) \
218		(((Xim)im)->private.proto.flag |= NEED_SYNC_REPLY)
219#define UNMARK_NEED_SYNC_REPLY(im) \
220		(((Xim)im)->private.proto.flag &= ~NEED_SYNC_REPLY)
221
222/*
223 * bit mask for the register_filter_event of XIMPrivateRec/XICPrivateRec
224 */
225#define KEYPRESS_MASK		(1L)
226#define KEYRELEASE_MASK		(1L << 1)
227#define DESTROYNOTIFY_MASK	(1L << 2)
228
229typedef struct _XimCommitInfoRec {
230    struct _XimCommitInfoRec	*next;
231    char			*string;
232    int				 string_len;
233    KeySym			*keysym;
234    int				 keysym_len;
235} XimCommitInfoRec, *XimCommitInfo;
236
237typedef struct _XimPendingCallback {
238    int				 major_opcode;
239    Xim				 im;
240    Xic				 ic;
241    char			*proto;
242    int				 proto_len;
243    struct _XimPendingCallback	*next;
244} XimPendingCallbackRec, *XimPendingCallback;
245
246
247/*
248 * private part of IC
249 */
250typedef struct _XicProtoPrivateRec {
251    XICID	         icid;			/* ICID		*/
252    CARD16		 dmy;
253    BITMASK32		 flag;			/* Input Mode	*/
254
255    BITMASK32		 registed_filter_event; /* registed filter mask */
256    EVENTMASK		 forward_event_mask;	/* forward event mask */
257    EVENTMASK		 synchronous_event_mask;/* sync event mask */
258    EVENTMASK		 filter_event_mask;	/* negrect event mask */
259    EVENTMASK		 intercept_event_mask;	/* deselect event mask */
260    EVENTMASK		 select_event_mask;	/* select event mask */
261
262    char		*preedit_font;		/* Base font name list */
263    int			 preedit_font_length;	/* length of base font name */
264    char		*status_font;		/* Base font name list */
265    int			 status_font_length;	/* length of base font name */
266
267    XimCommitInfo	 commit_info;
268    XIMResourceList	 ic_resources;
269    unsigned int	 ic_num_resources;
270    XIMResourceList	 ic_inner_resources;
271    unsigned int	 ic_num_inner_resources;
272    XrmQuark		*saved_icvalues;
273    int			 num_saved_icvalues;
274    XimPendingCallback	 pend_cb_que;
275    Bool		 waitCallback;
276} XicProtoPrivateRec ;
277
278/*
279 * bit mask for the flag of XICPrivateRec
280 */
281#define IC_CONNECTED		(1L)
282
283/*
284 * macro for the flag of XICPrivateRec
285 */
286#define	IS_IC_CONNECTED(ic) \
287		(((Xic)ic)->private.proto.flag & IC_CONNECTED)
288#define	MARK_IC_CONNECTED(ic) \
289		(((Xic)ic)->private.proto.flag |= IC_CONNECTED)
290#define	UNMARK_IC_CONNECTED(ic) \
291		(((Xic)ic)->private.proto.flag &= ~IC_CONNECTED)
292
293/*
294 * macro for the filter_event_mask of XICPrivateRec
295 */
296#define	IS_NEGLECT_EVENT(ic, mask) \
297		(((Xic)ic)->private.proto.filter_event_mask & (mask))
298
299/*
300 * macro for the forward_event_mask of XICPrivateRec
301 */
302#define	IS_FORWARD_EVENT(ic, mask) \
303		(((Xic)ic)->private.proto.forward_event_mask & (mask))
304
305/*
306 * macro for the synchronous_event_mask of XICPrivateRec
307 */
308#define	IS_SYNCHRONOUS_EVENT(ic, mask) \
309   ((((Xic)ic)->private.proto.synchronous_event_mask & (mask)) ? True: False)
310
311#define XIM_MAXIMNAMELEN 64
312#define XIM_MAXLCNAMELEN 64
313
314_X_HIDDEN Bool
315_XimFabricateSerial(
316    Xim                  im,
317    XKeyEvent           *event);
318
319_X_HIDDEN Bool
320_XimUnfabricateSerial(
321    Xim                  im,
322    Xic                  ic,
323    XKeyEvent           *event);
324
325_X_HIDDEN Bool
326_XimIsFabricatedSerial(
327    Xim                  im,
328    XKeyEvent           *event);
329
330#endif /* _XIMINTP_H */
331