1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "ParaSpacingWindow.hxx"
22 #include <cppuhelper/queryinterface.hxx>
23 #include <editeng/ulspitem.hxx>
24 #include <editeng/lrspitem.hxx>
25 #include <editeng/editids.hrc>
26 #include <svx/ParaSpacingControl.hxx>
27 #include <vcl/toolbox.hxx>
28 #include <sfx2/sfxsids.hrc>
29 #include <svl/intitem.hxx>
30 #include <comphelper/processfactory.hxx>
32 #include <com/sun/star/frame/XFrame.hpp>
33 #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
34 #include <com/sun/star/ui/XContextChangeEventMultiplexer.hpp>
38 SFX_IMPL_TOOLBOX_CONTROL(ParaAboveSpacingControl
, SvxULSpaceItem
);
39 SFX_IMPL_TOOLBOX_CONTROL(ParaBelowSpacingControl
, SvxULSpaceItem
);
41 SFX_IMPL_TOOLBOX_CONTROL(ParaLeftSpacingControl
, SvxLRSpaceItem
);
42 SFX_IMPL_TOOLBOX_CONTROL(ParaRightSpacingControl
, SvxLRSpaceItem
);
43 SFX_IMPL_TOOLBOX_CONTROL(ParaFirstLineSpacingControl
, SvxLRSpaceItem
);
45 ParaULSpacingControl::ParaULSpacingControl(sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
)
46 : SfxToolBoxControl(nSlotId
, nId
, rTbx
)
48 addStatusListener(".uno:MetricUnit");
51 ParaULSpacingControl::~ParaULSpacingControl()
55 void ParaULSpacingControl::StateChangedAtToolBoxControl(sal_uInt16 nSID
, SfxItemState eState
,
56 const SfxPoolItem
* pState
)
58 ToolBoxItemId nId
= GetId();
59 ToolBox
& rTbx
= GetToolBox();
60 ParaULSpacingWindow
* pWindow
= static_cast<ParaULSpacingWindow
*>(rTbx
.GetItemWindow(nId
));
62 DBG_ASSERT( pWindow
, "Control not found!" );
64 if(SfxItemState::DISABLED
== eState
)
69 rTbx
.EnableItem(nId
, SfxItemState::DISABLED
!= eState
);
71 if(nSID
== SID_ATTR_METRIC
&& pState
&& eState
>= SfxItemState::DEFAULT
)
73 const SfxUInt16Item
* pMetricItem
= static_cast<const SfxUInt16Item
*>(pState
);
74 pWindow
->SetUnit(static_cast<FieldUnit
>(pMetricItem
->GetValue()));
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
));
83 // ParaAboveSpacingControl
85 ParaAboveSpacingControl::ParaAboveSpacingControl(sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
)
86 : ParaULSpacingControl(nSlotId
, nId
, rTbx
)
90 VclPtr
<InterimItemWindow
> ParaAboveSpacingControl::CreateItemWindow(vcl::Window
* pParent
)
92 VclPtr
<ParaAboveSpacingWindow
> pWindow
= VclPtr
<ParaAboveSpacingWindow
>::Create(pParent
);
98 // ParaBelowSpacingControl
100 ParaBelowSpacingControl::ParaBelowSpacingControl(sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
)
101 : ParaULSpacingControl(nSlotId
, nId
, rTbx
)
105 VclPtr
<InterimItemWindow
> ParaBelowSpacingControl::CreateItemWindow(vcl::Window
* pParent
)
107 VclPtr
<ParaBelowSpacingWindow
> pWindow
= VclPtr
<ParaBelowSpacingWindow
>::Create(pParent
);
113 // ParaLRSpacingControl
115 ParaLRSpacingControl::ParaLRSpacingControl(sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
)
116 : SfxToolBoxControl(nSlotId
, nId
, rTbx
)
118 addStatusListener(".uno:MetricUnit");
121 ParaLRSpacingControl::~ParaLRSpacingControl()
125 void SAL_CALL
ParaLRSpacingControl::dispose()
127 if(m_xMultiplexer
.is())
129 m_xMultiplexer
->removeAllContextChangeEventListeners(this);
130 m_xMultiplexer
.clear();
133 SfxToolBoxControl::dispose();
136 void ParaLRSpacingControl::StateChangedAtToolBoxControl(sal_uInt16 nSID
, SfxItemState eState
,
137 const SfxPoolItem
* pState
)
139 ToolBoxItemId nId
= GetId();
140 ToolBox
& rTbx
= GetToolBox();
141 ParaLRSpacingWindow
* pWindow
= static_cast<ParaLRSpacingWindow
*>(rTbx
.GetItemWindow(nId
));
143 DBG_ASSERT( pWindow
, "Control not found!" );
145 if(SfxItemState::DISABLED
== eState
)
150 if(!m_xMultiplexer
.is() && m_xFrame
.is())
152 m_xMultiplexer
= css::ui::ContextChangeEventMultiplexer::get(
153 ::comphelper::getProcessComponentContext());
155 m_xMultiplexer
->addContextChangeEventListener(this, m_xFrame
->getController());
158 if(nSID
== SID_ATTR_METRIC
&& pState
&& eState
>= SfxItemState::DEFAULT
)
160 const SfxUInt16Item
* pMetricItem
= static_cast<const SfxUInt16Item
*>(pState
);
161 pWindow
->SetUnit(static_cast<FieldUnit
>(pMetricItem
->GetValue()));
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
169 pWindow
->SetValue(eState
, pState
);
173 void SAL_CALL
ParaLRSpacingControl::notifyContextChangeEvent(const css::ui::ContextChangeEventObject
& rEvent
)
175 ToolBoxItemId nId
= GetId();
176 ToolBox
& rTbx
= GetToolBox();
177 ParaLRSpacingWindow
* pWindow
= static_cast<ParaLRSpacingWindow
*>(rTbx
.GetItemWindow(nId
));
181 vcl::EnumContext
eContext(
182 vcl::EnumContext::GetApplicationEnum(rEvent
.ApplicationName
),
183 vcl::EnumContext::GetContextEnum(rEvent
.ContextName
));
184 pWindow
->SetContext(eContext
);
188 ::css::uno::Any SAL_CALL
ParaLRSpacingControl::queryInterface(const ::css::uno::Type
& aType
)
190 ::css::uno::Any
a(SfxToolBoxControl::queryInterface(aType
));
194 return ::cppu::queryInterface(aType
, static_cast<css::ui::XContextChangeEventListener
*>(this));
197 void SAL_CALL
ParaLRSpacingControl::acquire() noexcept
199 SfxToolBoxControl::acquire();
202 void SAL_CALL
ParaLRSpacingControl::disposing(const ::css::lang::EventObject
&)
204 SfxToolBoxControl::disposing();
207 void SAL_CALL
ParaLRSpacingControl::release() noexcept
209 SfxToolBoxControl::release();
212 // ParaLeftSpacingControl
214 ParaLeftSpacingControl::ParaLeftSpacingControl(sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
)
215 : ParaLRSpacingControl(nSlotId
, nId
, rTbx
)
219 VclPtr
<InterimItemWindow
> ParaLeftSpacingControl::CreateItemWindow(vcl::Window
* pParent
)
221 VclPtr
<ParaLeftSpacingWindow
> pWindow
= VclPtr
<ParaLeftSpacingWindow
>::Create(pParent
);
227 // ParaRightSpacingControl
229 ParaRightSpacingControl::ParaRightSpacingControl(sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
)
230 : ParaLRSpacingControl(nSlotId
, nId
, rTbx
)
234 VclPtr
<InterimItemWindow
> ParaRightSpacingControl::CreateItemWindow(vcl::Window
* pParent
)
236 VclPtr
<ParaRightSpacingWindow
> pWindow
= VclPtr
<ParaRightSpacingWindow
>::Create(pParent
);
242 // ParaFirstLineSpacingControl
244 ParaFirstLineSpacingControl::ParaFirstLineSpacingControl(sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
)
245 : ParaLRSpacingControl(nSlotId
, nId
, rTbx
)
249 VclPtr
<InterimItemWindow
> ParaFirstLineSpacingControl::CreateItemWindow(vcl::Window
* pParent
)
251 VclPtr
<ParaFirstLineSpacingWindow
> pWindow
= VclPtr
<ParaFirstLineSpacingWindow
>::Create(pParent
);
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */