sc: filter: rtf: add method "AddFont"
[LibreOffice.git] / include / svl / itempool.hxx
blob8d1f2324363badae78a21468406319cd79b85e30
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 #pragma once
22 #include <rtl/ref.hxx>
23 #include <svl/poolitem.hxx>
24 #include <svl/svldllapi.h>
25 #include <svl/typedwhich.hxx>
26 #include <svl/whichranges.hxx>
27 #include <memory>
28 #include <vector>
29 #include <o3tl/sorted_vector.hxx>
30 #include <salhelper/simplereferenceobject.hxx>
32 class SfxBroadcaster;
33 struct SfxItemPool_Impl;
35 struct SfxItemInfo
37 sal_uInt16 _nSID;
38 bool _bPoolable;
41 class SfxItemPool;
43 /** Base class for providers of defaults of SfxPoolItems.
45 * The derived classes hold the concrete (const) instances which are referenced in several places
46 * (usually within a single document).
47 * This helps to lower the amount of calls to lifecycle methods, speeds up comparisons within a document
48 * and facilitates loading and saving of attributes.
50 class SVL_DLLPUBLIC SfxItemPool : public salhelper::SimpleReferenceObject
52 friend struct SfxItemPool_Impl;
53 friend class SfxItemSet;
54 friend class SfxAllItemSet;
56 const SfxItemInfo* pItemInfos;
57 std::unique_ptr<SfxItemPool_Impl> pImpl;
59 private:
60 sal_uInt16 GetIndex_Impl(sal_uInt16 nWhich) const;
61 sal_uInt16 GetSize_Impl() const;
63 SVL_DLLPRIVATE bool IsItemPoolable_Impl( sal_uInt16 nWhich ) const;
65 public:
66 // for default SfxItemSet::CTOR, set default WhichRanges
67 void FillItemIdRanges_Impl( WhichRangesContainer& pWhichRanges ) const;
68 const WhichRangesContainer & GetFrozenIdRanges() const;
70 protected:
71 static inline void ClearRefCount(SfxPoolItem& rItem);
72 static inline void AddRef(const SfxPoolItem& rItem);
73 static inline sal_uInt32 ReleaseRef(const SfxPoolItem& rItem, sal_uInt32 n = 1);
75 public:
76 SfxItemPool( const SfxItemPool &rPool,
77 bool bCloneStaticDefaults = false );
78 SfxItemPool( const OUString &rName,
79 sal_uInt16 nStart, sal_uInt16 nEnd,
80 const SfxItemInfo *pItemInfos,
81 std::vector<SfxPoolItem*> *pDefaults = nullptr );
83 public:
84 virtual ~SfxItemPool();
86 SfxBroadcaster& BC();
88 void SetPoolDefaultItem( const SfxPoolItem& );
90 const SfxPoolItem* GetPoolDefaultItem( sal_uInt16 nWhich ) const;
91 template<class T> const T* GetPoolDefaultItem( TypedWhichId<T> nWhich ) const
92 { return static_cast<const T*>(GetPoolDefaultItem(sal_uInt16(nWhich))); }
94 void ResetPoolDefaultItem( sal_uInt16 nWhich );
96 void SetDefaults(std::vector<SfxPoolItem*>* pDefaults);
97 void ClearDefaults();
98 void ReleaseDefaults( bool bDelete = false );
99 static void ReleaseDefaults( std::vector<SfxPoolItem*> *pDefaults, bool bDelete = false );
101 virtual MapUnit GetMetric( sal_uInt16 nWhich ) const;
102 void SetDefaultMetric( MapUnit eNewMetric );
103 MapUnit GetDefaultMetric() const;
105 /** Request string representation of pool items.
107 This virtual function produces a string representation
108 from the respective SfxItemPool subclass' known SfxPoolItems.
110 Subclasses, please override this method, and handle
111 SfxPoolItems that don't return useful/complete information on
112 SfxPoolItem::GetPresentation()
114 This baseclass yields the unmodified string representation of
115 rItem.
117 @param[in] rItem
118 SfxPoolItem to query the string representation of
120 @param[in] ePresent
121 requested kind of representation - see SfxItemPresentation
123 @param[in] eMetric
124 requested unit of measure of the representation
126 @param[out] rText
127 string representation of 'rItem'
129 @return true if it has a valid string representation
131 virtual bool GetPresentation( const SfxPoolItem& rItem,
132 MapUnit ePresentationMetric,
133 OUString& rText,
134 const IntlWrapper& rIntlWrapper ) const;
135 virtual rtl::Reference<SfxItemPool> Clone() const;
136 const OUString& GetName() const;
138 template<class T> const T& Put( std::unique_ptr<T> xItem, sal_uInt16 nWhich = 0 )
139 { return static_cast<const T&>(PutImpl( *xItem.release(), nWhich, /*bPassingOwnership*/true)); }
140 template<class T> const T& Put( const T& rItem, sal_uInt16 nWhich = 0 )
141 { return static_cast<const T&>(PutImpl( rItem, nWhich, /*bPassingOwnership*/false)); }
142 void Remove( const SfxPoolItem& );
144 const SfxPoolItem& GetDefaultItem( sal_uInt16 nWhich ) const;
145 template<class T> const T& GetDefaultItem( TypedWhichId<T> nWhich ) const
146 { return static_cast<const T&>(GetDefaultItem(sal_uInt16(nWhich))); }
148 bool CheckItemInPool(const SfxPoolItem *) const;
150 struct Item2Range
152 o3tl::sorted_vector<SfxPoolItem*>::const_iterator m_begin;
153 o3tl::sorted_vector<SfxPoolItem*>::const_iterator m_end;
154 o3tl::sorted_vector<SfxPoolItem*>::const_iterator const & begin() const { return m_begin; }
155 o3tl::sorted_vector<SfxPoolItem*>::const_iterator const & end() const { return m_end; }
157 const SfxPoolItem * GetItem2Default(sal_uInt16 nWhich) const;
158 template<class T> const T* GetItem2Default( TypedWhichId<T> nWhich ) const
159 { return static_cast<const T*>(GetItem2Default(sal_uInt16(nWhich))); }
161 sal_uInt32 GetItemCount2(sal_uInt16 nWhich) const;
162 Item2Range GetItemSurrogates(sal_uInt16 nWhich) const;
164 This is only valid for SfxPoolItem that override IsSortable and operator<.
165 Returns a range of items defined by using operator<.
166 @param rNeedle must be the same type or a supertype of the pool items for nWhich.
168 std::vector<const SfxPoolItem*> FindItemSurrogate(sal_uInt16 nWhich, SfxPoolItem const & rNeedle) const;
170 sal_uInt16 GetFirstWhich() const;
171 sal_uInt16 GetLastWhich() const;
172 bool IsInRange( sal_uInt16 nWhich ) const;
173 void SetSecondaryPool( SfxItemPool *pPool );
174 SfxItemPool* GetSecondaryPool() const;
175 /* get the last pool by following the GetSecondaryPool chain */
176 SfxItemPool* GetLastPoolInChain();
177 SfxItemPool* GetMasterPool() const;
178 void FreezeIdRanges();
180 void Delete();
182 bool IsItemPoolable( sal_uInt16 nWhich ) const;
183 bool IsItemPoolable( const SfxPoolItem &rItem ) const
184 { return IsItemPoolable( rItem.Which() ); }
185 void SetItemInfos( const SfxItemInfo *pInfos );
186 sal_uInt16 GetWhich( sal_uInt16 nSlot, bool bDeep = true ) const;
187 sal_uInt16 GetSlotId( sal_uInt16 nWhich ) const;
188 sal_uInt16 GetTrueWhich( sal_uInt16 nSlot, bool bDeep = true ) const;
189 sal_uInt16 GetTrueSlotId( sal_uInt16 nWhich ) const;
191 static bool IsWhich(sal_uInt16 nId) {
192 return nId && nId <= SFX_WHICH_MAX; }
193 static bool IsSlot(sal_uInt16 nId) {
194 return nId && nId > SFX_WHICH_MAX; }
196 void dumpAsXml(xmlTextWriterPtr pWriter) const;
198 protected:
199 virtual const SfxPoolItem& PutImpl( const SfxPoolItem&, sal_uInt16 nWhich = 0, bool bPassingOwnership = false );
200 private:
201 const SfxItemPool& operator=(const SfxItemPool &) = delete;
203 //IDs below or equal are Which IDs, IDs above slot IDs
204 static const sal_uInt16 SFX_WHICH_MAX = 4999;
207 // only the pool may manipulate the reference counts
208 inline void SfxItemPool::ClearRefCount(SfxPoolItem& rItem)
210 rItem.SetRefCount(0);
213 // only the pool may manipulate the reference counts
214 inline void SfxItemPool::AddRef(const SfxPoolItem& rItem)
216 rItem.AddRef();
219 // only the pool may manipulate the reference counts
220 inline sal_uInt32 SfxItemPool::ReleaseRef(const SfxPoolItem& rItem, sal_uInt32 n)
222 return rItem.ReleaseRef(n);
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */