Create.c revision 1477040f
1444c061aSmrg/* $Xorg: Create.c,v 1.4 2001/02/09 02:03:54 xorgcvs Exp $ */
2444c061aSmrg
3444c061aSmrg/***********************************************************
41477040fSmrgCopyright 1993 Sun Microsystems, Inc.  All rights reserved.
51477040fSmrg
61477040fSmrgPermission is hereby granted, free of charge, to any person obtaining a
71477040fSmrgcopy of this software and associated documentation files (the "Software"),
81477040fSmrgto deal in the Software without restriction, including without limitation
91477040fSmrgthe rights to use, copy, modify, merge, publish, distribute, sublicense,
101477040fSmrgand/or sell copies of the Software, and to permit persons to whom the
111477040fSmrgSoftware is furnished to do so, subject to the following conditions:
121477040fSmrg
131477040fSmrgThe above copyright notice and this permission notice (including the next
141477040fSmrgparagraph) shall be included in all copies or substantial portions of the
151477040fSmrgSoftware.
161477040fSmrg
171477040fSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
181477040fSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
191477040fSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
201477040fSmrgTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
211477040fSmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
221477040fSmrgFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
231477040fSmrgDEALINGS IN THE SOFTWARE.
241477040fSmrg
251477040fSmrgCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
26444c061aSmrg
27444c061aSmrg                        All Rights Reserved
28444c061aSmrg
29444c061aSmrgPermission to use, copy, modify, and distribute this software and its
30444c061aSmrgdocumentation for any purpose and without fee is hereby granted,
31444c061aSmrgprovided that the above copyright notice appear in all copies and that
32444c061aSmrgboth that copyright notice and this permission notice appear in
331477040fSmrgsupporting documentation, and that the name of Digital not be
34444c061aSmrgused in advertising or publicity pertaining to distribution of the
35444c061aSmrgsoftware without specific, written prior permission.
36444c061aSmrg
37444c061aSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38444c061aSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39444c061aSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40444c061aSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41444c061aSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42444c061aSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
43444c061aSmrgSOFTWARE.
44444c061aSmrg
45444c061aSmrg******************************************************************/
46444c061aSmrg/* $XFree86: xc/lib/Xt/Create.c,v 3.10 2002/12/17 04:50:58 dawes Exp $ */
47444c061aSmrg
48444c061aSmrg/*
49444c061aSmrg
50444c061aSmrgCopyright 1987, 1988, 1994, 1998  The Open Group
51444c061aSmrg
52444c061aSmrgPermission to use, copy, modify, distribute, and sell this software and its
53444c061aSmrgdocumentation for any purpose is hereby granted without fee, provided that
54444c061aSmrgthe above copyright notice appear in all copies and that both that
55444c061aSmrgcopyright notice and this permission notice appear in supporting
56444c061aSmrgdocumentation.
57444c061aSmrg
58444c061aSmrgThe above copyright notice and this permission notice shall be included in
59444c061aSmrgall copies or substantial portions of the Software.
60444c061aSmrg
61444c061aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
62444c061aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
63444c061aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
64444c061aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
65444c061aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
66444c061aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
67444c061aSmrg
68444c061aSmrgExcept as contained in this notice, the name of The Open Group shall not be
69444c061aSmrgused in advertising or otherwise to promote the sale, use or other dealings
70444c061aSmrgin this Software without prior written authorization from The Open Group.
71444c061aSmrg
72444c061aSmrg*/
73444c061aSmrg
74444c061aSmrg#ifdef HAVE_CONFIG_H
75444c061aSmrg#include <config.h>
76444c061aSmrg#endif
77444c061aSmrg#include "IntrinsicI.h"
78444c061aSmrg#include "VarargsI.h"
79444c061aSmrg#include "ShellP.h"
80444c061aSmrg#include "CreateI.h"
81444c061aSmrg#ifndef X_NO_RESOURCE_CONFIGURATION_MANAGEMENT
82444c061aSmrg#include "ResConfigP.h"
83444c061aSmrg#endif
84444c061aSmrg#include <stdio.h>
85444c061aSmrg
86444c061aSmrgstatic String XtNxtCreateWidget = "xtCreateWidget";
87444c061aSmrgstatic String XtNxtCreatePopupShell = "xtCreatePopupShell";
88444c061aSmrg
89444c061aSmrgstatic void
90444c061aSmrgCallClassPartInit(WidgetClass ancestor, WidgetClass wc)
91444c061aSmrg{
92444c061aSmrg    if (ancestor->core_class.superclass != NULL) {
93444c061aSmrg	CallClassPartInit(ancestor->core_class.superclass, wc);
94444c061aSmrg    }
95444c061aSmrg    if (ancestor->core_class.class_part_initialize != NULL) {
96444c061aSmrg	(*(ancestor->core_class.class_part_initialize)) (wc);
97444c061aSmrg    }
98444c061aSmrg}
99444c061aSmrg
100444c061aSmrgvoid
1012265a131SmrgXtInitializeWidgetClass(WidgetClass wc)
102444c061aSmrg{
103444c061aSmrg    XtEnum inited;
104444c061aSmrg    LOCK_PROCESS;
105444c061aSmrg    if (wc->core_class.class_inited) {
106444c061aSmrg	UNLOCK_PROCESS;
107444c061aSmrg	return;
108444c061aSmrg    }
109444c061aSmrg    inited = 0x01;
110444c061aSmrg    {
111444c061aSmrg	WidgetClass pc;
112444c061aSmrg#define LeaveIfClass(c, d) if (pc == c) { inited = d; break; }
113444c061aSmrg	for (pc = wc; pc; pc = pc->core_class.superclass) {
114444c061aSmrg	    LeaveIfClass(rectObjClass, 0x01 |
115444c061aSmrg			 RectObjClassFlag);
116444c061aSmrg	    LeaveIfClass(coreWidgetClass, 0x01 |
117444c061aSmrg			 RectObjClassFlag |
118444c061aSmrg			 WidgetClassFlag);
119444c061aSmrg	    LeaveIfClass(compositeWidgetClass, 0x01 |
120444c061aSmrg			 RectObjClassFlag |
121444c061aSmrg			 WidgetClassFlag |
122444c061aSmrg			 CompositeClassFlag);
123444c061aSmrg	    LeaveIfClass(constraintWidgetClass, 0x01 |
124444c061aSmrg			 RectObjClassFlag |
125444c061aSmrg			 WidgetClassFlag |
126444c061aSmrg			 CompositeClassFlag |
127444c061aSmrg			 ConstraintClassFlag);
128444c061aSmrg	    LeaveIfClass(shellWidgetClass, 0x01 |
129444c061aSmrg			 RectObjClassFlag |
130444c061aSmrg			 WidgetClassFlag |
131444c061aSmrg			 CompositeClassFlag |
132444c061aSmrg			 ShellClassFlag);
133444c061aSmrg	    LeaveIfClass(wmShellWidgetClass, 0x01 |
134444c061aSmrg			 RectObjClassFlag |
135444c061aSmrg			 WidgetClassFlag |
136444c061aSmrg			 CompositeClassFlag |
137444c061aSmrg			 ShellClassFlag |
138444c061aSmrg			 WMShellClassFlag);
139444c061aSmrg	    LeaveIfClass(topLevelShellWidgetClass, 0x01 |
140444c061aSmrg			 RectObjClassFlag |
141444c061aSmrg			 WidgetClassFlag |
142444c061aSmrg			 CompositeClassFlag |
143444c061aSmrg			 ShellClassFlag |
144444c061aSmrg			 WMShellClassFlag |
145444c061aSmrg			 TopLevelClassFlag);
146444c061aSmrg	}
147444c061aSmrg#undef LeaveIfClass
148444c061aSmrg    }
149444c061aSmrg    if (wc->core_class.version != XtVersion &&
150444c061aSmrg	wc->core_class.version != XtVersionDontCheck) {
151444c061aSmrg	String param[3];
152444c061aSmrg	String mismatch = "Widget class %s version mismatch (recompilation needed):\n  widget %d vs. intrinsics %d.";
153444c061aSmrg	String recompile = "Widget class %s must be re-compiled.";
154444c061aSmrg	Cardinal num_params;
155444c061aSmrg
156444c061aSmrg	param[0] = wc->core_class.class_name;
157444c061aSmrg	param[1] = (String) wc->core_class.version;
158444c061aSmrg	param[2] = (String) XtVersion;
159444c061aSmrg
160444c061aSmrg	if (wc->core_class.version == (11 * 1000 + 5) || /* MIT X11R5 */
161444c061aSmrg	    wc->core_class.version == (11 * 1000 + 4)) { /* MIT X11R4 */
162444c061aSmrg	    if ((inited & WMShellClassFlag) &&
163444c061aSmrg		(sizeof(Boolean) != sizeof(char) ||
164444c061aSmrg		 sizeof(Atom) != sizeof(Widget) ||
165444c061aSmrg		 sizeof(Atom) != sizeof(String))) {
166444c061aSmrg		num_params=3;
167444c061aSmrg		XtWarningMsg("versionMismatch","widget",XtCXtToolkitError,
168444c061aSmrg			     mismatch, param, &num_params);
169444c061aSmrg		num_params=1;
170444c061aSmrg		XtErrorMsg("R4orR5versionMismatch","widget",XtCXtToolkitError,
171444c061aSmrg			   recompile, param, &num_params);
172444c061aSmrg
173444c061aSmrg	    }
174444c061aSmrg	}
175444c061aSmrg	else if (wc->core_class.version == (11 * 1000 + 3)) { /* MIT X11R3 */
176444c061aSmrg	    if (inited & ShellClassFlag) {
177444c061aSmrg		num_params=1;
178444c061aSmrg		XtWarningMsg("r3versionMismatch","widget",XtCXtToolkitError,
179444c061aSmrg			     "Shell Widget class %s binary compiled for R3",
180444c061aSmrg			     param,&num_params);
181444c061aSmrg		XtErrorMsg("R3versionMismatch","widget",XtCXtToolkitError,
182444c061aSmrg			   recompile, param, &num_params);
183444c061aSmrg	    }
184444c061aSmrg	}
185444c061aSmrg	else {
186444c061aSmrg	    num_params=3;
187444c061aSmrg	    XtWarningMsg("versionMismatch","widget",XtCXtToolkitError,
188444c061aSmrg			 mismatch, param, &num_params);
189444c061aSmrg	    if (wc->core_class.version == (2 * 1000 + 2)) /* MIT X11R2 */ {
190444c061aSmrg		num_params=1;
191444c061aSmrg		XtErrorMsg("r2versionMismatch","widget",XtCXtToolkitError,
192444c061aSmrg			   recompile, param, &num_params);
193444c061aSmrg	    }
194444c061aSmrg	}
195444c061aSmrg    }
196444c061aSmrg
197444c061aSmrg    if ((wc->core_class.superclass != NULL)
198444c061aSmrg	    && (!(wc->core_class.superclass->core_class.class_inited)))
199444c061aSmrg 	XtInitializeWidgetClass(wc->core_class.superclass);
200444c061aSmrg
201444c061aSmrg    if (wc->core_class.class_initialize != NULL)
202444c061aSmrg	(*(wc->core_class.class_initialize))();
203444c061aSmrg    CallClassPartInit(wc, wc);
204444c061aSmrg    wc->core_class.class_inited = inited;
205444c061aSmrg    UNLOCK_PROCESS;
206444c061aSmrg}
207444c061aSmrg
208444c061aSmrgstatic void
209444c061aSmrgCallInitialize (
210444c061aSmrg    WidgetClass class,
211444c061aSmrg    Widget      req_widget,
212444c061aSmrg    Widget      new_widget,
213444c061aSmrg    ArgList     args,
214444c061aSmrg    Cardinal    num_args)
215444c061aSmrg{
216444c061aSmrg    WidgetClass superclass;
217444c061aSmrg    XtInitProc initialize;
218444c061aSmrg    XtArgsProc initialize_hook;
219444c061aSmrg
220444c061aSmrg    LOCK_PROCESS;
221444c061aSmrg    superclass = class->core_class.superclass;
222444c061aSmrg    UNLOCK_PROCESS;
223444c061aSmrg    if (superclass)
224444c061aSmrg        CallInitialize (superclass, req_widget, new_widget, args, num_args);
225444c061aSmrg    LOCK_PROCESS;
226444c061aSmrg    initialize = class->core_class.initialize;
227444c061aSmrg    UNLOCK_PROCESS;
228444c061aSmrg    if (initialize)
229444c061aSmrg	(*initialize) (req_widget, new_widget, args, &num_args);
230444c061aSmrg    LOCK_PROCESS;
231444c061aSmrg    initialize_hook = class->core_class.initialize_hook;
232444c061aSmrg    UNLOCK_PROCESS;
233444c061aSmrg    if (initialize_hook)
234444c061aSmrg	(*initialize_hook) (new_widget, args, &num_args);
235444c061aSmrg}
236444c061aSmrg
237444c061aSmrgstatic void
238444c061aSmrgCallConstraintInitialize (
239444c061aSmrg    ConstraintWidgetClass class,
240444c061aSmrg    Widget	req_widget,
241444c061aSmrg    Widget	new_widget,
242444c061aSmrg    ArgList	args,
243444c061aSmrg    Cardinal	num_args)
244444c061aSmrg{
245444c061aSmrg    WidgetClass superclass;
246444c061aSmrg    XtInitProc initialize;
247444c061aSmrg
248444c061aSmrg    LOCK_PROCESS;
249444c061aSmrg    superclass = class->core_class.superclass;
250444c061aSmrg    UNLOCK_PROCESS;
251444c061aSmrg    if (superclass != constraintWidgetClass)
252444c061aSmrg	CallConstraintInitialize((ConstraintWidgetClass) superclass,
253444c061aSmrg		req_widget, new_widget, args, num_args);
254444c061aSmrg    LOCK_PROCESS;
255444c061aSmrg    initialize = class->constraint_class.initialize;
256444c061aSmrg    UNLOCK_PROCESS;
257444c061aSmrg    if (initialize)
258444c061aSmrg        (*initialize) (req_widget, new_widget, args, &num_args);
259444c061aSmrg}
260444c061aSmrg
261444c061aSmrgstatic Widget
262444c061aSmrgxtWidgetAlloc(
263444c061aSmrg    WidgetClass widget_class,
264444c061aSmrg    ConstraintWidgetClass parent_constraint_class,
265444c061aSmrg    Widget parent,
266444c061aSmrg    String name,
267444c061aSmrg    ArgList     args,		/* must be NULL if typed_args is non-NULL */
268444c061aSmrg    Cardinal    num_args,
269444c061aSmrg    XtTypedArgList typed_args,	/* must be NULL if args is non-NULL */
270444c061aSmrg    Cardinal	num_typed_args)
271444c061aSmrg{
272444c061aSmrg    Widget widget;
273444c061aSmrg    Cardinal                wsize, csize = 0;
274444c061aSmrg    ObjectClassExtension    ext;
275444c061aSmrg
276444c061aSmrg    LOCK_PROCESS;
277444c061aSmrg    if (! (widget_class->core_class.class_inited))
278444c061aSmrg	XtInitializeWidgetClass(widget_class);
279444c061aSmrg    ext = (ObjectClassExtension)
280444c061aSmrg	XtGetClassExtension(widget_class,
281444c061aSmrg			    XtOffsetOf(ObjectClassRec, object_class.extension),
282444c061aSmrg			    NULLQUARK, XtObjectExtensionVersion,
283444c061aSmrg			    sizeof(ObjectClassExtensionRec));
284444c061aSmrg    if (parent_constraint_class)
285444c061aSmrg	csize = parent_constraint_class->constraint_class.constraint_size;
286444c061aSmrg    if (ext && ext->allocate) {
287444c061aSmrg	XtAllocateProc allocate;
288444c061aSmrg	Cardinal extra = 0;
289444c061aSmrg	Cardinal nargs = num_args;
290444c061aSmrg	Cardinal ntyped = num_typed_args;
291444c061aSmrg	allocate = ext->allocate;
292444c061aSmrg	UNLOCK_PROCESS;
293444c061aSmrg	(*allocate)(widget_class, &csize, &extra, args, &nargs,
294444c061aSmrg		    typed_args, &ntyped, &widget, NULL);
295444c061aSmrg    } else {
296444c061aSmrg	wsize = widget_class->core_class.widget_size;
297444c061aSmrg	UNLOCK_PROCESS;
298444c061aSmrg	if (csize) {
299444c061aSmrg	    if (sizeof(struct {char a; double b;}) !=
300444c061aSmrg		(sizeof(struct {char a; unsigned long b;}) -
301444c061aSmrg		 sizeof(unsigned long) + sizeof(double))) {
302444c061aSmrg		if (csize && !(csize & (sizeof(double) - 1)))
303444c061aSmrg		    wsize = (wsize + sizeof(double) - 1) & ~(sizeof(double)-1);
304444c061aSmrg	    }
305444c061aSmrg	}
306444c061aSmrg	widget = (Widget) __XtMalloc((unsigned)(wsize + csize));
307444c061aSmrg	bzero(widget, wsize + csize);
308444c061aSmrg	widget->core.constraints =
309444c061aSmrg	    (csize ? (XtPointer)((char *)widget + wsize) : NULL);
310444c061aSmrg    }
311444c061aSmrg    widget->core.self = widget;
312444c061aSmrg    widget->core.parent = parent;
313444c061aSmrg    widget->core.widget_class = widget_class;
314444c061aSmrg    widget->core.xrm_name = StringToName((name != NULL) ? name : "");
315444c061aSmrg    widget->core.being_destroyed =
316444c061aSmrg	(parent != NULL ? parent->core.being_destroyed : FALSE);
317444c061aSmrg    return widget;
318444c061aSmrg}
319444c061aSmrg
320444c061aSmrgstatic void
321444c061aSmrgCompileCallbacks(
322444c061aSmrg    Widget widget)
323444c061aSmrg{
324444c061aSmrg    CallbackTable offsets;
325444c061aSmrg    InternalCallbackList* cl;
326444c061aSmrg    int i;
327444c061aSmrg
328444c061aSmrg    LOCK_PROCESS;
329444c061aSmrg    offsets = (CallbackTable)
330444c061aSmrg	widget->core.widget_class->core_class.callback_private;
331444c061aSmrg
332444c061aSmrg    for (i = (int)(long) *(offsets++); --i >= 0; offsets++) {
333444c061aSmrg	cl = (InternalCallbackList *)
334444c061aSmrg	    ((char *) widget - (*offsets)->xrm_offset - 1);
335444c061aSmrg	if (*cl)
336444c061aSmrg	    *cl = _XtCompileCallbackList((XtCallbackList) *cl);
337444c061aSmrg    }
338444c061aSmrg    UNLOCK_PROCESS;
339444c061aSmrg}
340444c061aSmrg
341444c061aSmrgstatic Widget
342444c061aSmrgxtCreate(
343444c061aSmrg    char        *name,
344444c061aSmrg    char        *class,
345444c061aSmrg    WidgetClass widget_class,
346444c061aSmrg    Widget      parent,
347444c061aSmrg    Screen*     default_screen, /* undefined when creating a nonwidget */
348444c061aSmrg    ArgList     args,		/* must be NULL if typed_args is non-NULL */
349444c061aSmrg    Cardinal    num_args,
350444c061aSmrg    XtTypedArgList typed_args,	/* must be NULL if args is non-NULL */
351444c061aSmrg    Cardinal	num_typed_args,
352444c061aSmrg    ConstraintWidgetClass parent_constraint_class,
353444c061aSmrg        /* NULL if not a subclass of Constraint or if child is popup shell */
354444c061aSmrg    XtWidgetProc post_proc)
355444c061aSmrg{
356444c061aSmrg    /* need to use strictest alignment rules possible in next two decls. */
357444c061aSmrg    double                  widget_cache[100];
358444c061aSmrg    double                  constraint_cache[20];
359444c061aSmrg    Widget                  req_widget;
360444c061aSmrg    XtPointer               req_constraints = NULL;
361444c061aSmrg    Cardinal                wsize, csize;
362444c061aSmrg    Widget	    	    widget;
363444c061aSmrg    XtCacheRef		    *cache_refs;
364444c061aSmrg    Cardinal		    i;
365444c061aSmrg    XtCreateHookDataRec     call_data;
366444c061aSmrg
367444c061aSmrg    widget = xtWidgetAlloc(widget_class, parent_constraint_class, parent,
368444c061aSmrg		name, args, num_args, typed_args, num_typed_args);
369444c061aSmrg
370444c061aSmrg    if (XtIsRectObj(widget)) {
371444c061aSmrg	widget->core.managed = FALSE;
372444c061aSmrg    }
373444c061aSmrg    if (XtIsWidget(widget)) {
374444c061aSmrg	widget->core.name = XrmNameToString(widget->core.xrm_name);
375444c061aSmrg        widget->core.screen = default_screen;
376444c061aSmrg        widget->core.tm.translations = NULL;
377444c061aSmrg	widget->core.window = (Window) 0;
378444c061aSmrg	widget->core.visible = TRUE;
379444c061aSmrg	widget->core.popup_list = NULL;
380444c061aSmrg	widget->core.num_popups = 0;
381444c061aSmrg    };
382444c061aSmrg    LOCK_PROCESS;
383444c061aSmrg    if (XtIsApplicationShell(widget)) {
384444c061aSmrg	ApplicationShellWidget a = (ApplicationShellWidget) widget;
385444c061aSmrg	if (class != NULL)
386444c061aSmrg	    a->application.xrm_class = StringToClass(class);
387444c061aSmrg	else
388444c061aSmrg	    a->application.xrm_class = widget_class->core_class.xrm_class;
389444c061aSmrg	a->application.class = XrmQuarkToString(a->application.xrm_class);
390444c061aSmrg    }
391444c061aSmrg    UNLOCK_PROCESS;
392444c061aSmrg
393444c061aSmrg    /* fetch resources */
394444c061aSmrg    cache_refs = _XtGetResources(widget, args, num_args,
395444c061aSmrg		typed_args, &num_typed_args);
396444c061aSmrg
397444c061aSmrg    /* Convert typed arg list to arg list */
398444c061aSmrg    if (typed_args != NULL && num_typed_args > 0) {
399444c061aSmrg	args = (ArgList)ALLOCATE_LOCAL(sizeof(Arg) * num_typed_args);
400444c061aSmrg	if (args == NULL) _XtAllocError(NULL);
401444c061aSmrg	for (i = 0; i < num_typed_args; i++) {
402444c061aSmrg	    args[i].name = typed_args[i].name;
403444c061aSmrg	    args[i].value = typed_args[i].value;
404444c061aSmrg	}
405444c061aSmrg	num_args = num_typed_args;
406444c061aSmrg    }
407444c061aSmrg
408444c061aSmrg    CompileCallbacks(widget);
409444c061aSmrg
410444c061aSmrg    if (cache_refs != NULL) {
411444c061aSmrg	XtAddCallback(widget, XtNdestroyCallback,
412444c061aSmrg		XtCallbackReleaseCacheRefList, (XtPointer)cache_refs );
413444c061aSmrg    }
414444c061aSmrg
415444c061aSmrg    wsize = widget_class->core_class.widget_size;
416444c061aSmrg    csize = 0;
417444c061aSmrg    req_widget = (Widget) XtStackAlloc(wsize, widget_cache);
418444c061aSmrg    (void) memmove ((char *) req_widget, (char *) widget, (int) wsize);
419444c061aSmrg    CallInitialize (XtClass(widget), req_widget, widget, args, num_args);
420444c061aSmrg    if (parent_constraint_class != NULL) {
421444c061aSmrg        csize = parent_constraint_class->constraint_class.constraint_size;
422444c061aSmrg	if (csize) {
423444c061aSmrg	    req_constraints = XtStackAlloc(csize, constraint_cache);
424444c061aSmrg	    (void) memmove((char*)req_constraints, widget->core.constraints,
425444c061aSmrg			(int)csize);
426444c061aSmrg	    req_widget->core.constraints = req_constraints;
427444c061aSmrg	} else req_widget->core.constraints = NULL;
428444c061aSmrg	CallConstraintInitialize(parent_constraint_class, req_widget, widget,
429444c061aSmrg		args, num_args);
430444c061aSmrg	if (csize) {
431444c061aSmrg	    XtStackFree(req_constraints, constraint_cache);
432444c061aSmrg	}
433444c061aSmrg    }
434444c061aSmrg    XtStackFree((XtPointer)req_widget, widget_cache);
435444c061aSmrg    if (post_proc != (XtWidgetProc) NULL) {
436444c061aSmrg	Widget hookobj;
437444c061aSmrg	(*post_proc)(widget);
438444c061aSmrg	hookobj = XtHooksOfDisplay((default_screen != (Screen*) NULL) ?
439444c061aSmrg		default_screen->display :
440444c061aSmrg		XtDisplayOfObject(parent));
441444c061aSmrg	if (XtHasCallbacks(hookobj, XtNcreateHook) == XtCallbackHasSome) {
442444c061aSmrg
443444c061aSmrg	    call_data.type = XtHcreate;
444444c061aSmrg	    call_data.widget = widget;
445444c061aSmrg	    call_data.args = args;
446444c061aSmrg	    call_data.num_args = num_args;
447444c061aSmrg	    XtCallCallbackList(hookobj,
448444c061aSmrg		((HookObject)hookobj)->hooks.createhook_callbacks,
449444c061aSmrg		(XtPointer)&call_data);
450444c061aSmrg	}
451444c061aSmrg    }
452444c061aSmrg    if (typed_args != NULL) {
453444c061aSmrg	while (num_typed_args-- > 0) {
454444c061aSmrg
455444c061aSmrg	    /* In GetResources we may have dynamically alloc'd store to hold */
456444c061aSmrg	    /* a copy of a resource which was larger then sizeof(XtArgVal). */
457444c061aSmrg	    /* We must free this store now in order to prevent a memory leak */
458444c061aSmrg	    /* A typed arg that has a converted value in dynamic store has a */
459444c061aSmrg	    /* negated size field. */
460444c061aSmrg
461444c061aSmrg	    if (typed_args->type != NULL && typed_args->size < 0) {
462444c061aSmrg		XtFree((char*)typed_args->value);
463444c061aSmrg		typed_args->size = -(typed_args->size);
464444c061aSmrg	    }
465444c061aSmrg	    typed_args++;
466444c061aSmrg	}
467444c061aSmrg	DEALLOCATE_LOCAL((char*)args);
468444c061aSmrg    }
469444c061aSmrg    return (widget);
470444c061aSmrg}
471444c061aSmrg
472444c061aSmrgstatic void
473444c061aSmrgwidgetPostProc(Widget w)
474444c061aSmrg{
475444c061aSmrg    XtWidgetProc insert_child;
476444c061aSmrg    Widget parent = XtParent(w);
477444c061aSmrg    String param = XtName(w);
478444c061aSmrg    Cardinal num_params = 1;
479444c061aSmrg
480444c061aSmrg    if (XtIsComposite(parent)) {
481444c061aSmrg	LOCK_PROCESS;
482444c061aSmrg	insert_child = ((CompositeWidgetClass) parent->core.widget_class)->
483444c061aSmrg	    composite_class.insert_child;
484444c061aSmrg	UNLOCK_PROCESS;
485444c061aSmrg    } else {
486444c061aSmrg	return;
487444c061aSmrg    }
488444c061aSmrg    if (insert_child == NULL) {
489444c061aSmrg	XtAppErrorMsg(XtWidgetToApplicationContext(parent),
490444c061aSmrg		"nullProc","insertChild",XtCXtToolkitError,
491444c061aSmrg		"\"%s\" parent has NULL insert_child method",
492444c061aSmrg		&param, &num_params);
493444c061aSmrg    } else {
494444c061aSmrg	(*insert_child) (w);
495444c061aSmrg    }
496444c061aSmrg}
497444c061aSmrg
498444c061aSmrgWidget
499444c061aSmrg_XtCreateWidget(
500444c061aSmrg    String      name,
501444c061aSmrg    WidgetClass widget_class,
502444c061aSmrg    Widget      parent,
503444c061aSmrg    ArgList     args,
504444c061aSmrg    Cardinal    num_args,
505444c061aSmrg    XtTypedArgList typed_args,
506444c061aSmrg    Cardinal	num_typed_args)
507444c061aSmrg{
508444c061aSmrg    register Widget	    widget;
509444c061aSmrg    ConstraintWidgetClass   cwc;
510444c061aSmrg    Screen*                 default_screen;
511444c061aSmrg    XtEnum		    class_inited;
512444c061aSmrg    String		    params[3];
513444c061aSmrg    Cardinal		    num_params;
514444c061aSmrg
515444c061aSmrg    params[0] = name;
516444c061aSmrg    num_params = 1;
517444c061aSmrg
518444c061aSmrg    if (parent == NULL) {
519444c061aSmrg	XtErrorMsg("invalidParent", XtNxtCreateWidget, XtCXtToolkitError,
520444c061aSmrg		   "XtCreateWidget \"%s\" requires non-NULL parent",
521444c061aSmrg		   params, &num_params);
522444c061aSmrg    } else if (widget_class == NULL) {
523444c061aSmrg	XtAppErrorMsg(XtWidgetToApplicationContext(parent),
524444c061aSmrg		      "invalidClass", XtNxtCreateWidget, XtCXtToolkitError,
525444c061aSmrg		      "XtCreateWidget \"%s\" requires non-NULL widget class",
526444c061aSmrg		      params, &num_params);
527444c061aSmrg    }
528444c061aSmrg    LOCK_PROCESS;
529444c061aSmrg    if (!widget_class->core_class.class_inited)
530444c061aSmrg	XtInitializeWidgetClass(widget_class);
531444c061aSmrg    class_inited = widget_class->core_class.class_inited;
532444c061aSmrg    UNLOCK_PROCESS;
533444c061aSmrg    if ((class_inited & WidgetClassFlag) == 0) {
534444c061aSmrg	/* not a widget */
535444c061aSmrg	default_screen = NULL;
536444c061aSmrg	if (XtIsComposite(parent)) {
537444c061aSmrg	    CompositeClassExtension ext;
538444c061aSmrg	    ext = (CompositeClassExtension)
539444c061aSmrg		XtGetClassExtension(XtClass(parent),
540444c061aSmrg		      XtOffsetOf(CompositeClassRec, composite_class.extension),
541444c061aSmrg		      NULLQUARK, 1L, (Cardinal) 0);
542444c061aSmrg	    LOCK_PROCESS;
543444c061aSmrg	    if (ext &&
544444c061aSmrg		(ext->version > XtCompositeExtensionVersion ||
545444c061aSmrg		 ext->record_size > sizeof(CompositeClassExtensionRec))) {
546444c061aSmrg		params[1] = XtClass(parent)->core_class.class_name;
547444c061aSmrg		num_params = 2;
548444c061aSmrg		XtAppWarningMsg(XtWidgetToApplicationContext(parent),
549444c061aSmrg				"invalidExtension", XtNxtCreateWidget,
550444c061aSmrg				XtCXtToolkitError,
551444c061aSmrg	   "widget \"%s\" class %s has invalid CompositeClassExtension record",
552444c061aSmrg				params, &num_params);
553444c061aSmrg	    }
554444c061aSmrg	    if (!ext || !ext->accepts_objects) {
555444c061aSmrg		params[1] = XtName(parent);
556444c061aSmrg		num_params = 2;
557444c061aSmrg		XtAppErrorMsg(XtWidgetToApplicationContext(parent),
558444c061aSmrg			      "nonWidget", XtNxtCreateWidget,XtCXtToolkitError,
559444c061aSmrg"attempt to add non-widget child \"%s\" to parent \"%s\" which supports only widgets",
560444c061aSmrg			      params, &num_params);
561444c061aSmrg	    }
562444c061aSmrg	    UNLOCK_PROCESS;
563444c061aSmrg	}
564444c061aSmrg    } else {
565444c061aSmrg	default_screen = parent->core.screen;
566444c061aSmrg    }
567444c061aSmrg
568444c061aSmrg    if (XtIsConstraint(parent)) {
569444c061aSmrg	cwc = (ConstraintWidgetClass) parent->core.widget_class;
570444c061aSmrg    } else {
571444c061aSmrg	cwc = NULL;
572444c061aSmrg    }
573444c061aSmrg    widget = xtCreate(name, (char *)NULL, widget_class, parent,
574444c061aSmrg		default_screen, args, num_args,
575444c061aSmrg		typed_args, num_typed_args, cwc, widgetPostProc);
576444c061aSmrg    return (widget);
577444c061aSmrg}
578444c061aSmrg
579444c061aSmrgWidget
580444c061aSmrgXtCreateWidget(
581444c061aSmrg    _Xconst char* name,
582444c061aSmrg    WidgetClass widget_class,
583444c061aSmrg    Widget   	parent,
584444c061aSmrg    ArgList 	args,
585444c061aSmrg    Cardinal    num_args
586444c061aSmrg    )
587444c061aSmrg{
588444c061aSmrg    Widget retval;
589444c061aSmrg    WIDGET_TO_APPCON(parent);
590444c061aSmrg
591444c061aSmrg    LOCK_APP(app);
592444c061aSmrg    retval = _XtCreateWidget((String)name, widget_class, parent, args, num_args,
593444c061aSmrg		(XtTypedArgList)NULL, (Cardinal)0);
594444c061aSmrg    UNLOCK_APP(app);
595444c061aSmrg    return retval;
596444c061aSmrg}
597444c061aSmrg
598444c061aSmrg
599444c061aSmrgWidget
600444c061aSmrgXtCreateManagedWidget(
601444c061aSmrg    _Xconst char* name,
602444c061aSmrg    WidgetClass widget_class,
603444c061aSmrg    Widget      parent,
604444c061aSmrg    ArgList     args,
605444c061aSmrg    Cardinal    num_args
606444c061aSmrg    )
607444c061aSmrg{
608444c061aSmrg    register Widget	    widget;
609444c061aSmrg    WIDGET_TO_APPCON(parent);
610444c061aSmrg
611444c061aSmrg    LOCK_APP(app);
612444c061aSmrg    XtCheckSubclass(parent, compositeWidgetClass, "in XtCreateManagedWidget");
613444c061aSmrg    widget = _XtCreateWidget((String)name, widget_class, parent, args,
614444c061aSmrg		num_args, (XtTypedArgList)NULL, (Cardinal) 0);
615444c061aSmrg    XtManageChild(widget);
616444c061aSmrg    UNLOCK_APP(app);
617444c061aSmrg    return widget;
618444c061aSmrg}
619444c061aSmrg
620444c061aSmrgstatic void
621444c061aSmrgpopupPostProc(Widget w)
622444c061aSmrg{
623444c061aSmrg    Widget parent = XtParent(w);
624444c061aSmrg
625444c061aSmrg    parent->core.popup_list =
626444c061aSmrg	(WidgetList) XtRealloc((char*) parent->core.popup_list,
627444c061aSmrg		(unsigned) (parent->core.num_popups+1) * sizeof(Widget));
628444c061aSmrg    parent->core.popup_list[parent->core.num_popups++] = w;
629444c061aSmrg}
630444c061aSmrg
631444c061aSmrgWidget
632444c061aSmrg_XtCreatePopupShell(
633444c061aSmrg    String      name,
634444c061aSmrg    WidgetClass widget_class,
635444c061aSmrg    Widget      parent,
636444c061aSmrg    ArgList     args,
637444c061aSmrg    Cardinal    num_args,
638444c061aSmrg    XtTypedArgList      typed_args,
639444c061aSmrg    Cardinal            num_typed_args)
640444c061aSmrg{
641444c061aSmrg    register Widget widget;
642444c061aSmrg    Screen* default_screen;
643444c061aSmrg
644444c061aSmrg    if (parent == NULL) {
645444c061aSmrg	XtErrorMsg("invalidParent",XtNxtCreatePopupShell,XtCXtToolkitError,
646444c061aSmrg		"XtCreatePopupShell requires non-NULL parent",
647444c061aSmrg		(String *)NULL, (Cardinal *)NULL);
648444c061aSmrg    } else if (widget_class == NULL) {
649444c061aSmrg	XtAppErrorMsg(XtWidgetToApplicationContext(parent),
650444c061aSmrg		"invalidClass",XtNxtCreatePopupShell,XtCXtToolkitError,
651444c061aSmrg		"XtCreatePopupShell requires non-NULL widget class",
652444c061aSmrg		(String *)NULL, (Cardinal *)NULL);
653444c061aSmrg    }
654444c061aSmrg    XtCheckSubclass(parent, coreWidgetClass, "in XtCreatePopupShell");
655444c061aSmrg    default_screen = parent->core.screen;
656444c061aSmrg    widget = xtCreate(name, (char *)NULL, widget_class, parent,
657444c061aSmrg		default_screen, args, num_args, typed_args,
658444c061aSmrg		num_typed_args, (ConstraintWidgetClass)NULL,
659444c061aSmrg		popupPostProc);
660444c061aSmrg
661444c061aSmrg#ifndef X_NO_RESOURCE_CONFIGURATION_MANAGEMENT
662444c061aSmrg    XtAddEventHandler (widget, (EventMask) PropertyChangeMask, FALSE,
663444c061aSmrg		(XtEventHandler) _XtResourceConfigurationEH, NULL);
664444c061aSmrg#endif
665444c061aSmrg    return(widget);
666444c061aSmrg}
667444c061aSmrg
668444c061aSmrgWidget
669444c061aSmrgXtCreatePopupShell(
670444c061aSmrg    _Xconst char* name,
671444c061aSmrg    WidgetClass widget_class,
672444c061aSmrg    Widget      parent,
673444c061aSmrg    ArgList     args,
674444c061aSmrg    Cardinal    num_args
675444c061aSmrg    )
676444c061aSmrg{
677444c061aSmrg    Widget retval;
678444c061aSmrg    WIDGET_TO_APPCON(parent);
679444c061aSmrg
680444c061aSmrg    LOCK_APP(app);
681444c061aSmrg    retval = _XtCreatePopupShell((String)name, widget_class, parent, args,
682444c061aSmrg		num_args, (XtTypedArgList)NULL, (Cardinal)0);
683444c061aSmrg    UNLOCK_APP(app);
684444c061aSmrg    return retval;
685444c061aSmrg}
686444c061aSmrg
687444c061aSmrgWidget
688444c061aSmrg_XtAppCreateShell(
689444c061aSmrg    String      name,
690444c061aSmrg    String      class,
691444c061aSmrg    WidgetClass widget_class,
692444c061aSmrg    Display*    display,
693444c061aSmrg    ArgList     args,
694444c061aSmrg    Cardinal    num_args,
695444c061aSmrg    XtTypedArgList typed_args,
696444c061aSmrg    Cardinal	num_typed_args)
697444c061aSmrg{
698444c061aSmrg    Widget shell;
699444c061aSmrg
700444c061aSmrg    if (widget_class == NULL) {
701444c061aSmrg	XtAppErrorMsg(XtDisplayToApplicationContext(display),
702444c061aSmrg		"invalidClass","xtAppCreateShell",XtCXtToolkitError,
703444c061aSmrg		"XtAppCreateShell requires non-NULL widget class",
704444c061aSmrg		(String *)NULL, (Cardinal *)NULL);
705444c061aSmrg    }
706444c061aSmrg    if (name == NULL)
707444c061aSmrg	name = XrmNameToString(_XtGetPerDisplay(display)->name);
708444c061aSmrg    shell = xtCreate(name, class, widget_class, (Widget)NULL,
709444c061aSmrg		(Screen*)DefaultScreenOfDisplay(display),
710444c061aSmrg		args, num_args, typed_args, num_typed_args,
711444c061aSmrg		(ConstraintWidgetClass) NULL, _XtAddShellToHookObj);
712444c061aSmrg
713444c061aSmrg#ifndef X_NO_RESOURCE_CONFIGURATION_MANAGEMENT
714444c061aSmrg    XtAddEventHandler (shell, (EventMask) PropertyChangeMask, FALSE,
715444c061aSmrg		(XtEventHandler) _XtResourceConfigurationEH, NULL);
716444c061aSmrg#endif
717444c061aSmrg
718444c061aSmrg    return shell;
719444c061aSmrg}
720444c061aSmrg
721444c061aSmrgWidget
722444c061aSmrgXtAppCreateShell(
723444c061aSmrg    _Xconst char*       name,
724444c061aSmrg    _Xconst char*       class,
725444c061aSmrg    WidgetClass         widget_class,
726444c061aSmrg    Display             *display,
727444c061aSmrg    ArgList             args,
728444c061aSmrg    Cardinal            num_args
729444c061aSmrg    )
730444c061aSmrg{
731444c061aSmrg    Widget retval;
732444c061aSmrg    DPY_TO_APPCON(display);
733444c061aSmrg
734444c061aSmrg    LOCK_APP(app);
735444c061aSmrg    retval = _XtAppCreateShell((String)name, (String)class, widget_class,
736444c061aSmrg		display, args, num_args, (XtTypedArgList)NULL, (Cardinal)0);
737444c061aSmrg    UNLOCK_APP(app);
738444c061aSmrg    return retval;
739444c061aSmrg}
740444c061aSmrg
741444c061aSmrg/* ARGSUSED */
742444c061aSmrgWidget
743444c061aSmrgXtCreateApplicationShell(
744444c061aSmrg    _Xconst char* name,		/* unused in R3 and later */
745444c061aSmrg    WidgetClass widget_class,
746444c061aSmrg    ArgList     args,
747444c061aSmrg    Cardinal    num_args
748444c061aSmrg    )
749444c061aSmrg{
750444c061aSmrg    Widget retval;
751444c061aSmrg    Display* dpy;
752444c061aSmrg    XrmClass class;
753444c061aSmrg    XtAppContext app = _XtDefaultAppContext();
754444c061aSmrg
755444c061aSmrg    LOCK_APP(app);
756444c061aSmrg    dpy = app->list[0];
757444c061aSmrg    class = _XtGetPerDisplay(dpy)->class;
758444c061aSmrg
759444c061aSmrg    retval = _XtAppCreateShell((String)NULL, XrmQuarkToString((XrmQuark)class),
760444c061aSmrg		widget_class, dpy, args, num_args,
761444c061aSmrg		(XtTypedArgList)NULL, (Cardinal)0);
762444c061aSmrg    UNLOCK_APP(app);
763444c061aSmrg    return retval;
764444c061aSmrg}
765444c061aSmrg
766444c061aSmrgWidget
767444c061aSmrg_XtCreateHookObj(Screen* screen)
768444c061aSmrg{
769444c061aSmrg    Widget req_widget;
770444c061aSmrg    double widget_cache[100];
771444c061aSmrg    Cardinal wsize = 0;
772444c061aSmrg    Widget hookobj = xtWidgetAlloc(hookObjectClass,
773444c061aSmrg		(ConstraintWidgetClass)NULL,
774444c061aSmrg		(Widget)NULL, "hooks",
775444c061aSmrg		(ArgList)NULL, (Cardinal)0,
776444c061aSmrg		(XtTypedArgList)NULL, (Cardinal)0);
777444c061aSmrg
778444c061aSmrg    ((HookObject)hookobj)->hooks.screen = screen;
779444c061aSmrg    (void) _XtGetResources(hookobj, (ArgList)NULL, 0,
780444c061aSmrg		(XtTypedArgList)NULL, &wsize);
781444c061aSmrg    CompileCallbacks(hookobj);
782444c061aSmrg    wsize = hookObjectClass->core_class.widget_size;
783444c061aSmrg    req_widget = (Widget) XtStackAlloc(wsize, widget_cache);
784444c061aSmrg    (void) memmove ((char *) req_widget, (char *) hookobj, (int) wsize);
785444c061aSmrg    CallInitialize (hookObjectClass, req_widget, hookobj,
786444c061aSmrg		(ArgList)NULL, (Cardinal) 0);
787444c061aSmrg    XtStackFree((XtPointer)req_widget, widget_cache);
788444c061aSmrg    return hookobj;
789444c061aSmrg}
790