home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / Sessions / Traut / ZStrings / Source / MacOS / GraphicalTool / MacZStringToolApp.cp < prev    next >
Encoding:
Text File  |  2001-06-23  |  5.3 KB  |  198 lines

  1. /*==================================================================
  2.     File:        MacZStringToolApp.cp
  3.  
  4.     Contains:    Primary application class for the Mac ZString tool
  5.                 (based on the PowerPlant framework)
  6.  
  7.     Written by:    Eric Traut
  8.  
  9.     Copyright:    2000-2001 Connectix Corporation
  10.     
  11.     This source has been placed into the public domain by
  12.     Connectix Corporation. You have the right to modify, 
  13.     distribute or use this code without any legal limitations
  14.     or finanicial/licensing requirements. Connectix is not 
  15.     liable for any problems that result from the use of this 
  16.     code.
  17.     
  18.     If you have comments, feedback, questions, or would like
  19.     to submit bug fixes or updates to this code, please email
  20.     opensource@connectix.com.
  21. ==================================================================*/
  22.  
  23. #include "MacZStringToolApp.h"
  24.  
  25. #include <LGrowZone.h>
  26. #include <PP_Messages.h>
  27. #include <PP_Resources.h>
  28. #include <UDrawingState.h>
  29. #include <UMemoryMgr.h>
  30. #include <URegistrar.h>
  31. #include <UEnvironment.h>
  32.  
  33. #include <UControlRegistry.h>
  34.  
  35. #include "MacZStringWindow.h"
  36. #include "FileIconPane.h"
  37. #include "FileSelectionGroupView.h"
  38.  
  39. #include <Appearance.h>
  40.  
  41.  
  42.     // Constant declarations
  43. const ResIDT    PPob_SampleWindow            = 128;
  44.  
  45.  
  46. // ===========================================================================
  47. //    • main
  48. // ===========================================================================
  49.  
  50. int main()
  51. {                            
  52.         // Set Debugging options
  53.     SetDebugThrow_(debugAction_Alert);
  54.     SetDebugSignal_(debugAction_Alert);
  55.  
  56.         // Initialize Memory Manager. Parameter is the number of
  57.         // master pointer blocks to allocate
  58.     InitializeHeap(3);
  59.     
  60.         // Initialize standard Toolbox managers
  61.     UQDGlobals::InitializeToolbox(&qd);
  62.     
  63.         // Install a GrowZone to catch low-memory situations    
  64.     new LGrowZone(20000);
  65.  
  66.         // Create the application object and run
  67.     MacZStringToolApp    theApp;
  68.     theApp.Run();
  69.     
  70.     return 0;
  71. }
  72.  
  73.  
  74. // ---------------------------------------------------------------------------
  75. //    • MacZStringToolApp                                [public]
  76. // ---------------------------------------------------------------------------
  77. //    Application object constructor
  78.  
  79. MacZStringToolApp::MacZStringToolApp()
  80. {
  81.         // Register ourselves with the Appearance Manager
  82.     if (UEnvironment::HasFeature(env_HasAppearance))
  83.         ::RegisterAppearanceClient();
  84.  
  85.     RegisterClasses();
  86. }
  87.  
  88.  
  89. // ---------------------------------------------------------------------------
  90. //    • ~MacZStringToolApp                                [public, virtual]
  91. // ---------------------------------------------------------------------------
  92. //    Application object destructor
  93.  
  94. MacZStringToolApp::~MacZStringToolApp()
  95. {
  96.     // Nothing
  97. }
  98.  
  99.  
  100. // ---------------------------------------------------------------------------
  101. //    • StartUp                                        [protected, virtual]
  102. // ---------------------------------------------------------------------------
  103. //    Perform an action in response to the Open Application AppleEvent.
  104. //    Here, issue the New command to open a window.
  105.  
  106. void
  107. MacZStringToolApp::StartUp()
  108. {
  109.     ObeyCommand(cmd_New, NULL);
  110. }
  111.  
  112.  
  113. // ---------------------------------------------------------------------------
  114. //    • ObeyCommand                                    [public, virtual]
  115. // ---------------------------------------------------------------------------
  116. //    Respond to Commands. Returns true if the Command was handled, false if not.
  117.  
  118. Boolean
  119. MacZStringToolApp::ObeyCommand(
  120.     CommandT    inCommand,
  121.     void*        ioParam)
  122. {
  123.     Boolean        cmdHandled = true;    // Assume we'll handle the command
  124.  
  125.     switch (inCommand)
  126.     {
  127.         case cmd_New:
  128.             LWindow* theWindow = LWindow::CreateWindow(PPob_SampleWindow, this);
  129.             ThrowIfNULL_(theWindow);
  130.  
  131.             theWindow->Show();
  132.             break;
  133.  
  134.         default:
  135.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  136.             break;
  137.     }
  138.     
  139.     return cmdHandled;
  140. }
  141.  
  142.  
  143. // ---------------------------------------------------------------------------
  144. //    • FindCommandStatus                                [public, virtual]
  145. // ---------------------------------------------------------------------------
  146. //    Determine the status of a Command for the purposes of menu updating.
  147.  
  148. void
  149. MacZStringToolApp::FindCommandStatus(
  150.     CommandT    inCommand,
  151.     Boolean&    outEnabled,
  152.     Boolean&    outUsesMark,
  153.     UInt16&        outMark,
  154.     Str255        outName)
  155. {
  156.     switch (inCommand)
  157.     {
  158.         case cmd_New:
  159.             outEnabled = true;
  160.             break;
  161.  
  162.         default:
  163.             LApplication::FindCommandStatus(inCommand, outEnabled,
  164.                                             outUsesMark, outMark, outName);
  165.             break;
  166.     }
  167. }
  168.  
  169.  
  170. // ---------------------------------------------------------------------------
  171. //    • RegisterClasses                                [protected]
  172. // ---------------------------------------------------------------------------
  173. //    To reduce clutter within the Application object's constructor, class
  174. //    registrations appear here in this seperate function for ease of use.
  175.  
  176. void
  177. MacZStringToolApp::RegisterClasses()
  178. {
  179.         // Register core PowerPlant classes.
  180.     RegisterClass_(LWindow);
  181.     RegisterClass_(MacZStringWindow);
  182.     RegisterClass_(FileIconPane);
  183.     RegisterClass_(FileSelectionGroupView);
  184.  
  185.         // Register the Appearance Manager/GA classes. You may want
  186.         // to remove this use of UControlRegistry and instead perform
  187.         // a "manual" registration of the classes. This cuts down on
  188.         // extra code being linked in and streamlines your app and
  189.         // project. However, use UControlRegistry as a reference/index
  190.         // for your work, and ensure to check UControlRegistry against
  191.         // your registrations each PowerPlant release in case
  192.         // any mappings might have changed.
  193.         
  194.     UControlRegistry::RegisterClasses();
  195. }
  196.  
  197.  
  198.