home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / scnote / cplussmp.014 / TApplication.h < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-01  |  5.5 KB  |  153 lines

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    MultiFinder-Aware Simple TextEdit Sample Application
  6. #
  7. #    CPlusTESample
  8. #
  9. #    TApplication.h    -    C++ source
  10. #
  11. #    Copyright ⌐ 1989 Apple Computer, Inc.
  12. #    All rights reserved.
  13. #
  14. #    Versions:    
  15. #            1.20                    10/89
  16. #            1.10                     07/89
  17. #            1.00                     04/89
  18. #    
  19. #    Components:
  20. #            CPlusTESample.make        October 1, 1989
  21. #            TApplicationCommon.h    October 1, 1989
  22. #            TApplication.h            October 1, 1989
  23. #            TDocument.h                October 1, 1989
  24. #            TECommon.h                October 1, 1989
  25. #            TESample.h                October 1, 1989
  26. #            TEDocument.h            October 1, 1989
  27. #            TApplication.cp            October 1, 1989
  28. #            TDocument.cp            October 1, 1989
  29. #            TESample.cp                October 1, 1989
  30. #            TEDocument.cp            October 1, 1989
  31. #            TESampleGlue.a            October 1, 1989
  32. #            TApplication.r            October 1, 1989
  33. #            TESample.r                October 1, 1989
  34. #
  35. #    CPlusTESample is an example application that demonstrates
  36. #    how to initialize the commonly used toolbox managers,
  37. #    operate successfully under MultiFinder, handle desk
  38. #    accessories and create, grow, and zoom windows. The
  39. #    fundamental TextEdit toolbox calls and TextEdit autoscroll
  40. #    are demonstrated. It also shows how to create and maintain
  41. #    scrollbar controls. 
  42. #
  43. #    This version of TESample has been substantially reworked in
  44. #    C++ to show how a "typical" object oriented program could
  45. #    be written. To this end, what was once a single source code
  46. #    file has been restructured into a set of classes which
  47. #    demonstrate the advantages of object-oriented programming.
  48. #
  49. ------------------------------------------------------------------------------*/
  50.  
  51. #ifndef __TAPPLICATION__
  52. #define __TAPPLICATION__
  53.  
  54. // Include necessary interface files
  55. #include <Types.h>
  56. #include <Desk.h>
  57. #include <Events.h>
  58. #include <OSUtils.h>
  59.  
  60. // we need resource ids
  61. #ifndef __TAPPLICATIONCOMMON__
  62. #include "TApplicationCommon.h"
  63. #endif __TAPPLICATIONCOMMON__
  64.  
  65. // we need definitions of DocumentList class
  66. #ifndef __TDOCUMENT__
  67. #include "TDocument.h"
  68. #endif __TDOCUMENT__
  69.  
  70. /*
  71.     TApplication:
  72.  
  73.     This is our class which implements a basic Macintosh style program,
  74.     including a MultiFinder-aware event loop. 
  75. */
  76.  
  77. // we derive from handle object to prevent fragmentation
  78. class TApplication : HandleObject {
  79. public:
  80.     // Our constructor
  81.     TApplication();
  82.  
  83.     // Call this routine to start event loop running
  84.     void EventLoop();
  85.  
  86.     // Utility routines you can use
  87.     Boolean TrapAvailable(short tNumber,TrapType tType);    // Is trap implemented???
  88.     inline TDocumentList* DocList() { return fDocList; }
  89.  
  90. protected:
  91.     // Returns total stack space required in bytes.
  92.     // Returns 0 by default, which tells the initialization code
  93.     // to use the default stack size.
  94.     virtual long StackNeeded() { return 0; };
  95.     // Returns total heap space required in bytes.
  96.     // Returns 0 by default, which tells the initialization code
  97.     // to use whatever heap size is given.
  98.     virtual long HeapNeeded() { return 0; };
  99.  
  100.     // Loop control methods you may need to override
  101.     virtual void SetUp() {};                // Run before event loop starts
  102.     virtual void CleanUp() {};                // run at end of loop
  103.     virtual void ExitLoop();                // to end loop, call this routine
  104.     virtual void DoIdle() {};                // idle time handler (blink caret, background tasks)
  105.     virtual void AdjustMenus() {};            // menu updater routine
  106.  
  107.     // event handlers you shouldn't need to override in a typical application
  108.     virtual void DoOSEvent();                // Calls DoSuspend, DoResume and DoIdle as apropos
  109.     virtual void DoMouseDown();                // Calls DoContent, DoGrow, DoZoom, etc
  110.     virtual void DoKeyDown();                // also called for autokey events
  111.     virtual void DoActivateEvt();            // handles setup, and calls DoActivate (below)
  112.     virtual void DoUpdateEvt();                // handles setup, and calls DoUpdate (below)
  113.     virtual void DoMouseInSysWindow() { SystemClick(&fTheEvent, fWhichWindow); };
  114.     virtual void DoDrag();
  115.     virtual void DoGoAway();                // handles setup, calls TDocument::DoClose
  116.  
  117.     // handlers you MUST override for functionality:
  118.     virtual void AdjustCursor() = 0;        // cursor adjust routine, should setup mouseRgn
  119.     virtual void DoMenuCommand(short menuID, short menuItem) = 0;
  120.  
  121.     // If you have an app that needs to know about these, override them
  122.     virtual void DoMouseUp() {};
  123.     virtual void DoDiskEvt() {};
  124.  
  125.     // called by OSEvent (just calls DoActivate by default, so no clip conversion
  126.     // is done). If you want to convert clipboard, override these routines
  127.     virtual void DoSuspend(Boolean doClipConvert);
  128.     virtual void DoResume(Boolean doClipConvert);
  129.     
  130.     // Utility routines you need to provide to do MultiFinder stuff
  131.     virtual unsigned long SleepVal() { return 0; };        // how long to sleep in WaitNextEvent
  132.  
  133.     // useful variables
  134.     Boolean            fHaveWaitNextEvent;        // true if we have WaitNextEvent trap
  135.     Boolean            fDone;                    // set to true when we are ready to quit
  136.     EventRecord        fTheEvent;                // our event record
  137.     WindowPtr        fWhichWindow;            // currently active window
  138.     Boolean            fInBackground;            // true if our app is suspended
  139.     Boolean            fWantFrontClicks;        // true if we want front clicks
  140.     RgnHandle        fMouseRgn;                // mouse moved region (set it in your DoIdle)
  141.     TDocument*        fCurDoc;                // currently active document (if any)
  142.     TDocumentList*    fDocList;                // the list of documents
  143. };
  144.  
  145. // some other handy utility routines, not actually a part of application class
  146.  
  147. // display alert, using specified error STR# resource and error code as index
  148. void AlertUser(short errResID, short errCode);
  149. // call AlertUser to display error message, then quit...
  150. void BigBadError(short errResID, short errCode);
  151.  
  152. #endif __TAPPLICATION__
  153.