IMWrap.c revision 1ab64890
1/*
2 * $Xorg: IMWrap.c,v 1.3 2000/08/17 19:44:37 cpqbld Exp $
3 */
4
5/*
6 * Copyright 1991 by the Open Software Foundation
7 * Copyright 1993, 1994 by the Sony Corporation
8 *
9 * Permission to use, copy, modify, distribute, and sell this software and its
10 * documentation for any purpose is hereby granted without fee, provided that
11 * the above copyright notice appear in all copies and that both that
12 * copyright notice and this permission notice appear in supporting
13 * documentation, and that the names of Open Software Foundation and
14 * Sony Corporation not be used in advertising or publicity pertaining to
15 * distribution of the software without specific, written prior permission.
16 * Open Software Foundation and Sony Corporation make no
17 * representations about the suitability of this software for any purpose.
18 * It is provided "as is" without express or implied warranty.
19 *
20 * OPEN SOFTWARE FOUNDATION AND SONY CORPORATION DISCLAIM ALL
21 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL OPEN
23 * SOFTWARE FOUNDATIONN OR SONY CORPORATION BE LIABLE FOR ANY SPECIAL,
24 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
25 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
26 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
27 * PERFORMANCE OF THIS SOFTWARE.
28 *
29 *		 M. Collins		OSF
30 *               Makoto Wakamatsu       Sony Corporation
31 */
32/*
33
34Copyright 1991, 1998  The Open Group
35
36Permission to use, copy, modify, distribute, and sell this software and its
37documentation for any purpose is hereby granted without fee, provided that
38the above copyright notice appear in all copies and that both that
39copyright notice and this permission notice appear in supporting
40documentation.
41
42The above copyright notice and this permission notice shall be included
43in all copies or substantial portions of the Software.
44
45THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
46OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
47MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
48IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
49OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
50ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
51OTHER DEALINGS IN THE SOFTWARE.
52
53Except as contained in this notice, the name of The Open Group shall
54not be used in advertising or otherwise to promote the sale, use or
55other dealings in this Software without prior written authorization
56from The Open Group.
57
58*/
59
60/* $XFree86: xc/lib/X11/IMWrap.c,v 3.8 2001/12/14 19:54:01 dawes Exp $ */
61
62#ifdef HAVE_CONFIG_H
63#include <config.h>
64#endif
65#include "Xlibint.h"
66#include "Xlcint.h"
67
68/*
69 * Compile the resource name. (resource_name ---> xrm_name)
70 */
71void
72_XIMCompileResourceList(res, num_res)
73    register XIMResourceList res;
74    unsigned int num_res;
75{
76    register unsigned int count;
77
78    for (count = 0; count < num_res; res++, count++) {
79	res->xrm_name = XrmStringToQuark(res->resource_name);
80    }
81}
82
83void
84_XCopyToArg(src, dst, size)
85    XPointer src;
86    XPointer *dst;
87    register unsigned int size;
88{
89    if (!*dst) {
90	union {
91	    long	longval;
92#ifdef LONG64
93	    int		intval;
94#endif
95	    short	shortval;
96	    char	charval;
97	    char*	charptr;
98	    XPointer	ptr;
99	} u;
100	if (size <= sizeof(XPointer)) {
101	    memcpy((char *)&u, (char *)src, (int)size);
102	    if (size == sizeof(long))	       *dst = (XPointer)u.longval;
103#ifdef LONG64
104	    else if (size == sizeof(int))      *dst = (XPointer)(long)u.intval;
105#endif
106	    else if (size == sizeof(short))    *dst = (XPointer)(long)u.shortval;
107	    else if (size == sizeof(char))     *dst = (XPointer)(long)u.charval;
108	    else if (size == sizeof(char*))    *dst = (XPointer)u.charptr;
109	    else if (size == sizeof(XPointer)) *dst = (XPointer)u.ptr;
110	    else memcpy( (char*)dst, (char*)src, (int)size );
111	} else {
112	    memcpy( (char*)dst, (char*)src, (int)size );
113	}
114    } else {
115	memcpy( (char*)*dst, (char*)src, (int)size );
116    }
117}
118
119/*
120 * Connects to an input method matching current locale specification, creates
121 * a XIM object and return a pointer the newly created XIM back to the caller.
122 */
123
124XIM
125XOpenIM( display, rdb, res_name, res_class )
126    Display	*display;
127    XrmDatabase	 rdb;
128    char	*res_name;
129    char	*res_class;
130{
131    XLCd	lcd = _XOpenLC( (char *)NULL );
132
133    if( !lcd )
134	return( (XIM)NULL );
135    return (*lcd->methods->open_im) (lcd, display, rdb, res_name, res_class);
136}
137
138/*
139 * Close the connection to the input manager, and free the XIM structure
140 */
141Status
142XCloseIM(im)
143    XIM im;
144{
145    Status s;
146    XIC ic;
147    XLCd lcd = im->core.lcd;
148
149    s = (im->methods->close) (im);
150    for (ic = im->core.ic_chain; ic; ic = ic->core.next)
151	ic->core.im = (XIM)NULL;
152    Xfree ((char *) im);
153    _XCloseLC (lcd);
154    return (s);
155}
156
157/*
158 * Return the Display associated with the input method.
159 */
160Display *
161XDisplayOfIM(im)
162    XIM im;
163{
164    return im->core.display;
165}
166
167/*
168 * Return the Locale associated with the input method.
169 */
170char *
171XLocaleOfIM(im)
172    XIM im;
173{
174    return im->core.lcd->core->name;
175}
176
177/*
178 * Register to a input method instantiation callback to prepare the
179 * on-demand input method instantiation.
180 */
181Bool
182XRegisterIMInstantiateCallback(
183    Display	*display,
184    XrmDatabase	 rdb,
185    char	*res_name,
186    char	*res_class,
187    XIDProc	 callback,
188    XPointer	 client_data)
189{
190    XLCd	lcd = _XOpenLC( (char *)NULL );
191
192    if( !lcd )
193	return( False );
194    return( (*lcd->methods->register_callback)( lcd, display, rdb, res_name,
195						res_class, callback,
196						client_data ) );
197}
198
199/*
200 * Unregister to a input method instantiation callback.
201 */
202Bool
203XUnregisterIMInstantiateCallback(
204    Display	*display,
205    XrmDatabase	 rdb,
206    char	*res_name,
207    char	*res_class,
208    XIDProc	 callback,
209    XPointer	 client_data)
210{
211    XLCd	lcd = _XlcCurrentLC();
212
213    if( !lcd )
214	return( False );
215    if( lcd->methods->unregister_callback == NULL )
216	return( False );
217    return( (*lcd->methods->unregister_callback)( lcd, display, rdb, res_name,
218						  res_class, callback,
219						  client_data ) );
220}
221
222