pendulum68k/pendMenu.c

1 line
2.5 KiB
C

#include "pendMenu.h"
#include "common.h"
#include "pendDialog.h"
#define GET_MENU(mid) menus[(mid)-1]
extern struct dialog_prefs_t pendPrefs;
enum {
appleID=1,
fileID,
editID,
endID
};
enum {
apple_AboutID=1,
apple_EndID
};
enum {
file_RandID=1,
file_RstID=3,
file_QuitID
};
enum {
edit_UndoID=1,
edit_CutID=3,
edit_CopyID,
edit_PasteID,
edit_ClearID,
edit_PrefsID=8
};
extern Boolean resetting, running;
static MenuHandle menus[endID-1];
static void DoAboutMenu(int item);
static void DoFileMenu(int item);
static void DoEditMenu(int item);
void MenuCreate(void) {
int i;
menus[0] = NewMenu(appleID, "\p\024");
menus[1] = NewMenu(fileID, "\pFile");
menus[2] = NewMenu(editID, "\pEdit");
for(i = appleID; i < endID; ++i) {
InsertMenu(GET_MENU(i), 0);
}
DrawMenuBar();
AppendMenu(GET_MENU(appleID), "\pAbout Pendulum...;(-");
AddResMenu(GET_MENU(appleID), 'DRVR');
AppendMenu(GET_MENU(fileID), "\p(Random;(-;Restart/R;Quit/Q");
AppendMenu(GET_MENU(editID),
"\p(Undo/Z;(-;(Cut/X;(Copy/C;(Paste/V;(Clear;(-;Preferences.../,");
}
void MenuEvent(long menuItem) {
GrafPtr oldPort;
Str255 name;
int menuID = HIWORD(menuItem);
int itemID = LOWORD(menuItem);
if(!menuID) return;
switch(menuID) {
case appleID: {
if(itemID < apple_EndID) {
DoAboutMenu(itemID);
} else {
/*StringPtr name = (StringPtr) NewPtr(sizeof(Str255));*/
GetPort(&oldPort);
GetItem(GET_MENU(appleID), itemID, name);
OpenDeskAcc(name);
SetPort(oldPort);
/*DisposPtr(name);*/
}
} break;
case fileID:
DoFileMenu(itemID);
break;
case editID:
DoEditMenu(itemID);
break;
}
}
void MenuEditMode(Boolean active) {
if(active) {
EnableItem(GET_MENU(editID), edit_UndoID);
EnableItem(GET_MENU(editID), edit_CutID);
EnableItem(GET_MENU(editID), edit_CopyID);
EnableItem(GET_MENU(editID), edit_PasteID);
EnableItem(GET_MENU(editID), edit_ClearID);
} else {
DisableItem(GET_MENU(editID), edit_UndoID);
DisableItem(GET_MENU(editID), edit_CutID);
DisableItem(GET_MENU(editID), edit_CopyID);
DisableItem(GET_MENU(editID), edit_PasteID);
DisableItem(GET_MENU(editID), edit_ClearID);
}
}
void DoAboutMenu(int item) {
switch(item) {
case apple_AboutID:
DialogAbout();
break;
}
}
void DoFileMenu(int item) {
switch(item) {
case file_RstID:
resetting = true;
break;
case file_QuitID:
running = false;
break;
}
}
void DoEditMenu(int item) {
if(item <= edit_ClearID) {
SystemEdit(item - 1);
} else {
switch(item) {
case edit_PrefsID:
DialogPrefs(&pendPrefs);
break;
}
}
}