[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - 2 commits - sc/inc sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Wed Aug 7 13:35:18 PDT 2013


 sc/inc/formulacell.hxx                    |    3 
 sc/source/core/data/column3.cxx           |    2 
 sc/source/core/data/formulacell.cxx       |   28 +++
 sc/source/filter/excel/namebuff.cxx       |    2 
 sc/source/filter/excel/xestream.cxx       |    7 
 sc/source/filter/inc/formulabuffer.hxx    |   43 ++++-
 sc/source/filter/inc/workbookhelper.hxx   |    2 
 sc/source/filter/inc/worksheethelper.hxx  |   13 +
 sc/source/filter/inc/xestream.hxx         |    2 
 sc/source/filter/oox/formulabuffer.cxx    |  235 ++++++++++++++++++++++--------
 sc/source/filter/oox/sheetdatacontext.cxx |    9 -
 sc/source/filter/oox/workbookhelper.cxx   |    2 
 sc/source/filter/oox/worksheethelper.cxx  |   11 -
 sc/source/ui/unoobj/cellsuno.cxx          |    2 
 14 files changed, 270 insertions(+), 91 deletions(-)

New commits:
commit 7e7419e0db04a309a4b817c6c41b3979837e1eb7
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Aug 7 16:35:06 2013 -0400

    Map shared formulas to Calc's formula groups on xlsx import.
    
    Change-Id: If8d11c5ee55afd8529070a699ca50284880ceb45

diff --git a/sc/source/filter/excel/namebuff.cxx b/sc/source/filter/excel/namebuff.cxx
index ac609a4..4e47c09 100644
--- a/sc/source/filter/excel/namebuff.cxx
+++ b/sc/source/filter/excel/namebuff.cxx
@@ -89,8 +89,6 @@ void SharedFormulaBuffer::Store( const ScRange& rRange, const ScTokenArray& rArr
         ScFormulaCellGroupRef xNewGroup(new ScFormulaCellGroup);
         xNewGroup->mnStart = rRange.aStart.Row();
         xNewGroup->mnLength = nGroupLen;
-        xNewGroup->mpCode = rArray.Clone();
-        xNewGroup->mbInvariant = rArray.IsInvariant();
         xNewGroup->setCode(rArray);
         maFormulaGroups.insert(FormulaGroupsType::value_type(aPos, xNewGroup));
     }
diff --git a/sc/source/filter/inc/formulabuffer.hxx b/sc/source/filter/inc/formulabuffer.hxx
index 1e98060..c5d8f96 100644
--- a/sc/source/filter/inc/formulabuffer.hxx
+++ b/sc/source/filter/inc/formulabuffer.hxx
@@ -29,13 +29,35 @@ namespace oox { namespace xls {
 
 class FormulaBuffer : public WorkbookHelper
 {
+    /**
+     * Represents a shared formula definition.
+     */
     struct SharedFormulaEntry
     {
-        ::com::sun::star::table::CellAddress maAddress;
+        com::sun::star::table::CellAddress maAddress;
+        com::sun::star::table::CellRangeAddress maRange;
         OUString maTokenStr;
         sal_Int32 mnSharedId;
-        ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XFormulaTokens > mxFormulaTokens;
-        SharedFormulaEntry( const ::com::sun::star::table::CellAddress& rAddress, const OUString& rTokenStr, sal_Int32 nSharedId ) : maAddress( rAddress ), maTokenStr( rTokenStr ), mnSharedId( nSharedId ) {}
+
+        SharedFormulaEntry(
+            const com::sun::star::table::CellAddress& rAddress,
+            const com::sun::star::table::CellRangeAddress& rRange,
+            const OUString& rTokenStr, sal_Int32 nSharedId );
+    };
+
+    /**
+     * Represents a formula cell that uses shared formula.
+     */
+    struct SharedFormulaDesc
+    {
+        com::sun::star::table::CellAddress maAddress;
+        sal_Int32 mnSharedId;
+        OUString maCellValue;
+        sal_Int32 mnValueType;
+
+        SharedFormulaDesc(
+            const com::sun::star::table::CellAddress& rAddr, sal_Int32 nSharedId,
+            const OUString& rCellValue, sal_Int32 nValueType );
     };
 
     struct TokenAddressItem
@@ -54,8 +76,6 @@ class FormulaBuffer : public WorkbookHelper
 
     typedef ::std::map< sal_Int32, std::vector< TokenAddressItem > > FormulaDataMap;
     typedef ::std::map< sal_Int32, std::vector< TokenRangeAddressItem > > ArrayFormulaDataMap;
-    // shared formuala descriptions, the id and address the formula is at
-    typedef std::pair< ::com::sun::star::table::CellAddress, sal_Int32 > SharedFormulaDesc;
     // sheet -> list of shared formula descriptions
     typedef ::std::map< sal_Int32, std::vector< SharedFormulaDesc > > SheetToSharedFormulaid;
     // sheet -> stuff needed to create shared formulae
@@ -66,7 +86,6 @@ class FormulaBuffer : public WorkbookHelper
     typedef ::std::pair< ::com::sun::star::table::CellAddress, double > ValueAddressPair;
     typedef ::std::map< sal_Int32, std::vector< ValueAddressPair > > FormulaValueMap;
 
-    void createSharedFormula(  const ::com::sun::star::table::CellAddress& rAddress,  sal_Int32 nSharedId, const OUString& rTokens );
     ::com::sun::star::uno::Reference< com::sun::star::table::XCellRange > getRange( const ::com::sun::star::table::CellRangeAddress& rRange);
     com::sun::star::uno::Reference< com::sun::star::sheet::XSpreadsheet > mxCurrSheet;
     FormulaDataMap      cellFormulas;
@@ -80,15 +99,23 @@ class FormulaBuffer : public WorkbookHelper
     void                applyCellFormula( ScDocument& rDoc, const ApiTokenSequence& rTokens, const ::com::sun::star::table::CellAddress& rAddress );
     void                applyCellFormulas(  const std::vector< TokenAddressItem >& rVector );
     void                applyCellFormulaValues( const std::vector< ValueAddressPair >& rVector );
+    void applySharedFormulas( sal_Int32 nTab );
 
 public:
     explicit            FormulaBuffer( const WorkbookHelper& rHelper );
     void                finalizeImport();
     void                setCellFormula( const ::com::sun::star::table::CellAddress& rAddress, const OUString&  );
-    void                setCellFormula( const ::com::sun::star::table::CellAddress& rAddress, sal_Int32 nSharedId );
+
+    void setCellFormula(
+        const ::com::sun::star::table::CellAddress& rAddress, sal_Int32 nSharedId,
+        const OUString& rCellValue, sal_Int32 nValueType );
+
     void                setCellFormulaValue( const ::com::sun::star::table::CellAddress& rAddress, double fValue  );
     void                setCellArrayFormula( const ::com::sun::star::table::CellRangeAddress& rRangeAddress, const ::com::sun::star::table::CellAddress& rTokenAddress, const OUString&  );
-    void                createSharedFormulaMapEntry( const ::com::sun::star::table::CellAddress& rAddress, sal_Int32 nSharedId, const OUString& rTokens );
+    void createSharedFormulaMapEntry(
+        const com::sun::star::table::CellAddress& rAddress,
+        const com::sun::star::table::CellRangeAddress& rRange,
+        sal_Int32 nSharedId, const OUString& rTokens );
 };
 
 }}
diff --git a/sc/source/filter/inc/workbookhelper.hxx b/sc/source/filter/inc/workbookhelper.hxx
index f4ce1cc..e540ba0 100644
--- a/sc/source/filter/inc/workbookhelper.hxx
+++ b/sc/source/filter/inc/workbookhelper.hxx
@@ -156,7 +156,7 @@ public:
 
     /** Returns a reference to the specified spreadsheet in the document model. */
     ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet >
-                        getSheetFromDoc( sal_Int16 nSheet ) const;
+                        getSheetFromDoc( sal_Int32 nSheet ) const;
     /** Returns a reference to the specified spreadsheet in the document model. */
     ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet >
                         getSheetFromDoc( const OUString& rSheet ) const;
diff --git a/sc/source/filter/inc/worksheethelper.hxx b/sc/source/filter/inc/worksheethelper.hxx
index 53b7ed1..270cafe 100644
--- a/sc/source/filter/inc/worksheethelper.hxx
+++ b/sc/source/filter/inc/worksheethelper.hxx
@@ -307,9 +307,18 @@ public:
     void finalizeDrawingImport();
 
     void                setCellFormula( const ::com::sun::star::table::CellAddress& rTokenAddress, const OUString&  );
-    void                setCellFormula( const ::com::sun::star::table::CellAddress& rTokenAddress, sal_Int32  );
+
+    void setCellFormula(
+        const com::sun::star::table::CellAddress& rAddr, sal_Int32 nSharedId,
+        const OUString& rCellValue, sal_Int32 nValueType );
+
     void                setCellArrayFormula( const ::com::sun::star::table::CellRangeAddress& rRangeAddress, const ::com::sun::star::table::CellAddress& rTokenAddress, const OUString&  );
-    void                createSharedFormulaMapEntry( const ::com::sun::star::table::CellAddress& rAddress, sal_Int32 nSharedId, const OUString& rTokens );
+
+    void createSharedFormulaMapEntry(
+        const com::sun::star::table::CellAddress& rAddress,
+        const com::sun::star::table::CellRangeAddress& rRange,
+        sal_Int32 nSharedId, const OUString& rTokens );
+
     void                setCellFormulaValue( const ::com::sun::star::table::CellAddress& rAddress,
                             double fValue  );
 private:
diff --git a/sc/source/filter/oox/formulabuffer.cxx b/sc/source/filter/oox/formulabuffer.cxx
index 3889b53..66d15ea 100644
--- a/sc/source/filter/oox/formulabuffer.cxx
+++ b/sc/source/filter/oox/formulabuffer.cxx
@@ -22,15 +22,26 @@
 #include "autonamecache.hxx"
 #include "tokenuno.hxx"
 #include "tokenarray.hxx"
+#include "oox/token/tokens.hxx"
 
-namespace oox {
-namespace xls {
-
+using namespace com::sun::star;
 using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::table;
 using namespace ::com::sun::star::sheet;
 using namespace ::com::sun::star::container;
 
+namespace oox { namespace xls {
+
+FormulaBuffer::FormulaBuffer::SharedFormulaEntry::SharedFormulaEntry(
+    const table::CellAddress& rAddr, const table::CellRangeAddress& rRange,
+    const OUString& rTokenStr, sal_Int32 nSharedId ) :
+    maAddress(rAddr), maRange(rRange), maTokenStr(rTokenStr), mnSharedId(nSharedId) {}
+
+FormulaBuffer::FormulaBuffer::SharedFormulaDesc::SharedFormulaDesc(
+    const com::sun::star::table::CellAddress& rAddr, sal_Int32 nSharedId,
+    const OUString& rCellValue, sal_Int32 nValueType ) :
+    maAddress(rAddr), mnSharedId(nSharedId), maCellValue(rCellValue), mnValueType(nValueType) {}
+
 FormulaBuffer::FormulaBuffer( const WorkbookHelper& rHelper ) : WorkbookHelper( rHelper )
 {
 }
@@ -55,43 +66,13 @@ void FormulaBuffer::finalizeImport()
     ScDocument& rDoc = getScDocument();
     Reference< XIndexAccess > xSheets( getDocument()->getSheets(), UNO_QUERY_THROW );
     rDoc.SetAutoNameCache( new ScAutoNameCache( &rDoc ) );
-    for ( sal_Int16 nTab = 0, nElem = xSheets->getCount(); nTab < nElem; ++nTab )
+    for ( sal_Int32 nTab = 0, nElem = xSheets->getCount(); nTab < nElem; ++nTab )
     {
         double fPosition = static_cast< double> (nTab + 1) /static_cast<double>(nElem);
         xFormulaBar->setPosition( fPosition );
         mxCurrSheet = getSheetFromDoc( nTab );
-        // process shared Formula
-        SheetToFormulaEntryMap::iterator sharedIt = sharedFormulas.find( nTab );
-        if ( sharedIt != sharedFormulas.end() )
-        {
-            // shared id ( to create the special shared names from )
-            std::vector<SharedFormulaEntry>& rSharedFormulas = sharedIt->second;
-            for ( std::vector<SharedFormulaEntry>::iterator it = rSharedFormulas.begin(), it_end = rSharedFormulas.end(); it != it_end; ++it )
-            {
-                 createSharedFormula( it->maAddress, it->mnSharedId, it->maTokenStr );
-            }
-        }
-        // now process any defined shared formulae
-        SheetToSharedFormulaid::iterator formulDescIt = sharedFormulaIds.find( nTab );
-        SheetToSharedIdToTokenIndex::iterator tokensIt = tokenIndexes.find( nTab );
-        if ( formulDescIt != sharedFormulaIds.end() && tokensIt !=  tokenIndexes.end() )
-        {
-            SharedIdToTokenIndex& rTokenIdMap = tokensIt->second;
-            std::vector< SharedFormulaDesc >& rVector = formulDescIt->second;
-            for ( std::vector< SharedFormulaDesc >::iterator it = rVector.begin(), it_end = rVector.end(); it != it_end; ++it )
-            {
-                // see if we have a
-                // resolved tokenId
-                CellAddress& rAddress = it->first;
-                sal_Int32& rnSharedId = it->second;
-                SharedIdToTokenIndex::iterator itTokenId =  rTokenIdMap.find( rnSharedId );
-                if ( itTokenId != rTokenIdMap.end() )
-                {
-                    ApiTokenSequence aTokens =  getFormulaParser().convertNameToFormula( itTokenId->second );
-                    applyCellFormula( rDoc, aTokens, rAddress );
-                }
-            }
-        }
+
+        applySharedFormulas(nTab);
 
         FormulaDataMap::iterator cellIt = cellFormulas.find( nTab );
         if ( cellIt != cellFormulas.end() )
@@ -155,6 +136,157 @@ void FormulaBuffer::applyCellFormulaValues( const std::vector< ValueAddressPair
         }
     }
 }
+
+namespace {
+
+class SharedFormulaGroups
+{
+    struct Key
+    {
+        sal_Int32 mnId;
+        sal_Int32 mnCol;
+
+        Key(sal_Int32 nId, sal_Int32 nCol) : mnId(nId), mnCol(nCol) {}
+
+        bool operator== ( const Key& rOther ) const
+        {
+            return mnId == rOther.mnId && mnCol == rOther.mnCol;
+        }
+
+        bool operator!= ( const Key& rOther ) const
+        {
+            return !operator==(rOther);
+        }
+    };
+
+    struct KeyHash
+    {
+        size_t operator() ( const Key& rKey ) const
+        {
+            double nVal = rKey.mnId;
+            nVal *= 256.0;
+            nVal += rKey.mnCol;
+            return static_cast<size_t>(nVal);
+        }
+    };
+
+    typedef boost::unordered_map<Key, ScFormulaCellGroupRef, KeyHash> StoreType;
+    StoreType maStore;
+public:
+
+    void set( sal_Int32 nSharedId, sal_Int32 nCol, const ScFormulaCellGroupRef& xGroup )
+    {
+        Key aKey(nSharedId, nCol);
+        maStore.insert(StoreType::value_type(aKey, xGroup));
+    }
+
+    ScFormulaCellGroupRef get( sal_Int32 nSharedId, sal_Int32 nCol ) const
+    {
+        Key aKey(nSharedId, nCol);
+        StoreType::const_iterator it = maStore.find(aKey);
+        return it == maStore.end() ? ScFormulaCellGroupRef() : it->second;
+    }
+};
+
+}
+
+void FormulaBuffer::applySharedFormulas( sal_Int32 nTab )
+{
+    SheetToFormulaEntryMap::const_iterator itShared = sharedFormulas.find(nTab);
+    if (itShared == sharedFormulas.end())
+        // There is no shared formulas for this sheet.
+        return;
+
+    SheetToSharedFormulaid::const_iterator itCells = sharedFormulaIds.find(nTab);
+    if (itCells == sharedFormulaIds.end())
+        // There is no formula cells that use shared formulas for this sheet.
+        return;
+
+    const std::vector<SharedFormulaEntry>& rSharedFormulas = itShared->second;
+    const std::vector<SharedFormulaDesc>& rCells = itCells->second;
+
+    ScDocument& rDoc = getScDocument();
+
+    SharedFormulaGroups aGroups;
+    {
+        // Process shared formulas first.
+        std::vector<SharedFormulaEntry>::const_iterator it = rSharedFormulas.begin(), itEnd = rSharedFormulas.end();
+        for (; it != itEnd; ++it)
+        {
+            const table::CellAddress& rAddr = it->maAddress;
+            const table::CellRangeAddress& rRange = it->maRange;
+            sal_Int32 nId = it->mnSharedId;
+            const OUString& rTokenStr = it->maTokenStr;
+
+            ScAddress aPos;
+            ScUnoConversion::FillScAddress(aPos, rAddr);
+            ScCompiler aComp(&rDoc, aPos);
+            aComp.SetGrammar(formula::FormulaGrammar::GRAM_ENGLISH_XL_OOX);
+            ScTokenArray* pArray = aComp.CompileString(rTokenStr);
+            if (pArray)
+            {
+                for (sal_Int32 nCol = rRange.StartColumn; nCol <= rRange.EndColumn; ++nCol)
+                {
+                    // Create one group per column, since Calc doesn't support
+                    // shared formulas across multiple columns.
+                    ScFormulaCellGroupRef xNewGroup(new ScFormulaCellGroup);
+                    xNewGroup->mnStart = rRange.StartRow;
+                    xNewGroup->mnLength = rRange.EndRow - rRange.StartRow;
+                    xNewGroup->setCode(*pArray);
+                    aGroups.set(nId, nCol, xNewGroup);
+                }
+            }
+        }
+    }
+
+    {
+        // Process formulas that use shared formulas.
+        std::vector<SharedFormulaDesc>::const_iterator it = rCells.begin(), itEnd = rCells.end();
+        for (; it != itEnd; ++it)
+        {
+            const table::CellAddress& rAddr = it->maAddress;
+
+            ScFormulaCellGroupRef xGroup = aGroups.get(it->mnSharedId, rAddr.Column);
+            if (!xGroup)
+                continue;
+
+            ScAddress aPos;
+            ScUnoConversion::FillScAddress(aPos, rAddr);
+            ScFormulaCell* pCell = new ScFormulaCell(&rDoc, aPos, xGroup);
+
+            bool bInserted = rDoc.SetGroupFormulaCell(aPos, pCell);
+            if (!bInserted)
+            {
+                // Insertion failed.
+                delete pCell;
+                continue;
+            }
+
+            pCell->StartListeningTo(&rDoc);
+
+            if (it->maCellValue.isEmpty())
+            {
+                // No cached cell value. Mark it for re-calculation.
+                pCell->SetDirty(true);
+                continue;
+            }
+
+            // Set cached formula results. For now, we only use numeric
+            // results. Find out how to utilize cached results of other types.
+            switch (it->mnValueType)
+            {
+                case XML_n:
+                    // numeric value.
+                    pCell->SetResultDouble(it->maCellValue.toDouble());
+                break;
+                default:
+                    // Mark it for re-calculation.
+                    pCell->SetDirty(true);
+            }
+        }
+    }
+}
+
 // bound to need this somewhere else, if so probably need to move it to
 // worksheethelper or somewhere else more suitable
 void StartCellListening( sal_Int16 nSheet, sal_Int32 nRow, sal_Int32 nCol, ScDocument& rDoc )
@@ -193,10 +325,12 @@ void FormulaBuffer::applyArrayFormulas( const std::vector< TokenRangeAddressItem
     }
 }
 
-void FormulaBuffer::createSharedFormulaMapEntry( const ::com::sun::star::table::CellAddress& rAddress, sal_Int32 nSharedId, const OUString& rTokens )
+void FormulaBuffer::createSharedFormulaMapEntry(
+    const table::CellAddress& rAddress, const table::CellRangeAddress& rRange,
+    sal_Int32 nSharedId, const OUString& rTokens )
 {
     std::vector<SharedFormulaEntry>& rSharedFormulas = sharedFormulas[ rAddress.Sheet ];
-    SharedFormulaEntry aEntry( rAddress, rTokens, nSharedId );
+    SharedFormulaEntry aEntry(rAddress, rRange, rTokens, nSharedId);
     rSharedFormulas.push_back( aEntry );
 }
 
@@ -205,9 +339,11 @@ void FormulaBuffer::setCellFormula( const ::com::sun::star::table::CellAddress&
     cellFormulas[ rAddress.Sheet ].push_back( TokenAddressItem( rTokenStr, rAddress ) );
 }
 
-void FormulaBuffer::setCellFormula( const ::com::sun::star::table::CellAddress& rAddress, sal_Int32 nSharedId )
+void FormulaBuffer::setCellFormula(
+    const table::CellAddress& rAddress, sal_Int32 nSharedId, const OUString& rCellValue, sal_Int32 nValueType )
 {
-    sharedFormulaIds[ rAddress.Sheet ].push_back( SharedFormulaDesc( rAddress, nSharedId ) );
+    sharedFormulaIds[rAddress.Sheet].push_back(
+        SharedFormulaDesc(rAddress, nSharedId, rCellValue, nValueType));
 }
 
 void FormulaBuffer::setCellArrayFormula( const ::com::sun::star::table::CellRangeAddress& rRangeAddress, const ::com::sun::star::table::CellAddress& rTokenAddress, const OUString& rTokenStr )
@@ -222,21 +358,6 @@ void FormulaBuffer::setCellFormulaValue( const ::com::sun::star::table::CellAddr
     cellFormulaValues[ rAddress.Sheet ].push_back( ValueAddressPair( rAddress, fValue ) );
 }
 
-void FormulaBuffer::createSharedFormula( const ::com::sun::star::table::CellAddress& rAddress,  sal_Int32 nSharedId, const OUString& rTokenStr )
-{
-    ApiTokenSequence aTokens = getFormulaParser().importFormula( rAddress, rTokenStr );
-    OUString aName = OUStringBuffer().appendAscii( RTL_CONSTASCII_STRINGPARAM( "__shared_" ) ).
-        append( static_cast< sal_Int32 >( rAddress.Sheet + 1 ) ).
-        append( sal_Unicode( '_' ) ).append( nSharedId ).
-        append( OUString("_0") ).makeStringAndClear();
-    ScRangeData* pScRangeData  = createNamedRangeObject( aName, aTokens, 0  );
-
-    pScRangeData->SetType(RT_SHARED);
-    sal_Int32 nTokenIndex = static_cast< sal_Int32 >( pScRangeData->GetIndex() );
-
-        // store the token index in the map
-   tokenIndexes[  rAddress.Sheet ][ nSharedId ] = nTokenIndex;
-}
-} // namespace xls
-} // namespace oox
+}}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/oox/sheetdatacontext.cxx b/sc/source/filter/oox/sheetdatacontext.cxx
index e1efe16..24be4d7 100644
--- a/sc/source/filter/oox/sheetdatacontext.cxx
+++ b/sc/source/filter/oox/sheetdatacontext.cxx
@@ -157,7 +157,7 @@ void SheetDataContext::onCharacters( const OUString& rChars )
         case XLS_TOKEN( f ):
             if( maFmlaData.mnFormulaType != XML_TOKEN_INVALID )
             {
-                  maFormulaStr = rChars;
+                maFormulaStr = rChars;
             }
         break;
     }
