Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / xmloff / source / style / xmlstyle.cxx
blobbd4273056c980da0098eaeb11eb5619a0c4d7249
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 <config_wasm_strip.h>
22 #include <sal/config.h>
24 #include <com/sun/star/frame/XModel.hpp>
25 #include <com/sun/star/xml/sax/XAttributeList.hpp>
26 #include <com/sun/star/container/XNameContainer.hpp>
27 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
28 #include <com/sun/star/style/XAutoStylesSupplier.hpp>
29 #include <com/sun/star/style/XAutoStyleFamily.hpp>
30 #include <PageMasterPropMapper.hxx>
31 #include <sal/log.hxx>
32 #include <svl/style.hxx>
33 #include <utility>
34 #include <xmloff/namespacemap.hxx>
35 #include <xmloff/xmlnamespace.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/xmlnumfi.hxx>
45 #include <XMLChartStyleContext.hxx>
46 #include <XMLChartPropertySetMapper.hxx>
47 #include <xmloff/XMLShapeStyleContext.hxx>
48 #include "FillStyleContext.hxx"
49 #include <XMLFootnoteConfigurationImportContext.hxx>
50 #include <XMLIndexBibliographyConfigurationContext.hxx>
51 #include <XMLLineNumberingImportContext.hxx>
52 #include <PageMasterImportContext.hxx>
53 #include "PageMasterImportPropMapper.hxx"
55 #include <memory>
56 #include <set>
57 #include <string_view>
58 #include <vector>
60 using namespace ::com::sun::star;
61 using namespace ::com::sun::star::uno;
62 using namespace ::com::sun::star::container;
63 using namespace ::com::sun::star::style;
64 using namespace ::xmloff::token;
66 constexpr OUStringLiteral gsParaStyleServiceName( u"com.sun.star.style.ParagraphStyle" );
67 constexpr OUStringLiteral gsTextStyleServiceName( u"com.sun.star.style.CharacterStyle" );
69 void SvXMLStyleContext::SetAttribute( sal_Int32 nElement,
70 const OUString& rValue )
72 switch (nElement)
74 case XML_ELEMENT(STYLE, XML_FAMILY):
76 if( IsXMLToken( rValue, XML_PARAGRAPH ) )
77 mnFamily = XmlStyleFamily(SfxStyleFamily::Para);
78 else if( IsXMLToken( rValue, XML_TEXT ) )
79 mnFamily = XmlStyleFamily(SfxStyleFamily::Char);
80 break;
82 case XML_ELEMENT(STYLE, XML_NAME):
83 maName = rValue;
84 break;
85 case XML_ELEMENT(STYLE, XML_DISPLAY_NAME):
86 maDisplayName = rValue;
87 break;
88 case XML_ELEMENT(STYLE, XML_PARENT_STYLE_NAME):
89 maParentName = rValue;
90 break;
91 case XML_ELEMENT(STYLE, XML_NEXT_STYLE_NAME):
92 maFollow = rValue;
93 break;
94 case XML_ELEMENT(LO_EXT, XML_LINKED_STYLE_NAME):
95 maLinked = rValue;
96 break;
97 case XML_ELEMENT(STYLE, XML_HIDDEN):
98 mbHidden = rValue.toBoolean();
99 break;
100 case XML_ELEMENT(LO_EXT, XML_HIDDEN):
101 mbHidden = rValue.toBoolean();
102 break;
107 SvXMLStyleContext::SvXMLStyleContext(
108 SvXMLImport& rImp,
109 XmlStyleFamily nFam, bool bDefault ) :
110 SvXMLImportContext( rImp ),
111 mbHidden( false ),
112 mnFamily( nFam ),
113 mbValid( true ),
114 mbNew( true ),
115 mbDefaultStyle( bDefault )
119 SvXMLStyleContext::~SvXMLStyleContext()
123 void SvXMLStyleContext::startFastElement(
124 sal_Int32 /*nElement*/,
125 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
127 for( auto &it : sax_fastparser::castToFastAttributeList( xAttrList ) )
128 SetAttribute( it.getToken(), it.toString() );
131 void SvXMLStyleContext::SetDefaults()
135 void SvXMLStyleContext::CreateAndInsert( bool /*bOverwrite*/ )
139 void SvXMLStyleContext::CreateAndInsertLate( bool /*bOverwrite*/ )
143 void SvXMLStyleContext::Finish( bool /*bOverwrite*/ )
147 bool SvXMLStyleContext::IsTransient() const
149 return false;
152 namespace {
154 class SvXMLStyleIndex_Impl
156 OUString sName;
157 XmlStyleFamily nFamily;
158 // we deliberately don't use a reference here, to avoid creating a ref-count-cycle
159 SvXMLStyleContext* mpStyle;
161 public:
163 SvXMLStyleIndex_Impl( XmlStyleFamily nFam, OUString aName ) :
164 sName(std::move( aName )),
165 nFamily( nFam ),
166 mpStyle(nullptr)
170 SvXMLStyleIndex_Impl( const rtl::Reference<SvXMLStyleContext> &rStl ) :
171 sName( rStl->GetName() ),
172 nFamily( rStl->GetFamily() ),
173 mpStyle ( rStl.get() )
177 const OUString& GetName() const { return sName; }
178 XmlStyleFamily GetFamily() const { return nFamily; }
179 const SvXMLStyleContext *GetStyle() const { return mpStyle; }
182 struct SvXMLStyleIndexCmp_Impl
184 bool operator()(const SvXMLStyleIndex_Impl& r1, const SvXMLStyleIndex_Impl& r2) const
186 sal_Int32 nRet;
188 if( r1.GetFamily() < r2.GetFamily() )
189 nRet = -1;
190 else if( r1.GetFamily() > r2.GetFamily() )
191 nRet = 1;
192 else
193 nRet = r1.GetName().compareTo( r2.GetName() );
195 return nRet < 0;
201 class SvXMLStylesContext_Impl
203 typedef std::set<SvXMLStyleIndex_Impl, SvXMLStyleIndexCmp_Impl> IndicesType;
205 std::vector<rtl::Reference<SvXMLStyleContext>> aStyles;
206 mutable std::unique_ptr<IndicesType> pIndices;
207 bool bAutomaticStyle;
209 #if OSL_DEBUG_LEVEL > 0
210 mutable sal_uInt32 m_nIndexCreated;
211 #endif
213 void FlushIndex() { pIndices.reset(); }
215 public:
216 explicit SvXMLStylesContext_Impl( bool bAuto );
218 size_t GetStyleCount() const { return aStyles.size(); }
220 SvXMLStyleContext *GetStyle( size_t i )
222 return i < aStyles.size() ? aStyles[ i ].get() : nullptr;
225 inline void AddStyle( SvXMLStyleContext *pStyle );
226 void dispose();
228 const SvXMLStyleContext *FindStyleChildContext( XmlStyleFamily nFamily,
229 const OUString& rName,
230 bool bCreateIndex ) const;
231 bool IsAutomaticStyle() const { return bAutomaticStyle; }
234 SvXMLStylesContext_Impl::SvXMLStylesContext_Impl( bool bAuto ) :
235 bAutomaticStyle( bAuto )
236 #if OSL_DEBUG_LEVEL > 0
237 , m_nIndexCreated( 0 )
238 #endif
241 inline void SvXMLStylesContext_Impl::AddStyle( SvXMLStyleContext *pStyle )
243 #if OSL_DEBUG_LEVEL > 0
244 // for (auto const & xStyle : aStyles)
245 // if (xStyle->GetFamily() == pStyle->GetFamily() && xStyle->GetName() == pStyle->GetName())
246 // assert(false && "duplicate style");
247 #endif
248 aStyles.emplace_back(pStyle );
250 FlushIndex();
253 void SvXMLStylesContext_Impl::dispose()
255 FlushIndex();
256 aStyles.clear();
259 const SvXMLStyleContext *SvXMLStylesContext_Impl::FindStyleChildContext( XmlStyleFamily nFamily,
260 const OUString& rName,
261 bool bCreateIndex ) const
263 const SvXMLStyleContext *pStyle = nullptr;
265 if( !pIndices && bCreateIndex && !aStyles.empty() )
267 pIndices = std::make_unique<IndicesType>(aStyles.begin(), aStyles.end());
268 SAL_WARN_IF(pIndices->size() != aStyles.size(), "xmloff.style", "Here is a duplicate Style");
269 #if OSL_DEBUG_LEVEL > 0
270 SAL_WARN_IF(0 != m_nIndexCreated, "xmloff.style",
271 "Performance warning: sdbcx::Index created multiple times");
272 ++m_nIndexCreated;
273 #endif
276 if( pIndices )
278 SvXMLStyleIndex_Impl aIndex( nFamily, rName );
279 IndicesType::iterator aFind = pIndices->find(aIndex);
280 if( aFind != pIndices->end() )
281 pStyle = aFind->GetStyle();
283 else
285 for( size_t i = 0; !pStyle && i < aStyles.size(); i++ )
287 const SvXMLStyleContext *pS = aStyles[ i ].get();
288 if( pS->GetFamily() == nFamily &&
289 pS->GetName() == rName )
290 pStyle = pS;
293 return pStyle;
297 sal_uInt32 SvXMLStylesContext::GetStyleCount() const
299 return mpImpl->GetStyleCount();
302 SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i )
304 return mpImpl->GetStyle( i );
307 const SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i ) const
309 return mpImpl->GetStyle( i );
312 bool SvXMLStylesContext::IsAutomaticStyle() const
314 return mpImpl->IsAutomaticStyle();
317 SvXMLStyleContext *SvXMLStylesContext::CreateStyleChildContext(
318 sal_Int32 nElement,
319 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList)
321 SvXMLStyleContext *pStyle = nullptr;
323 if(GetImport().GetDataStylesImport())
325 pStyle = GetImport().GetDataStylesImport()->CreateChildContext(GetImport(), nElement,
326 xAttrList, *this);
327 if (pStyle)
328 return pStyle;
331 switch (nElement)
333 case XML_ELEMENT(STYLE, XML_STYLE):
334 case XML_ELEMENT(STYLE, XML_DEFAULT_STYLE):
336 XmlStyleFamily nFamily = XmlStyleFamily::DATA_STYLE;
337 for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) )
339 if( aIter.getToken() == XML_ELEMENT(STYLE, XML_FAMILY) )
341 nFamily = GetFamily( aIter.toString() );
342 break;
345 pStyle = XML_ELEMENT(STYLE, XML_STYLE)==nElement
346 ? CreateStyleStyleChildContext( nFamily, nElement, xAttrList )
347 : CreateDefaultStyleStyleChildContext( nFamily, nElement, xAttrList );
348 break;
350 case XML_ELEMENT(TEXT, XML_BIBLIOGRAPHY_CONFIGURATION):
351 pStyle = new XMLIndexBibliographyConfigurationContext(GetImport());
352 break;
353 case XML_ELEMENT(TEXT, XML_NOTES_CONFIGURATION):
354 pStyle = new XMLFootnoteConfigurationImportContext(
355 GetImport(), nElement, xAttrList);
356 break;
357 case XML_ELEMENT(TEXT, XML_LINENUMBERING_CONFIGURATION):
358 pStyle = new XMLLineNumberingImportContext(GetImport());
359 break;
360 case XML_ELEMENT(STYLE, XML_PAGE_LAYOUT):
361 case XML_ELEMENT(STYLE, XML_DEFAULT_PAGE_LAYOUT):
363 //there is not page family in ODF now, so I specify one for it
364 bool bDefaultStyle = XML_ELEMENT(STYLE, XML_DEFAULT_PAGE_LAYOUT) == nElement;
365 pStyle = new PageStyleContext( GetImport(), *this, bDefaultStyle );
367 break;
368 case XML_ELEMENT(TEXT, XML_LIST_STYLE):
369 pStyle = new SvxXMLListStyleContext( GetImport() );
370 break;
371 case XML_ELEMENT(TEXT, XML_OUTLINE_STYLE):
372 pStyle = new SvxXMLListStyleContext( GetImport(), true );
373 break;
375 // FillStyles
377 case XML_ELEMENT(DRAW, XML_GRADIENT):
379 pStyle = new XMLGradientStyleContext( GetImport(), nElement, xAttrList );
380 break;
382 case XML_ELEMENT(DRAW, XML_HATCH):
384 pStyle = new XMLHatchStyleContext( GetImport(), nElement, xAttrList );
385 break;
387 case XML_ELEMENT(DRAW, XML_FILL_IMAGE):
389 pStyle = new XMLBitmapStyleContext( GetImport(), nElement, xAttrList );
390 break;
392 case XML_ELEMENT(DRAW, XML_OPACITY):
394 pStyle = new XMLTransGradientStyleContext( GetImport(), nElement, xAttrList );
395 break;
397 case XML_ELEMENT(DRAW, XML_MARKER):
399 pStyle = new XMLMarkerStyleContext( GetImport(), nElement, xAttrList );
400 break;
402 case XML_ELEMENT(DRAW, XML_STROKE_DASH):
404 pStyle = new XMLDashStyleContext( GetImport(), nElement, xAttrList );
405 break;
409 if (!pStyle)
410 SAL_WARN("xmloff", "Unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement));
412 return pStyle;
415 SvXMLStyleContext *SvXMLStylesContext::CreateStyleStyleChildContext(
416 XmlStyleFamily nFamily, sal_Int32 /*nElement*/,
417 const uno::Reference< xml::sax::XFastAttributeList > & /*xAttrList*/ )
419 SvXMLStyleContext *pStyle = nullptr;
421 switch( nFamily )
423 case XmlStyleFamily::TEXT_PARAGRAPH:
424 case XmlStyleFamily::TEXT_TEXT:
425 case XmlStyleFamily::TEXT_SECTION:
426 pStyle = new XMLTextStyleContext( GetImport(), *this, nFamily );
427 break;
429 case XmlStyleFamily::TEXT_RUBY:
430 pStyle = new XMLPropStyleContext( GetImport(), *this, nFamily );
431 break;
432 #if !ENABLE_WASM_STRIP_CHART
433 // WASM_CHART change
434 case XmlStyleFamily::SCH_CHART_ID:
435 pStyle = new XMLChartStyleContext( GetImport(), *this, nFamily );
436 break;
437 #endif
438 case XmlStyleFamily::SD_GRAPHICS_ID:
439 case XmlStyleFamily::SD_PRESENTATION_ID:
440 case XmlStyleFamily::SD_POOL_ID:
441 pStyle = new XMLShapeStyleContext( GetImport(), *this, nFamily );
442 break;
443 default: break;
446 return pStyle;
449 SvXMLStyleContext *SvXMLStylesContext::CreateDefaultStyleStyleChildContext(
450 XmlStyleFamily /*nFamily*/, sal_Int32 /*nElement*/,
451 const uno::Reference< xml::sax::XFastAttributeList > & )
453 return nullptr;
456 bool SvXMLStylesContext::InsertStyleFamily( XmlStyleFamily ) const
458 return true;
461 XmlStyleFamily SvXMLStylesContext::GetFamily( std::u16string_view rValue )
463 XmlStyleFamily nFamily = XmlStyleFamily::DATA_STYLE;
464 if( IsXMLToken( rValue, XML_PARAGRAPH ) )
466 nFamily = XmlStyleFamily::TEXT_PARAGRAPH;
468 else if( IsXMLToken( rValue, XML_TEXT ) )
470 nFamily = XmlStyleFamily::TEXT_TEXT;
472 else if( IsXMLToken( rValue, XML_DATA_STYLE ) )
474 nFamily = XmlStyleFamily::DATA_STYLE;
476 else if ( IsXMLToken( rValue, XML_SECTION ) )
478 nFamily = XmlStyleFamily::TEXT_SECTION;
480 else if( IsXMLToken( rValue, XML_TABLE ) )
482 nFamily = XmlStyleFamily::TABLE_TABLE;
484 else if( IsXMLToken( rValue, XML_TABLE_COLUMN ) )
485 nFamily = XmlStyleFamily::TABLE_COLUMN;
486 else if( IsXMLToken( rValue, XML_TABLE_ROW ) )
487 nFamily = XmlStyleFamily::TABLE_ROW;
488 else if( IsXMLToken( rValue, XML_TABLE_CELL ) )
489 nFamily = XmlStyleFamily::TABLE_CELL;
490 else if ( rValue == XML_STYLE_FAMILY_SD_GRAPHICS_NAME )
492 nFamily = XmlStyleFamily::SD_GRAPHICS_ID;
494 else if ( rValue == XML_STYLE_FAMILY_SD_PRESENTATION_NAME )
496 nFamily = XmlStyleFamily::SD_PRESENTATION_ID;
498 else if ( rValue == XML_STYLE_FAMILY_SD_POOL_NAME )
500 nFamily = XmlStyleFamily::SD_POOL_ID;
502 else if ( rValue == XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME )
504 nFamily = XmlStyleFamily::SD_DRAWINGPAGE_ID;
506 else if ( rValue == XML_STYLE_FAMILY_SCH_CHART_NAME )
508 nFamily = XmlStyleFamily::SCH_CHART_ID;
510 else if ( IsXMLToken( rValue, XML_RUBY ) )
512 nFamily = XmlStyleFamily::TEXT_RUBY;
515 return nFamily;
518 rtl::Reference < SvXMLImportPropertyMapper > SvXMLStylesContext::GetImportPropertyMapper(
519 XmlStyleFamily nFamily ) const
521 rtl::Reference < SvXMLImportPropertyMapper > xMapper;
523 switch( nFamily )
525 case XmlStyleFamily::TEXT_PARAGRAPH:
526 if( !mxParaImpPropMapper.is() )
528 SvXMLStylesContext * pThis = const_cast<SvXMLStylesContext *>(this);
529 pThis->mxParaImpPropMapper =
530 pThis->GetImport().GetTextImport()
531 ->GetParaImportPropertySetMapper();
533 xMapper = mxParaImpPropMapper;
534 break;
535 case XmlStyleFamily::TEXT_TEXT:
536 if( !mxTextImpPropMapper.is() )
538 SvXMLStylesContext * pThis = const_cast<SvXMLStylesContext *>(this);
539 pThis->mxTextImpPropMapper =
540 pThis->GetImport().GetTextImport()
541 ->GetTextImportPropertySetMapper();
543 xMapper = mxTextImpPropMapper;
544 break;
546 case XmlStyleFamily::TEXT_SECTION:
547 // don't cache section mapper, as it's rarely used
548 // *sigh*, cast to non-const, because this is a const method,
549 // but SvXMLImport::GetTextImport() isn't.
550 xMapper = const_cast<SvXMLStylesContext*>(this)->GetImport().GetTextImport()->
551 GetSectionImportPropertySetMapper();
552 break;
554 case XmlStyleFamily::TEXT_RUBY:
555 // don't cache section mapper, as it's rarely used
556 // *sigh*, cast to non-const, because this is a const method,
557 // but SvXMLImport::GetTextImport() isn't.
558 xMapper = const_cast<SvXMLStylesContext*>(this)->GetImport().GetTextImport()->
559 GetRubyImportPropertySetMapper();
560 break;
562 case XmlStyleFamily::SD_GRAPHICS_ID:
563 case XmlStyleFamily::SD_PRESENTATION_ID:
564 case XmlStyleFamily::SD_POOL_ID:
565 if(!mxShapeImpPropMapper.is())
567 rtl::Reference< XMLShapeImportHelper > aImpHelper = const_cast<SvXMLImport&>(GetImport()).GetShapeImport();
568 const_cast<SvXMLStylesContext*>(this)->mxShapeImpPropMapper =
569 aImpHelper->GetPropertySetMapper();
571 xMapper = mxShapeImpPropMapper;
572 break;
573 #if !ENABLE_WASM_STRIP_CHART
574 // WASM_CHART change
575 case XmlStyleFamily::SCH_CHART_ID:
576 if( ! mxChartImpPropMapper.is() )
578 XMLPropertySetMapper *const pPropMapper = new XMLChartPropertySetMapper(nullptr);
579 mxChartImpPropMapper = new XMLChartImportPropertyMapper( pPropMapper, GetImport() );
581 xMapper = mxChartImpPropMapper;
582 break;
583 #endif
584 case XmlStyleFamily::PAGE_MASTER:
585 if( ! mxPageImpPropMapper.is() )
587 XMLPropertySetMapper *pPropMapper =
588 new XMLPageMasterPropSetMapper();
589 mxPageImpPropMapper =
590 new PageMasterImportPropertyMapper( pPropMapper,
591 const_cast<SvXMLStylesContext*>(this)->GetImport() );
593 xMapper = mxPageImpPropMapper;
594 break;
595 default: break;
598 return xMapper;
601 Reference < XAutoStyleFamily > SvXMLStylesContext::GetAutoStyles( XmlStyleFamily nFamily ) const
603 Reference < XAutoStyleFamily > xAutoStyles;
604 if( XmlStyleFamily::TEXT_TEXT == nFamily || XmlStyleFamily::TEXT_PARAGRAPH == nFamily)
606 bool bPara = XmlStyleFamily::TEXT_PARAGRAPH == nFamily;
607 if( !bPara && mxTextAutoStyles.is() )
608 xAutoStyles = mxTextAutoStyles;
609 else if( bPara && mxParaAutoStyles.is() )
610 xAutoStyles = mxParaAutoStyles;
611 else
613 OUString sName(bPara ? std::u16string_view( u"ParagraphStyles" ): std::u16string_view( u"CharacterStyles" ));
614 Reference< XAutoStylesSupplier > xAutoStylesSupp( GetImport().GetModel(), UNO_QUERY );
615 Reference< XAutoStyles > xAutoStyleFamilies = xAutoStylesSupp->getAutoStyles();
616 if (xAutoStyleFamilies->hasByName(sName))
618 Any aAny = xAutoStyleFamilies->getByName( sName );
619 aAny >>= xAutoStyles;
620 if( bPara )
621 const_cast<SvXMLStylesContext *>(this)->mxParaAutoStyles = xAutoStyles;
622 else
623 const_cast<SvXMLStylesContext *>(this)->mxTextAutoStyles = xAutoStyles;
627 return xAutoStyles;
630 Reference < XNameContainer > SvXMLStylesContext::GetStylesContainer(
631 XmlStyleFamily nFamily ) const
633 Reference < XNameContainer > xStyles;
634 OUString sName;
635 switch( nFamily )
637 case XmlStyleFamily::TEXT_PARAGRAPH:
638 if( mxParaStyles.is() )
639 xStyles = mxParaStyles;
640 else
641 sName = "ParagraphStyles";
642 break;
644 case XmlStyleFamily::TEXT_TEXT:
645 if( mxTextStyles.is() )
646 xStyles = mxTextStyles;
647 else
648 sName = "CharacterStyles";
649 break;
650 default: break;
652 if( !xStyles.is() && !sName.isEmpty() )
654 Reference< XStyleFamiliesSupplier > xFamiliesSupp(
655 GetImport().GetModel(), UNO_QUERY );
656 if ( xFamiliesSupp.is() )
658 Reference< XNameAccess > xFamilies = xFamiliesSupp->getStyleFamilies();
659 if (xFamilies->hasByName(sName))
661 xStyles.set(xFamilies->getByName( sName ),uno::UNO_QUERY);
663 switch( nFamily )
665 case XmlStyleFamily::TEXT_PARAGRAPH:
666 const_cast<SvXMLStylesContext *>(this)->mxParaStyles = xStyles;
667 break;
669 case XmlStyleFamily::TEXT_TEXT:
670 const_cast<SvXMLStylesContext *>(this)->mxTextStyles = xStyles;
671 break;
672 default: break;
678 return xStyles;
681 OUString SvXMLStylesContext::GetServiceName( XmlStyleFamily nFamily ) const
683 OUString sServiceName;
684 switch( nFamily )
686 case XmlStyleFamily::TEXT_PARAGRAPH:
687 sServiceName = gsParaStyleServiceName;
688 break;
689 case XmlStyleFamily::TEXT_TEXT:
690 sServiceName = gsTextStyleServiceName;
691 break;
692 default: break;
695 return sServiceName;
698 SvXMLStylesContext::SvXMLStylesContext( SvXMLImport& rImport, bool bAuto ) :
699 SvXMLImportContext( rImport ),
700 mpImpl( new SvXMLStylesContext_Impl( bAuto ) )
704 SvXMLStylesContext::~SvXMLStylesContext()
708 css::uno::Reference< css::xml::sax::XFastContextHandler > SvXMLStylesContext::createFastChildContext(
709 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
711 SvXMLStyleContext *pStyle =
712 CreateStyleChildContext( nElement, xAttrList );
713 if( pStyle )
715 if( !pStyle->IsTransient() )
716 mpImpl->AddStyle( pStyle );
717 return pStyle;
720 return nullptr;
723 void SvXMLStylesContext::AddStyle(SvXMLStyleContext& rNew)
725 mpImpl->AddStyle( &rNew );
728 void SvXMLStylesContext::dispose()
730 mpImpl->dispose();
733 void SvXMLStylesContext::CopyAutoStylesToDoc()
735 sal_uInt32 nCount = GetStyleCount();
736 sal_uInt32 i;
737 for( i = 0; i < nCount; i++ )
739 SvXMLStyleContext *pStyle = GetStyle( i );
740 if( !pStyle || ( pStyle->GetFamily() != XmlStyleFamily::TEXT_TEXT &&
741 pStyle->GetFamily() != XmlStyleFamily::TEXT_PARAGRAPH &&
742 pStyle->GetFamily() != XmlStyleFamily::TABLE_CELL ) )
743 continue;
744 pStyle->CreateAndInsert( false );
748 void SvXMLStylesContext::CopyStylesToDoc( bool bOverwrite,
749 bool bFinish )
751 // pass 1: create text, paragraph and frame styles
752 sal_uInt32 nCount = GetStyleCount();
753 sal_uInt32 i;
755 for( i = 0; i < nCount; i++ )
757 SvXMLStyleContext *pStyle = GetStyle( i );
758 if( !pStyle )
759 continue;
761 if (pStyle->IsDefaultStyle())
763 if (bOverwrite) pStyle->SetDefaults();
765 else if( InsertStyleFamily( pStyle->GetFamily() ) )
766 pStyle->CreateAndInsert( bOverwrite );
769 // pass 2: create list styles (they require char styles)
770 for( i=0; i<nCount; i++ )
772 SvXMLStyleContext *pStyle = GetStyle( i );
773 if( !pStyle || pStyle->IsDefaultStyle())
774 continue;
776 if( InsertStyleFamily( pStyle->GetFamily() ) )
777 pStyle->CreateAndInsertLate( bOverwrite );
780 // pass3: finish creation of styles
781 if( bFinish )
782 FinishStyles( bOverwrite );
785 void SvXMLStylesContext::FinishStyles( bool bOverwrite )
787 sal_uInt32 nCount = GetStyleCount();
788 for( sal_uInt32 i=0; i<nCount; i++ )
790 SvXMLStyleContext *pStyle = GetStyle( i );
791 if( !pStyle || !pStyle->IsValid() || pStyle->IsDefaultStyle() )
792 continue;
794 if( InsertStyleFamily( pStyle->GetFamily() ) )
795 pStyle->Finish( bOverwrite );
799 const SvXMLStyleContext *SvXMLStylesContext::FindStyleChildContext(
800 XmlStyleFamily nFamily,
801 const OUString& rName,
802 bool bCreateIndex ) const
804 return mpImpl->FindStyleChildContext( nFamily, rName, bCreateIndex );
807 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */