update emoji autocorrect entries from po-files
[LibreOffice.git] / include / oox / helper / propertyset.hxx
blob359d27db4351ac02a6550a1e7d11af0cc1cff4a1
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/beans/XMultiPropertySet.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/beans/XPropertySetInfo.hpp>
26 #include <oox/dllapi.h>
28 namespace oox {
30 class PropertyMap;
34 /** A wrapper for a UNO property set.
36 This class provides functions to silently get and set properties (without
37 exceptions, without the need to check validity of the UNO property set).
39 An instance is constructed with the reference to a UNO property set or any
40 other interface (the constructor will query for the
41 com.sun.star.beans.XPropertySet interface then). The reference to the
42 property set will be kept as long as the instance of this class is alive.
44 The functions setProperties() tries to handle all passed values at once,
45 using the com.sun.star.beans.XMultiPropertySet interface. If the
46 implementation does not support the XMultiPropertySet interface, all
47 properties are handled separately in a loop.
49 class OOX_DLLPUBLIC PropertySet
51 public:
52 PropertySet() {}
54 /** Constructs a property set wrapper with the passed UNO property set. */
55 explicit PropertySet(
56 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rxPropSet )
57 { set( rxPropSet ); }
59 /** Constructs a property set wrapper after querying the XPropertySet interface. */
60 template< typename Type >
61 explicit PropertySet( const Type& rObject ) { set( rObject ); }
63 /** Sets the passed UNO property set and releases the old UNO property set. */
64 void set( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rxPropSet );
66 /** Queries the passed object (interface or any) for an XPropertySet and releases the old UNO property set. */
67 template< typename Type >
68 void set( const Type& rObject )
69 { set( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >( rObject, ::com::sun::star::uno::UNO_QUERY ) ); }
71 /** Returns true, if the contained XPropertySet interface is valid. */
72 bool is() const { return mxPropSet.is(); }
74 /** Returns the contained XPropertySet interface. */
75 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
76 getXPropertySet() const { return mxPropSet; }
78 /** Returns true, if the specified property is supported by the property set. */
79 bool hasProperty( sal_Int32 nPropId ) const;
81 // Get properties ---------------------------------------------------------
83 /** Gets the specified property from the property set.
84 @return the property value, or an empty Any, if the property is missing. */
85 ::com::sun::star::uno::Any getAnyProperty( sal_Int32 nPropId ) const;
87 /** Gets the specified property from the property set.
88 @return true, if the passed variable could be filled with the property value. */
89 template< typename Type >
90 bool getProperty( Type& orValue, sal_Int32 nPropId ) const
91 { return getAnyProperty( nPropId ) >>= orValue; }
93 /** Gets the specified boolean property from the property set.
94 @return true = property contains true; false = property contains false or error occurred. */
95 bool getBoolProperty( sal_Int32 nPropId ) const
96 { bool bValue = false; return getProperty( bValue, nPropId ) && bValue; }
97 // Set properties ---------------------------------------------------------
99 /** Puts the passed any into the property set. */
100 bool setAnyProperty( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue );
102 /** Puts the passed value into the property set. */
103 template< typename Type >
104 bool setProperty( sal_Int32 nPropId, const Type& rValue )
105 { return setAnyProperty( nPropId, ::com::sun::star::uno::Any( rValue ) ); }
107 /** Puts the passed properties into the property set. Tries to use the XMultiPropertySet interface.
108 @param rPropNames The property names. MUST be ordered alphabetically.
109 @param rValues The related property values. */
110 void setProperties(
111 const ::com::sun::star::uno::Sequence< OUString >& rPropNames,
112 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rValues );
114 /** Puts the passed property map into the property set. Tries to use the XMultiPropertySet interface.
115 @param rPropertyMap The property map. */
116 void setProperties( const PropertyMap& rPropertyMap );
118 #ifdef DBG_UTIL
119 void dump();
120 #endif
123 private:
124 /** Gets the specified property from the property set.
125 @return true, if the any could be filled with the property value. */
126 bool implGetPropertyValue( ::com::sun::star::uno::Any& orValue, const OUString& rPropName ) const;
128 /** Puts the passed any into the property set. */
129 bool implSetPropertyValue( const OUString& rPropName, const ::com::sun::star::uno::Any& rValue );
131 private:
132 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
133 mxPropSet; ///< The mandatory property set interface.
134 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet >
135 mxMultiPropSet; ///< The optional multi property set interface.
136 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
137 mxPropSetInfo; ///< Property information.
142 } // namespace oox
144 #endif
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */