tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / include / comphelper / property.hxx
blobb9787f1308bcd765926afb3aefd6ae735b85b30f
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 #ifndef INCLUDED_COMPHELPER_PROPERTY_HXX
21 #define INCLUDED_COMPHELPER_PROPERTY_HXX
23 #include <cppuhelper/proptypehlp.hxx>
24 #include <comphelper/extract.hxx>
25 #include <com/sun/star/beans/Property.hpp>
26 #include <type_traits>
27 #include <comphelper/comphelperdllapi.h>
29 namespace com::sun::star::beans { class XPropertySet; }
31 namespace comphelper
34 // comparing two property instances
35 struct PropertyCompareByName
37 bool operator() (const css::beans::Property& x, const css::beans::Property& y) const
39 return x.Name.compareTo(y.Name) < 0;
43 /// remove the property with the given name from the given sequence
44 COMPHELPER_DLLPUBLIC void RemoveProperty(css::uno::Sequence<css::beans::Property>& seqProps, const OUString& _rPropName);
46 /** within the given property sequence, modify attributes of a special property
47 @param _rProps the sequence of properties to search in
48 @param _sPropName the name of the property which's attributes should be modified
49 @param _nAddAttrib the attributes which should be added
50 @param _nRemoveAttrib the attributes which should be removed
52 COMPHELPER_DLLPUBLIC void ModifyPropertyAttributes(css::uno::Sequence<css::beans::Property>& _rProps, const OUString& _sPropName, sal_Int16 _nAddAttrib, sal_Int16 _nRemoveAttrib);
54 /** check if the given set has the given property.
56 COMPHELPER_DLLPUBLIC bool hasProperty(const OUString& _rName, const css::uno::Reference<css::beans::XPropertySet>& _rxSet);
58 /** copy properties between property sets, in compliance with the property
59 attributes of the target object
61 COMPHELPER_DLLPUBLIC void copyProperties(const css::uno::Reference<css::beans::XPropertySet>& _rxSource,
62 const css::uno::Reference<css::beans::XPropertySet>& _rxDest);
64 /** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue
65 @param _rConvertedValue the conversion result (if successful)
66 @param _rOldValue the old value of the property, calculated from _rCurrentValue
67 @param _rValueToSet the new value which is about to be set
68 @param _rCurrentValue the current value of the property
69 @return sal_True, if the value could be converted and has changed
70 sal_False, if the value could be converted and has not changed
71 @exception InvalidArgumentException thrown if the value could not be converted to the requested type (which is the template argument)
73 template <typename T>
74 bool tryPropertyValue(css::uno::Any& /*out*/_rConvertedValue, css::uno::Any& /*out*/_rOldValue, const css::uno::Any& _rValueToSet, const T& _rCurrentValue)
76 bool bModified(false);
77 T aNewValue = T();
78 ::cppu::convertPropertyValue(aNewValue, _rValueToSet);
79 if (aNewValue != _rCurrentValue)
81 _rConvertedValue <<= aNewValue;
82 _rOldValue <<= _rCurrentValue;
83 bModified = true;
85 return bModified;
88 /** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue for enum values
89 @param _rConvertedValue the conversion result (if successful)
90 @param _rOldValue the old value of the property, calculated from _rCurrentValue
91 @param _rValueToSet the new value which is about to be set
92 @param _rCurrentValue the current value of the property
93 @return sal_True, if the value could be converted and has changed
94 sal_False, if the value could be converted and has not changed
95 @exception InvalidArgumentException thrown if the value could not be converted to the requested type (which is the template argument)
97 template <class ENUMTYPE>
98 typename std::enable_if<std::is_enum<ENUMTYPE>::value, bool>::type
99 tryPropertyValueEnum(css::uno::Any& /*out*/_rConvertedValue, css::uno::Any& /*out*/_rOldValue, const css::uno::Any& _rValueToSet, const ENUMTYPE& _rCurrentValue)
101 bool bModified(false);
102 ENUMTYPE aNewValue;
103 ::cppu::any2enum(aNewValue, _rValueToSet);
104 // will throw an exception if not convertible
106 if (aNewValue != _rCurrentValue)
108 _rConvertedValue <<= aNewValue;
109 _rOldValue <<= _rCurrentValue;
110 bModified = true;
112 return bModified;
115 /** helper for implementing ::cppu::OPropertySetHelper::convertFastPropertyValue
116 @param _rConvertedValue the conversion result (if successful)
117 @param _rOldValue the old value of the property, calculated from _rCurrentValue
118 @param _rValueToSet the new value which is about to be set
119 @param _rCurrentValue the current value of the property
120 @param _rExpectedType the type which the property should have (if not void)
121 @return sal_True, if the value could be converted and has changed
122 sal_False, if the value could be converted and has not changed
123 @exception InvalidArgumentException thrown if the value could not be converted to the requested type (which is the template argument)
125 COMPHELPER_DLLPUBLIC bool tryPropertyValue(css::uno::Any& _rConvertedValue, css::uno::Any& _rOldValue, const css::uno::Any& _rValueToSet, const css::uno::Any& _rCurrentValue, const css::uno::Type& _rExpectedType);
129 #endif // INCLUDED_COMPHELPER_PROPERTY_HXX
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */