home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / SoundSwirl / dostuff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-15  |  5.1 KB  |  281 lines  |  [TEXT/KAHL]

  1. /***************************
  2. ** dostuff.c
  3. **
  4. ** Contains all the DoXxxx() routines
  5. ** for the application.
  6. ***************************/
  7.  
  8. #define kHighLevelEvent 23    /* from Inside mac, volume 6 */
  9.  
  10. #include "main.h"
  11.  
  12.  
  13. /******************
  14. ** DoEvent()
  15. ** 
  16. ** Determines the type of event and dispatches it
  17. ** to the correct event handler.
  18. *******************/
  19. void DoEvent(EventRecord *theEvent)
  20. {
  21.     switch (theEvent->what) {
  22.         case mouseDown:
  23.             DoMouseDown(theEvent);
  24.             break;
  25.         case keyDown:
  26.         case autoKey:
  27.             DoKey(theEvent);
  28.             break;
  29.         case activateEvt:
  30.             break;
  31.         case updateEvt:
  32.             if (gMainWindow != NULL)
  33.             {
  34.                 BeginUpdate(gMainWindow);
  35.                 EraseRect( &(gMainWindow->portRect));
  36.                 /* DrawControls(gMainWindow);  */
  37.                 /* DrawGrowIcon( gMainWindow); */
  38.                 /** do other window drawing here **/
  39.                 EndUpdate(gMainWindow);
  40.             }
  41.             break;
  42.         case osEvt:
  43.             break;
  44.         case kHighLevelEvent:
  45.             break;
  46.     }
  47. } /* DoEvent() */
  48.  
  49.  
  50. /********************
  51. ** DoMouseDown()
  52. **
  53. ** handles mouseDown events.
  54. *********************/
  55.  
  56. void DoMouseDown(EventRecord *theEvent)
  57. {
  58.     WindowPtr whichWindow;
  59.     
  60.     switch (FindWindow( theEvent->where, &whichWindow)) {
  61.         case inSysWindow:
  62.             SystemClick( theEvent, whichWindow);
  63.             break;
  64.         case inMenuBar:
  65.             DoCommand( MenuSelect(theEvent->where) );
  66.             break;
  67.         case inDrag:
  68.             DragWindow(whichWindow, theEvent->where,
  69.                 &qd.screenBits.bounds);
  70.             break;
  71.         case inContent:
  72.             DoContent(theEvent);
  73.             break;
  74.         case inGoAway:
  75.             if (TrackGoAway(whichWindow, theEvent->where))
  76.                 DoFileClose();
  77.             break;
  78.     }
  79. } /* DoMouseDown() */
  80.  
  81.  
  82. /*****************
  83. ** DoCommand()
  84. **
  85. ** executes the menu options.
  86. ******************/
  87.  
  88. void DoCommand(long mResult)
  89. {
  90.     int theItem = LoWord(mResult);
  91.     int theMenu = HiWord(mResult);
  92.     Str255 name;
  93.     int temp;
  94.     
  95.     switch (theMenu) {
  96.         case APPLE_MENU:
  97.             if (theItem == AppleAboutItem) {
  98.                 DoAbout();
  99.             } else {
  100.                 GetItem( gAppleM, theItem, name);
  101.                 temp = OpenDeskAcc(name);
  102.             }
  103.             break;
  104.             
  105.         case FILE_MENU:
  106.             switch (theItem) {
  107.                 case FileNewItem:
  108.                     DoFileNew();
  109.                     break;
  110.                 case FileOpenItem:
  111.                     break;
  112.                 case FileCloseItem:
  113.                     DoFileClose();
  114.                     break;
  115.                 case FileSaveItem:
  116.                 case FileSaveAsItem:
  117.                     break;
  118.                 case FileQuitItem:
  119.                     Cleanup();
  120.                     break;
  121.             } /* switch theItem */
  122.             break;
  123.             
  124.         case EDIT_MENU:
  125.             switch (theItem) {
  126.                 case EditUndoItem:
  127.                     break;
  128.                 case EditCopyItem:
  129.                     break;
  130.                 case EditCutItem:
  131.                     break;
  132.                 case EditPasteItem:
  133.                     break;
  134.                 case EditClearItem:
  135.                     break;
  136.             } /* switch */
  137.             break;
  138.             
  139.         case LISTEN_MENU:
  140.             switch (theItem) {
  141.                 case ListenBegin:  /* begin listening */
  142.                     gListening = 1;
  143.                     SndListenBegin();
  144.                     DisableItem( gListenM, ListenBegin);
  145.                     EnableItem(  gListenM, ListenStop);
  146.                     break;
  147.                 case ListenStop:   /* stop listening */
  148.                     gListening = 0;
  149.                     SndListenStop();
  150.                     EnableItem(  gListenM, ListenBegin);
  151.                     DisableItem( gListenM, ListenStop);
  152.                     break;
  153.             } /* switch */
  154.             break;
  155.             
  156.     } /* switch theMenu */
  157.     HiliteMenu(0);        /* unhilite the selected menu */
  158. } /* DoCommand() */
  159.  
  160.  
  161. /*****************
  162. ** DoAbout()
  163. **
  164. ** Displays the about box
  165. ******************/
  166.  
  167. void DoAbout(void)
  168. {
  169.     DialogPtr aboutDlog;
  170.     GrafPtr savedPort;
  171.     int itemHit = -9;
  172.     
  173.     GetPort( &savedPort);
  174.     aboutDlog = GetNewDialog(AboutDlogID, NULL, (void*)(-1) );
  175.     if (aboutDlog == NULL) return;
  176.     SelectWindow((WindowPtr)aboutDlog);
  177.     while (itemHit != AboutOKButt)
  178.         ModalDialog( NULL, &itemHit);
  179.     DisposDialog(aboutDlog);
  180.     aboutDlog = NULL;
  181.     SetPort( savedPort);
  182. } /* DoAbout() */
  183.  
  184.  
  185. /*********************
  186. ** DoFileNew()
  187. **
  188. ** executes the File menu, New option.
  189. **
  190. *****************/
  191.  
  192. void DoFileNew(void)
  193. {
  194. } /* DoFileNew() */
  195.  
  196.  
  197. /***************
  198. ** DoFileClose()
  199. **
  200. ****************/
  201.  
  202. void DoFileClose(void)
  203. {
  204. } /* DoFileClose() */
  205.  
  206.  
  207. void DoContent(EventRecord *theEvent)
  208. {
  209.     int part;
  210.     int value;
  211.     Point pt;
  212.     ControlHandle control;
  213.     
  214.     pt = theEvent->where;
  215.     GlobalToLocal(&pt);
  216.     
  217.   /* In the content area? */
  218.     if ( 1)
  219.     {
  220.     }
  221.   /* In the scroll bar? */
  222.     else
  223.     {
  224.         part = FindControl(pt, gMainWindow, &control);
  225.         switch ( part ) {
  226.             case 0:                        /* do nothing for viewRect case */
  227.                 break;
  228.             case inThumb:
  229.                 value = GetCtlValue(control);
  230.                 part = TrackControl(control, pt, NULL);
  231.                 if ( part != 0 ) {
  232.                     value -= GetCtlValue(control);
  233.                     /* value now has CHANGE in value; if value changed, scroll */
  234.                 }
  235.                 break;
  236.             default:        /* they clicked in an arrow, so track & scroll */
  237.                 break;
  238.         } /* switch */
  239.     } /* if */
  240. } /* DoContent() */
  241.  
  242.  
  243. /****************
  244. ** DoKey()
  245. **
  246. ** This is the keyDown event handler.
  247. ** 1) handle command-keys
  248. ** 2) handle keypresses for other functions
  249. *****************/
  250.  
  251. void DoKey(EventRecord *theEvent)
  252. {
  253.     char c = theEvent->message & charCodeMask;
  254.     
  255.     if ((theEvent->modifiers & cmdKey ) == cmdKey)
  256.         DoCommand(MenuKey(c));
  257.     else
  258.     {
  259.         /* pass keypress onto something else */
  260.         switch(c) {
  261.         case '+':
  262.         case '=': gRadius += 5;
  263.             break;
  264.         case '-':
  265.         case '_': gRadius -= 5;
  266.             break;
  267.         case ']': gAngleStep += PI/180.;   /* 1° in radians */
  268.             break;
  269.         case '[': gAngleStep -= PI/180.;   /* 1° in radians */
  270.             break;
  271.         case '1': HideCursor();
  272.             break;
  273.         case '2': ShowCursor();
  274.             break;
  275.         }
  276.     }
  277. } /* DoKey() */
  278.  
  279.  
  280.  
  281.