xref: /trunk/main/xmloff/source/style/xmlstyle.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 <com/sun/star/xml/sax/SAXParseException.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/xml/sax/SAXException.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XAttributeList.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XLocator.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/style/XAutoStylesSupplier.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/style/XAutoStyleFamily.hpp>
41*cdf0e10cSrcweir #ifndef _XMLOFF_PAGEMASTERPROPMAPPER_HXX
42*cdf0e10cSrcweir #include "PageMasterPropMapper.hxx"
43*cdf0e10cSrcweir #endif
44*cdf0e10cSrcweir #include <tools/debug.hxx>
45*cdf0e10cSrcweir #include <tools/list.hxx>
46*cdf0e10cSrcweir #include <svl/cntnrsrt.hxx>
47*cdf0e10cSrcweir #include <svl/itemset.hxx>
48*cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
49*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
50*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir #ifndef _XMLOFF_FAMILIES_HXX
53*cdf0e10cSrcweir #include <xmloff/families.hxx>
54*cdf0e10cSrcweir #endif
55*cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
56*cdf0e10cSrcweir #include <xmloff/xmlnumi.hxx>
57*cdf0e10cSrcweir #include <xmloff/xmlimppr.hxx>
58*cdf0e10cSrcweir #include <xmloff/xmlstyle.hxx>
59*cdf0e10cSrcweir #ifndef _XMLOFF_TXTSTYLI_HXX
60*cdf0e10cSrcweir #include <xmloff/txtstyli.hxx>
61*cdf0e10cSrcweir #endif
62*cdf0e10cSrcweir #ifndef _XMLOFF_TXTPRMAP_HXX
63*cdf0e10cSrcweir #include <xmloff/txtprmap.hxx>
64*cdf0e10cSrcweir #endif
65*cdf0e10cSrcweir #include <xmloff/xmlnumfi.hxx>
66*cdf0e10cSrcweir #include "XMLChartStyleContext.hxx"
67*cdf0e10cSrcweir #include "XMLChartPropertySetMapper.hxx"
68*cdf0e10cSrcweir #include <xmloff/XMLShapeStyleContext.hxx>
69*cdf0e10cSrcweir #include "FillStyleContext.hxx"
70*cdf0e10cSrcweir #include "XMLFootnoteConfigurationImportContext.hxx"
71*cdf0e10cSrcweir #include "XMLIndexBibliographyConfigurationContext.hxx"
72*cdf0e10cSrcweir #include "XMLLineNumberingImportContext.hxx"
73*cdf0e10cSrcweir #include "PageMasterImportContext.hxx"
74*cdf0e10cSrcweir #include "PageMasterImportPropMapper.hxx"
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir using ::rtl::OUString;
77*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir using namespace ::com::sun::star;
80*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
81*cdf0e10cSrcweir using namespace ::com::sun::star::container;
82*cdf0e10cSrcweir using namespace ::com::sun::star::style;
83*cdf0e10cSrcweir using namespace ::xmloff::token;
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir // ---------------------------------------------------------------------
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir static __FAR_DATA SvXMLTokenMapEntry aStyleStylesElemTokenMap[] =
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir     { XML_NAMESPACE_STYLE,  XML_STYLE,          XML_TOK_STYLE_STYLE                },
90*cdf0e10cSrcweir     { XML_NAMESPACE_STYLE,  XML_PAGE_LAYOUT,    XML_TOK_STYLE_PAGE_MASTER          },
91*cdf0e10cSrcweir     { XML_NAMESPACE_TEXT,   XML_LIST_STYLE,     XML_TOK_TEXT_LIST_STYLE            },
92*cdf0e10cSrcweir     { XML_NAMESPACE_TEXT,   XML_OUTLINE_STYLE,  XML_TOK_TEXT_OUTLINE               },
93*cdf0e10cSrcweir     { XML_NAMESPACE_STYLE,  XML_DEFAULT_STYLE,  XML_TOK_STYLE_DEFAULT_STYLE        },
94*cdf0e10cSrcweir     { XML_NAMESPACE_DRAW,   XML_GRADIENT,       XML_TOK_STYLES_GRADIENTSTYLES      },
95*cdf0e10cSrcweir     { XML_NAMESPACE_DRAW,   XML_HATCH,          XML_TOK_STYLES_HATCHSTYLES         },
96*cdf0e10cSrcweir     { XML_NAMESPACE_DRAW,   XML_FILL_IMAGE,     XML_TOK_STYLES_BITMAPSTYLES        },
97*cdf0e10cSrcweir     { XML_NAMESPACE_DRAW,   XML_OPACITY,        XML_TOK_STYLES_TRANSGRADIENTSTYLES },
98*cdf0e10cSrcweir     { XML_NAMESPACE_DRAW,   XML_MARKER,         XML_TOK_STYLES_MARKERSTYLES        },
99*cdf0e10cSrcweir     { XML_NAMESPACE_DRAW,   XML_STROKE_DASH,    XML_TOK_STYLES_DASHSTYLES        },
100*cdf0e10cSrcweir     { XML_NAMESPACE_TEXT,   XML_NOTES_CONFIGURATION,    XML_TOK_TEXT_NOTE_CONFIG },
101*cdf0e10cSrcweir     { XML_NAMESPACE_TEXT,   XML_BIBLIOGRAPHY_CONFIGURATION, XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG },
102*cdf0e10cSrcweir     { XML_NAMESPACE_TEXT,   XML_LINENUMBERING_CONFIGURATION,XML_TOK_TEXT_LINENUMBERING_CONFIG },
103*cdf0e10cSrcweir     { XML_NAMESPACE_STYLE,  XML_DEFAULT_PAGE_LAYOUT,    XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT        },
104*cdf0e10cSrcweir     XML_TOKEN_MAP_END
105*cdf0e10cSrcweir };
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir const SvXMLTokenMap& SvXMLStylesContext::GetStyleStylesElemTokenMap()
108*cdf0e10cSrcweir {
109*cdf0e10cSrcweir     if( !mpStyleStylesElemTokenMap )
110*cdf0e10cSrcweir         mpStyleStylesElemTokenMap =
111*cdf0e10cSrcweir             new SvXMLTokenMap( aStyleStylesElemTokenMap );
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir     return *mpStyleStylesElemTokenMap;
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir // ---------------------------------------------------------------------
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir void SvXMLStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
119*cdf0e10cSrcweir                                       const OUString& rLocalName,
120*cdf0e10cSrcweir                                       const OUString& rValue )
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir     // TODO: use a map here
123*cdf0e10cSrcweir     if( XML_NAMESPACE_STYLE == nPrefixKey )
124*cdf0e10cSrcweir     {
125*cdf0e10cSrcweir         if( IsXMLToken( rLocalName, XML_FAMILY ) )
126*cdf0e10cSrcweir         {
127*cdf0e10cSrcweir             if( IsXMLToken( rValue, XML_PARAGRAPH ) )
128*cdf0e10cSrcweir                 mnFamily = (sal_uInt16)SFX_STYLE_FAMILY_PARA;
129*cdf0e10cSrcweir             else if( IsXMLToken( rValue, XML_TEXT ) )
130*cdf0e10cSrcweir                 mnFamily = (sal_uInt16)SFX_STYLE_FAMILY_CHAR;
131*cdf0e10cSrcweir         }
132*cdf0e10cSrcweir         else if( IsXMLToken( rLocalName, XML_NAME ) )
133*cdf0e10cSrcweir         {
134*cdf0e10cSrcweir             maName = rValue;
135*cdf0e10cSrcweir         }
136*cdf0e10cSrcweir         else if( IsXMLToken( rLocalName, XML_DISPLAY_NAME ) )
137*cdf0e10cSrcweir         {
138*cdf0e10cSrcweir             maDisplayName = rValue;
139*cdf0e10cSrcweir         }
140*cdf0e10cSrcweir         else if( IsXMLToken( rLocalName, XML_PARENT_STYLE_NAME ) )
141*cdf0e10cSrcweir         {
142*cdf0e10cSrcweir             maParentName = rValue;
143*cdf0e10cSrcweir         }
144*cdf0e10cSrcweir         else if( IsXMLToken( rLocalName, XML_NEXT_STYLE_NAME ) )
145*cdf0e10cSrcweir         {
146*cdf0e10cSrcweir             maFollow = rValue;
147*cdf0e10cSrcweir         }
148*cdf0e10cSrcweir         else if( IsXMLToken( rLocalName, XML_HELP_FILE_NAME ) )
149*cdf0e10cSrcweir         {
150*cdf0e10cSrcweir             maHelpFile = rValue;
151*cdf0e10cSrcweir         }
152*cdf0e10cSrcweir         else if( IsXMLToken( rLocalName, XML_HELP_ID ) )
153*cdf0e10cSrcweir         {
154*cdf0e10cSrcweir             sal_Int32 nTmp = rValue.toInt32();
155*cdf0e10cSrcweir             mnHelpId =
156*cdf0e10cSrcweir                 (nTmp < 0L) ? 0U : ( (nTmp > USHRT_MAX) ? USHRT_MAX
157*cdf0e10cSrcweir                                                         : (sal_uInt16)nTmp );
158*cdf0e10cSrcweir         }
159*cdf0e10cSrcweir     }
160*cdf0e10cSrcweir }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir TYPEINIT1( SvXMLStyleContext, SvXMLImportContext );
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir SvXMLStyleContext::SvXMLStyleContext(
165*cdf0e10cSrcweir         SvXMLImport& rImp, sal_uInt16 nPrfx,
166*cdf0e10cSrcweir         const OUString& rLName,
167*cdf0e10cSrcweir         const uno::Reference< xml::sax::XAttributeList >&,
168*cdf0e10cSrcweir         sal_uInt16 nFam, sal_Bool bDefault ) :
169*cdf0e10cSrcweir     SvXMLImportContext( rImp, nPrfx, rLName ),
170*cdf0e10cSrcweir     mnHelpId( UCHAR_MAX ),
171*cdf0e10cSrcweir     mnFamily( nFam ),
172*cdf0e10cSrcweir     mbValid( sal_True ),
173*cdf0e10cSrcweir     mbNew( sal_True ),
174*cdf0e10cSrcweir     mbDefaultStyle( bDefault )
175*cdf0e10cSrcweir {
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir SvXMLStyleContext::~SvXMLStyleContext()
179*cdf0e10cSrcweir {
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir SvXMLImportContext *SvXMLStyleContext::CreateChildContext( sal_uInt16 nPrefix,
183*cdf0e10cSrcweir                                             const OUString& rLocalName,
184*cdf0e10cSrcweir                                             const uno::Reference< xml::sax::XAttributeList > & )
185*cdf0e10cSrcweir {
186*cdf0e10cSrcweir     return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );;
187*cdf0e10cSrcweir }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir void SvXMLStyleContext::StartElement( const uno::Reference< xml::sax::XAttributeList > & xAttrList )
190*cdf0e10cSrcweir {
191*cdf0e10cSrcweir     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
192*cdf0e10cSrcweir     for( sal_Int16 i=0; i < nAttrCount; i++ )
193*cdf0e10cSrcweir     {
194*cdf0e10cSrcweir         const OUString& rAttrName = xAttrList->getNameByIndex( i );
195*cdf0e10cSrcweir         OUString aLocalName;
196*cdf0e10cSrcweir         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
197*cdf0e10cSrcweir         const OUString& rValue = xAttrList->getValueByIndex( i );
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir         SetAttribute( nPrefix, aLocalName, rValue );
200*cdf0e10cSrcweir     }
201*cdf0e10cSrcweir }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir void SvXMLStyleContext::SetDefaults()
204*cdf0e10cSrcweir {
205*cdf0e10cSrcweir }
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir void SvXMLStyleContext::CreateAndInsert( sal_Bool /*bOverwrite*/ )
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir void SvXMLStyleContext::CreateAndInsertLate( sal_Bool /*bOverwrite*/ )
212*cdf0e10cSrcweir {
213*cdf0e10cSrcweir }
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir void SvXMLStyleContext::Finish( sal_Bool /*bOverwrite*/ )
216*cdf0e10cSrcweir {
217*cdf0e10cSrcweir }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir sal_Bool SvXMLStyleContext::IsTransient() const
220*cdf0e10cSrcweir {
221*cdf0e10cSrcweir     return sal_False;
222*cdf0e10cSrcweir }
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir // ---------------------------------------------------------------------
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir class SvXMLStyleIndex_Impl
227*cdf0e10cSrcweir {
228*cdf0e10cSrcweir     OUString              sName;
229*cdf0e10cSrcweir     sal_uInt16            nFamily;
230*cdf0e10cSrcweir     const SvXMLStyleContext *pStyle;
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir public:
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir     SvXMLStyleIndex_Impl( sal_uInt16 nFam, const OUString& rName ) :
235*cdf0e10cSrcweir         sName( rName ),
236*cdf0e10cSrcweir         nFamily( nFam ),
237*cdf0e10cSrcweir         pStyle ( 0 )
238*cdf0e10cSrcweir     {
239*cdf0e10cSrcweir     }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir     SvXMLStyleIndex_Impl( const SvXMLStyleContext *pStl ) :
242*cdf0e10cSrcweir         sName( pStl->GetName() ),
243*cdf0e10cSrcweir         nFamily( pStl->GetFamily() ),
244*cdf0e10cSrcweir         pStyle ( pStl )
245*cdf0e10cSrcweir     {
246*cdf0e10cSrcweir     }
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir     const OUString& GetName() const { return sName; }
249*cdf0e10cSrcweir     sal_uInt16 GetFamily() const { return nFamily; }
250*cdf0e10cSrcweir     const SvXMLStyleContext *GetStyle() const { return pStyle; }
251*cdf0e10cSrcweir };
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir int SvXMLStyleIndexCmp_Impl( const SvXMLStyleIndex_Impl& r1,
254*cdf0e10cSrcweir                               const SvXMLStyleIndex_Impl& r2 )
255*cdf0e10cSrcweir {
256*cdf0e10cSrcweir     int nRet;
257*cdf0e10cSrcweir     if( (sal_uInt16)r1.GetFamily() < (sal_uInt16)r2.GetFamily() )
258*cdf0e10cSrcweir         nRet = -1;
259*cdf0e10cSrcweir     else if( (sal_uInt16)r1.GetFamily() > (sal_uInt16)r2.GetFamily() )
260*cdf0e10cSrcweir         nRet = 1;
261*cdf0e10cSrcweir     else
262*cdf0e10cSrcweir         nRet = (int)r1.GetName().compareTo( r2.GetName() );
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir     return nRet;
265*cdf0e10cSrcweir }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir // ---------------------------------------------------------------------
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir typedef SvXMLStyleContext *SvXMLStyleContextPtr;
270*cdf0e10cSrcweir DECLARE_LIST( SvXMLStyleContexts_Impl, SvXMLStyleContextPtr )
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir DECLARE_CONTAINER_SORT_DEL( SvXMLStyleIndices_Impl, SvXMLStyleIndex_Impl )
273*cdf0e10cSrcweir IMPL_CONTAINER_SORT( SvXMLStyleIndices_Impl, SvXMLStyleIndex_Impl,
274*cdf0e10cSrcweir                      SvXMLStyleIndexCmp_Impl )
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir class SvXMLStylesContext_Impl
278*cdf0e10cSrcweir {
279*cdf0e10cSrcweir     SvXMLStyleContexts_Impl aStyles;
280*cdf0e10cSrcweir     SvXMLStyleIndices_Impl  *pIndices;
281*cdf0e10cSrcweir     sal_Bool bAutomaticStyle;
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir #ifdef DBG_UTIL
284*cdf0e10cSrcweir     sal_uInt32 nIndexCreated;
285*cdf0e10cSrcweir #endif
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir     void FlushIndex() { delete pIndices; pIndices = 0; }
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir public:
290*cdf0e10cSrcweir     SvXMLStylesContext_Impl( sal_Bool bAuto );
291*cdf0e10cSrcweir     ~SvXMLStylesContext_Impl();
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir     sal_uInt32 GetStyleCount() const { return aStyles.Count(); }
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir     const SvXMLStyleContext *GetStyle( sal_uInt32 i ) const
296*cdf0e10cSrcweir     {
297*cdf0e10cSrcweir         return i < aStyles.Count() ? aStyles.GetObject(i) : 0;
298*cdf0e10cSrcweir     }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir     SvXMLStyleContext *GetStyle( sal_uInt32 i )
301*cdf0e10cSrcweir     {
302*cdf0e10cSrcweir         return i < aStyles.Count() ? aStyles.GetObject(i) : 0;
303*cdf0e10cSrcweir     }
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir     inline void AddStyle( SvXMLStyleContext *pStyle );
306*cdf0e10cSrcweir     void Clear();
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir     const SvXMLStyleContext *FindStyleChildContext( sal_uInt16 nFamily,
309*cdf0e10cSrcweir                             const OUString& rName, sal_Bool bCreateIndex ) const;
310*cdf0e10cSrcweir     sal_Bool IsAutomaticStyle() const { return bAutomaticStyle; }
311*cdf0e10cSrcweir };
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir SvXMLStylesContext_Impl::SvXMLStylesContext_Impl( sal_Bool bAuto ) :
314*cdf0e10cSrcweir     aStyles( 20, 5 ),
315*cdf0e10cSrcweir     pIndices( 0 ),
316*cdf0e10cSrcweir     bAutomaticStyle( bAuto )
317*cdf0e10cSrcweir #ifdef DBG_UTIL
318*cdf0e10cSrcweir ,   nIndexCreated( 0 )
319*cdf0e10cSrcweir #endif
320*cdf0e10cSrcweir {}
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir SvXMLStylesContext_Impl::~SvXMLStylesContext_Impl()
323*cdf0e10cSrcweir {
324*cdf0e10cSrcweir     delete pIndices;
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir     while( aStyles.Count() )
327*cdf0e10cSrcweir     {
328*cdf0e10cSrcweir         SvXMLStyleContext *pStyle = aStyles.GetObject(0);
329*cdf0e10cSrcweir         aStyles.Remove( 0UL );
330*cdf0e10cSrcweir         pStyle->ReleaseRef();
331*cdf0e10cSrcweir     }
332*cdf0e10cSrcweir }
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir inline void SvXMLStylesContext_Impl::AddStyle( SvXMLStyleContext *pStyle )
335*cdf0e10cSrcweir {
336*cdf0e10cSrcweir     aStyles.Insert( pStyle, aStyles.Count() );
337*cdf0e10cSrcweir     pStyle->AddRef();
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir     FlushIndex();
340*cdf0e10cSrcweir }
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir void SvXMLStylesContext_Impl::Clear()
343*cdf0e10cSrcweir {
344*cdf0e10cSrcweir     FlushIndex();
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir     while( aStyles.Count() )
347*cdf0e10cSrcweir     {
348*cdf0e10cSrcweir         SvXMLStyleContext *pStyle = aStyles.GetObject(0);
349*cdf0e10cSrcweir         aStyles.Remove( 0UL );
350*cdf0e10cSrcweir         pStyle->ReleaseRef();
351*cdf0e10cSrcweir     }
352*cdf0e10cSrcweir }
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir const SvXMLStyleContext *SvXMLStylesContext_Impl::FindStyleChildContext(
355*cdf0e10cSrcweir                                   sal_uInt16 nFamily,
356*cdf0e10cSrcweir                                   const OUString& rName,
357*cdf0e10cSrcweir                                   sal_Bool bCreateIndex ) const
358*cdf0e10cSrcweir {
359*cdf0e10cSrcweir     const SvXMLStyleContext *pStyle = 0;
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir     if( !pIndices && bCreateIndex && aStyles.Count() > 0 )
362*cdf0e10cSrcweir     {
363*cdf0e10cSrcweir #ifdef DBG_UTIL
364*cdf0e10cSrcweir         DBG_ASSERT( 0==nIndexCreated,
365*cdf0e10cSrcweir                     "Performance warning: sdbcx::Index created multiple times" );
366*cdf0e10cSrcweir #endif
367*cdf0e10cSrcweir         ((SvXMLStylesContext_Impl *)this)->pIndices =
368*cdf0e10cSrcweir             new SvXMLStyleIndices_Impl(
369*cdf0e10cSrcweir                 sal::static_int_cast< sal_uInt16 >(aStyles.Count()), 5 );
370*cdf0e10cSrcweir         for( sal_uInt32 i=0; i < aStyles.Count(); i++ )
371*cdf0e10cSrcweir         {
372*cdf0e10cSrcweir             SvXMLStyleIndex_Impl* pStyleIndex = new SvXMLStyleIndex_Impl( aStyles.GetObject(i));
373*cdf0e10cSrcweir             if (!pIndices->Insert( pStyleIndex ))
374*cdf0e10cSrcweir             {
375*cdf0e10cSrcweir                 DBG_ERROR("Here is a double Style");
376*cdf0e10cSrcweir                 delete pStyleIndex;
377*cdf0e10cSrcweir             }
378*cdf0e10cSrcweir         }
379*cdf0e10cSrcweir #ifdef DBG_UTIL
380*cdf0e10cSrcweir         ((SvXMLStylesContext_Impl *)this)->nIndexCreated++;
381*cdf0e10cSrcweir #endif
382*cdf0e10cSrcweir     }
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir     if( pIndices )
385*cdf0e10cSrcweir     {
386*cdf0e10cSrcweir         SvXMLStyleIndex_Impl aIndex( nFamily, rName );
387*cdf0e10cSrcweir         sal_uLong nPos = 0;
388*cdf0e10cSrcweir         if( pIndices->Seek_Entry( &aIndex, &nPos ) )
389*cdf0e10cSrcweir             pStyle = pIndices->GetObject( nPos )->GetStyle();
390*cdf0e10cSrcweir     }
391*cdf0e10cSrcweir     else
392*cdf0e10cSrcweir     {
393*cdf0e10cSrcweir         for( sal_uInt32 i=0; !pStyle && i < aStyles.Count(); i++ )
394*cdf0e10cSrcweir         {
395*cdf0e10cSrcweir             const SvXMLStyleContext *pS = aStyles.GetObject( i );
396*cdf0e10cSrcweir             if( pS->GetFamily() == nFamily &&
397*cdf0e10cSrcweir                 pS->GetName() == rName )
398*cdf0e10cSrcweir                 pStyle = pS;
399*cdf0e10cSrcweir         }
400*cdf0e10cSrcweir     }
401*cdf0e10cSrcweir     return pStyle;
402*cdf0e10cSrcweir }
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir // ---------------------------------------------------------------------
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir TYPEINIT1( SvXMLStylesContext, SvXMLImportContext );
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir sal_uInt32 SvXMLStylesContext::GetStyleCount() const
409*cdf0e10cSrcweir {
410*cdf0e10cSrcweir     return mpImpl->GetStyleCount();
411*cdf0e10cSrcweir }
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i )
414*cdf0e10cSrcweir {
415*cdf0e10cSrcweir     return mpImpl->GetStyle( i );
416*cdf0e10cSrcweir }
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir const SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i ) const
419*cdf0e10cSrcweir {
420*cdf0e10cSrcweir     return mpImpl->GetStyle( i );
421*cdf0e10cSrcweir }
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir sal_Bool SvXMLStylesContext::IsAutomaticStyle() const
424*cdf0e10cSrcweir {
425*cdf0e10cSrcweir     return mpImpl->IsAutomaticStyle();
426*cdf0e10cSrcweir }
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir SvXMLStyleContext *SvXMLStylesContext::CreateStyleChildContext(
429*cdf0e10cSrcweir         sal_uInt16 p_nPrefix,
430*cdf0e10cSrcweir         const OUString& rLocalName,
431*cdf0e10cSrcweir         const uno::Reference< xml::sax::XAttributeList > & xAttrList )
432*cdf0e10cSrcweir {
433*cdf0e10cSrcweir     SvXMLStyleContext *pStyle = NULL;
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir     if(GetImport().GetDataStylesImport())
436*cdf0e10cSrcweir     {
437*cdf0e10cSrcweir         pStyle = GetImport().GetDataStylesImport()->CreateChildContext(GetImport(), p_nPrefix,
438*cdf0e10cSrcweir                                             rLocalName, xAttrList, *this);
439*cdf0e10cSrcweir     }
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir     if (!pStyle)
442*cdf0e10cSrcweir     {
443*cdf0e10cSrcweir         const SvXMLTokenMap& rTokenMap = GetStyleStylesElemTokenMap();
444*cdf0e10cSrcweir         sal_uInt16 nToken = rTokenMap.Get( p_nPrefix, rLocalName );
445*cdf0e10cSrcweir         switch( nToken  )
446*cdf0e10cSrcweir         {
447*cdf0e10cSrcweir             case XML_TOK_STYLE_STYLE:
448*cdf0e10cSrcweir             case XML_TOK_STYLE_DEFAULT_STYLE:
449*cdf0e10cSrcweir             {
450*cdf0e10cSrcweir                 sal_uInt16 nFamily = 0;
451*cdf0e10cSrcweir                 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
452*cdf0e10cSrcweir                 for( sal_Int16 i=0; i < nAttrCount; i++ )
453*cdf0e10cSrcweir                 {
454*cdf0e10cSrcweir                     const OUString& rAttrName = xAttrList->getNameByIndex( i );
455*cdf0e10cSrcweir                     OUString aLocalName;
456*cdf0e10cSrcweir                     sal_uInt16 nPrefix =
457*cdf0e10cSrcweir                         GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
458*cdf0e10cSrcweir                                                                     &aLocalName );
459*cdf0e10cSrcweir                     if( XML_NAMESPACE_STYLE == nPrefix &&
460*cdf0e10cSrcweir                         IsXMLToken( aLocalName, XML_FAMILY ) )
461*cdf0e10cSrcweir                     {
462*cdf0e10cSrcweir                         const OUString& rValue = xAttrList->getValueByIndex( i );
463*cdf0e10cSrcweir                         nFamily = GetFamily( rValue );
464*cdf0e10cSrcweir                         break;
465*cdf0e10cSrcweir                     }
466*cdf0e10cSrcweir                 }
467*cdf0e10cSrcweir                 pStyle = XML_TOK_STYLE_STYLE==nToken
468*cdf0e10cSrcweir                     ? CreateStyleStyleChildContext( nFamily, p_nPrefix,
469*cdf0e10cSrcweir                                                     rLocalName, xAttrList )
470*cdf0e10cSrcweir                     : CreateDefaultStyleStyleChildContext( nFamily, p_nPrefix,
471*cdf0e10cSrcweir                                                     rLocalName, xAttrList );
472*cdf0e10cSrcweir             }
473*cdf0e10cSrcweir             break;
474*cdf0e10cSrcweir             case XML_TOK_STYLE_PAGE_MASTER:
475*cdf0e10cSrcweir             case XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT:
476*cdf0e10cSrcweir             {
477*cdf0e10cSrcweir                 //there is not page family in odf now, so I specify one for it
478*cdf0e10cSrcweir                 sal_Bool bDefaultStyle  = XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT == nToken
479*cdf0e10cSrcweir                     ? sal_True: sal_False;
480*cdf0e10cSrcweir                 pStyle = new PageStyleContext( GetImport(), p_nPrefix,
481*cdf0e10cSrcweir                                                     rLocalName, xAttrList, *this, bDefaultStyle );
482*cdf0e10cSrcweir             }
483*cdf0e10cSrcweir             break;
484*cdf0e10cSrcweir             case XML_TOK_TEXT_LIST_STYLE:
485*cdf0e10cSrcweir                 pStyle = new SvxXMLListStyleContext( GetImport(), p_nPrefix,
486*cdf0e10cSrcweir                                                     rLocalName, xAttrList );
487*cdf0e10cSrcweir                 break;
488*cdf0e10cSrcweir             case XML_TOK_TEXT_OUTLINE:
489*cdf0e10cSrcweir                 pStyle = new SvxXMLListStyleContext( GetImport(), p_nPrefix,
490*cdf0e10cSrcweir                                                     rLocalName, xAttrList, sal_True );
491*cdf0e10cSrcweir                 break;
492*cdf0e10cSrcweir             case XML_TOK_TEXT_NOTE_CONFIG:
493*cdf0e10cSrcweir #ifndef SVX_LIGHT
494*cdf0e10cSrcweir                 pStyle = new XMLFootnoteConfigurationImportContext(GetImport(),
495*cdf0e10cSrcweir                                                                    p_nPrefix,
496*cdf0e10cSrcweir                                                                    rLocalName,
497*cdf0e10cSrcweir                                                                    xAttrList);
498*cdf0e10cSrcweir #else
499*cdf0e10cSrcweir                 // create default context to skip content
500*cdf0e10cSrcweir                 pStyle = new SvXMLStyleContext( GetImport(), nPrefix, rLocalName, xAttrList );
501*cdf0e10cSrcweir #endif // #ifndef SVX_LIGHT
502*cdf0e10cSrcweir                 break;
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir             case XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG:
505*cdf0e10cSrcweir #ifndef SVX_LIGHT
506*cdf0e10cSrcweir                 pStyle = new XMLIndexBibliographyConfigurationContext(
507*cdf0e10cSrcweir                     GetImport(), p_nPrefix, rLocalName, xAttrList);
508*cdf0e10cSrcweir #else
509*cdf0e10cSrcweir                 // create default context to skip content
510*cdf0e10cSrcweir                 pStyle = new SvXMLStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
511*cdf0e10cSrcweir #endif // #ifndef SVX_LIGHT
512*cdf0e10cSrcweir                 break;
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir             case XML_TOK_TEXT_LINENUMBERING_CONFIG:
515*cdf0e10cSrcweir #ifndef SVX_LIGHT
516*cdf0e10cSrcweir                 pStyle = new XMLLineNumberingImportContext(
517*cdf0e10cSrcweir                     GetImport(), p_nPrefix, rLocalName, xAttrList);
518*cdf0e10cSrcweir #else
519*cdf0e10cSrcweir                 // create default context to skip content
520*cdf0e10cSrcweir                 pStyle = new SvXMLStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
521*cdf0e10cSrcweir #endif // #ifndef SVX_LIGHT
522*cdf0e10cSrcweir                 break;
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir             //
525*cdf0e10cSrcweir             // FillStyles
526*cdf0e10cSrcweir             //
527*cdf0e10cSrcweir             case XML_TOK_STYLES_GRADIENTSTYLES:
528*cdf0e10cSrcweir             {
529*cdf0e10cSrcweir                 pStyle = new XMLGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
530*cdf0e10cSrcweir                 break;
531*cdf0e10cSrcweir             }
532*cdf0e10cSrcweir             case XML_TOK_STYLES_HATCHSTYLES:
533*cdf0e10cSrcweir             {
534*cdf0e10cSrcweir                 pStyle = new XMLHatchStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
535*cdf0e10cSrcweir                 break;
536*cdf0e10cSrcweir             }
537*cdf0e10cSrcweir             case XML_TOK_STYLES_BITMAPSTYLES:
538*cdf0e10cSrcweir             {
539*cdf0e10cSrcweir                 pStyle = new XMLBitmapStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
540*cdf0e10cSrcweir                 break;
541*cdf0e10cSrcweir             }
542*cdf0e10cSrcweir             case XML_TOK_STYLES_TRANSGRADIENTSTYLES:
543*cdf0e10cSrcweir             {
544*cdf0e10cSrcweir                 pStyle = new XMLTransGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
545*cdf0e10cSrcweir                 break;
546*cdf0e10cSrcweir             }
547*cdf0e10cSrcweir             case XML_TOK_STYLES_MARKERSTYLES:
548*cdf0e10cSrcweir             {
549*cdf0e10cSrcweir                 pStyle = new XMLMarkerStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
550*cdf0e10cSrcweir                 break;
551*cdf0e10cSrcweir             }
552*cdf0e10cSrcweir             case XML_TOK_STYLES_DASHSTYLES:
553*cdf0e10cSrcweir             {
554*cdf0e10cSrcweir                 pStyle = new XMLDashStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
555*cdf0e10cSrcweir                 break;
556*cdf0e10cSrcweir             }
557*cdf0e10cSrcweir         }
558*cdf0e10cSrcweir     }
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir     return pStyle;
561*cdf0e10cSrcweir }
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir SvXMLStyleContext *SvXMLStylesContext::CreateStyleStyleChildContext(
564*cdf0e10cSrcweir         sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
565*cdf0e10cSrcweir         const uno::Reference< xml::sax::XAttributeList > & xAttrList )
566*cdf0e10cSrcweir {
567*cdf0e10cSrcweir     SvXMLStyleContext *pStyle = 0;
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir     switch( nFamily )
570*cdf0e10cSrcweir     {
571*cdf0e10cSrcweir         case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
572*cdf0e10cSrcweir         case XML_STYLE_FAMILY_TEXT_TEXT:
573*cdf0e10cSrcweir         case XML_STYLE_FAMILY_TEXT_SECTION:
574*cdf0e10cSrcweir             pStyle = new XMLTextStyleContext( GetImport(), nPrefix, rLocalName,
575*cdf0e10cSrcweir                                               xAttrList, *this, nFamily );
576*cdf0e10cSrcweir             break;
577*cdf0e10cSrcweir 
578*cdf0e10cSrcweir         case XML_STYLE_FAMILY_TEXT_RUBY:
579*cdf0e10cSrcweir             pStyle = new XMLPropStyleContext( GetImport(), nPrefix, rLocalName,
580*cdf0e10cSrcweir                                               xAttrList, *this, nFamily );
581*cdf0e10cSrcweir             break;
582*cdf0e10cSrcweir         case XML_STYLE_FAMILY_SCH_CHART_ID:
583*cdf0e10cSrcweir             pStyle = new XMLChartStyleContext( GetImport(), nPrefix, rLocalName,
584*cdf0e10cSrcweir                                                xAttrList, *this, nFamily );
585*cdf0e10cSrcweir             break;
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir         case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
588*cdf0e10cSrcweir         case XML_STYLE_FAMILY_SD_PRESENTATION_ID:
589*cdf0e10cSrcweir         case XML_STYLE_FAMILY_SD_POOL_ID:
590*cdf0e10cSrcweir             pStyle = new XMLShapeStyleContext( GetImport(), nPrefix, rLocalName,
591*cdf0e10cSrcweir                                                xAttrList, *this, nFamily );
592*cdf0e10cSrcweir     }
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir     return pStyle;
595*cdf0e10cSrcweir }
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir SvXMLStyleContext *SvXMLStylesContext::CreateDefaultStyleStyleChildContext(
598*cdf0e10cSrcweir         sal_uInt16 /*nFamily*/, sal_uInt16 /*nPrefix*/, const OUString& /*rLocalName*/,
599*cdf0e10cSrcweir         const uno::Reference< xml::sax::XAttributeList > & )
600*cdf0e10cSrcweir {
601*cdf0e10cSrcweir     return 0;
602*cdf0e10cSrcweir }
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir sal_Bool SvXMLStylesContext::InsertStyleFamily( sal_uInt16 ) const
606*cdf0e10cSrcweir {
607*cdf0e10cSrcweir     return sal_True;
608*cdf0e10cSrcweir }
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir sal_uInt16 SvXMLStylesContext::GetFamily(
611*cdf0e10cSrcweir         const ::rtl::OUString& rValue ) const
612*cdf0e10cSrcweir {
613*cdf0e10cSrcweir     sal_uInt16 nFamily = 0U;
614*cdf0e10cSrcweir     if( IsXMLToken( rValue, XML_PARAGRAPH ) )
615*cdf0e10cSrcweir     {
616*cdf0e10cSrcweir         nFamily = XML_STYLE_FAMILY_TEXT_PARAGRAPH;
617*cdf0e10cSrcweir     }
618*cdf0e10cSrcweir     else if( IsXMLToken( rValue, XML_TEXT ) )
619*cdf0e10cSrcweir     {
620*cdf0e10cSrcweir         nFamily = XML_STYLE_FAMILY_TEXT_TEXT;
621*cdf0e10cSrcweir     }
622*cdf0e10cSrcweir     else if( IsXMLToken( rValue, XML_DATA_STYLE ) )
623*cdf0e10cSrcweir     {
624*cdf0e10cSrcweir         nFamily = XML_STYLE_FAMILY_DATA_STYLE;
625*cdf0e10cSrcweir     }
626*cdf0e10cSrcweir     else if ( IsXMLToken( rValue, XML_SECTION ) )
627*cdf0e10cSrcweir     {
628*cdf0e10cSrcweir         nFamily = XML_STYLE_FAMILY_TEXT_SECTION;
629*cdf0e10cSrcweir     }
630*cdf0e10cSrcweir     else if( IsXMLToken( rValue, XML_TABLE ) )
631*cdf0e10cSrcweir     {
632*cdf0e10cSrcweir         nFamily = XML_STYLE_FAMILY_TABLE_TABLE;
633*cdf0e10cSrcweir     }
634*cdf0e10cSrcweir     else if( IsXMLToken( rValue, XML_TABLE_COLUMN ) )
635*cdf0e10cSrcweir         nFamily = XML_STYLE_FAMILY_TABLE_COLUMN;
636*cdf0e10cSrcweir     else if( IsXMLToken( rValue, XML_TABLE_ROW ) )
637*cdf0e10cSrcweir         nFamily = XML_STYLE_FAMILY_TABLE_ROW;
638*cdf0e10cSrcweir     else if( IsXMLToken( rValue, XML_TABLE_CELL ) )
639*cdf0e10cSrcweir         nFamily = XML_STYLE_FAMILY_TABLE_CELL;
640*cdf0e10cSrcweir     else if( rValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(XML_STYLE_FAMILY_SD_GRAPHICS_NAME)))
641*cdf0e10cSrcweir     {
642*cdf0e10cSrcweir         nFamily = XML_STYLE_FAMILY_SD_GRAPHICS_ID;
643*cdf0e10cSrcweir     }
644*cdf0e10cSrcweir     else if( rValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(XML_STYLE_FAMILY_SD_PRESENTATION_NAME)))
645*cdf0e10cSrcweir     {
646*cdf0e10cSrcweir         nFamily = XML_STYLE_FAMILY_SD_PRESENTATION_ID;
647*cdf0e10cSrcweir     }
648*cdf0e10cSrcweir     else if( rValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(XML_STYLE_FAMILY_SD_POOL_NAME)))
649*cdf0e10cSrcweir     {
650*cdf0e10cSrcweir         nFamily = XML_STYLE_FAMILY_SD_POOL_ID;
651*cdf0e10cSrcweir     }
652*cdf0e10cSrcweir     else if( rValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME)))
653*cdf0e10cSrcweir     {
654*cdf0e10cSrcweir         nFamily = XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID;
655*cdf0e10cSrcweir     }
656*cdf0e10cSrcweir     else if( rValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( XML_STYLE_FAMILY_SCH_CHART_NAME )))
657*cdf0e10cSrcweir     {
658*cdf0e10cSrcweir         nFamily = XML_STYLE_FAMILY_SCH_CHART_ID;
659*cdf0e10cSrcweir     }
660*cdf0e10cSrcweir     else if ( IsXMLToken( rValue, XML_RUBY ) )
661*cdf0e10cSrcweir     {
662*cdf0e10cSrcweir         nFamily = XML_STYLE_FAMILY_TEXT_RUBY;
663*cdf0e10cSrcweir     }
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir     return nFamily;
666*cdf0e10cSrcweir }
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir UniReference < SvXMLImportPropertyMapper > SvXMLStylesContext::GetImportPropertyMapper(
669*cdf0e10cSrcweir                         sal_uInt16 nFamily ) const
670*cdf0e10cSrcweir {
671*cdf0e10cSrcweir     UniReference < SvXMLImportPropertyMapper > xMapper;
672*cdf0e10cSrcweir 
673*cdf0e10cSrcweir     switch( nFamily )
674*cdf0e10cSrcweir     {
675*cdf0e10cSrcweir     case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
676*cdf0e10cSrcweir         if( !mxParaImpPropMapper.is() )
677*cdf0e10cSrcweir         {
678*cdf0e10cSrcweir             SvXMLStylesContext * pThis = (SvXMLStylesContext *)this;
679*cdf0e10cSrcweir             pThis->mxParaImpPropMapper =
680*cdf0e10cSrcweir                 pThis->GetImport().GetTextImport()
681*cdf0e10cSrcweir                      ->GetParaImportPropertySetMapper();
682*cdf0e10cSrcweir         }
683*cdf0e10cSrcweir         xMapper = mxParaImpPropMapper;
684*cdf0e10cSrcweir         break;
685*cdf0e10cSrcweir     case XML_STYLE_FAMILY_TEXT_TEXT:
686*cdf0e10cSrcweir         if( !mxTextImpPropMapper.is() )
687*cdf0e10cSrcweir         {
688*cdf0e10cSrcweir             SvXMLStylesContext * pThis = (SvXMLStylesContext *)this;
689*cdf0e10cSrcweir             pThis->mxTextImpPropMapper =
690*cdf0e10cSrcweir                 pThis->GetImport().GetTextImport()
691*cdf0e10cSrcweir                      ->GetTextImportPropertySetMapper();
692*cdf0e10cSrcweir         }
693*cdf0e10cSrcweir         xMapper = mxTextImpPropMapper;
694*cdf0e10cSrcweir         break;
695*cdf0e10cSrcweir 
696*cdf0e10cSrcweir     case XML_STYLE_FAMILY_TEXT_SECTION:
697*cdf0e10cSrcweir         // don't cache section mapper, as it's rarely used
698*cdf0e10cSrcweir         // *sigh*, cast to non-const, because this is a const method,
699*cdf0e10cSrcweir         // but SvXMLImport::GetTextImport() isn't.
700*cdf0e10cSrcweir         xMapper = ((SvXMLStylesContext*)this)->GetImport().GetTextImport()->
701*cdf0e10cSrcweir             GetSectionImportPropertySetMapper();
702*cdf0e10cSrcweir         break;
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir     case XML_STYLE_FAMILY_TEXT_RUBY:
705*cdf0e10cSrcweir         // don't cache section mapper, as it's rarely used
706*cdf0e10cSrcweir         // *sigh*, cast to non-const, because this is a const method,
707*cdf0e10cSrcweir         // but SvXMLImport::GetTextImport() isn't.
708*cdf0e10cSrcweir         xMapper = ((SvXMLStylesContext*)this)->GetImport().GetTextImport()->
709*cdf0e10cSrcweir             GetRubyImportPropertySetMapper();
710*cdf0e10cSrcweir         break;
711*cdf0e10cSrcweir 
712*cdf0e10cSrcweir     case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
713*cdf0e10cSrcweir     case XML_STYLE_FAMILY_SD_PRESENTATION_ID:
714*cdf0e10cSrcweir     case XML_STYLE_FAMILY_SD_POOL_ID:
715*cdf0e10cSrcweir         if(!mxShapeImpPropMapper.is())
716*cdf0e10cSrcweir         {
717*cdf0e10cSrcweir             UniReference< XMLShapeImportHelper > aImpHelper = ((SvXMLImport&)GetImport()).GetShapeImport();
718*cdf0e10cSrcweir             ((SvXMLStylesContext*)this)->mxShapeImpPropMapper =
719*cdf0e10cSrcweir                 aImpHelper->GetPropertySetMapper();
720*cdf0e10cSrcweir         }
721*cdf0e10cSrcweir         xMapper = mxShapeImpPropMapper;
722*cdf0e10cSrcweir         break;
723*cdf0e10cSrcweir #ifndef SVX_LIGHT
724*cdf0e10cSrcweir     case XML_STYLE_FAMILY_SCH_CHART_ID:
725*cdf0e10cSrcweir         if( ! mxChartImpPropMapper.is() )
726*cdf0e10cSrcweir         {
727*cdf0e10cSrcweir             XMLPropertySetMapper *pPropMapper = new XMLChartPropertySetMapper();
728*cdf0e10cSrcweir             mxChartImpPropMapper = new XMLChartImportPropertyMapper( pPropMapper, GetImport() );
729*cdf0e10cSrcweir         }
730*cdf0e10cSrcweir         xMapper = mxChartImpPropMapper;
731*cdf0e10cSrcweir         break;
732*cdf0e10cSrcweir #endif
733*cdf0e10cSrcweir     case XML_STYLE_FAMILY_PAGE_MASTER:
734*cdf0e10cSrcweir         if( ! mxPageImpPropMapper.is() )
735*cdf0e10cSrcweir         {
736*cdf0e10cSrcweir             XMLPropertySetMapper *pPropMapper =
737*cdf0e10cSrcweir                 new XMLPageMasterPropSetMapper();
738*cdf0e10cSrcweir             mxPageImpPropMapper =
739*cdf0e10cSrcweir                 new PageMasterImportPropertyMapper( pPropMapper,
740*cdf0e10cSrcweir                                     ((SvXMLStylesContext*)this)->GetImport() );
741*cdf0e10cSrcweir         }
742*cdf0e10cSrcweir         xMapper = mxPageImpPropMapper;
743*cdf0e10cSrcweir         break;
744*cdf0e10cSrcweir     }
745*cdf0e10cSrcweir 
746*cdf0e10cSrcweir     return xMapper;
747*cdf0e10cSrcweir }
748*cdf0e10cSrcweir 
749*cdf0e10cSrcweir Reference < XAutoStyleFamily > SvXMLStylesContext::GetAutoStyles( sal_uInt16 nFamily ) const
750*cdf0e10cSrcweir {
751*cdf0e10cSrcweir     Reference < XAutoStyleFamily > xAutoStyles;
752*cdf0e10cSrcweir     if( XML_STYLE_FAMILY_TEXT_TEXT == nFamily || XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily)
753*cdf0e10cSrcweir     {
754*cdf0e10cSrcweir         bool bPara = XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily;
755*cdf0e10cSrcweir         OUString sName;
756*cdf0e10cSrcweir         if( !bPara && mxTextAutoStyles.is() )
757*cdf0e10cSrcweir             xAutoStyles = mxTextAutoStyles;
758*cdf0e10cSrcweir         else if( bPara && mxParaAutoStyles.is() )
759*cdf0e10cSrcweir             xAutoStyles = mxParaAutoStyles;
760*cdf0e10cSrcweir         else
761*cdf0e10cSrcweir         {
762*cdf0e10cSrcweir             sName = bPara ?
763*cdf0e10cSrcweir                 OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphStyles" ) ):
764*cdf0e10cSrcweir                 OUString( RTL_CONSTASCII_USTRINGPARAM( "CharacterStyles" ) );
765*cdf0e10cSrcweir             Reference< XAutoStylesSupplier > xAutoStylesSupp(   GetImport().GetModel(), UNO_QUERY );
766*cdf0e10cSrcweir             Reference< XAutoStyles > xAutoStyleFamilies = xAutoStylesSupp->getAutoStyles();
767*cdf0e10cSrcweir             if (xAutoStyleFamilies->hasByName(sName))
768*cdf0e10cSrcweir             {
769*cdf0e10cSrcweir                 Any aAny = xAutoStyleFamilies->getByName( sName );
770*cdf0e10cSrcweir                 xAutoStyles = *(Reference<XAutoStyleFamily>*)aAny.getValue();
771*cdf0e10cSrcweir                 if( bPara )
772*cdf0e10cSrcweir                     ((SvXMLStylesContext *)this)->mxParaAutoStyles = xAutoStyles;
773*cdf0e10cSrcweir                 else
774*cdf0e10cSrcweir                     ((SvXMLStylesContext *)this)->mxTextAutoStyles = xAutoStyles;
775*cdf0e10cSrcweir             }
776*cdf0e10cSrcweir         }
777*cdf0e10cSrcweir     }
778*cdf0e10cSrcweir     return xAutoStyles;
779*cdf0e10cSrcweir }
780*cdf0e10cSrcweir 
781*cdf0e10cSrcweir Reference < XNameContainer > SvXMLStylesContext::GetStylesContainer(
782*cdf0e10cSrcweir                                                 sal_uInt16 nFamily ) const
783*cdf0e10cSrcweir {
784*cdf0e10cSrcweir     Reference < XNameContainer > xStyles;
785*cdf0e10cSrcweir     OUString sName;
786*cdf0e10cSrcweir     switch( nFamily )
787*cdf0e10cSrcweir     {
788*cdf0e10cSrcweir     case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
789*cdf0e10cSrcweir         if( mxParaStyles.is() )
790*cdf0e10cSrcweir             xStyles = mxParaStyles;
791*cdf0e10cSrcweir         else
792*cdf0e10cSrcweir             sName =
793*cdf0e10cSrcweir                 OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphStyles" ) );
794*cdf0e10cSrcweir         break;
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir     case XML_STYLE_FAMILY_TEXT_TEXT:
797*cdf0e10cSrcweir         if( mxTextStyles.is() )
798*cdf0e10cSrcweir             xStyles = mxTextStyles;
799*cdf0e10cSrcweir         else
800*cdf0e10cSrcweir             sName =
801*cdf0e10cSrcweir                 OUString( RTL_CONSTASCII_USTRINGPARAM( "CharacterStyles" ) );
802*cdf0e10cSrcweir         break;
803*cdf0e10cSrcweir     }
804*cdf0e10cSrcweir     if( !xStyles.is() && sName.getLength() )
805*cdf0e10cSrcweir     {
806*cdf0e10cSrcweir         Reference< XStyleFamiliesSupplier > xFamiliesSupp(
807*cdf0e10cSrcweir                                         GetImport().GetModel(), UNO_QUERY );
808*cdf0e10cSrcweir         if ( xFamiliesSupp.is() )
809*cdf0e10cSrcweir         {
810*cdf0e10cSrcweir             Reference< XNameAccess > xFamilies = xFamiliesSupp->getStyleFamilies();
811*cdf0e10cSrcweir             if (xFamilies->hasByName(sName))
812*cdf0e10cSrcweir             {
813*cdf0e10cSrcweir                 xStyles.set(xFamilies->getByName( sName ),uno::UNO_QUERY);
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir                 switch( nFamily )
816*cdf0e10cSrcweir                 {
817*cdf0e10cSrcweir                 case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
818*cdf0e10cSrcweir                     ((SvXMLStylesContext *)this)->mxParaStyles = xStyles;
819*cdf0e10cSrcweir                     break;
820*cdf0e10cSrcweir 
821*cdf0e10cSrcweir                 case XML_STYLE_FAMILY_TEXT_TEXT:
822*cdf0e10cSrcweir                     ((SvXMLStylesContext *)this)->mxTextStyles = xStyles;
823*cdf0e10cSrcweir                     break;
824*cdf0e10cSrcweir                 }
825*cdf0e10cSrcweir             }
826*cdf0e10cSrcweir         }
827*cdf0e10cSrcweir     }
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir     return xStyles;
830*cdf0e10cSrcweir }
831*cdf0e10cSrcweir 
832*cdf0e10cSrcweir OUString SvXMLStylesContext::GetServiceName( sal_uInt16 nFamily ) const
833*cdf0e10cSrcweir {
834*cdf0e10cSrcweir     String sServiceName;
835*cdf0e10cSrcweir     switch( nFamily )
836*cdf0e10cSrcweir     {
837*cdf0e10cSrcweir     case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
838*cdf0e10cSrcweir         sServiceName = msParaStyleServiceName;
839*cdf0e10cSrcweir         break;
840*cdf0e10cSrcweir     case XML_STYLE_FAMILY_TEXT_TEXT:
841*cdf0e10cSrcweir         sServiceName = msTextStyleServiceName;
842*cdf0e10cSrcweir         break;
843*cdf0e10cSrcweir     }
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir     return sServiceName;
846*cdf0e10cSrcweir }
847*cdf0e10cSrcweir 
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir SvXMLStylesContext::SvXMLStylesContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
850*cdf0e10cSrcweir                                         const OUString& rLName,
851*cdf0e10cSrcweir                                         const uno::Reference< xml::sax::XAttributeList > &, sal_Bool bAuto ) :
852*cdf0e10cSrcweir     SvXMLImportContext( rImport, nPrfx, rLName ),
853*cdf0e10cSrcweir     msParaStyleServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.ParagraphStyle" ) ),
854*cdf0e10cSrcweir     msTextStyleServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.CharacterStyle" ) ),
855*cdf0e10cSrcweir     mpImpl( new SvXMLStylesContext_Impl( bAuto ) ),
856*cdf0e10cSrcweir     mpStyleStylesElemTokenMap( 0 )
857*cdf0e10cSrcweir {
858*cdf0e10cSrcweir }
859*cdf0e10cSrcweir 
860*cdf0e10cSrcweir 
861*cdf0e10cSrcweir SvXMLStylesContext::~SvXMLStylesContext()
862*cdf0e10cSrcweir {
863*cdf0e10cSrcweir     delete mpStyleStylesElemTokenMap;
864*cdf0e10cSrcweir     delete mpImpl;
865*cdf0e10cSrcweir }
866*cdf0e10cSrcweir 
867*cdf0e10cSrcweir SvXMLImportContext *SvXMLStylesContext::CreateChildContext( sal_uInt16 nPrefix,
868*cdf0e10cSrcweir                                          const OUString& rLocalName,
869*cdf0e10cSrcweir                                          const uno::Reference< xml::sax::XAttributeList > & xAttrList )
870*cdf0e10cSrcweir {
871*cdf0e10cSrcweir     SvXMLImportContext *pContext = 0;
872*cdf0e10cSrcweir 
873*cdf0e10cSrcweir     SvXMLStyleContext *pStyle =
874*cdf0e10cSrcweir         CreateStyleChildContext( nPrefix, rLocalName, xAttrList );
875*cdf0e10cSrcweir //      DBG_ASSERT( pStyle->GetFamily(), "Style without a family" );
876*cdf0e10cSrcweir     if( pStyle )
877*cdf0e10cSrcweir     {
878*cdf0e10cSrcweir         if( !pStyle->IsTransient() )
879*cdf0e10cSrcweir             mpImpl->AddStyle( pStyle );
880*cdf0e10cSrcweir         pContext = pStyle;
881*cdf0e10cSrcweir     }
882*cdf0e10cSrcweir     else
883*cdf0e10cSrcweir     {
884*cdf0e10cSrcweir         pContext = new SvXMLImportContext( GetImport(), nPrefix,
885*cdf0e10cSrcweir                                            rLocalName );
886*cdf0e10cSrcweir     }
887*cdf0e10cSrcweir 
888*cdf0e10cSrcweir     return pContext;
889*cdf0e10cSrcweir }
890*cdf0e10cSrcweir 
891*cdf0e10cSrcweir void SvXMLStylesContext::EndElement()
892*cdf0e10cSrcweir {
893*cdf0e10cSrcweir }
894*cdf0e10cSrcweir 
895*cdf0e10cSrcweir void SvXMLStylesContext::AddStyle(SvXMLStyleContext& rNew)
896*cdf0e10cSrcweir {
897*cdf0e10cSrcweir     mpImpl->AddStyle( &rNew );
898*cdf0e10cSrcweir }
899*cdf0e10cSrcweir 
900*cdf0e10cSrcweir void SvXMLStylesContext::Clear()
901*cdf0e10cSrcweir {
902*cdf0e10cSrcweir     mpImpl->Clear();
903*cdf0e10cSrcweir }
904*cdf0e10cSrcweir 
905*cdf0e10cSrcweir void SvXMLStylesContext::CopyAutoStylesToDoc()
906*cdf0e10cSrcweir {
907*cdf0e10cSrcweir     sal_uInt32 nCount = GetStyleCount();
908*cdf0e10cSrcweir     sal_uInt32 i;
909*cdf0e10cSrcweir     for( i = 0; i < nCount; i++ )
910*cdf0e10cSrcweir     {
911*cdf0e10cSrcweir         SvXMLStyleContext *pStyle = GetStyle( i );
912*cdf0e10cSrcweir         if( !pStyle || ( pStyle->GetFamily() != XML_STYLE_FAMILY_TEXT_TEXT &&
913*cdf0e10cSrcweir             pStyle->GetFamily() != XML_STYLE_FAMILY_TEXT_PARAGRAPH  &&
914*cdf0e10cSrcweir             pStyle->GetFamily() != XML_STYLE_FAMILY_TABLE_CELL ) )
915*cdf0e10cSrcweir             continue;
916*cdf0e10cSrcweir         pStyle->CreateAndInsert( sal_False );
917*cdf0e10cSrcweir     }
918*cdf0e10cSrcweir }
919*cdf0e10cSrcweir 
920*cdf0e10cSrcweir void SvXMLStylesContext::CopyStylesToDoc( sal_Bool bOverwrite,
921*cdf0e10cSrcweir                                           sal_Bool bFinish )
922*cdf0e10cSrcweir {
923*cdf0e10cSrcweir     // pass 1: create text, paragraph and frame styles
924*cdf0e10cSrcweir     sal_uInt32 nCount = GetStyleCount();
925*cdf0e10cSrcweir     sal_uInt32 i;
926*cdf0e10cSrcweir 
927*cdf0e10cSrcweir     for( i = 0; i < nCount; i++ )
928*cdf0e10cSrcweir     {
929*cdf0e10cSrcweir         SvXMLStyleContext *pStyle = GetStyle( i );
930*cdf0e10cSrcweir         if( !pStyle )
931*cdf0e10cSrcweir             continue;
932*cdf0e10cSrcweir 
933*cdf0e10cSrcweir         if (pStyle->IsDefaultStyle())
934*cdf0e10cSrcweir             pStyle->SetDefaults();
935*cdf0e10cSrcweir         else if( InsertStyleFamily( pStyle->GetFamily() ) )
936*cdf0e10cSrcweir             pStyle->CreateAndInsert( bOverwrite );
937*cdf0e10cSrcweir     }
938*cdf0e10cSrcweir 
939*cdf0e10cSrcweir     // pass 2: create list styles (they require char styles)
940*cdf0e10cSrcweir     for( i=0; i<nCount; i++ )
941*cdf0e10cSrcweir     {
942*cdf0e10cSrcweir         SvXMLStyleContext *pStyle = GetStyle( i );
943*cdf0e10cSrcweir         if( !pStyle || pStyle->IsDefaultStyle())
944*cdf0e10cSrcweir             continue;
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir         if( InsertStyleFamily( pStyle->GetFamily() ) )
947*cdf0e10cSrcweir             pStyle->CreateAndInsertLate( bOverwrite );
948*cdf0e10cSrcweir     }
949*cdf0e10cSrcweir 
950*cdf0e10cSrcweir     // pass3: finish creation of styles
951*cdf0e10cSrcweir     if( bFinish )
952*cdf0e10cSrcweir         FinishStyles( bOverwrite );
953*cdf0e10cSrcweir }
954*cdf0e10cSrcweir 
955*cdf0e10cSrcweir void SvXMLStylesContext::FinishStyles( sal_Bool bOverwrite )
956*cdf0e10cSrcweir {
957*cdf0e10cSrcweir     sal_uInt32 nCount = GetStyleCount();
958*cdf0e10cSrcweir     for( sal_uInt32 i=0; i<nCount; i++ )
959*cdf0e10cSrcweir     {
960*cdf0e10cSrcweir         SvXMLStyleContext *pStyle = GetStyle( i );
961*cdf0e10cSrcweir         if( !pStyle || !pStyle->IsValid() || pStyle->IsDefaultStyle() )
962*cdf0e10cSrcweir             continue;
963*cdf0e10cSrcweir 
964*cdf0e10cSrcweir         if( InsertStyleFamily( pStyle->GetFamily() ) )
965*cdf0e10cSrcweir             pStyle->Finish( bOverwrite );
966*cdf0e10cSrcweir     }
967*cdf0e10cSrcweir }
968*cdf0e10cSrcweir 
969*cdf0e10cSrcweir 
970*cdf0e10cSrcweir const SvXMLStyleContext *SvXMLStylesContext::FindStyleChildContext(
971*cdf0e10cSrcweir                                   sal_uInt16 nFamily,
972*cdf0e10cSrcweir                                   const OUString& rName,
973*cdf0e10cSrcweir                                   sal_Bool bCreateIndex ) const
974*cdf0e10cSrcweir {
975*cdf0e10cSrcweir     return mpImpl->FindStyleChildContext( nFamily, rName, bCreateIndex );
976*cdf0e10cSrcweir }
977