update credits
[LibreOffice.git] / forms / source / component / scrollbar.cxx
blobfbab6e7ad2e0305989a26b111d67f64bde93380c
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 "scrollbar.hxx"
21 #include <comphelper/streamsection.hxx>
22 #include <comphelper/basicio.hxx>
23 #include <rtl/math.hxx>
25 //--------------------------------------------------------------------------
26 extern "C" void SAL_CALL createRegistryInfo_OScrollBarModel()
28 static ::frm::OMultiInstanceAutoRegistration< ::frm::OScrollBarModel > aRegisterModel;
31 //........................................................................
32 namespace frm
34 //........................................................................
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::beans;
38 using namespace ::com::sun::star::form;
39 using namespace ::com::sun::star::awt;
40 using namespace ::com::sun::star::lang;
41 using namespace ::com::sun::star::util;
42 using namespace ::com::sun::star::io;
43 using namespace ::com::sun::star::form::binding;
45 //====================================================================
46 //= helper
47 //====================================================================
48 //--------------------------------------------------------------------
49 Any translateExternalDoubleToControlIntValue(
50 const Any& _rExternalValue, const Reference< XPropertySet >& _rxProperties,
51 const OUString& _rMinValueName, const OUString& _rMaxValueName )
53 OSL_ENSURE( _rxProperties.is(), "translateExternalDoubleToControlIntValue: no aggregate!?" );
55 sal_Int32 nControlValue( 0 );
56 double nExternalValue = 0;
57 if ( _rExternalValue >>= nExternalValue )
59 if ( ::rtl::math::isInf( nExternalValue ) )
61 // set the minimum or maximum of the scroll values
62 OUString sLimitPropertyName = ::rtl::math::isSignBitSet( nExternalValue )
63 ? _rMinValueName : _rMaxValueName;
64 if ( _rxProperties.is() )
65 _rxProperties->getPropertyValue( sLimitPropertyName ) >>= nControlValue;
67 else
69 nControlValue = (sal_Int32)::rtl::math::round( nExternalValue );
72 else
74 if ( _rxProperties.is() )
75 _rxProperties->getPropertyValue( _rMinValueName ) >>= nControlValue;
78 return makeAny( nControlValue );
81 //--------------------------------------------------------------------
82 Any translateControlIntToExternalDoubleValue( const Any& _rControlIntValue )
84 Any aExternalDoubleValue;
85 sal_Int32 nScrollValue = 0;
86 if ( _rControlIntValue >>= nScrollValue )
87 aExternalDoubleValue <<= (double)nScrollValue;
88 else
90 OSL_FAIL( "translateControlIntToExternalDoubleValue: no integer scroll value!" );
91 // aExternalDoubleValue is void here, which is okay for this purpose ...
94 return aExternalDoubleValue;
97 //====================================================================
98 //= OScrollBarModel
99 //====================================================================
100 //--------------------------------------------------------------------
101 DBG_NAME( OScrollBarModel )
102 //--------------------------------------------------------------------
103 OScrollBarModel::OScrollBarModel( const Reference<XMultiServiceFactory>& _rxFactory )
104 :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_SCROLLBAR, VCL_CONTROL_SCROLLBAR, sal_True, sal_True, sal_False )
105 ,m_nDefaultScrollValue( 0 )
107 DBG_CTOR( OScrollBarModel, NULL );
109 m_nClassId = FormComponentType::SCROLLBAR;
110 initValueProperty( PROPERTY_SCROLL_VALUE, PROPERTY_ID_SCROLL_VALUE );
113 //--------------------------------------------------------------------
114 OScrollBarModel::OScrollBarModel( const OScrollBarModel* _pOriginal, const Reference< XMultiServiceFactory >& _rxFactory )
115 :OBoundControlModel( _pOriginal, _rxFactory )
117 DBG_CTOR( OScrollBarModel, NULL );
118 m_nDefaultScrollValue = _pOriginal->m_nDefaultScrollValue;
121 //--------------------------------------------------------------------
122 OScrollBarModel::~OScrollBarModel( )
124 DBG_DTOR( OScrollBarModel, NULL );
127 //--------------------------------------------------------------------
128 IMPLEMENT_SERVICE_REGISTRATION_2( OScrollBarModel, OControlModel, FRM_SUN_COMPONENT_SCROLLBAR, BINDABLE_INTEGER_VALUE_RANGE )
129 // note that we're passing OControlModel as "base class". This is because
130 // OBoundControlModel, our real base class, claims to support the DataAwareControlModel
131 // service, which isn't really true for us. We only derive from this class
132 // to benefit from the functionality for binding to spreadsheet cells
134 //------------------------------------------------------------------------------
135 IMPLEMENT_DEFAULT_CLONING( OScrollBarModel )
137 //------------------------------------------------------------------------------
138 void SAL_CALL OScrollBarModel::disposing()
140 OBoundControlModel::disposing();
143 //--------------------------------------------------------------------
144 void OScrollBarModel::describeFixedProperties( Sequence< Property >& _rProps ) const
146 BEGIN_DESCRIBE_PROPERTIES( 3, OControlModel )
147 DECL_PROP1( DEFAULT_SCROLL_VALUE, sal_Int32, BOUND );
148 DECL_PROP1( TABINDEX, sal_Int16, BOUND );
149 DECL_PROP2( CONTROLSOURCEPROPERTY,OUString, READONLY, TRANSIENT );
150 END_DESCRIBE_PROPERTIES();
153 //------------------------------------------------------------------------------
154 void OScrollBarModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
156 switch ( _nHandle )
158 case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
159 _rValue <<= m_nDefaultScrollValue;
160 break;
162 default:
163 OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
167 //------------------------------------------------------------------------------
168 void OScrollBarModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception )
170 switch ( _nHandle )
172 case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
173 OSL_VERIFY( _rValue >>= m_nDefaultScrollValue );
174 resetNoBroadcast();
175 break;
177 default:
178 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
182 //------------------------------------------------------------------------------
183 sal_Bool OScrollBarModel::convertFastPropertyValue(
184 Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
185 throw ( IllegalArgumentException )
187 sal_Bool bModified( sal_False );
188 switch ( _nHandle )
190 case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
191 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nDefaultScrollValue );
192 break;
194 default:
195 bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
196 break;
198 return bModified;
201 //--------------------------------------------------------------------
202 Any OScrollBarModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
204 Any aReturn;
206 switch ( _nHandle )
208 case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
209 aReturn <<= (sal_Int32)0;
210 break;
212 default:
213 aReturn = OBoundControlModel::getPropertyDefaultByHandle( _nHandle );
214 break;
217 return aReturn;
220 //------------------------------------------------------------------------------
221 Any OScrollBarModel::translateDbColumnToControlValue( )
223 OSL_FAIL( "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
224 return Any();
227 //------------------------------------------------------------------------------
228 sal_Bool OScrollBarModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
230 OSL_FAIL( "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
231 return sal_True;
234 //------------------------------------------------------------------------------
235 Any OScrollBarModel::getDefaultForReset() const
237 return makeAny( (sal_Int32)m_nDefaultScrollValue );
240 //--------------------------------------------------------------------
241 OUString SAL_CALL OScrollBarModel::getServiceName() throw( RuntimeException )
243 return OUString(FRM_SUN_COMPONENT_SCROLLBAR);
246 //--------------------------------------------------------------------
247 void SAL_CALL OScrollBarModel::write( const Reference< XObjectOutputStream >& _rxOutStream )
248 throw( IOException, RuntimeException )
250 OBoundControlModel::write( _rxOutStream );
251 ::osl::MutexGuard aGuard( m_aMutex );
253 OStreamSection aSection( Reference< XDataOutputStream >( _rxOutStream, UNO_QUERY ) );
255 // version
256 _rxOutStream->writeShort( 0x0001 );
258 // properties
259 _rxOutStream << m_nDefaultScrollValue;
260 writeHelpTextCompatibly( _rxOutStream );
263 //--------------------------------------------------------------------
264 void SAL_CALL OScrollBarModel::read( const Reference< XObjectInputStream>& _rxInStream ) throw( IOException, RuntimeException )
266 OBoundControlModel::read( _rxInStream );
267 ::osl::MutexGuard aGuard( m_aMutex );
269 // version
271 OStreamSection aSection( Reference< XDataInputStream >( _rxInStream, UNO_QUERY ) );
273 sal_uInt16 nVersion = _rxInStream->readShort();
274 if ( nVersion == 0x0001 )
276 _rxInStream >> m_nDefaultScrollValue;
277 readHelpTextCompatibly( _rxInStream );
279 else
280 defaultCommonProperties();
282 // here, everything in the stream section which is left will be skipped
286 //--------------------------------------------------------------------
287 Any OScrollBarModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
289 return translateExternalDoubleToControlIntValue( _rExternalValue, m_xAggregateSet,
290 OUString( "ScrollValueMin" ),
291 OUString( "ScrollValueMax" ) );
294 //--------------------------------------------------------------------
295 Any OScrollBarModel::translateControlValueToExternalValue( ) const
297 // by definition, the base class simply obtains the property value
298 return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
301 //--------------------------------------------------------------------
302 Sequence< Type > OScrollBarModel::getSupportedBindingTypes()
304 return Sequence< Type >( &::getCppuType( static_cast< double* >( NULL ) ), 1 );
307 //........................................................................
308 } // namespace frm
309 //........................................................................
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */