Kaydet (Commit) fa0fe19e authored tarafından Matúš Kukan's avatar Matúš Kukan

export data streams; pretend to be an area link

Fix ScXMLExport::GetAreaLinks to not use UNO, so we can hack DataStreams
into ScMyAreaLinksContainer.
We need to connect them to cells for export / import - that does not make
sense for DataStream without any attached range. We use an arbitrary one.
But you might remove it, if you create another ScAreaLink / DataStream
with the same range, without knowing about it.

Maybe it wouldn't be that bad to let DataStream inherit from ScAreaLink.

Change-Id: I5b85a9329ba1ca46fb2893b54fe5161d2fb22f47
üst 55d6fdaf
...@@ -60,6 +60,8 @@ ...@@ -60,6 +60,8 @@
#include "stylehelper.hxx" #include "stylehelper.hxx"
#include "edittextiterator.hxx" #include "edittextiterator.hxx"
#include "editattributemap.hxx" #include "editattributemap.hxx"
#include <arealink.hxx>
#include <datastream.hxx>
#include <xmloff/xmltoken.hxx> #include <xmloff/xmltoken.hxx>
#include <xmloff/xmlnmspe.hxx> #include <xmloff/xmlnmspe.hxx>
...@@ -147,6 +149,7 @@ ...@@ -147,6 +149,7 @@
#include "XMLCodeNameProvider.hxx" #include "XMLCodeNameProvider.hxx"
#include <sfx2/linkmgr.hxx>
#include <sfx2/objsh.hxx> #include <sfx2/objsh.hxx>
#include <vector> #include <vector>
...@@ -814,37 +817,35 @@ table::CellRangeAddress ScXMLExport::GetEndAddress(const uno::Reference<sheet::X ...@@ -814,37 +817,35 @@ table::CellRangeAddress ScXMLExport::GetEndAddress(const uno::Reference<sheet::X
return aCellAddress; return aCellAddress;
} }
void ScXMLExport::GetAreaLinks( uno::Reference< sheet::XSpreadsheetDocument>& xSpreadDoc, void ScXMLExport::GetAreaLinks( ScMyAreaLinksContainer& rAreaLinks )
ScMyAreaLinksContainer& rAreaLinks )
{ {
uno::Reference< beans::XPropertySet > xPropSet( xSpreadDoc, uno::UNO_QUERY ); if (pDoc->GetLinkManager())
if( !xPropSet.is() ) return;
uno::Reference< container::XIndexAccess > xLinksIAccess( xPropSet->getPropertyValue( OUString( SC_UNO_AREALINKS ) ), uno::UNO_QUERY);
if( xLinksIAccess.is() )
{ {
const OUString sFilter( SC_UNONAME_FILTER ); const sfx2::SvBaseLinks& rLinks = pDoc->GetLinkManager()->GetLinks();
const OUString sFilterOpt( SC_UNONAME_FILTOPT ); for (size_t i = 0; i < rLinks.size(); i++)
const OUString sURL( SC_UNONAME_LINKURL );
const OUString sRefresh( SC_UNONAME_REFDELAY );
sal_Int32 nCount(xLinksIAccess->getCount());
for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex )
{ {
uno::Reference< sheet::XAreaLink > xAreaLink(xLinksIAccess->getByIndex( nIndex ), uno::UNO_QUERY); ScAreaLink *pLink = dynamic_cast<ScAreaLink*>(&(*(*rLinks[i])));
if( xAreaLink.is() ) if (pLink)
{ {
ScMyAreaLink aAreaLink; ScMyAreaLink aAreaLink;
aAreaLink.aDestRange = xAreaLink->getDestArea(); ScUnoConversion::FillApiRange( aAreaLink.aDestRange, pLink->GetDestArea() );
aAreaLink.sSourceStr = xAreaLink->getSourceArea(); aAreaLink.sSourceStr = pLink->GetSource();
uno::Reference< beans::XPropertySet > xLinkProp( xAreaLink, uno::UNO_QUERY ); aAreaLink.sFilter = pLink->GetFilter();
if( xLinkProp.is() ) aAreaLink.sFilterOptions = pLink->GetOptions();
{ aAreaLink.sURL = pLink->GetFile();
xLinkProp->getPropertyValue( sFilter ) >>= aAreaLink.sFilter; aAreaLink.nRefresh = pLink->GetTimeout();
xLinkProp->getPropertyValue( sFilterOpt ) >>= aAreaLink.sFilterOptions; rAreaLinks.AddNewAreaLink( aAreaLink );
xLinkProp->getPropertyValue( sURL ) >>= aAreaLink.sURL; }
xLinkProp->getPropertyValue( sRefresh ) >>= aAreaLink.nRefresh; DataStream *pStream = dynamic_cast<DataStream*>(&(*(*rLinks[i])));
} if (pStream)
{
ScMyAreaLink aAreaLink;
ScUnoConversion::FillApiRange( aAreaLink.aDestRange, pStream->GetRange() );
aAreaLink.sSourceStr = pStream->GetMove();
aAreaLink.sFilter = OUString::number(pStream->GetLimit());
aAreaLink.sFilterOptions = "DataStream";
aAreaLink.sURL = pStream->GetURL();
aAreaLink.nRefresh = pStream->GetSettings();
rAreaLinks.AddNewAreaLink( aAreaLink ); rAreaLinks.AddNewAreaLink( aAreaLink );
} }
} }
...@@ -1904,7 +1905,7 @@ void ScXMLExport::_ExportContent() ...@@ -1904,7 +1905,7 @@ void ScXMLExport::_ExportContent()
WriteCalculationSettings(xSpreadDoc); WriteCalculationSettings(xSpreadDoc);
sal_Int32 nTableCount(xIndex->getCount()); sal_Int32 nTableCount(xIndex->getCount());
ScMyAreaLinksContainer aAreaLinks; ScMyAreaLinksContainer aAreaLinks;
GetAreaLinks( xSpreadDoc, aAreaLinks ); GetAreaLinks( aAreaLinks );
ScMyEmptyDatabaseRangesContainer aEmptyRanges(aExportDatabaseRanges.GetEmptyDatabaseRanges()); ScMyEmptyDatabaseRangesContainer aEmptyRanges(aExportDatabaseRanges.GetEmptyDatabaseRanges());
ScMyDetectiveOpContainer aDetectiveOpContainer; ScMyDetectiveOpContainer aDetectiveOpContainer;
GetDetectiveOpList( aDetectiveOpContainer ); GetDetectiveOpList( aDetectiveOpContainer );
......
...@@ -144,7 +144,7 @@ class ScXMLExport : public SvXMLExport ...@@ -144,7 +144,7 @@ class ScXMLExport : public SvXMLExport
com::sun::star::table::CellRangeAddress GetEndAddress(const com::sun::star::uno::Reference<com::sun::star::sheet::XSpreadsheet>& xTable, com::sun::star::table::CellRangeAddress GetEndAddress(const com::sun::star::uno::Reference<com::sun::star::sheet::XSpreadsheet>& xTable,
const sal_Int32 nTable); const sal_Int32 nTable);
// ScMyEmptyDatabaseRangesContainer GetEmptyDatabaseRanges(); // ScMyEmptyDatabaseRangesContainer GetEmptyDatabaseRanges();
void GetAreaLinks( com::sun::star::uno::Reference< com::sun::star::sheet::XSpreadsheetDocument>& xSpreadDoc, ScMyAreaLinksContainer& rAreaLinks ); void GetAreaLinks( ScMyAreaLinksContainer& rAreaLinks );
void GetDetectiveOpList( ScMyDetectiveOpContainer& rDetOp ); void GetDetectiveOpList( ScMyDetectiveOpContainer& rDetOp );
void WriteSingleColumn(const sal_Int32 nRepeatColumns, const sal_Int32 nStyleIndex, void WriteSingleColumn(const sal_Int32 nRepeatColumns, const sal_Int32 nStyleIndex,
const sal_Int32 nIndex, const bool bIsAutoStyle, const bool bIsVisible); const sal_Int32 nIndex, const bool bIsAutoStyle, const bool bIsVisible);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <salhelper/thread.hxx> #include <salhelper/thread.hxx>
#include <sfx2/linkmgr.hxx> #include <sfx2/linkmgr.hxx>
#include <sfx2/viewfrm.hxx> #include <sfx2/viewfrm.hxx>
#include <arealink.hxx>
#include <asciiopt.hxx> #include <asciiopt.hxx>
#include <dbfunc.hxx> #include <dbfunc.hxx>
#include <docsh.hxx> #include <docsh.hxx>
...@@ -166,9 +167,44 @@ void DataStream::MakeToolbarVisible(ScDocShell *pShell) ...@@ -166,9 +167,44 @@ void DataStream::MakeToolbarVisible(ScDocShell *pShell)
DataStream* DataStream::Set(ScDocShell *pShell, const OUString& rURL, const OUString& rRange, DataStream* DataStream::Set(ScDocShell *pShell, const OUString& rURL, const OUString& rRange,
sal_Int32 nLimit, const OUString& rMove, sal_uInt32 nSettings) sal_Int32 nLimit, const OUString& rMove, 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.
sfx2::LinkManager* pLinkManager = pShell->GetDocument()->GetLinkManager();
ScRange aDestArea;
aDestArea.Parse(rRange, pShell->GetDocument());
sal_uInt16 nLinkPos = 0;
while (nLinkPos < pLinkManager->GetLinks().size())
{
sfx2::SvBaseLink* pBase = *pLinkManager->GetLinks()[nLinkPos];
if (rRange.isEmpty())
{
if ( (pBase->ISA(ScAreaLink) && dynamic_cast<ScAreaLink*>
(&(*pBase))->GetDestArea().aStart == aDestArea.aStart)
|| (pBase->ISA(DataStream) && dynamic_cast<DataStream*>
(&(*pBase))->GetRange().aStart == aDestArea.aStart) )
{
aDestArea.Move(0, 1, 0);
nLinkPos = 0;
continue;
}
else
++nLinkPos;
}
else if ( (pBase->ISA(ScAreaLink) && dynamic_cast<ScAreaLink*>
(&(*pBase))->GetDestArea().aStart == aDestArea.aStart)
|| (pBase->ISA(DataStream) && dynamic_cast<DataStream*>
(&(*pBase))->GetRange().aStart == aDestArea.aStart) )
{
pLinkManager->Remove( pBase );
}
else
++nLinkPos;
}
sfx2::SvBaseLink *pLink = 0; sfx2::SvBaseLink *pLink = 0;
pLink = new DataStream( pShell, rURL, rRange, nLimit, rMove, nSettings ); pLink = new DataStream( pShell, rURL, rRange, nLimit, rMove, nSettings );
sfx2::LinkManager* pLinkManager = pShell->GetDocument()->GetLinkManager();
pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, rURL, NULL, NULL ); pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, rURL, NULL, NULL );
return dynamic_cast<DataStream*>(pLink); return dynamic_cast<DataStream*>(pLink);
} }
...@@ -181,20 +217,19 @@ DataStream::DataStream(ScDocShell *pShell, const OUString& rURL, const OUString& ...@@ -181,20 +217,19 @@ DataStream::DataStream(ScDocShell *pShell, const OUString& rURL, const OUString&
, mbRunning(false) , mbRunning(false)
, mpLines(0) , mpLines(0)
, mnLinesCount(0) , mnLinesCount(0)
, mpRange(new ScRange())
, mpEndRange(NULL) , mpEndRange(NULL)
{ {
mxThread = new datastreams::CallerThread( this ); mxThread = new datastreams::CallerThread( this );
mxThread->launch(); mxThread->launch();
Decode(rURL, rRange, rMove, nSettings); Decode(rURL, rRange, nLimit, rMove, nSettings);
mpStartRange.reset( new ScRange(*mpRange.get()) ); maStartRange = maRange;
sal_Int32 nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1; sal_Int32 nHeight = maRange.aEnd.Row() - maRange.aStart.Row() + 1;
nLimit = nHeight * (nLimit / nHeight); nLimit = nHeight * (nLimit / nHeight);
if (nLimit && mpRange->aStart.Row() + nLimit - 1 < MAXROW) if (nLimit && maRange.aStart.Row() + nLimit - 1 < MAXROW)
{ {
mpEndRange.reset( new ScRange(*mpRange) ); mpEndRange.reset( new ScRange(maRange) );
mpEndRange->Move(0, nLimit - nHeight, 0); mpEndRange->Move(0, nLimit - nHeight, 0);
} }
} }
...@@ -235,28 +270,32 @@ OString DataStream::ConsumeLine() ...@@ -235,28 +270,32 @@ OString DataStream::ConsumeLine()
return mpLines->at(mnLinesCount++); return mpLines->at(mnLinesCount++);
} }
void DataStream::Decode( const OUString& rURL, const OUString& rRange, void DataStream::Decode(const OUString& rURL, const OUString& rRange,
const OUString& rMove, sal_uInt32 nSettings) const sal_Int32 nLimit, const OUString& rMove, const sal_uInt32 nSettings)
{ {
msURL = rURL;
msRange = rRange;
mnLimit = nLimit;
msMove = rMove;
mnSettings = nSettings;
maRange.Parse(msRange);
SvStream *pStream = 0; SvStream *pStream = 0;
if (nSettings & SCRIPT_STREAM) if (mnSettings & SCRIPT_STREAM)
pStream = new SvScriptStream(rURL); pStream = new SvScriptStream(msURL);
else else
pStream = new SvFileStream(rURL, STREAM_READ); pStream = new SvFileStream(msURL, STREAM_READ);
mxReaderThread = new datastreams::ReaderThread( pStream ); mxReaderThread = new datastreams::ReaderThread( pStream );
mxReaderThread->launch(); mxReaderThread->launch();
mbValuesInLine = nSettings & VALUES_IN_LINE; mbValuesInLine = mnSettings & VALUES_IN_LINE;
if (!mbValuesInLine) if (!mbValuesInLine)
return; return;
mpRange->Parse(rRange, mpScDocument); if (msMove == "NO_MOVE")
if (rMove == "NO_MOVE")
meMove = NO_MOVE; meMove = NO_MOVE;
else if (rMove == "RANGE_DOWN") else if (msMove == "RANGE_DOWN")
meMove = RANGE_DOWN; meMove = RANGE_DOWN;
else if (rMove == "MOVE_DOWN") else if (msMove == "MOVE_DOWN")
meMove = MOVE_DOWN; meMove = MOVE_DOWN;
} }
...@@ -283,17 +322,17 @@ void DataStream::MoveData() ...@@ -283,17 +322,17 @@ void DataStream::MoveData()
switch (meMove) switch (meMove)
{ {
case RANGE_DOWN: case RANGE_DOWN:
if (mpRange->aStart == mpEndRange->aStart) if (maRange.aStart == mpEndRange->aStart)
meMove = MOVE_UP; meMove = MOVE_UP;
break; break;
case MOVE_UP: case MOVE_UP:
mpScDocument->DeleteRow(*mpStartRange); mpScDocument->DeleteRow(maStartRange);
mpScDocument->InsertRow(*mpEndRange); mpScDocument->InsertRow(*mpEndRange);
break; break;
case MOVE_DOWN: case MOVE_DOWN:
if (mpEndRange.get()) if (mpEndRange.get())
mpScDocument->DeleteRow(*mpEndRange); mpScDocument->DeleteRow(*mpEndRange);
mpScDocument->InsertRow(*mpRange); mpScDocument->InsertRow(maRange);
break; break;
case NO_MOVE: case NO_MOVE:
break; break;
...@@ -306,7 +345,7 @@ bool DataStream::ImportData() ...@@ -306,7 +345,7 @@ bool DataStream::ImportData()
MoveData(); MoveData();
if (mbValuesInLine) if (mbValuesInLine)
{ {
SCROW nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1; SCROW nHeight = maRange.aEnd.Row() - maRange.aStart.Row() + 1;
OStringBuffer aBuf; OStringBuffer aBuf;
while (nHeight--) while (nHeight--)
{ {
...@@ -314,7 +353,7 @@ bool DataStream::ImportData() ...@@ -314,7 +353,7 @@ bool DataStream::ImportData()
aBuf.append('\n'); aBuf.append('\n');
} }
SvMemoryStream aMemoryStream((void *)aBuf.getStr(), aBuf.getLength(), STREAM_READ); SvMemoryStream aMemoryStream((void *)aBuf.getStr(), aBuf.getLength(), STREAM_READ);
ScImportExport aImport(mpScDocument, *mpRange); ScImportExport aImport(mpScDocument, maRange);
aImport.SetSeparator(','); aImport.SetSeparator(',');
aImport.ImportStream(aMemoryStream, OUString(), FORMAT_STRING); aImport.ImportStream(aMemoryStream, OUString(), FORMAT_STRING);
} }
...@@ -352,13 +391,13 @@ bool DataStream::ImportData() ...@@ -352,13 +391,13 @@ bool DataStream::ImportData()
if (meMove == RANGE_DOWN) if (meMove == RANGE_DOWN)
{ {
mpRange->Move(0, mpRange->aEnd.Row() - mpRange->aStart.Row() + 1, 0); maRange.Move(0, maRange.aEnd.Row() - maRange.aStart.Row() + 1, 0);
mpScDocShell->GetViewData()->GetView()->AlignToCursor( mpScDocShell->GetViewData()->GetView()->AlignToCursor(
mpRange->aStart.Col(), mpRange->aStart.Row(), SC_FOLLOW_JUMP); maRange.aStart.Col(), maRange.aStart.Row(), SC_FOLLOW_JUMP);
} }
SCROW aEndRow = mpEndRange.get() ? mpEndRange->aEnd.Row() : MAXROW; SCROW aEndRow = mpEndRange.get() ? mpEndRange->aEnd.Row() : MAXROW;
mpScDocShell->PostPaint( ScRange( mpStartRange->aStart, ScAddress( mpRange->aEnd.Col(), mpScDocShell->PostPaint( ScRange( maStartRange.aStart, ScAddress( maRange.aEnd.Col(),
aEndRow, mpRange->aStart.Tab()) ), PAINT_GRID ); aEndRow, maRange.aStart.Tab()) ), PAINT_GRID );
return mbRunning; return mbRunning;
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <rtl/ref.hxx> #include <rtl/ref.hxx>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <sfx2/lnkbase.hxx> #include <sfx2/lnkbase.hxx>
#include <address.hxx>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
...@@ -23,7 +24,6 @@ namespace datastreams { ...@@ -23,7 +24,6 @@ namespace datastreams {
} }
class ScDocShell; class ScDocShell;
class ScDocument; class ScDocument;
class ScRange;
class Window; class Window;
typedef std::vector<OString> LinesList; typedef std::vector<OString> LinesList;
...@@ -31,7 +31,8 @@ typedef std::vector<OString> LinesList; ...@@ -31,7 +31,8 @@ typedef std::vector<OString> LinesList;
class DataStream : boost::noncopyable, public sfx2::SvBaseLink class DataStream : boost::noncopyable, public sfx2::SvBaseLink
{ {
OString ConsumeLine(); OString ConsumeLine();
void Decode(const OUString& rURL, const OUString& rRange, const OUString& rMove, sal_uInt32 nSettings); void Decode(const OUString& rURL, const OUString& rRange, const sal_Int32 nLimit,
const OUString& rMove, const sal_uInt32 nSettings);
void MoveData(); void MoveData();
public: public:
...@@ -49,6 +50,11 @@ public: ...@@ -49,6 +50,11 @@ public:
const OUString& , const css::uno::Any& ) SAL_OVERRIDE; const OUString& , const css::uno::Any& ) SAL_OVERRIDE;
virtual void Edit(Window* , const Link& ) SAL_OVERRIDE; virtual void Edit(Window* , const Link& ) SAL_OVERRIDE;
const ScRange& GetRange() const { return maRange; }
const OUString& GetURL() const { return msURL; }
const sal_Int32& GetLimit() const { return mnLimit; }
const OUString& GetMove() const { return msMove; }
const sal_uInt32& GetSettings() const { return mnSettings; }
bool ImportData(); bool ImportData();
void Start(); void Start();
void Stop(); void Stop();
...@@ -56,14 +62,19 @@ public: ...@@ -56,14 +62,19 @@ public:
private: private:
ScDocShell *mpScDocShell; ScDocShell *mpScDocShell;
ScDocument *mpScDocument; ScDocument *mpScDocument;
OUString msURL;
OUString msRange;
OUString msMove;
sal_Int32 mnLimit;
sal_uInt32 mnSettings;
MoveEnum meMove; MoveEnum meMove;
bool mbRunning; bool mbRunning;
bool mbIsUndoEnabled; bool mbIsUndoEnabled;
bool mbValuesInLine; bool mbValuesInLine;
LinesList *mpLines; LinesList *mpLines;
size_t mnLinesCount; size_t mnLinesCount;
boost::scoped_ptr<ScRange> mpRange; ScRange maRange;
boost::scoped_ptr<ScRange> mpStartRange; ScRange maStartRange;
boost::scoped_ptr<ScRange> mpEndRange; boost::scoped_ptr<ScRange> mpEndRange;
rtl::Reference<datastreams::CallerThread> mxThread; rtl::Reference<datastreams::CallerThread> mxThread;
rtl::Reference<datastreams::ReaderThread> mxReaderThread; rtl::Reference<datastreams::ReaderThread> mxReaderThread;
......
...@@ -66,6 +66,7 @@ void DataStreamDlg::UpdateEnable() ...@@ -66,6 +66,7 @@ void DataStreamDlg::UpdateEnable()
m_pVclFrameLimit->Hide(); m_pVclFrameLimit->Hide();
m_pVclFrameMove->Hide(); m_pVclFrameMove->Hide();
m_pVclFrameRange->Hide(); m_pVclFrameRange->Hide();
m_pEdRange->SetText("");
} }
else else
{ {
......
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