[Libreoffice-commits] .: sc/source
Kohei Yoshida
kohei at kemper.freedesktop.org
Tue Jun 7 21:30:26 PDT 2011
sc/source/filter/xml/xmlimprt.cxx | 82 ++++++++++++++++++++++++++++++++++++++
sc/source/filter/xml/xmlimprt.hxx | 8 +++
sc/source/filter/xml/xmlnexpi.cxx | 37 +----------------
sc/source/filter/xml/xmlnexpi.hxx | 7 +--
sc/source/filter/xml/xmltabi.cxx | 16 +------
5 files changed, 101 insertions(+), 49 deletions(-)
New commits:
commit 8c02d7e41b5406471ede62099fceac5c8ce17fe4
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Wed Jun 8 00:28:35 2011 -0400
fdo#37947: Correctly import sheet-local named ranges.
The key is to temporarily store all sheet-local named range data,
and insert them en masse after importing the sheet contents fully.
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index c967397..aedb799 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -95,6 +95,8 @@
#include <com/sun/star/io/XSeekable.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
+#include <memory>
+
#define SC_LOCALE "Locale"
#define SC_STANDARDFORMAT "StandardFormat"
#define SC_CURRENCYSYMBOL "CurrencySymbol"
@@ -2036,6 +2038,25 @@ sal_Bool ScXMLImport::GetValidation(const rtl::OUString& sName, ScMyImportValida
return false;
}
+void ScXMLImport::AddNamedExpression(SCTAB nTab, ScMyNamedExpression* pNamedExp)
+{
+ ::std::auto_ptr<ScMyNamedExpression> p(pNamedExp);
+ SheetNamedExpMap::iterator itr = maSheetNamedExpressions.find(nTab);
+ if (itr == maSheetNamedExpressions.end())
+ {
+ // No chain exists for this sheet. Create one.
+ ::std::auto_ptr<ScMyNamedExpressions> pNew(new ScMyNamedExpressions);
+ ::std::pair<SheetNamedExpMap::iterator, bool> r = maSheetNamedExpressions.insert(nTab, pNew);
+ if (!r.second)
+ // insertion failed.
+ return;
+
+ itr = r.first;
+ }
+ ScMyNamedExpressions& r = *itr->second;
+ r.push_back(p);
+}
+
ScXMLChangeTrackingImportHelper* ScXMLImport::GetChangeTrackingImportHelper()
{
if (!pChangeTrackingImportHelper)
@@ -2850,6 +2871,66 @@ void ScXMLImport::SetNamedRanges()
}
}
+namespace {
+
+class SheetRangeNameInserter : public ::std::unary_function<ScMyNamedExpression, void>
+{
+ ScDocument* mpDoc;
+ ScRangeName& mrRangeName;
+public:
+ SheetRangeNameInserter(ScDocument* pDoc, ScRangeName& rRangeName) :
+ mpDoc(pDoc), mrRangeName(rRangeName) {}
+
+ void operator() (const ScMyNamedExpression& r) const
+ {
+ using namespace formula;
+
+ if (r.sRangeType.getLength() > 0)
+ // For now, we only accept normal named expressions.
+ return;
+
+ if (mpDoc && !mrRangeName.findByName(r.sName))
+ {
+ // Insert a new name.
+ ScAddress aPos;
+ sal_Int32 nOffset = 0;
+ bool bSuccess = ScRangeStringConverter::GetAddressFromString(
+ aPos, r.sBaseCellAddress, mpDoc, FormulaGrammar::CONV_OOO, nOffset);
+
+ if (bSuccess)
+ {
+ ::rtl::OUString aContent = r.sContent;
+ if (!r.bIsExpression)
+ ScXMLConverter::ParseFormula(aContent, false);
+
+ ScRangeData* pData = new ScRangeData(
+ mpDoc, r.sName, r.sContent, aPos, RT_NAME, r.eGrammar);
+ mrRangeName.insert(pData);
+ }
+ }
+ }
+};
+
+}
+
+void ScXMLImport::SetSheetNamedRanges()
+{
+ if (!pDoc)
+ return;
+
+ SheetNamedExpMap::const_iterator itr = maSheetNamedExpressions.begin(), itrEnd = maSheetNamedExpressions.end();
+ for (; itr != itrEnd; ++itr)
+ {
+ SCTAB nTab = itr->first;
+ ScRangeName* pRangeNames = pDoc->GetRangeName(nTab);
+ if (!pRangeNames)
+ continue;
+
+ const ScMyNamedExpressions& rNames = *itr->second;
+ ::std::for_each(rNames.begin(), rNames.end(), SheetRangeNameInserter(pDoc, *pRangeNames));
+ }
+}
+
void SAL_CALL ScXMLImport::endDocument(void)
throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException )
{
@@ -2891,6 +2972,7 @@ throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeE
}
SetLabelRanges();
SetNamedRanges();
+ SetSheetNamedRanges();
}
GetProgressBarHelper()->End(); // make room for subsequent SfxProgressBars
if (pDoc)
diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx
index cdde3be..20ae685 100644
--- a/sc/source/filter/xml/xmlimprt.hxx
+++ b/sc/source/filter/xml/xmlimprt.hxx
@@ -55,6 +55,7 @@
#include <vector>
#include <boost/unordered_map.hpp>
#include <boost/ptr_container/ptr_list.hpp>
+#include <boost/ptr_container/ptr_map.hpp>
class ScRangeList;
class ScMyStyleNumberFormats;
@@ -674,6 +675,8 @@ class ScMyStylesImportHelper;
class ScXMLImport: public SvXMLImport
{
typedef ::boost::unordered_map< ::rtl::OUString, sal_Int16, ::rtl::OUStringHash > CellTypeMap;
+ typedef ::boost::ptr_map<SCTAB, ScMyNamedExpressions> SheetNamedExpMap;
+
CellTypeMap aCellTypeMap;
ScDocument* pDoc;
@@ -763,6 +766,8 @@ class ScXMLImport: public SvXMLImport
ScMyTables aTables;
ScMyNamedExpressions* pMyNamedExpressions;
+ SheetNamedExpMap maSheetNamedExpressions;
+
ScMyLabelRanges* pMyLabelRanges;
ScMyImportValidations* pValidations;
ScMyImpDetectiveOpArray* pDetectiveOpArray;
@@ -918,6 +923,8 @@ public:
ScMyNamedExpressions* GetNamedExpressions() { return pMyNamedExpressions; }
+ void AddNamedExpression(SCTAB nTab, ScMyNamedExpression* pNamedExp);
+
void AddLabelRange(const ScMyLabelRange* pMyLabelRange) {
if (!pMyLabelRanges)
pMyLabelRanges = new ScMyLabelRanges();
@@ -1006,6 +1013,7 @@ public:
sal_Int32 GetRangeType(const rtl::OUString sRangeType) const;
void SetNamedRanges();
+ void SetSheetNamedRanges();
void SetLabelRanges();
void AddDefaultNote( const com::sun::star::table::CellAddress& aCell );
diff --git a/sc/source/filter/xml/xmlnexpi.cxx b/sc/source/filter/xml/xmlnexpi.cxx
index ce33d78..fcb02bd 100644
--- a/sc/source/filter/xml/xmlnexpi.cxx
+++ b/sc/source/filter/xml/xmlnexpi.cxx
@@ -36,16 +36,11 @@
#include "xmlimprt.hxx"
#include "xmlcelli.hxx"
#include "docuno.hxx"
-#include "global.hxx"
#include "document.hxx"
-#include "XMLConverter.hxx"
-#include "rangeutl.hxx"
#include <xmloff/xmltkmap.hxx>
#include <xmloff/nmspmap.hxx>
-#include <boost/scoped_ptr.hpp>
-
using namespace com::sun::star;
//------------------------------------------------------------------
@@ -58,38 +53,12 @@ void ScXMLNamedExpressionsContext::GlobalInserter::insert(ScMyNamedExpression* p
mrImport.AddNamedExpression(pExp);
}
-ScXMLNamedExpressionsContext::SheetLocalInserter::SheetLocalInserter(
- ScDocument* pDoc, ScRangeName& rRangeName) : mpDoc(pDoc), mrRangeName(rRangeName) {}
+ScXMLNamedExpressionsContext::SheetLocalInserter::SheetLocalInserter(ScXMLImport& rImport, SCTAB nTab) :
+ mrImport(rImport), mnTab(nTab) {}
void ScXMLNamedExpressionsContext::SheetLocalInserter::insert(ScMyNamedExpression* pExp)
{
- using namespace formula;
-
- ::boost::scoped_ptr<ScMyNamedExpression> p(pExp);
-
- if (p->sRangeType.getLength() > 0)
- // For now, we only accept normal named expressions.
- return;
-
- if (mpDoc && !mrRangeName.findByName(p->sName))
- {
- // Insert a new name.
- ScAddress aPos;
- sal_Int32 nOffset = 0;
- bool bSuccess = ScRangeStringConverter::GetAddressFromString(
- aPos, p->sBaseCellAddress, mpDoc, FormulaGrammar::CONV_OOO, nOffset);
-
- if (bSuccess)
- {
- ::rtl::OUString aContent = p->sContent;
- if (!p->bIsExpression)
- ScXMLConverter::ParseFormula(aContent, false);
-
- ScRangeData* pData = new ScRangeData(
- mpDoc, p->sName, p->sContent, aPos, RT_NAME, p->eGrammar);
- mrRangeName.insert(pData);
- }
- }
+ mrImport.AddNamedExpression(mnTab, pExp);
}
ScXMLNamedExpressionsContext::ScXMLNamedExpressionsContext(
diff --git a/sc/source/filter/xml/xmlnexpi.hxx b/sc/source/filter/xml/xmlnexpi.hxx
index d66881a..71355c2 100644
--- a/sc/source/filter/xml/xmlnexpi.hxx
+++ b/sc/source/filter/xml/xmlnexpi.hxx
@@ -30,6 +30,7 @@
#include <xmloff/xmlictxt.hxx>
#include <xmloff/xmlimp.hxx>
+#include "address.hxx"
#include <boost/shared_ptr.hpp>
@@ -72,11 +73,11 @@ public:
class SheetLocalInserter : public Inserter
{
public:
- SheetLocalInserter(ScDocument* pDoc, ScRangeName& rRangeName);
+ SheetLocalInserter(ScXMLImport& rImport, SCTAB nTab);
virtual void insert(ScMyNamedExpression* pExp);
private:
- ScDocument* mpDoc;
- ScRangeName& mrRangeName;
+ ScXMLImport& mrImport;
+ SCTAB mnTab;
};
ScXMLNamedExpressionsContext(
diff --git a/sc/source/filter/xml/xmltabi.cxx b/sc/source/filter/xml/xmltabi.cxx
index de55886..6daf2d6 100644
--- a/sc/source/filter/xml/xmltabi.cxx
+++ b/sc/source/filter/xml/xmltabi.cxx
@@ -282,18 +282,10 @@ SvXMLImportContext *ScXMLTableContext::CreateChildContext( sal_uInt16 nPrefix,
{
case XML_TOK_TABLE_NAMED_EXPRESSIONS:
{
- ScDocument* pDoc = GetScImport().GetDocument();
- if (pDoc)
- {
- SCTAB nTab = GetScImport().GetTables().GetCurrentSheet();
- ScRangeName* pRN = pDoc->GetRangeName(nTab);
- if (pRN)
- {
- pContext = new ScXMLNamedExpressionsContext(
- GetScImport(), nPrefix, rLName, xAttrList,
- new ScXMLNamedExpressionsContext::SheetLocalInserter(pDoc, *pRN));
- }
- }
+ SCTAB nTab = GetScImport().GetTables().GetCurrentSheet();
+ pContext = new ScXMLNamedExpressionsContext(
+ GetScImport(), nPrefix, rLName, xAttrList,
+ new ScXMLNamedExpressionsContext::SheetLocalInserter(GetScImport(), nTab));
}
break;
case XML_TOK_TABLE_COL_GROUP:
More information about the Libreoffice-commits
mailing list