home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-20 | 2.1 KB | 101 lines | [TEXT/CWIE] |
- //Copyright (c) 1997 Aidan Cully
- //All rights reserved
-
- #include "CLEventDispatcher.h"
- #include "CLBaseWindow.h"
- #include "CLActionHandler.h"
- #include "CLMouseHandler.h"
- #include "CLKeyboardHandler.h"
- #include "CLApplication.h"
-
- MEventDispatcher *MEventDispatcher::sCurDispatcher= 0;
- TDeviceHandler *MEventDispatcher::mhHandlers[16];
-
- MEventDispatcher::MEventDispatcher():
- mhDone( false )
- {
- }
-
- MEventDispatcher::~MEventDispatcher()
- {
- }
-
- BOOLEAN MEventDispatcher::Run()
- {
- return( RunSelf() );
- }
-
- void MEventDispatcher::SetDeviceHandler( UINT16 evMask, TDeviceHandler *handler ) {
- int temp;
-
- for( temp = nullEvent; temp <= osEvt; temp++ )
- if( evMask&(1<<temp) )
- mhHandlers[temp] = handler;
- }
-
- void MEventDispatcher::EventLoop()
- {
- EventRecord event;
- Point pt;
- GWorldPtr globWorld, world;
- GDHandle globDevice, device;
- GrafPtr globPort, port;
- MEventDispatcher *oldDispatcher= sCurDispatcher;
-
- sCurDispatcher= this;
- TApplication::SCurApp()->GetGlobalWorld( globWorld, globDevice );
- globPort= TApplication::SCurApp()->GetGlobalPort();
-
- for( int i=0; i<16; i++ )
- if( mhHandlers[i] )
- mhHandlers[i]->NewDispatcher();
- if( Run() )
- while( !mhDone ) {
- ::WaitNextEvent( everyEvent, &event, 10, TMouseHandler::SGetMouse()->MouseMoveRgn() );
- TKeyboardHandler::GetKeyboard()->mModifiers= event.modifiers;
- DispatchEvent( event );
- }
- sCurDispatcher= oldDispatcher;
- for( int i=0; i<16; i++ )
- if( mhHandlers[i] )
- mhHandlers[i]->OldDispatcher();
- }
-
- void MEventDispatcher::DispatchEvent( const EventRecord &event )
- {
- WindowRef theWindow;
- short partCode;
-
- switch( event.what )
- {
- case updateEvt:
- ((TBaseWindow*)GetWRefCon((WindowRef)event.message))->DoUpdate();
- break;
- default:
- if( (event.what <= osEvt) && mhHandlers[event.what] )
- mhHandlers[event.what]->DispatchEvent( event );
- }
- }
-
- BOOLEAN MEventDispatcher::AttemptQuit()
- {
- BOOLEAN ret= AttemptQuitSelf();
- if( ret )
- Quit();
- return( ret );
- }
-
- BOOLEAN MEventDispatcher::AttemptQuitSelf()
- {
- return( true );
- }
-
- void MEventDispatcher::Quit()
- {
- QuitSelf();
- mhDone= true;
- }
-
- void MEventDispatcher::QuitSelf()
- {
- }