diff options
-rw-r--r-- | sc/inc/dbdata.hxx | 1 | ||||
-rw-r--r-- | sc/inc/document.hxx | 7 | ||||
-rw-r--r-- | sc/inc/table.hxx | 3 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 7 | ||||
-rw-r--r-- | sc/source/core/data/table4.cxx | 34 | ||||
-rw-r--r-- | sc/source/core/tool/dbdata.cxx | 17 | ||||
-rw-r--r-- | sc/source/ui/view/gridwin.cxx | 1 | ||||
-rw-r--r-- | sc/source/ui/view/tabvwshc.cxx | 1 |
8 files changed, 71 insertions, 0 deletions
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 1cff7a3ce4e4..11b65e9262c0 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1513,6 +1513,13 @@ public: 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 * have empty col/row inrange-segments in the beginning/end. diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 68b4c614c68b..8907bde5a150 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -641,6 +641,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 6225e92781b9..0b4ae5ca0da8 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -1081,6 +1081,13 @@ void ScDocument::GetDataArea( SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow, pTable->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 d8a4cf584132..62b9dbb9e006 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 7ae933b1cf65..6456ded939e9 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -1014,6 +1014,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 d253e8102396..be6fddc26740 100644 --- a/sc/source/ui/view/tabvwshc.cxx +++ b/sc/source/ui/view/tabvwshc.cxx @@ -336,6 +336,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; |