[Libreoffice-commits] core.git: sc/inc sc/qa sc/source

Attila Szűcs (via logerrit) logerrit at kemper.freedesktop.org
Tue Feb 9 15:38:31 UTC 2021


 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 2bf3e0d00e3bccb5b250642ee0d3fdbe6cae8ecc
Author:     Attila Szűcs <szucs.attila3 at nisz.hu>
AuthorDate: Wed Jan 27 17:43:43 2021 +0100
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Tue Feb 9 16:37:51 2021 +0100

    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 <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 79091e89504c..6d012c9b01ec 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 309d49d4f140..fed4d4b12388 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 874069ade2f5..384591fe1a10 100644
--- a/sc/qa/unit/bugfix-test.cxx
+++ b/sc/qa/unit/bugfix-test.cxx
@@ -59,6 +59,7 @@ public:
     void testTdf128951();
     void testTdf129789();
     void testTdf130725();
+    void testTdf104502_hiddenColsCountedInPageCount();
 
     CPPUNIT_TEST_SUITE(ScFiltersTest);
     CPPUNIT_TEST(testTdf137576_Measureline);
@@ -81,6 +82,7 @@ public:
     CPPUNIT_TEST(testTdf128951);
     CPPUNIT_TEST(testTdf129789);
     CPPUNIT_TEST(testTdf130725);
+    CPPUNIT_TEST(testTdf104502_hiddenColsCountedInPageCount);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -721,6 +723,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 56e4fac4d711..e49694224fd6 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 48282126b0fc..ba9cee894875 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -1016,11 +1016,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 0e35edf44d05..0665e90a4542 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -249,6 +249,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 ),
@@ -541,22 +543,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;
@@ -564,6 +579,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())
             {
@@ -589,18 +606,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;


More information about the Libreoffice-commits mailing list