imLcIc.c revision ebe525bc
1/******************************************************************
2
3                Copyright 1992,1993, 1994 by FUJITSU LIMITED
4
5Permission to use, copy, modify, distribute, and sell this software
6and its documentation for any purpose is hereby granted without fee,
7provided that the above copyright notice appear in all copies and
8that both that copyright notice and this permission notice appear
9in supporting documentation, and that the name of FUJITSU LIMITED
10not be used in advertising or publicity pertaining to distribution
11of the software without specific, written prior permission.
12FUJITSU LIMITED makes no representations about the suitability of
13this software for any purpose.
14It is provided "as is" without express or implied warranty.
15
16FUJITSU LIMITED DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18EVENT SHALL FUJITSU LIMITED BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
20USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22PERFORMANCE OF THIS SOFTWARE.
23
24  Author: Takashi Fujiwara     FUJITSU LIMITED
25                               fujiwara@a80.tech.yk.fujitsu.co.jp
26
27******************************************************************/
28
29#ifdef HAVE_CONFIG_H
30#include <config.h>
31#endif
32#include <stdio.h>
33#include <X11/Xlib.h>
34#include <X11/Xmd.h>
35#include "Xlibint.h"
36#include "Xlcint.h"
37#include "Ximint.h"
38
39static void
40_XimLocalUnSetFocus(
41    XIC	 xic)
42{
43    Xic  ic = (Xic)xic;
44    ((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL;
45
46    if (ic->core.focus_window)
47	_XUnregisterFilter(ic->core.im->core.display,
48			ic->core.focus_window, _XimLocalFilter, (XPointer)ic);
49    return;
50}
51
52static void
53_XimLocalDestroyIC(
54    XIC	 xic)
55{
56    Xic	 ic = (Xic)xic;
57
58    if(((Xim)ic->core.im)->private.local.current_ic == (XIC)ic) {
59	((Xim)ic->core.im)->private.local.current_ic = (XIC)NULL;
60    }
61    if (ic->core.focus_window)
62	_XUnregisterFilter(ic->core.im->core.display,
63			ic->core.focus_window, _XimLocalFilter, (XPointer)ic);
64
65    Xfree(ic->private.local.ic_resources);
66    ic->private.local.ic_resources = NULL;
67
68    Xfree(ic->core.res_name);
69    ic->core.res_name=NULL;
70
71    Xfree(ic->core.res_class);
72    ic->core.res_class = NULL;
73
74    return;
75}
76
77static void
78_XimLocalSetFocus(
79    XIC	 xic)
80{
81    Xic	 ic = (Xic)xic;
82    XIC	 current_ic = ((Xim)ic->core.im)->private.local.current_ic;
83
84    if (current_ic == (XIC)ic)
85	return;
86
87    if (current_ic != (XIC)NULL) {
88	_XimLocalUnSetFocus(current_ic);
89    }
90    ((Xim)ic->core.im)->private.local.current_ic = (XIC)ic;
91
92    if (ic->core.focus_window)
93	_XRegisterFilterByType(ic->core.im->core.display,
94			ic->core.focus_window, KeyPress, KeyRelease,
95			_XimLocalFilter, (XPointer)ic);
96    return;
97}
98
99static void
100_XimLocalReset(
101    XIC	 xic)
102{
103    Xic	 ic = (Xic)xic;
104    ic->private.local.composed       = 0;
105    ic->private.local.context        = ((Xim)ic->core.im)->private.local.top;
106    ic->private.local.brl_pressed    = 0;
107    ic->private.local.brl_committing = 0;
108    ic->private.local.brl_committed  = 0;
109}
110
111static char *
112_XimLocalMbReset(
113    XIC	 xic)
114{
115    _XimLocalReset(xic);
116    return (char *)NULL;
117}
118
119static wchar_t *
120_XimLocalWcReset(
121    XIC	 xic)
122{
123    _XimLocalReset(xic);
124    return (wchar_t *)NULL;
125}
126
127static XICMethodsRec Local_ic_methods = {
128    _XimLocalDestroyIC, 	/* destroy */
129    _XimLocalSetFocus,  	/* set_focus */
130    _XimLocalUnSetFocus,	/* unset_focus */
131    _XimLocalSetICValues,	/* set_values */
132    _XimLocalGetICValues,	/* get_values */
133    _XimLocalMbReset,		/* mb_reset */
134    _XimLocalWcReset,		/* wc_reset */
135    _XimLocalMbReset,		/* utf8_reset */
136    _XimLocalMbLookupString,	/* mb_lookup_string */
137    _XimLocalWcLookupString,	/* wc_lookup_string */
138    _XimLocalUtf8LookupString	/* utf8_lookup_string */
139};
140
141XIC
142_XimLocalCreateIC(
143    XIM			 im,
144    XIMArg		*values)
145{
146    Xic			 ic;
147    XimDefICValues	 ic_values={ 0 };
148    XIMResourceList	 res;
149    unsigned int	 num;
150    int			 len;
151
152    ic = Xcalloc(1, sizeof(XicRec));
153    if( ic  == (Xic)NULL) {
154	return ((XIC)NULL);
155    }
156
157    ic->methods = &Local_ic_methods;
158    ic->core.im = im;
159    ic->private.local.base           = ((Xim)im)->private.local.base;
160    ic->private.local.context        = ((Xim)im)->private.local.top;
161    ic->private.local.composed       = 0;
162    ic->private.local.brl_pressed    = 0;
163    ic->private.local.brl_committing = 0;
164    ic->private.local.brl_committed  = 0;
165
166    num = im->core.ic_num_resources;
167    len = sizeof(XIMResource) * num;
168    res = Xmalloc(len);
169    if( res  == (XIMResourceList)NULL) {
170	goto Set_Error;
171    }
172    (void)memcpy((char *)res, (char *)im->core.ic_resources, len);
173    ic->private.local.ic_resources     = res;
174    ic->private.local.ic_num_resources = num;
175
176     if(_XimCheckLocalInputStyle(ic, (XPointer)&ic_values, values,
177				 im->core.styles, res, num) == False) {
178	goto Set_Error;
179    }
180
181    _XimSetICMode(res, num, ic_values.input_style);
182
183    if(_XimSetICValueData(ic, (XPointer)&ic_values,
184			ic->private.local.ic_resources,
185			ic->private.local.ic_num_resources,
186			values, XIM_CREATEIC, True)) {
187	goto Set_Error;
188    }
189    ic_values.filter_events = KeyPressMask | KeyReleaseMask;
190    _XimSetCurrentICValues(ic, &ic_values);
191    if(_XimSetICDefaults(ic, (XPointer)&ic_values,
192				XIM_SETICDEFAULTS, res, num) == False) {
193	goto Set_Error;
194    }
195    _XimSetCurrentICValues(ic, &ic_values);
196
197    return((XIC)ic);
198
199Set_Error :
200
201    Xfree(ic->private.local.ic_resources);
202     ic->private.local.ic_resources = NULL;
203
204    Xfree(ic);
205    return((XIC)NULL);
206}
207