home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / HCmdButtonAttachment 1.1.1 / HCmdButtonAttachment Demo / PP Basic Starter.cp < prev    next >
Encoding:
Text File  |  1997-04-23  |  4.9 KB  |  189 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    PP Basic Starter.cp         ©1994-1997 Metrowerks Inc. All rights reserved.
  3. // ===========================================================================
  4. //
  5. //    This file contains the starter code for a basic PowerPlant application
  6.  
  7. #include "PP Basic Starter.h"
  8.  
  9. #include <LGrowZone.h>
  10. #include <LWindow.h>
  11. #include <PP_Messages.h>
  12. #include <PP_Resources.h>
  13. #include <UDrawingState.h>
  14. #include <UMemoryMgr.h>
  15. #include <URegistrar.h>
  16. #include <UModalDialogs.h>
  17. #include <LEditField.h>
  18. #include <LGADialogBox.h>
  19. #include <LGAPushButton.h>
  20. #include <LGATextButton.h>
  21. #include <LGAPrimaryGroup.h>
  22. #include <LGARadioButton.h>
  23. #include <LGACheckbox.h>
  24. #include <LGAIconButton.h>
  25.  
  26. #include "HCmdButtonAttachment.h"
  27.  
  28. // put declarations for resource ids (ResIDTs) here
  29.  
  30. const ResIDT    window_Sample        = 1;    // EXAMPLE
  31. const ResIDT    dialog_Sample        = 2;
  32.  
  33.  
  34. // ===========================================================================
  35. //        • Main Program
  36. // ===========================================================================
  37.  
  38. void main(void)
  39. {
  40.                                     // Set Debugging options
  41.     SetDebugThrow_(debugAction_Alert);
  42.     SetDebugSignal_(debugAction_Alert);
  43.  
  44.     InitializeHeap(3);                // Initialize Memory Manager
  45.                                     // Parameter is number of Master Pointer
  46.                                     //   blocks to allocate
  47.     
  48.                                     // Initialize standard Toolbox managers
  49.     UQDGlobals::InitializeToolbox(&qd);
  50.     
  51.     new LGrowZone(20000);            // Install a GrowZone function to catch
  52.                                     //    low memory situations.
  53.  
  54.     CPPStarterApp    theApp;            // replace this with your App type
  55.     theApp.Run();
  56. }
  57.  
  58.  
  59. // ---------------------------------------------------------------------------
  60. //        • CPPStarterApp             // replace this with your App type
  61. // ---------------------------------------------------------------------------
  62. //    Constructor
  63.  
  64. CPPStarterApp::CPPStarterApp()
  65. {
  66.     // Register functions to create core PowerPlant classes
  67.     
  68.     RegisterClass_(LWindow);
  69.     RegisterClass_(LCaption);
  70.     RegisterClass_(LStdButton);
  71.     RegisterClass_(LGADialogBox);
  72.     RegisterClass_(LGAPushButton);
  73.     RegisterClass_(LGATextButton);
  74.     RegisterClass_(LGAPrimaryGroup);
  75.     RegisterClass_(LGARadioButton);
  76.     RegisterClass_(LGACheckbox);
  77.     RegisterClass_(LGAIconButton);
  78.     
  79.     RegisterClass_(HCmdButtonAttachment);
  80. }
  81.  
  82.  
  83. // ---------------------------------------------------------------------------
  84. //        • ~CPPStarterApp            // replace this with your App type
  85. // ---------------------------------------------------------------------------
  86. //    Destructor
  87. //
  88.  
  89. CPPStarterApp::~CPPStarterApp()
  90. {
  91. }
  92.  
  93. // ---------------------------------------------------------------------------
  94. //        • StartUp
  95. // ---------------------------------------------------------------------------
  96. //    This function lets you do something when the application starts up
  97. //    without a document. For example, you could issue your own new command.
  98.  
  99. void
  100. CPPStarterApp::StartUp()
  101. {
  102.     ObeyCommand(cmd_New, nil);        // EXAMPLE, create a new window
  103. }
  104.  
  105. // ---------------------------------------------------------------------------
  106. //        • ObeyCommand
  107. // ---------------------------------------------------------------------------
  108. //    Respond to commands
  109.  
  110. Boolean
  111. CPPStarterApp::ObeyCommand(
  112.     CommandT    inCommand,
  113.     void        *ioParam)
  114. {
  115.     Boolean        cmdHandled = true;
  116.  
  117.     switch (inCommand) {
  118.     
  119.         // Deal with command messages (defined in PP_Messages.h).
  120.         // Any that you don't handle will be passed to LApplication
  121.              
  122.         case cmd_New:
  123.                                         // EXAMPLE, create a new window
  124.             LWindow        *theWindow;
  125.             theWindow = LWindow::CreateWindow(window_Sample, this);    
  126.             theWindow->Show();
  127.             break;
  128.  
  129.         case cmd_Open: {
  130.         
  131.             StDialogHandler theHandler(dialog_Sample, this );
  132.             
  133.             // attach a HCmdButtonAttachment on the fly...
  134.             
  135.             theHandler.GetDialog()->AddAttachment(  new HCmdButtonAttachment(
  136.                                                     'Fly ',        // our PaneIDT
  137.                                                     0,            // use the desc's first char
  138.                                                     30,            // wait half a sec
  139.                                                     true ) );    // and draw the shortcut
  140.             theHandler.GetDialog()->Show();
  141.             
  142.             MessageT theMessage;
  143.             do {
  144.                 theMessage = theHandler.DoDialog();
  145.             } while ( (theMessage != msg_OK) && (theMessage != msg_Cancel));
  146.             
  147.             break;
  148.         }
  149.  
  150.         default:
  151.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  152.             break;
  153.     }
  154.     
  155.     return cmdHandled;
  156. }
  157.  
  158. // ---------------------------------------------------------------------------
  159. //        • FindCommandStatus
  160. // ---------------------------------------------------------------------------
  161. //    This function enables menu commands.
  162. //
  163.  
  164. void
  165. CPPStarterApp::FindCommandStatus(
  166.     CommandT    inCommand,
  167.     Boolean        &outEnabled,
  168.     Boolean        &outUsesMark,
  169.     Char16        &outMark,
  170.     Str255        outName)
  171. {
  172.  
  173.     switch (inCommand) {
  174.     
  175.         // Return menu item status according to command messages.
  176.         // Any that you don't handle will be passed to LApplication
  177.  
  178.         case cmd_New:                    // EXAMPLE
  179.         case cmd_Open:
  180.             outEnabled = true;            // enable the New command
  181.             break;
  182.  
  183.         default:
  184.             LApplication::FindCommandStatus(inCommand, outEnabled,
  185.                                                 outUsesMark, outMark, outName);
  186.             break;
  187.     }
  188. }
  189.