docmodel/Library_docmodel.mk | 1 docmodel/source/theme/Theme.cxx | 7 + docmodel/source/uno/UnoTheme.cxx | 50 +++++++++++ include/docmodel/theme/Theme.hxx | 2 include/docmodel/uno/UnoTheme.hxx | 46 ++++++++++ offapi/UnoApi_offapi.mk | 1 offapi/com/sun/star/util/XTheme.idl | 34 +++++++ xmloff/Library_xo.mk | 3 xmloff/inc/XMLThemeContext.hxx | 63 ++++++++++++++ xmloff/source/draw/ximpstyl.cxx | 138 -------------------------------- xmloff/source/style/XMLThemeContext.cxx | 123 ++++++++++++++++++++++++++++ 11 files changed, 332 insertions(+), 136 deletions(-)
New commits: commit 7ba71ec27f9eca53cf0645d2b6bbfb37155efac4 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue Jan 24 14:25:50 2023 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Fri Feb 17 05:23:31 2023 +0000 xmloff: extract XMLThemeContext into own class Change-Id: Iee30a84915148297ad5c105d29fdf48098261a9d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146051 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit 5d135edd8843471f582a88f4e1a9a9b9fc0fd89b) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146449 Tested-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/xmloff/Library_xo.mk b/xmloff/Library_xo.mk index 19c9db439e62..11934fbb2016 100644 --- a/xmloff/Library_xo.mk +++ b/xmloff/Library_xo.mk @@ -59,7 +59,7 @@ $(eval $(call gb_Library_use_libraries,xo,\ i18nlangtag \ sal \ salhelper \ - sax \ + sax \ svl \ tl \ utl \ @@ -251,6 +251,7 @@ $(eval $(call gb_Library_add_exception_objects,xo,\ xmloff/source/style/XMLPageExport \ xmloff/source/style/XMLPercentOrMeasurePropertyHandler \ xmloff/source/style/XMLRectangleMembersHandler \ + xmloff/source/style/XMLThemeContext \ xmloff/source/style/adjushdl \ xmloff/source/style/backhdl \ xmloff/source/style/bordrhdl \ diff --git a/xmloff/inc/XMLThemeContext.hxx b/xmloff/inc/XMLThemeContext.hxx new file mode 100644 index 000000000000..706c1251a534 --- /dev/null +++ b/xmloff/inc/XMLThemeContext.hxx @@ -0,0 +1,63 @@ +/* -*- 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 <utility> +#include <xmloff/xmlprcon.hxx> + +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/util/Color.hpp> +#include <com/sun/star/container/XNameContainer.hpp> + +#include <comphelper/sequenceashashmap.hxx> +#include <comphelper/namecontainer.hxx> + +/// Imports the theme +class XMLThemeContext : public SvXMLImportContext +{ + css::uno::Reference<css::drawing::XDrawPage> m_xPage; + comphelper::SequenceAsHashMap m_aTheme; + +public: + XMLThemeContext(SvXMLImport& rImport, + css::uno::Reference<css::xml::sax::XFastAttributeList> const& xAttrList, + css::uno::Reference<css::drawing::XDrawPage> const& xPage); + ~XMLThemeContext(); + + css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttribs) override; +}; + +/// Imports the color table of a theme +class XMLColorTableContext : public SvXMLImportContext +{ + comphelper::SequenceAsHashMap& m_rTheme; + std::vector<css::util::Color> m_aColorScheme; + +public: + XMLColorTableContext(SvXMLImport& rImport, + css::uno::Reference<css::xml::sax::XFastAttributeList> const& xAttrList, + comphelper::SequenceAsHashMap& rTheme); + ~XMLColorTableContext(); + + css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL createFastChildContext( + sal_Int32 nElement, + css::uno::Reference<css::xml::sax::XFastAttributeList> const& xAttribs) override; +}; + +/// Imports a color for a color table +class XMLColorContext : public SvXMLImportContext +{ +public: + XMLColorContext(SvXMLImport& rImport, + css::uno::Reference<css::xml::sax::XFastAttributeList> const& xAttrList, + std::vector<css::util::Color>& rColorScheme); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/draw/ximpstyl.cxx b/xmloff/source/draw/ximpstyl.cxx index cc23cee1a885..196aeb136a1e 100644 --- a/xmloff/source/draw/ximpstyl.cxx +++ b/xmloff/source/draw/ximpstyl.cxx @@ -52,6 +52,7 @@ #include "layerimp.hxx" #include <xmloff/XMLGraphicsDefaultStyle.hxx> #include <XMLNumberStylesImport.hxx> +#include <XMLThemeContext.hxx> #include <unotools/configmgr.hxx> #include <xmloff/xmlerror.hxx> #include <xmloff/table/XMLTableImport.hxx> @@ -82,48 +83,7 @@ public: ::std::vector< XMLPropertyState > &rProperties, const XMLPropertyState& rProp ) override; }; - -/// Imports <loext:theme>. -class XMLThemeContext : public SvXMLImportContext -{ - uno::Reference<beans::XPropertySet> m_xMasterPage; - comphelper::SequenceAsHashMap m_aTheme; - -public: - XMLThemeContext(SvXMLImport& rImport, - const uno::Reference<xml::sax::XFastAttributeList>& xAttrList, - uno::Reference<beans::XPropertySet> xMasterPage); - ~XMLThemeContext(); - - uno::Reference<xml::sax::XFastContextHandler> SAL_CALL createFastChildContext( - sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& xAttribs) override; -}; - -/// Imports <loext:color-table> inside <loext:theme>. -class XMLColorTableContext : public SvXMLImportContext -{ - comphelper::SequenceAsHashMap& m_rTheme; - std::vector<util::Color> m_aColorScheme; - -public: - XMLColorTableContext(SvXMLImport& rImport, - const uno::Reference<xml::sax::XFastAttributeList>& xAttrList, - comphelper::SequenceAsHashMap& rTheme); - ~XMLColorTableContext(); - - uno::Reference<xml::sax::XFastContextHandler> SAL_CALL createFastChildContext( - sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& xAttribs) override; -}; - -/// Imports <loext:color> inside <loext:color-table>. -class XMLColorContext : public SvXMLImportContext -{ -public: - XMLColorContext(SvXMLImport& rImport, - const uno::Reference<xml::sax::XFastAttributeList>& xAttrList, - std::vector<util::Color>& rColorScheme); -}; -} +} // end anonymous namespace SdXMLDrawingPagePropertySetContext::SdXMLDrawingPagePropertySetContext( SvXMLImport& rImport, sal_Int32 nElement, @@ -878,8 +838,7 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLMasterPageContext { if (GetSdImport().IsImpress()) { - uno::Reference<beans::XPropertySet> xMasterPage(GetLocalShapesContext(), - uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xMasterPage(GetLocalShapesContext(), uno::UNO_QUERY); return new XMLThemeContext(GetSdImport(), xAttrList, xMasterPage); } break; @@ -1487,97 +1446,6 @@ void SdXMLHeaderFooterDeclContext::characters( const OUString& rChars ) maStrText += rChars; } -XMLThemeContext::XMLThemeContext(SvXMLImport& rImport, - const uno::Reference<xml::sax::XFastAttributeList>& xAttrList, - uno::Reference<beans::XPropertySet> xMasterPage) - : SvXMLImportContext(rImport) - , m_xMasterPage(std::move(xMasterPage)) -{ - for (const auto& rAttribute : sax_fastparser::castToFastAttributeList(xAttrList)) - { - switch (rAttribute.getToken()) - { - case XML_ELEMENT(LO_EXT, XML_NAME): - { - m_aTheme["Name"] <<= rAttribute.toString(); - break; - } - } - } -} - -XMLThemeContext::~XMLThemeContext() -{ - uno::Any aTheme(m_aTheme.getAsConstPropertyValueList()); - m_xMasterPage->setPropertyValue("Theme", aTheme); -} - -uno::Reference<xml::sax::XFastContextHandler> SAL_CALL XMLThemeContext::createFastChildContext( - sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& xAttribs) -{ - if (nElement == XML_ELEMENT(LO_EXT, XML_COLOR_TABLE)) - { - return new XMLColorTableContext(GetImport(), xAttribs, m_aTheme); - } - - return nullptr; -} - -XMLColorTableContext::XMLColorTableContext( - SvXMLImport& rImport, const uno::Reference<xml::sax::XFastAttributeList>& xAttrList, - comphelper::SequenceAsHashMap& rTheme) - : SvXMLImportContext(rImport) - , m_rTheme(rTheme) -{ - for (const auto& rAttribute : sax_fastparser::castToFastAttributeList(xAttrList)) - { - switch (rAttribute.getToken()) - { - case XML_ELEMENT(LO_EXT, XML_NAME): - { - m_rTheme["ColorSchemeName"] <<= rAttribute.toString(); - break; - } - } - } -} - -XMLColorTableContext::~XMLColorTableContext() -{ - m_rTheme["ColorScheme"] <<= comphelper::containerToSequence(m_aColorScheme); -} - -uno::Reference<xml::sax::XFastContextHandler> SAL_CALL XMLColorTableContext::createFastChildContext( - sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& xAttribs) -{ - if (nElement == XML_ELEMENT(LO_EXT, XML_COLOR)) - { - return new XMLColorContext(GetImport(), xAttribs, m_aColorScheme); - } - - return nullptr; -} - -XMLColorContext::XMLColorContext(SvXMLImport& rImport, - const uno::Reference<xml::sax::XFastAttributeList>& xAttrList, - std::vector<util::Color>& rColorScheme) - : SvXMLImportContext(rImport) -{ - for (const auto& rAttribute : sax_fastparser::castToFastAttributeList(xAttrList)) - { - switch (rAttribute.getToken()) - { - case XML_ELEMENT(LO_EXT, XML_COLOR): - { - util::Color nColor; - sax::Converter::convertColor(nColor, rAttribute.toView()); - rColorScheme.push_back(nColor); - break; - } - } - } -} - namespace xmloff { bool IsIgnoreFillStyleNamedItem( diff --git a/xmloff/source/style/XMLThemeContext.cxx b/xmloff/source/style/XMLThemeContext.cxx new file mode 100644 index 000000000000..41602665a06b --- /dev/null +++ b/xmloff/source/style/XMLThemeContext.cxx @@ -0,0 +1,123 @@ +/* -*- 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 <XMLThemeContext.hxx> + +#include <xmloff/maptype.hxx> +#include <xmloff/xmlnamespace.hxx> +#include <xmloff/xmltoken.hxx> +#include <xmloff/xmlprcon.hxx> +#include <xmloff/xmlerror.hxx> +#include <xmloff/namespacemap.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmlement.hxx> +#include <xmloff/xmlprhdl.hxx> + +#include <sal/log.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> + +#include <sax/tools/converter.hxx> +#include <comphelper/sequence.hxx> + +using namespace css; +using namespace xmloff::token; + +XMLThemeContext::XMLThemeContext(SvXMLImport& rImport, + const uno::Reference<xml::sax::XFastAttributeList>& xAttrList, + css::uno::Reference<css::drawing::XDrawPage> const& xPage) + : SvXMLImportContext(rImport) + , m_xPage(xPage) +{ + for (const auto& rAttribute : sax_fastparser::castToFastAttributeList(xAttrList)) + { + switch (rAttribute.getToken()) + { + case XML_ELEMENT(LO_EXT, XML_NAME): + { + m_aTheme["Name"] <<= rAttribute.toString(); + break; + } + } + } +} + +XMLThemeContext::~XMLThemeContext() +{ + uno::Any aTheme(m_aTheme.getAsConstPropertyValueList()); + uno::Reference<beans::XPropertySet> xPropertySet(m_xPage, uno::UNO_QUERY); + xPropertySet->setPropertyValue("Theme", aTheme); +} + +uno::Reference<xml::sax::XFastContextHandler> SAL_CALL XMLThemeContext::createFastChildContext( + sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& xAttribs) +{ + if (nElement == XML_ELEMENT(LO_EXT, XML_COLOR_TABLE)) + { + return new XMLColorTableContext(GetImport(), xAttribs, m_aTheme); + } + + return nullptr; +} + +XMLColorTableContext::XMLColorTableContext( + SvXMLImport& rImport, const uno::Reference<xml::sax::XFastAttributeList>& xAttrList, + comphelper::SequenceAsHashMap& rTheme) + : SvXMLImportContext(rImport) + , m_rTheme(rTheme) +{ + for (const auto& rAttribute : sax_fastparser::castToFastAttributeList(xAttrList)) + { + switch (rAttribute.getToken()) + { + case XML_ELEMENT(LO_EXT, XML_NAME): + { + m_rTheme["ColorSchemeName"] <<= rAttribute.toString(); + break; + } + } + } +} + +XMLColorTableContext::~XMLColorTableContext() +{ + m_rTheme["ColorScheme"] <<= comphelper::containerToSequence(m_aColorScheme); +} + +uno::Reference<xml::sax::XFastContextHandler> SAL_CALL XMLColorTableContext::createFastChildContext( + sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& xAttribs) +{ + if (nElement == XML_ELEMENT(LO_EXT, XML_COLOR)) + { + return new XMLColorContext(GetImport(), xAttribs, m_aColorScheme); + } + + return nullptr; +} + +XMLColorContext::XMLColorContext(SvXMLImport& rImport, + const uno::Reference<xml::sax::XFastAttributeList>& xAttrList, + std::vector<util::Color>& rColorScheme) + : SvXMLImportContext(rImport) +{ + for (const auto& rAttribute : sax_fastparser::castToFastAttributeList(xAttrList)) + { + switch (rAttribute.getToken()) + { + case XML_ELEMENT(LO_EXT, XML_COLOR): + { + util::Color nColor; + sax::Converter::convertColor(nColor, rAttribute.toView()); + rColorScheme.push_back(nColor); + break; + } + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit b09436929a8a2c8671939fac7b8b0c23cc5d3967 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Fri Jan 27 12:13:29 2023 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Fri Feb 17 05:23:19 2023 +0000 introduce XTheme and UnoTheme implementation Needed to transprt model::Theme around using throught UNO API as xmloff can't access SdrPage directly. Change-Id: I5931e42352186d62e7f09b112d8e8c9e4fb79440 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146224 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit 312f83bcf52d2f681eb9fa1bbdbb98bfd063a3b4) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146447 Tested-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/docmodel/Library_docmodel.mk b/docmodel/Library_docmodel.mk index 7974027a7a9e..8db7d0fa6f93 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/uno/UnoTheme \ docmodel/source/theme/ColorSet \ docmodel/source/theme/Theme \ )) diff --git a/docmodel/source/theme/Theme.cxx b/docmodel/source/theme/Theme.cxx index 0f8ff8002870..5f755b0774a3 100644 --- a/docmodel/source/theme/Theme.cxx +++ b/docmodel/source/theme/Theme.cxx @@ -29,6 +29,13 @@ Theme::Theme(OUString const& rName) { } +Theme::Theme(Theme const& rTheme) + : maName(rTheme.maName) + , mpColorSet(new ColorSet(*rTheme.GetColorSet())) + , maFontScheme(rTheme.maFontScheme) +{ +} + void Theme::SetColorSet(std::unique_ptr<model::ColorSet> pColorSet) { mpColorSet = std::move(pColorSet); diff --git a/docmodel/source/uno/UnoTheme.cxx b/docmodel/source/uno/UnoTheme.cxx new file mode 100644 index 000000000000..80d2735be47b --- /dev/null +++ b/docmodel/source/uno/UnoTheme.cxx @@ -0,0 +1,50 @@ +/* -*- 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/uno/UnoTheme.hxx> +#include <docmodel/theme/ThemeColorType.hxx> +#include <cppuhelper/queryinterface.hxx> +#include <o3tl/enumrange.hxx> +#include <comphelper/sequence.hxx> + +using namespace css; + +OUString UnoTheme::getName() { return maTheme.GetName(); } + +css::uno::Sequence<sal_Int32> UnoTheme::getColorSet() +{ + std::vector<sal_Int32> aColorScheme(12); + auto* pColorSet = maTheme.GetColorSet(); + if (pColorSet) + { + size_t i = 0; + + for (auto eThemeColorType : o3tl::enumrange<model::ThemeColorType>()) + { + if (eThemeColorType == model::ThemeColorType::Unknown) + continue; + Color aColor = pColorSet->getColor(eThemeColorType); + aColorScheme[i] = sal_Int32(aColor); + i++; + } + } + return comphelper::containerToSequence(aColorScheme); +} + +namespace model::theme +{ +uno::Reference<util::XTheme> createXTheme(model::Theme const& rTheme) +{ + return new UnoTheme(rTheme); +} + +} // end model::theme + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/docmodel/theme/Theme.hxx b/include/docmodel/theme/Theme.hxx index 1f6a91762964..6ef239fc7578 100644 --- a/include/docmodel/theme/Theme.hxx +++ b/include/docmodel/theme/Theme.hxx @@ -136,6 +136,8 @@ private: public: Theme(OUString const& rName); + Theme(Theme const& rTheme); + void setFontScheme(FontScheme const& rFontScheme) { maFontScheme = rFontScheme; } FontScheme const& getFontScheme() const { return maFontScheme; } diff --git a/include/docmodel/uno/UnoTheme.hxx b/include/docmodel/uno/UnoTheme.hxx new file mode 100644 index 000000000000..f1abc4ccaede --- /dev/null +++ b/include/docmodel/uno/UnoTheme.hxx @@ -0,0 +1,46 @@ +/* -*- 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 <cppuhelper/implbase.hxx> +#include <cppuhelper/supportsservice.hxx> +#include <comphelper/servicehelper.hxx> + +#include <com/sun/star/util/Color.hpp> +#include <com/sun/star/util/XTheme.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +#include <utility> +#include <docmodel/dllapi.h> +#include <docmodel/theme/Theme.hxx> + +class DOCMODEL_DLLPUBLIC UnoTheme final : public cppu::WeakImplHelper<css::util::XTheme> +{ +private: + model::Theme maTheme; + +public: + UnoTheme(model::Theme const& rTheme) + : maTheme(rTheme) + { + } + + model::Theme const& getTheme() const { return maTheme; } + + // XTheme + OUString SAL_CALL getName() override; + css::uno::Sequence<sal_Int32> SAL_CALL getColorSet() override; +}; + +namespace model::theme +{ +DOCMODEL_DLLPUBLIC css::uno::Reference<css::util::XTheme> createXTheme(model::Theme const& rTheme); +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk index 6bd7f932831c..494256b29f78 100644 --- a/offapi/UnoApi_offapi.mk +++ b/offapi/UnoApi_offapi.mk @@ -4174,6 +4174,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/util,\ XCloseBroadcaster \ XCloseListener \ XCloseable \ + XTheme \ XThemeColor \ XDataEditor \ XDataEditorListener \ diff --git a/offapi/com/sun/star/util/XTheme.idl b/offapi/com/sun/star/util/XTheme.idl new file mode 100644 index 000000000000..0efa1847aaed --- /dev/null +++ b/offapi/com/sun/star/util/XTheme.idl @@ -0,0 +1,34 @@ +/* -*- 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/. + */ + +module com { module sun { module star { module util { + +/** Theme interface + + @since LibreOffice 7.6 +*/ +interface XTheme +{ + /** Get the name of the theme */ + string getName(); + + /** Get the color set defined for the theme. + + The color set is a sequence of 12 colors: + Dark 1, Light 1, Dark 2, Light 2, + Accent 1, Accent 2, Accent 3, Accent 4, Accent 5, Accent6, + Hyperlink, FollowedHyperlink + + */ + sequence<com::sun::star::util::Color> getColorSet(); +}; + +}; }; }; }; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */