xref: /aoo41x/main/svl/source/items/poolio.cxx (revision 40df464e)
1*40df464eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*40df464eSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*40df464eSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*40df464eSAndrew Rist  * distributed with this work for additional information
6*40df464eSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*40df464eSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*40df464eSAndrew Rist  * "License"); you may not use this file except in compliance
9*40df464eSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*40df464eSAndrew Rist  *
11*40df464eSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*40df464eSAndrew Rist  *
13*40df464eSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*40df464eSAndrew Rist  * software distributed under the License is distributed on an
15*40df464eSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*40df464eSAndrew Rist  * KIND, either express or implied.  See the License for the
17*40df464eSAndrew Rist  * specific language governing permissions and limitations
18*40df464eSAndrew Rist  * under the License.
19*40df464eSAndrew Rist  *
20*40df464eSAndrew Rist  *************************************************************/
21*40df464eSAndrew Rist 
22*40df464eSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <string.h>
28cdf0e10cSrcweir #include <stdio.h>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #ifndef GCC
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <tools/solar.h>
34cdf0e10cSrcweir #include <svl/itempool.hxx>
35cdf0e10cSrcweir #include "whassert.hxx"
36cdf0e10cSrcweir #include <svl/brdcst.hxx>
37cdf0e10cSrcweir #include <svl/filerec.hxx>
38cdf0e10cSrcweir #include <svl/svldata.hxx>
39cdf0e10cSrcweir #include "poolio.hxx"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
42cdf0e10cSrcweir 
43cdf0e10cSrcweir DBG_NAME(SfxItemPool);
44cdf0e10cSrcweir 
45cdf0e10cSrcweir //========================================================================
46cdf0e10cSrcweir 
SetStoringPool(const SfxItemPool * pStoringPool)47cdf0e10cSrcweir void SfxItemPool::SetStoringPool( const SfxItemPool *pStoringPool )
48cdf0e10cSrcweir 
49cdf0e10cSrcweir /*	[Beschreibung]
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 	Diese Methode setzt den <SfxItemPool>, der gerade gespeichert wird.
52cdf0e10cSrcweir 	Sie sollte nur in Notf"allen verwendet werden, um z.B. File-Format-
53cdf0e10cSrcweir 	Kompatibilit"at zu gew"ahrleisten o."o. - z.B. in der "uberladung eines
54cdf0e10cSrcweir 	<SfxPoolItem::Store()> zus"atzliche Daten aus dem dazuge"horigen
55cdf0e10cSrcweir 	Pool mit <SfxItemPool::GetStoringPool()> zu besorgen.
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 	Sie wird von <SfxItemPool::Store()> bedient, kann jedoch f"ur nicht
58cdf0e10cSrcweir 	poolable Items auch direkt gerufen werden. Bitte m"oglichst nicht
59cdf0e10cSrcweir 	f"ur jedes Item einzeln, da 2 Calls!
60cdf0e10cSrcweir */
61cdf0e10cSrcweir 
62cdf0e10cSrcweir {
63cdf0e10cSrcweir 	ImpSvlData::GetSvlData().pStoringPool = pStoringPool;
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir //-------------------------------------------------------------------------
67cdf0e10cSrcweir 
GetStoringPool()68cdf0e10cSrcweir const SfxItemPool* SfxItemPool::GetStoringPool()
69cdf0e10cSrcweir 
70cdf0e10cSrcweir /*	[Beschreibung]
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	Diese Methode liefert den <SfxItemPool>, der gerade gespeichert wird.
73cdf0e10cSrcweir 	Sie sollte nur in Notf"allen verwendet werden, um z.B. File-Format-
74cdf0e10cSrcweir 	Kompatibilit"at zu gew"ahrleisten o."o. - z.B. in der "uberladung eines
75cdf0e10cSrcweir 	<SfxPoolItem::Store()> zus"atzliche Daten aus dem dazuge"horigen
76cdf0e10cSrcweir 	Pool zu besorgen.
77cdf0e10cSrcweir */
78cdf0e10cSrcweir 
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 	return ImpSvlData::GetSvlData().pStoringPool;
81cdf0e10cSrcweir }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir //-------------------------------------------------------------------------
84cdf0e10cSrcweir 
Store(SvStream & rStream) const85cdf0e10cSrcweir SvStream &SfxItemPool::Store(SvStream &rStream) const
86cdf0e10cSrcweir 
87cdf0e10cSrcweir /*	[Beschreibung]
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	Der SfxItemPool wird inklusive aller seiner Sekund"arpools mit
90cdf0e10cSrcweir 	Pool-Defaults und gepoolten Items in dem angegebenen Stream gespeichert.
91cdf0e10cSrcweir 	Die statischen Defaults werden nicht gespeichert.
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	[Fileformat]
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	;zun"achst ein Kompatiblit"ats-Header-Block
97cdf0e10cSrcweir 	Start:		0x1111	SFX_ITEMPOOL_TAG_STARTPOOLS(_4/_5)
98cdf0e10cSrcweir 				sal_uInt8	MAJOR_VER					;SfxItemPool-Version
99cdf0e10cSrcweir 				sal_uInt8	MINOR_VER					;"
100cdf0e10cSrcweir 				0xFFFF	SFX_ITEMPOOL_TAG_TRICK4OLD  ;ex. GetVersion()
101cdf0e10cSrcweir 				sal_uInt16	0x0000						;Pseudo-StyleSheetPool
102cdf0e10cSrcweir 				sal_uInt16	0x0000						;Pseudo-StyleSheetPool
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	;den ganzen Pool in einen Record
105cdf0e10cSrcweir 				record	SfxMiniRecod(SFX_ITEMPOOL_REC)
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	;je ein Header vorweg
108cdf0e10cSrcweir 	Header:		record  	SfxMiniRecord(SFX_ITEMPOOL_REC_HEADER)
109cdf0e10cSrcweir 				sal_uInt16			GetVersion()			;Which-Ranges etc.
110cdf0e10cSrcweir 				String			GetName()				;Pool-Name
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	;die Versions-Map, um WhichIds neuer File-Versionen mappen zu k"onnen
113cdf0e10cSrcweir 	Versions:	record	    SfxMultiRecord(SFX_ITEMPOOL_REC_VERSIONS, 0)
114cdf0e10cSrcweir 				sal_uInt16			OldVersion
115cdf0e10cSrcweir 				sal_uInt16			OldStartWhich
116cdf0e10cSrcweir 				sal_uInt16			OldEndWhich
117cdf0e10cSrcweir 				sal_uInt16[]        NewWhich (OldEndWhich-OldStartWhich+1)
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	;jetzt die gepoolten Items (zuerst nicht-SfxSetItems)
120cdf0e10cSrcweir 	Items:  	record      SfxMultiRecord(SFX_ITEMPOOL_REC_WHICHIDS, 0)
121cdf0e10cSrcweir 				content 		SlotId, 0
122cdf0e10cSrcweir 				sal_uInt16			WhichId
123cdf0e10cSrcweir 				sal_uInt16			pItem->GetVersion()
124cdf0e10cSrcweir 				sal_uInt16			Array-Size
125cdf0e10cSrcweir 				record			SfxMultiRecord(SFX_, 0)
126cdf0e10cSrcweir 				content				Surrogate
127cdf0e10cSrcweir 				sal_uInt16				RefCount
128cdf0e10cSrcweir 				unknown 			pItem->Store()
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	;jetzt die gesetzten Pool-Defaults
131cdf0e10cSrcweir 	Defaults:	record	    SfxMultiRecord(SFX_ITEMPOOL_REC_DEFAULTS, 0)
132cdf0e10cSrcweir 				content			SlotId, 0
133cdf0e10cSrcweir 				sal_uInt16			WhichId
134cdf0e10cSrcweir 				sal_uInt16			pPoolDef->GetVersion()
135cdf0e10cSrcweir 				unknown			pPoolDef->Store();
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	;dahinter folgt ggf. der Secondary ohne Kompatiblit"ats-Header-Block
138cdf0e10cSrcweir */
139cdf0e10cSrcweir 
140cdf0e10cSrcweir {
141cdf0e10cSrcweir 	DBG_CHKTHIS(SfxItemPool, 0);
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 	// Store-Master finden
144cdf0e10cSrcweir 	SfxItemPool *pStoreMaster = pMaster != this ? pMaster : 0;
145cdf0e10cSrcweir 	while ( pStoreMaster && !pStoreMaster->pImp->bStreaming )
146cdf0e10cSrcweir 		pStoreMaster = pStoreMaster->pSecondary;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	// Alter-Header (Version des Pools an sich und Inhalts-Version 0xffff)
149cdf0e10cSrcweir 	pImp->bStreaming = sal_True;
150cdf0e10cSrcweir 	if ( !pStoreMaster )
151cdf0e10cSrcweir 	{
152cdf0e10cSrcweir 		rStream << ( rStream.GetVersion() >= SOFFICE_FILEFORMAT_50
153cdf0e10cSrcweir 				? SFX_ITEMPOOL_TAG_STARTPOOL_5
154cdf0e10cSrcweir 				: SFX_ITEMPOOL_TAG_STARTPOOL_4 );
155cdf0e10cSrcweir 		rStream << SFX_ITEMPOOL_VER_MAJOR << SFX_ITEMPOOL_VER_MINOR;
156cdf0e10cSrcweir 		rStream << SFX_ITEMPOOL_TAG_TRICK4OLD;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 		// SfxStyleSheet-Bug umgehen
159cdf0e10cSrcweir 		rStream << sal_uInt16(0); // Version
160cdf0e10cSrcweir 		rStream << sal_uInt16(0); // Count (2. Schleife f"allt sonst auf die Fresse)
161cdf0e10cSrcweir 	}
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 	// jeder Pool ist als ganzes ein Record
164cdf0e10cSrcweir 	SfxMiniRecordWriter aPoolRec( &rStream, SFX_ITEMPOOL_REC );
165cdf0e10cSrcweir 	ImpSvlData::GetSvlData().pStoringPool = this;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 	// Einzel-Header (Version des Inhalts und Name)
168cdf0e10cSrcweir 	{
169cdf0e10cSrcweir 		SfxMiniRecordWriter aPoolHeaderRec( &rStream, SFX_ITEMPOOL_REC_HEADER);
170cdf0e10cSrcweir 		rStream << pImp->nVersion;
171cdf0e10cSrcweir 		SfxPoolItem::writeByteString(rStream, aName);
172cdf0e10cSrcweir 	}
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 	// Version-Maps
175cdf0e10cSrcweir 	{
176cdf0e10cSrcweir 		SfxMultiVarRecordWriter aVerRec( &rStream, SFX_ITEMPOOL_REC_VERSIONMAP, 0 );
177cdf0e10cSrcweir 		for ( size_t nVerNo = 0; nVerNo < pImp->aVersions.size(); ++nVerNo )
178cdf0e10cSrcweir 		{
179cdf0e10cSrcweir 			aVerRec.NewContent();
180cdf0e10cSrcweir 			SfxPoolVersion_ImplPtr pVer = pImp->aVersions[nVerNo];
181cdf0e10cSrcweir 			rStream << pVer->_nVer << pVer->_nStart << pVer->_nEnd;
182cdf0e10cSrcweir 			sal_uInt16 nCount = pVer->_nEnd - pVer->_nStart + 1;
183cdf0e10cSrcweir 			sal_uInt16 nNewWhich = 0;
184cdf0e10cSrcweir 			for ( sal_uInt16 n = 0; n < nCount; ++n )
185cdf0e10cSrcweir 			{
186cdf0e10cSrcweir 				nNewWhich = pVer->_pMap[n];
187cdf0e10cSrcweir 				rStream << nNewWhich;
188cdf0e10cSrcweir 			}
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 			// Workaround gegen Bug in SetVersionMap der 312
191cdf0e10cSrcweir 			if ( SOFFICE_FILEFORMAT_31 == _nFileFormatVersion )
192cdf0e10cSrcweir 				rStream << sal_uInt16(nNewWhich+1);
193cdf0e10cSrcweir 		}
194cdf0e10cSrcweir 	}
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 	// gepoolte Items
197cdf0e10cSrcweir 	{
198cdf0e10cSrcweir 		SfxMultiMixRecordWriter aWhichIdsRec( &rStream, SFX_ITEMPOOL_REC_WHICHIDS, 0 );
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 		// erst Atomaren-Items und dann die Sets schreiben (wichtig beim Laden)
201cdf0e10cSrcweir 		for ( pImp->bInSetItem = sal_False; pImp->bInSetItem <= sal_True && !rStream.GetError(); ++pImp->bInSetItem )
202cdf0e10cSrcweir 		{
203cdf0e10cSrcweir 			SfxPoolItemArray_Impl **pArr = pImp->ppPoolItems;
204cdf0e10cSrcweir 			SfxPoolItem **ppDefItem = ppStaticDefaults;
205cdf0e10cSrcweir 			const sal_uInt16 nSize = GetSize_Impl();
206cdf0e10cSrcweir 			for ( size_t i = 0; i < nSize && !rStream.GetError(); ++i, ++pArr, ++ppDefItem )
207cdf0e10cSrcweir 			{
208cdf0e10cSrcweir 				// Version des Items feststellen
209cdf0e10cSrcweir 				sal_uInt16 nItemVersion = (*ppDefItem)->GetVersion( _nFileFormatVersion );
210cdf0e10cSrcweir 				if ( USHRT_MAX == nItemVersion )
211cdf0e10cSrcweir 					// => kam in zu exportierender Version gar nicht vor
212cdf0e10cSrcweir 					continue;
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 				// !poolable wird gar nicht im Pool gespeichert
215cdf0e10cSrcweir 				// und itemsets/plain-items je nach Runde
216cdf0e10cSrcweir #ifdef TF_POOLABLE
217cdf0e10cSrcweir 				if ( *pArr && IsItemFlag(**ppDefItem, SFX_ITEM_POOLABLE) &&
218cdf0e10cSrcweir #else
219cdf0e10cSrcweir 				if ( *pArr && (*ppDefItem)->IsPoolable() &&
220cdf0e10cSrcweir #endif
221cdf0e10cSrcweir 					 pImp->bInSetItem == (*ppDefItem)->ISA(SfxSetItem) )
222cdf0e10cSrcweir 				{
223cdf0e10cSrcweir 					// eigene Kennung, globale Which-Id und Item-Version
224cdf0e10cSrcweir 					sal_uInt16 nSlotId = GetSlotId( (*ppDefItem)->Which(), sal_False );
225cdf0e10cSrcweir 					aWhichIdsRec.NewContent(nSlotId, 0);
226cdf0e10cSrcweir 					rStream << (*ppDefItem)->Which();
227cdf0e10cSrcweir 					rStream << nItemVersion;
228cdf0e10cSrcweir 					const sal_uInt32 nCount = ::std::min<size_t>( (*pArr)->size(), SAL_MAX_UINT32 );
229cdf0e10cSrcweir 					DBG_ASSERT(nCount, "ItemArr is empty");
230cdf0e10cSrcweir 					rStream << nCount;
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 					// Items an sich schreiben
233cdf0e10cSrcweir 					SfxMultiMixRecordWriter aItemsRec( &rStream, SFX_ITEMPOOL_REC_ITEMS, 0 );
234cdf0e10cSrcweir 					for ( size_t j = 0; j < nCount; ++j )
235cdf0e10cSrcweir 					{
236cdf0e10cSrcweir 						// Item selbst besorgen
237cdf0e10cSrcweir 						const SfxPoolItem *pItem = (*pArr)->operator[](j);
238cdf0e10cSrcweir 						if ( pItem && pItem->GetRefCount() ) //! siehe anderes MI-REF
239cdf0e10cSrcweir 						{
240cdf0e10cSrcweir 							aItemsRec.NewContent((sal_uInt16)j, 'X' );
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 							if ( pItem->GetRefCount() == SFX_ITEMS_SPECIAL )
243cdf0e10cSrcweir 								rStream << (sal_uInt16) pItem->GetKind();
244cdf0e10cSrcweir 							else
245cdf0e10cSrcweir 							{
246cdf0e10cSrcweir 								rStream << (sal_uInt16) pItem->GetRefCount();
247cdf0e10cSrcweir 								if( pItem->GetRefCount() > SFX_ITEMS_OLD_MAXREF )
248cdf0e10cSrcweir 									rStream.SetError( ERRCODE_IO_NOTSTORABLEINBINARYFORMAT );
249cdf0e10cSrcweir 							}
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 							if ( !rStream.GetError() )
252cdf0e10cSrcweir 								pItem->Store(rStream, nItemVersion);
253cdf0e10cSrcweir 							else
254cdf0e10cSrcweir 								break;
255cdf0e10cSrcweir #ifdef DBG_UTIL_MI
256cdf0e10cSrcweir 							if ( !pItem->ISA(SfxSetItem) )
257cdf0e10cSrcweir 							{
258cdf0e10cSrcweir 								sal_uLong nMark = rStream.Tell();
259cdf0e10cSrcweir 								rStream.Seek( nItemStartPos + sizeof(sal_uInt16) );
260cdf0e10cSrcweir 								SfxPoolItem *pClone = pItem->Create(rStream, nItemVersion );
261cdf0e10cSrcweir 								sal_uInt16 nWh = pItem->Which();
262cdf0e10cSrcweir 								SFX_ASSERT( rStream.Tell() == nMark, nWh,"asymmetric store/create" );
263cdf0e10cSrcweir 								SFX_ASSERT( *pClone == *pItem, nWh, "unequal after store/create" );
264cdf0e10cSrcweir 								delete pClone;
265cdf0e10cSrcweir 							}
266cdf0e10cSrcweir #endif
267cdf0e10cSrcweir 						}
268cdf0e10cSrcweir 					}
269cdf0e10cSrcweir 				}
270cdf0e10cSrcweir 			}
271cdf0e10cSrcweir 		}
272cdf0e10cSrcweir 
273cdf0e10cSrcweir 		pImp->bInSetItem = sal_False;
274cdf0e10cSrcweir 	}
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 	// die gesetzten Defaults speichern (Pool-Defaults)
277cdf0e10cSrcweir 	if ( !rStream.GetError() )
278cdf0e10cSrcweir 	{
279cdf0e10cSrcweir 		SfxMultiMixRecordWriter aDefsRec( &rStream, SFX_ITEMPOOL_REC_DEFAULTS, 0 );
280cdf0e10cSrcweir 		sal_uInt16 nCount = GetSize_Impl();
281cdf0e10cSrcweir 		for ( sal_uInt16 n = 0; n < nCount; ++n )
282cdf0e10cSrcweir 		{
283cdf0e10cSrcweir 			const SfxPoolItem* pDefaultItem = ppPoolDefaults[n];
284cdf0e10cSrcweir 			if ( pDefaultItem )
285cdf0e10cSrcweir 			{
286cdf0e10cSrcweir 				// Version ermitteln
287cdf0e10cSrcweir 				sal_uInt16 nItemVersion = pDefaultItem->GetVersion( _nFileFormatVersion );
288cdf0e10cSrcweir 				if ( USHRT_MAX == nItemVersion )
289cdf0e10cSrcweir 					// => gab es in der Version noch nicht
290cdf0e10cSrcweir 					continue;
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 				// eigene Kennung, globale Kennung, Version
293cdf0e10cSrcweir 				sal_uInt16 nSlotId = GetSlotId( pDefaultItem->Which(), sal_False );
294cdf0e10cSrcweir 				aDefsRec.NewContent( nSlotId, 0 );
295cdf0e10cSrcweir 				rStream << pDefaultItem->Which();
296cdf0e10cSrcweir 				rStream << nItemVersion;
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 				// Item an sich
299cdf0e10cSrcweir 				pDefaultItem->Store( rStream, nItemVersion );
300cdf0e10cSrcweir 			}
301cdf0e10cSrcweir 		}
302cdf0e10cSrcweir 	}
303cdf0e10cSrcweir 
304cdf0e10cSrcweir 	// weitere Pools rausschreiben
305cdf0e10cSrcweir 	ImpSvlData::GetSvlData().pStoringPool = 0;
306cdf0e10cSrcweir 	aPoolRec.Close();
307cdf0e10cSrcweir 	if ( !rStream.GetError() && pSecondary )
308cdf0e10cSrcweir 		pSecondary->Store( rStream );
309cdf0e10cSrcweir 
310cdf0e10cSrcweir 	pImp->bStreaming = sal_False;
311cdf0e10cSrcweir 	return rStream;
312cdf0e10cSrcweir }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir // -----------------------------------------------------------------------
315cdf0e10cSrcweir 
LoadCompleted()316cdf0e10cSrcweir void SfxItemPool::LoadCompleted()
317cdf0e10cSrcweir 
318cdf0e10cSrcweir /*	[Beschreibung]
319cdf0e10cSrcweir 
320cdf0e10cSrcweir 	Wurde der SfxItemPool mit 'bRefCounts' == sal_False geladen, mu\s das
321cdf0e10cSrcweir 	Laden der Dokumentinhalte mit einem Aufruf dieser Methode beendet
322cdf0e10cSrcweir 	werden. Ansonsten hat der Aufruf dieser Methode keine Funktion.
323cdf0e10cSrcweir 
324cdf0e10cSrcweir 
325cdf0e10cSrcweir 	[Anmerkung]
326cdf0e10cSrcweir 
327cdf0e10cSrcweir 	Beim Laden ohne Ref-Counts werden diese tats"achlich auf 1 gesetzt,
328cdf0e10cSrcweir 	damit nicht w"ahrend des Ladevorgangs SfxPoolItems gel"oscht werden,
329cdf0e10cSrcweir 	die danach, aber auch noch beim Ladevorgang, ben"otigt werden. Diese
330cdf0e10cSrcweir 	Methode setzt den Ref-Count wieder zur"uck und entfernt dabei
331cdf0e10cSrcweir 	gleichzeitig alle nicht mehr ben"otigten Items.
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 
334cdf0e10cSrcweir 	[Querverweise]
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 	<SfxItemPool::Load()>
337cdf0e10cSrcweir */
338cdf0e10cSrcweir 
339cdf0e10cSrcweir {
340cdf0e10cSrcweir 	// wurden keine Ref-Counts mitgeladen?
341cdf0e10cSrcweir 	if ( pImp->nInitRefCount > 1 )
342cdf0e10cSrcweir 	{
343cdf0e10cSrcweir 
344cdf0e10cSrcweir 		// "uber alle Which-Werte iterieren
345cdf0e10cSrcweir 		SfxPoolItemArray_Impl** ppItemArr = pImp->ppPoolItems;
346cdf0e10cSrcweir 		for( sal_uInt16 nArrCnt = GetSize_Impl(); nArrCnt; --nArrCnt, ++ppItemArr )
347cdf0e10cSrcweir 		{
348cdf0e10cSrcweir 			// ist "uberhaupt ein Item mit dem Which-Wert da?
349cdf0e10cSrcweir 			if ( *ppItemArr )
350cdf0e10cSrcweir 			{
351cdf0e10cSrcweir 				// "uber alle Items mit dieser Which-Id iterieren
352cdf0e10cSrcweir 				SfxPoolItemArrayBase_Impl::iterator ppHtArr = (*ppItemArr)->begin();
353cdf0e10cSrcweir 				for( size_t n = (*ppItemArr)->size(); n; --n, ++ppHtArr )
354cdf0e10cSrcweir 					if (*ppHtArr)
355cdf0e10cSrcweir 					{
356cdf0e10cSrcweir                         #ifdef DBG_UTIL
357cdf0e10cSrcweir 						const SfxPoolItem &rItem = **ppHtArr;
358cdf0e10cSrcweir 						DBG_ASSERT( !rItem.ISA(SfxSetItem) ||
359cdf0e10cSrcweir 									0 != &((const SfxSetItem&)rItem).GetItemSet(),
360cdf0e10cSrcweir 									"SetItem without ItemSet" );
361cdf0e10cSrcweir                         #endif
362cdf0e10cSrcweir 
363cdf0e10cSrcweir 						if ( !ReleaseRef( **ppHtArr, 1 ) )
364cdf0e10cSrcweir 							DELETEZ( *ppHtArr );
365cdf0e10cSrcweir 					}
366cdf0e10cSrcweir 			}
367cdf0e10cSrcweir 		}
368cdf0e10cSrcweir 
369cdf0e10cSrcweir 		// from now on normal initial ref count
370cdf0e10cSrcweir 		pImp->nInitRefCount = 1;
371cdf0e10cSrcweir 	}
372cdf0e10cSrcweir 
373cdf0e10cSrcweir 	// notify secondary pool
374cdf0e10cSrcweir 	if ( pSecondary )
375cdf0e10cSrcweir 		pSecondary->LoadCompleted();
376cdf0e10cSrcweir }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir //============================================================================
379cdf0e10cSrcweir // This had to be moved to a method of its own to keep Solaris GCC happy:
readTheItems(SvStream & rStream,sal_uInt32 nItemCount,sal_uInt16 nVersion,SfxPoolItem * pDefItem,SfxPoolItemArray_Impl ** ppArr)380cdf0e10cSrcweir void SfxItemPool::readTheItems (
381cdf0e10cSrcweir 	SvStream & rStream, sal_uInt32 nItemCount, sal_uInt16 nVersion,
382cdf0e10cSrcweir 	SfxPoolItem * pDefItem, SfxPoolItemArray_Impl ** ppArr)
383cdf0e10cSrcweir {
384cdf0e10cSrcweir 	SfxMultiRecordReader aItemsRec( &rStream, SFX_ITEMPOOL_REC_ITEMS );
385cdf0e10cSrcweir 
386cdf0e10cSrcweir 	SfxPoolItemArray_Impl *pNewArr = new SfxPoolItemArray_Impl();
387cdf0e10cSrcweir 	SfxPoolItem *pItem = 0;
388cdf0e10cSrcweir 
389cdf0e10cSrcweir 	sal_uLong n, nLastSurrogate = sal_uLong(-1);
390cdf0e10cSrcweir 	while (aItemsRec.GetContent())
391cdf0e10cSrcweir 	{
392cdf0e10cSrcweir 		// n"achstes Surrogat holen
393cdf0e10cSrcweir 		sal_uInt16 nSurrogate = aItemsRec.GetContentTag();
394cdf0e10cSrcweir 		DBG_ASSERT( aItemsRec.GetContentVersion() == 'X',
395cdf0e10cSrcweir 					"not an item content" );
396cdf0e10cSrcweir 
397cdf0e10cSrcweir 		// fehlende auff"ullen
398cdf0e10cSrcweir 		for ( pItem = 0, n = nLastSurrogate+1; n < nSurrogate; ++n )
399cdf0e10cSrcweir 			pNewArr->push_back( (SfxPoolItem*) pItem );
400cdf0e10cSrcweir 		nLastSurrogate = nSurrogate;
401cdf0e10cSrcweir 
402cdf0e10cSrcweir 		// Ref-Count und Item laden
4036fb30688SEike Rathke 		sal_uInt16 nRef(0);
404cdf0e10cSrcweir 		rStream >> nRef;
405cdf0e10cSrcweir 
406cdf0e10cSrcweir 		pItem = pDefItem->Create(rStream, nVersion);
407cdf0e10cSrcweir 		pNewArr->push_back( (SfxPoolItem*) pItem );
408cdf0e10cSrcweir 
409cdf0e10cSrcweir 		if ( !bPersistentRefCounts )
410cdf0e10cSrcweir 			// bis <SfxItemPool::LoadCompleted()> festhalten
411cdf0e10cSrcweir 			AddRef(*pItem, 1);
412cdf0e10cSrcweir 		else
413cdf0e10cSrcweir 		{
414cdf0e10cSrcweir 			if ( nRef > SFX_ITEMS_OLD_MAXREF )
415cdf0e10cSrcweir 				pItem->SetKind( nRef );
416cdf0e10cSrcweir 			else
417cdf0e10cSrcweir 				AddRef(*pItem, nRef);
418cdf0e10cSrcweir 		}
419cdf0e10cSrcweir 	}
420cdf0e10cSrcweir 
421cdf0e10cSrcweir 	// fehlende auff"ullen
422cdf0e10cSrcweir 	for ( pItem = 0, n = nLastSurrogate+1; n < nItemCount; ++n )
423cdf0e10cSrcweir 		pNewArr->push_back( (SfxPoolItem*) pItem );
424cdf0e10cSrcweir 
425cdf0e10cSrcweir 	SfxPoolItemArray_Impl *pOldArr = *ppArr;
426cdf0e10cSrcweir 	*ppArr = pNewArr;
427cdf0e10cSrcweir 
428cdf0e10cSrcweir 	// die Items merken, die schon im Pool sind
429cdf0e10cSrcweir 	bool bEmpty = true;
430cdf0e10cSrcweir 	if ( 0 != pOldArr )
431cdf0e10cSrcweir 		for ( n = 0; bEmpty && n < pOldArr->size(); ++n )
432cdf0e10cSrcweir 			bEmpty = pOldArr->operator[](n) == 0;
433cdf0e10cSrcweir 	DBG_ASSERTWARNING( bEmpty, "loading non-empty pool" );
434cdf0e10cSrcweir 	if ( !bEmpty )
435cdf0e10cSrcweir 	{
436cdf0e10cSrcweir 		// f"ur alle alten suchen, ob ein gleiches neues existiert
437cdf0e10cSrcweir 		for ( size_t nOld = 0; nOld < pOldArr->size(); ++nOld )
438cdf0e10cSrcweir 		{
439cdf0e10cSrcweir 			SfxPoolItem *pOldItem = (*pOldArr)[nOld];
440cdf0e10cSrcweir 			if ( pOldItem )
441cdf0e10cSrcweir 			{
442cdf0e10cSrcweir 				sal_uInt32 nFree = SAL_MAX_UINT32;
443cdf0e10cSrcweir 				bool bFound = false;
444cdf0e10cSrcweir 				for ( size_t nNew = (*ppArr)->size(); nNew--; )
445cdf0e10cSrcweir 				{
446cdf0e10cSrcweir 					// geladenes Item
447cdf0e10cSrcweir 					SfxPoolItem *&rpNewItem =
448cdf0e10cSrcweir 						(SfxPoolItem*&)(*ppArr)->operator[](nNew);
449cdf0e10cSrcweir 
450cdf0e10cSrcweir 					// surrogat unbenutzt?
451cdf0e10cSrcweir 					if ( !rpNewItem )
452cdf0e10cSrcweir 						nFree = nNew;
453cdf0e10cSrcweir 
454cdf0e10cSrcweir 					// gefunden?
455cdf0e10cSrcweir 					else if ( *rpNewItem == *pOldItem )
456cdf0e10cSrcweir 					{
457cdf0e10cSrcweir 						// wiederverwenden
458cdf0e10cSrcweir 						AddRef( *pOldItem, rpNewItem->GetRefCount() );
459cdf0e10cSrcweir 						SetRefCount( *rpNewItem, 0 );
460cdf0e10cSrcweir 						delete rpNewItem;
461cdf0e10cSrcweir 						rpNewItem = pOldItem;
462cdf0e10cSrcweir 						bFound = true;
463cdf0e10cSrcweir 						break;
464cdf0e10cSrcweir 					}
465cdf0e10cSrcweir 				}
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 				// vorhervorhandene, nicht geladene uebernehmen
468cdf0e10cSrcweir 				if ( !bFound )
469cdf0e10cSrcweir 				{
470cdf0e10cSrcweir 					if ( nFree != SAL_MAX_UINT32 )
471cdf0e10cSrcweir 						(SfxPoolItem*&)(*ppArr)->operator[](nFree) = pOldItem;
472cdf0e10cSrcweir 					else
473cdf0e10cSrcweir 						(*ppArr)->push_back( (SfxPoolItem*) pOldItem );
474cdf0e10cSrcweir 				}
475cdf0e10cSrcweir 			}
476cdf0e10cSrcweir 		}
477cdf0e10cSrcweir 	}
478cdf0e10cSrcweir 	delete pOldArr;
479cdf0e10cSrcweir }
480cdf0e10cSrcweir 
481cdf0e10cSrcweir // -----------------------------------------------------------------------
482cdf0e10cSrcweir 
Load(SvStream & rStream)483cdf0e10cSrcweir SvStream &SfxItemPool::Load(SvStream &rStream)
484cdf0e10cSrcweir {
485cdf0e10cSrcweir 	DBG_CHKTHIS(SfxItemPool, 0);
486cdf0e10cSrcweir 	DBG_ASSERT(ppStaticDefaults, "kein DefaultArray");
487cdf0e10cSrcweir 
488cdf0e10cSrcweir 	// protect items by increasing ref count
489cdf0e10cSrcweir 	if ( !bPersistentRefCounts )
490cdf0e10cSrcweir 	{
491cdf0e10cSrcweir 
492cdf0e10cSrcweir 		// "uber alle Which-Werte iterieren
493cdf0e10cSrcweir 		SfxPoolItemArray_Impl** ppItemArr = pImp->ppPoolItems;
494cdf0e10cSrcweir 		for( size_t nArrCnt = GetSize_Impl(); nArrCnt; --nArrCnt, ++ppItemArr )
495cdf0e10cSrcweir 		{
496cdf0e10cSrcweir 			// ist "uberhaupt ein Item mit dem Which-Wert da?
497cdf0e10cSrcweir 			if ( *ppItemArr )
498cdf0e10cSrcweir 			{
499cdf0e10cSrcweir 				// "uber alle Items mit dieser Which-Id iterieren
500cdf0e10cSrcweir 				SfxPoolItemArrayBase_Impl::iterator ppHtArr = (*ppItemArr)->begin();
501cdf0e10cSrcweir 				for( size_t n = (*ppItemArr)->size(); n; --n, ++ppHtArr )
502cdf0e10cSrcweir 					if (*ppHtArr)
503cdf0e10cSrcweir 					{
504cdf0e10cSrcweir                         #ifdef DBG_UTIL
505cdf0e10cSrcweir 						const SfxPoolItem &rItem = **ppHtArr;
506cdf0e10cSrcweir 						DBG_ASSERT( !rItem.ISA(SfxSetItem) ||
507cdf0e10cSrcweir 									0 != &((const SfxSetItem&)rItem).GetItemSet(),
508cdf0e10cSrcweir 									"SetItem without ItemSet" );
509cdf0e10cSrcweir 						DBG_WARNING( "loading non-empty ItemPool" );
510cdf0e10cSrcweir                         #endif
511cdf0e10cSrcweir 
512cdf0e10cSrcweir 						AddRef( **ppHtArr, 1 );
513cdf0e10cSrcweir 					}
514cdf0e10cSrcweir 			}
515cdf0e10cSrcweir 		}
516cdf0e10cSrcweir 
517cdf0e10cSrcweir 		// during loading (until LoadCompleted()) protect all items
518cdf0e10cSrcweir 		pImp->nInitRefCount = 2;
519cdf0e10cSrcweir 	}
520cdf0e10cSrcweir 
521cdf0e10cSrcweir 	// Load-Master finden
522cdf0e10cSrcweir 	SfxItemPool *pLoadMaster = pMaster != this ? pMaster : 0;
523cdf0e10cSrcweir 	while ( pLoadMaster && !pLoadMaster->pImp->bStreaming )
524cdf0e10cSrcweir 		pLoadMaster = pLoadMaster->pSecondary;
525cdf0e10cSrcweir 
526cdf0e10cSrcweir 	// Gesamt Header einlesen
527cdf0e10cSrcweir 	pImp->bStreaming = sal_True;
528cdf0e10cSrcweir 	if ( !pLoadMaster )
529cdf0e10cSrcweir 	{
530cdf0e10cSrcweir 		// Format-Version laden
531cdf0e10cSrcweir 		CHECK_FILEFORMAT2( rStream,
532cdf0e10cSrcweir 				SFX_ITEMPOOL_TAG_STARTPOOL_5, SFX_ITEMPOOL_TAG_STARTPOOL_4 );
533cdf0e10cSrcweir 		rStream >> pImp->nMajorVer >> pImp->nMinorVer;
534cdf0e10cSrcweir 
535cdf0e10cSrcweir 		// Format-Version in Master-Pool "ubertragen
536cdf0e10cSrcweir 		pMaster->pImp->nMajorVer = pImp->nMajorVer;
537cdf0e10cSrcweir 		pMaster->pImp->nMinorVer = pImp->nMinorVer;
538cdf0e10cSrcweir 
539cdf0e10cSrcweir 		// altes Format?
540cdf0e10cSrcweir 		if ( pImp->nMajorVer < 2 )
541cdf0e10cSrcweir 			// pImp->bStreaming wird von Load1_Impl() zur"uckgesetzt
542cdf0e10cSrcweir 			return Load1_Impl( rStream );
543cdf0e10cSrcweir 
544cdf0e10cSrcweir 		// zu neues Format?
545cdf0e10cSrcweir 		if ( pImp->nMajorVer > SFX_ITEMPOOL_VER_MAJOR )
546cdf0e10cSrcweir 		{
547cdf0e10cSrcweir 			rStream.SetError(SVSTREAM_FILEFORMAT_ERROR);
548cdf0e10cSrcweir 			pImp->bStreaming = sal_False;
549cdf0e10cSrcweir 			return rStream;
550cdf0e10cSrcweir 		}
551cdf0e10cSrcweir 
552cdf0e10cSrcweir 		// Version 1.2-Trick-Daten "uberspringen
553cdf0e10cSrcweir 		CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_TRICK4OLD );
554cdf0e10cSrcweir 		rStream.SeekRel( 4 ); // Hack-Daten wegen SfxStyleSheetPool-Bug  skippen
555cdf0e10cSrcweir 	}
556cdf0e10cSrcweir 
557cdf0e10cSrcweir 	// neues Record-orientiertes Format
558cdf0e10cSrcweir 	SfxMiniRecordReader aPoolRec( &rStream, SFX_ITEMPOOL_REC );
559cdf0e10cSrcweir 	if ( rStream.GetError() )
560cdf0e10cSrcweir 	{
561cdf0e10cSrcweir 		pImp->bStreaming = sal_False;
562cdf0e10cSrcweir 		return rStream;
563cdf0e10cSrcweir 	}
564cdf0e10cSrcweir 
565cdf0e10cSrcweir 	// Einzel-Header
566cdf0e10cSrcweir 	int bOwnPool = sal_True;
567cdf0e10cSrcweir 	UniString aExternName;
568cdf0e10cSrcweir 	{
569cdf0e10cSrcweir 		// Header-Record suchen
570cdf0e10cSrcweir 		SfxMiniRecordReader aPoolHeaderRec( &rStream, SFX_ITEMPOOL_REC_HEADER );
571cdf0e10cSrcweir 		if ( rStream.GetError() )
572cdf0e10cSrcweir 		{
573cdf0e10cSrcweir 			pImp->bStreaming = sal_False;
574cdf0e10cSrcweir 			return rStream;
575cdf0e10cSrcweir 		}
576cdf0e10cSrcweir 
577cdf0e10cSrcweir 		// Header-lesen
578cdf0e10cSrcweir 		rStream >> pImp->nLoadingVersion;
579cdf0e10cSrcweir 		SfxPoolItem::readByteString(rStream, aExternName);
580cdf0e10cSrcweir 		bOwnPool = aExternName == aName;
581cdf0e10cSrcweir 
582cdf0e10cSrcweir 		//! solange wir keine fremden Pools laden k"onnen
583cdf0e10cSrcweir 		if ( !bOwnPool )
584cdf0e10cSrcweir 		{
585cdf0e10cSrcweir 			rStream.SetError(SVSTREAM_FILEFORMAT_ERROR);
586cdf0e10cSrcweir 			aPoolRec.Skip();
587cdf0e10cSrcweir 			pImp->bStreaming = sal_False;
588cdf0e10cSrcweir 			return rStream;
589cdf0e10cSrcweir 		}
590cdf0e10cSrcweir 	}
591cdf0e10cSrcweir 
592cdf0e10cSrcweir 	// Version-Maps
593cdf0e10cSrcweir 	{
594cdf0e10cSrcweir 		SfxMultiRecordReader aVerRec( &rStream, SFX_ITEMPOOL_REC_VERSIONMAP );
595cdf0e10cSrcweir 		if ( rStream.GetError() )
596cdf0e10cSrcweir 		{
597cdf0e10cSrcweir 			pImp->bStreaming = sal_False;
598cdf0e10cSrcweir 			return rStream;
599cdf0e10cSrcweir 		}
600cdf0e10cSrcweir 
601cdf0e10cSrcweir 		// Versions-Maps einlesen
602cdf0e10cSrcweir 		sal_uInt16 nOwnVersion = pImp->nVersion;
603cdf0e10cSrcweir 		for ( sal_uInt16 nVerNo = 0; aVerRec.GetContent(); ++nVerNo )
604cdf0e10cSrcweir 		{
605cdf0e10cSrcweir 			// Header f"ur einzelne Version einlesen
6066fb30688SEike Rathke 			sal_uInt16 nVersion(0), nHStart(0), nHEnd(0);
607cdf0e10cSrcweir 			rStream >> nVersion >> nHStart >> nHEnd;
608cdf0e10cSrcweir 			sal_uInt16 nCount = nHEnd - nHStart + 1;
609cdf0e10cSrcweir 
610cdf0e10cSrcweir 			// Is new version is known?
611cdf0e10cSrcweir 			if ( nVerNo >= pImp->aVersions.size() )
612cdf0e10cSrcweir 			{
613cdf0e10cSrcweir 				// Add new Version
614cdf0e10cSrcweir 				sal_uInt16 *pMap = new sal_uInt16[nCount];
6156fb30688SEike Rathke                 memset(pMap, 0, nCount * sizeof(sal_uInt16));
616cdf0e10cSrcweir 				for ( sal_uInt16 n = 0; n < nCount; ++n )
617cdf0e10cSrcweir 					rStream >> pMap[n];
618cdf0e10cSrcweir 				SetVersionMap( nVersion, nHStart, nHEnd, pMap );
619cdf0e10cSrcweir 			}
620cdf0e10cSrcweir 		}
621cdf0e10cSrcweir 		pImp->nVersion = nOwnVersion;
622cdf0e10cSrcweir 	}
623cdf0e10cSrcweir 
624cdf0e10cSrcweir 	// Items laden
625cdf0e10cSrcweir 	FASTBOOL bSecondaryLoaded = sal_False;
626cdf0e10cSrcweir 	long nSecondaryEnd = 0;
627cdf0e10cSrcweir 	{
628cdf0e10cSrcweir 		SfxMultiRecordReader aWhichIdsRec( &rStream, SFX_ITEMPOOL_REC_WHICHIDS);
629cdf0e10cSrcweir 		while ( aWhichIdsRec.GetContent() )
630cdf0e10cSrcweir 		{
631cdf0e10cSrcweir 			// SlotId, Which-Id und Item-Version besorgen
6326fb30688SEike Rathke 			sal_uInt32 nCount(0);
6336fb30688SEike Rathke 			sal_uInt16 nVersion(0), nWhich(0);
634cdf0e10cSrcweir 			//!sal_uInt16 nSlotId = aWhichIdsRec.GetContentTag();
635cdf0e10cSrcweir 			rStream >> nWhich;
636cdf0e10cSrcweir 			if ( pImp->nLoadingVersion != pImp->nVersion )
637cdf0e10cSrcweir 				// Which-Id aus File-Version in Pool-Version verschieben
638cdf0e10cSrcweir 				nWhich = GetNewWhich( nWhich );
639cdf0e10cSrcweir 
640cdf0e10cSrcweir 			// unbekanntes Item aus neuerer Version
641cdf0e10cSrcweir 			if ( !IsInRange(nWhich) )
642cdf0e10cSrcweir 				continue;
643cdf0e10cSrcweir 
644cdf0e10cSrcweir 			rStream >> nVersion;
645cdf0e10cSrcweir 			rStream >> nCount;
646cdf0e10cSrcweir 			//!SFX_ASSERTWARNING( !nSlotId || !HasMap() ||
647cdf0e10cSrcweir 			//!			( nSlotId == GetSlotId( nWhich, sal_False ) ) ||
648cdf0e10cSrcweir 			//!			!GetSlotId( nWhich, sal_False ),
649cdf0e10cSrcweir 			//!			nWhich, "Slot/Which mismatch" );
650cdf0e10cSrcweir 
651cdf0e10cSrcweir 			sal_uInt16 nIndex = GetIndex_Impl(nWhich);
652cdf0e10cSrcweir 			SfxPoolItemArray_Impl **ppArr = pImp->ppPoolItems + nIndex;
653cdf0e10cSrcweir 
654cdf0e10cSrcweir 			// SfxSetItems k"onnten Items aus Sekund"arpools beinhalten
655cdf0e10cSrcweir 			SfxPoolItem *pDefItem = *(ppStaticDefaults + nIndex);
656cdf0e10cSrcweir 			pImp->bInSetItem = pDefItem->ISA(SfxSetItem);
657cdf0e10cSrcweir 			if ( !bSecondaryLoaded && pSecondary && pImp->bInSetItem )
658cdf0e10cSrcweir 			{
659cdf0e10cSrcweir 				// an das Ende des eigenen Pools seeken
660cdf0e10cSrcweir 				sal_uLong nLastPos = rStream.Tell();
661cdf0e10cSrcweir 				aPoolRec.Skip();
662cdf0e10cSrcweir 
663cdf0e10cSrcweir 				// Sekund"arpool einlesen
664cdf0e10cSrcweir 				pSecondary->Load( rStream );
665cdf0e10cSrcweir 				bSecondaryLoaded = sal_True;
666cdf0e10cSrcweir 				nSecondaryEnd = rStream.Tell();
667cdf0e10cSrcweir 
668cdf0e10cSrcweir 				// zur"uck zu unseren eigenen Items
669cdf0e10cSrcweir 				rStream.Seek(nLastPos);
670cdf0e10cSrcweir 			}
671cdf0e10cSrcweir 
672cdf0e10cSrcweir 			// Items an sich lesen
673cdf0e10cSrcweir 			readTheItems(rStream, nCount, nVersion, pDefItem, ppArr);
674cdf0e10cSrcweir 
675cdf0e10cSrcweir 			pImp->bInSetItem = sal_False;
676cdf0e10cSrcweir 		}
677cdf0e10cSrcweir 	}
678cdf0e10cSrcweir 
679cdf0e10cSrcweir 	// Pool-Defaults lesen
680cdf0e10cSrcweir 	{
681cdf0e10cSrcweir 		SfxMultiRecordReader aDefsRec( &rStream, SFX_ITEMPOOL_REC_DEFAULTS );
682cdf0e10cSrcweir 
683cdf0e10cSrcweir 		while ( aDefsRec.GetContent() )
684cdf0e10cSrcweir 		{
685cdf0e10cSrcweir 			// SlotId, Which-Id und Item-Version besorgen
6866fb30688SEike Rathke 			sal_uInt16 nVersion(0), nWhich(0);
687cdf0e10cSrcweir 			//!sal_uInt16 nSlotId = aDefsRec.GetContentTag();
688cdf0e10cSrcweir 			rStream >> nWhich;
689cdf0e10cSrcweir 			if ( pImp->nLoadingVersion != pImp->nVersion )
690cdf0e10cSrcweir 				// Which-Id aus File-Version in Pool-Version verschieben
691cdf0e10cSrcweir 				nWhich = GetNewWhich( nWhich );
692cdf0e10cSrcweir 
693cdf0e10cSrcweir 			// unbekanntes Item aus neuerer Version
694cdf0e10cSrcweir 			if ( !IsInRange(nWhich) )
695cdf0e10cSrcweir 				continue;
696cdf0e10cSrcweir 
697cdf0e10cSrcweir 			rStream >> nVersion;
698cdf0e10cSrcweir 			//!SFX_ASSERTWARNING( !HasMap() || ( nSlotId == GetSlotId( nWhich, sal_False ) ),
699cdf0e10cSrcweir 			//!			nWhich, "Slot/Which mismatch" );
700cdf0e10cSrcweir 
701cdf0e10cSrcweir 			// Pool-Default-Item selbst laden
702cdf0e10cSrcweir 			SfxPoolItem *pItem =
703cdf0e10cSrcweir 					( *( ppStaticDefaults + GetIndex_Impl(nWhich) ) )
704cdf0e10cSrcweir 					->Create( rStream, nVersion );
705cdf0e10cSrcweir 			pItem->SetKind( SFX_ITEMS_POOLDEFAULT );
706cdf0e10cSrcweir 			*( ppPoolDefaults + GetIndex_Impl(nWhich) ) = pItem;
707cdf0e10cSrcweir 		}
708cdf0e10cSrcweir 	}
709cdf0e10cSrcweir 
710cdf0e10cSrcweir 	// ggf. Secondary-Pool laden
711cdf0e10cSrcweir 	aPoolRec.Skip();
712cdf0e10cSrcweir 	if ( pSecondary )
713cdf0e10cSrcweir 	{
714cdf0e10cSrcweir 		if ( !bSecondaryLoaded )
715cdf0e10cSrcweir 			pSecondary->Load( rStream );
716cdf0e10cSrcweir 		else
717cdf0e10cSrcweir 			rStream.Seek( nSecondaryEnd );
718cdf0e10cSrcweir 	}
719cdf0e10cSrcweir 
720cdf0e10cSrcweir 	// wenn nicht own-Pool, dann kein Name
721cdf0e10cSrcweir 	if ( aExternName != aName )
722cdf0e10cSrcweir 		aName.Erase();
723cdf0e10cSrcweir 
724cdf0e10cSrcweir 	pImp->bStreaming = sal_False;
725cdf0e10cSrcweir 	return rStream;
726cdf0e10cSrcweir };
727cdf0e10cSrcweir 
728cdf0e10cSrcweir // -----------------------------------------------------------------------
729cdf0e10cSrcweir 
Load1_Impl(SvStream & rStream)730cdf0e10cSrcweir SvStream &SfxItemPool::Load1_Impl(SvStream &rStream)
731cdf0e10cSrcweir {
732cdf0e10cSrcweir 	// beim Master ist der Header schon von <Load()> geladen worden
733cdf0e10cSrcweir 	if ( !pImp->bStreaming )
734cdf0e10cSrcweir 	{
735cdf0e10cSrcweir 		// Header des Secondary lesen
736cdf0e10cSrcweir 		CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_STARTPOOL_4 );
737cdf0e10cSrcweir 		rStream >> pImp->nMajorVer >> pImp->nMinorVer;
738cdf0e10cSrcweir 	}
7396fb30688SEike Rathke 	sal_uInt32 nAttribSize(0);
740cdf0e10cSrcweir 	int bOwnPool = sal_True;
741cdf0e10cSrcweir 	UniString aExternName;
742cdf0e10cSrcweir 	if ( pImp->nMajorVer > 1 || pImp->nMinorVer >= 2 )
743cdf0e10cSrcweir 		rStream >> pImp->nLoadingVersion;
744cdf0e10cSrcweir 	SfxPoolItem::readByteString(rStream, aExternName);
745cdf0e10cSrcweir 	bOwnPool = aExternName == aName;
746cdf0e10cSrcweir 	pImp->bStreaming = sal_True;
747cdf0e10cSrcweir 
748cdf0e10cSrcweir 	//! solange wir keine fremden laden k"onnen
749cdf0e10cSrcweir 	if ( !bOwnPool )
750cdf0e10cSrcweir 	{
751cdf0e10cSrcweir 		rStream.SetError(SVSTREAM_FILEFORMAT_ERROR);
752cdf0e10cSrcweir 		pImp->bStreaming = sal_False;
753cdf0e10cSrcweir 		return rStream;
754cdf0e10cSrcweir 	}
755cdf0e10cSrcweir 
756cdf0e10cSrcweir 	// Versionen bis 1.3 k"onnen noch keine Which-Verschiebungen lesen
757cdf0e10cSrcweir 	if ( pImp->nMajorVer == 1 && pImp->nMinorVer <= 2 &&
758cdf0e10cSrcweir 		 pImp->nVersion < pImp->nLoadingVersion )
759cdf0e10cSrcweir 	{
760cdf0e10cSrcweir 		rStream.SetError(ERRCODE_IO_WRONGVERSION);
761cdf0e10cSrcweir 		pImp->bStreaming = sal_False;
762cdf0e10cSrcweir 		return rStream;
763cdf0e10cSrcweir 	}
764cdf0e10cSrcweir 
765cdf0e10cSrcweir 	// Size-Table liegt hinter den eigentlichen Attributen
766cdf0e10cSrcweir 	rStream >> nAttribSize;
767cdf0e10cSrcweir 
768cdf0e10cSrcweir 	// Size-Table einlesen
769cdf0e10cSrcweir 	sal_uLong nStartPos = rStream.Tell();
770cdf0e10cSrcweir 	rStream.SeekRel( nAttribSize );
771cdf0e10cSrcweir 	CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_SIZES );
7726fb30688SEike Rathke 	sal_uInt32 nSizeTableLen(0);
773cdf0e10cSrcweir 	rStream >> nSizeTableLen;
774cdf0e10cSrcweir 	sal_Char *pBuf = new sal_Char[nSizeTableLen];
775cdf0e10cSrcweir 	rStream.Read( pBuf, nSizeTableLen );
776cdf0e10cSrcweir 	sal_uLong nEndOfSizes = rStream.Tell();
777cdf0e10cSrcweir 	SvMemoryStream aSizeTable( pBuf, nSizeTableLen, STREAM_READ );
778cdf0e10cSrcweir 
779cdf0e10cSrcweir 	// ab Version 1.3 steht in der Size-Table eine Versions-Map
780cdf0e10cSrcweir 	if ( pImp->nMajorVer > 1 || pImp->nMinorVer >= 3 )
781cdf0e10cSrcweir 	{
782cdf0e10cSrcweir 		// Version-Map finden (letztes sal_uLong der Size-Table gibt Pos an)
783cdf0e10cSrcweir 		rStream.Seek( nEndOfSizes - sizeof(sal_uInt32) );
7846fb30688SEike Rathke 		sal_uInt32 nVersionMapPos(0);
785cdf0e10cSrcweir 		rStream >> nVersionMapPos;
786cdf0e10cSrcweir 		rStream.Seek( nVersionMapPos );
787cdf0e10cSrcweir 
788cdf0e10cSrcweir 		// Versions-Maps einlesen
789cdf0e10cSrcweir 		CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_VERSIONMAP );
7906fb30688SEike Rathke 		sal_uInt16 nVerCount(0);
791cdf0e10cSrcweir 		rStream >> nVerCount;
792cdf0e10cSrcweir 		for ( sal_uInt16 nVerNo = 0; nVerNo < nVerCount; ++nVerNo )
793cdf0e10cSrcweir 		{
794cdf0e10cSrcweir 			// Header f"ur einzelne Version einlesen
7956fb30688SEike Rathke 			sal_uInt16 nVersion(0), nHStart(0), nHEnd(0);
796cdf0e10cSrcweir 			rStream >> nVersion >> nHStart >> nHEnd;
797cdf0e10cSrcweir 			sal_uInt16 nCount = nHEnd - nHStart + 1;
798cdf0e10cSrcweir 			sal_uInt16 nBytes = (nCount)*sizeof(sal_uInt16);
799cdf0e10cSrcweir 
800cdf0e10cSrcweir 			// Is new version is known?
801cdf0e10cSrcweir 			if ( nVerNo >= pImp->aVersions.size() )
802cdf0e10cSrcweir 			{
803cdf0e10cSrcweir 				// Add new Version
804cdf0e10cSrcweir 				sal_uInt16 *pMap = new sal_uInt16[nCount];
8056fb30688SEike Rathke                 memset(pMap, 0, nCount * sizeof(sal_uInt16));
806cdf0e10cSrcweir 				for ( sal_uInt16 n = 0; n < nCount; ++n )
807cdf0e10cSrcweir 					rStream >> pMap[n];
808cdf0e10cSrcweir 				SetVersionMap( nVersion, nHStart, nHEnd, pMap );
809cdf0e10cSrcweir 			}
810cdf0e10cSrcweir 			else
811cdf0e10cSrcweir 				// Version schon bekannt => "uberspringen
812cdf0e10cSrcweir 				rStream.SeekRel( nBytes );
813cdf0e10cSrcweir 		}
814cdf0e10cSrcweir 	}
815cdf0e10cSrcweir 
816cdf0e10cSrcweir 	// Items laden
817cdf0e10cSrcweir 	rStream.Seek( nStartPos );
818cdf0e10cSrcweir 	CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_ITEMS );
819cdf0e10cSrcweir 	FASTBOOL bSecondaryLoaded = sal_False;
820cdf0e10cSrcweir 	long nSecondaryEnd = 0;
8216fb30688SEike Rathke 	sal_uInt16 nWhich(0), nSlot(0);
822cdf0e10cSrcweir 	while ( rStream >> nWhich, nWhich )
823cdf0e10cSrcweir 	{
824cdf0e10cSrcweir 		// ggf. Which-Id aus alter Version verschieben?
825cdf0e10cSrcweir 		if ( pImp->nLoadingVersion != pImp->nVersion )
826cdf0e10cSrcweir 			nWhich = GetNewWhich( nWhich );
827cdf0e10cSrcweir 
828cdf0e10cSrcweir 		rStream >> nSlot;
829cdf0e10cSrcweir 		sal_uInt16 nMappedWhich = GetWhich(nSlot, sal_False);
830cdf0e10cSrcweir 		int bKnownItem = bOwnPool || IsWhich(nMappedWhich);
831cdf0e10cSrcweir 
8326fb30688SEike Rathke 		sal_uInt16 nRef(0), nCount(0), nVersion(0);
8336fb30688SEike Rathke 		sal_uInt32 nAttrSize(0);
834cdf0e10cSrcweir 		rStream >> nVersion >> nCount;
835cdf0e10cSrcweir 
836cdf0e10cSrcweir 		SfxPoolItemArray_Impl **ppArr = 0;
837cdf0e10cSrcweir 		SfxPoolItemArray_Impl *pNewArr = 0;
838cdf0e10cSrcweir 		SfxPoolItem *pDefItem = 0;
839cdf0e10cSrcweir 		if ( bKnownItem )
840cdf0e10cSrcweir 		{
841cdf0e10cSrcweir 			if ( !bOwnPool )
842cdf0e10cSrcweir 				nWhich = nMappedWhich;
843cdf0e10cSrcweir 
844cdf0e10cSrcweir 			//!SFX_ASSERTWARNING( !nSlot || !HasMap() ||
845cdf0e10cSrcweir 			//!			( nSlot == GetSlotId( nWhich, sal_False ) ) ||
846cdf0e10cSrcweir 			//!			!GetSlotId( nWhich, sal_False ),
847cdf0e10cSrcweir 			//!			nWhich, "Slot/Which mismatch" );
848cdf0e10cSrcweir 
849cdf0e10cSrcweir 			sal_uInt16 nIndex = GetIndex_Impl(nWhich);
850cdf0e10cSrcweir 			ppArr = pImp->ppPoolItems + nIndex;
851cdf0e10cSrcweir 			pNewArr = new SfxPoolItemArray_Impl();
852cdf0e10cSrcweir 			pDefItem = *(ppStaticDefaults + nIndex);
853cdf0e10cSrcweir 		}
854cdf0e10cSrcweir 
855cdf0e10cSrcweir 		// Position vor ersten Item merken
856cdf0e10cSrcweir 		sal_uLong nLastPos = rStream.Tell();
857cdf0e10cSrcweir 
858cdf0e10cSrcweir 		// SfxSetItems k"onnten Items aus Sekund"arpools beinhalten
859cdf0e10cSrcweir 		if ( !bSecondaryLoaded && pSecondary && pDefItem->ISA(SfxSetItem) )
860cdf0e10cSrcweir 		{
861cdf0e10cSrcweir 			// an das Ende des eigenen Pools seeken
862cdf0e10cSrcweir 			rStream.Seek(nEndOfSizes);
863cdf0e10cSrcweir             CHECK_FILEFORMAT_RELEASE( rStream, SFX_ITEMPOOL_TAG_ENDPOOL, pNewArr );
864cdf0e10cSrcweir             CHECK_FILEFORMAT_RELEASE( rStream, SFX_ITEMPOOL_TAG_ENDPOOL, pNewArr );
865cdf0e10cSrcweir 
866cdf0e10cSrcweir 			// Sekund"arpool einlesen
867cdf0e10cSrcweir 			pSecondary->Load1_Impl( rStream );
868cdf0e10cSrcweir 			bSecondaryLoaded = sal_True;
869cdf0e10cSrcweir 			nSecondaryEnd = rStream.Tell();
870cdf0e10cSrcweir 
871cdf0e10cSrcweir 			// zur"uck zu unseren eigenen Items
872cdf0e10cSrcweir 			rStream.Seek(nLastPos);
873cdf0e10cSrcweir 		}
874cdf0e10cSrcweir 
875cdf0e10cSrcweir 		// Items an sich lesen
876cdf0e10cSrcweir 		for ( sal_uInt16 j = 0; j < nCount; ++j )
877cdf0e10cSrcweir 		{
878cdf0e10cSrcweir 			sal_uLong nPos = nLastPos;
879cdf0e10cSrcweir 			rStream >> nRef;
880cdf0e10cSrcweir 
881cdf0e10cSrcweir 			if ( bKnownItem )
882cdf0e10cSrcweir 			{
883cdf0e10cSrcweir 				SfxPoolItem *pItem = 0;
884cdf0e10cSrcweir 				if ( nRef )
885cdf0e10cSrcweir 				{
886cdf0e10cSrcweir 					pItem = pDefItem->Create(rStream, nVersion);
887cdf0e10cSrcweir 
888cdf0e10cSrcweir 					if ( !bPersistentRefCounts )
889cdf0e10cSrcweir 						// bis <SfxItemPool::LoadCompleted()> festhalten
890cdf0e10cSrcweir 						AddRef(*pItem, 1);
891cdf0e10cSrcweir 					else
892cdf0e10cSrcweir 					{
893cdf0e10cSrcweir 						if ( nRef > SFX_ITEMS_OLD_MAXREF )
894cdf0e10cSrcweir 							pItem->SetKind( nRef );
895cdf0e10cSrcweir 						else
896cdf0e10cSrcweir 							AddRef(*pItem, nRef);
897cdf0e10cSrcweir 					}
898cdf0e10cSrcweir 				}
899cdf0e10cSrcweir 				//pNewArr->insert( pItem, j );
900cdf0e10cSrcweir 				pNewArr->push_back( (SfxPoolItem*) pItem );
901cdf0e10cSrcweir 
902cdf0e10cSrcweir 				// restliche gespeicherte Laenge skippen (neueres Format)
903cdf0e10cSrcweir 				nLastPos = rStream.Tell();
904cdf0e10cSrcweir 			}
905cdf0e10cSrcweir 
906cdf0e10cSrcweir 			aSizeTable >> nAttrSize;
907cdf0e10cSrcweir 			SFX_ASSERT( !bKnownItem || ( nPos + nAttrSize) >= nLastPos,
908cdf0e10cSrcweir 						nPos,
909cdf0e10cSrcweir 						"too many bytes read - version mismatch?" );
910cdf0e10cSrcweir 
911cdf0e10cSrcweir 			if ( !bKnownItem || ( nLastPos < (nPos + nAttrSize) ) )
912cdf0e10cSrcweir 			{
913cdf0e10cSrcweir 				nLastPos = nPos + nAttrSize;
914cdf0e10cSrcweir 				rStream.Seek( nLastPos );
915cdf0e10cSrcweir 			}
916cdf0e10cSrcweir 		}
917cdf0e10cSrcweir 
918cdf0e10cSrcweir 		if ( bKnownItem )
919cdf0e10cSrcweir 		{
920cdf0e10cSrcweir 			SfxPoolItemArray_Impl *pOldArr = *ppArr;
921cdf0e10cSrcweir 			*ppArr = pNewArr;
922cdf0e10cSrcweir 
923cdf0e10cSrcweir 			// die Items merken, die schon im Pool sind
924cdf0e10cSrcweir 			int bEmpty = sal_True;
925cdf0e10cSrcweir 			if ( 0 != pOldArr )
926cdf0e10cSrcweir 				for ( size_t n = 0; bEmpty && n < pOldArr->size(); ++n )
927cdf0e10cSrcweir 					bEmpty = pOldArr->operator[](n) == 0;
928cdf0e10cSrcweir 			DBG_ASSERTWARNING( bEmpty, "loading non-empty pool" );
929cdf0e10cSrcweir 			if ( !bEmpty )
930cdf0e10cSrcweir 			{
931cdf0e10cSrcweir 				// f"ur alle alten suchen, ob ein gleiches neues existiert
932cdf0e10cSrcweir 				for ( size_t nOld = 0; nOld < pOldArr->size(); ++nOld )
933cdf0e10cSrcweir 				{
934cdf0e10cSrcweir 					SfxPoolItem *pOldItem = (*pOldArr)[nOld];
935cdf0e10cSrcweir 					if ( pOldItem )
936cdf0e10cSrcweir 					{
937cdf0e10cSrcweir 						bool bFound = false;
938cdf0e10cSrcweir 						for ( size_t nNew = 0;
939cdf0e10cSrcweir 							  nNew < (*ppArr)->size();  ++nNew )
940cdf0e10cSrcweir 						{
941cdf0e10cSrcweir 							SfxPoolItem *&rpNewItem =
942cdf0e10cSrcweir 								(SfxPoolItem*&)(*ppArr)->operator[](nNew);
943cdf0e10cSrcweir 
944cdf0e10cSrcweir 							if ( rpNewItem && *rpNewItem == *pOldItem )
945cdf0e10cSrcweir 							{
946cdf0e10cSrcweir 								AddRef( *pOldItem, rpNewItem->GetRefCount() );
947cdf0e10cSrcweir 								SetRefCount( *rpNewItem, 0 );
948cdf0e10cSrcweir 								delete rpNewItem;
949cdf0e10cSrcweir 								rpNewItem = pOldItem;
950cdf0e10cSrcweir 								bFound = true;
951cdf0e10cSrcweir 								SFX_TRACE( "reusing item", pOldItem );
952cdf0e10cSrcweir 								break;
953cdf0e10cSrcweir 							}
954cdf0e10cSrcweir 						}
955cdf0e10cSrcweir 						if ( !bFound )
956cdf0e10cSrcweir                         {
957cdf0e10cSrcweir 							SFX_TRACE( "item not found: ", pOldItem );
958cdf0e10cSrcweir                         }
959cdf0e10cSrcweir 					}
960cdf0e10cSrcweir 				}
961cdf0e10cSrcweir 			}
962cdf0e10cSrcweir 			delete pOldArr; /* @@@ */
963cdf0e10cSrcweir 		}
964cdf0e10cSrcweir 	}
965cdf0e10cSrcweir 
966cdf0e10cSrcweir 	// Pool-Defaults lesen
967cdf0e10cSrcweir 	if ( pImp->nMajorVer > 1 || pImp->nMinorVer > 0 )
968cdf0e10cSrcweir 		CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_DEFAULTS );
969cdf0e10cSrcweir 
970cdf0e10cSrcweir 	sal_uLong nLastPos = rStream.Tell();
971cdf0e10cSrcweir 	while ( rStream >> nWhich, nWhich )
972cdf0e10cSrcweir 	{
973cdf0e10cSrcweir 		// ggf. Which-Id aus alter Version verschieben?
974cdf0e10cSrcweir 		if ( pImp->nLoadingVersion != pImp->nVersion )
975cdf0e10cSrcweir 			nWhich = GetNewWhich( nWhich );
976cdf0e10cSrcweir 
977cdf0e10cSrcweir 		rStream >> nSlot;
978cdf0e10cSrcweir 		sal_uInt16 nMappedWhich = GetWhich(nSlot, sal_False);
979cdf0e10cSrcweir 		int bKnownItem = bOwnPool || IsWhich(nMappedWhich);
980cdf0e10cSrcweir 
981cdf0e10cSrcweir 		sal_uLong nPos = nLastPos;
9826fb30688SEike Rathke 		sal_uInt32 nSize(0);
9836fb30688SEike Rathke 		sal_uInt16 nVersion(0);
984cdf0e10cSrcweir 		rStream >> nVersion;
985cdf0e10cSrcweir 
986cdf0e10cSrcweir 		if ( bKnownItem )
987cdf0e10cSrcweir 		{
988cdf0e10cSrcweir 			if ( !bOwnPool )
989cdf0e10cSrcweir 				nWhich = nMappedWhich;
990cdf0e10cSrcweir 			SfxPoolItem *pItem =
991cdf0e10cSrcweir 				( *( ppStaticDefaults + GetIndex_Impl(nWhich) ) )
992cdf0e10cSrcweir 				->Create( rStream, nVersion );
993cdf0e10cSrcweir 			pItem->SetKind( SFX_ITEMS_POOLDEFAULT );
994cdf0e10cSrcweir 			*( ppPoolDefaults + GetIndex_Impl(nWhich) ) = pItem;
995cdf0e10cSrcweir 		}
996cdf0e10cSrcweir 
997cdf0e10cSrcweir 		nLastPos = rStream.Tell();
998cdf0e10cSrcweir 		aSizeTable >> nSize;
999cdf0e10cSrcweir 		SFX_ASSERT( ( nPos + nSize) >= nLastPos, nPos,
1000cdf0e10cSrcweir 					"too many bytes read - version mismatch?" );
1001cdf0e10cSrcweir 		if ( nLastPos < (nPos + nSize) )
1002cdf0e10cSrcweir 			rStream.Seek( nPos + nSize );
1003cdf0e10cSrcweir 	}
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir 	delete[] pBuf;
1006cdf0e10cSrcweir 	rStream.Seek(nEndOfSizes);
1007cdf0e10cSrcweir 	CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_ENDPOOL );
1008cdf0e10cSrcweir 	CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_ENDPOOL );
1009cdf0e10cSrcweir 
1010cdf0e10cSrcweir 	if ( pSecondary )
1011cdf0e10cSrcweir 	{
1012cdf0e10cSrcweir 		if ( !bSecondaryLoaded )
1013cdf0e10cSrcweir 			pSecondary->Load1_Impl( rStream );
1014cdf0e10cSrcweir 		else
1015cdf0e10cSrcweir 			rStream.Seek( nSecondaryEnd );
1016cdf0e10cSrcweir 	}
1017cdf0e10cSrcweir 
1018cdf0e10cSrcweir 	if ( aExternName != aName )
1019cdf0e10cSrcweir 		aName.Erase();
1020cdf0e10cSrcweir 
1021cdf0e10cSrcweir 	pImp->bStreaming = sal_False;
1022cdf0e10cSrcweir 	return rStream;
1023cdf0e10cSrcweir }
1024cdf0e10cSrcweir 
1025cdf0e10cSrcweir // -----------------------------------------------------------------------
1026cdf0e10cSrcweir 
LoadSurrogate(SvStream & rStream,sal_uInt16 & rWhich,sal_uInt16 nSlotId,const SfxItemPool * pRefPool)1027cdf0e10cSrcweir const SfxPoolItem* SfxItemPool::LoadSurrogate
1028cdf0e10cSrcweir (
1029cdf0e10cSrcweir 	SvStream&			rStream,	// vor einem Surrogat positionierter Stream
1030cdf0e10cSrcweir 	sal_uInt16& 			rWhich, 	// Which-Id des zu ladenden <SfxPoolItem>s
1031cdf0e10cSrcweir 	sal_uInt16				nSlotId,	// Slot-Id des zu ladenden <SfxPoolItem>s
1032cdf0e10cSrcweir 	const SfxItemPool*	pRefPool	// <SfxItemPool> in dem das Surrogat gilt
1033cdf0e10cSrcweir )
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir /*	[Beschreibung]
1036cdf0e10cSrcweir 
1037cdf0e10cSrcweir 	L"adt Surrogat aus 'rStream' und liefert das dadurch in 'rRefPool'
1038cdf0e10cSrcweir 	repr"asentierte SfxPoolItem zu"ruck. Ist das im Stream befindliche
1039cdf0e10cSrcweir 	Surrogat == SFX_ITEMS_DIRECT (!SFX_ITEM_POOLABLE) wird 0 zur"uckgegeben,
1040cdf0e10cSrcweir 	das Item ist direkt aus dem Stream zu laden. Bei 0xfffffff0 (SFX_ITEMS_NULL)
1041cdf0e10cSrcweir 	wird auch 0 zurueckgegeben und rWhich auf 0 gesetzt, das Item ist nicht
1042cdf0e10cSrcweir 	verfuegbar.
1043cdf0e10cSrcweir 
1044cdf0e10cSrcweir 	Ansonsten wird ber"ucksichtigt, ob der betroffene Pool ohne Ref-Counts
1045cdf0e10cSrcweir 	geladen wird, ob aus einem neuen Pool nachgeladen wird (&rRefPool != this)
1046cdf0e10cSrcweir 	oder ob aus einem g"anzlich anders aufgebauten Pool geladen wird.
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir 	Wird aus einem anders aufgebauten Pool geladen und die 'nSlotId' kann
1049cdf0e10cSrcweir 	nicht in eine Which-Id dieses Pools gemappt werden, wird ebenfalls 0
1050cdf0e10cSrcweir 	zur"uckgeliefert.
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir 	Preconditions:	- Pool mu\s geladen sein
1053cdf0e10cSrcweir 					- LoadCompleted darf noch nicht gerufen worden sein
1054cdf0e10cSrcweir 					- 'rStream' steht genau an der Position, an der ein
1055cdf0e10cSrcweir 					  Surrogat f"ur ein Item mit der SlotId 'nSlotId' und
1056cdf0e10cSrcweir 					  der WhichId 'rWhichId' mit StoreSurrogate gepeichert
1057cdf0e10cSrcweir 					  wurde
1058cdf0e10cSrcweir 
1059cdf0e10cSrcweir 	Postconditions:	- 'rStream' ist so positioniert, wie auch StoreSurrogate
1060cdf0e10cSrcweir 					  sein speichern beendet hatte
1061cdf0e10cSrcweir 					- konnte ein Item geladen werden, befindet es sich
1062cdf0e10cSrcweir 					  in diesem SfxItemPool
1063cdf0e10cSrcweir 					- 'rWhichId' enth"alt die ggf. gemappte Which-Id
1064cdf0e10cSrcweir 	Laufzeit:       Tiefe des Ziel Sekund"arpools * 10 + 10
1065cdf0e10cSrcweir 
1066cdf0e10cSrcweir 	[Querverweise]
1067cdf0e10cSrcweir 
1068cdf0e10cSrcweir 	<SfxItemPool::StoreSurrogate(SvStream&,const SfxPoolItem &)const>
1069cdf0e10cSrcweir */
1070cdf0e10cSrcweir 
1071cdf0e10cSrcweir {
1072cdf0e10cSrcweir 	// Read the first surrogate
10736fb30688SEike Rathke 	sal_uInt32 nSurrogat(0);
1074cdf0e10cSrcweir 	rStream >> nSurrogat;
1075cdf0e10cSrcweir 
1076cdf0e10cSrcweir 	// Is item stored directly?
1077cdf0e10cSrcweir 	if ( SFX_ITEMS_DIRECT == nSurrogat )
1078cdf0e10cSrcweir 		return 0;
1079cdf0e10cSrcweir 
1080cdf0e10cSrcweir 	// Item does not exist?
1081cdf0e10cSrcweir 	if ( SFX_ITEMS_NULL == nSurrogat )
1082cdf0e10cSrcweir 	{
1083cdf0e10cSrcweir 		rWhich = 0;
1084cdf0e10cSrcweir 		return 0;
1085cdf0e10cSrcweir 	}
1086cdf0e10cSrcweir 
1087cdf0e10cSrcweir 	// Bei einem identisch aufgebauten Pool (im Stream) kann das Surrogat
1088cdf0e10cSrcweir 	// auf jeden Fall aufgel"ost werden.
1089cdf0e10cSrcweir 	if ( !pRefPool )
1090cdf0e10cSrcweir 		pRefPool = this;
1091cdf0e10cSrcweir 	FASTBOOL bResolvable = pRefPool->GetName().Len() > 0;
1092cdf0e10cSrcweir 	if ( !bResolvable )
1093cdf0e10cSrcweir 	{
1094cdf0e10cSrcweir 		// Bei einem anders aufgebauten Pool im Stream, mu\s die SlotId
1095cdf0e10cSrcweir 		// aus dem Stream in eine Which-Id gemappt werden k"onnen.
1096cdf0e10cSrcweir 		sal_uInt16 nMappedWhich = nSlotId ? GetWhich(nSlotId, sal_True) : 0;
1097cdf0e10cSrcweir 		if ( IsWhich(nMappedWhich) )
1098cdf0e10cSrcweir 		{
1099cdf0e10cSrcweir 			// gemappte SlotId kann "ubernommen werden
1100cdf0e10cSrcweir 			rWhich = nMappedWhich;
1101cdf0e10cSrcweir 			bResolvable = sal_True;
1102cdf0e10cSrcweir 		}
1103cdf0e10cSrcweir 	}
1104cdf0e10cSrcweir 
1105cdf0e10cSrcweir 	// kann Surrogat aufgel"ost werden?
1106cdf0e10cSrcweir 	const SfxPoolItem *pItem = 0;
1107cdf0e10cSrcweir 	if ( bResolvable )
1108cdf0e10cSrcweir 	{
1109cdf0e10cSrcweir 		for ( SfxItemPool *pTarget = this; pTarget; pTarget = pTarget->pSecondary )
1110cdf0e10cSrcweir 		{
1111cdf0e10cSrcweir 			// richtigen (Folge-) Pool gefunden?
1112cdf0e10cSrcweir 			if ( pTarget->IsInRange(rWhich) )
1113cdf0e10cSrcweir 			{
1114cdf0e10cSrcweir 				// dflt-Attribut?
1115cdf0e10cSrcweir 				if ( SFX_ITEMS_DEFAULT == nSurrogat )
1116cdf0e10cSrcweir 					return *(pTarget->ppStaticDefaults +
1117cdf0e10cSrcweir 							pTarget->GetIndex_Impl(rWhich));
1118cdf0e10cSrcweir 
1119cdf0e10cSrcweir 				SfxPoolItemArray_Impl* pItemArr = *(pTarget->pImp->ppPoolItems +
1120cdf0e10cSrcweir 						pTarget->GetIndex_Impl(rWhich));
1121cdf0e10cSrcweir 				pItem = pItemArr && nSurrogat < pItemArr->size()
1122cdf0e10cSrcweir 							? (*pItemArr)[nSurrogat]
1123cdf0e10cSrcweir 							: 0;
1124cdf0e10cSrcweir 				if ( !pItem )
1125cdf0e10cSrcweir 				{
1126cdf0e10cSrcweir 					DBG_ERROR( "can't resolve surrogate" );
1127cdf0e10cSrcweir 					rWhich = 0; // nur zur Sicherheit fuer richtige Stream-Pos
1128cdf0e10cSrcweir 					return 0;
1129cdf0e10cSrcweir 				}
1130cdf0e10cSrcweir 
1131cdf0e10cSrcweir 				// Nachladen aus Ref-Pool?
1132cdf0e10cSrcweir 				if ( pRefPool != pMaster )
1133cdf0e10cSrcweir 					return &pTarget->Put( *pItem );
1134cdf0e10cSrcweir 
1135cdf0e10cSrcweir 				// Referenzen sind NICHT schon mit Pool geladen worden?
1136cdf0e10cSrcweir 				if ( !pTarget->HasPersistentRefCounts() )
1137cdf0e10cSrcweir 					AddRef( *pItem, 1 );
1138cdf0e10cSrcweir 				else
1139cdf0e10cSrcweir 					return pItem;
1140cdf0e10cSrcweir 
1141cdf0e10cSrcweir 				return pItem;
1142cdf0e10cSrcweir 			}
1143cdf0e10cSrcweir 		}
1144cdf0e10cSrcweir 
1145cdf0e10cSrcweir 		SFX_ASSERT( sal_False, rWhich, "can't resolve Which-Id in LoadSurrogate" );
1146cdf0e10cSrcweir 	}
1147cdf0e10cSrcweir 
1148cdf0e10cSrcweir 	return 0;
1149cdf0e10cSrcweir }
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir //-------------------------------------------------------------------------
1152cdf0e10cSrcweir 
1153cdf0e10cSrcweir 
StoreSurrogate(SvStream & rStream,const SfxPoolItem * pItem) const1154cdf0e10cSrcweir FASTBOOL SfxItemPool::StoreSurrogate
1155cdf0e10cSrcweir (
1156cdf0e10cSrcweir 	SvStream&			rStream,
1157cdf0e10cSrcweir 	const SfxPoolItem* 	pItem
1158cdf0e10cSrcweir )	const
1159cdf0e10cSrcweir 
1160cdf0e10cSrcweir /*	[Beschreibung]
1161cdf0e10cSrcweir 
1162cdf0e10cSrcweir 	Speichert ein Surrogat f"ur '*pItem' in 'rStream'.
1163cdf0e10cSrcweir 
1164cdf0e10cSrcweir 
1165cdf0e10cSrcweir 	[R"uckgabewert]
1166cdf0e10cSrcweir 
1167cdf0e10cSrcweir 	FASTBOOL				sal_True
1168cdf0e10cSrcweir 							es wurde ein echtes Surrogat gespeichert, auch
1169cdf0e10cSrcweir 							SFX_ITEMS_NULL bei 'pItem==0',
1170cdf0e10cSrcweir 							SFX_ITEMS_STATICDEFAULT und SFX_ITEMS_POOLDEFAULT
1171cdf0e10cSrcweir 							gelten als 'echte' Surrogate
1172cdf0e10cSrcweir 
1173cdf0e10cSrcweir 							sal_False
1174cdf0e10cSrcweir 							es wurde ein Dummy-Surrogat (SFX_ITEMS_DIRECT)
1175cdf0e10cSrcweir 							gespeichert, das eigentliche Item mu\s direkt
1176cdf0e10cSrcweir 							hinterher selbst gespeichert werden
1177cdf0e10cSrcweir */
1178cdf0e10cSrcweir 
1179cdf0e10cSrcweir {
1180cdf0e10cSrcweir 	if ( pItem )
1181cdf0e10cSrcweir 	{
1182cdf0e10cSrcweir 		FASTBOOL bRealSurrogate = IsItemFlag(*pItem, SFX_ITEM_POOLABLE);
1183cdf0e10cSrcweir 		rStream << ( bRealSurrogate
1184cdf0e10cSrcweir 						? GetSurrogate( pItem )
1185cdf0e10cSrcweir 						: SFX_ITEMS_DIRECT );
1186cdf0e10cSrcweir 		return bRealSurrogate;
1187cdf0e10cSrcweir 	}
1188cdf0e10cSrcweir 
1189cdf0e10cSrcweir     rStream << SFX_ITEMS_NULL;
1190cdf0e10cSrcweir 	return sal_True;
1191cdf0e10cSrcweir }
1192cdf0e10cSrcweir 
1193cdf0e10cSrcweir // -----------------------------------------------------------------------
1194cdf0e10cSrcweir 
GetSurrogate(const SfxPoolItem * pItem) const1195cdf0e10cSrcweir sal_uInt32 SfxItemPool::GetSurrogate(const SfxPoolItem *pItem) const
1196cdf0e10cSrcweir {
1197cdf0e10cSrcweir 	DBG_CHKTHIS(SfxItemPool, 0);
1198cdf0e10cSrcweir 	DBG_ASSERT( pItem, "no 0-Pointer Surrogate" );
1199cdf0e10cSrcweir 	DBG_ASSERT( !IsInvalidItem(pItem), "no Invalid-Item Surrogate" );
1200cdf0e10cSrcweir 	DBG_ASSERT( !IsPoolDefaultItem(pItem), "no Pool-Default-Item Surrogate" );
1201cdf0e10cSrcweir 
1202cdf0e10cSrcweir 	if ( !IsInRange(pItem->Which()) )
1203cdf0e10cSrcweir 	{
1204cdf0e10cSrcweir 		if ( pSecondary )
1205cdf0e10cSrcweir 			return pSecondary->GetSurrogate( pItem );
1206cdf0e10cSrcweir 		SFX_ASSERT( 0, pItem->Which(), "unknown Which-Id - dont ask me for surrogates" );
1207cdf0e10cSrcweir 	}
1208cdf0e10cSrcweir 
1209cdf0e10cSrcweir 	// Pointer auf static- oder pool-dflt-Attribut?
1210cdf0e10cSrcweir 	if( IsStaticDefaultItem(pItem) || IsPoolDefaultItem(pItem) )
1211cdf0e10cSrcweir 		return SFX_ITEMS_DEFAULT;
1212cdf0e10cSrcweir 
1213cdf0e10cSrcweir 	SfxPoolItemArray_Impl* pItemArr = *(pImp->ppPoolItems + GetIndex_Impl(pItem->Which()));
1214cdf0e10cSrcweir 	DBG_ASSERT(pItemArr, "ItemArr is not available");
1215cdf0e10cSrcweir 
1216cdf0e10cSrcweir 	for ( size_t i = 0; i < pItemArr->size(); ++i )
1217cdf0e10cSrcweir 	{
1218cdf0e10cSrcweir 		const SfxPoolItem *p = (*pItemArr)[i];
1219cdf0e10cSrcweir 		if ( p == pItem )
1220cdf0e10cSrcweir 			return i;
1221cdf0e10cSrcweir 	}
1222cdf0e10cSrcweir 	SFX_ASSERT( 0, pItem->Which(), "Item not in the pool");
1223cdf0e10cSrcweir 	return SFX_ITEMS_NULL;
1224cdf0e10cSrcweir }
1225cdf0e10cSrcweir 
1226cdf0e10cSrcweir // -----------------------------------------------------------------------
1227cdf0e10cSrcweir 
IsInStoringRange(sal_uInt16 nWhich) const1228cdf0e10cSrcweir FASTBOOL SfxItemPool::IsInStoringRange( sal_uInt16 nWhich ) const
1229cdf0e10cSrcweir {
1230cdf0e10cSrcweir 	return nWhich >= pImp->nStoringStart &&
1231cdf0e10cSrcweir 		   nWhich <= pImp->nStoringEnd;
1232cdf0e10cSrcweir }
1233cdf0e10cSrcweir 
1234cdf0e10cSrcweir //------------------------------------------------------------------------
1235cdf0e10cSrcweir 
SetStoringRange(sal_uInt16 nFrom,sal_uInt16 nTo)1236cdf0e10cSrcweir void SfxItemPool::SetStoringRange( sal_uInt16 nFrom, sal_uInt16 nTo )
1237cdf0e10cSrcweir 
1238cdf0e10cSrcweir /*	[Beschreibung]
1239cdf0e10cSrcweir 
1240cdf0e10cSrcweir 	Mit dieser Methode kann der Which-Bereich eingeengt werden, der
1241cdf0e10cSrcweir 	von ItemSets dieses Pool (und dem Pool selbst) gespeichert wird.
1242cdf0e10cSrcweir 	Die Methode muss dazu vor <SfxItemPool::Store()> gerufen werden
1243cdf0e10cSrcweir 	und die Werte muessen auch noch gesetzt sein, wenn das eigentliche
1244cdf0e10cSrcweir 	Dokument (also die ItemSets gespeicher werden).
1245cdf0e10cSrcweir 
1246cdf0e10cSrcweir 	Ein Zuruecksetzen ist dann nicht noetig, wenn dieser Range vor
1247cdf0e10cSrcweir 	JEDEM Speichern richtig gesetzt wird, da er nur beim Speichern
1248cdf0e10cSrcweir 	beruecksichtigt wird.
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir 	Dieses muss fuer das 3.1-Format gemacht werden, da dort eine
1251cdf0e10cSrcweir 	Bug in der Pool-Lade-Methode vorliegt.
1252cdf0e10cSrcweir */
1253cdf0e10cSrcweir 
1254cdf0e10cSrcweir {
1255cdf0e10cSrcweir 	pImp->nStoringStart = nFrom;
1256cdf0e10cSrcweir 	pImp->nStoringEnd = nTo;
1257cdf0e10cSrcweir }
1258cdf0e10cSrcweir 
1259cdf0e10cSrcweir // -----------------------------------------------------------------------
1260cdf0e10cSrcweir 
SetVersionMap(sal_uInt16 nVer,sal_uInt16 nOldStart,sal_uInt16 nOldEnd,sal_uInt16 * pOldWhichIdTab)1261cdf0e10cSrcweir void SfxItemPool::SetVersionMap
1262cdf0e10cSrcweir (
1263cdf0e10cSrcweir 	sal_uInt16 	nVer, 				/* 	neue Versionsnummer */
1264cdf0e10cSrcweir 	sal_uInt16  nOldStart,          /*  alte erste Which-Id */
1265cdf0e10cSrcweir 	sal_uInt16  nOldEnd,            /*  alte letzte Which-Id */
1266cdf0e10cSrcweir 	sal_uInt16*	pOldWhichIdTab		/* 	Array mit genau dem Aufbau der Which-Ids
1267cdf0e10cSrcweir 									der vorhergehenden Version, in denen
1268cdf0e10cSrcweir 									die jeweils neue Which-Id steht. */
1269cdf0e10cSrcweir )
1270cdf0e10cSrcweir 
1271cdf0e10cSrcweir /*	[Beschreibung]
1272cdf0e10cSrcweir 
1273cdf0e10cSrcweir 	Mit dieser Methode k"onnen neue, inkompatible Which-Id-Folgen oder
1274cdf0e10cSrcweir 	Verteilungen realisiert werden. Pools, die noch mit alten Versionen
1275cdf0e10cSrcweir 	gespeichert wurden, werden dann "uber die angegebene Tabelle solange
1276cdf0e10cSrcweir 	gemappt, bis die aktuelle Version erreicht ist. Neuere Pools k"onnen
1277cdf0e10cSrcweir 	unter Verlust neuer Attribute geladen werden, da die Map mit dem Pool
1278cdf0e10cSrcweir 	gespeichert wird.
1279cdf0e10cSrcweir 
1280cdf0e10cSrcweir 	Precondition:	Pool darf noch nicht geladen sein
1281cdf0e10cSrcweir 	Postcondition:	Which-Ids aus fr"uheren Versionen k"onnen bei Laden auf
1282cdf0e10cSrcweir 					Version 'nVer' gemappt werden
1283cdf0e10cSrcweir 	Laufzeit:       1.5 * new + 10
1284cdf0e10cSrcweir 
1285cdf0e10cSrcweir 	[Anmerkung]
1286cdf0e10cSrcweir 
1287cdf0e10cSrcweir 	F"ur neue Which-Ranges (nStart,nEnd) m"ssen im Vergleich zur Vorg"anger-
1288cdf0e10cSrcweir 	Version (nOldStart,nOldEnd) immer gelten, da\s (nOldStart,nOldEnd)
1289cdf0e10cSrcweir 	vollst"andig in (nStart,nEnd) enthalten ist. Es ist also zul"assig, den
1290cdf0e10cSrcweir 	Which-Range in beide Richtungen zu erweitern, auch durch Einf"ugung
1291cdf0e10cSrcweir 	von Which-Ids, nicht aber ihn zu beschneiden.
1292cdf0e10cSrcweir 
1293cdf0e10cSrcweir 	Diese Methode sollte nur im oder direkt nach Aufruf des Konstruktors
1294cdf0e10cSrcweir 	gerufen werden.
1295cdf0e10cSrcweir 
1296cdf0e10cSrcweir 	Das Array mu\s statisch sein, da es nicht kopiert wird und au\serdem
1297cdf0e10cSrcweir 	im Copy-Ctor des SfxItemPool wiederverwendet wird.
1298cdf0e10cSrcweir 
1299cdf0e10cSrcweir 
1300cdf0e10cSrcweir 	[Beispiel]
1301cdf0e10cSrcweir 
1302cdf0e10cSrcweir 	Urspr"unglich (Version 0) hatte der Pool folgende Which-Ids:
1303cdf0e10cSrcweir 
1304cdf0e10cSrcweir 		1:A, 2:B, 3:C, 4:D
1305cdf0e10cSrcweir 
1306cdf0e10cSrcweir 	Nun soll eine neue Version (Version 1) zwei zus"atzliche Ids X und Y
1307cdf0e10cSrcweir 	zwischen B und C erhalten, also wie folgt aussehen:
1308cdf0e10cSrcweir 
1309cdf0e10cSrcweir 		1:A, 2:B, 3:X, 4:Y, 5:C, 6:D
1310cdf0e10cSrcweir 
1311cdf0e10cSrcweir 	Dabei haben sich also die Ids 3 und 4 ge"andert. F"ur die neue Version
1312cdf0e10cSrcweir 	m"u\ste am Pool folgendes gesetzt werden:
1313cdf0e10cSrcweir 
1314cdf0e10cSrcweir 		static sal_uInt16 nVersion1Map = { 1, 2, 5, 6 };
1315cdf0e10cSrcweir 		pPool->SetVersionMap( 1, 1, 4, &nVersion1Map );
1316cdf0e10cSrcweir 
1317cdf0e10cSrcweir 
1318cdf0e10cSrcweir 	[Querverweise]
1319cdf0e10cSrcweir 
1320cdf0e10cSrcweir 	<SfxItemPool::IsLoadingVersionCurrent()const>
1321cdf0e10cSrcweir 	<SfxItemPool::GetNewWhich(sal_uInt16)>
1322cdf0e10cSrcweir 	<SfxItemPool::GetVersion()const>
1323cdf0e10cSrcweir 	<SfxItemPool::GetLoadingVersion()const>
1324cdf0e10cSrcweir */
1325cdf0e10cSrcweir 
1326cdf0e10cSrcweir {
1327cdf0e10cSrcweir 	// create new map entry to insert
1328cdf0e10cSrcweir 	const SfxPoolVersion_ImplPtr pVerMap = SfxPoolVersion_ImplPtr( new SfxPoolVersion_Impl(
1329cdf0e10cSrcweir 				nVer, nOldStart, nOldEnd, pOldWhichIdTab ) );
1330cdf0e10cSrcweir 	pImp->aVersions.push_back( pVerMap );
1331cdf0e10cSrcweir 
1332cdf0e10cSrcweir 	DBG_ASSERT( nVer > pImp->nVersion, "Versions not sorted" );
1333cdf0e10cSrcweir 	pImp->nVersion = nVer;
1334cdf0e10cSrcweir 
1335cdf0e10cSrcweir 	// Versions-Range anpassen
1336cdf0e10cSrcweir 	for ( sal_uInt16 n = 0; n < nOldEnd-nOldStart+1; ++n )
1337cdf0e10cSrcweir 	{
1338cdf0e10cSrcweir 		sal_uInt16 nWhich = pOldWhichIdTab[n];
1339cdf0e10cSrcweir 		if ( nWhich < pImp->nVerStart )
1340cdf0e10cSrcweir 		{
1341cdf0e10cSrcweir 			if ( !nWhich )
1342cdf0e10cSrcweir 				nWhich = 0;
1343cdf0e10cSrcweir 			pImp->nVerStart = nWhich;
1344cdf0e10cSrcweir 		}
1345cdf0e10cSrcweir 		else if ( nWhich > pImp->nVerEnd )
1346cdf0e10cSrcweir 			pImp->nVerEnd = nWhich;
1347cdf0e10cSrcweir 	}
1348cdf0e10cSrcweir }
1349cdf0e10cSrcweir 
1350cdf0e10cSrcweir // -----------------------------------------------------------------------
1351cdf0e10cSrcweir 
GetNewWhich(sal_uInt16 nFileWhich) const1352cdf0e10cSrcweir sal_uInt16 SfxItemPool::GetNewWhich
1353cdf0e10cSrcweir (
1354cdf0e10cSrcweir 	sal_uInt16	nFileWhich		// die aus dem Stream geladene Which-Id
1355cdf0e10cSrcweir )	const
1356cdf0e10cSrcweir 
1357cdf0e10cSrcweir /*	[Beschreibung]
1358cdf0e10cSrcweir 
1359cdf0e10cSrcweir 	Diese Methoden rechnet Which-Ids aus einem File-Format in die der
1360cdf0e10cSrcweir 	aktuellen Pool-Version um. Ist das File-Format "alter, werden die vom
1361cdf0e10cSrcweir 	Pool-Entwickler mit SetVersion() gesetzten Tabellen verwendet,
1362cdf0e10cSrcweir 	ist das File-Format neuer, dann die aus dem File geladenen Tabellen.
1363cdf0e10cSrcweir 	Im letzteren Fall kann ggf. nicht jede Which-Id gemappt werden,
1364cdf0e10cSrcweir 	so da\s 0 zur"uckgeliefert wird.
1365cdf0e10cSrcweir 
1366cdf0e10cSrcweir 	Die Berechnung ist nur f"ur Which-Ids definiert, die in der betreffenden
1367cdf0e10cSrcweir 	File-Version unterst"utzt wurden. Dies ist per Assertion abgesichert.
1368cdf0e10cSrcweir 
1369cdf0e10cSrcweir 	Precondition:	Pool mu\s geladen sein
1370cdf0e10cSrcweir 	Postcondition:	unver"andert
1371cdf0e10cSrcweir 	Laufzeit:		linear(Anzahl der Sekund"arpools) +
1372cdf0e10cSrcweir 					linear(Differenz zwischen alter und neuer Version)
1373cdf0e10cSrcweir 
1374cdf0e10cSrcweir 
1375cdf0e10cSrcweir 	[Querverweise]
1376cdf0e10cSrcweir 
1377cdf0e10cSrcweir 	<SfxItemPool::IsLoadingVersionCurrent()const>
1378cdf0e10cSrcweir 	<SfxItemPool::SetVersionMap(sal_uInt16,sal_uInt16,sal_uInt16,sal_uInt16*)>
1379cdf0e10cSrcweir 	<SfxItemPool::GetVersion()const>
1380cdf0e10cSrcweir 	<SfxItemPool::GetLoadingVersion()const>
1381cdf0e10cSrcweir */
1382cdf0e10cSrcweir 
1383cdf0e10cSrcweir {
1384cdf0e10cSrcweir 	// (Sekund"ar-) Pool bestimmen
1385cdf0e10cSrcweir 	if ( !IsInVersionsRange(nFileWhich) )
1386cdf0e10cSrcweir 	{
1387cdf0e10cSrcweir 		if ( pSecondary )
1388cdf0e10cSrcweir 			return pSecondary->GetNewWhich( nFileWhich );
1389cdf0e10cSrcweir 		SFX_ASSERT( 0, nFileWhich, "unknown which in GetNewWhich()" );
1390cdf0e10cSrcweir 	}
1391cdf0e10cSrcweir 
1392cdf0e10cSrcweir 	// Version neuer/gleich/"alter?
1393cdf0e10cSrcweir 	short nDiff = (short)pImp->nLoadingVersion - (short)pImp->nVersion;
1394cdf0e10cSrcweir 
1395cdf0e10cSrcweir 	// Which-Id einer neueren Version?
1396cdf0e10cSrcweir 	if ( nDiff > 0 )
1397cdf0e10cSrcweir 	{
1398cdf0e10cSrcweir 		// von der Top-Version bis runter zur File-Version stufenweise mappen
1399cdf0e10cSrcweir 		for ( size_t nMap = pImp->aVersions.size(); nMap > 0; --nMap )
1400cdf0e10cSrcweir 		{
1401cdf0e10cSrcweir 			SfxPoolVersion_ImplPtr pVerInfo = pImp->aVersions[nMap-1];
1402cdf0e10cSrcweir 			if ( pVerInfo->_nVer > pImp->nVersion )
1403cdf0e10cSrcweir 			{	sal_uInt16 nOfs;
1404cdf0e10cSrcweir 				sal_uInt16 nCount = pVerInfo->_nEnd - pVerInfo->_nStart + 1;
1405cdf0e10cSrcweir 				for ( nOfs = 0;
1406cdf0e10cSrcweir 					  nOfs <= nCount &&
1407cdf0e10cSrcweir 						pVerInfo->_pMap[nOfs] != nFileWhich;
1408cdf0e10cSrcweir 					  ++nOfs )
1409cdf0e10cSrcweir 					continue;
1410cdf0e10cSrcweir 
1411cdf0e10cSrcweir 				if ( pVerInfo->_pMap[nOfs] == nFileWhich )
1412cdf0e10cSrcweir 					nFileWhich = pVerInfo->_nStart + nOfs;
1413cdf0e10cSrcweir 				else
1414cdf0e10cSrcweir 					return 0;
1415cdf0e10cSrcweir 			}
1416cdf0e10cSrcweir 			else
1417cdf0e10cSrcweir 				break;
1418cdf0e10cSrcweir 		}
1419cdf0e10cSrcweir 	}
1420cdf0e10cSrcweir 
1421cdf0e10cSrcweir 	// Which-Id einer neueren Version?
1422cdf0e10cSrcweir 	else if ( nDiff < 0 )
1423cdf0e10cSrcweir 	{
1424cdf0e10cSrcweir 		// von der File-Version bis zur aktuellen Version stufenweise mappen
1425cdf0e10cSrcweir 		for ( size_t nMap = 0; nMap < pImp->aVersions.size(); ++nMap )
1426cdf0e10cSrcweir 		{
1427cdf0e10cSrcweir 			SfxPoolVersion_ImplPtr pVerInfo = pImp->aVersions[nMap];
1428cdf0e10cSrcweir 			if ( pVerInfo->_nVer > pImp->nLoadingVersion )
1429cdf0e10cSrcweir 			{
1430cdf0e10cSrcweir 				DBG_ASSERT( nFileWhich >= pVerInfo->_nStart &&
1431cdf0e10cSrcweir 							nFileWhich <= pVerInfo->_nEnd,
1432cdf0e10cSrcweir 							"which-id unknown in version" );
1433cdf0e10cSrcweir 				nFileWhich = pVerInfo->_pMap[nFileWhich - pVerInfo->_nStart];
1434cdf0e10cSrcweir 			}
1435cdf0e10cSrcweir 		}
1436cdf0e10cSrcweir 	}
1437cdf0e10cSrcweir 
1438cdf0e10cSrcweir 	// originale (nDiff==0) bzw. gemappte (nDiff!=0) Id zur"uckliefern
1439cdf0e10cSrcweir 	return nFileWhich;
1440cdf0e10cSrcweir }
1441cdf0e10cSrcweir 
1442cdf0e10cSrcweir // -----------------------------------------------------------------------
1443cdf0e10cSrcweir 
1444cdf0e10cSrcweir 
IsInVersionsRange(sal_uInt16 nWhich) const1445cdf0e10cSrcweir FASTBOOL SfxItemPool::IsInVersionsRange( sal_uInt16 nWhich ) const
1446cdf0e10cSrcweir {
1447cdf0e10cSrcweir 	return nWhich >= pImp->nVerStart && nWhich <= pImp->nVerEnd;
1448cdf0e10cSrcweir }
1449cdf0e10cSrcweir 
1450cdf0e10cSrcweir // -----------------------------------------------------------------------
1451cdf0e10cSrcweir 
IsCurrentVersionLoading() const1452cdf0e10cSrcweir FASTBOOL SfxItemPool::IsCurrentVersionLoading() const
1453cdf0e10cSrcweir 
1454cdf0e10cSrcweir /*	[Beschreibung]
1455cdf0e10cSrcweir 
1456cdf0e10cSrcweir 	Mit dieser Methode kann festgestellt werden, ob die geladene Pool-Version
1457cdf0e10cSrcweir 	dem aktuellen Pool-Aufbau entspricht.
1458cdf0e10cSrcweir 
1459cdf0e10cSrcweir 	Precondition:	Pool mu\s geladen sein
1460cdf0e10cSrcweir 	Postcondition:	unver"andert
1461cdf0e10cSrcweir 	Laufzeit:		linear(Anzahl der Sekund"arpools)
1462cdf0e10cSrcweir 
1463cdf0e10cSrcweir 
1464cdf0e10cSrcweir 	[Querverweise]
1465cdf0e10cSrcweir 
1466cdf0e10cSrcweir 	<SfxItemPool::SetVersionMap(sal_uInt16,sal_uInt16,sal_uInt16,sal_uInt16*)>
1467cdf0e10cSrcweir 	<SfxItemPool::GetNewWhich(sal_uInt16)const>
1468cdf0e10cSrcweir 	<SfxItemPool::GetVersion()const>
1469cdf0e10cSrcweir 	<SfxItemPool::GetLoadingVersion()const>
1470cdf0e10cSrcweir */
1471cdf0e10cSrcweir 
1472cdf0e10cSrcweir {
1473cdf0e10cSrcweir 	return ( pImp->nVersion == pImp->nLoadingVersion ) &&
1474cdf0e10cSrcweir 		   ( !pSecondary || pSecondary->IsCurrentVersionLoading() );
1475cdf0e10cSrcweir }
1476cdf0e10cSrcweir 
1477cdf0e10cSrcweir // -----------------------------------------------------------------------
1478cdf0e10cSrcweir 
GetVersion() const1479cdf0e10cSrcweir sal_uInt16 SfxItemPool::GetVersion() const
1480cdf0e10cSrcweir 
1481cdf0e10cSrcweir /*	[Beschreibung]
1482cdf0e10cSrcweir 
1483cdf0e10cSrcweir 	Diese Methode liefert die aktuelle Versionsnummer des SfxItemPool-Aufbaus
1484cdf0e10cSrcweir 	(also des Which-Bereichs).
1485cdf0e10cSrcweir 
1486cdf0e10cSrcweir 	Precondition:	keine
1487cdf0e10cSrcweir 	Postcondition:	unver"andert
1488cdf0e10cSrcweir 	Laufzeit:       2
1489cdf0e10cSrcweir 
1490cdf0e10cSrcweir 
1491cdf0e10cSrcweir 	[Anmerkung]
1492cdf0e10cSrcweir 
1493cdf0e10cSrcweir 	Achtung: Es mu\s ggf. die Versionsnummer von Sekund"arpools
1494cdf0e10cSrcweir 	ber"ucksichtigt werden.
1495cdf0e10cSrcweir 
1496cdf0e10cSrcweir 
1497cdf0e10cSrcweir 	[Querverweise]
1498cdf0e10cSrcweir 
1499cdf0e10cSrcweir 	<SfxItemPool::IsLoadingVersionCurrent()const>
1500cdf0e10cSrcweir 	<SfxItemPool::SetVersionMap(sal_uInt16,sal_uInt16,sal_uInt16,sal_uInt16*)>
1501cdf0e10cSrcweir 	<SfxItemPool::GetNewWhich(sal_uInt16)const>
1502cdf0e10cSrcweir 	<SfxItemPool::GetLoadingVersion()const>
1503cdf0e10cSrcweir */
1504cdf0e10cSrcweir 
1505cdf0e10cSrcweir {
1506cdf0e10cSrcweir 	return pImp->nVersion;
1507cdf0e10cSrcweir }
1508cdf0e10cSrcweir 
1509cdf0e10cSrcweir // -----------------------------------------------------------------------
1510cdf0e10cSrcweir 
GetLoadingVersion() const1511cdf0e10cSrcweir sal_uInt16 SfxItemPool::GetLoadingVersion() const
1512cdf0e10cSrcweir 
1513cdf0e10cSrcweir /*	[Beschreibung]
1514cdf0e10cSrcweir 
1515cdf0e10cSrcweir 	Diese Methode liefert die Versionsnummer des SfxItemPool-Aufbaus
1516cdf0e10cSrcweir 	(also des Which-Bereichs), die bei Laden vorgefunden wurde.
1517cdf0e10cSrcweir 
1518cdf0e10cSrcweir 	Precondition:	Pool mu\s geladen sein
1519cdf0e10cSrcweir 	Postcondition:	unver"andert
1520cdf0e10cSrcweir 	Laufzeit:       2
1521cdf0e10cSrcweir 
1522cdf0e10cSrcweir 
1523cdf0e10cSrcweir 	[Anmerkung]
1524cdf0e10cSrcweir 
1525cdf0e10cSrcweir 	Achtung: Es mu\s ggf. die Versionsnummer von Sekund"arpools
1526cdf0e10cSrcweir 	ber"ucksichtigt werden.
1527cdf0e10cSrcweir 
1528cdf0e10cSrcweir 
1529cdf0e10cSrcweir 	[Querverweise]
1530cdf0e10cSrcweir 
1531cdf0e10cSrcweir 	<SfxItemPool::IsLoadingVersionCurrent()const>
1532cdf0e10cSrcweir 	<SfxItemPool::SetVersionMap(sal_uInt16,sal_uInt16,sal_uInt16,sal_uInt16*)>
1533cdf0e10cSrcweir 	<SfxItemPool::GetNewWhich(sal_uInt16)const>
1534cdf0e10cSrcweir 	<SfxItemPool::GetVersion()const>
1535cdf0e10cSrcweir */
1536cdf0e10cSrcweir 
1537cdf0e10cSrcweir {
1538cdf0e10cSrcweir 	return pImp->nLoadingVersion;
1539cdf0e10cSrcweir }
1540cdf0e10cSrcweir 
1541cdf0e10cSrcweir //-------------------------------------------------------------------------
1542cdf0e10cSrcweir 
IsVer2_Impl() const1543cdf0e10cSrcweir FASTBOOL SfxItemPool::IsVer2_Impl() const
1544cdf0e10cSrcweir {
1545cdf0e10cSrcweir 	return pMaster->pImp->nMajorVer >= 2;
1546cdf0e10cSrcweir }
1547cdf0e10cSrcweir 
1548cdf0e10cSrcweir //-------------------------------------------------------------------------
1549cdf0e10cSrcweir 
1550cdf0e10cSrcweir 
StoreItem(SvStream & rStream,const SfxPoolItem & rItem,FASTBOOL bDirect) const1551cdf0e10cSrcweir FASTBOOL SfxItemPool::StoreItem( SvStream &rStream, const SfxPoolItem &rItem,
1552cdf0e10cSrcweir 								 FASTBOOL bDirect ) const
1553cdf0e10cSrcweir 
1554cdf0e10cSrcweir /*	[Beschreibung]
1555cdf0e10cSrcweir 
1556cdf0e10cSrcweir 	Speichert das <SfxPoolItem> 'rItem' in den <SvStream> 'rStream'
1557cdf0e10cSrcweir 	entweder als Surrogat ('bDirect == sal_False') oder direkt mit 'rItem.Store()'.
1558cdf0e10cSrcweir 	Nicht poolable Items werden immer direkt gespeichert. Items ohne Which-Id,
1559cdf0e10cSrcweir 	also SID-Items, werden nicht gespeichert, ebenso wenn Items, die in der
1560cdf0e10cSrcweir 	File-Format-Version noch nicht vorhanden waren (return sal_False).
1561cdf0e10cSrcweir 
1562cdf0e10cSrcweir 	Das Item wird im Stream wie folgt abgelegt:
1563cdf0e10cSrcweir 
1564cdf0e10cSrcweir 	sal_uInt16	rItem.Which()
1565cdf0e10cSrcweir 	sal_uInt16	GetSlotId( rItem.Which() ) bzw. 0 falls nicht verf"urbar
1566cdf0e10cSrcweir 	sal_uInt16	GetSurrogate( &rItem ) bzw. SFX_ITEM_DIRECT bei '!SFX_ITEM_POOLBLE'
1567cdf0e10cSrcweir 
1568cdf0e10cSrcweir 	optional (falls 'bDirect == sal_True' oder '!rItem.IsPoolable()':
1569cdf0e10cSrcweir 
1570cdf0e10cSrcweir 	sal_uInt16  rItem.GetVersion()
1571cdf0e10cSrcweir 	sal_uLong 	Size
1572cdf0e10cSrcweir 	Size    rItem.Store()
1573cdf0e10cSrcweir 
1574cdf0e10cSrcweir 
1575cdf0e10cSrcweir 	[Querverweise]
1576cdf0e10cSrcweir 
1577cdf0e10cSrcweir 	<SfxItemPool::LoadItem(SvStream&,FASTBOOL)const>
1578cdf0e10cSrcweir */
1579cdf0e10cSrcweir 
1580cdf0e10cSrcweir {
1581cdf0e10cSrcweir 	DBG_ASSERT( !IsInvalidItem(&rItem), "cannot store invalid items" );
1582cdf0e10cSrcweir 
1583cdf0e10cSrcweir 	if ( IsSlot( rItem.Which() ) )
1584cdf0e10cSrcweir 		return sal_False;
1585cdf0e10cSrcweir 	const SfxItemPool *pPool = this;
1586cdf0e10cSrcweir 	while ( !pPool->IsInStoringRange(rItem.Which()) )
1587cdf0e10cSrcweir 		if ( 0 == ( pPool = pPool->pSecondary ) )
1588cdf0e10cSrcweir 			return sal_False;
1589cdf0e10cSrcweir 
1590cdf0e10cSrcweir 	DBG_ASSERT( !pImp->bInSetItem || !rItem.ISA(SfxSetItem),
1591cdf0e10cSrcweir 				"SetItem contains ItemSet with SetItem" );
1592cdf0e10cSrcweir 
1593cdf0e10cSrcweir 	sal_uInt16 nSlotId = pPool->GetSlotId( rItem.Which(), sal_True );
1594cdf0e10cSrcweir 	sal_uInt16 nItemVersion = rItem.GetVersion(_nFileFormatVersion);
1595cdf0e10cSrcweir 	if ( USHRT_MAX == nItemVersion )
1596cdf0e10cSrcweir 		return sal_False;
1597cdf0e10cSrcweir 
1598cdf0e10cSrcweir 	rStream << rItem.Which() << nSlotId;
1599cdf0e10cSrcweir 	if ( bDirect || !pPool->StoreSurrogate( rStream, &rItem ) )
1600cdf0e10cSrcweir 	{
1601cdf0e10cSrcweir 		rStream << nItemVersion;
1602cdf0e10cSrcweir 		rStream << (sal_uInt32) 0L; 		  // Platz fuer Laenge in Bytes
1603cdf0e10cSrcweir 		sal_uLong nIStart = rStream.Tell();
1604cdf0e10cSrcweir 		rItem.Store(rStream, nItemVersion);
1605cdf0e10cSrcweir 		sal_uLong nIEnd = rStream.Tell();
1606cdf0e10cSrcweir 		rStream.Seek( nIStart-4 );
1607cdf0e10cSrcweir 		rStream << (sal_Int32) ( nIEnd-nIStart );
1608cdf0e10cSrcweir 		rStream.Seek( nIEnd );
1609cdf0e10cSrcweir 	}
1610cdf0e10cSrcweir 
1611cdf0e10cSrcweir 	return sal_True;
1612cdf0e10cSrcweir }
1613cdf0e10cSrcweir 
1614cdf0e10cSrcweir //-------------------------------------------------------------------------
1615cdf0e10cSrcweir 
1616cdf0e10cSrcweir 
LoadItem(SvStream & rStream,FASTBOOL bDirect,const SfxItemPool * pRefPool)1617cdf0e10cSrcweir const SfxPoolItem* SfxItemPool::LoadItem( SvStream &rStream, FASTBOOL bDirect,
1618cdf0e10cSrcweir 										  const SfxItemPool *pRefPool )
1619cdf0e10cSrcweir 
1620cdf0e10cSrcweir // pRefPool==-1 => nicht putten!
1621cdf0e10cSrcweir 
1622cdf0e10cSrcweir {
16236fb30688SEike Rathke 	sal_uInt16 nWhich(0), nSlot(0); // nSurrogate;
1624cdf0e10cSrcweir 	rStream >> nWhich >> nSlot;
1625cdf0e10cSrcweir 
1626cdf0e10cSrcweir 	sal_Bool bDontPut = (SfxItemPool*)-1 == pRefPool;
1627cdf0e10cSrcweir 	if ( bDontPut || !pRefPool )
1628cdf0e10cSrcweir 		pRefPool = this;
1629cdf0e10cSrcweir 
1630cdf0e10cSrcweir 	// richtigen Sekund"ar-Pool finden
1631cdf0e10cSrcweir 	while ( !pRefPool->IsInVersionsRange(nWhich) )
1632cdf0e10cSrcweir 	{
1633cdf0e10cSrcweir 		if ( pRefPool->pSecondary )
1634cdf0e10cSrcweir 			pRefPool = pRefPool->pSecondary;
1635cdf0e10cSrcweir 		else
1636cdf0e10cSrcweir 		{
1637cdf0e10cSrcweir 			// WID in der Version nicht vorhanden => ueberspringen
16386fb30688SEike Rathke 			sal_uInt32 nSurro(0);
16396fb30688SEike Rathke 			sal_uInt16 nVersion(0), nLen(0);
1640cdf0e10cSrcweir 			rStream >> nSurro;
1641cdf0e10cSrcweir 			if ( SFX_ITEMS_DIRECT == nSurro )
1642cdf0e10cSrcweir 			{
1643cdf0e10cSrcweir 				rStream >> nVersion >> nLen;
1644cdf0e10cSrcweir 				rStream.SeekRel( nLen );
1645cdf0e10cSrcweir 			}
1646cdf0e10cSrcweir 			return 0;
1647cdf0e10cSrcweir 		}
1648cdf0e10cSrcweir 	}
1649cdf0e10cSrcweir 
1650cdf0e10cSrcweir 	// wird eine andere Version geladen?
1651cdf0e10cSrcweir 	FASTBOOL bCurVersion = pRefPool->IsCurrentVersionLoading();
1652cdf0e10cSrcweir 	if ( !bCurVersion )
1653cdf0e10cSrcweir 		// Which-Id auf neue Version mappen
1654cdf0e10cSrcweir 		nWhich = pRefPool->GetNewWhich( nWhich );
1655cdf0e10cSrcweir 
1656cdf0e10cSrcweir 	DBG_ASSERT( !nWhich || !pImp->bInSetItem ||
1657cdf0e10cSrcweir 				!pRefPool->ppStaticDefaults[pRefPool->GetIndex_Impl(nWhich)]->ISA(SfxSetItem),
1658cdf0e10cSrcweir 				"loading SetItem in ItemSet of SetItem" );
1659cdf0e10cSrcweir 
1660cdf0e10cSrcweir 	// soll "uber Surrogat geladen werden?
1661cdf0e10cSrcweir 	const SfxPoolItem *pItem = 0;
1662cdf0e10cSrcweir 	if ( !bDirect )
1663cdf0e10cSrcweir 	{
1664cdf0e10cSrcweir 		// Which-Id in dieser Version bekannt?
1665cdf0e10cSrcweir 		if ( nWhich )
1666cdf0e10cSrcweir 			// Surrogat laden, reagieren falls keins vorhanden
1667cdf0e10cSrcweir 			pItem = LoadSurrogate( rStream, nWhich, nSlot, pRefPool );
1668cdf0e10cSrcweir 		else
1669cdf0e10cSrcweir 			// sonst "uberspringen
1670cdf0e10cSrcweir 			rStream.SeekRel( sizeof(sal_uInt16) );
1671cdf0e10cSrcweir 	}
1672cdf0e10cSrcweir 
1673cdf0e10cSrcweir 	// wird direkt, also nicht "uber Surrogat geladen?
1674cdf0e10cSrcweir 	if ( bDirect || ( nWhich && !pItem ) )
1675cdf0e10cSrcweir 	{
1676cdf0e10cSrcweir 		// bDirekt bzw. nicht IsPoolable() => Item direkt laden
16776fb30688SEike Rathke 		sal_uInt16 nVersion(0);
16786fb30688SEike Rathke 		sal_uInt32 nLen(0);
1679cdf0e10cSrcweir 		rStream >> nVersion >> nLen;
1680cdf0e10cSrcweir 		sal_uLong nIStart = rStream.Tell();
1681cdf0e10cSrcweir 
1682cdf0e10cSrcweir 		// Which-Id in dieser Version bekannt?
1683cdf0e10cSrcweir 		if ( nWhich )
1684cdf0e10cSrcweir 		{
1685cdf0e10cSrcweir 			// Item direkt laden
1686cdf0e10cSrcweir 			SfxPoolItem *pNewItem =
1687cdf0e10cSrcweir 					pRefPool->GetDefaultItem(nWhich).Create(rStream, nVersion);
1688cdf0e10cSrcweir 			if ( bDontPut )
1689cdf0e10cSrcweir 				pItem = pNewItem;
1690cdf0e10cSrcweir 			else
1691cdf0e10cSrcweir 				if ( pNewItem )
1692cdf0e10cSrcweir 				{
1693cdf0e10cSrcweir 					pItem = &Put(*pNewItem);
1694cdf0e10cSrcweir 					delete pNewItem;
1695cdf0e10cSrcweir 				}
1696cdf0e10cSrcweir 				else
1697cdf0e10cSrcweir 					pItem = 0;
1698cdf0e10cSrcweir 			sal_uLong nIEnd = rStream.Tell();
1699cdf0e10cSrcweir 			DBG_ASSERT( nIEnd <= (nIStart+nLen), "read past end of item" );
1700cdf0e10cSrcweir 			if ( (nIStart+nLen) != nIEnd )
1701cdf0e10cSrcweir 				rStream.Seek( nIStart+nLen );
1702cdf0e10cSrcweir 		}
1703cdf0e10cSrcweir 		else
1704cdf0e10cSrcweir 			// Item "uberspringen
1705cdf0e10cSrcweir 			rStream.Seek( nIStart+nLen );
1706cdf0e10cSrcweir 	}
1707cdf0e10cSrcweir 
1708cdf0e10cSrcweir 	return pItem;
1709cdf0e10cSrcweir }
1710cdf0e10cSrcweir 
1711cdf0e10cSrcweir 
1712