LibreOffice Module sw (master) 1
ThemePanel.cxx
Go to the documentation of this file.
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>
18#include <ThemeColorChanger.hxx>
19#include <vcl/settings.hxx>
20#include <vcl/svapp.hxx>
22#include <svx/svdpage.hxx>
24#include <com/sun/star/lang/IllegalArgumentException.hpp>
25
26namespace sw::sidebar
27{
28
29std::unique_ptr<PanelLayout> ThemePanel::Create(weld::Widget* pParent)
30{
31 if (pParent == nullptr)
32 throw css::lang::IllegalArgumentException("no parent Window given to PagePropertyPanel::Create", nullptr, 0);
33
34 return std::make_unique<ThemePanel>(pParent);
35}
36
38 : PanelLayout(pParent, "ThemePanel", "modules/swriter/ui/sidebartheme.ui")
39 , mxValueSetColors(new svx::ThemeColorValueSet)
40 , mxValueSetColorsWin(new weld::CustomWeld(*m_xBuilder, "valueset_colors", *mxValueSetColors))
41 , mxApplyButton(m_xBuilder->weld_button("apply"))
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
63{
64 mxValueSetColorsWin.reset();
65 mxValueSetColors.reset();
66 mxApplyButton.reset();
67}
68
70{
71 DoubleClickHdl();
72}
73
74IMPL_LINK_NOARG(ThemePanel, DoubleClickValueSetHdl, ValueSet*, void)
75{
76 DoubleClickHdl();
77}
78
80{
81 DoubleClickHdl();
82 return true;
83}
84
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
103void 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: */
static const AllSettings & GetSettings()
static SAL_WARN_UNUSED_RESULT SfxObjectShell * Current()
static ColorSets & get()
void apply(std::shared_ptr< model::ColorSet > const &pColorSet) override
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState) override
Definition: ThemePanel.cxx:103
virtual ~ThemePanel() override
Definition: ThemePanel.cxx:62
std::unique_ptr< svx::ThemeColorValueSet > mxValueSetColors
Definition: ThemePanel.hxx:42
std::unique_ptr< weld::CustomWeld > mxValueSetColorsWin
Definition: ThemePanel.hxx:43
std::unique_ptr< weld::Button > mxApplyButton
Definition: ThemePanel.hxx:44
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent)
Definition: ThemePanel.cxx:29
ThemePanel(weld::Widget *pParent)
Definition: ThemePanel.cxx:37
sal_Int32 nIndex
IMPL_LINK_NOARG(AccessibilityCheckEntry, GotoButtonClicked, weld::LinkButton &, bool)
SfxItemState