tdf#147404 sc AutoFillPreview: consider hidden cells
Back in the days before LO 3.6, only filtered cells
were skipped by autoFill. But when hidden cells were
also skipped, the preview function wasn't updated to look
for hidden cells instead of filtered cells.
(I said "instead" because filtered cells are also
considered to be hidden, so it encompasses both cases.)
Change-Id: I38b230361f0f0f1722873bbdd2c870d55b77bd06
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129912
Tested-by: Jenkins
Reviewed-by: Justin Luth <jluth@mail.com>
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 30c92cd..08624a9 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -928,6 +928,8 @@ public:
SCROW CountVisibleRows(SCROW nStartRow, SCROW nEndRow) const;
tools::Long GetTotalRowHeight(SCROW nStartRow, SCROW nEndRow, bool bHiddenAsZero = true) const;
SCCOL CountVisibleCols(SCCOL nStartCol, SCCOL nEndCol) const;
SCCOLROW LastHiddenColRow(SCCOLROW nPos, bool bCol) const;
bool RowFiltered(SCROW nRow, SCROW* pFirstRow = nullptr, SCROW* pLastRow = nullptr) const;
diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx
index a4b232e..a3d49aa 100644
--- a/sc/source/core/data/table4.cxx
+++ b/sc/source/core/data/table4.cxx
@@ -1247,6 +1247,49 @@ OUString ScTable::GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW
if ( bOk )
{
tools::Long nBegin = 0;
tools::Long nEnd = 0;
tools::Long nHidden = 0;
if (eFillDir == FILL_TO_BOTTOM || eFillDir == FILL_TO_TOP)
{
if (nEndY > nRow1)
{
nBegin = nRow2+1;
nEnd = nEndY;
}
else
{
nBegin = nEndY;
nEnd = nRow1 -1;
}
tools::Long nVisible = CountVisibleRows(nBegin, nEnd);
nHidden = nEnd + 1 - nBegin - nVisible;
}
else
{
if (nEndX > nCol1)
{
nBegin = nCol2+1;
nEnd = nEndX;
}
else
{
nBegin = nEndX;
nEnd = nCol1 -1;
}
tools::Long nVisible = CountVisibleCols(nBegin, nEnd);
nHidden = nEnd + 1 - nBegin - nVisible;
}
if (nHidden)
{
if (nIndex > 0)
nIndex = nIndex - nHidden;
else
nIndex = nIndex + nHidden;
}
FillCmd eFillCmd;
FillDateCmd eDateCmd;
double nInc;
@@ -1277,30 +1320,6 @@ OUString ScTable::GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW
}
else if ( eFillCmd == FILL_SIMPLE ) // fill with pattern/sample
{
if ((eFillDir == FILL_TO_BOTTOM)||(eFillDir == FILL_TO_TOP))
{
tools::Long nBegin = 0;
tools::Long nEnd = 0;
if (nEndY > nRow1)
{
nBegin = nRow2+1;
nEnd = nEndY;
}
else
{
nBegin = nEndY;
nEnd = nRow1 -1;
}
tools::Long nNonFiltered = CountNonFilteredRows(nBegin, nEnd);
tools::Long nFiltered = nEnd + 1 - nBegin - nNonFiltered;
if (nIndex > 0)
nIndex = nIndex - nFiltered;
else
nIndex = nIndex + nFiltered;
}
tools::Long nPosIndex = nIndex;
while ( nPosIndex < 0 )
nPosIndex += nSrcCount;
diff --git a/sc/source/core/data/table5.cxx b/sc/source/core/data/table5.cxx
index d62b94e..4c51021 100644
--- a/sc/source/core/data/table5.cxx
+++ b/sc/source/core/data/table5.cxx
@@ -796,6 +796,28 @@ tools::Long ScTable::GetTotalRowHeight(SCROW nStartRow, SCROW nEndRow, bool bHid
return nHeight;
}
SCCOL ScTable::CountVisibleCols(SCCOL nStartCol, SCCOL nEndCol) const
{
assert(nStartCol <= nEndCol);
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)