LibreOffice Module toolkit (master) 1
vclxspinbutton.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
21#include <helper/property.hxx>
22#include <com/sun/star/awt/ScrollBarOrientation.hpp>
23
24#include <vcl/toolkit/spin.hxx>
25#include <vcl/svapp.hxx>
27
28namespace toolkit
29{
30
31
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::awt;
34 using namespace ::com::sun::star::lang;
35 using namespace ::com::sun::star::beans;
36
37
38 namespace
39 {
40 void lcl_modifyStyle( vcl::Window* _pWindow, WinBits _nStyleBits, bool _bShouldBePresent )
41 {
42 WinBits nStyle = _pWindow->GetStyle();
43 if ( _bShouldBePresent )
44 nStyle |= _nStyleBits;
45 else
46 nStyle &= ~_nStyleBits;
47 _pWindow->SetStyle( nStyle );
48 }
49 }
50
52 :maAdjustmentListeners( *this )
53 {
54 }
55
56
58 {
59 }
60
61
63
64
66
67
68 void SAL_CALL VCLXSpinButton::dispose( )
69 {
70 {
71 SolarMutexGuard aGuard;
72
73 EventObject aDisposeEvent;
74 aDisposeEvent.Source = *this;
75 maAdjustmentListeners.disposeAndClear( aDisposeEvent );
76 }
77
79 }
80
81
82 void SAL_CALL VCLXSpinButton::addAdjustmentListener( const Reference< XAdjustmentListener >& listener )
83 {
84 if ( listener.is() )
85 maAdjustmentListeners.addInterface( listener );
86 }
87
88
89 void SAL_CALL VCLXSpinButton::removeAdjustmentListener( const Reference< XAdjustmentListener >& listener )
90 {
91 if ( listener.is() )
92 maAdjustmentListeners.removeInterface( listener );
93 }
94
95 namespace
96 {
97 typedef void (SpinButton::*SetSpinButtonValue) (tools::Long);
98 typedef tools::Long (SpinButton::*GetSpinButtonValue) () const;
99
100
101 void lcl_setSpinButtonValue(vcl::Window* _pWindow, SetSpinButtonValue _pSetter, sal_Int32 _nValue )
102 {
103 SolarMutexGuard aGuard;
104 SpinButton* pSpinButton = static_cast< SpinButton* >( _pWindow );
105 if ( pSpinButton )
106 (pSpinButton->*_pSetter)( _nValue );
107 }
108
109
110 sal_Int32 lcl_getSpinButtonValue(const vcl::Window* _pWindow, GetSpinButtonValue _pGetter )
111 {
112 SolarMutexGuard aGuard;
113
114 sal_Int32 nValue = 0;
115
116 const SpinButton* pSpinButton = static_cast< const SpinButton* >( _pWindow );
117 if ( pSpinButton )
118 nValue = (pSpinButton->*_pGetter)( );
119 return nValue;
120 }
121 }
122
123
124 void SAL_CALL VCLXSpinButton::setValue( sal_Int32 n )
125 {
126 lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValue, n );
127 }
128
129
130 void SAL_CALL VCLXSpinButton::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue )
131 {
132 SolarMutexGuard aGuard;
133
134 setMinimum( minValue );
135 setMaximum( maxValue );
136 setValue( currentValue );
137 }
138
139
140 sal_Int32 SAL_CALL VCLXSpinButton::getValue( )
141 {
142 return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetValue );
143 }
144
145
146 void SAL_CALL VCLXSpinButton::setMinimum( sal_Int32 minValue )
147 {
148 lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMin, minValue );
149 }
150
151
152 void SAL_CALL VCLXSpinButton::setMaximum( sal_Int32 maxValue )
153 {
154 lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMax, maxValue );
155 }
156
157
158 sal_Int32 SAL_CALL VCLXSpinButton::getMinimum( )
159 {
160 return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetRangeMin );
161 }
162
163
164 sal_Int32 SAL_CALL VCLXSpinButton::getMaximum( )
165 {
166 return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetRangeMax );
167 }
168
169
170 void SAL_CALL VCLXSpinButton::setSpinIncrement( sal_Int32 spinIncrement )
171 {
172 lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValueStep, spinIncrement );
173 }
174
175
177 {
178 return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetValueStep );
179 }
180
181
183 {
184 SolarMutexGuard aGuard;
185
186 lcl_modifyStyle( GetWindow(), WB_HSCROLL, orientation == ScrollBarOrientation::HORIZONTAL );
187 }
188
189
190 sal_Int32 SAL_CALL VCLXSpinButton::getOrientation( )
191 {
192 return ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) )
193 ? ScrollBarOrientation::HORIZONTAL
194 : ScrollBarOrientation::VERTICAL;
195 }
196
197
199 {
201 Reference< XSpinValue > xKeepAlive( this );
202 VclPtr<SpinButton> pSpinButton = GetAs<SpinButton>();
203 if ( !pSpinButton )
204 return;
205
206 switch ( _rVclWindowEvent.GetId() )
207 {
208 case VclEventId::SpinbuttonUp:
209 case VclEventId::SpinbuttonDown:
210 if ( maAdjustmentListeners.getLength() )
211 {
212 AdjustmentEvent aEvent;
213 aEvent.Source = *this;
214 aEvent.Value = pSpinButton->GetValue();
215
216 aGuard.clear();
217 maAdjustmentListeners.adjustmentValueChanged( aEvent );
218 }
219 break;
220
221 default:
222 xKeepAlive.clear();
223 aGuard.clear();
224 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
225 break;
226 }
227 }
228
229
230 void SAL_CALL VCLXSpinButton::setProperty( const OUString& PropertyName, const Any& Value )
231 {
232 SolarMutexGuard aGuard;
233
234 sal_Int32 nValue = 0;
235 bool bIsLongValue = ( Value >>= nValue );
236
237 if ( !GetWindow() )
238 return;
239
240 sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
241 switch ( nPropertyId )
242 {
244 // the default implementation of the base class doesn't work here, since our
245 // interpretation for this property is slightly different
247 break;
248
250 if ( bIsLongValue )
251 setValue( nValue );
252 break;
253
255 if ( bIsLongValue )
257 break;
258
260 if ( bIsLongValue )
262 break;
263
265 if ( bIsLongValue )
267 break;
268
270 if ( bIsLongValue )
271 lcl_modifyStyle( GetWindow(), WB_HSCROLL, nValue == ScrollBarOrientation::HORIZONTAL );
272 break;
273
274 default:
275 VCLXWindow::setProperty( PropertyName, Value );
276 }
277 }
278
279
280 Any SAL_CALL VCLXSpinButton::getProperty( const OUString& PropertyName )
281 {
282 SolarMutexGuard aGuard;
283
284 Any aReturn;
285
286 if ( GetWindow() )
287 {
288 sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
289 switch ( nPropertyId )
290 {
292 // the default implementation of the base class doesn't work here, since our
293 // interpretation for this property is slightly different
294 aReturn = getButtonLikeFaceColor( GetWindow() );
295 break;
296
298 aReturn <<= getValue( );
299 break;
300
302 aReturn <<= getMinimum( );
303 break;
304
306 aReturn <<= getMaximum( );
307 break;
308
310 aReturn <<= getSpinIncrement( );
311 break;
312
314 aReturn <<= static_cast<sal_Int32>( ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) )
315 ? ScrollBarOrientation::HORIZONTAL
316 : ScrollBarOrientation::VERTICAL
317 );
318 break;
319
320 default:
321 aReturn = VCLXWindow::getProperty( PropertyName );
322 }
323 }
324 return aReturn;
325 }
326
327
328} // namespace toolkit
329
330
331/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropFlags nPropertyId
AnyEventRef aEvent
vcl::Window * GetWindow() const
Definition: vclxwindow.hxx:131
virtual void ProcessWindowEvent(const VclWindowEvent &rVclWindowEvent)
Definition: vclxwindow.cxx:426
css::uno::Any SAL_CALL getProperty(const OUString &PropertyName) override
void SAL_CALL setProperty(const OUString &PropertyName, const css::uno::Any &Value) override
void SAL_CALL dispose() override
Definition: vclxwindow.cxx:907
VclEventId GetId() const
virtual sal_Int32 SAL_CALL getValue() override
AdjustmentListenerMultiplexer maAdjustmentListeners
void ProcessWindowEvent(const VclWindowEvent &_rVclWindowEvent) override
virtual css::uno::Any SAL_CALL getProperty(const OUString &PropertyName) override
virtual void SAL_CALL addAdjustmentListener(const css::uno::Reference< css::awt::XAdjustmentListener > &listener) override
virtual void SAL_CALL setOrientation(sal_Int32 orientation) override
virtual void SAL_CALL setSpinIncrement(sal_Int32 spinIncrement) override
virtual void SAL_CALL setMinimum(sal_Int32 minValue) override
virtual ~VCLXSpinButton() override
virtual void SAL_CALL setValues(sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue) override
virtual sal_Int32 SAL_CALL getMinimum() override
virtual sal_Int32 SAL_CALL getMaximum() override
virtual sal_Int32 SAL_CALL getOrientation() override
virtual void SAL_CALL removeAdjustmentListener(const css::uno::Reference< css::awt::XAdjustmentListener > &listener) override
virtual sal_Int32 SAL_CALL getSpinIncrement() override
virtual void SAL_CALL setMaximum(sal_Int32 maxValue) override
virtual void SAL_CALL setValue(sal_Int32 n) override
virtual void SAL_CALL setProperty(const OUString &PropertyName, const css::uno::Any &Value) override
void SetStyle(WinBits nStyle)
WinBits GetStyle() const
sal_Int16 nValue
sal_Int64 n
Value
orientation
Any getButtonLikeFaceColor(const vcl::Window *_pWindow)
void setButtonLikeFaceColor(vcl::Window *_pWindow, const css::uno::Any &_rColorValue)
sets the "face color" for button like controls (scroll bar, spin button)
Definition: vclxwindows.cxx:99
long Long
sal_uInt16 GetPropertyId(const OUString &rPropertyName)
Definition: property.cxx:278
#define BASEPROPERTY_SPININCREMENT
Definition: property.hxx:133
#define BASEPROPERTY_SPINVALUE
Definition: property.hxx:130
#define BASEPROPERTY_ORIENTATION
Definition: property.hxx:115
#define BASEPROPERTY_BACKGROUNDCOLOR
Definition: property.hxx:35
#define BASEPROPERTY_SPINVALUE_MAX
Definition: property.hxx:132
#define BASEPROPERTY_SPINVALUE_MIN
Definition: property.hxx:131
IMPLEMENT_FORWARD_XINTERFACE2(ORoadmapEntry, ORoadmapEntry_Base, ::comphelper::OPropertyContainer)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ORoadmapEntry, ORoadmapEntry_Base, ::comphelper::OPropertyContainer)
sal_Int64 WinBits
WinBits const WB_HSCROLL