home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / RandomDot 1.1.0 / source / Menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-07  |  3.9 KB  |  197 lines  |  [TEXT/KAHL]

  1. /* Menu.c - code for handling the menubar in RandomDot
  2.     by David Phillip Oster October 1994 oster@netcom.com
  3.     for:
  4.     Stuart Inglis singlis@waikato.ac.nz
  5.     Department of Computer Science
  6.     University of Waikato, Hamilton, New Zealand
  7.  */
  8. #ifndef __IMAGECOMPRESSION__
  9. #include <ImageCompression.h>
  10. #endif    /* __IMAGECOMPRESSION__ */
  11.  
  12. #ifndef __GESTALTEQU__
  13. #include <GestaltEqu.h>
  14. #endif    /* __GESTALTEQU__ */
  15.  
  16. #ifndef __BALLOONS__
  17. #include <Balloons.h>
  18. #endif    /* __BALLOONS__ */
  19.  
  20. #include "RandomDotMain.h"
  21. #include "RandomDotRes.h"
  22.  
  23. #include "RandomDotWin.h"
  24. #include "RandomDotWinCommands.h"
  25. #include "RandomDotPrint.h"
  26. #include "Error.h"
  27. #include "Menu.h"
  28. #include "Help.h"
  29. #include "Progress.h"
  30. #include "Utils.h"
  31. #include "pgm.h"
  32.  
  33. static Integer myHelpItem = -2;
  34.  
  35.  
  36. /* GetAboutWin - 
  37.  */
  38. static WindowPtr GetAboutWin(void){
  39.     WindowPtr    win;
  40.  
  41.     win = GetNewDialog(rAbout, NIL, (WindowPtr) -1L);
  42.     ShowWindow(win);
  43.     SelectWindow(win);
  44.     return win;
  45. }
  46.  
  47. /* DoAppleMenu - 
  48.  */
  49. static void DoAppleMenu(Integer item){
  50.     Str255        s;
  51.     WindowPtr    win;
  52.  
  53.     if(1 == item){
  54.         win = GetAboutWin();
  55.         SetDialogDefaultItem(win, kOK);
  56.         ModalDialog(NIL, &item);
  57.         DisposeWindow(win);
  58.         if(kOK != item){
  59.             DoHelp();
  60.         }
  61.     }else{
  62.         GetItem(GetMHandle(kAppleMenu), item, s);
  63.         OpenDeskAcc(s);
  64.     }
  65. }
  66.  
  67. /* OpenFileFilterProc - return FALSE if we should show the file.
  68.     i.e., we show PICT files and PGM files
  69.  */
  70. static pascal Boolean OpenFileFilterProc(ParmBlkPtr io){
  71.     return NOT ('PICT' == io->fileParam.ioFlFndrInfo.fdType ||
  72.         IsPGMFile(io));
  73. }
  74.  
  75.  
  76. /* DoOpen - 
  77.  */
  78. void DoOpen(void){
  79.     LongInt                attr;
  80.     StandardFileReply    reply;
  81.     static    OSType    applType[] = { 'PICT' };
  82.     static    FileFilterUPP    fileFilter = NIL;
  83.  
  84.     if(NIL == fileFilter)
  85.     {
  86.         fileFilter = NewFileFilterProc(OpenFileFilterProc);
  87.     }
  88.     StandardGetFile(fileFilter, 0, applType, &reply);
  89.     if(reply.sfGood)
  90.     {
  91.         TellError(RandomDotOpen(&reply.sfFile, reply.sfScript));
  92.     }
  93. }
  94.  
  95. void DoCloseWin(WindowPtr win){
  96.     if(NIL == win){
  97.         /* empty */
  98.     }else if(userKind == ((WindowPeek) win)->windowKind){
  99.         RandomDotDisposeWindow(win);
  100.     }else{
  101.         HideWindow(win);
  102.     }
  103. }
  104.  
  105. void DoClose(void){
  106.     WindowPtr    win;
  107.  
  108.     if(NIL != (win = FrontWindow())){
  109.         DoCloseWin(win);
  110.     }
  111. }
  112.  
  113.  
  114. /* DoQuit - do a quit command
  115.  */
  116. void DoQuit(void){
  117.     RecordProgress();
  118.     ExitToShell();
  119. }
  120.  
  121. /* DoFileMenu - 
  122.  */
  123. static void DoFileMenu(Integer item){
  124.     switch(item){
  125.     case kOpenI:        DoOpen();        break;
  126.     case kCloseI:        DoClose();        break;
  127.     case kSaveI:        DoRandomDotSave();        break;
  128.     case kSaveAsI:        DoRandomDotSaveAs();    break;
  129.     case kPageSetupI:    DoRandomDotPageSetup();    break;
  130.     case kPrintI:        DoRandomDotPrint();        break;
  131.     case kQuitI:        DoQuit();        break;
  132.     }
  133. }
  134.  
  135. /* DoEditMenu - 
  136.  */
  137. static void DoEditMenu(Integer item){
  138.     if(NOT SystemEdit(item - 1)){
  139.         switch(item){
  140.         case kUndoI:    break;
  141.         case kCutI:        DoRandomDotCut();    break;
  142.         case kCopyI:    DoRandomDotCopy();    break;
  143.         case kPasteI:    DoRandomDotPaste();    break;
  144.         case kClearI:    break;
  145.             break;
  146.         }
  147.     }
  148. }
  149.  
  150. /* DoRandomDotMenu - 
  151.  */
  152. static void DoRandomDotMenu(Integer item){
  153.     switch(item){
  154.     case kGrayI:        DoRandomDotGrayState();            break;
  155.     case kBWStereoI:    DoRandomDotBWStereoState();        break;
  156.     case kGrayStereoI:    DoRandomDotGrayStereoState();    break;
  157.     case kShimmerI:        DoRandomDotShimmer();            break;
  158.     }
  159. }
  160.  
  161. /* InitHelpItem - augment the help menu with our item, for system 7 only.
  162.  */
  163. void InitHelpItem(void){
  164.     MenuHandle    mh;
  165.     Str255        sName;
  166.  
  167.     if(noErr == HMGetHelpMenuHandle(&mh)){
  168.         GetIndString(sName, kMainStrs, kOurHelpS);
  169.         AppendMenu(mh, sName);
  170.         myHelpItem = CountMItems(mh);
  171.     }
  172. }
  173.  
  174. /* DoHelpMenu - do items added to help menu.
  175.  */
  176. static void DoHelpMenu(Integer item){
  177.     if(item == myHelpItem){
  178.         DoHelp();
  179.     }
  180. }
  181.  
  182. /* GoMenu - do one menu command
  183.  */
  184. void GoMenu(LongInt selector){
  185.     Integer    theLow;
  186.  
  187.     theLow = LoWord(selector);
  188.     switch(HiWord(selector)){
  189.     case kAppleMenu:    DoAppleMenu(theLow);        break;
  190.     case kFileMenu:        DoFileMenu(theLow);            break;
  191.     case kEditMenu:        DoEditMenu(theLow);            break;
  192.     case kRandomDotMenu:DoRandomDotMenu(theLow);    break;
  193.     case kHMHelpMenuID:    DoHelpMenu(theLow);            break;
  194.     }
  195.     HiliteMenu(0);
  196. }
  197.