home *** CD-ROM | disk | FTP | other *** search
- #include "MyApp.h"
-
- #include <LGrowZone.h>
- #include <UDrawingState.h>
- #include <UMemoryMgr.h>
- #include <UModalDialogs.h>
- #include <URegistrar.h>
- #include <UDebugging.h>
- #include <UEnvironment.h>
-
- #include <LWindow.h>
- #include <LTabGroupView.h>
- #include <LEditText.h>
- #include <LCheckBox.h>
- #include <UAttachments.h>
-
- #include <UControlRegistry.h>
-
- #include <LThread.h>
- #include <UThread.h>
- #include <LCleanupTask.h>
-
- #include "AppConstants.h"
-
- #include "MyVUMeterPeriodical.h"
-
-
- // ---------------------------------------------------------------------------
- // • main
- // ---------------------------------------------------------------------------
-
- int main()
- {
- // Set Debugging options
- SetDebugThrow_(debugAction_Alert);
- SetDebugSignal_(debugAction_Alert);
-
- // Initialize Memory Manager. Parameter is the number of
- // master pointer blocks to allocate
- InitializeHeap(15);
-
- // Initialize standard Toolbox managers
- UQDGlobals::InitializeToolbox(&qd);
-
- // Check for Thread Manager.
- if (UEnvironment::HasFeature(env_HasThreadManager) == false) {
- ::StopAlert(ALRT_NoThreadManager, nil);
- ::ExitToShell();
- }
-
- // Install a GrowZone to catch low-memory situations
- new LGrowZone(20000);
-
- // Run the application.
- new UMainThread;
-
- MyApp theApp;
- theApp.AddAttachment(new LYieldAttachment);
- theApp.Run();
-
- // Make sure async tasks get cleaned up. This call is VERY IMPORTANT.
- // (Note: LCleanupTask patches ExitToShell, so things get cleaned up
- // appropriately if you kill the application.)
- LCleanupTask::CleanUpAtExit();
-
- return 0;
- }
-
-
- // ---------------------------------------------------------------------------
- // • MyApp [public]
- // ---------------------------------------------------------------------------
- // Applicaton object constructor
-
- MyApp::MyApp()
- {
- // Register ourselves with the Appearance Manager
- if (UEnvironment::HasFeature(env_HasAppearance)) {
- ::RegisterAppearanceClient();
- }
-
- RegisterClasses();
-
- // Increase responsiveness for Networking
- SetSleepTime(1);
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~MyApp [public, virtual]
- // ---------------------------------------------------------------------------
- // Application object destructor
-
- MyApp::~MyApp()
- {
- // Nothing
- }
-
-
- // ---------------------------------------------------------------------------
- // • StartUp [protected, virtual]
- // ---------------------------------------------------------------------------
- // Perform an action in response to the Open Application AppleEvent.
- // Here, issue the New command to open a window.
-
- void
- MyApp::StartUp()
- {
- // ObeyCommand(cmd_New, nil);
- ObeyCommand(cmd_About, nil);
- ObeyCommand(1000, nil);
- }
-
-
- // ---------------------------------------------------------------------------
- // • ObeyCommand [public, virtual]
- // ---------------------------------------------------------------------------
- // Respond to Commands. Returns true if the Command was handled, false if not.
-
- Boolean
- MyApp::ObeyCommand(
- CommandT inCommand,
- void* ioParam)
- {
- Boolean cmdHandled = true; // Assume we'll handle the command
-
- switch (inCommand) {
-
- case 1000:
- {
- MyVUMeterPeriodical::Instance().Toggle();
- break;
- }
-
- default: {
- cmdHandled = LDocApplication::ObeyCommand(inCommand, ioParam);
- break;
- }
- }
-
- return cmdHandled;
- }
-
-
- // ---------------------------------------------------------------------------
- // • FindCommandStatus [public, virtual]
- // ---------------------------------------------------------------------------
- // Determine the status of a Command for the purposes of menu updating.
-
- void
- MyApp::FindCommandStatus(
- CommandT inCommand,
- Boolean& outEnabled,
- Boolean& outUsesMark,
- UInt16& outMark,
- Str255 outName)
- {
- switch (inCommand) {
-
- case 1000:
- {
- outEnabled = true;
- break;
- }
-
- case cmd_Open: {
- // The stationery default does nothing for these
- // commands, so they are disabled to avoid any confusion
- // in the menubar. If you implement the appropriate
- // handler functions (e.g. ChooseDocument for cmd_Open)
- // be certain to either remove the case from here
- // (and let LDocApplication or another Commander handle it)
- // or add your own handler here.
-
- outEnabled = false;
- break;
- }
-
- default: {
- LDocApplication::FindCommandStatus(inCommand, outEnabled,
- outUsesMark, outMark, outName);
- break;
- }
- }
- }
-
- // ---------------------------------------------------------------------------
- // • MakeNewDocument [public, virtual]
- // ---------------------------------------------------------------------------
- // What happens to File->New Session from the menu. Creates a settings dialog
- // then waits modally for a configuration. If completed, then opens a new session.
-
- LModelObject*
- MyApp::MakeNewDocument()
- {
- return NULL;
- }
-
-
- // ---------------------------------------------------------------------------
- // • OpenDocument [public, virtual]
- // ---------------------------------------------------------------------------
- // Open a Document specified by an FSSpec
-
- void
- MyApp::OpenDocument(
- FSSpec* inMacFSSpec)
- {
- #pragma unused(inMacFSSpec)
-
- // You must implement.
- }
-
-
- // ---------------------------------------------------------------------------
- // • PrintDocument [public, virtual]
- // ---------------------------------------------------------------------------
- // Print a Document specified by an FSSpec
-
- void
- MyApp::PrintDocument(
- FSSpec* inMacFSSpec)
- {
- #pragma unused(inMacFSSpec)
-
- // You must implement
- }
-
-
- // ---------------------------------------------------------------------------
- // • ChooseDocument [public, virtual]
- // ---------------------------------------------------------------------------
- // Allow the user to pick a Document (usually for opening)
-
- void
- MyApp::ChooseDocument()
- {
- // You must implement
- }
-
-
- // ---------------------------------------------------------------------------
- // • RegisterClasses [protected, virtual]
- // ---------------------------------------------------------------------------
- // To reduce clutter within the Application object's constructor, class
- // registrations appear here in this seperate function for ease of use.
-
- void
- MyApp::RegisterClasses()
- {
- // Register core PowerPlant classes.
- // RegisterClass_(LWindow);
-
- // Register the Appearance Manager/GA classes. You may want
- // to remove this use of UControlRegistry and instead perform
- // a "manual" registration of the classes. This cuts down on
- // extra code being linked in and streamlines your app and
- // project. However, use UControlRegistry as a reference/index
- // for your work, and ensure to check UControlRegistry against
- // your registrations each PowerPlant release in case
- // any mappings might have changed.
-
- // UControlRegistry::RegisterClasses();
- }