From e0820c761f37169a0ab02e8b9bf64c328ffdc29e Mon Sep 17 00:00:00 2001 From: Dennis Francis Date: Tue, 8 May 2018 14:57:15 +0530 Subject: Let ScDocument::RoundValueAsShown accept optional... interpreter context for getting format table from it rather than accessing the format table from the document if possible. Always use interpreter context to obtain number format via ScDocument::GetNumberFormat() whenever possible. Change-Id: Ib812cda25dc2e80bc79c81d26bc7c7b8a5c997e1 Reviewed-on: https://gerrit.libreoffice.org/53970 Tested-by: Jenkins Reviewed-by: Michael Meeks --- sc/inc/document.hxx | 2 +- sc/source/core/data/documen4.cxx | 5 +++-- sc/source/core/data/formulacell.cxx | 14 +++++++------- sc/source/core/tool/interpr4.cxx | 4 ++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index e62c2e47f7c2..77dfca451d2a 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1124,7 +1124,7 @@ public: SC_DLLPUBLIC void GetValue( SCCOL nCol, SCROW nRow, SCTAB nTab, double& rValue ) const; SC_DLLPUBLIC const EditTextObject* GetEditText( const ScAddress& rPos ) const; void RemoveEditTextCharAttribs( const ScAddress& rPos, const ScPatternAttr& rAttr ); - SC_DLLPUBLIC double RoundValueAsShown( double fVal, sal_uInt32 nFormat ) const; + SC_DLLPUBLIC double RoundValueAsShown( double fVal, sal_uInt32 nFormat, const ScInterpreterContext* pContext = nullptr ) const; SC_DLLPUBLIC void GetNumberFormat( SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt32& rFormat ) const; sal_uInt32 GetNumberFormat( const ScRange& rRange ) const; diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx index 0b387179e306..58f7c82aedc1 100644 --- a/sc/source/core/data/documen4.cxx +++ b/sc/source/core/data/documen4.cxx @@ -653,9 +653,10 @@ bool ScDocument::GetSelectionFunction( ScSubTotalFunc eFunc, return !aData.bError; } -double ScDocument::RoundValueAsShown( double fVal, sal_uInt32 nFormat ) const +double ScDocument::RoundValueAsShown( double fVal, sal_uInt32 nFormat, const ScInterpreterContext* pContext ) const { - const SvNumberformat* pFormat = GetFormatTable()->GetEntry( nFormat ); + const SvNumberFormatter* pFormatter = pContext ? pContext->GetFormatTable() : GetFormatTable(); + const SvNumberformat* pFormat = pFormatter->GetEntry( nFormat ); SvNumFormatType nType; if (pFormat && (nType = pFormat->GetMaskedType()) != SvNumFormatType::DATE && nType != SvNumFormatType::TIME && nType != SvNumFormatType::DATETIME ) diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index 7d06d2961cde..d0833e1296f0 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -1904,8 +1904,8 @@ void ScFormulaCell::InterpretTail( ScInterpreterContext& rContext, ScInterpretTa bForceNumberFormat = false; else { - nOldFormatIndex = pDocument->GetNumberFormat( aPos); - nFormatType = pDocument->GetFormatTable()->GetType( nOldFormatIndex); + nOldFormatIndex = pDocument->GetNumberFormat( rContext, aPos); + nFormatType = rContext.GetFormatTable()->GetType( nOldFormatIndex); switch (nFormatType) { case SvNumFormatType::PERCENT: @@ -1930,11 +1930,11 @@ void ScFormulaCell::InterpretTail( ScInterpreterContext& rContext, ScInterpretTa { if (nOldFormatIndex == NUMBERFORMAT_ENTRY_NOT_FOUND) { - nOldFormatIndex = pDocument->GetNumberFormat( aPos); - nFormatType = pDocument->GetFormatTable()->GetType( nOldFormatIndex); + nOldFormatIndex = pDocument->GetNumberFormat( rContext, aPos); + nFormatType = rContext.GetFormatTable()->GetType( nOldFormatIndex); } if (nOldFormatIndex != - ScGlobal::GetStandardFormat( *pDocument->GetFormatTable(), nOldFormatIndex, nFormatType)) + ScGlobal::GetStandardFormat( *rContext.GetFormatTable(), nOldFormatIndex, nFormatType)) bForceNumberFormat = false; } } @@ -2065,9 +2065,9 @@ void ScFormulaCell::InterpretTail( ScInterpreterContext& rContext, ScInterpretTa && nFormatType != SvNumFormatType::TIME && nFormatType != SvNumFormatType::DATETIME ) { - sal_uInt32 nFormat = pDocument->GetNumberFormat( aPos ); + sal_uInt32 nFormat = pDocument->GetNumberFormat( rContext, aPos ); aResult.SetDouble( pDocument->RoundValueAsShown( - aResult.GetDouble(), nFormat)); + aResult.GetDouble(), nFormat, &rContext)); } if (eTailParam == SCITP_NORMAL) { diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx index d516a631c187..c600cdca34b1 100644 --- a/sc/source/core/tool/interpr4.cxx +++ b/sc/source/core/tool/interpr4.cxx @@ -151,7 +151,7 @@ double ScInterpreter::GetValueCellValue( const ScAddress& rPos, double fOrig ) if ( bCalcAsShown && fOrig != 0.0 ) { sal_uInt32 nFormat = pDok->GetNumberFormat( mrContext, rPos ); - fOrig = pDok->RoundValueAsShown( fOrig, nFormat ); + fOrig = pDok->RoundValueAsShown( fOrig, nFormat, &mrContext ); } return fOrig; } @@ -223,7 +223,7 @@ double ScInterpreter::GetCellValueOrZero( const ScAddress& rPos, ScRefCellValue& nCurFmtIndex = pDok->GetNumberFormat( mrContext, rPos ); nCurFmtType = pFormatter->GetType( nCurFmtIndex ); if ( bCalcAsShown && fValue != 0.0 ) - fValue = pDok->RoundValueAsShown( fValue, nCurFmtIndex ); + fValue = pDok->RoundValueAsShown( fValue, nCurFmtIndex, &mrContext ); } break; case CELLTYPE_STRING: -- cgit