1444c061aSmrg/***********************************************************
2fdf6a26fSmrgCopyright (c) 1993, Oracle and/or its affiliates.
31477040fSmrg
41477040fSmrgPermission is hereby granted, free of charge, to any person obtaining a
51477040fSmrgcopy of this software and associated documentation files (the "Software"),
61477040fSmrgto deal in the Software without restriction, including without limitation
71477040fSmrgthe rights to use, copy, modify, merge, publish, distribute, sublicense,
81477040fSmrgand/or sell copies of the Software, and to permit persons to whom the
91477040fSmrgSoftware is furnished to do so, subject to the following conditions:
101477040fSmrg
111477040fSmrgThe above copyright notice and this permission notice (including the next
121477040fSmrgparagraph) shall be included in all copies or substantial portions of the
131477040fSmrgSoftware.
141477040fSmrg
151477040fSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
161477040fSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
171477040fSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
181477040fSmrgTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
191477040fSmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
201477040fSmrgFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
211477040fSmrgDEALINGS IN THE SOFTWARE.
221477040fSmrg
231477040fSmrgCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
24444c061aSmrg
25444c061aSmrg                        All Rights Reserved
26444c061aSmrg
27444c061aSmrgPermission to use, copy, modify, and distribute this software and its
28444c061aSmrgdocumentation for any purpose and without fee is hereby granted,
29444c061aSmrgprovided that the above copyright notice appear in all copies and that
30444c061aSmrgboth that copyright notice and this permission notice appear in
311477040fSmrgsupporting documentation, and that the name of Digital not be
32444c061aSmrgused in advertising or publicity pertaining to distribution of the
33444c061aSmrgsoftware without specific, written prior permission.
34444c061aSmrg
35444c061aSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
36444c061aSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
37444c061aSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
38444c061aSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
39444c061aSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
40444c061aSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
41444c061aSmrgSOFTWARE.
42444c061aSmrg
43444c061aSmrg******************************************************************/
44444c061aSmrg
45444c061aSmrg/*
46444c061aSmrg
47444c061aSmrgCopyright 1987, 1988, 1994, 1998  The Open Group
48444c061aSmrg
49444c061aSmrgPermission to use, copy, modify, distribute, and sell this software and its
50444c061aSmrgdocumentation for any purpose is hereby granted without fee, provided that
51444c061aSmrgthe above copyright notice appear in all copies and that both that
52444c061aSmrgcopyright notice and this permission notice appear in supporting
53444c061aSmrgdocumentation.
54444c061aSmrg
55444c061aSmrgThe above copyright notice and this permission notice shall be included in
56444c061aSmrgall copies or substantial portions of the Software.
57444c061aSmrg
58444c061aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59444c061aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60444c061aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
61444c061aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
62444c061aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
63444c061aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
64444c061aSmrg
65444c061aSmrgExcept as contained in this notice, the name of The Open Group shall not be
66444c061aSmrgused in advertising or otherwise to promote the sale, use or other dealings
67444c061aSmrgin this Software without prior written authorization from The Open Group.
68444c061aSmrg
69444c061aSmrg*/
70444c061aSmrg
71444c061aSmrg#ifdef HAVE_CONFIG_H
72444c061aSmrg#include <config.h>
73444c061aSmrg#endif
74444c061aSmrg#include "IntrinsicI.h"
75444c061aSmrg#include "VarargsI.h"
76444c061aSmrg#include "ShellP.h"
77444c061aSmrg#include "CreateI.h"
78444c061aSmrg#ifndef X_NO_RESOURCE_CONFIGURATION_MANAGEMENT
79444c061aSmrg#include "ResConfigP.h"
80444c061aSmrg#endif
81444c061aSmrg#include <stdio.h>
82444c061aSmrg
830568f49bSmrgstatic _Xconst _XtString XtNxtCreateWidget = "xtCreateWidget";
840568f49bSmrgstatic _Xconst _XtString XtNxtCreatePopupShell = "xtCreatePopupShell";
85444c061aSmrg
86444c061aSmrgstatic void
87444c061aSmrgCallClassPartInit(WidgetClass ancestor, WidgetClass wc)
88444c061aSmrg{
89444c061aSmrg    if (ancestor->core_class.superclass != NULL) {
90a3bd7f05Smrg        CallClassPartInit(ancestor->core_class.superclass, wc);
91444c061aSmrg    }
92444c061aSmrg    if (ancestor->core_class.class_part_initialize != NULL) {
93a3bd7f05Smrg        (*(ancestor->core_class.class_part_initialize)) (wc);
94444c061aSmrg    }
95444c061aSmrg}
96444c061aSmrg
97444c061aSmrgvoid
982265a131SmrgXtInitializeWidgetClass(WidgetClass wc)
99444c061aSmrg{
100444c061aSmrg    XtEnum inited;
101a3bd7f05Smrg
102444c061aSmrg    LOCK_PROCESS;
103444c061aSmrg    if (wc->core_class.class_inited) {
104a3bd7f05Smrg        UNLOCK_PROCESS;
105a3bd7f05Smrg        return;
106444c061aSmrg    }
107444c061aSmrg    inited = 0x01;
108444c061aSmrg    {
109a3bd7f05Smrg        WidgetClass pc;
110a3bd7f05Smrg
111444c061aSmrg#define LeaveIfClass(c, d) if (pc == c) { inited = d; break; }
112a3bd7f05Smrg        for (pc = wc; pc; pc = pc->core_class.superclass) {
113a3bd7f05Smrg            LeaveIfClass(rectObjClass, 0x01 | RectObjClassFlag);
114a3bd7f05Smrg            LeaveIfClass(coreWidgetClass, 0x01 |
115a3bd7f05Smrg                         RectObjClassFlag | WidgetClassFlag);
116a3bd7f05Smrg            LeaveIfClass(compositeWidgetClass, 0x01 |
117a3bd7f05Smrg                         RectObjClassFlag |
118a3bd7f05Smrg                         WidgetClassFlag | CompositeClassFlag);
119a3bd7f05Smrg            LeaveIfClass(constraintWidgetClass, 0x01 |
120a3bd7f05Smrg                         RectObjClassFlag |
121a3bd7f05Smrg                         WidgetClassFlag |
122a3bd7f05Smrg                         CompositeClassFlag | ConstraintClassFlag);
123a3bd7f05Smrg            LeaveIfClass(shellWidgetClass, 0x01 |
124a3bd7f05Smrg                         RectObjClassFlag |
125a3bd7f05Smrg                         WidgetClassFlag | CompositeClassFlag | ShellClassFlag);
126a3bd7f05Smrg            LeaveIfClass(wmShellWidgetClass, 0x01 |
127a3bd7f05Smrg                         RectObjClassFlag |
128a3bd7f05Smrg                         WidgetClassFlag |
129a3bd7f05Smrg                         CompositeClassFlag |
130a3bd7f05Smrg                         ShellClassFlag | WMShellClassFlag);
131a3bd7f05Smrg            LeaveIfClass(topLevelShellWidgetClass, 0x01 |
132a3bd7f05Smrg                         RectObjClassFlag |
133a3bd7f05Smrg                         WidgetClassFlag |
134a3bd7f05Smrg                         CompositeClassFlag |
135a3bd7f05Smrg                         ShellClassFlag | WMShellClassFlag | TopLevelClassFlag);
136a3bd7f05Smrg        }
137444c061aSmrg#undef LeaveIfClass
138444c061aSmrg    }
139444c061aSmrg    if (wc->core_class.version != XtVersion &&
140a3bd7f05Smrg        wc->core_class.version != XtVersionDontCheck) {
141a3bd7f05Smrg        String param[3];
142a3bd7f05Smrg        _Xconst _XtString mismatch =
143a3bd7f05Smrg            "Widget class %s version mismatch (recompilation needed):\n  widget %d vs. intrinsics %d.";
144a3bd7f05Smrg        _Xconst _XtString recompile = "Widget class %s must be re-compiled.";
145a3bd7f05Smrg        Cardinal num_params;
146a3bd7f05Smrg
147a3bd7f05Smrg        param[0] = wc->core_class.class_name;
148fdf6a26fSmrg        param[1] = (String) (XtIntPtr) wc->core_class.version;
149fdf6a26fSmrg        param[2] = (String) (XtIntPtr) XtVersion;
150a3bd7f05Smrg
151a3bd7f05Smrg        if (wc->core_class.version == (11 * 1000 + 5) ||        /* MIT X11R5 */
152a3bd7f05Smrg            wc->core_class.version == (11 * 1000 + 4)) {        /* MIT X11R4 */
153a3bd7f05Smrg            if ((inited & WMShellClassFlag) &&
154a3bd7f05Smrg                (sizeof(Boolean) != sizeof(char) ||
155a3bd7f05Smrg                 sizeof(Atom) != sizeof(Widget) ||
156a3bd7f05Smrg                 sizeof(Atom) != sizeof(String))) {
157a3bd7f05Smrg                num_params = 3;
158a3bd7f05Smrg                XtWarningMsg("versionMismatch", "widget", XtCXtToolkitError,
159a3bd7f05Smrg                             mismatch, param, &num_params);
160a3bd7f05Smrg                num_params = 1;
161a3bd7f05Smrg                XtErrorMsg("R4orR5versionMismatch", "widget", XtCXtToolkitError,
162a3bd7f05Smrg                           recompile, param, &num_params);
163a3bd7f05Smrg
164a3bd7f05Smrg            }
165a3bd7f05Smrg        }
166a3bd7f05Smrg        else if (wc->core_class.version == (11 * 1000 + 3)) {   /* MIT X11R3 */
167a3bd7f05Smrg            if (inited & ShellClassFlag) {
168a3bd7f05Smrg                num_params = 1;
169a3bd7f05Smrg                XtWarningMsg("r3versionMismatch", "widget", XtCXtToolkitError,
170a3bd7f05Smrg                             "Shell Widget class %s binary compiled for R3",
171a3bd7f05Smrg                             param, &num_params);
172a3bd7f05Smrg                XtErrorMsg("R3versionMismatch", "widget", XtCXtToolkitError,
173a3bd7f05Smrg                           recompile, param, &num_params);
174a3bd7f05Smrg            }
175a3bd7f05Smrg        }
176a3bd7f05Smrg        else {
177a3bd7f05Smrg            num_params = 3;
178a3bd7f05Smrg            XtWarningMsg("versionMismatch", "widget", XtCXtToolkitError,
179a3bd7f05Smrg                         mismatch, param, &num_params);
180a3bd7f05Smrg            if (wc->core_class.version == (2 * 1000 + 2)) {     /* MIT X11R2 */
181a3bd7f05Smrg                num_params = 1;
182a3bd7f05Smrg                XtErrorMsg("r2versionMismatch", "widget", XtCXtToolkitError,
183a3bd7f05Smrg                           recompile, param, &num_params);
184a3bd7f05Smrg            }
185a3bd7f05Smrg        }
186444c061aSmrg    }
187444c061aSmrg
188444c061aSmrg    if ((wc->core_class.superclass != NULL)
189a3bd7f05Smrg        && (!(wc->core_class.superclass->core_class.class_inited)))
190a3bd7f05Smrg        XtInitializeWidgetClass(wc->core_class.superclass);
191444c061aSmrg
192444c061aSmrg    if (wc->core_class.class_initialize != NULL)
193a3bd7f05Smrg        (*(wc->core_class.class_initialize)) ();
194444c061aSmrg    CallClassPartInit(wc, wc);
195444c061aSmrg    wc->core_class.class_inited = inited;
196444c061aSmrg    UNLOCK_PROCESS;
197444c061aSmrg}
198444c061aSmrg
199444c061aSmrgstatic void
200a3bd7f05SmrgCallInitialize(WidgetClass class,
201a3bd7f05Smrg               Widget req_widget,
202a3bd7f05Smrg               Widget new_widget,
203a3bd7f05Smrg               ArgList args,
204a3bd7f05Smrg               Cardinal num_args)
205444c061aSmrg{
206444c061aSmrg    WidgetClass superclass;
207444c061aSmrg    XtInitProc initialize;
208444c061aSmrg    XtArgsProc initialize_hook;
209444c061aSmrg
210444c061aSmrg    LOCK_PROCESS;
211444c061aSmrg    superclass = class->core_class.superclass;
212444c061aSmrg    UNLOCK_PROCESS;
213444c061aSmrg    if (superclass)
214a3bd7f05Smrg        CallInitialize(superclass, req_widget, new_widget, args, num_args);
215444c061aSmrg    LOCK_PROCESS;
216444c061aSmrg    initialize = class->core_class.initialize;
217444c061aSmrg    UNLOCK_PROCESS;
218444c061aSmrg    if (initialize)
219a3bd7f05Smrg        (*initialize) (req_widget, new_widget, args, &num_args);
220444c061aSmrg    LOCK_PROCESS;
221444c061aSmrg    initialize_hook = class->core_class.initialize_hook;
222444c061aSmrg    UNLOCK_PROCESS;
223444c061aSmrg    if (initialize_hook)
224a3bd7f05Smrg        (*initialize_hook) (new_widget, args, &num_args);
225444c061aSmrg}
226444c061aSmrg
227444c061aSmrgstatic void
228a3bd7f05SmrgCallConstraintInitialize(ConstraintWidgetClass class,
229a3bd7f05Smrg                         Widget req_widget,
230a3bd7f05Smrg                         Widget new_widget,
231a3bd7f05Smrg                         ArgList args,
232a3bd7f05Smrg                         Cardinal num_args)
233444c061aSmrg{
234444c061aSmrg    WidgetClass superclass;
235444c061aSmrg    XtInitProc initialize;
236444c061aSmrg
237444c061aSmrg    LOCK_PROCESS;
238444c061aSmrg    superclass = class->core_class.superclass;
239444c061aSmrg    UNLOCK_PROCESS;
240444c061aSmrg    if (superclass != constraintWidgetClass)
241a3bd7f05Smrg        CallConstraintInitialize((ConstraintWidgetClass) superclass,
242a3bd7f05Smrg                                 req_widget, new_widget, args, num_args);
243444c061aSmrg    LOCK_PROCESS;
244444c061aSmrg    initialize = class->constraint_class.initialize;
245444c061aSmrg    UNLOCK_PROCESS;
246444c061aSmrg    if (initialize)
247444c061aSmrg        (*initialize) (req_widget, new_widget, args, &num_args);
248444c061aSmrg}
249444c061aSmrg
250444c061aSmrgstatic Widget
251a3bd7f05SmrgxtWidgetAlloc(WidgetClass widget_class,
252a3bd7f05Smrg              ConstraintWidgetClass parent_constraint_class,
253a3bd7f05Smrg              Widget parent,
254a3bd7f05Smrg              _Xconst _XtString name,
255a3bd7f05Smrg              ArgList args,     /* must be NULL if typed_args is non-NULL */
256a3bd7f05Smrg              Cardinal num_args,
257a3bd7f05Smrg              XtTypedArgList typed_args,     /* must be NULL if args is non-NULL */
258a3bd7f05Smrg              Cardinal num_typed_args)
259444c061aSmrg{
260444c061aSmrg    Widget widget;
261a3bd7f05Smrg    Cardinal csize = 0;
262a3bd7f05Smrg    ObjectClassExtension ext;
263444c061aSmrg
2640568f49bSmrg    if (widget_class == NULL)
265a3bd7f05Smrg        return 0;
2660568f49bSmrg
267444c061aSmrg    LOCK_PROCESS;
268a3bd7f05Smrg    if (!(widget_class->core_class.class_inited))
269a3bd7f05Smrg        XtInitializeWidgetClass(widget_class);
270444c061aSmrg    ext = (ObjectClassExtension)
271a3bd7f05Smrg        XtGetClassExtension(widget_class,
272a3bd7f05Smrg                            XtOffsetOf(ObjectClassRec, object_class.extension),
273a3bd7f05Smrg                            NULLQUARK, XtObjectExtensionVersion,
274a3bd7f05Smrg                            sizeof(ObjectClassExtensionRec));
275444c061aSmrg    if (parent_constraint_class)
276a3bd7f05Smrg        csize = parent_constraint_class->constraint_class.constraint_size;
277444c061aSmrg    if (ext && ext->allocate) {
278a3bd7f05Smrg        XtAllocateProc allocate;
279a3bd7f05Smrg        Cardinal extra = 0;
280a3bd7f05Smrg        Cardinal nargs = num_args;
281a3bd7f05Smrg        Cardinal ntyped = num_typed_args;
282a3bd7f05Smrg
283a3bd7f05Smrg        allocate = ext->allocate;
284a3bd7f05Smrg        UNLOCK_PROCESS;
285a3bd7f05Smrg        (*allocate) (widget_class, &csize, &extra, args, &nargs,
286a3bd7f05Smrg                     typed_args, &ntyped, &widget, NULL);
287a3bd7f05Smrg    }
288a3bd7f05Smrg    else {
2890568f49bSmrg        Cardinal wsize = widget_class->core_class.widget_size;
290a3bd7f05Smrg
291a3bd7f05Smrg        UNLOCK_PROCESS;
292a3bd7f05Smrg        if (csize) {
293a3bd7f05Smrg            if (sizeof(struct {
294a3bd7f05Smrg                       char a; double b;}) != (sizeof(struct {
295a3bd7f05Smrg                                                      char a;
296a3bd7f05Smrg                                                      unsigned long b;}) -
297a3bd7f05Smrg                                               sizeof(unsigned long) +
298a3bd7f05Smrg                                               sizeof(double))) {
299a3bd7f05Smrg                if (csize && !(csize & (sizeof(double) - 1)))
300a3bd7f05Smrg                    wsize = (Cardinal) ((wsize + sizeof(double) - 1)
301a3bd7f05Smrg                                        & ~(sizeof(double) - 1));
302a3bd7f05Smrg            }
303a3bd7f05Smrg        }
304a3bd7f05Smrg        widget = (Widget) __XtCalloc(1, (unsigned) (wsize + csize));
305a3bd7f05Smrg        widget->core.constraints =
306a3bd7f05Smrg            (csize ? (XtPointer) ((char *) widget + wsize) : NULL);
307444c061aSmrg    }
308444c061aSmrg    widget->core.self = widget;
309444c061aSmrg    widget->core.parent = parent;
310444c061aSmrg    widget->core.widget_class = widget_class;
311444c061aSmrg    widget->core.xrm_name = StringToName((name != NULL) ? name : "");
312444c061aSmrg    widget->core.being_destroyed =
313a3bd7f05Smrg        (parent != NULL ? parent->core.being_destroyed : FALSE);
314444c061aSmrg    return widget;
315444c061aSmrg}
316444c061aSmrg
317444c061aSmrgstatic void
318a3bd7f05SmrgCompileCallbacks(Widget widget)
319444c061aSmrg{
320444c061aSmrg    CallbackTable offsets;
321444c061aSmrg    int i;
322444c061aSmrg
323444c061aSmrg    LOCK_PROCESS;
324444c061aSmrg    offsets = (CallbackTable)
325a3bd7f05Smrg        widget->core.widget_class->core_class.callback_private;
326a3bd7f05Smrg
327a3bd7f05Smrg    for (i = (int) (long) *(offsets++); --i >= 0; offsets++) {
328a3bd7f05Smrg        InternalCallbackList *cl = (InternalCallbackList *)
329a3bd7f05Smrg            ((char *) widget - (*offsets)->xrm_offset - 1);
330444c061aSmrg
331a3bd7f05Smrg        if (*cl)
332a3bd7f05Smrg            *cl = _XtCompileCallbackList((XtCallbackList) *cl);
333444c061aSmrg    }
334444c061aSmrg    UNLOCK_PROCESS;
335444c061aSmrg}
336444c061aSmrg
337444c061aSmrgstatic Widget
338a3bd7f05SmrgxtCreate(String name,
339a3bd7f05Smrg         String class,
340a3bd7f05Smrg         WidgetClass widget_class,
341a3bd7f05Smrg         Widget parent,
342a3bd7f05Smrg         Screen *default_screen,    /* undefined when creating a nonwidget */
343a3bd7f05Smrg         ArgList args,          /* must be NULL if typed_args is non-NULL */
344a3bd7f05Smrg         Cardinal num_args,
345a3bd7f05Smrg         XtTypedArgList typed_args,  /* must be NULL if args is non-NULL */
346a3bd7f05Smrg         Cardinal num_typed_args,
347a3bd7f05Smrg         ConstraintWidgetClass parent_constraint_class,
348a3bd7f05Smrg         /* NULL if not a subclass of Constraint or if child is popup shell */
349a3bd7f05Smrg         XtWidgetProc post_proc)
350444c061aSmrg{
351444c061aSmrg    /* need to use strictest alignment rules possible in next two decls. */
352a3bd7f05Smrg    double widget_cache[100];
353a3bd7f05Smrg    Widget req_widget;
354a3bd7f05Smrg    XtPointer req_constraints = NULL;
355fdf6a26fSmrg    Cardinal wsize;
356a3bd7f05Smrg    Widget widget;
357a3bd7f05Smrg    XtCacheRef *cache_refs;
358a3bd7f05Smrg    XtCreateHookDataRec call_data;
359444c061aSmrg
360444c061aSmrg    widget = xtWidgetAlloc(widget_class, parent_constraint_class, parent,
361a3bd7f05Smrg                           name, args, num_args, typed_args, num_typed_args);
362444c061aSmrg
363444c061aSmrg    if (XtIsRectObj(widget)) {
364a3bd7f05Smrg        widget->core.managed = FALSE;
365444c061aSmrg    }
366444c061aSmrg    if (XtIsWidget(widget)) {
367a3bd7f05Smrg        widget->core.name = XrmNameToString(widget->core.xrm_name);
368444c061aSmrg        widget->core.screen = default_screen;
369444c061aSmrg        widget->core.tm.translations = NULL;
370a3bd7f05Smrg        widget->core.window = (Window) 0;
371a3bd7f05Smrg        widget->core.visible = TRUE;
372a3bd7f05Smrg        widget->core.popup_list = NULL;
373a3bd7f05Smrg        widget->core.num_popups = 0;
374444c061aSmrg    };
375444c061aSmrg    LOCK_PROCESS;
376444c061aSmrg    if (XtIsApplicationShell(widget)) {
377a3bd7f05Smrg        ApplicationShellWidget a = (ApplicationShellWidget) widget;
378a3bd7f05Smrg
379a3bd7f05Smrg        if (class != NULL)
380a3bd7f05Smrg            a->application.xrm_class = StringToClass(class);
381a3bd7f05Smrg        else
382a3bd7f05Smrg            a->application.xrm_class = widget_class->core_class.xrm_class;
383a3bd7f05Smrg        a->application.class = XrmQuarkToString(a->application.xrm_class);
384444c061aSmrg    }
385444c061aSmrg    UNLOCK_PROCESS;
386444c061aSmrg
387444c061aSmrg    /* fetch resources */
388444c061aSmrg    cache_refs = _XtGetResources(widget, args, num_args,
389a3bd7f05Smrg                                 typed_args, &num_typed_args);
390444c061aSmrg
391444c061aSmrg    /* Convert typed arg list to arg list */
392444c061aSmrg    if (typed_args != NULL && num_typed_args > 0) {
393a3bd7f05Smrg        Cardinal i;
394a3bd7f05Smrg
395a3bd7f05Smrg        args = (ArgList) ALLOCATE_LOCAL(sizeof(Arg) * num_typed_args);
396a3bd7f05Smrg        if (args == NULL)
397a3bd7f05Smrg            _XtAllocError(NULL);
398a3bd7f05Smrg        for (i = 0; i < num_typed_args; i++) {
399a3bd7f05Smrg            args[i].name = typed_args[i].name;
400a3bd7f05Smrg            args[i].value = typed_args[i].value;
401a3bd7f05Smrg        }
402a3bd7f05Smrg        num_args = num_typed_args;
403444c061aSmrg    }
404444c061aSmrg
405444c061aSmrg    CompileCallbacks(widget);
406444c061aSmrg
407444c061aSmrg    if (cache_refs != NULL) {
408a3bd7f05Smrg        XtAddCallback(widget, XtNdestroyCallback,
409a3bd7f05Smrg                      XtCallbackReleaseCacheRefList, (XtPointer) cache_refs);
410444c061aSmrg    }
411444c061aSmrg
412444c061aSmrg    wsize = widget_class->core_class.widget_size;
413444c061aSmrg    req_widget = (Widget) XtStackAlloc(wsize, widget_cache);
414fdf6a26fSmrg    (void) memcpy(req_widget, (char *) widget, (size_t) wsize);
415a3bd7f05Smrg    CallInitialize(XtClass(widget), req_widget, widget, args, num_args);
416444c061aSmrg    if (parent_constraint_class != NULL) {
417a3bd7f05Smrg        double constraint_cache[20];
418fdf6a26fSmrg        Cardinal csize;
419a3bd7f05Smrg
420444c061aSmrg        csize = parent_constraint_class->constraint_class.constraint_size;
421a3bd7f05Smrg        if (csize) {
422a3bd7f05Smrg            req_constraints = XtStackAlloc(csize, constraint_cache);
423fdf6a26fSmrg            (void) memcpy(req_constraints, widget->core.constraints,
424a3bd7f05Smrg                           (size_t) csize);
425a3bd7f05Smrg            req_widget->core.constraints = req_constraints;
426a3bd7f05Smrg        }
427a3bd7f05Smrg        else
428a3bd7f05Smrg            req_widget->core.constraints = NULL;
429a3bd7f05Smrg        CallConstraintInitialize(parent_constraint_class, req_widget, widget,
430a3bd7f05Smrg                                 args, num_args);
431a3bd7f05Smrg        if (csize) {
432a3bd7f05Smrg            XtStackFree(req_constraints, constraint_cache);
433a3bd7f05Smrg        }
434444c061aSmrg    }
435a3bd7f05Smrg    XtStackFree((XtPointer) req_widget, widget_cache);
436fdf6a26fSmrg    if (post_proc != (XtWidgetProc) NULL && (parent != NULL)) {
437a3bd7f05Smrg        Widget hookobj;
438a3bd7f05Smrg
439a3bd7f05Smrg        (*post_proc) (widget);
440a3bd7f05Smrg        hookobj = XtHooksOfDisplay((default_screen != (Screen *) NULL) ?
441a3bd7f05Smrg                                   default_screen->display :
442a3bd7f05Smrg                                   XtDisplayOfObject(parent));
443a3bd7f05Smrg        if (XtHasCallbacks(hookobj, XtNcreateHook) == XtCallbackHasSome) {
444a3bd7f05Smrg
445a3bd7f05Smrg            call_data.type = XtHcreate;
446a3bd7f05Smrg            call_data.widget = widget;
447a3bd7f05Smrg            call_data.args = args;
448a3bd7f05Smrg            call_data.num_args = num_args;
449a3bd7f05Smrg            XtCallCallbackList(hookobj,
450a3bd7f05Smrg                               ((HookObject) hookobj)->hooks.
451a3bd7f05Smrg                               createhook_callbacks, (XtPointer) &call_data);
452a3bd7f05Smrg        }
453444c061aSmrg    }
454444c061aSmrg    if (typed_args != NULL) {
455a3bd7f05Smrg        while (num_typed_args-- > 0) {
456a3bd7f05Smrg
457a3bd7f05Smrg            /* In GetResources we may have dynamically alloc'd store to hold */
458a3bd7f05Smrg            /* a copy of a resource which was larger then sizeof(XtArgVal). */
459a3bd7f05Smrg            /* We must free this store now in order to prevent a memory leak */
460a3bd7f05Smrg            /* A typed arg that has a converted value in dynamic store has a */
461a3bd7f05Smrg            /* negated size field. */
462a3bd7f05Smrg
463a3bd7f05Smrg            if (typed_args->type != NULL && typed_args->size < 0) {
464a3bd7f05Smrg                XtFree((char *) typed_args->value);
465a3bd7f05Smrg                typed_args->size = -(typed_args->size);
466a3bd7f05Smrg            }
467a3bd7f05Smrg            typed_args++;
468a3bd7f05Smrg        }
469a3bd7f05Smrg        DEALLOCATE_LOCAL((char *) args);
470444c061aSmrg    }
471444c061aSmrg    return (widget);
472444c061aSmrg}
473444c061aSmrg
474444c061aSmrgstatic void
475444c061aSmrgwidgetPostProc(Widget w)
476444c061aSmrg{
477444c061aSmrg    XtWidgetProc insert_child;
478444c061aSmrg    Widget parent = XtParent(w);
479444c061aSmrg    String param = XtName(w);
480444c061aSmrg    Cardinal num_params = 1;
481444c061aSmrg
482444c061aSmrg    if (XtIsComposite(parent)) {
483a3bd7f05Smrg        LOCK_PROCESS;
484a3bd7f05Smrg        insert_child =
485a3bd7f05Smrg            ((CompositeWidgetClass) parent->core.widget_class)->composite_class.
486a3bd7f05Smrg            insert_child;
487a3bd7f05Smrg        UNLOCK_PROCESS;
488a3bd7f05Smrg    }
489a3bd7f05Smrg    else {
490a3bd7f05Smrg        return;
491444c061aSmrg    }
492444c061aSmrg    if (insert_child == NULL) {
493a3bd7f05Smrg        XtAppErrorMsg(XtWidgetToApplicationContext(parent),
494a3bd7f05Smrg                      "nullProc", "insertChild", XtCXtToolkitError,
495a3bd7f05Smrg                      "\"%s\" parent has NULL insert_child method",
496a3bd7f05Smrg                      &param, &num_params);
497a3bd7f05Smrg    }
498a3bd7f05Smrg    else {
499a3bd7f05Smrg        (*insert_child) (w);
500444c061aSmrg    }
501444c061aSmrg}
502444c061aSmrg
503444c061aSmrgWidget
504a3bd7f05Smrg_XtCreateWidget(String name,
505a3bd7f05Smrg                WidgetClass widget_class,
506a3bd7f05Smrg                Widget parent,
507a3bd7f05Smrg                ArgList args,
508a3bd7f05Smrg                Cardinal num_args,
509a3bd7f05Smrg                XtTypedArgList typed_args,
510a3bd7f05Smrg                Cardinal num_typed_args)
511444c061aSmrg{
512a3bd7f05Smrg    register Widget widget;
513a3bd7f05Smrg    ConstraintWidgetClass cwc;
514a3bd7f05Smrg    Screen *default_screen;
515a3bd7f05Smrg    XtEnum class_inited;
516a3bd7f05Smrg    String params[3];
517a3bd7f05Smrg    Cardinal num_params;
518444c061aSmrg
519444c061aSmrg    params[0] = name;
520444c061aSmrg    num_params = 1;
521444c061aSmrg
522444c061aSmrg    if (parent == NULL) {
523a3bd7f05Smrg        XtErrorMsg("invalidParent", XtNxtCreateWidget, XtCXtToolkitError,
524a3bd7f05Smrg                   "XtCreateWidget \"%s\" requires non-NULL parent",
525a3bd7f05Smrg                   params, &num_params);
526a3bd7f05Smrg    }
527a3bd7f05Smrg    else if (widget_class == NULL) {
528a3bd7f05Smrg        XtAppErrorMsg(XtWidgetToApplicationContext(parent),
529a3bd7f05Smrg                      "invalidClass", XtNxtCreateWidget, XtCXtToolkitError,
530a3bd7f05Smrg                      "XtCreateWidget \"%s\" requires non-NULL widget class",
531a3bd7f05Smrg                      params, &num_params);
532444c061aSmrg    }
533444c061aSmrg    LOCK_PROCESS;
534444c061aSmrg    if (!widget_class->core_class.class_inited)
535a3bd7f05Smrg        XtInitializeWidgetClass(widget_class);
536444c061aSmrg    class_inited = widget_class->core_class.class_inited;
537444c061aSmrg    UNLOCK_PROCESS;
538444c061aSmrg    if ((class_inited & WidgetClassFlag) == 0) {
539a3bd7f05Smrg        /* not a widget */
540a3bd7f05Smrg        default_screen = NULL;
541a3bd7f05Smrg        if (XtIsComposite(parent)) {
542a3bd7f05Smrg            CompositeClassExtension ext;
543a3bd7f05Smrg
544a3bd7f05Smrg            ext = (CompositeClassExtension)
545a3bd7f05Smrg                XtGetClassExtension(XtClass(parent),
546a3bd7f05Smrg                                    XtOffsetOf(CompositeClassRec,
547a3bd7f05Smrg                                               composite_class.extension),
548a3bd7f05Smrg                                    NULLQUARK, 1L, (Cardinal) 0);
549a3bd7f05Smrg            LOCK_PROCESS;
550a3bd7f05Smrg            if (ext &&
551a3bd7f05Smrg                (ext->version > XtCompositeExtensionVersion ||
552a3bd7f05Smrg                 ext->record_size > sizeof(CompositeClassExtensionRec))) {
553a3bd7f05Smrg                params[1] = XtClass(parent)->core_class.class_name;
554a3bd7f05Smrg                num_params = 2;
555a3bd7f05Smrg                XtAppWarningMsg(XtWidgetToApplicationContext(parent),
556a3bd7f05Smrg                                "invalidExtension", XtNxtCreateWidget,
557a3bd7f05Smrg                                XtCXtToolkitError,
558a3bd7f05Smrg                                "widget \"%s\" class %s has invalid CompositeClassExtension record",
559a3bd7f05Smrg                                params, &num_params);
560a3bd7f05Smrg            }
561a3bd7f05Smrg            if (!ext || !ext->accepts_objects) {
562a3bd7f05Smrg                params[1] = XtName(parent);
563a3bd7f05Smrg                num_params = 2;
564a3bd7f05Smrg                XtAppErrorMsg(XtWidgetToApplicationContext(parent),
565a3bd7f05Smrg                              "nonWidget", XtNxtCreateWidget, XtCXtToolkitError,
566a3bd7f05Smrg                              "attempt to add non-widget child \"%s\" to parent \"%s\" which supports only widgets",
567a3bd7f05Smrg                              params, &num_params);
568a3bd7f05Smrg            }
569a3bd7f05Smrg            UNLOCK_PROCESS;
570a3bd7f05Smrg        }
571a3bd7f05Smrg    }
572a3bd7f05Smrg    else {
573a3bd7f05Smrg        default_screen = parent->core.screen;
574444c061aSmrg    }
575444c061aSmrg
576444c061aSmrg    if (XtIsConstraint(parent)) {
577a3bd7f05Smrg        cwc = (ConstraintWidgetClass) parent->core.widget_class;
578a3bd7f05Smrg    }
579a3bd7f05Smrg    else {
580a3bd7f05Smrg        cwc = NULL;
581444c061aSmrg    }
582a3bd7f05Smrg    widget = xtCreate(name, (char *) NULL, widget_class, parent,
583a3bd7f05Smrg                      default_screen, args, num_args,
584a3bd7f05Smrg                      typed_args, num_typed_args, cwc, widgetPostProc);
585444c061aSmrg    return (widget);
586444c061aSmrg}
587444c061aSmrg
588444c061aSmrgWidget
589a3bd7f05SmrgXtCreateWidget(_Xconst char *name,
590a3bd7f05Smrg               WidgetClass widget_class,
591a3bd7f05Smrg               Widget parent,
592a3bd7f05Smrg               ArgList args,
593a3bd7f05Smrg               Cardinal num_args)
594444c061aSmrg{
595444c061aSmrg    Widget retval;
596a3bd7f05Smrg
597444c061aSmrg    WIDGET_TO_APPCON(parent);
598444c061aSmrg
599444c061aSmrg    LOCK_APP(app);
600a3bd7f05Smrg    retval =
601a3bd7f05Smrg        _XtCreateWidget((String) name, widget_class, parent, args, num_args,
602a3bd7f05Smrg                        (XtTypedArgList) NULL, (Cardinal) 0);
603444c061aSmrg    UNLOCK_APP(app);
604444c061aSmrg    return retval;
605444c061aSmrg}
606444c061aSmrg
607444c061aSmrgWidget
608a3bd7f05SmrgXtCreateManagedWidget(_Xconst char *name,
609a3bd7f05Smrg                      WidgetClass widget_class,
610a3bd7f05Smrg                      Widget parent,
611a3bd7f05Smrg                      ArgList args,
612a3bd7f05Smrg                      Cardinal num_args)
613444c061aSmrg{
614a3bd7f05Smrg    register Widget widget;
615a3bd7f05Smrg
616444c061aSmrg    WIDGET_TO_APPCON(parent);
617444c061aSmrg
618444c061aSmrg    LOCK_APP(app);
619444c061aSmrg    XtCheckSubclass(parent, compositeWidgetClass, "in XtCreateManagedWidget");
620a3bd7f05Smrg    widget = _XtCreateWidget((String) name, widget_class, parent, args,
621a3bd7f05Smrg                             num_args, (XtTypedArgList) NULL, (Cardinal) 0);
622444c061aSmrg    XtManageChild(widget);
623444c061aSmrg    UNLOCK_APP(app);
624444c061aSmrg    return widget;
625444c061aSmrg}
626444c061aSmrg
627444c061aSmrgstatic void
628444c061aSmrgpopupPostProc(Widget w)
629444c061aSmrg{
630444c061aSmrg    Widget parent = XtParent(w);
631444c061aSmrg
632fdf6a26fSmrg    parent->core.popup_list = XtReallocArray(parent->core.popup_list,
633fdf6a26fSmrg                                             (parent->core.num_popups + 1),
634fdf6a26fSmrg                                             (Cardinal) sizeof(Widget));
635444c061aSmrg    parent->core.popup_list[parent->core.num_popups++] = w;
636444c061aSmrg}
637444c061aSmrg
638444c061aSmrgWidget
639a3bd7f05Smrg_XtCreatePopupShell(String name,
640a3bd7f05Smrg                    WidgetClass widget_class,
641a3bd7f05Smrg                    Widget parent,
642a3bd7f05Smrg                    ArgList args,
643a3bd7f05Smrg                    Cardinal num_args,
644a3bd7f05Smrg                    XtTypedArgList typed_args,
645a3bd7f05Smrg                    Cardinal num_typed_args)
646444c061aSmrg{
647444c061aSmrg    register Widget widget;
648a3bd7f05Smrg    Screen *default_screen;
649444c061aSmrg
650444c061aSmrg    if (parent == NULL) {
651a3bd7f05Smrg        XtErrorMsg("invalidParent", XtNxtCreatePopupShell, XtCXtToolkitError,
652a3bd7f05Smrg                   "XtCreatePopupShell requires non-NULL parent", NULL, NULL);
653a3bd7f05Smrg    }
654a3bd7f05Smrg    else if (widget_class == NULL) {
655a3bd7f05Smrg        XtAppErrorMsg(XtWidgetToApplicationContext(parent),
656a3bd7f05Smrg                      "invalidClass", XtNxtCreatePopupShell, XtCXtToolkitError,
657a3bd7f05Smrg                      "XtCreatePopupShell requires non-NULL widget class",
658a3bd7f05Smrg                      NULL, NULL);
659444c061aSmrg    }
660444c061aSmrg    XtCheckSubclass(parent, coreWidgetClass, "in XtCreatePopupShell");
661444c061aSmrg    default_screen = parent->core.screen;
662a3bd7f05Smrg    widget = xtCreate(name, (char *) NULL, widget_class, parent,
663a3bd7f05Smrg                      default_screen, args, num_args, typed_args,
664a3bd7f05Smrg                      num_typed_args, (ConstraintWidgetClass) NULL,
665a3bd7f05Smrg                      popupPostProc);
666444c061aSmrg
667444c061aSmrg#ifndef X_NO_RESOURCE_CONFIGURATION_MANAGEMENT
668a3bd7f05Smrg    XtAddEventHandler(widget, (EventMask) PropertyChangeMask, FALSE,
66935525df4Smrg                      _XtResourceConfigurationEH, NULL);
670444c061aSmrg#endif
671a3bd7f05Smrg    return (widget);
672444c061aSmrg}
673444c061aSmrg
674444c061aSmrgWidget
675a3bd7f05SmrgXtCreatePopupShell(_Xconst char *name,
676a3bd7f05Smrg                   WidgetClass widget_class,
677a3bd7f05Smrg                   Widget parent,
678a3bd7f05Smrg                   ArgList args,
679a3bd7f05Smrg                   Cardinal num_args)
680444c061aSmrg{
681444c061aSmrg    Widget retval;
682a3bd7f05Smrg
683444c061aSmrg    WIDGET_TO_APPCON(parent);
684444c061aSmrg
685444c061aSmrg    LOCK_APP(app);
686a3bd7f05Smrg    retval = _XtCreatePopupShell((String) name, widget_class, parent, args,
687a3bd7f05Smrg                                 num_args, (XtTypedArgList) NULL, (Cardinal) 0);
688444c061aSmrg    UNLOCK_APP(app);
689444c061aSmrg    return retval;
690444c061aSmrg}
691444c061aSmrg
692444c061aSmrgWidget
693a3bd7f05Smrg_XtAppCreateShell(String name,
694a3bd7f05Smrg                  String class,
695a3bd7f05Smrg                  WidgetClass widget_class,
696a3bd7f05Smrg                  Display *display,
697a3bd7f05Smrg                  ArgList args,
698a3bd7f05Smrg                  Cardinal num_args,
699a3bd7f05Smrg                  XtTypedArgList typed_args,
700a3bd7f05Smrg                  Cardinal num_typed_args)
701444c061aSmrg{
702444c061aSmrg    Widget shell;
703444c061aSmrg
704444c061aSmrg    if (widget_class == NULL) {
705a3bd7f05Smrg        XtAppErrorMsg(XtDisplayToApplicationContext(display),
706a3bd7f05Smrg                      "invalidClass", "xtAppCreateShell", XtCXtToolkitError,
707a3bd7f05Smrg                      "XtAppCreateShell requires non-NULL widget class",
708a3bd7f05Smrg                      NULL, NULL);
709444c061aSmrg    }
710444c061aSmrg    if (name == NULL)
711a3bd7f05Smrg        name = XrmNameToString(_XtGetPerDisplay(display)->name);
712a3bd7f05Smrg    shell = xtCreate(name, class, widget_class, (Widget) NULL,
713a3bd7f05Smrg                     (Screen *) DefaultScreenOfDisplay(display),
714a3bd7f05Smrg                     args, num_args, typed_args, num_typed_args,
715a3bd7f05Smrg                     (ConstraintWidgetClass) NULL, _XtAddShellToHookObj);
716444c061aSmrg
717444c061aSmrg#ifndef X_NO_RESOURCE_CONFIGURATION_MANAGEMENT
718a3bd7f05Smrg    XtAddEventHandler(shell, (EventMask) PropertyChangeMask, FALSE,
71935525df4Smrg                      _XtResourceConfigurationEH, NULL);
720444c061aSmrg#endif
721444c061aSmrg
722444c061aSmrg    return shell;
723444c061aSmrg}
724444c061aSmrg
725444c061aSmrgWidget
726a3bd7f05SmrgXtAppCreateShell(_Xconst char *name,
727a3bd7f05Smrg                 _Xconst char *class,
728a3bd7f05Smrg                 WidgetClass widget_class,
729a3bd7f05Smrg                 Display *display, ArgList args, Cardinal num_args)
730444c061aSmrg{
731444c061aSmrg    Widget retval;
732444c061aSmrg    DPY_TO_APPCON(display);
733444c061aSmrg
734444c061aSmrg    LOCK_APP(app);
735a3bd7f05Smrg    retval = _XtAppCreateShell((String) name, (String) class, widget_class,
736a3bd7f05Smrg                               display, args, num_args, (XtTypedArgList) NULL,
737a3bd7f05Smrg                               (Cardinal) 0);
738444c061aSmrg    UNLOCK_APP(app);
739444c061aSmrg    return retval;
740444c061aSmrg}
741444c061aSmrg
742444c061aSmrgWidget
743a3bd7f05SmrgXtCreateApplicationShell(_Xconst char *name _X_UNUSED,
744a3bd7f05Smrg                         WidgetClass widget_class,
745a3bd7f05Smrg                         ArgList args,
746a3bd7f05Smrg                         Cardinal num_args)
747444c061aSmrg{
748444c061aSmrg    Widget retval;
749a3bd7f05Smrg    Display *dpy;
750444c061aSmrg    XrmClass class;
751444c061aSmrg    XtAppContext app = _XtDefaultAppContext();
752444c061aSmrg
753444c061aSmrg    LOCK_APP(app);
754444c061aSmrg    dpy = app->list[0];
755444c061aSmrg    class = _XtGetPerDisplay(dpy)->class;
756444c061aSmrg
757a3bd7f05Smrg    retval =
758a3bd7f05Smrg        _XtAppCreateShell((String) NULL, XrmQuarkToString((XrmQuark) class),
759a3bd7f05Smrg                          widget_class, dpy, args, num_args,
760a3bd7f05Smrg                          (XtTypedArgList) NULL, (Cardinal) 0);
761444c061aSmrg    UNLOCK_APP(app);
762444c061aSmrg    return retval;
763444c061aSmrg}
764444c061aSmrg
765444c061aSmrgWidget
766a3bd7f05Smrg_XtCreateHookObj(Screen *screen)
767444c061aSmrg{
768444c061aSmrg    Widget req_widget;
769444c061aSmrg    double widget_cache[100];
770444c061aSmrg    Cardinal wsize = 0;
771444c061aSmrg    Widget hookobj = xtWidgetAlloc(hookObjectClass,
772a3bd7f05Smrg                                   (ConstraintWidgetClass) NULL,
773a3bd7f05Smrg                                   (Widget) NULL, "hooks",
774a3bd7f05Smrg                                   (ArgList) NULL, (Cardinal) 0,
775a3bd7f05Smrg                                   (XtTypedArgList) NULL, (Cardinal) 0);
776a3bd7f05Smrg
777a3bd7f05Smrg    ((HookObject) hookobj)->hooks.screen = screen;
778a3bd7f05Smrg    (void) _XtGetResources(hookobj, (ArgList) NULL, 0,
779a3bd7f05Smrg                           (XtTypedArgList) NULL, &wsize);
780444c061aSmrg    CompileCallbacks(hookobj);
781444c061aSmrg    wsize = hookObjectClass->core_class.widget_size;
782444c061aSmrg    req_widget = (Widget) XtStackAlloc(wsize, widget_cache);
783fdf6a26fSmrg    (void) memcpy(req_widget, (char *) hookobj, (size_t) wsize);
784a3bd7f05Smrg    CallInitialize(hookObjectClass, req_widget, hookobj,
785a3bd7f05Smrg                   (ArgList) NULL, (Cardinal) 0);
786a3bd7f05Smrg    XtStackFree((XtPointer) req_widget, widget_cache);
787444c061aSmrg    return hookobj;
788444c061aSmrg}
789