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