Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


the attached patch is a squash ( and conflict fix ) of

http://cgit.freedesktop.org/libreoffice/core/commit/?id=7539a695b801b92d10ff30463a8c08672a258442

http://cgit.freedesktop.org/libreoffice/core/commit/?id=67cde863f63725cb25d69c38d1b74a8d2bfaf9a7
From 18dc6c39cb85dccab5070b8c0709dcc02df52c73 Mon Sep 17 00:00:00 2001
From: Noel Power <noel.power@suse.com>
Date: Thu, 20 Sep 2012 15:05:00 +0100
Subject: [PATCH] xlsx fix cyclic referenced defined names partially fixes bnc#780296 bnc#781166

Change-Id: Ibad37ac05c608c0211063bfa73931427d48c11f9

Use scoped_ptr instead of deprecated auto_ptr

Change-Id: I87e5000424bed95fd25951b398bd61c3939a97ae
---
 sc/inc/rangenam.hxx                     |    3 +-
 sc/source/core/tool/rangenam.cxx        |   37 +++++++++++++++++++++----------
 sc/source/filter/oox/defnamesbuffer.cxx |   13 +++++++++-
 3 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/sc/inc/rangenam.hxx b/sc/inc/rangenam.hxx
index dfb7d9e..d1bd54d 100644
--- a/sc/inc/rangenam.hxx
+++ b/sc/inc/rangenam.hxx
@@ -89,7 +89,7 @@ private:
     ScRangeData( sal_uInt16 nIndex );
 
     void CompileRangeData( const String& rSymbol, bool bSetError );
-
+    void InitCode();
 public:
     typedef ::std::map<sal_uInt16, sal_uInt16> IndexMap;
 
@@ -122,6 +122,7 @@ public:
     void            SetIndex( sal_uInt16 nInd )         { nIndex = nInd; }
     sal_uInt16    GetIndex() const                { return nIndex; }
     ScTokenArray*   GetCode()                       { return pCode; }
+    SC_DLLPUBLIC void   SetCode( ScTokenArray& );
     const ScTokenArray* GetCode() const             { return pCode; }
     SC_DLLPUBLIC sal_uInt16 GetErrCode() const;
     bool            HasReferences() const;
diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx
index e671585..d9eea00 100644
--- a/sc/source/core/tool/rangenam.cxx
+++ b/sc/source/core/tool/rangenam.cxx
@@ -32,6 +32,7 @@
 
 #include <string.h>
 #include <memory>
+#include <boost/scoped_ptr.hpp>
 #include <unotools/collatorwrapper.hxx>
 #include <unotools/transliterationwrapper.hxx>
 #include <com/sun/star/sheet/NamedRangeFlag.hpp>
@@ -110,18 +111,7 @@ ScRangeData::ScRangeData( ScDocument* pDok,
                 mnMaxRow    (-1),
                 mnMaxCol    (-1)
 {
-    if( !pCode->GetCodeError() )
-    {
-        pCode->Reset();
-        FormulaToken* p = pCode->GetNextReference();
-        if( p )// genau eine Referenz als erstes
-        {
-            if( p->GetType() == svSingleRef )
-                eType = eType | RT_ABSPOS;
-            else
-                eType = eType | RT_ABSAREA;
-        }
-    }
+    InitCode();
 }
 
 ScRangeData::ScRangeData( ScDocument* pDok,
@@ -684,6 +674,29 @@ void ScRangeData::ValidateTabRefs()
     }
 }
 
+void ScRangeData::SetCode( ScTokenArray& rArr )
+{
+    boost::scoped_ptr<ScTokenArray> pOldCode( pCode); // old pCode will be deleted
+    pCode = new ScTokenArray( rArr );
+    InitCode();
+}
+
+void ScRangeData::InitCode()
+{
+    if( !pCode->GetCodeError() )
+    {
+        pCode->Reset();
+        FormulaToken* p = pCode->GetNextReference();
+        if( p )   // exact one reference at first
+        {
+            if( p->GetType() == svSingleRef )
+                eType = eType | RT_ABSPOS;
+            else
+                eType = eType | RT_ABSAREA;
+        }
+    }
+}
+
 
 extern "C"
 int SAL_CALL ScRangeData_QsortNameCompare( const void* p1, const void* p2 )
diff --git a/sc/source/filter/oox/defnamesbuffer.cxx b/sc/source/filter/oox/defnamesbuffer.cxx
index 4eafab7..2cf0c00 100644
--- a/sc/source/filter/oox/defnamesbuffer.cxx
+++ b/sc/source/filter/oox/defnamesbuffer.cxx
@@ -382,9 +382,9 @@ void DefinedName::createNameObject( sal_Int32 nIndex )
 
     // create the name and insert it into the document, maCalcName will be changed to the 
resulting name
     if (maModel.mnSheet >= 0)
-        mpScRangeData = createLocalNamedRangeObject( maCalcName, getTokens(), nIndex, nNameFlags, 
maModel.mnSheet );
+        mpScRangeData = createLocalNamedRangeObject( maCalcName, ApiTokenSequence(), nIndex, 
nNameFlags, maModel.mnSheet );
     else
-        mpScRangeData = createNamedRangeObject( maCalcName, getTokens(), nIndex, nNameFlags );
+        mpScRangeData = createNamedRangeObject( maCalcName, ApiTokenSequence(), nIndex, nNameFlags 
);
     mnTokenIndex = nIndex;
 }
 
@@ -426,6 +426,15 @@ DefinedName::getTokens()
 
 void DefinedName::convertFormula()
 {
+    // convert and set formula of the defined name
+    if ( getFilterType() == FILTER_OOXML )
+    {
+        ApiTokenSequence aTokens = getTokens();
+        ScTokenArray aTokenArray;
+        (void)ScTokenConversion::ConvertToTokenArray( this->getScDocument(), aTokenArray, aTokens 
);
+        mpScRangeData->SetCode( aTokenArray );
+    }
+
     ScTokenArray* pTokenArray = mpScRangeData->GetCode();
     Sequence< FormulaToken > aFTokenSeq;
     (void)ScTokenConversion::ConvertToTokenSequence( this->getScDocument(), aFTokenSeq, 
*pTokenArray );
-- 
1.7.3.4


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.