comparison lib/InputConv.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: InputConv.c,v 1.17 1999/01/13 08:42:00 ishisone Exp $";
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 "InputConvP.h"
24
25 static XtResource resources[] = {
26 #define offset(field) XtOffset(InputConvObject, inputConv.field)
27 {XtNselectionControl, XtCCallback, XtRCallback, sizeof(XtCallbackList),
28 offset(selectioncallback), XtRCallback, (XtPointer)NULL},
29 {XtNtextChangeNotify, XtCCallback, XtRCallback, sizeof(XtCallbackList),
30 offset(textchangecallback), XtRCallback, (XtPointer)NULL},
31 {XtNmodeChangeNotify, XtCCallback, XtRCallback, sizeof(XtCallbackList),
32 offset(modechangecallback), XtRCallback, (XtPointer)NULL},
33 {XtNendNotify, XtCCallback, XtRCallback, sizeof(XtCallbackList),
34 offset(endcallback), XtRCallback, (XtPointer)NULL},
35 {XtNfixNotify, XtCCallback, XtRCallback, sizeof(XtCallbackList),
36 offset(fixcallback), XtRCallback, (XtPointer)NULL},
37 {XtNauxControl, XtCCallback, XtRCallback, sizeof(XtCallbackList),
38 offset(auxcallback), XtRCallback, (XtPointer)NULL},
39 {XtNdisplayObjectClass, XtCClass, XtRPointer, sizeof(WidgetClass),
40 offset(displayObjClass), XtRImmediate, (XtPointer)NULL },
41 #undef offset
42 };
43
44 static void ClassPartInitialize();
45 static void Initialize();
46 static void Destroy();
47
48 static int InputEvent();
49 static ICString *GetMode();
50 static int CursorPos();
51 static int NumSegments();
52 static ICString *GetSegment();
53 static int CompareSegment();
54 static ICString *GetItemList();
55 static int SelectItem();
56 static int ConvertedString();
57 static int Clear();
58 static ICString *GetAuxSegments();
59 static int GetTriggerKeys();
60 static int GetPreeditString();
61 static int GetStatusString();
62
63 InputConvClassRec inputConvClassRec = {
64 { /* object fields */
65 /* superclass */ (WidgetClass) &objectClassRec,
66 /* class_name */ "InputConv",
67 /* widget_size */ sizeof(InputConvRec),
68 /* class_initialize */ NULL,
69 /* class_part_initialize */ ClassPartInitialize,
70 /* class_inited */ FALSE,
71 /* initialize */ Initialize,
72 /* initialize_hook */ NULL,
73 /* obj1 */ NULL,
74 /* obj2 */ NULL,
75 /* obj3 */ 0,
76 /* resources */ resources,
77 /* num_resources */ XtNumber(resources),
78 /* xrm_class */ NULLQUARK,
79 /* obj4 */ FALSE,
80 /* obj5 */ FALSE,
81 /* obj6 */ FALSE,
82 /* obj7 */ FALSE,
83 /* destroy */ Destroy,
84 /* obj8 */ NULL,
85 /* obj9 */ NULL,
86 /* set_values */ NULL,
87 /* set_values_hook */ NULL,
88 /* obj10 */ NULL,
89 /* get_values_hook */ NULL,
90 /* obj11 */ NULL,
91 /* version */ XtVersion,
92 /* callback_private */ NULL,
93 /* obj12 */ NULL,
94 /* obj13 */ NULL,
95 /* obj14 */ NULL,
96 /* extension */ NULL,
97 },
98 { /* inputConv fields */
99 /* InputEvent */ InputEvent,
100 /* GetMode */ GetMode,
101 /* CursorPos */ CursorPos,
102 /* NumSegments */ NumSegments,
103 /* GetSegment */ GetSegment,
104 /* CompareSegment */ CompareSegment,
105 /* GetItemList */ GetItemList,
106 /* SelectItem */ SelectItem,
107 /* GetConvertedString */ ConvertedString,
108 /* ClearConversion */ Clear,
109 /* GetSegments */ GetAuxSegments,
110 /* SupportMultipleObjects */ False,
111 /* GetTriggerKeys */ GetTriggerKeys,
112 /* num_trigger_keys */ 0,
113 /* trigger_keys */ NULL,
114 /* GetPreeditString */ GetPreeditString,
115 /* GetStatusString */ GetStatusString,
116 /* NoMoreObjects */ False,
117 }
118 };
119
120 WidgetClass inputConvObjectClass = (WidgetClass)&inputConvClassRec;
121
122 static void
123 ClassPartInitialize(cl)
124 WidgetClass cl;
125 {
126 InputConvObjectClass class = (InputConvObjectClass)cl;
127 InputConvObjectClass super = (InputConvObjectClass)class->object_class.superclass;
128
129 if (class->inputConv_class.InputEvent == XtInheritInputEvent)
130 class->inputConv_class.InputEvent = super->inputConv_class.InputEvent;
131 if (class->inputConv_class.GetMode == XtInheritGetMode)
132 class->inputConv_class.GetMode = super->inputConv_class.GetMode;
133 if (class->inputConv_class.CursorPos == XtInheritCursorPos)
134 class->inputConv_class.CursorPos = super->inputConv_class.CursorPos;
135 if (class->inputConv_class.NumSegments == XtInheritNumSegments)
136 class->inputConv_class.NumSegments = super->inputConv_class.NumSegments;
137 if (class->inputConv_class.GetSegment == XtInheritGetSegment)
138 class->inputConv_class.GetSegment = super->inputConv_class.GetSegment;
139 if (class->inputConv_class.CompareSegment == XtInheritCompareSegment)
140 class->inputConv_class.CompareSegment = super->inputConv_class.CompareSegment;
141 if (class->inputConv_class.GetItemList == XtInheritGetItemList)
142 class->inputConv_class.GetItemList = super->inputConv_class.GetItemList;
143 if (class->inputConv_class.SelectItem == XtInheritSelectItem)
144 class->inputConv_class.SelectItem = super->inputConv_class.SelectItem;
145 if (class->inputConv_class.GetConvertedString == XtInheritGetConvertedString)
146 class->inputConv_class.GetConvertedString = super->inputConv_class.GetConvertedString;
147 if (class->inputConv_class.ClearConversion == XtInheritClearConversion)
148 class->inputConv_class.ClearConversion = super->inputConv_class.ClearConversion;
149 if (class->inputConv_class.GetAuxSegments == XtInheritGetAuxSegments)
150 class->inputConv_class.GetAuxSegments = super->inputConv_class.GetAuxSegments;
151 if (class->inputConv_class.GetTriggerKeys == XtInheritGetTriggerKeys)
152 class->inputConv_class.GetTriggerKeys = super->inputConv_class.GetTriggerKeys;
153 if (class->inputConv_class.GetPreeditString == XtInheritGetPreeditString)
154 class->inputConv_class.GetPreeditString = super->inputConv_class.GetPreeditString;
155 if (class->inputConv_class.GetStatusString == XtInheritGetStatusString)
156 class->inputConv_class.GetStatusString = super->inputConv_class.GetStatusString;
157
158 class->inputConv_class.NoMoreObjects = False;
159 }
160
161 /* ARGSUSED */
162 static void
163 Initialize(req, new, args, num_args)
164 Widget req;
165 Widget new;
166 ArgList args;
167 Cardinal *num_args;
168 {
169 InputConvObjectClass class = (InputConvObjectClass)new->core.widget_class;
170 String params[1];
171 Cardinal num_params;
172
173 if (class->inputConv_class.NoMoreObjects) {
174 params[0] = XtClass(new)->core_class.class_name;
175 num_params = 1;
176 XtAppErrorMsg(XtWidgetToApplicationContext(new),
177 "creationError", "widget", "WidgetError",
178 "Class %s cannot have multiple instances",
179 params, &num_params);
180 }
181 if (!class->inputConv_class.SupportMultipleObjects) {
182 class->inputConv_class.NoMoreObjects = True;
183 }
184 }
185
186 static void
187 Destroy(w)
188 Widget w;
189 {
190 InputConvObjectClass class = (InputConvObjectClass)w->core.widget_class;
191
192 class->inputConv_class.NoMoreObjects = False;
193 }
194
195 /* ARGSUSED */
196 static int
197 InputEvent(w, event)
198 Widget w;
199 XEvent *event;
200 {
201 XtAppError(XtWidgetToApplicationContext(w),
202 "InputConv Object: InputEvent function isn't defined.");
203 return -1; /* for lint */
204 }
205
206 /* ARGSUSED */
207 static ICString *
208 GetMode(w)
209 Widget w;
210 {
211 XtAppError(XtWidgetToApplicationContext(w),
212 "InputConv Object: GetMode function isn't defined.");
213 return NULL; /* for lint */
214 }
215
216 /* ARGSUSED */
217 static int
218 CursorPos(w, segidx, offset)
219 Widget w;
220 Cardinal *segidx;
221 Cardinal *offset;
222 {
223 XtAppError(XtWidgetToApplicationContext(w),
224 "InputConv Object: CursorPos function isn't defined.");
225 return 0; /* for lint */
226 }
227
228 /* ARGSUSED */
229 static int
230 NumSegments(w)
231 Widget w;
232 {
233 XtAppError(XtWidgetToApplicationContext(w),
234 "InputConv Object: NumSegments function isn't defined.");
235 return 0; /* for lint */
236 }
237
238 /* ARGSUSED */
239 static ICString *
240 GetSegment(w, n)
241 Widget w;
242 Cardinal n;
243 {
244 XtAppError(XtWidgetToApplicationContext(w),
245 "InputConv Object: GetSegment function isn't defined.");
246 return NULL; /* for lint */
247 }
248
249 /* ARGSUSED */
250 static int
251 CompareSegment(w, seg1, seg2, n)
252 Widget w;
253 ICString *seg1;
254 ICString *seg2;
255 Cardinal *n;
256 {
257 XtAppError(XtWidgetToApplicationContext(w),
258 "InputConv Object: CompareSegment function isn't defined.");
259 return 0; /* for lint */
260 }
261
262 /* ARGSUSED */
263 static ICString *
264 GetItemList(w, n)
265 Widget w;
266 Cardinal *n;
267 {
268 XtAppError(XtWidgetToApplicationContext(w),
269 "InputConv Object: GetItem function isn't defined.");
270 return NULL; /* for lint */
271 }
272
273 /* ARGSUSED */
274 static int
275 SelectItem(w, n)
276 Widget w;
277 int n;
278 {
279 XtAppError(XtWidgetToApplicationContext(w),
280 "InputConv Object: SelectItem function isn't defined.");
281 return -1; /* for lint */
282 }
283
284 /* ARGSUSED */
285 static int
286 ConvertedString(w, encoding, format, length, string)
287 Widget w;
288 Atom *encoding;
289 int *format;
290 int *length;
291 XtPointer *string;
292 {
293 XtAppError(XtWidgetToApplicationContext(w),
294 "InputConv Object: GetConvertedString function isn't defined.");
295 return -1; /* for lint */
296 }
297
298 /* ARGSUSED */
299 static int
300 Clear(w)
301 Widget w;
302 {
303 XtAppError(XtWidgetToApplicationContext(w),
304 "InputConv Object: ClearConversion function isn't defined.");
305 return -1; /* for lint */
306 }
307
308 /* ARGSUSED */
309 static ICString *
310 GetAuxSegments(w, n, ns, nc)
311 Widget w;
312 Cardinal *n, *ns, *nc;
313 {
314 XtAppError(XtWidgetToApplicationContext(w),
315 "InputConv Object: GetAuxSegments function isn't defined.");
316 return NULL; /* for lint */
317 }
318
319
320 /* ARGSUSED */
321 static int
322 GetTriggerKeys(w, keys_return)
323 Widget w;
324 ICTriggerKey **keys_return;
325 {
326 return 0;
327 }
328
329 /* ARGSUSED */
330 static int
331 GetPreeditString(w, segn, offset, encoding, format, length, string)
332 Widget w;
333 int segn;
334 int offset;
335 Atom *encoding;
336 int *format;
337 int *length;
338 XtPointer *string;
339 {
340 XtAppError(XtWidgetToApplicationContext(w),
341 "InputConv Object: GetPreeditString function isn't defined.");
342 return 0; /* for lint */
343 }
344
345 static int
346 GetStatusString(w, encoding, format, length, string, nchars)
347 Widget w;
348 Atom *encoding;
349 int *format;
350 int *length;
351 XtPointer *string;
352 int *nchars;
353 {
354 XtAppError(XtWidgetToApplicationContext(w),
355 "InputConv Object: GetStatusString function isn't defined.");
356 return 0; /* for lint */
357 }
358
359
360 /*
361 * public functions
362 */
363
364 Boolean
365 ICSupportMultipleObjects(cl)
366 WidgetClass cl;
367 {
368 InputConvObjectClass class = (InputConvObjectClass)cl;
369
370 /* check if specified class is a subclass of InputConvObjectClass */
371 while (cl != NULL) {
372 if (cl == inputConvObjectClass) {
373 /* OK */
374 XtInitializeWidgetClass(cl);
375 return class->inputConv_class.SupportMultipleObjects;
376 }
377 cl = cl->core_class.superclass;
378 }
379 return True; /* for almost all of other classes, it's True */
380 }
381
382 int
383 ICInputEvent(w, event)
384 Widget w;
385 XEvent *event;
386 {
387 InputConvObjectClass class = (InputConvObjectClass)w->core.widget_class;
388
389 XtCheckSubclass(w, inputConvObjectClass, "ICInputEvent()");
390 return (*class->inputConv_class.InputEvent)(w, event);
391 }
392
393 ICString *
394 ICGetMode(w)
395 Widget w;
396 {
397 InputConvObjectClass class = (InputConvObjectClass)w->core.widget_class;
398
399 XtCheckSubclass(w, inputConvObjectClass, "ICGetMode()");
400 return (*class->inputConv_class.GetMode)(w);
401 }
402
403 int
404 ICCursorPos(w, segidx, offset)
405 Widget w;
406 Cardinal *segidx;
407 Cardinal *offset;
408 {
409 InputConvObjectClass class = (InputConvObjectClass)w->core.widget_class;
410
411 XtCheckSubclass(w, inputConvObjectClass, "ICCursorPos()");
412 return (*class->inputConv_class.CursorPos)(w, segidx, offset);
413 }
414
415 int
416 ICNumSegments(w)
417 Widget w;
418 {
419 InputConvObjectClass class = (InputConvObjectClass)w->core.widget_class;
420
421 XtCheckSubclass(w, inputConvObjectClass, "ICNumSegments()");
422 return (*class->inputConv_class.NumSegments)(w);
423 }
424
425 ICString *
426 ICGetSegment(w, n)
427 Widget w;
428 Cardinal n;
429 {
430 InputConvObjectClass class = (InputConvObjectClass)w->core.widget_class;
431
432 XtCheckSubclass(w, inputConvObjectClass, "ICGetSegment()");
433 return (*class->inputConv_class.GetSegment)(w, n);
434 }
435
436 int
437 ICCompareSegment(w, seg1, seg2, n)
438 Widget w;
439 ICString *seg1;
440 ICString *seg2;
441 Cardinal *n;
442 {
443 InputConvObjectClass class = (InputConvObjectClass)w->core.widget_class;
444
445 XtCheckSubclass(w, inputConvObjectClass, "ICCompareSegment()");
446 return (*class->inputConv_class.CompareSegment)(w, seg1, seg2, n);
447 }
448
449 ICString *
450 ICGetItemList(w, n)
451 Widget w;
452 Cardinal *n;
453 {
454 InputConvObjectClass class = (InputConvObjectClass)w->core.widget_class;
455
456 XtCheckSubclass(w, inputConvObjectClass, "ICGetItemList()");
457 return (*class->inputConv_class.GetItemList)(w, n);
458 }
459
460 int
461 ICSelectItem(w, n)
462 Widget w;
463 int n;
464 {
465 InputConvObjectClass class = (InputConvObjectClass)w->core.widget_class;
466
467 XtCheckSubclass(w, inputConvObjectClass, "ICSelectItem()");
468 return (*class->inputConv_class.SelectItem)(w, n);
469 }
470
471 int
472 ICGetConvertedString(w, encoding, format, length, string)
473 Widget w;
474 Atom *encoding;
475 int *format;
476 int *length;
477 XtPointer *string;
478 {
479 InputConvObjectClass class = (InputConvObjectClass)w->core.widget_class;
480
481 XtCheckSubclass(w, inputConvObjectClass, "ICGetConvertedString()");
482 return (*class->inputConv_class.GetConvertedString)(w, encoding, format,
483 length, string);
484 }
485
486 int
487 ICClearConversion(w)
488 Widget w;
489 {
490 InputConvObjectClass class = (InputConvObjectClass)w->core.widget_class;
491
492 XtCheckSubclass(w, inputConvObjectClass, "ICClearConversion()");
493 return (*class->inputConv_class.ClearConversion)(w);
494 }
495
496 ICString *
497 ICGetAuxSegments(w, n, ns, nc)
498 Widget w;
499 Cardinal *n, *ns, *nc;
500 {
501 InputConvObjectClass class = (InputConvObjectClass)w->core.widget_class;
502
503 XtCheckSubclass(w, inputConvObjectClass, "ICGetAuxSegments()");
504 return (*class->inputConv_class.GetAuxSegments)(w, n, ns, nc);
505 }
506
507 int
508 ICGetPreeditString(w, segn, offset, encoding, format, length, string)
509 Widget w;
510 int segn;
511 int offset;
512 Atom *encoding;
513 int *format;
514 int *length;
515 XtPointer *string;
516 {
517 InputConvObjectClass class = (InputConvObjectClass)w->core.widget_class;
518
519 XtCheckSubclass(w, inputConvObjectClass, "ICGetPreeditString()");
520 return (*class->inputConv_class.GetPreeditString)(w, segn, offset, encoding, format, length, string);
521 }
522
523 int
524 ICGetStatusString(w, encoding, format, length, string, nchars)
525 Widget w;
526 Atom *encoding;
527 int *format;
528 int *length;
529 XtPointer *string;
530 int *nchars;
531 {
532 InputConvObjectClass class = (InputConvObjectClass)w->core.widget_class;
533
534 XtCheckSubclass(w, inputConvObjectClass, "ICGetStatusString()");
535 return (*class->inputConv_class.GetStatusString)(w, encoding, format, length, string, nchars);
536 }
537
538 /*
539
540 Though the following procedure should be done during initialization
541 of object class, I will do the following separately from the
542 initialization procedure in order to prevent duplicate
543 initialization of input object, that is, to prevent making
544 connection twice to input conversion server.
545
546 */
547
548 int
549 ICRegisterTriggerKeys(w)
550 Widget w;
551 {
552 InputConvObjectClass class = (InputConvObjectClass)w->core.widget_class;
553
554 XtCheckSubclass(w, inputConvObjectClass, "ICRegisterTriggerKeys()");
555 return class->inputConv_class.num_trigger_keys =
556 (*class->inputConv_class.GetTriggerKeys)
557 (w, &class->inputConv_class.trigger_keys);
558 }
559
560 int
561 ICGetTriggerKeysOfInputObjectClass(cl, keys_return)
562 WidgetClass cl;
563 ICTriggerKey **keys_return;
564 {
565 InputConvObjectClass class = (InputConvObjectClass)cl;
566
567 *keys_return = class->inputConv_class.trigger_keys;
568 return class->inputConv_class.num_trigger_keys;
569 }