sc/inc/table.hxx | 2 + sc/source/core/data/table4.cxx | 67 ++++++++++++++++++++++++++--------------- sc/source/core/data/table5.cxx | 22 +++++++++++++ 3 files changed, 67 insertions(+), 24 deletions(-)
New commits: commit 9cd4da63b6ed19b71a2475fccb4ab135f0a87873 Author: Justin Luth <justin_l...@sil.org> AuthorDate: Mon Feb 14 14:40:06 2022 +0200 Commit: Eike Rathke <er...@redhat.com> CommitDate: Fri Feb 25 18:46:54 2022 +0100 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 <jl...@mail.com> diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 30c92cd87520..08624a937172 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 a4b232ea44d9..a3d49aa1c190 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 d62b94e40f28..4c510213edd9 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)