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 // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir #include "EnhancedCustomShapeEngine.hxx"
31*cdf0e10cSrcweir #include "svx/EnhancedCustomShape2d.hxx"
32*cdf0e10cSrcweir #include "EnhancedCustomShape3d.hxx"
33*cdf0e10cSrcweir #include "EnhancedCustomShapeFontWork.hxx"
34*cdf0e10cSrcweir #include "EnhancedCustomShapeHandle.hxx"
35*cdf0e10cSrcweir #include "svx/EnhancedCustomShapeGeometry.hxx"
36*cdf0e10cSrcweir #include <svx/unoshape.hxx>
37*cdf0e10cSrcweir #ifndef _SVX_UNOPAGE_HXX
38*cdf0e10cSrcweir #include "svx/unopage.hxx"
39*cdf0e10cSrcweir #endif
40*cdf0e10cSrcweir #include "svx/unoapi.hxx"
41*cdf0e10cSrcweir #include <svx/svdobj.hxx>
42*cdf0e10cSrcweir #include <svx/svdoashp.hxx>
43*cdf0e10cSrcweir #include <svx/svdogrp.hxx>
44*cdf0e10cSrcweir #include <svx/svdorect.hxx>
45*cdf0e10cSrcweir #include <editeng/outlobj.hxx>
46*cdf0e10cSrcweir #include <editeng/outliner.hxx>
47*cdf0e10cSrcweir #include <svx/svdoutl.hxx>
48*cdf0e10cSrcweir #include <svl/itemset.hxx>
49*cdf0e10cSrcweir #include <svx/svdopath.hxx>
50*cdf0e10cSrcweir #include <svx/svdpage.hxx>
51*cdf0e10cSrcweir #include <svx/svdmodel.hxx>
52*cdf0e10cSrcweir #include "svx/svditer.hxx"
53*cdf0e10cSrcweir #include "unopolyhelper.hxx"
54*cdf0e10cSrcweir #include <uno/mapping.hxx>
55*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
56*cdf0e10cSrcweir #include <com/sun/star/document/XActionLockable.hpp>
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir // ---------------------------
59*cdf0e10cSrcweir // - EnhancedCustomShapeEngine -
60*cdf0e10cSrcweir // ---------------------------
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir rtl::OUString EnhancedCustomShapeEngine_getImplementationName()
63*cdf0e10cSrcweir 	throw( NMSP_UNO::RuntimeException )
64*cdf0e10cSrcweir {
65*cdf0e10cSrcweir 	return B2UCONST( "com.sun.star.drawing.EnhancedCustomShapeEngine" );
66*cdf0e10cSrcweir }
67*cdf0e10cSrcweir sal_Bool SAL_CALL EnhancedCustomShapeEngine_supportsService( const rtl::OUString& ServiceName )
68*cdf0e10cSrcweir 	throw( NMSP_UNO::RuntimeException )
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir     return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.drawing.CustomShapeEngine" ) );
71*cdf0e10cSrcweir }
72*cdf0e10cSrcweir SEQ( rtl::OUString ) SAL_CALL EnhancedCustomShapeEngine_getSupportedServiceNames()
73*cdf0e10cSrcweir 	throw( NMSP_UNO::RuntimeException )
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir 	SEQ( rtl::OUString ) aRet(1);
76*cdf0e10cSrcweir     rtl::OUString* pArray = aRet.getArray();
77*cdf0e10cSrcweir     pArray[0] = B2UCONST( "com.sun.star.drawing.CustomShapeEngine" );
78*cdf0e10cSrcweir     return aRet;
79*cdf0e10cSrcweir }
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir // -----------------------------------------------------------------------------
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir EnhancedCustomShapeEngine::EnhancedCustomShapeEngine( const REF( NMSP_LANG::XMultiServiceFactory )& rxMgr ) :
84*cdf0e10cSrcweir 	mxFact					( rxMgr ),
85*cdf0e10cSrcweir 	mbForceGroupWithText	( sal_False )
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir }
88*cdf0e10cSrcweir EnhancedCustomShapeEngine::~EnhancedCustomShapeEngine()
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir }
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir // XInterface -----------------------------------------------------------------
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir void SAL_CALL EnhancedCustomShapeEngine::acquire() throw()
95*cdf0e10cSrcweir {
96*cdf0e10cSrcweir 	OWeakObject::acquire();
97*cdf0e10cSrcweir }
98*cdf0e10cSrcweir void SAL_CALL EnhancedCustomShapeEngine::release() throw()
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir 	OWeakObject::release();
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir // XInitialization ------------------------------------------------------------
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir void SAL_CALL EnhancedCustomShapeEngine::initialize( const SEQ( NMSP_UNO::Any )& aArguments )
106*cdf0e10cSrcweir 	throw ( NMSP_UNO::Exception, NMSP_UNO::RuntimeException )
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir 	sal_Int32 i;
109*cdf0e10cSrcweir 	SEQ( NMSP_BEANS::PropertyValue ) aParameter;
110*cdf0e10cSrcweir 	for ( i = 0; i < aArguments.getLength(); i++ )
111*cdf0e10cSrcweir 	{
112*cdf0e10cSrcweir 		if ( aArguments[ i ] >>= aParameter )
113*cdf0e10cSrcweir 			break;
114*cdf0e10cSrcweir 	}
115*cdf0e10cSrcweir 	for ( i = 0; i < aParameter.getLength(); i++ )
116*cdf0e10cSrcweir 	{
117*cdf0e10cSrcweir 		const NMSP_BEANS::PropertyValue& rProp = aParameter[ i ];
118*cdf0e10cSrcweir 		if ( rProp.Name.equalsAscii( "CustomShape" ) )
119*cdf0e10cSrcweir 			rProp.Value >>= mxShape;
120*cdf0e10cSrcweir 		else if ( rProp.Name.equalsAscii( "ForceGroupWithText" ) )
121*cdf0e10cSrcweir 			rProp.Value >>= mbForceGroupWithText;
122*cdf0e10cSrcweir 	}
123*cdf0e10cSrcweir }
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir // XServiceInfo ---------------------------------------------------------------
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir rtl::OUString SAL_CALL EnhancedCustomShapeEngine::getImplementationName()
128*cdf0e10cSrcweir 	throw( NMSP_UNO::RuntimeException )
129*cdf0e10cSrcweir {
130*cdf0e10cSrcweir 	return EnhancedCustomShapeEngine_getImplementationName();
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir sal_Bool SAL_CALL EnhancedCustomShapeEngine::supportsService( const rtl::OUString& rServiceName )
133*cdf0e10cSrcweir 	throw( NMSP_UNO::RuntimeException )
134*cdf0e10cSrcweir {
135*cdf0e10cSrcweir     return EnhancedCustomShapeEngine_supportsService( rServiceName );
136*cdf0e10cSrcweir }
137*cdf0e10cSrcweir SEQ( rtl::OUString ) SAL_CALL EnhancedCustomShapeEngine::getSupportedServiceNames()
138*cdf0e10cSrcweir 	throw ( NMSP_UNO::RuntimeException )
139*cdf0e10cSrcweir {
140*cdf0e10cSrcweir     return EnhancedCustomShapeEngine_getSupportedServiceNames();
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir // XCustomShapeEngine -----------------------------------------------------------
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir SdrObject* EnhancedCustomShapeEngine::ImplForceGroupWithText( const SdrObjCustomShape* pCustoObj, SdrObject* pRenderedShape )
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir 	bool bHasText = pCustoObj->HasText();
148*cdf0e10cSrcweir 	if ( pRenderedShape || bHasText )
149*cdf0e10cSrcweir 	{
150*cdf0e10cSrcweir 		// applying shadow
151*cdf0e10cSrcweir 		const SdrObject* pShadowGeometry = pCustoObj->GetSdrObjectShadowFromCustomShape();
152*cdf0e10cSrcweir 		if ( pShadowGeometry )
153*cdf0e10cSrcweir 		{
154*cdf0e10cSrcweir 			if ( pRenderedShape )
155*cdf0e10cSrcweir 			{
156*cdf0e10cSrcweir 				if ( !pRenderedShape->ISA( SdrObjGroup ) )
157*cdf0e10cSrcweir 				{
158*cdf0e10cSrcweir 					SdrObject* pTmp = pRenderedShape;
159*cdf0e10cSrcweir 					pRenderedShape = new SdrObjGroup();
160*cdf0e10cSrcweir 					((SdrObjGroup*)pRenderedShape)->GetSubList()->NbcInsertObject( pTmp );
161*cdf0e10cSrcweir 				}
162*cdf0e10cSrcweir 				((SdrObjGroup*)pRenderedShape)->GetSubList()->NbcInsertObject( pShadowGeometry->Clone(), 0 );
163*cdf0e10cSrcweir 			}
164*cdf0e10cSrcweir 			else
165*cdf0e10cSrcweir 				pRenderedShape = pShadowGeometry->Clone();
166*cdf0e10cSrcweir 		}
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 		// apply text
169*cdf0e10cSrcweir 		if ( bHasText )
170*cdf0e10cSrcweir 		{
171*cdf0e10cSrcweir 			// #i37011# also create a text object and add at rPos + 1
172*cdf0e10cSrcweir 			SdrTextObj* pTextObj = (SdrTextObj*)SdrObjFactory::MakeNewObject(
173*cdf0e10cSrcweir 				pCustoObj->GetObjInventor(), OBJ_TEXT, 0L, pCustoObj->GetModel());
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 			// Copy text content
176*cdf0e10cSrcweir 			OutlinerParaObject* pParaObj = pCustoObj->GetOutlinerParaObject();
177*cdf0e10cSrcweir 			if( pParaObj )
178*cdf0e10cSrcweir 				pTextObj->NbcSetOutlinerParaObject( new OutlinerParaObject(*pParaObj) );
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 			// copy all attributes
181*cdf0e10cSrcweir 			SfxItemSet aTargetItemSet( pCustoObj->GetMergedItemSet() );
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir 			// clear fill and line style
184*cdf0e10cSrcweir 			aTargetItemSet.Put(XLineStyleItem(XLINE_NONE));
185*cdf0e10cSrcweir 			aTargetItemSet.Put(XFillStyleItem(XFILL_NONE));
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir 			// get the text bounds and set at text object
188*cdf0e10cSrcweir 			Rectangle aTextBounds = pCustoObj->GetSnapRect();
189*cdf0e10cSrcweir 			SdrObject* pSdrObjCustomShape( GetSdrObjectFromXShape( mxShape ) );
190*cdf0e10cSrcweir 			if ( pSdrObjCustomShape )
191*cdf0e10cSrcweir 			{
192*cdf0e10cSrcweir 				EnhancedCustomShape2d aCustomShape2d( pSdrObjCustomShape );
193*cdf0e10cSrcweir 				aTextBounds = aCustomShape2d.GetTextRect();
194*cdf0e10cSrcweir 			}
195*cdf0e10cSrcweir 			pTextObj->SetSnapRect( aTextBounds );
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 			// if rotated, copy GeoStat, too.
198*cdf0e10cSrcweir 			const GeoStat& rSourceGeo = pCustoObj->GetGeoStat();
199*cdf0e10cSrcweir 			if ( rSourceGeo.nDrehWink )
200*cdf0e10cSrcweir 			{
201*cdf0e10cSrcweir 				pTextObj->NbcRotate(
202*cdf0e10cSrcweir 					pCustoObj->GetSnapRect().Center(), rSourceGeo.nDrehWink,
203*cdf0e10cSrcweir 					rSourceGeo.nSin, rSourceGeo.nCos);
204*cdf0e10cSrcweir 			}
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir 			// set modified ItemSet at text object
207*cdf0e10cSrcweir 			pTextObj->SetMergedItemSet(aTargetItemSet);
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 			if ( pRenderedShape )
210*cdf0e10cSrcweir 			{
211*cdf0e10cSrcweir 				if ( !pRenderedShape->ISA( SdrObjGroup ) )
212*cdf0e10cSrcweir 				{
213*cdf0e10cSrcweir 					SdrObject* pTmp = pRenderedShape;
214*cdf0e10cSrcweir 					pRenderedShape = new SdrObjGroup();
215*cdf0e10cSrcweir 					((SdrObjGroup*)pRenderedShape)->GetSubList()->NbcInsertObject( pTmp );
216*cdf0e10cSrcweir 				}
217*cdf0e10cSrcweir 				((SdrObjGroup*)pRenderedShape)->GetSubList()->NbcInsertObject( pTextObj, LIST_APPEND );
218*cdf0e10cSrcweir 			}
219*cdf0e10cSrcweir 			else
220*cdf0e10cSrcweir 				pRenderedShape = pTextObj;
221*cdf0e10cSrcweir 		}
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 		// force group
224*cdf0e10cSrcweir 		if ( pRenderedShape )
225*cdf0e10cSrcweir 		{
226*cdf0e10cSrcweir 			if ( !pRenderedShape->ISA( SdrObjGroup ) )
227*cdf0e10cSrcweir 			{
228*cdf0e10cSrcweir 				SdrObject* pTmp = pRenderedShape;
229*cdf0e10cSrcweir 				pRenderedShape = new SdrObjGroup();
230*cdf0e10cSrcweir 				((SdrObjGroup*)pRenderedShape)->GetSubList()->NbcInsertObject( pTmp );
231*cdf0e10cSrcweir 			}
232*cdf0e10cSrcweir 			pRenderedShape->SetPage( pCustoObj->GetPage() );
233*cdf0e10cSrcweir 			pRenderedShape->SetModel( pCustoObj->GetModel() );
234*cdf0e10cSrcweir 		}
235*cdf0e10cSrcweir 	}
236*cdf0e10cSrcweir 	return pRenderedShape;
237*cdf0e10cSrcweir }
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir void SetTemporary( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xShape )
240*cdf0e10cSrcweir {
241*cdf0e10cSrcweir 	if ( xShape.is() )
242*cdf0e10cSrcweir 	{
243*cdf0e10cSrcweir 		SvxShape* pShape = SvxShape::getImplementation( xShape );
244*cdf0e10cSrcweir 		if ( pShape )
245*cdf0e10cSrcweir 			pShape->TakeSdrObjectOwnership();
246*cdf0e10cSrcweir /*
247*cdf0e10cSrcweir 		::com::sun::star::uno::Reference<
248*cdf0e10cSrcweir 			::com::sun::star::drawing::XShapes > xShapes( xShape, ::com::sun::star::uno::UNO_QUERY );
249*cdf0e10cSrcweir 		if ( xShapes.is() )
250*cdf0e10cSrcweir 		{
251*cdf0e10cSrcweir 			sal_Int32 i;
252*cdf0e10cSrcweir 			for ( i = 0; i < xShapes->getCount(); i++ )
253*cdf0e10cSrcweir 			{
254*cdf0e10cSrcweir 	            ::com::sun::star::uno::Any aAny( xShapes->getByIndex( i ) );
255*cdf0e10cSrcweir 				::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape;
256*cdf0e10cSrcweir 				if ( aAny >>= xShape )
257*cdf0e10cSrcweir 					SetTemporary( xShape );
258*cdf0e10cSrcweir 			}
259*cdf0e10cSrcweir 		}
260*cdf0e10cSrcweir */
261*cdf0e10cSrcweir 	}
262*cdf0e10cSrcweir }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir REF( com::sun::star::drawing::XShape ) SAL_CALL EnhancedCustomShapeEngine::render()
265*cdf0e10cSrcweir 	throw ( NMSP_UNO::RuntimeException )
266*cdf0e10cSrcweir {
267*cdf0e10cSrcweir 	REF( com::sun::star::drawing::XShape ) xShape;
268*cdf0e10cSrcweir 	SdrObject* pSdrObjCustomShape( GetSdrObjectFromXShape( mxShape ) );
269*cdf0e10cSrcweir 	if ( pSdrObjCustomShape )
270*cdf0e10cSrcweir 	{
271*cdf0e10cSrcweir 		// retrieving the TextPath property to check if feature is enabled
272*cdf0e10cSrcweir 		SdrCustomShapeGeometryItem& rGeometryItem = (SdrCustomShapeGeometryItem&)
273*cdf0e10cSrcweir 			pSdrObjCustomShape->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY );
274*cdf0e10cSrcweir 		sal_Bool bTextPathOn = sal_False;
275*cdf0e10cSrcweir 		const rtl::OUString	sTextPath( RTL_CONSTASCII_USTRINGPARAM ( "TextPath" ) );
276*cdf0e10cSrcweir 		com::sun::star::uno::Any* pAny = rGeometryItem.GetPropertyValueByName( sTextPath, sTextPath );
277*cdf0e10cSrcweir 		if ( pAny )
278*cdf0e10cSrcweir 			*pAny >>= bTextPathOn;
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir 		EnhancedCustomShape2d aCustomShape2d( pSdrObjCustomShape );
281*cdf0e10cSrcweir 		sal_Int32 nRotateAngle = aCustomShape2d.GetRotateAngle();
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir 		sal_Bool bFlipV = aCustomShape2d.IsFlipVert();
284*cdf0e10cSrcweir 		sal_Bool bFlipH = aCustomShape2d.IsFlipHorz();
285*cdf0e10cSrcweir 		sal_Bool bLineGeometryNeededOnly = bTextPathOn;
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir 		SdrObject* pRenderedShape = aCustomShape2d.CreateObject( bLineGeometryNeededOnly );
288*cdf0e10cSrcweir 		if ( pRenderedShape )
289*cdf0e10cSrcweir 		{
290*cdf0e10cSrcweir 			if ( bTextPathOn )
291*cdf0e10cSrcweir 			{
292*cdf0e10cSrcweir 				SdrObject* pRenderedFontWork = EnhancedCustomShapeFontWork::CreateFontWork( pRenderedShape, pSdrObjCustomShape );
293*cdf0e10cSrcweir 				if ( pRenderedFontWork )
294*cdf0e10cSrcweir                 {
295*cdf0e10cSrcweir                     SdrObject::Free( pRenderedShape );
296*cdf0e10cSrcweir                     pRenderedShape = pRenderedFontWork;
297*cdf0e10cSrcweir                 }
298*cdf0e10cSrcweir 			}
299*cdf0e10cSrcweir 			SdrObject* pRenderedShape3d = EnhancedCustomShape3d::Create3DObject( pRenderedShape, pSdrObjCustomShape );
300*cdf0e10cSrcweir 			if ( pRenderedShape3d )
301*cdf0e10cSrcweir 			{
302*cdf0e10cSrcweir 				bFlipV = bFlipH = sal_False;
303*cdf0e10cSrcweir 				nRotateAngle = 0;
304*cdf0e10cSrcweir                 SdrObject::Free( pRenderedShape );
305*cdf0e10cSrcweir 				pRenderedShape = pRenderedShape3d;
306*cdf0e10cSrcweir 			}
307*cdf0e10cSrcweir 			Rectangle aRect( pSdrObjCustomShape->GetSnapRect() );
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir 			const GeoStat& rGeoStat = ((SdrObjCustomShape*)pSdrObjCustomShape)->GetGeoStat();
310*cdf0e10cSrcweir 			if ( rGeoStat.nShearWink )
311*cdf0e10cSrcweir 			{
312*cdf0e10cSrcweir 				long nShearWink = rGeoStat.nShearWink;
313*cdf0e10cSrcweir 				double nTan = rGeoStat.nTan;
314*cdf0e10cSrcweir 				if ((bFlipV&&!bFlipH )||(bFlipH&&!bFlipV))
315*cdf0e10cSrcweir 				{
316*cdf0e10cSrcweir 					nShearWink = -nShearWink;
317*cdf0e10cSrcweir 					nTan = -nTan;
318*cdf0e10cSrcweir 				}
319*cdf0e10cSrcweir 				pRenderedShape->Shear( pSdrObjCustomShape->GetSnapRect().Center(), nShearWink, nTan, sal_False);
320*cdf0e10cSrcweir 			}
321*cdf0e10cSrcweir 			if( nRotateAngle )
322*cdf0e10cSrcweir 			{
323*cdf0e10cSrcweir 				double a = nRotateAngle * F_PI18000;
324*cdf0e10cSrcweir 				pRenderedShape->NbcRotate( pSdrObjCustomShape->GetSnapRect().Center(), nRotateAngle, sin( a ), cos( a ) );
325*cdf0e10cSrcweir 			}
326*cdf0e10cSrcweir 			if ( bFlipV )
327*cdf0e10cSrcweir 			{
328*cdf0e10cSrcweir 				Point aLeft( aRect.Left(), ( aRect.Top() + aRect.Bottom() ) >> 1 );
329*cdf0e10cSrcweir 				Point aRight( aLeft.X() + 1000, aLeft.Y() );
330*cdf0e10cSrcweir 				pRenderedShape->NbcMirror( aLeft, aRight );
331*cdf0e10cSrcweir 			}
332*cdf0e10cSrcweir 			if ( bFlipH )
333*cdf0e10cSrcweir 			{
334*cdf0e10cSrcweir 				Point aTop( ( aRect.Left() + aRect.Right() ) >> 1, aRect.Top() );
335*cdf0e10cSrcweir 				Point aBottom( aTop.X(), aTop.Y() + 1000 );
336*cdf0e10cSrcweir 				pRenderedShape->NbcMirror( aTop, aBottom );
337*cdf0e10cSrcweir 			}
338*cdf0e10cSrcweir 			pRenderedShape->NbcSetStyleSheet( pSdrObjCustomShape->GetStyleSheet(), sal_True );
339*cdf0e10cSrcweir 			pRenderedShape->RecalcSnapRect();
340*cdf0e10cSrcweir 		}
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 		if ( mbForceGroupWithText )
343*cdf0e10cSrcweir 			pRenderedShape = ImplForceGroupWithText( (SdrObjCustomShape*)pSdrObjCustomShape, pRenderedShape );
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 		if ( pRenderedShape )
346*cdf0e10cSrcweir 		{
347*cdf0e10cSrcweir 			aCustomShape2d.ApplyGluePoints( pRenderedShape );
348*cdf0e10cSrcweir 			xShape = SvxDrawPage::CreateShapeByTypeAndInventor( pRenderedShape->GetObjIdentifier(),
349*cdf0e10cSrcweir 				pRenderedShape->GetObjInventor(), pRenderedShape, NULL );
350*cdf0e10cSrcweir 		}
351*cdf0e10cSrcweir 		SetTemporary( xShape );
352*cdf0e10cSrcweir 	}
353*cdf0e10cSrcweir 	return xShape;
354*cdf0e10cSrcweir }
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir com::sun::star::awt::Rectangle SAL_CALL EnhancedCustomShapeEngine::getTextBounds()
357*cdf0e10cSrcweir 	throw ( NMSP_UNO::RuntimeException )
358*cdf0e10cSrcweir {
359*cdf0e10cSrcweir 	com::sun::star::awt::Rectangle aTextRect;
360*cdf0e10cSrcweir 	SdrObject* pSdrObjCustomShape( GetSdrObjectFromXShape( mxShape ) );
361*cdf0e10cSrcweir 	::com::sun::star::uno::Reference< ::com::sun::star::document::XActionLockable > xLockable( mxShape, ::com::sun::star::uno::UNO_QUERY );
362*cdf0e10cSrcweir 	if ( pSdrObjCustomShape && pSdrObjCustomShape->GetModel() && xLockable.is() && !xLockable->isActionLocked() )
363*cdf0e10cSrcweir 	{
364*cdf0e10cSrcweir 		if ( pSdrObjCustomShape )
365*cdf0e10cSrcweir 		{
366*cdf0e10cSrcweir 			EnhancedCustomShape2d aCustomShape2d( pSdrObjCustomShape );
367*cdf0e10cSrcweir 			Rectangle aRect( aCustomShape2d.GetTextRect() );
368*cdf0e10cSrcweir 			aTextRect.X = aRect.Left();
369*cdf0e10cSrcweir 			aTextRect.Y = aRect.Top();
370*cdf0e10cSrcweir 			aTextRect.Width = aRect.GetWidth();
371*cdf0e10cSrcweir 			aTextRect.Height = aRect.GetHeight();
372*cdf0e10cSrcweir 		}
373*cdf0e10cSrcweir 	}
374*cdf0e10cSrcweir 	return aTextRect;
375*cdf0e10cSrcweir }
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir com::sun::star::drawing::PolyPolygonBezierCoords SAL_CALL EnhancedCustomShapeEngine::getLineGeometry()
378*cdf0e10cSrcweir 	throw ( NMSP_UNO::RuntimeException )
379*cdf0e10cSrcweir {
380*cdf0e10cSrcweir 	com::sun::star::drawing::PolyPolygonBezierCoords aPolyPolygonBezierCoords;
381*cdf0e10cSrcweir 	SdrObject* pSdrObjCustomShape( GetSdrObjectFromXShape( mxShape ) );
382*cdf0e10cSrcweir 	if ( pSdrObjCustomShape )
383*cdf0e10cSrcweir 	{
384*cdf0e10cSrcweir 		EnhancedCustomShape2d aCustomShape2d( pSdrObjCustomShape );
385*cdf0e10cSrcweir 		SdrObject* pObj = aCustomShape2d.CreateLineGeometry();
386*cdf0e10cSrcweir 		if ( pObj )
387*cdf0e10cSrcweir 		{
388*cdf0e10cSrcweir 			Rectangle aRect( pSdrObjCustomShape->GetSnapRect() );
389*cdf0e10cSrcweir 			sal_Bool bFlipV = aCustomShape2d.IsFlipVert();
390*cdf0e10cSrcweir 			sal_Bool bFlipH = aCustomShape2d.IsFlipHorz();
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir 			const GeoStat& rGeoStat = ((SdrObjCustomShape*)pSdrObjCustomShape)->GetGeoStat();
393*cdf0e10cSrcweir 			if ( rGeoStat.nShearWink )
394*cdf0e10cSrcweir 			{
395*cdf0e10cSrcweir 				long nShearWink = rGeoStat.nShearWink;
396*cdf0e10cSrcweir 				double nTan = rGeoStat.nTan;
397*cdf0e10cSrcweir 				if ((bFlipV&&!bFlipH )||(bFlipH&&!bFlipV))
398*cdf0e10cSrcweir 				{
399*cdf0e10cSrcweir 					nShearWink = -nShearWink;
400*cdf0e10cSrcweir 					nTan = -nTan;
401*cdf0e10cSrcweir 				}
402*cdf0e10cSrcweir 				pObj->Shear( aRect.Center(), nShearWink, nTan, sal_False);
403*cdf0e10cSrcweir 			}
404*cdf0e10cSrcweir 			sal_Int32 nRotateAngle = aCustomShape2d.GetRotateAngle();
405*cdf0e10cSrcweir 			if( nRotateAngle )
406*cdf0e10cSrcweir 			{
407*cdf0e10cSrcweir 				double a = nRotateAngle * F_PI18000;
408*cdf0e10cSrcweir 				pObj->NbcRotate( aRect.Center(), nRotateAngle, sin( a ), cos( a ) );
409*cdf0e10cSrcweir 			}
410*cdf0e10cSrcweir 			if ( bFlipH )
411*cdf0e10cSrcweir 			{
412*cdf0e10cSrcweir 				Point aTop( ( aRect.Left() + aRect.Right() ) >> 1, aRect.Top() );
413*cdf0e10cSrcweir 				Point aBottom( aTop.X(), aTop.Y() + 1000 );
414*cdf0e10cSrcweir 				pObj->NbcMirror( aTop, aBottom );
415*cdf0e10cSrcweir 			}
416*cdf0e10cSrcweir 			if ( bFlipV )
417*cdf0e10cSrcweir 			{
418*cdf0e10cSrcweir 				Point aLeft( aRect.Left(), ( aRect.Top() + aRect.Bottom() ) >> 1 );
419*cdf0e10cSrcweir 				Point aRight( aLeft.X() + 1000, aLeft.Y() );
420*cdf0e10cSrcweir 				pObj->NbcMirror( aLeft, aRight );
421*cdf0e10cSrcweir 			}
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir 			basegfx::B2DPolyPolygon aPolyPolygon;
424*cdf0e10cSrcweir 			SdrObjListIter aIter( *pObj, IM_DEEPWITHGROUPS );
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir 			while ( aIter.IsMore() )
427*cdf0e10cSrcweir 			{
428*cdf0e10cSrcweir 				SdrObject* pNewObj = NULL;
429*cdf0e10cSrcweir 				basegfx::B2DPolyPolygon aPP;
430*cdf0e10cSrcweir 				const SdrObject* pNext = aIter.Next();
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir 				if ( pNext->ISA( SdrPathObj ) )
433*cdf0e10cSrcweir 				{
434*cdf0e10cSrcweir 					aPP = ((SdrPathObj*)pNext)->GetPathPoly();
435*cdf0e10cSrcweir 				}
436*cdf0e10cSrcweir 				else
437*cdf0e10cSrcweir 				{
438*cdf0e10cSrcweir 					pNewObj = pNext->ConvertToPolyObj( sal_False, sal_False );
439*cdf0e10cSrcweir 					SdrPathObj* pPath = PTR_CAST( SdrPathObj, pNewObj );
440*cdf0e10cSrcweir 					if ( pPath )
441*cdf0e10cSrcweir 						aPP = pPath->GetPathPoly();
442*cdf0e10cSrcweir 				}
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir 				if ( aPP.count() )
445*cdf0e10cSrcweir 					aPolyPolygon.append(aPP);
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir 				SdrObject::Free( pNewObj );
448*cdf0e10cSrcweir 			}
449*cdf0e10cSrcweir             SdrObject::Free( pObj );
450*cdf0e10cSrcweir 			SvxConvertB2DPolyPolygonToPolyPolygonBezier( aPolyPolygon, aPolyPolygonBezierCoords );
451*cdf0e10cSrcweir 		}
452*cdf0e10cSrcweir 	}
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir 	return aPolyPolygonBezierCoords;
455*cdf0e10cSrcweir }
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir SEQ( REF( com::sun::star::drawing::XCustomShapeHandle ) ) SAL_CALL EnhancedCustomShapeEngine::getInteraction()
458*cdf0e10cSrcweir 	throw ( NMSP_UNO::RuntimeException )
459*cdf0e10cSrcweir {
460*cdf0e10cSrcweir 	sal_uInt32 i, nHdlCount = 0;
461*cdf0e10cSrcweir 	SdrObject* pSdrObjCustomShape = GetSdrObjectFromXShape( mxShape );
462*cdf0e10cSrcweir 	if ( pSdrObjCustomShape )
463*cdf0e10cSrcweir 	{
464*cdf0e10cSrcweir 		EnhancedCustomShape2d aCustomShape2d( pSdrObjCustomShape );
465*cdf0e10cSrcweir 		nHdlCount = aCustomShape2d.GetHdlCount();
466*cdf0e10cSrcweir 	}
467*cdf0e10cSrcweir 	SEQ( REF( com::sun::star::drawing::XCustomShapeHandle ) ) aSeq( nHdlCount );
468*cdf0e10cSrcweir 	for ( i = 0; i < nHdlCount; i++ )
469*cdf0e10cSrcweir 		aSeq[ i ] = new EnhancedCustomShapeHandle( mxShape, i );
470*cdf0e10cSrcweir 	return aSeq;
471*cdf0e10cSrcweir }
472