More consistent number format inheritence policy.
The new policy is to always inherit number format of a formula cell
from its reference unless the cell already has an explicit number format
set.
Also to avoid recalculating formula cells on load just because they have
the 'General' number format. This leads to excessive re-calculation of
formula cells upon load even when the cells already have results cached.
Change-Id: I28128d3fef296e09e62bea72e8aab75de9876239
diff --git a/sc/inc/formulacell.hxx b/sc/inc/formulacell.hxx
index 6f3c555..f2bc36c 100644
--- a/sc/inc/formulacell.hxx
+++ b/sc/inc/formulacell.hxx
@@ -210,6 +210,7 @@ public:
void SetNeedsListening( bool bVar );
void SetNeedsDirty( bool bVar );
void SetNeedNumberFormat( bool bVal );
bool NeedsNumberFormat() const;
short GetFormatType() const;
void Compile(const OUString& rFormula,
bool bNoListening = false,
diff --git a/sc/qa/unit/data/contentCSV/cachedValue.csv b/sc/qa/unit/data/contentCSV/cachedValue.csv
index 7fed884..597eda1 100644
--- a/sc/qa/unit/data/contentCSV/cachedValue.csv
+++ b/sc/qa/unit/data/contentCSV/cachedValue.csv
@@ -1,2 +1,2 @@
1.00,200.00%,$3.00,1/3/00,00:00,6.00E+000,7 1/5,TRUE,9,1000%,01-10
1,200.00%,$3.00,01/03/00,12:00:00 AM,6.00E+000,7 1/5,TRUE,9,1000.00%,01/10/00
1.00,200.00%,$3.00,1/3/00,12:00:00 AM,6.00E+000,7 1/5,TRUE,9,1000.00%,01-10
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index b7fd479..8b74fcf 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -3121,8 +3121,12 @@ public:
{
sal_uInt32 nFormat = mrCol.GetNumberFormat(nRow);
if( (nFormat % SV_COUNTRY_LANGUAGE_OFFSET) != 0)
// Non-default number format is set.
pCell->SetNeedNumberFormat(false);
else
else if (pCell->NeedsNumberFormat())
pCell->SetDirtyVar();
if (pCell->GetMatrixFlag())
pCell->SetDirtyVar();
pCell->CompileXML(mrCxt, mrProgress);
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 38eb94e..8b4b619 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -2749,12 +2749,7 @@ void ScColumn::SetFormulaResults( SCROW nRow, const formula::FormulaTokenRef* pR
void ScColumn::SetNumberFormat( SCROW nRow, sal_uInt32 nNumberFormat )
{
short eOldType = pDocument->GetFormatTable()->GetType(
(sal_uLong)((SfxUInt32Item*)GetAttr(nRow, ATTR_VALUE_FORMAT))->GetValue());
short eNewType = pDocument->GetFormatTable()->GetType(nNumberFormat);
if (!pDocument->GetFormatTable()->IsCompatible(eOldType, eNewType))
ApplyAttr(nRow, SfxUInt32Item(ATTR_VALUE_FORMAT, nNumberFormat));
ApplyAttr(nRow, SfxUInt32Item(ATTR_VALUE_FORMAT, nNumberFormat));
}
const ScFormulaCell* ScColumn::FetchFormulaCell( SCROW nRow ) const
diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx
index c8aa429..5b23770 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -976,6 +976,12 @@ void ScFormulaCell::SetNeedsDirty( bool bVar )
}
void ScFormulaCell::SetNeedNumberFormat( bool bVal ) { mbNeedsNumberFormat = bVal; }
bool ScFormulaCell::NeedsNumberFormat() const
{
return mbNeedsNumberFormat;
}
short ScFormulaCell::GetFormatType() const { return nFormatType; }
void ScFormulaCell::Compile( const OUString& rFormula, bool bNoListening,
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index c1be178..6a50c76 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -4486,9 +4486,6 @@ StackVar ScInterpreter::Interpret()
}
else
nRetFmtType = NUMBERFORMAT_NUMBER;
// inherit the format index only for currency formats
if ( nRetFmtType != NUMBERFORMAT_CURRENCY )
nRetFmtIndex = 0;
if (nGlobalError && GetStackType() != svError )
PushError( nGlobalError);
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index be0a75e..c61657e 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -163,7 +163,8 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
mbPossibleErrorCell(false),
mbCheckWithCompilerForError(false),
mbEditEngineHasText(false),
mbHasFormatRuns(false)
mbHasFormatRuns(false),
mbHasStyle(false)
{
rtl::math::setNan(&fValue); // NaN by default
@@ -185,6 +186,7 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
{
case XML_TOK_TABLE_ROW_CELL_ATTR_STYLE_NAME:
pStyleName = new OUString(sValue);
mbHasStyle = true;
break;
case XML_TOK_TABLE_ROW_CELL_ATTR_CONTENT_VALIDATION_NAME:
OSL_ENSURE(!maContentValidationName, "here should be only one Validation Name");
@@ -1376,7 +1378,9 @@ void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos )
ScFormulaCell* pNewCell = new ScFormulaCell(pDoc, rCellPos, *pCode, eGrammar, MM_NONE);
SetFormulaCell(pNewCell);
rDoc.setFormulaCell(rCellPos, pNewCell);
pNewCell->SetNeedNumberFormat( true );
// Re-calculate to get number format only when style is not set.
pNewCell->SetNeedNumberFormat(!mbHasStyle);
}
else if ( aText[0] == '\'' && aText.getLength() > 1 )
{
diff --git a/sc/source/filter/xml/xmlcelli.hxx b/sc/source/filter/xml/xmlcelli.hxx
index 15c95fb..6fbcca5 100644
--- a/sc/source/filter/xml/xmlcelli.hxx
+++ b/sc/source/filter/xml/xmlcelli.hxx
@@ -94,6 +94,7 @@ class ScXMLTableRowCellContext : public ScXMLImportContext
bool mbCheckWithCompilerForError;
bool mbEditEngineHasText;
bool mbHasFormatRuns;
bool mbHasStyle;
sal_Int16 GetCellType(const OUString& sOUValue) const;