nss: upgrade to release 3.73
[LibreOffice.git] / forms / source / component / scrollbar.cxx
blob4e18dd69ec565cb0264b0716524f47d13d670eae
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 <property.hxx>
22 #include <services.hxx>
23 #include <comphelper/property.hxx>
24 #include <comphelper/streamsection.hxx>
25 #include <comphelper/basicio.hxx>
26 #include <rtl/math.hxx>
27 #include <com/sun/star/form/FormComponentType.hpp>
29 namespace frm
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::beans;
34 using namespace ::com::sun::star::form;
35 using namespace ::com::sun::star::awt;
36 using namespace ::com::sun::star::lang;
37 using namespace ::com::sun::star::util;
38 using namespace ::com::sun::star::io;
39 using namespace ::com::sun::star::form::binding;
42 //= helper
44 Any translateExternalDoubleToControlIntValue(
45 const Any& _rExternalValue, const Reference< XPropertySet >& _rxProperties,
46 const OUString& _rMinValueName, const OUString& _rMaxValueName )
48 OSL_ENSURE( _rxProperties.is(), "translateExternalDoubleToControlIntValue: no aggregate!?" );
50 sal_Int32 nControlValue( 0 );
51 double nExternalValue = 0;
52 if ( _rExternalValue >>= nExternalValue )
54 if ( std::isinf( nExternalValue ) )
56 // set the minimum or maximum of the scroll values
57 OUString sLimitPropertyName = std::signbit( nExternalValue )
58 ? _rMinValueName : _rMaxValueName;
59 if ( _rxProperties.is() )
60 _rxProperties->getPropertyValue( sLimitPropertyName ) >>= nControlValue;
62 else
64 nControlValue = static_cast<sal_Int32>(::rtl::math::round( nExternalValue ));
67 else
69 if ( _rxProperties.is() )
70 _rxProperties->getPropertyValue( _rMinValueName ) >>= nControlValue;
73 return makeAny( nControlValue );
77 Any translateControlIntToExternalDoubleValue( const Any& _rControlIntValue )
79 Any aExternalDoubleValue;
80 sal_Int32 nScrollValue = 0;
81 if ( _rControlIntValue >>= nScrollValue )
82 aExternalDoubleValue <<= static_cast<double>(nScrollValue);
83 else
85 OSL_FAIL( "translateControlIntToExternalDoubleValue: no integer scroll value!" );
86 // aExternalDoubleValue is void here, which is okay for this purpose ...
89 return aExternalDoubleValue;
92 OScrollBarModel::OScrollBarModel( const Reference<XComponentContext>& _rxFactory )
93 :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_SCROLLBAR, VCL_CONTROL_SCROLLBAR, true, true, false )
94 ,m_nDefaultScrollValue( 0 )
97 m_nClassId = FormComponentType::SCROLLBAR;
98 initValueProperty( PROPERTY_SCROLL_VALUE, PROPERTY_ID_SCROLL_VALUE );
102 OScrollBarModel::OScrollBarModel( const OScrollBarModel* _pOriginal, const Reference< XComponentContext >& _rxFactory )
103 :OBoundControlModel( _pOriginal, _rxFactory )
105 m_nDefaultScrollValue = _pOriginal->m_nDefaultScrollValue;
109 OScrollBarModel::~OScrollBarModel( )
113 OUString SAL_CALL OScrollBarModel::getImplementationName()
115 return "com.sun.star.comp.forms.OScrollBarModel";
118 // note that we're passing OControlModel as "base class". This is because
119 // OBoundControlModel, our real base class, claims to support the DataAwareControlModel
120 // service, which isn't really true for us. We only derive from this class
121 // to benefit from the functionality for binding to spreadsheet cells
122 Sequence< OUString > SAL_CALL OScrollBarModel::getSupportedServiceNames()
124 Sequence< OUString > aOwnNames { FRM_SUN_COMPONENT_SCROLLBAR, BINDABLE_INTEGER_VALUE_RANGE };
126 return ::comphelper::combineSequences(
127 getAggregateServiceNames(),
128 ::comphelper::concatSequences(
129 OControlModel::getSupportedServiceNames_Static(),
130 aOwnNames)
134 IMPLEMENT_DEFAULT_CLONING( OScrollBarModel )
137 void OScrollBarModel::describeFixedProperties( Sequence< Property >& _rProps ) const
139 BEGIN_DESCRIBE_PROPERTIES( 3, OControlModel )
140 DECL_PROP1( DEFAULT_SCROLL_VALUE, sal_Int32, BOUND );
141 DECL_PROP1( TABINDEX, sal_Int16, BOUND );
142 DECL_PROP2( CONTROLSOURCEPROPERTY,OUString, READONLY, TRANSIENT );
143 END_DESCRIBE_PROPERTIES();
147 void OScrollBarModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
149 switch ( _nHandle )
151 case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
152 _rValue <<= m_nDefaultScrollValue;
153 break;
155 default:
156 OBoundControlModel::getFastPropertyValue( _rValue, _nHandle );
161 void OScrollBarModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue )
163 switch ( _nHandle )
165 case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
166 OSL_VERIFY( _rValue >>= m_nDefaultScrollValue );
167 resetNoBroadcast();
168 break;
170 default:
171 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
176 sal_Bool OScrollBarModel::convertFastPropertyValue(
177 Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue )
179 bool bModified( false );
180 switch ( _nHandle )
182 case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
183 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nDefaultScrollValue );
184 break;
186 default:
187 bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
188 break;
190 return bModified;
194 Any OScrollBarModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
196 Any aReturn;
198 switch ( _nHandle )
200 case PROPERTY_ID_DEFAULT_SCROLL_VALUE:
201 aReturn <<= sal_Int32(0);
202 break;
204 default:
205 aReturn = OBoundControlModel::getPropertyDefaultByHandle( _nHandle );
206 break;
209 return aReturn;
213 Any OScrollBarModel::translateDbColumnToControlValue( )
215 OSL_FAIL( "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
216 return Any();
220 bool OScrollBarModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
222 OSL_FAIL( "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
223 return true;
227 Any OScrollBarModel::getDefaultForReset() const
229 return makeAny( m_nDefaultScrollValue );
233 OUString SAL_CALL OScrollBarModel::getServiceName()
235 return FRM_SUN_COMPONENT_SCROLLBAR;
239 void SAL_CALL OScrollBarModel::write( const Reference< XObjectOutputStream >& _rxOutStream )
241 OBoundControlModel::write( _rxOutStream );
242 ::osl::MutexGuard aGuard( m_aMutex );
244 OStreamSection aSection( _rxOutStream );
246 // version
247 _rxOutStream->writeShort( 0x0001 );
249 // properties
250 _rxOutStream << m_nDefaultScrollValue;
251 writeHelpTextCompatibly( _rxOutStream );
255 void SAL_CALL OScrollBarModel::read( const Reference< XObjectInputStream>& _rxInStream )
257 OBoundControlModel::read( _rxInStream );
258 ::osl::MutexGuard aGuard( m_aMutex );
260 // version
262 OStreamSection aSection( _rxInStream );
264 sal_uInt16 nVersion = _rxInStream->readShort();
265 if ( nVersion == 0x0001 )
267 _rxInStream >> m_nDefaultScrollValue;
268 readHelpTextCompatibly( _rxInStream );
270 else
271 defaultCommonProperties();
273 // here, everything in the stream section which is left will be skipped
278 Any OScrollBarModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
280 return translateExternalDoubleToControlIntValue( _rExternalValue, m_xAggregateSet,
281 "ScrollValueMin",
282 "ScrollValueMax" );
286 Any OScrollBarModel::translateControlValueToExternalValue( ) const
288 // by definition, the base class simply obtains the property value
289 return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
293 Sequence< Type > OScrollBarModel::getSupportedBindingTypes()
295 return Sequence< Type >( & cppu::UnoType<double>::get(), 1 );
298 } // namespace frm
300 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
301 com_sun_star_comp_forms_OScrollBarModel_get_implementation(css::uno::XComponentContext* component,
302 css::uno::Sequence<css::uno::Any> const &)
304 return cppu::acquire(new frm::OScrollBarModel(component));
307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */