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