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