LibreOffice Module svx (master) 1
ParaSpacingControl.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "ParaSpacingWindow.hxx"
21
23#include <editeng/ulspitem.hxx>
24#include <editeng/lrspitem.hxx>
25#include <editeng/editids.hrc>
27#include <vcl/toolbox.hxx>
28#include <sfx2/sfxsids.hrc>
29#include <svl/intitem.hxx>
31
32#include <com/sun/star/frame/XFrame.hpp>
33#include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
34#include <com/sun/star/ui/XContextChangeEventMultiplexer.hpp>
35
36using namespace svx;
37
40
44
45ParaULSpacingControl::ParaULSpacingControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox& rTbx)
46 : SfxToolBoxControl(nSlotId, nId, rTbx)
47{
48 addStatusListener(".uno:MetricUnit");
49}
50
52{
53}
54
56 const SfxPoolItem* pState)
57{
59 ToolBox& rTbx = GetToolBox();
60 ParaULSpacingWindow* pWindow = static_cast<ParaULSpacingWindow*>(rTbx.GetItemWindow(nId));
61
62 DBG_ASSERT( pWindow, "Control not found!" );
63
64 if(SfxItemState::DISABLED == eState)
65 pWindow->Disable();
66 else
67 pWindow->Enable();
68
69 rTbx.EnableItem(nId, SfxItemState::DISABLED != eState);
70
71 if(nSID == SID_ATTR_METRIC && pState && eState >= SfxItemState::DEFAULT)
72 {
73 const SfxUInt16Item* pMetricItem = static_cast<const SfxUInt16Item*>(pState);
74 pWindow->SetUnit(static_cast<FieldUnit>(pMetricItem->GetValue()));
75 }
76 else if((nSID == SID_ATTR_PARA_ULSPACE
77 || nSID == SID_ATTR_PARA_ABOVESPACE
78 || nSID == SID_ATTR_PARA_BELOWSPACE )
79 && pState && eState >= SfxItemState::DEFAULT)
80 pWindow->SetValue(static_cast<const SvxULSpaceItem*>(pState));
81}
82
83// ParaAboveSpacingControl
84
86 : ParaULSpacingControl(nSlotId, nId, rTbx)
87{
88}
89
91{
93 pWindow->Show();
94
95 return pWindow;
96}
97
98// ParaBelowSpacingControl
99
101 : ParaULSpacingControl(nSlotId, nId, rTbx)
102{
103}
104
106{
108 pWindow->Show();
109
110 return pWindow;
111}
112
113// ParaLRSpacingControl
114
116 : SfxToolBoxControl(nSlotId, nId, rTbx)
117{
118 addStatusListener(".uno:MetricUnit");
119}
120
122{
123}
124
126{
127 if(m_xMultiplexer.is())
128 {
129 m_xMultiplexer->removeAllContextChangeEventListeners(this);
130 m_xMultiplexer.clear();
131 }
132
134}
135
137 const SfxPoolItem* pState)
138{
140 ToolBox& rTbx = GetToolBox();
141 ParaLRSpacingWindow* pWindow = static_cast<ParaLRSpacingWindow*>(rTbx.GetItemWindow(nId));
142
143 DBG_ASSERT( pWindow, "Control not found!" );
144
145 if(SfxItemState::DISABLED == eState)
146 pWindow->Disable();
147 else
148 pWindow->Enable();
149
150 if(!m_xMultiplexer.is() && m_xFrame.is())
151 {
152 m_xMultiplexer = css::ui::ContextChangeEventMultiplexer::get(
153 ::comphelper::getProcessComponentContext());
154
155 m_xMultiplexer->addContextChangeEventListener(this, m_xFrame->getController());
156 }
157
158 if(nSID == SID_ATTR_METRIC && pState && eState >= SfxItemState::DEFAULT)
159 {
160 const SfxUInt16Item* pMetricItem = static_cast<const SfxUInt16Item*>(pState);
161 pWindow->SetUnit(static_cast<FieldUnit>(pMetricItem->GetValue()));
162 }
163 else if(nSID == SID_ATTR_PARA_LRSPACE
164 || nSID == SID_ATTR_PARA_LEFTSPACE
165 || nSID == SID_ATTR_PARA_RIGHTSPACE
166 || nSID == SID_ATTR_PARA_FIRSTLINESPACE
167 )
168 {
169 pWindow->SetValue(eState, pState);
170 }
171}
172
173void SAL_CALL ParaLRSpacingControl::notifyContextChangeEvent(const css::ui::ContextChangeEventObject& rEvent)
174{
176 ToolBox& rTbx = GetToolBox();
177 ParaLRSpacingWindow* pWindow = static_cast<ParaLRSpacingWindow*>(rTbx.GetItemWindow(nId));
178
179 if(pWindow)
180 {
181 vcl::EnumContext eContext(
182 vcl::EnumContext::GetApplicationEnum(rEvent.ApplicationName),
183 vcl::EnumContext::GetContextEnum(rEvent.ContextName));
184 pWindow->SetContext(eContext);
185 }
186}
187
188::css::uno::Any SAL_CALL ParaLRSpacingControl::queryInterface(const ::css::uno::Type& aType)
189{
190 ::css::uno::Any a(SfxToolBoxControl::queryInterface(aType));
191 if (a.hasValue())
192 return a;
193
194 return ::cppu::queryInterface(aType, static_cast<css::ui::XContextChangeEventListener*>(this));
195}
196
197void SAL_CALL ParaLRSpacingControl::acquire() noexcept
198{
199 SfxToolBoxControl::acquire();
200}
201
202void SAL_CALL ParaLRSpacingControl::disposing(const ::css::lang::EventObject&)
203{
204 SfxToolBoxControl::disposing();
205}
206
207void SAL_CALL ParaLRSpacingControl::release() noexcept
208{
209 SfxToolBoxControl::release();
210}
211
212// ParaLeftSpacingControl
213
215: ParaLRSpacingControl(nSlotId, nId, rTbx)
216{
217}
218
220{
222 pWindow->Show();
223
224 return pWindow;
225}
226
227// ParaRightSpacingControl
228
230: ParaLRSpacingControl(nSlotId, nId, rTbx)
231{
232}
233
235{
237 pWindow->Show();
238
239 return pWindow;
240}
241
242// ParaFirstLineSpacingControl
243
245: ParaLRSpacingControl(nSlotId, nId, rTbx)
246{
247}
248
250{
252 pWindow->Show();
253
254 return pWindow;
255}
256
257/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SFX_IMPL_TOOLBOX_CONTROL(ParaAboveSpacingControl, SvxULSpaceItem)
css::uno::Reference< css::lang::XComponent > m_xFrame
sal_uInt16 GetValue() const
ToolBoxItemId GetId() const
virtual void SAL_CALL dispose() override
ToolBox & GetToolBox() const
void EnableItem(ToolBoxItemId nItemId, bool bEnable=true)
vcl::Window * GetItemWindow(ToolBoxItemId nItemId) const
static VclPtr< reference_type > Create(Arg &&... arg)
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
ParaAboveSpacingControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
ParaBelowSpacingControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
ParaFirstLineSpacingControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
virtual void SAL_CALL acquire() noexcept override
virtual void SAL_CALL notifyContextChangeEvent(const css::ui::ContextChangeEventObject &rEvent) override
virtual ::css::uno::Any SAL_CALL queryInterface(const ::css::uno::Type &aType) override
virtual ~ParaLRSpacingControl() override
virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
css::uno::Reference< css::ui::XContextChangeEventMultiplexer > m_xMultiplexer
virtual void SAL_CALL release() noexcept override
virtual void SAL_CALL disposing(const ::css::lang::EventObject &) override
virtual void SAL_CALL dispose() override
ParaLRSpacingControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
void SetContext(const vcl::EnumContext &eContext)
void SetUnit(FieldUnit eUnit)
void SetValue(SfxItemState eState, const SfxPoolItem *pState)
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
ParaLeftSpacingControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
ParaRightSpacingControl(sal_uInt16 nSlotId, ToolBoxItemId nId, ToolBox &rTbx)
virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
virtual ~ParaULSpacingControl() override
void SetUnit(FieldUnit eUnit)
void SetValue(const SvxULSpaceItem *pItem)
static Application GetApplicationEnum(const OUString &rsApplicationName)
static Context GetContextEnum(const OUString &rsContextName)
void Disable(bool bChild=true)
void Enable(bool bEnable=true, bool bChild=true)
#define DBG_ASSERT(sCon, aError)
FieldUnit
uno_Any a
sal_Int16 nId
SfxItemState