From a17794d5fa8d6757a1f3caff7d9428720c0a357e Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Wed, 18 Dec 2013 23:51:27 -0500 Subject: Switch away from using the sfx2 link manager for data stream. Change-Id: I05ac5a8151135ace7f4e351cfedab0170c8d9a57 --- sc/source/ui/docshell/datastream.cxx | 88 ++----------------------------- sc/source/ui/docshell/documentlinkmgr.cxx | 44 ++++++++++++++++ sc/source/ui/inc/datastream.hxx | 11 +--- sc/source/ui/view/cellsh2.cxx | 52 ++++++++---------- 4 files changed, 73 insertions(+), 122 deletions(-) create mode 100644 sc/source/ui/docshell/documentlinkmgr.cxx (limited to 'sc/source/ui') diff --git a/sc/source/ui/docshell/datastream.cxx b/sc/source/ui/docshell/datastream.cxx index c506ee407ded..5b1b9dd04832 100644 --- a/sc/source/ui/docshell/datastream.cxx +++ b/sc/source/ui/docshell/datastream.cxx @@ -16,18 +16,14 @@ #include #include #include -#include #include -#include #include -#include #include -#include -#include #include #include #include #include +#include #include @@ -189,46 +185,9 @@ DataStream* DataStream::Set( ScDocShell *pShell, const OUString& rURL, const ScRange& rRange, sal_Int32 nLimit, MoveType eMove, sal_uInt32 nSettings) { - // Each DataStream needs a destination area in order to be exported. - // There can be only one ScAreaLink / DataStream per cell. - // So - if we don't need range (DataStream with mbValuesInLine == false), - // just find a free cell for now. - ScRange aDestArea; - if (rRange.IsValid()) - aDestArea = rRange; - - sfx2::LinkManager* pLinkManager = pShell->GetDocument()->GetLinkManager(); - sal_uInt16 nLinkPos = 0; - while (nLinkPos < pLinkManager->GetLinks().size()) - { - sfx2::SvBaseLink* pBase = *pLinkManager->GetLinks()[nLinkPos]; - if (!rRange.IsValid()) - { - if ( (pBase->ISA(ScAreaLink) && static_cast - (&(*pBase))->GetDestArea().aStart == aDestArea.aStart) - || (pBase->ISA(DataStream) && static_cast - (&(*pBase))->GetRange().aStart == aDestArea.aStart) ) - { - aDestArea.Move(0, 1, 0); - nLinkPos = 0; - continue; - } - else - ++nLinkPos; - } - else if ( (pBase->ISA(ScAreaLink) && static_cast - (&(*pBase))->GetDestArea().aStart == aDestArea.aStart) - || (pBase->ISA(DataStream) && static_cast - (&(*pBase))->GetRange().aStart == aDestArea.aStart) ) - { - pLinkManager->Remove( pBase ); - } - else - ++nLinkPos; - } - - DataStream* pLink = new DataStream(pShell, rURL, aDestArea, nLimit, eMove, nSettings); - pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, rURL, NULL, NULL ); + DataStream* pLink = new DataStream(pShell, rURL, rRange, nLimit, eMove, nSettings); + sc::DocumentLinkManager& rMgr = pShell->GetDocument()->GetDocLinkManager(); + rMgr.setDataStream(pLink); return pLink; } @@ -435,12 +394,6 @@ void DataStream::MoveData() } } -IMPL_LINK_NOARG(DataStream, RefreshHdl) -{ - ImportData(); - return 0; -} - #if ENABLE_ORCUS namespace { @@ -573,39 +526,6 @@ bool DataStream::ImportData() return mbRunning; } -sfx2::SvBaseLink::UpdateResult DataStream::DataChanged( - const OUString& , const css::uno::Any& ) -{ - MakeToolbarVisible(); - StopImport(); - bool bStart = true; - if (mnSettings & SCRIPT_STREAM && !mxReaderThread.is() && - officecfg::Office::Common::Security::Scripting::MacroSecurityLevel::get() >= 1) - { - MessageDialog aQBox( NULL, "QueryRunStreamScriptDialog", "modules/scalc/ui/queryrunstreamscriptdialog.ui"); - aQBox.set_primary_text( aQBox.get_primary_text().replaceFirst("%URL", msURL) ); - if (RET_YES != aQBox.Execute()) - bStart = false; - } - if (bStart) - StartImport(); - return SUCCESS; -} - -void DataStream::Edit( Window* pWindow, const Link& ) -{ - DataStreamDlg aDialog(mpDocShell, pWindow); - aDialog.Init(msURL, maStartRange, mnLimit, meMove, mnSettings); - if (aDialog.Execute() == RET_OK) - { - bool bWasRunning = mbRunning; - StopImport(); - aDialog.StartStream(this); - if (bWasRunning) - StartImport(); - } -} - } // namespace sc /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/docshell/documentlinkmgr.cxx b/sc/source/ui/docshell/documentlinkmgr.cxx new file mode 100644 index 000000000000..2b9998f96244 --- /dev/null +++ b/sc/source/ui/docshell/documentlinkmgr.cxx @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * 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/. + */ + +#include +#include + +#include +#include + +namespace sc { + +struct DocumentLinkManagerImpl : boost::noncopyable +{ + boost::scoped_ptr mpDataStream; + + DocumentLinkManagerImpl() : mpDataStream(NULL) {} +}; + +DocumentLinkManager::DocumentLinkManager() : mpImpl(new DocumentLinkManagerImpl) {} + +void DocumentLinkManager::setDataStream( DataStream* p ) +{ + mpImpl->mpDataStream.reset(p); +} + +DataStream* DocumentLinkManager::getDataStream() +{ + return mpImpl->mpDataStream.get(); +} + +const DataStream* DocumentLinkManager::getDataStream() const +{ + return mpImpl->mpDataStream.get(); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/datastream.hxx b/sc/source/ui/inc/datastream.hxx index 1cde20e69b9a..935e89547118 100644 --- a/sc/source/ui/inc/datastream.hxx +++ b/sc/source/ui/inc/datastream.hxx @@ -14,14 +14,12 @@ #include #include -#include #include #include #include #include -#include #include class ScDocShell; @@ -37,12 +35,11 @@ namespace datastreams { typedef std::vector LinesList; -class DataStream : boost::noncopyable, public sfx2::SvBaseLink +class DataStream : boost::noncopyable { OString ConsumeLine(); void MoveData(); void Text2Doc(); - DECL_LINK( RefreshHdl, void* ); public: enum MoveType { NO_MOVE, RANGE_DOWN, MOVE_DOWN, MOVE_UP }; @@ -58,11 +55,7 @@ public: ScDocShell *pShell, const OUString& rURL, const ScRange& rRange, sal_Int32 nLimit, MoveType eMove, sal_uInt32 nSettings); - virtual ~DataStream(); - // sfx2::SvBaseLink - virtual sfx2::SvBaseLink::UpdateResult DataChanged( - const OUString& , const css::uno::Any& ) SAL_OVERRIDE; - virtual void Edit(Window* , const Link& ) SAL_OVERRIDE; + ~DataStream(); ScRange GetRange() const; const OUString& GetURL() const { return msURL; } diff --git a/sc/source/ui/view/cellsh2.cxx b/sc/source/ui/view/cellsh2.cxx index 9cba2015d26f..b55e00cb15ff 100644 --- a/sc/source/ui/view/cellsh2.cxx +++ b/sc/source/ui/view/cellsh2.cxx @@ -20,7 +20,6 @@ #include "scitems.hxx" #include #include -#include #include #include #include @@ -62,6 +61,7 @@ #include "datastreamdlg.hxx" #include "queryentry.hxx" #include "markdata.hxx" +#include #include @@ -742,36 +742,30 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq ) } break; case SID_DATA_STREAMS: - { - sc::DataStreamDlg aDialog( GetViewData()->GetDocShell(), pTabViewShell->GetDialogParent() ); - if (aDialog.Execute() == RET_OK) - aDialog.StartStream(); - } - break; + { + sc::DataStreamDlg aDialog( GetViewData()->GetDocShell(), pTabViewShell->GetDialogParent() ); + if (aDialog.Execute() == RET_OK) + aDialog.StartStream(); + } + break; case SID_DATA_STREAMS_PLAY: - { - ScDocument *pDoc = GetViewData()->GetDocument(); - if (pDoc->GetLinkManager()) - { - const sfx2::SvBaseLinks& rLinks = pDoc->GetLinkManager()->GetLinks(); - for (size_t i = 0; i < rLinks.size(); i++) - if (sc::DataStream *pStream = dynamic_cast(&(*(*rLinks[i])))) - pStream->StartImport(); - } - } - break; + { + ScDocument *pDoc = GetViewData()->GetDocument(); + sc::DocumentLinkManager& rMgr = pDoc->GetDocLinkManager(); + sc::DataStream* pStrm = rMgr.getDataStream(); + if (pStrm) + pStrm->StartImport(); + } + break; case SID_DATA_STREAMS_STOP: - { - ScDocument *pDoc = GetViewData()->GetDocument(); - if (pDoc->GetLinkManager()) - { - const sfx2::SvBaseLinks& rLinks = pDoc->GetLinkManager()->GetLinks(); - for (size_t i = 0; i < rLinks.size(); i++) - if (sc::DataStream *pStream = dynamic_cast(&(*(*rLinks[i])))) - pStream->StopImport(); - } - } - break; + { + ScDocument *pDoc = GetViewData()->GetDocument(); + sc::DocumentLinkManager& rMgr = pDoc->GetDocLinkManager(); + sc::DataStream* pStrm = rMgr.getDataStream(); + if (pStrm) + pStrm->StopImport(); + } + break; case SID_MANAGE_XML_SOURCE: ExecuteXMLSourceDialog(); break; -- cgit