home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / PowerPlant / CContextHandler / CContextHandler.h < prev   
Encoding:
Text File  |  1995-10-09  |  3.1 KB  |  85 lines  |  [TEXT/CWIE]

  1. // =================================================================================
  2. //    CContextHandler.cp    version 1.0        ©1995 Harold Ekstrom. All rights reserved.
  3. // =================================================================================
  4. //    The CContextHandler class encapsulates AppleGuide context checking for
  5. //    PowerPlant applications. It uses a single ContextReplyProc to dispatch context
  6. //    checks to specific context checking objects. Two useful subclasses are provided
  7. //    for checking the enabled state of commands and the front window's pane id.
  8. //    These context checks are more powerful than the kinds of context checking that
  9. //    can be done from external modules because they don't depend on menu item text
  10. //    or position or on window title or size.
  11. //
  12. //    This class may be freely used in any project.  The source itself may not
  13. //    be sold.  The source may be placed on ftp sites, BBSs, and similar locations
  14. //    but distribution on solid media, CD, floppy, etc, requires my permission.
  15. //    
  16. //    Usage:
  17. //
  18. //    (1) During application startup create the context checking objects like this:
  19. //    Try_{
  20. //        new CCmdContextHandler( 'cmd ' );
  21. //        new CPaneIDContextHandler( 'pane' );
  22. //    } Catch_( inErr ) {
  23. //    } EndCatch_
  24. //
  25. //    (2) In your guide file source, define the context checks like this:
  26. //    <Define Context Check> "IsCommandEnabled", 'cmd ', '????', LONG
  27. //    <Define Context Check> "IsFrontWindowPaneID", 'pane', '????', LONG
  28. //    where '????' is replaced by your application's creator.
  29. //
  30. //    (3) And finally use it in your guide source like any other context check.
  31. //
  32. //    Note: when you compile your guide source GuideMaker will give you a warning
  33. //    that there's no external module for the context checks you've defined.
  34. //    Just ignore it.
  35.  
  36. #pragma once
  37.  
  38. #include <AppleGuide.h>
  39.  
  40. class CContextHandler {
  41. public:
  42.                             CContextHandler( AEEventID inEventID );
  43.     virtual                    ~CContextHandler();
  44.  
  45. protected:
  46.                             // Pure virtual. Subclasses must override.
  47.     virtual Boolean            DoContextCheck( const Ptr inData, Size inDataSize ) = 0;
  48.  
  49. private:
  50.     AGContextRefNum            mContextRefNum;
  51.     static ContextReplyUPP    sContextReplyUPP;
  52.  
  53.     static pascal OSErr        ContextReplyProc( Ptr inData, Size inDataSize,
  54.                                 Ptr *outData, Size *outDataSize,
  55.                                 AGAppInfoHdl inAppInfo );
  56. };
  57.  
  58.  
  59. // =================================================================================
  60. //    • CCmdContextHandler
  61. // =================================================================================
  62.  
  63. class CCmdContextHandler : public CContextHandler {
  64. public:
  65.                         CCmdContextHandler( AEEventID inEventID );
  66.     virtual                ~CCmdContextHandler();
  67.  
  68. protected:
  69.     virtual Boolean        DoContextCheck( const Ptr inData, Size inDataSize );
  70. };
  71.  
  72.  
  73. // =================================================================================
  74. //    • CPaneIDContextHandler
  75. // =================================================================================
  76.  
  77. class CPaneIDContextHandler : public CContextHandler {
  78. public:
  79.                         CPaneIDContextHandler( AEEventID inEventID );
  80.     virtual                ~CPaneIDContextHandler();
  81.  
  82. protected:
  83.     virtual Boolean        DoContextCheck( const Ptr inData, Size inDataSize );
  84. };
  85.