include/svx/theme/ThemeColorChangerCommon.hxx | 12 ---- sc/qa/unit/ucalc_sparkline.cxx | 1 sc/source/ui/inc/ThemeColorChanger.hxx | 2 sc/source/ui/theme/ThemeColorChanger.cxx | 1 sd/Library_sd.mk | 1 sd/inc/theme/ThemeColorChanger.hxx | 33 +++++++++++ sd/qa/unit/ThemeTest.cxx | 10 +++ sd/sdi/_drvwsh.sdi | 6 +- sd/source/core/ThemeColorChanger.cxx | 75 ++++++++++++++++++++++++++ sd/source/ui/view/drviews2.cxx | 35 ++++++++++++ sd/uiconfig/sdraw/menubar/menubar.xml | 1 sd/uiconfig/simpress/menubar/menubar.xml | 1 svx/Library_svxcore.mk | 2 svx/source/svdraw/svdpage.cxx | 18 ------ svx/source/theme/ThemeColorChangerCommon.cxx | 39 +------------ sw/source/core/inc/ThemeColorChanger.hxx | 2 sw/source/core/model/ThemeColorChanger.cxx | 1 17 files changed, 170 insertions(+), 70 deletions(-)
New commits: commit ad873064b0135e4e00389cd38c7de688286c1fa1 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sat Aug 12 04:03:57 2023 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Wed Aug 23 23:16:38 2023 +0200 sd: add ThemeDialog to Impress/Draw, refactor ThemeColorChanger Add "Theme" menu action, which starts the common ThemeDialog. Add Impress/Draw specific ThemeColorChanger and remove the one in svx, so that only the interface and common function remain. Rename the svx ThemeColorChanger files to THemeColorChangerCommon. Change-Id: Ibf07a443cadf0452747ab6685f65df37b145c984 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155682 Tested-by: Tomaž Vajngerl <qui...@gmail.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/svx/theme/ThemeColorChanger.hxx b/include/svx/theme/ThemeColorChangerCommon.hxx similarity index 72% rename from include/svx/theme/ThemeColorChanger.hxx rename to include/svx/theme/ThemeColorChangerCommon.hxx index 8e942ea975ad..235648df2cab 100644 --- a/include/svx/theme/ThemeColorChanger.hxx +++ b/include/svx/theme/ThemeColorChangerCommon.hxx @@ -22,18 +22,6 @@ namespace theme SVXCORE_DLLPUBLIC void updateSdrObject(model::ColorSet const& rColorSet, SdrObject* pObject); } -class SVXCORE_DLLPUBLIC ThemeColorChanger : public IThemeColorChanger -{ -private: - SdrPage* mpPage; - -public: - ThemeColorChanger(SdrPage* pPage); - virtual ~ThemeColorChanger() override; - - void apply(std::shared_ptr<model::ColorSet> const& pColorSet) override; -}; - } // end svx namespace /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/unit/ucalc_sparkline.cxx b/sc/qa/unit/ucalc_sparkline.cxx index db74f67e3c89..951ae2c9047b 100644 --- a/sc/qa/unit/ucalc_sparkline.cxx +++ b/sc/qa/unit/ucalc_sparkline.cxx @@ -20,6 +20,7 @@ #include <SparklineAttributes.hxx> #include <ThemeColorChanger.hxx> #include <docmodel/theme/Theme.hxx> +#include <svx/svdpage.hxx> using namespace css; diff --git a/sc/source/ui/inc/ThemeColorChanger.hxx b/sc/source/ui/inc/ThemeColorChanger.hxx index f3f3b7379671..57ca91cdb83c 100644 --- a/sc/source/ui/inc/ThemeColorChanger.hxx +++ b/sc/source/ui/inc/ThemeColorChanger.hxx @@ -11,7 +11,7 @@ #pragma once #include <scdllapi.h> -#include <svx/theme/ThemeColorChanger.hxx> +#include <svx/theme/IThemeColorChanger.hxx> #include "docsh.hxx" namespace sc diff --git a/sc/source/ui/theme/ThemeColorChanger.cxx b/sc/source/ui/theme/ThemeColorChanger.cxx index 2c0933da5cd9..acef84f89fa0 100644 --- a/sc/source/ui/theme/ThemeColorChanger.cxx +++ b/sc/source/ui/theme/ThemeColorChanger.cxx @@ -19,6 +19,7 @@ #include <editeng/boxitem.hxx> #include <editeng/borderline.hxx> #include <svx/svditer.hxx> +#include <svx/theme/ThemeColorChangerCommon.hxx> #include <undodraw.hxx> #include <stlpool.hxx> diff --git a/sd/Library_sd.mk b/sd/Library_sd.mk index 926dd86ee755..62a1579dc6aa 100644 --- a/sd/Library_sd.mk +++ b/sd/Library_sd.mk @@ -155,6 +155,7 @@ $(eval $(call gb_Library_add_exception_objects,sd,\ sd/source/core/EffectMigration \ sd/source/core/PageListWatcher \ sd/source/core/TransitionPreset \ + sd/source/core/ThemeColorChanger \ sd/source/core/anminfo \ sd/source/core/annotations/Annotation \ sd/source/core/annotations/AnnotationEnumeration \ diff --git a/sd/inc/theme/ThemeColorChanger.hxx b/sd/inc/theme/ThemeColorChanger.hxx new file mode 100644 index 000000000000..8c8179460dd8 --- /dev/null +++ b/sd/inc/theme/ThemeColorChanger.hxx @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include <sddllapi.h> +#include <svx/theme/IThemeColorChanger.hxx> +#include <docmodel/theme/ColorSet.hxx> +#include <svx/svdpage.hxx> + +namespace sd +{ +class SD_DLLPUBLIC ThemeColorChanger : public svx::IThemeColorChanger +{ +private: + SdrPage* mpMasterPage; + +public: + ThemeColorChanger(SdrPage* pMasterPage); + virtual ~ThemeColorChanger() override; + + void apply(std::shared_ptr<model::ColorSet> const& pColorSet) override; +}; + +} // end sd namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/qa/unit/ThemeTest.cxx b/sd/qa/unit/ThemeTest.cxx index 98ffd6c1bbab..65c261f23700 100644 --- a/sd/qa/unit/ThemeTest.cxx +++ b/sd/qa/unit/ThemeTest.cxx @@ -16,6 +16,7 @@ #include <com/sun/star/drawing/XMasterPageTarget.hpp> #include <com/sun/star/text/XTextRange.hpp> #include <docmodel/uno/UnoComplexColor.hxx> +#include <docmodel/theme/Theme.hxx> #include <svx/unoapi.hxx> @@ -23,6 +24,7 @@ #include <unomodel.hxx> #include <sdpage.hxx> #include <ViewShell.hxx> +#include <theme/ThemeColorChanger.hxx> using namespace css; @@ -124,6 +126,14 @@ CPPUNIT_TEST_FIXTURE(ThemeTest, testThemeChange) uno::Reference<beans::XPropertySet> xMasterPage(xDrawPage->getMasterPage(), uno::UNO_QUERY); xMasterPage->setPropertyValue("Theme", aTheme); + css::uno::Reference<css::drawing::XDrawPage> xDrawPageMaster(xMasterPage, uno::UNO_QUERY); + CPPUNIT_ASSERT(xDrawPageMaster.is()); + auto* pMasterPage = GetSdrPageFromXDrawPage(xDrawPageMaster); + auto pTheme = pMasterPage->getSdrPageProperties().GetTheme(); + + sd::ThemeColorChanger aChanger(pMasterPage); + aChanger.apply(pTheme->getColorSet()); + // Then make sure the shape text color is now green: CPPUNIT_ASSERT_EQUAL(Color(0x90c226), GetShapeTextColor(xShape)); // Green, lighter: diff --git a/sd/sdi/_drvwsh.sdi b/sd/sdi/_drvwsh.sdi index 7d501ba20bdc..55ed82d07dbe 100644 --- a/sd/sdi/_drvwsh.sdi +++ b/sd/sdi/_drvwsh.sdi @@ -2947,5 +2947,9 @@ interface DrawView ExecMethod = FuTemporary; StateMethod = GetAttrState; ] - + SID_THEME_DIALOG + [ + ExecMethod = FuTemporary; + StateMethod = GetAttrState; + ] } diff --git a/sd/source/core/ThemeColorChanger.cxx b/sd/source/core/ThemeColorChanger.cxx new file mode 100644 index 000000000000..7ca2b6478232 --- /dev/null +++ b/sd/source/core/ThemeColorChanger.cxx @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <theme/ThemeColorChanger.hxx> +#include <svx/theme/ThemeColorChangerCommon.hxx> +#include <svx/svdmodel.hxx> +#include <svx/svditer.hxx> +#include <docmodel/theme/Theme.hxx> + +using namespace css; + +namespace sd +{ +ThemeColorChanger::ThemeColorChanger(SdrPage* pMasterPage) + : mpMasterPage(pMasterPage) +{ +} + +ThemeColorChanger::~ThemeColorChanger() = default; + +namespace +{ +void changeTheTheme(SdrPage* pMasterPage, std::shared_ptr<model::ColorSet> const& pColorSet) +{ + auto pTheme = pMasterPage->getSdrPageProperties().GetTheme(); + if (!pTheme) + { + pTheme = std::make_shared<model::Theme>("Office"); + pMasterPage->getSdrPageProperties().SetTheme(pTheme); + } + pTheme->setColorSet(pColorSet); +} + +} // end anonymous ns + +void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet) +{ + SdrModel& rModel = mpMasterPage->getSdrModelFromSdrPage(); + for (sal_uInt16 nPage = 0; nPage < rModel.GetPageCount(); ++nPage) + { + SdrPage* pCurrentPage = rModel.GetPage(nPage); + if (!pCurrentPage->TRG_HasMasterPage() + || &pCurrentPage->TRG_GetMasterPage() != mpMasterPage) + continue; + + for (size_t nObject = 0; nObject < pCurrentPage->GetObjCount(); ++nObject) + { + SdrObject* pObject = pCurrentPage->GetObj(nObject); + svx::theme::updateSdrObject(*pColorSet, pObject); + + // update child objects + SdrObjList* pList = pObject->GetSubList(); + if (pList) + { + SdrObjListIter aIter(pList, SdrIterMode::DeepWithGroups); + while (aIter.IsMore()) + { + svx::theme::updateSdrObject(*pColorSet, aIter.Next()); + } + } + } + } + + changeTheTheme(mpMasterPage, pColorSet); +} + +} // end sd namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx index 8aac86b3b426..8ad647cc8048 100644 --- a/sd/source/ui/view/drviews2.cxx +++ b/sd/source/ui/view/drviews2.cxx @@ -186,6 +186,12 @@ #include <controller/SlsPageSelector.hxx> #include <tools/GraphicSizeCheck.hxx> +#include <theme/ThemeColorChanger.hxx> +#include <svx/dialog/ThemeDialog.hxx> +#include <svx/theme/ThemeColorPaletteManager.hxx> +#include <sfx2/lokhelper.hxx> +#include <LibreOfficeKit/LibreOfficeKitEnums.h> + #include <ViewShellBase.hxx> #include <memory> @@ -3571,6 +3577,35 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq) } break; + case SID_THEME_DIALOG: + { + 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) + { + if (RET_OK != nResult) + return; + + auto pColorSet = pDialog->getCurrentColorSet(); + if (pColorSet) + { + sd::ThemeColorChanger aChanger(pMasterPage); + aChanger.apply(pColorSet); + + if (comphelper::LibreOfficeKit::isActive()) + { + svx::ThemeColorPaletteManager aManager(pColorSet); + SfxLokHelper::notifyAllViews(LOK_CALLBACK_COLOR_PALETTES, aManager.generateJSON()); + } + } + }); + + Cancel(); + rReq.Ignore(); + } + break; + case SID_ADDITIONS_DIALOG: { OUString sAdditionsTag = ""; diff --git a/sd/uiconfig/sdraw/menubar/menubar.xml b/sd/uiconfig/sdraw/menubar/menubar.xml index 4c97ad97e240..824c3fd15124 100644 --- a/sd/uiconfig/sdraw/menubar/menubar.xml +++ b/sd/uiconfig/sdraw/menubar/menubar.xml @@ -362,6 +362,7 @@ <menu:menuitem menu:id=".uno:FontDialog"/> <menu:menuitem menu:id=".uno:ParagraphDialog"/> <menu:menuitem menu:id=".uno:OutlineBullet"/> + <menu:menuitem menu:id=".uno:ThemeDialog"/> <menu:menuseparator/> <menu:menuitem menu:id=".uno:ModifyLayer"/> <menu:menu menu:id=".uno:TableMenu"> diff --git a/sd/uiconfig/simpress/menubar/menubar.xml b/sd/uiconfig/simpress/menubar/menubar.xml index 78489c56383e..319e47214415 100644 --- a/sd/uiconfig/simpress/menubar/menubar.xml +++ b/sd/uiconfig/simpress/menubar/menubar.xml @@ -394,6 +394,7 @@ <menu:menuitem menu:id=".uno:FontDialog"/> <menu:menuitem menu:id=".uno:ParagraphDialog"/> <menu:menuitem menu:id=".uno:OutlineBullet"/> + <menu:menuitem menu:id=".uno:ThemeDialog"/> <menu:menuseparator/> <menu:menu menu:id=".uno:TableMenu"> <menu:menupopup> diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk index bdff68a6a4b1..6e7466541427 100644 --- a/svx/Library_svxcore.mk +++ b/svx/Library_svxcore.mk @@ -424,7 +424,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\ svx/source/table/tablerows \ svx/source/table/tableundo \ svx/source/table/viewcontactoftableobj \ - svx/source/theme/ThemeColorChanger \ + svx/source/theme/ThemeColorChangerCommon \ svx/source/theme/ThemeColorPaletteManager \ svx/source/tbxctrls/extrusioncontrols \ svx/source/tbxctrls/fontworkgallery \ diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx index a0adb39cb5cd..3d380292ce04 100644 --- a/svx/source/svdraw/svdpage.cxx +++ b/svx/source/svdraw/svdpage.cxx @@ -45,7 +45,6 @@ #include <svx/svdundo.hxx> #include <svx/xfillit0.hxx> #include <svx/fmdpage.hxx> -#include <svx/theme/ThemeColorChanger.hxx> #include <svx/ColorSets.hxx> #include <sdr/contact/viewcontactofsdrpage.hxx> @@ -1278,23 +1277,6 @@ void SdrPageProperties::SetTheme(std::shared_ptr<model::Theme> const& pTheme) return; mpTheme = pTheme; - - if (mpTheme && mpTheme->getColorSet() && mpSdrPage->IsMasterPage()) - { - SdrModel& rModel = mpSdrPage->getSdrModelFromSdrPage(); - sal_uInt16 nPageCount = rModel.GetPageCount(); - for (sal_uInt16 nPage = 0; nPage < nPageCount; ++nPage) - { - SdrPage* pPage = rModel.GetPage(nPage); - if (!pPage->TRG_HasMasterPage() || &pPage->TRG_GetMasterPage() != mpSdrPage) - { - continue; - } - - svx::ThemeColorChanger aChanger(pPage); - aChanger.apply(mpTheme->getColorSet()); - } - } } std::shared_ptr<model::Theme> const& SdrPageProperties::GetTheme() const diff --git a/svx/source/theme/ThemeColorChanger.cxx b/svx/source/theme/ThemeColorChangerCommon.cxx similarity index 83% rename from svx/source/theme/ThemeColorChanger.cxx rename to svx/source/theme/ThemeColorChangerCommon.cxx index 7e7ba984729d..db78e1c343b1 100644 --- a/svx/source/theme/ThemeColorChanger.cxx +++ b/svx/source/theme/ThemeColorChangerCommon.cxx @@ -7,11 +7,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <svx/theme/ThemeColorChanger.hxx> +#include <svx/theme/ThemeColorChangerCommon.hxx> #include <sal/config.h> -#include <svx/svdpage.hxx> -#include <svx/svditer.hxx> #include <editeng/unoprnms.hxx> #include <docmodel/uno/UnoComplexColor.hxx> #include <docmodel/theme/ColorSet.hxx> @@ -24,9 +22,7 @@ using namespace css; -namespace svx -{ -namespace theme +namespace svx::theme { namespace { @@ -126,35 +122,6 @@ void updateSdrObject(model::ColorSet const& rColorSet, SdrObject* pObject) updateLineColorSet(rColorSet, xShapeProps); } -} // end theme - -ThemeColorChanger::ThemeColorChanger(SdrPage* pPage) - : mpPage(pPage) -{ -} - -ThemeColorChanger::~ThemeColorChanger() = default; - -void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet) -{ - for (size_t nObject = 0; nObject < mpPage->GetObjCount(); ++nObject) - { - SdrObject* pObject = mpPage->GetObj(nObject); - theme::updateSdrObject(*pColorSet, pObject); - - // update child objects - SdrObjList* pList = pObject->GetSubList(); - if (pList) - { - SdrObjListIter aIter(pList, SdrIterMode::DeepWithGroups); - while (aIter.IsMore()) - { - theme::updateSdrObject(*pColorSet, aIter.Next()); - } - } - } -} - -} // end svx namespace +} // end svx::theme namespace /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/inc/ThemeColorChanger.hxx b/sw/source/core/inc/ThemeColorChanger.hxx index 6c3e9f3cc7f7..6eeb3a25f612 100644 --- a/sw/source/core/inc/ThemeColorChanger.hxx +++ b/sw/source/core/inc/ThemeColorChanger.hxx @@ -12,7 +12,7 @@ #include <swdllapi.h> #include <docsh.hxx> #include <docmodel/theme/ColorSet.hxx> -#include <svx/theme/ThemeColorChanger.hxx> +#include <svx/theme/IThemeColorChanger.hxx> namespace sw { diff --git a/sw/source/core/model/ThemeColorChanger.cxx b/sw/source/core/model/ThemeColorChanger.cxx index 14da568e2369..ea66cc4f2f54 100644 --- a/sw/source/core/model/ThemeColorChanger.cxx +++ b/sw/source/core/model/ThemeColorChanger.cxx @@ -30,6 +30,7 @@ #include <sal/config.h> #include <svx/svdpage.hxx> #include <svx/svditer.hxx> +#include <svx/theme/ThemeColorChangerCommon.hxx> #include <docmodel/uno/UnoComplexColor.hxx> #include <docmodel/theme/Theme.hxx> #include <editeng/unoprnms.hxx>