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