summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2015-12-18 23:22:24 +0100
committerEike Rathke <erack@redhat.com>2015-12-18 23:33:42 +0100
commit9a9bf646cfc388324df017fb0b9e0f6ad71acabd (patch)
tree3102cdb7a3ee6345fcb80fa5719d96b7d8caeac3 /sc
parentd86e429f339131e05081132a6ef6aae41e5f6811 (diff)
Formula Wizard: evaluating expressions always in matrix context is wrong
Change-Id: I276f7bbf2bd6fa7c67d8691634ad9d79e4a08b1c (cherry picked from commit dc89367a5622748dd7c37b89ac300a663b8b98e9)
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/simpleformulacalc.hxx6
-rw-r--r--sc/qa/unit/ucalc.cxx4
-rw-r--r--sc/source/core/data/simpleformulacalc.cxx16
-rw-r--r--sc/source/ui/app/inputhdl.cxx4
-rw-r--r--sc/source/ui/formdlg/formula.cxx8
-rw-r--r--sc/source/ui/inc/formula.hxx2
6 files changed, 23 insertions, 17 deletions
diff --git a/sc/inc/simpleformulacalc.hxx b/sc/inc/simpleformulacalc.hxx
index 081823de12ce..fef4fe9400a7 100644
--- a/sc/inc/simpleformulacalc.hxx
+++ b/sc/inc/simpleformulacalc.hxx
@@ -31,13 +31,15 @@ private:
ScDocument* mpDoc;
ScFormulaResult maResult;
formula::FormulaGrammar::Grammar maGram;
- bool bIsMatrix;
+ bool mbMatrixResult;
OUString maMatrixFormulaResult;
bool mbLimitString;
+ bool mbMatrixFormula;
public:
ScSimpleFormulaCalculator(ScDocument* pDoc, const ScAddress& rAddr,
- const OUString& rFormula, formula::FormulaGrammar::Grammar eGram = formula::FormulaGrammar::GRAM_DEFAULT);
+ const OUString& rFormula, bool bMatrixFormula,
+ formula::FormulaGrammar::Grammar eGram = formula::FormulaGrammar::GRAM_DEFAULT);
~ScSimpleFormulaCalculator();
void Calculate();
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index bf22802d95db..337a4ef0acd3 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -6584,7 +6584,7 @@ void Test::testFormulaWizardSubformula()
m_pDoc->SetString(ScAddress(1,1,0), "=1/0"); // B2
m_pDoc->SetString(ScAddress(1,2,0), "=gibberish"); // B3
- ScSimpleFormulaCalculator pFCell1( m_pDoc, ScAddress(0,0,0), "=B1:B3" );
+ ScSimpleFormulaCalculator pFCell1( m_pDoc, ScAddress(0,0,0), "=B1:B3", true );
sal_uInt16 nErrCode = pFCell1.GetErrCode();
CPPUNIT_ASSERT( nErrCode == 0 || pFCell1.IsMatrix() );
CPPUNIT_ASSERT_EQUAL( OUString("{1;#DIV/0!;#NAME?}"), pFCell1.GetString().getString() );
@@ -6592,7 +6592,7 @@ void Test::testFormulaWizardSubformula()
m_pDoc->SetString(ScAddress(1,0,0), "=NA()"); // B1
m_pDoc->SetString(ScAddress(1,1,0), "2"); // B2
m_pDoc->SetString(ScAddress(1,2,0), "=1+2"); // B3
- ScSimpleFormulaCalculator pFCell2( m_pDoc, ScAddress(0,0,0), "=B1:B3" );
+ ScSimpleFormulaCalculator pFCell2( m_pDoc, ScAddress(0,0,0), "=B1:B3", true );
nErrCode = pFCell2.GetErrCode();
CPPUNIT_ASSERT( nErrCode == 0 || pFCell2.IsMatrix() );
CPPUNIT_ASSERT_EQUAL( OUString("{#N/A;2;3}"), pFCell2.GetString().getString() );
diff --git a/sc/source/core/data/simpleformulacalc.cxx b/sc/source/core/data/simpleformulacalc.cxx
index 7d2efe2fddc6..49b3459f06c0 100644
--- a/sc/source/core/data/simpleformulacalc.cxx
+++ b/sc/source/core/data/simpleformulacalc.cxx
@@ -16,15 +16,16 @@
#define DISPLAY_LEN 15
ScSimpleFormulaCalculator::ScSimpleFormulaCalculator( ScDocument* pDoc, const ScAddress& rAddr,
- const OUString& rFormula, formula::FormulaGrammar::Grammar eGram )
+ const OUString& rFormula, bool bMatrixFormula, formula::FormulaGrammar::Grammar eGram )
: mnFormatType(0)
, mnFormatIndex(0)
, mbCalculated(false)
, maAddr(rAddr)
, mpDoc(pDoc)
, maGram(eGram)
- , bIsMatrix(false)
+ , mbMatrixResult(false)
, mbLimitString(false)
+ , mbMatrixFormula(bMatrixFormula)
{
// compile already here
ScCompiler aComp(mpDoc, maAddr);
@@ -45,7 +46,8 @@ void ScSimpleFormulaCalculator::Calculate()
mbCalculated = true;
ScInterpreter aInt(nullptr, mpDoc, maAddr, *mpCode.get());
- aInt.AssertFormulaMatrix();
+ if (mbMatrixFormula)
+ aInt.AssertFormulaMatrix();
formula::StackVar aIntType = aInt.Interpret();
if ( aIntType == formula::svMatrixCell )
@@ -55,7 +57,7 @@ void ScSimpleFormulaCalculator::Calculate()
OUStringBuffer aStr;
aComp.CreateStringFromToken(aStr, aInt.GetResultToken().get());
- bIsMatrix = true;
+ mbMatrixResult = true;
if (mbLimitString)
{
@@ -82,7 +84,7 @@ bool ScSimpleFormulaCalculator::IsValue()
{
Calculate();
- if (bIsMatrix)
+ if (mbMatrixResult)
return false;
return maResult.IsValue();
@@ -90,7 +92,7 @@ bool ScSimpleFormulaCalculator::IsValue()
bool ScSimpleFormulaCalculator::IsMatrix()
{
- return bIsMatrix;
+ return mbMatrixResult;
}
sal_uInt16 ScSimpleFormulaCalculator::GetErrCode()
@@ -118,7 +120,7 @@ svl::SharedString ScSimpleFormulaCalculator::GetString()
{
Calculate();
- if (bIsMatrix)
+ if (mbMatrixResult)
return maMatrixFormulaResult;
if ((!mpCode->GetCodeError() || mpCode->GetCodeError() == errDoubleRef) &&
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index 4138bad3b57b..a464c3476b0c 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -1246,7 +1246,7 @@ static OUString lcl_Calculate( const OUString& rFormula, ScDocument* pDoc, const
if(rFormula.isEmpty())
return OUString();
- std::unique_ptr<ScSimpleFormulaCalculator> pCalc( new ScSimpleFormulaCalculator( pDoc, rPos, rFormula ) );
+ std::unique_ptr<ScSimpleFormulaCalculator> pCalc( new ScSimpleFormulaCalculator( pDoc, rPos, rFormula, false ) );
// FIXME: HACK! In order to not get a #REF! for ColRowNames, if a name is actually inserted as a Range
// into the whole Formula, but is interpreted as a single cell reference when displaying it on its own
@@ -1261,7 +1261,7 @@ static OUString lcl_Calculate( const OUString& rFormula, ScDocument* pDoc, const
aBraced.append('(');
aBraced.append(rFormula);
aBraced.append(')');
- pCalc.reset( new ScSimpleFormulaCalculator( pDoc, rPos, aBraced.makeStringAndClear() ) );
+ pCalc.reset( new ScSimpleFormulaCalculator( pDoc, rPos, aBraced.makeStringAndClear(), false ) );
}
else
bColRowName = false;
diff --git a/sc/source/ui/formdlg/formula.cxx b/sc/source/ui/formdlg/formula.cxx
index e4d466ef0be3..5692bbc0b704 100644
--- a/sc/source/ui/formdlg/formula.cxx
+++ b/sc/source/ui/formdlg/formula.cxx
@@ -301,9 +301,10 @@ bool ScFormulaDlg::Close()
// functions for right side
-bool ScFormulaDlg::calculateValue( const OUString& rStrExp, OUString& rStrResult )
+bool ScFormulaDlg::calculateValue( const OUString& rStrExp, OUString& rStrResult, bool bMatrixFormula )
{
- std::unique_ptr<ScSimpleFormulaCalculator> pFCell(new ScSimpleFormulaCalculator(m_pDoc, m_CursorPos, rStrExp));
+ std::unique_ptr<ScSimpleFormulaCalculator> pFCell( new ScSimpleFormulaCalculator(
+ m_pDoc, m_CursorPos, rStrExp, bMatrixFormula));
pFCell->SetLimitString(true);
// HACK! to avoid neither #REF! from ColRowNames
@@ -320,7 +321,8 @@ bool ScFormulaDlg::calculateValue( const OUString& rStrExp, OUString& rStrResult
aBraced.append('(');
aBraced.append(rStrExp);
aBraced.append(')');
- pFCell.reset(new ScSimpleFormulaCalculator(m_pDoc, m_CursorPos, aBraced.makeStringAndClear()));
+ pFCell.reset( new ScSimpleFormulaCalculator(
+ m_pDoc, m_CursorPos, aBraced.makeStringAndClear(), bMatrixFormula));
pFCell->SetLimitString(true);
}
else
diff --git a/sc/source/ui/inc/formula.hxx b/sc/source/ui/inc/formula.hxx
index 3ebdb61da57a..60613b70d7c7 100644
--- a/sc/source/ui/inc/formula.hxx
+++ b/sc/source/ui/inc/formula.hxx
@@ -59,7 +59,7 @@ public:
// IFormulaEditorHelper
virtual void notifyChange() override;
virtual void fill() override;
- virtual bool calculateValue(const OUString& _sExpression, OUString& _rResult) override;
+ virtual bool calculateValue(const OUString& _sExpression, OUString& _rResult, bool bMatrixFormula) override;
virtual void doClose(bool _bOk) override;
virtual void insertEntryToLRUList(const formula::IFunctionDescription* pDesc) override;
virtual void showReference(const OUString& _sFormula) override;