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