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 / Content.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  5.5 KB  |  206 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Content.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 CONTENT_H
  15. #include "Content.h"
  16. #endif
  17.  
  18. #ifndef PART_H
  19. #include "Part.h"
  20. #endif
  21.  
  22. #ifndef PROXY_H
  23. #include "Proxy.h"
  24. #endif
  25.  
  26. #ifndef FRAME_H
  27. #include "Frame.h"
  28. #endif
  29.  
  30. #ifndef FWPRESEN_H
  31. #include "FWPresen.h"
  32. #endif
  33.  
  34. #ifndef FWKIND_H
  35. #include "FWKind.h"
  36. #endif
  37.  
  38. #ifndef FWSUSINK_H
  39. #include "FWSUSink.h"
  40. #endif
  41.  
  42. #ifndef FWSUUTIL_H
  43. #include "FWSUUtil.h"
  44. #endif
  45.  
  46. #ifndef FWBUFSIN_H
  47. #include "FWBufSin.h"
  48. #endif
  49.  
  50. // ----- OpenDoc Includes -----
  51.  
  52. #ifndef SOM_Module_OpenDoc_StdProps_defined
  53. #include <StdProps.xh>
  54. #endif
  55.  
  56. //========================================================================================
  57. //    Runtime information
  58. //========================================================================================
  59.  
  60. #ifdef FW_BUILD_MAC
  61. #pragma segment odfembed
  62. #endif
  63.  
  64. FW_DEFINE_AUTO(CEmbedContent)
  65.  
  66. //========================================================================================
  67. //    CLASS CEmbedContent
  68. //========================================================================================
  69.  
  70. //----------------------------------------------------------------------------------------
  71. // CEmbedContent constructor
  72. //----------------------------------------------------------------------------------------
  73.  
  74. CEmbedContent::CEmbedContent(Environment* ev, CEmbedPart* part)
  75. :    FW_CEmbeddingContent(ev, part),
  76.     fEmbedPart(part),
  77.     fProxy(NULL)
  78. {
  79. }
  80.  
  81. //----------------------------------------------------------------------------------------
  82. //    CEmbedContent destructor
  83. //----------------------------------------------------------------------------------------
  84.  
  85. CEmbedContent::~CEmbedContent()
  86. {
  87.     delete fProxy;
  88.     fProxy = NULL;
  89. }
  90.  
  91. //----------------------------------------------------------------------------------------
  92. //    CEmbedContent::Externalize
  93. //----------------------------------------------------------------------------------------
  94.  
  95. void CEmbedContent::ExternalizeKind(Environment* ev,
  96.                                  ODStorageUnit* storageUnit,
  97.                                  FW_CKind* kind,
  98.                                  FW_StorageKinds storageKind,
  99.                                  FW_CPromise* promise,
  100.                                  FW_CCloneInfo* cloneInfo)
  101. {
  102. FW_UNUSED(storageKind);
  103. FW_UNUSED(promise);
  104.  
  105.     FW_ASSERT(kind->IsPartKind(ev));    // We only support one kind
  106.  
  107.     // ----- Create a stream -----
  108.     FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, kind->GetType(ev));
  109.     FW_CWritableStream stream(suSink);
  110.     
  111.     // ----- Write number of embedded parts -----
  112.     unsigned long count = (fProxy ? 1 : 0);
  113.     stream << count;
  114.     
  115.     // ----- Write embedded part -----
  116.     if (fProxy)
  117.         fProxy->Externalize(ev, suSink->GetStorageUnitView(ev), cloneInfo);
  118.     
  119.     // ----- Delete whatever follows -----
  120.     FW_SUDeleteEndOfFocusedValue(ev, storageUnit);
  121. }
  122.  
  123. //----------------------------------------------------------------------------------------
  124. //    CEmbedContent::InternalizeKind
  125. //----------------------------------------------------------------------------------------
  126.  
  127. FW_Boolean CEmbedContent::InternalizeKind(Environment* ev,
  128.                                        ODStorageUnit* storageUnit, 
  129.                                        FW_CKind* kind,
  130.                                        FW_StorageKinds storageKind,
  131.                                        FW_CCloneInfo* cloneInfo)
  132. {
  133. FW_UNUSED(storageKind);
  134.     FW_ASSERT(kind->IsPartKind(ev));    // We only support one kind
  135.  
  136.     // ----- Create a stream -----
  137.     FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, kind->GetType(ev));
  138.     FW_PBufferedSink sink(ev, suSink);
  139.     FW_CReadableStream stream(sink);
  140.     
  141.     // ----- Read number of embedded parts -----
  142.     unsigned long count;
  143.     stream >> count;
  144.     
  145.     // ----- Read embedded part, if any -----
  146.     if (count == 1)
  147.     {
  148.         fProxy = new CEmbedProxy(ev, fEmbedPart);
  149.         fProxy->Internalize(ev, suSink->GetStorageUnitView(ev), cloneInfo);
  150.     }    
  151.  
  152.     return true;
  153. }
  154.  
  155. //----------------------------------------------------------------------------------------
  156. //    CEmbedContent::SingleEmbeddedFrameInternalized
  157. //----------------------------------------------------------------------------------------
  158.  
  159. void CEmbedContent::SingleEmbeddedFrameInternalized(Environment* ev,
  160.                                                     FW_CEmbeddingFrame* scopeFrame,
  161.                                                     ODPart* odEmbeddedPart, 
  162.                                                     ODFrame* odEmbeddedFrame,
  163.                                                     ODShape* suggestedShape,
  164.                                                     ODTypeToken viewType)
  165. {
  166. FW_UNUSED(suggestedShape);
  167.     // ----- Detach existing proxy, if any -----
  168.     if (fProxy)
  169.     {
  170.         fProxy->SetSelectState(ev, false);
  171.         fProxy->DetachEmbeddedFrames(ev);
  172.     }
  173.  
  174.     // ----- Calculate the frame shape -----
  175.     FW_CAcquiredODShape aqFrameShape = ((CEmbedFrame*)scopeFrame)->CreateFrameShape(ev);
  176.         
  177.     // ----- Create the proxy -----
  178.     CEmbedProxy* newProxy = new CEmbedProxy(ev, fEmbedPart);
  179.     
  180.     // ----- Embed the Part/Frame -----
  181.     newProxy->Embed(ev, 
  182.                     scopeFrame->GetPresentation(ev),
  183.                     odEmbeddedPart, 
  184.                     odEmbeddedFrame,
  185.                     kODFrameObject,
  186.                     aqFrameShape, 
  187.                     viewType, 
  188.                     NULL,        // no presentation
  189.                       0,            // group id
  190.                       FALSE,        // is overlaid
  191.                       false);        // sub-frame?
  192.  
  193.     // ----- Set the proxy  -----
  194.     fProxy = newProxy;
  195. }
  196.  
  197. //----------------------------------------------------------------------------------------
  198. //    CEmbedContent::IsDataOnlyOneProxy
  199. //----------------------------------------------------------------------------------------
  200.  
  201. FW_MProxy* CEmbedContent::IsDataOnlyOneProxy(Environment* ev) const
  202. {
  203. FW_UNUSED(ev);
  204.     return fProxy;
  205. }
  206.