/*
 *	Example code to demonstrate enforcing radioBox style behavior in a
 *	non-XmRowColumn manager.
 *
 *	Note:  This code is hereby contributed to the public domain.
 *	Author:	Greg Ullmann
 */
#include <stdio.h>
#include <Xm/Form.h>
#include <Xm/PushB.h>
#include <Xm/ToggleB.h>
#include <Xm/ToggleBG.h>

extern void EnforceRadioBehaviorCB(Widget, XtPointer, XtPointer);

/*
 *	Let's get out of here...
 */
/*ARGSUSED*/
void
quit(Widget w, XtPointer clientData, XtPointer callData)
{
	exit(0);
}

/*
 *	A dummy example to show how to use the radioCB callback for toggles
 *	that are children of another manager besides a XmRowColumn widget.
 */
int
main(int ac, char **av)
{
	XtAppContext	appCtxt;
	Widget	topLevel;
	Widget	form;
	Widget	pb;
	Widget	toggle1;
	Widget	toggle2;
	Widget	toggle3;

	/* toplevel shell */
	topLevel = XtAppInitialize(&appCtxt, "Radio", NULL, 0, &ac, av, NULL, NULL, 0);

	/* form manager */
	form = XmCreateForm(topLevel, "form", NULL, 0);

	/* create some toggle buttons and gadgets */
	toggle1 = XmCreateToggleButton(form, "animal", NULL, 0);
	XtVaSetValues(toggle1,
				  XmNindicatorType, XmONE_OF_MANY,
				  NULL);

	toggle2 = XmCreateToggleButtonGadget(form, "vegetable", NULL, 0);
	XtVaSetValues(toggle2,
				  XmNindicatorType, XmONE_OF_MANY,
				  XmNleftAttachment, XmATTACH_WIDGET,
				  XmNleftWidget, toggle1,
				  NULL);

	toggle3 = XmCreateToggleButton(form, "mineral", NULL, 0);
	XtVaSetValues(toggle3,
				  XmNindicatorType, XmONE_OF_MANY,
				  XmNleftAttachment, XmATTACH_WIDGET,
				  XmNleftWidget, toggle2,
				  NULL);

	/*
	 *	Allow a means to quit and to show that other widget can be managed
	 *	and remain unaffected by the radioCB.
	 */
	pb = XmCreatePushButton(form, "quit", NULL, 0);
	XtVaSetValues(pb,
				  XmNtopAttachment, XmATTACH_WIDGET,
				  XmNtopWidget, toggle2,
				  XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
				  XmNleftWidget, toggle2,
				  NULL);
	XtAddCallback(pb, XmNactivateCallback, quit, NULL);

	/* set the first toggle */
	XmToggleButtonSetState(toggle1, True, True);

	/* add the radioCB to all sibling toggle buttons */
	XtAddCallback(toggle1, XmNvalueChangedCallback, 
		      EnforceRadioBehaviorCB, NULL);
	XtAddCallback(toggle2, XmNvalueChangedCallback, 
		      EnforceRadioBehaviorCB, NULL);
	XtAddCallback(toggle3, XmNvalueChangedCallback, 
		      EnforceRadioBehaviorCB, NULL);

	/* manage and go... */
	XtManageChild(toggle1);
	XtManageChild(toggle2);
	XtManageChild(toggle3);
	XtManageChild(pb);
	XtManageChild(form);

	XtRealizeWidget(topLevel);

	XtAppMainLoop(appCtxt);

	/*NOTREACHED*/
}
