sw: clean up Start/EndAction in SwViewShell hierarchy
[LibreOffice.git] / include / oox / helper / propertyset.hxx
blob676ec4cebf829db37c582b482dfa41a22adf9a8d
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_OOX_HELPER_PROPERTYSET_HXX
21 #define INCLUDED_OOX_HELPER_PROPERTYSET_HXX
23 #include <com/sun/star/uno/Any.hxx>
24 #include <com/sun/star/uno/Reference.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
26 #include <oox/dllapi.h>
27 #include <rtl/ustring.hxx>
28 #include <sal/types.h>
29 #include <tools/color.hxx>
31 namespace com::sun::star {
32 namespace beans { class XMultiPropertySet; }
33 namespace beans { class XPropertySet; }
34 namespace beans { class XPropertySetInfo; }
37 namespace oox {
39 class PropertyMap;
42 /** A wrapper for a UNO property set.
44 This class provides functions to silently get and set properties (without
45 exceptions, without the need to check validity of the UNO property set).
47 An instance is constructed with the reference to a UNO property set or any
48 other interface (the constructor will query for the
49 com.sun.star.beans.XPropertySet interface then). The reference to the
50 property set will be kept as long as the instance of this class is alive.
52 The functions setProperties() tries to handle all passed values at once,
53 using the com.sun.star.beans.XMultiPropertySet interface. If the
54 implementation does not support the XMultiPropertySet interface, all
55 properties are handled separately in a loop.
57 class OOX_DLLPUBLIC PropertySet
59 public:
60 PropertySet() {}
62 /** Constructs a property set wrapper with the passed UNO property set. */
63 explicit PropertySet(
64 const css::uno::Reference< css::beans::XPropertySet >& rxPropSet )
65 { set( rxPropSet ); }
67 /** Constructs a property set wrapper after querying the XPropertySet interface. */
68 template< typename Type >
69 explicit PropertySet( const Type& rObject ) { set( rObject ); }
71 /** Sets the passed UNO property set and releases the old UNO property set. */
72 void set( const css::uno::Reference< css::beans::XPropertySet >& rxPropSet );
74 /** Queries the passed object (interface or any) for an XPropertySet and releases the old UNO property set. */
75 template< typename Type >
76 void set( const Type& rObject )
77 { set( css::uno::Reference< css::beans::XPropertySet >( rObject, css::uno::UNO_QUERY ) ); }
79 /** Returns true, if the contained XPropertySet interface is valid. */
80 bool is() const { return mxPropSet.is(); }
82 /** Returns true, if the specified property is supported by the property set. */
83 bool hasProperty( sal_Int32 nPropId ) const;
85 // Get properties ---------------------------------------------------------
87 /** Gets the specified property from the property set.
88 @return the property value, or an empty Any, if the property is missing. */
89 css::uno::Any getAnyProperty( sal_Int32 nPropId ) const;
91 /** Gets the specified property from the property set.
92 @return true, if the passed variable could be filled with the property value. */
93 template< typename Type >
94 bool getProperty( Type& orValue, sal_Int32 nPropId ) const
95 { return getAnyProperty( nPropId ) >>= orValue; }
97 /** Gets the specified boolean property from the property set.
98 @return true = property contains true; false = property contains false or error occurred. */
99 bool getBoolProperty( sal_Int32 nPropId ) const
100 { bool bValue = false; return getProperty( bValue, nPropId ) && bValue; }
101 // Set properties ---------------------------------------------------------
103 /** Puts the passed any into the property set. */
104 bool setAnyProperty( sal_Int32 nPropId, const css::uno::Any& rValue );
106 /** Puts the passed value into the property set. */
107 template< typename Type >
108 bool setProperty( sal_Int32 nPropId, const Type& rValue )
109 { return setAnyProperty( nPropId, css::uno::Any( rValue ) ); }
110 bool setProperty( sal_Int32 nPropId, ::Color rValue )
111 { return setAnyProperty( nPropId, css::uno::Any( rValue ) ); }
113 /** Puts the passed properties into the property set. Tries to use the XMultiPropertySet interface.
114 @param rPropNames The property names. MUST be ordered alphabetically.
115 @param rValues The related property values. */
116 void setProperties(
117 const css::uno::Sequence< OUString >& rPropNames,
118 const css::uno::Sequence< css::uno::Any >& rValues );
120 /** Puts the passed property map into the property set. Tries to use the XMultiPropertySet interface.
121 @param rPropertyMap The property map. */
122 void setProperties( const PropertyMap& rPropertyMap );
124 #ifdef DBG_UTIL
125 void dump();
126 #endif
129 private:
130 /** Gets the specified property from the property set.
131 @return true, if the any could be filled with the property value. */
132 bool implGetPropertyValue( css::uno::Any& orValue, const OUString& rPropName ) const;
134 /** Puts the passed any into the property set. */
135 bool implSetPropertyValue( const OUString& rPropName, const css::uno::Any& rValue );
137 private:
138 css::uno::Reference< css::beans::XPropertySet >
139 mxPropSet; ///< The mandatory property set interface.
140 css::uno::Reference< css::beans::XMultiPropertySet >
141 mxMultiPropSet; ///< The optional multi property set interface.
142 css::uno::Reference< css::beans::XPropertySetInfo >
143 mxPropSetInfo; ///< Property information.
147 } // namespace oox
149 #endif
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */