Bump for 4.0-11
[LibreOffice.git] / xmloff / source / draw / ximpshap.cxx
blobf0307c9f98063297b4cfeab07098be96f6bb0102
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <cassert>
22 #include <tools/debug.hxx>
23 #include <com/sun/star/document/XEventsSupplier.hpp>
24 #include <com/sun/star/container/XNameReplace.hpp>
25 #include <com/sun/star/presentation/ClickAction.hpp>
26 #include <com/sun/star/drawing/FillStyle.hpp>
27 #include <com/sun/star/drawing/LineStyle.hpp>
28 #include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
29 #include <com/sun/star/drawing/XGluePointsSupplier.hpp>
30 #include <com/sun/star/container/XIdentifierAccess.hpp>
31 #include <com/sun/star/drawing/GluePoint2.hpp>
32 #include <com/sun/star/drawing/Alignment.hpp>
33 #include <com/sun/star/drawing/EscapeDirection.hpp>
34 #include <com/sun/star/media/ZoomLevel.hpp>
35 #include <com/sun/star/awt/Rectangle.hpp>
37 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
38 #include <com/sun/star/container/XNameAccess.hpp>
39 #include <comphelper/extract.hxx>
40 #include "ximpshap.hxx"
41 #include <xmloff/XMLBase64ImportContext.hxx>
42 #include <xmloff/XMLShapeStyleContext.hxx>
43 #include <xmloff/xmluconv.hxx>
44 #include <com/sun/star/container/XNamed.hpp>
45 #include <com/sun/star/drawing/CircleKind.hpp>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <com/sun/star/awt/XControlModel.hpp>
48 #include <com/sun/star/drawing/XControlShape.hpp>
49 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
50 #include <com/sun/star/drawing/PointSequence.hpp>
51 #include <com/sun/star/lang/XServiceInfo.hpp>
52 #include <com/sun/star/util/XCloneable.hpp>
53 #include <com/sun/star/beans/XMultiPropertyStates.hpp>
54 #include "xexptran.hxx"
55 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
56 #include <com/sun/star/beans/XPropertySetInfo.hpp>
57 #include <com/sun/star/drawing/ConnectorType.hpp>
58 #include <com/sun/star/drawing/HomogenMatrix3.hpp>
60 #include <sax/tools/converter.hxx>
62 #include "PropertySetMerger.hxx"
63 #include <xmloff/families.hxx>
64 #include "ximpstyl.hxx"
65 #include"xmloff/xmlnmspe.hxx"
66 #include <xmloff/xmltoken.hxx>
67 #include "EnhancedCustomShapeToken.hxx"
68 #include "XMLReplacementImageContext.hxx"
69 #include "XMLImageMapContext.hxx"
70 #include "sdpropls.hxx"
71 #include "eventimp.hxx"
73 #include "descriptionimp.hxx"
74 #include "ximpcustomshape.hxx"
75 #include "XMLEmbeddedObjectImportContext.hxx"
76 #include "xmloff/xmlerror.hxx"
77 #include <basegfx/matrix/b2dhommatrix.hxx>
78 #include <com/sun/star/drawing/XEnhancedCustomShapeDefaulter.hpp>
79 #include <com/sun/star/container/XChild.hpp>
80 #include <com/sun/star/text/XTextDocument.hpp>
82 using ::rtl::OUString;
83 using ::rtl::OUStringBuffer;
85 using namespace ::com::sun::star;
86 using namespace ::com::sun::star::uno;
87 using namespace ::com::sun::star::drawing;
88 using namespace ::com::sun::star::style;
89 using namespace ::com::sun::star::container;
90 using namespace ::com::sun::star::document;
91 using namespace ::xmloff::token;
92 using namespace ::xmloff::EnhancedCustomShapeToken;
94 SvXMLEnumMapEntry aXML_GlueAlignment_EnumMap[] =
96 { XML_TOP_LEFT, drawing::Alignment_TOP_LEFT },
97 { XML_TOP, drawing::Alignment_TOP },
98 { XML_TOP_RIGHT, drawing::Alignment_TOP_RIGHT },
99 { XML_LEFT, drawing::Alignment_LEFT },
100 { XML_CENTER, drawing::Alignment_CENTER },
101 { XML_RIGHT, drawing::Alignment_RIGHT },
102 { XML_BOTTOM_LEFT, drawing::Alignment_BOTTOM_LEFT },
103 { XML_BOTTOM, drawing::Alignment_BOTTOM },
104 { XML_BOTTOM_RIGHT, drawing::Alignment_BOTTOM_RIGHT },
105 { XML_TOKEN_INVALID, 0 }
108 SvXMLEnumMapEntry aXML_GlueEscapeDirection_EnumMap[] =
110 { XML_AUTO, drawing::EscapeDirection_SMART },
111 { XML_LEFT, drawing::EscapeDirection_LEFT },
112 { XML_RIGHT, drawing::EscapeDirection_RIGHT },
113 { XML_UP, drawing::EscapeDirection_UP },
114 { XML_DOWN, drawing::EscapeDirection_DOWN },
115 { XML_HORIZONTAL, drawing::EscapeDirection_HORIZONTAL },
116 { XML_VERTICAL, drawing::EscapeDirection_VERTICAL },
117 { XML_TOKEN_INVALID, 0 }
120 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
122 static bool ImpIsEmptyURL( const ::rtl::OUString& rURL )
124 if( rURL.isEmpty() )
125 return true;
127 // #i13140# Also compare against 'toplevel' URLs. which also
128 // result in empty filename strings.
129 if( 0 == rURL.compareToAscii( "#./" ) )
130 return true;
132 return false;
135 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
137 TYPEINIT1( SvXMLShapeContext, SvXMLImportContext );
138 TYPEINIT1( SdXMLShapeContext, SvXMLShapeContext );
140 SdXMLShapeContext::SdXMLShapeContext(
141 SvXMLImport& rImport,
142 sal_uInt16 nPrfx,
143 const OUString& rLocalName,
144 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
145 uno::Reference< drawing::XShapes >& rShapes,
146 sal_Bool bTemporaryShape)
147 : SvXMLShapeContext( rImport, nPrfx, rLocalName, bTemporaryShape )
148 , mxShapes( rShapes )
149 , mxAttrList(xAttrList)
150 , mbListContextPushed( false )
151 , mnStyleFamily(XML_STYLE_FAMILY_SD_GRAPHICS_ID)
152 , mbIsPlaceholder(sal_False)
153 , mbClearDefaultAttributes( true )
154 , mbIsUserTransformed(sal_False)
155 , mnZOrder(-1)
156 , maSize(1, 1)
157 , maPosition(0, 0)
158 , mbVisible(true)
159 , mbPrintable(true)
163 //////////////////////////////////////////////////////////////////////////////
165 SdXMLShapeContext::~SdXMLShapeContext()
169 //////////////////////////////////////////////////////////////////////////////
171 SvXMLImportContext *SdXMLShapeContext::CreateChildContext( sal_uInt16 p_nPrefix,
172 const OUString& rLocalName,
173 const uno::Reference< xml::sax::XAttributeList>& xAttrList )
175 SvXMLImportContext * pContext = NULL;
177 // #i68101#
178 if( p_nPrefix == XML_NAMESPACE_SVG &&
179 (IsXMLToken( rLocalName, XML_TITLE ) || IsXMLToken( rLocalName, XML_DESC ) ) )
181 pContext = new SdXMLDescriptionContext( GetImport(), p_nPrefix, rLocalName, xAttrList, mxShape );
183 else if( p_nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) )
185 pContext = new SdXMLEventsContext( GetImport(), p_nPrefix, rLocalName, xAttrList, mxShape );
187 else if( p_nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( rLocalName, XML_GLUE_POINT ) )
189 addGluePoint( xAttrList );
191 else if( p_nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( rLocalName, XML_THUMBNAIL ) )
193 // search attributes for xlink:href
194 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
195 for(sal_Int16 i=0; i < nAttrCount; i++)
197 OUString sAttrName = xAttrList->getNameByIndex( i );
198 OUString aLocalName;
199 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
201 if( nPrefix == XML_NAMESPACE_XLINK )
203 if( IsXMLToken( aLocalName, XML_HREF ) )
205 maThumbnailURL = xAttrList->getValueByIndex( i );
206 break;
211 else
213 // create text cursor on demand
214 if( !mxCursor.is() )
216 uno::Reference< text::XText > xText( mxShape, uno::UNO_QUERY );
217 if( xText.is() )
219 UniReference < XMLTextImportHelper > xTxtImport =
220 GetImport().GetTextImport();
221 mxOldCursor = xTxtImport->GetCursor();
222 mxCursor = xText->createTextCursor();
223 if( mxCursor.is() )
225 xTxtImport->SetCursor( mxCursor );
228 // remember old list item and block (#91964#) and reset them
229 // for the text frame
230 xTxtImport->PushListContext();
231 mbListContextPushed = true;
235 // if we have a text cursor, lets try to import some text
236 if( mxCursor.is() )
238 pContext = GetImport().GetTextImport()->CreateTextChildContext(
239 GetImport(), p_nPrefix, rLocalName, xAttrList );
243 // call parent for content
244 if(!pContext)
245 pContext = SvXMLImportContext::CreateChildContext( p_nPrefix, rLocalName, xAttrList );
247 return pContext;
250 void SdXMLShapeContext::addGluePoint( const uno::Reference< xml::sax::XAttributeList>& xAttrList )
252 // get the glue points container for this shape if its not already there
253 if( !mxGluePoints.is() )
255 uno::Reference< drawing::XGluePointsSupplier > xSupplier( mxShape, uno::UNO_QUERY );
256 if( !xSupplier.is() )
257 return;
259 mxGluePoints = uno::Reference< container::XIdentifierContainer >::query( xSupplier->getGluePoints() );
261 if( !mxGluePoints.is() )
262 return;
265 drawing::GluePoint2 aGluePoint;
266 aGluePoint.IsUserDefined = sal_True;
267 aGluePoint.Position.X = 0;
268 aGluePoint.Position.Y = 0;
269 aGluePoint.Escape = drawing::EscapeDirection_SMART;
270 aGluePoint.PositionAlignment = drawing::Alignment_CENTER;
271 aGluePoint.IsRelative = sal_True;
273 sal_Int32 nId = -1;
275 // read attributes for the 3DScene
276 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
277 for(sal_Int16 i=0; i < nAttrCount; i++)
279 OUString sAttrName = xAttrList->getNameByIndex( i );
280 OUString aLocalName;
281 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
282 const OUString sValue( xAttrList->getValueByIndex( i ) );
284 if( nPrefix == XML_NAMESPACE_SVG )
286 if( IsXMLToken( aLocalName, XML_X ) )
288 GetImport().GetMM100UnitConverter().convertMeasureToCore(
289 aGluePoint.Position.X, sValue);
291 else if( IsXMLToken( aLocalName, XML_Y ) )
293 GetImport().GetMM100UnitConverter().convertMeasureToCore(
294 aGluePoint.Position.Y, sValue);
297 else if( nPrefix == XML_NAMESPACE_DRAW )
299 if( IsXMLToken( aLocalName, XML_ID ) )
301 nId = sValue.toInt32();
303 else if( IsXMLToken( aLocalName, XML_ALIGN ) )
305 sal_uInt16 eKind;
306 if( SvXMLUnitConverter::convertEnum( eKind, sValue, aXML_GlueAlignment_EnumMap ) )
308 aGluePoint.PositionAlignment = (drawing::Alignment)eKind;
309 aGluePoint.IsRelative = sal_False;
312 else if( IsXMLToken( aLocalName, XML_ESCAPE_DIRECTION ) )
314 sal_uInt16 eKind;
315 if( SvXMLUnitConverter::convertEnum( eKind, sValue, aXML_GlueEscapeDirection_EnumMap ) )
317 aGluePoint.Escape = (drawing::EscapeDirection)eKind;
323 if( nId != -1 )
327 sal_Int32 nInternalId = mxGluePoints->insert( uno::makeAny( aGluePoint ) );
328 GetImport().GetShapeImport()->addGluePointMapping( mxShape, nId, nInternalId );
330 catch(const uno::Exception&)
332 OSL_FAIL( "exception during setting of glue points!");
336 //////////////////////////////////////////////////////////////////////////////
338 void SdXMLShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>&)
340 GetImport().GetShapeImport()->finishShape( mxShape, mxAttrList, mxShapes );
343 void SdXMLShapeContext::EndElement()
345 if(mxCursor.is())
347 // delete addition newline
348 const OUString aEmpty;
349 mxCursor->gotoEnd( sal_False );
350 mxCursor->goLeft( 1, sal_True );
351 mxCursor->setString( aEmpty );
353 // reset cursor
354 GetImport().GetTextImport()->ResetCursor();
357 if(mxOldCursor.is())
358 GetImport().GetTextImport()->SetCursor( mxOldCursor );
360 // reinstall old list item (if necessary) #91964#
361 if (mbListContextPushed) {
362 GetImport().GetTextImport()->PopListContext();
365 if( !msHyperlink.isEmpty() ) try
367 uno::Reference< beans::XPropertySet > xProp( mxShape, uno::UNO_QUERY );
369 rtl::OUString sLink( "Hyperlink" );
370 if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName( sLink ) )
371 xProp->setPropertyValue( sLink, uno::Any( msHyperlink ) );
372 Reference< XEventsSupplier > xEventsSupplier( mxShape, UNO_QUERY );
373 const OUString sBookmark( "Bookmark" );
375 if( xEventsSupplier.is() )
377 const OUString sEventType( "EventType" );
378 const OUString sClickAction( "ClickAction" );
380 Reference< XNameReplace > xEvents( xEventsSupplier->getEvents(), UNO_QUERY_THROW );
382 uno::Sequence< beans::PropertyValue > aProperties( 3 );
383 aProperties[0].Name = sEventType;
384 aProperties[0].Handle = -1;
385 aProperties[0].Value <<= OUString( "Presentation" );
386 aProperties[0].State = beans::PropertyState_DIRECT_VALUE;
388 aProperties[1].Name = sClickAction;
389 aProperties[1].Handle = -1;
390 aProperties[1].Value <<= ::com::sun::star::presentation::ClickAction_DOCUMENT;
391 aProperties[1].State = beans::PropertyState_DIRECT_VALUE;
393 aProperties[2].Name = sBookmark;
394 aProperties[2].Handle = -1;
395 aProperties[2].Value <<= msHyperlink;
396 aProperties[2].State = beans::PropertyState_DIRECT_VALUE;
398 const OUString sAPIEventName( "OnClick" );
399 xEvents->replaceByName( sAPIEventName, Any( aProperties ) );
401 else
403 // in draw use the Bookmark property
404 Reference< beans::XPropertySet > xSet( mxShape, UNO_QUERY_THROW );
405 xSet->setPropertyValue( sBookmark, Any( msHyperlink ) );
406 xSet->setPropertyValue( OUString( "OnClick" ), Any( ::com::sun::star::presentation::ClickAction_DOCUMENT ) );
409 catch(const Exception&)
411 OSL_FAIL("xmloff::SdXMLShapeContext::EndElement(), exception caught while setting hyperlink!");
414 if( mxLockable.is() )
415 mxLockable->removeActionLock();
418 //////////////////////////////////////////////////////////////////////////////
420 void SdXMLShapeContext::AddShape(uno::Reference< drawing::XShape >& xShape)
422 if(xShape.is())
424 // set shape local
425 mxShape = xShape;
427 if(!maShapeName.isEmpty())
429 uno::Reference< container::XNamed > xNamed( mxShape, uno::UNO_QUERY );
430 if( xNamed.is() )
431 xNamed->setName( maShapeName );
434 UniReference< XMLShapeImportHelper > xImp( GetImport().GetShapeImport() );
435 xImp->addShape( xShape, mxAttrList, mxShapes );
437 if( mbClearDefaultAttributes )
439 uno::Reference<beans::XMultiPropertyStates> xMultiPropertyStates(xShape, uno::UNO_QUERY );
440 if (xMultiPropertyStates.is())
441 xMultiPropertyStates->setAllPropertiesToDefault();
444 if( !mbVisible || !mbPrintable ) try
446 uno::Reference< beans::XPropertySet > xSet( xShape, uno::UNO_QUERY_THROW );
447 if( !mbVisible )
448 xSet->setPropertyValue( rtl::OUString( "Visible" ), uno::Any( sal_False ) );
450 if( !mbPrintable )
451 xSet->setPropertyValue( rtl::OUString( "Printable" ), uno::Any( sal_False ) );
453 catch(const Exception&)
455 OSL_FAIL( "SdXMLShapeContext::AddShape(), exception caught!" );
458 // #107848#
459 if(!mbTemporaryShape && (!GetImport().HasTextImport()
460 || !GetImport().GetTextImport()->IsInsideDeleteContext()))
462 xImp->shapeWithZIndexAdded( xShape, mnZOrder );
465 if( !maShapeId.isEmpty() )
467 uno::Reference< uno::XInterface > xRef( static_cast<uno::XInterface *>(xShape.get()) );
468 GetImport().getInterfaceToIdentifierMapper().registerReference( maShapeId, xRef );
471 // #91065# count only if counting for shape import is enabled
472 if(GetImport().GetShapeImport()->IsHandleProgressBarEnabled())
474 // #80365# increment progress bar at load once for each draw object
475 GetImport().GetProgressBarHelper()->Increment();
479 mxLockable = uno::Reference< document::XActionLockable >::query( xShape );
481 if( mxLockable.is() )
482 mxLockable->addActionLock();
486 //////////////////////////////////////////////////////////////////////////////
488 void SdXMLShapeContext::AddShape(const char* pServiceName )
490 uno::Reference< lang::XMultiServiceFactory > xServiceFact(GetImport().GetModel(), uno::UNO_QUERY);
491 if(xServiceFact.is())
495 /* Since fix for issue i33294 the Writer model doesn't support
496 com.sun.star.drawing.OLE2Shape anymore.
497 To handle Draw OLE objects it's decided to import these
498 objects as com.sun.star.drawing.OLE2Shape and convert these
499 objects after the import into com.sun.star.drawing.GraphicObjectShape.
501 uno::Reference< drawing::XShape > xShape;
502 if ( OUString::createFromAscii(pServiceName).compareToAscii( "com.sun.star.drawing.OLE2Shape" ) == 0 &&
503 uno::Reference< text::XTextDocument >(GetImport().GetModel(), uno::UNO_QUERY).is() )
505 xShape = uno::Reference< drawing::XShape >(xServiceFact->createInstance(OUString("com.sun.star.drawing.temporaryForXMLImportOLE2Shape")), uno::UNO_QUERY);
507 else
509 xShape = uno::Reference< drawing::XShape >(xServiceFact->createInstance(OUString::createFromAscii(pServiceName)), uno::UNO_QUERY);
511 if( xShape.is() )
512 AddShape( xShape );
514 catch(const uno::Exception& e)
516 uno::Sequence<rtl::OUString> aSeq( 1 );
517 aSeq[0] = OUString::createFromAscii(pServiceName);
518 GetImport().SetError( XMLERROR_FLAG_ERROR | XMLERROR_API,
519 aSeq, e.Message, NULL );
524 //////////////////////////////////////////////////////////////////////////////
526 void SdXMLShapeContext::SetTransformation()
528 if(mxShape.is())
530 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
531 if(xPropSet.is())
533 ::basegfx::B2DHomMatrix aTransformation;
535 if(maSize.Width != 1 || maSize.Height != 1)
537 // take care there are no zeros used by error
538 if(0 == maSize.Width)
539 maSize.Width = 1;
540 if(0 == maSize.Height)
541 maSize.Height = 1;
543 // set global size. This should always be used.
544 aTransformation.scale(maSize.Width, maSize.Height);
547 if(maPosition.X != 0 || maPosition.Y != 0)
549 // if global position is used, add it to transformation
550 aTransformation.translate(maPosition.X, maPosition.Y);
553 if(mnTransform.NeedsAction())
555 // transformation is used, apply to object.
556 // NOTICE: The transformation is applied AFTER evtl. used
557 // global positioning and scaling is used, so any shear or
558 // rotate used herein is applied around the (0,0) position
559 // of the PAGE object !!!
560 ::basegfx::B2DHomMatrix aMat;
561 mnTransform.GetFullTransform(aMat);
563 // now add to transformation
564 aTransformation *= aMat;
567 // now set transformation for this object
568 uno::Any aAny;
569 drawing::HomogenMatrix3 aMatrix;
571 aMatrix.Line1.Column1 = aTransformation.get(0, 0);
572 aMatrix.Line1.Column2 = aTransformation.get(0, 1);
573 aMatrix.Line1.Column3 = aTransformation.get(0, 2);
575 aMatrix.Line2.Column1 = aTransformation.get(1, 0);
576 aMatrix.Line2.Column2 = aTransformation.get(1, 1);
577 aMatrix.Line2.Column3 = aTransformation.get(1, 2);
579 aMatrix.Line3.Column1 = aTransformation.get(2, 0);
580 aMatrix.Line3.Column2 = aTransformation.get(2, 1);
581 aMatrix.Line3.Column3 = aTransformation.get(2, 2);
583 aAny <<= aMatrix;
585 xPropSet->setPropertyValue(
586 OUString("Transformation"), aAny);
591 //////////////////////////////////////////////////////////////////////////////
593 void SdXMLShapeContext::SetStyle( bool bSupportsStyle /* = true */)
597 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
598 if( !xPropSet.is() )
599 return;
603 XMLPropStyleContext* pDocStyle = NULL;
605 // set style on shape
606 if(maDrawStyleName.isEmpty())
607 break;
609 const SvXMLStyleContext* pStyle = 0L;
610 sal_Bool bAutoStyle(sal_False);
612 if(GetImport().GetShapeImport()->GetAutoStylesContext())
613 pStyle = GetImport().GetShapeImport()->GetAutoStylesContext()->FindStyleChildContext(mnStyleFamily, maDrawStyleName);
615 if(pStyle)
616 bAutoStyle = sal_True;
618 if(!pStyle && GetImport().GetShapeImport()->GetStylesContext())
619 pStyle = GetImport().GetShapeImport()->GetStylesContext()->FindStyleChildContext(mnStyleFamily, maDrawStyleName);
621 OUString aStyleName = maDrawStyleName;
622 uno::Reference< style::XStyle > xStyle;
624 if( pStyle && pStyle->ISA(XMLShapeStyleContext) )
626 pDocStyle = PTR_CAST( XMLShapeStyleContext, pStyle );
628 if( pDocStyle->GetStyle().is() )
630 xStyle = pDocStyle->GetStyle();
632 else
634 aStyleName = pDocStyle->GetParentName();
638 if( !xStyle.is() && !aStyleName.isEmpty() )
643 uno::Reference< style::XStyleFamiliesSupplier > xFamiliesSupplier( GetImport().GetModel(), uno::UNO_QUERY );
645 if( xFamiliesSupplier.is() )
647 uno::Reference< container::XNameAccess > xFamilies( xFamiliesSupplier->getStyleFamilies() );
648 if( xFamilies.is() )
651 uno::Reference< container::XNameAccess > xFamily;
653 if( XML_STYLE_FAMILY_SD_PRESENTATION_ID == mnStyleFamily )
655 aStyleName = GetImport().GetStyleDisplayName(
656 XML_STYLE_FAMILY_SD_PRESENTATION_ID,
657 aStyleName );
658 sal_Int32 nPos = aStyleName.lastIndexOf( sal_Unicode('-') );
659 if( -1 != nPos )
661 OUString aFamily( aStyleName.copy( 0, nPos ) );
663 xFamilies->getByName( aFamily ) >>= xFamily;
664 aStyleName = aStyleName.copy( nPos + 1 );
667 else
669 // get graphics familie
670 xFamilies->getByName( OUString( "graphics" ) ) >>= xFamily;
671 aStyleName = GetImport().GetStyleDisplayName(
672 XML_STYLE_FAMILY_SD_GRAPHICS_ID,
673 aStyleName );
676 if( xFamily.is() )
677 xFamily->getByName( aStyleName ) >>= xStyle;
681 catch(const uno::Exception&)
683 OSL_FAIL( "could not find style for shape!" );
687 if( bSupportsStyle && xStyle.is() )
691 // set style on object
692 uno::Any aAny;
693 aAny <<= xStyle;
694 xPropSet->setPropertyValue(OUString("Style"), aAny);
696 catch(const uno::Exception&)
698 OSL_FAIL( "could not find style for shape!" );
702 // if this is an auto style, set its properties
703 if(bAutoStyle && pDocStyle)
705 // set PropertySet on object
706 pDocStyle->FillPropertySet(xPropSet);
709 } while(0);
711 // try to set text auto style
714 // set style on shape
715 if( maTextStyleName.isEmpty() )
716 break;
718 if( NULL == GetImport().GetShapeImport()->GetAutoStylesContext())
719 break;
721 const SvXMLStyleContext* pTempStyle = GetImport().GetShapeImport()->GetAutoStylesContext()->FindStyleChildContext(XML_STYLE_FAMILY_TEXT_PARAGRAPH, maTextStyleName);
722 XMLPropStyleContext* pStyle = PTR_CAST( XMLPropStyleContext, pTempStyle ); // use temp var, PTR_CAST is a bad macro, FindStyleChildContext will be called twice
723 if( pStyle == NULL )
724 break;
726 // set PropertySet on object
727 pStyle->FillPropertySet(xPropSet);
729 } while(0);
731 catch(const uno::Exception&)
736 void SdXMLShapeContext::SetLayer()
738 if( !maLayerName.isEmpty() )
742 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
743 if(xPropSet.is() )
745 uno::Any aAny;
746 aAny <<= maLayerName;
748 xPropSet->setPropertyValue(OUString("LayerName"), aAny);
749 return;
752 catch(const uno::Exception&)
758 void SdXMLShapeContext::SetThumbnail()
760 if( maThumbnailURL.isEmpty() )
761 return;
765 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
766 if( !xPropSet.is() )
767 return;
769 const OUString sProperty("ThumbnailGraphicURL");
771 uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xPropSet->getPropertySetInfo() );
772 if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName( sProperty ) )
774 // load the thumbnail graphic and export it to a wmf stream so we can set
775 // it at the api
777 const OUString aInternalURL( GetImport().ResolveGraphicObjectURL( maThumbnailURL, sal_False ) );
778 xPropSet->setPropertyValue( sProperty, uno::makeAny( aInternalURL ) );
781 catch(const uno::Exception&)
786 // this is called from the parent group for each unparsed attribute in the attribute list
787 void SdXMLShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
789 bool bHaveXmlId( false );
790 if( (XML_NAMESPACE_DRAW == nPrefix) || (XML_NAMESPACE_DRAW_EXT == nPrefix) )
792 if( IsXMLToken( rLocalName, XML_ZINDEX ) )
794 mnZOrder = rValue.toInt32();
796 else if( IsXMLToken( rLocalName, XML_ID ) )
798 if (!bHaveXmlId) { maShapeId = rValue; };
800 else if( IsXMLToken( rLocalName, XML_NAME ) )
802 maShapeName = rValue;
804 else if( IsXMLToken( rLocalName, XML_STYLE_NAME ) )
806 maDrawStyleName = rValue;
808 else if( IsXMLToken( rLocalName, XML_TEXT_STYLE_NAME ) )
810 maTextStyleName = rValue;
812 else if( IsXMLToken( rLocalName, XML_LAYER ) )
814 maLayerName = rValue;
816 else if( IsXMLToken( rLocalName, XML_TRANSFORM ) )
818 mnTransform.SetString(rValue, GetImport().GetMM100UnitConverter());
820 else if( IsXMLToken( rLocalName, XML_DISPLAY ) )
822 mbVisible = IsXMLToken( rValue, XML_ALWAYS ) || IsXMLToken( rValue, XML_SCREEN );
823 mbPrintable = IsXMLToken( rValue, XML_ALWAYS ) || IsXMLToken( rValue, XML_PRINTER );
826 else if( XML_NAMESPACE_PRESENTATION == nPrefix )
828 if( IsXMLToken( rLocalName, XML_USER_TRANSFORMED ) )
830 mbIsUserTransformed = IsXMLToken( rValue, XML_TRUE );
832 else if( IsXMLToken( rLocalName, XML_PLACEHOLDER ) )
834 mbIsPlaceholder = IsXMLToken( rValue, XML_TRUE );
835 if( mbIsPlaceholder )
836 mbClearDefaultAttributes = false;
838 else if( IsXMLToken( rLocalName, XML_CLASS ) )
840 maPresentationClass = rValue;
842 else if( IsXMLToken( rLocalName, XML_STYLE_NAME ) )
844 maDrawStyleName = rValue;
845 mnStyleFamily = XML_STYLE_FAMILY_SD_PRESENTATION_ID;
848 else if( XML_NAMESPACE_SVG == nPrefix )
850 if( IsXMLToken( rLocalName, XML_X ) )
852 GetImport().GetMM100UnitConverter().convertMeasureToCore(
853 maPosition.X, rValue);
855 else if( IsXMLToken( rLocalName, XML_Y ) )
857 GetImport().GetMM100UnitConverter().convertMeasureToCore(
858 maPosition.Y, rValue);
860 else if( IsXMLToken( rLocalName, XML_WIDTH ) )
862 GetImport().GetMM100UnitConverter().convertMeasureToCore(
863 maSize.Width, rValue);
864 if( maSize.Width > 0 )
865 maSize.Width += 1;
866 else if( maSize.Width < 0 )
867 maSize.Width -= 1;
869 else if( IsXMLToken( rLocalName, XML_HEIGHT ) )
871 GetImport().GetMM100UnitConverter().convertMeasureToCore(
872 maSize.Height, rValue);
873 if( maSize.Height > 0 )
874 maSize.Height += 1;
875 else if( maSize.Height < 0 )
876 maSize.Height -= 1;
878 else if( IsXMLToken( rLocalName, XML_TRANSFORM ) )
880 // because of #85127# take svg:transform into account and hanle like
881 // draw:transform for compatibility
882 mnTransform.SetString(rValue, GetImport().GetMM100UnitConverter());
885 // #i68101#
886 else if( IsXMLToken( rLocalName, XML_TITLE ) )
888 maShapeTitle = rValue;
890 else if( IsXMLToken( rLocalName, XML_DESC ) )
892 maShapeDescription = rValue;
895 else if( (XML_NAMESPACE_NONE == nPrefix) || (XML_NAMESPACE_XML == nPrefix) )
897 if( IsXMLToken( rLocalName, XML_ID ) )
899 maShapeId = rValue;
900 bHaveXmlId = true;
905 sal_Bool SdXMLShapeContext::isPresentationShape() const
907 if( !maPresentationClass.isEmpty() && (const_cast<SdXMLShapeContext*>(this))->GetImport().GetShapeImport()->IsPresentationShapesSupported() )
909 if(XML_STYLE_FAMILY_SD_PRESENTATION_ID == mnStyleFamily)
911 return sal_True;
914 if( IsXMLToken( maPresentationClass, XML_HEADER ) || IsXMLToken( maPresentationClass, XML_FOOTER ) ||
915 IsXMLToken( maPresentationClass, XML_PAGE_NUMBER ) || IsXMLToken( maPresentationClass, XML_DATE_TIME ) )
917 return sal_True;
921 return sal_False;
924 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
925 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
927 TYPEINIT1( SdXMLRectShapeContext, SdXMLShapeContext );
929 SdXMLRectShapeContext::SdXMLRectShapeContext(
930 SvXMLImport& rImport,
931 sal_uInt16 nPrfx,
932 const OUString& rLocalName,
933 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
934 uno::Reference< drawing::XShapes >& rShapes,
935 sal_Bool bTemporaryShape)
936 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
937 mnRadius( 0L )
941 //////////////////////////////////////////////////////////////////////////////
943 SdXMLRectShapeContext::~SdXMLRectShapeContext()
947 //////////////////////////////////////////////////////////////////////////////
949 // this is called from the parent group for each unparsed attribute in the attribute list
950 void SdXMLRectShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
952 if( XML_NAMESPACE_DRAW == nPrefix )
954 if( IsXMLToken( rLocalName, XML_CORNER_RADIUS ) )
956 GetImport().GetMM100UnitConverter().convertMeasureToCore(
957 mnRadius, rValue);
958 return;
962 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
965 //////////////////////////////////////////////////////////////////////////////
967 void SdXMLRectShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
969 // create rectangle shape
970 AddShape("com.sun.star.drawing.RectangleShape");
971 if(mxShape.is())
973 // Add, set Style and properties from base shape
974 SetStyle();
975 SetLayer();
977 // set pos, size, shear and rotate
978 SetTransformation();
980 if(mnRadius)
982 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
983 if(xPropSet.is())
987 xPropSet->setPropertyValue(OUString("CornerRadius"), uno::makeAny( mnRadius ) );
989 catch(const uno::Exception&)
991 OSL_FAIL( "exception during setting of corner radius!");
995 SdXMLShapeContext::StartElement(xAttrList);
999 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1000 ////////////////////////////////////////3////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1002 TYPEINIT1( SdXMLLineShapeContext, SdXMLShapeContext );
1004 SdXMLLineShapeContext::SdXMLLineShapeContext(
1005 SvXMLImport& rImport,
1006 sal_uInt16 nPrfx,
1007 const OUString& rLocalName,
1008 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
1009 uno::Reference< drawing::XShapes >& rShapes,
1010 sal_Bool bTemporaryShape)
1011 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
1012 mnX1( 0L ),
1013 mnY1( 0L ),
1014 mnX2( 1L ),
1015 mnY2( 1L )
1019 //////////////////////////////////////////////////////////////////////////////
1021 SdXMLLineShapeContext::~SdXMLLineShapeContext()
1025 //////////////////////////////////////////////////////////////////////////////
1027 // this is called from the parent group for each unparsed attribute in the attribute list
1028 void SdXMLLineShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
1030 if( XML_NAMESPACE_SVG == nPrefix )
1032 if( IsXMLToken( rLocalName, XML_X1 ) )
1034 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1035 mnX1, rValue);
1036 return;
1038 if( IsXMLToken( rLocalName, XML_Y1 ) )
1040 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1041 mnY1, rValue);
1042 return;
1044 if( IsXMLToken( rLocalName, XML_X2 ) )
1046 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1047 mnX2, rValue);
1048 return;
1050 if( IsXMLToken( rLocalName, XML_Y2 ) )
1052 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1053 mnY2, rValue);
1054 return;
1058 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
1061 //////////////////////////////////////////////////////////////////////////////
1063 void SdXMLLineShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
1065 // #85920# use SetTransformation() to handle import of simple lines.
1066 // This is necessary to kake into account all anchor positions and
1067 // other things. All shape imports use the same import schemata now.
1068 // create necessary shape (Line Shape)
1069 AddShape("com.sun.star.drawing.PolyLineShape");
1071 if(mxShape.is())
1073 // Add, set Style and properties from base shape
1074 SetStyle();
1075 SetLayer();
1077 // get sizes and offsets
1078 awt::Point aTopLeft(mnX1, mnY1);
1079 awt::Point aBottomRight(mnX2, mnY2);
1081 if(mnX1 > mnX2)
1083 aTopLeft.X = mnX2;
1084 aBottomRight.X = mnX1;
1087 if(mnY1 > mnY2)
1089 aTopLeft.Y = mnY2;
1090 aBottomRight.Y = mnY1;
1093 // set local parameters on shape
1094 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
1095 if(xPropSet.is())
1097 drawing::PointSequenceSequence aPolyPoly(1L);
1098 drawing::PointSequence* pOuterSequence = aPolyPoly.getArray();
1099 pOuterSequence->realloc(2L);
1100 awt::Point* pInnerSequence = pOuterSequence->getArray();
1101 uno::Any aAny;
1103 *pInnerSequence = awt::Point( mnX1 - aTopLeft.X, mnY1 - aTopLeft.Y);
1104 pInnerSequence++;
1105 *pInnerSequence = awt::Point( mnX2 - aTopLeft.X, mnY2 - aTopLeft.Y);
1107 aAny <<= aPolyPoly;
1108 xPropSet->setPropertyValue(
1109 OUString("Geometry"), aAny);
1112 // set sizes for transformation
1113 maSize.Width = aBottomRight.X - aTopLeft.X;
1114 maSize.Height = aBottomRight.Y - aTopLeft.Y;
1115 maPosition.X = aTopLeft.X;
1116 maPosition.Y = aTopLeft.Y;
1118 // set pos, size, shear and rotate and get copy of matrix
1119 SetTransformation();
1121 SdXMLShapeContext::StartElement(xAttrList);
1125 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1126 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1128 TYPEINIT1( SdXMLEllipseShapeContext, SdXMLShapeContext );
1130 SdXMLEllipseShapeContext::SdXMLEllipseShapeContext(
1131 SvXMLImport& rImport,
1132 sal_uInt16 nPrfx,
1133 const OUString& rLocalName,
1134 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
1135 uno::Reference< drawing::XShapes >& rShapes,
1136 sal_Bool bTemporaryShape)
1137 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
1138 mnCX( 0L ),
1139 mnCY( 0L ),
1140 mnRX( 1L ),
1141 mnRY( 1L ),
1142 meKind( drawing::CircleKind_FULL ),
1143 mnStartAngle( 0 ),
1144 mnEndAngle( 0 )
1148 //////////////////////////////////////////////////////////////////////////////
1150 SdXMLEllipseShapeContext::~SdXMLEllipseShapeContext()
1154 //////////////////////////////////////////////////////////////////////////////
1156 // this is called from the parent group for each unparsed attribute in the attribute list
1157 void SdXMLEllipseShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
1159 if( XML_NAMESPACE_SVG == nPrefix )
1161 if( IsXMLToken( rLocalName, XML_RX ) )
1163 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1164 mnRX, rValue);
1165 return;
1167 if( IsXMLToken( rLocalName, XML_RY ) )
1169 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1170 mnRY, rValue);
1171 return;
1173 if( IsXMLToken( rLocalName, XML_CX ) )
1175 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1176 mnCX, rValue);
1177 return;
1179 if( IsXMLToken( rLocalName, XML_CY ) )
1181 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1182 mnCY, rValue);
1183 return;
1185 if( IsXMLToken( rLocalName, XML_R ) )
1187 // single radius, it's a circle and both radii are the same
1188 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1189 mnRX, rValue);
1190 mnRY = mnRX;
1191 return;
1194 else if( XML_NAMESPACE_DRAW == nPrefix )
1196 if( IsXMLToken( rLocalName, XML_KIND ) )
1198 sal_uInt16 eKind;
1199 if( SvXMLUnitConverter::convertEnum( eKind, rValue, aXML_CircleKind_EnumMap ) )
1201 meKind = eKind;
1203 return;
1205 if( IsXMLToken( rLocalName, XML_START_ANGLE ) )
1207 double dStartAngle;
1208 if (::sax::Converter::convertDouble( dStartAngle, rValue ))
1209 mnStartAngle = (sal_Int32)(dStartAngle * 100.0);
1210 return;
1212 if( IsXMLToken( rLocalName, XML_END_ANGLE ) )
1214 double dEndAngle;
1215 if (::sax::Converter::convertDouble( dEndAngle, rValue ))
1216 mnEndAngle = (sal_Int32)(dEndAngle * 100.0);
1217 return;
1221 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
1224 //////////////////////////////////////////////////////////////////////////////
1226 void SdXMLEllipseShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
1228 // create rectangle shape
1229 AddShape("com.sun.star.drawing.EllipseShape");
1230 if(mxShape.is())
1232 // Add, set Style and properties from base shape
1233 SetStyle();
1234 SetLayer();
1236 // set pos, size, shear and rotate
1237 SetTransformation();
1239 if( meKind != drawing::CircleKind_FULL )
1241 uno::Reference< beans::XPropertySet > xPropSet( mxShape, uno::UNO_QUERY );
1242 if( xPropSet.is() )
1244 uno::Any aAny;
1245 aAny <<= (drawing::CircleKind)meKind;
1246 xPropSet->setPropertyValue( OUString("CircleKind"), aAny );
1248 aAny <<= mnStartAngle;
1249 xPropSet->setPropertyValue( OUString("CircleStartAngle"), aAny );
1251 aAny <<= mnEndAngle;
1252 xPropSet->setPropertyValue( OUString("CircleEndAngle"), aAny );
1256 SdXMLShapeContext::StartElement(xAttrList);
1260 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1261 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1263 TYPEINIT1( SdXMLPolygonShapeContext, SdXMLShapeContext );
1265 SdXMLPolygonShapeContext::SdXMLPolygonShapeContext(
1266 SvXMLImport& rImport,
1267 sal_uInt16 nPrfx,
1268 const OUString& rLocalName,
1269 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
1270 uno::Reference< drawing::XShapes >& rShapes, sal_Bool bClosed, sal_Bool bTemporaryShape)
1271 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
1272 mbClosed( bClosed )
1276 //////////////////////////////////////////////////////////////////////////////
1278 // this is called from the parent group for each unparsed attribute in the attribute list
1279 void SdXMLPolygonShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
1281 if( XML_NAMESPACE_SVG == nPrefix )
1283 if( IsXMLToken( rLocalName, XML_VIEWBOX ) )
1285 maViewBox = rValue;
1286 return;
1289 else if( XML_NAMESPACE_DRAW == nPrefix )
1291 if( IsXMLToken( rLocalName, XML_POINTS ) )
1293 maPoints = rValue;
1294 return;
1298 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
1301 //////////////////////////////////////////////////////////////////////////////
1303 SdXMLPolygonShapeContext::~SdXMLPolygonShapeContext()
1307 //////////////////////////////////////////////////////////////////////////////
1309 void SdXMLPolygonShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
1311 // Add, set Style and properties from base shape
1312 if(mbClosed)
1313 AddShape("com.sun.star.drawing.PolyPolygonShape");
1314 else
1315 AddShape("com.sun.star.drawing.PolyLineShape");
1317 if( mxShape.is() )
1319 SetStyle();
1320 SetLayer();
1322 // set local parameters on shape
1323 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
1324 if(xPropSet.is())
1326 // set polygon
1327 if(!maPoints.isEmpty() && !maViewBox.isEmpty())
1329 SdXMLImExViewBox aViewBox(maViewBox, GetImport().GetMM100UnitConverter());
1330 awt::Size aSize(aViewBox.GetWidth(), aViewBox.GetHeight());
1331 if (maSize.Width != 0 && maSize.Height !=0)
1333 aSize = maSize;
1335 awt::Point aPosition(aViewBox.GetX(), aViewBox.GetY());
1336 SdXMLImExPointsElement aPoints(maPoints, aViewBox,
1337 aPosition, aSize, GetImport().GetMM100UnitConverter());
1339 uno::Any aAny;
1340 aAny <<= aPoints.GetPointSequenceSequence();
1341 xPropSet->setPropertyValue(
1342 OUString("Geometry"), aAny);
1346 // set pos, size, shear and rotate and get copy of matrix
1347 SetTransformation();
1349 SdXMLShapeContext::StartElement(xAttrList);
1353 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1354 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1356 TYPEINIT1( SdXMLPathShapeContext, SdXMLShapeContext );
1358 SdXMLPathShapeContext::SdXMLPathShapeContext(
1359 SvXMLImport& rImport,
1360 sal_uInt16 nPrfx,
1361 const OUString& rLocalName,
1362 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
1363 uno::Reference< drawing::XShapes >& rShapes,
1364 sal_Bool bTemporaryShape)
1365 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape )
1369 //////////////////////////////////////////////////////////////////////////////
1371 SdXMLPathShapeContext::~SdXMLPathShapeContext()
1375 //////////////////////////////////////////////////////////////////////////////
1377 // this is called from the parent group for each unparsed attribute in the attribute list
1378 void SdXMLPathShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
1380 if( XML_NAMESPACE_SVG == nPrefix )
1382 if( IsXMLToken( rLocalName, XML_VIEWBOX ) )
1384 maViewBox = rValue;
1385 return;
1387 else if( IsXMLToken( rLocalName, XML_D ) )
1389 maD = rValue;
1390 return;
1394 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
1397 //////////////////////////////////////////////////////////////////////////////
1399 void SdXMLPathShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
1401 // create polygon shape
1402 if(!maD.isEmpty())
1404 // prepare some of the parameters
1405 SdXMLImExViewBox aViewBox(maViewBox, GetImport().GetMM100UnitConverter());
1406 awt::Size aSize(aViewBox.GetWidth(), aViewBox.GetHeight());
1407 awt::Point aPosition(aViewBox.GetX(), aViewBox.GetY());
1408 if (maSize.Width != 0 && maSize.Height !=0)
1410 aSize = maSize;
1412 SdXMLImExSvgDElement aPoints(maD, aViewBox, aPosition, aSize, GetImport());
1414 const char* pService;
1415 // now create shape
1416 if(aPoints.IsCurve())
1418 if(aPoints.IsClosed())
1420 pService = "com.sun.star.drawing.ClosedBezierShape";
1422 else
1424 pService = "com.sun.star.drawing.OpenBezierShape";
1427 else
1429 if(aPoints.IsClosed())
1431 pService = "com.sun.star.drawing.PolyPolygonShape";
1433 else
1435 pService = "com.sun.star.drawing.PolyLineShape";
1439 // Add, set Style and properties from base shape
1440 AddShape(pService);
1442 // #89344# test for mxShape.is() and not for mxShapes.is() to support
1443 // shape import helper classes WITHOUT XShapes (member mxShapes). This
1444 // is used by the writer.
1445 if( mxShape.is() )
1447 SetStyle();
1448 SetLayer();
1450 // set local parameters on shape
1451 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
1452 if(xPropSet.is())
1454 uno::Any aAny;
1456 // set svg:d
1457 if(!maD.isEmpty())
1459 if(aPoints.IsCurve())
1461 drawing::PolyPolygonBezierCoords aSourcePolyPolygon(
1462 aPoints.GetPointSequenceSequence(),
1463 aPoints.GetFlagSequenceSequence());
1465 aAny <<= aSourcePolyPolygon;
1466 xPropSet->setPropertyValue(
1467 OUString("Geometry"), aAny);
1469 else
1471 aAny <<= aPoints.GetPointSequenceSequence();
1472 xPropSet->setPropertyValue(
1473 OUString("Geometry"), aAny);
1478 // set pos, size, shear and rotate
1479 SetTransformation();
1481 SdXMLShapeContext::StartElement(xAttrList);
1486 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1487 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1489 TYPEINIT1( SdXMLTextBoxShapeContext, SdXMLShapeContext );
1491 SdXMLTextBoxShapeContext::SdXMLTextBoxShapeContext(
1492 SvXMLImport& rImport,
1493 sal_uInt16 nPrfx,
1494 const OUString& rLocalName,
1495 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
1496 uno::Reference< drawing::XShapes >& rShapes,
1497 sal_Bool bTemporaryShape)
1498 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
1499 mnRadius(0)
1503 //////////////////////////////////////////////////////////////////////////////
1505 SdXMLTextBoxShapeContext::~SdXMLTextBoxShapeContext()
1509 //////////////////////////////////////////////////////////////////////////////
1511 // this is called from the parent group for each unparsed attribute in the attribute list
1512 void SdXMLTextBoxShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
1514 if( XML_NAMESPACE_DRAW == nPrefix )
1516 if( IsXMLToken( rLocalName, XML_CORNER_RADIUS ) )
1518 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1519 mnRadius, rValue);
1520 return;
1524 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
1527 //////////////////////////////////////////////////////////////////////////////
1529 void SdXMLTextBoxShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>&)
1531 // create textbox shape
1532 sal_Bool bIsPresShape = sal_False;
1533 bool bClearText = false;
1535 const char *pService = NULL;
1537 if( isPresentationShape() )
1539 // check if the current document supports presentation shapes
1540 if( GetImport().GetShapeImport()->IsPresentationShapesSupported() )
1542 if( IsXMLToken( maPresentationClass, XML_PRESENTATION_SUBTITLE ))
1544 // XmlShapeTypePresSubtitleShape
1545 pService = "com.sun.star.presentation.SubtitleShape";
1547 else if( IsXMLToken( maPresentationClass, XML_PRESENTATION_OUTLINE ) )
1549 // XmlShapeTypePresOutlinerShape
1550 pService = "com.sun.star.presentation.OutlinerShape";
1552 else if( IsXMLToken( maPresentationClass, XML_PRESENTATION_NOTES ) )
1554 // XmlShapeTypePresNotesShape
1555 pService = "com.sun.star.presentation.NotesShape";
1557 else if( IsXMLToken( maPresentationClass, XML_HEADER ) )
1559 // XmlShapeTypePresHeaderShape
1560 pService = "com.sun.star.presentation.HeaderShape";
1561 bClearText = true;
1563 else if( IsXMLToken( maPresentationClass, XML_FOOTER ) )
1565 // XmlShapeTypePresFooterShape
1566 pService = "com.sun.star.presentation.FooterShape";
1567 bClearText = true;
1569 else if( IsXMLToken( maPresentationClass, XML_PAGE_NUMBER ) )
1571 // XmlShapeTypePresSlideNumberShape
1572 pService = "com.sun.star.presentation.SlideNumberShape";
1573 bClearText = true;
1575 else if( IsXMLToken( maPresentationClass, XML_DATE_TIME ) )
1577 // XmlShapeTypePresDateTimeShape
1578 pService = "com.sun.star.presentation.DateTimeShape";
1579 bClearText = true;
1581 else // IsXMLToken( maPresentationClass, XML_PRESENTATION_TITLE ) )
1583 // XmlShapeTypePresTitleTextShape
1584 pService = "com.sun.star.presentation.TitleTextShape";
1586 bIsPresShape = sal_True;
1590 if( NULL == pService )
1592 // normal text shape
1593 pService = "com.sun.star.drawing.TextShape";
1596 // Add, set Style and properties from base shape
1597 AddShape(pService);
1599 if( mxShape.is() )
1601 SetStyle();
1602 SetLayer();
1604 if(bIsPresShape)
1606 uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY);
1607 if(xProps.is())
1609 uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() );
1610 if( xPropsInfo.is() )
1612 if( !mbIsPlaceholder && xPropsInfo->hasPropertyByName(OUString("IsEmptyPresentationObject" )))
1613 xProps->setPropertyValue( OUString("IsEmptyPresentationObject" ), ::cppu::bool2any( sal_False ) );
1615 if( mbIsUserTransformed && xPropsInfo->hasPropertyByName(OUString("IsPlaceholderDependent" )))
1616 xProps->setPropertyValue( OUString("IsPlaceholderDependent" ), ::cppu::bool2any( sal_False ) );
1621 if( bClearText )
1623 uno::Reference< text::XText > xText( mxShape, uno::UNO_QUERY );
1624 OUString aEmpty;
1625 xText->setString( aEmpty );
1628 // set parameters on shape
1629 //A AW->CL: Eventually You need to strip scale and translate from the transformation
1630 //A to reach the same goal again.
1631 //A if(!bIsPresShape || mbIsUserTransformed)
1632 //A {
1633 //A // set pos and size on shape, this should remove binding
1634 //A // to pres object on masterpage
1635 //A SetSizeAndPosition();
1636 //A }
1638 // set pos, size, shear and rotate
1639 SetTransformation();
1641 if(mnRadius)
1643 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
1644 if(xPropSet.is())
1648 xPropSet->setPropertyValue(OUString("CornerRadius"), uno::makeAny( mnRadius ) );
1650 catch(const uno::Exception&)
1652 OSL_FAIL( "exception during setting of corner radius!");
1657 SdXMLShapeContext::StartElement(mxAttrList);
1661 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1662 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1664 TYPEINIT1( SdXMLControlShapeContext, SdXMLShapeContext );
1666 SdXMLControlShapeContext::SdXMLControlShapeContext(
1667 SvXMLImport& rImport,
1668 sal_uInt16 nPrfx,
1669 const OUString& rLocalName,
1670 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
1671 uno::Reference< drawing::XShapes >& rShapes,
1672 sal_Bool bTemporaryShape)
1673 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape )
1677 //////////////////////////////////////////////////////////////////////////////
1679 SdXMLControlShapeContext::~SdXMLControlShapeContext()
1683 //////////////////////////////////////////////////////////////////////////////
1685 // this is called from the parent group for each unparsed attribute in the attribute list
1686 void SdXMLControlShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
1688 if( XML_NAMESPACE_DRAW == nPrefix )
1690 if( IsXMLToken( rLocalName, XML_CONTROL ) )
1692 maFormId = rValue;
1693 return;
1697 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
1700 void SdXMLControlShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
1702 // create Control shape
1703 // add, set style and properties from base shape
1704 AddShape("com.sun.star.drawing.ControlShape");
1705 if( mxShape.is() )
1707 DBG_ASSERT( !maFormId.isEmpty(), "draw:control without a form:id attribute!" );
1708 if( !maFormId.isEmpty() )
1710 if( GetImport().IsFormsSupported() )
1712 uno::Reference< awt::XControlModel > xControlModel( GetImport().GetFormImport()->lookupControl( maFormId ), uno::UNO_QUERY );
1713 if( xControlModel.is() )
1715 uno::Reference< drawing::XControlShape > xControl( mxShape, uno::UNO_QUERY );
1716 if( xControl.is() )
1717 xControl->setControl( xControlModel );
1723 SetStyle();
1724 SetLayer();
1726 // set pos, size, shear and rotate
1727 SetTransformation();
1729 SdXMLShapeContext::StartElement(xAttrList);
1733 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1734 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1736 TYPEINIT1( SdXMLConnectorShapeContext, SdXMLShapeContext );
1738 SdXMLConnectorShapeContext::SdXMLConnectorShapeContext(
1739 SvXMLImport& rImport,
1740 sal_uInt16 nPrfx,
1741 const OUString& rLocalName,
1742 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
1743 uno::Reference< drawing::XShapes >& rShapes,
1744 sal_Bool bTemporaryShape)
1745 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
1746 maStart(0,0),
1747 maEnd(1,1),
1748 mnType( (sal_uInt16)drawing::ConnectorType_STANDARD ),
1749 mnStartGlueId(-1),
1750 mnEndGlueId(-1),
1751 mnDelta1(0),
1752 mnDelta2(0),
1753 mnDelta3(0)
1757 //////////////////////////////////////////////////////////////////////////////
1759 SdXMLConnectorShapeContext::~SdXMLConnectorShapeContext()
1763 //////////////////////////////////////////////////////////////////////////////
1765 // this is called from the parent group for each unparsed attribute in the attribute list
1766 void SdXMLConnectorShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
1768 switch( nPrefix )
1770 case XML_NAMESPACE_DRAW:
1772 if( IsXMLToken( rLocalName, XML_START_SHAPE ) )
1774 maStartShapeId = rValue;
1775 return;
1777 if( IsXMLToken( rLocalName, XML_START_GLUE_POINT ) )
1779 mnStartGlueId = rValue.toInt32();
1780 return;
1782 if( IsXMLToken( rLocalName, XML_END_SHAPE ) )
1784 maEndShapeId = rValue;
1785 return;
1787 if( IsXMLToken( rLocalName, XML_END_GLUE_POINT ) )
1789 mnEndGlueId = rValue.toInt32();
1790 return;
1792 if( IsXMLToken( rLocalName, XML_LINE_SKEW ) )
1794 SvXMLTokenEnumerator aTokenEnum( rValue );
1795 OUString aToken;
1796 if( aTokenEnum.getNextToken( aToken ) )
1798 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1799 mnDelta1, aToken);
1800 if( aTokenEnum.getNextToken( aToken ) )
1802 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1803 mnDelta2, aToken);
1804 if( aTokenEnum.getNextToken( aToken ) )
1806 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1807 mnDelta3, aToken);
1811 return;
1813 if( IsXMLToken( rLocalName, XML_TYPE ) )
1815 SvXMLUnitConverter::convertEnum( mnType, rValue, aXML_ConnectionKind_EnumMap );
1816 return;
1819 case XML_NAMESPACE_SVG:
1821 if( IsXMLToken( rLocalName, XML_X1 ) )
1823 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1824 maStart.X, rValue);
1825 return;
1827 if( IsXMLToken( rLocalName, XML_Y1 ) )
1829 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1830 maStart.Y, rValue);
1831 return;
1833 if( IsXMLToken( rLocalName, XML_X2 ) )
1835 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1836 maEnd.X, rValue);
1837 return;
1839 if( IsXMLToken( rLocalName, XML_Y2 ) )
1841 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1842 maEnd.Y, rValue);
1843 return;
1845 if( IsXMLToken( rLocalName, XML_D ) )
1847 SdXMLImExViewBox aViewBox( 0, 0, 1, 1 );
1848 awt::Point aPoint( 0, 0 );
1849 awt::Size aSize( 1, 1 );
1851 SdXMLImExSvgDElement aPoints( rValue, aViewBox, aPoint, aSize, GetImport() );
1853 if ( aPoints.IsCurve() )
1855 drawing::PolyPolygonBezierCoords aSourcePolyPolygon(
1856 aPoints.GetPointSequenceSequence(),
1857 aPoints.GetFlagSequenceSequence());
1858 maPath <<= aSourcePolyPolygon;
1860 else
1862 const drawing::PointSequenceSequence& rOuterSeq = aPoints.GetPointSequenceSequence();
1863 drawing::FlagSequenceSequence aFlagSeqSeq( rOuterSeq.getLength() );
1864 for ( int a = 0; a < rOuterSeq.getLength(); a++ )
1865 aFlagSeqSeq[ a ] = drawing::FlagSequence( rOuterSeq[ a ].getLength() );
1867 drawing::PolyPolygonBezierCoords aSourcePolyPolygon(
1868 aPoints.GetPointSequenceSequence(),
1869 aFlagSeqSeq );
1870 maPath <<= aSourcePolyPolygon;
1876 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
1879 //////////////////////////////////////////////////////////////////////////////
1881 void SdXMLConnectorShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
1883 // #107928#
1884 // For security reasons, do not add empty connectors. There may have been an error in EA2
1885 // that created empty, far set off connectors (e.g. 63 meters below top of document). This
1886 // is not guaranteed, but it's definitely safe to not add empty connectors.
1887 sal_Bool bDoAdd(sal_True);
1889 if( maStartShapeId.isEmpty()
1890 && maEndShapeId.isEmpty()
1891 && maStart.X == maEnd.X
1892 && maStart.Y == maEnd.Y
1893 && 0 == mnDelta1
1894 && 0 == mnDelta2
1895 && 0 == mnDelta3
1898 bDoAdd = sal_False;
1901 if(bDoAdd)
1903 // create Connector shape
1904 // add, set style and properties from base shape
1905 AddShape("com.sun.star.drawing.ConnectorShape");
1906 if(mxShape.is())
1908 // add connection ids
1909 if( !maStartShapeId.isEmpty() )
1910 GetImport().GetShapeImport()->addShapeConnection( mxShape, sal_True, maStartShapeId, mnStartGlueId );
1911 if( !maEndShapeId.isEmpty() )
1912 GetImport().GetShapeImport()->addShapeConnection( mxShape, sal_False, maEndShapeId, mnEndGlueId );
1914 uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY );
1915 if( xProps.is() )
1917 uno::Any aAny;
1918 aAny <<= maStart;
1919 xProps->setPropertyValue(OUString("StartPosition"), aAny);
1921 aAny <<= maEnd;
1922 xProps->setPropertyValue(OUString("EndPosition"), aAny );
1924 aAny <<= (drawing::ConnectorType)mnType;
1925 xProps->setPropertyValue(OUString("EdgeKind"), aAny );
1927 aAny <<= mnDelta1;
1928 xProps->setPropertyValue(OUString("EdgeLine1Delta"), aAny );
1930 aAny <<= mnDelta2;
1931 xProps->setPropertyValue(OUString("EdgeLine2Delta"), aAny );
1933 aAny <<= mnDelta3;
1934 xProps->setPropertyValue(OUString("EdgeLine3Delta"), aAny );
1936 SetStyle();
1937 SetLayer();
1939 if ( maPath.hasValue() )
1941 // #i115492#
1942 // Ignore svg:d attribute for text documents created by OpenOffice.org
1943 // versions before OOo 3.3, because these OOo versions are storing
1944 // svg:d values not using the correct unit.
1945 bool bApplySVGD( true );
1946 if ( uno::Reference< text::XTextDocument >(GetImport().GetModel(), uno::UNO_QUERY).is() )
1948 sal_Int32 nUPD( 0 );
1949 sal_Int32 nBuild( 0 );
1950 const bool bBuildIdFound = GetImport().getBuildIds( nUPD, nBuild );
1951 if ( GetImport().IsTextDocInOOoFileFormat() ||
1952 ( bBuildIdFound &&
1953 ( ( nUPD == 641 ) || ( nUPD == 645 ) || // prior OOo 2.0
1954 ( nUPD == 680 ) || // OOo 2.x
1955 ( nUPD == 300 ) || // OOo 3.0 - OOo 3.0.1
1956 ( nUPD == 310 ) || // OOo 3.1 - OOo 3.1.1
1957 ( nUPD == 320 ) ) ) ) // OOo 3.2 - OOo 3.2.1
1959 bApplySVGD = false;
1963 if ( bApplySVGD )
1965 xProps->setPropertyValue( OUString("PolyPolygonBezier" ), maPath );
1969 SdXMLShapeContext::StartElement(xAttrList);
1974 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1975 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1977 TYPEINIT1( SdXMLMeasureShapeContext, SdXMLShapeContext );
1979 SdXMLMeasureShapeContext::SdXMLMeasureShapeContext(
1980 SvXMLImport& rImport,
1981 sal_uInt16 nPrfx,
1982 const OUString& rLocalName,
1983 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
1984 uno::Reference< drawing::XShapes >& rShapes,
1985 sal_Bool bTemporaryShape)
1986 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
1987 maStart(0,0),
1988 maEnd(1,1)
1992 //////////////////////////////////////////////////////////////////////////////
1994 SdXMLMeasureShapeContext::~SdXMLMeasureShapeContext()
1998 // this is called from the parent group for each unparsed attribute in the attribute list
1999 void SdXMLMeasureShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
2001 switch( nPrefix )
2003 case XML_NAMESPACE_SVG:
2005 if( IsXMLToken( rLocalName, XML_X1 ) )
2007 GetImport().GetMM100UnitConverter().convertMeasureToCore(
2008 maStart.X, rValue);
2009 return;
2011 if( IsXMLToken( rLocalName, XML_Y1 ) )
2013 GetImport().GetMM100UnitConverter().convertMeasureToCore(
2014 maStart.Y, rValue);
2015 return;
2017 if( IsXMLToken( rLocalName, XML_X2 ) )
2019 GetImport().GetMM100UnitConverter().convertMeasureToCore(
2020 maEnd.X, rValue);
2021 return;
2023 if( IsXMLToken( rLocalName, XML_Y2 ) )
2025 GetImport().GetMM100UnitConverter().convertMeasureToCore(
2026 maEnd.Y, rValue);
2027 return;
2032 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
2035 //////////////////////////////////////////////////////////////////////////////
2037 void SdXMLMeasureShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
2039 // create Measure shape
2040 // add, set style and properties from base shape
2041 AddShape("com.sun.star.drawing.MeasureShape");
2042 if(mxShape.is())
2044 SetStyle();
2045 SetLayer();
2047 uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY );
2048 if( xProps.is() )
2050 uno::Any aAny;
2051 aAny <<= maStart;
2052 xProps->setPropertyValue(OUString("StartPosition"), aAny);
2054 aAny <<= maEnd;
2055 xProps->setPropertyValue(OUString("EndPosition"), aAny );
2058 // delete pre created fields
2059 uno::Reference< text::XText > xText( mxShape, uno::UNO_QUERY );
2060 if( xText.is() )
2062 const OUString aEmpty( " " );
2063 xText->setString( aEmpty );
2066 SdXMLShapeContext::StartElement(xAttrList);
2070 void SdXMLMeasureShapeContext::EndElement()
2074 // delete pre created fields
2075 uno::Reference< text::XText > xText( mxShape, uno::UNO_QUERY );
2076 if( !xText.is() )
2077 break;
2079 uno::Reference< text::XTextCursor > xCursor( xText->createTextCursor() );
2080 if( !xCursor.is() )
2081 break;
2083 const OUString aEmpty;
2084 xCursor->collapseToStart();
2085 xCursor->goRight( 1, sal_True );
2086 xCursor->setString( aEmpty );
2088 while(0);
2090 SdXMLShapeContext::EndElement();
2093 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2094 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2096 TYPEINIT1( SdXMLPageShapeContext, SdXMLShapeContext );
2098 SdXMLPageShapeContext::SdXMLPageShapeContext(
2099 SvXMLImport& rImport,
2100 sal_uInt16 nPrfx,
2101 const OUString& rLocalName,
2102 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
2103 uno::Reference< drawing::XShapes >& rShapes,
2104 sal_Bool bTemporaryShape)
2105 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ), mnPageNumber(0)
2107 mbClearDefaultAttributes = false;
2110 //////////////////////////////////////////////////////////////////////////////
2112 SdXMLPageShapeContext::~SdXMLPageShapeContext()
2116 //////////////////////////////////////////////////////////////////////////////
2118 // this is called from the parent group for each unparsed attribute in the attribute list
2119 void SdXMLPageShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
2121 if( XML_NAMESPACE_DRAW == nPrefix )
2123 if( IsXMLToken( rLocalName, XML_PAGE_NUMBER ) )
2125 mnPageNumber = rValue.toInt32();
2126 return;
2130 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
2133 //////////////////////////////////////////////////////////////////////////////
2135 void SdXMLPageShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
2137 // create Page shape
2138 // add, set style and properties from base shape
2140 // #86163# take into account which type of PageShape needs to
2141 // be constructed. It's an pres shape if presentation:XML_CLASS == XML_PRESENTATION_PAGE.
2142 sal_Bool bIsPresentation = !maPresentationClass.isEmpty() &&
2143 GetImport().GetShapeImport()->IsPresentationShapesSupported();
2145 uno::Reference< lang::XServiceInfo > xInfo( mxShapes, uno::UNO_QUERY );
2146 const sal_Bool bIsOnHandoutPage = xInfo.is() && xInfo->supportsService( OUString( "com.sun.star.presentation.HandoutMasterPage") );
2148 if( bIsOnHandoutPage )
2150 AddShape("com.sun.star.presentation.HandoutShape");
2152 else
2154 if(bIsPresentation && !IsXMLToken( maPresentationClass, XML_PRESENTATION_PAGE ) )
2156 bIsPresentation = sal_False;
2159 if(bIsPresentation)
2161 AddShape("com.sun.star.presentation.PageShape");
2163 else
2165 AddShape("com.sun.star.drawing.PageShape");
2169 if(mxShape.is())
2171 SetStyle();
2172 SetLayer();
2174 // set pos, size, shear and rotate
2175 SetTransformation();
2177 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
2178 if(xPropSet.is())
2180 uno::Reference< beans::XPropertySetInfo > xPropSetInfo( xPropSet->getPropertySetInfo() );
2181 const OUString aPageNumberStr("PageNumber");
2182 if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName(aPageNumberStr))
2183 xPropSet->setPropertyValue(aPageNumberStr, uno::makeAny( mnPageNumber ));
2186 SdXMLShapeContext::StartElement(xAttrList);
2190 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2191 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2193 TYPEINIT1( SdXMLCaptionShapeContext, SdXMLShapeContext );
2195 SdXMLCaptionShapeContext::SdXMLCaptionShapeContext(
2196 SvXMLImport& rImport,
2197 sal_uInt16 nPrfx,
2198 const OUString& rLocalName,
2199 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
2200 uno::Reference< drawing::XShapes >& rShapes,
2201 sal_Bool bTemporaryShape)
2202 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
2203 // #86616# for correct edge rounding import mnRadius needs to be initialized
2204 mnRadius( 0L )
2208 //////////////////////////////////////////////////////////////////////////////
2210 SdXMLCaptionShapeContext::~SdXMLCaptionShapeContext()
2214 //////////////////////////////////////////////////////////////////////////////
2216 void SdXMLCaptionShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
2218 // create Caption shape
2219 // add, set style and properties from base shape
2220 AddShape("com.sun.star.drawing.CaptionShape");
2221 if( mxShape.is() )
2223 SetStyle();
2224 SetLayer();
2226 uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY );
2228 // SJ: If AutoGrowWidthItem is set, SetTransformation will lead to the wrong SnapRect
2229 // because NbcAdjustTextFrameWidthAndHeight() is called (text is set later and center alignment
2230 // is the default setting, so the top left reference point that is used by the caption point is
2231 // no longer correct) There are two ways to solve this problem, temporarily disabling the
2232 // autogrowwith as we are doing here or to apply the CaptionPoint after setting text
2233 sal_Bool bIsAutoGrowWidth = sal_False;
2234 if ( xProps.is() )
2236 uno::Any aAny( xProps->getPropertyValue( OUString("TextAutoGrowWidth" ) ) );
2237 aAny >>= bIsAutoGrowWidth;
2239 if ( bIsAutoGrowWidth )
2240 xProps->setPropertyValue( OUString("TextAutoGrowWidth"), uno::makeAny( sal_False ) );
2243 // set pos, size, shear and rotate
2244 SetTransformation();
2245 if( xProps.is() )
2246 xProps->setPropertyValue(OUString("CaptionPoint"), uno::makeAny( maCaptionPoint ) );
2248 if ( bIsAutoGrowWidth )
2249 xProps->setPropertyValue( OUString("TextAutoGrowWidth"), uno::makeAny( sal_True ) );
2251 if(mnRadius)
2253 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
2254 if(xPropSet.is())
2258 xPropSet->setPropertyValue(OUString("CornerRadius"), uno::makeAny( mnRadius ) );
2260 catch(const uno::Exception&)
2262 OSL_FAIL( "exception during setting of corner radius!");
2267 SdXMLShapeContext::StartElement(xAttrList);
2271 // this is called from the parent group for each unparsed attribute in the attribute list
2272 void SdXMLCaptionShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
2274 if( XML_NAMESPACE_DRAW == nPrefix )
2276 if( IsXMLToken( rLocalName, XML_CAPTION_POINT_X ) )
2278 GetImport().GetMM100UnitConverter().convertMeasureToCore(
2279 maCaptionPoint.X, rValue);
2280 return;
2282 if( IsXMLToken( rLocalName, XML_CAPTION_POINT_Y ) )
2284 GetImport().GetMM100UnitConverter().convertMeasureToCore(
2285 maCaptionPoint.Y, rValue);
2286 return;
2288 if( IsXMLToken( rLocalName, XML_CORNER_RADIUS ) )
2290 GetImport().GetMM100UnitConverter().convertMeasureToCore(
2291 mnRadius, rValue);
2292 return;
2295 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
2298 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2299 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2301 TYPEINIT1( SdXMLGraphicObjectShapeContext, SdXMLShapeContext );
2303 SdXMLGraphicObjectShapeContext::SdXMLGraphicObjectShapeContext(
2304 SvXMLImport& rImport,
2305 sal_uInt16 nPrfx,
2306 const OUString& rLocalName,
2307 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
2308 uno::Reference< drawing::XShapes >& rShapes,
2309 sal_Bool bTemporaryShape)
2310 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
2311 maURL()
2315 //////////////////////////////////////////////////////////////////////////////
2317 // this is called from the parent group for each unparsed attribute in the attribute list
2318 void SdXMLGraphicObjectShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
2320 if( XML_NAMESPACE_XLINK == nPrefix )
2322 if( IsXMLToken( rLocalName, XML_HREF ) )
2324 maURL = rValue;
2325 return;
2329 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
2332 //////////////////////////////////////////////////////////////////////////////
2334 void SdXMLGraphicObjectShapeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& )
2336 // create graphic object shape
2337 const char *pService;
2339 if( IsXMLToken( maPresentationClass, XML_GRAPHIC ) && GetImport().GetShapeImport()->IsPresentationShapesSupported() )
2341 pService = "com.sun.star.presentation.GraphicObjectShape";
2343 else
2345 pService = "com.sun.star.drawing.GraphicObjectShape";
2348 AddShape( pService );
2350 if(mxShape.is())
2352 SetStyle();
2353 SetLayer();
2355 uno::Reference< beans::XPropertySet > xPropset(mxShape, uno::UNO_QUERY);
2356 if(xPropset.is())
2358 // since OOo 1.x had no line or fill style for graphics, but may create
2359 // documents with them, we have to override them here
2360 sal_Int32 nUPD, nBuildId;
2361 if( GetImport().getBuildIds( nUPD, nBuildId ) && (nUPD == 645) ) try
2363 xPropset->setPropertyValue( OUString("FillStyle"), Any( FillStyle_NONE ) );
2364 xPropset->setPropertyValue( OUString("LineStyle"), Any( LineStyle_NONE ) );
2366 catch(const Exception&)
2370 uno::Reference< beans::XPropertySetInfo > xPropsInfo( xPropset->getPropertySetInfo() );
2371 if( xPropsInfo.is() && xPropsInfo->hasPropertyByName(OUString("IsEmptyPresentationObject" )))
2372 xPropset->setPropertyValue( OUString("IsEmptyPresentationObject" ), ::cppu::bool2any( mbIsPlaceholder ) );
2374 if( !mbIsPlaceholder )
2376 if( !maURL.isEmpty() )
2378 uno::Any aAny;
2379 aAny <<= GetImport().ResolveGraphicObjectURL( maURL, GetImport().isGraphicLoadOnDemandSupported() );
2382 xPropset->setPropertyValue( OUString("GraphicURL" ), aAny );
2383 xPropset->setPropertyValue( OUString("GraphicStreamURL" ), aAny );
2385 catch (const lang::IllegalArgumentException&)
2392 if(mbIsUserTransformed)
2394 uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY);
2395 if(xProps.is())
2397 uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() );
2398 if( xPropsInfo.is() )
2400 if( xPropsInfo->hasPropertyByName(OUString("IsPlaceholderDependent" )))
2401 xProps->setPropertyValue( OUString("IsPlaceholderDependent" ), ::cppu::bool2any( sal_False ) );
2406 // set pos, size, shear and rotate
2407 SetTransformation();
2409 SdXMLShapeContext::StartElement(mxAttrList);
2413 void SdXMLGraphicObjectShapeContext::EndElement()
2415 if( mxBase64Stream.is() )
2417 OUString sURL( GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream ) );
2418 if( !sURL.isEmpty() )
2422 uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY);
2423 if(xProps.is())
2425 const uno::Any aAny( uno::makeAny( sURL ) );
2426 xProps->setPropertyValue( OUString("GraphicURL" ), aAny );
2427 xProps->setPropertyValue( OUString("GraphicStreamURL" ), aAny );
2430 catch (const lang::IllegalArgumentException&)
2436 SdXMLShapeContext::EndElement();
2440 //////////////////////////////////////////////////////////////////////////////
2442 SvXMLImportContext* SdXMLGraphicObjectShapeContext::CreateChildContext(
2443 sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
2444 const uno::Reference<xml::sax::XAttributeList>& xAttrList )
2446 SvXMLImportContext* pContext = NULL;
2448 if( (XML_NAMESPACE_OFFICE == nPrefix) &&
2449 xmloff::token::IsXMLToken( rLocalName, xmloff::token::XML_BINARY_DATA ) )
2451 if( maURL.isEmpty() && !mxBase64Stream.is() )
2453 mxBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
2454 if( mxBase64Stream.is() )
2455 pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
2456 rLocalName, xAttrList,
2457 mxBase64Stream );
2461 // delegate to parent class if no context could be created
2462 if ( NULL == pContext )
2463 pContext = SdXMLShapeContext::CreateChildContext(nPrefix, rLocalName,
2464 xAttrList);
2466 return pContext;
2469 //////////////////////////////////////////////////////////////////////////////
2471 SdXMLGraphicObjectShapeContext::~SdXMLGraphicObjectShapeContext()
2476 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2477 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2479 TYPEINIT1( SdXMLChartShapeContext, SdXMLShapeContext );
2481 SdXMLChartShapeContext::SdXMLChartShapeContext(
2482 SvXMLImport& rImport,
2483 sal_uInt16 nPrfx,
2484 const OUString& rLocalName,
2485 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
2486 uno::Reference< drawing::XShapes >& rShapes,
2487 sal_Bool bTemporaryShape)
2488 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
2489 mpChartContext( NULL )
2493 //////////////////////////////////////////////////////////////////////////////
2495 SdXMLChartShapeContext::~SdXMLChartShapeContext()
2497 if( mpChartContext )
2498 delete mpChartContext;
2501 //////////////////////////////////////////////////////////////////////////////
2503 void SdXMLChartShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>& xAttrList)
2505 const sal_Bool bIsPresentation = isPresentationShape();
2507 AddShape( bIsPresentation ? "com.sun.star.presentation.ChartShape" : "com.sun.star.drawing.OLE2Shape" );
2509 if(mxShape.is())
2511 SetStyle();
2512 SetLayer();
2514 if( !mbIsPlaceholder )
2516 uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY);
2517 if(xProps.is())
2519 uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() );
2520 if( xPropsInfo.is() && xPropsInfo->hasPropertyByName(OUString("IsEmptyPresentationObject" )))
2521 xProps->setPropertyValue( OUString("IsEmptyPresentationObject" ), ::cppu::bool2any( sal_False ) );
2523 uno::Any aAny;
2525 const OUString aCLSID( "12DCAE26-281F-416F-a234-c3086127382e");
2527 aAny <<= aCLSID;
2528 xProps->setPropertyValue( OUString("CLSID" ), aAny );
2530 aAny = xProps->getPropertyValue( OUString("Model" ) );
2531 uno::Reference< frame::XModel > xChartModel;
2532 if( aAny >>= xChartModel )
2534 mpChartContext = GetImport().GetChartImport()->CreateChartContext( GetImport(), XML_NAMESPACE_SVG, GetXMLToken(XML_CHART), xChartModel, xAttrList );
2539 if(mbIsUserTransformed)
2541 uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY);
2542 if(xProps.is())
2544 uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() );
2545 if( xPropsInfo.is() )
2547 if( xPropsInfo->hasPropertyByName(OUString("IsPlaceholderDependent" )))
2548 xProps->setPropertyValue( OUString("IsPlaceholderDependent" ), ::cppu::bool2any( sal_False ) );
2554 // set pos, size, shear and rotate
2555 SetTransformation();
2557 SdXMLShapeContext::StartElement(xAttrList);
2559 if( mpChartContext )
2560 mpChartContext->StartElement( xAttrList );
2564 void SdXMLChartShapeContext::EndElement()
2566 if( mpChartContext )
2567 mpChartContext->EndElement();
2569 SdXMLShapeContext::EndElement();
2572 void SdXMLChartShapeContext::Characters( const ::rtl::OUString& rChars )
2574 if( mpChartContext )
2575 mpChartContext->Characters( rChars );
2578 SvXMLImportContext * SdXMLChartShapeContext::CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
2579 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
2581 if( mpChartContext )
2582 return mpChartContext->CreateChildContext( nPrefix, rLocalName, xAttrList );
2584 return NULL;
2587 //////////////////////////////////////////////////////////////////////////////
2589 TYPEINIT1( SdXMLObjectShapeContext, SdXMLShapeContext );
2591 SdXMLObjectShapeContext::SdXMLObjectShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
2592 const rtl::OUString& rLocalName,
2593 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
2594 com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes,
2595 sal_Bool bTemporaryShape)
2596 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape )
2600 SdXMLObjectShapeContext::~SdXMLObjectShapeContext()
2604 void SdXMLObjectShapeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& )
2606 // #96717# in theorie, if we don't have a url we shouldn't even
2607 // export this ole shape. But practical its to risky right now
2608 // to change this so we better dispose this on load
2609 //if( !mbIsPlaceholder && ImpIsEmptyURL(maHref) )
2610 // return;
2612 // #100592# this BugFix prevents that a shape is created. CL
2613 // is thinking about an alternative.
2614 // #i13140# Check for more than empty string in maHref, there are
2615 // other possibilities that maHref results in empty container
2616 // storage names
2617 if( !(GetImport().getImportFlags() & IMPORT_EMBEDDED) && !mbIsPlaceholder && ImpIsEmptyURL(maHref) )
2618 return;
2620 const char* pService = "com.sun.star.drawing.OLE2Shape";
2622 sal_Bool bIsPresShape = !maPresentationClass.isEmpty() && GetImport().GetShapeImport()->IsPresentationShapesSupported();
2624 if( bIsPresShape )
2626 if( IsXMLToken( maPresentationClass, XML_PRESENTATION_CHART ) )
2628 pService = "com.sun.star.presentation.ChartShape";
2630 else if( IsXMLToken( maPresentationClass, XML_PRESENTATION_TABLE ) )
2632 pService = "com.sun.star.presentation.CalcShape";
2634 else if( IsXMLToken( maPresentationClass, XML_PRESENTATION_OBJECT ) )
2636 pService = "com.sun.star.presentation.OLE2Shape";
2640 AddShape( pService );
2642 if( mxShape.is() )
2644 SetLayer();
2646 if(bIsPresShape)
2648 uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY);
2649 if(xProps.is())
2651 uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() );
2652 if( xPropsInfo.is() )
2654 if( !mbIsPlaceholder && xPropsInfo->hasPropertyByName(OUString("IsEmptyPresentationObject" )))
2655 xProps->setPropertyValue( OUString("IsEmptyPresentationObject" ), ::cppu::bool2any( sal_False ) );
2657 if( mbIsUserTransformed && xPropsInfo->hasPropertyByName(OUString("IsPlaceholderDependent" )))
2658 xProps->setPropertyValue( OUString("IsPlaceholderDependent" ), ::cppu::bool2any( sal_False ) );
2663 if( !mbIsPlaceholder && !maHref.isEmpty() )
2665 uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY );
2667 if( xProps.is() )
2669 OUString aPersistName = GetImport().ResolveEmbeddedObjectURL( maHref, maCLSID );
2671 if ( GetImport().IsPackageURL( maHref ) )
2673 const OUString sURL( "vnd.sun.star.EmbeddedObject:" );
2675 if ( aPersistName.compareTo( sURL, sURL.getLength() ) == 0 )
2676 aPersistName = aPersistName.copy( sURL.getLength() );
2678 xProps->setPropertyValue( OUString( "PersistName" ),
2679 uno::makeAny( aPersistName ) );
2681 else
2683 // this is OOo link object
2684 xProps->setPropertyValue( OUString( "LinkURL" ),
2685 uno::makeAny( aPersistName ) );
2690 // set pos, size, shear and rotate
2691 SetTransformation();
2693 SetStyle();
2695 GetImport().GetShapeImport()->finishShape( mxShape, mxAttrList, mxShapes );
2699 void SdXMLObjectShapeContext::EndElement()
2701 if (GetImport().isGeneratorVersionOlderThan(
2702 SvXMLImport::OOo_34x, SvXMLImport::LO_4x))
2704 // #i118485#
2705 // If it's an old file from us written before OOo3.4, we need to correct
2706 // FillStyle and LineStyle for OLE2 objects. The error was that the old paint
2707 // implementations just ignored added fill/linestyles completely, thus
2708 // those objects need to be corrected to not show blue and hairline which
2709 // always was the default, but would be shown now
2710 uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY);
2712 if( xProps.is() )
2714 xProps->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FillStyle")), uno::makeAny(drawing::FillStyle_NONE));
2715 xProps->setPropertyValue(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LineStyle")), uno::makeAny(drawing::LineStyle_NONE));
2719 // #100592#
2720 if( mxBase64Stream.is() )
2722 OUString aPersistName( GetImport().ResolveEmbeddedObjectURLFromBase64() );
2723 const OUString sURL( "vnd.sun.star.EmbeddedObject:" );
2725 aPersistName = aPersistName.copy( sURL.getLength() );
2727 uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY);
2728 if( xProps.is() )
2729 xProps->setPropertyValue( OUString( "PersistName" ), uno::makeAny( aPersistName ) );
2732 SdXMLShapeContext::EndElement();
2735 // this is called from the parent group for each unparsed attribute in the attribute list
2736 void SdXMLObjectShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
2738 switch( nPrefix )
2740 case XML_NAMESPACE_DRAW:
2741 if( IsXMLToken( rLocalName, XML_CLASS_ID ) )
2743 maCLSID = rValue;
2744 return;
2746 break;
2747 case XML_NAMESPACE_XLINK:
2748 if( IsXMLToken( rLocalName, XML_HREF ) )
2750 maHref = rValue;
2751 return;
2753 break;
2756 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
2759 SvXMLImportContext* SdXMLObjectShapeContext::CreateChildContext(
2760 sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
2761 const uno::Reference<xml::sax::XAttributeList>& xAttrList )
2763 // #100592#
2764 SvXMLImportContext* pContext = NULL;
2766 if((XML_NAMESPACE_OFFICE == nPrefix) && IsXMLToken(rLocalName, XML_BINARY_DATA))
2768 mxBase64Stream = GetImport().GetStreamForEmbeddedObjectURLFromBase64();
2769 if( mxBase64Stream.is() )
2770 pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
2771 rLocalName, xAttrList,
2772 mxBase64Stream );
2774 else if( ((XML_NAMESPACE_OFFICE == nPrefix) && IsXMLToken(rLocalName, XML_DOCUMENT)) ||
2775 ((XML_NAMESPACE_MATH == nPrefix) && IsXMLToken(rLocalName, XML_MATH)) )
2777 XMLEmbeddedObjectImportContext *pEContext =
2778 new XMLEmbeddedObjectImportContext( GetImport(), nPrefix,
2779 rLocalName, xAttrList );
2780 maCLSID = pEContext->GetFilterCLSID();
2781 if( !maCLSID.isEmpty() )
2783 uno::Reference< beans::XPropertySet > xPropSet(mxShape, uno::UNO_QUERY);
2784 if( xPropSet.is() )
2786 xPropSet->setPropertyValue( OUString("CLSID" ), uno::makeAny( maCLSID ) );
2788 uno::Reference< lang::XComponent > xComp;
2789 xPropSet->getPropertyValue( OUString("Model" ) ) >>= xComp;
2790 DBG_ASSERT( xComp.is(), "no xModel for own OLE format" );
2791 pEContext->SetComponent( xComp );
2794 pContext = pEContext;
2797 // delegate to parent class if no context could be created
2798 if(!pContext)
2799 pContext = SdXMLShapeContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
2801 return pContext;
2804 //////////////////////////////////////////////////////////////////////////////
2806 TYPEINIT1( SdXMLAppletShapeContext, SdXMLShapeContext );
2808 SdXMLAppletShapeContext::SdXMLAppletShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
2809 const rtl::OUString& rLocalName,
2810 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
2811 com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes,
2812 sal_Bool bTemporaryShape)
2813 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
2814 mbIsScript( sal_False )
2818 SdXMLAppletShapeContext::~SdXMLAppletShapeContext()
2822 void SdXMLAppletShapeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& )
2824 const char* pService = "com.sun.star.drawing.AppletShape";
2825 AddShape( pService );
2827 if( mxShape.is() )
2829 SetLayer();
2831 // set pos, size, shear and rotate
2832 SetTransformation();
2833 GetImport().GetShapeImport()->finishShape( mxShape, mxAttrList, mxShapes );
2837 // this is called from the parent group for each unparsed attribute in the attribute list
2838 void SdXMLAppletShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
2840 switch( nPrefix )
2842 case XML_NAMESPACE_DRAW:
2843 if( IsXMLToken( rLocalName, XML_APPLET_NAME ) )
2845 maAppletName = rValue;
2846 return;
2848 if( IsXMLToken( rLocalName, XML_CODE ) )
2850 maAppletCode = rValue;
2851 return;
2853 if( IsXMLToken( rLocalName, XML_MAY_SCRIPT ) )
2855 mbIsScript = IsXMLToken( rValue, XML_TRUE );
2856 return;
2858 break;
2859 case XML_NAMESPACE_XLINK:
2860 if( IsXMLToken( rLocalName, XML_HREF ) )
2862 maHref = GetImport().GetAbsoluteReference(rValue);
2863 return;
2865 break;
2868 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
2871 void SdXMLAppletShapeContext::EndElement()
2873 uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY );
2874 if( xProps.is() )
2876 uno::Any aAny;
2878 if ( maSize.Width && maSize.Height )
2880 // the visual area for applet must be set on loading
2881 awt::Rectangle aRect( 0, 0, maSize.Width, maSize.Height );
2882 aAny <<= aRect;
2883 xProps->setPropertyValue( OUString( "VisibleArea" ), aAny );
2886 if( maParams.getLength() )
2888 aAny <<= maParams;
2889 xProps->setPropertyValue( OUString( "AppletCommands" ), aAny );
2892 if( !maHref.isEmpty() )
2894 aAny <<= maHref;
2895 xProps->setPropertyValue( OUString( "AppletCodeBase" ), aAny );
2898 if( !maAppletName.isEmpty() )
2900 aAny <<= maAppletName;
2901 xProps->setPropertyValue( OUString( "AppletName" ), aAny );
2904 if( mbIsScript )
2906 aAny <<= mbIsScript;
2907 xProps->setPropertyValue( OUString( "AppletIsScript" ), aAny );
2911 if( !maAppletCode.isEmpty() )
2913 aAny <<= maAppletCode;
2914 xProps->setPropertyValue( OUString( "AppletCode" ), aAny );
2917 aAny <<= ::rtl::OUString( GetImport().GetDocumentBase() );
2918 xProps->setPropertyValue( OUString( "AppletDocBase" ), aAny );
2920 SetThumbnail();
2923 SdXMLShapeContext::EndElement();
2926 SvXMLImportContext * SdXMLAppletShapeContext::CreateChildContext( sal_uInt16 p_nPrefix, const ::rtl::OUString& rLocalName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
2928 if( p_nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( rLocalName, XML_PARAM ) )
2930 OUString aParamName, aParamValue;
2931 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
2932 // now parse the attribute list and look for draw:name and draw:value
2933 for(sal_Int16 a(0); a < nAttrCount; a++)
2935 const OUString& rAttrName = xAttrList->getNameByIndex(a);
2936 OUString aLocalName;
2937 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName);
2938 const OUString aValue( xAttrList->getValueByIndex(a) );
2940 if( nPrefix == XML_NAMESPACE_DRAW )
2942 if( IsXMLToken( aLocalName, XML_NAME ) )
2944 aParamName = aValue;
2946 else if( IsXMLToken( aLocalName, XML_VALUE ) )
2948 aParamValue = aValue;
2953 if( !aParamName.isEmpty() )
2955 sal_Int32 nIndex = maParams.getLength();
2956 maParams.realloc( nIndex + 1 );
2957 maParams[nIndex].Name = aParamName;
2958 maParams[nIndex].Handle = -1;
2959 maParams[nIndex].Value <<= aParamValue;
2960 maParams[nIndex].State = beans::PropertyState_DIRECT_VALUE;
2963 return new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
2966 return SdXMLShapeContext::CreateChildContext( p_nPrefix, rLocalName, xAttrList );
2969 //////////////////////////////////////////////////////////////////////////////
2971 TYPEINIT1( SdXMLPluginShapeContext, SdXMLShapeContext );
2973 SdXMLPluginShapeContext::SdXMLPluginShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
2974 const rtl::OUString& rLocalName,
2975 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
2976 com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes,
2977 sal_Bool bTemporaryShape) :
2978 SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
2979 mbMedia( false )
2983 SdXMLPluginShapeContext::~SdXMLPluginShapeContext()
2987 void SdXMLPluginShapeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList)
2989 // watch for MimeType attribute to see if we have a media object
2990 for( sal_Int16 n = 0, nAttrCount = ( xAttrList.is() ? xAttrList->getLength() : 0 ); n < nAttrCount; ++n )
2992 OUString aLocalName;
2993 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( n ), &aLocalName );
2995 if( nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( aLocalName, XML_MIME_TYPE ) )
2997 if( 0 == xAttrList->getValueByIndex( n ).compareToAscii( "application/vnd.sun.star.media" ) )
2998 mbMedia = true;
3000 // leave this loop
3001 n = nAttrCount - 1;
3005 const char* pService;
3007 sal_Bool bIsPresShape = sal_False;
3009 if( mbMedia )
3011 pService = "com.sun.star.drawing.MediaShape";
3013 bIsPresShape = !maPresentationClass.isEmpty() && GetImport().GetShapeImport()->IsPresentationShapesSupported();
3014 if( bIsPresShape )
3016 if( IsXMLToken( maPresentationClass, XML_PRESENTATION_OBJECT ) )
3018 pService = "com.sun.star.presentation.MediaShape";
3022 else
3023 pService = "com.sun.star.drawing.PluginShape";
3025 AddShape( pService );
3027 if( mxShape.is() )
3029 SetLayer();
3031 if(bIsPresShape)
3033 uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY );
3034 if(xProps.is())
3036 uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() );
3037 if( xPropsInfo.is() )
3039 if( !mbIsPlaceholder && xPropsInfo->hasPropertyByName(OUString("IsEmptyPresentationObject" )))
3040 xProps->setPropertyValue( OUString("IsEmptyPresentationObject" ), ::cppu::bool2any( sal_False ) );
3042 if( mbIsUserTransformed && xPropsInfo->hasPropertyByName(OUString("IsPlaceholderDependent" )))
3043 xProps->setPropertyValue( OUString("IsPlaceholderDependent" ), ::cppu::bool2any( sal_False ) );
3048 // set pos, size, shear and rotate
3049 SetTransformation();
3050 GetImport().GetShapeImport()->finishShape( mxShape, mxAttrList, mxShapes );
3054 static ::rtl::OUString
3055 lcl_GetMediaReference(SvXMLImport const& rImport, ::rtl::OUString const& rURL)
3057 if (rImport.IsPackageURL(rURL))
3059 return ::rtl::OUString( "vnd.sun.star.Package:") + rURL;
3061 else
3063 return rImport.GetAbsoluteReference(rURL);
3067 // this is called from the parent group for each unparsed attribute in the attribute list
3068 void SdXMLPluginShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
3070 switch( nPrefix )
3072 case XML_NAMESPACE_DRAW:
3073 if( IsXMLToken( rLocalName, XML_MIME_TYPE ) )
3075 maMimeType = rValue;
3076 return;
3078 break;
3079 case XML_NAMESPACE_XLINK:
3080 if( IsXMLToken( rLocalName, XML_HREF ) )
3082 maHref = lcl_GetMediaReference(GetImport(), rValue);
3083 return;
3085 break;
3088 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
3091 void SdXMLPluginShapeContext::EndElement()
3093 uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY );
3095 if( xProps.is() )
3097 uno::Any aAny;
3099 if ( maSize.Width && maSize.Height )
3101 const rtl::OUString sVisibleArea( "VisibleArea" );
3102 uno::Reference< beans::XPropertySetInfo > aXPropSetInfo( xProps->getPropertySetInfo() );
3103 if ( !aXPropSetInfo.is() || aXPropSetInfo->hasPropertyByName( sVisibleArea ) )
3105 // the visual area for a plugin must be set on loading
3106 awt::Rectangle aRect( 0, 0, maSize.Width, maSize.Height );
3107 aAny <<= aRect;
3108 xProps->setPropertyValue( sVisibleArea, aAny );
3112 if( !mbMedia )
3114 // in case we have a plugin object
3115 if( maParams.getLength() )
3117 aAny <<= maParams;
3118 xProps->setPropertyValue( OUString( "PluginCommands" ), aAny );
3121 if( !maMimeType.isEmpty() )
3123 aAny <<= maMimeType;
3124 xProps->setPropertyValue( OUString( "PluginMimeType" ), aAny );
3127 if( !maHref.isEmpty() )
3129 aAny <<= maHref;
3130 xProps->setPropertyValue( OUString( "PluginURL" ), aAny );
3133 else
3135 // in case we have a media object
3136 xProps->setPropertyValue(
3137 OUString("MediaURL"),
3138 uno::makeAny(maHref));
3140 for( sal_Int32 nParam = 0; nParam < maParams.getLength(); ++nParam )
3142 const OUString& rName = maParams[ nParam ].Name;
3144 if( 0 == rName.compareToAscii( "Loop" ) )
3146 OUString aValueStr;
3147 maParams[ nParam ].Value >>= aValueStr;
3148 xProps->setPropertyValue( OUString( "Loop" ),
3149 uno::makeAny( static_cast< sal_Bool >( 0 == aValueStr.compareToAscii( "true" ) ) ) );
3151 else if( 0 == rName.compareToAscii( "Mute" ) )
3153 OUString aValueStr;
3154 maParams[ nParam ].Value >>= aValueStr;
3155 xProps->setPropertyValue( OUString( "Mute" ),
3156 uno::makeAny( static_cast< sal_Bool >( 0 == aValueStr.compareToAscii( "true" ) ) ) );
3158 else if( 0 == rName.compareToAscii( "VolumeDB" ) )
3160 OUString aValueStr;
3161 maParams[ nParam ].Value >>= aValueStr;
3162 xProps->setPropertyValue( OUString( "VolumeDB" ),
3163 uno::makeAny( static_cast< sal_Int16 >( aValueStr.toInt32() ) ) );
3165 else if( 0 == rName.compareToAscii( "Zoom" ) )
3167 OUString aZoomStr;
3168 media::ZoomLevel eZoomLevel;
3170 maParams[ nParam ].Value >>= aZoomStr;
3172 if( 0 == aZoomStr.compareToAscii( "25%" ) )
3173 eZoomLevel = media::ZoomLevel_ZOOM_1_TO_4;
3174 else if( 0 == aZoomStr.compareToAscii( "50%" ) )
3175 eZoomLevel = media::ZoomLevel_ZOOM_1_TO_2;
3176 else if( 0 == aZoomStr.compareToAscii( "100%" ) )
3177 eZoomLevel = media::ZoomLevel_ORIGINAL;
3178 else if( 0 == aZoomStr.compareToAscii( "200%" ) )
3179 eZoomLevel = media::ZoomLevel_ZOOM_2_TO_1;
3180 else if( 0 == aZoomStr.compareToAscii( "400%" ) )
3181 eZoomLevel = media::ZoomLevel_ZOOM_4_TO_1;
3182 else if( 0 == aZoomStr.compareToAscii( "fit" ) )
3183 eZoomLevel = media::ZoomLevel_FIT_TO_WINDOW;
3184 else if( 0 == aZoomStr.compareToAscii( "fixedfit" ) )
3185 eZoomLevel = media::ZoomLevel_FIT_TO_WINDOW_FIXED_ASPECT;
3186 else if( 0 == aZoomStr.compareToAscii( "fullscreen" ) )
3187 eZoomLevel = media::ZoomLevel_FULLSCREEN;
3188 else
3189 eZoomLevel = media::ZoomLevel_NOT_AVAILABLE;
3191 xProps->setPropertyValue( OUString( "Zoom" ), uno::makeAny( eZoomLevel ) );
3196 SetThumbnail();
3199 SdXMLShapeContext::EndElement();
3202 SvXMLImportContext * SdXMLPluginShapeContext::CreateChildContext( sal_uInt16 p_nPrefix, const ::rtl::OUString& rLocalName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
3204 if( p_nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( rLocalName, XML_PARAM ) )
3206 OUString aParamName, aParamValue;
3207 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
3208 // now parse the attribute list and look for draw:name and draw:value
3209 for(sal_Int16 a(0); a < nAttrCount; a++)
3211 const OUString& rAttrName = xAttrList->getNameByIndex(a);
3212 OUString aLocalName;
3213 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(rAttrName, &aLocalName);
3214 const OUString aValue( xAttrList->getValueByIndex(a) );
3216 if( nPrefix == XML_NAMESPACE_DRAW )
3218 if( IsXMLToken( aLocalName, XML_NAME ) )
3220 aParamName = aValue;
3222 else if( IsXMLToken( aLocalName, XML_VALUE ) )
3224 aParamValue = aValue;
3228 if( !aParamName.isEmpty() )
3230 sal_Int32 nIndex = maParams.getLength();
3231 maParams.realloc( nIndex + 1 );
3232 maParams[nIndex].Name = aParamName;
3233 maParams[nIndex].Handle = -1;
3234 maParams[nIndex].Value <<= aParamValue;
3235 maParams[nIndex].State = beans::PropertyState_DIRECT_VALUE;
3239 return new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
3242 return SdXMLShapeContext::CreateChildContext( p_nPrefix, rLocalName, xAttrList );
3245 //////////////////////////////////////////////////////////////////////////////
3247 TYPEINIT1( SdXMLFloatingFrameShapeContext, SdXMLShapeContext );
3249 SdXMLFloatingFrameShapeContext::SdXMLFloatingFrameShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
3250 const rtl::OUString& rLocalName,
3251 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
3252 com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes,
3253 sal_Bool bTemporaryShape)
3254 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape )
3258 SdXMLFloatingFrameShapeContext::~SdXMLFloatingFrameShapeContext()
3262 void SdXMLFloatingFrameShapeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& )
3264 const char* pService = "com.sun.star.drawing.FrameShape";
3265 AddShape( pService );
3267 if( mxShape.is() )
3269 SetLayer();
3271 // set pos, size, shear and rotate
3272 SetTransformation();
3274 uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY );
3275 if( xProps.is() )
3277 uno::Any aAny;
3279 if( !maFrameName.isEmpty() )
3281 aAny <<= maFrameName;
3282 xProps->setPropertyValue( OUString( "FrameName" ), aAny );
3285 if( !maHref.isEmpty() )
3287 aAny <<= maHref;
3288 xProps->setPropertyValue( OUString( "FrameURL" ), aAny );
3292 SetStyle();
3294 GetImport().GetShapeImport()->finishShape( mxShape, mxAttrList, mxShapes );
3298 // this is called from the parent group for each unparsed attribute in the attribute list
3299 void SdXMLFloatingFrameShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
3301 switch( nPrefix )
3303 case XML_NAMESPACE_DRAW:
3304 if( IsXMLToken( rLocalName, XML_FRAME_NAME ) )
3306 maFrameName = rValue;
3307 return;
3309 break;
3310 case XML_NAMESPACE_XLINK:
3311 if( IsXMLToken( rLocalName, XML_HREF ) )
3313 maHref = GetImport().GetAbsoluteReference(rValue);
3314 return;
3316 break;
3319 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
3322 void SdXMLFloatingFrameShapeContext::EndElement()
3324 uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY );
3326 if( xProps.is() )
3328 if ( maSize.Width && maSize.Height )
3330 // the visual area for a floating frame must be set on loading
3331 awt::Rectangle aRect( 0, 0, maSize.Width, maSize.Height );
3332 uno::Any aAny;
3333 aAny <<= aRect;
3334 xProps->setPropertyValue( OUString( "VisibleArea" ), aAny );
3338 SetThumbnail();
3339 SdXMLShapeContext::EndElement();
3342 //////////////////////////////////////////////////////////////////////////////
3344 TYPEINIT1( SdXMLFrameShapeContext, SdXMLShapeContext );
3346 SdXMLFrameShapeContext::SdXMLFrameShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
3347 const rtl::OUString& rLocalName,
3348 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
3349 com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes,
3350 sal_Bool bTemporaryShape)
3351 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
3352 MultiImageImportHelper(),
3353 mbSupportsReplacement( sal_False ),
3354 mxImplContext(),
3355 mxReplImplContext()
3357 uno::Reference < util::XCloneable > xClone( xAttrList, uno::UNO_QUERY );
3358 if( xClone.is() )
3359 mxAttrList.set( xClone->createClone(), uno::UNO_QUERY );
3360 else
3361 mxAttrList = new SvXMLAttributeList( xAttrList );
3365 SdXMLFrameShapeContext::~SdXMLFrameShapeContext()
3369 void SdXMLFrameShapeContext::removeGraphicFromImportContext(const SvXMLImportContext& rContext) const
3371 const SdXMLGraphicObjectShapeContext* pSdXMLGraphicObjectShapeContext = dynamic_cast< const SdXMLGraphicObjectShapeContext* >(&rContext);
3373 if(pSdXMLGraphicObjectShapeContext)
3377 uno::Reference< container::XChild > xChild(pSdXMLGraphicObjectShapeContext->getShape(), uno::UNO_QUERY_THROW);
3379 if(xChild.is())
3381 uno::Reference< drawing::XShapes > xParent(xChild->getParent(), uno::UNO_QUERY_THROW);
3383 if(xParent.is())
3385 // remove from parent
3386 xParent->remove(pSdXMLGraphicObjectShapeContext->getShape());
3388 // dispose
3389 uno::Reference< lang::XComponent > xComp(pSdXMLGraphicObjectShapeContext->getShape(), UNO_QUERY);
3391 if(xComp.is())
3393 xComp->dispose();
3398 catch( uno::Exception& )
3400 OSL_FAIL( "Error in cleanup of multiple graphic object import (!)" );
3405 rtl::OUString SdXMLFrameShapeContext::getGraphicURLFromImportContext(const SvXMLImportContext& rContext) const
3407 rtl::OUString aRetval;
3408 const SdXMLGraphicObjectShapeContext* pSdXMLGraphicObjectShapeContext = dynamic_cast< const SdXMLGraphicObjectShapeContext* >(&rContext);
3410 if(pSdXMLGraphicObjectShapeContext)
3414 const uno::Reference< beans::XPropertySet > xPropSet(pSdXMLGraphicObjectShapeContext->getShape(), uno::UNO_QUERY_THROW);
3416 if(xPropSet.is())
3418 xPropSet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicStreamURL"))) >>= aRetval;
3420 if(!aRetval.getLength())
3422 // it maybe a link, try GraphicURL
3423 xPropSet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicURL"))) >>= aRetval;
3427 catch( uno::Exception& )
3429 OSL_FAIL( "Error in cleanup of multiple graphic object import (!)" );
3433 return aRetval;
3436 SvXMLImportContext *SdXMLFrameShapeContext::CreateChildContext( sal_uInt16 nPrefix,
3437 const OUString& rLocalName,
3438 const uno::Reference< xml::sax::XAttributeList>& xAttrList )
3440 SvXMLImportContext * pContext = 0;
3442 if( !mxImplContext.Is() )
3445 SvXMLShapeContext* pShapeContext= GetImport().GetShapeImport()->CreateFrameChildContext(
3446 GetImport(), nPrefix, rLocalName, xAttrList, mxShapes, mxAttrList );
3448 pContext = pShapeContext;
3450 // propagate the hyperlink to child context
3451 if ( !msHyperlink.isEmpty() )
3452 pShapeContext->setHyperlink( msHyperlink );
3454 mxImplContext = pContext;
3455 mbSupportsReplacement = IsXMLToken(rLocalName, XML_OBJECT ) || IsXMLToken(rLocalName, XML_OBJECT_OLE);
3456 setSupportsMultipleContents(IsXMLToken(rLocalName, XML_IMAGE));
3458 if(getSupportsMultipleContents() && dynamic_cast< SdXMLGraphicObjectShapeContext* >(pContext))
3460 addContent(*mxImplContext);
3463 else if(getSupportsMultipleContents() && XML_NAMESPACE_DRAW == nPrefix && IsXMLToken(rLocalName, XML_IMAGE))
3465 // read another image
3466 pContext = GetImport().GetShapeImport()->CreateFrameChildContext(
3467 GetImport(), nPrefix, rLocalName, xAttrList, mxShapes, mxAttrList);
3468 mxImplContext = pContext;
3470 if(dynamic_cast< SdXMLGraphicObjectShapeContext* >(pContext))
3472 addContent(*mxImplContext);
3475 else if( mbSupportsReplacement && !mxReplImplContext &&
3476 XML_NAMESPACE_DRAW == nPrefix &&
3477 IsXMLToken( rLocalName, XML_IMAGE ) )
3479 // read replacement image
3480 SvXMLImportContext *pImplContext = &mxImplContext;
3481 SdXMLShapeContext *pSContext =
3482 PTR_CAST( SdXMLShapeContext, pImplContext );
3483 if( pSContext )
3485 uno::Reference < beans::XPropertySet > xPropSet(
3486 pSContext->getShape(), uno::UNO_QUERY );
3487 if( xPropSet.is() )
3489 pContext = new XMLReplacementImageContext( GetImport(),
3490 nPrefix, rLocalName, xAttrList, xPropSet );
3491 mxReplImplContext = pContext;
3495 else if(
3496 ( nPrefix == XML_NAMESPACE_SVG && // #i68101#
3497 (IsXMLToken( rLocalName, XML_TITLE ) || IsXMLToken( rLocalName, XML_DESC ) ) ) ||
3498 (nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) ) ||
3499 (nPrefix == XML_NAMESPACE_DRAW && (IsXMLToken( rLocalName, XML_GLUE_POINT ) ||
3500 IsXMLToken( rLocalName, XML_THUMBNAIL ) ) ) )
3502 SvXMLImportContext *pImplContext = &mxImplContext;
3503 pContext = PTR_CAST( SdXMLShapeContext, pImplContext )->CreateChildContext( nPrefix,
3504 rLocalName, xAttrList );
3506 else if ( (XML_NAMESPACE_DRAW == nPrefix) && IsXMLToken( rLocalName, XML_IMAGE_MAP ) )
3508 SdXMLShapeContext *pSContext = dynamic_cast< SdXMLShapeContext* >( &mxImplContext );
3509 if( pSContext )
3511 uno::Reference < beans::XPropertySet > xPropSet( pSContext->getShape(), uno::UNO_QUERY );
3512 if (xPropSet.is())
3514 pContext = new XMLImageMapContext(GetImport(), nPrefix, rLocalName, xPropSet);
3519 // call parent for content
3520 if(!pContext)
3521 pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
3523 return pContext;
3526 void SdXMLFrameShapeContext::StartElement(const uno::Reference< xml::sax::XAttributeList>&)
3528 // ignore
3531 void SdXMLFrameShapeContext::EndElement()
3533 // solve if multiple image child contexts were imported
3534 const SvXMLImportContext* const pSelectedContext(solveMultipleImages());
3535 const SdXMLGraphicObjectShapeContext* pShapeContext( dynamic_cast<const SdXMLGraphicObjectShapeContext*>( pSelectedContext ) );
3536 if ( pShapeContext && !maShapeId.isEmpty() )
3538 // fdo#64512 and fdo#60075 - make sure *this* shape is
3539 // registered for given ID
3540 assert( mxImplContext.Is() );
3541 const uno::Reference< uno::XInterface > xShape( pShapeContext->getShape() );
3542 GetImport().getInterfaceToIdentifierMapper().registerReferenceAlways( maShapeId, xShape );
3545 if( !mxImplContext.Is() )
3547 // now check if this is an empty presentation object
3548 sal_Int16 nAttrCount = mxAttrList.is() ? mxAttrList->getLength() : 0;
3549 for(sal_Int16 a(0); a < nAttrCount; a++)
3551 OUString aLocalName;
3552 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(mxAttrList->getNameByIndex(a), &aLocalName);
3554 if( nPrefix == XML_NAMESPACE_PRESENTATION )
3556 if( IsXMLToken( aLocalName, XML_PLACEHOLDER ) )
3558 mbIsPlaceholder = IsXMLToken( mxAttrList->getValueByIndex(a), XML_TRUE );
3560 else if( IsXMLToken( aLocalName, XML_CLASS ) )
3562 maPresentationClass = mxAttrList->getValueByIndex(a);
3567 if( (!maPresentationClass.isEmpty()) && mbIsPlaceholder )
3569 uno::Reference< xml::sax::XAttributeList> xEmpty;
3571 enum XMLTokenEnum eToken = XML_TEXT_BOX;
3573 if( IsXMLToken( maPresentationClass, XML_GRAPHIC ) )
3575 eToken = XML_IMAGE;
3578 else if( IsXMLToken( maPresentationClass, XML_PRESENTATION_PAGE ) )
3580 eToken = XML_PAGE_THUMBNAIL;
3582 else if( IsXMLToken( maPresentationClass, XML_PRESENTATION_CHART ) ||
3583 IsXMLToken( maPresentationClass, XML_PRESENTATION_TABLE ) ||
3584 IsXMLToken( maPresentationClass, XML_PRESENTATION_OBJECT ) )
3586 eToken = XML_OBJECT;
3589 mxImplContext = GetImport().GetShapeImport()->CreateFrameChildContext(
3590 GetImport(), XML_NAMESPACE_DRAW, GetXMLToken( eToken ), mxAttrList, mxShapes, xEmpty );
3592 if( mxImplContext.Is() )
3594 mxImplContext->StartElement( mxAttrList );
3595 mxImplContext->EndElement();
3600 mxImplContext = 0;
3601 SdXMLShapeContext::EndElement();
3604 void SdXMLFrameShapeContext::processAttribute( sal_uInt16 nPrefix,
3605 const OUString& rLocalName, const OUString& rValue )
3607 bool bId( false );
3609 switch ( nPrefix )
3611 case XML_NAMESPACE_DRAW :
3612 case XML_NAMESPACE_DRAW_EXT :
3613 bId = IsXMLToken( rLocalName, XML_ID );
3614 break;
3615 case XML_NAMESPACE_NONE :
3616 case XML_NAMESPACE_XML :
3617 bId = IsXMLToken( rLocalName, XML_ID );
3618 break;
3621 if ( bId )
3622 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
3625 TYPEINIT1( SdXMLCustomShapeContext, SdXMLShapeContext );
3627 SdXMLCustomShapeContext::SdXMLCustomShapeContext(
3628 SvXMLImport& rImport,
3629 sal_uInt16 nPrfx,
3630 const OUString& rLocalName,
3631 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
3632 uno::Reference< drawing::XShapes >& rShapes,
3633 sal_Bool bTemporaryShape)
3634 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape )
3638 //////////////////////////////////////////////////////////////////////////////
3640 SdXMLCustomShapeContext::~SdXMLCustomShapeContext()
3644 //////////////////////////////////////////////////////////////////////////////
3646 // this is called from the parent group for each unparsed attribute in the attribute list
3647 void SdXMLCustomShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
3649 if( XML_NAMESPACE_DRAW == nPrefix )
3651 if( IsXMLToken( rLocalName, XML_ENGINE ) )
3653 maCustomShapeEngine = rValue;
3654 return;
3656 if ( IsXMLToken( rLocalName, XML_DATA ) )
3658 maCustomShapeData = rValue;
3659 return;
3662 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
3665 //////////////////////////////////////////////////////////////////////////////
3667 void SdXMLCustomShapeContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
3669 // create rectangle shape
3670 AddShape("com.sun.star.drawing.CustomShape");
3671 if ( mxShape.is() )
3673 // Add, set Style and properties from base shape
3674 SetStyle();
3675 SetLayer();
3677 // set pos, size, shear and rotate
3678 SetTransformation();
3682 uno::Reference< beans::XPropertySet > xPropSet( mxShape, uno::UNO_QUERY );
3683 if( xPropSet.is() )
3685 if ( !maCustomShapeEngine.isEmpty() )
3687 uno::Any aAny;
3688 aAny <<= maCustomShapeEngine;
3689 xPropSet->setPropertyValue( EASGet( EAS_CustomShapeEngine ), aAny );
3691 if ( !maCustomShapeData.isEmpty() )
3693 uno::Any aAny;
3694 aAny <<= maCustomShapeData;
3695 xPropSet->setPropertyValue( EASGet( EAS_CustomShapeData ), aAny );
3699 catch(const uno::Exception&)
3701 OSL_FAIL( "could not set enhanced customshape geometry" );
3703 SdXMLShapeContext::StartElement(xAttrList);
3707 void SdXMLCustomShapeContext::EndElement()
3709 if ( !maCustomShapeGeometry.empty() )
3711 const rtl::OUString sCustomShapeGeometry ( "CustomShapeGeometry" );
3713 // converting the vector to a sequence
3714 uno::Sequence< beans::PropertyValue > aSeq( maCustomShapeGeometry.size() );
3715 beans::PropertyValue* pValues = aSeq.getArray();
3716 std::vector< beans::PropertyValue >::const_iterator aIter( maCustomShapeGeometry.begin() );
3717 std::vector< beans::PropertyValue >::const_iterator aEnd( maCustomShapeGeometry.end() );
3718 while ( aIter != aEnd )
3719 *pValues++ = *aIter++;
3723 uno::Reference< beans::XPropertySet > xPropSet( mxShape, uno::UNO_QUERY );
3724 if( xPropSet.is() )
3726 uno::Any aAny;
3727 aAny <<= aSeq;
3728 xPropSet->setPropertyValue( sCustomShapeGeometry, aAny );
3731 catch(const uno::Exception&)
3733 OSL_FAIL( "could not set enhanced customshape geometry" );
3736 sal_Int32 nUPD( 0 );
3737 sal_Int32 nBuild( 0 );
3738 GetImport().getBuildIds( nUPD, nBuild );
3739 if( ((nUPD >= 640 && nUPD <= 645) || (nUPD == 680)) && (nBuild <= 9221) )
3741 Reference< drawing::XEnhancedCustomShapeDefaulter > xDefaulter( mxShape, UNO_QUERY );
3742 if( xDefaulter.is() )
3744 rtl::OUString aEmptyType;
3745 xDefaulter->createCustomShapeDefaults( aEmptyType );
3750 SdXMLShapeContext::EndElement();
3753 //////////////////////////////////////////////////////////////////////////////
3755 SvXMLImportContext* SdXMLCustomShapeContext::CreateChildContext(
3756 sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
3757 const uno::Reference<xml::sax::XAttributeList>& xAttrList )
3759 SvXMLImportContext* pContext = NULL;
3760 if ( XML_NAMESPACE_DRAW == nPrefix )
3762 if ( IsXMLToken( rLocalName, XML_ENHANCED_GEOMETRY ) )
3764 uno::Reference< beans::XPropertySet > xPropSet( mxShape,uno::UNO_QUERY );
3765 if ( xPropSet.is() )
3766 pContext = new XMLEnhancedCustomShapeContext( GetImport(), mxShape, nPrefix, rLocalName, maCustomShapeGeometry );
3769 // delegate to parent class if no context could be created
3770 if ( NULL == pContext )
3771 pContext = SdXMLShapeContext::CreateChildContext( nPrefix, rLocalName,
3772 xAttrList);
3773 return pContext;
3776 ///////////////////////////////////////////////////////////////////////
3778 //////////////////////////////////////////////////////////////////////////////
3780 TYPEINIT1( SdXMLTableShapeContext, SdXMLShapeContext );
3782 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 )
3783 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, sal_False )
3785 memset( &maTemplateStylesUsed, 0, sizeof( maTemplateStylesUsed ) );
3788 SdXMLTableShapeContext::~SdXMLTableShapeContext()
3792 void SdXMLTableShapeContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList )
3794 const char* pService = "com.sun.star.drawing.TableShape";
3796 sal_Bool bIsPresShape = !maPresentationClass.isEmpty() && GetImport().GetShapeImport()->IsPresentationShapesSupported();
3797 if( bIsPresShape )
3799 if( IsXMLToken( maPresentationClass, XML_PRESENTATION_TABLE ) )
3801 pService = "com.sun.star.presentation.TableShape";
3805 AddShape( pService );
3807 if( mxShape.is() )
3809 SetLayer();
3811 uno::Reference< beans::XPropertySet > xProps(mxShape, uno::UNO_QUERY);
3813 if(bIsPresShape)
3815 if(xProps.is())
3817 uno::Reference< beans::XPropertySetInfo > xPropsInfo( xProps->getPropertySetInfo() );
3818 if( xPropsInfo.is() )
3820 if( !mbIsPlaceholder && xPropsInfo->hasPropertyByName(OUString("IsEmptyPresentationObject" )))
3821 xProps->setPropertyValue( OUString("IsEmptyPresentationObject" ), ::cppu::bool2any( sal_False ) );
3823 if( mbIsUserTransformed && xPropsInfo->hasPropertyByName(OUString("IsPlaceholderDependent" )))
3824 xProps->setPropertyValue( OUString("IsPlaceholderDependent" ), ::cppu::bool2any( sal_False ) );
3829 SetStyle();
3831 if( xProps.is() )
3833 if( !msTemplateStyleName.isEmpty() ) try
3835 Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetImport().GetModel(), UNO_QUERY_THROW );
3836 Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
3837 const OUString sFamilyName( "table" );
3838 Reference< XNameAccess > xTableFamily( xFamilies->getByName( sFamilyName ), UNO_QUERY_THROW );
3839 Reference< XStyle > xTableStyle( xTableFamily->getByName( msTemplateStyleName ), UNO_QUERY_THROW );
3840 xProps->setPropertyValue( OUString( "TableTemplate" ), Any( xTableStyle ) );
3842 catch(const Exception&)
3844 OSL_FAIL("SdXMLTableShapeContext::StartElement(), exception caught!");
3847 const XMLPropertyMapEntry* pEntry = &aXMLTableShapeAttributes[0];
3848 for( int i = 0; pEntry->msApiName && (i < 6); i++, pEntry++ )
3852 const OUString sAPIPropertyName( OUString(pEntry->msApiName, pEntry->nApiNameLength, RTL_TEXTENCODING_ASCII_US ) );
3853 xProps->setPropertyValue( sAPIPropertyName, Any( maTemplateStylesUsed[i] ) );
3855 catch(const Exception&)
3857 OSL_FAIL("SdXMLTableShapeContext::StartElement(), exception caught!");
3862 GetImport().GetShapeImport()->finishShape( mxShape, mxAttrList, mxShapes );
3864 const rtl::Reference< XMLTableImport >& xTableImport( GetImport().GetShapeImport()->GetShapeTableImport() );
3865 if( xTableImport.is() && xProps.is() )
3867 uno::Reference< table::XColumnRowRange > xColumnRowRange(
3868 xProps->getPropertyValue( OUString("Model" ) ), uno::UNO_QUERY );
3870 if( xColumnRowRange.is() )
3871 mxTableImportContext = xTableImport->CreateTableContext( GetPrefix(), GetLocalName(), xColumnRowRange );
3873 if( mxTableImportContext.Is() )
3874 mxTableImportContext->StartElement( xAttrList );
3879 void SdXMLTableShapeContext::EndElement()
3881 if( mxTableImportContext.Is() )
3882 mxTableImportContext->EndElement();
3884 SdXMLShapeContext::EndElement();
3886 if( mxShape.is() )
3888 // set pos, size, shear and rotate
3889 SetTransformation();
3893 // this is called from the parent group for each unparsed attribute in the attribute list
3894 void SdXMLTableShapeContext::processAttribute( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
3896 if( nPrefix == XML_NAMESPACE_TABLE )
3898 if( IsXMLToken( rLocalName, XML_TEMPLATE_NAME ) )
3900 msTemplateStyleName = rValue;
3902 else
3904 int i = 0;
3905 const XMLPropertyMapEntry* pEntry = &aXMLTableShapeAttributes[0];
3906 while( pEntry->msApiName && (i < 6) )
3908 if( IsXMLToken( rLocalName, pEntry->meXMLName ) )
3910 if( IsXMLToken( rValue, XML_TRUE ) )
3911 maTemplateStylesUsed[i] = sal_True;
3912 break;
3914 pEntry++;
3915 i++;
3919 SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue );
3922 SvXMLImportContext* SdXMLTableShapeContext::CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& xAttrList )
3924 if( mxTableImportContext.Is() && (nPrefix == XML_NAMESPACE_TABLE) )
3925 return mxTableImportContext->CreateChildContext(nPrefix, rLocalName, xAttrList);
3926 else
3927 return SdXMLShapeContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
3930 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */