bump product version to 5.0.4.1
[LibreOffice.git] / forms / source / component / spinbutton.cxx
blob77ea31200aaaf47615acfe06d95961f8fa989163
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/streamsection.hxx>
23 #include <comphelper/basicio.hxx>
26 namespace frm
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::beans;
31 using namespace ::com::sun::star::form;
32 using namespace ::com::sun::star::awt;
33 using namespace ::com::sun::star::lang;
34 using namespace ::com::sun::star::util;
35 using namespace ::com::sun::star::io;
36 using namespace ::com::sun::star::form::binding;
39 //= OSpinButtonModel
41 OSpinButtonModel::OSpinButtonModel( const Reference<XComponentContext>& _rxFactory )
42 :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_SPINBUTTON, VCL_CONTROL_SPINBUTTON, true, true, false )
43 ,m_nDefaultSpinValue( 0 )
46 m_nClassId = FormComponentType::SPINBUTTON;
47 initValueProperty( PROPERTY_SPIN_VALUE, PROPERTY_ID_SPIN_VALUE );
51 OSpinButtonModel::OSpinButtonModel( const OSpinButtonModel* _pOriginal, const Reference< XComponentContext >& _rxFactory )
52 :OBoundControlModel( _pOriginal, _rxFactory )
54 m_nDefaultSpinValue = _pOriginal->m_nDefaultSpinValue;
58 OSpinButtonModel::~OSpinButtonModel( )
62 OUString SAL_CALL OSpinButtonModel::getImplementationName() throw ( RuntimeException, std::exception )
64 return OUString( "com.sun.star.comp.forms.OSpinButtonModel" );
67 // note that we're passing OControlModel as "base class". This is because
68 // OBoundControlModel, our real base class, claims to support the DataAwareControlModel
69 // service, which isn't really true for us. We only derive from this class
70 // to benefit from the functionality for binding to spreadsheet cells
71 Sequence< OUString > SAL_CALL OSpinButtonModel::getSupportedServiceNames() throw (RuntimeException, std::exception)
73 Sequence< OUString > aOwnNames( 2 );
74 aOwnNames[ 0 ] = FRM_SUN_COMPONENT_SPINBUTTON;
75 aOwnNames[ 1 ] = BINDABLE_INTEGER_VALUE_RANGE;
77 return ::comphelper::combineSequences(
78 getAggregateServiceNames(),
79 ::comphelper::concatSequences(
80 OControlModel::getSupportedServiceNames_Static(),
81 aOwnNames
86 IMPLEMENT_DEFAULT_CLONING( OSpinButtonModel )
89 void SAL_CALL OSpinButtonModel::disposing()
91 OBoundControlModel::disposing();
95 void OSpinButtonModel::describeFixedProperties( Sequence< Property >& _rProps ) const
97 BEGIN_DESCRIBE_PROPERTIES( 3, OControlModel )
98 DECL_PROP1( DEFAULT_SPIN_VALUE, sal_Int32, BOUND );
99 DECL_PROP1( TABINDEX, sal_Int16, BOUND );
100 DECL_PROP2( CONTROLSOURCEPROPERTY,OUString, READONLY, TRANSIENT );
101 END_DESCRIBE_PROPERTIES();
105 void OSpinButtonModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
107 switch ( _nHandle )
109 case PROPERTY_ID_DEFAULT_SPIN_VALUE:
110 _rValue <<= m_nDefaultSpinValue;
111 break;
113 default:
114 OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
119 void OSpinButtonModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception, std::exception )
121 switch ( _nHandle )
123 case PROPERTY_ID_DEFAULT_SPIN_VALUE:
124 OSL_VERIFY( _rValue >>= m_nDefaultSpinValue );
125 resetNoBroadcast();
126 break;
128 default:
129 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
134 sal_Bool OSpinButtonModel::convertFastPropertyValue(
135 Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
136 throw ( IllegalArgumentException )
138 bool bModified( false );
139 switch ( _nHandle )
141 case PROPERTY_ID_DEFAULT_SPIN_VALUE:
142 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nDefaultSpinValue );
143 break;
145 default:
146 bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
147 break;
149 return bModified;
153 Any OSpinButtonModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
155 Any aReturn;
157 switch ( _nHandle )
159 case PROPERTY_ID_DEFAULT_SPIN_VALUE:
160 aReturn <<= (sal_Int32)0;
161 break;
163 default:
164 aReturn = OBoundControlModel::getPropertyDefaultByHandle( _nHandle );
165 break;
168 return aReturn;
172 Any OSpinButtonModel::translateDbColumnToControlValue( )
174 OSL_FAIL( "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
175 return Any();
179 bool OSpinButtonModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
181 OSL_FAIL( "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
182 return true;
186 Any OSpinButtonModel::getDefaultForReset() const
188 return makeAny( (sal_Int32)m_nDefaultSpinValue );
192 OUString SAL_CALL OSpinButtonModel::getServiceName() throw( RuntimeException, std::exception )
194 return OUString(FRM_SUN_COMPONENT_SPINBUTTON);
198 void SAL_CALL OSpinButtonModel::write( const Reference< XObjectOutputStream >& _rxOutStream )
199 throw( IOException, RuntimeException, std::exception )
201 OBoundControlModel::write( _rxOutStream );
202 ::osl::MutexGuard aGuard( m_aMutex );
204 OStreamSection aSection( _rxOutStream );
206 // version
207 _rxOutStream->writeShort( 0x0001 );
209 // properties
210 _rxOutStream << m_nDefaultSpinValue;
211 writeHelpTextCompatibly( _rxOutStream );
215 void SAL_CALL OSpinButtonModel::read( const Reference< XObjectInputStream>& _rxInStream ) throw( IOException, RuntimeException, std::exception )
217 OBoundControlModel::read( _rxInStream );
218 ::osl::MutexGuard aGuard( m_aMutex );
220 // version
222 OStreamSection aSection( _rxInStream );
224 sal_uInt16 nVersion = _rxInStream->readShort();
225 if ( nVersion == 0x0001 )
227 _rxInStream >> m_nDefaultSpinValue;
228 readHelpTextCompatibly( _rxInStream );
230 else
231 defaultCommonProperties();
233 // here, everything in the stream section which is left will be skipped
238 Any OSpinButtonModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
240 return translateExternalDoubleToControlIntValue( _rExternalValue, m_xAggregateSet,
241 OUString( "SpinValueMin" ),
242 OUString( "SpinValueMax" ) );
246 Any OSpinButtonModel::translateControlValueToExternalValue( ) const
248 // by definition, the base class simply obtains the property value
249 return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
253 Sequence< Type > OSpinButtonModel::getSupportedBindingTypes()
255 return Sequence< Type >( &cppu::UnoType<double>::get(), 1 );
258 } // namespace frm
260 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
261 com_sun_star_comp_forms_OSpinButtonModel_get_implementation(::com::sun::star::uno::XComponentContext* component,
262 ::com::sun::star::uno::Sequence<css::uno::Any> const &)
264 return cppu::acquire(new frm::OSpinButtonModel(component));
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */