fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / oox / source / drawingml / shape.cxx
blob97159735c78383e3269c855b71948c226ec38242
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 "oox/drawingml/shape.hxx"
21 #include "oox/drawingml/customshapeproperties.hxx"
22 #include "oox/drawingml/theme.hxx"
23 #include "oox/drawingml/fillproperties.hxx"
24 #include "oox/drawingml/lineproperties.hxx"
25 #include "oox/drawingml/effectproperties.hxx"
26 #include "oox/drawingml/shapepropertymap.hxx"
27 #include "oox/drawingml/textbody.hxx"
28 #include "oox/drawingml/table/tableproperties.hxx"
29 #include "oox/drawingml/chart/chartconverter.hxx"
30 #include "oox/drawingml/chart/chartspacefragment.hxx"
31 #include "oox/drawingml/chart/chartspacemodel.hxx"
32 #include "oox/vml/vmldrawing.hxx"
33 #include "oox/vml/vmlshape.hxx"
34 #include "oox/vml/vmlshapecontainer.hxx"
35 #include "oox/core/xmlfilterbase.hxx"
36 #include "oox/helper/graphichelper.hxx"
37 #include "oox/helper/propertyset.hxx"
39 #include <tools/solar.h> // for the F_PI180 define
40 #include <com/sun/star/graphic/XGraphic.hpp>
41 #include <com/sun/star/container/XNamed.hpp>
42 #include <com/sun/star/container/XNameContainer.hpp>
43 #include <com/sun/star/beans/XMultiPropertySet.hpp>
44 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
45 #include <com/sun/star/xml/AttributeData.hpp>
46 #include <com/sun/star/drawing/HomogenMatrix3.hpp>
47 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
48 #include <com/sun/star/text/XText.hpp>
49 #include <com/sun/star/chart2/XChartDocument.hpp>
50 #include <com/sun/star/style/ParagraphAdjust.hpp>
51 #include <basegfx/point/b2dpoint.hxx>
52 #include <basegfx/polygon/b2dpolygon.hxx>
53 #include <basegfx/matrix/b2dhommatrix.hxx>
54 #include <com/sun/star/document/XActionLockable.hpp>
56 using namespace ::oox::core;
57 using namespace ::com::sun::star;
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star::beans;
60 using namespace ::com::sun::star::frame;
61 using namespace ::com::sun::star::text;
62 using namespace ::com::sun::star::drawing;
63 using namespace ::com::sun::star::style;
65 namespace oox { namespace drawingml {
67 // ============================================================================
69 Shape::Shape( const sal_Char* pServiceName )
70 : mbIsChild( false )
71 , mpLinePropertiesPtr( new LineProperties )
72 , mpFillPropertiesPtr( new FillProperties )
73 , mpGraphicPropertiesPtr( new GraphicProperties )
74 , mpCustomShapePropertiesPtr( new CustomShapeProperties )
75 , mpEffectPropertiesPtr( new EffectProperties )
76 , mpMasterTextListStyle( new TextListStyle )
77 , mnSubType( 0 )
78 , meFrameType( FRAMETYPE_GENERIC )
79 , mnRotation( 0 )
80 , mbFlipH( false )
81 , mbFlipV( false )
82 , mbHidden( false )
83 , mbHiddenMasterShape( false )
84 , mbLockedCanvas( false )
86 if ( pServiceName )
87 msServiceName = OUString::createFromAscii( pServiceName );
88 setDefaults();
91 Shape::Shape( const ShapePtr& pSourceShape )
92 : maChildren()
93 , mbIsChild( pSourceShape->mbIsChild )
94 , mpTextBody(pSourceShape->mpTextBody)
95 , mpLinePropertiesPtr( pSourceShape->mpLinePropertiesPtr )
96 , mpFillPropertiesPtr( pSourceShape->mpFillPropertiesPtr )
97 , mpGraphicPropertiesPtr( pSourceShape->mpGraphicPropertiesPtr )
98 , mpCustomShapePropertiesPtr( pSourceShape->mpCustomShapePropertiesPtr )
99 , mpTablePropertiesPtr( pSourceShape->mpTablePropertiesPtr )
100 , mp3DPropertiesPtr( pSourceShape->mp3DPropertiesPtr )
101 , mpEffectPropertiesPtr (pSourceShape->mpEffectPropertiesPtr)
102 , maShapeProperties( pSourceShape->maShapeProperties )
103 , mpMasterTextListStyle( pSourceShape->mpMasterTextListStyle )
104 , mxShape()
105 , msServiceName( pSourceShape->msServiceName )
106 , msName( pSourceShape->msName )
107 , msId( pSourceShape->msId )
108 , mnSubType( pSourceShape->mnSubType )
109 , moSubTypeIndex( pSourceShape->moSubTypeIndex )
110 , maShapeStyleRefs( pSourceShape->maShapeStyleRefs )
111 , maSize( pSourceShape->maSize )
112 , maPosition( pSourceShape->maPosition )
113 , meFrameType( pSourceShape->meFrameType )
114 , mnRotation( pSourceShape->mnRotation )
115 , mbFlipH( pSourceShape->mbFlipH )
116 , mbFlipV( pSourceShape->mbFlipV )
117 , mbHidden( pSourceShape->mbHidden )
118 , mbHiddenMasterShape( pSourceShape->mbHiddenMasterShape )
119 , mbLockedCanvas( pSourceShape->mbLockedCanvas )
123 Shape::~Shape()
127 table::TablePropertiesPtr Shape::getTableProperties()
129 if ( !mpTablePropertiesPtr.get() )
130 mpTablePropertiesPtr.reset( new table::TableProperties() );
131 return mpTablePropertiesPtr;
134 void Shape::setDefaults()
136 maDefaultShapeProperties[ PROP_TextAutoGrowHeight ] <<= false;
137 maDefaultShapeProperties[ PROP_TextWordWrap ] <<= true;
138 maDefaultShapeProperties[ PROP_TextLeftDistance ] <<= static_cast< sal_Int32 >( 250 );
139 maDefaultShapeProperties[ PROP_TextUpperDistance ] <<= static_cast< sal_Int32 >( 125 );
140 maDefaultShapeProperties[ PROP_TextRightDistance ] <<= static_cast< sal_Int32 >( 250 );
141 maDefaultShapeProperties[ PROP_TextLowerDistance ] <<= static_cast< sal_Int32 >( 125 );
142 maDefaultShapeProperties[ PROP_CharHeight ] <<= static_cast< float >( 18.0 );
143 maDefaultShapeProperties[ PROP_TextVerticalAdjust ] <<= TextVerticalAdjust_TOP;
144 maDefaultShapeProperties[ PROP_ParaAdjust ] <<= static_cast< sal_Int16 >( ParagraphAdjust_LEFT ); // check for RTL?
147 ::oox::vml::OleObjectInfo& Shape::setOleObjectType()
149 OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setOleObjectType - multiple frame types" );
150 meFrameType = FRAMETYPE_OLEOBJECT;
151 mxOleObjectInfo.reset( new ::oox::vml::OleObjectInfo( true ) );
152 return *mxOleObjectInfo;
155 ChartShapeInfo& Shape::setChartType( bool bEmbedShapes )
157 OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setChartType - multiple frame types" );
158 meFrameType = FRAMETYPE_CHART;
159 msServiceName = "com.sun.star.drawing.OLE2Shape";
160 mxChartShapeInfo.reset( new ChartShapeInfo( bEmbedShapes ) );
161 return *mxChartShapeInfo;
164 void Shape::setDiagramType()
166 OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setDiagramType - multiple frame types" );
167 meFrameType = FRAMETYPE_DIAGRAM;
168 msServiceName = "com.sun.star.drawing.GroupShape";
169 mnSubType = 0;
172 void Shape::setTableType()
174 OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setTableType - multiple frame types" );
175 meFrameType = FRAMETYPE_TABLE;
176 msServiceName = "com.sun.star.drawing.TableShape";
177 mnSubType = 0;
180 void Shape::setServiceName( const sal_Char* pServiceName )
182 if ( pServiceName )
183 msServiceName = OUString::createFromAscii( pServiceName );
187 const ShapeStyleRef* Shape::getShapeStyleRef( sal_Int32 nRefType ) const
189 ShapeStyleRefMap::const_iterator aIt = maShapeStyleRefs.find( nRefType );
190 return (aIt == maShapeStyleRefs.end()) ? 0 : &aIt->second;
193 void Shape::addShape(
194 ::oox::core::XmlFilterBase& rFilterBase,
195 const Theme* pTheme,
196 const Reference< XShapes >& rxShapes,
197 basegfx::B2DHomMatrix& aTransformation,
198 FillProperties& rShapeOrParentShapeFillProps,
199 const awt::Rectangle* pShapeRect,
200 ShapeIdMap* pShapeMap )
202 SAL_INFO("oox", OSL_THIS_FUNC << " id: " << msId);
206 OUString sServiceName( msServiceName );
207 if( !sServiceName.isEmpty() )
209 basegfx::B2DHomMatrix aMatrix( aTransformation );
210 Reference< XShape > xShape( createAndInsert( rFilterBase, sServiceName, pTheme, rxShapes, pShapeRect, sal_False, sal_False, aMatrix, rShapeOrParentShapeFillProps ) );
212 if( pShapeMap && !msId.isEmpty() )
214 (*pShapeMap)[ msId ] = shared_from_this();
217 // if this is a group shape, we have to add also each child shape
218 Reference< XShapes > xShapes( xShape, UNO_QUERY );
219 if ( xShapes.is() )
220 addChildren( rFilterBase, *this, pTheme, xShapes, pShapeRect ? *pShapeRect : awt::Rectangle( maPosition.X, maPosition.Y, maSize.Width, maSize.Height ), pShapeMap, aMatrix );
223 catch( const Exception& )
228 void Shape::setLockedCanvas(bool bLockedCanvas)
230 mbLockedCanvas = bLockedCanvas;
233 bool Shape::getLockedCanvas()
235 return mbLockedCanvas;
238 void Shape::applyShapeReference( const Shape& rReferencedShape, bool bUseText )
240 SAL_INFO("oox", "apply shape reference: " << rReferencedShape.msId << " to shape id: " << msId);
242 if ( rReferencedShape.mpTextBody.get() && bUseText )
243 mpTextBody = TextBodyPtr( new TextBody( *rReferencedShape.mpTextBody.get() ) );
244 else
245 mpTextBody.reset();
246 maShapeProperties = rReferencedShape.maShapeProperties;
247 mpLinePropertiesPtr = LinePropertiesPtr( new LineProperties( *rReferencedShape.mpLinePropertiesPtr.get() ) );
248 mpFillPropertiesPtr = FillPropertiesPtr( new FillProperties( *rReferencedShape.mpFillPropertiesPtr.get() ) );
249 mpCustomShapePropertiesPtr = CustomShapePropertiesPtr( new CustomShapeProperties( *rReferencedShape.mpCustomShapePropertiesPtr.get() ) );
250 mpTablePropertiesPtr = table::TablePropertiesPtr( rReferencedShape.mpTablePropertiesPtr.get() ? new table::TableProperties( *rReferencedShape.mpTablePropertiesPtr.get() ) : NULL );
251 mpEffectPropertiesPtr = EffectPropertiesPtr( new EffectProperties( *rReferencedShape.mpEffectPropertiesPtr.get() ) );
252 mpMasterTextListStyle = TextListStylePtr( new TextListStyle( *rReferencedShape.mpMasterTextListStyle.get() ) );
253 maShapeStyleRefs = rReferencedShape.maShapeStyleRefs;
254 maSize = rReferencedShape.maSize;
255 maPosition = rReferencedShape.maPosition;
256 mnRotation = rReferencedShape.mnRotation;
257 mbFlipH = rReferencedShape.mbFlipH;
258 mbFlipV = rReferencedShape.mbFlipV;
259 mbHidden = rReferencedShape.mbHidden;
262 void Shape::addChildren( ::oox::core::XmlFilterBase& rFilterBase,
263 const Theme* pTheme,
264 const Reference< XShapes >& rxShapes,
265 basegfx::B2DHomMatrix& aTransformation,
266 const awt::Rectangle* pShapeRect,
267 ShapeIdMap* pShapeMap )
269 addChildren(rFilterBase, *this, pTheme, rxShapes,
270 pShapeRect ?
271 *pShapeRect :
272 awt::Rectangle( maPosition.X, maPosition.Y, maSize.Width, maSize.Height ),
273 pShapeMap, aTransformation);
276 struct ActionLockGuard
278 explicit ActionLockGuard(Reference<drawing::XShape> const& xShape)
279 : m_xLockable(xShape, UNO_QUERY)
281 if (m_xLockable.is()) {
282 m_xLockable->addActionLock();
285 ~ActionLockGuard()
287 if (m_xLockable.is()) {
288 m_xLockable->removeActionLock();
291 private:
292 Reference<document::XActionLockable> m_xLockable;
295 // for group shapes, the following method is also adding each child
296 void Shape::addChildren(
297 XmlFilterBase& rFilterBase,
298 Shape& rMaster,
299 const Theme* pTheme,
300 const Reference< XShapes >& rxShapes,
301 const awt::Rectangle&,
302 ShapeIdMap* pShapeMap,
303 basegfx::B2DHomMatrix& aTransformation )
305 basegfx::B2DHomMatrix aChildTransformation;
307 aChildTransformation.translate(-maChPosition.X, -maChPosition.Y);
308 aChildTransformation.scale(1/(maChSize.Width ? maChSize.Width : 1.0), 1/(maChSize.Height ? maChSize.Height : 1.0));
309 aChildTransformation *= aTransformation;
311 OSL_TRACE("parent matrix:\n%f %f %f\n%f %f %f\n%f %f %f",
312 aChildTransformation.get(0, 0),
313 aChildTransformation.get(0, 1),
314 aChildTransformation.get(0, 2),
315 aChildTransformation.get(1, 0),
316 aChildTransformation.get(1, 1),
317 aChildTransformation.get(1, 2),
318 aChildTransformation.get(2, 0),
319 aChildTransformation.get(2, 1),
320 aChildTransformation.get(2, 2));
322 std::vector< ShapePtr >::iterator aIter( rMaster.maChildren.begin() );
323 while( aIter != rMaster.maChildren.end() ) {
324 (*aIter)->setMasterTextListStyle( mpMasterTextListStyle );
325 (*aIter++)->addShape( rFilterBase, pTheme, rxShapes, aChildTransformation, getFillProperties(), NULL, pShapeMap );
329 Reference< XShape > Shape::createAndInsert(
330 ::oox::core::XmlFilterBase& rFilterBase,
331 const OUString& rServiceName,
332 const Theme* pTheme,
333 const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
334 const awt::Rectangle* /* pShapeRect */,
335 sal_Bool bClearText,
336 sal_Bool bDoNotInsertEmptyTextBody,
337 basegfx::B2DHomMatrix& aParentTransformation,
338 FillProperties& rShapeOrParentShapeFillProps )
340 bool bIsEmbMedia = false;
341 SAL_INFO("oox", OSL_THIS_FUNC << " id: " << msId);
343 awt::Rectangle aShapeRectHmm( maPosition.X / 360, maPosition.Y / 360, maSize.Width / 360, maSize.Height / 360 );
345 OUString aServiceName;
346 if( rServiceName == "com.sun.star.drawing.GraphicObjectShape" &&
347 mpGraphicPropertiesPtr && !mpGraphicPropertiesPtr->maAudio.msEmbed.isEmpty() )
349 aServiceName = finalizeServiceName( rFilterBase, "com.sun.star.presentation.MediaShape", aShapeRectHmm );
350 bIsEmbMedia = true;
352 else
354 aServiceName = finalizeServiceName( rFilterBase, rServiceName, aShapeRectHmm );
356 sal_Bool bIsCustomShape = ( aServiceName == "com.sun.star.drawing.CustomShape" ||
357 aServiceName == "com.sun.star.drawing.ConnectorShape" );
359 basegfx::B2DHomMatrix aTransformation;
361 if( maSize.Width != 1 || maSize.Height != 1)
363 // take care there are no zeros used by error
364 aTransformation.scale(
365 maSize.Width ? maSize.Width : 1.0,
366 maSize.Height ? maSize.Height : 1.0 );
369 if( mbFlipH || mbFlipV || mnRotation != 0)
371 // calculate object's center
372 basegfx::B2DPoint aCenter(0.5, 0.5);
373 aCenter *= aTransformation;
375 // center object at origin
376 aTransformation.translate( -aCenter.getX(), -aCenter.getY() );
378 if( !bIsCustomShape && ( mbFlipH || mbFlipV ) )
380 // mirror around object's center
381 aTransformation.scale( mbFlipH ? -1.0 : 1.0, mbFlipV ? -1.0 : 1.0 );
384 if( mnRotation != 0 )
386 // rotate around object's center
387 aTransformation.rotate( F_PI180 * ( (double)mnRotation / 60000.0 ) );
390 // move object back from center
391 aTransformation.translate( aCenter.getX(), aCenter.getY() );
394 if( maPosition.X != 0 || maPosition.Y != 0)
396 // if global position is used, add it to transformation
397 aTransformation.translate( maPosition.X, maPosition.Y );
400 aTransformation = aParentTransformation*aTransformation;
401 aParentTransformation = aTransformation;
402 aTransformation.scale(1/360.0, 1/360.0);
404 // special for lineshape
405 if ( aServiceName == "com.sun.star.drawing.LineShape" )
407 ::basegfx::B2DPolygon aPoly;
408 aPoly.insert( 0, ::basegfx::B2DPoint( 0, 0 ) );
409 aPoly.insert( 1, ::basegfx::B2DPoint( maSize.Width ? 1 : 0, maSize.Height ? 1 : 0 ) );
410 aPoly.transform( aTransformation );
412 // now creating the corresponding PolyPolygon
413 sal_Int32 i, nNumPoints = aPoly.count();
414 uno::Sequence< awt::Point > aPointSequence( nNumPoints );
415 awt::Point* pPoints = aPointSequence.getArray();
416 for( i = 0; i < nNumPoints; ++i )
418 const ::basegfx::B2DPoint aPoint( aPoly.getB2DPoint( i ) );
419 pPoints[ i ] = awt::Point( static_cast< sal_Int32 >( aPoint.getX() ), static_cast< sal_Int32 >( aPoint.getY() ) );
421 uno::Sequence< uno::Sequence< awt::Point > > aPolyPolySequence( 1 );
422 aPolyPolySequence.getArray()[ 0 ] = aPointSequence;
424 maShapeProperties[ PROP_PolyPolygon ] <<= aPolyPolySequence;
426 else if ( aServiceName == "com.sun.star.drawing.ConnectorShape" )
428 ::basegfx::B2DPolygon aPoly;
429 aPoly.insert( 0, ::basegfx::B2DPoint( 0, 0 ) );
430 aPoly.insert( 1, ::basegfx::B2DPoint( maSize.Width ? 1 : 0, maSize.Height ? 1 : 0 ) );
431 aPoly.transform( aTransformation );
433 basegfx::B2DPoint aStartPosition( aPoly.getB2DPoint( 0 ) );
434 basegfx::B2DPoint aEndPosition( aPoly.getB2DPoint( 1 ) );
435 awt::Point aAWTStartPosition( static_cast< sal_Int32 >( aStartPosition.getX() ), static_cast< sal_Int32 >( aStartPosition.getY() ) );
436 awt::Point aAWTEndPosition( static_cast< sal_Int32 >( aEndPosition.getX() ), static_cast< sal_Int32 >( aEndPosition.getY() ) );
438 maShapeProperties[ PROP_StartPosition ] <<= aAWTStartPosition;
439 maShapeProperties[ PROP_EndPosition ] <<= aAWTEndPosition;
441 else
443 // now set transformation for this object
444 HomogenMatrix3 aMatrix;
447 aMatrix.Line1.Column1 = aTransformation.get(0,0);
448 aMatrix.Line1.Column2 = aTransformation.get(0,1);
449 aMatrix.Line1.Column3 = aTransformation.get(0,2);
451 aMatrix.Line2.Column1 = aTransformation.get(1,0);
452 aMatrix.Line2.Column2 = aTransformation.get(1,1);
453 aMatrix.Line2.Column3 = aTransformation.get(1,2);
455 aMatrix.Line3.Column1 = aTransformation.get(2,0);
456 aMatrix.Line3.Column2 = aTransformation.get(2,1);
457 aMatrix.Line3.Column3 = aTransformation.get(2,2);
459 maShapeProperties[ PROP_Transformation ] <<= aMatrix;
462 Reference< lang::XMultiServiceFactory > xServiceFact( rFilterBase.getModel(), UNO_QUERY_THROW );
463 if ( !mxShape.is() )
464 mxShape = Reference< drawing::XShape >( xServiceFact->createInstance( aServiceName ), UNO_QUERY_THROW );
466 Reference< XPropertySet > xSet( mxShape, UNO_QUERY );
467 if( mxShape.is() && xSet.is() )
469 if( !msName.isEmpty() )
471 Reference< container::XNamed > xNamed( mxShape, UNO_QUERY );
472 if( xNamed.is() )
473 xNamed->setName( msName );
475 rxShapes->add( mxShape );
477 if ( mbHidden || mbHiddenMasterShape )
479 SAL_INFO("oox", "invisible shape with id: " << msId);
480 const OUString sVisible( "Visible" );
481 xSet->setPropertyValue( sVisible, Any( sal_False ) );
484 ActionLockGuard const alg(mxShape);
486 // sj: removing default text of placeholder objects such as SlideNumberShape or HeaderShape
487 if ( bClearText )
489 uno::Reference< text::XText > xText( mxShape, uno::UNO_QUERY );
490 if ( xText.is() )
492 OUString aEmpty;
493 xText->setString( aEmpty );
497 const GraphicHelper& rGraphicHelper = rFilterBase.getGraphicHelper();
499 LineProperties aLineProperties;
500 aLineProperties.maLineFill.moFillType = XML_noFill;
501 sal_Int32 nLinePhClr = -1;
502 FillProperties aFillProperties;
503 aFillProperties.moFillType = XML_noFill;
504 sal_Int32 nFillPhClr = -1;
505 EffectProperties aEffectProperties;
506 // TODO: use ph color when applying effect properties
507 //sal_Int32 nEffectPhClr = -1;
509 if( pTheme )
511 if( const ShapeStyleRef* pLineRef = getShapeStyleRef( XML_lnRef ) )
513 if( const LineProperties* pLineProps = pTheme->getLineStyle( pLineRef->mnThemedIdx ) )
514 aLineProperties.assignUsed( *pLineProps );
515 nLinePhClr = pLineRef->maPhClr.getColor( rGraphicHelper );
517 if( const ShapeStyleRef* pFillRef = getShapeStyleRef( XML_fillRef ) )
519 if( const FillProperties* pFillProps = pTheme->getFillStyle( pFillRef->mnThemedIdx ) )
520 aFillProperties.assignUsed( *pFillProps );
521 nFillPhClr = pFillRef->maPhClr.getColor( rGraphicHelper );
523 if( const ShapeStyleRef* pEffectRef = getShapeStyleRef( XML_effectRef ) )
525 if( const EffectProperties* pEffectProps = pTheme->getEffectStyle( pEffectRef->mnThemedIdx ) )
526 aEffectProperties.assignUsed( *pEffectProps );
527 // TODO: use ph color when applying effect properties
528 // nEffectPhClr = pEffectRef->maPhClr.getColor( rGraphicHelper );
532 aLineProperties.assignUsed( getLineProperties() );
534 // group fill inherits from parent
535 if ( getFillProperties().moFillType.has() && getFillProperties().moFillType.get() == XML_grpFill )
536 getFillProperties().assignUsed( rShapeOrParentShapeFillProps );
537 aFillProperties.assignUsed( getFillProperties() );
538 aEffectProperties.assignUsed ( getEffectProperties() );
540 ShapePropertyMap aShapeProps( rFilterBase.getModelObjectHelper() );
542 // add properties from textbody to shape properties
543 if( mpTextBody.get() )
545 mpTextBody->getTextProperties().pushRotationAdjustments( mnRotation );
546 aShapeProps.assignUsed( mpTextBody->getTextProperties().maPropertyMap );
549 // applying properties
550 aShapeProps.assignUsed( getShapeProperties() );
551 aShapeProps.assignUsed( maDefaultShapeProperties );
552 if ( bIsEmbMedia || aServiceName == "com.sun.star.drawing.GraphicObjectShape" || aServiceName == "com.sun.star.drawing.OLE2Shape" )
553 mpGraphicPropertiesPtr->pushToPropMap( aShapeProps, rGraphicHelper );
554 if ( mpTablePropertiesPtr.get() && aServiceName == "com.sun.star.drawing.TableShape" )
555 mpTablePropertiesPtr->pushToPropSet( rFilterBase, xSet, mpMasterTextListStyle );
556 aFillProperties.pushToPropMap( aShapeProps, rGraphicHelper, mnRotation, nFillPhClr, mbFlipH, mbFlipV );
557 aLineProperties.pushToPropMap( aShapeProps, rGraphicHelper, nLinePhClr );
558 // TODO: use ph color when applying effect properties
559 aEffectProperties.pushToPropMap( aShapeProps, rGraphicHelper );
561 // applying autogrowheight property before setting shape size, because
562 // the shape size might be changed if currently autogrowheight is true
563 // we must also check that the PropertySet supports the property.
564 Reference< XPropertySetInfo > xSetInfo( xSet->getPropertySetInfo() );
565 const OUString& rPropName = PropertyMap::getPropertyName( PROP_TextAutoGrowHeight );
566 if( xSetInfo.is() && xSetInfo->hasPropertyByName( rPropName ) )
567 if( aShapeProps.hasProperty( PROP_TextAutoGrowHeight ) )
568 xSet->setPropertyValue( rPropName, Any( false ) );
570 // do not set properties at a group shape (this causes assertions from svx)
571 if( aServiceName != "com.sun.star.drawing.GroupShape" )
573 PropertySet( xSet ).setProperties( aShapeProps );
574 if (mbLockedCanvas && aServiceName == "com.sun.star.drawing.LineShape")
576 // It seems the position and size for lines inside a locked canvas is absolute.
577 mxShape->setPosition(awt::Point(aShapeRectHmm.X, aShapeRectHmm.Y));
578 mxShape->setSize(awt::Size(aShapeRectHmm.Width, aShapeRectHmm.Height));
582 if( bIsCustomShape )
584 if ( mbFlipH )
585 mpCustomShapePropertiesPtr->setMirroredX( sal_True );
586 if ( mbFlipV )
587 mpCustomShapePropertiesPtr->setMirroredY( sal_True );
588 if( getTextBody() )
590 sal_Int32 nTextRotateAngle = static_cast< sal_Int32 >( getTextBody()->getTextProperties().moRotation.get( 0 ) );
591 mpCustomShapePropertiesPtr->setTextRotateAngle( nTextRotateAngle / 60000 );
594 SAL_INFO("oox", "==cscode== shape name: '" << msName << "'");
595 mpCustomShapePropertiesPtr->pushToPropSet( rFilterBase, xSet, mxShape );
597 else if( getTextBody() )
598 getTextBody()->getTextProperties().pushVertSimulation();
600 // in some cases, we don't have any text body.
601 if( getTextBody() && ( !bDoNotInsertEmptyTextBody || !mpTextBody->isEmpty() ) )
603 Reference < XText > xText( mxShape, UNO_QUERY );
604 if ( xText.is() ) // not every shape is supporting an XText interface (e.g. GroupShape)
606 TextCharacterProperties aCharStyleProperties;
607 if( const ShapeStyleRef* pFontRef = getShapeStyleRef( XML_fontRef ) )
609 if( pTheme )
610 if( const TextCharacterProperties* pCharProps = pTheme->getFontStyle( pFontRef->mnThemedIdx ) )
611 aCharStyleProperties.assignUsed( *pCharProps );
612 SAL_INFO("oox", "use font color");
613 aCharStyleProperties.maCharColor.assignIfUsed( pFontRef->maPhClr );
616 Reference < XTextCursor > xAt = xText->createTextCursor();
617 getTextBody()->insertAt( rFilterBase, xText, xAt, aCharStyleProperties, mpMasterTextListStyle );
622 if( mxShape.is() )
623 finalizeXShape( rFilterBase, rxShapes );
625 return mxShape;
628 void Shape::setTextBody(const TextBodyPtr & pTextBody)
630 mpTextBody = pTextBody;
634 TextBodyPtr Shape::getTextBody()
636 return mpTextBody;
639 void Shape::moveAllToPosition( const awt::Point &rPoint )
641 setPosition( awt::Point( rPoint.X + maPosition.X, rPoint.Y + maPosition.Y ) );
642 for( ::std::vector<ShapePtr>::const_iterator aIt = maChildren.begin(), aEnd = maChildren.end();aIt != aEnd; ++aIt )
643 (*aIt)->moveAllToPosition( rPoint );
646 void Shape::setMasterTextListStyle( const TextListStylePtr& pMasterTextListStyle )
648 SAL_INFO("oox", "set master text list style to shape id: " << msId);
650 mpMasterTextListStyle = pMasterTextListStyle;
653 OUString Shape::finalizeServiceName( XmlFilterBase& rFilter, const OUString& rServiceName, const awt::Rectangle& rShapeRect )
655 OUString aServiceName = rServiceName;
656 switch( meFrameType )
658 case FRAMETYPE_OLEOBJECT:
660 awt::Size aOleSize( rShapeRect.Width, rShapeRect.Height );
661 if( rFilter.getOleObjectHelper().importOleObject( maShapeProperties, *mxOleObjectInfo, aOleSize ) )
662 aServiceName = "com.sun.star.drawing.OLE2Shape";
664 // get the path to the representation graphic
665 OUString aGraphicPath;
666 if( !mxOleObjectInfo->maShapeId.isEmpty() )
667 if( ::oox::vml::Drawing* pVmlDrawing = rFilter.getVmlDrawing() )
668 if( const ::oox::vml::ShapeBase* pVmlShape = pVmlDrawing->getShapes().getShapeById( mxOleObjectInfo->maShapeId, true ) )
669 aGraphicPath = pVmlShape->getGraphicPath();
671 // import and store the graphic
672 if( !aGraphicPath.isEmpty() )
674 Reference< graphic::XGraphic > xGraphic = rFilter.getGraphicHelper().importEmbeddedGraphic( aGraphicPath );
675 if( xGraphic.is() )
676 maShapeProperties[ PROP_Graphic ] <<= xGraphic;
679 break;
681 default:;
683 return aServiceName;
686 void Shape::finalizeXShape( XmlFilterBase& rFilter, const Reference< XShapes >& rxShapes )
688 switch( meFrameType )
690 case FRAMETYPE_CHART:
692 OSL_ENSURE( !mxChartShapeInfo->maFragmentPath.isEmpty(), "Shape::finalizeXShape - missing chart fragment" );
693 if( mxShape.is() && !mxChartShapeInfo->maFragmentPath.isEmpty() ) try
695 // set the chart2 OLE class ID at the OLE shape
696 PropertySet aShapeProp( mxShape );
697 aShapeProp.setProperty( PROP_CLSID, OUString( "12dcae26-281f-416f-a234-c3086127382e" ) );
699 // get the XModel interface of the embedded object from the OLE shape
700 Reference< frame::XModel > xDocModel;
701 aShapeProp.getProperty( xDocModel, PROP_Model );
702 Reference< chart2::XChartDocument > xChartDoc( xDocModel, UNO_QUERY_THROW );
704 // load the chart data from the XML fragment
705 chart::ChartSpaceModel aModel;
706 rFilter.importFragment( new chart::ChartSpaceFragment( rFilter, mxChartShapeInfo->maFragmentPath, aModel ) );
708 // convert imported chart model to chart document
709 Reference< drawing::XShapes > xExternalPage;
710 if( !mxChartShapeInfo->mbEmbedShapes )
711 xExternalPage = rxShapes;
712 if( rFilter.getChartConverter() )
713 rFilter.getChartConverter()->convertFromModel( rFilter, aModel, xChartDoc, xExternalPage, mxShape->getPosition(), mxShape->getSize() );
715 catch( Exception& )
719 break;
721 default:;
725 // ============================================================================
729 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */