calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / docmodel / source / theme / Theme.cxx
blobd4095eeb3ebda5d9031b32986160684c9e10ffaa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 */
11 #include <docmodel/theme/Theme.hxx>
13 #include <utility>
14 #include <libxml/xmlwriter.h>
15 #include <comphelper/sequenceashashmap.hxx>
16 #include <comphelper/sequence.hxx>
17 #include <sal/log.hxx>
18 #include <sal/types.h>
19 #include <o3tl/enumrange.hxx>
20 #include <com/sun/star/util/Color.hpp>
21 #include <com/sun/star/beans/PropertyValue.hpp>
23 using namespace com::sun::star;
25 namespace model
27 Theme::Theme() = default;
29 Theme::Theme(OUString const& rName)
30 : maName(rName)
34 Theme::Theme(Theme const& rTheme)
35 : maName(rTheme.maName)
36 , mpColorSet(new ColorSet(*rTheme.getColorSet()))
37 , maFontScheme(rTheme.maFontScheme)
41 void Theme::SetName(const OUString& rName) { maName = rName; }
43 const OUString& Theme::GetName() const { return maName; }
45 void Theme::dumpAsXml(xmlTextWriterPtr pWriter) const
47 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("Theme"));
48 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
49 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("maName"),
50 BAD_CAST(maName.toUtf8().getStr()));
52 if (mpColorSet)
54 mpColorSet->dumpAsXml(pWriter);
57 (void)xmlTextWriterEndElement(pWriter);
60 void Theme::ToAny(uno::Any& rVal) const
62 comphelper::SequenceAsHashMap aMap;
63 aMap["Name"] <<= maName;
65 if (mpColorSet)
67 std::vector<util::Color> aColorScheme;
68 for (auto eThemeColorType : o3tl::enumrange<model::ThemeColorType>())
70 if (eThemeColorType != model::ThemeColorType::Unknown)
72 Color aColor = mpColorSet->getColor(eThemeColorType);
73 aColorScheme.push_back(sal_Int32(aColor));
77 aMap["ColorSchemeName"] <<= mpColorSet->getName();
78 aMap["ColorScheme"] <<= comphelper::containerToSequence(aColorScheme);
81 rVal <<= aMap.getAsConstPropertyValueList();
84 std::unique_ptr<Theme> Theme::FromAny(const uno::Any& rVal)
86 comphelper::SequenceAsHashMap aMap(rVal);
87 std::unique_ptr<Theme> pTheme;
88 std::shared_ptr<model::ColorSet> pColorSet;
90 auto it = aMap.find("Name");
91 if (it != aMap.end())
93 OUString aName;
94 it->second >>= aName;
95 pTheme = std::make_unique<Theme>(aName);
98 it = aMap.find("ColorSchemeName");
99 if (it != aMap.end() && pTheme)
101 OUString aName;
102 it->second >>= aName;
103 pColorSet = std::make_shared<model::ColorSet>(aName);
104 pTheme->setColorSet(pColorSet);
107 it = aMap.find("ColorScheme");
108 if (it != aMap.end() && pColorSet)
110 uno::Sequence<util::Color> aColors;
111 it->second >>= aColors;
113 SAL_WARN_IF(aColors.size() > 12, "svx",
114 "Theme::FromAny: number of colors greater than max theme colors supported");
116 for (auto eThemeColorType : o3tl::enumrange<model::ThemeColorType>())
118 if (eThemeColorType != model::ThemeColorType::Unknown)
120 size_t nIndex(static_cast<sal_Int16>(eThemeColorType));
121 if (nIndex < aColors.size())
123 Color aColor(ColorTransparency, aColors[nIndex]);
124 pColorSet->add(eThemeColorType, aColor);
130 return pTheme;
133 std::vector<Color> Theme::GetColors() const
135 if (!mpColorSet)
136 return {};
138 std::vector<Color> aColors;
139 for (auto eThemeColorType : o3tl::enumrange<model::ThemeColorType>())
141 if (eThemeColorType != model::ThemeColorType::Unknown)
142 aColors.push_back(mpColorSet->getColor(eThemeColorType));
144 return aColors;
147 Color Theme::GetColor(model::ThemeColorType eType) const
149 if (!mpColorSet)
150 return {};
152 return mpColorSet->getColor(eType);
155 } // end of namespace model
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */