1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_forms.hxx" 30*cdf0e10cSrcweir #include "spinbutton.hxx" 31*cdf0e10cSrcweir #include <comphelper/streamsection.hxx> 32*cdf0e10cSrcweir #include <comphelper/basicio.hxx> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir //-------------------------------------------------------------------------- 35*cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_OSpinButtonModel() 36*cdf0e10cSrcweir { 37*cdf0e10cSrcweir static ::frm::OMultiInstanceAutoRegistration< ::frm::OSpinButtonModel > aRegisterModel; 38*cdf0e10cSrcweir } 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir //........................................................................ 41*cdf0e10cSrcweir namespace frm 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir //........................................................................ 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 46*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 47*cdf0e10cSrcweir using namespace ::com::sun::star::form; 48*cdf0e10cSrcweir using namespace ::com::sun::star::awt; 49*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 50*cdf0e10cSrcweir using namespace ::com::sun::star::util; 51*cdf0e10cSrcweir using namespace ::com::sun::star::io; 52*cdf0e10cSrcweir using namespace ::com::sun::star::form::binding; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir //==================================================================== 55*cdf0e10cSrcweir //= OSpinButtonModel 56*cdf0e10cSrcweir //==================================================================== 57*cdf0e10cSrcweir // implemented elsewhere 58*cdf0e10cSrcweir Any translateExternalDoubleToControlIntValue( 59*cdf0e10cSrcweir const Any& _rExternalValue, const Reference< XPropertySet >& _rxProperties, 60*cdf0e10cSrcweir const ::rtl::OUString& _rMinValueName, const ::rtl::OUString& _rMaxValueName ); 61*cdf0e10cSrcweir Any translateControlIntToExternalDoubleValue( const Any& _rControlIntValue ); 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir //==================================================================== 64*cdf0e10cSrcweir //= OSpinButtonModel 65*cdf0e10cSrcweir //==================================================================== 66*cdf0e10cSrcweir //-------------------------------------------------------------------- 67*cdf0e10cSrcweir DBG_NAME( OSpinButtonModel ) 68*cdf0e10cSrcweir //-------------------------------------------------------------------- 69*cdf0e10cSrcweir OSpinButtonModel::OSpinButtonModel( const Reference<XMultiServiceFactory>& _rxFactory ) 70*cdf0e10cSrcweir :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_SPINBUTTON, VCL_CONTROL_SPINBUTTON, sal_True, sal_True, sal_False ) 71*cdf0e10cSrcweir ,m_nDefaultSpinValue( 0 ) 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir DBG_CTOR( OSpinButtonModel, NULL ); 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir m_nClassId = FormComponentType::SPINBUTTON; 76*cdf0e10cSrcweir initValueProperty( PROPERTY_SPIN_VALUE, PROPERTY_ID_SPIN_VALUE ); 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir //-------------------------------------------------------------------- 80*cdf0e10cSrcweir OSpinButtonModel::OSpinButtonModel( const OSpinButtonModel* _pOriginal, const Reference< XMultiServiceFactory >& _rxFactory ) 81*cdf0e10cSrcweir :OBoundControlModel( _pOriginal, _rxFactory ) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir DBG_CTOR( OSpinButtonModel, NULL ); 84*cdf0e10cSrcweir m_nDefaultSpinValue = _pOriginal->m_nDefaultSpinValue; 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir //-------------------------------------------------------------------- 88*cdf0e10cSrcweir OSpinButtonModel::~OSpinButtonModel( ) 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir DBG_DTOR( OSpinButtonModel, NULL ); 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir //-------------------------------------------------------------------- 94*cdf0e10cSrcweir IMPLEMENT_SERVICE_REGISTRATION_2( OSpinButtonModel, OControlModel, FRM_SUN_COMPONENT_SPINBUTTON, BINDABLE_INTEGER_VALUE_RANGE ) 95*cdf0e10cSrcweir // note that we're passing OControlModel as "base class". This is because 96*cdf0e10cSrcweir // OBoundControlModel, our real base class, claims to support the DataAwareControlModel 97*cdf0e10cSrcweir // service, which isn't really true for us. We only derive from this class 98*cdf0e10cSrcweir // to benefit from the functionality for binding to spreadsheet cells 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir //------------------------------------------------------------------------------ 101*cdf0e10cSrcweir IMPLEMENT_DEFAULT_CLONING( OSpinButtonModel ) 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir //------------------------------------------------------------------------------ 104*cdf0e10cSrcweir void SAL_CALL OSpinButtonModel::disposing() 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir OBoundControlModel::disposing(); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir //-------------------------------------------------------------------- 110*cdf0e10cSrcweir void OSpinButtonModel::describeFixedProperties( Sequence< Property >& _rProps ) const 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir BEGIN_DESCRIBE_PROPERTIES( 3, OControlModel ) 113*cdf0e10cSrcweir DECL_PROP1( DEFAULT_SPIN_VALUE, sal_Int32, BOUND ); 114*cdf0e10cSrcweir DECL_PROP1( TABINDEX, sal_Int16, BOUND ); 115*cdf0e10cSrcweir DECL_PROP2( CONTROLSOURCEPROPERTY,::rtl::OUString, READONLY, TRANSIENT ); 116*cdf0e10cSrcweir END_DESCRIBE_PROPERTIES(); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir //------------------------------------------------------------------------------ 120*cdf0e10cSrcweir void OSpinButtonModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir switch ( _nHandle ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir case PROPERTY_ID_DEFAULT_SPIN_VALUE: 125*cdf0e10cSrcweir _rValue <<= m_nDefaultSpinValue; 126*cdf0e10cSrcweir break; 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir default: 129*cdf0e10cSrcweir OBoundControlModel::getFastPropertyValue( _rValue, _nHandle ); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir //------------------------------------------------------------------------------ 134*cdf0e10cSrcweir void OSpinButtonModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir switch ( _nHandle ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir case PROPERTY_ID_DEFAULT_SPIN_VALUE: 139*cdf0e10cSrcweir OSL_VERIFY( _rValue >>= m_nDefaultSpinValue ); 140*cdf0e10cSrcweir resetNoBroadcast(); 141*cdf0e10cSrcweir break; 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir default: 144*cdf0e10cSrcweir OBoundControlModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue ); 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir //------------------------------------------------------------------------------ 149*cdf0e10cSrcweir sal_Bool OSpinButtonModel::convertFastPropertyValue( 150*cdf0e10cSrcweir Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue ) 151*cdf0e10cSrcweir throw ( IllegalArgumentException ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir sal_Bool bModified( sal_False ); 154*cdf0e10cSrcweir switch ( _nHandle ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir case PROPERTY_ID_DEFAULT_SPIN_VALUE: 157*cdf0e10cSrcweir bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, m_nDefaultSpinValue ); 158*cdf0e10cSrcweir break; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir default: 161*cdf0e10cSrcweir bModified = OBoundControlModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue ); 162*cdf0e10cSrcweir break; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir return bModified; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir //-------------------------------------------------------------------- 168*cdf0e10cSrcweir Any OSpinButtonModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir Any aReturn; 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir switch ( _nHandle ) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir case PROPERTY_ID_DEFAULT_SPIN_VALUE: 175*cdf0e10cSrcweir aReturn <<= (sal_Int32)0; 176*cdf0e10cSrcweir break; 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir default: 179*cdf0e10cSrcweir aReturn = OBoundControlModel::getPropertyDefaultByHandle( _nHandle ); 180*cdf0e10cSrcweir break; 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir return aReturn; 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir //------------------------------------------------------------------------------ 187*cdf0e10cSrcweir Any OSpinButtonModel::translateDbColumnToControlValue( ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir OSL_ENSURE( sal_False, "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" ); 190*cdf0e10cSrcweir return Any(); 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir //------------------------------------------------------------------------------ 194*cdf0e10cSrcweir sal_Bool OSpinButtonModel::commitControlValueToDbColumn( bool /*_bPostReset*/ ) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir OSL_ENSURE( sal_False, "OSpinButtonModel::commitControlValueToDbColumn: never to be called (we're not bound)!" ); 197*cdf0e10cSrcweir return sal_True; 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir //------------------------------------------------------------------------------ 201*cdf0e10cSrcweir Any OSpinButtonModel::getDefaultForReset() const 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir return makeAny( (sal_Int32)m_nDefaultSpinValue ); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir //-------------------------------------------------------------------- 207*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OSpinButtonModel::getServiceName() throw( RuntimeException ) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir return FRM_SUN_COMPONENT_SPINBUTTON; 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir //-------------------------------------------------------------------- 213*cdf0e10cSrcweir void SAL_CALL OSpinButtonModel::write( const Reference< XObjectOutputStream >& _rxOutStream ) 214*cdf0e10cSrcweir throw( IOException, RuntimeException ) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir OBoundControlModel::write( _rxOutStream ); 217*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir OStreamSection aSection( Reference< XDataOutputStream >( _rxOutStream, UNO_QUERY ) ); 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir // version 222*cdf0e10cSrcweir _rxOutStream->writeShort( 0x0001 ); 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir // properties 225*cdf0e10cSrcweir _rxOutStream << m_nDefaultSpinValue; 226*cdf0e10cSrcweir writeHelpTextCompatibly( _rxOutStream ); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir //-------------------------------------------------------------------- 230*cdf0e10cSrcweir void SAL_CALL OSpinButtonModel::read( const Reference< XObjectInputStream>& _rxInStream ) throw( IOException, RuntimeException ) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir OBoundControlModel::read( _rxInStream ); 233*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir // version 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir OStreamSection aSection( Reference< XDataInputStream >( _rxInStream, UNO_QUERY ) ); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir sal_uInt16 nVersion = _rxInStream->readShort(); 240*cdf0e10cSrcweir if ( nVersion == 0x0001 ) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir _rxInStream >> m_nDefaultSpinValue; 243*cdf0e10cSrcweir readHelpTextCompatibly( _rxInStream ); 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir else 246*cdf0e10cSrcweir defaultCommonProperties(); 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir // here, everything in the stream section which is left will be skipped 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir //-------------------------------------------------------------------- 253*cdf0e10cSrcweir Any OSpinButtonModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir return translateExternalDoubleToControlIntValue( _rExternalValue, m_xAggregateSet, 256*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SpinValueMin" ) ), 257*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SpinValueMax" ) ) ); 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir //-------------------------------------------------------------------- 261*cdf0e10cSrcweir Any OSpinButtonModel::translateControlValueToExternalValue( ) const 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir // by definition, the base class simply obtains the property value 264*cdf0e10cSrcweir return translateControlIntToExternalDoubleValue( OBoundControlModel::translateControlValueToExternalValue() ); 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir //-------------------------------------------------------------------- 268*cdf0e10cSrcweir Sequence< Type > OSpinButtonModel::getSupportedBindingTypes() 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir return Sequence< Type >( &::getCppuType( static_cast< double* >( NULL ) ), 1 ); 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir //........................................................................ 274*cdf0e10cSrcweir } // namespace frm 275*cdf0e10cSrcweir //........................................................................ 276