@@ -187,10 +187,9 @@ void SheetDataContext::onEndElement()
                 if( maFmlaData.mnSharedId >= 0 )
                 {
                     if( mbValidRange && maFmlaData.isValidSharedRef( maCellData.maCellAddr ) )
-                    {
-                        createSharedFormulaMapEntry( maCellData.maCellAddr, maFmlaData.mnSharedId, maFormulaStr );
-                    }
-                    setCellFormula( maCellData.maCellAddr, maFmlaData.mnSharedId );
+                        createSharedFormulaMapEntry(maCellData.maCellAddr, maFmlaData.maFormulaRef, maFmlaData.mnSharedId, maFormulaStr);
+
+                    setCellFormula(maCellData.maCellAddr, maFmlaData.mnSharedId, maCellValue, maCellData.mnCellType);
                     mrSheetData.setCellFormat( maCellData );
                 }
                 else
diff --git a/sc/source/filter/oox/workbookhelper.cxx b/sc/source/filter/oox/workbookhelper.cxx
index 37d5191..8802389 100644
--- a/sc/source/filter/oox/workbookhelper.cxx
+++ b/sc/source/filter/oox/workbookhelper.cxx
@@ -740,7 +740,7 @@ Reference< XSpreadsheetDocument > WorkbookHelper::getDocument() const
     return mrBookGlob.getDocument();
 }
 
