xref: /core/sw/source/uibase/sidebar/ThemePanel.cxx (revision 782f7c23af25187b9205e7ca036cb819834be2df)
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  */
10 
11 #include "ThemePanel.hxx"
12 #include <sal/config.h>
13 
14 #include <doc.hxx>
15 #include <docsh.hxx>
16 #include <drawdoc.hxx>
17 #include <IDocumentDrawModelAccess.hxx>
18 #include <ThemeColorChanger.hxx>
19 #include <vcl/settings.hxx>
20 #include <vcl/svapp.hxx>
21 #include <docmodel/theme/Theme.hxx>
22 #include <svx/svdpage.hxx>
23 #include <svx/dialog/ThemeColorValueSet.hxx>
24 #include <com/sun/star/lang/IllegalArgumentException.hpp>
25 
26 namespace sw::sidebar
27 {
28 
Create(weld::Widget * pParent)29 std::unique_ptr<PanelLayout> ThemePanel::Create(weld::Widget* pParent)
30 {
31     if (pParent == nullptr)
32         throw css::lang::IllegalArgumentException(u"no parent Window given to PagePropertyPanel::Create"_ustr, nullptr, 0);
33 
34     return std::make_unique<ThemePanel>(pParent);
35 }
36 
ThemePanel(weld::Widget * pParent)37 ThemePanel::ThemePanel(weld::Widget* pParent)
38     : PanelLayout(pParent, u"ThemePanel"_ustr, u"modules/swriter/ui/sidebartheme.ui"_ustr)
39     , mxValueSetColors(new svx::ThemeColorValueSet)
40     , mxValueSetColorsWin(new weld::CustomWeld(*m_xBuilder, u"valueset_colors"_ustr, *mxValueSetColors))
41     , mxApplyButton(m_xBuilder->weld_button(u"apply"_ustr))
42 {
43     mxValueSetColors->SetColCount(2);
44     mxValueSetColors->SetLineCount(3);
45     mxValueSetColors->SetColor(Application::GetSettings().GetStyleSettings().GetFaceColor());
46 
47     mxApplyButton->connect_clicked(LINK(this, ThemePanel, ClickHdl));
48     mxValueSetColors->SetDoubleClickHdl(LINK(this, ThemePanel, DoubleClickValueSetHdl));
49 
50     auto const& rColorSets = svx::ColorSets::get();
51     for (model::ColorSet const& rColorSet : rColorSets.getColorSetVector())
52     {
53         mxValueSetColors->insert(rColorSet);
54     }
55 
56     mxValueSetColors->SetOptimalSize();
57 
58     if (!rColorSets.getColorSetVector().empty())
59         mxValueSetColors->SelectItem(1); // ItemId 1, position 0
60 }
61 
~ThemePanel()62 ThemePanel::~ThemePanel()
63 {
64     mxValueSetColorsWin.reset();
65     mxValueSetColors.reset();
66     mxApplyButton.reset();
67 }
68 
IMPL_LINK_NOARG(ThemePanel,ClickHdl,weld::Button &,void)69 IMPL_LINK_NOARG(ThemePanel, ClickHdl, weld::Button&, void)
70 {
71     DoubleClickHdl();
72 }
73 
IMPL_LINK_NOARG(ThemePanel,DoubleClickValueSetHdl,ValueSet *,void)74 IMPL_LINK_NOARG(ThemePanel, DoubleClickValueSetHdl, ValueSet*, void)
75 {
76     DoubleClickHdl();
77 }
78 
IMPL_LINK_NOARG(ThemePanel,DoubleClickHdl,weld::TreeView &,bool)79 IMPL_LINK_NOARG(ThemePanel, DoubleClickHdl, weld::TreeView&, bool)
80 {
81     DoubleClickHdl();
82     return true;
83 }
84 
DoubleClickHdl()85 void ThemePanel::DoubleClickHdl()
86 {
87     SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current());
88     if (!pDocSh)
89         return;
90 
91     sal_uInt32 nItemId = mxValueSetColors->GetSelectedItemId();
92     if (!nItemId)
93         return;
94     sal_uInt32 nIndex = nItemId - 1;
95 
96     auto const& rColorSets = svx::ColorSets::get();
97     model::ColorSet const& rColorSet = rColorSets.getColorSet(nIndex);
98 
99     ThemeColorChanger aChanger(pDocSh);
100     aChanger.apply(std::make_shared<model::ColorSet>(rColorSet));
101 }
102 
NotifyItemUpdate(const sal_uInt16,const SfxItemState,const SfxPoolItem *)103 void ThemePanel::NotifyItemUpdate(const sal_uInt16 /*nSId*/,
104                                          const SfxItemState /*eState*/,
105                                          const SfxPoolItem* /*pState*/)
106 {
107 }
108 
109 } // end of namespace ::sw::sidebar
110 
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
112