xref: /aoo41x/main/svl/source/items/style.cxx (revision 49bd4d4b)
140df464eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
340df464eSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
440df464eSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
540df464eSAndrew Rist  * distributed with this work for additional information
640df464eSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
740df464eSAndrew Rist  * to you under the Apache License, Version 2.0 (the
840df464eSAndrew Rist  * "License"); you may not use this file except in compliance
940df464eSAndrew Rist  * with the License.  You may obtain a copy of the License at
1040df464eSAndrew Rist  *
1140df464eSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1240df464eSAndrew Rist  *
1340df464eSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1440df464eSAndrew Rist  * software distributed under the License is distributed on an
1540df464eSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1640df464eSAndrew Rist  * KIND, either express or implied.  See the License for the
1740df464eSAndrew Rist  * specific language governing permissions and limitations
1840df464eSAndrew Rist  * under the License.
1940df464eSAndrew Rist  *
2040df464eSAndrew Rist  *************************************************************/
2140df464eSAndrew Rist 
2240df464eSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_
28cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #define _SVSTDARR_STRINGS
32cdf0e10cSrcweir #define _SVSTDARR_STRINGSSORTDTOR
33cdf0e10cSrcweir #define _SVSTDARR_BYTESTRINGS
34cdf0e10cSrcweir #define _SVSTDARR_BYTESTRINGSSORTDTOR
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <rtl/uuid.h>
37cdf0e10cSrcweir #include <tools/tenccvt.hxx>
38cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
39cdf0e10cSrcweir #include <unotools/intlwrapper.hxx>
40cdf0e10cSrcweir #include <svl/smplhint.hxx>
41cdf0e10cSrcweir #include <svl/poolitem.hxx>
42cdf0e10cSrcweir #include <svl/itemset.hxx>
43cdf0e10cSrcweir #include <svl/itempool.hxx>
44cdf0e10cSrcweir #include <poolio.hxx>
45cdf0e10cSrcweir #include <svl/filerec.hxx>
46cdf0e10cSrcweir #include <svl/itemiter.hxx>
47cdf0e10cSrcweir #include <svl/style.hxx>
48cdf0e10cSrcweir #include <svl/svstdarr.hxx>
49cdf0e10cSrcweir #include <unotools/syslocale.hxx>
50cdf0e10cSrcweir #include <algorithm>
51cdf0e10cSrcweir 
52cdf0e10cSrcweir #define STYLESTREAM 			"SfxStyleSheets"
53cdf0e10cSrcweir #define STYLESTREAM_VERSION 	sal_uInt16(50)
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #ifdef DBG_UTIL
56cdf0e10cSrcweir class DbgStyleSheetReferences
57cdf0e10cSrcweir {
58cdf0e10cSrcweir public:
DbgStyleSheetReferences()59cdf0e10cSrcweir 	DbgStyleSheetReferences() : mnStyles(0), mnPools(0) {}
~DbgStyleSheetReferences()60cdf0e10cSrcweir 	~DbgStyleSheetReferences()
61cdf0e10cSrcweir 	{
62cdf0e10cSrcweir 		OSL_TRACE("DbgStyleSheetReferences\nSfxStyleSheetBase left %ld\nSfxStyleSheetBasePool left %ld\n", mnStyles, mnPools );
63cdf0e10cSrcweir 	}
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	sal_uInt32 mnStyles;
66cdf0e10cSrcweir 	sal_uInt32 mnPools;
67cdf0e10cSrcweir }
68cdf0e10cSrcweir aDbgStyleSheetReferences;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir #endif
71cdf0e10cSrcweir 
72cdf0e10cSrcweir TYPEINIT0(SfxStyleSheetBase)
73cdf0e10cSrcweir 
74cdf0e10cSrcweir TYPEINIT3(SfxStyleSheet, SfxStyleSheetBase, SfxListener, SfxBroadcaster)
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 
77cdf0e10cSrcweir //=========================================================================
78cdf0e10cSrcweir 
79cdf0e10cSrcweir TYPEINIT1(SfxStyleSheetHint, SfxHint);
80cdf0e10cSrcweir TYPEINIT1(SfxStyleSheetHintExtended, SfxStyleSheetHint);
81cdf0e10cSrcweir TYPEINIT1(SfxStyleSheetPoolHint, SfxHint);
82cdf0e10cSrcweir 
SfxStyleSheetHintExtended(sal_uInt16 nAction,const String & rOldName)83cdf0e10cSrcweir SfxStyleSheetHintExtended::SfxStyleSheetHintExtended
84cdf0e10cSrcweir (
85cdf0e10cSrcweir 	sal_uInt16				nAction,		// SFX_STYLESHEET_... (s.o.)
86cdf0e10cSrcweir 	const String&       rOldName
87cdf0e10cSrcweir )
88cdf0e10cSrcweir :	SfxStyleSheetHint( nAction ),
89cdf0e10cSrcweir 	aName( rOldName )
90cdf0e10cSrcweir {}
SfxStyleSheetHintExtended(sal_uInt16 nAction,const String & rOldName,SfxStyleSheetBase & rStyleSheet)91cdf0e10cSrcweir SfxStyleSheetHintExtended::SfxStyleSheetHintExtended
92cdf0e10cSrcweir (
93cdf0e10cSrcweir 	sal_uInt16				nAction,		// SFX_STYLESHEET_... (s.o.)
94cdf0e10cSrcweir 	const String&       rOldName,
95cdf0e10cSrcweir 	SfxStyleSheetBase&	rStyleSheet 	// geh"ort weiterhin dem Aufrufer
96cdf0e10cSrcweir )
97cdf0e10cSrcweir :	SfxStyleSheetHint( nAction, rStyleSheet ),
98cdf0e10cSrcweir 	aName( rOldName )
99cdf0e10cSrcweir {}
100cdf0e10cSrcweir 
101cdf0e10cSrcweir //-------------------------------------------------------------------------
102cdf0e10cSrcweir 
SfxStyleSheetHint(sal_uInt16 nAction,SfxStyleSheetBase & rStyleSheet)103cdf0e10cSrcweir SfxStyleSheetHint::SfxStyleSheetHint
104cdf0e10cSrcweir (
105cdf0e10cSrcweir 	sal_uInt16				nAction,		// SFX_STYLESHEET_... (s.o.)
106cdf0e10cSrcweir 	SfxStyleSheetBase&	rStyleSheet 	// geh"ort weiterhin dem Aufrufer
107cdf0e10cSrcweir )
108cdf0e10cSrcweir :	pStyleSh( &rStyleSheet ),
109cdf0e10cSrcweir 	nHint( nAction )
110cdf0e10cSrcweir {}
111cdf0e10cSrcweir 
SfxStyleSheetHint(sal_uInt16 nAction)112cdf0e10cSrcweir SfxStyleSheetHint::SfxStyleSheetHint
113cdf0e10cSrcweir (
114cdf0e10cSrcweir 	sal_uInt16				nAction		// SFX_STYLESHEET_... (s.o.)
115cdf0e10cSrcweir )
116cdf0e10cSrcweir :	pStyleSh( NULL ),
117cdf0e10cSrcweir 	nHint( nAction )
118cdf0e10cSrcweir {}
119cdf0e10cSrcweir 
120cdf0e10cSrcweir //=========================================================================
121cdf0e10cSrcweir 
122cdf0e10cSrcweir class SfxStyleSheetBasePool_Impl
123cdf0e10cSrcweir {
124*49bd4d4bSArmin Le Grand public:
125cdf0e10cSrcweir 	SfxStyles aStyles;
126*49bd4d4bSArmin Le Grand 	SfxStyleSheetIteratorPtr pIter;
127cdf0e10cSrcweir };
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 
130cdf0e10cSrcweir //////////////////////////// SfxStyleSheetBase ///////////////////////////////
131cdf0e10cSrcweir 
132cdf0e10cSrcweir // Konstruktoren
133cdf0e10cSrcweir 
SfxStyleSheetBase(const XubString & rName,SfxStyleSheetBasePool & r,SfxStyleFamily eFam,sal_uInt16 mask)134cdf0e10cSrcweir SfxStyleSheetBase::SfxStyleSheetBase( const XubString& rName, SfxStyleSheetBasePool& r, SfxStyleFamily eFam, sal_uInt16 mask )
135cdf0e10cSrcweir 	: rPool( r )
136cdf0e10cSrcweir 	, nFamily( eFam )
137cdf0e10cSrcweir 	, aName( rName )
138cdf0e10cSrcweir 	, aParent()
139cdf0e10cSrcweir 	, aFollow( rName )
140cdf0e10cSrcweir 	, pSet( NULL )
141cdf0e10cSrcweir 	, nMask(mask)
142cdf0e10cSrcweir 	, nHelpId( 0 )
143cdf0e10cSrcweir 	, bMySet( sal_False )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir #ifdef DBG_UTIL
146cdf0e10cSrcweir 	aDbgStyleSheetReferences.mnStyles++;
147cdf0e10cSrcweir #endif
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
SfxStyleSheetBase(const SfxStyleSheetBase & r)150cdf0e10cSrcweir SfxStyleSheetBase::SfxStyleSheetBase( const SfxStyleSheetBase& r )
151cdf0e10cSrcweir 	: comphelper::OWeakTypeObject()
152cdf0e10cSrcweir 	, rPool( r.rPool )
153cdf0e10cSrcweir 	, nFamily( r.nFamily )
154cdf0e10cSrcweir 	, aName( r.aName )
155cdf0e10cSrcweir 	, aParent( r.aParent )
156cdf0e10cSrcweir 	, aFollow( r.aFollow )
157cdf0e10cSrcweir 	, aHelpFile( r.aHelpFile )
158cdf0e10cSrcweir 	, nMask( r.nMask )
159cdf0e10cSrcweir 	, nHelpId( r.nHelpId )
160cdf0e10cSrcweir 	, bMySet( r.bMySet )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir #ifdef DBG_UTIL
163cdf0e10cSrcweir 	aDbgStyleSheetReferences.mnStyles++;
164cdf0e10cSrcweir #endif
165cdf0e10cSrcweir 	if( r.pSet )
166cdf0e10cSrcweir 		pSet = bMySet ? new SfxItemSet( *r.pSet ) : r.pSet;
167cdf0e10cSrcweir 	else
168cdf0e10cSrcweir 		pSet = NULL;
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
implGetStaticPool()171cdf0e10cSrcweir static SfxStyleSheetBasePool& implGetStaticPool()
172cdf0e10cSrcweir {
173cdf0e10cSrcweir 	static SfxStyleSheetBasePool* pSheetPool = 0;
174cdf0e10cSrcweir 	static SfxItemPool* pBasePool = 0;
175cdf0e10cSrcweir 	if( !pSheetPool )
176cdf0e10cSrcweir 	{
177cdf0e10cSrcweir 		UniString aName;
178cdf0e10cSrcweir         pBasePool = new SfxItemPool( aName, 0, 0, 0 );
179cdf0e10cSrcweir 		pSheetPool = new SfxStyleSheetBasePool(*pBasePool);
180cdf0e10cSrcweir 	}
181cdf0e10cSrcweir 	return *pSheetPool;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
SfxStyleSheetBase()184cdf0e10cSrcweir SfxStyleSheetBase::SfxStyleSheetBase()
185cdf0e10cSrcweir : comphelper::OWeakTypeObject()
186cdf0e10cSrcweir , rPool( implGetStaticPool() )
187cdf0e10cSrcweir {
188cdf0e10cSrcweir }
189cdf0e10cSrcweir 
~SfxStyleSheetBase()190cdf0e10cSrcweir SfxStyleSheetBase::~SfxStyleSheetBase()
191cdf0e10cSrcweir {
192cdf0e10cSrcweir #ifdef DBG_UTIL
193cdf0e10cSrcweir 	--aDbgStyleSheetReferences.mnStyles;
194cdf0e10cSrcweir #endif
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 	if( bMySet )
197cdf0e10cSrcweir 	{
198cdf0e10cSrcweir 		delete pSet;
199cdf0e10cSrcweir 		pSet = 0;
200cdf0e10cSrcweir 	}
201cdf0e10cSrcweir }
202cdf0e10cSrcweir 
GetVersion() const203cdf0e10cSrcweir sal_uInt16 SfxStyleSheetBase::GetVersion() const
204cdf0e10cSrcweir {
205cdf0e10cSrcweir 	return 0x0000;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir // Namen aendern
209cdf0e10cSrcweir 
GetName() const210cdf0e10cSrcweir const XubString& SfxStyleSheetBase::GetName() const
211cdf0e10cSrcweir {
212cdf0e10cSrcweir 	return aName;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
SetName(const XubString & rName)215cdf0e10cSrcweir sal_Bool SfxStyleSheetBase::SetName( const XubString& rName )
216cdf0e10cSrcweir {
217cdf0e10cSrcweir 	if(rName.Len() == 0)
218cdf0e10cSrcweir 		return sal_False;
219cdf0e10cSrcweir 	if( aName != rName )
220cdf0e10cSrcweir 	{
221cdf0e10cSrcweir 		String aOldName = aName;
222cdf0e10cSrcweir 		SfxStyleSheetBase *pOther = rPool.Find( rName, nFamily ) ;
223cdf0e10cSrcweir 		if ( pOther && pOther != this )
224cdf0e10cSrcweir 			return sal_False;
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 		SfxStyleFamily eTmpFam=rPool.GetSearchFamily();
227cdf0e10cSrcweir 		sal_uInt16 nTmpMask=rPool.GetSearchMask();
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 		rPool.SetSearchMask(nFamily);
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 		if ( aName.Len() )
232cdf0e10cSrcweir 			rPool.ChangeParent( aName, rName, sal_False );
233cdf0e10cSrcweir 		if ( aFollow.Equals( aName ) )
234cdf0e10cSrcweir 			aFollow = rName;
235cdf0e10cSrcweir 		aName = rName;
236cdf0e10cSrcweir 		rPool.SetSearchMask(eTmpFam, nTmpMask);
237cdf0e10cSrcweir 		rPool.Broadcast( SfxStyleSheetHintExtended(
238cdf0e10cSrcweir 			SFX_STYLESHEET_MODIFIED, aOldName, *this ) );
239cdf0e10cSrcweir 	}
240cdf0e10cSrcweir 	return sal_True;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
GetDisplayName() const243cdf0e10cSrcweir rtl::OUString SfxStyleSheetBase::GetDisplayName() const
244cdf0e10cSrcweir {
245cdf0e10cSrcweir 	if( maDisplayName.getLength() == 0 )
246cdf0e10cSrcweir 	{
247cdf0e10cSrcweir 		return aName;
248cdf0e10cSrcweir 	}
249cdf0e10cSrcweir 	else
250cdf0e10cSrcweir 	{
251cdf0e10cSrcweir 		return maDisplayName;
252cdf0e10cSrcweir 	}
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
SetDisplayName(const rtl::OUString & rDisplayName)255cdf0e10cSrcweir void SfxStyleSheetBase::SetDisplayName( const rtl::OUString& rDisplayName )
256cdf0e10cSrcweir {
257cdf0e10cSrcweir 	maDisplayName = rDisplayName;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir 
260cdf0e10cSrcweir // Parent aendern
261cdf0e10cSrcweir 
GetParent() const262cdf0e10cSrcweir const XubString& SfxStyleSheetBase::GetParent() const
263cdf0e10cSrcweir {
264cdf0e10cSrcweir 	return aParent;
265cdf0e10cSrcweir }
266cdf0e10cSrcweir 
SetParent(const XubString & rName)267cdf0e10cSrcweir sal_Bool SfxStyleSheetBase::SetParent( const XubString& rName )
268cdf0e10cSrcweir {
269cdf0e10cSrcweir     if ( rName == aName )
270cdf0e10cSrcweir         return sal_False;
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 	if( aParent != rName )
273cdf0e10cSrcweir 	{
274cdf0e10cSrcweir 		SfxStyleSheetBase* pIter = rPool.Find(rName, nFamily);
275cdf0e10cSrcweir 		if( rName.Len() && !pIter )
276cdf0e10cSrcweir 		{
277cdf0e10cSrcweir 			DBG_ERROR( "StyleSheet-Parent nicht gefunden" );
278cdf0e10cSrcweir 			return sal_False;
279cdf0e10cSrcweir 		}
280cdf0e10cSrcweir 		// rekursive Verknuepfungen verhindern
281cdf0e10cSrcweir 		if( aName.Len() )
282cdf0e10cSrcweir 			while(pIter)
283cdf0e10cSrcweir 			{
284cdf0e10cSrcweir 				if(pIter->GetName() == aName && aName != rName)
285cdf0e10cSrcweir 					return sal_False;
286cdf0e10cSrcweir 				pIter = rPool.Find(pIter->GetParent(), nFamily);
287cdf0e10cSrcweir 			}
288cdf0e10cSrcweir 		aParent = rName;
289cdf0e10cSrcweir 	}
290cdf0e10cSrcweir 	rPool.Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, *this ) );
291cdf0e10cSrcweir 	return sal_True;
292cdf0e10cSrcweir }
293cdf0e10cSrcweir 
294cdf0e10cSrcweir // Follow aendern
295cdf0e10cSrcweir 
GetFollow() const296cdf0e10cSrcweir const XubString& SfxStyleSheetBase::GetFollow() const
297cdf0e10cSrcweir {
298cdf0e10cSrcweir 	return aFollow;
299cdf0e10cSrcweir }
300cdf0e10cSrcweir 
SetFollow(const XubString & rName)301cdf0e10cSrcweir sal_Bool SfxStyleSheetBase::SetFollow( const XubString& rName )
302cdf0e10cSrcweir {
303cdf0e10cSrcweir 	if( aFollow != rName )
304cdf0e10cSrcweir 	{
305cdf0e10cSrcweir 		if( !rPool.Find( rName, nFamily ) )
306cdf0e10cSrcweir 		{
307cdf0e10cSrcweir 			DBG_ERROR( "StyleSheet-Follow nicht gefunden" );
308cdf0e10cSrcweir 			return sal_False;
309cdf0e10cSrcweir 		}
310cdf0e10cSrcweir 		aFollow = rName;
311cdf0e10cSrcweir 	}
312cdf0e10cSrcweir 	rPool.Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, *this ) );
313cdf0e10cSrcweir 	return sal_True;
314cdf0e10cSrcweir }
315cdf0e10cSrcweir 
316cdf0e10cSrcweir // Itemset setzen. Die Dflt-Implementation legt ein neues Set an.
317cdf0e10cSrcweir 
GetItemSet()318cdf0e10cSrcweir SfxItemSet& SfxStyleSheetBase::GetItemSet()
319cdf0e10cSrcweir {
320cdf0e10cSrcweir 	if( !pSet )
321cdf0e10cSrcweir 	{
322cdf0e10cSrcweir 		pSet = new SfxItemSet( rPool.GetPool() );
323cdf0e10cSrcweir 		bMySet = sal_True;
324cdf0e10cSrcweir 	}
325cdf0e10cSrcweir 	return *pSet;
326cdf0e10cSrcweir }
327cdf0e10cSrcweir 
328cdf0e10cSrcweir // Hilfe-Datei und -ID setzen und abfragen
329cdf0e10cSrcweir 
GetHelpId(String & rFile)330cdf0e10cSrcweir sal_uLong SfxStyleSheetBase::GetHelpId( String& rFile )
331cdf0e10cSrcweir {
332cdf0e10cSrcweir 	rFile = aHelpFile;
333cdf0e10cSrcweir 	return nHelpId;
334cdf0e10cSrcweir }
335cdf0e10cSrcweir 
SetHelpId(const String & rFile,sal_uLong nId)336cdf0e10cSrcweir void SfxStyleSheetBase::SetHelpId( const String& rFile, sal_uLong nId )
337cdf0e10cSrcweir {
338cdf0e10cSrcweir 	aHelpFile = rFile;
339cdf0e10cSrcweir 	nHelpId = nId;
340cdf0e10cSrcweir }
341cdf0e10cSrcweir 
342cdf0e10cSrcweir // Folgevorlage m"oglich? Default: Ja
343cdf0e10cSrcweir 
HasFollowSupport() const344cdf0e10cSrcweir sal_Bool SfxStyleSheetBase::HasFollowSupport() const
345cdf0e10cSrcweir {
346cdf0e10cSrcweir 	return sal_True;
347cdf0e10cSrcweir }
348cdf0e10cSrcweir 
349cdf0e10cSrcweir // Basisvorlage m"oglich? Default: Ja
350cdf0e10cSrcweir 
HasParentSupport() const351cdf0e10cSrcweir sal_Bool SfxStyleSheetBase::HasParentSupport() const
352cdf0e10cSrcweir {
353cdf0e10cSrcweir 	return sal_True;
354cdf0e10cSrcweir }
355cdf0e10cSrcweir 
356cdf0e10cSrcweir // Basisvorlage uf NULL setzen m"oglich? Default: Nein
357cdf0e10cSrcweir 
HasClearParentSupport() const358cdf0e10cSrcweir sal_Bool SfxStyleSheetBase::HasClearParentSupport() const
359cdf0e10cSrcweir {
360cdf0e10cSrcweir 	return sal_False;
361cdf0e10cSrcweir }
362cdf0e10cSrcweir 
363cdf0e10cSrcweir // Defaultmaessig sind alle StyleSheets Used
364cdf0e10cSrcweir 
IsUsed() const365cdf0e10cSrcweir sal_Bool SfxStyleSheetBase::IsUsed() const
366cdf0e10cSrcweir {
367cdf0e10cSrcweir 	return sal_True;
368cdf0e10cSrcweir }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir // eingestellte Attribute ausgeben
371cdf0e10cSrcweir 
372cdf0e10cSrcweir 
GetDescription()373cdf0e10cSrcweir XubString SfxStyleSheetBase::GetDescription()
374cdf0e10cSrcweir {
375cdf0e10cSrcweir 	return GetDescription( SFX_MAPUNIT_CM );
376cdf0e10cSrcweir }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir // eingestellte Attribute ausgeben
379cdf0e10cSrcweir 
GetDescription(SfxMapUnit eMetric)380cdf0e10cSrcweir XubString SfxStyleSheetBase::GetDescription( SfxMapUnit eMetric )
381cdf0e10cSrcweir {
382cdf0e10cSrcweir 	SfxItemIter aIter( GetItemSet() );
383cdf0e10cSrcweir 	XubString aDesc;
384cdf0e10cSrcweir 	const SfxPoolItem* pItem = aIter.FirstItem();
385cdf0e10cSrcweir 
386cdf0e10cSrcweir     IntlWrapper aIntlWrapper(comphelper::getProcessServiceFactory(),
387cdf0e10cSrcweir             SvtSysLocale().GetLanguage());
388cdf0e10cSrcweir 	while ( pItem )
389cdf0e10cSrcweir 	{
390cdf0e10cSrcweir 		XubString aItemPresentation;
391cdf0e10cSrcweir 
392cdf0e10cSrcweir 		if ( !IsInvalidItem( pItem ) &&
393cdf0e10cSrcweir 			 rPool.GetPool().GetPresentation(
394cdf0e10cSrcweir 				*pItem, SFX_ITEM_PRESENTATION_COMPLETE,
395cdf0e10cSrcweir                 eMetric, aItemPresentation, &aIntlWrapper ) )
396cdf0e10cSrcweir         {
397cdf0e10cSrcweir 			if ( aDesc.Len() && aItemPresentation.Len() )
398cdf0e10cSrcweir 				aDesc.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" + "));
399cdf0e10cSrcweir 			if ( aItemPresentation.Len() )
400cdf0e10cSrcweir 				aDesc += aItemPresentation;
401cdf0e10cSrcweir 		}
402cdf0e10cSrcweir 		pItem = aIter.NextItem();
403cdf0e10cSrcweir 	}
404cdf0e10cSrcweir 	return aDesc;
405cdf0e10cSrcweir }
406cdf0e10cSrcweir 
407cdf0e10cSrcweir /////////////////////////// SfxStyleSheetIterator ///////////////////////////////
408cdf0e10cSrcweir 
GetSearchFamily() const409cdf0e10cSrcweir SfxStyleFamily SfxStyleSheetIterator::GetSearchFamily() const
410cdf0e10cSrcweir {
411cdf0e10cSrcweir 	return nSearchFamily;
412cdf0e10cSrcweir }
413cdf0e10cSrcweir 
IsTrivialSearch()414cdf0e10cSrcweir inline sal_Bool SfxStyleSheetIterator::IsTrivialSearch()
415cdf0e10cSrcweir {
416cdf0e10cSrcweir 	return nMask == 0xFFFF && GetSearchFamily() == SFX_STYLE_FAMILY_ALL;
417cdf0e10cSrcweir }
418cdf0e10cSrcweir 
DoesStyleMatch(SfxStyleSheetBase * pStyle)419cdf0e10cSrcweir sal_Bool SfxStyleSheetIterator::DoesStyleMatch(SfxStyleSheetBase *pStyle)
420cdf0e10cSrcweir {
421cdf0e10cSrcweir 	return ((GetSearchFamily() == SFX_STYLE_FAMILY_ALL) ||
422cdf0e10cSrcweir 			( pStyle->GetFamily() == GetSearchFamily() ))
423cdf0e10cSrcweir 		&& (( pStyle->GetMask() & ( GetSearchMask() & ~SFXSTYLEBIT_USED )) ||
424cdf0e10cSrcweir 			( bSearchUsed ? pStyle->IsUsed() : sal_False ) ||
425cdf0e10cSrcweir 			GetSearchMask() == SFXSTYLEBIT_ALL );
426cdf0e10cSrcweir }
427cdf0e10cSrcweir 
428cdf0e10cSrcweir 
SfxStyleSheetIterator(SfxStyleSheetBasePool * pBase,SfxStyleFamily eFam,sal_uInt16 n)429cdf0e10cSrcweir SfxStyleSheetIterator::SfxStyleSheetIterator(SfxStyleSheetBasePool *pBase,
430cdf0e10cSrcweir 											 SfxStyleFamily eFam, sal_uInt16 n)
431cdf0e10cSrcweir {
432cdf0e10cSrcweir 	pBasePool=pBase;
433cdf0e10cSrcweir 	nSearchFamily=eFam;
434cdf0e10cSrcweir 	bSearchUsed=sal_False;
435cdf0e10cSrcweir 		if((n != SFXSTYLEBIT_ALL ) && ((n & SFXSTYLEBIT_USED) == SFXSTYLEBIT_USED))
436cdf0e10cSrcweir 	{
437cdf0e10cSrcweir 		bSearchUsed = sal_True;
438cdf0e10cSrcweir 		n &= ~SFXSTYLEBIT_USED;
439cdf0e10cSrcweir 	}
440cdf0e10cSrcweir 	nMask=n;
441cdf0e10cSrcweir }
442cdf0e10cSrcweir 
~SfxStyleSheetIterator()443cdf0e10cSrcweir SfxStyleSheetIterator::~SfxStyleSheetIterator()
444cdf0e10cSrcweir {
445cdf0e10cSrcweir }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir 
Count()448cdf0e10cSrcweir sal_uInt16 SfxStyleSheetIterator::Count()
449cdf0e10cSrcweir {
450cdf0e10cSrcweir 	sal_uInt16 n = 0;
451cdf0e10cSrcweir 	if( IsTrivialSearch())
452cdf0e10cSrcweir 		n = (sal_uInt16) pBasePool->aStyles.size();
453cdf0e10cSrcweir 	else
454cdf0e10cSrcweir 		for(sal_uInt16 i=0; i<pBasePool->aStyles.size(); i++)
455cdf0e10cSrcweir 		{
456cdf0e10cSrcweir 			SfxStyleSheetBase* pStyle = pBasePool->aStyles[i].get();
457cdf0e10cSrcweir 			if(DoesStyleMatch(pStyle))
458cdf0e10cSrcweir 				n++;
459cdf0e10cSrcweir 		}
460cdf0e10cSrcweir 	return n;
461cdf0e10cSrcweir }
462cdf0e10cSrcweir 
operator [](sal_uInt16 nIdx)463cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetIterator::operator[](sal_uInt16 nIdx)
464cdf0e10cSrcweir {
465cdf0e10cSrcweir 	if( IsTrivialSearch())
466cdf0e10cSrcweir 		return pBasePool->aStyles[nIdx].get();
467cdf0e10cSrcweir 
468cdf0e10cSrcweir 	sal_uInt16 z = 0;
469cdf0e10cSrcweir 	for(sal_uInt16 n=0; n<pBasePool->aStyles.size(); n++)
470cdf0e10cSrcweir 	{
471cdf0e10cSrcweir 		SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get();
472cdf0e10cSrcweir 		if( DoesStyleMatch(pStyle))
473cdf0e10cSrcweir 		{
474cdf0e10cSrcweir 			if(z == nIdx)
475cdf0e10cSrcweir 			{
476cdf0e10cSrcweir 				nAktPosition=n;
477cdf0e10cSrcweir 				return pAktStyle=pStyle;
478cdf0e10cSrcweir 			}
479cdf0e10cSrcweir 			++z;
480cdf0e10cSrcweir 		}
481cdf0e10cSrcweir 	}
482cdf0e10cSrcweir 	DBG_ERROR("falscher Index");
483cdf0e10cSrcweir 	return 0;
484cdf0e10cSrcweir }
485cdf0e10cSrcweir 
First()486cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetIterator::First()
487cdf0e10cSrcweir {
488cdf0e10cSrcweir 	sal_Int32 nIdx = -1;
489cdf0e10cSrcweir 
490cdf0e10cSrcweir 	if ( IsTrivialSearch() && pBasePool->aStyles.size() )
491cdf0e10cSrcweir 		nIdx = 0;
492cdf0e10cSrcweir 	else
493cdf0e10cSrcweir 		for( sal_uInt16 n = 0; n < pBasePool->aStyles.size(); n++ )
494cdf0e10cSrcweir 		{
495cdf0e10cSrcweir 			SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get();
496cdf0e10cSrcweir 
497cdf0e10cSrcweir 			if ( DoesStyleMatch( pStyle ) )
498cdf0e10cSrcweir 			{
499cdf0e10cSrcweir 				nIdx = n;
500cdf0e10cSrcweir 				break;
501cdf0e10cSrcweir 			}
502cdf0e10cSrcweir 		}
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 	if ( nIdx != -1 )
505cdf0e10cSrcweir 	{
506cdf0e10cSrcweir 		nAktPosition = (sal_uInt16)nIdx;
507cdf0e10cSrcweir 		return pAktStyle = pBasePool->aStyles[nIdx].get();
508cdf0e10cSrcweir 	}
509cdf0e10cSrcweir 	return 0;
510cdf0e10cSrcweir }
511cdf0e10cSrcweir 
512cdf0e10cSrcweir 
Next()513cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetIterator::Next()
514cdf0e10cSrcweir {
515cdf0e10cSrcweir 	sal_Int32 nIdx = -1;
516cdf0e10cSrcweir 
517cdf0e10cSrcweir 	if ( IsTrivialSearch() &&
518cdf0e10cSrcweir 		 (sal_uInt16)pBasePool->aStyles.size() > nAktPosition + 1 )
519cdf0e10cSrcweir 		nIdx = nAktPosition + 1;
520cdf0e10cSrcweir 	else
521cdf0e10cSrcweir 		for( sal_uInt16 n = nAktPosition + 1; n < pBasePool->aStyles.size(); n++ )
522cdf0e10cSrcweir 		{
523cdf0e10cSrcweir 			SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get();
524cdf0e10cSrcweir 
525cdf0e10cSrcweir 			if ( DoesStyleMatch( pStyle ) )
526cdf0e10cSrcweir 			{
527cdf0e10cSrcweir 				nIdx = n;
528cdf0e10cSrcweir 				break;
529cdf0e10cSrcweir 			}
530cdf0e10cSrcweir 		}
531cdf0e10cSrcweir 
532cdf0e10cSrcweir 	if ( nIdx != -1 )
533cdf0e10cSrcweir 	{
534cdf0e10cSrcweir 		nAktPosition = (sal_uInt16)nIdx;
535cdf0e10cSrcweir 		return pAktStyle = pBasePool->aStyles[nIdx].get();
536cdf0e10cSrcweir 	}
537cdf0e10cSrcweir 	return 0;
538cdf0e10cSrcweir }
539cdf0e10cSrcweir 
540cdf0e10cSrcweir 
Find(const XubString & rStr)541cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetIterator::Find(const XubString& rStr)
542cdf0e10cSrcweir {
543cdf0e10cSrcweir 	for ( sal_uInt16 n = 0; n < pBasePool->aStyles.size(); n++ )
544cdf0e10cSrcweir 	{
545cdf0e10cSrcweir 		SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get();
546cdf0e10cSrcweir 
547cdf0e10cSrcweir         // #98454# performance: in case of bSearchUsed==sal_True it may be
548cdf0e10cSrcweir         // significant to first compare the name and only if it matches to call
549cdf0e10cSrcweir         // the style sheet IsUsed() method in DoesStyleMatch().
550cdf0e10cSrcweir         if ( pStyle->GetName().Equals( rStr ) && DoesStyleMatch( pStyle ) )
551cdf0e10cSrcweir 		{
552cdf0e10cSrcweir 			nAktPosition = n;
553cdf0e10cSrcweir 			return pAktStyle = pStyle;
554cdf0e10cSrcweir 		}
555cdf0e10cSrcweir 	}
556cdf0e10cSrcweir 	return 0;
557cdf0e10cSrcweir }
558cdf0e10cSrcweir 
559cdf0e10cSrcweir 
GetSearchMask() const560cdf0e10cSrcweir sal_uInt16 SfxStyleSheetIterator::GetSearchMask() const
561cdf0e10cSrcweir {
562cdf0e10cSrcweir 	sal_uInt16 mask = nMask;
563cdf0e10cSrcweir 
564cdf0e10cSrcweir 	if ( bSearchUsed )
565cdf0e10cSrcweir 		mask |= SFXSTYLEBIT_USED;
566cdf0e10cSrcweir 	return mask;
567cdf0e10cSrcweir }
568cdf0e10cSrcweir 
569cdf0e10cSrcweir /////////////////////////// SfxStyleSheetBasePool ///////////////////////////////
570cdf0e10cSrcweir 
Replace(SfxStyleSheetBase & rSource,SfxStyleSheetBase & rTarget)571cdf0e10cSrcweir void SfxStyleSheetBasePool::Replace(
572cdf0e10cSrcweir 	SfxStyleSheetBase& rSource, SfxStyleSheetBase& rTarget )
573cdf0e10cSrcweir {
574cdf0e10cSrcweir 	rTarget.SetFollow( rSource.GetFollow() );
575cdf0e10cSrcweir 	rTarget.SetParent( rSource.GetParent() );
576cdf0e10cSrcweir 	SfxItemSet& rSourceSet = rSource.GetItemSet();
577cdf0e10cSrcweir 	SfxItemSet& rTargetSet = rTarget.GetItemSet();
578cdf0e10cSrcweir 	rTargetSet.Intersect( rSourceSet );
579cdf0e10cSrcweir 	rTargetSet.Put( rSourceSet );
580cdf0e10cSrcweir }
581cdf0e10cSrcweir 
GetIterator_Impl()582cdf0e10cSrcweir SfxStyleSheetIterator& SfxStyleSheetBasePool::GetIterator_Impl()
583cdf0e10cSrcweir {
584*49bd4d4bSArmin Le Grand 	if( !pImp->pIter || (pImp->pIter->GetSearchMask() != nMask) || (pImp->pIter->GetSearchFamily() != nSearchFamily) )
585cdf0e10cSrcweir 	{
586*49bd4d4bSArmin Le Grand 		pImp->pIter = CreateIterator( nSearchFamily, nMask );
587cdf0e10cSrcweir 	}
588*49bd4d4bSArmin Le Grand 
589*49bd4d4bSArmin Le Grand     return *pImp->pIter;
590cdf0e10cSrcweir }
591cdf0e10cSrcweir 
592cdf0e10cSrcweir 
SfxStyleSheetBasePool(SfxItemPool & r)593cdf0e10cSrcweir SfxStyleSheetBasePool::SfxStyleSheetBasePool( SfxItemPool& r )
594cdf0e10cSrcweir 	: aAppName(r.GetName())
595cdf0e10cSrcweir 	, rPool(r)
596cdf0e10cSrcweir 	, nSearchFamily(SFX_STYLE_FAMILY_PARA)
597cdf0e10cSrcweir 	, nMask(0xFFFF)
598cdf0e10cSrcweir {
599cdf0e10cSrcweir #ifdef DBG_UTIL
600cdf0e10cSrcweir 	aDbgStyleSheetReferences.mnPools++;
601cdf0e10cSrcweir #endif
602cdf0e10cSrcweir 
603cdf0e10cSrcweir 	pImp = new SfxStyleSheetBasePool_Impl;
604cdf0e10cSrcweir }
605cdf0e10cSrcweir 
SfxStyleSheetBasePool(const SfxStyleSheetBasePool & r)606cdf0e10cSrcweir SfxStyleSheetBasePool::SfxStyleSheetBasePool( const SfxStyleSheetBasePool& r )
607cdf0e10cSrcweir 	: SfxBroadcaster( r )
608cdf0e10cSrcweir 	, comphelper::OWeakTypeObject()
609cdf0e10cSrcweir     , aAppName(r.aAppName)
610cdf0e10cSrcweir 	, rPool(r.rPool)
611cdf0e10cSrcweir 	, nSearchFamily(r.nSearchFamily)
612cdf0e10cSrcweir 	, nMask( r.nMask )
613cdf0e10cSrcweir {
614cdf0e10cSrcweir #ifdef DBG_UTIL
615cdf0e10cSrcweir 	aDbgStyleSheetReferences.mnPools++;
616cdf0e10cSrcweir #endif
617cdf0e10cSrcweir 
618cdf0e10cSrcweir 	pImp = new SfxStyleSheetBasePool_Impl;
619cdf0e10cSrcweir 	*this += r;
620cdf0e10cSrcweir }
621cdf0e10cSrcweir 
~SfxStyleSheetBasePool()622cdf0e10cSrcweir SfxStyleSheetBasePool::~SfxStyleSheetBasePool()
623cdf0e10cSrcweir {
624cdf0e10cSrcweir #ifdef DBG_UTIL
625cdf0e10cSrcweir 	aDbgStyleSheetReferences.mnPools--;
626cdf0e10cSrcweir #endif
627cdf0e10cSrcweir 
628cdf0e10cSrcweir 	Broadcast( SfxSimpleHint(SFX_HINT_DYING) );
629cdf0e10cSrcweir 	Clear();
630cdf0e10cSrcweir 	delete pImp;
631cdf0e10cSrcweir }
632cdf0e10cSrcweir 
SetParent(SfxStyleFamily eFam,const XubString & rStyle,const XubString & rParent)633cdf0e10cSrcweir sal_Bool SfxStyleSheetBasePool::SetParent(SfxStyleFamily eFam, const XubString& rStyle, const XubString& rParent)
634cdf0e10cSrcweir {
635cdf0e10cSrcweir 	SfxStyleSheetIterator aIter(this,eFam,SFXSTYLEBIT_ALL);
636cdf0e10cSrcweir 	SfxStyleSheetBase *pStyle =
637cdf0e10cSrcweir 		aIter.Find(rStyle);
638cdf0e10cSrcweir 	DBG_ASSERT(pStyle, "Vorlage nicht gefunden. Writer mit Solar <2541??");
639cdf0e10cSrcweir 	if(pStyle)
640cdf0e10cSrcweir 		return pStyle->SetParent(rParent);
641cdf0e10cSrcweir 	else
642cdf0e10cSrcweir 		return sal_False;
643cdf0e10cSrcweir }
644cdf0e10cSrcweir 
645cdf0e10cSrcweir 
SetSearchMask(SfxStyleFamily eFam,sal_uInt16 n)646cdf0e10cSrcweir void SfxStyleSheetBasePool::SetSearchMask(SfxStyleFamily eFam, sal_uInt16 n)
647cdf0e10cSrcweir {
648cdf0e10cSrcweir 	nSearchFamily = eFam; nMask = n;
649cdf0e10cSrcweir }
650cdf0e10cSrcweir 
GetSearchMask() const651cdf0e10cSrcweir sal_uInt16 SfxStyleSheetBasePool::GetSearchMask() const
652cdf0e10cSrcweir {
653cdf0e10cSrcweir 	return nMask;
654cdf0e10cSrcweir }
655cdf0e10cSrcweir 
656cdf0e10cSrcweir 
657cdf0e10cSrcweir // Der Name des Streams
658cdf0e10cSrcweir 
GetStreamName()659cdf0e10cSrcweir String SfxStyleSheetBasePool::GetStreamName()
660cdf0e10cSrcweir {
661cdf0e10cSrcweir 	return String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(STYLESTREAM));
662cdf0e10cSrcweir }
663cdf0e10cSrcweir 
664cdf0e10cSrcweir /////////////////////////////////// Factory ////////////////////////////////
665cdf0e10cSrcweir 
666cdf0e10cSrcweir 
667cdf0e10cSrcweir 
CreateIterator(SfxStyleFamily eFam,sal_uInt16 mask)668*49bd4d4bSArmin Le Grand SfxStyleSheetIteratorPtr SfxStyleSheetBasePool::CreateIterator
669*49bd4d4bSArmin Le Grand (
670*49bd4d4bSArmin Le Grand  SfxStyleFamily eFam,
671*49bd4d4bSArmin Le Grand  sal_uInt16 mask
672*49bd4d4bSArmin Le Grand )
673*49bd4d4bSArmin Le Grand {
674*49bd4d4bSArmin Le Grand 	return SfxStyleSheetIteratorPtr(new SfxStyleSheetIterator(this,eFam,mask));
675*49bd4d4bSArmin Le Grand }
676*49bd4d4bSArmin Le Grand 
677*49bd4d4bSArmin Le Grand 
Create(const XubString & rName,SfxStyleFamily eFam,sal_uInt16 mask)678cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetBasePool::Create
679cdf0e10cSrcweir (
680cdf0e10cSrcweir 	const XubString& rName,
681cdf0e10cSrcweir 	SfxStyleFamily eFam,
682cdf0e10cSrcweir 	sal_uInt16 mask
683cdf0e10cSrcweir )
684cdf0e10cSrcweir {
685cdf0e10cSrcweir 	return new SfxStyleSheetBase( rName, *this, eFam, mask );
686cdf0e10cSrcweir }
687cdf0e10cSrcweir 
Create(const SfxStyleSheetBase & r)688cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetBasePool::Create( const SfxStyleSheetBase& r )
689cdf0e10cSrcweir {
690cdf0e10cSrcweir 	return new SfxStyleSheetBase( r );
691cdf0e10cSrcweir }
692cdf0e10cSrcweir 
Make(const XubString & rName,SfxStyleFamily eFam,sal_uInt16 mask,sal_uInt16 nPos)693cdf0e10cSrcweir SfxStyleSheetBase& SfxStyleSheetBasePool::Make( const XubString& rName, SfxStyleFamily eFam, sal_uInt16 mask, sal_uInt16 nPos)
694cdf0e10cSrcweir {
695cdf0e10cSrcweir 	DBG_ASSERT( eFam != SFX_STYLE_FAMILY_ALL, "svl::SfxStyleSheetBasePool::Make(), FamilyAll is not a allowed Familie" );
696cdf0e10cSrcweir 
697cdf0e10cSrcweir 	SfxStyleSheetIterator aIter(this, eFam, mask);
698cdf0e10cSrcweir 	rtl::Reference< SfxStyleSheetBase > xStyle( aIter.Find( rName ) );
699cdf0e10cSrcweir 	DBG_ASSERT( !xStyle.is(), "svl::SfxStyleSheetBasePool::Make(), StyleSheet already exists" );
700cdf0e10cSrcweir 	SfxStyleSheetIterator& rIter = GetIterator_Impl();
701cdf0e10cSrcweir 
702cdf0e10cSrcweir 	if( !xStyle.is() )
703cdf0e10cSrcweir 	{
704cdf0e10cSrcweir 		xStyle = Create( rName, eFam, mask );
705cdf0e10cSrcweir 		if(0xffff == nPos || nPos == aStyles.size() || nPos == rIter.Count())
706cdf0e10cSrcweir 		{
707cdf0e10cSrcweir 			aStyles.push_back( xStyle );
708cdf0e10cSrcweir 		}
709cdf0e10cSrcweir 		else
710cdf0e10cSrcweir 		{
711cdf0e10cSrcweir 			rIter[nPos];
712cdf0e10cSrcweir 			aStyles.insert( aStyles.begin() + rIter.GetPos(), xStyle );
713cdf0e10cSrcweir 		}
714cdf0e10cSrcweir 		Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *xStyle.get() ) );
715cdf0e10cSrcweir 	}
716cdf0e10cSrcweir 	return *xStyle.get();
717cdf0e10cSrcweir }
718cdf0e10cSrcweir 
719cdf0e10cSrcweir /////////////////////////////// Kopieren ///////////////////////////////////
720cdf0e10cSrcweir 
721cdf0e10cSrcweir // Hilfsroutine: Falls eine Vorlage dieses Namens existiert, wird
722cdf0e10cSrcweir // sie neu erzeugt. Alle Vorlagen, die diese Vorlage zum Parent haben,
723cdf0e10cSrcweir // werden umgehaengt.
724cdf0e10cSrcweir 
Add(SfxStyleSheetBase & rSheet)725cdf0e10cSrcweir SfxStyleSheetBase& SfxStyleSheetBasePool::Add( SfxStyleSheetBase& rSheet )
726cdf0e10cSrcweir {
727cdf0e10cSrcweir 	SfxStyleSheetIterator aIter(this, rSheet.GetFamily(), nMask);
728cdf0e10cSrcweir 	SfxStyleSheetBase* pOld = aIter.Find( rSheet.GetName() );
729cdf0e10cSrcweir 	Remove( pOld );
730cdf0e10cSrcweir 	rtl::Reference< SfxStyleSheetBase > xNew( Create( rSheet ) );
731cdf0e10cSrcweir 	aStyles.push_back( xNew );
732cdf0e10cSrcweir 	Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CHANGED, *xNew.get() ) );
733cdf0e10cSrcweir 	return *xNew.get();
734cdf0e10cSrcweir }
735cdf0e10cSrcweir 
operator =(const SfxStyleSheetBasePool & r)736cdf0e10cSrcweir SfxStyleSheetBasePool& SfxStyleSheetBasePool::operator=( const SfxStyleSheetBasePool& r )
737cdf0e10cSrcweir {
738cdf0e10cSrcweir 	if( &r != this )
739cdf0e10cSrcweir 	{
740cdf0e10cSrcweir 		Clear();
741cdf0e10cSrcweir 		*this += r;
742cdf0e10cSrcweir 	}
743cdf0e10cSrcweir 	return *this;
744cdf0e10cSrcweir }
745cdf0e10cSrcweir 
operator +=(const SfxStyleSheetBasePool & r)746cdf0e10cSrcweir SfxStyleSheetBasePool& SfxStyleSheetBasePool::operator+=( const SfxStyleSheetBasePool& r )
747cdf0e10cSrcweir {
748cdf0e10cSrcweir 	if( &r != this )
749cdf0e10cSrcweir 	{
750cdf0e10cSrcweir 		SfxStyles::const_iterator aIter( r.aStyles.begin() );
751cdf0e10cSrcweir 		while( aIter != r.aStyles.end() )
752cdf0e10cSrcweir 		{
753cdf0e10cSrcweir 			Add(*(*aIter++).get());
754cdf0e10cSrcweir 		}
755cdf0e10cSrcweir 	}
756cdf0e10cSrcweir 	return *this;
757cdf0e10cSrcweir }
758cdf0e10cSrcweir 
759cdf0e10cSrcweir //////////////////////////////// Suchen ////////////////////////////////////
760cdf0e10cSrcweir 
Count()761cdf0e10cSrcweir sal_uInt16 SfxStyleSheetBasePool::Count()
762cdf0e10cSrcweir {
763cdf0e10cSrcweir 	return GetIterator_Impl().Count();
764cdf0e10cSrcweir }
765cdf0e10cSrcweir 
operator [](sal_uInt16 nIdx)766cdf0e10cSrcweir SfxStyleSheetBase *SfxStyleSheetBasePool::operator[](sal_uInt16 nIdx)
767cdf0e10cSrcweir {
768cdf0e10cSrcweir 	return GetIterator_Impl()[nIdx];
769cdf0e10cSrcweir }
770cdf0e10cSrcweir 
Find(const XubString & rName,SfxStyleFamily eFam,sal_uInt16 mask)771cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetBasePool::Find(const XubString& rName,
772cdf0e10cSrcweir 											   SfxStyleFamily eFam,
773cdf0e10cSrcweir 											   sal_uInt16 mask)
774cdf0e10cSrcweir {
775cdf0e10cSrcweir 	SfxStyleSheetIterator aIter(this,eFam,mask);
776cdf0e10cSrcweir 	return aIter.Find(rName);
777cdf0e10cSrcweir }
778cdf0e10cSrcweir 
GetStyles()779cdf0e10cSrcweir const SfxStyles& SfxStyleSheetBasePool::GetStyles()
780cdf0e10cSrcweir {
781cdf0e10cSrcweir 	return aStyles;
782cdf0e10cSrcweir }
783cdf0e10cSrcweir 
First()784cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetBasePool::First()
785cdf0e10cSrcweir {
786cdf0e10cSrcweir 	return GetIterator_Impl().First();
787cdf0e10cSrcweir }
788cdf0e10cSrcweir 
Next()789cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetBasePool::Next()
790cdf0e10cSrcweir {
791cdf0e10cSrcweir 	return GetIterator_Impl().Next();
792cdf0e10cSrcweir }
793cdf0e10cSrcweir 
794cdf0e10cSrcweir //////////////////////////////// Loeschen /////////////////////////////////
795cdf0e10cSrcweir 
Remove(SfxStyleSheetBase * p)796cdf0e10cSrcweir void SfxStyleSheetBasePool::Remove( SfxStyleSheetBase* p )
797cdf0e10cSrcweir {
798cdf0e10cSrcweir 	if( p )
799cdf0e10cSrcweir 	{
800cdf0e10cSrcweir 		SfxStyles::iterator aIter( std::find( aStyles.begin(), aStyles.end(), rtl::Reference< SfxStyleSheetBase >( p ) ) );
801cdf0e10cSrcweir 		if( aIter != aStyles.end() )
802cdf0e10cSrcweir 		{
803cdf0e10cSrcweir 			// Alle Styles umsetzen, deren Parent dieser hier ist
804cdf0e10cSrcweir 			ChangeParent( p->GetName(), p->GetParent() );
805cdf0e10cSrcweir 
8066b46875cSArmin Le Grand             // #120015# Do not dispose, the removed StyleSheet may still be used in
8076b46875cSArmin Le Grand             // existing SdrUndoAttrObj incarnations. Rely on refcounting for disposal,
8086b46875cSArmin Le Grand             // this works well under normal conditions (checked breaking and counting
8096b46875cSArmin Le Grand             // on SfxStyleSheetBase constructors and destructors)
8106b46875cSArmin Le Grand             //
8116b46875cSArmin Le Grand 			// com::sun::star::uno::Reference< com::sun::star::lang::XComponent > xComp( static_cast< ::cppu::OWeakObject* >((*aIter).get()), com::sun::star::uno::UNO_QUERY );
8126b46875cSArmin Le Grand 			// if( xComp.is() ) try
8136b46875cSArmin Le Grand 			// {
8146b46875cSArmin Le Grand 			// 	xComp->dispose();
8156b46875cSArmin Le Grand 			// }
8166b46875cSArmin Le Grand 			// catch( com::sun::star::uno::Exception& )
8176b46875cSArmin Le Grand 			// {
8186b46875cSArmin Le Grand 			// }
819cdf0e10cSrcweir 
820cdf0e10cSrcweir 			aStyles.erase(aIter);
821cdf0e10cSrcweir 			Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *p ) );
822cdf0e10cSrcweir 		}
823cdf0e10cSrcweir 	}
824cdf0e10cSrcweir }
825cdf0e10cSrcweir 
Insert(SfxStyleSheetBase * p)826cdf0e10cSrcweir void SfxStyleSheetBasePool::Insert( SfxStyleSheetBase* p )
827cdf0e10cSrcweir {
828cdf0e10cSrcweir 	DBG_ASSERT( p, "svl::SfxStyleSheetBasePool::Insert(), no stylesheet?" );
829cdf0e10cSrcweir 
830cdf0e10cSrcweir 	SfxStyleSheetIterator aIter(this, p->GetFamily(), p->GetMask());
831cdf0e10cSrcweir 	SfxStyleSheetBase* pOld = aIter.Find( p->GetName() );
832cdf0e10cSrcweir 	DBG_ASSERT( !pOld, "svl::SfxStyleSheetBasePool::Insert(), StyleSheet already inserted" );
833cdf0e10cSrcweir 	if( p->GetParent().Len() )
834cdf0e10cSrcweir 	{
835cdf0e10cSrcweir 		pOld = aIter.Find( p->GetParent() );
836cdf0e10cSrcweir 		DBG_ASSERT( pOld, "svl::SfxStyleSheetBasePool::Insert(), Parent not found!" );
837cdf0e10cSrcweir 	}
838cdf0e10cSrcweir 	aStyles.push_back( rtl::Reference< SfxStyleSheetBase >( p ) );
839cdf0e10cSrcweir 	Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *p ) );
840cdf0e10cSrcweir }
841cdf0e10cSrcweir 
Clear()842cdf0e10cSrcweir void SfxStyleSheetBasePool::Clear()
843cdf0e10cSrcweir {
844cdf0e10cSrcweir 	SfxStyles aClearStyles;
845cdf0e10cSrcweir 	aClearStyles.swap( aStyles );
846cdf0e10cSrcweir 
847cdf0e10cSrcweir 	SfxStyles::iterator aIter( aClearStyles.begin() );
848cdf0e10cSrcweir 	while( aIter != aClearStyles.end() )
849cdf0e10cSrcweir 	{
850cdf0e10cSrcweir 		com::sun::star::uno::Reference< com::sun::star::lang::XComponent > xComp( static_cast< ::cppu::OWeakObject* >((*aIter).get()), com::sun::star::uno::UNO_QUERY );
851cdf0e10cSrcweir 		if( xComp.is() ) try
852cdf0e10cSrcweir 		{
853cdf0e10cSrcweir 			xComp->dispose();
854cdf0e10cSrcweir 		}
855cdf0e10cSrcweir 		catch( com::sun::star::uno::Exception& )
856cdf0e10cSrcweir 		{
857cdf0e10cSrcweir 		}
858cdf0e10cSrcweir 
859cdf0e10cSrcweir 		Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *(*aIter++).get() ) );
860cdf0e10cSrcweir 	}
861cdf0e10cSrcweir }
862cdf0e10cSrcweir 
863cdf0e10cSrcweir /////////////////////////// Parents umsetzen ////////////////////////////////
864cdf0e10cSrcweir 
ChangeParent(const XubString & rOld,const XubString & rNew,sal_Bool bVirtual)865cdf0e10cSrcweir void SfxStyleSheetBasePool::ChangeParent(const XubString& rOld,
866cdf0e10cSrcweir 										 const XubString& rNew,
867cdf0e10cSrcweir 										 sal_Bool bVirtual)
868cdf0e10cSrcweir {
869cdf0e10cSrcweir 	const sal_uInt16 nTmpMask = GetSearchMask();
870cdf0e10cSrcweir 	SetSearchMask(GetSearchFamily(), 0xffff);
871cdf0e10cSrcweir 	for( SfxStyleSheetBase* p = First(); p; p = Next() )
872cdf0e10cSrcweir 	{
873cdf0e10cSrcweir 		if( p->GetParent().Equals( rOld ) )
874cdf0e10cSrcweir 		{
875cdf0e10cSrcweir 			if(bVirtual)
876cdf0e10cSrcweir 				p->SetParent( rNew );
877cdf0e10cSrcweir 			else
878cdf0e10cSrcweir 				p->aParent = rNew;
879cdf0e10cSrcweir 		}
880cdf0e10cSrcweir 	}
881cdf0e10cSrcweir 	SetSearchMask(GetSearchFamily(), nTmpMask);
882cdf0e10cSrcweir }
883cdf0e10cSrcweir 
884cdf0e10cSrcweir /////////////////////////// Laden/Speichern /////////////////////////////////
885cdf0e10cSrcweir 
Load(SvStream &,sal_uInt16)886cdf0e10cSrcweir void SfxStyleSheetBase::Load( SvStream&, sal_uInt16 )
887cdf0e10cSrcweir {
888cdf0e10cSrcweir }
889cdf0e10cSrcweir 
Store(SvStream &)890cdf0e10cSrcweir void SfxStyleSheetBase::Store( SvStream& )
891cdf0e10cSrcweir {
892cdf0e10cSrcweir }
893cdf0e10cSrcweir 
894cdf0e10cSrcweir 
Load(SvStream & rStream)895cdf0e10cSrcweir sal_Bool SfxStyleSheetBasePool::Load( SvStream& rStream )
896cdf0e10cSrcweir {
897cdf0e10cSrcweir 	// alte Version?
898cdf0e10cSrcweir 	if ( !rPool.IsVer2_Impl() )
899cdf0e10cSrcweir 		return Load1_Impl( rStream );
900cdf0e10cSrcweir 
901cdf0e10cSrcweir 	// gesamten StyleSheetPool in neuer Version aus einem MiniRecord lesen
902cdf0e10cSrcweir 	SfxMiniRecordReader aPoolRec( &rStream, SFX_STYLES_REC );
903cdf0e10cSrcweir 
904cdf0e10cSrcweir 	// Header-Record lesen
905cdf0e10cSrcweir 	short nCharSet = 0;
906cdf0e10cSrcweir 	if ( !rStream.GetError() )
907cdf0e10cSrcweir 	{
908cdf0e10cSrcweir 		SfxSingleRecordReader aHeaderRec( &rStream, SFX_STYLES_REC_HEADER );
909cdf0e10cSrcweir 		if ( !aHeaderRec.IsValid() )
910cdf0e10cSrcweir 			return sal_False;
911cdf0e10cSrcweir 
912cdf0e10cSrcweir 		aAppName = rPool.GetName();
913cdf0e10cSrcweir 		rStream >> nCharSet;
914cdf0e10cSrcweir 	}
915cdf0e10cSrcweir 
916cdf0e10cSrcweir 	// Styles-Record lesen
917cdf0e10cSrcweir 	if ( !rStream.GetError() )
918cdf0e10cSrcweir 	{
919cdf0e10cSrcweir 		SfxMultiRecordReader aStylesRec( &rStream, SFX_STYLES_REC_STYLES );
920cdf0e10cSrcweir 		if ( !aStylesRec.IsValid() )
921cdf0e10cSrcweir 			return sal_False;
922cdf0e10cSrcweir 
923cdf0e10cSrcweir 		rtl_TextEncoding eEnc = GetSOLoadTextEncoding(
924cdf0e10cSrcweir             (rtl_TextEncoding)nCharSet,
925cdf0e10cSrcweir             sal::static_int_cast< sal_uInt16 >(rStream.GetVersion()) );
926cdf0e10cSrcweir 		rtl_TextEncoding eOldEnc = rStream.GetStreamCharSet();
927cdf0e10cSrcweir 		rStream.SetStreamCharSet( eEnc );
928cdf0e10cSrcweir 
929cdf0e10cSrcweir 		sal_uInt16 nStyles;
930cdf0e10cSrcweir 		for ( nStyles = 0; aStylesRec.GetContent(); nStyles++ )
931cdf0e10cSrcweir 		{
932cdf0e10cSrcweir 			// kann nicht mehr weiterlesen?
933cdf0e10cSrcweir 			if ( rStream.GetError() )
934cdf0e10cSrcweir 				break;
935cdf0e10cSrcweir 
936cdf0e10cSrcweir 			// Globale Teile
937cdf0e10cSrcweir 			XubString aName, aParent, aFollow;
938cdf0e10cSrcweir 			String aHelpFile;
939cdf0e10cSrcweir 			sal_uInt16 nFamily, nStyleMask,nCount;
940cdf0e10cSrcweir 			sal_uInt32 nHelpId;
941cdf0e10cSrcweir 			rStream.ReadByteString(aName, eEnc );
942cdf0e10cSrcweir 			rStream.ReadByteString(aParent, eEnc );
943cdf0e10cSrcweir 			rStream.ReadByteString(aFollow, eEnc );
944cdf0e10cSrcweir 			rStream >> nFamily >> nStyleMask;
945cdf0e10cSrcweir 			SfxPoolItem::readByteString(rStream, aHelpFile);
946cdf0e10cSrcweir 			rStream >> nHelpId;
947cdf0e10cSrcweir 
948cdf0e10cSrcweir 			SfxStyleSheetBase& rSheet = Make( aName, (SfxStyleFamily)nFamily , nStyleMask);
949cdf0e10cSrcweir 			rSheet.SetHelpId( aHelpFile, nHelpId );
950cdf0e10cSrcweir 			// Hier erst einmal Parent und Follow zwischenspeichern
951cdf0e10cSrcweir 			rSheet.aParent = aParent;
952cdf0e10cSrcweir 			rSheet.aFollow = aFollow;
953cdf0e10cSrcweir 			sal_uInt32 nPos = rStream.Tell();
954cdf0e10cSrcweir 			rStream >> nCount;
955cdf0e10cSrcweir 			if(nCount)
956cdf0e10cSrcweir 			{
957cdf0e10cSrcweir 				rStream.Seek( nPos );
958cdf0e10cSrcweir 				// Das Laden des ItemSets bedient sich der Methode GetItemSet(),
959cdf0e10cSrcweir 				// damit eigene ItemSets untergeschoben werden koennen
960cdf0e10cSrcweir 				SfxItemSet& rSet = rSheet.GetItemSet();
961cdf0e10cSrcweir 				rSet.ClearItem();
962cdf0e10cSrcweir 	//! 		SfxItemSet aTmpSet( *pTmpPool );
963cdf0e10cSrcweir 				/*!aTmpSet*/ rSet.Load( rStream );
964cdf0e10cSrcweir 				//! rSet.Put( aTmpSet );
965cdf0e10cSrcweir 			}
966cdf0e10cSrcweir 			// Lokale Teile
967cdf0e10cSrcweir 			sal_uInt32 nSize;
968cdf0e10cSrcweir 			sal_uInt16 nVer;
969cdf0e10cSrcweir 			rStream >> nVer >> nSize;
970cdf0e10cSrcweir 			nPos = rStream.Tell() + nSize;
971cdf0e10cSrcweir 			rSheet.Load( rStream, nVer );
972cdf0e10cSrcweir 			rStream.Seek( nPos );
973cdf0e10cSrcweir 		}
974cdf0e10cSrcweir 
975cdf0e10cSrcweir 		//	#72939# only loop through the styles that were really inserted
976cdf0e10cSrcweir 		sal_uLong n = aStyles.size();
977cdf0e10cSrcweir 
978cdf0e10cSrcweir 		//! delete pTmpPool;
979cdf0e10cSrcweir 		// Jetzt Parent und Follow setzen. Alle Sheets sind geladen.
980cdf0e10cSrcweir 		// Mit Setxxx() noch einmal den String eintragen, da diese
981cdf0e10cSrcweir 		// virtuellen Methoden evtl. ueberlagert sind.
982cdf0e10cSrcweir 		for ( sal_uLong i = 0; i < n; i++ )
983cdf0e10cSrcweir 		{
984cdf0e10cSrcweir 			SfxStyleSheetBase* p = aStyles[ i ].get();
985cdf0e10cSrcweir 			XubString aText = p->aParent;
986cdf0e10cSrcweir 			p->aParent.Erase();
987cdf0e10cSrcweir 			p->SetParent( aText );
988cdf0e10cSrcweir 			aText = p->aFollow;
989cdf0e10cSrcweir 			p->aFollow.Erase();
990cdf0e10cSrcweir 			p->SetFollow( aText );
991cdf0e10cSrcweir 		}
992cdf0e10cSrcweir 
993cdf0e10cSrcweir 		rStream.SetStreamCharSet( eOldEnc );
994cdf0e10cSrcweir 	}
995cdf0e10cSrcweir 
996cdf0e10cSrcweir 	// alles klar?
997cdf0e10cSrcweir 	return sal_Bool( rStream.GetError() == SVSTREAM_OK );
998cdf0e10cSrcweir }
999cdf0e10cSrcweir 
Load1_Impl(SvStream & rStream)1000cdf0e10cSrcweir sal_Bool SfxStyleSheetBasePool::Load1_Impl( SvStream& rStream )
1001cdf0e10cSrcweir {
1002cdf0e10cSrcweir 	aAppName = rPool.GetName();
1003cdf0e10cSrcweir 	sal_uInt16 nVersion;
1004cdf0e10cSrcweir 	short nCharSet;
1005cdf0e10cSrcweir 	rStream >> nVersion;
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir 	if(nVersion!=STYLESTREAM_VERSION)
1008cdf0e10cSrcweir 		nCharSet=nVersion;
1009cdf0e10cSrcweir 	else
1010cdf0e10cSrcweir 		rStream >> nCharSet;
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir 	rtl_TextEncoding eEnc = GetSOLoadTextEncoding(
1013cdf0e10cSrcweir         (rtl_TextEncoding)nCharSet,
1014cdf0e10cSrcweir         sal::static_int_cast< sal_uInt16 >(rStream.GetVersion()) );
1015cdf0e10cSrcweir 	rtl_TextEncoding eOldEnc = rStream.GetStreamCharSet();
1016cdf0e10cSrcweir 	rStream.SetStreamCharSet( eEnc );
1017cdf0e10cSrcweir 
1018cdf0e10cSrcweir 	sal_uInt16 nStyles;
1019cdf0e10cSrcweir 	rStream >> nStyles;
1020cdf0e10cSrcweir 	sal_uInt16 i;
1021cdf0e10cSrcweir 	for ( i = 0; i < nStyles; i++ )
1022cdf0e10cSrcweir 	{
1023cdf0e10cSrcweir 		// kann nicht mehr weiterlesen?
1024cdf0e10cSrcweir 		if ( rStream.GetError() )
1025cdf0e10cSrcweir 		{
1026cdf0e10cSrcweir 			nStyles = i;
1027cdf0e10cSrcweir 			break;
1028cdf0e10cSrcweir 		}
1029cdf0e10cSrcweir 
1030cdf0e10cSrcweir 		// Globale Teile
1031cdf0e10cSrcweir 		XubString aName, aParent, aFollow;
1032cdf0e10cSrcweir 		String aHelpFile;
1033cdf0e10cSrcweir 		sal_uInt16 nFamily, nStyleMask,nCount;
1034cdf0e10cSrcweir 		sal_uInt32 nHelpId;
1035cdf0e10cSrcweir 		rStream.ReadByteString(aName, eEnc );
1036cdf0e10cSrcweir 		rStream.ReadByteString(aParent, eEnc );
1037cdf0e10cSrcweir 		rStream.ReadByteString(aFollow, eEnc );
1038cdf0e10cSrcweir 		rStream >> nFamily >> nStyleMask;
1039cdf0e10cSrcweir 		SfxPoolItem::readByteString(rStream, aHelpFile);
1040cdf0e10cSrcweir 		if(nVersion!=STYLESTREAM_VERSION)
1041cdf0e10cSrcweir 		{
1042cdf0e10cSrcweir 			sal_uInt16 nTmpHelpId;
1043cdf0e10cSrcweir 			rStream >> nTmpHelpId;
1044cdf0e10cSrcweir 			nHelpId=nTmpHelpId;
1045cdf0e10cSrcweir 		}
1046cdf0e10cSrcweir 		else
1047cdf0e10cSrcweir 			rStream >> nHelpId;
1048cdf0e10cSrcweir 
1049cdf0e10cSrcweir 		SfxStyleSheetBase& rSheet = Make( aName, (SfxStyleFamily)nFamily , nStyleMask);
1050cdf0e10cSrcweir 		rSheet.SetHelpId( aHelpFile, nHelpId );
1051cdf0e10cSrcweir 		// Hier erst einmal Parent und Follow zwischenspeichern
1052cdf0e10cSrcweir 		rSheet.aParent = aParent;
1053cdf0e10cSrcweir 		rSheet.aFollow = aFollow;
1054cdf0e10cSrcweir 		sal_uInt32 nPos = rStream.Tell();
1055cdf0e10cSrcweir 		rStream >> nCount;
1056cdf0e10cSrcweir 		if(nCount) {
1057cdf0e10cSrcweir 			rStream.Seek( nPos );
1058cdf0e10cSrcweir 			// Das Laden des ItemSets bedient sich der Methode GetItemSet(),
1059cdf0e10cSrcweir 			// damit eigene ItemSets untergeschoben werden koennen
1060cdf0e10cSrcweir 			SfxItemSet& rSet = rSheet.GetItemSet();
1061cdf0e10cSrcweir 			rSet.ClearItem();
1062cdf0e10cSrcweir //! 		SfxItemSet aTmpSet( *pTmpPool );
1063cdf0e10cSrcweir 			/*!aTmpSet*/ rSet.Load( rStream );
1064cdf0e10cSrcweir 			//! rSet.Put( aTmpSet );
1065cdf0e10cSrcweir 		}
1066cdf0e10cSrcweir 		// Lokale Teile
1067cdf0e10cSrcweir 		sal_uInt32 nSize;
1068cdf0e10cSrcweir 		sal_uInt16 nVer;
1069cdf0e10cSrcweir 		rStream >> nVer >> nSize;
1070cdf0e10cSrcweir 		nPos = rStream.Tell() + nSize;
1071cdf0e10cSrcweir 		rSheet.Load( rStream, nVer );
1072cdf0e10cSrcweir 		rStream.Seek( nPos );
1073cdf0e10cSrcweir 	}
1074cdf0e10cSrcweir 
1075cdf0e10cSrcweir 	//! delete pTmpPool;
1076cdf0e10cSrcweir 	// Jetzt Parent und Follow setzen. Alle Sheets sind geladen.
1077cdf0e10cSrcweir 	// Mit Setxxx() noch einmal den String eintragen, da diese
1078cdf0e10cSrcweir 	// virtuellen Methoden evtl. ueberlagert sind.
1079cdf0e10cSrcweir 	for ( i = 0; i < nStyles; i++ )
1080cdf0e10cSrcweir 	{
1081cdf0e10cSrcweir 		SfxStyleSheetBase* p = aStyles[ i ].get();
1082cdf0e10cSrcweir 		XubString aText = p->aParent;
1083cdf0e10cSrcweir 		p->aParent.Erase();
1084cdf0e10cSrcweir 		p->SetParent( aText );
1085cdf0e10cSrcweir 		aText = p->aFollow;
1086cdf0e10cSrcweir 		p->aFollow.Erase();
1087cdf0e10cSrcweir 		p->SetFollow( aText );
1088cdf0e10cSrcweir 	}
1089cdf0e10cSrcweir 
1090cdf0e10cSrcweir 	rStream.SetStreamCharSet( eOldEnc );
1091cdf0e10cSrcweir 
1092cdf0e10cSrcweir 	return sal_Bool( rStream.GetError() == SVSTREAM_OK );
1093cdf0e10cSrcweir }
1094cdf0e10cSrcweir 
Store(SvStream & rStream,sal_Bool bUsed)1095cdf0e10cSrcweir sal_Bool SfxStyleSheetBasePool::Store( SvStream& rStream, sal_Bool bUsed )
1096cdf0e10cSrcweir {
1097cdf0e10cSrcweir 	// den ganzen StyleSheet-Pool in einen Mini-Record
1098cdf0e10cSrcweir 	SfxMiniRecordWriter aPoolRec( &rStream, SFX_STYLES_REC );
1099cdf0e10cSrcweir 
1100cdf0e10cSrcweir 	// Erst einmal die Dummies rauszaehlen; die werden nicht gespeichert
1101cdf0e10cSrcweir 	sal_uInt16 nCount = 0;
1102cdf0e10cSrcweir 	for( SfxStyleSheetBase* p = First(); p; p = Next() )
1103cdf0e10cSrcweir 	{
1104cdf0e10cSrcweir 		if(!bUsed || p->IsUsed())
1105cdf0e10cSrcweir 			nCount++;
1106cdf0e10cSrcweir 	}
1107cdf0e10cSrcweir 
1108cdf0e10cSrcweir 	// einen Header-Record vorweg
1109cdf0e10cSrcweir 	rtl_TextEncoding eEnc
1110cdf0e10cSrcweir 		= ::GetSOStoreTextEncoding(
1111cdf0e10cSrcweir             rStream.GetStreamCharSet(),
1112cdf0e10cSrcweir             sal::static_int_cast< sal_uInt16 >(rStream.GetVersion()) );
1113cdf0e10cSrcweir 	rtl_TextEncoding eOldEnc = rStream.GetStreamCharSet();
1114cdf0e10cSrcweir 	rStream.SetStreamCharSet( eEnc );
1115cdf0e10cSrcweir 
1116cdf0e10cSrcweir 	{
1117cdf0e10cSrcweir 		SfxSingleRecordWriter aHeaderRec( &rStream,
1118cdf0e10cSrcweir 				SFX_STYLES_REC_HEADER,
1119cdf0e10cSrcweir 				STYLESTREAM_VERSION );
1120cdf0e10cSrcweir 		rStream << (short) eEnc;
1121cdf0e10cSrcweir 	}
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir 	// die StyleSheets in einen MultiVarRecord
1124cdf0e10cSrcweir 	{
1125cdf0e10cSrcweir 		// Bug 79478:
1126cdf0e10cSrcweir 		// make a check loop, to be shure, that the converted names are also
1127cdf0e10cSrcweir 		// unique like the originals! In other cases we get a loop.
1128cdf0e10cSrcweir 		SvStringsSortDtor aSortOrigNames( 0, 128 );
1129cdf0e10cSrcweir 		SvStrings aOrigNames( 0, 128 );
1130cdf0e10cSrcweir 		SvByteStringsSortDtor aSortConvNames( 0, 128 );
1131cdf0e10cSrcweir 		SvByteStrings aConvNames( 0, 128 );
1132cdf0e10cSrcweir 
1133cdf0e10cSrcweir 		{
1134cdf0e10cSrcweir 
1135cdf0e10cSrcweir 			for( SfxStyleSheetBase* p = First(); p; p = Next() )
1136cdf0e10cSrcweir 			{
1137cdf0e10cSrcweir 				if(!bUsed || p->IsUsed())
1138cdf0e10cSrcweir 				{
1139cdf0e10cSrcweir 					sal_uInt16 nFamily = (sal_uInt16)p->GetFamily();
1140cdf0e10cSrcweir 					String* pName = new String( p->GetName() );
1141cdf0e10cSrcweir 					ByteString* pConvName = new ByteString( *pName, eEnc );
1142cdf0e10cSrcweir 
1143cdf0e10cSrcweir 					pName->Insert( (sal_Unicode)nFamily, 0 );
1144cdf0e10cSrcweir 					pConvName->Insert( "  ", 0 );
1145cdf0e10cSrcweir 					pConvName->SetChar(
1146cdf0e10cSrcweir                         0,
1147cdf0e10cSrcweir                         sal::static_int_cast< char >(0xff & (nFamily >> 8)) );
1148cdf0e10cSrcweir 					pConvName->SetChar(
1149cdf0e10cSrcweir                         1, sal::static_int_cast< char >(0xff & nFamily) );
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir 					sal_uInt16 nInsPos, nAdd = aSortConvNames.Count();
1152cdf0e10cSrcweir 					while( !aSortConvNames.Insert( pConvName, nInsPos ) )
1153cdf0e10cSrcweir 						(pConvName->Append( '_' )).Append(
1154cdf0e10cSrcweir 									ByteString::CreateFromInt32( nAdd++ ));
1155cdf0e10cSrcweir 					aOrigNames.Insert( pName, nInsPos );
1156cdf0e10cSrcweir 				}
1157cdf0e10cSrcweir 			}
1158cdf0e10cSrcweir 
1159cdf0e10cSrcweir 			// now we have the list of the names, sorted by convertede names
1160cdf0e10cSrcweir 			// But now we need the sorted list of orignames.
1161cdf0e10cSrcweir 			{
1162cdf0e10cSrcweir 				sal_uInt16 nInsPos, nEnd = aOrigNames.Count();
1163cdf0e10cSrcweir 				const ByteStringPtr* ppB = aSortConvNames.GetData();
1164cdf0e10cSrcweir 				for( sal_uInt16 n = 0; n < nEnd; ++n, ++ppB )
1165cdf0e10cSrcweir 				{
1166cdf0e10cSrcweir 					String* p = aOrigNames.GetObject( n );
1167cdf0e10cSrcweir 					aSortOrigNames.Insert( p, nInsPos );
1168cdf0e10cSrcweir 					aConvNames.Insert( *ppB, nInsPos );
1169cdf0e10cSrcweir 				}
1170cdf0e10cSrcweir 
1171cdf0e10cSrcweir 			}
1172cdf0e10cSrcweir 		}
1173cdf0e10cSrcweir 
1174cdf0e10cSrcweir 
1175cdf0e10cSrcweir 		ByteString sEmpty;
1176cdf0e10cSrcweir 		sal_uInt16 nFndPos;
1177cdf0e10cSrcweir 		String sNm;
1178cdf0e10cSrcweir 		SfxMultiVarRecordWriter aStylesRec( &rStream, SFX_STYLES_REC_STYLES, 0 );
1179cdf0e10cSrcweir 		for( SfxStyleSheetBase* p = First(); p; p = Next() )
1180cdf0e10cSrcweir 		{
1181cdf0e10cSrcweir 			if(!bUsed || p->IsUsed())
1182cdf0e10cSrcweir 			{
1183cdf0e10cSrcweir 				aStylesRec.NewContent();
1184cdf0e10cSrcweir 
1185cdf0e10cSrcweir 				// Globale Teile speichern
1186cdf0e10cSrcweir 				String aHelpFile;
1187cdf0e10cSrcweir 				sal_uInt32 nHelpId = p->GetHelpId( aHelpFile );
1188cdf0e10cSrcweir 				sal_uInt16 nFamily = sal::static_int_cast< sal_uInt16 >(p->GetFamily());
1189cdf0e10cSrcweir 				String sFamily( (sal_Unicode)nFamily );
1190cdf0e10cSrcweir 
1191cdf0e10cSrcweir 				(sNm = sFamily) += p->GetName();
1192cdf0e10cSrcweir 				if( aSortOrigNames.Seek_Entry( &sNm, &nFndPos ))
1193cdf0e10cSrcweir 					rStream.WriteByteString( aConvNames.GetObject( nFndPos )->Copy( 2 ));
1194cdf0e10cSrcweir 				else
1195cdf0e10cSrcweir 					rStream.WriteByteString( sEmpty );
1196cdf0e10cSrcweir 
1197cdf0e10cSrcweir 				(sNm = sFamily) += p->GetParent();
1198cdf0e10cSrcweir 				if( aSortOrigNames.Seek_Entry( &sNm, &nFndPos ))
1199cdf0e10cSrcweir 					rStream.WriteByteString( aConvNames.GetObject( nFndPos )->Copy( 2 ));
1200cdf0e10cSrcweir 				else
1201cdf0e10cSrcweir 					rStream.WriteByteString( sEmpty );
1202cdf0e10cSrcweir 
1203cdf0e10cSrcweir 				(sNm = sFamily) += p->GetFollow();
1204cdf0e10cSrcweir 				if( aSortOrigNames.Seek_Entry( &sNm, &nFndPos ))
1205cdf0e10cSrcweir 					rStream.WriteByteString( aConvNames.GetObject( nFndPos )->Copy( 2 ));
1206cdf0e10cSrcweir 				else
1207cdf0e10cSrcweir 					rStream.WriteByteString( sEmpty );
1208cdf0e10cSrcweir 
1209cdf0e10cSrcweir 				rStream << nFamily << p->GetMask();
1210cdf0e10cSrcweir 				SfxPoolItem::writeByteString(rStream, aHelpFile);
1211cdf0e10cSrcweir 				rStream << nHelpId;
1212cdf0e10cSrcweir 				if(p->pSet)
1213cdf0e10cSrcweir 					p->pSet->Store( rStream );
1214cdf0e10cSrcweir 				else
1215cdf0e10cSrcweir 					rStream << (sal_uInt16)0;
1216cdf0e10cSrcweir 
1217cdf0e10cSrcweir 				// Lokale Teile speichern
1218cdf0e10cSrcweir 				// Vor dem lokalen Teil wird die Laenge der lokalen Daten
1219cdf0e10cSrcweir 				// als sal_uInt32 sowie die Versionsnummer gespeichert.
1220cdf0e10cSrcweir 				rStream << (sal_uInt16) p->GetVersion();
1221cdf0e10cSrcweir 				sal_uLong nPos1 = rStream.Tell();
1222cdf0e10cSrcweir 				rStream << (sal_uInt32) 0;
1223cdf0e10cSrcweir 				p->Store( rStream );
1224cdf0e10cSrcweir 				sal_uLong nPos2 = rStream.Tell();
1225cdf0e10cSrcweir 				rStream.Seek( nPos1 );
1226cdf0e10cSrcweir 				rStream << (sal_uInt32) ( nPos2 - nPos1 - sizeof( sal_uInt32 ) );
1227cdf0e10cSrcweir 				rStream.Seek( nPos2 );
1228cdf0e10cSrcweir 				if( rStream.GetError() != SVSTREAM_OK )
1229cdf0e10cSrcweir 					break;
1230cdf0e10cSrcweir 			}
1231cdf0e10cSrcweir 		}
1232cdf0e10cSrcweir 	}
1233cdf0e10cSrcweir 
1234cdf0e10cSrcweir 	rStream.SetStreamCharSet( eOldEnc );
1235cdf0e10cSrcweir 
1236cdf0e10cSrcweir 	return sal_Bool( rStream.GetError() == SVSTREAM_OK );
1237cdf0e10cSrcweir }
1238cdf0e10cSrcweir 
GetPool()1239cdf0e10cSrcweir SfxItemPool& SfxStyleSheetBasePool::GetPool()
1240cdf0e10cSrcweir {
1241cdf0e10cSrcweir 	return rPool;
1242cdf0e10cSrcweir }
1243cdf0e10cSrcweir 
GetPool() const1244cdf0e10cSrcweir const SfxItemPool& SfxStyleSheetBasePool::GetPool() const
1245cdf0e10cSrcweir {
1246cdf0e10cSrcweir 	return rPool;
1247cdf0e10cSrcweir }
1248cdf0e10cSrcweir 
1249cdf0e10cSrcweir /////////////////////// SfxStyleSheet /////////////////////////////////
1250cdf0e10cSrcweir 
SfxStyleSheet(const XubString & rName,const SfxStyleSheetBasePool & r_Pool,SfxStyleFamily eFam,sal_uInt16 mask)1251cdf0e10cSrcweir SfxStyleSheet::SfxStyleSheet(const XubString &rName,
1252cdf0e10cSrcweir 							 const SfxStyleSheetBasePool& r_Pool,
1253cdf0e10cSrcweir 							 SfxStyleFamily eFam,
1254cdf0e10cSrcweir 							 sal_uInt16 mask ):
1255cdf0e10cSrcweir 	SfxStyleSheetBase(rName, const_cast< SfxStyleSheetBasePool& >( r_Pool ), eFam, mask)
1256cdf0e10cSrcweir {}
1257cdf0e10cSrcweir 
SfxStyleSheet(const SfxStyleSheet & rStyle)1258cdf0e10cSrcweir SfxStyleSheet::SfxStyleSheet(const SfxStyleSheet& rStyle) :
1259cdf0e10cSrcweir 	SfxStyleSheetBase(rStyle),
1260cdf0e10cSrcweir     SfxListener( rStyle ),
1261cdf0e10cSrcweir     SfxBroadcaster( rStyle )
1262cdf0e10cSrcweir {}
1263cdf0e10cSrcweir 
SfxStyleSheet()1264cdf0e10cSrcweir SfxStyleSheet::SfxStyleSheet()
1265cdf0e10cSrcweir {
1266cdf0e10cSrcweir }
1267cdf0e10cSrcweir 
~SfxStyleSheet()1268cdf0e10cSrcweir SfxStyleSheet::~SfxStyleSheet()
1269cdf0e10cSrcweir {
1270cdf0e10cSrcweir 	Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_INDESTRUCTION, *this ) );
1271cdf0e10cSrcweir }
1272cdf0e10cSrcweir 
1273cdf0e10cSrcweir 
SetParent(const XubString & rName)1274cdf0e10cSrcweir sal_Bool SfxStyleSheet::SetParent( const XubString& rName )
1275cdf0e10cSrcweir {
1276cdf0e10cSrcweir 	if(aParent == rName)
1277cdf0e10cSrcweir 		return sal_True;
1278cdf0e10cSrcweir 	const XubString aOldParent(aParent);
1279cdf0e10cSrcweir 	if(SfxStyleSheetBase::SetParent(rName)) {
1280cdf0e10cSrcweir 			// aus der Benachrichtigungskette des alten
1281cdf0e10cSrcweir 			// Parents gfs. austragen
1282cdf0e10cSrcweir 		if(aOldParent.Len()) {
1283cdf0e10cSrcweir 			SfxStyleSheet *pParent = (SfxStyleSheet *)rPool.Find(aOldParent, nFamily, 0xffff);
1284cdf0e10cSrcweir 			if(pParent)
1285cdf0e10cSrcweir 				EndListening(*pParent);
1286cdf0e10cSrcweir 		}
1287cdf0e10cSrcweir 			// in die Benachrichtigungskette des neuen
1288cdf0e10cSrcweir 			// Parents eintragen
1289cdf0e10cSrcweir 		if(aParent.Len()) {
1290cdf0e10cSrcweir 			SfxStyleSheet *pParent = (SfxStyleSheet *)rPool.Find(aParent, nFamily, 0xffff);
1291cdf0e10cSrcweir 			if(pParent)
1292cdf0e10cSrcweir 				StartListening(*pParent);
1293cdf0e10cSrcweir 		}
1294cdf0e10cSrcweir 		return sal_True;
1295cdf0e10cSrcweir 	}
1296cdf0e10cSrcweir 	return sal_False;
1297cdf0e10cSrcweir }
1298cdf0e10cSrcweir 
1299cdf0e10cSrcweir // alle Zuhoerer benachtichtigen
1300cdf0e10cSrcweir 
Notify(SfxBroadcaster & rBC,const SfxHint & rHint)1301cdf0e10cSrcweir void SfxStyleSheet::Notify(SfxBroadcaster& rBC, const SfxHint& rHint )
1302cdf0e10cSrcweir {
1303cdf0e10cSrcweir 	Forward(rBC, rHint);
1304cdf0e10cSrcweir }
1305cdf0e10cSrcweir 
1306cdf0e10cSrcweir //////////////////////// SfxStyleSheetPool ///////////////////////////////
1307cdf0e10cSrcweir 
SfxStyleSheetPool(SfxItemPool const & rSet)1308cdf0e10cSrcweir SfxStyleSheetPool::SfxStyleSheetPool( SfxItemPool const& rSet)
1309cdf0e10cSrcweir : SfxStyleSheetBasePool( const_cast< SfxItemPool& >( rSet ) )
1310cdf0e10cSrcweir {
1311cdf0e10cSrcweir }
1312cdf0e10cSrcweir 
1313cdf0e10cSrcweir /////////////////////////////////// Factory ////////////////////////////////
1314cdf0e10cSrcweir 
Create(const XubString & rName,SfxStyleFamily eFam,sal_uInt16 mask)1315cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetPool::Create( const XubString& rName,
1316cdf0e10cSrcweir 									SfxStyleFamily eFam, sal_uInt16 mask )
1317cdf0e10cSrcweir {
1318cdf0e10cSrcweir 	return new SfxStyleSheet( rName, *this, eFam, mask );
1319cdf0e10cSrcweir }
1320cdf0e10cSrcweir 
Create(const SfxStyleSheet & r)1321cdf0e10cSrcweir SfxStyleSheetBase* SfxStyleSheetPool::Create( const SfxStyleSheet& r )
1322cdf0e10cSrcweir {
1323cdf0e10cSrcweir 	return new SfxStyleSheet( r );
1324cdf0e10cSrcweir }
1325cdf0e10cSrcweir /*
1326cdf0e10cSrcweir sal_Bool SfxStyleSheetPool::CopyTo(SfxStyleSheetPool &, const String &)
1327cdf0e10cSrcweir {
1328cdf0e10cSrcweir 	return sal_False;
1329cdf0e10cSrcweir }
1330cdf0e10cSrcweir */
1331cdf0e10cSrcweir 
1332cdf0e10cSrcweir // --------------------------------------------------------------------
1333cdf0e10cSrcweir // class SfxUnoStyleSheet
1334cdf0e10cSrcweir // --------------------------------------------------------------------
1335cdf0e10cSrcweir 
SfxUnoStyleSheet(const UniString & _rName,const SfxStyleSheetBasePool & _rPool,SfxStyleFamily _eFamily,sal_uInt16 _nMaske)1336cdf0e10cSrcweir SfxUnoStyleSheet::SfxUnoStyleSheet( const UniString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, sal_uInt16 _nMaske )
1337cdf0e10cSrcweir : ::cppu::ImplInheritanceHelper2< SfxStyleSheet, ::com::sun::star::style::XStyle, ::com::sun::star::lang::XUnoTunnel >( _rName, _rPool, _eFamily, _nMaske )
1338cdf0e10cSrcweir {
1339cdf0e10cSrcweir }
1340cdf0e10cSrcweir 
1341cdf0e10cSrcweir // --------------------------------------------------------------------
SfxUnoStyleSheet(const SfxStyleSheet & _rSheet)1342cdf0e10cSrcweir SfxUnoStyleSheet::SfxUnoStyleSheet( const SfxStyleSheet& _rSheet )
1343cdf0e10cSrcweir : ::cppu::ImplInheritanceHelper2< SfxStyleSheet, ::com::sun::star::style::XStyle, ::com::sun::star::lang::XUnoTunnel >( _rSheet )
1344cdf0e10cSrcweir {
1345cdf0e10cSrcweir }
1346cdf0e10cSrcweir 
1347cdf0e10cSrcweir // --------------------------------------------------------------------
1348cdf0e10cSrcweir 
getUnoStyleSheet(const::com::sun::star::uno::Reference<::com::sun::star::style::XStyle> & xStyle)1349cdf0e10cSrcweir SfxUnoStyleSheet* SfxUnoStyleSheet::getUnoStyleSheet( const ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle >& xStyle )
1350cdf0e10cSrcweir {
1351cdf0e10cSrcweir 	SfxUnoStyleSheet* pRet = dynamic_cast< SfxUnoStyleSheet* >( xStyle.get() );
1352cdf0e10cSrcweir 	if( !pRet )
1353cdf0e10cSrcweir 	{
1354cdf0e10cSrcweir 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( xStyle, ::com::sun::star::uno::UNO_QUERY );
1355cdf0e10cSrcweir 		if( xUT.is() )
1356cdf0e10cSrcweir 			pRet = reinterpret_cast<SfxUnoStyleSheet*>(sal::static_int_cast<sal_uIntPtr>(xUT->getSomething( SfxUnoStyleSheet::getIdentifier())));
1357cdf0e10cSrcweir 	}
1358cdf0e10cSrcweir 	return pRet;
1359cdf0e10cSrcweir }
1360cdf0e10cSrcweir 
1361cdf0e10cSrcweir // --------------------------------------------------------------------
1362cdf0e10cSrcweir // XUnoTunnel
1363cdf0e10cSrcweir // --------------------------------------------------------------------
1364cdf0e10cSrcweir 
getSomething(const::com::sun::star::uno::Sequence<::sal_Int8> & rId)1365cdf0e10cSrcweir ::sal_Int64 SAL_CALL SfxUnoStyleSheet::getSomething( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& rId ) throw (::com::sun::star::uno::RuntimeException)
1366cdf0e10cSrcweir {
1367cdf0e10cSrcweir 	if( rId.getLength() == 16 && 0 == rtl_compareMemory( getIdentifier().getConstArray(), rId.getConstArray(), 16 ) )
1368cdf0e10cSrcweir 	{
1369cdf0e10cSrcweir 		return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
1370cdf0e10cSrcweir 	}
1371cdf0e10cSrcweir 	else
1372cdf0e10cSrcweir 	{
1373cdf0e10cSrcweir 		return 0;
1374cdf0e10cSrcweir 	}
1375cdf0e10cSrcweir }
1376cdf0e10cSrcweir 
1377cdf0e10cSrcweir // --------------------------------------------------------------------
1378cdf0e10cSrcweir 
getIdentifier()1379cdf0e10cSrcweir const ::com::sun::star::uno::Sequence< ::sal_Int8 >& SfxUnoStyleSheet::getIdentifier()
1380cdf0e10cSrcweir {
1381cdf0e10cSrcweir 	static ::com::sun::star::uno::Sequence< sal_Int8 > * pSeq = 0;
1382cdf0e10cSrcweir 	if( !pSeq )
1383cdf0e10cSrcweir 	{
1384cdf0e10cSrcweir 		::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
1385cdf0e10cSrcweir 		if( !pSeq )
1386cdf0e10cSrcweir 		{
1387cdf0e10cSrcweir 			static ::com::sun::star::uno::Sequence< sal_Int8 > aSeq( 16 );
1388cdf0e10cSrcweir 			rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
1389cdf0e10cSrcweir 			pSeq = &aSeq;
1390cdf0e10cSrcweir 		}
1391cdf0e10cSrcweir 	}
1392cdf0e10cSrcweir 	return *pSeq;
1393cdf0e10cSrcweir }
1394cdf0e10cSrcweir 
1395cdf0e10cSrcweir // --------------------------------------------------------------------
1396