Michael B. Williams wrote:

> 1.) Why is this call for "Check Toggles" XtVaCreateManagedWidget the
> size of the dialog?


It's because the rowcol widget lays all its rows out with the left and right
margins specified by the marginWidth resource. This causes it to stretch
the push-button to nearly the width of the dialog. One way around this is
to use a form inside the rowcol widget to hold the push-button: here is how
you could do it to have the push-button centred and occupying about 20% of
the width:

form_w = XtVaCreateManagedWidget("form",
xmFormWidgetClass, rowcol,
XmNfractionBase, 100, NULL);

w = XtVaCreateManagedWidget ("Check Toggles",
xmPushButtonGadgetClass, form_w,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_POSITION,
XmNleftPosition, 40,
XmNrightAttachment, XmATTACH_POSITION,
XmNrightPosition, 60,
NULL);

(after including Xm/XmForm.h and declaring the widget form_w).

>
> 2.) How can I draw frame around the text ( ie the radio buttons
> created from TestNames)?


You can put a frame around each toggle button (including the text) by
changing the body of the loop that creates them to read:

{
frame_w = XtVaCreateManagedWidget (TestNames[i],
xmFrameWidgetClass, toggle_box, NULL);
w = XtVaCreateManagedWidget (TestNames[i],
xmToggleButtonGadgetClass, frame_w, NULL);
}

(after including Xm/XmFrame.h and declaring the widget frame_w).

However, if you want radio box functionality (exactly one toggle set at any
time), you'd have to implement that yourself in your callback, if you put
the toggle buttons inside frames.

>
>
> 3.) Is there an application that can generate this type of code for
> me?


You could check out UIL, perhaps?

Regards,

Rob Arthan.

>
> Thanks in advance
>
>
> Michael
>
>
> /* program below*/
>
> #include
> #include
> #include
> #include
>
> #include
>
> unsigned long toggles_set; /* has the bits of which toggles are set */
>
> char *TestNames[] = {
> "Some tests With the name One in it",
> "Some tests With the name Two in it",
> "Some tests With the name Three in it",
> "Some tests With the name Four in it ",
> "Some tests With the name Five in it",
> "Some tests With the name Six in it",
> "Some tests With the name Seven in it",
> "Some tests With the name Eight in it",
> "Some tests With the name Nine in it",
> "Some tests With the name Ten in it",
> };
>
> /* A RowColumn is used to manage a ToggleBox (also a RowColumn) and
> * a PushButton with a separator gadget in between.
> */
> main(argc, argv)
> int argc;
> char *argv[];
> {
> Widget toplevel, rowcol, toggle_box, w;
> XtAppContext app;
> void toggled(), check_bits();
> int i;
>
> XtSetLanguageProc (NULL, NULL, NULL);
>
> toplevel = XtVaAppInitialize (
> &app,
> "The Name of my app",
> NULL,
> 0,
> &argc,
> argv,
> NULL,
> NULL);
>
> // Set the Title to something I want it to be
> XtVaSetValues(toplevel, XmNtitle, "Michael", NULL);
>
> rowcol = XtVaCreateManagedWidget ("rowcolumn",
> xmRowColumnWidgetClass, toplevel,
> NULL);
>
> toggle_box = XtVaCreateWidget ("System STE",
> xmRowColumnWidgetClass, rowcol,
> XmNpacking, XmPACK_COLUMN,
> XmNnumColumns, 3,
> NULL);
>
> // Why doesn't this come above the
> XtVaCreateManagedWidget ("sep",
> xmSeparatorGadgetClass, rowcol, NULL);
>
> /* simply loop thru the strings creating a widget for each one */
> for (i = 0; i < XtNumber (TestNames); i++) {
> w = XtVaCreateManagedWidget (TestNames[i],
> xmToggleButtonGadgetClass, toggle_box, NULL);
> XtAddCallback (w, XmNvalueChangedCallback, toggled, i);
> }
>
> XtVaCreateManagedWidget ("sep",
> xmSeparatorGadgetClass, rowcol, NULL);
>
> w = XtVaCreateManagedWidget ("Check Toggles",
> xmPushButtonGadgetClass, rowcol, NULL);
> XtAddCallback (w, XmNactivateCallback, check_bits, NULL);
>
> XtManageChild (rowcol);
> XtManageChild (toggle_box);
>
> XtRealizeWidget (toplevel);
> XtAppMainLoop (app);
>
> }
>
> /* callback for all ToggleButtons. */
> void
> toggled(widget, client_data, call_data)
> Widget widget;
> XtPointer client_data;
> XtPointer call_data;
> {
> int bit = (int) client_data;
> XmToggleButtonCallbackStruct *toggle_data =
> (XmToggleButtonCallbackStruct *) call_data;
>
> if (toggle_data->set) /* if the toggle button is set, flip its bit
> */
> toggles_set |= (1 << bit);
> else /* if the toggle is "off", turn off the bit. */
> toggles_set &= ~(1 << bit);
> }
>
> void
> check_bits(widget, client_data, call_data)
> Widget widget;
> XtPointer client_data;
> XtPointer call_data;
> {
> int i;
>
> printf ("Toggles set:");
> for (i = 0; i < XtNumber (TestNames); i++)
> if (toggles_set & (1< > printf (" %s\n", TestNames[i]);
> putchar ('\n');