1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <awt/vclxspinbutton.hxx>
#include <toolkit/helper/property.hxx>
#include <com/sun/star/awt/ScrollBarOrientation.hpp>
#include <vcl/toolkit/spin.hxx>
#include <vcl/svapp.hxx>
#include "vclxwindows_internal.hxx"
namespace toolkit
{
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::beans;
namespace
{
void lcl_modifyStyle( vcl::Window* _pWindow, WinBits _nStyleBits, bool _bShouldBePresent )
{
WinBits nStyle = _pWindow->GetStyle();
if ( _bShouldBePresent )
nStyle |= _nStyleBits;
else
nStyle &= ~_nStyleBits;
_pWindow->SetStyle( nStyle );
}
}
VCLXSpinButton::VCLXSpinButton()
:maAdjustmentListeners( *this )
{
}
VCLXSpinButton::~VCLXSpinButton()
{
}
IMPLEMENT_FORWARD_XINTERFACE2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base )<--- There is an unknown macro here somewhere. Configuration is required. If IMPLEMENT_FORWARD_XINTERFACE2 is a macro then please configure it.
IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXSpinButton, VCLXWindow, VCLXSpinButton_Base )
void SAL_CALL VCLXSpinButton::dispose( )
{
{
SolarMutexGuard aGuard;
EventObject aDisposeEvent;
aDisposeEvent.Source = *this;
maAdjustmentListeners.disposeAndClear( aDisposeEvent );
}
VCLXWindow::dispose();
}
void SAL_CALL VCLXSpinButton::addAdjustmentListener( const Reference< XAdjustmentListener >& listener )
{
if ( listener.is() )
maAdjustmentListeners.addInterface( listener );
}
void SAL_CALL VCLXSpinButton::removeAdjustmentListener( const Reference< XAdjustmentListener >& listener )
{
if ( listener.is() )
maAdjustmentListeners.removeInterface( listener );
}
namespace
{
typedef void (SpinButton::*SetSpinButtonValue) (long);
typedef long (SpinButton::*GetSpinButtonValue) () const;
void lcl_setSpinButtonValue(vcl::Window* _pWindow, SetSpinButtonValue _pSetter, sal_Int32 _nValue )
{
SolarMutexGuard aGuard;
SpinButton* pSpinButton = static_cast< SpinButton* >( _pWindow );
if ( pSpinButton )
(pSpinButton->*_pSetter)( _nValue );
}
sal_Int32 lcl_getSpinButtonValue(const vcl::Window* _pWindow, GetSpinButtonValue _pGetter )
{
SolarMutexGuard aGuard;
sal_Int32 nValue = 0;
const SpinButton* pSpinButton = static_cast< const SpinButton* >( _pWindow );
if ( pSpinButton )
nValue = (pSpinButton->*_pGetter)( );
return nValue;
}
}
void SAL_CALL VCLXSpinButton::setValue( sal_Int32 n )
{
lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValue, n );
}
void SAL_CALL VCLXSpinButton::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue )
{
SolarMutexGuard aGuard;
setMinimum( minValue );
setMaximum( maxValue );
setValue( currentValue );
}
sal_Int32 SAL_CALL VCLXSpinButton::getValue( )
{
return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetValue );
}
void SAL_CALL VCLXSpinButton::setMinimum( sal_Int32 minValue )
{
lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMin, minValue );
}
void SAL_CALL VCLXSpinButton::setMaximum( sal_Int32 maxValue )
{
lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetRangeMax, maxValue );
}
sal_Int32 SAL_CALL VCLXSpinButton::getMinimum( )
{
return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetRangeMin );
}
sal_Int32 SAL_CALL VCLXSpinButton::getMaximum( )
{
return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetRangeMax );
}
void SAL_CALL VCLXSpinButton::setSpinIncrement( sal_Int32 spinIncrement )
{
lcl_setSpinButtonValue( GetWindow(), &SpinButton::SetValueStep, spinIncrement );
}
sal_Int32 SAL_CALL VCLXSpinButton::getSpinIncrement( )
{
return lcl_getSpinButtonValue( GetWindow(), &SpinButton::GetValueStep );
}
void SAL_CALL VCLXSpinButton::setOrientation( sal_Int32 orientation )
{
SolarMutexGuard aGuard;
lcl_modifyStyle( GetWindow(), WB_HSCROLL, orientation == ScrollBarOrientation::HORIZONTAL );
}
sal_Int32 SAL_CALL VCLXSpinButton::getOrientation( )
{
return ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) )
? ScrollBarOrientation::HORIZONTAL
: ScrollBarOrientation::VERTICAL;
}
void VCLXSpinButton::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
{
SolarMutexClearableGuard aGuard;
Reference< XSpinValue > xKeepAlive( this );
VclPtr<SpinButton> pSpinButton = GetAs<SpinButton>();
if ( !pSpinButton )
return;
switch ( _rVclWindowEvent.GetId() )
{
case VclEventId::SpinbuttonUp:
case VclEventId::SpinbuttonDown:
if ( maAdjustmentListeners.getLength() )
{
AdjustmentEvent aEvent;
aEvent.Source = *this;
aEvent.Value = pSpinButton->GetValue();
aGuard.clear();
maAdjustmentListeners.adjustmentValueChanged( aEvent );
}
break;
default:
xKeepAlive.clear();
aGuard.clear();
VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
break;
}
}
void SAL_CALL VCLXSpinButton::setProperty( const OUString& PropertyName, const Any& Value )
{
SolarMutexGuard aGuard;
sal_Int32 nValue = 0;
bool bIsLongValue = ( Value >>= nValue );
if ( GetWindow() )
{
sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
switch ( nPropertyId )
{
case BASEPROPERTY_BACKGROUNDCOLOR:
// the default implementation of the base class doesn't work here, since our
// interpretation for this property is slightly different
setButtonLikeFaceColor( GetWindow(), Value);
break;
case BASEPROPERTY_SPINVALUE:
if ( bIsLongValue )
setValue( nValue );
break;
case BASEPROPERTY_SPINVALUE_MIN:
if ( bIsLongValue )
setMinimum( nValue );
break;
case BASEPROPERTY_SPINVALUE_MAX:
if ( bIsLongValue )
setMaximum( nValue );
break;
case BASEPROPERTY_SPININCREMENT:
if ( bIsLongValue )
setSpinIncrement( nValue );
break;
case BASEPROPERTY_ORIENTATION:
if ( bIsLongValue )
lcl_modifyStyle( GetWindow(), WB_HSCROLL, nValue == ScrollBarOrientation::HORIZONTAL );
break;
default:
VCLXWindow::setProperty( PropertyName, Value );
}
}
}
Any SAL_CALL VCLXSpinButton::getProperty( const OUString& PropertyName )
{
SolarMutexGuard aGuard;
Any aReturn;
if ( GetWindow() )
{
sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
switch ( nPropertyId )
{
case BASEPROPERTY_BACKGROUNDCOLOR:
// the default implementation of the base class doesn't work here, since our
// interpretation for this property is slightly different
aReturn = getButtonLikeFaceColor( GetWindow() );
break;
case BASEPROPERTY_SPINVALUE:
aReturn <<= getValue( );
break;
case BASEPROPERTY_SPINVALUE_MIN:
aReturn <<= getMinimum( );
break;
case BASEPROPERTY_SPINVALUE_MAX:
aReturn <<= getMaximum( );
break;
case BASEPROPERTY_SPININCREMENT:
aReturn <<= getSpinIncrement( );
break;
case BASEPROPERTY_ORIENTATION:
aReturn <<= static_cast<sal_Int32>( ( 0 != ( GetWindow()->GetStyle() & WB_HSCROLL ) )
? ScrollBarOrientation::HORIZONTAL
: ScrollBarOrientation::VERTICAL
);
break;
default:
aReturn = VCLXWindow::getProperty( PropertyName );
}
}
return aReturn;
}
} // namespace toolkit
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|