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

Kohei Yoshida kohei.yoshida at gmail.com
Wed Aug 7 17:03:52 PDT 2013


 sc/Library_scfilt.mk                            |    1 
 sc/inc/rangenam.hxx                             |    2 
 sc/source/core/data/formulacell.cxx             |    4 
 sc/source/core/tool/compiler.cxx                |    7 -
 sc/source/filter/excel/xename.cxx               |    4 
 sc/source/filter/excel/xlformula.cxx            |   12 --
 sc/source/filter/ftools/sharedformulagroups.cxx |   49 ++++++++
 sc/source/filter/inc/orcusinterface.hxx         |    4 
 sc/source/filter/inc/sharedformulagroups.hxx    |   50 ++++++++
 sc/source/filter/inc/sheetdatabuffer.hxx        |    9 -
 sc/source/filter/oox/formulabuffer.cxx          |   58 ---------
 sc/source/filter/oox/sheetdatabuffer.cxx        |   32 -----
 sc/source/filter/oox/sheetdatacontext.cxx       |    9 -
 sc/source/filter/orcus/interface.cxx            |  143 +++++++++++++++++-------
 sc/source/ui/docshell/docfunc.cxx               |    8 -
 sc/source/ui/namedlg/namemgrtable.cxx           |    2 
 sc/source/ui/unoobj/nameuno.cxx                 |   15 --
 17 files changed, 230 insertions(+), 179 deletions(-)

New commits:
commit 776129ca13ee3ab67fd6610b1c931bf5a56aaeef
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Aug 7 19:04:53 2013 -0400

    No more RT_SHARED and RT_SHAREDMOD named range types.
    
    Change-Id: Ic8d98b62747ae29cc968ce926e2ae42537023840

diff --git a/sc/inc/rangenam.hxx b/sc/inc/rangenam.hxx
index 4a56ea1..e2731b5 100644
--- a/sc/inc/rangenam.hxx
+++ b/sc/inc/rangenam.hxx
@@ -51,8 +51,6 @@ typedef sal_uInt16 RangeType;
 #define RT_ABSAREA          ((RangeType)0x0020)
 #define RT_REFAREA          ((RangeType)0x0040)
 #define RT_ABSPOS           ((RangeType)0x0080)
-#define RT_SHARED           ((RangeType)0x0100)
-#define RT_SHAREDMOD        ((RangeType)0x0200)
 
 class ScRangeData
 {
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index c3ab5cd..d6254c2 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -2825,8 +2825,6 @@ void ScFormulaCell::UpdateTranspose( const ScRange& rSource, const ScAddress& rD
             {
                 if (pName->IsModified())
                     bRefChanged = true;
-                if (pName->HasType(RT_SHAREDMOD))
-                    pShared = pName;
             }
         }
         else if( t->GetType() != svIndex )
@@ -2902,8 +2900,6 @@ void ScFormulaCell::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY
             {
                 if (pName->IsModified())
                     bRefChanged = true;
-                if (pName->HasType(RT_SHAREDMOD))
-                    pShared = pName;
             }
         }
         else if( t->GetType() != svIndex )
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 6391690..547daa6 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -4302,12 +4302,7 @@ void ScCompiler::CreateStringFromIndex(OUStringBuffer& rBuffer,FormulaToken* _pT
         {
             ScRangeData* pData = GetRangeData( *_pTokenP);
             if (pData)
-            {
-                if (pData->HasType(RT_SHARED))
-                    pData->UpdateSymbol( aBuffer, aPos, GetGrammar());
-                else
-                    aBuffer.append(pData->GetName());
-            }
+                aBuffer.append(pData->GetName());
         }
         break;
         case ocDBArea:
diff --git a/sc/source/filter/excel/xename.cxx b/sc/source/filter/excel/xename.cxx
index 276624c..54f2e8d 100644
--- a/sc/source/filter/excel/xename.cxx
+++ b/sc/source/filter/excel/xename.cxx
@@ -657,7 +657,7 @@ void XclExpNameManagerImpl::CreateUserNames()
     for (; itr != itrEnd; ++itr)
     {
         // skip definitions of shared formulas
-        if (!itr->second->HasType(RT_SHARED) && !FindNamedExpIndex(SCTAB_GLOBAL, itr->second->GetIndex()))
+        if (!FindNamedExpIndex(SCTAB_GLOBAL, itr->second->GetIndex()))
             CreateName(SCTAB_GLOBAL, *itr->second);
     }
     //look at every sheet for local range names
@@ -670,7 +670,7 @@ void XclExpNameManagerImpl::CreateUserNames()
         for (; itr != itrEnd; ++itr)
         {
             // skip definitions of shared formulas
-            if (!itr->second->HasType(RT_SHARED) && !FindNamedExpIndex(tabIt->first, itr->second->GetIndex()))
+            if (!FindNamedExpIndex(tabIt->first, itr->second->GetIndex()))
                 CreateName(tabIt->first, *itr->second);
         }
     }
