home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWLnkSrc.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  9.2 KB  |  326 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWLnkSrc.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 FWLNKSRC_H
  13. #include "FWLnkSrc.h"
  14. #endif
  15.  
  16. // ----- Framework Includes -----
  17.  
  18. #ifndef FWPART_H
  19. #include "FWPart.h"
  20. #endif
  21.  
  22. #ifndef FWPRESEN_H
  23. #include "FWPresen.h"
  24. #endif
  25.  
  26. #ifndef FWLNKITE_H
  27. #include "FWLnkIte.h"
  28. #endif
  29.  
  30. #ifndef FWCLNINF_H
  31. #include "FWClnInf.h"
  32. #endif
  33.  
  34. #ifndef FWINTER_H
  35. #include "FWInter.h"
  36. #endif
  37.  
  38. #ifndef FWPRMISE_H
  39. #include "FWPrmise.h"
  40. #endif
  41.  
  42. // ----- Foundation Includes -----
  43.  
  44. #ifndef FWPRIDEB_H
  45. #include "FWPriDeb.h"
  46. #endif
  47.  
  48. #ifndef FWBARRAY_H
  49. #include "FWBArray.h"
  50. #endif
  51.  
  52. // ----- OpenDoc Includes -----
  53.  
  54. #ifndef SOM_Module_OpenDoc_StdProps_defined
  55. #include <StdProps.xh>
  56. #endif
  57.  
  58. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  59. #include <StdTypes.xh>
  60. #endif
  61.  
  62. #ifndef SOM_ODStorageUnit_xh
  63. #include <StorageU.xh>
  64. #endif
  65.  
  66. #ifndef SOM_ODSession_xh
  67. #include <ODSessn.xh>
  68. #endif
  69.  
  70. #ifndef SOM_ODLinkSpec_xh
  71. #include <LinkSpec.xh>
  72. #endif
  73.  
  74. #ifndef SOM_ODLinkSource_xh
  75. #include <LinkSrc.xh>
  76. #endif
  77.  
  78. //========================================================================================
  79. //    Runtime information
  80. //========================================================================================
  81.  
  82. #ifdef FW_BUILD_MAC
  83. #pragma segment odflinking
  84. #endif
  85.  
  86. //========================================================================================
  87. //    Template Instantiations
  88. //========================================================================================
  89.  
  90. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CLinkSource)
  91. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_CLinkSource)
  92.  
  93. #ifdef FW_USE_TEMPLATE_PRAGMAS
  94.  
  95. #pragma template_access public
  96. #pragma template FW_TOrderedCollection<FW_CLinkSource>
  97. #pragma template FW_TOrderedCollectionIterator<FW_CLinkSource>
  98.  
  99. #endif
  100.  
  101. //========================================================================================
  102. //    class FW_CLinkSource
  103. //========================================================================================
  104.  
  105. //---------------------------------------------------------------------------------------
  106. //    FW_CLinkSource::FW_CLinkSource
  107. //---------------------------------------------------------------------------------------
  108.  
  109. FW_CLinkSource::FW_CLinkSource(Environment* ev, 
  110.                                ODUpdateID updateID,
  111.                                FW_CPresentation* presentation)
  112. :    FW_CLink(ev, presentation),
  113.     fODLinkSource(NULL),
  114.     fUpdateID(updateID),
  115.     fPendingID(updateID),
  116.     fDataInterchange(presentation->GetPart(ev)->GetDataInterchange(ev)),
  117.     fPromise(NULL)            
  118. {
  119. }
  120.  
  121. //---------------------------------------------------------------------------------------
  122. //    FW_CLinkSource::~FW_CLinkSource
  123. //---------------------------------------------------------------------------------------
  124.  
  125. FW_CLinkSource::~FW_CLinkSource()
  126. {
  127.     if (fODLinkSource)
  128.     {
  129.         FW_SOMEnvironment ev;
  130.         fODLinkSource->Release(ev);
  131.     }
  132. }
  133.  
  134. //---------------------------------------------------------------------------------------
  135. //    FW_CLinkSource::SetODLinkSource
  136. //---------------------------------------------------------------------------------------
  137.  
  138. void FW_CLinkSource::SetODLinkSource(Environment* ev, ODLinkSource* odLinkSource)
  139. {
  140.     FW_ASSERT(odLinkSource!=NULL);
  141.     FW_ASSERT(fODLinkSource==NULL);
  142.     
  143.     fODLinkSource = odLinkSource;
  144.     odLinkSource->Acquire(ev);
  145. }
  146.  
  147. //---------------------------------------------------------------------------------------
  148. //    FW_CLinkSource::PrivSetPromise
  149. //---------------------------------------------------------------------------------------
  150.  
  151. void FW_CLinkSource::PrivSetPromise(Environment* ev, FW_CPromise* promise)
  152. {
  153. FW_UNUSED(ev);
  154.     if (fPromise != NULL)
  155.         delete fPromise;
  156.     
  157.     fPromise = promise;
  158. }
  159.  
  160. //---------------------------------------------------------------------------------------
  161. //    FW_CLinkSource::ContentUpdated
  162. //---------------------------------------------------------------------------------------
  163.  
  164. void FW_CLinkSource::ContentUpdated(Environment* ev, ODUpdateID updateID,
  165.                                     FW_Boolean forceUpdate)
  166. {
  167.     fUpdateID = updateID ? updateID : fPresentation->GetPart(ev)->GetSession(ev)->UniqueUpdateID(ev);
  168.  
  169.     // Don't update unless we really have to
  170.     if (this->IsOKtoUpdate(ev, forceUpdate))
  171.     {
  172.         ODLinkKey key;
  173.         FW_VOLATILE(key);
  174.  
  175.         if (fODLinkSource->Lock(ev, 0, &key)) 
  176.         {
  177.             FW_TRY
  178.             {
  179.                 fDataInterchange->PrivDeleteLinkPromises(ev, this);
  180.                 FW_ASSERT(fPromise == NULL);    // We should not have any promises left
  181.                 
  182.                 fODLinkSource->Clear(ev, fUpdateID, key);
  183.                 // Clear must be followed by GetContentStorageUnit, which writes out a new set of promises
  184.                 ODStorageUnit* linkSU = fODLinkSource->GetContentStorageUnit(ev, key);
  185.  
  186.                 ExternalizeLinkContent(ev, linkSU);
  187.  
  188.                 if (updateID != kODUnknownUpdate)
  189.                     fODLinkSource->ContentUpdated(ev, fUpdateID, key);
  190.             }
  191.             FW_CATCH_BEGIN
  192.             FW_CATCH_EVERYTHING()
  193.             {
  194.                 fODLinkSource->Unlock(ev, key);    
  195.                 FW_THROW_SAME();
  196.             }
  197.             FW_CATCH_END
  198.     
  199.             fODLinkSource->Unlock(ev, key);    
  200.         }
  201.     }
  202. }
  203.  
  204. //---------------------------------------------------------------------------------------
  205. //    FW_CLinkSource::ResolveAllPromises
  206. //----------------------------------------------------------------------------------------
  207. // [HLX] Might not be completely right ????
  208.  
  209. void FW_CLinkSource::ResolveAllPromises(Environment* ev)
  210. {
  211.     ODLinkKey key;
  212.     FW_VOLATILE(key);
  213.  
  214.     if (fODLinkSource->Lock(ev, 0, &key)) 
  215.     {
  216.         FW_TRY
  217.         {
  218.             ODStorageUnit* linkSU = fODLinkSource->GetContentStorageUnit(ev, key);
  219.             linkSU->ResolveAllPromises(ev);
  220.         }
  221.         FW_CATCH_BEGIN
  222.         FW_CATCH_EVERYTHING()
  223.         {
  224.             fODLinkSource->Unlock(ev, key);    
  225.             FW_THROW_SAME();
  226.         }
  227.         FW_CATCH_END
  228.  
  229.         fODLinkSource->Unlock(ev, key);    
  230.     }
  231. }
  232.  
  233. //---------------------------------------------------------------------------------------
  234. //    FW_CLinkSource::HasEmbeddedFrame
  235. //----------------------------------------------------------------------------------------
  236. FW_Boolean FW_CLinkSource::HasEmbeddedFrame(Environment* ev, ODFrame* odEmbeddedFrame)
  237. {
  238. FW_UNUSED(ev);
  239. FW_UNUSED(odEmbeddedFrame); 
  240.  
  241.     // Should be overridden if the part supports embedding.
  242.     // Return TRUE if odEmbeddedFrame is involved in this link source.
  243.  
  244.     return FALSE;
  245. }
  246.  
  247. //---------------------------------------------------------------------------------------
  248. //    FW_CLinkSource::IsOKtoUpdate
  249. //----------------------------------------------------------------------------------------
  250. FW_Boolean FW_CLinkSource::IsOKtoUpdate(Environment* ev, FW_Boolean forceUpdate)
  251. {
  252.     return (forceUpdate || fODLinkSource->IsAutoUpdate(ev));
  253. }
  254.  
  255. //---------------------------------------------------------------------------------------
  256. //    FW_CLinkSource::BreakLink
  257. //----------------------------------------------------------------------------------------
  258. void FW_CLinkSource::BreakLink(Environment* ev)
  259. {
  260.     fODLinkSource->SetSourcePart(ev, (ODStorageUnit*) kODNULL);
  261.     fUpdateID = kODUnknownUpdate;
  262. }
  263.  
  264. //---------------------------------------------------------------------------------------
  265. //    FW_CLinkSource::RestoreLink
  266. //----------------------------------------------------------------------------------------
  267. void FW_CLinkSource::RestoreLink(Environment* ev, FW_CPart* part)
  268. {
  269.     fODLinkSource->SetSourcePart(ev, part->GetStorageUnit(ev));
  270. }
  271.  
  272. //---------------------------------------------------------------------------------------
  273. //    FW_CLinkSource::ExternalizeLink
  274. //----------------------------------------------------------------------------------------
  275. void FW_CLinkSource::ExternalizeLink(Environment* ev, ODStorageUnit* storageUnit,
  276.                                       FW_CCloneInfo* cloneInfo)
  277. {
  278.     //-- Storage unit must be focused to property kODPropContents, value linkSourceFormat
  279.     ODStorageUnitRef suRef;
  280.     fODLinkSource->Externalize(ev);
  281.  
  282.     ODID linkID = fODLinkSource->GetID(ev);
  283.     if (cloneInfo != NULL)
  284.     {
  285.         linkID = cloneInfo->Clone(ev, linkID, 0, 0);
  286.         // May not have been able to clone the link
  287.         if (!cloneInfo->GetFromDraft(ev)->IsValidID(ev, linkID))
  288.             return;
  289.     }
  290.  
  291.     //--- Write the link version number ---
  292.     long version = FW_kLinkVersionNumber;
  293.     FW_CByteArray byteArray(&version, sizeof(long));
  294.     storageUnit->SetValue(ev, byteArray);
  295.  
  296.     //--- Write a reference to the link ---
  297.     storageUnit->GetStrongStorageUnitRef(ev, linkID, suRef);
  298.     byteArray.Set(&suRef, sizeof(ODStorageUnitRef));
  299.     storageUnit->SetValue(ev, byteArray);
  300.  
  301.     //--- Write the update ID ---
  302.     byteArray.Set(&fUpdateID, sizeof(ODUpdateID));
  303.     storageUnit->SetValue(ev, byteArray);
  304.  
  305.     //-- Write out data specific to this part's link --
  306.     this->DoExternalizeLink(ev, storageUnit, cloneInfo);
  307. }
  308.  
  309. //---------------------------------------------------------------------------------------
  310. //    FW_CLinkSource::PrivLinkEstablished
  311. //---------------------------------------------------------------------------------------
  312. void FW_CLinkSource::PrivLinkEstablished(Environment* ev)
  313. {
  314.     FW_ASSERT(fODLinkSource != NULL);
  315.     FW_CPart* part = fPresentation->GetPart(ev);
  316.     fODLinkSource->SetSourcePart(ev, part->GetODPart(ev)->GetStorageUnit(ev));
  317.  
  318.     //---- Change the link status of affected embedded frames (part-specific)
  319.     this->LinkEstablished(ev);
  320.  
  321.     //--- Force the first update using a new change ID
  322.     ODUpdateID change = part->GetSession(ev)->UniqueUpdateID(ev);
  323.     this->ContentUpdated(ev, change, TRUE);    
  324. }
  325.  
  326.