android: Update app-specific/MIME type icons
[LibreOffice.git] / comphelper / source / property / propertysethelper.cxx
blob519b0705fadd52c0bd106a15c89835d748dcaa70
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>
26 #include <utility>
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;
40 else
41 return nullptr;
45 PropertySetHelper::PropertySetHelper( rtl::Reference<comphelper::PropertySetInfo> xInfo ) noexcept
46 : mxInfo(std::move(xInfo))
50 PropertySetHelper::~PropertySetHelper() noexcept
54 // XPropertySet
55 Reference< XPropertySetInfo > SAL_CALL PropertySetHelper::getPropertySetInfo( )
57 return mxInfo;
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;
83 Any aAny;
84 _getPropertyValues( aEntries, &aAny );
86 return aAny;
89 void SAL_CALL PropertySetHelper::addPropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
91 // todo
94 void SAL_CALL PropertySetHelper::removePropertyChangeListener( const OUString&, const Reference< XPropertyChangeListener >& )
96 // todo
99 void SAL_CALL PropertySetHelper::addVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
101 // todo
104 void SAL_CALL PropertySetHelper::removeVetoableChangeListener( const OUString&, const Reference< XVetoableChangeListener >& )
106 // todo
109 // XMultiPropertySet
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("lengths do not match", uno::Reference<uno::XInterface>(), -1);
117 if( !nCount )
118 return;
120 std::unique_ptr<PropertyMapEntry const *[]> pEntries(new PropertyMapEntry const *[nCount+1]);
121 pEntries[nCount] = nullptr;
122 const OUString* pNames = rPropertyNames.getConstArray();
124 bool bUnknown = false;
125 sal_Int32 n;
126 for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
128 pEntries[n] = find( mxInfo, *pNames );
129 bUnknown = nullptr == pEntries[n];
132 if( !bUnknown )
133 _setPropertyValues( pEntries.get(), rValues.getConstArray() );
135 if( bUnknown )
136 throw RuntimeException( *pNames, static_cast< XPropertySet* >( this ) );
139 Sequence< Any > SAL_CALL PropertySetHelper::getPropertyValues(const Sequence< OUString >& rPropertyNames)
141 const sal_Int32 nCount = rPropertyNames.getLength();
143 if( !nCount )
144 return Sequence< Any >();
146 std::unique_ptr<PropertyMapEntry const *[]> pEntries(new PropertyMapEntry const *[nCount+1]);
147 const OUString* pNames = rPropertyNames.getConstArray();
149 bool bUnknown = false;
150 sal_Int32 n;
151 for( n = 0; !bUnknown && ( n < nCount ); n++, pNames++ )
153 pEntries[n] = find( mxInfo, *pNames );
154 bUnknown = nullptr == pEntries[n];
157 if( bUnknown )
158 throw RuntimeException( *pNames, static_cast< XPropertySet* >( this ) );
160 pEntries[nCount] = nullptr;
161 Sequence< Any > aValues(nCount);
162 aValues.realloc(nCount);
163 _getPropertyValues( pEntries.get(), aValues.getArray() );
164 return aValues;
168 void SAL_CALL PropertySetHelper::addPropertiesChangeListener( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
170 // todo
173 void SAL_CALL PropertySetHelper::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& )
175 // todo
178 void SAL_CALL PropertySetHelper::firePropertiesChangeEvent( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
180 // todo
183 // XPropertyState
184 PropertyState SAL_CALL PropertySetHelper::getPropertyState( const OUString& PropertyName )
186 PropertyMapEntry const * aEntries[2];
188 aEntries[0] = find( mxInfo, PropertyName );
189 if( aEntries[0] == nullptr )
190 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
192 aEntries[1] = nullptr;
194 PropertyState aState(PropertyState_AMBIGUOUS_VALUE);
195 _getPropertyStates( aEntries, &aState );
197 return aState;
200 Sequence< PropertyState > SAL_CALL PropertySetHelper::getPropertyStates( const Sequence< OUString >& aPropertyName )
202 const sal_Int32 nCount = aPropertyName.getLength();
204 Sequence< PropertyState > aStates( nCount );
206 if( nCount )
208 const OUString* pNames = aPropertyName.getConstArray();
210 bool bUnknown = false;
212 std::unique_ptr<PropertyMapEntry const *[]> pEntries(new PropertyMapEntry const *[nCount+1]);
214 sal_Int32 n;
215 for( n = 0; !bUnknown && (n < nCount); n++, pNames++ )
217 pEntries[n] = find( mxInfo, *pNames );
218 bUnknown = nullptr == pEntries[n];
221 pEntries[nCount] = nullptr;
223 if( !bUnknown )
224 _getPropertyStates( pEntries.get(), aStates.getArray() );
226 if( bUnknown )
227 throw UnknownPropertyException( *pNames, static_cast< XPropertySet* >( this ) );
230 return aStates;
233 void SAL_CALL PropertySetHelper::setPropertyToDefault( const OUString& PropertyName )
235 PropertyMapEntry const *pEntry = find(mxInfo, PropertyName );
236 if( nullptr == pEntry )
237 throw UnknownPropertyException( PropertyName, static_cast< XPropertySet* >( this ) );
239 _setPropertyToDefault( pEntry );
242 Any SAL_CALL PropertySetHelper::getPropertyDefault( const OUString& aPropertyName )
244 PropertyMapEntry const * pEntry = find(mxInfo, aPropertyName );
245 if( nullptr == pEntry )
246 throw UnknownPropertyException( aPropertyName, static_cast< XPropertySet* >( this ) );
248 return _getPropertyDefault( pEntry );
251 void PropertySetHelper::_getPropertyStates(
252 const comphelper::PropertyMapEntry**, PropertyState*)
254 OSL_FAIL( "you have to implement this yourself!");
257 void
258 PropertySetHelper::_setPropertyToDefault(const comphelper::PropertyMapEntry*)
260 OSL_FAIL( "you have to implement this yourself!");
263 Any PropertySetHelper::_getPropertyDefault(const comphelper::PropertyMapEntry*)
265 OSL_FAIL( "you have to implement this yourself!");
267 Any aAny;
268 return aAny;
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */