sc/inc/document.hxx | 8 - sc/inc/documentlinkmgr.hxx | 14 ++ sc/source/core/data/documen2.cxx | 2 sc/source/core/data/documen8.cxx | 170 ------------------------------ sc/source/ui/app/scmod.cxx | 4 sc/source/ui/docshell/docsh.cxx | 2 sc/source/ui/docshell/docsh4.cxx | 15 ++ sc/source/ui/docshell/documentlinkmgr.cxx | 162 ++++++++++++++++++++++++++++ sc/source/ui/unoobj/linkuno.cxx | 14 +- sc/source/ui/view/tabvwsh4.cxx | 8 + 10 files changed, 208 insertions(+), 191 deletions(-)
New commits: commit 18915452d17d6a0ca431eb07b6f5b9f1deb1e6af Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Thu Jan 9 23:40:33 2014 -0500 Move some of the link related methods to the document link manager. Change-Id: I9b4a3f31bd973a2b57fae5b44d98258ddad731f1 diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index b3d2a92..3fe416c 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -683,10 +683,8 @@ public: on first call. */ ScFormulaParserPool& GetFormulaParserPool() const; - bool HasDdeLinks() const; bool HasAreaLinks() const; void UpdateExternalRefLinks(Window* pWin); - void UpdateDdeLinks(Window* pWin); void UpdateAreaLinks(); // originating DDE links @@ -695,11 +693,6 @@ public: bool IsInDdeLinkUpdate() const { return nInDdeLinkUpdate != 0; } SC_DLLPUBLIC void CopyDdeLinks( ScDocument* pDestDoc ) const; - void DisconnectDdeLinks(); - - // for StarOne Api: - size_t GetDdeLinkCount() const; - bool UpdateDdeLink( const OUString& rAppl, const OUString& rTopic, const OUString& rItem ); /** Tries to find a DDE link with the specified connection data. @param rnDdePos (out-param) Returns the index of the DDE link (does not include other links from link manager). @@ -1685,7 +1678,6 @@ public: void InvalidateTextWidth( const ScAddress* pAdrFrom, const ScAddress* pAdrTo, bool bNumFormatChanged ); bool IdleCalcTextWidth(); - bool IdleCheckLinks(); void RepaintRange( const ScRange& rRange ); void RepaintRange( const ScRangeList& rRange ); diff --git a/sc/inc/documentlinkmgr.hxx b/sc/inc/documentlinkmgr.hxx index 5de8dcd..c4c4971 100644 --- a/sc/inc/documentlinkmgr.hxx +++ b/sc/inc/documentlinkmgr.hxx @@ -11,9 +11,11 @@ #define SC_DOCUMENTLINKMGR_HXX #include <boost/noncopyable.hpp> +#include <rtl/ustring.hxx> class ScDocument; class SfxObjectShell; +class Window; namespace sfx2 { @@ -47,6 +49,18 @@ public: sfx2::LinkManager* getLinkManager( bool bCreate = true ); const sfx2::LinkManager* getExistingLinkManager() const; + + bool idleCheckLinks(); + + bool hasDdeLinks() const; + + bool updateDdeLinks( Window* pWin ); + + bool updateDdeLink( const OUString& rAppl, const OUString& rTopic, const OUString& rItem ); + + size_t getDdeLinkCount() const; + + void disconnectDdeLinks(); }; } diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx index eeb04b1..91352a1 100644 --- a/sc/source/core/data/documen2.cxx +++ b/sc/source/core/data/documen2.cxx @@ -471,7 +471,7 @@ void ScDocument::InitClipPtrs( ScDocument* pSourceDoc ) // Links in Stream speichern delete pClipData; - if (pSourceDoc->HasDdeLinks()) + if (pSourceDoc->GetDocLinkManager().hasDdeLinks()) { pClipData = new SvMemoryStream; pSourceDoc->SaveDdeLinks(*pClipData); diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx index 1b9b20dd..41db3c0 100644 --- a/sc/source/core/data/documen8.cxx +++ b/sc/source/core/data/documen8.cxx @@ -745,36 +745,6 @@ void ScDocument::RepaintRange( const ScRangeList& rRange ) } } -//------------------------------------------------------------------------ - -bool ScDocument::IdleCheckLinks() // true = demnaechst wieder versuchen -{ - bool bAnyLeft = false; - - sfx2::LinkManager* pMgr = GetLinkManager(); - if (pMgr) - { - const ::sfx2::SvBaseLinks& rLinks = pMgr->GetLinks(); - sal_uInt16 nCount = rLinks.size(); - for (sal_uInt16 i=0; i<nCount; i++) - { - ::sfx2::SvBaseLink* pBase = *rLinks[i]; - if (pBase->ISA(ScDdeLink)) - { - ScDdeLink* pDdeLink = (ScDdeLink*)pBase; - if (pDdeLink->NeedsUpdate()) - { - pDdeLink->TryUpdate(); - if (pDdeLink->NeedsUpdate()) // war nix? - bAnyLeft = true; - } - } - } - } - - return bAnyLeft; -} - void ScDocument::SaveDdeLinks(SvStream& rStream) const { // bei 4.0-Export alle mit Modus != DEFAULT weglassen @@ -831,21 +801,6 @@ void ScDocument::LoadDdeLinks(SvStream& rStream) } } -bool ScDocument::HasDdeLinks() const -{ - const sfx2::LinkManager* pMgr = GetDocLinkManager().getExistingLinkManager(); - if (!pMgr) - return false; - - const ::sfx2::SvBaseLinks& rLinks = pMgr->GetLinks(); - sal_uInt16 nCount = rLinks.size(); - for (sal_uInt16 i=0; i<nCount; i++) - if ((*rLinks[i])->ISA(ScDdeLink)) - return true; - - return false; -} - void ScDocument::SetInLinkUpdate(bool bSet) { // called from TableLink and AreaLink @@ -915,111 +870,6 @@ void ScDocument::UpdateExternalRefLinks(Window* pWin) } } -void ScDocument::UpdateDdeLinks(Window* pWin) -{ - sfx2::LinkManager* pMgr = GetDocLinkManager().getLinkManager(bAutoCalc); - if (!pMgr) - return; - - const ::sfx2::SvBaseLinks& rLinks = pMgr->GetLinks(); - sal_uInt16 nCount = rLinks.size(); - sal_uInt16 i; - - // falls das Updaten laenger dauert, erstmal alle Werte - // zuruecksetzen, damit nichts altes (falsches) stehen bleibt - bool bAny = false; - for (i=0; i<nCount; i++) - { - ::sfx2::SvBaseLink* pBase = *rLinks[i]; - ScDdeLink* pDdeLink = dynamic_cast<ScDdeLink*>(pBase); - if (pDdeLink) - { - if (pDdeLink->Update()) - bAny = true; - else - { - // Update failed. Notify the user. - OUString aFile = pDdeLink->GetTopic(); - OUString aElem = pDdeLink->GetItem(); - OUString aType = pDdeLink->GetAppl(); - - OUStringBuffer aBuf; - aBuf.append(OUString(ScResId(SCSTR_DDEDOC_NOT_LOADED))); - aBuf.appendAscii("\n\n"); - aBuf.appendAscii("Source : "); - aBuf.append(aFile); - aBuf.appendAscii("\nElement : "); - aBuf.append(aElem); - aBuf.appendAscii("\nType : "); - aBuf.append(aType); - ErrorBox aBox(pWin, WB_OK, aBuf.makeStringAndClear()); - aBox.Execute(); - } - } - } - if (bAny) - { - // Formeln berechnen und painten wie im TrackTimeHdl - TrackFormulas(); - pShell->Broadcast( SfxSimpleHint( FID_DATACHANGED ) ); - - // wenn FID_DATACHANGED irgendwann mal asynchron werden sollte - // (z.B. mit Invalidate am Window), muss hier ein Update erzwungen werden. - } - - pMgr->CloseCachedComps(); -} - -bool ScDocument::UpdateDdeLink( const OUString& rAppl, const OUString& rTopic, const OUString& rItem ) -{ - // fuer refresh() per StarOne Api - // ResetValue() fuer einzelnen Link nicht noetig - //! wenn's mal alles asynchron wird, aber auch hier - - sfx2::LinkManager* pMgr = GetDocLinkManager().getLinkManager(bAutoCalc); - if (!pMgr) - return false; - - bool bFound = false; - - const ::sfx2::SvBaseLinks& rLinks = pMgr->GetLinks(); - sal_uInt16 nCount = rLinks.size(); - for (sal_uInt16 i=0; i<nCount; i++) - { - ::sfx2::SvBaseLink* pBase = *rLinks[i]; - if (pBase->ISA(ScDdeLink)) - { - ScDdeLink* pDdeLink = (ScDdeLink*)pBase; - if ( OUString(pDdeLink->GetAppl()) == rAppl && - OUString(pDdeLink->GetTopic()) == rTopic && - OUString(pDdeLink->GetItem()) == rItem ) - { - pDdeLink->TryUpdate(); - bFound = true; // koennen theoretisch mehrere sein (Mode), darum weitersuchen - } - } - } - pMgr->CloseCachedComps(); - - return bFound; -} - -void ScDocument::DisconnectDdeLinks() -{ - sfx2::LinkManager* pMgr = GetDocLinkManager().getLinkManager(bAutoCalc); - if (!pMgr) - return; - - const ::sfx2::SvBaseLinks& rLinks = pMgr->GetLinks(); - sal_uInt16 nCount = rLinks.size(); - for (sal_uInt16 i=0; i<nCount; i++) - { - ::sfx2::SvBaseLink* pBase = *rLinks[i]; - if (pBase->ISA(ScDdeLink)) - pBase->Disconnect(); // bleibt im LinkManager eingetragen - } -} - void ScDocument::CopyDdeLinks( ScDocument* pDestDoc ) const { if (bIsClip) // aus Stream erzeugen @@ -1055,26 +905,6 @@ void ScDocument::CopyDdeLinks( ScDocument* pDestDoc ) const } } -size_t ScDocument::GetDdeLinkCount() const -{ - const sfx2::LinkManager* pMgr = GetDocLinkManager().getExistingLinkManager(); - if (!pMgr) - return 0; - - size_t nDdeCount = 0; - if (GetLinkManager()) - { - const ::sfx2::SvBaseLinks& rLinks = pMgr->GetLinks(); - size_t nCount = rLinks.size(); - for (size_t i=0; i<nCount; i++) - if ((*rLinks[i])->ISA(ScDdeLink)) - ++nDdeCount; - } - return nDdeCount; -} - -// ---------------------------------------------------------------------------- - namespace { /** Tries to find the specified DDE link. diff --git a/sc/source/ui/app/scmod.cxx b/sc/source/ui/app/scmod.cxx index 353a468..4ff50e6 100644 --- a/sc/source/ui/app/scmod.cxx +++ b/sc/source/ui/app/scmod.cxx @@ -103,6 +103,7 @@ #include "scabstdlg.hxx" #include "formula/errorcodes.hxx" #include "formulagroup.hxx" +#include <documentlinkmgr.hxx> #define SC_IDLE_MIN 150 #define SC_IDLE_MAX 3000 @@ -1948,7 +1949,8 @@ IMPL_LINK_NOARG(ScModule, IdleHandler) if (pDocSh->IsReadOnly()) bAutoSpell = false; - sal_Bool bLinks = pDoc->IdleCheckLinks(); + sc::DocumentLinkManager& rLinkMgr = pDoc->GetDocLinkManager(); + bool bLinks = rLinkMgr.idleCheckLinks(); sal_Bool bWidth = pDoc->IdleCalcTextWidth(); bMore = bLinks || bWidth; // ueberhaupt noch was? diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index 01d4736..f3e0e07 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -2563,7 +2563,7 @@ void ScDocShell::PrepareReload() // werden. Dabei verklemmt sicht dann irgendwas. // -> Beim Reload die DDE-Links des alten Dokuments vorher disconnecten - aDocument.DisconnectDdeLinks(); + aDocument.GetDocLinkManager().disconnectDdeLinks(); } diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx index 375b59d..7819fc2 100644 --- a/sc/source/ui/docshell/docsh4.cxx +++ b/sc/source/ui/docshell/docsh4.cxx @@ -96,6 +96,7 @@ using namespace ::com::sun::star; #include "sharedocdlg.hxx" #include "conditio.hxx" #include "sheetevents.hxx" +#include <documentlinkmgr.hxx> //------------------------------------------------------------------ @@ -444,7 +445,19 @@ void ScDocShell::Execute( SfxRequest& rReq ) { ReloadTabLinks(); aDocument.UpdateExternalRefLinks(GetActiveDialogParent()); - aDocument.UpdateDdeLinks(GetActiveDialogParent()); + + bool bAny = aDocument.GetDocLinkManager().updateDdeLinks(GetActiveDialogParent()); + + if (bAny) + { + // Formeln berechnen und painten wie im TrackTimeHdl + aDocument.TrackFormulas(); + Broadcast(SfxSimpleHint(FID_DATACHANGED)); + + // wenn FID_DATACHANGED irgendwann mal asynchron werden sollte + // (z.B. mit Invalidate am Window), muss hier ein Update erzwungen werden. + } + aDocument.UpdateAreaLinks(); //! Test, ob Fehler diff --git a/sc/source/ui/docshell/documentlinkmgr.cxx b/sc/source/ui/docshell/documentlinkmgr.cxx index 6ece6b4..6220c45 100644 --- a/sc/source/ui/docshell/documentlinkmgr.cxx +++ b/sc/source/ui/docshell/documentlinkmgr.cxx @@ -5,11 +5,26 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include <documentlinkmgr.hxx> #include <datastream.hxx> +#include <ddelink.hxx> +#include <sc.hrc> +#include <scresid.hxx> + #include <sfx2/linkmgr.hxx> +#include <vcl/msgbox.hxx> #include <boost/noncopyable.hpp> #include <boost/scoped_ptr.hpp> @@ -76,6 +91,153 @@ const sfx2::LinkManager* DocumentLinkManager::getExistingLinkManager() const return mpImpl->mpLinkManager.get(); } +bool DocumentLinkManager::idleCheckLinks() +{ + if (!mpImpl->mpLinkManager) + return false; + + bool bAnyLeft = false; + const sfx2::SvBaseLinks& rLinks = mpImpl->mpLinkManager->GetLinks(); + for (size_t i = 0, n = rLinks.size(); i < n; ++i) + { + sfx2::SvBaseLink* pBase = *rLinks[i]; + ScDdeLink* pDdeLink = dynamic_cast<ScDdeLink*>(pBase); + if (!pDdeLink || !pDdeLink->NeedsUpdate()) + continue; + + pDdeLink->TryUpdate(); + if (pDdeLink->NeedsUpdate()) // war nix? + bAnyLeft = true; + } + + return bAnyLeft; +} + +bool DocumentLinkManager::hasDdeLinks() const +{ + if (!mpImpl->mpLinkManager) + return false; + + const sfx2::SvBaseLinks& rLinks = mpImpl->mpLinkManager->GetLinks(); + for (size_t i = 0, n = rLinks.size(); i < n; ++i) + { + sfx2::SvBaseLink* pBase = *rLinks[i]; + if (dynamic_cast<ScDdeLink*>(pBase)) + return true; + } + + return false; +} + +bool DocumentLinkManager::updateDdeLinks( Window* pWin ) +{ + if (!mpImpl->mpLinkManager) + return false; + + sfx2::LinkManager* pMgr = mpImpl->mpLinkManager.get(); + const sfx2::SvBaseLinks& rLinks = pMgr->GetLinks(); + + // falls das Updaten laenger dauert, erstmal alle Werte + // zuruecksetzen, damit nichts altes (falsches) stehen bleibt + bool bAny = false; + for (size_t i = 0, n = rLinks.size(); i < n; ++i) + { + sfx2::SvBaseLink* pBase = *rLinks[i]; + ScDdeLink* pDdeLink = dynamic_cast<ScDdeLink*>(pBase); + if (!pDdeLink) + continue; + + if (pDdeLink->Update()) + bAny = true; + else + { + // Update failed. Notify the user. + OUString aFile = pDdeLink->GetTopic(); + OUString aElem = pDdeLink->GetItem(); + OUString aType = pDdeLink->GetAppl(); + + OUStringBuffer aBuf; + aBuf.append(OUString(ScResId(SCSTR_DDEDOC_NOT_LOADED))); + aBuf.appendAscii("\n\n"); + aBuf.appendAscii("Source : "); + aBuf.append(aFile); + aBuf.appendAscii("\nElement : "); + aBuf.append(aElem); + aBuf.appendAscii("\nType : "); + aBuf.append(aType); + ErrorBox aBox(pWin, WB_OK, aBuf.makeStringAndClear()); + aBox.Execute(); + } + } + + pMgr->CloseCachedComps(); + + return bAny; +} + +bool DocumentLinkManager::updateDdeLink( const OUString& rAppl, const OUString& rTopic, const OUString& rItem ) +{ + if (!mpImpl->mpLinkManager) + return false; + + sfx2::LinkManager* pMgr = mpImpl->mpLinkManager.get(); + const sfx2::SvBaseLinks& rLinks = pMgr->GetLinks(); + + bool bFound = false; + for (size_t i = 0, n = rLinks.size(); i < n; ++i) + { + ::sfx2::SvBaseLink* pBase = *rLinks[i]; + ScDdeLink* pDdeLink = dynamic_cast<ScDdeLink*>(pBase); + if (!pDdeLink) + continue; + + if ( OUString(pDdeLink->GetAppl()) == rAppl && + OUString(pDdeLink->GetTopic()) == rTopic && + OUString(pDdeLink->GetItem()) == rItem ) + { + pDdeLink->TryUpdate(); + bFound = true; // koennen theoretisch mehrere sein (Mode), darum weitersuchen + } + } + + return bFound; +} + +size_t DocumentLinkManager::getDdeLinkCount() const +{ + if (!mpImpl->mpLinkManager) + return 0; + + size_t nDdeCount = 0; + const sfx2::SvBaseLinks& rLinks = mpImpl->mpLinkManager->GetLinks(); + for (size_t i = 0, n = rLinks.size(); i < n; ++i) + { + ::sfx2::SvBaseLink* pBase = *rLinks[i]; + ScDdeLink* pDdeLink = dynamic_cast<ScDdeLink*>(pBase); + if (!pDdeLink) + continue; + + ++nDdeCount; + } + + return nDdeCount; +} + +void DocumentLinkManager::disconnectDdeLinks() +{ + if (!mpImpl->mpLinkManager) + return; + + const sfx2::SvBaseLinks& rLinks = mpImpl->mpLinkManager->GetLinks(); + for (size_t i = 0, n = rLinks.size(); i < n; ++i) + { + ::sfx2::SvBaseLink* pBase = *rLinks[i]; + ScDdeLink* pDdeLink = dynamic_cast<ScDdeLink*>(pBase); + if (!pDdeLink) + pDdeLink->Disconnect(); + } +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/unoobj/linkuno.cxx b/sc/source/ui/unoobj/linkuno.cxx index c30bc43..e90a641 100644 --- a/sc/source/ui/unoobj/linkuno.cxx +++ b/sc/source/ui/unoobj/linkuno.cxx @@ -33,6 +33,7 @@ #include "rangeseq.hxx" #include "token.hxx" #include "scmatrix.hxx" +#include <documentlinkmgr.hxx> #include <vector> #include <climits> @@ -1136,9 +1137,8 @@ void SAL_CALL ScDDELinkObj::refresh() throw(uno::RuntimeException) SolarMutexGuard aGuard; if (pDocShell) { - ScDocument* pDoc = pDocShell->GetDocument(); - (void)pDoc->UpdateDdeLink( aAppl, aTopic, aItem ); - //! Fehler abfragen + sc::DocumentLinkManager& rMgr = pDocShell->GetDocument()->GetDocLinkManager(); + rMgr.updateDdeLink(aAppl, aTopic, aItem); } } @@ -1300,7 +1300,7 @@ ScDDELinkObj* ScDDELinksObj::GetObjectByName_Impl(const OUString& aName) OUString aAppl, aTopic, aItem; ScDocument* pDoc = pDocShell->GetDocument(); - size_t nCount = pDoc->GetDdeLinkCount(); + size_t nCount = pDoc->GetDocLinkManager().getDdeLinkCount(); for (size_t i=0; i<nCount; i++) { pDoc->GetDdeLinkData( i, aAppl, aTopic, aItem ); @@ -1327,7 +1327,7 @@ sal_Int32 SAL_CALL ScDDELinksObj::getCount() throw(uno::RuntimeException) SolarMutexGuard aGuard; sal_Int32 nAreaCount = 0; if (pDocShell) - nAreaCount = pDocShell->GetDocument()->GetDdeLinkCount(); + nAreaCount = pDocShell->GetDocument()->GetDocLinkManager().getDdeLinkCount(); return nAreaCount; } @@ -1375,7 +1375,7 @@ uno::Sequence<OUString> SAL_CALL ScDDELinksObj::getElementNames() throw(uno::Run OUString aAppl, aTopic, aItem; ScDocument* pDoc = pDocShell->GetDocument(); - size_t nCount = pDoc->GetDdeLinkCount(); + size_t nCount = pDocShell->GetDocument()->GetDocLinkManager().getDdeLinkCount(); uno::Sequence<OUString> aSeq(nCount); OUString* pAry = aSeq.getArray(); @@ -1399,7 +1399,7 @@ sal_Bool SAL_CALL ScDDELinksObj::hasByName( const OUString& aName ) OUString aAppl, aTopic, aItem; ScDocument* pDoc = pDocShell->GetDocument(); - size_t nCount = pDoc->GetDdeLinkCount(); + size_t nCount = pDocShell->GetDocument()->GetDocLinkManager().getDdeLinkCount(); for (size_t i=0; i<nCount; i++) { pDoc->GetDdeLinkData( i, aAppl, aTopic, aItem ); diff --git a/sc/source/ui/view/tabvwsh4.cxx b/sc/source/ui/view/tabvwsh4.cxx index 0421bb7..456df66 100644 --- a/sc/source/ui/view/tabvwsh4.cxx +++ b/sc/source/ui/view/tabvwsh4.cxx @@ -84,6 +84,7 @@ #include "markdata.hxx" #include "preview.hxx" #include "docoptio.hxx" +#include <documentlinkmgr.hxx> #include <com/sun/star/document/XDocumentProperties.hpp> @@ -1652,8 +1653,11 @@ void ScTabViewShell::Construct( sal_uInt8 nForceDesignMode ) bLink = true; } if (!bLink) - if (pDoc->HasDdeLinks() || pDoc->HasAreaLinks()) - bLink = sal_True; + { + const sc::DocumentLinkManager& rMgr = pDoc->GetDocLinkManager(); + if (rMgr.hasDdeLinks() || pDoc->HasAreaLinks()) + bLink = true; + } if (bLink) { if ( !pFirst ) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits