include/svx/strings.hrc | 1 sd/source/core/ThemeColorChanger.cxx | 96 ++++++++++++++++++++++++++--------- 2 files changed, 73 insertions(+), 24 deletions(-)
New commits: commit a29d4aba60f9e0e7e8d34f8973a351f75a114426 Author: Tomaž Vajngerl <[email protected]> AuthorDate: Tue Aug 15 17:38:03 2023 +0200 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Fri Aug 25 14:05:52 2023 +0200 sd: change text theme colors for graphic styles on theme change Change-Id: I6703c01999663c38d8e75654dcc308c49e014175 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155818 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/sd/source/core/ThemeColorChanger.cxx b/sd/source/core/ThemeColorChanger.cxx index 84a00527069c..01215f789fc2 100644 --- a/sd/source/core/ThemeColorChanger.cxx +++ b/sd/source/core/ThemeColorChanger.cxx @@ -80,6 +80,18 @@ bool changeStyle(sd::DrawDocShell* pDocShell, SdStyleSheet* pStyle, bChanged = true; } } + if (const SvxColorItem* pItem = aItemSet.GetItemIfSet(EE_CHAR_COLOR, false)) + { + model::ComplexColor const& rComplexColor = pItem->getComplexColor(); + if (rComplexColor.isValidThemeType()) + { + Color aNewColor = pColorSet->resolveColor(rComplexColor); + std::unique_ptr<SvxColorItem> pNewItem(pItem->Clone()); + pNewItem->setColor(aNewColor); + aItemSet.Put(*pNewItem); + bChanged = true; + } + } if (bChanged) { pDocShell->GetUndoManager()->AddUndoAction( commit 286bde4f083470490251c2f43ffb7ea9b236b4fd Author: Tomaž Vajngerl <[email protected]> AuthorDate: Tue Aug 15 17:25:15 2023 +0200 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Fri Aug 25 14:05:46 2023 +0200 sd: add undo/redo for line/fill styles theme change Change-Id: I780e261c013a44426ce1baa3b10ddcf497dd54c0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155817 Tested-by: Tomaž Vajngerl <[email protected]> Reviewed-by: Tomaž Vajngerl <[email protected]> diff --git a/include/svx/strings.hrc b/include/svx/strings.hrc index d0a7390045ae..f17b76c7a3ae 100644 --- a/include/svx/strings.hrc +++ b/include/svx/strings.hrc @@ -1135,6 +1135,7 @@ #define RID_SVXSTR_THEME_COLOR12 NC_("RID_SVXSTR_THEME_COLOR12", "Followed Hyperlink") #define RID_SVXSTR_THEME_EFFECT_LIGHTER NC_("RID_SVXSTR_THEME_EFFECT_LIGHTER", "$THEME_NAME, $PERCENTAGE% Lighter") #define RID_SVXSTR_THEME_EFFECT_DARKER NC_("RID_SVXSTR_THEME_EFFECT_DARKER", "$THEME_NAME, $PERCENTAGE% Darker") +#define RID_SVXSTR_UNDO_THEME_COLOR_CHANGE NC_("RID_SVXSTR_UNDO_THEME_COLOR_CHANGE", "Theme Color Change") #define RID_SVX_EXTRUSION_BAR NC_("RID_SVX_EXTRUSION_BAR", "Extrusion") #define RID_SVXSTR_UNDO_APPLY_EXTRUSION_ON_OFF NC_("RID_SVXSTR_UNDO_APPLY_EXTRUSION_ON_OFF", "Apply Extrusion On/Off") diff --git a/sd/source/core/ThemeColorChanger.cxx b/sd/source/core/ThemeColorChanger.cxx index d0a84c866495..84a00527069c 100644 --- a/sd/source/core/ThemeColorChanger.cxx +++ b/sd/source/core/ThemeColorChanger.cxx @@ -17,6 +17,13 @@ #include <svx/xlnclit.hxx> #include <svx/xflclit.hxx> #include <svx/xdef.hxx> +#include <svx/dialmgr.hxx> +#include <svx/strings.hrc> +#include <editeng/eeitem.hxx> + +#include <unchss.hxx> +#include <ViewShell.hxx> +#include <ViewShellBase.hxx> using namespace css; @@ -43,46 +50,73 @@ 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) +bool changeStyle(sd::DrawDocShell* pDocShell, SdStyleSheet* pStyle, + std::shared_ptr<model::ColorSet> const& pColorSet) { - SfxStyleSheetBasePool* pPool = pDocShell->GetStyleSheetPool(); + bool bChanged = false; - SdStyleSheet* pStyle = static_cast<SdStyleSheet*>(pPool->First(SfxStyleFamily::Para)); - while (pStyle) + auto aItemSet = pStyle->GetItemSet(); + if (const XFillColorItem* pItem = aItemSet.GetItemIfSet(XATTR_FILLCOLOR, false)) { - auto& rItemSet = pStyle->GetItemSet(); - if (const XFillColorItem* pItem = rItemSet.GetItemIfSet(XATTR_FILLCOLOR, false)) + model::ComplexColor const& rComplexColor = pItem->getComplexColor(); + if (rComplexColor.isValidThemeType()) { - 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); - } + Color aNewColor = pColorSet->resolveColor(rComplexColor); + std::unique_ptr<XFillColorItem> pNewItem(pItem->Clone()); + pNewItem->SetColorValue(aNewColor); + aItemSet.Put(*pNewItem); + bChanged = true; } - if (const XLineColorItem* pItem = rItemSet.GetItemIfSet(XATTR_LINECOLOR, false)) + } + if (const XLineColorItem* pItem = aItemSet.GetItemIfSet(XATTR_LINECOLOR, false)) + { + model::ComplexColor const& rComplexColor = pItem->getComplexColor(); + if (rComplexColor.isValidThemeType()) { - 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); - } + Color aNewColor = pColorSet->resolveColor(rComplexColor); + std::unique_ptr<XLineColorItem> pNewItem(pItem->Clone()); + pNewItem->SetColorValue(aNewColor); + aItemSet.Put(*pNewItem); + bChanged = true; } + } + if (bChanged) + { + pDocShell->GetUndoManager()->AddUndoAction( + std::make_unique<StyleSheetUndoAction>(pDocShell->GetDoc(), pStyle, &aItemSet)); + pStyle->GetItemSet().Put(aItemSet); + pStyle->Broadcast(SfxHint(SfxHintId::DataChanged)); + } + return bChanged; +} + +bool changeStyles(sd::DrawDocShell* pDocShell, std::shared_ptr<model::ColorSet> const& pColorSet) +{ + bool bChanged = false; + SfxStyleSheetBasePool* pPool = pDocShell->GetStyleSheetPool(); + + SdStyleSheet* pStyle = static_cast<SdStyleSheet*>(pPool->First(SfxStyleFamily::Para)); + while (pStyle) + { + bChanged = changeStyle(pDocShell, pStyle, pColorSet) || bChanged; pStyle = static_cast<SdStyleSheet*>(pPool->Next()); } - return true; + return bChanged; } } // end anonymous ns void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet) { + auto* pUndoManager = mpDocShell->GetUndoManager(); + + ViewShellId nViewShellId(-1); + if (sd::ViewShell* pViewShell = mpDocShell->GetViewShell()) + nViewShellId = pViewShell->GetViewShellBase().GetViewShellId(); + pUndoManager->EnterListAction(SvxResId(RID_SVXSTR_UNDO_THEME_COLOR_CHANGE), "", 0, + nViewShellId); + changeStyles(mpDocShell, pColorSet); SdrModel& rModel = mpMasterPage->getSdrModelFromSdrPage(); @@ -112,6 +146,8 @@ void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet) } changeTheTheme(mpMasterPage, pColorSet); + + pUndoManager->LeaveListAction(); } } // end sd namespace
