[Libreoffice-commits] core.git: Branch 'private/kohei/calc-data-stream' - sc/inc sc/Library_sc.mk sc/source
Kohei Yoshida
kohei.yoshida at collabora.com
Thu Dec 19 12:30:30 PST 2013
sc/Library_sc.mk | 2 +
sc/inc/importfilterdata.hxx | 49 ++++++++++++++++++++++++++++++++
sc/inc/xmlwrap.hxx | 6 +++
sc/source/filter/importfilterdata.cxx | 19 ++++++++++++
sc/source/filter/xml/xmlbodyi.cxx | 4 ++
sc/source/filter/xml/xmlimprt.cxx | 31 ++++++++++++++++++++
sc/source/filter/xml/xmlimprt.hxx | 27 ++++++++++++++++-
sc/source/filter/xml/xmlwrap.cxx | 9 +++++
sc/source/ui/docshell/datastream.cxx | 2 -
sc/source/ui/docshell/docsh.cxx | 34 ++++++++++++++++++++++
sc/source/ui/miscdlgs/datastreamdlg.cxx | 2 +
11 files changed, 183 insertions(+), 2 deletions(-)
New commits:
commit 2ca435ad62891627a2da68b028a10b742396c5f9
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Thu Dec 19 15:17:49 2013 -0500
Properly import data stream data from ods.
Change-Id: Iedae2226ba08c614f1b700a5444715a990899d38
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 8eeab59..11f4d06 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -269,6 +269,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
sc/source/core/tool/userlist \
sc/source/core/tool/viewopti \
sc/source/core/tool/zforauto \
+ sc/source/filter/xml/datastreamimport \
sc/source/filter/xml/XMLCalculationSettingsContext \
sc/source/filter/xml/XMLCellRangeSourceContext \
sc/source/filter/xml/XMLChangeTrackingExportHelper \
@@ -324,6 +325,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
sc/source/filter/xml/xmltabi \
sc/source/filter/xml/xmlwrap \
sc/source/filter/chart/chart_imp \
+ sc/source/filter/importfilterdata \
sc/source/ui/Accessibility/AccessibilityHints \
sc/source/ui/Accessibility/AccessibleCell \
sc/source/ui/Accessibility/AccessibleCellBase \
diff --git a/sc/inc/importfilterdata.hxx b/sc/inc/importfilterdata.hxx
new file mode 100644
index 0000000..23cef83
--- /dev/null
+++ b/sc/inc/importfilterdata.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/.
+ */
+
+#ifndef SC_IMPORTFILTERDATA_HXX
+#define SC_IMPORTFILTERDATA_HXX
+
+#include <address.hxx>
+
+#include <boost/noncopyable.hpp>
+#include <boost/scoped_ptr.hpp>
+
+namespace sc {
+
+/**
+ * Stores data imported from the file that need to be processed at the end
+ * of the import process.
+ */
+struct ImportPostProcessData : boost::noncopyable
+{
+ /**
+ * Data stream data needs to be post-processed because it requires
+ * ScDocShell instance which is not available in the filter code.
+ */
+ struct DataStream
+ {
+ enum InsertPos { InsertTop, InsertBottom };
+
+ OUString maURL;
+ ScRange maRange;
+ bool mbRefreshOnEmpty;
+ InsertPos meInsertPos;
+
+ DataStream();
+ };
+
+ boost::scoped_ptr<DataStream> mpDataStream;
+};
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/xmlwrap.hxx b/sc/inc/xmlwrap.hxx
index fb7b156..107ceb4 100644
--- a/sc/inc/xmlwrap.hxx
+++ b/sc/inc/xmlwrap.hxx
@@ -25,6 +25,8 @@
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/frame/XModel.hpp>
+#include <importfilterdata.hxx>
+
class ScDocument;
class SfxMedium;
class ScMySharedData;
@@ -44,6 +46,8 @@ namespace com { namespace sun { namespace star {
class ScXMLImportWrapper
{
+ sc::ImportPostProcessData maPostProcessData;
+
ScDocument& rDoc;
SfxMedium* pMedium;
::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > xStorage;
@@ -70,6 +74,8 @@ public:
ScXMLImportWrapper(ScDocument& rD, SfxMedium* pM, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >&);
sal_Bool Import(sal_Bool bStylesOnly, ErrCode& );
sal_Bool Export(sal_Bool bStylesOnly);
+
+ const sc::ImportPostProcessData& GetImportPostProcessData() const;
};
class ScXMLChartExportWrapper
diff --git a/sc/source/filter/importfilterdata.cxx b/sc/source/filter/importfilterdata.cxx
new file mode 100644
index 0000000..1001889
--- /dev/null
+++ b/sc/source/filter/importfilterdata.cxx
@@ -0,0 +1,19 @@
+/* -*- 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 <importfilterdata.hxx>
+
+namespace sc {
+
+ImportPostProcessData::DataStream::DataStream() :
+ mbRefreshOnEmpty(false), meInsertPos(InsertBottom) {}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/xml/xmlbodyi.cxx b/sc/source/filter/xml/xmlbodyi.cxx
index 10a0a94..2496a94 100644
--- a/sc/source/filter/xml/xmlbodyi.cxx
+++ b/sc/source/filter/xml/xmlbodyi.cxx
@@ -39,6 +39,7 @@
#include "XMLEmptyContext.hxx"
#include "scerrors.hxx"
#include "tabprotection.hxx"
+#include "datastreamimport.hxx"
#include <xmloff/xmltkmap.hxx>
#include <xmloff/xmltoken.hxx>
@@ -192,6 +193,9 @@ SvXMLImportContext *ScXMLBodyContext::CreateChildContext( sal_uInt16 nPrefix,
pContext = new ScXMLDDELinksContext ( GetScImport(), nPrefix, rLocalName,
xAttrList );
break;
+ case XML_TOK_BODY_DATA_STREAM_SOURCE:
+ pContext = new ScXMLDataStreamContext(GetScImport(), nPrefix, rLocalName, xAttrList);
+ break;
}
if( !pContext )
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index 0320be5..96be811 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -457,6 +457,7 @@ const SvXMLTokenMap& ScXMLImport::GetBodyElemTokenMap()
{ XML_NAMESPACE_TABLE, XML_DATA_PILOT_TABLES, XML_TOK_BODY_DATA_PILOT_TABLES },
{ XML_NAMESPACE_TABLE, XML_CONSOLIDATION, XML_TOK_BODY_CONSOLIDATION },
{ XML_NAMESPACE_TABLE, XML_DDE_LINKS, XML_TOK_BODY_DDE_LINKS },
+ { XML_NAMESPACE_CALC_EXT, XML_DATA_STREAM_SOURCE, XML_TOK_BODY_DATA_STREAM_SOURCE },
XML_TOKEN_MAP_END
};
@@ -1930,6 +1931,33 @@ const SvXMLTokenMap& ScXMLImport::GetCellTextSAttrTokenMap()
return *pCellTextSAttrTokenMap;
}
+const SvXMLTokenMap& ScXMLImport::GetDataStreamAttrTokenMap()
+{
+ if (!pDataStreamAttrTokenMap)
+ {
+ static const SvXMLTokenMapEntry aMap[] =
+ {
+ { XML_NAMESPACE_XLINK, XML_HREF, XML_TOK_DATA_STREAM_ATTR_URL },
+ { XML_NAMESPACE_TABLE, XML_TARGET_RANGE_ADDRESS, XML_TOK_DATA_STREAM_ATTR_RANGE },
+ { XML_NAMESPACE_CALC_EXT, XML_EMPTY_LINE_REFRESH, XML_TOK_DATA_STREAM_ATTR_EMPTY_LINE_REFRESH },
+ { XML_NAMESPACE_CALC_EXT, XML_INSERTION_POSITION, XML_TOK_DATA_STREAM_ATTR_INSERTION_POSITION },
+ XML_TOKEN_MAP_END
+ };
+ pDataStreamAttrTokenMap = new SvXMLTokenMap(aMap);
+ }
+ return *pDataStreamAttrTokenMap;
+}
+
+void ScXMLImport::SetPostProcessData( sc::ImportPostProcessData* p )
+{
+ mpPostProcessData = p;
+}
+
+sc::ImportPostProcessData* ScXMLImport::GetPostProcessData()
+{
+ return mpPostProcessData;
+}
+
SvXMLImportContext *ScXMLImport::CreateContext( sal_uInt16 nPrefix,
const OUString& rLocalName,
const uno::Reference<xml::sax::XAttributeList>& xAttrList )
@@ -2056,6 +2084,8 @@ ScXMLImport::ScXMLImport(
pCellTextSpanAttrTokenMap(NULL),
pCellTextURLAttrTokenMap(NULL),
pCellTextSAttrTokenMap(NULL),
+ pDataStreamAttrTokenMap(NULL),
+ mpPostProcessData(NULL),
aTables(*this),
pMyNamedExpressions(NULL),
pMyLabelRanges(NULL),
@@ -2197,6 +2227,7 @@ ScXMLImport::~ScXMLImport() throw()
delete pCellTextSpanAttrTokenMap;
delete pCellTextURLAttrTokenMap;
delete pCellTextSAttrTokenMap;
+ delete pDataStreamAttrTokenMap;
delete pChangeTrackingImportHelper;
delete pNumberFormatAttributesExportHelper;
diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx
index d4d45a7..f3dba75 100644
--- a/sc/source/filter/xml/xmlimprt.hxx
+++ b/sc/source/filter/xml/xmlimprt.hxx
@@ -55,6 +55,12 @@ class XMLNumberFormatAttributesExportHelper;
class ScEditEngineDefaulter;
class ScDocumentImport;
+namespace sc {
+
+struct ImportPostProcessData;
+
+}
+
enum ScXMLDocTokens
{
XML_TOK_DOC_FONTDECLS,
@@ -97,7 +103,8 @@ enum ScXMLBodyTokens
XML_TOK_BODY_DATABASE_RANGE,
XML_TOK_BODY_DATA_PILOT_TABLES,
XML_TOK_BODY_CONSOLIDATION,
- XML_TOK_BODY_DDE_LINKS
+ XML_TOK_BODY_DDE_LINKS,
+ XML_TOK_BODY_DATA_STREAM_SOURCE
};
enum ScXMLContentValidationsElemTokens
@@ -733,6 +740,17 @@ enum ScXMLCellTextSAttrTokens
XML_TOK_CELL_TEXT_S_ATTR_C
};
+/**
+ * Attribute tokens for <calcext:data-stream-source>.
+ */
+enum ScXMLDataStreamAttrTokens
+{
+ XML_TOK_DATA_STREAM_ATTR_URL,
+ XML_TOK_DATA_STREAM_ATTR_RANGE,
+ XML_TOK_DATA_STREAM_ATTR_EMPTY_LINE_REFRESH,
+ XML_TOK_DATA_STREAM_ATTR_INSERTION_POSITION
+};
+
class SvXMLTokenMap;
class XMLShapeImportHelper;
class ScXMLChangeTrackingImportHelper;
@@ -907,6 +925,9 @@ class ScXMLImport: public SvXMLImport, boost::noncopyable
SvXMLTokenMap *pCellTextSpanAttrTokenMap;
SvXMLTokenMap *pCellTextURLAttrTokenMap;
SvXMLTokenMap *pCellTextSAttrTokenMap;
+ SvXMLTokenMap *pDataStreamAttrTokenMap;
+
+ sc::ImportPostProcessData* mpPostProcessData; /// Lift cycle managed elsewhere, no need to delete.
ScMyTables aTables;
@@ -1076,6 +1097,10 @@ public:
const SvXMLTokenMap& GetCellTextSpanAttrTokenMap();
const SvXMLTokenMap& GetCellTextURLAttrTokenMap();
const SvXMLTokenMap& GetCellTextSAttrTokenMap();
+ const SvXMLTokenMap& GetDataStreamAttrTokenMap();
+
+ void SetPostProcessData( sc::ImportPostProcessData* p );
+ sc::ImportPostProcessData* GetPostProcessData();
void AddNamedExpression(ScMyNamedExpression* pMyNamedExpression)
{
diff --git a/sc/source/filter/xml/xmlwrap.cxx b/sc/source/filter/xml/xmlwrap.cxx
index ef38f08..4e2ef7d 100644
--- a/sc/source/filter/xml/xmlwrap.cxx
+++ b/sc/source/filter/xml/xmlwrap.cxx
@@ -174,6 +174,10 @@ sal_uInt32 ScXMLImportWrapper::ImportFromComponent(const uno::Reference<uno::XCo
if (xImporter.is())
xImporter->setTargetDocument( xComponent );
+ ScXMLImport* pImporterImpl = dynamic_cast<ScXMLImport*>(xImporter.get());
+ if (pImporterImpl)
+ pImporterImpl->SetPostProcessData(&maPostProcessData);
+
// connect parser and filter
xParser->setDocumentHandler( xDocHandler );
@@ -992,5 +996,10 @@ sal_Bool ScXMLImportWrapper::Export(sal_Bool bStylesOnly)
return false;
}
+const sc::ImportPostProcessData& ScXMLImportWrapper::GetImportPostProcessData() const
+{
+ return maPostProcessData;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/docshell/datastream.cxx b/sc/source/ui/docshell/datastream.cxx
index edd0e2a..493b922 100644
--- a/sc/source/ui/docshell/datastream.cxx
+++ b/sc/source/ui/docshell/datastream.cxx
@@ -288,7 +288,7 @@ void DataStream::Decode(const OUString& rURL, const ScRange& rRange,
meOrigMove = eMove;
mnSettings = nSettings;
- mbValuesInLine = mnSettings & VALUES_IN_LINE;
+ mbValuesInLine = true; // always true.
mnCurRow = rRange.aStart.Row();
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index ca39e78..3e18270 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -119,6 +119,8 @@
#include "dpobject.hxx"
#include "markdata.hxx"
#include "orcusfilters.hxx"
+#include <datastream.hxx>
+#include <documentlinkmgr.hxx>
#include <config_telepathy.h>
@@ -400,6 +402,36 @@ private:
ScDocument* mpDoc;
};
+void processDataStream( ScDocShell& rShell, const sc::ImportPostProcessData& rData )
+{
+ if (!rData.mpDataStream)
+ return;
+
+ const sc::ImportPostProcessData::DataStream& r = *rData.mpDataStream;
+ if (!r.maRange.IsValid())
+ return;
+
+ // Break the streamed range into the top range and the height limit. A
+ // height limit of 0 means unlimited i.e. the streamed data will go all
+ // the way to the last row.
+
+ ScRange aTopRange = r.maRange;
+ aTopRange.aEnd.SetRow(aTopRange.aStart.Row());
+ sal_Int32 nLimit = r.maRange.aEnd.Row() - r.maRange.aStart.Row() + 1;
+ if (r.maRange.aEnd.Row() == MAXROW)
+ // Unlimited range.
+ nLimit = 0;
+
+ sc::DataStream::MoveType eMove =
+ r.meInsertPos == sc::ImportPostProcessData::DataStream::InsertTop ?
+ sc::DataStream::MOVE_DOWN : sc::DataStream::RANGE_DOWN;
+
+ sc::DataStream* pStrm = new sc::DataStream(&rShell, r.maURL, aTopRange, nLimit, eMove, 0);
+ pStrm->SetRefreshOnEmptyLine(r.mbRefreshOnEmpty);
+ sc::DocumentLinkManager& rMgr = rShell.GetDocument()->GetDocLinkManager();
+ rMgr.setDataStream(pStrm);
+}
+
}
sal_Bool ScDocShell::LoadXML( SfxMedium* pLoadMedium, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStor )
@@ -430,6 +462,8 @@ sal_Bool ScDocShell::LoadXML( SfxMedium* pLoadMedium, const ::com::sun::star::un
if ( nError )
pLoadMedium->SetError( nError, OUString( OSL_LOG_PREFIX ) );
+ processDataStream(*this, aImport.GetImportPostProcessData());
+
//if the document was not generated by LibreOffice, do hard recalc in case some other document
//generator saved cached formula results that differ from LibreOffice's calculated results or
//did not use cached formula results.
diff --git a/sc/source/ui/miscdlgs/datastreamdlg.cxx b/sc/source/ui/miscdlgs/datastreamdlg.cxx
index cc58195..8a3bee5 100644
--- a/sc/source/ui/miscdlgs/datastreamdlg.cxx
+++ b/sc/source/ui/miscdlgs/datastreamdlg.cxx
@@ -150,6 +150,8 @@ void DataStreamDlg::Init( const DataStream& rStrm )
;
}
+ m_pCBRefreshOnEmpty->Check(rStrm.IsRefreshOnEmptyLine());
+
UpdateEnable();
}
More information about the Libreoffice-commits
mailing list