A Toggle Widget basically provides a simple switch type of selection. The Toggle is either a square or circle shape indicator which if pressed can be turned on and if pressed again turned off. Text and pictorial items (pixmaps) can be used to label a Toggle .
Several Toggle widgets can be grouped together to allow greater control of selection. Motif provides two methods of grouping Toggles together.
Fig. 15.1 A RadioBox set of Toggle Widgets
Fig. 15.2 A CheckBox set of Toggle Widgets
To create a single Toggle use
XtVaCreateManagedWidget() with a
xmToggleButtonWidgetClass
pointer or use XmCreateToggleButton() .
The header file <Xm/ToggleB.h>
holds definitions etc for this
widget.
Several Toggle Resources are relevant to the programmer:
The Pixmap is a standard X data type. You can use XmGetPixmap() to load in a Pixmap from a file. (See Chapter 16 on Graphics and Xlib for further details.)
Toggle Callbacks have the usual callback function format and are prototyped by:
void toggle_cbk(Widget, XtPointer, XmToggleCallbackStruct *).
Toggle Callbacks are activated upon an XmNvalueChangedCallback. The XmToggleCallbackStruct has a boolean element set that is True if the Toggle is on. The toggle.c (Section 15.3 below) illustrates the use of Toggle callbacks.
This program creates two CheckBox Toggles in a RowColumn Widget. When their Callbacks are activated, the state of the Toggle is interrogated and a message is printed to standard output.
#include <Xm/Xm.h> #include <Xm/ToggleB.h> #include <Xm/RowColumn.h> /* Prototype callback */ void toggle1_cbk(Widget , XtPointer , XmToggleButtonCallbackStruct *), void toggle2_cbk(Widget , XtPointer , XmToggleButtonCallbackStruct *); main(int argc, char **argv) { Widget toplevel, rowcol, toggle1, toggle2; XtAppContext app; toplevel = XtVaAppInitialize(&app, "Toggle", NULL, 0, &argc, argv, NULL, NULL); rowcol = XtVaCreateWidget("rowcol", xmRowColumnWidgetClass, toplevel, XmNwidth, 300, XmNheight, 200, NULL); toggle1 = XtVaCreateManagedWidget("Dolby ON/OFF", xmToggleButtonWidgetClass, rowcol, NULL); XtAddCallback(toggle1, XmNvalueChangedCallback, toggle1_cbk, NULL); toggle2 = XtVaCreateManagedWidget("Dolby B/C", xmToggleButtonWidgetClass, rowcol, NULL); XtAddCallback(toggle2, XmNvalueChangedCallback, toggle2_cbk, NULL); XtManageChild(rowcol); XtRealizeWidget(toplevel); XtAppMainLoop(app); } void toggle1_cbk(Widget widget, XtPointer client_data, XmToggleButtonCallbackStruct *state) { printf("%s: %s\n", XtName(widget), state->set? "on" : "off"); } void toggle2_cbk(Widget widget, XtPointer client_data, XmToggleButtonCallbackStruct *state) { printf("%s: %s\n", XtName(widget), state->set ? "B" : "C"); }
You can, if you wish, group RadioBoxes or CheckBox Toggles in RowColumn, or Forms yourself (as has been done in the above toggle.c program).
However, Motif provides a few convenience functions, XmCreateSimpleRadioBox() and XmCreateSimpleCheckBox() are common examples.
Basically, these are RowColumn Widgets with Toggle children created automatically. Appropriate resources can be set, e.g. XmNindicatorType or XmNradioBehaviour (in this enhanced RowColumn Widget) .
NEED SOME