sc/inc/attarray.hxx              |    2 -
 sc/inc/column.hxx                |    6 ++--
 sc/source/core/data/attarray.cxx |   56 +++++++++++++++++++++++----------------
 sc/source/core/data/table1.cxx   |   12 ++++++--
 4 files changed, 47 insertions(+), 29 deletions(-)

New commits:
commit 87ca7d2f146be2c309fc6fd36f9154f3ea4e4bd8
Author:     Czeber László Ádám <czeber.laszloa...@nisz.hu>
AuthorDate: Mon Jun 19 11:02:23 2023 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Tue Jul 25 00:32:30 2023 +0200

    tdf#93315 sc: Only 84 empty row show in the Print Preview
    
    Change in Calc behaviour, dropping the 84 line limit.
    This way, if all rows or columns are bordered, only up to the last
    cell containing data is displayed in the Print Preview. In other
    cases, all bordered cells are visible.
    
    Change-Id: I7d874a093d76d5ed92b1b63b645b97582d52629e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153256
    Tested-by: Jenkins
    Reviewed-by: Eike Rathke <er...@redhat.com>

diff --git a/sc/inc/attarray.hxx b/sc/inc/attarray.hxx
index 868118796560..cbc8f7cfe2f9 100644
--- a/sc/inc/attarray.hxx
+++ b/sc/inc/attarray.hxx
@@ -203,7 +203,7 @@ public:
     bool    IsEmpty() const;
 
     bool    GetFirstVisibleAttr( SCROW& rFirstRow ) const;
-    bool    GetLastVisibleAttr( SCROW& rLastRow, SCROW nLastData ) const;
+    bool    GetLastVisibleAttr( SCROW& rLastRow, SCROW nLastData, bool 
bSkipEmpty ) const;
     bool    HasVisibleAttrIn( SCROW nStartRow, SCROW nEndRow ) const;
     bool    IsVisibleEqual( const ScAttrArray& rOther,
                             SCROW nStartRow, SCROW nEndRow ) const;
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 4b64537e1705..fe3b84842af2 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -313,7 +313,7 @@ public:
     bool    HasSelectionMatrixFragment(const ScMarkData& rMark, const 
ScRangeList& rRangeList) const;
 
     bool    GetFirstVisibleAttr( SCROW& rFirstRow ) const;
-    bool    GetLastVisibleAttr( SCROW& rLastRow ) const;
+    bool    GetLastVisibleAttr( SCROW& rLastRow, bool bSkipEmpty ) const;
     bool    HasVisibleAttrIn( SCROW nStartRow, SCROW nEndRow ) const;
     bool    IsVisibleAttrEqual( const ScColumn& rCol, SCROW nStartRow, SCROW 
nEndRow ) const;
 
@@ -890,11 +890,11 @@ inline bool ScColumn::GetFirstVisibleAttr( SCROW& 
rFirstRow ) const
     return pAttrArray->GetFirstVisibleAttr( rFirstRow );
 }
 
-inline bool ScColumn::GetLastVisibleAttr( SCROW& rLastRow ) const
+inline bool ScColumn::GetLastVisibleAttr( SCROW& rLastRow, bool bSkipEmpty ) 
const
 {
     // row of last cell is needed
     SCROW nLastData = GetLastDataPos();    // always including notes, 0 if none
-    return pAttrArray->GetLastVisibleAttr( rLastRow, nLastData );
+    return pAttrArray->GetLastVisibleAttr( rLastRow, nLastData, bSkipEmpty );
 }
 
 inline bool ScColumn::HasVisibleAttrIn( SCROW nStartRow, SCROW nEndRow ) const
diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx
index 87fa2c11ccf1..02b6b9d793ed 100644
--- a/sc/source/core/data/attarray.cxx
+++ b/sc/source/core/data/attarray.cxx
@@ -1942,7 +1942,7 @@ bool ScAttrArray::GetFirstVisibleAttr( SCROW& rFirstRow ) 
const
 
 const SCROW SC_VISATTR_STOP = 84;
 
