sc/qa/unit/ucalc_condformat.cxx | 54 ++++++++++++++++++++++++++++++++++++++ sc/source/ui/docshell/docfunc.cxx | 2 - 2 files changed, 55 insertions(+), 1 deletion(-)
New commits: commit 77720a8f4338f2b6e393387e6fb683339618e826 Author: Tibor Nagy <nagy.tib...@nisz.hu> AuthorDate: Thu Jul 13 14:54:55 2023 +0200 Commit: László Németh <nem...@numbertext.org> CommitDate: Wed Jul 26 11:04:42 2023 +0200 tdf#99808 sc: fix background of conditional formatting in merged cell The background color of conditional formatting is applied only to the first cell in the merged block, at least under Windows. Note: Undo/Redo is still not perfect, at least under Linux. Change-Id: Ic87983fa6e3279a64841babc565fbe97710ff730 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154390 Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> (cherry picked from commit e384be0f6ea6453e57cd4a7c4402d26b49debc41) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154867 Tested-by: Jenkins diff --git a/sc/qa/unit/ucalc_condformat.cxx b/sc/qa/unit/ucalc_condformat.cxx index 634373b58ccc..6b79a4318501 100644 --- a/sc/qa/unit/ucalc_condformat.cxx +++ b/sc/qa/unit/ucalc_condformat.cxx @@ -12,6 +12,7 @@ #include <conditio.hxx> #include <colorscale.hxx> +#include <hints.hxx> #include <globstr.hrc> #include <scresid.hxx> #include <docfunc.hxx> @@ -25,6 +26,23 @@ namespace { +struct PaintListener : public SfxListener +{ + bool mbPaintAllMergedCell = false; + virtual void Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint) override + { + const ScPaintHint* pPaintHint = dynamic_cast<const ScPaintHint*>(&rHint); + if (pPaintHint) + { + if (pPaintHint->GetStartCol() == 0 && pPaintHint->GetEndCol() == 0 + && pPaintHint->GetStartRow() == 0 && pPaintHint->GetEndRow() == 1) + { + mbPaintAllMergedCell = true; + } + } + } +}; + struct ScDataBarLengthData { double nVal; @@ -1361,6 +1379,42 @@ CPPUNIT_TEST_FIXTURE(TestCondformat, testCondFormatVolatileFunctionRecalc) m_pDoc->DeleteTab(0); } +CPPUNIT_TEST_FIXTURE(TestCondformat, testConditionStyleInMergedCell) +{ + m_pDoc->InsertTab(0, "Test"); + + PaintListener aListener; + aListener.StartListening(*m_xDocShell); + + m_pDoc->DoMerge(0, 0, 0, 1, 0); // A1:A2 + CPPUNIT_ASSERT(m_pDoc->IsMerged(ScAddress(0, 0, 0))); + + m_pDoc->SetValue(ScAddress(0, 0, 0), 1.0); + + // Add a conditional format. + auto pFormat = std::make_unique<ScConditionalFormat>(1, m_pDoc); + pFormat->SetRange(ScRange(0, 0, 0, 0, 0, 0)); + auto pFormatTmp = pFormat.get(); + sal_uLong nKey = m_pDoc->AddCondFormat(std::move(pFormat), 0); + + // Add condition in which if the value equals 1, set the "Good" style. + ScCondFormatEntry* pEntry = new ScCondFormatEntry( + ScConditionMode::Equal, "=1", "", *m_pDoc, ScAddress(0, 0, 0), ScResId(STR_STYLENAME_GOOD)); + pFormatTmp->AddEntry(pEntry); + + // Apply the format to the range. + m_pDoc->AddCondFormatData(pFormatTmp->GetRange(), 0, nKey); + + ScDocFunc& rFunc = m_xDocShell->GetDocFunc(); + sal_uInt32 nOldFormat = pFormatTmp->GetKey(); + const ScRangeList& rRangeList = pFormatTmp->GetRange(); + rFunc.ReplaceConditionalFormat(nOldFormat, pFormatTmp->Clone(), 0, rRangeList); + + CPPUNIT_ASSERT_EQUAL(true, aListener.mbPaintAllMergedCell); + + m_pDoc->DeleteTab(0); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 4d99824fe0a0..4d3288558c40 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -5670,7 +5670,7 @@ void ScDocFunc::ReplaceConditionalFormat( sal_uLong nOldFormat, std::unique_ptr< } if(pRepaintRange) - rDocShell.PostPaint(*pRepaintRange, PaintPartFlags::Grid); + rDocShell.PostPaint(*pRepaintRange, PaintPartFlags::Grid, SC_PF_TESTMERGE); aModificator.SetDocumentModified(); SfxGetpApp()->Broadcast(SfxHint(SfxHintId::ScAreasChanged));