summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenry Castro <hcastro@collabora.com>2023-11-06 07:18:48 -0400
committerAron Budea <aron.budea@collabora.com>2023-12-09 21:18:57 +1030
commit4a3cb6b1c27173df5e8e4aac62d25079f7b59505 (patch)
tree0634fa3f5cda10e507a230b52ad9c5c071b09b7d
parent02bb1849ffa352cfafdf1e4a7d13ad7ca43205ca (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> (cherry picked from commit 768433f07873eb608837630f85e7e1b375239fca) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159238 Tested-by: Jenkins (cherry picked from commit 4abe6c83e76f825319e8b2a0c0b8b8e92177da65) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159249 (cherry picked from commit 64a4011951f54f8b86205798b968b20b532ea703)
-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 f12ba3fb976d..e03e41f6562a 100644
--- a/sc/inc/dbdata.hxx
+++ b/sc/inc/dbdata.hxx
@@ -213,6 +213,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 2050eac9595f..b8a0c3a2ed8f 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1456,6 +1456,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 4026a6b82d01..54792b66ea1c 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -598,6 +598,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 5fe2cfe08d0d..26b6db992a5f 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -1092,6 +1092,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 d2fdde2718b8..23c21aa577ed 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>
@@ -1208,6 +1209,39 @@ void ScTable::FillAuto( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
}
}
+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 = aCol[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 e441c7418796..29d96cd90692 100644
--- a/sc/source/core/tool/dbdata.cxx
+++ b/sc/source/core/tool/dbdata.cxx
@@ -666,6 +666,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 f41d7b580a01..93616da64389 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -901,6 +901,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 e43cb2ff31bc..e956f600356e 100644
--- a/sc/source/ui/view/tabvwshc.cxx
+++ b/sc/source/ui/view/tabvwshc.cxx
@@ -316,6 +316,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;