LibreOffice Module svx (master) 1
ThemeColorChanger.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
11
12#include <sal/config.h>
13#include <svx/svdpage.hxx>
14#include <svx/svditer.hxx>
15#include <editeng/unoprnms.hxx>
18
19#include <com/sun/star/text/XTextRange.hpp>
20#include <com/sun/star/container/XEnumerationAccess.hpp>
21#include <com/sun/star/container/XEnumeration.hpp>
22#include <com/sun/star/beans/XPropertySet.hpp>
23#include <com/sun/star/util/XComplexColor.hpp>
24
25using namespace css;
26
27namespace svx
28{
29namespace theme
30{
31namespace
32{
34void updateTextPortionColorSet(model::ColorSet const& rColorSet,
35 const uno::Reference<beans::XPropertySet>& xPortion)
36{
37 if (!xPortion->getPropertySetInfo()->hasPropertyByName(UNO_NAME_EDIT_CHAR_COMPLEX_COLOR))
38 {
39 return;
40 }
41
42 uno::Reference<util::XComplexColor> xComplexColor;
43 xPortion->getPropertyValue(UNO_NAME_EDIT_CHAR_COMPLEX_COLOR) >>= xComplexColor;
44 if (!xComplexColor.is())
45 return;
46
47 auto aComplexColor = model::color::getFromXComplexColor(xComplexColor);
48
49 if (aComplexColor.getSchemeType() == model::ThemeColorType::Unknown)
50 return;
51
52 Color aColor = rColorSet.resolveColor(aComplexColor);
53 xPortion->setPropertyValue(UNO_NAME_EDIT_CHAR_COLOR, uno::Any(static_cast<sal_Int32>(aColor)));
54}
55
57void updateFillColorSet(model::ColorSet const& rColorSet,
58 const uno::Reference<beans::XPropertySet>& xShape)
59{
60 if (!xShape->getPropertySetInfo()->hasPropertyByName(UNO_NAME_FILL_COMPLEX_COLOR))
61 return;
62
63 uno::Reference<util::XComplexColor> xComplexColor;
64 xShape->getPropertyValue(UNO_NAME_FILL_COMPLEX_COLOR) >>= xComplexColor;
65 if (!xComplexColor.is())
66 return;
67
68 auto aComplexColor = model::color::getFromXComplexColor(xComplexColor);
69
70 if (aComplexColor.getSchemeType() == model::ThemeColorType::Unknown)
71 return;
72
73 Color aColor = rColorSet.resolveColor(aComplexColor);
74 xShape->setPropertyValue(UNO_NAME_FILLCOLOR, uno::Any(static_cast<sal_Int32>(aColor)));
75}
76
78void updateLineColorSet(model::ColorSet const& rColorSet,
79 const uno::Reference<beans::XPropertySet>& xShape)
80{
81 if (!xShape->getPropertySetInfo()->hasPropertyByName(UNO_NAME_LINE_COMPLEX_COLOR))
82 return;
83
84 uno::Reference<util::XComplexColor> xComplexColor;
85 xShape->getPropertyValue(UNO_NAME_LINE_COMPLEX_COLOR) >>= xComplexColor;
86 if (!xComplexColor.is())
87 return;
88
89 auto aComplexColor = model::color::getFromXComplexColor(xComplexColor);
90
91 if (aComplexColor.getSchemeType() == model::ThemeColorType::Unknown)
92 return;
93
94 Color aColor = rColorSet.resolveColor(aComplexColor);
95 xShape->setPropertyValue(UNO_NAME_LINECOLOR, uno::Any(static_cast<sal_Int32>(aColor)));
96}
97
98} // end anonymous namespace
99
101void updateSdrObject(model::ColorSet const& rColorSet, SdrObject* pObject)
102{
103 uno::Reference<drawing::XShape> xShape = pObject->getUnoShape();
104 uno::Reference<text::XTextRange> xShapeText(xShape, uno::UNO_QUERY);
105 if (xShapeText.is())
106 {
107 // E.g. group shapes have no text.
108 uno::Reference<container::XEnumerationAccess> xText(xShapeText->getText(), uno::UNO_QUERY);
109 uno::Reference<container::XEnumeration> xParagraphs = xText->createEnumeration();
110 while (xParagraphs->hasMoreElements())
111 {
112 uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(),
113 uno::UNO_QUERY);
114 uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration();
115 while (xPortions->hasMoreElements())
116 {
117 uno::Reference<beans::XPropertySet> xPortion(xPortions->nextElement(),
118 uno::UNO_QUERY);
119 updateTextPortionColorSet(rColorSet, xPortion);
120 }
121 }
122 }
123
124 uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
125 updateFillColorSet(rColorSet, xShapeProps);
126 updateLineColorSet(rColorSet, xShapeProps);
127}
128
129} // end theme
130
132 : mpPage(pPage)
133{
134}
135
137
138void ThemeColorChanger::apply(std::shared_ptr<model::ColorSet> const& pColorSet)
139{
140 for (size_t nObject = 0; nObject < mpPage->GetObjCount(); ++nObject)
141 {
142 SdrObject* pObject = mpPage->GetObj(nObject);
143 theme::updateSdrObject(*pColorSet, pObject);
144
145 // update child objects
146 SdrObjList* pList = pObject->GetSubList();
147 if (pList)
148 {
150 while (aIter.IsMore())
151 {
152 theme::updateSdrObject(*pColorSet, aIter.Next());
153 }
154 }
155 }
156}
157
158} // end svx namespace
159
160/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FPDF_PAGE mpPage
SdrObject * Next()
Definition: svditer.hxx:63
bool IsMore() const
Definition: svditer.hxx:62
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:785
size_t GetObjCount() const
Definition: svdpage.cxx:779
Abstract DrawObject.
Definition: svdobj.hxx:260
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:379
Color resolveColor(model::ComplexColor const &rComplexColor) const
virtual ~ThemeColorChanger() override
ThemeColorChanger(SdrPage *pPage)
void apply(std::shared_ptr< model::ColorSet > const &pColorSet) override
EmbeddedObjectRef * pObject
model::ComplexColor getFromXComplexColor(uno::Reference< util::XComplexColor > const &rxColor)
void updateSdrObject(model::ColorSet const &rColorSet, SdrObject *pObject)
Updates properties of the SdrObject.
constexpr OUStringLiteral UNO_NAME_FILLCOLOR
constexpr OUStringLiteral UNO_NAME_LINE_COMPLEX_COLOR
constexpr OUStringLiteral UNO_NAME_EDIT_CHAR_COMPLEX_COLOR
constexpr OUStringLiteral UNO_NAME_EDIT_CHAR_COLOR
constexpr OUStringLiteral UNO_NAME_LINECOLOR
constexpr OUStringLiteral UNO_NAME_FILL_COMPLEX_COLOR