diff --git a/sc/source/filter/excel/xlformula.cxx b/sc/source/filter/excel/xlformula.cxx
index 94d9594..2eff911 100644
--- a/sc/source/filter/excel/xlformula.cxx
+++ b/sc/source/filter/excel/xlformula.cxx
@@ -765,15 +765,9 @@ void XclTokenArrayHelper::ConvertStringToList( ScTokenArray& rScTokArr, sal_Unic
 
 // shared formulas ------------------------------------------------------------
 
-const ScTokenArray* XclTokenArrayHelper::GetSharedFormula( const XclRoot& rRoot, const ScTokenArray& rScTokArr )
-{
-    if( rScTokArr.GetLen() == 1 )
-        if( const FormulaToken* pScToken = rScTokArr.GetArray()[ 0 ] )
-            if( pScToken->GetOpCode() == ocName )
-                if( ScRangeData* pData = rRoot.GetNamedRanges().findByIndex( pScToken->GetIndex() ) )
-                    if( pData->HasType( RT_SHARED ) )
-                        return pData->GetCode();
-    return 0;
+const ScTokenArray* XclTokenArrayHelper::GetSharedFormula( const XclRoot& /*rRoot*/, const ScTokenArray& /*rScTokArr*/ )
+{
+    return NULL;
 }
 
 // multiple operations --------------------------------------------------------
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index 2b26a73..f1b3491 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -5069,7 +5069,7 @@ sal_Bool ScDocFunc::InsertNameList( const ScAddress& rStartPos, sal_Bool bApi )
     for (ScRangeName::iterator itr = itrLocalBeg; itr != itrLocalEnd; ++itr)
     {
         const ScRangeData& r = *itr->second;
-        if (!r.HasType(RT_DATABASE) && !r.HasType(RT_SHARED))
+        if (!r.HasType(RT_DATABASE))
             ++nValidCount;
     }
     ScRangeName* pList = pDoc->GetRangeName();
@@ -5077,7 +5077,7 @@ sal_Bool ScDocFunc::InsertNameList( const ScAddress& rStartPos, sal_Bool bApi )
     for (ScRangeName::iterator itr = itrBeg; itr != itrEnd; ++itr)
     {
         const ScRangeData& r = *itr->second;
-        if (!r.HasType(RT_DATABASE) && !r.HasType(RT_SHARED) && !pLocalList->findByUpperName(r.GetUpperName()))
+        if (!r.HasType(RT_DATABASE) && !pLocalList->findByUpperName(r.GetUpperName()))
             ++nValidCount;
     }
 
@@ -5106,13 +5106,13 @@ sal_Bool ScDocFunc::InsertNameList( const ScAddress& rStartPos, sal_Bool bApi )
             for (ScRangeName::iterator itr = itrLocalBeg; itr != itrLocalEnd; ++itr)
             {
                 ScRangeData& r = *itr->second;
-                if (!r.HasType(RT_DATABASE) && !r.HasType(RT_SHARED))
+                if (!r.HasType(RT_DATABASE))
                     ppSortArray[j++] = &r;
             }
             for (ScRangeName::iterator itr = itrBeg; itr != itrEnd; ++itr)
             {
                 ScRangeData& r = *itr->second;
-                if (!r.HasType(RT_DATABASE) && !r.HasType(RT_SHARED) && !pLocalList->findByUpperName(itr->first))
+                if (!r.HasType(RT_DATABASE) && !pLocalList->findByUpperName(itr->first))
                     ppSortArray[j++] = &r;
             }
 #ifndef ICC
diff --git a/sc/source/ui/namedlg/namemgrtable.cxx b/sc/source/ui/namedlg/namemgrtable.cxx
index fd315c0..0fee2be 100644
--- a/sc/source/ui/namedlg/namemgrtable.cxx
+++ b/sc/source/ui/namedlg/namemgrtable.cxx
@@ -143,7 +143,7 @@ void ScRangeManagerTable::Init()
         for (ScRangeName::const_iterator it = pLocalRangeName->begin();
                 it != pLocalRangeName->end(); ++it)
         {
-            if (!it->second->HasType(RT_DATABASE) && !it->second->HasType(RT_SHARED))
+            if (!it->second->HasType(RT_DATABASE))
             {
                 aLine.aName = it->second->GetName();
                 addEntry(aLine, false);
diff --git a/sc/source/ui/unoobj/nameuno.cxx b/sc/source/ui/unoobj/nameuno.cxx
index 0ec46ba..ae7a342 100644
--- a/sc/source/ui/unoobj/nameuno.cxx
+++ b/sc/source/ui/unoobj/nameuno.cxx
@@ -82,7 +82,7 @@ static bool lcl_UserVisibleName(const ScRangeData& rData)
 {
     //! als Methode an ScRangeData
 
-    return !rData.HasType(RT_DATABASE) && !rData.HasType(RT_SHARED);
+    return !rData.HasType(RT_DATABASE);
 }
 
 ScNamedRangeObj::ScNamedRangeObj( rtl::Reference< ScNamedRangesObj > xParent, ScDocShell* pDocSh, const String& rNm, Reference<container::XNamed> xSheet):
@@ -378,7 +378,7 @@ uno::Reference<beans::XPropertySetInfo> SAL_CALL ScNamedRangeObj::getPropertySet
 }
 
 void SAL_CALL ScNamedRangeObj::setPropertyValue(
-                        const OUString& rPropertyName, const uno::Any& aValue )
+                        const OUString& rPropertyName, const uno::Any& /*aValue*/ )
                 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
                         lang::IllegalArgumentException, lang::WrappedTargetException,
                         uno::RuntimeException)
@@ -386,12 +386,7 @@ void SAL_CALL ScNamedRangeObj::setPropertyValue(
     SolarMutexGuard aGuard;
     if ( rPropertyName == SC_UNONAME_ISSHAREDFMLA )
     {
-        bool bIsShared = false;
-        if( aValue >>= bIsShared )
-        {
-            sal_uInt16 nNewType = bIsShared ? RT_SHARED : RT_NAME;
-            Modify_Impl( NULL, NULL, NULL, NULL, &nNewType,formula::FormulaGrammar::GRAM_PODF_A1 );
-        }
+        // Ignore this.
     }
 }
 
@@ -417,8 +412,8 @@ uno::Any SAL_CALL ScNamedRangeObj::getPropertyValue( const OUString& rPropertyNa
     }
     else if ( rPropertyName == SC_UNONAME_ISSHAREDFMLA )
     {
-        if( ScRangeData* pData = GetRangeData_Impl() )
-            aRet <<= static_cast< bool >( pData->HasType( RT_SHARED ) );
+        if (GetRangeData_Impl())
+            aRet <<= false;
     }
     return aRet;
 }
