Debian Codegraph @

nx-X11/lib/modules/im/ximcp/imThaiIc.c

raw
1 /******************************************************************
2
3 Copyright 1992, 1993, 1994 by FUJITSU LIMITED
4 Copyright 1993 by Digital Equipment Corporation
5
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 that
9 both that copyright notice and this permission notice appear in
10 supporting documentation, and that the name of FUJITSU LIMITED and
11 Digital Equipment Corporation not be used in advertising or publicity
12 pertaining to distribution of the software without specific, written
13 prior permission. FUJITSU LIMITED and Digital Equipment Corporation
14 makes no representations about the suitability of this software for
15 any purpose. It is provided "as is" without express or implied
16 warranty.
17
18 FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION DISCLAIM ALL
19 WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
20 WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
21 FUJITSU LIMITED AND DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
22 ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
23 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
24 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
25 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
26 THIS SOFTWARE.
27
28 Author: Takashi Fujiwara FUJITSU LIMITED
29 [email protected]
30 Modifier: Franky Ling Digital Equipment Corporation
31 [email protected]
32
33 ******************************************************************/
34
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38 #include <stdio.h>
39 #include <nx-X11/Xlib.h>
40 #include <nx-X11/Xmd.h>
41 #include "Xlibint.h"
42 #include "Xlcint.h"
43 #include "Ximint.h"
44
45 static void
46 _XimThaiUnSetFocus(
47 XIC xic)
48 {
49 Xic ic = (Xic)xic;
50 ((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL;
51
52 if (ic->core.focus_window)
53 _XUnregisterFilter(ic->core.im->core.display, ic->core.focus_window,
54 _XimThaiFilter, (XPointer)ic);
55 return;
56 }
57
58 static void
59 _XimThaiDestroyIC(
60 XIC xic)
61 {
62 Xic ic = (Xic)xic;
63 DefTreeBase *b = &ic->private.local.base;
64
65 if(((Xim)ic->core.im)->private.local.current_ic == (XIC)ic) {
66 _XimThaiUnSetFocus(xic);
67 }
68
69 Xfree(ic->private.local.ic_resources);
70 ic->private.local.ic_resources = NULL;
71
72 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 return;
84 }
85
86 static void
87 _XimThaiSetFocus(
88 XIC xic)
89 {
90 Xic ic = (Xic)xic;
91 XIC current_ic = ((Xim)ic->core.im)->private.local.current_ic;
92
93 if (current_ic == (XIC)ic)
94 return;
95
96 if (current_ic != (XIC)NULL) {
97 _XimThaiUnSetFocus(current_ic);
98 }
99 ((Xim)ic->core.im)->private.local.current_ic = (XIC)ic;
100
101 if (ic->core.focus_window)
102 _XRegisterFilterByType(ic->core.im->core.display, ic->core.focus_window,
103 KeyPress, KeyPress, _XimThaiFilter, (XPointer)ic);
104 return;
105 }
106
107 static void
108 _XimThaiReset(
109 XIC xic)
110 {
111 Xic ic = (Xic)xic;
112 DefTreeBase *b = &ic->private.local.base;
113 ic->private.local.thai.comp_state = 0;
114 ic->private.local.thai.keysym = 0;
115 b->mb[b->tree[ic->private.local.composed].mb] = '\0';
116 b->wc[b->tree[ic->private.local.composed].wc] = '\0';
117 b->utf8[b->tree[ic->private.local.composed].utf8] = '\0';
118 }
119
120 static char *
121 _XimThaiMbReset(
122 XIC xic)
123 {
124 _XimThaiReset(xic);
125 return (char *)NULL;
126 }
127
128 static wchar_t *
129 _XimThaiWcReset(
130 XIC xic)
131 {
132 _XimThaiReset(xic);
133 return (wchar_t *)NULL;
134 }
135
136 static XICMethodsRec Thai_ic_methods = {
137 _XimThaiDestroyIC, /* destroy */
138 _XimThaiSetFocus, /* set_focus */
139 _XimThaiUnSetFocus, /* unset_focus */
140 _XimLocalSetICValues, /* set_values */
141 _XimLocalGetICValues, /* get_values */
142 _XimThaiMbReset, /* mb_reset */
143 _XimThaiWcReset, /* wc_reset */
144 _XimThaiMbReset, /* utf8_reset */
145 _XimLocalMbLookupString, /* mb_lookup_string */
146 _XimLocalWcLookupString, /* wc_lookup_string */
147 _XimLocalUtf8LookupString /* utf8_lookup_string */
148 };
149
150 XIC
151 _XimThaiCreateIC(
152 XIM im,
153 XIMArg *values)
154 {
155 Xic ic;
156 XimDefICValues ic_values;
157 XIMResourceList res;
158 unsigned int num;
159 int len;
160 DefTree *tree;
161
162 if((ic = Xcalloc(1, sizeof(XicRec))) == (Xic)NULL) {
163 return ((XIC)NULL);
164 }
165
166 ic->methods = &Thai_ic_methods;
167 ic->core.im = im;
168 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 ic->private.local.context = 1;
179 tree[1].mb = 1;
180 tree[1].wc = 1;
181 tree[1].utf8 = 1;
182 ic->private.local.composed = 2;
183 tree[2].mb = 11;
184 tree[2].wc = 11;
185 tree[2].utf8 = 11;
186
187 ic->private.local.thai.comp_state = 0;
188 ic->private.local.thai.keysym = 0;
189 ic->private.local.thai.input_mode = 0;
190
191 num = im->core.ic_num_resources;
192 len = sizeof(XIMResource) * num;
193 if((res = Xmalloc(len)) == (XIMResourceList)NULL) {
194 goto Set_Error;
195 }
196 (void)memcpy((char *)res, (char *)im->core.ic_resources, len);
197 ic->private.local.ic_resources = res;
198 ic->private.local.ic_num_resources = num;
199
200 bzero((char *)&ic_values, sizeof(XimDefICValues));
201 if(_XimCheckLocalInputStyle(ic, (XPointer)&ic_values, values,
202 im->core.styles, res, num) == False) {
203 goto Set_Error;
204 }
205
206 _XimSetICMode(res, num, ic_values.input_style);
207
208 if(_XimSetICValueData(ic, (XPointer)&ic_values,
209 ic->private.local.ic_resources,
210 ic->private.local.ic_num_resources,
211 values, XIM_CREATEIC, True)) {
212 goto Set_Error;
213 }
214 if(_XimSetICDefaults(ic, (XPointer)&ic_values,
215 XIM_SETICDEFAULTS, res, num) == False) {
216 goto Set_Error;
217 }
218 ic_values.filter_events = KeyPressMask;
219 _XimSetCurrentICValues(ic, &ic_values);
220
221 return ((XIC)ic);
222
223 Set_Error :
224 if (ic->private.local.ic_resources) {
225 Xfree(ic->private.local.ic_resources);
226 }
227 Xfree(ic);
228 return((XIC)NULL);
229 }