merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / draw / ximpstyl.cxx
blobe47b144ff72456f8a5fa8b0bbfdf76a94488d3d8
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: ximpstyl.cxx,v $
10 * $Revision: 1.53 $
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_xmloff.hxx"
35 #include "ximpstyl.hxx"
36 #include <xmloff/XMLShapeStyleContext.hxx>
37 #include "xmlnmspe.hxx"
38 #include <xmloff/xmltoken.hxx>
39 #include <xmloff/xmluconv.hxx>
40 #include "ximpnote.hxx"
41 #include <tools/debug.hxx>
43 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
44 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
45 #include <com/sun/star/presentation/XPresentationPage.hpp>
46 #include <com/sun/star/drawing/XDrawPages.hpp>
47 #include <com/sun/star/container/XNamed.hpp>
48 #include <com/sun/star/beans/XPropertySet.hpp>
49 #include <com/sun/star/beans/XPropertyState.hpp>
50 #include <com/sun/star/presentation/XHandoutMasterSupplier.hpp>
51 #include <comphelper/namecontainer.hxx>
52 #include <xmloff/xmlprcon.hxx>
53 #include <xmloff/families.hxx>
54 #include <com/sun/star/container/XNameContainer.hpp>
55 #include <svtools/zforlist.hxx>
56 #include "PropertySetMerger.hxx"
57 #include "sdpropls.hxx"
58 #include "layerimp.hxx"
59 #include <xmloff/XMLGraphicsDefaultStyle.hxx>
60 #include "XMLNumberStylesImport.hxx"
61 #include "xmlerror.hxx"
63 using ::rtl::OUString;
64 using ::rtl::OUStringBuffer;
66 using namespace ::com::sun::star;
67 using namespace ::com::sun::star::uno;
68 using namespace ::com::sun::star::xml::sax;
69 using namespace ::xmloff::token;
71 //////////////////////////////////////////////////////////////////////////////
73 class SdXMLDrawingPagePropertySetContext : public SvXMLPropertySetContext
75 public:
77 TYPEINFO();
79 SdXMLDrawingPagePropertySetContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
80 const ::rtl::OUString& rLName,
81 const ::com::sun::star::uno::Reference<
82 ::com::sun::star::xml::sax::XAttributeList >& xAttrList,
83 ::std::vector< XMLPropertyState > &rProps,
84 const UniReference < SvXMLImportPropertyMapper > &rMap );
86 virtual ~SdXMLDrawingPagePropertySetContext();
88 using SvXMLPropertySetContext::CreateChildContext;
89 virtual SvXMLImportContext *CreateChildContext( USHORT nPrefix,
90 const ::rtl::OUString& rLocalName,
91 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList,
92 ::std::vector< XMLPropertyState > &rProperties,
93 const XMLPropertyState& rProp);
96 TYPEINIT1( SdXMLDrawingPagePropertySetContext, SvXMLPropertySetContext );
98 SdXMLDrawingPagePropertySetContext::SdXMLDrawingPagePropertySetContext(
99 SvXMLImport& rImport, sal_uInt16 nPrfx,
100 const OUString& rLName,
101 const uno::Reference< xml::sax::XAttributeList > & xAttrList,
102 ::std::vector< XMLPropertyState > &rProps,
103 const UniReference < SvXMLImportPropertyMapper > &rMap ) :
104 SvXMLPropertySetContext( rImport, nPrfx, rLName, xAttrList,
105 XML_TYPE_PROP_DRAWING_PAGE, rProps, rMap )
109 SdXMLDrawingPagePropertySetContext::~SdXMLDrawingPagePropertySetContext()
113 SvXMLImportContext *SdXMLDrawingPagePropertySetContext::CreateChildContext(
114 sal_uInt16 p_nPrefix,
115 const OUString& rLocalName,
116 const uno::Reference< xml::sax::XAttributeList > & xAttrList,
117 ::std::vector< XMLPropertyState > &rProperties,
118 const XMLPropertyState& rProp )
120 SvXMLImportContext *pContext = 0;
122 switch( mxMapper->getPropertySetMapper()->GetEntryContextId( rProp.mnIndex ) )
124 case CTF_PAGE_SOUND_URL:
126 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
127 for(sal_Int16 i=0; i < nAttrCount; i++)
129 OUString aLocalName;
130 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(xAttrList->getNameByIndex(i), &aLocalName);
132 if( (nPrefix == XML_NAMESPACE_XLINK) && IsXMLToken( aLocalName, XML_HREF ) )
134 uno::Any aAny( GetImport().GetAbsoluteReference( xAttrList->getValueByIndex(i) ) );
135 XMLPropertyState aPropState( rProp.mnIndex, aAny );
136 rProperties.push_back( aPropState );
139 break;
143 if( !pContext )
144 pContext = SvXMLPropertySetContext::CreateChildContext( p_nPrefix, rLocalName,
145 xAttrList,
146 rProperties, rProp );
148 return pContext;
151 //////////////////////////////////////////////////////////////////////////////
153 class SdXMLDrawingPageStyleContext : public XMLPropStyleContext
155 public:
156 TYPEINFO();
158 SdXMLDrawingPageStyleContext(
159 SvXMLImport& rImport,
160 sal_uInt16 nPrfx,
161 const rtl::OUString& rLName,
162 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList,
163 SvXMLStylesContext& rStyles,
164 sal_uInt16 nFamily = XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID);
165 virtual ~SdXMLDrawingPageStyleContext();
167 SvXMLImportContext * CreateChildContext(
168 sal_uInt16 nPrefix,
169 const ::rtl::OUString& rLocalName,
170 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList );
172 virtual void Finish( sal_Bool bOverwrite );
174 // #i35918#
175 virtual void FillPropertySet(
176 const ::com::sun::star::uno::Reference<
177 ::com::sun::star::beans::XPropertySet > & rPropSet );
180 TYPEINIT1( SdXMLDrawingPageStyleContext, XMLPropStyleContext );
182 SdXMLDrawingPageStyleContext::SdXMLDrawingPageStyleContext(
183 SvXMLImport& rImport,
184 sal_uInt16 nPrfx,
185 const OUString& rLName,
186 const uno::Reference< xml::sax::XAttributeList >& xAttrList,
187 SvXMLStylesContext& rStyles,
188 sal_uInt16 nFamily)
189 : XMLPropStyleContext(rImport, nPrfx, rLName, xAttrList, rStyles, nFamily )
193 SdXMLDrawingPageStyleContext::~SdXMLDrawingPageStyleContext()
197 SvXMLImportContext *SdXMLDrawingPageStyleContext::CreateChildContext(
198 sal_uInt16 nPrefix,
199 const OUString& rLocalName,
200 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
202 SvXMLImportContext *pContext = 0;
204 if( XML_NAMESPACE_STYLE == nPrefix &&
205 IsXMLToken( rLocalName, XML_DRAWING_PAGE_PROPERTIES ) )
207 UniReference < SvXMLImportPropertyMapper > xImpPrMap =
208 GetStyles()->GetImportPropertyMapper( GetFamily() );
209 if( xImpPrMap.is() )
210 pContext = new SdXMLDrawingPagePropertySetContext( GetImport(), nPrefix,
211 rLocalName, xAttrList,
212 GetProperties(),
213 xImpPrMap );
216 if( !pContext )
217 pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName,
218 xAttrList );
220 return pContext;
223 void SdXMLDrawingPageStyleContext::Finish( sal_Bool bOverwrite )
225 XMLPropStyleContext::Finish( bOverwrite );
227 ::std::vector< XMLPropertyState > &rProperties = GetProperties();
229 const UniReference< XMLPropertySetMapper >& rImpPrMap = GetStyles()->GetImportPropertyMapper( GetFamily() )->getPropertySetMapper();
231 ::std::vector< XMLPropertyState >::iterator property = rProperties.begin();
232 for(; property != rProperties.end(); property++)
234 if( property->mnIndex == -1 )
235 continue;
237 sal_Int16 nContextID = rImpPrMap->GetEntryContextId(property->mnIndex);
238 switch( nContextID )
240 case CTF_DATE_TIME_FORMAT:
242 OUString sStyleName;
243 (*property).maValue >>= sStyleName;
245 sal_Int32 nStyle = 0;
247 SdXMLNumberFormatImportContext* pSdNumStyle =
248 PTR_CAST( SdXMLNumberFormatImportContext,
249 GetStyles()->FindStyleChildContext( XML_STYLE_FAMILY_DATA_STYLE, sStyleName, sal_True ) );
251 if( pSdNumStyle )
252 nStyle = pSdNumStyle->GetDrawKey();
254 (*property).maValue <<= nStyle;
256 break;
262 // #i35918#
263 void SdXMLDrawingPageStyleContext::FillPropertySet(
264 const Reference< beans::XPropertySet > & rPropSet )
266 const sal_uInt16 MAX_SPECIAL_DRAW_STYLES = 7;
267 struct _ContextID_Index_Pair aContextIDs[MAX_SPECIAL_DRAW_STYLES+1] =
269 { CTF_DASHNAME , -1 },
270 { CTF_LINESTARTNAME , -1 },
271 { CTF_LINEENDNAME , -1 },
272 { CTF_FILLGRADIENTNAME, -1 },
273 { CTF_FILLTRANSNAME , -1 },
274 { CTF_FILLHATCHNAME , -1 },
275 { CTF_FILLBITMAPNAME , -1 },
276 { -1, -1 }
278 static sal_uInt16 aFamilies[MAX_SPECIAL_DRAW_STYLES] =
280 XML_STYLE_FAMILY_SD_STROKE_DASH_ID,
281 XML_STYLE_FAMILY_SD_MARKER_ID,
282 XML_STYLE_FAMILY_SD_MARKER_ID,
283 XML_STYLE_FAMILY_SD_GRADIENT_ID,
284 XML_STYLE_FAMILY_SD_GRADIENT_ID,
285 XML_STYLE_FAMILY_SD_HATCH_ID,
286 XML_STYLE_FAMILY_SD_FILL_IMAGE_ID
289 UniReference < SvXMLImportPropertyMapper > xImpPrMap =
290 GetStyles()->GetImportPropertyMapper( GetFamily() );
291 DBG_ASSERT( xImpPrMap.is(), "There is the import prop mapper" );
292 if( xImpPrMap.is() )
293 xImpPrMap->FillPropertySet( GetProperties(), rPropSet, aContextIDs );
295 Reference< beans::XPropertySetInfo > xInfo;
296 for( sal_uInt16 i=0; i<MAX_SPECIAL_DRAW_STYLES; i++ )
298 sal_Int32 nIndex = aContextIDs[i].nIndex;
299 if( nIndex != -1 )
301 struct XMLPropertyState& rState = GetProperties()[nIndex];
302 OUString sStyleName;
303 rState.maValue >>= sStyleName;
304 sStyleName = GetImport().GetStyleDisplayName( aFamilies[i],
305 sStyleName );
306 // get property set mapper
307 UniReference<XMLPropertySetMapper> rPropMapper =
308 xImpPrMap->getPropertySetMapper();
310 // set property
311 const OUString& rPropertyName =
312 rPropMapper->GetEntryAPIName(rState.mnIndex);
313 if( !xInfo.is() )
314 xInfo = rPropSet->getPropertySetInfo();
315 if ( xInfo->hasPropertyByName( rPropertyName ) )
317 rPropSet->setPropertyValue( rPropertyName, Any( sStyleName ) );
323 //////////////////////////////////////////////////////////////////////////////
325 TYPEINIT1( SdXMLPageMasterStyleContext, SvXMLStyleContext );
327 SdXMLPageMasterStyleContext::SdXMLPageMasterStyleContext(
328 SdXMLImport& rImport,
329 sal_uInt16 nPrfx,
330 const OUString& rLName,
331 const uno::Reference< xml::sax::XAttributeList>& xAttrList)
332 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_SD_PAGEMASTERSTYLECONEXT_ID),
333 mnBorderBottom( 0L ),
334 mnBorderLeft( 0L ),
335 mnBorderRight( 0L ),
336 mnBorderTop( 0L ),
337 mnWidth( 0L ),
338 mnHeight( 0L ),
339 meOrientation(GetSdImport().IsDraw() ? view::PaperOrientation_PORTRAIT : view::PaperOrientation_LANDSCAPE)
341 // set family to something special at SvXMLStyleContext
342 // for differences in search-methods
344 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
345 for(sal_Int16 i=0; i < nAttrCount; i++)
347 OUString sAttrName = xAttrList->getNameByIndex(i);
348 OUString aLocalName;
349 sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName(sAttrName, &aLocalName);
350 OUString sValue = xAttrList->getValueByIndex(i);
351 const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetPageMasterStyleAttrTokenMap();
353 switch(rAttrTokenMap.Get(nPrefix, aLocalName))
355 case XML_TOK_PAGEMASTERSTYLE_MARGIN_TOP:
357 GetSdImport().GetMM100UnitConverter().convertMeasure(mnBorderTop, sValue);
358 break;
360 case XML_TOK_PAGEMASTERSTYLE_MARGIN_BOTTOM:
362 GetSdImport().GetMM100UnitConverter().convertMeasure(mnBorderBottom, sValue);
363 break;
365 case XML_TOK_PAGEMASTERSTYLE_MARGIN_LEFT:
367 GetSdImport().GetMM100UnitConverter().convertMeasure(mnBorderLeft, sValue);
368 break;
370 case XML_TOK_PAGEMASTERSTYLE_MARGIN_RIGHT:
372 GetSdImport().GetMM100UnitConverter().convertMeasure(mnBorderRight, sValue);
373 break;
375 case XML_TOK_PAGEMASTERSTYLE_PAGE_WIDTH:
377 GetSdImport().GetMM100UnitConverter().convertMeasure(mnWidth, sValue);
378 break;
380 case XML_TOK_PAGEMASTERSTYLE_PAGE_HEIGHT:
382 GetSdImport().GetMM100UnitConverter().convertMeasure(mnHeight, sValue);
383 break;
385 case XML_TOK_PAGEMASTERSTYLE_PAGE_ORIENTATION:
387 if( IsXMLToken( sValue, XML_PORTRAIT ) )
388 meOrientation = view::PaperOrientation_PORTRAIT;
389 else
390 meOrientation = view::PaperOrientation_LANDSCAPE;
391 break;
397 //////////////////////////////////////////////////////////////////////////////
399 SdXMLPageMasterStyleContext::~SdXMLPageMasterStyleContext()
403 //////////////////////////////////////////////////////////////////////////////
404 //////////////////////////////////////////////////////////////////////////////
406 TYPEINIT1( SdXMLPageMasterContext, SvXMLStyleContext );
408 SdXMLPageMasterContext::SdXMLPageMasterContext(
409 SdXMLImport& rImport,
410 sal_uInt16 nPrfx,
411 const OUString& rLName,
412 const uno::Reference< xml::sax::XAttributeList>& xAttrList)
413 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_SD_PAGEMASTERCONEXT_ID),
414 mpPageMasterStyle( 0L )
416 // set family to something special at SvXMLStyleContext
417 // for differences in search-methods
419 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
420 for(sal_Int16 i=0; i < nAttrCount; i++)
422 OUString sAttrName = xAttrList->getNameByIndex(i);
423 OUString aLocalName;
424 sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName(sAttrName, &aLocalName);
425 OUString sValue = xAttrList->getValueByIndex(i);
426 const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetPageMasterAttrTokenMap();
428 switch(rAttrTokenMap.Get(nPrefix, aLocalName))
430 case XML_TOK_PAGEMASTER_NAME:
432 msName = sValue;
433 break;
439 //////////////////////////////////////////////////////////////////////////////
441 SdXMLPageMasterContext::~SdXMLPageMasterContext()
443 // release remembered contexts, they are no longer needed
444 if(mpPageMasterStyle)
446 mpPageMasterStyle->ReleaseRef();
447 mpPageMasterStyle = 0L;
451 //////////////////////////////////////////////////////////////////////////////
453 SvXMLImportContext *SdXMLPageMasterContext::CreateChildContext(
454 sal_uInt16 nPrefix,
455 const OUString& rLocalName,
456 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
458 SvXMLImportContext* pContext = 0;
460 if(nPrefix == XML_NAMESPACE_STYLE && IsXMLToken( rLocalName, XML_PAGE_LAYOUT_PROPERTIES) )
462 pContext = new SdXMLPageMasterStyleContext(GetSdImport(), nPrefix, rLocalName, xAttrList);
464 // remember SdXMLPresentationPlaceholderContext for later evaluation
465 if(pContext)
467 pContext->AddRef();
468 DBG_ASSERT(!mpPageMasterStyle, "PageMasterStyle is set, there seem to be two of them (!)");
469 mpPageMasterStyle = (SdXMLPageMasterStyleContext*)pContext;
473 // call base class
474 if(!pContext)
475 pContext = SvXMLStyleContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
477 return pContext;
480 //////////////////////////////////////////////////////////////////////////////
481 //////////////////////////////////////////////////////////////////////////////
483 TYPEINIT1( SdXMLPresentationPageLayoutContext, SvXMLStyleContext );
485 SdXMLPresentationPageLayoutContext::SdXMLPresentationPageLayoutContext(
486 SdXMLImport& rImport,
487 sal_uInt16 nPrfx,
488 const OUString& rLName,
489 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
490 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_SD_PRESENTATIONPAGELAYOUT_ID),
491 mnTypeId( 20 ) // AUTOLAYOUT_NONE
493 // set family to somethiong special at SvXMLStyleContext
494 // for differences in search-methods
496 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
497 for( sal_Int16 i=0; i < nAttrCount; i++ )
499 const OUString& rAttrName = xAttrList->getNameByIndex( i );
500 OUString aLocalName;
501 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
503 if(nPrefix == XML_NAMESPACE_STYLE && IsXMLToken( aLocalName, XML_NAME ) )
505 msName = xAttrList->getValueByIndex( i );
510 SdXMLPresentationPageLayoutContext::~SdXMLPresentationPageLayoutContext()
514 SvXMLImportContext *SdXMLPresentationPageLayoutContext::CreateChildContext(
515 sal_uInt16 nPrefix,
516 const OUString& rLocalName,
517 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
519 SvXMLImportContext* pContext = 0;
521 if(nPrefix == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_PLACEHOLDER ) )
523 // presentation:placeholder inside style:presentation-page-layout context
524 pContext = new SdXMLPresentationPlaceholderContext(
525 GetSdImport(), nPrefix, rLocalName, xAttrList);
527 // remember SdXMLPresentationPlaceholderContext for later evaluation
528 if(pContext)
530 pContext->AddRef();
531 maList.Insert((SdXMLPresentationPlaceholderContext*)pContext, LIST_APPEND);
535 // call base class
536 if(!pContext)
537 pContext = SvXMLStyleContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
539 return pContext;
542 void SdXMLPresentationPageLayoutContext::EndElement()
544 // build presentation page layout type here
545 // calc mnTpeId due to content of maList
546 // at the moment only use number of types used there
547 if(maList.Count())
549 SdXMLPresentationPlaceholderContext* pObj0 = maList.GetObject(0);
550 if(pObj0->GetName().equals(OUString(RTL_CONSTASCII_USTRINGPARAM("handout"))))
552 switch( maList.Count() )
554 case 1:
555 mnTypeId = 22; // AUTOLAYOUT_HANDOUT1
556 break;
557 case 2:
558 mnTypeId = 23; // AUTOLAYOUT_HANDOUT2
559 break;
560 case 3:
561 mnTypeId = 24; // AUTOLAYOUT_HANDOUT3
562 break;
563 case 4:
564 mnTypeId = 25; // AUTOLAYOUT_HANDOUT4
565 break;
566 case 9:
567 mnTypeId = 31; // AUTOLAYOUT_HANDOUT9
568 break;
569 default:
570 mnTypeId = 26; // AUTOLAYOUT_HANDOUT6
573 else
575 switch(maList.Count())
577 case 1:
579 if(pObj0->GetName().equals(OUString(RTL_CONSTASCII_USTRINGPARAM("title"))))
581 mnTypeId = 19; // AUTOLAYOUT_ONLY_TITLE
583 else
585 mnTypeId = 32; // AUTOLAYOUT_ONLY_TEXT
587 break;
589 case 2:
591 SdXMLPresentationPlaceholderContext* pObj1 = maList.GetObject(1);
593 if(pObj1->GetName().equals(
594 OUString(RTL_CONSTASCII_USTRINGPARAM("subtitle"))))
596 mnTypeId = 0; // AUTOLAYOUT_TITLE
598 else if(pObj1->GetName().equals(
599 OUString(RTL_CONSTASCII_USTRINGPARAM("outline"))))
601 mnTypeId = 1; // AUTOLAYOUT_ENUM
603 else if(pObj1->GetName().equals(
604 OUString(RTL_CONSTASCII_USTRINGPARAM("chart"))))
606 mnTypeId = 2; // AUTOLAYOUT_CHART
608 else if(pObj1->GetName().equals(
609 OUString(RTL_CONSTASCII_USTRINGPARAM("table"))))
611 mnTypeId = 8; // AUTOLAYOUT_TAB
613 else if(pObj1->GetName().equals(
614 OUString(RTL_CONSTASCII_USTRINGPARAM("object"))))
616 mnTypeId = 11; // AUTOLAYOUT_OBJ
618 else if(pObj1->GetName().equals(
619 OUString(RTL_CONSTASCII_USTRINGPARAM("vertical_outline"))))
621 if(pObj0->GetName().equals(OUString(RTL_CONSTASCII_USTRINGPARAM("vertical_title"))))
623 // AUTOLAYOUT_VERTICAL_TITLE_VERTICAL_OUTLINE
624 mnTypeId = 28;
626 else
628 // AUTOLAYOUT_TITLE_VERTICAL_OUTLINE
629 mnTypeId = 29;
632 else
634 mnTypeId = 21; // AUTOLAYOUT_NOTES
636 break;
638 case 3:
640 SdXMLPresentationPlaceholderContext* pObj1 = maList.GetObject(1);
641 SdXMLPresentationPlaceholderContext* pObj2 = maList.GetObject(2);
643 if(pObj1->GetName().equals(
644 OUString(RTL_CONSTASCII_USTRINGPARAM("outline"))))
646 if(pObj2->GetName().equals(
647 OUString(RTL_CONSTASCII_USTRINGPARAM("outline"))))
649 mnTypeId = 3; // AUTOLAYOUT_2TEXT
651 else if(pObj2->GetName().equals(
652 OUString(RTL_CONSTASCII_USTRINGPARAM("chart"))))
654 mnTypeId = 4; // AUTOLAYOUT_TEXTCHART
656 else if(pObj2->GetName().equals(
657 OUString(RTL_CONSTASCII_USTRINGPARAM("graphic"))))
659 mnTypeId = 6; // AUTOLAYOUT_TEXTCLIP
661 else
663 if(pObj1->GetX() < pObj2->GetX())
665 mnTypeId = 10; // AUTOLAYOUT_TEXTOBJ -> outline left, object right
667 else
669 mnTypeId = 17; // AUTOLAYOUT_TEXTOVEROBJ -> outline top, object right
673 else if(pObj1->GetName().equals(
674 OUString(RTL_CONSTASCII_USTRINGPARAM("chart"))))
676 mnTypeId = 7; // AUTOLAYOUT_CHARTTEXT
678 else if(pObj1->GetName().equals(
679 OUString(RTL_CONSTASCII_USTRINGPARAM("graphic"))))
681 if(pObj2->GetName().equals(OUString(RTL_CONSTASCII_USTRINGPARAM("vertical_outline"))))
683 // AUTOLAYOUT_TITLE_VERTICAL_OUTLINE_CLIPART
684 mnTypeId = 30;
686 else
688 mnTypeId = 9; // AUTOLAYOUT_CLIPTEXT
691 else if(pObj1->GetName().equals(
692 OUString(RTL_CONSTASCII_USTRINGPARAM("vertical_outline"))))
694 // AUTOLAYOUT_VERTICAL_TITLE_TEXT_CHART
695 mnTypeId = 27;
697 else
699 if(pObj1->GetX() < pObj2->GetX())
701 mnTypeId = 13; // AUTOLAYOUT_OBJTEXT -> left, right
703 else
705 mnTypeId = 14; // AUTOLAYOUT_OBJOVERTEXT -> top, bottom
708 break;
710 case 4:
712 SdXMLPresentationPlaceholderContext* pObj1 = maList.GetObject(1);
713 SdXMLPresentationPlaceholderContext* pObj2 = maList.GetObject(2);
715 if(pObj1->GetName().equals(
716 OUString(RTL_CONSTASCII_USTRINGPARAM("object"))))
718 if(pObj1->GetX() < pObj2->GetX())
720 mnTypeId = 16; // AUTOLAYOUT_2OBJOVERTEXT
722 else
724 mnTypeId = 15; // AUTOLAYOUT_2OBJTEXT
727 else
729 mnTypeId = 12; // AUTOLAYOUT_TEXT2OBJ
731 break;
733 case 5:
735 SdXMLPresentationPlaceholderContext* pObj1 = maList.GetObject(1);
737 if(pObj1->GetName().equals(
738 OUString(RTL_CONSTASCII_USTRINGPARAM("object"))))
740 mnTypeId = 18; // AUTOLAYOUT_4OBJ
742 else
744 mnTypeId = 33; // AUTOLAYOUT_4CLIPART
746 break;
749 case 7:
751 mnTypeId = 33; // AUTOLAYOUT_6CLIPART
752 break;
754 default:
756 mnTypeId = 20; // AUTOLAYOUT_NONE
757 break;
762 // release remembered contexts, they are no longer needed
763 while(maList.Count())
764 maList.Remove(maList.Count() - 1)->ReleaseRef();
768 //////////////////////////////////////////////////////////////////////////////
769 //////////////////////////////////////////////////////////////////////////////
771 SdXMLPresentationPlaceholderContext::SdXMLPresentationPlaceholderContext(
772 SdXMLImport& rImport,
773 sal_uInt16 nPrfx, const
774 OUString& rLName,
775 const uno::Reference< xml::sax::XAttributeList>& xAttrList)
776 : SvXMLImportContext( rImport, nPrfx, rLName),
777 mnX(0L),
778 mnY(0L),
779 mnWidth(1L),
780 mnHeight(1L)
782 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
783 for(sal_Int16 i=0; i < nAttrCount; i++)
785 OUString sAttrName = xAttrList->getNameByIndex(i);
786 OUString aLocalName;
787 sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName(sAttrName, &aLocalName);
788 OUString sValue = xAttrList->getValueByIndex(i);
789 const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetPresentationPlaceholderAttrTokenMap();
791 switch(rAttrTokenMap.Get(nPrefix, aLocalName))
793 case XML_TOK_PRESENTATIONPLACEHOLDER_OBJECTNAME:
795 msName = sValue;
796 break;
798 case XML_TOK_PRESENTATIONPLACEHOLDER_X:
800 GetSdImport().GetMM100UnitConverter().convertMeasure(mnX, sValue);
801 break;
803 case XML_TOK_PRESENTATIONPLACEHOLDER_Y:
805 GetSdImport().GetMM100UnitConverter().convertMeasure(mnY, sValue);
806 break;
808 case XML_TOK_PRESENTATIONPLACEHOLDER_WIDTH:
810 GetSdImport().GetMM100UnitConverter().convertMeasure(mnWidth, sValue);
811 break;
813 case XML_TOK_PRESENTATIONPLACEHOLDER_HEIGHT:
815 GetSdImport().GetMM100UnitConverter().convertMeasure(mnHeight, sValue);
816 break;
822 //////////////////////////////////////////////////////////////////////////////
824 SdXMLPresentationPlaceholderContext::~SdXMLPresentationPlaceholderContext()
828 //////////////////////////////////////////////////////////////////////////////
829 //////////////////////////////////////////////////////////////////////////////
831 TYPEINIT1( SdXMLMasterPageContext, SdXMLGenericPageContext );
833 SdXMLMasterPageContext::SdXMLMasterPageContext(
834 SdXMLImport& rImport,
835 sal_uInt16 nPrfx,
836 const OUString& rLName,
837 const uno::Reference< xml::sax::XAttributeList>& xAttrList,
838 uno::Reference< drawing::XShapes >& rShapes)
839 : SdXMLGenericPageContext( rImport, nPrfx, rLName, xAttrList, rShapes )
841 const sal_Bool bHandoutMaster = IsXMLToken( rLName, XML_HANDOUT_MASTER );
843 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
844 for(sal_Int16 i=0; i < nAttrCount; i++)
846 OUString sAttrName = xAttrList->getNameByIndex( i );
847 OUString aLocalName;
848 sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
849 OUString sValue = xAttrList->getValueByIndex( i );
850 const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetMasterPageAttrTokenMap();
852 switch(rAttrTokenMap.Get(nPrefix, aLocalName))
854 case XML_TOK_MASTERPAGE_NAME:
856 msName = sValue;
857 break;
859 case XML_TOK_MASTERPAGE_DISPLAY_NAME:
861 msDisplayName = sValue;
862 break;
864 case XML_TOK_MASTERPAGE_PAGE_MASTER_NAME:
866 msPageMasterName = sValue;
867 break;
869 case XML_TOK_MASTERPAGE_STYLE_NAME:
871 msStyleName = sValue;
872 break;
874 case XML_TOK_MASTERPAGE_PAGE_LAYOUT_NAME:
876 maPageLayoutName = sValue;
877 break;
879 case XML_TOK_MASTERPAGE_USE_HEADER_NAME:
881 maUseHeaderDeclName = sValue;
882 break;
884 case XML_TOK_MASTERPAGE_USE_FOOTER_NAME:
886 maUseFooterDeclName = sValue;
887 break;
889 case XML_TOK_MASTERPAGE_USE_DATE_TIME_NAME:
891 maUseDateTimeDeclName = sValue;
892 break;
897 if( !msDisplayName.getLength() )
898 msDisplayName = msName;
899 else if( msDisplayName != msName )
900 GetImport().AddStyleDisplayName( XML_STYLE_FAMILY_MASTER_PAGE, msName, msDisplayName );
902 GetImport().GetShapeImport()->startPage( GetLocalShapesContext() );
904 // set page name?
905 if(!bHandoutMaster && msDisplayName.getLength() && GetLocalShapesContext().is())
907 uno::Reference < container::XNamed > xNamed(GetLocalShapesContext(), uno::UNO_QUERY);
908 if(xNamed.is())
909 xNamed->setName(msDisplayName);
912 // set page-master?
913 if(msPageMasterName.getLength())
915 SetPageMaster( msPageMasterName );
918 SetStyle( msStyleName );
920 SetLayout();
922 DeleteAllShapes();
925 //////////////////////////////////////////////////////////////////////////////
927 SdXMLMasterPageContext::~SdXMLMasterPageContext()
931 //////////////////////////////////////////////////////////////////////////////
933 void SdXMLMasterPageContext::EndElement()
935 // set styles on master-page
936 if(msName.getLength() && GetSdImport().GetShapeImport()->GetStylesContext())
938 SvXMLImportContext* pContext = GetSdImport().GetShapeImport()->GetStylesContext();
939 if( pContext && pContext->ISA( SvXMLStyleContext ) )
940 ((SdXMLStylesContext*)pContext)->SetMasterPageStyles(*this);
943 SdXMLGenericPageContext::EndElement();
944 GetImport().GetShapeImport()->endPage(GetLocalShapesContext());
947 //////////////////////////////////////////////////////////////////////////////
949 SvXMLImportContext* SdXMLMasterPageContext::CreateChildContext(
950 sal_uInt16 nPrefix,
951 const OUString& rLocalName,
952 const uno::Reference< xml::sax::XAttributeList>& xAttrList )
954 SvXMLImportContext* pContext = 0;
955 const SvXMLTokenMap& rTokenMap = GetSdImport().GetMasterPageElemTokenMap();
957 // some special objects inside style:masterpage context
958 switch(rTokenMap.Get(nPrefix, rLocalName))
960 case XML_TOK_MASTERPAGE_STYLE:
962 if(GetSdImport().GetShapeImport()->GetStylesContext())
964 // style:style inside master-page context -> presentation style
965 XMLShapeStyleContext* pNew = new XMLShapeStyleContext(
966 GetSdImport(), nPrefix, rLocalName, xAttrList,
967 *GetSdImport().GetShapeImport()->GetStylesContext(),
968 XML_STYLE_FAMILY_SD_PRESENTATION_ID);
970 // add this style to the outer StylesContext class for later processing
971 if(pNew)
973 pContext = pNew;
974 GetSdImport().GetShapeImport()->GetStylesContext()->AddStyle(*pNew);
977 break;
979 case XML_TOK_MASTERPAGE_NOTES:
981 if( GetSdImport().IsImpress() )
983 // get notes page
984 uno::Reference< presentation::XPresentationPage > xPresPage(GetLocalShapesContext(), uno::UNO_QUERY);
985 if(xPresPage.is())
987 uno::Reference< drawing::XDrawPage > xNotesDrawPage(xPresPage->getNotesPage(), uno::UNO_QUERY);
988 if(xNotesDrawPage.is())
990 uno::Reference< drawing::XShapes > xNewShapes(xNotesDrawPage, uno::UNO_QUERY);
991 if(xNewShapes.is())
993 // presentation:notes inside master-page context
994 pContext = new SdXMLNotesContext( GetSdImport(), nPrefix, rLocalName, xAttrList, xNewShapes);
1002 // call base class
1003 if(!pContext)
1004 pContext = SdXMLGenericPageContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
1006 return pContext;
1009 //////////////////////////////////////////////////////////////////////////////
1010 //////////////////////////////////////////////////////////////////////////////
1012 TYPEINIT1( SdXMLStylesContext, SvXMLStyleContext );
1014 SdXMLStylesContext::SdXMLStylesContext(
1015 SdXMLImport& rImport,
1016 sal_uInt16 nPrfx,
1017 const OUString& rLName,
1018 const uno::Reference< xml::sax::XAttributeList >& xAttrList,
1019 sal_Bool bIsAutoStyle)
1020 : SvXMLStylesContext(rImport, nPrfx, rLName, xAttrList),
1021 mbIsAutoStyle(bIsAutoStyle)
1023 // #110680#
1024 // Reference< lang::XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory();
1025 Reference< lang::XMultiServiceFactory > xMSF = rImport.getServiceFactory();
1027 mpNumFormatter = new SvNumberFormatter( xMSF, LANGUAGE_SYSTEM );
1029 // #110680#
1030 // mpNumFmtHelper = new SvXMLNumFmtHelper( mpNumFormatter );
1031 mpNumFmtHelper = new SvXMLNumFmtHelper( mpNumFormatter, xMSF );
1034 //////////////////////////////////////////////////////////////////////////////
1036 SdXMLStylesContext::~SdXMLStylesContext()
1038 delete mpNumFmtHelper;
1039 delete mpNumFormatter;
1042 //////////////////////////////////////////////////////////////////////////////
1044 SvXMLStyleContext* SdXMLStylesContext::CreateStyleChildContext(
1045 sal_uInt16 nPrefix,
1046 const OUString& rLocalName,
1047 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
1049 SvXMLStyleContext* pContext = 0;
1050 const SvXMLTokenMap& rStyleTokenMap = GetSdImport().GetStylesElemTokenMap();
1052 switch(rStyleTokenMap.Get(nPrefix, rLocalName))
1054 case XML_TOK_STYLES_PAGE_MASTER:
1056 // style:page-master inside office:styles context
1057 pContext = new SdXMLPageMasterContext(GetSdImport(), nPrefix, rLocalName, xAttrList);
1058 break;
1060 case XML_TOK_STYLES_PRESENTATION_PAGE_LAYOUT:
1062 // style:presentation-page-layout inside office:styles context
1063 pContext = new SdXMLPresentationPageLayoutContext(GetSdImport(), nPrefix, rLocalName, xAttrList);
1064 break;
1068 if(!pContext)
1070 const SvXMLTokenMap& rTokenMap = mpNumFmtHelper->GetStylesElemTokenMap();
1071 sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
1072 switch (nToken)
1074 case XML_TOK_STYLES_DATE_STYLE:
1075 case XML_TOK_STYLES_TIME_STYLE:
1076 // number:date-style or number:time-style
1077 pContext = new SdXMLNumberFormatImportContext( GetSdImport(), nPrefix, rLocalName, mpNumFmtHelper->getData(), nToken, xAttrList, *this );
1078 break;
1080 case XML_TOK_STYLES_NUMBER_STYLE:
1081 case XML_TOK_STYLES_CURRENCY_STYLE:
1082 case XML_TOK_STYLES_PERCENTAGE_STYLE:
1083 case XML_TOK_STYLES_BOOLEAN_STYLE:
1084 case XML_TOK_STYLES_TEXT_STYLE:
1085 pContext = new SvXMLNumFormatContext( GetSdImport(), nPrefix, rLocalName,
1086 mpNumFmtHelper->getData(), nToken, xAttrList, *this );
1087 break;
1091 if(!pContext && nPrefix == XML_NAMESPACE_PRESENTATION )
1093 if( IsXMLToken( rLocalName, XML_HEADER_DECL ) ||
1094 IsXMLToken( rLocalName, XML_FOOTER_DECL ) ||
1095 IsXMLToken( rLocalName, XML_DATE_TIME_DECL ) )
1097 pContext = new SdXMLHeaderFooterDeclContext( GetImport(), nPrefix, rLocalName, xAttrList );
1101 if(!pContext && (nPrefix == XML_NAMESPACE_TABLE) && IsXMLToken( rLocalName, XML_TABLE_TEMPLATE ) )
1103 pContext = GetImport().GetShapeImport()->GetShapeTableImport()->CreateTableTemplateContext(nPrefix, rLocalName, xAttrList );
1106 // call base class
1107 if(!pContext)
1108 pContext = SvXMLStylesContext::CreateStyleChildContext(nPrefix, rLocalName, xAttrList);
1110 return pContext;
1113 //////////////////////////////////////////////////////////////////////////////
1115 SvXMLStyleContext* SdXMLStylesContext::CreateStyleStyleChildContext(
1116 sal_uInt16 nFamily,
1117 sal_uInt16 nPrefix,
1118 const OUString& rLocalName,
1119 const uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList)
1121 SvXMLStyleContext* pContext = 0;
1123 switch( nFamily )
1125 case XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID:
1126 pContext = new SdXMLDrawingPageStyleContext(GetSdImport(), nPrefix, rLocalName, xAttrList, *this );
1127 break;
1128 case XML_STYLE_FAMILY_TABLE_CELL:
1129 case XML_STYLE_FAMILY_TABLE_COLUMN:
1130 case XML_STYLE_FAMILY_TABLE_ROW:
1131 pContext = new XMLShapeStyleContext( GetSdImport(), nPrefix, rLocalName, xAttrList, *this, nFamily );
1132 break;
1135 // call base class
1136 if(!pContext)
1137 pContext = SvXMLStylesContext::CreateStyleStyleChildContext(nFamily, nPrefix, rLocalName, xAttrList);
1139 return pContext;
1142 //////////////////////////////////////////////////////////////////////////////
1144 SvXMLStyleContext* SdXMLStylesContext::CreateDefaultStyleStyleChildContext(
1145 sal_uInt16 nFamily,
1146 sal_uInt16 nPrefix,
1147 const OUString& rLocalName,
1148 const Reference< XAttributeList > & xAttrList )
1150 SvXMLStyleContext* pContext = 0;
1152 switch( nFamily )
1154 case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
1155 pContext = new XMLGraphicsDefaultStyle(GetSdImport(), nPrefix, rLocalName, xAttrList, *this );
1156 break;
1159 // call base class
1160 if(!pContext)
1161 pContext = SvXMLStylesContext::CreateDefaultStyleStyleChildContext(nFamily, nPrefix, rLocalName, xAttrList);
1163 return pContext;
1166 //////////////////////////////////////////////////////////////////////////////
1168 sal_uInt16 SdXMLStylesContext::GetFamily( const OUString& rFamily ) const
1170 // if(rFamily.getLength())
1171 // {
1172 // if(rFamily.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_SD_GRAPHICS_NAME))))
1173 // return XML_STYLE_FAMILY_SD_GRAPHICS_ID;
1175 // if(rFamily.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_SD_PRESENTATION_NAME))))
1176 // return XML_STYLE_FAMILY_SD_PRESENTATION_ID;
1178 // if(rFamily.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_SD_POOL_NAME))))
1179 // return XML_STYLE_FAMILY_SD_POOL_ID;
1181 // if(rFamily.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME))))
1182 // return XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID;
1183 // }
1185 // call base class
1186 return SvXMLStylesContext::GetFamily(rFamily);
1189 //////////////////////////////////////////////////////////////////////////////
1191 UniReference< SvXMLImportPropertyMapper > SdXMLStylesContext::GetImportPropertyMapper(
1192 sal_uInt16 nFamily) const
1194 UniReference < SvXMLImportPropertyMapper > xMapper;
1196 // if(XML_STYLE_FAMILY_SD_GRAPHICS_ID == nFamily
1197 // || XML_STYLE_FAMILY_SD_PRESENTATION_ID == nFamily
1198 // || XML_STYLE_FAMILY_SD_POOL_ID == nFamily)
1199 // {
1200 // if(!xPropImpPropMapper.is())
1201 // {
1202 // UniReference< XMLShapeImportHelper > aImpHelper = ((SvXMLImport&)GetImport()).GetShapeImport();
1203 // ((SdXMLStylesContext*)this)->xPropImpPropMapper =
1204 // new SvXMLImportPropertyMapper(aImpHelper->GetPropertySetMapper());
1205 // }
1206 // xMapper = xPropImpPropMapper;
1207 // return xMapper;
1208 // }
1210 switch( nFamily )
1212 case XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID:
1214 if(!xPresImpPropMapper.is())
1216 UniReference< XMLShapeImportHelper > aImpHelper = ((SvXMLImport&)GetImport()).GetShapeImport();
1217 ((SdXMLStylesContext*)this)->xPresImpPropMapper =
1218 aImpHelper->GetPresPagePropsMapper();
1220 xMapper = xPresImpPropMapper;
1221 break;
1224 case XML_STYLE_FAMILY_TABLE_COLUMN:
1225 case XML_STYLE_FAMILY_TABLE_ROW:
1226 case XML_STYLE_FAMILY_TABLE_CELL:
1228 const rtl::Reference< XMLTableImport >& xTableImport( const_cast< SvXMLImport& >( GetImport() ).GetShapeImport()->GetShapeTableImport() );
1230 switch( nFamily )
1232 case XML_STYLE_FAMILY_TABLE_COLUMN: xMapper = xTableImport->GetColumnImportPropertySetMapper().get(); break;
1233 case XML_STYLE_FAMILY_TABLE_ROW: xMapper = xTableImport->GetRowImportPropertySetMapper().get(); break;
1234 case XML_STYLE_FAMILY_TABLE_CELL: xMapper = xTableImport->GetCellImportPropertySetMapper().get(); break;
1236 break;
1240 // call base class
1241 if( !xMapper.is() )
1242 xMapper = SvXMLStylesContext::GetImportPropertyMapper(nFamily);
1243 return xMapper;
1246 //////////////////////////////////////////////////////////////////////////////
1247 // Process all style and object info
1249 void SdXMLStylesContext::EndElement()
1251 if(mbIsAutoStyle)
1253 // AutoStyles for text import
1254 GetImport().GetTextImport()->SetAutoStyles( this );
1256 // AutoStyles for chart
1257 GetImport().GetChartImport()->SetAutoStylesContext( this );
1259 // AutoStyles for forms
1260 GetImport().GetFormImport()->setAutoStyleContext( this );
1262 // associate AutoStyles with styles in preparation to setting Styles on shapes
1263 for(sal_uInt32 a(0L); a < GetStyleCount(); a++)
1265 const SvXMLStyleContext* pStyle = GetStyle(a);
1266 if(pStyle && pStyle->ISA(XMLShapeStyleContext))
1268 XMLShapeStyleContext* pDocStyle = (XMLShapeStyleContext*)pStyle;
1269 // pDocStyle->Filter();
1271 SvXMLStylesContext* pStylesContext = GetSdImport().GetShapeImport()->GetStylesContext();
1272 if( pStylesContext )
1274 pStyle = pStylesContext->FindStyleChildContext(pStyle->GetFamily(), pStyle->GetParentName());
1276 if(pStyle && pStyle->ISA(XMLShapeStyleContext))
1278 XMLShapeStyleContext* pParentStyle = (XMLShapeStyleContext*)pStyle;
1279 if(pParentStyle->GetStyle().is())
1281 pDocStyle->SetStyle(pParentStyle->GetStyle());
1288 FinishStyles( false );
1290 else
1292 // Process styles list
1293 ImpSetGraphicStyles();
1294 ImpSetCellStyles();
1295 GetImport().GetShapeImport()->GetShapeTableImport()->finishStyles();
1297 // put style infos in the info set for other components ( content import f.e. )
1298 uno::Reference< beans::XPropertySet > xInfoSet( GetImport().getImportInfo() );
1299 if( xInfoSet.is() )
1301 uno::Reference< beans::XPropertySetInfo > xInfoSetInfo( xInfoSet->getPropertySetInfo() );
1303 if( xInfoSetInfo->hasPropertyByName( OUString( RTL_CONSTASCII_USTRINGPARAM( "PageLayouts" ) ) ) )
1304 xInfoSet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "PageLayouts" ) ), uno::makeAny( getPageLayouts() ) );
1310 //////////////////////////////////////////////////////////////////////////////
1311 // set master-page styles (all with family="presentation" and a special
1312 // prefix) on given master-page.
1314 void SdXMLStylesContext::SetMasterPageStyles(SdXMLMasterPageContext& rMaster) const
1316 UniString sPrefix(rMaster.GetDisplayName(), (sal_uInt16)rMaster.GetDisplayName().getLength());
1317 sPrefix += sal_Unicode('-');
1319 if(GetSdImport().GetLocalDocStyleFamilies().is() && GetSdImport().GetLocalDocStyleFamilies()->hasByName(rMaster.GetDisplayName())) try
1321 uno::Reference< container::XNameAccess > xMasterPageStyles( GetSdImport().GetLocalDocStyleFamilies()->getByName(rMaster.GetDisplayName()), UNO_QUERY_THROW );
1322 ImpSetGraphicStyles(xMasterPageStyles, XML_STYLE_FAMILY_SD_PRESENTATION_ID, sPrefix);
1324 catch( uno::Exception& )
1326 DBG_ERROR( "xmloff::SdXMLStylesContext::SetMasterPageStyles(), exception caught!" );
1330 //////////////////////////////////////////////////////////////////////////////
1331 // Process styles list:
1332 // set graphic styles (all with family="graphics"). Remember xStyle at list element.
1334 void SdXMLStylesContext::ImpSetGraphicStyles() const
1336 if(GetSdImport().GetLocalDocStyleFamilies().is()) try
1338 const OUString sGraphicStyleName(OUString(RTL_CONSTASCII_USTRINGPARAM("graphics")));
1339 uno::Reference< container::XNameAccess > xGraphicPageStyles( GetSdImport().GetLocalDocStyleFamilies()->getByName(sGraphicStyleName), uno::UNO_QUERY_THROW );
1341 UniString aPrefix;
1342 ImpSetGraphicStyles(xGraphicPageStyles, XML_STYLE_FAMILY_SD_GRAPHICS_ID, aPrefix);
1344 catch( uno::Exception& )
1346 DBG_ERROR( "xmloff::SdXMLStylesContext::ImpSetGraphicStyles(), exception caught!" );
1350 void SdXMLStylesContext::ImpSetCellStyles() const
1352 if(GetSdImport().GetLocalDocStyleFamilies().is()) try
1354 const OUString sCellStyleName(OUString(RTL_CONSTASCII_USTRINGPARAM("cell")));
1355 uno::Reference< container::XNameAccess > xGraphicPageStyles( GetSdImport().GetLocalDocStyleFamilies()->getByName(sCellStyleName), uno::UNO_QUERY_THROW );
1357 UniString aPrefix;
1358 ImpSetGraphicStyles(xGraphicPageStyles, XML_STYLE_FAMILY_TABLE_CELL, aPrefix);
1360 catch( uno::Exception& )
1362 DBG_ERROR( "xmloff::SdXMLStylesContext::ImpSetCellStyles(), exception caught!" );
1366 //////////////////////////////////////////////////////////////////////////////
1367 // help function used by ImpSetGraphicStyles() and ImpSetMasterPageStyles()
1369 void SdXMLStylesContext::ImpSetGraphicStyles( uno::Reference< container::XNameAccess >& xPageStyles, sal_uInt16 nFamily, const UniString& rPrefix) const
1371 xub_StrLen nPrefLen(rPrefix.Len());
1373 sal_uInt32 a;
1375 // set defaults
1376 for( a = 0; a < GetStyleCount(); a++)
1378 const SvXMLStyleContext* pStyle = GetStyle(a);
1380 if(nFamily == pStyle->GetFamily() && pStyle->IsDefaultStyle())
1382 ((SvXMLStyleContext*)pStyle)->SetDefaults();
1386 // create all styles and set properties
1387 for( a = 0; a < GetStyleCount(); a++)
1391 const SvXMLStyleContext* pStyle = GetStyle(a);
1392 if(nFamily == pStyle->GetFamily() && !pStyle->IsDefaultStyle())
1394 OUString aStyleName(pStyle->GetDisplayName());
1395 if( nPrefLen )
1397 sal_Int32 nStylePrefLen = aStyleName.lastIndexOf( sal_Unicode('-') ) + 1;
1398 if( (nPrefLen != nStylePrefLen) || (aStyleName.compareTo( rPrefix, nPrefLen ) != 0) )
1399 continue;
1401 aStyleName = aStyleName.copy( nPrefLen );
1404 uno::Reference< style::XStyle > xStyle;
1405 if(xPageStyles->hasByName(aStyleName))
1407 xPageStyles->getByName(aStyleName) >>= xStyle;
1409 // set properties of existing styles to default
1410 uno::Reference< beans::XPropertySet > xPropSet( xStyle, uno::UNO_QUERY );
1411 uno::Reference< beans::XPropertySetInfo > xPropSetInfo;
1412 if( xPropSet.is() )
1413 xPropSetInfo = xPropSet->getPropertySetInfo();
1415 uno::Reference< beans::XPropertyState > xPropState( xStyle, uno::UNO_QUERY );
1417 if( xPropState.is() )
1419 UniReference < XMLPropertySetMapper > xPrMap;
1420 UniReference < SvXMLImportPropertyMapper > xImpPrMap = GetImportPropertyMapper( nFamily );
1421 DBG_ASSERT( xImpPrMap.is(), "There is the import prop mapper" );
1422 if( xImpPrMap.is() )
1423 xPrMap = xImpPrMap->getPropertySetMapper();
1424 if( xPrMap.is() )
1426 const sal_Int32 nCount = xPrMap->GetEntryCount();
1427 for( sal_Int32 i = 0; i < nCount; i++ )
1429 const OUString& rName = xPrMap->GetEntryAPIName( i );
1430 if( xPropSetInfo->hasPropertyByName( rName ) && beans::PropertyState_DIRECT_VALUE == xPropState->getPropertyState( rName ) )
1432 xPropState->setPropertyToDefault( rName );
1438 else
1440 // graphics style does not exist, create and add it
1441 uno::Reference< lang::XSingleServiceFactory > xServiceFact(xPageStyles, uno::UNO_QUERY);
1442 if(xServiceFact.is())
1444 uno::Reference< style::XStyle > xNewStyle( xServiceFact->createInstance(), uno::UNO_QUERY);
1446 if(xNewStyle.is())
1448 // remember style
1449 xStyle = xNewStyle;
1451 // add new style to graphics style pool
1452 uno::Reference< container::XNameContainer > xInsertContainer(xPageStyles, uno::UNO_QUERY);
1453 if(xInsertContainer.is())
1454 xInsertContainer->insertByName(aStyleName, uno::Any( xStyle ) );
1459 if(xStyle.is())
1461 // set properties at style
1462 XMLPropStyleContext* pPropStyle = dynamic_cast< XMLPropStyleContext* >( const_cast< SvXMLStyleContext* >( pStyle ) );
1463 uno::Reference< beans::XPropertySet > xPropSet(xStyle, uno::UNO_QUERY);
1465 if(xPropSet.is() && pPropStyle)
1467 pPropStyle->FillPropertySet(xPropSet);
1468 pPropStyle->SetStyle(xStyle);
1473 catch( Exception& e)
1475 uno::Sequence<OUString> aSeq(0);
1476 const_cast<SdXMLImport*>(&GetSdImport())->SetError( XMLERROR_FLAG_WARNING | XMLERROR_API, aSeq, e.Message, NULL );
1480 // now set parents for all styles (when necessary)
1481 for(a = 0L; a < GetStyleCount(); a++)
1483 const SvXMLStyleContext* pStyle = GetStyle(a);
1485 if(pStyle && pStyle->GetName().getLength() && (nFamily == pStyle->GetFamily())) try
1487 OUString aStyleName(pStyle->GetDisplayName());
1488 if( nPrefLen )
1490 sal_Int32 nStylePrefLen = aStyleName.lastIndexOf( sal_Unicode('-') ) + 1;
1491 if( (nPrefLen != nStylePrefLen) || (aStyleName.compareTo( rPrefix, nPrefLen ) != 0) )
1492 continue;
1494 aStyleName = aStyleName.copy( nPrefLen );
1497 uno::Reference< style::XStyle > xStyle( xPageStyles->getByName(aStyleName), UNO_QUERY );
1498 if(xStyle.is())
1500 // set parent style name
1501 ::rtl::OUString sParentStyleDisplayName( const_cast< SvXMLImport& >( GetImport() ).GetStyleDisplayName( pStyle->GetFamily(), pStyle->GetParentName() ) );
1502 if( nPrefLen )
1504 sal_Int32 nStylePrefLen = sParentStyleDisplayName.lastIndexOf( sal_Unicode('-') ) + 1;
1505 if( (nPrefLen != nStylePrefLen) || (sParentStyleDisplayName.compareTo( rPrefix, nPrefLen ) != 0) )
1506 continue;
1508 sParentStyleDisplayName = sParentStyleDisplayName.copy( nPrefLen );
1510 xStyle->setParentStyle( sParentStyleDisplayName );
1513 catch( Exception& e )
1515 uno::Sequence<OUString> aSeq(0);
1516 const_cast<SdXMLImport*>(&GetSdImport())->SetError( XMLERROR_FLAG_WARNING | XMLERROR_API, aSeq, e.Message, NULL );
1521 ////////////////////////////////////////////////////////////////////////////////
1522 // helper function to create the uno component that hold the mappings from
1523 // xml auto layout name to internal autolayout id
1525 uno::Reference< container::XNameAccess > SdXMLStylesContext::getPageLayouts() const
1527 uno::Reference< container::XNameContainer > xLayouts( comphelper::NameContainer_createInstance( ::getCppuType((const sal_Int32*)0)) );
1529 for(sal_uInt32 a(0L); a < GetStyleCount(); a++)
1531 const SvXMLStyleContext* pStyle = GetStyle(a);
1532 if(pStyle && pStyle->ISA(SdXMLPresentationPageLayoutContext))
1534 xLayouts->insertByName( pStyle->GetName(), uno::makeAny(
1535 (sal_Int32)((SdXMLPresentationPageLayoutContext*)pStyle)->GetTypeId() ) );
1539 return uno::Reference< container::XNameAccess >::query( xLayouts );
1542 ////////////////////////////////////////////////////////////////////////////////
1543 ////////////////////////////////////////////////////////////////////////////////
1545 TYPEINIT1( SdXMLMasterStylesContext, SvXMLImportContext );
1547 SdXMLMasterStylesContext::SdXMLMasterStylesContext(
1548 SdXMLImport& rImport,
1549 sal_uInt16 nPrfx,
1550 const rtl::OUString& rLName)
1551 : SvXMLImportContext( rImport, nPrfx, rLName)
1555 SdXMLMasterStylesContext::~SdXMLMasterStylesContext()
1557 while(maMasterPageList.Count())
1558 maMasterPageList.Remove(maMasterPageList.Count() - 1)->ReleaseRef();
1561 SvXMLImportContext* SdXMLMasterStylesContext::CreateChildContext(
1562 sal_uInt16 nPrefix,
1563 const rtl::OUString& rLocalName,
1564 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
1566 SvXMLImportContext* pContext = 0;
1568 if(nPrefix == XML_NAMESPACE_STYLE
1569 && IsXMLToken( rLocalName, XML_MASTER_PAGE ) )
1571 // style:masterpage inside office:styles context
1572 uno::Reference< drawing::XDrawPage > xNewMasterPage;
1573 uno::Reference< drawing::XDrawPages > xMasterPages(GetSdImport().GetLocalMasterPages(), uno::UNO_QUERY);
1575 if( xMasterPages.is() )
1577 if(GetSdImport().GetNewMasterPageCount() + 1 > xMasterPages->getCount())
1579 // new page, create and insert
1580 xNewMasterPage = xMasterPages->insertNewByIndex(xMasterPages->getCount());
1582 else
1584 // existing page, use it
1585 xMasterPages->getByIndex(GetSdImport().GetNewMasterPageCount()) >>= xNewMasterPage;
1588 // increment global import page counter
1589 GetSdImport().IncrementNewMasterPageCount();
1591 if(xNewMasterPage.is())
1593 uno::Reference< drawing::XShapes > xNewShapes(xNewMasterPage, uno::UNO_QUERY);
1594 if(xNewShapes.is() && GetSdImport().GetShapeImport()->GetStylesContext())
1596 pContext = new SdXMLMasterPageContext(GetSdImport(),
1597 nPrefix, rLocalName, xAttrList, xNewShapes);
1599 if(pContext)
1601 pContext->AddRef();
1602 maMasterPageList.Insert((SdXMLMasterPageContext*)pContext, LIST_APPEND);
1608 else if(nPrefix == XML_NAMESPACE_STYLE
1609 && IsXMLToken( rLocalName, XML_HANDOUT_MASTER ) )
1611 uno::Reference< presentation::XHandoutMasterSupplier > xHandoutSupp( GetSdImport().GetModel(), uno::UNO_QUERY );
1612 if( xHandoutSupp.is() )
1614 uno::Reference< drawing::XShapes > xHandoutPage( xHandoutSupp->getHandoutMasterPage(), uno::UNO_QUERY );
1615 if(xHandoutPage.is() && GetSdImport().GetShapeImport()->GetStylesContext())
1617 pContext = new SdXMLMasterPageContext(GetSdImport(),
1618 nPrefix, rLocalName, xAttrList, xHandoutPage);
1622 else if( (nPrefix == XML_NAMESPACE_DRAW )&& IsXMLToken( rLocalName, XML_LAYER_SET ) )
1624 pContext = new SdXMLLayerSetContext( GetImport(), nPrefix, rLocalName, xAttrList );
1627 // call base class
1628 if(!pContext)
1629 pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
1631 return pContext;
1634 ///////////////////////////////////////////////////////////////////////
1636 SdXMLHeaderFooterDeclContext::SdXMLHeaderFooterDeclContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
1637 const ::rtl::OUString& rLName,
1638 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList )
1639 : SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList )
1641 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1642 for(sal_Int16 i=0; i < nAttrCount; i++)
1644 OUString aLocalName;
1645 const OUString aValue( xAttrList->getValueByIndex(i) );
1646 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(xAttrList->getNameByIndex(i), &aLocalName);
1648 if( nPrefix == XML_NAMESPACE_PRESENTATION )
1650 if( IsXMLToken( aLocalName, XML_NAME ) )
1652 maStrName = aValue;
1654 else if( IsXMLToken( aLocalName, XML_SOURCE ) )
1656 mbFixed = IsXMLToken( aValue, XML_FIXED );
1659 else if( nPrefix == XML_NAMESPACE_STYLE )
1661 if( IsXMLToken( aLocalName, XML_DATA_STYLE_NAME ) )
1663 maStrDateTimeFormat = aValue;
1669 BOOL SdXMLHeaderFooterDeclContext::IsTransient() const
1671 return TRUE;
1674 void SdXMLHeaderFooterDeclContext::EndElement()
1676 SdXMLImport& rImport = *dynamic_cast< SdXMLImport* >( &GetImport() );
1677 if( IsXMLToken( GetLocalName(), XML_HEADER_DECL ) )
1679 rImport.AddHeaderDecl( maStrName, maStrText );
1681 else if( IsXMLToken( GetLocalName(), XML_FOOTER_DECL ) )
1683 rImport.AddFooterDecl( maStrName, maStrText );
1685 else if( IsXMLToken( GetLocalName(), XML_DATE_TIME_DECL ) )
1687 rImport.AddDateTimeDecl( maStrName, maStrText, mbFixed, maStrDateTimeFormat );
1691 void SdXMLHeaderFooterDeclContext::Characters( const ::rtl::OUString& rChars )
1693 maStrText += rChars;