summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorHenry Castro <hcastro@collabora.com>2023-11-06 07:18:48 -0400
committerTomaž Vajngerl <quikee@gmail.com>2023-11-07 11:23:34 +0100
commit768433f07873eb608837630f85e7e1b375239fca (patch)
treedcee9703e935784815f264890b15a79f8e130dc8 /sc
parentca5225ae4a53a8e99640cfa9440e112f3b39b11b (diff)
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 <hcastro@collabora.com> Change-Id: I341c602247e7f71e3c9665e1b594177d8f5553b5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158991 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/dbdata.hxx1
-rw-r--r--sc/inc/document.hxx7
-rw-r--r--sc/inc/table.hxx3
-rw-r--r--sc/source/core/data/document.cxx7
-rw-r--r--sc/source/core/data/table4.cxx34
-rw-r--r--sc/source/core/tool/dbdata.cxx17
-rw-r--r--sc/source/ui/view/gridwin.cxx1
-rw-r--r--sc/source/ui/view/tabvwshc.cxx1
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 9717c809aa31..8b91cbf49b0e 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1511,6 +1511,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 3367af129c19..4f7407809115 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -627,6 +627,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 4721bfeba70a..fceaec1bb386 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -1104,6 +1104,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 293bb20a4976..5a85a57703f8 100644
--- a/sc/source/core/tool/dbdata.cxx
+++ b/sc/source/core/tool/dbdata.cxx
@@ -670,6 +670,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 765d67ddda1f..93e9033d97d6 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -928,6 +928,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 cd1bcfc05def..35efe0f58744 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;