resolves: tdf#162337 Initial selection of tracked change when Manage
[LibreOffice.git] / include / svl / itemprop.hxx
blobddd636272ea4e140a9dc35eca0008870f93e348b
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 .
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 <span>
30 #include <string_view>
31 #include <utility>
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
43 sal_Int16 nFlags;
44 /// "member ID" to tell QueryValue/PutValue which property it is
45 /// (when multiple properties map to the same nWID)
46 sal_uInt8 nMemberId;
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 ))
52 , aType( _rType )
53 , nWID( _nWID )
54 , nFlags( _nFlags )
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
61 // SvxUnoConvertToMM.
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)
68 ) );
72 class SVL_DLLPUBLIC SfxItemPropertyMap
74 public:
75 SfxItemPropertyMap( std::span<const SfxItemPropertyMapEntry> pEntries );
76 SfxItemPropertyMap( const SfxItemPropertyMap& rSource );
77 ~SfxItemPropertyMap();
79 const SfxItemPropertyMapEntry* getByName( const OUString & rName ) const;
80 css::uno::Sequence< css::beans::Property > const & getProperties() const;
81 /// @throws css::beans::UnknownPropertyException
82 css::beans::Property getPropertyByName( const OUString & rName ) const;
83 bool hasPropertyByName( const OUString & rName ) const;
85 const std::unordered_map< OUString, const SfxItemPropertyMapEntry* >& getPropertyEntries() const { return m_aMap; }
86 private:
87 std::unordered_map< OUString, const SfxItemPropertyMapEntry* > m_aMap;
88 mutable css::uno::Sequence< css::beans::Property > m_aPropSeq;
91 class SVL_DLLPUBLIC SfxItemPropertySet final
93 SfxItemPropertyMap m_aMap;
94 mutable css::uno::Reference<css::beans::XPropertySetInfo> m_xInfo;
96 public:
97 SfxItemPropertySet( std::span<const SfxItemPropertyMapEntry> pMap ) :
98 m_aMap(pMap) {}
99 ~SfxItemPropertySet();
101 /// @throws css::uno::RuntimeException
102 static void getPropertyValue( const SfxItemPropertyMapEntry& rEntry,
103 const SfxItemSet& rSet,
104 css::uno::Any& rAny);
105 /// @throws css::uno::RuntimeException
106 /// @throws css::beans::UnknownPropertyException
107 void getPropertyValue( const OUString &rName,
108 const SfxItemSet& rSet,
109 css::uno::Any& rAny) const;
110 /// @throws css::uno::RuntimeException
111 /// @throws css::beans::UnknownPropertyException
112 css::uno::Any
113 getPropertyValue( const OUString &rName,
114 const SfxItemSet& rSet ) const;
115 /// @throws css::uno::RuntimeException
116 /// @throws css::lang::IllegalArgumentException
117 static void setPropertyValue( const SfxItemPropertyMapEntry& rEntry,
118 const css::uno::Any& aVal,
119 SfxItemSet& rSet );
120 /// @throws css::uno::RuntimeException
121 /// @throws css::lang::IllegalArgumentException
122 /// @throws css::beans::UnknownPropertyException
123 void setPropertyValue( const OUString& rPropertyName,
124 const css::uno::Any& aVal,
125 SfxItemSet& rSet ) const;
127 /// @throws css::beans::UnknownPropertyException
128 css::beans::PropertyState
129 getPropertyState(const OUString& rName, const SfxItemSet& rSet)const;
130 static css::beans::PropertyState
131 getPropertyState(const SfxItemPropertyMapEntry& rEntry, const SfxItemSet& rSet)
132 noexcept;
134 css::uno::Reference<css::beans::XPropertySetInfo> const &
135 getPropertySetInfo() const;
136 const SfxItemPropertyMap& getPropertyMap() const {return m_aMap;}
139 // workaround for incremental linking bugs in MSVC2015
140 class SAL_DLLPUBLIC_TEMPLATE SfxItemPropertySetInfo_Base : public cppu::WeakImplHelper< css::beans::XPropertySetInfo > {};
142 class SVL_DLLPUBLIC SfxItemPropertySetInfo final : public SfxItemPropertySetInfo_Base
144 SfxItemPropertyMap m_aOwnMap;
146 public:
147 SfxItemPropertySetInfo(const SfxItemPropertyMap &rMap );
148 SfxItemPropertySetInfo(std::span<const SfxItemPropertyMapEntry> pEntries );
149 virtual ~SfxItemPropertySetInfo() override;
151 virtual css::uno::Sequence< css::beans::Property > SAL_CALL
152 getProperties( ) override;
154 virtual css::beans::Property SAL_CALL
155 getPropertyByName( const OUString& aName ) override;
157 virtual sal_Bool SAL_CALL
158 hasPropertyByName( const OUString& Name ) override;
162 struct SfxItemPropertyMapCompare2
164 bool operator() ( const SfxItemPropertyMapEntry & lhs, const SfxItemPropertyMapEntry & rhs ) const
166 return lhs.aName < rhs.aName;
170 // workaround for incremental linking bugs in MSVC2015
171 class SAL_DLLPUBLIC_TEMPLATE SfxExtItemPropertySetInfo_Base : public cppu::WeakImplHelper< css::beans::XPropertySetInfo > {};
173 class SVL_DLLPUBLIC SfxExtItemPropertySetInfo final : public SfxExtItemPropertySetInfo_Base
175 public:
176 SfxExtItemPropertySetInfo(
177 std::span<const SfxItemPropertyMapEntry> pMap,
178 const css::uno::Sequence<css::beans::Property>& rPropSeq );
179 virtual ~SfxExtItemPropertySetInfo() override;
181 virtual css::uno::Sequence< css::beans::Property > SAL_CALL
182 getProperties( ) override;
184 virtual css::beans::Property SAL_CALL
185 getPropertyByName( const OUString& aName ) override;
187 virtual sal_Bool SAL_CALL
188 hasPropertyByName( const OUString& Name ) override;
190 private:
191 const SfxItemPropertyMapEntry* getByName( std::u16string_view rName ) const;
192 o3tl::sorted_vector< SfxItemPropertyMapEntry, SfxItemPropertyMapCompare2 > maMap;
193 mutable css::uno::Sequence< css::beans::Property > m_aPropSeq;
196 #endif
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */