1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
28 using namespace ::com::sun::star::uno
;
29 using namespace ::com::sun::star::beans
;
30 using namespace ::com::sun::star::form
;
31 using namespace ::com::sun::star::awt
;
32 using namespace ::com::sun::star::lang
;
33 using namespace ::com::sun::star::util
;
34 using namespace ::com::sun::star::io
;
35 using namespace ::com::sun::star::form::binding
;
40 Any
translateExternalDoubleToControlIntValue(
41 const Any
& _rExternalValue
, const Reference
< XPropertySet
>& _rxProperties
,
42 const OUString
& _rMinValueName
, const OUString
& _rMaxValueName
)
44 OSL_ENSURE( _rxProperties
.is(), "translateExternalDoubleToControlIntValue: no aggregate!?" );
46 sal_Int32
nControlValue( 0 );
47 double nExternalValue
= 0;
48 if ( _rExternalValue
>>= nExternalValue
)
50 if ( ::rtl::math::isInf( nExternalValue
) )
52 // set the minimum or maximum of the scroll values
53 OUString sLimitPropertyName
= ::rtl::math::isSignBitSet( nExternalValue
)
54 ? _rMinValueName
: _rMaxValueName
;
55 if ( _rxProperties
.is() )
56 _rxProperties
->getPropertyValue( sLimitPropertyName
) >>= nControlValue
;
60 nControlValue
= (sal_Int32
)::rtl::math::round( nExternalValue
);
65 if ( _rxProperties
.is() )
66 _rxProperties
->getPropertyValue( _rMinValueName
) >>= nControlValue
;
69 return makeAny( nControlValue
);
73 Any
translateControlIntToExternalDoubleValue( const Any
& _rControlIntValue
)
75 Any aExternalDoubleValue
;
76 sal_Int32 nScrollValue
= 0;
77 if ( _rControlIntValue
>>= nScrollValue
)
78 aExternalDoubleValue
<<= (double)nScrollValue
;
81 OSL_FAIL( "translateControlIntToExternalDoubleValue: no integer scroll value!" );
82 // aExternalDoubleValue is void here, which is okay for this purpose ...
85 return aExternalDoubleValue
;
88 OScrollBarModel::OScrollBarModel( const Reference
<XComponentContext
>& _rxFactory
)
89 :OBoundControlModel( _rxFactory
, VCL_CONTROLMODEL_SCROLLBAR
, VCL_CONTROL_SCROLLBAR
, true, true, false )
90 ,m_nDefaultScrollValue( 0 )
93 m_nClassId
= FormComponentType::SCROLLBAR
;
94 initValueProperty( PROPERTY_SCROLL_VALUE
, PROPERTY_ID_SCROLL_VALUE
);
98 OScrollBarModel::OScrollBarModel( const OScrollBarModel
* _pOriginal
, const Reference
< XComponentContext
>& _rxFactory
)
99 :OBoundControlModel( _pOriginal
, _rxFactory
)
101 m_nDefaultScrollValue
= _pOriginal
->m_nDefaultScrollValue
;
105 OScrollBarModel::~OScrollBarModel( )
109 OUString SAL_CALL
OScrollBarModel::getImplementationName() throw ( RuntimeException
, std::exception
)
111 return OUString( "com.sun.star.comp.forms.OScrollBarModel" );
114 // note that we're passing OControlModel as "base class". This is because
115 // OBoundControlModel, our real base class, claims to support the DataAwareControlModel
116 // service, which isn't really true for us. We only derive from this class
117 // to benefit from the functionality for binding to spreadsheet cells
118 Sequence
< OUString
> SAL_CALL
OScrollBarModel::getSupportedServiceNames() throw (RuntimeException
, std::exception
)
120 Sequence
< OUString
> aOwnNames( 2 );
121 aOwnNames
[ 0 ] = FRM_SUN_COMPONENT_SCROLLBAR
;
122 aOwnNames
[ 1 ] = BINDABLE_INTEGER_VALUE_RANGE
;
124 return ::comphelper::combineSequences(
125 getAggregateServiceNames(),
126 ::comphelper::concatSequences(
127 OControlModel::getSupportedServiceNames_Static(),
132 IMPLEMENT_DEFAULT_CLONING( OScrollBarModel
)
135 void SAL_CALL
OScrollBarModel::disposing()
137 OBoundControlModel::disposing();
141 void OScrollBarModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
143 BEGIN_DESCRIBE_PROPERTIES( 3, OControlModel
)
144 DECL_PROP1( DEFAULT_SCROLL_VALUE
, sal_Int32
, BOUND
);
145 DECL_PROP1( TABINDEX
, sal_Int16
, BOUND
);
146 DECL_PROP2( CONTROLSOURCEPROPERTY
,OUString
, READONLY
, TRANSIENT
);
147 END_DESCRIBE_PROPERTIES();
151 void OScrollBarModel::getFastPropertyValue( Any
& _rValue
, sal_Int32 _nHandle
) const
155 case PROPERTY_ID_DEFAULT_SCROLL_VALUE
:
156 _rValue
<<= m_nDefaultScrollValue
;
160 OBoundControlModel::getFastPropertyValue( _rValue
, _nHandle
);
165 void OScrollBarModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle
, const Any
& _rValue
) throw ( Exception
, std::exception
)
169 case PROPERTY_ID_DEFAULT_SCROLL_VALUE
:
170 OSL_VERIFY( _rValue
>>= m_nDefaultScrollValue
);
175 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle
, _rValue
);
180 sal_Bool
OScrollBarModel::convertFastPropertyValue(
181 Any
& _rConvertedValue
, Any
& _rOldValue
, sal_Int32 _nHandle
, const Any
& _rValue
)
182 throw ( IllegalArgumentException
)
184 bool bModified( false );
187 case PROPERTY_ID_DEFAULT_SCROLL_VALUE
:
188 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_nDefaultScrollValue
);
192 bModified
= OBoundControlModel::convertFastPropertyValue( _rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
199 Any
OScrollBarModel::getPropertyDefaultByHandle( sal_Int32 _nHandle
) const
205 case PROPERTY_ID_DEFAULT_SCROLL_VALUE
:
206 aReturn
<<= (sal_Int32
)0;
210 aReturn
= OBoundControlModel::getPropertyDefaultByHandle( _nHandle
);
218 Any
OScrollBarModel::translateDbColumnToControlValue( )
220 OSL_FAIL( "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
225 bool OScrollBarModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
227 OSL_FAIL( "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
232 Any
OScrollBarModel::getDefaultForReset() const
234 return makeAny( (sal_Int32
)m_nDefaultScrollValue
);
238 OUString SAL_CALL
OScrollBarModel::getServiceName() throw( RuntimeException
, std::exception
)
240 return OUString(FRM_SUN_COMPONENT_SCROLLBAR
);
244 void SAL_CALL
OScrollBarModel::write( const Reference
< XObjectOutputStream
>& _rxOutStream
)
245 throw( IOException
, RuntimeException
, std::exception
)
247 OBoundControlModel::write( _rxOutStream
);
248 ::osl::MutexGuard
aGuard( m_aMutex
);
250 OStreamSection
aSection( _rxOutStream
);
253 _rxOutStream
->writeShort( 0x0001 );
256 _rxOutStream
<< m_nDefaultScrollValue
;
257 writeHelpTextCompatibly( _rxOutStream
);
261 void SAL_CALL
OScrollBarModel::read( const Reference
< XObjectInputStream
>& _rxInStream
) throw( IOException
, RuntimeException
, std::exception
)
263 OBoundControlModel::read( _rxInStream
);
264 ::osl::MutexGuard
aGuard( m_aMutex
);
268 OStreamSection
aSection( _rxInStream
);
270 sal_uInt16 nVersion
= _rxInStream
->readShort();
271 if ( nVersion
== 0x0001 )
273 _rxInStream
>> m_nDefaultScrollValue
;
274 readHelpTextCompatibly( _rxInStream
);
277 defaultCommonProperties();
279 // here, everything in the stream section which is left will be skipped
284 Any
OScrollBarModel::translateExternalValueToControlValue( const Any
& _rExternalValue
) const
286 return translateExternalDoubleToControlIntValue( _rExternalValue
, m_xAggregateSet
,
287 OUString( "ScrollValueMin" ),
288 OUString( "ScrollValueMax" ) );
292 Any
OScrollBarModel::translateControlValueToExternalValue( ) const
294 // by definition, the base class simply obtains the property value
295 return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
299 Sequence
< Type
> OScrollBarModel::getSupportedBindingTypes()
301 return Sequence
< Type
>( & cppu::UnoType
<double>::get(), 1 );
306 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface
* SAL_CALL
307 com_sun_star_comp_forms_OScrollBarModel_get_implementation(::com::sun::star::uno::XComponentContext
* component
,
308 ::com::sun::star::uno::Sequence
<css::uno::Any
> const &)
310 return cppu::acquire(new frm::OScrollBarModel(component
));
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */