LibreOffice Module oox (master)  1
propertyset.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_OOX_HELPER_PROPERTYSET_HXX
21 #define INCLUDED_OOX_HELPER_PROPERTYSET_HXX
22 
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>
30 
31 namespace com::sun::star {
32  namespace beans { class XMultiPropertySet; }
33  namespace beans { class XPropertySet; }
34  namespace beans { class XPropertySetInfo; }
35 }
36 
37 namespace oox {
38 
39 class PropertyMap;
40 
41 
58 {
59 public:
61 
63  explicit PropertySet(
64  const css::uno::Reference< css::beans::XPropertySet >& rxPropSet )
65  { set( rxPropSet ); }
66 
68  template< typename Type >
69  explicit PropertySet( const Type& rObject ) { set( rObject ); }
70 
72  void set( const css::uno::Reference< css::beans::XPropertySet >& rxPropSet );
73 
75  template< typename Type >
76  void set( const Type& rObject )
77  { set( css::uno::Reference< css::beans::XPropertySet >( rObject, css::uno::UNO_QUERY ) ); }
78 
80  bool is() const { return mxPropSet.is(); }
81 
83  bool hasProperty( sal_Int32 nPropId ) const;
84 
85  // Get properties ---------------------------------------------------------
86 
89  css::uno::Any getAnyProperty( sal_Int32 nPropId ) const;
90 
93  template< typename Type >
94  bool getProperty( Type& orValue, sal_Int32 nPropId ) const
95  { return getAnyProperty( nPropId ) >>= orValue; }
96 
99  bool getBoolProperty( sal_Int32 nPropId ) const
100  { bool bValue = false; return getProperty( bValue, nPropId ) && bValue; }
101  // Set properties ---------------------------------------------------------
102 
104  bool setAnyProperty( sal_Int32 nPropId, const css::uno::Any& rValue );
105 
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::makeAny( rValue ) ); }
112 
116  void setProperties(
117  const css::uno::Sequence< OUString >& rPropNames,
118  const css::uno::Sequence< css::uno::Any >& rValues );
119 
122  void setProperties( const PropertyMap& rPropertyMap );
123 
124 #ifdef DBG_UTIL
125  void dump();
126 #endif
127 
128 
129 private:
132  bool implGetPropertyValue( css::uno::Any& orValue, const OUString& rPropName ) const;
133 
135  bool implSetPropertyValue( const OUString& rPropName, const css::uno::Any& rValue );
136 
137 private:
138  css::uno::Reference< css::beans::XPropertySet >
140  css::uno::Reference< css::beans::XMultiPropertySet >
142  css::uno::Reference< css::beans::XPropertySetInfo >
144 };
145 
146 
147 } // namespace oox
148 
149 #endif
150 
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Type
A helper that maps property identifiers to property values.
Definition: propertymap.hxx:52
bool getProperty(Type &orValue, sal_Int32 nPropId) const
Gets the specified property from the property set.
Definition: propertyset.hxx:94
PropertySet(const css::uno::Reference< css::beans::XPropertySet > &rxPropSet)
Constructs a property set wrapper with the passed UNO property set.
Definition: propertyset.hxx:63
css::uno::Reference< css::beans::XMultiPropertySet > mxMultiPropSet
The optional multi property set interface.
OUString getProperty(uno::Reference< beans::XPropertyContainer > const &rxPropertyContainer, OUString const &rName)
std::map< sal_Int32, STLPropertyMapEntry > PropertyMap
class SAL_NO_VTABLE XPropertySet
bool is() const
Returns true, if the contained XPropertySet interface is valid.
Definition: propertyset.hxx:80
bool setProperty(sal_Int32 nPropId,::Color rValue)
A wrapper for a UNO property set.
Definition: propertyset.hxx:57
VCL_DLLPUBLIC void dump(const SkBitmap &bitmap, const char *file)
exports com.sun.star. beans
bool getBoolProperty(sal_Int32 nPropId) const
Gets the specified boolean property from the property set.
Definition: propertyset.hxx:99
css::uno::Reference< css::beans::XPropertySet > mxPropSet
The mandatory property set interface.
void set(const Type &rObject)
Queries the passed object (interface or any) for an XPropertySet and releases the old UNO property se...
Definition: propertyset.hxx:76
#define OOX_DLLPUBLIC
Definition: dllapi.h:28
bool hasProperty(const OUString &_rName, const Reference< XPropertySet > &_rxSet)
PropertySet(const Type &rObject)
Constructs a property set wrapper after querying the XPropertySet interface.
Definition: propertyset.hxx:69
css::uno::Reference< css::beans::XPropertySetInfo > mxPropSetInfo
Property information.
bool setProperty(sal_Int32 nPropId, const Type &rValue)
Puts the passed value into the property set.
void set(css::uno::UnoInterfaceReference const &value)