LibreOffice Module xmloff (master) 1
PropertySetMerger.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <com/sun/star/beans/XPropertyState.hpp>
21#include <PropertySetMerger.hxx>
22
23using namespace ::com::sun::star;
24using namespace ::com::sun::star::uno;
25using namespace ::com::sun::star::beans;
26using namespace ::com::sun::star::lang;
27
30
31namespace {
32
33class PropertySetMergerImpl : public ::cppu::WeakAggImplHelper3< XPropertySet, XPropertyState, XPropertySetInfo >
34{
35private:
36 Reference< XPropertySet > mxPropSet1;
37 Reference< XPropertyState > mxPropSet1State;
38 Reference< XPropertySetInfo > mxPropSet1Info;
39
40 Reference< XPropertySet > mxPropSet2;
41 Reference< XPropertyState > mxPropSet2State;
42 Reference< XPropertySetInfo > mxPropSet2Info;
43
44public:
45 PropertySetMergerImpl( const Reference< XPropertySet > & rPropSet1, const Reference< XPropertySet > & rPropSet2 );
46
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;
55
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;
61
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;
66};
67
68}
69
70// Interface implementation
71
72PropertySetMergerImpl::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() )
79{
80}
81
82// XPropertySet
83Reference< XPropertySetInfo > SAL_CALL PropertySetMergerImpl::getPropertySetInfo( )
84{
85 return this;
86}
87
88void SAL_CALL PropertySetMergerImpl::setPropertyValue( const OUString& aPropertyName, const Any& aValue )
89{
90 if( mxPropSet1Info->hasPropertyByName( aPropertyName ) )
91 {
92 mxPropSet1->setPropertyValue( aPropertyName, aValue );
93 }
94 else
95 {
96 mxPropSet2->setPropertyValue( aPropertyName, aValue );
97 }
98}
99
100Any SAL_CALL PropertySetMergerImpl::getPropertyValue( const OUString& PropertyName )
101{
102 if( mxPropSet1Info->hasPropertyByName( PropertyName ) )
103 {
104 return mxPropSet1->getPropertyValue( PropertyName );
105 }
106 else
107 {
108 return mxPropSet2->getPropertyValue( PropertyName );
109 }
110}
111
112void SAL_CALL PropertySetMergerImpl::addPropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*xListener*/ )
113{
114}
115
116void SAL_CALL PropertySetMergerImpl::removePropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*aListener*/ )
117{
118}
119
120void SAL_CALL PropertySetMergerImpl::addVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ )
121{
122}
123
124void SAL_CALL PropertySetMergerImpl::removeVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ )
125{
126}
127
128// XPropertyState
129PropertyState SAL_CALL PropertySetMergerImpl::getPropertyState( const OUString& PropertyName )
130{
131 if( mxPropSet1Info->hasPropertyByName( PropertyName ) )
132 {
133 if( mxPropSet1State.is() )
134 {
135 return mxPropSet1State->getPropertyState( PropertyName );
136 }
137 else
138 {
139 return PropertyState_DIRECT_VALUE;
140 }
141 }
142 else
143 {
144 if( mxPropSet2State.is() )
145 {
146 return mxPropSet2State->getPropertyState( PropertyName );
147 }
148 else
149 {
150 return PropertyState_DIRECT_VALUE;
151 }
152 }
153}
154
155Sequence< PropertyState > SAL_CALL PropertySetMergerImpl::getPropertyStates( const Sequence< OUString >& aPropertyName )
156{
157 const sal_Int32 nCount = aPropertyName.getLength();
158 Sequence< PropertyState > aPropStates( nCount );
159
160 std::transform(aPropertyName.begin(), aPropertyName.end(), aPropStates.getArray(),
161 [this](const OUString& rPropName) -> PropertyState { return getPropertyState(rPropName); });
162
163 return aPropStates;
164}
165
166void SAL_CALL PropertySetMergerImpl::setPropertyToDefault( const OUString& PropertyName )
167{
168 if( mxPropSet1State.is() && mxPropSet1Info->hasPropertyByName( PropertyName ) )
169 {
170 mxPropSet1State->setPropertyToDefault( PropertyName );
171 }
172 else
173 {
174 if( mxPropSet2State.is() )
175 {
176 mxPropSet2State->setPropertyToDefault( PropertyName );
177 }
178 }
179}
180
181Any SAL_CALL PropertySetMergerImpl::getPropertyDefault( const OUString& aPropertyName )
182{
183 if( mxPropSet1State.is() && mxPropSet1Info->hasPropertyByName( aPropertyName ) )
184 {
185 return mxPropSet1State->getPropertyDefault( aPropertyName );
186 }
187 else
188 {
189 if( mxPropSet2State.is() )
190 {
191 return mxPropSet2State->getPropertyDefault( aPropertyName );
192 }
193 else
194 {
195 Any aAny;
196 return aAny;
197 }
198 }
199}
200
201// XPropertySetInfo
202Sequence< Property > SAL_CALL PropertySetMergerImpl::getProperties()
203{
204 Sequence< Property > aProps1( mxPropSet1Info->getProperties() );
205 Sequence< Property > aProps2( mxPropSet2Info->getProperties() );
206
207 return comphelper::concatSequences(aProps1, aProps2);
208}
209
210Property SAL_CALL PropertySetMergerImpl::getPropertyByName( const OUString& aName )
211{
212 if( mxPropSet1Info->hasPropertyByName( aName ) )
213 return mxPropSet1Info->getPropertyByName( aName );
214
215 return mxPropSet2Info->getPropertyByName( aName );
216}
217
218sal_Bool SAL_CALL PropertySetMergerImpl::hasPropertyByName( const OUString& Name )
219{
220 if(mxPropSet1Info->hasPropertyByName( Name ) )
221 return true;
222
223 return mxPropSet2Info->hasPropertyByName( Name );
224}
225
226Reference< XPropertySet > PropertySetMerger_CreateInstance( const Reference< XPropertySet >& rPropSet1, const Reference< XPropertySet >& rPropSet2 ) noexcept
227{
228 return new PropertySetMergerImpl( rPropSet1, rPropSet2 );
229}
230
231/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XPropertySet > PropertySetMerger_CreateInstance(const Reference< XPropertySet > &rPropSet1, const Reference< XPropertySet > &rPropSet2) noexcept
int nCount
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
VBAHELPER_DLLPUBLIC bool setPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
unsigned char sal_Bool