sc/inc/document.hxx | 5 - sc/inc/table.hxx | 7 + sc/qa/unit/bugfix-test.cxx | 19 ++++ sc/qa/unit/data/ods/tdf104502_hiddenColsCountedInPageCount.ods |binary sc/source/core/data/documen2.cxx | 4 sc/source/core/data/document.cxx | 4 sc/source/core/data/table1.cxx | 47 +++++++--- sc/source/ui/unoobj/cursuno.cxx | 2 8 files changed, 66 insertions(+), 22 deletions(-)
New commits: commit 30eaa0b7e316129ece585a57460540a6e63e670a Author: Attila Szűcs <szucs.atti...@nisz.hu> AuthorDate: Wed Jan 27 17:43:43 2021 +0100 Commit: Gabor Kelemen <kelemen.gab...@nisz.hu> CommitDate: Mon Jun 28 17:06:20 2021 +0200 tdf#104502 sc: skip hidden columns at printing pages Page calculation counted the hidden columns, resulted printing blank pages by accident. Extend GetPrintArea() and GetTableArea() to count pages without the hidden columns, too. Co-authored-by: Tibor Nagy (NISZ) Change-Id: I4817965a675e059cdc8f81ca3bb6e128af874f2f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110028 Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> (cherry picked from commit 2bf3e0d00e3bccb5b250642ee0d3fdbe6cae8ecc) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117984 Tested-by: Gabor Kelemen <kelemen.gab...@nisz.hu> Reviewed-by: Gabor Kelemen <kelemen.gab...@nisz.hu> diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 832a02410eed..80592f15b3aa 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1456,9 +1456,10 @@ public: bool GetDataAreaSubrange(ScRange& rRange) const; SC_DLLPUBLIC bool GetCellArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow ) const; - SC_DLLPUBLIC bool GetTableArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow ) const; + SC_DLLPUBLIC bool GetTableArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow, + bool bCalcHiddens = false) const; SC_DLLPUBLIC bool GetPrintArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow, - bool bNotes = true ) const; + bool bNotes = true, bool bCalcHiddens = false) const; SC_DLLPUBLIC bool GetPrintAreaHor( SCTAB nTab, SCROW nStartRow, SCROW nEndRow, SCCOL& rEndCol ) const; SC_DLLPUBLIC bool GetPrintAreaVer( SCTAB nTab, SCCOL nStartCol, SCCOL nEndCol, diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index ea13cf9b4071..5cba3d0af77b 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -198,6 +198,8 @@ private: mutable SCCOL nTableAreaX; mutable SCROW nTableAreaY; + mutable SCCOL nTableAreaVisibleX; + mutable SCROW nTableAreaVisibleY; SCTAB nTab; ScDocument& rDocument; @@ -232,6 +234,7 @@ private: bool bLoadingRTL:1; bool bPageSizeValid:1; mutable bool bTableAreaValid:1; + mutable bool bTableAreaVisibleValid:1; bool bVisible:1; bool bStreamValid:1; bool bPendingRowHeights:1; @@ -567,8 +570,8 @@ public: void InvalidatePageBreaks(); bool GetCellArea( SCCOL& rEndCol, SCROW& rEndRow ) const; // FALSE = empty - bool GetTableArea( SCCOL& rEndCol, SCROW& rEndRow ) const; - bool GetPrintArea( SCCOL& rEndCol, SCROW& rEndRow, bool bNotes ) const; + bool GetTableArea( SCCOL& rEndCol, SCROW& rEndRow, bool bCalcHiddens = false) const; + bool GetPrintArea( SCCOL& rEndCol, SCROW& rEndRow, bool bNotes, bool bCalcHiddens = false) const; bool GetPrintAreaHor( SCROW nStartRow, SCROW nEndRow, SCCOL& rEndCol ) const; bool GetPrintAreaVer( SCCOL nStartCol, SCCOL nEndCol, diff --git a/sc/qa/unit/bugfix-test.cxx b/sc/qa/unit/bugfix-test.cxx index be2a00a94e76..88b48326505e 100644 --- a/sc/qa/unit/bugfix-test.cxx +++ b/sc/qa/unit/bugfix-test.cxx @@ -58,6 +58,7 @@ public: void testTdf128951(); void testTdf129789(); void testTdf130725(); + void testTdf104502_hiddenColsCountedInPageCount(); CPPUNIT_TEST_SUITE(ScFiltersTest); CPPUNIT_TEST(testTdf137576_Measureline); @@ -80,6 +81,7 @@ public: CPPUNIT_TEST(testTdf128951); CPPUNIT_TEST(testTdf129789); CPPUNIT_TEST(testTdf130725); + CPPUNIT_TEST(testTdf104502_hiddenColsCountedInPageCount); CPPUNIT_TEST_SUITE_END(); private: @@ -716,6 +718,23 @@ void ScFiltersTest::testTdf130725() 0.0042, xCell->getValue()); // strict equality } +void ScFiltersTest::testTdf104502_hiddenColsCountedInPageCount() +{ + ScDocShellRef xShell = loadDoc(u"tdf104502_hiddenColsCountedInPageCount.", FORMAT_ODS); + CPPUNIT_ASSERT(xShell.is()); + + ScDocument& rDoc = xShell->GetDocument(); + + //Check that hidden columns are not calculated into Print Area + SCCOL nEndCol = 0; + SCROW nEndRow = 0; + CPPUNIT_ASSERT(rDoc.GetPrintArea(0, nEndCol, nEndRow, false)); + CPPUNIT_ASSERT_EQUAL(SCCOL(0), nEndCol); + CPPUNIT_ASSERT_EQUAL(SCROW(55), nEndRow); + + xShell->DoClose(); +} + ScFiltersTest::ScFiltersTest() : ScBootstrapFixture( "sc/qa/unit/data" ) { diff --git a/sc/qa/unit/data/ods/tdf104502_hiddenColsCountedInPageCount.ods b/sc/qa/unit/data/ods/tdf104502_hiddenColsCountedInPageCount.ods new file mode 100644 index 000000000000..166b86b2e8c1 Binary files /dev/null and b/sc/qa/unit/data/ods/tdf104502_hiddenColsCountedInPageCount.ods differ diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx index be95822d89ba..5a624e8fe24a 100644 --- a/sc/source/core/data/documen2.cxx +++ b/sc/source/core/data/documen2.cxx @@ -571,11 +571,11 @@ const svl::SharedStringPool& ScDocument::GetSharedStringPool() const } bool ScDocument::GetPrintArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow, - bool bNotes ) const + bool bNotes, bool bCalcHiddens) const { if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab]) { - bool bAny = maTabs[nTab]->GetPrintArea( rEndCol, rEndRow, bNotes ); + bool bAny = maTabs[nTab]->GetPrintArea( rEndCol, rEndRow, bNotes, bCalcHiddens); if (mpDrawLayer) { ScRange aDrawRange(0,0,nTab, MaxCol(),MaxRow(),nTab); diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index b3cac25303af..a2eead753ae3 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -1018,11 +1018,11 @@ bool ScDocument::GetCellArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow ) const return false; } -bool ScDocument::GetTableArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow ) const +bool ScDocument::GetTableArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow, bool bCalcHiddens) const { if (ValidTab(nTab) && nTab < static_cast<SCTAB> (maTabs.size())) if (maTabs[nTab]) - return maTabs[nTab]->GetTableArea( rEndCol, rEndRow ); + return maTabs[nTab]->GetTableArea( rEndCol, rEndRow, bCalcHiddens); rEndCol = 0; rEndRow = 0; diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx index 11ac1f1d3e83..8b4a6e1344da 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -248,6 +248,8 @@ ScTable::ScTable( ScDocument& rDoc, SCTAB nNewTab, const OUString& rNewName, mpFilteredRows(new ScFlatBoolRowSegments(rDoc.MaxRow())), nTableAreaX( 0 ), nTableAreaY( 0 ), + nTableAreaVisibleX( 0 ), + nTableAreaVisibleY( 0 ), nTab( nNewTab ), rDocument( rDoc ), pSortCollator( nullptr ), @@ -540,22 +542,35 @@ bool ScTable::GetCellArea( SCCOL& rEndCol, SCROW& rEndRow ) const return bFound; } -bool ScTable::GetTableArea( SCCOL& rEndCol, SCROW& rEndRow ) const +bool ScTable::GetTableArea( SCCOL& rEndCol, SCROW& rEndRow, bool bCalcHiddens) const { bool bRet = true; //TODO: remember? - if (!bTableAreaValid) + if (bCalcHiddens) { - bRet = GetPrintArea(nTableAreaX, nTableAreaY, true); - bTableAreaValid = true; + if (!bTableAreaValid) + { + bRet = GetPrintArea(nTableAreaX, nTableAreaY, true, bCalcHiddens); + bTableAreaValid = true; + } + rEndCol = nTableAreaX; + rEndRow = nTableAreaY; + } + else + { + if (!bTableAreaVisibleValid) + { + bRet = GetPrintArea(nTableAreaVisibleX, nTableAreaVisibleY, true, bCalcHiddens); + bTableAreaVisibleValid = true; + } + rEndCol = nTableAreaVisibleX; + rEndRow = nTableAreaVisibleY; } - rEndCol = nTableAreaX; - rEndRow = nTableAreaY; return bRet; } const SCCOL SC_COLUMNS_STOP = 30; -bool ScTable::GetPrintArea( SCCOL& rEndCol, SCROW& rEndRow, bool bNotes ) const +bool ScTable::GetPrintArea( SCCOL& rEndCol, SCROW& rEndRow, bool bNotes, bool bCalcHiddens ) const { bool bFound = false; SCCOL nMaxX = 0; @@ -563,6 +578,8 @@ bool ScTable::GetPrintArea( SCCOL& rEndCol, SCROW& rEndRow, bool bNotes ) const SCCOL i; for (i=0; i<aCol.size(); i++) // Test data + { + if (bCalcHiddens || !rDocument.ColHidden(i, nTab)) { if (!aCol[i].IsEmptyData()) { @@ -588,18 +605,22 @@ bool ScTable::GetPrintArea( SCCOL& rEndCol, SCROW& rEndRow, bool bNotes ) const } } } + } SCCOL nMaxDataX = nMaxX; for (i=0; i<aCol.size(); i++) // Test attribute { - SCROW nLastRow; - if (aCol[i].GetLastVisibleAttr( nLastRow )) + if (bCalcHiddens || !rDocument.ColHidden(i, nTab)) { - bFound = true; - nMaxX = i; - if (nLastRow > nMaxY) - nMaxY = nLastRow; + SCROW nLastRow; + if (aCol[i].GetLastVisibleAttr( nLastRow )) + { + bFound = true; + nMaxX = i; + if (nLastRow > nMaxY) + nMaxY = nLastRow; + } } } diff --git a/sc/source/ui/unoobj/cursuno.cxx b/sc/source/ui/unoobj/cursuno.cxx index a301be0ae24f..7928fceb0dbb 100644 --- a/sc/source/ui/unoobj/cursuno.cxx +++ b/sc/source/ui/unoobj/cursuno.cxx @@ -257,7 +257,7 @@ void SAL_CALL ScCellCursorObj::gotoEndOfUsedArea( sal_Bool bExpand ) SCCOL nUsedX = 0; // fetch the end SCROW nUsedY = 0; - if (!pDocSh->GetDocument().GetTableArea( nTab, nUsedX, nUsedY )) + if (!pDocSh->GetDocument().GetTableArea( nTab, nUsedX, nUsedY, true )) { nUsedX = 0; nUsedY = 0; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits