sc/inc/document.hxx | 1 + sc/qa/unit/data/ods/tdf154005.ods |binary sc/qa/unit/scshapetest.cxx | 30 ++++++++++++++++++++++++++++++ sc/source/core/data/document.cxx | 8 ++++++++ sc/source/core/data/drwlayer.cxx | 16 ++++++++++++++-- 5 files changed, 53 insertions(+), 2 deletions(-)
New commits: commit 97a38dbfa998967c45efaf3303fedfa1a709a2bb Author: Balazs Varga <balazs.varga.ext...@allotropia.de> AuthorDate: Sun Mar 12 17:49:53 2023 +0100 Commit: Thorsten Behrens <thorsten.behr...@allotropia.de> CommitDate: Tue Mar 14 02:04:50 2023 +0000 tdf#154005 sc ods fileopen: fix dropdown form control size Dropdown form control size was increased by the size of hidden rows or columns. Regression from commit: 1f0b3c7a40edfa81bbc7a58d123a6a2dfd83e4ca (Improve 'resize with cell' handling) Change-Id: Ic903a488cab22286f95cfdf4ee559013fd7bfa02 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148738 Tested-by: Thorsten Behrens <thorsten.behr...@allotropia.de> Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de> diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 09fcc126ed06..137b786e8c8b 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -2036,6 +2036,7 @@ public: SC_DLLPUBLIC SCROW FirstVisibleRow(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const; SC_DLLPUBLIC SCROW LastVisibleRow(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const; SCROW CountVisibleRows(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const; + SCCOL CountVisibleCols(SCROW nStartCol, SCROW nEndCol, SCTAB nTab) const; SC_DLLPUBLIC bool RowFiltered(SCROW nRow, SCTAB nTab, SCROW* pFirstRow = nullptr, SCROW* pLastRow = nullptr) const; bool HasFilteredRows(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const; diff --git a/sc/qa/unit/data/ods/tdf154005.ods b/sc/qa/unit/data/ods/tdf154005.ods new file mode 100644 index 000000000000..1349ec725869 Binary files /dev/null and b/sc/qa/unit/data/ods/tdf154005.ods differ diff --git a/sc/qa/unit/scshapetest.cxx b/sc/qa/unit/scshapetest.cxx index dc60439a536f..c89189d892a9 100644 --- a/sc/qa/unit/scshapetest.cxx +++ b/sc/qa/unit/scshapetest.cxx @@ -57,6 +57,7 @@ public: void testTdf137576_LogicRectInNewMeasureline(); void testMeasurelineHideColSave(); void testHideColsShow(); + void testFormSizeWithHiddenCol(); void testTdf138138_MoveCellWithRotatedShape(); void testLoadVerticalFlip(); void testTdf117948_CollapseBeforeShape(); @@ -85,6 +86,7 @@ public: CPPUNIT_TEST(testTdf137576_LogicRectInNewMeasureline); CPPUNIT_TEST(testMeasurelineHideColSave); CPPUNIT_TEST(testHideColsShow); + CPPUNIT_TEST(testFormSizeWithHiddenCol); CPPUNIT_TEST(testTdf138138_MoveCellWithRotatedShape); CPPUNIT_TEST(testLoadVerticalFlip); CPPUNIT_TEST(testTdf117948_CollapseBeforeShape); @@ -759,6 +761,34 @@ void ScShapeTest::testHideColsShow() CPPUNIT_ASSERT_RECTANGLE_EQUAL_WITH_TOLERANCE(aSnapRectOrig, aSnapRectShow, 1); } +void ScShapeTest::testFormSizeWithHiddenCol() +{ + // The document contains a form (Listbox) shape anchored "To Cell (resize with cell)" with starts in cell B5 and + // ends in cell D5. The error was the form shape was resized if there was hidden col/row. + + createScDoc("tdf154005.ods"); + + // Get document and shape + ScDocument* pDoc = getScDoc(); + SdrUnoObj* pObj = static_cast<SdrUnoObj*>(lcl_getSdrObjectWithAssert(*pDoc, 0)); + + // Check Position and Size + pDoc->SetDrawPageSize(0); // trigger recalcpos + tools::Rectangle aRect(2432, 3981, 4932, 4631); // expected snap rect from values in file + const tools::Rectangle& rShapeRect(pObj->GetSnapRect()); + CPPUNIT_ASSERT_RECTANGLE_EQUAL_WITH_TOLERANCE(aRect, rShapeRect, 1); + + // Check anchor + ScDrawObjData* pData = ScDrawLayer::GetObjData(pObj); + CPPUNIT_ASSERT_MESSAGE("expected object meta data", pData); + + const OUString sActual("start col " + OUString::number(pData->maStart.Col()) + " row " + + OUString::number(pData->maStart.Row()) + " end col " + + OUString::number(pData->maEnd.Col()) + " row " + + OUString::number(pData->maEnd.Row())); + CPPUNIT_ASSERT_EQUAL(OUString("start col 1 row 4 end col 3 row 4"), sActual); +} + void ScShapeTest::testTdf138138_MoveCellWithRotatedShape() { // The document contains a 90deg rotated, cell-anchored rectangle in column D. Insert 2 columns diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index b53de471e776..eac0117f6994 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -4563,6 +4563,14 @@ SCROW ScDocument::CountVisibleRows(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) c return maTabs[nTab]->CountVisibleRows(nStartRow, nEndRow); } +SCCOL ScDocument::CountVisibleCols(SCROW nStartCol, SCROW nEndCol, SCTAB nTab) const +{ + if (!ValidTab(nTab) || nTab >= static_cast<SCTAB>(maTabs.size()) || !maTabs[nTab]) + return 0; + + return maTabs[nTab]->CountVisibleCols(nStartCol, nEndCol); +} + bool ScDocument::RowFiltered(SCROW nRow, SCTAB nTab, SCROW* pFirstRow, SCROW* pLastRow) const { if (!ValidTab(nTab) || nTab >= static_cast<SCTAB>(maTabs.size()) || !maTabs[nTab]) diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx index ec4fee275ed1..e6203697a4e7 100644 --- a/sc/source/core/data/drwlayer.cxx +++ b/sc/source/core/data/drwlayer.cxx @@ -703,6 +703,18 @@ void lcl_SetLogicRectFromAnchor(SdrObject* pObj, const ScDrawObjData& rAnchor, c if (!pObj || !pDoc || !rAnchor.maEnd.IsValid() || !rAnchor.maStart.IsValid()) return; + SCROW nHiddenRows = 0; + SCCOL nHiddenCols = 0; + // tdf#154005: Handle hidden row/col: remove hidden row/cols size from the ScDrawObjData shape size in case of forms + if (pObj->GetObjIdentifier() == SdrObjKind::UNO && pObj->GetObjInventor() == SdrInventor::FmForm) + { + nHiddenRows = ((rAnchor.maEnd.Row() - rAnchor.maStart.Row()) + 1) - + (pDoc->CountVisibleRows(rAnchor.maStart.Row(), rAnchor.maEnd.Row(), rAnchor.maStart.Tab())); + + nHiddenCols = ((rAnchor.maEnd.Col() - rAnchor.maStart.Col()) + 1) - + (pDoc->CountVisibleCols(rAnchor.maStart.Col(), rAnchor.maEnd.Col(), rAnchor.maStart.Tab())); + } + // In case of a vertical mirrored custom shape, LibreOffice uses internally an additional 180deg // in aGeo.nRotationAngle and in turn has a different logic rectangle position. We remove flip, // set the logic rectangle, and apply flip again. You cannot simple use a 180deg-rotated @@ -726,8 +738,8 @@ void lcl_SetLogicRectFromAnchor(SdrObject* pObj, const ScDrawObjData& rAnchor, c aStartPoint.AdjustY(rAnchor.maStartOffset.getY()); const tools::Rectangle aEndCellRect( - pDoc->GetMMRect(rAnchor.maEnd.Col(), rAnchor.maEnd.Row(), rAnchor.maEnd.Col(), - rAnchor.maEnd.Row(), rAnchor.maEnd.Tab(), false /*bHiddenAsZero*/)); + pDoc->GetMMRect(rAnchor.maEnd.Col() - nHiddenCols, rAnchor.maEnd.Row() - nHiddenRows, rAnchor.maEnd.Col() - nHiddenCols, + rAnchor.maEnd.Row() - nHiddenRows, rAnchor.maEnd.Tab(), false /*bHiddenAsZero*/)); Point aEndPoint(aEndCellRect.Left(), aEndCellRect.Top()); aEndPoint.AdjustX(rAnchor.maEndOffset.getX()); aEndPoint.AdjustY(rAnchor.maEndOffset.getY());