summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-03-25 10:37:25 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-03-26 01:41:18 -0400
commit04e265e9dbe34d7417a9aefc095510979fcc8658 (patch)
treee3520151ca6299bd32da60ccf5235ec43426fa88
parent0e9e3be6f51436c1e5bf1481a434a85e334c09ea (diff)
Add variant of GetCellValue() that takes ScCellIterator instead of ScBaseCell.
And hopefully we can eventually remove the original one that takes ScBaseCell somehow... Change-Id: I162c8072aa2c699abfd3eb202b90a6331123eb1b
-rw-r--r--sc/source/core/inc/interpre.hxx3
-rw-r--r--sc/source/core/tool/interpr4.cxx173
-rw-r--r--sc/source/core/tool/interpr5.cxx5
3 files changed, 128 insertions, 53 deletions
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index 906f4d692d4c..760a0c7239bb 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -51,6 +51,7 @@ struct ScComplexRefData;
class ScToken;
class ScJumpMatrix;
+class ScCellIterator;
#define MAXSTACK (4096 / sizeof(formula::FormulaToken*))
@@ -186,7 +187,9 @@ bool IsTableOpInRange( const ScRange& );
sal_uLong GetCellNumberFormat( const ScAddress&, const ScBaseCell* );
double ConvertStringToValue( const String& );
double GetCellValue( const ScAddress&, const ScBaseCell* );
+double GetCellValue( ScCellIterator& rIter );
double GetCellValueOrZero( const ScAddress&, const ScBaseCell* );
+double GetCellValueOrZero( ScCellIterator& rIter );
double GetValueCellValue( const ScAddress&, const ScValueCell* );
ScBaseCell* GetCell( const ScAddress& rPos );
void GetCellString( String& rStr, const ScBaseCell* pCell );
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index 752c595cfb40..bfd949486861 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -470,77 +470,152 @@ double ScInterpreter::GetCellValue( const ScAddress& rPos, const ScBaseCell* pCe
return nVal;
}
+double ScInterpreter::GetCellValue( ScCellIterator& rIter )
+{
+ sal_uInt16 nErr = nGlobalError;
+ nGlobalError = 0;
+ double nVal = GetCellValueOrZero(rIter);
+ if ( !nGlobalError || nGlobalError == errCellNoValue )
+ nGlobalError = nErr;
+ return nVal;
+}
double ScInterpreter::GetCellValueOrZero( const ScAddress& rPos, const ScBaseCell* pCell )
{
RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::GetCellValueOrZero" );
double fValue = 0.0;
- if (pCell)
+ if (!pCell)
+ return fValue;
+
+ CellType eType = pCell->GetCellType();
+ switch (eType)
{
- CellType eType = pCell->GetCellType();
- switch ( eType )
+ case CELLTYPE_FORMULA:
{
- case CELLTYPE_FORMULA:
+ ScFormulaCell* pFCell = (ScFormulaCell*) pCell;
+ sal_uInt16 nErr = pFCell->GetErrCode();
+ if( !nErr )
{
- ScFormulaCell* pFCell = (ScFormulaCell*) pCell;
- sal_uInt16 nErr = pFCell->GetErrCode();
- if( !nErr )
+ if (pFCell->IsValue())
{
- if (pFCell->IsValue())
- {
- fValue = pFCell->GetValue();
- pDok->GetNumberFormatInfo( nCurFmtType, nCurFmtIndex,
- rPos, pFCell );
- }
- else
- {
- String aStr = pFCell->GetString();
- fValue = ConvertStringToValue( aStr );
- }
+ fValue = pFCell->GetValue();
+ pDok->GetNumberFormatInfo( nCurFmtType, nCurFmtIndex,
+ rPos, pFCell );
}
else
{
- fValue = 0.0;
- SetError(nErr);
+ String aStr = pFCell->GetString();
+ fValue = ConvertStringToValue( aStr );
}
}
- break;
- case CELLTYPE_VALUE:
+ else
{
- fValue = ((ScValueCell*)pCell)->GetValue();
- nCurFmtIndex = pDok->GetNumberFormat( rPos );
- nCurFmtType = pFormatter->GetType( nCurFmtIndex );
- if ( bCalcAsShown && fValue != 0.0 )
- fValue = pDok->RoundValueAsShown( fValue, nCurFmtIndex );
+ fValue = 0.0;
+ SetError(nErr);
}
- break;
- case CELLTYPE_STRING:
- case CELLTYPE_EDIT:
+ }
+ break;
+ case CELLTYPE_VALUE:
+ {
+ fValue = ((ScValueCell*)pCell)->GetValue();
+ nCurFmtIndex = pDok->GetNumberFormat( rPos );
+ nCurFmtType = pFormatter->GetType( nCurFmtIndex );
+ if ( bCalcAsShown && fValue != 0.0 )
+ fValue = pDok->RoundValueAsShown( fValue, nCurFmtIndex );
+ }
+ break;
+ case CELLTYPE_STRING:
+ case CELLTYPE_EDIT:
+ {
+ // SUM(A1:A2) differs from A1+A2. No good. But people insist on
+ // it ... #i5658#
+ String aStr;
+ if ( eType == CELLTYPE_STRING )
+ aStr = ((ScStringCell*)pCell)->GetString();
+ else
+ aStr = ((ScEditCell*)pCell)->GetString();
+ fValue = ConvertStringToValue( aStr );
+ }
+ break;
+ case CELLTYPE_NONE:
+ case CELLTYPE_NOTE:
+ fValue = 0.0; // empty or broadcaster cell
+ break;
+#if OSL_DEBUG_LEVEL > 0
+ case CELLTYPE_DESTROYED:
+#endif
+ SetError(errCellNoValue);
+ fValue = 0.0;
+ break;
+ }
+
+ return fValue;
+}
+
+double ScInterpreter::GetCellValueOrZero( ScCellIterator& rIter )
+{
+ RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::GetCellValueOrZero" );
+ double fValue = 0.0;
+
+ CellType eType = rIter.getType();
+ const ScAddress& rPos = rIter.GetPos();
+ switch (eType)
+ {
+ case CELLTYPE_FORMULA:
+ {
+ ScFormulaCell* pFCell = rIter.getFormulaCell();
+ sal_uInt16 nErr = pFCell->GetErrCode();
+ if( !nErr )
{
- // SUM(A1:A2) differs from A1+A2. No good. But people insist on
- // it ... #i5658#
- String aStr;
- if ( eType == CELLTYPE_STRING )
- aStr = ((ScStringCell*)pCell)->GetString();
+ if (pFCell->IsValue())
+ {
+ fValue = pFCell->GetValue();
+ pDok->GetNumberFormatInfo( nCurFmtType, nCurFmtIndex,
+ rPos, pFCell );
+ }
else
- aStr = ((ScEditCell*)pCell)->GetString();
- fValue = ConvertStringToValue( aStr );
+ {
+ String aStr = pFCell->GetString();
+ fValue = ConvertStringToValue( aStr );
+ }
}
- break;
- case CELLTYPE_NONE:
- case CELLTYPE_NOTE:
- fValue = 0.0; // empty or broadcaster cell
- break;
-#if OSL_DEBUG_LEVEL > 0
- case CELLTYPE_DESTROYED:
-#endif
- SetError(errCellNoValue);
+ else
+ {
fValue = 0.0;
- break;
+ SetError(nErr);
+ }
+ }
+ break;
+ case CELLTYPE_VALUE:
+ {
+ fValue = rIter.getValue();
+ nCurFmtIndex = pDok->GetNumberFormat( rPos );
+ nCurFmtType = pFormatter->GetType( nCurFmtIndex );
+ if ( bCalcAsShown && fValue != 0.0 )
+ fValue = pDok->RoundValueAsShown( fValue, nCurFmtIndex );
+ }
+ break;
+ case CELLTYPE_STRING:
+ case CELLTYPE_EDIT:
+ {
+ // SUM(A1:A2) differs from A1+A2. No good. But people insist on
+ // it ... #i5658#
+ OUString aStr = rIter.getString();
+ fValue = ConvertStringToValue( aStr );
}
+ break;
+ case CELLTYPE_NONE:
+ case CELLTYPE_NOTE:
+ fValue = 0.0; // empty or broadcaster cell
+ break;
+#if OSL_DEBUG_LEVEL > 0
+ case CELLTYPE_DESTROYED:
+#endif
+ SetError(errCellNoValue);
+ fValue = 0.0;
+ break;
}
- else
- fValue = 0.0;
+
return fValue;
}
diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx
index 74bccc74fffe..28e3b9722b62 100644
--- a/sc/source/core/tool/interpr5.cxx
+++ b/sc/source/core/tool/interpr5.cxx
@@ -437,10 +437,7 @@ ScMatrixRef ScInterpreter::CreateMatrixFromDoubleRef( const FormulaToken* pToken
if (aCellIter.hasNumeric())
{
ScAddress aAdr(nCol, nThisRow, nTab1);
-
- // TODO: Come back to this and fix it.
- ScBaseCell* pBC = pDok->GetCell(aAdr);
- double fVal = GetCellValue(aAdr, pBC);
+ double fVal = GetCellValue(aCellIter);
if ( nGlobalError )
{