From e944d9510404d8c67b3867d7cd9f313fd5091004 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Mon, 17 Oct 2016 23:19:23 -0400 Subject: tdf#93894: Prohibit grouping when certain token types are present. For instance, column / row label tokens don't work correctly in grouped cells with the current implementation. Change-Id: Idf86312ef15fbfd4382aa90ee6d131c671a80683 --- formula/source/core/api/token.cxx | 5 ++++- include/formula/tokenarray.hxx | 11 +++++++++++ sc/source/core/data/formulacell.cxx | 5 ++++- sc/source/core/tool/compiler.cxx | 26 ++++++++++++++++++++------ sc/source/core/tool/token.cxx | 1 + 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx index a9abdd0ef133..7c85b15552e7 100644 --- a/formula/source/core/api/token.cxx +++ b/formula/source/core/api/token.cxx @@ -723,7 +723,8 @@ FormulaTokenArray::FormulaTokenArray() : nError(FormulaError::NONE), nMode(ScRecalcMode::NORMAL), bHyperLink(false), - mbFromRangeName(false) + mbFromRangeName(false), + mbShareable(true) { } @@ -746,6 +747,7 @@ void FormulaTokenArray::Assign( const FormulaTokenArray& r ) nMode = r.nMode; bHyperLink = r.bHyperLink; mbFromRangeName = r.mbFromRangeName; + mbShareable = r.mbShareable; pCode = nullptr; pRPN = nullptr; FormulaToken** pp; @@ -807,6 +809,7 @@ void FormulaTokenArray::Clear() nLen = nIndex = nRPN = 0; bHyperLink = false; mbFromRangeName = false; + mbShareable = true; ClearRecalcMode(); } diff --git a/include/formula/tokenarray.hxx b/include/formula/tokenarray.hxx index 1c6ed2256f79..cdb4e34e58c1 100644 --- a/include/formula/tokenarray.hxx +++ b/include/formula/tokenarray.hxx @@ -127,6 +127,7 @@ protected: ScRecalcMode nMode; // Flags to indicate when to recalc this code bool bHyperLink; // If HYPERLINK() occurs in the formula. bool mbFromRangeName; // If this array originates from a named expression + bool mbShareable; // Whether or not it can be shared with adjacent cells. protected: void Assign( const FormulaTokenArray& ); @@ -190,6 +191,16 @@ public: void SetFromRangeName( bool b ) { mbFromRangeName = b; } bool IsFromRangeName() const { return mbFromRangeName; } + void SetShareable( bool b ) { mbShareable = b; } + + /** + * Check if this token array is shareable between multiple adjacent + * formula cells. Certain tokens may not function correctly when shared. + * + * @return true if the token array is shareable, false otherwise. + */ + bool IsShareable() const { return mbShareable; } + void Clear(); void DelRPN(); FormulaToken* First() { nIndex = 0; return Next(); } diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index de5fc6809355..7ca01dbcf1ab 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -1299,7 +1299,7 @@ void ScFormulaCell::CompileXML( sc::CompileFormulaContext& rCxt, ScProgress& rPr ScAddress aPreviousCell( aPos ); aPreviousCell.IncRow( -1 ); ScFormulaCell *pPreviousCell = pDocument->GetFormulaCell( aPreviousCell ); - if( pPreviousCell ) + if (pPreviousCell && pPreviousCell->GetCode()->IsShareable()) { // Build formula string using the tokens from the previous cell, // but use the current cell position. @@ -3827,6 +3827,9 @@ ScFormulaCell::CompareState ScFormulaCell::CompareByTokenArray( ScFormulaCell& r if ( GetHash() != rOther.GetHash() ) return NotEqual; + if (!pCode->IsShareable() || !rOther.pCode->IsShareable()) + return NotEqual; + FormulaToken **pThis = pCode->GetCode(); sal_uInt16 nThisLen = pCode->GetCodeLen(); FormulaToken **pOther = rOther.pCode->GetCode(); diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index fa117a03c257..2c7ff4d3fcdd 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -4470,6 +4470,12 @@ ScTokenArray* ScCompiler::CompileString( const OUString& rFormula ) --nFunction; } break; + case ocColRowName: + case ocColRowNameAuto: + // The current implementation of column / row labels doesn't + // function correctly in grouped cells. + aArr.SetShareable(false); + break; default: break; } @@ -5359,8 +5365,10 @@ bool ScCompiler::HandleColRowName() { ScSingleRefData aRefData; aRefData.InitAddress( aRange.aStart ); - aRefData.SetColRel( true ); - aRefData.SetRowRel( true ); + if ( bColName ) + aRefData.SetColRel( true ); + else + aRefData.SetRowRel( true ); aRefData.SetAddress(aRange.aStart, aPos); pNew->AddSingleReference( aRefData ); } @@ -5368,10 +5376,16 @@ bool ScCompiler::HandleColRowName() { ScComplexRefData aRefData; aRefData.InitRange( aRange ); - aRefData.Ref1.SetColRel( true ); - aRefData.Ref2.SetColRel( true ); - aRefData.Ref1.SetRowRel( true ); - aRefData.Ref2.SetRowRel( true ); + if ( bColName ) + { + aRefData.Ref1.SetColRel( true ); + aRefData.Ref2.SetColRel( true ); + } + else + { + aRefData.Ref1.SetRowRel( true ); + aRefData.Ref2.SetRowRel( true ); + } aRefData.SetRange(aRange, aPos); if ( bInList ) pNew->AddDoubleReference( aRefData ); diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index 44dbe384e6e5..c5bac8d1c55f 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -1796,6 +1796,7 @@ ScTokenArray* ScTokenArray::Clone() const p->mnHashValue = mnHashValue; p->meVectorState = meVectorState; p->mbFromRangeName = mbFromRangeName; + p->mbShareable = mbShareable; FormulaToken** pp; if( nLen ) -- cgit v1.2.3