1*dde7d3faSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*dde7d3faSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*dde7d3faSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*dde7d3faSAndrew Rist * distributed with this work for additional information 6*dde7d3faSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*dde7d3faSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*dde7d3faSAndrew Rist * "License"); you may not use this file except in compliance 9*dde7d3faSAndrew Rist * with the License. You may obtain a copy of the License at 10*dde7d3faSAndrew Rist * 11*dde7d3faSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*dde7d3faSAndrew Rist * 13*dde7d3faSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*dde7d3faSAndrew Rist * software distributed under the License is distributed on an 15*dde7d3faSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*dde7d3faSAndrew Rist * KIND, either express or implied. See the License for the 17*dde7d3faSAndrew Rist * specific language governing permissions and limitations 18*dde7d3faSAndrew Rist * under the License. 19*dde7d3faSAndrew Rist * 20*dde7d3faSAndrew Rist *************************************************************/ 21*dde7d3faSAndrew Rist 22*dde7d3faSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_comphelper.hxx" 26cdf0e10cSrcweir #include <comphelper/propstate.hxx> 27cdf0e10cSrcweir #include <com/sun/star/uno/genfunc.h> 28cdf0e10cSrcweir #include <cppuhelper/queryinterface.hxx> 29cdf0e10cSrcweir #include <comphelper/sequence.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir //......................................................................... 32cdf0e10cSrcweir namespace comphelper 33cdf0e10cSrcweir { 34cdf0e10cSrcweir //......................................................................... 35cdf0e10cSrcweir 36cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 37cdf0e10cSrcweir using ::com::sun::star::uno::Type; 38cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 39cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 40cdf0e10cSrcweir using ::com::sun::star::lang::XTypeProvider; 41cdf0e10cSrcweir using ::com::sun::star::uno::Any; 42cdf0e10cSrcweir using ::com::sun::star::uno::cpp_queryInterface; 43cdf0e10cSrcweir using ::com::sun::star::uno::cpp_release; 44cdf0e10cSrcweir using ::com::sun::star::beans::PropertyState_DEFAULT_VALUE; 45cdf0e10cSrcweir using ::com::sun::star::beans::PropertyState_DIRECT_VALUE; 46cdf0e10cSrcweir 47cdf0e10cSrcweir //===================================================================== 48cdf0e10cSrcweir // OPropertyStateHelper 49cdf0e10cSrcweir //===================================================================== 50cdf0e10cSrcweir 51cdf0e10cSrcweir //--------------------------------------------------------------------- queryInterface(const::com::sun::star::uno::Type & _rType)52cdf0e10cSrcweir ::com::sun::star::uno::Any SAL_CALL OPropertyStateHelper::queryInterface(const ::com::sun::star::uno::Type& _rType) throw( ::com::sun::star::uno::RuntimeException) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir ::com::sun::star::uno::Any aReturn = OPropertySetHelper::queryInterface(_rType); 55cdf0e10cSrcweir // our own ifaces 56cdf0e10cSrcweir if ( !aReturn.hasValue() ) 57cdf0e10cSrcweir aReturn = ::cppu::queryInterface(_rType, static_cast< ::com::sun::star::beans::XPropertyState*>(this)); 58cdf0e10cSrcweir 59cdf0e10cSrcweir return aReturn; 60cdf0e10cSrcweir } 61cdf0e10cSrcweir 62cdf0e10cSrcweir //--------------------------------------------------------------------- getTypes()63cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> OPropertyStateHelper::getTypes() throw( ::com::sun::star::uno::RuntimeException) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> aTypes; 66cdf0e10cSrcweir if (!aTypes.getLength()) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir aTypes.realloc(4); 69cdf0e10cSrcweir ::com::sun::star::uno::Type* pTypes = aTypes.getArray(); 70cdf0e10cSrcweir // base class types 71cdf0e10cSrcweir pTypes[0] = getCppuType(( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>*)NULL); 72cdf0e10cSrcweir pTypes[1] = getCppuType(( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet>*)NULL); 73cdf0e10cSrcweir pTypes[2] = getCppuType(( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet>*)NULL); 74cdf0e10cSrcweir // my own type 75cdf0e10cSrcweir pTypes[3] = getCppuType(( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState>*)NULL); 76cdf0e10cSrcweir } 77cdf0e10cSrcweir return aTypes; 78cdf0e10cSrcweir } 79cdf0e10cSrcweir OPropertyStateHelper(::cppu::OBroadcastHelper & rBHlp,::cppu::IEventNotificationHook * i_pFireEvents)80cdf0e10cSrcweir OPropertyStateHelper::OPropertyStateHelper( 81cdf0e10cSrcweir ::cppu::OBroadcastHelper& rBHlp, 82cdf0e10cSrcweir ::cppu::IEventNotificationHook *i_pFireEvents) 83cdf0e10cSrcweir : ::cppu::OPropertySetHelper(rBHlp, i_pFireEvents) { } 84cdf0e10cSrcweir ~OPropertyStateHelper()85cdf0e10cSrcweir OPropertyStateHelper::~OPropertyStateHelper() {} 86cdf0e10cSrcweir 87cdf0e10cSrcweir //--------------------------------------------------------------------- firePropertyChange(sal_Int32 nHandle,const::com::sun::star::uno::Any & aNewValue,const::com::sun::star::uno::Any & aOldValue)88cdf0e10cSrcweir void OPropertyStateHelper::firePropertyChange(sal_Int32 nHandle, const ::com::sun::star::uno::Any& aNewValue, const ::com::sun::star::uno::Any& aOldValue) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir fire(&nHandle, &aNewValue, &aOldValue, 1, sal_False); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir // XPropertyState 94cdf0e10cSrcweir //--------------------------------------------------------------------- getPropertyState(const::rtl::OUString & _rsName)95cdf0e10cSrcweir ::com::sun::star::beans::PropertyState SAL_CALL OPropertyStateHelper::getPropertyState(const ::rtl::OUString& _rsName) throw( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir cppu::IPropertyArrayHelper& rPH = getInfoHelper(); 98cdf0e10cSrcweir sal_Int32 nHandle = rPH.getHandleByName(_rsName); 99cdf0e10cSrcweir 100cdf0e10cSrcweir if (nHandle == -1) 101cdf0e10cSrcweir throw ::com::sun::star::beans::UnknownPropertyException(); 102cdf0e10cSrcweir 103cdf0e10cSrcweir return getPropertyStateByHandle(nHandle); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir //--------------------------------------------------------------------- setPropertyToDefault(const::rtl::OUString & _rsName)107cdf0e10cSrcweir void SAL_CALL OPropertyStateHelper::setPropertyToDefault(const ::rtl::OUString& _rsName) throw( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir cppu::IPropertyArrayHelper& rPH = getInfoHelper(); 110cdf0e10cSrcweir sal_Int32 nHandle = rPH.getHandleByName(_rsName); 111cdf0e10cSrcweir 112cdf0e10cSrcweir if (nHandle == -1) 113cdf0e10cSrcweir throw ::com::sun::star::beans::UnknownPropertyException(); 114cdf0e10cSrcweir 115cdf0e10cSrcweir setPropertyToDefaultByHandle(nHandle); 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir //--------------------------------------------------------------------- getPropertyDefault(const::rtl::OUString & _rsName)119cdf0e10cSrcweir ::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) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir cppu::IPropertyArrayHelper& rPH = getInfoHelper(); 122cdf0e10cSrcweir sal_Int32 nHandle = rPH.getHandleByName(_rsName); 123cdf0e10cSrcweir 124cdf0e10cSrcweir if (nHandle == -1) 125cdf0e10cSrcweir throw ::com::sun::star::beans::UnknownPropertyException(); 126cdf0e10cSrcweir 127cdf0e10cSrcweir return getPropertyDefaultByHandle(nHandle); 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir //--------------------------------------------------------------------- getPropertyStates(const::com::sun::star::uno::Sequence<::rtl::OUString> & _rPropertyNames)131cdf0e10cSrcweir ::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) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir sal_Int32 nLen = _rPropertyNames.getLength(); 134cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState> aRet(nLen); 135cdf0e10cSrcweir ::com::sun::star::beans::PropertyState* pValues = aRet.getArray(); 136cdf0e10cSrcweir const ::rtl::OUString* pNames = _rPropertyNames.getConstArray(); 137cdf0e10cSrcweir 138cdf0e10cSrcweir cppu::IPropertyArrayHelper& rHelper = getInfoHelper(); 139cdf0e10cSrcweir 140cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property> aProps = rHelper.getProperties(); 141cdf0e10cSrcweir const ::com::sun::star::beans::Property* pProps = aProps.getConstArray(); 142cdf0e10cSrcweir sal_Int32 nPropCount = aProps.getLength(); 143cdf0e10cSrcweir 144cdf0e10cSrcweir osl::MutexGuard aGuard(rBHelper.rMutex); 145cdf0e10cSrcweir for (sal_Int32 i=0, j=0; i<nPropCount && j<nLen; ++i, ++pProps) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir // get the values only for valid properties 148cdf0e10cSrcweir if (pProps->Name.equals(*pNames)) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir *pValues = getPropertyState(*pNames); 151cdf0e10cSrcweir ++pValues; 152cdf0e10cSrcweir ++pNames; 153cdf0e10cSrcweir ++j; 154cdf0e10cSrcweir } 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir return aRet; 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir //--------------------------------------------------------------------- getPropertyStateByHandle(sal_Int32 _nHandle)161cdf0e10cSrcweir ::com::sun::star::beans::PropertyState OPropertyStateHelper::getPropertyStateByHandle( sal_Int32 _nHandle ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir // simply compare the current and the default value 164cdf0e10cSrcweir Any aCurrentValue = getPropertyDefaultByHandle( _nHandle ); 165cdf0e10cSrcweir Any aDefaultValue; getFastPropertyValue( aDefaultValue, _nHandle ); 166cdf0e10cSrcweir 167cdf0e10cSrcweir sal_Bool bEqual = uno_type_equalData( 168cdf0e10cSrcweir const_cast< void* >( aCurrentValue.getValue() ), aCurrentValue.getValueType().getTypeLibType(), 169cdf0e10cSrcweir const_cast< void* >( aDefaultValue.getValue() ), aDefaultValue.getValueType().getTypeLibType(), 170cdf0e10cSrcweir reinterpret_cast< uno_QueryInterfaceFunc >(cpp_queryInterface), 171cdf0e10cSrcweir reinterpret_cast< uno_ReleaseFunc >(cpp_release) 172cdf0e10cSrcweir ); 173cdf0e10cSrcweir return bEqual ? PropertyState_DEFAULT_VALUE : PropertyState_DIRECT_VALUE; 174cdf0e10cSrcweir } 175cdf0e10cSrcweir 176cdf0e10cSrcweir //--------------------------------------------------------------------- setPropertyToDefaultByHandle(sal_Int32 _nHandle)177cdf0e10cSrcweir void OPropertyStateHelper::setPropertyToDefaultByHandle( sal_Int32 _nHandle ) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir setFastPropertyValue( _nHandle, getPropertyDefaultByHandle( _nHandle ) ); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir //--------------------------------------------------------------------- getPropertyDefaultByHandle(sal_Int32) const183cdf0e10cSrcweir ::com::sun::star::uno::Any OPropertyStateHelper::getPropertyDefaultByHandle( sal_Int32 ) const 184cdf0e10cSrcweir { 185cdf0e10cSrcweir return ::com::sun::star::uno::Any(); 186cdf0e10cSrcweir } 187cdf0e10cSrcweir 188cdf0e10cSrcweir //===================================================================== 189cdf0e10cSrcweir // OStatefulPropertySet 190cdf0e10cSrcweir //===================================================================== 191cdf0e10cSrcweir //--------------------------------------------------------------------- OStatefulPropertySet()192cdf0e10cSrcweir OStatefulPropertySet::OStatefulPropertySet() 193cdf0e10cSrcweir :OPropertyStateHelper( GetBroadcastHelper() ) 194cdf0e10cSrcweir { 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir //--------------------------------------------------------------------- ~OStatefulPropertySet()198cdf0e10cSrcweir OStatefulPropertySet::~OStatefulPropertySet() 199cdf0e10cSrcweir { 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir //--------------------------------------------------------------------- getTypes()203cdf0e10cSrcweir Sequence< Type > SAL_CALL OStatefulPropertySet::getTypes() throw(RuntimeException) 204cdf0e10cSrcweir { 205cdf0e10cSrcweir Sequence< Type > aOwnTypes( 2 ); 206cdf0e10cSrcweir aOwnTypes[0] = XWeak::static_type(); 207cdf0e10cSrcweir aOwnTypes[1] = XTypeProvider::static_type(); 208cdf0e10cSrcweir 209cdf0e10cSrcweir return concatSequences( 210cdf0e10cSrcweir aOwnTypes, 211cdf0e10cSrcweir OPropertyStateHelper::getTypes() 212cdf0e10cSrcweir ); 213cdf0e10cSrcweir } 214cdf0e10cSrcweir 215cdf0e10cSrcweir //--------------------------------------------------------------------- getImplementationId()216cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL OStatefulPropertySet::getImplementationId() throw(RuntimeException) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir static ::cppu::OImplementationId * pId = NULL; 219cdf0e10cSrcweir if ( !pId ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 222cdf0e10cSrcweir if ( !pId ) 223cdf0e10cSrcweir { 224cdf0e10cSrcweir static ::cppu::OImplementationId aId; 225cdf0e10cSrcweir pId = &aId; 226cdf0e10cSrcweir } 227cdf0e10cSrcweir } 228cdf0e10cSrcweir return pId->getImplementationId(); 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir //--------------------------------------------------------------------- queryInterface(const Type & _rType)232cdf0e10cSrcweir Any SAL_CALL OStatefulPropertySet::queryInterface( const Type& _rType ) throw(RuntimeException) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir Any aReturn = OWeakObject::queryInterface( _rType ); 235cdf0e10cSrcweir if ( !aReturn.hasValue() ) 236cdf0e10cSrcweir aReturn = ::cppu::queryInterface( _rType, static_cast< XTypeProvider* >( this ) ); 237cdf0e10cSrcweir if ( !aReturn.hasValue() ) 238cdf0e10cSrcweir aReturn = OPropertyStateHelper::queryInterface( _rType ); 239cdf0e10cSrcweir return aReturn; 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242cdf0e10cSrcweir //--------------------------------------------------------------------- acquire()243cdf0e10cSrcweir void SAL_CALL OStatefulPropertySet::acquire() throw() 244cdf0e10cSrcweir { 245cdf0e10cSrcweir ::cppu::OWeakObject::acquire(); 246cdf0e10cSrcweir } 247cdf0e10cSrcweir 248cdf0e10cSrcweir //--------------------------------------------------------------------- release()249cdf0e10cSrcweir void SAL_CALL OStatefulPropertySet::release() throw() 250cdf0e10cSrcweir { 251cdf0e10cSrcweir ::cppu::OWeakObject::release(); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir 254cdf0e10cSrcweir //......................................................................... 255cdf0e10cSrcweir } 256cdf0e10cSrcweir //......................................................................... 257cdf0e10cSrcweir 258