1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
/*
* Miscellaneous X utility routines
*
* $Id: Xju.c,v 1.3 1995/01/04 17:28:33 jdd Exp $
*/
#include <varargs.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
extern Widget root;
void SetArgs(va_alist)
va_dcl
{
/* SetArgs takes a variable number of arguments, of the form
of char *argtype, XtArgVal value pairs. This ends with
a NULL. SetArgs then returns the corresponding argument list.
SetArgs' second argument should be a pointer to a Cardinal,
which will contain the number of args in the new arglist,
and its first argument should be a pointer to an Arg
pointer which will be set to the returned arg list */
va_list argindex;
unsigned i;
Arg **arglist;
Cardinal *count;
va_start(argindex);
/* Get first two arguments */
arglist = va_arg(argindex, Arg **);
count = va_arg(argindex, Cardinal *);
/* Count number of passed Arglist pairs */
*count = 0;
while(1){
if(NULL == va_arg(argindex, char *))
break;
(void) va_arg(argindex, XtArgVal);
(*count)++;
}
va_end(argindex);
/* Allocate sufficient memory for new arg list */
*arglist = (Arg *)XtMalloc((*count)*sizeof(Arg));
/* Set new Arg list */
va_start(argindex);
/* skip past first two arguments */
(void) va_arg(argindex, Arg **);
(void) va_arg(argindex, int *);
for(i=0;i<*count;i++){
XtSetArg((*arglist)[i], va_arg(argindex, char *),
va_arg(argindex, XtArgVal));
}
va_end(argindex);
}
Widget CreateWidget(va_alist)
va_dcl
{
/* CreateWidget takes a variable number of arguments,
the first of which are the following:
widget name, widget class, widget parent.
All following arguments are char *argtype, XtArgVal pairs. The
last argument must be a NULL.
CreateWidget will construct a widget of the given class,
with the given name and parent. An argument list for the
widget constructed out of the char *argtype, XtArgVal pairs
will be created as well. CreateWidget will call
XtCreateManagedWidget, and return the resulting widget id */
va_list argindex;
unsigned i;
Arg *arglist;
Cardinal count;
Widget w, parent;
char *name;
WidgetClass class;
va_start(argindex);
/* Get first three arguments */
name = va_arg(argindex, char *);
class = va_arg(argindex, WidgetClass);
parent = va_arg(argindex, Widget);
/* Count number of passed Arglist pairs */
count = 0;
while(1){
if (NULL == va_arg(argindex, char *))
break;
(void) va_arg(argindex, XtArgVal);
count++;
}
va_end(argindex);
/* Allocate sufficient memory for new arg list */
arglist = (Arg *)XtMalloc((count)*sizeof(Arg));
/* Set new Arg list */
va_start(argindex);
/* skip past first three arguments */
(void) va_arg(argindex, char *);
(void) va_arg(argindex, WidgetClass);
(void) va_arg(argindex, Widget);
for(i=0;i<count;i++){
XtSetArg(arglist[i], va_arg(argindex, char *),
va_arg(argindex, XtArgVal));
}
va_end(argindex);
if(parent == NULL) (void) printf("%s\n", name);
w = XtCreateManagedWidget(name, class, parent,
arglist, count);
XtFree((char *)arglist);
return(w);
}
void QueryWidget(va_alist)
va_dcl
{
/* QueryWidget takes a variable number of arguments,
the first of which is the widget being queried.
All following arguments are char *argtype, *XtArgVal pairs. The
last argument must be a NULL.
QueryWidget will query the specified widget using XtGetValues,
and will return the results in the same way as XtGetValues. */
va_list argindex;
unsigned i;
Arg *arglist;
Cardinal count;
Widget w;
va_start(argindex);
/* Get first argument */
w = va_arg(argindex, Widget);
/* Count number of passed Arglist pairs */
count = 0;
while(1){
if (NULL == va_arg(argindex, char *))
break;
(void) va_arg(argindex, XtArgVal);
count++;
}
va_end(argindex);
/* Allocate sufficient memory for new arg list */
arglist = (Arg *)XtMalloc(count*sizeof(Arg));
/* Set new Arg list */
va_start(argindex);
/* skip past first argument */
(void) va_arg(argindex, Widget);
for(i=0;i<count;i++){
XtSetArg(arglist[i], va_arg(argindex, char *),
va_arg(argindex, XtArgVal));
}
va_end(argindex);
XtGetValues(w, arglist, count);
XtFree((char *)arglist);
}
void ConfigureWidget(va_alist)
va_dcl
{
/* ConfigureWidget takes a variable number of arguments, the
first of which is the widget being queried. All following arguments
are char *argtype, XtArgVal pairs. The last argument must be a
NULL.
ConfigureWidget will configure the specified widget using
XtSetValues. */
va_list argindex;
unsigned i;
Arg *arglist;
Cardinal count;
Widget w;
va_start(argindex);
/* Get first argument */
w = va_arg(argindex, Widget);
/* Count number of passed Arglist pairs */
count = 0;
while(1){
if (NULL== va_arg(argindex, char *))
break;
(void) va_arg(argindex, XtArgVal);
count++;
}
va_end(argindex);
/* Allocate sufficient memory for new arg list */
arglist = (Arg *)XtMalloc(count*sizeof(Arg));
/* Set new Arg list */
va_start(argindex);
/* skip past first argument */
(void) va_arg(argindex, Widget);
for(i=0;i<count;i++){
XtSetArg(arglist[i], va_arg(argindex, char *),
va_arg(argindex, XtArgVal));
}
va_end(argindex);
XtSetValues(w, arglist, count);
XtFree((char *)arglist);
}
|