1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include <svx/theme/ThemeColorChanger.hxx>
12 #include <sal/config.h>
13 #include <svx/svdpage.hxx>
14 #include <svx/svditer.hxx>
15 #include <editeng/unoprnms.hxx>
16 #include <docmodel/uno/UnoComplexColor.hxx>
17 #include <docmodel/theme/ColorSet.hxx>
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>
33 /// Updates text portion property colors
34 void updateTextPortionColorSet(model::ColorSet
const& rColorSet
,
35 const uno::Reference
<beans::XPropertySet
>& xPortion
)
37 if (!xPortion
->getPropertySetInfo()->hasPropertyByName(UNO_NAME_EDIT_CHAR_COMPLEX_COLOR
))
42 uno::Reference
<util::XComplexColor
> xComplexColor
;
43 xPortion
->getPropertyValue(UNO_NAME_EDIT_CHAR_COMPLEX_COLOR
) >>= xComplexColor
;
44 if (!xComplexColor
.is())
47 auto aComplexColor
= model::color::getFromXComplexColor(xComplexColor
);
49 if (aComplexColor
.getSchemeType() == model::ThemeColorType::Unknown
)
52 Color aColor
= rColorSet
.resolveColor(aComplexColor
);
53 xPortion
->setPropertyValue(UNO_NAME_EDIT_CHAR_COLOR
, uno::Any(static_cast<sal_Int32
>(aColor
)));
56 /// Updates the fill property colors
57 void updateFillColorSet(model::ColorSet
const& rColorSet
,
58 const uno::Reference
<beans::XPropertySet
>& xShape
)
60 if (!xShape
->getPropertySetInfo()->hasPropertyByName(UNO_NAME_FILL_COMPLEX_COLOR
))
63 uno::Reference
<util::XComplexColor
> xComplexColor
;
64 xShape
->getPropertyValue(UNO_NAME_FILL_COMPLEX_COLOR
) >>= xComplexColor
;
65 if (!xComplexColor
.is())
68 auto aComplexColor
= model::color::getFromXComplexColor(xComplexColor
);
70 if (aComplexColor
.getSchemeType() == model::ThemeColorType::Unknown
)
73 Color aColor
= rColorSet
.resolveColor(aComplexColor
);
74 xShape
->setPropertyValue(UNO_NAME_FILLCOLOR
, uno::Any(static_cast<sal_Int32
>(aColor
)));
77 /// Updates the line property colors
78 void updateLineColorSet(model::ColorSet
const& rColorSet
,
79 const uno::Reference
<beans::XPropertySet
>& xShape
)
81 if (!xShape
->getPropertySetInfo()->hasPropertyByName(UNO_NAME_LINE_COMPLEX_COLOR
))
84 uno::Reference
<util::XComplexColor
> xComplexColor
;
85 xShape
->getPropertyValue(UNO_NAME_LINE_COMPLEX_COLOR
) >>= xComplexColor
;
86 if (!xComplexColor
.is())
89 auto aComplexColor
= model::color::getFromXComplexColor(xComplexColor
);
91 if (aComplexColor
.getSchemeType() == model::ThemeColorType::Unknown
)
94 Color aColor
= rColorSet
.resolveColor(aComplexColor
);
95 xShape
->setPropertyValue(UNO_NAME_LINECOLOR
, uno::Any(static_cast<sal_Int32
>(aColor
)));
98 } // end anonymous namespace
100 /// Updates properties of the SdrObject
101 void updateSdrObject(model::ColorSet
const& rColorSet
, SdrObject
* pObject
)
103 uno::Reference
<drawing::XShape
> xShape
= pObject
->getUnoShape();
104 uno::Reference
<text::XTextRange
> xShapeText(xShape
, uno::UNO_QUERY
);
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())
112 uno::Reference
<container::XEnumerationAccess
> xParagraph(xParagraphs
->nextElement(),
114 uno::Reference
<container::XEnumeration
> xPortions
= xParagraph
->createEnumeration();
115 while (xPortions
->hasMoreElements())
117 uno::Reference
<beans::XPropertySet
> xPortion(xPortions
->nextElement(),
119 updateTextPortionColorSet(rColorSet
, xPortion
);
124 uno::Reference
<beans::XPropertySet
> xShapeProps(xShape
, uno::UNO_QUERY
);
125 updateFillColorSet(rColorSet
, xShapeProps
);
126 updateLineColorSet(rColorSet
, xShapeProps
);
131 ThemeColorChanger::ThemeColorChanger(SdrPage
* pPage
)
136 ThemeColorChanger::~ThemeColorChanger() = default;
138 void ThemeColorChanger::apply(std::shared_ptr
<model::ColorSet
> const& pColorSet
)
140 for (size_t nObject
= 0; nObject
< mpPage
->GetObjCount(); ++nObject
)
142 SdrObject
* pObject
= mpPage
->GetObj(nObject
);
143 theme::updateSdrObject(*pColorSet
, pObject
);
145 // update child objects
146 SdrObjList
* pList
= pObject
->GetSubList();
149 SdrObjListIter
aIter(pList
, SdrIterMode::DeepWithGroups
);
150 while (aIter
.IsMore())
152 theme::updateSdrObject(*pColorSet
, aIter
.Next());
158 } // end svx namespace
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */