Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/toolkit/source/controls/tkspinbutton.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 <com/sun/star/awt/ScrollBarOrientation.hpp>
21
#include <com/sun/star/awt/XSpinValue.hpp>
22
#include <com/sun/star/awt/XAdjustmentListener.hpp>
23
#include <com/sun/star/uno/XComponentContext.hpp>
24
25
#include <comphelper/uno3.hxx>
26
#include <cppuhelper/implbase2.hxx>
27
#include <rtl/ref.hxx>
28
#include <toolkit/controls/unocontrolmodel.hxx>
29
#include <toolkit/controls/unocontrolbase.hxx>
30
#include <helper/property.hxx>
31
32
#include <helper/unopropertyarrayhelper.hxx>
33
34
using namespace ::com::sun::star::uno;
35
using namespace ::com::sun::star::awt;
36
using namespace ::com::sun::star::lang;
37
using namespace ::com::sun::star::beans;
38
39
namespace {
40
41
class UnoSpinButtonModel : public UnoControlModel
42
{
43
protected:
44
    css::uno::Any      ImplGetDefaultValue( sal_uInt16 nPropId ) const override;
45
    ::cppu::IPropertyArrayHelper& getInfoHelper() override;
46
47
public:
48
    explicit UnoSpinButtonModel( const css::uno::Reference< css::uno::XComponentContext >& i_factory );
49
0
    UnoSpinButtonModel(const UnoSpinButtonModel & rOther) : UnoControlModel(rOther) {}
50
51
0
    rtl::Reference<UnoControlModel> Clone() const override { return new UnoSpinButtonModel( *this ); }
52
53
    // XMultiPropertySet
54
    css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) override;
55
56
    // XPersistObject
57
    OUString SAL_CALL getServiceName() override;
58
59
    // XServiceInfo
60
    OUString SAL_CALL getImplementationName(  ) override;
61
    css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
62
};
63
64
65
//= UnoSpinButtonControl
66
67
68
typedef ::cppu::ImplHelper2 <   css::awt::XAdjustmentListener
69
                            ,   css::awt::XSpinValue
70
                            >   UnoSpinButtonControl_Base;
71
72
class UnoSpinButtonControl :public UnoControlBase
73
                           ,public UnoSpinButtonControl_Base
74
{
75
private:
76
    AdjustmentListenerMultiplexer maAdjustmentListeners;
77
78
public:
79
                                UnoSpinButtonControl();
80
    OUString             GetComponentServiceName() const override;
81
82
    DECLARE_UNO3_AGG_DEFAULTS( UnoSpinButtonControl, UnoControlBase )
83
    css::uno::Any  SAL_CALL queryAggregation( const css::uno::Type & rType ) override;
84
85
    void SAL_CALL createPeer( const css::uno::Reference< css::awt::XToolkit >& Toolkit, const css::uno::Reference< css::awt::XWindowPeer >& Parent ) override;
86
0
    void SAL_CALL disposing( const css::lang::EventObject& Source ) override { UnoControlBase::disposing( Source ); }
87
    void SAL_CALL dispose(  ) override;
88
89
    // XTypeProvider
90
    DECLARE_XTYPEPROVIDER()
91
92
    // XAdjustmentListener
93
    void SAL_CALL adjustmentValueChanged( const css::awt::AdjustmentEvent& rEvent ) override;
94
95
    // XSpinValue
96
    virtual void SAL_CALL addAdjustmentListener( const css::uno::Reference< css::awt::XAdjustmentListener >& listener ) override;
97
    virtual void SAL_CALL removeAdjustmentListener( const css::uno::Reference< css::awt::XAdjustmentListener >& listener ) override;
98
    virtual void SAL_CALL setValue( sal_Int32 value ) override;
99
    virtual void SAL_CALL setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue ) override;
100
    virtual sal_Int32 SAL_CALL getValue(  ) override;
101
    virtual void SAL_CALL setMinimum( sal_Int32 minValue ) override;
102
    virtual void SAL_CALL setMaximum( sal_Int32 maxValue ) override;
103
    virtual sal_Int32 SAL_CALL getMinimum(  ) override;
