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 / ODF / Framewrk / FWPart / Sources / FWIntrng.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  16.8 KB  |  508 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWIntrng.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWINTRNG_H
  13. #include "FWIntrng.h"
  14. #endif
  15.  
  16. #ifndef FWPROXY_H
  17. #include "FWProxy.h"
  18. #endif
  19.  
  20. #ifndef FWPRESEN_H
  21. #include "FWPresen.h"
  22. #endif
  23.  
  24. #ifndef FWFRMING_H
  25. #include "FWFrming.h"
  26. #endif
  27.  
  28. #ifndef FWPXYFRM_H
  29. #include "FWPxyFrm.h"
  30. #endif
  31.  
  32. #ifndef FWUTIL_H
  33. #include "FWUtil.h"
  34. #endif
  35.  
  36. #ifndef FWCLNINF_H
  37. #include "FWClnInf.h"
  38. #endif
  39.  
  40. #ifndef FWCONTNG_H
  41. #include "FWContng.h"
  42. #endif
  43.  
  44. // ----- OS Includes -----
  45.  
  46. #ifndef FWBARRAY_H
  47. #include "FWBArray.h"
  48. #endif
  49.  
  50. #ifndef FWODGEOM_H
  51. #include "FWODGeom.h"
  52. #endif
  53.  
  54. // ----- OD Utils -----
  55.  
  56. #ifndef _EDITRSET_
  57. #include "EditrSet.h"
  58. #endif
  59.  
  60. #ifndef _BNDNSUTL_
  61. #include "BndNSUtl.h"
  62. #endif
  63.  
  64. #ifndef _STDTYPIO_
  65. #include "StdTypIO.h"
  66. #endif
  67.  
  68. // ----- OpenDoc Includes -----
  69.  
  70. #ifndef SOM_Module_OpenDoc_StdProps_defined
  71. #include <StdProps.xh>
  72. #endif
  73.  
  74. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  75. #include <StdTypes.xh>
  76. #endif
  77.  
  78. #ifndef SOM_ODSession_xh
  79. #include <ODSessn.xh>
  80. #endif
  81.  
  82. #ifndef SOM_ODWindowState_xh
  83. #include "WinStat.xh"
  84. #endif
  85.  
  86. #ifndef SOM_ODContainer_xh
  87. #include "ODCtr.xh"
  88. #endif
  89.  
  90. //========================================================================================
  91. // RunTime Info
  92. //========================================================================================
  93.  
  94. #ifdef FW_BUILD_MAC
  95. #pragma segment fw_embedding2
  96. #endif
  97.  
  98. //========================================================================================
  99. //    class FW_CEmbeddingDataInterchange
  100. //========================================================================================
  101.  
  102. //----------------------------------------------------------------------------------------
  103. //    FW_CEmbeddingDataInterchange constructor
  104. //----------------------------------------------------------------------------------------
  105. FW_CEmbeddingDataInterchange::FW_CEmbeddingDataInterchange(Environment* ev, FW_CEmbeddingPart* part) :
  106.     FW_CDataInterchange(ev, part)
  107. {
  108. }
  109.  
  110. //----------------------------------------------------------------------------------------
  111. //    FW_CEmbeddingDataInterchange destructor
  112. //----------------------------------------------------------------------------------------
  113. FW_CEmbeddingDataInterchange::~FW_CEmbeddingDataInterchange()
  114. {
  115. }
  116.  
  117. //----------------------------------------------------------------------------------------
  118. //    FW_CEmbeddingDataInterchange::DoExternalizeSingleEmbeddedFrame
  119. //----------------------------------------------------------------------------------------
  120.  
  121. void FW_CEmbeddingDataInterchange::DoExternalizeSingleEmbeddedFrame(Environment* ev, 
  122.                                         ODFrame* odEmbeddedFrame, 
  123.                                         ODStorageUnit* destinationSU, 
  124.                                         FW_CCloneInfo* cloneInfo)
  125. {            
  126.     destinationSU->AddProperty(ev, kODPropContentFrame);
  127.     destinationSU->AddValue(ev, kODWeakStorageUnitRef);
  128.         
  129.     // Add the cloneKind property and value
  130.     destinationSU->AddProperty(ev, kODPropCloneKindUsed)->AddValue(ev, kODCloneKind);
  131.     ODCloneKind cloneKind = cloneInfo->GetCloneKind(ev);
  132.     FW_CByteArray byteArray(&cloneKind, sizeof(ODCloneKind));
  133.     destinationSU->SetValue(ev, byteArray);
  134.         
  135.     //    Clone the embedded part into the root storage unit.
  136.     FW_CAcquiredODPart aqPart = odEmbeddedFrame->AcquirePart(ev);
  137.     ODID toRootID = cloneInfo->Clone(ev, aqPart->GetID(ev), destinationSU->GetID(ev), odEmbeddedFrame->GetID(ev));
  138.         
  139.     // Clone the embedded frame to any storage unit. Must be done
  140.     // after cloning the part because it strongly references the part
  141.     ODID toFrameID = cloneInfo->Clone(ev, odEmbeddedFrame->GetID(ev), 0, odEmbeddedFrame->GetID(ev));
  142.         
  143.     //    Weakly reference the frame
  144.     destinationSU->Focus(ev, kODPropContentFrame, kODPosUndefined, kODWeakStorageUnitRef, 0, kODPosUndefined);
  145.     ODStorageUnitRef aSURef;
  146.     destinationSU->GetWeakStorageUnitRef(ev, toFrameID, aSURef);
  147.     byteArray.Set(&aSURef, sizeof(ODStorageUnitRef));
  148.     destinationSU->SetValue(ev, byteArray);
  149. }
  150.  
  151. //----------------------------------------------------------------------------------------
  152. //    FW_CEmbeddingDataInterchange::DoInternalizeSingleEmbeddedFrame
  153. //----------------------------------------------------------------------------------------
  154.  
  155. FW_EInternalizeResult FW_CEmbeddingDataInterchange::DoInternalizeSingleEmbeddedFrame(Environment* ev, 
  156.                                                                              ODStorageUnit* sourceSU,
  157.                                                                              FW_CCloneInfo* cloneInfo)
  158. {
  159.     FW_EInternalizeResult result = FW_kInternalizeFailed;
  160.     
  161.     ODDraft* myDraft = fPart->GetDraft(ev);
  162.     
  163.     cloneInfo->fClonedPartID = cloneInfo->Clone(ev, sourceSU->GetID(ev), 0, 0);
  164.     FW_ASSERT(cloneInfo->fClonedPartID != kODNULLID);
  165.     
  166.     result = FW_kInternalizePart;
  167.  
  168.     // ----- Try Cloning the frame -----
  169.     ODStorageUnitRef aSURef;
  170.     sourceSU->Focus(ev, kODPropContentFrame, kODPosUndefined, kODWeakStorageUnitRef, 0, kODPosUndefined);
  171.     
  172.     FW_CByteArray byteArray; 
  173.     sourceSU->GetValue(ev, sizeof(aSURef), byteArray);
  174.     byteArray.CopyBuffer( &aSURef, sizeof(aSURef));
  175.  
  176.     if (sourceSU->IsValidStorageUnitRef(ev, aSURef))
  177.     {
  178.         ODID sourceFrameID = sourceSU->GetIDFromStorageUnitRef(ev, aSURef);
  179.         cloneInfo->fClonedFrameID = cloneInfo->Clone(ev, sourceFrameID, 0, 0);
  180.         FW_ASSERT(cloneInfo->fClonedFrameID != kODNULLID);
  181.         
  182.         result = FW_kInternalizeFrame;
  183.     }
  184.     
  185.     return result;
  186. }
  187.  
  188. //----------------------------------------------------------------------------------------
  189. //    FW_CEmbeddingDataInterchange::PrivHandleExternalizeData
  190. //----------------------------------------------------------------------------------------
  191. //    Here we have two cases: 
  192. //        1) The data consists of only one embedded part(frame). In this case
  193. //            we just want to clone it into the storage unit.
  194. //        2) The data is two or more embedded parts or one or more
  195. //            embedded parts plus content. In this case we externalize the data.
  196.  
  197. void FW_CEmbeddingDataInterchange::PrivHandleExternalizeData(Environment* ev, 
  198.                                                             FW_CContent* content,
  199.                                                             ODStorageUnit* destinationSU,
  200.                                                             FW_EStorageKinds storageKind, 
  201.                                                             FW_CCloneInfo* cloneInfo)
  202. {
  203.     FW_ASSERT(cloneInfo->GetScopeFrame(ev));
  204.     
  205.     FW_MProxy* singleProxy = content ? ((FW_CEmbeddingContent*)content)->IsDataOnlyOneProxy(ev) : NULL;
  206.     if (singleProxy)        // if the data is only one embedded frame clone it into the SU 
  207.     {
  208.         FW_CEmbeddingFrame* embeddingFrame = FW_DYNAMIC_CAST(FW_CEmbeddingFrame, cloneInfo->GetScopeFrame(ev));
  209.         FW_ASSERT(embeddingFrame);
  210.  
  211.         FW_CAcquiredODFrame aqEmbeddedFrame = singleProxy->AcquireEmbeddedFrame(ev, embeddingFrame);    
  212.         FW_ASSERT(aqEmbeddedFrame != NULL);
  213.         
  214.         DoExternalizeSingleEmbeddedFrame(ev, aqEmbeddedFrame, destinationSU, cloneInfo);        
  215.     
  216.     }
  217.     else
  218.     {
  219.         FW_CDataInterchange::PrivHandleExternalizeData(ev, content, destinationSU, storageKind, cloneInfo);
  220.     }
  221. }
  222.  
  223. //----------------------------------------------------------------------------------------
  224. //    FW_CEmbeddingDataInterchange::PrivHandleInternalizeData
  225. //----------------------------------------------------------------------------------------
  226.  
  227. FW_EInternalizeResult FW_CEmbeddingDataInterchange::PrivHandleInternalizeData(Environment* ev, 
  228.                                                                              FW_CContent* content,
  229.                                                                             ODStorageUnit* sourceSU,
  230.                                                                             FW_EStorageKinds storageKind, 
  231.                                                                             FW_CCloneInfo* cloneInfo)
  232. {
  233.     FW_EInternalizeResult result = FW_kInternalizeFailed;
  234.     
  235.     // ----- Test first if the data consists of a single embedded frame
  236.     if (sourceSU->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0))
  237.     {
  238.         result = DoInternalizeSingleEmbeddedFrame(ev, sourceSU, cloneInfo);
  239.     }
  240.     else
  241.     {
  242.         // ----- Try to incorporate -----
  243.         result = FW_CDataInterchange::PrivHandleInternalizeData(ev, content, sourceSU, storageKind, cloneInfo);
  244.  
  245.         // ----- Then try embedding -----
  246.         if (result == FW_kInternalizeFailed)
  247.             result = PrivClonePart(ev, sourceSU, cloneInfo);
  248.     }
  249.     
  250.     return result;
  251. }
  252.  
  253. //----------------------------------------------------------------------------------------
  254. //    FW_CEmbeddingDataInterchange::PrivPostInternalizeData
  255. //----------------------------------------------------------------------------------------
  256.  
  257. void FW_CEmbeddingDataInterchange::PrivPostInternalizeData(Environment* ev, 
  258.                                                             FW_CContent* content,
  259.                                                                FW_CCloneInfo* cloneInfo, 
  260.                                                                FW_EInternalizeResult result)
  261. {
  262.     switch (result)
  263.     {
  264.         case FW_kInternalizeFailed:
  265.             FW_DEBUG_MESSAGE("PrivPostInternalizeData should not have been called");
  266.             break;
  267.             
  268.         case FW_kInternalizeContent:
  269.             if (cloneInfo->fClonedProxyList != NULL)    // No embedded frames have been read
  270.                 PrivPostInternalizeContent(ev, cloneInfo);
  271.             break;
  272.             
  273.         case FW_kInternalizePart:
  274.             PrivPostInternalizePart(ev, (FW_CEmbeddingContent*)content, cloneInfo, GetPresentation(ev, cloneInfo)->GetDefaultEmbeddedFrameViewType(ev));
  275.             break;
  276.             
  277.         case FW_kInternalizeFrame:
  278.             PrivPostInternalizeFrame(ev, (FW_CEmbeddingContent*)content, cloneInfo, GetPresentation(ev, cloneInfo)->GetDefaultEmbeddedFrameViewType(ev));
  279.             break;
  280.     }
  281. }
  282.  
  283. //----------------------------------------------------------------------------------------
  284. //    FW_CEmbeddingDataInterchange::PrivReadFrameShape
  285. //----------------------------------------------------------------------------------------
  286.  
  287. ODShape* FW_CEmbeddingDataInterchange::PrivReadFrameShape(Environment* ev, ODStorageUnit* sourceSU)
  288. {
  289.     // ----- Look for a frame shape property -----
  290.     ODShape* frameShape = NULL;
  291.     
  292.     if (sourceSU->Exists(ev, kODPropFrameShape, (ODValueType)NULL, 0))
  293.     {
  294.         // ----- Note: we focus on the property, ReadShape will focus on the value
  295.         sourceSU->Focus(ev, kODPropFrameShape, 
  296.                             kODPosUndefined, 
  297.                                (ODValueType)NULL, 
  298.                             (ODValueIndex)1, 
  299.                             kODPosUndefined);
  300.         
  301.         frameShape = ::FW_NewODShape(ev);
  302.         frameShape = frameShape->ReadShape(ev, sourceSU);
  303.     }
  304.     
  305.     return frameShape;
  306. }
  307.  
  308. //----------------------------------------------------------------------------------------
  309. //    FW_CEmbeddingDataInterchange::PrivPostInternalizeContent
  310. //----------------------------------------------------------------------------------------
  311.  
  312. void FW_CEmbeddingDataInterchange::PrivPostInternalizeContent(Environment* ev, FW_CCloneInfo* cloneInfo)
  313. {
  314.     FW_TOrderedCollectionIterator<FW_MProxy> ite(cloneInfo->fClonedProxyList);
  315.     for (FW_MProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  316.     {
  317.         proxy->PrivPostClone(ev, cloneInfo);
  318.     }
  319. }
  320.  
  321. //----------------------------------------------------------------------------------------
  322. //    FW_CEmbeddingDataInterchange::PrivPostInternalizeFrame
  323. //----------------------------------------------------------------------------------------
  324.  
  325. void FW_CEmbeddingDataInterchange::PrivPostInternalizeFrame(Environment* ev,
  326.                                                             FW_CEmbeddingContent* content, 
  327.                                                             FW_CCloneInfo* cloneInfo,
  328.                                                             ODTypeToken viewAs)
  329. {
  330.     FW_ASSERT(cloneInfo->fClonedPartID != kODNULLID);
  331.     FW_ASSERT(cloneInfo->fClonedFrameID != kODNULLID);
  332.  
  333.     FW_CEmbeddingFrame* embeddingScopeFrame = FW_DYNAMIC_CAST(FW_CEmbeddingFrame, cloneInfo->GetScopeFrame(ev));
  334.     FW_ASSERT(embeddingScopeFrame);
  335.  
  336.     // ----- Get the part -----
  337. //    ODDraft* myDraft = fPart->GetDraft(ev);
  338. //    FW_CAcquiredODPart aqNewPart = myDraft->AcquirePart(ev, cloneInfo->fClonedPartID);
  339.     ODDraft* toDraft = cloneInfo->GetToDraft(ev);
  340.     FW_CAcquiredODPart aqNewPart = toDraft->AcquirePart(ev, cloneInfo->fClonedPartID);
  341.     FW_ASSERT(aqNewPart != NULL);
  342.         
  343.     FW_TRY
  344.     {
  345. //        FW_CAcquiredODFrame aqNewFrame = myDraft->AcquireFrame(ev, cloneInfo->fClonedFrameID);
  346.         FW_CAcquiredODFrame aqNewFrame = toDraft->AcquireFrame(ev, cloneInfo->fClonedFrameID);
  347.         FW_ASSERT(aqNewFrame != NULL);
  348.  
  349.         aqNewFrame->SetContainingFrame(ev, embeddingScopeFrame->GetODFrame(ev));
  350.         
  351.         FW_CAcquiredODShape aqFrameShape = aqNewFrame->AcquireFrameShape(ev, NULL);
  352.  
  353.         content->SingleEmbeddedFrameInternalized(ev, 
  354.                                                  embeddingScopeFrame,
  355.                                                  aqNewPart, 
  356.                                                  aqNewFrame, 
  357.                                                  aqFrameShape,
  358.                                                  viewAs);
  359.     }
  360.     FW_CATCH_BEGIN
  361.     FW_CATCH_EVERYTHING()
  362.     {
  363.         FW_THROW_SAME();
  364.     }
  365.     FW_CATCH_END
  366. }
  367.  
  368. //----------------------------------------------------------------------------------------
  369. //    FW_CEmbeddingDataInterchange::PrivPostInternalizePart
  370. //----------------------------------------------------------------------------------------
  371.  
  372. void FW_CEmbeddingDataInterchange::PrivPostInternalizePart(Environment* ev, 
  373.                                                         FW_CEmbeddingContent* content,
  374.                                                         FW_CCloneInfo* cloneInfo,
  375.                                                            ODTypeToken viewAs)
  376. {
  377.     FW_ASSERT(cloneInfo->fClonedPartID != kODNULLID);
  378.     FW_ASSERT(cloneInfo->fClonedFrameID == kODNULLID);
  379.     
  380. //    ODDraft* myDraft = fPart->GetDraft(ev);
  381. //    FW_CAcquiredODPart aqEmbeddedPart = myDraft->AcquirePart(ev, cloneInfo->fClonedPartID);
  382.     FW_CAcquiredODPart aqEmbeddedPart = cloneInfo->GetToDraft(ev)->AcquirePart(ev, cloneInfo->fClonedPartID);
  383.     
  384.     FW_CEmbeddingFrame* embeddingScopeFrame = FW_DYNAMIC_CAST(FW_CEmbeddingFrame, cloneInfo->GetScopeFrame(ev));
  385.     FW_ASSERT(embeddingScopeFrame);
  386.     
  387.     content->SingleEmbeddedFrameInternalized(ev, 
  388.                                             embeddingScopeFrame,
  389.                                             aqEmbeddedPart, 
  390.                                             NULL, 
  391.                                             cloneInfo->fFrameShape,
  392.                                             viewAs);
  393. }
  394.  
  395. //----------------------------------------------------------------------------------------
  396. //    FW_CEmbeddingDataInterchange::PrivClonePart
  397. //----------------------------------------------------------------------------------------
  398.  
  399. FW_EInternalizeResult FW_CEmbeddingDataInterchange::PrivClonePart(Environment* ev, 
  400.                                                                  ODStorageUnit* sourceSU,
  401.                                                                   FW_CCloneInfo* cloneInfo)
  402. {
  403.     FW_EInternalizeResult result = FW_kInternalizeFailed;
  404.  
  405.     // ----- Clone the part -----            
  406.     cloneInfo->fClonedPartID = cloneInfo->Clone(ev, sourceSU->GetID(ev), 0, 0);
  407.     FW_ASSERT(cloneInfo->fClonedPartID != kODNULLID);
  408.     result = FW_kInternalizePart;
  409.     
  410.     // ----- Look for the frame shape -----    
  411.     cloneInfo->fFrameShape = PrivReadFrameShape(ev, sourceSU);
  412.  
  413.     return result;
  414. }
  415.  
  416. //----------------------------------------------------------------------------------------
  417. //    FW_CEmbeddingDataInterchange::PrivHandleEmbedAs
  418. //----------------------------------------------------------------------------------------
  419.  
  420. FW_EInternalizeResult FW_CEmbeddingDataInterchange::PrivHandleEmbedAs(Environment* ev, 
  421.                                                                       FW_CContent* content,
  422.                                                                       ODStorageUnit* sourceSU,
  423.                                                                       FW_CCloneInfo* cloneInfo,
  424.                                                                       ODPasteAsResult* embedAsInfo)
  425. {
  426.     ODDraft* dstDraft = fPart->GetDraft(ev);
  427.     FW_EInternalizeResult result = FW_kInternalizeFailed;
  428.  
  429.     cloneInfo->BeginClone(ev, dstDraft);
  430.  
  431.     result = PrivClonePart(ev, sourceSU, cloneInfo);
  432.     
  433.     if (result == FW_kInternalizeFailed) 
  434.     {
  435.         cloneInfo->AbortClone(ev);
  436.         return result;
  437.     }
  438.     
  439.     cloneInfo->EndClone(ev);
  440.  
  441.     result = PrivPostEmbedAs(ev, content, sourceSU, cloneInfo, embedAsInfo);
  442.     
  443.     return result;
  444. }
  445.  
  446. //----------------------------------------------------------------------------------------
  447. //    FW_CEmbeddingDataInterchange::PrivPostEmbedAs
  448. //----------------------------------------------------------------------------------------
  449. FW_EInternalizeResult FW_CEmbeddingDataInterchange::PrivPostEmbedAs(Environment* ev,
  450.                                                                     FW_CContent* content,
  451.                                                                     ODStorageUnit* sourceSU,
  452.                                                                     FW_CCloneInfo* cloneInfo,
  453.                                                                     ODPasteAsResult* embedAsInfo)
  454. {
  455. FW_UNUSED(sourceSU);
  456.     ODStorageUnit* newSU = NULL;
  457.     FW_VOLATILE(newSU);
  458.  
  459.     FW_TRY
  460.     {
  461.         // ----- Acquire the newly embedded storage unit
  462.         ODDraft* dstDraft = fPart->GetDraft(ev);
  463.         newSU = dstDraft->AcquireStorageUnit(ev, cloneInfo->fClonedPartID);
  464.  
  465.         /*-- If user wants translation, do it before the part gets embedded --*/
  466.         if (embedAsInfo->translateKind != NULL)
  467.         {
  468.             ODTranslateResult transResult = fPart->TranslateData(ev, newSU, 
  469.                                                                 embedAsInfo->selectedKind, 
  470.                                                                 embedAsInfo->translateKind);
  471.             FW_ASSERT(transResult != kODCannotTranslate);
  472.     
  473.             //-- Translation was successful, save the preferred kind in the cloned SU
  474.             ODSetISOStrProp(ev, newSU, kODPropPreferredKind, kODISOStr, embedAsInfo->selectedKind);
  475.         }
  476.  
  477.         //-- Save the preferred editor in the cloned SU
  478.         if (embedAsInfo->editor != kODNoEditor)
  479.         {
  480.             ODSetISOStrProp(ev, newSU, kODPropPreferredEditor, kODEditor, embedAsInfo->editor);
  481.         }
  482.  
  483.         //-- Complete embedding of the part
  484.         this->PrivPostInternalizePart(ev, (FW_CEmbeddingContent*)content, cloneInfo, embedAsInfo->selectedView);
  485.  
  486.         newSU->Release(ev);
  487.     }
  488.     FW_CATCH_BEGIN
  489.     FW_CATCH_EVERYTHING()
  490.     {
  491.         if (newSU)
  492.             newSU->Release(ev);
  493.         FW_THROW_SAME();
  494.     }
  495.     FW_CATCH_END
  496.  
  497.     return FW_kInternalizePart;
  498. }
  499.  
  500. //----------------------------------------------------------------------------------------
  501. //    FW_CEmbeddingDataInterchange::GetPresentation
  502. //----------------------------------------------------------------------------------------
  503.  
  504. FW_CPresentation* FW_CEmbeddingDataInterchange::GetPresentation(Environment* ev, FW_CCloneInfo* cloneInfo)
  505. {
  506.     return cloneInfo->GetScopeFrame(ev)->GetPresentation(ev);
  507. }
  508.