xref: /aoo42x/main/xmloff/source/draw/ximpshap.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 
31 
32 
33 #include <tools/debug.hxx>
34 #include <com/sun/star/document/XEventsSupplier.hpp>
35 #include <com/sun/star/container/XNameReplace.hpp>
36 #include <com/sun/star/presentation/ClickAction.hpp>
37 #include <com/sun/star/drawing/FillStyle.hpp>
38 #include <com/sun/star/drawing/LineStyle.hpp>
39 #include "unointerfacetouniqueidentifiermapper.hxx"
40 #include <com/sun/star/drawing/XGluePointsSupplier.hpp>
41 #include <com/sun/star/container/XIdentifierAccess.hpp>
42 #include <com/sun/star/drawing/GluePoint2.hpp>
43 #include <com/sun/star/drawing/Alignment.hpp>
44 #include <com/sun/star/drawing/EscapeDirection.hpp>
45 #include <com/sun/star/media/ZoomLevel.hpp>
46 #include <com/sun/star/awt/Rectangle.hpp>
47 
48 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
49 #include <com/sun/star/container/XNameAccess.hpp>
50 #include <comphelper/extract.hxx>
51 #include "ximpshap.hxx"
52 #include <xmloff/XMLBase64ImportContext.hxx>
53 #include <xmloff/XMLShapeStyleContext.hxx>
54 #include <xmloff/xmluconv.hxx>
55 #include <com/sun/star/container/XNamed.hpp>
56 #include <com/sun/star/drawing/CircleKind.hpp>
57 #include <com/sun/star/beans/XPropertySet.hpp>
58 #include <com/sun/star/awt/XControlModel.hpp>
59 #include <com/sun/star/drawing/XControlShape.hpp>
60 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
61 #include <com/sun/star/drawing/PointSequence.hpp>
62 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
63 #include <com/sun/star/lang/XServiceInfo.hpp>
64 #include <com/sun/star/util/XCloneable.hpp>
65 #include <com/sun/star/beans/XMultiPropertyStates.hpp>
66 #include "xexptran.hxx"
67 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
68 #include <com/sun/star/beans/XPropertySetInfo.hpp>
69 #include <com/sun/star/drawing/ConnectorType.hpp>
70 #include <com/sun/star/drawing/HomogenMatrix3.hpp>
71 #include "PropertySetMerger.hxx"
72 #include <xmloff/families.hxx>
73 #include "ximpstyl.hxx"
74 #include"xmloff/xmlnmspe.hxx"
75 #include <xmloff/xmltoken.hxx>
76 #include "EnhancedCustomShapeToken.hxx"
77 #include "XMLReplacementImageContext.hxx"
78 #include "XMLImageMapContext.hxx"
79 #include "sdpropls.hxx"
80 #include "eventimp.hxx"
81 
82 #include "descriptionimp.hxx"
83 #include "ximpcustomshape.hxx"
84 #include "XMLEmbeddedObjectImportContext.hxx"
85 #include "xmloff/xmlerror.hxx"
86 #include <basegfx/matrix/b2dhommatrix.hxx>
87 #include <tools/string.hxx>
88 #include <com/sun/star/drawing/XEnhancedCustomShapeDefaulter.hpp>
89 
90 // --> OD 2006-02-22 #b6382898#
91 #include <com/sun/star/text/XTextDocument.hpp>
92 // <--
93 
94 using ::rtl::OUString;
95 using ::rtl::OUStringBuffer;
96 
97 using namespace ::com::sun::star;
98 using namespace ::com::sun::star::uno;
99 using namespace ::com::sun::star::drawing;
100 using namespace ::com::sun::star::style;
101 using namespace ::com::sun::star::container;
102 using namespace ::com::sun::star::document;
103 using namespace ::xmloff::token;
104 using namespace ::xmloff::EnhancedCustomShapeToken;
105 
106 SvXMLEnumMapEntry aXML_GlueAlignment_EnumMap[] =
107 {
108 	{ XML_TOP_LEFT, 	drawing::Alignment_TOP_LEFT },
109 	{ XML_TOP,			drawing::Alignment_TOP },
110 	{ XML_TOP_RIGHT,	drawing::Alignment_TOP_RIGHT },
111 	{ XML_LEFT,		    drawing::Alignment_LEFT },
112 	{ XML_CENTER,		drawing::Alignment_CENTER },
113 	{ XML_RIGHT,		drawing::Alignment_RIGHT },
114 	{ XML_BOTTOM_LEFT,	drawing::Alignment_BOTTOM_LEFT },
115 	{ XML_BOTTOM,		drawing::Alignment_BOTTOM },
116 	{ XML_BOTTOM_RIGHT, drawing::Alignment_BOTTOM_RIGHT },
117 	{ XML_TOKEN_INVALID, 0 }
118 };
119 
120 SvXMLEnumMapEntry aXML_GlueEscapeDirection_EnumMap[] =
121 {
122 	{ XML_AUTO, 		drawing::EscapeDirection_SMART },
123 	{ XML_LEFT,	    	drawing::EscapeDirection_LEFT },
124     { XML_RIGHT,		drawing::EscapeDirection_RIGHT },
125     { XML_UP,			drawing::EscapeDirection_UP },
126     { XML_DOWN,		    drawing::EscapeDirection_DOWN },
127     { XML_HORIZONTAL,	drawing::EscapeDirection_HORIZONTAL },
128     { XML_VERTICAL,	    drawing::EscapeDirection_VERTICAL },
129 	{ XML_TOKEN_INVALID, 0 }
130 };
131 
132 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
133 
134 static bool ImpIsEmptyURL( const ::rtl::OUString& rURL )
135 {
136     if( rURL.getLength() == 0 )
137         return true;
138 
139     // #i13140# Also compare against 'toplevel' URLs. which also
140     // result in empty filename strings.
141     if( 0 == rURL.compareToAscii( "#./" ) )
142         return true;
143 
144     return false;
145 }
146 
147 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
148 
149 TYPEINIT1( SvXMLShapeContext, SvXMLImportContext );
150 TYPEINIT1( SdXMLShapeContext, SvXMLShapeContext );
151 
152 SdXMLShapeContext::SdXMLShapeContext(
153 	SvXMLImport& rImport,
154 	sal_uInt16 nPrfx,
155 	const OUString& rLocalName,
156 	const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
157 	uno::Reference< drawing::XShapes >& rShapes,
158     sal_Bool bTemporaryShape)
159 :	SvXMLShapeContext( rImport, nPrfx, rLocalName, bTemporaryShape )
160 ,	mxShapes( rShapes )
161 ,	mxAttrList(xAttrList)
162 ,	mbListContextPushed( false )
163 ,	mnStyleFamily(XML_STYLE_FAMILY_SD_GRAPHICS_ID)
164 ,	mbIsPlaceholder(sal_False)
165 ,	mbClearDefaultAttributes( true )
166 ,	mbIsUserTransformed(sal_False)
167 ,	mnZOrder(-1)
168 ,	maSize(1, 1)
169 ,	maPosition(0, 0)
170 ,	mbVisible(true)
171 ,	mbPrintable(true)
172 {
173 }
174 
175 //////////////////////////////////////////////////////////////////////////////
176 
177 SdXMLShapeContext::~SdXMLShapeContext()
178 {
179 }
180 
181 //////////////////////////////////////////////////////////////////////////////
182 
183 SvXMLImportContext *SdXMLShapeContext::CreateChildContext( sal_uInt16 p_nPrefix,
184 	const OUString& rLocalName,
185 	const uno::Reference< xml::sax::XAttributeList>& xAttrList )
186 {
187 	SvXMLImportContext * pContext = NULL;
188 
189 	// #i68101#
190 	if( p_nPrefix == XML_NAMESPACE_SVG &&
191 		(IsXMLToken( rLocalName, XML_TITLE ) || IsXMLToken( rLocalName, XML_DESC ) ) )
192 	{
193 		pContext = new SdXMLDescriptionContext( GetImport(), p_nPrefix, rLocalName, xAttrList, mxShape );
194 	}
195 	else if( p_nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) )
196 	{
197 		pContext = new SdXMLEventsContext( GetImport(), p_nPrefix, rLocalName, xAttrList, mxShape );
198 	}
199 	else if( p_nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( rLocalName, XML_GLUE_POINT ) )
200 	{
201 		addGluePoint( xAttrList );
202 	}
203 	else if( p_nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( rLocalName, XML_THUMBNAIL ) )
204 	{
205 		// search attributes for xlink:href
206 		sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
207 		for(sal_Int16 i=0; i < nAttrCount; i++)
208 		{
209 			OUString sAttrName = xAttrList->getNameByIndex( i );
210 			OUString aLocalName;
211 			sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
212 
213 			if( nPrefix == XML_NAMESPACE_XLINK )
214 			{
215 				if( IsXMLToken( aLocalName, XML_HREF ) )
216 				{
217 					maThumbnailURL = xAttrList->getValueByIndex( i );
218 					break;
219 				}
220 			}
221 		}
222 	}
223 	else
224 	{
225 		// create text cursor on demand
226 		if( !mxCursor.is() )
227 		{
228 			uno::Reference< text::XText > xText( mxShape, uno::UNO_QUERY );
229 			if( xText.is() )
230 			{
231 				UniReference < XMLTextImportHelper > xTxtImport =
232 					GetImport().GetTextImport();
233 				mxOldCursor = xTxtImport->GetCursor();
234 				mxCursor = xText->createTextCursor();
235 				if( mxCursor.is() )
236 				{
237 					xTxtImport->SetCursor( mxCursor );
238 				}
239 
240 				// remember old list item and block (#91964#) and reset them
241 				// for the text frame
242                 xTxtImport->PushListContext();
243                 mbListContextPushed = true;
244 			}
245 		}
246 
247 		// if we have a text cursor, lets  try to import some text
248 		if( mxCursor.is() )
249 		{
250 			pContext = GetImport().GetTextImport()->CreateTextChildContext(
251 				GetImport(), p_nPrefix, rLocalName, xAttrList );
252 		}
253 	}
254 
255 	// call parent for content
256 	if(!pContext)
257 		pContext = SvXMLImportContext::CreateChildContext( p_nPrefix, rLocalName, xAttrList );
258 
259 	return pContext;
260 }
261 
262 void SdXMLShapeContext::addGluePoint( const uno::Reference< xml::sax::XAttributeList>& xAttrList )
263 {
264 	// get the glue points container for this shape if its not already there
265 	if( !mxGluePoints.is() )
266 	{
267 		uno::Reference< drawing::XGluePointsSupplier > xSupplier( mxShape, uno::UNO_QUERY );
268 		if( !xSupplier.is() )
269 			return;
270 
271 		mxGluePoints = uno::Reference< container::XIdentifierContainer >::query( xSupplier->getGluePoints() );
272 
273 		if( !mxGluePoints.is() )
274 			return;
275 	}
276 
277 	drawing::GluePoint2 aGluePoint;
278 	aGluePoint.IsUserDefined = sal_True;
279 	aGluePoint.Position.X = 0;
280 	aGluePoint.Position.Y = 0;
281 	aGluePoint.Escape = drawing::EscapeDirection_SMART;
282 	aGluePoint.PositionAlignment = drawing::Alignment_CENTER;
283 	aGluePoint.IsRelative = sal_True;
284 
285 	sal_Int32 nId = -1;
286 
287 	// read attributes for the 3DScene
288 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
289 	for(sal_Int16 i=0; i < nAttrCount; i++)
290 	{
291 		OUString sAttrName = xAttrList->getNameByIndex( i );
292 		OUString aLocalName;
293 		sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
294 		const OUString sValue( xAttrList->getValueByIndex( i ) );
295 
296 		if( nPrefix == XML_NAMESPACE_SVG )
297 		{
298 			if( IsXMLToken( aLocalName, XML_X ) )
299 			{
300 				GetImport().GetMM100UnitConverter().convertMeasure(aGluePoint.Position.X, sValue);
301 			}
302 			else if( IsXMLToken( aLocalName, XML_Y ) )
303 			{
304 				GetImport().GetMM100UnitConverter().convertMeasure(aGluePoint.Position.Y, sValue);
305 			}
306 		}
307 		else if( nPrefix == XML_NAMESPACE_DRAW )
308 		{
309 			if( IsXMLToken( aLocalName, XML_ID ) )
310 			{
311 				nId = sValue.toInt32();
312 			}
313 			else if( IsXMLToken( aLocalName, XML_ALIGN ) )
314 			{
315 				sal_uInt16 eKind;
316 				if( SvXMLUnitConverter::convertEnum( eKind, sValue, aXML_GlueAlignment_EnumMap ) )
317 				{
318 					aGluePoint.PositionAlignment = (drawing::Alignment)eKind;
319 					aGluePoint.IsRelative = sal_False;
320 				}
321 			}
322 			else if( IsXMLToken( aLocalName, XML_ESCAPE_DIRECTION ) )
323 			{
324 				sal_uInt16 eKind;
325 				if( SvXMLUnitConverter::convertEnum( eKind, sValue, aXML_GlueEscapeDirection_EnumMap ) )
326 				{
327 					aGluePoint.Escape = (drawing::EscapeDirection)eKind;
328 				}
329 			}
330 		}
331 	}
332 
333 	if( nId != -1 )
334 	{
335 		try
336 		{
337 			sal_Int32 nInternalId = mxGluePoints->insert( uno::makeAny( aGluePoint ) );
338 			GetImport().GetShapeImport()->addGluePointMapping( mxShape, nId, nInternalId );
339 		}
340 		catch( uno::Exception& )
341 		{
342 			DBG_ERROR( "exception during setting of glue points!");
343 		}
344 	}
345 }
346 //////////////////////////////////////////////////////////////////////////////
347 
348 void SdXMLShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>&)
349 {
350     GetImport().GetShapeImport()->finishShape( mxShape, mxAttrList, mxShapes );
351 }
352 
353 void SdXMLShapeContext::EndElement()
354 {
355 	if(mxCursor.is())
356 	{
357 		// delete addition newline
358 		const OUString aEmpty;
359 		mxCursor->gotoEnd( sal_False );
360 		mxCursor->goLeft( 1, sal_True );
361 		mxCursor->setString( aEmpty );
362 
363 		// reset cursor
364 		GetImport().GetTextImport()->ResetCursor();
365 	}
366 
367 	if(mxOldCursor.is())
368 		GetImport().GetTextImport()->SetCursor( mxOldCursor );
369 
370     // reinstall old list item (if necessary) #91964#
371     if (mbListContextPushed) {
372         GetImport().GetTextImport()->PopListContext();
373     }
374 
375 	if( msHyperlink.getLength() != 0 ) try
376 	{
377 		const OUString sBookmark( RTL_CONSTASCII_USTRINGPARAM( "Bookmark" ) );
378 
379         Reference< XEventsSupplier > xEventsSupplier( mxShape, UNO_QUERY );
380 		if( xEventsSupplier.is() )
381 		{
382 			const OUString sEventType( RTL_CONSTASCII_USTRINGPARAM( "EventType" ) );
383 			const OUString sClickAction( RTL_CONSTASCII_USTRINGPARAM( "ClickAction" ) );
384 
385 			Reference< XNameReplace > xEvents( xEventsSupplier->getEvents(), UNO_QUERY_THROW );
386 
387 			uno::Sequence< beans::PropertyValue > aProperties( 3 );
388 			aProperties[0].Name = sEventType;
389 			aProperties[0].Handle = -1;
390 			aProperties[0].Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM("Presentation") );
391 			aProperties[0].State = beans::PropertyState_DIRECT_VALUE;
392 
393 			aProperties[1].Name = sClickAction;
394 			aProperties[1].Handle = -1;
395 			aProperties[1].Value <<= ::com::sun::star::presentation::ClickAction_DOCUMENT;
396 			aProperties[1].State = beans::PropertyState_DIRECT_VALUE;
397 
398 			aProperties[2].Name = sBookmark;
399 			aProperties[2].Handle = -1;
400 			aProperties[2].Value <<= msHyperlink;
401 			aProperties[2].State = beans::PropertyState_DIRECT_VALUE;
402 
403 			const OUString sAPIEventName( RTL_CONSTASCII_USTRINGPARAM( "OnClick" ) );
404 			xEvents->replaceByName( sAPIEventName, Any( aProperties ) );
405 		}
406 		else
407 		{
408 			// in draw use the Bookmark property
409 			Reference< beans::XPropertySet > xSet( mxShape, UNO_QUERY_THROW );
410 			xSet->setPropertyValue( sBookmark, Any( msHyperlink ) );
411 			xSet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "OnClick" ) ), Any( ::com::sun::star::presentation::ClickAction_DOCUMENT ) );
412 		}
413 	}
414 	catch( Exception& )
415 	{
416 		DBG_ERROR("xmloff::SdXMLShapeContext::EndElement(), exception caught while setting hyperlink!");
417 	}
418 
419 	if( mxLockable.is() )
420 		mxLockable->removeActionLock();
421 }
422 
423 //////////////////////////////////////////////////////////////////////////////
424 
425 void SdXMLShapeContext::AddShape(uno::Reference< drawing::XShape >& xShape)
426 {
427 	if(xShape.is())
428 	{
429 		// set shape local
430 		mxShape = xShape;
431 
432 		if(maShapeName.getLength())
433 		{
434 			uno::Reference< container::XNamed > xNamed( mxShape, uno::UNO_QUERY );
435 			if( xNamed.is() )
436 				xNamed->setName( maShapeName );
437 		}
438 
439 		UniReference< XMLShapeImportHelper > xImp( GetImport().GetShapeImport() );
440 		xImp->addShape( xShape, mxAttrList, mxShapes );
441 
442 		if( mbClearDefaultAttributes )
443 		{
444 	        uno::Reference<beans::XMultiPropertyStates> xMultiPropertyStates(xShape, uno::UNO_QUERY );
445 		    if (xMultiPropertyStates.is())
446 			    xMultiPropertyStates->setAllPropertiesToDefault();
447 		}
448 
449 		if( !mbVisible || !mbPrintable ) try
450 		{
451 			uno::Reference< beans::XPropertySet > xSet( xShape, uno::UNO_QUERY_THROW );
452 			if( !mbVisible )
453 				xSet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Visible" ) ), uno::Any( sal_False ) );
454 
455 			if( !mbPrintable )
456 				xSet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Printable" ) ), uno::Any( sal_False ) );
457 		}
458 		catch( Exception& )
459 		{
460 			DBG_ERROR( "SdXMLShapeContext::AddShape(), exception caught!" );
461 		}
462 
463 		// #107848#
464 		if(!mbTemporaryShape && (!GetImport().HasTextImport()
465 			|| !GetImport().GetTextImport()->IsInsideDeleteContext()))
466 		{
467 			xImp->shapeWithZIndexAdded( xShape, mnZOrder );
468 		}
469 
470 		if( maShapeId.getLength() )
471 		{
472 			uno::Reference< uno::XInterface > xRef( xShape, uno::UNO_QUERY );
473 			GetImport().getInterfaceToIdentifierMapper().registerReference( maShapeId, xRef );
474 		}
475 
476 		// #91065# count only if counting for shape import is enabled
477 		if(GetImport().GetShapeImport()->IsHandleProgressBarEnabled())
478 		{
479 			// #80365# increment progress bar at load once for each draw object
480 			GetImport().GetProgressBarHelper()->Increment();
481 		}
482 	}
483 
484 	mxLockable = uno::Reference< document::XActionLockable >::query( xShape );
485 
486 	if( mxLockable.is() )
487 		mxLockable->addActionLock();
488 
489 }
490 
491 //////////////////////////////////////////////////////////////////////////////
492 
493 void SdXMLShapeContext::AddShape(const char* pServiceName )
494 {
495 	uno::Reference< lang::XMultiServiceFactory > xServiceFact(GetImport().GetModel(), uno::UNO_QUERY);
496 	if(xServiceFact.is())
497 	{
498         try
499         {
500             // --> OD 2006-02-22 #b6382898#
501             // Since fix for issue i33294 the Writer model doesn't support
502             // com.sun.star.drawing.OLE2Shape anymore.
503             // To handle Draw OLE objects it's decided to import these
504             // objects as com.sun.star.drawing.OLE2Shape and convert these
505             // objects after the import into com.sun.star.drawing.GraphicObjectShape.
506             uno::Reference< drawing::XShape > xShape;
507             if ( OUString::createFromAscii(pServiceName).compareToAscii( "com.sun.star.drawing.OLE2Shape" ) == 0 &&
508                  uno::Reference< text::XTextDocument >(GetImport().GetModel(), uno::UNO_QUERY).is() )
509             {
510                 xShape = uno::Reference< drawing::XShape >(xServiceFact->createInstance(OUString::createFromAscii("com.sun.star.drawing.temporaryForXMLImportOLE2Shape")), uno::UNO_QUERY);
511             }
512             else
513             {
514                 xShape = uno::Reference< drawing::XShape >(xServiceFact->createInstance(OUString::createFromAscii(pServiceName)), uno::UNO_QUERY);
515             }
516             // <--
517             if( xShape.is() )
518                 AddShape( xShape );
519         }
520         catch( const uno::Exception& e )
521         {
522             uno::Sequence<rtl::OUString> aSeq( 1 );
523             aSeq[0] = OUString::createFromAscii(pServiceName);
524             GetImport().SetError( XMLERROR_FLAG_ERROR | XMLERROR_API,
525                                   aSeq, e.Message, NULL );
526         }
527 	}
528 }
529 
530 //////////////////////////////////////////////////////////////////////////////
531 
532 void SdXMLShapeContext::SetTransformation()
533 {
534 	if(mxShape.is())
535 	{
536 		uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
537 		if(xPropSet.is())
538 		{
539 			::basegfx::B2DHomMatrix aTransformation;
540 
541 			if(maSize.Width != 1 || maSize.Height != 1)
542 			{
543 				// take care there are no zeros used by error
544 				if(0 == maSize.Width)
545 					maSize.Width = 1;
546 				if(0 == maSize.Height)
547 					maSize.Height = 1;
548 
549 				// set global size. This should always be used.
550 				aTransformation.scale(maSize.Width, maSize.Height);
551 			}
552 
553 			if(maPosition.X != 0 || maPosition.Y != 0)
554 			{
555 				// if global position is used, add it to transformation
556 				aTransformation.translate(maPosition.X, maPosition.Y);
557 			}
558 
559 			if(mnTransform.NeedsAction())
560 			{
561 				// transformation is used, apply to object.
562 				// NOTICE: The transformation is applied AFTER evtl. used
563 				// global positioning and scaling is used, so any shear or
564 				// rotate used herein is applied around the (0,0) position
565 				// of the PAGE object !!!
566 				::basegfx::B2DHomMatrix aMat;
567 				mnTransform.GetFullTransform(aMat);
568 
569 				// now add to transformation
570 				aTransformation *= aMat;
571 			}
572 
573 			// now set transformation for this object
574 			uno::Any aAny;
575 			drawing::HomogenMatrix3 aMatrix;
576 
577 			aMatrix.Line1.Column1 = aTransformation.get(0, 0);
578 			aMatrix.Line1.Column2 = aTransformation.get(0, 1);
579 			aMatrix.Line1.Column3 = aTransformation.get(0, 2);
580 
581 			aMatrix.Line2.Column1 = aTransformation.get(1, 0);
582 			aMatrix.Line2.Column2 = aTransformation.get(1, 1);
583 			aMatrix.Line2.Column3 = aTransformation.get(1, 2);
584 
585 			aMatrix.Line3.Column1 = aTransformation.get(2, 0);
586 			aMatrix.Line3.Column2 = aTransformation.get(2, 1);
587 			aMatrix.Line3.Column3 = aTransformation.get(2, 2);
588 
589 			aAny <<= aMatrix;
590 
591 			xPropSet->setPropertyValue(
592 				OUString(RTL_CONSTASCII_USTRINGPARAM("Transformation")), aAny);
593         }
594 	}
595 }
596 
597 //////////////////////////////////////////////////////////////////////////////
598 
599 void SdXMLShapeContext::SetStyle( bool bSupportsStyle /* = true */)
600 {
601 	try
602 	{
603 		uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
604 		if( !xPropSet.is() )
605 			return;
606 
607 		do
608 		{
609 			XMLPropStyleContext* pDocStyle = NULL;
610 
611 			// set style on shape
612 			if(maDrawStyleName.getLength() == 0)
613 				break;
614 
615 			const SvXMLStyleContext* pStyle = 0L;
616 			sal_Bool bAutoStyle(sal_False);
617 
618 			if(GetImport().GetShapeImport()->GetAutoStylesContext())
619 				pStyle = GetImport().GetShapeImport()->GetAutoStylesContext()->FindStyleChildContext(mnStyleFamily, maDrawStyleName);
620 
621 			if(pStyle)
622 				bAutoStyle = sal_True;
623 
624 			if(!pStyle && GetImport().GetShapeImport()->GetStylesContext())
625 				pStyle = GetImport().GetShapeImport()->GetStylesContext()->FindStyleChildContext(mnStyleFamily, maDrawStyleName);
626 
627 			OUString aStyleName = maDrawStyleName;
628 			uno::Reference< style::XStyle > xStyle;
629 
630 			if( pStyle && pStyle->ISA(XMLShapeStyleContext) )
631 			{
632 				pDocStyle = PTR_CAST( XMLShapeStyleContext, pStyle );
633 
634 				if( pDocStyle->GetStyle().is() )
635 				{
636 					xStyle = pDocStyle->GetStyle();
637 				}
638 				else
639 				{
640                     aStyleName = pDocStyle->GetParentName();
641 				}
642 			}
643 
644 			if( !xStyle.is() && aStyleName.getLength() )
645 			{
646 				try
647 				{
648 
649 					uno::Reference< style::XStyleFamiliesSupplier > xFamiliesSupplier( GetImport().GetModel(), uno::UNO_QUERY );
650 
651 					if( xFamiliesSupplier.is() )
652 					{
653 						uno::Reference< container::XNameAccess > xFamilies( xFamiliesSupplier->getStyleFamilies() );
654 						if( xFamilies.is() )
655 						{
656 
657 							uno::Reference< container::XNameAccess > xFamily;
658 
659 							if( XML_STYLE_FAMILY_SD_PRESENTATION_ID == mnStyleFamily )
660 							{
661 								aStyleName = GetImport().GetStyleDisplayName(
662 									XML_STYLE_FAMILY_SD_PRESENTATION_ID,
663 									aStyleName );
664 								sal_Int32 nPos = aStyleName.lastIndexOf( sal_Unicode('-') );
665 								if( -1 != nPos )
666 								{
667 									OUString aFamily( aStyleName.copy( 0, nPos ) );
668 
669 									xFamilies->getByName( aFamily ) >>= xFamily;
670 									aStyleName = aStyleName.copy( nPos + 1 );
671 								}
672 							}
673 							else
674 							{
675 								// get graphics familie
676 								xFamilies->getByName( OUString( RTL_CONSTASCII_USTRINGPARAM( "graphics" ) ) ) >>= xFamily;
677 								aStyleName = GetImport().GetStyleDisplayName(
678 									XML_STYLE_FAMILY_SD_GRAPHICS_ID,
679 									aStyleName );
680 							}
681 
682 							if( xFamily.is() )
683 								xFamily->getByName( aStyleName ) >>= xStyle;
684 						}
685 					}
686 				}
687 				catch( uno::Exception& )
688 				{
689 					DBG_ERROR( "could not find style for shape!" );
690 				}
691 			}
692 
693 			if( bSupportsStyle && xStyle.is() )
694 			{
695 				try
696 				{
697 					// set style on object
698 					uno::Any aAny;
699 					aAny <<= xStyle;
700 					xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Style")), aAny);
701 				}
702 				catch( uno::Exception& )
703 				{
704 					DBG_ERROR( "could not find style for shape!" );
705 				}
706 			}
707 
708 			// if this is an auto style, set its properties
709 			if(bAutoStyle && pDocStyle)
710 			{
711 				// set PropertySet on object
712 				pDocStyle->FillPropertySet(xPropSet);
713 			}
714 
715 		} while(0);
716 
717 		// try to set text auto style
718 		do
719 		{
720 			// set style on shape
721 			if( 0 == maTextStyleName.getLength() )
722 				break;
723 
724 			if( NULL == GetImport().GetShapeImport()->GetAutoStylesContext())
725 				break;
726 
727             const SvXMLStyleContext* pTempStyle = GetImport().GetShapeImport()->GetAutoStylesContext()->FindStyleChildContext(XML_STYLE_FAMILY_TEXT_PARAGRAPH, maTextStyleName);
728 			XMLPropStyleContext* pStyle = PTR_CAST( XMLPropStyleContext, pTempStyle ); // use temp var, PTR_CAST is a bad macro, FindStyleChildContext will be called twice
729 			if( pStyle == NULL )
730 				break;
731 
732 			// set PropertySet on object
733 			pStyle->FillPropertySet(xPropSet);
734 
735 		} while(0);
736 	}
737 	catch( uno::Exception& )
738 	{
739 	}
740 }
741 
742 void SdXMLShapeContext::SetLayer()
743 {
744 	if( maLayerName.getLength() )
745 	{
746 		try
747 		{
748 			uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
749 			if(xPropSet.is() )
750 			{
751 				uno::Any aAny;
752 				aAny <<= maLayerName;
753 
754 				xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("LayerName")), aAny);
755 				return;
756 			}
757 		}
758 		catch( uno::Exception e )
759 		{
760 		}
761 	}
762 }
763 
764 void SdXMLShapeContext::SetThumbnail()
765 {
766 	if( 0 == maThumbnailURL.getLength() )
767 		return;
768 
769 	try
770 	{
771 		uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
772 		if( !xPropSet.is() )
773 			return;
774 
775 		const OUString sProperty(RTL_CONSTASCII_USTRINGPARAM("ThumbnailGraphicURL"));
776 
777 		uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xPropSet->getPropertySetInfo() );
778 		if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName( sProperty ) )
779 		{
780 			// load the thumbnail graphic and export it to a wmf stream so we can set
781 			// it at the api
782 
783 			const OUString aInternalURL( GetImport().ResolveGraphicObjectURL( maThumbnailURL, sal_False ) );
784 			xPropSet->setPropertyValue( sProperty, uno::makeAny( aInternalURL ) );
785 		}
786 	}
787 	catch( uno::Exception e )
788 	{
789 	}
790 }
791 
792 // this is called from the parent group for each unparsed attribute in the attribute list
793 void SdXMLShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
794 {
795     bool bHaveXmlId( false );
796 	if( (XML_NAMESPACE_DRAW == nPrefix) || (XML_NAMESPACE_DRAW_EXT == nPrefix) )
797 	{
798 		if( IsXMLToken( rLocalName, XML_ZINDEX ) )
799 		{
800 			mnZOrder = rValue.toInt32();
801 		}
802 		else if( IsXMLToken( rLocalName, XML_ID ) )
803         {
804             if (!bHaveXmlId) { maShapeId = rValue; };
805         }
806 		else if( IsXMLToken( rLocalName, XML_NAME ) )
807 		{
808 			maShapeName = rValue;
809 		}
810 		else if( IsXMLToken( rLocalName, XML_STYLE_NAME ) )
811 		{
812 			maDrawStyleName = rValue;
813 		}
814 		else if( IsXMLToken( rLocalName, XML_TEXT_STYLE_NAME ) )
815 		{
816 			maTextStyleName = rValue;
817 		}
818 		else if( IsXMLToken( rLocalName, XML_LAYER ) )
819 		{
820 			maLayerName = rValue;
821 		}
822 		else if( IsXMLToken( rLocalName, XML_TRANSFORM ) )
823 		{
824 			mnTransform.SetString(rValue, GetImport().GetMM100UnitConverter());
825 		}
826 		else if( IsXMLToken( rLocalName, XML_DISPLAY ) )
827 		{
828 			mbVisible = IsXMLToken( rValue, XML_ALWAYS ) || IsXMLToken( rValue, XML_SCREEN );
829 			mbPrintable = IsXMLToken( rValue, XML_ALWAYS ) || IsXMLToken( rValue, XML_PRINTER );
830 		}
831 	}
832 	else if( XML_NAMESPACE_PRESENTATION == nPrefix )
833 	{
834 		if( IsXMLToken( rLocalName, XML_USER_TRANSFORMED ) )
835 		{
836 			mbIsUserTransformed = IsXMLToken( rValue, XML_TRUE );
837 		}
838 		else if( IsXMLToken( rLocalName, XML_PLACEHOLDER ) )
839 		{
840 			mbIsPlaceholder = IsXMLToken( rValue, XML_TRUE );
841 			if( mbIsPlaceholder )
842 				mbClearDefaultAttributes = false;
843 		}
844 		else if( IsXMLToken( rLocalName, XML_CLASS ) )
845 		{
846 			maPresentationClass = rValue;
847 		}
848 		else if( IsXMLToken( rLocalName, XML_STYLE_NAME ) )
849 		{
850 			maDrawStyleName = rValue;
851 			mnStyleFamily = XML_STYLE_FAMILY_SD_PRESENTATION_ID;
852 		}
853 	}
854 	else if( XML_NAMESPACE_SVG == nPrefix )
855 	{
856 		if( IsXMLToken( rLocalName, XML_X ) )
857 		{
858 			GetImport().GetMM100UnitConverter().convertMeasure(maPosition.X, rValue);
859 		}
860 		else if( IsXMLToken( rLocalName, XML_Y ) )
861 		{
862 			GetImport().GetMM100UnitConverter().convertMeasure(maPosition.Y, rValue);
863 		}
864 		else if( IsXMLToken( rLocalName, XML_WIDTH ) )
865 		{
866 			GetImport().GetMM100UnitConverter().convertMeasure(maSize.Width, rValue);
867 			if( maSize.Width > 0 )
868 				maSize.Width += 1;
869 			else if( maSize.Width < 0 )
870 				maSize.Width -= 1;
871 		}
872 		else if( IsXMLToken( rLocalName, XML_HEIGHT ) )
873 		{
874 			GetImport().GetMM100UnitConverter().convertMeasure(maSize.Height, rValue);
875 			if( maSize.Height > 0 )
876 				maSize.Height += 1;
877 			else if( maSize.Height < 0 )
878 				maSize.Height -= 1;
879 		}
880 		else if( IsXMLToken( rLocalName, XML_TRANSFORM ) )
881 		{
882 			// because of #85127# take svg:transform into account and hanle like
883 			// draw:transform for compatibility
884 			mnTransform.SetString(rValue, GetImport().GetMM100UnitConverter());
885 		}
886 
887 		// #i68101#
888 		else if( IsXMLToken( rLocalName, XML_TITLE ) )
889 		{
890 			maShapeTitle = rValue;
891 		}
892 		else if( IsXMLToken( rLocalName, XML_DESC ) )
893 		{
894 			maShapeDescription = rValue;
895 		}
896 	}
897 	else if( (XML_NAMESPACE_NONE == nPrefix) || (XML_NAMESPACE_XML == nPrefix) )
898 	{
899 		if( IsXMLToken( rLocalName, XML_ID ) )
900 		{
901 			maShapeId = rValue;
902             bHaveXmlId = true;
903         }
904     }
905 }
906 
907 sal_Bool SdXMLShapeContext::isPresentationShape() const
908 {
909 	if( maPresentationClass.getLength() && (const_cast<SdXMLShapeContext*>(this))->GetImport().GetShapeImport()->IsPresentationShapesSupported() )
910 	{
911 		if(XML_STYLE_FAMILY_SD_PRESENTATION_ID == mnStyleFamily)
912 		{
913 			return sal_True;
914 		}
915 
916 		if( IsXMLToken( maPresentationClass, XML_HEADER ) || IsXMLToken( maPresentationClass, XML_FOOTER ) ||
917 			IsXMLToken( maPresentationClass, XML_PAGE_NUMBER ) || IsXMLToken( maPresentationClass, XML_DATE_TIME ) )
918 		{
919 			return sal_True;
920 		}
921 	}
922 
923 	return sal_False;
924 }
925 
926 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
927 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
928 
929 TYPEINIT1( SdXMLRectShapeContext, SdXMLShapeContext );
930 
931 SdXMLRectShapeContext::SdXMLRectShapeContext(
932 	SvXMLImport& rImport,
933 	sal_uInt16 nPrfx,
934 	const OUString& rLocalName,
935 	const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
936 	uno::Reference< drawing::XShapes >& rShapes,
937     sal_Bool bTemporaryShape)
938 :	SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
939 	mnRadius( 0L )
940 {
941 }
942 
943 //////////////////////////////////////////////////////////////////////////////
944 
945 SdXMLRectShapeContext::~SdXMLRectShapeContext()
946 {
947 }
948 
949 //////////////////////////////////////////////////////////////////////////////
950 
951 // this is called from the parent group for each unparsed attribute in the attribute list
952 void SdXMLRectShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
953 {
954 	if( XML_NAMESPACE_DRAW == nPrefix )
955 	{
956 		if( IsXMLToken( rLocalName, XML_CORNER_RADIUS ) )
957 		{
958 			GetImport().GetMM100UnitConverter().convertMeasure(mnRadius, rValue);
959 			return;
960 		}
961 	}
962 
963 	SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
964 }
965 
966 //////////////////////////////////////////////////////////////////////////////
967 
968 void SdXMLRectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
969 {
970 	// create rectangle shape
971 	AddShape("com.sun.star.drawing.RectangleShape");
972 	if(mxShape.is())
973 	{
974 		// Add, set Style and properties from base shape
975 		SetStyle();
976 		SetLayer();
977 
978 		// set pos, size, shear and rotate
979 		SetTransformation();
980 
981 		if(mnRadius)
982 		{
983 			uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
984 			if(xPropSet.is())
985 			{
986 				try
987 				{
988 					xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("CornerRadius")), uno::makeAny( mnRadius ) );
989 				}
990 				catch( uno::Exception& )
991 				{
992 					DBG_ERROR( "exception during setting of corner radius!");
993 				}
994 			}
995 		}
996 		SdXMLShapeContext::StartElement(xAttrList);
997 	}
998 }
999 
1000 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1001 ////////////////////////////////////////3////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1002 
1003 TYPEINIT1( SdXMLLineShapeContext, SdXMLShapeContext );
1004 
1005 SdXMLLineShapeContext::SdXMLLineShapeContext(
1006 	SvXMLImport& rImport,
1007 	sal_uInt16 nPrfx,
1008 	const OUString& rLocalName,
1009 	const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
1010 	uno::Reference< drawing::XShapes >& rShapes,
1011     sal_Bool bTemporaryShape)
1012 :	SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
1013 	mnX1( 0L ),
1014 	mnY1( 0L ),
1015 	mnX2( 1L ),
1016 	mnY2( 1L )
1017 {
1018 }
1019 
1020 //////////////////////////////////////////////////////////////////////////////
1021 
1022 SdXMLLineShapeContext::~SdXMLLineShapeContext()
1023 {
1024 }
1025 
1026 //////////////////////////////////////////////////////////////////////////////
1027 
1028 // this is called from the parent group for each unparsed attribute in the attribute list
1029 void SdXMLLineShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
1030 {
1031 	if( XML_NAMESPACE_SVG == nPrefix )
1032 	{
1033 		if( IsXMLToken( rLocalName, XML_X1 ) )
1034 		{
1035 			GetImport().GetMM100UnitConverter().convertMeasure(mnX1, rValue);
1036 			return;
1037 		}
1038 		if( IsXMLToken( rLocalName, XML_Y1 ) )
1039 		{
1040 			GetImport().GetMM100UnitConverter().convertMeasure(mnY1, rValue);
1041 			return;
1042 		}
1043 		if( IsXMLToken( rLocalName, XML_X2 ) )
1044 		{
1045 			GetImport().GetMM100UnitConverter().convertMeasure(mnX2, rValue);
1046 			return;
1047 		}
1048 		if( IsXMLToken( rLocalName, XML_Y2 ) )
1049 		{
1050 			GetImport().GetMM100UnitConverter().convertMeasure(mnY2, rValue);
1051 			return;
1052 		}
1053 	}
1054 
1055 	SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
1056 }
1057 
1058 //////////////////////////////////////////////////////////////////////////////
1059 
1060 void SdXMLLineShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
1061 {
1062 	// #85920# use SetTransformation() to handle import of simple lines.
1063 	// This is necessary to kake into account all anchor positions and
1064 	// other things. All shape imports use the same import schemata now.
1065 	// create necessary shape (Line Shape)
1066 	AddShape("com.sun.star.drawing.PolyLineShape");
1067 
1068 	if(mxShape.is())
1069 	{
1070 		// Add, set Style and properties from base shape
1071 		SetStyle();
1072 		SetLayer();
1073 
1074 		// get sizes and offsets
1075 		awt::Point aTopLeft(mnX1, mnY1);
1076 		awt::Point aBottomRight(mnX2, mnY2);
1077 
1078 		if(mnX1 > mnX2)
1079 		{
1080 			aTopLeft.X = mnX2;
1081 			aBottomRight.X = mnX1;
1082 		}
1083 
1084 		if(mnY1 > mnY2)
1085 		{
1086 			aTopLeft.Y = mnY2;
1087 			aBottomRight.Y = mnY1;
1088 		}
1089 
1090 		// set local parameters on shape
1091 		uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
1092 		if(xPropSet.is())
1093 		{
1094 			drawing::PointSequenceSequence aPolyPoly(1L);
1095 			drawing::PointSequence* pOuterSequence = aPolyPoly.getArray();
1096 			pOuterSequence->realloc(2L);
1097 			awt::Point* pInnerSequence = pOuterSequence->getArray();
1098 			uno::Any aAny;
1099 
1100 			*pInnerSequence = awt::Point( mnX1 - aTopLeft.X, mnY1 - aTopLeft.Y);
1101 			pInnerSequence++;
1102 			*pInnerSequence = awt::Point( mnX2 - aTopLeft.X, mnY2 - aTopLeft.Y);
1103 
1104 			aAny <<= aPolyPoly;
1105 			xPropSet->setPropertyValue(
1106 				OUString(RTL_CONSTASCII_USTRINGPARAM("Geometry")), aAny);
1107 		}
1108 
1109 		// set sizes for transformation
1110 		maSize.Width = aBottomRight.X - aTopLeft.X;
1111 		maSize.Height = aBottomRight.Y - aTopLeft.Y;
1112 		maPosition.X = aTopLeft.X;
1113 		maPosition.Y = aTopLeft.Y;
1114 
1115 		// set pos, size, shear and rotate and get copy of matrix
1116 		SetTransformation();
1117 
1118 		SdXMLShapeContext::StartElement(xAttrList);
1119 	}
1120 }
1121 
1122 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1123 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1124 
1125 TYPEINIT1( SdXMLEllipseShapeContext, SdXMLShapeContext );
1126 
1127 SdXMLEllipseShapeContext::SdXMLEllipseShapeContext(
1128 	SvXMLImport& rImport,
1129 	sal_uInt16 nPrfx,
1130 	const OUString& rLocalName,
1131 	const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
1132 	uno::Reference< drawing::XShapes >& rShapes,
1133     sal_Bool bTemporaryShape)
1134 :	SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
1135 	mnCX( 0L ),
1136 	mnCY( 0L ),
1137 	mnRX( 1L ),
1138 	mnRY( 1L ),
1139 	meKind( drawing::CircleKind_FULL ),
1140 	mnStartAngle( 0 ),
1141 	mnEndAngle( 0 )
1142 {
1143 }
1144 
1145 //////////////////////////////////////////////////////////////////////////////
1146 
1147 SdXMLEllipseShapeContext::~SdXMLEllipseShapeContext()
1148 {
1149 }
1150 
1151 //////////////////////////////////////////////////////////////////////////////
1152 
1153 // this is called from the parent group for each unparsed attribute in the attribute list
1154 void SdXMLEllipseShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
1155 {
1156 	if( XML_NAMESPACE_SVG == nPrefix )
1157 	{
1158 		if( IsXMLToken( rLocalName, XML_RX ) )
1159 		{
1160 			GetImport().GetMM100UnitConverter().convertMeasure(mnRX, rValue);
1161 			return;
1162 		}
1163 		if( IsXMLToken( rLocalName, XML_RY ) )
1164 		{
1165 			GetImport().GetMM100UnitConverter().convertMeasure(mnRY, rValue);
1166 			return;
1167 		}
1168 		if( IsXMLToken( rLocalName, XML_CX ) )
1169 		{
1170 			GetImport().GetMM100UnitConverter().convertMeasure(mnCX, rValue);
1171 			return;
1172 		}
1173 		if( IsXMLToken( rLocalName, XML_CY ) )
1174 		{
1175 			GetImport().GetMM100UnitConverter().convertMeasure(mnCY, rValue);
1176 			return;
1177 		}
1178 		if( IsXMLToken( rLocalName, XML_R ) )
1179 		{
1180 			// single radius, it's a circle and both radii are the same
1181 			GetImport().GetMM100UnitConverter().convertMeasure(mnRX, rValue);
1182 			mnRY = mnRX;
1183 			return;
1184 		}
1185 	}
1186 	else if( XML_NAMESPACE_DRAW == nPrefix )
1187 	{
1188 		if( IsXMLToken( rLocalName, XML_KIND ) )
1189 		{
1190 			sal_uInt16 eKind;
1191 			if( SvXMLUnitConverter::convertEnum( eKind, rValue, aXML_CircleKind_EnumMap ) )
1192 			{
1193 				meKind = eKind;
1194 			}
1195 			return;
1196 		}
1197 		if( IsXMLToken( rLocalName, XML_START_ANGLE ) )
1198 		{
1199 			double dStartAngle;
1200 			if( SvXMLUnitConverter::convertDouble( dStartAngle, rValue ) )
1201 				mnStartAngle = (sal_Int32)(dStartAngle * 100.0);
1202 			return;
1203 		}
1204 		if( IsXMLToken( rLocalName, XML_END_ANGLE ) )
1205 		{
1206 			double dEndAngle;
1207 			if( SvXMLUnitConverter::convertDouble( dEndAngle, rValue ) )
1208 				mnEndAngle = (sal_Int32)(dEndAngle * 100.0);
1209 			return;
1210 		}
1211 	}
1212 
1213 	SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
1214 }
1215 
1216 //////////////////////////////////////////////////////////////////////////////
1217 
1218 void SdXMLEllipseShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
1219 {
1220 	// create rectangle shape
1221 	AddShape("com.sun.star.drawing.EllipseShape");
1222 	if(mxShape.is())
1223 	{
1224 		// Add, set Style and properties from base shape
1225 		SetStyle();
1226 		SetLayer();
1227 
1228 		// set pos, size, shear and rotate
1229 		SetTransformation();
1230 
1231 		if( meKind != drawing::CircleKind_FULL )
1232 		{
1233 			uno::Reference< beans::XPropertySet > xPropSet( mxShape, uno::UNO_QUERY );
1234 			if( xPropSet.is() )
1235 			{
1236 				uno::Any aAny;
1237 				aAny <<= (drawing::CircleKind)meKind;
1238 				xPropSet->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("CircleKind")), aAny );
1239 
1240 				aAny <<= mnStartAngle;
1241 				xPropSet->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("CircleStartAngle")), aAny );
1242 
1243 				aAny <<= mnEndAngle;
1244 				xPropSet->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("CircleEndAngle")), aAny );
1245 			}
1246 		}
1247 
1248 		SdXMLShapeContext::StartElement(xAttrList);
1249 	}
1250 }
1251 
1252 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1253 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1254 
1255 TYPEINIT1( SdXMLPolygonShapeContext, SdXMLShapeContext );
1256 
1257 SdXMLPolygonShapeContext::SdXMLPolygonShapeContext(
1258 	SvXMLImport& rImport,
1259 	sal_uInt16 nPrfx,
1260 	const OUString& rLocalName,
1261 	const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
1262 	uno::Reference< drawing::XShapes >& rShapes, sal_Bool bClosed, sal_Bool bTemporaryShape)
1263 :	SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
1264 	mbClosed( bClosed )
1265 {
1266 }
1267 
1268 //////////////////////////////////////////////////////////////////////////////
1269 
1270 // this is called from the parent group for each unparsed attribute in the attribute list
1271 void SdXMLPolygonShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
1272 {
1273 	if( XML_NAMESPACE_SVG == nPrefix )
1274 	{
1275 		if( IsXMLToken( rLocalName, XML_VIEWBOX ) )
1276 		{
1277 			maViewBox = rValue;
1278 			return;
1279 		}
1280 	}
1281 	else if( XML_NAMESPACE_DRAW == nPrefix )
1282 	{
1283 		if( IsXMLToken( rLocalName, XML_POINTS ) )
1284 		{
1285 			maPoints = rValue;
1286 			return;
1287 		}
1288 	}
1289 
1290 	SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
1291 }
1292 
1293 //////////////////////////////////////////////////////////////////////////////
1294 
1295 SdXMLPolygonShapeContext::~SdXMLPolygonShapeContext()
1296 {
1297 }
1298 
1299 //////////////////////////////////////////////////////////////////////////////
1300 
1301 void SdXMLPolygonShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
1302 {
1303 	// Add, set Style and properties from base shape
1304 	if(mbClosed)
1305 		AddShape("com.sun.star.drawing.PolyPolygonShape");
1306 	else
1307 		AddShape("com.sun.star.drawing.PolyLineShape");
1308 
1309 	if( mxShape.is() )
1310 	{
1311 		SetStyle();
1312 		SetLayer();
1313 
1314 		// set local parameters on shape
1315 		uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
1316 		if(xPropSet.is())
1317 		{
1318 			// set polygon
1319 			if(maPoints.getLength() && maViewBox.getLength())
1320 			{
1321 				SdXMLImExViewBox aViewBox(maViewBox, GetImport().GetMM100UnitConverter());
1322 				awt::Size aSize(aViewBox.GetWidth(), aViewBox.GetHeight());
1323 				if (maSize.Width != 0 && maSize.Height !=0)
1324 				{
1325 					aSize = maSize;
1326 				}
1327 				awt::Point aPosition(aViewBox.GetX(), aViewBox.GetY());
1328 				SdXMLImExPointsElement aPoints(maPoints, aViewBox,
1329 					aPosition, aSize, GetImport().GetMM100UnitConverter());
1330 
1331 				uno::Any aAny;
1332 				aAny <<= aPoints.GetPointSequenceSequence();
1333 				xPropSet->setPropertyValue(
1334 					OUString(RTL_CONSTASCII_USTRINGPARAM("Geometry")), aAny);
1335 			}
1336 		}
1337 
1338 		// set pos, size, shear and rotate and get copy of matrix
1339 		SetTransformation();
1340 
1341 		SdXMLShapeContext::StartElement(xAttrList);
1342 	}
1343 }
1344 
1345 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1346 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1347 
1348 TYPEINIT1( SdXMLPathShapeContext, SdXMLShapeContext );
1349 
1350 SdXMLPathShapeContext::SdXMLPathShapeContext(
1351 	SvXMLImport& rImport,
1352 	sal_uInt16 nPrfx,
1353 	const OUString& rLocalName,
1354 	const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
1355 	uno::Reference< drawing::XShapes >& rShapes,
1356     sal_Bool bTemporaryShape)
1357 :	SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
1358 	mbClosed( sal_True )
1359 {
1360 }
1361 
1362 //////////////////////////////////////////////////////////////////////////////
1363 
1364 SdXMLPathShapeContext::~SdXMLPathShapeContext()
1365 {
1366 }
1367 
1368 //////////////////////////////////////////////////////////////////////////////
1369 
1370 // this is called from the parent group for each unparsed attribute in the attribute list
1371 void SdXMLPathShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
1372 {
1373 	if( XML_NAMESPACE_SVG == nPrefix )
1374 	{
1375 		if( IsXMLToken( rLocalName, XML_VIEWBOX ) )
1376 		{
1377 			maViewBox = rValue;
1378 			return;
1379 		}
1380 		else if( IsXMLToken( rLocalName, XML_D ) )
1381 		{
1382 			maD = rValue;
1383 			return;
1384 		}
1385 	}
1386 
1387 	SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
1388 }
1389 
1390 //////////////////////////////////////////////////////////////////////////////
1391 
1392 void SdXMLPathShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
1393 {
1394 	// create polygon shape
1395 	if(maD.getLength())
1396 	{
1397 		// prepare some of the parameters
1398 		SdXMLImExViewBox aViewBox(maViewBox, GetImport().GetMM100UnitConverter());
1399 		awt::Size aSize(aViewBox.GetWidth(), aViewBox.GetHeight());
1400 		awt::Point aPosition(aViewBox.GetX(), aViewBox.GetY());
1401 		if (maSize.Width != 0 && maSize.Height !=0)
1402 		{
1403 			aSize = maSize;
1404 		}
1405 		SdXMLImExSvgDElement aPoints(maD, aViewBox,
1406 			aPosition, aSize, GetImport().GetMM100UnitConverter());
1407 
1408 		const char* pService;
1409 		// now create shape
1410 		if(aPoints.IsCurve())
1411 		{
1412 			if(aPoints.IsClosed())
1413 			{
1414 				pService = "com.sun.star.drawing.ClosedBezierShape";
1415 			}
1416 			else
1417 			{
1418 				pService = "com.sun.star.drawing.OpenBezierShape";
1419 			}
1420 		}
1421 		else
1422 		{
1423 			if(aPoints.IsClosed())
1424 			{
1425 				pService = "com.sun.star.drawing.PolyPolygonShape";
1426 			}
1427 			else
1428 			{
1429 				pService = "com.sun.star.drawing.PolyLineShape";
1430 			}
1431 		}
1432 
1433 		// Add, set Style and properties from base shape
1434 		AddShape(pService);
1435 
1436 		// #89344# test for mxShape.is() and not for mxShapes.is() to support
1437 		// shape import helper classes WITHOUT XShapes (member mxShapes). This
1438 		// is used by the writer.
1439 		if( mxShape.is() )
1440 		{
1441 			SetStyle();
1442 			SetLayer();
1443 
1444 			// set local parameters on shape
1445 			uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
1446 			if(xPropSet.is())
1447 			{
1448 				uno::Any aAny;
1449 
1450 				// set svg:d
1451 				if(maD.getLength())
1452 				{
1453 					if(aPoints.IsCurve())
1454 					{
1455 						drawing::PolyPolygonBezierCoords aSourcePolyPolygon(
1456 							aPoints.GetPointSequenceSequence(),
1457 							aPoints.GetFlagSequenceSequence());
1458 
1459 						aAny <<= aSourcePolyPolygon;
1460 						xPropSet->setPropertyValue(
1461 							OUString(RTL_CONSTASCII_USTRINGPARAM("Geometry")), aAny);
1462 					}
1463 					else
1464 					{
1465 						aAny <<= aPoints.GetPointSequenceSequence();
1466 						xPropSet->setPropertyValue(
1467 							OUString(RTL_CONSTASCII_USTRINGPARAM("Geometry")), aAny);
1468 					}
1469 				}
1470 			}
1471 
1472 			// set pos, size, shear and rotate
1473 			SetTransformation();
1474 
1475 			SdXMLShapeContext::StartElement(xAttrList);
1476 		}
1477 	}
1478 }
1479 
1480 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1481 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1482 
1483 TYPEINIT1( SdXMLTextBoxShapeContext, SdXMLShapeContext );
1484 
1485 SdXMLTextBoxShapeContext::SdXMLTextBoxShapeContext(
1486 	SvXMLImport& rImport,
1487 	sal_uInt16 nPrfx,
1488 	const OUString& rLocalName,
1489 	const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
1490 	uno::Reference< drawing::XShapes >& rShapes,
1491     sal_Bool bTemporaryShape)
1492 :	SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
1493 	mnRadius(0)
1494 {
1495 }
1496 
1497 //////////////////////////////////////////////////////////////////////////////
1498 
1499 SdXMLTextBoxShapeContext::~SdXMLTextBoxShapeContext()
1500 {
1501 }
1502 
1503 //////////////////////////////////////////////////////////////////////////////
1504 
1505 // this is called from the parent group for each unparsed attribute in the attribute list
1506 void SdXMLTextBoxShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
1507 {
1508 	if( XML_NAMESPACE_DRAW == nPrefix )
1509 	{
1510 		if( IsXMLToken( rLocalName, XML_CORNER_RADIUS ) )
1511 		{
1512 			GetImport().GetMM100UnitConverter().convertMeasure(mnRadius, rValue);
1513 			return;
1514 		}
1515 	}
1516 
1517 	SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
1518 }
1519 
1520 //////////////////////////////////////////////////////////////////////////////
1521 
1522 void SdXMLTextBoxShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>&)
1523 {
1524 	// create textbox shape
1525 	sal_Bool bIsPresShape = sal_False;
1526 	bool bClearText = false;
1527 
1528 	const char *pService = NULL;
1529 
1530 	if( isPresentationShape() )
1531 	{
1532 		// check if the current document supports presentation shapes
1533 		if( GetImport().GetShapeImport()->IsPresentationShapesSupported() )
1534 		{
1535 			if( IsXMLToken( maPresentationClass, XML_PRESENTATION_SUBTITLE ))
1536 			{
1537 				// XmlShapeTypePresSubtitleShape
1538 				pService = "com.sun.star.presentation.SubtitleShape";
1539 			}
1540 			else if( IsXMLToken( maPresentationClass, XML_PRESENTATION_OUTLINE ) )
1541 			{
1542 				// XmlShapeTypePresOutlinerShape
1543 				pService = "com.sun.star.presentation.OutlinerShape";
1544 			}
1545 			else if( IsXMLToken( maPresentationClass, XML_PRESENTATION_NOTES ) )
1546 			{
1547 				// XmlShapeTypePresNotesShape
1548 				pService = "com.sun.star.presentation.NotesShape";
1549 			}
1550 			else if( IsXMLToken( maPresentationClass, XML_HEADER ) )
1551 			{
1552 				// XmlShapeTypePresHeaderShape
1553 				pService = "com.sun.star.presentation.HeaderShape";
1554 				bClearText = true;
1555 			}
1556 			else if( IsXMLToken( maPresentationClass, XML_FOOTER ) )
1557 			{
1558 				// XmlShapeTypePresFooterShape
1559 				pService = "com.sun.star.presentation.FooterShape";
1560 				bClearText = true;
1561 			}
1562 			else if( IsXMLToken( maPresentationClass, XML_PAGE_NUMBER ) )
1563 			{
1564 				// XmlShapeTypePresSlideNumberShape
1565 				pService = "com.sun.star.presentation.SlideNumberShape";
1566 				bClearText = true;
1567 			}
1568 			else if( IsXMLToken( maPresentationClass, XML_DATE_TIME ) )
1569 			{
1570 				// XmlShapeTypePresDateTimeShape
1571 				pService = "com.sun.star.presentation.DateTimeShape";
1572 				bClearText = true;
1573 			}
1574 			else //  IsXMLToken( maPresentationClass, XML_PRESENTATION_TITLE ) )
1575 			{
1576 				// XmlShapeTypePresTitleTextShape
1577 				pService = "com.sun.star.presentation.TitleTextShape";
1578 			}
1579 			bIsPresShape = sal_True;
1580 		}
1581 	}
1582 
1583 	if( NULL == pService )
1584 	{
1585 		// normal text shape
1586 		pService = "com.sun.star.drawing.TextShape";
1587 	}
1588 
1589 	// Add, set Style and properties from base shape
1590 	AddShape(pService);
1591 
1592 	if( mxShape.is() )
1593 	{
1594 		SetStyle();
1595 		SetLayer();
1596 
1597 		if(bIsPresShape)
1598 		{
1599 			uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY);
1600 			if(xProps.is())
1601 			{
1602 				uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() );
1603 				if( xPropsInfo.is() )
1604 				{
1605 					if( !mbIsPlaceholder && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") )))
1606 						xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ), ::cppu::bool2any( sal_False ) );
1607 
1608 					if( mbIsUserTransformed && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") )))
1609 						xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") ), ::cppu::bool2any( sal_False ) );
1610 				}
1611 			}
1612 		}
1613 
1614 		if( bClearText )
1615 		{
1616 			uno::Reference< text::XText > xText( mxShape, uno::UNO_QUERY );
1617 			OUString aEmpty;
1618 			xText->setString( aEmpty );
1619 		}
1620 
1621 		// set parameters on shape
1622 //A AW->CL: Eventually You need to strip scale and translate from the transformation
1623 //A to reach the same goal again.
1624 //A		if(!bIsPresShape || mbIsUserTransformed)
1625 //A		{
1626 //A			// set pos and size on shape, this should remove binding
1627 //A			// to pres object on masterpage
1628 //A			SetSizeAndPosition();
1629 //A		}
1630 
1631 		// set pos, size, shear and rotate
1632 		SetTransformation();
1633 
1634 		if(mnRadius)
1635 		{
1636 			uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
1637 			if(xPropSet.is())
1638 			{
1639 				try
1640 				{
1641 					xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("CornerRadius")), uno::makeAny( mnRadius ) );
1642 				}
1643 				catch( uno::Exception& )
1644 				{
1645 					DBG_ERROR( "exception during setting of corner radius!");
1646 				}
1647 			}
1648 		}
1649 
1650 		SdXMLShapeContext::StartElement(mxAttrList);
1651 	}
1652 }
1653 
1654 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1655 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1656 
1657 TYPEINIT1( SdXMLControlShapeContext, SdXMLShapeContext );
1658 
1659 SdXMLControlShapeContext::SdXMLControlShapeContext(
1660 	SvXMLImport& rImport,
1661 	sal_uInt16 nPrfx,
1662 	const OUString& rLocalName,
1663 	const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
1664 	uno::Reference< drawing::XShapes >& rShapes,
1665     sal_Bool bTemporaryShape)
1666 :	SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape )
1667 {
1668 }
1669 
1670 //////////////////////////////////////////////////////////////////////////////
1671 
1672 SdXMLControlShapeContext::~SdXMLControlShapeContext()
1673 {
1674 }
1675 
1676 //////////////////////////////////////////////////////////////////////////////
1677 
1678 // this is called from the parent group for each unparsed attribute in the attribute list
1679 void SdXMLControlShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
1680 {
1681 	if( XML_NAMESPACE_DRAW == nPrefix )
1682 	{
1683 		if( IsXMLToken( rLocalName, XML_CONTROL ) )
1684 		{
1685 			maFormId = rValue;
1686 			return;
1687 		}
1688 	}
1689 
1690 	SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
1691 }
1692 
1693 void SdXMLControlShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
1694 {
1695 	// create Control shape
1696 	// add, set style and properties from base shape
1697 	AddShape("com.sun.star.drawing.ControlShape");
1698 	if( mxShape.is() )
1699 	{
1700 		DBG_ASSERT( maFormId.getLength(), "draw:control without a form:id attribute!" );
1701 		if( maFormId.getLength() )
1702 		{
1703 #ifndef SVX_LIGHT
1704 			if( GetImport().IsFormsSupported() )
1705 			{
1706 				uno::Reference< awt::XControlModel > xControlModel( GetImport().GetFormImport()->lookupControl( maFormId ), uno::UNO_QUERY );
1707 				if( xControlModel.is() )
1708 				{
1709 					uno::Reference< drawing::XControlShape > xControl( mxShape, uno::UNO_QUERY );
1710 					if( xControl.is() )
1711 						xControl->setControl(  xControlModel );
1712 
1713 				}
1714 			}
1715 #endif // #ifndef SVX_LIGHT
1716 		}
1717 
1718 		SetStyle();
1719 		SetLayer();
1720 
1721 		// set pos, size, shear and rotate
1722 		SetTransformation();
1723 
1724 		SdXMLShapeContext::StartElement(xAttrList);
1725 	}
1726 }
1727 
1728 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1729 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1730 
1731 TYPEINIT1( SdXMLConnectorShapeContext, SdXMLShapeContext );
1732 
1733 SdXMLConnectorShapeContext::SdXMLConnectorShapeContext(
1734 	SvXMLImport& rImport,
1735 	sal_uInt16 nPrfx,
1736 	const OUString& rLocalName,
1737 	const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
1738 	uno::Reference< drawing::XShapes >& rShapes,
1739     sal_Bool bTemporaryShape)
1740 :	SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
1741 	maStart(0,0),
1742 	maEnd(1,1),
1743 	mnType( (sal_uInt16)drawing::ConnectorType_STANDARD ),
1744 	mnStartGlueId(-1),
1745 	mnEndGlueId(-1),
1746 	mnDelta1(0),
1747 	mnDelta2(0),
1748 	mnDelta3(0)
1749 {
1750 }
1751 
1752 //////////////////////////////////////////////////////////////////////////////
1753 
1754 SdXMLConnectorShapeContext::~SdXMLConnectorShapeContext()
1755 {
1756 }
1757 
1758 //////////////////////////////////////////////////////////////////////////////
1759 
1760 // this is called from the parent group for each unparsed attribute in the attribute list
1761 void SdXMLConnectorShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
1762 {
1763 	switch( nPrefix )
1764 	{
1765 	case XML_NAMESPACE_DRAW:
1766 	{
1767 		if( IsXMLToken( rLocalName, XML_START_SHAPE ) )
1768 		{
1769 			maStartShapeId = rValue;
1770 			return;
1771 		}
1772 		if( IsXMLToken( rLocalName, XML_START_GLUE_POINT ) )
1773 		{
1774 			mnStartGlueId = rValue.toInt32();
1775 			return;
1776 		}
1777 		if( IsXMLToken( rLocalName, XML_END_SHAPE ) )
1778 		{
1779 			maEndShapeId = rValue;
1780 			return;
1781 		}
1782 		if( IsXMLToken( rLocalName, XML_END_GLUE_POINT ) )
1783 		{
1784 			mnEndGlueId = rValue.toInt32();
1785 			return;
1786 		}
1787 		if( IsXMLToken( rLocalName, XML_LINE_SKEW ) )
1788 		{
1789 			SvXMLTokenEnumerator aTokenEnum( rValue );
1790 			OUString aToken;
1791 			if( aTokenEnum.getNextToken( aToken ) )
1792 			{
1793 				GetImport().GetMM100UnitConverter().convertMeasure(mnDelta1, aToken);
1794 				if( aTokenEnum.getNextToken( aToken ) )
1795 				{
1796 					GetImport().GetMM100UnitConverter().convertMeasure(mnDelta2, aToken);
1797 					if( aTokenEnum.getNextToken( aToken ) )
1798 					{
1799 						GetImport().GetMM100UnitConverter().convertMeasure(mnDelta3, aToken);
1800 					}
1801 				}
1802 			}
1803 			return;
1804 		}
1805 		if( IsXMLToken( rLocalName, XML_TYPE ) )
1806 		{
1807 			SvXMLUnitConverter::convertEnum( mnType, rValue, aXML_ConnectionKind_EnumMap );
1808 			return;
1809 		}
1810 	}
1811 	case XML_NAMESPACE_SVG:
1812 	{
1813 		if( IsXMLToken( rLocalName, XML_X1 ) )
1814 		{
1815 			GetImport().GetMM100UnitConverter().convertMeasure(maStart.X, rValue);
1816 			return;
1817 		}
1818 		if( IsXMLToken( rLocalName, XML_Y1 ) )
1819 		{
1820 			GetImport().GetMM100UnitConverter().convertMeasure(maStart.Y, rValue);
1821 			return;
1822 		}
1823 		if( IsXMLToken( rLocalName, XML_X2 ) )
1824 		{
1825 			GetImport().GetMM100UnitConverter().convertMeasure(maEnd.X, rValue);
1826 			return;
1827 		}
1828 		if( IsXMLToken( rLocalName, XML_Y2 ) )
1829 		{
1830 			GetImport().GetMM100UnitConverter().convertMeasure(maEnd.Y, rValue);
1831 			return;
1832 		}
1833 		if( IsXMLToken( rLocalName, XML_D ) )
1834 		{
1835 			SdXMLImExViewBox aViewBox( 0, 0, 1, 1 );
1836 			awt::Point aPoint( 0, 0 );
1837 			awt::Size aSize( 1, 1 );
1838 
1839 			SdXMLImExSvgDElement aPoints( rValue, aViewBox,
1840 				aPoint, aSize, GetImport().GetMM100UnitConverter() );
1841 
1842 			if ( aPoints.IsCurve() )
1843 			{
1844 				drawing::PolyPolygonBezierCoords aSourcePolyPolygon(
1845 					aPoints.GetPointSequenceSequence(),
1846 					aPoints.GetFlagSequenceSequence());
1847 				maPath <<= aSourcePolyPolygon;
1848 			}
1849 			else
1850 			{
1851 				const drawing::PointSequenceSequence& rOuterSeq = aPoints.GetPointSequenceSequence();
1852 				drawing::FlagSequenceSequence aFlagSeqSeq( rOuterSeq.getLength() );
1853 				for ( int a = 0; a < rOuterSeq.getLength(); a++ )
1854 					aFlagSeqSeq[ a ] = drawing::FlagSequence( rOuterSeq[ a ].getLength() );
1855 
1856 				drawing::PolyPolygonBezierCoords aSourcePolyPolygon(
1857 					aPoints.GetPointSequenceSequence(),
1858 					aFlagSeqSeq );
1859 				maPath <<= aSourcePolyPolygon;
1860 			}
1861 		}
1862 	}
1863 	}
1864 
1865 	SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
1866 }
1867 
1868 //////////////////////////////////////////////////////////////////////////////
1869 
1870 void SdXMLConnectorShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
1871 {
1872 	// #107928#
1873 	// For security reasons, do not add empty connectors. There may have been an error in EA2
1874 	// that created empty, far set off connectors (e.g. 63 meters below top of document). This
1875 	// is not guaranteed, but it's definitely safe to not add empty connectors.
1876 	sal_Bool bDoAdd(sal_True);
1877 
1878 	if(    0 == maStartShapeId.getLength()
1879 		&& 0 == maEndShapeId.getLength()
1880 		&& maStart.X == maEnd.X
1881 		&& maStart.Y == maEnd.Y
1882 		&& 0 == mnDelta1
1883 		&& 0 == mnDelta2
1884 		&& 0 == mnDelta3
1885 		)
1886 	{
1887 		bDoAdd = sal_False;
1888 	}
1889 
1890 	if(bDoAdd)
1891 	{
1892 		// create Connector shape
1893 		// add, set style and properties from base shape
1894 		AddShape("com.sun.star.drawing.ConnectorShape");
1895 		if(mxShape.is())
1896 		{
1897 			// add connection ids
1898 			if( maStartShapeId.getLength() )
1899 				GetImport().GetShapeImport()->addShapeConnection( mxShape, sal_True, maStartShapeId, mnStartGlueId );
1900 			if( maEndShapeId.getLength() )
1901 				GetImport().GetShapeImport()->addShapeConnection( mxShape, sal_False, maEndShapeId, mnEndGlueId );
1902 
1903 			uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY );
1904 			if( xProps.is() )
1905 			{
1906 				uno::Any aAny;
1907 				aAny <<= maStart;
1908 				xProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("StartPosition")), aAny);
1909 
1910 				aAny <<= maEnd;
1911 				xProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("EndPosition")), aAny );
1912 
1913 				aAny <<= (drawing::ConnectorType)mnType;
1914 				xProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("EdgeKind")), aAny );
1915 
1916 				aAny <<= mnDelta1;
1917 				xProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("EdgeLine1Delta")), aAny );
1918 
1919 				aAny <<= mnDelta2;
1920 				xProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("EdgeLine2Delta")), aAny );
1921 
1922 				aAny <<= mnDelta3;
1923 				xProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("EdgeLine3Delta")), aAny );
1924 			}
1925 			SetStyle();
1926 			SetLayer();
1927 
1928 			if ( maPath.hasValue() )
1929             {
1930                 // --> OD #i115492#
1931                 // Ignore svg:d attribute for text documents created by OpenOffice.org
1932                 // versions before OOo 3.3, because these OOo versions are storing
1933                 // svg:d values not using the correct unit.
1934                 bool bApplySVGD( true );
1935                 if ( uno::Reference< text::XTextDocument >(GetImport().GetModel(), uno::UNO_QUERY).is() )
1936                 {
1937                     sal_Int32 nUPD( 0 );
1938                     sal_Int32 nBuild( 0 );
1939                     const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
1940                     if ( GetImport().IsTextDocInOOoFileFormat() ||
1941                          ( bBuildIdFound &&
1942                            ( ( nUPD == 641 ) || ( nUPD == 645 ) ||  // prior OOo 2.0
1943                              ( nUPD == 680 ) ||                     // OOo 2.x
1944                              ( nUPD == 300 ) ||                     // OOo 3.0 - OOo 3.0.1
1945                              ( nUPD == 310 ) ||                     // OOo 3.1 - OOo 3.1.1
1946                              ( nUPD == 320 ) ) ) )                  // OOo 3.2 - OOo 3.2.1
1947                     {
1948                         bApplySVGD = false;
1949                     }
1950                 }
1951 
1952                 if ( bApplySVGD )
1953                 {
1954                     xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("PolyPolygonBezier") ), maPath );
1955                 }
1956                 // <--
1957             }
1958 
1959 			SdXMLShapeContext::StartElement(xAttrList);
1960 		}
1961 	}
1962 }
1963 
1964 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1965 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1966 
1967 TYPEINIT1( SdXMLMeasureShapeContext, SdXMLShapeContext );
1968 
1969 SdXMLMeasureShapeContext::SdXMLMeasureShapeContext(
1970 	SvXMLImport& rImport,
1971 	sal_uInt16 nPrfx,
1972 	const OUString& rLocalName,
1973 	const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
1974 	uno::Reference< drawing::XShapes >& rShapes,
1975     sal_Bool bTemporaryShape)
1976 :	SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
1977 	maStart(0,0),
1978 	maEnd(1,1)
1979 {
1980 }
1981 
1982 //////////////////////////////////////////////////////////////////////////////
1983 
1984 SdXMLMeasureShapeContext::~SdXMLMeasureShapeContext()
1985 {
1986 }
1987 
1988 // this is called from the parent group for each unparsed attribute in the attribute list
1989 void SdXMLMeasureShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
1990 {
1991 	switch( nPrefix )
1992 	{
1993 	case XML_NAMESPACE_SVG:
1994 	{
1995 		if( IsXMLToken( rLocalName, XML_X1 ) )
1996 		{
1997 			GetImport().GetMM100UnitConverter().convertMeasure(maStart.X, rValue);
1998 			return;
1999 		}
2000 		if( IsXMLToken( rLocalName, XML_Y1 ) )
2001 		{
2002 			GetImport().GetMM100UnitConverter().convertMeasure(maStart.Y, rValue);
2003 			return;
2004 		}
2005 		if( IsXMLToken( rLocalName, XML_X2 ) )
2006 		{
2007 			GetImport().GetMM100UnitConverter().convertMeasure(maEnd.X, rValue);
2008 			return;
2009 		}
2010 		if( IsXMLToken( rLocalName, XML_Y2 ) )
2011 		{
2012 			GetImport().GetMM100UnitConverter().convertMeasure(maEnd.Y, rValue);
2013 			return;
2014 		}
2015 	}
2016 	}
2017 
2018 	SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
2019 }
2020 
2021 //////////////////////////////////////////////////////////////////////////////
2022 
2023 void SdXMLMeasureShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
2024 {
2025 	// create Measure shape
2026 	// add, set style and properties from base shape
2027 	AddShape("com.sun.star.drawing.MeasureShape");
2028 	if(mxShape.is())
2029 	{
2030 		SetStyle();
2031 		SetLayer();
2032 
2033 		uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY );
2034 		if( xProps.is() )
2035 		{
2036 			uno::Any aAny;
2037 			aAny <<= maStart;
2038 			xProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("StartPosition")), aAny);
2039 
2040 			aAny <<= maEnd;
2041 			xProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("EndPosition")), aAny );
2042 		}
2043 
2044 		// delete pre created fields
2045 		uno::Reference< text::XText > xText( mxShape, uno::UNO_QUERY );
2046 		if( xText.is() )
2047 		{
2048 			const OUString aEmpty( RTL_CONSTASCII_USTRINGPARAM( " " ) );
2049 			xText->setString( aEmpty );
2050 		}
2051 
2052 		SdXMLShapeContext::StartElement(xAttrList);
2053 	}
2054 }
2055 
2056 void SdXMLMeasureShapeContext::EndElement()
2057 {
2058 	do
2059 	{
2060 		// delete pre created fields
2061 		uno::Reference< text::XText > xText( mxShape, uno::UNO_QUERY );
2062 		if( !xText.is() )
2063 			break;
2064 
2065 		uno::Reference< text::XTextCursor > xCursor( xText->createTextCursor() );
2066 		if( !xCursor.is() )
2067 			break;
2068 
2069 		const OUString aEmpty;
2070 		xCursor->collapseToStart();
2071 		xCursor->goRight( 1, sal_True );
2072 		xCursor->setString( aEmpty );
2073 	}
2074 	while(0);
2075 
2076 	SdXMLShapeContext::EndElement();
2077 }
2078 
2079 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2080 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2081 
2082 TYPEINIT1( SdXMLPageShapeContext, SdXMLShapeContext );
2083 
2084 SdXMLPageShapeContext::SdXMLPageShapeContext(
2085 	SvXMLImport& rImport,
2086 	sal_uInt16 nPrfx,
2087 	const OUString& rLocalName,
2088 	const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
2089 	uno::Reference< drawing::XShapes >& rShapes,
2090     sal_Bool bTemporaryShape)
2091 :	SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), mnPageNumber(0)
2092 {
2093 	mbClearDefaultAttributes = false;
2094 }
2095 
2096 //////////////////////////////////////////////////////////////////////////////
2097 
2098 SdXMLPageShapeContext::~SdXMLPageShapeContext()
2099 {
2100 }
2101 
2102 //////////////////////////////////////////////////////////////////////////////
2103 
2104 // this is called from the parent group for each unparsed attribute in the attribute list
2105 void SdXMLPageShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
2106 {
2107 	if( XML_NAMESPACE_DRAW == nPrefix )
2108 	{
2109 		if( IsXMLToken( rLocalName, XML_PAGE_NUMBER ) )
2110 		{
2111 			mnPageNumber = rValue.toInt32();
2112 			return;
2113 		}
2114 	}
2115 
2116 	SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
2117 }
2118 
2119 //////////////////////////////////////////////////////////////////////////////
2120 
2121 void SdXMLPageShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
2122 {
2123 	// create Page shape
2124 	// add, set style and properties from base shape
2125 
2126 	// #86163# take into account which type of PageShape needs to
2127 	// be constructed. It's an pres shape if presentation:XML_CLASS == XML_PRESENTATION_PAGE.
2128 	sal_Bool bIsPresentation = maPresentationClass.getLength() &&
2129 		   GetImport().GetShapeImport()->IsPresentationShapesSupported();
2130 
2131 	uno::Reference< lang::XServiceInfo > xInfo( mxShapes, uno::UNO_QUERY );
2132 	const sal_Bool bIsOnHandoutPage = xInfo.is() && xInfo->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.HandoutMasterPage")) );
2133 
2134 	if( bIsOnHandoutPage )
2135 	{
2136 		AddShape("com.sun.star.presentation.HandoutShape");
2137 	}
2138 	else
2139 	{
2140 		if(bIsPresentation && !IsXMLToken( maPresentationClass, XML_PRESENTATION_PAGE ) )
2141 		{
2142 			bIsPresentation = sal_False;
2143 		}
2144 
2145 		if(bIsPresentation)
2146 		{
2147 			AddShape("com.sun.star.presentation.PageShape");
2148 		}
2149 		else
2150 		{
2151 			AddShape("com.sun.star.drawing.PageShape");
2152 		}
2153 	}
2154 
2155 	if(mxShape.is())
2156 	{
2157 		SetStyle();
2158 		SetLayer();
2159 
2160 		// set pos, size, shear and rotate
2161 		SetTransformation();
2162 
2163 		uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
2164 		if(xPropSet.is())
2165 		{
2166 			uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xPropSet->getPropertySetInfo() );
2167 			const OUString aPageNumberStr(RTL_CONSTASCII_USTRINGPARAM("PageNumber"));
2168 			if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName(aPageNumberStr))
2169 				xPropSet->setPropertyValue(aPageNumberStr, uno::makeAny( mnPageNumber ));
2170 		}
2171 
2172 		SdXMLShapeContext::StartElement(xAttrList);
2173 	}
2174 }
2175 
2176 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2177 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2178 
2179 TYPEINIT1( SdXMLCaptionShapeContext, SdXMLShapeContext );
2180 
2181 SdXMLCaptionShapeContext::SdXMLCaptionShapeContext(
2182 	SvXMLImport& rImport,
2183 	sal_uInt16 nPrfx,
2184 	const OUString& rLocalName,
2185 	const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
2186 	uno::Reference< drawing::XShapes >& rShapes,
2187     sal_Bool bTemporaryShape)
2188 :	SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
2189 	// #86616# for correct edge rounding import mnRadius needs to be initialized
2190 	mnRadius( 0L )
2191 {
2192 }
2193 
2194 //////////////////////////////////////////////////////////////////////////////
2195 
2196 SdXMLCaptionShapeContext::~SdXMLCaptionShapeContext()
2197 {
2198 }
2199 
2200 //////////////////////////////////////////////////////////////////////////////
2201 
2202 void SdXMLCaptionShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
2203 {
2204 	// create Caption shape
2205 	// add, set style and properties from base shape
2206 	AddShape("com.sun.star.drawing.CaptionShape");
2207 	if( mxShape.is() )
2208 	{
2209 		SetStyle();
2210 		SetLayer();
2211 
2212 		uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY );
2213 
2214 		// SJ: If AutoGrowWidthItem is set, SetTransformation will lead to the wrong SnapRect
2215 		// because NbcAdjustTextFrameWidthAndHeight() is called (text is set later and center alignment
2216 		// is the default setting, so the top left reference point that is used by the caption point is
2217 		// no longer correct) There are two ways to solve this problem, temporarily disabling the
2218 		// autogrowwith as we are doing here or to apply the CaptionPoint after setting text
2219 		sal_Bool bIsAutoGrowWidth = sal_False;
2220 		if ( xProps.is() )
2221 		{
2222 			uno::Any aAny( xProps->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("TextAutoGrowWidth") ) ) );
2223 			aAny >>= bIsAutoGrowWidth;
2224 
2225 			if ( bIsAutoGrowWidth )
2226 				xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("TextAutoGrowWidth")), uno::makeAny( sal_False ) );
2227 		}
2228 
2229 		// set pos, size, shear and rotate
2230 		SetTransformation();
2231 		if( xProps.is() )
2232 			xProps->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("CaptionPoint")), uno::makeAny( maCaptionPoint ) );
2233 
2234 		if ( bIsAutoGrowWidth )
2235 			xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("TextAutoGrowWidth")), uno::makeAny( sal_True ) );
2236 
2237 		if(mnRadius)
2238 		{
2239 			uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
2240 			if(xPropSet.is())
2241 			{
2242 				try
2243 				{
2244 					xPropSet->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("CornerRadius")), uno::makeAny( mnRadius ) );
2245 				}
2246 				catch( uno::Exception& )
2247 				{
2248 					DBG_ERROR( "exception during setting of corner radius!");
2249 				}
2250 			}
2251 		}
2252 
2253 		SdXMLShapeContext::StartElement(xAttrList);
2254 	}
2255 }
2256 
2257 // this is called from the parent group for each unparsed attribute in the attribute list
2258 void SdXMLCaptionShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
2259 {
2260 	if( XML_NAMESPACE_DRAW == nPrefix )
2261 	{
2262 		if( IsXMLToken( rLocalName, XML_CAPTION_POINT_X ) )
2263 		{
2264 			GetImport().GetMM100UnitConverter().convertMeasure(maCaptionPoint.X, rValue);
2265 			return;
2266 		}
2267 		if( IsXMLToken( rLocalName, XML_CAPTION_POINT_Y ) )
2268 		{
2269 			GetImport().GetMM100UnitConverter().convertMeasure(maCaptionPoint.Y, rValue);
2270 			return;
2271 		}
2272 		if( IsXMLToken( rLocalName, XML_CORNER_RADIUS ) )
2273 		{
2274 			GetImport().GetMM100UnitConverter().convertMeasure(mnRadius, rValue);
2275 			return;
2276 		}
2277 	}
2278 	SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
2279 }
2280 
2281 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2282 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2283 
2284 TYPEINIT1( SdXMLGraphicObjectShapeContext, SdXMLShapeContext );
2285 
2286 SdXMLGraphicObjectShapeContext::SdXMLGraphicObjectShapeContext(
2287 	SvXMLImport& rImport,
2288 	sal_uInt16 nPrfx,
2289 	const OUString& rLocalName,
2290 	const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
2291 	uno::Reference< drawing::XShapes >& rShapes,
2292     sal_Bool bTemporaryShape)
2293 :	SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
2294 	maURL()
2295 {
2296 }
2297 
2298 //////////////////////////////////////////////////////////////////////////////
2299 
2300 // this is called from the parent group for each unparsed attribute in the attribute list
2301 void SdXMLGraphicObjectShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
2302 {
2303 	if( XML_NAMESPACE_XLINK == nPrefix )
2304 	{
2305 		if( IsXMLToken( rLocalName, XML_HREF ) )
2306 		{
2307 			maURL = rValue;
2308 			return;
2309 		}
2310 	}
2311 
2312 	SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
2313 }
2314 
2315 //////////////////////////////////////////////////////////////////////////////
2316 
2317 void SdXMLGraphicObjectShapeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& )
2318 {
2319 	// create graphic object shape
2320 	const char *pService;
2321 
2322 	if( IsXMLToken( maPresentationClass, XML_GRAPHIC ) && GetImport().GetShapeImport()->IsPresentationShapesSupported() )
2323 	{
2324 		pService = "com.sun.star.presentation.GraphicObjectShape";
2325 	}
2326 	else
2327 	{
2328 		pService = "com.sun.star.drawing.GraphicObjectShape";
2329 	}
2330 
2331 	AddShape( pService );
2332 
2333 	if(mxShape.is())
2334 	{
2335 		SetStyle();
2336 		SetLayer();
2337 
2338 		uno::Reference< beans::XPropertySet > xPropset(mxShape, uno::UNO_QUERY);
2339 		if(xPropset.is())
2340 		{
2341 			// since OOo 1.x had no line or fill style for graphics, but may create
2342 			// documents with them, we have to override them here
2343 			sal_Int32 nUPD, nBuildId;
2344 			if( GetImport().getBuildIds( nUPD, nBuildId ) && (nUPD == 645) ) try
2345 			{
2346 				xPropset->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("FillStyle")), Any( FillStyle_NONE ) );
2347 				xPropset->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("LineStyle")), Any( LineStyle_NONE ) );
2348 			}
2349 			catch( Exception& )
2350 			{
2351 			}
2352 
2353 			uno::Reference< beans::XPropertySetInfo > xPropsInfo( xPropset->getPropertySetInfo() );
2354 			if( xPropsInfo.is() && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") )))
2355 				xPropset->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ), ::cppu::bool2any( mbIsPlaceholder ) );
2356 
2357 			if( !mbIsPlaceholder )
2358 			{
2359 				if( maURL.getLength() )
2360 				{
2361 					uno::Any aAny;
2362 					aAny <<= GetImport().ResolveGraphicObjectURL( maURL, GetImport().isGraphicLoadOnDemandSupported() );
2363 					try
2364 					{
2365 						xPropset->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicURL") ), aAny );
2366 						xPropset->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicStreamURL") ), aAny );
2367 					}
2368 					catch (lang::IllegalArgumentException const &)
2369 					{
2370 					}
2371 				}
2372 			}
2373 		}
2374 
2375 		if(mbIsUserTransformed)
2376 		{
2377 			uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY);
2378 			if(xProps.is())
2379 			{
2380 				uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() );
2381 				if( xPropsInfo.is() )
2382 				{
2383 					if( xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") )))
2384 						xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") ), ::cppu::bool2any( sal_False ) );
2385 				}
2386 			}
2387 		}
2388 
2389 		// set pos, size, shear and rotate
2390 		SetTransformation();
2391 
2392 		SdXMLShapeContext::StartElement(mxAttrList);
2393 	}
2394 }
2395 
2396 void SdXMLGraphicObjectShapeContext::EndElement()
2397 {
2398 	if( mxBase64Stream.is() )
2399 	{
2400 		OUString sURL( GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream ) );
2401 		if( sURL.getLength() )
2402 		{
2403 			try
2404 			{
2405 				uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY);
2406 				if(xProps.is())
2407 				{
2408 					const uno::Any aAny( uno::makeAny( sURL ) );
2409 					xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicURL") ), aAny );
2410 					xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicStreamURL") ), aAny );
2411 				}
2412 			}
2413 			catch (lang::IllegalArgumentException const &)
2414 			{
2415 			}
2416 		}
2417 	}
2418 
2419 	SdXMLShapeContext::EndElement();
2420 }
2421 
2422 
2423 //////////////////////////////////////////////////////////////////////////////
2424 
2425 SvXMLImportContext* SdXMLGraphicObjectShapeContext::CreateChildContext(
2426 	sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
2427 	const uno::Reference<xml::sax::XAttributeList>& xAttrList )
2428 {
2429 	SvXMLImportContext* pContext = NULL;
2430 
2431 	if( (XML_NAMESPACE_OFFICE == nPrefix) &&
2432 			 xmloff::token::IsXMLToken( rLocalName, xmloff::token::XML_BINARY_DATA ) )
2433 	{
2434 		if( !maURL.getLength() && !mxBase64Stream.is() )
2435 		{
2436 			mxBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
2437 			if( mxBase64Stream.is() )
2438 				pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
2439 													rLocalName, xAttrList,
2440 													mxBase64Stream );
2441 		}
2442 	}
2443 
2444 	// delegate to parent class if no context could be created
2445 	if ( NULL == pContext )
2446 		pContext = SdXMLShapeContext::CreateChildContext(nPrefix, rLocalName,
2447 														 xAttrList);
2448 
2449 	return pContext;
2450 }
2451 
2452 //////////////////////////////////////////////////////////////////////////////
2453 
2454 SdXMLGraphicObjectShapeContext::~SdXMLGraphicObjectShapeContext()
2455 {
2456 
2457 }
2458 
2459 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2460 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2461 
2462 TYPEINIT1( SdXMLChartShapeContext, SdXMLShapeContext );
2463 
2464 SdXMLChartShapeContext::SdXMLChartShapeContext(
2465 	SvXMLImport& rImport,
2466 	sal_uInt16 nPrfx,
2467 	const OUString& rLocalName,
2468 	const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
2469 	uno::Reference< drawing::XShapes >& rShapes,
2470     sal_Bool bTemporaryShape)
2471 :	SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
2472 	mpChartContext( NULL )
2473 {
2474 }
2475 
2476 //////////////////////////////////////////////////////////////////////////////
2477 
2478 SdXMLChartShapeContext::~SdXMLChartShapeContext()
2479 {
2480 	if( mpChartContext )
2481 		delete mpChartContext;
2482 }
2483 
2484 //////////////////////////////////////////////////////////////////////////////
2485 
2486 void SdXMLChartShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
2487 {
2488 	const sal_Bool bIsPresentation = isPresentationShape();
2489 
2490 	AddShape( bIsPresentation ? "com.sun.star.presentation.ChartShape" : "com.sun.star.drawing.OLE2Shape" );
2491 
2492 	if(mxShape.is())
2493 	{
2494 		SetStyle();
2495 		SetLayer();
2496 
2497 		if( !mbIsPlaceholder )
2498 		{
2499 			uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY);
2500 			if(xProps.is())
2501 			{
2502 				uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() );
2503 				if( xPropsInfo.is() && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") )))
2504 					xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ), ::cppu::bool2any( sal_False ) );
2505 
2506 				uno::Any aAny;
2507 
2508 				const OUString aCLSID( RTL_CONSTASCII_USTRINGPARAM("12DCAE26-281F-416F-a234-c3086127382e"));
2509 
2510 				aAny <<= aCLSID;
2511 				xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("CLSID") ), aAny );
2512 
2513 #ifndef SVX_LIGHT
2514 				aAny = xProps->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("Model") ) );
2515 				uno::Reference< frame::XModel > xChartModel;
2516 				if( aAny >>= xChartModel )
2517 				{
2518 					mpChartContext = GetImport().GetChartImport()->CreateChartContext( GetImport(), XML_NAMESPACE_SVG, GetXMLToken(XML_CHART), xChartModel, xAttrList );
2519 				}
2520 #endif
2521 			}
2522 		}
2523 
2524 		if(mbIsUserTransformed)
2525 		{
2526 			uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY);
2527 			if(xProps.is())
2528 			{
2529 				uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() );
2530 				if( xPropsInfo.is() )
2531 				{
2532 					if( xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") )))
2533 						xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") ), ::cppu::bool2any( sal_False ) );
2534 				}
2535 			}
2536 		}
2537 
2538 
2539 		// set pos, size, shear and rotate
2540 		SetTransformation();
2541 
2542 		SdXMLShapeContext::StartElement(xAttrList);
2543 
2544 		if( mpChartContext )
2545 			mpChartContext->StartElement( xAttrList );
2546 	}
2547 }
2548 
2549 void SdXMLChartShapeContext::EndElement()
2550 {
2551 	if( mpChartContext )
2552 		mpChartContext->EndElement();
2553 
2554 	SdXMLShapeContext::EndElement();
2555 }
2556 
2557 void SdXMLChartShapeContext::Characters( const ::rtl::OUString& rChars )
2558 {
2559 	if( mpChartContext )
2560 		mpChartContext->Characters( rChars );
2561 }
2562 
2563 SvXMLImportContext * SdXMLChartShapeContext::CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
2564 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
2565 {
2566 	if( mpChartContext )
2567 		return mpChartContext->CreateChildContext( nPrefix, rLocalName, xAttrList );
2568 
2569 	return NULL;
2570 }
2571 
2572 //////////////////////////////////////////////////////////////////////////////
2573 
2574 TYPEINIT1( SdXMLObjectShapeContext, SdXMLShapeContext );
2575 
2576 SdXMLObjectShapeContext::SdXMLObjectShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
2577 		const rtl::OUString& rLocalName,
2578 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
2579 		com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes,
2580         sal_Bool bTemporaryShape)
2581 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape )
2582 {
2583 }
2584 
2585 SdXMLObjectShapeContext::~SdXMLObjectShapeContext()
2586 {
2587 }
2588 
2589 void SdXMLObjectShapeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& )
2590 {
2591 	// #96717# in theorie, if we don't have a url we shouldn't even
2592 	// export this ole shape. But practical its to risky right now
2593 	// to change this so we better dispose this on load
2594 	//if( !mbIsPlaceholder && ImpIsEmptyURL(maHref) )
2595 	//	return;
2596 
2597 	// #100592# this BugFix prevents that a shape is created. CL
2598 	// is thinking about an alternative.
2599     // #i13140# Check for more than empty string in maHref, there are
2600     // other possibilities that maHref results in empty container
2601     // storage names
2602 	if( !(GetImport().getImportFlags() & IMPORT_EMBEDDED) && !mbIsPlaceholder && ImpIsEmptyURL(maHref) )
2603 		return;
2604 
2605 	const char* pService = "com.sun.star.drawing.OLE2Shape";
2606 
2607 	sal_Bool bIsPresShape = maPresentationClass.getLength() && GetImport().GetShapeImport()->IsPresentationShapesSupported();
2608 
2609 	if( bIsPresShape )
2610 	{
2611 		if( IsXMLToken( maPresentationClass, XML_PRESENTATION_CHART ) )
2612 		{
2613 			pService = "com.sun.star.presentation.ChartShape";
2614 		}
2615 		else if( IsXMLToken( maPresentationClass, XML_PRESENTATION_TABLE ) )
2616 		{
2617 			pService = "com.sun.star.presentation.CalcShape";
2618 		}
2619 		else if( IsXMLToken( maPresentationClass, XML_PRESENTATION_OBJECT ) )
2620 		{
2621 			pService = "com.sun.star.presentation.OLE2Shape";
2622 		}
2623 	}
2624 
2625 	AddShape( pService );
2626 
2627 	if( mxShape.is() )
2628 	{
2629 		SetLayer();
2630 
2631 		if(bIsPresShape)
2632 		{
2633 			uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY);
2634 			if(xProps.is())
2635 			{
2636 				uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() );
2637 				if( xPropsInfo.is() )
2638 				{
2639 					if( !mbIsPlaceholder && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") )))
2640 						xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ), ::cppu::bool2any( sal_False ) );
2641 
2642 					if( mbIsUserTransformed && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") )))
2643 						xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") ), ::cppu::bool2any( sal_False ) );
2644 				}
2645 			}
2646 		}
2647 
2648 		if( !mbIsPlaceholder && maHref.getLength() )
2649 		{
2650         	uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY );
2651 
2652             if( xProps.is() )
2653         	{
2654 				OUString aPersistName = GetImport().ResolveEmbeddedObjectURL( maHref, maCLSID );
2655 
2656 				if ( GetImport().IsPackageURL( maHref ) )
2657 				{
2658 					const OUString  sURL(RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.EmbeddedObject:" ));
2659 
2660 					if ( aPersistName.compareTo( sURL, sURL.getLength() ) == 0 )
2661 						aPersistName = aPersistName.copy( sURL.getLength() );
2662 
2663         			xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "PersistName" ) ),
2664 											  uno::makeAny( aPersistName ) );
2665 				}
2666 				else
2667 				{
2668 					// this is OOo link object
2669 					xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "LinkURL" ) ),
2670 											  uno::makeAny( aPersistName ) );
2671 				}
2672 			}
2673 		}
2674 
2675 		// set pos, size, shear and rotate
2676 		SetTransformation();
2677 
2678 		SetStyle();
2679 
2680 		GetImport().GetShapeImport()->finishShape( mxShape, mxAttrList, mxShapes );
2681 	}
2682 }
2683 
2684 void SdXMLObjectShapeContext::EndElement()
2685 {
2686 	// #100592#
2687 	if( mxBase64Stream.is() )
2688 	{
2689 		OUString aPersistName( GetImport().ResolveEmbeddedObjectURLFromBase64() );
2690 		const OUString  sURL(RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.EmbeddedObject:" ));
2691 
2692         aPersistName = aPersistName.copy( sURL.getLength() );
2693 
2694 		uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY);
2695 		if( xProps.is() )
2696 			xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "PersistName" ) ), uno::makeAny( aPersistName ) );
2697 	}
2698 
2699 	SdXMLShapeContext::EndElement();
2700 }
2701 
2702 // this is called from the parent group for each unparsed attribute in the attribute list
2703 void SdXMLObjectShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
2704 {
2705 	switch( nPrefix )
2706 	{
2707 	case XML_NAMESPACE_DRAW:
2708 		if( IsXMLToken( rLocalName, XML_CLASS_ID ) )
2709 		{
2710 			maCLSID = rValue;
2711 			return;
2712 		}
2713 		break;
2714 	case XML_NAMESPACE_XLINK:
2715 		if( IsXMLToken( rLocalName, XML_HREF ) )
2716 		{
2717 			maHref = rValue;
2718 			return;
2719 		}
2720 		break;
2721 	}
2722 
2723 	SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
2724 }
2725 
2726 SvXMLImportContext* SdXMLObjectShapeContext::CreateChildContext(
2727 	sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
2728 	const uno::Reference<xml::sax::XAttributeList>& xAttrList )
2729 {
2730 	// #100592#
2731 	SvXMLImportContext* pContext = NULL;
2732 
2733 	if((XML_NAMESPACE_OFFICE == nPrefix) && IsXMLToken(rLocalName, XML_BINARY_DATA))
2734 	{
2735 		mxBase64Stream = GetImport().GetStreamForEmbeddedObjectURLFromBase64();
2736 		if( mxBase64Stream.is() )
2737 			pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
2738 												rLocalName, xAttrList,
2739 												mxBase64Stream );
2740 	}
2741 	else if( ((XML_NAMESPACE_OFFICE == nPrefix) && IsXMLToken(rLocalName, XML_DOCUMENT)) ||
2742 				((XML_NAMESPACE_MATH == nPrefix) && IsXMLToken(rLocalName, XML_MATH)) )
2743 	{
2744 		XMLEmbeddedObjectImportContext *pEContext =
2745 			new XMLEmbeddedObjectImportContext( GetImport(), nPrefix,
2746 												rLocalName, xAttrList );
2747 		maCLSID = pEContext->GetFilterCLSID();
2748 		if( maCLSID.getLength() != 0 )
2749 		{
2750 			uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
2751 			if( xPropSet.is() )
2752 			{
2753 				xPropSet->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("CLSID") ), uno::makeAny( maCLSID ) );
2754 
2755 				uno::Reference< lang::XComponent > xComp;
2756 				xPropSet->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("Model") ) ) >>= xComp;
2757 				DBG_ASSERT( xComp.is(), "no xModel for own OLE format" );
2758 				pEContext->SetComponent( xComp );
2759 			}
2760 		}
2761 		pContext = pEContext;
2762 	}
2763 
2764 	// delegate to parent class if no context could be created
2765 	if(!pContext)
2766 		pContext = SdXMLShapeContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
2767 
2768 	return pContext;
2769 }
2770 
2771 //////////////////////////////////////////////////////////////////////////////
2772 
2773 TYPEINIT1( SdXMLAppletShapeContext, SdXMLShapeContext );
2774 
2775 SdXMLAppletShapeContext::SdXMLAppletShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
2776 		const rtl::OUString& rLocalName,
2777 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
2778 		com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes,
2779         sal_Bool bTemporaryShape)
2780 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
2781   mbIsScript( sal_False )
2782 {
2783 }
2784 
2785 SdXMLAppletShapeContext::~SdXMLAppletShapeContext()
2786 {
2787 }
2788 
2789 void SdXMLAppletShapeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& )
2790 {
2791 	const char* pService = "com.sun.star.drawing.AppletShape";
2792 	AddShape( pService );
2793 
2794 	if( mxShape.is() )
2795 	{
2796 		SetLayer();
2797 
2798 		// set pos, size, shear and rotate
2799 		SetTransformation();
2800 		GetImport().GetShapeImport()->finishShape( mxShape, mxAttrList, mxShapes );
2801 	}
2802 }
2803 
2804 // this is called from the parent group for each unparsed attribute in the attribute list
2805 void SdXMLAppletShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
2806 {
2807 	switch( nPrefix )
2808 	{
2809 	case XML_NAMESPACE_DRAW:
2810 		if( IsXMLToken( rLocalName, XML_APPLET_NAME ) )
2811 		{
2812 			maAppletName = rValue;
2813 			return;
2814 		}
2815 		if( IsXMLToken( rLocalName, XML_CODE ) )
2816 		{
2817 			maAppletCode = rValue;
2818 			return;
2819 		}
2820 		if( IsXMLToken( rLocalName, XML_MAY_SCRIPT ) )
2821 		{
2822 			mbIsScript = IsXMLToken( rValue, XML_TRUE );
2823 			return;
2824 		}
2825 		break;
2826 	case XML_NAMESPACE_XLINK:
2827 		if( IsXMLToken( rLocalName, XML_HREF ) )
2828 		{
2829 			maHref = GetImport().GetAbsoluteReference(rValue);
2830 			return;
2831 		}
2832 		break;
2833 	}
2834 
2835 	SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
2836 }
2837 
2838 void SdXMLAppletShapeContext::EndElement()
2839 {
2840 	uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY );
2841 	if( xProps.is() )
2842 	{
2843 		uno::Any aAny;
2844 
2845 		if ( maSize.Width && maSize.Height )
2846 		{
2847 			// the visual area for applet must be set on loading
2848 			awt::Rectangle aRect( 0, 0, maSize.Width, maSize.Height );
2849 			aAny <<= aRect;
2850 			xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "VisibleArea" ) ), aAny );
2851 		}
2852 
2853 		if( maParams.getLength() )
2854 		{
2855 			aAny <<= maParams;
2856 			xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "AppletCommands" ) ), aAny );
2857 		}
2858 
2859 		if( maHref.getLength() )
2860 		{
2861 			aAny <<= maHref;
2862 			xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "AppletCodeBase" ) ), aAny );
2863 		}
2864 
2865 		if( maAppletName.getLength() )
2866 		{
2867 			aAny <<= maAppletName;
2868 			xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "AppletName" ) ), aAny );
2869 		}
2870 
2871 		if( mbIsScript )
2872 		{
2873 			aAny <<= mbIsScript;
2874 			xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "AppletIsScript" ) ), aAny );
2875 
2876 		}
2877 
2878 		if( maAppletCode.getLength() )
2879 		{
2880 			aAny <<= maAppletCode;
2881 			xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "AppletCode" ) ), aAny );
2882 		}
2883 
2884         aAny <<= ::rtl::OUString( GetImport().GetDocumentBase() );
2885         xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "AppletDocBase" ) ), aAny );
2886 
2887 		SetThumbnail();
2888 	}
2889 
2890 	SdXMLShapeContext::EndElement();
2891 }
2892 
2893 SvXMLImportContext * SdXMLAppletShapeContext::CreateChildContext( sal_uInt16 p_nPrefix, const ::rtl::OUString& rLocalName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
2894 {
2895 	if( p_nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( rLocalName, XML_PARAM ) )
2896 	{
2897 		OUString aParamName, aParamValue;
2898 		const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
2899 		// now parse the attribute list and look for draw:name and draw:value
2900 		for(sal_Int16 a(0); a < nAttrCount; a++)
2901 		{
2902 			const OUString& rAttrName = xAttrList->getNameByIndex(a);
2903 			OUString aLocalName;
2904 			sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName);
2905 			const OUString aValue( xAttrList->getValueByIndex(a) );
2906 
2907 			if( nPrefix == XML_NAMESPACE_DRAW )
2908 			{
2909 				if( IsXMLToken( aLocalName, XML_NAME ) )
2910 				{
2911 					aParamName = aValue;
2912 				}
2913 				else if( IsXMLToken( aLocalName, XML_VALUE ) )
2914 				{
2915 					aParamValue = aValue;
2916 				}
2917 			}
2918 		}
2919 
2920 		if( aParamName.getLength() )
2921 		{
2922 			sal_Int32 nIndex = maParams.getLength();
2923 			maParams.realloc( nIndex + 1 );
2924 			maParams[nIndex].Name = aParamName;
2925 			maParams[nIndex].Handle = -1;
2926 			maParams[nIndex].Value <<= aParamValue;
2927 			maParams[nIndex].State = beans::PropertyState_DIRECT_VALUE;
2928 		}
2929 
2930 		return new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
2931 	}
2932 
2933 	return SdXMLShapeContext::CreateChildContext( p_nPrefix, rLocalName, xAttrList );
2934 }
2935 
2936 //////////////////////////////////////////////////////////////////////////////
2937 
2938 TYPEINIT1( SdXMLPluginShapeContext, SdXMLShapeContext );
2939 
2940 SdXMLPluginShapeContext::SdXMLPluginShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
2941 		const rtl::OUString& rLocalName,
2942 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
2943 		com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes,
2944         sal_Bool bTemporaryShape) :
2945 SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
2946 mbMedia( false )
2947 {
2948 }
2949 
2950 SdXMLPluginShapeContext::~SdXMLPluginShapeContext()
2951 {
2952 }
2953 
2954 void SdXMLPluginShapeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList)
2955 {
2956 	// watch for MimeType attribute to see if we have a media object
2957 	for( sal_Int16 n = 0, nAttrCount = ( xAttrList.is() ? xAttrList->getLength() : 0 ); n < nAttrCount; ++n )
2958 	{
2959 		OUString 	aLocalName;
2960 		sal_uInt16 	nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( n ), &aLocalName );
2961 
2962 		if( nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( aLocalName, XML_MIME_TYPE ) )
2963 		{
2964 			if( 0 == xAttrList->getValueByIndex( n ).compareToAscii( "application/vnd.sun.star.media" ) )
2965 				mbMedia = true;
2966 
2967 			// leave this loop
2968 			n = nAttrCount - 1;
2969 		}
2970 	}
2971 
2972 	const char* pService;
2973 
2974 	sal_Bool bIsPresShape = sal_False;
2975 
2976 	if( mbMedia )
2977 	{
2978 		pService = "com.sun.star.drawing.MediaShape";
2979 
2980 		bIsPresShape = maPresentationClass.getLength() && GetImport().GetShapeImport()->IsPresentationShapesSupported();
2981 		if( bIsPresShape )
2982 		{
2983 			if( IsXMLToken( maPresentationClass, XML_PRESENTATION_OBJECT ) )
2984 			{
2985 				pService = "com.sun.star.presentation.MediaShape";
2986 			}
2987 		}
2988 	}
2989 	else
2990 		pService = "com.sun.star.drawing.PluginShape";
2991 
2992 	AddShape( pService );
2993 
2994 	if( mxShape.is() )
2995 	{
2996 		SetLayer();
2997 
2998 		if(bIsPresShape)
2999 		{
3000 			uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY );
3001 			if(xProps.is())
3002 			{
3003 				uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() );
3004 				if( xPropsInfo.is() )
3005 				{
3006 					if( !mbIsPlaceholder && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") )))
3007 						xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ), ::cppu::bool2any( sal_False ) );
3008 
3009 					if( mbIsUserTransformed && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") )))
3010 						xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") ), ::cppu::bool2any( sal_False ) );
3011 				}
3012 			}
3013 		}
3014 
3015 		// set pos, size, shear and rotate
3016 		SetTransformation();
3017 		GetImport().GetShapeImport()->finishShape( mxShape, mxAttrList, mxShapes );
3018 	}
3019 }
3020 
3021 // this is called from the parent group for each unparsed attribute in the attribute list
3022 void SdXMLPluginShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
3023 {
3024 	switch( nPrefix )
3025 	{
3026 	case XML_NAMESPACE_DRAW:
3027 		if( IsXMLToken( rLocalName, XML_MIME_TYPE ) )
3028 		{
3029 			maMimeType = rValue;
3030 			return;
3031 		}
3032 		break;
3033 	case XML_NAMESPACE_XLINK:
3034 		if( IsXMLToken( rLocalName, XML_HREF ) )
3035 		{
3036 			maHref = GetImport().GetAbsoluteReference(rValue);
3037 			return;
3038 		}
3039 		break;
3040 	}
3041 
3042 	SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
3043 }
3044 
3045 void SdXMLPluginShapeContext::EndElement()
3046 {
3047 	uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY );
3048 
3049 	if( xProps.is() )
3050 	{
3051 		uno::Any aAny;
3052 
3053 		if ( maSize.Width && maSize.Height )
3054 		{
3055 			const rtl::OUString sVisibleArea( RTL_CONSTASCII_USTRINGPARAM( "VisibleArea" ) );
3056 			uno::Reference< beans::XPropertySetInfo > aXPropSetInfo( xProps->getPropertySetInfo() );
3057             if ( !aXPropSetInfo.is() || aXPropSetInfo->hasPropertyByName( sVisibleArea ) )
3058 			{
3059 				// the visual area for a plugin must be set on loading
3060 				awt::Rectangle aRect( 0, 0, maSize.Width, maSize.Height );
3061 				aAny <<= aRect;
3062 				xProps->setPropertyValue( sVisibleArea, aAny );
3063 			}
3064 		}
3065 
3066 		if( !mbMedia )
3067 		{
3068 			// in case we have a plugin object
3069 			if( maParams.getLength() )
3070 			{
3071 				aAny <<= maParams;
3072 				xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "PluginCommands" ) ), aAny );
3073 			}
3074 
3075 			if( maMimeType.getLength() )
3076 			{
3077 				aAny <<= maMimeType;
3078 				xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "PluginMimeType" ) ), aAny );
3079 			}
3080 
3081 			if( maHref.getLength() )
3082 			{
3083 				aAny <<= maHref;
3084 				xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "PluginURL" ) ), aAny );
3085 			}
3086 		}
3087 		else
3088 		{
3089 			// in case we have a media object
3090 
3091 			OUString sTempRef;
3092 
3093 			// check for package URL
3094 			if( GetImport().IsPackageURL( maHref ) )
3095 			{
3096 			    sTempRef = OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.Package:" ) );
3097 			}
3098 
3099 			sTempRef += maHref;
3100 
3101 			xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaURL" ) ), uno::makeAny( sTempRef ) );
3102 
3103 			for( sal_Int32 nParam = 0; nParam < maParams.getLength(); ++nParam )
3104 			{
3105 				const OUString& rName = maParams[ nParam ].Name;
3106 
3107 				if( 0 == rName.compareToAscii( "Loop" ) )
3108 				{
3109 					OUString aValueStr;
3110 					maParams[ nParam ].Value >>= aValueStr;
3111 					xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Loop" ) ),
3112 						uno::makeAny( static_cast< sal_Bool >( 0 == aValueStr.compareToAscii( "true" ) ) ) );
3113 				}
3114 				else if( 0 == rName.compareToAscii( "Mute" ) )
3115 				{
3116 					OUString aValueStr;
3117 					maParams[ nParam ].Value >>= aValueStr;
3118 					xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Mute" ) ),
3119 						uno::makeAny( static_cast< sal_Bool >( 0 == aValueStr.compareToAscii( "true" ) ) ) );
3120 				}
3121 				else if( 0 == rName.compareToAscii( "VolumeDB" ) )
3122 				{
3123 					OUString aValueStr;
3124 					maParams[ nParam ].Value >>= aValueStr;
3125 					xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "VolumeDB" ) ),
3126 					                            uno::makeAny( static_cast< sal_Int16 >( aValueStr.toInt32() ) ) );
3127 				}
3128 				else if( 0 == rName.compareToAscii( "Zoom" ) )
3129 				{
3130 					OUString 			aZoomStr;
3131 					media::ZoomLevel	eZoomLevel;
3132 
3133 					maParams[ nParam ].Value >>= aZoomStr;
3134 
3135 					if( 0 == aZoomStr.compareToAscii( "25%" ) )
3136 						eZoomLevel = media::ZoomLevel_ZOOM_1_TO_4;
3137 					else if( 0 == aZoomStr.compareToAscii( "50%" ) )
3138 						eZoomLevel = media::ZoomLevel_ZOOM_1_TO_2;
3139 					else if( 0 == aZoomStr.compareToAscii( "100%" ) )
3140 						eZoomLevel = media::ZoomLevel_ORIGINAL;
3141 					else if( 0 == aZoomStr.compareToAscii( "200%" ) )
3142 						eZoomLevel = media::ZoomLevel_ZOOM_2_TO_1;
3143 					else if( 0 == aZoomStr.compareToAscii( "400%" ) )
3144 						eZoomLevel = media::ZoomLevel_ZOOM_4_TO_1;
3145 					else if( 0 == aZoomStr.compareToAscii( "fit" ) )
3146 						eZoomLevel = media::ZoomLevel_FIT_TO_WINDOW;
3147 					else if( 0 == aZoomStr.compareToAscii( "fixedfit" ) )
3148 						eZoomLevel = media::ZoomLevel_FIT_TO_WINDOW_FIXED_ASPECT;
3149 					else if( 0 == aZoomStr.compareToAscii( "fullscreen" ) )
3150 						eZoomLevel = media::ZoomLevel_FULLSCREEN;
3151 					else
3152 						eZoomLevel = media::ZoomLevel_NOT_AVAILABLE;
3153 
3154 					xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Zoom" ) ), uno::makeAny( eZoomLevel ) );
3155 				}
3156 			}
3157 		}
3158 
3159 		SetThumbnail();
3160 	}
3161 
3162 	SdXMLShapeContext::EndElement();
3163 }
3164 
3165 SvXMLImportContext * SdXMLPluginShapeContext::CreateChildContext( sal_uInt16 p_nPrefix, const ::rtl::OUString& rLocalName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
3166 {
3167 	if( p_nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( rLocalName, XML_PARAM ) )
3168 	{
3169 		OUString aParamName, aParamValue;
3170 		const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
3171 		// now parse the attribute list and look for draw:name and draw:value
3172 		for(sal_Int16 a(0); a < nAttrCount; a++)
3173 		{
3174 			const OUString& rAttrName = xAttrList->getNameByIndex(a);
3175 			OUString aLocalName;
3176 			sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName);
3177 			const OUString aValue( xAttrList->getValueByIndex(a) );
3178 
3179 			if( nPrefix == XML_NAMESPACE_DRAW )
3180 			{
3181 				if( IsXMLToken( aLocalName, XML_NAME ) )
3182 				{
3183 					aParamName = aValue;
3184 				}
3185 				else if( IsXMLToken( aLocalName, XML_VALUE ) )
3186 				{
3187 					aParamValue = aValue;
3188 				}
3189 			}
3190 
3191 			if( aParamName.getLength() )
3192 			{
3193 				sal_Int32 nIndex = maParams.getLength();
3194 				maParams.realloc( nIndex + 1 );
3195 				maParams[nIndex].Name = aParamName;
3196 				maParams[nIndex].Handle = -1;
3197 				maParams[nIndex].Value <<= aParamValue;
3198 				maParams[nIndex].State = beans::PropertyState_DIRECT_VALUE;
3199 			}
3200 		}
3201 
3202 		return new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
3203 	}
3204 
3205 	return SdXMLShapeContext::CreateChildContext( p_nPrefix, rLocalName, xAttrList );
3206 }
3207 
3208 //////////////////////////////////////////////////////////////////////////////
3209 
3210 TYPEINIT1( SdXMLFloatingFrameShapeContext, SdXMLShapeContext );
3211 
3212 SdXMLFloatingFrameShapeContext::SdXMLFloatingFrameShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
3213 		const rtl::OUString& rLocalName,
3214 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
3215 		com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes,
3216         sal_Bool bTemporaryShape)
3217 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape )
3218 {
3219 }
3220 
3221 SdXMLFloatingFrameShapeContext::~SdXMLFloatingFrameShapeContext()
3222 {
3223 }
3224 
3225 void SdXMLFloatingFrameShapeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& )
3226 {
3227 	const char* pService = "com.sun.star.drawing.FrameShape";
3228 	AddShape( pService );
3229 
3230 	if( mxShape.is() )
3231 	{
3232 		SetLayer();
3233 
3234 		// set pos, size, shear and rotate
3235 		SetTransformation();
3236 
3237 		uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY );
3238 		if( xProps.is() )
3239 		{
3240 			uno::Any aAny;
3241 
3242 			if( maFrameName.getLength() )
3243 			{
3244 				aAny <<= maFrameName;
3245 				xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "FrameName" ) ), aAny );
3246 			}
3247 
3248 			if( maHref.getLength() )
3249 			{
3250 				aAny <<= maHref;
3251 				xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "FrameURL" ) ), aAny );
3252 			}
3253 		}
3254 
3255 		SetStyle();
3256 
3257 		GetImport().GetShapeImport()->finishShape( mxShape, mxAttrList, mxShapes );
3258 	}
3259 }
3260 
3261 // this is called from the parent group for each unparsed attribute in the attribute list
3262 void SdXMLFloatingFrameShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
3263 {
3264 	switch( nPrefix )
3265 	{
3266 	case XML_NAMESPACE_DRAW:
3267 		if( IsXMLToken( rLocalName, XML_FRAME_NAME ) )
3268 		{
3269 			maFrameName = rValue;
3270 			return;
3271 		}
3272 		break;
3273 	case XML_NAMESPACE_XLINK:
3274 		if( IsXMLToken( rLocalName, XML_HREF ) )
3275 		{
3276 			maHref = GetImport().GetAbsoluteReference(rValue);
3277 			return;
3278 		}
3279 		break;
3280 	}
3281 
3282 	SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
3283 }
3284 
3285 void SdXMLFloatingFrameShapeContext::EndElement()
3286 {
3287 	uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY );
3288 
3289 	if( xProps.is() )
3290 	{
3291 		if ( maSize.Width && maSize.Height )
3292 		{
3293 			// the visual area for a floating frame must be set on loading
3294 			awt::Rectangle aRect( 0, 0, maSize.Width, maSize.Height );
3295 			uno::Any aAny;
3296 			aAny <<= aRect;
3297 			xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "VisibleArea" ) ), aAny );
3298 		}
3299 	}
3300 
3301 	SetThumbnail();
3302 	SdXMLShapeContext::EndElement();
3303 }
3304 
3305 //////////////////////////////////////////////////////////////////////////////
3306 
3307 TYPEINIT1( SdXMLFrameShapeContext, SdXMLShapeContext );
3308 
3309 SdXMLFrameShapeContext::SdXMLFrameShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
3310 		const rtl::OUString& rLocalName,
3311 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
3312 		com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes,
3313         sal_Bool bTemporaryShape)
3314 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
3315 	mbSupportsReplacement( sal_False )
3316 {
3317 	uno::Reference < util::XCloneable > xClone( xAttrList, uno::UNO_QUERY );
3318 	if( xClone.is() )
3319 		mxAttrList.set( xClone->createClone(), uno::UNO_QUERY );
3320 	else
3321 		mxAttrList = new SvXMLAttributeList( xAttrList );
3322 
3323 }
3324 
3325 SdXMLFrameShapeContext::~SdXMLFrameShapeContext()
3326 {
3327 }
3328 
3329 SvXMLImportContext *SdXMLFrameShapeContext::CreateChildContext( sal_uInt16 nPrefix,
3330 	const OUString& rLocalName,
3331 	const uno::Reference< xml::sax::XAttributeList>& xAttrList )
3332 {
3333 	SvXMLImportContext * pContext = 0;
3334 
3335 	if( !mxImplContext.Is() )
3336 	{
3337 		pContext = GetImport().GetShapeImport()->CreateFrameChildContext(
3338 						GetImport(), nPrefix, rLocalName, xAttrList, mxShapes, mxAttrList );
3339 
3340 		mxImplContext = pContext;
3341 		mbSupportsReplacement = IsXMLToken( rLocalName, XML_OBJECT ) ||
3342 								IsXMLToken( rLocalName, XML_OBJECT_OLE );
3343 	}
3344 	else if( mbSupportsReplacement && !mxReplImplContext &&
3345 			 XML_NAMESPACE_DRAW == nPrefix &&
3346 			 IsXMLToken( rLocalName, XML_IMAGE ) )
3347 	{
3348 		// read replacement image
3349 		SvXMLImportContext *pImplContext = &mxImplContext;
3350 		SdXMLShapeContext *pSContext =
3351 			PTR_CAST( SdXMLShapeContext, pImplContext );
3352 		if( pSContext )
3353 		{
3354 			uno::Reference < beans::XPropertySet > xPropSet(
3355 					pSContext->getShape(), uno::UNO_QUERY );
3356 			if( xPropSet.is() )
3357 			{
3358 				pContext = new XMLReplacementImageContext( GetImport(),
3359 									nPrefix, rLocalName, xAttrList, xPropSet );
3360 				mxReplImplContext = pContext;
3361 			}
3362 		}
3363 	}
3364 	else if(
3365 			( nPrefix == XML_NAMESPACE_SVG &&	// #i68101#
3366 				(IsXMLToken( rLocalName, XML_TITLE ) || IsXMLToken( rLocalName, XML_DESC ) ) ) ||
3367 			 (nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) ) ||
3368 			 (nPrefix == XML_NAMESPACE_DRAW && (IsXMLToken( rLocalName, XML_GLUE_POINT ) ||
3369 												IsXMLToken( rLocalName, XML_THUMBNAIL ) ) ) )
3370 	{
3371 		SvXMLImportContext *pImplContext = &mxImplContext;
3372 		pContext = PTR_CAST( SdXMLShapeContext, pImplContext )->CreateChildContext( nPrefix,
3373 																		rLocalName, xAttrList );
3374 	}
3375 	else if ( (XML_NAMESPACE_DRAW == nPrefix) && IsXMLToken( rLocalName, XML_IMAGE_MAP ) )
3376 	{
3377 		SdXMLShapeContext *pSContext = dynamic_cast< SdXMLShapeContext* >( &mxImplContext );
3378 		if( pSContext )
3379 		{
3380 			uno::Reference < beans::XPropertySet > xPropSet( pSContext->getShape(), uno::UNO_QUERY );
3381 			if (xPropSet.is())
3382 			{
3383 				pContext = new XMLImageMapContext(GetImport(), nPrefix, rLocalName, xPropSet);
3384 			}
3385 		}
3386 	}
3387 
3388 	// call parent for content
3389 	if(!pContext)
3390 		pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
3391 
3392 	return pContext;
3393 }
3394 
3395 void SdXMLFrameShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>&)
3396 {
3397 	// ignore
3398 }
3399 
3400 void SdXMLFrameShapeContext::EndElement()
3401 {
3402 	if( !mxImplContext.Is() )
3403 	{
3404 		// now check if this is an empty presentation object
3405 		sal_Int16 nAttrCount = mxAttrList.is() ? mxAttrList->getLength() : 0;
3406 		for(sal_Int16 a(0); a < nAttrCount; a++)
3407 		{
3408 			OUString aLocalName;
3409 			sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(mxAttrList->getNameByIndex(a), &aLocalName);
3410 
3411 			if( nPrefix == XML_NAMESPACE_PRESENTATION )
3412 			{
3413 				if( IsXMLToken( aLocalName, XML_PLACEHOLDER ) )
3414 				{
3415 					mbIsPlaceholder = IsXMLToken( mxAttrList->getValueByIndex(a), XML_TRUE );
3416 				}
3417 				else if( IsXMLToken( aLocalName, XML_CLASS ) )
3418 				{
3419 					maPresentationClass = mxAttrList->getValueByIndex(a);
3420 				}
3421 			}
3422 		}
3423 
3424 		if( (maPresentationClass.getLength() != 0) && mbIsPlaceholder )
3425 		{
3426 			uno::Reference< xml::sax::XAttributeList> xEmpty;
3427 
3428 			enum XMLTokenEnum eToken = XML_TEXT_BOX;
3429 
3430 			if( IsXMLToken( maPresentationClass, XML_GRAPHIC ) )
3431 			{
3432 				eToken = XML_IMAGE;
3433 
3434 			}
3435 			else if( IsXMLToken( maPresentationClass, XML_PRESENTATION_PAGE ) )
3436 			{
3437 				eToken = XML_PAGE_THUMBNAIL;
3438 			}
3439 			else if( IsXMLToken( maPresentationClass, XML_PRESENTATION_CHART ) ||
3440 					 IsXMLToken( maPresentationClass, XML_PRESENTATION_TABLE ) ||
3441 					 IsXMLToken( maPresentationClass, XML_PRESENTATION_OBJECT ) )
3442 			{
3443 				eToken = XML_OBJECT;
3444 			}
3445 
3446 			mxImplContext = GetImport().GetShapeImport()->CreateFrameChildContext(
3447 					GetImport(), XML_NAMESPACE_DRAW, GetXMLToken( eToken ), mxAttrList, mxShapes, xEmpty );
3448 
3449 			if( mxImplContext.Is() )
3450 			{
3451 				mxImplContext->StartElement( mxAttrList );
3452 				mxImplContext->EndElement();
3453 			}
3454 		}
3455 	}
3456 
3457 	mxImplContext = 0;
3458 	SdXMLShapeContext::EndElement();
3459 }
3460 
3461 void SdXMLFrameShapeContext::processAttribute( sal_uInt16,
3462 		const ::rtl::OUString&, const ::rtl::OUString& )
3463 {
3464 	// ignore
3465 }
3466 
3467 TYPEINIT1( SdXMLCustomShapeContext, SdXMLShapeContext );
3468 
3469 SdXMLCustomShapeContext::SdXMLCustomShapeContext(
3470 	SvXMLImport& rImport,
3471 	sal_uInt16 nPrfx,
3472 	const OUString& rLocalName,
3473 	const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
3474 	uno::Reference< drawing::XShapes >& rShapes,
3475     sal_Bool bTemporaryShape)
3476 :	SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape )
3477 {
3478 }
3479 
3480 //////////////////////////////////////////////////////////////////////////////
3481 
3482 SdXMLCustomShapeContext::~SdXMLCustomShapeContext()
3483 {
3484 }
3485 
3486 //////////////////////////////////////////////////////////////////////////////
3487 
3488 // this is called from the parent group for each unparsed attribute in the attribute list
3489 void SdXMLCustomShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
3490 {
3491 	if( XML_NAMESPACE_DRAW == nPrefix )
3492 	{
3493 		if( IsXMLToken( rLocalName, XML_ENGINE ) )
3494 		{
3495 			maCustomShapeEngine = rValue;
3496 			return;
3497 		}
3498 		if ( IsXMLToken( rLocalName, XML_DATA ) )
3499 		{
3500 			maCustomShapeData = rValue;
3501 			return;
3502 		}
3503 	}
3504 	SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
3505 }
3506 
3507 //////////////////////////////////////////////////////////////////////////////
3508 
3509 void SdXMLCustomShapeContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
3510 {
3511 	// create rectangle shape
3512 	AddShape("com.sun.star.drawing.CustomShape");
3513 	if ( mxShape.is() )
3514 	{
3515 		// Add, set Style and properties from base shape
3516 		SetStyle();
3517 		SetLayer();
3518 
3519 		// set pos, size, shear and rotate
3520 		SetTransformation();
3521 
3522 		try
3523 		{
3524 			uno::Reference< beans::XPropertySet > xPropSet( mxShape, uno::UNO_QUERY );
3525 			if( xPropSet.is() )
3526 			{
3527 				if ( maCustomShapeEngine.getLength() )
3528 				{
3529 					uno::Any aAny;
3530 					aAny <<= maCustomShapeEngine;
3531 					xPropSet->setPropertyValue( EASGet( EAS_CustomShapeEngine ), aAny );
3532 				}
3533 				if ( maCustomShapeData.getLength() )
3534 				{
3535 					uno::Any aAny;
3536 					aAny <<= maCustomShapeData;
3537 					xPropSet->setPropertyValue( EASGet( EAS_CustomShapeData ), aAny );
3538 				}
3539 			}
3540 		}
3541 		catch( uno::Exception& )
3542 		{
3543 			DBG_ERROR( "could not set enhanced customshape geometry" );
3544 		}
3545 		SdXMLShapeContext::StartElement(xAttrList);
3546 	}
3547 }
3548 
3549 void SdXMLCustomShapeContext::EndElement()
3550 {
3551 	if ( !maCustomShapeGeometry.empty() )
3552 	{
3553 		const rtl::OUString	sCustomShapeGeometry	( RTL_CONSTASCII_USTRINGPARAM( "CustomShapeGeometry" ) );
3554 
3555 		// converting the vector to a sequence
3556 		uno::Sequence< beans::PropertyValue > aSeq( maCustomShapeGeometry.size() );
3557 		beans::PropertyValue* pValues = aSeq.getArray();
3558 		std::vector< beans::PropertyValue >::const_iterator aIter( maCustomShapeGeometry.begin() );
3559 		std::vector< beans::PropertyValue >::const_iterator aEnd( maCustomShapeGeometry.end() );
3560 		while ( aIter != aEnd )
3561 			*pValues++ = *aIter++;
3562 
3563 		try
3564 		{
3565 			uno::Reference< beans::XPropertySet > xPropSet( mxShape, uno::UNO_QUERY );
3566 			if( xPropSet.is() )
3567 			{
3568 				uno::Any aAny;
3569 				aAny <<= aSeq;
3570 				xPropSet->setPropertyValue( sCustomShapeGeometry, aAny );
3571 			}
3572 		}
3573 		catch( uno::Exception& )
3574 		{
3575 			DBG_ERROR( "could not set enhanced customshape geometry" );
3576 		}
3577 
3578         sal_Int32 nUPD( 0 );
3579         sal_Int32 nBuild( 0 );
3580         GetImport().getBuildIds( nUPD, nBuild );
3581         if( ((nUPD >= 640 && nUPD <= 645) || (nUPD == 680)) && (nBuild <= 9221) )
3582 		{
3583 			Reference< drawing::XEnhancedCustomShapeDefaulter > xDefaulter( mxShape, UNO_QUERY );
3584 			if( xDefaulter.is() )
3585 			{
3586 				rtl::OUString aEmptyType;
3587 				xDefaulter->createCustomShapeDefaults( aEmptyType );
3588 			}
3589 		}
3590 	}
3591 
3592 	SdXMLShapeContext::EndElement();
3593 }
3594 
3595 //////////////////////////////////////////////////////////////////////////////
3596 
3597 SvXMLImportContext* SdXMLCustomShapeContext::CreateChildContext(
3598 	sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
3599 	const uno::Reference<xml::sax::XAttributeList>& xAttrList )
3600 {
3601 	SvXMLImportContext* pContext = NULL;
3602 	if ( XML_NAMESPACE_DRAW == nPrefix )
3603 	{
3604 		if ( IsXMLToken( rLocalName, XML_ENHANCED_GEOMETRY ) )
3605 		{
3606 			uno::Reference< beans::XPropertySet > xPropSet( mxShape,uno::UNO_QUERY );
3607 			if ( xPropSet.is() )
3608 				pContext = new XMLEnhancedCustomShapeContext( GetImport(), mxShape, nPrefix, rLocalName, maCustomShapeGeometry );
3609 		}
3610 	}
3611 	// delegate to parent class if no context could be created
3612 	if ( NULL == pContext )
3613 		pContext = SdXMLShapeContext::CreateChildContext( nPrefix, rLocalName,
3614 														 xAttrList);
3615 	return pContext;
3616 }
3617 
3618 ///////////////////////////////////////////////////////////////////////
3619 
3620 //////////////////////////////////////////////////////////////////////////////
3621 
3622 TYPEINIT1( SdXMLTableShapeContext, SdXMLShapeContext );
3623 
3624 SdXMLTableShapeContext::SdXMLTableShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLocalName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes )
3625 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, sal_False )
3626 {
3627 	memset( &maTemplateStylesUsed, 0, sizeof( maTemplateStylesUsed ) );
3628 }
3629 
3630 SdXMLTableShapeContext::~SdXMLTableShapeContext()
3631 {
3632 }
3633 
3634 void SdXMLTableShapeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList )
3635 {
3636 	const char* pService = "com.sun.star.drawing.TableShape";
3637 
3638 	sal_Bool bIsPresShape = maPresentationClass.getLength() && GetImport().GetShapeImport()->IsPresentationShapesSupported();
3639 	if( bIsPresShape )
3640 	{
3641 		if( IsXMLToken( maPresentationClass, XML_PRESENTATION_TABLE ) )
3642 		{
3643 			pService = "com.sun.star.presentation.TableShape";
3644 		}
3645 	}
3646 
3647 	AddShape( pService );
3648 
3649 	if( mxShape.is() )
3650 	{
3651 		SetLayer();
3652 
3653 		uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY);
3654 
3655 		if(bIsPresShape)
3656 		{
3657 			if(xProps.is())
3658 			{
3659 				uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() );
3660 				if( xPropsInfo.is() )
3661 				{
3662 					if( !mbIsPlaceholder && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") )))
3663 						xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsEmptyPresentationObject") ), ::cppu::bool2any( sal_False ) );
3664 
3665 					if( mbIsUserTransformed && xPropsInfo->hasPropertyByName(OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") )))
3666 						xProps->setPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("IsPlaceholderDependent") ), ::cppu::bool2any( sal_False ) );
3667 				}
3668 			}
3669 		}
3670 
3671 		SetStyle();
3672 
3673 		if( xProps.is() )
3674 		{
3675 			if( msTemplateStyleName.getLength() ) try
3676 			{
3677 				Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetImport().GetModel(), UNO_QUERY_THROW );
3678 				Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
3679 				const OUString sFamilyName( RTL_CONSTASCII_USTRINGPARAM("table" ) );
3680 				Reference< XNameAccess > xTableFamily( xFamilies->getByName( sFamilyName ), UNO_QUERY_THROW );
3681 				Reference< XStyle > xTableStyle( xTableFamily->getByName( msTemplateStyleName ), UNO_QUERY_THROW );
3682 				xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "TableTemplate" ) ), Any( xTableStyle ) );
3683 			}
3684 			catch( Exception& )
3685 			{
3686 				DBG_ERROR("SdXMLTableShapeContext::StartElement(), exception caught!");
3687 			}
3688 
3689 			const XMLPropertyMapEntry* pEntry = &aXMLTableShapeAttributes[0];
3690 			for( int i = 0; pEntry->msApiName && (i < 6); i++, pEntry++ )
3691 			{
3692 			    try
3693 			    {
3694 				    const OUString sAPIPropertyName( OUString(pEntry->msApiName, pEntry->nApiNameLength, RTL_TEXTENCODING_ASCII_US ) );
3695 				    xProps->setPropertyValue( sAPIPropertyName, Any( maTemplateStylesUsed[i] ) );
3696 			    }
3697 			    catch( Exception& )
3698 			    {
3699 				    DBG_ERROR("SdXMLTableShapeContext::StartElement(), exception caught!");
3700 			    }
3701             }
3702 		}
3703 
3704 		GetImport().GetShapeImport()->finishShape( mxShape, mxAttrList, mxShapes );
3705 
3706 		const rtl::Reference< XMLTableImport >& xTableImport( GetImport().GetShapeImport()->GetShapeTableImport() );
3707 		if( xTableImport.is() && xProps.is() )
3708 		{
3709 			uno::Reference< table::XColumnRowRange > xColumnRowRange(
3710 				xProps->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("Model") ) ), uno::UNO_QUERY );
3711 
3712 			if( xColumnRowRange.is() )
3713 				mxTableImportContext = xTableImport->CreateTableContext( GetPrefix(), GetLocalName(), xColumnRowRange );
3714 
3715 			if( mxTableImportContext.Is() )
3716 				mxTableImportContext->StartElement( xAttrList );
3717 		}
3718 	}
3719 }
3720 
3721 void SdXMLTableShapeContext::EndElement()
3722 {
3723 	if( mxTableImportContext.Is() )
3724 		mxTableImportContext->EndElement();
3725 
3726 	SdXMLShapeContext::EndElement();
3727 
3728 	if( mxShape.is() )
3729 	{
3730 		// set pos, size, shear and rotate
3731 		SetTransformation();
3732 	}
3733 }
3734 
3735 // this is called from the parent group for each unparsed attribute in the attribute list
3736 void SdXMLTableShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
3737 {
3738 	if( nPrefix == XML_NAMESPACE_TABLE )
3739 	{
3740 		if( IsXMLToken( rLocalName, XML_TEMPLATE_NAME ) )
3741 		{
3742 			msTemplateStyleName = rValue;
3743 		}
3744 		else
3745 		{
3746 			int i = 0;
3747 			const XMLPropertyMapEntry* pEntry = &aXMLTableShapeAttributes[0];
3748 			while( pEntry->msApiName && (i < 6) )
3749 			{
3750 				if( IsXMLToken( rLocalName, pEntry->meXMLName ) )
3751 				{
3752 					if( IsXMLToken( rValue, XML_TRUE ) )
3753 						maTemplateStylesUsed[i] = sal_True;
3754 					break;
3755 				}
3756 				pEntry++;
3757 				i++;
3758 			}
3759 		}
3760 	}
3761 	SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
3762 }
3763 
3764 SvXMLImportContext* SdXMLTableShapeContext::CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& xAttrList )
3765 {
3766 	if( mxTableImportContext.Is() && (nPrefix == XML_NAMESPACE_TABLE) )
3767 		return mxTableImportContext->CreateChildContext(nPrefix, rLocalName, xAttrList);
3768 	else
3769 		return SdXMLShapeContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
3770 }
3771 
3772