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 <com/sun/star/lang/IllegalArgumentException.hpp>
25 #include <comphelper/propertysetinfo.hxx>
26 #include <cppuhelper/implbase.hxx>
27 #include <svl/itemset.hxx>
28 #include <svl/svldllapi.h>
32 /// map a property between beans::XPropertySet and SfxPoolItem
33 struct SfxItemPropertyMapEntry
35 OUString aName
; ///< name of property
36 sal_uInt16 nWID
; ///< WhichId of SfxPoolItem
37 css::uno::Type aType
; ///< UNO type of property
38 /// flag bitmap, @see css::beans::PropertyAttribute
40 /// "member ID" to tell QueryValue/PutValue which property it is
41 /// (when multiple properties map to the same nWID)
43 PropertyMoreFlags nMoreFlags
;
45 SfxItemPropertyMapEntry(OUString _aName
, sal_uInt16 _nWID
, css::uno::Type
const & _rType
,
46 sal_Int16 _nFlags
, sal_uInt8
const _nMemberId
, PropertyMoreFlags _nMoreFlags
= PropertyMoreFlags::NONE
)
51 , nMemberId( _nMemberId
)
52 , nMoreFlags( _nMoreFlags
)
54 assert(_nFlags
<= 0x1ff );
55 assert( (_nMemberId
& 0x40) == 0 );
56 // Verify that if METRIC_ITEM is set, we are one of the types supported by
58 assert(!(_nMoreFlags
& PropertyMoreFlags::METRIC_ITEM
) ||
59 ( (aType
.getTypeClass() == css::uno::TypeClass_BYTE
)
60 || (aType
.getTypeClass() == css::uno::TypeClass_SHORT
)
61 || (aType
.getTypeClass() == css::uno::TypeClass_UNSIGNED_SHORT
)
62 || (aType
.getTypeClass() == css::uno::TypeClass_LONG
)
63 || (aType
.getTypeClass() == css::uno::TypeClass_UNSIGNED_LONG
)
68 struct SfxItemPropertySimpleEntry
72 /// flag bitmap, @see css::beans::PropertyAttribute
75 PropertyMoreFlags nMoreFlags
= PropertyMoreFlags::NONE
;
77 SfxItemPropertySimpleEntry()
84 SfxItemPropertySimpleEntry(sal_uInt16 _nWID
, css::uno::Type
const & _rType
,
91 assert(_nFlags
<= 0x1ff );
94 SfxItemPropertySimpleEntry( const SfxItemPropertyMapEntry
* pMapEntry
)
95 : nWID( pMapEntry
->nWID
)
96 , aType( pMapEntry
->aType
)
97 , nFlags( pMapEntry
->nFlags
)
98 , nMemberId( pMapEntry
->nMemberId
)
99 , nMoreFlags( pMapEntry
->nMoreFlags
)
104 struct SfxItemPropertyNamedEntry
: public SfxItemPropertySimpleEntry
107 SfxItemPropertyNamedEntry( const OUString
& rName
, const SfxItemPropertySimpleEntry
& rSimpleEntry
)
108 : SfxItemPropertySimpleEntry( rSimpleEntry
)
114 typedef std::vector
< SfxItemPropertyNamedEntry
> PropertyEntryVector_t
;
115 class SfxItemPropertyMap_Impl
;
116 class SVL_DLLPUBLIC SfxItemPropertyMap
118 std::unique_ptr
<SfxItemPropertyMap_Impl
> m_pImpl
;
120 SfxItemPropertyMap( const SfxItemPropertyMapEntry
* pEntries
);
121 SfxItemPropertyMap( const SfxItemPropertyMap
& rSource
);
122 ~SfxItemPropertyMap();
124 const SfxItemPropertySimpleEntry
* getByName( const OUString
&rName
) const;
125 css::uno::Sequence
< css::beans::Property
> const & getProperties() const;
126 /// @throws css::beans::UnknownPropertyException
127 css::beans::Property
getPropertyByName( const OUString
& rName
) const;
128 bool hasPropertyByName( const OUString
& rName
) const;
130 void mergeProperties( const css::uno::Sequence
< css::beans::Property
>& rPropSeq
);
131 PropertyEntryVector_t
getPropertyEntries() const;
132 sal_uInt32
getSize() const;
136 class SVL_DLLPUBLIC SfxItemPropertySet final
138 SfxItemPropertyMap m_aMap
;
139 mutable css::uno::Reference
<css::beans::XPropertySetInfo
> m_xInfo
;
142 SfxItemPropertySet( const SfxItemPropertyMapEntry
*pMap
) :
144 ~SfxItemPropertySet();
146 /// @throws css::uno::RuntimeException
147 void getPropertyValue( const SfxItemPropertySimpleEntry
& rEntry
,
148 const SfxItemSet
& rSet
,
149 css::uno::Any
& rAny
) const;
150 /// @throws css::uno::RuntimeException
151 /// @throws css::beans::UnknownPropertyException
152 void getPropertyValue( const OUString
&rName
,
153 const SfxItemSet
& rSet
,
154 css::uno::Any
& rAny
) const;
155 /// @throws css::uno::RuntimeException
156 /// @throws css::beans::UnknownPropertyException
158 getPropertyValue( const OUString
&rName
,
159 const SfxItemSet
& rSet
) const;
160 /// @throws css::uno::RuntimeException
161 /// @throws css::lang::IllegalArgumentException
162 void setPropertyValue( const SfxItemPropertySimpleEntry
& rEntry
,
163 const css::uno::Any
& aVal
,
164 SfxItemSet
& rSet
) const;
165 /// @throws css::uno::RuntimeException
166 /// @throws css::lang::IllegalArgumentException
167 /// @throws css::beans::UnknownPropertyException
168 void setPropertyValue( const OUString
& rPropertyName
,
169 const css::uno::Any
& aVal
,
170 SfxItemSet
& rSet
) const;
172 /// @throws css::beans::UnknownPropertyException
173 css::beans::PropertyState
174 getPropertyState(const OUString
& rName
, const SfxItemSet
& rSet
)const;
175 css::beans::PropertyState
176 getPropertyState(const SfxItemPropertySimpleEntry
& rEntry
, const SfxItemSet
& rSet
) const
179 css::uno::Reference
<css::beans::XPropertySetInfo
> const &
180 getPropertySetInfo() const;
181 const SfxItemPropertyMap
& getPropertyMap() const {return m_aMap
;}
184 // workaround for incremental linking bugs in MSVC2015
185 class SAL_DLLPUBLIC_TEMPLATE SfxItemPropertySetInfo_Base
: public cppu::WeakImplHelper
< css::beans::XPropertySetInfo
> {};
187 class SVL_DLLPUBLIC SfxItemPropertySetInfo
: public SfxItemPropertySetInfo_Base
189 SfxItemPropertyMap m_aOwnMap
;
192 SfxItemPropertySetInfo(const SfxItemPropertyMap
&rMap
);
193 SfxItemPropertySetInfo(const SfxItemPropertyMapEntry
*pEntries
);
194 virtual ~SfxItemPropertySetInfo() override
;
196 virtual css::uno::Sequence
< css::beans::Property
> SAL_CALL
197 getProperties( ) override
;
199 virtual css::beans::Property SAL_CALL
200 getPropertyByName( const OUString
& aName
) override
;
202 virtual sal_Bool SAL_CALL
203 hasPropertyByName( const OUString
& Name
) override
;
207 // workaround for incremental linking bugs in MSVC2015
208 class SAL_DLLPUBLIC_TEMPLATE SfxExtItemPropertySetInfo_Base
: public cppu::WeakImplHelper
< css::beans::XPropertySetInfo
> {};
210 class SVL_DLLPUBLIC SfxExtItemPropertySetInfo
: public SfxExtItemPropertySetInfo_Base
212 SfxItemPropertyMap aExtMap
;
214 SfxExtItemPropertySetInfo(
215 const SfxItemPropertyMapEntry
*pMap
,
216 const css::uno::Sequence
<css::beans::Property
>& rPropSeq
);
217 virtual ~SfxExtItemPropertySetInfo() override
;
219 virtual css::uno::Sequence
< css::beans::Property
> SAL_CALL
220 getProperties( ) override
;
222 virtual css::beans::Property SAL_CALL
223 getPropertyByName( const OUString
& aName
) override
;
225 virtual sal_Bool SAL_CALL
226 hasPropertyByName( const OUString
& Name
) override
;
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */