update dev300-m58
[ooovba.git] / forms / source / component / scrollbar.cxx
blob6c6ddf7f1c27d628bec6de5139255366ca0a250b
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: scrollbar.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 "scrollbar.hxx"
34 #include <comphelper/streamsection.hxx>
35 #include <comphelper/basicio.hxx>
36 #include <rtl/math.hxx>
38 //--------------------------------------------------------------------------
39 extern "C" void SAL_CALL createRegistryInfo_OScrollBarModel()
41 static ::frm::OMultiInstanceAutoRegistration< ::frm::OScrollBarModel > aRegisterModel;
44 //........................................................................
45 namespace frm
47 //........................................................................
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::beans;
51 using namespace ::com::sun::star::form;
52 using namespace ::com::sun::star::awt;
53 using namespace ::com::sun::star::lang;
54 using namespace ::com::sun::star::util;
55 using namespace ::com::sun::star::io;
56 using namespace ::com::sun::star::form::binding;
58 //====================================================================
59 //= helper
60 //====================================================================
61 //--------------------------------------------------------------------
62 Any translateExternalDoubleToControlIntValue(
63 const Any& _rExternalValue, const Reference< XPropertySet >& _rxProperties,
64 const ::rtl::OUString& _rMinValueName, const ::rtl::OUString& _rMaxValueName )
66 OSL_ENSURE( _rxProperties.is(), "translateExternalDoubleToControlIntValue: no aggregate!?" );
68 sal_Int32 nControlValue( 0 );
69 double nExternalValue = 0;
70 if ( _rExternalValue >>= nExternalValue )
72 if ( ::rtl::math::isInf( nExternalValue ) )
74 // set the minimum or maximum of the scroll values
75 ::rtl::OUString sLimitPropertyName = ::rtl::math::isSignBitSet( nExternalValue )
76 ? _rMinValueName : _rMaxValueName;
77 if ( _rxProperties.is() )
78 _rxProperties->getPropertyValue( sLimitPropertyName ) >>= nControlValue;
80 else
82 nControlValue = (sal_Int32)::rtl::math::round( nExternalValue );
85 else
87 if ( _rxProperties.is() )
88 _rxProperties->getPropertyValue( _rMinValueName ) >>= nControlValue;
91 return makeAny( nControlValue );
94 //--------------------------------------------------------------------
95 Any translateControlIntToExternalDoubleValue( const Any& _rControlIntValue )
97 Any aExternalDoubleValue;
98 sal_Int32 nScrollValue = 0;
99 if ( _rControlIntValue >>= nScrollValue )
100 aExternalDoubleValue <<= (double)nScrollValue;
101 else
103 OSL_ENSURE( sal_False, "translateControlIntToExternalDoubleValue: no integer scroll value!" );
104 // aExternalDoubleValue is void here, which is okay for this purpose ...
107 return aExternalDoubleValue;
110 //====================================================================
111 //= OScrollBarModel
112 //====================================================================
113 //--------------------------------------------------------------------
114 DBG_NAME( OScrollBarModel )
115 //--------------------------------------------------------------------
116 OScrollBarModel::OScrollBarModel( const Reference<XMultiServiceFactory>& _rxFactory )
117 :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_SCROLLBAR, VCL_CONTROL_SCROLLBAR, sal_True, sal_True, sal_False )
118 ,m_nDefaultScrollValue( 0 )
120 DBG_CTOR( OScrollBarModel, NULL );
122 m_nClassId = FormComponentType::SCROLLBAR;
123 initValueProperty( PROPERTY_SCROLL_VALUE, PROPERTY_ID_SCROLL_VALUE );
126 //--------------------------------------------------------------------
127 OScrollBarModel::OScrollBarModel( const OScrollBarModel* _pOriginal, const Reference< XMultiServiceFactory >& _rxFactory )
128 :OBoundControlModel( _pOriginal, _rxFactory )
130 DBG_CTOR( OScrollBarModel, NULL );
131 m_nDefaultScrollValue = _pOriginal->m_nDefaultScrollValue;
134 //--------------------------------------------------------------------
135 OScrollBarModel::~OScrollBarModel( )
137 DBG_DTOR( OScrollBarModel, NULL );
140 //--------------------------------------------------------------------
141 IMPLEMENT_SERVICE_REGISTRATION_2( OScrollBarModel, OControlModel, FRM_SUN_COMPONENT_SCROLLBAR, BINDABLE_INTEGER_VALUE_RANGE )
142 // note that we're passing OControlModel as "base class". This is because
143 // OBoundControlModel, our real base class, claims to support the DataAwareControlModel
144 // service, which isn't really true for us. We only derive from this class
145 // to benefit from the functionality for binding to spreadsheet cells
147 //------------------------------------------------------------------------------
148 IMPLEMENT_DEFAULT_CLONING( OScrollBarModel )
150 //------------------------------------------------------------------------------
151 void SAL_CALL OScrollBarModel::disposing()
153 OBoundControlModel::disposing();
156 //--------------------------------------------------------------------
157 void OScrollBarModel::describeFixedProperties( Sequence< Property >& _rProps ) const
159 BEGIN_DESCRIBE_PROPERTIES( 3, OControlModel )
160 DECL_PROP1( DEFAULT_SCROLL_VALUE, sal_Int32, BOUND );
161 DECL_PROP1( TABINDEX, sal_Int16, BOUND );
162 DECL_PROP2( CONTROLSOURCEPROPERTY,::rtl::OUString, READONLY, TRANSIENT );
163 END_DESCRIBE_PROPERTIES();
166 //------------------------------------------------------------------------------
167 void OScrollBarModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
169 switch ( _nHandle )
171 case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
172 _rValue <<= m_nDefaultScrollValue;
173 break;
175 default:
176 OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
180 //------------------------------------------------------------------------------
181 void OScrollBarModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception )
183 switch ( _nHandle )
185 case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
186 OSL_VERIFY( _rValue >>= m_nDefaultScrollValue );
187 resetNoBroadcast();
188 break;
190 default:
191 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
195 //------------------------------------------------------------------------------
196 sal_Bool OScrollBarModel::convertFastPropertyValue(
197 Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
198 throw ( IllegalArgumentException )
200 sal_Bool bModified( sal_False );
201 switch ( _nHandle )
203 case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
204 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nDefaultScrollValue );
205 break;
207 default:
208 bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
209 break;
211 return bModified;
214 //--------------------------------------------------------------------
215 Any OScrollBarModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
217 Any aReturn;
219 switch ( _nHandle )
221 case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
222 aReturn <<= (sal_Int32)0;
223 break;
225 default:
226 aReturn = OBoundControlModel::getPropertyDefaultByHandle( _nHandle );
227 break;
230 return aReturn;
233 //------------------------------------------------------------------------------
234 Any OScrollBarModel::translateDbColumnToControlValue( )
236 OSL_ENSURE( sal_False, "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
237 return Any();
240 //------------------------------------------------------------------------------
241 sal_Bool OScrollBarModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
243 OSL_ENSURE( sal_False, "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
244 return sal_True;
247 //------------------------------------------------------------------------------
248 Any OScrollBarModel::getDefaultForReset() const
250 return makeAny( (sal_Int32)m_nDefaultScrollValue );
253 //--------------------------------------------------------------------
254 ::rtl::OUString SAL_CALL OScrollBarModel::getServiceName() throw( RuntimeException )
256 return FRM_SUN_COMPONENT_SCROLLBAR;
259 //--------------------------------------------------------------------
260 void SAL_CALL OScrollBarModel::write( const Reference< XObjectOutputStream >& _rxOutStream )
261 throw( IOException, RuntimeException )
263 OBoundControlModel::write( _rxOutStream );
264 ::osl::MutexGuard aGuard( m_aMutex );
266 OStreamSection aSection( Reference< XDataOutputStream >( _rxOutStream, UNO_QUERY ) );
268 // version
269 _rxOutStream->writeShort( 0x0001 );
271 // properties
272 _rxOutStream << m_nDefaultScrollValue;
273 writeHelpTextCompatibly( _rxOutStream );
276 //--------------------------------------------------------------------
277 void SAL_CALL OScrollBarModel::read( const Reference< XObjectInputStream>& _rxInStream ) throw( IOException, RuntimeException )
279 OBoundControlModel::read( _rxInStream );
280 ::osl::MutexGuard aGuard( m_aMutex );
282 // version
284 OStreamSection aSection( Reference< XDataInputStream >( _rxInStream, UNO_QUERY ) );
286 sal_uInt16 nVersion = _rxInStream->readShort();
287 if ( nVersion == 0x0001 )
289 _rxInStream >> m_nDefaultScrollValue;
290 readHelpTextCompatibly( _rxInStream );
292 else
293 defaultCommonProperties();
295 // here, everything in the stream section which is left will be skipped
299 //--------------------------------------------------------------------
300 Any OScrollBarModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
302 return translateExternalDoubleToControlIntValue( _rExternalValue, m_xAggregateSet,
303 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScrollValueMin" ) ),
304 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScrollValueMax" ) ) );
307 //--------------------------------------------------------------------
308 Any OScrollBarModel::translateControlValueToExternalValue( ) const
310 // by definition, the base class simply obtains the property value
311 return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
314 //--------------------------------------------------------------------
315 Sequence< Type > OScrollBarModel::getSupportedBindingTypes()
317 return Sequence< Type >( &::getCppuType( static_cast< double* >( NULL ) ), 1 );
320 //........................................................................
321 } // namespace frm
322 //........................................................................