1 /* $XConsortium: Vendor.c,v 1.27 94/04/17 20:13:25 kaleb Exp $ */
3 /***********************************************************
5 Copyright (c) 1987, 1988, 1994 X Consortium
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:
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
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.
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.
29 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
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.
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
49 ******************************************************************/
52 * This is a copy of Xt/Vendor.c with an additional ClassInitialize
53 * procedure to register Xmu resource type converters, and all the
54 * monkey business associated with input methods...
58 /* 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>
76 static XtResource resources
[] = {
77 {XtNinput
, XtCInput
, XtRBool
, sizeof(Bool
),
78 XtOffsetOf(VendorShellRec
, wm
.wm_hints
.input
),
79 XtRImmediate
, (XtPointer
)True
}
82 /***************************************************************************
84 * Vendor shell class record
86 ***************************************************************************/
88 static void XawVendorShellClassInitialize();
89 static void XawVendorShellClassPartInit();
90 static void XawVendorShellInitialize();
91 static Boolean
XawVendorShellSetValues();
92 static void Realize(), ChangeManaged();
93 static XtGeometryResult
GeometryManager();
94 void XawVendorShellExtResize();
96 static CompositeClassExtensionRec vendorCompositeExt
= {
97 /* next_extension */ NULL
,
98 /* record_type */ NULLQUARK
,
99 /* version */ XtCompositeExtensionVersion
,
100 /* record_size */ sizeof (CompositeClassExtensionRec
),
101 /* accepts_objects */ TRUE
,
102 /* allows_change_managed_set */ FALSE
105 #define SuperClass (&wmShellClassRec)
106 externaldef(vendorshellclassrec
) VendorShellClassRec vendorShellClassRec
= {
108 /* superclass */ (WidgetClass
)SuperClass
,
109 /* class_name */ "VendorShell",
110 /* size */ sizeof(VendorShellRec
),
111 /* class_initialize */ XawVendorShellClassInitialize
,
112 /* class_part_init */ XawVendorShellClassPartInit
,
113 /* Class init'ed ? */ FALSE
,
114 /* initialize */ XawVendorShellInitialize
,
115 /* initialize_hook */ NULL
,
116 /* realize */ Realize
,
119 /* resources */ resources
,
120 /* resource_count */ XtNumber(resources
),
121 /* xrm_class */ NULLQUARK
,
122 /* compress_motion */ FALSE
,
123 /* compress_exposure */ TRUE
,
124 /* compress_enterleave*/ FALSE
,
125 /* visible_interest */ FALSE
,
127 /* resize */ XawVendorShellExtResize
,
129 /* set_values */ XawVendorShellSetValues
,
130 /* set_values_hook */ NULL
,
131 /* set_values_almost */ XtInheritSetValuesAlmost
,
132 /* get_values_hook */ NULL
,
133 /* accept_focus */ NULL
,
134 /* intrinsics version */ XtVersion
,
135 /* callback offsets */ NULL
,
137 /* query_geometry */ NULL
,
138 /* display_accelerator*/ NULL
,
141 /* geometry_manager */ GeometryManager
,
142 /* change_managed */ ChangeManaged
,
143 /* insert_child */ XtInheritInsertChild
,
144 /* delete_child */ XtInheritDeleteChild
,
145 /* extension */ (XtPointer
) &vendorCompositeExt
155 externaldef(vendorshellwidgetclass
) WidgetClass vendorShellWidgetClass
=
156 (WidgetClass
) (&vendorShellClassRec
);
159 /***************************************************************************
161 * The following section is for the Vendor shell Extension class record
163 ***************************************************************************/
165 static XtResource ext_resources
[] = {
166 {XtNinputMethod
, XtCInputMethod
, XtRString
, sizeof(String
),
167 XtOffsetOf(XawVendorShellExtRec
, vendor_ext
.im
.input_method
),
168 XtRString
, (XtPointer
)NULL
},
169 {XtNpreeditType
, XtCPreeditType
, XtRString
, sizeof(String
),
170 XtOffsetOf(XawVendorShellExtRec
, vendor_ext
.im
.preedit_type
),
171 XtRString
, (XtPointer
)"OverTheSpot,OffTheSpot,Root"},
172 {XtNopenIm
, XtCOpenIm
, XtRBoolean
, sizeof(Boolean
),
173 XtOffsetOf(XawVendorShellExtRec
, vendor_ext
.im
.open_im
),
174 XtRImmediate
, (XtPointer
)TRUE
},
175 {XtNsharedIc
, XtCSharedIc
, XtRBoolean
, sizeof(Boolean
),
176 XtOffsetOf(XawVendorShellExtRec
, vendor_ext
.ic
.shared_ic
),
177 XtRImmediate
, (XtPointer
)FALSE
}
180 static void XawVendorShellExtClassInitialize();
181 static void XawVendorShellExtInitialize();
182 static void XawVendorShellExtDestroy();
183 static Boolean
XawVendorShellExtSetValues();
185 externaldef(vendorshellextclassrec
) XawVendorShellExtClassRec
186 xawvendorShellExtClassRec
= {
188 /* superclass */ (WidgetClass
)&objectClassRec
,
189 /* class_name */ "VendorShellExt",
190 /* size */ sizeof(XawVendorShellExtRec
),
191 /* class_initialize */ XawVendorShellExtClassInitialize
,
192 /* class_part_initialize*/ NULL
,
193 /* Class init'ed ? */ FALSE
,
194 /* initialize */ XawVendorShellExtInitialize
,
195 /* initialize_hook */ NULL
,
199 /* resources */ ext_resources
,
200 /* resource_count */ XtNumber(ext_resources
),
201 /* xrm_class */ NULLQUARK
,
206 /* destroy */ XawVendorShellExtDestroy
,
209 /* set_values */ XawVendorShellExtSetValues
,
210 /* set_values_hook */ NULL
,
212 /* get_values_hook */ NULL
,
214 /* version */ XtVersion
,
215 /* callback_offsets */ NULL
,
225 externaldef(xawvendorshellwidgetclass
) WidgetClass
226 xawvendorShellExtWidgetClass
= (WidgetClass
) (&xawvendorShellExtClassRec
);
231 XawCvtCompoundTextToString(dpy
, args
, num_args
, fromVal
, toVal
, cvt_data
)
242 static char *mbs
= NULL
;
245 prop
.value
= (unsigned char *)fromVal
->addr
;
246 prop
.encoding
= XA_COMPOUND_TEXT(dpy
);
248 prop
.nitems
= fromVal
->size
;
250 if(XmbTextPropertyToTextList(dpy
, &prop
, &list
, &count
) < Success
) {
251 XtAppWarningMsg(XtDisplayToApplicationContext(dpy
),
252 "converter", "XmbTextPropertyToTextList", "XawError",
253 "conversion from CT to MB failed.", NULL
, 0);
258 mbs
= XtRealloc(mbs
, len
+ 1); /* keep buffer because no one call free :( */
260 XFreeStringList(list
);
261 toVal
->addr
= (XtPointer
)mbs
;
265 static void XawVendorShellClassInitialize()
267 static XtConvertArgRec screenConvertArg
[] = {
268 {XtWidgetBaseOffset
, (XtPointer
) XtOffsetOf(WidgetRec
, core
.screen
),
272 XtAddConverter(XtRString
, XtRCursor
, XmuCvtStringToCursor
,
273 screenConvertArg
, XtNumber(screenConvertArg
));
275 XtAddConverter(XtRString
, XtRBitmap
, XmuCvtStringToBitmap
,
276 screenConvertArg
, XtNumber(screenConvertArg
));
278 XtSetTypeConverter("CompoundText", XtRString
, XawCvtCompoundTextToString
,
279 NULL
, 0, XtCacheNone
, NULL
);
282 static void XawVendorShellClassPartInit(class)
285 CompositeClassExtension ext
;
286 VendorShellWidgetClass vsclass
= (VendorShellWidgetClass
) class;
288 if ((ext
= (CompositeClassExtension
)
289 XtGetClassExtension (class,
290 XtOffsetOf(CompositeClassRec
,
291 composite_class
.extension
),
292 NULLQUARK
, 1L, (Cardinal
) 0)) == NULL
) {
293 ext
= (CompositeClassExtension
) XtNew (CompositeClassExtensionRec
);
295 ext
->next_extension
= vsclass
->composite_class
.extension
;
296 ext
->record_type
= NULLQUARK
;
297 ext
->version
= XtCompositeExtensionVersion
;
298 ext
->record_size
= sizeof (CompositeClassExtensionRec
);
299 ext
->accepts_objects
= TRUE
;
300 ext
->allows_change_managed_set
= FALSE
;
301 vsclass
->composite_class
.extension
= (XtPointer
) ext
;
307 /* stupid OSF/1 shared libraries have the wrong semantics */
308 /* symbols do not get resolved external to the shared library */
309 void _XawFixupVendorShell()
311 transientShellWidgetClass
->core_class
.superclass
=
312 (WidgetClass
) &vendorShellClassRec
;
313 topLevelShellWidgetClass
->core_class
.superclass
=
314 (WidgetClass
) &vendorShellClassRec
;
319 static void XawVendorShellInitialize(req
, new, args
, num_args
)
324 XtAddEventHandler(new, (EventMask
) 0, TRUE
, _XEditResCheckMessages
, NULL
);
325 XtAddEventHandler(new, (EventMask
) 0, TRUE
, XmuRegisterExternalAgent
, NULL
);
326 XtCreateWidget("shellext", xawvendorShellExtWidgetClass
,
327 new, args
, *num_args
);
331 static Boolean
XawVendorShellSetValues(old
, ref
, new)
332 Widget old
, ref
, new;
337 static void Realize(wid
, vmask
, attr
)
340 XSetWindowAttributes
*attr
;
342 WidgetClass super
= wmShellWidgetClass
;
344 /* Make my superclass do all the dirty work */
346 (*super
->core_class
.realize
) (wid
, vmask
, attr
);
351 static void XawVendorShellExtClassInitialize()
356 static void XawVendorShellExtInitialize(req
, new)
359 _XawImInitialize(new->core
.parent
, new);
363 static void XawVendorShellExtDestroy( w
)
366 _XawImDestroy( w
->core
.parent
, w
);
370 static Boolean
XawVendorShellExtSetValues(old
, ref
, new)
371 Widget old
, ref
, new;
376 void XawVendorShellExtResize( w
)
379 ShellWidget sw
= (ShellWidget
) w
;
384 _XawImResizeVendorShell( w
);
385 core_height
= _XawImGetShellHeight( w
);
386 for( i
= 0; i
< sw
->composite
.num_children
; i
++ ) {
387 if( XtIsManaged( sw
->composite
.children
[ i
] ) ) {
388 childwid
= sw
->composite
.children
[ i
];
389 XtResizeWidget( childwid
, sw
->core
.width
, core_height
,
390 childwid
->core
.border_width
);
396 static XtGeometryResult
GeometryManager( wid
, request
, reply
)
398 XtWidgetGeometry
*request
;
399 XtWidgetGeometry
*reply
;
401 ShellWidget shell
= (ShellWidget
)(wid
->core
.parent
);
402 XtWidgetGeometry my_request
;
404 if(shell
->shell
.allow_shell_resize
== FALSE
&& XtIsRealized(wid
))
405 return(XtGeometryNo
);
407 if (request
->request_mode
& (CWX
| CWY
))
408 return(XtGeometryNo
);
410 /* %%% worry about XtCWQueryOnly */
411 my_request
.request_mode
= 0;
412 if (request
->request_mode
& CWWidth
) {
413 my_request
.width
= request
->width
;
414 my_request
.request_mode
|= CWWidth
;
416 if (request
->request_mode
& CWHeight
) {
417 my_request
.height
= request
->height
418 + _XawImGetImAreaHeight( wid
);
419 my_request
.request_mode
|= CWHeight
;
421 if (request
->request_mode
& CWBorderWidth
) {
422 my_request
.border_width
= request
->border_width
;
423 my_request
.request_mode
|= CWBorderWidth
;
425 if (XtMakeGeometryRequest((Widget
)shell
, &my_request
, NULL
)
427 /* assert: if (request->request_mode & CWWidth) then
428 * shell->core.width == request->width
429 * assert: if (request->request_mode & CWHeight) then
430 * shell->core.height == request->height
432 * so, whatever the WM sized us to (if the Shell requested
433 * only one of the two) is now the correct child size
436 wid
->core
.width
= shell
->core
.width
;
437 wid
->core
.height
= shell
->core
.height
;
438 if (request
->request_mode
& CWBorderWidth
) {
439 wid
->core
.x
= wid
->core
.y
= -request
->border_width
;
441 _XawImCallVendorShellExtResize(wid
);
442 return XtGeometryYes
;
443 } else return XtGeometryNo
;
446 static void ChangeManaged(wid
)
449 ShellWidget w
= (ShellWidget
) wid
;
453 (*SuperClass
->composite_class
.change_managed
)(wid
);
454 for (i
= w
->composite
.num_children
, childP
= w
->composite
.children
;
456 if (XtIsManaged(*childP
)) {
457 XtSetKeyboardFocus(wid
, *childP
);