diff options
Diffstat (limited to 'sc/source/ui')
-rw-r--r-- | sc/source/ui/inc/cellsh.hxx | 3 | ||||
-rw-r--r-- | sc/source/ui/inc/datastreams.hxx | 49 | ||||
-rw-r--r-- | sc/source/ui/miscdlgs/datastreams.cxx | 157 | ||||
-rw-r--r-- | sc/source/ui/miscdlgs/datastreamsdlg.cxx | 123 | ||||
-rw-r--r-- | sc/source/ui/view/cellsh.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/view/cellsh2.cxx | 4 |
6 files changed, 338 insertions, 0 deletions
diff --git a/sc/source/ui/inc/cellsh.hxx b/sc/source/ui/inc/cellsh.hxx index b44eb9f25904..d7be8ac993d7 100644 --- a/sc/source/ui/inc/cellsh.hxx +++ b/sc/source/ui/inc/cellsh.hxx @@ -33,16 +33,19 @@ class SvxClipboardFmtItem; class TransferableDataHelper; class TransferableClipboardListener; class AbstractScLinkedAreaDlg; +class DataStreams; struct CellShell_Impl { TransferableClipboardListener* m_pClipEvtLstnr; AbstractScLinkedAreaDlg* m_pLinkedDlg; + DataStreams* m_pDataStreams; SfxRequest* m_pRequest; CellShell_Impl() : m_pClipEvtLstnr( NULL ), m_pLinkedDlg( NULL ), + m_pDataStreams( NULL ), m_pRequest( NULL ) {} }; diff --git a/sc/source/ui/inc/datastreams.hxx b/sc/source/ui/inc/datastreams.hxx new file mode 100644 index 000000000000..cd8bc09962be --- /dev/null +++ b/sc/source/ui/inc/datastreams.hxx @@ -0,0 +1,49 @@ +/* -*- 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 <sal/config.h> + +#include <rtl/ref.hxx> +#include <rtl/ustring.hxx> + +#include <boost/noncopyable.hpp> +#include <boost/scoped_ptr.hpp> + +namespace datastreams { class CallerThread; } +class ScDocShell; +class ScDocument; +class ScRange; +class SvStream; +class Window; + +class DataStreams : boost::noncopyable +{ + ScDocShell *mpScDocShell; + ScDocument *mpScDocument; + bool mbMove; + bool mbRunning; + bool mbIsUndoEnabled; + boost::scoped_ptr<ScRange> mpRange; + boost::scoped_ptr<ScRange> mpEndRange; + boost::scoped_ptr<SvStream> mpStream; + rtl::Reference<datastreams::CallerThread> mxThread; + +public: + DataStreams(ScDocShell *pScDocShell); + virtual ~DataStreams(); + bool ImportData(); + void Move(); + void ShowDialog(Window *pParent); + void Start(); + void Stop(); + void Set(const OUString& rUrl, bool bIsScript, const OUString& rRange); + void SetMove(sal_Int32 nLimit); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/miscdlgs/datastreams.cxx b/sc/source/ui/miscdlgs/datastreams.cxx new file mode 100644 index 000000000000..9dd394b1cc0f --- /dev/null +++ b/sc/source/ui/miscdlgs/datastreams.cxx @@ -0,0 +1,157 @@ +/* -*- 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 <datastreams.hxx> + +#include <osl/conditn.hxx> +#include <rtl/strbuf.hxx> +#include <salhelper/thread.hxx> +#include <asciiopt.hxx> +#include <docsh.hxx> +#include <impex.hxx> + +namespace datastreams { + +class CallerThread : public salhelper::Thread +{ + DataStreams *mpDataStreams; +public: + osl::Condition maStart; + bool mbTerminate; + + CallerThread(DataStreams *pData): + Thread("CallerThread") + ,mpDataStreams(pData) + ,mbTerminate(false) + {} + +private: + virtual void execute() + { + while (!mbTerminate) + { + // wait for a small amount of time, so that + // painting methods have a chance to be called. + // And also to make UI more responsive. + TimeValue const aTime = {0, 100000}; + maStart.wait(); + maStart.reset(); + if (!mbTerminate) + while (mpDataStreams->ImportData()) + wait(aTime); + }; + } +}; + +} + +DataStreams::DataStreams(ScDocShell *pScDocShell): + mpScDocShell(pScDocShell) + , mpScDocument(mpScDocShell->GetDocument()) + , mbMove(false) +{ + mxThread = new datastreams::CallerThread( this ); + mxThread->launch(); +} + +DataStreams::~DataStreams() +{ + if (mbRunning) + Stop(); + mxThread->mbTerminate = true; + mxThread->maStart.set(); + mxThread->join(); +} + +void DataStreams::Start() +{ + mbIsUndoEnabled = mpScDocument->IsUndoEnabled(); + mpScDocument->EnableUndo(false); + mbRunning = true; + mxThread->maStart.set(); +} + +void DataStreams::Stop() +{ + mbRunning = false; + mpScDocument->EnableUndo(mbIsUndoEnabled); + mbMove = false; +} + +void DataStreams::Set(const OUString& rUrl, bool bIsScript, const OUString& rRange) +{ + mpRange.reset ( new ScRange() ); + mpRange->Parse(rRange, mpScDocument); + if (bIsScript) + mpStream.reset( new SvScriptStream(rUrl) ); + else + mpStream.reset( new SvFileStream(rUrl, STREAM_READ) ); +} + +void DataStreams::SetMove(sal_Int32 nLimit) +{ + mpEndRange.reset( NULL ); + mbMove = true; + sal_Int32 nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1; + nLimit = nHeight * (nLimit / nHeight); + if (nLimit && mpRange->aStart.Row() + nLimit - 1 < MAXROW) + { + mpEndRange.reset( new ScRange(*mpRange) ); + mpEndRange->Move(0, nLimit - nHeight, 0); + } +} + +void DataStreams::Move() +{ + if (!mbMove) + return; + if (mpEndRange.get()) + { + mpScDocument->DeleteRow(*mpEndRange); + } + mpScDocument->InsertRow(*mpRange); +} + +bool DataStreams::ImportData() +{ + if (!mpStream->good()) + { + // if there is a problem with SvStream, stop running + mbRunning = false; + return mbRunning; + } + + SolarMutexGuard aGuard; + Move(); + SCROW nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1; + OStringBuffer aBuf; + OString sTmp; + while (nHeight--) + { + mpStream->ReadLine(sTmp); + aBuf.append(sTmp); + aBuf.append('\n'); + } + SvMemoryStream aMemoryStream((void *)aBuf.getStr(), aBuf.getLength(), STREAM_READ); + ScImportExport aImport(mpScDocument, *mpRange); + aImport.SetSeparator(','); + aImport.ImportStream(aMemoryStream, OUString(), FORMAT_STRING); + // ImportStream calls PostPaint for relevant area, + // we need to call it explicitly only when moving rows. + if (!mbMove) + return mbRunning; + + SCROW aEndRow = mpEndRange.get() ? mpEndRange->aEnd.Row() : MAXROW; + mpScDocShell->PostPaint( ScRange( mpRange->aStart, ScAddress( mpRange->aEnd.Col(), + aEndRow, mpRange->aStart.Tab()) ), PAINT_GRID ); + + return mbRunning; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/miscdlgs/datastreamsdlg.cxx b/sc/source/ui/miscdlgs/datastreamsdlg.cxx new file mode 100644 index 000000000000..b2f5d275bd80 --- /dev/null +++ b/sc/source/ui/miscdlgs/datastreamsdlg.cxx @@ -0,0 +1,123 @@ +/* -*- 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 <sfx2/filedlghelper.hxx> +#include <svtools/inettbc.hxx> +#include <vcl/dialog.hxx> +#include <datastreams.hxx> + +namespace { + +class DataStreamsDlg : public ModalDialog +{ + DataStreams *mpDataStreams; + + SvtURLBox* m_pCbUrl; + PushButton* m_pBtnBrowse; + PushButton* m_pBtnStop; + RadioButton* m_pRBDirectData; + RadioButton* m_pRBScriptData; + RadioButton* m_pRBDataDown; + RadioButton* m_pRBRangeDown; + RadioButton* m_pRBNoMove; + RadioButton* m_pRBMaxLimit; + RadioButton* m_pRBUnlimited; + Edit* m_pEdRange; + Edit* m_pEdLimit; + OKButton* m_pBtnOk; + + DECL_LINK(UpdateHdl, void *); + DECL_LINK(BrowseHdl, void *); + DECL_LINK(StopHdl, void *); + + void UpdateEnable(); + +public: + DataStreamsDlg(DataStreams *pDataStreams, Window* pParent); + ~DataStreamsDlg() {} + void Start(); +}; + +DataStreamsDlg::DataStreamsDlg(DataStreams *pDataStreams, Window* pParent) + : ModalDialog(pParent, "DataStreamsDialog", "modules/scalc/ui/datastreams.ui") + , mpDataStreams(pDataStreams) +{ + get(m_pCbUrl, "url"); + get(m_pBtnBrowse, "browse"); + get(m_pBtnStop, "stop"); + get(m_pRBDirectData, "directdata"); + get(m_pRBScriptData, "scriptdata"); + get(m_pRBDataDown, "datadown"); + get(m_pRBRangeDown, "rangedown"); + get(m_pRBNoMove, "nomove"); + get(m_pRBMaxLimit, "maxlimit"); + get(m_pRBUnlimited, "unlimited"); + get(m_pEdRange, "range"); + get(m_pEdLimit, "limit"); + get(m_pBtnOk, "ok"); + + m_pCbUrl->SetSelectHdl( LINK( this, DataStreamsDlg, UpdateHdl ) ); + m_pEdRange->SetModifyHdl( LINK( this, DataStreamsDlg, UpdateHdl ) ); + m_pBtnBrowse->SetClickHdl( LINK( this, DataStreamsDlg, BrowseHdl ) ); + m_pBtnStop->SetClickHdl( LINK( this, DataStreamsDlg, StopHdl ) ); + UpdateEnable(); +} + +void DataStreamsDlg::Start() +{ + bool bIsScript = m_pRBScriptData->IsChecked(); + sal_Int32 nLimit = 0; + if (m_pRBMaxLimit->IsChecked()) + nLimit = m_pEdLimit->GetText().toInt32(); + mpDataStreams->Set(m_pCbUrl->GetText(), bIsScript, m_pEdRange->GetText(), + nLimit, m_pRBNoMove->IsChecked() ? DataStreams::NO_MOVE : + m_pRBRangeDown->IsChecked() ? DataStreams::RANGE_DOWN : DataStreams::MOVE_DOWN); + mpDataStreams->Start(); +} + +IMPL_LINK_NOARG(DataStreamsDlg, BrowseHdl) +{ + sfx2::FileDialogHelper aFileDialog(0, 0); + if ( aFileDialog.Execute() != ERRCODE_NONE ) + return 0; + + m_pCbUrl->SetText( aFileDialog.GetPath() ); + UpdateEnable(); + return 0; +} + +IMPL_LINK_NOARG(DataStreamsDlg, StopHdl) +{ + mpDataStreams->Stop(); + return 0; +} + +IMPL_LINK_NOARG(DataStreamsDlg, UpdateHdl) +{ + UpdateEnable(); + return 0; +} + +void DataStreamsDlg::UpdateEnable() +{ + bool bOk = !m_pEdRange->GetText().isEmpty(); + bOk = bOk && !m_pCbUrl->GetURL().isEmpty(); + m_pBtnOk->Enable(bOk); +} + +} + +void DataStreams::ShowDialog(Window *pParent) +{ + DataStreamsDlg aDialog(this, pParent); + if (aDialog.Execute() == RET_OK) + aDialog.Start(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx index e1ed032bcadd..943379f2d0af 100644 --- a/sc/source/ui/view/cellsh.cxx +++ b/sc/source/ui/view/cellsh.cxx @@ -55,6 +55,7 @@ #include "postit.hxx" #include "cliputil.hxx" #include "clipparam.hxx" +#include "datastreams.hxx" #include "markdata.hxx" //------------------------------------------------------------------ @@ -98,6 +99,7 @@ ScCellShell::~ScCellShell() } delete pImpl->m_pLinkedDlg; + delete pImpl->m_pDataStreams; delete pImpl->m_pRequest; delete pImpl; } diff --git a/sc/source/ui/view/cellsh2.cxx b/sc/source/ui/view/cellsh2.cxx index 12a46a8c3e87..b5d4bf7a84c8 100644 --- a/sc/source/ui/view/cellsh2.cxx +++ b/sc/source/ui/view/cellsh2.cxx @@ -56,6 +56,7 @@ #include "scabstdlg.hxx" #include "impex.hxx" #include "asciiopt.hxx" +#include "datastreams.hxx" #include "queryentry.hxx" #include "markdata.hxx" @@ -733,6 +734,9 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq ) } break; case SID_DATA_STREAMS: + if (!pImpl->m_pDataStreams) + pImpl->m_pDataStreams = new DataStreams(GetViewData()->GetDocShell()); + pImpl->m_pDataStreams->ShowDialog( pTabViewShell->GetDialogParent() ); break; case SID_MANAGE_XML_SOURCE: ExecuteXMLSourceDialog(); |