nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / core / PropertySetMerger.cxx
blob812201024c86fcb9068d05911546dcb986152d76
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <comphelper/sequence.hxx>
29 #include <cppuhelper/implbase3.hxx>
31 namespace {
33 class PropertySetMergerImpl : public ::cppu::WeakAggImplHelper3< XPropertySet, XPropertyState, XPropertySetInfo >
35 private:
36 Reference< XPropertySet > mxPropSet1;
37 Reference< XPropertyState > mxPropSet1State;
38 Reference< XPropertySetInfo > mxPropSet1Info;
40 Reference< XPropertySet > mxPropSet2;
41 Reference< XPropertyState > mxPropSet2State;
42 Reference< XPropertySetInfo > mxPropSet2Info;
44 public:
45 PropertySetMergerImpl( const Reference< XPropertySet > & rPropSet1, const Reference< XPropertySet > & rPropSet2 );
47 // XPropertySet
48 virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
49 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const Any& aValue ) override;
50 virtual Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
51 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener ) override;
52 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& aListener ) override;
53 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) override;
54 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) override;
56 // XPropertyState
57 virtual PropertyState SAL_CALL getPropertyState( const OUString& PropertyName ) override;
58 virtual Sequence< PropertyState > SAL_CALL getPropertyStates( const Sequence< OUString >& aPropertyName ) override;
59 virtual void SAL_CALL setPropertyToDefault( const OUString& PropertyName ) override;
60 virtual Any SAL_CALL getPropertyDefault( const OUString& aPropertyName ) override;
62 // XPropertySetInfo
63 virtual Sequence< Property > SAL_CALL getProperties( ) override;
64 virtual Property SAL_CALL getPropertyByName( const OUString& aName ) override;
65 virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) override;
70 // Interface implementation
72 PropertySetMergerImpl::PropertySetMergerImpl( Reference< XPropertySet > const & rPropSet1, Reference< XPropertySet > const & rPropSet2 )
73 : mxPropSet1( rPropSet1 )
74 , mxPropSet1State( rPropSet1, UNO_QUERY )
75 , mxPropSet1Info( rPropSet1->getPropertySetInfo() )
76 , mxPropSet2( rPropSet2 )
77 , mxPropSet2State( rPropSet2, UNO_QUERY )
78 , mxPropSet2Info( rPropSet2->getPropertySetInfo() )
82 // XPropertySet
83 Reference< XPropertySetInfo > SAL_CALL PropertySetMergerImpl::getPropertySetInfo( )
85 return this;
88 void SAL_CALL PropertySetMergerImpl::setPropertyValue( const OUString& aPropertyName, const Any& aValue )
90 if( mxPropSet1Info->hasPropertyByName( aPropertyName ) )
92 mxPropSet1->setPropertyValue( aPropertyName, aValue );
94 else
96 mxPropSet2->setPropertyValue( aPropertyName, aValue );
100 Any SAL_CALL PropertySetMergerImpl::getPropertyValue( const OUString& PropertyName )
102 if( mxPropSet1Info->hasPropertyByName( PropertyName ) )
104 return mxPropSet1->getPropertyValue( PropertyName );
106 else
108 return mxPropSet2->getPropertyValue( PropertyName );
112 void SAL_CALL PropertySetMergerImpl::addPropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*xListener*/ )
116 void SAL_CALL PropertySetMergerImpl::removePropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*aListener*/ )
120 void SAL_CALL PropertySetMergerImpl::addVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ )
124 void SAL_CALL PropertySetMergerImpl::removeVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ )
128 // XPropertyState
129 PropertyState SAL_CALL PropertySetMergerImpl::getPropertyState( const OUString& PropertyName )
131 if( mxPropSet1Info->hasPropertyByName( PropertyName ) )
133 if( mxPropSet1State.is() )
135 return mxPropSet1State->getPropertyState( PropertyName );
137 else
139 return PropertyState_DIRECT_VALUE;
142 else
144 if( mxPropSet2State.is() )
146 return mxPropSet2State->getPropertyState( PropertyName );
148 else
150 return PropertyState_DIRECT_VALUE;
155 Sequence< PropertyState > SAL_CALL PropertySetMergerImpl::getPropertyStates( const Sequence< OUString >& aPropertyName )
157 const sal_Int32 nCount = aPropertyName.getLength();
158 Sequence< PropertyState > aPropStates( nCount );
160 std::transform(aPropertyName.begin(), aPropertyName.end(), aPropStates.begin(),
161 [this](const OUString& rPropName) -> PropertyState { return getPropertyState(rPropName); });
163 return aPropStates;
166 void SAL_CALL PropertySetMergerImpl::setPropertyToDefault( const OUString& PropertyName )
168 if( mxPropSet1State.is() && mxPropSet1Info->hasPropertyByName( PropertyName ) )
170 mxPropSet1State->setPropertyToDefault( PropertyName );
172 else
174 if( mxPropSet2State.is() )
176 mxPropSet2State->setPropertyToDefault( PropertyName );
181 Any SAL_CALL PropertySetMergerImpl::getPropertyDefault( const OUString& aPropertyName )
183 if( mxPropSet1State.is() && mxPropSet1Info->hasPropertyByName( aPropertyName ) )
185 return mxPropSet1State->getPropertyDefault( aPropertyName );
187 else
189 if( mxPropSet2State.is() )
191 return mxPropSet2State->getPropertyDefault( aPropertyName );
193 else
195 Any aAny;
196 return aAny;
201 // XPropertySetInfo
202 Sequence< Property > SAL_CALL PropertySetMergerImpl::getProperties()
204 Sequence< Property > aProps1( mxPropSet1Info->getProperties() );
205 Sequence< Property > aProps2( mxPropSet2Info->getProperties() );
207 return comphelper::concatSequences(aProps1, aProps2);
210 Property SAL_CALL PropertySetMergerImpl::getPropertyByName( const OUString& aName )
212 if( mxPropSet1Info->hasPropertyByName( aName ) )
213 return mxPropSet1Info->getPropertyByName( aName );
215 return mxPropSet2Info->getPropertyByName( aName );
218 sal_Bool SAL_CALL PropertySetMergerImpl::hasPropertyByName( const OUString& Name )
220 if(mxPropSet1Info->hasPropertyByName( Name ) )
221 return true;
223 return mxPropSet2Info->hasPropertyByName( Name );
226 Reference< XPropertySet > PropertySetMerger_CreateInstance( const Reference< XPropertySet >& rPropSet1, const Reference< XPropertySet >& rPropSet2 ) throw()
228 return new PropertySetMergerImpl( rPropSet1, rPropSet2 );
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */