[PATCH libreoffice-4-1] let us use scoped_ptr when possible

Markus Mohrhard (via Code Review) gerrit at gerrit.libreoffice.org
Mon Jun 3 18:02:28 PDT 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/4147

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/47/4147/1

let us use scoped_ptr when possible

Change-Id: Ia8199bdc63ee732bada51687df195c9ab9cae9aa
---
M sc/Library_sc.mk
M sc/inc/document.hxx
M sc/inc/formulacell.hxx
M sc/inc/formularesult.hxx
A sc/inc/simpleformulacalc.hxx
M sc/source/core/data/column.cxx
M sc/source/core/data/column2.cxx
M sc/source/core/data/column3.cxx
M sc/source/core/data/dociter.cxx
M sc/source/core/data/document.cxx
M sc/source/core/data/formulacell.cxx
A sc/source/core/data/simpleformulacalc.cxx
M sc/source/core/tool/cellform.cxx
M sc/source/core/tool/interpr2.cxx
M sc/source/core/tool/interpr4.cxx
M sc/source/core/tool/interpr5.cxx
M sc/source/filter/excel/xestream.cxx
M sc/source/filter/excel/xetable.cxx
M sc/source/filter/html/htmlexp.cxx
M sc/source/filter/inc/xetable.hxx
M sc/source/filter/xml/xmlcelli.cxx
M sc/source/filter/xml/xmlexprt.cxx
M sc/source/ui/app/inputhdl.cxx
M sc/source/ui/app/transobj.cxx
M sc/source/ui/docshell/docsh8.cxx
M sc/source/ui/formdlg/formula.cxx
M sc/source/ui/unoobj/chart2uno.cxx
M sc/source/ui/unoobj/funcuno.cxx
M sc/source/ui/view/output2.cxx
M sc/source/ui/view/tabvwsha.cxx
30 files changed, 358 insertions(+), 379 deletions(-)



diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 373ba8a..9178c92 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -153,6 +153,7 @@
 	sc/source/core/data/postit \
 	sc/source/core/data/segmenttree \
 	sc/source/core/data/sheetevents \
+	sc/source/core/data/simpleformulacalc \
 	sc/source/core/data/sortparam \
 	sc/source/core/data/stlpool \
 	sc/source/core/data/stlsheet \
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index f5d3414..d6ba9f9 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -852,13 +852,7 @@
     SC_DLLPUBLIC sal_uInt32 GetNumberFormat( const ScAddress& ) const;
     void SetNumberFormat( const ScAddress& rPos, sal_uInt32 nNumberFormat );
 
-    /**
-     * If no number format attribute is set and a formula cell pointer is
-     * passed, the calculated number format of the formula cell is returned.
-     * pCell may be NULL.
-     */
-    SC_DLLPUBLIC void GetNumberFormatInfo( short& nType, sal_uLong& nIndex,
-                        const ScAddress& rPos, const ScFormulaCell* pCell ) const;
+    void GetNumberFormatInfo( short& nType, sal_uLong& nIndex, const ScAddress& rPos ) const;
     void            GetFormula( SCCOL nCol, SCROW nRow, SCTAB nTab, String& rFormula ) const;
     const ScTokenArray* GetFormulaTokens( const ScAddress& rPos ) const;
     SC_DLLPUBLIC const ScFormulaCell* GetFormulaCell( const ScAddress& rPos ) const;
diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index 4760062..c6d3aa7 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -77,10 +77,9 @@
     ScFormulaCell*  pPreviousTrack;
     ScFormulaCell*  pNextTrack;
     ScFormulaCellGroupRef xGroup;       // re-factoring hack - group of formulae we're part of.
-    sal_uLong       nFormatIndex;       // Number format set by calculation
-    short           nFormatType;        // Number format type set by calculation
     sal_uInt16      nSeenInIteration;   // Iteration cycle in which the cell was last encountered
     sal_uInt8       cMatrixFlag;        // One of ScMatrixMode
+    short           nFormatType;
     bool            bDirty         : 1; // Must be (re)calculated
     bool            bChanged       : 1; // Whether something changed regarding display/representation
     bool            bRunning       : 1; // Already interpreting right now
@@ -90,6 +89,7 @@
     bool            bInChangeTrack : 1; // Cell is in ChangeTrack
     bool            bTableOpDirty  : 1; // Dirty flag for TableOp
     bool            bNeedListening : 1; // Listeners need to be re-established after UpdateReference
+    bool            mbNeedsNumberFormat : 1; // set the calculated number format as hard number format
 
                     enum ScInterpretTailParameter
                     {
@@ -100,7 +100,6 @@
     void            InterpretTail( ScInterpretTailParameter );
 
     ScFormulaCell( const ScFormulaCell& );
-
 public:
 
     enum CompareState { NotEqual = 0, EqualInvariant, EqualRelativeRef };
@@ -153,6 +152,8 @@
     void            ResetDirty() { bDirty = false; }
     bool            NeedsListening() const { return bNeedListening; }
     void            SetNeedsListening( bool bVar ) { bNeedListening = bVar; }
+    void            SetNeedNumberFormat( bool bVal ) { mbNeedsNumberFormat = bVal; }
+    short           GetFormatType() const { return nFormatType; }
     void            Compile(const OUString& rFormula,
                             bool bNoListening = false,
                             const formula::FormulaGrammar::Grammar = formula::FormulaGrammar::GRAM_DEFAULT );
@@ -214,10 +215,6 @@
     sal_uInt16      GetMatrixEdge( ScAddress& rOrgPos );
     sal_uInt16      GetErrCode();   // interpret first if necessary
     sal_uInt16      GetRawError();  // don't interpret, just return code or result error
-    short           GetFormatType() const                   { return nFormatType; }
-    sal_uLong       GetFormatIndex() const                  { return nFormatIndex; }
-    void            GetFormatInfo( short& nType, sal_uLong& nIndex ) const
-                        { nType = nFormatType; nIndex = nFormatIndex; }
     sal_uInt8       GetMatrixFlag() const                   { return cMatrixFlag; }
     ScTokenArray*   GetCode() const                         { return pCode; }
 
@@ -245,10 +242,6 @@
                     // cell belongs to ChangeTrack and not to the real document
     void            SetInChangeTrack( bool bVal ) { bInChangeTrack = bVal; }
     bool            IsInChangeTrack() const { return bInChangeTrack; }
-
-                    // standard format for type and format
-                    // for format "Standard" possibly the format used in the formula cell
-    sal_uLong       GetStandardFormat( SvNumberFormatter& rFormatter, sal_uLong nFormat ) const;
 
     // For import filters!
     void            AddRecalcMode( formula::ScRecalcMode );
diff --git a/sc/inc/formularesult.hxx b/sc/inc/formularesult.hxx
index 4e6fd39..b337d2f 100644
--- a/sc/inc/formularesult.hxx
+++ b/sc/inc/formularesult.hxx
@@ -23,8 +23,6 @@
 #include "token.hxx"
 #include "scdllapi.h"
 
-#include <sal/log.hxx>
-
 /** Store a variable formula cell result, balancing between runtime performance
     and memory consumption. */
 class ScFormulaResult
diff --git a/sc/inc/simpleformulacalc.hxx b/sc/inc/simpleformulacalc.hxx
new file mode 100644
index 0000000..43ff6ea
--- /dev/null
+++ b/sc/inc/simpleformulacalc.hxx
@@ -0,0 +1,54 @@
+/* -*- 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_SIMPLE_FORMULA_CALC_HXX
+#define SC_SIMPLE_FORMULA_CALC_HXX
+
+#include <boost/scoped_ptr.hpp>
+#include <formula/grammar.hxx>
+
+#include "address.hxx"
+#include "formularesult.hxx"
+
+class ScDocument;
+class ScTokenArray;
+
+class ScSimpleFormulaCalculator
+{
+private:
+    short mnFormatType;
+    sal_uLong mnFormatIndex;
+
+    bool mbCalculated;
+    boost::scoped_ptr<ScTokenArray> mpCode;
+    ScAddress maAddr;
+    ScDocument* mpDoc;
+    ScFormulaResult maResult;
+
+public:
+    ScSimpleFormulaCalculator(ScDocument* pDoc, const ScAddress& rAddr,
+            const OUString& rFormula, formula::FormulaGrammar::Grammar eGram = formula::FormulaGrammar::GRAM_DEFAULT);
+    ~ScSimpleFormulaCalculator();
+
+    void Calculate();
+    bool IsValue();
+    sal_uInt16 GetErrCode();
+    double GetValue();
+    OUString GetString();
+    short GetFormatType() const { return mnFormatType; }
+    sal_uLong GetFormatIndex() const { return mnFormatIndex; }
+
+    bool HasColRowName();
+
+    ScTokenArray* GetCode();
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index dfbc21d..8782552 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -2183,13 +2183,13 @@
             ScBaseCell* pCell = maItems[i].pCell;
             if (pCell->GetCellType() == CELLTYPE_FORMULA)
             {
+                ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell);
 #if OSL_DEBUG_LEVEL > 1
                 // after F9 ctrl-F9: check the calculation for each FormulaTree
-                ScFormulaCell* pFCell = (ScFormulaCell*)pCell;
                 double nOldVal, nNewVal;
                 nOldVal = pFCell->GetValue();
 #endif
-                ((ScFormulaCell*)pCell)->Interpret();
+                pFCell->Interpret();
 #if OSL_DEBUG_LEVEL > 1
                 if ( pFCell->GetCode()->IsRecalcModeNormal() )
                     nNewVal = pFCell->GetValue();
@@ -2214,9 +2214,10 @@
                 SCROW nRow = maItems[i].nRow;
                 // for unconditional compilation
                 // bCompile=true and pCode->nError=0
-                ((ScFormulaCell*)pCell)->GetCode()->SetCodeError( 0 );
-                ((ScFormulaCell*)pCell)->SetCompile( true );
-                ((ScFormulaCell*)pCell)->CompileTokenArray();
+                ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell);
+                pFCell->GetCode()->SetCodeError( 0 );
+                pFCell->SetCompile( true );
+                pFCell->CompileTokenArray();
                 if ( nRow != maItems[i].nRow )
                     Search( nRow, i );      // Listener deleted/inserted?
             }
@@ -2234,7 +2235,14 @@
             if ( pCell->GetCellType() == CELLTYPE_FORMULA )
             {
                 SCROW nRow = maItems[i].nRow;
-                ((ScFormulaCell*)pCell)->CompileXML( rProgress );
+                ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell);
+                sal_uInt32 nCellFormat = GetNumberFormat( nRow );
+                if( (nCellFormat % SV_COUNTRY_LANGUAGE_OFFSET) != 0)
+                    pFCell->SetNeedNumberFormat(false);
+                else
+                    pFCell->SetDirty(true);
+
+                pFCell->CompileXML( rProgress );
                 if ( nRow != maItems[i].nRow )
                     Search( nRow, i );      // Listener deleted/inserted?
             }
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index fbd0c0a..b987a31 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -160,10 +160,7 @@
         // #i111387# disable automatic line breaks only for "General" number format
         if (bBreak && aCell.hasNumeric() && ( nFormat % SV_COUNTRY_LANGUAGE_OFFSET ) == 0 )
         {
-            // also take formula result type into account for number format
-            if (aCell.meType != CELLTYPE_FORMULA ||
-                (aCell.mpFormula->GetStandardFormat(*pFormatter, nFormat) % SV_COUNTRY_LANGUAGE_OFFSET) == 0)
-                bBreak = false;
+            bBreak = false;
         }
 
         //  get other attributes from pattern and conditional formatting
@@ -1477,6 +1474,15 @@
 
 void ScColumn::SetCell( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, ScBaseCell* pNewCell )
 {
+    if(pNewCell->GetCellType() == CELLTYPE_FORMULA)
+    {
+        ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pNewCell);
+        sal_uInt32 nCellFormat = GetNumberFormat( nRow );
+        if( (nCellFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0)
+            pFCell->SetNeedNumberFormat(true);
+
+    }
+
     bool bIsAppended = false;
     if ( !maItems.empty() )
     {
@@ -1513,6 +1519,15 @@
 
 void ScColumn::SetCell( SCROW nRow, ScBaseCell* pNewCell )
 {
+    if(pNewCell->GetCellType() == CELLTYPE_FORMULA)
+    {
+        ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pNewCell);
+        sal_uInt32 nCellFormat = GetNumberFormat( nRow );
+        if( (nCellFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0)
+            pFCell->SetNeedNumberFormat(true);
+
+    }
+
     bool bIsAppended = false;
     if ( !maItems.empty() )
     {
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 60eb8e3..f36dbd0 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1448,13 +1448,22 @@
 void ScColumn::SetFormula( SCROW nRow, const ScTokenArray& rArray, formula::FormulaGrammar::Grammar eGram )
 {
     ScAddress aPos(nCol, nRow, nTab);
-    Insert(nRow, new ScFormulaCell(pDocument, aPos, &rArray, eGram));
+    ScFormulaCell* pCell = new ScFormulaCell(pDocument, aPos, &rArray, eGram);
+    sal_uInt32 nCellFormat = GetNumberFormat( nRow );
+    if( (nCellFormat % SV_COUNTRY_LANGUAGE_OFFSET) != 0)
+        pCell->SetNeedNumberFormat(true);
+    Insert(nRow, pCell);
 }
 
 void ScColumn::SetFormula( SCROW nRow, const OUString& rFormula, formula::FormulaGrammar::Grammar eGram )
 {
     ScAddress aPos(nCol, nRow, nTab);
-    Insert(nRow, new ScFormulaCell(pDocument, aPos, rFormula, eGram));
+    ScFormulaCell* pCell = new ScFormulaCell(pDocument, aPos, rFormula, eGram);
+
+    sal_uInt32 nCellFormat = GetNumberFormat( nRow );
+    if( (nCellFormat % SV_COUNTRY_LANGUAGE_OFFSET) != 0)
+        pCell->SetNeedNumberFormat(true);
+    Insert(nRow, pCell);
 }
 
 void ScColumn::SetFormulaCell( SCROW nRow, ScFormulaCell* pCell )
@@ -1696,6 +1705,11 @@
     {
         ScRefCellValue aCell;
         aCell.assign(*maItems[nIndex].pCell);
+
+        // ugly hack for ordering problem with GetNumberFormat and missing inherited formats
+        if(aCell.meType == CELLTYPE_FORMULA)
+            aCell.mpFormula->MaybeInterpret();
+
         sal_uLong nFormat = GetNumberFormat( nRow );
         ScCellFormat::GetString(aCell, nFormat, rString, &pColor, *(pDocument->GetFormatTable()));
     }
diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx
index b834a0c..8f6d1c2 100644
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@ -415,27 +415,7 @@
     {
         const ScColumn* pCol = &(pDoc->maTabs[nTab])->aCol[nCol];
         nNumFmtIndex = pCol->GetNumberFormat( nRow );
-        if ( (nNumFmtIndex % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
-        {
-            const ScBaseCell* pCell;
-            SCSIZE nIdx = nColRow - 1;
-            // Something might have rearranged; be on the safe side
-            if ( nIdx < pCol->maItems.size() && pCol->maItems[nIdx].nRow == nRow )
-                pCell = pCol->maItems[nIdx].pCell;
-            else
-            {
-                if ( pCol->Search( nRow, nIdx ) )
-                    pCell = pCol->maItems[nIdx].pCell;
-                else
-                    pCell = NULL;
-            }
-            if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA )
-                ((const ScFormulaCell*)pCell)->GetFormatInfo( nNumFmtType, nNumFmtIndex );
-            else
-                nNumFmtType = pDoc->GetFormatTable()->GetType( nNumFmtIndex );
-        }
-        else
-            nNumFmtType = pDoc->GetFormatTable()->GetType( nNumFmtIndex );
+        nNumFmtType = pDoc->GetFormatTable()->GetType( nNumFmtIndex );
         bNumValid = true;
     }
     nType = nNumFmtType;
@@ -612,8 +592,7 @@
                                 rValue.mfValue = ((ScFormulaCell*)pCell)->GetValue();
                                 rValue.mbIsNumber = true;
                                 mpDoc->GetNumberFormatInfo( nNumFmtType,
-                                    nNumFmtIndex, ScAddress(nCol, nRow, nTab),
-                                    static_cast<ScFormulaCell*>(pCell));
+                                    nNumFmtIndex, ScAddress(nCol, nRow, nTab));
                                 rValue.mnError = ((ScFormulaCell*)pCell)->GetErrCode();
                                 return true; // Found it!
                             }
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 34ae049..e631307 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -3320,16 +3320,13 @@
 }
 
 void ScDocument::GetNumberFormatInfo( short& nType, sal_uLong& nIndex,
-            const ScAddress& rPos, const ScFormulaCell* pCell ) const
+            const ScAddress& rPos ) const
 {
     SCTAB nTab = rPos.Tab();
     if ( nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
     {
         nIndex = maTabs[nTab]->GetNumberFormat( rPos );
-        if ( (nIndex % SV_COUNTRY_LANGUAGE_OFFSET) == 0 && pCell)
-            pCell->GetFormatInfo(nType, nIndex);
-        else
-            nType = GetFormatTable()->GetType( nIndex );
+        nType = GetFormatTable()->GetType( nIndex );
     }
     else
     {
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index 98df69a..b75bdcc 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -401,10 +401,9 @@
     pNext(0),
     pPreviousTrack(0),
     pNextTrack(0),
-    nFormatIndex(0),
-    nFormatType( NUMBERFORMAT_NUMBER ),
     nSeenInIteration(0),
     cMatrixFlag ( cMatInd ),
+    nFormatType ( NUMBERFORMAT_NUMBER ),
     bDirty( true ), // -> Because of the use of the Auto Pilot Function was: cMatInd != 0
     bChanged( false ),
     bRunning( false ),
@@ -414,6 +413,7 @@
     bInChangeTrack( false ),
     bTableOpDirty( false ),
     bNeedListening( false ),
+    mbNeedsNumberFormat( false ),
     aPos( rPos )
 {
     Compile( rFormula, true, eGrammar );    // bNoListening, Insert does that
@@ -435,10 +435,9 @@
     pNext(0),
     pPreviousTrack(0),
     pNextTrack(0),
-    nFormatIndex(0),
-    nFormatType( NUMBERFORMAT_NUMBER ),
     nSeenInIteration(0),
     cMatrixFlag ( cInd ),
+    nFormatType ( NUMBERFORMAT_NUMBER ),
     bDirty( NULL != pArr ), // -> Because of the use of the Auto Pilot Function was: cInd != 0
     bChanged( false ),
     bRunning( false ),
@@ -448,6 +447,7 @@
     bInChangeTrack( false ),
     bTableOpDirty( false ),
     bNeedListening( false ),
+    mbNeedsNumberFormat( false ),
     aPos( rPos )
 {
     // UPN-Array generation
@@ -481,10 +481,9 @@
     pNext(0),
     pPreviousTrack(0),
     pNextTrack(0),
-    nFormatIndex( &rDoc == rCell.pDocument ? rCell.nFormatIndex : 0 ),
-    nFormatType( rCell.nFormatType ),
     nSeenInIteration(0),
     cMatrixFlag ( rCell.cMatrixFlag ),
+    nFormatType( rCell.nFormatType ),
     bDirty( rCell.bDirty ),
     bChanged( rCell.bChanged ),
     bRunning( false ),
@@ -494,6 +493,7 @@
     bInChangeTrack( false ),
     bTableOpDirty( false ),
     bNeedListening( false ),
+    mbNeedsNumberFormat( false ),
     aPos( rPos )
 {
     pCode = rCell.pCode->Clone();
@@ -767,7 +767,6 @@
         if( !pCode->GetCodeError() )
         {
             nFormatType = aComp.GetNumFormatType();
-            nFormatIndex = 0;
             bChanged = true;
             aResult.SetToken( NULL);
             bCompile = false;
@@ -817,7 +816,6 @@
         if( !pCode->GetCodeError() )
         {
             nFormatType = aComp.GetNumFormatType();
-            nFormatIndex = 0;
             bChanged = true;
             bCompile = false;
             StartListeningTo( pDocument );
@@ -868,7 +866,6 @@
         aComp.SetGrammar(pDocument->GetGrammar());
         bSubTotal = aComp.CompileTokenArray();
         nFormatType = aComp.GetNumFormatType();
-        nFormatIndex = 0;
         bDirty = true;
         bCompile = false;
         bNewCompiled = true;
@@ -1292,16 +1289,24 @@
             if ( aResult.GetCellResultType() != svUnknown )
                 bContentChanged = true;
         }
-        // Different number format?
-        if( nFormatType != p->GetRetFormatType() )
+
+        if( mbNeedsNumberFormat )
         {
             nFormatType = p->GetRetFormatType();
+            sal_Int32 nFormatIndex = p->GetRetFormatIndex();
+
+            // don't set text format as hard format
+            if(nFormatType == NUMBERFORMAT_TEXT)
+                nFormatIndex = 0;
+            else if((nFormatIndex % SV_COUNTRY_LANGUAGE_OFFSET) == 0)
+                nFormatIndex = ScGlobal::GetStandardFormat(*pDocument->GetFormatTable(),
+                        nFormatIndex, nFormatType);
+
+            // set number format explicitly
+            pDocument->SetNumberFormat( aPos, nFormatIndex );
+
             bChanged = true;
-        }
-        if( nFormatIndex != p->GetRetFormatIndex() )
-        {
-            nFormatIndex = p->GetRetFormatIndex();
-            bChanged = true;
+            mbNeedsNumberFormat = false;
         }
 
         // In case of changes just obtain the result, no temporary and
@@ -1367,11 +1372,6 @@
           && nFormatType != NUMBERFORMAT_DATETIME )
         {
             sal_uLong nFormat = pDocument->GetNumberFormat( aPos );
-            if ( nFormatIndex && (nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
-                nFormat = nFormatIndex;
-            if ( (nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
-                nFormat = ScGlobal::GetStandardFormat(
-                    *pDocument->GetFormatTable(), nFormat, nFormatType );
             aResult.SetDouble( pDocument->RoundValueAsShown(
                         aResult.GetDouble(), nFormat));
         }
@@ -1492,18 +1492,6 @@
         nCols = 0;
         nRows = 0;
     }
-}
-
-
-sal_uLong ScFormulaCell::GetStandardFormat( SvNumberFormatter& rFormatter, sal_uLong nFormat ) const
-{
-    if ( nFormatIndex && (nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
-        return nFormatIndex;
-    //! not ScFormulaCell::IsValue(), that could reinterpret the formula again.
-    if ( aResult.IsValue() )
-        return ScGlobal::GetStandardFormat( aResult.GetDouble(), rFormatter, nFormat, nFormatType );
-    else
-        return ScGlobal::GetStandardFormat( rFormatter, nFormat, nFormatType );
 }
 
 
@@ -1654,10 +1642,7 @@
     sal_uLong nCellFormat = pDocument->GetNumberFormat( aPos );
     SvNumberFormatter* pFormatter = pDocument->GetFormatTable();
 
-    if ( (nCellFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
-        nCellFormat = GetStandardFormat( *pFormatter,nCellFormat );
-
-   sal_uLong nURLFormat = ScGlobal::GetStandardFormat( *pFormatter,nCellFormat, NUMBERFORMAT_NUMBER);
+    sal_uLong nURLFormat = ScGlobal::GetStandardFormat( *pFormatter, nCellFormat, NUMBERFORMAT_NUMBER);
 
     if ( IsValue() )
     {
diff --git a/sc/source/core/data/simpleformulacalc.cxx b/sc/source/core/data/simpleformulacalc.cxx
new file mode 100644
index 0000000..1b2cd35
--- /dev/null
+++ b/sc/source/core/data/simpleformulacalc.cxx
@@ -0,0 +1,100 @@
+/* -*- 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 "simpleformulacalc.hxx"
+#include "document.hxx"
+#include "tokenarray.hxx"
+#include "interpre.hxx"
+#include "compiler.hxx"
+
+
+ScSimpleFormulaCalculator::ScSimpleFormulaCalculator( ScDocument* pDoc, const ScAddress& rAddr,
+        const OUString& rFormula, formula::FormulaGrammar::Grammar eGram ):
+    mbCalculated(false),
+    maAddr(rAddr),
+    mpDoc(pDoc)
+{
+    // compile already here
+    ScCompiler aComp(pDoc, rAddr);
+    aComp.SetGrammar(eGram);
+    mpCode.reset(aComp.CompileString(rFormula));
+    if(!mpCode->GetCodeError() && mpCode->GetLen())
+        aComp.CompileTokenArray();
+}
+
+ScSimpleFormulaCalculator::~ScSimpleFormulaCalculator()
+{
+}
+
+void ScSimpleFormulaCalculator::Calculate()
+{
+    if(mbCalculated)
+        return;
+
+    mbCalculated = true;
+    ScInterpreter aInt(NULL, mpDoc, maAddr, *mpCode.get());
+    aInt.Interpret();
+
+    mnFormatType = aInt.GetRetFormatType();
+    mnFormatIndex = aInt.GetRetFormatIndex();
+    maResult.SetToken(aInt.GetResultToken().get());
+}
+
+bool ScSimpleFormulaCalculator::IsValue()
+{
+    Calculate();
+
+    return maResult.IsValue();
+}
+
+sal_uInt16 ScSimpleFormulaCalculator::GetErrCode()
+{
+    Calculate();
+
+    sal_uInt16 nErr = mpCode->GetCodeError();
+    if (nErr)
+        return nErr;
+    return maResult.GetResultError();
+}
+
+
+double ScSimpleFormulaCalculator::GetValue()
+{
+    Calculate();
+
+    if ((!mpCode->GetCodeError() || mpCode->GetCodeError() == errDoubleRef) &&
+            !maResult.GetResultError())
+        return maResult.GetDouble();
+
+    return 0.0;
+}
+
+OUString ScSimpleFormulaCalculator::GetString()
+{
+    Calculate();
+
+    if ((!mpCode->GetCodeError() || mpCode->GetCodeError() == errDoubleRef) &&
+            !maResult.GetResultError())
+        return maResult.GetString();
+
+    return OUString();
+}
+
+bool ScSimpleFormulaCalculator::HasColRowName()
+{
+    mpCode->Reset();
+    return mpCode->GetNextColRowName() != NULL;
+}
+
+ScTokenArray* ScSimpleFormulaCalculator::GetCode()
+{
+    return mpCode.get();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/tool/cellform.cxx b/sc/source/core/tool/cellform.cxx
index cb7ce81..a33405f 100644
--- a/sc/source/core/tool/cellform.cxx
+++ b/sc/source/core/tool/cellform.cxx
@@ -101,11 +101,6 @@
                 {
                     sal_uInt16 nErrCode = pFCell->GetErrCode();
 
-                    // get the number format only after interpretation (GetErrCode):
-                    if ( (nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
-                        nFormat = pFCell->GetStandardFormat( rFormatter,
-                            nFormat );
-
                     if (nErrCode != 0)
                         rString = ScGlobal::GetErrorString(nErrCode);
                     else if ( pFCell->IsEmptyDisplayedAsString() )
@@ -202,10 +197,6 @@
                 else
                 {
                     sal_uInt16 nErrCode = pFCell->GetErrCode();
-
-                    // get the number format only after interpretation (GetErrCode):
-                    if ((nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0) nFormat = pFCell->GetStandardFormat(rFormatter,
-                                                                                                         nFormat);
 
                     if (nErrCode != 0) aString = ScGlobal::GetErrorString(nErrCode);
                     else if (pFCell->IsEmptyDisplayedAsString()) aString = OUString();
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index 4e0cde4..3be5536 100644
--- a/sc/source/core/tool/interpr2.cxx
+++ b/sc/source/core/tool/interpr2.cxx
@@ -2274,8 +2274,8 @@
 
             //  Nach dem Laden muss neu interpretiert werden (Verknuepfungen aufbauen)
 
-        if ( pMyFormulaCell->GetCode()->IsRecalcModeNormal() )
-            pMyFormulaCell->GetCode()->SetExclusiveRecalcModeOnLoad();
+        if ( rArr.IsRecalcModeNormal() )
+            rArr.SetExclusiveRecalcModeOnLoad();
 
             //  solange der Link nicht ausgewertet ist, Idle abklemmen
             //  (um zirkulaere Referenzen zu vermeiden)
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index adbf268..1f789b9 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -170,8 +170,6 @@
         else
             nErr = 0;
         nFormat = pDok->GetNumberFormat( rPos );
-        if (rCell.meType == CELLTYPE_FORMULA && ((nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0))
-            nFormat = rCell.mpFormula->GetStandardFormat(*pFormatter, nFormat);
     }
 
     SetError(nErr);
@@ -464,7 +462,7 @@
                 {
                     fValue = pFCell->GetValue();
                     pDok->GetNumberFormatInfo( nCurFmtType, nCurFmtIndex,
-                        rPos, pFCell );
+                        rPos );
                 }
                 else
                 {
@@ -980,7 +978,7 @@
     {
         bool bInherited = (aCell.meType == CELLTYPE_FORMULA);
         if (pRetTypeExpr && pRetIndexExpr)
-            pDok->GetNumberFormatInfo(*pRetTypeExpr, *pRetIndexExpr, rAddress, (bInherited ? aCell.mpFormula : NULL));
+            pDok->GetNumberFormatInfo(*pRetTypeExpr, *pRetIndexExpr, rAddress);
         PushTempToken( new ScEmptyCellToken( bInherited, bDisplayEmptyAsString));
         return;
     }
@@ -2647,8 +2645,8 @@
                 else
                 {
                     // nach dem Laden Asyncs wieder anwerfen
-                    if ( pMyFormulaCell->GetCode()->IsRecalcModeNormal() )
-                        pMyFormulaCell->GetCode()->SetExclusiveRecalcModeOnLoad();
+                    if ( rArr.IsRecalcModeNormal() )
+                        rArr.SetExclusiveRecalcModeOnLoad();
                     // garantiert identischer Handle bei identischem Aufruf?!?
                     // sonst schei*e ...
                     double nErg = 0.0;
@@ -3019,9 +3017,9 @@
 
             if ( aCall.HasVarRes() )                        // handle async functions
             {
-                if ( pMyFormulaCell->GetCode()->IsRecalcModeNormal() )
+                if ( rArr.IsRecalcModeNormal() )
                 {
-                    pMyFormulaCell->GetCode()->SetExclusiveRecalcModeOnLoad();
+                    rArr.SetExclusiveRecalcModeOnLoad();
                 }
                 uno::Reference<sheet::XVolatileResult> xRes = aCall.GetVarRes();
                 ScAddInListener* pLis = ScAddInListener::Get( xRes );
@@ -3724,8 +3722,14 @@
 {
     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::ScTTT" );
 
-    sal_uInt8 cMatFlag = pMyFormulaCell->GetMatrixFlag();
-    bMatrixFormula = ( cMatFlag == MM_FORMULA || cMatFlag == MM_FAKE );
+    if(pMyFormulaCell)
+    {
+        sal_uInt8 cMatFlag = pMyFormulaCell->GetMatrixFlag();
+        bMatrixFormula = ( cMatFlag == MM_FORMULA || cMatFlag == MM_FAKE );
+    }
+    else
+        bMatrixFormula = false;
+
     if (!bGlobalStackInUse)
     {
         bGlobalStackInUse = true;
diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx
index fc904a4..df47cf0 100644
--- a/sc/source/core/tool/interpr5.cxx
+++ b/sc/source/core/tool/interpr5.cxx
@@ -3293,7 +3293,7 @@
             else
             {
                 PushDouble(nMatVal.fVal);  // handles DoubleError
-                pDok->GetNumberFormatInfo(nCurFmtType, nCurFmtIndex, aAdr, aCell.mpFormula);
+                pDok->GetNumberFormatInfo(nCurFmtType, nCurFmtIndex, aAdr);
                 nFuncFmtType = nCurFmtType;
                 nFuncFmtIndex = nCurFmtIndex;
             }
@@ -3312,7 +3312,7 @@
             OUString aVal = aCell.mpFormula->GetString();
             PushString( aVal );
         }
-        pDok->GetNumberFormatInfo(nCurFmtType, nCurFmtIndex, aAdr, aCell.mpFormula);
+        pDok->GetNumberFormatInfo(nCurFmtType, nCurFmtIndex, aAdr);
         nFuncFmtType = nCurFmtType;
         nFuncFmtIndex = nCurFmtIndex;
     }
diff --git a/sc/source/filter/excel/xestream.cxx b/sc/source/filter/excel/xestream.cxx
index dacbb1d..bf9c1d8 100644
--- a/sc/source/filter/excel/xestream.cxx
+++ b/sc/source/filter/excel/xestream.cxx
@@ -675,30 +675,29 @@
 
 void XclXmlUtils::GetFormulaTypeAndValue( ScFormulaCell& rCell, const char*& rsType, OUString& rsValue )
 {
+    sal_uInt16 nScErrCode = rCell.GetErrCode();
+    if( nScErrCode )
+    {
+        rsType = "e";
+        rsValue = ToOUString( lcl_GetErrorString( nScErrCode ) );
+
+        return;
+    }
+
     switch( rCell.GetFormatType() )
     {
         case NUMBERFORMAT_NUMBER:
         {
             // either value or error code
-            sal_uInt16 nScErrCode = rCell.GetErrCode();
-            if( nScErrCode )
-            {
-                rsType = "e";
-                rsValue = ToOUString( lcl_GetErrorString( nScErrCode ) );
-            }
-            else
-            {
-                rsType = "n";
-                rsValue = OUString::valueOf( rCell.GetValue() );
-            }
+            rsType = "n";
+            rsValue = OUString::valueOf( rCell.GetValue() );
         }
         break;
 
         case NUMBERFORMAT_TEXT:
         {
             rsType = "str";
-            String aResult = rCell.GetString();
-            rsValue = ToOUString( aResult );
+            rsValue = rCell.GetString();
         }
         break;
 
@@ -712,8 +711,7 @@
         default:
         {
             rsType = "inlineStr";
-            String aResult = rCell.GetString();
-            rsValue = ToOUString( aResult );
+            rsValue = rCell.GetString();
         }
         break;
     }
diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx
index 9c29380..39f2e03 100644
--- a/sc/source/filter/excel/xetable.cxx
+++ b/sc/source/filter/excel/xetable.cxx
@@ -760,55 +760,13 @@
 
 XclExpFormulaCell::XclExpFormulaCell(
         const XclExpRoot& rRoot, const XclAddress& rXclPos,
-        const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
-        const ScFormulaCell& rScFmlaCell,
+        sal_uInt32 nForcedXFId, const ScFormulaCell& rScFmlaCell,
         XclExpArrayBuffer& rArrayBfr,
         XclExpShrfmlaBuffer& rShrfmlaBfr,
         XclExpTableopBuffer& rTableopBfr ) :
     XclExpSingleCellBase( EXC_ID2_FORMULA, 0, rXclPos, nForcedXFId ),
     mrScFmlaCell( const_cast< ScFormulaCell& >( rScFmlaCell ) )
 {
-    // *** Find result number format overwriting cell number format *** -------
-
-    if( GetXFId() == EXC_XFID_NOTFOUND )
-    {
-        SvNumberFormatter& rFormatter = rRoot.GetFormatter();
-        XclExpNumFmtBuffer& rNumFmtBfr = rRoot.GetNumFmtBuffer();
-
-        // current cell number format
-        sal_uLong nScNumFmt = pPattern ?
-            GETITEMVALUE( pPattern->GetItemSet(), SfxUInt32Item, ATTR_VALUE_FORMAT, sal_uLong ) :
-            rNumFmtBfr.GetStandardFormat();
-
-        // alternative number format passed to XF buffer
-        sal_uLong nAltScNumFmt = NUMBERFORMAT_ENTRY_NOT_FOUND;
-        /*  Xcl doesn't know Boolean number formats, we write
-            "TRUE";"FALSE" (language dependent). Don't do it for automatic
-            formula formats, because Excel gets them right. */
-        /*  #i8640# Don't set text format, if we have string results. */
-        short nFormatType = mrScFmlaCell.GetFormatType();
-        if( ((nScNumFmt % SV_COUNTRY_LANGUAGE_OFFSET) == 0) &&
-                (nFormatType != NUMBERFORMAT_LOGICAL) &&
-                (nFormatType != NUMBERFORMAT_TEXT) )
-            nAltScNumFmt = mrScFmlaCell.GetStandardFormat( rFormatter, nScNumFmt );
-        /*  If cell number format is Boolean and automatic formula
-            format is Boolean don't write that ugly special format. */
-        else if( (nFormatType == NUMBERFORMAT_LOGICAL) &&
-                (rFormatter.GetType( nScNumFmt ) == NUMBERFORMAT_LOGICAL) )
-            nAltScNumFmt = rNumFmtBfr.GetStandardFormat();
-
-        // #i41420# find script type according to result type (always latin for numeric results)
-        sal_Int16 nScript = ApiScriptType::LATIN;
-        bool bForceLineBreak = false;
-        if( nFormatType == NUMBERFORMAT_TEXT )
-        {
-            String aResult = mrScFmlaCell.GetString();
-            bForceLineBreak = mrScFmlaCell.IsMultilineResult();
-            nScript = XclExpStringHelper::GetLeadingScriptType( rRoot, aResult );
-        }
-        SetXFId( rRoot.GetXFBuffer().InsertWithNumFmt( pPattern, nScript, nAltScNumFmt, bForceLineBreak ) );
-    }
-
     // *** Convert the formula token array *** --------------------------------
 
     ScAddress aScPos( static_cast< SCCOL >( rXclPos.mnCol ), static_cast< SCROW >( rXclPos.mnRow ), rRoot.GetCurrScTab() );
