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 .
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>
31 struct SfxItemPool_Impl
;
33 #define SFX_WHICH_MAX 4999
35 enum class SfxItemPoolFlags
43 template<> struct typed_flags
<SfxItemPoolFlags
> : is_typed_flags
<SfxItemPoolFlags
, 0x03> {};
49 SfxItemPoolFlags _nFlags
;
52 class SfxStyleSheetIterator
;
53 struct SfxPoolItemArray_Impl
;
56 class SVL_DLLPUBLIC SfxItemPoolUser
59 virtual void ObjectInDestruction(const SfxItemPool
& rSfxItemPool
) = 0;
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
;
80 void AddSfxItemPoolUser(SfxItemPoolUser
& rNewUser
);
81 void RemoveSfxItemPoolUser(SfxItemPoolUser
& rOldUser
);
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;
90 // for default SfxItemSet::CTOR, set default WhichRanges
91 void FillItemIdRanges_Impl( sal_uInt16
*& pWhichRanges
) const;
92 const sal_uInt16
* GetFrozenIdRanges() const;
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
);
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 );
110 virtual ~SfxItemPool();
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
141 SfxPoolItem to query the string representation of
144 requested kind of representation - see SfxItemPresentation
147 requested unit of measure of the representation
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
,
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();
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();
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
)
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
);
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */