home *** CD-ROM | disk | FTP | other *** search
- // ===========================================================================
- // CBasicApp.cp ©1994-1998 Metrowerks Inc. All rights reserved.
- // ===========================================================================
- // This file contains the starter code for a basic PowerPlant project
-
- #include "CBasicApp.h"
-
- #include <LGrowZone.h>
- #include <PP_Messages.h>
- #include <PP_Resources.h>
- #include <PPobClasses.h>
- #include <UDrawingState.h>
- #include <UMemoryMgr.h>
- #include <URegistrar.h>
-
- #include <LWindow.h>
- #include <LCaption.h>
- #include <LStdControl.h>
-
- // put declarations for resource ids (ResIDTs) here
-
-
- const PP_PowerPlant::ResIDT wind_SampleWindow = 128; // EXAMPLE, create a new window
- const PP_PowerPlant::MessageT MSG_Fish = 'Fish';
- const PP_PowerPlant::PaneIDT Button_Fish = 2048;
-
-
- // ===========================================================================
- // • Main Program
- // ===========================================================================
-
- int main()
- {
-
- SetDebugThrow_(PP_PowerPlant::debugAction_Alert); // Set Debugging options
- SetDebugSignal_(PP_PowerPlant::debugAction_Alert);
-
- PP_PowerPlant::InitializeHeap(3); // Initialize Memory Manager
- // Parameter is number of Master Pointer
- // blocks to allocate
-
- PP_PowerPlant::UQDGlobals::InitializeToolbox(&qd); // Initialize standard Toolbox managers
-
- new PP_PowerPlant::LGrowZone(20000); // Install a GrowZone function to catch
- // low memory situations.
-
- CBasicApp theApp; // replace this with your App type
- theApp.Run();
-
- return 0;
- }
-
-
- // ---------------------------------------------------------------------------
- // • CBasicApp
- // ---------------------------------------------------------------------------
- // Constructor
-
- CBasicApp::CBasicApp()
- {
- RegisterClass_(PP_PowerPlant::LWindow); // You must register each kind of
- RegisterClass_(PP_PowerPlant::LCaption); // PowerPlant classes that you use
- // in your PPob resource.
- RegisterClass_(PP_PowerPlant::LPane);
- RegisterClass_(PP_PowerPlant::LView);
- RegisterClass_(PP_PowerPlant::LPicture);
- RegisterClass_(PP_PowerPlant::LStdButton);
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~CBasicApp
- // ---------------------------------------------------------------------------
- // Destructor
-
- CBasicApp::~CBasicApp()
- {
- }
-
- // ---------------------------------------------------------------------------
- // • StartUp
- // ---------------------------------------------------------------------------
- // This method lets you do something when the application starts up
- // without a document. For example, you could issue your own new command.
-
- void
- CBasicApp::StartUp()
- {
- ObeyCommand(PP_PowerPlant::cmd_New, nil); // EXAMPLE, create a new window
- }
-
- // ---------------------------------------------------------------------------
- // • ObeyCommand
- // ---------------------------------------------------------------------------
- // This method lets the application respond to commands like Menu commands
-
- Boolean
- CBasicApp::ObeyCommand(
- PP_PowerPlant::CommandT inCommand,
- void *ioParam)
- {
- Boolean cmdHandled = true;
-
- switch (inCommand) {
-
- // Handle command messages (defined in PP_Messages.h).
- case PP_PowerPlant::cmd_New:
-
- PP_PowerPlant::LWindow *theWindow =
- PP_PowerPlant::LWindow::CreateWindow(wind_SampleWindow, this);
- ThrowIfNil_(theWindow);
-
- // Hookup the Clear Button
- PP_PowerPlant::LStdButton *button = (PP_PowerPlant::LStdButton*)theWindow->FindPaneByID(Button_Fish);
- ThrowIfNil_(button);
- button->AddListener(this);
-
- // LWindow is not initially visible in PPob resource
- theWindow->Show();
- break;
-
- case MSG_Fish:
- SysBeep(10);
- break;
-
- // Any that you don't handle, such as cmd_About and cmd_Quit,
- // will be passed up to LApplication
- default:
- cmdHandled = PP_PowerPlant::LApplication::ObeyCommand(inCommand, ioParam);
- break;
- }
-
- return cmdHandled;
- }
-
- // ---------------------------------------------------------------------------
- // • ListenToMessage
- // ---------------------------------------------------------------------------
-
- void
- CBasicApp::ListenToMessage(
- PP_PowerPlant::MessageT inMessage,
- void* /* ioParam */)
- {
- switch (inMessage)
- {
- case MSG_Fish:
- {
- SysBeep(10);
- break;
- }
-
- default:
- break;
- }
- }
-
- // ---------------------------------------------------------------------------
- // • FindCommandStatus
- // ---------------------------------------------------------------------------
- // This method enables menu items.
-
- void
- CBasicApp::FindCommandStatus(
- PP_PowerPlant::CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- PP_PowerPlant::Char16 &outMark,
- Str255 outName)
- {
-
- switch (inCommand) {
-
- // Return menu item status according to command messages.
- case PP_PowerPlant::cmd_New:
- case MSG_Fish:
- outEnabled = true;
- break;
-
- // Any that you don't handle, such as cmd_About and cmd_Quit,
- // will be passed up to LApplication
- default:
- LApplication::FindCommandStatus(inCommand, outEnabled,
- outUsesMark, outMark, outName);
- break;
- }
- }
-