home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / macraysh.sit / Code / Source / machandler.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-18  |  2.4 KB  |  121 lines

  1. /*
  2.  * machandler.c
  3.  *
  4.  * Handles all IO events directed to us by the operating system, and passes them on to specialised
  5.  * procedures.
  6.  *
  7.  */
  8.  
  9. #include <MacHeaders>
  10. #include <Controls.h>
  11. #include <Events.h>
  12. #include <Dialogs.h>
  13. #include "geom.h"
  14. #include "macmenus.h"
  15. #include "maceditor.h"
  16.  
  17. extern WindowPtr imageWindow, informationWindow;
  18. extern DialogPtr editorDialog ;
  19. extern struct menuinfo menuInfo ;
  20.  
  21. void HandleMouseDown (EventRecord    *theEvent);
  22. void HandleEvent(void);
  23.  
  24. Rect dragRect = { 0, 0, 1024, 1024 };
  25.  
  26. void HandleEditorEvent(EventRecord    *theEvent) ;
  27. extern ControlHandle SnatchHandle(DialogPtr thebox, short theGetItem) ;
  28.  
  29.  
  30. /*
  31.  * HandleEvent()
  32.  *
  33.  *        The main event dispatcher. This routine should be called
  34.  *        repeatedly (it  handles only one event).
  35.  *
  36.  */
  37.  
  38. void HandleEvent(void)
  39. {
  40.     DialogPtr theDialog;
  41.     short dialogItem ;
  42.     int ok;
  43.     EventRecord    theEvent;
  44.  
  45.     SystemTask();        /* Handle desk accessories */
  46.     ok = GetNextEvent(everyEvent, &theEvent);
  47.     if (ok) {
  48.         if (IsDialogEvent(&theEvent)) {
  49.             HandleEditorEvent(&theEvent) ;
  50.         }
  51.         else {
  52.             switch (theEvent.what) {
  53.             case mouseDown:
  54.                 HandleMouseDown(&theEvent);
  55.                 break;
  56.             case keyDown: 
  57.             case autoKey:
  58.                 if ((theEvent.modifiers & cmdKey) != 0) {
  59.                     AdjustMenus();
  60.                     HandleMenu(MenuKey((char) (theEvent.message & charCodeMask)));
  61.                 }
  62.                 break;
  63.             case updateEvt:
  64.                 UpdateWind() ;
  65.                 UpdateEditor() ;
  66.                 break;
  67.             case activateEvt:
  68.                 break;
  69.             default:
  70.                 break ;
  71.             }
  72.         }
  73.     }
  74. }
  75.  
  76. /*
  77.  * HandleMouseDown (theEvent)
  78.  *
  79.  *    Take care of mouseDown events.
  80.  *
  81.  */
  82.  
  83. void HandleMouseDown (EventRecord    *theEvent)
  84.  
  85. {
  86.     WindowPtr theWindow;
  87.     int windowCode  ;
  88.     
  89.     windowCode = FindWindow(theEvent->where, &theWindow);
  90.     switch (windowCode) {
  91.         case inSysWindow: 
  92.             SystemClick (theEvent, theWindow);
  93.             break;
  94.         case inMenuBar:
  95.             HandleMenu(MenuSelect(theEvent->where));
  96.             AdjustMenus();
  97.             HiliteMenu(0);
  98.             break;
  99.         case inDrag:
  100.             DragWindow(theWindow, theEvent->where, &dragRect);
  101.             break;
  102.         case inContent:
  103.             if (theWindow != FrontWindow()) ;
  104.                 SelectWindow(theWindow);
  105.             break;
  106.         case inGoAway:
  107.             if (theWindow && (theWindow == imageWindow) && !menuInfo.rendering) {
  108.                 if (TrackGoAway(theWindow, theEvent->where))
  109.                     CloseMacWindow() ;
  110.             }
  111.             break;
  112.         case inGrow:
  113.             if(theWindow && (theWindow == imageWindow) && !menuInfo.rendering)
  114.                 SizeImage(theEvent->where) ;
  115.             break ;
  116.         default:
  117.             break ;
  118.     }
  119. }
  120. /* end HandleMouseDown */
  121.