home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 32.7 KB | 1,005 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: TblLink.cpp
- // Release Version: $ 1.0d11 $
- //
- // Author: Mary Boetcher
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef TBLLINK_H
- #include "TblLink.h"
- #endif
-
- #ifndef TBLPART_H
- #include "TblPart.h"
- #endif
-
- #ifndef TBLSEL_H
- #include "TblSel.h"
- #endif
-
- #ifndef TBLCMDS_H
- #include "TblCmds.h"
- #endif
-
- #ifndef TBLPROXY_H
- #include "TblProxy.h"
- #endif
-
- #ifndef TBLFRAME_H
- #include "TblFrame.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
-
- // ----- 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
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- FW_DEFINE_CLASS_M1(CTablePublishLink, FW_CPublishLink)
- FW_DEFINE_CLASS_M1(CTableSubscribeLink, FW_CSubscribeLink)
- FW_DEFINE_CLASS_M1(CTableLinkManager, FW_CLinkManager)
-
- #ifdef FW_BUILD_MAC
- #pragma segment opftable
- #endif
-
- //========================================================================================
- // Constants
- //========================================================================================
-
- const ODValueType kTableLinkValue = "Table:Value";
-
- const ODPropertyName kODPropSourceLink = "Table:Property:SourceLink";
- const ODPropertyName kODPropDestLink = "Table:Property:DestLink";
-
- //========================================================================================
- // class CTablePublishLink
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CTablePublishLink constructor
- //----------------------------------------------------------------------------------------
-
- CTablePublishLink::CTablePublishLink(Environment *ev, ODUpdateID changeID,
- FW_CPresentation* presentation,
- CTablePart* part,
- CTableSelection* selection) :
- FW_CPublishLink(ev, changeID, presentation),
- fTablePart(part),
- fTableSelection(selection),
- fLinkCell(selection->GetCell())
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTablePublishLink destructor
- //----------------------------------------------------------------------------------------
-
- CTablePublishLink::~CTablePublishLink()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTablePublishLink::Publish
- //----------------------------------------------------------------------------------------
-
- void CTablePublishLink::Publish(Environment* ev)
- {
- FW_ASSERT(fODLinkSource != NULL);
- fODLinkSource->SetSourcePart(ev, fTablePart->GetODPart(ev)->GetStorageUnit(ev));
-
- //---- Change the link status of affected embedded frames
- fTablePart->ChangeFrameStatus(ev, fLinkCell, kODInLinkSource);
-
- //--- Force the first update using a new change ID
- ODUpdateID change = fTablePart->GetSession(ev)->UniqueUpdateID(ev);
- this->ContentUpdated(ev, change, TRUE);
- }
-
- //----------------------------------------------------------------------------------------
- // CTablePublishLink::Externalize
- //----------------------------------------------------------------------------------------
-
- void CTablePublishLink::Externalize(Environment* ev, ODStorageUnit* storageUnit,
- FW_CCloneInfo* cloneInfo)
- {
- //-- Storage unit must be focussed to property kODPropDestLink, value kTableLinkValue
- ODStorageUnitRef suRef;
- fODLinkSource->Externalize(ev);
-
- ODID linkID = fODLinkSource->GetID(ev);
- if (cloneInfo != NULL)
- {
- linkID = cloneInfo->Clone(ev, linkID, 0, 0);
- }
- FW_ASSERT(linkID != kODNULL);
-
- storageUnit->GetStrongStorageUnitRef(ev, linkID, suRef);
- FW_CByteArray byteArray(&suRef, sizeof(ODStorageUnitRef));
- storageUnit->SetValue(ev, byteArray);
- byteArray.Set(&fUpdateID, sizeof(ODUpdateID));
- storageUnit->SetValue(ev, byteArray);
-
- //-- Write out data specific to this part's publisher --
- CCell cell = fLinkCell; // table cell associated with this publisher
- byteArray.Set(&cell, sizeof(CCell));
- storageUnit->SetValue(ev, byteArray);
- }
-
- //----------------------------------------------------------------------------------------
- // CTablePublishLink::ExternalizeLinkContent
- //----------------------------------------------------------------------------------------
-
- void CTablePublishLink::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(fPresentation);
- FW_CFrame* frame = piter.First();
- FW_ASSERT(frame);
-
- // Since FW_CFrame::PrivHandleExternalizeScrap writes the current selection,
- // we need to temporarily select our link cell
- CCell savedCell = fTableSelection->GetCell();
- fTableSelection->Select(ev, fLinkCell, FALSE);
-
- fTableSelection->ExternalizeData(ev, frame, FW_kLinkStorage, linkSU, kODCloneToLink);
-
- // Restore the saved selection
- fTableSelection->Select(ev, savedCell, FALSE);
- }
-
- //----------------------------------------------------------------------------------------
- // CTablePublishLink::GetFrameToRevealLink
- //----------------------------------------------------------------------------------------
- FW_CFrame* CTablePublishLink::GetFrameToRevealLink(Environment* ev)
- {
- // By default, return the presentation's first display frame
- FW_CPresentationFrameIterator piter(fPresentation);
- return piter.First();
- }
-
- //----------------------------------------------------------------------------------------
- // CTablePublishLink::DoSelect
- //----------------------------------------------------------------------------------------
- void CTablePublishLink::DoSelect(Environment* ev, FW_CFrame* /*frame*/)
- {
- fTableSelection->Select(ev, fLinkCell, TRUE); // drawNow = TRUE
- }
-
- //----------------------------------------------------------------------------------------
- // CTablePublishLink::HasEmbeddedFrame
- //---------------------------------------------------------------------------------------
- FW_Boolean CTablePublishLink::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 = fTablePart->CellToProxy(ev, fLinkCell);
- 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;
- }
-
- //----------------------------------------------------------------------------------------
- // CTablePublishLink::DoLinkInfo
- //----------------------------------------------------------------------------------------
- CBreakLinkSourceCommand* CTablePublishLink::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
- }
-
- //----------------------------------------------------------------------------------------
- // CTablePublishLink::BreakLink
- //----------------------------------------------------------------------------------------
- void CTablePublishLink::BreakLink(Environment* ev)
- {
- FW_CPublishLink::BreakLink(ev);
-
- //--- Erase Link Borders ---
- fPresentation->Invalidate(ev); // force all frames to be redrawn
-
- //--- Change status of embedded frames ---
- fTablePart->ChangeFrameStatus(ev, fLinkCell, kODNotInLink);
- }
-
- //========================================================================================
- // class CTableSubscribeLink
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CTableSubscribeLink constructor
- //----------------------------------------------------------------------------------------
-
- CTableSubscribeLink::CTableSubscribeLink(Environment* ev,
- ODLink* odLink,
- ODLinkInfo* linkInfo,
- FW_CPresentation* presentation,
- CTablePart* part,
- CTableSelection* selection) :
- FW_CSubscribeLink(ev, odLink, linkInfo, presentation),
- fTablePart(part),
- fTableSelection(selection),
- fLinkCell(selection->GetCell())
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSubscribeLink destructor
- //----------------------------------------------------------------------------------------
-
- CTableSubscribeLink::~CTableSubscribeLink()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSubscribeLink::Subscribe
- //----------------------------------------------------------------------------------------
-
- void CTableSubscribeLink::Subscribe(Environment* ev)
- {
- fTablePart->ChangeFrameStatus(ev, fLinkCell, kODInLinkDestination);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSubscribeLink::DoUpdateLink
- //--------------------------------------------------------------------
- void CTableSubscribeLink::DoUpdateLink(Environment* ev, ODStorageUnit* linkContentSU)
- {
- FW_CPresentationFrameIterator piter(fPresentation);
- FW_CFrame* frame = piter.First();
- FW_ASSERT(frame);
-
- // Since CTableFrame::EmbedSingleFrame embeds into the selected cell,
- // we need to temporarily select our link cell
- CCell savedCell = fTableSelection->GetCell();
- fTableSelection->Select(ev, fLinkCell, FALSE);
-
- //-- Read data from the linkContentSU --
- fTableSelection->InternalizeData(ev, frame, linkContentSU, kODCloneFromLink);
-
- //-- Restore the previous selection
- fTableSelection->Select(ev, savedCell, FALSE);
-
- fPresentation->Invalidate(ev); // force all frames to be redrawn
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSubscribeLink::DoLinkInfo
- //----------------------------------------------------------------------------------------
- CBreakLinkCommand* CTableSubscribeLink::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
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSubscribeLink::BreakLink
- //----------------------------------------------------------------------------------------
- void CTableSubscribeLink::BreakLink(Environment* ev)
- {
- FW_CSubscribeLink::BreakLink(ev);
-
- //--- Erase Link Borders ---
- fPresentation->Invalidate(ev); // force all frames to be redrawn
-
- //--- Change status of embedded frames ---
- fTablePart->ChangeFrameStatus(ev, fLinkCell, kODNotInLink);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSubscribeLink::Externalize
- //----------------------------------------------------------------------------------------
-
- void CTableSubscribeLink::Externalize(Environment* ev, ODStorageUnit* storageUnit,
- FW_CCloneInfo* cloneInfo)
- {
- //-- Storage unit must be focussed to property kODPropDestLink, value kTableLinkValue
- ODStorageUnitRef suRef;
- fODLink->Externalize(ev);
-
- ODID linkID = fODLink->GetID(ev);
- if (cloneInfo != NULL)
- {
- linkID = cloneInfo->Clone(ev, linkID, 0, 0);
- }
- FW_ASSERT(linkID != kODNULL);
-
- storageUnit->GetStrongStorageUnitRef(ev, linkID, suRef);
- FW_CByteArray byteArray(&suRef, sizeof(ODStorageUnitRef));
- storageUnit->SetValue(ev, byteArray);
-
- ODType kind = fLinkInfo.kind; // save kind string
- fLinkInfo.kind = (ODType) strlen(kind) + 1;
- byteArray.Set(&fLinkInfo, sizeof(ODLinkInfo));
- storageUnit->SetValue(ev, byteArray); // write out linkinfo
- byteArray.Set((void*)kind, (ODULong)fLinkInfo.kind);
- storageUnit->SetValue(ev, byteArray); // write out kind string
- fLinkInfo.kind = kind; // restore kind string
-
- // Write out data specific to this part's subscriber
- CCell cell = fLinkCell; // table cell associated with this link
- byteArray.Set(&cell, sizeof(CCell));
- storageUnit->SetValue(ev, byteArray);
- }
-
- //========================================================================================
- // class CTableLinkManager
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager constructor
- //----------------------------------------------------------------------------------------
-
- CTableLinkManager::CTableLinkManager(Environment* ev, CTablePart* thePart) :
- FW_CLinkManager(ev, (FW_CPart*)thePart),
- fTablePart(thePart)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager destructor
- //----------------------------------------------------------------------------------------
-
- CTableLinkManager::~CTableLinkManager()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::NewPublishLink
- //----------------------------------------------------------------------------------------
-
- FW_CPublishLink* CTableLinkManager::NewPublishLink(Environment* ev, ODUpdateID changeID,
- FW_CPresentation* presentation)
- {
- return new CTablePublishLink(ev, changeID, presentation, fTablePart, fTablePart->GetTableSelection(ev));
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::NewSubscribeLink
- //----------------------------------------------------------------------------------------
-
- FW_CSubscribeLink* CTableLinkManager::NewSubscribeLink(Environment* ev, ODLink *odLink,
- ODLinkInfo* linkInfo,
- FW_CPresentation* presentation)
- {
- return new CTableSubscribeLink(ev, odLink, linkInfo, presentation, fTablePart, 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.
-
- FW_COrderedCollectionIterator iter(fTablePart->fProxys);
- for (CTableProxy* proxy = (CTableProxy*)iter.First(); iter.IsNotComplete(); proxy = (CTableProxy*)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::DoUpdateLinks
- //----------------------------------------------------------------------------------------
-
- void CTableLinkManager::DoUpdateLinks(Environment* ev, ODFrame* odEmbeddedFrame, ODUpdateID change)
- {
- // Content displayed in the embedded frame has changed
-
- /* 1) If odEmbeddedFrame is involved in one of my link sources, update the link with new data.
- "If the part maintains the source of a link that includes the embedded frame, the
- part should update the link." (Recipe p.12) */
- if (this->CountPublishers(ev) > 0)
- {
- FW_CPartPublishIterator iter(fPart);
- for (CTablePublishLink* publisher = (CTablePublishLink*)iter.First(); iter.IsNotComplete();
- publisher = (CTablePublishLink*)iter.Next())
- {
- if (publisher->HasEmbeddedFrame(ev, odEmbeddedFrame))
- {
- publisher->ContentUpdated(ev, change, FALSE);
- break;
- }
- }
- }
-
- /* 2) Call ContentUpdated on my display frames as appropriate */
- FW_CPartFrameIterator ite(fPart);
- for (FW_CFrame* frame = ite.First(); ite.IsNotComplete(); frame = ite.Next())
- {
- frame->GetODFrame(ev)->ContentUpdated(ev, change);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::RevealLink
- //----------------------------------------------------------------------------------------
-
- void CTableLinkManager::RevealLink(Environment *ev, ODLinkSource* linkSource)
- {
- CTablePublishLink* sourceLink = (CTablePublishLink*) ODtoPublishLink(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->IsActive(ev))
- {
- FW_CFrameFacetIterator iter(ev, frame); // find a facet
- frame->ActivateFrame(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_CPartPublishIterator piter(fPart);
- for (CTablePublishLink* publisher = (CTablePublishLink*)piter.First(); piter.IsNotComplete();
- publisher = (CTablePublishLink*)piter.Next())
- {
- if (publisher->GetCell(ev) == cell)
- return TRUE;
- }
-
- //--- Check whether the cell participates in any of our destination links
- FW_CPartSubscribeIterator siter(fPart);
- for (CTableSubscribeLink* link = (CTableSubscribeLink*)siter.First(); siter.IsNotComplete();
- link = (CTableSubscribeLink*)siter.Next())
- {
- if (link->GetCell(ev) == cell)
- return TRUE;
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::CellToPublishLink
- //----------------------------------------------------------------------------------------
- CTablePublishLink* CTableLinkManager::CellToPublishLink(Environment* ev, const CCell& cell) const
- {
- FW_CPartPublishIterator iter(fPart);
- for (CTablePublishLink* slink = (CTablePublishLink*)iter.First(); iter.IsNotComplete();
- slink = (CTablePublishLink*)iter.Next())
- {
- if (slink->GetCell(ev) == cell)
- return slink;
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::CellToSubscribeLink
- //----------------------------------------------------------------------------------------
- CTableSubscribeLink* CTableLinkManager::CellToSubscribeLink(Environment* ev, const CCell& cell) const
- {
- FW_CPartSubscribeIterator iter(fPart);
- for (CTableSubscribeLink* link = (CTableSubscribeLink*)iter.First(); iter.IsNotComplete();
- link = (CTableSubscribeLink*)iter.Next())
- {
- if (link->GetCell(ev) == cell)
- return link;
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::RegisterSubscribers
- //----------------------------------------------------------------------------------------
-
- void CTableLinkManager::RegisterSubscribers(Environment* ev)
- {
- if (this->CountSubscribers(ev) > 0)
- {
- FW_CPartSubscribeIterator iter(fPart);
- for (FW_CSubscribeLink* link = iter.First(); iter.IsNotComplete(); link = iter.Next())
- {
- if (link)
- link->Register(ev, fPart);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::ShowLinkInfo
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTableLinkManager::ShowLinkInfo(Environment* ev, ODFacet* facet)
- {
- FW_Boolean handledIt = TRUE;
-
- CTablePublishLink* publisher = this->GetSelectedLinkSource(ev);
- if (publisher)
- {
- CBreakLinkSourceCommand* cmd = publisher->DoLinkInfo(ev, facet);
- if (cmd)
- fPart->ExecuteCommand(ev, (FW_CCommand*)cmd); // break the link
- }
- else
- {
- CTableSubscribeLink* subscriber = this->GetSelectedLinkDest(ev);
- if (subscriber)
- {
- CBreakLinkCommand* cmd = subscriber->DoLinkInfo(ev, facet);
- if (cmd)
- fPart->ExecuteCommand(ev, (FW_CCommand*)cmd); // break the link
- }
- else
- handledIt = FALSE;
- }
-
- return handledIt;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::GetSelectedLinkSource
- //----------------------------------------------------------------------------------------
- CTablePublishLink* CTableLinkManager::GetSelectedLinkSource(Environment* ev)
- {
- /* for now, return a link source if its cell is selected */
- CTableSelection* selection = fTablePart->GetTableSelection(ev);
- return this->CellToPublishLink(ev, selection->GetCell());
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::GetSelectedLinkDest
- //----------------------------------------------------------------------------------------
- CTableSubscribeLink* CTableLinkManager::GetSelectedLinkDest(Environment* ev)
- {
- /* for now, return a link if its cell is selected */
- CTableSelection* selection = fTablePart->GetTableSelection(ev);
- return this->CellToSubscribeLink(ev, selection->GetCell());
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::InternalizeOneSourceLink
- //---------------------------------------------------------------------------------------
-
- void CTableLinkManager::InternalizeOneSourceLink(Environment* ev,
- ODStorageUnitView* suView,
- ODDraft* suDraft)
- {
- ODStorageUnitRef suRef;
- ODUpdateID changeID;
- FW_Boolean validLink = TRUE;
-
- FW_TRY
- {
- FW_CByteArray byteArray;
- suView->GetValue(ev, sizeof(ODStorageUnitRef), byteArray);
- byteArray.CopyBuffer(&suRef, sizeof(ODStorageUnitRef));
- if (suView->IsValidStorageUnitRef(ev, suRef))
- {
- //-- Read the link source data
- ODID linkSourceID = suView->GetIDFromStorageUnitRef(ev, suRef);
- ODLinkSource* odLinkSource = suDraft->AcquireLinkSource(ev, linkSourceID);
- FW_CByteArray ba;
- suView->GetValue(ev, sizeof(ODUpdateID), ba);
- ba.CopyBuffer(&changeID, sizeof(ODUpdateID));
-
- //-- Read the link source's cell
- CCell cell;
- FW_CByteArray ba2;
- suView->GetValue(ev, sizeof(CCell), ba2);
- ba2.CopyBuffer(&cell, sizeof(CCell));
-
- //-- Ensure the link source object references our part as the source of the link
- odLinkSource->SetSourcePart(ev, fTablePart->GetStorageUnit(ev));
-
- //-- Create and add a publisher to represent the link source
- CTablePublishLink* publisher = (CTablePublishLink*)this->NewPublishLink(ev,
- changeID, fTablePart->fTablePresentation);
- publisher->SetODLinkSource(ev, odLinkSource);
- publisher->SetCell(ev, cell);
- this->AddToPublishLinkList(ev, publisher);
- fTablePart->ChangeFrameStatus(ev, cell, kODInLinkSource);
- odLinkSource->Release(ev); // to balance AcquireLinkSource above
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- validLink = FALSE;
- DebugStr("\pException reading source link in InternalizeOneSourceLink");
- FW_THROW_SAME();
- }
- FW_CATCH_END
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::InternalizeOneDestLink
- //---------------------------------------------------------------------------------------
-
- void CTableLinkManager::InternalizeOneDestLink(Environment* ev,
- ODStorageUnitView* suView,
- ODDraft* suDraft)
- {
- //--- Storage unit must already be focussed to a kTableLinkValue value in the kODPropDestLink property
- FW_Boolean validLink = TRUE;
- ODStorageUnitRef suRef;
-
- FW_TRY
- {
- FW_CByteArray byteArray;
- suView->GetValue(ev, sizeof(ODStorageUnitRef), byteArray);
- byteArray.CopyBuffer(&suRef, sizeof(ODStorageUnitRef));
- if (suView->IsValidStorageUnitRef(ev, suRef))
- {
- //-- Read the link data
- ODID linkID = suView->GetIDFromStorageUnitRef(ev, suRef);
- ODLink* odLink = suDraft->AcquireLink(ev, linkID, NULL);
- ODLinkInfo linkInfo;
-
- FW_CByteArray ba;
- suView->GetValue(ev, sizeof(ODLinkInfo), ba);
- ba.CopyBuffer(&linkInfo, sizeof(ODLinkInfo));
- ODType kind = (ODType) FW_CMemoryManager::AllocateBlock((ODULong)linkInfo.kind); // allocate linkInfo.kind bytes;
-
- FW_CByteArray ba2;
- suView->GetValue(ev, (ODULong)linkInfo.kind, ba2);
- ba2.CopyBuffer((void*)kind, (ODULong)linkInfo.kind);
- linkInfo.kind = kind;
-
- //-- Read the link's cell
- CCell cell;
- FW_CByteArray ba3;
- suView->GetValue(ev, sizeof(CCell), ba3);
- ba3.CopyBuffer(&cell, sizeof(CCell));
-
- //-- Create and add a subscriber to represent the link
- CTableSubscribeLink* subscriber = (CTableSubscribeLink*)this->NewSubscribeLink(ev,
- odLink, &linkInfo, fTablePart->fTablePresentation);
- subscriber->SetCell(ev, cell);
- this->AddToSubscribeLinkList(ev, subscriber);
- subscriber->HandleSubscribe(ev);
- odLink->Release(ev); // to balance AcquireLink above
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- validLink = FALSE;
- DebugStr("\pException reading dest link in InternalizeOneDestLink");
- FW_THROW_SAME();
- }
- FW_CATCH_END
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::UpdateLinkSource
- //----------------------------------------------------------------------------------------
-
- void CTableLinkManager::UpdateLinkSource(Environment* ev, ODUpdateID updateID)
- {
- CTablePublishLink* 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 --
- CTablePublishLink* linkSource = this->CellToPublishLink(ev, cell);
- if (linkSource)
- {
- this->BreakPublishLink(ev, linkSource);
- delete linkSource;
- }
- CTableSubscribeLink* link = this->CellToSubscribeLink(ev, cell);
- if (link)
- {
- this->BreakSubscribeLink(ev, link);
- delete link;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTableLinkManager::MoveExistingLinks
- //----------------------------------------------------------------------------------------
- void CTableLinkManager::MoveExistingLinks(Environment* ev,
- const CCell& fromCell,
- const CCell& toCell)
- {
- //-- Adjust affected links --
- CTablePublishLink* slink = this->CellToPublishLink(ev, fromCell);
- if (slink)
- slink->SetCell(ev, toCell);
- CTableSubscribeLink* link = this->CellToSubscribeLink(ev, fromCell);
- if (link)
- link->SetCell(ev, toCell);
- }
-
- //------------------------------------------------------------------------------
- // CTableLinkManager::ExternalizeLinks
- //------------------------------------------------------------------------------
- void CTableLinkManager::ExternalizeLinks(Environment* ev, ODStorageUnitView* suView,
- FW_CCloneInfo* cloneInfo)
- {
- ODStorageUnit* su = suView->GetStorageUnit(ev);
-
- //--- Write out the source links ---
- if (this->CountPublishers(ev) > 0)
- {
- //-- Make sure the correct property and value is present in the SU --
- FW_SUForceFocus(ev, su, kODPropSourceLink, kTableLinkValue);
-
- FW_CPartPublishIterator iter(fPart);
- for (CTablePublishLink* slink = (CTablePublishLink*)iter.First(); iter.IsNotComplete();
- slink = (CTablePublishLink*)iter.Next())
- {
- slink->Externalize(ev, su, cloneInfo);
- }
- }
- else
- FW_SURemoveProperty(ev, su, kODPropSourceLink);
-
- //--- Write out the destination links ---
- if (this->CountSubscribers(ev) > 0)
- {
- //-- Make sure the correct property and value is present in the SU --
- FW_SUForceFocus(ev, su, kODPropDestLink, kTableLinkValue);
-
- FW_CPartSubscribeIterator iter(fPart);
- for (CTableSubscribeLink* link = (CTableSubscribeLink*)iter.First(); iter.IsNotComplete();
- link = (CTableSubscribeLink*)iter.Next())
- {
- link->Externalize(ev, su, cloneInfo);
- }
- }
- else
- FW_SURemoveProperty(ev, su, kODPropDestLink);
- }
-
- //------------------------------------------------------------------------------
- // CTableLinkManager::InternalizeLinks
- //------------------------------------------------------------------------------
- void CTableLinkManager::InternalizeLinks(Environment* ev, ODStorageUnit* storageUnit)
- {
- unsigned long offsetLimit;
-
- if (storageUnit->Exists(ev, kODPropSourceLink, kTableLinkValue, 0))
- {
- storageUnit->Focus(ev, kODPropSourceLink, kODPosUndefined, kTableLinkValue, 0, kODPosUndefined);
- ODStorageUnitView* suView = storageUnit->CreateView(ev);
- offsetLimit = suView->GetSize(ev);
-
- while (suView->GetOffset(ev) < offsetLimit)
- {
- InternalizeOneSourceLink(ev, suView, storageUnit->GetDraft(ev));
- }
- delete suView;
- }
-
- if (storageUnit->Exists(ev, kODPropDestLink, kTableLinkValue, 0))
- {
- storageUnit->Focus(ev, kODPropDestLink, kODPosUndefined, kTableLinkValue, 0, kODPosUndefined);
- ODStorageUnitView* suView = storageUnit->CreateView(ev);
- offsetLimit = suView->GetSize(ev);
-
- while (suView->GetOffset(ev) < offsetLimit)
- {
- InternalizeOneDestLink(ev, suView, storageUnit->GetDraft(ev));
- }
- delete suView;
- }
- }
-
-