Kaydet (Commit) 8fde2885 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Move the LinkManager instance from ScDocument to ScDocumentLinkManager.

Change-Id: I096322fa200abed5bacc786c1abc57a3ec51276f
üst eb89c6f7
...@@ -280,7 +280,6 @@ private: ...@@ -280,7 +280,6 @@ private:
ScChartCollection* pChartCollection; ScChartCollection* pChartCollection;
std::auto_ptr< ScTemporaryChartLock > apTemporaryChartLock; std::auto_ptr< ScTemporaryChartLock > apTemporaryChartLock;
ScPatternAttr* pSelectionAttr; // Attributes of a block ScPatternAttr* pSelectionAttr; // Attributes of a block
mutable sfx2::LinkManager* pLinkManager;
ScFormulaCell* pFormulaTree; // formula tree (start) ScFormulaCell* pFormulaTree; // formula tree (start)
ScFormulaCell* pEOFormulaTree; // formula tree (end), last cell ScFormulaCell* pEOFormulaTree; // formula tree (end), last cell
ScFormulaCell* pFormulaTrack; // BroadcastTrack (start) ScFormulaCell* pFormulaTrack; // BroadcastTrack (start)
...@@ -469,7 +468,8 @@ public: ...@@ -469,7 +468,8 @@ public:
SC_DLLPUBLIC void InitDrawLayer( SfxObjectShell* pDocShell = NULL ); SC_DLLPUBLIC void InitDrawLayer( SfxObjectShell* pDocShell = NULL );
rtl::Reference<XColorList> GetColorList(); rtl::Reference<XColorList> GetColorList();
SC_DLLPUBLIC sfx2::LinkManager* GetLinkManager() const; SC_DLLPUBLIC sfx2::LinkManager* GetLinkManager();
SC_DLLPUBLIC const sfx2::LinkManager* GetLinkManager() const;
sc::DocumentLinkManager& GetDocLinkManager(); sc::DocumentLinkManager& GetDocLinkManager();
const sc::DocumentLinkManager& GetDocLinkManager() const; const sc::DocumentLinkManager& GetDocLinkManager() const;
......
...@@ -12,6 +12,15 @@ ...@@ -12,6 +12,15 @@
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
class ScDocument;
class SfxObjectShell;
namespace sfx2 {
class LinkManager;
}
namespace sc { namespace sc {
class DataStream; class DataStream;
...@@ -22,11 +31,21 @@ class DocumentLinkManager : boost::noncopyable ...@@ -22,11 +31,21 @@ class DocumentLinkManager : boost::noncopyable
DocumentLinkManagerImpl* mpImpl; DocumentLinkManagerImpl* mpImpl;
public: public:
DocumentLinkManager(); DocumentLinkManager( ScDocument& rDoc, SfxObjectShell* pShell );
void setDataStream( DataStream* p ); void setDataStream( DataStream* p );
DataStream* getDataStream(); DataStream* getDataStream();
const DataStream* getDataStream() const; const DataStream* getDataStream() const;
/**
* @param bCreate if true, create a new link manager instance in case one
* does not exist.
*
* @return link manager instance.
*/
sfx2::LinkManager* getLinkManager( bool bCreate = true );
const sfx2::LinkManager* getExistingLinkManager() const;
}; };
} }
......
...@@ -139,7 +139,6 @@ ScDocument::ScDocument( ScDocumentMode eMode, SfxObjectShell* pDocShell ) : ...@@ -139,7 +139,6 @@ ScDocument::ScDocument( ScDocumentMode eMode, SfxObjectShell* pDocShell ) :
pFormatExchangeList( NULL ), pFormatExchangeList( NULL ),
pRangeName(NULL), pRangeName(NULL),
pDPCollection( NULL ), pDPCollection( NULL ),
pLinkManager( NULL ),
pFormulaTree( NULL ), pFormulaTree( NULL ),
pEOFormulaTree( NULL ), pEOFormulaTree( NULL ),
pFormulaTrack( NULL ), pFormulaTrack( NULL ),
...@@ -228,9 +227,6 @@ ScDocument::ScDocument( ScDocumentMode eMode, SfxObjectShell* pDocShell ) : ...@@ -228,9 +227,6 @@ ScDocument::ScDocument( ScDocumentMode eMode, SfxObjectShell* pDocShell ) :
if ( eMode == SCDOCMODE_DOCUMENT ) if ( eMode == SCDOCMODE_DOCUMENT )
{ {
if ( pDocShell )
pLinkManager = new sfx2::LinkManager( pDocShell );
xPoolHelper = new ScPoolHelper( this ); xPoolHelper = new ScPoolHelper( this );
pBASM = new ScBroadcastAreaSlotMachine( this ); pBASM = new ScBroadcastAreaSlotMachine( this );
...@@ -257,27 +253,26 @@ ScDocument::ScDocument( ScDocumentMode eMode, SfxObjectShell* pDocShell ) : ...@@ -257,27 +253,26 @@ ScDocument::ScDocument( ScDocumentMode eMode, SfxObjectShell* pDocShell ) :
aTrackTimer.SetTimeout( 100 ); aTrackTimer.SetTimeout( 100 );
} }
sfx2::LinkManager* ScDocument::GetLinkManager() const sfx2::LinkManager* ScDocument::GetLinkManager()
{ {
if ( bAutoCalc && !pLinkManager && pShell) return GetDocLinkManager().getLinkManager(bAutoCalc);
{ }
pLinkManager = new sfx2::LinkManager( pShell );
} const sfx2::LinkManager* ScDocument::GetLinkManager() const
return pLinkManager; {
return GetDocLinkManager().getExistingLinkManager();
} }
sc::DocumentLinkManager& ScDocument::GetDocLinkManager() sc::DocumentLinkManager& ScDocument::GetDocLinkManager()
{ {
if (!mpDocLinkMgr) if (!mpDocLinkMgr)
mpDocLinkMgr.reset(new sc::DocumentLinkManager); mpDocLinkMgr.reset(new sc::DocumentLinkManager(*this, pShell));
return *mpDocLinkMgr; return *mpDocLinkMgr;
} }
const sc::DocumentLinkManager& ScDocument::GetDocLinkManager() const const sc::DocumentLinkManager& ScDocument::GetDocLinkManager() const
{ {
if (!mpDocLinkMgr) return const_cast<ScDocument*>(this)->GetDocLinkManager();
mpDocLinkMgr.reset(new sc::DocumentLinkManager);
return *mpDocLinkMgr;
} }
void ScDocument::SetStorageGrammar( formula::FormulaGrammar::Grammar eGram ) void ScDocument::SetStorageGrammar( formula::FormulaGrammar::Grammar eGram )
...@@ -386,19 +381,6 @@ ScDocument::~ScDocument() ...@@ -386,19 +381,6 @@ ScDocument::~ScDocument()
delete pRefreshTimerControl, pRefreshTimerControl = NULL; delete pRefreshTimerControl, pRefreshTimerControl = NULL;
} }
// Links aufrauemen
if ( GetLinkManager() )
{
// BaseLinks freigeben
::sfx2::SvLinkSources aTemp(pLinkManager->GetServers());
for( ::sfx2::SvLinkSources::const_iterator it = aTemp.begin(); it != aTemp.end(); ++it )
(*it)->Closed();
if ( pLinkManager->GetLinks().size() )
pLinkManager->Remove( 0, pLinkManager->GetLinks().size() );
}
mxFormulaParserPool.reset(); mxFormulaParserPool.reset();
// Destroy the external ref mgr instance here because it has a timer // Destroy the external ref mgr instance here because it has a timer
// which needs to be stopped before the app closes. // which needs to be stopped before the app closes.
...@@ -438,7 +420,6 @@ ScDocument::~ScDocument() ...@@ -438,7 +420,6 @@ ScDocument::~ScDocument()
delete pPrinter; delete pPrinter;
ImplDeleteOptions(); ImplDeleteOptions();
delete pConsolidateDlgData; delete pConsolidateDlgData;
delete pLinkManager;
delete pClipData; delete pClipData;
delete pDetOpList; // loescht auch die Eintraege delete pDetOpList; // loescht auch die Eintraege
delete pChangeTrack; delete pChangeTrack;
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
#include "postit.hxx" #include "postit.hxx"
#include "charthelper.hxx" #include "charthelper.hxx"
#include "interpre.hxx" #include "interpre.hxx"
#include <documentlinkmgr.hxx>
using namespace ::com::sun::star; using namespace ::com::sun::star;
#include <stdio.h> #include <stdio.h>
...@@ -130,8 +131,10 @@ void ScDocument::InitDrawLayer( SfxObjectShell* pDocShell ) ...@@ -130,8 +131,10 @@ void ScDocument::InitDrawLayer( SfxObjectShell* pDocShell )
if ( pShell && !pShell->IsLoading() ) // don't call GetTitle while loading if ( pShell && !pShell->IsLoading() ) // don't call GetTitle while loading
aName = pShell->GetTitle(); aName = pShell->GetTitle();
pDrawLayer = new ScDrawLayer( this, aName ); pDrawLayer = new ScDrawLayer( this, aName );
if (GetLinkManager())
pDrawLayer->SetLinkManager( pLinkManager ); sfx2::LinkManager* pMgr = GetDocLinkManager().getLinkManager(bAutoCalc);
if (pMgr)
pDrawLayer->SetLinkManager(pMgr);
// Drawing pages are accessed by table number, so they must also be present // Drawing pages are accessed by table number, so they must also be present
// for preceding table numbers, even if the tables aren't allocated // for preceding table numbers, even if the tables aren't allocated
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <documentlinkmgr.hxx> #include <documentlinkmgr.hxx>
#include <datastream.hxx> #include <datastream.hxx>
#include <sfx2/linkmgr.hxx>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
...@@ -17,12 +18,31 @@ namespace sc { ...@@ -17,12 +18,31 @@ namespace sc {
struct DocumentLinkManagerImpl : boost::noncopyable struct DocumentLinkManagerImpl : boost::noncopyable
{ {
ScDocument& mrDoc;
SfxObjectShell* mpShell;
boost::scoped_ptr<DataStream> mpDataStream; boost::scoped_ptr<DataStream> mpDataStream;
boost::scoped_ptr<sfx2::LinkManager> mpLinkManager;
DocumentLinkManagerImpl() : mpDataStream(NULL) {} DocumentLinkManagerImpl( ScDocument& rDoc, SfxObjectShell* pShell ) :
mrDoc(rDoc), mpShell(pShell), mpDataStream(NULL), mpLinkManager(NULL) {}
~DocumentLinkManagerImpl()
{
// Shared base links
if (mpLinkManager)
{
sfx2::SvLinkSources aTemp = mpLinkManager->GetServers();
for (sfx2::SvLinkSources::const_iterator it = aTemp.begin(); it != aTemp.end(); ++it)
(*it)->Closed();
if (!mpLinkManager->GetLinks().empty())
mpLinkManager->Remove(0, mpLinkManager->GetLinks().size());
}
}
}; };
DocumentLinkManager::DocumentLinkManager() : mpImpl(new DocumentLinkManagerImpl) {} DocumentLinkManager::DocumentLinkManager( ScDocument& rDoc, SfxObjectShell* pShell ) :
mpImpl(new DocumentLinkManagerImpl(rDoc, pShell)) {}
void DocumentLinkManager::setDataStream( DataStream* p ) void DocumentLinkManager::setDataStream( DataStream* p )
{ {
...@@ -39,6 +59,18 @@ const DataStream* DocumentLinkManager::getDataStream() const ...@@ -39,6 +59,18 @@ const DataStream* DocumentLinkManager::getDataStream() const
return mpImpl->mpDataStream.get(); return mpImpl->mpDataStream.get();
} }
sfx2::LinkManager* DocumentLinkManager::getLinkManager( bool bCreate )
{
if (!mpImpl->mpLinkManager && bCreate && mpImpl->mpShell)
mpImpl->mpLinkManager.reset(new sfx2::LinkManager(mpImpl->mpShell));
return mpImpl->mpLinkManager.get();
}
const sfx2::LinkManager* DocumentLinkManager::getExistingLinkManager() const
{
return mpImpl->mpLinkManager.get();
}
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -47,7 +47,7 @@ public: ...@@ -47,7 +47,7 @@ public:
bool IsEqualSource( const ScAreaLink& rCompare ) const; bool IsEqualSource( const ScAreaLink& rCompare ) const;
void WriteToLink( ScAreaLink& rLink ) const; void WriteToLink( ScAreaLink& rLink ) const;
void InsertNewLink( ScDocument* pDoc ) const; void InsertNewLink( ScDocument* pDoc );
}; };
...@@ -62,11 +62,12 @@ public: ...@@ -62,11 +62,12 @@ public:
bool IsEqual( const ScDocument* pDoc ) const; bool IsEqual( const ScDocument* pDoc ) const;
void Restore( ScDocument* pDoc ) const; void Restore( ScDocument* pDoc );
// returns NULL if empty // returns NULL if empty
static ScAreaLinkSaveCollection* CreateFromDoc( const ScDocument* pDoc ); static ScAreaLinkSaveCollection* CreateFromDoc( const ScDocument* pDoc );
ScAreaLinkSaver* operator[](size_t nIndex);
const ScAreaLinkSaver* operator[](size_t nIndex) const; const ScAreaLinkSaver* operator[](size_t nIndex) const;
size_t size() const; size_t size() const;
void push_back(ScAreaLinkSaver* p); void push_back(ScAreaLinkSaver* p);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "areasave.hxx" #include "areasave.hxx"
#include "arealink.hxx" #include "arealink.hxx"
#include "document.hxx" #include "document.hxx"
#include <documentlinkmgr.hxx>
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
...@@ -67,7 +68,7 @@ void ScAreaLinkSaver::WriteToLink( ScAreaLink& rLink ) const ...@@ -67,7 +68,7 @@ void ScAreaLinkSaver::WriteToLink( ScAreaLink& rLink ) const
rLink.SetDestArea( aDestArea ); rLink.SetDestArea( aDestArea );
} }
void ScAreaLinkSaver::InsertNewLink( ScDocument* pDoc ) const void ScAreaLinkSaver::InsertNewLink( ScDocument* pDoc )
{ {
// (see ScUndoRemoveAreaLink::Undo) // (see ScUndoRemoveAreaLink::Undo)
...@@ -99,7 +100,7 @@ bool ScAreaLinkSaveCollection::IsEqual( const ScDocument* pDoc ) const ...@@ -99,7 +100,7 @@ bool ScAreaLinkSaveCollection::IsEqual( const ScDocument* pDoc ) const
// IsEqual can be checked in sequence. // IsEqual can be checked in sequence.
// Neither ref-update nor removing links will change the order. // Neither ref-update nor removing links will change the order.
sfx2::LinkManager* pLinkManager = const_cast<ScDocument*>(pDoc)->GetLinkManager(); const sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
if (pLinkManager) if (pLinkManager)
{ {
size_t nPos = 0; size_t nPos = 0;
...@@ -138,21 +139,21 @@ static ScAreaLink* lcl_FindLink( const ::sfx2::SvBaseLinks& rLinks, const ScArea ...@@ -138,21 +139,21 @@ static ScAreaLink* lcl_FindLink( const ::sfx2::SvBaseLinks& rLinks, const ScArea
return NULL; // not found return NULL; // not found
} }
void ScAreaLinkSaveCollection::Restore( ScDocument* pDoc ) const void ScAreaLinkSaveCollection::Restore( ScDocument* pDoc )
{ {
// The save collection may contain additional entries that are not in the document. // The save collection may contain additional entries that are not in the document.
// They must be inserted again. // They must be inserted again.
// Entries from the save collection must be searched via source data, as the order // Entries from the save collection must be searched via source data, as the order
// of links changes if deleted entries are re-added to the link manager (always at the end). // of links changes if deleted entries are re-added to the link manager (always at the end).
sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager(); sfx2::LinkManager* pLinkManager = pDoc->GetDocLinkManager().getLinkManager(false);
if (pLinkManager) if (pLinkManager)
{ {
const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks(); const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
size_t nSaveCount = size(); size_t nSaveCount = size();
for (size_t nPos=0; nPos<nSaveCount; ++nPos) for (size_t nPos=0; nPos<nSaveCount; ++nPos)
{ {
const ScAreaLinkSaver* pSaver = (*this)[nPos]; ScAreaLinkSaver* pSaver = (*this)[nPos];
ScAreaLink* pLink = lcl_FindLink( rLinks, *pSaver ); ScAreaLink* pLink = lcl_FindLink( rLinks, *pSaver );
if ( pLink ) if ( pLink )
pSaver->WriteToLink( *pLink ); // restore output position pSaver->WriteToLink( *pLink ); // restore output position
...@@ -188,6 +189,11 @@ ScAreaLinkSaveCollection* ScAreaLinkSaveCollection::CreateFromDoc( const ScDocum ...@@ -188,6 +189,11 @@ ScAreaLinkSaveCollection* ScAreaLinkSaveCollection::CreateFromDoc( const ScDocum
return pColl; return pColl;
} }
ScAreaLinkSaver* ScAreaLinkSaveCollection::operator [](size_t nIndex)
{
return &maData[nIndex];
}
const ScAreaLinkSaver* ScAreaLinkSaveCollection::operator [](size_t nIndex) const const ScAreaLinkSaver* ScAreaLinkSaveCollection::operator [](size_t nIndex) const
{ {
return &maData[nIndex]; return &maData[nIndex];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment