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 <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"
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 static SvXMLTokenMapEntry aStyleStylesElemTokenMap
[] =
67 { XML_NAMESPACE_STYLE
, XML_STYLE
, XML_TOK_STYLE_STYLE
},
68 { XML_NAMESPACE_STYLE
, XML_PAGE_LAYOUT
, XML_TOK_STYLE_PAGE_MASTER
},
69 { XML_NAMESPACE_TEXT
, XML_LIST_STYLE
, XML_TOK_TEXT_LIST_STYLE
},
70 { XML_NAMESPACE_TEXT
, XML_OUTLINE_STYLE
, XML_TOK_TEXT_OUTLINE
},
71 { XML_NAMESPACE_STYLE
, XML_DEFAULT_STYLE
, XML_TOK_STYLE_DEFAULT_STYLE
},
72 { XML_NAMESPACE_DRAW
, XML_GRADIENT
, XML_TOK_STYLES_GRADIENTSTYLES
},
73 { XML_NAMESPACE_DRAW
, XML_HATCH
, XML_TOK_STYLES_HATCHSTYLES
},
74 { XML_NAMESPACE_DRAW
, XML_FILL_IMAGE
, XML_TOK_STYLES_BITMAPSTYLES
},
75 { XML_NAMESPACE_DRAW
, XML_OPACITY
, XML_TOK_STYLES_TRANSGRADIENTSTYLES
},
76 { XML_NAMESPACE_DRAW
, XML_MARKER
, XML_TOK_STYLES_MARKERSTYLES
},
77 { XML_NAMESPACE_DRAW
, XML_STROKE_DASH
, XML_TOK_STYLES_DASHSTYLES
},
78 { XML_NAMESPACE_TEXT
, XML_NOTES_CONFIGURATION
, XML_TOK_TEXT_NOTE_CONFIG
},
79 { XML_NAMESPACE_TEXT
, XML_BIBLIOGRAPHY_CONFIGURATION
, XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG
},
80 { XML_NAMESPACE_TEXT
, XML_LINENUMBERING_CONFIGURATION
,XML_TOK_TEXT_LINENUMBERING_CONFIG
},
81 { XML_NAMESPACE_STYLE
, XML_DEFAULT_PAGE_LAYOUT
, XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT
},
85 const SvXMLTokenMap
& SvXMLStylesContext::GetStyleStylesElemTokenMap()
87 if( !mpStyleStylesElemTokenMap
)
88 mpStyleStylesElemTokenMap
=
89 new SvXMLTokenMap( aStyleStylesElemTokenMap
);
91 return *mpStyleStylesElemTokenMap
;
94 void SvXMLStyleContext::SetAttribute( sal_uInt16 nPrefixKey
,
95 const OUString
& rLocalName
,
96 const OUString
& rValue
)
98 // TODO: use a map here
99 if( XML_NAMESPACE_STYLE
== nPrefixKey
)
101 if( IsXMLToken( rLocalName
, XML_FAMILY
) )
103 if( IsXMLToken( rValue
, XML_PARAGRAPH
) )
104 mnFamily
= (sal_uInt16
)SFX_STYLE_FAMILY_PARA
;
105 else if( IsXMLToken( rValue
, XML_TEXT
) )
106 mnFamily
= (sal_uInt16
)SFX_STYLE_FAMILY_CHAR
;
108 else if( IsXMLToken( rLocalName
, XML_NAME
) )
112 else if( IsXMLToken( rLocalName
, XML_DISPLAY_NAME
) )
114 maDisplayName
= rValue
;
116 else if( IsXMLToken( rLocalName
, XML_PARENT_STYLE_NAME
) )
118 maParentName
= rValue
;
120 else if( IsXMLToken( rLocalName
, XML_NEXT_STYLE_NAME
) )
124 else if( IsXMLToken( rLocalName
, XML_HELP_FILE_NAME
) )
128 else if( IsXMLToken( rLocalName
, XML_HELP_ID
) )
130 sal_Int32 nTmp
= rValue
.toInt32();
132 (nTmp
< 0L) ? 0U : ( (nTmp
> USHRT_MAX
) ? USHRT_MAX
133 : (sal_uInt16
)nTmp
);
135 else if( IsXMLToken( rLocalName
, XML_HIDDEN
) )
137 mbHidden
= rValue
.toBoolean();
142 TYPEINIT1( SvXMLStyleContext
, SvXMLImportContext
);
144 SvXMLStyleContext::SvXMLStyleContext(
145 SvXMLImport
& rImp
, sal_uInt16 nPrfx
,
146 const OUString
& rLName
,
147 const uno::Reference
< xml::sax::XAttributeList
>&,
148 sal_uInt16 nFam
, bool bDefault
) :
149 SvXMLImportContext( rImp
, nPrfx
, rLName
),
151 mnHelpId( UCHAR_MAX
),
155 mbDefaultStyle( bDefault
)
159 SvXMLStyleContext::~SvXMLStyleContext()
163 SvXMLImportContext
*SvXMLStyleContext::CreateChildContext( sal_uInt16 nPrefix
,
164 const OUString
& rLocalName
,
165 const uno::Reference
< xml::sax::XAttributeList
> & )
167 return new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
170 void SvXMLStyleContext::StartElement( const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
172 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
173 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
175 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
177 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
, &aLocalName
);
178 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
180 SetAttribute( nPrefix
, aLocalName
, rValue
);
184 void SvXMLStyleContext::SetDefaults()
188 void SvXMLStyleContext::CreateAndInsert( bool /*bOverwrite*/ )
192 void SvXMLStyleContext::CreateAndInsertLate( bool /*bOverwrite*/ )
196 void SvXMLStyleContext::Finish( bool /*bOverwrite*/ )
200 bool SvXMLStyleContext::IsTransient() const
205 class SvXMLStyleIndex_Impl
209 const SvXMLStyleContext
*pStyle
;
213 SvXMLStyleIndex_Impl( sal_uInt16 nFam
, const OUString
& rName
) :
220 SvXMLStyleIndex_Impl( const SvXMLStyleContext
*pStl
) :
221 sName( pStl
->GetName() ),
222 nFamily( pStl
->GetFamily() ),
227 const OUString
& GetName() const { return sName
; }
228 sal_uInt16
GetFamily() const { return nFamily
; }
229 const SvXMLStyleContext
*GetStyle() const { return pStyle
; }
232 struct SvXMLStyleIndexCmp_Impl
234 bool operator()(const SvXMLStyleIndex_Impl
& r1
, const SvXMLStyleIndex_Impl
& r2
) const
238 if( (sal_uInt16
)r1
.GetFamily() < (sal_uInt16
)r2
.GetFamily() )
240 else if( (sal_uInt16
)r1
.GetFamily() > (sal_uInt16
)r2
.GetFamily() )
243 nRet
= r1
.GetName().compareTo( r2
.GetName() );
249 class SvXMLStylesContext_Impl
251 typedef std::vector
<SvXMLStyleContext
*> StylesType
;
252 typedef std::set
<SvXMLStyleIndex_Impl
, SvXMLStyleIndexCmp_Impl
> IndicesType
;
255 mutable IndicesType
* pIndices
;
256 bool bAutomaticStyle
;
258 #if OSL_DEBUG_LEVEL > 0
259 mutable sal_uInt32 m_nIndexCreated
;
262 void FlushIndex() { delete pIndices
; pIndices
= 0; }
265 SvXMLStylesContext_Impl( bool bAuto
);
266 ~SvXMLStylesContext_Impl();
268 size_t GetStyleCount() const { return aStyles
.size(); }
270 SvXMLStyleContext
*GetStyle( size_t i
)
272 return i
< aStyles
.size() ? aStyles
[ i
] : 0;
275 inline void AddStyle( SvXMLStyleContext
*pStyle
);
278 const SvXMLStyleContext
*FindStyleChildContext( sal_uInt16 nFamily
,
279 const OUString
& rName
,
280 bool bCreateIndex
) const;
281 bool IsAutomaticStyle() const { return bAutomaticStyle
; }
284 SvXMLStylesContext_Impl::SvXMLStylesContext_Impl( bool bAuto
) :
286 bAutomaticStyle( bAuto
)
287 #if OSL_DEBUG_LEVEL > 0
288 , m_nIndexCreated( 0 )
292 SvXMLStylesContext_Impl::~SvXMLStylesContext_Impl()
296 for ( size_t i
= 0, n
= aStyles
.size(); i
< n
; ++i
)
298 SvXMLStyleContext
*pStyle
= aStyles
[ i
];
299 pStyle
->ReleaseRef();
304 inline void SvXMLStylesContext_Impl::AddStyle( SvXMLStyleContext
*pStyle
)
306 aStyles
.push_back( pStyle
);
307 pStyle
->AddFirstRef();
312 void SvXMLStylesContext_Impl::Clear()
316 for ( size_t i
= 0, n
= aStyles
.size(); i
< n
; ++i
)
318 SvXMLStyleContext
*pStyle
= aStyles
[ i
];
319 pStyle
->ReleaseRef();
324 const SvXMLStyleContext
*SvXMLStylesContext_Impl::FindStyleChildContext( sal_uInt16 nFamily
,
325 const OUString
& rName
,
326 bool bCreateIndex
) const
328 const SvXMLStyleContext
*pStyle
= 0;
330 if( !pIndices
&& bCreateIndex
&& !aStyles
.empty() )
332 pIndices
= new IndicesType(aStyles
.begin(), aStyles
.end());
333 SAL_WARN_IF(pIndices
->size() != aStyles
.size(), "xmloff", "Here is a duplicate Style");
334 #if OSL_DEBUG_LEVEL > 0
335 SAL_WARN_IF(0 != m_nIndexCreated
, "xmloff.style",
336 "Performance warning: sdbcx::Index created multiple times");
343 SvXMLStyleIndex_Impl
aIndex( nFamily
, rName
);
344 IndicesType::iterator aFind
= pIndices
->find(aIndex
);
345 if( aFind
!= pIndices
->end() )
346 pStyle
= aFind
->GetStyle();
350 for( size_t i
= 0; !pStyle
&& i
< aStyles
.size(); i
++ )
352 const SvXMLStyleContext
*pS
= aStyles
[ i
];
353 if( pS
->GetFamily() == nFamily
&&
354 pS
->GetName() == rName
)
361 TYPEINIT1( SvXMLStylesContext
, SvXMLImportContext
);
363 sal_uInt32
SvXMLStylesContext::GetStyleCount() const
365 return mpImpl
->GetStyleCount();
368 SvXMLStyleContext
*SvXMLStylesContext::GetStyle( sal_uInt32 i
)
370 return mpImpl
->GetStyle( i
);
373 const SvXMLStyleContext
*SvXMLStylesContext::GetStyle( sal_uInt32 i
) const
375 return mpImpl
->GetStyle( i
);
378 bool SvXMLStylesContext::IsAutomaticStyle() const
380 return mpImpl
->IsAutomaticStyle();
383 SvXMLStyleContext
*SvXMLStylesContext::CreateStyleChildContext( sal_uInt16 p_nPrefix
,
384 const OUString
& rLocalName
,
385 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
387 SvXMLStyleContext
*pStyle
= NULL
;
389 if(GetImport().GetDataStylesImport())
391 pStyle
= GetImport().GetDataStylesImport()->CreateChildContext(GetImport(), p_nPrefix
,
392 rLocalName
, xAttrList
, *this);
397 const SvXMLTokenMap
& rTokenMap
= GetStyleStylesElemTokenMap();
398 sal_uInt16 nToken
= rTokenMap
.Get( p_nPrefix
, rLocalName
);
401 case XML_TOK_STYLE_STYLE
:
402 case XML_TOK_STYLE_DEFAULT_STYLE
:
404 sal_uInt16 nFamily
= 0;
405 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
406 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
408 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
411 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
413 if( XML_NAMESPACE_STYLE
== nPrefix
&&
414 IsXMLToken( aLocalName
, XML_FAMILY
) )
416 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
417 nFamily
= GetFamily( rValue
);
421 pStyle
= XML_TOK_STYLE_STYLE
==nToken
422 ? CreateStyleStyleChildContext( nFamily
, p_nPrefix
,
423 rLocalName
, xAttrList
)
424 : CreateDefaultStyleStyleChildContext( nFamily
, p_nPrefix
,
425 rLocalName
, xAttrList
);
428 case XML_TOK_STYLE_PAGE_MASTER
:
429 case XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT
:
431 //there is not page family in ODF now, so I specify one for it
432 bool bDefaultStyle
= XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT
== nToken
;
433 pStyle
= new PageStyleContext( GetImport(), p_nPrefix
,
434 rLocalName
, xAttrList
, *this, bDefaultStyle
);
437 case XML_TOK_TEXT_LIST_STYLE
:
438 pStyle
= new SvxXMLListStyleContext( GetImport(), p_nPrefix
,
439 rLocalName
, xAttrList
);
441 case XML_TOK_TEXT_OUTLINE
:
442 pStyle
= new SvxXMLListStyleContext( GetImport(), p_nPrefix
,
443 rLocalName
, xAttrList
, true );
445 case XML_TOK_TEXT_NOTE_CONFIG
:
446 pStyle
= new XMLFootnoteConfigurationImportContext(GetImport(),
452 case XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG
:
453 pStyle
= new XMLIndexBibliographyConfigurationContext(
454 GetImport(), p_nPrefix
, rLocalName
, xAttrList
);
457 case XML_TOK_TEXT_LINENUMBERING_CONFIG
:
458 pStyle
= new XMLLineNumberingImportContext(
459 GetImport(), p_nPrefix
, rLocalName
, xAttrList
);
465 case XML_TOK_STYLES_GRADIENTSTYLES
:
467 pStyle
= new XMLGradientStyleContext( GetImport(), p_nPrefix
, rLocalName
, xAttrList
);
470 case XML_TOK_STYLES_HATCHSTYLES
:
472 pStyle
= new XMLHatchStyleContext( GetImport(), p_nPrefix
, rLocalName
, xAttrList
);
475 case XML_TOK_STYLES_BITMAPSTYLES
:
477 pStyle
= new XMLBitmapStyleContext( GetImport(), p_nPrefix
, rLocalName
, xAttrList
);
480 case XML_TOK_STYLES_TRANSGRADIENTSTYLES
:
482 pStyle
= new XMLTransGradientStyleContext( GetImport(), p_nPrefix
, rLocalName
, xAttrList
);
485 case XML_TOK_STYLES_MARKERSTYLES
:
487 pStyle
= new XMLMarkerStyleContext( GetImport(), p_nPrefix
, rLocalName
, xAttrList
);
490 case XML_TOK_STYLES_DASHSTYLES
:
492 pStyle
= new XMLDashStyleContext( GetImport(), p_nPrefix
, rLocalName
, xAttrList
);
501 SvXMLStyleContext
*SvXMLStylesContext::CreateStyleStyleChildContext(
502 sal_uInt16 nFamily
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
503 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
505 SvXMLStyleContext
*pStyle
= 0;
509 case XML_STYLE_FAMILY_TEXT_PARAGRAPH
:
510 case XML_STYLE_FAMILY_TEXT_TEXT
:
511 case XML_STYLE_FAMILY_TEXT_SECTION
:
512 pStyle
= new XMLTextStyleContext( GetImport(), nPrefix
, rLocalName
,
513 xAttrList
, *this, nFamily
);
516 case XML_STYLE_FAMILY_TEXT_RUBY
:
517 pStyle
= new XMLPropStyleContext( GetImport(), nPrefix
, rLocalName
,
518 xAttrList
, *this, nFamily
);
520 case XML_STYLE_FAMILY_SCH_CHART_ID
:
521 pStyle
= new XMLChartStyleContext( GetImport(), nPrefix
, rLocalName
,
522 xAttrList
, *this, nFamily
);
525 case XML_STYLE_FAMILY_SD_GRAPHICS_ID
:
526 case XML_STYLE_FAMILY_SD_PRESENTATION_ID
:
527 case XML_STYLE_FAMILY_SD_POOL_ID
:
528 pStyle
= new XMLShapeStyleContext( GetImport(), nPrefix
, rLocalName
,
529 xAttrList
, *this, nFamily
);
535 SvXMLStyleContext
*SvXMLStylesContext::CreateDefaultStyleStyleChildContext(
536 sal_uInt16
/*nFamily*/, sal_uInt16
/*nPrefix*/, const OUString
& /*rLocalName*/,
537 const uno::Reference
< xml::sax::XAttributeList
> & )
542 bool SvXMLStylesContext::InsertStyleFamily( sal_uInt16
) const
547 sal_uInt16
SvXMLStylesContext::GetFamily( const OUString
& rValue
) const
549 sal_uInt16 nFamily
= 0U;
550 if( IsXMLToken( rValue
, XML_PARAGRAPH
) )
552 nFamily
= XML_STYLE_FAMILY_TEXT_PARAGRAPH
;
554 else if( IsXMLToken( rValue
, XML_TEXT
) )
556 nFamily
= XML_STYLE_FAMILY_TEXT_TEXT
;
558 else if( IsXMLToken( rValue
, XML_DATA_STYLE
) )
560 nFamily
= XML_STYLE_FAMILY_DATA_STYLE
;
562 else if ( IsXMLToken( rValue
, XML_SECTION
) )
564 nFamily
= XML_STYLE_FAMILY_TEXT_SECTION
;
566 else if( IsXMLToken( rValue
, XML_TABLE
) )
568 nFamily
= XML_STYLE_FAMILY_TABLE_TABLE
;
570 else if( IsXMLToken( rValue
, XML_TABLE_COLUMN
) )
571 nFamily
= XML_STYLE_FAMILY_TABLE_COLUMN
;
572 else if( IsXMLToken( rValue
, XML_TABLE_ROW
) )
573 nFamily
= XML_STYLE_FAMILY_TABLE_ROW
;
574 else if( IsXMLToken( rValue
, XML_TABLE_CELL
) )
575 nFamily
= XML_STYLE_FAMILY_TABLE_CELL
;
576 else if ( rValue
== XML_STYLE_FAMILY_SD_GRAPHICS_NAME
)
578 nFamily
= XML_STYLE_FAMILY_SD_GRAPHICS_ID
;
580 else if ( rValue
== XML_STYLE_FAMILY_SD_PRESENTATION_NAME
)
582 nFamily
= XML_STYLE_FAMILY_SD_PRESENTATION_ID
;
584 else if ( rValue
== XML_STYLE_FAMILY_SD_POOL_NAME
)
586 nFamily
= XML_STYLE_FAMILY_SD_POOL_ID
;
588 else if ( rValue
== XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME
)
590 nFamily
= XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID
;
592 else if ( rValue
== XML_STYLE_FAMILY_SCH_CHART_NAME
)
594 nFamily
= XML_STYLE_FAMILY_SCH_CHART_ID
;
596 else if ( IsXMLToken( rValue
, XML_RUBY
) )
598 nFamily
= XML_STYLE_FAMILY_TEXT_RUBY
;
604 rtl::Reference
< SvXMLImportPropertyMapper
> SvXMLStylesContext::GetImportPropertyMapper(
605 sal_uInt16 nFamily
) const
607 rtl::Reference
< SvXMLImportPropertyMapper
> xMapper
;
611 case XML_STYLE_FAMILY_TEXT_PARAGRAPH
:
612 if( !mxParaImpPropMapper
.is() )
614 SvXMLStylesContext
* pThis
= const_cast<SvXMLStylesContext
*>(this);
615 pThis
->mxParaImpPropMapper
=
616 pThis
->GetImport().GetTextImport()
617 ->GetParaImportPropertySetMapper();
619 xMapper
= mxParaImpPropMapper
;
621 case XML_STYLE_FAMILY_TEXT_TEXT
:
622 if( !mxTextImpPropMapper
.is() )
624 SvXMLStylesContext
* pThis
= const_cast<SvXMLStylesContext
*>(this);
625 pThis
->mxTextImpPropMapper
=
626 pThis
->GetImport().GetTextImport()
627 ->GetTextImportPropertySetMapper();
629 xMapper
= mxTextImpPropMapper
;
632 case XML_STYLE_FAMILY_TEXT_SECTION
:
633 // don't cache section mapper, as it's rarely used
634 // *sigh*, cast to non-const, because this is a const method,
635 // but SvXMLImport::GetTextImport() isn't.
636 xMapper
= const_cast<SvXMLStylesContext
*>(this)->GetImport().GetTextImport()->
637 GetSectionImportPropertySetMapper();
640 case XML_STYLE_FAMILY_TEXT_RUBY
:
641 // don't cache section mapper, as it's rarely used
642 // *sigh*, cast to non-const, because this is a const method,
643 // but SvXMLImport::GetTextImport() isn't.
644 xMapper
= const_cast<SvXMLStylesContext
*>(this)->GetImport().GetTextImport()->
645 GetRubyImportPropertySetMapper();
648 case XML_STYLE_FAMILY_SD_GRAPHICS_ID
:
649 case XML_STYLE_FAMILY_SD_PRESENTATION_ID
:
650 case XML_STYLE_FAMILY_SD_POOL_ID
:
651 if(!mxShapeImpPropMapper
.is())
653 rtl::Reference
< XMLShapeImportHelper
> aImpHelper
= ((SvXMLImport
&)GetImport()).GetShapeImport();
654 const_cast<SvXMLStylesContext
*>(this)->mxShapeImpPropMapper
=
655 aImpHelper
->GetPropertySetMapper();
657 xMapper
= mxShapeImpPropMapper
;
659 case XML_STYLE_FAMILY_SCH_CHART_ID
:
660 if( ! mxChartImpPropMapper
.is() )
662 XMLPropertySetMapper
*pPropMapper
= new XMLChartPropertySetMapper( false );
663 mxChartImpPropMapper
= new XMLChartImportPropertyMapper( pPropMapper
, GetImport() );
665 xMapper
= mxChartImpPropMapper
;
667 case XML_STYLE_FAMILY_PAGE_MASTER
:
668 if( ! mxPageImpPropMapper
.is() )
670 XMLPropertySetMapper
*pPropMapper
=
671 new XMLPageMasterPropSetMapper( false );
672 mxPageImpPropMapper
=
673 new PageMasterImportPropertyMapper( pPropMapper
,
674 const_cast<SvXMLStylesContext
*>(this)->GetImport() );
676 xMapper
= mxPageImpPropMapper
;
683 Reference
< XAutoStyleFamily
> SvXMLStylesContext::GetAutoStyles( sal_uInt16 nFamily
) const
685 Reference
< XAutoStyleFamily
> xAutoStyles
;
686 if( XML_STYLE_FAMILY_TEXT_TEXT
== nFamily
|| XML_STYLE_FAMILY_TEXT_PARAGRAPH
== nFamily
)
688 bool bPara
= XML_STYLE_FAMILY_TEXT_PARAGRAPH
== nFamily
;
690 if( !bPara
&& mxTextAutoStyles
.is() )
691 xAutoStyles
= mxTextAutoStyles
;
692 else if( bPara
&& mxParaAutoStyles
.is() )
693 xAutoStyles
= mxParaAutoStyles
;
696 sName
= bPara
? OUString( "ParagraphStyles" ): OUString( "CharacterStyles" );
697 Reference
< XAutoStylesSupplier
> xAutoStylesSupp( GetImport().GetModel(), UNO_QUERY
);
698 Reference
< XAutoStyles
> xAutoStyleFamilies
= xAutoStylesSupp
->getAutoStyles();
699 if (xAutoStyleFamilies
->hasByName(sName
))
701 Any aAny
= xAutoStyleFamilies
->getByName( sName
);
702 xAutoStyles
= *static_cast<Reference
<XAutoStyleFamily
> const *>(aAny
.getValue());
704 const_cast<SvXMLStylesContext
*>(this)->mxParaAutoStyles
= xAutoStyles
;
706 const_cast<SvXMLStylesContext
*>(this)->mxTextAutoStyles
= xAutoStyles
;
713 Reference
< XNameContainer
> SvXMLStylesContext::GetStylesContainer(
714 sal_uInt16 nFamily
) const
716 Reference
< XNameContainer
> xStyles
;
720 case XML_STYLE_FAMILY_TEXT_PARAGRAPH
:
721 if( mxParaStyles
.is() )
722 xStyles
= mxParaStyles
;
724 sName
= "ParagraphStyles";
727 case XML_STYLE_FAMILY_TEXT_TEXT
:
728 if( mxTextStyles
.is() )
729 xStyles
= mxTextStyles
;
731 sName
= "CharacterStyles";
734 if( !xStyles
.is() && !sName
.isEmpty() )
736 Reference
< XStyleFamiliesSupplier
> xFamiliesSupp(
737 GetImport().GetModel(), UNO_QUERY
);
738 if ( xFamiliesSupp
.is() )
740 Reference
< XNameAccess
> xFamilies
= xFamiliesSupp
->getStyleFamilies();
741 if (xFamilies
->hasByName(sName
))
743 xStyles
.set(xFamilies
->getByName( sName
),uno::UNO_QUERY
);
747 case XML_STYLE_FAMILY_TEXT_PARAGRAPH
:
748 const_cast<SvXMLStylesContext
*>(this)->mxParaStyles
= xStyles
;
751 case XML_STYLE_FAMILY_TEXT_TEXT
:
752 const_cast<SvXMLStylesContext
*>(this)->mxTextStyles
= xStyles
;
762 OUString
SvXMLStylesContext::GetServiceName( sal_uInt16 nFamily
) const
764 OUString sServiceName
;
767 case XML_STYLE_FAMILY_TEXT_PARAGRAPH
:
768 sServiceName
= msParaStyleServiceName
;
770 case XML_STYLE_FAMILY_TEXT_TEXT
:
771 sServiceName
= msTextStyleServiceName
;
778 SvXMLStylesContext::SvXMLStylesContext( SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
779 const OUString
& rLName
,
780 const uno::Reference
< xml::sax::XAttributeList
> &, bool bAuto
) :
781 SvXMLImportContext( rImport
, nPrfx
, rLName
),
782 msParaStyleServiceName( "com.sun.star.style.ParagraphStyle" ),
783 msTextStyleServiceName( "com.sun.star.style.CharacterStyle" ),
784 mpImpl( new SvXMLStylesContext_Impl( bAuto
) ),
785 mpStyleStylesElemTokenMap( 0 )
789 SvXMLStylesContext::~SvXMLStylesContext()
791 delete mpStyleStylesElemTokenMap
;
795 SvXMLImportContext
*SvXMLStylesContext::CreateChildContext( sal_uInt16 nPrefix
,
796 const OUString
& rLocalName
,
797 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
799 SvXMLImportContext
*pContext
= 0;
801 SvXMLStyleContext
*pStyle
=
802 CreateStyleChildContext( nPrefix
, rLocalName
, xAttrList
);
805 if( !pStyle
->IsTransient() )
806 mpImpl
->AddStyle( pStyle
);
811 pContext
= new SvXMLImportContext( GetImport(), nPrefix
,
818 void SvXMLStylesContext::EndElement()
822 void SvXMLStylesContext::AddStyle(SvXMLStyleContext
& rNew
)
824 mpImpl
->AddStyle( &rNew
);
827 void SvXMLStylesContext::Clear()
832 void SvXMLStylesContext::CopyAutoStylesToDoc()
834 sal_uInt32 nCount
= GetStyleCount();
836 for( i
= 0; i
< nCount
; i
++ )
838 SvXMLStyleContext
*pStyle
= GetStyle( i
);
839 if( !pStyle
|| ( pStyle
->GetFamily() != XML_STYLE_FAMILY_TEXT_TEXT
&&
840 pStyle
->GetFamily() != XML_STYLE_FAMILY_TEXT_PARAGRAPH
&&
841 pStyle
->GetFamily() != XML_STYLE_FAMILY_TABLE_CELL
) )
843 pStyle
->CreateAndInsert( false );
847 void SvXMLStylesContext::CopyStylesToDoc( bool bOverwrite
,
850 // pass 1: create text, paragraph and frame styles
851 sal_uInt32 nCount
= GetStyleCount();
854 for( i
= 0; i
< nCount
; i
++ )
856 SvXMLStyleContext
*pStyle
= GetStyle( i
);
860 if (pStyle
->IsDefaultStyle())
861 pStyle
->SetDefaults();
862 else if( InsertStyleFamily( pStyle
->GetFamily() ) )
863 pStyle
->CreateAndInsert( bOverwrite
);
866 // pass 2: create list styles (they require char styles)
867 for( i
=0; i
<nCount
; i
++ )
869 SvXMLStyleContext
*pStyle
= GetStyle( i
);
870 if( !pStyle
|| pStyle
->IsDefaultStyle())
873 if( InsertStyleFamily( pStyle
->GetFamily() ) )
874 pStyle
->CreateAndInsertLate( bOverwrite
);
877 // pass3: finish creation of styles
879 FinishStyles( bOverwrite
);
882 void SvXMLStylesContext::FinishStyles( bool bOverwrite
)
884 sal_uInt32 nCount
= GetStyleCount();
885 for( sal_uInt32 i
=0; i
<nCount
; i
++ )
887 SvXMLStyleContext
*pStyle
= GetStyle( i
);
888 if( !pStyle
|| !pStyle
->IsValid() || pStyle
->IsDefaultStyle() )
891 if( InsertStyleFamily( pStyle
->GetFamily() ) )
892 pStyle
->Finish( bOverwrite
);
896 const SvXMLStyleContext
*SvXMLStylesContext::FindStyleChildContext(
898 const OUString
& rName
,
899 bool bCreateIndex
) const
901 return mpImpl
->FindStyleChildContext( nFamily
, rName
, bCreateIndex
);
904 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */