summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2023-08-12 04:03:57 +0900
committerTomaž Vajngerl <quikee@gmail.com>2023-08-23 23:16:38 +0200
commitad873064b0135e4e00389cd38c7de688286c1fa1 (patch)
treeb40a724847d284cca6332fa18dcbda84f3d7e2f4 /sd
parentbf15445b7102a4e2bea2f96891093bc4bf07c4c6 (diff)
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 <quikee@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sd')
-rw-r--r--sd/Library_sd.mk1
-rw-r--r--sd/inc/theme/ThemeColorChanger.hxx33
-rw-r--r--sd/qa/unit/ThemeTest.cxx10
-rw-r--r--sd/sdi/_drvwsh.sdi6
-rw-r--r--sd/source/core/ThemeColorChanger.cxx75
-rw-r--r--sd/source/ui/view/drviews2.cxx35
-rw-r--r--sd/uiconfig/sdraw/menubar/menubar.xml1
-rw-r--r--sd/uiconfig/simpress/menubar/menubar.xml1
8 files changed, 161 insertions, 1 deletions
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>