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