docmodel/source/theme/Theme.cxx | 17 ++++++++++++++--- include/docmodel/theme/Theme.hxx | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-)
New commits: commit e5c690c6be7df71cc612ef90e4502839ab519eb6 Author: Mike Kaganski <[email protected]> AuthorDate: Sun Jun 15 03:09:24 2025 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Sun Jun 15 12:00:59 2025 +0200 tdf#167018: let Theme::FromAny handle XTheme It is created e.g. in XMLThemeContext dtor. The type of return of FromAny is changed to shared_ptr, which allows to return the result of UnoTheme::getTheme, and which matches the types used by all the function callers. Change-Id: Ie223e5663843be098e2da45cb04d825c72c372fd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186508 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Jenkins diff --git a/docmodel/source/theme/Theme.cxx b/docmodel/source/theme/Theme.cxx index 364b25fc7187..55a39f2b6afd 100644 --- a/docmodel/source/theme/Theme.cxx +++ b/docmodel/source/theme/Theme.cxx @@ -9,6 +9,7 @@ */ #include <docmodel/theme/Theme.hxx> +#include <docmodel/uno/UnoTheme.hxx> #include <utility> #include <libxml/xmlwriter.h> @@ -19,6 +20,8 @@ #include <o3tl/enumrange.hxx> #include <com/sun/star/util/Color.hpp> #include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/util/XTheme.hpp> using namespace com::sun::star; @@ -81,10 +84,18 @@ void Theme::ToAny(uno::Any& rVal) const rVal <<= aMap.getAsConstPropertyValueList(); } -std::unique_ptr<Theme> Theme::FromAny(const uno::Any& rVal) +std::shared_ptr<Theme> Theme::FromAny(const uno::Any& rVal) { + if (css::uno::Reference<css::util::XTheme> xTheme; rVal >>= xTheme) + { + if (auto* pUnoTheme = dynamic_cast<UnoTheme*>(xTheme.get())) + return pUnoTheme->getTheme(); + else + throw css::lang::IllegalArgumentException(); + } + comphelper::SequenceAsHashMap aMap(rVal); - std::unique_ptr<Theme> pTheme; + std::shared_ptr<Theme> pTheme; std::shared_ptr<model::ColorSet> pColorSet; auto it = aMap.find(u"Name"_ustr); @@ -92,7 +103,7 @@ std::unique_ptr<Theme> Theme::FromAny(const uno::Any& rVal) { OUString aName; it->second >>= aName; - pTheme = std::make_unique<Theme>(aName); + pTheme = std::make_shared<Theme>(aName); } it = aMap.find(u"ColorSchemeName"_ustr); diff --git a/include/docmodel/theme/Theme.hxx b/include/docmodel/theme/Theme.hxx index c13f0549b7a8..6ab23a54ae6c 100644 --- a/include/docmodel/theme/Theme.hxx +++ b/include/docmodel/theme/Theme.hxx @@ -185,7 +185,7 @@ public: void ToAny(css::uno::Any& rVal) const; - static std::unique_ptr<Theme> FromAny(const css::uno::Any& rVal); + static std::shared_ptr<Theme> FromAny(const css::uno::Any& rVal); std::vector<Color> GetColors() const;