@@ -929,27 +887,31 @@
 
 void XclExpFormulaCell::WriteContents( XclExpStream& rStrm )
 {
+    sal_uInt16 nScErrCode = mrScFmlaCell.GetErrCode();
+    if( nScErrCode )
+    {
+        rStrm << EXC_FORMULA_RES_ERROR << sal_uInt8( 0 )
+            << XclTools::GetXclErrorCode( nScErrCode )
+            << sal_uInt8( 0 ) << sal_uInt16( 0 )
+            << sal_uInt16( 0xFFFF );
+
+        return;
+    }
+
     // result of the formula
     switch( mrScFmlaCell.GetFormatType() )
     {
         case NUMBERFORMAT_NUMBER:
         {
             // either value or error code
-            sal_uInt16 nScErrCode = mrScFmlaCell.GetErrCode();
-            if( nScErrCode )
-                rStrm << EXC_FORMULA_RES_ERROR << sal_uInt8( 0 )
-                      << XclTools::GetXclErrorCode( nScErrCode )
-                      << sal_uInt8( 0 ) << sal_uInt16( 0 )
-                      << sal_uInt16( 0xFFFF );
-            else
-                rStrm << mrScFmlaCell.GetValue();
+            rStrm << mrScFmlaCell.GetValue();
         }
         break;
 
         case NUMBERFORMAT_TEXT:
         {
-            String aResult = mrScFmlaCell.GetString();
-            if( aResult.Len() || (rStrm.GetRoot().GetBiff() <= EXC_BIFF5) )
+            OUString aResult = mrScFmlaCell.GetString();
+            if( !aResult.isEmpty() || (rStrm.GetRoot().GetBiff() <= EXC_BIFF5) )
             {
                 rStrm << EXC_FORMULA_RES_STRING;
                 mxStringRec.reset( new XclExpStringRec( rStrm.GetRoot(), aResult ) );
@@ -2374,7 +2336,7 @@
             case CELLTYPE_FORMULA:
             {
                 xCell.reset(new XclExpFormulaCell(
-                    GetRoot(), aXclPos, pPattern, nMergeBaseXFId,
+                    GetRoot(), aXclPos, nMergeBaseXFId,
                     *rScCell.mpFormula, maArrayBfr, maShrfmlaBfr, maTableopBfr));
             }
             break;
diff --git a/sc/source/filter/html/htmlexp.cxx b/sc/source/filter/html/htmlexp.cxx
index af79ad7..603dfee 100644
--- a/sc/source/filter/html/htmlexp.cxx
+++ b/sc/source/filter/html/htmlexp.cxx
@@ -1065,9 +1065,6 @@
                 break;
             case CELLTYPE_FORMULA:
                 fVal = aCell.mpFormula->GetValue();
-                if ( (nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
-                    nFormat = ScGlobal::GetStandardFormat( fVal, *pFormatter,
-                        nFormat, aCell.mpFormula->GetFormatType() );
                 break;
             default:
                 OSL_FAIL( "value data with unsupported cell type" );
diff --git a/sc/source/filter/inc/xetable.hxx b/sc/source/filter/inc/xetable.hxx
index 655d6ea..b0253b3 100644
--- a/sc/source/filter/inc/xetable.hxx
+++ b/sc/source/filter/inc/xetable.hxx
@@ -451,8 +451,7 @@
 
 public:
     explicit            XclExpFormulaCell( const XclExpRoot& rRoot, const XclAddress& rXclPos,
-                            const ScPatternAttr* pPattern, sal_uInt32 nForcedXFId,
-                            const ScFormulaCell& rScFmlaCell,
+                            sal_uInt32 nForcedXFId, const ScFormulaCell& rScFmlaCell,
                             XclExpArrayBuffer& rArrayBfr,
                             XclExpShrfmlaBuffer& rShrfmlaBfr,
                             XclExpTableopBuffer& rTableopBfr );
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index b1f83dc..1e838a0 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -1116,6 +1116,7 @@
         {
             ScFormulaCell* pFCell = rXMLImport.GetDocument()->GetFormulaCell(rCurrentPos);
             SetFormulaCell(pFCell);
+            pFCell->SetNeedNumberFormat( true );
         }
     }
     else  //regular value cell
@@ -1347,6 +1348,7 @@
             ScFormulaCell* pNewCell = new ScFormulaCell(pDoc, rCellPos, pCode.get(), eGrammar, MM_NONE);
             SetFormulaCell(pNewCell);
             pDoc->SetFormulaCell(rCellPos, pNewCell);
+            pNewCell->SetNeedNumberFormat( true );
         }
         else if ( aText[0] == '\'' && aText.getLength() > 1 )
         {
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index a4cbb40..2b72e89 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -2929,33 +2929,14 @@
                         bool bIsStandard;
                         OUString sCurrency;
                         GetNumberFormatAttributesExportHelper()->GetCellType(aCell.nNumberFormat, sCurrency, bIsStandard);
-                        if (bIsStandard)
+                        if (pDoc)
                         {
-                            if (pDoc)
+                            GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
+                                    aCell.nNumberFormat, pDoc->GetValue( aCellPos ));
+                            if( getDefaultVersion() >= SvtSaveOptions::ODFVER_012 )
                             {
                                 GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
-                                    pFormulaCell->GetStandardFormat(*pDoc->GetFormatTable(), 0),
-                                    pDoc->GetValue( aCellPos ));
-                                if( getDefaultVersion() > SvtSaveOptions::ODFVER_012 )
-                                {
-                                    GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
-                                            pFormulaCell->GetStandardFormat(*pDoc->GetFormatTable(), 0),
-                                            pDoc->GetValue( aCellPos ), false, XML_NAMESPACE_CALC_EXT, false);
-                                }
-                            }
-                        }
-                        else
-                        {
-                            if (pDoc)
-                            {
-                                GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
-                                        aCell.nNumberFormat, pDoc->GetValue( aCellPos ));
-                                if( getDefaultVersion() > SvtSaveOptions::ODFVER_012 )
-                                {
-                                    GetNumberFormatAttributesExportHelper()->SetNumberFormatAttributes(
-                                            aCell.nNumberFormat, pDoc->GetValue( aCellPos ), false, XML_NAMESPACE_CALC_EXT, false );
-
-                                }
+                                        aCell.nNumberFormat, pDoc->GetValue( aCellPos ), false, XML_NAMESPACE_CALC_EXT, false );
                             }
                         }
                     }
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index 0f6ce72..76e0752 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -70,7 +70,7 @@
 #include "userlist.hxx"
 #include "rfindlst.hxx"
 #include "inputopt.hxx"
