1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlfmt.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <rtl/ustrbuf.hxx>
36 #include <tools/urlobj.hxx>
38 #ifndef _SVSTDARR_STRINGSSORT_DECL
39 #define _SVSTDARR_STRINGSSORT
40 #include <svtools/svstdarr.hxx>
42 #include <xmloff/nmspmap.hxx>
47 #include <poolfmt.hxx>
48 #include <charfmt.hxx>
52 #include "unostyle.hxx"
53 #include "fmtpdsc.hxx"
54 #include "pagedesc.hxx"
55 #include <xmloff/xmlnmspe.hxx>
56 #include <xmloff/i18nmap.hxx>
57 #include <xmloff/xmltkmap.hxx>
58 #include "xmlitem.hxx"
59 #include <xmloff/xmlstyle.hxx>
60 #ifndef _XMLOFF_TXTSTYLI_HXX
61 #include <xmloff/txtstyli.hxx>
63 #ifndef _XMLOFF_TXTIMP_HXX
64 #include <xmloff/txtimp.hxx>
66 #ifndef _XMLOFF_FAMILIES_HXX
67 #include <xmloff/families.hxx>
69 #include <xmloff/XMLTextMasterStylesContext.hxx>
70 #ifndef _XMLOFF_XMLTEXTSHAPESTYLECONTEXT_HXX
71 #include <xmloff/XMLTextShapeStyleContext.hxx>
73 #include <xmloff/XMLGraphicsDefaultStyle.hxx>
75 #include "xmltbli.hxx"
76 #include "cellatr.hxx"
77 #include <SwStyleNameMapper.hxx>
78 #include <xmloff/attrlist.hxx>
79 #include <unotxdoc.hxx>
82 using namespace ::com::sun::star
;
83 using ::rtl::OUString
;
84 using ::rtl::OUStringBuffer
;
85 using namespace ::xmloff::token
;
87 class SwXMLConditionParser_Impl
91 sal_uInt32 nCondition
;
92 sal_uInt32 nSubCondition
;
97 inline sal_Bool
SkipWS();
98 inline sal_Bool
MatchChar( sal_Unicode c
);
99 inline sal_Bool
MatchName( OUString
& rName
);
100 inline sal_Bool
MatchNumber( sal_uInt32
& rNumber
);
104 SwXMLConditionParser_Impl( const OUString
& rInp
);
106 sal_Bool
IsValid() const { return 0 != nCondition
; }
108 sal_uInt32
GetCondition() const { return nCondition
; }
109 sal_uInt32
GetSubCondition() const { return nSubCondition
; }
112 inline sal_Bool
SwXMLConditionParser_Impl::SkipWS()
114 while( nPos
< nLength
&& ' ' == sInput
[nPos
] )
119 inline sal_Bool
SwXMLConditionParser_Impl::MatchChar( sal_Unicode c
)
121 sal_Bool bRet
= sal_False
;
122 if( nPos
< nLength
&& c
== sInput
[nPos
] )
130 inline sal_Bool
SwXMLConditionParser_Impl::MatchName( OUString
& rName
)
132 OUStringBuffer
sBuffer( nLength
);
133 while( nPos
< nLength
&&
134 ( ('a' <= sInput
[nPos
] && sInput
[nPos
] <= 'z') ||
135 '-' == sInput
[nPos
] ) )
137 sBuffer
.append( sInput
[nPos
] );
140 rName
= sBuffer
.makeStringAndClear();
141 return rName
.getLength() > 0;
144 inline sal_Bool
SwXMLConditionParser_Impl::MatchNumber( sal_uInt32
& rNumber
)
146 OUStringBuffer
sBuffer( nLength
);
147 while( nPos
< nLength
&& '0' <= sInput
[nPos
] && sInput
[nPos
] <= '9' )
149 sBuffer
.append( sInput
[nPos
] );
153 OUString
sNum( sBuffer
.makeStringAndClear() );
154 if( sNum
.getLength() )
155 rNumber
= sNum
.toInt32();
156 return sNum
.getLength() > 0;
159 SwXMLConditionParser_Impl::SwXMLConditionParser_Impl( const OUString
& rInp
) :
164 nLength( rInp
.getLength() )
167 sal_Bool bHasSub
= sal_False
;
169 sal_Bool bOK
= SkipWS() && MatchName( sFunc
) && SkipWS() &&
170 MatchChar( '(' ) && SkipWS() && MatchChar( ')' ) && SkipWS();
171 if( bOK
&& MatchChar( '=' ) )
173 bOK
= SkipWS() && MatchNumber( nSub
) && SkipWS();
177 bOK
&= nPos
== nLength
;
181 if( IsXMLToken( sFunc
, XML_ENDNOTE
) && !bHasSub
)
182 nCondition
= PARA_IN_ENDNOTE
;
183 else if( IsXMLToken( sFunc
, XML_FOOTER
) && !bHasSub
)
184 nCondition
= PARA_IN_FOOTER
;
185 else if( IsXMLToken( sFunc
, XML_FOOTNOTE
) && !bHasSub
)
186 nCondition
= PARA_IN_FOOTENOTE
;
187 else if( IsXMLToken( sFunc
, XML_HEADER
) && !bHasSub
)
188 nCondition
= PARA_IN_HEADER
;
189 else if( IsXMLToken( sFunc
, XML_LIST_LEVEL
) &&
190 nSub
>=1 && nSub
<= MAXLEVEL
)
192 nCondition
= PARA_IN_LIST
;
193 nSubCondition
= nSub
-1;
195 else if( IsXMLToken( sFunc
, XML_OUTLINE_LEVEL
) &&
196 nSub
>=1 && nSub
<= MAXLEVEL
)
198 nCondition
= PARA_IN_OUTLINE
;
199 nSubCondition
= nSub
-1;
201 else if( IsXMLToken( sFunc
, XML_SECTION
) && !bHasSub
)
203 nCondition
= PARA_IN_SECTION
;
205 else if( IsXMLToken( sFunc
, XML_TABLE
) && !bHasSub
)
207 nCondition
= PARA_IN_TABLEBODY
;
209 else if( IsXMLToken( sFunc
, XML_TABLE_HEADER
) && !bHasSub
)
211 nCondition
= PARA_IN_TABLEHEAD
;
213 else if( IsXMLToken( sFunc
, XML_TEXT_BOX
) && !bHasSub
)
215 nCondition
= PARA_IN_FRAME
;
220 // ---------------------------------------------------------------------
222 class SwXMLConditionContext_Impl
: public SvXMLImportContext
224 sal_uInt32 nCondition
;
225 sal_uInt32 nSubCondition
;
227 OUString sApplyStyle
;
229 void ParseCondition( const OUString
& rCond
);
233 SwXMLConditionContext_Impl(
234 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
235 const OUString
& rLName
,
236 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
237 virtual ~SwXMLConditionContext_Impl();
241 sal_Bool
IsValid() const { return 0 != nCondition
; }
243 sal_uInt32
GetCondition() const { return nCondition
; }
244 sal_uInt32
GetSubCondition() const { return nSubCondition
; }
245 const OUString
& GetApplyStyle() const { return sApplyStyle
; }
248 SwXMLConditionContext_Impl::SwXMLConditionContext_Impl(
249 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
250 const OUString
& rLName
,
251 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
) :
252 SvXMLImportContext( rImport
, nPrfx
, rLName
),
256 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
257 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
259 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
262 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
264 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
266 // TODO: use a map here
267 if( XML_NAMESPACE_STYLE
== nPrefix
)
269 if( IsXMLToken( aLocalName
, XML_CONDITION
) )
271 SwXMLConditionParser_Impl
aCondParser( rValue
);
272 if( aCondParser
.IsValid() )
274 nCondition
= aCondParser
.GetCondition();
275 nSubCondition
= aCondParser
.GetSubCondition();
278 else if( IsXMLToken( aLocalName
, XML_APPLY_STYLE_NAME
) )
280 sApplyStyle
= rValue
;
286 SwXMLConditionContext_Impl::~SwXMLConditionContext_Impl()
290 TYPEINIT1( SwXMLConditionContext_Impl
, XMLTextStyleContext
);
292 // ---------------------------------------------------------------------
294 typedef SwXMLConditionContext_Impl
*SwXMLConditionContextPtr
;
295 SV_DECL_PTRARR( SwXMLConditions_Impl
, SwXMLConditionContextPtr
, 5, 2 )
297 class SwXMLTextStyleContext_Impl
: public XMLTextStyleContext
299 SwXMLConditions_Impl
*pConditions
;
303 virtual uno::Reference
< style::XStyle
> Create();
309 SwXMLTextStyleContext_Impl( SwXMLImport
& rImport
, sal_uInt16 nPrfx
,
310 const OUString
& rLName
,
311 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
313 SvXMLStylesContext
& rStyles
);
314 virtual ~SwXMLTextStyleContext_Impl();
316 virtual SvXMLImportContext
*CreateChildContext(
318 const OUString
& rLocalName
,
319 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
321 virtual void Finish( sal_Bool bOverwrite
);
324 TYPEINIT1( SwXMLTextStyleContext_Impl
, XMLTextStyleContext
);
326 uno::Reference
< style::XStyle
> SwXMLTextStyleContext_Impl::Create()
328 uno::Reference
< style::XStyle
> xNewStyle
;
330 if( pConditions
&& XML_STYLE_FAMILY_TEXT_PARAGRAPH
== GetFamily() )
332 uno::Reference
< lang::XMultiServiceFactory
> xFactory( GetImport().GetModel(),
336 OUString
sServiceName( RTL_CONSTASCII_USTRINGPARAM(
337 "com.sun.star.style.ConditionalParagraphStyle" ) );
338 uno::Reference
< uno::XInterface
> xIfc
=
339 xFactory
->createInstance( sServiceName
);
341 xNewStyle
= uno::Reference
< style::XStyle
>( xIfc
, uno::UNO_QUERY
);
346 xNewStyle
= XMLTextStyleContext::Create();
352 SwXMLTextStyleContext_Impl::SwXMLTextStyleContext_Impl( SwXMLImport
& rImport
,
353 sal_uInt16 nPrfx
, const OUString
& rLName
,
354 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
356 SvXMLStylesContext
& rStyles
) :
357 XMLTextStyleContext( rImport
, nPrfx
, rLName
, xAttrList
, rStyles
, nFamily
),
362 SwXMLTextStyleContext_Impl::~SwXMLTextStyleContext_Impl()
366 while( pConditions
->Count() )
368 SwXMLConditionContext_Impl
*pCond
= pConditions
->GetObject(0);
369 pConditions
->Remove( 0UL );
376 SvXMLImportContext
*SwXMLTextStyleContext_Impl::CreateChildContext(
378 const OUString
& rLocalName
,
379 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
381 SvXMLImportContext
*pContext
= 0;
383 if( XML_NAMESPACE_STYLE
== nPrefix
&& IsXMLToken( rLocalName
, XML_MAP
) )
385 SwXMLConditionContext_Impl
*pCond
=
386 new SwXMLConditionContext_Impl( GetImport(), nPrefix
,
387 rLocalName
, xAttrList
);
388 if( pCond
->IsValid() )
391 pConditions
= new SwXMLConditions_Impl
;
392 pConditions
->Insert( pCond
, pConditions
->Count() );
399 pContext
= XMLTextStyleContext::CreateChildContext( nPrefix
, rLocalName
,
405 void SwXMLTextStyleContext_Impl::Finish( sal_Bool bOverwrite
)
407 XMLTextStyleContext::Finish( bOverwrite
);
409 if( !pConditions
|| XML_STYLE_FAMILY_TEXT_PARAGRAPH
!= GetFamily() )
412 uno::Reference
< style::XStyle
> xStyle
= GetStyle();
416 const SwXStyle
* pStyle
= 0;
417 uno::Reference
<lang::XUnoTunnel
> xStyleTunnel( xStyle
, uno::UNO_QUERY
);
418 if( xStyleTunnel
.is() )
420 pStyle
= reinterpret_cast< SwXStyle
* >(
421 sal::static_int_cast
< sal_IntPtr
>( xStyleTunnel
->getSomething( SwXStyle::getUnoTunnelId() )));
426 const SwDoc
*pDoc
= pStyle
->GetDoc();
428 SwTxtFmtColl
*pColl
= pDoc
->FindTxtFmtCollByName( pStyle
->GetStyleName() );
429 ASSERT( pColl
, "Text collection not found" );
430 if( !pColl
|| RES_CONDTXTFMTCOLL
!= pColl
->Which() )
433 sal_uInt16 nCount
= pConditions
->Count();
436 for( sal_uInt16 i
= 0; i
< nCount
; i
++ )
438 const SwXMLConditionContext_Impl
*pCond
= (*pConditions
)[i
];
439 OUString
aDisplayName(
440 GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_PARAGRAPH
,
441 pCond
->GetApplyStyle() ) );
442 SwStyleNameMapper::FillUIName( aDisplayName
,
444 nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL
,
447 SwTxtFmtColl
* pCondColl
= pDoc
->FindTxtFmtCollByName( sName
);
449 "SwXMLItemSetStyleContext_Impl::ConnectConditions: cond coll missing" );
452 SwCollCondition
aCond( pCondColl
, pCond
->GetCondition(),
453 pCond
->GetSubCondition() );
454 ((SwConditionTxtFmtColl
*)pColl
)->InsertCondition( aCond
);
459 // ---------------------------------------------------------------------
461 class SwXMLItemSetStyleContext_Impl
: public SvXMLStyleContext
463 OUString sMasterPageName
;
464 SfxItemSet
*pItemSet
;
465 SwXMLTextStyleContext_Impl
*pTextStyle
;
466 SvXMLStylesContext
&rStyles
;
468 OUString sDataStyleName
;
470 sal_Bool bHasMasterPageName
: 1;
471 sal_Bool bPageDescConnected
: 1;
472 sal_Bool bDataStyleIsResolved
;
474 SvXMLImportContext
*CreateItemSetContext(
476 const OUString
& rLName
,
477 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
481 virtual void SetAttribute( sal_uInt16 nPrefixKey
,
482 const OUString
& rLocalName
,
483 const OUString
& rValue
);
485 const SwXMLImport
& GetSwImport() const
486 { return (const SwXMLImport
&)GetImport(); }
487 SwXMLImport
& GetSwImport() { return (SwXMLImport
&)GetImport(); }
493 SwXMLItemSetStyleContext_Impl(
494 SwXMLImport
& rImport
, sal_uInt16 nPrfx
,
495 const OUString
& rLName
,
496 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
497 SvXMLStylesContext
& rStylesC
,
499 virtual ~SwXMLItemSetStyleContext_Impl();
501 virtual void CreateAndInsert( sal_Bool bOverwrite
);
502 virtual SvXMLImportContext
*CreateChildContext(
504 const OUString
& rLocalName
,
505 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
507 // The item set may be empty!
508 SfxItemSet
*GetItemSet() { return pItemSet
; }
509 const SfxItemSet
*GetItemSet() const { return pItemSet
; }
511 const OUString
& GetMasterPageName() const { return sMasterPageName
; }
512 sal_Bool
HasMasterPageName() const { return bHasMasterPageName
; }
514 sal_Bool
IsPageDescConnected() const { return bPageDescConnected
; }
515 void ConnectPageDesc();
517 sal_Bool
ResolveDataStyleName();
520 void SwXMLItemSetStyleContext_Impl::SetAttribute( sal_uInt16 nPrefixKey
,
521 const OUString
& rLocalName
,
522 const OUString
& rValue
)
524 if( XML_NAMESPACE_STYLE
== nPrefixKey
)
526 if ( IsXMLToken( rLocalName
, XML_MASTER_PAGE_NAME
) )
528 sMasterPageName
= rValue
;
529 bHasMasterPageName
= sal_True
;
531 else if ( IsXMLToken( rLocalName
, XML_DATA_STYLE_NAME
) )
533 // if we have a valid data style name
534 if (rValue
.getLength() > 0)
536 sDataStyleName
= rValue
;
537 bDataStyleIsResolved
= sal_False
; // needs to be resolved
542 SvXMLStyleContext::SetAttribute( nPrefixKey
, rLocalName
, rValue
);
547 SvXMLStyleContext::SetAttribute( nPrefixKey
, rLocalName
, rValue
);
551 SvXMLImportContext
*SwXMLItemSetStyleContext_Impl::CreateItemSetContext(
552 sal_uInt16 nPrefix
, const OUString
& rLName
,
553 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
556 "SwXMLItemSetStyleContext_Impl::CreateItemSetContext: item set exists" );
558 SvXMLImportContext
*pContext
= 0;
560 SwDoc
* pDoc
= SwImport::GetDocFromXMLImport( GetSwImport() );
562 SfxItemPool
& rItemPool
= pDoc
->GetAttrPool();
563 switch( GetFamily() )
565 case XML_STYLE_FAMILY_TABLE_TABLE
:
566 pItemSet
= new SfxItemSet( rItemPool
, aTableSetRange
);
568 case XML_STYLE_FAMILY_TABLE_COLUMN
:
569 pItemSet
= new SfxItemSet( rItemPool
, RES_FRM_SIZE
, RES_FRM_SIZE
, 0 );
571 case XML_STYLE_FAMILY_TABLE_ROW
:
572 pItemSet
= new SfxItemSet( rItemPool
, aTableLineSetRange
);
574 case XML_STYLE_FAMILY_TABLE_CELL
:
575 pItemSet
= new SfxItemSet( rItemPool
, aTableBoxSetRange
);
579 "SwXMLItemSetStyleContext_Impl::CreateItemSetContext: unknown family" );
583 pContext
= GetSwImport().CreateTableItemImportContext(
584 nPrefix
, rLName
, xAttrList
, GetFamily(),
595 TYPEINIT1( SwXMLItemSetStyleContext_Impl
, SvXMLStyleContext
);
597 SwXMLItemSetStyleContext_Impl::SwXMLItemSetStyleContext_Impl( SwXMLImport
& rImport
,
598 sal_uInt16 nPrfx
, const OUString
& rLName
,
599 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
600 SvXMLStylesContext
& rStylesC
,
601 sal_uInt16 nFamily
) :
602 SvXMLStyleContext( rImport
, nPrfx
, rLName
, xAttrList
, nFamily
),
606 bHasMasterPageName( sal_False
),
607 bPageDescConnected( sal_False
),
608 bDataStyleIsResolved( sal_True
)
612 SwXMLItemSetStyleContext_Impl::~SwXMLItemSetStyleContext_Impl()
617 void SwXMLItemSetStyleContext_Impl::CreateAndInsert( sal_Bool bOverwrite
)
620 pTextStyle
->CreateAndInsert( bOverwrite
);
623 SvXMLImportContext
*SwXMLItemSetStyleContext_Impl::CreateChildContext(
625 const OUString
& rLocalName
,
626 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
628 SvXMLImportContext
*pContext
= 0;
630 if( XML_NAMESPACE_STYLE
== nPrefix
)
632 if( IsXMLToken( rLocalName
, XML_TABLE_PROPERTIES
) ||
633 IsXMLToken( rLocalName
, XML_TABLE_COLUMN_PROPERTIES
) ||
634 IsXMLToken( rLocalName
, XML_TABLE_ROW_PROPERTIES
) ||
635 IsXMLToken( rLocalName
, XML_TABLE_CELL_PROPERTIES
) )
637 pContext
= CreateItemSetContext( nPrefix
, rLocalName
, xAttrList
);
639 else if( IsXMLToken( rLocalName
, XML_TEXT_PROPERTIES
) ||
640 IsXMLToken( rLocalName
, XML_PARAGRAPH_PROPERTIES
))
644 SvXMLAttributeList
*pTmp
= new SvXMLAttributeList
;
645 OUString aStr
= GetImport().GetNamespaceMap().GetQNameByKey( nPrefix
, GetXMLToken(XML_NAME
) );
646 pTmp
->AddAttribute( aStr
, GetName() );
647 uno::Reference
<xml::sax::XAttributeList
> xTmpAttrList
= pTmp
;
648 pTextStyle
= new SwXMLTextStyleContext_Impl( GetSwImport(), nPrefix
,
649 rLocalName
, xTmpAttrList
, XML_STYLE_FAMILY_TEXT_PARAGRAPH
, rStyles
);
650 pTextStyle
->StartElement( xTmpAttrList
);
651 rStyles
.AddStyle( *pTextStyle
);
653 pContext
= pTextStyle
->CreateChildContext( nPrefix
, rLocalName
, xAttrList
);
658 pContext
= SvXMLStyleContext::CreateChildContext( nPrefix
, rLocalName
,
664 void SwXMLItemSetStyleContext_Impl::ConnectPageDesc()
666 if( bPageDescConnected
|| !HasMasterPageName() )
668 bPageDescConnected
= sal_True
;
670 SwDoc
*pDoc
= SwImport::GetDocFromXMLImport( GetSwImport() );
673 // --> OD 2005-02-01 #i40788# - first determine the display name of the
674 // page style, then map this name to the corresponding user interface name.
675 sName
= GetImport().GetStyleDisplayName( XML_STYLE_FAMILY_MASTER_PAGE
,
676 GetMasterPageName() );
677 SwStyleNameMapper::FillUIName( sName
,
679 nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC
,
682 SwPageDesc
*pPageDesc
= pDoc
->FindPageDescByName( sName
);
685 // If the page style is a pool style, then we maybe have to create it
686 // first if it hasn't been used by now.
687 sal_uInt16 nPoolId
= SwStyleNameMapper::GetPoolIdFromUIName( sName
, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC
);
688 if( USHRT_MAX
!= nPoolId
)
689 pPageDesc
= pDoc
->GetPageDescFromPool( nPoolId
, false );
697 SfxItemPool
& rItemPool
= pDoc
->GetAttrPool();
698 pItemSet
= new SfxItemSet( rItemPool
, aTableSetRange
);
701 const SfxPoolItem
*pItem
;
702 SwFmtPageDesc
*pFmtPageDesc
= 0;
703 if( SFX_ITEM_SET
== pItemSet
->GetItemState( RES_PAGEDESC
, sal_False
,
706 if( ((SwFmtPageDesc
*)pItem
)->GetPageDesc() != pPageDesc
)
707 pFmtPageDesc
= new SwFmtPageDesc( *(SwFmtPageDesc
*)pItem
);
710 pFmtPageDesc
= new SwFmtPageDesc();
714 pPageDesc
->Add( pFmtPageDesc
);
715 pItemSet
->Put( *pFmtPageDesc
);
720 sal_Bool
SwXMLItemSetStyleContext_Impl::ResolveDataStyleName()
722 // resolve, if not already done
723 if (! bDataStyleIsResolved
)
725 // get the format key
727 GetImport().GetTextImport()->GetDataStyleKey(sDataStyleName
);
729 // if the key is valid, insert Item into ItemSet
734 SwDoc
*pDoc
= SwImport::GetDocFromXMLImport( GetSwImport() );
736 SfxItemPool
& rItemPool
= pDoc
->GetAttrPool();
737 pItemSet
= new SfxItemSet( rItemPool
, aTableBoxSetRange
);
739 SwTblBoxNumFormat
aNumFormatItem(nFormat
);
740 pItemSet
->Put(aNumFormatItem
);
744 bDataStyleIsResolved
= sal_True
;
749 // was already resolved; nothing to do
754 // ---------------------------------------------------------------------
756 class SwXMLStylesContext_Impl
: public SvXMLStylesContext
758 SwXMLItemSetStyleContext_Impl
*GetSwStyle( sal_uInt16 i
) const;
760 SwXMLImport
& GetSwImport() { return (SwXMLImport
&)GetImport(); }
761 const SwXMLImport
& GetSwImport() const
762 { return (const SwXMLImport
&)GetImport(); }
766 virtual SvXMLStyleContext
*CreateStyleStyleChildContext( sal_uInt16 nFamily
,
767 sal_uInt16 nPrefix
, const OUString
& rLocalName
,
768 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
769 virtual SvXMLStyleContext
*CreateDefaultStyleStyleChildContext(
770 sal_uInt16 nFamily
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
771 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
773 virtual UniReference
< SvXMLImportPropertyMapper
> GetImportPropertyMapper(
774 sal_uInt16 nFamily
) const;
776 virtual uno::Reference
< container::XNameContainer
>
777 GetStylesContainer( sal_uInt16 nFamily
) const;
778 virtual ::rtl::OUString
GetServiceName( sal_uInt16 nFamily
) const;
785 SwXMLStylesContext_Impl(
786 SwXMLImport
& rImport
, sal_uInt16 nPrfx
,
787 const OUString
& rLName
,
788 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
790 virtual ~SwXMLStylesContext_Impl();
792 virtual sal_Bool
InsertStyleFamily( sal_uInt16 nFamily
) const;
794 virtual void EndElement();
797 TYPEINIT1( SwXMLStylesContext_Impl
, SvXMLStylesContext
);
799 inline SwXMLItemSetStyleContext_Impl
*SwXMLStylesContext_Impl::GetSwStyle(
802 return PTR_CAST( SwXMLItemSetStyleContext_Impl
, GetStyle( i
) );
805 SvXMLStyleContext
*SwXMLStylesContext_Impl::CreateStyleStyleChildContext(
806 sal_uInt16 nFamily
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
807 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
809 SvXMLStyleContext
*pStyle
= 0;
813 case XML_STYLE_FAMILY_TEXT_PARAGRAPH
:
814 pStyle
= new SwXMLTextStyleContext_Impl( GetSwImport(), nPrefix
,
815 rLocalName
, xAttrList
, nFamily
, *this );
817 case XML_STYLE_FAMILY_TABLE_TABLE
:
818 case XML_STYLE_FAMILY_TABLE_COLUMN
:
819 case XML_STYLE_FAMILY_TABLE_ROW
:
820 case XML_STYLE_FAMILY_TABLE_CELL
:
821 pStyle
= new SwXMLItemSetStyleContext_Impl( GetSwImport(), nPrefix
,
822 rLocalName
, xAttrList
, *this, nFamily
);
824 case XML_STYLE_FAMILY_SD_GRAPHICS_ID
:
825 // As long as there are no element items, we can use the text
827 pStyle
= new XMLTextShapeStyleContext( GetImport(), nPrefix
,
828 rLocalName
, xAttrList
, *this, nFamily
);
831 pStyle
= SvXMLStylesContext::CreateStyleStyleChildContext( nFamily
,
841 SvXMLStyleContext
*SwXMLStylesContext_Impl::CreateDefaultStyleStyleChildContext(
842 sal_uInt16 nFamily
, sal_uInt16 nPrefix
, const OUString
& rLocalName
,
843 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
845 SvXMLStyleContext
*pStyle
= 0;
849 case XML_STYLE_FAMILY_TEXT_PARAGRAPH
:
850 case XML_STYLE_FAMILY_TABLE_TABLE
:
851 case XML_STYLE_FAMILY_TABLE_ROW
:
852 pStyle
= new XMLTextStyleContext( GetImport(), nPrefix
, rLocalName
,
853 xAttrList
, *this, nFamily
,
856 case XML_STYLE_FAMILY_SD_GRAPHICS_ID
:
857 // There are no writer specific defaults for graphic styles!
858 pStyle
= new XMLGraphicsDefaultStyle( GetImport(), nPrefix
,
859 rLocalName
, xAttrList
, *this );
862 pStyle
= SvXMLStylesContext::CreateDefaultStyleStyleChildContext( nFamily
,
873 SwXMLStylesContext_Impl::SwXMLStylesContext_Impl(
874 SwXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
875 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
877 SvXMLStylesContext( rImport
, nPrfx
, rLName
, xAttrList
, bAuto
)
881 SwXMLStylesContext_Impl::~SwXMLStylesContext_Impl()
885 sal_Bool
SwXMLStylesContext_Impl::InsertStyleFamily( sal_uInt16 nFamily
) const
887 const SwXMLImport
& rSwImport
= GetSwImport();
888 sal_uInt16 nStyleFamilyMask
= rSwImport
.GetStyleFamilyMask();
890 sal_Bool bIns
= sal_True
;
893 case XML_STYLE_FAMILY_TEXT_PARAGRAPH
:
894 bIns
= (nStyleFamilyMask
& SFX_STYLE_FAMILY_PARA
) != 0;
896 case XML_STYLE_FAMILY_TEXT_TEXT
:
897 bIns
= (nStyleFamilyMask
& SFX_STYLE_FAMILY_CHAR
) != 0;
899 case XML_STYLE_FAMILY_SD_GRAPHICS_ID
:
900 bIns
= (nStyleFamilyMask
& SFX_STYLE_FAMILY_FRAME
) != 0;
902 case XML_STYLE_FAMILY_TEXT_LIST
:
903 bIns
= (nStyleFamilyMask
& SFX_STYLE_FAMILY_PSEUDO
) != 0;
905 case XML_STYLE_FAMILY_TEXT_OUTLINE
:
906 case XML_STYLE_FAMILY_TEXT_FOOTNOTECONFIG
:
907 case XML_STYLE_FAMILY_TEXT_ENDNOTECONFIG
:
908 case XML_STYLE_FAMILY_TEXT_LINENUMBERINGCONFIG
:
909 case XML_STYLE_FAMILY_TEXT_BIBLIOGRAPHYCONFIG
:
910 bIns
= !(rSwImport
.IsInsertMode() || rSwImport
.IsStylesOnlyMode() ||
911 rSwImport
.IsBlockMode());
914 bIns
= SvXMLStylesContext::InsertStyleFamily( nFamily
);
921 UniReference
< SvXMLImportPropertyMapper
> SwXMLStylesContext_Impl::GetImportPropertyMapper(
922 sal_uInt16 nFamily
) const
924 UniReference
< SvXMLImportPropertyMapper
> xMapper
;
925 if( nFamily
== XML_STYLE_FAMILY_TABLE_TABLE
)
926 xMapper
= XMLTextImportHelper::CreateTableDefaultExtPropMapper(
927 const_cast<SwXMLStylesContext_Impl
*>( this )->GetImport() );
928 else if( nFamily
== XML_STYLE_FAMILY_TABLE_ROW
)
929 xMapper
= XMLTextImportHelper::CreateTableRowDefaultExtPropMapper(
930 const_cast<SwXMLStylesContext_Impl
*>( this )->GetImport() );
932 xMapper
= SvXMLStylesContext::GetImportPropertyMapper( nFamily
);
936 uno::Reference
< container::XNameContainer
> SwXMLStylesContext_Impl::GetStylesContainer(
937 sal_uInt16 nFamily
) const
939 uno::Reference
< container::XNameContainer
> xStyles
;
940 if( XML_STYLE_FAMILY_SD_GRAPHICS_ID
== nFamily
)
941 xStyles
= ((SvXMLImport
*)&GetImport())->GetTextImport()->GetFrameStyles();
943 xStyles
= SvXMLStylesContext::GetStylesContainer( nFamily
);
948 OUString
SwXMLStylesContext_Impl::GetServiceName( sal_uInt16 nFamily
) const
951 if( XML_STYLE_FAMILY_SD_GRAPHICS_ID
== nFamily
)
952 sServiceName
= OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.FrameStyle") );
954 sServiceName
= SvXMLStylesContext::GetServiceName( nFamily
);
959 void SwXMLStylesContext_Impl::EndElement()
961 GetSwImport().InsertStyles( IsAutomaticStyle() );
962 // --> OD 2006-10-11 #i69629#
963 // assign paragraph styles to list levels of outline style after all styles
964 // are imported and finished.
965 // if( !bAutoStyles )
966 // GetImport().GetTextImport()->SetOutlineStyles( sal_True );
970 // ---------------------------------------------------------------------
972 class SwXMLMasterStylesContext_Impl
: public XMLTextMasterStylesContext
975 virtual sal_Bool
InsertStyleFamily( sal_uInt16 nFamily
) const;
977 SwXMLImport
& GetSwImport() { return (SwXMLImport
&)GetImport(); }
978 const SwXMLImport
& GetSwImport() const
979 { return (const SwXMLImport
&)GetImport(); }
985 SwXMLMasterStylesContext_Impl(
986 SwXMLImport
& rImport
, sal_uInt16 nPrfx
,
987 const OUString
& rLName
,
988 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
);
989 virtual ~SwXMLMasterStylesContext_Impl();
990 virtual void EndElement();
993 TYPEINIT1( SwXMLMasterStylesContext_Impl
, XMLTextMasterStylesContext
);
995 SwXMLMasterStylesContext_Impl::SwXMLMasterStylesContext_Impl(
996 SwXMLImport
& rImport
, sal_uInt16 nPrfx
,
997 const OUString
& rLName
,
998 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
) :
999 XMLTextMasterStylesContext( rImport
, nPrfx
, rLName
, xAttrList
)
1003 SwXMLMasterStylesContext_Impl::~SwXMLMasterStylesContext_Impl()
1007 sal_Bool
SwXMLMasterStylesContext_Impl::InsertStyleFamily( sal_uInt16 nFamily
) const
1011 const SwXMLImport
& rSwImport
= GetSwImport();
1012 sal_uInt16 nStyleFamilyMask
= rSwImport
.GetStyleFamilyMask();
1013 if( XML_STYLE_FAMILY_MASTER_PAGE
== nFamily
)
1014 bIns
= (nStyleFamilyMask
& SFX_STYLE_FAMILY_PAGE
) != 0;
1016 bIns
= XMLTextMasterStylesContext::InsertStyleFamily( nFamily
);
1021 void SwXMLMasterStylesContext_Impl::EndElement()
1023 FinishStyles( !GetSwImport().IsInsertMode() );
1024 GetSwImport().FinishStyles();
1026 // ---------------------------------------------------------------------
1028 SvXMLImportContext
*SwXMLImport::CreateStylesContext(
1029 const OUString
& rLocalName
,
1030 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
1033 SvXMLStylesContext
*pContext
=
1034 new SwXMLStylesContext_Impl( *this, XML_NAMESPACE_OFFICE
, rLocalName
,
1037 SetAutoStyles( pContext
);
1039 SetStyles( pContext
);
1044 SvXMLImportContext
*SwXMLImport::CreateMasterStylesContext(
1045 const OUString
& rLocalName
,
1046 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
1048 SvXMLStylesContext
*pContext
=
1049 new SwXMLMasterStylesContext_Impl( *this, XML_NAMESPACE_OFFICE
, rLocalName
,
1051 SetMasterStyles( pContext
);
1056 void SwXMLImport::InsertStyles( sal_Bool bAuto
)
1058 if( bAuto
&& GetAutoStyles() )
1059 GetAutoStyles()->CopyAutoStylesToDoc();
1060 if( !bAuto
&& GetStyles() )
1061 GetStyles()->CopyStylesToDoc( !IsInsertMode(), sal_False
);
1064 void SwXMLImport::FinishStyles()
1067 GetStyles()->FinishStyles( !IsInsertMode() );
1070 void SwXMLImport::UpdateTxtCollConditions( SwDoc
*pDoc
)
1073 pDoc
= SwImport::GetDocFromXMLImport( *this );
1075 const SwTxtFmtColls
& rColls
= *pDoc
->GetTxtFmtColls();
1076 sal_uInt16 nCount
= rColls
.Count();
1077 for( sal_uInt16 i
=0; i
< nCount
; i
++ )
1079 SwTxtFmtColl
*pColl
= rColls
[i
];
1080 if( pColl
&& RES_CONDTXTFMTCOLL
== pColl
->Which() )
1082 const SwFmtCollConditions
& rConditions
=
1083 ((const SwConditionTxtFmtColl
*)pColl
)->GetCondColls();
1084 sal_Bool bSendModify
= sal_False
;
1085 for( sal_uInt16 j
=0; j
< rConditions
.Count() && !bSendModify
; j
++ )
1087 const SwCollCondition
& rCond
= *rConditions
[j
];
1088 switch( rCond
.GetCondition() )
1090 case PARA_IN_TABLEHEAD
:
1091 case PARA_IN_TABLEBODY
:
1092 case PARA_IN_FOOTER
:
1093 case PARA_IN_HEADER
:
1094 bSendModify
= sal_True
;
1100 SwCondCollCondChg
aMsg( pColl
);
1101 pColl
->Modify( &aMsg
, &aMsg
);
1107 sal_Bool
SwXMLImport::FindAutomaticStyle(
1109 const OUString
& rName
,
1110 const SfxItemSet
**ppItemSet
,
1111 OUString
*pParent
) const
1113 SwXMLItemSetStyleContext_Impl
*pStyle
= 0;
1114 if( GetAutoStyles() )
1116 pStyle
= PTR_CAST( SwXMLItemSetStyleContext_Impl
,
1118 FindStyleChildContext( nFamily
, rName
,
1124 if( XML_STYLE_FAMILY_TABLE_TABLE
== pStyle
->GetFamily() &&
1125 pStyle
->HasMasterPageName() &&
1126 !pStyle
->IsPageDescConnected() )
1127 pStyle
->ConnectPageDesc();
1128 (*ppItemSet
) = pStyle
->GetItemSet();
1130 // resolve data style name late
1131 if( XML_STYLE_FAMILY_TABLE_CELL
== pStyle
->GetFamily() &&
1132 pStyle
->ResolveDataStyleName() )
1134 (*ppItemSet
) = pStyle
->GetItemSet();
1140 *pParent
= pStyle
->GetParentName();