update emoji autocorrect entries from po-files
[LibreOffice.git] / include / svl / itempool.hxx
blob39f0b797fa4a3364c0e6bdc720958b32b40f30c7
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_ITEMPOOL_HXX
21 #define INCLUDED_SVL_ITEMPOOL_HXX
23 #include <rtl/string.hxx>
24 #include <svl/poolitem.hxx>
25 #include <svl/svldllapi.h>
26 #include <tools/solar.h>
27 #include <o3tl/typed_flags_set.hxx>
29 class SvStream;
30 class SfxBroadcaster;
31 struct SfxItemPool_Impl;
33 #define SFX_WHICH_MAX 4999
35 enum class SfxItemPoolFlags
37 NONE = 0x00,
38 POOLABLE = 0x01,
39 NOT_POOLABLE = 0x02,
41 namespace o3tl
43 template<> struct typed_flags<SfxItemPoolFlags> : is_typed_flags<SfxItemPoolFlags, 0x03> {};
46 struct SfxItemInfo
48 sal_uInt16 _nSID;
49 SfxItemPoolFlags _nFlags;
52 class SfxStyleSheetIterator;
53 struct SfxPoolItemArray_Impl;
54 class SfxItemPool;
56 class SVL_DLLPUBLIC SfxItemPoolUser
58 public:
59 virtual void ObjectInDestruction(const SfxItemPool& rSfxItemPool) = 0;
61 protected:
62 ~SfxItemPoolUser() {}
65 /** Base class for providers of defaults of SfxPoolItems.
67 * The derived classes hold the concrete (const) instances which are referenced in several places
68 * (usually within a single document).
69 * This helps to lower the amount of calls to lifecycle methods, speeds up comparisons within a document
70 * and facilitates loading and saving of attributes.
72 class SVL_DLLPUBLIC SfxItemPool
74 friend struct SfxItemPool_Impl;
76 const SfxItemInfo* pItemInfos;
77 SfxItemPool_Impl* pImp;
79 public:
80 void AddSfxItemPoolUser(SfxItemPoolUser& rNewUser);
81 void RemoveSfxItemPoolUser(SfxItemPoolUser& rOldUser);
83 private:
84 sal_uInt16 GetIndex_Impl(sal_uInt16 nWhich) const;
85 sal_uInt16 GetSize_Impl() const;
87 SVL_DLLPRIVATE bool IsItemFlag_Impl( sal_uInt16 nWhich, SfxItemPoolFlags nFlag ) const;
89 public:
90 // for default SfxItemSet::CTOR, set default WhichRanges
91 void FillItemIdRanges_Impl( sal_uInt16*& pWhichRanges ) const;
92 const sal_uInt16* GetFrozenIdRanges() const;
94 protected:
95 static inline void SetRefCount( SfxPoolItem& rItem, sal_uLong n );
96 static inline void AddRef( const SfxPoolItem& rItem, sal_uLong n = 1 );
97 static inline sal_uLong ReleaseRef( const SfxPoolItem& rItem, sal_uLong n = 1);
98 static inline void SetKind( SfxPoolItem& rItem, SfxItemKind nRef );
100 public:
101 SfxItemPool( const SfxItemPool &rPool,
102 bool bCloneStaticDefaults = false );
103 SfxItemPool( const OUString &rName,
104 sal_uInt16 nStart, sal_uInt16 nEnd,
105 const SfxItemInfo *pItemInfos,
106 SfxPoolItem **pDefaults = 0,
107 bool bLoadRefCounts = true );
109 protected:
110 virtual ~SfxItemPool();
112 public:
113 static void Free(SfxItemPool* pPool);
115 SfxBroadcaster& BC();
117 void SetPoolDefaultItem( const SfxPoolItem& );
118 const SfxPoolItem* GetPoolDefaultItem( sal_uInt16 nWhich ) const;
119 void ResetPoolDefaultItem( sal_uInt16 nWhich );
121 void SetDefaults( SfxPoolItem **pDefaults );
122 void ReleaseDefaults( bool bDelete = false );
123 static void ReleaseDefaults( SfxPoolItem **pDefaults, sal_uInt16 nCount, bool bDelete = false );
125 virtual SfxMapUnit GetMetric( sal_uInt16 nWhich ) const;
126 void SetDefaultMetric( SfxMapUnit eNewMetric );
128 /** Request string representation of pool items.
130 This virtual function produces a string representation
131 from the respective SfxItemPool subclass' known SfxPoolItems.
133 Subclasses, please override this method, and handle
134 SfxPoolItems that don't return useful/complete information on
135 SfxPoolItem::GetPresentation()
137 This baseclass yields the unmodified string representation of
138 rItem.
140 @param[in] rItem
141 SfxPoolItem to query the string representation of
143 @param[in] ePresent
144 requested kind of representation - see SfxItemPresentation
146 @param[in] eMetric
147 requested unit of measure of the representation
149 @param[out] rText
150 string representation of 'rItem'
152 @return true if it has a valid string representation
154 virtual bool GetPresentation( const SfxPoolItem& rItem,
155 SfxMapUnit ePresentationMetric,
156 OUString& rText,
157 const IntlWrapper * pIntlWrapper = 0 ) const;
158 virtual SfxItemPool* Clone() const;
159 const OUString& GetName() const;
161 virtual const SfxPoolItem& Put( const SfxPoolItem&, sal_uInt16 nWhich = 0 );
162 virtual void Remove( const SfxPoolItem& );
163 const SfxPoolItem& GetDefaultItem( sal_uInt16 nWhich ) const;
165 const SfxPoolItem* LoadItem( SvStream &rStream,
166 bool bDirect = false,
167 const SfxItemPool *pRefPool = 0 );
168 bool StoreItem( SvStream &rStream,
169 const SfxPoolItem &rItem,
170 bool bDirect = false ) const;
172 sal_uInt32 GetSurrogate(const SfxPoolItem *) const;
173 const SfxPoolItem * GetItem2(sal_uInt16 nWhich, sal_uInt32 nSurrogate) const;
174 const SfxPoolItem * GetItem2Default(sal_uInt16 nWhich) const;
175 sal_uInt32 GetItemCount2(sal_uInt16 nWhich) const;
176 const SfxPoolItem* LoadSurrogate(SvStream& rStream,
177 sal_uInt16 &rWhich, sal_uInt16 nSlotId,
178 const SfxItemPool* pRefPool = 0 );
179 bool StoreSurrogate(SvStream& rStream,
180 const SfxPoolItem *pItem ) const;
182 SvStream & Load(SvStream &);
183 virtual SvStream & Store(SvStream &) const;
184 bool HasPersistentRefCounts() const;
185 void LoadCompleted();
187 sal_uInt16 GetFirstWhich() const;
188 sal_uInt16 GetLastWhich() const;
189 bool IsInRange( sal_uInt16 nWhich ) const;
190 bool IsInVersionsRange( sal_uInt16 nWhich ) const;
191 bool IsInStoringRange( sal_uInt16 nWhich ) const;
192 void SetStoringRange( sal_uInt16 nFrom, sal_uInt16 nTo );
193 void SetSecondaryPool( SfxItemPool *pPool );
194 SfxItemPool* GetSecondaryPool() const;
195 SfxItemPool* GetMasterPool() const;
196 void FreezeIdRanges();
198 void Delete();
200 bool IsItemFlag( sal_uInt16 nWhich, SfxItemPoolFlags nFlag ) const;
201 bool IsItemFlag( const SfxPoolItem &rItem, SfxItemPoolFlags nFlag ) const
202 { return IsItemFlag( rItem.Which(), nFlag ); }
203 void SetItemInfos( const SfxItemInfo *pInfos );
204 sal_uInt16 GetWhich( sal_uInt16 nSlot, bool bDeep = true ) const;
205 sal_uInt16 GetSlotId( sal_uInt16 nWhich, bool bDeep = true ) const;
206 sal_uInt16 GetTrueWhich( sal_uInt16 nSlot, bool bDeep = true ) const;
207 sal_uInt16 GetTrueSlotId( sal_uInt16 nWhich, bool bDeep = true ) const;
209 void SetVersionMap( sal_uInt16 nVer,
210 sal_uInt16 nOldStart, sal_uInt16 nOldEnd,
211 const sal_uInt16 *pWhichIdTab );
212 sal_uInt16 GetNewWhich( sal_uInt16 nOldWhich ) const;
213 sal_uInt16 GetVersion() const;
214 void SetFileFormatVersion( sal_uInt16 nFileFormatVersion );
215 bool IsCurrentVersionLoading() const;
217 static bool IsWhich(sal_uInt16 nId) {
218 return nId && nId <= SFX_WHICH_MAX; }
219 static bool IsSlot(sal_uInt16 nId) {
220 return nId && nId > SFX_WHICH_MAX; }
222 static const SfxItemPool* GetStoringPool();
224 private:
225 const SfxItemPool& operator=(const SfxItemPool &) SAL_DELETED_FUNCTION;
227 static const SfxItemPool* pStoringPool_;
230 // only the pool may manipulate the reference counts
231 inline void SfxItemPool::SetRefCount( SfxPoolItem& rItem, sal_uLong n )
233 rItem.SetRefCount(n);
236 // only the pool may manipulate the reference counts
237 inline void SfxItemPool::AddRef( const SfxPoolItem& rItem, sal_uLong n )
239 rItem.AddRef(n);
242 // only the pool may manipulate the reference counts
243 inline sal_uLong SfxItemPool::ReleaseRef( const SfxPoolItem& rItem, sal_uLong n )
245 return rItem.ReleaseRef(n);
248 inline void SfxItemPool::SetKind( SfxPoolItem& rItem, SfxItemKind nRef )
250 rItem.SetKind( nRef );
253 #endif
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */