merge the formfield patch from ooo-build
[ooovba.git] / forms / source / component / spinbutton.cxx
blobd2903f04362da44fd0f8cfaec75ee06f86c2c6f5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: spinbutton.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_forms.hxx"
33 #include "spinbutton.hxx"
34 #include <comphelper/streamsection.hxx>
35 #include <comphelper/basicio.hxx>
37 //--------------------------------------------------------------------------
38 extern "C" void SAL_CALL createRegistryInfo_OSpinButtonModel()
40 static ::frm::OMultiInstanceAutoRegistration< ::frm::OSpinButtonModel > aRegisterModel;
43 //........................................................................
44 namespace frm
46 //........................................................................
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::beans;
50 using namespace ::com::sun::star::form;
51 using namespace ::com::sun::star::awt;
52 using namespace ::com::sun::star::lang;
53 using namespace ::com::sun::star::util;
54 using namespace ::com::sun::star::io;
55 using namespace ::com::sun::star::form::binding;
57 //====================================================================
58 //= OSpinButtonModel
59 //====================================================================
60 // implemented elsewhere
61 Any translateExternalDoubleToControlIntValue(
62 const Any& _rExternalValue, const Reference< XPropertySet >& _rxProperties,
63 const ::rtl::OUString& _rMinValueName, const ::rtl::OUString& _rMaxValueName );
64 Any translateControlIntToExternalDoubleValue( const Any& _rControlIntValue );
66 //====================================================================
67 //= OSpinButtonModel
68 //====================================================================
69 //--------------------------------------------------------------------
70 DBG_NAME( OSpinButtonModel )
71 //--------------------------------------------------------------------
72 OSpinButtonModel::OSpinButtonModel( const Reference<XMultiServiceFactory>& _rxFactory )
73 :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_SPINBUTTON, VCL_CONTROL_SPINBUTTON, sal_True, sal_True, sal_False )
74 ,m_nDefaultSpinValue( 0 )
76 DBG_CTOR( OSpinButtonModel, NULL );
78 m_nClassId = FormComponentType::SPINBUTTON;
79 initValueProperty( PROPERTY_SPIN_VALUE, PROPERTY_ID_SPIN_VALUE );
82 //--------------------------------------------------------------------
83 OSpinButtonModel::OSpinButtonModel( const OSpinButtonModel* _pOriginal, const Reference< XMultiServiceFactory >& _rxFactory )
84 :OBoundControlModel( _pOriginal, _rxFactory )
86 DBG_CTOR( OSpinButtonModel, NULL );
87 m_nDefaultSpinValue = _pOriginal->m_nDefaultSpinValue;
90 //--------------------------------------------------------------------
91 OSpinButtonModel::~OSpinButtonModel( )
93 DBG_DTOR( OSpinButtonModel, NULL );
96 //--------------------------------------------------------------------
97 IMPLEMENT_SERVICE_REGISTRATION_2( OSpinButtonModel, OControlModel, FRM_SUN_COMPONENT_SPINBUTTON, BINDABLE_INTEGER_VALUE_RANGE )
98 // note that we're passing OControlModel as "base class". This is because
99 // OBoundControlModel, our real base class, claims to support the DataAwareControlModel
100 // service, which isn't really true for us. We only derive from this class
101 // to benefit from the functionality for binding to spreadsheet cells
103 //------------------------------------------------------------------------------
104 IMPLEMENT_DEFAULT_CLONING( OSpinButtonModel )
106 //------------------------------------------------------------------------------
107 void SAL_CALL OSpinButtonModel::disposing()
109 OBoundControlModel::disposing();
112 //--------------------------------------------------------------------
113 void OSpinButtonModel::describeFixedProperties( Sequence< Property >& _rProps ) const
115 BEGIN_DESCRIBE_PROPERTIES( 3, OControlModel )
116 DECL_PROP1( DEFAULT_SPIN_VALUE, sal_Int32, BOUND );
117 DECL_PROP1( TABINDEX, sal_Int16, BOUND );
118 DECL_PROP2( CONTROLSOURCEPROPERTY,::rtl::OUString, READONLY, TRANSIENT );
119 END_DESCRIBE_PROPERTIES();
122 //------------------------------------------------------------------------------
123 void OSpinButtonModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
125 switch ( _nHandle )
127 case PROPERTY_ID_DEFAULT_SPIN_VALUE:
128 _rValue <<= m_nDefaultSpinValue;
129 break;
131 default:
132 OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
136 //------------------------------------------------------------------------------
137 void OSpinButtonModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception )
139 switch ( _nHandle )
141 case PROPERTY_ID_DEFAULT_SPIN_VALUE:
142 OSL_VERIFY( _rValue >>= m_nDefaultSpinValue );
143 resetNoBroadcast();
144 break;
146 default:
147 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
151 //------------------------------------------------------------------------------
152 sal_Bool OSpinButtonModel::convertFastPropertyValue(
153 Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
154 throw ( IllegalArgumentException )
156 sal_Bool bModified( sal_False );
157 switch ( _nHandle )
159 case PROPERTY_ID_DEFAULT_SPIN_VALUE:
160 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nDefaultSpinValue );
161 break;
163 default:
164 bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
165 break;
167 return bModified;
170 //--------------------------------------------------------------------
171 Any OSpinButtonModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
173 Any aReturn;
175 switch ( _nHandle )
177 case PROPERTY_ID_DEFAULT_SPIN_VALUE:
178 aReturn <<= (sal_Int32)0;
179 break;
181 default:
182 aReturn = OBoundControlModel::getPropertyDefaultByHandle( _nHandle );
183 break;
186 return aReturn;
189 //------------------------------------------------------------------------------
190 Any OSpinButtonModel::translateDbColumnToControlValue( )
192 OSL_ENSURE( sal_False, "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
193 return Any();
196 //------------------------------------------------------------------------------
197 sal_Bool OSpinButtonModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
199 OSL_ENSURE( sal_False, "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
200 return sal_True;
203 //------------------------------------------------------------------------------
204 Any OSpinButtonModel::getDefaultForReset() const
206 return makeAny( (sal_Int32)m_nDefaultSpinValue );
209 //--------------------------------------------------------------------
210 ::rtl::OUString SAL_CALL OSpinButtonModel::getServiceName() throw( RuntimeException )
212 return FRM_SUN_COMPONENT_SPINBUTTON;
215 //--------------------------------------------------------------------
216 void SAL_CALL OSpinButtonModel::write( const Reference< XObjectOutputStream >& _rxOutStream )
217 throw( IOException, RuntimeException )
219 OBoundControlModel::write( _rxOutStream );
220 ::osl::MutexGuard aGuard( m_aMutex );
222 OStreamSection aSection( Reference< XDataOutputStream >( _rxOutStream, UNO_QUERY ) );
224 // version
225 _rxOutStream->writeShort( 0x0001 );
227 // properties
228 _rxOutStream << m_nDefaultSpinValue;
229 writeHelpTextCompatibly( _rxOutStream );
232 //--------------------------------------------------------------------
233 void SAL_CALL OSpinButtonModel::read( const Reference< XObjectInputStream>& _rxInStream ) throw( IOException, RuntimeException )
235 OBoundControlModel::read( _rxInStream );
236 ::osl::MutexGuard aGuard( m_aMutex );
238 // version
240 OStreamSection aSection( Reference< XDataInputStream >( _rxInStream, UNO_QUERY ) );
242 sal_uInt16 nVersion = _rxInStream->readShort();
243 if ( nVersion == 0x0001 )
245 _rxInStream >> m_nDefaultSpinValue;
246 readHelpTextCompatibly( _rxInStream );
248 else
249 defaultCommonProperties();
251 // here, everything in the stream section which is left will be skipped
255 //--------------------------------------------------------------------
256 Any OSpinButtonModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
258 return translateExternalDoubleToControlIntValue( _rExternalValue, m_xAggregateSet,
259 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SpinValueMin" ) ),
260 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SpinValueMax" ) ) );
263 //--------------------------------------------------------------------
264 Any OSpinButtonModel::translateControlValueToExternalValue( ) const
266 // by definition, the base class simply obtains the property value
267 return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
270 //--------------------------------------------------------------------
271 Sequence< Type > OSpinButtonModel::getSupportedBindingTypes()
273 return Sequence< Type >( &::getCppuType( static_cast< double* >( NULL ) ), 1 );
276 //........................................................................
277 } // namespace frm
278 //........................................................................