From bf1ffc64128f5b96d7c2fcc7adc81cbc25e232fd Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Sun, 16 Jul 2017 15:18:09 +0200 Subject: FormulaDlg_Impl::UpdateValues: evaluate in force-array context if present Change-Id: I32488373bd22e644ee06920045008f3d9e20e985 --- formula/source/ui/dlg/formula.cxx | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'formula') diff --git a/formula/source/ui/dlg/formula.cxx b/formula/source/ui/dlg/formula.cxx index 8742cc2184c7..d3a50fd6f0a5 100644 --- a/formula/source/ui/dlg/formula.cxx +++ b/formula/source/ui/dlg/formula.cxx @@ -561,11 +561,29 @@ bool FormulaDlg_Impl::CalcValue( const OUString& rStrExp, OUString& rStrResult, void FormulaDlg_Impl::UpdateValues( bool bForceRecalcStruct ) { - /* TODO: this must take array context of the outer - * FormulaToken::IsInForceArray() into account. As is, this is just the - * currently selected formula text part. */ + // Take a force-array context into account. RPN creation propagated those + // to tokens that are ref-counted so also available in the token array. + bool bForceArray = false; + // Only necessary if it's not a matrix formula anyway. + if (!m_pBtnMatrix->IsChecked()) + { + const sal_Int32 nPos = m_aFuncSel.Min(); + assert( 0 <= nPos && nPos < m_pHelper->getCurrentFormula().getLength()); + OUStringBuffer aBuf; + std::unique_ptr pCompiler( m_pHelper->createCompiler( *m_pTokenArray.get())); + const FormulaToken* pToken = nullptr; + for (pToken = m_pTokenArrayIterator->First(); pToken; pToken = m_pTokenArrayIterator->Next()) + { + pCompiler->CreateStringFromToken( aBuf, pToken); + if (nPos < aBuf.getLength()) + break; + } + if (pToken && nPos < aBuf.getLength()) + bForceArray = pToken->IsInForceArray(); + } + OUString aStrResult; - if ( m_pFuncDesc && CalcValue( m_pFuncDesc->getFormula( m_aArguments ), aStrResult ) ) + if (m_pFuncDesc && CalcValue( m_pFuncDesc->getFormula( m_aArguments), aStrResult, bForceArray)) m_pWndResult->SetText( aStrResult ); if (m_bMakingTree) -- cgit