diff options
Diffstat (limited to 'modules/im/ximcp/imLcLkup.c')
-rw-r--r-- | modules/im/ximcp/imLcLkup.c | 118 |
1 files changed, 103 insertions, 15 deletions
diff --git a/modules/im/ximcp/imLcLkup.c b/modules/im/ximcp/imLcLkup.c index fa92701d..46ef857a 100644 --- a/modules/im/ximcp/imLcLkup.c +++ b/modules/im/ximcp/imLcLkup.c @@ -29,6 +29,7 @@ PERFORMANCE OF THIS SOFTWARE. fujiwara@a80.tech.yk.fujitsu.co.jp ******************************************************************/ +/* $XFree86: xc/lib/X11/imLcLkup.c,v 3.6 2001/08/13 21:46:46 dawes Exp $ */ #include <stdio.h> #include <X11/Xatom.h> @@ -56,7 +57,7 @@ _XimLocalMbLookupString(xic, ev, buffer, bytes, keysym, status) if(status) *status = XLookupNone; return(0); } - if(ev->keycode == 0) { /* Composed Event */ + if(ev->keycode == 0 && ic->private.local.composed != NULL) { /* Composed Event */ ret = strlen(ic->private.local.composed->mb); if(ret > bytes) { if(status) *status = XBufferOverflow; @@ -155,21 +156,72 @@ _XimLocalWcLookupString(xic, ev, buffer, wlen, keysym, status) return (ret); } -#ifndef MAXINT -#define MAXINT (~((unsigned int)1 << (8 * sizeof(int)) - 1)) -#endif /* !MAXINT */ - Public int -_XimLcctstombs(xim, from, from_len, to, to_len, state) - XIM xim; +_XimLocalUtf8LookupString(xic, ev, buffer, bytes, keysym, status) + XIC xic; + XKeyEvent *ev; + char *buffer; + int bytes; + KeySym *keysym; + Status *status; +{ + Xic ic = (Xic)xic; + int ret; + + if(ev->type != KeyPress) { + if(status) *status = XLookupNone; + return(0); + } + if(ev->keycode == 0) { /* Composed Event */ + ret = strlen(ic->private.local.composed->utf8); + if(ret > bytes) { + if(status) *status = XBufferOverflow; + return (ret); + } + memcpy(buffer, ic->private.local.composed->utf8, ret); + if(keysym) *keysym = ic->private.local.composed->ks; + if (ret > 0) { + if(keysym && *keysym != NoSymbol) { + if(status) *status = XLookupBoth; + } else { + if(status) *status = XLookupChars; + } + } else { + if(keysym && *keysym != NoSymbol) { + if(status) *status = XLookupKeySym; + } else { + if(status) *status = XLookupNone; + } + } + return (ret); + } else { /* Throughed Event */ + ret = _XimLookupUTF8Text(ic, ev, buffer, bytes, keysym, NULL); + if(ret > 0) { + if(keysym && *keysym != NoSymbol) { + if(status) *status = XLookupBoth; + } else { + if(status) *status = XLookupChars; + } + } else { + if(keysym && *keysym != NoSymbol) { + if(status) *status = XLookupKeySym; + } else { + if(status) *status = XLookupNone; + } + } + } + return (ret); +} + +Private int +_XimLcctsconvert(conv, from, from_len, to, to_len, state) + XlcConv conv; char *from; int from_len; char *to; int to_len; Status *state; { - Xim im = (Xim)xim; - XlcConv conv = im->private.local.ctom_conv; int from_left; int to_left; int from_savelen; @@ -178,6 +230,7 @@ _XimLcctstombs(xim, from, from_len, to, to_len, state) int to_cnvlen; char *from_buf; char *to_buf; + char scratchbuf[BUFSIZ]; Status tmp_state; if (!state) @@ -188,6 +241,10 @@ _XimLcctstombs(xim, from, from_len, to, to_len, state) return 0; } + /* Reset the converter. The CompoundText at 'from' starts in + initial state. */ + _XlcResetConverter(conv); + if (to && to_len) { from_left = from_len; to_left = to_len; @@ -221,10 +278,10 @@ _XimLcctstombs(xim, from, from_len, to, to_len, state) from_left = from_len; from_cnvlen = 0; to_cnvlen = 0; - to_buf = NULL; for (;;) { from_savelen = from_left; - to_left = MAXINT; + to_buf = scratchbuf; + to_left = BUFSIZ; from_buf = &from[from_cnvlen]; if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left, (XPointer *)&to_buf, &to_left, NULL, 0) < 0) { @@ -232,7 +289,7 @@ _XimLcctstombs(xim, from, from_len, to, to_len, state) return 0; } from_cnvlen += (from_savelen - from_left); - to_cnvlen += (MAXINT - to_left); + to_cnvlen += (BUFSIZ - to_left); if (from_left == 0) { if (to_cnvlen > 0) *state = XBufferOverflow; @@ -245,6 +302,19 @@ _XimLcctstombs(xim, from, from_len, to, to_len, state) } Public int +_XimLcctstombs(xim, from, from_len, to, to_len, state) + XIM xim; + char *from; + int from_len; + char *to; + int to_len; + Status *state; +{ + return _XimLcctsconvert(((Xim)xim)->private.local.ctom_conv, + from, from_len, to, to_len, state); +} + +Public int _XimLcctstowcs(xim, from, from_len, to, to_len, state) XIM xim; char *from; @@ -263,6 +333,7 @@ _XimLcctstowcs(xim, from, from_len, to, to_len, state) int to_cnvlen; char *from_buf; wchar_t *to_buf; + wchar_t scratchbuf[BUFSIZ]; Status tmp_state; if (!state) @@ -273,6 +344,10 @@ _XimLcctstowcs(xim, from, from_len, to, to_len, state) return 0; } + /* Reset the converter. The CompoundText at 'from' starts in + initial state. */ + _XlcResetConverter(conv); + if (to && to_len) { from_left = from_len; to_left = to_len; @@ -306,10 +381,10 @@ _XimLcctstowcs(xim, from, from_len, to, to_len, state) from_left = from_len; from_cnvlen = 0; to_cnvlen = 0; - to_buf = (wchar_t *)NULL; for (;;) { from_savelen = from_left; - to_left = MAXINT; + to_buf = scratchbuf; + to_left = BUFSIZ * sizeof(wchar_t); from_buf = &from[from_cnvlen]; if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left, (XPointer *)&to_buf, &to_left, NULL, 0) < 0) { @@ -317,7 +392,7 @@ _XimLcctstowcs(xim, from, from_len, to, to_len, state) return 0; } from_cnvlen += (from_savelen - from_left); - to_cnvlen += (MAXINT - to_left); + to_cnvlen += (BUFSIZ * sizeof(wchar_t) - to_left); if (from_left == 0) { if (to_cnvlen > 0) *state = XBufferOverflow; @@ -328,3 +403,16 @@ _XimLcctstowcs(xim, from, from_len, to, to_len, state) } return to_cnvlen; } + +Public int +_XimLcctstoutf8(xim, from, from_len, to, to_len, state) + XIM xim; + char *from; + int from_len; + char *to; + int to_len; + Status *state; +{ + return _XimLcctsconvert(((Xim)xim)->private.local.ctoutf8_conv, + from, from_len, to, to_len, state); +} |