[comp.sys.amiga] Need Help with Menus

mark@unisec.usi.com (Mark Rinfret) (09/04/87)

I've stumbled up against a problem with menu processing that is most
likely due to my misreading the documentation, but I can't for the
life of me figure out how to correctly process extended menu selection.
According to what I've read, the NextSelect field of the MenuItem gets
you either MENUNULL (0xFFFF) or the next MenuNumber value to be processed.

If you're interested in helping, please read the code fragment below and
tell me what I'm doing wrong else key(n).  The constants for the menu and
item numbers aren't included here, nor are the menu structures themselves.
I assume the problem is in the following code and not the structures since
everything else appears to work correctly.  Thanks for your time.

Mark
--------------------------------------------------------------------------
/* Handle a menu selection. 
 * Called with:
 *		xcode:		menu selection code
 * Returns:
 *		status code (1 => Quit was selected)
 */

int
UserMenu(xcode)
	USHORT xcode;
{
	USHORT code = xcode;	/* copied to local since it will change */
	struct MenuItem *item;
	USHORT itemnum,menunum;

	while (code != MENUNULL) {

		menunum = MENUNUM(code);
		itemnum = ITEMNUM(code);
#ifdef DEBUG
		sprintf(debugmsg,"menu = %d, item = %d\n",menunum,itemnum);
		DebugWrite(debugmsg);
#endif
		item = ItemAddress(&Titles[0], code);
		if (!item) {				/* temp DEBUG stuff */
			WriteConsole("Null item returned from ItemAddress!\n");
			return;
		}
		switch (menunum) {
		case MENU_PROJECT:			/* Project Menu */
			switch (itemnum) {
			case ITEM_BACKUP:		/* Backup */
				Backup();
				break;
			case ITEM_RESTORE:		/* Restore */
				Restore();
				break;
			case ITEM_ABOUT:		/* About */
				About();
				break;
			case ITEM_QUIT:			/* Quit */
				return 1;			
			default:
				DisplayBeep(NULL);
				break;
			}
			break;

		case MENU_FLAGS:			/* Flags Menu */
			switch (itemnum) {
			case ITEM_COMPRESS:		/* Compression */
				do_compress = IsChecked(item); 
				break;
			case ITEM_NOCOMPRESS:	/* No Compression */
				do_compress = !IsChecked(item);
				break;
			case ITEM_LIST:			/* Listing */
				do_listing = IsChecked(item);
				break;
			case ITEM_NOLIST:		/* No Listing */
				do_listing = !IsChecked(item);
				break;
			case ITEM_SPEECH:		/* Speech */
				do_speech = IsChecked(item);
				SetSpeech();
				break;
			case ITEM_NOSPEECH:		/* No Speech */
				do_speech = !IsChecked(item);
				SetSpeech();
				break;
			default:
				DisplayBeep(NULL);
				break;
			}
		}
		code = item->NextSelect; 
		/* This next line is a kludge.  Testing has revealed that
		 * the NextSelect field is returning 0000x.  Why?
		 */
		if (!code) break;
	}
	return 0;
}

-- 
| Mark R. Rinfret, SofTech, Inc.		mark@unisec.usi.com |
| Guest of UniSecure Systems, Inc., Newport, RI                     |
| UUCP:  {gatech|mirror|cbosgd|uiucdcs|ihnp4}!rayssd!unisec!mark    |
| work: (401)-849-4174	home: (401)-846-7639                        |