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::awt
;
39 using namespace ::com::sun::star::lang
;
40 using namespace ::com::sun::star::util
;
41 using namespace ::com::sun::star::io
;
42 using namespace ::com::sun::star::form::binding
;
47 OSpinButtonModel::OSpinButtonModel( const Reference
<XComponentContext
>& _rxFactory
)
48 :OBoundControlModel( _rxFactory
, VCL_CONTROLMODEL_SPINBUTTON
, VCL_CONTROL_SPINBUTTON
, true, true, false )
49 ,m_nDefaultSpinValue( 0 )
52 m_nClassId
= FormComponentType::SPINBUTTON
;
53 initValueProperty( PROPERTY_SPIN_VALUE
, PROPERTY_ID_SPIN_VALUE
);
57 OSpinButtonModel::OSpinButtonModel( const OSpinButtonModel
* _pOriginal
, const Reference
< XComponentContext
>& _rxFactory
)
58 :OBoundControlModel( _pOriginal
, _rxFactory
)
60 m_nDefaultSpinValue
= _pOriginal
->m_nDefaultSpinValue
;
64 OSpinButtonModel::~OSpinButtonModel( )
68 OUString SAL_CALL
OSpinButtonModel::getImplementationName()
70 return "com.sun.star.comp.forms.OSpinButtonModel";
73 // note that we're passing OControlModel as "base class". This is because
74 // OBoundControlModel, our real base class, claims to support the DataAwareControlModel
75 // service, which isn't really true for us. We only derive from this class
76 // to benefit from the functionality for binding to spreadsheet cells
77 Sequence
< OUString
> SAL_CALL
OSpinButtonModel::getSupportedServiceNames()
79 Sequence
< OUString
> aOwnNames
{ FRM_SUN_COMPONENT_SPINBUTTON
, BINDABLE_INTEGER_VALUE_RANGE
};
81 return ::comphelper::combineSequences(
82 getAggregateServiceNames(),
83 ::comphelper::concatSequences(
84 OControlModel::getSupportedServiceNames_Static(),
90 css::uno::Reference
< css::util::XCloneable
> SAL_CALL
OSpinButtonModel::createClone()
92 rtl::Reference
<OSpinButtonModel
> pClone
= new OSpinButtonModel(this, getContext());
93 pClone
->clonedFrom(this);
98 void OSpinButtonModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
100 OControlModel::describeFixedProperties( _rProps
);
101 sal_Int32 nOldCount
= _rProps
.getLength();
102 _rProps
.realloc( nOldCount
+ 3);
103 css::beans::Property
* pProperties
= _rProps
.getArray() + nOldCount
;
104 *pProperties
++ = css::beans::Property(PROPERTY_DEFAULT_SPIN_VALUE
, PROPERTY_ID_DEFAULT_SPIN_VALUE
, cppu::UnoType
<sal_Int32
>::get(), css::beans::PropertyAttribute::BOUND
);
105 *pProperties
++ = css::beans::Property(PROPERTY_TABINDEX
, PROPERTY_ID_TABINDEX
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::BOUND
);
106 *pProperties
++ = css::beans::Property(PROPERTY_CONTROLSOURCEPROPERTY
, PROPERTY_ID_CONTROLSOURCEPROPERTY
, cppu::UnoType
<OUString
>::get(), css::beans::PropertyAttribute::READONLY
| css::beans::PropertyAttribute::TRANSIENT
);
107 DBG_ASSERT( pProperties
== _rProps
.getArray() + _rProps
.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
111 void OSpinButtonModel::getFastPropertyValue( Any
& _rValue
, sal_Int32 _nHandle
) const
115 case PROPERTY_ID_DEFAULT_SPIN_VALUE
:
116 _rValue
<<= m_nDefaultSpinValue
;
120 OBoundControlModel::getFastPropertyValue( _rValue
, _nHandle
);
125 void OSpinButtonModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle
, const Any
& _rValue
)
129 case PROPERTY_ID_DEFAULT_SPIN_VALUE
:
130 OSL_VERIFY( _rValue
>>= m_nDefaultSpinValue
);
135 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle
, _rValue
);
140 sal_Bool
OSpinButtonModel::convertFastPropertyValue(
141 Any
& _rConvertedValue
, Any
& _rOldValue
, sal_Int32 _nHandle
, const Any
& _rValue
)
143 bool bModified( false );
146 case PROPERTY_ID_DEFAULT_SPIN_VALUE
:
147 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_nDefaultSpinValue
);
151 bModified
= OBoundControlModel::convertFastPropertyValue( _rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
158 Any
OSpinButtonModel::getPropertyDefaultByHandle( sal_Int32 _nHandle
) const
164 case PROPERTY_ID_DEFAULT_SPIN_VALUE
:
165 aReturn
<<= sal_Int32(0);
169 aReturn
= OBoundControlModel::getPropertyDefaultByHandle( _nHandle
);
177 Any
OSpinButtonModel::translateDbColumnToControlValue( )
179 OSL_FAIL( "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
184 bool OSpinButtonModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
186 OSL_FAIL( "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
191 Any
OSpinButtonModel::getDefaultForReset() const
193 return Any( m_nDefaultSpinValue
);
197 OUString SAL_CALL
OSpinButtonModel::getServiceName()
199 return FRM_SUN_COMPONENT_SPINBUTTON
;
203 void SAL_CALL
OSpinButtonModel::write( const Reference
< XObjectOutputStream
>& _rxOutStream
)
205 OBoundControlModel::write( _rxOutStream
);
206 ::osl::MutexGuard
aGuard( m_aMutex
);
208 OStreamSection
aSection( _rxOutStream
);
211 _rxOutStream
->writeShort( 0x0001 );
214 _rxOutStream
<< m_nDefaultSpinValue
;
215 writeHelpTextCompatibly( _rxOutStream
);
219 void SAL_CALL
OSpinButtonModel::read( const Reference
< XObjectInputStream
>& _rxInStream
)
221 OBoundControlModel::read( _rxInStream
);
222 ::osl::MutexGuard
aGuard( m_aMutex
);
226 OStreamSection
aSection( _rxInStream
);
228 sal_uInt16 nVersion
= _rxInStream
->readShort();
229 if ( nVersion
== 0x0001 )
231 _rxInStream
>> m_nDefaultSpinValue
;
232 readHelpTextCompatibly( _rxInStream
);
235 defaultCommonProperties();
237 // here, everything in the stream section which is left will be skipped
242 Any
OSpinButtonModel::translateExternalValueToControlValue( const Any
& _rExternalValue
) const
244 return translateExternalDoubleToControlIntValue( _rExternalValue
, m_xAggregateSet
,
250 Any
OSpinButtonModel::translateControlValueToExternalValue( ) const
252 // by definition, the base class simply obtains the property value
253 return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
257 Sequence
< Type
> OSpinButtonModel::getSupportedBindingTypes()
259 return Sequence
< Type
>( &cppu::UnoType
<double>::get(), 1 );
264 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
265 com_sun_star_comp_forms_OSpinButtonModel_get_implementation(css::uno::XComponentContext
* component
,
266 css::uno::Sequence
<css::uno::Any
> const &)
268 return cppu::acquire(new frm::OSpinButtonModel(component
));
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */