bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / sidebar / textcolumns / TextColumnsPropertyPanel.cxx
blobc1614bed24e2f93e00448fd874ec790f0686134a
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 "TextColumnsPropertyPanel.hxx"
14 #include <sfx2/app.hxx>
15 #include <sfx2/dispatch.hxx>
16 #include <sfx2/module.hxx>
17 #include <sfx2/objsh.hxx>
18 #include <svtools/unitconv.hxx>
19 #include <svx/sdmetitm.hxx>
20 #include <svx/svddef.hxx>
21 #include <svx/svxids.hrc>
22 #include <svx/unoshprp.hxx>
24 #include <com/sun/star/lang/IllegalArgumentException.hpp>
26 namespace
28 MapUnit GetUnit(const SfxBindings* pBindings, sal_uInt16 nWhich)
30 assert(pBindings);
32 SfxObjectShell* pSh = nullptr;
33 if (auto pShell = pBindings->GetDispatcher()->GetShell(0))
34 pSh = pShell->GetObjectShell();
35 if (!pSh)
36 pSh = SfxObjectShell::Current();
37 SfxItemPool& rPool = pSh ? pSh->GetPool() : SfxGetpApp()->GetPool();
38 return rPool.GetMetric(nWhich);
42 namespace svx::sidebar
44 TextColumnsPropertyPanel::TextColumnsPropertyPanel(weld::Widget* pParent, SfxBindings* pBindings)
45 : PanelLayout(pParent, "TextColumnsPropertyPanel", "svx/ui/sidebartextcolumnspanel.ui")
46 , mpBindings(pBindings)
47 , m_xColumnsNumber(m_xBuilder->weld_spin_button("FLD_COL_NUMBER"))
48 , m_xColumnsSpacing(m_xBuilder->weld_metric_spin_button("MTR_FLD_COL_SPACING", FieldUnit::CM))
49 , maColumnsNumberController(SID_ATTR_TEXTCOLUMNS_NUMBER, *pBindings, *this)
50 , maColumnsSpacingController(SID_ATTR_TEXTCOLUMNS_SPACING, *pBindings, *this)
52 m_xColumnsNumber->connect_value_changed(
53 LINK(this, TextColumnsPropertyPanel, ModifyColumnsNumberHdl));
54 m_xColumnsSpacing->connect_value_changed(
55 LINK(this, TextColumnsPropertyPanel, ModifyColumnsSpacingHdl));
58 TextColumnsPropertyPanel::~TextColumnsPropertyPanel()
60 maColumnsSpacingController.dispose();
61 maColumnsNumberController.dispose();
63 m_xColumnsSpacing.reset();
64 m_xColumnsNumber.reset();
67 IMPL_LINK_NOARG(TextColumnsPropertyPanel, ModifyColumnsNumberHdl, weld::SpinButton&, void)
69 SfxInt16Item aItem(SDRATTR_TEXTCOLUMNS_NUMBER, m_xColumnsNumber->get_value());
70 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_TEXTCOLUMNS_NUMBER, SfxCallMode::RECORD,
71 { &aItem });
74 IMPL_LINK_NOARG(TextColumnsPropertyPanel, ModifyColumnsSpacingHdl, weld::MetricSpinButton&, void)
76 const MapUnit aUnit = GetUnit(mpBindings, SDRATTR_TEXTCOLUMNS_SPACING);
77 SdrMetricItem aItem(SDRATTR_TEXTCOLUMNS_SPACING, GetCoreValue(*m_xColumnsSpacing, aUnit));
78 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_TEXTCOLUMNS_SPACING, SfxCallMode::RECORD,
79 { &aItem });
82 void TextColumnsPropertyPanel::NotifyItemUpdate(sal_uInt16 nSID, SfxItemState eState,
83 const SfxPoolItem* pState)
85 switch (nSID)
87 case SID_ATTR_TEXTCOLUMNS_NUMBER:
88 if (eState >= SfxItemState::DEFAULT)
90 if (const auto pItem = dynamic_cast<const SfxInt16Item*>(pState))
91 m_xColumnsNumber->set_value(pItem->GetValue());
93 break;
94 case SID_ATTR_TEXTCOLUMNS_SPACING:
95 if (eState >= SfxItemState::DEFAULT)
97 const MapUnit aUnit = GetUnit(mpBindings, SDRATTR_TEXTCOLUMNS_SPACING);
98 if (const auto pItem = dynamic_cast<const SdrMetricItem*>(pState))
99 SetMetricValue(*m_xColumnsSpacing, pItem->GetValue(), aUnit);
101 break;
105 std::unique_ptr<PanelLayout> TextColumnsPropertyPanel::Create(weld::Widget* pParent,
106 SfxBindings* pBindings)
108 if (pParent == nullptr)
109 throw css::lang::IllegalArgumentException(
110 "no parent Window given to TextColumnsPropertyPanel::Create", nullptr, 0);
111 if (pBindings == nullptr)
112 throw css::lang::IllegalArgumentException(
113 "no SfxBindings given to TextColumnsPropertyPanel::Create", nullptr, 2);
115 return std::make_unique<TextColumnsPropertyPanel>(pParent, pBindings);
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */