home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / Papers / aSEPiA example source / Application / source / CDocumentApp.cp next >
Encoding:
Text File  |  1999-06-25  |  5.2 KB  |  173 lines  |  [TEXT/CWIE]

  1. // =================================================================================
  2. //    CDocumentApp.cp                    ©1996-1998 Metrowerks Inc. All rights reserved.
  3. // =================================================================================
  4. //    This file contains the starter code for a document PowerPlant project
  5. //
  6. //  The Application is derived from LDocApplication.  New Windows are managed
  7. //  by CTextDocument which is derived from LSingleDoc.  Each document contains
  8. //  a smart text view that remembers if it has changed since it was last saved.
  9.  
  10. #include "CDocumentApp.h"
  11.  
  12. #include <StandardFile.h>
  13.  
  14. #include <LGrowZone.h>
  15. #include <PP_Messages.h>
  16. #include <PP_Resources.h>
  17. #include <PPobClasses.h>
  18. #include <UDesktop.h>
  19. #include <UDrawingState.h>
  20. #include <UMemoryMgr.h>
  21. #include <URegistrar.h>
  22. #include <UTextTraits.h>
  23.  
  24. #include <UStandardDialogs.h>
  25.  
  26. #include <LActiveScroller.h>
  27. #include <LWindow.h>
  28. #include <LPrintout.h>
  29. #include <LPlaceHolder.h>
  30.  
  31. #include "PrintingConstants.h"
  32. #include "CTextDocument.h"
  33. #include "CTextView.h"
  34.  
  35.  
  36. // =================================================================================
  37. //        • Main Program
  38. // ===========================================================================
  39.  
  40. int main()
  41. {
  42.                                 
  43.     SetDebugThrow_(PP_PowerPlant::debugAction_Alert);    // Set Debugging options
  44.     SetDebugSignal_(PP_PowerPlant::debugAction_Alert);
  45.  
  46.     PP_PowerPlant::InitializeHeap(3);                    // Initialize Memory Manager
  47.                                                         // Parameter is number of Master Pointer
  48.                                                         // blocks to allocate
  49.     
  50.     PP_PowerPlant::UQDGlobals::InitializeToolbox(&qd);    // Initialize standard Toolbox managers
  51.     
  52.     new PP_PowerPlant::LGrowZone(20000);                // Install a GrowZone function to catch
  53.                                                         // low memory situations.
  54.  
  55.     CDocumentApp    theApp;                                // create instance of your application
  56.     theApp.Run();
  57.     
  58.     return 0;
  59. }
  60.  
  61.  
  62. // ---------------------------------------------------------------------------------
  63. //        • CDocumentApp
  64. // ---------------------------------------------------------------------------------
  65. //    Constructor
  66.  
  67. CDocumentApp::CDocumentApp()
  68. {
  69.     RegisterClass_(PP_PowerPlant::LWindow);            // You must register each kind of
  70.     RegisterClass_(PP_PowerPlant::LActiveScroller);    // PowerPlant classes that you use
  71.     RegisterClass_(PP_PowerPlant::LPrintout);        // in your PPob resource.
  72.     RegisterClass_(PP_PowerPlant::LPlaceHolder);
  73.     RegisterClass_(CTextView);
  74.     
  75.     PP_PowerPlant::PP_StandardDialogs::Load();        // Preload facilities for std dialogs    
  76. }
  77.  
  78.  
  79. // ---------------------------------------------------------------------------------
  80. //        • ~CDocumentApp
  81. // ---------------------------------------------------------------------------------
  82. //    Destructor
  83.  
  84. CDocumentApp::~CDocumentApp()
  85. {
  86.     PP_PowerPlant::PP_StandardDialogs::Unload();    // Clean up after std dialogs
  87. }
  88.  
  89.  
  90. // ---------------------------------------------------------------------------------
  91. //        • StartUp
  92. // ---------------------------------------------------------------------------------
  93. //    This function lets you do something when the application starts up
  94. //    without a document. For example, you could issue your own new command.
  95.  
  96. void
  97. CDocumentApp::StartUp()
  98. {
  99. }
  100.  
  101.  
  102. // ---------------------------------------------------------------------------------
  103. //        • OpenDocument
  104. // ---------------------------------------------------------------------------------
  105. // This method is called when a file is chosen from the StandardFile Open Dialog
  106. // File_Menu->Open item.
  107.  
  108. void
  109. CDocumentApp::OpenDocument(
  110.     FSSpec    *inMacFSSpec )
  111. {
  112.     PP_PowerPlant::LDocument    *theDoc = PP_PowerPlant::LDocument::FindByFileSpec(*inMacFSSpec);
  113.     
  114.     // If the document is already open, make it the current document
  115.     if (theDoc != nil) {                
  116.         theDoc->MakeCurrent();
  117.         
  118.     // otherwise, make a new Document
  119.     } else {                            
  120.         theDoc = new CTextDocument(this, inMacFSSpec);
  121.     }
  122. }
  123.  
  124.  
  125. // ---------------------------------------------------------------------------------
  126. //        • MakeNewDocument
  127. // ---------------------------------------------------------------------------------
  128. // This method creates a new document and installs it into the application's
  129. // Apple Event Object Model hierarchy.
  130.  
  131. PP_PowerPlant::LModelObject *
  132. CDocumentApp::MakeNewDocument()
  133. {
  134.     // Make a new empty document.
  135.     return new CTextDocument( this, nil );
  136. }
  137.  
  138.  
  139. // ---------------------------------------------------------------------------------
  140. //        • ChooseDocument
  141. // ---------------------------------------------------------------------------------
  142. // This method uses the PowerPlant Standard Dialogs to let the user choose a
  143. // document to open.
  144.  
  145. void
  146. CDocumentApp::ChooseDocument()
  147. {
  148.     PP_PowerPlant::PP_StandardDialogs::LFileChooser    chooser;
  149.     
  150.     if (chooser.AskOpenFile(PP_PowerPlant::LFileTypeList('TEXT'))) {
  151.         AEDescList        docList;
  152.         chooser.GetFileDescList(docList);
  153.         OpenOrPrintDocList(docList, PP_PowerPlant::ae_OpenDoc);
  154.     }
  155. }
  156.  
  157.  
  158. // ---------------------------------------------------------------------------------
  159. //        • PrintDocument
  160. // ---------------------------------------------------------------------------------
  161. // This method is called when the FileMenu->Print item is chosen.
  162.  
  163. void
  164. CDocumentApp::PrintDocument(
  165.     FSSpec    *inMacFSSpec )
  166. {
  167.     // Create a new document using the file spec.
  168.     CTextDocument    *theDocument = new CTextDocument( this, inMacFSSpec );
  169.  
  170.     // Tell the document to print.
  171.     theDocument->DoPrint();
  172. }
  173.