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 
36 using namespace svx;
37 
40 
44 
45 ParaULSpacingControl::ParaULSpacingControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx)
46  : SfxToolBoxControl(nSlotId, nId, rTbx)
47 {
48  addStatusListener(".uno:MetricUnit");
49 }
50 
52 {
53 }
54 
55 void ParaULSpacingControl::StateChanged(sal_uInt16 nSID, SfxItemState eState,
56  const SfxPoolItem* pState)
57 {
58  sal_uInt16 nId = GetId();
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 
85 ParaAboveSpacingControl::ParaAboveSpacingControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx)
86  : ParaULSpacingControl(nSlotId, nId, rTbx)
87 {
88 }
89 
91 {
93  pWindow->Show();
94 
95  return pWindow;
96 }
97 
98 // ParaBelowSpacingControl
99 
100 ParaBelowSpacingControl::ParaBelowSpacingControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx)
101  : ParaULSpacingControl(nSlotId, nId, rTbx)
102 {
103 }
104 
106 {
108  pWindow->Show();
109 
110  return pWindow;
111 }
112 
113 // ParaLRSpacingControl
114 
115 ParaLRSpacingControl::ParaLRSpacingControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx)
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 {
139  sal_uInt16 nId = GetId();
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(
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 
173 void SAL_CALL ParaLRSpacingControl::notifyContextChangeEvent(const css::ui::ContextChangeEventObject& rEvent)
174 {
175  sal_uInt16 nId = GetId();
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 
197 void SAL_CALL ParaLRSpacingControl::acquire() throw ()
198 {
199  SfxToolBoxControl::acquire();
200 }
201 
202 void SAL_CALL ParaLRSpacingControl::disposing(const ::css::lang::EventObject&)
203 {
204  SfxToolBoxControl::disposing();
205 }
206 
207 void SAL_CALL ParaLRSpacingControl::release() throw ()
208 {
209  SfxToolBoxControl::release();
210 }
211 
212 // ParaLeftSpacingControl
213 
214 ParaLeftSpacingControl::ParaLeftSpacingControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx)
215 : ParaLRSpacingControl(nSlotId, nId, rTbx)
216 {
217 }
218 
220 {
222  pWindow->Show();
223 
224  return pWindow;
225 }
226 
227 // ParaRightSpacingControl
228 
229 ParaRightSpacingControl::ParaRightSpacingControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx)
230 : ParaLRSpacingControl(nSlotId, nId, rTbx)
231 {
232 }
233 
235 {
237  pWindow->Show();
238 
239  return pWindow;
240 }
241 
242 // ParaFirstLineSpacingControl
243 
244 ParaFirstLineSpacingControl::ParaFirstLineSpacingControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx)
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: */
void SetValue(SfxItemState eState, const SfxPoolItem *pState)
virtual ~ParaLRSpacingControl() override
ToolBox & GetToolBox() const
ParaLeftSpacingControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
static Context GetContextEnum(const OUString &rsContextName)
ParaFirstLineSpacingControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
css::uno::Reference< css::lang::XComponent > m_xFrame
sal_uInt16 GetValue() const
sal_Int16 nId
ParaBelowSpacingControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
void SetContext(const vcl::EnumContext &eContext)
virtual void SAL_CALL dispose() override
void Enable(bool bEnable=true, bool bChild=true)
SFX_IMPL_TOOLBOX_CONTROL(FormatPaintBrushToolBoxControl, SfxBoolItem)
virtual void SAL_CALL notifyContextChangeEvent(const css::ui::ContextChangeEventObject &rEvent) override
virtual void SAL_CALL disposing(const ::css::lang::EventObject &) override
void EnableItem(sal_uInt16 nItemId, bool bEnable=true)
virtual void SAL_CALL dispose() override
css::uno::Reference< css::ui::XContextChangeEventMultiplexer > m_xMultiplexer
#define DBG_ASSERT(sCon, aError)
virtual ~ParaULSpacingControl() override
uno_Any a
ParaRightSpacingControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
static Application GetApplicationEnum(const OUString &rsApplicationName)
vcl::Window * GetItemWindow(sal_uInt16 nItemId) const
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
ParaULSpacingControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
ParaLRSpacingControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
void Disable(bool bChild=true)
virtual void SAL_CALL release() override
SfxItemState
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
unsigned short GetId() const
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
void SetUnit(FieldUnit eUnit)
void SetUnit(FieldUnit eUnit)
static VclPtr< reference_type > Create(Arg &&...arg)
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
void SetValue(const SvxULSpaceItem *pItem)
Reference< XComponentContext > getProcessComponentContext()
virtual ::css::uno::Any SAL_CALL queryInterface(const ::css::uno::Type &aType) override
virtual void SAL_CALL acquire() override
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
virtual VclPtr< InterimItemWindow > CreateItemWindow(vcl::Window *pParent) override
ParaAboveSpacingControl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)