1 /* SCCS Id: @(#)macmenu.c 3.4 1999/11/24 */
2 /* Copyright (c) Macintosh NetHack Port Team, 1993. */
3 /* NetHack may be freely redistributed. See license for details. */
5 /****************************************\
6 * Extended Macintosh menu support
8 * provides access to all keyboard commands from cmd.c
9 * provides control key functionality for classic keyboards
10 * provides key equivalent references and logical menu groups
11 * supports various menu highlighting modes
12 \****************************************/
14 /****************************************\
17 * 930512 - More bug fixes and getting tty to work again, Jon W{tte
18 * 930508 - Bug fixes in-flight, Jon W{tte
19 * 04/29/93 - 1st Release Draft, David Hairston
20 * 04/11/93 - 1st Draft, David Hairston
21 \****************************************/
23 /******** Application Defines ********/
28 #include "patchlevel.h"
30 /******** Toolbox Defines ********/
31 #if !TARGET_API_MAC_CARBON
34 #include <Resources.h>
35 #include <TextUtils.h>
36 #include <ToolUtils.h>
40 /* Borrowed from the Mac tty port */
41 extern WindowPtr _mt_window;
43 /******** Local Defines ********/
45 /* 'MNU#' (menu list record) */
46 typedef union menuRefUnn
48 short mresID; /* MENU resource ID (before GetMenu) */
49 MenuHandle mhnd; /* MENU handle (after GetMenu) */
52 typedef struct menuListRec
57 } menuListRec, *menuListPtr, **menuListHandle;
59 /* indices and resource IDs of the menu list data */
69 /* the following mref[] indices are reserved */
81 /* the following menu items are reserved */
85 menuAppleAboutBox = 1,
100 /* standard minimum Edit menu items */
103 menuWizardAttributes = 1
108 * menuListRec data (preloaded and locked) specifies the number of menus in
109 * the menu bar, the number of hierarchal or submenus and the menu IDs of
110 * all of those menus. menus that go into in the menu bar are specified by
111 * 'MNU#' 128 and submenus are specified by 'MNU#' 129. the fields of the
113 * firstMenuID - the menu ID (not resource ID) of the 1st menu. subsequent
114 * menus in the list are _forced_ to have consecutively incremented IDs.
115 * numMenus - the total count of menus in a given list (and the extent of
117 * mref[] - initially the MENU resource ID is stored in the placeholder for
118 * the resource handle. after loading (GetResource), the menu handle
119 * is stored and the menu ID, in memory, is set as noted above.
121 * NOTE: a ResEdit template editor is supplied to edit the 'MNU#' resources.
123 * NOTE: the resource IDs do not need to match the menu IDs in a menu list
124 * record although they have been originally set that way.
126 * NOTE: the menu ID's of menus in the submenu list record may be reset, as
127 * noted above. it is the programmers responsibility to make sure that
128 * submenu references/IDs are valid.
130 * WARNING: the existence of the submenu list record is assumed even if the
131 * number of submenus is zero. also, no error checking is done on the
132 * extents of the menu IDs. this must be correctly setup by the programmer.
135 #define ID1_MBAR pMenuList[listMenubar]->firstMenuID
136 #define ID1_SUBM pMenuList[listSubmenu]->firstMenuID
138 #define NUM_MBAR pMenuList[listMenubar]->numMenus
139 #define NUM_SUBM pMenuList[listSubmenu]->numMenus
141 #define MHND_APPLE pMenuList[listMenubar]->mref[menuApple].mhnd
142 #define MHND_FILE pMenuList[listMenubar]->mref[menuFile].mhnd
143 #define MHND_EDIT pMenuList[listMenubar]->mref[menuEdit].mhnd
145 #define MBARHND(x) pMenuList[listMenubar]->mref[(x)].mhnd
147 #define MHND_WIZ pMenuList[listSubmenu]->mref[menuWizard].mhnd
150 /* mutually exclusive (and prioritized) menu bar states */
158 mbarSpecial /* explore or debug mode */
161 #define WKND_MAP (WIN_BASE_KIND + NHW_MAP)
164 /* menu routine error numbers */
169 errGetANDlogTemplate,
177 /* menu 'STR#' comment char */
178 #define mstrEndChar 0xA5 /* '\245' or option-* or "bullet" */
183 alrt_Menu_start = 5000,
184 alrtMenuNote = alrt_Menu_start,
189 #define beepMenuAlertErr 1 /* # of SysBeep()'s before exitting */
197 /******** Globals ********/
198 static unsigned char *menuErrStr[err_Menu_total] =
200 "\pAbort: Bad \'MNU#\' resource!", /* errGetMenuList */
201 "\pAbort: Bad \'MENU\' resource!", /* errGetMenu */
202 "\pAbort: Bad \'DLOG\' resource!", /* errGetANDlogTemplate */
203 "\pAbort: Bad \'DITL\' resource!", /* errGetANDlogItems */
204 "\pAbort: Bad Dialog Allocation!", /* errGetANDialog */
205 "\pAbort: Bad Menu Allocation!", /* errANNewMenu */
207 static menuListPtr pMenuList[2];
208 static short theMenubar = mbarDA; /* force initial update */
209 static short kAdjustWizardMenu = 1;
212 /******** Prototypes ********/
213 #if !TARGET_API_MAC_CARBON
214 static void alignAD(Rect *, short);
216 static void mustGetMenuAlerts(void);
217 static void menuError(short);
218 static void aboutNetHack(void);
219 static void askSave(void);
220 static void askQuit(void);
223 /*** Askname dialog box ***/
225 #define RSRC_ASK 6000 /* Askname dialog and item list */
226 #define RSRC_ASK_PLAY 1 /* Play button */
227 #define RSRC_ASK_QUIT 2 /* Quit button */
228 #define RSRC_ASK_DEFAULT 3 /* Default ring */
229 #define RSRC_ASK_ROLE 4 /* Role popup menu */
230 #define RSRC_ASK_RACE 5 /* Race popup menu */
231 #define RSRC_ASK_GEND 6 /* Gender popup menu */
232 #define RSRC_ASK_ALIGN 7 /* Alignment popup menu */
233 #define RSRC_ASK_MODE 8 /* Mode popup menu */
234 #define RSRC_ASK_NAME 9 /* Name text field */
235 #define RSRC_ASK_MAX 10 /* Maximum enabled item */
237 #define KEY_MASK 0xff00
238 #define KEY_RETURN 0x2400
239 #define KEY_ENTER 0x4c00
240 #define KEY_ESCAPE 0x3500
241 #define CH_MASK 0x00ff
242 #define CH_RETURN 0x000d
243 #define CH_ENTER 0x0003
244 #define CH_ESCAPE 0x001b
246 static void ask_restring(const char *cstr, unsigned char *pstr);
247 static void ask_enable(DialogRef wind, short item, int enable);
248 static pascal void ask_redraw(DialogRef wind, DialogItemIndex item);
249 static pascal Boolean ask_filter(DialogRef wind, EventRecord *event, DialogItemIndex *item);
250 #define noresource(t,n) {SysBeep(3); ExitToShell();}
251 #define fatal(s) {SysBeep(3); ExitToShell();}
253 static MenuHandle askmenu[RSRC_ASK_MAX];
254 static int askselect[RSRC_ASK_MAX];
255 #define currrole askselect[RSRC_ASK_ROLE]
256 #define currrace askselect[RSRC_ASK_RACE]
257 #define currgend askselect[RSRC_ASK_GEND]
258 #define curralign askselect[RSRC_ASK_ALIGN]
259 #define currmode askselect[RSRC_ASK_MODE]
262 blackcolor = {0x0000, 0x0000, 0x0000},
263 // indentcolor = {0x4000, 0x4000, 0x4000},
264 darkcolor = {0x8000, 0x8000, 0x8000},
265 backcolor = {0xdddd, 0xdddd, 0xdddd},
266 lightcolor = {0xffff, 0xffff, 0xffff},
267 whitecolor = {0xffff, 0xffff, 0xffff};
270 /* Convert a mixed-case C string to a Capitalized Pascal string */
272 ask_restring (const char *cstr, unsigned char *pstr)
277 for (i = 0; *cstr && (i < 255); i++)
280 if ((pstr[1] >= 'a') && (pstr[1] <= 'z'))
281 pstr[1] += 'A' - 'a';
286 /* Enable the dialog item with the given index */
288 ask_enable (DialogRef wind, short item, int enable)
295 /* Enable or disable the appropriate item */
296 GetDialogItem(wind, item, &type, &handle, &rect);
297 if (enable) type &= ~itemDisable;
298 else type |= itemDisable;
299 HiliteControl((ControlHandle)handle, enable ? 0 : 255);
300 SetDialogItem(wind, item, type, handle, &rect);
306 ask_redraw (DialogRef wind, DialogItemIndex item)
311 static char *modechar = "NED";
314 /* Which item shall we redraw? */
315 GetDialogItem(wind, item, &type, &handle, &rect);
317 case RSRC_ASK_DEFAULT:
319 FrameRoundRect(&rect, 16, 16);
327 if (macFlags.color) {
328 RGBForeColor(&blackcolor);
329 RGBBackColor(&backcolor);
335 /* Draw the frame and drop shadow */
339 MoveTo(rect.right, rect.top+1);
340 LineTo(rect.right, rect.bottom);
341 LineTo(rect.left+1, rect.bottom);
343 /* Draw the menu character */
344 MoveTo(rect.left+4, rect.top+12);
347 DrawText(roles[askselect[item]].filecode, 0, 3);
350 DrawText(races[askselect[item]].filecode, 0, 3);
353 DrawText(genders[askselect[item]].filecode, 0, 3);
356 DrawText(aligns[askselect[item]].filecode, 0, 3);
359 DrawChar(modechar[askselect[item]]);
363 /* Draw the popup symbol */
364 MoveTo(rect.right - 16, rect.top + 5);
365 LineTo(rect.right - 6, rect.top + 5);
366 LineTo(rect.right - 11, rect.top + 10);
367 LineTo(rect.right - 15, rect.top + 6);
368 LineTo(rect.right - 8, rect.top + 6);
369 LineTo(rect.right - 11, rect.top + 9);
370 LineTo(rect.right - 13, rect.top + 7);
371 LineTo(rect.right - 10, rect.top + 7);
372 LineTo(rect.right - 11, rect.top + 8);
374 /* Draw the shadow */
375 InsetRect(&rect, 1, 1);
376 if (macFlags.color) {
380 /* Save the foreground color */
381 GetForeColor(&color);
383 /* Draw the top and left */
384 RGBForeColor(&lightcolor);
385 MoveTo(rect.left, rect.bottom-1);
386 LineTo(rect.left, rect.top);
387 LineTo(rect.right-1, rect.top);
389 /* Draw the bottom and right */
390 RGBForeColor(&darkcolor);
391 MoveTo(rect.right-1, rect.top+1);
392 LineTo(rect.right-1, rect.bottom-1);
393 LineTo(rect.left+1, rect.bottom-1);
395 /* Restore the foreground color */
396 RGBForeColor(&color);
402 if (macFlags.color) {
403 RGBForeColor(&whitecolor);
404 RGBBackColor(&whitecolor);
410 InsetRect(&rect, -1, -1);
412 InsetRect(&rect, -1, -1);
414 InsetRect(&rect, -2, -2);
415 if (macFlags.color) {
416 /* Draw the top and left */
417 RGBForeColor(&darkcolor);
418 MoveTo(rect.left, rect.bottom-1);
419 LineTo(rect.left, rect.top);
420 LineTo(rect.right-1, rect.top);
422 /* Draw the bottom and right */
423 RGBForeColor(&lightcolor);
424 MoveTo(rect.right-1, rect.top+1);
425 LineTo(rect.right-1, rect.bottom-1);
426 LineTo(rect.left+1, rect.bottom-1);
428 /* Restore the colors */
429 RGBForeColor(&blackcolor);
430 RGBBackColor(&backcolor);
438 static pascal Boolean
439 ask_filter (DialogRef wind, EventRecord *event, DialogItemIndex *item)
444 switch (event->what) {
447 ch = event->message & CH_MASK;
448 key = event->message & KEY_MASK;
449 /* Handle equivalents for OK */
450 if ((ch == CH_RETURN) || (key == KEY_RETURN) ||
451 (ch == CH_ENTER) || (key == KEY_ENTER)) {
452 if (GetDialogTextEditHandle(wind)[0]->teLength) {
453 FlashButton(wind, RSRC_ASK_PLAY);
454 *item = RSRC_ASK_PLAY;
459 /* Handle equivalents for Normal/Explore/Debug */
460 if ((event->modifiers & cmdKey) && (ch == 'n')) {
462 ask_redraw(wind, RSRC_ASK_MODE);
463 *item = RSRC_ASK_MODE;
466 if ((event->modifiers & cmdKey) && (ch == 'e')) {
468 ask_redraw(wind, RSRC_ASK_MODE);
469 *item = RSRC_ASK_MODE;
472 if ((event->modifiers & cmdKey) && (ch == 'd')) {
474 ask_redraw(wind, RSRC_ASK_MODE);
475 *item = RSRC_ASK_MODE;
478 /* Handle equivalents for Cancel and Quit */
479 if ((ch == CH_ESCAPE) || (key == KEY_ESCAPE) ||
480 ((event->modifiers & cmdKey) && (ch == 'q')) ||
481 ((event->modifiers & cmdKey) && (ch == '.'))) {
482 FlashButton(wind, RSRC_ASK_QUIT);
483 *item = RSRC_ASK_QUIT;
488 ask_redraw(wind, RSRC_ASK_NAME);
500 short i, j, item, type;
505 UserItemUPP redraw = NewUserItemUPP(ask_redraw);
506 ModalFilterUPP filter = NewModalFilterUPP(ask_filter);
509 /* Create the dialog */
510 if (!(askdialog = GetNewDialog(RSRC_ASK, NULL, (WindowRef)-1)))
511 noresource('DLOG', RSRC_ASK);
513 SetPortDialogPort(askdialog);
515 /* Initialize the name text item */
516 ask_restring(plname, str);
518 GetDialogItem(askdialog, RSRC_ASK_NAME, &type, &handle, &rect);
519 SetDialogItemText(handle, str);
525 if (plname && plname [0]) {
526 strcpy ((char *) pName, plname);
527 c2pstr ((char *) pName);
530 h = GetResource ('STR ', -16096);
531 if (((Handle) 0 != h) && (GetHandleSize (h) > 0)) {
537 BlockMove (*h, pName, **h + 1);
542 GetDialogItem(askdialog, RSRC_ASK_NAME, &type, &handle, &rect);
543 SetDialogItemText(handle, pName);
544 if (pName [0] > 2 && pName [pName [0] - 1] == '-') {
545 short role = (*pANR).anMenu[anRole];
546 char suffix = (char) pName[pName[0]],
547 *sfxindx = strchr(pl_classes, suffix);
550 role = (short) (sfxindx - pl_classes);
551 else if (suffix == '@')
552 role = (short) rn2((int) strlen(pl_classes));
553 (*pANR).anMenu[anRole] = role;
558 SelectDialogItemText(askdialog, RSRC_ASK_NAME, 0, 32767);
560 /* Initialize the role popup menu */
561 if (!(askmenu[RSRC_ASK_ROLE] = NewMenu(RSRC_ASK_ROLE, "\p")))
562 fatal("\pCannot create role menu");
563 for (i = 0; roles[i].name.m; i++) {
564 ask_restring(roles[i].name.m, str);
565 AppendMenu(askmenu[RSRC_ASK_ROLE], str);
567 InsertMenu(askmenu[RSRC_ASK_ROLE], hierMenu);
568 if (flags.initrole >= 0)
569 currrole = flags.initrole;
570 /* Check for backward compatibility */
571 else if ((currrole = str2role(pl_character)) < 0)
572 currrole = randrole();
574 /* Initialize the race popup menu */
575 if (!(askmenu[RSRC_ASK_RACE] = NewMenu(RSRC_ASK_RACE, "\p")))
576 fatal("\pCannot create race menu");
577 for (i = 0; races[i].noun; i++) {
578 ask_restring(races[i].noun, str);
579 AppendMenu(askmenu[RSRC_ASK_RACE], str);
581 InsertMenu(askmenu[RSRC_ASK_RACE], hierMenu);
582 if (flags.initrace >= 0)
583 currrace = flags.initrace;
585 currrace = randrace(currrole);
587 /* Initialize the gender popup menu */
588 if (!(askmenu[RSRC_ASK_GEND] = NewMenu(RSRC_ASK_GEND, "\p")))
589 fatal("\pCannot create gender menu");
590 for (i = 0; i < ROLE_GENDERS; i++) {
591 ask_restring(genders[i].adj, str);
592 AppendMenu(askmenu[RSRC_ASK_GEND], str);
594 InsertMenu(askmenu[RSRC_ASK_GEND], hierMenu);
595 if (flags.initgend >= 0)
596 currgend = flags.initgend;
597 else if (flags.female)
600 currgend = randgend(currrole, currrace);
602 /* Initialize the alignment popup menu */
603 if (!(askmenu[RSRC_ASK_ALIGN] = NewMenu(RSRC_ASK_ALIGN, "\p")))
604 fatal("\pCannot create alignment menu");
605 for (i = 0; i < ROLE_ALIGNS; i++) {
606 ask_restring(aligns[i].adj, str);
607 AppendMenu(askmenu[RSRC_ASK_ALIGN], str);
609 InsertMenu(askmenu[RSRC_ASK_ALIGN], hierMenu);
610 if (flags.initalign >= 0)
611 curralign = flags.initalign;
613 curralign = randalign(currrole, currrace);
615 /* Initialize the mode popup menu */
616 if (!(askmenu[RSRC_ASK_MODE] = NewMenu(RSRC_ASK_MODE, "\p")))
617 fatal("\pCannot create mode menu");
618 AppendMenu(askmenu[RSRC_ASK_MODE], "\pNormal");
619 AppendMenu(askmenu[RSRC_ASK_MODE], "\pExplore");
621 AppendMenu(askmenu[RSRC_ASK_MODE], "\pDebug");
623 InsertMenu(askmenu[RSRC_ASK_MODE], hierMenu);
626 /* Set the redraw procedures */
627 for (item = RSRC_ASK_DEFAULT; item <= RSRC_ASK_MODE; item++) {
628 GetDialogItem(askdialog, item, &type, &handle, &rect);
629 SetDialogItem(askdialog, item, type, (Handle)redraw, &rect);
632 /* Handle dialog events */
634 /* Adjust the Play button */
635 ask_enable(askdialog, RSRC_ASK_PLAY,
636 GetDialogTextEditHandle(askdialog)[0]->teLength);
638 /* Adjust the race popup menu */
641 if (validrace(currrole, j)) {
642 EnableMenuItem(askmenu[RSRC_ASK_RACE], j+1);
643 CheckMenuItem(askmenu[RSRC_ASK_RACE], j+1,
646 DisableMenuItem(askmenu[RSRC_ASK_RACE], j+1);
647 CheckMenuItem(askmenu[RSRC_ASK_RACE], j+1, FALSE);
648 if ((currrace == j) && !races[++currrace].noun)
651 if (!races[++j].noun) j = 0;
654 GetDialogItem(askdialog, RSRC_ASK_RACE, &type, &handle, &rect);
655 InvalWindowRect(GetDialogWindow(askdialog), &rect);
658 /* Adjust the gender popup menu */
661 if (validgend(currrole, currrace, j)) {
662 EnableMenuItem(askmenu[RSRC_ASK_GEND], j+1);
663 CheckMenuItem(askmenu[RSRC_ASK_GEND], j+1,
666 DisableMenuItem(askmenu[RSRC_ASK_GEND], j+1);
667 CheckMenuItem(askmenu[RSRC_ASK_GEND], j+1, FALSE);
668 if ((currgend == j) && (++currgend >= ROLE_GENDERS))
671 if (++j >= ROLE_GENDERS) j = 0;
674 GetDialogItem(askdialog, RSRC_ASK_GEND, &type, &handle, &rect);
675 InvalWindowRect(GetDialogWindow(askdialog), &rect);
678 /* Adjust the alignment popup menu */
681 if (validalign(currrole, currrace, j)) {
682 EnableMenuItem(askmenu[RSRC_ASK_ALIGN], j+1);
683 CheckMenuItem(askmenu[RSRC_ASK_ALIGN], j+1,
686 DisableMenuItem(askmenu[RSRC_ASK_ALIGN], j+1);
687 CheckMenuItem(askmenu[RSRC_ASK_ALIGN], j+1, FALSE);
688 if ((curralign == j) && (++curralign >= ROLE_ALIGNS))
691 if (++j >= ROLE_ALIGNS) j = 0;
693 if (curralign != i) {
694 GetDialogItem(askdialog, RSRC_ASK_ALIGN, &type, &handle, &rect);
695 InvalWindowRect(GetDialogWindow(askdialog), &rect);
698 /* Adjust the role popup menu */
699 for (i = 0; roles[i].name.m; i++) {
700 ask_restring((currgend && roles[i].name.f) ?
701 roles[i].name.f : roles[i].name.m, str);
702 SetMenuItemText(askmenu[RSRC_ASK_ROLE], i+1, str);
703 CheckMenuItem(askmenu[RSRC_ASK_ROLE], i+1, currrole == i);
706 /* Adjust the mode popup menu */
707 CheckMenuItem(askmenu[RSRC_ASK_MODE], 1, currmode == 0);
708 CheckMenuItem(askmenu[RSRC_ASK_MODE], 2, currmode == 1);
710 CheckMenuItem(askmenu[RSRC_ASK_MODE], 3, currmode == 2);
713 /* Wait for an action on an item */
714 ModalDialog(filter, &item);
726 GetDialogItem(askdialog, item, &type, &handle, &rect);
727 pt = *(Point *)▭
729 if (!!(i = PopUpMenuSelect(askmenu[item], pt.v, pt.h,
730 askselect[item] + 1)))
731 askselect[item] = LoWord(i) - 1;
732 InvalWindowRect(GetDialogWindow(askdialog), &rect);
736 /* limit the data here to 25 chars */
738 short beepTEDelete = 1;
740 while ((**dRec.textH).teLength > 25)
742 if (beepTEDelete++ <= 3)
744 TEKey('\b', dRec.textH);
748 /* special case filter (that doesn't plug all the holes!) */
749 if (((**dRec.textH).teLength == 1) && (**((**dRec.textH).hText) < 32))
750 TEKey('\b', dRec.textH);
754 } while ((item != RSRC_ASK_PLAY) && (item != RSRC_ASK_QUIT));
756 /* Process the name */
757 GetDialogItem(askdialog, RSRC_ASK_NAME, &type, &handle, &rect);
758 GetDialogItemText(handle, str);
759 if (str[0] > PL_NSIZ-1) str[0] = PL_NSIZ-1;
760 BlockMove(&str[1], plname, str[0]);
761 plname[str[0]] = '\0';
763 /* Destroy the dialog */
764 for (i = RSRC_ASK_ROLE; i <= RSRC_ASK_MODE; i++) {
766 DisposeMenu(askmenu[i]);
769 DisposeDialog(askdialog);
770 DisposeRoutineDescriptor(filter);
771 DisposeRoutineDescriptor(redraw);
773 /* Process the mode */
781 case 1: /* Explore */
787 strcpy(plname, WIZARD);
794 /* Process the role */
795 strcpy(pl_character, roles[currrole].name.m);
796 flags.initrole = currrole;
798 /* Process the race */
799 flags.initrace = currrace;
801 /* Process the gender */
802 flags.female = flags.initgend = currgend;
804 /* Process the alignment */
805 flags.initalign = curralign;
812 /*** Menu bar routines ***/
814 #if !TARGET_API_MAC_CARBON
816 alignAD(Rect *pRct, short vExempt)
821 GetQDGlobalsScreenBits(&qbitmap);
822 (*pRct).right -= (*pRct).left; /* width */
823 (*pRct).bottom -= (*pRct).top; /* height */
824 (*pRct).left = (qbitmap.bounds.right - (*pRct).right) / 2;
825 (*pRct).top = (qbitmap.bounds.bottom - (*pRct).bottom - vExempt) / 2;
826 (*pRct).top += vExempt;
827 (*pRct).right += (*pRct).left;
828 (*pRct).bottom += (*pRct).top;
839 for (i = alrt_Menu_start; i < alrt_Menu_limit; i++)
841 if (! (hRct = (Rect **) GetResource('ALRT', i))) /* AlertTHndl */
843 for (i = 0; i < beepMenuAlertErr; i++)
848 #if !TARGET_API_MAC_CARBON
849 alignAD(*hRct, GetMBarHeight());
855 menuError(short menuErr)
859 for (i = 0; i < beepMenuAlertErr; i++)
862 ParamText(menuErrStr[menuErr], "\p", "\p", "\p");
863 (void) Alert(alrtMenuNote, (ModalFilterUPP) 0L);
871 static Boolean was_inited = 0;
873 menuListHandle mlHnd;
882 for (i = listMenubar; i <= listSubmenu; i++) {
883 if (! (mlHnd = (menuListHandle) GetResource('MNU#', (menuBarListID + i))))
884 menuError(errGetMenuList);
886 pMenuList[i] = (menuListPtr) NewPtr(GetHandleSize((Handle) mlHnd));
887 *pMenuList[i] = **mlHnd;
889 for (j = 0; j < pMenuList[i]->numMenus; j++)
891 if (! (menu = (MenuHandle) GetMenu((**mlHnd).mref[j].mresID))) {
893 NumToString ((**mlHnd).mref[j].mresID, d);
894 menuError(errGetMenu);
897 pMenuList[i]->mref[j].mhnd = menu;
898 SetMenuID(menu, j + (**mlHnd).firstMenuID); /* consecutive IDs */
900 /* expand apple menu */
901 if ((i == listMenubar) && (j == menuApple)) {
902 AppendResMenu(menu, 'DRVR');
905 InsertMenu(menu, ((i == listSubmenu) ? hierMenu : 0));
913 AdjustMenus(short dimMenubar)
915 short newMenubar = mbarRegular;
916 WindowRef win = FrontWindow();
920 * if (windowprocs != mac_procs) {
924 /* determine the new menubar state */
926 newMenubar = mbarDim;
928 newMenubar = mbarNoWindows;
929 else if (GetWindowKind(win) < 0)
931 else if (!IsWindowVisible(_mt_window))
932 newMenubar = mbarNoMap;
934 if (newMenubar != mbarRegular)
935 ; /* we've already found its state */
939 newMenubar = mbarSpecial;
941 if (kAdjustWizardMenu)
943 kAdjustWizardMenu = 0;
945 SetMenuItemText(MHND_FILE, menuFilePlayMode, "\pDebug");
952 newMenubar = mbarSpecial;
954 if (kAdjustWizardMenu)
956 kAdjustWizardMenu = 0;
958 SetMenuItemText(MHND_FILE, menuFilePlayMode, "\pExplore");
960 for (i = CountMenuItems(MHND_WIZ); i > menuWizardAttributes; i--)
961 DeleteMenuItem(MHND_WIZ, i);
965 /* adjust the menubar, if there's a state change */
966 if (theMenubar != newMenubar)
968 switch(theMenubar = newMenubar)
971 /* disable all menus (except the apple menu) */
972 for (i = menuFile; i < NUM_MBAR; i++)
973 DisableMenuItem(MBARHND(i), 0);
979 /* enable the file menu, but ... */
980 EnableMenuItem(MHND_FILE, 0);
982 /* ... disable the window commands! */
983 for (i = menuFileRedraw; i <= menuFileEnterExplore; i++)
984 DisableMenuItem(MHND_FILE, i);
986 /* ... and disable the rest of the menus */
987 for (i = menuEdit; i < NUM_MBAR; i++)
988 DisableMenuItem(MBARHND(i), 0);
990 if (theMenubar == mbarDA)
991 EnableMenuItem(MHND_EDIT, 0);
997 /* enable all menus ... */
998 for (i = menuFile; i < NUM_MBAR; i++)
999 EnableMenuItem(MBARHND(i), 0);
1001 /* ... except the unused Edit menu */
1002 DisableMenuItem(MHND_EDIT, 0);
1004 /* ... enable the window commands */
1005 for (i = menuFileRedraw; i <= menuFileEnterExplore; i++)
1006 EnableMenuItem(MHND_FILE, i);
1008 if (theMenubar == mbarRegular)
1009 DisableMenuItem(MHND_FILE, menuFilePlayMode);
1011 DisableMenuItem(MHND_FILE, menuFileEnterExplore);
1021 DoMenuEvt(long menuEntry)
1023 short menuID = HiWord(menuEntry);
1024 short menuItem = LoWord(menuEntry);
1026 switch(menuID - ID1_MBAR) /* all submenus are default case */
1029 if (menuItem == menuAppleAboutBox)
1031 #if !TARGET_API_MAC_CARBON
1034 unsigned char daName[32];
1036 GetMenuItemText(MHND_APPLE, menuItem, * (Str255 *) daName);
1037 (void) OpenDeskAcc(daName);
1043 * Those direct calls are ugly: they should be installed into cmd.c .
1044 * Those AddToKeyQueue() calls are also ugly: they should be put into
1045 * the 'STR#' resource.
1050 case menuFileRedraw:
1051 AddToKeyQueue ('R' & 0x1f, 1);
1054 case menuFilePrevMsg:
1055 AddToKeyQueue ('P' & 0x1f, 1);
1058 case menuFileCleanup:
1059 (void) SanePositions();
1062 case menuFileEnterExplore:
1063 AddToKeyQueue ('X', 1);
1077 #if !TARGET_API_MAC_CARBON
1078 (void) SystemEdit(menuItem - 1);
1082 default: /* get associated string and add to key queue */
1087 GetIndString(mstr, menuID, menuItem);
1088 if (mstr[0] > QUEUE_LEN)
1089 mstr[0] = QUEUE_LEN;
1091 for (i = 1; ((i <= mstr[0]) && (mstr[i] != mstrEndChar)); i++)
1092 AddToKeyQueue(mstr[i], false);
1103 if (theMenubar >= mbarRegular) {
1104 (void) doversion(); /* is this necessary? */
1106 unsigned char aboutStr[32] = "\pNetHack 3.4.";
1108 if (PATCHLEVEL > 10) {
1109 aboutStr[++aboutStr[0]] = '0'+PATCHLEVEL/10;
1112 aboutStr[++aboutStr[0]] = '0' + (PATCHLEVEL % 10);
1114 ParamText(aboutStr, "\p\rdevteam@www.nethack.org", "\p", "\p");
1115 (void) Alert(alrtMenuNote, (ModalFilterUPP) 0L);
1127 if (theMenubar < mbarRegular) {
1130 ParamText("\pReally Save?", "\p", "\p", "\p");
1131 itemHit = Alert(alrtMenu_NY, (ModalFilterUPP) 0L);
1134 if (itemHit != bttnMenuAlertYes) {
1141 AddToKeyQueue ('S', 1);
1143 AddToKeyQueue ('y', 1);
1156 if (!strcmp (windowprocs.name, "mac"))
1161 if (theMenubar < mbarRegular) {
1164 ParamText("\pReally Quit?", "\p", "\p", "\p");
1165 itemHit = Alert(alrtMenu_NY, (ModalFilterUPP) 0L);
1168 if (itemHit != bttnMenuAlertYes) {
1175 /* MWM -- forgive me lord, an even uglier kludge to deal with differences
1176 in command input handling
1179 quitinput = "#quit\r";
1183 /* KMH -- Ugly kludge */
1185 AddToKeyQueue(*quitinput++, 1);
1188 quitinput = "y\rq\r\r\r";
1192 AddToKeyQueue(*quitinput++, 1);