104
    virtual sal_Int32 SAL_CALL getMaximum(  ) override;
105
    virtual void SAL_CALL setSpinIncrement( sal_Int32 spinIncrement ) override;
106
    virtual sal_Int32 SAL_CALL getSpinIncrement(  ) override;
107
    virtual void SAL_CALL setOrientation( sal_Int32 orientation ) override;
108
    virtual sal_Int32 SAL_CALL getOrientation(  ) override;
109
110
    // XServiceInfo
111
    OUString SAL_CALL getImplementationName(  ) override;
112
    css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
113
};
114
115
116
    //= UnoSpinButtonModel
117
118
119
    UnoSpinButtonModel::UnoSpinButtonModel( const css::uno::Reference< css::uno::XComponentContext >& i_factory )
120
0
        :UnoControlModel( i_factory )
121
0
    {
122
0
        ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
123
0
        ImplRegisterProperty( BASEPROPERTY_BORDER );
124
0
        ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
125
0
        ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
126
0
        ImplRegisterProperty( BASEPROPERTY_ENABLED );
127
0
        ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE );
128
0
        ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
129
0
        ImplRegisterProperty( BASEPROPERTY_HELPURL );
130
0
        ImplRegisterProperty( BASEPROPERTY_ORIENTATION );
131
0
        ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
132
0
        ImplRegisterProperty( BASEPROPERTY_REPEAT );
133
0
        ImplRegisterProperty( BASEPROPERTY_REPEAT_DELAY );
134
0
        ImplRegisterProperty( BASEPROPERTY_SYMBOL_COLOR );
135
0
        ImplRegisterProperty( BASEPROPERTY_SPINVALUE );
136
0
        ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MIN );
137
0
        ImplRegisterProperty( BASEPROPERTY_SPINVALUE_MAX );
138
0
        ImplRegisterProperty( BASEPROPERTY_SPININCREMENT );
139
0
        ImplRegisterProperty( BASEPROPERTY_TABSTOP );
140
0
        ImplRegisterProperty( BASEPROPERTY_WRITING_MODE );
141
0
        ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE );
142
0
    }
143
144
145
    OUString UnoSpinButtonModel::getServiceName( )
146
0
    {
147
0
        return u"com.sun.star.awt.UnoControlSpinButtonModel"_ustr;
148
0
    }
149
150
151
    Any UnoSpinButtonModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
152
0
    {
153
0
        switch ( nPropId )
154
0
        {
155
0
        case BASEPROPERTY_DEFAULTCONTROL:
156
0
            return Any( u"com.sun.star.awt.UnoControlSpinButton"_ustr );
157
158
0
        case BASEPROPERTY_BORDER:
159
0
            return Any( sal_Int16(0) );
160
161
0
        case BASEPROPERTY_REPEAT:
162
0
            return Any( true );
163
164
0
        default:
165
0
            return UnoControlModel::ImplGetDefaultValue( nPropId );
166
0
        }
167
0
    }
168
169
170
    ::cppu::IPropertyArrayHelper& UnoSpinButtonModel::getInfoHelper()
171
0
    {
172
0
        static UnoPropertyArrayHelper aHelper( ImplGetPropertyIds() );
173
0
        return aHelper;
174
0
    }
175
176
177
    Reference< XPropertySetInfo > UnoSpinButtonModel::getPropertySetInfo(  )
178
0
    {
179
0
        static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
180
0
        return xInfo;
181
0
    }
182
183
184
    OUString SAL_CALL UnoSpinButtonModel::getImplementationName(  )
185
0
    {
186
0
        return u"stardiv.Toolkit.UnoSpinButtonModel"_ustr;
187
0
    }
188
189
190
    Sequence< OUString > SAL_CALL UnoSpinButtonModel::getSupportedServiceNames()
191
0
    {
192
0
        const css::uno::Sequence<OUString> vals { u"com.sun.star.awt.UnoControlSpinButtonModel"_ustr };
193
0
        return comphelper::concatSequences( UnoControlModel::getSupportedServiceNames(), vals );
194
0
    }
195
196
197
    //= UnoSpinButtonControl
198
199
200
    UnoSpinButtonControl::UnoSpinButtonControl()
