aboutsummaryrefslogtreecommitdiff
path: root/libX11/modules/im/ximcp/imThaiFlt.c
diff options
context:
space:
mode:
Diffstat (limited to 'libX11/modules/im/ximcp/imThaiFlt.c')
-rw-r--r--libX11/modules/im/ximcp/imThaiFlt.c158
1 files changed, 97 insertions, 61 deletions
diff --git a/libX11/modules/im/ximcp/imThaiFlt.c b/libX11/modules/im/ximcp/imThaiFlt.c
index ac851963e..645f0e60f 100644
--- a/libX11/modules/im/ximcp/imThaiFlt.c
+++ b/libX11/modules/im/ximcp/imThaiFlt.c
@@ -28,13 +28,13 @@ Copyright 1993 by Digital Equipment Corporation, Maynard, Massachusetts.
All Rights Reserved
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted,
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in
+both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Digital not be
used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.
+software without specific, written prior permission.
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
@@ -48,20 +48,20 @@ SOFTWARE.
/* $XFree86: xc/lib/X11/imThaiFlt.c,v 3.22tsi Exp $ */
/*
-**++
-** FACILITY:
-**
-** Xlib
-**
-** ABSTRACT:
-**
+**++
+** FACILITY:
+**
+** Xlib
+**
+** ABSTRACT:
+**
** Thai specific functions.
** Handles character classifications, composibility checking,
** Input sequence check and other Thai specific requirements
** according to WTT specification and DEC extensions.
-**
-** MODIFICATION HISTORY:
-**
+**
+** MODIFICATION HISTORY:
+**
**/
#ifdef HAVE_CONFIG_H
@@ -318,17 +318,17 @@ THAI_istone (unsigned char ch)
Private Bool
THAI_iscomposible (
- unsigned char follow_ch,
+ unsigned char follow_ch,
unsigned char lead_ch)
{/* "Can follow_ch be put in the same display cell as lead_ch?" */
- return (write_rules_lookup[THAI_chtype(lead_ch)][THAI_chtype(follow_ch)]
+ return (write_rules_lookup[THAI_chtype(lead_ch)][THAI_chtype(follow_ch)]
== CP);
}
Private Bool
THAI_isaccepted (
- unsigned char follow_ch,
+ unsigned char follow_ch,
unsigned char lead_ch,
unsigned char mode)
{
@@ -337,11 +337,11 @@ THAI_isaccepted (
switch (mode)
{
case WTT_ISC1:
- iskeyvalid =
+ iskeyvalid =
(wtt_isc1_lookup[THAI_chtype(lead_ch)][THAI_chtype(follow_ch)] != RJ);
break;
case WTT_ISC2:
- iskeyvalid =
+ iskeyvalid =
(wtt_isc2_lookup[THAI_chtype(lead_ch)][THAI_chtype(follow_ch)] != RJ);
break;
case THAICAT_ISC:
@@ -357,15 +357,15 @@ THAI_isaccepted (
}
#ifdef UNUSED
-Private void
+Private void
THAI_apply_write_rules(
- unsigned char *instr,
- unsigned char *outstr,
- unsigned char insert_ch,
+ unsigned char *instr,
+ unsigned char *outstr,
+ unsigned char insert_ch,
int *num_insert_ch)
{
/*
-Input parameters:
+Input parameters:
instr - input string
insert_ch specify what char to be added when invalid composition is found
Output parameters:
@@ -389,8 +389,8 @@ Output parameters:
*out_ch++ = *lead_ch;
while (*follow_ch != '\0') /* more char in string to check */
{
- if (THAI_isdead(*follow_ch) &&
- !THAI_iscomposible(*follow_ch,*lead_ch))
+ if (THAI_isdead(*follow_ch) &&
+ !THAI_iscomposible(*follow_ch,*lead_ch))
{
*out_ch++ = SPACE;
(*num_insert_ch)++;
@@ -403,9 +403,9 @@ Output parameters:
}
}
-Private int
+Private int
THAI_find_chtype (
- unsigned char *instr,
+ unsigned char *instr,
int chtype)
{
/*
@@ -423,7 +423,7 @@ Output parameters:
case DEAD:
for (i = 0; *instr != '\0' && THAI_isdead(*instr); i++, instr++)
;
- if (*instr != '\0') position = i;
+ if (*instr != '\0') position = i;
break;
default:
break;
@@ -432,12 +432,12 @@ Output parameters:
}
-Private int
+Private int
THAI_apply_scm(
- unsigned char *instr,
- unsigned char *outstr,
- unsigned char spec_ch,
- int num_sp,
+ unsigned char *instr,
+ unsigned char *outstr,
+ unsigned char spec_ch,
+ int num_sp,
unsigned char insert_ch)
{
unsigned char *scan, *outch;
@@ -452,7 +452,7 @@ THAI_apply_scm(
if (THAI_isdead(*scan))
dead_count++; /* count number of non-spacing char */
if (*scan == spec_ch)
- if (!isconsecutive)
+ if (!isconsecutive)
found_count++; /* count number consecutive spec char found */
*outch++ = *scan++;
if (found_count == num_sp) {
@@ -474,7 +474,7 @@ Private void SetLed(Display *dpy, int num, int state);
Private CARD8 FindKeyCode();
-/* The following functions are specific to this module */
+/* The following functions are specific to this module */
Private int XThaiTranslateKey();
Private int XThaiTranslateKeySym();
@@ -560,13 +560,37 @@ IC_RealGetPreviousChar(Xic ic, unsigned short pos)
{
c = 0;
} else {
+ Xim im;
+ XlcConv conv;
+ int from_left;
+ int to_left;
+ char *from_buf;
+ char *to_buf;
+
+ im = (Xim) XIMOfIC((XIC)ic);
if (screc.text->encoding_is_wchar) {
- c = ucs2tis(screc.text->string.wcs[0]);
- XFree(screc.text->string.wcs);
+ conv = _XlcOpenConverter(im->core.lcd, XlcNWideChar,
+ im->core.lcd, XlcNCharSet);
+ from_buf = (char *) screc.text->string.wcs;
+ from_left = screc.text->length * sizeof(wchar_t);
} else {
- c = screc.text->string.mbs[0];
- XFree(screc.text->string.mbs);
+ conv = _XlcOpenConverter(im->core.lcd, XlcNMultiByte,
+ im->core.lcd, XlcNCharSet);
+ from_buf = screc.text->string.mbs;
+ from_left = screc.text->length;
+ }
+ to_buf = (char *)&c;
+ to_left = 1;
+
+ _XlcResetConverter(conv);
+ if (_XlcConvert(conv, (XPointer *)&from_buf, &from_left,
+ (XPointer *)&to_buf, &to_left, NULL, 0) < 0)
+ {
+ c = (unsigned char) b->mb[b->tree[(ic)->private.local.context].mb];
}
+ _XlcCloseConverter(conv);
+
+ XFree(screc.text->string.mbs);
}
XFree(screc.text);
return c;
@@ -794,12 +818,12 @@ XThaiTranslateKey(
}
/*
* ThaiCat keyboard support :
- * When the Shift and Thai keys are hold for some keys a 'Thai Compose'
+ * When the Shift and Thai keys are hold for some keys a 'Thai Compose'
* character code is generated which is different from column 3 and
- * 4 of the keymap.
+ * 4 of the keymap.
* Since we don't know whether ThaiCat keyboard or WTT keyboard is
* in use, the same mapping is done for all Thai input.
- * We just arbitary choose to use column 3 keysyms as the indices of
+ * We just arbitary choose to use column 3 keysyms as the indices of
* this mapping.
* When the control key is also hold, this mapping has no effect.
*/
@@ -817,7 +841,7 @@ XThaiTranslateKey(
return 1;
}
-/*
+/*
* XThaiTranslateKeySym
*
* Translate KeySym to TACTIS code output.
@@ -836,7 +860,7 @@ XThaiTranslateKeySym(
int nbytes)
{
KeySym ckey = 0;
- register struct _XKeytrans *p;
+ register struct _XKeytrans *p;
int length;
unsigned long hiBytes;
register unsigned char c;
@@ -913,8 +937,8 @@ XThaiTranslateKeySym(
}
/*
* ThaiCat has a key that generates two TACTIS codes D1 & E9.
- * It is represented by the latin-1 keysym XK_thorn (0xfe).
- * If c is XK_thorn, this key is pressed and it is converted to
+ * It is represented by the latin-1 keysym XK_thorn (0xfe).
+ * If c is XK_thorn, this key is pressed and it is converted to
* 0xd1 0xe9.
*/
if (c == XK_thorn) {
@@ -940,7 +964,7 @@ FindKeyCode(
register KeySym code)
{
- register KeySym *kmax = dpy->keysyms +
+ register KeySym *kmax = dpy->keysyms +
(dpy->max_keycode - dpy->min_keycode + 1) * dpy->keysyms_per_keycode;
register KeySym *k = dpy->keysyms;
while (k < kmax) {
@@ -990,8 +1014,8 @@ ComputeMaskFromKeytrans(
*
*
* Compose handling routines - compose handlers 0,1,2
- *
- *
+ *
+ *
************************************************************************/
#define NORMAL_KEY_STATE 0
@@ -1087,7 +1111,7 @@ int tactis_code;
hi_digit = ks1 - XK_a + 10;
else /* out of range */
return NoSymbol;
-
+
if ((ks2 >= XK_0) && (ks2 <= XK_9))
lo_digit = ks2 - XK_0;
else if ((ks2 >= XK_A) && (ks2 <= XK_F))
@@ -1156,7 +1180,7 @@ void SetLed(
#endif
/*
- * Initialize ISC mode from im modifier
+ * Initialize ISC mode from im modifier
*/
Private void InitIscMode(Xic ic)
{
@@ -1187,7 +1211,7 @@ Private void InitIscMode(Xic ic)
return;
}
-
+
/*
* Helper functions for _XimThaiFilter()
*/
@@ -1236,15 +1260,27 @@ ThaiFltReplaceInput(Xic ic, unsigned char new_char, KeySym symbol)
return True;
}
+Private unsigned
+NumLockMask(Display *d)
+{
+ int i;
+ XModifierKeymap *map = XGetModifierMapping (d);
+ KeyCode numlock_keycode = XKeysymToKeycode (d, XK_Num_Lock);
+ if (numlock_keycode == NoSymbol)
+ return 0;
+
+ for (i = 0; i < 8; i++) {
+ if (map->modifiermap[map->max_keypermod * i] == numlock_keycode)
+ return 1 << i;
+ }
+ return 0;
+}
+
/*
* Filter function for TACTIS
*/
Bool
-_XimThaiFilter(d, w, ev, client_data)
-Display *d;
-Window w;
-XEvent *ev;
-XPointer client_data;
+_XimThaiFilter(Display *d, Window w, XEvent *ev, XPointer client_data)
{
Xic ic = (Xic)client_data;
KeySym symbol;
@@ -1271,7 +1307,7 @@ XPointer client_data;
XwcLookupString((XIC)ic, &ev->xkey, wbuf, sizeof(wbuf) / sizeof(wbuf[0]),
&symbol, NULL);
- if ((ev->xkey.state & (AllMods & ~ShiftMask)) ||
+ if ((ev->xkey.state & (AllMods & ~(ShiftMask|LockMask|NumLockMask(d)))) ||
((symbol >> 8 == 0xFF) &&
((XK_BackSpace <= symbol && symbol <= XK_Clear) ||
(symbol == XK_Return) ||
@@ -1285,7 +1321,7 @@ XPointer client_data;
IsMiscFunctionKey(symbol) ||
IsFunctionKey(symbol))))
{
- IC_ClearPreviousChar(ic);
+ IC_ClearPreviousChar(ic);
return False;
}
if (((symbol >> 8 == 0xFF) &&
@@ -1304,7 +1340,7 @@ XPointer client_data;
return False;
/*
- * Hex input method processing
+ * Hex input method processing
*/
thai_part = &ic->private.local.thai;