home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Hello / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  6.4 KB  |  259 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                HelloPrt.cpp
  4. //    Release Version:    $ ODF 2 $
  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.     FW_END_CONSTRUCTOR
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. // CHelloPart destructor
  138. //----------------------------------------------------------------------------------------
  139.  
  140. CHelloPart::~CHelloPart()
  141. {
  142.     FW_START_DESTRUCTOR
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. // CHelloPart::Initialize
  147. //----------------------------------------------------------------------------------------
  148.  
  149. void CHelloPart::Initialize(Environment* ev, ODStorageUnit* storageUnit, FW_Boolean fromStorage)
  150. {
  151.     FW_CPart::Initialize(ev, storageUnit, fromStorage);
  152.  
  153.     // ----- Register our Presentation
  154.     fPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, FW_NEW(CHelloSelection, (ev, fPartContent)));
  155.     
  156.     // ----- Register our other kinds -----
  157.     RegisterKind(ev, 'TEXT', kODPlatformDataType, FW_kAllStorage, FW_kImportExportEnabled);
  158.     RegisterKind(ev, 'TEXT', kODPlatformFileType, FW_kDataInterchangeStorage, FW_kImport);
  159. }
  160.  
  161. //----------------------------------------------------------------------------------------
  162. // CHelloPart::NewFrame
  163. //----------------------------------------------------------------------------------------
  164.  
  165. FW_CFrame* CHelloPart::NewFrame(Environment* ev,
  166.                                 ODFrame* odFrame,
  167.                                 FW_CPresentation* presentation,
  168.                                 FW_Boolean fromStorage)    // Override
  169. {
  170.     FW_UNUSED(fromStorage);
  171.  
  172.     return FW_NEW(CHelloFrame, (ev, odFrame, presentation, fPartContent));
  173. }
  174.  
  175. //------------------------------------------------------------------------------
  176. // CHelloPart::NewPartContent
  177. //------------------------------------------------------------------------------
  178.  
  179. FW_CContent* CHelloPart::NewPartContent(Environment* ev)
  180. {
  181.     fPartContent = FW_NEW(CHelloContent, (ev, this));
  182.     return fPartContent;
  183. }
  184.  
  185. //----------------------------------------------------------------------------------------
  186. // CHelloPart::DoMenu
  187. //----------------------------------------------------------------------------------------
  188.  
  189. FW_Handled CHelloPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent) // Override
  190. {
  191.     FW_Handled menuHandled = FW_kHandled;
  192.     ODCommandID id = theMenuEvent.GetCommandID(ev);
  193.     
  194.     switch (id)
  195.     {
  196.         case cPlaceInCenter:
  197.             fPartContent->CenterText(ev, TRUE);
  198.             break;
  199.             
  200.         case cPlaceAtTop:
  201.             fPartContent->CenterText(ev, FALSE);
  202.             break;        
  203.  
  204.         default:
  205.             menuHandled = FW_kNotHandled;
  206.     }
  207.     
  208.     return menuHandled;
  209. }
  210.  
  211. //----------------------------------------------------------------------------------------
  212. //    CHelloPart::DoAbout
  213. //----------------------------------------------------------------------------------------
  214.  
  215. FW_Handled CHelloPart::DoAbout(Environment* ev)
  216. {
  217.     ::FW_About(ev, this, kAbout);
  218.     
  219.     return FW_kHandled;
  220. }
  221.  
  222. //----------------------------------------------------------------------------------------
  223. // CHelloPart::DoAdjustMenus
  224. //----------------------------------------------------------------------------------------
  225.  
  226. FW_Handled CHelloPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  227.                                      FW_Boolean hasMenuFocus,
  228.                                      FW_Boolean isRoot)
  229. {
  230. FW_UNUSED(isRoot);
  231.     if (hasMenuFocus)
  232.     {
  233.         // ----- Set up the Hello menu
  234.         menuBar->EnableAndCheckCommand(ev, cPlaceInCenter, TRUE, fPartContent->IsTextCentered());
  235.         menuBar->EnableAndCheckCommand(ev, cPlaceAtTop, TRUE, !fPartContent->IsTextCentered());
  236.     }
  237.     
  238.     return FW_kNotHandled;
  239. }
  240.  
  241. //----------------------------------------------------------------------------------------
  242. // CHelloPart::PartChanged
  243. //----------------------------------------------------------------------------------------
  244.  
  245. void CHelloPart::PartChanged(Environment* ev, FW_Boolean invalidateOnly)
  246. {
  247.     if (!invalidateOnly)
  248.     {
  249.         // Mark the document's draft as changed so it can be saved
  250.         this->Changed(ev);
  251.  
  252.         // Mark the display frame as changed, so that containing parts can update links
  253.         fPresentation->ContentUpdated(ev);
  254.     }
  255.  
  256.     // Force all display frames to be redrawn
  257.     fPresentation->Invalidate(ev);
  258. }
  259.