home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-08-23 | 4.1 KB | 178 lines | [TEXT/PJMM] |
- unit MyMenus;
- { DeHQX v2.0.0 © Peter Lewis, Aug 1991 }
-
- interface
-
- uses
- Types, Traps, Balloons, MyTypes, MyUtilities;
-
- const
- M_Apple = 128;
- M_File = 129;
- M_Edit = 130;
- M_About = 1;
-
- var
- M_Help_I, M_Close_I, M_HM_Help_I: integer;
- MH_Apple, MH_File, MH_Edit: menuHandle;
- quitNow: boolean;
- editEnabled, closeEnabled, aboutFront, helpFront: boolean;
-
- procedure SimpleInitMenus (M_Help, M_Close: integer; hstr: str31);
- { set quitNow, editEnabled, & M_Help_I. hstr is the string to add to the help menu }
- procedure SimpleSetMenus;
- { handle the edit menu }
- function SimpleDoMenu (m, i: integer): boolean; { true if you have to do it }
- { handle About, DAs, Help, and Edit }
- procedure AddMenu (M_What: integer; title, menus: str255);
- { NewMenu, AppendMenu, InsertMenu }
- procedure AddAboutMenu (name: str255);
- procedure AddEditMenu;
-
- implementation
-
- function SimpleDoMenu (m, i: integer): boolean; { true if I cant do it }
- var
- save: grafPtr;
- DAName: str255;
- oe: integer;
- sdm: boolean;
- wp: windowPtr;
- begin
- sdm := false;
- case m of
- M_Apple:
- case i of
- M_About:
- DoAbout;
- otherwise
- begin
- GetPort(save);
- GetItem(GetMenu(M_apple), i, DAName);
- oe := OpenDeskAcc(DAName);
- SetPort(save);
- end;
- end;
- M_File:
- if i = M_Help_I then
- DoHelp
- else if i = M_Close_I then begin
- sdm := SimpleClose(FrontWindow);
- end
- else
- sdm := true;
- M_Edit:
- if i > 6 then
- sdm := true
- else
- sdm := not SystemEdit(i - 1);
- kHMHelpMenuID:
- DoHelp;
- otherwise
- end;
- if not sdm then
- HiliteMenu(0);
- SimpleDoMenu := sdm;
- end;
-
- procedure SimpleSetMenus;
- var
- oldEditEnabled, oldAboutFront, oldHelpFront, oldCloseEnabled: boolean;
- fw: windowPtr;
- mh: MenuHandle;
- oe: OSErr;
- begin
- oldEditEnabled := editEnabled;
- oldAboutFront := aboutFront;
- oldHelpFront := helpFront;
- oldCloseEnabled := closeEnabled;
- fw := FrontWindow;
- if fw = nil then begin
- editEnabled := false;
- aboutFront := false;
- helpFront := false;
- closeEnabled := false;
- end
- else begin
- editEnabled := windowPeek(fw)^.windowKind < 0;
- aboutFront := about_dialog = fw;
- helpFront := help_dialog = fw;
- closeEnabled := windowPeek(fw)^.goAwayFlag;
- end;
- if editEnabled <> oldEditEnabled then
- SetItemEnable(GetMenu(M_Edit), 0, editEnabled);
- if aboutFront <> oldAboutFront then
- SetItemEnable(GetMenu(M_Apple), M_About, not aboutFront);
- if helpFront <> oldHelpFront then begin
- if M_Help_I > 0 then
- SetItemEnable(GetMenu(M_File), M_Help_I, not helpFront);
- if M_HM_Help_I > 0 then begin
- oe := HMGetHelpMenuHandle(mh);
- if (oe = noErr) and (mh <> nil) then
- SetItemEnable(mh, M_HM_Help_I, not helpFront);
- end;
- end;
- if closeEnabled <> oldCloseEnabled then
- if M_Close_I > 0 then
- SetItemEnable(GetMenu(M_File), M_Close_I, closeEnabled);
-
- if (editEnabled <> oldEditEnabled) then
- DrawMenuBar;
- end;
-
- procedure SimpleInitMenus (M_Help, M_Close: integer; hstr: str31);
- var
- mh: menuHandle;
- oe: OSErr;
- begin
- M_Help_I := M_Help;
- M_Close_I := M_Close;
- quitNow := false;
- editEnabled := false;
- closeEnabled := false;
- aboutFront := false;
- helpFront := false;
-
- MH_Apple := GetMenu(M_Apple);
- AddResMenu(MH_Apple, 'DRVR');
- InsertMenu(MH_Apple, 0);
- MH_File := GetMenu(M_File);
- InsertMenu(MH_File, 0);
- MH_Edit := GetMenu(M_Edit);
- InsertMenu(MH_Edit, 0);
-
- M_HM_Help_I := -1;
- if has_HelpMgr and (hstr <> '') then begin
- oe := HMGetHelpMenuHandle(mh);
- if (oe = noErr) and (mh <> nil) then begin
- AppendMenu(mh, hstr);
- M_HM_Help_I := CountMItems(mh);
- end;
- end;
- end;
-
- procedure AddMenu (M_What: integer; title, menus: str255);
- var
- mh: menuHandle;
- begin
- mh := NewMenu(M_What, title);
- AppendMenu(mh, menus);
- InsertMenu(mh, 0);
- end;
-
- procedure AddAboutMenu (name: str255);
- var
- mh: menuHandle;
- begin
- mh := NewMenu(M_About, chr(appleMark));
- AppendMenu(mh, Concat('About ', name, '…;(-'));
- AddResMenu(mh, 'DRVR');
- InsertMenu(mh, 0);
- end;
-
- procedure AddEditMenu;
- begin
- AddMenu(M_Edit, 'Edit', 'Undo/Z;(-;Cut/X;Copy/C;Paste/V;Clear/B');
- end;
-
- end.