home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-25 | 20.1 KB | 667 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Content.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Container.hpp"
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef SELECT_H
- #include "Select.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWFCTCLP_H
- #include "FWFctClp.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- #ifndef FWMEMORY_H
- #include "FWMemory.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfcontainer
- #endif
-
- FW_DEFINE_AUTO(CBaseContent)
- FW_DEFINE_AUTO(CPartContent)
- FW_DEFINE_AUTO(CSelectionContent)
- FW_DEFINE_AUTO(CUndoContent)
- FW_DEFINE_AUTO(CContentProxyIterator)
-
- //========================================================================================
- // class CBaseContent
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CBaseContent::CBaseContent
- //----------------------------------------------------------------------------------------
- // CBaseContent constructor
-
- CBaseContent::CBaseContent(Environment* ev, CContainerPart* part) :
- FW_CEmbeddingContent(ev, part),
- fProxyList(NULL),
- fContainerPart(part)
- {
- fProxyList = FW_NEW(CProxyCollection, ());
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CBaseContent::CBaseContent
- //----------------------------------------------------------------------------------------
-
- CBaseContent::CBaseContent(Environment* ev, CBaseContent* other) :
- FW_CEmbeddingContent(ev, other->fContainerPart),
- fProxyList(NULL),
- fContainerPart(other->fContainerPart)
- {
- fProxyList = FW_NEW(CProxyCollection, ());
-
- CContentProxyIterator ite(other);
- for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
- {
- this->AddProxy(ev, proxy);
- }
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CBaseContent::~CBaseContent
- //----------------------------------------------------------------------------------------
- // CBaseContent destructor
-
- CBaseContent::~CBaseContent()
- {
- FW_START_DESTRUCTOR
- delete fProxyList;
- }
-
- //----------------------------------------------------------------------------------------
- // CBaseContent::AddProxy
- //----------------------------------------------------------------------------------------
-
- void CBaseContent::AddProxy(Environment* ev, CProxy* proxy)
- {
- fProxyList->AddLast(proxy);
- }
-
- //----------------------------------------------------------------------------------------
- // CBaseContent::RemoveProxy
- //----------------------------------------------------------------------------------------
-
- void CBaseContent::RemoveProxy(Environment* ev, CProxy* proxy)
- {
- fProxyList->Remove(proxy);
- }
-
- //----------------------------------------------------------------------------------------
- // CBaseContent::CountProxies
- //----------------------------------------------------------------------------------------
-
- unsigned long CBaseContent::CountProxies() const
- {
- return fProxyList->Count();
- }
-
- //----------------------------------------------------------------------------------------
- // CBaseContent::GetFirstProxy
- //----------------------------------------------------------------------------------------
-
- CProxy* CBaseContent::GetFirstProxy() const
- {
- return fProxyList->First();
- }
-
- //----------------------------------------------------------------------------------------
- // CBaseContent::IsEmpty
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CBaseContent::IsEmpty() const
- {
- return (fProxyList->Count() == 0);
- }
-
- //----------------------------------------------------------------------------------------
- // CBaseContent::CalcUpdateShape
- //----------------------------------------------------------------------------------------
-
- ODShape* CBaseContent::CalcUpdateShape(Environment* ev)
- {
- if (this->IsEmpty())
- return NULL;
-
- ODShape* updateShape = ::FW_NewODShape(ev);
-
- FW_CAcquiredODShape aqTempShape = ::FW_NewODShape(ev);
- FW_Boolean first = TRUE;
-
- CContentProxyIterator ite(this);
- for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
- {
- proxy->GetUpdateBox(ev, aqTempShape);
- if (first)
- updateShape->CopyFrom(ev, aqTempShape);
- else
- updateShape->Union(ev, aqTempShape);
-
- first = FALSE;
- }
-
- return updateShape;
- }
-
- //----------------------------------------------------------------------------------------
- // CBaseContent::RedrawProxies
- //----------------------------------------------------------------------------------------
-
- void CBaseContent::RedrawProxies(Environment* ev)
- {
- // Calculate the update shape and invalidate it
- FW_CAcquiredODShape updateShape = CalcUpdateShape(ev);
- if (updateShape != NULL)
- {
- // Invalidate the update shape
- FW_CPresentation* presentation = fContainerPart->GetMainPresentation();
- FW_CFacetClipper facetClipper(ev, fContainerPart);
- facetClipper.Clip(ev, presentation, updateShape);
- presentation->Invalidate(ev, updateShape);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CBaseContent::PostInternalizeProxy
- //----------------------------------------------------------------------------------------
-
- void CBaseContent::PostInternalizeProxy(Environment* ev, const FW_CPoint& offset, CProxy* /*proxy*/)
- {
- // Default is to do nothing
- }
-
- //----------------------------------------------------------------------------------------
- // CBaseContent::ExternalizeProxyList
- //----------------------------------------------------------------------------------------
-
- void CBaseContent::ExternalizeProxyList(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_CCloneInfo* cloneInfo,
- FW_Fixed offsetX,
- FW_Fixed offsetY)
- {
- // ----- Create an archive for our proxies -----
- FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, fContainerPart->GetPartKind(ev));
- FW_CWritableStream archive(suSink);
-
- // ----- Write number of proxies -----
- unsigned long count = fProxyList->Count();
- archive << count;
-
- // ----- Write top, left offsets -----
- archive << offsetX;
- archive << offsetY;
-
- // ----- Write proxies -----
- CProxyCollectionIterator ite(fProxyList);
- FW_CRect frameRect;
- for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
- {
- FW_CRect bounds = proxy->GetBounds(ev);
- archive << bounds;
- proxy->Externalize(ev, suSink->GetStorageUnitView(ev), cloneInfo);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CBaseContent::InternalizeProxyList
- //----------------------------------------------------------------------------------------
-
- void CBaseContent::InternalizeProxyList(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_CCloneInfo* cloneInfo)
- {
- // ----- Create an archive for our proxies -----
- FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, fContainerPart->GetPartKind(ev));
- FW_CReadableStream archive(suSink);
-
- // ----- Read number of proxies -----
- unsigned long count;
- archive >> count;
-
- // ----- Read top left offset -----
- FW_CPoint offset;
- archive >> offset.x;
- archive >> offset.y;
-
- FW_CRect frameRect;
- CProxy* proxy;
- for (short i = 0; i<count; i++)
- {
- archive >> frameRect;
- proxy = new CProxy(ev, frameRect, fContainerPart);
- proxy->Internalize(ev, suSink->GetStorageUnitView(ev), cloneInfo);
-
- // ----- Add the proxy to the proxy list -----
- this->AddProxy(ev, proxy);
-
- // ----- Do whatever else needs to be done to the proxy -----
- this->PostInternalizeProxy(ev, offset, proxy);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CBaseContent::IsDataOnlyOneProxy
- //----------------------------------------------------------------------------------------
-
- FW_MProxy* CBaseContent::IsDataOnlyOneProxy(Environment* ev) const
- {
- if (CountProxies() == 1)
- {
- return (CProxy*)GetFirstProxy();
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CBaseContent::AddSingleEmbeddedFrame
- //----------------------------------------------------------------------------------------
-
- CProxy* CBaseContent::AddSingleEmbeddedFrame(Environment* ev,
- FW_CEmbeddingFrame* scopeFrame,
- ODPart* embeddedPart,
- ODFrame* embeddedFrame,
- ODShape* suggestedShape,
- ODTypeToken viewType)
- {
- // ----- Calculate the default proxy rect -----
- FW_CRect proxyRect;
- if (suggestedShape)
- {
- proxyRect = FW_GetShapeBoundingBox(ev, suggestedShape);
- proxyRect.Offset(-proxyRect.left, -proxyRect.top);
- }
- else
- {
- proxyRect.SetInt(0, 0, 80, 80);
- }
-
- // ----- Calculate the shape of the embedded frame -----
- FW_CAcquiredODShape aqFrameShape = ::FW_NewODShape(ev, proxyRect);
-
- // ----- Calculate the position of the embedded frame -----
- // ----- We place it in the middle of the content view -----
- FW_CRect frameBounds = scopeFrame->GetContentView(ev)->GetBoundsInContent(ev);
- proxyRect.PlaceInCenter(frameBounds);
-
- // ----- Create the proxy -----
- CProxy* proxy = new CProxy(ev, proxyRect, fContainerPart);
-
- // Make sure that if an exception occurs before we complete this method,
- // we dispose of the proxy
- FW_TRY
- {
- scopeFrame->GetPresentation(ev)->Embed(ev,
- embeddedPart,
- embeddedFrame,
- kODFrameObject, // I want persistent frames
- proxy,
- aqFrameShape,
- viewType,
- NULL, // no presentation
- 0, // group id
- FALSE, // IsOverlaid
- FALSE); // sub-frame
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING () {
- // cleanup in case the Embed failed
- delete proxy;
- FW_THROW_SAME ();
- }
- FW_CATCH_END
-
- // ----- Add the proxy to our list -----
- this->AddProxy(ev, proxy);
-
- return proxy;
- }
-
- //========================================================================================
- // class CContentProxyIterator
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CContentProxyIterator::CContentProxyIterator
- //----------------------------------------------------------------------------------------
-
- CContentProxyIterator::CContentProxyIterator(CBaseContent* content) :
- CProxyCollectionIterator(content->fProxyList)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CContentProxyIterator::~CContentProxyIterator
- //----------------------------------------------------------------------------------------
-
- CContentProxyIterator::~CContentProxyIterator()
- {
- FW_START_DESTRUCTOR
- }
-
- //========================================================================================
- // class CPartContent
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CPartContent::CPartContent
- //----------------------------------------------------------------------------------------
- // CPartContent constructor
-
- CPartContent::CPartContent(Environment* ev, CContainerPart* part)
- : CBaseContent(ev, part)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CPartContent::~CPartContent
- //----------------------------------------------------------------------------------------
- // CPartContent destructor
-
- CPartContent::~CPartContent()
- {
- if (fProxyList)
- {
- CProxy* proxy;
- while ((proxy = fProxyList->First()) != NULL)
- {
- fProxyList->Remove(proxy);
- delete proxy;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CPartContent::Externalize
- //----------------------------------------------------------------------------------------
-
- void CPartContent::Externalize (Environment* ev,
- ODStorageUnit* storageUnit,
- FW_EStorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- ExternalizeProxyList(ev, storageUnit, cloneInfo, FW_kFixed0, FW_kFixed0);
- }
-
- //----------------------------------------------------------------------------------------
- // CPartContent::Internalize
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CPartContent::Internalize(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_EStorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- InternalizeProxyList(ev, storageUnit, cloneInfo);
- return true;
- }
-
- //----------------------------------------------------------------------------------------
- // CPartContent::PostInternalizeProxy
- //----------------------------------------------------------------------------------------
-
- void CPartContent::PostInternalizeProxy(Environment* ev, const FW_CPoint& offset, CProxy* proxy)
- {
- proxy->OffsetProxy(ev, -offset.x, -offset.y);
- }
-
- //========================================================================================
- // class CSelectionContent
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CSelectionContent::CSelectionContent
- //----------------------------------------------------------------------------------------
- // CSelectionContent constructor
-
- CSelectionContent::CSelectionContent(Environment* ev, CContainerPart* part, CContainerSelection* selection)
- : CBaseContent(ev, part),
- fContainerSelection(selection)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CSelectionContent::~CSelectionContent
- //----------------------------------------------------------------------------------------
- // CSelectionContent destructor
-
- CSelectionContent::~CSelectionContent()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CSelectionContent::Internalize
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CSelectionContent::Internalize(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_EStorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- if (!storageUnit->Exists(ev, kODPropContents, fContainerPart->GetPartKind(ev), 0))
- return false;
-
- // ----- Read in the proxies -----
- InternalizeProxyList(ev, storageUnit, cloneInfo);
- return true;
- }
-
- //----------------------------------------------------------------------------------------
- // CSelectionContent::Externalize
- //----------------------------------------------------------------------------------------
-
- void CSelectionContent::Externalize(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_EStorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- FW_CRect selectRect;
- fContainerSelection->GetDragRect(selectRect);
-
- ExternalizeProxyList(ev, storageUnit, cloneInfo, selectRect.left, selectRect.top);
- }
-
- //----------------------------------------------------------------------------------------
- // CSelectionContent::SingleEmbeddedFrameInternalized
- //----------------------------------------------------------------------------------------
-
- void CSelectionContent::SingleEmbeddedFrameInternalized(Environment* ev,
- FW_CEmbeddingFrame* scopeFrame,
- ODPart* embeddedPart,
- ODFrame* embeddedFrame,
- ODShape* suggestedShape,
- ODTypeToken viewType)
- {
- CProxy* insertedProxy = AddSingleEmbeddedFrame(ev,
- scopeFrame,
- embeddedPart,
- embeddedFrame,
- suggestedShape,
- viewType);
- PostInternalizeProxy(ev, FW_kZeroPoint, insertedProxy);
- }
-
- //----------------------------------------------------------------------------------------
- // CSelectionContent::PostInternalizeProxy
- //----------------------------------------------------------------------------------------
-
- void CSelectionContent::PostInternalizeProxy(Environment* ev, const FW_CPoint& offset, CProxy* proxy)
- {
- // ----- Add the proxy to the right places -----
- fContainerPart->AddProxyToPart(ev, proxy); // Add to the part data
-
- // ----- Proxy has already been added to the selection list (fProxyList)
- fContainerSelection->ProxyAdded(ev, proxy);
- }
-
- //----------------------------------------------------------------------------------------
- // CSelectionContent::CreateDataFrameShape
- //----------------------------------------------------------------------------------------
-
- ODShape* CSelectionContent::CreateDataFrameShape(Environment* ev) const
- {
- FW_CRect selectionRect;
- fContainerSelection->GetDragRect(selectionRect);
- selectionRect.Place(FW_kZeroPoint);
-
- ODShape* selectionShape = ::FW_NewODShape(ev, selectionRect);
- return selectionShape;
- }
-
- //========================================================================================
- // class CUndoContent
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CUndoContent::CUndoContent
- //----------------------------------------------------------------------------------------
- // CUndoContent constructor
-
- CUndoContent::CUndoContent(Environment* ev, CContainerSelection* selection) :
- CBaseContent(ev, selection->GetSelectionContent(ev)),
- fContainerSelection(selection)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CUndoContent::~CUndoContent
- //----------------------------------------------------------------------------------------
- // CUndoContent destructor
-
- CUndoContent::~CUndoContent()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CUndoContent::RemoveProxySelection
- //----------------------------------------------------------------------------------------
-
- void CUndoContent::RemoveProxySelection(Environment* ev)
- {
- // Select the saved proxies
- fContainerSelection->SelectContent(ev, this);
-
- // Clear the selected proxies
- fContainerSelection->ClearSelection(ev);
-
- // Notify everybody
- fContainerSelection->SelectionChanged(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CUndoContent::RestoreProxySelection
- //----------------------------------------------------------------------------------------
-
- void CUndoContent::RestoreProxySelection(Environment* ev)
- {
- // Add the saved proxies back into the part
- CContentProxyIterator ite(this);
- for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
- {
- fContainerPart->AttachProxy(ev, proxy);
- }
-
- // Redraw the restored proxies
- RedrawProxies(ev);
-
- // Select the saved proxies
- fContainerSelection->SelectContent(ev, this);
-
- // Notify everybody
- fContainerSelection->SelectionChanged(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CUndoContent::DeleteSavedProxies
- //----------------------------------------------------------------------------------------
-
- void CUndoContent::DeleteSavedProxies(Environment* ev)
- {
- // ----- Delete all the saved proxies -----
- CProxy* proxy;
- while ((proxy = GetFirstProxy()) != NULL)
- {
- RemoveProxy(ev, proxy);
- delete proxy;
- }
- }
-
-