xref: /aoo42x/main/xmloff/source/style/impastp4.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
30*cdf0e10cSrcweir #include <tools/debug.hxx>
31*cdf0e10cSrcweir #include <xmloff/xmlaustp.hxx>
32*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
33*cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
34*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
35*cdf0e10cSrcweir #include <xmloff/attrlist.hxx>
36*cdf0e10cSrcweir #include "impastpl.hxx"
37*cdf0e10cSrcweir #include <xmloff/xmlexppr.hxx>
38*cdf0e10cSrcweir #include <xmloff/xmlexp.hxx>
39*cdf0e10cSrcweir #include <xmloff/families.hxx>
40*cdf0e10cSrcweir #ifndef _XMLOFF_PAGEMASTERSTYLEMAP_HXX
41*cdf0e10cSrcweir #include <xmloff/PageMasterStyleMap.hxx>
42*cdf0e10cSrcweir #endif
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir using namespace ::std;
45*cdf0e10cSrcweir using ::rtl::OUString;
46*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir using namespace ::com::sun::star;
49*cdf0e10cSrcweir using namespace ::xmloff::token;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir //#############################################################################
52*cdf0e10cSrcweir //
53*cdf0e10cSrcweir // Class SvXMLAutoStylePool_Impl
54*cdf0e10cSrcweir //
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
57*cdf0e10cSrcweir //
58*cdf0e10cSrcweir // ctor/dtor class SvXMLAutoStylePool_Impl
59*cdf0e10cSrcweir //
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir SvXMLAutoStylePoolP_Impl::SvXMLAutoStylePoolP_Impl( SvXMLExport& rExp)
62*cdf0e10cSrcweir     :	rExport( rExp ),
63*cdf0e10cSrcweir         maFamilyList( 5, 5 )
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir }
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir SvXMLAutoStylePoolP_Impl::~SvXMLAutoStylePoolP_Impl()
68*cdf0e10cSrcweir {
69*cdf0e10cSrcweir 	for (;;) {
70*cdf0e10cSrcweir         XMLFamilyData_Impl* pData = maFamilyList.Remove( sal_uLong(0) );
71*cdf0e10cSrcweir         if (pData == NULL) {
72*cdf0e10cSrcweir             break;
73*cdf0e10cSrcweir         }
74*cdf0e10cSrcweir 		delete pData;
75*cdf0e10cSrcweir     }
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
79*cdf0e10cSrcweir //
80*cdf0e10cSrcweir // Adds stylefamily-informations to sorted list
81*cdf0e10cSrcweir //
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir void SvXMLAutoStylePoolP_Impl::AddFamily(
84*cdf0e10cSrcweir 		sal_Int32 nFamily,
85*cdf0e10cSrcweir 		const OUString& rStrName,
86*cdf0e10cSrcweir 		const UniReference < SvXMLExportPropertyMapper > & rMapper,
87*cdf0e10cSrcweir 	   	const OUString& rStrPrefix,
88*cdf0e10cSrcweir 		sal_Bool bAsFamily )
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir 	// store family in a list if not already stored
91*cdf0e10cSrcweir 	sal_uLong nPos;
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 	sal_uInt16 nExportFlags = GetExport().getExportFlags();
94*cdf0e10cSrcweir 	sal_Bool bStylesOnly = (nExportFlags & EXPORT_STYLES) != 0 && (nExportFlags & EXPORT_CONTENT) == 0;
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir 	OUString aPrefix( rStrPrefix );
97*cdf0e10cSrcweir 	if( bStylesOnly )
98*cdf0e10cSrcweir 	{
99*cdf0e10cSrcweir 		aPrefix = OUString( 'M' );
100*cdf0e10cSrcweir 		aPrefix += rStrPrefix;
101*cdf0e10cSrcweir 	}
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 	XMLFamilyData_Impl *pFamily = new XMLFamilyData_Impl( nFamily, rStrName, rMapper, aPrefix, bAsFamily );
104*cdf0e10cSrcweir 	if( !maFamilyList.Seek_Entry( pFamily, &nPos ) )
105*cdf0e10cSrcweir 		maFamilyList.Insert( pFamily );
106*cdf0e10cSrcweir 	else
107*cdf0e10cSrcweir 		delete pFamily;
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
111*cdf0e10cSrcweir //
112*cdf0e10cSrcweir // Adds a name to list
113*cdf0e10cSrcweir //
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir void SvXMLAutoStylePoolP_Impl::RegisterName( sal_Int32 nFamily, const OUString& rName )
116*cdf0e10cSrcweir {
117*cdf0e10cSrcweir 	SvXMLAutoStylePoolNamesP_Impl *pNames = 0;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 	sal_uLong nPos;
120*cdf0e10cSrcweir 	XMLFamilyData_Impl aTmp( nFamily );
121*cdf0e10cSrcweir 	if( maFamilyList.Seek_Entry( &aTmp, &nPos ) )
122*cdf0e10cSrcweir 		pNames = maFamilyList.GetObject( nPos )->mpNameList;
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 	DBG_ASSERT( pNames,
125*cdf0e10cSrcweir 				"SvXMLAutoStylePool_Impl::RegisterName: unknown family" );
126*cdf0e10cSrcweir 	if( pNames )
127*cdf0e10cSrcweir 	{
128*cdf0e10cSrcweir 		OUString *pName = new OUString( rName );
129*cdf0e10cSrcweir 		if( !pNames->Insert( pName ) )
130*cdf0e10cSrcweir 			delete pName;
131*cdf0e10cSrcweir 	}
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
135*cdf0e10cSrcweir //
136*cdf0e10cSrcweir // Retrieve the list of registered names
137*cdf0e10cSrcweir //
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir void SvXMLAutoStylePoolP_Impl::GetRegisteredNames(
140*cdf0e10cSrcweir     uno::Sequence<sal_Int32>& rFamilies,
141*cdf0e10cSrcweir     uno::Sequence<OUString>& rNames )
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir     // collect registered names + families
144*cdf0e10cSrcweir     vector<sal_Int32> aFamilies;
145*cdf0e10cSrcweir     vector<OUString> aNames;
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir     // iterate over families
148*cdf0e10cSrcweir     sal_uInt32 nCount = maFamilyList.Count();
149*cdf0e10cSrcweir     for( sal_uInt32 i = 0; i < nCount; i++ )
150*cdf0e10cSrcweir     {
151*cdf0e10cSrcweir         XMLFamilyData_Impl* pFamily = maFamilyList.GetObject( i );
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir         // iterate over names
154*cdf0e10cSrcweir         SvXMLAutoStylePoolNamesP_Impl* pNames = pFamily->mpNameList;
155*cdf0e10cSrcweir         sal_uInt32 nNames = ( pNames != NULL ) ? pNames->Count() : 0;
156*cdf0e10cSrcweir         for( sal_uInt32 j = 0; j < nNames; j++ )
157*cdf0e10cSrcweir         {
158*cdf0e10cSrcweir             aFamilies.push_back( pFamily->mnFamily );
159*cdf0e10cSrcweir             aNames.push_back( *pNames->GetObject( j ) );
160*cdf0e10cSrcweir         }
161*cdf0e10cSrcweir     }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir     // copy the families + names into the sequence types
164*cdf0e10cSrcweir     DBG_ASSERT( aFamilies.size() == aNames.size(), "families != names" );
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     rFamilies.realloc( aFamilies.size() );
167*cdf0e10cSrcweir     std::copy( aFamilies.begin(), aFamilies.end(), rFamilies.getArray() );
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir     rNames.realloc( aNames.size() );
170*cdf0e10cSrcweir     std::copy( aNames.begin(), aNames.end(), rNames.getArray() );
171*cdf0e10cSrcweir }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
174*cdf0e10cSrcweir //
175*cdf0e10cSrcweir // Adds a array of XMLPropertyState ( vector< XMLPropertyState > ) to list
176*cdf0e10cSrcweir // if not added, yet.
177*cdf0e10cSrcweir //
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir /*OUString SvXMLAutoStylePoolP_Impl::Add( sal_Int32 nFamily,
180*cdf0e10cSrcweir 							 		    const OUString& rParent,
181*cdf0e10cSrcweir 									    const vector< XMLPropertyState >& rProperties,
182*cdf0e10cSrcweir 									    sal_Bool bCache )*/
183*cdf0e10cSrcweir sal_Bool SvXMLAutoStylePoolP_Impl::Add(OUString& rName, sal_Int32 nFamily,
184*cdf0e10cSrcweir 				const OUString& rParent,
185*cdf0e10cSrcweir 				const ::std::vector< XMLPropertyState >& rProperties,
186*cdf0e10cSrcweir 				sal_Bool bCache,
187*cdf0e10cSrcweir                 bool bDontSeek )
188*cdf0e10cSrcweir {
189*cdf0e10cSrcweir 	sal_Bool bRet(sal_False);
190*cdf0e10cSrcweir 	sal_uLong nPos;
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 	XMLFamilyData_Impl *pFamily = 0;
193*cdf0e10cSrcweir 	XMLFamilyData_Impl aTemporary( nFamily );
194*cdf0e10cSrcweir 	if( maFamilyList.Seek_Entry( &aTemporary, &nPos ) )
195*cdf0e10cSrcweir 	{
196*cdf0e10cSrcweir 		pFamily = maFamilyList.GetObject( nPos );
197*cdf0e10cSrcweir 	}
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir 	DBG_ASSERT( pFamily, "SvXMLAutoStylePool_Impl::Add: unknown family" );
200*cdf0e10cSrcweir 	if( pFamily )
201*cdf0e10cSrcweir 	{
202*cdf0e10cSrcweir 		SvXMLAutoStylePoolParentP_Impl aTmp( rParent );
203*cdf0e10cSrcweir 		SvXMLAutoStylePoolParentP_Impl *pParent = 0;
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 		SvXMLAutoStylePoolParentsP_Impl *pParents = pFamily->mpParentList;
206*cdf0e10cSrcweir 		if( pParents->Seek_Entry( &aTmp, &nPos ) )
207*cdf0e10cSrcweir 		{
208*cdf0e10cSrcweir 			pParent = pParents->GetObject( nPos );
209*cdf0e10cSrcweir 		}
210*cdf0e10cSrcweir 		else
211*cdf0e10cSrcweir 		{
212*cdf0e10cSrcweir 			pParent = new SvXMLAutoStylePoolParentP_Impl( rParent );
213*cdf0e10cSrcweir 			pParents->Insert( pParent );
214*cdf0e10cSrcweir 		}
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 		if( pParent->Add( pFamily, rProperties, rName, bDontSeek ) )
217*cdf0e10cSrcweir 		{
218*cdf0e10cSrcweir 			pFamily->mnCount++;
219*cdf0e10cSrcweir 			bRet = sal_True;
220*cdf0e10cSrcweir 		}
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 		if( bCache )
223*cdf0e10cSrcweir 		{
224*cdf0e10cSrcweir 			if( !pFamily->pCache )
225*cdf0e10cSrcweir 				pFamily->pCache = new SvXMLAutoStylePoolCache_Impl( 256, 256 );
226*cdf0e10cSrcweir 			if( pFamily->pCache->Count() < MAX_CACHE_SIZE )
227*cdf0e10cSrcweir 				pFamily->pCache->Insert( new OUString( rName ),
228*cdf0e10cSrcweir 										 pFamily->pCache->Count() );
229*cdf0e10cSrcweir 		}
230*cdf0e10cSrcweir 	}
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 	return bRet;
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir sal_Bool SvXMLAutoStylePoolP_Impl::AddNamed(const OUString& rName, sal_Int32 nFamily,
236*cdf0e10cSrcweir                 const OUString& rParent, const ::std::vector< XMLPropertyState >& rProperties )
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir     // get family and parent the same way as in Add()
239*cdf0e10cSrcweir     sal_Bool bRet(sal_False);
240*cdf0e10cSrcweir     sal_uLong nPos;
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir     XMLFamilyData_Impl *pFamily = 0;
243*cdf0e10cSrcweir     XMLFamilyData_Impl aTemporary( nFamily );
244*cdf0e10cSrcweir     if( maFamilyList.Seek_Entry( &aTemporary, &nPos ) )
245*cdf0e10cSrcweir     {
246*cdf0e10cSrcweir         pFamily = maFamilyList.GetObject( nPos );
247*cdf0e10cSrcweir     }
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir     DBG_ASSERT( pFamily, "SvXMLAutoStylePool_Impl::Add: unknown family" );
250*cdf0e10cSrcweir     if( pFamily )
251*cdf0e10cSrcweir     {
252*cdf0e10cSrcweir         SvXMLAutoStylePoolParentP_Impl aTmp( rParent );
253*cdf0e10cSrcweir         SvXMLAutoStylePoolParentP_Impl *pParent = 0;
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir         SvXMLAutoStylePoolParentsP_Impl *pParents = pFamily->mpParentList;
256*cdf0e10cSrcweir         if( pParents->Seek_Entry( &aTmp, &nPos ) )
257*cdf0e10cSrcweir         {
258*cdf0e10cSrcweir             pParent = pParents->GetObject( nPos );
259*cdf0e10cSrcweir         }
260*cdf0e10cSrcweir         else
261*cdf0e10cSrcweir         {
262*cdf0e10cSrcweir             pParent = new SvXMLAutoStylePoolParentP_Impl( rParent );
263*cdf0e10cSrcweir             pParents->Insert( pParent );
264*cdf0e10cSrcweir         }
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir         if( pParent->AddNamed( pFamily, rProperties, rName ) )
267*cdf0e10cSrcweir         {
268*cdf0e10cSrcweir             pFamily->mnCount++;
269*cdf0e10cSrcweir             bRet = sal_True;
270*cdf0e10cSrcweir         }
271*cdf0e10cSrcweir     }
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir     return bRet;
274*cdf0e10cSrcweir }
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir OUString SvXMLAutoStylePoolP_Impl::AddToCache( sal_Int32 nFamily,
277*cdf0e10cSrcweir 							 		    const OUString& rParent )
278*cdf0e10cSrcweir {
279*cdf0e10cSrcweir 	sal_uLong nPos;
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir 	XMLFamilyData_Impl *pFamily = 0;
282*cdf0e10cSrcweir 	XMLFamilyData_Impl aTmp( nFamily );
283*cdf0e10cSrcweir 	if( maFamilyList.Seek_Entry( &aTmp, &nPos ) )
284*cdf0e10cSrcweir 	{
285*cdf0e10cSrcweir 		pFamily = maFamilyList.GetObject( nPos );
286*cdf0e10cSrcweir 	}
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 	DBG_ASSERT( pFamily, "SvXMLAutoStylePool_Impl::Add: unknown family" );
289*cdf0e10cSrcweir 	if( pFamily )
290*cdf0e10cSrcweir 	{
291*cdf0e10cSrcweir 		if( !pFamily->pCache )
292*cdf0e10cSrcweir 			pFamily->pCache = new SvXMLAutoStylePoolCache_Impl( 256, 256 );
293*cdf0e10cSrcweir 		if( pFamily->pCache->Count() < MAX_CACHE_SIZE )
294*cdf0e10cSrcweir 			pFamily->pCache->Insert( new OUString( rParent ),
295*cdf0e10cSrcweir 									 pFamily->pCache->Count() );
296*cdf0e10cSrcweir 	}
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 	return rParent;
299*cdf0e10cSrcweir }
300*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
301*cdf0e10cSrcweir //
302*cdf0e10cSrcweir // Search for a array of XMLPropertyState ( vector< XMLPropertyState > ) in list
303*cdf0e10cSrcweir //
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir OUString SvXMLAutoStylePoolP_Impl::Find( sal_Int32 nFamily,
306*cdf0e10cSrcweir 										 const OUString& rParent,
307*cdf0e10cSrcweir 										 const vector< XMLPropertyState >& rProperties ) const
308*cdf0e10cSrcweir {
309*cdf0e10cSrcweir 	OUString sName;
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 	sal_uLong nPos;
312*cdf0e10cSrcweir 	XMLFamilyData_Impl aTemporary( nFamily );
313*cdf0e10cSrcweir 	XMLFamilyData_Impl *pFamily = 0;
314*cdf0e10cSrcweir 	if( maFamilyList.Seek_Entry( &aTemporary, &nPos ) )
315*cdf0e10cSrcweir 	{
316*cdf0e10cSrcweir 		pFamily = maFamilyList.GetObject( nPos );
317*cdf0e10cSrcweir 	}
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir 	DBG_ASSERT( pFamily, "SvXMLAutoStylePool_Impl::Find: unknown family" );
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir 	if( pFamily )
322*cdf0e10cSrcweir 	{
323*cdf0e10cSrcweir 		SvXMLAutoStylePoolParentP_Impl aTmp( rParent );
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir 		const SvXMLAutoStylePoolParentsP_Impl* pParents =
326*cdf0e10cSrcweir 			pFamily->mpParentList;
327*cdf0e10cSrcweir 		if( pParents->Seek_Entry( &aTmp, &nPos ) )
328*cdf0e10cSrcweir 			sName = pParents->GetObject( nPos )->Find( pFamily, rProperties );
329*cdf0e10cSrcweir 	}
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 	return sName;
332*cdf0e10cSrcweir }
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir OUString SvXMLAutoStylePoolP_Impl::FindAndRemoveCached( sal_Int32 nFamily ) const
335*cdf0e10cSrcweir {
336*cdf0e10cSrcweir 	OUString sName;
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir 	sal_uLong nPos;
339*cdf0e10cSrcweir 	XMLFamilyData_Impl aTmp( nFamily );
340*cdf0e10cSrcweir 	XMLFamilyData_Impl *pFamily = 0;
341*cdf0e10cSrcweir 	if( maFamilyList.Seek_Entry( &aTmp, &nPos ) )
342*cdf0e10cSrcweir 	{
343*cdf0e10cSrcweir 		pFamily = maFamilyList.GetObject( nPos );
344*cdf0e10cSrcweir 	}
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir 	DBG_ASSERT( pFamily, "SvXMLAutoStylePool_Impl::Find: unknown family" );
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir 	if( pFamily )
349*cdf0e10cSrcweir 	{
350*cdf0e10cSrcweir 		DBG_ASSERT( pFamily->pCache, "family doesn't have a cache" );
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir 		// The cache may be empty already. This happens if it was filled
353*cdf0e10cSrcweir 		// completly.
354*cdf0e10cSrcweir 		if( pFamily->pCache && pFamily->pCache->Count() )
355*cdf0e10cSrcweir 		{
356*cdf0e10cSrcweir 			OUString *pName = pFamily->pCache->Remove( 0UL );
357*cdf0e10cSrcweir 			sName = *pName;
358*cdf0e10cSrcweir 			delete pName;
359*cdf0e10cSrcweir 		}
360*cdf0e10cSrcweir 	}
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir 	return sName;
363*cdf0e10cSrcweir }
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
366*cdf0e10cSrcweir //
367*cdf0e10cSrcweir // export
368*cdf0e10cSrcweir //
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir void SvXMLAutoStylePoolP_Impl::exportXML(
371*cdf0e10cSrcweir 	   	sal_Int32 nFamily,
372*cdf0e10cSrcweir 		const uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > &,
373*cdf0e10cSrcweir 		const SvXMLUnitConverter&,
374*cdf0e10cSrcweir 		const SvXMLNamespaceMap&,
375*cdf0e10cSrcweir 		const SvXMLAutoStylePoolP *pAntiImpl) const
376*cdf0e10cSrcweir {
377*cdf0e10cSrcweir 	sal_uInt32 nCount = 0;
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir 	// Get list of parents for current family (nFamily)
380*cdf0e10cSrcweir 	sal_uLong nPos;
381*cdf0e10cSrcweir 	XMLFamilyData_Impl aTmp( nFamily );
382*cdf0e10cSrcweir 	XMLFamilyData_Impl *pFamily = 0;
383*cdf0e10cSrcweir 	if( maFamilyList.Seek_Entry( &aTmp, &nPos ) )
384*cdf0e10cSrcweir 	{
385*cdf0e10cSrcweir 		pFamily = maFamilyList.GetObject( nPos );
386*cdf0e10cSrcweir 		nCount         = pFamily->mnCount;
387*cdf0e10cSrcweir 	}
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir 	DBG_ASSERT( pFamily,
390*cdf0e10cSrcweir 				"SvXMLAutoStylePool_Impl::exportXML: unknown family" );
391*cdf0e10cSrcweir 	if( pFamily && nCount > 0 )
392*cdf0e10cSrcweir 	{
393*cdf0e10cSrcweir 		/////////////////////////////////////////////////////////////////////////////////////
394*cdf0e10cSrcweir 		// create, initialize and fill helper-structure (SvXMLAutoStylePoolProperties_Impl)
395*cdf0e10cSrcweir 		// wich contains a parent-name and a SvXMLAutoStylePoolProperties_Impl
396*cdf0e10cSrcweir 		//
397*cdf0e10cSrcweir 		const SvXMLAutoStylePoolParentsP_Impl *pParents =
398*cdf0e10cSrcweir 			pFamily->mpParentList;
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir 		SvXMLAutoStylePoolPExport_Impl* aExpStyles =
401*cdf0e10cSrcweir 			new SvXMLAutoStylePoolPExport_Impl[nCount];
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir 		sal_uInt32 i;
404*cdf0e10cSrcweir 		for( i=0; i < nCount; i++ )
405*cdf0e10cSrcweir 		{
406*cdf0e10cSrcweir 			aExpStyles[i].mpParent = 0;
407*cdf0e10cSrcweir 			aExpStyles[i].mpProperties = 0;
408*cdf0e10cSrcweir 		}
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir 		sal_uInt32 nParents = pParents->Count();
411*cdf0e10cSrcweir 		for( i=0; i < nParents; i++ )
412*cdf0e10cSrcweir 		{
413*cdf0e10cSrcweir 			const SvXMLAutoStylePoolParentP_Impl* pParent =
414*cdf0e10cSrcweir 				pParents->GetObject( i );
415*cdf0e10cSrcweir 			sal_uInt32 nProperties = pParent->GetPropertiesList().Count();
416*cdf0e10cSrcweir 			for( sal_uInt32 j=0; j < nProperties; j++ )
417*cdf0e10cSrcweir 			{
418*cdf0e10cSrcweir 				const SvXMLAutoStylePoolPropertiesP_Impl *pProperties =
419*cdf0e10cSrcweir 					pParent->GetPropertiesList().GetObject( j );
420*cdf0e10cSrcweir 				nPos = pProperties->GetPos();
421*cdf0e10cSrcweir 				DBG_ASSERT( nPos < nCount,
422*cdf0e10cSrcweir 						"SvXMLAutoStylePool_Impl::exportXML: wrong position" );
423*cdf0e10cSrcweir 				if( nPos < nCount )
424*cdf0e10cSrcweir 				{
425*cdf0e10cSrcweir 					DBG_ASSERT( !aExpStyles[nPos].mpProperties,
426*cdf0e10cSrcweir 						"SvXMLAutoStylePool_Impl::exportXML: double position" );
427*cdf0e10cSrcweir 					aExpStyles[nPos].mpProperties = pProperties;
428*cdf0e10cSrcweir 					aExpStyles[nPos].mpParent = &pParent->GetParent();
429*cdf0e10cSrcweir 				}
430*cdf0e10cSrcweir 			}
431*cdf0e10cSrcweir 		}
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir 		/////////////////////////////////////////////////////////////////////////////////////
434*cdf0e10cSrcweir 		//
435*cdf0e10cSrcweir 		// create string to export for each XML-style. That means for each property-list
436*cdf0e10cSrcweir 		//
437*cdf0e10cSrcweir 		OUString aStrFamilyName = pFamily->maStrFamilyName;
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir 		for( i=0; i<nCount; i++ )
440*cdf0e10cSrcweir 		{
441*cdf0e10cSrcweir 			DBG_ASSERT( aExpStyles[i].mpProperties,
442*cdf0e10cSrcweir 						"SvXMLAutoStylePool_Impl::exportXML: empty position" );
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir 			if( aExpStyles[i].mpProperties )
445*cdf0e10cSrcweir 			{
446*cdf0e10cSrcweir                 GetExport().AddAttribute(
447*cdf0e10cSrcweir                     XML_NAMESPACE_STYLE, XML_NAME,
448*cdf0e10cSrcweir                     aExpStyles[i].mpProperties->GetName() );
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir 				if( pFamily->bAsFamily )
451*cdf0e10cSrcweir 				{
452*cdf0e10cSrcweir                     GetExport().AddAttribute(
453*cdf0e10cSrcweir                         XML_NAMESPACE_STYLE, XML_FAMILY, aStrFamilyName );
454*cdf0e10cSrcweir 				}
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir 				if( aExpStyles[i].mpParent->getLength() )
457*cdf0e10cSrcweir 				{
458*cdf0e10cSrcweir                     GetExport().AddAttribute(
459*cdf0e10cSrcweir                         XML_NAMESPACE_STYLE, XML_PARENT_STYLE_NAME,
460*cdf0e10cSrcweir                     	GetExport().EncodeStyleName(
461*cdf0e10cSrcweir 							*aExpStyles[i].mpParent ) );
462*cdf0e10cSrcweir 				}
463*cdf0e10cSrcweir 
464*cdf0e10cSrcweir                 OUString sName;
465*cdf0e10cSrcweir 				if( pFamily->bAsFamily )
466*cdf0e10cSrcweir 					sName = GetXMLToken(XML_STYLE);
467*cdf0e10cSrcweir 				else
468*cdf0e10cSrcweir 					sName = pFamily->maStrFamilyName;
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir 				pAntiImpl->exportStyleAttributes(
471*cdf0e10cSrcweir                     GetExport().GetAttrList(),
472*cdf0e10cSrcweir                     nFamily,
473*cdf0e10cSrcweir                     aExpStyles[i].mpProperties->GetProperties(),
474*cdf0e10cSrcweir                     *pFamily->mxMapper.get()
475*cdf0e10cSrcweir 						, GetExport().GetMM100UnitConverter(),
476*cdf0e10cSrcweir                         GetExport().GetNamespaceMap()
477*cdf0e10cSrcweir                     );
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir                 SvXMLElementExport aElem( GetExport(),
480*cdf0e10cSrcweir                                           XML_NAMESPACE_STYLE, sName,
481*cdf0e10cSrcweir                                           sal_True, sal_True );
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir 				sal_Int32 nStart(-1);
484*cdf0e10cSrcweir 				sal_Int32 nEnd(-1);
485*cdf0e10cSrcweir 				if (nFamily == XML_STYLE_FAMILY_PAGE_MASTER)
486*cdf0e10cSrcweir 				{
487*cdf0e10cSrcweir 					nStart = 0;
488*cdf0e10cSrcweir 					sal_Int32 nIndex = 0;
489*cdf0e10cSrcweir 					UniReference< XMLPropertySetMapper > aPropMapper =
490*cdf0e10cSrcweir 						pFamily->mxMapper->getPropertySetMapper();
491*cdf0e10cSrcweir 					sal_Int16 nContextID;
492*cdf0e10cSrcweir 					while(nIndex < aPropMapper->GetEntryCount() && nEnd == -1)
493*cdf0e10cSrcweir 					{
494*cdf0e10cSrcweir 						nContextID = aPropMapper->GetEntryContextId( nIndex );
495*cdf0e10cSrcweir 						if (nContextID && ((nContextID & CTF_PM_FLAGMASK) != XML_PM_CTF_START))
496*cdf0e10cSrcweir 							nEnd = nIndex;
497*cdf0e10cSrcweir 						nIndex++;
498*cdf0e10cSrcweir 					}
499*cdf0e10cSrcweir 					if (nEnd == -1)
500*cdf0e10cSrcweir 						nEnd = nIndex;
501*cdf0e10cSrcweir 				}
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir 				pFamily->mxMapper->exportXML(
504*cdf0e10cSrcweir                     GetExport(),
505*cdf0e10cSrcweir                     aExpStyles[i].mpProperties->GetProperties(),
506*cdf0e10cSrcweir                     nStart, nEnd, XML_EXPORT_FLAG_IGN_WS );
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir 				pAntiImpl->exportStyleContent(
509*cdf0e10cSrcweir                     GetExport().GetDocHandler(),
510*cdf0e10cSrcweir                     nFamily,
511*cdf0e10cSrcweir                     aExpStyles[i].mpProperties->GetProperties(),
512*cdf0e10cSrcweir                     *pFamily->mxMapper.get(),
513*cdf0e10cSrcweir                     GetExport().GetMM100UnitConverter(),
514*cdf0e10cSrcweir                     GetExport().GetNamespaceMap()
515*cdf0e10cSrcweir                     );
516*cdf0e10cSrcweir 			}
517*cdf0e10cSrcweir 		}
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir 		delete[] aExpStyles;
520*cdf0e10cSrcweir 	}
521*cdf0e10cSrcweir }
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir void SvXMLAutoStylePoolP_Impl::ClearEntries()
524*cdf0e10cSrcweir {
525*cdf0e10cSrcweir 	for(sal_uInt32 a = 0L; a < maFamilyList.Count(); a++)
526*cdf0e10cSrcweir 		maFamilyList[a]->ClearEntries();
527*cdf0e10cSrcweir }
528