VarCreate.c revision 0568f49b
1/* 2 3Copyright (c) 1993, Oracle and/or its affiliates. All rights reserved. 4 5Permission is hereby granted, free of charge, to any person obtaining a 6copy of this software and associated documentation files (the "Software"), 7to deal in the Software without restriction, including without limitation 8the rights to use, copy, modify, merge, publish, distribute, sublicense, 9and/or sell copies of the Software, and to permit persons to whom the 10Software is furnished to do so, subject to the following conditions: 11 12The above copyright notice and this permission notice (including the next 13paragraph) shall be included in all copies or substantial portions of the 14Software. 15 16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22DEALINGS IN THE SOFTWARE. 23 24*/ 25 26/* 27 28Copyright 1885, 1986, 1987, 1988, 1989, 1994, 1998 The Open Group 29 30Permission to use, copy, modify, distribute, and sell this software and its 31documentation for any purpose is hereby granted without fee, provided that 32the above copyright notice appear in all copies and that both that 33copyright notice and this permission notice appear in supporting 34documentation. 35 36The above copyright notice and this permission notice shall be included in 37all copies or substantial portions of the Software. 38 39THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 40IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 41FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 42OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 43AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 44CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 45 46Except as contained in this notice, the name of The Open Group shall not be 47used in advertising or otherwise to promote the sale, use or other dealings 48in this Software without prior written authorization from The Open Group. 49 50*/ 51 52#ifdef HAVE_CONFIG_H 53#include <config.h> 54#endif 55#include "IntrinsicI.h" 56#include "StringDefs.h" 57#include "Shell.h" 58#include "VarargsI.h" 59#include "CreateI.h" 60 61#if (defined(SUNSHLIB) || defined(AIXSHLIB)) && defined(SHAREDCODE) 62#define XtToolkitInitialize _XtToolkitInitialize 63#endif /* (SUNSHLIB || AIXSHLIB) && SHAREDCODE */ 64 65static Widget 66_XtVaCreateWidget( 67 String name, 68 WidgetClass widget_class, 69 Widget parent, 70 va_list var, 71 int count) 72{ 73 register Widget widget; 74 XtTypedArgList typed_args = NULL; 75 Cardinal num_args; 76 77 _XtVaToTypedArgList(var, count, &typed_args, &num_args); 78 79 widget = _XtCreateWidget(name, widget_class, parent, (ArgList)NULL, 80 (Cardinal)0, typed_args, num_args); 81 82 83 XtFree((XtPointer)typed_args); 84 85 return widget; 86} 87 88 89Widget 90XtVaCreateWidget( 91 _Xconst char* name, 92 WidgetClass widget_class, 93 Widget parent, 94 ...) 95{ 96 va_list var; 97 register Widget widget; 98 int total_count, typed_count; 99 WIDGET_TO_APPCON(parent); 100 101 LOCK_APP(app); 102 va_start(var,parent); 103 _XtCountVaList(var, &total_count, &typed_count); 104 va_end(var); 105 106 va_start(var,parent); 107 widget = _XtVaCreateWidget((String)name, widget_class, parent, var, 108 total_count); 109 va_end(var); 110 UNLOCK_APP(app); 111 return widget; 112} 113 114 115Widget 116XtVaCreateManagedWidget( 117 _Xconst char* name, 118 WidgetClass widget_class, 119 Widget parent, 120 ...) 121{ 122 va_list var; 123 register Widget widget; 124 int total_count, typed_count; 125 WIDGET_TO_APPCON(parent); 126 127 LOCK_APP(app); 128 va_start(var,parent); 129 _XtCountVaList(var, &total_count, &typed_count); 130 va_end(var); 131 132 va_start(var,parent); 133 widget = _XtVaCreateWidget((String)name, widget_class, parent, var, 134 total_count); 135 XtManageChild(widget); 136 va_end(var); 137 UNLOCK_APP(app); 138 return widget; 139} 140 141 142Widget 143XtVaAppCreateShell( 144 _Xconst char* name, 145 _Xconst char* class, 146 WidgetClass widget_class, 147 Display* display, 148 ...) 149{ 150 va_list var; 151 register Widget widget; 152 XtTypedArgList typed_args = NULL; 153 Cardinal num_args; 154 int total_count, typed_count; 155 DPY_TO_APPCON(display); 156 157 LOCK_APP(app); 158 va_start(var,display); 159 _XtCountVaList(var, &total_count, &typed_count); 160 va_end(var); 161 162 va_start(var,display); 163 164 _XtVaToTypedArgList(var, total_count, &typed_args, &num_args); 165 widget = _XtAppCreateShell((String)name, (String)class, widget_class, 166 display, (ArgList)NULL, (Cardinal)0, typed_args, num_args); 167 168 XtFree((XtPointer)typed_args); 169 170 va_end(var); 171 UNLOCK_APP(app); 172 return widget; 173} 174 175 176Widget 177XtVaCreatePopupShell( 178 _Xconst char* name, 179 WidgetClass widget_class, 180 Widget parent, 181 ...) 182{ 183 va_list var; 184 register Widget widget; 185 XtTypedArgList typed_args = NULL; 186 Cardinal num_args; 187 int total_count, typed_count; 188 WIDGET_TO_APPCON(parent); 189 190 LOCK_APP(app); 191 va_start(var,parent); 192 _XtCountVaList(var, &total_count, &typed_count); 193 va_end(var); 194 195 va_start(var,parent); 196 197 _XtVaToTypedArgList(var, total_count, &typed_args, &num_args); 198 widget = _XtCreatePopupShell((String)name, widget_class, parent, 199 (ArgList)NULL, (Cardinal)0, typed_args, num_args); 200 201 XtFree((XtPointer)typed_args); 202 203 va_end(var); 204 UNLOCK_APP(app); 205 return widget; 206} 207 208void 209XtVaSetValues(Widget widget, ...) 210{ 211 va_list var; 212 ArgList args = NULL; 213 Cardinal num_args; 214 int total_count, typed_count; 215 WIDGET_TO_APPCON(widget); 216 217 LOCK_APP(app); 218 va_start(var,widget); 219 _XtCountVaList(var, &total_count, &typed_count); 220 va_end(var); 221 222 va_start(var,widget); 223 224 _XtVaToArgList(widget, var, total_count, &args, &num_args); 225 XtSetValues(widget, args, num_args); 226 _XtFreeArgList(args, total_count, typed_count); 227 228 UNLOCK_APP(app); 229 va_end(var); 230} 231 232 233void 234XtVaSetSubvalues(XtPointer base, XtResourceList resources, Cardinal num_resources, ...) 235{ 236 va_list var; 237 ArgList args; 238 Cardinal num_args; 239 int total_count, typed_count; 240 241 va_start(var, num_resources); 242 _XtCountVaList(var, &total_count, &typed_count); 243 va_end(var); 244 245 if (typed_count != 0) { 246 XtWarning("XtVaTypedArg is not valid in XtVaSetSubvalues()\n"); 247 } 248 249 va_start(var, num_resources); 250 _XtVaToArgList((Widget)NULL, var, total_count, &args, &num_args); 251 252 XtSetSubvalues(base, resources, num_resources, args, num_args); 253 254 XtFree((XtPointer)args); 255 256 va_end(var); 257} 258 259Widget 260_XtVaOpenApplication( 261 XtAppContext *app_context_return, 262 _Xconst char* application_class, 263 XrmOptionDescList options, 264 Cardinal num_options, 265 int *argc_in_out, 266 _XtString *argv_in_out, 267 String *fallback_resources, 268 WidgetClass widget_class, 269 va_list var_args) 270{ 271 XtAppContext app_con; 272 Display * dpy; 273 register int saved_argc = *argc_in_out; 274 Widget root; 275 String attr; 276 int count = 0; 277 XtTypedArgList typed_args; 278 279 XtToolkitInitialize(); /* cannot be moved into _XtAppInit */ 280 281 dpy = _XtAppInit(&app_con, (String)application_class, options, num_options, 282 argc_in_out, &argv_in_out, fallback_resources); 283 284 typed_args = (XtTypedArgList) __XtMalloc((unsigned) sizeof(XtTypedArg)); 285 attr = va_arg (var_args, String); 286 for(; attr != NULL; attr = va_arg (var_args, String)) { 287 if (strcmp(attr, XtVaTypedArg) == 0) { 288 typed_args[count].name = va_arg(var_args, String); 289 typed_args[count].type = va_arg(var_args, String); 290 typed_args[count].value = va_arg(var_args, XtArgVal); 291 typed_args[count].size = va_arg(var_args, int); 292 } else { 293 typed_args[count].name = attr; 294 typed_args[count].type = NULL; 295 typed_args[count].value = va_arg(var_args, XtArgVal); 296 typed_args[count].size = 0; 297 } 298 count++; 299 typed_args = (XtTypedArgList) 300 XtRealloc((char *) typed_args, 301 (Cardinal) ((size_t)(count + 1) * sizeof(XtTypedArg))); 302 } 303 typed_args[count].name = NULL; 304 305 va_end (var_args); 306 307 root = 308 XtVaAppCreateShell( NULL, application_class, 309 widget_class, dpy, 310 XtNscreen, (XtArgVal)DefaultScreenOfDisplay(dpy), 311 XtNargc, (XtArgVal)saved_argc, 312 XtNargv, (XtArgVal)argv_in_out, 313 XtVaNestedList, (XtVarArgsList)typed_args, 314 NULL ); 315 316 if (app_context_return != NULL) 317 *app_context_return = app_con; 318 319 XtFree((XtPointer)typed_args); 320 XtFree((XtPointer)argv_in_out); 321 return(root); 322} 323 324Widget 325_XtVaAppInitialize( 326 XtAppContext *app_context_return, 327 _Xconst char* application_class, 328 XrmOptionDescList options, 329 Cardinal num_options, 330 int *argc_in_out, 331 _XtString *argv_in_out, 332 String *fallback_resources, 333 va_list var_args) 334{ 335 return _XtVaOpenApplication(app_context_return, application_class, 336 options, num_options, 337 argc_in_out, argv_in_out, fallback_resources, 338 applicationShellWidgetClass, var_args); 339} 340 341#if !((defined(SUNSHLIB) || defined(AIXSHLIB)) && defined(SHAREDCODE)) 342 343/* 344 * If not used as a shared library, we still need a front end to 345 * _XtVaOpenApplication and to _XtVaAppInitialize. 346 */ 347 348Widget 349XtVaOpenApplication( 350 XtAppContext *app_context_return, 351 _Xconst char* application_class, 352 XrmOptionDescList options, 353 Cardinal num_options, 354 int *argc_in_out, 355 _XtString *argv_in_out, 356 String *fallback_resources, 357 WidgetClass widget_class, 358 ...) 359{ 360 Widget code; 361 va_list var; 362 363 va_start(var, widget_class); 364 code = _XtVaOpenApplication(app_context_return, (String)application_class, 365 options, num_options, argc_in_out, argv_in_out, 366 fallback_resources, widget_class, var); 367 va_end(var); 368 return code; 369} 370 371Widget 372XtVaAppInitialize( 373 XtAppContext *app_context_return, 374 _Xconst char* application_class, 375 XrmOptionDescList options, 376 Cardinal num_options, 377 int *argc_in_out, 378 _XtString *argv_in_out, 379 String *fallback_resources, 380 ...) 381{ 382 Widget code; 383 va_list var; 384 385 va_start(var, fallback_resources); 386 code = _XtVaOpenApplication(app_context_return, (String)application_class, 387 options, num_options, argc_in_out, argv_in_out, 388 fallback_resources, 389 applicationShellWidgetClass, var); 390 va_end(var); 391 return code; 392} 393 394#endif /* !((SUNSHLIB || AIXSHLIB) && SHAREDCODE) */ 395 396