1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: itempool.hxx,v $
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
36 #define INCLUDED_LIMITS_H
40 #include <tools/solar.h>
44 #include <tools/string.hxx>
48 #include <bf_svtools/svarray.hxx>
51 #ifndef _SFXPOOLITEM_HXX
52 #include <bf_svtools/poolitem.hxx>
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 //====================================================================
93 //====================================================================
95 class SfxStyleSheetIterator
;
96 struct SfxPoolItemArray_Impl
;
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
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
114 void readTheItems(SvStream
& rStream
, USHORT nCount
, USHORT nVersion
,
115 SfxPoolItem
* pDefItem
, SfxPoolItemArray_Impl
** pArr
);
119 USHORT _nFileFormatVersion
;
121 const SfxItemInfo
* pItemInfos
;
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
;
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;
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;
153 //---------------------------------------------------------------------
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);
161 SfxItemPool( const SfxItemPool
&rPool
,
162 BOOL bCloneStaticDefaults
= FALSE
);
163 SfxItemPool( const UniString
&rName
,
164 USHORT nStart
, USHORT nEnd
,
166 const SfxItemInfo
*pItemInfos
,
168 SfxPoolItem
**pDefaults
= 0,
170 USHORT
*pSlotIds
= 0,
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
,
189 const ::IntlWrapper
* pIntlWrapper
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
&&
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 {
231 SfxItemPool
* GetMasterPool() const {
233 void FreezeIdRanges();
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
; }
244 int HasMap() const { return 0 != pSlotIds
; }
245 void SetMap( USHORT
*pNewSlotIds
)
246 { pSlotIds
= pNewSlotIds
; }
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
* );
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
);