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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
|
/*
* Motif
*
* Copyright (c) 1987-2012, The Open Group. All rights reserved.
*
* These libraries and programs are free software; you can
* redistribute them and/or modify them under the terms of the GNU
* Lesser General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* These libraries and programs are distributed in the hope that
* they will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with these librararies and programs; if not, write
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301 USA
*/
/*
* HISTORY
*/
#ifdef REV_INFO
#ifndef lint
static char rcsid[] = "$XConsortium: SelectBox1.c /main/9 1995/07/13 19:19:18 drk $"
#endif
#endif
/*
* (c) Copyright 1987, 1988, 1989 HEWLETT-PACKARD COMPANY */
#include <testlib.h>
#define NITEMS 62
#define VITEMS 20
char *Istrings[] = {
"btest1a", "btest1b", "btest2", "btest3",
"decor00", "decor01", "decor02", "decor03", "decor04", "decor05",
"decor06", "decor07", "decor08", "decor09",
"func00", "func01", "func02", "func03", "func04",
"func05", "func06", "func07", "func08", "func09",
"func10", "func11", "func12", "func13", "func14",
"iplac00", "iplac01", "iplac02", "iplac03", "iplac04",
"iplac05", "iplac06", "iplac07", "iplac08",
"menu00", "menu01", "menu02", "menu03",
"menu04", "menu05", "menu06", "menu07",
"mtest1", "mtest2", "mvrz00", "mvrz01",
"parse00", "parse01", "parse02", "parse03", "pitest1",
"prop00", "prop01", "prop02", "prop03", "prop04", "prop05",
"rstest1"
};
Widget ScaleDialog;
Widget ScaleWidth, ScaleColumns;
void UpdateScale();
static void ApplyToSelectionBox();
static void KillYourself();
static void PostDialog();
void GetResources ();
Widget SelectionBox1;
static void noMatchCB();
static void okCB();
static void applyCB();
static void cancelCB();
void main(argc, argv)
int argc;
char **argv;
{
register int n;
Arg args[MAX_ARGS];
XmString tcs, tcs2, tcs3, tcs4, ItemList[NITEMS];
int i;
Widget help_child;
CommonTestInit(argc, argv);
n = 0;
XtSetArg(args[n], XmNwidth, 10); n++;
XtSetArg(args[n], XmNheight, 10); n++;
XtSetValues(Shell1, args, n);
XtRealizeWidget(Shell1);
tcs = XmStringLtoRCreate("test: ", XmSTRING_DEFAULT_CHARSET);
tcs2 = XmStringLtoRCreate("Pick a Test", XmSTRING_DEFAULT_CHARSET);
tcs3 = XmStringCreate("MyDialogTitle", "iso8859-1");
n = 0;
tcs4 = XmStringCreateLtoR ("prop00", XmSTRING_DEFAULT_CHARSET);
XtSetArg(args[n], XmNselectionLabelString, tcs); n++;
XtSetArg(args[n], XmNautoUnmanage, False); n++;
XtSetArg(args[n], XmNlistLabelString, tcs2); n++;
XtSetArg(args[n], XmNmustMatch, True); n++;
XtSetArg(args[n], XmNdialogTitle, tcs3); n++;
XtSetArg(args[n], XmNtextString, tcs4 ); n++;
SelectionBox1 = XmCreateSelectionDialog(Shell1, "SelectionBox1", args, n);
XtManageChild(XmSelectionBoxGetChild(SelectionBox1,XmDIALOG_APPLY_BUTTON));
/* Convert the items to Xm strings */
for (n = 0; n < NITEMS; n++)
ItemList[n] = XmStringCreateLtoR((char *)Istrings[n],
XmSTRING_DEFAULT_CHARSET);
/* Add 'em to the SelectionBox */
n = 0;
XtSetArg(args[n], XmNlistItems, ItemList); n++;
XtSetArg(args[n], XmNlistItemCount, NITEMS); n++;
XtSetArg(args[n], XmNlistVisibleItemCount, VITEMS); n++;
XtSetValues(SelectionBox1, args, n);
XtManageChild(SelectionBox1);
XmStringFree(tcs);
XmStringFree(tcs2);
XmStringFree(tcs4);
XtAddCallback(SelectionBox1, XmNnoMatchCallback, noMatchCB, NULL);
XtAddCallback(SelectionBox1, XmNokCallback, okCB, NULL);
XtAddCallback(SelectionBox1, XmNapplyCallback, applyCB, NULL);
XtAddCallback(SelectionBox1, XmNcancelCallback, cancelCB, NULL);
CommonPause();
CommonPause();
CommonPause();
CommonPause();
CommonPause();
help_child = XmMessageBoxGetChild(InstructionBox, XmDIALOG_HELP_BUTTON);
tcs = XmStringCreateSimple("Measure");
n = 0;
XtSetArg(args[n], XmNsensitive, True); n++;
XtSetArg(args[n], XmNlabelString, tcs); n++;
XtSetValues(help_child, args, n);
GetResources();
XtAddCallback(help_child, XmNactivateCallback, PostDialog, NULL);
XmStringFree(tcs);
CommonPause(); /* measure */
/* unmanage text and make all button children disappear on activate */
XtUnmanageChild(XmSelectionBoxGetChild(SelectionBox1, XmDIALOG_TEXT));
XtAddCallback(XmSelectionBoxGetChild(SelectionBox1, XmDIALOG_APPLY_BUTTON),
XmNactivateCallback, KillYourself, NULL);
XtAddCallback(XmSelectionBoxGetChild(SelectionBox1, XmDIALOG_CANCEL_BUTTON),
XmNactivateCallback, KillYourself, NULL);
XtAddCallback(XmSelectionBoxGetChild(SelectionBox1, XmDIALOG_DEFAULT_BUTTON)
, XmNactivateCallback, KillYourself, NULL);
XtAddCallback(XmSelectionBoxGetChild(SelectionBox1, XmDIALOG_HELP_BUTTON),
XmNactivateCallback, KillYourself, NULL);
CommonPause(); /* more measure without Text */
XtAppMainLoop(app_context);
}
static void KillYourself (w, client_data, call_data)
Widget w;
XtPointer client_data, call_data;
{
XtUnmanageChild (w);
}
void GetResources ()
{
short col;
Dimension width;
int n;
Arg args[10];
XmString tcs;
Widget ScaleOK;
static char *scaleWidgets[] = { "ScaleWidth",
"ScaleColumns",
(char *) NULL
};
n = 0;
XtSetArg (args[n], XmNautoUnmanage, False); n++;
XtSetArg (args[n], XmNdefaultPosition, False); n++;
XtSetArg (args[n], XmNx, 350); n++;
XtSetArg (args[n], XmNy, 350); n++;
ScaleDialog = XmCreateBulletinBoardDialog(SelectionBox1, "ScaleDialog",
args, n);
n = 0;
tcs = XmStringCreateSimple ("Width");
XtSetArg (args[n], XmNorientation, XmHORIZONTAL); n++;
XtSetArg (args[n], XmNshowValue, True); n++;
XtSetArg (args[n], XmNminimum, 1); n++;
XtSetArg (args[n], XmNmaximum, 600); n++;
XtSetArg (args[n], XmNtitleString, tcs ); n++;
XtSetArg (args[n], XmNy, 10); n++;
XtSetArg (args[n], XmNx, 10); n++;
ScaleWidth = XmCreateScale (ScaleDialog, "ScaleWidth", args, n);
XmStringFree(tcs);
n = 0;
tcs = XmStringCreateSimple("Columns");
XtSetArg (args[n], XmNorientation, XmHORIZONTAL); n++;
XtSetArg (args[n], XmNshowValue, True); n++;
XtSetArg (args[n], XmNminimum, 1); n++;
XtSetArg (args[n], XmNmaximum, 132); n++;
XtSetArg (args[n], XmNtitleString, tcs ); n++;
XtSetArg (args[n], XmNy, 100); n++;
XtSetArg (args[n], XmNx, 10); n++;
ScaleColumns = XmCreateScale (ScaleDialog, "ScaleColumns", args, n);
XmStringFree(tcs);
n = 0;
tcs = XmStringCreateSimple ("OK");
XtSetArg (args[n], XmNx, 100); n++;
XtSetArg (args[n], XmNy, 200); n++;
XtSetArg (args[n], XmNlabelString, tcs ); n++;
ScaleOK = XmCreatePushButtonGadget (ScaleDialog, "ScaleOK", args, n);
XmStringFree(tcs);
XtAddCallback
(ScaleOK, XmNactivateCallback, ApplyToSelectionBox, scaleWidgets);
XtManageChild (ScaleOK);
XtManageChild (ScaleWidth);
XtManageChild (ScaleColumns);
}
void UpdateScale (scale, value)
Widget scale;
int value;
{
Arg args[2];
int min, max;
int n;
n = 0;
XtSetArg (args[n], XmNminimum, &min); n++;
XtSetArg (args[n], XmNmaximum, &max); n++;
XtGetValues (scale, args, n);
/* fix up end cases first */
if (value < min) value = min;
if (value > max) value = max;
XtSetArg (args[0], XmNvalue, value);
XtSetValues (scale, args, 1);
}
static void PostDialog(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
register int n;
Arg args[10];
short col;
Dimension width;
/* set the scales to the current values of the selection box */
n = 0;
XtSetArg (args[n], XmNtextColumns, &col) ; n++;
XtSetArg (args[n], XmNwidth, &width); n++;
XtGetValues (SelectionBox1, args, n);
UpdateScale (ScaleColumns, col);
UpdateScale (ScaleWidth, width);
XtManageChild(ScaleDialog);
}
static void ApplyToSelectionBox(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
Arg args[1];
int n;
int value;
Widget whichScale;
char **widgetList;
widgetList = (char **) client_data;
while (*widgetList != NULL) {
whichScale = XtNameToWidget(ScaleDialog, *widgetList);
if (whichScale) {
n = 0;
XtSetArg (args[n], XmNvalue, &value); n++;
XtGetValues (whichScale, args, n);
if (strcmp(*widgetList, "ScaleWidth") == 0) {
n = 0;
XtSetArg (args[n], XmNwidth, value); n++;
XtSetValues (SelectionBox1, args, n);
}
else
if (strcmp(*widgetList, "ScaleColumns") == 0) {
n = 0;
XtSetArg (args[n], XmNtextColumns, value); n++;
XtSetValues (SelectionBox1, args, n);
}
} /*if whichScale */
widgetList++;
} /* while */
XtUnmanageChild(XtParent(w));
} /* end routine */
static void noMatchCB(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
char *text;
XmStringGetLtoR(((XmSelectionBoxCallbackStruct *)call_data)->value,
XmSTRING_DEFAULT_CHARSET, &text);
printf("noMatch: %s\n", text);
XtFree(text);
}
static void okCB(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
char *text;
XmStringGetLtoR(((XmSelectionBoxCallbackStruct *)call_data)->value,
XmSTRING_DEFAULT_CHARSET, &text);
printf("ok: %s\n", text);
XtFree(text);
}
static void applyCB(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
char *text;
XmStringGetLtoR(((XmSelectionBoxCallbackStruct *)call_data)->value,
XmSTRING_DEFAULT_CHARSET, &text);
printf("apply: %s\n", text);
XtFree(text);
}
static void cancelCB(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
char *text;
XmStringGetLtoR(((XmSelectionBoxCallbackStruct *)call_data)->value,
XmSTRING_DEFAULT_CHARSET, &text);
printf("cancel: %s\n", text);
XtFree(text);
}
|