1 /***********************************************************
3 Copyright 1987, 1988, 1994, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
26 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
46 ******************************************************************/
49 * This is a copy of Xt/Vendor.c with an additional ClassInitialize
50 * procedure to register Xmu resource type converters, and all the
51 * monkey business associated with input methods...
55 /* Make sure all wm properties can make it out of the resource manager */
61 #include <X11/IntrinsicP.h>
62 #include <X11/StringDefs.h>
63 #include <X11/ShellP.h>
64 #include <X11/VendorP.h>
65 #include <X11/Xmu/Converters.h>
66 #include <X11/Xmu/Atoms.h>
67 #include <X11/Xmu/Editres.h>
68 #include <X11/Xmu/ExtAgent.h>
70 /* The following two headers are for the input method. */
72 #include <X11/Xaw/VendorEP.h>
73 #include <X11/Xaw/XawImP.h>
78 static void XawVendorShellChangeManaged(Widget);
79 static Boolean XawCvtCompoundTextToString(Display*, XrmValuePtr, Cardinal*,
80 XrmValue*, XrmValue*, XtPointer*);
81 static void XawVendorShellClassInitialize(void);
82 static XtGeometryResult XawVendorShellGeometryManager(Widget,
85 static void XawVendorShellExtClassInitialize(void);
86 static void XawVendorShellExtDestroy(Widget);
87 static void XawVendorShellExtInitialize(Widget, Widget, ArgList, Cardinal*);
88 void XawVendorShellExtResize(Widget);
89 static Boolean XawVendorShellExtSetValues(Widget, Widget, Widget,
91 static void XawVendorShellClassPartInit(WidgetClass);
92 static void XawVendorShellInitialize(Widget, Widget, ArgList, Cardinal*);
93 static void XawVendorShellRealize(Widget, Mask*, XSetWindowAttributes*);
94 static Boolean XawVendorShellSetValues(Widget, Widget, Widget,
100 void XawVendorStructureNotifyHandler(Widget, XtPointer, XEvent*, Boolean*);
102 static XtResource resources[] = {
103 {XtNinput, XtCInput, XtRBool, sizeof(Bool),
104 XtOffsetOf(VendorShellRec, wm.wm_hints.input),
105 XtRImmediate, (XtPointer)True}
108 /***************************************************************************
110 * Vendor shell class record
112 ***************************************************************************/
114 #if defined(__UNIXOS2__) || defined(__CYGWIN__) || defined(__MINGW32__)
115 /* to fix the EditRes problem because of wrong linker semantics */
116 extern WidgetClass vendorShellWidgetClass; /* from Xt/Vendor.c */
117 extern VendorShellClassRec _XawVendorShellClassRec;
118 extern void _XawFixupVendorShell();
120 #if defined(__UNIXOS2__)
121 unsigned long _DLL_InitTerm(unsigned long mod,unsigned long flag)
124 case 0: /*called on init*/
126 vendorShellWidgetClass = (WidgetClass)(&_XawVendorShellClassRec);
127 _XawFixupVendorShell();
129 case 1: /*called on exit*/
137 #if defined(__CYGWIN__) || defined(__MINGW32__)
139 DllMain(unsigned long mod_handle, unsigned long flag, void *routine)
143 case 1: /* DLL_PROCESS_ATTACH - process attach */
144 vendorShellWidgetClass = (WidgetClass)(&_XawVendorShellClassRec);
145 _XawFixupVendorShell();
147 case 0: /* DLL_PROCESS_DETACH - process detach */
154 #define vendorShellClassRec _XawVendorShellClassRec
158 static CompositeClassExtensionRec vendorCompositeExt = {
159 /* next_extension */ NULL,
160 /* record_type */ NULLQUARK,
161 /* version */ XtCompositeExtensionVersion,
162 /* record_size */ sizeof (CompositeClassExtensionRec),
163 /* accepts_objects */ TRUE,
164 /* allows_change_managed_set */ FALSE
167 #define SuperClass (&wmShellClassRec)
168 externaldef(vendorshellclassrec) VendorShellClassRec vendorShellClassRec = {
170 /* superclass */ (WidgetClass)SuperClass,
171 /* class_name */ "VendorShell",
172 /* size */ sizeof(VendorShellRec),
173 /* class_initialize */ XawVendorShellClassInitialize,
174 /* class_part_init */ XawVendorShellClassPartInit,
175 /* Class init'ed ? */ FALSE,
176 /* initialize */ XawVendorShellInitialize,
177 /* initialize_hook */ NULL,
178 /* realize */ XawVendorShellRealize,
181 /* resources */ resources,
182 /* resource_count */ XtNumber(resources),
183 /* xrm_class */ NULLQUARK,
184 /* compress_motion */ FALSE,
185 /* compress_exposure */ TRUE,
186 /* compress_enterleave*/ FALSE,
187 /* visible_interest */ FALSE,
189 /* resize */ XawVendorShellExtResize,
191 /* set_values */ XawVendorShellSetValues,
192 /* set_values_hook */ NULL,
193 /* set_values_almost */ XtInheritSetValuesAlmost,
194 /* get_values_hook */ NULL,
195 /* accept_focus */ NULL,
196 /* intrinsics version */ XtVersion,
197 /* callback offsets */ NULL,
199 /* query_geometry */ NULL,
200 /* display_accelerator*/ NULL,
203 /* geometry_manager */ XawVendorShellGeometryManager,
204 /* change_managed */ XawVendorShellChangeManaged,
205 /* insert_child */ XtInheritInsertChild,
206 /* delete_child */ XtInheritDeleteChild,
207 /* extension */ (XtPointer) &vendorCompositeExt
218 externaldef(vendorshellwidgetclass) WidgetClass vendorShellWidgetClass =
219 (WidgetClass) (&vendorShellClassRec);
222 /***************************************************************************
224 * The following section is for the Vendor shell Extension class record
226 ***************************************************************************/
228 static XtResource ext_resources[] = {
229 {XtNinputMethod, XtCInputMethod, XtRString, sizeof(String),
230 XtOffsetOf(XawVendorShellExtRec, vendor_ext.im.input_method),
231 XtRString, (XtPointer)NULL},
232 {XtNpreeditType, XtCPreeditType, XtRString, sizeof(String),
233 XtOffsetOf(XawVendorShellExtRec, vendor_ext.im.preedit_type),
234 XtRString, (XtPointer)"OverTheSpot,OffTheSpot,Root"},
235 {XtNopenIm, XtCOpenIm, XtRBoolean, sizeof(Boolean),
236 XtOffsetOf(XawVendorShellExtRec, vendor_ext.im.open_im),
237 XtRImmediate, (XtPointer)TRUE},
238 {XtNsharedIc, XtCSharedIc, XtRBoolean, sizeof(Boolean),
239 XtOffsetOf(XawVendorShellExtRec, vendor_ext.ic.shared_ic),
240 XtRImmediate, (XtPointer)FALSE}
243 externaldef(vendorshellextclassrec) XawVendorShellExtClassRec
244 xawvendorShellExtClassRec = {
246 /* superclass */ (WidgetClass)&objectClassRec,
247 /* class_name */ "VendorShellExt",
248 /* size */ sizeof(XawVendorShellExtRec),
249 /* class_initialize */ XawVendorShellExtClassInitialize,
250 /* class_part_initialize*/ NULL,
251 /* Class init'ed ? */ FALSE,
252 /* initialize */ XawVendorShellExtInitialize,
253 /* initialize_hook */ NULL,
257 /* resources */ ext_resources,
258 /* resource_count */ XtNumber(ext_resources),
259 /* xrm_class */ NULLQUARK,
264 /* destroy */ XawVendorShellExtDestroy,
267 /* set_values */ XawVendorShellExtSetValues,
268 /* set_values_hook */ NULL,
270 /* get_values_hook */ NULL,
272 /* version */ XtVersion,
273 /* callback_offsets */ NULL,
283 externaldef(xawvendorshellwidgetclass) WidgetClass
284 xawvendorShellExtWidgetClass = (WidgetClass) (&xawvendorShellExtClassRec);
289 XawCvtCompoundTextToString(Display *dpy, XrmValuePtr args, Cardinal *num_args,
290 XrmValue *fromVal, XrmValue *toVal,
296 static char *mbs = NULL;
299 prop.value = (unsigned char *)fromVal->addr;
300 prop.encoding = XA_COMPOUND_TEXT(dpy);
302 prop.nitems = fromVal->size;
304 if(XmbTextPropertyToTextList(dpy, &prop, &list, &count) < Success) {
305 XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
306 "converter", "XmbTextPropertyToTextList", "XawError",
307 "conversion from CT to MB failed.", NULL, NULL);
312 mbs = XtRealloc(mbs, len + 1); /* keep buffer because no one call free :( */
314 XFreeStringList(list);
315 toVal->addr = (XtPointer)mbs;
320 XawVendorShellClassInitialize(void)
322 static XtConvertArgRec screenConvertArg[] = {
323 {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.screen),
327 XtAddConverter(XtRString, XtRCursor, XmuCvtStringToCursor,
328 screenConvertArg, XtNumber(screenConvertArg));
330 XtAddConverter(XtRString, XtRBitmap, XmuCvtStringToBitmap,
331 screenConvertArg, XtNumber(screenConvertArg));
333 XtSetTypeConverter("CompoundText", XtRString, XawCvtCompoundTextToString,
334 NULL, 0, XtCacheNone, NULL);
338 XawVendorShellClassPartInit(WidgetClass cclass)
340 CompositeClassExtension ext;
341 VendorShellWidgetClass vsclass = (VendorShellWidgetClass)cclass;
343 if ((ext = (CompositeClassExtension)
344 XtGetClassExtension (cclass,
345 XtOffsetOf(CompositeClassRec,
346 composite_class.extension),
347 NULLQUARK, 1L, (Cardinal) 0)) == NULL) {
348 ext = (CompositeClassExtension) XtNew (CompositeClassExtensionRec);
350 ext->next_extension = vsclass->composite_class.extension;
351 ext->record_type = NULLQUARK;
352 ext->version = XtCompositeExtensionVersion;
353 ext->record_size = sizeof (CompositeClassExtensionRec);
354 ext->accepts_objects = TRUE;
355 ext->allows_change_managed_set = FALSE;
356 vsclass->composite_class.extension = (XtPointer) ext;
361 #if defined(__osf__) || defined(__UNIXOS2__) || defined(__CYGWIN__) || defined(__MINGW32__)
362 /* stupid OSF/1 shared libraries have the wrong semantics */
363 /* symbols do not get resolved external to the shared library */
364 void _XawFixupVendorShell()
366 transientShellWidgetClass->core_class.superclass =
367 (WidgetClass) &vendorShellClassRec;
368 topLevelShellWidgetClass->core_class.superclass =
369 (WidgetClass) &vendorShellClassRec;
375 XawVendorShellInitialize(Widget req, Widget cnew,
376 ArgList args, Cardinal *num_args)
378 XtAddEventHandler(cnew, (EventMask) 0, TRUE, _XEditResCheckMessages, NULL);
379 XtAddEventHandler(cnew, (EventMask) 0, TRUE, XmuRegisterExternalAgent, NULL);
380 XtCreateWidget("shellext", xawvendorShellExtWidgetClass,
381 cnew, args, *num_args);
386 XawVendorShellSetValues(Widget old, Widget ref, Widget cnew,
387 ArgList args, Cardinal *num_args)
393 XawVendorShellRealize(Widget wid, Mask *vmask, XSetWindowAttributes *attr)
395 WidgetClass super = wmShellWidgetClass;
397 /* Make my superclass do all the dirty work */
399 (*super->core_class.realize) (wid, vmask, attr);
405 XawVendorShellExtClassInitialize(void)
411 XawVendorShellExtInitialize(Widget req, Widget cnew,
412 ArgList args, Cardinal *num_args)
414 _XawImInitialize(cnew->core.parent, cnew);
419 XawVendorShellExtDestroy(Widget w)
421 _XawImDestroy( w->core.parent, w );
426 XawVendorShellExtSetValues(Widget old, Widget ref, Widget cnew,
427 ArgList args, Cardinal *num_args)
433 XawVendorShellExtResize(Widget w)
435 ShellWidget sw = (ShellWidget) w;
440 _XawImResizeVendorShell( w );
441 core_height = _XawImGetShellHeight( w );
442 for( i = 0; i < sw->composite.num_children; i++ ) {
443 if( XtIsManaged( sw->composite.children[ i ] ) ) {
444 childwid = sw->composite.children[ i ];
445 XtResizeWidget( childwid, sw->core.width, core_height,
446 childwid->core.border_width );
453 XawVendorStructureNotifyHandler(Widget w, XtPointer closure, XEvent *event,
454 Boolean *continue_to_dispatch)
456 XawVendorShellExtResize(w);
460 static XtGeometryResult
461 XawVendorShellGeometryManager(Widget wid, XtWidgetGeometry *request,
462 XtWidgetGeometry *reply)
464 ShellWidget shell = (ShellWidget)(wid->core.parent);
465 XtWidgetGeometry my_request;
467 if(shell->shell.allow_shell_resize == FALSE && XtIsRealized(wid))
468 return(XtGeometryNo);
470 if (request->request_mode & (CWX | CWY))
471 return(XtGeometryNo);
473 /* %%% worry about XtCWQueryOnly */
474 my_request.request_mode = 0;
475 if (request->request_mode & CWWidth) {
476 my_request.width = request->width;
477 my_request.request_mode |= CWWidth;
479 if (request->request_mode & CWHeight) {
480 my_request.height = request->height
481 + _XawImGetImAreaHeight( wid );
482 my_request.request_mode |= CWHeight;
484 if (request->request_mode & CWBorderWidth) {
485 my_request.border_width = request->border_width;
486 my_request.request_mode |= CWBorderWidth;
488 if (XtMakeGeometryRequest((Widget)shell, &my_request, NULL)
490 /* assert: if (request->request_mode & CWWidth) then
491 * shell->core.width == request->width
492 * assert: if (request->request_mode & CWHeight) then
493 * shell->core.height == request->height
495 * so, whatever the WM sized us to (if the Shell requested
496 * only one of the two) is now the correct child size
499 wid->core.width = shell->core.width;
500 wid->core.height = shell->core.height;
501 if (request->request_mode & CWBorderWidth) {
502 wid->core.x = wid->core.y = -request->border_width;
504 _XawImCallVendorShellExtResize(wid);
505 return XtGeometryYes;
506 } else return XtGeometryNo;
510 XawVendorShellChangeManaged(Widget wid)
512 ShellWidget w = (ShellWidget) wid;
516 (*SuperClass->composite_class.change_managed)(wid);
517 for (i = w->composite.num_children, childP = w->composite.children;
519 if (XtIsManaged(*childP)) {
520 XtSetKeyboardFocus(wid, *childP);