1 /******************************************************************
3 Copyright 1991, 1992 by Fuji Xerox Co.,Ltd.
4 Copyright 1993, 1994 by FUJITSU LIMITED
6 Permission to use, copy, modify, distribute, and sell this software
7 and its documentation for any purpose is hereby granted without fee,
8 provided that the above copyright notice appear in all copies and
9 that both that copyright notice and this permission notice appear
10 in supporting documentation, and that the name of Fuji Xerox Co.,Ltd.
11 , and that the name of FUJITSU LIMITED not be used in advertising or
12 publicity pertaining to distribution of the software without specific,
13 written prior permission.
14 Fuji Xerox Co.,Ltd. , and FUJITSU LIMITED makes no representations about
15 the suitability of this software for any purpose.
16 It is provided "as is" without express or implied warranty.
18 FUJI XEROX CO.,LTD. AND FUJITSU LIMITED DISCLAIMS ALL WARRANTIES WITH
19 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
20 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJI XEROX CO.,LTD.
21 AND FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT
22 OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
24 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
25 THE USE OR PERFORMANCE OF THIS SOFTWARE.
27 Auther: Kazunori Nishihara, Fuji Xerox Co.,Ltd.
28 kaz@ssdev.ksp.fujixerox.co.jp
29 Modifier: Takashi Fujiwara FUJITSU LIMITED
30 fujiwara@a80.tech.yk.fujitsu.co.jp
32 ******************************************************************/
33 /* 2000 Modifier: Ivan Pascal The XFree86 Project.
47 * rather than just call _XLookupString (i.e. the pre-XKB XLookupString)
48 * do this because with XKB the event may have some funky modifiers that
49 * _XLookupString doesn't grok.
52 #define XLOOKUPSTRING lookup_string
54 #define XLOOKUPSTRING XLookupString
57 typedef unsigned int ucs4_t;
59 typedef int (*ucstocsConvProc)(
67 const char encoding_name[8];
68 const char charset_name[12];
71 static const struct SubstRec SubstTable[] = {
72 {"STRING", "ISO8859-1"},
73 {"TIS620", "TIS620-0"},
74 {"UTF-8", "ISO10646-1"}
76 #define num_substitute (sizeof SubstTable / sizeof SubstTable[0])
79 * Given the name of a charset, returns the pointer to convertors
80 * from UCS char to specified charset char.
81 * This converter is needed for _XimGetCharCode subroutine.
85 _Xconst char* encoding_name)
87 XPointer cvt = _Utf8GetConvByName(encoding_name);
88 if (!cvt && encoding_name) {
90 for (i = 0; i < num_substitute; i++)
91 if (!strcmp(encoding_name, SubstTable[i].encoding_name))
92 return _Utf8GetConvByName(SubstTable[i].charset_name);
98 * Returns the locale dependent representation of a keysym.
99 * The locale's encoding is passed in form of pointer to UCS convertor.
100 * The resulting multi-byte sequence is placed starting at buf (a buffer
101 * with nbytes bytes, nbytes should be >= 8) and is NUL terminated.
102 * Returns the length of the resulting multi-byte sequence, excluding the
103 * terminating NUL byte. Return 0 if the keysym is not representable in the
115 ucstocsConvProc cvt = (ucstocsConvProc) ucs_conv;
119 buf[0] = (char) keysym;
122 ucs4 = KeySymToUcs4(keysym);
124 count = (*cvt)((XPointer)NULL, buf, ucs4, nbytes);
137 static int lookup_string(
142 XComposeStatus* status)
145 unsigned ctrls = XkbGetXlibControls (event->display);
146 XkbSetXlibControls (event->display,
147 XkbLC_ForceLatin1Lookup, XkbLC_ForceLatin1Lookup);
148 ret = XLookupString(event, (char *)buffer, nbytes, keysym, status);
149 XkbSetXlibControls (event->display,
150 XkbLC_ForceLatin1Lookup, ctrls);
155 #define BUF_SIZE (20)
164 XComposeStatus* status)
169 Xim im = (Xim)ic->core.im;
170 XimCommonPrivateRec* private = &im->private.common;
171 unsigned char look[BUF_SIZE];
174 /* force a latin-1 lookup for compatibility */
175 count = XLOOKUPSTRING(event, (char *)buffer, nbytes, &symbol, status);
176 if (keysym != NULL) *keysym = symbol;
177 if ((nbytes == 0) || (symbol == NoSymbol)) return count;
180 memcpy(look, (char *)buffer,count);
182 if ((count = im->methods->ctstombs(ic->core.im,
184 buffer, nbytes, &dummy)) < 0) {
187 } else if ((count == 0) ||
188 (count == 1 && (symbol > 0x7f && symbol < 0xff00))) {
190 XPointer from = (XPointer) &ucs4;
191 XPointer to = (XPointer) look;
193 int to_len = BUF_SIZE;
196 args[0] = (XPointer) &charset;
197 ucs4 = (ucs4_t) KeySymToUcs4(symbol);
201 if (_XlcConvert(private->ucstoc_conv,
202 &from, &from_len, &to, &to_len,
206 from = (XPointer) look;
207 to = (XPointer) buffer;
208 from_len = BUF_SIZE - to_len;
210 args[0] = (XPointer) charset;
211 if (_XlcConvert(private->cstomb_conv,
212 &from, &from_len, &to, &to_len,
216 count = nbytes - to_len;
221 * we should make sure that if the character is a Latin1 character
222 * and it's on the right side, and we're in a non-Latin1 locale
223 * that this is a valid Latin1 character for this locale.
235 XComposeStatus* status)
240 Xim im = (Xim)ic->core.im;
241 XimCommonPrivateRec* private = &im->private.common;
242 unsigned char look[BUF_SIZE];
245 /* force a latin-1 lookup for compatibility */
246 count = XLOOKUPSTRING(event, (char *)look, nbytes, &symbol, status);
247 if (keysym != NULL) *keysym = symbol;
248 if ((nbytes == 0) || (symbol == NoSymbol)) return count;
251 if ((count = im->methods->ctstowcs(ic->core.im,
253 buffer, nbytes, &dummy)) < 0) {
256 } else if ((count == 0) ||
257 (count == 1 && (symbol > 0x7f && symbol < 0xff00))) {
259 XPointer from = (XPointer) &ucs4;
260 XPointer to = (XPointer) look;
262 int to_len = BUF_SIZE;
265 args[0] = (XPointer) &charset;
266 ucs4 = (ucs4_t) KeySymToUcs4(symbol);
270 if (_XlcConvert(private->ucstoc_conv,
271 &from, &from_len, &to, &to_len,
275 from = (XPointer) look;
276 to = (XPointer) buffer;
277 from_len = BUF_SIZE - to_len;
279 args[0] = (XPointer) charset;
281 if (_XlcConvert(private->cstowc_conv,
282 &from, &from_len, &to, &to_len,
286 count = nbytes - to_len;
291 * we should make sure that if the character is a Latin1 character
292 * and it's on the right side, and we're in a non-Latin1 locale
293 * that this is a valid Latin1 character for this locale.
307 XComposeStatus* status)
312 Xim im = (Xim)ic->core.im;
313 XimCommonPrivateRec* private = &im->private.common;
314 unsigned char look[BUF_SIZE];
317 /* force a latin-1 lookup for compatibility */
318 count = XLOOKUPSTRING(event, (char *)buffer, nbytes, &symbol, status);
319 if (keysym != NULL) *keysym = symbol;
320 if ((nbytes == 0) || (symbol == NoSymbol)) return count;
323 memcpy(look, (char *)buffer,count);
325 if ((count = im->methods->ctstoutf8(ic->core.im,
327 buffer, nbytes, &dummy)) < 0) {
330 } else if ((count == 0) ||
331 (count == 1 && (symbol > 0x7f && symbol < 0xff00))) {
333 XPointer from = (XPointer) &ucs4;
335 XPointer to = (XPointer) buffer;
338 ucs4 = (ucs4_t) KeySymToUcs4(symbol);
342 if (_XlcConvert(private->ucstoutf8_conv,
343 &from, &from_len, &to, &to_len,
347 count = nbytes - to_len;
351 * we should make sure that if the character is a Latin1 character
352 * and it's on the right side, and we're in a non-Latin1 locale
353 * that this is a valid Latin1 character for this locale.