sc/qa/extras/macros-test.cxx | 2 -- sc/qa/unit/ucalc_formula.cxx | 18 ++++++++++++++++++ sc/source/core/tool/token.cxx | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 52 insertions(+), 6 deletions(-)
New commits: commit 3bade6b47973a228723b240b9410f15891487812 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Wed Jul 31 21:10:50 2013 -0400 Fix reference update on range references in named expressions. This fixes the macro test failure. Change-Id: I8ddaaaa49d1faf36cc37212895c21023a4ab6135 diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx index 9bc3a0f..023f627 100644 --- a/sc/qa/extras/macros-test.cxx +++ b/sc/qa/extras/macros-test.cxx @@ -198,12 +198,10 @@ void ScMacrosTest::testVba() OUString("Shapes."), OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, -#if 0 // TODO : fix this { OUString("Ranges."), OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, -#endif { OUString("CheckOptionToggleValue."), OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index 83094d2..4703cde 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -2598,6 +2598,20 @@ bool adjustSingleRefInName( return bChanged; } +bool adjustDoubleRefInName( + ScComplexRefData& rRef, const sc::RefUpdateContext& rCxt, const ScAddress& rPos ) +{ + bool bRefChanged = false; + + if (adjustSingleRefInName(rRef.Ref1, rCxt, rPos)) + bRefChanged = true; + + if (adjustSingleRefInName(rRef.Ref2, rCxt, rPos)) + bRefChanged = true; + + return bRefChanged; +} + } sc::RefUpdateResult ScTokenArray::AdjustReferenceInName( @@ -2623,10 +2637,26 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceInName( { ScToken* pToken = static_cast<ScToken*>(*p); ScComplexRefData& rRef = pToken->GetDoubleRef(); - if (adjustSingleRefInName(rRef.Ref1, rCxt, rPos)) - aRes.mbReferenceModified = true; - if (adjustSingleRefInName(rRef.Ref2, rCxt, rPos)) - aRes.mbReferenceModified = true; + ScRange aAbs = rRef.toAbs(rPos); + if (rCxt.maRange.In(aAbs)) + { + // This range is entirely within the shifted region. + if (adjustDoubleRefInName(rRef, rCxt, rPos)) + aRes.mbReferenceModified = true; + } + else if (rCxt.maRange.Intersects(aAbs)) + { + if (rCxt.mnColDelta && rCxt.maRange.aStart.Row() <= aAbs.aStart.Row() && aAbs.aEnd.Row() <= rCxt.maRange.aEnd.Row()) + { + if (adjustDoubleRefInName(rRef, rCxt, rPos)) + aRes.mbReferenceModified = true; + } + if (rCxt.mnRowDelta && rCxt.maRange.aStart.Col() <= aAbs.aStart.Col() && aAbs.aEnd.Col() <= rCxt.maRange.aEnd.Col()) + { + if (adjustDoubleRefInName(rRef, rCxt, rPos)) + aRes.mbReferenceModified = true; + } + } } break; default: commit 10dfaebc6cc2191745d4d7323596bb8e22c9d029 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Wed Jul 31 19:19:41 2013 -0400 Add test on updating references in named range. This currently fails. Change-Id: Ibb2b9e4430c97479d068d94d233f04f60b255966 diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index f731f2a..e85c01c55 100644 --- a/sc/qa/unit/ucalc_formula.cxx +++ b/sc/qa/unit/ucalc_formula.cxx @@ -1064,6 +1064,24 @@ void Test::testFormulaRefUpdateNamedExpression() CPPUNIT_ASSERT_EQUAL(34.0, m_pDoc->GetValue(ScAddress(2,7,0))); #endif + // Clear all and start over. + clearRange(m_pDoc, ScRange(0,0,0,100,100,0)); + pGlobalNames->clear(); + + pName = new ScRangeData( + m_pDoc, "MyRange", "$B$1:$C$6", ScAddress(0,0,0), RT_NAME, formula::FormulaGrammar::GRAM_NATIVE); + bInserted = pGlobalNames->insert(pName); + CPPUNIT_ASSERT_MESSAGE("Failed to insert a new name.", bInserted); + pName->GetSymbol(aExpr); + CPPUNIT_ASSERT_EQUAL(OUString("$B$1:$C$6"), aExpr); + + // Insert range of cells to shift right. The range partially overlaps the named range. + m_pDoc->InsertCol(ScRange(2,4,0,3,8,0)); + + // This should not alter the range. + pName->GetSymbol(aExpr); + CPPUNIT_ASSERT_EQUAL(OUString("$B$1:$C$6"), aExpr); + m_pDoc->DeleteTab(0); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits