bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / style / xmlstyle.cxx
blob7ca0b206409af78513daa7f1596bfbfe94ca7e13
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/xml/sax/SAXParseException.hpp>
21 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
22 #include <com/sun/star/xml/sax/SAXException.hpp>
23 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
24 #include <com/sun/star/xml/sax/XAttributeList.hpp>
25 #include <com/sun/star/xml/sax/XLocator.hpp>
26 #include <com/sun/star/container/XNameContainer.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
29 #include <com/sun/star/style/XAutoStylesSupplier.hpp>
30 #include <com/sun/star/style/XAutoStyleFamily.hpp>
31 #include "PageMasterPropMapper.hxx"
32 #include <tools/debug.hxx>
33 #include <svl/itemset.hxx>
34 #include <xmloff/nmspmap.hxx>
35 #include "xmloff/xmlnmspe.hxx"
36 #include <xmloff/xmltoken.hxx>
38 #include <xmloff/families.hxx>
39 #include <xmloff/xmlimp.hxx>
40 #include <xmloff/xmlnumi.hxx>
41 #include <xmloff/xmlimppr.hxx>
42 #include <xmloff/xmlstyle.hxx>
43 #include <xmloff/txtstyli.hxx>
44 #include <xmloff/txtprmap.hxx>
45 #include <xmloff/xmlnumfi.hxx>
46 #include "XMLChartStyleContext.hxx"
47 #include "XMLChartPropertySetMapper.hxx"
48 #include <xmloff/XMLShapeStyleContext.hxx>
49 #include "FillStyleContext.hxx"
50 #include "XMLFootnoteConfigurationImportContext.hxx"
51 #include "XMLIndexBibliographyConfigurationContext.hxx"
52 #include "XMLLineNumberingImportContext.hxx"
53 #include "PageMasterImportContext.hxx"
54 #include "PageMasterImportPropMapper.hxx"
56 #include <set>
57 #include <vector>
59 using namespace ::com::sun::star;
60 using namespace ::com::sun::star::uno;
61 using namespace ::com::sun::star::container;
62 using namespace ::com::sun::star::style;
63 using namespace ::xmloff::token;
65 // ---------------------------------------------------------------------
67 static SvXMLTokenMapEntry aStyleStylesElemTokenMap[] =
69 { XML_NAMESPACE_STYLE, XML_STYLE, XML_TOK_STYLE_STYLE },
70 { XML_NAMESPACE_STYLE, XML_PAGE_LAYOUT, XML_TOK_STYLE_PAGE_MASTER },
71 { XML_NAMESPACE_TEXT, XML_LIST_STYLE, XML_TOK_TEXT_LIST_STYLE },
72 { XML_NAMESPACE_TEXT, XML_OUTLINE_STYLE, XML_TOK_TEXT_OUTLINE },
73 { XML_NAMESPACE_STYLE, XML_DEFAULT_STYLE, XML_TOK_STYLE_DEFAULT_STYLE },
74 { XML_NAMESPACE_DRAW, XML_GRADIENT, XML_TOK_STYLES_GRADIENTSTYLES },
75 { XML_NAMESPACE_DRAW, XML_HATCH, XML_TOK_STYLES_HATCHSTYLES },
76 { XML_NAMESPACE_DRAW, XML_FILL_IMAGE, XML_TOK_STYLES_BITMAPSTYLES },
77 { XML_NAMESPACE_DRAW, XML_OPACITY, XML_TOK_STYLES_TRANSGRADIENTSTYLES },
78 { XML_NAMESPACE_DRAW, XML_MARKER, XML_TOK_STYLES_MARKERSTYLES },
79 { XML_NAMESPACE_DRAW, XML_STROKE_DASH, XML_TOK_STYLES_DASHSTYLES },
80 { XML_NAMESPACE_TEXT, XML_NOTES_CONFIGURATION, XML_TOK_TEXT_NOTE_CONFIG },
81 { XML_NAMESPACE_TEXT, XML_BIBLIOGRAPHY_CONFIGURATION, XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG },
82 { XML_NAMESPACE_TEXT, XML_LINENUMBERING_CONFIGURATION,XML_TOK_TEXT_LINENUMBERING_CONFIG },
83 { XML_NAMESPACE_STYLE, XML_DEFAULT_PAGE_LAYOUT, XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT },
84 XML_TOKEN_MAP_END
87 const SvXMLTokenMap& SvXMLStylesContext::GetStyleStylesElemTokenMap()
89 if( !mpStyleStylesElemTokenMap )
90 mpStyleStylesElemTokenMap =
91 new SvXMLTokenMap( aStyleStylesElemTokenMap );
93 return *mpStyleStylesElemTokenMap;
96 // ---------------------------------------------------------------------
98 void SvXMLStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
99 const OUString& rLocalName,
100 const OUString& rValue )
102 // TODO: use a map here
103 if( XML_NAMESPACE_STYLE == nPrefixKey )
105 if( IsXMLToken( rLocalName, XML_FAMILY ) )
107 if( IsXMLToken( rValue, XML_PARAGRAPH ) )
108 mnFamily = (sal_uInt16)SFX_STYLE_FAMILY_PARA;
109 else if( IsXMLToken( rValue, XML_TEXT ) )
110 mnFamily = (sal_uInt16)SFX_STYLE_FAMILY_CHAR;
112 else if( IsXMLToken( rLocalName, XML_NAME ) )
114 maName = rValue;
116 else if( IsXMLToken( rLocalName, XML_DISPLAY_NAME ) )
118 maDisplayName = rValue;
120 else if( IsXMLToken( rLocalName, XML_PARENT_STYLE_NAME ) )
122 maParentName = rValue;
124 else if( IsXMLToken( rLocalName, XML_NEXT_STYLE_NAME ) )
126 maFollow = rValue;
128 else if( IsXMLToken( rLocalName, XML_HELP_FILE_NAME ) )
130 maHelpFile = rValue;
132 else if( IsXMLToken( rLocalName, XML_HELP_ID ) )
134 sal_Int32 nTmp = rValue.toInt32();
135 mnHelpId =
136 (nTmp < 0L) ? 0U : ( (nTmp > USHRT_MAX) ? USHRT_MAX
137 : (sal_uInt16)nTmp );
139 else if( IsXMLToken( rLocalName, XML_HIDDEN ) )
141 mbHidden = rValue.toBoolean();
146 TYPEINIT1( SvXMLStyleContext, SvXMLImportContext );
148 SvXMLStyleContext::SvXMLStyleContext(
149 SvXMLImport& rImp, sal_uInt16 nPrfx,
150 const OUString& rLName,
151 const uno::Reference< xml::sax::XAttributeList >&,
152 sal_uInt16 nFam, sal_Bool bDefault ) :
153 SvXMLImportContext( rImp, nPrfx, rLName ),
154 mbHidden( sal_False ),
155 mnHelpId( UCHAR_MAX ),
156 mnFamily( nFam ),
157 mbValid( sal_True ),
158 mbNew( sal_True ),
159 mbDefaultStyle( bDefault )
163 SvXMLStyleContext::~SvXMLStyleContext()
167 SvXMLImportContext *SvXMLStyleContext::CreateChildContext( sal_uInt16 nPrefix,
168 const OUString& rLocalName,
169 const uno::Reference< xml::sax::XAttributeList > & )
171 return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
174 void SvXMLStyleContext::StartElement( const uno::Reference< xml::sax::XAttributeList > & xAttrList )
176 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
177 for( sal_Int16 i=0; i < nAttrCount; i++ )
179 const OUString& rAttrName = xAttrList->getNameByIndex( i );
180 OUString aLocalName;
181 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
182 const OUString& rValue = xAttrList->getValueByIndex( i );
184 SetAttribute( nPrefix, aLocalName, rValue );
188 void SvXMLStyleContext::SetDefaults()
192 void SvXMLStyleContext::CreateAndInsert( sal_Bool /*bOverwrite*/ )
196 void SvXMLStyleContext::CreateAndInsertLate( sal_Bool /*bOverwrite*/ )
200 void SvXMLStyleContext::Finish( sal_Bool /*bOverwrite*/ )
204 sal_Bool SvXMLStyleContext::IsTransient() const
206 return sal_False;
209 // ---------------------------------------------------------------------
211 class SvXMLStyleIndex_Impl
213 OUString sName;
214 sal_uInt16 nFamily;
215 const SvXMLStyleContext *pStyle;
217 public:
219 SvXMLStyleIndex_Impl( sal_uInt16 nFam, const OUString& rName ) :
220 sName( rName ),
221 nFamily( nFam ),
222 pStyle ( 0 )
226 SvXMLStyleIndex_Impl( const SvXMLStyleContext *pStl ) :
227 sName( pStl->GetName() ),
228 nFamily( pStl->GetFamily() ),
229 pStyle ( pStl )
233 const OUString& GetName() const { return sName; }
234 sal_uInt16 GetFamily() const { return nFamily; }
235 const SvXMLStyleContext *GetStyle() const { return pStyle; }
238 struct SvXMLStyleIndexCmp_Impl
240 bool operator()(const SvXMLStyleIndex_Impl& r1, const SvXMLStyleIndex_Impl& r2) const
242 sal_Int32 nRet;
244 if( (sal_uInt16)r1.GetFamily() < (sal_uInt16)r2.GetFamily() )
245 nRet = -1;
246 else if( (sal_uInt16)r1.GetFamily() > (sal_uInt16)r2.GetFamily() )
247 nRet = 1;
248 else
249 nRet = r1.GetName().compareTo( r2.GetName() );
251 return nRet < 0;
256 class SvXMLStylesContext_Impl
258 typedef std::vector<SvXMLStyleContext*> StylesType;
259 typedef std::set<SvXMLStyleIndex_Impl, SvXMLStyleIndexCmp_Impl> IndicesType;
261 StylesType aStyles;
262 mutable IndicesType* pIndices;
263 bool bAutomaticStyle;
265 #ifdef DBG_UTIL
266 mutable sal_uInt32 nIndexCreated;
267 #endif
269 void FlushIndex() { delete pIndices; pIndices = 0; }
271 public:
272 SvXMLStylesContext_Impl( bool bAuto );
273 ~SvXMLStylesContext_Impl();
275 size_t GetStyleCount() const { return aStyles.size(); }
277 const SvXMLStyleContext *GetStyle( size_t i ) const
279 return i < aStyles.size() ? aStyles[ i ] : 0;
282 SvXMLStyleContext *GetStyle( size_t i )
284 return i < aStyles.size() ? aStyles[ i ] : 0;
287 inline void AddStyle( SvXMLStyleContext *pStyle );
288 void Clear();
290 const SvXMLStyleContext *FindStyleChildContext( sal_uInt16 nFamily,
291 const OUString& rName,
292 sal_Bool bCreateIndex ) const;
293 sal_Bool IsAutomaticStyle() const { return bAutomaticStyle; }
296 SvXMLStylesContext_Impl::SvXMLStylesContext_Impl( bool bAuto ) :
297 pIndices( 0 ),
298 bAutomaticStyle( bAuto )
299 #ifdef DBG_UTIL
300 , nIndexCreated( 0 )
301 #endif
304 SvXMLStylesContext_Impl::~SvXMLStylesContext_Impl()
306 delete pIndices;
308 for ( size_t i = 0, n = aStyles.size(); i < n; ++i )
310 SvXMLStyleContext *pStyle = aStyles[ i ];
311 pStyle->ReleaseRef();
313 aStyles.clear();
316 inline void SvXMLStylesContext_Impl::AddStyle( SvXMLStyleContext *pStyle )
318 aStyles.push_back( pStyle );
319 pStyle->AddRef();
321 FlushIndex();
324 void SvXMLStylesContext_Impl::Clear()
326 FlushIndex();
328 for ( size_t i = 0, n = aStyles.size(); i < n; ++i )
330 SvXMLStyleContext *pStyle = aStyles[ i ];
331 pStyle->ReleaseRef();
333 aStyles.clear();
336 const SvXMLStyleContext *SvXMLStylesContext_Impl::FindStyleChildContext( sal_uInt16 nFamily,
337 const OUString& rName,
338 sal_Bool bCreateIndex ) const
340 const SvXMLStyleContext *pStyle = 0;
342 if( !pIndices && bCreateIndex && !aStyles.empty() )
344 #ifdef DBG_UTIL
345 DBG_ASSERT( 0==nIndexCreated,
346 "Performance warning: sdbcx::Index created multiple times" );
347 #endif
348 pIndices = new IndicesType(aStyles.begin(), aStyles.end());
349 SAL_WARN_IF(pIndices->size() != aStyles.size(), "xmloff", "Here is a duplicate Style");
350 #ifdef DBG_UTIL
351 ++nIndexCreated;
352 #endif
355 if( pIndices )
357 SvXMLStyleIndex_Impl aIndex( nFamily, rName );
358 IndicesType::iterator aFind = pIndices->find(aIndex);
359 if( aFind != pIndices->end() )
360 pStyle = aFind->GetStyle();
362 else
364 for( size_t i = 0; !pStyle && i < aStyles.size(); i++ )
366 const SvXMLStyleContext *pS = aStyles[ i ];
367 if( pS->GetFamily() == nFamily &&
368 pS->GetName() == rName )
369 pStyle = pS;
372 return pStyle;
375 // ---------------------------------------------------------------------
377 TYPEINIT1( SvXMLStylesContext, SvXMLImportContext );
379 sal_uInt32 SvXMLStylesContext::GetStyleCount() const
381 return mpImpl->GetStyleCount();
384 SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i )
386 return mpImpl->GetStyle( i );
389 const SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i ) const
391 return mpImpl->GetStyle( i );
394 sal_Bool SvXMLStylesContext::IsAutomaticStyle() const
396 return mpImpl->IsAutomaticStyle();
399 SvXMLStyleContext *SvXMLStylesContext::CreateStyleChildContext( sal_uInt16 p_nPrefix,
400 const OUString& rLocalName,
401 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
403 SvXMLStyleContext *pStyle = NULL;
405 if(GetImport().GetDataStylesImport())
407 pStyle = GetImport().GetDataStylesImport()->CreateChildContext(GetImport(), p_nPrefix,
408 rLocalName, xAttrList, *this);
411 if (!pStyle)
413 const SvXMLTokenMap& rTokenMap = GetStyleStylesElemTokenMap();
414 sal_uInt16 nToken = rTokenMap.Get( p_nPrefix, rLocalName );
415 switch( nToken )
417 case XML_TOK_STYLE_STYLE:
418 case XML_TOK_STYLE_DEFAULT_STYLE:
420 sal_uInt16 nFamily = 0;
421 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
422 for( sal_Int16 i=0; i < nAttrCount; i++ )
424 const OUString& rAttrName = xAttrList->getNameByIndex( i );
425 OUString aLocalName;
426 sal_uInt16 nPrefix =
427 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
428 &aLocalName );
429 if( XML_NAMESPACE_STYLE == nPrefix &&
430 IsXMLToken( aLocalName, XML_FAMILY ) )
432 const OUString& rValue = xAttrList->getValueByIndex( i );
433 nFamily = GetFamily( rValue );
434 break;
437 pStyle = XML_TOK_STYLE_STYLE==nToken
438 ? CreateStyleStyleChildContext( nFamily, p_nPrefix,
439 rLocalName, xAttrList )
440 : CreateDefaultStyleStyleChildContext( nFamily, p_nPrefix,
441 rLocalName, xAttrList );
443 break;
444 case XML_TOK_STYLE_PAGE_MASTER:
445 case XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT:
447 //there is not page family in ODF now, so I specify one for it
448 sal_Bool bDefaultStyle = XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT == nToken
449 ? sal_True: sal_False;
450 pStyle = new PageStyleContext( GetImport(), p_nPrefix,
451 rLocalName, xAttrList, *this, bDefaultStyle );
453 break;
454 case XML_TOK_TEXT_LIST_STYLE:
455 pStyle = new SvxXMLListStyleContext( GetImport(), p_nPrefix,
456 rLocalName, xAttrList );
457 break;
458 case XML_TOK_TEXT_OUTLINE:
459 pStyle = new SvxXMLListStyleContext( GetImport(), p_nPrefix,
460 rLocalName, xAttrList, sal_True );
461 break;
462 case XML_TOK_TEXT_NOTE_CONFIG:
463 pStyle = new XMLFootnoteConfigurationImportContext(GetImport(),
464 p_nPrefix,
465 rLocalName,
466 xAttrList);
467 break;
469 case XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG:
470 pStyle = new XMLIndexBibliographyConfigurationContext(
471 GetImport(), p_nPrefix, rLocalName, xAttrList);
472 break;
474 case XML_TOK_TEXT_LINENUMBERING_CONFIG:
475 pStyle = new XMLLineNumberingImportContext(
476 GetImport(), p_nPrefix, rLocalName, xAttrList);
477 break;
480 // FillStyles
482 case XML_TOK_STYLES_GRADIENTSTYLES:
484 pStyle = new XMLGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
485 break;
487 case XML_TOK_STYLES_HATCHSTYLES:
489 pStyle = new XMLHatchStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
490 break;
492 case XML_TOK_STYLES_BITMAPSTYLES:
494 pStyle = new XMLBitmapStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
495 break;
497 case XML_TOK_STYLES_TRANSGRADIENTSTYLES:
499 pStyle = new XMLTransGradientStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
500 break;
502 case XML_TOK_STYLES_MARKERSTYLES:
504 pStyle = new XMLMarkerStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
505 break;
507 case XML_TOK_STYLES_DASHSTYLES:
509 pStyle = new XMLDashStyleContext( GetImport(), p_nPrefix, rLocalName, xAttrList );
510 break;
515 return pStyle;
518 SvXMLStyleContext *SvXMLStylesContext::CreateStyleStyleChildContext(
519 sal_uInt16 nFamily, sal_uInt16 nPrefix, const OUString& rLocalName,
520 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
522 SvXMLStyleContext *pStyle = 0;
524 switch( nFamily )
526 case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
527 case XML_STYLE_FAMILY_TEXT_TEXT:
528 case XML_STYLE_FAMILY_TEXT_SECTION:
529 pStyle = new XMLTextStyleContext( GetImport(), nPrefix, rLocalName,
530 xAttrList, *this, nFamily );
531 break;
533 case XML_STYLE_FAMILY_TEXT_RUBY:
534 pStyle = new XMLPropStyleContext( GetImport(), nPrefix, rLocalName,
535 xAttrList, *this, nFamily );
536 break;
537 case XML_STYLE_FAMILY_SCH_CHART_ID:
538 pStyle = new XMLChartStyleContext( GetImport(), nPrefix, rLocalName,
539 xAttrList, *this, nFamily );
540 break;
542 case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
543 case XML_STYLE_FAMILY_SD_PRESENTATION_ID:
544 case XML_STYLE_FAMILY_SD_POOL_ID:
545 pStyle = new XMLShapeStyleContext( GetImport(), nPrefix, rLocalName,
546 xAttrList, *this, nFamily );
549 return pStyle;
552 SvXMLStyleContext *SvXMLStylesContext::CreateDefaultStyleStyleChildContext(
553 sal_uInt16 /*nFamily*/, sal_uInt16 /*nPrefix*/, const OUString& /*rLocalName*/,
554 const uno::Reference< xml::sax::XAttributeList > & )
556 return 0;
560 sal_Bool SvXMLStylesContext::InsertStyleFamily( sal_uInt16 ) const
562 return sal_True;
565 sal_uInt16 SvXMLStylesContext::GetFamily( const OUString& rValue ) const
567 sal_uInt16 nFamily = 0U;
568 if( IsXMLToken( rValue, XML_PARAGRAPH ) )
570 nFamily = XML_STYLE_FAMILY_TEXT_PARAGRAPH;
572 else if( IsXMLToken( rValue, XML_TEXT ) )
574 nFamily = XML_STYLE_FAMILY_TEXT_TEXT;
576 else if( IsXMLToken( rValue, XML_DATA_STYLE ) )
578 nFamily = XML_STYLE_FAMILY_DATA_STYLE;
580 else if ( IsXMLToken( rValue, XML_SECTION ) )
582 nFamily = XML_STYLE_FAMILY_TEXT_SECTION;
584 else if( IsXMLToken( rValue, XML_TABLE ) )
586 nFamily = XML_STYLE_FAMILY_TABLE_TABLE;
588 else if( IsXMLToken( rValue, XML_TABLE_COLUMN ) )
589 nFamily = XML_STYLE_FAMILY_TABLE_COLUMN;
590 else if( IsXMLToken( rValue, XML_TABLE_ROW ) )
591 nFamily = XML_STYLE_FAMILY_TABLE_ROW;
592 else if( IsXMLToken( rValue, XML_TABLE_CELL ) )
593 nFamily = XML_STYLE_FAMILY_TABLE_CELL;
594 else if ( rValue == XML_STYLE_FAMILY_SD_GRAPHICS_NAME )
596 nFamily = XML_STYLE_FAMILY_SD_GRAPHICS_ID;
598 else if ( rValue == XML_STYLE_FAMILY_SD_PRESENTATION_NAME )
600 nFamily = XML_STYLE_FAMILY_SD_PRESENTATION_ID;
602 else if ( rValue == XML_STYLE_FAMILY_SD_POOL_NAME )
604 nFamily = XML_STYLE_FAMILY_SD_POOL_ID;
606 else if ( rValue == XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME )
608 nFamily = XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID;
610 else if ( rValue == XML_STYLE_FAMILY_SCH_CHART_NAME )
612 nFamily = XML_STYLE_FAMILY_SCH_CHART_ID;
614 else if ( IsXMLToken( rValue, XML_RUBY ) )
616 nFamily = XML_STYLE_FAMILY_TEXT_RUBY;
619 return nFamily;
622 UniReference < SvXMLImportPropertyMapper > SvXMLStylesContext::GetImportPropertyMapper(
623 sal_uInt16 nFamily ) const
625 UniReference < SvXMLImportPropertyMapper > xMapper;
627 switch( nFamily )
629 case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
630 if( !mxParaImpPropMapper.is() )
632 SvXMLStylesContext * pThis = (SvXMLStylesContext *)this;
633 pThis->mxParaImpPropMapper =
634 pThis->GetImport().GetTextImport()
635 ->GetParaImportPropertySetMapper();
637 xMapper = mxParaImpPropMapper;
638 break;
639 case XML_STYLE_FAMILY_TEXT_TEXT:
640 if( !mxTextImpPropMapper.is() )
642 SvXMLStylesContext * pThis = (SvXMLStylesContext *)this;
643 pThis->mxTextImpPropMapper =
644 pThis->GetImport().GetTextImport()
645 ->GetTextImportPropertySetMapper();
647 xMapper = mxTextImpPropMapper;
648 break;
650 case XML_STYLE_FAMILY_TEXT_SECTION:
651 // don't cache section mapper, as it's rarely used
652 // *sigh*, cast to non-const, because this is a const method,
653 // but SvXMLImport::GetTextImport() isn't.
654 xMapper = ((SvXMLStylesContext*)this)->GetImport().GetTextImport()->
655 GetSectionImportPropertySetMapper();
656 break;
658 case XML_STYLE_FAMILY_TEXT_RUBY:
659 // don't cache section mapper, as it's rarely used
660 // *sigh*, cast to non-const, because this is a const method,
661 // but SvXMLImport::GetTextImport() isn't.
662 xMapper = ((SvXMLStylesContext*)this)->GetImport().GetTextImport()->
663 GetRubyImportPropertySetMapper();
664 break;
666 case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
667 case XML_STYLE_FAMILY_SD_PRESENTATION_ID:
668 case XML_STYLE_FAMILY_SD_POOL_ID:
669 if(!mxShapeImpPropMapper.is())
671 UniReference< XMLShapeImportHelper > aImpHelper = ((SvXMLImport&)GetImport()).GetShapeImport();
672 ((SvXMLStylesContext*)this)->mxShapeImpPropMapper =
673 aImpHelper->GetPropertySetMapper();
675 xMapper = mxShapeImpPropMapper;
676 break;
677 case XML_STYLE_FAMILY_SCH_CHART_ID:
678 if( ! mxChartImpPropMapper.is() )
680 XMLPropertySetMapper *pPropMapper = new XMLChartPropertySetMapper( false );
681 mxChartImpPropMapper = new XMLChartImportPropertyMapper( pPropMapper, GetImport() );
683 xMapper = mxChartImpPropMapper;
684 break;
685 case XML_STYLE_FAMILY_PAGE_MASTER:
686 if( ! mxPageImpPropMapper.is() )
688 XMLPropertySetMapper *pPropMapper =
689 new XMLPageMasterPropSetMapper( false );
690 mxPageImpPropMapper =
691 new PageMasterImportPropertyMapper( pPropMapper,
692 ((SvXMLStylesContext*)this)->GetImport() );
694 xMapper = mxPageImpPropMapper;
695 break;
698 return xMapper;
701 Reference < XAutoStyleFamily > SvXMLStylesContext::GetAutoStyles( sal_uInt16 nFamily ) const
703 Reference < XAutoStyleFamily > xAutoStyles;
704 if( XML_STYLE_FAMILY_TEXT_TEXT == nFamily || XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily)
706 bool bPara = XML_STYLE_FAMILY_TEXT_PARAGRAPH == nFamily;
707 OUString sName;
708 if( !bPara && mxTextAutoStyles.is() )
709 xAutoStyles = mxTextAutoStyles;
710 else if( bPara && mxParaAutoStyles.is() )
711 xAutoStyles = mxParaAutoStyles;
712 else
714 sName = bPara ? OUString( "ParagraphStyles" ): OUString( "CharacterStyles" );
715 Reference< XAutoStylesSupplier > xAutoStylesSupp( GetImport().GetModel(), UNO_QUERY );
716 Reference< XAutoStyles > xAutoStyleFamilies = xAutoStylesSupp->getAutoStyles();
717 if (xAutoStyleFamilies->hasByName(sName))
719 Any aAny = xAutoStyleFamilies->getByName( sName );
720 xAutoStyles = *(Reference<XAutoStyleFamily>*)aAny.getValue();
721 if( bPara )
722 ((SvXMLStylesContext *)this)->mxParaAutoStyles = xAutoStyles;
723 else
724 ((SvXMLStylesContext *)this)->mxTextAutoStyles = xAutoStyles;
728 return xAutoStyles;
731 Reference < XNameContainer > SvXMLStylesContext::GetStylesContainer(
732 sal_uInt16 nFamily ) const
734 Reference < XNameContainer > xStyles;
735 OUString sName;
736 switch( nFamily )
738 case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
739 if( mxParaStyles.is() )
740 xStyles = mxParaStyles;
741 else
742 sName = "ParagraphStyles";
743 break;
745 case XML_STYLE_FAMILY_TEXT_TEXT:
746 if( mxTextStyles.is() )
747 xStyles = mxTextStyles;
748 else
749 sName = "CharacterStyles";
750 break;
752 if( !xStyles.is() && !sName.isEmpty() )
754 Reference< XStyleFamiliesSupplier > xFamiliesSupp(
755 GetImport().GetModel(), UNO_QUERY );
756 if ( xFamiliesSupp.is() )
758 Reference< XNameAccess > xFamilies = xFamiliesSupp->getStyleFamilies();
759 if (xFamilies->hasByName(sName))
761 xStyles.set(xFamilies->getByName( sName ),uno::UNO_QUERY);
763 switch( nFamily )
765 case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
766 ((SvXMLStylesContext *)this)->mxParaStyles = xStyles;
767 break;
769 case XML_STYLE_FAMILY_TEXT_TEXT:
770 ((SvXMLStylesContext *)this)->mxTextStyles = xStyles;
771 break;
777 return xStyles;
780 OUString SvXMLStylesContext::GetServiceName( sal_uInt16 nFamily ) const
782 OUString sServiceName;
783 switch( nFamily )
785 case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
786 sServiceName = msParaStyleServiceName;
787 break;
788 case XML_STYLE_FAMILY_TEXT_TEXT:
789 sServiceName = msTextStyleServiceName;
790 break;
793 return sServiceName;
797 SvXMLStylesContext::SvXMLStylesContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
798 const OUString& rLName,
799 const uno::Reference< xml::sax::XAttributeList > &, sal_Bool bAuto ) :
800 SvXMLImportContext( rImport, nPrfx, rLName ),
801 msParaStyleServiceName( "com.sun.star.style.ParagraphStyle" ),
802 msTextStyleServiceName( "com.sun.star.style.CharacterStyle" ),
803 mpImpl( new SvXMLStylesContext_Impl( bAuto ) ),
804 mpStyleStylesElemTokenMap( 0 )
809 SvXMLStylesContext::~SvXMLStylesContext()
811 delete mpStyleStylesElemTokenMap;
812 delete mpImpl;
815 SvXMLImportContext *SvXMLStylesContext::CreateChildContext( sal_uInt16 nPrefix,
816 const OUString& rLocalName,
817 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
819 SvXMLImportContext *pContext = 0;
821 SvXMLStyleContext *pStyle =
822 CreateStyleChildContext( nPrefix, rLocalName, xAttrList );
823 if( pStyle )
825 if( !pStyle->IsTransient() )
826 mpImpl->AddStyle( pStyle );
827 pContext = pStyle;
829 else
831 pContext = new SvXMLImportContext( GetImport(), nPrefix,
832 rLocalName );
835 return pContext;
838 void SvXMLStylesContext::EndElement()
842 void SvXMLStylesContext::AddStyle(SvXMLStyleContext& rNew)
844 mpImpl->AddStyle( &rNew );
847 void SvXMLStylesContext::Clear()
849 mpImpl->Clear();
852 void SvXMLStylesContext::CopyAutoStylesToDoc()
854 sal_uInt32 nCount = GetStyleCount();
855 sal_uInt32 i;
856 for( i = 0; i < nCount; i++ )
858 SvXMLStyleContext *pStyle = GetStyle( i );
859 if( !pStyle || ( pStyle->GetFamily() != XML_STYLE_FAMILY_TEXT_TEXT &&
860 pStyle->GetFamily() != XML_STYLE_FAMILY_TEXT_PARAGRAPH &&
861 pStyle->GetFamily() != XML_STYLE_FAMILY_TABLE_CELL ) )
862 continue;
863 pStyle->CreateAndInsert( sal_False );
867 void SvXMLStylesContext::CopyStylesToDoc( sal_Bool bOverwrite,
868 sal_Bool bFinish )
870 // pass 1: create text, paragraph and frame styles
871 sal_uInt32 nCount = GetStyleCount();
872 sal_uInt32 i;
874 for( i = 0; i < nCount; i++ )
876 SvXMLStyleContext *pStyle = GetStyle( i );
877 if( !pStyle )
878 continue;
880 if (pStyle->IsDefaultStyle())
881 pStyle->SetDefaults();
882 else if( InsertStyleFamily( pStyle->GetFamily() ) )
883 pStyle->CreateAndInsert( bOverwrite );
886 // pass 2: create list styles (they require char styles)
887 for( i=0; i<nCount; i++ )
889 SvXMLStyleContext *pStyle = GetStyle( i );
890 if( !pStyle || pStyle->IsDefaultStyle())
891 continue;
893 if( InsertStyleFamily( pStyle->GetFamily() ) )
894 pStyle->CreateAndInsertLate( bOverwrite );
897 // pass3: finish creation of styles
898 if( bFinish )
899 FinishStyles( bOverwrite );
902 void SvXMLStylesContext::FinishStyles( sal_Bool bOverwrite )
904 sal_uInt32 nCount = GetStyleCount();
905 for( sal_uInt32 i=0; i<nCount; i++ )
907 SvXMLStyleContext *pStyle = GetStyle( i );
908 if( !pStyle || !pStyle->IsValid() || pStyle->IsDefaultStyle() )
909 continue;
911 if( InsertStyleFamily( pStyle->GetFamily() ) )
912 pStyle->Finish( bOverwrite );
917 const SvXMLStyleContext *SvXMLStylesContext::FindStyleChildContext(
918 sal_uInt16 nFamily,
919 const OUString& rName,
920 sal_Bool bCreateIndex ) const
922 return mpImpl->FindStyleChildContext( nFamily, rName, bCreateIndex );
925 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */