sc/qa/extras/macros-test.cxx | 32 ++++++++++++++++++++++++++++++++ sc/source/ui/unoobj/viewuno.cxx | 18 +++++++++++++----- 2 files changed, 45 insertions(+), 5 deletions(-)
New commits: commit 10f2e8363076fb9217b4fc8acf12b4d9c13328cc Author: Andreas Heinisch <andreas.heini...@yahoo.de> AuthorDate: Fri Apr 14 14:29:12 2023 +0200 Commit: Andreas Heinisch <andreas.heini...@yahoo.de> CommitDate: Tue Apr 18 12:40:49 2023 +0200 tdf#154803 - Check if range is entirely merged Regression from commit b9411e587586750f36ba9009b5f1e29fe461d8b5 where I missinterpreted the check to get merged cells. Regression: tdf#147122 - Return cell object when a simple selection is merged Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145378 Change-Id: I2e39599a206cf102b1da8c7fc4bb2d8c0a4b106c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150412 Tested-by: Jenkins Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de> diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx index dd971e36dec1..1135fbd38f69 100644 --- a/sc/qa/extras/macros-test.cxx +++ b/sc/qa/extras/macros-test.cxx @@ -911,6 +911,38 @@ CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf147122) CPPUNIT_ASSERT_EQUAL(Any(OUString("This is a test")), aRet); } +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf154803) +{ + mxComponent = loadFromDesktop("private:factory/scalc"); + + css::uno::Reference<css::document::XEmbeddedScripts> xDocScr(mxComponent, UNO_QUERY_THROW); + auto xLibs = xDocScr->getBasicLibraries(); + auto xLibrary = xLibs->createLibrary("TestLibrary"); + xLibrary->insertByName( + "TestModule", + uno::Any( + OUString("Function TestExtendedMergedSelection\n" + // Merge A1:B2 cell range + " oActiveSheet = ThisComponent.CurrentController.ActiveSheet\n" + " oRange = oActiveSheet.getCellRangeByName(\"A1:B2\")\n" + " ThisComponent.getCurrentController.Select(oRange)\n" + " oActiveCell = ThisComponent.CurrentSelection\n" + " oActiveCell.Merge(True)\n" + // Select A1:B3 range and check for its implementation name + " oRange = oActiveSheet.getCellRangeByName(\"A1:B3\")\n" + " ThisComponent.getCurrentController.Select(oRange)\n" + " TestExtendedMergedSelection = ThisComponent.CurrentSelection.ImplementationName\n" + "End Function\n"))); + + Any aRet = executeMacro("vnd.sun.Star.script:TestLibrary.TestModule.TestExtendedMergedSelection?" + "language=Basic&location=document"); + // Without the fix in place, this test would have failed with + // - Expected : ScCellRangeObj + // - Actual : ScCellObj + // i.e. the selection was interpreted as a single cell instead of a range + CPPUNIT_ASSERT_EQUAL(Any(OUString("ScCellRangeObj")), aRet); +} + CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf116127) { mxComponent = loadFromDesktop("private:factory/scalc"); diff --git a/sc/source/ui/unoobj/viewuno.cxx b/sc/source/ui/unoobj/viewuno.cxx index 96b055250c72..bfde44272010 100644 --- a/sc/source/ui/unoobj/viewuno.cxx +++ b/sc/source/ui/unoobj/viewuno.cxx @@ -54,6 +54,7 @@ #include <prevwsh.hxx> #include <docsh.hxx> #include <drwlayer.hxx> +#include <attrib.hxx> #include <drawview.hxx> #include <fupoor.hxx> #include <sc.hrc> @@ -873,13 +874,20 @@ uno::Any SAL_CALL ScTabViewObj::getSelection() ScMarkType eMarkType = rViewData.GetSimpleArea(aRange); if ( nTabs == 1 && (eMarkType == SC_MARK_SIMPLE) ) { - // tdf#147122 - return cell object when a simple selection is merged + // tdf#154803 - check if range is entirely merged ScDocument& rDoc = pDocSh->GetDocument(); - const ScPatternAttr* pMarkPattern = rDoc.GetPattern(aRange.aStart); + const ScMergeAttr* pMergeAttr = rDoc.GetAttr(aRange.aStart, ATTR_MERGE); + SCCOL nColSpan = 1; + SCROW nRowSpan = 1; + if (pMergeAttr && pMergeAttr->IsMerged()) + { + nColSpan = pMergeAttr->GetColMerge(); + nRowSpan = pMergeAttr->GetRowMerge(); + } + // tdf#147122 - return cell object when a simple selection is entirely merged if (aRange.aStart == aRange.aEnd - || (pMarkPattern - && pMarkPattern->GetItemSet().GetItemState(ATTR_MERGE, false) - == SfxItemState::SET)) + || (aRange.aEnd.Col() - aRange.aStart.Col() == nColSpan - 1 + && aRange.aEnd.Row() - aRange.aStart.Row() == nRowSpan - 1)) pObj = new ScCellObj( pDocSh, aRange.aStart ); else pObj = new ScCellRangeObj( pDocSh, aRange );