home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / System Pulse ƒ / Source Code / Source / CBasicApp.cp next >
Encoding:
Text File  |  2000-06-23  |  3.9 KB  |  164 lines

  1. // ===========================================================================
  2. //    CBasicApp.cp                 ©1994-1999 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //    This file contains the starter code for a basic PowerPlant project
  5.  
  6. #include "CBasicApp.h"
  7.  
  8. #include <LGrowZone.h>
  9. #include <PP_Messages.h>
  10. #include <PP_Resources.h>
  11. #include <UDrawingState.h>
  12. #include <UMemoryMgr.h>
  13. #include <URegistrar.h>
  14.  
  15. #include <LWindow.h>
  16. #include <LCaption.h>
  17.  
  18. #include "MenuBarEffects.h"
  19.  
  20.     // Constant declarations
  21. const ResIDT    PPob_SampleWindow            = 128;
  22.  
  23.  
  24. // ===========================================================================
  25. //    • main
  26. // ===========================================================================
  27.  
  28. int main()
  29. {                            
  30.         // Set Debugging options
  31.     SetDebugThrow_(debugAction_Alert);
  32.     SetDebugSignal_(debugAction_Alert);
  33.  
  34.         // Initialize Memory Manager. Parameter is the number of
  35.         // master pointer blocks to allocate
  36.     InitializeHeap(3);
  37.     
  38.         // Initialize standard Toolbox managers
  39.     UQDGlobals::InitializeToolbox(&qd);
  40.     
  41.         // Install a GrowZone to catch low-memory situations    
  42.     new LGrowZone(20000);
  43.  
  44.         // Create the application object and run
  45.     CBasicApp    theApp;
  46.     
  47.     StartMenuBarEffect();
  48.  
  49.     theApp.Run();
  50.     
  51.     EndMenuBarEffect();
  52.     
  53.     return 0;
  54. }
  55.  
  56.  
  57. // ---------------------------------------------------------------------------
  58. //    • CBasicApp                                        [public]
  59. // ---------------------------------------------------------------------------
  60. //    Application object constructor
  61.  
  62. CBasicApp::CBasicApp()
  63. {
  64.     RegisterClasses();
  65. }
  66.  
  67.  
  68. // ---------------------------------------------------------------------------
  69. //    • ~CBasicApp                                    [public, virtual]
  70. // ---------------------------------------------------------------------------
  71. //    Application object destructor
  72.  
  73. CBasicApp::~CBasicApp()
  74. {
  75.     // Nothing
  76. }
  77.  
  78.  
  79. // ---------------------------------------------------------------------------
  80. //    • StartUp                                        [protected, virtual]
  81. // ---------------------------------------------------------------------------
  82. //    Perform an action in response to the Open Application AppleEvent.
  83. //    Here, issue the New command to open a window.
  84.  
  85. void
  86. CBasicApp::StartUp()
  87. {
  88.     ObeyCommand(cmd_New, nil);
  89. }
  90.  
  91.  
  92. // ---------------------------------------------------------------------------
  93. //    • ObeyCommand                                    [public, virtual]
  94. // ---------------------------------------------------------------------------
  95. //    Respond to Commands. Returns true if the Command was handled, false if not.
  96.  
  97. Boolean
  98. CBasicApp::ObeyCommand(
  99.     CommandT    inCommand,
  100.     void*        ioParam)
  101. {
  102.     Boolean        cmdHandled = true;    // Assume we'll handle the command
  103.  
  104.     switch (inCommand) {
  105.  
  106.         case cmd_New: {
  107.             LWindow* theWindow = LWindow::CreateWindow(PPob_SampleWindow, this);
  108.             ThrowIfNil_(theWindow);
  109.  
  110.             theWindow->Show();
  111.             break;
  112.         }
  113.  
  114.         default: {
  115.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  116.             break;
  117.         }
  118.     }
  119.     
  120.     return cmdHandled;
  121. }
  122.  
  123.  
  124. // ---------------------------------------------------------------------------
  125. //    • FindCommandStatus                                [public, virtual]
  126. // ---------------------------------------------------------------------------
  127. //    Determine the status of a Command for the purposes of menu updating.
  128.  
  129. void
  130. CBasicApp::FindCommandStatus(
  131.     CommandT    inCommand,
  132.     Boolean&    outEnabled,
  133.     Boolean&    outUsesMark,
  134.     UInt16&        outMark,
  135.     Str255        outName)
  136. {
  137.     switch (inCommand) {
  138.  
  139.         case cmd_New: {
  140.             outEnabled = true;
  141.             break;
  142.         }
  143.  
  144.         default: {
  145.             LApplication::FindCommandStatus(inCommand, outEnabled,
  146.                                             outUsesMark, outMark, outName);
  147.             break;
  148.         }
  149.     }
  150. }
  151.  
  152.  
  153. // ---------------------------------------------------------------------------
  154. //    • RegisterClasses                                [protected]
  155. // ---------------------------------------------------------------------------
  156. //    To reduce clutter within the Application object's constructor, class
  157. //    registrations appear here in this seperate function for ease of use.
  158.  
  159. void
  160. CBasicApp::RegisterClasses()
  161. {
  162.     RegisterClass_(LWindow);
  163.     RegisterClass_(LCaption);
  164. }