[Libreoffice-commits] core.git: Branch 'distro/nisz/libreoffice-7-0' - sc/inc sc/qa sc/source

Attila Szűcs (via logerrit) logerrit at kemper.freedesktop.org
Thu Apr 22 10:50:08 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 1ff3352565040f5357f96b4568fe29e5ca213d41
Author:     Attila Szűcs <szucs.attila3 at nisz.hu>
AuthorDate: Wed Jan 27 17:43:43 2021 +0100
Commit:     Gabor Kelemen <kelemen.gabor2 at nisz.hu>
CommitDate: Thu Apr 22 12:49:34 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 <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>
    (cherry picked from commit 2bf3e0d00e3bccb5b250642ee0d3fdbe6cae8ecc)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114430
    Tested-by: Gabor Kelemen <kelemen.gabor2 at nisz.hu>
    Reviewed-by: Gabor Kelemen <kelemen.gabor2 at nisz.hu>

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 2b91d9fc32c3..e31d9fd1a0de 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1452,9 +1452,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 5b3c09a18fc0..7141f2652bfa 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -197,6 +197,8 @@ private:
 
     mutable SCCOL nTableAreaX;
     mutable SCROW nTableAreaY;
+    mutable SCCOL nTableAreaVisibleX;
+    mutable SCROW nTableAreaVisibleY;
 
     SCTAB           nTab;
     ScDocument*     pDocument;
@@ -229,6 +231,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;
@@ -564,8 +567,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 2b2523319cec..10e414009270 100644
--- a/sc/qa/unit/bugfix-test.cxx
+++ b/sc/qa/unit/bugfix-test.cxx
@@ -48,6 +48,7 @@ public:
     void testTdf128951();
     void testTdf129789();
     void testTdf130725();
+    void testTdf104502_hiddenColsCountedInPageCount();
 
     CPPUNIT_TEST_SUITE(ScFiltersTest);
     CPPUNIT_TEST(testTdf64229);
@@ -66,6 +67,7 @@ public:
     CPPUNIT_TEST(testTdf128951);
     CPPUNIT_TEST(testTdf129789);
     CPPUNIT_TEST(testTdf130725);
+    CPPUNIT_TEST(testTdf104502_hiddenColsCountedInPageCount);
     CPPUNIT_TEST_SUITE_END();
 private:
     uno::Reference<uno::XInterface> m_xCalcComponent;
@@ -500,6 +502,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 6e52ee8fb8fe..54975921add7 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -567,11 +567,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 ad292b70b7e2..3eca0be1ffda 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -1025,11 +1025,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 16e6e5d594d5..fcdde031ec24 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -248,6 +248,8 @@ ScTable::ScTable( ScDocument* pDoc, SCTAB nNewTab, const OUString& rNewName,
     mpFilteredRows(new ScFlatBoolRowSegments(pDoc->MaxRow())),
     nTableAreaX( 0 ),
     nTableAreaY( 0 ),
+    nTableAreaVisibleX( 0 ),
+    nTableAreaVisibleY( 0 ),
     nTab( nNewTab ),
     pDocument( pDoc ),
     pSortCollator( nullptr ),
@@ -539,22 +541,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;
@@ -562,6 +577,8 @@ bool ScTable::GetPrintArea( SCCOL& rEndCol, SCROW& rEndRow, bool bNotes ) const
     SCCOL i;
 
     for (i=0; i<aCol.size(); i++)               // Test data
+    {
+        if (bCalcHiddens || !pDocument->ColHidden(i, nTab))
         {
             if (!aCol[i].IsEmptyData())
             {
@@ -587,18 +604,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 || !pDocument->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 6f18ed237c76..61f0bfb71254 100644
--- a/sc/source/ui/unoobj/cursuno.cxx
+++ b/sc/source/ui/unoobj/cursuno.cxx
@@ -256,7 +256,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