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