imRm.c revision 818534a1
1/******************************************************************
2
3	  Copyright 1990, 1991, 1992,1993, 1994 by FUJITSU LIMITED
4	  Copyright 1994                        by Sony Corporation
5
6Permission to use, copy, modify, distribute, and sell this software
7and its documentation for any purpose is hereby granted without fee,
8provided that the above copyright notice appear in all copies and
9that both that copyright notice and this permission notice appear
10in supporting documentation, and that the name of FUJITSU LIMITED
11and Sony Corporation not be used in advertising or publicity
12pertaining to distribution of the software without specific,
13written prior permission. FUJITSU LIMITED and Sony Corporation make
14no representations about the suitability of this software for any
15purpose. It is provided "as is" without express or implied warranty.
16
17FUJITSU LIMITED AND SONY CORPORATION DISCLAIM ALL WARRANTIES WITH
18REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
19MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJITSU LIMITED AND
20SONY CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
21DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
22PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
23TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24PERFORMANCE OF THIS SOFTWARE.
25
26  Author: Takashi Fujiwara     FUJITSU LIMITED
27			       fujiwara@a80.tech.yk.fujitsu.co.jp
28  Modifier: Makoto Wakamatsu   Sony Corporation
29			       makoto@sm.sony.co.jp
30
31******************************************************************/
32
33#ifdef HAVE_CONFIG_H
34#include <config.h>
35#endif
36#include <stdio.h>
37#include <X11/Xlib.h>
38#include "Xlibint.h"
39#include "Xlcint.h"
40#include "Ximint.h"
41#include "Xresource.h"
42
43#define GET_NAME(x) name_table + x.name_offset
44
45typedef struct _XimValueOffsetInfo {
46    unsigned short name_offset;
47    XrmQuark		 quark;
48    unsigned int	 offset;
49    Bool		 (*defaults)(
50	struct _XimValueOffsetInfo *, XPointer, XPointer, unsigned long
51			 );
52    Bool		 (*encode)(
53	struct _XimValueOffsetInfo *, XPointer, XPointer
54			 );
55    Bool		 (*decode)(
56	struct _XimValueOffsetInfo *, XPointer, XPointer
57			 );
58} XimValueOffsetInfoRec, *XimValueOffsetInfo;
59
60#ifdef XIM_CONNECTABLE
61static Bool
62_XimCheckBool(str)
63    char	*str;
64{
65    if(!strcmp(str, "True") || !strcmp(str, "true") ||
66       !strcmp(str, "Yes")  || !strcmp(str, "yes")  ||
67       !strcmp(str, "ON")   || !strcmp(str, "on"))
68	return True;
69    return False;
70}
71
72void
73_XimSetProtoResource(im)
74    Xim		 im;
75{
76    char	res_name_buf[256];
77    char*	res_name;
78    size_t	res_name_len;
79    char	res_class_buf[256];
80    char*	res_class;
81    size_t	res_class_len;
82    char*	str_type;
83    XrmValue	value;
84    XIMStyle	preedit_style = 0;
85    XIMStyle	status_style = 0;
86    XIMStyles*	imstyles;
87    char*	dotximdot = ".xim.";
88    char*	ximdot = "xim.";
89    char*	dotXimdot = ".Xim.";
90    char*	Ximdot = "Xim.";
91
92    if (!im->core.rdb)
93	return;
94
95    res_name_len = strlen (im->core.res_name);
96    if (res_name_len < 200) {
97	res_name = res_name_buf;
98	res_name_len = sizeof(res_name_buf);
99    }
100    else {
101	res_name_len += 50;
102	res_name = Xmalloc (res_name_len);
103    }
104    res_class_len = strlen (im->core.res_class);
105    if (res_class_len < 200) {
106	res_class = res_class_buf;
107	res_class_len = sizeof(res_class_buf);
108    }
109    else {
110	res_class_len += 50;
111	res_class = Xmalloc (res_class_len);
112    }
113    /* pretend malloc always works */
114
115    (void) snprintf (res_name, res_name_len, "%s%s%s",
116	im->core.res_name != NULL ? im->core.res_name : "*",
117	im->core.res_name != NULL ? dotximdot : ximdot,
118	"useAuth");
119    (void) snprintf (res_class, res_class_len, "%s%s%s",
120	im->core.res_class != NULL ? im->core.res_class : "*",
121	im->core.res_class != NULL ? dotXimdot : Ximdot,
122	"UseAuth");
123    bzero(&value, sizeof(XrmValue));
124    if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
125	if(_XimCheckBool(value.addr)) {
126	    MARK_USE_AUTHORIZATION_FUNC(im);
127	}
128    }
129
130    (void) snprintf (res_name, res_name_len, "%s%s%s",
131	im->core.res_name != NULL ? im->core.res_name : "*",
132	im->core.res_name != NULL ? dotximdot : ximdot,
133	"delaybinding");
134    (void) snprintf (res_class, res_class_len, "%s%s%s",
135	im->core.res_class != NULL ? im->core.res_class : "*",
136	im->core.res_class != NULL ? dotXimdot : Ximdot,
137	"Delaybinding");
138    bzero(&value, sizeof(XrmValue));
139    if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
140	if(_XimCheckBool(value.addr)) {
141	    MARK_DELAYBINDABLE(im);
142	}
143    }
144
145    (void) snprintf (res_name, res_name_len, "%s%s%s",
146	im->core.res_name != NULL ? im->core.res_name : "*",
147	im->core.res_name != NULL ? dotximdot : ximdot,
148	"reconnect");
149    (void) snprintf (res_class, res_class_len, "%s%s%s",
150	im->core.res_class != NULL ? im->core.res_class : "*",
151	im->core.res_class != NULL ? dotXimdot : Ximdot,
152	"Reconnect");
153    bzero(&value, sizeof(XrmValue));
154    if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
155	if(_XimCheckBool(value.addr)) {
156	    MARK_RECONNECTABLE(im);
157	}
158    }
159
160    if(!IS_CONNECTABLE(im)) {
161	if (res_name != res_name_buf) Xfree (res_name);
162	if (res_class != res_class_buf) Xfree (res_class);
163	return;
164    }
165
166    (void) snprintf (res_name, res_name_len, "%s%s%s",
167	im->core.res_name != NULL ? im->core.res_name : "*",
168	im->core.res_name != NULL ? dotximdot : ximdot,
169	"preeditDefaultStyle");
170    (void) snprintf (res_class, res_class_len, "%s%s%s",
171	im->core.res_class != NULL ? im->core.res_class : "*",
172	im->core.res_class != NULL ? dotXimdot : Ximdot,
173	"PreeditDefaultStyle");
174    if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
175	if(!strcmp(value.addr, "XIMPreeditArea"))
176	    preedit_style = XIMPreeditArea;
177	else if(!strcmp(value.addr, "XIMPreeditCallbacks"))
178	    preedit_style = XIMPreeditCallbacks;
179	else if(!strcmp(value.addr, "XIMPreeditPosition"))
180	    preedit_style = XIMPreeditPosition;
181	else if(!strcmp(value.addr, "XIMPreeditNothing"))
182	    preedit_style = XIMPreeditNothing;
183	else if(!strcmp(value.addr, "XIMPreeditNone"))
184	    preedit_style = XIMPreeditNone;
185    }
186    if(!preedit_style)
187	preedit_style = XIMPreeditNothing;
188
189    (void) snprintf (res_name, res_name_len, "%s%s%s",
190	im->core.res_name != NULL ? im->core.res_name : "*",
191	im->core.res_name != NULL ? dotximdot : ximdot,
192	"statusDefaultStyle");
193    (void) snprintf (res_class, res_class_len, "%s%s%s",
194	im->core.res_class != NULL ? im->core.res_class : "*",
195	im->core.res_class != NULL ? dotXimdot : Ximdot,
196	"StatusDefaultStyle");
197    if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) {
198	if(!strcmp(value.addr, "XIMStatusArea"))
199	    status_style = XIMStatusArea;
200	else if(!strcmp(value.addr, "XIMStatusCallbacks"))
201	    status_style = XIMStatusCallbacks;
202	else if(!strcmp(value.addr, "XIMStatusNothing"))
203	    status_style = XIMStatusNothing;
204	else if(!strcmp(value.addr, "XIMStatusNone"))
205	    status_style = XIMStatusNone;
206    }
207    if(!status_style)
208	status_style = XIMStatusNothing;
209
210    if(!(imstyles = Xmalloc(sizeof(XIMStyles) + sizeof(XIMStyle)))){
211	if (res_name != res_name_buf) Xfree (res_name);
212	if (res_class != res_class_buf) Xfree (res_class);
213	return;
214    }
215    imstyles->count_styles = 1;
216    imstyles->supported_styles =
217			(XIMStyle *)((char *)imstyles + sizeof(XIMStyles));
218    imstyles->supported_styles[0] = preedit_style | status_style;
219    im->private.proto.default_styles = imstyles;
220    if (res_name != res_name_buf) Xfree (res_name);
221    if (res_class != res_class_buf) Xfree (res_class);
222}
223#endif /* XIM_CONNECTABLE */
224
225static const char name_table[] =
226    /*   0 */ XNQueryInputStyle"\0"
227    /*  16 */ XNClientWindow"\0"
228    /*  29 */ XNInputStyle"\0"
229    /*  40 */ XNFocusWindow"\0"
230    /*  52 */ XNResourceName"\0"
231    /*  65 */ XNResourceClass"\0"
232    /*  79 */ XNGeometryCallback"\0"
233    /*  96 */ XNDestroyCallback"\0"
234    /* 112 */ XNFilterEvents"\0"
235    /* 125 */ XNPreeditStartCallback"\0"
236    /* 146 */ XNPreeditDoneCallback"\0"
237    /* 166 */ XNPreeditDrawCallback"\0"
238    /* 186 */ XNPreeditCaretCallback"\0"
239    /* 207 */ XNPreeditStateNotifyCallback"\0"
240    /* 234 */ XNPreeditAttributes"\0"
241    /* 252 */ XNStatusStartCallback"\0"
242    /* 272 */ XNStatusDoneCallback"\0"
243    /* 291 */ XNStatusDrawCallback"\0"
244    /* 310 */ XNStatusAttributes"\0"
245    /* 327 */ XNArea"\0"
246    /* 332 */ XNAreaNeeded"\0"
247    /* 343 */ XNSpotLocation"\0"
248    /* 356 */ XNColormap"\0"
249    /* 365 */ XNStdColormap"\0"
250    /* 377 */ XNForeground"\0"
251    /* 388 */ XNBackground"\0"
252    /* 399 */ XNBackgroundPixmap"\0"
253    /* 416 */ XNFontSet"\0"
254    /* 424 */ XNLineSpace"\0"
255    /* 434 */ XNCursor"\0"
256    /* 441 */ XNQueryIMValuesList"\0"
257    /* 459 */ XNQueryICValuesList"\0"
258    /* 477 */ XNVisiblePosition"\0"
259    /* 493 */ XNStringConversionCallback"\0"
260    /* 518 */ XNStringConversion"\0"
261    /* 535 */ XNResetState"\0"
262    /* 546 */ XNHotKey"\0"
263    /* 553 */ XNHotKeyState"\0"
264    /* 565 */ XNPreeditState
265;
266
267#define OFFSET_XNQUERYINPUTSTYLE 0
268#define OFFSET_XNCLIENTWINDOW 16
269#define OFFSET_XNINPUTSTYLE 29
270#define OFFSET_XNFOCUSWINDOW 40
271#define OFFSET_XNRESOURCENAME 52
272#define OFFSET_XNRESOURCECLASS 65
273#define OFFSET_XNGEOMETRYCALLBACK 79
274#define OFFSET_XNDESTROYCALLBACK 96
275#define OFFSET_XNFILTEREVENTS 112
276#define OFFSET_XNPREEDITSTARTCALLBACK 125
277#define OFFSET_XNPREEDITDONECALLBACK 146
278#define OFFSET_XNPREEDITDRAWCALLBACK 166
279#define OFFSET_XNPREEDITCARETCALLBACK 186
280#define OFFSET_XNPREEDITSTATENOTIFYCALLBACK 207
281#define OFFSET_XNPREEDITATTRIBUTES 234
282#define OFFSET_XNSTATUSSTARTCALLBACK 252
283#define OFFSET_XNSTATUSDONECALLBACK 272
284#define OFFSET_XNSTATUSDRAWCALLBACK 291
285#define OFFSET_XNSTATUSATTRIBUTES 310
286#define OFFSET_XNAREA 327
287#define OFFSET_XNAREANEEDED 332
288#define OFFSET_XNSPOTLOCATION 343
289#define OFFSET_XNCOLORMAP 356
290#define OFFSET_XNSTDCOLORMAP 365
291#define OFFSET_XNFOREGROUND 377
292#define OFFSET_XNBACKGROUND 388
293#define OFFSET_XNBACKGROUNDPIXMAP 399
294#define OFFSET_XNFONTSET 416
295#define OFFSET_XNLINESPACE 424
296#define OFFSET_XNCURSOR 434
297#define OFFSET_XNQUERYIMVALUESLIST 441
298#define OFFSET_XNQUERYICVALUESLIST 459
299#define OFFSET_XNVISIBLEPOSITION 477
300#define OFFSET_XNSTRINGCONVERSIONCALLBACK 493
301#define OFFSET_XNSTRINGCONVERSION 518
302#define OFFSET_XNRESETSTATE 535
303#define OFFSET_XNHOTKEY 546
304#define OFFSET_XNHOTKEYSTATE 553
305#define OFFSET_XNPREEDITSTATE 565
306
307/* offsets into name_table */
308static const unsigned short supported_local_im_values_list[] = {
309    OFFSET_XNQUERYINPUTSTYLE,
310    OFFSET_XNRESOURCENAME,
311    OFFSET_XNRESOURCECLASS,
312    OFFSET_XNDESTROYCALLBACK,
313    OFFSET_XNQUERYIMVALUESLIST,
314    OFFSET_XNQUERYICVALUESLIST,
315    OFFSET_XNVISIBLEPOSITION
316};
317
318/* offsets into name_table */
319static const unsigned short supported_local_ic_values_list[] = {
320    OFFSET_XNINPUTSTYLE,
321    OFFSET_XNCLIENTWINDOW,
322    OFFSET_XNFOCUSWINDOW,
323    OFFSET_XNRESOURCENAME,
324    OFFSET_XNRESOURCECLASS,
325    OFFSET_XNGEOMETRYCALLBACK,
326    OFFSET_XNFILTEREVENTS,
327    OFFSET_XNDESTROYCALLBACK,
328    OFFSET_XNSTRINGCONVERSIONCALLBACK,
329    OFFSET_XNSTRINGCONVERSIONCALLBACK,
330    OFFSET_XNRESETSTATE,
331    OFFSET_XNHOTKEY,
332    OFFSET_XNHOTKEYSTATE,
333    OFFSET_XNPREEDITATTRIBUTES,
334    OFFSET_XNSTATUSATTRIBUTES,
335    OFFSET_XNAREA,
336    OFFSET_XNAREANEEDED,
337    OFFSET_XNSPOTLOCATION,
338    OFFSET_XNCOLORMAP,
339    OFFSET_XNSTDCOLORMAP,
340    OFFSET_XNFOREGROUND,
341    OFFSET_XNBACKGROUND,
342    OFFSET_XNBACKGROUNDPIXMAP,
343    OFFSET_XNFONTSET,
344    OFFSET_XNLINESPACE,
345    OFFSET_XNCURSOR,
346    OFFSET_XNPREEDITSTARTCALLBACK,
347    OFFSET_XNPREEDITDONECALLBACK,
348    OFFSET_XNPREEDITDRAWCALLBACK,
349    OFFSET_XNPREEDITCARETCALLBACK,
350    OFFSET_XNSTATUSSTARTCALLBACK,
351    OFFSET_XNSTATUSDONECALLBACK,
352    OFFSET_XNSTATUSDRAWCALLBACK,
353    OFFSET_XNPREEDITSTATE,
354    OFFSET_XNPREEDITSTATENOTIFYCALLBACK
355};
356
357static XIMStyle const supported_local_styles[] = {
358    XIMPreeditNone	| XIMStatusNone,
359    XIMPreeditNothing	| XIMStatusNothing,
360    0						/* dummy */
361};
362
363static Bool
364_XimDefaultStyles(
365    XimValueOffsetInfo	  info,
366    XPointer	 	  top,
367    XPointer	 	  parm,			/* unused */
368    unsigned long	  mode)			/* unused */
369{
370    XIMStyles		 *styles;
371    XIMStyles		**out;
372    register int	  i;
373    unsigned int	  n;
374    int			  len;
375    XPointer		  tmp;
376
377    n = XIMNumber(supported_local_styles) - 1;
378    len = sizeof(XIMStyles) + sizeof(XIMStyle) * n;
379    if(!(tmp = Xcalloc(1, len))) {
380	return False;
381    }
382
383    styles = (XIMStyles *)tmp;
384    if (n > 0) {
385	styles->count_styles = (unsigned short)n;
386	styles->supported_styles =
387				(XIMStyle *)((char *)tmp + sizeof(XIMStyles));
388	for(i = 0; i < n; i++) {
389	    styles->supported_styles[i] = supported_local_styles[i];
390	}
391    }
392
393    out = (XIMStyles **)((char *)top + info->offset);
394    *out = styles;
395    return True;
396}
397
398static Bool
399_XimDefaultIMValues(
400    XimValueOffsetInfo	  info,
401    XPointer	 	  top,
402    XPointer	 	  parm,			/* unused */
403    unsigned long	  mode)			/* unused */
404{
405    XIMValuesList	 *values_list;
406    XIMValuesList	**out;
407    register int	  i;
408    unsigned int	  n;
409    int			  len;
410    XPointer		  tmp;
411
412    n = XIMNumber(supported_local_im_values_list);
413    len = sizeof(XIMValuesList) + sizeof(char **) * n;
414    if(!(tmp = Xcalloc(1, len))) {
415	return False;
416    }
417
418    values_list = (XIMValuesList *)tmp;
419    if (n > 0) {
420	values_list->count_values = (unsigned short)n;
421	values_list->supported_values
422			 = (char **)((char *)tmp + sizeof(XIMValuesList));
423	for(i = 0; i < n; i++) {
424	    values_list->supported_values[i] =
425		(char *)name_table + supported_local_im_values_list[i];
426	}
427    }
428
429    out = (XIMValuesList **)((char *)top + info->offset);
430    *out = values_list;
431    return True;
432}
433
434static Bool
435_XimDefaultICValues(
436    XimValueOffsetInfo	  info,
437    XPointer	 	  top,
438    XPointer	 	  parm,			/* unused */
439    unsigned long	  mode)			/* unused */
440{
441    XIMValuesList	 *values_list;
442    XIMValuesList	**out;
443    register int	  i;
444    unsigned int	  n;
445    int			  len;
446    XPointer		  tmp;
447
448    n = XIMNumber(supported_local_ic_values_list);
449    len = sizeof(XIMValuesList) + sizeof(char **) * n;
450    if(!(tmp = Xcalloc(1, len))) {
451	return False;
452    }
453
454    values_list = (XIMValuesList *)tmp;
455    if (n > 0) {
456	values_list->count_values = (unsigned short)n;
457	values_list->supported_values
458			 = (char **)((char *)tmp + sizeof(XIMValuesList));
459	for(i = 0; i < n; i++) {
460	    values_list->supported_values[i] =
461		(char *)name_table + supported_local_ic_values_list[i];
462	}
463    }
464
465    out = (XIMValuesList **)((char *)top + info->offset);
466    *out = values_list;
467    return True;
468}
469
470static Bool
471_XimDefaultVisiblePos(
472    XimValueOffsetInfo	  info,
473    XPointer	 	  top,
474    XPointer	 	  parm,			/* unused */
475    unsigned long	  mode)			/* unused */
476{
477    Bool		*out;
478
479    out = (Bool *)((char *)top + info->offset);
480    *out = False;
481    return True;
482}
483
484static Bool
485_XimDefaultFocusWindow(
486    XimValueOffsetInfo	 info,
487    XPointer	 	 top,
488    XPointer	 	 parm,
489    unsigned long	 mode)
490{
491    Xic			 ic = (Xic)parm;
492    Window		*out;
493
494    if(ic->core.client_window == (Window)NULL) {
495	return True;
496    }
497
498    out = (Window *)((char *)top + info->offset);
499    *out = ic->core.client_window;
500    return True;
501}
502
503static Bool
504_XimDefaultResName(
505    XimValueOffsetInfo	  info,
506    XPointer	 	  top,
507    XPointer	 	  parm,
508    unsigned long	  mode)
509{
510    Xic			  ic = (Xic)parm;
511    Xim			  im = (Xim)ic->core.im;
512    char		**out;
513
514    if(im->core.res_name == (char *)NULL) {
515	return True;
516    }
517
518    out = (char **)((char *)top + info->offset);
519    *out = im->core.res_name;
520    return True;
521}
522
523static Bool
524_XimDefaultResClass(
525    XimValueOffsetInfo	   info,
526    XPointer	 	   top,
527    XPointer	 	   parm,
528    unsigned long	   mode)
529{
530    Xic			  ic = (Xic)parm;
531    Xim			  im = (Xim)ic->core.im;
532    char		**out;
533
534    if(im->core.res_class == (char *)NULL) {
535	return True;
536    }
537
538    out = (char **)((char *)top + info->offset);
539    *out = im->core.res_class;
540    return True;
541}
542
543static Bool
544_XimDefaultDestroyCB(
545    XimValueOffsetInfo	  info,
546    XPointer	 	  top,
547    XPointer	 	  parm,
548    unsigned long	  mode)
549{
550    Xic			 ic = (Xic)parm;
551    Xim			 im = (Xim)ic->core.im;
552    XIMCallback		*out;
553
554    out = (XIMCallback *)((char *)top + info->offset);
555    *out = im->core.destroy_callback;
556    return True;
557}
558
559static Bool
560_XimDefaultResetState(
561    XimValueOffsetInfo	  info,
562    XPointer	 	  top,
563    XPointer	 	  parm,
564    unsigned long	  mode)
565{
566    XIMResetState	*out;
567
568    out = (XIMResetState *)((char *)top + info->offset);
569    *out = XIMInitialState;
570    return True;
571}
572
573static Bool
574_XimDefaultHotKeyState(
575    XimValueOffsetInfo	  info,
576    XPointer	 	  top,
577    XPointer	 	  parm,
578    unsigned long	  mode)
579{
580    XIMHotKeyState	*out;
581
582    out = (XIMHotKeyState *)((char *)top + info->offset);
583    *out = XIMHotKeyStateOFF;
584    return True;
585}
586
587static Bool
588_XimDefaultArea(
589    XimValueOffsetInfo	 info,
590    XPointer	 	 top,
591    XPointer	 	 parm,
592    unsigned long	 mode)
593{
594    Xic			 ic = (Xic)parm;
595    Xim			 im = (Xim)ic->core.im;
596    Window		 root_return;
597    int			 x_return, y_return;
598    unsigned int	 width_return, height_return;
599    unsigned int	 border_width_return;
600    unsigned int	 depth_return;
601    XRectangle		 area;
602    XRectangle		*out;
603
604    if(ic->core.focus_window == (Window)NULL) {
605	return True;
606    }
607    if(XGetGeometry(im->core.display, (Drawable)ic->core.focus_window,
608		&root_return, &x_return, &y_return, &width_return,
609		&height_return, &border_width_return, &depth_return)
610		== (Status)Success) {
611	return True;
612    }
613    area.x	= 0;
614    area.y	= 0;
615    area.width	= width_return;
616    area.height	= height_return;
617
618    out = (XRectangle *)((char *)top + info->offset);
619    *out = area;
620    return True;
621}
622
623static Bool
624_XimDefaultColormap(
625    XimValueOffsetInfo	 info,
626    XPointer	 	 top,
627    XPointer	 	 parm,
628    unsigned long	 mode)
629{
630    Xic			 ic = (Xic)parm;
631    Xim			 im = (Xim)ic->core.im;
632    XWindowAttributes	 win_attr;
633    Colormap		*out;
634
635    if(ic->core.client_window == (Window)NULL) {
636	return True;
637    }
638    if(XGetWindowAttributes(im->core.display, ic->core.client_window,
639					&win_attr) == (Status)Success) {
640	return True;
641    }
642
643    out = (Colormap *)((char *)top + info->offset);
644    *out = win_attr.colormap;
645    return True;
646}
647
648static Bool
649_XimDefaultStdColormap(
650    XimValueOffsetInfo	 info,
651    XPointer	 	 top,
652    XPointer	 	 parm,
653    unsigned long	 mode)
654{
655    Atom		*out;
656
657    out = (Atom *)((char *)top + info->offset);
658    *out = (Atom)0;
659    return True;
660}
661
662static Bool
663_XimDefaultFg(
664    XimValueOffsetInfo	 info,
665    XPointer	 	 top,
666    XPointer	 	 parm,
667    unsigned long	 mode)
668{
669    Xic			 ic = (Xic)parm;
670    Xim			 im = (Xim)ic->core.im;
671    unsigned long	 fg;
672    unsigned long	*out;
673
674    fg = WhitePixel(im->core.display, DefaultScreen(im->core.display));
675    out = (unsigned long *)((char *)top + info->offset);
676    *out = fg;
677    return True;
678}
679
680static Bool
681_XimDefaultBg(
682    XimValueOffsetInfo	 info,
683    XPointer	 	 top,
684    XPointer	 	 parm,
685    unsigned long	 mode)
686{
687    Xic			 ic = (Xic)parm;
688    Xim			 im = (Xim)ic->core.im;
689    unsigned long	 bg;
690    unsigned long	*out;
691
692    bg = BlackPixel(im->core.display, DefaultScreen(im->core.display));
693    out = (unsigned long *)((char *)top + info->offset);
694    *out = bg;
695    return True;
696}
697
698static Bool
699_XimDefaultBgPixmap(
700    XimValueOffsetInfo	 info,
701    XPointer	 	 top,
702    XPointer	 	 parm,
703    unsigned long	 mode)
704{
705    Pixmap		*out;
706
707    out = (Pixmap *)((char *)top + info->offset);
708    *out = (Pixmap)0;
709    return True;
710}
711
712static Bool
713_XimDefaultFontSet(
714    XimValueOffsetInfo	 info,
715    XPointer	 	 top,
716    XPointer	 	 parm,
717    unsigned long	 mode)
718{
719    XFontSet		*out;
720
721    out = (XFontSet *)((char *)top + info->offset);
722    *out = 0;
723    return True;
724}
725
726static Bool
727_XimDefaultLineSpace(
728    XimValueOffsetInfo	 info,
729    XPointer	 	 top,
730    XPointer	 	 parm,
731    unsigned long	 mode)
732{
733    Xic			 ic = (Xic)parm;
734    XFontSet		 fontset;
735    XFontSetExtents	*fset_extents;
736    int			 line_space = 0;
737    int			*out;
738
739    if(mode & XIM_PREEDIT_ATTR) {
740	fontset = ic->core.preedit_attr.fontset;
741    } else if(mode & XIM_STATUS_ATTR) {
742	fontset = ic->core.status_attr.fontset;
743    } else {
744	return True;
745    }
746    if (fontset) {
747	fset_extents = XExtentsOfFontSet(fontset);
748	line_space = fset_extents->max_logical_extent.height;
749    }
750    out = (int *)((char *)top + info->offset);
751    *out = line_space;
752    return True;
753}
754
755static Bool
756_XimDefaultCursor(
757    XimValueOffsetInfo	 info,
758    XPointer	 	 top,
759    XPointer	 	 parm,
760    unsigned long	 mode)
761{
762    Cursor		*out;
763
764    out = (Cursor *)((char *)top + info->offset);
765    *out = (Cursor)0;
766    return True;
767}
768
769static Bool
770_XimDefaultPreeditState(
771    XimValueOffsetInfo	 info,
772    XPointer	 	 top,
773    XPointer	 	 parm,
774    unsigned long	 mode)
775{
776    XIMPreeditState	*out;
777
778    out = (XIMPreeditState *)((char *)top + info->offset);
779    *out = XIMPreeditDisable;
780    return True;
781}
782
783static Bool
784_XimDefaultNest(
785    XimValueOffsetInfo	 info,
786    XPointer	 	 top,
787    XPointer	 	 parm,
788    unsigned long	 mode)
789{
790    return True;
791}
792
793static Bool
794_XimEncodeCallback(
795    XimValueOffsetInfo	 info,
796    XPointer	 	 top,
797    XPointer	 	 val)
798{
799    XIMCallback		*out;
800
801    out = (XIMCallback *)((char *)top + info->offset);
802    *out = *((XIMCallback *)val);
803    return True;
804}
805
806static Bool
807_XimEncodeString(
808    XimValueOffsetInfo	  info,
809    XPointer	 	  top,
810    XPointer	 	  val)
811{
812    char		 *string;
813    char		**out;
814
815    if(val == (XPointer)NULL) {
816	return False;
817    }
818    if (!(string = strdup((char *)val))) {
819	return False;
820    }
821
822    out = (char **)((char *)top + info->offset);
823    if(*out) {
824	Xfree(*out);
825    }
826    *out = string;
827    return True;
828}
829
830static Bool
831_XimEncodeStyle(
832    XimValueOffsetInfo	 info,
833    XPointer	 	 top,
834    XPointer	 	 val)
835{
836    XIMStyle		*out;
837
838    out = (XIMStyle *)((char *)top + info->offset);
839    *out = (XIMStyle)val;
840    return True;
841}
842
843static Bool
844_XimEncodeWindow(
845    XimValueOffsetInfo	 info,
846    XPointer	 	 top,
847    XPointer	 	 val)
848{
849    Window		*out;
850
851    out = (Window *)((char *)top + info->offset);
852    *out = (Window)val;
853    return True;
854}
855
856static Bool
857_XimEncodeStringConv(
858    XimValueOffsetInfo		 info,
859    XPointer		 	 top,
860    XPointer		 	 val)
861{
862    /*
863     * Not yet
864     */
865    return True;
866}
867
868static Bool
869_XimEncodeResetState(
870    XimValueOffsetInfo	 info,
871    XPointer	 	 top,
872    XPointer	 	 val)
873{
874    XIMResetState	*out;
875
876    out = (XIMResetState *)((char *)top + info->offset);
877    *out = (XIMResetState)val;
878    return True;
879}
880
881static Bool
882_XimEncodeHotKey(
883    XimValueOffsetInfo	  info,
884    XPointer	 	  top,
885    XPointer	 	  val)
886{
887    XIMHotKeyTriggers	 *hotkey = (XIMHotKeyTriggers *)val;
888    XIMHotKeyTriggers	**out;
889    XIMHotKeyTriggers	 *key_list;
890    XIMHotKeyTrigger	 *key;
891    XPointer		  tmp;
892    int			  num;
893    int			  len;
894    register int	  i;
895
896    if(hotkey == (XIMHotKeyTriggers *)NULL) {
897	return True;
898    }
899
900    if((num = hotkey->num_hot_key) == 0) {
901	return True;
902    }
903
904    len = sizeof(XIMHotKeyTriggers) + sizeof(XIMHotKeyTrigger) * num;
905    if(!(tmp = Xmalloc(len))) {
906	return False;
907    }
908
909    key_list = (XIMHotKeyTriggers *)tmp;
910    key = (XIMHotKeyTrigger *)((char *)tmp + sizeof(XIMHotKeyTriggers));
911
912    for(i = 0; i < num; i++) {
913	key[i] = hotkey->key[i];
914    }
915
916    key_list->num_hot_key = num;
917    key_list->key = key;
918
919    out = (XIMHotKeyTriggers **)((char *)top + info->offset);
920    *out = key_list;
921    return True;
922}
923
924static Bool
925_XimEncodeHotKetState(
926    XimValueOffsetInfo	 info,
927    XPointer	 	 top,
928    XPointer	 	 val)
929{
930    XIMHotKeyState	*out;
931
932    out = (XIMHotKeyState *)((char *)top + info->offset);
933    *out = (XIMHotKeyState)val;
934    return True;
935}
936
937static Bool
938_XimEncodeRectangle(
939    XimValueOffsetInfo	 info,
940    XPointer	 	 top,
941    XPointer	 	 val)
942{
943    XRectangle		*out;
944
945    out = (XRectangle *)((char *)top + info->offset);
946    *out = *((XRectangle *)val);
947    return True;
948}
949
950static Bool
951_XimEncodeSpot(
952    XimValueOffsetInfo	 info,
953    XPointer	 	 top,
954    XPointer	 	 val)
955{
956    XPoint		*out;
957
958    out = (XPoint *)((char *)top + info->offset);
959    *out = *((XPoint *)val);
960    return True;
961}
962
963static Bool
964_XimEncodeColormap(
965    XimValueOffsetInfo	 info,
966    XPointer	 	 top,
967    XPointer	 	 val)
968{
969    Colormap		*out;
970
971    out = (Colormap *)((char *)top + info->offset);
972    *out = (Colormap)val;
973    return True;
974}
975
976static Bool
977_XimEncodeStdColormap(
978    XimValueOffsetInfo	 info,
979    XPointer	 	 top,
980    XPointer	 	 val)
981{
982    Atom		*out;
983
984    out = (Atom *)((char *)top + info->offset);
985    *out = (Atom)val;
986    return True;
987}
988
989static Bool
990_XimEncodeLong(
991    XimValueOffsetInfo	 info,
992    XPointer	 	 top,
993    XPointer	 	 val)
994{
995    unsigned long	*out;
996
997    out = (unsigned long *)((char *)top + info->offset);
998    *out = (unsigned long)val;
999    return True;
1000}
1001
1002static Bool
1003_XimEncodeBgPixmap(
1004    XimValueOffsetInfo	 info,
1005    XPointer	 	 top,
1006    XPointer	 	 val)
1007{
1008    Pixmap		*out;
1009
1010    out = (Pixmap *)((char *)top + info->offset);
1011    *out = (Pixmap)val;
1012    return True;
1013}
1014
1015static Bool
1016_XimEncodeFontSet(
1017    XimValueOffsetInfo	 info,
1018    XPointer	 	 top,
1019    XPointer	 	 val)
1020{
1021    XFontSet		*out;
1022
1023    out = (XFontSet *)((char *)top + info->offset);
1024    *out = (XFontSet)val;
1025    return True;
1026}
1027
1028static Bool
1029_XimEncodeLineSpace(
1030    XimValueOffsetInfo	 info,
1031    XPointer	 	 top,
1032    XPointer	 	 val)
1033{
1034    int			*out;
1035
1036    out = (int *)((char *)top + info->offset);
1037    *out = (long)val;
1038    return True;
1039}
1040
1041static Bool
1042_XimEncodeCursor(
1043    XimValueOffsetInfo	 info,
1044    XPointer	 	 top,
1045    XPointer	 	 val)
1046{
1047    Cursor		*out;
1048
1049    out = (Cursor *)((char *)top + info->offset);
1050    *out = (Cursor)val;
1051    return True;
1052}
1053
1054static Bool
1055_XimEncodePreeditState(
1056    XimValueOffsetInfo	 info,
1057    XPointer	 	 top,
1058    XPointer	 	 val)
1059{
1060    XIMPreeditState	*out;
1061
1062    out = (XIMPreeditState *)((char *)top + info->offset);
1063    *out = (XIMPreeditState)val;
1064    return True;
1065}
1066
1067static Bool
1068_XimEncodeNest(
1069    XimValueOffsetInfo	 info,
1070    XPointer	 	 top,
1071    XPointer	 	 val)
1072{
1073    return True;
1074}
1075
1076static Bool
1077_XimDecodeStyles(
1078    XimValueOffsetInfo	 info,
1079    XPointer	 	 top,
1080    XPointer	 	 val)
1081{
1082    XIMStyles		*styles;
1083    XIMStyles		*out;
1084    register int	 i;
1085    unsigned int	 num;
1086    int			 len;
1087    XPointer		 tmp;
1088
1089    if(val == (XPointer)NULL) {
1090	return False;
1091    }
1092
1093    styles = *((XIMStyles **)((char *)top + info->offset));
1094    num = styles->count_styles;
1095
1096    len = sizeof(XIMStyles) + sizeof(XIMStyle) * num;
1097    if(!(tmp = Xcalloc(1, len))) {
1098	return False;
1099    }
1100
1101    out = (XIMStyles *)tmp;
1102    if(num >0) {
1103	out->count_styles = (unsigned short)num;
1104	out->supported_styles = (XIMStyle *)((char *)tmp + sizeof(XIMStyles));
1105
1106	for(i = 0; i < num; i++) {
1107	    out->supported_styles[i] = styles->supported_styles[i];
1108	}
1109    }
1110    *((XIMStyles **)val) = out;
1111    return True;
1112}
1113
1114static Bool
1115_XimDecodeValues(
1116    XimValueOffsetInfo	 info,
1117    XPointer	 	 top,
1118    XPointer	 	 val)
1119{
1120    XIMValuesList	*values_list;
1121    XIMValuesList	*out;
1122    register int	 i;
1123    unsigned int	 num;
1124    int			 len;
1125    XPointer		 tmp;
1126
1127    if(val == (XPointer)NULL) {
1128	return False;
1129    }
1130
1131    values_list = *((XIMValuesList **)((char *)top + info->offset));
1132    num = values_list->count_values;
1133
1134    len = sizeof(XIMValuesList) + sizeof(char **) * num;
1135    if(!(tmp = Xcalloc(1, len))) {
1136	return False;
1137    }
1138
1139    out = (XIMValuesList *)tmp;
1140    if(num) {
1141	out->count_values = (unsigned short)num;
1142	out->supported_values = (char **)((char *)tmp + sizeof(XIMValuesList));
1143
1144	for(i = 0; i < num; i++) {
1145	    out->supported_values[i] = values_list->supported_values[i];
1146	}
1147    }
1148    *((XIMValuesList **)val) = out;
1149    return True;
1150}
1151
1152static Bool
1153_XimDecodeCallback(
1154    XimValueOffsetInfo	 info,
1155    XPointer	 	 top,
1156    XPointer	 	 val)
1157{
1158    XIMCallback		*in;
1159    XIMCallback		*callback;
1160
1161    in = (XIMCallback *)((char *)top + info->offset);
1162    if(!(callback = Xmalloc(sizeof(XIMCallback)))) {
1163	return False;
1164    }
1165    callback->client_data = in->client_data;
1166    callback->callback    = in->callback;
1167
1168    *((XIMCallback **)val) = callback;
1169    return True;
1170}
1171
1172static Bool
1173_XimDecodeString(
1174    XimValueOffsetInfo	 info,
1175    XPointer	 	 top,
1176    XPointer	 	 val)
1177{
1178    char		*in;
1179    char		*string;
1180
1181    in = *((char **)((char *)top + info->offset));
1182    if (in != NULL) {
1183	string = strdup(in);
1184    } else {
1185	string = Xcalloc(1, 1); /* strdup("") */
1186    }
1187    if (string == NULL) {
1188	return False;
1189    }
1190    *((char **)val) = string;
1191    return True;
1192}
1193
1194static Bool
1195_XimDecodeBool(
1196    XimValueOffsetInfo	 info,
1197    XPointer	 	 top,
1198    XPointer	 	 val)
1199{
1200    Bool		*in;
1201
1202    in = (Bool *)((char *)top + info->offset);
1203    *((Bool *)val) = *in;
1204    return True;
1205}
1206
1207static Bool
1208_XimDecodeStyle(
1209    XimValueOffsetInfo	 info,
1210    XPointer	 	 top,
1211    XPointer	 	 val)
1212{
1213    XIMStyle		*in;
1214
1215    in = (XIMStyle *)((char *)top + info->offset);
1216    *((XIMStyle *)val) = *in;
1217    return True;
1218}
1219
1220static Bool
1221_XimDecodeWindow(
1222    XimValueOffsetInfo	 info,
1223    XPointer	 	 top,
1224    XPointer	 	 val)
1225{
1226    Window		*in;
1227
1228    in = (Window *)((char *)top + info->offset);
1229    *((Window *)val) = *in;
1230    return True;
1231}
1232
1233static Bool
1234_XimDecodeStringConv(
1235    XimValueOffsetInfo	 info,
1236    XPointer	 	 top,
1237    XPointer	 	 val)
1238{
1239    /*
1240     * Not yet
1241     */
1242    return True;
1243}
1244
1245static Bool
1246_XimDecodeResetState(
1247    XimValueOffsetInfo	 info,
1248    XPointer	 	 top,
1249    XPointer	 	 val)
1250{
1251    XIMResetState	*in;
1252
1253    in = (XIMResetState *)((char *)top + info->offset);
1254    *((XIMResetState *)val) = *in;
1255    return True;
1256}
1257
1258static Bool
1259_XimDecodeHotKey(
1260    XimValueOffsetInfo	 info,
1261    XPointer	 	 top,
1262    XPointer	 	 val)
1263{
1264    XIMHotKeyTriggers	*in;
1265    XIMHotKeyTriggers	*hotkey;
1266    XIMHotKeyTrigger	*key;
1267    XPointer		 tmp;
1268    int			 num;
1269    int			 len;
1270    register int	 i;
1271
1272    in = *((XIMHotKeyTriggers **)((char *)top + info->offset));
1273    num = in->num_hot_key;
1274    len = sizeof(XIMHotKeyTriggers) + sizeof(XIMHotKeyTrigger) * num;
1275    if(!(tmp = Xmalloc(len))) {
1276	return False;
1277    }
1278
1279    hotkey = (XIMHotKeyTriggers *)tmp;
1280    key = (XIMHotKeyTrigger *)((char *)tmp + sizeof(XIMHotKeyTriggers));
1281
1282    for(i = 0; i < num; i++) {
1283	key[i] = in->key[i];
1284    }
1285    hotkey->num_hot_key = num;
1286    hotkey->key = key;
1287
1288    *((XIMHotKeyTriggers **)val) = hotkey;
1289    return True;
1290}
1291
1292static Bool
1293_XimDecodeHotKetState(
1294    XimValueOffsetInfo	 info,
1295    XPointer	 	 top,
1296    XPointer	 	 val)
1297{
1298    XIMHotKeyState	*in;
1299
1300    in = (XIMHotKeyState *)((char *)top + info->offset);
1301    *((XIMHotKeyState *)val) = *in;
1302    return True;
1303}
1304
1305static Bool
1306_XimDecodeRectangle(
1307    XimValueOffsetInfo	 info,
1308    XPointer	 	 top,
1309    XPointer	 	 val)
1310{
1311    XRectangle		*in;
1312    XRectangle		*rect;
1313
1314    in = (XRectangle *)((char *)top + info->offset);
1315    if(!(rect = Xmalloc(sizeof(XRectangle)))) {
1316	return False;
1317    }
1318    *rect = *in;
1319    *((XRectangle **)val) = rect;
1320    return True;
1321}
1322
1323static Bool
1324_XimDecodeSpot(
1325    XimValueOffsetInfo	 info,
1326    XPointer	 	 top,
1327    XPointer	 	 val)
1328{
1329    XPoint		*in;
1330    XPoint		*spot;
1331
1332    in = (XPoint *)((char *)top + info->offset);
1333    if(!(spot = Xmalloc(sizeof(XPoint)))) {
1334	return False;
1335    }
1336    *spot = *in;
1337    *((XPoint **)val) = spot;
1338    return True;
1339}
1340
1341static Bool
1342_XimDecodeColormap(
1343    XimValueOffsetInfo	 info,
1344    XPointer	 	 top,
1345    XPointer	 	 val)
1346{
1347    Colormap		*in;
1348
1349    in = (Colormap *)((char *)top + info->offset);
1350    *((Colormap *)val) = *in;
1351    return True;
1352}
1353
1354static Bool
1355_XimDecodeStdColormap(
1356    XimValueOffsetInfo	 info,
1357    XPointer	 	 top,
1358    XPointer	 	 val)
1359{
1360    Atom		*in;
1361
1362    in = (Atom *)((char *)top + info->offset);
1363    *((Atom *)val) = *in;
1364    return True;
1365}
1366
1367static Bool
1368_XimDecodeLong(
1369    XimValueOffsetInfo	 info,
1370    XPointer	 	 top,
1371    XPointer	 	 val)
1372{
1373    unsigned long	*in;
1374
1375    in = (unsigned long *)((char *)top + info->offset);
1376    *((unsigned long *)val) = *in;
1377    return True;
1378}
1379
1380static Bool
1381_XimDecodeBgPixmap(
1382    XimValueOffsetInfo	 info,
1383    XPointer	 	 top,
1384    XPointer	 	 val)
1385{
1386    Pixmap		*in;
1387
1388    in = (Pixmap *)((char *)top + info->offset);
1389    *((Pixmap *)val) = *in;
1390    return True;
1391}
1392
1393static Bool
1394_XimDecodeFontSet(
1395    XimValueOffsetInfo	 info,
1396    XPointer	 	 top,
1397    XPointer	 	 val)
1398{
1399    XFontSet		*in;
1400
1401    in = (XFontSet *)((char *)top + info->offset);
1402    *((XFontSet *)val) = *in;
1403    return True;
1404}
1405
1406static Bool
1407_XimDecodeLineSpace(
1408    XimValueOffsetInfo	 info,
1409    XPointer	 	 top,
1410    XPointer	 	 val)
1411{
1412    int		*in;
1413
1414    in = (int *)((char *)top + info->offset);
1415    *((int *)val) = *in;
1416    return True;
1417}
1418
1419static Bool
1420_XimDecodeCursor(
1421    XimValueOffsetInfo	 info,
1422    XPointer	 	 top,
1423    XPointer	 	 val)
1424{
1425    Cursor		*in;
1426
1427    in = (Cursor *)((char *)top + info->offset);
1428    *((Cursor *)val) = *in;
1429    return True;
1430}
1431
1432static Bool
1433_XimDecodePreeditState(
1434    XimValueOffsetInfo	 info,
1435    XPointer	 	 top,
1436    XPointer	 	 val)
1437{
1438    XIMPreeditState	*in;
1439
1440    in = (XIMPreeditState *)((char *)top + info->offset);
1441    *((XIMPreeditState *)val) = *in;
1442    return True;
1443}
1444
1445static Bool
1446_XimDecodeNest(
1447    XimValueOffsetInfo	 info,
1448    XPointer	 	 top,
1449    XPointer	 	 val)
1450{
1451    return True;
1452}
1453
1454static	XIMResource	im_resources[] = {
1455    {XNQueryInputStyle,		   0, XimType_XIMStyles,	0, 0, 0},
1456    {XNDestroyCallback,		   0,  0,			0, 0, 0},
1457    {XNResourceName,		   0, XimType_STRING8,		0, 0, 0},
1458    {XNResourceClass,		   0, XimType_STRING8,		0, 0, 0},
1459    {XNQueryIMValuesList,	   0, 0,			0, 0, 0},
1460    {XNQueryICValuesList,	   0, 0,			0, 0, 0},
1461    {XNVisiblePosition,		   0, 0,			0, 0, 0}
1462};
1463
1464static	XIMResource	im_inner_resources[] = {
1465    {XNDestroyCallback,		   0, 0,			0, 0, 0},
1466    {XNResourceName,		   0, XimType_STRING8,		0, 0, 0},
1467    {XNResourceClass,		   0, XimType_STRING8,		0, 0, 0},
1468    {XNQueryIMValuesList,	   0, 0,			0, 0, 0},
1469    {XNQueryICValuesList,	   0, 0,			0, 0, 0},
1470    {XNVisiblePosition,		   0, 0,			0, 0, 0}
1471};
1472
1473static	XIMResource	ic_resources[] = {
1474    {XNInputStyle,		   0, XimType_CARD32,		0, 0, 0},
1475    {XNClientWindow,		   0, XimType_Window,		0, 0, 0},
1476    {XNFocusWindow,		   0, XimType_Window,		0, 0, 0},
1477    {XNResourceName,		   0, XimType_STRING8,		0, 0, 0},
1478    {XNResourceClass,		   0, XimType_STRING8,		0, 0, 0},
1479    {XNGeometryCallback,	   0, 0,			0, 0, 0},
1480    {XNFilterEvents,		   0, XimType_CARD32,		0, 0, 0},
1481    {XNDestroyCallback,		   0, 0,			0, 0, 0},
1482    {XNStringConversionCallback,   0, 0,			0, 0, 0},
1483    {XNStringConversion,	   0, XimType_XIMStringConversion,0, 0, 0},
1484    {XNResetState,		   0, 0,			0, 0, 0},
1485    {XNHotKey,			   0, XimType_XIMHotKeyTriggers,0, 0, 0},
1486    {XNHotKeyState,		   0, XimType_XIMHotKeyState, 	0, 0, 0},
1487    {XNPreeditAttributes,	   0, XimType_NEST,		0, 0, 0},
1488    {XNStatusAttributes,	   0, XimType_NEST,		0, 0, 0},
1489    {XNArea,			   0, XimType_XRectangle,	0, 0, 0},
1490    {XNAreaNeeded,		   0, XimType_XRectangle,	0, 0, 0},
1491    {XNSpotLocation,		   0, XimType_XPoint,		0, 0, 0},
1492    {XNColormap,		   0, XimType_CARD32,		0, 0, 0},
1493    {XNStdColormap,		   0, XimType_CARD32,		0, 0, 0},
1494    {XNForeground,		   0, XimType_CARD32,		0, 0, 0},
1495    {XNBackground,		   0, XimType_CARD32,		0, 0, 0},
1496    {XNBackgroundPixmap,	   0, XimType_CARD32,		0, 0, 0},
1497    {XNFontSet,			   0, XimType_XFontSet,		0, 0, 0},
1498    {XNLineSpace,		   0, XimType_CARD32,		0, 0, 0},
1499    {XNCursor,			   0, XimType_CARD32,		0, 0, 0},
1500    {XNPreeditStartCallback,	   0, 0,			0, 0, 0},
1501    {XNPreeditDoneCallback,	   0, 0,			0, 0, 0},
1502    {XNPreeditDrawCallback,	   0, 0,			0, 0, 0},
1503    {XNPreeditCaretCallback,	   0, 0,			0, 0, 0},
1504    {XNStatusStartCallback,	   0, 0,			0, 0, 0},
1505    {XNStatusDoneCallback,	   0, 0,			0, 0, 0},
1506    {XNStatusDrawCallback,	   0, 0,			0, 0, 0},
1507    {XNPreeditState,		   0, 0,			0, 0, 0},
1508    {XNPreeditStateNotifyCallback, 0, 0,			0, 0, 0},
1509};
1510
1511static	XIMResource	ic_inner_resources[] = {
1512    {XNResourceName,		   0, XimType_STRING8,		0, 0, 0},
1513    {XNResourceClass,		   0, XimType_STRING8,		0, 0, 0},
1514    {XNGeometryCallback,	   0, 0,			0, 0, 0},
1515    {XNDestroyCallback,		   0, 0,			0, 0, 0},
1516    {XNStringConversionCallback,   0, 0,			0, 0, 0},
1517    {XNPreeditStartCallback,	   0, 0,			0, 0, 0},
1518    {XNPreeditDoneCallback,	   0, 0,			0, 0, 0},
1519    {XNPreeditDrawCallback,	   0, 0,			0, 0, 0},
1520    {XNPreeditCaretCallback,	   0, 0,			0, 0, 0},
1521    {XNStatusStartCallback,	   0, 0,			0, 0, 0},
1522    {XNStatusDoneCallback,	   0, 0,			0, 0, 0},
1523    {XNStatusDrawCallback,	   0, 0,			0, 0, 0},
1524    {XNPreeditStateNotifyCallback, 0, 0,			0, 0, 0},
1525};
1526
1527static XimValueOffsetInfoRec im_attr_info[] = {
1528    {OFFSET_XNQUERYINPUTSTYLE,		 0,
1529	XOffsetOf(XimDefIMValues, styles),
1530	_XimDefaultStyles,	 NULL,			_XimDecodeStyles},
1531
1532    {OFFSET_XNDESTROYCALLBACK,		 0,
1533	XOffsetOf(XimDefIMValues, destroy_callback),
1534	NULL,		 	 _XimEncodeCallback,	_XimDecodeCallback},
1535
1536    {OFFSET_XNRESOURCENAME,		 0,
1537	XOffsetOf(XimDefIMValues, res_name),
1538	NULL,		 	 _XimEncodeString,	_XimDecodeString},
1539
1540    {OFFSET_XNRESOURCECLASS,		 0,
1541	XOffsetOf(XimDefIMValues, res_class),
1542	NULL,		 	 _XimEncodeString,	_XimDecodeString},
1543
1544    {OFFSET_XNQUERYIMVALUESLIST,		 0,
1545	XOffsetOf(XimDefIMValues, im_values_list),
1546	_XimDefaultIMValues,	 NULL,			_XimDecodeValues},
1547
1548    {OFFSET_XNQUERYICVALUESLIST,		 0,
1549	XOffsetOf(XimDefIMValues, ic_values_list),
1550	_XimDefaultICValues,	 NULL,			_XimDecodeValues},
1551
1552    {OFFSET_XNVISIBLEPOSITION,			 0,
1553	XOffsetOf(XimDefIMValues, visible_position),
1554	_XimDefaultVisiblePos,	 NULL,			_XimDecodeBool}
1555};
1556
1557static XimValueOffsetInfoRec ic_attr_info[] = {
1558    {OFFSET_XNINPUTSTYLE,		 0,
1559	XOffsetOf(XimDefICValues, input_style),
1560	NULL,			 _XimEncodeStyle,	_XimDecodeStyle},
1561
1562    {OFFSET_XNCLIENTWINDOW,		 0,
1563	XOffsetOf(XimDefICValues, client_window),
1564	NULL,			 _XimEncodeWindow,	_XimDecodeWindow},
1565
1566    {OFFSET_XNFOCUSWINDOW,		 0,
1567	XOffsetOf(XimDefICValues, focus_window),
1568	_XimDefaultFocusWindow,  _XimEncodeWindow,	_XimDecodeWindow},
1569
1570    {OFFSET_XNRESOURCENAME,		 0,
1571	XOffsetOf(XimDefICValues, res_name),
1572	_XimDefaultResName,	 _XimEncodeString,	_XimDecodeString},
1573
1574    {OFFSET_XNRESOURCECLASS,		 0,
1575	XOffsetOf(XimDefICValues, res_class),
1576	_XimDefaultResClass,	 _XimEncodeString,	_XimDecodeString},
1577
1578    {OFFSET_XNGEOMETRYCALLBACK,	 0,
1579	XOffsetOf(XimDefICValues, geometry_callback),
1580	NULL,			 _XimEncodeCallback,	_XimDecodeCallback},
1581
1582    {OFFSET_XNFILTEREVENTS,		 0,
1583	XOffsetOf(XimDefICValues, filter_events),
1584	NULL,			 NULL,			_XimDecodeLong},
1585
1586    {OFFSET_XNDESTROYCALLBACK,		 0,
1587	XOffsetOf(XimDefICValues, destroy_callback),
1588	_XimDefaultDestroyCB,	 _XimEncodeCallback,	_XimDecodeCallback},
1589
1590    {OFFSET_XNSTRINGCONVERSIONCALLBACK, 0,
1591	XOffsetOf(XimDefICValues, string_conversion_callback),
1592	NULL,			 _XimEncodeCallback,	_XimDecodeCallback},
1593
1594    {OFFSET_XNSTRINGCONVERSION,	 0,
1595	XOffsetOf(XimDefICValues, string_conversion),
1596	NULL,			 _XimEncodeStringConv,	_XimDecodeStringConv},
1597
1598    {OFFSET_XNRESETSTATE,		 0,
1599	XOffsetOf(XimDefICValues, reset_state),
1600	_XimDefaultResetState,	 _XimEncodeResetState,	_XimDecodeResetState},
1601
1602    {OFFSET_XNHOTKEY,			 0,
1603	XOffsetOf(XimDefICValues, hotkey),
1604	NULL,			 _XimEncodeHotKey,	_XimDecodeHotKey},
1605
1606    {OFFSET_XNHOTKEYSTATE,		 0,
1607	XOffsetOf(XimDefICValues, hotkey_state),
1608	_XimDefaultHotKeyState,	 _XimEncodeHotKetState,	_XimDecodeHotKetState},
1609
1610    {OFFSET_XNPREEDITATTRIBUTES,	 0,
1611	XOffsetOf(XimDefICValues, preedit_attr),
1612	_XimDefaultNest,	 _XimEncodeNest,	_XimDecodeNest},
1613
1614    {OFFSET_XNSTATUSATTRIBUTES,	 0,
1615	XOffsetOf(XimDefICValues, status_attr),
1616	_XimDefaultNest,	 _XimEncodeNest,	_XimDecodeNest},
1617};
1618
1619static XimValueOffsetInfoRec ic_pre_attr_info[] = {
1620    {OFFSET_XNAREA,			 0,
1621	XOffsetOf(ICPreeditAttributes, area),
1622	_XimDefaultArea,	 _XimEncodeRectangle,	_XimDecodeRectangle},
1623
1624    {OFFSET_XNAREANEEDED,		 0,
1625	XOffsetOf(ICPreeditAttributes, area_needed),
1626	NULL,			 _XimEncodeRectangle,	_XimDecodeRectangle},
1627
1628    {OFFSET_XNSPOTLOCATION,		 0,
1629	XOffsetOf(ICPreeditAttributes, spot_location),
1630	NULL,			 _XimEncodeSpot,	_XimDecodeSpot},
1631
1632    {OFFSET_XNCOLORMAP,		 0,
1633	XOffsetOf(ICPreeditAttributes, colormap),
1634	_XimDefaultColormap,	 _XimEncodeColormap,	_XimDecodeColormap},
1635
1636    {OFFSET_XNSTDCOLORMAP,		 0,
1637	XOffsetOf(ICPreeditAttributes, std_colormap),
1638	_XimDefaultStdColormap,	 _XimEncodeStdColormap,	_XimDecodeStdColormap},
1639
1640    {OFFSET_XNFOREGROUND,		 0,
1641	XOffsetOf(ICPreeditAttributes, foreground),
1642	_XimDefaultFg,		 _XimEncodeLong,	_XimDecodeLong},
1643
1644    {OFFSET_XNBACKGROUND,		 0,
1645	XOffsetOf(ICPreeditAttributes, background),
1646	_XimDefaultBg,		 _XimEncodeLong,	_XimDecodeLong},
1647
1648    {OFFSET_XNBACKGROUNDPIXMAP,	 0,
1649	XOffsetOf(ICPreeditAttributes, background_pixmap),
1650	_XimDefaultBgPixmap, 	 _XimEncodeBgPixmap,	_XimDecodeBgPixmap},
1651
1652    {OFFSET_XNFONTSET,			 0,
1653	XOffsetOf(ICPreeditAttributes, fontset),
1654	_XimDefaultFontSet,	 _XimEncodeFontSet,	_XimDecodeFontSet},
1655
1656    {OFFSET_XNLINESPACE,		 0,
1657	XOffsetOf(ICPreeditAttributes, line_spacing),
1658	_XimDefaultLineSpace,	 _XimEncodeLineSpace,	_XimDecodeLineSpace},
1659
1660    {OFFSET_XNCURSOR,			 0,
1661	XOffsetOf(ICPreeditAttributes, cursor),
1662	_XimDefaultCursor,	 _XimEncodeCursor,	_XimDecodeCursor},
1663
1664    {OFFSET_XNPREEDITSTARTCALLBACK,	 0,
1665	XOffsetOf(ICPreeditAttributes, start_callback),
1666	NULL,			 _XimEncodeCallback,	_XimDecodeCallback},
1667
1668    {OFFSET_XNPREEDITDONECALLBACK,	 0,
1669	XOffsetOf(ICPreeditAttributes, done_callback),
1670	NULL,			 _XimEncodeCallback,	_XimDecodeCallback},
1671
1672    {OFFSET_XNPREEDITDRAWCALLBACK,	 0,
1673	XOffsetOf(ICPreeditAttributes, draw_callback),
1674	NULL,			 _XimEncodeCallback,	_XimDecodeCallback},
1675
1676    {OFFSET_XNPREEDITCARETCALLBACK,	 0,
1677	XOffsetOf(ICPreeditAttributes, caret_callback),
1678	NULL,			 _XimEncodeCallback,	_XimDecodeCallback},
1679
1680    {OFFSET_XNPREEDITSTATE,		 0,
1681	XOffsetOf(ICPreeditAttributes, preedit_state),
1682	_XimDefaultPreeditState, _XimEncodePreeditState,_XimDecodePreeditState},
1683
1684    {OFFSET_XNPREEDITSTATENOTIFYCALLBACK, 0,
1685	XOffsetOf(ICPreeditAttributes, state_notify_callback),
1686	NULL,			 _XimEncodeCallback,	_XimDecodeCallback},
1687};
1688
1689static XimValueOffsetInfoRec ic_sts_attr_info[] = {
1690    {OFFSET_XNAREA,			 0,
1691	XOffsetOf(ICStatusAttributes, area),
1692	_XimDefaultArea,	 _XimEncodeRectangle,	_XimDecodeRectangle},
1693
1694    {OFFSET_XNAREANEEDED,		 0,
1695	XOffsetOf(ICStatusAttributes, area_needed),
1696	NULL,			 _XimEncodeRectangle,	_XimDecodeRectangle},
1697
1698    {OFFSET_XNCOLORMAP,		 0,
1699	XOffsetOf(ICStatusAttributes, colormap),
1700	_XimDefaultColormap,	 _XimEncodeColormap,	_XimDecodeColormap},
1701
1702    {OFFSET_XNSTDCOLORMAP,		 0,
1703	XOffsetOf(ICStatusAttributes, std_colormap),
1704	_XimDefaultStdColormap,	 _XimEncodeStdColormap,	_XimDecodeStdColormap},
1705
1706    {OFFSET_XNFOREGROUND,		 0,
1707	XOffsetOf(ICStatusAttributes, foreground),
1708	_XimDefaultFg,		 _XimEncodeLong,	_XimDecodeLong},
1709
1710    {OFFSET_XNBACKGROUND,		 0,
1711	XOffsetOf(ICStatusAttributes, background),
1712	_XimDefaultBg,		 _XimEncodeLong,	_XimDecodeLong},
1713
1714    {OFFSET_XNBACKGROUNDPIXMAP,	 0,
1715	XOffsetOf(ICStatusAttributes, background_pixmap),
1716	_XimDefaultBgPixmap, 	 _XimEncodeBgPixmap,	_XimDecodeBgPixmap},
1717
1718    {OFFSET_XNFONTSET,			 0,
1719	XOffsetOf(ICStatusAttributes, fontset),
1720	_XimDefaultFontSet,	 _XimEncodeFontSet,	_XimDecodeFontSet},
1721
1722    {OFFSET_XNLINESPACE,		 0,
1723	XOffsetOf(ICStatusAttributes, line_spacing),
1724	_XimDefaultLineSpace,	 _XimEncodeLineSpace,	_XimDecodeLineSpace},
1725
1726    {OFFSET_XNCURSOR,			 0,
1727	XOffsetOf(ICStatusAttributes, cursor),
1728	_XimDefaultCursor,	 _XimEncodeCursor,	_XimDecodeCursor},
1729
1730    {OFFSET_XNSTATUSSTARTCALLBACK,	 0,
1731	XOffsetOf(ICStatusAttributes, start_callback),
1732	NULL,			 _XimEncodeCallback,	_XimDecodeCallback},
1733
1734    {OFFSET_XNSTATUSDONECALLBACK,	 0,
1735	XOffsetOf(ICStatusAttributes, done_callback),
1736	NULL,			 _XimEncodeCallback,	_XimDecodeCallback},
1737
1738    {OFFSET_XNSTATUSDRAWCALLBACK,	 0,
1739	XOffsetOf(ICStatusAttributes, draw_callback),
1740	NULL,			 _XimEncodeCallback,	_XimDecodeCallback}
1741};
1742
1743typedef struct _XimIMMode {
1744    unsigned short name_offset;
1745    unsigned short	 mode;
1746} XimIMMode;
1747
1748static const XimIMMode im_mode[] = {
1749    {OFFSET_XNQUERYINPUTSTYLE,
1750		(XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)},
1751    {OFFSET_XNDESTROYCALLBACK,
1752		(XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)},
1753    {OFFSET_XNRESOURCENAME,
1754		(XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)},
1755    {OFFSET_XNRESOURCECLASS,
1756		(XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)},
1757    {OFFSET_XNQUERYIMVALUESLIST,
1758		(XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)},
1759    {OFFSET_XNQUERYICVALUESLIST,
1760		(XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)},
1761    {OFFSET_XNVISIBLEPOSITION,
1762		(XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)}
1763};
1764
1765typedef struct _XimICMode {
1766    unsigned short name_offset;
1767    unsigned short	 preedit_callback_mode;
1768    unsigned short	 preedit_position_mode;
1769    unsigned short	 preedit_area_mode;
1770    unsigned short	 preedit_nothing_mode;
1771    unsigned short	 preedit_none_mode;
1772    unsigned short	 status_callback_mode;
1773    unsigned short	 status_area_mode;
1774    unsigned short	 status_nothing_mode;
1775    unsigned short	 status_none_mode;
1776} XimICMode;
1777
1778static const XimICMode ic_mode[] = {
1779    {OFFSET_XNINPUTSTYLE,
1780		(XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
1781		(XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
1782		(XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
1783		(XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
1784		(XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET),
1785		(XIM_MODE_STS_CREATE | XIM_MODE_STS_GET),
1786		(XIM_MODE_STS_CREATE | XIM_MODE_STS_GET),
1787		(XIM_MODE_STS_CREATE | XIM_MODE_STS_GET),
1788		(XIM_MODE_STS_CREATE | XIM_MODE_STS_GET)},
1789    {OFFSET_XNCLIENTWINDOW,
1790		(XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
1791		(XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
1792		(XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
1793		(XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET),
1794		0,
1795		(XIM_MODE_STS_ONCE | XIM_MODE_STS_GET),
1796		(XIM_MODE_STS_ONCE | XIM_MODE_STS_GET),
1797		(XIM_MODE_STS_ONCE | XIM_MODE_STS_GET),
1798		0},
1799    {OFFSET_XNFOCUSWINDOW,
1800		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1801		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1802		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1803		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1804		0,
1805		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1806		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1807		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1808		0},
1809    {OFFSET_XNRESOURCENAME,
1810		0,
1811		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1812		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1813		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1814		0,
1815		0,
1816		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1817		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1818		0},
1819    {OFFSET_XNRESOURCECLASS,
1820		0,
1821		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1822		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1823		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1824		0,
1825		0,
1826		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1827		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1828		0},
1829    {OFFSET_XNGEOMETRYCALLBACK,
1830		0,
1831		0,
1832		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1833		0,
1834		0,
1835		0,
1836		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1837		0,
1838		0},
1839    {OFFSET_XNFILTEREVENTS,
1840		XIM_MODE_PRE_GET,
1841		XIM_MODE_PRE_GET,
1842		XIM_MODE_PRE_GET,
1843		XIM_MODE_PRE_GET,
1844		0,
1845		XIM_MODE_STS_GET,
1846		XIM_MODE_STS_GET,
1847		XIM_MODE_STS_GET,
1848		XIM_MODE_STS_GET},
1849    {OFFSET_XNDESTROYCALLBACK,
1850		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1851		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1852		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1853		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1854		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1855		0,
1856		0,
1857		0,
1858		0},
1859    {OFFSET_XNSTRINGCONVERSIONCALLBACK,
1860		(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1861		(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1862		(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1863		(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1864		(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1865		0,
1866		0,
1867		0,
1868		0},
1869    {OFFSET_XNSTRINGCONVERSION,
1870		XIM_MODE_PRE_SET,
1871		XIM_MODE_PRE_SET,
1872		XIM_MODE_PRE_SET,
1873		XIM_MODE_PRE_SET,
1874		XIM_MODE_PRE_SET,
1875		0,
1876		0,
1877		0,
1878		0},
1879    {OFFSET_XNRESETSTATE,
1880		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1881		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1882		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1883		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1884		0,
1885		0,
1886		0,
1887		0,
1888		0},
1889    {OFFSET_XNHOTKEY,
1890		(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1891		(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1892		(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1893		(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1894		0,
1895		0,
1896		0,
1897		0,
1898		0},
1899    {OFFSET_XNHOTKEYSTATE,
1900		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1901		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1902		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1903		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1904		0,
1905		0,
1906		0,
1907		0,
1908		0},
1909    {OFFSET_XNPREEDITATTRIBUTES,
1910		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1911		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1912		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1913		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1914		0,
1915		0,
1916		0,
1917		0,
1918		0},
1919    {OFFSET_XNSTATUSATTRIBUTES,
1920		0,
1921		0,
1922		0,
1923		0,
1924		0,
1925		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1926		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1927		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1928		0},
1929    {OFFSET_XNAREA,
1930		0,
1931		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1932		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1933		0,
1934		0,
1935		0,
1936		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1937		0,
1938		0},
1939    {OFFSET_XNAREANEEDED,
1940		0,
1941		0,
1942		(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1943		0,
1944		0,
1945		0,
1946		(XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1947		0,
1948		0},
1949    {OFFSET_XNSPOTLOCATION,
1950		0, /*(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),*/
1951		(XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1952		0,
1953		(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1954		(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1955		0,
1956		0,
1957		0,
1958		0},
1959    {OFFSET_XNCOLORMAP,
1960		0,
1961		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1962		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1963		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1964		0,
1965		0,
1966		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1967		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1968		0},
1969    {OFFSET_XNSTDCOLORMAP,
1970		0,
1971		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1972		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1973		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1974		0,
1975		0,
1976		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1977		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1978		0},
1979    {OFFSET_XNFOREGROUND,
1980		0,
1981		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1982		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1983		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1984		0,
1985		0,
1986		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1987		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1988		0},
1989    {OFFSET_XNBACKGROUND,
1990		0,
1991		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1992		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1993		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
1994		0,
1995		0,
1996		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1997		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
1998		0},
1999    {OFFSET_XNBACKGROUNDPIXMAP,
2000		0,
2001		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2002		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2003		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2004		0,
2005		0,
2006		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
2007		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
2008		0},
2009    {OFFSET_XNFONTSET,
2010		0,
2011		(XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2012		(XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2013		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2014		0,
2015		0,
2016		(XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
2017		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
2018		0},
2019    {OFFSET_XNLINESPACE,
2020		0,
2021		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2022		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2023		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2024		0,
2025		0,
2026		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
2027		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
2028		0},
2029    {OFFSET_XNCURSOR,
2030		0,
2031		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2032		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2033		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2034		0,
2035		0,
2036		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
2037		(XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
2038		0},
2039    {OFFSET_XNPREEDITSTARTCALLBACK,
2040		(XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2041		0,
2042		0,
2043		0,
2044		0,
2045		0,
2046		0,
2047		0,
2048		0},
2049    {OFFSET_XNPREEDITDONECALLBACK,
2050		(XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2051		0,
2052		0,
2053		0,
2054		0,
2055		0,
2056		0,
2057		0,
2058		0},
2059    {OFFSET_XNPREEDITDRAWCALLBACK,
2060		(XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2061		0,
2062		0,
2063		0,
2064		0,
2065		0,
2066		0,
2067		0,
2068		0},
2069    {OFFSET_XNPREEDITCARETCALLBACK,
2070		(XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2071		0,
2072		0,
2073		0,
2074		0,
2075		0,
2076		0,
2077		0,
2078		0},
2079    {OFFSET_XNPREEDITSTATE,
2080		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2081		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2082		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2083		(XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2084		0,
2085		0,
2086		0,
2087		0,
2088		0},
2089    {OFFSET_XNPREEDITSTATENOTIFYCALLBACK,
2090		(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2091		(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2092		(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2093		(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),
2094		0,
2095		0,
2096		0,
2097		0,
2098		0},
2099    {OFFSET_XNSTATUSSTARTCALLBACK,
2100		0,
2101		0,
2102		0,
2103		0,
2104		0,
2105		(XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
2106		0,
2107		0,
2108		0},
2109    {OFFSET_XNSTATUSDONECALLBACK,
2110		0,
2111		0,
2112		0,
2113		0,
2114		0,
2115		(XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
2116		0,
2117		0,
2118		0},
2119    {OFFSET_XNSTATUSDRAWCALLBACK,
2120		0,
2121		0,
2122		0,
2123		0,
2124		0,
2125		(XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET),
2126		0,
2127		0,
2128		0}
2129};
2130
2131/* the quarks are separated from im_mode/ic_mode so those arrays
2132 * can be const.
2133 */
2134static XrmQuark im_mode_quark[sizeof(im_mode) / sizeof(im_mode[0])];
2135static XrmQuark ic_mode_quark[sizeof(ic_mode) / sizeof(ic_mode[0])];
2136
2137static Bool
2138_XimSetResourceList(
2139    XIMResourceList	 *res_list,
2140    unsigned int	 *list_num,
2141    XIMResourceList	  resource,
2142    unsigned int	  num_resource,
2143    unsigned short	  id)
2144{
2145    register int	  i;
2146    int			  len;
2147    XIMResourceList	  res;
2148
2149    len = sizeof(XIMResource) * num_resource;
2150    if(!(res = Xcalloc(1, len))) {
2151	return False;
2152    }
2153
2154    for(i = 0; i < num_resource; i++, id++) {
2155	res[i]    = resource[i];
2156	res[i].id = id;
2157    }
2158
2159    _XIMCompileResourceList(res, num_resource);
2160    *res_list  = res;
2161    *list_num  = num_resource;
2162    return True;
2163}
2164
2165Bool
2166_XimSetIMResourceList(
2167    XIMResourceList	*res_list,
2168    unsigned int	*list_num)
2169{
2170    return _XimSetResourceList(res_list, list_num,
2171				im_resources, XIMNumber(im_resources), 100);
2172}
2173
2174Bool
2175_XimSetICResourceList(
2176    XIMResourceList	*res_list,
2177    unsigned int	*list_num)
2178{
2179    return _XimSetResourceList(res_list, list_num,
2180				ic_resources, XIMNumber(ic_resources), 200);
2181}
2182
2183Bool
2184_XimSetInnerIMResourceList(
2185    XIMResourceList	*res_list,
2186    unsigned int	*list_num)
2187{
2188    return _XimSetResourceList(res_list, list_num,
2189		im_inner_resources, XIMNumber(im_inner_resources), 100);
2190}
2191
2192Bool
2193_XimSetInnerICResourceList(
2194    XIMResourceList	*res_list,
2195    unsigned int	*list_num)
2196{
2197    return _XimSetResourceList(res_list, list_num,
2198		ic_inner_resources, XIMNumber(ic_inner_resources), 200);
2199}
2200
2201static XIMResourceList
2202_XimGetResourceListRecByMode(
2203    XIMResourceList	 res_list,
2204    unsigned int	 list_num,
2205    unsigned short	 mode)
2206{
2207    register int	 i;
2208
2209    for(i = 0; i < list_num; i++) {
2210	if (res_list[i].mode & mode) {
2211	    return (XIMResourceList)&res_list[i];
2212	}
2213    }
2214    return (XIMResourceList)NULL;
2215}
2216
2217Bool
2218_XimCheckCreateICValues(
2219    XIMResourceList	 res_list,
2220    unsigned int	 list_num)
2221{
2222    if (!_XimGetResourceListRecByMode(res_list, list_num, XIM_MODE_IC_CREATE)) {
2223	return True;
2224    }
2225    return False;
2226}
2227
2228XIMResourceList
2229_XimGetResourceListRecByQuark(
2230    XIMResourceList	 res_list,
2231    unsigned int	 list_num,
2232    XrmQuark		 quark)
2233{
2234    register int	 i;
2235
2236    for(i = 0; i < list_num; i++) {
2237	if (res_list[i].xrm_name == quark) {
2238	    return (XIMResourceList)&res_list[i];
2239	}
2240    }
2241    return (XIMResourceList)NULL;
2242}
2243
2244XIMResourceList
2245_XimGetResourceListRec(
2246    XIMResourceList	 res_list,
2247    unsigned int	 list_num,
2248    const char		*name)
2249{
2250    XrmQuark		 quark = XrmStringToQuark(name);
2251
2252    return _XimGetResourceListRecByQuark(res_list, list_num, quark);
2253}
2254
2255char *
2256_XimSetIMValueData(
2257    Xim			 im,
2258    XPointer		 top,
2259    XIMArg		*values,
2260    XIMResourceList	 res_list,
2261    unsigned int	 list_num)
2262{
2263    register XIMArg	*p;
2264    XIMResourceList	 res;
2265    int			 check;
2266
2267    for(p = values; p->name != NULL; p++) {
2268	if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) {
2269	    return p->name;
2270	}
2271	check = _XimCheckIMMode(res, XIM_SETIMVALUES);
2272	if(check == XIM_CHECK_INVALID) {
2273	    continue;
2274	} else if (check == XIM_CHECK_ERROR) {
2275	    return p->name;
2276	}
2277
2278	if(!_XimEncodeLocalIMAttr(res, top, p->value)) {
2279	    return p->name;
2280	}
2281    }
2282    return NULL;
2283}
2284
2285char *
2286_XimGetIMValueData(
2287    Xim			 im,
2288    XPointer		 top,
2289    XIMArg		*values,
2290    XIMResourceList	 res_list,
2291    unsigned int	 list_num)
2292{
2293    register XIMArg	*p;
2294    XIMResourceList	 res;
2295    int			 check;
2296
2297    for(p = values; p->name != NULL; p++) {
2298	if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) {
2299	    return p->name;
2300	}
2301	check = _XimCheckIMMode(res, XIM_GETIMVALUES);
2302	if(check == XIM_CHECK_INVALID) {
2303	    continue;
2304	} else if (check == XIM_CHECK_ERROR) {
2305	    return p->name;
2306	}
2307
2308	if(!_XimDecodeLocalIMAttr(res, top, p->value)) {
2309	    return p->name;
2310	}
2311    }
2312    return NULL;
2313}
2314
2315void
2316_XimSetIMMode(
2317    XIMResourceList	res_list,
2318    unsigned int	list_num)
2319{
2320    XIMResourceList	res;
2321    unsigned int	n = XIMNumber(im_mode);
2322    register int	i;
2323
2324    for(i = 0; i < n; i++) {
2325	if(!(res = _XimGetResourceListRecByQuark(res_list,
2326						list_num, im_mode_quark[i]))) {
2327	    continue;
2328	}
2329	res->mode = im_mode[i].mode;
2330    }
2331    return;
2332}
2333
2334static int
2335_XimCheckSetIMDefaultsMode(
2336    XIMResourceList	res)
2337{
2338    if(res->mode & XIM_MODE_IM_DEFAULT) {
2339	return XIM_CHECK_VALID;
2340    }
2341    return XIM_CHECK_INVALID;
2342}
2343
2344static int
2345_XimCheckSetIMValuesMode(
2346    XIMResourceList	res)
2347{
2348    if(res->mode & XIM_MODE_IM_SET) {
2349	return XIM_CHECK_VALID;
2350    }
2351    return XIM_CHECK_INVALID;
2352}
2353
2354static int
2355 _XimCheckGetIMValuesMode(
2356    XIMResourceList	res)
2357{
2358    if(res->mode & XIM_MODE_IM_GET) {
2359	return XIM_CHECK_VALID;
2360    }
2361    return XIM_CHECK_INVALID;
2362}
2363
2364int
2365 _XimCheckIMMode(
2366    XIMResourceList	res,
2367    unsigned long	mode)
2368{
2369    if(res->mode == 0) {
2370	return XIM_CHECK_INVALID;
2371    }
2372    if(mode & XIM_SETIMDEFAULTS) {
2373	return _XimCheckSetIMDefaultsMode(res);
2374    } else if (mode & XIM_SETIMVALUES) {
2375	return _XimCheckSetIMValuesMode(res);
2376    } else if (mode & XIM_GETIMVALUES) {
2377	return _XimCheckGetIMValuesMode(res);
2378    } else {
2379	return XIM_CHECK_ERROR;
2380    }
2381}
2382
2383void
2384_XimSetICMode(XIMResourceList res_list, unsigned int list_num, XIMStyle style)
2385{
2386    XIMResourceList	res;
2387    unsigned int	n = XIMNumber(ic_mode);
2388    register int	i;
2389    unsigned int	pre_offset;
2390    unsigned int	sts_offset;
2391
2392    if(style & XIMPreeditArea) {
2393	pre_offset = XOffsetOf(XimICMode, preedit_area_mode);
2394    } else if(style & XIMPreeditCallbacks) {
2395	pre_offset = XOffsetOf(XimICMode, preedit_callback_mode);
2396    } else if(style & XIMPreeditPosition) {
2397	pre_offset = XOffsetOf(XimICMode, preedit_position_mode);
2398    } else if(style & XIMPreeditNothing) {
2399	pre_offset = XOffsetOf(XimICMode, preedit_nothing_mode);
2400    } else {
2401	pre_offset = XOffsetOf(XimICMode, preedit_none_mode);
2402    }
2403
2404    if(style & XIMStatusArea) {
2405	sts_offset = XOffsetOf(XimICMode, status_area_mode);
2406    } else if(style & XIMStatusCallbacks) {
2407	sts_offset = XOffsetOf(XimICMode, status_callback_mode);
2408    } else if(style & XIMStatusNothing) {
2409	sts_offset = XOffsetOf(XimICMode, status_nothing_mode);
2410    } else {
2411	sts_offset = XOffsetOf(XimICMode, status_none_mode);
2412    }
2413
2414    for(i = 0; i < n; i++) {
2415	if(!(res = _XimGetResourceListRecByQuark(res_list,
2416						list_num, ic_mode_quark[i]))) {
2417	    continue;
2418	}
2419	res->mode = ( (*(const unsigned short *)((const char *)&ic_mode[i] + pre_offset))
2420		    | (*(const unsigned short *)((const char *)&ic_mode[i] + sts_offset)));
2421    }
2422    return;
2423}
2424
2425static int
2426_XimCheckSetICDefaultsMode(
2427    XIMResourceList	res,
2428    unsigned long	mode)
2429{
2430    if(mode & XIM_PREEDIT_ATTR) {
2431	if(!(res->mode & XIM_MODE_PRE_MASK)) {
2432	    return XIM_CHECK_INVALID;
2433	}
2434
2435	if(res->mode & XIM_MODE_PRE_CREATE) {
2436	    return XIM_CHECK_ERROR;
2437	} else if (!(res->mode & XIM_MODE_PRE_DEFAULT)) {
2438	    return XIM_CHECK_INVALID;
2439	}
2440
2441    } else if(mode & XIM_STATUS_ATTR) {
2442	if(!(res->mode & XIM_MODE_STS_MASK)) {
2443	    return XIM_CHECK_INVALID;
2444	}
2445
2446	if(res->mode & XIM_MODE_STS_CREATE) {
2447	    return XIM_CHECK_ERROR;
2448	}
2449	if(!(res->mode & XIM_MODE_STS_DEFAULT)) {
2450	    return XIM_CHECK_INVALID;
2451	}
2452
2453    } else {
2454	if(!res->mode) {
2455	    return XIM_CHECK_INVALID;
2456	}
2457
2458	if(res->mode & XIM_MODE_IC_CREATE) {
2459	    return XIM_CHECK_ERROR;
2460	}
2461	if(!(res->mode & XIM_MODE_IC_DEFAULT)) {
2462	    return XIM_CHECK_INVALID;
2463	}
2464    }
2465    return XIM_CHECK_VALID;
2466}
2467
2468static int
2469_XimCheckCreateICMode(
2470    XIMResourceList	res,
2471    unsigned long	mode)
2472{
2473    if(mode & XIM_PREEDIT_ATTR) {
2474	if(!(res->mode & XIM_MODE_PRE_MASK)) {
2475	    return XIM_CHECK_INVALID;
2476	}
2477
2478	if(res->mode & XIM_MODE_PRE_CREATE) {
2479	    res->mode &= ~XIM_MODE_PRE_CREATE;
2480	} else if(res->mode & XIM_MODE_PRE_ONCE) {
2481	    res->mode &= ~XIM_MODE_PRE_ONCE;
2482	} else if(res->mode & XIM_MODE_PRE_DEFAULT) {
2483	    res->mode &= ~XIM_MODE_PRE_DEFAULT;
2484	} else if (!(res->mode & XIM_MODE_PRE_SET)) {
2485	    return XIM_CHECK_ERROR;
2486	}
2487
2488    } else if(mode & XIM_STATUS_ATTR) {
2489	if(!(res->mode & XIM_MODE_STS_MASK)) {
2490	    return  XIM_CHECK_INVALID;
2491	}
2492
2493	if(res->mode & XIM_MODE_STS_CREATE) {
2494	    res->mode &= ~XIM_MODE_STS_CREATE;
2495	} else if(res->mode & XIM_MODE_STS_ONCE) {
2496	    res->mode &= ~XIM_MODE_STS_ONCE;
2497	} else if(res->mode & XIM_MODE_STS_DEFAULT) {
2498	    res->mode &= ~XIM_MODE_STS_DEFAULT;
2499	} else if (!(res->mode & XIM_MODE_STS_SET)) {
2500	    return XIM_CHECK_ERROR;
2501	}
2502
2503    } else {
2504	if(!res->mode) {
2505	    return XIM_CHECK_INVALID;
2506	}
2507
2508	if(res->mode & XIM_MODE_IC_CREATE) {
2509	    res->mode &= ~XIM_MODE_IC_CREATE;
2510	} else if(res->mode & XIM_MODE_IC_ONCE) {
2511	    res->mode &= ~XIM_MODE_IC_ONCE;
2512	} else if(res->mode & XIM_MODE_IC_DEFAULT) {
2513	    res->mode &= ~XIM_MODE_IC_DEFAULT;
2514	} else if (!(res->mode & XIM_MODE_IC_SET)) {
2515	    return XIM_CHECK_ERROR;
2516	}
2517    }
2518    return XIM_CHECK_VALID;
2519}
2520
2521static int
2522_XimCheckSetICValuesMode(
2523    XIMResourceList	res,
2524    unsigned long	mode)
2525{
2526    if(mode & XIM_PREEDIT_ATTR) {
2527	if(!(res->mode & XIM_MODE_PRE_MASK)) {
2528	    return XIM_CHECK_INVALID;
2529	}
2530
2531	if(res->mode & XIM_MODE_PRE_ONCE) {
2532	    res->mode &= ~XIM_MODE_PRE_ONCE;
2533	} else if(!(res->mode & XIM_MODE_PRE_SET)) {
2534	    return XIM_CHECK_ERROR;
2535	}
2536
2537    } else if(mode & XIM_STATUS_ATTR) {
2538	if(!(res->mode & XIM_MODE_STS_MASK)) {
2539	    return XIM_CHECK_INVALID;
2540	}
2541
2542	if(res->mode & XIM_MODE_STS_ONCE) {
2543	    res->mode &= ~XIM_MODE_STS_ONCE;
2544	} else if(!(res->mode & XIM_MODE_STS_SET)) {
2545	    return XIM_CHECK_ERROR;
2546	}
2547
2548    } else {
2549	if(!res->mode) {
2550	    return XIM_CHECK_INVALID;
2551	}
2552
2553	if(res->mode & XIM_MODE_IC_ONCE) {
2554	    res->mode &= ~XIM_MODE_IC_ONCE;
2555	} else if(!(res->mode & XIM_MODE_IC_SET)) {
2556	    return XIM_CHECK_ERROR;
2557	}
2558    }
2559    return XIM_CHECK_VALID;
2560}
2561
2562static int
2563_XimCheckGetICValuesMode(
2564    XIMResourceList	res,
2565    unsigned long	mode)
2566{
2567    if(mode & XIM_PREEDIT_ATTR) {
2568	if(!(res->mode & XIM_MODE_PRE_MASK)) {
2569	    return XIM_CHECK_INVALID;
2570	}
2571
2572	if(!(res->mode & XIM_MODE_PRE_GET)) {
2573	    return XIM_CHECK_ERROR;
2574	}
2575
2576    } else if(mode & XIM_STATUS_ATTR) {
2577	if(!(res->mode & XIM_MODE_STS_MASK)) {
2578	    return XIM_CHECK_INVALID;
2579	}
2580
2581	if(!(res->mode & XIM_MODE_STS_GET)) {
2582	    return XIM_CHECK_ERROR;
2583	}
2584
2585    } else {
2586	if(!res->mode) {
2587	    return XIM_CHECK_INVALID;
2588	}
2589
2590	if(!(res->mode & XIM_MODE_IC_GET)) {
2591	    return XIM_CHECK_ERROR;
2592	}
2593    }
2594    return XIM_CHECK_VALID;
2595}
2596
2597int
2598 _XimCheckICMode(
2599    XIMResourceList     res,
2600    unsigned long       mode)
2601{
2602    if(mode &XIM_SETICDEFAULTS) {
2603	return _XimCheckSetICDefaultsMode(res, mode);
2604    } else if (mode & XIM_CREATEIC) {
2605	return _XimCheckCreateICMode(res, mode);
2606    } else if (mode & XIM_SETICVALUES) {
2607	return _XimCheckSetICValuesMode(res, mode);
2608    } else if (mode & XIM_GETICVALUES) {
2609	return _XimCheckGetICValuesMode(res, mode);
2610    } else {
2611	return XIM_CHECK_ERROR;
2612    }
2613}
2614
2615Bool
2616_XimSetLocalIMDefaults(
2617    Xim			 im,
2618    XPointer		 top,
2619    XIMResourceList	 res_list,
2620    unsigned int	 list_num)
2621{
2622    XimValueOffsetInfo	 info;
2623    unsigned int	 num;
2624    register int	 i;
2625    XIMResourceList	 res;
2626    int			 check;
2627
2628    info = im_attr_info;
2629    num  = XIMNumber(im_attr_info);
2630
2631    for(i = 0; i < num; i++) {
2632	if((res = _XimGetResourceListRecByQuark( res_list, list_num,
2633				info[i].quark)) == (XIMResourceList)NULL) {
2634	    return False;
2635	}
2636
2637	check = _XimCheckIMMode(res, XIM_SETIMDEFAULTS);
2638	if(check == XIM_CHECK_INVALID) {
2639	    continue;
2640	} else if (check == XIM_CHECK_ERROR) {
2641	    return False;
2642	}
2643
2644	if(!info[i].defaults) {
2645	    continue;
2646	}
2647	if(!(info[i].defaults(&info[i], top, (XPointer)NULL, 0))) {
2648	    return False;
2649	}
2650    }
2651    return True;
2652}
2653
2654Bool
2655_XimSetICDefaults(
2656    Xic			 ic,
2657    XPointer		 top,
2658    unsigned long	 mode,
2659    XIMResourceList	 res_list,
2660    unsigned int	 list_num)
2661{
2662    unsigned int	 num;
2663    XimValueOffsetInfo	 info;
2664    register int	 i;
2665    XIMResourceList	 res;
2666    int			 check;
2667    XrmQuark		 pre_quark;
2668    XrmQuark		 sts_quark;
2669
2670    pre_quark = XrmStringToQuark(XNPreeditAttributes);
2671    sts_quark = XrmStringToQuark(XNStatusAttributes);
2672
2673    if(mode & XIM_PREEDIT_ATTR) {
2674	info = ic_pre_attr_info;
2675	num  = XIMNumber(ic_pre_attr_info);
2676    } else if(mode & XIM_STATUS_ATTR) {
2677	info = ic_sts_attr_info;
2678	num  = XIMNumber(ic_sts_attr_info);
2679    } else {
2680	info = ic_attr_info;
2681	num  = XIMNumber(ic_attr_info);
2682    }
2683
2684    for(i = 0; i < num; i++) {
2685	if(info[i].quark == pre_quark) {
2686	    if(!_XimSetICDefaults(ic, (XPointer)((char *)top + info[i].offset),
2687			(mode | XIM_PREEDIT_ATTR), res_list, list_num)) {
2688		return False;
2689	    }
2690	} else if (info[i].quark == sts_quark) {
2691	    if(!_XimSetICDefaults(ic, (XPointer)((char *)top + info[i].offset),
2692			(mode | XIM_STATUS_ATTR), res_list, list_num)) {
2693		return False;
2694	    }
2695	} else {
2696	    if(!(res = _XimGetResourceListRecByQuark(res_list, list_num,
2697							info[i].quark))) {
2698		return False;
2699	    }
2700
2701	    check = _XimCheckICMode(res, mode);
2702	    if (check == XIM_CHECK_INVALID) {
2703		continue;
2704	    } else if (check == XIM_CHECK_ERROR) {
2705		return False;
2706	    }
2707
2708	    if (!info[i].defaults) {
2709		continue;
2710	    }
2711	    if (!(info[i].defaults(&info[i], top, (XPointer)ic, mode))) {
2712		return False;
2713	    }
2714	}
2715    }
2716    return True;
2717}
2718
2719static Bool
2720_XimEncodeAttr(
2721    XimValueOffsetInfo	 info,
2722    unsigned int	 num,
2723    XIMResourceList	 res,
2724    XPointer		 top,
2725    XPointer		 val)
2726{
2727    register int	 i;
2728
2729    for(i = 0; i < num; i++ ) {
2730	if(info[i].quark == res->xrm_name) {
2731	    if(!info[i].encode) {
2732		return False;
2733	    }
2734	    return (*info[i].encode)(&info[i], top, val);
2735	}
2736    }
2737    return False;
2738}
2739
2740Bool
2741_XimEncodeLocalIMAttr(
2742    XIMResourceList	 res,
2743    XPointer		 top,
2744    XPointer		 val)
2745{
2746    return _XimEncodeAttr(im_attr_info, XIMNumber(im_attr_info),
2747					res, top, val);
2748}
2749
2750Bool
2751_XimEncodeLocalICAttr(
2752    Xic			 ic,
2753    XIMResourceList	 res,
2754    XPointer		 top,
2755    XIMArg		*arg,
2756    unsigned long	 mode)
2757{
2758    unsigned int	 num;
2759    XimValueOffsetInfo	 info;
2760
2761    if(mode & XIM_PREEDIT_ATTR) {
2762	info = ic_pre_attr_info;
2763	num  = XIMNumber(ic_pre_attr_info);
2764    } else if(mode & XIM_STATUS_ATTR) {
2765	info = ic_sts_attr_info;
2766	num  = XIMNumber(ic_sts_attr_info);
2767    } else {
2768	info = ic_attr_info;
2769	num  = XIMNumber(ic_attr_info);
2770    }
2771
2772    return _XimEncodeAttr(info, num, res, top, arg->value);
2773}
2774
2775static Bool
2776_XimEncodeLocalTopValue(
2777    Xic			 ic,
2778    XIMResourceList	 res,
2779    XPointer		 val,
2780    Bool		 flag)
2781{
2782    XIMArg		*p = (XIMArg *)val;
2783
2784    if (res->xrm_name == XrmStringToQuark(XNClientWindow)) {
2785	ic->core.client_window = (Window)p->value;
2786	if (ic->core.focus_window == (Window)0)
2787	    ic->core.focus_window = ic->core.client_window;
2788	if (flag) {
2789	    _XRegisterFilterByType(ic->core.im->core.display,
2790			ic->core.focus_window,
2791			KeyPress, KeyRelease, _XimLocalFilter, (XPointer)ic);
2792	}
2793    } else if (res->xrm_name == XrmStringToQuark(XNFocusWindow)) {
2794	if (ic->core.client_window) {
2795	    if (flag) {
2796	        _XUnregisterFilter(ic->core.im->core.display,
2797			ic->core.focus_window, _XimLocalFilter, (XPointer)ic);
2798	    }
2799	    ic->core.focus_window = (Window)p->value;
2800	    if (flag) {
2801	        _XRegisterFilterByType(ic->core.im->core.display,
2802			ic->core.focus_window, KeyPress, KeyRelease,
2803			_XimLocalFilter, (XPointer)ic);
2804	    }
2805	} else
2806	    ic->core.focus_window = (Window)p->value;
2807    }
2808    return True;
2809}
2810
2811static Bool
2812_XimEncodeLocalPreeditValue(
2813    Xic			 ic,
2814    XIMResourceList	 res,
2815    XPointer		 val)
2816{
2817    XIMArg		*p = (XIMArg *)val;
2818
2819    if (res->xrm_name == XrmStringToQuark(XNStdColormap)) {
2820	XStandardColormap	*colormap_ret;
2821	int			 count;
2822
2823	if (!(XGetRGBColormaps(ic->core.im->core.display,
2824				ic->core.focus_window, &colormap_ret,
2825				&count, (Atom)p->value)))
2826	    return False;
2827
2828	Xfree(colormap_ret);
2829    }
2830    return True;
2831}
2832
2833static Bool
2834_XimEncodeLocalStatusValue(
2835    Xic			 ic,
2836    XIMResourceList	 res,
2837    XPointer		 val)
2838{
2839    XIMArg		*p = (XIMArg *)val;
2840
2841    if (res->xrm_name == XrmStringToQuark(XNStdColormap)) {
2842	XStandardColormap	*colormap_ret;
2843	int			 count;
2844
2845	if (!(XGetRGBColormaps(ic->core.im->core.display,
2846				ic->core.focus_window, &colormap_ret,
2847				&count, (Atom)p->value)))
2848	    return False;
2849
2850	Xfree(colormap_ret);
2851    }
2852    return True;
2853}
2854
2855char *
2856_XimSetICValueData(
2857    Xic			 ic,
2858    XPointer		 top,
2859    XIMResourceList	 res_list,
2860    unsigned int	 list_num,
2861    XIMArg		*values,
2862    unsigned long	 mode,
2863    Bool		 flag)
2864{
2865    register  XIMArg	*p;
2866    XIMResourceList	 res;
2867    char		*name;
2868    int			 check;
2869    XrmQuark		 pre_quark;
2870    XrmQuark		 sts_quark;
2871
2872    pre_quark = XrmStringToQuark(XNPreeditAttributes);
2873    sts_quark = XrmStringToQuark(XNStatusAttributes);
2874
2875    for(p = values; p->name != NULL; p++) {
2876	if((res = _XimGetResourceListRec(res_list, list_num,
2877					p->name)) == (XIMResourceList)NULL) {
2878	    return p->name;
2879	}
2880	if(res->xrm_name == pre_quark) {
2881	    if(((name = _XimSetICValueData(ic,
2882			(XPointer)(&((XimDefICValues *)top)->preedit_attr),
2883			res_list, list_num, (XIMArg *)p->value,
2884			(mode | XIM_PREEDIT_ATTR), flag)))) {
2885		return name;
2886	    }
2887	} else if(res->xrm_name == sts_quark) {
2888	    if(((name = _XimSetICValueData(ic,
2889			(XPointer)(&((XimDefICValues *)top)->status_attr),
2890			res_list, list_num, (XIMArg *)p->value,
2891			(mode | XIM_STATUS_ATTR), flag)))) {
2892		return name;
2893	    }
2894	} else {
2895	    check = _XimCheckICMode(res, mode);
2896	    if(check == XIM_CHECK_INVALID) {
2897		continue;
2898	    } else if(check == XIM_CHECK_ERROR) {
2899		return p->name;
2900	    }
2901
2902	    if(mode & XIM_PREEDIT_ATTR) {
2903		if (!_XimEncodeLocalPreeditValue(ic, res, (XPointer)p))
2904		    return p->name;
2905    	    } else if(mode & XIM_STATUS_ATTR) {
2906		if (!_XimEncodeLocalStatusValue(ic, res, (XPointer)p))
2907		    return p->name;
2908    	    } else {
2909		if (!_XimEncodeLocalTopValue(ic, res, (XPointer)p, flag))
2910		    return p->name;
2911    	    }
2912	    if(_XimEncodeLocalICAttr(ic, res, top, p, mode) == False) {
2913		return p->name;
2914	    }
2915	}
2916    }
2917    return NULL;
2918}
2919
2920static Bool
2921_XimCheckInputStyle(
2922    XIMStyles		*styles,
2923    XIMStyle		 style)
2924{
2925    int			 num = styles->count_styles;
2926    register int	 i;
2927
2928    for(i = 0; i < num; i++) {
2929	if(styles->supported_styles[i] == style) {
2930	    return True;
2931	}
2932    }
2933    return False;
2934}
2935
2936Bool
2937_XimCheckLocalInputStyle(
2938    Xic			 ic,
2939    XPointer		 top,
2940    XIMArg		*values,
2941    XIMStyles		*styles,
2942    XIMResourceList	 res_list,
2943    unsigned int	 list_num)
2944{
2945    XrmQuark		 quark = XrmStringToQuark(XNInputStyle);
2946    register XIMArg	*p;
2947    XIMResourceList	 res;
2948
2949    for(p = values; p && p->name != NULL; p++) {
2950	if(quark == XrmStringToQuark(p->name)) {
2951	    if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) {
2952		return False;
2953	    }
2954	    if(!_XimEncodeLocalICAttr(ic, res, top, p, 0)) {
2955		return False;
2956	    }
2957	    if (_XimCheckInputStyle(styles,
2958			((XimDefICValues *)top)->input_style)) {
2959		return True;
2960	    }
2961	    return False;
2962	}
2963    }
2964    return False;
2965}
2966
2967static Bool
2968_XimDecodeAttr(
2969    XimValueOffsetInfo	 info,
2970    unsigned int	 num,
2971    XIMResourceList	 res,
2972    XPointer		 top,
2973    XPointer		 val)
2974{
2975    register int	 i;
2976
2977    for(i = 0; i < num; i++ ) {
2978	if(info[i].quark == res->xrm_name) {
2979	    if(!info[i].decode) {
2980		return False;
2981	    }
2982	    return (*info[i].decode)(&info[i], top, val);
2983	}
2984    }
2985    return False;
2986}
2987
2988Bool
2989_XimDecodeLocalIMAttr(
2990    XIMResourceList	 res,
2991    XPointer		 top,
2992    XPointer		 val)
2993{
2994    return _XimDecodeAttr(im_attr_info, XIMNumber(im_attr_info),
2995					res, top, val);
2996}
2997
2998Bool
2999_XimDecodeLocalICAttr(
3000    XIMResourceList	 res,
3001    XPointer		 top,
3002    XPointer		 val,
3003    unsigned long	 mode)
3004{
3005    unsigned int	 num;
3006    XimValueOffsetInfo	 info;
3007
3008    if(mode & XIM_PREEDIT_ATTR) {
3009	info = ic_pre_attr_info;
3010	num  = XIMNumber(ic_pre_attr_info);
3011    } else if(mode & XIM_STATUS_ATTR) {
3012	info = ic_sts_attr_info;
3013	num  = XIMNumber(ic_sts_attr_info);
3014    } else {
3015	info = ic_attr_info;
3016	num  = XIMNumber(ic_attr_info);
3017    }
3018
3019    return _XimDecodeAttr(info, num, res, top, val);
3020}
3021
3022char *
3023_XimGetICValueData(Xic ic, XPointer top, XIMResourceList res_list,
3024		   unsigned int	 list_num, XIMArg *values, unsigned long mode)
3025{
3026    register  XIMArg	*p;
3027    XIMResourceList	 res;
3028    char		*name;
3029    int			 check;
3030    XrmQuark		 pre_quark;
3031    XrmQuark		 sts_quark;
3032
3033    pre_quark = XrmStringToQuark(XNPreeditAttributes);
3034    sts_quark = XrmStringToQuark(XNStatusAttributes);
3035
3036    for(p = values; p->name != NULL; p++) {
3037	if((res = _XimGetResourceListRec(res_list, list_num,
3038					p->name)) == (XIMResourceList)NULL) {
3039	    return p->name;
3040	}
3041	if(res->xrm_name == pre_quark) {
3042	    if((name = _XimGetICValueData(ic,
3043			(XPointer)(&((XimDefICValues *)top)->preedit_attr),
3044			res_list, list_num, (XIMArg *)p->value,
3045			(mode | XIM_PREEDIT_ATTR)))) {
3046		return name;
3047	    }
3048	} else if(res->xrm_name == sts_quark) {
3049	    if((name = _XimGetICValueData(ic,
3050			(XPointer)(&((XimDefICValues *)top)->status_attr),
3051			res_list, list_num, (XIMArg *)p->value,
3052			(mode | XIM_STATUS_ATTR)))) {
3053		return name;
3054	    }
3055	} else {
3056	    check = _XimCheckICMode(res, mode);
3057	    if(check == XIM_CHECK_INVALID) {
3058		continue;
3059	    } else if(check == XIM_CHECK_ERROR) {
3060		return p->name;
3061	    }
3062
3063	    if(_XimDecodeLocalICAttr(res, top, p->value, mode) == False) {
3064		return p->name;
3065	    }
3066	}
3067    }
3068    return NULL;
3069}
3070
3071void
3072_XimGetCurrentIMValues(Xim im, XimDefIMValues *im_values)
3073{
3074    bzero((char *)im_values, sizeof(XimDefIMValues));
3075
3076    im_values->styles		= im->core.styles;
3077    im_values->im_values_list	= im->core.im_values_list;
3078    im_values->ic_values_list	= im->core.ic_values_list;
3079    im_values->destroy_callback = im->core.destroy_callback;
3080    im_values->res_name		= im->core.res_name;
3081    im_values->res_class	= im->core.res_class;
3082    im_values->visible_position	= im->core.visible_position;
3083}
3084
3085void
3086_XimSetCurrentIMValues(Xim im, XimDefIMValues *im_values)
3087{
3088    im->core.styles		= im_values->styles;
3089    im->core.im_values_list	= im_values->im_values_list;
3090    im->core.ic_values_list	= im_values->ic_values_list;
3091    im->core.destroy_callback	= im_values->destroy_callback;
3092    im->core.res_name		= im_values->res_name;
3093    im->core.res_class		= im_values->res_class;
3094    im->core.visible_position	= im_values->visible_position;
3095}
3096
3097void
3098_XimGetCurrentICValues(Xic ic, XimDefICValues *ic_values)
3099{
3100    bzero((char *)ic_values, sizeof(XimDefICValues));
3101
3102    ic_values->input_style	 = ic->core.input_style;
3103    ic_values->client_window	 = ic->core.client_window;
3104    ic_values->focus_window	 = ic->core.focus_window;
3105    ic_values->filter_events	 = ic->core.filter_events;
3106    ic_values->geometry_callback = ic->core.geometry_callback;
3107    ic_values->res_name		 = ic->core.res_name;
3108    ic_values->res_class	 = ic->core.res_class;
3109    ic_values->destroy_callback	 = ic->core.destroy_callback;
3110    ic_values->string_conversion_callback
3111				 = ic->core.string_conversion_callback;
3112    ic_values->string_conversion = ic->core.string_conversion;
3113    ic_values->reset_state	 = ic->core.reset_state;
3114    ic_values->hotkey		 = ic->core.hotkey;
3115    ic_values->hotkey_state	 = ic->core.hotkey_state;
3116    ic_values->preedit_attr	 = ic->core.preedit_attr;
3117    ic_values->status_attr	 = ic->core.status_attr;
3118}
3119
3120void
3121_XimSetCurrentICValues(
3122    Xic			 ic,
3123    XimDefICValues	*ic_values)
3124{
3125    ic->core.input_style	= ic_values->input_style;
3126    ic->core.client_window	= ic_values->client_window;
3127    if (ic_values->focus_window)
3128	ic->core.focus_window	= ic_values->focus_window;
3129    ic->core.filter_events	= ic_values->filter_events;
3130    ic->core.geometry_callback	= ic_values->geometry_callback;
3131    ic->core.res_name		= ic_values->res_name;
3132    ic->core.res_class		= ic_values->res_class;
3133    ic->core.destroy_callback 	= ic_values->destroy_callback;
3134    ic->core.string_conversion_callback
3135				= ic_values->string_conversion_callback;
3136    ic->core.string_conversion	= ic_values->string_conversion;
3137    ic->core.reset_state	= ic_values->reset_state;
3138    ic->core.hotkey		= ic_values->hotkey;
3139    ic->core.hotkey_state	= ic_values->hotkey_state;
3140    ic->core.preedit_attr	= ic_values->preedit_attr;
3141    ic->core.status_attr	= ic_values->status_attr;
3142}
3143
3144static void
3145_XimInitialIMOffsetInfo(void)
3146{
3147    unsigned int	 n = XIMNumber(im_attr_info);
3148    register int	 i;
3149
3150    for(i = 0; i < n; i++) {
3151	im_attr_info[i].quark = XrmStringToQuark(GET_NAME(im_attr_info[i]));
3152    }
3153}
3154
3155static void
3156_XimInitialICOffsetInfo(void)
3157{
3158    unsigned int	 n;
3159    register int	 i;
3160
3161    n = XIMNumber(ic_attr_info);
3162    for(i = 0; i < n; i++) {
3163	ic_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_attr_info[i]));
3164    }
3165
3166    n = XIMNumber(ic_pre_attr_info);
3167    for(i = 0; i < n; i++) {
3168	ic_pre_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_pre_attr_info[i]));
3169    }
3170
3171    n = XIMNumber(ic_sts_attr_info);
3172    for(i = 0; i < n; i++) {
3173	ic_sts_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_sts_attr_info[i]));
3174    }
3175}
3176
3177static void
3178_XimInitialIMMode(void)
3179{
3180    unsigned int	n = XIMNumber(im_mode);
3181    register int	i;
3182
3183    for(i = 0; i < n; i++) {
3184	im_mode_quark[i] = XrmStringToQuark(GET_NAME(im_mode[i]));
3185    }
3186}
3187
3188static void
3189_XimInitialICMode(void)
3190{
3191    unsigned int	n = XIMNumber(ic_mode);
3192    register int	i;
3193
3194    for(i = 0; i < n; i++) {
3195	ic_mode_quark[i] = XrmStringToQuark(GET_NAME(ic_mode[i]));
3196    }
3197}
3198
3199void
3200_XimInitialResourceInfo(void)
3201{
3202    static Bool	init_flag = False;
3203
3204    if(init_flag == True) {
3205	return;
3206    }
3207    _XimInitialIMOffsetInfo();
3208    _XimInitialICOffsetInfo();
3209    _XimInitialIMMode();
3210    _XimInitialICMode();
3211    init_flag = True;
3212}
3213