1 /***********************************************************
2 Copyright (c) 1993, Oracle and/or its affiliates. All rights reserved.
3 
4 Permission is hereby granted, free of charge, to any person obtaining a
5 copy of this software and associated documentation files (the "Software"),
6 to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and/or sell copies of the Software, and to permit persons to whom the
9 Software is furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice (including the next
12 paragraph) shall be included in all copies or substantial portions of the
13 Software.
14 
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 DEALINGS IN THE SOFTWARE.
22 
23 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
24 
25                         All Rights Reserved
26 
27 Permission to use, copy, modify, and distribute this software and its
28 documentation for any purpose and without fee is hereby granted,
29 provided that the above copyright notice appear in all copies and that
30 both that copyright notice and this permission notice appear in
31 supporting documentation, and that the name of Digital not be
32 used in advertising or publicity pertaining to distribution of the
33 software without specific, written prior permission.
34 
35 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
36 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
37 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
38 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
39 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
40 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
41 SOFTWARE.
42 
43 ******************************************************************/
44 
45 /*
46 
47 Copyright 1987, 1988, 1994, 1998  The Open Group
48 
49 Permission to use, copy, modify, distribute, and sell this software and its
50 documentation for any purpose is hereby granted without fee, provided that
51 the above copyright notice appear in all copies and that both that
52 copyright notice and this permission notice appear in supporting
53 documentation.
54 
55 The above copyright notice and this permission notice shall be included in
56 all copies or substantial portions of the Software.
57 
58 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
61 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
62 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
63 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
64 
65 Except as contained in this notice, the name of The Open Group shall not be
66 used in advertising or otherwise to promote the sale, use or other dealings
67 in this Software without prior written authorization from The Open Group.
68 
69 */
70 
71 #ifdef HAVE_CONFIG_H
72 #include <config.h>
73 #endif
74 #include "IntrinsicI.h"
75 #include "VarargsI.h"
76 #include "ShellP.h"
77 #include "CreateI.h"
78 #ifndef X_NO_RESOURCE_CONFIGURATION_MANAGEMENT
79 #include "ResConfigP.h"
80 #endif
81 #include <stdio.h>
82 
83 static _Xconst _XtString XtNxtCreateWidget = "xtCreateWidget";
84 static _Xconst _XtString XtNxtCreatePopupShell = "xtCreatePopupShell";
85 
86 static void
CallClassPartInit(WidgetClass ancestor,WidgetClass wc)87 CallClassPartInit(WidgetClass ancestor, WidgetClass wc)
88 {
89     if (ancestor->core_class.superclass != NULL) {
90         CallClassPartInit(ancestor->core_class.superclass, wc);
91     }
92     if (ancestor->core_class.class_part_initialize != NULL) {
93         (*(ancestor->core_class.class_part_initialize)) (wc);
94     }
95 }
96 
97 void
XtInitializeWidgetClass(WidgetClass wc)98 XtInitializeWidgetClass(WidgetClass wc)
99 {
100     XtEnum inited;
101 
102     LOCK_PROCESS;
103     if (wc->core_class.class_inited) {
104         UNLOCK_PROCESS;
105         return;
106     }
107     inited = 0x01;
108     {
109         WidgetClass pc;
110 
111 #define LeaveIfClass(c, d) if (pc == c) { inited = d; break; }
112         for (pc = wc; pc; pc = pc->core_class.superclass) {
113             LeaveIfClass(rectObjClass, 0x01 | RectObjClassFlag);
114             LeaveIfClass(coreWidgetClass, 0x01 |
115                          RectObjClassFlag | WidgetClassFlag);
116             LeaveIfClass(compositeWidgetClass, 0x01 |
117                          RectObjClassFlag |
118                          WidgetClassFlag | CompositeClassFlag);
119             LeaveIfClass(constraintWidgetClass, 0x01 |
120                          RectObjClassFlag |
121                          WidgetClassFlag |
122                          CompositeClassFlag | ConstraintClassFlag);
123             LeaveIfClass(shellWidgetClass, 0x01 |
124                          RectObjClassFlag |
125                          WidgetClassFlag | CompositeClassFlag | ShellClassFlag);
126             LeaveIfClass(wmShellWidgetClass, 0x01 |
127                          RectObjClassFlag |
128                          WidgetClassFlag |
129                          CompositeClassFlag |
130                          ShellClassFlag | WMShellClassFlag);
131             LeaveIfClass(topLevelShellWidgetClass, 0x01 |
132                          RectObjClassFlag |
133                          WidgetClassFlag |
134                          CompositeClassFlag |
135                          ShellClassFlag | WMShellClassFlag | TopLevelClassFlag);
136         }
137 #undef LeaveIfClass
138     }
139     if (wc->core_class.version != XtVersion &&
140         wc->core_class.version != XtVersionDontCheck) {
141         String param[3];
142         _Xconst _XtString mismatch =
143             "Widget class %s version mismatch (recompilation needed):\n  widget %d vs. intrinsics %d.";
144         _Xconst _XtString recompile = "Widget class %s must be re-compiled.";
145         Cardinal num_params;
146 
147         param[0] = wc->core_class.class_name;
148         param[1] = (String) wc->core_class.version;
149         param[2] = (String) XtVersion;
150 
151         if (wc->core_class.version == (11 * 1000 + 5) ||        /* MIT X11R5 */
152             wc->core_class.version == (11 * 1000 + 4)) {        /* MIT X11R4 */
153             if ((inited & WMShellClassFlag) &&
154                 (sizeof(Boolean) != sizeof(char) ||
155                  sizeof(Atom) != sizeof(Widget) ||
156                  sizeof(Atom) != sizeof(String))) {
157                 num_params = 3;
158                 XtWarningMsg("versionMismatch", "widget", XtCXtToolkitError,
159                              mismatch, param, &num_params);
160                 num_params = 1;
161                 XtErrorMsg("R4orR5versionMismatch", "widget", XtCXtToolkitError,
162                            recompile, param, &num_params);
163 
164             }
165         }
166         else if (wc->core_class.version == (11 * 1000 + 3)) {   /* MIT X11R3 */
167             if (inited & ShellClassFlag) {
168                 num_params = 1;
169                 XtWarningMsg("r3versionMismatch", "widget", XtCXtToolkitError,
170                              "Shell Widget class %s binary compiled for R3",
171                              param, &num_params);
172                 XtErrorMsg("R3versionMismatch", "widget", XtCXtToolkitError,
173                            recompile, param, &num_params);
174             }
175         }
176         else {
177             num_params = 3;
178             XtWarningMsg("versionMismatch", "widget", XtCXtToolkitError,
179                          mismatch, param, &num_params);
180             if (wc->core_class.version == (2 * 1000 + 2)) {     /* MIT X11R2 */
181                 num_params = 1;
182                 XtErrorMsg("r2versionMismatch", "widget", XtCXtToolkitError,
183                            recompile, param, &num_params);
184             }
185         }
186     }
187 
188     if ((wc->core_class.superclass != NULL)
189         && (!(wc->core_class.superclass->core_class.class_inited)))
190         XtInitializeWidgetClass(wc->core_class.superclass);
191 
192     if (wc->core_class.class_initialize != NULL)
193         (*(wc->core_class.class_initialize)) ();
194     CallClassPartInit(wc, wc);
195     wc->core_class.class_inited = inited;
196     UNLOCK_PROCESS;
197 }
198 
199 static void
CallInitialize(WidgetClass class,Widget req_widget,Widget new_widget,ArgList args,Cardinal num_args)200 CallInitialize(WidgetClass class,
201                Widget req_widget,
202                Widget new_widget,
203                ArgList args,
204                Cardinal num_args)
205 {
206     WidgetClass superclass;
207     XtInitProc initialize;
208     XtArgsProc initialize_hook;
209 
210     LOCK_PROCESS;
211     superclass = class->core_class.superclass;
212     UNLOCK_PROCESS;
213     if (superclass)
214         CallInitialize(superclass, req_widget, new_widget, args, num_args);
215     LOCK_PROCESS;
216     initialize = class->core_class.initialize;
217     UNLOCK_PROCESS;
218     if (initialize)
219         (*initialize) (req_widget, new_widget, args, &num_args);
220     LOCK_PROCESS;
221     initialize_hook = class->core_class.initialize_hook;
222     UNLOCK_PROCESS;
223     if (initialize_hook)
224         (*initialize_hook) (new_widget, args, &num_args);
225 }
226 
227 static void
CallConstraintInitialize(ConstraintWidgetClass class,Widget req_widget,Widget new_widget,ArgList args,Cardinal num_args)228 CallConstraintInitialize(ConstraintWidgetClass class,
229                          Widget req_widget,
230                          Widget new_widget,
231                          ArgList args,
232                          Cardinal num_args)
233 {
234     WidgetClass superclass;
235     XtInitProc initialize;
236 
237     LOCK_PROCESS;
238     superclass = class->core_class.superclass;
239     UNLOCK_PROCESS;
240     if (superclass != constraintWidgetClass)
241         CallConstraintInitialize((ConstraintWidgetClass) superclass,
242                                  req_widget, new_widget, args, num_args);
243     LOCK_PROCESS;
244     initialize = class->constraint_class.initialize;
245     UNLOCK_PROCESS;
246     if (initialize)
247         (*initialize) (req_widget, new_widget, args, &num_args);
248 }
249 
250 static Widget
xtWidgetAlloc(WidgetClass widget_class,ConstraintWidgetClass parent_constraint_class,Widget parent,_Xconst _XtString name,ArgList args,Cardinal num_args,XtTypedArgList typed_args,Cardinal num_typed_args)251 xtWidgetAlloc(WidgetClass widget_class,
252               ConstraintWidgetClass parent_constraint_class,
253               Widget parent,
254               _Xconst _XtString name,
255               ArgList args,     /* must be NULL if typed_args is non-NULL */
256               Cardinal num_args,
257               XtTypedArgList typed_args,     /* must be NULL if args is non-NULL */
258               Cardinal num_typed_args)
259 {
260     Widget widget;
261     Cardinal csize = 0;
262     ObjectClassExtension ext;
263 
264     if (widget_class == NULL)
265         return 0;
266 
267     LOCK_PROCESS;
268     if (!(widget_class->core_class.class_inited))
269         XtInitializeWidgetClass(widget_class);
270     ext = (ObjectClassExtension)
271         XtGetClassExtension(widget_class,
272                             XtOffsetOf(ObjectClassRec, object_class.extension),
273                             NULLQUARK, XtObjectExtensionVersion,
274                             sizeof(ObjectClassExtensionRec));
275     if (parent_constraint_class)
276         csize = parent_constraint_class->constraint_class.constraint_size;
277     if (ext && ext->allocate) {
278         XtAllocateProc allocate;
279         Cardinal extra = 0;
280         Cardinal nargs = num_args;
281         Cardinal ntyped = num_typed_args;
282 
283         allocate = ext->allocate;
284         UNLOCK_PROCESS;
285         (*allocate) (widget_class, &csize, &extra, args, &nargs,
286                      typed_args, &ntyped, &widget, NULL);
287     }
288     else {
289         Cardinal wsize = widget_class->core_class.widget_size;
290 
291         UNLOCK_PROCESS;
292         if (csize) {
293             if (sizeof(struct {
294                        char a; double b;}) != (sizeof(struct {
295                                                       char a;
296                                                       unsigned long b;}) -
297                                                sizeof(unsigned long) +
298                                                sizeof(double))) {
299                 if (csize && !(csize & (sizeof(double) - 1)))
300                     wsize = (Cardinal) ((wsize + sizeof(double) - 1)
301                                         & ~(sizeof(double) - 1));
302             }
303         }
304         widget = (Widget) __XtCalloc(1, (unsigned) (wsize + csize));
305         widget->core.constraints =
306             (csize ? (XtPointer) ((char *) widget + wsize) : NULL);
307     }
308     widget->core.self = widget;
309     widget->core.parent = parent;
310     widget->core.widget_class = widget_class;
311     widget->core.xrm_name = StringToName((name != NULL) ? name : "");
312     widget->core.being_destroyed =
313         (parent != NULL ? parent->core.being_destroyed : FALSE);
314     return widget;
315 }
316 
317 static void
CompileCallbacks(Widget widget)318 CompileCallbacks(Widget widget)
319 {
320     CallbackTable offsets;
321     int i;
322 
323     LOCK_PROCESS;
324     offsets = (CallbackTable)
325         widget->core.widget_class->core_class.callback_private;
326 
327     for (i = (int) (long) *(offsets++); --i >= 0; offsets++) {
328         InternalCallbackList *cl = (InternalCallbackList *)
329             ((char *) widget - (*offsets)->xrm_offset - 1);
330 
331         if (*cl)
332             *cl = _XtCompileCallbackList((XtCallbackList) *cl);
333     }
334     UNLOCK_PROCESS;
335 }
336 
337 static Widget
xtCreate(String name,String class,WidgetClass widget_class,Widget parent,Screen * default_screen,ArgList args,Cardinal num_args,XtTypedArgList typed_args,Cardinal num_typed_args,ConstraintWidgetClass parent_constraint_class,XtWidgetProc post_proc)338 xtCreate(String name,
339          String class,
340          WidgetClass widget_class,
341          Widget parent,
342          Screen *default_screen,    /* undefined when creating a nonwidget */
343          ArgList args,          /* must be NULL if typed_args is non-NULL */
344          Cardinal num_args,
345          XtTypedArgList typed_args,  /* must be NULL if args is non-NULL */
346          Cardinal num_typed_args,
347          ConstraintWidgetClass parent_constraint_class,
348          /* NULL if not a subclass of Constraint or if child is popup shell */
349          XtWidgetProc post_proc)
350 {
351     /* need to use strictest alignment rules possible in next two decls. */
352     double widget_cache[100];
353     Widget req_widget;
354     XtPointer req_constraints = NULL;
355     Cardinal wsize, csize;
356     Widget widget;
357     XtCacheRef *cache_refs;
358     XtCreateHookDataRec call_data;
359 
360     widget = xtWidgetAlloc(widget_class, parent_constraint_class, parent,
361                            name, args, num_args, typed_args, num_typed_args);
362 
363     if (XtIsRectObj(widget)) {
364         widget->core.managed = FALSE;
365     }
366     if (XtIsWidget(widget)) {
367         widget->core.name = XrmNameToString(widget->core.xrm_name);
368         widget->core.screen = default_screen;
369         widget->core.tm.translations = NULL;
370         widget->core.window = (Window) 0;
371         widget->core.visible = TRUE;
372         widget->core.popup_list = NULL;
373         widget->core.num_popups = 0;
374     };
375     LOCK_PROCESS;
376     if (XtIsApplicationShell(widget)) {
377         ApplicationShellWidget a = (ApplicationShellWidget) widget;
378 
379         if (class != NULL)
380             a->application.xrm_class = StringToClass(class);
381         else
382             a->application.xrm_class = widget_class->core_class.xrm_class;
383         a->application.class = XrmQuarkToString(a->application.xrm_class);
384     }
385     UNLOCK_PROCESS;
386 
387     /* fetch resources */
388     cache_refs = _XtGetResources(widget, args, num_args,
389                                  typed_args, &num_typed_args);
390 
391     /* Convert typed arg list to arg list */
392     if (typed_args != NULL && num_typed_args > 0) {
393         Cardinal i;
394 
395         args = (ArgList) ALLOCATE_LOCAL(sizeof(Arg) * num_typed_args);
396         if (args == NULL)
397             _XtAllocError(NULL);
398         for (i = 0; i < num_typed_args; i++) {
399             args[i].name = typed_args[i].name;
400             args[i].value = typed_args[i].value;
401         }
402         num_args = num_typed_args;
403     }
404 
405     CompileCallbacks(widget);
406 
407     if (cache_refs != NULL) {
408         XtAddCallback(widget, XtNdestroyCallback,
409                       XtCallbackReleaseCacheRefList, (XtPointer) cache_refs);
410     }
411 
412     wsize = widget_class->core_class.widget_size;
413     req_widget = (Widget) XtStackAlloc(wsize, widget_cache);
414     (void) memmove((char *) req_widget, (char *) widget, (size_t) wsize);
415     CallInitialize(XtClass(widget), req_widget, widget, args, num_args);
416     if (parent_constraint_class != NULL) {
417         double constraint_cache[20];
418 
419         csize = parent_constraint_class->constraint_class.constraint_size;
420         if (csize) {
421             req_constraints = XtStackAlloc(csize, constraint_cache);
422             (void) memmove((char *) req_constraints, widget->core.constraints,
423                            (size_t) csize);
424             req_widget->core.constraints = req_constraints;
425         }
426         else
427             req_widget->core.constraints = NULL;
428         CallConstraintInitialize(parent_constraint_class, req_widget, widget,
429                                  args, num_args);
430         if (csize) {
431             XtStackFree(req_constraints, constraint_cache);
432         }
433     }
434     XtStackFree((XtPointer) req_widget, widget_cache);
435     if (post_proc != (XtWidgetProc) NULL) {
436         Widget hookobj;
437 
438         (*post_proc) (widget);
439         hookobj = XtHooksOfDisplay((default_screen != (Screen *) NULL) ?
440                                    default_screen->display :
441                                    XtDisplayOfObject(parent));
442         if (XtHasCallbacks(hookobj, XtNcreateHook) == XtCallbackHasSome) {
443 
444             call_data.type = XtHcreate;
445             call_data.widget = widget;
446             call_data.args = args;
447             call_data.num_args = num_args;
448             XtCallCallbackList(hookobj,
449                                ((HookObject) hookobj)->hooks.
450                                createhook_callbacks, (XtPointer) &call_data);
451         }
452     }
453     if (typed_args != NULL) {
454         while (num_typed_args-- > 0) {
455 
456             /* In GetResources we may have dynamically alloc'd store to hold */
457             /* a copy of a resource which was larger then sizeof(XtArgVal). */
458             /* We must free this store now in order to prevent a memory leak */
459             /* A typed arg that has a converted value in dynamic store has a */
460             /* negated size field. */
461 
462             if (typed_args->type != NULL && typed_args->size < 0) {
463                 XtFree((char *) typed_args->value);
464                 typed_args->size = -(typed_args->size);
465             }
466             typed_args++;
467         }
468         DEALLOCATE_LOCAL((char *) args);
469     }
470     return (widget);
471 }
472 
473 static void
widgetPostProc(Widget w)474 widgetPostProc(Widget w)
475 {
476     XtWidgetProc insert_child;
477     Widget parent = XtParent(w);
478     String param = XtName(w);
479     Cardinal num_params = 1;
480 
481     if (XtIsComposite(parent)) {
482         LOCK_PROCESS;
483         insert_child =
484             ((CompositeWidgetClass) parent->core.widget_class)->composite_class.
485             insert_child;
486         UNLOCK_PROCESS;
487     }
488     else {
489         return;
490     }
491     if (insert_child == NULL) {
492         XtAppErrorMsg(XtWidgetToApplicationContext(parent),
493                       "nullProc", "insertChild", XtCXtToolkitError,
494                       "\"%s\" parent has NULL insert_child method",
495                       &param, &num_params);
496     }
497     else {
498         (*insert_child) (w);
499     }
500 }
501 
502 Widget
_XtCreateWidget(String name,WidgetClass widget_class,Widget parent,ArgList args,Cardinal num_args,XtTypedArgList typed_args,Cardinal num_typed_args)503 _XtCreateWidget(String name,
504                 WidgetClass widget_class,
505                 Widget parent,
506                 ArgList args,
507                 Cardinal num_args,
508                 XtTypedArgList typed_args,
509                 Cardinal num_typed_args)
510 {
511     register Widget widget;
512     ConstraintWidgetClass cwc;
513     Screen *default_screen;
514     XtEnum class_inited;
515     String params[3];
516     Cardinal num_params;
517 
518     params[0] = name;
519     num_params = 1;
520 
521     if (parent == NULL) {
522         XtErrorMsg("invalidParent", XtNxtCreateWidget, XtCXtToolkitError,
523                    "XtCreateWidget \"%s\" requires non-NULL parent",
524                    params, &num_params);
525     }
526     else if (widget_class == NULL) {
527         XtAppErrorMsg(XtWidgetToApplicationContext(parent),
528                       "invalidClass", XtNxtCreateWidget, XtCXtToolkitError,
529                       "XtCreateWidget \"%s\" requires non-NULL widget class",
530                       params, &num_params);
531     }
532     LOCK_PROCESS;
533     if (!widget_class->core_class.class_inited)
534         XtInitializeWidgetClass(widget_class);
535     class_inited = widget_class->core_class.class_inited;
536     UNLOCK_PROCESS;
537     if ((class_inited & WidgetClassFlag) == 0) {
538         /* not a widget */
539         default_screen = NULL;
540         if (XtIsComposite(parent)) {
541             CompositeClassExtension ext;
542 
543             ext = (CompositeClassExtension)
544                 XtGetClassExtension(XtClass(parent),
545                                     XtOffsetOf(CompositeClassRec,
546                                                composite_class.extension),
547                                     NULLQUARK, 1L, (Cardinal) 0);
548             LOCK_PROCESS;
549             if (ext &&
550                 (ext->version > XtCompositeExtensionVersion ||
551                  ext->record_size > sizeof(CompositeClassExtensionRec))) {
552                 params[1] = XtClass(parent)->core_class.class_name;
553                 num_params = 2;
554                 XtAppWarningMsg(XtWidgetToApplicationContext(parent),
555                                 "invalidExtension", XtNxtCreateWidget,
556                                 XtCXtToolkitError,
557                                 "widget \"%s\" class %s has invalid CompositeClassExtension record",
558                                 params, &num_params);
559             }
560             if (!ext || !ext->accepts_objects) {
561                 params[1] = XtName(parent);
562                 num_params = 2;
563                 XtAppErrorMsg(XtWidgetToApplicationContext(parent),
564                               "nonWidget", XtNxtCreateWidget, XtCXtToolkitError,
565                               "attempt to add non-widget child \"%s\" to parent \"%s\" which supports only widgets",
566                               params, &num_params);
567             }
568             UNLOCK_PROCESS;
569         }
570     }
571     else {
572         default_screen = parent->core.screen;
573     }
574 
575     if (XtIsConstraint(parent)) {
576         cwc = (ConstraintWidgetClass) parent->core.widget_class;
577     }
578     else {
579         cwc = NULL;
580     }
581     widget = xtCreate(name, (char *) NULL, widget_class, parent,
582                       default_screen, args, num_args,
583                       typed_args, num_typed_args, cwc, widgetPostProc);
584     return (widget);
585 }
586 
587 Widget
XtCreateWidget(_Xconst char * name,WidgetClass widget_class,Widget parent,ArgList args,Cardinal num_args)588 XtCreateWidget(_Xconst char *name,
589                WidgetClass widget_class,
590                Widget parent,
591                ArgList args,
592                Cardinal num_args)
593 {
594     Widget retval;
595 
596     WIDGET_TO_APPCON(parent);
597 
598     LOCK_APP(app);
599     retval =
600         _XtCreateWidget((String) name, widget_class, parent, args, num_args,
601                         (XtTypedArgList) NULL, (Cardinal) 0);
602     UNLOCK_APP(app);
603     return retval;
604 }
605 
606 Widget
XtCreateManagedWidget(_Xconst char * name,WidgetClass widget_class,Widget parent,ArgList args,Cardinal num_args)607 XtCreateManagedWidget(_Xconst char *name,
608                       WidgetClass widget_class,
609                       Widget parent,
610                       ArgList args,
611                       Cardinal num_args)
612 {
613     register Widget widget;
614 
615     WIDGET_TO_APPCON(parent);
616 
617     LOCK_APP(app);
618     XtCheckSubclass(parent, compositeWidgetClass, "in XtCreateManagedWidget");
619     widget = _XtCreateWidget((String) name, widget_class, parent, args,
620                              num_args, (XtTypedArgList) NULL, (Cardinal) 0);
621     XtManageChild(widget);
622     UNLOCK_APP(app);
623     return widget;
624 }
625 
626 static void
popupPostProc(Widget w)627 popupPostProc(Widget w)
628 {
629     Widget parent = XtParent(w);
630 
631     parent->core.popup_list =
632         (WidgetList) XtRealloc((char *) parent->core.popup_list,
633                                (Cardinal) ((unsigned)
634                                            (parent->core.num_popups +
635                                             1) * sizeof(Widget)));
636     parent->core.popup_list[parent->core.num_popups++] = w;
637 }
638 
639 Widget
_XtCreatePopupShell(String name,WidgetClass widget_class,Widget parent,ArgList args,Cardinal num_args,XtTypedArgList typed_args,Cardinal num_typed_args)640 _XtCreatePopupShell(String name,
641                     WidgetClass widget_class,
642                     Widget parent,
643                     ArgList args,
644                     Cardinal num_args,
645                     XtTypedArgList typed_args,
646                     Cardinal num_typed_args)
647 {
648     register Widget widget;
649     Screen *default_screen;
650 
651     if (parent == NULL) {
652         XtErrorMsg("invalidParent", XtNxtCreatePopupShell, XtCXtToolkitError,
653                    "XtCreatePopupShell requires non-NULL parent", NULL, NULL);
654     }
655     else if (widget_class == NULL) {
656         XtAppErrorMsg(XtWidgetToApplicationContext(parent),
657                       "invalidClass", XtNxtCreatePopupShell, XtCXtToolkitError,
658                       "XtCreatePopupShell requires non-NULL widget class",
659                       NULL, NULL);
660     }
661     XtCheckSubclass(parent, coreWidgetClass, "in XtCreatePopupShell");
662     default_screen = parent->core.screen;
663     widget = xtCreate(name, (char *) NULL, widget_class, parent,
664                       default_screen, args, num_args, typed_args,
665                       num_typed_args, (ConstraintWidgetClass) NULL,
666                       popupPostProc);
667 
668 #ifndef X_NO_RESOURCE_CONFIGURATION_MANAGEMENT
669     XtAddEventHandler(widget, (EventMask) PropertyChangeMask, FALSE,
670                       (XtEventHandler) _XtResourceConfigurationEH, NULL);
671 #endif
672     return (widget);
673 }
674 
675 Widget
XtCreatePopupShell(_Xconst char * name,WidgetClass widget_class,Widget parent,ArgList args,Cardinal num_args)676 XtCreatePopupShell(_Xconst char *name,
677                    WidgetClass widget_class,
678                    Widget parent,
679                    ArgList args,
680                    Cardinal num_args)
681 {
682     Widget retval;
683 
684     WIDGET_TO_APPCON(parent);
685 
686     LOCK_APP(app);
687     retval = _XtCreatePopupShell((String) name, widget_class, parent, args,
688                                  num_args, (XtTypedArgList) NULL, (Cardinal) 0);
689     UNLOCK_APP(app);
690     return retval;
691 }
692 
693 Widget
_XtAppCreateShell(String name,String class,WidgetClass widget_class,Display * display,ArgList args,Cardinal num_args,XtTypedArgList typed_args,Cardinal num_typed_args)694 _XtAppCreateShell(String name,
695                   String class,
696                   WidgetClass widget_class,
697                   Display *display,
698                   ArgList args,
699                   Cardinal num_args,
700                   XtTypedArgList typed_args,
701                   Cardinal num_typed_args)
702 {
703     Widget shell;
704 
705     if (widget_class == NULL) {
706         XtAppErrorMsg(XtDisplayToApplicationContext(display),
707                       "invalidClass", "xtAppCreateShell", XtCXtToolkitError,
708                       "XtAppCreateShell requires non-NULL widget class",
709                       NULL, NULL);
710     }
711     if (name == NULL)
712         name = XrmNameToString(_XtGetPerDisplay(display)->name);
713     shell = xtCreate(name, class, widget_class, (Widget) NULL,
714                      (Screen *) DefaultScreenOfDisplay(display),
715                      args, num_args, typed_args, num_typed_args,
716                      (ConstraintWidgetClass) NULL, _XtAddShellToHookObj);
717 
718 #ifndef X_NO_RESOURCE_CONFIGURATION_MANAGEMENT
719     XtAddEventHandler(shell, (EventMask) PropertyChangeMask, FALSE,
720                       (XtEventHandler) _XtResourceConfigurationEH, NULL);
721 #endif
722 
723     return shell;
724 }
725 
726 Widget
XtAppCreateShell(_Xconst char * name,_Xconst char * class,WidgetClass widget_class,Display * display,ArgList args,Cardinal num_args)727 XtAppCreateShell(_Xconst char *name,
728                  _Xconst char *class,
729                  WidgetClass widget_class,
730                  Display *display, ArgList args, Cardinal num_args)
731 {
732     Widget retval;
733     DPY_TO_APPCON(display);
734 
735     LOCK_APP(app);
736     retval = _XtAppCreateShell((String) name, (String) class, widget_class,
737                                display, args, num_args, (XtTypedArgList) NULL,
738                                (Cardinal) 0);
739     UNLOCK_APP(app);
740     return retval;
741 }
742 
743 Widget
XtCreateApplicationShell(_Xconst char * name _X_UNUSED,WidgetClass widget_class,ArgList args,Cardinal num_args)744 XtCreateApplicationShell(_Xconst char *name _X_UNUSED,
745                          WidgetClass widget_class,
746                          ArgList args,
747                          Cardinal num_args)
748 {
749     Widget retval;
750     Display *dpy;
751     XrmClass class;
752     XtAppContext app = _XtDefaultAppContext();
753 
754     LOCK_APP(app);
755     dpy = app->list[0];
756     class = _XtGetPerDisplay(dpy)->class;
757 
758     retval =
759         _XtAppCreateShell((String) NULL, XrmQuarkToString((XrmQuark) class),
760                           widget_class, dpy, args, num_args,
761                           (XtTypedArgList) NULL, (Cardinal) 0);
762     UNLOCK_APP(app);
763     return retval;
764 }
765 
766 Widget
_XtCreateHookObj(Screen * screen)767 _XtCreateHookObj(Screen *screen)
768 {
769     Widget req_widget;
770     double widget_cache[100];
771     Cardinal wsize = 0;
772     Widget hookobj = xtWidgetAlloc(hookObjectClass,
773                                    (ConstraintWidgetClass) NULL,
774                                    (Widget) NULL, "hooks",
775                                    (ArgList) NULL, (Cardinal) 0,
776                                    (XtTypedArgList) NULL, (Cardinal) 0);
777 
778     ((HookObject) hookobj)->hooks.screen = screen;
779     (void) _XtGetResources(hookobj, (ArgList) NULL, 0,
780                            (XtTypedArgList) NULL, &wsize);
781     CompileCallbacks(hookobj);
782     wsize = hookObjectClass->core_class.widget_size;
783     req_widget = (Widget) XtStackAlloc(wsize, widget_cache);
784     (void) memmove((char *) req_widget, (char *) hookobj, (size_t) wsize);
785     CallInitialize(hookObjectClass, req_widget, hookobj,
786                    (ArgList) NULL, (Cardinal) 0);
787     XtStackFree((XtPointer) req_widget, widget_cache);
788     return hookobj;
789 }
790