1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/beans/XPropertySet.hpp>
25 #include <com/sun/star/frame/XModel.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 <com/sun/star/drawing/XDrawPageSupplier.hpp>
31 #include <PageMasterPropMapper.hxx>
33 #include <comphelper/diagnose_ex.hxx>
34 #include <sal/log.hxx>
35 #include <svl/style.hxx>
37 #include <xmloff/xmlnamespace.hxx>
38 #include <xmloff/xmltoken.hxx>
40 #include <xmloff/families.hxx>
41 #include <xmloff/xmlimp.hxx>
42 #include <xmloff/xmlnumi.hxx>
43 #include <xmloff/xmlimppr.hxx>
44 #include <xmloff/xmlstyle.hxx>
45 #include <xmloff/txtstyli.hxx>
46 #include <xmloff/xmlnumfi.hxx>
47 #include <XMLChartStyleContext.hxx>
48 #include <XMLChartPropertySetMapper.hxx>
49 #include <XMLThemeContext.hxx>
50 #include <xmloff/XMLShapeStyleContext.hxx>
51 #include "FillStyleContext.hxx"
52 #include <XMLFootnoteConfigurationImportContext.hxx>
53 #include <XMLIndexBibliographyConfigurationContext.hxx>
54 #include <XMLLineNumberingImportContext.hxx>
55 #include <PageMasterImportContext.hxx>
56 #include "PageMasterImportPropMapper.hxx"
60 #include <string_view>
63 using namespace ::com::sun::star
;
64 using namespace ::com::sun::star::uno
;
65 using namespace ::com::sun::star::container
;
66 using namespace ::com::sun::star::style
;
67 using namespace ::xmloff::token
;
69 constexpr OUStringLiteral
gsParaStyleServiceName( u
"com.sun.star.style.ParagraphStyle" );
70 constexpr OUStringLiteral
gsTextStyleServiceName( u
"com.sun.star.style.CharacterStyle" );
71 constexpr OUString
gsParagraphStyles(u
"ParagraphStyles"_ustr
);
72 constexpr OUString
gsCharacterStyles(u
"CharacterStyles"_ustr
);
74 void SvXMLStyleContext::SetAttribute( sal_Int32 nElement
,
75 const OUString
& rValue
)
79 case XML_ELEMENT(STYLE
, XML_FAMILY
):
81 if( IsXMLToken( rValue
, XML_PARAGRAPH
) )
82 mnFamily
= XmlStyleFamily(SfxStyleFamily::Para
);
83 else if( IsXMLToken( rValue
, XML_TEXT
) )
84 mnFamily
= XmlStyleFamily(SfxStyleFamily::Char
);
87 case XML_ELEMENT(STYLE
, XML_NAME
):
90 case XML_ELEMENT(STYLE
, XML_DISPLAY_NAME
):
91 maDisplayName
= rValue
;
93 case XML_ELEMENT(STYLE
, XML_PARENT_STYLE_NAME
):
94 maParentName
= rValue
;
96 case XML_ELEMENT(STYLE
, XML_NEXT_STYLE_NAME
):
99 case XML_ELEMENT(LO_EXT
, XML_LINKED_STYLE_NAME
):
102 case XML_ELEMENT(STYLE
, XML_HIDDEN
):
103 case XML_ELEMENT(LO_EXT
, XML_HIDDEN
):
104 mbHidden
= rValue
.toBoolean();
110 SvXMLStyleContext::SvXMLStyleContext(
112 XmlStyleFamily nFam
, bool bDefault
) :
113 SvXMLImportContext( rImp
),
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 for( auto &it
: sax_fastparser::castToFastAttributeList( xAttrList
) )
131 SetAttribute( it
.getToken(), it
.toString() );
134 void SvXMLStyleContext::SetDefaults()
138 void SvXMLStyleContext::CreateAndInsert( bool /*bOverwrite*/ )
142 void SvXMLStyleContext::CreateAndInsertLate( bool /*bOverwrite*/ )
146 void SvXMLStyleContext::Finish( bool /*bOverwrite*/ )
150 bool SvXMLStyleContext::IsTransient() const
156 struct StyleIndexCompareByName
158 bool operator()(const SvXMLStyleContext
* r1
, const SvXMLStyleContext
* r2
) const
160 if( r1
->GetFamily() < r2
->GetFamily() )
162 if( r1
->GetFamily() > r2
->GetFamily() )
164 return r1
->GetName() < r2
->GetName();
167 struct StyleIndexCompareByDisplayName
169 bool operator()(const SvXMLStyleContext
* r1
, const SvXMLStyleContext
* r2
) const
171 if( r1
->GetFamily() < r2
->GetFamily() )
173 if( r1
->GetFamily() > r2
->GetFamily() )
175 return r1
->GetDisplayName() < r2
->GetDisplayName();
180 class SvXMLStylesContext_Impl
182 std::vector
<rtl::Reference
<SvXMLStyleContext
>> aStyles
;
183 // it would be better if we could share one vector for the styles and the index, but some code in calc
184 // is sensitive to having styles re-ordered
185 mutable SvXMLStylesContext::StyleIndex maStylesIndexByName
;
186 mutable SvXMLStylesContext::StyleIndex maStylesIndexByDisplayName
;
187 bool bAutomaticStyle
;
189 #if OSL_DEBUG_LEVEL > 0
190 mutable sal_uInt32 m_nIndexCreated
;
194 explicit SvXMLStylesContext_Impl( bool bAuto
);
196 size_t GetStyleCount() const { return aStyles
.size(); }
198 SvXMLStyleContext
*GetStyle( size_t i
)
200 return i
< aStyles
.size() ? aStyles
[ i
].get() : nullptr;
203 inline void AddStyle( SvXMLStyleContext
*pStyle
);
206 const SvXMLStyleContext
*FindStyleChildContext( XmlStyleFamily nFamily
,
207 const OUString
& rName
,
208 bool bCreateIndex
) const;
210 std::pair
<SvXMLStylesContext::StyleIndex::const_iterator
, SvXMLStylesContext::StyleIndex::const_iterator
>
211 FindStyleChildContextByDisplayNamePrefix( XmlStyleFamily nFamily
,
212 const OUString
& rPrefix
) const;
214 bool IsAutomaticStyle() const { return bAutomaticStyle
; }
217 void BuildNameIndex() const;
218 void BuildDisplayNameIndex() const;
221 SvXMLStylesContext_Impl::SvXMLStylesContext_Impl( bool bAuto
) :
222 bAutomaticStyle( bAuto
)
223 #if OSL_DEBUG_LEVEL > 0
224 , m_nIndexCreated( 0 )
228 inline void SvXMLStylesContext_Impl::AddStyle( SvXMLStyleContext
*pStyle
)
230 #if OSL_DEBUG_LEVEL > 0
231 // for (auto const & xStyle : aStyles)
232 // if (xStyle->GetFamily() == pStyle->GetFamily() && xStyle->GetName() == pStyle->GetName())
233 // assert(false && "duplicate style");
235 aStyles
.emplace_back(pStyle
);
237 maStylesIndexByName
.clear();
238 maStylesIndexByDisplayName
.clear();
241 void SvXMLStylesContext_Impl::dispose()
246 const SvXMLStyleContext
*SvXMLStylesContext_Impl::FindStyleChildContext( XmlStyleFamily nFamily
,
247 const OUString
& rName
,
248 bool bCreateIndex
) const
250 const SvXMLStyleContext
*pStyle
= nullptr;
252 if( maStylesIndexByName
.empty() && bCreateIndex
&& !aStyles
.empty() )
255 if( !maStylesIndexByName
.empty() )
257 auto it
= std::lower_bound(maStylesIndexByName
.begin(), maStylesIndexByName
.end(), true,
258 [&nFamily
, &rName
](const SvXMLStyleContext
* lhs
, bool /*rhs*/)
260 if (lhs
->GetFamily() < nFamily
)
262 if (lhs
->GetFamily() > nFamily
)
264 return lhs
->GetName() < rName
;
266 if (it
!= maStylesIndexByName
.end() && (*it
)->GetFamily() == nFamily
&& (*it
)->GetName() == rName
)
271 for( size_t i
= 0; !pStyle
&& i
< aStyles
.size(); i
++ )
273 const SvXMLStyleContext
*pS
= aStyles
[ i
].get();
274 if( pS
->GetFamily() == nFamily
&&
275 pS
->GetName() == rName
)
284 struct PrefixProbeLowerBound
286 XmlStyleFamily nFamily
;
287 const OUString
& rPrefix
;
289 bool operator()(const SvXMLStyleContext
* lhs
, bool /*rhs*/)
291 if (lhs
->GetFamily() < nFamily
)
293 if (lhs
->GetFamily() > nFamily
)
295 return lhs
->GetDisplayName() < rPrefix
;
298 struct PrefixProbeUpperBound
300 XmlStyleFamily nFamily
;
301 const OUString
& rPrefix
;
303 bool operator()(bool /*lhs*/, const SvXMLStyleContext
* rhs
)
305 if (nFamily
< rhs
->GetFamily())
307 if (nFamily
> rhs
->GetFamily())
309 std::u16string_view rhsName
= rhs
->GetDisplayName();
310 // For the upper bound we want to view the vector's data as if
311 // every element was truncated to the size of the prefix.
312 // Then perform a normal match.
313 rhsName
= rhsName
.substr(0, rPrefix
.getLength());
314 // compare UP TO the length of the prefix and no farther
315 if (int cmp
= rPrefix
.compareTo(rhsName
))
317 // The strings are equal to the length of the prefix so
318 // behave as if they are equal. That means s1 < s2 == false
324 std::pair
<SvXMLStylesContext::StyleIndex::const_iterator
, SvXMLStylesContext::StyleIndex::const_iterator
>
325 SvXMLStylesContext_Impl::FindStyleChildContextByDisplayNamePrefix( XmlStyleFamily nFamily
,
326 const OUString
& rPrefix
) const
328 if( maStylesIndexByDisplayName
.empty() )
329 BuildDisplayNameIndex();
330 auto itStart
= std::lower_bound(maStylesIndexByDisplayName
.begin(), maStylesIndexByDisplayName
.end(), true, PrefixProbeLowerBound
{nFamily
,rPrefix
});
331 auto itEnd
= std::upper_bound(itStart
, maStylesIndexByDisplayName
.end(), true, PrefixProbeUpperBound
{nFamily
,rPrefix
});
332 return {itStart
, itEnd
};
335 void SvXMLStylesContext_Impl::BuildNameIndex() const
337 maStylesIndexByName
.reserve(aStyles
.size());
339 for (const auto & i
: aStyles
)
340 maStylesIndexByName
.push_back(i
.get());
341 std::sort(maStylesIndexByName
.begin(), maStylesIndexByName
.end(), StyleIndexCompareByName());
343 #if OSL_DEBUG_LEVEL > 0
344 SAL_WARN_IF(0 != m_nIndexCreated
, "xmloff.style",
345 "Performance warning: sdbcx::Index created multiple times");
350 void SvXMLStylesContext_Impl::BuildDisplayNameIndex() const
352 maStylesIndexByDisplayName
.reserve(aStyles
.size());
353 for (const auto & i
: aStyles
)
354 maStylesIndexByDisplayName
.push_back(i
.get());
355 std::sort(maStylesIndexByDisplayName
.begin(), maStylesIndexByDisplayName
.end(), StyleIndexCompareByDisplayName());
358 sal_uInt32
SvXMLStylesContext::GetStyleCount() const
360 return mpImpl
->GetStyleCount();
363 SvXMLStyleContext
*SvXMLStylesContext::GetStyle( sal_uInt32 i
)
365 return mpImpl
->GetStyle( i
);
368 const SvXMLStyleContext
*SvXMLStylesContext::GetStyle( sal_uInt32 i
) const
370 return mpImpl
->GetStyle( i
);
373 bool SvXMLStylesContext::IsAutomaticStyle() const
375 return mpImpl
->IsAutomaticStyle();
378 SvXMLStyleContext
*SvXMLStylesContext::CreateStyleChildContext(
380 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
382 SvXMLStyleContext
*pStyle
= nullptr;
384 if(GetImport().GetDataStylesImport())
386 pStyle
= GetImport().GetDataStylesImport()->CreateChildContext(GetImport(), nElement
,
394 case XML_ELEMENT(STYLE
, XML_STYLE
):
395 case XML_ELEMENT(STYLE
, XML_DEFAULT_STYLE
):
397 XmlStyleFamily nFamily
= XmlStyleFamily::DATA_STYLE
;
398 for( auto &aIter
: sax_fastparser::castToFastAttributeList( xAttrList
) )
400 if( aIter
.getToken() == XML_ELEMENT(STYLE
, XML_FAMILY
) )
402 nFamily
= GetFamily( aIter
.toString() );
406 pStyle
= XML_ELEMENT(STYLE
, XML_STYLE
)==nElement
407 ? CreateStyleStyleChildContext( nFamily
, nElement
, xAttrList
)
408 : CreateDefaultStyleStyleChildContext( nFamily
, nElement
, xAttrList
);
411 case XML_ELEMENT(TEXT
, XML_BIBLIOGRAPHY_CONFIGURATION
):
412 pStyle
= new XMLIndexBibliographyConfigurationContext(GetImport());
414 case XML_ELEMENT(TEXT
, XML_NOTES_CONFIGURATION
):
415 pStyle
= new XMLFootnoteConfigurationImportContext(
416 GetImport(), nElement
, xAttrList
);
418 case XML_ELEMENT(TEXT
, XML_LINENUMBERING_CONFIGURATION
):
419 pStyle
= new XMLLineNumberingImportContext(GetImport());
421 case XML_ELEMENT(STYLE
, XML_PAGE_LAYOUT
):
422 case XML_ELEMENT(STYLE
, XML_DEFAULT_PAGE_LAYOUT
):
424 //there is not page family in ODF now, so I specify one for it
425 bool bDefaultStyle
= XML_ELEMENT(STYLE
, XML_DEFAULT_PAGE_LAYOUT
) == nElement
;
426 pStyle
= new PageStyleContext( GetImport(), *this, bDefaultStyle
);
429 case XML_ELEMENT(TEXT
, XML_LIST_STYLE
):
430 pStyle
= new SvxXMLListStyleContext( GetImport() );
432 case XML_ELEMENT(TEXT
, XML_OUTLINE_STYLE
):
433 pStyle
= new SvxXMLListStyleContext( GetImport(), true );
438 case XML_ELEMENT(DRAW
, XML_GRADIENT
):
440 pStyle
= new XMLGradientStyleContext( GetImport(), nElement
, xAttrList
);
443 case XML_ELEMENT(DRAW
, XML_HATCH
):
445 pStyle
= new XMLHatchStyleContext( GetImport(), nElement
, xAttrList
);
448 case XML_ELEMENT(DRAW
, XML_FILL_IMAGE
):
450 pStyle
= new XMLBitmapStyleContext( GetImport(), nElement
, xAttrList
);
453 case XML_ELEMENT(DRAW
, XML_OPACITY
):
455 pStyle
= new XMLTransGradientStyleContext( GetImport(), nElement
, xAttrList
);
458 case XML_ELEMENT(DRAW
, XML_MARKER
):
460 pStyle
= new XMLMarkerStyleContext( GetImport(), nElement
, xAttrList
);
463 case XML_ELEMENT(DRAW
, XML_STROKE_DASH
):
465 pStyle
= new XMLDashStyleContext( GetImport(), nElement
, xAttrList
);
471 SAL_WARN("xmloff", "Unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement
));
476 SvXMLStyleContext
*SvXMLStylesContext::CreateStyleStyleChildContext(
477 XmlStyleFamily nFamily
, sal_Int32
/*nElement*/,
478 const uno::Reference
< xml::sax::XFastAttributeList
> & /*xAttrList*/ )
480 SvXMLStyleContext
*pStyle
= nullptr;
484 case XmlStyleFamily::TEXT_PARAGRAPH
:
485 case XmlStyleFamily::TEXT_TEXT
:
486 case XmlStyleFamily::TEXT_SECTION
:
487 pStyle
= new XMLTextStyleContext( GetImport(), *this, nFamily
);
490 case XmlStyleFamily::TEXT_RUBY
:
491 pStyle
= new XMLPropStyleContext( GetImport(), *this, nFamily
);
493 #if !ENABLE_WASM_STRIP_CHART
495 case XmlStyleFamily::SCH_CHART_ID
:
496 pStyle
= new XMLChartStyleContext( GetImport(), *this, nFamily
);
499 case XmlStyleFamily::SD_GRAPHICS_ID
:
500 case XmlStyleFamily::SD_PRESENTATION_ID
:
501 case XmlStyleFamily::SD_POOL_ID
:
502 pStyle
= new XMLShapeStyleContext( GetImport(), *this, nFamily
);
510 SvXMLStyleContext
*SvXMLStylesContext::CreateDefaultStyleStyleChildContext(
511 XmlStyleFamily
/*nFamily*/, sal_Int32
/*nElement*/,
512 const uno::Reference
< xml::sax::XFastAttributeList
> & )
517 bool SvXMLStylesContext::InsertStyleFamily( XmlStyleFamily
) const
522 XmlStyleFamily
SvXMLStylesContext::GetFamily( std::u16string_view rValue
)
524 XmlStyleFamily nFamily
= XmlStyleFamily::DATA_STYLE
;
525 if( IsXMLToken( rValue
, XML_PARAGRAPH
) )
527 nFamily
= XmlStyleFamily::TEXT_PARAGRAPH
;
529 else if( IsXMLToken( rValue
, XML_TEXT
) )
531 nFamily
= XmlStyleFamily::TEXT_TEXT
;
533 else if( IsXMLToken( rValue
, XML_DATA_STYLE
) )
535 nFamily
= XmlStyleFamily::DATA_STYLE
;
537 else if ( IsXMLToken( rValue
, XML_SECTION
) )
539 nFamily
= XmlStyleFamily::TEXT_SECTION
;
541 else if( IsXMLToken( rValue
, XML_TABLE
) )
543 nFamily
= XmlStyleFamily::TABLE_TABLE
;
545 else if( IsXMLToken( rValue
, XML_TABLE_COLUMN
) )
546 nFamily
= XmlStyleFamily::TABLE_COLUMN
;
547 else if( IsXMLToken( rValue
, XML_TABLE_ROW
) )
548 nFamily
= XmlStyleFamily::TABLE_ROW
;
549 else if( IsXMLToken( rValue
, XML_TABLE_CELL
) )
550 nFamily
= XmlStyleFamily::TABLE_CELL
;
551 else if ( rValue
== XML_STYLE_FAMILY_SD_GRAPHICS_NAME
)
553 nFamily
= XmlStyleFamily::SD_GRAPHICS_ID
;
555 else if ( rValue
== XML_STYLE_FAMILY_SD_PRESENTATION_NAME
)
557 nFamily
= XmlStyleFamily::SD_PRESENTATION_ID
;
559 else if ( rValue
== XML_STYLE_FAMILY_SD_POOL_NAME
)
561 nFamily
= XmlStyleFamily::SD_POOL_ID
;
563 else if ( rValue
== XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME
)
565 nFamily
= XmlStyleFamily::SD_DRAWINGPAGE_ID
;
567 else if ( rValue
== XML_STYLE_FAMILY_SCH_CHART_NAME
)
569 nFamily
= XmlStyleFamily::SCH_CHART_ID
;
571 else if ( IsXMLToken( rValue
, XML_RUBY
) )
573 nFamily
= XmlStyleFamily::TEXT_RUBY
;
579 rtl::Reference
< SvXMLImportPropertyMapper
> SvXMLStylesContext::GetImportPropertyMapper(
580 XmlStyleFamily nFamily
) const
582 rtl::Reference
< SvXMLImportPropertyMapper
> xMapper
;
586 case XmlStyleFamily::TEXT_PARAGRAPH
:
587 if( !mxParaImpPropMapper
.is() )
589 SvXMLStylesContext
* pThis
= const_cast<SvXMLStylesContext
*>(this);
590 pThis
->mxParaImpPropMapper
=
591 pThis
->GetImport().GetTextImport()
592 ->GetParaImportPropertySetMapper();
594 xMapper
= mxParaImpPropMapper
;
596 case XmlStyleFamily::TEXT_TEXT
:
597 if( !mxTextImpPropMapper
.is() )
599 SvXMLStylesContext
* pThis
= const_cast<SvXMLStylesContext
*>(this);
600 pThis
->mxTextImpPropMapper
=
601 pThis
->GetImport().GetTextImport()
602 ->GetTextImportPropertySetMapper();
604 xMapper
= mxTextImpPropMapper
;
607 case XmlStyleFamily::TEXT_SECTION
:
608 // don't cache section mapper, as it's rarely used
609 // *sigh*, cast to non-const, because this is a const method,
610 // but SvXMLImport::GetTextImport() isn't.
611 xMapper
= const_cast<SvXMLStylesContext
*>(this)->GetImport().GetTextImport()->
612 GetSectionImportPropertySetMapper();
615 case XmlStyleFamily::TEXT_RUBY
:
616 // don't cache section mapper, as it's rarely used
617 // *sigh*, cast to non-const, because this is a const method,
618 // but SvXMLImport::GetTextImport() isn't.
619 xMapper
= const_cast<SvXMLStylesContext
*>(this)->GetImport().GetTextImport()->
620 GetRubyImportPropertySetMapper();
623 case XmlStyleFamily::SD_GRAPHICS_ID
:
624 case XmlStyleFamily::SD_PRESENTATION_ID
:
625 case XmlStyleFamily::SD_POOL_ID
:
626 if(!mxShapeImpPropMapper
.is())
628 rtl::Reference
< XMLShapeImportHelper
> aImpHelper
= const_cast<SvXMLImport
&>(GetImport()).GetShapeImport();
629 const_cast<SvXMLStylesContext
*>(this)->mxShapeImpPropMapper
=
630 aImpHelper
->GetPropertySetMapper();
632 xMapper
= mxShapeImpPropMapper
;
634 #if !ENABLE_WASM_STRIP_CHART
636 case XmlStyleFamily::SCH_CHART_ID
:
637 if( ! mxChartImpPropMapper
.is() )
639 XMLPropertySetMapper
*const pPropMapper
= new XMLChartPropertySetMapper(nullptr);
640 mxChartImpPropMapper
= new XMLChartImportPropertyMapper( pPropMapper
, GetImport() );
642 xMapper
= mxChartImpPropMapper
;
645 case XmlStyleFamily::PAGE_MASTER
:
646 if( ! mxPageImpPropMapper
.is() )
648 XMLPropertySetMapper
*pPropMapper
=
649 new XMLPageMasterPropSetMapper();
650 mxPageImpPropMapper
=
651 new PageMasterImportPropertyMapper( pPropMapper
,
652 const_cast<SvXMLStylesContext
*>(this)->GetImport() );
654 xMapper
= mxPageImpPropMapper
;
662 Reference
< XAutoStyleFamily
> SvXMLStylesContext::GetAutoStyles( XmlStyleFamily nFamily
) const
664 Reference
< XAutoStyleFamily
> xAutoStyles
;
665 if( XmlStyleFamily::TEXT_TEXT
== nFamily
|| XmlStyleFamily::TEXT_PARAGRAPH
== nFamily
)
667 bool bPara
= XmlStyleFamily::TEXT_PARAGRAPH
== nFamily
;
668 const Reference
<XAutoStyleFamily
>& rxAutoStyles
= bPara
? mxParaAutoStyles
: mxTextAutoStyles
;
671 OUString
sName(bPara
? gsParagraphStyles
: gsCharacterStyles
);
672 Reference
< XAutoStylesSupplier
> xAutoStylesSupp( GetImport().GetModel(), UNO_QUERY
);
673 Reference
< XAutoStyles
> xAutoStyleFamilies
= xAutoStylesSupp
->getAutoStyles();
674 if (xAutoStyleFamilies
->hasByName(sName
))
676 Any aAny
= xAutoStyleFamilies
->getByName( sName
);
677 aAny
>>= const_cast<Reference
<XAutoStyleFamily
>&>(rxAutoStyles
);
680 xAutoStyles
= rxAutoStyles
;
685 Reference
< XNameContainer
> SvXMLStylesContext::GetStylesContainer(
686 XmlStyleFamily nFamily
) const
688 Reference
< XNameContainer
> xStyles
;
689 if (XmlStyleFamily::TEXT_TEXT
== nFamily
|| XmlStyleFamily::TEXT_PARAGRAPH
== nFamily
)
691 bool bPara
= XmlStyleFamily::TEXT_PARAGRAPH
== nFamily
;
692 const Reference
<XNameContainer
>& rxStyles
= bPara
? mxParaStyles
: mxTextStyles
;
695 OUString
sName(bPara
? gsParagraphStyles
: gsCharacterStyles
);
696 Reference
<XStyleFamiliesSupplier
> xFamiliesSupp(GetImport().GetModel(), UNO_QUERY
);
697 if (xFamiliesSupp
.is())
699 Reference
<XNameAccess
> xFamilies
= xFamiliesSupp
->getStyleFamilies();
700 if (xFamilies
->hasByName(sName
))
702 Any aAny
= xFamilies
->getByName(sName
);
703 aAny
>>= const_cast<Reference
<XNameContainer
>&>(rxStyles
);
713 OUString
SvXMLStylesContext::GetServiceName( XmlStyleFamily nFamily
) const
715 OUString sServiceName
;
718 case XmlStyleFamily::TEXT_PARAGRAPH
:
719 sServiceName
= gsParaStyleServiceName
;
721 case XmlStyleFamily::TEXT_TEXT
:
722 sServiceName
= gsTextStyleServiceName
;
730 SvXMLStylesContext::SvXMLStylesContext( SvXMLImport
& rImport
, bool bAuto
) :
731 SvXMLImportContext( rImport
),
732 mpImpl( new SvXMLStylesContext_Impl( bAuto
) )
736 SvXMLStylesContext::~SvXMLStylesContext()
740 css::uno::Reference
< css::xml::sax::XFastContextHandler
> SvXMLStylesContext::createFastChildContext(
741 sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
743 if (nElement
== XML_ELEMENT(LO_EXT
, XML_THEME
))
745 if (auto xImportInfo
= GetImport().getImportInfo())
749 if (auto xPropertySetInfo
= xImportInfo
->getPropertySetInfo())
751 if (xPropertySetInfo
->hasPropertyByName(u
"IsInPaste"_ustr
))
753 css::uno::Any value
= xImportInfo
->getPropertyValue(u
"IsInPaste"_ustr
);
754 if (bool b
; (value
>>= b
) && b
)
755 return nullptr; // do not import themes in paste mode
759 catch (const css::uno::Exception
&)
761 DBG_UNHANDLED_EXCEPTION("xmloff");
765 uno::Reference
<uno::XInterface
> xObject(GetImport().GetModel(), uno::UNO_QUERY
);
766 uno::Reference
<drawing::XDrawPageSupplier
> const xDrawPageSupplier(GetImport().GetModel(), uno::UNO_QUERY
);
767 if (xDrawPageSupplier
.is())
769 uno::Reference
<drawing::XDrawPage
> xPage
= xDrawPageSupplier
->getDrawPage();
774 return new XMLThemeContext(GetImport(), xAttrList
, xObject
);
777 SvXMLStyleContext
* pStyle
= CreateStyleChildContext( nElement
, xAttrList
);
780 if (!pStyle
->IsTransient())
781 mpImpl
->AddStyle(pStyle
);
788 void SvXMLStylesContext::AddStyle(SvXMLStyleContext
& rNew
)
790 mpImpl
->AddStyle( &rNew
);
793 void SvXMLStylesContext::dispose()
798 void SvXMLStylesContext::CopyAutoStylesToDoc()
800 sal_uInt32 nCount
= GetStyleCount();
802 for( i
= 0; i
< nCount
; i
++ )
804 SvXMLStyleContext
*pStyle
= GetStyle( i
);
805 if( !pStyle
|| ( pStyle
->GetFamily() != XmlStyleFamily::TEXT_TEXT
&&
806 pStyle
->GetFamily() != XmlStyleFamily::TEXT_PARAGRAPH
&&
807 pStyle
->GetFamily() != XmlStyleFamily::TABLE_CELL
) )
809 pStyle
->CreateAndInsert( false );
813 void SvXMLStylesContext::CopyStylesToDoc( bool bOverwrite
,
816 // pass 1: create text, paragraph and frame styles
817 sal_uInt32 nCount
= GetStyleCount();
820 for( i
= 0; i
< nCount
; i
++ )
822 SvXMLStyleContext
*pStyle
= GetStyle( i
);
826 if (pStyle
->IsDefaultStyle())
828 if (bOverwrite
) pStyle
->SetDefaults();
830 else if( InsertStyleFamily( pStyle
->GetFamily() ) )
831 pStyle
->CreateAndInsert( bOverwrite
);
834 // pass 2: create list styles (they require char styles)
835 for( i
=0; i
<nCount
; i
++ )
837 SvXMLStyleContext
*pStyle
= GetStyle( i
);
838 if( !pStyle
|| pStyle
->IsDefaultStyle())
841 if( InsertStyleFamily( pStyle
->GetFamily() ) )
842 pStyle
->CreateAndInsertLate( bOverwrite
);
845 // pass3: finish creation of styles
847 FinishStyles( bOverwrite
);
850 void SvXMLStylesContext::FinishStyles( bool bOverwrite
)
852 sal_uInt32 nCount
= GetStyleCount();
853 for( sal_uInt32 i
=0; i
<nCount
; i
++ )
855 SvXMLStyleContext
*pStyle
= GetStyle( i
);
856 if( !pStyle
|| !pStyle
->IsValid() || pStyle
->IsDefaultStyle() )
859 if( InsertStyleFamily( pStyle
->GetFamily() ) )
860 pStyle
->Finish( bOverwrite
);
864 const SvXMLStyleContext
*SvXMLStylesContext::FindStyleChildContext(
865 XmlStyleFamily nFamily
,
866 const OUString
& rName
,
867 bool bCreateIndex
) const
869 return mpImpl
->FindStyleChildContext( nFamily
, rName
, bCreateIndex
);
872 std::pair
<SvXMLStylesContext::StyleIndex::const_iterator
, SvXMLStylesContext::StyleIndex::const_iterator
>
873 SvXMLStylesContext::FindStyleChildContextByDisplayNamePrefix(
874 XmlStyleFamily nFamily
,
875 const OUString
& rNamePrefix
) const
877 return mpImpl
->FindStyleChildContextByDisplayNamePrefix( nFamily
, rNamePrefix
);
880 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */