home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 14.3 KB | 496 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPartng.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWPARTNG_H
- #include "FWPartng.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRSTNG_H
- #include "FWPrstng.h"
- #endif
-
- #ifndef FWPRTITE_H
- #include "FWPrtIte.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWFRMING_H
- #include "FWFrming.h"
- #endif
-
- #ifndef FWPXYFRM_H
- #include "FWPxyFrm.h"
- #endif
-
- #ifndef FWLNKMGR_H
- #include "FWLnkMgr.h"
- #endif
-
- #ifndef FWCMD_H
- #include "FWCmd.h"
- #endif
-
- #ifndef FWPROXY_H
- #include "FWProxy.h"
- #endif
-
- #ifndef FWPRMISE_H
- #include "FWPrmise.h"
- #endif
-
- #ifndef FWITEXT_H
- #include "FWIText.h"
- #endif
-
- #ifndef FWMNUBAR_H
- #include "FWMnuBar.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- #ifndef FWCLNINF_H
- #include "FWClnInf.h"
- #endif
-
- // ----- OpenDoc Utilites -----
-
- #ifndef _INFOUTIL_
- #include "InfoUtil.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODStorageUnitView_xh
- #include <SUView.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Foci_defined
- #include <Foci.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODClipboard_xh
- #include <Clipbd.xh>
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifdef FW_BUILD_WIN
-
- #include <plfmdef.h>
- #include <t_regist.h>
-
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fw_embedding
- #endif
-
- FW_DEFINE_CLASS_M1(FW_CEmbeddingPart, FW_CPart)
-
- //========================================================================================
- // class FW_CEmbeddingPart
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingPart::FW_CEmbeddingPart
- //----------------------------------------------------------------------------------------
-
- FW_CEmbeddingPart::FW_CEmbeddingPart(ODPart* odPart,
- ODValueType partKind,
- ODValueType partUserName,
- FW_Instance partInstance,
- FW_ResourceId iconID) :
- FW_CPart(odPart, partKind, partUserName, partInstance, iconID),
- fProxyFrames(NULL)
- #ifdef FW_BUILD_WIN
- ,fWinEmbedMenu(NULL)
- #endif
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingPart::~FW_CEmbeddingPart
- //----------------------------------------------------------------------------------------
-
- FW_CEmbeddingPart::~FW_CEmbeddingPart()
- {
- delete fProxyFrames;
- fProxyFrames = NULL;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CEmbeddingPart::Initialize
- //---------------------------------------------------------------------------------------
- // Call inherited first when overriding
-
- void FW_CEmbeddingPart::Initialize(Environment *ev)
- {
- FW_CPart::Initialize(ev);
-
- // ----- Proxy Frame collection -----
- fProxyFrames = new FW_CPrivOrderedCollection;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CEmbeddingPart::LinkStatusChanged
- //---------------------------------------------------------------------------------------
-
- void FW_CEmbeddingPart::LinkStatusChanged(Environment *ev, ODFrame* odFrame)
- {
- // The following code is default behavior for parts that don't create links.
-
- FW_CEmbeddingFrame* frame = FW_CEmbeddingFrame::ODtoFWEmbeddingFrame(ev, odFrame);
- if (frame)
- {
- ODLinkStatus linkStatus = odFrame->GetLinkStatus(ev);
-
- // You only need to propagate linkStatus to embedded frames that don't participate in
- // any of this part's links; otherwise their local link status takes precedence.
-
- FW_CPartEmbeddedFrameIterator iter(ev, this);
- for (ODFrame* odEmbeddedFrame = iter.First(ev); iter.IsNotComplete(ev); odEmbeddedFrame = iter.Next(ev))
- odEmbeddedFrame->ChangeLinkStatus(ev, linkStatus);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingPart::ReleaseAll
- //----------------------------------------------------------------------------------------
- // Call inherited first when overrided
-
- void FW_CEmbeddingPart::ReleaseAll(Environment *ev)
- {
- FW_CPart::ReleaseAll(ev);
-
- // ----- Delete Proxy Frames collection -----
- if (fProxyFrames)
- {
- FW_CProxyFrame* proxyFrame;
- while ((proxyFrame = (FW_CProxyFrame*)fProxyFrames->First()) != NULL)
- {
- PrivRemoveProxyFrame(ev, proxyFrame);
- }
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CEmbeddingPart::Purge
- //---------------------------------------------------------------------------------------
-
- ODSize FW_CEmbeddingPart::Purge(Environment *ev, ODSize size)
- {
- ODSize odSize = FW_CPart::Purge(ev, size);
-
- // ----- Purge embedded frames -----
- if (IsSupportingFramePaging(ev))
- {
- FW_CPartProxyFrameIterator ite(this);
- for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
- {
- odSize += proxyFrame->Purge(ev);
- }
- }
-
- return odSize;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CEmbeddingPart::Dragging
- //---------------------------------------------------------------------------------------
-
- void FW_CEmbeddingPart::Dragging(Environment *ev, FW_CFrame* frame, FW_Boolean state)
- {
- FW_CPartProxyFrameIterator ite(this);
- for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
- {
- if (proxyFrame->IsFrameInMemory(ev) && proxyFrame->GetContainingFrame(ev) == frame)
- {
- if (proxyFrame->HasASelectedFacet(ev))
- proxyFrame->GetFrame(ev)->SetDragging(ev, state);
- }
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CEmbeddingPart::GetProxy
- //---------------------------------------------------------------------------------------
-
- FW_MProxy* FW_CEmbeddingPart::GetProxy(Environment* ev, ODFrame* embeddedFrame) const
- {
- FW_ASSERT(embeddedFrame != NULL);
-
- ODID embeddedFrameID = embeddedFrame->GetID(ev);
-
- FW_CPartProxyFrameIterator ite(this);
- for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
- {
- if (proxyFrame->GetFrameID(ev) == embeddedFrameID)
- return proxyFrame->GetProxy(ev);
- }
-
- return NULL;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CEmbeddingPart::PrivAddProxyFrame
- //---------------------------------------------------------------------------------------
-
- void FW_CEmbeddingPart::PrivAddProxyFrame(Environment* ev, FW_CProxyFrame* proxyFrame)
- {
- fProxyFrames->AddLast(proxyFrame);
- proxyFrame->Acquire();
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CEmbeddingPart::PrivRemoveProxyFrame
- //---------------------------------------------------------------------------------------
-
- long FW_CEmbeddingPart::PrivRemoveProxyFrame(Environment* ev, FW_CProxyFrame* proxyFrame)
- {
- fProxyFrames->Remove(proxyFrame);
- return proxyFrame->Release();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingPart::PrivAcquireProxyFrame
- //----------------------------------------------------------------------------------------
-
- FW_CProxyFrame* FW_CEmbeddingPart::PrivAcquireProxyFrame(Environment* ev, ODStorageUnitID frameID) const
- {
- return FW_CProxyFrame::PrivAcquireProxyFrame(ev, fProxyFrames, frameID);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CEmbeddingPart::CloneInto
- //---------------------------------------------------------------------------------------
-
- void FW_CEmbeddingPart::PrivCloneInto(Environment *ev,
- ODDraftKey key,
- ODStorageUnit* toSU,
- ODFrame* scope)
- {
- ODStorageUnit* su = GetStorageUnit(ev);
- ODDraft* fromDraft = su->GetDraft(ev);
-
- FW_ASSERT((scope == NULL) || (scope != NULL && IsValidDisplayFrame(ev, scope->GetID(ev))));
-
- FW_CFrame *frame = scope == NULL ? NULL : FW_CFrame::ODtoFWFrame(ev, scope);
- FW_ASSERT((scope == NULL) || (scope != NULL && frame != NULL));
-
- FW_CCloneInfo cloneInfo(ev, key, fromDraft, frame, 0); // fromDraft->GetCloneKind(ev)
-
- // ----- clone the proxy frames -----
- PrivExternalizeProxyFrames(ev, toSU, &cloneInfo);
-
- // ----- Externalize the content -----
- ExternalizeContent(ev, toSU, &cloneInfo);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CEmbeddingPart::PrivInternalizeProxyFrames
- //---------------------------------------------------------------------------------------
-
- void FW_CEmbeddingPart::PrivInternalizeProxyFrames(Environment *ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
- {
- if (!FW_SUExistsThenFocus(ev, storageUnit, FW_kPropEmbeddedFrames, kODStrongStorageUnitRefs))
- return;
-
- FW_CAcquireODStorageUnitView suView(ev, storageUnit);
-
- unsigned long offsetLimit = suView->GetSize(ev);
-
- while (suView->GetOffset(ev) < offsetLimit)
- {
- FW_CAcquiredProxyFrame aqProxyFrame = new FW_CProxyFrame(ev, this);
-
- if (!aqProxyFrame->InternalizeProxyFrame(ev, suView, cloneInfo))
- {
- long refCount = this->PrivRemoveProxyFrame(ev, aqProxyFrame); // should delete the proxy
- FW_ASSERT(refCount == 0);
- }
- }
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CEmbeddingPart::PrivExternalizeProxyFrames
- //---------------------------------------------------------------------------------------
-
- void FW_CEmbeddingPart::PrivExternalizeProxyFrames(Environment *ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
- {
- if (fProxyFrames->Count() == 0)
- {
- FW_SURemoveProperty(ev, storageUnit, FW_kPropEmbeddedFrames); // FW_SURemoveProperty test first that the property exist
- return;
- }
-
- // ----- force the creation of the FW_kPropEmbeddedFrames property
- FW_SUForceFocus(ev, storageUnit, FW_kPropEmbeddedFrames, kODStrongStorageUnitRefs);
-
- // ----- Create a storage unit view -----
- FW_CAcquireODStorageUnitView suView(ev, storageUnit);
-
- // ----- Save previous value -----
- unsigned long oldValueSize = suView->GetSize(ev);
-
- // ----- Set offset to zero -----
- suView->SetOffset(ev, 0);
-
- // ----- Externalize Each proxy frame -----
- FW_COrderedCollectionIterator ite(fProxyFrames);
- for (FW_CProxyFrame* proxyFrame = (FW_CProxyFrame*)ite.First(); ite.IsNotComplete(); proxyFrame = (FW_CProxyFrame*)ite.Next())
- {
- proxyFrame->ExternalizeProxyFrame(ev, suView, cloneInfo);
- }
-
- // ----- Get the current position -----
- unsigned long offset = suView->GetOffset(ev);
-
- // ----- remove what's left -----
- if (oldValueSize > offset)
- suView->DeleteValue(ev, oldValueSize - offset);
-
- FW_ASSERT(suView->GetSize(ev) == offset);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingPart::NewPresentation
- //----------------------------------------------------------------------------------------
-
- FW_CPresentation* FW_CEmbeddingPart::NewPresentation(Environment *ev,
- FW_CSelection* selection,
- ODTypeToken presentationType)
- {
- return new FW_CEmbeddingPresentation(ev, this, (FW_CEmbeddingSelection*)selection, presentationType);
- }
-
- #ifdef FW_BUILD_WIN
- //------------------------------------------------------------------------------
- // FW_CEmbeddingPart::WinAddEmbedMenu
- //------------------------------------------------------------------------------
-
- void FW_CEmbeddingPart::WinAddEmbedMenu(Environment *ev, FW_CMenuBar *menuBar)
- {
- ODPartRegistryIterator iter;
- ODPartRegistryData data;
- char partString[50];
- LPSTR partPtr, tmpPtr;
-
- unsigned short partCount = -1; //TAG - this will increment the 1st time to 0 to
- // exclude the omnipresent IDM_DRAW part...
-
- unsigned short stringIndex = 0; // This indexes into part type string buffer.
- fWinFirstPartID = FW_kFirstUserCommandID + 0x8000;
-
- fWinEmbedMenu = new FW_CPullDownMenu(ev, FW_CString32("Embed"));
-
- for (iter.First(kODTrue,&data);iter.IsNotComplete();iter.Next(&data))
- {
- partCount++;
-
- // Keep the last word of the partKind
- FW_PrimitiveStringCopy(data.partKind, partPtr=partString);
- tmpPtr = partPtr;
- while (tmpPtr != NULL)
- {
- tmpPtr = FW_PrimitiveStringFindCharacter(partPtr, ':');
- if (tmpPtr != NULL)
- partPtr = ++tmpPtr;
- }
-
- FW_CString255 name(partPtr);
- fWinEmbedMenu->AppendTextItem(ev, name, fWinFirstPartID + partCount);
-
- fTypePtr[partCount] = &(fTypeString[stringIndex]);
- FW_PrimitiveStringCopy(data.partKind, fTypePtr[partCount]);
- stringIndex += FW_PrimitiveStringLength(fTypePtr[partCount]) + 1;
- }
- fWinLastPartID = fWinFirstPartID + partCount;
-
- menuBar->AdoptMenuLast(ev, fWinEmbedMenu);
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingPart::WinCreateEmbeddedPartFromCommand
- //----------------------------------------------------------------------------------------
-
- ODPart* FW_CEmbeddingPart::WinCreateEmbeddedPartFromCommand(Environment* ev, ODCommandID commandID)
- {
- if ((commandID >= fWinFirstPartID) && (commandID <= fWinLastPartID))
- {
- ODStorageUnit* su = this->GetStorageUnit(ev);
- return su->GetDraft(ev)->CreatePart(ev, fTypePtr[commandID - fWinFirstPartID], NULL);
- }
-
- return NULL;
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // FW_CEmbeddingPart::WinEnableEmbedMenu
- //----------------------------------------------------------------------------------------
-
- void FW_CEmbeddingPart::WinEnableEmbedMenu(Environment* ev, FW_CMenuBar* menuBar)
- {
- if (fWinEmbedMenu != NULL && fWinEmbedMenu->GetMenuBar(ev) == menuBar)
- {
- fWinEmbedMenu->EnableAll(ev);
- }
- }
- #endif
-
-
-