sc/inc/document.hxx              |    3 +-
 sc/inc/table.hxx                 |    3 +-
 sc/source/core/data/document.cxx |   12 ++++++++--
 sc/source/core/data/drwlayer.cxx |    7 +-----
 sc/source/core/data/table5.cxx   |   44 ++++++++++++++++++++++++++++-----------
 5 files changed, 48 insertions(+), 21 deletions(-)

New commits:
commit a1b4eca5fc9898b9741325de52b89f406635b52a
Author:     Balazs Varga <balazs.varga.ext...@allotropia.de>
AuthorDate: Sat Mar 25 18:57:08 2023 +0100
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Thu Mar 30 16:14:52 2023 +0000

    Related: tdf#154005 sc ods fileopen: fix dropdown form control size
    
    Fixing the crashtesting assert/crash after the original change.
    Also a little clean-up.
    
    Change-Id: I35453fbc55b3d5d4064179e84755334c2d3a01ca
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149583
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Reviewed-by: Balazs Varga <balazs.varga.ext...@allotropia.de>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149683
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>
    Tested-by: Thorsten Behrens <thorsten.behr...@allotropia.de>

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 03a4345ead15..6c0c58b001b2 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1919,7 +1919,8 @@ public:
     SC_DLLPUBLIC SCROW          FirstVisibleRow(SCROW nStartRow, SCROW 
nEndRow, SCTAB nTab) const;
     SC_DLLPUBLIC SCROW          LastVisibleRow(SCROW nStartRow, SCROW nEndRow, 
SCTAB nTab) const;
     SCROW                       CountVisibleRows(SCROW nStartRow, SCROW 
nEndRow, SCTAB nTab) const;
-    SCCOL                       CountVisibleCols(SCROW nStartCol, SCROW 
nEndCol, SCTAB nTab) const;
+    SCROW                       CountHiddenRows(SCROW nStartRow, SCROW 
nEndRow, SCTAB nTab) const;
+    SCCOL                       CountHiddenCols(SCROW nStartCol, SCROW 
nEndCol, SCTAB nTab) const;
 
     bool                        RowFiltered(SCROW nRow, SCTAB nTab, SCROW* 
pFirstRow = nullptr, SCROW* pLastRow = nullptr) const;
     bool                        HasFilteredRows(SCROW nStartRow, SCROW 
nEndRow, SCTAB nTab) const;
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index cc90bd31b980..96f31c9ca2a6 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -905,8 +905,9 @@ public:
     SCROW       FirstVisibleRow(SCROW nStartRow, SCROW nEndRow) const;
     SCROW       LastVisibleRow(SCROW nStartRow, SCROW nEndRow) const;
     SCROW       CountVisibleRows(SCROW nStartRow, SCROW nEndRow) const;
-    SCCOL       CountVisibleCols(SCCOL nStartCol, SCCOL nEndCol) const;
+    SCROW       CountHiddenRows(SCROW nStartRow, SCROW nEndRow) const;
     sal_uInt32  GetTotalRowHeight(SCROW nStartRow, SCROW nEndRow, bool 
bHiddenAsZero = true) const;
+    SCCOL       CountHiddenCols(SCCOL nStartCol, SCCOL nEndCol) const;
 
     SCCOLROW    LastHiddenColRow(SCCOLROW nPos, bool bCol) const;
 
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index a9c794fab7ec..c5b65d0a37fd 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -4483,12 +4483,20 @@ SCROW ScDocument::CountVisibleRows(SCROW nStartRow, 
SCROW nEndRow, SCTAB nTab) c
     return maTabs[nTab]->CountVisibleRows(nStartRow, nEndRow);
 }
 
