home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / Effect library / Demo ƒ / MSG Shell ƒ / msg menus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-12  |  8.5 KB  |  415 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        msg menus.c
  4.  
  5. Purpose:    This module handles menu selections, including selection
  6.             of dimmed menu items (hehe).
  7.  
  8.  
  9. MSG Demo -- graphic effects demonstration program
  10. Copyright (C) 1992-4 Mark Pilgrim & Dave Blumenthal
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg menus.h"
  30. #include "msg main.h"
  31. #include "msg graphics.h"
  32. #include "msg about.h"
  33. #include "msg help.h"
  34. #include "msg prefs.h"
  35. #include "msg sounds.h"
  36. #include "msg environment.h"
  37. #include "demo crash.h"
  38. #include "demo.h"
  39. #include "program globals.h"
  40.  
  41. extern    long        menuDisable : 0x0b54;
  42.  
  43. Boolean            gMenuEnabled;
  44. MenuHandle        gAppleMenu;
  45. MenuHandle        gFileMenu;
  46. MenuHandle        gEditMenu;
  47. MenuHandle        gWipesMenu;
  48. MenuHandle        gAdditionsMenu;
  49. MenuHandle        gScrollMenu;
  50. MenuHandle        gFluffMenu;
  51. MenuHandle        gHelpMenu;
  52. MenuHandle        gCrashMenu;
  53.  
  54. void AdjustMenus(void)
  55. {
  56.     WindowPeek    theWindow;
  57.     int            kind;
  58.     
  59.     theWindow = (WindowPeek)FrontWindow();
  60.     kind = theWindow ? theWindow->windowKind : 0;
  61.     
  62.     if(kind < 0)
  63.         EnableItem(gEditMenu, 0);
  64.     else
  65.         DisableItem(gEditMenu, 0);
  66.     
  67.     if(theWindow)
  68.         EnableItem(gFileMenu, closeItem);
  69.     else
  70.         DisableItem(gFileMenu, closeItem);
  71.     
  72.     if(gTheWindow[kMainWindow])
  73.         DisableItem(gFileMenu, openItem);
  74.     else
  75.         EnableItem(gFileMenu, openItem);
  76.     
  77.     if (gDisableQuit)
  78.     {
  79.         DisableItem(gFileMenu, quitItem);
  80.         DisableItem(gFileMenu, disableQuitItem);
  81.         EnableItem(gFileMenu, enableQuitItem);
  82.     }
  83.     else
  84.     {
  85.         EnableItem(gFileMenu, quitItem);
  86.         EnableItem(gFileMenu, disableQuitItem);
  87.         DisableItem(gFileMenu, enableQuitItem);
  88.     }
  89.     if (gLastWipe==-1)
  90.         DisableItem(gFluffMenu, repeatItem);
  91.     else
  92.         EnableItem(gFluffMenu, repeatItem);
  93.     
  94.     if (gWipeStatus==kFullScreen)
  95.     {
  96.         DisableItem(gWipesMenu, caste1Item);
  97.         DisableItem(gWipesMenu, rippleItem);
  98.         DisableItem(gWipesMenu, dissolveItem);
  99.         DisableItem(gWipesMenu, caste2Item);
  100.     }
  101.     else
  102.     {
  103.         EnableItem(gWipesMenu, caste1Item);
  104.         EnableItem(gWipesMenu, rippleItem);
  105.         EnableItem(gWipesMenu, dissolveItem);
  106.         EnableItem(gWipesMenu, caste2Item);
  107.     }
  108.     
  109.     if (gIsReversed)
  110.     {
  111.         DisableItem(gWipesMenu, spiralItem);
  112.         DisableItem(gAdditionsMenu, serendipityItem);
  113.         DisableItem(gAdditionsMenu, bulgeItem);
  114.         DisableItem(gScrollMenu, scrollInItem);
  115.         DisableItem(gScrollMenu, splitScrollItem);
  116.     }
  117.     else
  118.     {
  119.         EnableItem(gWipesMenu, spiralItem);
  120.         EnableItem(gAdditionsMenu, serendipityItem);
  121.         EnableItem(gAdditionsMenu, bulgeItem);
  122.         EnableItem(gScrollMenu, scrollInItem);
  123.         EnableItem(gScrollMenu, splitScrollItem);
  124.     }
  125.     
  126.     CheckItem(gFluffMenu, effectsOnlyItem, (gWipeStatus==kEffectsOnly));
  127.     CheckItem(gFluffMenu, effectsPlusFadesItem, (gWipeStatus==kFadesPlusEffects));
  128.     CheckItem(gFluffMenu, reverseEffectsPlusFadesItem, (gWipeStatus==kFadesPlusReverseEffects));
  129.     CheckItem(gFluffMenu, fullScreenFadesItem, (gWipeStatus==kFullScreen));
  130.     CheckItem(gFluffMenu, soundToggle, gSoundToggle&&gSoundAvailable);
  131.     if (gSoundAvailable)
  132.         EnableItem(gFluffMenu, soundToggle);
  133.     else
  134.         DisableItem(gFluffMenu, soundToggle);
  135. }
  136.  
  137. void HandleMenu(long mSelect)
  138. {
  139.     int            menuID = HiWord(mSelect);
  140.     int            menuItem = LoWord(mSelect);
  141.     
  142.     if (menuID==0)
  143.     {
  144.         menuID=HiWord(menuDisable);
  145.         menuItem=LoWord(menuDisable);
  146.         gMenuEnabled=FALSE;
  147.     }
  148.     else gMenuEnabled=TRUE;
  149.     menuDisable=0L;
  150.  
  151.     switch (menuID)
  152.     {
  153.         case appleMenu:
  154.             HandleAppleMenu(menuItem);
  155.             break;
  156.         case fileMenu:
  157.             HandleFileMenu(menuItem);
  158.             break;    
  159.         case editMenu:
  160.             HandleEditMenu(menuItem);
  161.             break;
  162.         case wipesMenu:
  163.             HandleWipesMenu(menuItem);
  164.             break;
  165.         case additionsMenu:
  166.             HandleAdditionsMenu(menuItem);
  167.             break;
  168.         case scrollMenu:
  169.             HandleScrollMenu(menuItem);
  170.             break;
  171.         case helpMenu:
  172.             HandleHelpMenu(menuItem);
  173.             break;
  174.         case fluffMenu:
  175.             HandleFluffMenu(menuItem);
  176.             break;
  177.         case crashMenu:
  178.             HandleCrashMenu(menuItem);
  179.             break;
  180.     }
  181. }
  182.  
  183. void HandleAppleMenu(int menuItem)
  184. {
  185.     GrafPtr        savePort;
  186.     Str255        name;
  187.     
  188.     if(menuItem == 1)
  189.         ShowInformation();
  190.     if (menuItem == 2)
  191.         ShowSplashScreen();
  192.     else if(menuItem > 4)
  193.     {
  194.         GetPort(&savePort);
  195.         GetItem(gAppleMenu, menuItem, name);
  196.         OpenDeskAcc(name);
  197.         SetPort(savePort);
  198.     }
  199. }
  200.  
  201. void HandleFileMenu(int menuItem)
  202. {
  203.     WindowPtr            theWindow;
  204.     int                    i;
  205.     Boolean                gotone;
  206.     
  207.     switch (menuItem)
  208.     {
  209.         case openItem:
  210.             if (gMenuEnabled)
  211.                 OpenTheWindow(kMainWindow);
  212.             else
  213.                 DoSound(sound_fluff, TRUE);
  214.             break;
  215.         case closeItem:
  216.             if (gMenuEnabled)
  217.             {
  218.                 theWindow=FrontWindow();
  219.                 gotone=FALSE;
  220.                 for (i=0; (i<NUM_WINDOWS) && (!gotone); i++)
  221.                     gotone=(theWindow==gTheWindow[i]);
  222.                     
  223.                 if (gotone)
  224.                     CloseTheWindow(i-1);
  225.                 else
  226.                     DisposeWindow(theWindow);
  227.                 
  228.                 AdjustMenus();
  229.             }
  230.             else DoSound(sound_fluff, TRUE);
  231.             break;
  232.         case disableQuitItem:
  233.             if (gMenuEnabled)
  234.             {
  235.                 gDisableQuit=TRUE;
  236.                 AdjustMenus();
  237.             }
  238.             else DoSound(sound_fluff, TRUE);
  239.             break;
  240.         case enableQuitItem:
  241.             if (gMenuEnabled)
  242.             {
  243.                 gDisableQuit=FALSE;
  244.                 AdjustMenus();
  245.             }
  246.             else DoSound(sound_fluff, TRUE);
  247.             break;
  248.         case quitItem:
  249.             gDone = TRUE;
  250.             break;
  251.     }
  252. }
  253.  
  254. void HandleEditMenu(int menuItem)
  255. {
  256.     if ((menuItem>0) && (menuItem!=2))
  257.     {
  258.         if (gMenuEnabled)
  259.             SystemEdit(menuItem - 1);
  260.         else DoSound(sound_fluff, TRUE);
  261.     }
  262. }
  263.  
  264. void HandleWipesMenu(int menuItem)
  265. {
  266.     if ((menuItem>0) && (menuItem<=13))
  267.     {
  268.         if (gMenuEnabled)
  269.         {
  270.             if (gWipeStatus==kFullScreen)
  271.                 DoFullScreenFade(menuItem, TRUE);
  272.             else
  273.             {
  274.                 OpenTheWindow(kMainWindow);
  275.                 gWhichWipe=menuItem;
  276.                 OpenTheWindow(kMainWindow);
  277.             }
  278.         }
  279.         else DoSound(sound_fluff, TRUE);
  280.     }
  281. }
  282.  
  283. void HandleAdditionsMenu(int menuItem)
  284. {
  285.     if ((menuItem>0) && (menuItem<=11))
  286.     {
  287.         if (gMenuEnabled)
  288.         {
  289.             if (gWipeStatus==kFullScreen)
  290.                 DoFullScreenFade(menuItem+13, TRUE);
  291.             else
  292.             {
  293.                 OpenTheWindow(kMainWindow);
  294.                 gWhichWipe=menuItem+13;
  295.                 OpenTheWindow(kMainWindow);
  296.             }
  297.         }
  298.         else DoSound(sound_fluff, TRUE);
  299.     }
  300. }
  301.  
  302. void HandleScrollMenu(int menuItem)
  303. {
  304.     if ((menuItem>0) && (menuItem<=8))
  305.     {
  306.         if (gMenuEnabled)
  307.         {
  308.             if (gWipeStatus==kFullScreen)
  309.                 DoFullScreenFade(menuItem+24, TRUE);
  310.             else
  311.             {
  312.                 OpenTheWindow(kMainWindow);
  313.                 gWhichWipe=menuItem+24;
  314.                 OpenTheWindow(kMainWindow);
  315.             }
  316.         }
  317.         else DoSound(sound_fluff, TRUE);
  318.     }
  319. }
  320.  
  321. void HandleHelpMenu(int menuItem)
  322. {
  323.     if ((menuItem>0) && (menuItem<=gNumHelp))
  324.     {
  325.         gWhichHelp=menuItem;
  326.         UpdateHelpWindow();
  327.     }
  328. }
  329.  
  330. void HandleFluffMenu(int menuItem)
  331. {
  332.     switch (menuItem)
  333.     {
  334.         case repeatItem:
  335.             if (gMenuEnabled)
  336.             {
  337.                 if (gWipeStatus==kFullScreen)
  338.                     DoFullScreenFade(gLastWipe, TRUE);
  339.                 else
  340.                 {
  341.                     OpenTheWindow(kMainWindow);
  342.                     gWhichWipe=gLastWipe;
  343.                     OpenTheWindow(kMainWindow);
  344.                 }
  345.             }
  346.             else DoSound(sound_fluff, TRUE);
  347.             break;
  348.         case soundToggle:
  349.             if (gMenuEnabled)
  350.             {
  351.                 gSoundToggle=!gSoundToggle;
  352.                 SaveThePrefs();
  353.                 DoSound(sound_on, TRUE);
  354.             }
  355.             break;
  356.         case effectsOnlyItem:
  357.             gWipeStatus=kEffectsOnly;
  358.             SaveThePrefs();
  359.             break;
  360.         case effectsPlusFadesItem:
  361.             gWipeStatus=kFadesPlusEffects;
  362.             SaveThePrefs();
  363.             break;
  364.         case reverseEffectsPlusFadesItem:
  365.             gWipeStatus=kFadesPlusReverseEffects;
  366.             SaveThePrefs();
  367.             break;
  368.         case fullScreenFadesItem:
  369.             gWipeStatus=kFullScreen;
  370.             SaveThePrefs();
  371.             break;
  372.         case reverseToggle:
  373.             gIsReversed=!gIsReversed;
  374.             SaveThePrefs();
  375.             ReverseAllWipes();
  376.             break;
  377.     }
  378. }
  379.  
  380. void HandleCrashMenu(int menuItem)
  381. {
  382.     if (menuItem>0)
  383.         CrashAndBurn(menuItem);
  384. }
  385.  
  386. void ReverseAllWipes(void)
  387. {
  388.     int                whichMenu, whichItem, i;
  389.     MenuHandle        thisMenu;
  390.     Str255            thisName;
  391.     char            thisChar;
  392.     
  393.     for (whichMenu=0; whichMenu<3; whichMenu++)
  394.     {
  395.         switch (whichMenu)
  396.         {
  397.             case 0:    thisMenu=gWipesMenu;        break;
  398.             case 1:    thisMenu=gAdditionsMenu;    break;
  399.             case 2:    thisMenu=gScrollMenu;        break;
  400.         }
  401.         
  402.         for (whichItem=CountMItems(thisMenu); whichItem>0; whichItem--)
  403.         {
  404.             GetItem(thisMenu, whichItem, thisName);
  405.             for (i=thisName[0]; i>thisName[0]/2; i--)
  406.             {
  407.                 thisChar=thisName[i];
  408.                 thisName[i]=thisName[thisName[0]-i+1];
  409.                 thisName[thisName[0]-i+1]=thisChar;
  410.             }
  411.             SetItem(thisMenu, whichItem, thisName);
  412.         }
  413.     }
  414. }
  415.