home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / MLTE SDK / TEtoMLTESample / CommonSources / TDocument.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-10  |  6.1 KB  |  170 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    MultiFinder-Aware Simple Application Framework
  6. #
  7. #    TDocument
  8. #
  9. #    TDocument.h        -    C++ source
  10. #
  11. #    Copyright © 1989 Apple Computer, Inc.
  12. #    All rights reserved.
  13. #
  14. #    Versions:    
  15. #            1.20                    10/91
  16. #            1.10                     07/89
  17. #            1.00                     04/89
  18. #
  19. #    Components:
  20. #            TDocument.h                July 9, 1989
  21. #            TDocument.cp            July 9, 1989
  22. #
  23. ------------------------------------------------------------------------------*/
  24.  
  25. #ifndef TDocument_Defs
  26. #define TDocument_Defs
  27.  
  28. // Include necessary interface files
  29. #include <Types.h>
  30. #include <Quickdraw.h>
  31.  
  32.  
  33. // Define HiWrd and LoWrd macros for efficiency
  34. #define HiWrd(aLong)    ((short) (((aLong) >> 16) & 0xFFFF))
  35. #define LoWrd(aLong)    ((short) ((aLong) & 0xFFFF))
  36.  
  37. // Define TopLeft and BotRight macros for convenience. Notice the implicit
  38. // dependency on the ordering of fields within a Rect
  39. #define TopLeft(aRect)    (* (Point *) &(aRect).top)
  40. #define BotRight(aRect)    (* (Point *) &(aRect).bottom)
  41.  
  42. const long kMaxSleepTime = 60;    // 1 second worth of ticks
  43.  
  44. /***********************************************************************/
  45. //
  46. //    Class definitions
  47. //
  48. /***********************************************************************/
  49.  
  50.  
  51. //-----------------------------------------------------------------------
  52. // TDocument -    some basic member functions are included. Although it is 
  53. //                not a complete set, it does provide enough functionality
  54. //                to develop subclasses. As you develop subclasses, you may
  55. //                choose to incorporate common functionality of those
  56. //                subclasses into the base class to reduce the complexity
  57. //                of creating others.
  58. //
  59.     class TDocument {
  60.     
  61.         protected:
  62.             WindowPtr fDocWindow;
  63.         
  64.         public:
  65.             TDocument( short resID );        // our constructor - creates window using resID as template
  66.             virtual ~TDocument();            // our destructor - disposes of window
  67.         
  68.             // you will need to override these in your subclasses,
  69.             // since they are do-nothing routines by default...
  70.                 virtual void DoZoom        ( short            /*partCode*/ )            {}
  71.                 virtual void DoGrow        ( EventRecord*    /*theEvent*/ )            {}
  72.                 virtual void DoContent    ( EventRecord*    /*theEvent*/ )            {}
  73.                 virtual void DoKeyDown    ( EventRecord*    /*theEvent*/ )            {}
  74.                 virtual void DoActivate    ( Boolean        /*becomingActive*/ )    {}
  75.                 virtual void DoUpdate    ( void )                                {}
  76.         
  77.             // file handling routines
  78.                 virtual void DoOpen        ( void )    {};
  79.                 virtual void DoClose    ( void )    { delete this; };    // by default, we just delete ourself & let destructor do cleanup
  80.                 virtual void DoSave        ( void )    {};
  81.                 virtual void DoSaveAs    ( void )    {};
  82.                 virtual void DoRevert    ( void )    {};
  83.                 virtual void DoPrint    ( void )    {};
  84.         
  85.             // do standard edit menu actions
  86.                 virtual void DoUndo        ( void )    {};
  87.                 virtual void DoCut        ( void )    {};
  88.                 virtual void DoCopy        ( void )    {};
  89.                 virtual void DoPaste    ( void )    {};
  90.                 virtual void DoClear    ( void )    {};
  91.                 virtual void DoSelectAll( void )    {};
  92.         
  93.             // idle time routines: you can use these to do cursor handling,
  94.             // TE caret blinking, marquee effects, etc...
  95.                 virtual void DoIdle                ( void )                 {};
  96.                 virtual unsigned long CalcIdle    ( void )                 { return kMaxSleepTime; };    // by default, we don't need idle
  97.                 virtual void AdjustCursor        ( Point /*where*/ )     {};                            // where is in local coords
  98.             
  99.             // query state of document - useful for adjusting menu state
  100.                 virtual Boolean HaveUndo        ( void )    { return false; };
  101.                 virtual Boolean HaveSelection    ( void )    { return false; };
  102.                 virtual Boolean HavePaste        ( void )    { return false; };
  103.                 virtual Boolean CanClose        ( void )    { return true;  };
  104.                 virtual Boolean CanSave            ( void )    { return false; };
  105.                 virtual Boolean CanSaveAs        ( void )    { return true;  };
  106.                 virtual Boolean CanRevert        ( void )    { return false; };
  107.                 virtual Boolean CanPrint        ( void )     { return false; };
  108.         
  109.             // utility routine to get window pointer for document
  110.                 inline WindowPtr GetDocWindow    ( void )     { return fDocWindow; }
  111.                 
  112.     }; /* class TDocument */
  113.  
  114.  
  115. //-----------------------------------------------------------------------
  116. // TDocumentLink -    is a simple utility class which is used by the TDocumentList
  117. //                     class below. You cannot allocate objects of this type yourself,
  118. //                    since its constructor is private. We get around this for
  119. //                    TDocumentList by making it a "friend" of this class. This is
  120. //                    a handy trick.
  121. //
  122.     class TDocumentLink
  123.     {
  124.         friend class TDocumentList;
  125.     
  126.         // class variables
  127.             TDocumentLink*            fNext;            // the link to the next document
  128.             TDocument*                fDoc;            // the document this link refers to
  129.     
  130.         // our constructor. Note that it can take args for convenience,
  131.         // but that they default to nil.
  132.             TDocumentLink( TDocumentLink *n = nil, TDocument *v = nil );
  133.     
  134.         // implementation of our TDocumentLink routines is done inline, for speed
  135.             inline TDocumentLink*    GetNext    ()                             { return fNext;  };
  136.             inline TDocument*         GetDoc    ()                             { return fDoc;   };
  137.             inline void                SetNext    ( TDocumentLink* aLink )     { fNext = aLink; };
  138.             inline void             SetDoc    ( TDocument* aDoc )         { fDoc = aDoc;   };
  139.         
  140.     }; /* class TDocumentLink */
  141.  
  142.  
  143. //-----------------------------------------------------------------------
  144. // TDocumentList -    is a simple linked list of documents, implemented C++ style. I
  145. //                    could have made a general linked list class & just made this a
  146. //                    subclass. This would have been a more general (and more
  147. //                    object-oriented) solution, but I did it from scratch in a
  148. //                    futile attempt at keeping the size of this program at a
  149. //                    reasonable level.
  150. //
  151.     class TDocumentList
  152.     {
  153.         // class variables
  154.             TDocumentLink*    fDocList;    // the first link in our list
  155.             int                fNumDocs;    // the number of elements in the list
  156.         
  157.         public:
  158.             TDocumentList( void );        // our constructor
  159.         
  160.             virtual void        AddDoc        ( TDocument* doc );
  161.             virtual void        RemoveDoc    ( TDocument* doc );
  162.             virtual TDocument*    FindDoc        ( WindowPtr window );        // find the TDocument associated with the window
  163.         
  164.             inline int            NumDocs() { return fNumDocs; }            // return number of active documents
  165.         
  166.     }; /* class TDocumentList */
  167.  
  168.  
  169. #endif // TDocument_Defs
  170.