Vendor.c revision c889a3bf
1/***********************************************************
2
3Copyright 1987, 1988, 1994, 1998  The Open Group
4
5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting
9documentation.
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21Except as contained in this notice, the name of The Open Group shall not be
22used in advertising or otherwise to promote the sale, use or other dealings
23in this Software without prior written authorization from The Open Group.
24
25
26Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
27
28                        All Rights Reserved
29
30Permission to use, copy, modify, and distribute this software and its
31documentation for any purpose and without fee is hereby granted,
32provided that the above copyright notice appear in all copies and that
33both that copyright notice and this permission notice appear in
34supporting documentation, and that the name of Digital not be
35used in advertising or publicity pertaining to distribution of the
36software without specific, written prior permission.
37
38DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44SOFTWARE.
45
46******************************************************************/
47
48/*
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...
52 *
53 */
54
55/* Make sure all wm properties can make it out of the resource manager */
56
57#ifdef HAVE_CONFIG_H
58#include <config.h>
59#endif
60#include <stdio.h>
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>
69
70/* The following two headers are for the input method. */
71
72#include <X11/Xaw/VendorEP.h>
73#include <X11/Xaw/XawImP.h>
74
75/*
76 * Class Methods
77 */
78static void XawVendorShellChangeManaged(Widget);
79static Boolean XawCvtCompoundTextToString(Display*, XrmValuePtr, Cardinal*,
80					  XrmValue*, XrmValue*, XtPointer*);
81static void XawVendorShellClassInitialize(void);
82static XtGeometryResult XawVendorShellGeometryManager(Widget,
83						      XtWidgetGeometry*,
84						      XtWidgetGeometry*);
85static void XawVendorShellExtClassInitialize(void);
86static void XawVendorShellExtDestroy(Widget);
87static void XawVendorShellExtInitialize(Widget, Widget, ArgList, Cardinal*);
88void XawVendorShellExtResize(Widget);
89static Boolean XawVendorShellExtSetValues(Widget, Widget, Widget,
90					  ArgList, Cardinal*);
91static void XawVendorShellClassPartInit(WidgetClass);
92static void XawVendorShellInitialize(Widget, Widget, ArgList, Cardinal*);
93static void XawVendorShellRealize(Widget, Mask*, XSetWindowAttributes*);
94static Boolean XawVendorShellSetValues(Widget, Widget, Widget,
95				       ArgList, Cardinal*);
96
97/*
98 * External
99 */
100void XawVendorStructureNotifyHandler(Widget, XtPointer, XEvent*, Boolean*);
101
102static XtResource resources[] = {
103  {XtNinput, XtCInput, XtRBool, sizeof(Bool),
104		XtOffsetOf(VendorShellRec, wm.wm_hints.input),
105		XtRImmediate, (XtPointer)True}
106};
107
108/***************************************************************************
109 *
110 * Vendor shell class record
111 *
112 ***************************************************************************/
113
114#if defined(__CYGWIN__) || defined(__MINGW32__)
115/* to fix the EditRes problem because of wrong linker semantics */
116extern WidgetClass vendorShellWidgetClass; /* from Xt/Vendor.c */
117extern VendorShellClassRec _XawVendorShellClassRec;
118extern void _XawFixupVendorShell();
119
120int __stdcall
121DllMain(unsigned long mod_handle, unsigned long flag, void *routine)
122{
123  switch (flag)
124    {
125    case 1: /* DLL_PROCESS_ATTACH - process attach */
126      vendorShellWidgetClass = (WidgetClass)(&_XawVendorShellClassRec);
127      _XawFixupVendorShell();
128      break;
129    case 0: /* DLL_PROCESS_DETACH - process detach */
130      break;
131    }
132  return 1;
133}
134
135#define vendorShellClassRec _XawVendorShellClassRec
136
137#endif
138
139static CompositeClassExtensionRec vendorCompositeExt = {
140    /* next_extension     */	NULL,
141    /* record_type        */    NULLQUARK,
142    /* version            */    XtCompositeExtensionVersion,
143    /* record_size        */    sizeof (CompositeClassExtensionRec),
144    /* accepts_objects    */    TRUE,
145    /* allows_change_managed_set */ FALSE
146};
147
148#define SuperClass (&wmShellClassRec)
149externaldef(vendorshellclassrec) VendorShellClassRec vendorShellClassRec = {
150  {
151    /* superclass	  */	(WidgetClass)SuperClass,
152    /* class_name	  */	"VendorShell",
153    /* size		  */	sizeof(VendorShellRec),
154    /* class_initialize	  */	XawVendorShellClassInitialize,
155    /* class_part_init	  */	XawVendorShellClassPartInit,
156    /* Class init'ed ?	  */	FALSE,
157    /* initialize         */	XawVendorShellInitialize,
158    /* initialize_hook	  */	NULL,
159    /* realize		  */	XawVendorShellRealize,
160    /* actions		  */	NULL,
161    /* num_actions	  */	0,
162    /* resources	  */	resources,
163    /* resource_count	  */	XtNumber(resources),
164    /* xrm_class	  */	NULLQUARK,
165    /* compress_motion	  */	FALSE,
166    /* compress_exposure  */	TRUE,
167    /* compress_enterleave*/	FALSE,
168    /* visible_interest	  */	FALSE,
169    /* destroy		  */	NULL,
170    /* resize		  */	XawVendorShellExtResize,
171    /* expose		  */	NULL,
172    /* set_values	  */	XawVendorShellSetValues,
173    /* set_values_hook	  */	NULL,
174    /* set_values_almost  */	XtInheritSetValuesAlmost,
175    /* get_values_hook	  */	NULL,
176    /* accept_focus	  */	NULL,
177    /* intrinsics version */	XtVersion,
178    /* callback offsets	  */	NULL,
179    /* tm_table		  */	NULL,
180    /* query_geometry	  */	NULL,
181    /* display_accelerator*/	NULL,
182    /* extension	  */	NULL
183  },{
184    /* geometry_manager	  */	XawVendorShellGeometryManager,
185    /* change_managed	  */	XawVendorShellChangeManaged,
186    /* insert_child	  */	XtInheritInsertChild,
187    /* delete_child	  */	XtInheritDeleteChild,
188    /* extension	  */	(XtPointer) &vendorCompositeExt
189  },{
190    /* extension	  */	NULL
191  },{
192    /* extension	  */	NULL
193  },{
194    /* extension	  */	NULL
195  }
196};
197
198#ifndef __UNIXOS2__
199externaldef(vendorshellwidgetclass) WidgetClass vendorShellWidgetClass =
200	(WidgetClass) (&vendorShellClassRec);
201#endif
202
203/***************************************************************************
204 *
205 * The following section is for the Vendor shell Extension class record
206 *
207 ***************************************************************************/
208
209static XtResource ext_resources[] = {
210  {XtNinputMethod, XtCInputMethod, XtRString, sizeof(String),
211		XtOffsetOf(XawVendorShellExtRec, vendor_ext.im.input_method),
212		XtRString, (XtPointer)NULL},
213  {XtNpreeditType, XtCPreeditType, XtRString, sizeof(String),
214		XtOffsetOf(XawVendorShellExtRec, vendor_ext.im.preedit_type),
215		XtRString, (XtPointer)"OverTheSpot,OffTheSpot,Root"},
216  {XtNopenIm, XtCOpenIm, XtRBoolean, sizeof(Boolean),
217		XtOffsetOf(XawVendorShellExtRec, vendor_ext.im.open_im),
218		XtRImmediate, (XtPointer)TRUE},
219  {XtNsharedIc, XtCSharedIc, XtRBoolean, sizeof(Boolean),
220		XtOffsetOf(XawVendorShellExtRec, vendor_ext.ic.shared_ic),
221		XtRImmediate, (XtPointer)FALSE}
222};
223
224externaldef(vendorshellextclassrec) XawVendorShellExtClassRec
225       xawvendorShellExtClassRec = {
226  {
227    /* superclass	  */	(WidgetClass)&objectClassRec,
228    /* class_name	  */	"VendorShellExt",
229    /* size		  */	sizeof(XawVendorShellExtRec),
230    /* class_initialize	  */	XawVendorShellExtClassInitialize,
231    /* class_part_initialize*/	NULL,
232    /* Class init'ed ?	  */	FALSE,
233    /* initialize	  */	XawVendorShellExtInitialize,
234    /* initialize_hook	  */	NULL,
235    /* pad		  */	NULL,
236    /* pad		  */	NULL,
237    /* pad		  */	0,
238    /* resources	  */	ext_resources,
239    /* resource_count	  */	XtNumber(ext_resources),
240    /* xrm_class	  */	NULLQUARK,
241    /* pad		  */	FALSE,
242    /* pad		  */	FALSE,
243    /* pad		  */	FALSE,
244    /* pad		  */	FALSE,
245    /* destroy		  */	XawVendorShellExtDestroy,
246    /* pad		  */	NULL,
247    /* pad		  */	NULL,
248    /* set_values	  */	XawVendorShellExtSetValues,
249    /* set_values_hook	  */	NULL,
250    /* pad		  */	NULL,
251    /* get_values_hook	  */	NULL,
252    /* pad		  */	NULL,
253    /* version		  */	XtVersion,
254    /* callback_offsets	  */	NULL,
255    /* pad		  */	NULL,
256    /* pad		  */	NULL,
257    /* pad		  */	NULL,
258    /* extension	  */	NULL
259  },{
260    /* extension	  */	NULL
261  }
262};
263
264externaldef(xawvendorshellwidgetclass) WidgetClass
265     xawvendorShellExtWidgetClass = (WidgetClass) (&xawvendorShellExtClassRec);
266
267
268/*ARGSUSED*/
269static Boolean
270XawCvtCompoundTextToString(Display *dpy, XrmValuePtr args, Cardinal *num_args,
271			   XrmValue *fromVal, XrmValue *toVal,
272			   XtPointer *cvt_data)
273{
274    XTextProperty prop;
275    char **list;
276    int count;
277    static char *mbs = NULL;
278    int len;
279
280    prop.value = (unsigned char *)fromVal->addr;
281    prop.encoding = XA_COMPOUND_TEXT(dpy);
282    prop.format = 8;
283    prop.nitems = fromVal->size;
284
285    if(XmbTextPropertyToTextList(dpy, &prop, &list, &count) < Success) {
286	XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
287	"converter", "XmbTextPropertyToTextList", "XawError",
288	"conversion from CT to MB failed.", NULL, NULL);
289	return False;
290    }
291    len = strlen(*list);
292    toVal->size = len;
293    mbs = XtRealloc(mbs, len + 1); /* keep buffer because no one call free :( */
294    strcpy(mbs, *list);
295    XFreeStringList(list);
296    toVal->addr = (XtPointer)mbs;
297    return True;
298}
299
300static void
301XawVendorShellClassInitialize(void)
302{
303    static XtConvertArgRec screenConvertArg[] = {
304        {XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.screen),
305	     sizeof(Screen *)}
306    };
307
308    XtAddConverter(XtRString, XtRCursor, XmuCvtStringToCursor,
309		   screenConvertArg, XtNumber(screenConvertArg));
310
311    XtAddConverter(XtRString, XtRBitmap, XmuCvtStringToBitmap,
312		   screenConvertArg, XtNumber(screenConvertArg));
313
314    XtSetTypeConverter("CompoundText", XtRString, XawCvtCompoundTextToString,
315			NULL, 0, XtCacheNone, NULL);
316}
317
318static void
319XawVendorShellClassPartInit(WidgetClass cclass)
320{
321    CompositeClassExtension ext;
322    VendorShellWidgetClass vsclass = (VendorShellWidgetClass)cclass;
323
324    if ((ext = (CompositeClassExtension)
325	    XtGetClassExtension (cclass,
326				 XtOffsetOf(CompositeClassRec,
327					    composite_class.extension),
328				 NULLQUARK, 1L, (Cardinal) 0)) == NULL) {
329	ext = (CompositeClassExtension) XtNew (CompositeClassExtensionRec);
330	if (ext != NULL) {
331	    ext->next_extension = vsclass->composite_class.extension;
332	    ext->record_type = NULLQUARK;
333	    ext->version = XtCompositeExtensionVersion;
334	    ext->record_size = sizeof (CompositeClassExtensionRec);
335	    ext->accepts_objects = TRUE;
336	    ext->allows_change_managed_set = FALSE;
337	    vsclass->composite_class.extension = (XtPointer) ext;
338	}
339    }
340}
341
342#if defined(__osf__) || defined(__UNIXOS2__) || defined(__CYGWIN__) || defined(__MINGW32__)
343/* stupid OSF/1 shared libraries have the wrong semantics */
344/* symbols do not get resolved external to the shared library */
345void _XawFixupVendorShell()
346{
347    transientShellWidgetClass->core_class.superclass =
348        (WidgetClass) &vendorShellClassRec;
349    topLevelShellWidgetClass->core_class.superclass =
350        (WidgetClass) &vendorShellClassRec;
351}
352#endif
353
354/* ARGSUSED */
355static void
356XawVendorShellInitialize(Widget req, Widget cnew,
357			 ArgList args, Cardinal *num_args)
358{
359    XtAddEventHandler(cnew, (EventMask) 0, TRUE, _XEditResCheckMessages, NULL);
360    XtAddEventHandler(cnew, (EventMask) 0, TRUE, XmuRegisterExternalAgent, NULL);
361    XtCreateWidget("shellext", xawvendorShellExtWidgetClass,
362		   cnew, args, *num_args);
363}
364
365/* ARGSUSED */
366static Boolean
367XawVendorShellSetValues(Widget old, Widget ref, Widget cnew,
368			ArgList args, Cardinal *num_args)
369{
370	return FALSE;
371}
372
373static void
374XawVendorShellRealize(Widget wid, Mask *vmask, XSetWindowAttributes *attr)
375{
376	WidgetClass super = wmShellWidgetClass;
377
378	/* Make my superclass do all the dirty work */
379
380	(*super->core_class.realize) (wid, vmask, attr);
381	_XawImRealize(wid);
382}
383
384
385static void
386XawVendorShellExtClassInitialize(void)
387{
388}
389
390/* ARGSUSED */
391static void
392XawVendorShellExtInitialize(Widget req, Widget cnew,
393			    ArgList args, Cardinal *num_args)
394{
395    _XawImInitialize(cnew->core.parent, cnew);
396}
397
398/* ARGSUSED */
399static void
400XawVendorShellExtDestroy(Widget w)
401{
402    _XawImDestroy( w->core.parent, w );
403}
404
405/* ARGSUSED */
406static Boolean
407XawVendorShellExtSetValues(Widget old, Widget ref, Widget cnew,
408			   ArgList args, Cardinal *num_args)
409{
410	return FALSE;
411}
412
413void
414XawVendorShellExtResize(Widget w)
415{
416	ShellWidget sw = (ShellWidget) w;
417	Widget childwid;
418	Cardinal i;
419	int core_height;
420
421	_XawImResizeVendorShell( w );
422	core_height = _XawImGetShellHeight( w );
423	for( i = 0; i < sw->composite.num_children; i++ ) {
424	    if( XtIsManaged( sw->composite.children[ i ] ) ) {
425		childwid = sw->composite.children[ i ];
426		XtResizeWidget( childwid, sw->core.width, core_height,
427			       childwid->core.border_width );
428	    }
429	}
430}
431
432/*ARGSUSED*/
433void
434XawVendorStructureNotifyHandler(Widget w, XtPointer closure, XEvent *event,
435				Boolean *continue_to_dispatch)
436{
437  XawVendorShellExtResize(w);
438}
439
440/*ARGSUSED*/
441static XtGeometryResult
442XawVendorShellGeometryManager(Widget wid, XtWidgetGeometry *request,
443			      XtWidgetGeometry *reply)
444{
445	ShellWidget shell = (ShellWidget)(wid->core.parent);
446	XtWidgetGeometry my_request;
447
448	if(shell->shell.allow_shell_resize == FALSE && XtIsRealized(wid))
449		return(XtGeometryNo);
450
451	if (request->request_mode & (CWX | CWY))
452	    return(XtGeometryNo);
453
454	/* %%% worry about XtCWQueryOnly */
455	my_request.request_mode = 0;
456	if (request->request_mode & CWWidth) {
457	    my_request.width = request->width;
458	    my_request.request_mode |= CWWidth;
459	}
460	if (request->request_mode & CWHeight) {
461	    my_request.height = request->height
462			      + _XawImGetImAreaHeight( wid );
463	    my_request.request_mode |= CWHeight;
464	}
465	if (request->request_mode & CWBorderWidth) {
466	    my_request.border_width = request->border_width;
467	    my_request.request_mode |= CWBorderWidth;
468	}
469	if (XtMakeGeometryRequest((Widget)shell, &my_request, NULL)
470		== XtGeometryYes) {
471	    /* assert: if (request->request_mode & CWWidth) then
472	     * 		  shell->core.width == request->width
473	     * assert: if (request->request_mode & CWHeight) then
474	     * 		  shell->core.height == request->height
475	     *
476	     * so, whatever the WM sized us to (if the Shell requested
477	     * only one of the two) is now the correct child size
478	     */
479
480	    wid->core.width = shell->core.width;
481	    wid->core.height = shell->core.height;
482	    if (request->request_mode & CWBorderWidth) {
483		wid->core.x = wid->core.y = -request->border_width;
484	    }
485	    _XawImCallVendorShellExtResize(wid);
486	    return XtGeometryYes;
487	} else return XtGeometryNo;
488}
489
490static void
491XawVendorShellChangeManaged(Widget wid)
492{
493	ShellWidget w = (ShellWidget) wid;
494	Widget* childP;
495	int i;
496
497	(*SuperClass->composite_class.change_managed)(wid);
498	for (i = w->composite.num_children, childP = w->composite.children;
499	     i; i--, childP++) {
500	    if (XtIsManaged(*childP)) {
501		XtSetKeyboardFocus(wid, *childP);
502		break;
503	    }
504	}
505}
506