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 / Embed / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  6.2 KB  |  236 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Part.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Author:                M.Boetcher
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Embed.hpp"
  13.  
  14. #ifndef PART_H
  15. #include "Part.h"
  16. #endif
  17.  
  18. #ifndef BINDING_K
  19. #include "Binding.k"
  20. #endif
  21.  
  22. #ifndef DEFINES_K
  23. #include "Defines.k"
  24. #endif
  25.  
  26. #ifndef SELECT_H
  27. #include "Select.h"
  28. #endif
  29.  
  30. #ifndef PROXY_H
  31. #include "Proxy.h"
  32. #endif
  33.  
  34. #ifndef FRAME_H
  35. #include "Frame.h"
  36. #endif
  37.  
  38. #ifndef CONTENT_H
  39. #include "Content.h"
  40. #endif
  41.  
  42. // ----- ODF -----
  43.  
  44. #ifndef FWABOUT_H
  45. #include "FWAbout.h"
  46. #endif
  47.  
  48. #ifndef FWMENUS_K
  49. #include "FWMenus.k"
  50. #endif
  51.  
  52. #ifndef FWSUSINK_H
  53. #include "FWSUSink.h"
  54. #endif
  55.  
  56. #ifndef FWCFMRES_H
  57. #include "FWCFMRes.h"
  58. #endif
  59.  
  60. #ifndef FWMNUBAR_H
  61. #include "FWMnuBar.h"
  62. #endif
  63.  
  64. // ----- OpenDoc Includes -----
  65.  
  66. #ifndef SOM_Module_OpenDoc_Commands_defined
  67. #include <CmdDefs.xh>
  68. #endif
  69.  
  70. #ifndef SOM_Module_OpenDoc_StdProps_defined
  71. #include <StdProps.xh>
  72. #endif
  73.  
  74. //========================================================================================
  75. //    Runtime information
  76. //========================================================================================
  77.  
  78. #ifdef FW_BUILD_MAC
  79. #pragma segment odfembed
  80. #endif
  81.  
  82. FW_DEFINE_AUTO(CEmbedPart)
  83.  
  84. //========================================================================================
  85. //    CLASS CEmbedPart
  86. //========================================================================================
  87.  
  88. #define kMainPresentation "Apple:Presentation:EmbedPart"
  89.  
  90. //----------------------------------------------------------------------------------------
  91. //     CEmbedPart constructor
  92. //----------------------------------------------------------------------------------------
  93.  
  94. CEmbedPart::CEmbedPart(ODPart* odPart):
  95.     FW_CEmbeddingPart(odPart, FW_gInstance, kPartInfoID),
  96.     fPresentation(NULL),
  97.     fEmbedContent(NULL),
  98.     fFacetNumber(cOneFacet),
  99.     fRotation(0)
  100. {
  101.     // Do not call anything that can fail
  102.     FW_END_CONSTRUCTOR
  103. }
  104.  
  105. //----------------------------------------------------------------------------------------
  106. //     CEmbedPart::Initialize
  107. //----------------------------------------------------------------------------------------
  108.  
  109. void CEmbedPart::Initialize(Environment* ev, ODStorageUnit* storageUnit, FW_Boolean fromStorage)
  110. {
  111.     FW_CEmbeddingPart::Initialize(ev, storageUnit, fromStorage);
  112.  
  113.     // Create the presentation and selection objects.
  114.     // The selection object is actually owned by the presentation
  115.     CEmbedSelection* selection = FW_NEW(CEmbedSelection, (ev, fEmbedContent));
  116.     fPresentation = RegisterPresentation(ev, kMainPresentation, true, selection);
  117. }
  118.  
  119. //----------------------------------------------------------------------------------------
  120. //     CEmbedPart destructor
  121. //----------------------------------------------------------------------------------------
  122.  
  123. CEmbedPart::~CEmbedPart()
  124. {
  125.     FW_START_DESTRUCTOR
  126. }
  127.  
  128. //----------------------------------------------------------------------------------------
  129. //    CEmbedPart::NewPartContent
  130. //----------------------------------------------------------------------------------------
  131.  
  132. FW_CContent* CEmbedPart::NewPartContent(Environment* ev)
  133. {
  134.     fEmbedContent = FW_NEW(CEmbedContent, (ev, this));
  135.     return fEmbedContent;
  136. }
  137.  
  138. //----------------------------------------------------------------------------------------
  139. //     CEmbedPart::NewFrame
  140. //----------------------------------------------------------------------------------------
  141.  
  142. FW_CFrame* CEmbedPart::NewFrame(Environment* ev, 
  143.                                 ODFrame* odFrame, 
  144.                                 FW_CPresentation* presentation, 
  145.                                 FW_Boolean fromStorage)
  146. {
  147. FW_UNUSED(presentation);
  148. FW_UNUSED(fromStorage);
  149.     
  150.     return FW_NEW(CEmbedFrame, (ev, odFrame, presentation, this, fEmbedContent));
  151. }
  152.  
  153. //----------------------------------------------------------------------------------------
  154. // CEmbedPart::DoAdjustMenus
  155. //----------------------------------------------------------------------------------------
  156.  
  157. FW_Handled CEmbedPart::DoAdjustMenus(Environment* ev, 
  158.                                     FW_CMenuBar* menuBar, 
  159.                                     FW_Boolean hasMenuFocus,
  160.                                     FW_Boolean isRoot)
  161. {
  162. FW_UNUSED(isRoot);
  163.     if (hasMenuFocus)
  164.     {
  165.         FW_Boolean hasProxy = (fEmbedContent->GetProxy() != NULL);
  166.         FW_Boolean oneFacet = (fFacetNumber == cOneFacet);
  167.         
  168.         menuBar->EnableAndCheckCommand(ev, cOneFacet, hasProxy, oneFacet);
  169.         menuBar->EnableAndCheckCommand(ev, cFourFacets, hasProxy, !oneFacet);
  170.         menuBar->EnableAndCheckCommand(ev, cRotateFacets, !oneFacet && (fEmbedContent->GetProxy() != NULL), false);
  171.     }
  172.     
  173.     return FW_kNotHandled;
  174. }
  175.  
  176. //----------------------------------------------------------------------------------------
  177. // CEmbedPart::DoMenu
  178. //----------------------------------------------------------------------------------------
  179.  
  180. FW_Handled CEmbedPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  181. {
  182.     FW_Handled menuHandled = FW_kHandled;
  183.     ODCommandID id = theMenuEvent.GetCommandID(ev);
  184.     
  185.     switch (id)
  186.     {
  187.         case cOneFacet:
  188.         case cFourFacets:
  189.             ChangeEmbeddedFacets(ev, id);
  190.             break;
  191.         
  192.         case cRotateFacets:
  193.             CEmbedProxy* proxy = fEmbedContent->GetProxy();
  194.             FW_ASSERT(proxy);    
  195.             fRotation++;        
  196.             proxy->RotateFacets(ev, fRotation);        
  197.             break;
  198.             
  199.         default:
  200.             menuHandled = FW_kNotHandled;
  201.     }
  202.     
  203.     return menuHandled;
  204. }
  205.  
  206. //----------------------------------------------------------------------------------------
  207. //    CEmbedPart::DoAbout
  208. //----------------------------------------------------------------------------------------
  209.  
  210. FW_Handled CEmbedPart::DoAbout(Environment* ev)
  211. {
  212.     ::FW_About(ev, this, kAbout);
  213.     
  214.     return FW_kHandled;
  215. }
  216.  
  217. //----------------------------------------------------------------------------------------
  218. //     CEmbedPart::ChangeEmbeddedFacets
  219. //----------------------------------------------------------------------------------------
  220.  
  221. void CEmbedPart::ChangeEmbeddedFacets(Environment* ev, ODCommandID facetNumber)
  222. {
  223.     if (fFacetNumber != facetNumber)
  224.     {
  225.         CEmbedProxy* proxy = fEmbedContent->GetProxy();
  226.         FW_ASSERT(proxy);
  227.         
  228.         proxy->HideShow(ev, FALSE);            // hide will remove all the facets    
  229.         fFacetNumber = facetNumber;
  230.         proxy->HideShow(ev, TRUE);            // Show will recreate the facets    
  231.     
  232.         fPresentation->Invalidate(ev);
  233.     }
  234. }
  235.  
  236.