home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / Aidan's Class Libraries / Source / Action / EventDispatcher.cpp < prev    next >
Encoding:
Text File  |  1997-07-20  |  2.1 KB  |  101 lines  |  [TEXT/CWIE]

  1. //Copyright (c) 1997 Aidan Cully
  2. //All rights reserved
  3.  
  4. #include "CLEventDispatcher.h"
  5. #include "CLBaseWindow.h"
  6. #include "CLActionHandler.h"
  7. #include "CLMouseHandler.h"
  8. #include "CLKeyboardHandler.h"
  9. #include "CLApplication.h"
  10.  
  11. MEventDispatcher *MEventDispatcher::sCurDispatcher= 0;
  12. TDeviceHandler *MEventDispatcher::mhHandlers[16];
  13.  
  14. MEventDispatcher::MEventDispatcher():
  15.     mhDone( false )
  16. {
  17. }
  18.  
  19. MEventDispatcher::~MEventDispatcher()
  20. {
  21. }
  22.  
  23. BOOLEAN MEventDispatcher::Run()
  24. {
  25.     return( RunSelf() );
  26. }
  27.  
  28. void MEventDispatcher::SetDeviceHandler( UINT16 evMask, TDeviceHandler *handler ) {
  29.     int temp;
  30.  
  31.     for( temp = nullEvent; temp <= osEvt; temp++ )
  32.         if( evMask&(1<<temp) )
  33.             mhHandlers[temp] = handler;
  34. }
  35.  
  36. void MEventDispatcher::EventLoop()
  37. {
  38.     EventRecord event;
  39.     Point pt;
  40.     GWorldPtr globWorld, world;
  41.     GDHandle globDevice, device;
  42.     GrafPtr globPort, port;
  43.     MEventDispatcher *oldDispatcher= sCurDispatcher;
  44.  
  45.     sCurDispatcher= this;
  46.     TApplication::SCurApp()->GetGlobalWorld( globWorld, globDevice );
  47.     globPort= TApplication::SCurApp()->GetGlobalPort();
  48.  
  49.     for( int i=0; i<16; i++ )
  50.         if( mhHandlers[i] )
  51.             mhHandlers[i]->NewDispatcher();
  52.     if( Run() )
  53.         while( !mhDone ) {
  54.             ::WaitNextEvent( everyEvent, &event, 10, TMouseHandler::SGetMouse()->MouseMoveRgn() );
  55.             TKeyboardHandler::GetKeyboard()->mModifiers= event.modifiers;
  56.             DispatchEvent( event );
  57.         }
  58.     sCurDispatcher= oldDispatcher;
  59.     for( int i=0; i<16; i++ )
  60.         if( mhHandlers[i] )
  61.             mhHandlers[i]->OldDispatcher();
  62. }
  63.  
  64. void MEventDispatcher::DispatchEvent( const EventRecord &event )
  65. {
  66.     WindowRef theWindow;
  67.     short partCode;
  68.  
  69.     switch( event.what )
  70.     {
  71.     case updateEvt:
  72.         ((TBaseWindow*)GetWRefCon((WindowRef)event.message))->DoUpdate();
  73.         break;
  74.     default:
  75.         if( (event.what <= osEvt) && mhHandlers[event.what] )
  76.             mhHandlers[event.what]->DispatchEvent( event );
  77.     }
  78. }
  79.  
  80. BOOLEAN MEventDispatcher::AttemptQuit()
  81. {
  82.     BOOLEAN ret= AttemptQuitSelf();
  83.     if( ret )
  84.         Quit();
  85.     return( ret );
  86. }
  87.  
  88. BOOLEAN MEventDispatcher::AttemptQuitSelf()
  89. {
  90.     return( true );
  91. }
  92.  
  93. void MEventDispatcher::Quit()
  94. {
  95.     QuitSelf();
  96.     mhDone= true;
  97. }
  98.  
  99. void MEventDispatcher::QuitSelf()
  100. {
  101. }