home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 14.8 KB | 496 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWInter.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWINTER_H
- #include "FWInter.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWPRMISE_H
- #include "FWPrmise.h"
- #endif
-
- #ifndef FWCLNINF_H
- #include "FWClnInf.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWCONTNT_H
- #include "FWContnt.h"
- #endif
-
- #ifndef FWPRMISE_H
- #include "FWPrmise.h"
- #endif
-
- #ifndef FWLNKSRC_H
- #include "FWLnkSrc.h"
- #endif
-
- #ifndef FWSESION_H
- #include "FWSesion.h"
- #endif
-
- #ifndef FWSUUTIL_H
- #include "FWSUUtil.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODClipboard_xh
- #include <Clipbd.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWFrameworkContent
- #endif
-
- //========================================================================================
- // class FW_CDataInterchange
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange constructor
- //----------------------------------------------------------------------------------------
-
- FW_CDataInterchange::FW_CDataInterchange(Environment* ev, FW_CPart* part) :
- fPart(part),
- fClipboardPromise(NULL),
- fDragAndDropPromise(NULL),
- fLinkPromise(NULL),
- fClipboardUpdateID(0)
- {
- FW_UNUSED(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange destructor
- //----------------------------------------------------------------------------------------
-
- FW_CDataInterchange::~FW_CDataInterchange()
- {
- FW_ASSERT(fClipboardPromise == NULL); // Should be NULL by now
- FW_ASSERT(fDragAndDropPromise == NULL); // Should be NULL by now
- FW_ASSERT(fLinkPromise == NULL); // Should be NULL by now
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CDataInterchange::ExternalizeData
- //---------------------------------------------------------------------------------------
- // Note: Even if I am not an embedding part I still need to call BeginClone/EndClone
- // otherwise OpenDoc's OriginalCloneKind property in the draft is not set correctly
-
- void FW_CDataInterchange::ExternalizeData(Environment* ev,
- FW_CContent* content,
- FW_CFrame* scopeFrame,
- ODStorageUnit* destinationSU,
- FW_StorageKinds storageKind,
- ODCloneKind cloneKind)
- {
- if (content == NULL)
- return;
-
- ODDraft* fromDraft = fPart->GetDraft(ev);
- ODDraft* dstDraft = destinationSU->GetDraft(ev);
-
- FW_CCloneInfo cloneInfo(ev, fromDraft, scopeFrame, cloneKind);
-
- cloneInfo.BeginClone(ev, dstDraft);
-
- PrivHandleExternalizeData(ev, content, destinationSU, storageKind, &cloneInfo);
-
- cloneInfo.EndClone(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange::PrivHandleExternalizeData
- //----------------------------------------------------------------------------------------
-
- void FW_CDataInterchange::PrivHandleExternalizeData(Environment* ev,
- FW_CContent* content,
- ODStorageUnit* destinationSU,
- FW_StorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- if (storageKind == FW_kClipboardStorage || storageKind == FW_kDragAndDropStorage)
- PrivDeletePromises(ev, storageKind);
-
- // ----- Add the needed properties first -----
- fPart->PrepContentProperty(ev, destinationSU, storageKind, FALSE);
-
- content->Externalize(ev, destinationSU, storageKind, cloneInfo);
-
- // ----- If supported, write a shape property -----
- FW_CAcquiredODShape aqSuggestedFrameShape = content->AcquireSuggestedFrameShape(ev);
- if (((ODShape*)aqSuggestedFrameShape) != NULL)
- {
- // ----- Add the property. WriteShape will add the value
- if (destinationSU->Exists(ev, kODPropSuggestedFrameShape, (ODValueType)NULL, 0))
- {
- destinationSU->Focus(ev, kODPropSuggestedFrameShape,
- kODPosUndefined,
- (ODValueType)NULL,
- (ODValueIndex)1,
- kODPosUndefined);
- destinationSU->Remove(ev); // remove the first value
- }
- else
- destinationSU->AddProperty(ev, kODPropSuggestedFrameShape);
-
- aqSuggestedFrameShape->WriteShape(ev, destinationSU);
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CDataInterchange::InternalizeData
- //---------------------------------------------------------------------------------------
- // Note: Even if I am not an embedding part I still need to call BeginClone/EndClone
- // otherwise OpenDoc's OriginalCloneKind property in the draft is not set correctly
-
- FW_EInternalizeResult FW_CDataInterchange::InternalizeData(Environment* ev,
- FW_CContent* content,
- FW_CFrame* scopeFrame,
- ODStorageUnit* sourceSU,
- FW_StorageKinds storageKind,
- ODCloneKind cloneKind,
- ODPasteAsResult* embedAsInfo)
- {
- ODDraft* fromDraft = sourceSU->GetDraft(ev);
- ODDraft* dstDraft = fPart->GetDraft(ev);
-
- FW_EInternalizeResult result = FW_kInternalizeFailed;
-
- FW_CCloneInfo cloneInfo(ev, fromDraft, scopeFrame, cloneKind);
-
- if (embedAsInfo && embedAsInfo->mergeSetting == kODFalse)
- {
- result = PrivHandleEmbedAs(ev, content, sourceSU, &cloneInfo, embedAsInfo);
- }
- else
- {
- cloneInfo.BeginClone(ev, dstDraft);
-
- result = PrivHandleInternalizeData(ev, content, sourceSU, storageKind, &cloneInfo);
-
- if (result == FW_kInternalizeFailed)
- {
- cloneInfo.AbortClone(ev);
- return result;
- }
-
- cloneInfo.EndClone(ev);
-
- PrivPostInternalizeData(ev, content, &cloneInfo, result);
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange::PrivPostInternalizeData
- //----------------------------------------------------------------------------------------
-
- void FW_CDataInterchange::PrivPostInternalizeData(Environment* ev,
- FW_CContent* content,
- FW_CCloneInfo* cloneInfo,
- FW_EInternalizeResult result)
- {
- FW_UNUSED(ev);
- FW_UNUSED(content);
- FW_UNUSED(result);
- FW_UNUSED(cloneInfo);
-
- // Nothing to do. See: FW_CEmbeddingDataInterchange::PrivPostInternalizeData
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange::PrivHandleInternalizeData
- //----------------------------------------------------------------------------------------
-
- FW_EInternalizeResult FW_CDataInterchange::PrivHandleInternalizeData(Environment* ev,
- FW_CContent* content,
- ODStorageUnit* sourceSU,
- FW_StorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
-
- FW_Boolean result = content->Internalize(ev, sourceSU, storageKind, cloneInfo);
- return result ? FW_kInternalizeContent : FW_kInternalizeFailed;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange::PrivHandleEmbedAs
- //----------------------------------------------------------------------------------------
-
- FW_EInternalizeResult FW_CDataInterchange::PrivHandleEmbedAs(Environment* ev,
- FW_CContent* content,
- ODStorageUnit* sourceSU,
- FW_CCloneInfo* cloneInfo,
- ODPasteAsResult* embedAsInfo)
- {
- FW_UNUSED(ev);
- FW_UNUSED(content);
- FW_UNUSED(sourceSU);
- FW_UNUSED(cloneInfo);
- FW_UNUSED(embedAsInfo);
-
- FW_DEBUG_MESSAGE("FW_CDataInterchange::PrivHandleEmbedAs should never be called");
- return FW_kInternalizeFailed;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange::ResolveClipboardPromise
- //----------------------------------------------------------------------------------------
-
- void FW_CDataInterchange::ResolveClipboardPromise(Environment* ev)
- {
- if (fClipboardPromise == NULL)
- return;
-
- ODClipboard* clipboard = FW_CSession::GetClipboard(ev);
- ODStorageUnit* clipboardSU = clipboard->GetContentStorageUnit(ev);
- if (clipboard->GetUpdateID(ev) == fClipboardPromise->GetUpdateID(ev))
- clipboardSU->ResolveAllPromises(ev);
- else
- PrivDeletePromises(ev, FW_kClipboardStorage);
-
- FW_ASSERT(fClipboardPromise == NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange::ResolveAllPromises
- //----------------------------------------------------------------------------------------
- // Will resolve all promises (clipboard and all link promises)
-
- void FW_CDataInterchange::ResolveAllPromises(Environment* ev)
- {
- // ----- I should never have to resolve a drag and drop promise or a link promise -----
- PrivDeletePromises(ev, FW_kDragAndDropStorage);
- PrivDeletePromises(ev, FW_kLinkStorage);
-
- // ----- resolve Clipboard promise -----
- ResolveClipboardPromise(ev);
-
- // ----- Should be NULL by now
- FW_ASSERT(fClipboardPromise == NULL);
- FW_ASSERT(fDragAndDropPromise == NULL);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CDataInterchange::PrivDeletePromises
- //---------------------------------------------------------------------------------------
-
- void FW_CDataInterchange::PrivDeletePromises(Environment* ev, FW_StorageKinds storageKind)
- {
- FW_UNUSED(ev);
- switch(storageKind)
- {
-
- case FW_kClipboardStorage:
- delete fClipboardPromise; // Will call PrivPromiseDeleted
- FW_ASSERT(fClipboardPromise == NULL);
- break;
- case FW_kDragAndDropStorage:
- delete fDragAndDropPromise; // Will call PrivPromiseDeleted
- FW_ASSERT(fDragAndDropPromise == NULL);
- break;
- case FW_kLinkStorage:
- delete fLinkPromise;
- FW_ASSERT(fLinkPromise == NULL);
- break;
-
- default:
- FW_DEBUG_MESSAGE("FW_CDataInterchange::PrivDeletePromises - Unknown storageKind");
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange::PrivPromise
- //----------------------------------------------------------------------------------------
-
- void FW_CDataInterchange::PrivPromise(Environment* ev,
- FW_CPromise* promise,
- ODStorageUnit* storageUnit,
- ODPropertyName propertyName,
- ODValueType valueType)
- {
- FW_ASSERT(propertyName != NULL);
- FW_ASSERT(valueType != NULL);
-
- storageUnit->Focus(ev, propertyName, kODPosUndefined, NULL, 0, kODPosUndefined);
-
- FW_CPromise* buffer = promise;
- FW_CByteArray bArray(&buffer, sizeof(FW_CPromise*));
- storageUnit->SetPromiseValue(ev,
- valueType,
- 0,
- bArray,
- fPart->GetODPart(ev));
-
- // ----- add the promise -----
- // Note that a promise object can be promised multiple times
-
- FW_StorageKinds storageKind = promise->GetStorageKind(ev);
-
- if (storageKind == FW_kLinkStorage)
- {
- FW_CLinkSource* linkSrc = promise->PrivGetLinkSource(ev);
- if (linkSrc != NULL)
- linkSrc->SetLinkPromise(ev, promise);
- else if (fLinkPromise != promise)
- {
- PrivDeletePromises(ev, FW_kLinkStorage);
- fLinkPromise = promise;
- }
- }
- else if (storageKind == FW_kClipboardStorage)
- {
- if (fClipboardPromise != promise)
- {
- PrivDeletePromises(ev, FW_kClipboardStorage);
- fClipboardPromise = promise;
- }
- }
- else if (storageKind == FW_kDragAndDropStorage)
- {
- if (fDragAndDropPromise != promise)
- {
- PrivDeletePromises(ev, FW_kDragAndDropStorage);
- fDragAndDropPromise = promise;
- }
- }
- else
- {
- FW_DEBUG_MESSAGE("FW_CDataInterchange::PrivPromise - Unknown storageKind");
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDataInterchange::PrivPromiseDeleted
- //----------------------------------------------------------------------------------------
- // called by the destructor of FW_CPromise
-
- void FW_CDataInterchange::PrivPromiseDeleted(Environment *ev, FW_CPromise* promise)
- {
- FW_StorageKinds storageKind = promise->GetStorageKind(ev);
-
- if (storageKind == FW_kLinkStorage)
- {
- if ( promise == fLinkPromise)
- fLinkPromise = NULL;
- else
- {
- FW_ASSERT(promise->PrivGetLinkSource(ev) != NULL);
- FW_ASSERT(promise->PrivGetLinkSource(ev)->GetLinkPromise(ev) == promise);
- }
- }
- else if (storageKind == FW_kClipboardStorage)
- {
- FW_ASSERT(fClipboardPromise == promise);
- fClipboardPromise = NULL;
- }
- else if (storageKind == FW_kDragAndDropStorage)
- {
- FW_ASSERT(fDragAndDropPromise == promise);
- fDragAndDropPromise = NULL;
- }
- else
- {
- FW_DEBUG_MESSAGE("FW_CDataInterchange::PrivPromiseDeleted - Unknown storageKind");
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CDataInterchange::TranslateData
- //---------------------------------------------------------------------------------------
-
- ODTranslateResult FW_CDataInterchange::TranslateData(Environment* ev,
- ODStorageUnit* storageUnit,
- ODType translateKind,
- ODType desiredKind)
- {
- // Translation was requested from translateKind to desiredKind
-
- //--- Add desiredKind value and create the destination storage unit view
- FW_SUForceFocus(ev, storageUnit, kODPropContents, desiredKind);
- FW_CAcquireODStorageUnitView toView(ev, storageUnit);
-
- //--- Create the source storage unit view
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, translateKind, 0, kODPosUndefined);
- FW_CAcquireODStorageUnitView fromView(ev, storageUnit);
-
- //--- Get the translation object and perform the translation
- ODTranslation* translation = FW_CSession::GetTranslation(ev);
- ODTranslateResult translateResult = translation->TranslateView(ev, fromView, toView);
-
- return translateResult;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CDataInterchange::PrivHandleFulfillPromise
- //---------------------------------------------------------------------------------------
-
- void FW_CDataInterchange::PrivHandleFulfillPromise( Environment* ev,
- FW_CPromise* promise,
- ODStorageUnitView* promiseSUView)
- {
- long count = promise->PrivHandleFulfillPromise(ev, fPart, promiseSUView);
-
- if (count == 0)
- {
- if (promise->GetStorageKind(ev) == FW_kLinkStorage)
- {
- if (promise == fLinkPromise)
- delete promise;
- else
- {
- FW_CLinkSource* linkSrc = promise->PrivGetLinkSource(ev);
- FW_ASSERT(linkSrc != NULL);
- linkSrc->SetLinkPromise(ev, NULL);
- }
- }
- else
- delete promise;
- }
- }
-
-
-