sync master with lastest vba changes
[ooovba.git] / binfilter / inc / bf_svtools / itempool.hxx
blobbf1d5a2cac3d228af69fdac59b7a1343c6202ae7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: itempool.hxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _SFXITEMPOOL_HXX
32 #define _SFXITEMPOOL_HXX
34 #ifndef INCLUDED_LIMITS_H
35 #include <limits.h>
36 #define INCLUDED_LIMITS_H
37 #endif
39 #ifndef _SOLAR_H
40 #include <tools/solar.h>
41 #endif
43 #ifndef _STRING_HXX
44 #include <tools/string.hxx>
45 #endif
47 #ifndef _SVARRAY_HXX
48 #include <bf_svtools/svarray.hxx>
49 #endif
51 #ifndef _SFXPOOLITEM_HXX
52 #include <bf_svtools/poolitem.hxx>
53 #endif
55 class SvStream;
57 namespace binfilter
60 class SfxBroadcaster;
61 struct SfxItemPool_Impl;
63 #define SFX_WHICH_MAX 4999
65 DBG_NAMEEX(SfxItemPool)
67 //====================================================================
69 #define SFX_ITEM_POOLABLE 0x0001
70 #define SFX_ITEM_NOT_POOLABLE 0x0002
72 #define SFX_ITEM_USERFLAG0 0x0100
73 #define SFX_ITEM_USERFLAG1 0x0200
74 #define SFX_ITEM_USERFLAG2 0x0400
75 #define SFX_ITEM_USERFLAG3 0x0800
76 #define SFX_ITEM_USERFLAG4 0x1000
77 #define SFX_ITEM_USERFLAG5 0x2000
78 #define SFX_ITEM_USERFLAG6 0x4000
79 #define SFX_ITEM_USERFLAG7 0x8000
80 #define SFX_ITEM_USERFLAG8 0x0010
81 #define SFX_ITEM_USERFLAG9 0x0020
82 #define SFX_ITEM_USERFLAGA 0x0040
83 #define SFX_ITEM_USERFLAGB 0x0080
85 //====================================================================
87 struct SfxItemInfo
89 USHORT _nSID;
90 USHORT _nFlags;
93 //====================================================================
95 class SfxStyleSheetIterator;
96 struct SfxPoolItemArray_Impl;
98 class SfxItemPool
100 /* [Beschreibung]
102 Die von dieser Klasse abgeleiteten Klassen dienen der Bereitstellung von
103 Defaults von SfxPoolItems und halten konkrete (konstante) Instanzen, die
104 dann von mehreren Stellen (i.d.R. eines Dokuments) referenziert werden
105 k�nnen.
107 Dadurch ist jeder Wert nur einmalig gespeichert, was zu wenig Konstruktor
108 und Destruktor-Aufrufen f�hrt, Vergleiche zwischen Items eines Dokuments
109 beschleunigt und ein einfaches Laden und Speichern von Attributen
110 bereitstellt.
114 void readTheItems(SvStream & rStream, USHORT nCount, USHORT nVersion,
115 SfxPoolItem * pDefItem, SfxPoolItemArray_Impl ** pArr);
117 UniString aName;
118 USHORT nStart, nEnd;
119 USHORT _nFileFormatVersion;
120 #ifdef TF_POOLABLE
121 const SfxItemInfo* pItemInfos;
122 #else
123 USHORT* pSlotIds;
124 #endif
125 SfxItemPool_Impl* pImp;
126 SfxPoolItem** ppStaticDefaults;
127 SfxPoolItem** ppPoolDefaults;
128 SfxItemPool* pSecondary;
129 SfxItemPool* pMaster;
130 USHORT* _pPoolRanges;
131 FASTBOOL bPersistentRefCounts;
133 //---------------------------------------------------------------------
134 #ifndef _SFXITEMS_HXX
136 friend class SfxPoolWhichMap;
138 private:
139 inline USHORT GetIndex_Impl(USHORT nWhich) const;
140 inline USHORT GetSize_Impl() const { return nEnd - nStart + 1; }
142 SvStream& Load1_Impl( SvStream &rStream );
143 FASTBOOL IsItemFlag_Impl( USHORT nWhich, USHORT nFlag ) const;
145 public:
146 // fuer dflt. SfxItemSet::CTOR, setze dflt. WhichRanges
147 void FillItemIdRanges_Impl( USHORT*& pWhichRanges ) const;
148 const USHORT* GetFrozenIdRanges() const
149 { return _pPoolRanges; }
150 FASTBOOL IsVer2_Impl() const;
152 #endif
153 //---------------------------------------------------------------------
155 protected:
156 static inline void SetRefCount( SfxPoolItem& rItem, ULONG n );
157 static inline ULONG AddRef( const SfxPoolItem& rItem, ULONG n = 1 );
158 static inline ULONG ReleaseRef( const SfxPoolItem& rItem, ULONG n = 1);
160 public:
161 SfxItemPool( const SfxItemPool &rPool,
162 BOOL bCloneStaticDefaults = FALSE );
163 SfxItemPool( const UniString &rName,
164 USHORT nStart, USHORT nEnd,
165 #ifdef TF_POOLABLE
166 const SfxItemInfo *pItemInfos,
167 #endif
168 SfxPoolItem **pDefaults = 0,
169 #ifndef TF_POOLABLE
170 USHORT *pSlotIds = 0,
171 #endif
172 FASTBOOL bLoadRefCounts = TRUE );
173 virtual ~SfxItemPool();
175 void SetPoolDefaultItem( const SfxPoolItem& );
176 const SfxPoolItem* GetPoolDefaultItem( USHORT nWhich ) const;
177 void ResetPoolDefaultItem( USHORT nWhich );
179 void SetDefaults( SfxPoolItem **pDefaults );
180 void ReleaseDefaults( BOOL bDelete = FALSE );
181 static void ReleaseDefaults( SfxPoolItem **pDefaults, USHORT nCount, BOOL bDelete = FALSE );
183 virtual SfxMapUnit GetMetric( USHORT nWhich ) const;
184 void SetDefaultMetric( SfxMapUnit eNewMetric );
185 virtual SfxItemPresentation GetPresentation( const SfxPoolItem& rItem,
186 SfxItemPresentation ePresentation,
187 SfxMapUnit ePresentationMetric,
188 XubString& rText,
189 const ::IntlWrapper * pIntlWrapper
190 = 0 ) const;
191 virtual SfxItemPool* Clone() const;
192 UniString const & GetName() const { return aName; }
194 virtual const SfxPoolItem& Put( const SfxPoolItem&, USHORT nWhich = 0 );
195 virtual void Remove( const SfxPoolItem& );
196 virtual const SfxPoolItem& GetDefaultItem( USHORT nWhich ) const;
198 const SfxPoolItem* LoadItem( SvStream &rStream,
199 FASTBOOL bDirect = FALSE,
200 const SfxItemPool *pRefPool = 0 );
201 FASTBOOL StoreItem( SvStream &rStream,
202 const SfxPoolItem &rItem,
203 FASTBOOL bDirect = FALSE ) const;
205 USHORT GetSurrogate(const SfxPoolItem *) const;
206 const SfxPoolItem * GetItem(USHORT nWhich, USHORT nSurrogate) const;
207 USHORT GetItemCount(USHORT nWhich) const;
208 const SfxPoolItem* LoadSurrogate(SvStream& rStream,
209 USHORT &rWhich, USHORT nSlotId,
210 const SfxItemPool* pRefPool = 0 );
211 FASTBOOL StoreSurrogate(SvStream& rStream,
212 const SfxPoolItem *pItem ) const;
214 virtual SvStream & Load(SvStream &);
215 virtual SvStream & Store(SvStream &) const;
216 int HasPersistentRefCounts() const {
217 return bPersistentRefCounts; }
218 void LoadCompleted();
220 USHORT GetFirstWhich() const { return nStart; }
221 USHORT GetLastWhich() const { return nEnd; }
222 FASTBOOL IsInRange( USHORT nWhich ) const {
223 return nWhich >= nStart &&
224 nWhich <= nEnd; }
225 FASTBOOL IsInVersionsRange( USHORT nWhich ) const;
226 FASTBOOL IsInStoringRange( USHORT nWhich ) const;
227 void SetStoringRange( USHORT nFrom, USHORT nTo );
228 void SetSecondaryPool( SfxItemPool *pPool );
229 SfxItemPool* GetSecondaryPool() const {
230 return pSecondary; }
231 SfxItemPool* GetMasterPool() const {
232 return pMaster; }
233 void FreezeIdRanges();
235 void Delete();
237 #ifdef TF_POOLABLE
238 FASTBOOL IsItemFlag( USHORT nWhich, USHORT nFlag ) const;
239 FASTBOOL IsItemFlag( const SfxPoolItem &rItem, USHORT nFlag ) const
240 { return IsItemFlag( rItem.Which(), nFlag ); }
241 void SetItemInfos( const SfxItemInfo *pInfos )
242 { pItemInfos = pInfos; }
243 #else
244 int HasMap() const { return 0 != pSlotIds; }
245 void SetMap( USHORT *pNewSlotIds )
246 { pSlotIds = pNewSlotIds; }
247 #endif
248 USHORT GetWhich( USHORT nSlot, BOOL bDeep = TRUE ) const;
249 USHORT GetSlotId( USHORT nWhich, BOOL bDeep = TRUE ) const;
250 USHORT GetTrueWhich( USHORT nSlot, BOOL bDeep = TRUE ) const;
251 USHORT GetTrueSlotId( USHORT nWhich, BOOL bDeep = TRUE ) const;
253 void SetVersionMap( USHORT nVer,
254 USHORT nOldStart, USHORT nOldEnd,
255 USHORT *pWhichIdTab );
256 USHORT GetNewWhich( USHORT nOldWhich ) const;
257 USHORT GetFileFormatVersion() const
258 { return _nFileFormatVersion; }
259 void SetFileFormatVersion( USHORT nFileFormatVersion );
260 USHORT GetLoadingVersion() const;
261 FASTBOOL IsCurrentVersionLoading() const;
263 static int IsWhich(USHORT nId) {
264 return nId && nId <= SFX_WHICH_MAX; }
265 static int IsSlot(USHORT nId) {
266 return nId && nId > SFX_WHICH_MAX; }
268 static const SfxItemPool* GetStoringPool();
269 static void SetStoringPool( const SfxItemPool * );
271 private:
272 const SfxItemPool& operator=(const SfxItemPool &); // n.i.!!
275 // --------------- Inline Implementierungen ------------------------------
277 // nur der Pool darf den Referenz-Zaehler manipulieren !!!
278 inline void SfxItemPool::SetRefCount( SfxPoolItem& rItem, ULONG n )
280 rItem.SetRefCount(n);
283 // nur der Pool darf den Referenz-Zaehler manipulieren !!!
284 inline ULONG SfxItemPool::AddRef( const SfxPoolItem& rItem, ULONG n )
286 return rItem.AddRef(n);
289 // nur der Pool darf den Referenz-Zaehler manipulieren !!!
290 inline ULONG SfxItemPool::ReleaseRef( const SfxPoolItem& rItem, ULONG n )
292 return rItem.ReleaseRef(n);
297 #endif