home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- #
- # Apple Macintosh Developer Technical Support
- #
- # MultiFinder-Aware Simple TextEdit Sample Application
- #
- # CPlusTESample
- #
- # TApplication.h - C++ source
- #
- # Copyright ⌐ 1989 Apple Computer, Inc.
- # All rights reserved.
- #
- # Versions:
- # 1.20 10/89
- # 1.10 07/89
- # 1.00 04/89
- #
- # Components:
- # CPlusTESample.make October 1, 1989
- # TApplicationCommon.h October 1, 1989
- # TApplication.h October 1, 1989
- # TDocument.h October 1, 1989
- # TECommon.h October 1, 1989
- # TESample.h October 1, 1989
- # TEDocument.h October 1, 1989
- # TApplication.cp October 1, 1989
- # TDocument.cp October 1, 1989
- # TESample.cp October 1, 1989
- # TEDocument.cp October 1, 1989
- # TESampleGlue.a October 1, 1989
- # TApplication.r October 1, 1989
- # TESample.r October 1, 1989
- #
- # CPlusTESample is an example application that demonstrates
- # how to initialize the commonly used toolbox managers,
- # operate successfully under MultiFinder, handle desk
- # accessories and create, grow, and zoom windows. The
- # fundamental TextEdit toolbox calls and TextEdit autoscroll
- # are demonstrated. It also shows how to create and maintain
- # scrollbar controls.
- #
- # This version of TESample has been substantially reworked in
- # C++ to show how a "typical" object oriented program could
- # be written. To this end, what was once a single source code
- # file has been restructured into a set of classes which
- # demonstrate the advantages of object-oriented programming.
- #
- ------------------------------------------------------------------------------*/
-
- #ifndef __TAPPLICATION__
- #define __TAPPLICATION__
-
- // Include necessary interface files
- #include <Types.h>
- #include <Desk.h>
- #include <Events.h>
- #include <OSUtils.h>
-
- // we need resource ids
- #ifndef __TAPPLICATIONCOMMON__
- #include "TApplicationCommon.h"
- #endif __TAPPLICATIONCOMMON__
-
- // we need definitions of DocumentList class
- #ifndef __TDOCUMENT__
- #include "TDocument.h"
- #endif __TDOCUMENT__
-
- /*
- TApplication:
-
- This is our class which implements a basic Macintosh style program,
- including a MultiFinder-aware event loop.
- */
-
- // we derive from handle object to prevent fragmentation
- class TApplication : HandleObject {
- public:
- // Our constructor
- TApplication();
-
- // Call this routine to start event loop running
- void EventLoop();
-
- // Utility routines you can use
- Boolean TrapAvailable(short tNumber,TrapType tType); // Is trap implemented???
- inline TDocumentList* DocList() { return fDocList; }
-
- protected:
- // Returns total stack space required in bytes.
- // Returns 0 by default, which tells the initialization code
- // to use the default stack size.
- virtual long StackNeeded() { return 0; };
- // Returns total heap space required in bytes.
- // Returns 0 by default, which tells the initialization code
- // to use whatever heap size is given.
- virtual long HeapNeeded() { return 0; };
-
- // Loop control methods you may need to override
- virtual void SetUp() {}; // Run before event loop starts
- virtual void CleanUp() {}; // run at end of loop
- virtual void ExitLoop(); // to end loop, call this routine
- virtual void DoIdle() {}; // idle time handler (blink caret, background tasks)
- virtual void AdjustMenus() {}; // menu updater routine
-
- // event handlers you shouldn't need to override in a typical application
- virtual void DoOSEvent(); // Calls DoSuspend, DoResume and DoIdle as apropos
- virtual void DoMouseDown(); // Calls DoContent, DoGrow, DoZoom, etc
- virtual void DoKeyDown(); // also called for autokey events
- virtual void DoActivateEvt(); // handles setup, and calls DoActivate (below)
- virtual void DoUpdateEvt(); // handles setup, and calls DoUpdate (below)
- virtual void DoMouseInSysWindow() { SystemClick(&fTheEvent, fWhichWindow); };
- virtual void DoDrag();
- virtual void DoGoAway(); // handles setup, calls TDocument::DoClose
-
- // handlers you MUST override for functionality:
- virtual void AdjustCursor() = 0; // cursor adjust routine, should setup mouseRgn
- virtual void DoMenuCommand(short menuID, short menuItem) = 0;
-
- // If you have an app that needs to know about these, override them
- virtual void DoMouseUp() {};
- virtual void DoDiskEvt() {};
-
- // called by OSEvent (just calls DoActivate by default, so no clip conversion
- // is done). If you want to convert clipboard, override these routines
- virtual void DoSuspend(Boolean doClipConvert);
- virtual void DoResume(Boolean doClipConvert);
-
- // Utility routines you need to provide to do MultiFinder stuff
- virtual unsigned long SleepVal() { return 0; }; // how long to sleep in WaitNextEvent
-
- // useful variables
- Boolean fHaveWaitNextEvent; // true if we have WaitNextEvent trap
- Boolean fDone; // set to true when we are ready to quit
- EventRecord fTheEvent; // our event record
- WindowPtr fWhichWindow; // currently active window
- Boolean fInBackground; // true if our app is suspended
- Boolean fWantFrontClicks; // true if we want front clicks
- RgnHandle fMouseRgn; // mouse moved region (set it in your DoIdle)
- TDocument* fCurDoc; // currently active document (if any)
- TDocumentList* fDocList; // the list of documents
- };
-
- // some other handy utility routines, not actually a part of application class
-
- // display alert, using specified error STR# resource and error code as index
- void AlertUser(short errResID, short errCode);
- // call AlertUser to display error message, then quit...
- void BigBadError(short errResID, short errCode);
-
- #endif __TAPPLICATION__
-