LibreOffice Module svx (master)  1
TextColumnsPropertyPanel.cxx
Go to the documentation of this file.
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.
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 #include <sal/config.h>
11 
13 
14 #include <sfx2/app.hxx>
15 #include <sfx2/dispatch.hxx>
16 #include <sfx2/module.hxx>
17 #include <sfx2/objsh.hxx>
18 #include <svl/itempool.hxx>
19 #include <svtools/unitconv.hxx>
20 #include <svx/sdmetitm.hxx>
21 #include <svx/svddef.hxx>
22 #include <svx/svxids.hrc>
23 #include <svx/unoshprp.hxx>
24 
25 #include <com/sun/star/lang/IllegalArgumentException.hpp>
26 
27 namespace
28 {
29 MapUnit GetUnit(const SfxBindings* pBindings, sal_uInt16 nWhich)
30 {
31  assert(pBindings);
32 
33  SfxObjectShell* pSh = nullptr;
34  if (auto pShell = pBindings->GetDispatcher()->GetShell(0))
35  pSh = pShell->GetObjectShell();
36  if (!pSh)
38  SfxItemPool& rPool = pSh ? pSh->GetPool() : SfxGetpApp()->GetPool();
39  return rPool.GetMetric(nWhich);
40 }
41 }
42 
43 namespace svx::sidebar
44 {
46  : PanelLayout(pParent, "TextColumnsPropertyPanel", "svx/ui/sidebartextcolumnspanel.ui")
47  , mpBindings(pBindings)
48  , m_xColumnsNumber(m_xBuilder->weld_spin_button("FLD_COL_NUMBER"))
49  , m_xColumnsSpacing(m_xBuilder->weld_metric_spin_button("MTR_FLD_COL_SPACING", FieldUnit::CM))
50  , maColumnsNumberController(SID_ATTR_TEXTCOLUMNS_NUMBER, *pBindings, *this)
51  , maColumnsSpacingController(SID_ATTR_TEXTCOLUMNS_SPACING, *pBindings, *this)
52 {
53  m_xColumnsNumber->connect_value_changed(
54  LINK(this, TextColumnsPropertyPanel, ModifyColumnsNumberHdl));
55  m_xColumnsSpacing->connect_value_changed(
56  LINK(this, TextColumnsPropertyPanel, ModifyColumnsSpacingHdl));
57 }
58 
60 {
63 
64  m_xColumnsSpacing.reset();
65  m_xColumnsNumber.reset();
66 }
67 
69 {
70  SfxInt16Item aItem(SDRATTR_TEXTCOLUMNS_NUMBER, m_xColumnsNumber->get_value());
71  mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_TEXTCOLUMNS_NUMBER, SfxCallMode::RECORD,
72  { &aItem });
73 }
74 
76 {
77  const MapUnit aUnit = GetUnit(mpBindings, SDRATTR_TEXTCOLUMNS_SPACING);
78  SdrMetricItem aItem(SDRATTR_TEXTCOLUMNS_SPACING, GetCoreValue(*m_xColumnsSpacing, aUnit));
79  mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_TEXTCOLUMNS_SPACING, SfxCallMode::RECORD,
80  { &aItem });
81 }
82 
84  const SfxPoolItem* pState)
85 {
86  switch (nSID)
87  {
88  case SID_ATTR_TEXTCOLUMNS_NUMBER:
89  if (eState >= SfxItemState::DEFAULT)
90  {
91  if (const auto pItem = dynamic_cast<const SfxInt16Item*>(pState))
92  m_xColumnsNumber->set_value(pItem->GetValue());
93  }
94  break;
95  case SID_ATTR_TEXTCOLUMNS_SPACING:
96  if (eState >= SfxItemState::DEFAULT)
97  {
98  const MapUnit aUnit = GetUnit(mpBindings, SDRATTR_TEXTCOLUMNS_SPACING);
99  if (const auto pItem = dynamic_cast<const SdrMetricItem*>(pState))
100  SetMetricValue(*m_xColumnsSpacing, pItem->GetValue(), aUnit);
101  }
102  break;
103  }
104 }
105 
106 std::unique_ptr<PanelLayout> TextColumnsPropertyPanel::Create(weld::Widget* pParent,
107  SfxBindings* pBindings)
108 {
109  if (pParent == nullptr)
110  throw css::lang::IllegalArgumentException(
111  "no parent Window given to TextColumnsPropertyPanel::Create", nullptr, 0);
112  if (pBindings == nullptr)
113  throw css::lang::IllegalArgumentException(
114  "no SfxBindings given to TextColumnsPropertyPanel::Create", nullptr, 2);
115 
116  return std::make_unique<TextColumnsPropertyPanel>(pParent, pBindings);
117 }
118 }
119 
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
std::unique_ptr< weld::SpinButton > m_xColumnsNumber
FieldUnit
IMPL_LINK_NOARG(AreaPropertyPanelBase, ToolbarHdl_Impl, const OString &, void)
sfx2::sidebar::ControllerItem maColumnsNumberController
static SfxObjectShell * Current()
constexpr TypedWhichId< SdrMetricItem > SDRATTR_TEXTCOLUMNS_SPACING(SDRATTR_TEXTCOLUMNS_FIRST+1)
SfxApplication * SfxGetpApp()
std::unique_ptr< weld::MetricSpinButton > m_xColumnsSpacing
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
SfxShell * GetShell(sal_uInt16 nIdx) const
SfxItemPool & GetPool() const
virtual void dispose()
virtual SfxObjectShell * GetObjectShell() override
int GetCoreValue(const weld::MetricSpinButton &rField, MapUnit eUnit)
void SetMetricValue(weld::MetricSpinButton &rField, int nCoreValue, MapUnit eUnit)
SfxItemState
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState) override
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, SfxBindings *pBindings)
constexpr TypedWhichId< SfxInt16Item > SDRATTR_TEXTCOLUMNS_NUMBER(SDRATTR_TEXTCOLUMNS_FIRST+0)
TextColumnsPropertyPanel(weld::Widget *pParent, SfxBindings *pBindings)
SfxDispatcher * GetDispatcher() const
MapUnit
sfx2::sidebar::ControllerItem maColumnsSpacingController