sd: change fill/line theme colors for graphic styles on theme change
Change-Id: Ieeb425519e805160bf6726a64086508290f9d521
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155684
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
diff --git a/sd/inc/theme/ThemeColorChanger.hxx b/sd/inc/theme/ThemeColorChanger.hxx
index 8c81794..72ae70a 100644
--- a/sd/inc/theme/ThemeColorChanger.hxx
+++ b/sd/inc/theme/ThemeColorChanger.hxx
@@ -13,6 +13,8 @@
#include <svx/theme/IThemeColorChanger.hxx>
#include <docmodel/theme/ColorSet.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdpage.hxx>
#include <drawdoc.hxx>
namespace sd
{
@@ -20,9 +22,10 @@ class SD_DLLPUBLIC ThemeColorChanger : public svx::IThemeColorChanger
{
private:
SdrPage* mpMasterPage;
sd::DrawDocShell* mpDocShell;
public:
ThemeColorChanger(SdrPage* pMasterPage);
ThemeColorChanger(SdrPage* pMasterPage, sd::DrawDocShell* pDocShell);
virtual ~ThemeColorChanger() override;
void apply(std::shared_ptr<model::ColorSet> const& pColorSet) override;
diff --git a/sd/qa/unit/ThemeTest.cxx b/sd/qa/unit/ThemeTest.cxx
index 65c261f..1b4f242 100644
--- a/sd/qa/unit/ThemeTest.cxx
+++ b/sd/qa/unit/ThemeTest.cxx
@@ -67,6 +67,10 @@ CPPUNIT_TEST_FIXTURE(ThemeTest, testThemeChange)
// Given a document, with a first slide and blue shape text from theme:
loadFromURL(u"theme.pptx");
SdXImpressDocument* pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pXImpressDocument);
auto* pDocShell = pXImpressDocument->GetDocShell();
uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
// The draw page also contains a group shape to make sure we don't crash on group shapes.
uno::Reference<drawing::XMasterPageTarget> xDrawPage(
@@ -131,7 +135,7 @@ CPPUNIT_TEST_FIXTURE(ThemeTest, testThemeChange)
auto* pMasterPage = GetSdrPageFromXDrawPage(xDrawPageMaster);
auto pTheme = pMasterPage->getSdrPageProperties().GetTheme();
sd::ThemeColorChanger aChanger(pMasterPage);
sd::ThemeColorChanger aChanger(pMasterPage, pDocShell);
aChanger.apply(pTheme->getColorSet());
// Then make sure the shape text color is now green:
diff --git a/sd/source/core/ThemeColorChanger.cxx b/sd/source/core/ThemeColorChanger.cxx
index 7ca2b64..d0a84c8 100644
--- a/sd/source/core/ThemeColorChanger.cxx
+++ b/sd/source/core/ThemeColorChanger.cxx
@@ -12,13 +12,19 @@
#include <svx/svdmodel.hxx>
#include <svx/svditer.hxx>
#include <docmodel/theme/Theme.hxx>
#include <DrawDocShell.hxx>
#include <stlsheet.hxx>
#include <svx/xlnclit.hxx>
#include <svx/xflclit.hxx>
#include <svx/xdef.hxx>
using namespace css;
namespace sd
{
ThemeColorChanger::ThemeColorChanger(SdrPage* pMasterPage)
ThemeColorChanger::ThemeColorChanger(SdrPage* pMasterPage, sd::DrawDocShell* pDocShell)
: mpMasterPage(pMasterPage)
, mpDocShell(pDocShell)
{
}
@@ -37,10 +43,48 @@ void changeTheTheme(SdrPage* pMasterPage, std::shared_ptr<model::ColorSet> const
pTheme->setColorSet(pColorSet);
}
bool changeStyles(sd::DrawDocShell* pDocShell, std::shared_ptr<model::ColorSet> const& pColorSet)
{
SfxStyleSheetBasePool* pPool = pDocShell->GetStyleSheetPool();
SdStyleSheet* pStyle = static_cast<SdStyleSheet*>(pPool->First(SfxStyleFamily::Para));
while (pStyle)
{
auto& rItemSet = pStyle->GetItemSet();
if (const XFillColorItem* pItem = rItemSet.GetItemIfSet(XATTR_FILLCOLOR, false))
{
model::ComplexColor const& rComplexColor = pItem->getComplexColor();
if (rComplexColor.isValidThemeType())
{
Color aNewColor = pColorSet->resolveColor(rComplexColor);
std::unique_ptr<XFillColorItem> pNewItem(pItem->Clone());
pNewItem->SetColorValue(aNewColor);
rItemSet.Put(*pNewItem);
}
}
if (const XLineColorItem* pItem = rItemSet.GetItemIfSet(XATTR_LINECOLOR, false))
{
model::ComplexColor const& rComplexColor = pItem->getComplexColor();
if (rComplexColor.isValidThemeType())
{
Color aNewColor = pColorSet->resolveColor(rComplexColor);
std::unique_ptr<XLineColorItem> pNewItem(pItem->Clone());
pNewItem->SetColorValue(aNewColor);
rItemSet.Put(*pNewItem);
}
}
pStyle = static_cast<SdStyleSheet*>(pPool->Next());
}
return true;
}
} // end anonymous ns
void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet)
{
changeStyles(mpDocShell, pColorSet);
SdrModel& rModel = mpMasterPage->getSdrModelFromSdrPage();
for (sal_uInt16 nPage = 0; nPage < rModel.GetPageCount(); ++nPage)
{
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index 8ad647c..51ebf5e 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -3582,7 +3582,8 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
SdrPage* pMasterPage = &GetActualPage()->TRG_GetMasterPage();
auto pTheme = pMasterPage->getSdrPageProperties().GetTheme();
auto pDialog = std::make_shared<svx::ThemeDialog>(GetFrameWeld(), pTheme.get());
weld::DialogController::runAsync(pDialog, [pDialog, pMasterPage](sal_uInt32 nResult)
auto* pDocShell = GetDocSh();
weld::DialogController::runAsync(pDialog, [pDialog, pMasterPage, pDocShell](sal_uInt32 nResult)
{
if (RET_OK != nResult)
return;
@@ -3590,7 +3591,7 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
auto pColorSet = pDialog->getCurrentColorSet();
if (pColorSet)
{
sd::ThemeColorChanger aChanger(pMasterPage);
sd::ThemeColorChanger aChanger(pMasterPage, pDocShell);
aChanger.apply(pColorSet);
if (comphelper::LibreOfficeKit::isActive())