home *** CD-ROM | disk | FTP | other *** search
/ Megarom / Megarom Macintosh CD Software (Quantum Leap)(1992).iso / COMPRESS / DeHQX-200 / Source / MyMenus.unit < prev    next >
Encoding:
Text File  |  1991-08-23  |  4.1 KB  |  178 lines  |  [TEXT/PJMM]

  1. unit MyMenus;
  2. { DeHQX v2.0.0 © Peter Lewis, Aug 1991 }
  3.  
  4. interface
  5.  
  6.     uses
  7.         Types, Traps, Balloons, MyTypes, MyUtilities;
  8.  
  9.     const
  10.         M_Apple = 128;
  11.         M_File = 129;
  12.         M_Edit = 130;
  13.         M_About = 1;
  14.  
  15.     var
  16.         M_Help_I, M_Close_I, M_HM_Help_I: integer;
  17.         MH_Apple, MH_File, MH_Edit: menuHandle;
  18.         quitNow: boolean;
  19.         editEnabled, closeEnabled, aboutFront, helpFront: boolean;
  20.  
  21.     procedure SimpleInitMenus (M_Help, M_Close: integer; hstr: str31);
  22.         { set quitNow, editEnabled, & M_Help_I. hstr is the string to add to the help menu }
  23.     procedure SimpleSetMenus;
  24.         { handle the edit menu }
  25.     function SimpleDoMenu (m, i: integer): boolean;        { true if you have to do it }
  26.         { handle About, DAs, Help, and Edit }
  27.     procedure AddMenu (M_What: integer; title, menus: str255);
  28.         { NewMenu, AppendMenu, InsertMenu }
  29.     procedure AddAboutMenu (name: str255);
  30.     procedure AddEditMenu;
  31.  
  32. implementation
  33.  
  34.     function SimpleDoMenu (m, i: integer): boolean;        { true if I cant do it }
  35.         var
  36.             save: grafPtr;
  37.             DAName: str255;
  38.             oe: integer;
  39.             sdm: boolean;
  40.             wp: windowPtr;
  41.     begin
  42.         sdm := false;
  43.         case m of
  44.             M_Apple: 
  45.                 case i of
  46.                     M_About: 
  47.                         DoAbout;
  48.                     otherwise
  49.                         begin
  50.                         GetPort(save);
  51.                         GetItem(GetMenu(M_apple), i, DAName);
  52.                         oe := OpenDeskAcc(DAName);
  53.                         SetPort(save);
  54.                     end;
  55.                 end;
  56.             M_File: 
  57.                 if i = M_Help_I then
  58.                     DoHelp
  59.                 else if i = M_Close_I then begin
  60.                     sdm := SimpleClose(FrontWindow);
  61.                 end
  62.                 else
  63.                     sdm := true;
  64.             M_Edit: 
  65.                 if i > 6 then
  66.                     sdm := true
  67.                 else
  68.                     sdm := not SystemEdit(i - 1);
  69.             kHMHelpMenuID: 
  70.                 DoHelp;
  71.             otherwise
  72.         end;
  73.         if not sdm then
  74.             HiliteMenu(0);
  75.         SimpleDoMenu := sdm;
  76.     end;
  77.  
  78.     procedure SimpleSetMenus;
  79.         var
  80.             oldEditEnabled, oldAboutFront, oldHelpFront, oldCloseEnabled: boolean;
  81.             fw: windowPtr;
  82.             mh: MenuHandle;
  83.             oe: OSErr;
  84.     begin
  85.         oldEditEnabled := editEnabled;
  86.         oldAboutFront := aboutFront;
  87.         oldHelpFront := helpFront;
  88.         oldCloseEnabled := closeEnabled;
  89.         fw := FrontWindow;
  90.         if fw = nil then begin
  91.             editEnabled := false;
  92.             aboutFront := false;
  93.             helpFront := false;
  94.             closeEnabled := false;
  95.         end
  96.         else begin
  97.             editEnabled := windowPeek(fw)^.windowKind < 0;
  98.             aboutFront := about_dialog = fw;
  99.             helpFront := help_dialog = fw;
  100.             closeEnabled := windowPeek(fw)^.goAwayFlag;
  101.         end;
  102.         if editEnabled <> oldEditEnabled then
  103.             SetItemEnable(GetMenu(M_Edit), 0, editEnabled);
  104.         if aboutFront <> oldAboutFront then
  105.             SetItemEnable(GetMenu(M_Apple), M_About, not aboutFront);
  106.         if helpFront <> oldHelpFront then begin
  107.             if M_Help_I > 0 then
  108.                 SetItemEnable(GetMenu(M_File), M_Help_I, not helpFront);
  109.             if M_HM_Help_I > 0 then begin
  110.                 oe := HMGetHelpMenuHandle(mh);
  111.                 if (oe = noErr) and (mh <> nil) then
  112.                     SetItemEnable(mh, M_HM_Help_I, not helpFront);
  113.             end;
  114.         end;
  115.         if closeEnabled <> oldCloseEnabled then
  116.             if M_Close_I > 0 then
  117.                 SetItemEnable(GetMenu(M_File), M_Close_I, closeEnabled);
  118.  
  119.         if (editEnabled <> oldEditEnabled) then
  120.             DrawMenuBar;
  121.     end;
  122.  
  123.     procedure SimpleInitMenus (M_Help, M_Close: integer; hstr: str31);
  124.         var
  125.             mh: menuHandle;
  126.             oe: OSErr;
  127.     begin
  128.         M_Help_I := M_Help;
  129.         M_Close_I := M_Close;
  130.         quitNow := false;
  131.         editEnabled := false;
  132.         closeEnabled := false;
  133.         aboutFront := false;
  134.         helpFront := false;
  135.  
  136.         MH_Apple := GetMenu(M_Apple);
  137.         AddResMenu(MH_Apple, 'DRVR');
  138.         InsertMenu(MH_Apple, 0);
  139.         MH_File := GetMenu(M_File);
  140.         InsertMenu(MH_File, 0);
  141.         MH_Edit := GetMenu(M_Edit);
  142.         InsertMenu(MH_Edit, 0);
  143.  
  144.         M_HM_Help_I := -1;
  145.         if has_HelpMgr and (hstr <> '') then begin
  146.             oe := HMGetHelpMenuHandle(mh);
  147.             if (oe = noErr) and (mh <> nil) then begin
  148.                 AppendMenu(mh, hstr);
  149.                 M_HM_Help_I := CountMItems(mh);
  150.             end;
  151.         end;
  152.     end;
  153.  
  154.     procedure AddMenu (M_What: integer; title, menus: str255);
  155.         var
  156.             mh: menuHandle;
  157.     begin
  158.         mh := NewMenu(M_What, title);
  159.         AppendMenu(mh, menus);
  160.         InsertMenu(mh, 0);
  161.     end;
  162.  
  163.     procedure AddAboutMenu (name: str255);
  164.         var
  165.             mh: menuHandle;
  166.     begin
  167.         mh := NewMenu(M_About, chr(appleMark));
  168.         AppendMenu(mh, Concat('About ', name, '…;(-'));
  169.         AddResMenu(mh, 'DRVR');
  170.         InsertMenu(mh, 0);
  171.     end;
  172.  
  173.     procedure AddEditMenu;
  174.     begin
  175.         AddMenu(M_Edit, 'Edit', 'Undo/Z;(-;Cut/X;Copy/C;Paste/V;Clear/B');
  176.     end;
  177.  
  178. end.