home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / moldyn / source / CBasicApp.cp < prev    next >
Encoding:
Text File  |  1999-06-25  |  4.3 KB  |  155 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    CBasicApp.cp                 ©1994-1998 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //    This file contains the starter code for a basic PowerPlant project
  5.  
  6. #include "CBasicApp.h"
  7. #include "CMolDynView.h"
  8.  
  9. #include <LGrowZone.h>
  10. #include <PP_Messages.h>
  11. #include <PP_Resources.h>
  12. #include <PPobClasses.h>
  13. #include <UDrawingState.h>
  14. #include <UMemoryMgr.h>
  15. #include <URegistrar.h>
  16.  
  17. #include <LWindow.h>
  18. #include <LCaption.h>
  19.  
  20. // put declarations for resource ids (ResIDTs) here
  21.  
  22.  
  23. const PP_PowerPlant::ResIDT    wind_SampleWindow = 128;    // EXAMPLE, create a new window
  24.  
  25. // ===========================================================================
  26. //        • Main Program
  27. // ===========================================================================
  28.  
  29. int main()
  30. {
  31.                                 
  32.     SetDebugThrow_(PP_PowerPlant::debugAction_Alert);    // Set Debugging options
  33.     SetDebugSignal_(PP_PowerPlant::debugAction_Alert);
  34.  
  35.     PP_PowerPlant::InitializeHeap(3);                    // Initialize Memory Manager
  36.                                                         // Parameter is number of Master Pointer
  37.                                                         // blocks to allocate
  38.     
  39.     PP_PowerPlant::UQDGlobals::InitializeToolbox(&qd);    // Initialize standard Toolbox managers
  40.     
  41.     new PP_PowerPlant::LGrowZone(20000);                // Install a GrowZone function to catch
  42.                                                         // low memory situations.
  43.  
  44.     CBasicApp    theApp;                                    // replace this with your App type
  45.     theApp.Run();
  46.     
  47.     return 0;
  48. }
  49.  
  50.  
  51. // ---------------------------------------------------------------------------
  52. //        • CBasicApp
  53. // ---------------------------------------------------------------------------
  54. //    Constructor
  55.  
  56. CBasicApp::CBasicApp()
  57. {
  58.     RegisterClass_(PP_PowerPlant::LWindow);        // You must register each kind of
  59.     RegisterClass_(PP_PowerPlant::LCaption);    // PowerPlant classes that you use
  60.                                                 // in your PPob resource.
  61.     RegisterClass_(PP_PowerPlant::LOffscreenView);    // GGG19990624
  62.     RegisterClass_(CMolDynView);    // GGG19990624
  63.     
  64.     mSleepTime = 0;
  65.     
  66. }
  67.  
  68.  
  69. // ---------------------------------------------------------------------------
  70. //        • ~CBasicApp
  71. // ---------------------------------------------------------------------------
  72. //    Destructor
  73.  
  74. CBasicApp::~CBasicApp()
  75. {
  76. }
  77.  
  78. // ---------------------------------------------------------------------------
  79. //        • StartUp
  80. // ---------------------------------------------------------------------------
  81. //    This method lets you do something when the application starts up
  82. //    without a document. For example, you could issue your own new command.
  83.  
  84. void
  85. CBasicApp::StartUp()
  86. {
  87.     ObeyCommand(PP_PowerPlant::cmd_New, nil);        // EXAMPLE, create a new window
  88. }
  89.  
  90. // ---------------------------------------------------------------------------
  91. //        • ObeyCommand
  92. // ---------------------------------------------------------------------------
  93. //    This method lets the application respond to commands like Menu commands
  94.  
  95. Boolean
  96. CBasicApp::ObeyCommand(
  97.     PP_PowerPlant::CommandT    inCommand,
  98.     void                    *ioParam)
  99. {
  100.     Boolean        cmdHandled = true;
  101.  
  102.     switch (inCommand) {
  103.     
  104.         // Handle command messages (defined in PP_Messages.h).
  105.         case PP_PowerPlant::cmd_New:
  106.                                         
  107.             PP_PowerPlant::LWindow    *theWindow =
  108.                                     PP_PowerPlant::LWindow::CreateWindow(wind_SampleWindow, this);
  109.             ThrowIfNil_(theWindow);
  110.             
  111.             // LWindow is not initially visible in PPob resource
  112.             theWindow->Show();
  113.  
  114.             break;
  115.  
  116.         // Any that you don't handle, such as cmd_About and cmd_Quit,
  117.         // will be passed up to LApplication
  118.         default:
  119.             cmdHandled = PP_PowerPlant::LApplication::ObeyCommand(inCommand, ioParam);
  120.             break;
  121.     }
  122.     
  123.     return cmdHandled;
  124. }
  125.  
  126. // ---------------------------------------------------------------------------
  127. //        • FindCommandStatus
  128. // ---------------------------------------------------------------------------
  129. //    This method enables menu items.
  130.  
  131. void
  132. CBasicApp::FindCommandStatus(
  133.     PP_PowerPlant::CommandT    inCommand,
  134.     Boolean                    &outEnabled,
  135.     Boolean                    &outUsesMark,
  136.     PP_PowerPlant::Char16    &outMark,
  137.     Str255                    outName)
  138. {
  139.  
  140.     switch (inCommand) {
  141.     
  142.         // Return menu item status according to command messages.
  143.         case PP_PowerPlant::cmd_New:
  144.             outEnabled = true;
  145.             break;
  146.  
  147.         // Any that you don't handle, such as cmd_About and cmd_Quit,
  148.         // will be passed up to LApplication
  149.         default:
  150.             LApplication::FindCommandStatus(inCommand, outEnabled,
  151.                                                 outUsesMark, outMark, outName);
  152.             break;
  153.     }
  154. }
  155.