1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
19 #ifndef INCLUDED_SVL_ITEMPROP_HXX
20 #define INCLUDED_SVL_ITEMPROP_HXX
22 #include <com/sun/star/beans/XPropertySetInfo.hpp>
23 #include <com/sun/star/beans/PropertyState.hpp>
24 #include <comphelper/propertysetinfo.hxx>
25 #include <cppuhelper/implbase.hxx>
26 #include <svl/itemset.hxx>
27 #include <svl/svldllapi.h>
28 #include <o3tl/sorted_vector.hxx>
29 #include <o3tl/span.hxx>
30 #include <string_view>
33 // values from com/sun/star/beans/PropertyAttribute
34 #define PROPERTY_NONE 0
36 /// map a property between beans::XPropertySet and SfxPoolItem
37 struct SfxItemPropertyMapEntry
39 OUString aName
; ///< name of property
40 css::uno::Type aType
; ///< UNO type of property
41 sal_uInt16 nWID
; ///< WhichId of SfxPoolItem
42 /// flag bitmap, @see css::beans::PropertyAttribute
44 /// "member ID" to tell QueryValue/PutValue which property it is
45 /// (when multiple properties map to the same nWID)
47 PropertyMoreFlags nMoreFlags
;
49 SfxItemPropertyMapEntry(OUString _aName
, sal_uInt16 _nWID
, css::uno::Type
const & _rType
,
50 sal_Int16 _nFlags
, sal_uInt8
const _nMemberId
, PropertyMoreFlags _nMoreFlags
= PropertyMoreFlags::NONE
)
51 : aName(std::move( _aName
))
55 , nMemberId( _nMemberId
)
56 , nMoreFlags( _nMoreFlags
)
58 assert(_nFlags
<= 0x1ff );
59 assert( (_nMemberId
& 0x40) == 0 );
60 // Verify that if METRIC_ITEM is set, we are one of the types supported by
62 assert(!(_nMoreFlags
& PropertyMoreFlags::METRIC_ITEM
) ||
63 ( (aType
.getTypeClass() == css::uno::TypeClass_BYTE
)
64 || (aType
.getTypeClass() == css::uno::TypeClass_SHORT
)
65 || (aType
.getTypeClass() == css::uno::TypeClass_UNSIGNED_SHORT
)
66 || (aType
.getTypeClass() == css::uno::TypeClass_LONG
)
67 || (aType
.getTypeClass() == css::uno::TypeClass_UNSIGNED_LONG
)
72 struct SfxItemPropertyMapCompare
74 bool operator() ( const SfxItemPropertyMapEntry
* lhs
, const SfxItemPropertyMapEntry
* rhs
) const
76 return lhs
->aName
< rhs
->aName
;
79 class SVL_DLLPUBLIC SfxItemPropertyMap
81 o3tl::sorted_vector
< const SfxItemPropertyMapEntry
*, SfxItemPropertyMapCompare
> m_aMap
;
82 mutable css::uno::Sequence
< css::beans::Property
> m_aPropSeq
;
84 SfxItemPropertyMap( o3tl::span
<const SfxItemPropertyMapEntry
> pEntries
);
85 SfxItemPropertyMap( const SfxItemPropertyMap
& rSource
);
86 ~SfxItemPropertyMap();
88 const SfxItemPropertyMapEntry
* getByName( std::u16string_view rName
) const;
89 css::uno::Sequence
< css::beans::Property
> const & getProperties() const;
90 /// @throws css::beans::UnknownPropertyException
91 css::beans::Property
getPropertyByName( const OUString
& rName
) const;
92 bool hasPropertyByName( std::u16string_view rName
) const;
94 const o3tl::sorted_vector
< const SfxItemPropertyMapEntry
*, SfxItemPropertyMapCompare
>& getPropertyEntries() const { return m_aMap
; }
97 class SVL_DLLPUBLIC SfxItemPropertySet final
99 SfxItemPropertyMap m_aMap
;
100 mutable css::uno::Reference
<css::beans::XPropertySetInfo
> m_xInfo
;
103 SfxItemPropertySet( o3tl::span
<const SfxItemPropertyMapEntry
> pMap
) :
105 ~SfxItemPropertySet();
107 /// @throws css::uno::RuntimeException
108 void getPropertyValue( const SfxItemPropertyMapEntry
& rEntry
,
109 const SfxItemSet
& rSet
,
110 css::uno::Any
& rAny
) const;
111 /// @throws css::uno::RuntimeException
112 /// @throws css::beans::UnknownPropertyException
113 void getPropertyValue( const OUString
&rName
,
114 const SfxItemSet
& rSet
,
115 css::uno::Any
& rAny
) const;
116 /// @throws css::uno::RuntimeException
117 /// @throws css::beans::UnknownPropertyException
119 getPropertyValue( const OUString
&rName
,
120 const SfxItemSet
& rSet
) const;
121 /// @throws css::uno::RuntimeException
122 /// @throws css::lang::IllegalArgumentException
123 void setPropertyValue( const SfxItemPropertyMapEntry
& rEntry
,
124 const css::uno::Any
& aVal
,
125 SfxItemSet
& rSet
) const;
126 /// @throws css::uno::RuntimeException
127 /// @throws css::lang::IllegalArgumentException
128 /// @throws css::beans::UnknownPropertyException
129 void setPropertyValue( const OUString
& rPropertyName
,
130 const css::uno::Any
& aVal
,
131 SfxItemSet
& rSet
) const;
133 /// @throws css::beans::UnknownPropertyException
134 css::beans::PropertyState
135 getPropertyState(const OUString
& rName
, const SfxItemSet
& rSet
)const;
136 css::beans::PropertyState
137 getPropertyState(const SfxItemPropertyMapEntry
& rEntry
, const SfxItemSet
& rSet
) const
140 css::uno::Reference
<css::beans::XPropertySetInfo
> const &
141 getPropertySetInfo() const;
142 const SfxItemPropertyMap
& getPropertyMap() const {return m_aMap
;}
145 // workaround for incremental linking bugs in MSVC2015
146 class SAL_DLLPUBLIC_TEMPLATE SfxItemPropertySetInfo_Base
: public cppu::WeakImplHelper
< css::beans::XPropertySetInfo
> {};
148 class SVL_DLLPUBLIC SfxItemPropertySetInfo final
: public SfxItemPropertySetInfo_Base
150 SfxItemPropertyMap m_aOwnMap
;
153 SfxItemPropertySetInfo(const SfxItemPropertyMap
&rMap
);
154 SfxItemPropertySetInfo(o3tl::span
<const SfxItemPropertyMapEntry
> pEntries
);
155 virtual ~SfxItemPropertySetInfo() override
;
157 virtual css::uno::Sequence
< css::beans::Property
> SAL_CALL
158 getProperties( ) override
;
160 virtual css::beans::Property SAL_CALL
161 getPropertyByName( const OUString
& aName
) override
;
163 virtual sal_Bool SAL_CALL
164 hasPropertyByName( const OUString
& Name
) override
;
168 struct SfxItemPropertyMapCompare2
170 bool operator() ( const SfxItemPropertyMapEntry
& lhs
, const SfxItemPropertyMapEntry
& rhs
) const
172 return lhs
.aName
< rhs
.aName
;
176 // workaround for incremental linking bugs in MSVC2015
177 class SAL_DLLPUBLIC_TEMPLATE SfxExtItemPropertySetInfo_Base
: public cppu::WeakImplHelper
< css::beans::XPropertySetInfo
> {};
179 class SVL_DLLPUBLIC SfxExtItemPropertySetInfo final
: public SfxExtItemPropertySetInfo_Base
182 SfxExtItemPropertySetInfo(
183 o3tl::span
<const SfxItemPropertyMapEntry
> pMap
,
184 const css::uno::Sequence
<css::beans::Property
>& rPropSeq
);
185 virtual ~SfxExtItemPropertySetInfo() override
;
187 virtual css::uno::Sequence
< css::beans::Property
> SAL_CALL
188 getProperties( ) override
;
190 virtual css::beans::Property SAL_CALL
191 getPropertyByName( const OUString
& aName
) override
;
193 virtual sal_Bool SAL_CALL
194 hasPropertyByName( const OUString
& Name
) override
;
197 const SfxItemPropertyMapEntry
* getByName( std::u16string_view rName
) const;
198 o3tl::sorted_vector
< SfxItemPropertyMapEntry
, SfxItemPropertyMapCompare2
> maMap
;
199 mutable css::uno::Sequence
< css::beans::Property
> m_aPropSeq
;
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */