Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / comphelper / source / property / propertysethelper.cxx
blob979f1c9af8cfd3b8b02621c2bd868df0d06c3f13
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 .
21 #include "comphelper/propertysetinfo.hxx"
22 #include "comphelper/propertysethelper.hxx"
24 ///////////////////////////////////////////////////////////////////////
26 using namespace ::rtl;
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* find( const OUString& aName ) const throw();
40 PropertySetInfo* mpInfo;
44 PropertyMapEntry* PropertySetHelperImpl::find( const OUString& aName ) const throw()
46 PropertyMap::const_iterator aIter = mpInfo->getPropertyMap()->find( aName );
48 if( mpInfo->getPropertyMap()->end() != aIter )
50 return (*aIter).second;
52 else
54 return NULL;
58 ///////////////////////////////////////////////////////////////////////
60 PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo* pInfo ) throw()
62 mp = new PropertySetHelperImpl;
63 mp->mpInfo = pInfo;
64 pInfo->acquire();
67 PropertySetHelper::PropertySetHelper( comphelper::PropertySetInfo* pInfo, __sal_NoAcquire ) throw()
69 mp = new PropertySetHelperImpl;
70 mp->mpInfo = pInfo;
73 PropertySetHelper::~PropertySetHelper() throw()
75 mp->mpInfo->release();
76 delete mp;
79 // XPropertySet
80 Reference< XPropertySetInfo > SAL_CALL PropertySetHelper::getPropertySetInfo( ) throw(RuntimeException)
82 return mp->mpInfo;
85 void SAL_CALL PropertySetHelper::setPropertyValue( const ::rtl::OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
87 PropertyMapEntry* aEntries[2];
88 aEntries[0] = mp->find( aPropertyName );
90 if( NULL == aEntries[0] )
91 throw UnknownPropertyException( aPropertyName, static_cast< XPropertySet* >( this ) );
93 aEntries[1] = NULL;
95 _setPropertyValues( (const PropertyMapEntry**)aEntries, &aValue );
98 Any SAL_CALL PropertySetHelper::getPropertyValue( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
100 PropertyMapEntry* aEntries[2];
101 aEntries[0] = mp->find( PropertyName );
103 if( NULL == aEntries[0] )
104 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
106 aEntries[1] = NULL;
108 Any aAny;
109 _getPropertyValues( (const PropertyMapEntry**)aEntries, &aAny );
111 return aAny;
114 void SAL_CALL PropertySetHelper::addPropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
116 // todo
119 void SAL_CALL PropertySetHelper::removePropertyChangeListener( const ::rtl::OUString&, const Reference< XPropertyChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
121 // todo
124 void SAL_CALL PropertySetHelper::addVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
126 // todo
129 void SAL_CALL PropertySetHelper::removeVetoableChangeListener( const ::rtl::OUString&, const Reference< XVetoableChangeListener >& ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
131 // todo
134 // XMultiPropertySet
135 void SAL_CALL PropertySetHelper::setPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames, const Sequence< Any >& aValues ) throw(PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
137 const sal_Int32 nCount = aPropertyNames.getLength();
139 if( nCount != aValues.getLength() )
140 throw IllegalArgumentException();
142 if( nCount )
144 PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
145 pEntries[nCount] = NULL;
146 const OUString* pNames = aPropertyNames.getConstArray();
148 sal_Bool bUnknown = sal_False;
149 sal_Int32 n;
150 for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
152 pEntries[n] = mp->find( *pNames );
153 bUnknown = NULL == pEntries[n];
156 if( !bUnknown )
157 _setPropertyValues( (const PropertyMapEntry**)pEntries, aValues.getConstArray() );
159 delete[] pEntries;
161 if( bUnknown )
162 throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) );
166 Sequence< Any > SAL_CALL PropertySetHelper::getPropertyValues( const Sequence< ::rtl::OUString >& aPropertyNames ) throw(RuntimeException)
168 const sal_Int32 nCount = aPropertyNames.getLength();
170 Sequence< Any > aValues;
171 if( nCount )
173 PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
174 pEntries[nCount] = NULL;
175 const OUString* pNames = aPropertyNames.getConstArray();
177 sal_Bool bUnknown = sal_False;
178 sal_Int32 n;
179 for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
181 pEntries[n] = mp->find( *pNames );
182 bUnknown = NULL == pEntries[n];
185 if( !bUnknown )
187 aValues.realloc(nCount);
188 _getPropertyValues( (const PropertyMapEntry**)pEntries, aValues.getArray() );
191 delete[] pEntries;
193 if( bUnknown )
194 throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) );
197 return aValues;
200 void SAL_CALL PropertySetHelper::addPropertiesChangeListener( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& ) throw(RuntimeException)
202 // todo
205 void SAL_CALL PropertySetHelper::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& ) throw(RuntimeException)
207 // todo
210 void SAL_CALL PropertySetHelper::firePropertiesChangeEvent( const Sequence< ::rtl::OUString >&, const Reference< XPropertiesChangeListener >& ) throw(RuntimeException)
212 // todo
215 // XPropertyState
216 PropertyState SAL_CALL PropertySetHelper::getPropertyState( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
218 PropertyMapEntry* aEntries[2];
220 aEntries[0] = mp->find( PropertyName );
221 if( aEntries[0] == NULL )
222 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
224 aEntries[1] = NULL;
226 PropertyState aState;
227 _getPropertyStates( (const PropertyMapEntry**)aEntries, &aState );
229 return aState;
232 Sequence< PropertyState > SAL_CALL PropertySetHelper::getPropertyStates( const Sequence< ::rtl::OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException)
234 const sal_Int32 nCount = aPropertyName.getLength();
236 Sequence< PropertyState > aStates( nCount );
238 if( nCount )
240 const OUString* pNames = aPropertyName.getConstArray();
242 sal_Bool bUnknown = sal_False;
244 PropertyMapEntry** pEntries = new PropertyMapEntry*[nCount+1];
246 sal_Int32 n;
247 for( n = 0; !bUnknown && (n < nCount); n++, pNames++ )
249 pEntries[n] = mp->find( *pNames );
250 bUnknown = NULL == pEntries[n];
253 pEntries[nCount] = NULL;
255 if( !bUnknown )
256 _getPropertyStates( (const PropertyMapEntry**)pEntries, aStates.getArray() );
258 delete[] pEntries;
260 if( bUnknown )
261 throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) );
264 return aStates;
267 void SAL_CALL PropertySetHelper::setPropertyToDefault( const ::rtl::OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
269 PropertyMapEntry *pEntry = mp->find( PropertyName );
270 if( NULL == pEntry )
271 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
273 _setPropertyToDefault( pEntry );
276 Any SAL_CALL PropertySetHelper::getPropertyDefault( const ::rtl::OUString& aPropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
278 PropertyMapEntry* pEntry = mp->find( aPropertyName );
279 if( NULL == pEntry )
280 throw UnknownPropertyException( aPropertyName, static_cast< XPropertySet* >( this ) );
282 return _getPropertyDefault( pEntry );
285 void PropertySetHelper::_getPropertyStates( const comphelper::PropertyMapEntry**, PropertyState* ) throw(UnknownPropertyException )
287 OSL_FAIL( "you have to implement this yourself!");
290 void PropertySetHelper::_setPropertyToDefault( const comphelper::PropertyMapEntry* ) throw(UnknownPropertyException )
292 OSL_FAIL( "you have to implement this yourself!");
295 Any PropertySetHelper::_getPropertyDefault( const comphelper::PropertyMapEntry* ) throw(UnknownPropertyException, WrappedTargetException )
297 OSL_FAIL( "you have to implement this yourself!");
299 Any aAny;
300 return aAny;
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */