diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2023-01-24 14:25:50 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2023-01-24 10:50:20 +0000 |
commit | 5d135edd8843471f582a88f4e1a9a9b9fc0fd89b (patch) | |
tree | b25fa2668994d062ce0f3d4e5f9f13b2d9173263 /xmloff | |
parent | 06f98f94448fdf7b5dc3a55f45da8a27e5b212a8 (diff) |
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 <quikee@gmail.com>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/Library_xo.mk | 3 | ||||
-rw-r--r-- | xmloff/inc/XMLThemeContext.hxx | 63 | ||||
-rw-r--r-- | xmloff/source/draw/ximpstyl.cxx | 138 | ||||
-rw-r--r-- | xmloff/source/style/XMLThemeContext.cxx | 123 |
4 files changed, 191 insertions, 136 deletions
diff --git a/xmloff/Library_xo.mk b/xmloff/Library_xo.mk index 6a52570c6b9c..8a3fd112902d 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 \ @@ -250,6 +250,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: */ |