From a7ff6e0a3fc5fccad33f06ae9d4ec7019f9ae156 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Tue, 8 Oct 2013 13:47:49 -0400 Subject: Support for passing non-double formula results from group interpreter. Change-Id: I1cbe6b32d8a9b86a575e9806802f7a2a45eee873 --- sc/source/core/data/column2.cxx | 26 ++++++++++++++++++++++++++ sc/source/core/data/documen8.cxx | 9 ++++++++- sc/source/core/data/table1.cxx | 9 +++++++++ sc/source/core/tool/formulagroup.cxx | 4 ++-- 4 files changed, 45 insertions(+), 3 deletions(-) (limited to 'sc/source/core') diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index bb8cf5f7461f..ec3d475149ad 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -2466,6 +2466,32 @@ void ScColumn::SetFormulaResults( SCROW nRow, const double* pResults, size_t nLe } } +void ScColumn::SetFormulaResults( SCROW nRow, const formula::FormulaTokenRef* pResults, size_t nLen ) +{ + sc::CellStoreType::position_type aPos = maCells.position(nRow); + sc::CellStoreType::iterator it = aPos.first; + if (it->type != sc::element_type_formula) + // This is not a formula block. + return; + + size_t nBlockLen = it->size - aPos.second; + if (nBlockLen < nLen) + // Result array is longer than the length of formula cells. Not good. + return; + + sc::formula_block::iterator itCell = sc::formula_block::begin(*it->data); + std::advance(itCell, aPos.second); + + const formula::FormulaTokenRef* pResEnd = pResults + nLen; + for (; pResults != pResEnd; ++pResults, ++itCell) + { + ScFormulaCell& rCell = **itCell; + rCell.SetResultToken(pResults->get()); + rCell.ResetDirty(); + rCell.SetChanged(true); + } +} + void ScColumn::SetNumberFormat( SCROW nRow, sal_uInt32 nNumberFormat ) { short eOldType = pDocument->GetFormatTable()->GetType( diff --git a/sc/source/core/data/documen8.cxx b/sc/source/core/data/documen8.cxx index d69e25b3d79e..c7e6a99104d0 100644 --- a/sc/source/core/data/documen8.cxx +++ b/sc/source/core/data/documen8.cxx @@ -454,8 +454,15 @@ void ScDocument::SetFormulaResults( const ScAddress& rTopPos, const double* pRes pTab->SetFormulaResults(rTopPos.Col(), rTopPos.Row(), pResults, nLen); } +void ScDocument::SetFormulaResults( + const ScAddress& rTopPos, const formula::FormulaTokenRef* pResults, size_t nLen ) +{ + ScTable* pTab = FetchTable(rTopPos.Tab()); + if (!pTab) + return; -//------------------------------------------------------------------------ + pTab->SetFormulaResults(rTopPos.Col(), rTopPos.Row(), pResults, nLen); +} void ScDocument::InvalidateTextWidth( const ScAddress* pAdrFrom, const ScAddress* pAdrTo, bool bNumFormatChanged ) diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx index 0c985fde6abf..851cf6c86b2c 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -2231,6 +2231,15 @@ void ScTable::SetFormulaResults( SCCOL nCol, SCROW nRow, const double* pResults, aCol[nCol].SetFormulaResults(nRow, pResults, nLen); } +void ScTable::SetFormulaResults( + SCCOL nCol, SCROW nRow, const formula::FormulaTokenRef* pResults, size_t nLen ) +{ + if (!ValidCol(nCol)) + return; + + aCol[nCol].SetFormulaResults(nRow, pResults, nLen); +} + #if DEBUG_COLUMN_STORAGE void ScTable::DumpFormulaGroups( SCCOL nCol ) const { diff --git a/sc/source/core/tool/formulagroup.cxx b/sc/source/core/tool/formulagroup.cxx index 09076a831445..21edd7e4c591 100644 --- a/sc/source/core/tool/formulagroup.cxx +++ b/sc/source/core/tool/formulagroup.cxx @@ -141,7 +141,7 @@ bool FormulaGroupInterpreterSoftware::interpret(ScDocument& rDoc, const ScAddres // the group. ScAddress aTmpPos = rTopPos; - std::vector aResults; + std::vector aResults; aResults.reserve(xGroup->mnLength); CachedTokensType aCachedTokens; @@ -256,7 +256,7 @@ bool FormulaGroupInterpreterSoftware::interpret(ScDocument& rDoc, const ScAddres generateRPNCode(rDoc, aTmpPos, aCode2); ScInterpreter aInterpreter(pDest, &rDoc, aTmpPos, aCode2); aInterpreter.Interpret(); - aResults.push_back(aInterpreter.GetResultToken()->GetDouble()); + aResults.push_back(aInterpreter.GetResultToken()); } // for loop end (xGroup->mnLength) if (!aResults.empty()) -- cgit v1.2.1