docmodel/Library_docmodel.mk | 5 docmodel/source/theme/ColorSet.cxx | 74 ++++++++++ include/docmodel/theme/ColorSet.hxx | 45 ++++++ include/oox/drawingml/clrscheme.hxx | 4 include/svx/ColorSets.hxx | 43 +----- include/svx/dialog/ThemeColorValueSet.hxx | 6 include/svx/theme/IThemeColorChanger.hxx | 6 include/svx/theme/ThemeColorChanger.hxx | 39 +++++ oox/source/drawingml/clrscheme.cxx | 2 oox/source/drawingml/theme.cxx | 3 oox/source/export/ThemeExport.cxx | 4 sd/source/filter/eppt/pptx-epptooxml.cxx | 4 svx/Library_svx.mk | 1 svx/Library_svxcore.mk | 1 svx/source/dialog/ThemeColorValueSet.cxx | 4 svx/source/dialog/ThemeDialog.cxx | 3 svx/source/styles/ColorSets.cxx | 188 ++------------------------- svx/source/svdraw/svdpage.cxx | 6 svx/source/theme/ThemeColorChanger.cxx | 162 +++++++++++++++++++++++ sw/qa/core/theme/ThemeTest.cxx | 2 sw/source/core/inc/ThemeColorChanger.hxx | 12 - sw/source/core/model/ThemeColorChanger.cxx | 118 ++-------------- sw/source/uibase/sidebar/ThemePanel.cxx | 6 writerfilter/source/dmapper/ThemeHandler.cxx | 1 24 files changed, 401 insertions(+), 338 deletions(-)
New commits: commit a745ca096e100a4d2cbff3665112f7cba7291876 Author: Tomaž Vajngerl <[email protected]> AuthorDate: Thu Jan 26 23:43:00 2023 +0900 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Mon Jan 30 05:54:41 2023 +0000 move ColorSet class to own file inside docmodel Also move ColorSet from svx to model namespace so it is consistent with other classes in docmodel. Change-Id: Iacbdbdf5ece4015c628a0e45adf6a732b2d27777 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146220 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> (cherry picked from commit 69c6f7bccec838b7288a25a29a83b7f782ba7586) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146229 Tested-by: Tomaž Vajngerl <[email protected]> diff --git a/docmodel/Library_docmodel.mk b/docmodel/Library_docmodel.mk index 3e0d28dfda28..22ecdfa59ac4 100644 --- a/docmodel/Library_docmodel.mk +++ b/docmodel/Library_docmodel.mk @@ -11,6 +11,7 @@ $(eval $(call gb_Library_Library,docmodel)) $(eval $(call gb_Library_add_exception_objects,docmodel,\ docmodel/source/uno/UnoThemeColor \ + docmodel/source/theme/ColorSet \ )) $(eval $(call gb_Library_set_include,docmodel,\ @@ -18,6 +19,10 @@ $(eval $(call gb_Library_set_include,docmodel,\ -I$(SRCDIR)/docmodel/inc \ )) +$(eval $(call gb_Library_use_externals,docmodel,\ + libxml2 \ +)) + $(eval $(call gb_Library_add_defs,docmodel,\ -DDOCMODEL_DLLIMPLEMENTATION \ )) diff --git a/docmodel/source/theme/ColorSet.cxx b/docmodel/source/theme/ColorSet.cxx new file mode 100644 index 000000000000..55c03dadba8c --- /dev/null +++ b/docmodel/source/theme/ColorSet.cxx @@ -0,0 +1,74 @@ +/* -*- 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 <docmodel/theme/ColorSet.hxx> +#include <sstream> +#include <utility> +#include <libxml/xmlwriter.h> +#include <sal/log.hxx> + +namespace model +{ +ColorSet::ColorSet(OUString const& rName) + : maName(rName) +{ +} + +void ColorSet::add(model::ThemeColorType eType, Color aColorData) +{ + if (eType == model::ThemeColorType::Unknown) + return; + maColors[sal_Int16(eType)] = aColorData; +} + +Color ColorSet::getColor(model::ThemeColorType eType) const +{ + if (eType == model::ThemeColorType::Unknown) + { + SAL_WARN("svx", "ColorSet::getColor with ThemeColorType::Unknown"); + return COL_AUTO; + } + return maColors[size_t(eType)]; +} + +Color ColorSet::resolveColor(model::ThemeColor const& rThemeColor) const +{ + auto eType = rThemeColor.getType(); + if (eType == model::ThemeColorType::Unknown) + { + SAL_WARN("svx", "ColorSet::resolveColor with ThemeColorType::Unknown"); + return COL_AUTO; + } + Color aColor = getColor(eType); + return rThemeColor.applyTransformations(aColor); +} + +void ColorSet::dumpAsXml(xmlTextWriterPtr pWriter) const +{ + (void)xmlTextWriterStartElement(pWriter, BAD_CAST("ColorSet")); + (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this); + (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("maName"), + BAD_CAST(maName.toUtf8().getStr())); + + for (const auto& rColor : maColors) + { + (void)xmlTextWriterStartElement(pWriter, BAD_CAST("Color")); + std::stringstream ss; + ss << rColor; + (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(ss.str().c_str())); + (void)xmlTextWriterEndElement(pWriter); + } + + (void)xmlTextWriterEndElement(pWriter); +} + +} // end of namespace svx + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/docmodel/theme/ColorSet.hxx b/include/docmodel/theme/ColorSet.hxx new file mode 100644 index 000000000000..6e7fa94eafee --- /dev/null +++ b/include/docmodel/theme/ColorSet.hxx @@ -0,0 +1,45 @@ +/* -*- 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 <array> +#include <docmodel/dllapi.h> +#include <rtl/ustring.hxx> +#include <docmodel/theme/ThemeColorType.hxx> +#include <docmodel/theme/ThemeColor.hxx> +#include <tools/color.hxx> + +typedef struct _xmlTextWriter* xmlTextWriterPtr; + +namespace model +{ +class DOCMODEL_DLLPUBLIC ColorSet +{ + OUString maName; + std::array<Color, 12> maColors; + +public: + ColorSet(OUString const& rName); + + void add(model::ThemeColorType Type, Color aColorData); + + const OUString& getName() const { return maName; } + + Color resolveColor(model::ThemeColor const& rThemeColor) const; + + Color getColor(model::ThemeColorType eType) const; + + void dumpAsXml(xmlTextWriterPtr pWriter) const; +}; + +} // end of namespace model + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/oox/drawingml/clrscheme.hxx b/include/oox/drawingml/clrscheme.hxx index fd7662511a88..33ff971c7d81 100644 --- a/include/oox/drawingml/clrscheme.hxx +++ b/include/oox/drawingml/clrscheme.hxx @@ -30,7 +30,7 @@ #include <sal/types.h> #include <rtl/ustring.hxx> #include <tools/color.hxx> -#include <svx/ColorSets.hxx> +#include <docmodel/theme/ColorSet.hxx> namespace oox::drawingml { @@ -95,7 +95,7 @@ public: const OUString& GetName() const { return maName; } void ToAny(css::uno::Any& rVal) const; - void fill(svx::ColorSet& rColorSet) const; + void fill(model::ColorSet& rColorSet) const; }; diff --git a/include/svx/ColorSets.hxx b/include/svx/ColorSets.hxx index d4188c0ba2d8..839da43f4ba4 100644 --- a/include/svx/ColorSets.hxx +++ b/include/svx/ColorSets.hxx @@ -18,6 +18,7 @@ #include <sal/types.h> #include <svx/svxdllapi.h> #include <docmodel/theme/ThemeColor.hxx> +#include <docmodel/theme/ColorSet.hxx> #include <tools/color.hxx> typedef struct _xmlTextWriter* xmlTextWriterPtr; @@ -26,49 +27,27 @@ class SdrPage; namespace svx { - -class SVXCORE_DLLPUBLIC ColorSet -{ - OUString maName; - std::array<Color, 12> maColors; - -public: - ColorSet(OUString const& rName); - - void add(model::ThemeColorType Type, Color aColorData); - - const OUString& getName() const - { - return maName; - } - - Color resolveColor(model::ThemeColor const& rThemeColor) const; - Color getColor(model::ThemeColorType eType) const; - - void dumpAsXml(xmlTextWriterPtr pWriter) const; -}; - class SVXCORE_DLLPUBLIC ColorSets { - std::vector<ColorSet> maColorSets; + std::vector<model::ColorSet> maColorSets; public: ColorSets(); ~ColorSets(); void init(); - const std::vector<ColorSet>& getColorSets() const + const std::vector<model::ColorSet>& getColorSets() const { return maColorSets; } - const ColorSet& getColorSet(sal_uInt32 nIndex) const + const model::ColorSet& getColorSet(sal_uInt32 nIndex) const { return maColorSets[nIndex]; } - const ColorSet& getColorSet(std::u16string_view rName); + const model::ColorSet& getColorSet(std::u16string_view rName); - void insert(ColorSet const& rColorSet); + void insert(model::ColorSet const& rColorSet); }; struct SVXCORE_DLLPUBLIC ThemeSupplementalFont @@ -216,7 +195,7 @@ class SVXCORE_DLLPUBLIC Theme { private: OUString maName; - std::unique_ptr<ColorSet> mpColorSet; + std::unique_ptr<model::ColorSet> mpColorSet; FontScheme maFontScheme; @@ -230,9 +209,9 @@ public: FontScheme const& getFontScheme() const { return maFontScheme; } - void SetColorSet(std::unique_ptr<ColorSet> pColorSet); - const ColorSet* GetColorSet() const; - ColorSet* GetColorSet(); + void SetColorSet(std::unique_ptr<model::ColorSet> pColorSet); + const model::ColorSet* GetColorSet() const; + model::ColorSet* GetColorSet(); void SetName(const OUString& rName); const OUString& GetName() const; diff --git a/include/svx/dialog/ThemeColorValueSet.hxx b/include/svx/dialog/ThemeColorValueSet.hxx index 4b70ed0f56db..ee73275c4d41 100644 --- a/include/svx/dialog/ThemeColorValueSet.hxx +++ b/include/svx/dialog/ThemeColorValueSet.hxx @@ -12,13 +12,13 @@ #include <svx/svxdllapi.h> #include <sal/config.h> #include <svtools/valueset.hxx> -#include <svx/ColorSets.hxx> +#include <docmodel/theme/ColorSet.hxx> namespace svx { class SVX_DLLPUBLIC ThemeColorValueSet final : public ValueSet { - std::vector<std::reference_wrapper<const svx::ColorSet>> maColorSets; + std::vector<std::reference_wrapper<const model::ColorSet>> maColorSets; public: ThemeColorValueSet() @@ -30,7 +30,7 @@ public: void UserDraw(const UserDrawEvent& rUserDrawEvent) override; void StyleUpdated() override; - void insert(svx::ColorSet const& rColorSet); + void insert(model::ColorSet const& rColorSet); }; } // end svx namespace diff --git a/include/svx/theme/IThemeColorChanger.hxx b/include/svx/theme/IThemeColorChanger.hxx index 93cba5870b96..4f10ad15120f 100644 --- a/include/svx/theme/IThemeColorChanger.hxx +++ b/include/svx/theme/IThemeColorChanger.hxx @@ -10,7 +10,7 @@ #pragma once #include <svx/svxdllapi.h> -#include <svx/ColorSets.hxx> +#include <docmodel/theme/ColorSet.hxx> namespace svx { @@ -18,7 +18,7 @@ class SVXCORE_DLLPUBLIC IThemeColorChanger { public: virtual ~IThemeColorChanger() = default; - virtual void apply(svx::ColorSet const& rColorSet) = 0; + virtual void apply(model::ColorSet const& rColorSet) = 0; }; } // end svx namespace diff --git a/include/svx/theme/ThemeColorChanger.hxx b/include/svx/theme/ThemeColorChanger.hxx index cf4071824d9c..708344fef2b3 100644 --- a/include/svx/theme/ThemeColorChanger.hxx +++ b/include/svx/theme/ThemeColorChanger.hxx @@ -11,7 +11,7 @@ #include <svx/svxdllapi.h> #include <svx/theme/IThemeColorChanger.hxx> -#include <svx/ColorSets.hxx> +#include <docmodel/theme/ColorSet.hxx> #include <svx/svdpage.hxx> #include <svx/svdobj.hxx> @@ -19,7 +19,7 @@ namespace svx { namespace theme { -SVXCORE_DLLPUBLIC void updateSdrObject(svx::ColorSet const& rColorSet, SdrObject* pObject); +SVXCORE_DLLPUBLIC void updateSdrObject(model::ColorSet const& rColorSet, SdrObject* pObject); } class SVXCORE_DLLPUBLIC ThemeColorChanger : public IThemeColorChanger @@ -31,7 +31,7 @@ public: ThemeColorChanger(SdrPage* pPage); virtual ~ThemeColorChanger() override; - void apply(svx::ColorSet const& rColorSet) override; + void apply(model::ColorSet const& rColorSet) override; }; } // end svx namespace diff --git a/oox/source/drawingml/clrscheme.cxx b/oox/source/drawingml/clrscheme.cxx index b335c7655efc..2d66cf6fc4b9 100644 --- a/oox/source/drawingml/clrscheme.cxx +++ b/oox/source/drawingml/clrscheme.cxx @@ -120,7 +120,7 @@ void ClrScheme::ToAny(css::uno::Any& rVal) const rVal <<= comphelper::containerToSequence(aRet); } -void ClrScheme::fill(svx::ColorSet& rColorSet) const +void ClrScheme::fill(model::ColorSet& rColorSet) const { for (const auto& [nToken, rColor] : maClrScheme) { diff --git a/oox/source/drawingml/theme.cxx b/oox/source/drawingml/theme.cxx index dfa81feaff0d..78471490f35a 100644 --- a/oox/source/drawingml/theme.cxx +++ b/oox/source/drawingml/theme.cxx @@ -28,6 +28,7 @@ #include <svx/unopage.hxx> #include <svx/svdpage.hxx> #include <svx/ColorSets.hxx> +#include <docmodel/theme/ColorSet.hxx> #include <svx/unoapi.hxx> using namespace com::sun::star; @@ -111,7 +112,7 @@ const TextFont* Theme::resolveFont( std::u16string_view rName ) const std::unique_ptr<svx::Theme> Theme::createSvxTheme() const { auto pTheme = std::make_unique<svx::Theme>(maThemeName); - auto pColorSet = std::make_unique<svx::ColorSet>(maClrScheme.GetName()); + auto pColorSet = std::make_unique<model::ColorSet>(maClrScheme.GetName()); maClrScheme.fill(*pColorSet); pTheme->SetColorSet(std::move(pColorSet)); diff --git a/oox/source/export/ThemeExport.cxx b/oox/source/export/ThemeExport.cxx index b1684986f028..0f1b8eb919b8 100644 --- a/oox/source/export/ThemeExport.cxx +++ b/oox/source/export/ThemeExport.cxx @@ -37,7 +37,7 @@ void ThemeExport::write(OUString const& rPath, svx::Theme const& rTheme) pFS->startElementNS(XML_a, XML_themeElements); - const svx::ColorSet* pColorSet = rTheme.GetColorSet(); + const model::ColorSet* pColorSet = rTheme.GetColorSet(); pFS->startElementNS(XML_a, XML_clrScheme, XML_name, pColorSet->getName()); writeColorSet(pFS, rTheme); @@ -242,7 +242,7 @@ bool ThemeExport::writeColorSet(sax_fastparser::FSHelperPtr pFS, svx::Theme cons = { XML_dk1, XML_lt1, XML_dk2, XML_lt2, XML_accent1, XML_accent2, XML_accent3, XML_accent4, XML_accent5, XML_accent6, XML_hlink, XML_folHlink }; - const svx::ColorSet* pColorSet = rTheme.GetColorSet(); + const model::ColorSet* pColorSet = rTheme.GetColorSet(); if (!pColorSet) return false; diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx b/sd/source/filter/eppt/pptx-epptooxml.cxx index 3827c90e045e..5b8b5cf5b6f4 100644 --- a/sd/source/filter/eppt/pptx-epptooxml.cxx +++ b/sd/source/filter/eppt/pptx-epptooxml.cxx @@ -2176,7 +2176,7 @@ bool PowerPointExport::WriteColorSets(const FSHelperPtr& pFS, svx::Theme* pTheme return false; } - svx::ColorSet* pColorSet = pTheme->GetColorSet(); + model::ColorSet* pColorSet = pTheme->GetColorSet(); if (!pColorSet) { return false; @@ -2271,7 +2271,7 @@ void PowerPointExport::WriteTheme(sal_Int32 nThemeNum, svx::Theme* pTheme) OUString aColorSchemeName("Office"); if (pTheme) { - svx::ColorSet* pColorSet = pTheme->GetColorSet(); + model::ColorSet* pColorSet = pTheme->GetColorSet(); if (pColorSet) { aColorSchemeName = pColorSet->getName(); diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk index f4b2befd5394..074a18d0dc60 100644 --- a/svx/Library_svx.mk +++ b/svx/Library_svx.mk @@ -55,6 +55,7 @@ $(eval $(call gb_Library_use_libraries,svx,\ crashreport) \ $(call gb_Helper_optional,DBCONNECTIVITY, \ dbtools) \ + docmodel \ drawinglayercore \ drawinglayer \ editeng \ diff --git a/svx/source/dialog/ThemeColorValueSet.cxx b/svx/source/dialog/ThemeColorValueSet.cxx index 204a37ba72de..bc0356b2b711 100644 --- a/svx/source/dialog/ThemeColorValueSet.cxx +++ b/svx/source/dialog/ThemeColorValueSet.cxx @@ -19,7 +19,7 @@ constexpr tools::Long LABEL_HEIGHT = 16; constexpr tools::Long LABEL_TEXT_HEIGHT = 14; constexpr tools::Long constElementNumber = 8; -void ThemeColorValueSet::insert(svx::ColorSet const& rColorSet) +void ThemeColorValueSet::insert(model::ColorSet const& rColorSet) { maColorSets.push_back(std::cref(rColorSet)); InsertItem(maColorSets.size()); @@ -40,7 +40,7 @@ void ThemeColorValueSet::UserDraw(const UserDrawEvent& rUserDrawEvent) tools::Rectangle aRect = rUserDrawEvent.GetRect(); const Point aPosition = aRect.GetPos(); const sal_uInt16 nItemId = rUserDrawEvent.GetItemId(); - svx::ColorSet const& rColorSet = maColorSets[nItemId - 1]; + model::ColorSet const& rColorSet = maColorSets[nItemId - 1]; Size aSize = aRect.GetSize(); Size aMin(BORDER * 7 + SIZE * constElementNumber / 2 + BORDER * 2, diff --git a/svx/source/dialog/ThemeDialog.cxx b/svx/source/dialog/ThemeDialog.cxx index 449a466e88e4..ff078650d8e4 100644 --- a/svx/source/dialog/ThemeDialog.cxx +++ b/svx/source/dialog/ThemeDialog.cxx @@ -9,6 +9,7 @@ #include <svx/dialog/ThemeDialog.hxx> #include <docmodel/theme/ThemeColor.hxx> +#include <docmodel/theme/ColorSet.hxx> #include <vcl/svapp.hxx> namespace svx @@ -53,7 +54,7 @@ void ThemeDialog::DoubleClickHdl() sal_uInt32 nIndex = nItemId - 1; - svx::ColorSet const& rColorSet = maColorSets.getColorSet(nIndex); + model::ColorSet const& rColorSet = maColorSets.getColorSet(nIndex); mpChanger->apply(rColorSet); } diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx index eada260cf076..23adaf3281a1 100644 --- a/svx/source/styles/ColorSets.cxx +++ b/svx/source/styles/ColorSets.cxx @@ -10,7 +10,6 @@ #include <svx/ColorSets.hxx> -#include <sstream> #include <utility> #include <libxml/xmlwriter.h> @@ -21,6 +20,7 @@ #include <svx/svditer.hxx> #include <editeng/unoprnms.hxx> #include <docmodel/uno/UnoThemeColor.hxx> +#include <docmodel/theme/ColorSet.hxx> #include <o3tl/enumrange.hxx> #include <com/sun/star/util/Color.hpp> @@ -29,58 +29,6 @@ using namespace com::sun::star; namespace svx { -ColorSet::ColorSet(OUString const& rName) - : maName(rName) -{} - -void ColorSet::add(model::ThemeColorType eType, Color aColorData) -{ - if (eType == model::ThemeColorType::Unknown) - return; - maColors[sal_Int16(eType)] = aColorData; -} - -Color ColorSet::getColor(model::ThemeColorType eType) const -{ - if (eType == model::ThemeColorType::Unknown) - { - SAL_WARN("svx", "ColorSet::getColor with ThemeColorType::Unknown"); - return COL_AUTO; - } - return maColors[size_t(eType)]; -} - -Color ColorSet::resolveColor(model::ThemeColor const& rThemeColor) const -{ - auto eType = rThemeColor.getType(); - if (eType == model::ThemeColorType::Unknown) - { - SAL_WARN("svx", "ColorSet::resolveColor with ThemeColorType::Unknown"); - return COL_AUTO; - } - Color aColor = getColor(eType); - return rThemeColor.applyTransformations(aColor); -} - -void ColorSet::dumpAsXml(xmlTextWriterPtr pWriter) const -{ - (void)xmlTextWriterStartElement(pWriter, BAD_CAST("ColorSet")); - (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this); - (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("maName"), - BAD_CAST(maName.toUtf8().getStr())); - - for (const auto& rColor : maColors) - { - (void)xmlTextWriterStartElement(pWriter, BAD_CAST("Color")); - std::stringstream ss; - ss << rColor; - (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(ss.str().c_str())); - (void)xmlTextWriterEndElement(pWriter); - } - - (void)xmlTextWriterEndElement(pWriter); -} - ColorSets::ColorSets() {} @@ -90,7 +38,7 @@ ColorSets::~ColorSets() void ColorSets::init() { { - ColorSet aColorSet("LibreOffice"); + model::ColorSet aColorSet("LibreOffice"); aColorSet.add(model::ThemeColorType::Dark1, 0x000000); aColorSet.add(model::ThemeColorType::Light1, 0xFFFFFF); aColorSet.add(model::ThemeColorType::Dark2, 0x000000); @@ -106,7 +54,7 @@ void ColorSets::init() maColorSets.push_back(aColorSet); } { - ColorSet aColorSet("Rainbow"); + model::ColorSet aColorSet("Rainbow"); aColorSet.add(model::ThemeColorType::Dark1, 0x000000); aColorSet.add(model::ThemeColorType::Light1, 0xFFFFFF); aColorSet.add(model::ThemeColorType::Dark2, 0x1C1C1C); @@ -122,7 +70,7 @@ void ColorSets::init() maColorSets.push_back(aColorSet); } { - ColorSet aColorSet("Beach"); + model::ColorSet aColorSet("Beach"); aColorSet.add(model::ThemeColorType::Dark1, 0x000000); aColorSet.add(model::ThemeColorType::Light1, 0xFFFFFF); aColorSet.add(model::ThemeColorType::Dark2, 0xFFBF00); @@ -138,7 +86,7 @@ void ColorSets::init() maColorSets.push_back(aColorSet); } { - ColorSet aColorSet("Sunset"); + model::ColorSet aColorSet("Sunset"); aColorSet.add(model::ThemeColorType::Dark1, 0x000000); aColorSet.add(model::ThemeColorType::Light1, 0xFFFFFF); aColorSet.add(model::ThemeColorType::Dark2, 0x492300); @@ -154,7 +102,7 @@ void ColorSets::init() maColorSets.push_back(aColorSet); } { - ColorSet aColorSet("Ocean"); + model::ColorSet aColorSet("Ocean"); aColorSet.add(model::ThemeColorType::Dark1, 0x000000); aColorSet.add(model::ThemeColorType::Light1, 0xFFFFFF); aColorSet.add(model::ThemeColorType::Dark2, 0x2A6099); @@ -170,7 +118,7 @@ void ColorSets::init() maColorSets.push_back(aColorSet); } { - ColorSet aColorSet("Forest"); + model::ColorSet aColorSet("Forest"); aColorSet.add(model::ThemeColorType::Dark1, 0x000000); aColorSet.add(model::ThemeColorType::Light1, 0xFFFFFF); aColorSet.add(model::ThemeColorType::Dark2, 0x000000); @@ -186,7 +134,7 @@ void ColorSets::init() maColorSets.push_back(aColorSet); } { - ColorSet aColorSet("Breeze"); + model::ColorSet aColorSet("Breeze"); aColorSet.add(model::ThemeColorType::Dark1, 0x232629); aColorSet.add(model::ThemeColorType::Light1, 0xFCFCFC); aColorSet.add(model::ThemeColorType::Dark2, 0x31363B); @@ -203,9 +151,9 @@ void ColorSets::init() } } -const ColorSet& ColorSets::getColorSet(std::u16string_view rName) +const model::ColorSet& ColorSets::getColorSet(std::u16string_view rName) { - for (const ColorSet & rColorSet : maColorSets) + for (const model::ColorSet & rColorSet : maColorSets) { if (rColorSet.getName() == rName) return rColorSet; @@ -213,7 +161,7 @@ const ColorSet& ColorSets::getColorSet(std::u16string_view rName) return maColorSets[0]; } -void ColorSets::insert(ColorSet const& rColorSet) +void ColorSets::insert(model::ColorSet const& rColorSet) { maColorSets.push_back(rColorSet); } @@ -223,11 +171,11 @@ Theme::Theme(OUString const& rName) { } -void Theme::SetColorSet(std::unique_ptr<ColorSet> pColorSet) { mpColorSet = std::move(pColorSet); } +void Theme::SetColorSet(std::unique_ptr<model::ColorSet> pColorSet) { mpColorSet = std::move(pColorSet); } -const ColorSet* Theme::GetColorSet() const { return mpColorSet.get(); } +const model::ColorSet* Theme::GetColorSet() const { return mpColorSet.get(); } -ColorSet* Theme::GetColorSet() { return mpColorSet.get(); } +model::ColorSet* Theme::GetColorSet() { return mpColorSet.get(); } void Theme::SetName(const OUString& rName) { maName = rName; } @@ -276,7 +224,7 @@ std::unique_ptr<Theme> Theme::FromAny(const css::uno::Any& rVal) { comphelper::SequenceAsHashMap aMap(rVal); std::unique_ptr<Theme> pTheme; - ColorSet* pColorSet = nullptr; + model::ColorSet* pColorSet = nullptr; auto it = aMap.find("Name"); if (it != aMap.end()) @@ -291,7 +239,7 @@ std::unique_ptr<Theme> Theme::FromAny(const css::uno::Any& rVal) { OUString aName; it->second >>= aName; - auto pSet = std::make_unique<ColorSet>(aName); + auto pSet = std::make_unique<model::ColorSet>(aName); pTheme->SetColorSet(std::move(pSet)); pColorSet = pTheme->GetColorSet(); } diff --git a/svx/source/theme/ThemeColorChanger.cxx b/svx/source/theme/ThemeColorChanger.cxx index 677a0446451a..792f85d3bda9 100644 --- a/svx/source/theme/ThemeColorChanger.cxx +++ b/svx/source/theme/ThemeColorChanger.cxx @@ -14,6 +14,7 @@ #include <svx/svditer.hxx> #include <editeng/unoprnms.hxx> #include <docmodel/uno/UnoThemeColor.hxx> +#include <docmodel/theme/ColorSet.hxx> #include <com/sun/star/text/XTextRange.hpp> #include <com/sun/star/container/XEnumerationAccess.hpp> @@ -30,7 +31,7 @@ namespace theme namespace { /// Updates text portion property colors -void updateTextPortionColorSet(svx::ColorSet const& rColorSet, +void updateTextPortionColorSet(model::ColorSet const& rColorSet, const uno::Reference<beans::XPropertySet>& xPortion) { if (!xPortion->getPropertySetInfo()->hasPropertyByName( @@ -53,7 +54,7 @@ void updateTextPortionColorSet(svx::ColorSet const& rColorSet, } /// Updates the fill property colors -void updateFillColorSet(svx::ColorSet const& rColorSet, +void updateFillColorSet(model::ColorSet const& rColorSet, const uno::Reference<beans::XPropertySet>& xShape) { if (!xShape->getPropertySetInfo()->hasPropertyByName(UNO_NAME_FILLCOLOR_THEME_REFERENCE)) @@ -75,7 +76,7 @@ void updateFillColorSet(svx::ColorSet const& rColorSet, } /// Updates the line property colors -void updateLineColorSet(svx::ColorSet const& rColorSet, +void updateLineColorSet(model::ColorSet const& rColorSet, const uno::Reference<beans::XPropertySet>& xShape) { if (!xShape->getPropertySetInfo()->hasPropertyByName(UNO_NAME_LINECOLOR_THEME_REFERENCE)) @@ -99,7 +100,7 @@ void updateLineColorSet(svx::ColorSet const& rColorSet, } // end anonymous namespace /// Updates properties of the SdrObject -void updateSdrObject(svx::ColorSet const& rColorSet, SdrObject* pObject) +void updateSdrObject(model::ColorSet const& rColorSet, SdrObject* pObject) { uno::Reference<drawing::XShape> xShape = pObject->getUnoShape(); uno::Reference<text::XTextRange> xShapeText(xShape, uno::UNO_QUERY); @@ -136,7 +137,7 @@ ThemeColorChanger::ThemeColorChanger(SdrPage* pPage) ThemeColorChanger::~ThemeColorChanger() = default; -void ThemeColorChanger::apply(svx::ColorSet const& rColorSet) +void ThemeColorChanger::apply(model::ColorSet const& rColorSet) { for (size_t nObject = 0; nObject < mpPage->GetObjCount(); ++nObject) { diff --git a/sw/qa/core/theme/ThemeTest.cxx b/sw/qa/core/theme/ThemeTest.cxx index 43cc2a669fe2..412482e3f471 100644 --- a/sw/qa/core/theme/ThemeTest.cxx +++ b/sw/qa/core/theme/ThemeTest.cxx @@ -53,7 +53,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreThemeTest, testDrawPageThemeExists) CPPUNIT_ASSERT(pTheme); CPPUNIT_ASSERT_EQUAL(OUString(u"Office Theme"), pTheme->GetName()); - svx::ColorSet* pColorSet = pTheme->GetColorSet(); + model::ColorSet* pColorSet = pTheme->GetColorSet(); CPPUNIT_ASSERT(pColorSet); CPPUNIT_ASSERT_EQUAL(OUString(u"Orange"), pColorSet->getName()); diff --git a/sw/source/core/inc/ThemeColorChanger.hxx b/sw/source/core/inc/ThemeColorChanger.hxx index a246f17453a1..71526f79d216 100644 --- a/sw/source/core/inc/ThemeColorChanger.hxx +++ b/sw/source/core/inc/ThemeColorChanger.hxx @@ -10,7 +10,7 @@ #pragma once #include <docsh.hxx> -#include <svx/ColorSets.hxx> +#include <docmodel/theme/ColorSet.hxx> #include <svx/theme/ThemeColorChanger.hxx> namespace sw @@ -24,7 +24,7 @@ public: ThemeColorChanger(SwDocShell* pDocSh); virtual ~ThemeColorChanger() override; - void apply(svx::ColorSet const& rColorSet) override; + void apply(model::ColorSet const& rColorSet) override; }; } // end sw namespace diff --git a/sw/source/core/model/ThemeColorChanger.cxx b/sw/source/core/model/ThemeColorChanger.cxx index dc9a7fe1c86c..715c02e68b63 100644 --- a/sw/source/core/model/ThemeColorChanger.cxx +++ b/sw/source/core/model/ThemeColorChanger.cxx @@ -46,10 +46,10 @@ namespace class ThemeColorHandler : public sw::ModelTraverseHandler { SwDoc& mrDocument; - svx::ColorSet const& mrColorSet; + model::ColorSet const& mrColorSet; public: - ThemeColorHandler(SwDoc& rDocument, svx::ColorSet const& rColorSet) + ThemeColorHandler(SwDoc& rDocument, model::ColorSet const& rColorSet) : mrDocument(rDocument) , mrColorSet(rColorSet) { @@ -115,7 +115,7 @@ public: } }; -void changeColor(SwFormat* pFormat, svx::ColorSet const& rColorSet, SwDoc* pDocument) +void changeColor(SwFormat* pFormat, model::ColorSet const& rColorSet, SwDoc* pDocument) { const SwAttrSet& rAttrSet = pFormat->GetAttrSet(); std::unique_ptr<SfxItemSet> pNewSet = rAttrSet.Clone(); @@ -142,7 +142,7 @@ ThemeColorChanger::ThemeColorChanger(SwDocShell* pDocSh) ThemeColorChanger::~ThemeColorChanger() = default; -void ThemeColorChanger::apply(svx::ColorSet const& rColorSet) +void ThemeColorChanger::apply(model::ColorSet const& rColorSet) { SwDoc* pDocument = mpDocSh->GetDoc(); if (!pDocument) @@ -154,13 +154,13 @@ void ThemeColorChanger::apply(svx::ColorSet const& rColorSet) svx::Theme* pTheme = pPage->getSdrPageProperties().GetTheme(); if (pTheme) { - pTheme->SetColorSet(std::make_unique<svx::ColorSet>(rColorSet)); + pTheme->SetColorSet(std::make_unique<model::ColorSet>(rColorSet)); } else { pPage->getSdrPageProperties().SetTheme(std::make_unique<svx::Theme>("Office")); pTheme = pPage->getSdrPageProperties().GetTheme(); - pTheme->SetColorSet(std::make_unique<svx::ColorSet>(rColorSet)); + pTheme->SetColorSet(std::make_unique<model::ColorSet>(rColorSet)); } SfxStyleSheetBasePool* pPool = mpDocSh->GetStyleSheetPool(); diff --git a/sw/source/uibase/sidebar/ThemePanel.cxx b/sw/source/uibase/sidebar/ThemePanel.cxx index 76fd5e59870b..d2c225c171c3 100644 --- a/sw/source/uibase/sidebar/ThemePanel.cxx +++ b/sw/source/uibase/sidebar/ThemePanel.cxx @@ -59,10 +59,10 @@ ThemePanel::ThemePanel(weld::Widget* pParent) maColorSets.insert(*pTheme->GetColorSet()); } - const std::vector<svx::ColorSet>& aColorSets = maColorSets.getColorSets(); + const std::vector<model::ColorSet>& aColorSets = maColorSets.getColorSets(); for (size_t i = 0; i < aColorSets.size(); ++i) { - const svx::ColorSet& rColorSet = aColorSets[i]; + const model::ColorSet& rColorSet = aColorSets[i]; mxValueSetColors->insert(rColorSet); } @@ -106,7 +106,7 @@ void ThemePanel::DoubleClickHdl() return; sal_uInt32 nIndex = nItemId - 1; - svx::ColorSet const& rColorSet = maColorSets.getColorSet(nIndex); + model::ColorSet const& rColorSet = maColorSets.getColorSet(nIndex); ThemeColorChanger aChanger(pDocSh); aChanger.apply(rColorSet); diff --git a/writerfilter/source/dmapper/ThemeHandler.cxx b/writerfilter/source/dmapper/ThemeHandler.cxx index 555a2b491fcc..3a7260d89047 100644 --- a/writerfilter/source/dmapper/ThemeHandler.cxx +++ b/writerfilter/source/dmapper/ThemeHandler.cxx @@ -10,6 +10,7 @@ #include "ThemeHandler.hxx" #include <i18nlangtag/languagetag.hxx> #include <ooxml/resourceids.hxx> +#include <svx/ColorSets.hxx> using namespace com::sun::star; commit 5f15b05d0681c847ff7aeca560927fa5d975fecb Author: Tomaž Vajngerl <[email protected]> AuthorDate: Thu Jan 26 21:19:31 2023 +0900 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Mon Jan 30 05:54:29 2023 +0000 use ThemeColorChanger also in svx, when changing theme for SdrPage This refactors the code in the Theme class to remove code that is responsible for changing the color for the SdrPage and adds an implementation of IThemeColorChanger - svx::ThemeColorChanger, that is performing the same task from now on. The svx::ThemeColorChanger is also partially used in Writer by sw::ThemeColorChanger, when it needs to change the colors in the common (Sdr) objects. Change-Id: I39cfa278d31bdd802a5bf36eeaf6d472c8013dba Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146173 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <[email protected]> (cherry picked from commit 9cbc3a64492e0670427f17b753d0908657c8c5bd) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146228 Tested-by: Tomaž Vajngerl <[email protected]> diff --git a/include/svx/ColorSets.hxx b/include/svx/ColorSets.hxx index 115236da1979..d4188c0ba2d8 100644 --- a/include/svx/ColorSets.hxx +++ b/include/svx/ColorSets.hxx @@ -243,8 +243,6 @@ public: static std::unique_ptr<Theme> FromAny(const css::uno::Any& rVal); - void UpdateSdrPage(const SdrPage* pPage); - std::vector<Color> GetColors() const; Color GetColor(model::ThemeColorType eType) const; diff --git a/include/svx/theme/IThemeColorChanger.hxx b/include/svx/theme/IThemeColorChanger.hxx index 5f90f273ee37..93cba5870b96 100644 --- a/include/svx/theme/IThemeColorChanger.hxx +++ b/include/svx/theme/IThemeColorChanger.hxx @@ -14,7 +14,7 @@ namespace svx { -class SVX_DLLPUBLIC IThemeColorChanger +class SVXCORE_DLLPUBLIC IThemeColorChanger { public: virtual ~IThemeColorChanger() = default; diff --git a/include/svx/theme/ThemeColorChanger.hxx b/include/svx/theme/ThemeColorChanger.hxx new file mode 100644 index 000000000000..cf4071824d9c --- /dev/null +++ b/include/svx/theme/ThemeColorChanger.hxx @@ -0,0 +1,39 @@ +/* -*- 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 <svx/svxdllapi.h> +#include <svx/theme/IThemeColorChanger.hxx> +#include <svx/ColorSets.hxx> +#include <svx/svdpage.hxx> +#include <svx/svdobj.hxx> + +namespace svx +{ +namespace theme +{ +SVXCORE_DLLPUBLIC void updateSdrObject(svx::ColorSet const& rColorSet, SdrObject* pObject); +} + +class SVXCORE_DLLPUBLIC ThemeColorChanger : public IThemeColorChanger +{ +private: + SdrPage* mpPage; + +public: + ThemeColorChanger(SdrPage* pPage); + virtual ~ThemeColorChanger() override; + + void apply(svx::ColorSet const& rColorSet) override; +}; + +} // end svx namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk index 439ae516427c..9ecc9ec58fc4 100644 --- a/svx/Library_svxcore.mk +++ b/svx/Library_svxcore.mk @@ -428,6 +428,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/tbxctrls/extrusioncontrols \ svx/source/tbxctrls/fontworkgallery \ svx/source/tbxctrls/linectrl \ diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx index 66a5e3e91016..eada260cf076 100644 --- a/svx/source/styles/ColorSets.cxx +++ b/svx/source/styles/ColorSets.cxx @@ -11,15 +11,9 @@ #include <svx/ColorSets.hxx> #include <sstream> +#include <utility> #include <libxml/xmlwriter.h> - -#include <com/sun/star/util/Color.hpp> -#include <com/sun/star/text/XTextRange.hpp> -#include <com/sun/star/container/XEnumerationAccess.hpp> -#include <com/sun/star/container/XEnumeration.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> - #include <comphelper/sequenceashashmap.hxx> #include <comphelper/sequence.hxx> #include <sal/log.hxx> @@ -28,86 +22,10 @@ #include <editeng/unoprnms.hxx> #include <docmodel/uno/UnoThemeColor.hxx> #include <o3tl/enumrange.hxx> -#include <utility> +#include <com/sun/star/util/Color.hpp> using namespace com::sun::star; -namespace -{ -/// Updates a text portion to match a new color set, in case it already uses theme colors. -void UpdateTextPortionColorSet(const uno::Reference<beans::XPropertySet>& xPortion, - const svx::ColorSet& rColorSet) -{ - if (!xPortion->getPropertySetInfo()->hasPropertyByName(UNO_NAME_EDIT_CHAR_COLOR_THEME_REFERENCE)) - return; - - uno::Reference<util::XThemeColor> xThemeColor; - xPortion->getPropertyValue(UNO_NAME_EDIT_CHAR_COLOR_THEME_REFERENCE) >>= xThemeColor; - if (!xThemeColor.is()) - return; - - model::ThemeColor aThemeColor; - model::theme::setFromXThemeColor(aThemeColor, xThemeColor); - - if (aThemeColor.getType() == model::ThemeColorType::Unknown) - return; - - Color aColor = rColorSet.resolveColor(aThemeColor); - xPortion->setPropertyValue(UNO_NAME_EDIT_CHAR_COLOR, uno::Any(static_cast<sal_Int32>(aColor))); -} - -void UpdateFillColorSet(const uno::Reference<beans::XPropertySet>& xShape, const svx::ColorSet& rColorSet) -{ - if (!xShape->getPropertySetInfo()->hasPropertyByName(UNO_NAME_FILLCOLOR_THEME_REFERENCE)) - return; - - uno::Reference<util::XThemeColor> xThemeColor; - xShape->getPropertyValue(UNO_NAME_FILLCOLOR_THEME_REFERENCE) >>= xThemeColor; - if (!xThemeColor.is()) - return; - - model::ThemeColor aThemeColor; - model::theme::setFromXThemeColor(aThemeColor, xThemeColor); - - if (aThemeColor.getType() == model::ThemeColorType::Unknown) - return; - - Color aColor = rColorSet.resolveColor(aThemeColor); - xShape->setPropertyValue(UNO_NAME_FILLCOLOR, uno::Any(static_cast<sal_Int32>(aColor))); -} - -void UpdateSdrObject(svx::Theme* pTheme, SdrObject* pObject) -{ - const svx::ColorSet* pColorSet = pTheme->GetColorSet(); - if (!pColorSet) - { - return; - } - - uno::Reference<drawing::XShape> xShape = pObject->getUnoShape(); - uno::Reference<text::XTextRange> xShapeText(xShape, uno::UNO_QUERY); - if (xShapeText.is()) - { - // E.g. group shapes have no text. - uno::Reference<container::XEnumerationAccess> xText(xShapeText->getText(), uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xParagraphs = xText->createEnumeration(); - while (xParagraphs->hasMoreElements()) - { - uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); - while (xPortions->hasMoreElements()) - { - uno::Reference<beans::XPropertySet> xPortion(xPortions->nextElement(), uno::UNO_QUERY); - UpdateTextPortionColorSet(xPortion, *pColorSet); - } - } - } - - uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY); - UpdateFillColorSet(xShapeProps, *pColorSet); -} -} - namespace svx { @@ -403,24 +321,6 @@ std::unique_ptr<Theme> Theme::FromAny(const css::uno::Any& rVal) return pTheme; } -void Theme::UpdateSdrPage(const SdrPage* pPage) -{ - for (size_t nObject = 0; nObject < pPage->GetObjCount(); ++nObject) - { - SdrObject* pObject = pPage->GetObj(nObject); - UpdateSdrObject(this, pObject); - SdrObjList* pList = pObject->GetSubList(); - if (pList) - { - SdrObjListIter aIter(pList, SdrIterMode::DeepWithGroups); - while (aIter.IsMore()) - { - UpdateSdrObject(this, aIter.Next()); - } - } - } -} - std::vector<Color> Theme::GetColors() const { if (!mpColorSet) diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx index a4c804f53e12..7ec883e397c5 100644 --- a/svx/source/svdraw/svdpage.cxx +++ b/svx/source/svdraw/svdpage.cxx @@ -44,6 +44,7 @@ #include <svx/svdundo.hxx> #include <svx/xfillit0.hxx> #include <svx/fmdpage.hxx> +#include <svx/theme/ThemeColorChanger.hxx> #include <sdr/contact/viewcontactofsdrpage.hxx> #include <svx/sdr/contact/viewobjectcontact.hxx> @@ -1291,7 +1292,7 @@ void SdrPageProperties::SetTheme(std::unique_ptr<svx::Theme> pTheme) { mpTheme = std::move(pTheme); - if (mpTheme && mpSdrPage->IsMasterPage()) + if (mpTheme && mpTheme->GetColorSet() && mpSdrPage->IsMasterPage()) { SdrModel& rModel = mpSdrPage->getSdrModelFromSdrPage(); sal_uInt16 nPageCount = rModel.GetPageCount(); @@ -1303,7 +1304,8 @@ void SdrPageProperties::SetTheme(std::unique_ptr<svx::Theme> pTheme) continue; } - mpTheme->UpdateSdrPage(pPage); + svx::ThemeColorChanger aChanger(pPage); + aChanger.apply(*mpTheme->GetColorSet()); } } } diff --git a/svx/source/theme/ThemeColorChanger.cxx b/svx/source/theme/ThemeColorChanger.cxx new file mode 100644 index 000000000000..677a0446451a --- /dev/null +++ b/svx/source/theme/ThemeColorChanger.cxx @@ -0,0 +1,161 @@ +/* -*- 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 <svx/theme/ThemeColorChanger.hxx> + +#include <sal/config.h> +#include <svx/svdpage.hxx> +#include <svx/svditer.hxx> +#include <editeng/unoprnms.hxx> +#include <docmodel/uno/UnoThemeColor.hxx> + +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XEnumeration.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/util/XThemeColor.hpp> + +using namespace css; + +namespace svx +{ +namespace theme +{ +namespace +{ +/// Updates text portion property colors +void updateTextPortionColorSet(svx::ColorSet const& rColorSet, + const uno::Reference<beans::XPropertySet>& xPortion) +{ + if (!xPortion->getPropertySetInfo()->hasPropertyByName( + UNO_NAME_EDIT_CHAR_COLOR_THEME_REFERENCE)) + return; + + uno::Reference<util::XThemeColor> xThemeColor; + xPortion->getPropertyValue(UNO_NAME_EDIT_CHAR_COLOR_THEME_REFERENCE) >>= xThemeColor; + if (!xThemeColor.is()) + return; + + model::ThemeColor aThemeColor; + model::theme::setFromXThemeColor(aThemeColor, xThemeColor); + + if (aThemeColor.getType() == model::ThemeColorType::Unknown) + return; + + Color aColor = rColorSet.resolveColor(aThemeColor); + xPortion->setPropertyValue(UNO_NAME_EDIT_CHAR_COLOR, uno::Any(static_cast<sal_Int32>(aColor))); +} + +/// Updates the fill property colors +void updateFillColorSet(svx::ColorSet const& rColorSet, + const uno::Reference<beans::XPropertySet>& xShape) +{ + if (!xShape->getPropertySetInfo()->hasPropertyByName(UNO_NAME_FILLCOLOR_THEME_REFERENCE)) + return; + + uno::Reference<util::XThemeColor> xThemeColor; + xShape->getPropertyValue(UNO_NAME_FILLCOLOR_THEME_REFERENCE) >>= xThemeColor; + if (!xThemeColor.is()) + return; + + model::ThemeColor aThemeColor; + model::theme::setFromXThemeColor(aThemeColor, xThemeColor); + + if (aThemeColor.getType() == model::ThemeColorType::Unknown) + return; + + Color aColor = rColorSet.resolveColor(aThemeColor); + xShape->setPropertyValue(UNO_NAME_FILLCOLOR, uno::Any(static_cast<sal_Int32>(aColor))); +} + +/// Updates the line property colors +void updateLineColorSet(svx::ColorSet const& rColorSet, + const uno::Reference<beans::XPropertySet>& xShape) +{ + if (!xShape->getPropertySetInfo()->hasPropertyByName(UNO_NAME_LINECOLOR_THEME_REFERENCE)) + return; + + uno::Reference<util::XThemeColor> xThemeColor; + xShape->getPropertyValue(UNO_NAME_LINECOLOR_THEME_REFERENCE) >>= xThemeColor; + if (!xThemeColor.is()) + return; + + model::ThemeColor aThemeColor; + model::theme::setFromXThemeColor(aThemeColor, xThemeColor); + + if (aThemeColor.getType() == model::ThemeColorType::Unknown) + return; + + Color aColor = rColorSet.resolveColor(aThemeColor); + xShape->setPropertyValue(UNO_NAME_LINECOLOR, uno::Any(static_cast<sal_Int32>(aColor))); +} + +} // end anonymous namespace + +/// Updates properties of the SdrObject +void updateSdrObject(svx::ColorSet const& rColorSet, SdrObject* pObject) +{ + uno::Reference<drawing::XShape> xShape = pObject->getUnoShape(); + uno::Reference<text::XTextRange> xShapeText(xShape, uno::UNO_QUERY); + if (xShapeText.is()) + { + // E.g. group shapes have no text. + uno::Reference<container::XEnumerationAccess> xText(xShapeText->getText(), uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParagraphs = xText->createEnumeration(); + while (xParagraphs->hasMoreElements()) + { + uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), + uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); + while (xPortions->hasMoreElements()) + { + uno::Reference<beans::XPropertySet> xPortion(xPortions->nextElement(), + uno::UNO_QUERY); + updateTextPortionColorSet(rColorSet, xPortion); + } + } + } + + uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY); + updateFillColorSet(rColorSet, xShapeProps); + updateLineColorSet(rColorSet, xShapeProps); +} + +} // end theme + +ThemeColorChanger::ThemeColorChanger(SdrPage* pPage) + : mpPage(pPage) +{ +} + +ThemeColorChanger::~ThemeColorChanger() = default; + +void ThemeColorChanger::apply(svx::ColorSet const& rColorSet) +{ + for (size_t nObject = 0; nObject < mpPage->GetObjCount(); ++nObject) + { + SdrObject* pObject = mpPage->GetObj(nObject); + theme::updateSdrObject(rColorSet, pObject); + + // update child objects + SdrObjList* pList = pObject->GetSubList(); + if (pList) + { + SdrObjListIter aIter(pList, SdrIterMode::DeepWithGroups); + while (aIter.IsMore()) + { + theme::updateSdrObject(rColorSet, aIter.Next()); + } + } + } +} + +} // end svx 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 d4ba7a9fcad5..a246f17453a1 100644 --- a/sw/source/core/inc/ThemeColorChanger.hxx +++ b/sw/source/core/inc/ThemeColorChanger.hxx @@ -11,7 +11,7 @@ #include <docsh.hxx> #include <svx/ColorSets.hxx> -#include <svx/theme/IThemeColorChanger.hxx> +#include <svx/theme/ThemeColorChanger.hxx> namespace sw { @@ -21,11 +21,7 @@ private: SwDocShell* mpDocSh; public: - ThemeColorChanger(SwDocShell* pDocSh) - : mpDocSh(pDocSh) - { - } - + ThemeColorChanger(SwDocShell* pDocSh); virtual ~ThemeColorChanger() override; void apply(svx::ColorSet const& rColorSet) override; diff --git a/sw/source/core/model/ThemeColorChanger.cxx b/sw/source/core/model/ThemeColorChanger.cxx index 87f1901083c4..dc9a7fe1c86c 100644 --- a/sw/source/core/model/ThemeColorChanger.cxx +++ b/sw/source/core/model/ThemeColorChanger.cxx @@ -97,105 +97,10 @@ public: updateHints(pNode->GetTextNode()); } - /// Updates text portion property colors - void updateTextPortionColorSet(const uno::Reference<beans::XPropertySet>& xPortion) - { - if (!xPortion->getPropertySetInfo()->hasPropertyByName( - UNO_NAME_EDIT_CHAR_COLOR_THEME_REFERENCE)) - return; - - uno::Reference<util::XThemeColor> xThemeColor; - xPortion->getPropertyValue(UNO_NAME_EDIT_CHAR_COLOR_THEME_REFERENCE) >>= xThemeColor; - if (!xThemeColor.is()) - return; - - model::ThemeColor aThemeColor; - model::theme::setFromXThemeColor(aThemeColor, xThemeColor); - - if (aThemeColor.getType() == model::ThemeColorType::Unknown) - return; - - Color aColor = mrColorSet.resolveColor(aThemeColor); - xPortion->setPropertyValue(UNO_NAME_EDIT_CHAR_COLOR, - uno::Any(static_cast<sal_Int32>(aColor))); - } - - /// Updates the fill property colors - void updateFillColorSet(const uno::Reference<beans::XPropertySet>& xShape) - { - if (!xShape->getPropertySetInfo()->hasPropertyByName(UNO_NAME_FILLCOLOR_THEME_REFERENCE)) - return; - - uno::Reference<util::XThemeColor> xThemeColor; - xShape->getPropertyValue(UNO_NAME_FILLCOLOR_THEME_REFERENCE) >>= xThemeColor; - if (!xThemeColor.is()) - return; - - model::ThemeColor aThemeColor; - model::theme::setFromXThemeColor(aThemeColor, xThemeColor); - - if (aThemeColor.getType() == model::ThemeColorType::Unknown) - return; - - Color aColor = mrColorSet.resolveColor(aThemeColor); - xShape->setPropertyValue(UNO_NAME_FILLCOLOR, uno::Any(static_cast<sal_Int32>(aColor))); - } - - /// Updates the line property colors - void updateLineColorSet(const uno::Reference<beans::XPropertySet>& xShape) - { - if (!xShape->getPropertySetInfo()->hasPropertyByName(UNO_NAME_LINECOLOR_THEME_REFERENCE)) - return; - - uno::Reference<util::XThemeColor> xThemeColor; - xShape->getPropertyValue(UNO_NAME_LINECOLOR_THEME_REFERENCE) >>= xThemeColor; - if (!xThemeColor.is()) - return; - - model::ThemeColor aThemeColor; - model::theme::setFromXThemeColor(aThemeColor, xThemeColor); - - if (aThemeColor.getType() == model::ThemeColorType::Unknown) - return; - - Color aColor = mrColorSet.resolveColor(aThemeColor); - xShape->setPropertyValue(UNO_NAME_LINECOLOR, uno::Any(static_cast<sal_Int32>(aColor))); - } - - /// Updates properties of the SdrObject - void updateSdrObject(SdrObject* pObject) - { - uno::Reference<drawing::XShape> xShape = pObject->getUnoShape(); - uno::Reference<text::XTextRange> xShapeText(xShape, uno::UNO_QUERY); - if (xShapeText.is()) - { - // E.g. group shapes have no text. - uno::Reference<container::XEnumerationAccess> xText(xShapeText->getText(), - uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xParagraphs = xText->createEnumeration(); - while (xParagraphs->hasMoreElements()) - { - uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(), - uno::UNO_QUERY); - uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration(); - while (xPortions->hasMoreElements()) - { - uno::Reference<beans::XPropertySet> xPortion(xPortions->nextElement(), - uno::UNO_QUERY); - updateTextPortionColorSet(xPortion); - } - } - } - - uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY); - updateFillColorSet(xShapeProps); - updateLineColorSet(xShapeProps); - } - void handleSdrObject(SdrObject* pObject) override { // update current object - updateSdrObject(pObject); + svx::theme::updateSdrObject(mrColorSet, pObject); // update child objects SdrObjList* pList = pObject->GetSubList(); @@ -204,7 +109,7 @@ public: SdrObjListIter aIter(pList, SdrIterMode::DeepWithGroups); while (aIter.IsMore()) { - updateSdrObject(aIter.Next()); + svx::theme::updateSdrObject(mrColorSet, aIter.Next()); } } } @@ -230,7 +135,12 @@ void changeColor(SwFormat* pFormat, svx::ColorSet const& rColorSet, SwDoc* pDocu } // end anonymous namespace -ThemeColorChanger::~ThemeColorChanger() {} +ThemeColorChanger::ThemeColorChanger(SwDocShell* pDocSh) + : mpDocSh(pDocSh) +{ +} + +ThemeColorChanger::~ThemeColorChanger() = default; void ThemeColorChanger::apply(svx::ColorSet const& rColorSet) {
