/** $Id: Menuradio.c,v 1.1 1997/05/01 15:22:11 archer Exp $
 **	MENURADIO.C - Manage radio (i.e. checklists) menus
 **/
#include <Widget/MenuItemP.h>


/**
 ** X11_MENU_ITEM_RADIO_CHECK
 **	This menu item is checked. All others are now unchecked
 **/
void X11_MenuItemRadioCheck(X11_widget wdg)
{
X11_widget	menu;
/*
 * Uncheck all items
 */
	for (menu = wdg->parent->child; menu; menu = menu->sibling)
		if (menu != wdg && strcmp(menu->class, x11__menuitem_class) == 0)
			X11_MenuItemCheck(menu, False);
	X11_MenuItemCheck(wdg, True);
}


/**
 ** X11_MENU_ITEM_RADIO
 **	Fills the menu with items
 **/
void X11_MenuItemRadio(X11_widget menu, char **titles, char *keys, int first,
						X11_int_call call, void *data)
{
X11_widget	wdg;
int		i;
char		name[16];
/*
 * Creation
 */
	if (!keys)
		keys = "";
/*
 * Loop on all titles
 */
	for (i = 0; *titles; i++) {
		snprintf(name, sizeof(name), "radio%d", i);
		wdg = X11_MenuItem(menu, name, *titles, *keys, 0, data);
		X11_MenuItemCheck(wdg, (i == first) ? True : False);
		W_MENUITEM->callback = call;
/*
 * Next item
 */
		if (*keys)
			keys++;
		titles++;
	}
}