-bool ScAttrArray::GetLastVisibleAttr( SCROW& rLastRow, SCROW nLastData ) const
+bool ScAttrArray::GetLastVisibleAttr( SCROW& rLastRow, SCROW nLastData, bool 
bSkipEmpty ) const
 {
     if ( mvData.empty() )
     {
@@ -1971,31 +1971,43 @@ bool ScAttrArray::GetLastVisibleAttr( SCROW& rLastRow, 
SCROW nLastData ) const
         rLastRow = nLastData;
         return false;
     }
-
-    // Find a run below last data row.
+    // tdf#93315: If "Suppress output of empty pages" in Calc Options is not 
checked, show empty
+    // (containing only empty data cells) page in the document
     bool bFound = false;
-    Search( nLastData, nPos );
-    while ( nPos < mvData.size() )
+    if (bSkipEmpty)
+    {
+        Search( nLastData, nPos );
+        while ( nPos < mvData.size() )
+        {
+            // find range of visually equal formats
+            SCSIZE nEndPos = nPos;
+            while ( nEndPos < mvData.size()-1 &&
+                    
mvData[nEndPos].pPattern->IsVisibleEqual(*mvData[nEndPos+1].pPattern))
+                ++nEndPos;
+            SCROW nAttrStartRow = ( nPos > 0 ) ? ( mvData[nPos-1].nEndRow + 1) 
: 0;
+            if ( nAttrStartRow <= nLastData )
+                nAttrStartRow = nLastData + 1;
+            SCROW nAttrSize = mvData[nEndPos].nEndRow + 1 - nAttrStartRow;
+            if ( nAttrSize >= SC_VISATTR_STOP )
+                break;  // while, ignore this range and below
+            else if ( mvData[nEndPos].pPattern->IsVisible() )
+            {
+                rLastRow = mvData[nEndPos].nEndRow;
+                bFound = true;
+            }
+            nPos = nEndPos + 1;
+        }
+    }
+    else
     {
-        // find range of visually equal formats
-        SCSIZE nEndPos = nPos;
-        while ( nEndPos < mvData.size()-1 &&
-                mvData[nEndPos].pPattern->IsVisibleEqual( 
*mvData[nEndPos+1].pPattern))
-            ++nEndPos;
-        SCROW nAttrStartRow = ( nPos > 0 ) ? ( mvData[nPos-1].nEndRow + 1 ) : 
0;
-        if ( nAttrStartRow <= nLastData )
-            nAttrStartRow = nLastData + 1;
-        SCROW nAttrSize = mvData[nEndPos].nEndRow + 1 - nAttrStartRow;
-        if ( nAttrSize >= SC_VISATTR_STOP )
-            break;  // while, ignore this range and below
-        else if ( mvData[nEndPos].pPattern->IsVisible() )
-        {
-            rLastRow = mvData[nEndPos].nEndRow;
-            bFound = true;
+        if ((nPos > 0 && mvData[nPos-1].pPattern->IsVisible())
+                || (nPos > 1 && 
!mvData[nPos-1].pPattern->IsVisibleEqual(*mvData[nPos-2].pPattern)))
+        {
+            rLastRow = mvData[nPos-1].nEndRow;
+            return true;
         }
-        nPos = nEndPos + 1;
+        rLastRow = nLastData;
     }
-
     return bFound;
 }
 
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 3b33b7e242a3..fff48f1e0c3f 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -37,6 +37,8 @@
 #include <markdata.hxx>
 #include <progress.hxx>
 #include <prnsave.hxx>
+#include <printopt.hxx>
+#include <scmod.hxx>
 #include <tabprotection.hxx>
 #include <sheetevents.hxx>
 #include <segmenttree.hxx>
@@ -610,6 +612,8 @@ bool ScTable::GetPrintArea( SCCOL& rEndCol, SCROW& rEndRow, 
bool bNotes, bool bC
     SCROW nMaxY = 0;
     SCCOL i;
 
+    bool bSkipEmpty = SC_MOD()->GetPrintOptions().GetSkipEmpty();
+
     for (i=0; i<aCol.size(); i++)               // Test data
     {
         if (bCalcHiddens || !rDocument.ColHidden(i, nTab))
@@ -661,7 +665,7 @@ bool ScTable::GetPrintArea( SCCOL& rEndCol, SCROW& rEndRow, 
bool bNotes, bool bC
         if (bCalcHiddens || !rDocument.ColHidden(i, nTab))
         {
             SCROW nLastRow;
-            if (aCol[i].GetLastVisibleAttr( nLastRow ))
+            if (aCol[i].GetLastVisibleAttr( nLastRow, bSkipEmpty ))
             {
                 bFound = true;
                 nMaxX = i;
@@ -697,7 +701,7 @@ bool ScTable::GetPrintArea( SCCOL& rEndCol, SCROW& rEndRow, 
bool bNotes, bool bC
 
                 // also don't include default-formatted columns before that
                 SCROW nDummyRow;
-                while ( nMaxX > nMaxDataX && !aCol[nMaxX].GetLastVisibleAttr( 
nDummyRow ) )
+                while ( nMaxX > nMaxDataX && !aCol[nMaxX].GetLastVisibleAttr( 
nDummyRow, bSkipEmpty ) )
                     --nMaxX;
                 break;
             }
@@ -762,10 +766,12 @@ bool ScTable::GetPrintAreaVer( SCCOL nStartCol, SCCOL 
nEndCol,
     SCROW nMaxY = 0;
     SCCOL i;
 
+    bool bSkipEmpty = SC_MOD()->GetPrintOptions().GetSkipEmpty();
+
     for (i=nStartCol; i<=nEndCol && i < aCol.size(); i++)              // Test 
attribute
     {
         SCROW nLastRow;
-        if (aCol[i].GetLastVisibleAttr( nLastRow ))
+        if (aCol[i].GetLastVisibleAttr( nLastRow, bSkipEmpty ))
         {
             bFound = true;
             if (nLastRow > nMaxY)

Reply via email to