PackIt pitmenu.c

/*
				PackIt menu handling code

	This file contains all the code for handling the menus used by PackIt.

	© Copyright 1986 by Harry R. Chesley.
	All rights reserved.
*/

#include <quickdraw.h>
#include <menu.h>
#include <desk.h>
#include <toolutil.h>

#define NMENU 2				/* Number of menus. */

MenuHandle myMenu[NMENU];	/* Handles for my menus. */

/* Resource/menu IDs for my menus: */

#define APPLEMENU 256
#define FILEMENU 257

#define FILEINDX 1	/* Index into myMenu[]. */

/* Apple (accessory) menu items: */
#define APPLEABOUT 1

/* File menu items: */
#define FILEPACK 1
#define FILEUNPACK 2
#define FILESETP 4
#define FILEDEL 6
#define FILEHELP 8
#define FILEQUIT 10

/* Globals: */

int quit;		/* TRUE if time to give it up. */

/*	menuSetUp()

	Function: Set up the menu control structures, and display the menus.

	Algorithm: Call NewMenu()/AppendMenu() for each menu, including the accessories menu. Then
	call InsertMenu() for each. Finally, call DrawMenuBar() to do the displaying.

	Comments: We should, perhaps, also have an Edit menu, in case people want to use it with the
	desk accessories...
*/

menuSetUp()

{
	register int i;

	/* Init the toolbox menu code. */
	InitMenus();

	/* Prep the Apple (accessories) menu. */
	myMenu[0] = GetMenu(APPLEMENU);
	AddResMenu(myMenu[0],'DRVR');

	/* Prep the File menu. */
	myMenu[1] = GetMenu(FILEMENU);

	/* Now insert them into the menu list. */
	for (i = 0; i < NMENU; i++) InsertMenu(myMenu[i],0);

	/* And display them. */
	DrawMenuBar();
}

/*	doCommand(cmd)

	Function: Handle a menu or keyboard command. cmd is the result of either SelectMenu() or
	MenuKey(); i.e., the menu number is in the hi word and the item within the menu is in the low
	word.

	Algorithm: Switch on the menu, switch on the item, and do whatever is requested.

	Comments: None.
*/

doCommand(cmd)

long cmd;

{
	register int whichMenu, whichItem;
	char name[40];

	/* Decode cmd. */
	whichMenu = HiWord(cmd); whichItem = LoWord(cmd);

	/* Switch on the menu. */
	switch (whichMenu) {

		case APPLEMENU:
			/* Either "About..." or accessory. */
			if (whichItem == APPLEABOUT) displayAbout();
			else {
				/* Get the accessory name & open it. */
				GetItem(myMenu[0],whichItem,name);
				OpenDeskAcc(name);
			};
			break;

		case FILEMENU:
			/* Switch on item. */
			switch (whichItem) {
				case FILEPACK:
					packFile();
					break;
				case FILEUNPACK:
					unpackFile();
					break;
				case FILESETP:
					setPassword();
					break;
				case FILEDEL:
					deleteFile();
					break;
				case FILEHELP:
					displayHelp();
					break;
				case FILEQUIT:
					quit = TRUE;
					break;
			};
			break;
	};

	/* Turn off menu hi-lighting. */
	HiliteMenu(0);
}