home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-06-25 | 5.2 KB | 173 lines | [TEXT/CWIE] |
- // =================================================================================
- // CDocumentApp.cp ©1996-1998 Metrowerks Inc. All rights reserved.
- // =================================================================================
- // This file contains the starter code for a document PowerPlant project
- //
- // The Application is derived from LDocApplication. New Windows are managed
- // by CTextDocument which is derived from LSingleDoc. Each document contains
- // a smart text view that remembers if it has changed since it was last saved.
-
- #include "CDocumentApp.h"
-
- #include <StandardFile.h>
-
- #include <LGrowZone.h>
- #include <PP_Messages.h>
- #include <PP_Resources.h>
- #include <PPobClasses.h>
- #include <UDesktop.h>
- #include <UDrawingState.h>
- #include <UMemoryMgr.h>
- #include <URegistrar.h>
- #include <UTextTraits.h>
-
- #include <UStandardDialogs.h>
-
- #include <LActiveScroller.h>
- #include <LWindow.h>
- #include <LPrintout.h>
- #include <LPlaceHolder.h>
-
- #include "PrintingConstants.h"
- #include "CTextDocument.h"
- #include "CTextView.h"
-
-
- // =================================================================================
- // • 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.
-
- CDocumentApp theApp; // create instance of your application
- theApp.Run();
-
- return 0;
- }
-
-
- // ---------------------------------------------------------------------------------
- // • CDocumentApp
- // ---------------------------------------------------------------------------------
- // Constructor
-
- CDocumentApp::CDocumentApp()
- {
- RegisterClass_(PP_PowerPlant::LWindow); // You must register each kind of
- RegisterClass_(PP_PowerPlant::LActiveScroller); // PowerPlant classes that you use
- RegisterClass_(PP_PowerPlant::LPrintout); // in your PPob resource.
- RegisterClass_(PP_PowerPlant::LPlaceHolder);
- RegisterClass_(CTextView);
-
- PP_PowerPlant::PP_StandardDialogs::Load(); // Preload facilities for std dialogs
- }
-
-
- // ---------------------------------------------------------------------------------
- // • ~CDocumentApp
- // ---------------------------------------------------------------------------------
- // Destructor
-
- CDocumentApp::~CDocumentApp()
- {
- PP_PowerPlant::PP_StandardDialogs::Unload(); // Clean up after std dialogs
- }
-
-
- // ---------------------------------------------------------------------------------
- // • StartUp
- // ---------------------------------------------------------------------------------
- // This function lets you do something when the application starts up
- // without a document. For example, you could issue your own new command.
-
- void
- CDocumentApp::StartUp()
- {
- }
-
-
- // ---------------------------------------------------------------------------------
- // • OpenDocument
- // ---------------------------------------------------------------------------------
- // This method is called when a file is chosen from the StandardFile Open Dialog
- // File_Menu->Open item.
-
- void
- CDocumentApp::OpenDocument(
- FSSpec *inMacFSSpec )
- {
- PP_PowerPlant::LDocument *theDoc = PP_PowerPlant::LDocument::FindByFileSpec(*inMacFSSpec);
-
- // If the document is already open, make it the current document
- if (theDoc != nil) {
- theDoc->MakeCurrent();
-
- // otherwise, make a new Document
- } else {
- theDoc = new CTextDocument(this, inMacFSSpec);
- }
- }
-
-
- // ---------------------------------------------------------------------------------
- // • MakeNewDocument
- // ---------------------------------------------------------------------------------
- // This method creates a new document and installs it into the application's
- // Apple Event Object Model hierarchy.
-
- PP_PowerPlant::LModelObject *
- CDocumentApp::MakeNewDocument()
- {
- // Make a new empty document.
- return new CTextDocument( this, nil );
- }
-
-
- // ---------------------------------------------------------------------------------
- // • ChooseDocument
- // ---------------------------------------------------------------------------------
- // This method uses the PowerPlant Standard Dialogs to let the user choose a
- // document to open.
-
- void
- CDocumentApp::ChooseDocument()
- {
- PP_PowerPlant::PP_StandardDialogs::LFileChooser chooser;
-
- if (chooser.AskOpenFile(PP_PowerPlant::LFileTypeList('TEXT'))) {
- AEDescList docList;
- chooser.GetFileDescList(docList);
- OpenOrPrintDocList(docList, PP_PowerPlant::ae_OpenDoc);
- }
- }
-
-
- // ---------------------------------------------------------------------------------
- // • PrintDocument
- // ---------------------------------------------------------------------------------
- // This method is called when the FileMenu->Print item is chosen.
-
- void
- CDocumentApp::PrintDocument(
- FSSpec *inMacFSSpec )
- {
- // Create a new document using the file spec.
- CTextDocument *theDocument = new CTextDocument( this, inMacFSSpec );
-
- // Tell the document to print.
- theDocument->DoPrint();
- }
-