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_comphelper.hxx" 30*cdf0e10cSrcweir #include <comphelper/propstate.hxx> 31*cdf0e10cSrcweir #include <com/sun/star/uno/genfunc.h> 32*cdf0e10cSrcweir #include <cppuhelper/queryinterface.hxx> 33*cdf0e10cSrcweir #include <comphelper/sequence.hxx> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir //......................................................................... 36*cdf0e10cSrcweir namespace comphelper 37*cdf0e10cSrcweir { 38*cdf0e10cSrcweir //......................................................................... 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 41*cdf0e10cSrcweir using ::com::sun::star::uno::Type; 42*cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 43*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 44*cdf0e10cSrcweir using ::com::sun::star::lang::XTypeProvider; 45*cdf0e10cSrcweir using ::com::sun::star::uno::Any; 46*cdf0e10cSrcweir using ::com::sun::star::uno::cpp_queryInterface; 47*cdf0e10cSrcweir using ::com::sun::star::uno::cpp_release; 48*cdf0e10cSrcweir using ::com::sun::star::beans::PropertyState_DEFAULT_VALUE; 49*cdf0e10cSrcweir using ::com::sun::star::beans::PropertyState_DIRECT_VALUE; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir //===================================================================== 52*cdf0e10cSrcweir // OPropertyStateHelper 53*cdf0e10cSrcweir //===================================================================== 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir //--------------------------------------------------------------------- 56*cdf0e10cSrcweir ::com::sun::star::uno::Any SAL_CALL OPropertyStateHelper::queryInterface(const ::com::sun::star::uno::Type& _rType) throw( ::com::sun::star::uno::RuntimeException) 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir ::com::sun::star::uno::Any aReturn = OPropertySetHelper::queryInterface(_rType); 59*cdf0e10cSrcweir // our own ifaces 60*cdf0e10cSrcweir if ( !aReturn.hasValue() ) 61*cdf0e10cSrcweir aReturn = ::cppu::queryInterface(_rType, static_cast< ::com::sun::star::beans::XPropertyState*>(this)); 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir return aReturn; 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir //--------------------------------------------------------------------- 67*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> OPropertyStateHelper::getTypes() throw( ::com::sun::star::uno::RuntimeException) 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> aTypes; 70*cdf0e10cSrcweir if (!aTypes.getLength()) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir aTypes.realloc(4); 73*cdf0e10cSrcweir ::com::sun::star::uno::Type* pTypes = aTypes.getArray(); 74*cdf0e10cSrcweir // base class types 75*cdf0e10cSrcweir pTypes[0] = getCppuType(( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>*)NULL); 76*cdf0e10cSrcweir pTypes[1] = getCppuType(( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet>*)NULL); 77*cdf0e10cSrcweir pTypes[2] = getCppuType(( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet>*)NULL); 78*cdf0e10cSrcweir // my own type 79*cdf0e10cSrcweir pTypes[3] = getCppuType(( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState>*)NULL); 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir return aTypes; 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir OPropertyStateHelper::OPropertyStateHelper( 85*cdf0e10cSrcweir ::cppu::OBroadcastHelper& rBHlp, 86*cdf0e10cSrcweir ::cppu::IEventNotificationHook *i_pFireEvents) 87*cdf0e10cSrcweir : ::cppu::OPropertySetHelper(rBHlp, i_pFireEvents) { } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir OPropertyStateHelper::~OPropertyStateHelper() {} 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir //--------------------------------------------------------------------- 92*cdf0e10cSrcweir void OPropertyStateHelper::firePropertyChange(sal_Int32 nHandle, const ::com::sun::star::uno::Any& aNewValue, const ::com::sun::star::uno::Any& aOldValue) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir fire(&nHandle, &aNewValue, &aOldValue, 1, sal_False); 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir // XPropertyState 98*cdf0e10cSrcweir //--------------------------------------------------------------------- 99*cdf0e10cSrcweir ::com::sun::star::beans::PropertyState SAL_CALL OPropertyStateHelper::getPropertyState(const ::rtl::OUString& _rsName) throw( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir cppu::IPropertyArrayHelper& rPH = getInfoHelper(); 102*cdf0e10cSrcweir sal_Int32 nHandle = rPH.getHandleByName(_rsName); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir if (nHandle == -1) 105*cdf0e10cSrcweir throw ::com::sun::star::beans::UnknownPropertyException(); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir return getPropertyStateByHandle(nHandle); 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir //--------------------------------------------------------------------- 111*cdf0e10cSrcweir void SAL_CALL OPropertyStateHelper::setPropertyToDefault(const ::rtl::OUString& _rsName) throw( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir cppu::IPropertyArrayHelper& rPH = getInfoHelper(); 114*cdf0e10cSrcweir sal_Int32 nHandle = rPH.getHandleByName(_rsName); 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir if (nHandle == -1) 117*cdf0e10cSrcweir throw ::com::sun::star::beans::UnknownPropertyException(); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir setPropertyToDefaultByHandle(nHandle); 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir //--------------------------------------------------------------------- 123*cdf0e10cSrcweir ::com::sun::star::uno::Any SAL_CALL OPropertyStateHelper::getPropertyDefault(const ::rtl::OUString& _rsName) throw( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir cppu::IPropertyArrayHelper& rPH = getInfoHelper(); 126*cdf0e10cSrcweir sal_Int32 nHandle = rPH.getHandleByName(_rsName); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir if (nHandle == -1) 129*cdf0e10cSrcweir throw ::com::sun::star::beans::UnknownPropertyException(); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir return getPropertyDefaultByHandle(nHandle); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir //--------------------------------------------------------------------- 135*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState> SAL_CALL OPropertyStateHelper::getPropertyStates(const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rPropertyNames) throw( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir sal_Int32 nLen = _rPropertyNames.getLength(); 138*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState> aRet(nLen); 139*cdf0e10cSrcweir ::com::sun::star::beans::PropertyState* pValues = aRet.getArray(); 140*cdf0e10cSrcweir const ::rtl::OUString* pNames = _rPropertyNames.getConstArray(); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir cppu::IPropertyArrayHelper& rHelper = getInfoHelper(); 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property> aProps = rHelper.getProperties(); 145*cdf0e10cSrcweir const ::com::sun::star::beans::Property* pProps = aProps.getConstArray(); 146*cdf0e10cSrcweir sal_Int32 nPropCount = aProps.getLength(); 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir osl::MutexGuard aGuard(rBHelper.rMutex); 149*cdf0e10cSrcweir for (sal_Int32 i=0, j=0; i<nPropCount && j<nLen; ++i, ++pProps) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir // get the values only for valid properties 152*cdf0e10cSrcweir if (pProps->Name.equals(*pNames)) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir *pValues = getPropertyState(*pNames); 155*cdf0e10cSrcweir ++pValues; 156*cdf0e10cSrcweir ++pNames; 157*cdf0e10cSrcweir ++j; 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir return aRet; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir //--------------------------------------------------------------------- 165*cdf0e10cSrcweir ::com::sun::star::beans::PropertyState OPropertyStateHelper::getPropertyStateByHandle( sal_Int32 _nHandle ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir // simply compare the current and the default value 168*cdf0e10cSrcweir Any aCurrentValue = getPropertyDefaultByHandle( _nHandle ); 169*cdf0e10cSrcweir Any aDefaultValue; getFastPropertyValue( aDefaultValue, _nHandle ); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir sal_Bool bEqual = uno_type_equalData( 172*cdf0e10cSrcweir const_cast< void* >( aCurrentValue.getValue() ), aCurrentValue.getValueType().getTypeLibType(), 173*cdf0e10cSrcweir const_cast< void* >( aDefaultValue.getValue() ), aDefaultValue.getValueType().getTypeLibType(), 174*cdf0e10cSrcweir reinterpret_cast< uno_QueryInterfaceFunc >(cpp_queryInterface), 175*cdf0e10cSrcweir reinterpret_cast< uno_ReleaseFunc >(cpp_release) 176*cdf0e10cSrcweir ); 177*cdf0e10cSrcweir return bEqual ? PropertyState_DEFAULT_VALUE : PropertyState_DIRECT_VALUE; 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir //--------------------------------------------------------------------- 181*cdf0e10cSrcweir void OPropertyStateHelper::setPropertyToDefaultByHandle( sal_Int32 _nHandle ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir setFastPropertyValue( _nHandle, getPropertyDefaultByHandle( _nHandle ) ); 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir //--------------------------------------------------------------------- 187*cdf0e10cSrcweir ::com::sun::star::uno::Any OPropertyStateHelper::getPropertyDefaultByHandle( sal_Int32 ) const 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir return ::com::sun::star::uno::Any(); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir //===================================================================== 193*cdf0e10cSrcweir // OStatefulPropertySet 194*cdf0e10cSrcweir //===================================================================== 195*cdf0e10cSrcweir //--------------------------------------------------------------------- 196*cdf0e10cSrcweir OStatefulPropertySet::OStatefulPropertySet() 197*cdf0e10cSrcweir :OPropertyStateHelper( GetBroadcastHelper() ) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir //--------------------------------------------------------------------- 202*cdf0e10cSrcweir OStatefulPropertySet::~OStatefulPropertySet() 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir //--------------------------------------------------------------------- 207*cdf0e10cSrcweir Sequence< Type > SAL_CALL OStatefulPropertySet::getTypes() throw(RuntimeException) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir Sequence< Type > aOwnTypes( 2 ); 210*cdf0e10cSrcweir aOwnTypes[0] = XWeak::static_type(); 211*cdf0e10cSrcweir aOwnTypes[1] = XTypeProvider::static_type(); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir return concatSequences( 214*cdf0e10cSrcweir aOwnTypes, 215*cdf0e10cSrcweir OPropertyStateHelper::getTypes() 216*cdf0e10cSrcweir ); 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir //--------------------------------------------------------------------- 220*cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL OStatefulPropertySet::getImplementationId() throw(RuntimeException) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir static ::cppu::OImplementationId * pId = NULL; 223*cdf0e10cSrcweir if ( !pId ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 226*cdf0e10cSrcweir if ( !pId ) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir static ::cppu::OImplementationId aId; 229*cdf0e10cSrcweir pId = &aId; 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir return pId->getImplementationId(); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir //--------------------------------------------------------------------- 236*cdf0e10cSrcweir Any SAL_CALL OStatefulPropertySet::queryInterface( const Type& _rType ) throw(RuntimeException) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir Any aReturn = OWeakObject::queryInterface( _rType ); 239*cdf0e10cSrcweir if ( !aReturn.hasValue() ) 240*cdf0e10cSrcweir aReturn = ::cppu::queryInterface( _rType, static_cast< XTypeProvider* >( this ) ); 241*cdf0e10cSrcweir if ( !aReturn.hasValue() ) 242*cdf0e10cSrcweir aReturn = OPropertyStateHelper::queryInterface( _rType ); 243*cdf0e10cSrcweir return aReturn; 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir //--------------------------------------------------------------------- 247*cdf0e10cSrcweir void SAL_CALL OStatefulPropertySet::acquire() throw() 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir ::cppu::OWeakObject::acquire(); 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir //--------------------------------------------------------------------- 253*cdf0e10cSrcweir void SAL_CALL OStatefulPropertySet::release() throw() 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir ::cppu::OWeakObject::release(); 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir //......................................................................... 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir //......................................................................... 261*cdf0e10cSrcweir 262