home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / StandardGetFolder / Bullseye Get Folder source / bullseye.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-28  |  2.6 KB  |  159 lines  |  [TEXT/KAHL]

  1. /*****
  2.  * bullseye.c
  3.  *
  4.  *    A simple demonstration program to play with the debugger
  5.  *
  6.  *
  7.  *****/
  8.  
  9. #include "bullMenus.h"
  10. #include "bullWindow.h"
  11.  
  12. extern    WindowPtr    bullseyeWindow;
  13. extern    Rect        dragRect;
  14.  
  15. void InitMacintosh(void);
  16. void HandleMouseDown (EventRecord    *theEvent);
  17. void HandleEvent(void);
  18.  
  19. /****
  20.  * InitMacintosh()
  21.  *
  22.  * Initialize all the managers & memory
  23.  *
  24.  ****/
  25.  
  26. void InitMacintosh(void)
  27.  
  28. {
  29.     MaxApplZone();
  30.     
  31.     InitGraf(&thePort);
  32.     InitFonts();
  33.     FlushEvents(everyEvent, 0);
  34.     InitWindows();
  35.     InitMenus();
  36.     TEInit();
  37.     InitDialogs(0L);
  38.     InitCursor();
  39.  
  40. }
  41. /* end InitMacintosh */
  42.  
  43.  
  44. /****
  45.  * HandleMouseDown (theEvent)
  46.  *
  47.  *    Take care of mouseDown events.
  48.  *
  49.  ****/
  50.  
  51. void HandleMouseDown (EventRecord    *theEvent)
  52.  
  53. {
  54.     WindowPtr    theWindow;
  55.     int            windowCode = FindWindow (theEvent->where, &theWindow);
  56.     
  57.     switch (windowCode)
  58.       {
  59.       case inSysWindow: 
  60.         SystemClick (theEvent, theWindow);
  61.         break;
  62.         
  63.       case inMenuBar:
  64.           AdjustMenus();
  65.         HandleMenu(MenuSelect(theEvent->where));
  66.         break;
  67.         
  68.       case inDrag:
  69.           if (theWindow == bullseyeWindow)
  70.             DragWindow(bullseyeWindow, theEvent->where, &dragRect);
  71.             break;
  72.             
  73.       case inContent:
  74.           if (theWindow == bullseyeWindow)
  75.             {
  76.             if (theWindow != FrontWindow())
  77.               SelectWindow(bullseyeWindow);
  78.             else
  79.               InvalRect(&bullseyeWindow->portRect);
  80.             }
  81.           break;
  82.           
  83.       case inGoAway:
  84.           if (theWindow == bullseyeWindow && 
  85.               TrackGoAway(bullseyeWindow, theEvent->where))
  86.           HideWindow(bullseyeWindow);
  87.             break;
  88.       }
  89. }
  90. /* end HandleMouseDown */
  91.  
  92.  
  93. /****
  94.  * HandleEvent()
  95.  *
  96.  *        The main event dispatcher. This routine should be called
  97.  *        repeatedly (it  handles only one event).
  98.  *
  99.  *****/
  100.  
  101. void HandleEvent(void)
  102.  
  103. {
  104.     int            ok;
  105.     EventRecord    theEvent;
  106.  
  107.     HiliteMenu(0);
  108.     SystemTask ();        /* Handle desk accessories */
  109.     
  110.     ok = GetNextEvent (everyEvent, &theEvent);
  111.     if (ok)
  112.       switch (theEvent.what)
  113.         {
  114.         case mouseDown:
  115.             HandleMouseDown(&theEvent);
  116.             break;
  117.             
  118.         case keyDown: 
  119.         case autoKey:
  120.             if ((theEvent.modifiers & cmdKey) != 0)
  121.               {
  122.               AdjustMenus();
  123.               HandleMenu(MenuKey((char) (theEvent.message & charCodeMask)));
  124.               }
  125.             break;
  126.             
  127.         case updateEvt:
  128.             BeginUpdate(bullseyeWindow);
  129.             DrawBullseye(((WindowPeek) bullseyeWindow)->hilited);
  130.             EndUpdate(bullseyeWindow);
  131.             break;
  132.             
  133.         case activateEvt:
  134.             InvalRect(&bullseyeWindow->portRect);
  135.             break;
  136.         }
  137. }
  138. /* end HandleEvent */
  139.  
  140.  
  141. /*****
  142.  * main()
  143.  *
  144.  *    This is where everything happens
  145.  *
  146.  *****/
  147.  
  148.  
  149. main()
  150.  
  151. {
  152.     InitMacintosh();
  153.     SetUpMenus();
  154.     SetUpWindow();
  155.     
  156.     for (;;)
  157.         HandleEvent();
  158. }
  159. /* end main */