home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / Hello / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  5.9 KB  |  243 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                HelloPrt.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Hello.hpp"
  11.  
  12. #ifndef PART_H
  13. #include "Part.h"
  14. #endif
  15.  
  16. #ifndef CONTENT_H
  17. #include "Content.h"
  18. #endif
  19.  
  20. #ifndef BINDING_K
  21. #include "Binding.k"
  22. #endif
  23.  
  24. #ifndef FRAME_H
  25. #include "Frame.h"
  26. #endif
  27.  
  28. #ifndef SELECT_H
  29. #include "Select.h"
  30. #endif
  31.  
  32. // ----- Framework Layer -----
  33.  
  34. #ifndef FWUTIL_H
  35. #include "FWUtil.h"
  36. #endif
  37.  
  38. #ifndef FWITERS_H
  39. #include "FWIters.h"
  40. #endif
  41.  
  42. #ifndef FWPRESEN_H
  43. #include "FWPresen.h"
  44. #endif
  45.  
  46. // ----- OS Layer -----
  47.  
  48. #ifndef FWMENU_H
  49. #include "FWMenu.h"
  50. #endif
  51.  
  52. #ifndef FWCFMRES_H
  53. #include "FWCFMRes.h"
  54. #endif
  55.  
  56. #ifndef FWRESTYP_H
  57. #include "FWResTyp.h"
  58. #endif
  59.  
  60. #ifndef FWSUSINK_H
  61. #include "FWSUSink.h"
  62. #endif
  63.  
  64. #ifndef FWEVENT_H
  65. #include "FWEvent.h"
  66. #endif
  67.  
  68. #ifndef FWBARRAY_H
  69. #include "FWBArray.h"
  70. #endif
  71.  
  72. #ifndef FWABOUT_H
  73. #include "FWAbout.h"
  74. #endif
  75.  
  76. // ----- Foundation Includes -----
  77.  
  78. #ifndef FWSTREAM_H
  79. #include "FWStream.h"
  80. #endif
  81.  
  82. #ifndef FWSTRS_H
  83. #include "FWStrs.h"
  84. #endif
  85.  
  86. #ifndef FWSUSINK_H
  87. #include "FWSUSink.h"
  88. #endif
  89.  
  90. // ----- OpenDoc Includes -----
  91.  
  92. #ifndef SOM_Module_OpenDoc_StdProps_defined
  93. #include <StdProps.xh>
  94. #endif
  95.  
  96. #ifndef SOM_ODTranslation_xh
  97. #include <Translt.xh>
  98. #endif
  99.  
  100. #ifndef SOM_ODSession_xh
  101. #include <ODSessn.xh>
  102. #endif
  103.  
  104. //========================================================================================
  105. // Constants and Globals
  106. //========================================================================================
  107.  
  108. #define kMainPresentation    "ODFExamples:Presentation:ODFHello"
  109.  
  110. //========================================================================================
  111. //    Runtime info
  112. //========================================================================================
  113.  
  114. #ifdef FW_BUILD_MAC
  115. #pragma segment odfhello
  116. #endif
  117.  
  118. FW_DEFINE_AUTO(CHelloPart)
  119.  
  120. //========================================================================================
  121. //    CHelloPart class
  122. //========================================================================================
  123.  
  124. //----------------------------------------------------------------------------------------
  125. // CHelloPart constructor
  126. //----------------------------------------------------------------------------------------
  127.  
  128. CHelloPart::CHelloPart(ODPart* odPart) :
  129.     FW_CPart(odPart, FW_gInstance, kPartInfoID),
  130.     fPartContent(NULL),
  131.     fPresentation(NULL)
  132. {
  133. }
  134.  
  135. //----------------------------------------------------------------------------------------
  136. // CHelloPart destructor
  137. //----------------------------------------------------------------------------------------
  138.  
  139. CHelloPart::~CHelloPart()
  140. {
  141. }
  142.  
  143. //----------------------------------------------------------------------------------------
  144. // CHelloPart::Initialize
  145. //----------------------------------------------------------------------------------------
  146.  
  147. void CHelloPart::Initialize(Environment* ev)
  148. {
  149.     FW_CPart::Initialize(ev);
  150.  
  151.     // ----- Register our Presentation
  152.     fPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, FW_NEW(CHelloSelection, (ev, fPartContent)));
  153.  
  154.     // ----- Initialize my menu -----
  155.     GetMenuBar(ev)->InitializeFromResource(ev, kMenuBar);
  156. }
  157.  
  158. //----------------------------------------------------------------------------------------
  159. // CHelloPart::NewFrame
  160. //----------------------------------------------------------------------------------------
  161.  
  162. FW_CFrame* CHelloPart::NewFrame(Environment* ev,
  163.                                 ODFrame* odFrame,
  164.                                 FW_CPresentation* presentation,
  165.                                 FW_Boolean fromStorage)    // Override
  166. {
  167.     FW_UNUSED(fromStorage);
  168.  
  169.     return FW_NEW(CHelloFrame, (ev, odFrame, presentation, fPartContent));
  170. }
  171.  
  172. //------------------------------------------------------------------------------
  173. // CHelloPart::NewPartContent
  174. //------------------------------------------------------------------------------
  175.  
  176. FW_CContent* CHelloPart::NewPartContent(Environment* ev)
  177. {
  178.     fPartContent = FW_NEW(CHelloContent, (ev, this));
  179.     return fPartContent;
  180. }
  181.  
  182. //----------------------------------------------------------------------------------------
  183. // CHelloPart::DoMenu
  184. //----------------------------------------------------------------------------------------
  185.  
  186. FW_Boolean CHelloPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent) // Override
  187. {
  188.     FW_Boolean menuHandled = TRUE;
  189.     ODCommandID id = theMenuEvent.GetCommandID(ev);
  190.     
  191.     switch (id)
  192.     {
  193.         case cFirstCommand:
  194.         case cSecondCommand:
  195.             // Toggle the flag that tells whether to center the string
  196.             fPartContent->CenterText(ev, !fPartContent->IsTextCentered());
  197.             break;        
  198.  
  199.         case kODCommandAbout:
  200.             ::FW_About(ev, this, kAbout);
  201.             break;
  202.  
  203.         default:
  204.             menuHandled = FALSE;
  205.     }
  206.     
  207.     return menuHandled;
  208. }
  209.  
  210. //----------------------------------------------------------------------------------------
  211. // CHelloPart::DoAdjustMenus
  212. //----------------------------------------------------------------------------------------
  213.  
  214. FW_Boolean CHelloPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  215.                                      FW_Boolean hasMenuFocus,
  216.                                      FW_Boolean isRoot)
  217. {
  218.     if (hasMenuFocus)
  219.     {
  220.         // ----- Set up the Hello menu
  221.         menuBar->EnableAndCheckCommand(ev, cFirstCommand, TRUE, fPartContent->IsTextCentered());
  222.         menuBar->EnableAndCheckCommand(ev, cSecondCommand, TRUE, !fPartContent->IsTextCentered());
  223.     }
  224.     
  225.     return FALSE;
  226. }
  227.  
  228. //----------------------------------------------------------------------------------------
  229. // CHelloPart::PartChanged
  230. //----------------------------------------------------------------------------------------
  231.  
  232. void CHelloPart::PartChanged(Environment* ev)
  233. {
  234.     // Mark the document's draft as changed so it can be saved
  235.     this->Changed(ev);
  236.  
  237.     // Mark the display frame as changed, so that containing parts can update links
  238.     fPresentation->ContentUpdated(ev);
  239.  
  240.     // Force all display frames to be redrawn
  241.     fPresentation->Invalidate(ev);
  242. }
  243.