home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 15.5 KB | 516 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Content.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef PROXY_H
- #include "Proxy.h"
- #endif
-
- #ifndef SELECTION_H
- #include "Selection.h"
- #endif
-
- #ifndef LINKING_H
- #include "Linking.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWFRMING_H
- #include "FWFrming.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- //========================================================================================
- // Runtime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfTable
- #endif
-
- FW_DEFINE_AUTO(CTableContent)
- FW_DEFINE_AUTO(CTableSelectionContent)
-
- //========================================================================================
- // class CTableContent
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CTableContent::CTableContent
- //----------------------------------------------------------------------------------------
-
- CTableContent::CTableContent(Environment* ev, CTablePart* part) :
- FW_CEmbeddingContent(ev, part),
- fTablePart(part),
- fProxys(NULL)
- {
- // ----- Create list of proxies -----
- fProxys = FW_NEW(CTableProxyCollection, ());
-
- fCells.fX = kMaxCols;
- fCells.fY = kMaxRows;
-
- // ----- Initialize arrays
- unsigned long s;
- for(s=0; s < kMaxCols; s++)
- fWidth[s] = kDefaultCellWidth;
- for(s=0; s < kMaxRows; s++)
- fHeight[s] = kDefaultCellHeight;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableContent::~CTableContent
- //----------------------------------------------------------------------------------------
-
- CTableContent::~CTableContent()
- {
- // just delete all the CTableProxy
-
- if (fProxys)
- {
- CTableProxy* proxy;
- while ((proxy = (CTableProxy*)fProxys->First()) != NULL)
- {
- fProxys->Remove(proxy);
- delete proxy;
- }
- }
-
- delete fProxys;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableContent::Externalize
- //----------------------------------------------------------------------------------------
-
- void CTableContent::Externalize(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_EStorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(storageKind);
-
- // ---- Write out grid info ----
- FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, fTablePart->GetPartKind(ev));
- FW_CWritableStream archive(suSink);
-
- archive << fCells.fX;
- archive << fCells.fY;
- archive.Write(fWidth, fCells.fX);
- archive.Write(fHeight, fCells.fY);
-
- // ---- Write number of embedded parts ----
- unsigned long partCount = fProxys->Count();
- archive << partCount;
-
- // ---- Write out embedded frames ----
- if (partCount > 0)
- {
- CTableProxyCollectionIterator iter(fProxys);
- for (CTableProxy* proxy = iter.First(); iter.IsNotComplete(); proxy = iter.Next())
- {
- CCell cell = proxy->GetCell();
- archive << cell.fX;
- archive << cell.fY;
- proxy->Externalize(ev, suSink->GetStorageUnitView(ev), cloneInfo);
- }
- }
-
- //--- Write source and destination links, if any ---
- CTableLinkManager* linkMgr = (CTableLinkManager*) fTablePart->GetLinkManager(ev);
- linkMgr->ExternalizeLinks(ev, storageUnit, cloneInfo);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableContent::Internalize
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTableContent::Internalize(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_EStorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(storageKind);
-
- if (!storageUnit->Exists(ev, kODPropContents, fTablePart->GetPartKind(ev), 0))
- return false;
-
- // ---- Read grid info -----
- FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, fTablePart->GetPartKind(ev));
- FW_PBufferedSink sink(ev, suSink);
- FW_CReadableStream archive(sink);
-
- archive >> fCells.fX;
- archive >> fCells.fY;
-
- FW_ASSERT(fCells.fX == kMaxCols);
- archive.Read(fWidth, fCells.fX);
-
- FW_ASSERT(fCells.fY == kMaxRows);
- archive.Read(fHeight, fCells.fY);
-
- // ---- Read number of embedded parts ----
- unsigned long partCount;
- archive >> partCount;
-
- // ---- Read embedded parts ----
- CCell cell;
- CTableProxy* proxy;
- for (unsigned long i = 0; i < partCount; i++)
- {
- archive >> cell.fX;
- archive >> cell.fY;
- proxy = new CTableProxy(ev, fTablePart, this, fTablePart->GetTablePresentation(ev));
- proxy->SetCell(cell);
- proxy->Internalize(ev, suSink->GetStorageUnitView(ev), cloneInfo); // read part and embed it
- this->AddProxy(proxy);
- }
-
- // ----- Read link information -----
- CTableLinkManager* linkMgr = (CTableLinkManager*) fTablePart->GetLinkManager(ev);
- linkMgr->InternalizeLinks(ev, storageUnit);
-
- return true;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableContent::IsDataOnlyOneProxy
- //----------------------------------------------------------------------------------------
-
- FW_MProxy* CTableContent::IsDataOnlyOneProxy(Environment* ev) const
- {
- // This method is only called on the content object associated with the selection to
- // test for the Single Embedded Frame case. The part content should just retur NULL.
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableContent::CellToProxy
- //----------------------------------------------------------------------------------------
-
- CTableProxy* CTableContent::CellToProxy(const CCell& cell) const
- {
- // Convert a cell to a Proxy pointer by going through the
-
- CTableProxyCollectionIterator iter(fProxys);
- for (CTableProxy* proxy = iter.First(); iter.IsNotComplete(); proxy = iter.Next())
- {
- if (proxy->GetCell() == cell)
- return proxy;
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableContent::GetWidth
- //----------------------------------------------------------------------------------------
-
- FW_Fixed CTableContent::GetWidth(short c) const
- {
- return (c < fCells.fX ? fWidth[c] : kDefaultCellWidth);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableContent::GetHeight
- //----------------------------------------------------------------------------------------
-
- FW_Fixed CTableContent::GetHeight(short r) const
- {
- return (r < fCells.fY ? fHeight[r] : kDefaultCellHeight);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableContent::SetWidth
- //----------------------------------------------------------------------------------------
-
- void CTableContent::SetWidth(short c, FW_Fixed w)
- {
- FW_ASSERT(c < fCells.fX);
- fWidth[c] = w;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableContent::SetHeight
- //----------------------------------------------------------------------------------------
-
- void CTableContent::SetHeight(short r, FW_Fixed h)
- {
- FW_ASSERT(r < fCells.fY);
- fHeight[r] = h;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableContent::AddProxy
- //----------------------------------------------------------------------------------------
-
- void CTableContent::AddProxy(CTableProxy* proxy)
- {
- fProxys->AddLast(proxy);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableContent::RemoveProxy
- //----------------------------------------------------------------------------------------
-
- void CTableContent::RemoveProxy(CTableProxy* proxy)
- {
- fProxys->Remove(proxy);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableContent::FindLeft
- //----------------------------------------------------------------------------------------
-
- FW_Fixed CTableContent::FindLeft(short col) const
- {
- FW_Fixed x = kHMargin + kBorderWidth;
- for(short c = 0; c < col; c += 1)
- x += this->GetWidth(c) + kBorderWidth;
- return x;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableContent::FindTop
- //----------------------------------------------------------------------------------------
-
- FW_Fixed CTableContent::FindTop(short row) const
- {
- FW_Fixed y = kVMargin + kBorderHeight;
- for(short r = 0; r < row; r += 1)
- y += this->GetHeight(r) + kBorderWidth;
- return y;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableContent::FindRect
- //----------------------------------------------------------------------------------------
-
- void CTableContent::FindRect(const CCell& cell, FW_CRect& rect) const
- {
- FW_Fixed x = this->FindLeft(cell.fX);
- FW_Fixed y = this->FindTop (cell.fY);
-
- rect.Set(x, y,
- x + this->GetWidth(cell.fX),
- y + this->GetHeight(cell.fY));
- }
-
- //----------------------------------------------------------------------------------------
- // CTableContent::Resize
- //----------------------------------------------------------------------------------------
-
- void CTableContent::Resize(Environment* ev, const CCell& cell, ETableLoc tl, const FW_CPoint& delta)
- {
- CCell topLeftCell(cell);
-
- if (delta.x != FW_kFixed0)
- {
- if ((tl & kTLLeftBorder) != 0)
- topLeftCell.fX -= 1;
- SetWidth(topLeftCell.fX, GetWidth (topLeftCell.fX) + delta.x);
- }
-
- if (delta.y != FW_kFixed0)
- {
- if ((tl & kTLTopBorder) != 0)
- topLeftCell.fY -= 1;
- SetHeight(topLeftCell.fY, GetHeight(topLeftCell.fY) + delta.y);
- }
-
- // Move all embedded frames
- CTableProxyCollectionIterator ite(fProxys);
- for (CTableProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
- {
- // Get operations being performed
- CCell frCell = proxy->GetCell();
- FW_Boolean resizing = (frCell.fX == topLeftCell.fX || frCell.fY == topLeftCell.fY);
- FW_Boolean moving = (frCell.fX > topLeftCell.fX || frCell.fY > topLeftCell.fY);
-
- if (resizing || moving)
- proxy->MoveEmbeddedFrames(ev, frCell);
- }
-
- fTablePart->Changed(ev);
- }
-
- //========================================================================================
- // class CTableSelectionContent
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CTableSelectionContent::CTableSelectionContent
- //----------------------------------------------------------------------------------------
-
- CTableSelectionContent::CTableSelectionContent(Environment* ev, CTablePart* part, CTableContent* content) :
- FW_CEmbeddingContent(ev, part),
- fTableContent(content),
- fTablePart(part),
- fCell(0, 0)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelectionContent::~CTableSelectionContent
- //----------------------------------------------------------------------------------------
-
- CTableSelectionContent::~CTableSelectionContent()
- {
- }
-
-
- //----------------------------------------------------------------------------------------
- // IsDataOnlyOneProxy
- //----------------------------------------------------------------------------------------
-
- FW_MProxy* CTableSelectionContent::IsDataOnlyOneProxy(Environment* ev) const
- {
- return fTableContent->CellToProxy(fCell);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelectionContent::Internalize
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTableSelectionContent::Internalize(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_EStorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- // Should never be called because I always internalize a single embedded frame
- FW_UNUSED(storageUnit);
- FW_UNUSED(storageKind);
- FW_UNUSED(cloneInfo);
-
- return false;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelectionContent::Externalize
- //----------------------------------------------------------------------------------------
-
- void CTableSelectionContent::Externalize(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_EStorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(storageKind);
-
- CTableProxy* proxy = GetSelectedProxy(ev);
- if (proxy)
- {
- FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, fTablePart->GetPartKind(ev));
- proxy->Externalize(ev, suSink->GetStorageUnitView(ev), cloneInfo);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelectionContent::GetSelectedProxy
- //----------------------------------------------------------------------------------------
-
- CTableProxy* CTableSelectionContent::GetSelectedProxy(Environment* ev) const
- {
- return fTableContent->CellToProxy(fCell);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelectionContent::SingleEmbeddedFrameInternalized
- //----------------------------------------------------------------------------------------
-
- void CTableSelectionContent::SingleEmbeddedFrameInternalized(Environment* ev,
- FW_CEmbeddingFrame* scopeFrame,
- ODPart* embeddedPart,
- ODFrame* embeddedFrame,
- ODShape* suggestedShape,
- ODTypeToken viewType)
- {
- // A single embedded frame has been internalized (Drag&Drop, Clipboard or Insert).
-
- FW_UNUSED(suggestedShape);
-
- CCell selectionCell = GetCell();
-
- CTableProxy* proxy = fTableContent->CellToProxy(selectionCell);
-
- FW_CRect rect;
- fTableContent->FindRect(selectionCell, rect);
- rect.Place(FW_kZeroPoint);
-
- FW_CAcquiredODShape aqShape = ::FW_NewODShape(ev, rect);
-
- // ----- Create the proxy -----
- CTableProxy* newProxy = new CTableProxy(ev, fTablePart, fTableContent, scopeFrame->GetPresentation(ev));
- newProxy->SetCell(selectionCell);
-
- // ----- Add the newProxy to the part -----
- fTableContent->AddProxy(newProxy);
-
- // ----- Embed the part or the frame -----
- scopeFrame->GetPresentation(ev)->Embed(ev,
- embeddedPart,
- embeddedFrame,
- kODFrameObject,
- newProxy,
- aqShape,
- viewType,
- NULL, // no presentation
- 0, // group id
- false, // overlaid
- false); // sub frame
-
- // ----- Delete the old proxy if there was one in the cell
- if (proxy != NULL)
- {
- proxy->DetachEmbeddedFrames(ev);
- fTableContent->RemoveProxy(proxy);
- delete proxy;
- }
-
- // ----- Select the new proxy -----
- newProxy->Selected(TRUE);
-
- // ----- Change its hilite state
- if (scopeFrame && scopeFrame->HasSelectionFocus(ev))
- newProxy->ChangeHighlight(ev, scopeFrame->GetWindow(ev)->IsActive(ev) ? kODFullHighlight : kODDimHighlight, scopeFrame);
-
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelectionContent::CreateDataFrameShape
- //----------------------------------------------------------------------------------------
-
- ODShape* CTableSelectionContent::CreateDataFrameShape(Environment* ev) const
- {
- // return the shape used for the kODPropFrameShape property.
-
- FW_CRect rect;
- fTableContent->FindRect(GetCell(), rect);
-
- ODShape* shape = ::FW_NewODShape(ev, rect);
- return shape;
- }
-
-
-