1*24acc546SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*24acc546SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*24acc546SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*24acc546SAndrew Rist * distributed with this work for additional information 6*24acc546SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*24acc546SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*24acc546SAndrew Rist * "License"); you may not use this file except in compliance 9*24acc546SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*24acc546SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*24acc546SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*24acc546SAndrew Rist * software distributed under the License is distributed on an 15*24acc546SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*24acc546SAndrew Rist * KIND, either express or implied. See the License for the 17*24acc546SAndrew Rist * specific language governing permissions and limitations 18*24acc546SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*24acc546SAndrew Rist *************************************************************/ 21*24acc546SAndrew Rist 22*24acc546SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_forms.hxx" 26cdf0e10cSrcweir #include "scrollbar.hxx" 27cdf0e10cSrcweir #include <comphelper/streamsection.hxx> 28cdf0e10cSrcweir #include <comphelper/basicio.hxx> 29cdf0e10cSrcweir #include <rtl/math.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir //-------------------------------------------------------------------------- 32cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_OScrollBarModel() 33cdf0e10cSrcweir { 34cdf0e10cSrcweir static ::frm::OMultiInstanceAutoRegistration< ::frm::OScrollBarModel > aRegisterModel; 35cdf0e10cSrcweir } 36cdf0e10cSrcweir 37cdf0e10cSrcweir //........................................................................ 38cdf0e10cSrcweir namespace frm 39cdf0e10cSrcweir { 40cdf0e10cSrcweir //........................................................................ 41cdf0e10cSrcweir 42cdf0e10cSrcweir using namespace ::com::sun::star::uno; 43cdf0e10cSrcweir using namespace ::com::sun::star::beans; 44cdf0e10cSrcweir using namespace ::com::sun::star::form; 45cdf0e10cSrcweir using namespace ::com::sun::star::awt; 46cdf0e10cSrcweir using namespace ::com::sun::star::lang; 47cdf0e10cSrcweir using namespace ::com::sun::star::util; 48cdf0e10cSrcweir using namespace ::com::sun::star::io; 49cdf0e10cSrcweir using namespace ::com::sun::star::form::binding; 50cdf0e10cSrcweir 51cdf0e10cSrcweir //==================================================================== 52cdf0e10cSrcweir //= helper 53cdf0e10cSrcweir //==================================================================== 54cdf0e10cSrcweir //-------------------------------------------------------------------- 55cdf0e10cSrcweir Any translateExternalDoubleToControlIntValue( 56cdf0e10cSrcweir const Any& _rExternalValue, const Reference< XPropertySet >& _rxProperties, 57cdf0e10cSrcweir const ::rtl::OUString& _rMinValueName, const ::rtl::OUString& _rMaxValueName ) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir OSL_ENSURE( _rxProperties.is(), "translateExternalDoubleToControlIntValue: no aggregate!?" ); 60cdf0e10cSrcweir 61cdf0e10cSrcweir sal_Int32 nControlValue( 0 ); 62cdf0e10cSrcweir double nExternalValue = 0; 63cdf0e10cSrcweir if ( _rExternalValue >>= nExternalValue ) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir if ( ::rtl::math::isInf( nExternalValue ) ) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir // set the minimum or maximum of the scroll values 68cdf0e10cSrcweir ::rtl::OUString sLimitPropertyName = ::rtl::math::isSignBitSet( nExternalValue ) 69cdf0e10cSrcweir ? _rMinValueName : _rMaxValueName; 70cdf0e10cSrcweir if ( _rxProperties.is() ) 71cdf0e10cSrcweir _rxProperties->getPropertyValue( sLimitPropertyName ) >>= nControlValue; 72cdf0e10cSrcweir } 73cdf0e10cSrcweir else 74cdf0e10cSrcweir { 75cdf0e10cSrcweir nControlValue = (sal_Int32)::rtl::math::round( nExternalValue ); 76cdf0e10cSrcweir } 77cdf0e10cSrcweir } 78cdf0e10cSrcweir else 79cdf0e10cSrcweir { 80cdf0e10cSrcweir if ( _rxProperties.is() ) 81cdf0e10cSrcweir _rxProperties->getPropertyValue( _rMinValueName ) >>= nControlValue; 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir return makeAny( nControlValue ); 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir //-------------------------------------------------------------------- 88cdf0e10cSrcweir Any translateControlIntToExternalDoubleValue( const Any& _rControlIntValue ) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir Any aExternalDoubleValue; 91cdf0e10cSrcweir sal_Int32 nScrollValue = 0; 92cdf0e10cSrcweir if ( _rControlIntValue >>= nScrollValue ) 93cdf0e10cSrcweir aExternalDoubleValue <<= (double)nScrollValue; 94cdf0e10cSrcweir else 95cdf0e10cSrcweir { 96cdf0e10cSrcweir OSL_ENSURE( sal_False, "translateControlIntToExternalDoubleValue: no integer scroll value!" ); 97cdf0e10cSrcweir // aExternalDoubleValue is void here, which is okay for this purpose ... 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir return aExternalDoubleValue; 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir //==================================================================== 104cdf0e10cSrcweir //= OScrollBarModel 105cdf0e10cSrcweir //==================================================================== 106cdf0e10cSrcweir //-------------------------------------------------------------------- 107cdf0e10cSrcweir DBG_NAME( OScrollBarModel ) 108cdf0e10cSrcweir //-------------------------------------------------------------------- 109cdf0e10cSrcweir OScrollBarModel::OScrollBarModel( const Reference<XMultiServiceFactory>& _rxFactory ) 110cdf0e10cSrcweir :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_SCROLLBAR, VCL_CONTROL_SCROLLBAR, sal_True, sal_True, sal_False ) 111cdf0e10cSrcweir ,m_nDefaultScrollValue( 0 ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir DBG_CTOR( OScrollBarModel, NULL ); 114cdf0e10cSrcweir 115cdf0e10cSrcweir m_nClassId = FormComponentType::SCROLLBAR; 116cdf0e10cSrcweir initValueProperty( PROPERTY_SCROLL_VALUE, PROPERTY_ID_SCROLL_VALUE ); 117cdf0e10cSrcweir } 118cdf0e10cSrcweir 119cdf0e10cSrcweir //-------------------------------------------------------------------- 120cdf0e10cSrcweir OScrollBarModel::OScrollBarModel( const OScrollBarModel* _pOriginal, const Reference< XMultiServiceFactory >& _rxFactory ) 121cdf0e10cSrcweir :OBoundControlModel( _pOriginal, _rxFactory ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir DBG_CTOR( OScrollBarModel, NULL ); 124cdf0e10cSrcweir m_nDefaultScrollValue = _pOriginal->m_nDefaultScrollValue; 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir //-------------------------------------------------------------------- 128cdf0e10cSrcweir OScrollBarModel::~OScrollBarModel( ) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir DBG_DTOR( OScrollBarModel, NULL ); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir //-------------------------------------------------------------------- 134cdf0e10cSrcweir IMPLEMENT_SERVICE_REGISTRATION_2( OScrollBarModel, OControlModel, FRM_SUN_COMPONENT_SCROLLBAR, BINDABLE_INTEGER_VALUE_RANGE ) 135cdf0e10cSrcweir // note that we're passing OControlModel as "base class". This is because 136cdf0e10cSrcweir // OBoundControlModel, our real base class, claims to support the DataAwareControlModel 137cdf0e10cSrcweir // service, which isn't really true for us. We only derive from this class 138cdf0e10cSrcweir // to benefit from the functionality for binding to spreadsheet cells 139cdf0e10cSrcweir 140cdf0e10cSrcweir //------------------------------------------------------------------------------ 141cdf0e10cSrcweir IMPLEMENT_DEFAULT_CLONING( OScrollBarModel ) 142cdf0e10cSrcweir 143cdf0e10cSrcweir //------------------------------------------------------------------------------ 144cdf0e10cSrcweir void SAL_CALL OScrollBarModel::disposing() 145cdf0e10cSrcweir { 146cdf0e10cSrcweir OBoundControlModel::disposing(); 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir //-------------------------------------------------------------------- 150cdf0e10cSrcweir void OScrollBarModel::describeFixedProperties( Sequence< Property >& _rProps ) const 151cdf0e10cSrcweir { 152cdf0e10cSrcweir BEGIN_DESCRIBE_PROPERTIES( 3, OControlModel ) 153cdf0e10cSrcweir DECL_PROP1( DEFAULT_SCROLL_VALUE, sal_Int32, BOUND ); 154cdf0e10cSrcweir DECL_PROP1( TABINDEX, sal_Int16, BOUND ); 155cdf0e10cSrcweir DECL_PROP2( CONTROLSOURCEPROPERTY,::rtl::OUString, READONLY, TRANSIENT ); 156cdf0e10cSrcweir END_DESCRIBE_PROPERTIES(); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir //------------------------------------------------------------------------------ 160cdf0e10cSrcweir void OScrollBarModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const 161cdf0e10cSrcweir { 162cdf0e10cSrcweir switch ( _nHandle ) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir case PROPERTY_ID_DEFAULT_SCROLL_VALUE: 165cdf0e10cSrcweir _rValue <<= m_nDefaultScrollValue; 166cdf0e10cSrcweir break; 167cdf0e10cSrcweir 168cdf0e10cSrcweir default: 169cdf0e10cSrcweir OBoundControlModel::getFastPropertyValue( _rValue, _nHandle ); 170cdf0e10cSrcweir } 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir //------------------------------------------------------------------------------ 174cdf0e10cSrcweir void OScrollBarModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception ) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir switch ( _nHandle ) 177cdf0e10cSrcweir { 178cdf0e10cSrcweir case PROPERTY_ID_DEFAULT_SCROLL_VALUE: 179cdf0e10cSrcweir OSL_VERIFY( _rValue >>= m_nDefaultScrollValue ); 180cdf0e10cSrcweir resetNoBroadcast(); 181cdf0e10cSrcweir break; 182cdf0e10cSrcweir 183cdf0e10cSrcweir default: 184cdf0e10cSrcweir OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue ); 185cdf0e10cSrcweir } 186cdf0e10cSrcweir } 187cdf0e10cSrcweir 188cdf0e10cSrcweir //------------------------------------------------------------------------------ 189cdf0e10cSrcweir sal_Bool OScrollBarModel::convertFastPropertyValue( 190cdf0e10cSrcweir Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue ) 191cdf0e10cSrcweir throw ( IllegalArgumentException ) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir sal_Bool bModified( sal_False ); 194cdf0e10cSrcweir switch ( _nHandle ) 195cdf0e10cSrcweir { 196cdf0e10cSrcweir case PROPERTY_ID_DEFAULT_SCROLL_VALUE: 197cdf0e10cSrcweir bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nDefaultScrollValue ); 198cdf0e10cSrcweir break; 199cdf0e10cSrcweir 200cdf0e10cSrcweir default: 201cdf0e10cSrcweir bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue ); 202cdf0e10cSrcweir break; 203cdf0e10cSrcweir } 204cdf0e10cSrcweir return bModified; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir //-------------------------------------------------------------------- 208cdf0e10cSrcweir Any OScrollBarModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const 209cdf0e10cSrcweir { 210cdf0e10cSrcweir Any aReturn; 211cdf0e10cSrcweir 212cdf0e10cSrcweir switch ( _nHandle ) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir case PROPERTY_ID_DEFAULT_SCROLL_VALUE: 215cdf0e10cSrcweir aReturn <<= (sal_Int32)0; 216cdf0e10cSrcweir break; 217cdf0e10cSrcweir 218cdf0e10cSrcweir default: 219cdf0e10cSrcweir aReturn = OBoundControlModel::getPropertyDefaultByHandle( _nHandle ); 220cdf0e10cSrcweir break; 221cdf0e10cSrcweir } 222cdf0e10cSrcweir 223cdf0e10cSrcweir return aReturn; 224cdf0e10cSrcweir } 225cdf0e10cSrcweir 226cdf0e10cSrcweir //------------------------------------------------------------------------------ 227cdf0e10cSrcweir Any OScrollBarModel::translateDbColumnToControlValue( ) 228cdf0e10cSrcweir { 229cdf0e10cSrcweir OSL_ENSURE( sal_False, "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" ); 230cdf0e10cSrcweir return Any(); 231cdf0e10cSrcweir } 232cdf0e10cSrcweir 233cdf0e10cSrcweir //------------------------------------------------------------------------------ 234cdf0e10cSrcweir sal_Bool OScrollBarModel::commitControlValueToDbColumn( bool /*_bPostReset*/ ) 235cdf0e10cSrcweir { 236cdf0e10cSrcweir OSL_ENSURE( sal_False, "OScrollBarModel::commitControlValueToDbColumn: never to be called (we're not bound)!" ); 237cdf0e10cSrcweir return sal_True; 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir //------------------------------------------------------------------------------ 241cdf0e10cSrcweir Any OScrollBarModel::getDefaultForReset() const 242cdf0e10cSrcweir { 243cdf0e10cSrcweir return makeAny( (sal_Int32)m_nDefaultScrollValue ); 244cdf0e10cSrcweir } 245cdf0e10cSrcweir 246cdf0e10cSrcweir //-------------------------------------------------------------------- 247cdf0e10cSrcweir ::rtl::OUString SAL_CALL OScrollBarModel::getServiceName() throw( RuntimeException ) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir return FRM_SUN_COMPONENT_SCROLLBAR; 250cdf0e10cSrcweir } 251cdf0e10cSrcweir 252cdf0e10cSrcweir //-------------------------------------------------------------------- 253cdf0e10cSrcweir void SAL_CALL OScrollBarModel::write( const Reference< XObjectOutputStream >& _rxOutStream ) 254cdf0e10cSrcweir throw( IOException, RuntimeException ) 255cdf0e10cSrcweir { 256cdf0e10cSrcweir OBoundControlModel::write( _rxOutStream ); 257cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 258cdf0e10cSrcweir 259cdf0e10cSrcweir OStreamSection aSection( Reference< XDataOutputStream >( _rxOutStream, UNO_QUERY ) ); 260cdf0e10cSrcweir 261cdf0e10cSrcweir // version 262cdf0e10cSrcweir _rxOutStream->writeShort( 0x0001 ); 263cdf0e10cSrcweir 264cdf0e10cSrcweir // properties 265cdf0e10cSrcweir _rxOutStream << m_nDefaultScrollValue; 266cdf0e10cSrcweir writeHelpTextCompatibly( _rxOutStream ); 267cdf0e10cSrcweir } 268cdf0e10cSrcweir 269cdf0e10cSrcweir //-------------------------------------------------------------------- 270cdf0e10cSrcweir void SAL_CALL OScrollBarModel::read( const Reference< XObjectInputStream>& _rxInStream ) throw( IOException, RuntimeException ) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir OBoundControlModel::read( _rxInStream ); 273cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 274cdf0e10cSrcweir 275cdf0e10cSrcweir // version 276cdf0e10cSrcweir { 277cdf0e10cSrcweir OStreamSection aSection( Reference< XDataInputStream >( _rxInStream, UNO_QUERY ) ); 278cdf0e10cSrcweir 279cdf0e10cSrcweir sal_uInt16 nVersion = _rxInStream->readShort(); 280cdf0e10cSrcweir if ( nVersion == 0x0001 ) 281cdf0e10cSrcweir { 282cdf0e10cSrcweir _rxInStream >> m_nDefaultScrollValue; 283cdf0e10cSrcweir readHelpTextCompatibly( _rxInStream ); 284cdf0e10cSrcweir } 285cdf0e10cSrcweir else 286cdf0e10cSrcweir defaultCommonProperties(); 287cdf0e10cSrcweir 288cdf0e10cSrcweir // here, everything in the stream section which is left will be skipped 289cdf0e10cSrcweir } 290cdf0e10cSrcweir } 291cdf0e10cSrcweir 292cdf0e10cSrcweir //-------------------------------------------------------------------- 293cdf0e10cSrcweir Any OScrollBarModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const 294cdf0e10cSrcweir { 295cdf0e10cSrcweir return translateExternalDoubleToControlIntValue( _rExternalValue, m_xAggregateSet, 296cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScrollValueMin" ) ), 297cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScrollValueMax" ) ) ); 298cdf0e10cSrcweir } 299cdf0e10cSrcweir 300cdf0e10cSrcweir //-------------------------------------------------------------------- 301cdf0e10cSrcweir Any OScrollBarModel::translateControlValueToExternalValue( ) const 302cdf0e10cSrcweir { 303cdf0e10cSrcweir // by definition, the base class simply obtains the property value 304cdf0e10cSrcweir return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() ); 305cdf0e10cSrcweir } 306cdf0e10cSrcweir 307cdf0e10cSrcweir //-------------------------------------------------------------------- 308cdf0e10cSrcweir Sequence< Type > OScrollBarModel::getSupportedBindingTypes() 309cdf0e10cSrcweir { 310cdf0e10cSrcweir return Sequence< Type >( &::getCppuType( static_cast< double* >( NULL ) ), 1 ); 311cdf0e10cSrcweir } 312cdf0e10cSrcweir 313cdf0e10cSrcweir //........................................................................ 314cdf0e10cSrcweir } // namespace frm 315cdf0e10cSrcweir //........................................................................ 316