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 <comphelper/propertysetinfo.hxx>
21 #include <comphelper/propertysethelper.hxx>
22 #include <osl/diagnose.h>
23 #include <rtl/ref.hxx>
28 using namespace ::comphelper
;
29 using namespace ::com::sun::star
;
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::beans
;
32 using namespace ::com::sun::star::lang
;
34 static PropertyMapEntry
const * find( const rtl::Reference
<PropertySetInfo
>& mxInfo
, const OUString
& aName
) noexcept
36 PropertyMap::const_iterator aIter
= mxInfo
->getPropertyMap().find( aName
);
38 if( mxInfo
->getPropertyMap().end() != aIter
)
39 return (*aIter
).second
;
45 PropertySetHelper::PropertySetHelper( rtl::Reference
<comphelper::PropertySetInfo
> xInfo
) noexcept
46 : mxInfo(std::move(xInfo
))
50 PropertySetHelper::~PropertySetHelper() noexcept
55 Reference
< XPropertySetInfo
> SAL_CALL
PropertySetHelper::getPropertySetInfo( )
60 void SAL_CALL
PropertySetHelper::setPropertyValue( const OUString
& aPropertyName
, const Any
& aValue
)
62 PropertyMapEntry
const * aEntries
[2];
63 aEntries
[0] = find( mxInfo
, aPropertyName
);
65 if( nullptr == aEntries
[0] )
66 throw UnknownPropertyException( aPropertyName
, static_cast< XPropertySet
* >( this ) );
68 aEntries
[1] = nullptr;
70 _setPropertyValues( aEntries
, &aValue
);
73 Any SAL_CALL
PropertySetHelper::getPropertyValue( const OUString
& PropertyName
)
75 PropertyMapEntry
const * aEntries
[2];
76 aEntries
[0] = find( mxInfo
, PropertyName
);
78 if( nullptr == aEntries
[0] )
79 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
81 aEntries
[1] = nullptr;
84 _getPropertyValues( aEntries
, &aAny
);
89 void SAL_CALL
PropertySetHelper::addPropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& )
94 void SAL_CALL
PropertySetHelper::removePropertyChangeListener( const OUString
&, const Reference
< XPropertyChangeListener
>& )
99 void SAL_CALL
PropertySetHelper::addVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& )
104 void SAL_CALL
PropertySetHelper::removeVetoableChangeListener( const OUString
&, const Reference
< XVetoableChangeListener
>& )
110 void SAL_CALL
PropertySetHelper::setPropertyValues( const Sequence
< OUString
>& rPropertyNames
, const Sequence
< Any
>& rValues
)
112 const sal_Int32 nCount
= rPropertyNames
.getLength();
114 if( nCount
!= rValues
.getLength() )
115 throw IllegalArgumentException(u
"lengths do not match"_ustr
, static_cast<XPropertySet
*>(this), -1);
120 std::unique_ptr
<PropertyMapEntry
const *[]> pEntries(new PropertyMapEntry
const *[nCount
+1]);
121 pEntries
[nCount
] = nullptr;
123 for (sal_Int32 n
= 0; n
< nCount
; n
++)
125 pEntries
[n
] = find(mxInfo
, rPropertyNames
[n
]);
127 throw UnknownPropertyException(rPropertyNames
[n
], static_cast<XPropertySet
*>(this));
130 _setPropertyValues(pEntries
.get(), rValues
.getConstArray());
133 Sequence
< Any
> SAL_CALL
PropertySetHelper::getPropertyValues(const Sequence
< OUString
>& rPropertyNames
)
135 const sal_Int32 nCount
= rPropertyNames
.getLength();
138 return Sequence
< Any
>();
140 std::unique_ptr
<PropertyMapEntry
const *[]> pEntries(new PropertyMapEntry
const *[nCount
+1]);
142 for (sal_Int32 n
= 0; n
< nCount
; n
++)
144 pEntries
[n
] = find(mxInfo
, rPropertyNames
[n
]);
146 throw UnknownPropertyException(rPropertyNames
[n
], static_cast<XPropertySet
*>(this));
149 pEntries
[nCount
] = nullptr;
150 Sequence
< Any
> aValues(nCount
);
151 _getPropertyValues( pEntries
.get(), aValues
.getArray() );
156 void SAL_CALL
PropertySetHelper::addPropertiesChangeListener( const Sequence
< OUString
>&, const Reference
< XPropertiesChangeListener
>& )
161 void SAL_CALL
PropertySetHelper::removePropertiesChangeListener( const Reference
< XPropertiesChangeListener
>& )
166 void SAL_CALL
PropertySetHelper::firePropertiesChangeEvent( const Sequence
< OUString
>&, const Reference
< XPropertiesChangeListener
>& )
172 PropertyState SAL_CALL
PropertySetHelper::getPropertyState( const OUString
& PropertyName
)
174 PropertyMapEntry
const * aEntries
[2];
176 aEntries
[0] = find( mxInfo
, PropertyName
);
177 if( aEntries
[0] == nullptr )
178 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
180 aEntries
[1] = nullptr;
182 PropertyState
aState(PropertyState_AMBIGUOUS_VALUE
);
183 _getPropertyStates( aEntries
, &aState
);
188 Sequence
< PropertyState
> SAL_CALL
PropertySetHelper::getPropertyStates( const Sequence
< OUString
>& aPropertyName
)
190 const sal_Int32 nCount
= aPropertyName
.getLength();
192 Sequence
< PropertyState
> aStates( nCount
);
196 std::unique_ptr
<PropertyMapEntry
const *[]> pEntries(new PropertyMapEntry
const *[nCount
+1]);
199 for (n
= 0; n
< nCount
; n
++)
201 pEntries
[n
] = find(mxInfo
, aPropertyName
[n
]);
203 throw UnknownPropertyException(aPropertyName
[n
], static_cast<XPropertySet
*>(this));
206 pEntries
[nCount
] = nullptr;
208 _getPropertyStates(pEntries
.get(), aStates
.getArray());
214 void SAL_CALL
PropertySetHelper::setPropertyToDefault( const OUString
& PropertyName
)
216 PropertyMapEntry
const *pEntry
= find(mxInfo
, PropertyName
);
217 if( nullptr == pEntry
)
218 throw UnknownPropertyException( PropertyName
, static_cast< XPropertySet
* >( this ) );
220 _setPropertyToDefault( pEntry
);
223 Any SAL_CALL
PropertySetHelper::getPropertyDefault( const OUString
& aPropertyName
)
225 PropertyMapEntry
const * pEntry
= find(mxInfo
, aPropertyName
);
226 if( nullptr == pEntry
)
227 throw UnknownPropertyException( aPropertyName
, static_cast< XPropertySet
* >( this ) );
229 return _getPropertyDefault( pEntry
);
232 void PropertySetHelper::_getPropertyStates(
233 const comphelper::PropertyMapEntry
**, PropertyState
*)
235 OSL_FAIL( "you have to implement this yourself!");
239 PropertySetHelper::_setPropertyToDefault(const comphelper::PropertyMapEntry
*)
241 OSL_FAIL( "you have to implement this yourself!");
244 Any
PropertySetHelper::_getPropertyDefault(const comphelper::PropertyMapEntry
*)
246 OSL_FAIL( "you have to implement this yourself!");
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */