1 /* $XConsortium: Vendor.c,v 1.27 94/04/17 20:13:25 kaleb Exp $ */
2
3 /***********************************************************
4
5 Copyright (c) 1987, 1988, 1994 X Consortium
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24 Except as contained in this notice, the name of the X Consortium shall not be
25 used in advertising or otherwise to promote the sale, use or other dealings
26 in this Software without prior written authorization from the X Consortium.
27
28
29 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
30
31 All Rights Reserved
32
33 Permission to use, copy, modify, and distribute this software and its
34 documentation for any purpose and without fee is hereby granted,
35 provided that the above copyright notice appear in all copies and that
36 both that copyright notice and this permission notice appear in
37 supporting documentation, and that the name of Digital not be
38 used in advertising or publicity pertaining to distribution of the
39 software without specific, written prior permission.
40
41 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
42 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
43 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
44 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
45 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
46 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47 SOFTWARE.
48
49 ******************************************************************/
50
51 /*
52 * Portions Copyright (c) 1996 Alfredo Kojima
53 * Rights, permissions, and disclaimer per the above X Consortium license.
54 */
55
56 /*
57 * This is a copy of Xt/Vendor.c with an additional ClassInitialize
58 * procedure to register Xmu resource type converters, and all the
59 * monkey business associated with input methods...
60 *
61 */
62
63 /* Make sure all wm properties can make it out of the resource manager */
64
65 #include "Xaw3dP.h"
66 #include <stdio.h>
67 #include <X11/IntrinsicP.h>
68 #include <X11/StringDefs.h>
69 #include <X11/ShellP.h>
70 #include <X11/VendorP.h>
71 #include <X11/Xmu/Converters.h>
72 #include <X11/Xmu/Atoms.h>
73 #include <X11/Xmu/Editres.h>
74 #ifdef XAW_INTERNATIONALIZATION
75 #include <X11/Xmu/ExtAgent.h>
76 #endif
77 #ifdef XAW_MULTIPLANE_PIXMAPS
78 #include <X11/xpm.h>
79 #include <X11/Xmu/Drawing.h>
80 #endif
81
82 /* The following two headers are for the input method. */
83 #ifdef XAW_INTERNATIONALIZATION
84 #include <X11/Xaw3d/VendorEP.h>
85 #include <X11/Xaw3d/XawImP.h>
86 #endif
87
88
89 static XtResource resources[] = {
90 {XtNinput, XtCInput, XtRBool, sizeof(Bool),
91 XtOffsetOf(VendorShellRec, wm.wm_hints.input),
92 XtRImmediate, (XtPointer)True}
93 };
94
95 /***************************************************************************
96 *
97 * Vendor shell class record
98 *
99 ***************************************************************************/
100
101 static void XawVendorShellClassInitialize();
102 static void XawVendorShellInitialize();
103 static Boolean XawVendorShellSetValues();
104 static void Realize(), ChangeManaged();
105 static XtGeometryResult GeometryManager();
106 #ifdef XAW_INTERNATIONALIZATION
107 static void XawVendorShellClassPartInit();
108 void XawVendorShellExtResize();
109 #endif
110
111 #ifdef XAW_INTERNATIONALIZATION
112 static CompositeClassExtensionRec vendorCompositeExt = {
113 /* next_extension */ NULL,
114 /* record_type */ NULLQUARK,
115 /* version */ XtCompositeExtensionVersion,
116 /* record_size */ sizeof (CompositeClassExtensionRec),
117 /* accepts_objects */ TRUE,
118 /* allows_change_managed_set */ FALSE
119 };
120 #endif
121
122 #define SuperClass (&wmShellClassRec)
123 externaldef(vendorshellclassrec) VendorShellClassRec vendorShellClassRec = {
124 {
125 /* superclass */ (WidgetClass)SuperClass,
126 /* class_name */ "VendorShell",
127 /* size */ sizeof(VendorShellRec),
128 /* class_initialize */ XawVendorShellClassInitialize,
129 #ifdef XAW_INTERNATIONALIZATION
130 /* class_part_init */ XawVendorShellClassPartInit,
131 #else
132 /* class_part_init */ NULL,
133 #endif
134 /* Class init'ed ? */ FALSE,
135 /* initialize */ XawVendorShellInitialize,
136 /* initialize_hook */ NULL,
137 /* realize */ Realize,
138 /* actions */ NULL,
139 /* num_actions */ 0,
140 /* resources */ resources,
141 /* resource_count */ XtNumber(resources),
142 /* xrm_class */ NULLQUARK,
143 /* compress_motion */ FALSE,
144 /* compress_exposure */ TRUE,
145 /* compress_enterleave*/ FALSE,
146 /* visible_interest */ FALSE,
147 /* destroy */ NULL,
148 #ifdef XAW_INTERNATIONALIZATION
149 /* resize */ XawVendorShellExtResize,
150 #else
151 /* resize */ XtInheritResize,
152 #endif
153 /* expose */ NULL,
154 /* set_values */ XawVendorShellSetValues,
155 /* set_values_hook */ NULL,
156 /* set_values_almost */ XtInheritSetValuesAlmost,
157 /* get_values_hook */ NULL,
158 /* accept_focus */ NULL,
159 /* intrinsics version */ XtVersion,
160 /* callback offsets */ NULL,
161 /* tm_table */ NULL,
162 /* query_geometry */ NULL,
163 /* display_accelerator*/ NULL,
164 /* extension */ NULL
165 },{
166 /* geometry_manager */ GeometryManager,
167 /* change_managed */ ChangeManaged,
168 /* insert_child */ XtInheritInsertChild,
169 /* delete_child */ XtInheritDeleteChild,
170 #ifdef XAW_INTERNATIONALIZATION
171 /* extension */ (XtPointer) &vendorCompositeExt
172 #else
173 /* extension */ NULL
174 #endif
175 },{
176 /* extension */ NULL
177 },{
178 /* extension */ NULL
179 },{
180 /* extension */ NULL
181 }
182 };
183
184 externaldef(vendorshellwidgetclass) WidgetClass vendorShellWidgetClass =
185 (WidgetClass) (&vendorShellClassRec);
186
187
188 #ifdef XAW_INTERNATIONALIZATION
189 /***************************************************************************
190 *
191 * The following section is for the Vendor shell Extension class record
192 *
193 ***************************************************************************/
194
195 static XtResource ext_resources[] = {
196 {XtNinputMethod, XtCInputMethod, XtRString, sizeof(String),
197 XtOffsetOf(XawVendorShellExtRec, vendor_ext.im.input_method),
198 XtRString, (XtPointer)NULL},
199 {XtNpreeditType, XtCPreeditType, XtRString, sizeof(String),
200 XtOffsetOf(XawVendorShellExtRec, vendor_ext.im.preedit_type),
201 XtRString, (XtPointer)"OverTheSpot,OffTheSpot,Root"},
202 {XtNopenIm, XtCOpenIm, XtRBoolean, sizeof(Boolean),
203 XtOffsetOf(XawVendorShellExtRec, vendor_ext.im.open_im),
204 XtRImmediate, (XtPointer)TRUE},
205 {XtNsharedIc, XtCSharedIc, XtRBoolean, sizeof(Boolean),
206 XtOffsetOf(XawVendorShellExtRec, vendor_ext.ic.shared_ic),
207 XtRImmediate, (XtPointer)FALSE}
208 };
209
210 static void XawVendorShellExtClassInitialize();
211 static void XawVendorShellExtInitialize();
212 static void XawVendorShellExtDestroy();
213 static Boolean XawVendorShellExtSetValues();
214
215 externaldef(vendorshellextclassrec) XawVendorShellExtClassRec
216 xawvendorShellExtClassRec = {
217 {
218 /* superclass */ (WidgetClass)&objectClassRec,
219 /* class_name */ "VendorShellExt",
220 /* size */ sizeof(XawVendorShellExtRec),
221 /* class_initialize */ XawVendorShellExtClassInitialize,
222 /* class_part_initialize*/ NULL,
223 /* Class init'ed ? */ FALSE,
224 /* initialize */ XawVendorShellExtInitialize,
225 /* initialize_hook */ NULL,
226 /* pad */ NULL,
227 /* pad */ NULL,
228 /* pad */ 0,
229 /* resources */ ext_resources,
230 /* resource_count */ XtNumber(ext_resources),
231 /* xrm_class */ NULLQUARK,
232 /* pad */ FALSE,
233 /* pad */ FALSE,
234 /* pad */ FALSE,
235 /* pad */ FALSE,
236 /* destroy */ XawVendorShellExtDestroy,
237 /* pad */ NULL,
238 /* pad */ NULL,
239 /* set_values */ XawVendorShellExtSetValues,
240 /* set_values_hook */ NULL,
241 /* pad */ NULL,
242 /* get_values_hook */ NULL,
243 /* pad */ NULL,
244 /* version */ XtVersion,
245 /* callback_offsets */ NULL,
246 /* pad */ NULL,
247 /* pad */ NULL,
248 /* pad */ NULL,
249 /* extension */ NULL
250 },{
251 /* extension */ NULL
252 }
253 };
254
255 externaldef(xawvendorshellwidgetclass) WidgetClass
256 xawvendorShellExtWidgetClass = (WidgetClass) (&xawvendorShellExtClassRec);
257 #endif
258
259
260 /*ARGSUSED*/
261 static Boolean
XawCvtCompoundTextToString(dpy,args,num_args,fromVal,toVal,cvt_data)262 XawCvtCompoundTextToString(dpy, args, num_args, fromVal, toVal, cvt_data)
263 Display *dpy;
264 XrmValuePtr args;
265 Cardinal *num_args;
266 XrmValue *fromVal;
267 XrmValue *toVal;
268 XtPointer *cvt_data;
269 {
270 XTextProperty prop;
271 char **list;
272 int count;
273 static char *mbs = NULL;
274 int len;
275
276 prop.value = (unsigned char *)fromVal->addr;
277 prop.encoding = XA_COMPOUND_TEXT(dpy);
278 prop.format = 8;
279 prop.nitems = fromVal->size;
280
281 if(XmbTextPropertyToTextList(dpy, &prop, &list, &count) < Success) {
282 XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
283 "converter", "XmbTextPropertyToTextList", "XawError",
284 "conversion from CT to MB failed.", NULL, 0);
285 return False;
286 }
287 len = strlen(*list);
288 toVal->size = len;
289 mbs = XtRealloc(mbs, len + 1); /* keep buffer because no one call free :( */
290 strcpy(mbs, *list);
291 XFreeStringList(list);
292 toVal->addr = (XtPointer)mbs;
293 return True;
294 }
295
296 #ifdef XAW_MULTIPLANE_PIXMAPS
297 #define DONE(type, address) \
298 {to->size = sizeof(type); to->addr = (XPointer)address;}
299
300 /* ARGSUSED */
301 static Boolean
_XawCvtStringToPixmap(dpy,args,nargs,from,to,data)302 _XawCvtStringToPixmap(dpy, args, nargs, from, to, data)
303 Display *dpy;
304 XrmValuePtr args;
305 Cardinal *nargs;
306 XrmValuePtr from, to;
307 XtPointer *data;
308 {
309 static Pixmap pixmap;
310 Window win;
311 XpmAttributes attr;
312 XpmColorSymbol colors[1];
313
314 if (*nargs != 3)
315 XtAppErrorMsg(XtDisplayToApplicationContext(dpy),
316 "_XawCvtStringToPixmap", "wrongParameters", "XtToolkitError",
317 "_XawCvtStringToPixmap needs screen, colormap, and background_pixel",
318 (String *) NULL, (Cardinal *) NULL);
319
320 if (strcmp(from->addr, "None") == 0)
321 {
322 pixmap = None;
323 DONE(Pixmap, &pixmap);
324 return (True);
325 }
326 if (strcmp(from->addr, "ParentRelative") == 0)
327 {
328 pixmap = ParentRelative;
329 DONE(Pixmap, &pixmap);
330 return (True);
331 }
332
333 win = RootWindowOfScreen(*((Screen **) args[0].addr));
334
335 attr.colormap = *((Colormap *) args[1].addr);
336 attr.closeness = 32768; /* might help on 8-bpp displays? */
337 attr.valuemask = XpmColormap | XpmCloseness;
338
339 colors[0].name = NULL;
340 colors[0].value = "none";
341 colors[0].pixel = *((Pixel *) args[2].addr);
342 attr.colorsymbols = colors;
343 attr.numsymbols = 1;
344 attr.valuemask |= XpmColorSymbols;
345
346 if (XpmReadFileToPixmap(dpy, win, (String) from->addr,
347 &pixmap, NULL, &attr) != XpmSuccess)
348 {
349 if ((pixmap = XmuLocateBitmapFile(*((Screen **) args[0].addr),
350 (char *)from->addr, NULL, 0, NULL, NULL, NULL, NULL)) == None)
351 {
352 XtDisplayStringConversionWarning(dpy, (String) from->addr,
353 XtRPixmap);
354 return (False);
355 }
356 }
357
358 if (to->addr == NULL)
359 to->addr = (XtPointer) & pixmap;
360 else
361 {
362 if (to->size < sizeof(Pixmap))
363 {
364 to->size = sizeof(Pixmap);
365 XtDisplayStringConversionWarning(dpy, (String) from->addr,
366 XtRPixmap);
367 return (False);
368 }
369
370 *((Pixmap *) to->addr) = pixmap;
371 }
372 to->size = sizeof(Pixmap);
373 return (True);
374 }
375 #endif
376
XawVendorShellClassInitialize()377 static void XawVendorShellClassInitialize()
378 {
379 static XtConvertArgRec screenConvertArg[] = {
380 {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.screen),
381 sizeof(Screen *)}
382 };
383 #ifdef XAW_MULTIPLANE_PIXMAPS
384 static XtConvertArgRec _XawCvtStrToPix[] = {
385 {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.screen),
386 sizeof(Screen *)},
387 {XtWidgetBaseOffset, (XtPointer)XtOffsetOf(WidgetRec, core.colormap),
388 sizeof(Colormap)},
389 {XtWidgetBaseOffset,
390 (XtPointer)XtOffsetOf(WidgetRec, core.background_pixel),
391 sizeof(Pixel)}
392 };
393 #endif
394
395 XtAddConverter(XtRString, XtRCursor, XmuCvtStringToCursor,
396 screenConvertArg, XtNumber(screenConvertArg));
397
398 #ifdef XAW_MULTIPLANE_PIXMAPS
399 XtSetTypeConverter(XtRString, XtRBitmap,
400 (XtTypeConverter)_XawCvtStringToPixmap,
401 _XawCvtStrToPix, XtNumber(_XawCvtStrToPix),
402 XtCacheByDisplay, (XtDestructor)NULL);
403 #else
404 XtAddConverter(XtRString, XtRBitmap, XmuCvtStringToBitmap,
405 screenConvertArg, XtNumber(screenConvertArg));
406 #endif
407
408 XtSetTypeConverter("CompoundText", XtRString, XawCvtCompoundTextToString,
409 NULL, 0, XtCacheNone, NULL);
410 }
411
412 #ifdef XAW_INTERNATIONALIZATION
XawVendorShellClassPartInit(class)413 static void XawVendorShellClassPartInit(class)
414 WidgetClass class;
415 {
416 CompositeClassExtension ext;
417 VendorShellWidgetClass vsclass = (VendorShellWidgetClass) class;
418
419 if ((ext = (CompositeClassExtension)
420 XtGetClassExtension (class,
421 XtOffsetOf(CompositeClassRec,
422 composite_class.extension),
423 NULLQUARK, 1L, (Cardinal) 0)) == NULL) {
424 ext = (CompositeClassExtension) XtNew (CompositeClassExtensionRec);
425 if (ext != NULL) {
426 ext->next_extension = vsclass->composite_class.extension;
427 ext->record_type = NULLQUARK;
428 ext->version = XtCompositeExtensionVersion;
429 ext->record_size = sizeof (CompositeClassExtensionRec);
430 ext->accepts_objects = TRUE;
431 ext->allows_change_managed_set = FALSE;
432 vsclass->composite_class.extension = (XtPointer) ext;
433 }
434 }
435 }
436 #endif
437
438 #ifdef __osf__
439 /* stupid OSF/1 shared libraries have the wrong semantics */
440 /* symbols do not get resolved external to the shared library */
_XawFixupVendorShell()441 void _XawFixupVendorShell()
442 {
443 transientShellWidgetClass->core_class.superclass =
444 (WidgetClass) &vendorShellClassRec;
445 topLevelShellWidgetClass->core_class.superclass =
446 (WidgetClass) &vendorShellClassRec;
447 }
448 #endif
449
450 /* ARGSUSED */
XawVendorShellInitialize(req,new,args,num_args)451 static void XawVendorShellInitialize(req, new, args, num_args)
452 Widget req, new;
453 ArgList args;
454 Cardinal *num_args;
455 {
456 XtAddEventHandler(new, (EventMask) 0, TRUE, _XEditResCheckMessages, NULL);
457 #ifdef XAW_INTERNATIONALIZATION
458 XtAddEventHandler(new, (EventMask) 0, TRUE, XmuRegisterExternalAgent, NULL);
459 XtCreateWidget("shellext", xawvendorShellExtWidgetClass,
460 new, args, *num_args);
461 #endif
462 }
463
464 /* ARGSUSED */
XawVendorShellSetValues(old,ref,new)465 static Boolean XawVendorShellSetValues(old, ref, new)
466 Widget old, ref, new;
467 {
468 return FALSE;
469 }
470
Realize(wid,vmask,attr)471 static void Realize(wid, vmask, attr)
472 Widget wid;
473 Mask *vmask;
474 XSetWindowAttributes *attr;
475 {
476 WidgetClass super = wmShellWidgetClass;
477
478 /* Make my superclass do all the dirty work */
479
480 (*super->core_class.realize) (wid, vmask, attr);
481 #ifdef XAW_INTERNATIONALIZATION
482 _XawImRealize(wid);
483 #endif
484 }
485
486
487 #ifdef XAW_INTERNATIONALIZATION
XawVendorShellExtClassInitialize()488 static void XawVendorShellExtClassInitialize()
489 {
490 }
491
492 /* ARGSUSED */
XawVendorShellExtInitialize(req,new)493 static void XawVendorShellExtInitialize(req, new)
494 Widget req, new;
495 {
496 _XawImInitialize(new->core.parent, new);
497 }
498
499 /* ARGSUSED */
XawVendorShellExtDestroy(w)500 static void XawVendorShellExtDestroy( w )
501 Widget w;
502 {
503 _XawImDestroy( w->core.parent, w );
504 }
505
506 /* ARGSUSED */
XawVendorShellExtSetValues(old,ref,new)507 static Boolean XawVendorShellExtSetValues(old, ref, new)
508 Widget old, ref, new;
509 {
510 return FALSE;
511 }
512
XawVendorShellExtResize(w)513 void XawVendorShellExtResize( w )
514 Widget w;
515 {
516 ShellWidget sw = (ShellWidget) w;
517 Widget childwid;
518 int i;
519 int core_height;
520
521 _XawImResizeVendorShell( w );
522 core_height = _XawImGetShellHeight( w );
523 for( i = 0; i < sw->composite.num_children; i++ ) {
524 if( XtIsManaged( sw->composite.children[ i ] ) ) {
525 childwid = sw->composite.children[ i ];
526 XtResizeWidget( childwid, sw->core.width, core_height,
527 childwid->core.border_width );
528 }
529 }
530 }
531 #endif
532
533 /*ARGSUSED*/
GeometryManager(wid,request,reply)534 static XtGeometryResult GeometryManager( wid, request, reply )
535 Widget wid;
536 XtWidgetGeometry *request;
537 XtWidgetGeometry *reply;
538 {
539 ShellWidget shell = (ShellWidget)(wid->core.parent);
540 XtWidgetGeometry my_request;
541
542 if(shell->shell.allow_shell_resize == FALSE && XtIsRealized(wid))
543 return(XtGeometryNo);
544
545 if (request->request_mode & (CWX | CWY))
546 return(XtGeometryNo);
547
548 /* %%% worry about XtCWQueryOnly */
549 my_request.request_mode = 0;
550 if (request->request_mode & CWWidth) {
551 my_request.width = request->width;
552 my_request.request_mode |= CWWidth;
553 }
554 if (request->request_mode & CWHeight) {
555 my_request.height = request->height
556 #ifdef XAW_INTERNATIONALIZATION
557 + _XawImGetImAreaHeight( wid )
558 #endif
559 ;
560 my_request.request_mode |= CWHeight;
561 }
562 if (request->request_mode & CWBorderWidth) {
563 my_request.border_width = request->border_width;
564 my_request.request_mode |= CWBorderWidth;
565 }
566 if (XtMakeGeometryRequest((Widget)shell, &my_request, NULL)
567 == XtGeometryYes) {
568 /* assert: if (request->request_mode & CWWidth) then
569 * shell->core.width == request->width
570 * assert: if (request->request_mode & CWHeight) then
571 * shell->core.height == request->height
572 *
573 * so, whatever the WM sized us to (if the Shell requested
574 * only one of the two) is now the correct child size
575 */
576
577 wid->core.width = shell->core.width;
578 wid->core.height = shell->core.height;
579 if (request->request_mode & CWBorderWidth) {
580 wid->core.x = wid->core.y = -request->border_width;
581 }
582 #ifdef XAW_INTERNATIONALIZATION
583 _XawImCallVendorShellExtResize(wid);
584 #endif
585 return XtGeometryYes;
586 } else return XtGeometryNo;
587 }
588
ChangeManaged(wid)589 static void ChangeManaged(wid)
590 Widget wid;
591 {
592 ShellWidget w = (ShellWidget) wid;
593 Widget* childP;
594 int i;
595
596 (*SuperClass->composite_class.change_managed)(wid);
597 for (i = w->composite.num_children, childP = w->composite.children;
598 i; i--, childP++) {
599 if (XtIsManaged(*childP)) {
600 XtSetKeyboardFocus(wid, *childP);
601 break;
602 }
603 }
604 }
605