nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / style / xmlstyle.cxx
blobfdaf07f47b4d4e534bada9b9c89b817ec04c7b7f
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 <sal/config.h>
22 #include <com/sun/star/frame/XModel.hpp>
23 #include <com/sun/star/xml/sax/XAttributeList.hpp>
24 #include <com/sun/star/container/XNameContainer.hpp>
25 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
26 #include <com/sun/star/style/XAutoStylesSupplier.hpp>
27 #include <com/sun/star/style/XAutoStyleFamily.hpp>
28 #include <PageMasterPropMapper.hxx>
29 #include <sal/log.hxx>
30 #include <svl/style.hxx>
31 #include <xmloff/namespacemap.hxx>
32 #include <xmloff/xmlnamespace.hxx>
33 #include <xmloff/xmltoken.hxx>
35 #include <xmloff/families.hxx>
36 #include <xmloff/xmlimp.hxx>
37 #include <xmloff/xmlnumi.hxx>
38 #include <xmloff/xmlimppr.hxx>
39 #include <xmloff/xmlstyle.hxx>
40 #include <xmloff/txtstyli.hxx>
41 #include <xmloff/xmlnumfi.hxx>
42 #include <XMLChartStyleContext.hxx>
43 #include <XMLChartPropertySetMapper.hxx>
44 #include <xmloff/XMLShapeStyleContext.hxx>
45 #include "FillStyleContext.hxx"
46 #include <XMLFootnoteConfigurationImportContext.hxx>
47 #include <XMLIndexBibliographyConfigurationContext.hxx>
48 #include <XMLLineNumberingImportContext.hxx>
49 #include <PageMasterImportContext.hxx>
50 #include "PageMasterImportPropMapper.hxx"
52 #include <memory>
53 #include <set>
54 #include <vector>
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::container;
59 using namespace ::com::sun::star::style;
60 using namespace ::xmloff::token;
62 constexpr OUStringLiteral gsParaStyleServiceName( u"com.sun.star.style.ParagraphStyle" );
63 constexpr OUStringLiteral gsTextStyleServiceName( u"com.sun.star.style.CharacterStyle" );
65 void SvXMLStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
66 const OUString& rLocalName,
67 const OUString& rValue )
69 // TODO: use a map here
70 if( XML_NAMESPACE_STYLE == nPrefixKey )
72 if( IsXMLToken( rLocalName, XML_FAMILY ) )
74 if( IsXMLToken( rValue, XML_PARAGRAPH ) )
75 mnFamily = XmlStyleFamily(SfxStyleFamily::Para);
76 else if( IsXMLToken( rValue, XML_TEXT ) )
77 mnFamily = XmlStyleFamily(SfxStyleFamily::Char);
79 else if( IsXMLToken( rLocalName, XML_NAME ) )
81 maName = rValue;
83 else if( IsXMLToken( rLocalName, XML_DISPLAY_NAME ) )
85 maDisplayName = rValue;
87 else if( IsXMLToken( rLocalName, XML_PARENT_STYLE_NAME ) )
89 maParentName = rValue;
91 else if( IsXMLToken( rLocalName, XML_NEXT_STYLE_NAME ) )
93 maFollow = rValue;
95 else if( IsXMLToken( rLocalName, XML_HIDDEN ) )
97 mbHidden = rValue.toBoolean();
100 else if (XML_NAMESPACE_LO_EXT == nPrefixKey)
102 if (IsXMLToken(rLocalName, XML_HIDDEN))
104 mbHidden = rValue.toBoolean();
110 SvXMLStyleContext::SvXMLStyleContext(
111 SvXMLImport& rImp,
112 XmlStyleFamily nFam, bool bDefault ) :
113 SvXMLImportContext( rImp ),
114 mbHidden( false ),
115 mnFamily( nFam ),
116 mbValid( true ),
117 mbNew( true ),
118 mbDefaultStyle( bDefault )
122 SvXMLStyleContext::~SvXMLStyleContext()
126 void SvXMLStyleContext::startFastElement(
127 sal_Int32 /*nElement*/,
128 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
130 // Fall back from fastparser to slowparser code
131 for( auto &it : sax_fastparser::castToFastAttributeList( xAttrList ) )
133 sal_Int32 nToken = it.getToken();
134 const OUString& rAttrNamespacePrefix = SvXMLImport::getNamespacePrefixFromToken(nToken, &GetImport().GetNamespaceMap());
135 OUString sAttrName = SvXMLImport::getNameFromToken( nToken );
136 if ( !rAttrNamespacePrefix.isEmpty() )
137 sAttrName = rAttrNamespacePrefix + SvXMLImport::aNamespaceSeparator + sAttrName;
138 OUString aLocalName;
139 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
141 SetAttribute( nPrefix, aLocalName, it.toString() );
145 void SvXMLStyleContext::SetDefaults()
149 void SvXMLStyleContext::CreateAndInsert( bool /*bOverwrite*/ )
153 void SvXMLStyleContext::CreateAndInsertLate( bool /*bOverwrite*/ )
157 void SvXMLStyleContext::Finish( bool /*bOverwrite*/ )
161 bool SvXMLStyleContext::IsTransient() const
163 return false;
166 namespace {
168 class SvXMLStyleIndex_Impl
170 OUString sName;
171 XmlStyleFamily nFamily;
172 // we deliberately don't use a reference here, to avoid creating a ref-count-cycle
173 SvXMLStyleContext* mpStyle;
175 public:
177 SvXMLStyleIndex_Impl( XmlStyleFamily nFam, const OUString& rName ) :
178 sName( rName ),
179 nFamily( nFam ),
180 mpStyle(nullptr)
184 SvXMLStyleIndex_Impl( const rtl::Reference<SvXMLStyleContext> &rStl ) :
185 sName( rStl->GetName() ),
186 nFamily( rStl->GetFamily() ),
187 mpStyle ( rStl.get() )
191 const OUString& GetName() const { return sName; }
192 XmlStyleFamily GetFamily() const { return nFamily; }
193 const SvXMLStyleContext *GetStyle() const { return mpStyle; }
196 struct SvXMLStyleIndexCmp_Impl
198 bool operator()(const SvXMLStyleIndex_Impl& r1, const SvXMLStyleIndex_Impl& r2) const
200 sal_Int32 nRet;
202 if( r1.GetFamily() < r2.GetFamily() )
203 nRet = -1;
204 else if( r1.GetFamily() > r2.GetFamily() )
205 nRet = 1;
206 else
207 nRet = r1.GetName().compareTo( r2.GetName() );
209 return nRet < 0;
215 class SvXMLStylesContext_Impl
217 typedef std::set<SvXMLStyleIndex_Impl, SvXMLStyleIndexCmp_Impl> IndicesType;
219 std::vector<rtl::Reference<SvXMLStyleContext>> aStyles;
220 mutable std::unique_ptr<IndicesType> pIndices;
221 bool bAutomaticStyle;
223 #if OSL_DEBUG_LEVEL > 0
224 mutable sal_uInt32 m_nIndexCreated;
225 #endif
227 void FlushIndex() { pIndices.reset(); }
229 public:
230 explicit SvXMLStylesContext_Impl( bool bAuto );
232 size_t GetStyleCount() const { return aStyles.size(); }
234 SvXMLStyleContext *GetStyle( size_t i )
236 return i < aStyles.size() ? aStyles[ i ].get() : nullptr;
239 inline void AddStyle( SvXMLStyleContext *pStyle );
240 void dispose();
242 const SvXMLStyleContext *FindStyleChildContext( XmlStyleFamily nFamily,
243 const OUString& rName,
244 bool bCreateIndex ) const;
245 bool IsAutomaticStyle() const { return bAutomaticStyle; }
248 SvXMLStylesContext_Impl::SvXMLStylesContext_Impl( bool bAuto ) :
249 bAutomaticStyle( bAuto )
250 #if OSL_DEBUG_LEVEL > 0
251 , m_nIndexCreated( 0 )
252 #endif
255 inline void SvXMLStylesContext_Impl::AddStyle( SvXMLStyleContext *pStyle )
257 #if OSL_DEBUG_LEVEL > 0
258 // for (auto const & xStyle : aStyles)
259 // if (xStyle->GetFamily() == pStyle->GetFamily() && xStyle->GetName() == pStyle->GetName())
260 // assert(false && "duplicate style");
261 #endif
262 aStyles.emplace_back(pStyle );
264 FlushIndex();
267 void SvXMLStylesContext_Impl::dispose()
269 FlushIndex();
270 aStyles.clear();
273 const SvXMLStyleContext *SvXMLStylesContext_Impl::FindStyleChildContext( XmlStyleFamily nFamily,
274 const OUString& rName,
275 bool bCreateIndex ) const
277 const SvXMLStyleContext *pStyle = nullptr;
279 if( !pIndices && bCreateIndex && !aStyles.empty() )
281 pIndices = std::make_unique<IndicesType>(aStyles.begin(), aStyles.end());
282 SAL_WARN_IF(pIndices->size() != aStyles.size(), "xmloff.style", "Here is a duplicate Style");
283 #if OSL_DEBUG_LEVEL > 0
284 SAL_WARN_IF(0 != m_nIndexCreated, "xmloff.style",
285 "Performance warning: sdbcx::Index created multiple times");
286 ++m_nIndexCreated;
287 #endif
290 if( pIndices )
292 SvXMLStyleIndex_Impl aIndex( nFamily, rName );
293 IndicesType::iterator aFind = pIndices->find(aIndex);
294 if( aFind != pIndices->end() )
295 pStyle = aFind->GetStyle();
297 else
299 for( size_t i = 0; !pStyle && i < aStyles.size(); i++ )
301 const SvXMLStyleContext *pS = aStyles[ i ].get();
302 if( pS->GetFamily() == nFamily &&
303 pS->GetName() == rName )
304 pStyle = pS;
307 return pStyle;
311 sal_uInt32 SvXMLStylesContext::GetStyleCount() const
313 return mpImpl->GetStyleCount();
316 SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i )
318 return mpImpl->GetStyle( i );
321 const SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i ) const
323 return mpImpl->GetStyle( i );
326 bool SvXMLStylesContext::IsAutomaticStyle() const
328 return mpImpl->IsAutomaticStyle();
331 SvXMLStyleContext *SvXMLStylesContext::CreateStyleChildContext(
332 sal_Int32 nElement,
333 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList)
335 SvXMLStyleContext *pStyle = nullptr;
337 if(GetImport().GetDataStylesImport())
339 pStyle = GetImport().GetDataStylesImport()->CreateChildContext(GetImport(), nElement,
340 xAttrList, *this);
341 if (pStyle)
342 return pStyle;
345 switch (nElement)
347 case XML_ELEMENT(STYLE, XML_STYLE):
348 case XML_ELEMENT(STYLE, XML_DEFAULT_STYLE):
350 XmlStyleFamily nFamily = XmlStyleFamily::DATA_STYLE;
351 for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) )
353 if( aIter.getToken() == XML_ELEMENT(STYLE, XML_FAMILY) )
355 nFamily = GetFamily( aIter.toString() );
356 break;
359 pStyle = XML_ELEMENT(STYLE, XML_STYLE)==nElement
360 ? CreateStyleStyleChildContext( nFamily, nElement, xAttrList )
361 : CreateDefaultStyleStyleChildContext( nFamily, nElement, xAttrList );
362 break;
364 case XML_ELEMENT(TEXT, XML_BIBLIOGRAPHY_CONFIGURATION):
365 pStyle = new XMLIndexBibliographyConfigurationContext(GetImport());
366 break;
367 case XML_ELEMENT(TEXT, XML_NOTES_CONFIGURATION):
368 pStyle = new XMLFootnoteConfigurationImportContext(
369 GetImport(), nElement, xAttrList);
370 break;
371 case XML_ELEMENT(TEXT, XML_LINENUMBERING_CONFIGURATION):
372 pStyle = new XMLLineNumberingImportContext(GetImport());
373 break;
374 case XML_ELEMENT(STYLE, XML_PAGE_LAYOUT):
375 case XML_ELEMENT(STYLE, XML_DEFAULT_PAGE_LAYOUT):
377 //there is not page family in ODF now, so I specify one for it
378 bool bDefaultStyle = XML_ELEMENT(STYLE, XML_DEFAULT_PAGE_LAYOUT) == nElement;
379 pStyle = new PageStyleContext( GetImport(), *this, bDefaultStyle );
381 break;
382 case XML_ELEMENT(TEXT, XML_LIST_STYLE):
383 pStyle = new SvxXMLListStyleContext( GetImport() );
384 break;
385 case XML_ELEMENT(TEXT, XML_OUTLINE_STYLE):
386 pStyle = new SvxXMLListStyleContext( GetImport(), true );
387 break;
389 // FillStyles
391 case XML_ELEMENT(DRAW, XML_GRADIENT):
393 pStyle = new XMLGradientStyleContext( GetImport(), nElement, xAttrList );
394 break;
396 case XML_ELEMENT(DRAW, XML_HATCH):
398 pStyle = new XMLHatchStyleContext( GetImport(), nElement, xAttrList );
399 break;
401 case XML_ELEMENT(DRAW, XML_FILL_IMAGE):
403 pStyle = new XMLBitmapStyleContext( GetImport(), nElement, xAttrList );
404 break;
406 case XML_ELEMENT(DRAW, XML_OPACITY):
408 pStyle = new XMLTransGradientStyleContext( GetImport(), nElement, xAttrList );
409 break;
411 case XML_ELEMENT(DRAW, XML_MARKER):
413 pStyle = new XMLMarkerStyleContext( GetImport(), nElement, xAttrList );
414 break;
416 case XML_ELEMENT(DRAW, XML_STROKE_DASH):
418 pStyle = new XMLDashStyleContext( GetImport(), nElement, xAttrList );
419 break;
423 if (!pStyle)
424 SAL_WARN("xmloff", "Unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement));
426 return pStyle;
429 SvXMLStyleContext *SvXMLStylesContext::CreateStyleStyleChildContext(
430 XmlStyleFamily nFamily, sal_Int32 /*nElement*/,
431 const uno::Reference< xml::sax::XFastAttributeList > & /*xAttrList*/ )
433 SvXMLStyleContext *pStyle = nullptr;
435 switch( nFamily )
437 case XmlStyleFamily::TEXT_PARAGRAPH:
438 case XmlStyleFamily::TEXT_TEXT:
439 case XmlStyleFamily::TEXT_SECTION:
440 pStyle = new XMLTextStyleContext( GetImport(), *this, nFamily );
441 break;
443 case XmlStyleFamily::TEXT_RUBY:
444 pStyle = new XMLPropStyleContext( GetImport(), *this, nFamily );
445 break;
446 case XmlStyleFamily::SCH_CHART_ID:
447 pStyle = new XMLChartStyleContext( GetImport(), *this, nFamily );
448 break;
450 case XmlStyleFamily::SD_GRAPHICS_ID:
451 case XmlStyleFamily::SD_PRESENTATION_ID:
452 case XmlStyleFamily::SD_POOL_ID:
453 pStyle = new XMLShapeStyleContext( GetImport(), *this, nFamily );
454 break;
455 default: break;
458 return pStyle;
461 SvXMLStyleContext *SvXMLStylesContext::CreateDefaultStyleStyleChildContext(
462 XmlStyleFamily /*nFamily*/, sal_Int32 /*nElement*/,
463 const uno::Reference< xml::sax::XFastAttributeList > & )
465 return nullptr;
468 bool SvXMLStylesContext::InsertStyleFamily( XmlStyleFamily ) const
470 return true;
473 XmlStyleFamily SvXMLStylesContext::GetFamily( const OUString& rValue )
475 XmlStyleFamily nFamily = XmlStyleFamily::DATA_STYLE;
476 if( IsXMLToken( rValue, XML_PARAGRAPH ) )
478 nFamily = XmlStyleFamily::TEXT_PARAGRAPH;
480 else if( IsXMLToken( rValue, XML_TEXT ) )
482 nFamily = XmlStyleFamily::TEXT_TEXT;
484 else if( IsXMLToken( rValue, XML_DATA_STYLE ) )
486 nFamily = XmlStyleFamily::DATA_STYLE;
488 else if ( IsXMLToken( rValue, XML_SECTION ) )
490 nFamily = XmlStyleFamily::TEXT_SECTION;
492 else if( IsXMLToken( rValue, XML_TABLE ) )
494 nFamily = XmlStyleFamily::TABLE_TABLE;
496 else if( IsXMLToken( rValue, XML_TABLE_COLUMN ) )
497 nFamily = XmlStyleFamily::TABLE_COLUMN;
498 else if( IsXMLToken( rValue, XML_TABLE_ROW ) )
499 nFamily = XmlStyleFamily::TABLE_ROW;
500 else if( IsXMLToken( rValue, XML_TABLE_CELL ) )
501 nFamily = XmlStyleFamily::TABLE_CELL;
502 else if ( rValue == XML_STYLE_FAMILY_SD_GRAPHICS_NAME )
504 nFamily = XmlStyleFamily::SD_GRAPHICS_ID;
506 else if ( rValue == XML_STYLE_FAMILY_SD_PRESENTATION_NAME )
508 nFamily = XmlStyleFamily::SD_PRESENTATION_ID;
510 else if ( rValue == XML_STYLE_FAMILY_SD_POOL_NAME )
512 nFamily = XmlStyleFamily::SD_POOL_ID;
514 else if ( rValue == XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME )
516 nFamily = XmlStyleFamily::SD_DRAWINGPAGE_ID;
518 else if ( rValue == XML_STYLE_FAMILY_SCH_CHART_NAME )
520 nFamily = XmlStyleFamily::SCH_CHART_ID;
522 else if ( IsXMLToken( rValue, XML_RUBY ) )
524 nFamily = XmlStyleFamily::TEXT_RUBY;
527 return nFamily;
530 rtl::Reference < SvXMLImportPropertyMapper > SvXMLStylesContext::GetImportPropertyMapper(
531 XmlStyleFamily nFamily ) const
533 rtl::Reference < SvXMLImportPropertyMapper > xMapper;
535 switch( nFamily )
537 case XmlStyleFamily::TEXT_PARAGRAPH:
538 if( !mxParaImpPropMapper.is() )
540 SvXMLStylesContext * pThis = const_cast<SvXMLStylesContext *>(this);
541 pThis->mxParaImpPropMapper =
542 pThis->GetImport().GetTextImport()
543 ->GetParaImportPropertySetMapper();
545 xMapper = mxParaImpPropMapper;
546 break;
547 case XmlStyleFamily::TEXT_TEXT:
548 if( !mxTextImpPropMapper.is() )
550 SvXMLStylesContext * pThis = const_cast<SvXMLStylesContext *>(this);
551 pThis->mxTextImpPropMapper =
552 pThis->GetImport().GetTextImport()
553 ->GetTextImportPropertySetMapper();
555 xMapper = mxTextImpPropMapper;
556 break;
558 case XmlStyleFamily::TEXT_SECTION:
559 // don't cache section mapper, as it's rarely used
560 // *sigh*, cast to non-const, because this is a const method,
561 // but SvXMLImport::GetTextImport() isn't.
562 xMapper = const_cast<SvXMLStylesContext*>(this)->GetImport().GetTextImport()->
563 GetSectionImportPropertySetMapper();
564 break;
566 case XmlStyleFamily::TEXT_RUBY:
567 // don't cache section mapper, as it's rarely used
568 // *sigh*, cast to non-const, because this is a const method,
569 // but SvXMLImport::GetTextImport() isn't.
570 xMapper = const_cast<SvXMLStylesContext*>(this)->GetImport().GetTextImport()->
571 GetRubyImportPropertySetMapper();
572 break;
574 case XmlStyleFamily::SD_GRAPHICS_ID:
575 case XmlStyleFamily::SD_PRESENTATION_ID:
576 case XmlStyleFamily::SD_POOL_ID:
577 if(!mxShapeImpPropMapper.is())
579 rtl::Reference< XMLShapeImportHelper > aImpHelper = const_cast<SvXMLImport&>(GetImport()).GetShapeImport();
580 const_cast<SvXMLStylesContext*>(this)->mxShapeImpPropMapper =
581 aImpHelper->GetPropertySetMapper();
583 xMapper = mxShapeImpPropMapper;
584 break;
585 case XmlStyleFamily::SCH_CHART_ID:
586 if( ! mxChartImpPropMapper.is() )
588 XMLPropertySetMapper *const pPropMapper = new XMLChartPropertySetMapper(nullptr);
589 mxChartImpPropMapper = new XMLChartImportPropertyMapper( pPropMapper, GetImport() );
591 xMapper = mxChartImpPropMapper;
592 break;
593 case XmlStyleFamily::PAGE_MASTER:
594 if( ! mxPageImpPropMapper.is() )
596 XMLPropertySetMapper *pPropMapper =
597 new XMLPageMasterPropSetMapper();
598 mxPageImpPropMapper =
599 new PageMasterImportPropertyMapper( pPropMapper,
600 const_cast<SvXMLStylesContext*>(this)->GetImport() );
602 xMapper = mxPageImpPropMapper;
603 break;
604 default: break;
607 return xMapper;
610 Reference < XAutoStyleFamily > SvXMLStylesContext::GetAutoStyles( XmlStyleFamily nFamily ) const
612 Reference < XAutoStyleFamily > xAutoStyles;
613 if( XmlStyleFamily::TEXT_TEXT == nFamily || XmlStyleFamily::TEXT_PARAGRAPH == nFamily)
615 bool bPara = XmlStyleFamily::TEXT_PARAGRAPH == nFamily;
616 if( !bPara && mxTextAutoStyles.is() )
617 xAutoStyles = mxTextAutoStyles;
618 else if( bPara && mxParaAutoStyles.is() )
619 xAutoStyles = mxParaAutoStyles;
620 else
622 OUStringLiteral sName = bPara ? OUStringLiteral( u"ParagraphStyles" ): OUStringLiteral( u"CharacterStyles" );
623 Reference< XAutoStylesSupplier > xAutoStylesSupp( GetImport().GetModel(), UNO_QUERY );
624 Reference< XAutoStyles > xAutoStyleFamilies = xAutoStylesSupp->getAutoStyles();
625 if (xAutoStyleFamilies->hasByName(sName))
627 Any aAny = xAutoStyleFamilies->getByName( sName );
628 aAny >>= xAutoStyles;
629 if( bPara )
630 const_cast<SvXMLStylesContext *>(this)->mxParaAutoStyles = xAutoStyles;
631 else
632 const_cast<SvXMLStylesContext *>(this)->mxTextAutoStyles = xAutoStyles;
636 return xAutoStyles;
639 Reference < XNameContainer > SvXMLStylesContext::GetStylesContainer(
640 XmlStyleFamily nFamily ) const
642 Reference < XNameContainer > xStyles;
643 OUString sName;
644 switch( nFamily )
646 case XmlStyleFamily::TEXT_PARAGRAPH:
647 if( mxParaStyles.is() )
648 xStyles = mxParaStyles;
649 else
650 sName = "ParagraphStyles";
651 break;
653 case XmlStyleFamily::TEXT_TEXT:
654 if( mxTextStyles.is() )
655 xStyles = mxTextStyles;
656 else
657 sName = "CharacterStyles";
658 break;
659 default: break;
661 if( !xStyles.is() && !sName.isEmpty() )
663 Reference< XStyleFamiliesSupplier > xFamiliesSupp(
664 GetImport().GetModel(), UNO_QUERY );
665 if ( xFamiliesSupp.is() )
667 Reference< XNameAccess > xFamilies = xFamiliesSupp->getStyleFamilies();
668 if (xFamilies->hasByName(sName))
670 xStyles.set(xFamilies->getByName( sName ),uno::UNO_QUERY);
672 switch( nFamily )
674 case XmlStyleFamily::TEXT_PARAGRAPH:
675 const_cast<SvXMLStylesContext *>(this)->mxParaStyles = xStyles;
676 break;
678 case XmlStyleFamily::TEXT_TEXT:
679 const_cast<SvXMLStylesContext *>(this)->mxTextStyles = xStyles;
680 break;
681 default: break;
687 return xStyles;
690 OUString SvXMLStylesContext::GetServiceName( XmlStyleFamily nFamily ) const
692 OUString sServiceName;
693 switch( nFamily )
695 case XmlStyleFamily::TEXT_PARAGRAPH:
696 sServiceName = gsParaStyleServiceName;
697 break;
698 case XmlStyleFamily::TEXT_TEXT:
699 sServiceName = gsTextStyleServiceName;
700 break;
701 default: break;
704 return sServiceName;
707 SvXMLStylesContext::SvXMLStylesContext( SvXMLImport& rImport, bool bAuto ) :
708 SvXMLImportContext( rImport ),
709 mpImpl( new SvXMLStylesContext_Impl( bAuto ) )
713 SvXMLStylesContext::~SvXMLStylesContext()
717 css::uno::Reference< css::xml::sax::XFastContextHandler > SvXMLStylesContext::createFastChildContext(
718 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
720 SvXMLStyleContext *pStyle =
721 CreateStyleChildContext( nElement, xAttrList );
722 if( pStyle )
724 if( !pStyle->IsTransient() )
725 mpImpl->AddStyle( pStyle );
726 return pStyle;
729 return nullptr;
732 void SvXMLStylesContext::AddStyle(SvXMLStyleContext& rNew)
734 mpImpl->AddStyle( &rNew );
737 void SvXMLStylesContext::dispose()
739 mpImpl->dispose();
742 void SvXMLStylesContext::CopyAutoStylesToDoc()
744 sal_uInt32 nCount = GetStyleCount();
745 sal_uInt32 i;
746 for( i = 0; i < nCount; i++ )
748 SvXMLStyleContext *pStyle = GetStyle( i );
749 if( !pStyle || ( pStyle->GetFamily() != XmlStyleFamily::TEXT_TEXT &&
750 pStyle->GetFamily() != XmlStyleFamily::TEXT_PARAGRAPH &&
751 pStyle->GetFamily() != XmlStyleFamily::TABLE_CELL ) )
752 continue;
753 pStyle->CreateAndInsert( false );
757 void SvXMLStylesContext::CopyStylesToDoc( bool bOverwrite,
758 bool bFinish )
760 // pass 1: create text, paragraph and frame styles
761 sal_uInt32 nCount = GetStyleCount();
762 sal_uInt32 i;
764 for( i = 0; i < nCount; i++ )
766 SvXMLStyleContext *pStyle = GetStyle( i );
767 if( !pStyle )
768 continue;
770 if (pStyle->IsDefaultStyle())
772 if (bOverwrite) pStyle->SetDefaults();
774 else if( InsertStyleFamily( pStyle->GetFamily() ) )
775 pStyle->CreateAndInsert( bOverwrite );
778 // pass 2: create list styles (they require char styles)
779 for( i=0; i<nCount; i++ )
781 SvXMLStyleContext *pStyle = GetStyle( i );
782 if( !pStyle || pStyle->IsDefaultStyle())
783 continue;
785 if( InsertStyleFamily( pStyle->GetFamily() ) )
786 pStyle->CreateAndInsertLate( bOverwrite );
789 // pass3: finish creation of styles
790 if( bFinish )
791 FinishStyles( bOverwrite );
794 void SvXMLStylesContext::FinishStyles( bool bOverwrite )
796 sal_uInt32 nCount = GetStyleCount();
797 for( sal_uInt32 i=0; i<nCount; i++ )
799 SvXMLStyleContext *pStyle = GetStyle( i );
800 if( !pStyle || !pStyle->IsValid() || pStyle->IsDefaultStyle() )
801 continue;
803 if( InsertStyleFamily( pStyle->GetFamily() ) )
804 pStyle->Finish( bOverwrite );
808 const SvXMLStyleContext *SvXMLStylesContext::FindStyleChildContext(
809 XmlStyleFamily nFamily,
810 const OUString& rName,
811 bool bCreateIndex ) const
813 return mpImpl->FindStyleChildContext( nFamily, rName, bCreateIndex );
816 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */