nss: upgrade to release 3.73
[LibreOffice.git] / include / svl / poolitem.hxx
blobce4ebeaef6798f4cf1e2a01985acf50fe08cb71a
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_SVL_POOLITEM_HXX
21 #define INCLUDED_SVL_POOLITEM_HXX
23 #include <sal/config.h>
25 #include <memory>
27 #include <com/sun/star/uno/Any.hxx>
28 #include <svl/hint.hxx>
29 #include <svl/svldllapi.h>
30 #include <svl/typedwhich.hxx>
31 #include <tools/mapunit.hxx>
32 #include <tools/long.hxx>
33 #include <boost/property_tree/ptree_fwd.hpp>
35 class IntlWrapper;
37 enum class SfxItemKind : sal_Int8
39 NONE,
40 DeleteOnIdle,
41 StaticDefault,
42 PoolDefault
45 #define SFX_ITEMS_OLD_MAXREF 0xffef
46 #define SFX_ITEMS_MAXREF 0xfffffffe
47 #define SFX_ITEMS_SPECIAL 0xffffffff
49 #define CONVERT_TWIPS 0x80 // Uno conversion for measurement (for MemberId)
51 // warning, if there is no boolean inside the any this will always return the value false
52 inline bool Any2Bool( const css::uno::Any&rValue )
54 bool bValue = false;
55 if( !(rValue >>= bValue) )
57 sal_Int32 nNum = 0;
58 if( rValue >>= nNum )
59 bValue = nNum != 0;
62 return bValue;
66 * The values of this enum describe the degree of textual
67 * representation of an item after calling the virtual
68 * method <SfxPoolItem::GetPresentation()const>.
70 enum class SfxItemPresentation
72 Nameless,
73 Complete
76 /**
77 * These values have to match the values in the
78 * css::frame::status::ItemState IDL
79 * to be found at offapi/com/sun/star/frame/status/ItemState.idl
81 enum class SfxItemState {
83 /** Specifies an unknown state. */
84 UNKNOWN = 0,
86 /** Specifies that the property is currently disabled. */
87 DISABLED = 0x0001,
89 /** Specifies that the property is currently read-only. */
90 READONLY = 0x0002,
92 /** Specifies that the property is currently in a don't care state.
93 * <br/>
94 * This is normally used if a selection provides more than one state
95 * for a property at the same time.
97 DONTCARE = 0x0010,
99 /** Specifies that the property is currently in a default state. */
100 DEFAULT = 0x0020,
102 /** The property has been explicitly set to a given value hence we know
103 * we are not taking the default value.
104 * <br/>
105 * For example, you may want to get the font color and it might either
106 * be the default one or one that has been explicitly set.
108 SET = 0x0040
111 #define INVALID_POOL_ITEM reinterpret_cast<SfxPoolItem*>(-1)
113 class SfxItemPool;
114 class SfxItemSet;
115 typedef struct _xmlTextWriter* xmlTextWriterPtr;
117 class SVL_DLLPUBLIC SfxPoolItem
119 friend class SfxItemPool;
120 friend class SfxItemDisruptor_Impl;
121 friend class SfxItemPoolCache;
122 friend class SfxItemSet;
123 friend class SfxVoidItem;
125 mutable sal_uInt32 m_nRefCount;
126 sal_uInt16 m_nWhich;
127 SfxItemKind m_nKind;
129 private:
130 inline void SetRefCount(sal_uInt32 n);
131 inline void SetKind( SfxItemKind n );
132 public:
133 inline void AddRef(sal_uInt32 n = 1) const;
134 private:
135 inline sal_uInt32 ReleaseRef(sal_uInt32 n = 1) const;
137 protected:
138 explicit SfxPoolItem( sal_uInt16 nWhich = 0 );
139 SfxPoolItem( const SfxPoolItem& rCopy)
140 : SfxPoolItem(rCopy.m_nWhich) {}
142 public:
143 virtual ~SfxPoolItem();
145 void SetWhich( sal_uInt16 nId )
147 // can only change the Which before we are in a set
148 assert(m_nRefCount==0);
149 m_nWhich = nId;
151 sal_uInt16 Which() const { return m_nWhich; }
152 virtual bool operator==( const SfxPoolItem& ) const = 0;
153 bool operator!=( const SfxPoolItem& rItem ) const
154 { return !(*this == rItem); }
156 // Sorting is only used for faster searching in a pool which contains large quantities
157 // of a single kind of pool item.
158 virtual bool operator<( const SfxPoolItem& ) const { assert(false); return false; }
159 virtual bool IsSortable() const { return false; }
161 /** @return true if it has a valid string representation */
162 virtual bool GetPresentation( SfxItemPresentation ePresentation,
163 MapUnit eCoreMetric,
164 MapUnit ePresentationMetric,
165 OUString &rText,
166 const IntlWrapper& rIntlWrapper ) const;
168 virtual void ScaleMetrics( tools::Long lMult, tools::Long lDiv );
169 virtual bool HasMetrics() const;
171 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const;
172 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId );
174 virtual SfxPoolItem* Clone( SfxItemPool *pPool = nullptr ) const = 0;
175 // clone and call SetWhich
176 std::unique_ptr<SfxPoolItem> CloneSetWhich( sal_uInt16 nNewWhich ) const;
177 template<class T> std::unique_ptr<T> CloneSetWhich( TypedWhichId<T> nId ) const
179 return std::unique_ptr<T>(static_cast<T*>(CloneSetWhich(sal_uInt16(nId)).release()));
182 sal_uInt32 GetRefCount() const { return m_nRefCount; }
183 SfxItemKind GetKind() const { return m_nKind; }
184 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
185 virtual boost::property_tree::ptree dumpAsJSON() const;
187 /** Only SfxVoidItem shall and must return true for this.
189 This avoids costly calls to dynamic_cast<const SfxVoidItem*>()
190 specifically in SfxItemSet::GetItemState()
192 virtual bool IsVoidItem() const;
194 private:
195 SfxPoolItem& operator=( const SfxPoolItem& ) = delete;
198 inline void SfxPoolItem::SetRefCount(sal_uInt32 n)
200 m_nRefCount = n;
201 m_nKind = SfxItemKind::NONE;
204 inline void SfxPoolItem::SetKind( SfxItemKind n )
206 m_nRefCount = SFX_ITEMS_SPECIAL;
207 m_nKind = n;
210 inline void SfxPoolItem::AddRef(sal_uInt32 n) const
212 assert(m_nRefCount <= SFX_ITEMS_MAXREF && "AddRef with non-Pool-Item");
213 assert(n <= SFX_ITEMS_MAXREF - m_nRefCount && "AddRef: refcount overflow");
214 m_nRefCount += n;
217 inline sal_uInt32 SfxPoolItem::ReleaseRef(sal_uInt32 n) const
219 assert(m_nRefCount <= SFX_ITEMS_MAXREF && "ReleaseRef with non-Pool-Item");
220 assert(n <= m_nRefCount);
221 m_nRefCount -= n;
222 return m_nRefCount;
225 inline bool IsPoolDefaultItem(const SfxPoolItem *pItem )
227 return pItem && pItem->GetKind() == SfxItemKind::PoolDefault;
230 inline bool IsStaticDefaultItem(const SfxPoolItem *pItem )
232 return pItem && pItem->GetKind() == SfxItemKind::StaticDefault;
235 inline bool IsDefaultItem( const SfxPoolItem *pItem )
237 return pItem && (pItem->GetKind() == SfxItemKind::StaticDefault || pItem->GetKind() == SfxItemKind::PoolDefault);
240 inline bool IsPooledItem( const SfxPoolItem *pItem )
242 return pItem && pItem->GetRefCount() > 0 && pItem->GetRefCount() <= SFX_ITEMS_MAXREF;
245 inline bool IsInvalidItem(const SfxPoolItem *pItem)
247 return pItem == INVALID_POOL_ITEM;
250 class SVL_DLLPUBLIC SfxVoidItem final: public SfxPoolItem
252 public:
253 static SfxPoolItem* CreateDefault();
254 explicit SfxVoidItem( sal_uInt16 nWhich );
255 virtual ~SfxVoidItem() override;
257 SfxVoidItem(SfxVoidItem const &) = default;
258 SfxVoidItem(SfxVoidItem &&) = default;
259 SfxVoidItem & operator =(SfxVoidItem const &) = delete; // due to SfxPoolItem
260 SfxVoidItem & operator =(SfxVoidItem &&) = delete; // due to SfxPoolItem
262 virtual bool operator==( const SfxPoolItem& ) const override;
264 virtual bool GetPresentation( SfxItemPresentation ePres,
265 MapUnit eCoreMetric,
266 MapUnit ePresMetric,
267 OUString &rText,
268 const IntlWrapper& ) const override;
269 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
271 // create a copy of itself
272 virtual SfxVoidItem* Clone( SfxItemPool *pPool = nullptr ) const override;
274 /** Always returns true as this is an SfxVoidItem. */
275 virtual bool IsVoidItem() const override;
278 class SVL_DLLPUBLIC SfxSetItem: public SfxPoolItem
280 std::unique_ptr<SfxItemSet> pSet;
282 SfxSetItem & operator=( const SfxSetItem& ) = delete;
284 public:
285 SfxSetItem( sal_uInt16 nWhich, std::unique_ptr<SfxItemSet> &&pSet );
286 SfxSetItem( sal_uInt16 nWhich, const SfxItemSet &rSet );
287 SfxSetItem( const SfxSetItem&, SfxItemPool *pPool = nullptr );
288 virtual ~SfxSetItem() override;
290 virtual bool operator==( const SfxPoolItem& ) const override;
292 virtual bool GetPresentation( SfxItemPresentation ePres,
293 MapUnit eCoreMetric,
294 MapUnit ePresMetric,
295 OUString &rText,
296 const IntlWrapper& ) const override;
298 // create a copy of itself
299 virtual SfxSetItem* Clone( SfxItemPool *pPool = nullptr ) const override = 0;
301 const SfxItemSet& GetItemSet() const
302 { return *pSet; }
303 SfxItemSet& GetItemSet()
304 { return *pSet; }
307 class SVL_DLLPUBLIC SfxPoolItemHint final : public SfxHint
309 SfxPoolItem* pObj;
310 public:
311 explicit SfxPoolItemHint( SfxPoolItem* Object ) : pObj(Object) {}
312 SfxPoolItem* GetObject() const { return pObj; }
315 #endif
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */