Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / sidebar / textcolumns / TextColumnsPropertyPanel.cxx
blob2a06c57059ead871d71ee7fe46569118e6ea9012
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/objsh.hxx>
17 #include <svl/itempool.hxx>
18 #include <svtools/unitconv.hxx>
19 #include <svx/sdmetitm.hxx>
20 #include <svx/svddef.hxx>
21 #include <svx/svxids.hrc>
23 #include <com/sun/star/lang/IllegalArgumentException.hpp>
25 namespace
27 MapUnit GetUnit(const SfxBindings* pBindings, sal_uInt16 nWhich)
29 assert(pBindings);
31 SfxObjectShell* pSh = nullptr;
32 if (auto pShell = pBindings->GetDispatcher()->GetShell(0))
33 pSh = pShell->GetObjectShell();
34 if (!pSh)
35 pSh = SfxObjectShell::Current();
36 SfxItemPool& rPool = pSh ? pSh->GetPool() : SfxGetpApp()->GetPool();
37 return rPool.GetMetric(nWhich);
41 namespace svx::sidebar
43 TextColumnsPropertyPanel::TextColumnsPropertyPanel(weld::Widget* pParent, SfxBindings* pBindings)
44 : PanelLayout(pParent, "TextColumnsPropertyPanel", "svx/ui/sidebartextcolumnspanel.ui")
45 , mpBindings(pBindings)
46 , m_xColumnsNumber(m_xBuilder->weld_spin_button("FLD_COL_NUMBER"))
47 , m_xColumnsSpacing(m_xBuilder->weld_metric_spin_button("MTR_FLD_COL_SPACING", FieldUnit::CM))
48 , maColumnsNumberController(SID_ATTR_TEXTCOLUMNS_NUMBER, *pBindings, *this)
49 , maColumnsSpacingController(SID_ATTR_TEXTCOLUMNS_SPACING, *pBindings, *this)
51 m_xColumnsNumber->connect_value_changed(
52 LINK(this, TextColumnsPropertyPanel, ModifyColumnsNumberHdl));
53 m_xColumnsSpacing->connect_value_changed(
54 LINK(this, TextColumnsPropertyPanel, ModifyColumnsSpacingHdl));
57 TextColumnsPropertyPanel::~TextColumnsPropertyPanel()
59 maColumnsSpacingController.dispose();
60 maColumnsNumberController.dispose();
62 m_xColumnsSpacing.reset();
63 m_xColumnsNumber.reset();
66 IMPL_LINK_NOARG(TextColumnsPropertyPanel, ModifyColumnsNumberHdl, weld::SpinButton&, void)
68 SfxInt16Item aItem(SDRATTR_TEXTCOLUMNS_NUMBER, m_xColumnsNumber->get_value());
69 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_TEXTCOLUMNS_NUMBER, SfxCallMode::RECORD,
70 { &aItem });
73 IMPL_LINK_NOARG(TextColumnsPropertyPanel, ModifyColumnsSpacingHdl, weld::MetricSpinButton&, void)
75 const MapUnit aUnit = GetUnit(mpBindings, SDRATTR_TEXTCOLUMNS_SPACING);
76 SdrMetricItem aItem(SDRATTR_TEXTCOLUMNS_SPACING, GetCoreValue(*m_xColumnsSpacing, aUnit));
77 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_TEXTCOLUMNS_SPACING, SfxCallMode::RECORD,
78 { &aItem });
81 void TextColumnsPropertyPanel::NotifyItemUpdate(sal_uInt16 nSID, SfxItemState eState,
82 const SfxPoolItem* pState)
84 switch (nSID)
86 case SID_ATTR_TEXTCOLUMNS_NUMBER:
87 if (eState >= SfxItemState::DEFAULT)
89 if (const auto pItem = dynamic_cast<const SfxInt16Item*>(pState))
90 m_xColumnsNumber->set_value(pItem->GetValue());
92 break;
93 case SID_ATTR_TEXTCOLUMNS_SPACING:
94 if (eState >= SfxItemState::DEFAULT)
96 const MapUnit aUnit = GetUnit(mpBindings, SDRATTR_TEXTCOLUMNS_SPACING);
97 if (const auto pItem = dynamic_cast<const SdrMetricItem*>(pState))
98 SetMetricValue(*m_xColumnsSpacing, pItem->GetValue(), aUnit);
100 break;
104 std::unique_ptr<PanelLayout> TextColumnsPropertyPanel::Create(weld::Widget* pParent,
105 SfxBindings* pBindings)
107 if (pParent == nullptr)
108 throw css::lang::IllegalArgumentException(
109 "no parent Window given to TextColumnsPropertyPanel::Create", nullptr, 0);
110 if (pBindings == nullptr)
111 throw css::lang::IllegalArgumentException(
112 "no SfxBindings given to TextColumnsPropertyPanel::Create", nullptr, 2);
114 return std::make_unique<TextColumnsPropertyPanel>(pParent, pBindings);
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */