Add Marathi autocorrect
[LibreOffice.git] / sw / source / uibase / sidebar / ThemePanel.cxx
blobf73ca7bbc8a065c4f0b8567d33a60a262b2d0937
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 "ThemePanel.hxx"
12 #include <sal/config.h>
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>
26 namespace sw::sidebar
29 std::unique_ptr<PanelLayout> ThemePanel::Create(weld::Widget* pParent)
31 if (pParent == nullptr)
32 throw css::lang::IllegalArgumentException(u"no parent Window given to PagePropertyPanel::Create"_ustr, nullptr, 0);
34 return std::make_unique<ThemePanel>(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))
43 mxValueSetColors->SetColCount(2);
44 mxValueSetColors->SetLineCount(3);
45 mxValueSetColors->SetColor(Application::GetSettings().GetStyleSettings().GetFaceColor());
47 mxApplyButton->connect_clicked(LINK(this, ThemePanel, ClickHdl));
48 mxValueSetColors->SetDoubleClickHdl(LINK(this, ThemePanel, DoubleClickValueSetHdl));
50 auto const& rColorSets = svx::ColorSets::get();
51 for (model::ColorSet const& rColorSet : rColorSets.getColorSetVector())
53 mxValueSetColors->insert(rColorSet);
56 mxValueSetColors->SetOptimalSize();
58 if (!rColorSets.getColorSetVector().empty())
59 mxValueSetColors->SelectItem(1); // ItemId 1, position 0
62 ThemePanel::~ThemePanel()
64 mxValueSetColorsWin.reset();
65 mxValueSetColors.reset();
66 mxApplyButton.reset();
69 IMPL_LINK_NOARG(ThemePanel, ClickHdl, weld::Button&, void)
71 DoubleClickHdl();
74 IMPL_LINK_NOARG(ThemePanel, DoubleClickValueSetHdl, ValueSet*, void)
76 DoubleClickHdl();
79 IMPL_LINK_NOARG(ThemePanel, DoubleClickHdl, weld::TreeView&, bool)
81 DoubleClickHdl();
82 return true;
85 void ThemePanel::DoubleClickHdl()
87 SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current());
88 if (!pDocSh)
89 return;
91 sal_uInt32 nItemId = mxValueSetColors->GetSelectedItemId();
92 if (!nItemId)
93 return;
94 sal_uInt32 nIndex = nItemId - 1;
96 auto const& rColorSets = svx::ColorSets::get();
97 model::ColorSet const& rColorSet = rColorSets.getColorSet(nIndex);
99 ThemeColorChanger aChanger(pDocSh);
100 aChanger.apply(std::make_shared<model::ColorSet>(rColorSet));
103 void ThemePanel::NotifyItemUpdate(const sal_uInt16 /*nSId*/,
104 const SfxItemState /*eState*/,
105 const SfxPoolItem* /*pState*/)
109 } // end of namespace ::sw::sidebar
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */