sc/qa/unit/uicalc/uicalc.cxx | 49 +++++++++++++++++++++++++++++++++++++++++ sc/source/ui/view/viewfunc.cxx | 11 +++++---- 2 files changed, 56 insertions(+), 4 deletions(-)
New commits: commit 9caf9f8fde68f075a9ae1377bcc0cf6127c1737f Author: Andreas Heinisch <andreas.heini...@yahoo.de> AuthorDate: Sat Sep 3 16:40:11 2022 +0200 Commit: Andreas Heinisch <andreas.heini...@yahoo.de> CommitDate: Mon Sep 12 10:26:01 2022 +0200 tdf#131073 - Don't show hidden rows/cols after setting optimal row/col height Change-Id: I1dbe92cfc577e3425787b942415182889cda6a76 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139327 Tested-by: Jenkins Reviewed-by: Heiko Tietze <heiko.tie...@documentfoundation.org> Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de> diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx index ab258894eb16..bd175ec1bde5 100644 --- a/sc/qa/unit/uicalc/uicalc.cxx +++ b/sc/qa/unit/uicalc/uicalc.cxx @@ -2277,6 +2277,55 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf132431) CPPUNIT_ASSERT_EQUAL(OUString("Err:502"), pDoc->GetString(ScAddress(7, 219, 0))); } +CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf131073) +{ + mxComponent = loadFromDesktop("private:factory/scalc"); + ScModelObj* pModelObj = dynamic_cast<ScModelObj*>(mxComponent.get()); + CPPUNIT_ASSERT(pModelObj); + ScDocument* pDoc = pModelObj->GetDocument(); + CPPUNIT_ASSERT(pDoc); + + for (SCCOLROW nColRow = 0; nColRow < 3; nColRow++) + { + pDoc->SetString(ScAddress(0, nColRow, 0), "Hello World"); + pDoc->SetRowHeight(0, nColRow, 1000 * (nColRow + 1)); + pDoc->SetString(ScAddress(nColRow, 0, 0), "Hello World"); + pDoc->SetColWidth(nColRow, 0, 1000 * (nColRow + 1)); + } + + // Check rows + pDoc->SetRowHidden(1, 1, 0, true); + goToCell("A1:A3"); + dispatchCommand( + mxComponent, ".uno:SetOptimalRowHeight", + comphelper::InitPropertySequence({ { "aExtraHeight", uno::Any(sal_uInt16(0)) } })); + + CPPUNIT_ASSERT(!pDoc->RowHidden(0, 0)); + // tdf#131073: Without the fix in place, the second row would not be hidden + CPPUNIT_ASSERT(pDoc->RowHidden(1, 0)); + CPPUNIT_ASSERT(!pDoc->RowHidden(2, 0)); + const sal_uInt16 nStdRowHeight = pDoc->GetRowHeight(4, 0); + CPPUNIT_ASSERT_EQUAL(nStdRowHeight, pDoc->GetRowHeight(0, 0)); + CPPUNIT_ASSERT_EQUAL(nStdRowHeight, pDoc->GetRowHeight(1, SCTAB(0), false)); + CPPUNIT_ASSERT_EQUAL(nStdRowHeight, pDoc->GetRowHeight(2, 0)); + + // Check columns + pDoc->SetColHidden(1, 1, 0, true); + goToCell("A1:C1"); + dispatchCommand( + mxComponent, ".uno:SetOptimalColumnWidth", + comphelper::InitPropertySequence({ { "aExtraWidth", uno::Any(sal_uInt16(0)) } })); + + CPPUNIT_ASSERT(!pDoc->ColHidden(0, 0)); + // tdf#131073: Without the fix in place, the second column would not be hidden + CPPUNIT_ASSERT(pDoc->ColHidden(1, 0)); + CPPUNIT_ASSERT(!pDoc->ColHidden(2, 0)); + const sal_uInt16 nStdColWidth = pDoc->GetColWidth(0, 0); + CPPUNIT_ASSERT_EQUAL(nStdColWidth, pDoc->GetColWidth(0, 0)); + CPPUNIT_ASSERT_EQUAL(nStdColWidth, pDoc->GetColWidth(1, SCTAB(0), false)); + CPPUNIT_ASSERT_EQUAL(nStdColWidth, pDoc->GetColWidth(2, 0)); +} + CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf83901) { mxComponent = loadFromDesktop("private:factory/scalc"); diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index c1c003205828..c5341aadfa65 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -2238,8 +2238,6 @@ void ScViewFunc::SetWidthOrHeight( aCxt.setForceAutoSize(bAll); aCxt.setExtraHeight(nSizeTwips); rDoc.SetOptimalHeight(aCxt, nStartNo, nEndNo, nTab, true); - if (bAll) - rDoc.ShowRows( nStartNo, nEndNo, nTab, true ); // Manual-Flag already (re)set in SetOptimalHeight in case of bAll=sal_True // (set for Extra-Height, else reset). @@ -2268,7 +2266,8 @@ void ScViewFunc::SetWidthOrHeight( { for (SCCOL nCol=static_cast<SCCOL>(nStartNo); nCol<=static_cast<SCCOL>(nEndNo); nCol++) { - if ( eMode != SC_SIZE_VISOPT || !rDoc.ColHidden(nCol, nTab) ) + const bool bIsColHidden = rDoc.ColHidden(nCol, nTab); + if ( eMode != SC_SIZE_VISOPT || !bIsColHidden ) { sal_uInt16 nThisSize = nSizeTwips; @@ -2277,7 +2276,11 @@ void ScViewFunc::SetWidthOrHeight( if ( nThisSize ) rDoc.SetColWidth( nCol, nTab, nThisSize ); - rDoc.ShowCol( nCol, nTab, bShow ); + // tdf#131073 - Don't show hidden cols after setting optimal col width + if (eMode == SC_SIZE_OPTIMAL) + rDoc.ShowCol(nCol, nTab, !bIsColHidden); + else + rDoc.ShowCol( nCol, nTab, bShow ); if (!bShow && nCol == nCurX && nTab == nCurTab) {