bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / draw / ximpstyl.cxx
bloba490221f8010cbc6d688206ab89832d68bdf21a6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "ximpstyl.hxx"
21 #include <xmloff/XMLShapeStyleContext.hxx>
22 #include <xmloff/xmlnmspe.hxx>
23 #include <xmloff/xmltoken.hxx>
24 #include <xmloff/xmluconv.hxx>
25 #include "ximpnote.hxx"
26 #include <tools/debug.hxx>
27 #include <osl/diagnose.h>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
31 #include <com/sun/star/presentation/XPresentationPage.hpp>
32 #include <com/sun/star/drawing/XDrawPages.hpp>
33 #include <com/sun/star/container/XNamed.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/beans/XPropertyState.hpp>
36 #include <com/sun/star/presentation/XHandoutMasterSupplier.hpp>
37 #include <comphelper/namecontainer.hxx>
38 #include <xmloff/xmlprcon.hxx>
39 #include <xmloff/families.hxx>
40 #include <com/sun/star/container/XNameContainer.hpp>
41 #include <svl/zforlist.hxx>
42 #include "PropertySetMerger.hxx"
43 #include "sdpropls.hxx"
44 #include "layerimp.hxx"
45 #include <xmloff/XMLGraphicsDefaultStyle.hxx>
46 #include "XMLNumberStylesImport.hxx"
47 #include <xmloff/xmlerror.hxx>
49 using namespace ::com::sun::star;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::xml::sax;
52 using namespace ::xmloff::token;
54 class SdXMLDrawingPagePropertySetContext : public SvXMLPropertySetContext
56 public:
58 TYPEINFO_OVERRIDE();
60 SdXMLDrawingPagePropertySetContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
61 const OUString& rLName,
62 const ::com::sun::star::uno::Reference<
63 ::com::sun::star::xml::sax::XAttributeList >& xAttrList,
64 ::std::vector< XMLPropertyState > &rProps,
65 const rtl::Reference < SvXMLImportPropertyMapper > &rMap );
67 virtual ~SdXMLDrawingPagePropertySetContext();
69 using SvXMLPropertySetContext::CreateChildContext;
70 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
71 const OUString& rLocalName,
72 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList,
73 ::std::vector< XMLPropertyState > &rProperties,
74 const XMLPropertyState& rProp) SAL_OVERRIDE;
77 TYPEINIT1( SdXMLDrawingPagePropertySetContext, SvXMLPropertySetContext );
79 SdXMLDrawingPagePropertySetContext::SdXMLDrawingPagePropertySetContext(
80 SvXMLImport& rImport, sal_uInt16 nPrfx,
81 const OUString& rLName,
82 const uno::Reference< xml::sax::XAttributeList > & xAttrList,
83 ::std::vector< XMLPropertyState > &rProps,
84 const rtl::Reference < SvXMLImportPropertyMapper > &rMap ) :
85 SvXMLPropertySetContext( rImport, nPrfx, rLName, xAttrList,
86 XML_TYPE_PROP_DRAWING_PAGE, rProps, rMap )
90 SdXMLDrawingPagePropertySetContext::~SdXMLDrawingPagePropertySetContext()
94 SvXMLImportContext *SdXMLDrawingPagePropertySetContext::CreateChildContext(
95 sal_uInt16 p_nPrefix,
96 const OUString& rLocalName,
97 const uno::Reference< xml::sax::XAttributeList > & xAttrList,
98 ::std::vector< XMLPropertyState > &rProperties,
99 const XMLPropertyState& rProp )
101 SvXMLImportContext *pContext = 0;
103 switch( mxMapper->getPropertySetMapper()->GetEntryContextId( rProp.mnIndex ) )
105 case CTF_PAGE_SOUND_URL:
107 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
108 for(sal_Int16 i=0; i < nAttrCount; i++)
110 OUString aLocalName;
111 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(xAttrList->getNameByIndex(i), &aLocalName);
113 if( (nPrefix == XML_NAMESPACE_XLINK) && IsXMLToken( aLocalName, XML_HREF ) )
115 uno::Any aAny( GetImport().GetAbsoluteReference( xAttrList->getValueByIndex(i) ) );
116 XMLPropertyState aPropState( rProp.mnIndex, aAny );
117 rProperties.push_back( aPropState );
120 break;
124 if( !pContext )
125 pContext = SvXMLPropertySetContext::CreateChildContext( p_nPrefix, rLocalName,
126 xAttrList,
127 rProperties, rProp );
129 return pContext;
132 class SdXMLDrawingPageStyleContext : public XMLPropStyleContext
134 public:
135 TYPEINFO_OVERRIDE();
137 SdXMLDrawingPageStyleContext(
138 SvXMLImport& rImport,
139 sal_uInt16 nPrfx,
140 const OUString& rLName,
141 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList,
142 SvXMLStylesContext& rStyles,
143 sal_uInt16 nFamily = XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID);
144 virtual ~SdXMLDrawingPageStyleContext();
146 SvXMLImportContext * CreateChildContext(
147 sal_uInt16 nPrefix,
148 const OUString& rLocalName,
149 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
151 virtual void Finish( bool bOverwrite ) SAL_OVERRIDE;
153 // #i35918#
154 virtual void FillPropertySet(
155 const ::com::sun::star::uno::Reference<
156 ::com::sun::star::beans::XPropertySet > & rPropSet ) SAL_OVERRIDE;
159 TYPEINIT1( SdXMLDrawingPageStyleContext, XMLPropStyleContext );
161 SdXMLDrawingPageStyleContext::SdXMLDrawingPageStyleContext(
162 SvXMLImport& rImport,
163 sal_uInt16 nPrfx,
164 const OUString& rLName,
165 const uno::Reference< xml::sax::XAttributeList >& xAttrList,
166 SvXMLStylesContext& rStyles,
167 sal_uInt16 nFamily)
168 : XMLPropStyleContext(rImport, nPrfx, rLName, xAttrList, rStyles, nFamily )
172 SdXMLDrawingPageStyleContext::~SdXMLDrawingPageStyleContext()
176 SvXMLImportContext *SdXMLDrawingPageStyleContext::CreateChildContext(
177 sal_uInt16 nPrefix,
178 const OUString& rLocalName,
179 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
181 SvXMLImportContext *pContext = 0;
183 if( XML_NAMESPACE_STYLE == nPrefix &&
184 IsXMLToken( rLocalName, XML_DRAWING_PAGE_PROPERTIES ) )
186 rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap =
187 GetStyles()->GetImportPropertyMapper( GetFamily() );
188 if( xImpPrMap.is() )
189 pContext = new SdXMLDrawingPagePropertySetContext( GetImport(), nPrefix,
190 rLocalName, xAttrList,
191 GetProperties(),
192 xImpPrMap );
195 if( !pContext )
196 pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName,
197 xAttrList );
199 return pContext;
202 void SdXMLDrawingPageStyleContext::Finish( bool bOverwrite )
204 XMLPropStyleContext::Finish( bOverwrite );
206 ::std::vector< XMLPropertyState > &rProperties = GetProperties();
208 const rtl::Reference< XMLPropertySetMapper >& rImpPrMap = GetStyles()->GetImportPropertyMapper( GetFamily() )->getPropertySetMapper();
210 ::std::vector< XMLPropertyState >::iterator property = rProperties.begin();
211 for(; property != rProperties.end(); ++property)
213 if( property->mnIndex == -1 )
214 continue;
216 sal_Int16 nContextID = rImpPrMap->GetEntryContextId(property->mnIndex);
217 switch( nContextID )
219 case CTF_DATE_TIME_FORMAT:
221 OUString sStyleName;
222 (*property).maValue >>= sStyleName;
224 sal_Int32 nStyle = 0;
226 const SdXMLNumberFormatImportContext* pSdNumStyle =
227 PTR_CAST( SdXMLNumberFormatImportContext,
228 GetStyles()->FindStyleChildContext( XML_STYLE_FAMILY_DATA_STYLE, sStyleName, true ) );
230 if( pSdNumStyle )
231 nStyle = pSdNumStyle->GetDrawKey();
233 (*property).maValue <<= nStyle;
235 break;
241 // #i35918#
242 void SdXMLDrawingPageStyleContext::FillPropertySet(
243 const Reference< beans::XPropertySet > & rPropSet )
245 static const sal_uInt16 MAX_SPECIAL_DRAW_STYLES = 7;
246 struct _ContextID_Index_Pair aContextIDs[MAX_SPECIAL_DRAW_STYLES+1] =
248 { CTF_DASHNAME , -1 },
249 { CTF_LINESTARTNAME , -1 },
250 { CTF_LINEENDNAME , -1 },
251 { CTF_FILLGRADIENTNAME, -1 },
252 { CTF_FILLTRANSNAME , -1 },
253 { CTF_FILLHATCHNAME , -1 },
254 { CTF_FILLBITMAPNAME , -1 },
255 { -1, -1 }
257 static const sal_uInt16 aFamilies[MAX_SPECIAL_DRAW_STYLES] =
259 XML_STYLE_FAMILY_SD_STROKE_DASH_ID,
260 XML_STYLE_FAMILY_SD_MARKER_ID,
261 XML_STYLE_FAMILY_SD_MARKER_ID,
262 XML_STYLE_FAMILY_SD_GRADIENT_ID,
263 XML_STYLE_FAMILY_SD_GRADIENT_ID,
264 XML_STYLE_FAMILY_SD_HATCH_ID,
265 XML_STYLE_FAMILY_SD_FILL_IMAGE_ID
268 rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap =
269 GetStyles()->GetImportPropertyMapper( GetFamily() );
270 DBG_ASSERT( xImpPrMap.is(), "There is the import prop mapper" );
271 if( xImpPrMap.is() )
272 xImpPrMap->FillPropertySet( GetProperties(), rPropSet, aContextIDs );
274 Reference< beans::XPropertySetInfo > xInfo;
275 for( sal_uInt16 i=0; i<MAX_SPECIAL_DRAW_STYLES; i++ )
277 sal_Int32 nIndex = aContextIDs[i].nIndex;
278 if( nIndex != -1 )
280 struct XMLPropertyState& rState = GetProperties()[nIndex];
281 OUString sStyleName;
282 rState.maValue >>= sStyleName;
283 sStyleName = GetImport().GetStyleDisplayName( aFamilies[i],
284 sStyleName );
285 // get property set mapper
286 rtl::Reference<XMLPropertySetMapper> rPropMapper =
287 xImpPrMap->getPropertySetMapper();
289 // set property
290 const OUString& rPropertyName =
291 rPropMapper->GetEntryAPIName(rState.mnIndex);
292 if( !xInfo.is() )
293 xInfo = rPropSet->getPropertySetInfo();
294 if ( xInfo->hasPropertyByName( rPropertyName ) )
296 rPropSet->setPropertyValue( rPropertyName, Any( sStyleName ) );
302 TYPEINIT1( SdXMLPageMasterStyleContext, SvXMLStyleContext );
304 SdXMLPageMasterStyleContext::SdXMLPageMasterStyleContext(
305 SdXMLImport& rImport,
306 sal_uInt16 nPrfx,
307 const OUString& rLName,
308 const uno::Reference< xml::sax::XAttributeList>& xAttrList)
309 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_SD_PAGEMASTERSTYLECONEXT_ID),
310 mnBorderBottom( 0L ),
311 mnBorderLeft( 0L ),
312 mnBorderRight( 0L ),
313 mnBorderTop( 0L ),
314 mnWidth( 0L ),
315 mnHeight( 0L ),
316 meOrientation(GetSdImport().IsDraw() ? view::PaperOrientation_PORTRAIT : view::PaperOrientation_LANDSCAPE)
318 // set family to something special at SvXMLStyleContext
319 // for differences in search-methods
321 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
322 for(sal_Int16 i=0; i < nAttrCount; i++)
324 OUString sAttrName = xAttrList->getNameByIndex(i);
325 OUString aLocalName;
326 sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName(sAttrName, &aLocalName);
327 OUString sValue = xAttrList->getValueByIndex(i);
328 const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetPageMasterStyleAttrTokenMap();
330 switch(rAttrTokenMap.Get(nPrefix, aLocalName))
332 case XML_TOK_PAGEMASTERSTYLE_MARGIN_TOP:
334 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
335 mnBorderTop, sValue);
336 break;
338 case XML_TOK_PAGEMASTERSTYLE_MARGIN_BOTTOM:
340 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
341 mnBorderBottom, sValue);
342 break;
344 case XML_TOK_PAGEMASTERSTYLE_MARGIN_LEFT:
346 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
347 mnBorderLeft, sValue);
348 break;
350 case XML_TOK_PAGEMASTERSTYLE_MARGIN_RIGHT:
352 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
353 mnBorderRight, sValue);
354 break;
356 case XML_TOK_PAGEMASTERSTYLE_PAGE_WIDTH:
358 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
359 mnWidth, sValue);
360 break;
362 case XML_TOK_PAGEMASTERSTYLE_PAGE_HEIGHT:
364 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
365 mnHeight, sValue);
366 break;
368 case XML_TOK_PAGEMASTERSTYLE_PAGE_ORIENTATION:
370 if( IsXMLToken( sValue, XML_PORTRAIT ) )
371 meOrientation = view::PaperOrientation_PORTRAIT;
372 else
373 meOrientation = view::PaperOrientation_LANDSCAPE;
374 break;
380 SdXMLPageMasterStyleContext::~SdXMLPageMasterStyleContext()
384 TYPEINIT1( SdXMLPageMasterContext, SvXMLStyleContext );
386 SdXMLPageMasterContext::SdXMLPageMasterContext(
387 SdXMLImport& rImport,
388 sal_uInt16 nPrfx,
389 const OUString& rLName,
390 const uno::Reference< xml::sax::XAttributeList>& xAttrList)
391 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_SD_PAGEMASTERCONEXT_ID),
392 mpPageMasterStyle( 0L )
394 // set family to something special at SvXMLStyleContext
395 // for differences in search-methods
397 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
398 for(sal_Int16 i=0; i < nAttrCount; i++)
400 OUString sAttrName = xAttrList->getNameByIndex(i);
401 OUString aLocalName;
402 sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName(sAttrName, &aLocalName);
403 OUString sValue = xAttrList->getValueByIndex(i);
404 const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetPageMasterAttrTokenMap();
406 switch(rAttrTokenMap.Get(nPrefix, aLocalName))
408 case XML_TOK_PAGEMASTER_NAME:
410 msName = sValue;
411 break;
417 SdXMLPageMasterContext::~SdXMLPageMasterContext()
419 // release remembered contexts, they are no longer needed
420 if(mpPageMasterStyle)
422 mpPageMasterStyle->ReleaseRef();
423 mpPageMasterStyle = 0L;
427 SvXMLImportContext *SdXMLPageMasterContext::CreateChildContext(
428 sal_uInt16 nPrefix,
429 const OUString& rLocalName,
430 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
432 SvXMLImportContext* pContext = 0;
434 if(nPrefix == XML_NAMESPACE_STYLE && IsXMLToken( rLocalName, XML_PAGE_LAYOUT_PROPERTIES) )
436 pContext = new SdXMLPageMasterStyleContext(GetSdImport(), nPrefix, rLocalName, xAttrList);
438 // remember SdXMLPresentationPlaceholderContext for later evaluation
439 pContext->AddFirstRef();
440 DBG_ASSERT(!mpPageMasterStyle, "PageMasterStyle is set, there seem to be two of them (!)");
441 mpPageMasterStyle = static_cast<SdXMLPageMasterStyleContext*>(pContext);
444 // call base class
445 if(!pContext)
446 pContext = SvXMLStyleContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
448 return pContext;
451 TYPEINIT1( SdXMLPresentationPageLayoutContext, SvXMLStyleContext );
453 SdXMLPresentationPageLayoutContext::SdXMLPresentationPageLayoutContext(
454 SdXMLImport& rImport,
455 sal_uInt16 nPrfx,
456 const OUString& rLName,
457 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
458 : SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_SD_PRESENTATIONPAGELAYOUT_ID),
459 mnTypeId( 20 ) // AUTOLAYOUT_NONE
461 // set family to somethiong special at SvXMLStyleContext
462 // for differences in search-methods
464 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
465 for( sal_Int16 i=0; i < nAttrCount; i++ )
467 const OUString& rAttrName = xAttrList->getNameByIndex( i );
468 OUString aLocalName;
469 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
471 if(nPrefix == XML_NAMESPACE_STYLE && IsXMLToken( aLocalName, XML_NAME ) )
473 msName = xAttrList->getValueByIndex( i );
478 SdXMLPresentationPageLayoutContext::~SdXMLPresentationPageLayoutContext()
482 SvXMLImportContext *SdXMLPresentationPageLayoutContext::CreateChildContext(
483 sal_uInt16 nPrefix,
484 const OUString& rLocalName,
485 const uno::Reference< xml::sax::XAttributeList >& xAttrList )
487 SvXMLImportContext* pContext = 0;
489 if(nPrefix == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_PLACEHOLDER ) )
491 // presentation:placeholder inside style:presentation-page-layout context
492 pContext = new SdXMLPresentationPlaceholderContext(
493 GetSdImport(), nPrefix, rLocalName, xAttrList);
495 // remember SdXMLPresentationPlaceholderContext for later evaluation
496 pContext->AddFirstRef();
497 maList.push_back( static_cast<SdXMLPresentationPlaceholderContext*>(pContext) );
500 // call base class
501 if(!pContext)
502 pContext = SvXMLStyleContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
504 return pContext;
507 void SdXMLPresentationPageLayoutContext::EndElement()
509 // build presentation page layout type here
510 // calc mnTpeId due to content of maList
511 // at the moment only use number of types used there
512 if( !maList.empty() )
514 SdXMLPresentationPlaceholderContext* pObj0 = maList[ 0 ];
515 if( pObj0->GetName() == "handout" )
517 switch( maList.size() )
519 case 1:
520 mnTypeId = 22; // AUTOLAYOUT_HANDOUT1
521 break;
522 case 2:
523 mnTypeId = 23; // AUTOLAYOUT_HANDOUT2
524 break;
525 case 3:
526 mnTypeId = 24; // AUTOLAYOUT_HANDOUT3
527 break;
528 case 4:
529 mnTypeId = 25; // AUTOLAYOUT_HANDOUT4
530 break;
531 case 9:
532 mnTypeId = 31; // AUTOLAYOUT_HANDOUT9
533 break;
534 default:
535 mnTypeId = 26; // AUTOLAYOUT_HANDOUT6
538 else
540 switch( maList.size() )
542 case 1:
544 if( pObj0->GetName() == "title" )
546 mnTypeId = 19; // AUTOLAYOUT_ONLY_TITLE
548 else
550 mnTypeId = 32; // AUTOLAYOUT_ONLY_TEXT
552 break;
554 case 2:
556 SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ];
558 if( pObj1->GetName() == "subtitle" )
560 mnTypeId = 0; // AUTOLAYOUT_TITLE
562 else if( pObj1->GetName() == "outline" )
564 mnTypeId = 1; // AUTOLAYOUT_ENUM
566 else if( pObj1->GetName() == "chart" )
568 mnTypeId = 2; // AUTOLAYOUT_CHART
570 else if( pObj1->GetName() == "table" )
572 mnTypeId = 8; // AUTOLAYOUT_TAB
574 else if( pObj1->GetName() == "object" )
576 mnTypeId = 11; // AUTOLAYOUT_OBJ
578 else if( pObj1->GetName() == "vertical_outline" )
580 if( pObj0->GetName() == "vertical_title" )
582 // AUTOLAYOUT_VERTICAL_TITLE_VERTICAL_OUTLINE
583 mnTypeId = 28;
585 else
587 // AUTOLAYOUT_TITLE_VERTICAL_OUTLINE
588 mnTypeId = 29;
591 else
593 mnTypeId = 21; // AUTOLAYOUT_NOTES
595 break;
597 case 3:
599 SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ];
600 SdXMLPresentationPlaceholderContext* pObj2 = maList[ 2 ];
602 if( pObj1->GetName() == "outline" )
604 if( pObj2->GetName() == "outline" )
606 mnTypeId = 3; // AUTOLAYOUT_2TEXT
608 else if( pObj2->GetName() == "chart" )
610 mnTypeId = 4; // AUTOLAYOUT_TEXTCHART
612 else if( pObj2->GetName() == "graphic" )
614 mnTypeId = 6; // AUTOLAYOUT_TEXTCLIP
616 else
618 if(pObj1->GetX() < pObj2->GetX())
620 mnTypeId = 10; // AUTOLAYOUT_TEXTOBJ -> outline left, object right
622 else
624 mnTypeId = 17; // AUTOLAYOUT_TEXTOVEROBJ -> outline top, object right
628 else if( pObj1->GetName() == "chart" )
630 mnTypeId = 7; // AUTOLAYOUT_CHARTTEXT
632 else if( pObj1->GetName() == "graphic" )
634 if( pObj2->GetName() == "vertical_outline" )
636 // AUTOLAYOUT_TITLE_VERTICAL_OUTLINE_CLIPART
637 mnTypeId = 30;
639 else
641 mnTypeId = 9; // AUTOLAYOUT_CLIPTEXT
644 else if( pObj1->GetName() == "vertical_outline" )
646 // AUTOLAYOUT_VERTICAL_TITLE_TEXT_CHART
647 mnTypeId = 27;
649 else
651 if(pObj1->GetX() < pObj2->GetX())
653 mnTypeId = 13; // AUTOLAYOUT_OBJTEXT -> left, right
655 else
657 mnTypeId = 14; // AUTOLAYOUT_OBJOVERTEXT -> top, bottom
660 break;
662 case 4:
664 SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ];
665 SdXMLPresentationPlaceholderContext* pObj2 = maList[ 2 ];
667 if( pObj1->GetName() == "object" )
669 if(pObj1->GetX() < pObj2->GetX())
671 mnTypeId = 16; // AUTOLAYOUT_2OBJOVERTEXT
673 else
675 mnTypeId = 15; // AUTOLAYOUT_2OBJTEXT
678 else
680 mnTypeId = 12; // AUTOLAYOUT_TEXT2OBJ
682 break;
684 case 5:
686 SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ];
688 if( pObj1->GetName() == "object" )
690 mnTypeId = 18; // AUTOLAYOUT_4OBJ
692 else
694 mnTypeId = 33; // AUTOLAYOUT_4CLIPART
696 break;
699 case 7:
701 mnTypeId = 33; // AUTOLAYOUT_6CLIPART
702 break;
704 default:
706 mnTypeId = 20; // AUTOLAYOUT_NONE
707 break;
712 // release remembered contexts, they are no longer needed
713 for ( size_t i = maList.size(); i > 0; )
714 maList[ --i ]->ReleaseRef();
715 maList.clear();
719 SdXMLPresentationPlaceholderContext::SdXMLPresentationPlaceholderContext(
720 SdXMLImport& rImport,
721 sal_uInt16 nPrfx, const
722 OUString& rLName,
723 const uno::Reference< xml::sax::XAttributeList>& xAttrList)
724 : SvXMLImportContext( rImport, nPrfx, rLName),
725 mnX(0L),
726 mnY(0L),
727 mnWidth(1L),
728 mnHeight(1L)
730 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
731 for(sal_Int16 i=0; i < nAttrCount; i++)
733 OUString sAttrName = xAttrList->getNameByIndex(i);
734 OUString aLocalName;
735 sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName(sAttrName, &aLocalName);
736 OUString sValue = xAttrList->getValueByIndex(i);
737 const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetPresentationPlaceholderAttrTokenMap();
739 switch(rAttrTokenMap.Get(nPrefix, aLocalName))
741 case XML_TOK_PRESENTATIONPLACEHOLDER_OBJECTNAME:
743 msName = sValue;
744 break;
746 case XML_TOK_PRESENTATIONPLACEHOLDER_X:
748 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
749 mnX, sValue);
750 break;
752 case XML_TOK_PRESENTATIONPLACEHOLDER_Y:
754 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
755 mnY, sValue);
756 break;
758 case XML_TOK_PRESENTATIONPLACEHOLDER_WIDTH:
760 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
761 mnWidth, sValue);
762 break;
764 case XML_TOK_PRESENTATIONPLACEHOLDER_HEIGHT:
766 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
767 mnHeight, sValue);
768 break;
774 SdXMLPresentationPlaceholderContext::~SdXMLPresentationPlaceholderContext()
778 TYPEINIT1( SdXMLMasterPageContext, SdXMLGenericPageContext );
780 SdXMLMasterPageContext::SdXMLMasterPageContext(
781 SdXMLImport& rImport,
782 sal_uInt16 nPrfx,
783 const OUString& rLName,
784 const uno::Reference< xml::sax::XAttributeList>& xAttrList,
785 uno::Reference< drawing::XShapes >& rShapes)
786 : SdXMLGenericPageContext( rImport, nPrfx, rLName, xAttrList, rShapes )
788 const bool bHandoutMaster = IsXMLToken( rLName, XML_HANDOUT_MASTER );
790 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
791 for(sal_Int16 i=0; i < nAttrCount; i++)
793 OUString sAttrName = xAttrList->getNameByIndex( i );
794 OUString aLocalName;
795 sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
796 OUString sValue = xAttrList->getValueByIndex( i );
797 const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetMasterPageAttrTokenMap();
799 switch(rAttrTokenMap.Get(nPrefix, aLocalName))
801 case XML_TOK_MASTERPAGE_NAME:
803 msName = sValue;
804 break;
806 case XML_TOK_MASTERPAGE_DISPLAY_NAME:
808 msDisplayName = sValue;
809 break;
811 case XML_TOK_MASTERPAGE_PAGE_MASTER_NAME:
813 msPageMasterName = sValue;
814 break;
816 case XML_TOK_MASTERPAGE_STYLE_NAME:
818 msStyleName = sValue;
819 break;
821 case XML_TOK_MASTERPAGE_PAGE_LAYOUT_NAME:
823 maPageLayoutName = sValue;
824 break;
826 case XML_TOK_MASTERPAGE_USE_HEADER_NAME:
828 maUseHeaderDeclName = sValue;
829 break;
831 case XML_TOK_MASTERPAGE_USE_FOOTER_NAME:
833 maUseFooterDeclName = sValue;
834 break;
836 case XML_TOK_MASTERPAGE_USE_DATE_TIME_NAME:
838 maUseDateTimeDeclName = sValue;
839 break;
844 if( msDisplayName.isEmpty() )
845 msDisplayName = msName;
846 else if( msDisplayName != msName )
847 GetImport().AddStyleDisplayName( XML_STYLE_FAMILY_MASTER_PAGE, msName, msDisplayName );
849 GetImport().GetShapeImport()->startPage( GetLocalShapesContext() );
851 // set page name?
852 if(!bHandoutMaster && !msDisplayName.isEmpty() && GetLocalShapesContext().is())
854 uno::Reference < container::XNamed > xNamed(GetLocalShapesContext(), uno::UNO_QUERY);
855 if(xNamed.is())
856 xNamed->setName(msDisplayName);
859 // set page-master?
860 if(!msPageMasterName.isEmpty())
862 SetPageMaster( msPageMasterName );
865 SetStyle( msStyleName );
867 SetLayout();
869 DeleteAllShapes();
872 SdXMLMasterPageContext::~SdXMLMasterPageContext()
876 void SdXMLMasterPageContext::EndElement()
878 // set styles on master-page
879 if(!msName.isEmpty() && GetSdImport().GetShapeImport()->GetStylesContext())
881 SvXMLImportContext* pContext = GetSdImport().GetShapeImport()->GetStylesContext();
882 if( pContext && pContext->ISA( SvXMLStyleContext ) )
883 static_cast<SdXMLStylesContext*>(pContext)->SetMasterPageStyles(*this);
886 SdXMLGenericPageContext::EndElement();
887 GetImport().GetShapeImport()->endPage(GetLocalShapesContext());
890 SvXMLImportContext* SdXMLMasterPageContext::CreateChildContext(
891 sal_uInt16 nPrefix,
892 const OUString& rLocalName,
893 const uno::Reference< xml::sax::XAttributeList>& xAttrList )
895 SvXMLImportContext* pContext = 0;
896 const SvXMLTokenMap& rTokenMap = GetSdImport().GetMasterPageElemTokenMap();
898 // some special objects inside style:masterpage context
899 switch(rTokenMap.Get(nPrefix, rLocalName))
901 case XML_TOK_MASTERPAGE_STYLE:
903 if(GetSdImport().GetShapeImport()->GetStylesContext())
905 // style:style inside master-page context -> presentation style
906 XMLShapeStyleContext* pNew = new XMLShapeStyleContext(
907 GetSdImport(), nPrefix, rLocalName, xAttrList,
908 *GetSdImport().GetShapeImport()->GetStylesContext(),
909 XML_STYLE_FAMILY_SD_PRESENTATION_ID);
911 // add this style to the outer StylesContext class for later processing
912 pContext = pNew;
913 GetSdImport().GetShapeImport()->GetStylesContext()->AddStyle(*pNew);
915 break;
917 case XML_TOK_MASTERPAGE_NOTES:
919 if( GetSdImport().IsImpress() )
921 // get notes page
922 uno::Reference< presentation::XPresentationPage > xPresPage(GetLocalShapesContext(), uno::UNO_QUERY);
923 if(xPresPage.is())
925 uno::Reference< drawing::XDrawPage > xNotesDrawPage(xPresPage->getNotesPage(), uno::UNO_QUERY);
926 if(xNotesDrawPage.is())
928 uno::Reference< drawing::XShapes > xNewShapes(xNotesDrawPage, uno::UNO_QUERY);
929 if(xNewShapes.is())
931 // presentation:notes inside master-page context
932 pContext = new SdXMLNotesContext( GetSdImport(), nPrefix, rLocalName, xAttrList, xNewShapes);
940 // call base class
941 if(!pContext)
942 pContext = SdXMLGenericPageContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
944 return pContext;
947 TYPEINIT1( SdXMLStylesContext, SvXMLStyleContext );
949 SdXMLStylesContext::SdXMLStylesContext(
950 SdXMLImport& rImport,
951 sal_uInt16 nPrfx,
952 const OUString& rLName,
953 const uno::Reference< xml::sax::XAttributeList >& xAttrList,
954 bool bIsAutoStyle)
955 : SvXMLStylesContext(rImport, nPrfx, rLName, xAttrList),
956 mbIsAutoStyle(bIsAutoStyle)
958 Reference< uno::XComponentContext > xContext = rImport.GetComponentContext();
959 mpNumFormatter = new SvNumberFormatter( xContext, LANGUAGE_SYSTEM );
960 mpNumFmtHelper = new SvXMLNumFmtHelper( mpNumFormatter, xContext );
963 SdXMLStylesContext::~SdXMLStylesContext()
965 delete mpNumFmtHelper;
966 delete mpNumFormatter;
969 SvXMLStyleContext* SdXMLStylesContext::CreateStyleChildContext(
970 sal_uInt16 nPrefix,
971 const OUString& rLocalName,
972 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
974 SvXMLStyleContext* pContext = 0;
975 const SvXMLTokenMap& rStyleTokenMap = GetSdImport().GetStylesElemTokenMap();
977 switch(rStyleTokenMap.Get(nPrefix, rLocalName))
979 case XML_TOK_STYLES_PAGE_MASTER:
981 // style:page-master inside office:styles context
982 pContext = new SdXMLPageMasterContext(GetSdImport(), nPrefix, rLocalName, xAttrList);
983 break;
985 case XML_TOK_STYLES_PRESENTATION_PAGE_LAYOUT:
987 // style:presentation-page-layout inside office:styles context
988 pContext = new SdXMLPresentationPageLayoutContext(GetSdImport(), nPrefix, rLocalName, xAttrList);
989 break;
993 if(!pContext)
995 const SvXMLTokenMap& rTokenMap = mpNumFmtHelper->GetStylesElemTokenMap();
996 sal_uInt16 nToken = rTokenMap.Get( nPrefix, rLocalName );
997 switch (nToken)
999 case XML_TOK_STYLES_DATE_STYLE:
1000 case XML_TOK_STYLES_TIME_STYLE:
1001 // number:date-style or number:time-style
1002 pContext = new SdXMLNumberFormatImportContext( GetSdImport(), nPrefix, rLocalName, mpNumFmtHelper->getData(), nToken, xAttrList, *this );
1003 break;
1005 case XML_TOK_STYLES_NUMBER_STYLE:
1006 case XML_TOK_STYLES_CURRENCY_STYLE:
1007 case XML_TOK_STYLES_PERCENTAGE_STYLE:
1008 case XML_TOK_STYLES_BOOLEAN_STYLE:
1009 case XML_TOK_STYLES_TEXT_STYLE:
1010 pContext = new SvXMLNumFormatContext( GetSdImport(), nPrefix, rLocalName,
1011 mpNumFmtHelper->getData(), nToken, xAttrList, *this );
1012 break;
1016 if(!pContext && nPrefix == XML_NAMESPACE_PRESENTATION )
1018 if( IsXMLToken( rLocalName, XML_HEADER_DECL ) ||
1019 IsXMLToken( rLocalName, XML_FOOTER_DECL ) ||
1020 IsXMLToken( rLocalName, XML_DATE_TIME_DECL ) )
1022 pContext = new SdXMLHeaderFooterDeclContext( GetImport(), nPrefix, rLocalName, xAttrList );
1026 if(!pContext && (nPrefix == XML_NAMESPACE_TABLE) && IsXMLToken( rLocalName, XML_TABLE_TEMPLATE ) )
1028 pContext = GetImport().GetShapeImport()->GetShapeTableImport()->CreateTableTemplateContext(nPrefix, rLocalName, xAttrList );
1031 // call base class
1032 if(!pContext)
1033 pContext = SvXMLStylesContext::CreateStyleChildContext(nPrefix, rLocalName, xAttrList);
1035 return pContext;
1038 SvXMLStyleContext* SdXMLStylesContext::CreateStyleStyleChildContext(
1039 sal_uInt16 nFamily,
1040 sal_uInt16 nPrefix,
1041 const OUString& rLocalName,
1042 const uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList)
1044 SvXMLStyleContext* pContext = 0;
1046 switch( nFamily )
1048 case XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID:
1049 pContext = new SdXMLDrawingPageStyleContext(GetSdImport(), nPrefix, rLocalName, xAttrList, *this );
1050 break;
1051 case XML_STYLE_FAMILY_TABLE_CELL:
1052 case XML_STYLE_FAMILY_TABLE_COLUMN:
1053 case XML_STYLE_FAMILY_TABLE_ROW:
1054 pContext = new XMLShapeStyleContext( GetSdImport(), nPrefix, rLocalName, xAttrList, *this, nFamily );
1055 break;
1058 // call base class
1059 if(!pContext)
1060 pContext = SvXMLStylesContext::CreateStyleStyleChildContext(nFamily, nPrefix, rLocalName, xAttrList);
1062 return pContext;
1065 SvXMLStyleContext* SdXMLStylesContext::CreateDefaultStyleStyleChildContext(
1066 sal_uInt16 nFamily,
1067 sal_uInt16 nPrefix,
1068 const OUString& rLocalName,
1069 const Reference< XAttributeList > & xAttrList )
1071 SvXMLStyleContext* pContext = 0;
1073 switch( nFamily )
1075 case XML_STYLE_FAMILY_SD_GRAPHICS_ID:
1076 pContext = new XMLGraphicsDefaultStyle(GetSdImport(), nPrefix, rLocalName, xAttrList, *this );
1077 break;
1080 // call base class
1081 if(!pContext)
1082 pContext = SvXMLStylesContext::CreateDefaultStyleStyleChildContext(nFamily, nPrefix, rLocalName, xAttrList);
1084 return pContext;
1087 sal_uInt16 SdXMLStylesContext::GetFamily( const OUString& rFamily ) const
1089 // call base class
1090 return SvXMLStylesContext::GetFamily(rFamily);
1093 rtl::Reference< SvXMLImportPropertyMapper > SdXMLStylesContext::GetImportPropertyMapper(
1094 sal_uInt16 nFamily) const
1096 rtl::Reference < SvXMLImportPropertyMapper > xMapper;
1098 switch( nFamily )
1100 case XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID:
1102 if(!xPresImpPropMapper.is())
1104 rtl::Reference< XMLShapeImportHelper > aImpHelper = ((SvXMLImport&)GetImport()).GetShapeImport();
1105 const_cast<SdXMLStylesContext*>(this)->xPresImpPropMapper =
1106 aImpHelper->GetPresPagePropsMapper();
1108 xMapper = xPresImpPropMapper;
1109 break;
1112 case XML_STYLE_FAMILY_TABLE_COLUMN:
1113 case XML_STYLE_FAMILY_TABLE_ROW:
1114 case XML_STYLE_FAMILY_TABLE_CELL:
1116 const rtl::Reference< XMLTableImport >& xTableImport( const_cast< SvXMLImport& >( GetImport() ).GetShapeImport()->GetShapeTableImport() );
1118 switch( nFamily )
1120 case XML_STYLE_FAMILY_TABLE_COLUMN: xMapper = xTableImport->GetColumnImportPropertySetMapper().get(); break;
1121 case XML_STYLE_FAMILY_TABLE_ROW: xMapper = xTableImport->GetRowImportPropertySetMapper().get(); break;
1122 case XML_STYLE_FAMILY_TABLE_CELL: xMapper = xTableImport->GetCellImportPropertySetMapper().get(); break;
1124 break;
1128 // call base class
1129 if( !xMapper.is() )
1130 xMapper = SvXMLStylesContext::GetImportPropertyMapper(nFamily);
1131 return xMapper;
1134 // Process all style and object info
1136 void SdXMLStylesContext::EndElement()
1138 if(mbIsAutoStyle)
1140 // AutoStyles for text import
1141 GetImport().GetTextImport()->SetAutoStyles( this );
1143 // AutoStyles for chart
1144 GetImport().GetChartImport()->SetAutoStylesContext( this );
1146 // AutoStyles for forms
1147 GetImport().GetFormImport()->setAutoStyleContext( this );
1149 // associate AutoStyles with styles in preparation to setting Styles on shapes
1150 for(sal_uInt32 a(0L); a < GetStyleCount(); a++)
1152 const SvXMLStyleContext* pStyle = GetStyle(a);
1153 if(pStyle && pStyle->ISA(XMLShapeStyleContext))
1155 const XMLShapeStyleContext* pDocStyle = static_cast<const XMLShapeStyleContext*>(pStyle);
1157 SvXMLStylesContext* pStylesContext = GetSdImport().GetShapeImport()->GetStylesContext();
1158 if( pStylesContext )
1160 pStyle = pStylesContext->FindStyleChildContext(pStyle->GetFamily(), pStyle->GetParentName());
1162 if(pStyle && pStyle->ISA(XMLShapeStyleContext))
1164 const XMLShapeStyleContext* pParentStyle = static_cast<const XMLShapeStyleContext*>(pStyle);
1165 if(pParentStyle->GetStyle().is())
1167 const_cast<XMLShapeStyleContext*>(pDocStyle)->SetStyle(pParentStyle->GetStyle());
1174 FinishStyles( false );
1176 else
1178 // Process styles list
1179 ImpSetGraphicStyles();
1180 ImpSetCellStyles();
1181 GetImport().GetShapeImport()->GetShapeTableImport()->finishStyles();
1183 // put style infos in the info set for other components ( content import f.e. )
1184 uno::Reference< beans::XPropertySet > xInfoSet( GetImport().getImportInfo() );
1185 if( xInfoSet.is() )
1187 uno::Reference< beans::XPropertySetInfo > xInfoSetInfo( xInfoSet->getPropertySetInfo() );
1189 if( xInfoSetInfo->hasPropertyByName("PageLayouts") )
1190 xInfoSet->setPropertyValue("PageLayouts", uno::makeAny( getPageLayouts() ) );
1196 // set master-page styles (all with family="presentation" and a special
1197 // prefix) on given master-page.
1199 void SdXMLStylesContext::SetMasterPageStyles(SdXMLMasterPageContext& rMaster) const
1201 const uno::Reference<container::XNameAccess>& rStyleFamilies =
1202 GetSdImport().GetLocalDocStyleFamilies();
1204 if (!rStyleFamilies.is())
1205 return;
1207 if (!rStyleFamilies->hasByName(rMaster.GetDisplayName()))
1208 return;
1212 uno::Reference< container::XNameAccess > xMasterPageStyles( rStyleFamilies->getByName(rMaster.GetDisplayName()), UNO_QUERY_THROW );
1213 OUString sPrefix(rMaster.GetDisplayName());
1214 sPrefix += "-";
1215 ImpSetGraphicStyles(xMasterPageStyles, XML_STYLE_FAMILY_SD_PRESENTATION_ID, sPrefix);
1217 catch (const uno::Exception&)
1219 OSL_FAIL( "xmloff::SdXMLStylesContext::SetMasterPageStyles(), exception caught!" );
1223 // Process styles list:
1224 // set graphic styles (all with family="graphics"). Remember xStyle at list element.
1226 void SdXMLStylesContext::ImpSetGraphicStyles() const
1228 if(GetSdImport().GetLocalDocStyleFamilies().is()) try
1230 const OUString sGraphicStyleName("graphics");
1231 uno::Reference< container::XNameAccess > xGraphicPageStyles( GetSdImport().GetLocalDocStyleFamilies()->getByName(sGraphicStyleName), uno::UNO_QUERY_THROW );
1233 ImpSetGraphicStyles(xGraphicPageStyles, XML_STYLE_FAMILY_SD_GRAPHICS_ID, OUString());
1235 catch( uno::Exception& )
1237 OSL_FAIL( "xmloff::SdXMLStylesContext::ImpSetGraphicStyles(), exception caught!" );
1241 void SdXMLStylesContext::ImpSetCellStyles() const
1243 if(GetSdImport().GetLocalDocStyleFamilies().is()) try
1245 const OUString sCellStyleName("cell");
1246 uno::Reference< container::XNameAccess > xGraphicPageStyles( GetSdImport().GetLocalDocStyleFamilies()->getByName(sCellStyleName), uno::UNO_QUERY_THROW );
1248 ImpSetGraphicStyles(xGraphicPageStyles, XML_STYLE_FAMILY_TABLE_CELL, OUString());
1250 catch( uno::Exception& )
1252 OSL_FAIL( "xmloff::SdXMLStylesContext::ImpSetCellStyles(), exception caught!" );
1256 //Resolves: fdo#34987 if the style's auto height before and after is the same
1257 //then don't reset it back to the underlying default of true for the small
1258 //period before its going to be reset to false again. Doing this avoids the
1259 //master page shapes from resizing themselves due to autoheight becoming
1260 //enabled before having autoheight turned off again and getting stuck on that
1261 //autosized height
1262 static bool canSkipReset(const OUString &rName, const XMLPropStyleContext* pPropStyle,
1263 const uno::Reference< beans::XPropertySet > &rPropSet, const rtl::Reference < XMLPropertySetMapper >& rPrMap)
1265 bool bCanSkipReset = false;
1266 if (pPropStyle && rName == "TextAutoGrowHeight")
1268 bool bOldStyleTextAutoGrowHeight(false);
1269 rPropSet->getPropertyValue("TextAutoGrowHeight") >>= bOldStyleTextAutoGrowHeight;
1271 sal_Int32 nIndexStyle = rPrMap->GetEntryIndex(XML_NAMESPACE_DRAW, "auto-grow-height", 0);
1272 if (nIndexStyle != -1)
1274 const ::std::vector< XMLPropertyState > &rProperties = pPropStyle->GetProperties();
1275 ::std::vector< XMLPropertyState >::const_iterator property = rProperties.begin();
1276 for(; property != rProperties.end(); ++property)
1278 sal_Int32 nIdx = property->mnIndex;
1279 if (nIdx == nIndexStyle)
1281 bool bNewStyleTextAutoGrowHeight(false);
1282 property->maValue >>= bNewStyleTextAutoGrowHeight;
1283 if (bNewStyleTextAutoGrowHeight == bOldStyleTextAutoGrowHeight)
1284 bCanSkipReset = true;;
1285 break;
1290 return bCanSkipReset;
1293 // help function used by ImpSetGraphicStyles() and ImpSetMasterPageStyles()
1295 void SdXMLStylesContext::ImpSetGraphicStyles( uno::Reference< container::XNameAccess >& xPageStyles, sal_uInt16 nFamily, const OUString& rPrefix) const
1297 sal_Int32 nPrefLen(rPrefix.getLength());
1299 sal_uInt32 a;
1301 // set defaults
1302 for( a = 0; a < GetStyleCount(); a++)
1304 const SvXMLStyleContext* pStyle = GetStyle(a);
1306 if(nFamily == pStyle->GetFamily() && pStyle->IsDefaultStyle())
1308 const_cast<SvXMLStyleContext*>(pStyle)->SetDefaults();
1312 // create all styles and set properties
1313 for( a = 0; a < GetStyleCount(); a++)
1317 const SvXMLStyleContext* pStyle = GetStyle(a);
1318 if(nFamily == pStyle->GetFamily() && !pStyle->IsDefaultStyle())
1320 OUString aStyleName(pStyle->GetDisplayName());
1322 if( nPrefLen )
1324 sal_Int32 nStylePrefLen = aStyleName.lastIndexOf( '-' ) + 1;
1325 if( (nPrefLen != nStylePrefLen) || (aStyleName.compareTo( rPrefix, nPrefLen ) != 0) )
1326 continue;
1328 aStyleName = aStyleName.copy( nPrefLen );
1331 XMLPropStyleContext* pPropStyle = dynamic_cast< XMLPropStyleContext* >(const_cast< SvXMLStyleContext* >( pStyle ) );
1333 uno::Reference< style::XStyle > xStyle;
1334 if(xPageStyles->hasByName(aStyleName))
1336 xPageStyles->getByName(aStyleName) >>= xStyle;
1338 // set properties of existing styles to default
1339 uno::Reference< beans::XPropertySet > xPropSet( xStyle, uno::UNO_QUERY );
1340 uno::Reference< beans::XPropertySetInfo > xPropSetInfo;
1341 if( xPropSet.is() )
1342 xPropSetInfo = xPropSet->getPropertySetInfo();
1344 uno::Reference< beans::XPropertyState > xPropState( xStyle, uno::UNO_QUERY );
1346 if( xPropState.is() )
1348 rtl::Reference < XMLPropertySetMapper > xPrMap;
1349 rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap = GetImportPropertyMapper( nFamily );
1350 DBG_ASSERT( xImpPrMap.is(), "There is the import prop mapper" );
1351 if( xImpPrMap.is() )
1352 xPrMap = xImpPrMap->getPropertySetMapper();
1353 if( xPrMap.is() )
1355 const sal_Int32 nCount = xPrMap->GetEntryCount();
1356 for( sal_Int32 i = 0; i < nCount; i++ )
1358 const OUString& rName = xPrMap->GetEntryAPIName( i );
1359 if( xPropSetInfo->hasPropertyByName( rName ) && beans::PropertyState_DIRECT_VALUE == xPropState->getPropertyState( rName ) )
1361 bool bCanSkipReset = canSkipReset(rName, pPropStyle, xPropSet, xPrMap);
1362 if (bCanSkipReset)
1363 continue;
1364 xPropState->setPropertyToDefault( rName );
1370 else
1372 // graphics style does not exist, create and add it
1373 uno::Reference< lang::XSingleServiceFactory > xServiceFact(xPageStyles, uno::UNO_QUERY);
1374 if(xServiceFact.is())
1376 uno::Reference< style::XStyle > xNewStyle( xServiceFact->createInstance(), uno::UNO_QUERY);
1378 if(xNewStyle.is())
1380 // remember style
1381 xStyle = xNewStyle;
1383 // add new style to graphics style pool
1384 uno::Reference< container::XNameContainer > xInsertContainer(xPageStyles, uno::UNO_QUERY);
1385 if(xInsertContainer.is())
1386 xInsertContainer->insertByName(aStyleName, uno::Any( xStyle ) );
1391 if(xStyle.is())
1393 // set properties at style
1394 uno::Reference< beans::XPropertySet > xPropSet(xStyle, uno::UNO_QUERY);
1395 if(xPropSet.is() && pPropStyle)
1397 pPropStyle->FillPropertySet(xPropSet);
1398 pPropStyle->SetStyle(xStyle);
1403 catch(const Exception& e)
1405 uno::Sequence<OUString> aSeq(0);
1406 const_cast<SdXMLImport*>(&GetSdImport())->SetError( XMLERROR_FLAG_WARNING | XMLERROR_API, aSeq, e.Message, NULL );
1410 // now set parents for all styles (when necessary)
1411 for(a = 0L; a < GetStyleCount(); a++)
1413 const SvXMLStyleContext* pStyle = GetStyle(a);
1415 if(pStyle && !pStyle->GetDisplayName().isEmpty() && (nFamily == pStyle->GetFamily())) try
1417 OUString aStyleName(pStyle->GetDisplayName());
1418 if( nPrefLen )
1420 sal_Int32 nStylePrefLen = aStyleName.lastIndexOf( '-' ) + 1;
1421 if( (nPrefLen != nStylePrefLen) || (aStyleName.compareTo( rPrefix, nPrefLen ) != 0) )
1422 continue;
1424 aStyleName = aStyleName.copy( nPrefLen );
1427 uno::Reference< style::XStyle > xStyle( xPageStyles->getByName(aStyleName), UNO_QUERY );
1428 if(xStyle.is())
1430 // set parent style name
1431 OUString sParentStyleDisplayName( GetImport().GetStyleDisplayName( pStyle->GetFamily(), pStyle->GetParentName() ) );
1432 if( nPrefLen )
1434 sal_Int32 nStylePrefLen = sParentStyleDisplayName.lastIndexOf( '-' ) + 1;
1435 if( (nPrefLen != nStylePrefLen) || (sParentStyleDisplayName.compareTo( rPrefix, nPrefLen ) != 0) )
1436 continue;
1438 sParentStyleDisplayName = sParentStyleDisplayName.copy( nPrefLen );
1440 xStyle->setParentStyle( sParentStyleDisplayName );
1443 catch( const Exception& e )
1445 uno::Sequence<OUString> aSeq(0);
1446 const_cast<SdXMLImport*>(&GetSdImport())->SetError( XMLERROR_FLAG_WARNING | XMLERROR_API, aSeq, e.Message, NULL );
1451 // helper function to create the uno component that hold the mappings from
1452 // xml auto layout name to internal autolayout id
1454 uno::Reference< container::XNameAccess > SdXMLStylesContext::getPageLayouts() const
1456 uno::Reference< container::XNameContainer > xLayouts( comphelper::NameContainer_createInstance( ::cppu::UnoType<sal_Int32>::get()) );
1458 for(sal_uInt32 a(0L); a < GetStyleCount(); a++)
1460 const SvXMLStyleContext* pStyle = GetStyle(a);
1461 if(pStyle && pStyle->ISA(SdXMLPresentationPageLayoutContext))
1463 xLayouts->insertByName( pStyle->GetName(), uno::makeAny(
1464 (sal_Int32)static_cast<const SdXMLPresentationPageLayoutContext*>(pStyle)->GetTypeId() ) );
1468 return uno::Reference< container::XNameAccess >::query( xLayouts );
1472 TYPEINIT1( SdXMLMasterStylesContext, SvXMLImportContext );
1474 SdXMLMasterStylesContext::SdXMLMasterStylesContext(
1475 SdXMLImport& rImport,
1476 sal_uInt16 nPrfx,
1477 const OUString& rLName)
1478 : SvXMLImportContext( rImport, nPrfx, rLName)
1482 SdXMLMasterStylesContext::~SdXMLMasterStylesContext()
1484 for ( size_t i = maMasterPageList.size(); i > 0; )
1485 maMasterPageList[ --i ]->ReleaseRef();
1486 maMasterPageList.clear();
1489 SvXMLImportContext* SdXMLMasterStylesContext::CreateChildContext(
1490 sal_uInt16 nPrefix,
1491 const OUString& rLocalName,
1492 const uno::Reference< xml::sax::XAttributeList >& xAttrList)
1494 SvXMLImportContext* pContext = 0;
1496 if(nPrefix == XML_NAMESPACE_STYLE
1497 && IsXMLToken( rLocalName, XML_MASTER_PAGE ) )
1499 // style:masterpage inside office:styles context
1500 uno::Reference< drawing::XDrawPage > xNewMasterPage;
1501 uno::Reference< drawing::XDrawPages > xMasterPages(GetSdImport().GetLocalMasterPages(), uno::UNO_QUERY);
1503 if( xMasterPages.is() )
1505 if(GetSdImport().GetNewMasterPageCount() + 1 > xMasterPages->getCount())
1507 // new page, create and insert
1508 xNewMasterPage = xMasterPages->insertNewByIndex(xMasterPages->getCount());
1510 else
1512 // existing page, use it
1513 xMasterPages->getByIndex(GetSdImport().GetNewMasterPageCount()) >>= xNewMasterPage;
1516 // increment global import page counter
1517 GetSdImport().IncrementNewMasterPageCount();
1519 if(xNewMasterPage.is())
1521 uno::Reference< drawing::XShapes > xNewShapes(xNewMasterPage, uno::UNO_QUERY);
1522 if(xNewShapes.is() && GetSdImport().GetShapeImport()->GetStylesContext())
1524 pContext = new SdXMLMasterPageContext(GetSdImport(),
1525 nPrefix, rLocalName, xAttrList, xNewShapes);
1527 pContext->AddFirstRef();
1528 maMasterPageList.push_back( static_cast<SdXMLMasterPageContext*>(pContext) );
1533 else if(nPrefix == XML_NAMESPACE_STYLE
1534 && IsXMLToken( rLocalName, XML_HANDOUT_MASTER ) )
1536 uno::Reference< presentation::XHandoutMasterSupplier > xHandoutSupp( GetSdImport().GetModel(), uno::UNO_QUERY );
1537 if( xHandoutSupp.is() )
1539 uno::Reference< drawing::XShapes > xHandoutPage( xHandoutSupp->getHandoutMasterPage(), uno::UNO_QUERY );
1540 if(xHandoutPage.is() && GetSdImport().GetShapeImport()->GetStylesContext())
1542 pContext = new SdXMLMasterPageContext(GetSdImport(),
1543 nPrefix, rLocalName, xAttrList, xHandoutPage);
1547 else if( (nPrefix == XML_NAMESPACE_DRAW )&& IsXMLToken( rLocalName, XML_LAYER_SET ) )
1549 pContext = new SdXMLLayerSetContext( GetImport(), nPrefix, rLocalName, xAttrList );
1552 // call base class
1553 if(!pContext)
1554 pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
1556 return pContext;
1559 SdXMLHeaderFooterDeclContext::SdXMLHeaderFooterDeclContext(SvXMLImport& rImport,
1560 sal_uInt16 nPrfx, const OUString& rLName,
1561 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList)
1562 : SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList)
1563 , mbFixed(false)
1565 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1566 for(sal_Int16 i=0; i < nAttrCount; i++)
1568 OUString aLocalName;
1569 const OUString aValue( xAttrList->getValueByIndex(i) );
1570 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(xAttrList->getNameByIndex(i), &aLocalName);
1572 if( nPrefix == XML_NAMESPACE_PRESENTATION )
1574 if( IsXMLToken( aLocalName, XML_NAME ) )
1576 maStrName = aValue;
1578 else if( IsXMLToken( aLocalName, XML_SOURCE ) )
1580 mbFixed = IsXMLToken( aValue, XML_FIXED );
1583 else if( nPrefix == XML_NAMESPACE_STYLE )
1585 if( IsXMLToken( aLocalName, XML_DATA_STYLE_NAME ) )
1587 maStrDateTimeFormat = aValue;
1593 bool SdXMLHeaderFooterDeclContext::IsTransient() const
1595 return true;
1598 void SdXMLHeaderFooterDeclContext::EndElement()
1600 SdXMLImport& rImport = dynamic_cast<SdXMLImport&>(GetImport());
1601 if( IsXMLToken( GetLocalName(), XML_HEADER_DECL ) )
1603 rImport.AddHeaderDecl( maStrName, maStrText );
1605 else if( IsXMLToken( GetLocalName(), XML_FOOTER_DECL ) )
1607 rImport.AddFooterDecl( maStrName, maStrText );
1609 else if( IsXMLToken( GetLocalName(), XML_DATE_TIME_DECL ) )
1611 rImport.AddDateTimeDecl( maStrName, maStrText, mbFixed, maStrDateTimeFormat );
1615 void SdXMLHeaderFooterDeclContext::Characters( const OUString& rChars )
1617 maStrText += rChars;
1620 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */