merge the formfield patch from ooo-build
[ooovba.git] / sw / source / filter / xml / xmlfmt.cxx
blobec50718350b828f12580f3a884507cf70713c916
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlfmt.cxx,v $
10 * $Revision: 1.40 $
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>
41 #endif
42 #include <xmloff/nmspmap.hxx>
43 #include <format.hxx>
44 #include <fmtcol.hxx>
45 #include <hints.hxx>
46 #include <unoobj.hxx>
47 #include <poolfmt.hxx>
48 #include <charfmt.hxx>
49 #include <paratr.hxx>
50 #include <doc.hxx>
51 #include "docary.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>
62 #endif
63 #ifndef _XMLOFF_TXTIMP_HXX
64 #include <xmloff/txtimp.hxx>
65 #endif
66 #ifndef _XMLOFF_FAMILIES_HXX
67 #include <xmloff/families.hxx>
68 #endif
69 #include <xmloff/XMLTextMasterStylesContext.hxx>
70 #ifndef _XMLOFF_XMLTEXTSHAPESTYLECONTEXT_HXX
71 #include <xmloff/XMLTextShapeStyleContext.hxx>
72 #endif
73 #include <xmloff/XMLGraphicsDefaultStyle.hxx>
74 #include "xmlimp.hxx"
75 #include "xmltbli.hxx"
76 #include "cellatr.hxx"
77 #include <SwStyleNameMapper.hxx>
78 #include <xmloff/attrlist.hxx>
79 #include <unotxdoc.hxx>
80 #include <docsh.hxx>
82 using namespace ::com::sun::star;
83 using ::rtl::OUString;
84 using ::rtl::OUStringBuffer;
85 using namespace ::xmloff::token;
87 class SwXMLConditionParser_Impl
89 OUString sInput;
91 sal_uInt32 nCondition;
92 sal_uInt32 nSubCondition;
94 sal_Int32 nPos;
95 sal_Int32 nLength;
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 );
102 public:
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] )
115 nPos++;
116 return sal_True;
119 inline sal_Bool SwXMLConditionParser_Impl::MatchChar( sal_Unicode c )
121 sal_Bool bRet = sal_False;
122 if( nPos < nLength && c == sInput[nPos] )
124 nPos++;
125 bRet = sal_True;
127 return bRet;
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] );
138 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] );
150 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 ) :
160 sInput( rInp ),
161 nCondition( 0 ),
162 nSubCondition( 0 ),
163 nPos( 0 ),
164 nLength( rInp.getLength() )
166 OUString sFunc;
167 sal_Bool bHasSub = sal_False;
168 sal_uInt32 nSub = 0;
169 sal_Bool bOK = SkipWS() && MatchName( sFunc ) && SkipWS() &&
170 MatchChar( '(' ) && SkipWS() && MatchChar( ')' ) && SkipWS();
171 if( bOK && MatchChar( '=' ) )
173 bOK = SkipWS() && MatchNumber( nSub ) && SkipWS();
174 bHasSub = sal_True;
177 bOK &= nPos == nLength;
179 if( bOK )
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 );
231 public:
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();
239 TYPEINFO();
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 ),
253 nCondition( 0 ),
254 nSubCondition( 0 )
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 );
260 OUString aLocalName;
261 sal_uInt16 nPrefix =
262 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
263 &aLocalName );
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;
301 protected:
303 virtual uno::Reference < style::XStyle > Create();
305 public:
307 TYPEINFO();
309 SwXMLTextStyleContext_Impl( SwXMLImport& rImport, sal_uInt16 nPrfx,
310 const OUString& rLName,
311 const uno::Reference< xml::sax::XAttributeList > & xAttrList,
312 sal_uInt16 nFamily,
313 SvXMLStylesContext& rStyles );
314 virtual ~SwXMLTextStyleContext_Impl();
316 virtual SvXMLImportContext *CreateChildContext(
317 sal_uInt16 nPrefix,
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(),
333 uno::UNO_QUERY );
334 if( xFactory.is() )
336 OUString sServiceName( RTL_CONSTASCII_USTRINGPARAM(
337 "com.sun.star.style.ConditionalParagraphStyle" ) );
338 uno::Reference < uno::XInterface > xIfc =
339 xFactory->createInstance( sServiceName );
340 if( xIfc.is() )
341 xNewStyle = uno::Reference < style::XStyle >( xIfc, uno::UNO_QUERY );
344 else
346 xNewStyle = XMLTextStyleContext::Create();
349 return xNewStyle;
352 SwXMLTextStyleContext_Impl::SwXMLTextStyleContext_Impl( SwXMLImport& rImport,
353 sal_uInt16 nPrfx, const OUString& rLName,
354 const uno::Reference< xml::sax::XAttributeList > & xAttrList,
355 sal_uInt16 nFamily,
356 SvXMLStylesContext& rStyles ) :
357 XMLTextStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily ),
358 pConditions( 0 )
362 SwXMLTextStyleContext_Impl::~SwXMLTextStyleContext_Impl()
364 if( pConditions )
366 while( pConditions->Count() )
368 SwXMLConditionContext_Impl *pCond = pConditions->GetObject(0);
369 pConditions->Remove( 0UL );
370 pCond->ReleaseRef();
372 delete pConditions;
376 SvXMLImportContext *SwXMLTextStyleContext_Impl::CreateChildContext(
377 sal_uInt16 nPrefix,
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() )
390 if( !pConditions )
391 pConditions = new SwXMLConditions_Impl;
392 pConditions->Insert( pCond, pConditions->Count() );
393 pCond->AddRef();
395 pContext = pCond;
398 if( !pContext )
399 pContext = XMLTextStyleContext::CreateChildContext( nPrefix, rLocalName,
400 xAttrList );
402 return pContext;
405 void SwXMLTextStyleContext_Impl::Finish( sal_Bool bOverwrite )
407 XMLTextStyleContext::Finish( bOverwrite );
409 if( !pConditions || XML_STYLE_FAMILY_TEXT_PARAGRAPH != GetFamily() )
410 return;
412 uno::Reference < style::XStyle > xStyle = GetStyle();
413 if( !xStyle.is() )
414 return;
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() )));
423 if( !pStyle )
424 return;
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() )
431 return;
433 sal_uInt16 nCount = pConditions->Count();
434 String aString;
435 OUString sName;
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,
443 aString,
444 nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL,
445 sal_True);
446 sName = aString;
447 SwTxtFmtColl* pCondColl = pDoc->FindTxtFmtCollByName( sName );
448 ASSERT( pCondColl,
449 "SwXMLItemSetStyleContext_Impl::ConnectConditions: cond coll missing" );
450 if( pCondColl )
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(
475 sal_uInt16 nPrefix,
476 const OUString& rLName,
477 const uno::Reference< xml::sax::XAttributeList > & xAttrList);
479 protected:
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(); }
489 public:
491 TYPEINFO();
493 SwXMLItemSetStyleContext_Impl(
494 SwXMLImport& rImport, sal_uInt16 nPrfx,
495 const OUString& rLName,
496 const uno::Reference< xml::sax::XAttributeList > & xAttrList,
497 SvXMLStylesContext& rStylesC,
498 sal_uInt16 nFamily);
499 virtual ~SwXMLItemSetStyleContext_Impl();
501 virtual void CreateAndInsert( sal_Bool bOverwrite );
502 virtual SvXMLImportContext *CreateChildContext(
503 sal_uInt16 nPrefix,
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
540 else
542 SvXMLStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
545 else
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 )
555 ASSERT( !pItemSet,
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 );
567 break;
568 case XML_STYLE_FAMILY_TABLE_COLUMN:
569 pItemSet = new SfxItemSet( rItemPool, RES_FRM_SIZE, RES_FRM_SIZE, 0 );
570 break;
571 case XML_STYLE_FAMILY_TABLE_ROW:
572 pItemSet = new SfxItemSet( rItemPool, aTableLineSetRange );
573 break;
574 case XML_STYLE_FAMILY_TABLE_CELL:
575 pItemSet = new SfxItemSet( rItemPool, aTableBoxSetRange );
576 break;
577 default:
578 ASSERT( !this,
579 "SwXMLItemSetStyleContext_Impl::CreateItemSetContext: unknown family" );
580 break;
582 if( pItemSet )
583 pContext = GetSwImport().CreateTableItemImportContext(
584 nPrefix, rLName, xAttrList, GetFamily(),
585 *pItemSet );
586 if( !pContext )
588 delete pItemSet;
589 pItemSet = 0;
592 return pContext;
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 ),
603 pItemSet( 0 ),
604 pTextStyle( 0 ),
605 rStyles( rStylesC ),
606 bHasMasterPageName( sal_False ),
607 bPageDescConnected( sal_False ),
608 bDataStyleIsResolved( sal_True )
612 SwXMLItemSetStyleContext_Impl::~SwXMLItemSetStyleContext_Impl()
614 delete pItemSet;
617 void SwXMLItemSetStyleContext_Impl::CreateAndInsert( sal_Bool bOverwrite )
619 if( pTextStyle )
620 pTextStyle->CreateAndInsert( bOverwrite );
623 SvXMLImportContext *SwXMLItemSetStyleContext_Impl::CreateChildContext(
624 sal_uInt16 nPrefix,
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 ))
642 if( !pTextStyle )
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 );
657 if( !pContext )
658 pContext = SvXMLStyleContext::CreateChildContext( nPrefix, rLocalName,
659 xAttrList );
661 return pContext;
664 void SwXMLItemSetStyleContext_Impl::ConnectPageDesc()
666 if( bPageDescConnected || !HasMasterPageName() )
667 return;
668 bPageDescConnected = sal_True;
670 SwDoc *pDoc = SwImport::GetDocFromXMLImport( GetSwImport() );
672 String sName;
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,
678 sName,
679 nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC,
680 sal_True);
681 // <--
682 SwPageDesc *pPageDesc = pDoc->FindPageDescByName( sName );
683 if( !pPageDesc )
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 );
692 if( !pPageDesc )
693 return;
695 if( !pItemSet )
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,
704 &pItem ) )
706 if( ((SwFmtPageDesc *)pItem)->GetPageDesc() != pPageDesc )
707 pFmtPageDesc = new SwFmtPageDesc( *(SwFmtPageDesc *)pItem );
709 else
710 pFmtPageDesc = new SwFmtPageDesc();
712 if( pFmtPageDesc )
714 pPageDesc->Add( pFmtPageDesc );
715 pItemSet->Put( *pFmtPageDesc );
716 delete pFmtPageDesc;
720 sal_Bool SwXMLItemSetStyleContext_Impl::ResolveDataStyleName()
722 // resolve, if not already done
723 if (! bDataStyleIsResolved)
725 // get the format key
726 sal_Int32 nFormat =
727 GetImport().GetTextImport()->GetDataStyleKey(sDataStyleName);
729 // if the key is valid, insert Item into ItemSet
730 if( -1 != nFormat )
732 if( !pItemSet )
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);
743 // now resolved
744 bDataStyleIsResolved = sal_True;
745 return sal_True;
747 else
749 // was already resolved; nothing to do
750 return sal_False;
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(); }
764 protected:
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 );
772 // HACK
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;
779 // HACK
781 public:
783 TYPEINFO();
785 SwXMLStylesContext_Impl(
786 SwXMLImport& rImport, sal_uInt16 nPrfx,
787 const OUString& rLName ,
788 const uno::Reference< xml::sax::XAttributeList > & xAttrList,
789 sal_Bool bAuto );
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(
800 sal_uInt16 i ) const
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;
811 switch( nFamily )
813 case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
814 pStyle = new SwXMLTextStyleContext_Impl( GetSwImport(), nPrefix,
815 rLocalName, xAttrList, nFamily, *this );
816 break;
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 );
823 break;
824 case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
825 // As long as there are no element items, we can use the text
826 // style class.
827 pStyle = new XMLTextShapeStyleContext( GetImport(), nPrefix,
828 rLocalName, xAttrList, *this, nFamily );
829 break;
830 default:
831 pStyle = SvXMLStylesContext::CreateStyleStyleChildContext( nFamily,
832 nPrefix,
833 rLocalName,
834 xAttrList );
835 break;
838 return pStyle;
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;
847 switch( nFamily )
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,
854 sal_True );
855 break;
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 );
860 break;
861 default:
862 pStyle = SvXMLStylesContext::CreateDefaultStyleStyleChildContext( nFamily,
863 nPrefix,
864 rLocalName,
865 xAttrList );
866 break;
869 return pStyle;
873 SwXMLStylesContext_Impl::SwXMLStylesContext_Impl(
874 SwXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
875 const uno::Reference< xml::sax::XAttributeList > & xAttrList,
876 sal_Bool bAuto ) :
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;
891 switch( nFamily )
893 case XML_STYLE_FAMILY_TEXT_PARAGRAPH:
894 bIns = (nStyleFamilyMask & SFX_STYLE_FAMILY_PARA) != 0;
895 break;
896 case XML_STYLE_FAMILY_TEXT_TEXT:
897 bIns = (nStyleFamilyMask & SFX_STYLE_FAMILY_CHAR) != 0;
898 break;
899 case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
900 bIns = (nStyleFamilyMask & SFX_STYLE_FAMILY_FRAME) != 0;
901 break;
902 case XML_STYLE_FAMILY_TEXT_LIST:
903 bIns = (nStyleFamilyMask & SFX_STYLE_FAMILY_PSEUDO) != 0;
904 break;
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());
912 break;
913 default:
914 bIns = SvXMLStylesContext::InsertStyleFamily( nFamily );
915 break;
918 return bIns;
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() );
931 else
932 xMapper = SvXMLStylesContext::GetImportPropertyMapper( nFamily );
933 return xMapper;
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();
942 else
943 xStyles = SvXMLStylesContext::GetStylesContainer( nFamily );
945 return xStyles;
948 OUString SwXMLStylesContext_Impl::GetServiceName( sal_uInt16 nFamily ) const
950 String sServiceName;
951 if( XML_STYLE_FAMILY_SD_GRAPHICS_ID == nFamily )
952 sServiceName = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.FrameStyle") );
953 else
954 sServiceName = SvXMLStylesContext::GetServiceName( nFamily );
956 return sServiceName;
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 );
967 // <--
970 // ---------------------------------------------------------------------
972 class SwXMLMasterStylesContext_Impl : public XMLTextMasterStylesContext
974 protected:
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(); }
981 public:
983 TYPEINFO();
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
1009 sal_Bool bIns;
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;
1015 else
1016 bIns = XMLTextMasterStylesContext::InsertStyleFamily( nFamily );
1018 return bIns;
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,
1031 sal_Bool bAuto )
1033 SvXMLStylesContext *pContext =
1034 new SwXMLStylesContext_Impl( *this, XML_NAMESPACE_OFFICE, rLocalName,
1035 xAttrList, bAuto );
1036 if( bAuto )
1037 SetAutoStyles( pContext );
1038 else
1039 SetStyles( pContext );
1041 return 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,
1050 xAttrList );
1051 SetMasterStyles( pContext );
1053 return 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()
1066 if( GetStyles() )
1067 GetStyles()->FinishStyles( !IsInsertMode() );
1070 void SwXMLImport::UpdateTxtCollConditions( SwDoc *pDoc )
1072 if( !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;
1095 break;
1098 if( bSendModify )
1100 SwCondCollCondChg aMsg( pColl );
1101 pColl->Modify( &aMsg, &aMsg );
1107 sal_Bool SwXMLImport::FindAutomaticStyle(
1108 sal_uInt16 nFamily,
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,
1117 GetAutoStyles()->
1118 FindStyleChildContext( nFamily, rName,
1119 sal_True ) );
1120 if( pStyle )
1122 if( ppItemSet )
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();
1139 if( pParent )
1140 *pParent = pStyle->GetParentName();
1144 return pStyle != 0;