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/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>
22
23#include <com/sun/star/lang/IllegalArgumentException.hpp>
24
25namespace
26{
27MapUnit GetUnit(const SfxBindings* pBindings, sal_uInt16 nWhich)
28{
29 assert(pBindings);
30
31 SfxObjectShell* pSh = nullptr;
32 if (auto pShell = pBindings->GetDispatcher()->GetShell(0))
33 pSh = pShell->GetObjectShell();
34 if (!pSh)
36 SfxItemPool& rPool = pSh ? pSh->GetPool() : SfxGetpApp()->GetPool();
37 return rPool.GetMetric(nWhich);
38}
39}
40
41namespace svx::sidebar
42{
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)
50{
51 m_xColumnsNumber->connect_value_changed(
52 LINK(this, TextColumnsPropertyPanel, ModifyColumnsNumberHdl));
53 m_xColumnsSpacing->connect_value_changed(
54 LINK(this, TextColumnsPropertyPanel, ModifyColumnsSpacingHdl));
55}
56
58{
61
62 m_xColumnsSpacing.reset();
63 m_xColumnsNumber.reset();
64}
65
67{
68 SfxInt16Item aItem(SDRATTR_TEXTCOLUMNS_NUMBER, m_xColumnsNumber->get_value());
69 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_TEXTCOLUMNS_NUMBER, SfxCallMode::RECORD,
70 { &aItem });
71}
72
74{
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 });
79}
80
82 const SfxPoolItem* pState)
83{
84 switch (nSID)
85 {
86 case SID_ATTR_TEXTCOLUMNS_NUMBER:
87 if (eState >= SfxItemState::DEFAULT)
88 {
89 if (const auto pItem = dynamic_cast<const SfxInt16Item*>(pState))
90 m_xColumnsNumber->set_value(pItem->GetValue());
91 }
92 break;
93 case SID_ATTR_TEXTCOLUMNS_SPACING:
94 if (eState >= SfxItemState::DEFAULT)
95 {
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);
99 }
100 break;
101 }
102}
103
104std::unique_ptr<PanelLayout> TextColumnsPropertyPanel::Create(weld::Widget* pParent,
105 SfxBindings* pBindings)
106{
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);
113
114 return std::make_unique<TextColumnsPropertyPanel>(pParent, pBindings);
115}
116}
117
118/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
SfxApplication * SfxGetpApp()
SfxDispatcher * GetDispatcher() const
virtual void dispose()
SfxShell * GetShell(sal_uInt16 nIdx) const
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
virtual SfxObjectShell * GetObjectShell() override
static SAL_WARN_UNUSED_RESULT SfxObjectShell * Current()
SfxItemPool & GetPool() const
std::unique_ptr< weld::SpinButton > m_xColumnsNumber
std::unique_ptr< weld::MetricSpinButton > m_xColumnsSpacing
sfx2::sidebar::ControllerItem maColumnsNumberController
TextColumnsPropertyPanel(weld::Widget *pParent, SfxBindings *pBindings)
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, SfxBindings *pBindings)
sfx2::sidebar::ControllerItem maColumnsSpacingController
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState) override
FieldUnit
MapUnit
IMPL_LINK_NOARG(AreaPropertyPanelBase, ToolbarHdl_Impl, const OUString &, void)
SfxItemState
constexpr TypedWhichId< SfxInt16Item > SDRATTR_TEXTCOLUMNS_NUMBER(SDRATTR_TEXTCOLUMNS_FIRST+0)
constexpr TypedWhichId< SdrMetricItem > SDRATTR_TEXTCOLUMNS_SPACING(SDRATTR_TEXTCOLUMNS_FIRST+1)
SVT_DLLPUBLIC sal_Int64 GetCoreValue(const weld::MetricSpinButton &rField, MapUnit eUnit)
SVT_DLLPUBLIC void SetMetricValue(weld::MetricSpinButton &rField, sal_Int64 nCoreValue, MapUnit eUnit)