-#include "formulacell.hxx"             // fuer Formel-Preview
+#include "simpleformulacalc.hxx"
 #include "compiler.hxx"         // fuer Formel-Preview
 #include "editable.hxx"
 #include "funcdesc.hxx"
@@ -1299,79 +1299,69 @@
 //      Selektion berechnen und als Tip-Hilfe anzeigen
 //
 
-static String lcl_Calculate( const String& rFormula, ScDocument* pDoc, const ScAddress &rPos )
+static OUString lcl_Calculate( const OUString& rFormula, ScDocument* pDoc, const ScAddress &rPos )
 {
     //!     mit ScFormulaDlg::CalcValue zusammenfassen und ans Dokument verschieben !!!!
     //!     (Anfuehrungszeichen bei Strings werden nur hier eingefuegt)
 
-    String aValue;
+    if(rFormula.isEmpty())
+        return String();
 
-    if (rFormula.Len())
+    boost::scoped_ptr<ScSimpleFormulaCalculator> pCalc( new ScSimpleFormulaCalculator( pDoc, rPos, rFormula ) );
+
+    // HACK! um bei ColRowNames kein #REF! zu bekommen,
+    // wenn ein Name eigentlich als Bereich in die Gesamt-Formel
+    // eingefuegt wird, bei der Einzeldarstellung aber als
+    // single-Zellbezug interpretiert wird
+    bool bColRowName = pCalc->HasColRowName();
+    if ( bColRowName )
     {
-        ScFormulaCell* pCell = new ScFormulaCell( pDoc, rPos, rFormula );
-
-        // HACK! um bei ColRowNames kein #REF! zu bekommen,
-        // wenn ein Name eigentlich als Bereich in die Gesamt-Formel
-        // eingefuegt wird, bei der Einzeldarstellung aber als
-        // single-Zellbezug interpretiert wird
-        bool bColRowName = pCell->HasColRowName();
-        if ( bColRowName )
-        {
-            // ColRowName im RPN-Code?
-            if ( pCell->GetCode()->GetCodeLen() <= 1 )
-            {   // ==1: einzelner ist als Parameter immer Bereich
-                // ==0: es waere vielleicht einer, wenn..
-                OUStringBuffer aBraced;
-                aBraced.append('(');
-                aBraced.append(rFormula);
-                aBraced.append(')');
-                delete pCell;
-                pCell = new ScFormulaCell( pDoc, rPos, aBraced.makeStringAndClear() );
-            }
-            else
-                bColRowName = false;
-        }
-
-        sal_uInt16 nErrCode = pCell->GetErrCode();
-        if ( nErrCode == 0 )
-        {
-            SvNumberFormatter& aFormatter = *(pDoc->GetFormatTable());
-            Color* pColor;
-            if ( pCell->IsValue() )
-            {
-                double n = pCell->GetValue();
-                sal_uLong nFormat = aFormatter.GetStandardFormat( n, 0,
-                                pCell->GetFormatType(), ScGlobal::eLnge );
-                aFormatter.GetInputLineString( n, nFormat, aValue );
-                //! display OutputString but insert InputLineString
-            }
-            else
-            {
-                String aStr = pCell->GetString();
-                sal_uLong nFormat = aFormatter.GetStandardFormat(
-                                pCell->GetFormatType(), ScGlobal::eLnge);
-                {
-                OUString sTempIn(aStr);
-                OUString sTempOut(aValue);
-                aFormatter.GetOutputString( sTempIn, nFormat,
-                                            sTempOut, &pColor );
-                aStr = sTempIn;
-                aValue = sTempOut;
-                }
-
-                aValue.Insert('"',0);   // in Anfuehrungszeichen
-                aValue+='"';
-                //! Anfuehrungszeichen im String escapen ????
-            }
-
-            ScRange aTestRange;
-            if ( bColRowName || (aTestRange.Parse(rFormula) & SCA_VALID) )
-                aValue.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " ..." ));       // Bereich
+        // ColRowName im RPN-Code?
+        if ( pCalc->GetCode()->GetCodeLen() <= 1 )
+        {   // ==1: einzelner ist als Parameter immer Bereich
+            // ==0: es waere vielleicht einer, wenn..
+            OUStringBuffer aBraced;
+            aBraced.append('(');
+            aBraced.append(rFormula);
+            aBraced.append(')');
+            pCalc.reset( new ScSimpleFormulaCalculator( pDoc, rPos, aBraced.makeStringAndClear() ) );
         }
         else
-            aValue = ScGlobal::GetErrorString(nErrCode);
-        delete pCell;
+            bColRowName = false;
     }
+
+    sal_uInt16 nErrCode = pCalc->GetErrCode();
+    if ( nErrCode != 0 )
+        return ScGlobal::GetErrorString(nErrCode);
+
+    SvNumberFormatter& aFormatter = *(pDoc->GetFormatTable());
+    OUString aValue;
+    if ( pCalc->IsValue() )
+    {
+        double n = pCalc->GetValue();
+        sal_uLong nFormat = aFormatter.GetStandardFormat( n, 0,
+                pCalc->GetFormatType(), ScGlobal::eLnge );
+        aFormatter.GetInputLineString( n, nFormat, aValue );
+        //! display OutputString but insert InputLineString
+    }
+    else
+    {
+        OUString aStr = pCalc->GetString();
+        sal_uLong nFormat = aFormatter.GetStandardFormat(
+                pCalc->GetFormatType(), ScGlobal::eLnge);
+        {
+            Color* pColor;
+            aFormatter.GetOutputString( aStr, nFormat,
+                    aValue, &pColor );
+        }
+
+        aValue = "\"" + aValue + "\"";
+        //! Anfuehrungszeichen im String escapen ????
+    }
+
+    ScRange aTestRange;
+    if ( bColRowName || (aTestRange.Parse(rFormula) & SCA_VALID) )
+        aValue = aValue + " ...";
 
     return aValue;
 }
@@ -1382,8 +1372,8 @@
     EditView* pActiveView = pTopView ? pTopView : pTableView;
     if ( pActiveView && pActiveViewSh )
     {
-        String aPart = pActiveView->GetSelected();
-        if (!aPart.Len())
+        OUString aPart = pActiveView->GetSelected();
+        if (aPart.isEmpty())
             aPart = pEngine->GetText(0);
         ScDocument* pDoc = pActiveViewSh->GetViewData()->GetDocShell()->GetDocument();
         aValue = lcl_Calculate( aPart, pDoc, aCursorPos );
diff --git a/sc/source/ui/app/transobj.cxx b/sc/source/ui/app/transobj.cxx
index a68adf3..8d77350 100644
--- a/sc/source/ui/app/transobj.cxx
+++ b/sc/source/ui/app/transobj.cxx
@@ -773,7 +773,6 @@
         return;
     }
 
-    SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
     ScRange aRef;
 
     ScCellIterator aIter( pDoc, ScRange(nStartX, nStartY, nSrcTab, nEndX, nEndY, nSrcTab) );
@@ -830,18 +829,6 @@
                     aParam.setTextInput();
                     pDestDoc->SetString(aPos, aStr);
                 }
-            }
-
-            //  number formats
-
-            sal_uLong nOldFormat = ((const SfxUInt32Item*)
-                            pDestDoc->GetAttr(nCol,nRow,nDestTab, ATTR_VALUE_FORMAT))->GetValue();
-            if ( (nOldFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
-            {
-                sal_uLong nNewFormat = pFCell->GetStandardFormat( *pFormatter,
-                    nOldFormat );
-                pDestDoc->ApplyAttr( nCol,nRow,nDestTab,
-                            SfxUInt32Item(ATTR_VALUE_FORMAT, nNewFormat) );
             }
         }
     }
diff --git a/sc/source/ui/docshell/docsh8.cxx b/sc/source/ui/docshell/docsh8.cxx
index 120b386..2eb7b25 100644
--- a/sc/source/ui/docshell/docsh8.cxx
+++ b/sc/source/ui/docshell/docsh8.cxx
@@ -628,12 +628,6 @@
             {
                 sal_uInt32 nFormat;
                 pDoc->GetNumberFormat( nCol, nFirstDataRow, nTab, nFormat );
-                if (aCell.meType == CELLTYPE_FORMULA && ((nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0))
-                {
-                    nFormat = ScGlobal::GetStandardFormat(
-                        aCell.mpFormula->GetValue(), *pNumFmt, nFormat,
-                        aCell.mpFormula->GetFormatType());
-                }
                 switch ( pNumFmt->GetType( nFormat ) )
                 {
                     case NUMBERFORMAT_LOGICAL :
diff --git a/sc/source/ui/formdlg/formula.cxx b/sc/source/ui/formdlg/formula.cxx
index 6b04dc3..522a277 100644
--- a/sc/source/ui/formdlg/formula.cxx
+++ b/sc/source/ui/formdlg/formula.cxx
@@ -39,7 +39,7 @@
 #include "scresid.hxx"
 #include "reffact.hxx"
 #include "document.hxx"
-#include "formulacell.hxx"
+#include "simpleformulacalc.hxx"
 #include "scmod.hxx"
 #include "inputhdl.hxx"
 #include "tabvwsh.hxx"
@@ -184,8 +184,6 @@
         pData->SetMode( (sal_uInt16) eMode );
         String rStrExp = GetMeText();
 
-        pCell = new ScFormulaCell( pDoc, aCursorPos, rStrExp );
-
         Update(rStrExp);
     }
 
@@ -241,8 +239,6 @@
 
         SetMeText(rStrExp);
 
-        pCell = new ScFormulaCell( pDoc, aCursorPos, rStrExp );
-
         Update();
         // Jetzt nochmals zurueckschalten, da evtl. neues Doc geoeffnet wurde!
         pScMod->SetRefInputHdl(NULL);
@@ -260,8 +256,6 @@
         pScMod->SetRefInputHdl(NULL);
         StoreFormEditData(pData);
     } // if (pData) // wird nicht ueber Close zerstoert;
-
-    delete pCell;
 }
 
 sal_Bool ScFormulaDlg::IsInputHdl(ScInputHandler* pHdl)
