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