VarCreate.c revision fdf6a26f
1/* 2 3Copyright (c) 1993, Oracle and/or its affiliates. 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(String name, 67 WidgetClass widget_class, 68 Widget parent, 69 va_list var, 70 int count) 71{ 72 register Widget widget; 73 XtTypedArgList typed_args = NULL; 74 Cardinal num_args; 75 76 _XtVaToTypedArgList(var, count, &typed_args, &num_args); 77 78 widget = _XtCreateWidget(name, widget_class, parent, (ArgList) NULL, 79 (Cardinal) 0, typed_args, num_args); 80 81 XtFree((XtPointer) typed_args); 82 83 return widget; 84} 85 86Widget 87XtVaCreateWidget(_Xconst char *name, 88 WidgetClass widget_class, 89 Widget parent, 90 ...) 91{ 92 va_list var; 93 register Widget widget; 94 int total_count, typed_count; 95 96 WIDGET_TO_APPCON(parent); 97 98 LOCK_APP(app); 99 va_start(var, parent); 100 _XtCountVaList(var, &total_count, &typed_count); 101 va_end(var); 102 103 va_start(var, parent); 104 widget = _XtVaCreateWidget((String) name, widget_class, parent, var, 105 total_count); 106 va_end(var); 107 UNLOCK_APP(app); 108 return widget; 109} 110 111Widget 112XtVaCreateManagedWidget(_Xconst char *name, 113 WidgetClass widget_class, 114 Widget parent, 115 ...) 116{ 117 va_list var; 118 register Widget widget; 119 int total_count, typed_count; 120 121 WIDGET_TO_APPCON(parent); 122 123 LOCK_APP(app); 124 va_start(var, parent); 125 _XtCountVaList(var, &total_count, &typed_count); 126 va_end(var); 127 128 va_start(var, parent); 129 widget = _XtVaCreateWidget((String) name, widget_class, parent, var, 130 total_count); 131 XtManageChild(widget); 132 va_end(var); 133 UNLOCK_APP(app); 134 return widget; 135} 136 137Widget 138XtVaAppCreateShell(_Xconst char *name, 139 _Xconst char *class, 140 WidgetClass widget_class, 141 Display *display, 142 ...) 143{ 144 va_list var; 145 register Widget widget; 146 XtTypedArgList typed_args = NULL; 147 Cardinal num_args; 148 int total_count, typed_count; 149 DPY_TO_APPCON(display); 150 151 LOCK_APP(app); 152 va_start(var, display); 153 154 _XtCountVaList(var, &total_count, &typed_count); 155 va_end(var); 156 157 va_start(var, display); 158 159 _XtVaToTypedArgList(var, total_count, &typed_args, &num_args); 160 widget = _XtAppCreateShell((String) name, (String) class, widget_class, 161 display, (ArgList) NULL, (Cardinal) 0, 162 typed_args, num_args); 163 164 XtFree((XtPointer) typed_args); 165 166 va_end(var); 167 UNLOCK_APP(app); 168 return widget; 169} 170 171Widget 172XtVaCreatePopupShell(_Xconst char *name, 173 WidgetClass widget_class, 174 Widget parent, 175 ...) 176{ 177 va_list var; 178 register Widget widget; 179 XtTypedArgList typed_args = NULL; 180 Cardinal num_args; 181 int total_count, typed_count; 182 183 WIDGET_TO_APPCON(parent); 184 185 LOCK_APP(app); 186 va_start(var, parent); 187 _XtCountVaList(var, &total_count, &typed_count); 188 va_end(var); 189 190 va_start(var, parent); 191 192 _XtVaToTypedArgList(var, total_count, &typed_args, &num_args); 193 widget = _XtCreatePopupShell((String) name, widget_class, parent, 194 (ArgList) NULL, (Cardinal) 0, typed_args, 195 num_args); 196 197 XtFree((XtPointer) typed_args); 198 199 va_end(var); 200 UNLOCK_APP(app); 201 return widget; 202} 203 204void 205XtVaSetValues(Widget widget, ...) 206{ 207 va_list var; 208 ArgList args = NULL; 209 Cardinal num_args; 210 int total_count, typed_count; 211 212 WIDGET_TO_APPCON(widget); 213 214 LOCK_APP(app); 215 va_start(var, widget); 216 _XtCountVaList(var, &total_count, &typed_count); 217 va_end(var); 218 219 va_start(var, widget); 220 221 _XtVaToArgList(widget, var, total_count, &args, &num_args); 222 XtSetValues(widget, args, num_args); 223 _XtFreeArgList(args, total_count, typed_count); 224 225 UNLOCK_APP(app); 226 va_end(var); 227} 228 229void 230XtVaSetSubvalues(XtPointer base, 231 XtResourceList resources, 232 Cardinal num_resources, 233 ...) 234{ 235 va_list var; 236 ArgList args; 237 Cardinal num_args; 238 int total_count, typed_count; 239 240 va_start(var, num_resources); 241 _XtCountVaList(var, &total_count, &typed_count); 242 va_end(var); 243 244 if (typed_count != 0) { 245 XtWarning("XtVaTypedArg is not valid in XtVaSetSubvalues()\n"); 246 } 247 248 va_start(var, num_resources); 249 _XtVaToArgList((Widget) NULL, var, total_count, &args, &num_args); 250 251 XtSetSubvalues(base, resources, num_resources, args, num_args); 252 253 XtFree((XtPointer) args); 254 255 va_end(var); 256} 257 258Widget 259_XtVaOpenApplication(XtAppContext *app_context_return, 260 _Xconst char *application_class, 261 XrmOptionDescList options, 262 Cardinal num_options, 263 int *argc_in_out, 264 _XtString *argv_in_out, 265 String *fallback_resources, 266 WidgetClass widget_class, 267 va_list var_args) 268{ 269 XtAppContext app_con; 270 Display *dpy; 271 register int saved_argc = *argc_in_out; 272 Widget root; 273 String attr; 274 int count = 0; 275 XtTypedArgList typed_args; 276 277 XtToolkitInitialize(); /* cannot be moved into _XtAppInit */ 278 279 dpy = _XtAppInit(&app_con, (String) application_class, options, num_options, 280 argc_in_out, &argv_in_out, fallback_resources); 281 282 typed_args = (XtTypedArgList) __XtMalloc((unsigned) sizeof(XtTypedArg)); 283 attr = va_arg(var_args, String); 284 for (; attr != NULL; attr = va_arg(var_args, String)) { 285 if (strcmp(attr, XtVaTypedArg) == 0) { 286 typed_args[count].name = va_arg(var_args, String); 287 typed_args[count].type = va_arg(var_args, String); 288 typed_args[count].value = va_arg(var_args, XtArgVal); 289 typed_args[count].size = va_arg(var_args, int); 290 } 291 else { 292 typed_args[count].name = attr; 293 typed_args[count].type = NULL; 294 typed_args[count].value = va_arg(var_args, XtArgVal); 295 typed_args[count].size = 0; 296 } 297 count++; 298 typed_args = XtReallocArray(typed_args, (Cardinal) count + 1, 299 (Cardinal) sizeof(XtTypedArg)); 300 } 301 typed_args[count].name = NULL; 302 303 va_end(var_args); 304 305 root = 306 XtVaAppCreateShell(NULL, application_class, 307 widget_class, dpy, 308 XtNscreen, (XtArgVal) DefaultScreenOfDisplay(dpy), 309 XtNargc, (XtArgVal) saved_argc, 310 XtNargv, (XtArgVal) argv_in_out, 311 XtVaNestedList, (XtVarArgsList) typed_args, NULL); 312 313 if (app_context_return != NULL) 314 *app_context_return = app_con; 315 316 XtFree((XtPointer) typed_args); 317 XtFree((XtPointer) argv_in_out); 318 return (root); 319} 320 321Widget 322_XtVaAppInitialize(XtAppContext *app_context_return, 323 _Xconst char *application_class, 324 XrmOptionDescList options, 325 Cardinal num_options, 326 int *argc_in_out, 327 _XtString *argv_in_out, 328 String *fallback_resources, 329 va_list var_args) 330{ 331 return _XtVaOpenApplication(app_context_return, application_class, 332 options, num_options, 333 argc_in_out, argv_in_out, fallback_resources, 334 applicationShellWidgetClass, var_args); 335} 336 337#if !((defined(SUNSHLIB) || defined(AIXSHLIB)) && defined(SHAREDCODE)) 338 339/* 340 * If not used as a shared library, we still need a front end to 341 * _XtVaOpenApplication and to _XtVaAppInitialize. 342 */ 343 344Widget 345XtVaOpenApplication(XtAppContext *app_context_return, 346 _Xconst char *application_class, 347 XrmOptionDescList options, 348 Cardinal num_options, 349 int *argc_in_out, 350 _XtString *argv_in_out, 351 String *fallback_resources, 352 WidgetClass widget_class, 353 ...) 354{ 355 Widget code; 356 va_list var; 357 358 va_start(var, widget_class); 359 code = _XtVaOpenApplication(app_context_return, (String) application_class, 360 options, num_options, argc_in_out, argv_in_out, 361 fallback_resources, widget_class, var); 362 va_end(var); 363 return code; 364} 365 366Widget 367XtVaAppInitialize(XtAppContext *app_context_return, 368 _Xconst char *application_class, 369 XrmOptionDescList options, 370 Cardinal num_options, 371 int *argc_in_out, 372 _XtString *argv_in_out, 373 String *fallback_resources, 374 ...) 375{ 376 Widget code; 377 va_list var; 378 379 va_start(var, fallback_resources); 380 code = _XtVaOpenApplication(app_context_return, (String) application_class, 381 options, num_options, argc_in_out, argv_in_out, 382 fallback_resources, 383 applicationShellWidgetClass, var); 384 va_end(var); 385 return code; 386} 387 388#endif /* !((SUNSHLIB || AIXSHLIB) && SHAREDCODE) */ 389