Bump for 3.6-28
[LibreOffice.git] / xmloff / source / style / xmlstyle.cxx
blobd99469d703387cc2a674925da29d1af2b4d2d1f8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <com/sun/star/xml/sax/SAXParseException.hpp>
30 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
31 #include <com/sun/star/xml/sax/SAXException.hpp>
32 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
33 #include <com/sun/star/xml/sax/XAttributeList.hpp>
34 #include <com/sun/star/xml/sax/XLocator.hpp>
35 #include <com/sun/star/container/XNameContainer.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
38 #include <com/sun/star/style/XAutoStylesSupplier.hpp>
39 #include <com/sun/star/style/XAutoStyleFamily.hpp>
40 #include "PageMasterPropMapper.hxx"
41 #include <tools/debug.hxx>
42 #include <svl/cntnrsrt.hxx>
43 #include <svl/itemset.hxx>
44 #include <xmloff/nmspmap.hxx>
45 #include "xmloff/xmlnmspe.hxx"
46 #include <xmloff/xmltoken.hxx>
48 #include <xmloff/families.hxx>
49 #include <xmloff/xmlimp.hxx>
50 #include <xmloff/xmlnumi.hxx>
51 #include <xmloff/xmlimppr.hxx>
52 #include <xmloff/xmlstyle.hxx>
53 #include <xmloff/txtstyli.hxx>
54 #include <xmloff/txtprmap.hxx>
55 #include <xmloff/xmlnumfi.hxx>
56 #include "XMLChartStyleContext.hxx"
57 #include "XMLChartPropertySetMapper.hxx"
58 #include <xmloff/XMLShapeStyleContext.hxx>
59 #include "FillStyleContext.hxx"
60 #include "XMLFootnoteConfigurationImportContext.hxx"
61 #include "XMLIndexBibliographyConfigurationContext.hxx"
62 #include "XMLLineNumberingImportContext.hxx"
63 #include "PageMasterImportContext.hxx"
64 #include "PageMasterImportPropMapper.hxx"
66 #include <vector>
68 using ::rtl::OUString;
69 using ::rtl::OUStringBuffer;
70 using ::std::vector;
72 using namespace ::com::sun::star;
73 using namespace ::com::sun::star::uno;
74 using namespace ::com::sun::star::container;
75 using namespace ::com::sun::star::style;
76 using namespace ::xmloff::token;
78 // ---------------------------------------------------------------------
80 static SvXMLTokenMapEntry aStyleStylesElemTokenMap[] =
82 { XML_NAMESPACE_STYLE, XML_STYLE, XML_TOK_STYLE_STYLE },
83 { XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT, XML_TOK_STYLE_PAGE_MASTER },
84 { XML_NAMESPACE_TEXT, XML_LIST_STYLE, XML_TOK_TEXT_LIST_STYLE },
85 { XML_NAMESPACE_TEXT, XML_OUTLINE_STYLE, XML_TOK_TEXT_OUTLINE },
86 { XML_NAMESPACE_STYLE, XML_DEFAULT_STYLE, XML_TOK_STYLE_DEFAULT_STYLE },
87 { XML_NAMESPACE_DRAW, XML_GRADIENT, XML_TOK_STYLES_GRADIENTSTYLES },
88 { XML_NAMESPACE_DRAW, XML_HATCH, XML_TOK_STYLES_HATCHSTYLES },
89 { XML_NAMESPACE_DRAW, XML_FILL_IMAGE, XML_TOK_STYLES_BITMAPSTYLES },
90 { XML_NAMESPACE_DRAW, XML_OPACITY, XML_TOK_STYLES_TRANSGRADIENTSTYLES },
91 { XML_NAMESPACE_DRAW, XML_MARKER, XML_TOK_STYLES_MARKERSTYLES },
92 { XML_NAMESPACE_DRAW, XML_STROKE_DASH, XML_TOK_STYLES_DASHSTYLES },
93 { XML_NAMESPACE_TEXT, XML_NOTES_CONFIGURATION, XML_TOK_TEXT_NOTE_CONFIG },
94 { XML_NAMESPACE_TEXT, XML_BIBLIOGRAPHY_CONFIGURATION, XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG },
95 { XML_NAMESPACE_TEXT, XML_LINENUMBERING_CONFIGURATION,XML_TOK_TEXT_LINENUMBERING_CONFIG },
96 { XML_NAMESPACE_STYLE, XML_DEFAULT_PAGE_LAYOUT, XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT },
97 XML_TOKEN_MAP_END
100 const SvXMLTokenMap& SvXMLStylesContext::GetStyleStylesElemTokenMap()
102 if( !mpStyleStylesElemTokenMap )
103 mpStyleStylesElemTokenMap =
104 new SvXMLTokenMap( aStyleStylesElemTokenMap );
106 return *mpStyleStylesElemTokenMap;
109 // ---------------------------------------------------------------------
111 void SvXMLStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
112 const OUString& rLocalName,
113 const OUString& rValue )
115 // TODO: use a map here
116 if( XML_NAMESPACE_STYLE == nPrefixKey )
118 if( IsXMLToken( rLocalName, XML_FAMILY ) )
120 if( IsXMLToken( rValue, XML_PARAGRAPH ) )
121 mnFamily = (sal_uInt16)SFX_STYLE_FAMILY_PARA;
122 else if( IsXMLToken( rValue, XML_TEXT ) )
123 mnFamily = (sal_uInt16)SFX_STYLE_FAMILY_CHAR;
125 else if( IsXMLToken( rLocalName, XML_NAME ) )
127 maName = rValue;
129 else if( IsXMLToken( rLocalName, XML_DISPLAY_NAME ) )
131 maDisplayName = rValue;
133 else if( IsXMLToken( rLocalName, XML_PARENT_STYLE_NAME ) )
135 maParentName = rValue;
137 else if( IsXMLToken( rLocalName, XML_NEXT_STYLE_NAME ) )
139 maFollow = rValue;
141 else if( IsXMLToken( rLocalName, XML_HELP_FILE_NAME ) )
143 maHelpFile = rValue;
145 else if( IsXMLToken( rLocalName, XML_HELP_ID ) )
147 sal_Int32 nTmp = rValue.toInt32();
148 mnHelpId =
149 (nTmp < 0L) ? 0U : ( (nTmp > USHRT_MAX) ? USHRT_MAX
150 : (sal_uInt16)nTmp );
155 TYPEINIT1( SvXMLStyleContext, SvXMLImportContext );
157 SvXMLStyleContext::SvXMLStyleContext(
158 SvXMLImport& rImp, sal_uInt16 nPrfx,
159 const OUString& rLName,
160 const uno::Reference< xml::sax::XAttributeList >&,
161 sal_uInt16 nFam, sal_Bool bDefault ) :
162 SvXMLImportContext( rImp, nPrfx, rLName ),
163 mnHelpId( UCHAR_MAX ),
164 mnFamily( nFam ),
165 mbValid( sal_True ),
166 mbNew( sal_True ),
167 mbDefaultStyle( bDefault )
171 SvXMLStyleContext::~SvXMLStyleContext()
175 SvXMLImportContext *SvXMLStyleContext::CreateChildContext( sal_uInt16 nPrefix,
176 const OUString& rLocalName,
177 const uno::Reference< xml::sax::XAttributeList > & )
179 return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
182 void SvXMLStyleContext::StartElement( const uno::Reference< xml::sax::XAttributeList > & xAttrList )
184 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
185 for( sal_Int16 i=0; i < nAttrCount; i++ )
187 const OUString& rAttrName = xAttrList->getNameByIndex( i );
188 OUString aLocalName;
189 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
190 const OUString& rValue = xAttrList->getValueByIndex( i );
192 SetAttribute( nPrefix, aLocalName, rValue );
196 void SvXMLStyleContext::SetDefaults()
200 void SvXMLStyleContext::CreateAndInsert( sal_Bool /*bOverwrite*/ )
204 void SvXMLStyleContext::CreateAndInsertLate( sal_Bool /*bOverwrite*/ )
208 void SvXMLStyleContext::Finish( sal_Bool /*bOverwrite*/ )
212 sal_Bool SvXMLStyleContext::IsTransient() const
214 return sal_False;
217 // ---------------------------------------------------------------------
219 class SvXMLStyleIndex_Impl
221 OUString sName;
222 sal_uInt16 nFamily;
223 const SvXMLStyleContext *pStyle;
225 public:
227 SvXMLStyleIndex_Impl( sal_uInt16 nFam, const OUString& rName ) :
228 sName( rName ),
229 nFamily( nFam ),
230 pStyle ( 0 )
234 SvXMLStyleIndex_Impl( const SvXMLStyleContext *pStl ) :
235 sName( pStl->GetName() ),
236 nFamily( pStl->GetFamily() ),
237 pStyle ( pStl )
241 const OUString& GetName() const { return sName; }
242 sal_uInt16 GetFamily() const { return nFamily; }
243 const SvXMLStyleContext *GetStyle() const { return pStyle; }
246 int SvXMLStyleIndexCmp_Impl( const SvXMLStyleIndex_Impl& r1,
247 const SvXMLStyleIndex_Impl& r2 )
249 int nRet;
250 if( (sal_uInt16)r1.GetFamily() < (sal_uInt16)r2.GetFamily() )
251 nRet = -1;
252 else if( (sal_uInt16)r1.GetFamily() > (sal_uInt16)r2.GetFamily() )
253 nRet = 1;
254 else
255 nRet = (int)r1.GetName().compareTo( r2.GetName() );
257 return nRet;
260 // ---------------------------------------------------------------------
262 typedef SvXMLStyleContext *SvXMLStyleContextPtr;
263 typedef vector< SvXMLStyleContextPtr > SvXMLStyleContexts_Impl;
265 DECLARE_CONTAINER_SORT_DEL( SvXMLStyleIndices_Impl, SvXMLStyleIndex_Impl )
266 IMPL_CONTAINER_SORT( SvXMLStyleIndices_Impl, SvXMLStyleIndex_Impl,
267 SvXMLStyleIndexCmp_Impl )
270 class SvXMLStylesContext_Impl
272 SvXMLStyleContexts_Impl aStyles;
273 SvXMLStyleIndices_Impl *pIndices;
274 sal_Bool bAutomaticStyle;
276 #ifdef DBG_UTIL
277 sal_uInt32 nIndexCreated;
278 #endif
280 void FlushIndex() { delete pIndices; pIndices = 0; }
282 public:
283 SvXMLStylesContext_Impl( sal_Bool bAuto );
284 ~SvXMLStylesContext_Impl();
286 size_t GetStyleCount() const { return aStyles.size(); }
288 const SvXMLStyleContext *GetStyle( size_t i ) const
290 return i < aStyles.size() ? aStyles[ i ] : 0;
293 SvXMLStyleContext *GetStyle( size_t i )
295 return i < aStyles.size() ? aStyles[ i ] : 0;
298 inline void AddStyle( SvXMLStyleContext *pStyle );
299 void Clear();
301 const SvXMLStyleContext *FindStyleChildContext( sal_uInt16 nFamily,
302 const OUString& rName, sal_Bool bCreateIndex ) const;
303 sal_Bool IsAutomaticStyle() const { return bAutomaticStyle; }
306 SvXMLStylesContext_Impl::SvXMLStylesContext_Impl( sal_Bool bAuto ) :
307 pIndices( 0 ),
308 bAutomaticStyle( bAuto )
309 #ifdef DBG_UTIL
310 , nIndexCreated( 0 )
311 #endif
314 SvXMLStylesContext_Impl::~SvXMLStylesContext_Impl()
316 delete pIndices;
318 for ( size_t i = 0, n = aStyles.size(); i < n; ++i )
320 SvXMLStyleContext *pStyle = aStyles[ i ];
321 pStyle->ReleaseRef();
323 aStyles.clear();
326 inline void SvXMLStylesContext_Impl::AddStyle( SvXMLStyleContext *pStyle )
328 aStyles.push_back( pStyle );
329 pStyle->AddRef();
331 FlushIndex();
334 void SvXMLStylesContext_Impl::Clear()
336 FlushIndex();
338 for ( size_t i = 0, n = aStyles.size(); i < n; ++i )
340 SvXMLStyleContext *pStyle = aStyles[ i ];
341 pStyle->ReleaseRef();
343 aStyles.clear();
346 const SvXMLStyleContext *SvXMLStylesContext_Impl::FindStyleChildContext(
347 sal_uInt16 nFamily,
348 const OUString& rName,
349 sal_Bool bCreateIndex ) const
351 const SvXMLStyleContext *pStyle = 0;
353 if( !pIndices && bCreateIndex && !aStyles.empty() )
355 #ifdef DBG_UTIL
356 DBG_ASSERT( 0==nIndexCreated,
357 "Performance warning: sdbcx::Index created multiple times" );
358 #endif
359 ((SvXMLStylesContext_Impl *)this)->pIndices =
360 new SvXMLStyleIndices_Impl(
361 sal::static_int_cast< sal_uInt16 >( aStyles.size() ), 5 );
362 for( size_t i = 0; i < aStyles.size(); i++ )
364 SvXMLStyleIndex_Impl* pStyleIndex = new SvXMLStyleIndex_Impl( aStyles[ i ] );
365 if (!pIndices->Insert( pStyleIndex ))
367 OSL_FAIL("Here is a double Style");
368 delete pStyleIndex;
371 #ifdef DBG_UTIL
372 ((SvXMLStylesContext_Impl *)this)->nIndexCreated++;
373 #endif
376 if( pIndices )
378 SvXMLStyleIndex_Impl aIndex( nFamily, rName );
379 sal_uLong nPos = 0;
380 if( pIndices->Seek_Entry( &aIndex, &nPos ) )
381 pStyle = pIndices->GetObject( nPos )->GetStyle();
383 else
385 for( size_t i = 0; !pStyle && i < aStyles.size(); i++ )
387 const SvXMLStyleContext *pS = aStyles[ i ];
388 if( pS->GetFamily() == nFamily &&
389 pS->GetName() == rName )
390 pStyle = pS;
393 return pStyle;
396 // ---------------------------------------------------------------------
398 TYPEINIT1( SvXMLStylesContext, SvXMLImportContext );
400 sal_uInt32 SvXMLStylesContext::GetStyleCount() const
402 return mpImpl->GetStyleCount();
405 SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i )
407 return mpImpl->GetStyle( i );
410 const SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i ) const
412 return mpImpl->GetStyle( i );
415 sal_Bool SvXMLStylesContext::IsAutomaticStyle() const
417 return mpImpl->IsAutomaticStyle();
420 SvXMLStyleContext *SvXMLStylesContext::CreateStyleChildContext(
421 sal_uInt16 p_nPrefix,
422 const OUString& rLocalName,
423 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
425 SvXMLStyleContext *pStyle = NULL;
427 if(GetImport().GetDataStylesImport())
429 pStyle = GetImport().GetDataStylesImport()->CreateChildContext(GetImport(), p_nPrefix,
430 rLocalName, xAttrList, *this);
433 if (!pStyle)
435 const SvXMLTokenMap& rTokenMap = GetStyleStylesElemTokenMap();
436 sal_uInt16 nToken = rTokenMap.Get( p_nPrefix, rLocalName );
437 switch( nToken )
439 case XML_TOK_STYLE_STYLE:
440 case XML_TOK_STYLE_DEFAULT_STYLE:
442 sal_uInt16 nFamily = 0;
443 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
444 for( sal_Int16 i=0; i < nAttrCount; i++ )
446 const OUString& rAttrName = xAttrList->getNameByIndex( i );
447 OUString aLocalName;
448 sal_uInt16 nPrefix =
449 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
450 &aLocalName );
451 if( XML_NAMESPACE_STYLE == nPrefix &&
452 IsXMLToken( aLocalName, XML_FAMILY ) )
454 const OUString& rValue = xAttrList->getValueByIndex( i );
455 nFamily = GetFamily( rValue );
456 break;
459 pStyle = XML_TOK_STYLE_STYLE==nToken
460 ? CreateStyleStyleChildContext( nFamily, p_nPrefix,
461 rLocalName, xAttrList )
462 : CreateDefaultStyleStyleChildContext( nFamily, p_nPrefix,
463 rLocalName, xAttrList );
465 break;
466 case XML_TOK_STYLE_PAGE_MASTER:
467 case XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT:
469 //there is not page family in odf now, so I specify one for it
470 sal_Bool bDefaultStyle = XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT == nToken
471 ? sal_True: sal_False;
472 pStyle = new PageStyleContext( GetImport(), p_nPrefix,
473 rLocalName, xAttrList, *this, bDefaultStyle );
475 break;
476 case XML_TOK_TEXT_LIST_STYLE:
477 pStyle = new SvxXMLListStyleContext( GetImport(), p_nPrefix,
478 rLocalName, xAttrList );
479 break;
480 case XML_TOK_TEXT_OUTLINE:
481 pStyle = new SvxXMLListStyleContext( GetImport(), p_nPrefix,
482 rLocalName, xAttrList, sal_True );
483 break;
484 case XML_TOK_TEXT_NOTE_CONFIG:
485 pStyle = new XMLFootnoteConfigurationImportContext(GetImport(),
486 p_nPrefix,
487 rLocalName,
488 xAttrList);
489 break;
491 case XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG:
492 pStyle = new XMLIndexBibliographyConfigurationContext(
493 GetImport(), p_nPrefix, rLocalName, xAttrList);
494 break;
496 case XML_TOK_TEXT_LINENUMBERING_CONFIG:
497 pStyle = new XMLLineNumberingImportContext(
498 GetImport(), p_nPrefix, rLocalName, xAttrList);
499 break;
502 // FillStyles
504 case XML_TOK_STYLES_GRADIENTSTYLES:
506 pStyle = new XMLGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
507 break;
509 case XML_TOK_STYLES_HATCHSTYLES:
511 pStyle = new XMLHatchStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
512 break;
514 case XML_TOK_STYLES_BITMAPSTYLES:
516 pStyle = new XMLBitmapStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
517 break;
519 case XML_TOK_STYLES_TRANSGRADIENTSTYLES:
521 pStyle = new XMLTransGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
522 break;
524 case XML_TOK_STYLES_MARKERSTYLES:
526 pStyle = new XMLMarkerStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
527 break;
529 case XML_TOK_STYLES_DASHSTYLES:
531 pStyle = new XMLDashStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
532 break;
537 return pStyle;
540 SvXMLStyleContext *SvXMLStylesContext::CreateStyleStyleChildContext(
541 sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
542 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
544 SvXMLStyleContext *pStyle = 0;
546 switch( nFamily )
548 case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
549 case XML_STYLE_FAMILY_TEXT_TEXT:
550 case XML_STYLE_FAMILY_TEXT_SECTION:
551 pStyle = new XMLTextStyleContext( GetImport(), nPrefix, rLocalName,
552 xAttrList, *this, nFamily );
553 break;
555 case XML_STYLE_FAMILY_TEXT_RUBY:
556 pStyle = new XMLPropStyleContext( GetImport(), nPrefix, rLocalName,
557 xAttrList, *this, nFamily );
558 break;
559 case XML_STYLE_FAMILY_SCH_CHART_ID:
560 pStyle = new XMLChartStyleContext( GetImport(), nPrefix, rLocalName,
561 xAttrList, *this, nFamily );
562 break;
564 case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
565 case XML_STYLE_FAMILY_SD_PRESENTATION_ID:
566 case XML_STYLE_FAMILY_SD_POOL_ID:
567 pStyle = new XMLShapeStyleContext( GetImport(), nPrefix, rLocalName,
568 xAttrList, *this, nFamily );
571 return pStyle;
574 SvXMLStyleContext *SvXMLStylesContext::CreateDefaultStyleStyleChildContext(
575 sal_uInt16 /*nFamily*/, sal_uInt16 /*nPrefix*/, const OUString& /*rLocalName*/,
576 const uno::Reference< xml::sax::XAttributeList > & )
578 return 0;
582 sal_Bool SvXMLStylesContext::InsertStyleFamily( sal_uInt16 ) const
584 return sal_True;
587 sal_uInt16 SvXMLStylesContext::GetFamily(
588 const ::rtl::OUString& rValue ) const
590 sal_uInt16 nFamily = 0U;
591 if( IsXMLToken( rValue, XML_PARAGRAPH ) )
593 nFamily = XML_STYLE_FAMILY_TEXT_PARAGRAPH;
595 else if( IsXMLToken( rValue, XML_TEXT ) )
597 nFamily = XML_STYLE_FAMILY_TEXT_TEXT;
599 else if( IsXMLToken( rValue, XML_DATA_STYLE ) )
601 nFamily = XML_STYLE_FAMILY_DATA_STYLE;
603 else if ( IsXMLToken( rValue, XML_SECTION ) )
605 nFamily = XML_STYLE_FAMILY_TEXT_SECTION;
607 else if( IsXMLToken( rValue, XML_TABLE ) )
609 nFamily = XML_STYLE_FAMILY_TABLE_TABLE;
611 else if( IsXMLToken( rValue, XML_TABLE_COLUMN ) )
612 nFamily = XML_STYLE_FAMILY_TABLE_COLUMN;
613 else if( IsXMLToken( rValue, XML_TABLE_ROW ) )
614 nFamily = XML_STYLE_FAMILY_TABLE_ROW;
615 else if( IsXMLToken( rValue, XML_TABLE_CELL ) )
616 nFamily = XML_STYLE_FAMILY_TABLE_CELL;
617 else if ( rValue == XML_STYLE_FAMILY_SD_GRAPHICS_NAME )
619 nFamily = XML_STYLE_FAMILY_SD_GRAPHICS_ID;
621 else if ( rValue == XML_STYLE_FAMILY_SD_PRESENTATION_NAME )
623 nFamily = XML_STYLE_FAMILY_SD_PRESENTATION_ID;
625 else if ( rValue == XML_STYLE_FAMILY_SD_POOL_NAME )
627 nFamily = XML_STYLE_FAMILY_SD_POOL_ID;
629 else if ( rValue == XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME )
631 nFamily = XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID;
633 else if ( rValue == XML_STYLE_FAMILY_SCH_CHART_NAME )
635 nFamily = XML_STYLE_FAMILY_SCH_CHART_ID;
637 else if ( IsXMLToken( rValue, XML_RUBY ) )
639 nFamily = XML_STYLE_FAMILY_TEXT_RUBY;
642 return nFamily;
645 UniReference < SvXMLImportPropertyMapper > SvXMLStylesContext::GetImportPropertyMapper(
646 sal_uInt16 nFamily ) const
648 UniReference < SvXMLImportPropertyMapper > xMapper;
650 switch( nFamily )
652 case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
653 if( !mxParaImpPropMapper.is() )
655 SvXMLStylesContext * pThis = (SvXMLStylesContext *)this;
656 pThis->mxParaImpPropMapper =
657 pThis->GetImport().GetTextImport()
658 ->GetParaImportPropertySetMapper();
660 xMapper = mxParaImpPropMapper;
661 break;
662 case XML_STYLE_FAMILY_TEXT_TEXT:
663 if( !mxTextImpPropMapper.is() )
665 SvXMLStylesContext * pThis = (SvXMLStylesContext *)this;
666 pThis->mxTextImpPropMapper =
667 pThis->GetImport().GetTextImport()
668 ->GetTextImportPropertySetMapper();
670 xMapper = mxTextImpPropMapper;
671 break;
673 case XML_STYLE_FAMILY_TEXT_SECTION:
674 // don't cache section mapper, as it's rarely used
675 // *sigh*, cast to non-const, because this is a const method,
676 // but SvXMLImport::GetTextImport() isn't.
677 xMapper = ((SvXMLStylesContext*)this)->GetImport().GetTextImport()->
678 GetSectionImportPropertySetMapper();
679 break;
681 case XML_STYLE_FAMILY_TEXT_RUBY:
682 // don't cache section mapper, as it's rarely used
683 // *sigh*, cast to non-const, because this is a const method,
684 // but SvXMLImport::GetTextImport() isn't.
685 xMapper = ((SvXMLStylesContext*)this)->GetImport().GetTextImport()->
686 GetRubyImportPropertySetMapper();
687 break;
689 case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
690 case XML_STYLE_FAMILY_SD_PRESENTATION_ID:
691 case XML_STYLE_FAMILY_SD_POOL_ID:
692 if(!mxShapeImpPropMapper.is())
694 UniReference< XMLShapeImportHelper > aImpHelper = ((SvXMLImport&)GetImport()).GetShapeImport();
695 ((SvXMLStylesContext*)this)->mxShapeImpPropMapper =
696 aImpHelper->GetPropertySetMapper();
698 xMapper = mxShapeImpPropMapper;
699 break;
700 case XML_STYLE_FAMILY_SCH_CHART_ID:
701 if( ! mxChartImpPropMapper.is() )
703 XMLPropertySetMapper *pPropMapper = new XMLChartPropertySetMapper();
704 mxChartImpPropMapper = new XMLChartImportPropertyMapper( pPropMapper, GetImport() );
706 xMapper = mxChartImpPropMapper;
707 break;
708 case XML_STYLE_FAMILY_PAGE_MASTER:
709 if( ! mxPageImpPropMapper.is() )
711 XMLPropertySetMapper *pPropMapper =
712 new XMLPageMasterPropSetMapper();
713 mxPageImpPropMapper =
714 new PageMasterImportPropertyMapper( pPropMapper,
715 ((SvXMLStylesContext*)this)->GetImport() );
717 xMapper = mxPageImpPropMapper;
718 break;
721 return xMapper;
724 Reference < XAutoStyleFamily > SvXMLStylesContext::GetAutoStyles( sal_uInt16 nFamily ) const
726 Reference < XAutoStyleFamily > xAutoStyles;
727 if( XML_STYLE_FAMILY_TEXT_TEXT == nFamily || XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily)
729 bool bPara = XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily;
730 OUString sName;
731 if( !bPara && mxTextAutoStyles.is() )
732 xAutoStyles = mxTextAutoStyles;
733 else if( bPara && mxParaAutoStyles.is() )
734 xAutoStyles = mxParaAutoStyles;
735 else
737 sName = bPara ?
738 OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphStyles" ) ):
739 OUString( RTL_CONSTASCII_USTRINGPARAM( "CharacterStyles" ) );
740 Reference< XAutoStylesSupplier > xAutoStylesSupp( GetImport().GetModel(), UNO_QUERY );
741 Reference< XAutoStyles > xAutoStyleFamilies = xAutoStylesSupp->getAutoStyles();
742 if (xAutoStyleFamilies->hasByName(sName))
744 Any aAny = xAutoStyleFamilies->getByName( sName );
745 xAutoStyles = *(Reference<XAutoStyleFamily>*)aAny.getValue();
746 if( bPara )
747 ((SvXMLStylesContext *)this)->mxParaAutoStyles = xAutoStyles;
748 else
749 ((SvXMLStylesContext *)this)->mxTextAutoStyles = xAutoStyles;
753 return xAutoStyles;
756 Reference < XNameContainer > SvXMLStylesContext::GetStylesContainer(
757 sal_uInt16 nFamily ) const
759 Reference < XNameContainer > xStyles;
760 OUString sName;
761 switch( nFamily )
763 case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
764 if( mxParaStyles.is() )
765 xStyles = mxParaStyles;
766 else
767 sName =
768 OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphStyles" ) );
769 break;
771 case XML_STYLE_FAMILY_TEXT_TEXT:
772 if( mxTextStyles.is() )
773 xStyles = mxTextStyles;
774 else
775 sName =
776 OUString( RTL_CONSTASCII_USTRINGPARAM( "CharacterStyles" ) );
777 break;
779 if( !xStyles.is() && !sName.isEmpty() )
781 Reference< XStyleFamiliesSupplier > xFamiliesSupp(
782 GetImport().GetModel(), UNO_QUERY );
783 if ( xFamiliesSupp.is() )
785 Reference< XNameAccess > xFamilies = xFamiliesSupp->getStyleFamilies();
786 if (xFamilies->hasByName(sName))
788 xStyles.set(xFamilies->getByName( sName ),uno::UNO_QUERY);
790 switch( nFamily )
792 case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
793 ((SvXMLStylesContext *)this)->mxParaStyles = xStyles;
794 break;
796 case XML_STYLE_FAMILY_TEXT_TEXT:
797 ((SvXMLStylesContext *)this)->mxTextStyles = xStyles;
798 break;
804 return xStyles;
807 OUString SvXMLStylesContext::GetServiceName( sal_uInt16 nFamily ) const
809 String sServiceName;
810 switch( nFamily )
812 case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
813 sServiceName = msParaStyleServiceName;
814 break;
815 case XML_STYLE_FAMILY_TEXT_TEXT:
816 sServiceName = msTextStyleServiceName;
817 break;
820 return sServiceName;
824 SvXMLStylesContext::SvXMLStylesContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
825 const OUString& rLName,
826 const uno::Reference< xml::sax::XAttributeList > &, sal_Bool bAuto ) :
827 SvXMLImportContext( rImport, nPrfx, rLName ),
828 msParaStyleServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.ParagraphStyle" ) ),
829 msTextStyleServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.style.CharacterStyle" ) ),
830 mpImpl( new SvXMLStylesContext_Impl( bAuto ) ),
831 mpStyleStylesElemTokenMap( 0 )
836 SvXMLStylesContext::~SvXMLStylesContext()
838 delete mpStyleStylesElemTokenMap;
839 delete mpImpl;
842 SvXMLImportContext *SvXMLStylesContext::CreateChildContext( sal_uInt16 nPrefix,
843 const OUString& rLocalName,
844 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
846 SvXMLImportContext *pContext = 0;
848 SvXMLStyleContext *pStyle =
849 CreateStyleChildContext( nPrefix, rLocalName, xAttrList );
850 if( pStyle )
852 if( !pStyle->IsTransient() )
853 mpImpl->AddStyle( pStyle );
854 pContext = pStyle;
856 else
858 pContext = new SvXMLImportContext( GetImport(), nPrefix,
859 rLocalName );
862 return pContext;
865 void SvXMLStylesContext::EndElement()
869 void SvXMLStylesContext::AddStyle(SvXMLStyleContext& rNew)
871 mpImpl->AddStyle( &rNew );
874 void SvXMLStylesContext::Clear()
876 mpImpl->Clear();
879 void SvXMLStylesContext::CopyAutoStylesToDoc()
881 sal_uInt32 nCount = GetStyleCount();
882 sal_uInt32 i;
883 for( i = 0; i < nCount; i++ )
885 SvXMLStyleContext *pStyle = GetStyle( i );
886 if( !pStyle || ( pStyle->GetFamily() != XML_STYLE_FAMILY_TEXT_TEXT &&
887 pStyle->GetFamily() != XML_STYLE_FAMILY_TEXT_PARAGRAPH &&
888 pStyle->GetFamily() != XML_STYLE_FAMILY_TABLE_CELL ) )
889 continue;
890 pStyle->CreateAndInsert( sal_False );
894 void SvXMLStylesContext::CopyStylesToDoc( sal_Bool bOverwrite,
895 sal_Bool bFinish )
897 // pass 1: create text, paragraph and frame styles
898 sal_uInt32 nCount = GetStyleCount();
899 sal_uInt32 i;
901 for( i = 0; i < nCount; i++ )
903 SvXMLStyleContext *pStyle = GetStyle( i );
904 if( !pStyle )
905 continue;
907 if (pStyle->IsDefaultStyle())
908 pStyle->SetDefaults();
909 else if( InsertStyleFamily( pStyle->GetFamily() ) )
910 pStyle->CreateAndInsert( bOverwrite );
913 // pass 2: create list styles (they require char styles)
914 for( i=0; i<nCount; i++ )
916 SvXMLStyleContext *pStyle = GetStyle( i );
917 if( !pStyle || pStyle->IsDefaultStyle())
918 continue;
920 if( InsertStyleFamily( pStyle->GetFamily() ) )
921 pStyle->CreateAndInsertLate( bOverwrite );
924 // pass3: finish creation of styles
925 if( bFinish )
926 FinishStyles( bOverwrite );
929 void SvXMLStylesContext::FinishStyles( sal_Bool bOverwrite )
931 sal_uInt32 nCount = GetStyleCount();
932 for( sal_uInt32 i=0; i<nCount; i++ )
934 SvXMLStyleContext *pStyle = GetStyle( i );
935 if( !pStyle || !pStyle->IsValid() || pStyle->IsDefaultStyle() )
936 continue;
938 if( InsertStyleFamily( pStyle->GetFamily() ) )
939 pStyle->Finish( bOverwrite );
944 const SvXMLStyleContext *SvXMLStylesContext::FindStyleChildContext(
945 sal_uInt16 nFamily,
946 const OUString& rName,
947 sal_Bool bCreateIndex ) const
949 return mpImpl->FindStyleChildContext( nFamily, rName, bCreateIndex );
952 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */