Create.c revision a3bd7f05
1444c061aSmrg/*********************************************************** 2249c3046SmrgCopyright (c) 1993, Oracle and/or its affiliates. All rights reserved. 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; 148a3bd7f05Smrg param[1] = (String) wc->core_class.version; 149a3bd7f05Smrg param[2] = (String) 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; 355a3bd7f05Smrg Cardinal wsize, csize; 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); 414a3bd7f05Smrg (void) memmove((char *) 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]; 418a3bd7f05Smrg 419444c061aSmrg csize = parent_constraint_class->constraint_class.constraint_size; 420a3bd7f05Smrg if (csize) { 421a3bd7f05Smrg req_constraints = XtStackAlloc(csize, constraint_cache); 422a3bd7f05Smrg (void) memmove((char *) req_constraints, widget->core.constraints, 423a3bd7f05Smrg (size_t) csize); 424a3bd7f05Smrg req_widget->core.constraints = req_constraints; 425a3bd7f05Smrg } 426a3bd7f05Smrg else 427a3bd7f05Smrg req_widget->core.constraints = NULL; 428a3bd7f05Smrg CallConstraintInitialize(parent_constraint_class, req_widget, widget, 429a3bd7f05Smrg args, num_args); 430a3bd7f05Smrg if (csize) { 431a3bd7f05Smrg XtStackFree(req_constraints, constraint_cache); 432a3bd7f05Smrg } 433444c061aSmrg } 434a3bd7f05Smrg XtStackFree((XtPointer) req_widget, widget_cache); 435444c061aSmrg if (post_proc != (XtWidgetProc) NULL) { 436a3bd7f05Smrg Widget hookobj; 437a3bd7f05Smrg 438a3bd7f05Smrg (*post_proc) (widget); 439a3bd7f05Smrg hookobj = XtHooksOfDisplay((default_screen != (Screen *) NULL) ? 440a3bd7f05Smrg default_screen->display : 441a3bd7f05Smrg XtDisplayOfObject(parent)); 442a3bd7f05Smrg if (XtHasCallbacks(hookobj, XtNcreateHook) == XtCallbackHasSome) { 443a3bd7f05Smrg 444a3bd7f05Smrg call_data.type = XtHcreate; 445a3bd7f05Smrg call_data.widget = widget; 446a3bd7f05Smrg call_data.args = args; 447a3bd7f05Smrg call_data.num_args = num_args; 448a3bd7f05Smrg XtCallCallbackList(hookobj, 449a3bd7f05Smrg ((HookObject) hookobj)->hooks. 450a3bd7f05Smrg createhook_callbacks, (XtPointer) &call_data); 451a3bd7f05Smrg } 452444c061aSmrg } 453444c061aSmrg if (typed_args != NULL) { 454a3bd7f05Smrg while (num_typed_args-- > 0) { 455a3bd7f05Smrg 456a3bd7f05Smrg /* In GetResources we may have dynamically alloc'd store to hold */ 457a3bd7f05Smrg /* a copy of a resource which was larger then sizeof(XtArgVal). */ 458a3bd7f05Smrg /* We must free this store now in order to prevent a memory leak */ 459a3bd7f05Smrg /* A typed arg that has a converted value in dynamic store has a */ 460a3bd7f05Smrg /* negated size field. */ 461a3bd7f05Smrg 462a3bd7f05Smrg if (typed_args->type != NULL && typed_args->size < 0) { 463a3bd7f05Smrg XtFree((char *) typed_args->value); 464a3bd7f05Smrg typed_args->size = -(typed_args->size); 465a3bd7f05Smrg } 466a3bd7f05Smrg typed_args++; 467a3bd7f05Smrg } 468a3bd7f05Smrg DEALLOCATE_LOCAL((char *) args); 469444c061aSmrg } 470444c061aSmrg return (widget); 471444c061aSmrg} 472444c061aSmrg 473444c061aSmrgstatic void 474444c061aSmrgwidgetPostProc(Widget w) 475444c061aSmrg{ 476444c061aSmrg XtWidgetProc insert_child; 477444c061aSmrg Widget parent = XtParent(w); 478444c061aSmrg String param = XtName(w); 479444c061aSmrg Cardinal num_params = 1; 480444c061aSmrg 481444c061aSmrg if (XtIsComposite(parent)) { 482a3bd7f05Smrg LOCK_PROCESS; 483a3bd7f05Smrg insert_child = 484a3bd7f05Smrg ((CompositeWidgetClass) parent->core.widget_class)->composite_class. 485a3bd7f05Smrg insert_child; 486a3bd7f05Smrg UNLOCK_PROCESS; 487a3bd7f05Smrg } 488a3bd7f05Smrg else { 489a3bd7f05Smrg return; 490444c061aSmrg } 491444c061aSmrg if (insert_child == NULL) { 492a3bd7f05Smrg XtAppErrorMsg(XtWidgetToApplicationContext(parent), 493a3bd7f05Smrg "nullProc", "insertChild", XtCXtToolkitError, 494a3bd7f05Smrg "\"%s\" parent has NULL insert_child method", 495a3bd7f05Smrg ¶m, &num_params); 496a3bd7f05Smrg } 497a3bd7f05Smrg else { 498a3bd7f05Smrg (*insert_child) (w); 499444c061aSmrg } 500444c061aSmrg} 501444c061aSmrg 502444c061aSmrgWidget 503a3bd7f05Smrg_XtCreateWidget(String name, 504a3bd7f05Smrg WidgetClass widget_class, 505a3bd7f05Smrg Widget parent, 506a3bd7f05Smrg ArgList args, 507a3bd7f05Smrg Cardinal num_args, 508a3bd7f05Smrg XtTypedArgList typed_args, 509a3bd7f05Smrg Cardinal num_typed_args) 510444c061aSmrg{ 511a3bd7f05Smrg register Widget widget; 512a3bd7f05Smrg ConstraintWidgetClass cwc; 513a3bd7f05Smrg Screen *default_screen; 514a3bd7f05Smrg XtEnum class_inited; 515a3bd7f05Smrg String params[3]; 516a3bd7f05Smrg Cardinal num_params; 517444c061aSmrg 518444c061aSmrg params[0] = name; 519444c061aSmrg num_params = 1; 520444c061aSmrg 521444c061aSmrg if (parent == NULL) { 522a3bd7f05Smrg XtErrorMsg("invalidParent", XtNxtCreateWidget, XtCXtToolkitError, 523a3bd7f05Smrg "XtCreateWidget \"%s\" requires non-NULL parent", 524a3bd7f05Smrg params, &num_params); 525a3bd7f05Smrg } 526a3bd7f05Smrg else if (widget_class == NULL) { 527a3bd7f05Smrg XtAppErrorMsg(XtWidgetToApplicationContext(parent), 528a3bd7f05Smrg "invalidClass", XtNxtCreateWidget, XtCXtToolkitError, 529a3bd7f05Smrg "XtCreateWidget \"%s\" requires non-NULL widget class", 530a3bd7f05Smrg params, &num_params); 531444c061aSmrg } 532444c061aSmrg LOCK_PROCESS; 533444c061aSmrg if (!widget_class->core_class.class_inited) 534a3bd7f05Smrg XtInitializeWidgetClass(widget_class); 535444c061aSmrg class_inited = widget_class->core_class.class_inited; 536444c061aSmrg UNLOCK_PROCESS; 537444c061aSmrg if ((class_inited & WidgetClassFlag) == 0) { 538a3bd7f05Smrg /* not a widget */ 539a3bd7f05Smrg default_screen = NULL; 540a3bd7f05Smrg if (XtIsComposite(parent)) { 541a3bd7f05Smrg CompositeClassExtension ext; 542a3bd7f05Smrg 543a3bd7f05Smrg ext = (CompositeClassExtension) 544a3bd7f05Smrg XtGetClassExtension(XtClass(parent), 545a3bd7f05Smrg XtOffsetOf(CompositeClassRec, 546a3bd7f05Smrg composite_class.extension), 547a3bd7f05Smrg NULLQUARK, 1L, (Cardinal) 0); 548a3bd7f05Smrg LOCK_PROCESS; 549a3bd7f05Smrg if (ext && 550a3bd7f05Smrg (ext->version > XtCompositeExtensionVersion || 551a3bd7f05Smrg ext->record_size > sizeof(CompositeClassExtensionRec))) { 552a3bd7f05Smrg params[1] = XtClass(parent)->core_class.class_name; 553a3bd7f05Smrg num_params = 2; 554a3bd7f05Smrg XtAppWarningMsg(XtWidgetToApplicationContext(parent), 555a3bd7f05Smrg "invalidExtension", XtNxtCreateWidget, 556a3bd7f05Smrg XtCXtToolkitError, 557a3bd7f05Smrg "widget \"%s\" class %s has invalid CompositeClassExtension record", 558a3bd7f05Smrg params, &num_params); 559a3bd7f05Smrg } 560a3bd7f05Smrg if (!ext || !ext->accepts_objects) { 561a3bd7f05Smrg params[1] = XtName(parent); 562a3bd7f05Smrg num_params = 2; 563a3bd7f05Smrg XtAppErrorMsg(XtWidgetToApplicationContext(parent), 564a3bd7f05Smrg "nonWidget", XtNxtCreateWidget, XtCXtToolkitError, 565a3bd7f05Smrg "attempt to add non-widget child \"%s\" to parent \"%s\" which supports only widgets", 566a3bd7f05Smrg params, &num_params); 567a3bd7f05Smrg } 568a3bd7f05Smrg UNLOCK_PROCESS; 569a3bd7f05Smrg } 570a3bd7f05Smrg } 571a3bd7f05Smrg else { 572a3bd7f05Smrg default_screen = parent->core.screen; 573444c061aSmrg } 574444c061aSmrg 575444c061aSmrg if (XtIsConstraint(parent)) { 576a3bd7f05Smrg cwc = (ConstraintWidgetClass) parent->core.widget_class; 577a3bd7f05Smrg } 578a3bd7f05Smrg else { 579a3bd7f05Smrg cwc = NULL; 580444c061aSmrg } 581a3bd7f05Smrg widget = xtCreate(name, (char *) NULL, widget_class, parent, 582a3bd7f05Smrg default_screen, args, num_args, 583a3bd7f05Smrg typed_args, num_typed_args, cwc, widgetPostProc); 584444c061aSmrg return (widget); 585444c061aSmrg} 586444c061aSmrg 587444c061aSmrgWidget 588a3bd7f05SmrgXtCreateWidget(_Xconst char *name, 589a3bd7f05Smrg WidgetClass widget_class, 590a3bd7f05Smrg Widget parent, 591a3bd7f05Smrg ArgList args, 592a3bd7f05Smrg Cardinal num_args) 593444c061aSmrg{ 594444c061aSmrg Widget retval; 595a3bd7f05Smrg 596444c061aSmrg WIDGET_TO_APPCON(parent); 597444c061aSmrg 598444c061aSmrg LOCK_APP(app); 599a3bd7f05Smrg retval = 600a3bd7f05Smrg _XtCreateWidget((String) name, widget_class, parent, args, num_args, 601a3bd7f05Smrg (XtTypedArgList) NULL, (Cardinal) 0); 602444c061aSmrg UNLOCK_APP(app); 603444c061aSmrg return retval; 604444c061aSmrg} 605444c061aSmrg 606444c061aSmrgWidget 607a3bd7f05SmrgXtCreateManagedWidget(_Xconst char *name, 608a3bd7f05Smrg WidgetClass widget_class, 609a3bd7f05Smrg Widget parent, 610a3bd7f05Smrg ArgList args, 611a3bd7f05Smrg Cardinal num_args) 612444c061aSmrg{ 613a3bd7f05Smrg register Widget widget; 614a3bd7f05Smrg 615444c061aSmrg WIDGET_TO_APPCON(parent); 616444c061aSmrg 617444c061aSmrg LOCK_APP(app); 618444c061aSmrg XtCheckSubclass(parent, compositeWidgetClass, "in XtCreateManagedWidget"); 619a3bd7f05Smrg widget = _XtCreateWidget((String) name, widget_class, parent, args, 620a3bd7f05Smrg num_args, (XtTypedArgList) NULL, (Cardinal) 0); 621444c061aSmrg XtManageChild(widget); 622444c061aSmrg UNLOCK_APP(app); 623444c061aSmrg return widget; 624444c061aSmrg} 625444c061aSmrg 626444c061aSmrgstatic void 627444c061aSmrgpopupPostProc(Widget w) 628444c061aSmrg{ 629444c061aSmrg Widget parent = XtParent(w); 630444c061aSmrg 631444c061aSmrg parent->core.popup_list = 632a3bd7f05Smrg (WidgetList) XtRealloc((char *) parent->core.popup_list, 633a3bd7f05Smrg (Cardinal) ((unsigned) 634a3bd7f05Smrg (parent->core.num_popups + 635a3bd7f05Smrg 1) * sizeof(Widget))); 636444c061aSmrg parent->core.popup_list[parent->core.num_popups++] = w; 637444c061aSmrg} 638444c061aSmrg 639444c061aSmrgWidget 640a3bd7f05Smrg_XtCreatePopupShell(String name, 641a3bd7f05Smrg WidgetClass widget_class, 642a3bd7f05Smrg Widget parent, 643a3bd7f05Smrg ArgList args, 644a3bd7f05Smrg Cardinal num_args, 645a3bd7f05Smrg XtTypedArgList typed_args, 646a3bd7f05Smrg Cardinal num_typed_args) 647444c061aSmrg{ 648444c061aSmrg register Widget widget; 649a3bd7f05Smrg Screen *default_screen; 650444c061aSmrg 651444c061aSmrg if (parent == NULL) { 652a3bd7f05Smrg XtErrorMsg("invalidParent", XtNxtCreatePopupShell, XtCXtToolkitError, 653a3bd7f05Smrg "XtCreatePopupShell requires non-NULL parent", NULL, NULL); 654a3bd7f05Smrg } 655a3bd7f05Smrg else if (widget_class == NULL) { 656a3bd7f05Smrg XtAppErrorMsg(XtWidgetToApplicationContext(parent), 657a3bd7f05Smrg "invalidClass", XtNxtCreatePopupShell, XtCXtToolkitError, 658a3bd7f05Smrg "XtCreatePopupShell requires non-NULL widget class", 659a3bd7f05Smrg NULL, NULL); 660444c061aSmrg } 661444c061aSmrg XtCheckSubclass(parent, coreWidgetClass, "in XtCreatePopupShell"); 662444c061aSmrg default_screen = parent->core.screen; 663a3bd7f05Smrg widget = xtCreate(name, (char *) NULL, widget_class, parent, 664a3bd7f05Smrg default_screen, args, num_args, typed_args, 665a3bd7f05Smrg num_typed_args, (ConstraintWidgetClass) NULL, 666a3bd7f05Smrg popupPostProc); 667444c061aSmrg 668444c061aSmrg#ifndef X_NO_RESOURCE_CONFIGURATION_MANAGEMENT 669a3bd7f05Smrg XtAddEventHandler(widget, (EventMask) PropertyChangeMask, FALSE, 670a3bd7f05Smrg (XtEventHandler) _XtResourceConfigurationEH, NULL); 671444c061aSmrg#endif 672a3bd7f05Smrg return (widget); 673444c061aSmrg} 674444c061aSmrg 675444c061aSmrgWidget 676a3bd7f05SmrgXtCreatePopupShell(_Xconst char *name, 677a3bd7f05Smrg WidgetClass widget_class, 678a3bd7f05Smrg Widget parent, 679a3bd7f05Smrg ArgList args, 680a3bd7f05Smrg Cardinal num_args) 681444c061aSmrg{ 682444c061aSmrg Widget retval; 683a3bd7f05Smrg 684444c061aSmrg WIDGET_TO_APPCON(parent); 685444c061aSmrg 686444c061aSmrg LOCK_APP(app); 687a3bd7f05Smrg retval = _XtCreatePopupShell((String) name, widget_class, parent, args, 688a3bd7f05Smrg num_args, (XtTypedArgList) NULL, (Cardinal) 0); 689444c061aSmrg UNLOCK_APP(app); 690444c061aSmrg return retval; 691444c061aSmrg} 692444c061aSmrg 693444c061aSmrgWidget 694a3bd7f05Smrg_XtAppCreateShell(String name, 695a3bd7f05Smrg String class, 696a3bd7f05Smrg WidgetClass widget_class, 697a3bd7f05Smrg Display *display, 698a3bd7f05Smrg ArgList args, 699a3bd7f05Smrg Cardinal num_args, 700a3bd7f05Smrg XtTypedArgList typed_args, 701a3bd7f05Smrg Cardinal num_typed_args) 702444c061aSmrg{ 703444c061aSmrg Widget shell; 704444c061aSmrg 705444c061aSmrg if (widget_class == NULL) { 706a3bd7f05Smrg XtAppErrorMsg(XtDisplayToApplicationContext(display), 707a3bd7f05Smrg "invalidClass", "xtAppCreateShell", XtCXtToolkitError, 708a3bd7f05Smrg "XtAppCreateShell requires non-NULL widget class", 709a3bd7f05Smrg NULL, NULL); 710444c061aSmrg } 711444c061aSmrg if (name == NULL) 712a3bd7f05Smrg name = XrmNameToString(_XtGetPerDisplay(display)->name); 713a3bd7f05Smrg shell = xtCreate(name, class, widget_class, (Widget) NULL, 714a3bd7f05Smrg (Screen *) DefaultScreenOfDisplay(display), 715a3bd7f05Smrg args, num_args, typed_args, num_typed_args, 716a3bd7f05Smrg (ConstraintWidgetClass) NULL, _XtAddShellToHookObj); 717444c061aSmrg 718444c061aSmrg#ifndef X_NO_RESOURCE_CONFIGURATION_MANAGEMENT 719a3bd7f05Smrg XtAddEventHandler(shell, (EventMask) PropertyChangeMask, FALSE, 720a3bd7f05Smrg (XtEventHandler) _XtResourceConfigurationEH, NULL); 721444c061aSmrg#endif 722444c061aSmrg 723444c061aSmrg return shell; 724444c061aSmrg} 725444c061aSmrg 726444c061aSmrgWidget 727a3bd7f05SmrgXtAppCreateShell(_Xconst char *name, 728a3bd7f05Smrg _Xconst char *class, 729a3bd7f05Smrg WidgetClass widget_class, 730a3bd7f05Smrg Display *display, ArgList args, Cardinal num_args) 731444c061aSmrg{ 732444c061aSmrg Widget retval; 733444c061aSmrg DPY_TO_APPCON(display); 734444c061aSmrg 735444c061aSmrg LOCK_APP(app); 736a3bd7f05Smrg retval = _XtAppCreateShell((String) name, (String) class, widget_class, 737a3bd7f05Smrg display, args, num_args, (XtTypedArgList) NULL, 738a3bd7f05Smrg (Cardinal) 0); 739444c061aSmrg UNLOCK_APP(app); 740444c061aSmrg return retval; 741444c061aSmrg} 742444c061aSmrg 743444c061aSmrgWidget 744a3bd7f05SmrgXtCreateApplicationShell(_Xconst char *name _X_UNUSED, 745a3bd7f05Smrg WidgetClass widget_class, 746a3bd7f05Smrg ArgList args, 747a3bd7f05Smrg Cardinal num_args) 748444c061aSmrg{ 749444c061aSmrg Widget retval; 750a3bd7f05Smrg Display *dpy; 751444c061aSmrg XrmClass class; 752444c061aSmrg XtAppContext app = _XtDefaultAppContext(); 753444c061aSmrg 754444c061aSmrg LOCK_APP(app); 755444c061aSmrg dpy = app->list[0]; 756444c061aSmrg class = _XtGetPerDisplay(dpy)->class; 757444c061aSmrg 758a3bd7f05Smrg retval = 759a3bd7f05Smrg _XtAppCreateShell((String) NULL, XrmQuarkToString((XrmQuark) class), 760a3bd7f05Smrg widget_class, dpy, args, num_args, 761a3bd7f05Smrg (XtTypedArgList) NULL, (Cardinal) 0); 762444c061aSmrg UNLOCK_APP(app); 763444c061aSmrg return retval; 764444c061aSmrg} 765444c061aSmrg 766444c061aSmrgWidget 767a3bd7f05Smrg_XtCreateHookObj(Screen *screen) 768444c061aSmrg{ 769444c061aSmrg Widget req_widget; 770444c061aSmrg double widget_cache[100]; 771444c061aSmrg Cardinal wsize = 0; 772444c061aSmrg Widget hookobj = xtWidgetAlloc(hookObjectClass, 773a3bd7f05Smrg (ConstraintWidgetClass) NULL, 774a3bd7f05Smrg (Widget) NULL, "hooks", 775a3bd7f05Smrg (ArgList) NULL, (Cardinal) 0, 776a3bd7f05Smrg (XtTypedArgList) NULL, (Cardinal) 0); 777a3bd7f05Smrg 778a3bd7f05Smrg ((HookObject) hookobj)->hooks.screen = screen; 779a3bd7f05Smrg (void) _XtGetResources(hookobj, (ArgList) NULL, 0, 780a3bd7f05Smrg (XtTypedArgList) NULL, &wsize); 781444c061aSmrg CompileCallbacks(hookobj); 782444c061aSmrg wsize = hookObjectClass->core_class.widget_size; 783444c061aSmrg req_widget = (Widget) XtStackAlloc(wsize, widget_cache); 784a3bd7f05Smrg (void) memmove((char *) req_widget, (char *) hookobj, (size_t) wsize); 785a3bd7f05Smrg CallInitialize(hookObjectClass, req_widget, hookobj, 786a3bd7f05Smrg (ArgList) NULL, (Cardinal) 0); 787a3bd7f05Smrg XtStackFree((XtPointer) req_widget, widget_cache); 788444c061aSmrg return hookobj; 789444c061aSmrg} 790