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