home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-05-31 | 2.0 KB | 80 lines | [TEXT/CWIE] |
- //Copyright (c) 1997 Aidan Cully
- //All rights reserved
-
- #include <Menus.h>
- #include <Devices.h>
- #include "CLActionHandler.h"
-
- MActionHandler *MActionHandler::sCurHandler = 0l;
-
- MActionHandler::MActionHandler( MActionHandler *super )
- {
- mSuperHandler = super;
- mActive = false;
- }
-
- Boolean MActionHandler::SetSuperHandler( MActionHandler *super )
- {
- mSuperHandler = super;
- return( true );
- }
-
- //MActionHandler::MakeActive()
- // uses:
- // This procedure deactivates the current Handler tree, then activates its own (from
- // itself up to the superest handler of all). All actions will now be sent to the root
- // of this procedure.
- // return values:
- // 0: success
- // other values can be returned by the subclassed version, and only the programmer at that
- // stage would have any idea what they mean.
- SInt8 MActionHandler::MakeActive()
- {
- if( sCurHandler == this )
- return( 0 );
- if( sCurHandler ) {
- sCurHandler->MakeInactive();
- //set the curHandler == 0, so that this handler's superhandlers (if any) will not call
- //MakeInactive() again.
- sCurHandler = 0l;
- }
- if( mSuperHandler )
- mSuperHandler->MakeActive();
- //Now, we can finally set the curHandler;
- sCurHandler = this;
- mActive = true;
- return( 0 );
- }
-
- //This procedure should only be called from MakeActive();
- SInt8 MActionHandler::MakeInactive()
- {
- if( mSuperHandler )
- mSuperHandler->MakeInactive();
- mActive = false;
- return( 0 );
- }
-
- //MActionHandler::HandleAction()
- // in:
- // UInt32 action:
- // this number corresponds to the number returned by MenuSelect() or MenuKey(), or
- // any application defined values. It is up to the programmer to make sure that the
- // two don't conflict.
- SInt8 MActionHandler::HandleAction( UInt32 action )
- {
- if( mSuperHandler )
- return( mSuperHandler->HandleAction( action ) );
- return( 0 );
- }
-
- void MActionHandler::OpenDeskAcc( UInt32 action )
- {
- int mID, mItem;
- Str255 theName;
-
- mID = action>>16;
- mItem = (action&0x0000ffff);
- GetMenuItemText( GetMenuHandle( mID ), mItem, theName );
- ::OpenDeskAcc( theName );
- }