-SCCOL ScDocument::CountVisibleCols(SCROW nStartCol, SCROW nEndCol, SCTAB nTab) 
const
+SCROW ScDocument::CountHiddenRows(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) 
const
 {
     if (!ValidTab(nTab) || nTab >= static_cast<SCTAB>(maTabs.size()) || 
!maTabs[nTab])
         return 0;
 
-    return maTabs[nTab]->CountVisibleCols(nStartCol, nEndCol);
+    return maTabs[nTab]->CountHiddenRows(nStartRow, nEndRow);
+}
+
+SCCOL ScDocument::CountHiddenCols(SCROW nStartCol, SCROW nEndCol, SCTAB nTab) 
const
+{
+    if (!ValidTab(nTab) || nTab >= static_cast<SCTAB>(maTabs.size()) || 
!maTabs[nTab])
+        return 0;
+
+    return maTabs[nTab]->CountHiddenCols(nStartCol, nEndCol);
 }
 
 bool ScDocument::RowFiltered(SCROW nRow, SCTAB nTab, SCROW* pFirstRow, SCROW* 
pLastRow) const
diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx
index 03d30c914dad..8dd013f1a817 100644
--- a/sc/source/core/data/drwlayer.cxx
+++ b/sc/source/core/data/drwlayer.cxx
@@ -671,11 +671,8 @@ void lcl_SetLogicRectFromAnchor(SdrObject* pObj, 
ScDrawObjData& rAnchor, ScDocum
     // tdf#154005: Handle hidden row/col: remove hidden row/cols size from the 
ScDrawObjData shape size in case of forms
     if (pObj->GetObjIdentifier() == SdrObjKind::OBJ_UNO && 
pObj->GetObjInventor() == SdrInventor::FmForm)
     {
-        nHiddenRows = ((rAnchor.maEnd.Row() - rAnchor.maStart.Row()) + 1) -
-            (pDoc->CountVisibleRows(rAnchor.maStart.Row(), 
rAnchor.maEnd.Row(), rAnchor.maStart.Tab()));
-
-        nHiddenCols = ((rAnchor.maEnd.Col() - rAnchor.maStart.Col()) + 1) -
-            (pDoc->CountVisibleCols(rAnchor.maStart.Col(), 
rAnchor.maEnd.Col(), rAnchor.maStart.Tab()));
+        nHiddenRows = pDoc->CountHiddenRows(rAnchor.maStart.Row(), 
rAnchor.maEnd.Row(), rAnchor.maStart.Tab());
+        nHiddenCols = pDoc->CountHiddenCols(rAnchor.maStart.Col(), 
rAnchor.maEnd.Col(), rAnchor.maStart.Tab());
     }
 
     // In case of a vertical mirrored custom shape, LibreOffice uses 
internally an additional 180deg
diff --git a/sc/source/core/data/table5.cxx b/sc/source/core/data/table5.cxx
index 9756f13d8390..7d94d82b744b 100644
--- a/sc/source/core/data/table5.cxx
+++ b/sc/source/core/data/table5.cxx
@@ -775,24 +775,23 @@ SCROW ScTable::CountVisibleRows(SCROW nStartRow, SCROW 
nEndRow) const
     return nCount;
 }
 
-SCCOL ScTable::CountVisibleCols(SCCOL nStartCol, SCCOL nEndCol) const
+SCROW ScTable::CountHiddenRows(SCROW nStartRow, SCROW nEndRow) const
 {
-    assert(nStartCol <= nEndCol);
-    SCCOL nCount = 0;
-    SCCOL nCol = nStartCol;
-    ScFlatBoolColSegments::RangeData aData;
-    while (nCol <= nEndCol)
+    SCROW nCount = 0;
+    SCROW nRow = nStartRow;
+    ScFlatBoolRowSegments::RangeData aData;
+    while (nRow <= nEndRow)
     {
-        if (!mpHiddenCols->getRangeData(nCol, aData))
+        if (!mpHiddenRows->getRangeData(nRow, aData))
             break;
 
-        if (aData.mnCol2 > nEndCol)
-            aData.mnCol2 = nEndCol;
+        if (aData.mnRow2 > nEndRow)
+            aData.mnRow2 = nEndRow;
 
-        if (!aData.mbValue)
-            nCount += aData.mnCol2 - nCol + 1;
+        if (aData.mbValue)
+            nCount += aData.mnRow2 - nRow + 1;
 
-        nCol = aData.mnCol2 + 1;
+        nRow = aData.mnRow2 + 1;
     }
     return nCount;
 }
@@ -820,6 +819,27 @@ sal_uInt32 ScTable::GetTotalRowHeight(SCROW nStartRow, 
SCROW nEndRow, bool bHidd
     return nHeight;
 }
 
+SCCOL ScTable::CountHiddenCols(SCCOL nStartCol, SCCOL nEndCol) const
+{
+    SCCOL nCount = 0;
+    SCCOL nCol = nStartCol;
+    ScFlatBoolColSegments::RangeData aData;
+    while (nCol <= nEndCol)
+    {
+        if (!mpHiddenCols->getRangeData(nCol, aData))
+            break;
+
+        if (aData.mnCol2 > nEndCol)
+            aData.mnCol2 = nEndCol;
+
+        if (aData.mbValue)
+            nCount += aData.mnCol2 - nCol + 1;
+
+        nCol = aData.mnCol2 + 1;
+    }
+    return nCount;
+}
+
 SCCOLROW ScTable::LastHiddenColRow(SCCOLROW nPos, bool bCol) const
 {
     if (bCol)

Reply via email to