home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / AESample.sit / AESample / sources / sample.menu.c < prev    next >
Text File  |  1996-06-22  |  5KB  |  178 lines

  1. /*
  2.  *--------------------------------------------------------------
  3.  * sample.menu.c
  4.  *--------------------------------------------------------------
  5.  */
  6. #include "sample.h"
  7. #include "sample.menu.h"
  8. #include "sample.subs.h"
  9. #include "sample.send.h"
  10. #include "sample.dlog.h"
  11.  
  12. /*
  13.  *--------------------------------------------------------------
  14.  * static functuions only used in this source
  15.  *--------------------------------------------------------------
  16.  */
  17. static Boolean EnabeMyMItem(MenuRef, short, Boolean);
  18.  
  19. /*
  20.  *--------------------------------------------------------------
  21.  * macro
  22.  *--------------------------------------------------------------
  23.  */
  24. extern    Boolean isEnabled(MenuRef, const short);
  25. #define isEnabled(mH, item)    ((**(mH)).enableFlags & (1 << (item)))
  26.  
  27. /*
  28.  *--------------------------------------------------------------
  29.  * SetUpMyMenus
  30.  *--------------------------------------------------------------
  31.  *    setup menus
  32.  *--------------------------------------------------------------
  33.  */
  34. Boolean SetUpMyMenus(void)
  35. {
  36.     Handle    menuBar = GetNewMBar(rMenuBarID);
  37.     if (menuBar == nil) return (false);
  38.  
  39.     SetMenuBar(menuBar);
  40.     DisposeHandle(menuBar);
  41.     AppendResMenu(GetMenuHandle(mAppleID), 'DRVR');
  42.     DrawMenuBar();
  43.     return (true);
  44. }
  45. /*
  46.  *--------------------------------------------------------------
  47.  *    DoMenus
  48.  *--------------------------------------------------------------
  49.  *    Handle the menu selection. mSelect is what MenuSelect() and
  50.  *    MenuKey() return: the high word is the menu ID, the low word
  51.  *    is the menu item
  52.  *--------------------------------------------------------------
  53.  */
  54. void DoMenus(long mSelect)
  55. {
  56.     short    menuID  = HiWord(mSelect);
  57.     short    menuItm = LoWord(mSelect);
  58.  
  59.     switch (menuID) {
  60.     case mAppleID:    DoAppleMenu(menuItm);    break;
  61.     case mFileID:    DoFileMenu(menuItm);    break;
  62.     case mEditID:    if (!SystemEdit(menuItm -1))    DoEditMenu(menuItm);    break;
  63.     case mSendID:    DoSendMenu(menuItm);    break;
  64.     }
  65.     HiliteMenu(0);
  66. }
  67. /*
  68.  *--------------------------------------------------------------
  69.  *    DoAppleMenu
  70.  *--------------------------------------------------------------
  71.  */
  72. void DoAppleMenu(const short theItem)
  73. {
  74.     if (theItem == of_About) {
  75.         DoAboutMe();
  76.     } else {
  77.         /* Desk Accessories */
  78.         GrafPtr    savePort;
  79.         Str63    itsDAname;
  80.  
  81.         GetPort(&savePort);
  82.         GetMenuItemText(GetMenuHandle(mAppleID), theItem, itsDAname);
  83.         OpenDeskAcc(itsDAname);
  84.         SetPort(savePort);
  85.     }    
  86. }
  87. /*
  88.  *--------------------------------------------------------------
  89.  *    DoFileMenu
  90.  *--------------------------------------------------------------
  91.  */
  92. void DoFileMenu(const short theItem)
  93. {
  94.     WindowRef    aWindow = FrontWindow();
  95.  
  96.     switch (theItem) {
  97.     case of_Open:    DoOpenFile();    break;
  98.     case of_Close:
  99.         if (aWindow == gMainWindow) {
  100.             gForever = false;
  101.         }
  102.         else
  103.         if (aWindow == gViewDialog) {
  104.             CloseWindow(gViewDialog);
  105.         }
  106.         break;
  107.     case of_Print:    DoPrintFile();    break;
  108.     case of_Quit:    gForever = false;    break;
  109.     }
  110. }
  111. /*
  112.  *--------------------------------------------------------------
  113.  *    DoEditMenu
  114.  *--------------------------------------------------------------
  115.  */
  116. void DoEditMenu(const short theItem)
  117. {
  118.     switch (theItem) {
  119.     case of_Undo:    break;
  120.     case of_Cut:    break;
  121.     case of_Copy:    break;
  122.     case of_Paste:    break;
  123.     case of_Clear:    break;
  124.     case of_SelAll:    break;
  125.     }
  126. }
  127. /*
  128.  *--------------------------------------------------------------
  129.  *    DoSendMenu
  130.  *--------------------------------------------------------------
  131.  */
  132. void DoSendMenu(const short theItem)
  133. {
  134.     switch (theItem) {
  135.     case of_Hold:    DoHoldFile();    break;
  136.     case of_Send:    DoSendFile();    break;
  137.     }
  138. }
  139. /*
  140.  *--------------------------------------------------------------
  141.  * AdjustMyMenus
  142.  *--------------------------------------------------------------
  143.  *    change menu status according to current conditions
  144.  *--------------------------------------------------------------
  145.  */
  146. void AdjustMyMenus(void)
  147. {
  148.     MenuRef    aMenu = GetMenuHandle(mEditID);
  149.     Boolean        redraw = false;
  150.  
  151.     redraw |= EnabeMyMItem(aMenu, of_Title, GetWindowKind(FrontWindow()) < 0);
  152.  
  153.     aMenu = GetMenuHandle(mSendID);
  154.     redraw |= EnabeMyMItem(aMenu, of_Send, gDocSpec.name[0] > 0);
  155.  
  156.     if (redraw) DrawMenuBar();
  157. }
  158. /*
  159.  *--------------------------------------------------------------
  160.  * EnabeMyMItem
  161.  *--------------------------------------------------------------
  162.  *    enable or disable menu item according to the conditon
  163.  *--------------------------------------------------------------
  164.  */
  165. static Boolean EnabeMyMItem(MenuRef myMenu, short item, Boolean activate)
  166. {
  167.     Boolean    redraw;
  168.  
  169.     if (activate) {
  170.         redraw = (isEnabled(myMenu, item)) ? false : true;
  171.         EnableItem(myMenu, item);
  172.     } else {
  173.         redraw = (isEnabled(myMenu, item)) ? true : false;
  174.         DisableItem(myMenu, item);
  175.     }
  176.     return (redraw);
  177. }
  178.