home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-09 | 3.1 KB | 85 lines | [TEXT/CWIE] |
- // =================================================================================
- // CContextHandler.cp version 1.0 ©1995 Harold Ekstrom. All rights reserved.
- // =================================================================================
- // The CContextHandler class encapsulates AppleGuide context checking for
- // PowerPlant applications. It uses a single ContextReplyProc to dispatch context
- // checks to specific context checking objects. Two useful subclasses are provided
- // for checking the enabled state of commands and the front window's pane id.
- // These context checks are more powerful than the kinds of context checking that
- // can be done from external modules because they don't depend on menu item text
- // or position or on window title or size.
- //
- // This class may be freely used in any project. The source itself may not
- // be sold. The source may be placed on ftp sites, BBSs, and similar locations
- // but distribution on solid media, CD, floppy, etc, requires my permission.
- //
- // Usage:
- //
- // (1) During application startup create the context checking objects like this:
- // Try_{
- // new CCmdContextHandler( 'cmd ' );
- // new CPaneIDContextHandler( 'pane' );
- // } Catch_( inErr ) {
- // } EndCatch_
- //
- // (2) In your guide file source, define the context checks like this:
- // <Define Context Check> "IsCommandEnabled", 'cmd ', '????', LONG
- // <Define Context Check> "IsFrontWindowPaneID", 'pane', '????', LONG
- // where '????' is replaced by your application's creator.
- //
- // (3) And finally use it in your guide source like any other context check.
- //
- // Note: when you compile your guide source GuideMaker will give you a warning
- // that there's no external module for the context checks you've defined.
- // Just ignore it.
-
- #pragma once
-
- #include <AppleGuide.h>
-
- class CContextHandler {
- public:
- CContextHandler( AEEventID inEventID );
- virtual ~CContextHandler();
-
- protected:
- // Pure virtual. Subclasses must override.
- virtual Boolean DoContextCheck( const Ptr inData, Size inDataSize ) = 0;
-
- private:
- AGContextRefNum mContextRefNum;
- static ContextReplyUPP sContextReplyUPP;
-
- static pascal OSErr ContextReplyProc( Ptr inData, Size inDataSize,
- Ptr *outData, Size *outDataSize,
- AGAppInfoHdl inAppInfo );
- };
-
-
- // =================================================================================
- // • CCmdContextHandler
- // =================================================================================
-
- class CCmdContextHandler : public CContextHandler {
- public:
- CCmdContextHandler( AEEventID inEventID );
- virtual ~CCmdContextHandler();
-
- protected:
- virtual Boolean DoContextCheck( const Ptr inData, Size inDataSize );
- };
-
-
- // =================================================================================
- // • CPaneIDContextHandler
- // =================================================================================
-
- class CPaneIDContextHandler : public CContextHandler {
- public:
- CPaneIDContextHandler( AEEventID inEventID );
- virtual ~CPaneIDContextHandler();
-
- protected:
- virtual Boolean DoContextCheck( const Ptr inData, Size inDataSize );
- };
-