commit d57a934e1dcfd8f3f176d279a2f6fa9dab8fe411
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Aug 7 18:46:57 2013 -0400

    Rework shared formula import in orcus handler.
    
    Change-Id: I3a6ed347565fff7cc984960929c66997e3a18f1e

diff --git a/sc/Library_scfilt.mk b/sc/Library_scfilt.mk
index 89b96ed..75ee0fe 100644
--- a/sc/Library_scfilt.mk
+++ b/sc/Library_scfilt.mk
@@ -133,6 +133,7 @@ $(eval $(call gb_Library_add_exception_objects,scfilt,\
 	sc/source/filter/ftools/fapihelper \
 	sc/source/filter/ftools/fprogressbar \
 	sc/source/filter/ftools/ftools \
+	sc/source/filter/ftools/sharedformulagroups \
 	sc/source/filter/html/htmlexp \
 	sc/source/filter/html/htmlexp2 \
 	sc/source/filter/html/htmlimp \
diff --git a/sc/source/filter/ftools/sharedformulagroups.cxx b/sc/source/filter/ftools/sharedformulagroups.cxx
new file mode 100644
index 0000000..77da587
--- /dev/null
+++ b/sc/source/filter/ftools/sharedformulagroups.cxx
@@ -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/.
+ */
+
+#include "sharedformulagroups.hxx"
+
+namespace sc {
+
+SharedFormulaGroups::Key::Key(size_t nId, SCCOL nCol) : mnId(nId), mnCol(nCol) {}
+
+bool SharedFormulaGroups::Key::operator== ( const Key& rOther ) const
+{
+    return mnId == rOther.mnId && mnCol == rOther.mnCol;
+}
+
+bool SharedFormulaGroups::Key::operator!= ( const Key& rOther ) const
+{
+    return !operator==(rOther);
+}
+
+size_t SharedFormulaGroups::KeyHash::operator ()( const Key& rKey ) const
+{
+    double nVal = rKey.mnId;
+    nVal *= 256.0;
+    nVal += rKey.mnCol;
+    return static_cast<size_t>(nVal);
+}
+
+void SharedFormulaGroups::set( size_t nSharedId, SCCOL nCol, const ScFormulaCellGroupRef& xGroup )
+{
+    Key aKey(nSharedId, nCol);
+    maStore.insert(StoreType::value_type(aKey, xGroup));
+}
+
+ScFormulaCellGroupRef SharedFormulaGroups::get( size_t nSharedId, SCCOL nCol ) const
+{
+    Key aKey(nSharedId, nCol);
+    StoreType::const_iterator it = maStore.find(aKey);
+    return it == maStore.end() ? ScFormulaCellGroupRef() : it->second;
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/inc/orcusinterface.hxx b/sc/source/filter/inc/orcusinterface.hxx
index 6e6f2db..75b49f4 100644
--- a/sc/source/filter/inc/orcusinterface.hxx
+++ b/sc/source/filter/inc/orcusinterface.hxx
@@ -12,6 +12,9 @@
 
 #include "address.hxx"
 #include "documentimport.hxx"
+
+#include "sharedformulagroups.hxx"
+
 #include "rtl/strbuf.hxx"
 
 #define __ORCUS_STATIC_LIB
@@ -68,6 +71,7 @@ class ScOrcusSheet : public orcus::spreadsheet::iface::import_sheet
     ScDocumentImport& mrDoc;
     SCTAB mnTab;
     ScOrcusFactory& mrFactory;
+    sc::SharedFormulaGroups maFormulaGroups;
 
     typedef std::map<size_t, ScRangeData*> SharedFormulaContainer;
     SharedFormulaContainer maSharedFormulas;
diff --git a/sc/source/filter/inc/sharedformulagroups.hxx b/sc/source/filter/inc/sharedformulagroups.hxx
new file mode 100644
index 0000000..c6058fc
--- /dev/null
+++ b/sc/source/filter/inc/sharedformulagroups.hxx
@@ -0,0 +1,50 @@
+/* -*- 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_FILTER_SHAREDFORMULAGROUPS_HXX
+#define SC_FILTER_SHAREDFORMULAGROUPS_HXX
+
+#include "address.hxx"
+#include "formulacell.hxx"
+
+#include <boost/unordered_map.hpp>
+
+namespace sc {
+
+class SharedFormulaGroups
+{
+    struct Key
+    {
+        size_t mnId;
+        SCCOL mnCol;
+
+        Key(size_t nId, SCCOL nCol);
+
+        bool operator== ( const Key& rOther ) const;
+        bool operator!= ( const Key& rOther ) const;
+    };
+
+    struct KeyHash
+    {
+        size_t operator() ( const Key& rKey ) const;
+    };
+
+    typedef boost::unordered_map<Key, ScFormulaCellGroupRef, KeyHash> StoreType;
+    StoreType maStore;
+public:
+
+    void set( size_t nSharedId, SCCOL nCol, const ScFormulaCellGroupRef& xGroup );
+    ScFormulaCellGroupRef get( size_t nSharedId, SCCOL nCol ) const;
+};
+
+}
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/filter/oox/formulabuffer.cxx b/sc/source/filter/oox/formulabuffer.cxx
index 66d15ea..59518bc 100644
--- a/sc/source/filter/oox/formulabuffer.cxx
+++ b/sc/source/filter/oox/formulabuffer.cxx
@@ -22,6 +22,7 @@
 #include "autonamecache.hxx"
 #include "tokenuno.hxx"
 #include "tokenarray.hxx"
+#include "sharedformulagroups.hxx"
 #include "oox/token/tokens.hxx"
 
 using namespace com::sun::star;
@@ -137,59 +138,6 @@ 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);
@@ -207,7 +155,7 @@ void FormulaBuffer::applySharedFormulas( sal_Int32 nTab )
 
     ScDocument& rDoc = getScDocument();
 
-    SharedFormulaGroups aGroups;
+    sc::SharedFormulaGroups aGroups;
     {
         // Process shared formulas first.
         std::vector<SharedFormulaEntry>::const_iterator it = rSharedFormulas.begin(), itEnd = rSharedFormulas.end();
@@ -231,7 +179,7 @@ void FormulaBuffer::applySharedFormulas( sal_Int32 nTab )
                     // shared formulas across multiple columns.
                     ScFormulaCellGroupRef xNewGroup(new ScFormulaCellGroup);
                     xNewGroup->mnStart = rRange.StartRow;
-                    xNewGroup->mnLength = rRange.EndRow - rRange.StartRow;
+                    xNewGroup->mnLength = rRange.EndRow - rRange.StartRow + 1;
                     xNewGroup->setCode(*pArray);
                     aGroups.set(nId, nCol, xNewGroup);
                 }
diff --git a/sc/source/filter/orcus/interface.cxx b/sc/source/filter/orcus/interface.cxx
index a3c1e6d..495715f 100644
--- a/sc/source/filter/orcus/interface.cxx
+++ b/sc/source/filter/orcus/interface.cxx
@@ -16,6 +16,7 @@
 #include "globalnames.hxx"
 #include "docoptio.hxx"
 #include "globstr.hrc"
+#include "compiler.hxx"
 
 #include "formula/token.hxx"
 #include "tools/datetime.hxx"
@@ -256,7 +257,7 @@ formula::FormulaGrammar::Grammar getCalcGrammarFromOrcus( os::formula_grammar_t
             break;
         case orcus::spreadsheet::xlsx_2007:
         case orcus::spreadsheet::xlsx_2010:
-            eGrammar = formula::FormulaGrammar::GRAM_ENGLISH_XL_A1;
+            eGrammar = formula::FormulaGrammar::GRAM_ENGLISH_XL_OOX;
             break;
         case orcus::spreadsheet::gnumeric:
             eGrammar = formula::FormulaGrammar::GRAM_ENGLISH_XL_A1;
@@ -266,6 +267,55 @@ formula::FormulaGrammar::Grammar getCalcGrammarFromOrcus( os::formula_grammar_t
     return eGrammar;
 }
 
+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 ScOrcusSheet::set_formula(
@@ -291,57 +341,76 @@ void ScOrcusSheet::set_formula_result(os::row_t row, os::col_t col, const char*
 }
 
 void ScOrcusSheet::set_shared_formula(
-    os::row_t row, os::col_t col, os::formula_grammar_t grammar, size_t sindex,
-    const char* p_formula, size_t n_formula)
+    os::row_t /*row*/, os::col_t /*col*/, os::formula_grammar_t /*grammar*/, size_t /*sindex*/,
+    const char* /*p_formula*/, size_t /*n_formula*/)
 {
-    OUString aFormula( p_formula, n_formula, RTL_TEXTENCODING_UTF8 );
-    formula::FormulaGrammar::Grammar eGrammar =  getCalcGrammarFromOrcus( grammar );
-    ScRangeName* pRangeName = mrDoc.getDoc().GetRangeName();
-
-    OUString aName("shared_");
-    aName += OUString::valueOf(sal_Int32(pRangeName->size()));
-    ScRangeData* pSharedFormula = new ScRangeData(&mrDoc.getDoc(), aName, aFormula, ScAddress(col, row, mnTab), RT_SHARED, eGrammar);
-    if(pRangeName->insert(pSharedFormula))
-    {
-        maSharedFormulas.insert( std::pair<size_t, ScRangeData*>(sindex, pSharedFormula) );
-        ScTokenArray aArr;
-        aArr.AddToken( formula::FormulaIndexToken( ocName, pSharedFormula->GetIndex() ) );
-        mrDoc.setFormulaCell(ScAddress(col,row,mnTab), aArr);
-        cellInserted();
-    }
+    // TODO: We need to revise this interface in orcus.
 }
 
 void ScOrcusSheet::set_shared_formula(
     os::row_t row, os::col_t col, os::formula_grammar_t grammar, size_t sindex,
-    const char* p_formula, size_t n_formula, const char* /*p_range*/, size_t /*n_range*/)
-{
-    OUString aFormula( p_formula, n_formula, RTL_TEXTENCODING_UTF8 );
-    formula::FormulaGrammar::Grammar eGrammar = getCalcGrammarFromOrcus( grammar );
-    ScRangeName* pRangeName = mrDoc.getDoc().GetRangeName();
+    const char* p_formula, size_t n_formula, const char* p_range, size_t n_range)
+{
+    ScAddress aPos(col, row, mnTab);
+    OUString aFormula(p_formula, n_formula, RTL_TEXTENCODING_UTF8);
+    OUString aRangeStr(p_range, n_range, RTL_TEXTENCODING_UTF8);
+    formula::FormulaGrammar::Grammar eGram = getCalcGrammarFromOrcus(grammar);
+    formula::FormulaGrammar::AddressConvention eConv = formula::FormulaGrammar::extractRefConvention(eGram);
+
+    // Convert the shared formula range.
+    ScRange aRange;
+    sal_uInt16 nRes = aRange.Parse(aRangeStr, &mrDoc.getDoc(), eConv);
+    if (!(nRes & SCA_VALID))
+        // Conversion failed.
+        return;
+
+    // Compile the formula expression into tokens.
+    ScCompiler aComp(&mrDoc.getDoc(), aPos);
+    aComp.SetGrammar(eGram);
+    ScTokenArray* pArray = aComp.CompileString(aFormula);
+    if (!pArray)
+        // Tokenization failed.
+        return;
 
-    OUString aName("shared_");
-    aName += OUString::valueOf(sal_Int32(pRangeName->size()));
-    ScRangeData* pSharedFormula = new ScRangeData(&mrDoc.getDoc(), aName, aFormula, ScAddress(col, row, mnTab), RT_SHARED, eGrammar);
-    if(pRangeName->insert(pSharedFormula))
+    for (sal_Int32 nCol = aRange.aStart.Col(); nCol <= aRange.aEnd.Col(); ++nCol)
     {
-        maSharedFormulas.insert( std::pair<size_t, ScRangeData*>(sindex, pSharedFormula) );
-        ScTokenArray aArr;
-        aArr.AddToken( formula::FormulaIndexToken( ocName, pSharedFormula->GetIndex() ) );
-        mrDoc.setFormulaCell(ScAddress(col,row,mnTab), aArr);
-        cellInserted();
+        // Create one group per column, since Calc doesn't support shared
+        // formulas across multiple columns.
+        ScFormulaCellGroupRef xNewGroup(new ScFormulaCellGroup);
+        xNewGroup->mnStart = aRange.aStart.Row();
+        xNewGroup->mnLength = aRange.aEnd.Row() - aRange.aStart.Row() + 1;
+        xNewGroup->setCode(*pArray);
+        maFormulaGroups.set(sindex, nCol, xNewGroup);
     }
+
+    ScFormulaCellGroupRef xGroup = maFormulaGroups.get(sindex, aPos.Col());
+    if (!xGroup)
+        return;
+
+    ScFormulaCell* pCell = new ScFormulaCell(&mrDoc.getDoc(), aPos, xGroup);
+    mrDoc.setFormulaCell(aPos, pCell);
+    cellInserted();
+
+    // For now, orcus doesn't support setting cached result. Mark it for re-calculation.
+    pCell->SetDirty(true);
+    pCell->StartListeningTo(&mrDoc.getDoc());
 }
 
 void ScOrcusSheet::set_shared_formula(os::row_t row, os::col_t col, size_t sindex)
 {
-    if(maSharedFormulas.find(sindex) == maSharedFormulas.end())
+    ScAddress aPos(col, row, mnTab);
+
+    ScFormulaCellGroupRef xGroup = maFormulaGroups.get(sindex, aPos.Col());
+    if (!xGroup)
         return;
 
-    ScRangeData* pSharedFormula = maSharedFormulas.find(sindex)->second;
-    ScTokenArray aArr;
-    aArr.AddToken( formula::FormulaIndexToken( ocName, pSharedFormula->GetIndex() ) );
-    mrDoc.setFormulaCell(ScAddress(col,row,mnTab), aArr);
+    ScFormulaCell* pCell = new ScFormulaCell(&mrDoc.getDoc(), aPos, xGroup);
+    mrDoc.setFormulaCell(aPos, pCell);
     cellInserted();
+
+    // For now, orcus doesn't support setting cached result. Mark it for re-calculation.
+    pCell->SetDirty(true);
+    pCell->StartListeningTo(&mrDoc.getDoc());
 }
 
 void ScOrcusSheet::set_array_formula(
commit 98139353aa40d7bb0c0202ba5b3f588348eea36f
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Aug 7 17:30:20 2013 -0400

    This code is no longer needed.
    
    Change-Id: I319aae9d58fe1798e6add168f5a3613bceef7c26

diff --git a/sc/source/filter/inc/sheetdatabuffer.hxx b/sc/source/filter/inc/sheetdatabuffer.hxx
index 563145e..e826bd2 100644
--- a/sc/source/filter/inc/sheetdatabuffer.hxx
+++ b/sc/source/filter/inc/sheetdatabuffer.hxx
@@ -143,12 +143,6 @@ public:
                             const ::com::sun::star::table::CellRangeAddress& rRange,
                             const DataTableModel& rModel );
 
-    /** Creates a named range with a special name for a shared formula with the
-        specified base address and formula definition (BIFF only). */
-    void                createSharedFormula(
-                            const ::com::sun::star::table::CellAddress& rCellAddr,
-                            const ApiTokenSequence& rTokens );
-
     /** Sets default cell formatting for the specified range of rows. */
     void                setRowFormat( sal_Int32 nRow, sal_Int32 nXfId, bool bCustomFormat );
     /** Merges the cells in the passed cell range. */
@@ -173,9 +167,6 @@ private:
                             const ::com::sun::star::table::CellAddress& rCellAddr,
                             const ApiTokenSequence& rTokens );
 
-    /** Creates a named range with a special name for a shared formula with the
-        specified base address and formula definition. */
-    void                createSharedFormula( const BinAddress& rMapKey, const ApiTokenSequence& rTokens );
     /** Creates a formula token array representing the shared formula with the
         passed identifier. */
     ApiTokenSequence    resolveSharedFormula( const BinAddress& rMapKey ) const;
diff --git a/sc/source/filter/oox/sheetdatabuffer.cxx b/sc/source/filter/oox/sheetdatabuffer.cxx
index 174842a..99e8054 100644
--- a/sc/source/filter/oox/sheetdatabuffer.cxx
+++ b/sc/source/filter/oox/sheetdatabuffer.cxx
@@ -276,11 +276,6 @@ void SheetDataBuffer::createTableOperation( const CellRangeAddress& rRange, cons
     maTableOperations.push_back( TableOperation( rRange, rModel ) );
 }
 
-void SheetDataBuffer::createSharedFormula( const CellAddress& rCellAddr, const ApiTokenSequence& rTokens )
-{
-    createSharedFormula( BinAddress( rCellAddr ), rTokens );
-}
-
 void SheetDataBuffer::setRowFormat( sal_Int32 nRow, sal_Int32 nXfId, bool bCustomFormat )
 {
     // set row formatting
@@ -554,33 +549,6 @@ void SheetDataBuffer::setCellFormula( const CellAddress& rCellAddr, const ApiTok
     }
 }
 
-void SheetDataBuffer::createSharedFormula( const BinAddress& rMapKey, const ApiTokenSequence& rTokens )
-{
-    // create the defined name that will represent the shared formula
-    OUString aName = OUStringBuffer().appendAscii( RTL_CONSTASCII_STRINGPARAM( "__shared_" ) ).
-        append( static_cast< sal_Int32 >( getSheetIndex() + 1 ) ).
-        append( sal_Unicode( '_' ) ).append( rMapKey.mnRow ).
-        append( sal_Unicode( '_' ) ).append( rMapKey.mnCol ).makeStringAndClear();
-    ScRangeData* pScRangeData = createNamedRangeObject( aName, rTokens, 0 );
-    pScRangeData->SetType(RT_SHARED);
-
-    // get and store the token index of the defined name
-    OSL_ENSURE( maSharedFormulas.count( rMapKey ) == 0, "SheetDataBuffer::createSharedFormula - shared formula exists already" );
-    sal_Int32 nTokenIndex = static_cast< sal_Int32 >( pScRangeData->GetIndex() );
-    if( nTokenIndex >= 0 ) try
-    {
-        // store the token index in the map
-        maSharedFormulas[ rMapKey ] = nTokenIndex;
-        // retry to insert a pending shared formula cell
-        if( mbPendingSharedFmla )
-            setCellFormula( maSharedFmlaAddr, resolveSharedFormula( maSharedBaseAddr ) );
-    }
-    catch( Exception& )
-    {
-    }
-    mbPendingSharedFmla = false;
-}
-
 ApiTokenSequence SheetDataBuffer::resolveSharedFormula( const BinAddress& rMapKey ) const
 {
     sal_Int32 nTokenIndex = ContainerHelper::getMapElement( maSharedFormulas, rMapKey, -1 );
diff --git a/sc/source/filter/oox/sheetdatacontext.cxx b/sc/source/filter/oox/sheetdatacontext.cxx
index 24be4d7..3aaaaac 100644
--- a/sc/source/filter/oox/sheetdatacontext.cxx
+++ b/sc/source/filter/oox/sheetdatacontext.cxx
@@ -578,17 +578,10 @@ void SheetDataContext::importDataTable( SequenceInputStream& rStrm )
     }
 }
 
-void SheetDataContext::importSharedFmla( SequenceInputStream& rStrm )
+void SheetDataContext::importSharedFmla( SequenceInputStream& /*rStrm*/ )
 {
-    if( readFormulaRef( rStrm ) && maFmlaData.isValidSharedRef( maCellData.maCellAddr ) )
-    {
-        ApiTokenSequence aTokens = mrFormulaParser.importFormula( maCellData.maCellAddr, FORMULATYPE_SHAREDFORMULA, rStrm );
-        mrSheetData.createSharedFormula( maCellData.maCellAddr, aTokens );
-    }
 }
 
-// ============================================================================
-
 } // namespace xls
 } // namespace oox
 


More information about the Libreoffice-commits mailing list