sc/inc/dbdata.hxx | 1 + sc/inc/document.hxx | 7 +++++++ sc/inc/table.hxx | 3 +++ sc/source/core/data/document.cxx | 7 +++++++ sc/source/core/data/table4.cxx | 34 ++++++++++++++++++++++++++++++++++ sc/source/core/tool/dbdata.cxx | 17 +++++++++++++++++ sc/source/ui/view/gridwin.cxx | 1 + sc/source/ui/view/tabvwshc.cxx | 1 + 8 files changed, 71 insertions(+)
New commits: commit 644ad239a22f438b300f1dd7fbf602e920075316 Author: Henry Castro <hcas...@collabora.com> AuthorDate: Mon Nov 6 07:18:48 2023 -0400 Commit: Henry Castro <hcas...@collabora.com> CommitDate: Wed Nov 29 20:55:50 2023 +0100 sc: extend backcolor area If the filter background color is selected, the automatic selection area should include, the attribute of background cell color too. Signed-off-by: Henry Castro <hcas...@collabora.com> Change-Id: I341c602247e7f71e3c9665e1b594177d8f5553b5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158991 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit 768433f07873eb608837630f85e7e1b375239fca) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159238 Tested-by: Jenkins Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160109 diff --git a/sc/inc/dbdata.hxx b/sc/inc/dbdata.hxx index 482c55bc6aa4..df235ec52619 100644 --- a/sc/inc/dbdata.hxx +++ b/sc/inc/dbdata.hxx @@ -221,6 +221,7 @@ public: SCCOL nDx, SCROW nDy, SCTAB nDz); void ExtendDataArea(const ScDocument& rDoc); + void ExtendBackColorArea(const ScDocument& rDoc); void CalcSaveFilteredCount(SCSIZE nNonFilteredRowCount); void GetFilterSelCount(SCSIZE& nSelected, SCSIZE& nTotal); diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 8c999aef1d34..072db744c01b 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1507,6 +1507,13 @@ public: SCCOL& rEndCol, SCROW& rEndRow, bool bIncludeOld, bool bOnlyDown ) const; + /** + * Return the extended area containing at least all contiguous cells + * having background color. + */ + SC_DLLPUBLIC void GetBackColorArea( SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow, + SCCOL& rEndCol, SCROW& rEndRow ) const; + /** * Returns true if there is a non-empty subrange in the range given as input. * In that case it also modifies rRange to largest subrange that does not diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 780d122ce47e..7604787a4f77 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -634,6 +634,9 @@ public: void GetDataArea( SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, SCROW& rEndRow, bool bIncludeOld, bool bOnlyDown ) const; + void GetBackColorArea( SCCOL& rStartCol, SCROW& rStartRow, + SCCOL& rEndCol, SCROW& rEndRow ) const; + bool GetDataAreaSubrange( ScRange& rRange ) const; bool ShrinkToUsedDataArea( bool& o_bShrunk, SCCOL& rStartCol, SCROW& rStartRow, diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 6bcfc230b25b..6ddae7a04057 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -1101,6 +1101,13 @@ void ScDocument::GetDataArea( SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow, maTabs[nTab]->GetDataArea( rStartCol, rStartRow, rEndCol, rEndRow, bIncludeOld, bOnlyDown ); } +void ScDocument::GetBackColorArea( SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow, + SCCOL& rEndCol, SCROW& rEndRow ) const +{ + if (ValidTab(nTab) && nTab < static_cast<SCTAB> (maTabs.size()) && maTabs[nTab]) + maTabs[nTab]->GetBackColorArea( rStartCol, rStartRow, rEndCol, rEndRow ); +} + bool ScDocument::GetDataAreaSubrange(ScRange& rRange) const { SCTAB nTab = rRange.aStart.Tab(); diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx index 9c6852990efe..3ec8dc5aeab7 100644 --- a/sc/source/core/data/table4.cxx +++ b/sc/source/core/data/table4.cxx @@ -23,6 +23,7 @@ #include <editeng/editeng.hxx> #include <editeng/eeitem.hxx> #include <editeng/escapementitem.hxx> +#include <editeng/brushitem.hxx> #include <svl/numformat.hxx> #include <svl/zforlist.hxx> #include <vcl/keycodes.hxx> @@ -1293,6 +1294,39 @@ void ScTable::FillSparkline(bool bVertical, SCCOLROW nFixed, } } +void ScTable::GetBackColorArea(SCCOL& rStartCol, SCROW& /*rStartRow*/, + SCCOL& rEndCol, SCROW& rEndRow ) const +{ + bool bExtend; + const SvxBrushItem* pDefBackground = &rDocument.GetPool()->GetDefaultItem(ATTR_BACKGROUND); + + rStartCol = std::min<SCCOL>(rStartCol, aCol.size() - 1); + rEndCol = std::min<SCCOL>(rEndCol, aCol.size() - 1); + + do + { + bExtend = false; + + if (rEndRow < rDocument.MaxRow()) + { + for (SCCOL nCol = rStartCol; nCol <= rEndCol; ++nCol) + { + const ScPatternAttr* pPattern = ColumnData(nCol).GetPattern(rEndRow + 1); + const SvxBrushItem* pBackground = &pPattern->GetItem(ATTR_BACKGROUND); + if (!pPattern->GetItem(ATTR_CONDITIONAL).GetCondFormatData().empty() || + pBackground != pDefBackground) + { + bExtend = true; + break; + } + } + + if (bExtend) + ++rEndRow; + } + } while (bExtend); +} + OUString ScTable::GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW nEndY ) { OUString aValue; diff --git a/sc/source/core/tool/dbdata.cxx b/sc/source/core/tool/dbdata.cxx index d6f2a91b2256..4b24110658c3 100644 --- a/sc/source/core/tool/dbdata.cxx +++ b/sc/source/core/tool/dbdata.cxx @@ -665,6 +665,23 @@ void ScDBData::ExtendDataArea(const ScDocument& rDoc) } } +void ScDBData::ExtendBackColorArea(const ScDocument& rDoc) +{ + // Extend the DB area to include data rows immediately below. + SCCOL nOldCol1 = nStartCol, nOldCol2 = nEndCol; + SCROW nOldEndRow = nEndRow; + rDoc.GetBackColorArea(nTable, nStartCol, nStartRow, nEndCol, nEndRow); + + if (nOldEndRow < rDoc.MaxRow() && nEndRow < nOldEndRow) + nEndRow = nOldEndRow; + + if (nStartCol != nOldCol1 || nEndCol != nOldCol2) + { + SAL_WARN_IF( !maTableColumnNames.empty(), "sc.core", "ScDBData::ExtendBackColorArea - invalidating column names/offsets"); + InvalidateTableColumnNames( true); + } +} + void ScDBData::StartTableColumnNamesListener() { if (mpContainer && bHasHeader) diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index 5ba1cb71dab6..c88472f3ede7 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -999,6 +999,7 @@ void ScGridWindow::LaunchAutoFilterMenu(SCCOL nCol, SCROW nRow) if (!pDBData) return; + pDBData->ExtendBackColorArea(rDoc); pData->mpData = pDBData; mpAutoFilterPopup->setExtendedData(std::move(pData)); diff --git a/sc/source/ui/view/tabvwshc.cxx b/sc/source/ui/view/tabvwshc.cxx index fcafe6755242..fdd35968487f 100644 --- a/sc/source/ui/view/tabvwshc.cxx +++ b/sc/source/ui/view/tabvwshc.cxx @@ -328,6 +328,7 @@ std::shared_ptr<SfxModelessDialogController> ScTabViewShell::CreateRefDialogCont ScDBData* pDBData = GetDBData(false, SC_DB_MAKE, ScGetDBSelection::RowDown); pDBData->ExtendDataArea(rDoc); + pDBData->ExtendBackColorArea(rDoc); pDBData->GetQueryParam( aQueryParam ); ScRange aArea;