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_xmloff.hxx" 30*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyState.hpp> 31*cdf0e10cSrcweir #include "PropertySetMerger.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir using ::rtl::OUString; 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir using namespace ::com::sun::star; 36*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 37*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 38*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLBASE1_HXX_ 41*cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx> 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir class SvXMLAttrContainerItem_Impl; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir class PropertySetMergerImpl : public ::cppu::WeakAggImplHelper3< XPropertySet, XPropertyState, XPropertySetInfo > 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir private: 49*cdf0e10cSrcweir Reference< XPropertySet > mxPropSet1; 50*cdf0e10cSrcweir Reference< XPropertyState > mxPropSet1State; 51*cdf0e10cSrcweir Reference< XPropertySetInfo > mxPropSet1Info; 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir Reference< XPropertySet > mxPropSet2; 54*cdf0e10cSrcweir Reference< XPropertyState > mxPropSet2State; 55*cdf0e10cSrcweir Reference< XPropertySetInfo > mxPropSet2Info; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir public: 58*cdf0e10cSrcweir PropertySetMergerImpl( const Reference< XPropertySet > rPropSet1, const Reference< XPropertySet > rPropSet2 ); 59*cdf0e10cSrcweir virtual ~PropertySetMergerImpl(); 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir // XPropertySet 62*cdf0e10cSrcweir virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(RuntimeException); 63*cdf0e10cSrcweir virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException); 64*cdf0e10cSrcweir virtual Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException); 65*cdf0e10cSrcweir virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException); 66*cdf0e10cSrcweir virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& aListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException); 67*cdf0e10cSrcweir virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException); 68*cdf0e10cSrcweir virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException); 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir // XPropertyState 71*cdf0e10cSrcweir virtual PropertyState SAL_CALL getPropertyState( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException); 72*cdf0e10cSrcweir virtual Sequence< PropertyState > SAL_CALL getPropertyStates( const Sequence< OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException); 73*cdf0e10cSrcweir virtual void SAL_CALL setPropertyToDefault( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException); 74*cdf0e10cSrcweir virtual Any SAL_CALL getPropertyDefault( const OUString& aPropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException); 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir // XPropertySetInfo 77*cdf0e10cSrcweir virtual Sequence< Property > SAL_CALL getProperties( ) throw(RuntimeException); 78*cdf0e10cSrcweir virtual Property SAL_CALL getPropertyByName( const OUString& aName ) throw(UnknownPropertyException, RuntimeException); 79*cdf0e10cSrcweir virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw(RuntimeException); 80*cdf0e10cSrcweir }; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir // -------------------------------------------------------------------- 83*cdf0e10cSrcweir // Interface implementation 84*cdf0e10cSrcweir // -------------------------------------------------------------------- 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir PropertySetMergerImpl::PropertySetMergerImpl( Reference< XPropertySet > rPropSet1, Reference< XPropertySet > rPropSet2 ) 87*cdf0e10cSrcweir : mxPropSet1( rPropSet1 ) 88*cdf0e10cSrcweir , mxPropSet1State( rPropSet1, UNO_QUERY ) 89*cdf0e10cSrcweir , mxPropSet1Info( rPropSet1->getPropertySetInfo() ) 90*cdf0e10cSrcweir , mxPropSet2( rPropSet2 ) 91*cdf0e10cSrcweir , mxPropSet2State( rPropSet2, UNO_QUERY ) 92*cdf0e10cSrcweir , mxPropSet2Info( rPropSet2->getPropertySetInfo() ) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir PropertySetMergerImpl::~PropertySetMergerImpl() 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir // XPropertySet 101*cdf0e10cSrcweir Reference< XPropertySetInfo > SAL_CALL PropertySetMergerImpl::getPropertySetInfo( ) throw(RuntimeException) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir return this; 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir void SAL_CALL PropertySetMergerImpl::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir if( mxPropSet1Info->hasPropertyByName( aPropertyName ) ) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir mxPropSet1->setPropertyValue( aPropertyName, aValue ); 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir else 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir mxPropSet2->setPropertyValue( aPropertyName, aValue ); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir Any SAL_CALL PropertySetMergerImpl::getPropertyValue( const OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir if( mxPropSet1Info->hasPropertyByName( PropertyName ) ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir return mxPropSet1->getPropertyValue( PropertyName ); 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir else 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir return mxPropSet2->getPropertyValue( PropertyName ); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir void SAL_CALL PropertySetMergerImpl::addPropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*xListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir void SAL_CALL PropertySetMergerImpl::removePropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir void SAL_CALL PropertySetMergerImpl::addVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir void SAL_CALL PropertySetMergerImpl::removeVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir // XPropertyState 147*cdf0e10cSrcweir PropertyState SAL_CALL PropertySetMergerImpl::getPropertyState( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir if( mxPropSet1Info->hasPropertyByName( PropertyName ) ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir if( mxPropSet1State.is() ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir return mxPropSet1State->getPropertyState( PropertyName ); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir else 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir return PropertyState_DIRECT_VALUE; 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir else 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir if( mxPropSet2State.is() ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir return mxPropSet2State->getPropertyState( PropertyName ); 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir else 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir return PropertyState_DIRECT_VALUE; 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir Sequence< PropertyState > SAL_CALL PropertySetMergerImpl::getPropertyStates( const Sequence< OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir const sal_Int32 nCount = aPropertyName.getLength(); 176*cdf0e10cSrcweir Sequence< PropertyState > aPropStates( nCount ); 177*cdf0e10cSrcweir PropertyState* pPropStates = aPropStates.getArray(); 178*cdf0e10cSrcweir const OUString* pPropNames = aPropertyName.getConstArray(); 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir sal_Int32 nIndex; 181*cdf0e10cSrcweir for( nIndex = 0; nIndex < nCount; nIndex++ ) 182*cdf0e10cSrcweir *pPropStates++ = getPropertyState( *pPropNames++ ); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir return aPropStates; 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir void SAL_CALL PropertySetMergerImpl::setPropertyToDefault( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir if( mxPropSet1State.is() && mxPropSet1Info->hasPropertyByName( PropertyName ) ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir mxPropSet1State->setPropertyToDefault( PropertyName ); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir else 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir if( mxPropSet2State.is() ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir mxPropSet2State->setPropertyToDefault( PropertyName ); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir Any SAL_CALL PropertySetMergerImpl::getPropertyDefault( const OUString& aPropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir if( mxPropSet1State.is() && mxPropSet1Info->hasPropertyByName( aPropertyName ) ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir return mxPropSet1State->getPropertyDefault( aPropertyName ); 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir else 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir if( mxPropSet2State.is() ) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir return mxPropSet2State->getPropertyDefault( aPropertyName ); 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir else 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir Any aAny; 217*cdf0e10cSrcweir return aAny; 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir // XPropertySetInfo 223*cdf0e10cSrcweir Sequence< Property > SAL_CALL PropertySetMergerImpl::getProperties() throw(RuntimeException) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir Sequence< Property > aProps1( mxPropSet1Info->getProperties() ); 226*cdf0e10cSrcweir const Property* pProps1 = aProps1.getArray(); 227*cdf0e10cSrcweir const sal_Int32 nCount1 = aProps1.getLength(); 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir Sequence< Property > aProps2( mxPropSet1Info->getProperties() ); 230*cdf0e10cSrcweir const Property* pProps2 = aProps2.getArray(); 231*cdf0e10cSrcweir const sal_Int32 nCount2 = aProps2.getLength(); 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir Sequence< Property > aProperties( nCount1 + nCount2 ); 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir sal_Int32 nIndex; 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir Property* pProperties = aProperties.getArray(); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir for( nIndex = 0; nIndex < nCount1; nIndex++ ) 240*cdf0e10cSrcweir *pProperties++ = *pProps1++; 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir for( nIndex = 0; nIndex < nCount2; nIndex++ ) 243*cdf0e10cSrcweir *pProperties++ = *pProps2++; 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir return aProperties; 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir Property SAL_CALL PropertySetMergerImpl::getPropertyByName( const OUString& aName ) throw(UnknownPropertyException, RuntimeException) 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir if( mxPropSet1Info->hasPropertyByName( aName ) ) 251*cdf0e10cSrcweir return mxPropSet1Info->getPropertyByName( aName ); 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir return mxPropSet2Info->getPropertyByName( aName ); 254*cdf0e10cSrcweir } 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir sal_Bool SAL_CALL PropertySetMergerImpl::hasPropertyByName( const OUString& Name ) throw(RuntimeException) 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir if(mxPropSet1Info->hasPropertyByName( Name ) ) 259*cdf0e10cSrcweir return sal_True; 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir return mxPropSet2Info->hasPropertyByName( Name ); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir Reference< XPropertySet > PropertySetMerger_CreateInstance( Reference< XPropertySet > rPropSet1, Reference< XPropertySet > rPropSet2 ) throw() 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir return new PropertySetMergerImpl( rPropSet1, rPropSet2 ); 267*cdf0e10cSrcweir } 268