201
0
        :maAdjustmentListeners( *this )
202
0
    {
203
0
    }
204
205
206
    OUString UnoSpinButtonControl::GetComponentServiceName() const
207
0
    {
208
0
        return u"SpinButton"_ustr;
209
0
    }
210
211
212
    Any UnoSpinButtonControl::queryAggregation( const Type & rType )
213
0
    {
214
0
        Any aRet = UnoControlBase::queryAggregation( rType );
215
0
        if ( !aRet.hasValue() )
216
0
            aRet = UnoSpinButtonControl_Base::queryInterface( rType );
217
0
        return aRet;
218
0
    }
219
220
221
    IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoSpinButtonControl, UnoControlBase, UnoSpinButtonControl_Base )
222
223
224
    void UnoSpinButtonControl::dispose()
225
0
    {
226
0
        ::osl::ClearableMutexGuard aGuard( GetMutex() );
227
0
        if ( maAdjustmentListeners.getLength() )
228
0
        {
229
0
            Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
230
0
            if ( xSpinnable.is() )
231
0
                xSpinnable->removeAdjustmentListener( this );
232
233
0
            EventObject aDisposeEvent;
234
0
            aDisposeEvent.Source = *this;
235
236
0
            aGuard.clear();
237
0
            maAdjustmentListeners.disposeAndClear( aDisposeEvent );
238
0
        }
239
240
0
        UnoControl::dispose();
241
0
    }
242
243
244
    OUString SAL_CALL UnoSpinButtonControl::getImplementationName(  )
245
0
    {
246
0
        return u"stardiv.Toolkit.UnoSpinButtonControl"_ustr;
247
0
    }
248
249
250
    Sequence< OUString > SAL_CALL UnoSpinButtonControl::getSupportedServiceNames()
251
0
    {
252
0
        const css::uno::Sequence<OUString> vals { u"com.sun.star.awt.UnoControlSpinButton"_ustr };
253
0
        return comphelper::concatSequences( UnoControlBase::getSupportedServiceNames(), vals );
254
0
    }
255
256
257
    void UnoSpinButtonControl::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer >  & rParentPeer )
258
0
    {
259
0
        UnoControl::createPeer( rxToolkit, rParentPeer );
260
261
0
        Reference < XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
262
0
        if ( xSpinnable.is() )
263
0
            xSpinnable->addAdjustmentListener( this );
264
0
    }
265
266
267
    void UnoSpinButtonControl::adjustmentValueChanged( const AdjustmentEvent& rEvent )
268
0
    {
269
0
        switch ( rEvent.Type )
270
0
        {
271
0
            case AdjustmentType_ADJUST_LINE:
272
0
            case AdjustmentType_ADJUST_PAGE:
273
0
            case AdjustmentType_ADJUST_ABS:
274
0
                ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), Any( rEvent.Value ), false );
275
0
                break;
276
0
            default:
277
0
                OSL_FAIL( "UnoSpinButtonControl::adjustmentValueChanged - unknown Type" );
278
0
        }
279
280
0
        if ( maAdjustmentListeners.getLength() )
281
0
        {
282
0
            AdjustmentEvent aEvent( rEvent );
283
0
            aEvent.Source = *this;
284
0
            maAdjustmentListeners.adjustmentValueChanged( aEvent );
285
0
        }
286
0
    }
287
288
289
    void UnoSpinButtonControl::addAdjustmentListener( const Reference< XAdjustmentListener > & listener )
290
0
    {
291
0
        ::osl::MutexGuard aGuard( GetMutex() );
292
0
        maAdjustmentListeners.addInterface( listener );
293
0
    }
294
295
296
    void UnoSpinButtonControl::removeAdjustmentListener( const Reference< XAdjustmentListener > & listener )
297
0
    {
298
0
        ::osl::MutexGuard aGuard( GetMutex() );
299
0
        maAdjustmentListeners.removeInterface( listener );
300
0
    }
301
302
303
    void SAL_CALL UnoSpinButtonControl::setValue( sal_Int32 value )
304
0
    {
305
0
        ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), Any( value ), true );
306
0
    }
