Coverage Report

Created: 2026-10-14 09:33

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