-Reference< XSpreadsheet > WorkbookHelper::getSheetFromDoc( sal_Int16 nSheet ) const
+Reference< XSpreadsheet > WorkbookHelper::getSheetFromDoc( sal_Int32 nSheet ) const
 {
     Reference< XSpreadsheet > xSheet;
     try
diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx
index bd8b9ba..9fe9144 100644
--- a/sc/source/filter/oox/worksheethelper.cxx
+++ b/sc/source/filter/oox/worksheethelper.cxx
@@ -1602,9 +1602,11 @@ void WorksheetHelper::setCellFormula( const ::com::sun::star::table::CellAddress
     getFormulaBuffer().setCellFormula( rTokenAddress,  rTokenStr );
 }
 
-void WorksheetHelper::setCellFormula( const ::com::sun::star::table::CellAddress& rTokenAddress, sal_Int32 nSharedId )
+void WorksheetHelper::setCellFormula(
+    const ::com::sun::star::table::CellAddress& rAddr, sal_Int32 nSharedId,
+    const OUString& rCellValue, sal_Int32 nValueType )
 {
-    getFormulaBuffer().setCellFormula( rTokenAddress,  nSharedId );
+    getFormulaBuffer().setCellFormula(rAddr, nSharedId, rCellValue, nValueType);
 }
 
 void WorksheetHelper::setCellArrayFormula( const ::com::sun::star::table::CellRangeAddress& rRangeAddress, const ::com::sun::star::table::CellAddress& rTokenAddress, const OUString& rTokenStr )
@@ -1612,9 +1614,10 @@ void WorksheetHelper::setCellArrayFormula( const ::com::sun::star::table::CellRa
     getFormulaBuffer().setCellArrayFormula( rRangeAddress,  rTokenAddress, rTokenStr );
 }
 
-void WorksheetHelper::createSharedFormulaMapEntry(  const ::com::sun::star::table::CellAddress& rAddress, sal_Int32 nSharedId, const OUString& rTokens )
+void WorksheetHelper::createSharedFormulaMapEntry(
+    const table::CellAddress& rAddress, const table::CellRangeAddress& rRange, sal_Int32 nSharedId, const OUString& rTokens )
 {
-    getFormulaBuffer().createSharedFormulaMapEntry( rAddress, nSharedId, rTokens );
+    getFormulaBuffer().createSharedFormulaMapEntry(rAddress, rRange, nSharedId, rTokens);
 }
 
 // ============================================================================
commit fba2007b9d11b5dc2da7fc2f9e2d7c42e2ec4289
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Tue Aug 6 15:40:43 2013 -0400

    Const correctness at ScFormulaCell side.
    
    Though I had to use const_cast in some places...
    
    Change-Id: I22830bf291179efafc1b400f33a520072b7fab0f

diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index 3d70200..0d258a0 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -248,7 +248,8 @@ public:
     sal_uInt16      GetRawError();  // don't interpret, just return code or result error
     bool GetErrorOrValue( sal_uInt16& rErr, double& rVal );
     sal_uInt8       GetMatrixFlag() const;
-    ScTokenArray*   GetCode() const;
+    ScTokenArray* GetCode();
+    const ScTokenArray* GetCode() const;
 
     bool            IsRunning() const;
     void            SetRunning( bool bVal );
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 25af317..c4276d9 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -978,7 +978,7 @@ void lcl_AddCode( ScTokenArray& rArr, const ScFormulaCell* pCell )
 {
     rArr.AddOpCode(ocOpen);
 
-    ScTokenArray* pCode = pCell->GetCode();
+    ScTokenArray* pCode = const_cast<ScFormulaCell*>(pCell)->GetCode();
     if (pCode)
     {
         const formula::FormulaToken* pToken = pCode->First();
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 485d45c..c3ab5cd 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -2987,10 +2987,30 @@ void ScFormulaCell::SetChanged(bool b)
     bChanged = b;
 }
 
-sal_uInt8       ScFormulaCell::GetMatrixFlag() const                   { return cMatrixFlag; }
-ScTokenArray*   ScFormulaCell::GetCode() const                         { return pCode; }
-bool            ScFormulaCell::IsRunning() const                       { return bRunning; }
-void            ScFormulaCell::SetRunning( bool bVal )                 { bRunning = bVal; }
+sal_uInt8 ScFormulaCell::GetMatrixFlag() const
+{
+    return cMatrixFlag;
+}
+
+ScTokenArray* ScFormulaCell::GetCode()
+{
+    return pCode;
+}
+
+const ScTokenArray* ScFormulaCell::GetCode() const
+{
+    return pCode;
+}
+
+bool ScFormulaCell::IsRunning() const
+{
+    return bRunning;
+}
+
+void ScFormulaCell::SetRunning( bool bVal )
+{
+    bRunning = bVal;
+}
 
 void ScFormulaCell::CompileDBFormula()
 {
diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx
index de764b2..c90719a 100644
--- a/sc/source/filter/excel/xestream.cxx
+++ b/sc/source/filter/excel/xestream.cxx
@@ -845,10 +845,11 @@ OUString XclXmlUtils::ToOUString( const String& s )
     return OUString( s.GetBuffer(), s.Len() );
 }
 
-OUString XclXmlUtils::ToOUString( ScDocument& rDocument, const ScAddress& rAddress,
-        ScTokenArray* pTokenArray, const FormulaCompiler::OpCodeMapPtr & xOpCodeMap )
+OUString XclXmlUtils::ToOUString(
+    ScDocument& rDocument, const ScAddress& rAddress, const ScTokenArray* pTokenArray,
+    const FormulaCompiler::OpCodeMapPtr & xOpCodeMap )
 {
-    ScCompiler aCompiler( &rDocument, rAddress, *pTokenArray);
+    ScCompiler aCompiler( &rDocument, rAddress, const_cast<ScTokenArray&>(*pTokenArray));
     if (xOpCodeMap)
     {
         aCompiler.SetFormulaLanguage( xOpCodeMap );
diff --git a/sc/source/filter/inc/xestream.hxx b/sc/source/filter/inc/xestream.hxx
index 4b37a68..ba759ae 100644
--- a/sc/source/filter/inc/xestream.hxx
+++ b/sc/source/filter/inc/xestream.hxx
@@ -288,7 +288,7 @@ public:
     static OUString ToOUString( const ScfUInt16Vec& rBuffer, sal_Int32 nStart = 0, sal_Int32 nLength = -1 );
     static OUString ToOUString( const String& s );
     static OUString ToOUString( ScDocument& rDocument, const ScAddress& rAddress,
-                                       ScTokenArray* pTokenArray, const ScCompiler::OpCodeMapPtr & xOpCodeMap );
+                                const ScTokenArray* pTokenArray, const ScCompiler::OpCodeMapPtr & xOpCodeMap );
     static OUString ToOUString( const XclExpString& s );
     static const char* ToPsz( bool b );
 
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index 51a9b8d..528cc9e 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -5176,7 +5176,7 @@ uno::Sequence<sheet::FormulaToken> SAL_CALL ScCellRangeObj::getArrayTokens() thr
         {
             if (aStart1 == aStart2)
             {
-                ScTokenArray* pTokenArray = pFCell1->GetCode();
+                const ScTokenArray* pTokenArray = pFCell1->GetCode();
                 if (pTokenArray)
                     (void)ScTokenConversion::ConvertToTokenSequence(*pDoc, aSequence, *pTokenArray);
             }


More information about the Libreoffice-commits mailing list