307
308
309
    void SAL_CALL UnoSpinButtonControl::setValues( sal_Int32 minValue, sal_Int32 maxValue, sal_Int32 currentValue )
310
0
    {
311
0
        ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN ), Any( minValue ), true );
312
0
        ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX ), Any( maxValue ), true );
313
0
        ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE ), Any( currentValue ), true );
314
0
    }
315
316
317
    sal_Int32 SAL_CALL UnoSpinButtonControl::getValue(  )
318
0
    {
319
0
        ::osl::MutexGuard aGuard( GetMutex() );
320
0
        sal_Int32 nValue = 0;
321
322
0
        Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
323
0
        if ( xSpinnable.is() )
324
0
            nValue = xSpinnable->getValue();
325
326
0
        return nValue;
327
0
    }
328
329
330
    void SAL_CALL UnoSpinButtonControl::setMinimum( sal_Int32 minValue )
331
0
    {
332
0
        ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MIN ), Any( minValue ), true );
333
0
    }
334
335
336
    void SAL_CALL UnoSpinButtonControl::setMaximum( sal_Int32 maxValue )
337
0
    {
338
0
        ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPINVALUE_MAX ), Any( maxValue ), true );
339
0
    }
340
341
342
    sal_Int32 SAL_CALL UnoSpinButtonControl::getMinimum(  )
343
0
    {
344
0
        ::osl::MutexGuard aGuard( GetMutex() );
345
0
        sal_Int32 nMin = 0;
346
347
0
        Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
348
0
        if ( xSpinnable.is() )
349
0
            nMin = xSpinnable->getMinimum();
350
351
0
        return nMin;
352
0
    }
353
354
355
    sal_Int32 SAL_CALL UnoSpinButtonControl::getMaximum(  )
356
0
    {
357
0
        ::osl::MutexGuard aGuard( GetMutex() );
358
0
        sal_Int32 nMax = 0;
359
360
0
        Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
361
0
        if ( xSpinnable.is() )
362
0
            nMax = xSpinnable->getMaximum();
363
364
0
        return nMax;
365
0
    }
366
367
368
    void SAL_CALL UnoSpinButtonControl::setSpinIncrement( sal_Int32 spinIncrement )
369
0
    {
370
0
        ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SPININCREMENT ), Any( spinIncrement ), true );
371
0
    }
372
373
374
    sal_Int32 SAL_CALL UnoSpinButtonControl::getSpinIncrement(  )
375
0
    {
376
0
        ::osl::MutexGuard aGuard( GetMutex() );
377
0
        sal_Int32 nIncrement = 0;
378
379
0
        Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
380
0
        if ( xSpinnable.is() )
381
0
            nIncrement = xSpinnable->getSpinIncrement();
382
383
0
        return nIncrement;
384
0
    }
385
386
387
    void SAL_CALL UnoSpinButtonControl::setOrientation( sal_Int32 orientation )
388
0
    {
389
0
        ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION ), Any( orientation ), true );
390
0
    }
391
392
393
    sal_Int32 SAL_CALL UnoSpinButtonControl::getOrientation(  )
394
0
    {
395
0
        ::osl::MutexGuard aGuard( GetMutex() );
396
0
        sal_Int32 nOrientation = ScrollBarOrientation::HORIZONTAL;
397
398
0
        Reference< XSpinValue > xSpinnable( getPeer(), UNO_QUERY );
399
0
        if ( xSpinnable.is() )
400
0
            nOrientation = xSpinnable->getOrientation();
401
402
0
        return nOrientation;
403
0
    }
404
405
}
406
407
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
408
stardiv_Toolkit_UnoSpinButtonModel_get_implementation(
409
    css::uno::XComponentContext *context,
410
    css::uno::Sequence<css::uno::Any> const &)
411
0
{
412
0
    return cppu::acquire(new UnoSpinButtonModel(context));
413
0
}
414
415
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
416
stardiv_Toolkit_UnoSpinButtonControl_get_implementation(
417
    css::uno::XComponentContext *,
418
    css::uno::Sequence<css::uno::Any> const &)
419
0
{
420
0
    return cppu::acquire(new UnoSpinButtonControl());
421
0
}
422
423
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */