home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / Bowers Development / AppMaker 2.0b5 / Examples / Procedural / Gadgets / MainMenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-19  |  3.9 KB  |  207 lines  |  [TEXT/MMCC]

  1. /* MainMenu.c */
  2. /* Created 01/01/95 12:01 PM by AppMaker */
  3.  
  4. #include <Types.h>
  5. #include <Quickdraw.h>
  6. #include <Controls.h>
  7. #include <Dialogs.h>
  8. #include <Events.h>
  9. #include <Lists.h>
  10. #include <LowMem.h>
  11. #include <Menus.h>
  12. #include <TextEdit.h>
  13. #include "Globals.h"
  14. #include "ResourceDefs.h"
  15. #include "Miscellany.h"
  16.  
  17. #include "AboutDialog.h"
  18. #include "FileM.h"
  19. #include "EditM.h"
  20.  
  21. #include <Desk.h>
  22. #include <ToolUtils.h>
  23. #include "MainMenu.h"
  24.  
  25.  
  26. static void Enable            (short            itemNr,
  27.                              Boolean        enabled);
  28. static void EnableTitle        (MenuHandle        menu,
  29.                              Boolean        enabled);
  30. static void DoApple            (short            itemNr);
  31.  
  32. /*----------*/
  33. void InitTitles (void)
  34. {
  35.     InitFileM ();
  36.     InitEditM ();
  37.  
  38. } /*InitTitles*/
  39.  
  40. /*----------*/
  41. void LoadMenus (void)
  42. {
  43.     AppleMenu    = GetMenu (MENU_Apple);
  44.     FailNilResource ((Handle)AppleMenu);
  45.     AddResMenu (AppleMenu, 'DRVR');
  46.     FileMenu    = GetMenu (MENU_File);
  47.     EditMenu    = GetMenu (MENU_Edit);
  48.  
  49.     InsertMenu (AppleMenu, 0);
  50.     InsertMenu (FileMenu, 0);
  51.     InsertMenu (EditMenu, 0);
  52.  
  53.     DrawMenuBar ();
  54. } /*LoadMenus*/
  55.  
  56. /*----------*/
  57. static void DoAbout (void)
  58. {
  59.     AboutDialogRec                AboutDialogInfo;
  60.     register AboutDialogRecPtr    info;
  61.  
  62.     info = &AboutDialogInfo;
  63.     /*initialize AboutDialog info*/
  64.  
  65.     if (GetAboutDialog (&AboutDialogInfo)) {
  66.         /*use AboutDialog info*/
  67.     }
  68. } /*DoAbout*/
  69.  
  70.  
  71. /*----------*/
  72. static void DoApple (short     itemNr)
  73. {
  74.     Str255            name;
  75.     short            refNum;
  76.  
  77.     switch (itemNr) {
  78.         case AppleAbout:
  79.                 DoAbout ();
  80.             break;
  81.  
  82.         default:
  83.                 GetItem (AppleMenu, itemNr, name);
  84.                 refNum = OpenDeskAcc (name);
  85.             break;
  86.     } /*switch*/
  87. } /*DoApple*/
  88.  
  89. /*----------*/
  90. void DoMenu (long        menuChoice)
  91. {
  92.     short            menuID;
  93.     short            itemNr;
  94.  
  95.     menuID = HiWord (menuChoice);
  96.     itemNr = LoWord (menuChoice);
  97.  
  98.     switch (menuID) {
  99.     case 0:
  100.             /*Do nothing*/;
  101.         break;
  102.     case MENU_Apple:
  103.             DoApple (itemNr);
  104.         break;
  105.     case MENU_File:
  106.             DoFile (itemNr);
  107.         break;
  108.     case MENU_Edit:
  109.             DoEdit (itemNr);
  110.         break;
  111.  
  112.     } /*switch*/
  113.  
  114.     HiliteMenu (0);
  115. } /*DoMenu*/
  116.  
  117. /*----------*/
  118. MenuHandle        menu;
  119. Boolean            menuBarChanged;
  120.  
  121. /*----------*/
  122. static void Enable    (short        itemNr,
  123.                      Boolean    enabled)
  124. {
  125.     if (enabled) {
  126.         EnableItem  (menu, itemNr);
  127.     } else {
  128.         DisableItem (menu, itemNr);
  129.     }
  130. } /*Enable*/
  131.  
  132. /*----------*/
  133. static void EnableTitle    (MenuHandle        menu,
  134.                          Boolean        enabled)
  135. {
  136.     if (enabled != ((**menu).enableFlags & 1)) {
  137.         menuBarChanged = true;
  138.     }
  139.     if (enabled) {
  140.         EnableItem  (menu, 0);
  141.     } else {
  142.         DisableItem (menu, 0);
  143.     }
  144. } /*EnableTitle*/
  145.  
  146. /*----------*/
  147. void UpdateMenus (void)
  148. {
  149.     WindowPeek        frontPeek;
  150.     Boolean            isFront;            /*is there a front window?*/
  151.     Boolean            isCur;                /*is there a current window?*/
  152.     Boolean            isDirty;            /*is it dirty?*/
  153.     Boolean            hasFile;            /*does it have a file?*/
  154.     Boolean            isSelected;            /*is anything selected?*/
  155.     Boolean            isDesk;                /*is the front window a desk acc?*/
  156.     Boolean            isText;                /*is there a current text field?*/
  157.     Boolean            isScrap;            /*is there any scrap?*/
  158.     menuBarChanged = false;
  159.  
  160.     isFront        = (FrontWindow () != nil);
  161.     isCur        = (curWindow != nil);
  162.     isDirty        = false;
  163.     hasFile        = false;
  164.     isSelected    = false;
  165.     if (isCur) {
  166.         isDirty        =  cur->dirty;
  167.         hasFile        = (cur->fileNum != 0);
  168.     }
  169.  
  170.     isDesk = false;
  171.     if (isFront) {
  172.         frontPeek    = (WindowPeek) FrontWindow ();
  173.         isDesk        = (frontPeek->windowKind < 0);
  174.     }
  175.     isText        = isCur && (cur->text != nil);
  176.     isScrap        = false;
  177.     if (isText) {
  178.         isSelected    = ((**(cur->text)).selStart != (**(cur->text)).selEnd);
  179.         isScrap        = (TEGetScrapLen () > 0);
  180.     }
  181.  
  182.     menu = FileMenu;
  183.     Enable (FileClose,        isFront);
  184.     Enable (FileSave,        isDirty);
  185.     Enable (FileSaveAs,        isCur);
  186.     Enable (FileRevert,        isDirty);
  187.  
  188.     menu = EditMenu;
  189.     if (isFront) {
  190.         Enable (EditUndo,        isDesk);
  191.         Enable (EditCut,        isDesk || isSelected);
  192.         Enable (EditCopy,        isDesk || isSelected);
  193.         Enable (EditPaste,        isDesk || isScrap);
  194.         Enable (EditClear,        isDesk || isSelected);
  195.         Enable (EditSelectAll,    isText);
  196.  
  197.     }
  198.     EnableTitle (EditMenu,     isFront);
  199.  
  200.  
  201.     if (menuBarChanged) {
  202.         DrawMenuBar ();
  203.     }
  204. } /*UpdateMenus*/
  205.  
  206. /* MainMenu */
  207.