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 <rtl/ustrbuf.hxx>
22 #include <xmloff/nmspmap.hxx>
26 #include <poolfmt.hxx>
27 #include <charfmt.hxx>
31 #include "unostyle.hxx"
32 #include "fmtpdsc.hxx"
33 #include "pagedesc.hxx"
34 #include <xmloff/xmlnmspe.hxx>
35 #include <xmloff/i18nmap.hxx>
36 #include <xmloff/xmltkmap.hxx>
37 #include "xmlitem.hxx"
38 #include <xmloff/xmlstyle.hxx>
39 #include <xmloff/txtstyli.hxx>
40 #include <xmloff/txtimp.hxx>
41 #include <xmloff/families.hxx>
42 #include <xmloff/XMLTextMasterStylesContext.hxx>
43 #include <xmloff/XMLTextShapeStyleContext.hxx>
44 #include <xmloff/XMLGraphicsDefaultStyle.hxx>
46 #include "xmltbli.hxx"
47 #include "cellatr.hxx"
48 #include <SwStyleNameMapper.hxx>
49 #include <xmloff/attrlist.hxx>
50 #include <unotxdoc.hxx>
54 using namespace ::com::sun::star
;
55 using namespace ::xmloff::token
;
57 class SwXMLConditionParser_Impl
61 sal_uInt32 nCondition
;
62 sal_uInt32 nSubCondition
;
67 inline sal_Bool
SkipWS();
68 inline sal_Bool
MatchChar( sal_Unicode c
);
69 inline sal_Bool
MatchName( OUString
& rName
);
70 inline sal_Bool
MatchNumber( sal_uInt32
& rNumber
);
74 SwXMLConditionParser_Impl( const OUString
& rInp
);
76 bool IsValid() const { return 0 != nCondition
; }
78 sal_uInt32
GetCondition() const { return nCondition
; }
79 sal_uInt32
GetSubCondition() const { return nSubCondition
; }
82 inline sal_Bool
SwXMLConditionParser_Impl::SkipWS()
84 while( nPos
< nLength
&& ' ' == sInput
[nPos
] )
89 inline sal_Bool
SwXMLConditionParser_Impl::MatchChar( sal_Unicode c
)
91 sal_Bool bRet
= sal_False
;
92 if( nPos
< nLength
&& c
== sInput
[nPos
] )
100 inline sal_Bool
SwXMLConditionParser_Impl::MatchName( OUString
& rName
)
102 OUStringBuffer
sBuffer( nLength
);
103 while( nPos
< nLength
&&
104 ( ('a' <= sInput
[nPos
] && sInput
[nPos
] <= 'z') ||
105 '-' == sInput
[nPos
] ) )
107 sBuffer
.append( sInput
[nPos
] );
110 rName
= sBuffer
.makeStringAndClear();
111 return !rName
.isEmpty();
114 inline sal_Bool
SwXMLConditionParser_Impl::MatchNumber( sal_uInt32
& rNumber
)
116 OUStringBuffer
sBuffer( nLength
);
117 while( nPos
< nLength
&& '0' <= sInput
[nPos
] && sInput
[nPos
] <= '9' )
119 sBuffer
.append( sInput
[nPos
] );
123 OUString
sNum( sBuffer
.makeStringAndClear() );
124 if( !sNum
.isEmpty() )
125 rNumber
= sNum
.toInt32();
126 return !sNum
.isEmpty();
129 SwXMLConditionParser_Impl::SwXMLConditionParser_Impl( const OUString
& rInp
) :
134 nLength( rInp
.getLength() )
137 bool bHasSub
= false;
139 sal_Bool bOK
= SkipWS() && MatchName( sFunc
) && SkipWS() &&
140 MatchChar( '(' ) && SkipWS() && MatchChar( ')' ) && SkipWS();
141 if( bOK
&& MatchChar( '=' ) )
143 bOK
= SkipWS() && MatchNumber( nSub
) && SkipWS();
147 bOK
&= nPos
== nLength
;
151 if( IsXMLToken( sFunc
, XML_ENDNOTE
) && !bHasSub
)
152 nCondition
= PARA_IN_ENDNOTE
;
153 else if( IsXMLToken( sFunc
, XML_FOOTER
) && !bHasSub
)
154 nCondition
= PARA_IN_FOOTER
;
155 else if( IsXMLToken( sFunc
, XML_FOOTNOTE
) && !bHasSub
)
156 nCondition
= PARA_IN_FOOTENOTE
;
157 else if( IsXMLToken( sFunc
, XML_HEADER
) && !bHasSub
)
158 nCondition
= PARA_IN_HEADER
;
159 else if( IsXMLToken( sFunc
, XML_LIST_LEVEL
) &&
160 nSub
>=1 && nSub
<= MAXLEVEL
)
162 nCondition
= PARA_IN_LIST
;
163 nSubCondition
= nSub
-1;
165 else if( IsXMLToken( sFunc
, XML_OUTLINE_LEVEL
) &&
166 nSub
>=1 && nSub
<= MAXLEVEL
)
168 nCondition
= PARA_IN_OUTLINE
;
169 nSubCondition
= nSub
-1;
171 else if( IsXMLToken( sFunc
, XML_SECTION
) && !bHasSub
)
173 nCondition
= PARA_IN_SECTION
;
175 else if( IsXMLToken( sFunc
, XML_TABLE
) && !bHasSub
)
177 nCondition
= PARA_IN_TABLEBODY
;
179 else if( IsXMLToken( sFunc
, XML_TABLE_HEADER
) && !bHasSub
)
181 nCondition
= PARA_IN_TABLEHEAD
;
183 else if( IsXMLToken( sFunc
, XML_TEXT_BOX
) && !bHasSub
)
185 nCondition
= PARA_IN_FRAME
;
190 // ---------------------------------------------------------------------
192 class SwXMLConditionContext_Impl
: public SvXMLImportContext
194 sal_uInt32 nCondition
;
195 sal_uInt32 nSubCondition
;
197 OUString sApplyStyle
;
199 void ParseCondition( const OUString
& rCond
);
203 SwXMLConditionContext_Impl(
204 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
205 const OUString
& rLName
,
206 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
207 virtual ~SwXMLConditionContext_Impl();
211 bool IsValid() const { return 0 != nCondition
; }
213 sal_uInt32
GetCondition() const { return nCondition
; }
214 sal_uInt32
GetSubCondition() const { return nSubCondition
; }
215 const OUString
& GetApplyStyle() const { return sApplyStyle
; }
218 SwXMLConditionContext_Impl::SwXMLConditionContext_Impl(
219 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
220 const OUString
& rLName
,
221 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
) :
222 SvXMLImportContext( rImport
, nPrfx
, rLName
),
226 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
227 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
229 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
232 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
234 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
236 // TODO: use a map here
237 if( XML_NAMESPACE_STYLE
== nPrefix
)
239 if( IsXMLToken( aLocalName
, XML_CONDITION
) )
241 SwXMLConditionParser_Impl
aCondParser( rValue
);
242 if( aCondParser
.IsValid() )
244 nCondition
= aCondParser
.GetCondition();
245 nSubCondition
= aCondParser
.GetSubCondition();
248 else if( IsXMLToken( aLocalName
, XML_APPLY_STYLE_NAME
) )
250 sApplyStyle
= rValue
;
256 SwXMLConditionContext_Impl::~SwXMLConditionContext_Impl()
260 TYPEINIT1( SwXMLConditionContext_Impl
, XMLTextStyleContext
);
262 // ---------------------------------------------------------------------
264 typedef std::vector
<SwXMLConditionContext_Impl
*> SwXMLConditions_Impl
;
266 class SwXMLTextStyleContext_Impl
: public XMLTextStyleContext
268 SwXMLConditions_Impl
*pConditions
;
272 virtual uno::Reference
< style::XStyle
> Create();
278 SwXMLTextStyleContext_Impl( SwXMLImport
& rImport
, sal_uInt16 nPrfx
,
279 const OUString
& rLName
,
280 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
282 SvXMLStylesContext
& rStyles
);
283 virtual ~SwXMLTextStyleContext_Impl();
285 virtual SvXMLImportContext
*CreateChildContext(
287 const OUString
& rLocalName
,
288 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
290 virtual void Finish( sal_Bool bOverwrite
);
293 TYPEINIT1( SwXMLTextStyleContext_Impl
, XMLTextStyleContext
);
295 uno::Reference
< style::XStyle
> SwXMLTextStyleContext_Impl::Create()
297 uno::Reference
< style::XStyle
> xNewStyle
;
299 if( pConditions
&& XML_STYLE_FAMILY_TEXT_PARAGRAPH
== GetFamily() )
301 uno::Reference
< lang::XMultiServiceFactory
> xFactory( GetImport().GetModel(),
305 OUString
sServiceName(
306 "com.sun.star.style.ConditionalParagraphStyle" );
307 uno::Reference
< uno::XInterface
> xIfc
=
308 xFactory
->createInstance( sServiceName
);
310 xNewStyle
= uno::Reference
< style::XStyle
>( xIfc
, uno::UNO_QUERY
);
315 xNewStyle
= XMLTextStyleContext::Create();
321 SwXMLTextStyleContext_Impl::SwXMLTextStyleContext_Impl( SwXMLImport
& rImport
,
322 sal_uInt16 nPrfx
, const OUString
& rLName
,
323 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
325 SvXMLStylesContext
& rStyles
) :
326 XMLTextStyleContext( rImport
, nPrfx
, rLName
, xAttrList
, rStyles
, nFamily
),
331 SwXMLTextStyleContext_Impl::~SwXMLTextStyleContext_Impl()
335 while( !pConditions
->empty() )
337 SwXMLConditionContext_Impl
*pCond
= &*pConditions
->back();
338 pConditions
->pop_back();
345 SvXMLImportContext
*SwXMLTextStyleContext_Impl::CreateChildContext(
347 const OUString
& rLocalName
,
348 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
350 SvXMLImportContext
*pContext
= 0;
352 if( XML_NAMESPACE_STYLE
== nPrefix
&& IsXMLToken( rLocalName
, XML_MAP
) )
354 SwXMLConditionContext_Impl
*pCond
=
355 new SwXMLConditionContext_Impl( GetImport(), nPrefix
,
356 rLocalName
, xAttrList
);
357 if( pCond
->IsValid() )
360 pConditions
= new SwXMLConditions_Impl
;
361 pConditions
->push_back( pCond
);
368 pContext
= XMLTextStyleContext::CreateChildContext( nPrefix
, rLocalName
,
374 void SwXMLTextStyleContext_Impl::Finish( sal_Bool bOverwrite
)
376 XMLTextStyleContext::Finish( bOverwrite
);
378 if( !pConditions
|| XML_STYLE_FAMILY_TEXT_PARAGRAPH
!= GetFamily() )
381 uno::Reference
< style::XStyle
> xStyle
= GetStyle();
385 const SwXStyle
* pStyle
= 0;
386 uno::Reference
<lang::XUnoTunnel
> xStyleTunnel( xStyle
, uno::UNO_QUERY
);
387 if( xStyleTunnel
.is() )
389 pStyle
= reinterpret_cast< SwXStyle
* >(
390 sal::static_int_cast
< sal_IntPtr
>( xStyleTunnel
->getSomething( SwXStyle::getUnoTunnelId() )));
395 const SwDoc
*pDoc
= pStyle
->GetDoc();
397 SwTxtFmtColl
*pColl
= pDoc
->FindTxtFmtCollByName( pStyle
->GetStyleName() );
398 OSL_ENSURE( pColl
, "Text collection not found" );
399 if( !pColl
|| RES_CONDTXTFMTCOLL
!= pColl
->Which() )
402 sal_uInt16 nCount
= pConditions
->size();
405 for( sal_uInt16 i
= 0; i
< nCount
; i
++ )
407 const SwXMLConditionContext_Impl
*pCond
= (*pConditions
)[i
];
408 OUString
aDisplayName(
409 GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_PARAGRAPH
,
410 pCond
->GetApplyStyle() ) );
411 SwStyleNameMapper::FillUIName( aDisplayName
,
413 nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL
,
416 SwTxtFmtColl
* pCondColl
= pDoc
->FindTxtFmtCollByName( sName
);
417 OSL_ENSURE( pCondColl
,
418 "SwXMLItemSetStyleContext_Impl::ConnectConditions: cond coll missing" );
421 SwCollCondition
aCond( pCondColl
, pCond
->GetCondition(),
422 pCond
->GetSubCondition() );
423 ((SwConditionTxtFmtColl
*)pColl
)->InsertCondition( aCond
);
428 // ---------------------------------------------------------------------
430 class SwXMLItemSetStyleContext_Impl
: public SvXMLStyleContext
432 OUString sMasterPageName
;
433 SfxItemSet
*pItemSet
;
434 SwXMLTextStyleContext_Impl
*pTextStyle
;
435 SvXMLStylesContext
&rStyles
;
437 OUString sDataStyleName
;
439 bool bHasMasterPageName
: 1;
440 bool bPageDescConnected
: 1;
441 bool bDataStyleIsResolved
;
443 SvXMLImportContext
*CreateItemSetContext(
445 const OUString
& rLName
,
446 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
450 virtual void SetAttribute( sal_uInt16 nPrefixKey
,
451 const OUString
& rLocalName
,
452 const OUString
& rValue
);
454 const SwXMLImport
& GetSwImport() const
455 { return (const SwXMLImport
&)GetImport(); }
456 SwXMLImport
& GetSwImport() { return (SwXMLImport
&)GetImport(); }
462 SwXMLItemSetStyleContext_Impl(
463 SwXMLImport
& rImport
, sal_uInt16 nPrfx
,
464 const OUString
& rLName
,
465 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
466 SvXMLStylesContext
& rStylesC
,
468 virtual ~SwXMLItemSetStyleContext_Impl();
470 virtual void CreateAndInsert( sal_Bool bOverwrite
);
471 virtual SvXMLImportContext
*CreateChildContext(
473 const OUString
& rLocalName
,
474 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
476 // The item set may be empty!
477 SfxItemSet
*GetItemSet() { return pItemSet
; }
478 const SfxItemSet
*GetItemSet() const { return pItemSet
; }
480 const OUString
& GetMasterPageName() const { return sMasterPageName
; }
481 bool HasMasterPageName() const { return bHasMasterPageName
; }
483 bool IsPageDescConnected() const { return bPageDescConnected
; }
484 void ConnectPageDesc();
486 bool ResolveDataStyleName();
489 void SwXMLItemSetStyleContext_Impl::SetAttribute( sal_uInt16 nPrefixKey
,
490 const OUString
& rLocalName
,
491 const OUString
& rValue
)
493 if( XML_NAMESPACE_STYLE
== nPrefixKey
)
495 if ( IsXMLToken( rLocalName
, XML_MASTER_PAGE_NAME
) )
497 sMasterPageName
= rValue
;
498 bHasMasterPageName
= true;
500 else if ( IsXMLToken( rLocalName
, XML_DATA_STYLE_NAME
) )
502 // if we have a valid data style name
503 if (!rValue
.isEmpty())
505 sDataStyleName
= rValue
;
506 bDataStyleIsResolved
= false; // needs to be resolved
511 SvXMLStyleContext::SetAttribute( nPrefixKey
, rLocalName
, rValue
);
516 SvXMLStyleContext::SetAttribute( nPrefixKey
, rLocalName
, rValue
);
520 SvXMLImportContext
*SwXMLItemSetStyleContext_Impl::CreateItemSetContext(
521 sal_uInt16 nPrefix
, const OUString
& rLName
,
522 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
524 OSL_ENSURE( !pItemSet
,
525 "SwXMLItemSetStyleContext_Impl::CreateItemSetContext: item set exists" );
527 SvXMLImportContext
*pContext
= 0;
529 SwDoc
* pDoc
= SwImport::GetDocFromXMLImport( GetSwImport() );
531 SfxItemPool
& rItemPool
= pDoc
->GetAttrPool();
532 switch( GetFamily() )
534 case XML_STYLE_FAMILY_TABLE_TABLE
:
535 pItemSet
= new SfxItemSet( rItemPool
, aTableSetRange
);
537 case XML_STYLE_FAMILY_TABLE_COLUMN
:
538 pItemSet
= new SfxItemSet( rItemPool
, RES_FRM_SIZE
, RES_FRM_SIZE
, 0 );
540 case XML_STYLE_FAMILY_TABLE_ROW
:
541 pItemSet
= new SfxItemSet( rItemPool
, aTableLineSetRange
);
543 case XML_STYLE_FAMILY_TABLE_CELL
:
544 pItemSet
= new SfxItemSet( rItemPool
, aTableBoxSetRange
);
548 "SwXMLItemSetStyleContext_Impl::CreateItemSetContext: unknown family" );
552 pContext
= GetSwImport().CreateTableItemImportContext(
553 nPrefix
, rLName
, xAttrList
, GetFamily(),
564 TYPEINIT1( SwXMLItemSetStyleContext_Impl
, SvXMLStyleContext
);
566 SwXMLItemSetStyleContext_Impl::SwXMLItemSetStyleContext_Impl( SwXMLImport
& rImport
,
567 sal_uInt16 nPrfx
, const OUString
& rLName
,
568 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
569 SvXMLStylesContext
& rStylesC
,
570 sal_uInt16 nFamily
) :
571 SvXMLStyleContext( rImport
, nPrfx
, rLName
, xAttrList
, nFamily
),
575 bHasMasterPageName( false ),
576 bPageDescConnected( false ),
577 bDataStyleIsResolved( true )
581 SwXMLItemSetStyleContext_Impl::~SwXMLItemSetStyleContext_Impl()
586 void SwXMLItemSetStyleContext_Impl::CreateAndInsert( sal_Bool bOverwrite
)
589 pTextStyle
->CreateAndInsert( bOverwrite
);
592 SvXMLImportContext
*SwXMLItemSetStyleContext_Impl::CreateChildContext(
594 const OUString
& rLocalName
,
595 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
597 SvXMLImportContext
*pContext
= 0;
599 if( XML_NAMESPACE_STYLE
== nPrefix
)
601 if( IsXMLToken( rLocalName
, XML_TABLE_PROPERTIES
) ||
602 IsXMLToken( rLocalName
, XML_TABLE_COLUMN_PROPERTIES
) ||
603 IsXMLToken( rLocalName
, XML_TABLE_ROW_PROPERTIES
) ||
604 IsXMLToken( rLocalName
, XML_TABLE_CELL_PROPERTIES
) )
606 pContext
= CreateItemSetContext( nPrefix
, rLocalName
, xAttrList
);
608 else if( IsXMLToken( rLocalName
, XML_TEXT_PROPERTIES
) ||
609 IsXMLToken( rLocalName
, XML_PARAGRAPH_PROPERTIES
))
613 SvXMLAttributeList
*pTmp
= new SvXMLAttributeList
;
614 OUString aStr
= GetImport().GetNamespaceMap().GetQNameByKey( nPrefix
, GetXMLToken(XML_NAME
) );
615 pTmp
->AddAttribute( aStr
, GetName() );
616 uno::Reference
<xml::sax::XAttributeList
> xTmpAttrList
= pTmp
;
617 pTextStyle
= new SwXMLTextStyleContext_Impl( GetSwImport(), nPrefix
,
618 rLocalName
, xTmpAttrList
, XML_STYLE_FAMILY_TEXT_PARAGRAPH
, rStyles
);
619 pTextStyle
->StartElement( xTmpAttrList
);
620 rStyles
.AddStyle( *pTextStyle
);
622 pContext
= pTextStyle
->CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
627 pContext
= SvXMLStyleContext::CreateChildContext( nPrefix
, rLocalName
,
633 void SwXMLItemSetStyleContext_Impl::ConnectPageDesc()
635 if( bPageDescConnected
|| !HasMasterPageName() )
637 bPageDescConnected
= true;
639 SwDoc
*pDoc
= SwImport::GetDocFromXMLImport( GetSwImport() );
642 // #i40788# - first determine the display name of the page style,
643 // then map this name to the corresponding user interface name.
644 sName
= GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_MASTER_PAGE
,
645 GetMasterPageName() );
646 SwStyleNameMapper::FillUIName( sName
,
648 nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC
,
650 SwPageDesc
*pPageDesc
= pDoc
->FindPageDescByName( sName
);
653 // If the page style is a pool style, then we maybe have to create it
654 // first if it hasn't been used by now.
655 sal_uInt16 nPoolId
= SwStyleNameMapper::GetPoolIdFromUIName( sName
, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC
);
656 if( USHRT_MAX
!= nPoolId
)
657 pPageDesc
= pDoc
->GetPageDescFromPool( nPoolId
, false );
665 SfxItemPool
& rItemPool
= pDoc
->GetAttrPool();
666 pItemSet
= new SfxItemSet( rItemPool
, aTableSetRange
);
669 const SfxPoolItem
*pItem
;
670 SwFmtPageDesc
*pFmtPageDesc
= 0;
671 if( SFX_ITEM_SET
== pItemSet
->GetItemState( RES_PAGEDESC
, sal_False
,
674 if( ((SwFmtPageDesc
*)pItem
)->GetPageDesc() != pPageDesc
)
675 pFmtPageDesc
= new SwFmtPageDesc( *(SwFmtPageDesc
*)pItem
);
678 pFmtPageDesc
= new SwFmtPageDesc();
682 pFmtPageDesc
->RegisterToPageDesc( *pPageDesc
);
683 pItemSet
->Put( *pFmtPageDesc
);
688 bool SwXMLItemSetStyleContext_Impl::ResolveDataStyleName()
690 // resolve, if not already done
691 if (! bDataStyleIsResolved
)
693 // get the format key
695 GetImport().GetTextImport()->GetDataStyleKey(sDataStyleName
);
697 // if the key is valid, insert Item into ItemSet
702 SwDoc
*pDoc
= SwImport::GetDocFromXMLImport( GetSwImport() );
704 SfxItemPool
& rItemPool
= pDoc
->GetAttrPool();
705 pItemSet
= new SfxItemSet( rItemPool
, aTableBoxSetRange
);
707 SwTblBoxNumFormat
aNumFormatItem(nFormat
);
708 pItemSet
->Put(aNumFormatItem
);
712 bDataStyleIsResolved
= true;
717 // was already resolved; nothing to do
722 // ---------------------------------------------------------------------
724 class SwXMLStylesContext_Impl
: public SvXMLStylesContext
726 SwXMLItemSetStyleContext_Impl
*GetSwStyle( sal_uInt16 i
) const;
728 SwXMLImport
& GetSwImport() { return (SwXMLImport
&)GetImport(); }
729 const SwXMLImport
& GetSwImport() const
730 { return (const SwXMLImport
&)GetImport(); }
734 virtual SvXMLStyleContext
*CreateStyleStyleChildContext( sal_uInt16 nFamily
,
735 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
736 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
737 virtual SvXMLStyleContext
*CreateDefaultStyleStyleChildContext(
738 sal_uInt16 nFamily
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
739 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
741 virtual UniReference
< SvXMLImportPropertyMapper
> GetImportPropertyMapper(
742 sal_uInt16 nFamily
) const;
744 virtual uno::Reference
< container::XNameContainer
>
745 GetStylesContainer( sal_uInt16 nFamily
) const;
746 virtual OUString
GetServiceName( sal_uInt16 nFamily
) const;
753 SwXMLStylesContext_Impl(
754 SwXMLImport
& rImport
, sal_uInt16 nPrfx
,
755 const OUString
& rLName
,
756 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
758 virtual ~SwXMLStylesContext_Impl();
760 virtual sal_Bool
InsertStyleFamily( sal_uInt16 nFamily
) const;
762 virtual void EndElement();
765 TYPEINIT1( SwXMLStylesContext_Impl
, SvXMLStylesContext
);
767 inline SwXMLItemSetStyleContext_Impl
*SwXMLStylesContext_Impl::GetSwStyle(
770 return PTR_CAST( SwXMLItemSetStyleContext_Impl
, GetStyle( i
) );
773 SvXMLStyleContext
*SwXMLStylesContext_Impl::CreateStyleStyleChildContext(
774 sal_uInt16 nFamily
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
775 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
777 SvXMLStyleContext
*pStyle
= 0;
781 case XML_STYLE_FAMILY_TEXT_PARAGRAPH
:
782 pStyle
= new SwXMLTextStyleContext_Impl( GetSwImport(), nPrefix
,
783 rLocalName
, xAttrList
, nFamily
, *this );
785 case XML_STYLE_FAMILY_TABLE_TABLE
:
786 case XML_STYLE_FAMILY_TABLE_COLUMN
:
787 case XML_STYLE_FAMILY_TABLE_ROW
:
788 case XML_STYLE_FAMILY_TABLE_CELL
:
789 pStyle
= new SwXMLItemSetStyleContext_Impl( GetSwImport(), nPrefix
,
790 rLocalName
, xAttrList
, *this, nFamily
);
792 case XML_STYLE_FAMILY_SD_GRAPHICS_ID
:
793 // As long as there are no element items, we can use the text
795 pStyle
= new XMLTextShapeStyleContext( GetImport(), nPrefix
,
796 rLocalName
, xAttrList
, *this, nFamily
);
799 pStyle
= SvXMLStylesContext::CreateStyleStyleChildContext( nFamily
,
809 SvXMLStyleContext
*SwXMLStylesContext_Impl::CreateDefaultStyleStyleChildContext(
810 sal_uInt16 nFamily
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
811 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
813 SvXMLStyleContext
*pStyle
= 0;
817 case XML_STYLE_FAMILY_TEXT_PARAGRAPH
:
818 case XML_STYLE_FAMILY_TABLE_TABLE
:
819 case XML_STYLE_FAMILY_TABLE_ROW
:
820 pStyle
= new XMLTextStyleContext( GetImport(), nPrefix
, rLocalName
,
821 xAttrList
, *this, nFamily
,
824 case XML_STYLE_FAMILY_SD_GRAPHICS_ID
:
825 // There are no writer specific defaults for graphic styles!
826 pStyle
= new XMLGraphicsDefaultStyle( GetImport(), nPrefix
,
827 rLocalName
, xAttrList
, *this );
830 pStyle
= SvXMLStylesContext::CreateDefaultStyleStyleChildContext( nFamily
,
841 SwXMLStylesContext_Impl::SwXMLStylesContext_Impl(
842 SwXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
843 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
845 SvXMLStylesContext( rImport
, nPrfx
, rLName
, xAttrList
, bAuto
)
849 SwXMLStylesContext_Impl::~SwXMLStylesContext_Impl()
853 sal_Bool
SwXMLStylesContext_Impl::InsertStyleFamily( sal_uInt16 nFamily
) const
855 const SwXMLImport
& rSwImport
= GetSwImport();
856 sal_uInt16 nStyleFamilyMask
= rSwImport
.GetStyleFamilyMask();
858 sal_Bool bIns
= sal_True
;
861 case XML_STYLE_FAMILY_TEXT_PARAGRAPH
:
862 bIns
= (nStyleFamilyMask
& SFX_STYLE_FAMILY_PARA
) != 0;
864 case XML_STYLE_FAMILY_TEXT_TEXT
:
865 bIns
= (nStyleFamilyMask
& SFX_STYLE_FAMILY_CHAR
) != 0;
867 case XML_STYLE_FAMILY_SD_GRAPHICS_ID
:
868 bIns
= (nStyleFamilyMask
& SFX_STYLE_FAMILY_FRAME
) != 0;
870 case XML_STYLE_FAMILY_TEXT_LIST
:
871 bIns
= (nStyleFamilyMask
& SFX_STYLE_FAMILY_PSEUDO
) != 0;
873 case XML_STYLE_FAMILY_TEXT_OUTLINE
:
874 case XML_STYLE_FAMILY_TEXT_FOOTNOTECONFIG
:
875 case XML_STYLE_FAMILY_TEXT_ENDNOTECONFIG
:
876 case XML_STYLE_FAMILY_TEXT_LINENUMBERINGCONFIG
:
877 case XML_STYLE_FAMILY_TEXT_BIBLIOGRAPHYCONFIG
:
878 bIns
= !(rSwImport
.IsInsertMode() || rSwImport
.IsStylesOnlyMode() ||
879 rSwImport
.IsBlockMode());
882 bIns
= SvXMLStylesContext::InsertStyleFamily( nFamily
);
889 UniReference
< SvXMLImportPropertyMapper
> SwXMLStylesContext_Impl::GetImportPropertyMapper(
890 sal_uInt16 nFamily
) const
892 UniReference
< SvXMLImportPropertyMapper
> xMapper
;
893 if( nFamily
== XML_STYLE_FAMILY_TABLE_TABLE
)
894 xMapper
= XMLTextImportHelper::CreateTableDefaultExtPropMapper(
895 const_cast<SwXMLStylesContext_Impl
*>( this )->GetImport() );
896 else if( nFamily
== XML_STYLE_FAMILY_TABLE_ROW
)
897 xMapper
= XMLTextImportHelper::CreateTableRowDefaultExtPropMapper(
898 const_cast<SwXMLStylesContext_Impl
*>( this )->GetImport() );
900 xMapper
= SvXMLStylesContext::GetImportPropertyMapper( nFamily
);
904 uno::Reference
< container::XNameContainer
> SwXMLStylesContext_Impl::GetStylesContainer(
905 sal_uInt16 nFamily
) const
907 uno::Reference
< container::XNameContainer
> xStyles
;
908 if( XML_STYLE_FAMILY_SD_GRAPHICS_ID
== nFamily
)
909 xStyles
= ((SvXMLImport
*)&GetImport())->GetTextImport()->GetFrameStyles();
911 xStyles
= SvXMLStylesContext::GetStylesContainer( nFamily
);
916 OUString
SwXMLStylesContext_Impl::GetServiceName( sal_uInt16 nFamily
) const
919 if( XML_STYLE_FAMILY_SD_GRAPHICS_ID
== nFamily
)
920 sServiceName
= OUString("com.sun.star.style.FrameStyle");
922 sServiceName
= SvXMLStylesContext::GetServiceName( nFamily
);
927 void SwXMLStylesContext_Impl::EndElement()
929 GetSwImport().InsertStyles( IsAutomaticStyle() );
932 // ---------------------------------------------------------------------
934 class SwXMLMasterStylesContext_Impl
: public XMLTextMasterStylesContext
937 virtual sal_Bool
InsertStyleFamily( sal_uInt16 nFamily
) const;
939 SwXMLImport
& GetSwImport() { return (SwXMLImport
&)GetImport(); }
940 const SwXMLImport
& GetSwImport() const
941 { return (const SwXMLImport
&)GetImport(); }
947 SwXMLMasterStylesContext_Impl(
948 SwXMLImport
& rImport
, sal_uInt16 nPrfx
,
949 const OUString
& rLName
,
950 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
951 virtual ~SwXMLMasterStylesContext_Impl();
952 virtual void EndElement();
955 TYPEINIT1( SwXMLMasterStylesContext_Impl
, XMLTextMasterStylesContext
);
957 SwXMLMasterStylesContext_Impl::SwXMLMasterStylesContext_Impl(
958 SwXMLImport
& rImport
, sal_uInt16 nPrfx
,
959 const OUString
& rLName
,
960 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
) :
961 XMLTextMasterStylesContext( rImport
, nPrfx
, rLName
, xAttrList
)
965 SwXMLMasterStylesContext_Impl::~SwXMLMasterStylesContext_Impl()
969 sal_Bool
SwXMLMasterStylesContext_Impl::InsertStyleFamily( sal_uInt16 nFamily
) const
973 const SwXMLImport
& rSwImport
= GetSwImport();
974 sal_uInt16 nStyleFamilyMask
= rSwImport
.GetStyleFamilyMask();
975 if( XML_STYLE_FAMILY_MASTER_PAGE
== nFamily
)
976 bIns
= (nStyleFamilyMask
& SFX_STYLE_FAMILY_PAGE
) != 0;
978 bIns
= XMLTextMasterStylesContext::InsertStyleFamily( nFamily
);
983 void SwXMLMasterStylesContext_Impl::EndElement()
985 FinishStyles( !GetSwImport().IsInsertMode() );
986 GetSwImport().FinishStyles();
988 // ---------------------------------------------------------------------
990 SvXMLImportContext
*SwXMLImport::CreateStylesContext(
991 const OUString
& rLocalName
,
992 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
995 SvXMLStylesContext
*pContext
=
996 new SwXMLStylesContext_Impl( *this, XML_NAMESPACE_OFFICE
, rLocalName
,
999 SetAutoStyles( pContext
);
1001 SetStyles( pContext
);
1006 SvXMLImportContext
*SwXMLImport::CreateMasterStylesContext(
1007 const OUString
& rLocalName
,
1008 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
1010 SvXMLStylesContext
*pContext
=
1011 new SwXMLMasterStylesContext_Impl( *this, XML_NAMESPACE_OFFICE
, rLocalName
,
1013 SetMasterStyles( pContext
);
1018 void SwXMLImport::InsertStyles( sal_Bool bAuto
)
1020 if( bAuto
&& GetAutoStyles() )
1021 GetAutoStyles()->CopyAutoStylesToDoc();
1022 if( !bAuto
&& GetStyles() )
1023 GetStyles()->CopyStylesToDoc( !IsInsertMode(), sal_False
);
1026 void SwXMLImport::FinishStyles()
1029 GetStyles()->FinishStyles( !IsInsertMode() );
1032 void SwXMLImport::UpdateTxtCollConditions( SwDoc
*pDoc
)
1035 pDoc
= SwImport::GetDocFromXMLImport( *this );
1037 const SwTxtFmtColls
& rColls
= *pDoc
->GetTxtFmtColls();
1038 sal_uInt16 nCount
= rColls
.size();
1039 for( sal_uInt16 i
=0; i
< nCount
; i
++ )
1041 SwTxtFmtColl
*pColl
= rColls
[i
];
1042 if( pColl
&& RES_CONDTXTFMTCOLL
== pColl
->Which() )
1044 const SwFmtCollConditions
& rConditions
=
1045 ((const SwConditionTxtFmtColl
*)pColl
)->GetCondColls();
1046 bool bSendModify
= false;
1047 for( sal_uInt16 j
=0; j
< rConditions
.size() && !bSendModify
; j
++ )
1049 const SwCollCondition
& rCond
= rConditions
[j
];
1050 switch( rCond
.GetCondition() )
1052 case PARA_IN_TABLEHEAD
:
1053 case PARA_IN_TABLEBODY
:
1054 case PARA_IN_FOOTER
:
1055 case PARA_IN_HEADER
:
1062 SwCondCollCondChg
aMsg( pColl
);
1063 pColl
->ModifyNotification( &aMsg
, &aMsg
);
1069 bool SwXMLImport::FindAutomaticStyle(
1071 const OUString
& rName
,
1072 const SfxItemSet
**ppItemSet
,
1073 OUString
*pParent
) const
1075 SwXMLItemSetStyleContext_Impl
*pStyle
= 0;
1076 if( GetAutoStyles() )
1078 pStyle
= PTR_CAST( SwXMLItemSetStyleContext_Impl
,
1080 FindStyleChildContext( nFamily
, rName
,
1086 if( XML_STYLE_FAMILY_TABLE_TABLE
== pStyle
->GetFamily() &&
1087 pStyle
->HasMasterPageName() &&
1088 !pStyle
->IsPageDescConnected() )
1089 pStyle
->ConnectPageDesc();
1090 (*ppItemSet
) = pStyle
->GetItemSet();
1092 // resolve data style name late
1093 if( XML_STYLE_FAMILY_TABLE_CELL
== pStyle
->GetFamily() &&
1094 pStyle
->ResolveDataStyleName() )
1096 (*ppItemSet
) = pStyle
->GetItemSet();
1102 *pParent
= pStyle
->GetParentName();
1109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */