home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 29.4 KB | 893 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Linking.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef LINKING_H
- #include "Linking.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef SELECTION_H
- #include "Selection.h"
- #endif
-
- #ifndef COMMANDS_H
- #include "Commands.h"
- #endif
-
- #ifndef PROXY_H
- #include "Proxy.h"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- // for FW_CCloneInfo
- #ifndef FWPROXY_H
- #include "FWProxy.h"
- #endif
-
- // for FW_SUForceFocus
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPXYFRM_H
- #include "FWPxyFrm.h"
- #endif
-
- #ifndef FWPRTITE_H
- #include "FWPrtIte.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWCLNINF_H
- #include "FWClnInf.h"
- #endif
-
- #ifndef FWPXYITE_H
- #include "FWPxyIte.h"
- #endif
-
- #ifndef FWLNKITE_H
- #include "FWLnkIte.h"
- #endif
-
- #ifndef FWINTER_H
- #include "FWInter.h"
- #endif
-
- // ----- OS Includes -----
-
- #ifndef FWODEXCE_H
- #include "FWODExce.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.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_ODStorageUnitView_xh
- #include <SUView.xh>
- #endif
-
- #ifndef SOM_ODLink_xh
- #include <Link.xh>
- #endif
-
- #ifndef SOM_ODLinkSpec_xh
- #include <LinkSpec.xh>
- #endif
-
- #ifndef SOM_ODLinkSource_xh
- #include <LinkSrc.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- //========================================================================================
- // Constants
- //========================================================================================
-
- #define kPublishFormat "Apple:ODF:Publish:ODFTable"
- #define kSubscribeFormat "Apple:ODF:Subscribe:ODFTable"
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment opftable
- #endif
-
- //========================================================================================
- // Global Functions
- //========================================================================================
-
- ODShape* CreateLinkBorderShape(Environment* ev, CCell cell, CTableContent* content);
- void DrawLinkBorder(Environment* ev, ODShape* outline, FW_CGraphicContext& gc, FW_Boolean selected);
-
- //----------------------------------------------------------------------------------------
- // CreateLinkBorderShape
- //----------------------------------------------------------------------------------------
- ODShape* CreateLinkBorderShape(Environment* ev, CCell cell, CTableContent* content)
- {
- FW_CRect rect;
- content->FindRect(cell, rect);
- ODShape* shape = ::FW_NewODShape(ev, rect);
- return shape;
- }
-
- //----------------------------------------------------------------------------------------
- // DrawLinkBorder
- //----------------------------------------------------------------------------------------
- void DrawLinkBorder(Environment* ev, ODShape* outline, FW_CGraphicContext& gc, FW_Boolean selected)
- {
- FW_CRect box;
- outline->GetBoundingBox(ev, (ODRect*)&box);
-
- FW_CStyle horzStyle(FW_IntToFixed(FW_kLinkBorderWidth), FW_kHLinkPat);
- FW_CStyle vertStyle(FW_IntToFixed(FW_kLinkBorderWidth), FW_kVLinkPat);
- FW_CInk ink(FW_kXOr);
-
- if (selected)
- {
- horzStyle.SetPattern(FW_kSelectedHLinkPat);
- vertStyle.SetPattern(FW_kSelectedVLinkPat);
- }
-
- FW_CLineShape topLine(box.TopLeft(), box.TopRight(), ink, horzStyle);
- FW_CLineShape bottomLine(box.BotLeft(), box.BotRight(), ink, horzStyle);
- FW_CLineShape leftLine(box.TopLeft(), box.BotLeft(), ink, vertStyle);
- FW_CLineShape rightLine(box.TopRight(), box.BotRight(), ink, vertStyle);
-
- topLine.Render(gc);
- bottomLine.Render(gc);
- leftLine.Render(gc);
- rightLine.Render(gc);
- }
-
- //========================================================================================
- // class CTableLinkSource
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CTableLinkSource constructor
- //----------------------------------------------------------------------------------------
-
- CTableLinkSource::CTableLinkSource( Environment* ev, ODUpdateID changeID,
- FW_CPresentation* presentation,
- CTablePart* part,
- CTableContent* content,
- CTableSelection* selection)
- : FW_CLinkSource(ev, changeID, presentation),
- fTablePart(part),
- fPublishedContent(NULL)
- {
- fPublishedContent = FW_NEW(CTableSelectionContent, (ev, part, content));
- fPublishedContent->SetCell(selection->GetSelectedCell());
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkSource destructor
- //----------------------------------------------------------------------------------------
-
- CTableLinkSource::~CTableLinkSource()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkSource::LinkEstablished
- //----------------------------------------------------------------------------------------
-
- void CTableLinkSource::LinkEstablished(Environment* ev)
- {
- //---- Change the link status of affected embedded frames
- fTablePart->ChangeFrameStatus(ev, fPublishedContent->GetCell(), kODInLinkSource);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkSource::DoExternalizeLink
- //----------------------------------------------------------------------------------------
-
- void CTableLinkSource::DoExternalizeLink(Environment* ev, ODStorageUnit* storageUnit,
- FW_CCloneInfo* cloneInfo)
- {
- //-- Write out data specific to this part's publisher --
- CCell cell = fPublishedContent->GetCell(); // table cell associated with this publisher
- FW_CByteArray byteArray(&cell, sizeof(CCell));
- storageUnit->SetValue(ev, byteArray);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkSource::ExternalizeLinkContent
- //----------------------------------------------------------------------------------------
-
- void CTableLinkSource::ExternalizeLinkContent(Environment* ev, ODStorageUnit* linkSU)
- {
- // Remove any properties which FW_CEmbeddingSelection::DoExternalizeSingleEmbeddedFrame
- // expects to find missing.
- // ODLinkSource::Clear removed only the content property.
- FW_SURemoveProperty(ev, linkSU, kODPropContentFrame);
-
- // -- Pick a frame, any frame --
- FW_CPresentationFrameIterator piter(ev, fPresentation);
- FW_CFrame* frame = piter.First(ev);
- FW_ASSERT(frame);
-
- fDataInterchange->ExternalizeData(ev, fPublishedContent, frame, linkSU, FW_kLinkStorage, kODCloneToLink);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkSource::GetFrameToRevealLink
- //----------------------------------------------------------------------------------------
- FW_CFrame* CTableLinkSource::GetFrameToRevealLink(Environment* ev)
- {
- // By default, return the presentation's first display frame
- FW_CPresentationFrameIterator piter(ev, fPresentation);
- return piter.First(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkSource::HasEmbeddedFrame
- //---------------------------------------------------------------------------------------
- FW_Boolean CTableLinkSource::HasEmbeddedFrame(Environment* ev, ODFrame* odFrame)
- {
- // Is odFrame involved in this link source? (called by Part::EmbeddedFrameChanged)
-
- FW_Boolean result = false;
-
- // --- Find out whether odFrame is involved in any link source ---
- if (odFrame->GetLinkStatus(ev) == kODInLinkSource)
- {
- // -- Find out whether odFrame is one of my frames --
- FW_CFrame* fwFrame = FW_CFrame::ODtoFWFrame(ev, odFrame);
- if (fwFrame)
- {
- CTableProxy* proxy = fPublishedContent->GetSelectedProxy(ev);
- FW_CProxyProxyFrameIterator iter((FW_MProxy*) proxy);
- for (FW_CProxyFrame* proxyFrame = iter.First(); iter.IsNotComplete(); proxyFrame = iter.Next())
- if (proxyFrame->GetFrame(ev) == odFrame)
- {
- result = true;
- break;
- }
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkSource::DoLinkInfo
- //----------------------------------------------------------------------------------------
- CBreakLinkSourceCommand* CTableLinkSource::DoLinkInfo(Environment* ev, ODFacet* facet)
- {
- CBreakLinkSourceCommand* cmd = NULL;
- ODLinkInfoResult infoResult;
-
- if (fODLinkSource->ShowLinkSourceInfo(ev, facet, fODLinkSource->GetUpdateID(ev), true, &infoResult))
- {
- switch (infoResult.action)
- {
- case kODLinkInfoBreakLink:
- {
- // Create and return an undoable command to break the link
- FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
- cmd = FW_NEW(CBreakLinkSourceCommand, (ev, frame, this));
- }
- break;
- case kODLinkInfoUpdateNow:
- this->ContentUpdated(ev, fUpdateID, true);
- break;
- case kODLinkInfoOk:
- if (infoResult.autoUpdate != fODLinkSource->IsAutoUpdate(ev))
- {
- fODLinkSource->SetAutoUpdate(ev, infoResult.autoUpdate);
- if (infoResult.autoUpdate)
- if (fUpdateID != fODLinkSource->GetUpdateID(ev))
- // changed from manual to automatic updates, and
- // the link is out of date-- update it now
- this->ContentUpdated(ev, fODLinkSource->GetUpdateID(ev), true);
- }
- break;
- }
- }
-
- return cmd; // cmd is non-NULL if user said to break the link
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkSource::BreakLink
- //----------------------------------------------------------------------------------------
- void CTableLinkSource::BreakLink(Environment* ev)
- {
- FW_CLinkSource::BreakLink(ev);
-
- //--- Erase Link Borders ---
- fPresentation->Invalidate(ev); // force all frames to be redrawn
-
- //--- Change status of embedded frames ---
- fTablePart->ChangeFrameStatus(ev, fPublishedContent->GetCell(), kODNotInLink);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkSource::DoSelect
- //----------------------------------------------------------------------------------------
- void CTableLinkSource::DoSelect(Environment* ev, FW_CFrame* /*frame*/)
- {
- CTableSelection* selection = fTablePart->GetTableSelection(ev);
- selection->Select(ev, fPublishedContent->GetCell());
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkSource::GetCell
- //----------------------------------------------------------------------------------------
- CCell CTableLinkSource::GetCell(Environment* ev) const
- {
- return fPublishedContent->GetCell();
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkSource::SetCell
- //----------------------------------------------------------------------------------------
- void CTableLinkSource::SetCell(Environment* ev, const CCell& cell)
- {
- fPublishedContent->SetCell(cell);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkSource::DoCreateLinkBorderShape
- //----------------------------------------------------------------------------------------
- ODShape* CTableLinkSource::DoCreateLinkBorderShape(Environment* ev)
- {
- return CreateLinkBorderShape(ev, GetCell(ev), fTablePart->GetTableContent(ev));
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkSource::DoDrawLinkBorder
- //----------------------------------------------------------------------------------------
- void CTableLinkSource::DoDrawLinkBorder(Environment* ev, ODShape* outline, FW_CGraphicContext& gc)
- {
- DrawLinkBorder(ev, outline, gc, this->IsLinkSelected(ev));
- }
-
- //========================================================================================
- // class CTableLink
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CTableLink constructor
- //----------------------------------------------------------------------------------------
-
- CTableLink::CTableLink( Environment* ev,
- ODLink* odLink,
- ODLinkInfo* linkInfo,
- FW_CPresentation* presentation,
- CTablePart* part,
- CTableContent* content,
- CTableSelection* selection)
- : FW_CLinkDestination(ev, odLink, linkInfo, presentation),
- fTablePart(part),
- fLinkedContent(NULL)
- {
- //---- Create a new content object ----
- fLinkedContent = FW_NEW(CTableSelectionContent, (ev, part, content));
- fLinkedContent->SetCell(selection->GetSelectedCell());
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLink destructor
- //----------------------------------------------------------------------------------------
-
- CTableLink::~CTableLink()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLink::LinkEstablished
- //----------------------------------------------------------------------------------------
-
- void CTableLink::LinkEstablished(Environment* ev)
- {
- fTablePart->ChangeFrameStatus(ev, fLinkedContent->GetCell(), kODInLinkDestination);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLink::DoUpdateLink
- //--------------------------------------------------------------------
- FW_Boolean CTableLink::DoUpdateLink(Environment* ev, ODStorageUnit* linkContentSU, ODPasteAsResult* embedInfo)
- {
- FW_CPresentationFrameIterator piter(ev, fPresentation);
- FW_CFrame* frame = piter.First(ev);
- FW_ASSERT(frame);
-
- //-- Read data from the linkContentSU --
- FW_Boolean result = (fDataInterchange->InternalizeData(ev, fLinkedContent, frame, linkContentSU,
- FW_kLinkStorage, kODCloneFromLink, embedInfo)
- != FW_kInternalizeFailed);
- if (result)
- fPresentation->Invalidate(ev); // force all frames to be redrawn
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLink::DoLinkInfo
- //----------------------------------------------------------------------------------------
- CBreakLinkCommand* CTableLink::DoLinkInfo(Environment* ev, ODFacet* facet)
- {
- CBreakLinkCommand* cmd = NULL;
- ODLinkInfoResult infoResult;
-
- if (fODLink->ShowLinkDestinationInfo(ev, facet, &fLinkInfo, true, &infoResult))
- {
- switch (infoResult.action)
- {
- case kODLinkInfoFindSource:
- fODLink->ShowSourceContent(ev);
- break;
- case kODLinkInfoBreakLink:
- {
- // Create and return an undoable command to break the link
- FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
- cmd = FW_NEW(CBreakLinkCommand, (ev, frame, this));
- }
- break;
- case kODLinkInfoUpdateNow:
- this->LinkUpdated(ev, fODLink->GetUpdateID(ev));
- break;
- case kODLinkInfoOk:
- if (infoResult.autoUpdate != fLinkInfo.autoUpdate)
- {
- fLinkInfo.autoUpdate = infoResult.autoUpdate;
- this->Register(ev, fTablePart);
- }
- break;
- }
- }
-
- return cmd; // cmd is non-NULL if user said to break the link
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLink::BreakLink
- //----------------------------------------------------------------------------------------
- void CTableLink::BreakLink(Environment* ev)
- {
- FW_CLinkDestination::BreakLink(ev);
-
- //--- Erase Link Borders ---
- fPresentation->Invalidate(ev); // force all frames to be redrawn
-
- //--- Change status of embedded frames ---
- fTablePart->ChangeFrameStatus(ev, fLinkedContent->GetCell(), kODNotInLink);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLink::DoExternalizeLink
- //----------------------------------------------------------------------------------------
-
- void CTableLink::DoExternalizeLink(Environment* ev, ODStorageUnit* storageUnit, FW_CCloneInfo* cloneInfo)
- {
- // Write out data specific to this part's subscriber
- CCell cell = fLinkedContent->GetCell(); // table cell associated with this link
- FW_CByteArray byteArray(&cell, sizeof(CCell));
- storageUnit->SetValue(ev, byteArray);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLink::GetCell
- //----------------------------------------------------------------------------------------
- CCell CTableLink::GetCell(Environment* ev) const
- {
- return fLinkedContent->GetCell();
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLink::SetCell
- //----------------------------------------------------------------------------------------
- void CTableLink::SetCell(Environment* ev, const CCell& cell)
- {
- fLinkedContent->SetCell(cell);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLink::DoCreateLinkBorderShape
- //----------------------------------------------------------------------------------------
- ODShape* CTableLink::DoCreateLinkBorderShape(Environment* ev)
- {
- return CreateLinkBorderShape(ev, GetCell(ev), fTablePart->GetTableContent(ev));
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLink::DoDrawLinkBorder
- //----------------------------------------------------------------------------------------
- void CTableLink::DoDrawLinkBorder(Environment* ev, ODShape* outline, FW_CGraphicContext& gc)
- {
- DrawLinkBorder(ev, outline, gc, this->IsLinkSelected(ev));
- }
-
- //========================================================================================
- // class CTableLinkManager
- //========================================================================================
-
- FW_DEFINE_AUTO(CTableLinkManager)
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager constructor
- //----------------------------------------------------------------------------------------
-
- CTableLinkManager::CTableLinkManager(Environment* ev, CTablePart* thePart, CTableContent* tableContent) :
- FW_CLinkManager(ev, (FW_CPart*)thePart),
- fTablePart(thePart),
- fTableContent(tableContent)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager destructor
- //----------------------------------------------------------------------------------------
-
- CTableLinkManager::~CTableLinkManager()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::NewLinkSource
- //----------------------------------------------------------------------------------------
-
- FW_CLinkSource* CTableLinkManager::NewLinkSource(Environment* ev,
- ODUpdateID changeID,
- FW_CPresentation* presentation)
- {
- return new CTableLinkSource(ev, changeID, presentation, fTablePart, fTableContent, fTablePart->GetTableSelection(ev));
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::NewLinkDestination
- //----------------------------------------------------------------------------------------
-
- FW_CLinkDestination* CTableLinkManager::NewLinkDestination(Environment* ev, ODLink *odLink,
- ODLinkInfo* linkInfo,
- FW_CPresentation* presentation)
- {
- return new CTableLink(ev, odLink, linkInfo, presentation, fTablePart, fTableContent, fTablePart->GetTableSelection(ev));
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::DoChangeLinkStatus
- //----------------------------------------------------------------------------------------
-
- void CTableLinkManager::DoChangeLinkStatus(Environment* ev, ODFrame* odFrame)
- {
- // call ODFrame::ChangeLinkStatus on any embedded frames that are involved in a link
- // when a link is created, broken, moved, etc.
- // odFrame is the frame of this part whose link status has changed.
-
- FW_CEmbeddingFrame* frame = FW_CEmbeddingFrame::ODtoFWEmbeddingFrame(ev, odFrame);
- if (frame)
- {
- ODLinkStatus linkStatus = odFrame->GetLinkStatus(ev);
-
- // 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.
-
- CTableProxysIterator iter(fTableContent);
- for (CTableProxy* proxy = iter.First(); iter.IsNotComplete(); proxy = iter.Next())
- {
- if (!this->IsCellInLink(ev, proxy->GetCell()))
- {
- FW_CProxyEmbeddedFrameIterator efiter(ev, proxy);
- for (ODFrame* embFrame = efiter.First(ev); efiter.IsNotComplete(ev); embFrame = efiter.Next(ev))
- embFrame->ChangeLinkStatus(ev, linkStatus);
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::GetSourceLinkFormat, GetDestLinkFormat
- //----------------------------------------------------------------------------------------
- ODValueType CTableLinkManager::GetSourceLinkFormat(Environment* ev)
- {
- // Must be different from subscribe format!
- return kPublishFormat;
- }
-
- ODValueType CTableLinkManager::GetDestLinkFormat(Environment* ev)
- {
- // Must be different from publish format!
- return kSubscribeFormat;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::RevealLink
- //----------------------------------------------------------------------------------------
-
- void CTableLinkManager::RevealLink(Environment* ev, ODLinkSource* linkSource)
- {
- CTableLinkSource* sourceLink = (CTableLinkSource*) ODtoFWLinkSource(ev, linkSource);
- FW_ASSERT(sourceLink);
-
- // Choose a display frame for the source content
- FW_CFrame* frame = sourceLink->GetFrameToRevealLink(ev);
- if (frame)
- {
- // ----- Activate the frame's window -----
- if (!frame->GetWindow(ev)->IsActive(ev))
- frame->GetWindow(ev)->Select(ev);
-
- // ----- Activate the frame -----
- if (!frame->HasSelectionFocus(ev))
- {
- FW_CFrameFacetIterator iter(ev, frame); // find a facet
- frame->PrivActivateFrame(ev, iter.First(ev));
- }
-
- // ----- Select the link source -----
- sourceLink->DoSelect(ev, frame);
- }
- }
-
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::IsCellInLink
- //----------------------------------------------------------------------------------------
- FW_Boolean CTableLinkManager::IsCellInLink(Environment* ev, const CCell& cell)
- {
- //--- Check whether the cell participates in any of our source links
- FW_CLinkMgrLinkSourceIterator sit(this);
- for (CTableLinkSource* publisher = (CTableLinkSource*)sit.First(); sit.IsNotComplete();
- publisher = (CTableLinkSource*)sit.Next())
- {
- if (publisher->GetCell(ev) == cell)
- return true;
- }
-
- //--- Check whether the cell participates in any of our destination links
- FW_CLinkMgrLinkDestIterator dit(this);
- for (CTableLink* link = (CTableLink*)dit.First(); dit.IsNotComplete(); link = (CTableLink*)dit.Next())
- {
- if (link->GetCell(ev) == cell)
- return true;
- }
-
- return false;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::CellToSourceLink
- //----------------------------------------------------------------------------------------
- CTableLinkSource* CTableLinkManager::CellToSourceLink(Environment* ev, const CCell& cell) const
- {
- FW_CLinkMgrLinkSourceIterator iter(this);
- for (CTableLinkSource* slink = (CTableLinkSource*)iter.First(); iter.IsNotComplete();
- slink = (CTableLinkSource*)iter.Next())
- {
- if (slink->GetCell(ev) == cell)
- return slink;
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::CellToLink
- //----------------------------------------------------------------------------------------
- CTableLink* CTableLinkManager::CellToLink(Environment* ev, const CCell& cell) const
- {
- FW_CLinkMgrLinkDestIterator iter(this);
- for (CTableLink* link = (CTableLink*)iter.First(); iter.IsNotComplete();
- link = (CTableLink*)iter.Next())
- {
- if (link->GetCell(ev) == cell)
- return link;
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::ShowLinkInfo
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTableLinkManager::ShowLinkInfo(Environment* ev, ODFacet* facet)
- {
- FW_Boolean handledIt = true;
-
- CTableLinkSource* publisher = this->GetSelectedLinkSource(ev);
- if (publisher)
- {
- CBreakLinkSourceCommand* cmd = publisher->DoLinkInfo(ev, facet);
- if (cmd)
- cmd->Execute(ev); // break the link
- }
- else
- {
- CTableLink* subscriber = this->GetSelectedLinkDest(ev);
- if (subscriber)
- {
- CBreakLinkCommand* cmd = subscriber->DoLinkInfo(ev, facet);
- if (cmd)
- cmd->Execute(ev); // break the link
- }
- else
- handledIt = false;
- }
-
- return handledIt;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::GetSelectedLinkSource
- //----------------------------------------------------------------------------------------
- CTableLinkSource* CTableLinkManager::GetSelectedLinkSource(Environment* ev)
- {
- /* for now, return a link source if its cell is selected */
- CTableSelection* selection = fTablePart->GetTableSelection(ev);
- return this->CellToSourceLink(ev, selection->GetSelectedCell());
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::GetSelectedLinkDest
- //----------------------------------------------------------------------------------------
- CTableLink* CTableLinkManager::GetSelectedLinkDest(Environment* ev)
- {
- /* for now, return a link if its cell is selected */
- CTableSelection* selection = fTablePart->GetTableSelection(ev);
- return this->CellToLink(ev, selection->GetSelectedCell());
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::DoInternalizeOneSourceLink
- //---------------------------------------------------------------------------------------
-
- FW_CLinkSource* CTableLinkManager::DoInternalizeOneSourceLink(Environment* ev,
- ODStorageUnit* storageUnit,
- ODUpdateID updateID)
- {
- //-- Read the link source's cell
- CCell cell;
- FW_CByteArray byteArray;
- storageUnit->GetValue(ev, sizeof(CCell), byteArray);
- byteArray.CopyBuffer(&cell, sizeof(CCell));
-
- //-- Create and add a publisher to represent the link source
- CTableLinkSource* publisher = (CTableLinkSource*)this->NewLinkSource(ev,
- updateID, fTablePart->fTablePresentation);
- publisher->SetCell(ev, cell);
- fTablePart->ChangeFrameStatus(ev, cell, kODInLinkSource);
-
- return publisher;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::DoInternalizeOneDestLink
- //---------------------------------------------------------------------------------------
-
- FW_CLinkDestination* CTableLinkManager::DoInternalizeOneDestLink(Environment* ev,
- ODStorageUnit* storageUnit,
- ODLink* odLink,
- ODLinkInfo* linkInfo)
- {
- //-- Read the link's cell
- CCell cell;
- FW_CByteArray byteArray;
- storageUnit->GetValue(ev, sizeof(CCell), byteArray);
- byteArray.CopyBuffer(&cell, sizeof(CCell));
-
- //-- Create and add a subscriber to represent the link
- CTableLink* subscriber = (CTableLink*)this->NewLinkDestination(ev,
- odLink, linkInfo, fTablePart->fTablePresentation);
- subscriber->SetCell(ev, cell);
- return subscriber;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::UpdateLinkSource
- //----------------------------------------------------------------------------------------
-
- void CTableLinkManager::UpdateLinkSource(Environment* ev, ODUpdateID updateID)
- {
- CTableLinkSource* linkSource = this->GetSelectedLinkSource(ev);
- if (linkSource)
- linkSource->ContentUpdated(ev, updateID, true);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::BreakExistingLinks
- //----------------------------------------------------------------------------------------
- void CTableLinkManager::BreakExistingLinks(Environment* ev, const CCell& cell)
- {
- //-- Check for a link being broken --
- CTableLinkSource* linkSource = this->CellToSourceLink(ev, cell);
- if (linkSource)
- {
- this->BreakSourceLink(ev, linkSource);
- delete linkSource;
- }
- CTableLink* link = this->CellToLink(ev, cell);
- if (link)
- {
- this->BreakDestinationLink(ev, link);
- delete link;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::MoveExistingLinks
- //----------------------------------------------------------------------------------------
- void CTableLinkManager::MoveExistingLinks(Environment* ev,
- const CCell& fromCell,
- const CCell& toCell)
- {
- //-- Adjust affected links --
- CTableLinkSource* slink = this->CellToSourceLink(ev, fromCell);
- if (slink)
- slink->SetCell(ev, toCell);
- CTableLink* link = this->CellToLink(ev, fromCell);
- if (link)
- link->SetCell(ev, toCell);
- }
-
-