LibreOffice Module cui (master)  1
themepage.cxx
Go to the documentation of this file.
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.
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 <sal/config.h>
11 
12 #include <themepage.hxx>
13 
14 #include <com/sun/star/beans/PropertyValues.hpp>
15 #include <com/sun/star/util/Color.hpp>
16 
17 #include <comphelper/sequence.hxx>
19 #include <editeng/editids.hrc>
20 #include <sal/log.hxx>
21 #include <svl/grabbagitem.hxx>
22 #include <svx/colorbox.hxx>
23 
24 using namespace com::sun::star;
25 
27  SvxThemePage::m_pRanges(svl::Items<SID_ATTR_CHAR_GRABBAG, SID_ATTR_CHAR_GRABBAG>);
28 
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(); }))
58 {
59 }
60 
61 SvxThemePage::~SvxThemePage() = default;
62 
63 void SvxThemePage::Reset(const SfxItemSet* pAttrs)
64 {
65  const SfxGrabBagItem* pGrabBagItem = pAttrs->GetItemIfSet(SID_ATTR_CHAR_GRABBAG);
66  if (!pGrabBagItem)
67  {
68  SAL_WARN("cui.tabpages", "SvxThemePage::Reset: no SfxGrabBagItem");
69  return;
70  }
71 
72  auto itTheme = pGrabBagItem->GetGrabBag().find("Theme");
73  if (itTheme == pGrabBagItem->GetGrabBag().end())
74  {
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;
89  }
90 
91  comphelper::SequenceAsHashMap aMap(itTheme->second);
92  auto it = aMap.find("Name");
93  if (it != aMap.end())
94  {
95  OUString aName;
96  it->second >>= aName;
97  m_xThemeName->set_text(aName);
98  }
99 
100  it = aMap.find("ColorSchemeName");
101  if (it != aMap.end())
102  {
103  OUString aName;
104  it->second >>= aName;
105  m_xColorSetName->set_text(aName);
106  }
107 
108  it = aMap.find("ColorScheme");
109  if (it != aMap.end())
110  {
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]));
125  }
126 }
127 
129 {
130  const SfxItemSet& rOldSet = GetItemSet();
131 
132  if (!rOldSet.HasItem(SID_ATTR_CHAR_GRABBAG))
133  return true;
134 
135  SfxGrabBagItem aGrabBagItem(rOldSet.Get(SID_ATTR_CHAR_GRABBAG));
136 
138  auto it = aGrabBagItem.GetGrabBag().find("Theme");
139  if (it != aGrabBagItem.GetGrabBag().end())
140  {
141  aMap << it->second;
142  }
143 
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()),
159  };
160  aMap["ColorScheme"] <<= comphelper::containerToSequence(aColorScheme);
161 
162  beans::PropertyValues aTheme = aMap.getAsConstPropertyValueList();
163  aGrabBagItem.GetGrabBag()["Theme"] <<= aTheme;
164  pAttrs->Put(aGrabBagItem);
165 
166  return true;
167 }
168 
169 std::unique_ptr<SfxTabPage> SvxThemePage::Create(weld::Container* pPage,
170  weld::DialogController* pController,
171  const SfxItemSet* rAttrs)
172 {
173  return std::make_unique<SvxThemePage>(pPage, pController, *rAttrs);
174 }
175 
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
std::unique_ptr< ColorListBox > m_xHlink
Definition: themepage.hxx:37
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
std::unique_ptr< ColorListBox > m_xFolHlink
Definition: themepage.hxx:38
std::unique_ptr< ColorListBox > m_xAccent2
Definition: themepage.hxx:32
std::unique_ptr< weld::Entry > m_xColorSetName
Definition: themepage.hxx:26
std::unique_ptr< ColorListBox > m_xAccent5
Definition: themepage.hxx:35
std::unique_ptr< ColorListBox > m_xAccent3
Definition: themepage.hxx:33
virtual void Reset(const SfxItemSet *) override
Definition: themepage.cxx:63
HashMap_OWString_Interface aMap
std::unique_ptr< ColorListBox > m_xAccent1
Definition: themepage.hxx:31
static const WhichRangesContainer m_pRanges
Definition: themepage.hxx:23
std::unique_ptr< ColorListBox > m_xLt1
Definition: themepage.hxx:28
const SfxItemSet & GetItemSet() const
virtual bool FillItemSet(SfxItemSet *) override
Definition: themepage.cxx:128
std::unique_ptr< ColorListBox > m_xAccent6
Definition: themepage.hxx:36
const std::map< OUString, css::uno::Any > & GetGrabBag() const
ColorTransparency
virtual ~SvxThemePage() override
std::unique_ptr< ColorListBox > m_xLt2
Definition: themepage.hxx:30
std::unique_ptr< ColorListBox > m_xAccent4
Definition: themepage.hxx:34
std::unique_ptr< ColorListBox > m_xDk1
Definition: themepage.hxx:27
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: themepage.cxx:169
iterator find(const OUString &rKey)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
OUString aName
bool HasItem(sal_uInt16 nWhich, const SfxPoolItem **ppItem=nullptr) const
SfxOkDialogController * GetDialogController() const
std::unique_ptr< weld::Entry > m_xThemeName
Definition: themepage.hxx:25
#define SAL_WARN(area, stream)
std::unique_ptr< ColorListBox > m_xDk2
Definition: themepage.hxx:29
SvxThemePage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rInAttrs)
Definition: themepage.cxx:29