@@ -316,24 +310,24 @@
 //  --------------------------------------------------------------------------
 bool ScFormulaDlg::calculateValue( const String& rStrExp, String& rStrResult )
 {
-    boost::scoped_ptr<ScFormulaCell> pFCell( new ScFormulaCell( pDoc, aCursorPos, rStrExp ) );
+    boost::scoped_ptr<ScSimpleFormulaCalculator> pFCell( new ScSimpleFormulaCalculator( pDoc, aCursorPos, rStrExp ) );
 
     // HACK! um bei ColRowNames kein #REF! zu bekommen,
     // wenn ein Name eigentlich als Bereich in die Gesamt-Formel
     // eingefuegt wird, bei der Einzeldarstellung aber als
     // single-Zellbezug interpretiert wird
-    sal_Bool bColRowName = pCell->HasColRowName();
+    sal_Bool bColRowName = pFCell->HasColRowName();
     if ( bColRowName )
     {
         // ColRowName im RPN-Code?
-        if ( pCell->GetCode()->GetCodeLen() <= 1 )
+        if ( pFCell->GetCode()->GetCodeLen() <= 1 )
         {   // ==1: einzelner ist als Parameter immer Bereich
             // ==0: es waere vielleicht einer, wenn..
             OUStringBuffer aBraced;
             aBraced.append('(');
             aBraced.append(rStrExp);
             aBraced.append(')');
-            pFCell.reset( new ScFormulaCell( pDoc, aCursorPos, aBraced.makeStringAndClear() ) );
+            pFCell.reset( new ScSimpleFormulaCalculator( pDoc, aCursorPos, aBraced.makeStringAndClear() ) );
         }
         else
             bColRowName = false;
@@ -370,11 +364,6 @@
     }
     else
         rStrResult += ScGlobal::GetErrorString(nErrCode);
-
-    if(!isUserMatrix() && pFCell->GetMatrixFlag())
-    {
-        CheckMatrix();
-    }
 
     return true;
 }
diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx
index c6363a4..832f59c 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -3257,17 +3257,7 @@
 sal_uLong getDisplayNumberFormat(ScDocument* pDoc, const ScAddress& rPos)
 {
     sal_uLong nFormat = pDoc->GetNumberFormat(rPos); // original format from cell.
-    SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
-    if (!pFormatter)
-        return nFormat;
-
-    ScRefCellValue aCell;
-    aCell.assign(*pDoc, rPos);
-    if (aCell.isEmpty() || aCell.meType != CELLTYPE_FORMULA || nFormat)
-        return nFormat;
-
-    // With formula cell, the format may be inferred from the formula result.
-    return aCell.mpFormula->GetStandardFormat(*pFormatter, nFormat);
+    return nFormat;
 }
 
 }
diff --git a/sc/source/ui/unoobj/funcuno.cxx b/sc/source/ui/unoobj/funcuno.cxx
index 22fbf0e..7c57ee9 100644
--- a/sc/source/ui/unoobj/funcuno.cxx
+++ b/sc/source/ui/unoobj/funcuno.cxx
@@ -173,30 +173,6 @@
         pClipDoc->ApplyPatternAreaTab( 0,0, MAXCOL,MAXROW, nSrcTab, aPattern );
     }
 
-    // If the range contains formula cells with default number format,
-    // apply a number format for the formula result
-    ScCellIterator aIter( pClipDoc, rSrcRange );
-    for (bool bHas = aIter.first(); bHas; bHas = aIter.next())
-    {
-        if (aIter.getType() != CELLTYPE_FORMULA)
-            continue;
-
-        ScAddress aCellPos = aIter.GetPos();
-        sal_uInt32 nFormat = pClipDoc->GetNumberFormat(aCellPos);
-        if ( (nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
-        {
-            ScFormulaCell* pFCell = aIter.getFormulaCell();
-            sal_uInt16 nErrCode = pFCell->GetErrCode();
-            if ( nErrCode == 0 && pFCell->IsValue() )
-            {
-                sal_uInt32 nNewFormat = pFCell->GetStandardFormat( *pClipDoc->GetFormatTable(), nFormat );
-                if ( nNewFormat != nFormat )
-                    pClipDoc->ApplyAttr( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(),
-                                         SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) );
-            }
-        }
-    }
-
     ScMarkData aDestMark;
     aDestMark.SelectOneTable( nDestTab );
     aDestMark.SetMarkArea( aNewRange );
diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx
index 7bfcf4e..ae74320 100644
--- a/sc/source/ui/view/output2.cxx
+++ b/sc/source/ui/view/output2.cxx
@@ -155,7 +155,7 @@
     const Size&             GetTextSize() const     { return aTextSize; }
     long                    GetOriginalWidth() const { return nOriginalWidth; }
 
-    sal_uLong GetResultValueFormat( const ScRefCellValue& rCell ) const;
+    sal_uLong GetResultValueFormat() const;
 
     sal_uLong   GetValueFormat() const                  { return nValueFormat; }
     sal_Bool    GetLineBreak() const                    { return bLineBreak; }
@@ -596,18 +596,9 @@
         // If it's formula, the result must be a value.
         if (!pFCell->IsValue())
             return;
-
-        if (pFCell->GetFormatType() != NUMBERFORMAT_NUMBER)
-        {
-            // Make sure the format type implicitly set by the interpreter is
-            // of pure numeric type.  We don't want to adjust date and time
-            // values here.
-            SetHashText();
-            return;
-        }
     }
 
-    sal_uLong nFormat = GetResultValueFormat(rCell);
+    sal_uLong nFormat = GetResultValueFormat();
     if ((nFormat % SV_COUNTRY_LANGUAGE_OFFSET) != 0)
     {
         // Not 'General' number format.  Set hash text and bail out.
@@ -793,15 +784,12 @@
     return aString.SearchChar( pChars ) != STRING_NOTFOUND;
 }
 
-sal_uLong ScDrawStringsVars::GetResultValueFormat( const ScRefCellValue& rCell ) const
+sal_uLong ScDrawStringsVars::GetResultValueFormat() const
 {
     // Get the effective number format, including formula result types.
     // This assumes that a formula cell has already been calculated.
 
-    if ((nValueFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 && rCell.meType == CELLTYPE_FORMULA)
-        return rCell.mpFormula->GetStandardFormat(*pOutput->mpDoc->GetFormatTable(), nValueFormat);
-    else
-        return nValueFormat;
+    return nValueFormat;
 }
 
 //==================================================================
@@ -1685,7 +1673,7 @@
 
                     bool bBreak = ( aVars.GetLineBreak() || aVars.GetHorJust() == SVX_HOR_JUSTIFY_BLOCK );
                     // #i111387# #o11817313# disable automatic line breaks only for "General" number format
-                    if (bBreak && bCellIsValue && (aVars.GetResultValueFormat(aCell) % SV_COUNTRY_LANGUAGE_OFFSET) == 0)
+                    if (bBreak && bCellIsValue && (aVars.GetResultValueFormat() % SV_COUNTRY_LANGUAGE_OFFSET) == 0)
                         bBreak = false;
 
                     bool bRepeat = aVars.IsRepeat() && !bBreak;
diff --git a/sc/source/ui/view/tabvwsha.cxx b/sc/source/ui/view/tabvwsha.cxx
index 1cc39fd..4e2d645 100644
--- a/sc/source/ui/view/tabvwsha.cxx
+++ b/sc/source/ui/view/tabvwsha.cxx
@@ -112,13 +112,6 @@
                 {
                     //  Zahlformat aus Attributen oder Formel
                     pDoc->GetNumberFormat( nPosX, nPosY, nTab, nNumFmt );
-                    if ( (nNumFmt % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
-                    {
-                        ScRefCellValue aCell;
-                        aCell.assign(*pDoc, aCursor);
-                        if (aCell.meType == CELLTYPE_FORMULA)
-                            nNumFmt = aCell.mpFormula->GetStandardFormat(*pFormatter, nNumFmt);
-                    }
                 }
 
                 String aValStr;

-- 
To view, visit https://gerrit.libreoffice.org/4147
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia8199bdc63ee732bada51687df195c9ab9cae9aa
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-4-1
Gerrit-Owner: Markus Mohrhard <markus.mohrhard at googlemail.com>



More information about the LibreOffice mailing list