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 <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 <tools/debug.hxx>
28 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include <com/sun/star/form/FormComponentType.hpp>
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::beans
;
36 using namespace ::com::sun::star::form
;
37 using namespace ::com::sun::star::awt
;
38 using namespace ::com::sun::star::lang
;
39 using namespace ::com::sun::star::util
;
40 using namespace ::com::sun::star::io
;
41 using namespace ::com::sun::star::form::binding
;
46 Any
translateExternalDoubleToControlIntValue(
47 const Any
& _rExternalValue
, const Reference
< XPropertySet
>& _rxProperties
,
48 const OUString
& _rMinValueName
, const OUString
& _rMaxValueName
)
50 OSL_ENSURE( _rxProperties
.is(), "translateExternalDoubleToControlIntValue: no aggregate!?" );
52 sal_Int32
nControlValue( 0 );
53 double nExternalValue
= 0;
54 if ( _rExternalValue
>>= nExternalValue
)
56 if ( std::isinf( nExternalValue
) )
58 // set the minimum or maximum of the scroll values
59 OUString sLimitPropertyName
= std::signbit( nExternalValue
)
60 ? _rMinValueName
: _rMaxValueName
;
61 if ( _rxProperties
.is() )
62 _rxProperties
->getPropertyValue( sLimitPropertyName
) >>= nControlValue
;
66 nControlValue
= static_cast<sal_Int32
>(::rtl::math::round( nExternalValue
));
71 if ( _rxProperties
.is() )
72 _rxProperties
->getPropertyValue( _rMinValueName
) >>= nControlValue
;
75 return Any( nControlValue
);
79 Any
translateControlIntToExternalDoubleValue( const Any
& _rControlIntValue
)
81 Any aExternalDoubleValue
;
82 sal_Int32 nScrollValue
= 0;
83 if ( _rControlIntValue
>>= nScrollValue
)
84 aExternalDoubleValue
<<= static_cast<double>(nScrollValue
);
87 OSL_FAIL( "translateControlIntToExternalDoubleValue: no integer scroll value!" );
88 // aExternalDoubleValue is void here, which is okay for this purpose ...
91 return aExternalDoubleValue
;
94 OScrollBarModel::OScrollBarModel( const Reference
<XComponentContext
>& _rxFactory
)
95 :OBoundControlModel( _rxFactory
, VCL_CONTROLMODEL_SCROLLBAR
, VCL_CONTROL_SCROLLBAR
, true, true, false )
96 ,m_nDefaultScrollValue( 0 )
99 m_nClassId
= FormComponentType::SCROLLBAR
;
100 initValueProperty( PROPERTY_SCROLL_VALUE
, PROPERTY_ID_SCROLL_VALUE
);
104 OScrollBarModel::OScrollBarModel( const OScrollBarModel
* _pOriginal
, const Reference
< XComponentContext
>& _rxFactory
)
105 :OBoundControlModel( _pOriginal
, _rxFactory
)
107 m_nDefaultScrollValue
= _pOriginal
->m_nDefaultScrollValue
;
111 OScrollBarModel::~OScrollBarModel( )
115 OUString SAL_CALL
OScrollBarModel::getImplementationName()
117 return "com.sun.star.comp.forms.OScrollBarModel";
120 // note that we're passing OControlModel as "base class". This is because
121 // OBoundControlModel, our real base class, claims to support the DataAwareControlModel
122 // service, which isn't really true for us. We only derive from this class
123 // to benefit from the functionality for binding to spreadsheet cells
124 Sequence
< OUString
> SAL_CALL
OScrollBarModel::getSupportedServiceNames()
126 Sequence
< OUString
> aOwnNames
{ FRM_SUN_COMPONENT_SCROLLBAR
, BINDABLE_INTEGER_VALUE_RANGE
};
128 return ::comphelper::combineSequences(
129 getAggregateServiceNames(),
130 ::comphelper::concatSequences(
131 OControlModel::getSupportedServiceNames_Static(),
136 css::uno::Reference
< css::util::XCloneable
> SAL_CALL
OScrollBarModel::createClone()
138 rtl::Reference
<OScrollBarModel
> pClone
= new OScrollBarModel(this, getContext());
139 pClone
->clonedFrom(this);
144 void OScrollBarModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
146 OControlModel::describeFixedProperties( _rProps
);
147 sal_Int32 nOldCount
= _rProps
.getLength();
148 _rProps
.realloc( nOldCount
+ 3);
149 css::beans::Property
* pProperties
= _rProps
.getArray() + nOldCount
;
150 *pProperties
++ = css::beans::Property(PROPERTY_DEFAULT_SCROLL_VALUE
, PROPERTY_ID_DEFAULT_SCROLL_VALUE
, cppu::UnoType
<sal_Int32
>::get(), css::beans::PropertyAttribute::BOUND
);
151 *pProperties
++ = css::beans::Property(PROPERTY_TABINDEX
, PROPERTY_ID_TABINDEX
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::BOUND
);
152 *pProperties
++ = css::beans::Property(PROPERTY_CONTROLSOURCEPROPERTY
, PROPERTY_ID_CONTROLSOURCEPROPERTY
, cppu::UnoType
<OUString
>::get(), css::beans::PropertyAttribute::READONLY
| css::beans::PropertyAttribute::TRANSIENT
);
153 DBG_ASSERT( pProperties
== _rProps
.getArray() + _rProps
.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
157 void OScrollBarModel::getFastPropertyValue( Any
& _rValue
, sal_Int32 _nHandle
) const
161 case PROPERTY_ID_DEFAULT_SCROLL_VALUE
:
162 _rValue
<<= m_nDefaultScrollValue
;
166 OBoundControlModel::getFastPropertyValue( _rValue
, _nHandle
);
171 void OScrollBarModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle
, const Any
& _rValue
)
175 case PROPERTY_ID_DEFAULT_SCROLL_VALUE
:
176 OSL_VERIFY( _rValue
>>= m_nDefaultScrollValue
);
181 OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle
, _rValue
);
186 sal_Bool
OScrollBarModel::convertFastPropertyValue(
187 Any
& _rConvertedValue
, Any
& _rOldValue
, sal_Int32 _nHandle
, const Any
& _rValue
)
189 bool bModified( false );
192 case PROPERTY_ID_DEFAULT_SCROLL_VALUE
:
193 bModified
= tryPropertyValue( _rConvertedValue
, _rOldValue
, _rValue
, m_nDefaultScrollValue
);
197 bModified
= OBoundControlModel::convertFastPropertyValue( _rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
204 Any
OScrollBarModel::getPropertyDefaultByHandle( sal_Int32 _nHandle
) const
210 case PROPERTY_ID_DEFAULT_SCROLL_VALUE
:
211 aReturn
<<= sal_Int32(0);
215 aReturn
= OBoundControlModel::getPropertyDefaultByHandle( _nHandle
);
223 Any
OScrollBarModel::translateDbColumnToControlValue( )
225 OSL_FAIL( "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
230 bool OScrollBarModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
232 OSL_FAIL( "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" );
237 Any
OScrollBarModel::getDefaultForReset() const
239 return Any( m_nDefaultScrollValue
);
243 OUString SAL_CALL
OScrollBarModel::getServiceName()
245 return FRM_SUN_COMPONENT_SCROLLBAR
;
249 void SAL_CALL
OScrollBarModel::write( const Reference
< XObjectOutputStream
>& _rxOutStream
)
251 OBoundControlModel::write( _rxOutStream
);
252 ::osl::MutexGuard
aGuard( m_aMutex
);
254 OStreamSection
aSection( _rxOutStream
);
257 _rxOutStream
->writeShort( 0x0001 );
260 _rxOutStream
<< m_nDefaultScrollValue
;
261 writeHelpTextCompatibly( _rxOutStream
);
265 void SAL_CALL
OScrollBarModel::read( const Reference
< XObjectInputStream
>& _rxInStream
)
267 OBoundControlModel::read( _rxInStream
);
268 ::osl::MutexGuard
aGuard( m_aMutex
);
272 OStreamSection
aSection( _rxInStream
);
274 sal_uInt16 nVersion
= _rxInStream
->readShort();
275 if ( nVersion
== 0x0001 )
277 _rxInStream
>> m_nDefaultScrollValue
;
278 readHelpTextCompatibly( _rxInStream
);
281 defaultCommonProperties();
283 // here, everything in the stream section which is left will be skipped
288 Any
OScrollBarModel::translateExternalValueToControlValue( const Any
& _rExternalValue
) const
290 return translateExternalDoubleToControlIntValue( _rExternalValue
, m_xAggregateSet
,
296 Any
OScrollBarModel::translateControlValueToExternalValue( ) const
298 // by definition, the base class simply obtains the property value
299 return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() );
303 Sequence
< Type
> OScrollBarModel::getSupportedBindingTypes()
305 return Sequence
< Type
>( & cppu::UnoType
<double>::get(), 1 );
310 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
311 com_sun_star_comp_forms_OScrollBarModel_get_implementation(css::uno::XComponentContext
* component
,
312 css::uno::Sequence
<css::uno::Any
> const &)
314 return cppu::acquire(new frm::OScrollBarModel(component
));
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */