bump product version to 6.3.0.0.beta1
[LibreOffice.git] / comphelper / source / property / propertysethelper.cxx
blob1f456c2c00b39a89fc9e5868093847a0c755dc75
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 <comphelper/propertysetinfo.hxx>
21 #include <comphelper/propertysethelper.hxx>
22 #include <osl/diagnose.h>
23 #include <rtl/ref.hxx>
25 #include <memory>
27 using namespace ::comphelper;
28 using namespace ::com::sun::star;
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::beans;
31 using namespace ::com::sun::star::lang;
33 namespace comphelper
35 class PropertySetHelperImpl
37 public:
38 PropertyMapEntry const * find( const OUString& aName ) const throw();
40 rtl::Reference<PropertySetInfo> mxInfo;
44 PropertyMapEntry const * PropertySetHelperImpl::find( const OUString& aName ) const throw()
46 PropertyMap::const_iterator aIter = mxInfo->getPropertyMap().find( aName );
48 if( mxInfo->getPropertyMap().end() != aIter )
50 return (*aIter).second;
52 else
54 return nullptr;
59 PropertySetHelper::PropertySetHelper( rtl::Reference<comphelper::PropertySetInfo> const & xInfo ) throw()
60 : mpImpl(new PropertySetHelperImpl)
62 mpImpl->mxInfo = xInfo;
65 PropertySetHelper::~PropertySetHelper() throw()
69 // XPropertySet
70 Reference< XPropertySetInfo > SAL_CALL PropertySetHelper::getPropertySetInfo( )
72 return mpImpl->mxInfo.get();
75 void SAL_CALL PropertySetHelper::setPropertyValue( const OUString& aPropertyName, const Any& aValue )
77 PropertyMapEntry const * aEntries[2];
78 aEntries[0] = mpImpl->find( aPropertyName );
80 if( nullptr == aEntries[0] )
81 throw UnknownPropertyException( aPropertyName, static_cast< XPropertySet* >( this ) );
83 aEntries[1] = nullptr;
85 _setPropertyValues( aEntries, &aValue );
88 Any SAL_CALL PropertySetHelper::getPropertyValue( const OUString& PropertyName )
90 PropertyMapEntry const * aEntries[2];
91 aEntries[0] = mpImpl->find( PropertyName );
93 if( nullptr == aEntries[0] )
94 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
96 aEntries[1] = nullptr;
98 Any aAny;
99 _getPropertyValues( aEntries, &aAny );
101 return aAny;
104 void SAL_CALL PropertySetHelper::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
106 // todo
109 void SAL_CALL PropertySetHelper::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
111 // todo
114 void SAL_CALL PropertySetHelper::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
116 // todo
119 void SAL_CALL PropertySetHelper::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
121 // todo
124 // XMultiPropertySet
125 void SAL_CALL PropertySetHelper::setPropertyValues( const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rValues )
127 const sal_Int32 nCount = rPropertyNames.getLength();
129 if( nCount != rValues.getLength() )
130 throw IllegalArgumentException();
132 if( nCount )
134 std::unique_ptr<PropertyMapEntry const *[]> pEntries(new PropertyMapEntry const *[nCount+1]);
135 pEntries[nCount] = nullptr;
136 const OUString* pNames = rPropertyNames.getConstArray();
138 bool bUnknown = false;
139 sal_Int32 n;
140 for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
142 pEntries[n] = mpImpl->find( *pNames );
143 bUnknown = nullptr == pEntries[n];
146 if( !bUnknown )
147 _setPropertyValues( pEntries.get(), rValues.getConstArray() );
149 if( bUnknown )
150 throw RuntimeException( *pNames, static_cast< XPropertySet* >( this ) );
154 Sequence< Any > SAL_CALL PropertySetHelper::getPropertyValues(const Sequence< OUString >& rPropertyNames)
156 const sal_Int32 nCount = rPropertyNames.getLength();
158 Sequence< Any > aValues;
159 if( nCount )
161 std::unique_ptr<PropertyMapEntry const *[]> pEntries(new PropertyMapEntry const *[nCount+1]);
162 pEntries[nCount] = nullptr;
163 const OUString* pNames = rPropertyNames.getConstArray();
165 bool bUnknown = false;
166 sal_Int32 n;
167 for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
169 pEntries[n] = mpImpl->find( *pNames );
170 bUnknown = nullptr == pEntries[n];
173 if( !bUnknown )
175 aValues.realloc(nCount);
176 _getPropertyValues( pEntries.get(), aValues.getArray() );
179 if( bUnknown )
180 throw RuntimeException( *pNames, static_cast< XPropertySet* >( this ) );
183 return aValues;
186 void SAL_CALL PropertySetHelper::addPropertiesChangeListener( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
188 // todo
191 void SAL_CALL PropertySetHelper::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& )
193 // todo
196 void SAL_CALL PropertySetHelper::firePropertiesChangeEvent( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
198 // todo
201 // XPropertyState
202 PropertyState SAL_CALL PropertySetHelper::getPropertyState( const OUString& PropertyName )
204 PropertyMapEntry const * aEntries[2];
206 aEntries[0] = mpImpl->find( PropertyName );
207 if( aEntries[0] == nullptr )
208 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
210 aEntries[1] = nullptr;
212 PropertyState aState(PropertyState_AMBIGUOUS_VALUE);
213 _getPropertyStates( aEntries, &aState );
215 return aState;
218 Sequence< PropertyState > SAL_CALL PropertySetHelper::getPropertyStates( const Sequence< OUString >& aPropertyName )
220 const sal_Int32 nCount = aPropertyName.getLength();
222 Sequence< PropertyState > aStates( nCount );
224 if( nCount )
226 const OUString* pNames = aPropertyName.getConstArray();
228 bool bUnknown = false;
230 std::unique_ptr<PropertyMapEntry const *[]> pEntries(new PropertyMapEntry const *[nCount+1]);
232 sal_Int32 n;
233 for( n = 0; !bUnknown && (n < nCount); n++, pNames++ )
235 pEntries[n] = mpImpl->find( *pNames );
236 bUnknown = nullptr == pEntries[n];
239 pEntries[nCount] = nullptr;
241 if( !bUnknown )
242 _getPropertyStates( pEntries.get(), aStates.getArray() );
244 if( bUnknown )
245 throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) );
248 return aStates;
251 void SAL_CALL PropertySetHelper::setPropertyToDefault( const OUString& PropertyName )
253 PropertyMapEntry const *pEntry = mpImpl->find( PropertyName );
254 if( nullptr == pEntry )
255 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
257 _setPropertyToDefault( pEntry );
260 Any SAL_CALL PropertySetHelper::getPropertyDefault( const OUString& aPropertyName )
262 PropertyMapEntry const * pEntry = mpImpl->find( aPropertyName );
263 if( nullptr == pEntry )
264 throw UnknownPropertyException( aPropertyName, static_cast< XPropertySet* >( this ) );
266 return _getPropertyDefault( pEntry );
269 void PropertySetHelper::_getPropertyStates(
270 const comphelper::PropertyMapEntry**, PropertyState*)
272 OSL_FAIL( "you have to implement this yourself!");
275 void
276 PropertySetHelper::_setPropertyToDefault(const comphelper::PropertyMapEntry*)
278 OSL_FAIL( "you have to implement this yourself!");
281 Any PropertySetHelper::_getPropertyDefault(const comphelper::PropertyMapEntry*)
283 OSL_FAIL( "you have to implement this yourself!");
285 Any aAny;
286 return aAny;
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */