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