bump product version to 7.6.3.2-android
[LibreOffice.git] / cui / source / tabpages / themepage.cxx
bloba7ea42801b1288eb8de862ab1917c5bc765762db
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
8 */
10 #include <sal/config.h>
12 #include <themepage.hxx>
14 #include <com/sun/star/beans/PropertyValues.hpp>
15 #include <com/sun/star/util/Color.hpp>
17 #include <comphelper/sequence.hxx>
18 #include <comphelper/sequenceashashmap.hxx>
19 #include <editeng/editids.hrc>
20 #include <sal/log.hxx>
21 #include <svl/grabbagitem.hxx>
22 #include <svx/colorbox.hxx>
24 using namespace com::sun::star;
26 const WhichRangesContainer
27 SvxThemePage::m_pRanges(svl::Items<SID_ATTR_CHAR_GRABBAG, SID_ATTR_CHAR_GRABBAG>);
29 SvxThemePage::SvxThemePage(weld::Container* pPage, weld::DialogController* pController,
30 const SfxItemSet& rInAttrs)
31 : SfxTabPage(pPage, pController, "cui/ui/themetabpage.ui", "ThemePage", &rInAttrs)
32 , m_xThemeName(m_xBuilder->weld_entry("themeName"))
33 , m_xColorSetName(m_xBuilder->weld_entry("colorSetName"))
34 , m_xDk1(new ColorListBox(m_xBuilder->weld_menu_button("btnDk1"),
35 [this] { return GetDialogController()->getDialog(); }))
36 , m_xLt1(new ColorListBox(m_xBuilder->weld_menu_button("btnLt1"),
37 [this] { return GetDialogController()->getDialog(); }))
38 , m_xDk2(new ColorListBox(m_xBuilder->weld_menu_button("btnDk2"),
39 [this] { return GetDialogController()->getDialog(); }))
40 , m_xLt2(new ColorListBox(m_xBuilder->weld_menu_button("btnLt2"),
41 [this] { return GetDialogController()->getDialog(); }))
42 , m_xAccent1(new ColorListBox(m_xBuilder->weld_menu_button("btnAccent1"),
43 [this] { return GetDialogController()->getDialog(); }))
44 , m_xAccent2(new ColorListBox(m_xBuilder->weld_menu_button("btnAccent2"),
45 [this] { return GetDialogController()->getDialog(); }))
46 , m_xAccent3(new ColorListBox(m_xBuilder->weld_menu_button("btnAccent3"),
47 [this] { return GetDialogController()->getDialog(); }))
48 , m_xAccent4(new ColorListBox(m_xBuilder->weld_menu_button("btnAccent4"),
49 [this] { return GetDialogController()->getDialog(); }))
50 , m_xAccent5(new ColorListBox(m_xBuilder->weld_menu_button("btnAccent5"),
51 [this] { return GetDialogController()->getDialog(); }))
52 , m_xAccent6(new ColorListBox(m_xBuilder->weld_menu_button("btnAccent6"),
53 [this] { return GetDialogController()->getDialog(); }))
54 , m_xHlink(new ColorListBox(m_xBuilder->weld_menu_button("btnHlink"),
55 [this] { return GetDialogController()->getDialog(); }))
56 , m_xFolHlink(new ColorListBox(m_xBuilder->weld_menu_button("btnFolHlink"),
57 [this] { return GetDialogController()->getDialog(); }))
61 SvxThemePage::~SvxThemePage() = default;
63 void SvxThemePage::Reset(const SfxItemSet* pAttrs)
65 const SfxGrabBagItem* pGrabBagItem = pAttrs->GetItemIfSet(SID_ATTR_CHAR_GRABBAG);
66 if (!pGrabBagItem)
68 SAL_WARN("cui.tabpages", "SvxThemePage::Reset: no SfxGrabBagItem");
69 return;
72 auto itTheme = pGrabBagItem->GetGrabBag().find("Theme");
73 if (itTheme == pGrabBagItem->GetGrabBag().end())
75 // No theme was defined previously, allow specifying colors.
76 m_xDk1->set_sensitive(true);
77 m_xLt1->set_sensitive(true);
78 m_xDk2->set_sensitive(true);
79 m_xLt2->set_sensitive(true);
80 m_xAccent1->set_sensitive(true);
81 m_xAccent2->set_sensitive(true);
82 m_xAccent3->set_sensitive(true);
83 m_xAccent4->set_sensitive(true);
84 m_xAccent5->set_sensitive(true);
85 m_xAccent6->set_sensitive(true);
86 m_xHlink->set_sensitive(true);
87 m_xFolHlink->set_sensitive(true);
88 return;
91 comphelper::SequenceAsHashMap aMap(itTheme->second);
92 auto it = aMap.find("Name");
93 if (it != aMap.end())
95 OUString aName;
96 it->second >>= aName;
97 m_xThemeName->set_text(aName);
100 it = aMap.find("ColorSchemeName");
101 if (it != aMap.end())
103 OUString aName;
104 it->second >>= aName;
105 m_xColorSetName->set_text(aName);
108 it = aMap.find("ColorScheme");
109 if (it != aMap.end())
111 uno::Sequence<util::Color> aColors;
112 it->second >>= aColors;
113 m_xDk1->SelectEntry(Color(ColorTransparency, aColors[0]));
114 m_xLt1->SelectEntry(Color(ColorTransparency, aColors[1]));
115 m_xDk2->SelectEntry(Color(ColorTransparency, aColors[2]));
116 m_xLt2->SelectEntry(Color(ColorTransparency, aColors[3]));
117 m_xAccent1->SelectEntry(Color(ColorTransparency, aColors[4]));
118 m_xAccent2->SelectEntry(Color(ColorTransparency, aColors[5]));
119 m_xAccent3->SelectEntry(Color(ColorTransparency, aColors[6]));
120 m_xAccent4->SelectEntry(Color(ColorTransparency, aColors[7]));
121 m_xAccent5->SelectEntry(Color(ColorTransparency, aColors[8]));
122 m_xAccent6->SelectEntry(Color(ColorTransparency, aColors[9]));
123 m_xHlink->SelectEntry(Color(ColorTransparency, aColors[10]));
124 m_xFolHlink->SelectEntry(Color(ColorTransparency, aColors[11]));
128 bool SvxThemePage::FillItemSet(SfxItemSet* pAttrs)
130 const SfxItemSet& rOldSet = GetItemSet();
132 if (!rOldSet.HasItem(SID_ATTR_CHAR_GRABBAG))
133 return true;
135 SfxGrabBagItem aGrabBagItem(rOldSet.Get(SID_ATTR_CHAR_GRABBAG));
137 comphelper::SequenceAsHashMap aMap;
138 auto it = aGrabBagItem.GetGrabBag().find("Theme");
139 if (it != aGrabBagItem.GetGrabBag().end())
141 aMap << it->second;
144 aMap["Name"] <<= m_xThemeName->get_text();
145 aMap["ColorSchemeName"] <<= m_xColorSetName->get_text();
146 std::vector<util::Color> aColorScheme = {
147 static_cast<sal_Int32>(m_xDk1->GetSelectEntryColor()),
148 static_cast<sal_Int32>(m_xLt1->GetSelectEntryColor()),
149 static_cast<sal_Int32>(m_xDk2->GetSelectEntryColor()),
150 static_cast<sal_Int32>(m_xLt2->GetSelectEntryColor()),
151 static_cast<sal_Int32>(m_xAccent1->GetSelectEntryColor()),
152 static_cast<sal_Int32>(m_xAccent2->GetSelectEntryColor()),
153 static_cast<sal_Int32>(m_xAccent3->GetSelectEntryColor()),
154 static_cast<sal_Int32>(m_xAccent4->GetSelectEntryColor()),
155 static_cast<sal_Int32>(m_xAccent5->GetSelectEntryColor()),
156 static_cast<sal_Int32>(m_xAccent6->GetSelectEntryColor()),
157 static_cast<sal_Int32>(m_xHlink->GetSelectEntryColor()),
158 static_cast<sal_Int32>(m_xFolHlink->GetSelectEntryColor()),
160 aMap["ColorScheme"] <<= comphelper::containerToSequence(aColorScheme);
162 beans::PropertyValues aTheme = aMap.getAsConstPropertyValueList();
163 aGrabBagItem.GetGrabBag()["Theme"] <<= aTheme;
164 pAttrs->Put(aGrabBagItem);
166 return true;
169 std::unique_ptr<SfxTabPage> SvxThemePage::Create(weld::Container* pPage,
170 weld::DialogController* pController,
171 const SfxItemSet* rAttrs)
173 return std::make_unique<SvxThemePage>(pPage, pController, *rAttrs);
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */