xref: /AOO41X/main/oox/source/drawingml/shape.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "oox/drawingml/shape.hxx"
29*cdf0e10cSrcweir #include "oox/drawingml/customshapeproperties.hxx"
30*cdf0e10cSrcweir #include "oox/drawingml/theme.hxx"
31*cdf0e10cSrcweir #include "oox/drawingml/fillproperties.hxx"
32*cdf0e10cSrcweir #include "oox/drawingml/lineproperties.hxx"
33*cdf0e10cSrcweir #include "oox/drawingml/shapepropertymap.hxx"
34*cdf0e10cSrcweir #include "oox/drawingml/textbody.hxx"
35*cdf0e10cSrcweir #include "oox/drawingml/table/tableproperties.hxx"
36*cdf0e10cSrcweir #include "oox/drawingml/chart/chartconverter.hxx"
37*cdf0e10cSrcweir #include "oox/drawingml/chart/chartspacefragment.hxx"
38*cdf0e10cSrcweir #include "oox/drawingml/chart/chartspacemodel.hxx"
39*cdf0e10cSrcweir #include "oox/vml/vmldrawing.hxx"
40*cdf0e10cSrcweir #include "oox/vml/vmlshape.hxx"
41*cdf0e10cSrcweir #include "oox/vml/vmlshapecontainer.hxx"
42*cdf0e10cSrcweir #include "oox/core/xmlfilterbase.hxx"
43*cdf0e10cSrcweir #include "oox/helper/graphichelper.hxx"
44*cdf0e10cSrcweir #include "oox/helper/propertyset.hxx"
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #include <tools/solar.h>        // for the F_PI180 define
47*cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphic.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/beans/XMultiPropertySet.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/drawing/HomogenMatrix3.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/text/XText.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/chart2/XChartDocument.hpp>
54*cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
55*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
56*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
57*cdf0e10cSrcweir #include <com/sun/star/document/XActionLockable.hpp>
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir using rtl::OUString;
60*cdf0e10cSrcweir using namespace ::oox::core;
61*cdf0e10cSrcweir using namespace ::com::sun::star;
62*cdf0e10cSrcweir using namespace ::com::sun::star::awt;
63*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
64*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
65*cdf0e10cSrcweir using namespace ::com::sun::star::frame;
66*cdf0e10cSrcweir using namespace ::com::sun::star::text;
67*cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir namespace oox { namespace drawingml {
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir // ============================================================================
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir Shape::Shape( const sal_Char* pServiceName )
74*cdf0e10cSrcweir : mpLinePropertiesPtr( new LineProperties )
75*cdf0e10cSrcweir , mpFillPropertiesPtr( new FillProperties )
76*cdf0e10cSrcweir , mpGraphicPropertiesPtr( new GraphicProperties )
77*cdf0e10cSrcweir , mpCustomShapePropertiesPtr( new CustomShapeProperties )
78*cdf0e10cSrcweir , mpMasterTextListStyle( new TextListStyle )
79*cdf0e10cSrcweir , mnSubType( 0 )
80*cdf0e10cSrcweir , mnSubTypeIndex( -1 )
81*cdf0e10cSrcweir , meFrameType( FRAMETYPE_GENERIC )
82*cdf0e10cSrcweir , mnRotation( 0 )
83*cdf0e10cSrcweir , mbFlipH( false )
84*cdf0e10cSrcweir , mbFlipV( false )
85*cdf0e10cSrcweir , mbHidden( false )
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir     if ( pServiceName )
88*cdf0e10cSrcweir         msServiceName = OUString::createFromAscii( pServiceName );
89*cdf0e10cSrcweir     setDefaults();
90*cdf0e10cSrcweir }
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir Shape::~Shape()
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir table::TablePropertiesPtr Shape::getTableProperties()
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir     if ( !mpTablePropertiesPtr.get() )
99*cdf0e10cSrcweir         mpTablePropertiesPtr.reset( new table::TableProperties() );
100*cdf0e10cSrcweir     return mpTablePropertiesPtr;
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir void Shape::setDefaults()
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir     maShapeProperties[ PROP_TextAutoGrowHeight ] <<= false;
106*cdf0e10cSrcweir     maShapeProperties[ PROP_TextWordWrap ] <<= true;
107*cdf0e10cSrcweir     maShapeProperties[ PROP_TextLeftDistance ]  <<= static_cast< sal_Int32 >( 250 );
108*cdf0e10cSrcweir     maShapeProperties[ PROP_TextUpperDistance ] <<= static_cast< sal_Int32 >( 125 );
109*cdf0e10cSrcweir     maShapeProperties[ PROP_TextRightDistance ] <<= static_cast< sal_Int32 >( 250 );
110*cdf0e10cSrcweir     maShapeProperties[ PROP_TextLowerDistance ] <<= static_cast< sal_Int32 >( 125 );
111*cdf0e10cSrcweir     maShapeProperties[ PROP_CharHeight ] <<= static_cast< float >( 18.0 );
112*cdf0e10cSrcweir }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir ::oox::vml::OleObjectInfo& Shape::setOleObjectType()
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir     OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setOleObjectType - multiple frame types" );
117*cdf0e10cSrcweir     meFrameType = FRAMETYPE_OLEOBJECT;
118*cdf0e10cSrcweir     mxOleObjectInfo.reset( new ::oox::vml::OleObjectInfo( true ) );
119*cdf0e10cSrcweir     return *mxOleObjectInfo;
120*cdf0e10cSrcweir }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir ChartShapeInfo& Shape::setChartType( bool bEmbedShapes )
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir     OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setChartType - multiple frame types" );
125*cdf0e10cSrcweir     meFrameType = FRAMETYPE_CHART;
126*cdf0e10cSrcweir 	msServiceName = CREATE_OUSTRING( "com.sun.star.drawing.OLE2Shape" );
127*cdf0e10cSrcweir     mxChartShapeInfo.reset( new ChartShapeInfo( bEmbedShapes ) );
128*cdf0e10cSrcweir     return *mxChartShapeInfo;
129*cdf0e10cSrcweir }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir void Shape::setDiagramType()
132*cdf0e10cSrcweir {
133*cdf0e10cSrcweir     OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setDiagramType - multiple frame types" );
134*cdf0e10cSrcweir     meFrameType = FRAMETYPE_DIAGRAM;
135*cdf0e10cSrcweir 	msServiceName = CREATE_OUSTRING( "com.sun.star.drawing.GroupShape" );
136*cdf0e10cSrcweir 	mnSubType = 0;
137*cdf0e10cSrcweir }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir void Shape::setTableType()
140*cdf0e10cSrcweir {
141*cdf0e10cSrcweir     OSL_ENSURE( meFrameType == FRAMETYPE_GENERIC, "Shape::setTableType - multiple frame types" );
142*cdf0e10cSrcweir     meFrameType = FRAMETYPE_TABLE;
143*cdf0e10cSrcweir 	msServiceName = CREATE_OUSTRING( "com.sun.star.drawing.TableShape" );
144*cdf0e10cSrcweir 	mnSubType = 0;
145*cdf0e10cSrcweir }
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir void Shape::setServiceName( const sal_Char* pServiceName )
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir     if ( pServiceName )
150*cdf0e10cSrcweir         msServiceName = OUString::createFromAscii( pServiceName );
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir const ShapeStyleRef* Shape::getShapeStyleRef( sal_Int32 nRefType ) const
155*cdf0e10cSrcweir {
156*cdf0e10cSrcweir     ShapeStyleRefMap::const_iterator aIt = maShapeStyleRefs.find( nRefType );
157*cdf0e10cSrcweir     return (aIt == maShapeStyleRefs.end()) ? 0 : &aIt->second;
158*cdf0e10cSrcweir }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir void Shape::addShape(
161*cdf0e10cSrcweir         ::oox::core::XmlFilterBase& rFilterBase,
162*cdf0e10cSrcweir         const Theme* pTheme,
163*cdf0e10cSrcweir         const Reference< XShapes >& rxShapes,
164*cdf0e10cSrcweir         const awt::Rectangle* pShapeRect,
165*cdf0e10cSrcweir         ShapeIdMap* pShapeMap )
166*cdf0e10cSrcweir {
167*cdf0e10cSrcweir     try
168*cdf0e10cSrcweir     {
169*cdf0e10cSrcweir         rtl::OUString sServiceName( msServiceName );
170*cdf0e10cSrcweir         if( sServiceName.getLength() )
171*cdf0e10cSrcweir         {
172*cdf0e10cSrcweir             Reference< XShape > xShape( createAndInsert( rFilterBase, sServiceName, pTheme, rxShapes, pShapeRect, sal_False ) );
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir             if( pShapeMap && msId.getLength() )
175*cdf0e10cSrcweir             {
176*cdf0e10cSrcweir                 (*pShapeMap)[ msId ] = shared_from_this();
177*cdf0e10cSrcweir             }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir             // if this is a group shape, we have to add also each child shape
180*cdf0e10cSrcweir             Reference< XShapes > xShapes( xShape, UNO_QUERY );
181*cdf0e10cSrcweir             if ( xShapes.is() )
182*cdf0e10cSrcweir                 addChildren( rFilterBase, *this, pTheme, xShapes, pShapeRect ? *pShapeRect : awt::Rectangle( maPosition.X, maPosition.Y, maSize.Width, maSize.Height ), pShapeMap );
183*cdf0e10cSrcweir         }
184*cdf0e10cSrcweir     }
185*cdf0e10cSrcweir     catch( const Exception&  )
186*cdf0e10cSrcweir     {
187*cdf0e10cSrcweir     }
188*cdf0e10cSrcweir }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir void Shape::applyShapeReference( const Shape& rReferencedShape )
191*cdf0e10cSrcweir {
192*cdf0e10cSrcweir     mpTextBody = TextBodyPtr( new TextBody( *rReferencedShape.mpTextBody.get() ) );
193*cdf0e10cSrcweir     maShapeProperties = rReferencedShape.maShapeProperties;
194*cdf0e10cSrcweir     mpLinePropertiesPtr = LinePropertiesPtr( new LineProperties( *rReferencedShape.mpLinePropertiesPtr.get() ) );
195*cdf0e10cSrcweir     mpFillPropertiesPtr = FillPropertiesPtr( new FillProperties( *rReferencedShape.mpFillPropertiesPtr.get() ) );
196*cdf0e10cSrcweir     mpCustomShapePropertiesPtr = CustomShapePropertiesPtr( new CustomShapeProperties( *rReferencedShape.mpCustomShapePropertiesPtr.get() ) );
197*cdf0e10cSrcweir     mpTablePropertiesPtr = table::TablePropertiesPtr( rReferencedShape.mpTablePropertiesPtr.get() ? new table::TableProperties( *rReferencedShape.mpTablePropertiesPtr.get() ) : NULL );
198*cdf0e10cSrcweir     mpMasterTextListStyle = TextListStylePtr( new TextListStyle( *rReferencedShape.mpMasterTextListStyle.get() ) );
199*cdf0e10cSrcweir     maShapeStyleRefs = rReferencedShape.maShapeStyleRefs;
200*cdf0e10cSrcweir     maSize = rReferencedShape.maSize;
201*cdf0e10cSrcweir     maPosition = rReferencedShape.maPosition;
202*cdf0e10cSrcweir     mnRotation = rReferencedShape.mnRotation;
203*cdf0e10cSrcweir     mbFlipH = rReferencedShape.mbFlipH;
204*cdf0e10cSrcweir     mbFlipV = rReferencedShape.mbFlipV;
205*cdf0e10cSrcweir 	mbHidden = rReferencedShape.mbHidden;
206*cdf0e10cSrcweir }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir // for group shapes, the following method is also adding each child
209*cdf0e10cSrcweir void Shape::addChildren(
210*cdf0e10cSrcweir         XmlFilterBase& rFilterBase,
211*cdf0e10cSrcweir         Shape& rMaster,
212*cdf0e10cSrcweir         const Theme* pTheme,
213*cdf0e10cSrcweir         const Reference< XShapes >& rxShapes,
214*cdf0e10cSrcweir         const awt::Rectangle& rClientRect,
215*cdf0e10cSrcweir         ShapeIdMap* pShapeMap )
216*cdf0e10cSrcweir {
217*cdf0e10cSrcweir     // first the global child union needs to be calculated
218*cdf0e10cSrcweir     sal_Int32 nGlobalLeft  = SAL_MAX_INT32;
219*cdf0e10cSrcweir     sal_Int32 nGlobalRight = SAL_MIN_INT32;
220*cdf0e10cSrcweir     sal_Int32 nGlobalTop   = SAL_MAX_INT32;
221*cdf0e10cSrcweir     sal_Int32 nGlobalBottom= SAL_MIN_INT32;
222*cdf0e10cSrcweir     std::vector< ShapePtr >::iterator aIter( rMaster.maChildren.begin() );
223*cdf0e10cSrcweir     while( aIter != rMaster.maChildren.end() )
224*cdf0e10cSrcweir     {
225*cdf0e10cSrcweir         sal_Int32 l = (*aIter)->maPosition.X;
226*cdf0e10cSrcweir         sal_Int32 t = (*aIter)->maPosition.Y;
227*cdf0e10cSrcweir         sal_Int32 r = l + (*aIter)->maSize.Width;
228*cdf0e10cSrcweir         sal_Int32 b = t + (*aIter)->maSize.Height;
229*cdf0e10cSrcweir         if ( nGlobalLeft > l )
230*cdf0e10cSrcweir             nGlobalLeft = l;
231*cdf0e10cSrcweir         if ( nGlobalRight < r )
232*cdf0e10cSrcweir             nGlobalRight = r;
233*cdf0e10cSrcweir         if ( nGlobalTop > t )
234*cdf0e10cSrcweir             nGlobalTop = t;
235*cdf0e10cSrcweir         if ( nGlobalBottom < b )
236*cdf0e10cSrcweir             nGlobalBottom = b;
237*cdf0e10cSrcweir         aIter++;
238*cdf0e10cSrcweir     }
239*cdf0e10cSrcweir     aIter = rMaster.maChildren.begin();
240*cdf0e10cSrcweir     while( aIter != rMaster.maChildren.end() )
241*cdf0e10cSrcweir     {
242*cdf0e10cSrcweir         awt::Rectangle aShapeRect;
243*cdf0e10cSrcweir         awt::Rectangle* pShapeRect = 0;
244*cdf0e10cSrcweir         if ( ( nGlobalLeft != SAL_MAX_INT32 ) && ( nGlobalRight != SAL_MIN_INT32 ) && ( nGlobalTop != SAL_MAX_INT32 ) && ( nGlobalBottom != SAL_MIN_INT32 ) )
245*cdf0e10cSrcweir         {
246*cdf0e10cSrcweir             sal_Int32 nGlobalWidth = nGlobalRight - nGlobalLeft;
247*cdf0e10cSrcweir             sal_Int32 nGlobalHeight = nGlobalBottom - nGlobalTop;
248*cdf0e10cSrcweir             if ( nGlobalWidth && nGlobalHeight )
249*cdf0e10cSrcweir             {
250*cdf0e10cSrcweir                 double fWidth = (*aIter)->maSize.Width;
251*cdf0e10cSrcweir                 double fHeight= (*aIter)->maSize.Height;
252*cdf0e10cSrcweir                 double fXScale = (double)rClientRect.Width / (double)nGlobalWidth;
253*cdf0e10cSrcweir                 double fYScale = (double)rClientRect.Height / (double)nGlobalHeight;
254*cdf0e10cSrcweir                 aShapeRect.X = static_cast< sal_Int32 >( ( ( (*aIter)->maPosition.X - nGlobalLeft ) * fXScale ) + rClientRect.X );
255*cdf0e10cSrcweir                 aShapeRect.Y = static_cast< sal_Int32 >( ( ( (*aIter)->maPosition.Y - nGlobalTop  ) * fYScale ) + rClientRect.Y );
256*cdf0e10cSrcweir                 fWidth *= fXScale;
257*cdf0e10cSrcweir                 fHeight *= fYScale;
258*cdf0e10cSrcweir                 aShapeRect.Width = static_cast< sal_Int32 >( fWidth );
259*cdf0e10cSrcweir                 aShapeRect.Height = static_cast< sal_Int32 >( fHeight );
260*cdf0e10cSrcweir                 pShapeRect = &aShapeRect;
261*cdf0e10cSrcweir             }
262*cdf0e10cSrcweir         }
263*cdf0e10cSrcweir         (*aIter++)->addShape( rFilterBase, pTheme, rxShapes, pShapeRect, pShapeMap );
264*cdf0e10cSrcweir     }
265*cdf0e10cSrcweir }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir Reference< XShape > Shape::createAndInsert(
268*cdf0e10cSrcweir         ::oox::core::XmlFilterBase& rFilterBase,
269*cdf0e10cSrcweir         const rtl::OUString& rServiceName,
270*cdf0e10cSrcweir         const Theme* pTheme,
271*cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
272*cdf0e10cSrcweir         const awt::Rectangle* pShapeRect,
273*cdf0e10cSrcweir 		sal_Bool bClearText )
274*cdf0e10cSrcweir {
275*cdf0e10cSrcweir     awt::Size aSize( pShapeRect ? awt::Size( pShapeRect->Width, pShapeRect->Height ) : maSize );
276*cdf0e10cSrcweir     awt::Point aPosition( pShapeRect ? awt::Point( pShapeRect->X, pShapeRect->Y ) : maPosition );
277*cdf0e10cSrcweir     awt::Rectangle aShapeRectHmm( aPosition.X / 360, aPosition.Y / 360, aSize.Width / 360, aSize.Height / 360 );
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir     OUString aServiceName = finalizeServiceName( rFilterBase, rServiceName, aShapeRectHmm );
280*cdf0e10cSrcweir 	sal_Bool bIsCustomShape = aServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.drawing.CustomShape" ) );
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir     basegfx::B2DHomMatrix aTransformation;
283*cdf0e10cSrcweir     if( aSize.Width != 1 || aSize.Height != 1)
284*cdf0e10cSrcweir     {
285*cdf0e10cSrcweir         // take care there are no zeros used by error
286*cdf0e10cSrcweir         aTransformation.scale(
287*cdf0e10cSrcweir             aSize.Width ? aSize.Width / 360.0 : 1.0,
288*cdf0e10cSrcweir             aSize.Height ? aSize.Height / 360.0 : 1.0 );
289*cdf0e10cSrcweir     }
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir     if( mbFlipH || mbFlipV || mnRotation != 0)
292*cdf0e10cSrcweir     {
293*cdf0e10cSrcweir         // calculate object's center
294*cdf0e10cSrcweir         basegfx::B2DPoint aCenter(0.5, 0.5);
295*cdf0e10cSrcweir         aCenter *= aTransformation;
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir         // center object at origin
298*cdf0e10cSrcweir         aTransformation.translate( -aCenter.getX(), -aCenter.getY() );
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir         if( !bIsCustomShape && ( mbFlipH || mbFlipV ) )
301*cdf0e10cSrcweir         {
302*cdf0e10cSrcweir             // mirror around object's center
303*cdf0e10cSrcweir             aTransformation.scale( mbFlipH ? -1.0 : 1.0, mbFlipV ? -1.0 : 1.0 );
304*cdf0e10cSrcweir         }
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir         if( mnRotation != 0 )
307*cdf0e10cSrcweir         {
308*cdf0e10cSrcweir             // rotate around object's center
309*cdf0e10cSrcweir             aTransformation.rotate( F_PI180 * ( (double)mnRotation / 60000.0 ) );
310*cdf0e10cSrcweir         }
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir         // move object back from center
313*cdf0e10cSrcweir         aTransformation.translate( aCenter.getX(), aCenter.getY() );
314*cdf0e10cSrcweir     }
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir     if( aPosition.X != 0 || aPosition.Y != 0)
317*cdf0e10cSrcweir     {
318*cdf0e10cSrcweir         // if global position is used, add it to transformation
319*cdf0e10cSrcweir         aTransformation.translate( aPosition.X / 360.0, aPosition.Y / 360.0 );
320*cdf0e10cSrcweir     }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir     // special for lineshape
323*cdf0e10cSrcweir     if ( aServiceName == OUString::createFromAscii( "com.sun.star.drawing.LineShape" ) )
324*cdf0e10cSrcweir     {
325*cdf0e10cSrcweir         ::basegfx::B2DPolygon aPoly;
326*cdf0e10cSrcweir         aPoly.insert( 0, ::basegfx::B2DPoint( 0, 0 ) );
327*cdf0e10cSrcweir         aPoly.insert( 1, ::basegfx::B2DPoint( maSize.Width ? 1 : 0, maSize.Height ? 1 : 0 ) );
328*cdf0e10cSrcweir         aPoly.transform( aTransformation );
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir         // now creating the corresponding PolyPolygon
331*cdf0e10cSrcweir         sal_Int32 i, nNumPoints = aPoly.count();
332*cdf0e10cSrcweir         uno::Sequence< awt::Point > aPointSequence( nNumPoints );
333*cdf0e10cSrcweir         awt::Point* pPoints = aPointSequence.getArray();
334*cdf0e10cSrcweir         for( i = 0; i < nNumPoints; ++i )
335*cdf0e10cSrcweir         {
336*cdf0e10cSrcweir             const ::basegfx::B2DPoint aPoint( aPoly.getB2DPoint( i ) );
337*cdf0e10cSrcweir             pPoints[ i ] = awt::Point( static_cast< sal_Int32 >( aPoint.getX() ), static_cast< sal_Int32 >( aPoint.getY() ) );
338*cdf0e10cSrcweir         }
339*cdf0e10cSrcweir         uno::Sequence< uno::Sequence< awt::Point > > aPolyPolySequence( 1 );
340*cdf0e10cSrcweir         aPolyPolySequence.getArray()[ 0 ] = aPointSequence;
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir         maShapeProperties[ PROP_PolyPolygon ] <<= aPolyPolySequence;
343*cdf0e10cSrcweir     }
344*cdf0e10cSrcweir     else if ( aServiceName == OUString::createFromAscii( "com.sun.star.drawing.ConnectorShape" ) )
345*cdf0e10cSrcweir     {
346*cdf0e10cSrcweir         ::basegfx::B2DPolygon aPoly;
347*cdf0e10cSrcweir         aPoly.insert( 0, ::basegfx::B2DPoint( 0, 0 ) );
348*cdf0e10cSrcweir         aPoly.insert( 1, ::basegfx::B2DPoint( maSize.Width ? 1 : 0, maSize.Height ? 1 : 0 ) );
349*cdf0e10cSrcweir         aPoly.transform( aTransformation );
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir         basegfx::B2DPoint aStartPosition( aPoly.getB2DPoint( 0 ) );
352*cdf0e10cSrcweir         basegfx::B2DPoint aEndPosition( aPoly.getB2DPoint( 1 ) );
353*cdf0e10cSrcweir         awt::Point aAWTStartPosition( static_cast< sal_Int32 >( aStartPosition.getX() ), static_cast< sal_Int32 >( aStartPosition.getY() ) );
354*cdf0e10cSrcweir         awt::Point aAWTEndPosition( static_cast< sal_Int32 >( aEndPosition.getX() ), static_cast< sal_Int32 >( aEndPosition.getY() ) );
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir         maShapeProperties[ PROP_StartPosition ] <<= aAWTStartPosition;
357*cdf0e10cSrcweir         maShapeProperties[ PROP_EndPosition ] <<= aAWTEndPosition;
358*cdf0e10cSrcweir     }
359*cdf0e10cSrcweir     else
360*cdf0e10cSrcweir     {
361*cdf0e10cSrcweir         // now set transformation for this object
362*cdf0e10cSrcweir         HomogenMatrix3 aMatrix;
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir         aMatrix.Line1.Column1 = aTransformation.get(0,0);
365*cdf0e10cSrcweir         aMatrix.Line1.Column2 = aTransformation.get(0,1);
366*cdf0e10cSrcweir         aMatrix.Line1.Column3 = aTransformation.get(0,2);
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir         aMatrix.Line2.Column1 = aTransformation.get(1,0);
369*cdf0e10cSrcweir         aMatrix.Line2.Column2 = aTransformation.get(1,1);
370*cdf0e10cSrcweir         aMatrix.Line2.Column3 = aTransformation.get(1,2);
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir         aMatrix.Line3.Column1 = aTransformation.get(2,0);
373*cdf0e10cSrcweir         aMatrix.Line3.Column2 = aTransformation.get(2,1);
374*cdf0e10cSrcweir         aMatrix.Line3.Column3 = aTransformation.get(2,2);
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir         maShapeProperties[ PROP_Transformation ] <<= aMatrix;
377*cdf0e10cSrcweir     }
378*cdf0e10cSrcweir     Reference< lang::XMultiServiceFactory > xServiceFact( rFilterBase.getModel(), UNO_QUERY_THROW );
379*cdf0e10cSrcweir 	if ( !mxShape.is() )
380*cdf0e10cSrcweir         mxShape = Reference< drawing::XShape >( xServiceFact->createInstance( aServiceName ), UNO_QUERY_THROW );
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir     Reference< XPropertySet > xSet( mxShape, UNO_QUERY );
383*cdf0e10cSrcweir     if( mxShape.is() && xSet.is() )
384*cdf0e10cSrcweir     {
385*cdf0e10cSrcweir         if( msName.getLength() )
386*cdf0e10cSrcweir         {
387*cdf0e10cSrcweir             Reference< container::XNamed > xNamed( mxShape, UNO_QUERY );
388*cdf0e10cSrcweir             if( xNamed.is() )
389*cdf0e10cSrcweir                 xNamed->setName( msName );
390*cdf0e10cSrcweir         }
391*cdf0e10cSrcweir 	    rxShapes->add( mxShape );
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir 		if ( mbHidden )
394*cdf0e10cSrcweir 		{
395*cdf0e10cSrcweir 			const OUString sHidden( CREATE_OUSTRING( "Visible" ) );
396*cdf0e10cSrcweir 			xSet->setPropertyValue( sHidden, Any( !mbHidden ) );
397*cdf0e10cSrcweir 		}
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir 		Reference< document::XActionLockable > xLockable( mxShape, UNO_QUERY );
400*cdf0e10cSrcweir 		if( xLockable.is() )
401*cdf0e10cSrcweir 			xLockable->addActionLock();
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir 		// sj: removing default text of placeholder objects such as SlideNumberShape or HeaderShape
404*cdf0e10cSrcweir 		if ( bClearText )
405*cdf0e10cSrcweir 		{
406*cdf0e10cSrcweir 			uno::Reference< text::XText > xText( mxShape, uno::UNO_QUERY );
407*cdf0e10cSrcweir 			if ( xText.is() )
408*cdf0e10cSrcweir 			{
409*cdf0e10cSrcweir 				OUString aEmpty;
410*cdf0e10cSrcweir 				xText->setString( aEmpty );
411*cdf0e10cSrcweir 			}
412*cdf0e10cSrcweir 		}
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir         const GraphicHelper& rGraphicHelper = rFilterBase.getGraphicHelper();
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir 		LineProperties aLineProperties;
417*cdf0e10cSrcweir         aLineProperties.maLineFill.moFillType = XML_noFill;
418*cdf0e10cSrcweir         sal_Int32 nLinePhClr = -1;
419*cdf0e10cSrcweir         FillProperties aFillProperties;
420*cdf0e10cSrcweir         aFillProperties.moFillType = XML_noFill;
421*cdf0e10cSrcweir         sal_Int32 nFillPhClr = -1;
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir         if( pTheme )
424*cdf0e10cSrcweir         {
425*cdf0e10cSrcweir             if( const ShapeStyleRef* pLineRef = getShapeStyleRef( XML_lnRef ) )
426*cdf0e10cSrcweir             {
427*cdf0e10cSrcweir                 if( const LineProperties* pLineProps = pTheme->getLineStyle( pLineRef->mnThemedIdx ) )
428*cdf0e10cSrcweir                     aLineProperties.assignUsed( *pLineProps );
429*cdf0e10cSrcweir                 nLinePhClr = pLineRef->maPhClr.getColor( rGraphicHelper );
430*cdf0e10cSrcweir             }
431*cdf0e10cSrcweir             if( const ShapeStyleRef* pFillRef = getShapeStyleRef( XML_fillRef ) )
432*cdf0e10cSrcweir             {
433*cdf0e10cSrcweir                 if( const FillProperties* pFillProps = pTheme->getFillStyle( pFillRef->mnThemedIdx ) )
434*cdf0e10cSrcweir                     aFillProperties.assignUsed( *pFillProps );
435*cdf0e10cSrcweir                 nFillPhClr = pFillRef->maPhClr.getColor( rGraphicHelper );
436*cdf0e10cSrcweir             }
437*cdf0e10cSrcweir //            if( const ShapeStyleRef* pEffectRef = getShapeStyleRef( XML_fillRef ) )
438*cdf0e10cSrcweir //            {
439*cdf0e10cSrcweir //                if( const EffectProperties* pEffectProps = pTheme->getEffectStyle( pEffectRef->mnThemedIdx ) )
440*cdf0e10cSrcweir //                    aEffectProperties.assignUsed( *pEffectProps );
441*cdf0e10cSrcweir //                nEffectPhClr = pEffectRef->maPhClr.getColor( rGraphicHelper );
442*cdf0e10cSrcweir //            }
443*cdf0e10cSrcweir         }
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir         aLineProperties.assignUsed( getLineProperties() );
446*cdf0e10cSrcweir         aFillProperties.assignUsed( getFillProperties() );
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir         ShapePropertyMap aShapeProps( rFilterBase.getModelObjectHelper() );
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir         // add properties from textbody to shape properties
451*cdf0e10cSrcweir         if( mpTextBody.get() )
452*cdf0e10cSrcweir             aShapeProps.assignUsed( mpTextBody->getTextProperties().maPropertyMap );
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir         // applying properties
455*cdf0e10cSrcweir         aShapeProps.assignUsed( getShapeProperties() );
456*cdf0e10cSrcweir         if ( aServiceName == OUString::createFromAscii( "com.sun.star.drawing.GraphicObjectShape" ) )
457*cdf0e10cSrcweir             mpGraphicPropertiesPtr->pushToPropMap( aShapeProps, rGraphicHelper );
458*cdf0e10cSrcweir         if ( mpTablePropertiesPtr.get() && ( aServiceName == OUString::createFromAscii( "com.sun.star.drawing.TableShape" ) ) )
459*cdf0e10cSrcweir 		    mpTablePropertiesPtr->pushToPropSet( rFilterBase, xSet, mpMasterTextListStyle );
460*cdf0e10cSrcweir         aFillProperties.pushToPropMap( aShapeProps, rGraphicHelper, mnRotation, nFillPhClr );
461*cdf0e10cSrcweir         aLineProperties.pushToPropMap( aShapeProps, rGraphicHelper, nLinePhClr );
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir         // applying autogrowheight property before setting shape size, because
464*cdf0e10cSrcweir         // the shape size might be changed if currently autogrowheight is true
465*cdf0e10cSrcweir         // we must also check that the PropertySet supports the property.
466*cdf0e10cSrcweir         Reference< XPropertySetInfo > xSetInfo( xSet->getPropertySetInfo() );
467*cdf0e10cSrcweir         const OUString& rPropName = PropertyMap::getPropertyName( PROP_TextAutoGrowHeight );
468*cdf0e10cSrcweir         if( xSetInfo.is() && xSetInfo->hasPropertyByName( rPropName ) )
469*cdf0e10cSrcweir             if( aShapeProps.hasProperty( PROP_TextAutoGrowHeight ) )
470*cdf0e10cSrcweir                 xSet->setPropertyValue( rPropName, Any( false ) );
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir         // do not set properties at a group shape (this causes assertions from svx)
473*cdf0e10cSrcweir         if( aServiceName != OUString::createFromAscii( "com.sun.star.drawing.GroupShape" ) )
474*cdf0e10cSrcweir             PropertySet( xSet ).setProperties( aShapeProps );
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir         if( bIsCustomShape )
477*cdf0e10cSrcweir 		{
478*cdf0e10cSrcweir 			if ( mbFlipH )
479*cdf0e10cSrcweir 				mpCustomShapePropertiesPtr->setMirroredX( sal_True );
480*cdf0e10cSrcweir 			if ( mbFlipV )
481*cdf0e10cSrcweir 				mpCustomShapePropertiesPtr->setMirroredY( sal_True );
482*cdf0e10cSrcweir             mpCustomShapePropertiesPtr->pushToPropSet( rFilterBase, xSet, mxShape );
483*cdf0e10cSrcweir 		}
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir         // in some cases, we don't have any text body.
486*cdf0e10cSrcweir         if( getTextBody() )
487*cdf0e10cSrcweir         {
488*cdf0e10cSrcweir             Reference < XText > xText( mxShape, UNO_QUERY );
489*cdf0e10cSrcweir             if ( xText.is() )   // not every shape is supporting an XText interface (e.g. GroupShape)
490*cdf0e10cSrcweir             {
491*cdf0e10cSrcweir                 TextCharacterProperties aCharStyleProperties;
492*cdf0e10cSrcweir                 if( const ShapeStyleRef* pFontRef = getShapeStyleRef( XML_fontRef ) )
493*cdf0e10cSrcweir                 {
494*cdf0e10cSrcweir                     if( pTheme )
495*cdf0e10cSrcweir                         if( const TextCharacterProperties* pCharProps = pTheme->getFontStyle( pFontRef->mnThemedIdx ) )
496*cdf0e10cSrcweir                             aCharStyleProperties.assignUsed( *pCharProps );
497*cdf0e10cSrcweir                     aCharStyleProperties.maCharColor.assignIfUsed( pFontRef->maPhClr );
498*cdf0e10cSrcweir                 }
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir                 Reference < XTextCursor > xAt = xText->createTextCursor();
501*cdf0e10cSrcweir                 getTextBody()->insertAt( rFilterBase, xText, xAt, aCharStyleProperties, mpMasterTextListStyle );
502*cdf0e10cSrcweir             }
503*cdf0e10cSrcweir         }
504*cdf0e10cSrcweir         if( xLockable.is() )
505*cdf0e10cSrcweir 			xLockable->removeActionLock();
506*cdf0e10cSrcweir     }
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir     if( mxShape.is() )
509*cdf0e10cSrcweir         finalizeXShape( rFilterBase, rxShapes );
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir     return mxShape;
512*cdf0e10cSrcweir }
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir // the properties of rSource which are not part of rDest are being put into rDest
515*cdf0e10cSrcweir void addMissingProperties( const PropertyMap& rSource, PropertyMap& rDest )
516*cdf0e10cSrcweir {
517*cdf0e10cSrcweir     PropertyMap::const_iterator aSourceIter( rSource.begin() );
518*cdf0e10cSrcweir     while( aSourceIter != rSource.end() )
519*cdf0e10cSrcweir     {
520*cdf0e10cSrcweir         if ( rDest.find( (*aSourceIter ).first ) == rDest.end() )
521*cdf0e10cSrcweir             rDest[ (*aSourceIter).first ] <<= (*aSourceIter).second;
522*cdf0e10cSrcweir         aSourceIter++;
523*cdf0e10cSrcweir     }
524*cdf0e10cSrcweir }
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir void Shape::setTextBody(const TextBodyPtr & pTextBody)
527*cdf0e10cSrcweir {
528*cdf0e10cSrcweir     mpTextBody = pTextBody;
529*cdf0e10cSrcweir }
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir TextBodyPtr Shape::getTextBody()
533*cdf0e10cSrcweir {
534*cdf0e10cSrcweir     return mpTextBody;
535*cdf0e10cSrcweir }
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir void Shape::setMasterTextListStyle( const TextListStylePtr& pMasterTextListStyle )
538*cdf0e10cSrcweir {
539*cdf0e10cSrcweir     mpMasterTextListStyle = pMasterTextListStyle;
540*cdf0e10cSrcweir }
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir OUString Shape::finalizeServiceName( XmlFilterBase& rFilter, const OUString& rServiceName, const Rectangle& rShapeRect )
543*cdf0e10cSrcweir {
544*cdf0e10cSrcweir     OUString aServiceName = rServiceName;
545*cdf0e10cSrcweir     switch( meFrameType )
546*cdf0e10cSrcweir     {
547*cdf0e10cSrcweir         case FRAMETYPE_OLEOBJECT:
548*cdf0e10cSrcweir         {
549*cdf0e10cSrcweir             Size aOleSize( rShapeRect.Width, rShapeRect.Height );
550*cdf0e10cSrcweir             if( rFilter.getOleObjectHelper().importOleObject( maShapeProperties, *mxOleObjectInfo, aOleSize ) )
551*cdf0e10cSrcweir                 aServiceName = CREATE_OUSTRING( "com.sun.star.drawing.OLE2Shape" );
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir             // get the path to the representation graphic
554*cdf0e10cSrcweir             OUString aGraphicPath;
555*cdf0e10cSrcweir             if( mxOleObjectInfo->maShapeId.getLength() > 0 )
556*cdf0e10cSrcweir                 if( ::oox::vml::Drawing* pVmlDrawing = rFilter.getVmlDrawing() )
557*cdf0e10cSrcweir                     if( const ::oox::vml::ShapeBase* pVmlShape = pVmlDrawing->getShapes().getShapeById( mxOleObjectInfo->maShapeId, true ) )
558*cdf0e10cSrcweir                         aGraphicPath = pVmlShape->getGraphicPath();
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir             // import and store the graphic
561*cdf0e10cSrcweir             if( aGraphicPath.getLength() > 0 )
562*cdf0e10cSrcweir             {
563*cdf0e10cSrcweir                 Reference< graphic::XGraphic > xGraphic = rFilter.getGraphicHelper().importEmbeddedGraphic( aGraphicPath );
564*cdf0e10cSrcweir                 if( xGraphic.is() )
565*cdf0e10cSrcweir                     maShapeProperties[ PROP_Graphic ] <<= xGraphic;
566*cdf0e10cSrcweir             }
567*cdf0e10cSrcweir         }
568*cdf0e10cSrcweir         break;
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir         default:;
571*cdf0e10cSrcweir     }
572*cdf0e10cSrcweir     return aServiceName;
573*cdf0e10cSrcweir }
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir void Shape::finalizeXShape( XmlFilterBase& rFilter, const Reference< XShapes >& rxShapes )
576*cdf0e10cSrcweir {
577*cdf0e10cSrcweir     switch( meFrameType )
578*cdf0e10cSrcweir     {
579*cdf0e10cSrcweir         case FRAMETYPE_CHART:
580*cdf0e10cSrcweir         {
581*cdf0e10cSrcweir             OSL_ENSURE( mxChartShapeInfo->maFragmentPath.getLength() > 0, "Shape::finalizeXShape - missing chart fragment" );
582*cdf0e10cSrcweir             if( mxShape.is() && (mxChartShapeInfo->maFragmentPath.getLength() > 0) ) try
583*cdf0e10cSrcweir             {
584*cdf0e10cSrcweir                 // set the chart2 OLE class ID at the OLE shape
585*cdf0e10cSrcweir                 PropertySet aShapeProp( mxShape );
586*cdf0e10cSrcweir                 aShapeProp.setProperty( PROP_CLSID, CREATE_OUSTRING( "12dcae26-281f-416f-a234-c3086127382e" ) );
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir                 // get the XModel interface of the embedded object from the OLE shape
589*cdf0e10cSrcweir                 Reference< frame::XModel > xDocModel;
590*cdf0e10cSrcweir                 aShapeProp.getProperty( xDocModel, PROP_Model );
591*cdf0e10cSrcweir                 Reference< chart2::XChartDocument > xChartDoc( xDocModel, UNO_QUERY_THROW );
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir                 // load the chart data from the XML fragment
594*cdf0e10cSrcweir                 chart::ChartSpaceModel aModel;
595*cdf0e10cSrcweir                 rFilter.importFragment( new chart::ChartSpaceFragment( rFilter, mxChartShapeInfo->maFragmentPath, aModel ) );
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir                 // convert imported chart model to chart document
598*cdf0e10cSrcweir                 Reference< drawing::XShapes > xExternalPage;
599*cdf0e10cSrcweir                 if( !mxChartShapeInfo->mbEmbedShapes )
600*cdf0e10cSrcweir                     xExternalPage = rxShapes;
601*cdf0e10cSrcweir                 rFilter.getChartConverter().convertFromModel( rFilter, aModel, xChartDoc, xExternalPage, mxShape->getPosition(), mxShape->getSize() );
602*cdf0e10cSrcweir             }
603*cdf0e10cSrcweir             catch( Exception& )
604*cdf0e10cSrcweir             {
605*cdf0e10cSrcweir             }
606*cdf0e10cSrcweir         }
607*cdf0e10cSrcweir         break;
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir         default:;
610*cdf0e10cSrcweir     }
611*cdf0e10cSrcweir }
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir // ============================================================================
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir } }
616