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 / TApplication.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-19  |  5.2 KB  |  135 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    MultiFinder-Aware Simple Application Framework
  6. #
  7. #    TApplication
  8. #
  9. #    TApplication.h    -    C++ source
  10. #
  11. #    Copyright © 1991 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. #            TApplicationCommon.h    July 9, 1989
  21. #            TApplication.h            July 9, 1989
  22. #            TApplication.cp            July 9, 1989
  23. #            TApplication.r            July 9, 1989
  24. #            TDocument.h                July 9, 1989
  25. #
  26. #    CPlusAppLib is a rudimentary application framework
  27. #    for C++.
  28. #
  29. ------------------------------------------------------------------------------*/
  30.  
  31. #ifndef TAPPLICATION_H
  32. #define TAPPLICATION_H
  33.  
  34. // Include necessary interface files
  35. #include <Types.h>
  36. #include <Menus.h>
  37. #include <Devices.h>
  38. #include <Events.h>
  39. #include <OSUtils.h>
  40.  
  41. // we need resource ids
  42. #include "TApplicationCommon.h"            // use the local version. If you make changes
  43.                                         // that you've debugged and want other files
  44.                                         // to use, simple copy the header files into
  45.                                         // the C++ Includes folder (don't forget to
  46.                                         // copy the TApplication object library to the C++
  47.                                         // Libraries folder)!
  48.  
  49. // we need definitions of DocumentList class
  50. #include "TDocument.h"
  51.  
  52.  
  53. /*
  54.     TApplication:
  55.  
  56.     This is our class which implements a basic Macintosh style program,
  57.     including a MultiFinder-aware event loop. 
  58. */
  59.  
  60. // we derive from handle object to prevent fragmentation
  61. class TApplication {
  62.     public:
  63.         //    these member functions can be called by anyone
  64.                     TApplication            ( void );                                        // Our constructor & destructor
  65.             void    EventLoop                ( void );                                        // Call this routine to start event loop running
  66.             inline    TDocumentList* DocList    ( void )        { return fDocList; }            // a utility routine that you may need to use
  67.             Boolean TrapAvailable            ( short tNumber, TrapType tType );                // Is trap implemented???
  68.     
  69.     protected:
  70.         // useful variables
  71.             Boolean            fHaveWaitNextEvent;        // true if we have WaitNextEvent trap
  72.             Boolean            fDone;                    // set to true when we are ready to quit
  73.             EventRecord        fTheEvent;                // our event record
  74.             WindowPtr        fWhichWindow;            // currently active window
  75.             Boolean            fInBackground;            // true if our app is suspended
  76.             Boolean            fWantFrontClicks;        // true if we want front clicks
  77.             RgnHandle        fMouseRgn;                // mouse moved region (set it in your DoIdle)
  78.             TDocument*        fCurDoc;                // currently active document (if any)
  79.             TDocumentList*    fDocList;                // the list of documents
  80.  
  81.         // Returns total stack space required in bytes.
  82.         // Returns 0 by default, which tells the initialization code
  83.         // to use the default stack size.
  84.             virtual long StackNeeded        ( void )     { return 0; }
  85.     
  86.         // Returns total heap space required in bytes.
  87.         // Returns 0 by default, which tells the initialization code
  88.         // to use whatever heap size is given.
  89.             virtual long HeapNeeded            ( void )    { return 0; }
  90.     
  91.         // Loop control methods you may need to override
  92.             virtual void AdjustMenus        ( void )    {}                // menu updater routine
  93.             virtual void CleanUp            ( void )    {}                // run at end of loop
  94.             virtual void DoIdle                ( void )    {}                // idle time handler (blink caret, background tasks)
  95.             virtual void ExitLoop            ( void );                    // to end loop, call this routine
  96.             virtual void SetUp                ( void )    {}                // Run before event loop starts
  97.     
  98.         // event handlers you shouldn't need to override in a typical application
  99.             virtual void DoMouseInSysWindow    ( void )     { SystemClick(&fTheEvent, fWhichWindow); }
  100.             virtual void DoOSEvent            ( void );                    // Calls DoSuspend, DoResume and DoIdle as apropos
  101.             virtual void DoMouseDown        ( void );                    // Calls DoContent, DoGrow, DoZoom, etc
  102.             virtual void DoKeyDown            ( void );                    // also called for autokey events
  103.             virtual void DoActivateEvt        ( void );                    // handles setup, and calls DoActivate ( below)
  104.             virtual void DoGoAway            ( void );                    // handles setup, calls TDocument::DoClose
  105.             virtual void DoUpdateEvt        ( void );                    // handles setup, and calls DoUpdate ( below )
  106.             virtual void DoDrag                ( void );
  107.     
  108.         // handlers you will need to override for functionality:
  109.             // called by EventLoop and its handlers:
  110.                 virtual void AdjustCursor    ( void )    {}                // cursor adjust routine, should setup mouseRgn
  111.                 virtual void DoMenuCommand    ( short menuID, short menuItem )    { (void) menuID; (void) menuItem; /* avoid "not used" warning */}
  112.     
  113.             // called by OSEvent (just calls DoActivate by default, so no clip conversion
  114.             // is done). If you want to convert clipboard, override these routines
  115.                 virtual void DoSuspend(Boolean doClipConvert);
  116.                 virtual void DoResume(Boolean doClipConvert);
  117.         
  118.         // If you have an app that needs to know about these, override them
  119.             virtual void DoMouseUp( void ) {}
  120.             virtual void DoDiskEvt( void ) {}
  121.     
  122.         // Utility routines you need to provide to do MultiFinder stuff
  123.             virtual unsigned long SleepVal( void ) { return 0; }        // how long to sleep in WaitNextEvent
  124.  
  125.         // some other handy utility routines
  126.             // display alert, using specified error STR# resource and error code as index
  127.                 void AlertUser( short errResID, short errCode );
  128.             
  129.             // call AlertUser to display error message, then quit...
  130.                 void BigBadError( short errResID, short errCode );
  131.  
  132. }; /* class TApplication */
  133.  
  134. #endif
  135.