home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / The Hacks! / Talking KeyBoard / Source / event.c < prev    next >
Encoding:
Text File  |  1998-06-17  |  2.7 KB  |  124 lines  |  [TEXT/CWIE]

  1. // Program Author: Paul Baxter
  2. //    pbaxter@assistivetech.com
  3. //
  4. //
  5. #include <Speech.h>
  6. #include <Ctype.h>
  7. #include <DeskBus.h>
  8. #include <Retrace.h>
  9.  
  10. #include "filter.h"
  11. #include "adb.h"
  12. #include "pref.h"
  13. #include "globals.h"
  14. #include "menu.h"
  15. #include "speech.h"
  16. #include "event.h"
  17. #include "DeferredTask.h"
  18.  
  19. // * ****************************************************************************** *
  20. // *    EventLoop
  21. // *                            Main Event loop
  22. // * ****************************************************************************** *
  23. void EventLoop(void)
  24. {
  25.     EventRecord theEvent;
  26.  
  27.     do {
  28.         WaitNextEvent(everyEvent, &theEvent, 15, 0);
  29.         HandleEvent (&theEvent);
  30.     } while (!gQuitting);
  31. }
  32.  
  33. // * ****************************************************************************** *
  34. // *     HandleEvent
  35. // *                Handle One Event or One Fowarded Event from filter
  36. // * ****************************************************************************** *
  37. void HandleEvent(EventRecord* theEvent)
  38. {
  39.     WindowPtr whichWin, frontWin;
  40.     char theKey, theChar;
  41.     short thePart;
  42.     Boolean fowardedEvent;
  43.  
  44.  
  45.     fowardedEvent = (theEvent->what != nullEvent) ? false :  GetFowardedEvent(theEvent);
  46.  
  47.     switch (theEvent->what) {
  48.         case mouseDown:
  49.             if (!fowardedEvent)  {
  50.                 thePart = FindWindow(theEvent->where, &whichWin);
  51.                 frontWin = FrontWindow();
  52.                 switch(thePart) {
  53.                     case inMenuBar:
  54.                         DoMenuItem(MenuSelect(theEvent->where));
  55.                         break;
  56.  
  57.                     case inSysWindow:
  58.                         SystemClick(theEvent, whichWin);
  59.                         break;
  60.  
  61.                     default:
  62.                         break;
  63.                 }
  64.             }
  65.             else {
  66.                 AppendWordBuffer('.');
  67.                 AppendSentenceBuffer('.');
  68.             }
  69.             break;
  70.  
  71.         case keyDown:
  72.             theChar = theEvent->message & charCodeMask;
  73.             theKey = (theEvent->message & keyCodeMask) >> 8;
  74.             if (fowardedEvent) {
  75.                 AppendWordBuffer(theChar);
  76.                 AppendSentenceBuffer(theChar);
  77.  
  78.             }
  79.             else {
  80.                 if (theEvent->modifiers & cmdKey) {
  81.                     DoMenuItem(MenuKey(theChar));
  82.                 }
  83.             }
  84.             break;
  85.  
  86.         case kHighLevelEvent:
  87.             AEProcessAppleEvent(theEvent);
  88.             break;
  89.  
  90.         case osEvt:
  91.             InitCursor();
  92.  
  93.         default:
  94.             break;
  95.     }
  96.     if (fowardedEvent)
  97.         SpeakBuffers();
  98. }
  99.  
  100.  
  101. // * ****************************************************************************** *
  102. // *     GetFowardedEvent
  103. // *                            Get an event fowarded by our filter
  104. // * ****************************************************************************** *
  105. Boolean GetFowardedEvent(EventRecord *theEvent)
  106. {
  107.     Boolean fowardEvent = false;
  108.     short err=0;
  109.     EvQEl *fwdEvent=0;
  110.     
  111.     // Extract any forwarded events... and treat them as normal
  112.     if ((fwdEvent = (EvQEl *) gForwardedEvents.qHead) != nil)
  113.         err = Dequeue((QElemPtr) fwdEvent, &gForwardedEvents);
  114.  
  115.     if (fwdEvent && !err) {
  116.         BlockMove(&fwdEvent->evtQWhat, theEvent, sizeof(EventRecord));
  117.         DisposePtr((Ptr) fwdEvent);
  118.         
  119.         fowardEvent = true;
  120.     }
  121.         
  122.     return(fowardEvent);
  123. }
  124.