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
29
30using namespace css;
31using namespace xmloff::token;
32
34 const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
35 css::uno::Reference<css::drawing::XDrawPage> const& xPage)
36 : SvXMLImportContext(rImport)
37 , m_xPage(xPage)
38{
39 for (const auto& rAttribute : sax_fastparser::castToFastAttributeList(xAttrList))
40 {
41 switch (rAttribute.getToken())
42 {
43 case XML_ELEMENT(LO_EXT, XML_NAME):
44 {
45 OUString aName = rAttribute.toString();
47 break;
48 }
49 }
50 }
51}
52
54{
55 uno::Reference<beans::XPropertySet> xPropertySet(m_xPage, uno::UNO_QUERY);
56 uno::Reference<util::XTheme> xTheme(new UnoTheme(maTheme));
57 xPropertySet->setPropertyValue("Theme", uno::Any(xTheme));
58}
59
60uno::Reference<xml::sax::XFastContextHandler> SAL_CALL XMLThemeContext::createFastChildContext(
61 sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& xAttribs)
62{
63 if (nElement == XML_ELEMENT(LO_EXT, XML_COLOR_TABLE))
64 {
65 return new XMLColorTableContext(GetImport(), xAttribs, maTheme);
66 }
67
68 return nullptr;
69}
70
72 SvXMLImport& rImport, const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
73 model::Theme& rTheme)
74 : SvXMLImportContext(rImport)
75 , mrTheme(rTheme)
76{
77 for (const auto& rAttribute : sax_fastparser::castToFastAttributeList(xAttrList))
78 {
79 switch (rAttribute.getToken())
80 {
81 case XML_ELEMENT(LO_EXT, XML_NAME):
82 {
83 OUString aName = rAttribute.toString();
85 break;
86 }
87 }
88 }
89}
90
92{
93 if (mpColorSet)
94 mrTheme.SetColorSet(std::move(mpColorSet));
95}
96
97uno::Reference<xml::sax::XFastContextHandler> SAL_CALL XMLColorTableContext::createFastChildContext(
98 sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& xAttribs)
99{
100 if (nElement == XML_ELEMENT(LO_EXT, XML_COLOR))
101 {
102 if (mpColorSet)
103 return new XMLColorContext(GetImport(), xAttribs, mpColorSet);
104 }
105
106 return nullptr;
107}
108
110 const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
111 std::unique_ptr<model::ColorSet>& rpColorSet)
112 : SvXMLImportContext(rImport)
113{
114 OUString aName;
115 ::Color aColor;
116
117 for (const auto& rAttribute : sax_fastparser::castToFastAttributeList(xAttrList))
118 {
119 switch (rAttribute.getToken())
120 {
121 case XML_ELEMENT(LO_EXT, XML_NAME):
122 {
123 aName = rAttribute.toString();
124 break;
125 }
126 case XML_ELEMENT(LO_EXT, XML_COLOR):
127 {
128 sax::Converter::convertColor(aColor, rAttribute.toView());
129 break;
130 }
131 }
132 }
133
134 if (!aName.isEmpty())
135 {
137 if (aName == u"dk1")
139 else if (aName == u"lt1")
141 else if (aName == u"dk2")
143 else if (aName == u"lt2")
145 else if (aName == u"accent1")
147 else if (aName == u"accent2")
149 else if (aName == u"accent3")
151 else if (aName == u"accent4")
153 else if (aName == u"accent5")
155 else if (aName == u"accent6")
157 else if (aName == u"hlink")
159 else if (aName == u"folHlink")
161
163 {
164 rpColorSet->add(eType, aColor);
165 }
166 }
167}
168
169/* 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::unique_ptr< model::ColorSet > &rpColorSet)
Imports the color table of a theme.
model::Theme & mrTheme
std::unique_ptr< model::ColorSet > mpColorSet
css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttribs) override
XMLColorTableContext(SvXMLImport &rImport, css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttrList, model::Theme &mrTheme)
XMLThemeContext(SvXMLImport &rImport, css::uno::Reference< css::xml::sax::XFastAttributeList > const &xAttrList, css::uno::Reference< css::drawing::XDrawPage > const &xPage)
model::Theme maTheme
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::unique_ptr< ColorSet > pColorSet)
void SetName(const OUString &rName)
static bool convertColor(sal_Int32 &rColor, std::u16string_view rValue)
float u
DocumentType eType
OUString aName
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