home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-25 | 9.2 KB | 326 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWLnkSrc.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWLNKSRC_H
- #include "FWLnkSrc.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWLNKITE_H
- #include "FWLnkIte.h"
- #endif
-
- #ifndef FWCLNINF_H
- #include "FWClnInf.h"
- #endif
-
- #ifndef FWINTER_H
- #include "FWInter.h"
- #endif
-
- #ifndef FWPRMISE_H
- #include "FWPrmise.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODLinkSpec_xh
- #include <LinkSpec.xh>
- #endif
-
- #ifndef SOM_ODLinkSource_xh
- #include <LinkSrc.xh>
- #endif
-
- //========================================================================================
- // Runtime information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odflinking
- #endif
-
- //========================================================================================
- // Template Instantiations
- //========================================================================================
-
- FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CLinkSource)
- FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_CLinkSource)
-
- #ifdef FW_USE_TEMPLATE_PRAGMAS
-
- #pragma template_access public
- #pragma template FW_TOrderedCollection<FW_CLinkSource>
- #pragma template FW_TOrderedCollectionIterator<FW_CLinkSource>
-
- #endif
-
- //========================================================================================
- // class FW_CLinkSource
- //========================================================================================
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::FW_CLinkSource
- //---------------------------------------------------------------------------------------
-
- FW_CLinkSource::FW_CLinkSource(Environment* ev,
- ODUpdateID updateID,
- FW_CPresentation* presentation)
- : FW_CLink(ev, presentation),
- fODLinkSource(NULL),
- fUpdateID(updateID),
- fPendingID(updateID),
- fDataInterchange(presentation->GetPart(ev)->GetDataInterchange(ev)),
- fPromise(NULL)
- {
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::~FW_CLinkSource
- //---------------------------------------------------------------------------------------
-
- FW_CLinkSource::~FW_CLinkSource()
- {
- if (fODLinkSource)
- {
- FW_SOMEnvironment ev;
- fODLinkSource->Release(ev);
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::SetODLinkSource
- //---------------------------------------------------------------------------------------
-
- void FW_CLinkSource::SetODLinkSource(Environment* ev, ODLinkSource* odLinkSource)
- {
- FW_ASSERT(odLinkSource!=NULL);
- FW_ASSERT(fODLinkSource==NULL);
-
- fODLinkSource = odLinkSource;
- odLinkSource->Acquire(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::PrivSetPromise
- //---------------------------------------------------------------------------------------
-
- void FW_CLinkSource::PrivSetPromise(Environment* ev, FW_CPromise* promise)
- {
- FW_UNUSED(ev);
- if (fPromise != NULL)
- delete fPromise;
-
- fPromise = promise;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::ContentUpdated
- //---------------------------------------------------------------------------------------
-
- void FW_CLinkSource::ContentUpdated(Environment* ev, ODUpdateID updateID,
- FW_Boolean forceUpdate)
- {
- fUpdateID = updateID ? updateID : fPresentation->GetPart(ev)->GetSession(ev)->UniqueUpdateID(ev);
-
- // Don't update unless we really have to
- if (this->IsOKtoUpdate(ev, forceUpdate))
- {
- ODLinkKey key;
- FW_VOLATILE(key);
-
- if (fODLinkSource->Lock(ev, 0, &key))
- {
- FW_TRY
- {
- fDataInterchange->PrivDeleteLinkPromises(ev, this);
- FW_ASSERT(fPromise == NULL); // We should not have any promises left
-
- fODLinkSource->Clear(ev, fUpdateID, key);
- // Clear must be followed by GetContentStorageUnit, which writes out a new set of promises
- ODStorageUnit* linkSU = fODLinkSource->GetContentStorageUnit(ev, key);
-
- ExternalizeLinkContent(ev, linkSU);
-
- if (updateID != kODUnknownUpdate)
- fODLinkSource->ContentUpdated(ev, fUpdateID, key);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- fODLinkSource->Unlock(ev, key);
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- fODLinkSource->Unlock(ev, key);
- }
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::ResolveAllPromises
- //----------------------------------------------------------------------------------------
- // [HLX] Might not be completely right ????
-
- void FW_CLinkSource::ResolveAllPromises(Environment* ev)
- {
- ODLinkKey key;
- FW_VOLATILE(key);
-
- if (fODLinkSource->Lock(ev, 0, &key))
- {
- FW_TRY
- {
- ODStorageUnit* linkSU = fODLinkSource->GetContentStorageUnit(ev, key);
- linkSU->ResolveAllPromises(ev);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- fODLinkSource->Unlock(ev, key);
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- fODLinkSource->Unlock(ev, key);
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::HasEmbeddedFrame
- //----------------------------------------------------------------------------------------
- FW_Boolean FW_CLinkSource::HasEmbeddedFrame(Environment* ev, ODFrame* odEmbeddedFrame)
- {
- FW_UNUSED(ev);
- FW_UNUSED(odEmbeddedFrame);
-
- // Should be overridden if the part supports embedding.
- // Return TRUE if odEmbeddedFrame is involved in this link source.
-
- return FALSE;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::IsOKtoUpdate
- //----------------------------------------------------------------------------------------
- FW_Boolean FW_CLinkSource::IsOKtoUpdate(Environment* ev, FW_Boolean forceUpdate)
- {
- return (forceUpdate || fODLinkSource->IsAutoUpdate(ev));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::BreakLink
- //----------------------------------------------------------------------------------------
- void FW_CLinkSource::BreakLink(Environment* ev)
- {
- fODLinkSource->SetSourcePart(ev, (ODStorageUnit*) kODNULL);
- fUpdateID = kODUnknownUpdate;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::RestoreLink
- //----------------------------------------------------------------------------------------
- void FW_CLinkSource::RestoreLink(Environment* ev, FW_CPart* part)
- {
- fODLinkSource->SetSourcePart(ev, part->GetStorageUnit(ev));
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::ExternalizeLink
- //----------------------------------------------------------------------------------------
- void FW_CLinkSource::ExternalizeLink(Environment* ev, ODStorageUnit* storageUnit,
- FW_CCloneInfo* cloneInfo)
- {
- //-- Storage unit must be focused to property kODPropContents, value linkSourceFormat
- ODStorageUnitRef suRef;
- fODLinkSource->Externalize(ev);
-
- ODID linkID = fODLinkSource->GetID(ev);
- if (cloneInfo != NULL)
- {
- linkID = cloneInfo->Clone(ev, linkID, 0, 0);
- // May not have been able to clone the link
- if (!cloneInfo->GetFromDraft(ev)->IsValidID(ev, linkID))
- return;
- }
-
- //--- Write the link version number ---
- long version = FW_kLinkVersionNumber;
- FW_CByteArray byteArray(&version, sizeof(long));
- storageUnit->SetValue(ev, byteArray);
-
- //--- Write a reference to the link ---
- storageUnit->GetStrongStorageUnitRef(ev, linkID, suRef);
- byteArray.Set(&suRef, sizeof(ODStorageUnitRef));
- storageUnit->SetValue(ev, byteArray);
-
- //--- Write the update ID ---
- byteArray.Set(&fUpdateID, sizeof(ODUpdateID));
- storageUnit->SetValue(ev, byteArray);
-
- //-- Write out data specific to this part's link --
- this->DoExternalizeLink(ev, storageUnit, cloneInfo);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CLinkSource::PrivLinkEstablished
- //---------------------------------------------------------------------------------------
- void FW_CLinkSource::PrivLinkEstablished(Environment* ev)
- {
- FW_ASSERT(fODLinkSource != NULL);
- FW_CPart* part = fPresentation->GetPart(ev);
- fODLinkSource->SetSourcePart(ev, part->GetODPart(ev)->GetStorageUnit(ev));
-
- //---- Change the link status of affected embedded frames (part-specific)
- this->LinkEstablished(ev);
-
- //--- Force the first update using a new change ID
- ODUpdateID change = part->GetSession(ev)->UniqueUpdateID(ev);
- this->ContentUpdated(ev, change, TRUE);
- }
-
-