#include <Xm/Xm.h>
#include <Xm/ToggleB.h>
#include <Xm/ToggleBG.h>

/*
 *	Maintains the radio behavior of the toggle buttons within
 *	a non-XmRowColumn manager widget.
 *	This callback is intended as the XmNvalueChangedCallback
 *	on every toggle button in the manager.
 */
/*ARGSUSED*/
void EnforceRadioBehaviorCB(Widget toggle, XtPointer tag, XtPointer data)
{
    WidgetList	children;
    Cardinal	num_children;
    int		i;
    
    /*
     *	Always set the calling toggle button to true in case the toggle
     *	was clicked on while already set.  Don't notify, or we will spin
     *	in an infinite loop.
     */
    XmToggleButtonSetState(toggle, True, False);
    
    /* fetch all of the toggle's siblings */
    XtVaGetValues(XtParent(toggle),
		  XmNchildren, &children,
		  XmNnumChildren, &num_children,
		  NULL);
    
    /* search the list of children for toggles and turn them off */
    for(i=0; i < num_children; i++)
	if ((children[i] != toggle) &&
	    (XmIsToggleButton(children[i]) ||
	     XmIsToggleButtonGadget(children[i])))
	    XmToggleButtonSetState(children[i], False, False);
}
