tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / comphelper / source / property / propertysethelper.cxx
blob334adf58fb494330ca69930730b9fecda3fcaee8
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(u"lengths do not match"_ustr, static_cast<XPropertySet*>(this), -1);
117 if( !nCount )
118 return;
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]);
126 if (!pEntries[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();
137 if( !nCount )
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]);
145 if (!pEntries[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() );
152 return aValues;
156 void SAL_CALL PropertySetHelper::addPropertiesChangeListener( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
158 // todo
161 void SAL_CALL PropertySetHelper::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& )
163 // todo
166 void SAL_CALL PropertySetHelper::firePropertiesChangeEvent( const Sequence< OUString >&, const Reference< XPropertiesChangeListener >& )
168 // todo
171 // XPropertyState
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 );
185 return aState;
188 Sequence< PropertyState > SAL_CALL PropertySetHelper::getPropertyStates( const Sequence< OUString >& aPropertyName )
190 const sal_Int32 nCount = aPropertyName.getLength();
192 Sequence< PropertyState > aStates( nCount );
194 if( nCount )
196 std::unique_ptr<PropertyMapEntry const *[]> pEntries(new PropertyMapEntry const *[nCount+1]);
198 sal_Int32 n;
199 for (n = 0; n < nCount; n++)
201 pEntries[n] = find(mxInfo, aPropertyName[n]);
202 if (!pEntries[n])
203 throw UnknownPropertyException(aPropertyName[n], static_cast<XPropertySet*>(this));
206 pEntries[nCount] = nullptr;
208 _getPropertyStates(pEntries.get(), aStates.getArray());
211 return aStates;
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!");
238 void
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!");
248 Any aAny;
249 return aAny;
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */