LibreOffice Module xmloff (master) 1
XMLThemeContext.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10#include <XMLThemeContext.hxx>
11
12#include <xmloff/maptype.hxx>
14#include <xmloff/xmltoken.hxx>
15#include <xmloff/xmlprcon.hxx>
16#include <xmloff/xmlerror.hxx>
18#include <xmloff/xmlimp.hxx>
19#include <xmloff/xmlement.hxx>
20#include <xmloff/xmlprhdl.hxx>
21
22#include <sal/log.hxx>
23#include <com/sun/star/beans/XPropertySet.hpp>
24
27
30
31using namespace css;
32using namespace xmloff::token;
33
35 const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
36 css::uno::Reference<css::drawing::XDrawPage> const& xPage)
37 : SvXMLImportContext(rImport)
38 , m_xPage(xPage)
39 , mpTheme(new model::Theme)
40{
41 for (const auto& rAttribute : sax_fastparser::castToFastAttributeList(xAttrList))
42 {
43 switch (rAttribute.getToken())
44 {
45 case XML_ELEMENT(LO_EXT, XML_NAME):
46 {
47 OUString aName = rAttribute.toString();
48 mpTheme->SetName(aName);
49 break;
50 }
51 }
52 }
53}
54
56{
57 if (mpTheme && mpTheme->getColorSet())
58 {
59 uno::Reference<beans::XPropertySet> xPropertySet(m_xPage, uno::UNO_QUERY);
61 xPropertySet->setPropertyValue("Theme", uno::Any(xTheme));
62 }
63}
64
65uno::Reference<xml::sax::XFastContextHandler> SAL_CALL XMLThemeContext::createFastChildContext(
66 sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& xAttribs)
67{
68 if (nElement == XML_ELEMENT(LO_EXT, XML_THEME_COLORS))
69 {
70 return new XMLThemeColorsContext(GetImport(), xAttribs, *mpTheme);
71 }
72
73 return nullptr;
74}
75
77 SvXMLImport& rImport, const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
78 model::Theme& rTheme)
79 : SvXMLImportContext(rImport)
80 , mrTheme(rTheme)
81{
82 for (const auto& rAttribute : sax_fastparser::castToFastAttributeList(xAttrList))
83 {
84 switch (rAttribute.getToken())
85 {
86 case XML_ELEMENT(LO_EXT, XML_NAME):
87 {
88 OUString aName = rAttribute.toString();
90 break;
91 }
92 }
93 }
94}
95
97{
98 if (m_pColorSet)
100}
101
102uno::Reference<xml::sax::XFastContextHandler>
104 sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& xAttribs)
105{
106 if (nElement == XML_ELEMENT(LO_EXT, XML_COLOR))
107 {
108 if (m_pColorSet)
109 return new XMLColorContext(GetImport(), xAttribs, m_pColorSet);
110 }
111
112 return nullptr;
113}
114
116 const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
117 std::shared_ptr<model::ColorSet>& rpColorSet)
118 : SvXMLImportContext(rImport)
119{
120 OUString aName;
121 ::Color aColor;
122
123 for (const auto& rAttribute : sax_fastparser::castToFastAttributeList(xAttrList))
124 {
125 switch (rAttribute.getToken())
126 {
127 case XML_ELEMENT(LO_EXT, XML_NAME):
128 {
129 aName = rAttribute.toString();
130 break;
131 }
132 case XML_ELEMENT(LO_EXT, XML_COLOR):
133 {
134 sax::Converter::convertColor(aColor, rAttribute.toView());
135 break;
136 }
137 }
138 }
139
140 if (!aName.isEmpty())
141 {
143 if (aName == u"dark1")
145 else if (aName == u"light1")
147 else if (aName == u"dark2")
149 else if (aName == u"light2")
151 else if (aName == u"accent1")
153 else if (aName == u"accent2")
155 else if (aName == u"accent3")
157 else if (aName == u"accent4")
159 else if (aName == u"accent5")
161 else if (aName == u"accent6")
163 else if (aName == u"hyperlink")
165 else if (aName == u"followed-hyperlink")
167
169 {
170 rpColorSet->add(eType, aColor);
171 }
172 }
173}
174
175/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
Imports a color for a color table.
XMLColorContext(SvXMLImport &rImport, css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttrList, std::shared_ptr< model::ColorSet > &rpColorSet)
Imports the theme colors of a theme.
XMLThemeColorsContext(SvXMLImport &rImport, css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttrList, model::Theme &mrTheme)
std::shared_ptr< model::ColorSet > m_pColorSet
css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttribs) override
XMLThemeContext(SvXMLImport &rImport, css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttrList, css::uno::Reference< css::drawing::XDrawPage > const &xPage)
std::shared_ptr< model::Theme > mpTheme
css::uno::Reference< css::drawing::XDrawPage > m_xPage
css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttribs) override
void setColorSet(std::shared_ptr< model::ColorSet > const &pColorSet)
static bool convertColor(sal_Int32 &rColor, std::u16string_view rValue)
float u
DocumentType eType
OUString aName
uno::Reference< util::XTheme > createXTheme(std::shared_ptr< model::Theme > const &pTheme)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
model::Theme & mrTheme
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97