[Libreoffice-commits] core.git: Branch 'libreoffice-4-2' - sc/inc sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Sun Apr 27 06:03:24 PDT 2014


 sc/inc/tokenarray.hxx              |    2 +
 sc/source/core/tool/token.cxx      |   46 +++++++++++++++++++++++++++++++++++++
 sc/source/filter/excel/excform.cxx |    4 ++-
 sc/source/filter/excel/impop.cxx   |    1 
 4 files changed, 52 insertions(+), 1 deletion(-)

New commits:
commit da739f729223908516deb1c2564d0713231abb5b
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Fri Apr 25 23:21:22 2014 -0400

    fdo#76611: Wrap reference addresses at max boundaries.
    
    When importing shared formula tokens.
    
    Change-Id: I7e1a05a78c3a93330476516e0459cffb668e3f66
    (cherry picked from commit c6c286f14468d341f5fd88edc39a37175a1b6caa)
    Reviewed-on: https://gerrit.libreoffice.org/9167
    Tested-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx
index bc63154..3c7d7e8 100644
--- a/sc/inc/tokenarray.hxx
+++ b/sc/inc/tokenarray.hxx
@@ -205,6 +205,8 @@ public:
      */
     OUString CreateString( sc::TokenStringContext& rCxt, const ScAddress& rPos ) const;
 
+    void WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow );
+
 #if DEBUG_FORMULA_COMPILER
     void Dump() const;
 #endif
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 320c42e..0e0f8fd 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -3752,6 +3752,52 @@ OUString ScTokenArray::CreateString( sc::TokenStringContext& rCxt, const ScAddre
     return aBuf.makeStringAndClear();
 }
 
+namespace {
+
+void wrapAddress( ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow )
+{
+    if (rPos.Col() > nMaxCol)
+        rPos.SetCol(rPos.Col() - nMaxCol - 1);
+    if (rPos.Row() > nMaxRow)
+        rPos.SetRow(rPos.Row() - nMaxRow - 1);
+}
+
+}
+
+void ScTokenArray::WrapReference( const ScAddress& rPos, SCCOL nMaxCol, SCROW nMaxRow )
+{
+    FormulaToken** p = pCode;
+    FormulaToken** pEnd = p + static_cast<size_t>(nLen);
+    for (; p != pEnd; ++p)
+    {
+        switch ((*p)->GetType())
+        {
+            case svSingleRef:
+            {
+                ScToken* pToken = static_cast<ScToken*>(*p);
+                ScSingleRefData& rRef = pToken->GetSingleRef();
+                ScAddress aAbs = rRef.toAbs(rPos);
+                wrapAddress(aAbs, nMaxCol, nMaxRow);
+                rRef.SetAddress(aAbs, rPos);
+            }
+            break;
+            case svDoubleRef:
+            {
+                ScToken* pToken = static_cast<ScToken*>(*p);
+                ScComplexRefData& rRef = pToken->GetDoubleRef();
+                ScRange aAbs = rRef.toAbs(rPos);
+                wrapAddress(aAbs.aStart, nMaxCol, nMaxRow);
+                wrapAddress(aAbs.aEnd, nMaxCol, nMaxRow);
+                aAbs.PutInOrder();
+                rRef.SetRange(aAbs, rPos);
+            }
+            break;
+            default:
+                ;
+        }
+    }
+}
+
 #if DEBUG_FORMULA_COMPILER
 void ScTokenArray::Dump() const
 {
diff --git a/sc/source/filter/excel/excform.cxx b/sc/source/filter/excel/excform.cxx
index 1f1336e..b609e28 100644
--- a/sc/source/filter/excel/excform.cxx
+++ b/sc/source/filter/excel/excform.cxx
@@ -128,7 +128,8 @@ void ImportExcel::Formula(
             const ScTokenArray* pSharedCode = pFormConv->GetSharedFormula(aRefPos);
             if (pSharedCode)
             {
-                ScFormulaCell* pCell = new ScFormulaCell(pD, aScPos, *pSharedCode);
+                ScFormulaCell* pCell = new ScFormulaCell(pD, aScPos, pSharedCode->Clone());
+                pCell->GetCode()->WrapReference(aScPos, EXC_MAXCOL8, EXC_MAXROW8);
                 rDoc.getDoc().EnsureTable(aScPos.Tab());
                 rDoc.setFormulaCell(aScPos, pCell);
                 pCell->SetNeedNumberFormat(false);
@@ -156,6 +157,7 @@ void ImportExcel::Formula(
     if (pResult)
     {
         pCell = new ScFormulaCell(&rDoc.getDoc(), aScPos, *pResult);
+        pCell->GetCode()->WrapReference(aScPos, EXC_MAXCOL8, EXC_MAXROW8);
         rDoc.getDoc().EnsureTable(aScPos.Tab());
         rDoc.setFormulaCell(aScPos, pCell);
         SetLastFormula(aScPos.Col(), aScPos.Row(), fCurVal, nXF, pCell);
diff --git a/sc/source/filter/excel/impop.cxx b/sc/source/filter/excel/impop.cxx
index 913d1ba..312da25 100644
--- a/sc/source/filter/excel/impop.cxx
+++ b/sc/source/filter/excel/impop.cxx
@@ -882,6 +882,7 @@ void ImportExcel::Shrfmla( void )
     ScDocumentImport& rDoc = GetDocImport();
 
     ScFormulaCell* pCell = new ScFormulaCell(pD, aPos, *pErgebnis);
+    pCell->GetCode()->WrapReference(aPos, EXC_MAXCOL8, EXC_MAXROW8);
     rDoc.getDoc().EnsureTable(aPos.Tab());
     rDoc.setFormulaCell(aPos, pCell);
     pCell->SetNeedNumberFormat(false);


More information about the Libreoffice-commits mailing list