summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-05-03 03:41:12 +0200
committerKohei Yoshida <kohei.yoshida@suse.de>2013-06-04 01:31:34 +0000
commit2d556a55b136b67fbc010d29ba7f98a8419d1470 (patch)
treec619e24f3c29373a946ed87e1882b3a9347ea75a
parent40c21a597f7c9709c88b398ec74a401a70835b12 (diff)
remove inherited number formats, fdo#60215
Change-Id: Ia8199bdc63ee732bada51687df195c9ab9cae9aa Reviewed-on: https://gerrit.libreoffice.org/4147 Reviewed-by: Kohei Yoshida <kohei.yoshida@suse.de> Tested-by: Kohei Yoshida <kohei.yoshida@suse.de>
-rw-r--r--sc/Library_sc.mk1
-rw-r--r--sc/inc/document.hxx8
-rw-r--r--sc/inc/formulacell.hxx15
-rw-r--r--sc/inc/formularesult.hxx2
-rw-r--r--sc/inc/simpleformulacalc.hxx54
-rw-r--r--sc/source/core/data/column.cxx20
-rw-r--r--sc/source/core/data/column2.cxx23
-rw-r--r--sc/source/core/data/column3.cxx18
-rw-r--r--sc/source/core/data/dociter.cxx25
-rw-r--r--sc/source/core/data/document.cxx7
-rw-r--r--sc/source/core/data/formulacell.cxx59
-rw-r--r--sc/source/core/data/simpleformulacalc.cxx100
-rw-r--r--sc/source/core/tool/cellform.cxx9
-rw-r--r--sc/source/core/tool/interpr2.cxx4
-rw-r--r--sc/source/core/tool/interpr4.cxx24
-rw-r--r--sc/source/core/tool/interpr5.cxx4
-rw-r--r--sc/source/filter/excel/xestream.cxx28
-rw-r--r--sc/source/filter/excel/xetable.cxx70
-rw-r--r--sc/source/filter/html/htmlexp.cxx3
-rw-r--r--sc/source/filter/inc/xetable.hxx3
-rw-r--r--sc/source/filter/xml/xmlcelli.cxx2
-rw-r--r--sc/source/filter/xml/xmlexprt.cxx29
-rw-r--r--sc/source/ui/app/inputhdl.cxx122
-rw-r--r--sc/source/ui/app/transobj.cxx13
-rw-r--r--sc/source/ui/docshell/docsh8.cxx6
-rw-r--r--sc/source/ui/formdlg/formula.cxx21
-rw-r--r--sc/source/ui/unoobj/chart2uno.cxx12
-rw-r--r--sc/source/ui/unoobj/funcuno.cxx24
-rw-r--r--sc/source/ui/view/output2.cxx22
-rw-r--r--sc/source/ui/view/tabvwsha.cxx7
30 files changed, 357 insertions, 378 deletions
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 373ba8a9abd5..9178c925d546 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -153,6 +153,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
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 f5d34144e8ab..d6ba9f94ec7d 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -852,13 +852,7 @@ public:
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 4760062f4f8c..c6d3aa7bfdf6 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -77,10 +77,9 @@ private:
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 @@ private:
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 @@ private:
void InterpretTail( ScInterpretTailParameter );
ScFormulaCell( const ScFormulaCell& );
-
public:
enum CompareState { NotEqual = 0, EqualInvariant, EqualRelativeRef };
@@ -153,6 +152,8 @@ public:
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 @@ public:
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; }
@@ -246,10 +243,6 @@ public:
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 );
/** For import only: set a double result. */
diff --git a/sc/inc/formularesult.hxx b/sc/inc/formularesult.hxx
index 4e6fd393168e..b337d2f73d49 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 000000000000..43ff6eac4acf
--- /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 dfbc21d3115e..878255296911 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -2183,13 +2183,13 @@ void ScColumn::CalcAll()
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 @@ void ScColumn::CompileAll()
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 @@ void ScColumn::CompileXML( ScProgress& rProgress )
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 fbd0c0a26eb0..b987a31ad557 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -160,10 +160,7 @@ long ScColumn::GetNeededSize(
// #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::CopyCellTextAttrsToDocument(SCROW nRow1, SCROW nRow2, ScColumn& r
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( sc::ColumnBlockPosition& rBlockPos, SCROW nRow, ScBaseCe
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 60eb8e3e4340..f36dbd0e7c43 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1448,13 +1448,22 @@ void ScColumn::SetEditText( SCROW nRow, const EditTextObject& rEditText, const S
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 @@ void ScColumn::GetString( SCROW nRow, OUString& rString ) const
{
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 b834a0c33b66..8f6d1c2eaa2f 100644
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@ -415,27 +415,7 @@ void ScValueIterator::GetCurNumFmtInfo( short& nType, sal_uLong& nIndex )
{
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 @@ bool ScDBQueryDataIterator::DataAccessInternal::getCurrent(Value& rValue)
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 34ae049efc3e..e631307dcf3c 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -3320,16 +3320,13 @@ void ScDocument::SetNumberFormat( const ScAddress& rPos, sal_uInt32 nNumberForma
}
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 98df69afe19a..b75bdcc08f06 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -401,10 +401,9 @@ ScFormulaCell::ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos,
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 @@ ScFormulaCell::ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos,
bInChangeTrack( false ),
bTableOpDirty( false ),
bNeedListening( false ),
+ mbNeedsNumberFormat( false ),
aPos( rPos )
{
Compile( rFormula, true, eGrammar ); // bNoListening, Insert does that
@@ -435,10 +435,9 @@ ScFormulaCell::ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos,
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 @@ ScFormulaCell::ScFormulaCell( ScDocument* pDoc, const ScAddress& rPos,
bInChangeTrack( false ),
bTableOpDirty( false ),
bNeedListening( false ),
+ mbNeedsNumberFormat( false ),
aPos( rPos )
{
// UPN-Array generation
@@ -481,10 +481,9 @@ ScFormulaCell::ScFormulaCell( const ScFormulaCell& rCell, ScDocument& rDoc, cons
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 @@ ScFormulaCell::ScFormulaCell( const ScFormulaCell& rCell, ScDocument& rDoc, cons
bInChangeTrack( false ),
bTableOpDirty( false ),
bNeedListening( false ),
+ mbNeedsNumberFormat( false ),
aPos( rPos )
{
pCode = rCell.pCode->Clone();
@@ -767,7 +767,6 @@ void ScFormulaCell::CompileTokenArray( bool bNoListening )
if( !pCode->GetCodeError() )
{
nFormatType = aComp.GetNumFormatType();
- nFormatIndex = 0;
bChanged = true;
aResult.SetToken( NULL);
bCompile = false;
@@ -817,7 +816,6 @@ void ScFormulaCell::CompileXML( ScProgress& rProgress )
if( !pCode->GetCodeError() )
{
nFormatType = aComp.GetNumFormatType();
- nFormatIndex = 0;
bChanged = true;
bCompile = false;
StartListeningTo( pDocument );
@@ -868,7 +866,6 @@ void ScFormulaCell::CalcAfterLoad()
aComp.SetGrammar(pDocument->GetGrammar());
bSubTotal = aComp.CompileTokenArray();
nFormatType = aComp.GetNumFormatType();
- nFormatIndex = 0;
bDirty = true;
bCompile = false;
bNewCompiled = true;
@@ -1292,16 +1289,24 @@ void ScFormulaCell::InterpretTail( ScInterpretTailParameter eTailParam )
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 @@ void ScFormulaCell::InterpretTail( ScInterpretTailParameter eTailParam )
&& 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));
}
@@ -1495,18 +1495,6 @@ void ScFormulaCell::GetMatColsRows( SCCOL & nCols, SCROW & nRows ) const
}
-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 );
-}
-
-
void ScFormulaCell::Notify( SvtBroadcaster&, const SfxHint& rHint)
{
if ( !pDocument->IsInDtorClear() && !pDocument->GetHardRecalcState() )
@@ -1654,10 +1642,7 @@ void ScFormulaCell::GetURLResult( OUString& rURL, OUString& rCellText )
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 000000000000..1b2cd35f3b19
--- /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 cb7ce81996e6..a33405f9a05a 100644
--- a/sc/source/core/tool/cellform.cxx
+++ b/sc/source/core/tool/cellform.cxx
@@ -101,11 +101,6 @@ void ScCellFormat::GetString( ScRefCellValue& rCell, sal_uLong nFormat, OUString
{
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() )
@@ -203,10 +198,6 @@ OUString ScCellFormat::GetString(
{
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();
else if (pFCell->IsValue())
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index 4e0cde4fc896..3be5536b3591 100644
--- a/sc/source/core/tool/interpr2.cxx
+++ b/sc/source/core/tool/interpr2.cxx
@@ -2274,8 +2274,8 @@ void ScInterpreter::ScDde()
// 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 adbf2685cb9e..1f789b96b333 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -170,8 +170,6 @@ sal_uLong ScInterpreter::GetCellNumberFormat( const ScAddress& rPos, ScRefCellVa
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 @@ double ScInterpreter::GetCellValueOrZero( const ScAddress& rPos, ScRefCellValue&
{
fValue = pFCell->GetValue();
pDok->GetNumberFormatInfo( nCurFmtType, nCurFmtIndex,
- rPos, pFCell );
+ rPos );
}
else
{
@@ -980,7 +978,7 @@ void ScInterpreter::PushCellResultToken( bool bDisplayEmptyAsString,
{
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 @@ void ScInterpreter::ScExternal()
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 @@ void ScInterpreter::ScExternal()
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 @@ ScInterpreter::ScInterpreter( ScFormulaCell* pCell, ScDocument* pDoc,
{
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 fc904a4d5648..df47cf0d7a31 100644
--- a/sc/source/core/tool/interpr5.cxx
+++ b/sc/source/core/tool/interpr5.cxx
@@ -3293,7 +3293,7 @@ void ScInterpreter::ScMatRef()
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 @@ void ScInterpreter::ScMatRef()
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 dacbb1dfd8f6..bf9c1d84f779 100644
--- a/sc/source/filter/excel/xestream.cxx
+++ b/sc/source/filter/excel/xestream.cxx
@@ -675,30 +675,29 @@ static const char* lcl_GetErrorString( sal_uInt16 nScErrCode )
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 @@ void XclXmlUtils::GetFormulaTypeAndValue( ScFormulaCell& rCell, const char*& rsT
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 9c293807f7f7..39f2e038e239 100644
--- a/sc/source/filter/excel/xetable.cxx
+++ b/sc/source/filter/excel/xetable.cxx
@@ -760,55 +760,13 @@ IMPL_FIXEDMEMPOOL_NEWDEL( XclExpFormulaCell )
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::SaveXml( XclExpXmlStream& rStrm )
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 @@ XclExpCellTable::XclExpCellTable( const XclExpRoot& rRoot ) :
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 af79ad720337..603dfee65738 100644
--- a/sc/source/filter/html/htmlexp.cxx
+++ b/sc/source/filter/html/htmlexp.cxx
@@ -1065,9 +1065,6 @@ void ScHTMLExport::WriteCell( SCCOL nCol, SCROW nRow, SCTAB nTab )
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 655d6ea6cc3e..b0253b3c21ce 100644
--- a/sc/source/filter/inc/xetable.hxx
+++ b/sc/source/filter/inc/xetable.hxx
@@ -451,8 +451,7 @@ class XclExpFormulaCell : public XclExpSingleCellBase
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 b1f83dc9c920..1e838a0f350c 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -1116,6 +1116,7 @@ void ScXMLTableRowCellContext::PutValueCell( const ScAddress& rCurrentPos )
{
ScFormulaCell* pFCell = rXMLImport.GetDocument()->GetFormulaCell(rCurrentPos);
SetFormulaCell(pFCell);
+ pFCell->SetNeedNumberFormat( true );
}
}
else //regular value cell
@@ -1347,6 +1348,7 @@ void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos )
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 a4cbb407b68f..2b72e894df0e 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -2929,33 +2929,14 @@ void ScXMLExport::WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount)
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 0f6ce7228342..76e07524be07 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,80 +1299,70 @@ void ScInputHandler::PasteFunctionData()
// 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.Len())
- {
- 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;
+ if(rFormula.isEmpty())
+ return String();
+
+ 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 )
+ {
+ // 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
+ bColRowName = false;
+ }
- sal_uInt16 nErrCode = pCell->GetErrCode();
- if ( nErrCode == 0 )
+ 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);
{
- 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
+ aFormatter.GetOutputString( aStr, nFormat,
+ aValue, &pColor );
}
- else
- aValue = ScGlobal::GetErrorString(nErrCode);
- delete pCell;
+
+ aValue = "\"" + aValue + "\"";
+ //! Anfuehrungszeichen im String escapen ????
}
+ ScRange aTestRange;
+ if ( bColRowName || (aTestRange.Parse(rFormula) & SCA_VALID) )
+ aValue = aValue + " ...";
+
return aValue;
}
@@ -1382,8 +1372,8 @@ void ScInputHandler::FormulaPreview()
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 a68adf368d41..8d773501e93c 100644
--- a/sc/source/ui/app/transobj.cxx
+++ b/sc/source/ui/app/transobj.cxx
@@ -773,7 +773,6 @@ void ScTransferObj::StripRefs( ScDocument* pDoc,
return;
}
- SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
ScRange aRef;
ScCellIterator aIter( pDoc, ScRange(nStartX, nStartY, nSrcTab, nEndX, nEndY, nSrcTab) );
@@ -831,18 +830,6 @@ void ScTransferObj::StripRefs( ScDocument* pDoc,
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 120b3863dfed..2eb7b253dd7d 100644
--- a/sc/source/ui/docshell/docsh8.cxx
+++ b/sc/source/ui/docshell/docsh8.cxx
@@ -628,12 +628,6 @@ void lcl_GetColumnTypes(
{
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 6b04dc3435b9..522a277bf875 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 @@ ScFormulaDlg::ScFormulaDlg( SfxBindings* pB, SfxChildWindow* pCW,
pData->SetMode( (sal_uInt16) eMode );
String rStrExp = GetMeText();
- pCell = new ScFormulaCell( pDoc, aCursorPos, rStrExp );
-
Update(rStrExp);
}
@@ -241,8 +239,6 @@ void ScFormulaDlg::fill()
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 @@ ScFormulaDlg::~ScFormulaDlg()
pScMod->SetRefInputHdl(NULL);
StoreFormEditData(pData);
} // if (pData) // wird nicht ueber Close zerstoert;
-
- delete pCell;
}
sal_Bool ScFormulaDlg::IsInputHdl(ScInputHandler* pHdl)
@@ -316,24 +310,24 @@ sal_Bool ScFormulaDlg::Close()
// --------------------------------------------------------------------------
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;
@@ -371,11 +365,6 @@ bool ScFormulaDlg::calculateValue( const String& rStrExp, String& rStrResult )
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 c6363a4a7fe7..832f59c4e878 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -3257,17 +3257,7 @@ namespace {
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 22fbf0ecb091..7c57ee919c7f 100644
--- a/sc/source/ui/unoobj/funcuno.cxx
+++ b/sc/source/ui/unoobj/funcuno.cxx
@@ -173,30 +173,6 @@ static sal_Bool lcl_CopyData( ScDocument* pSrcDoc, const ScRange& rSrcRange,
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 7bfcf4e53cf7..ae74320ea335 100644
--- a/sc/source/ui/view/output2.cxx
+++ b/sc/source/ui/view/output2.cxx
@@ -155,7 +155,7 @@ public:
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 @@ void ScDrawStringsVars::SetTextToWidthOrHash( ScRefCellValue& rCell, long nWidth
// 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 @@ sal_Bool ScDrawStringsVars::HasEditCharacters() const
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 @@ void ScOutputData::DrawStrings( sal_Bool bPixelToLogic )
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 1cc39fd33ced..4e2d64517473 100644
--- a/sc/source/ui/view/tabvwsha.cxx
+++ b/sc/source/ui/view/tabvwsha.cxx
@@ -112,13 +112,6 @@ sal_Bool ScTabViewShell::GetFunction( String& rFuncStr, sal_uInt16 nErrCode )
{
// 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;