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