comparison lib/ConvMgr.c @ 0:92745d501b9a

initial import from kinput2-v3.1
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Mon, 08 Mar 2010 04:44:30 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:92745d501b9a
1 #ifndef lint
2 static char *rcsid = "$Id: ConvMgr.c,v 1.8 1991/10/14 06:40:01 ishisone Rel $";
3 #endif
4 /*
5 * Copyright (c) 1990 Software Research Associates, Inc.
6 *
7 * Permission to use, copy, modify, and distribute this software and its
8 * documentation for any purpose and without fee is hereby granted, provided
9 * that the above copyright notice appear in all copies and that both that
10 * copyright notice and this permission notice appear in supporting
11 * documentation, and that the name of Software Research Associates not be
12 * used in advertising or publicity pertaining to distribution of the
13 * software without specific, written prior permission. Software Research
14 * Associates makes no representations about the suitability of this software
15 * for any purpose. It is provided "as is" without express or implied
16 * warranty.
17 *
18 * Author: Makoto Ishisone, Software Research Associates, Inc., Japan
19 */
20
21 #include <X11/IntrinsicP.h>
22 #include <X11/StringDefs.h>
23 #include "ConvMgrP.h"
24 #include "InputConv.h"
25 #include "ConvCtrl.h"
26
27 static void Initialize(), Destroy();
28
29 static Screen *getScreen();
30 static ConverterRec *newConverter();
31 static InputObjRec *getInputObjRec();
32 static InputObjRec *newInputObj();
33 static Boolean isSomeoneBusy();
34
35 static CompositeClassExtensionRec CompositeExtension = {
36 /* next_extension */ NULL,
37 /* record_type */ NULLQUARK,
38 /* version */ XtCompositeExtensionVersion,
39 /* record_size */ sizeof(CompositeClassExtensionRec),
40 /* accept_objects */ True,
41 };
42
43 ConversionManagerClassRec conversionManagerClassRec = {
44 { /* core fields */
45 /* superclass */ (WidgetClass) &compositeClassRec,
46 /* class_name */ "ConversionManager",
47 /* widget_size */ sizeof(ConversionManagerRec),
48 /* class_initialize */ NULL,
49 /* class_part_initialize */ NULL,
50 /* class_inited */ FALSE,
51 /* initialize */ Initialize,
52 /* initialize_hook */ NULL,
53 /* realize */ XtInheritRealize,
54 /* actions */ NULL,
55 /* num_actions */ 0,
56 /* resources */ NULL,
57 /* num_resources */ 0,
58 /* xrm_class */ NULLQUARK,
59 /* compress_motion */ TRUE,
60 /* compress_exposure */ TRUE,
61 /* compress_enterleave */ TRUE,
62 /* visible_interest */ FALSE,
63 /* destroy */ Destroy,
64 /* resize */ NULL,
65 /* expose */ NULL,
66 /* set_values */ NULL,
67 /* set_values_hook */ NULL,
68 /* set_values_almost */ XtInheritSetValuesAlmost,
69 /* get_values_hook */ NULL,
70 /* accept_focus */ NULL,
71 /* version */ XtVersion,
72 /* callback_private */ NULL,
73 /* tm_table */ NULL,
74 /* query_geometry */ XtInheritQueryGeometry,
75 /* display_accelerator */ XtInheritDisplayAccelerator,
76 /* extension */ NULL
77 },
78 { /* composite fields */
79 /* geometry_manager */ NULL,
80 /* change_managed */ NULL,
81 /* insert_child */ XtInheritInsertChild,
82 /* delete_child */ XtInheritDeleteChild,
83 /* extension */ (XtPointer)&CompositeExtension,
84 },
85 { /* conversionmanager fields */
86 /* empty */ 0
87 }
88 };
89
90 WidgetClass conversionManagerWidgetClass = (WidgetClass)&conversionManagerClassRec;
91
92 /* ARGSUSED */
93 static void
94 Initialize(req, new, args, num_args)
95 Widget req;
96 Widget new;
97 ArgList args;
98 Cardinal *num_args;
99 {
100 ConversionManagerWidget cmw = (ConversionManagerWidget)new;
101
102 cmw->convmgr.converterlist = NULL;
103 cmw->convmgr.inputobjlist = NULL;
104 }
105
106 static void
107 Destroy(w)
108 Widget w;
109 {
110 ConversionManagerWidget cmw = (ConversionManagerWidget)w;
111 ConverterRec *clist = cmw->convmgr.converterlist;
112 ConverterRec *crp;
113 InputObjRec *ilist = cmw->convmgr.inputobjlist;
114 InputObjRec *iorp;
115
116 while (clist != NULL) {
117 crp = clist->next;
118 XtFree((char *)clist);
119 clist = crp;
120 }
121 while (ilist != NULL) {
122 if (ilist->inputobj != NULL) XtDestroyWidget(ilist->inputobj);
123 iorp = ilist->next;
124 XtFree((char *)ilist);
125 ilist = iorp;
126 }
127 }
128
129 static Screen *
130 getScreen(dpy, win)
131 Display *dpy;
132 Window win;
133 {
134 Window root;
135 int reqx, reqy;
136 unsigned int reqwidth, reqheight, reqborder, junk;
137 int i;
138
139 /* get root window */
140 XGetGeometry(dpy, win, &root, &reqx, &reqy,
141 &reqwidth, &reqheight, &reqborder, &junk);
142
143 /* get screen of the root window */
144 for (i = 0; i < ScreenCount(dpy); i++) {
145 if (root == RootWindow(dpy, i)) return ScreenOfDisplay(dpy, i);
146 }
147
148 return NULL;
149 }
150
151 static ConverterRec *
152 newConverter(cmw, screen, converterclass, inputobjclass, displayobjclass)
153 ConversionManagerWidget cmw;
154 Screen *screen;
155 WidgetClass converterclass;
156 WidgetClass inputobjclass;
157 WidgetClass displayobjclass;
158 {
159 Arg args[5];
160 int i;
161 ConverterRec *crp;
162 InputObjRec *iorp;
163
164 crp = XtNew(ConverterRec);
165 crp->busy = False;
166 crp->converterclass = converterclass;
167 crp->inputobjclass = inputobjclass;
168 crp->displayobjclass = displayobjclass;
169 crp->screen = screen;
170
171 if ((iorp = getInputObjRec(cmw, inputobjclass)) == NULL) {
172 iorp = newInputObj(cmw, inputobjclass, displayobjclass);
173 }
174
175 i = 0;
176 if (screen != XtScreen((Widget)cmw)) {
177 XtSetArg(args[i], XtNscreen, screen); i++;
178 XtSetArg(args[i], XtNdepth, DefaultDepthOfScreen(screen)); i++;
179 XtSetArg(args[i], XtNcolormap, DefaultColormapOfScreen(screen)); i++;
180 }
181 if (iorp->inputobj != NULL) {
182 XtSetArg(args[i], XtNinputObject, iorp->inputobj); i++;
183 } else {
184 XtSetArg(args[i], XtNinputObjectClass, inputobjclass); i++;
185 }
186 XtSetArg(args[i], XtNdisplayObjectClass, displayobjclass); i++;
187
188 crp->converter = XtCreatePopupShell("converter", converterclass,
189 (Widget)cmw, args, i);
190
191 /* insert it to the list */
192 crp->next = cmw->convmgr.converterlist;
193 cmw->convmgr.converterlist = crp;
194
195 return crp;
196 }
197
198 static InputObjRec *
199 getInputObjRec(cmw, objclass)
200 ConversionManagerWidget cmw;
201 WidgetClass objclass;
202 {
203 InputObjRec *iorp = cmw->convmgr.inputobjlist;
204
205 while (iorp != NULL) {
206 if (iorp->inputobjclass == objclass) return iorp;
207 iorp = iorp->next;
208 }
209 return NULL;
210 }
211
212 static InputObjRec *
213 newInputObj(cmw, objclass, dispobjclass)
214 ConversionManagerWidget cmw;
215 WidgetClass objclass;
216 WidgetClass dispobjclass;
217 {
218 InputObjRec *iorp;
219
220 iorp = XtNew(InputObjRec);
221 iorp->inputobjclass = objclass;
222 if (!ICSupportMultipleObjects(objclass)) {
223 Arg args[1];
224
225 XtSetArg(args[0], XtNdisplayObjectClass, dispobjclass);
226 iorp->inputobj = XtCreateWidget("convObject", objclass,
227 (Widget)cmw, args, 1);
228 } else {
229 iorp->inputobj = NULL;
230 }
231
232 iorp->next = cmw->convmgr.inputobjlist;
233 cmw->convmgr.inputobjlist = iorp;
234 return iorp;
235 }
236
237 static Boolean
238 isSomeoneBusy(clist, objclass)
239 ConverterRec *clist;
240 WidgetClass objclass;
241 {
242 while (clist != NULL) {
243 if (clist->inputobjclass == objclass && clist->busy) return True;
244 clist = clist->next;
245 }
246 return False;
247 }
248
249
250 /*
251 * public functions
252 */
253
254 void
255 CMPrepareConverter(w, screen, converterclass, inputobjclass, displayobjclass)
256 Widget w;
257 Screen *screen;
258 WidgetClass converterclass;
259 WidgetClass inputobjclass;
260 WidgetClass displayobjclass;
261 {
262 XtCheckSubclass(w, conversionManagerWidgetClass, "CMPrepareConverter()");
263 (void)newConverter((ConversionManagerWidget)w, screen,
264 converterclass, inputobjclass, displayobjclass);
265 }
266
267 Widget
268 CMGetConverter(w, client, converterclass, inputobjclass, displayobjclass)
269 Widget w;
270 Window client;
271 WidgetClass converterclass;
272 WidgetClass inputobjclass;
273 WidgetClass displayobjclass;
274 {
275 ConversionManagerWidget cmw = (ConversionManagerWidget)w;
276 ConverterRec *clist = cmw->convmgr.converterlist;
277 ConverterRec *crp;
278 InputObjRec *iorp;
279 Screen *scr;
280
281 XtCheckSubclass(w, conversionManagerWidgetClass, "CMGetConverter()");
282
283 if ((iorp = getInputObjRec(cmw, inputobjclass)) == NULL) {
284 iorp = newInputObj(cmw, inputobjclass, displayobjclass);
285 } else if (iorp->inputobj != NULL && isSomeoneBusy(clist, inputobjclass)) {
286 return NULL;
287 }
288
289 if ((scr = getScreen(XtDisplay(w), client)) == NULL) {
290 String params[1];
291 Cardinal num_params;
292
293 params[0] = XtClass(w)->core_class.class_name;
294 num_params = 1;
295 XtAppWarningMsg(XtWidgetToApplicationContext(w),
296 "parameterError", "cannotGetScreen", "WidgetError",
297 "%s: CMGetConverter() cannot get screen of specified client window",
298 params, &num_params);
299 return NULL;
300 }
301
302 while (clist != NULL) {
303 if (!clist->busy &&
304 clist->screen == scr &&
305 clist->converterclass == converterclass &&
306 clist->inputobjclass == inputobjclass &&
307 clist->displayobjclass == displayobjclass) {
308 /* found */
309 clist->busy = True;
310 return clist->converter;
311 }
312 clist = clist->next;
313 }
314
315 crp = newConverter(cmw, scr, converterclass,
316 inputobjclass, displayobjclass);
317 crp->busy = True;
318 return crp->converter;
319 }
320
321 void
322 CMReleaseConverter(w, converter)
323 Widget w;
324 Widget converter;
325 {
326 ConversionManagerWidget cmw = (ConversionManagerWidget)w;
327 ConverterRec *clist = cmw->convmgr.converterlist;
328 String params[1];
329 Cardinal num_params;
330
331 XtCheckSubclass(w, conversionManagerWidgetClass, "CMReleaseConverter()");
332
333 while (clist != NULL) {
334 if (clist->converter == converter) {
335 if (!clist->busy) {
336 params[0] = XtClass(w)->core_class.class_name;
337 num_params = 1;
338 XtAppWarningMsg(XtWidgetToApplicationContext(w),
339 "parameterError", "converterNotBusy",
340 "WidgetError",
341 "%s: CMReleaseConverter() converter isn't used",
342 params, &num_params);
343 }
344 clist->busy = False;
345 return;
346 }
347 clist = clist->next;
348 }
349
350 params[0] = XtClass(w)->core_class.class_name;
351 num_params = 1;
352 XtAppWarningMsg(XtWidgetToApplicationContext(w),
353 "parameterError", "noSuchConverter", "WidgetError",
354 "%s: CMReleaseConverter() no such converter",
355 params, &num_params);
356 }