1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/beans/XPropertyState.hpp>
21 #include "PropertySetMerger.hxx"
23 using namespace ::com::sun::star
;
24 using namespace ::com::sun::star::uno
;
25 using namespace ::com::sun::star::beans
;
26 using namespace ::com::sun::star::lang
;
28 #include <cppuhelper/implbase3.hxx>
30 class PropertySetMergerImpl
: public ::cppu::WeakAggImplHelper3
< XPropertySet
, XPropertyState
, XPropertySetInfo
>
33 Reference
< XPropertySet
> mxPropSet1
;
34 Reference
< XPropertyState
> mxPropSet1State
;
35 Reference
< XPropertySetInfo
> mxPropSet1Info
;
37 Reference
< XPropertySet
> mxPropSet2
;
38 Reference
< XPropertyState
> mxPropSet2State
;
39 Reference
< XPropertySetInfo
> mxPropSet2Info
;
42 PropertySetMergerImpl( const Reference
< XPropertySet
> rPropSet1
, const Reference
< XPropertySet
> rPropSet2
);
43 virtual ~PropertySetMergerImpl();
46 virtual Reference
< XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw(RuntimeException
, std::exception
) override
;
47 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
, const Any
& aValue
) throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
, std::exception
) override
;
48 virtual Any SAL_CALL
getPropertyValue( const OUString
& PropertyName
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
) override
;
49 virtual void SAL_CALL
addPropertyChangeListener( const OUString
& aPropertyName
, const Reference
< XPropertyChangeListener
>& xListener
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
) override
;
50 virtual void SAL_CALL
removePropertyChangeListener( const OUString
& aPropertyName
, const Reference
< XPropertyChangeListener
>& aListener
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
) override
;
51 virtual void SAL_CALL
addVetoableChangeListener( const OUString
& PropertyName
, const Reference
< XVetoableChangeListener
>& aListener
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
) override
;
52 virtual void SAL_CALL
removeVetoableChangeListener( const OUString
& PropertyName
, const Reference
< XVetoableChangeListener
>& aListener
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
) override
;
55 virtual PropertyState SAL_CALL
getPropertyState( const OUString
& PropertyName
) throw(UnknownPropertyException
, RuntimeException
, std::exception
) override
;
56 virtual Sequence
< PropertyState
> SAL_CALL
getPropertyStates( const Sequence
< OUString
>& aPropertyName
) throw(UnknownPropertyException
, RuntimeException
, std::exception
) override
;
57 virtual void SAL_CALL
setPropertyToDefault( const OUString
& PropertyName
) throw(UnknownPropertyException
, RuntimeException
, std::exception
) override
;
58 virtual Any SAL_CALL
getPropertyDefault( const OUString
& aPropertyName
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
) override
;
61 virtual Sequence
< Property
> SAL_CALL
getProperties( ) throw(RuntimeException
, std::exception
) override
;
62 virtual Property SAL_CALL
getPropertyByName( const OUString
& aName
) throw(UnknownPropertyException
, RuntimeException
, std::exception
) override
;
63 virtual sal_Bool SAL_CALL
hasPropertyByName( const OUString
& Name
) throw(RuntimeException
, std::exception
) override
;
66 // Interface implementation
68 PropertySetMergerImpl::PropertySetMergerImpl( Reference
< XPropertySet
> rPropSet1
, Reference
< XPropertySet
> rPropSet2
)
69 : mxPropSet1( rPropSet1
)
70 , mxPropSet1State( rPropSet1
, UNO_QUERY
)
71 , mxPropSet1Info( rPropSet1
->getPropertySetInfo() )
72 , mxPropSet2( rPropSet2
)
73 , mxPropSet2State( rPropSet2
, UNO_QUERY
)
74 , mxPropSet2Info( rPropSet2
->getPropertySetInfo() )
78 PropertySetMergerImpl::~PropertySetMergerImpl()
83 Reference
< XPropertySetInfo
> SAL_CALL
PropertySetMergerImpl::getPropertySetInfo( ) throw(RuntimeException
, std::exception
)
88 void SAL_CALL
PropertySetMergerImpl::setPropertyValue( const OUString
& aPropertyName
, const Any
& aValue
) throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
, std::exception
)
90 if( mxPropSet1Info
->hasPropertyByName( aPropertyName
) )
92 mxPropSet1
->setPropertyValue( aPropertyName
, aValue
);
96 mxPropSet2
->setPropertyValue( aPropertyName
, aValue
);
100 Any SAL_CALL
PropertySetMergerImpl::getPropertyValue( const OUString
& PropertyName
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
102 if( mxPropSet1Info
->hasPropertyByName( PropertyName
) )
104 return mxPropSet1
->getPropertyValue( PropertyName
);
108 return mxPropSet2
->getPropertyValue( PropertyName
);
112 void SAL_CALL
PropertySetMergerImpl::addPropertyChangeListener( const OUString
& /*aPropertyName*/, const Reference
< XPropertyChangeListener
>& /*xListener*/ ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
116 void SAL_CALL
PropertySetMergerImpl::removePropertyChangeListener( const OUString
& /*aPropertyName*/, const Reference
< XPropertyChangeListener
>& /*aListener*/ ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
120 void SAL_CALL
PropertySetMergerImpl::addVetoableChangeListener( const OUString
& /*PropertyName*/, const Reference
< XVetoableChangeListener
>& /*aListener*/ ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
124 void SAL_CALL
PropertySetMergerImpl::removeVetoableChangeListener( const OUString
& /*PropertyName*/, const Reference
< XVetoableChangeListener
>& /*aListener*/ ) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
129 PropertyState SAL_CALL
PropertySetMergerImpl::getPropertyState( const OUString
& PropertyName
) throw(UnknownPropertyException
, RuntimeException
, std::exception
)
131 if( mxPropSet1Info
->hasPropertyByName( PropertyName
) )
133 if( mxPropSet1State
.is() )
135 return mxPropSet1State
->getPropertyState( PropertyName
);
139 return PropertyState_DIRECT_VALUE
;
144 if( mxPropSet2State
.is() )
146 return mxPropSet2State
->getPropertyState( PropertyName
);
150 return PropertyState_DIRECT_VALUE
;
155 Sequence
< PropertyState
> SAL_CALL
PropertySetMergerImpl::getPropertyStates( const Sequence
< OUString
>& aPropertyName
) throw(UnknownPropertyException
, RuntimeException
, std::exception
)
157 const sal_Int32 nCount
= aPropertyName
.getLength();
158 Sequence
< PropertyState
> aPropStates( nCount
);
159 PropertyState
* pPropStates
= aPropStates
.getArray();
160 const OUString
* pPropNames
= aPropertyName
.getConstArray();
163 for( nIndex
= 0; nIndex
< nCount
; nIndex
++ )
164 *pPropStates
++ = getPropertyState( *pPropNames
++ );
169 void SAL_CALL
PropertySetMergerImpl::setPropertyToDefault( const OUString
& PropertyName
) throw(UnknownPropertyException
, RuntimeException
, std::exception
)
171 if( mxPropSet1State
.is() && mxPropSet1Info
->hasPropertyByName( PropertyName
) )
173 mxPropSet1State
->setPropertyToDefault( PropertyName
);
177 if( mxPropSet2State
.is() )
179 mxPropSet2State
->setPropertyToDefault( PropertyName
);
184 Any SAL_CALL
PropertySetMergerImpl::getPropertyDefault( const OUString
& aPropertyName
) throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
, std::exception
)
186 if( mxPropSet1State
.is() && mxPropSet1Info
->hasPropertyByName( aPropertyName
) )
188 return mxPropSet1State
->getPropertyDefault( aPropertyName
);
192 if( mxPropSet2State
.is() )
194 return mxPropSet2State
->getPropertyDefault( aPropertyName
);
205 Sequence
< Property
> SAL_CALL
PropertySetMergerImpl::getProperties() throw(RuntimeException
, std::exception
)
207 Sequence
< Property
> aProps1( mxPropSet1Info
->getProperties() );
208 const Property
* pProps1
= aProps1
.getArray();
209 const sal_Int32 nCount1
= aProps1
.getLength();
211 Sequence
< Property
> aProps2( mxPropSet1Info
->getProperties() );
212 const Property
* pProps2
= aProps2
.getArray();
213 const sal_Int32 nCount2
= aProps2
.getLength();
215 Sequence
< Property
> aProperties( nCount1
+ nCount2
);
219 Property
* pProperties
= aProperties
.getArray();
221 for( nIndex
= 0; nIndex
< nCount1
; nIndex
++ )
222 *pProperties
++ = *pProps1
++;
224 for( nIndex
= 0; nIndex
< nCount2
; nIndex
++ )
225 *pProperties
++ = *pProps2
++;
230 Property SAL_CALL
PropertySetMergerImpl::getPropertyByName( const OUString
& aName
) throw(UnknownPropertyException
, RuntimeException
, std::exception
)
232 if( mxPropSet1Info
->hasPropertyByName( aName
) )
233 return mxPropSet1Info
->getPropertyByName( aName
);
235 return mxPropSet2Info
->getPropertyByName( aName
);
238 sal_Bool SAL_CALL
PropertySetMergerImpl::hasPropertyByName( const OUString
& Name
) throw(RuntimeException
, std::exception
)
240 if(mxPropSet1Info
->hasPropertyByName( Name
) )
243 return mxPropSet2Info
->hasPropertyByName( Name
);
246 Reference
< XPropertySet
> PropertySetMerger_CreateInstance( const Reference
< XPropertySet
>& rPropSet1
, const Reference
< XPropertySet
>& rPropSet2
) throw()
248 return new PropertySetMergerImpl( rPropSet1
, rPropSet2
);
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */