xref: /trunk/main/xmloff/source/draw/ximppage.cxx (revision 4fe6f2d1)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 #include <tools/debug.hxx>
27 
28 #include <com/sun/star/geometry/RealPoint2D.hpp>
29 #include <com/sun/star/text/XTextCursor.hpp>
30 #include <com/sun/star/util/DateTime.hpp>
31 #include <cppuhelper/implbase1.hxx>
32 #include "XMLNumberStylesImport.hxx"
33 #include <xmloff/xmlstyle.hxx>
34 #include <xmloff/xmltoken.hxx>
35 #include <xmloff/xmlstyle.hxx>
36 #include "xmloff/xmlnmspe.hxx"
37 #include "ximppage.hxx"
38 #include "ximpshap.hxx"
39 #include "animimp.hxx"
40 #include "XMLStringBufferImportContext.hxx"
41 #include <xmloff/formsimp.hxx>
42 #include <xmloff/xmlictxt.hxx>
43 #include "ximpstyl.hxx"
44 #include <xmloff/prstylei.hxx>
45 #include "PropertySetMerger.hxx"
46 
47 #include "unointerfacetouniqueidentifiermapper.hxx"
48 #include <xmloff/xmluconv.hxx>
49 
50 using ::rtl::OUString;
51 using ::rtl::OUStringBuffer;
52 
53 using namespace ::com::sun::star;
54 using namespace ::xmloff::token;
55 using namespace ::com::sun::star::uno;
56 using namespace ::com::sun::star::lang;
57 using namespace ::com::sun::star::text;
58 using namespace ::com::sun::star::util;
59 using namespace ::com::sun::star::beans;
60 using namespace ::com::sun::star::drawing;
61 using namespace ::com::sun::star::container;
62 using namespace ::com::sun::star::office;
63 using namespace ::com::sun::star::xml::sax;
64 using namespace ::com::sun::star::geometry;
65 
66 
67 //////////////////////////////////////////////////////////////////////////////
68 
69 class DrawAnnotationContext : public SvXMLImportContext
70 {
71 
72 public:
73     DrawAnnotationContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName,const Reference< xml::sax::XAttributeList>& xAttrList, const Reference< XAnnotationAccess >& xAnnotationAccess );
74 
75 	virtual SvXMLImportContext * CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList );
76     virtual void EndElement();
77 
78 private:
79     Reference< XAnnotation > mxAnnotation;
80 	Reference< XTextCursor > mxCursor;
81 
82 	OUStringBuffer maAuthorBuffer;
83 	OUStringBuffer maDateBuffer;
84 };
85 
DrawAnnotationContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLocalName,const Reference<xml::sax::XAttributeList> & xAttrList,const Reference<XAnnotationAccess> & xAnnotationAccess)86 DrawAnnotationContext::DrawAnnotationContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName,const Reference< xml::sax::XAttributeList>& xAttrList, const Reference< XAnnotationAccess >& xAnnotationAccess )
87 : SvXMLImportContext( rImport, nPrfx, rLocalName )
88 , mxAnnotation( xAnnotationAccess->createAndInsertAnnotation() )
89 {
90     if( mxAnnotation.is() )
91     {
92 	    sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
93 
94         RealPoint2D aPosition;
95         RealSize2D aSize;
96 
97 	    for(sal_Int16 i=0; i < nAttrCount; i++)
98 	    {
99             OUString sValue( xAttrList->getValueByIndex( i ) );
100 		    OUString sAttrName( xAttrList->getNameByIndex( i ) );
101 		    OUString aLocalName;
102 		    switch( GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ) )
103             {
104             case XML_NAMESPACE_SVG:
105                 if( IsXMLToken( aLocalName, XML_X ) )
106                 {
107                     sal_Int32 x;
108                     GetImport().GetMM100UnitConverter().convertMeasure(x, sValue);
109                     aPosition.X = static_cast<double>(x) / 100.0;
110                 }
111                 else if( IsXMLToken( aLocalName, XML_Y ) )
112                 {
113                     sal_Int32 y;
114                     GetImport().GetMM100UnitConverter().convertMeasure(y, sValue);
115                     aPosition.Y = static_cast<double>(y) / 100.0;
116                 }
117                 else if( IsXMLToken( aLocalName, XML_WIDTH ) )
118                 {
119                     sal_Int32 w;
120                     GetImport().GetMM100UnitConverter().convertMeasure(w, sValue);
121                     aSize.Width = static_cast<double>(w) / 100.0;
122                 }
123                 else if( IsXMLToken( aLocalName, XML_HEIGHT ) )
124                 {
125                     sal_Int32 h;
126                     GetImport().GetMM100UnitConverter().convertMeasure(h, sValue);
127                     aSize.Height = static_cast<double>(h) / 100.0;
128                 }
129                 break;
130             default:
131                 break;
132 		    }
133 	    }
134 
135         mxAnnotation->setPosition( aPosition );
136         mxAnnotation->setSize( aSize );
137     }
138 }
139 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)140 SvXMLImportContext * DrawAnnotationContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList )
141 {
142 	SvXMLImportContext * pContext = NULL;
143 
144     if( mxAnnotation.is() )
145     {
146 	    if( XML_NAMESPACE_DC == nPrefix )
147 	    {
148 		    if( IsXMLToken( rLocalName, XML_CREATOR ) )
149 			    pContext = new XMLStringBufferImportContext(GetImport(), nPrefix, rLocalName, maAuthorBuffer);
150 		    else if( IsXMLToken( rLocalName, XML_DATE ) )
151 			    pContext = new XMLStringBufferImportContext(GetImport(), nPrefix, rLocalName, maDateBuffer);
152 	    }
153         else
154 	    {
155 		    // create text cursor on demand
156 		    if( !mxCursor.is() )
157 		    {
158 			    uno::Reference< text::XText > xText( mxAnnotation->getTextRange() );
159 			    if( xText.is() )
160 			    {
161 				    UniReference < XMLTextImportHelper > xTxtImport = GetImport().GetTextImport();
162 				    mxCursor = xText->createTextCursor();
163 				    if( mxCursor.is() )
164 					    xTxtImport->SetCursor( mxCursor );
165 			    }
166 		    }
167 
168 		    // if we have a text cursor, lets  try to import some text
169 		    if( mxCursor.is() )
170 		    {
171 			    pContext = GetImport().GetTextImport()->CreateTextChildContext( GetImport(), nPrefix, rLocalName, xAttrList );
172 		    }
173 	    }
174     }
175 
176 	// call parent for content
177 	if(!pContext)
178 		pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
179 
180 	return pContext;
181 }
182 
EndElement()183 void DrawAnnotationContext::EndElement()
184 {
185 	if(mxCursor.is())
186 	{
187 		// delete addition newline
188 		const OUString aEmpty;
189 		mxCursor->gotoEnd( sal_False );
190 		mxCursor->goLeft( 1, sal_True );
191 		mxCursor->setString( aEmpty );
192 
193 		// reset cursor
194 		GetImport().GetTextImport()->ResetCursor();
195     }
196 
197     if( mxAnnotation.is() )
198     {
199     	mxAnnotation->setAuthor( maAuthorBuffer.makeStringAndClear() );
200 
201     	DateTime aDateTime;
202 	    if(SvXMLUnitConverter::convertDateTime(aDateTime,  maDateBuffer.makeStringAndClear()))
203     		mxAnnotation->setDateTime(aDateTime);
204 	}
205 }
206 
207 //////////////////////////////////////////////////////////////////////////////
208 
209 TYPEINIT1( SdXMLGenericPageContext, SvXMLImportContext );
210 
SdXMLGenericPageContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLocalName,const Reference<xml::sax::XAttributeList> & xAttrList,Reference<drawing::XShapes> & rShapes)211 SdXMLGenericPageContext::SdXMLGenericPageContext(
212 	SvXMLImport& rImport,
213 	sal_uInt16 nPrfx, const OUString& rLocalName,
214 	const Reference< xml::sax::XAttributeList>& xAttrList,
215 	Reference< drawing::XShapes >& rShapes)
216 : SvXMLImportContext( rImport, nPrfx, rLocalName )
217 , mxShapes( rShapes )
218 , mxAnnotationAccess( rShapes, UNO_QUERY )
219 {
220 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
221 
222 	for(sal_Int16 i=0; i < nAttrCount; i++)
223 	{
224 		OUString sAttrName = xAttrList->getNameByIndex( i );
225 		OUString aLocalName;
226 		sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
227 		if( (nPrefix == XML_NAMESPACE_DRAW) && IsXMLToken( aLocalName, XML_NAV_ORDER ) )
228 		{
229 			msNavOrder = xAttrList->getValueByIndex( i );
230 			break;
231 		}
232 	}
233 }
234 
235 //////////////////////////////////////////////////////////////////////////////
236 
~SdXMLGenericPageContext()237 SdXMLGenericPageContext::~SdXMLGenericPageContext()
238 {
239 }
240 
241 //////////////////////////////////////////////////////////////////////////////
242 
StartElement(const Reference<::com::sun::star::xml::sax::XAttributeList> &)243 void SdXMLGenericPageContext::StartElement( const Reference< ::com::sun::star::xml::sax::XAttributeList >& )
244 {
245 	GetImport().GetShapeImport()->pushGroupForSorting( mxShapes );
246 
247 	if( GetImport().IsFormsSupported() )
248 		GetImport().GetFormImport()->startPage( Reference< drawing::XDrawPage >::query( mxShapes ) );
249 }
250 
251 //////////////////////////////////////////////////////////////////////////////
252 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<xml::sax::XAttributeList> & xAttrList)253 SvXMLImportContext* SdXMLGenericPageContext::CreateChildContext( sal_uInt16 nPrefix,
254 	const OUString& rLocalName,
255 	const Reference< xml::sax::XAttributeList>& xAttrList )
256 {
257 	SvXMLImportContext* pContext = 0L;
258 
259 	if( nPrefix == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_ANIMATIONS ) )
260 	{
261 		pContext = new XMLAnimationsContext( GetImport(), nPrefix, rLocalName, xAttrList );
262 	}
263 	else if( nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken( rLocalName, XML_FORMS ) )
264 	{
265 		if( GetImport().IsFormsSupported() )
266 			pContext = GetImport().GetFormImport()->createOfficeFormsContext( GetImport(), nPrefix, rLocalName );
267 	}
268     else if( ((nPrefix == XML_NAMESPACE_OFFICE) || (nPrefix == XML_NAMESPACE_OFFICE_EXT)) && IsXMLToken( rLocalName, XML_ANNOTATION ) )
269     {
270         if( mxAnnotationAccess.is() )
271             pContext = new DrawAnnotationContext( GetImport(), nPrefix, rLocalName, xAttrList, mxAnnotationAccess );
272     }
273 	else
274 	{
275 		// call GroupChildContext function at common ShapeImport
276 		pContext = GetImport().GetShapeImport()->CreateGroupChildContext(
277 			GetImport(), nPrefix, rLocalName, xAttrList, mxShapes);
278 	}
279 
280 	// call parent when no own context was created
281 	if(!pContext)
282 		pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
283 
284 	return pContext;
285 }
286 
287 //////////////////////////////////////////////////////////////////////////////
288 
EndElement()289 void SdXMLGenericPageContext::EndElement()
290 {
291 	GetImport().GetShapeImport()->popGroupAndSort();
292 
293 	if( GetImport().IsFormsSupported() )
294 		GetImport().GetFormImport()->endPage();
295 
296 	if( maUseHeaderDeclName.getLength() || maUseFooterDeclName.getLength() || maUseDateTimeDeclName.getLength() )
297 	{
298 		try
299 		{
300 			Reference <beans::XPropertySet> xSet(mxShapes, uno::UNO_QUERY_THROW );
301 			Reference< beans::XPropertySetInfo > xInfo( xSet->getPropertySetInfo() );
302 
303 			if( maUseHeaderDeclName.getLength() )
304 			{
305 				const OUString aStrHeaderTextProp( RTL_CONSTASCII_USTRINGPARAM( "HeaderText" ) );
306 				if( xInfo->hasPropertyByName( aStrHeaderTextProp ) )
307 					xSet->setPropertyValue( aStrHeaderTextProp,
308 											makeAny( GetSdImport().GetHeaderDecl( maUseHeaderDeclName ) ) );
309 			}
310 
311 			if( maUseFooterDeclName.getLength() )
312 			{
313 				const OUString aStrFooterTextProp( RTL_CONSTASCII_USTRINGPARAM( "FooterText" ) );
314 				if( xInfo->hasPropertyByName( aStrFooterTextProp ) )
315 					xSet->setPropertyValue( aStrFooterTextProp,
316 										makeAny( GetSdImport().GetFooterDecl( maUseFooterDeclName ) ) );
317 			}
318 
319 			if( maUseDateTimeDeclName.getLength() )
320 			{
321 				const OUString aStrDateTimeTextProp( RTL_CONSTASCII_USTRINGPARAM( "DateTimeText" ) );
322 				if( xInfo->hasPropertyByName( aStrDateTimeTextProp ) )
323 				{
324 					sal_Bool bFixed;
325 					OUString aDateTimeFormat;
326 					const OUString aText( GetSdImport().GetDateTimeDecl( maUseDateTimeDeclName, bFixed, aDateTimeFormat ) );
327 
328 					xSet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("IsDateTimeFixed") ),
329 										makeAny( bFixed ) );
330 
331 					if( bFixed )
332 					{
333 						xSet->setPropertyValue( aStrDateTimeTextProp, makeAny( aText ) );
334 					}
335 					else if( aDateTimeFormat.getLength() )
336 					{
337 						const SdXMLStylesContext* pStyles = dynamic_cast< const SdXMLStylesContext* >( GetSdImport().GetShapeImport()->GetStylesContext() );
338 						if( !pStyles )
339 							pStyles = dynamic_cast< const SdXMLStylesContext* >( GetSdImport().GetShapeImport()->GetAutoStylesContext() );
340 
341 						if( pStyles )
342 						{
343 							const SdXMLNumberFormatImportContext* pSdNumStyle =
344 								dynamic_cast< const SdXMLNumberFormatImportContext* >( pStyles->FindStyleChildContext( XML_STYLE_FAMILY_DATA_STYLE, aDateTimeFormat, sal_True ) );
345 
346 							if( pSdNumStyle )
347 							{
348 								xSet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("DateTimeFormat") ),
349 																	makeAny( pSdNumStyle->GetDrawKey() ) );
350 							}
351 						}
352 					}
353 				}
354 			}
355 		}
356 		catch( uno::Exception& e )
357 		{
358 			(void)e;
359 			DBG_ERROR("xmloff::SdXMLGenericPageContext::EndElement(), unexpected exception caught!");
360 		}
361 	}
362 
363 	SetNavigationOrder();
364 }
365 
SetStyle(rtl::OUString & rStyleName)366 void SdXMLGenericPageContext::SetStyle( rtl::OUString& rStyleName )
367 {
368 	// set PageProperties?
369 	if(rStyleName.getLength())
370 	{
371 		try
372 		{
373 			const SvXMLImportContext* pContext = GetSdImport().GetShapeImport()->GetAutoStylesContext();
374 
375 			if( pContext && pContext->ISA( SvXMLStyleContext ) )
376 			{
377 				const SdXMLStylesContext* pStyles = (SdXMLStylesContext*)pContext;
378 				if(pStyles)
379 				{
380 					const SvXMLStyleContext* pStyle = pStyles->FindStyleChildContext(
381 						XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID, rStyleName);
382 
383 					if(pStyle && pStyle->ISA(XMLPropStyleContext))
384 					{
385 						XMLPropStyleContext* pPropStyle = (XMLPropStyleContext*)pStyle;
386 
387 						Reference <beans::XPropertySet> xPropSet1(mxShapes, uno::UNO_QUERY);
388 						if(xPropSet1.is())
389 						{
390 							Reference< beans::XPropertySet > xPropSet( xPropSet1 );
391 							Reference< beans::XPropertySet > xBackgroundSet;
392 
393 							const OUString aBackground(RTL_CONSTASCII_USTRINGPARAM("Background"));
394 							if( xPropSet1->getPropertySetInfo()->hasPropertyByName( aBackground ) )
395 							{
396 								Reference< beans::XPropertySetInfo > xInfo( xPropSet1->getPropertySetInfo() );
397 								if( xInfo.is() && xInfo->hasPropertyByName( aBackground ) )
398 								{
399 									Reference< lang::XMultiServiceFactory > xServiceFact(GetSdImport().GetModel(), uno::UNO_QUERY);
400 									if(xServiceFact.is())
401 									{
402 										xBackgroundSet = Reference< beans::XPropertySet >::query(
403 											xServiceFact->createInstance(
404 											OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.Background"))));
405 									}
406 								}
407 
408 								if( xBackgroundSet.is() )
409 									xPropSet = PropertySetMerger_CreateInstance( xPropSet1, xBackgroundSet );
410 							}
411 
412 							if(xPropSet.is())
413 							{
414 								pPropStyle->FillPropertySet(xPropSet);
415 
416 								if( xBackgroundSet.is() )
417 									xPropSet1->setPropertyValue( aBackground, uno::makeAny( xBackgroundSet ) );
418 							}
419 						}
420 					}
421 				}
422 			}
423 		}
424 		catch( uno::Exception )
425 		{
426 			DBG_ERROR( "SdXMLGenericPageContext::SetStyle(): uno::Exception catched!" );
427 		}
428 	}
429 }
430 
SetLayout()431 void SdXMLGenericPageContext::SetLayout()
432 {
433 	// set PresentationPageLayout?
434 	if(GetSdImport().IsImpress() && maPageLayoutName.getLength())
435 	{
436 		sal_Int32 nType = -1;
437 
438 		const SvXMLImportContext* pContext = GetSdImport().GetShapeImport()->GetStylesContext();
439 
440 		if( pContext && pContext->ISA( SvXMLStyleContext ) )
441 		{
442 			const SdXMLStylesContext* pStyles = (SdXMLStylesContext*)pContext;
443 			if(pStyles)
444 			{
445 				const SvXMLStyleContext* pStyle = pStyles->FindStyleChildContext( XML_STYLE_FAMILY_SD_PRESENTATIONPAGELAYOUT_ID, maPageLayoutName);
446 
447 				if(pStyle && pStyle->ISA(SdXMLPresentationPageLayoutContext))
448 				{
449 					SdXMLPresentationPageLayoutContext* pLayout = (SdXMLPresentationPageLayoutContext*)pStyle;
450 					nType = pLayout->GetTypeId();
451 				}
452 			}
453 
454 		}
455 		if( -1 == nType )
456 		{
457 			Reference< container::XNameAccess > xPageLayouts( GetSdImport().getPageLayouts() );
458 			if( xPageLayouts.is() )
459 			{
460 				if( xPageLayouts->hasByName( maPageLayoutName ) )
461 					xPageLayouts->getByName( maPageLayoutName ) >>= nType;
462 			}
463 
464 		}
465 
466 		if( -1 != nType )
467 		{
468 			Reference <beans::XPropertySet> xPropSet(mxShapes, uno::UNO_QUERY);
469 			if(xPropSet.is())
470 			{
471 				OUString aPropName(RTL_CONSTASCII_USTRINGPARAM("Layout"));
472 				Reference< beans::XPropertySetInfo > xInfo( xPropSet->getPropertySetInfo() );
473 				if( xInfo.is() && xInfo->hasPropertyByName( aPropName ) )
474 					xPropSet->setPropertyValue(aPropName, uno::makeAny( (sal_Int16)nType ) );
475 			}
476 		}
477 	}
478 }
479 
DeleteAllShapes()480 void SdXMLGenericPageContext::DeleteAllShapes()
481 {
482 	// now delete all up-to-now contained shapes; they have been created
483 	// when setting the presentation page layout.
484 	while(mxShapes->getCount())
485 	{
486 		Reference< drawing::XShape > xShape;
487 		uno::Any aAny(mxShapes->getByIndex(0L));
488 
489 		aAny >>= xShape;
490 
491 		if(xShape.is())
492 		{
493 			mxShapes->remove(xShape);
494 		}
495 	}
496 }
497 
SetPageMaster(OUString & rsPageMasterName)498 void SdXMLGenericPageContext::SetPageMaster( OUString& rsPageMasterName )
499 {
500 	if( GetSdImport().GetShapeImport()->GetStylesContext() )
501 	{
502 		// look for PageMaster with this name
503 
504 		// #80012# GetStylesContext() replaced with GetAutoStylesContext()
505 		const SvXMLStylesContext* pAutoStyles = GetSdImport().GetShapeImport()->GetAutoStylesContext();
506 
507 		const SvXMLStyleContext* pStyle = pAutoStyles ? pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_SD_PAGEMASTERCONEXT_ID, rsPageMasterName) : NULL;
508 
509 		if(pStyle && pStyle->ISA(SdXMLPageMasterContext))
510 		{
511 			const SdXMLPageMasterContext* pPageMaster = (SdXMLPageMasterContext*)pStyle;
512 			const SdXMLPageMasterStyleContext* pPageMasterContext = pPageMaster->GetPageMasterStyle();
513 
514 			if(pPageMasterContext)
515 			{
516 				Reference< drawing::XDrawPage > xMasterPage(GetLocalShapesContext(), uno::UNO_QUERY);
517 				if(xMasterPage.is())
518 				{
519 					// set sizes for this masterpage
520 					Reference <beans::XPropertySet> xPropSet(xMasterPage, uno::UNO_QUERY);
521 					if(xPropSet.is())
522 					{
523 						uno::Any aAny;
524 
525 						aAny <<= pPageMasterContext->GetBorderBottom();
526 						xPropSet->setPropertyValue(
527 							OUString(RTL_CONSTASCII_USTRINGPARAM("BorderBottom")), aAny);
528 
529 						aAny <<= pPageMasterContext->GetBorderLeft();
530 						xPropSet->setPropertyValue(
531 							OUString(RTL_CONSTASCII_USTRINGPARAM("BorderLeft")), aAny);
532 
533 						aAny <<= pPageMasterContext->GetBorderRight();
534 						xPropSet->setPropertyValue(
535 							OUString(RTL_CONSTASCII_USTRINGPARAM("BorderRight")), aAny);
536 
537 						aAny <<= pPageMasterContext->GetBorderTop();
538 						xPropSet->setPropertyValue(
539 							OUString(RTL_CONSTASCII_USTRINGPARAM("BorderTop")), aAny);
540 
541 						aAny <<= pPageMasterContext->GetWidth();
542 						xPropSet->setPropertyValue(
543 							OUString(RTL_CONSTASCII_USTRINGPARAM("Width")), aAny);
544 
545 						aAny <<= pPageMasterContext->GetHeight();
546 						xPropSet->setPropertyValue(
547 							OUString(RTL_CONSTASCII_USTRINGPARAM("Height")), aAny);
548 
549 						aAny <<= pPageMasterContext->GetOrientation();
550 						xPropSet->setPropertyValue(
551 							OUString(RTL_CONSTASCII_USTRINGPARAM("Orientation")), aAny);
552 					}
553 				}
554 			}
555 		}
556 
557 	}
558 }
559 
560 class NavigationOrderAccess : public ::cppu::WeakImplHelper1< XIndexAccess >
561 {
562 public:
563 	NavigationOrderAccess( std::vector< Reference< XShape > >& rShapes );
564 
565 	// XIndexAccess
566     virtual sal_Int32 SAL_CALL getCount(  ) throw (RuntimeException);
567     virtual Any SAL_CALL getByIndex( sal_Int32 Index ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException);
568 
569     // XElementAccess
570     virtual Type SAL_CALL getElementType(  ) throw (RuntimeException);
571     virtual sal_Bool SAL_CALL hasElements(  ) throw (RuntimeException);
572 
573 private:
574 	std::vector< Reference< XShape > > maShapes;
575 };
576 
NavigationOrderAccess(std::vector<Reference<XShape>> & rShapes)577 NavigationOrderAccess::NavigationOrderAccess( std::vector< Reference< XShape > >& rShapes )
578 {
579 	maShapes.swap( rShapes );
580 }
581 
582 // XIndexAccess
getCount()583 sal_Int32 SAL_CALL NavigationOrderAccess::getCount(  ) throw (RuntimeException)
584 {
585 	return static_cast< sal_Int32 >( maShapes.size() );
586 }
587 
getByIndex(sal_Int32 Index)588 Any SAL_CALL NavigationOrderAccess::getByIndex( sal_Int32 Index ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
589 {
590 	if( (Index < 0) || (Index > getCount()) )
591 		throw IndexOutOfBoundsException();
592 
593 	return Any( maShapes[Index] );
594 }
595 
596 // XElementAccess
getElementType()597 Type SAL_CALL NavigationOrderAccess::getElementType(  ) throw (RuntimeException)
598 {
599 	return XShape::static_type();
600 }
601 
hasElements()602 sal_Bool SAL_CALL NavigationOrderAccess::hasElements(  ) throw (RuntimeException)
603 {
604 	return maShapes.empty() ? sal_False : sal_True;
605 }
606 
SetNavigationOrder()607 void SdXMLGenericPageContext::SetNavigationOrder()
608 {
609 	if( msNavOrder.getLength() != 0 ) try
610 	{
611 		sal_uInt32 nIndex;
612 		const sal_uInt32 nCount = static_cast< sal_uInt32 >( mxShapes->getCount() );
613 		std::vector< Reference< XShape > > aShapes( nCount );
614 
615 		::comphelper::UnoInterfaceToUniqueIdentifierMapper& rIdMapper = GetSdImport().getInterfaceToIdentifierMapper();
616 		SvXMLTokenEnumerator aEnumerator( msNavOrder );
617 		OUString sId;
618 		for( nIndex = 0; nIndex < nCount; ++nIndex )
619 		{
620 			if( !aEnumerator.getNextToken(sId) )
621 				break;
622 
623 			aShapes[nIndex] = Reference< XShape >( rIdMapper.getReference( sId ), UNO_QUERY );
624 		}
625 
626 		for( nIndex = 0; nIndex < nCount; ++nIndex )
627 		{
628 			if( !aShapes[nIndex].is() )
629 			{
630 				DBG_ERROR("xmloff::SdXMLGenericPageContext::SetNavigationOrder(), draw:nav-order attribute incomplete!");
631 				// todo: warning?
632 				return;
633 			}
634 		}
635 
636 		Reference< XPropertySet > xSet( mxShapes, UNO_QUERY_THROW );
637 		xSet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "NavigationOrder" ) ), Any( Reference< XIndexAccess >( new NavigationOrderAccess( aShapes ) ) ) );
638 	}
639 	catch( uno::Exception& )
640 	{
641 		DBG_ERROR("xmloff::SdXMLGenericPageContext::SetNavigationOrder(), unexpected exception caught while importing shape navigation order!");
642 	}
643 }
644