imThaiIc.c 6.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/******************************************************************

          Copyright 1992, 1993, 1994 by FUJITSU LIMITED
          Copyright 1993 by Digital Equipment Corporation

Permission to use, copy, modify, distribute, and sell this software
and its documentation for any purpose is hereby granted without fee,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of FUJITSU LIMITED and
Digital Equipment Corporation not be used in advertising or publicity
pertaining to distribution of the software without specific, written
prior permission.  FUJITSU LIMITED and Digital Equipment Corporation
makes no representations about the suitability of this software for
any purpose.  It is provided "as is" without express or implied
warranty.

18 19 20 21 22 23 24 25
FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION DISCLAIM ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
26 27
THIS SOFTWARE.

28
  Author:    Takashi Fujiwara     FUJITSU LIMITED
29 30 31 32 33 34 35 36 37 38
                               	  fujiwara@a80.tech.yk.fujitsu.co.jp
  Modifier:  Franky Ling          Digital Equipment Corporation
	                          frankyling@hgrd01.enet.dec.com

******************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
39 40
#include <nx-X11/Xlib.h>
#include <nx-X11/Xmd.h>
41 42 43 44
#include "Xlibint.h"
#include "Xlcint.h"
#include "Ximint.h"

45
static void
46 47 48 49 50 51 52 53 54 55 56 57
_XimThaiUnSetFocus(
    XIC	 xic)
{
    Xic  ic = (Xic)xic;
    ((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL;

    if (ic->core.focus_window)
	_XUnregisterFilter(ic->core.im->core.display, ic->core.focus_window,
			_XimThaiFilter, (XPointer)ic);
    return;
}

58
static void
59 60 61 62
_XimThaiDestroyIC(
    XIC	 xic)
{
    Xic	 ic = (Xic)xic;
63 64
    DefTreeBase *b = &ic->private.local.base;

65 66 67 68
    if(((Xim)ic->core.im)->private.local.current_ic == (XIC)ic) {
	_XimThaiUnSetFocus(xic);
    }

69 70 71 72
    Xfree(ic->private.local.ic_resources);
    ic->private.local.ic_resources = NULL;

    Xfree (b->tree);
73
    b->tree = NULL;
74 75

    Xfree (b->mb);
76
    b->mb   = NULL;
77 78

    Xfree (b->wc);
79
    b->wc   = NULL;
80 81

    Xfree (b->utf8);
82
    b->utf8 = NULL;
83 84 85
    return;
}

86
static void
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
_XimThaiSetFocus(
    XIC	 xic)
{
    Xic	 ic = (Xic)xic;
    XIC	 current_ic = ((Xim)ic->core.im)->private.local.current_ic;

    if (current_ic == (XIC)ic)
	return;

    if (current_ic != (XIC)NULL) {
	_XimThaiUnSetFocus(current_ic);
    }
    ((Xim)ic->core.im)->private.local.current_ic = (XIC)ic;

    if (ic->core.focus_window)
	_XRegisterFilterByType(ic->core.im->core.display, ic->core.focus_window,
			KeyPress, KeyPress, _XimThaiFilter, (XPointer)ic);
    return;
}

107
static void
108 109 110 111
_XimThaiReset(
    XIC	 xic)
{
    Xic	 ic = (Xic)xic;
112
    DefTreeBase *b   = &ic->private.local.base;
113 114
    ic->private.local.thai.comp_state = 0;
    ic->private.local.thai.keysym = 0;
115 116 117
    b->mb[b->tree[ic->private.local.composed].mb] = '\0';
    b->wc[b->tree[ic->private.local.composed].wc] = '\0';
    b->utf8[b->tree[ic->private.local.composed].utf8] = '\0';
118 119
}

120
static char *
121 122 123 124 125 126 127
_XimThaiMbReset(
    XIC	 xic)
{
    _XimThaiReset(xic);
    return (char *)NULL;
}

128
static wchar_t *
129 130 131 132 133 134 135
_XimThaiWcReset(
    XIC	 xic)
{
    _XimThaiReset(xic);
    return (wchar_t *)NULL;
}

136
static XICMethodsRec Thai_ic_methods = {
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
    _XimThaiDestroyIC, 	/* destroy */
    _XimThaiSetFocus,  	/* set_focus */
    _XimThaiUnSetFocus,	/* unset_focus */
    _XimLocalSetICValues,	/* set_values */
    _XimLocalGetICValues,	/* get_values */
    _XimThaiMbReset,		/* mb_reset */
    _XimThaiWcReset,		/* wc_reset */
    _XimThaiMbReset,		/* utf8_reset */
    _XimLocalMbLookupString,	/* mb_lookup_string */
    _XimLocalWcLookupString,	/* wc_lookup_string */
    _XimLocalUtf8LookupString	/* utf8_lookup_string */
};

XIC
_XimThaiCreateIC(
    XIM			 im,
    XIMArg		*values)
{
    Xic			 ic;
    XimDefICValues	 ic_values;
    XIMResourceList	 res;
    unsigned int	 num;
    int			 len;
160
    DefTree             *tree;
161

162
    if((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) {
163 164 165 166 167 168
	return ((XIC)NULL);
    }

    ic->methods = &Thai_ic_methods;
    ic->core.im = im;
    ic->core.filter_events = KeyPressMask;
169

170
    if (! (ic->private.local.base.tree = tree = Xmalloc(sizeof(DefTree)*3)) )
171
	goto Set_Error;
172
    if (! (ic->private.local.base.mb = Xmalloc(21)) )
173
	goto Set_Error;
174
    if (! (ic->private.local.base.wc = Xmalloc(sizeof(wchar_t)*21)) )
175
	goto Set_Error;
176
    if (! (ic->private.local.base.utf8 = Xmalloc(21)) )
177
	goto Set_Error;
178 179 180 181 182 183 184 185
    ic->private.local.context = 1;
    tree[1].mb   = 1;
    tree[1].wc   = 1;
    tree[1].utf8 = 1;
    ic->private.local.composed = 2;
    tree[2].mb   = 11;
    tree[2].wc   = 11;
    tree[2].utf8 = 11;
186 187 188 189 190 191 192

    ic->private.local.thai.comp_state = 0;
    ic->private.local.thai.keysym = 0;
    ic->private.local.thai.input_mode = 0;

    num = im->core.ic_num_resources;
    len = sizeof(XIMResource) * num;
193
    if((res = Xmalloc(len)) == (XIMResourceList)NULL) {
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
	goto Set_Error;
    }
    (void)memcpy((char *)res, (char *)im->core.ic_resources, len);
    ic->private.local.ic_resources     = res;
    ic->private.local.ic_num_resources = num;

    bzero((char *)&ic_values, sizeof(XimDefICValues));
    if(_XimCheckLocalInputStyle(ic, (XPointer)&ic_values, values,
				 im->core.styles, res, num) == False) {
	goto Set_Error;
    }

    _XimSetICMode(res, num, ic_values.input_style);

    if(_XimSetICValueData(ic, (XPointer)&ic_values,
			ic->private.local.ic_resources,
			ic->private.local.ic_num_resources,
			values, XIM_CREATEIC, True)) {
	goto Set_Error;
    }
    if(_XimSetICDefaults(ic, (XPointer)&ic_values,
				XIM_SETICDEFAULTS, res, num) == False) {
	goto Set_Error;
    }
    ic_values.filter_events = KeyPressMask;
    _XimSetCurrentICValues(ic, &ic_values);

    return ((XIC)ic);

Set_Error :
    if (ic->private.local.ic_resources) {
	Xfree(ic->private.local.ic_resources);
    }
    Xfree(ic);
    return((XIC)NULL);
}