1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "spinbutton.hxx"
21 #include "scrollbar.hxx"
22 #include <comphelper/property.hxx>
23 #include <comphelper/streamsection.hxx>
24 #include <comphelper/basicio.hxx>
25 #include <tools/debug.hxx>
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <com/sun/star/form/FormComponentType.hpp>
28 #include <property.hxx>
29 #include <services.hxx>
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::beans
;
37 using namespace ::com::sun::star::form
;
38 using namespace ::com::sun::star::util
;
39 using namespace ::com::sun::star::io
;
44 OSpinButtonModel::OSpinButtonModel( const Reference
<XComponentContext
>& _rxFactory
)
45 :OBoundControlModel( _rxFactory
, VCL_CONTROLMODEL_SPINBUTTON
, VCL_CONTROL_SPINBUTTON
, true, true, false )
46 ,m_nDefaultSpinValue( 0 )
49 m_nClassId
= FormComponentType::SPINBUTTON
;
50 initValueProperty( PROPERTY_SPIN_VALUE
, PROPERTY_ID_SPIN_VALUE
);
54 OSpinButtonModel::OSpinButtonModel( const OSpinButtonModel
* _pOriginal
, const Reference
< XComponentContext
>& _rxFactory
)
55 :OBoundControlModel( _pOriginal
, _rxFactory
)
57 m_nDefaultSpinValue
= _pOriginal
->m_nDefaultSpinValue
;
61 OSpinButtonModel::~OSpinButtonModel( )
65 OUString SAL_CALL
OSpinButtonModel::getImplementationName()
67 return u
"com.sun.star.comp.forms.OSpinButtonModel"_ustr
;
70 // note that we're passing OControlModel as "base class". This is because
71 // OBoundControlModel, our real base class, claims to support the DataAwareControlModel
72 // service, which isn't really true for us. We only derive from this class
73 // to benefit from the functionality for binding to spreadsheet cells
74 Sequence
< OUString
> SAL_CALL
OSpinButtonModel::getSupportedServiceNames()
76 static constexpr OUString aOwnNames
[] { FRM_SUN_COMPONENT_SPINBUTTON
, BINDABLE_INTEGER_VALUE_RANGE
};
78 return ::comphelper::combineSequences(
79 getAggregateServiceNames(),
80 ::comphelper::concatSequences(
81 OControlModel::getSupportedServiceNames_Static(),
87 css::uno::Reference
< css::util::XCloneable
> SAL_CALL
OSpinButtonModel::createClone()
89 rtl::Reference
<OSpinButtonModel
> pClone
= new OSpinButtonModel(this, getContext());
90 pClone
->clonedFrom(this);
95 void OSpinButtonModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
97 OControlModel::describeFixedProperties( _rProps
);
98 sal_Int32 nOldCount
= _rProps
.getLength();
99 _rProps
.realloc( nOldCount
+ 3);
100 css::beans::Property
* pProperties
= _rProps
.getArray() + nOldCount
;
101 *pProperties
++ = css::beans::Property(PROPERTY_DEFAULT_SPIN_VALUE
, PROPERTY_ID_DEFAULT_SPIN_VALUE
, cppu::UnoType
<sal_Int32
>::get(), css::beans::PropertyAttribute::BOUND
);
102 *pProperties
++ = css::beans::Property(PROPERTY_TABINDEX
, PROPERTY_ID_TABINDEX
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::BOUND
);
103 *pProperties
++ = css::beans::Property(PROPERTY_CONTROLSOURCEPROPERTY
, PROPERTY_ID_CONTROLSOURCEPROPERTY
, cppu::UnoType
<OUString
>::get(), css::beans::PropertyAttribute::READONLY
| css::beans::PropertyAttribute::TRANSIENT
);
104 DBG_ASSERT( pProperties
== _rProps
.getArray() + _rProps
.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
108 void OSpinButtonModel::getFastPropertyValue( Any
& _rValue
, sal_Int32 _nHandle
) const
112 case PROPERTY_ID_DEFAULT_SPIN_VALUE
:
113 _rValue
<<= m_nDefaultSpinValue
;
117 OBoundControlModel::getFastPropertyValue( _rValue
, _nHandle
);
122 void OSpinButtonModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle
, const Any
& _rValue
)
126 case PROPERTY_ID_DEFAULT_SPIN_VALUE
:
127 OSL_VERIFY( _rValue
>>= m_nDefaultSpinValue
);
132 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle
, _rValue
);
137 sal_Bool
OSpinButtonModel::convertFastPropertyValue(
138 Any
& _rConvertedValue
, Any
& _rOldValue
, sal_Int32 _nHandle
, const Any
& _rValue
)
140 bool bModified( false );
143 case PROPERTY_ID_DEFAULT_SPIN_VALUE
:
144 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_nDefaultSpinValue
);
148 bModified
= OBoundControlModel::convertFastPropertyValue( _rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
155 Any
OSpinButtonModel::getPropertyDefaultByHandle( sal_Int32 _nHandle
) const
161 case PROPERTY_ID_DEFAULT_SPIN_VALUE
:
162 aReturn
<<= sal_Int32(0);
166 aReturn
= OBoundControlModel::getPropertyDefaultByHandle( _nHandle
);
174 Any
OSpinButtonModel::translateDbColumnToControlValue( )
176 OSL_FAIL( "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
181 bool OSpinButtonModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
183 OSL_FAIL( "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
188 Any
OSpinButtonModel::getDefaultForReset() const
190 return Any( m_nDefaultSpinValue
);
194 OUString SAL_CALL
OSpinButtonModel::getServiceName()
196 return FRM_SUN_COMPONENT_SPINBUTTON
;
200 void SAL_CALL
OSpinButtonModel::write( const Reference
< XObjectOutputStream
>& _rxOutStream
)
202 OBoundControlModel::write( _rxOutStream
);
203 ::osl::MutexGuard
aGuard( m_aMutex
);
205 OStreamSection
aSection( _rxOutStream
);
208 _rxOutStream
->writeShort( 0x0001 );
211 _rxOutStream
<< m_nDefaultSpinValue
;
212 writeHelpTextCompatibly( _rxOutStream
);
216 void SAL_CALL
OSpinButtonModel::read( const Reference
< XObjectInputStream
>& _rxInStream
)
218 OBoundControlModel::read( _rxInStream
);
219 ::osl::MutexGuard
aGuard( m_aMutex
);
223 OStreamSection
aSection( _rxInStream
);
225 sal_uInt16 nVersion
= _rxInStream
->readShort();
226 if ( nVersion
== 0x0001 )
228 _rxInStream
>> m_nDefaultSpinValue
;
229 readHelpTextCompatibly( _rxInStream
);
232 defaultCommonProperties();
234 // here, everything in the stream section which is left will be skipped
239 Any
OSpinButtonModel::translateExternalValueToControlValue( const Any
& _rExternalValue
) const
241 return translateExternalDoubleToControlIntValue( _rExternalValue
, m_xAggregateSet
,
242 u
"SpinValueMin"_ustr
,
243 u
"SpinValueMax"_ustr
);
247 Any
OSpinButtonModel::translateControlValueToExternalValue( ) const
249 // by definition, the base class simply obtains the property value
250 return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
254 Sequence
< Type
> OSpinButtonModel::getSupportedBindingTypes()
256 return Sequence
< Type
>( &cppu::UnoType
<double>::get(), 1 );
261 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
262 com_sun_star_comp_forms_OSpinButtonModel_get_implementation(css::uno::XComponentContext
* component
,
263 css::uno::Sequence
<css::uno::Any
> const &)
265 return cppu::acquire(new frm::OSpinButtonModel(component
));
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */