7
#include <Xm/MessageB.h>
9
#include <Xm/ToggleB.h>
14
#include <Xm/RowColumn.h>
15
#include <Xm/MenuShell.h>
16
#include <Xm/ButtonBox.h>
20
void Exit(Widget w, XtPointer client, XtPointer call);
21
void Equal(Widget w, XtPointer client, XtPointer call);
22
void Fill(Widget w, XtPointer client, XtPointer call);
23
void Width(Widget w, XtPointer client, XtPointer call);
24
void OnlyNum(Widget w, XtPointer client, XtPointer call);
25
void Orient(Widget w, XtPointer client, XtPointer call);
26
void Explain(Widget w, XtPointer client, XtPointer call);
30
* These are fallbacks that are designed to ensure the
31
* program works properly in case the resource file is
36
static String fallbacks[] = {
38
* General fallback resources.
42
"*bbox*background: white",
46
"*fontList: -*-helvetica-medium-r-*-*-*-140-*-*-*-*-*-*",
47
"*infolabel*fontList: -*-helvetica-bold-r-*-*-*-140-*-*-*-*-*-*",
48
"*infolabel.marginWidth: 10",
49
"*infolabel.marginHeight: 10",
50
"*boxSizeLabel.labelString: XmNequalSize",
51
"*fillOptionLabel.labelString: XmNfillOption",
52
"*widLabel.labelString: XmNmarginWidth",
53
"*htLabel.labelString: XmNmarginHeight",
54
"*orientLabel.labelString: XmNorientation",
55
"*toggle1.labelString: True",
56
"*toggle2.labelString: False",
57
"*toggle3.labelString: XmHORIZONTAL",
58
"*toggle4.labelString: XmVERTICAL",
59
"*resform*XmPushButton.labelString: Explain...",
60
"*resform*pulldownMenu.nonePB.labelString: XmFillNone",
61
"*resform*pulldownMenu.minorPB.labelString: XmFillMinor",
62
"*resform*pulldownMenu.majorPB.labelString: XmFillMajor",
63
"*resform*pulldownMenu.allPB.labelString: XmFillAll",
64
"*quitPB.labelString: Quit",
68
void Exit(Widget w, XtPointer client, XtPointer call)
75
* This function forces the buttons to be of equal size.
79
void Equal(Widget w, XtPointer client, XtPointer call)
91
XtSetArg(args[argcnt], XmNequalSize, equal); argcnt++;
92
XtSetValues(bbox, args, argcnt);
98
* This function forces the margins along the sides (width)
99
* or along the top and bottom (height) to be of a particular
104
void Width(Widget w, XtPointer client, XtPointer call)
111
val = XmTextFieldGetString(w);
115
if ((int)client == 1)
117
XtSetArg(args[argcnt], XmNmarginHeight, (short) margin); argcnt++;
121
XtSetArg(args[argcnt], XmNmarginWidth, (short) margin); argcnt++;
123
XtSetValues(bbox, args, argcnt);
130
* Depending on the resource, the buttons either fill the box
131
* along the minor axis (minor), the major axis (major), neither (none)
132
* or completely fill the box (all).
136
void Fill(Widget w, XtPointer client, XtPointer call)
140
int val = (int)client;
145
XtSetArg(args[argcnt], XmNfillOption, XmFillNone); argcnt++;
146
XtSetValues(bbox, args, argcnt);
149
XtSetArg(args[argcnt], XmNfillOption, XmFillMinor); argcnt++;
150
XtSetValues(bbox, args, argcnt);
153
XtSetArg(args[argcnt], XmNfillOption, XmFillMajor); argcnt++;
154
XtSetValues(bbox, args, argcnt);
157
XtSetArg(args[argcnt], XmNfillOption, XmFillAll); argcnt++;
158
XtSetValues(bbox, args, argcnt);
164
* Validation of input.
166
* A common routine to ensure that the only values entered
167
* in the text box are all numeric.
171
void OnlyNum(Widget w, XtPointer client, XtPointer call)
173
XmTextVerifyCallbackStruct *verify_struct =
174
(XmTextVerifyCallbackStruct *) call;
176
if (verify_struct->text->ptr)
177
if (!isdigit(*verify_struct->text->ptr))
178
verify_struct->doit = False;
183
* Specifies the orientation of the buttons in the box.
187
void Orient(Widget w, XtPointer client, XtPointer call)
191
unsigned char orient;
193
if ((int)client == 1)
196
orient = XmHORIZONTAL;
199
XtSetArg(args[argcnt], XmNorientation, orient); argcnt++;
200
XtSetValues(bbox, args, argcnt);
207
* Stuff needed for the demo program to output info
211
void Explain(Widget w, XtPointer client, XtPointer call)
215
XmString xmstring = NULL;
216
static Widget info = NULL;
217
int explain = (int) client;
223
XtSetArg(args[argcnt], XmNtitle, "Explanation"); argcnt++;
224
info = XmCreateInformationDialog(w, "explain", args, argcnt);
226
temp = XmMessageBoxGetChild(info, XmDIALOG_CANCEL_BUTTON);
227
XtUnmanageChild(temp);
228
temp = XmMessageBoxGetChild(info, XmDIALOG_HELP_BUTTON);
229
XtUnmanageChild(temp);
234
xmstring = XmStringCreateLtoR(
235
"The equalSize resource specifies whether children of the Button\n\
236
Box have equal heights and widths. The height and width chosen for\n\
237
all the children is the height and width of the largest child.",
238
XmSTRING_DEFAULT_CHARSET);
241
xmstring = XmStringCreateLtoR(
242
"The fillOption resource sets four kinds of fill options: FillNone,\n\
243
FillMajor, FillMinor, and FillAll. Fill specifies how to use any extra\n\
244
space left over once all children have been sized. This resource usually\n\
245
expands children in a reasonable manner.\n\
247
FillMajor expands children in the direction of the orientation resource.\n\
248
FillMinor expands children in the opposite direction of the orientation \
250
FillAll expands children in both major and minor directions.\n\
251
FillNone doesn't expand children.",
252
XmSTRING_DEFAULT_CHARSET);
255
xmstring = XmStringCreateLtoR(
256
"marginWidth is the number of spacing pixels to the left and to the right\n\
257
of the children in the Button Box.",
258
XmSTRING_DEFAULT_CHARSET);
261
xmstring = XmStringCreateLtoR(
262
"marginHeight is the number of spacing pixels on top and on bottom of the \n\
263
children in the Button Box.",
264
XmSTRING_DEFAULT_CHARSET);
267
xmstring = XmStringCreateLtoR(
268
"orientation specifies whether the children of the Button Box are placed\n\
269
in a row or a column. HORIZONTAL places children in a row (major dimension\n\
270
is width, minor dimension is height). VERTICAL places children in a column\n\
271
(major dimension is height, minor dimension is width).",
272
XmSTRING_DEFAULT_CHARSET);
275
printf("explaining NOTHING\n");
280
XtSetArg(args[argcnt], XmNmessageString, xmstring); argcnt++;
281
XtSetValues(info, args, argcnt);
283
XmStringFree(xmstring);
288
main(int argc, char **argv)
292
Widget top, bboxframe, infoframe, infolabel, resframe, resform,
293
bboxSizeRC, boxSizeLabel, togl_btn1, togl_btn2, pushButton, radioRC,
294
fillOptionRC, fillOptionLabel, fillOptionMenu, nonePB, minorPB,
295
majorPB, allPB, menuShell, pulldownMenu, pushButton1,widRC,
296
widLabel, widText, htRC, htLabel, htText, pushButton2, orientRC,
297
orientLabel, pushButton3, pushButton4, quitPB, bbox_PB1, bbox_PB2,
298
bbox_PB3, bbox_PB4, togl_btn3, togl_btn4, orientRadio, bform;
304
XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL);
307
XtSetArg(args[argcnt], XmNtitle, "Button Box Demo"); argcnt++;
308
XtSetArg(args[argcnt], XmNallowShellResize, True); argcnt++;
309
top = XtOpenApplication(
317
sessionShellWidgetClass,
321
bform = XtVaCreateManagedWidget("bform", xmFormWidgetClass, top,
322
XmNresizePolicy, XmRESIZE_GROW, NULL);
324
bboxframe = XtVaCreateManagedWidget("bboxframe", xmFrameWidgetClass,bform,
325
XmNtopAttachment, XmATTACH_FORM,
326
XmNbottomAttachment, XmATTACH_FORM,
333
Widget dbbox = XmCreateFormDialog(top,"frame",NULL,0);
339
* Creation of the widget being demoed.
343
bbox = XtVaCreateManagedWidget("bbox",
344
xmButtonBoxWidgetClass, dbbox,
349
XmNleftAttachment, XmATTACH_FORM,
350
XmNrightAttachment, XmATTACH_FORM,
351
XmNtopAttachment, XmATTACH_FORM,
352
XmNbottomAttachment, XmATTACH_FORM,
354
XtManageChild(dbbox);
359
* The following widgets created are buttons to fill the box.
360
* This is to assist in the demonstration of the buttonBox's
365
bbox_PB1 = XmVaCreateManagedPushButton(bbox, "FirstButton",
368
bbox_PB2 = XmVaCreateManagedPushButton(bbox, "SecondButton",
371
bbox_PB3 = XmVaCreateManagedPushButton(bbox, "ThirdButton",
374
bbox_PB4 = XtCreateManagedWidget("LastButton",
375
xmPushButtonWidgetClass,
380
xmstring = XmStringCreateLtoR(
381
"The OpenMotif Button Box widget can arrange buttons into single rows and columns\n\
382
much more easily than the Motif Row Column or Motif Form!\n\
383
(And two ButtonBoxes paired together do a great job of lining items up.)\n\
385
The four buttons in the other window are inside an OpenMotif Button Box. Try \
387
this window! Try modifying the Button Box's resources using the area below.\n\
389
Press the \"Explain...\" button to find out more about a particular resource.",
390
XmSTRING_DEFAULT_CHARSET);
392
infoframe = XtVaCreateManagedWidget("infoframe", xmFrameWidgetClass, bform,
393
XmNbottomAttachment, XmATTACH_NONE,
394
XmNrightAttachment, XmATTACH_POSITION,
395
XmNrightPosition, 95,
399
XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
400
XmNtopWidget, bboxframe,
401
XmNleftAttachment, XmATTACH_WIDGET,
402
XmNleftWidget, bboxframe,
405
resframe = XtVaCreateManagedWidget("resframe", xmFrameWidgetClass, bform,
406
XmNbottomAttachment, XmATTACH_NONE,
407
XmNrightAttachment, XmATTACH_POSITION,
408
XmNrightPosition, 95,
412
XmNtopAttachment, XmATTACH_WIDGET,
413
XmNtopWidget, infoframe,
414
XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
415
XmNleftWidget, infoframe,
418
quitPB = XmVaCreatePushButton(bform, "quitPB",
419
XmNtopAttachment, XmATTACH_NONE,
420
XmNleftAttachment, XmATTACH_WIDGET,
421
XmNleftWidget, bboxframe,
422
XmNbottomAttachment, XmATTACH_FORM,
428
XtManageChild(quitPB);
430
infolabel = XtVaCreateManagedWidget("infolabel", xmLabelWidgetClass,
433
XmNalignment, XmALIGNMENT_BEGINNING,
434
XmNlabelString, xmstring,
438
resform = XtVaCreateManagedWidget("resform", xmFormWidgetClass, resframe,
439
XmNresizePolicy, XmRESIZE_GROW, NULL);
441
bboxSizeRC = XtVaCreateManagedWidget("bboxSizeRC", xmRowColumnWidgetClass,
443
XmNorientation, XmHORIZONTAL,
444
XmNpacking, XmPACK_TIGHT,
445
XmNtopAttachment, XmATTACH_FORM,
446
XmNleftAttachment, XmATTACH_FORM,
447
XmNrightAttachment, XmATTACH_NONE,
450
XmNrowColumnType, XmWORK_AREA,
453
fillOptionRC = XtVaCreateManagedWidget("fillOptionRC",
454
xmRowColumnWidgetClass, resform,
455
XmNorientation, XmHORIZONTAL,
456
XmNpacking, XmPACK_TIGHT,
457
XmNbottomAttachment, XmATTACH_NONE,
458
XmNleftAttachment, XmATTACH_FORM,
462
XmNrowColumnType, XmWORK_AREA,
463
XmNtopAttachment, XmATTACH_WIDGET,
464
XmNtopWidget, bboxSizeRC,
467
widRC = XtVaCreateManagedWidget("widRC", xmRowColumnWidgetClass, resform,
468
XmNorientation, XmHORIZONTAL,
469
XmNtopAttachment, XmATTACH_WIDGET,
470
XmNtopWidget, fillOptionRC,
471
XmNpacking, XmPACK_TIGHT,
472
XmNbottomAttachment, XmATTACH_NONE,
473
XmNleftAttachment, XmATTACH_FORM,
477
XmNrowColumnType, XmWORK_AREA,
480
htRC = XtVaCreateManagedWidget("htRC", xmRowColumnWidgetClass, resform,
481
XmNorientation, XmHORIZONTAL,
482
XmNtopAttachment, XmATTACH_WIDGET,
484
XmNpacking, XmPACK_TIGHT,
485
XmNbottomAttachment, XmATTACH_NONE,
486
XmNleftAttachment, XmATTACH_FORM,
490
XmNrowColumnType, XmWORK_AREA,
493
orientRC = XtVaCreateManagedWidget("orientRC", xmRowColumnWidgetClass,
495
XmNtopAttachment, XmATTACH_WIDGET,
497
XmNorientation, XmHORIZONTAL,
498
XmNpacking, XmPACK_TIGHT,
499
XmNbottomAttachment, XmATTACH_NONE,
500
XmNleftAttachment, XmATTACH_FORM,
504
XmNrowColumnType, XmWORK_AREA,
507
boxSizeLabel = XtVaCreateManagedWidget("boxSizeLabel", xmLabelWidgetClass,
513
XtSetArg(args[argcnt], XmNx, 82); argcnt++;
514
XtSetArg(args[argcnt], XmNy, 3); argcnt++;
515
XtSetArg(args[argcnt], XmNorientation, XmHORIZONTAL); argcnt++;
516
radioRC = XmCreateRadioBox(bboxSizeRC,"radioRC", args, argcnt);
518
togl_btn1 = XtVaCreateManagedWidget("toggle1", xmToggleButtonWidgetClass,
521
togl_btn2 = XtVaCreateManagedWidget("toggle2", xmToggleButtonWidgetClass,
524
XtManageChild(radioRC);
526
pushButton = XtVaCreateManagedWidget("pushButton",
527
xmPushButtonWidgetClass, bboxSizeRC,
531
fillOptionLabel = XtVaCreateManagedWidget("fillOptionLabel",
532
xmLabelWidgetClass, fillOptionRC,
537
XtSetArg(args[argcnt], XmNx, 100); argcnt++;
538
XtSetArg(args[argcnt], XmNy, 3); argcnt++;
539
fillOptionMenu = XmCreateOptionMenu(fillOptionRC, "fillOptionMenu",
541
XtManageChild(fillOptionMenu);
544
XtSetArg(args[argcnt], XmNwidth, 1); argcnt++;
545
XtSetArg(args[argcnt], XmNheight, 1); argcnt++;
546
menuShell = XtCreatePopupShell("menuShell", xmMenuShellWidgetClass,
547
fillOptionRC, args, argcnt);
550
XtSetArg(args[argcnt], XmNrowColumnType, XmMENU_PULLDOWN); argcnt++;
551
XtSetArg(args[argcnt], XmNx, 0); argcnt++;
552
XtSetArg(args[argcnt], XmNy, 0); argcnt++;
553
XtSetArg(args[argcnt], XmNwidth, 54); argcnt++;
554
XtSetArg(args[argcnt], XmNheight, 88); argcnt++;
555
pulldownMenu = XtCreateWidget("pulldownMenu", xmRowColumnWidgetClass,
556
menuShell, args, argcnt);
558
nonePB = XtVaCreateManagedWidget("nonePB", xmPushButtonWidgetClass,
561
minorPB = XtVaCreateManagedWidget("minorPB", xmPushButtonWidgetClass,
564
majorPB = XtVaCreateManagedWidget("majorPB", xmPushButtonWidgetClass,
567
allPB = XtVaCreateManagedWidget("allPB", xmPushButtonWidgetClass,
571
XtSetArg(args[argcnt], XmNsubMenuId, pulldownMenu); argcnt++;
572
XtSetValues(fillOptionMenu, args, argcnt);
574
pushButton1 = XtVaCreateManagedWidget("pushButton1",
575
xmPushButtonWidgetClass, fillOptionRC,
579
widLabel = XtVaCreateManagedWidget("widLabel", xmLabelWidgetClass, widRC,
583
widText = XtVaCreateManagedWidget("widText", xmTextFieldWidgetClass,
584
widRC, XmNx, 76, XmNy, 3, NULL);
586
pushButton2 = XtVaCreateManagedWidget("pushButton2",
587
xmPushButtonWidgetClass, widRC,
591
htLabel = XtVaCreateManagedWidget("htLabel", xmLabelWidgetClass, htRC,
595
htText = XtVaCreateManagedWidget("htText", xmTextFieldWidgetClass,
596
htRC, XmNx, 76, XmNy, 3, NULL);
598
pushButton3 = XtVaCreateManagedWidget("pushButton3",
599
xmPushButtonWidgetClass, htRC,
603
orientLabel = XtVaCreateManagedWidget("orientLabel", xmLabelWidgetClass,
609
XtSetArg(args[argcnt], XmNx, 82); argcnt++;
610
XtSetArg(args[argcnt], XmNy, 3); argcnt++;
611
XtSetArg(args[argcnt], XmNorientation, XmHORIZONTAL); argcnt++;
612
orientRadio = XmCreateRadioBox(orientRC,"orientRadio", args, argcnt);
614
togl_btn3 = XtVaCreateManagedWidget("toggle3", xmToggleButtonWidgetClass,
617
togl_btn4 = XtVaCreateManagedWidget("toggle4", xmToggleButtonWidgetClass,
621
unsigned char orientation;
622
XtVaGetValues(bbox, XmNorientation, &orientation, NULL);
623
if (XmHORIZONTAL == orientation)
624
XmToggleButtonSetState(togl_btn3, True, False);
626
XmToggleButtonSetState(togl_btn4, True, False);
629
XtManageChild(orientRadio);
631
pushButton4 = XtVaCreateManagedWidget("pushButton4",
632
xmPushButtonWidgetClass, orientRC,
636
XtAddCallback(quitPB, XmNactivateCallback, Exit, (XtPointer)0);
638
XtAddCallback(pushButton, XmNactivateCallback, Explain, (XtPointer)1);
640
XtAddCallback(pushButton1, XmNactivateCallback, Explain, (XtPointer)2);
642
XtAddCallback(pushButton2, XmNactivateCallback, Explain, (XtPointer)3);
644
XtAddCallback(pushButton3, XmNactivateCallback, Explain, (XtPointer)4);
646
XtAddCallback(pushButton4, XmNactivateCallback, Explain, (XtPointer)5);
648
XtAddCallback(togl_btn1, XmNvalueChangedCallback, Equal, (XtPointer)1);
650
XtAddCallback(togl_btn2, XmNvalueChangedCallback, Equal, (XtPointer)0);
652
XtAddCallback(nonePB, XmNactivateCallback, Fill, (XtPointer)1);
654
XtAddCallback(minorPB, XmNactivateCallback, Fill, (XtPointer)2);
656
XtAddCallback(majorPB, XmNactivateCallback, Fill, (XtPointer)3);
658
XtAddCallback(allPB, XmNactivateCallback, Fill, (XtPointer)4);
660
XtAddCallback(htText, XmNactivateCallback, Width, (XtPointer)1);
661
XtAddCallback(htText, XmNmodifyVerifyCallback, OnlyNum, (XtPointer)0);
663
XtAddCallback(widText, XmNactivateCallback, Width, (XtPointer)0);
664
XtAddCallback(widText, XmNmodifyVerifyCallback, OnlyNum, (XtPointer)0);
666
XtAddCallback(togl_btn4, XmNvalueChangedCallback, Orient, (XtPointer)1);
668
XtAddCallback(togl_btn3, XmNvalueChangedCallback, Orient, (XtPointer)0);
670
XtRealizeWidget(top);
674
/* appease compiler warning god */