xref: /aoo42x/main/svx/source/svdraw/svdoashp.cxx (revision 4334f1b5)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 #include <svx/svdoashp.hxx>
27 #include "svx/unoapi.hxx"
28 #include <svx/unoshape.hxx>
29 #include <ucbhelper/content.hxx>
30 #include <ucbhelper/contentbroker.hxx>
31 #include <unotools/datetime.hxx>
32 #include <sfx2/lnkbase.hxx>
33 #include <tools/urlobj.hxx>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/drawing/XShape.hpp>
36 #include <com/sun/star/drawing/XCustomShapeEngine.hpp>
37 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
38 #include <com/sun/star/beans/PropertyValue.hpp>
39 #include <com/sun/star/awt/Rectangle.hpp>
40 #include "unopolyhelper.hxx"
41 #include <comphelper/processfactory.hxx>
42 #include <svl/urihelper.hxx>
43 #include <com/sun/star/uno/Sequence.h>
44 #include <svx/svdogrp.hxx>
45 #include <vcl/salbtype.hxx>		// FRound
46 #include <svx/svddrag.hxx>
47 #include <svx/xpool.hxx>
48 #include <svx/xpoly.hxx>
49 #include <svx/svdmodel.hxx>
50 #include <svx/svdpage.hxx>
51 #include "svx/svditer.hxx"
52 #include <svx/svdobj.hxx>
53 #include <svx/svdtrans.hxx>
54 #include <svx/svdetc.hxx>
55 #include <svx/svdattrx.hxx>  // NotPersistItems
56 #include <svx/svdoedge.hxx>  // #32383# Die Verbinder nach Move nochmal anbroadcasten
57 #include "svx/svdglob.hxx"   // StringCache
58 #include "svx/svdstr.hrc"    // Objektname
59 #include <editeng/eeitem.hxx>
60 #include "editeng/editstat.hxx"
61 #include <svx/svdoutl.hxx>
62 #include <editeng/outlobj.hxx>
63 #include <svx/sdtfchim.hxx>
64 #include "../svx/EnhancedCustomShapeGeometry.hxx"
65 #include "../svx/EnhancedCustomShapeTypeNames.hxx"
66 #include "../svx/EnhancedCustomShape2d.hxx"
67 #include <com/sun/star/beans/PropertyValues.hpp>
68 #include <com/sun/star/drawing/EnhancedCustomShapeAdjustmentValue.hpp>
69 #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
70 #include <com/sun/star/drawing/EnhancedCustomShapeTextFrame.hpp>
71 #include <com/sun/star/drawing/EnhancedCustomShapeSegment.hpp>
72 #include <com/sun/star/drawing/EnhancedCustomShapeSegmentCommand.hpp>
73 #include <editeng/writingmodeitem.hxx>
74 #include <svx/xlnclit.hxx>
75 #include <svx/svxids.hrc>
76 #include <svl/whiter.hxx>
77 #include <svx/sdr/properties/customshapeproperties.hxx>
78 #include <svx/sdr/contact/viewcontactofsdrobjcustomshape.hxx>
79 #include <svx/xlnclit.hxx>
80 #include <svx/xlntrit.hxx>
81 #include <svx/xfltrit.hxx>
82 #include <svx/xflclit.hxx>
83 #include <svx/xflgrit.hxx>
84 #include <svx/xflhtit.hxx>
85 #include <svx/xbtmpit.hxx>
86 #include <vcl/bmpacc.hxx>
87 #include <svx/svdview.hxx>
88 #include <basegfx/polygon/b2dpolypolygontools.hxx>
89 #include <basegfx/matrix/b2dhommatrix.hxx>
90 #include <basegfx/matrix/b2dhommatrixtools.hxx>
91 
92 // #104018# replace macros above with type-safe methods
93 inline double ImplTwipsToMM(double fVal) { return (fVal * (127.0 / 72.0)); }
94 inline double ImplMMToTwips(double fVal) { return (fVal * (72.0 / 127.0)); }
95 
96 using namespace ::com::sun::star;
97 using namespace ::com::sun::star::uno;
98 using namespace ::com::sun::star::lang;
99 using namespace ::com::sun::star::beans;
100 using namespace ::com::sun::star::drawing;
101 
102 static MSO_SPT ImpGetCustomShapeType( const SdrObjCustomShape& rCustoShape )
103 {
104 	MSO_SPT eRetValue = mso_sptNil;
105 
106 	rtl::OUString aEngine( ( (SdrCustomShapeEngineItem&)rCustoShape.GetMergedItem( SDRATTR_CUSTOMSHAPE_ENGINE ) ).GetValue() );
107 	if ( !aEngine.getLength() || aEngine.equalsAscii( "com.sun.star.drawing.EnhancedCustomShapeEngine" ) )
108 	{
109 		rtl::OUString sShapeType;
110 		const rtl::OUString	sType( RTL_CONSTASCII_USTRINGPARAM ( "Type" ) );
111 		SdrCustomShapeGeometryItem& rGeometryItem( (SdrCustomShapeGeometryItem&)rCustoShape.GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
112 		Any* pAny = rGeometryItem.GetPropertyValueByName( sType );
113 		if ( pAny && ( *pAny >>= sShapeType ) )
114 			eRetValue = EnhancedCustomShapeTypeNames::Get( sShapeType );
115 	}
116 	return eRetValue;
117 };
118 
119 static sal_Bool ImpVerticalSwitch( const SdrObjCustomShape& rCustoShape )
120 {
121 	sal_Bool bRet = sal_False;
122 	MSO_SPT eShapeType( ImpGetCustomShapeType( rCustoShape ) );
123 	switch( eShapeType )
124 	{
125 		case mso_sptAccentBorderCallout90 :		// 2 ortho
126 		case mso_sptBorderCallout1 :			// 2 diag
127 		case mso_sptBorderCallout2 :			// 3
128 		{
129 			bRet = sal_True;
130 		}
131 		break;
132 /*
133 		case mso_sptCallout1 :
134 		case mso_sptAccentCallout1 :
135 		case mso_sptAccentBorderCallout1 :
136 		case mso_sptBorderCallout90 :
137 		case mso_sptCallout90 :
138 		case mso_sptAccentCallout90 :
139 		case mso_sptCallout2 :
140 		case mso_sptCallout3 :
141 		case mso_sptAccentCallout2 :
142 		case mso_sptAccentCallout3 :
143 		case mso_sptBorderCallout3 :
144 		case mso_sptAccentBorderCallout2 :
145 		case mso_sptAccentBorderCallout3 :
146 */
147 		default: break;
148 	}
149 	return bRet;
150 }
151 
152 ////////////////////////////////////////////////////////////////////////////////////////////////////
153 // #i37011# create a clone with all attributes changed to shadow attributes
154 // and translation executed, too.
155 SdrObject* ImpCreateShadowObjectClone(const SdrObject& rOriginal, const SfxItemSet& rOriginalSet)
156 {
157 	SdrObject* pRetval = 0L;
158 	const sal_Bool bShadow(((SdrShadowItem&)rOriginalSet.Get(SDRATTR_SHADOW)).GetValue());
159 
160 	if(bShadow)
161 	{
162 		// create a shadow representing object
163 		const sal_Int32 nXDist(((SdrShadowXDistItem&)(rOriginalSet.Get(SDRATTR_SHADOWXDIST))).GetValue());
164 		const sal_Int32 nYDist(((SdrShadowYDistItem&)(rOriginalSet.Get(SDRATTR_SHADOWYDIST))).GetValue());
165 		const ::Color aShadowColor(((SdrShadowColorItem&)(rOriginalSet.Get(SDRATTR_SHADOWCOLOR))).GetColorValue());
166 		const sal_uInt16 nShadowTransparence(((SdrShadowTransparenceItem&)(rOriginalSet.Get(SDRATTR_SHADOWTRANSPARENCE))).GetValue());
167 		pRetval = rOriginal.Clone();
168 		DBG_ASSERT(pRetval, "ImpCreateShadowObjectClone: Could not clone object (!)");
169 
170 		// look for used stuff
171 		SdrObjListIter aIterator(rOriginal);
172 		sal_Bool bLineUsed(sal_False);
173 		sal_Bool bAllFillUsed(sal_False);
174 		sal_Bool bSolidFillUsed(sal_False);
175 		sal_Bool bGradientFillUsed(sal_False);
176 		sal_Bool bHatchFillUsed(sal_False);
177 		sal_Bool bBitmapFillUsed(sal_False);
178 
179 		while(aIterator.IsMore())
180 		{
181 			SdrObject* pObj = aIterator.Next();
182 			XFillStyle eFillStyle = ((XFillStyleItem&)(pObj->GetMergedItem(XATTR_FILLSTYLE))).GetValue();
183 
184 			if(!bLineUsed)
185 			{
186 				XLineStyle eLineStyle = ((XLineStyleItem&)(pObj->GetMergedItem(XATTR_LINESTYLE))).GetValue();
187 
188 				if(XLINE_NONE != eLineStyle)
189 				{
190 					bLineUsed = sal_True;
191 				}
192 			}
193 
194 			if(!bAllFillUsed)
195 			{
196 				if(!bSolidFillUsed && XFILL_SOLID == eFillStyle)
197 				{
198 					bSolidFillUsed = sal_True;
199 					bAllFillUsed = (bSolidFillUsed || bGradientFillUsed || bHatchFillUsed || bBitmapFillUsed);
200 				}
201 				if(!bGradientFillUsed && XFILL_GRADIENT == eFillStyle)
202 				{
203 					bGradientFillUsed = sal_True;
204 					bAllFillUsed = (bSolidFillUsed || bGradientFillUsed || bHatchFillUsed || bBitmapFillUsed);
205 				}
206 				if(!bHatchFillUsed && XFILL_HATCH == eFillStyle)
207 				{
208 					bHatchFillUsed = sal_True;
209 					bAllFillUsed = (bSolidFillUsed || bGradientFillUsed || bHatchFillUsed || bBitmapFillUsed);
210 				}
211 				if(!bBitmapFillUsed && XFILL_BITMAP == eFillStyle)
212 				{
213 					bBitmapFillUsed = sal_True;
214 					bAllFillUsed = (bSolidFillUsed || bGradientFillUsed || bHatchFillUsed || bBitmapFillUsed);
215 				}
216 			}
217 		}
218 
219 		// translate to shadow coordinates
220 		pRetval->NbcMove(Size(nXDist, nYDist));
221 
222 		// set items as needed
223 		SfxItemSet aTempSet(rOriginalSet);
224 
225 		// SJ: #40108# :-(  if a SvxWritingModeItem (Top->Bottom) is set the text object
226 		// is creating a paraobject, but paraobjects can not be created without model. So
227 		// we are preventing the crash by setting the writing mode always left to right,
228 		// this is not bad since our shadow geometry does not contain text.
229         aTempSet.Put( SvxWritingModeItem( com::sun::star::text::WritingMode_LR_TB, SDRATTR_TEXTDIRECTION ) );
230 
231 		// no shadow
232 		aTempSet.Put(SdrShadowItem(sal_False));
233 		aTempSet.Put(SdrShadowXDistItem(0L));
234 		aTempSet.Put(SdrShadowYDistItem(0L));
235 
236 		// line color and transparence like shadow
237 		if(bLineUsed)
238 		{
239 			aTempSet.Put(XLineColorItem(String(), aShadowColor));
240 			aTempSet.Put(XLineTransparenceItem(nShadowTransparence));
241 		}
242 
243 		// fill color and transparence like shadow
244 		if(bSolidFillUsed)
245 		{
246 			aTempSet.Put(XFillColorItem(String(), aShadowColor));
247 			aTempSet.Put(XFillTransparenceItem(nShadowTransparence));
248 		}
249 
250 		// gradient and transparence like shadow
251 		if(bGradientFillUsed)
252 		{
253 			XGradient aGradient(((XFillGradientItem&)(rOriginalSet.Get(XATTR_FILLGRADIENT))).GetGradientValue());
254 			sal_uInt8 nStartLuminance(aGradient.GetStartColor().GetLuminance());
255 			sal_uInt8 nEndLuminance(aGradient.GetEndColor().GetLuminance());
256 
257 			if(aGradient.GetStartIntens() != 100)
258 			{
259 				nStartLuminance = (sal_uInt8)(nStartLuminance * ((double)aGradient.GetStartIntens() / 100.0));
260 			}
261 
262 			if(aGradient.GetEndIntens() != 100)
263 			{
264 				nEndLuminance = (sal_uInt8)(nEndLuminance * ((double)aGradient.GetEndIntens() / 100.0));
265 			}
266 
267             ::Color aStartColor(
268 				(sal_uInt8)((nStartLuminance * aShadowColor.GetRed()) / 256),
269 				(sal_uInt8)((nStartLuminance * aShadowColor.GetGreen()) / 256),
270 				(sal_uInt8)((nStartLuminance * aShadowColor.GetBlue()) / 256));
271 
272             ::Color aEndColor(
273 				(sal_uInt8)((nEndLuminance * aShadowColor.GetRed()) / 256),
274 				(sal_uInt8)((nEndLuminance * aShadowColor.GetGreen()) / 256),
275 				(sal_uInt8)((nEndLuminance * aShadowColor.GetBlue()) / 256));
276 
277 			aGradient.SetStartColor(aStartColor);
278 			aGradient.SetEndColor(aEndColor);
279 			aTempSet.Put(XFillGradientItem(aTempSet.GetPool(), aGradient));
280 			aTempSet.Put(XFillTransparenceItem(nShadowTransparence));
281 		}
282 
283 		// hatch and transparence like shadow
284 		if(bHatchFillUsed)
285 		{
286 			XHatch aHatch(((XFillHatchItem&)(rOriginalSet.Get(XATTR_FILLHATCH))).GetHatchValue());
287 			aHatch.SetColor(aShadowColor);
288 			aTempSet.Put(XFillHatchItem(aTempSet.GetPool(), aHatch));
289 			aTempSet.Put(XFillTransparenceItem(nShadowTransparence));
290 		}
291 
292 		// bitmap and transparence like shadow
293 		if(bBitmapFillUsed)
294 		{
295             GraphicObject aGraphicObject(((XFillBitmapItem&)(rOriginalSet.Get(XATTR_FILLBITMAP))).GetGraphicObject());
296             const BitmapEx aBitmapEx(aGraphicObject.GetGraphic().GetBitmapEx());
297 			Bitmap aBitmap(aBitmapEx.GetBitmap());
298 
299 			if(!aBitmap.IsEmpty())
300 			{
301     			BitmapReadAccess* pReadAccess = aBitmap.AcquireReadAccess();
302 
303                 if(pReadAccess)
304 				{
305 					Bitmap aDestBitmap(aBitmap.GetSizePixel(), 24L);
306 					BitmapWriteAccess* pWriteAccess = aDestBitmap.AcquireWriteAccess();
307 
308 					if(pWriteAccess)
309 					{
310 						for(sal_Int32 y(0L); y < pReadAccess->Height(); y++)
311 						{
312 							for(sal_Int32 x(0L); x < pReadAccess->Width(); x++)
313 							{
314 								sal_uInt16 nLuminance((sal_uInt16)pReadAccess->GetLuminance(y, x) + 1);
315 								const BitmapColor aDestColor(
316 									(sal_uInt8)((nLuminance * (sal_uInt16)aShadowColor.GetRed()) >> 8L),
317 									(sal_uInt8)((nLuminance * (sal_uInt16)aShadowColor.GetGreen()) >> 8L),
318 									(sal_uInt8)((nLuminance * (sal_uInt16)aShadowColor.GetBlue()) >> 8L));
319 								pWriteAccess->SetPixel(y, x, aDestColor);
320 							}
321 						}
322 
323 						aDestBitmap.ReleaseAccess(pWriteAccess);
324 					}
325 
326 					aBitmap.ReleaseAccess(pReadAccess);
327 
328                     if(aBitmapEx.IsTransparent())
329                     {
330                         if(aBitmapEx.IsAlpha())
331                         {
332                             aGraphicObject.SetGraphic(Graphic(BitmapEx(aDestBitmap, aBitmapEx.GetAlpha())));
333                         }
334                         else
335                         {
336                             aGraphicObject.SetGraphic(Graphic(BitmapEx(aDestBitmap, aBitmapEx.GetMask())));
337                         }
338                     }
339                     else
340                     {
341                         aGraphicObject.SetGraphic(Graphic(aDestBitmap));
342                     }
343 				}
344 			}
345 
346 			aTempSet.Put(XFillBitmapItem(aTempSet.GetPool(), aGraphicObject));
347 			aTempSet.Put(XFillTransparenceItem(nShadowTransparence));
348 		}
349 
350 		// set attributes and paint shadow object
351 		pRetval->SetMergedItemSet( aTempSet );
352 	}
353 	return pRetval;
354 }
355 
356 ////////////////////////////////////////////////////////////////////////////////////////////////////
357 
358 Reference< XCustomShapeEngine > SdrObjCustomShape::GetCustomShapeEngine( const SdrObjCustomShape* pCustomShape )
359 {
360 	Reference< XCustomShapeEngine > xCustomShapeEngine;
361 	String aEngine(((SdrCustomShapeEngineItem&)pCustomShape->GetMergedItem( SDRATTR_CUSTOMSHAPE_ENGINE )).GetValue());
362 	if ( !aEngine.Len() )
363 		aEngine = String( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.drawing.EnhancedCustomShapeEngine" ) );
364 
365 	Reference< XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
366 
367 	Reference< XShape > aXShape = GetXShapeForSdrObject( (SdrObjCustomShape*)pCustomShape );
368 	if ( aXShape.is() )
369 	{
370 		if ( aEngine.Len() && xFactory.is() )
371 		{
372 			Sequence< Any > aArgument( 1 );
373 			Sequence< PropertyValue > aPropValues( 1 );
374 			aPropValues[ 0 ].Name = rtl::OUString::createFromAscii( "CustomShape" );
375 			aPropValues[ 0 ].Value <<= aXShape;
376 			aArgument[ 0 ] <<= aPropValues;
377 			Reference< XInterface > xInterface( xFactory->createInstanceWithArguments( aEngine, aArgument ) );
378 			if ( xInterface.is() )
379 				xCustomShapeEngine = Reference< XCustomShapeEngine >( xInterface, UNO_QUERY );
380 		}
381 	}
382 	return xCustomShapeEngine;
383 }
384 const SdrObject* SdrObjCustomShape::GetSdrObjectFromCustomShape() const
385 {
386 	if ( !mXRenderedCustomShape.is() )
387 	{
388 		Reference< XCustomShapeEngine > xCustomShapeEngine( GetCustomShapeEngine( this ) );
389 		if ( xCustomShapeEngine.is() )
390 			((SdrObjCustomShape*)this)->mXRenderedCustomShape = xCustomShapeEngine->render();
391 	}
392 	SdrObject* pRenderedCustomShape = mXRenderedCustomShape.is()
393 				? GetSdrObjectFromXShape( mXRenderedCustomShape )
394 				: NULL;
395 	return pRenderedCustomShape;
396 }
397 
398 // #i37011# Shadow geometry creation
399 const SdrObject* SdrObjCustomShape::GetSdrObjectShadowFromCustomShape() const
400 {
401 	if(!mpLastShadowGeometry)
402 	{
403 		const SdrObject* pSdrObject = GetSdrObjectFromCustomShape();
404 		if(pSdrObject)
405 		{
406 			const SfxItemSet& rOriginalSet = GetObjectItemSet();
407 			const sal_Bool bShadow(((SdrShadowItem&)rOriginalSet.Get( SDRATTR_SHADOW )).GetValue());
408 
409 			if(bShadow)
410 			{
411 				// create a clone with all attributes changed to shadow attributes
412 				// and translation executed, too.
413 				((SdrObjCustomShape*)this)->mpLastShadowGeometry = ImpCreateShadowObjectClone(*pSdrObject, rOriginalSet);
414 			}
415 		}
416 	}
417 
418 	return mpLastShadowGeometry;
419 }
420 
421 sal_Bool SdrObjCustomShape::IsTextPath() const
422 {
423 	const rtl::OUString	sTextPath( RTL_CONSTASCII_USTRINGPARAM ( "TextPath" ) );
424 	sal_Bool bTextPathOn = sal_False;
425 	SdrCustomShapeGeometryItem& rGeometryItem = (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY );
426 	Any* pAny = rGeometryItem.GetPropertyValueByName( sTextPath, sTextPath );
427 	if ( pAny )
428 		*pAny >>= bTextPathOn;
429 	return bTextPathOn;
430 }
431 
432 sal_Bool SdrObjCustomShape::UseNoFillStyle() const
433 {
434 	sal_Bool bRet = sal_False;
435 	rtl::OUString sShapeType;
436 	const rtl::OUString	sType( RTL_CONSTASCII_USTRINGPARAM ( "Type" ) );
437 	SdrCustomShapeGeometryItem& rGeometryItem( (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
438 	Any* pAny = rGeometryItem.GetPropertyValueByName( sType );
439 	if ( pAny )
440 		*pAny >>= sShapeType;
441 	bRet = IsCustomShapeFilledByDefault( EnhancedCustomShapeTypeNames::Get( sType ) ) == 0;
442 
443 	return bRet;
444 }
445 
446 sal_Bool SdrObjCustomShape::IsMirroredX() const
447 {
448 	sal_Bool bMirroredX = sal_False;
449 	SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
450 	const rtl::OUString	sMirroredX( RTL_CONSTASCII_USTRINGPARAM ( "MirroredX" ) );
451 	com::sun::star::uno::Any* pAny = aGeometryItem.GetPropertyValueByName( sMirroredX );
452 	if ( pAny )
453 		*pAny >>= bMirroredX;
454 	return bMirroredX;
455 }
456 sal_Bool SdrObjCustomShape::IsMirroredY() const
457 {
458 	sal_Bool bMirroredY = sal_False;
459 	SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
460 	const rtl::OUString	sMirroredY( RTL_CONSTASCII_USTRINGPARAM ( "MirroredY" ) );
461 	com::sun::star::uno::Any* pAny = aGeometryItem.GetPropertyValueByName( sMirroredY );
462 	if ( pAny )
463 		*pAny >>= bMirroredY;
464 	return bMirroredY;
465 }
466 void SdrObjCustomShape::SetMirroredX( const sal_Bool bMirrorX )
467 {
468 	SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
469 	const rtl::OUString	sMirroredX( RTL_CONSTASCII_USTRINGPARAM ( "MirroredX" ) );
470 	//com::sun::star::uno::Any* pAny = aGeometryItem.GetPropertyValueByName( sMirroredX );
471 	PropertyValue aPropVal;
472 	aPropVal.Name = sMirroredX;
473 	aPropVal.Value <<= bMirrorX;
474 	aGeometryItem.SetPropertyValue( aPropVal );
475 	SetMergedItem( aGeometryItem );
476 }
477 void SdrObjCustomShape::SetMirroredY( const sal_Bool bMirrorY )
478 {
479 	SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
480 	const rtl::OUString	sMirroredY( RTL_CONSTASCII_USTRINGPARAM ( "MirroredY" ) );
481 	//com::sun::star::uno::Any* pAny = aGeometryItem.GetPropertyValueByName( sMirroredY );
482 	PropertyValue aPropVal;
483 	aPropVal.Name = sMirroredY;
484 	aPropVal.Value <<= bMirrorY;
485 	aGeometryItem.SetPropertyValue( aPropVal );
486 	SetMergedItem( aGeometryItem );
487 }
488 
489 double SdrObjCustomShape::GetObjectRotation() const
490 {
491 	return fObjectRotation;
492 }
493 
494 double SdrObjCustomShape::GetExtraTextRotation() const
495 {
496 	const com::sun::star::uno::Any* pAny;
497 	SdrCustomShapeGeometryItem& rGeometryItem = (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY );
498 	const rtl::OUString sTextRotateAngle( RTL_CONSTASCII_USTRINGPARAM ( "TextRotateAngle" ) );
499 	pAny = rGeometryItem.GetPropertyValueByName( sTextRotateAngle );
500 	double fExtraTextRotateAngle = 0.0;
501 	if ( pAny )
502 		*pAny >>= fExtraTextRotateAngle;
503 	return fExtraTextRotateAngle;
504 }
505 sal_Bool SdrObjCustomShape::GetTextBounds( Rectangle& rTextBound ) const
506 {
507 	sal_Bool bRet = sal_False;
508 	Reference< XCustomShapeEngine > xCustomShapeEngine( GetCustomShapeEngine( this ) );	// a candidate for being cached
509 	if ( xCustomShapeEngine.is() )
510 	{
511 		awt::Rectangle aR( xCustomShapeEngine->getTextBounds() );
512 		if ( aR.Width || aR.Height )
513 		{
514 			rTextBound = Rectangle( Point( aR.X, aR.Y ), Size( aR.Width, aR.Height ) );
515 			bRet = sal_True;
516 		}
517 	}
518 	return bRet;
519 }
520 basegfx::B2DPolyPolygon SdrObjCustomShape::GetLineGeometry( const SdrObjCustomShape* pCustomShape, const sal_Bool bBezierAllowed )
521 {
522 	basegfx::B2DPolyPolygon aRetval;
523 	sal_Bool bRet = sal_False;
524 	Reference< XCustomShapeEngine > xCustomShapeEngine( GetCustomShapeEngine( pCustomShape ) );
525 	if ( xCustomShapeEngine.is() )
526 	{
527 		com::sun::star::drawing::PolyPolygonBezierCoords aBezierCoords = xCustomShapeEngine->getLineGeometry();
528 		try
529 		{
530 			aRetval = SvxConvertPolyPolygonBezierToB2DPolyPolygon( &aBezierCoords );
531 			if ( !bBezierAllowed && aRetval.areControlPointsUsed())
532 			{
533 				aRetval = basegfx::tools::adaptiveSubdivideByAngle(aRetval);
534 			}
535 			bRet = sal_True;
536 		}
537 		catch ( const com::sun::star::lang::IllegalArgumentException )
538 		{
539 		}
540 	}
541 	return aRetval;
542 }
543 
544 std::vector< SdrCustomShapeInteraction > SdrObjCustomShape::GetInteractionHandles( const SdrObjCustomShape* pCustomShape ) const
545 {
546 	std::vector< SdrCustomShapeInteraction > xRet;
547 	try
548 	{
549 		Reference< XCustomShapeEngine > xCustomShapeEngine( GetCustomShapeEngine( pCustomShape ) );
550 		if ( xCustomShapeEngine.is() )
551 		{
552 			int i;
553 			Sequence< Reference< XCustomShapeHandle > > xInteractionHandles( xCustomShapeEngine->getInteraction() );
554 			for ( i = 0; i < xInteractionHandles.getLength(); i++ )
555 			{
556 				if ( xInteractionHandles[ i ].is() )
557 				{
558 					SdrCustomShapeInteraction aSdrCustomShapeInteraction;
559 					aSdrCustomShapeInteraction.xInteraction = xInteractionHandles[ i ];
560 					aSdrCustomShapeInteraction.aPosition = xInteractionHandles[ i ]->getPosition();
561 
562 					sal_Int32 nMode = 0;
563 					switch( ImpGetCustomShapeType( *this ) )
564 					{
565 						case mso_sptAccentBorderCallout90 :		// 2 ortho
566 						{
567 							if ( !i )
568 								nMode |= CUSTOMSHAPE_HANDLE_RESIZE_FIXED | CUSTOMSHAPE_HANDLE_CREATE_FIXED;
569 							else if ( i == 1)
570 								nMode |= CUSTOMSHAPE_HANDLE_RESIZE_ABSOLUTE_X | CUSTOMSHAPE_HANDLE_RESIZE_ABSOLUTE_Y | CUSTOMSHAPE_HANDLE_MOVE_SHAPE | CUSTOMSHAPE_HANDLE_ORTHO4;
571 						}
572 						break;
573 
574 						case mso_sptWedgeRectCallout :
575 						case mso_sptWedgeRRectCallout :
576 						case mso_sptCloudCallout :
577 						case mso_sptWedgeEllipseCallout :
578 						{
579 							if ( !i )
580 								nMode |= CUSTOMSHAPE_HANDLE_RESIZE_FIXED;
581 						}
582 						break;
583 
584 						case mso_sptBorderCallout1 :			// 2 diag
585 						{
586 							if ( !i )
587 								nMode |= CUSTOMSHAPE_HANDLE_RESIZE_FIXED | CUSTOMSHAPE_HANDLE_CREATE_FIXED;
588 							else if ( i == 1 )
589 								nMode |= CUSTOMSHAPE_HANDLE_RESIZE_ABSOLUTE_X | CUSTOMSHAPE_HANDLE_RESIZE_ABSOLUTE_Y | CUSTOMSHAPE_HANDLE_MOVE_SHAPE;
590 						}
591 						break;
592 						case mso_sptBorderCallout2 :			// 3
593 						{
594 							if ( !i )
595 								nMode |= CUSTOMSHAPE_HANDLE_RESIZE_FIXED | CUSTOMSHAPE_HANDLE_CREATE_FIXED;
596 							else if ( i == 2 )
597 								nMode |= CUSTOMSHAPE_HANDLE_RESIZE_ABSOLUTE_X | CUSTOMSHAPE_HANDLE_RESIZE_ABSOLUTE_Y | CUSTOMSHAPE_HANDLE_MOVE_SHAPE;
598 						}
599 						break;
600 						case mso_sptCallout90 :
601 						case mso_sptAccentCallout90 :
602 						case mso_sptBorderCallout90 :
603 						case mso_sptCallout1 :
604 						case mso_sptCallout2 :
605 						case mso_sptCallout3 :
606 						case mso_sptAccentCallout1 :
607 						case mso_sptAccentCallout2 :
608 						case mso_sptAccentCallout3 :
609 						case mso_sptBorderCallout3 :
610 						case mso_sptAccentBorderCallout1 :
611 						case mso_sptAccentBorderCallout2 :
612 						case mso_sptAccentBorderCallout3 :
613 						{
614 							if ( !i )
615 								nMode |= CUSTOMSHAPE_HANDLE_RESIZE_FIXED | CUSTOMSHAPE_HANDLE_CREATE_FIXED;
616 						}
617 						break;
618 						default: break;
619 					}
620 					aSdrCustomShapeInteraction.nMode = nMode;
621 					xRet.push_back( aSdrCustomShapeInteraction );
622 				}
623 			}
624 		}
625 	}
626 	catch( const uno::RuntimeException& )
627 	{
628 	}
629 	return xRet;
630 }
631 
632 //////////////////////////////////////////////////////////////////////////////
633 // BaseProperties section
634 #define	DEFAULT_MINIMUM_SIGNED_COMPARE	((sal_Int32)0x80000000)
635 #define	DEFAULT_MAXIMUM_SIGNED_COMPARE	((sal_Int32)0x7fffffff)
636 
637 sdr::properties::BaseProperties* SdrObjCustomShape::CreateObjectSpecificProperties()
638 {
639 	return new sdr::properties::CustomShapeProperties(*this);
640 }
641 
642 TYPEINIT1(SdrObjCustomShape,SdrTextObj);
643 SdrObjCustomShape::SdrObjCustomShape() :
644 	SdrTextObj(),
645 	fObjectRotation( 0.0 ),
646 	mpLastShadowGeometry(0L)
647 {
648 	bTextFrame = sal_True;
649 }
650 
651 SdrObjCustomShape::~SdrObjCustomShape()
652 {
653 	// delete buffered display geometry
654 	InvalidateRenderGeometry();
655 }
656 
657 void SdrObjCustomShape::MergeDefaultAttributes( const rtl::OUString* pType )
658 {
659 	PropertyValue aPropVal;
660 	rtl::OUString sShapeType;
661 	const rtl::OUString	sType( RTL_CONSTASCII_USTRINGPARAM ( "Type" ) );
662 	SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
663 	if ( pType && pType->getLength() )
664 	{
665 		sal_Int32 nType = pType->toInt32();
666 		if ( nType )
667 			sShapeType = EnhancedCustomShapeTypeNames::Get( static_cast< MSO_SPT >( nType ) );
668 		else
669 			sShapeType = *pType;
670 
671 		aPropVal.Name = sType;
672 		aPropVal.Value <<= sShapeType;
673 		aGeometryItem.SetPropertyValue( aPropVal );
674 	}
675 	else
676 	{
677 		Any *pAny = aGeometryItem.GetPropertyValueByName( sType );
678 		if ( pAny )
679 			*pAny >>= sShapeType;
680 	}
681 	MSO_SPT eSpType = EnhancedCustomShapeTypeNames::Get( sShapeType );
682 
683 	const sal_Int32* pDefData = NULL;
684 	const mso_CustomShape* pDefCustomShape = GetCustomShapeContent( eSpType );
685 	if ( pDefCustomShape )
686 		pDefData = pDefCustomShape->pDefData;
687 
688 	com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue > seqAdjustmentValues;
689 
690 	//////////////////////
691 	// AdjustmentValues //
692 	//////////////////////
693 	const rtl::OUString	sAdjustmentValues( RTL_CONSTASCII_USTRINGPARAM ( "AdjustmentValues" ) );
694 	const Any* pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sAdjustmentValues );
695 	if ( pAny )
696 		*pAny >>= seqAdjustmentValues;
697 	if ( pDefCustomShape && pDefData )	// now check if we have to default some adjustment values
698 	{
699 		// first check if there are adjustment values are to be appended
700 		sal_Int32 i, nAdjustmentValues = seqAdjustmentValues.getLength();
701 		sal_Int32 nAdjustmentDefaults = *pDefData++;
702 		if ( nAdjustmentDefaults > nAdjustmentValues )
703 		{
704 			seqAdjustmentValues.realloc( nAdjustmentDefaults );
705 			for ( i = nAdjustmentValues; i < nAdjustmentDefaults; i++ )
706 			{
707 				seqAdjustmentValues[ i ].Value <<= pDefData[ i ];
708 				seqAdjustmentValues[ i ].State = com::sun::star::beans::PropertyState_DIRECT_VALUE;	// com::sun::star::beans::PropertyState_DEFAULT_VALUE;
709 			}
710 		}
711 		// check if there are defaulted adjustment values that should be filled the hard coded defaults (pDefValue)
712 		sal_Int32 nCount = nAdjustmentValues > nAdjustmentDefaults ? nAdjustmentDefaults : nAdjustmentValues;
713 		for ( i = 0; i < nCount; i++ )
714 		{
715 			if ( seqAdjustmentValues[ i ].State != com::sun::star::beans::PropertyState_DIRECT_VALUE )
716 			{
717 				seqAdjustmentValues[ i ].Value <<= pDefData[ i ];
718 				seqAdjustmentValues[ i ].State = com::sun::star::beans::PropertyState_DIRECT_VALUE;
719 			}
720 		}
721 	}
722 	aPropVal.Name = sAdjustmentValues;
723 	aPropVal.Value <<= seqAdjustmentValues;
724 	aGeometryItem.SetPropertyValue( aPropVal );
725 
726 	///////////////
727 	// Coordsize //
728 	///////////////
729 	const rtl::OUString	sViewBox( RTL_CONSTASCII_USTRINGPARAM ( "ViewBox" ) );
730 	const Any* pViewBox = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sViewBox );
731 	com::sun::star::awt::Rectangle aViewBox;
732 	if ( !pViewBox || !(*pViewBox >>= aViewBox ) )
733 	{
734 		if ( pDefCustomShape )
735 		{
736 			aViewBox.X = 0;
737 			aViewBox.Y = 0;
738 			aViewBox.Width = pDefCustomShape->nCoordWidth;
739 			aViewBox.Height= pDefCustomShape->nCoordHeight;
740 			aPropVal.Name = sViewBox;
741 			aPropVal.Value <<= aViewBox;
742 			aGeometryItem.SetPropertyValue( aPropVal );
743 		}
744 	}
745 
746 	const rtl::OUString	sPath( RTL_CONSTASCII_USTRINGPARAM ( "Path" ) );
747 
748 	//////////////////////
749 	// Path/Coordinates //
750 	//////////////////////
751 	const rtl::OUString	sCoordinates( RTL_CONSTASCII_USTRINGPARAM ( "Coordinates" ) );
752 	pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sCoordinates );
753 	if ( !pAny && pDefCustomShape && pDefCustomShape->nVertices && pDefCustomShape->pVertices )
754 	{
755 		com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair> seqCoordinates;
756 
757 		sal_Int32 i, nCount = pDefCustomShape->nVertices;
758 		seqCoordinates.realloc( nCount );
759 		for ( i = 0; i < nCount; i++ )
760 		{
761 			EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqCoordinates[ i ].First, pDefCustomShape->pVertices[ i ].nValA );
762 			EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqCoordinates[ i ].Second, pDefCustomShape->pVertices[ i ].nValB );
763 		}
764 		aPropVal.Name = sCoordinates;
765 		aPropVal.Value <<= seqCoordinates;
766 		aGeometryItem.SetPropertyValue( sPath, aPropVal );
767 	}
768 
769 	/////////////////////
770 	// Path/GluePoints //
771 	/////////////////////
772 	const rtl::OUString	sGluePoints( RTL_CONSTASCII_USTRINGPARAM ( "GluePoints" ) );
773 	pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sGluePoints );
774 	if ( !pAny && pDefCustomShape && pDefCustomShape->nGluePoints && pDefCustomShape->pGluePoints )
775 	{
776 		com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair> seqGluePoints;
777 		sal_Int32 i, nCount = pDefCustomShape->nGluePoints;
778 		seqGluePoints.realloc( nCount );
779 		for ( i = 0; i < nCount; i++ )
780 		{
781 			EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqGluePoints[ i ].First, pDefCustomShape->pGluePoints[ i ].nValA );
782 			EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqGluePoints[ i ].Second, pDefCustomShape->pGluePoints[ i ].nValB );
783 		}
784 		aPropVal.Name = sGluePoints;
785 		aPropVal.Value <<= seqGluePoints;
786 		aGeometryItem.SetPropertyValue( sPath, aPropVal );
787 	}
788 
789 	///////////////////
790 	// Path/Segments //
791 	///////////////////
792 	const rtl::OUString	sSegments( RTL_CONSTASCII_USTRINGPARAM ( "Segments" ) );
793 	pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sSegments );
794 	if ( !pAny && pDefCustomShape && pDefCustomShape->nElements && pDefCustomShape->pElements )
795 	{
796 		com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeSegment > seqSegments;
797 
798 		sal_Int32 i, nCount = pDefCustomShape->nElements;
799 		seqSegments.realloc( nCount );
800 		for ( i = 0; i < nCount; i++ )
801 		{
802 			EnhancedCustomShapeSegment& rSegInfo = seqSegments[ i ];
803 			sal_uInt16 nSDat = pDefCustomShape->pElements[ i ];
804 			switch( nSDat >> 8 )
805 			{
806 				case 0x00 :
807 				{
808 					rSegInfo.Command = EnhancedCustomShapeSegmentCommand::LINETO;
809 					rSegInfo.Count   = nSDat & 0xff;
810 					if ( !rSegInfo.Count )
811 						rSegInfo.Count = 1;
812 				}
813 				break;
814 				case 0x20 :
815 				{
816 					rSegInfo.Command = EnhancedCustomShapeSegmentCommand::CURVETO;
817 					rSegInfo.Count   = nSDat & 0xff;
818 					if ( !rSegInfo.Count )
819 						rSegInfo.Count = 1;
820 				}
821 				break;
822 				case 0x40 :
823 				{
824 					rSegInfo.Command = EnhancedCustomShapeSegmentCommand::MOVETO;
825 					rSegInfo.Count   = nSDat & 0xff;
826 					if ( !rSegInfo.Count )
827 						rSegInfo.Count = 1;
828 				}
829 				break;
830 				case 0x60 :
831 				{
832 					rSegInfo.Command = EnhancedCustomShapeSegmentCommand::CLOSESUBPATH;
833 					rSegInfo.Count   = 0;
834 				}
835 				break;
836 				case 0x80 :
837 				{
838 					rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ENDSUBPATH;
839 					rSegInfo.Count   = 0;
840 				}
841 				break;
842 				case 0xa1 :
843 				{
844 					rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ANGLEELLIPSETO;
845 					rSegInfo.Count   = ( nSDat & 0xff ) / 3;
846 				}
847 				break;
848 				case 0xa2 :
849 				{
850 					rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ANGLEELLIPSE;
851 					rSegInfo.Count   = ( nSDat & 0xff ) / 3;
852 				}
853 				break;
854 				case 0xa3 :
855 				{
856 					rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ARCTO;
857 					rSegInfo.Count   = ( nSDat & 0xff ) >> 2;
858 				}
859 				break;
860 				case 0xa4 :
861 				{
862 					rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ARC;
863 					rSegInfo.Count   = ( nSDat & 0xff ) >> 2;
864 				}
865 				break;
866 				case 0xa5 :
867 				{
868 					rSegInfo.Command = EnhancedCustomShapeSegmentCommand::CLOCKWISEARCTO;
869 					rSegInfo.Count   = ( nSDat & 0xff ) >> 2;
870 				}
871 				break;
872 				case 0xa6 :
873 				{
874 					rSegInfo.Command = EnhancedCustomShapeSegmentCommand::CLOCKWISEARC;
875 					rSegInfo.Count   = ( nSDat & 0xff ) >> 2;
876 				}
877 				break;
878 				case 0xa7 :
879 				{
880 					rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ELLIPTICALQUADRANTX;
881 					rSegInfo.Count   = nSDat & 0xff;
882 				}
883 				break;
884 				case 0xa8 :
885 				{
886 					rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ELLIPTICALQUADRANTY;
887 					rSegInfo.Count   = nSDat & 0xff;
888 				}
889 				break;
890 				case 0xaa :
891 				{
892 					rSegInfo.Command = EnhancedCustomShapeSegmentCommand::NOFILL;
893 					rSegInfo.Count   = 0;
894 				}
895 				break;
896 				case 0xab :
897 				{
898 					rSegInfo.Command = EnhancedCustomShapeSegmentCommand::NOSTROKE;
899 					rSegInfo.Count   = 0;
900 				}
901 				break;
902 				default:
903 				case 0xf8 :
904 				{
905 					rSegInfo.Command = EnhancedCustomShapeSegmentCommand::UNKNOWN;
906 					rSegInfo.Count   = nSDat;
907 				}
908 				break;
909 			}
910 		}
911 		aPropVal.Name = sSegments;
912 		aPropVal.Value <<= seqSegments;
913 		aGeometryItem.SetPropertyValue( sPath, aPropVal );
914 	}
915 
916 	///////////////////
917 	// Path/StretchX //
918 	///////////////////
919 	const rtl::OUString	sStretchX( RTL_CONSTASCII_USTRINGPARAM ( "StretchX" ) );
920 	pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sStretchX );
921 	if ( !pAny && pDefCustomShape )
922 	{
923 		sal_Int32 nXRef = pDefCustomShape->nXRef;
924 		if ( ( nXRef != DEFAULT_MINIMUM_SIGNED_COMPARE ) )
925 		{
926 			aPropVal.Name = sStretchX;
927 			aPropVal.Value <<= nXRef;
928 			aGeometryItem.SetPropertyValue( sPath, aPropVal );
929 		}
930 	}
931 
932 	///////////////////
933 	// Path/StretchY //
934 	///////////////////
935 	const rtl::OUString	sStretchY( RTL_CONSTASCII_USTRINGPARAM ( "StretchY" ) );
936 	pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sStretchY );
937 	if ( !pAny && pDefCustomShape )
938 	{
939 		sal_Int32 nYRef = pDefCustomShape->nYRef;
940 		if ( ( nYRef != DEFAULT_MINIMUM_SIGNED_COMPARE ) )
941 		{
942 			aPropVal.Name = sStretchY;
943 			aPropVal.Value <<= nYRef;
944 			aGeometryItem.SetPropertyValue( sPath, aPropVal );
945 		}
946 	}
947 
948 	/////////////////////
949 	// Path/TextFrames //
950 	/////////////////////
951 	const rtl::OUString	sTextFrames( RTL_CONSTASCII_USTRINGPARAM ( "TextFrames" ) );
952 	pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sTextFrames );
953 	if ( !pAny && pDefCustomShape && pDefCustomShape->nTextRect && pDefCustomShape->pTextRect )
954 	{
955 		com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeTextFrame > seqTextFrames;
956 
957 		sal_Int32 i, nCount = pDefCustomShape->nTextRect;
958 		seqTextFrames.realloc( nCount );
959 		const SvxMSDffTextRectangles* pRectangles = pDefCustomShape->pTextRect;
960 		for ( i = 0; i < nCount; i++, pRectangles++ )
961 		{
962 			EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqTextFrames[ i ].TopLeft.First,	  pRectangles->nPairA.nValA );
963 			EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqTextFrames[ i ].TopLeft.Second,	  pRectangles->nPairA.nValB );
964 			EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqTextFrames[ i ].BottomRight.First,  pRectangles->nPairB.nValA );
965 			EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqTextFrames[ i ].BottomRight.Second, pRectangles->nPairB.nValB );
966 		}
967 		aPropVal.Name = sTextFrames;
968 		aPropVal.Value <<= seqTextFrames;
969 		aGeometryItem.SetPropertyValue( sPath, aPropVal );
970 	}
971 
972 	///////////////
973 	// Equations //
974 	///////////////
975 	const rtl::OUString	sEquations( RTL_CONSTASCII_USTRINGPARAM( "Equations" ) );
976 	pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sEquations );
977 	if ( !pAny && pDefCustomShape && pDefCustomShape->nCalculation && pDefCustomShape->pCalculation )
978 	{
979 		com::sun::star::uno::Sequence< rtl::OUString > seqEquations;
980 
981 		sal_Int32 i, nCount = pDefCustomShape->nCalculation;
982 		seqEquations.realloc( nCount );
983 		const SvxMSDffCalculationData* pData = pDefCustomShape->pCalculation;
984 		for ( i = 0; i < nCount; i++, pData++ )
985 			seqEquations[ i ] = EnhancedCustomShape2d::GetEquation( pData->nFlags, pData->nVal[ 0 ], pData->nVal[ 1 ], pData->nVal[ 2 ] );
986 		aPropVal.Name = sEquations;
987 		aPropVal.Value <<= seqEquations;
988 		aGeometryItem.SetPropertyValue( aPropVal );
989 	}
990 
991 	/////////////
992 	// Handles //
993 	/////////////
994 	const rtl::OUString	sHandles( RTL_CONSTASCII_USTRINGPARAM( "Handles" ) );
995 	pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sHandles );
996 	if ( !pAny && pDefCustomShape && pDefCustomShape->nHandles && pDefCustomShape->pHandles )
997 	{
998 		com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValues > seqHandles;
999 
1000 		sal_Int32 i, n, nCount = pDefCustomShape->nHandles;
1001 		const SvxMSDffHandle* pData = pDefCustomShape->pHandles;
1002 		seqHandles.realloc( nCount );
1003 		for ( i = 0; i < nCount; i++, pData++ )
1004 		{
1005 			sal_Int32 nPropertiesNeeded = 1;	// position is always needed
1006 			sal_Int32 nFlags = pData->nFlags;
1007 			if ( nFlags & MSDFF_HANDLE_FLAGS_MIRRORED_X )
1008 				nPropertiesNeeded++;
1009 			if ( nFlags & MSDFF_HANDLE_FLAGS_MIRRORED_Y )
1010 				nPropertiesNeeded++;
1011 			if ( nFlags & MSDFF_HANDLE_FLAGS_SWITCHED )
1012 				nPropertiesNeeded++;
1013 			if ( nFlags & MSDFF_HANDLE_FLAGS_POLAR )
1014 			{
1015 				nPropertiesNeeded++;
1016 				if ( nFlags & MSDFF_HANDLE_FLAGS_RADIUS_RANGE )
1017 				{
1018 					if ( pData->nRangeXMin != DEFAULT_MINIMUM_SIGNED_COMPARE )
1019 						nPropertiesNeeded++;
1020 					if ( pData->nRangeXMax != DEFAULT_MAXIMUM_SIGNED_COMPARE )
1021 						nPropertiesNeeded++;
1022 				}
1023 			}
1024 			else if ( nFlags & MSDFF_HANDLE_FLAGS_RANGE )
1025 			{
1026 				if ( pData->nRangeXMin != DEFAULT_MINIMUM_SIGNED_COMPARE )
1027 					nPropertiesNeeded++;
1028 				if ( pData->nRangeXMax != DEFAULT_MAXIMUM_SIGNED_COMPARE )
1029 					nPropertiesNeeded++;
1030 				if ( pData->nRangeYMin != DEFAULT_MINIMUM_SIGNED_COMPARE )
1031 					nPropertiesNeeded++;
1032 				if ( pData->nRangeYMax != DEFAULT_MAXIMUM_SIGNED_COMPARE )
1033 					nPropertiesNeeded++;
1034 			}
1035 
1036 			n = 0;
1037 			com::sun::star::beans::PropertyValues& rPropValues = seqHandles[ i ];
1038 			rPropValues.realloc( nPropertiesNeeded );
1039 
1040 			// POSITION
1041 			{
1042 				const rtl::OUString	sPosition( RTL_CONSTASCII_USTRINGPARAM ( "Position" ) );
1043 				::com::sun::star::drawing::EnhancedCustomShapeParameterPair aPosition;
1044 				EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aPosition.First, pData->nPositionX, sal_True, sal_True );
1045 				EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aPosition.Second, pData->nPositionY, sal_True, sal_False );
1046 				rPropValues[ n ].Name = sPosition;
1047 				rPropValues[ n++ ].Value <<= aPosition;
1048 			}
1049 			if ( nFlags & MSDFF_HANDLE_FLAGS_MIRRORED_X )
1050 			{
1051 				const rtl::OUString	sMirroredX( RTL_CONSTASCII_USTRINGPARAM ( "MirroredX" ) );
1052 				sal_Bool bMirroredX = sal_True;
1053 				rPropValues[ n ].Name = sMirroredX;
1054 				rPropValues[ n++ ].Value <<= bMirroredX;
1055 			}
1056 			if ( nFlags & MSDFF_HANDLE_FLAGS_MIRRORED_Y )
1057 			{
1058 				const rtl::OUString	sMirroredY( RTL_CONSTASCII_USTRINGPARAM ( "MirroredY" ) );
1059 				sal_Bool bMirroredY = sal_True;
1060 				rPropValues[ n ].Name = sMirroredY;
1061 				rPropValues[ n++ ].Value <<= bMirroredY;
1062 			}
1063 			if ( nFlags & MSDFF_HANDLE_FLAGS_SWITCHED )
1064 			{
1065 				const rtl::OUString	sSwitched( RTL_CONSTASCII_USTRINGPARAM ( "Switched" ) );
1066 				sal_Bool bSwitched = sal_True;
1067 				rPropValues[ n ].Name = sSwitched;
1068 				rPropValues[ n++ ].Value <<= bSwitched;
1069 			}
1070 			if ( nFlags & MSDFF_HANDLE_FLAGS_POLAR )
1071 			{
1072 				const rtl::OUString	sPolar( RTL_CONSTASCII_USTRINGPARAM ( "Polar" ) );
1073 				::com::sun::star::drawing::EnhancedCustomShapeParameterPair aCenter;
1074 				EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aCenter.First,  pData->nCenterX,
1075 					( nFlags & MSDFF_HANDLE_FLAGS_CENTER_X_IS_SPECIAL ) != 0, sal_True  );
1076 				EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aCenter.Second, pData->nCenterY,
1077 					( nFlags & MSDFF_HANDLE_FLAGS_CENTER_Y_IS_SPECIAL ) != 0, sal_False );
1078 				rPropValues[ n ].Name = sPolar;
1079 				rPropValues[ n++ ].Value <<= aCenter;
1080 				if ( nFlags & MSDFF_HANDLE_FLAGS_RADIUS_RANGE )
1081 				{
1082 					if ( pData->nRangeXMin != DEFAULT_MINIMUM_SIGNED_COMPARE )
1083 					{
1084 						const rtl::OUString	sRadiusRangeMinimum( RTL_CONSTASCII_USTRINGPARAM ( "RadiusRangeMinimum" ) );
1085 						::com::sun::star::drawing::EnhancedCustomShapeParameter aRadiusRangeMinimum;
1086 						EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRadiusRangeMinimum, pData->nRangeXMin,
1087 							( nFlags & MSDFF_HANDLE_FLAGS_RANGE_X_MIN_IS_SPECIAL ) != 0, sal_True  );
1088 						rPropValues[ n ].Name = sRadiusRangeMinimum;
1089 						rPropValues[ n++ ].Value <<= aRadiusRangeMinimum;
1090 					}
1091 					if ( pData->nRangeXMax != DEFAULT_MAXIMUM_SIGNED_COMPARE )
1092 					{
1093 						const rtl::OUString	sRadiusRangeMaximum( RTL_CONSTASCII_USTRINGPARAM ( "RadiusRangeMaximum" ) );
1094 						::com::sun::star::drawing::EnhancedCustomShapeParameter aRadiusRangeMaximum;
1095 						EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRadiusRangeMaximum, pData->nRangeXMax,
1096 							( nFlags & MSDFF_HANDLE_FLAGS_RANGE_X_MAX_IS_SPECIAL ) != 0, sal_False );
1097 						rPropValues[ n ].Name = sRadiusRangeMaximum;
1098 						rPropValues[ n++ ].Value <<= aRadiusRangeMaximum;
1099 					}
1100 				}
1101 			}
1102 			else if ( nFlags & MSDFF_HANDLE_FLAGS_RANGE )
1103 			{
1104 				if ( pData->nRangeXMin != DEFAULT_MINIMUM_SIGNED_COMPARE )
1105 				{
1106 					const rtl::OUString	sRangeXMinimum( RTL_CONSTASCII_USTRINGPARAM ( "RangeXMinimum" ) );
1107 					::com::sun::star::drawing::EnhancedCustomShapeParameter aRangeXMinimum;
1108 					EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRangeXMinimum, pData->nRangeXMin,
1109 						( nFlags & MSDFF_HANDLE_FLAGS_RANGE_X_MIN_IS_SPECIAL ) != 0, sal_True  );
1110 					rPropValues[ n ].Name = sRangeXMinimum;
1111 					rPropValues[ n++ ].Value <<= aRangeXMinimum;
1112 				}
1113 				if ( pData->nRangeXMax != DEFAULT_MAXIMUM_SIGNED_COMPARE )
1114 				{
1115 					const rtl::OUString	sRangeXMaximum( RTL_CONSTASCII_USTRINGPARAM ( "RangeXMaximum" ) );
1116 					::com::sun::star::drawing::EnhancedCustomShapeParameter aRangeXMaximum;
1117 					EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRangeXMaximum, pData->nRangeXMax,
1118 						( nFlags & MSDFF_HANDLE_FLAGS_RANGE_X_MAX_IS_SPECIAL ) != 0, sal_False );
1119 					rPropValues[ n ].Name = sRangeXMaximum;
1120 					rPropValues[ n++ ].Value <<= aRangeXMaximum;
1121 				}
1122 				if ( pData->nRangeYMin != DEFAULT_MINIMUM_SIGNED_COMPARE )
1123 				{
1124 					const rtl::OUString	sRangeYMinimum( RTL_CONSTASCII_USTRINGPARAM ( "RangeYMinimum" ) );
1125 					::com::sun::star::drawing::EnhancedCustomShapeParameter aRangeYMinimum;
1126 					EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRangeYMinimum, pData->nRangeYMin,
1127 						( nFlags & MSDFF_HANDLE_FLAGS_RANGE_Y_MIN_IS_SPECIAL ) != 0, sal_True );
1128 					rPropValues[ n ].Name = sRangeYMinimum;
1129 					rPropValues[ n++ ].Value <<= aRangeYMinimum;
1130 				}
1131 				if ( pData->nRangeYMax != DEFAULT_MAXIMUM_SIGNED_COMPARE )
1132 				{
1133 					const rtl::OUString	sRangeYMaximum( RTL_CONSTASCII_USTRINGPARAM ( "RangeYMaximum" ) );
1134 					::com::sun::star::drawing::EnhancedCustomShapeParameter aRangeYMaximum;
1135 					EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRangeYMaximum, pData->nRangeYMax,
1136 						( nFlags & MSDFF_HANDLE_FLAGS_RANGE_Y_MAX_IS_SPECIAL ) != 0, sal_False );
1137 					rPropValues[ n ].Name = sRangeYMaximum;
1138 					rPropValues[ n++ ].Value <<= aRangeYMaximum;
1139 				}
1140 			}
1141 		}
1142 		aPropVal.Name = sHandles;
1143 		aPropVal.Value <<= seqHandles;
1144 		aGeometryItem.SetPropertyValue( aPropVal );
1145 	}
1146 	SetMergedItem( aGeometryItem );
1147 }
1148 
1149 sal_Bool SdrObjCustomShape::IsDefaultGeometry( const DefaultType eDefaultType ) const
1150 {
1151 	sal_Bool bIsDefaultGeometry = sal_False;
1152 
1153 	PropertyValue aPropVal;
1154 	rtl::OUString sShapeType;
1155 	const rtl::OUString	sType( RTL_CONSTASCII_USTRINGPARAM ( "Type" ) );
1156 	SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
1157 
1158 	Any *pAny = aGeometryItem.GetPropertyValueByName( sType );
1159 	if ( pAny )
1160 		*pAny >>= sShapeType;
1161 
1162 	MSO_SPT eSpType = EnhancedCustomShapeTypeNames::Get( sShapeType );
1163 
1164 	const mso_CustomShape* pDefCustomShape = GetCustomShapeContent( eSpType );
1165 	const rtl::OUString	sPath( RTL_CONSTASCII_USTRINGPARAM ( "Path" ) );
1166 	switch( eDefaultType )
1167 	{
1168 		case DEFAULT_VIEWBOX :
1169 		{
1170 			const rtl::OUString	sViewBox( RTL_CONSTASCII_USTRINGPARAM ( "ViewBox" ) );
1171 			const Any* pViewBox = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sViewBox );
1172 			com::sun::star::awt::Rectangle aViewBox;
1173 			if ( pViewBox && ( *pViewBox >>= aViewBox ) )
1174 			{
1175 				if ( ( aViewBox.Width == pDefCustomShape->nCoordWidth )
1176 					&& ( aViewBox.Height == pDefCustomShape->nCoordHeight ) )
1177 					bIsDefaultGeometry = sal_True;
1178 			}
1179 		}
1180 		break;
1181 
1182 		case DEFAULT_PATH :
1183 		{
1184 			const rtl::OUString	sCoordinates( RTL_CONSTASCII_USTRINGPARAM ( "Coordinates" ) );
1185 			pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sCoordinates );
1186 			if ( pAny && pDefCustomShape && pDefCustomShape->nVertices && pDefCustomShape->pVertices )
1187 			{
1188 				com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair> seqCoordinates1, seqCoordinates2;
1189 				if ( *pAny >>= seqCoordinates1 )
1190 				{
1191 					sal_Int32 i, nCount = pDefCustomShape->nVertices;
1192 					seqCoordinates2.realloc( nCount );
1193 					for ( i = 0; i < nCount; i++ )
1194 					{
1195 						EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqCoordinates2[ i ].First, pDefCustomShape->pVertices[ i ].nValA );
1196 						EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqCoordinates2[ i ].Second, pDefCustomShape->pVertices[ i ].nValB );
1197 					}
1198 					if ( seqCoordinates1 == seqCoordinates2 )
1199 						bIsDefaultGeometry = sal_True;
1200 				}
1201 			}
1202 			else if ( pDefCustomShape && ( ( pDefCustomShape->nVertices == 0 ) || ( pDefCustomShape->pVertices == 0 ) ) )
1203 				bIsDefaultGeometry = sal_True;
1204 		}
1205 		break;
1206 
1207 		case DEFAULT_GLUEPOINTS :
1208 		{
1209 			const rtl::OUString	sGluePoints( RTL_CONSTASCII_USTRINGPARAM ( "GluePoints" ) );
1210 			pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sGluePoints );
1211 			if ( pAny && pDefCustomShape && pDefCustomShape->nGluePoints && pDefCustomShape->pGluePoints )
1212 			{
1213 				com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair> seqGluePoints1, seqGluePoints2;
1214 				if ( *pAny >>= seqGluePoints1 )
1215 				{
1216 					sal_Int32 i, nCount = pDefCustomShape->nGluePoints;
1217 					seqGluePoints2.realloc( nCount );
1218 					for ( i = 0; i < nCount; i++ )
1219 					{
1220 						EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqGluePoints2[ i ].First, pDefCustomShape->pGluePoints[ i ].nValA );
1221 						EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqGluePoints2[ i ].Second, pDefCustomShape->pGluePoints[ i ].nValB );
1222 					}
1223 					if ( seqGluePoints1 == seqGluePoints2 )
1224 						bIsDefaultGeometry = sal_True;
1225 				}
1226 			}
1227 			else if ( pDefCustomShape && ( pDefCustomShape->nGluePoints == 0 ) )
1228 				bIsDefaultGeometry = sal_True;
1229 		}
1230 		break;
1231 
1232 		case DEFAULT_SEGMENTS :
1233 		{
1234 			///////////////////
1235 			// Path/Segments //
1236 			///////////////////
1237 			const rtl::OUString	sSegments( RTL_CONSTASCII_USTRINGPARAM ( "Segments" ) );
1238 			pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sSegments );
1239 			if ( pAny )
1240 			{
1241 				com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeSegment > seqSegments1, seqSegments2;
1242 				if ( *pAny >>= seqSegments1 )
1243 				{
1244 					if ( pDefCustomShape && pDefCustomShape->nElements && pDefCustomShape->pElements )
1245 					{
1246 						sal_Int32 i, nCount = pDefCustomShape->nElements;
1247 						if ( nCount )
1248 						{
1249 							seqSegments2.realloc( nCount );
1250 							for ( i = 0; i < nCount; i++ )
1251 							{
1252 								EnhancedCustomShapeSegment& rSegInfo = seqSegments2[ i ];
1253 								sal_uInt16 nSDat = pDefCustomShape->pElements[ i ];
1254 								switch( nSDat >> 8 )
1255 								{
1256 									case 0x00 :
1257 									{
1258 										rSegInfo.Command = EnhancedCustomShapeSegmentCommand::LINETO;
1259 										rSegInfo.Count   = nSDat & 0xff;
1260 										if ( !rSegInfo.Count )
1261 											rSegInfo.Count = 1;
1262 									}
1263 									break;
1264 									case 0x20 :
1265 									{
1266 										rSegInfo.Command = EnhancedCustomShapeSegmentCommand::CURVETO;
1267 										rSegInfo.Count   = nSDat & 0xff;
1268 										if ( !rSegInfo.Count )
1269 											rSegInfo.Count = 1;
1270 									}
1271 									break;
1272 									case 0x40 :
1273 									{
1274 										rSegInfo.Command = EnhancedCustomShapeSegmentCommand::MOVETO;
1275 										rSegInfo.Count   = nSDat & 0xff;
1276 										if ( !rSegInfo.Count )
1277 											rSegInfo.Count = 1;
1278 									}
1279 									break;
1280 									case 0x60 :
1281 									{
1282 										rSegInfo.Command = EnhancedCustomShapeSegmentCommand::CLOSESUBPATH;
1283 										rSegInfo.Count   = 0;
1284 									}
1285 									break;
1286 									case 0x80 :
1287 									{
1288 										rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ENDSUBPATH;
1289 										rSegInfo.Count   = 0;
1290 									}
1291 									break;
1292 									case 0xa1 :
1293 									{
1294 										rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ANGLEELLIPSETO;
1295 										rSegInfo.Count   = ( nSDat & 0xff ) / 3;
1296 									}
1297 									break;
1298 									case 0xa2 :
1299 									{
1300 										rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ANGLEELLIPSE;
1301 										rSegInfo.Count   = ( nSDat & 0xff ) / 3;
1302 									}
1303 									break;
1304 									case 0xa3 :
1305 									{
1306 										rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ARCTO;
1307 										rSegInfo.Count   = ( nSDat & 0xff ) >> 2;
1308 									}
1309 									break;
1310 									case 0xa4 :
1311 									{
1312 										rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ARC;
1313 										rSegInfo.Count   = ( nSDat & 0xff ) >> 2;
1314 									}
1315 									break;
1316 									case 0xa5 :
1317 									{
1318 										rSegInfo.Command = EnhancedCustomShapeSegmentCommand::CLOCKWISEARCTO;
1319 										rSegInfo.Count   = ( nSDat & 0xff ) >> 2;
1320 									}
1321 									break;
1322 									case 0xa6 :
1323 									{
1324 										rSegInfo.Command = EnhancedCustomShapeSegmentCommand::CLOCKWISEARC;
1325 										rSegInfo.Count   = ( nSDat & 0xff ) >> 2;
1326 									}
1327 									break;
1328 									case 0xa7 :
1329 									{
1330 										rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ELLIPTICALQUADRANTX;
1331 										rSegInfo.Count   = nSDat & 0xff;
1332 									}
1333 									break;
1334 									case 0xa8 :
1335 									{
1336 										rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ELLIPTICALQUADRANTY;
1337 										rSegInfo.Count   = nSDat & 0xff;
1338 									}
1339 									break;
1340 									case 0xaa :
1341 									{
1342 										rSegInfo.Command = EnhancedCustomShapeSegmentCommand::NOFILL;
1343 										rSegInfo.Count   = 0;
1344 									}
1345 									break;
1346 									case 0xab :
1347 									{
1348 										rSegInfo.Command = EnhancedCustomShapeSegmentCommand::NOSTROKE;
1349 										rSegInfo.Count   = 0;
1350 									}
1351 									break;
1352 									default:
1353 									case 0xf8 :
1354 									{
1355 										rSegInfo.Command = EnhancedCustomShapeSegmentCommand::UNKNOWN;
1356 										rSegInfo.Count   = nSDat;
1357 									}
1358 									break;
1359 								}
1360 							}
1361 							if ( seqSegments1 == seqSegments2 )
1362 								bIsDefaultGeometry = sal_True;
1363 						}
1364 					}
1365 					else
1366 					{
1367 						// check if its the default segment description	( M L Z N )
1368 						if ( seqSegments1.getLength() == 4 )
1369 						{
1370 							if ( ( seqSegments1[ 0 ].Command == EnhancedCustomShapeSegmentCommand::MOVETO )
1371 								&& ( seqSegments1[ 1 ].Command == EnhancedCustomShapeSegmentCommand::LINETO )
1372 								&& ( seqSegments1[ 2 ].Command == EnhancedCustomShapeSegmentCommand::CLOSESUBPATH )
1373 								&& ( seqSegments1[ 3 ].Command == EnhancedCustomShapeSegmentCommand::ENDSUBPATH ) )
1374 								bIsDefaultGeometry = sal_True;
1375 						}
1376 					}
1377 				}
1378 			}
1379 			else if ( pDefCustomShape && ( ( pDefCustomShape->nElements == 0 ) || ( pDefCustomShape->pElements == 0 ) ) )
1380 				bIsDefaultGeometry = sal_True;
1381 		}
1382 		break;
1383 
1384 		case DEFAULT_STRETCHX :
1385 		{
1386 			const rtl::OUString	sStretchX( RTL_CONSTASCII_USTRINGPARAM ( "StretchX" ) );
1387 			pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sStretchX );
1388 			if ( pAny && pDefCustomShape )
1389 			{
1390 				sal_Int32 nStretchX = 0;
1391 				if ( *pAny >>= nStretchX )
1392 				{
1393 					if ( pDefCustomShape->nXRef == nStretchX )
1394 						bIsDefaultGeometry = sal_True;
1395 				}
1396 			}
1397 			else if ( pDefCustomShape && ( pDefCustomShape->nXRef == DEFAULT_MINIMUM_SIGNED_COMPARE ) )
1398 				bIsDefaultGeometry = sal_True;
1399 		}
1400 		break;
1401 
1402 		case DEFAULT_STRETCHY :
1403 		{
1404 			const rtl::OUString	sStretchY( RTL_CONSTASCII_USTRINGPARAM ( "StretchY" ) );
1405 			pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sStretchY );
1406 			if ( pAny && pDefCustomShape )
1407 			{
1408 				sal_Int32 nStretchY = 0;
1409 				if ( *pAny >>= nStretchY )
1410 				{
1411 					if ( pDefCustomShape->nYRef == nStretchY )
1412 						bIsDefaultGeometry = sal_True;
1413 				}
1414 			}
1415 			else if ( pDefCustomShape && ( pDefCustomShape->nYRef == DEFAULT_MINIMUM_SIGNED_COMPARE ) )
1416 				bIsDefaultGeometry = sal_True;
1417 		}
1418 		break;
1419 
1420 		case DEFAULT_EQUATIONS :
1421 		{
1422 			const rtl::OUString	sEquations( RTL_CONSTASCII_USTRINGPARAM( "Equations" ) );
1423 			pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sEquations );
1424 			if ( pAny && pDefCustomShape && pDefCustomShape->nCalculation && pDefCustomShape->pCalculation )
1425 			{
1426 				com::sun::star::uno::Sequence< rtl::OUString > seqEquations1, seqEquations2;
1427 				if ( *pAny >>= seqEquations1 )
1428 				{
1429 					sal_Int32 i, nCount = pDefCustomShape->nCalculation;
1430 					seqEquations2.realloc( nCount );
1431 
1432 					const SvxMSDffCalculationData* pData = pDefCustomShape->pCalculation;
1433 					for ( i = 0; i < nCount; i++, pData++ )
1434 						seqEquations2[ i ] = EnhancedCustomShape2d::GetEquation( pData->nFlags, pData->nVal[ 0 ], pData->nVal[ 1 ], pData->nVal[ 2 ] );
1435 
1436 					if ( seqEquations1 == seqEquations2 )
1437 						bIsDefaultGeometry = sal_True;
1438 				}
1439 			}
1440 			else if ( pDefCustomShape && ( ( pDefCustomShape->nCalculation == 0 ) || ( pDefCustomShape->pCalculation == 0 ) ) )
1441 				bIsDefaultGeometry = sal_True;
1442 		}
1443 		break;
1444 
1445 		case DEFAULT_TEXTFRAMES :
1446 		{
1447 			const rtl::OUString	sTextFrames( RTL_CONSTASCII_USTRINGPARAM( "TextFrames" ) );
1448 			pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sTextFrames );
1449 			if ( pAny && pDefCustomShape && pDefCustomShape->nTextRect && pDefCustomShape->pTextRect )
1450 			{
1451 				com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeTextFrame > seqTextFrames1, seqTextFrames2;
1452 				if ( *pAny >>= seqTextFrames1 )
1453 				{
1454 					sal_Int32 i, nCount = pDefCustomShape->nTextRect;
1455 					seqTextFrames2.realloc( nCount );
1456 					const SvxMSDffTextRectangles* pRectangles = pDefCustomShape->pTextRect;
1457 					for ( i = 0; i < nCount; i++, pRectangles++ )
1458 					{
1459 						EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqTextFrames2[ i ].TopLeft.First,	  pRectangles->nPairA.nValA );
1460 						EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqTextFrames2[ i ].TopLeft.Second,	  pRectangles->nPairA.nValB );
1461 						EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqTextFrames2[ i ].BottomRight.First,  pRectangles->nPairB.nValA );
1462 						EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqTextFrames2[ i ].BottomRight.Second, pRectangles->nPairB.nValB );
1463 					}
1464 					if ( seqTextFrames1 == seqTextFrames2 )
1465 						bIsDefaultGeometry = sal_True;
1466 				}
1467 			}
1468 			else if ( pDefCustomShape && ( ( pDefCustomShape->nTextRect == 0 ) || ( pDefCustomShape->pTextRect == 0 ) ) )
1469 				bIsDefaultGeometry = sal_True;
1470 		}
1471 		break;
1472 
1473 		case DEFAULT_HANDLES :
1474 		{
1475 			const rtl::OUString	sHandles( RTL_CONSTASCII_USTRINGPARAM( "Handles" ) );
1476 			pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sHandles );
1477 			if ( pAny && pDefCustomShape && pDefCustomShape->nHandles && pDefCustomShape->pHandles )
1478 			{
1479 				com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValues > seqHandles1, seqHandles2;
1480 				if ( *pAny >>= seqHandles1 )
1481 				{
1482 					sal_Int32 i, n, nCount = pDefCustomShape->nHandles;
1483 					const SvxMSDffHandle* pData = pDefCustomShape->pHandles;
1484 					seqHandles2.realloc( nCount );
1485 					for ( i = 0; i < nCount; i++, pData++ )
1486 					{
1487 						sal_Int32 nPropertiesNeeded = 1;	// position is always needed
1488 						sal_Int32 nFlags = pData->nFlags;
1489 						if ( nFlags & MSDFF_HANDLE_FLAGS_MIRRORED_X )
1490 							nPropertiesNeeded++;
1491 						if ( nFlags & MSDFF_HANDLE_FLAGS_MIRRORED_Y )
1492 							nPropertiesNeeded++;
1493 						if ( nFlags & MSDFF_HANDLE_FLAGS_SWITCHED )
1494 							nPropertiesNeeded++;
1495 						if ( nFlags & MSDFF_HANDLE_FLAGS_POLAR )
1496 						{
1497 							nPropertiesNeeded++;
1498 							if ( nFlags & MSDFF_HANDLE_FLAGS_RADIUS_RANGE )
1499 							{
1500 								if ( pData->nRangeXMin != DEFAULT_MINIMUM_SIGNED_COMPARE )
1501 									nPropertiesNeeded++;
1502 								if ( pData->nRangeXMax != DEFAULT_MAXIMUM_SIGNED_COMPARE )
1503 									nPropertiesNeeded++;
1504 							}
1505 						}
1506 						else if ( nFlags & MSDFF_HANDLE_FLAGS_RANGE )
1507 						{
1508 							if ( pData->nRangeXMin != DEFAULT_MINIMUM_SIGNED_COMPARE )
1509 								nPropertiesNeeded++;
1510 							if ( pData->nRangeXMax != DEFAULT_MAXIMUM_SIGNED_COMPARE )
1511 								nPropertiesNeeded++;
1512 							if ( pData->nRangeYMin != DEFAULT_MINIMUM_SIGNED_COMPARE )
1513 								nPropertiesNeeded++;
1514 							if ( pData->nRangeYMax != DEFAULT_MAXIMUM_SIGNED_COMPARE )
1515 								nPropertiesNeeded++;
1516 						}
1517 
1518 						n = 0;
1519 						com::sun::star::beans::PropertyValues& rPropValues = seqHandles2[ i ];
1520 						rPropValues.realloc( nPropertiesNeeded );
1521 
1522 						// POSITION
1523 						{
1524 							const rtl::OUString	sPosition( RTL_CONSTASCII_USTRINGPARAM ( "Position" ) );
1525 							::com::sun::star::drawing::EnhancedCustomShapeParameterPair aPosition;
1526 							EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aPosition.First, pData->nPositionX, sal_True, sal_True );
1527 							EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aPosition.Second, pData->nPositionY, sal_True, sal_False );
1528 							rPropValues[ n ].Name = sPosition;
1529 							rPropValues[ n++ ].Value <<= aPosition;
1530 						}
1531 						if ( nFlags & MSDFF_HANDLE_FLAGS_MIRRORED_X )
1532 						{
1533 							const rtl::OUString	sMirroredX( RTL_CONSTASCII_USTRINGPARAM ( "MirroredX" ) );
1534 							sal_Bool bMirroredX = sal_True;
1535 							rPropValues[ n ].Name = sMirroredX;
1536 							rPropValues[ n++ ].Value <<= bMirroredX;
1537 						}
1538 						if ( nFlags & MSDFF_HANDLE_FLAGS_MIRRORED_Y )
1539 						{
1540 							const rtl::OUString	sMirroredY( RTL_CONSTASCII_USTRINGPARAM ( "MirroredY" ) );
1541 							sal_Bool bMirroredY = sal_True;
1542 							rPropValues[ n ].Name = sMirroredY;
1543 							rPropValues[ n++ ].Value <<= bMirroredY;
1544 						}
1545 						if ( nFlags & MSDFF_HANDLE_FLAGS_SWITCHED )
1546 						{
1547 							const rtl::OUString	sSwitched( RTL_CONSTASCII_USTRINGPARAM ( "Switched" ) );
1548 							sal_Bool bSwitched = sal_True;
1549 							rPropValues[ n ].Name = sSwitched;
1550 							rPropValues[ n++ ].Value <<= bSwitched;
1551 						}
1552 						if ( nFlags & MSDFF_HANDLE_FLAGS_POLAR )
1553 						{
1554 							const rtl::OUString	sPolar( RTL_CONSTASCII_USTRINGPARAM ( "Polar" ) );
1555 							::com::sun::star::drawing::EnhancedCustomShapeParameterPair aCenter;
1556 							EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aCenter.First,  pData->nCenterX,
1557 								( nFlags & MSDFF_HANDLE_FLAGS_CENTER_X_IS_SPECIAL ) != 0, sal_True  );
1558 							EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aCenter.Second, pData->nCenterY,
1559 								( nFlags & MSDFF_HANDLE_FLAGS_CENTER_Y_IS_SPECIAL ) != 0, sal_False );
1560 							rPropValues[ n ].Name = sPolar;
1561 							rPropValues[ n++ ].Value <<= aCenter;
1562 							if ( nFlags & MSDFF_HANDLE_FLAGS_RADIUS_RANGE )
1563 							{
1564 								if ( pData->nRangeXMin != DEFAULT_MINIMUM_SIGNED_COMPARE )
1565 								{
1566 									const rtl::OUString	sRadiusRangeMinimum( RTL_CONSTASCII_USTRINGPARAM ( "RadiusRangeMinimum" ) );
1567 									::com::sun::star::drawing::EnhancedCustomShapeParameter aRadiusRangeMinimum;
1568 									EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRadiusRangeMinimum, pData->nRangeXMin,
1569 										( nFlags & MSDFF_HANDLE_FLAGS_RANGE_X_MIN_IS_SPECIAL ) != 0, sal_True  );
1570 									rPropValues[ n ].Name = sRadiusRangeMinimum;
1571 									rPropValues[ n++ ].Value <<= aRadiusRangeMinimum;
1572 								}
1573 								if ( pData->nRangeXMax != DEFAULT_MAXIMUM_SIGNED_COMPARE )
1574 								{
1575 									const rtl::OUString	sRadiusRangeMaximum( RTL_CONSTASCII_USTRINGPARAM ( "RadiusRangeMaximum" ) );
1576 									::com::sun::star::drawing::EnhancedCustomShapeParameter aRadiusRangeMaximum;
1577 									EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRadiusRangeMaximum, pData->nRangeXMax,
1578 										( nFlags & MSDFF_HANDLE_FLAGS_RANGE_X_MAX_IS_SPECIAL ) != 0, sal_False );
1579 									rPropValues[ n ].Name = sRadiusRangeMaximum;
1580 									rPropValues[ n++ ].Value <<= aRadiusRangeMaximum;
1581 								}
1582 							}
1583 						}
1584 						else if ( nFlags & MSDFF_HANDLE_FLAGS_RANGE )
1585 						{
1586 							if ( pData->nRangeXMin != DEFAULT_MINIMUM_SIGNED_COMPARE )
1587 							{
1588 								const rtl::OUString	sRangeXMinimum( RTL_CONSTASCII_USTRINGPARAM ( "RangeXMinimum" ) );
1589 								::com::sun::star::drawing::EnhancedCustomShapeParameter aRangeXMinimum;
1590 								EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRangeXMinimum, pData->nRangeXMin,
1591 									( nFlags & MSDFF_HANDLE_FLAGS_RANGE_X_MIN_IS_SPECIAL ) != 0, sal_True  );
1592 								rPropValues[ n ].Name = sRangeXMinimum;
1593 								rPropValues[ n++ ].Value <<= aRangeXMinimum;
1594 							}
1595 							if ( pData->nRangeXMax != DEFAULT_MAXIMUM_SIGNED_COMPARE )
1596 							{
1597 								const rtl::OUString	sRangeXMaximum( RTL_CONSTASCII_USTRINGPARAM ( "RangeXMaximum" ) );
1598 								::com::sun::star::drawing::EnhancedCustomShapeParameter aRangeXMaximum;
1599 								EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRangeXMaximum, pData->nRangeXMax,
1600 									( nFlags & MSDFF_HANDLE_FLAGS_RANGE_X_MAX_IS_SPECIAL ) != 0, sal_False );
1601 								rPropValues[ n ].Name = sRangeXMaximum;
1602 								rPropValues[ n++ ].Value <<= aRangeXMaximum;
1603 							}
1604 							if ( pData->nRangeYMin != DEFAULT_MINIMUM_SIGNED_COMPARE )
1605 							{
1606 								const rtl::OUString	sRangeYMinimum( RTL_CONSTASCII_USTRINGPARAM ( "RangeYMinimum" ) );
1607 								::com::sun::star::drawing::EnhancedCustomShapeParameter aRangeYMinimum;
1608 								EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRangeYMinimum, pData->nRangeYMin,
1609 									( nFlags & MSDFF_HANDLE_FLAGS_RANGE_Y_MIN_IS_SPECIAL ) != 0, sal_True );
1610 								rPropValues[ n ].Name = sRangeYMinimum;
1611 								rPropValues[ n++ ].Value <<= aRangeYMinimum;
1612 							}
1613 							if ( pData->nRangeYMax != DEFAULT_MAXIMUM_SIGNED_COMPARE )
1614 							{
1615 								const rtl::OUString	sRangeYMaximum( RTL_CONSTASCII_USTRINGPARAM ( "RangeYMaximum" ) );
1616 								::com::sun::star::drawing::EnhancedCustomShapeParameter aRangeYMaximum;
1617 								EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRangeYMaximum, pData->nRangeYMax,
1618 									( nFlags & MSDFF_HANDLE_FLAGS_RANGE_Y_MAX_IS_SPECIAL ) != 0, sal_False );
1619 								rPropValues[ n ].Name = sRangeYMaximum;
1620 								rPropValues[ n++ ].Value <<= aRangeYMaximum;
1621 							}
1622 						}
1623 					}
1624 					if ( seqHandles1 == seqHandles2 )
1625 						bIsDefaultGeometry = sal_True;
1626 				}
1627 			}
1628 			else if ( pDefCustomShape && ( ( pDefCustomShape->nHandles == 0 ) || ( pDefCustomShape->pHandles == 0 ) ) )
1629 				bIsDefaultGeometry = sal_True;
1630 		}
1631 		break;
1632 	}
1633 	return bIsDefaultGeometry;
1634 }
1635 
1636 void SdrObjCustomShape::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
1637 {
1638 	rInfo.bResizeFreeAllowed=fObjectRotation == 0.0;
1639 	rInfo.bResizePropAllowed=sal_True;
1640 	rInfo.bRotateFreeAllowed=sal_True;
1641 	rInfo.bRotate90Allowed  =sal_True;
1642 	rInfo.bMirrorFreeAllowed=sal_True;
1643 	rInfo.bMirror45Allowed  =sal_True;
1644 	rInfo.bMirror90Allowed  =sal_True;
1645 	rInfo.bTransparenceAllowed = sal_False;
1646 	rInfo.bGradientAllowed = sal_False;
1647 	rInfo.bShearAllowed     =sal_True;
1648 	rInfo.bEdgeRadiusAllowed=sal_False;
1649 	rInfo.bNoContortion     =sal_True;
1650 
1651 	// #i37011#
1652 	if ( mXRenderedCustomShape.is() )
1653 	{
1654 		const SdrObject* pRenderedCustomShape = GetSdrObjectFromXShape( mXRenderedCustomShape );
1655 		if ( pRenderedCustomShape )
1656 		{
1657 			// #i37262#
1658 			// Iterate self over the contained objects, since there are combinations of
1659 			// polygon and curve objects. In that case, aInfo.bCanConvToPath and
1660 			// aInfo.bCanConvToPoly would be false. What is needed here is an or, not an and.
1661 			SdrObjListIter aIterator(*pRenderedCustomShape);
1662 			while(aIterator.IsMore())
1663 			{
1664 				SdrObject* pCandidate = aIterator.Next();
1665 				SdrObjTransformInfoRec aInfo;
1666 				pCandidate->TakeObjInfo(aInfo);
1667 
1668 				// set path and poly conversion if one is possible since
1669 				// this object will first be broken
1670 				const sal_Bool bCanConvToPathOrPoly(aInfo.bCanConvToPath || aInfo.bCanConvToPoly);
1671 				if(rInfo.bCanConvToPath != bCanConvToPathOrPoly)
1672 				{
1673 					rInfo.bCanConvToPath = bCanConvToPathOrPoly;
1674 				}
1675 
1676 				if(rInfo.bCanConvToPoly != bCanConvToPathOrPoly)
1677 				{
1678 					rInfo.bCanConvToPoly = bCanConvToPathOrPoly;
1679 				}
1680 
1681 				if(rInfo.bCanConvToContour != aInfo.bCanConvToContour)
1682 				{
1683 					rInfo.bCanConvToContour = aInfo.bCanConvToContour;
1684 				}
1685 			}
1686 		}
1687 	}
1688 }
1689 
1690 void SdrObjCustomShape::SetModel(SdrModel* pNewModel)
1691 {
1692 	SdrTextObj::SetModel(pNewModel);
1693 	mXRenderedCustomShape.clear();
1694 }
1695 
1696 sal_uInt16 SdrObjCustomShape::GetObjIdentifier() const
1697 {
1698 	return sal_uInt16(OBJ_CUSTOMSHAPE);
1699 }
1700 
1701 ////////////////////////////////////////////////////////////////////////////////////////////////////
1702 ////////////////////////////////////////////////////////////////////////////////////////////////////
1703 ////////////////////////////////////////////////////////////////////////////////////////////////////
1704 
1705 void SdrObjCustomShape::RecalcSnapRect()
1706 {
1707 	SdrTextObj::RecalcSnapRect();
1708 }
1709 const Rectangle& SdrObjCustomShape::GetSnapRect() const
1710 {
1711 	return SdrTextObj::GetSnapRect();
1712 }
1713 const Rectangle& SdrObjCustomShape::GetCurrentBoundRect() const
1714 {
1715 	return SdrTextObj::GetCurrentBoundRect();
1716 }
1717 const Rectangle& SdrObjCustomShape::GetLogicRect() const
1718 {
1719 	return SdrTextObj::GetLogicRect();
1720 }
1721 void SdrObjCustomShape::NbcSetSnapRect( const Rectangle& rRect )
1722 {
1723 	aRect=rRect;
1724 	ImpJustifyRect(aRect);
1725 	InvalidateRenderGeometry();
1726 	Rectangle aTextBound( aRect );
1727 	if ( GetTextBounds( aTextBound ) )
1728 	{
1729 		if ( pModel==NULL || !pModel->IsPasteResize() )
1730 		{
1731 			long nHDist=GetTextLeftDistance()+GetTextRightDistance();
1732 			long nVDist=GetTextUpperDistance()+GetTextLowerDistance();
1733 			long nTWdt=aTextBound.GetWidth ()-1-nHDist; if (nTWdt<0) nTWdt=0;
1734 			long nTHgt=aTextBound.GetHeight()-1-nVDist; if (nTHgt<0) nTHgt=0;
1735 			if ( IsAutoGrowWidth() )
1736 				NbcSetMinTextFrameWidth( nTWdt );
1737 			if ( IsAutoGrowHeight() )
1738 				NbcSetMinTextFrameHeight( nTHgt );
1739 			NbcAdjustTextFrameWidthAndHeight();
1740 		}
1741 	}
1742 	ImpCheckShear();
1743 	SetRectsDirty();
1744 	SetChanged();
1745 }
1746 void SdrObjCustomShape::SetSnapRect( const Rectangle& rRect )
1747 {
1748 	Rectangle aBoundRect0;
1749 	if ( pUserCall )
1750 		aBoundRect0 = GetLastBoundRect();
1751 	NbcSetSnapRect( rRect );
1752 	BroadcastObjectChange();
1753 	SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
1754 }
1755 void SdrObjCustomShape::NbcSetLogicRect( const Rectangle& rRect )
1756 {
1757 	aRect = rRect;
1758 	ImpJustifyRect( aRect );
1759 	InvalidateRenderGeometry();
1760 	Rectangle aTextBound( aRect );
1761 	if ( GetTextBounds( aTextBound ) )
1762 	{
1763 		long nHDist=GetTextLeftDistance()+GetTextRightDistance();
1764 		long nVDist=GetTextUpperDistance()+GetTextLowerDistance();
1765 
1766 		long nTWdt=aTextBound.GetWidth()-1-nHDist; if (nTWdt<0) nTWdt=0;
1767 		long nTHgt=aTextBound.GetHeight()-1-nVDist; if (nTHgt<0) nTHgt=0;
1768 		if ( IsAutoGrowWidth() )
1769 			NbcSetMinTextFrameWidth( nTWdt );
1770 		if ( IsAutoGrowHeight() )
1771 			NbcSetMinTextFrameHeight( nTHgt );
1772 		NbcAdjustTextFrameWidthAndHeight();
1773 	}
1774 	SetRectsDirty();
1775 	SetChanged();
1776 }
1777 void SdrObjCustomShape::SetLogicRect( const Rectangle& rRect )
1778 {
1779 	Rectangle aBoundRect0;
1780 	if ( pUserCall )
1781 		aBoundRect0 = GetLastBoundRect();
1782 	NbcSetLogicRect(rRect);
1783 	BroadcastObjectChange();
1784 	SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
1785 }
1786 void SdrObjCustomShape::Move( const Size& rSiz )
1787 {
1788 	if ( rSiz.Width() || rSiz.Height() )
1789 	{
1790 		Rectangle aBoundRect0;
1791 		if ( pUserCall )
1792 			aBoundRect0 = GetLastBoundRect();
1793 		// #110094#-14 SendRepaintBroadcast();
1794 		NbcMove(rSiz);
1795 		SetChanged();
1796 		BroadcastObjectChange();
1797 		SendUserCall(SDRUSERCALL_MOVEONLY,aBoundRect0);
1798 	}
1799 }
1800 void SdrObjCustomShape::NbcMove( const Size& rSiz )
1801 {
1802 	SdrTextObj::NbcMove( rSiz );
1803 	if ( mXRenderedCustomShape.is() )
1804 	{
1805 		SdrObject* pRenderedCustomShape = GetSdrObjectFromXShape( mXRenderedCustomShape );
1806 		if ( pRenderedCustomShape )
1807         {
1808             // #i97149# the visualisation shape needs to be informed
1809             // about change, too
1810             pRenderedCustomShape->ActionChanged();
1811 			pRenderedCustomShape->NbcMove( rSiz );
1812         }
1813 	}
1814 
1815 	// #i37011# adapt geometry shadow
1816 	if(mpLastShadowGeometry)
1817 	{
1818 		mpLastShadowGeometry->NbcMove( rSiz );
1819 	}
1820 }
1821 void SdrObjCustomShape::Resize( const Point& rRef, const Fraction& xFact, const Fraction& yFact )
1822 {
1823 	SdrTextObj::Resize( rRef, xFact, yFact );
1824 }
1825 
1826 void SdrObjCustomShape::NbcResize( const Point& rRef, const Fraction& rxFact, const Fraction& ryFact )
1827 {
1828 	Fraction xFact( rxFact );
1829 	Fraction yFact( ryFact );
1830 
1831 	// taking care of handles that should not been changed
1832 	Rectangle aOld( aRect );
1833 	std::vector< SdrCustomShapeInteraction > aInteractionHandles( GetInteractionHandles( this ) );
1834 
1835 	SdrTextObj::NbcResize( rRef, xFact, yFact );
1836 
1837 	if ( ( xFact.GetNumerator() != xFact.GetDenominator() )
1838 		|| ( yFact.GetNumerator()!= yFact.GetDenominator() ) )
1839 	{
1840 		if ( ( ( xFact.GetNumerator() < 0 ) && ( xFact.GetDenominator() > 0 ) ) ||
1841 			( ( xFact.GetNumerator() > 0 ) && ( xFact.GetDenominator() < 0 ) ) )
1842 		{
1843 			SetMirroredX( IsMirroredX() == sal_False );
1844 		}
1845 		if ( ( ( yFact.GetNumerator() < 0 ) && ( yFact.GetDenominator() > 0 ) ) ||
1846 			( ( yFact.GetNumerator() > 0 ) && ( yFact.GetDenominator() < 0 ) ) )
1847 		{
1848 			SetMirroredY( IsMirroredY() == sal_False );
1849 		}
1850 	}
1851 
1852 	std::vector< SdrCustomShapeInteraction >::iterator aIter( aInteractionHandles.begin() );
1853 	while ( aIter != aInteractionHandles.end() )
1854 	{
1855 		try
1856 		{
1857 			if ( aIter->nMode & CUSTOMSHAPE_HANDLE_RESIZE_FIXED )
1858 				aIter->xInteraction->setControllerPosition( aIter->aPosition );
1859 			if ( aIter->nMode & CUSTOMSHAPE_HANDLE_RESIZE_ABSOLUTE_X )
1860 			{
1861 				sal_Int32 nX = ( aIter->aPosition.X - aOld.Left() ) + aRect.Left();
1862 				aIter->xInteraction->setControllerPosition( com::sun::star::awt::Point( nX, aIter->xInteraction->getPosition().Y ) );
1863 			}
1864 			if ( aIter->nMode & CUSTOMSHAPE_HANDLE_RESIZE_ABSOLUTE_Y )
1865 			{
1866 				sal_Int32 nY = ( aIter->aPosition.Y - aOld.Top() ) + aRect.Top();
1867 				aIter->xInteraction->setControllerPosition( com::sun::star::awt::Point( aIter->xInteraction->getPosition().X, nY ) );
1868 			}
1869 		}
1870 		catch ( const uno::RuntimeException& )
1871 		{
1872 		}
1873 		aIter++;
1874 	}
1875 	InvalidateRenderGeometry();
1876 }
1877 void SdrObjCustomShape::NbcRotate( const Point& rRef, long nWink, double sn, double cs )
1878 {
1879 	sal_Bool bMirroredX = IsMirroredX();
1880 	sal_Bool bMirroredY = IsMirroredY();
1881 
1882 	fObjectRotation = fmod( fObjectRotation, 360.0 );
1883 	if ( fObjectRotation < 0 )
1884 		fObjectRotation = 360 + fObjectRotation;
1885 
1886 	// the rotation angle for ashapes is stored in fObjectRotation, this rotation
1887 	// has to be applied to the text object (which is internally using aGeo.nWink).
1888 	SdrTextObj::NbcRotate( aRect.TopLeft(), -aGeo.nDrehWink,		// retrieving the unrotated text object
1889 							sin( (-aGeo.nDrehWink) * F_PI18000 ),
1890 							cos( (-aGeo.nDrehWink) * F_PI18000 ) );
1891 	aGeo.nDrehWink = 0;												// resetting aGeo data
1892 	aGeo.RecalcSinCos();
1893 
1894 	long nW = (long)( fObjectRotation * 100 );						// applying our object rotation
1895 	if ( bMirroredX )
1896 		nW = 36000 - nW;
1897 	if ( bMirroredY )
1898 		nW = 18000 - nW;
1899 	nW = nW % 36000;
1900 	if ( nW < 0 )
1901 		nW = 36000 + nW;
1902 	SdrTextObj::NbcRotate( aRect.TopLeft(), nW,						// applying text rotation
1903 							sin( nW * F_PI18000 ),
1904 							cos( nW * F_PI18000 ) );
1905 
1906 	int nSwap = 0;
1907 	if ( bMirroredX )
1908 		nSwap ^= 1;
1909 	if ( bMirroredY )
1910 		nSwap ^= 1;
1911 
1912 	double fWink = nWink;													// updating to our new object rotation
1913 	fWink /= 100.0;
1914 	fObjectRotation = fmod( nSwap ? fObjectRotation - fWink : fObjectRotation + fWink, 360.0 );
1915 	if ( fObjectRotation < 0 )
1916 		fObjectRotation = 360 + fObjectRotation;
1917 
1918 	SdrTextObj::NbcRotate( rRef, nWink, sn, cs );							// applying text rotation
1919 	InvalidateRenderGeometry();
1920 }
1921 
1922 void SdrObjCustomShape::NbcMirror( const Point& rRef1, const Point& rRef2 )
1923 {
1924     // TTTT: Fix for old mirroring, can be removed again in aw080
1925     // storing horizontal and vertical flipping without modifying the rotate angle
1926     // decompose other flipping to rotation and MirrorX.
1927     long ndx = rRef2.X()-rRef1.X();
1928     long ndy = rRef2.Y()-rRef1.Y();
1929 
1930     if(!ndx) // MirroredX
1931     {
1932          SetMirroredX(!IsMirroredX());
1933          SdrTextObj::NbcMirror( rRef1, rRef2 );
1934     }
1935     else
1936     {
1937         if(!ndy)  // MirroredY
1938         {
1939             SetMirroredY(!IsMirroredY());
1940             SdrTextObj::NbcMirror( rRef1, rRef2 );
1941         }
1942         else // neither horizontal nor vertical
1943         {
1944             SetMirroredX(!IsMirroredX());
1945 
1946             // call parent
1947             SdrTextObj::NbcMirror( rRef1, rRef2 );
1948 
1949             // update fObjectRotation
1950             long nTextObjRotation = aGeo.nDrehWink;
1951             double fWink = nTextObjRotation;
1952 
1953             fWink /= 100.0;
1954 
1955             bool bSingleFlip = (IsMirroredX()!= IsMirroredY());
1956 
1957             fObjectRotation = fmod( bSingleFlip ? -fWink : fWink, 360.0 );
1958 
1959             if ( fObjectRotation < 0 )
1960             {
1961                 fObjectRotation = 360.0 + fObjectRotation;
1962             }
1963          }
1964     }
1965 
1966     InvalidateRenderGeometry();
1967 }
1968 
1969 void SdrObjCustomShape::Shear( const Point& rRef, long nWink, double tn, FASTBOOL bVShear )
1970 {
1971 	SdrTextObj::Shear( rRef, nWink, tn, bVShear );
1972 	InvalidateRenderGeometry();
1973 }
1974 void SdrObjCustomShape::NbcShear( const Point& rRef, long nWink, double tn, FASTBOOL bVShear )
1975 {
1976     // TTTT: Fix for old mirroring, can be removed again in aw080
1977      SdrTextObj::NbcShear(rRef,nWink,tn,bVShear);
1978 
1979     // updating fObjectRotation
1980     long nTextObjRotation = aGeo.nDrehWink;
1981     double fWink = nTextObjRotation;
1982 
1983     fWink /= 100.0;
1984 
1985     bool bSingleFlip = (IsMirroredX()!= IsMirroredY());
1986 
1987     fObjectRotation = fmod( bSingleFlip ? -fWink : fWink, 360.0 );
1988 
1989     if ( fObjectRotation < 0 )
1990     {
1991         fObjectRotation = 360.0 + fObjectRotation;
1992     }
1993 
1994     InvalidateRenderGeometry();
1995 }
1996 
1997 ////////////////////////////////////////////////////////////////////////////////////////////////////
1998 
1999 SdrGluePoint SdrObjCustomShape::GetVertexGluePoint(sal_uInt16 nPosNum) const
2000 {
2001 	sal_Int32 nWdt = ImpGetLineWdt(); // #i25616# ((XLineWidthItem&)(GetObjectItem(XATTR_LINEWIDTH))).GetValue();
2002 
2003 	// #i25616#
2004 	if(!LineIsOutsideGeometry())
2005 	{
2006 		nWdt++;
2007 		nWdt /= 2;
2008 	}
2009 
2010 	Point aPt;
2011 	switch (nPosNum) {
2012 		case 0: aPt=aRect.TopCenter();    aPt.Y()-=nWdt; break;
2013 		case 1: aPt=aRect.RightCenter();  aPt.X()+=nWdt; break;
2014 		case 2: aPt=aRect.BottomCenter(); aPt.Y()+=nWdt; break;
2015 		case 3: aPt=aRect.LeftCenter();   aPt.X()-=nWdt; break;
2016 	}
2017 	if (aGeo.nShearWink!=0) ShearPoint(aPt,aRect.TopLeft(),aGeo.nTan);
2018 	if (aGeo.nDrehWink!=0) RotatePoint(aPt,aRect.TopLeft(),aGeo.nSin,aGeo.nCos);
2019 	aPt-=GetSnapRect().Center();
2020 	SdrGluePoint aGP(aPt);
2021 	aGP.SetPercent(sal_False);
2022 	return aGP;
2023 }
2024 
2025 ////////////////////////////////////////////////////////////////////////////////////////////////////
2026 
2027 // #i38892#
2028 void SdrObjCustomShape::ImpCheckCustomGluePointsAreAdded()
2029 {
2030 	const SdrObject* pSdrObject = GetSdrObjectFromCustomShape();
2031 
2032 	if(pSdrObject)
2033 	{
2034 		const SdrGluePointList* pSource = pSdrObject->GetGluePointList();
2035 
2036 		if(pSource && pSource->GetCount())
2037 		{
2038 			if(!SdrTextObj::GetGluePointList())
2039 			{
2040 				SdrTextObj::ForceGluePointList();
2041 			}
2042 
2043 			const SdrGluePointList* pList = SdrTextObj::GetGluePointList();
2044 
2045 			if(pList)
2046 			{
2047 				SdrGluePointList aNewList;
2048 				sal_uInt16 a;
2049 
2050 				for(a = 0; a < pSource->GetCount(); a++)
2051 				{
2052 					SdrGluePoint aCopy((*pSource)[a]);
2053 					aCopy.SetUserDefined(sal_False);
2054 					aNewList.Insert(aCopy);
2055 				}
2056 
2057 				sal_Bool bMirroredX = IsMirroredX();
2058 				sal_Bool bMirroredY = IsMirroredY();
2059 
2060 				long nShearWink = aGeo.nShearWink;
2061 				double fTan = aGeo.nTan;
2062 
2063 				if ( aGeo.nDrehWink || nShearWink || bMirroredX || bMirroredY )
2064 				{
2065 					Polygon aPoly( aRect );
2066 					if( nShearWink )
2067 					{
2068 						sal_uInt16 nPointCount=aPoly.GetSize();
2069 						for (sal_uInt16 i=0; i<nPointCount; i++)
2070 							ShearPoint(aPoly[i],aRect.Center(), fTan, sal_False );
2071 					}
2072 					if ( aGeo.nDrehWink )
2073 						aPoly.Rotate( aRect.Center(), aGeo.nDrehWink / 10 );
2074 
2075 					Rectangle aBoundRect( aPoly.GetBoundRect() );
2076 					sal_Int32 nXDiff = aBoundRect.Left() - aRect.Left();
2077 					sal_Int32 nYDiff = aBoundRect.Top() - aRect.Top();
2078 
2079 					if (nShearWink&&((bMirroredX&&!bMirroredY)||(bMirroredY&&!bMirroredX)))
2080 					{
2081 						nShearWink = -nShearWink;
2082 						fTan = -fTan;
2083 					}
2084 
2085 					Point aRef( aRect.GetWidth() / 2, aRect.GetHeight() / 2 );
2086 					for ( a = 0; a < aNewList.GetCount(); a++ )
2087 					{
2088 						SdrGluePoint& rPoint = aNewList[ a ];
2089 						Point aGlue( rPoint.GetPos() );
2090 						if ( nShearWink )
2091 							ShearPoint( aGlue, aRef, fTan );
2092 
2093 						RotatePoint( aGlue, aRef, sin( fObjectRotation * F_PI180 ), cos( fObjectRotation * F_PI180 ) );
2094 						if ( bMirroredX )
2095 							aGlue.X() = aRect.GetWidth() - aGlue.X();
2096 						if ( bMirroredY )
2097 							aGlue.Y() = aRect.GetHeight() - aGlue.Y();
2098 						aGlue.X() -= nXDiff;
2099 						aGlue.Y() -= nYDiff;
2100 						rPoint.SetPos( aGlue );
2101 					}
2102 				}
2103 
2104 				for(a = 0; a < pList->GetCount(); a++)
2105 				{
2106 					const SdrGluePoint& rCandidate = (*pList)[a];
2107 
2108 					if(rCandidate.IsUserDefined())
2109 					{
2110 						aNewList.Insert(rCandidate);
2111 					}
2112 				}
2113 
2114 				// copy new list to local. This is NOT very convenient behaviour, the local
2115 				// GluePointList should not be set, but be delivered by using GetGluePointList(),
2116 				// maybe on demand. Since the local object is changed here, this is assumed to
2117 				// be a result of GetGluePointList and thus the list is copied
2118 				if(pPlusData)
2119 				{
2120 					*pPlusData->pGluePoints = aNewList;
2121 				}
2122 			}
2123 		}
2124 	}
2125 }
2126 
2127 // #i38892#
2128 const SdrGluePointList* SdrObjCustomShape::GetGluePointList() const
2129 {
2130 	((SdrObjCustomShape*)this)->ImpCheckCustomGluePointsAreAdded();
2131 	return SdrTextObj::GetGluePointList();
2132 }
2133 
2134 // #i38892#
2135 //SdrGluePointList* SdrObjCustomShape::GetGluePointList()
2136 //{
2137 //	ImpCheckCustomGluePointsAreAdded();
2138 //	return SdrTextObj::GetGluePointList();
2139 //}
2140 
2141 // #i38892#
2142 SdrGluePointList* SdrObjCustomShape::ForceGluePointList()
2143 {
2144 	if(SdrTextObj::ForceGluePointList())
2145 	{
2146 		ImpCheckCustomGluePointsAreAdded();
2147 		return SdrTextObj::ForceGluePointList();
2148 	}
2149 	else
2150 	{
2151 		return 0L;
2152 	}
2153 }
2154 
2155 ////////////////////////////////////////////////////////////////////////////////////////////////////
2156 ////////////////////////////////////////////////////////////////////////////////////////////////////
2157 ////////////////////////////////////////////////////////////////////////////////////////////////////
2158 
2159 sal_uInt32 SdrObjCustomShape::GetHdlCount() const
2160 {
2161 	const sal_uInt32 nBasicHdlCount(SdrTextObj::GetHdlCount());
2162 	std::vector< SdrCustomShapeInteraction > aInteractionHandles( GetInteractionHandles( this ) );
2163 	return ( aInteractionHandles.size() + nBasicHdlCount );
2164 }
2165 
2166 SdrHdl* SdrObjCustomShape::GetHdl( sal_uInt32 nHdlNum ) const
2167 {
2168 	SdrHdl* pH = NULL;
2169 	const sal_uInt32 nBasicHdlCount(SdrTextObj::GetHdlCount());
2170 
2171 	if ( nHdlNum < nBasicHdlCount )
2172 		pH = SdrTextObj::GetHdl( nHdlNum );
2173 	else
2174 	{
2175 		std::vector< SdrCustomShapeInteraction > aInteractionHandles( GetInteractionHandles( this ) );
2176 		const sal_uInt32 nCustomShapeHdlNum(nHdlNum - nBasicHdlCount);
2177 
2178 		if ( nCustomShapeHdlNum < aInteractionHandles.size() )
2179 		{
2180 			if ( aInteractionHandles[ nCustomShapeHdlNum ].xInteraction.is() )
2181 			{
2182 				try
2183 				{
2184 					com::sun::star::awt::Point aPosition( aInteractionHandles[ nCustomShapeHdlNum ].xInteraction->getPosition() );
2185 					pH = new SdrHdl( Point( aPosition.X, aPosition.Y ), HDL_CUSTOMSHAPE1 );
2186 					pH->SetPointNum( nCustomShapeHdlNum );
2187 					pH->SetObj( (SdrObject*)this );
2188 				}
2189 				catch ( const uno::RuntimeException& )
2190 				{
2191 				}
2192 			}
2193 		}
2194 	}
2195 	return pH;
2196 }
2197 
2198 ////////////////////////////////////////////////////////////////////////////////////////////////////
2199 
2200 bool SdrObjCustomShape::hasSpecialDrag() const
2201 {
2202 	return true;
2203 }
2204 
2205 bool SdrObjCustomShape::beginSpecialDrag(SdrDragStat& rDrag) const
2206 {
2207 	const SdrHdl* pHdl = rDrag.GetHdl();
2208 
2209     if(pHdl && HDL_CUSTOMSHAPE1 == pHdl->GetKind())
2210 	{
2211 		rDrag.SetEndDragChangesAttributes(true);
2212 		rDrag.SetNoSnap(true);
2213 	}
2214 	else
2215 	{
2216 		const SdrHdl* pHdl2 = rDrag.GetHdl();
2217 		const SdrHdlKind eHdl((pHdl2 == NULL) ? HDL_MOVE : pHdl2->GetKind());
2218 
2219         switch( eHdl )
2220 		{
2221 			case HDL_UPLFT :
2222 			case HDL_UPPER :
2223 			case HDL_UPRGT :
2224 			case HDL_LEFT  :
2225 			case HDL_RIGHT :
2226 			case HDL_LWLFT :
2227 			case HDL_LOWER :
2228 			case HDL_LWRGT :
2229 			case HDL_MOVE  :
2230 			{
2231     			break;
2232 			}
2233 			default:
2234             {
2235 				return false;
2236             }
2237 		}
2238 	}
2239 
2240     return true;
2241 }
2242 
2243 void SdrObjCustomShape::DragResizeCustomShape( const Rectangle& rNewRect, SdrObjCustomShape* pObj ) const
2244 {
2245 	Rectangle	aOld( pObj->aRect );
2246 	sal_Bool	bOldMirroredX( pObj->IsMirroredX() );
2247 	sal_Bool	bOldMirroredY( pObj->IsMirroredY() );
2248 
2249 	Rectangle aNewRect( rNewRect );
2250 	aNewRect.Justify();
2251 
2252 	std::vector< SdrCustomShapeInteraction > aInteractionHandles( GetInteractionHandles( pObj ) );
2253 
2254 	GeoStat aGeoStat( pObj->GetGeoStat() );
2255 	if ( aNewRect.TopLeft()!= pObj->aRect.TopLeft() &&
2256 		( pObj->aGeo.nDrehWink || pObj->aGeo.nShearWink ) )
2257 	{
2258 		Point aNewPos( aNewRect.TopLeft() );
2259 		if ( pObj->aGeo.nShearWink ) ShearPoint( aNewPos, aOld.TopLeft(), aGeoStat.nTan );
2260 		if ( pObj->aGeo.nDrehWink )  RotatePoint(aNewPos, aOld.TopLeft(), aGeoStat.nSin, aGeoStat.nCos );
2261 		aNewRect.SetPos( aNewPos );
2262 	}
2263 	if ( aNewRect != pObj->aRect )
2264 	{
2265 		pObj->SetLogicRect( aNewRect );
2266 		pObj->InvalidateRenderGeometry();
2267 
2268 		if ( rNewRect.Left() > rNewRect.Right() )
2269 		{
2270 			Point aTop( ( pObj->GetSnapRect().Left() + pObj->GetSnapRect().Right() ) >> 1, pObj->GetSnapRect().Top() );
2271 			Point aBottom( aTop.X(), aTop.Y() + 1000 );
2272 			pObj->NbcMirror( aTop, aBottom );
2273 		}
2274 		if ( rNewRect.Top() > rNewRect.Bottom() )
2275 		{
2276 			Point aLeft( pObj->GetSnapRect().Left(), ( pObj->GetSnapRect().Top() + pObj->GetSnapRect().Bottom() ) >> 1 );
2277 			Point aRight( aLeft.X() + 1000, aLeft.Y() );
2278 			pObj->NbcMirror( aLeft, aRight );
2279 		}
2280 
2281 		std::vector< SdrCustomShapeInteraction >::iterator aIter( aInteractionHandles.begin() );
2282 		while ( aIter != aInteractionHandles.end() )
2283 		{
2284 			try
2285 			{
2286 				if ( aIter->nMode & CUSTOMSHAPE_HANDLE_RESIZE_FIXED )
2287 					aIter->xInteraction->setControllerPosition( aIter->aPosition );
2288 				if ( aIter->nMode & CUSTOMSHAPE_HANDLE_RESIZE_ABSOLUTE_X )
2289 				{
2290 					sal_Int32 nX;
2291 					if ( bOldMirroredX )
2292 					{
2293 						nX = ( aIter->aPosition.X - aOld.Right() );
2294 						if ( rNewRect.Left() > rNewRect.Right() )
2295 							nX = pObj->aRect.Left() - nX;
2296 						else
2297 							nX += pObj->aRect.Right();
2298 					}
2299 					else
2300 					{
2301 						nX = ( aIter->aPosition.X - aOld.Left() );
2302 						if ( rNewRect.Left() > rNewRect.Right() )
2303 							nX = pObj->aRect.Right() - nX;
2304 						else
2305 							nX += pObj->aRect.Left();
2306 					}
2307 					aIter->xInteraction->setControllerPosition( com::sun::star::awt::Point( nX, aIter->xInteraction->getPosition().Y ) );
2308 				}
2309 				if ( aIter->nMode & CUSTOMSHAPE_HANDLE_RESIZE_ABSOLUTE_Y )
2310 				{
2311 					sal_Int32 nY;
2312 					if ( bOldMirroredY )
2313 					{
2314 						nY = ( aIter->aPosition.Y - aOld.Bottom() );
2315 						if ( rNewRect.Top() > rNewRect.Bottom() )
2316 							nY = pObj->aRect.Top() - nY;
2317 						else
2318 							nY += pObj->aRect.Bottom();
2319 					}
2320 					else
2321 					{
2322 						nY = ( aIter->aPosition.Y - aOld.Top() );
2323 						if ( rNewRect.Top() > rNewRect.Bottom() )
2324 							nY = pObj->aRect.Bottom() - nY;
2325 						else
2326 							nY += pObj->aRect.Top();
2327 					}
2328 					aIter->xInteraction->setControllerPosition( com::sun::star::awt::Point( aIter->xInteraction->getPosition().X, nY ) );
2329 				}
2330 			}
2331 			catch ( const uno::RuntimeException& )
2332 			{
2333 			}
2334 			aIter++;
2335 		}
2336 	}
2337 }
2338 
2339 void SdrObjCustomShape::DragMoveCustomShapeHdl( const Point aDestination, const sal_uInt16 nCustomShapeHdlNum, SdrObjCustomShape* pObj ) const
2340 {
2341 	std::vector< SdrCustomShapeInteraction > aInteractionHandles( GetInteractionHandles( pObj ) );
2342 	if ( nCustomShapeHdlNum < aInteractionHandles.size() )
2343 	{
2344 		SdrCustomShapeInteraction aInteractionHandle( aInteractionHandles[ nCustomShapeHdlNum ] );
2345 		if ( aInteractionHandle.xInteraction.is() )
2346 		{
2347 			try
2348 			{
2349 				com::sun::star::awt::Point aPt( aDestination.X(), aDestination.Y() );
2350 				if ( aInteractionHandle.nMode & CUSTOMSHAPE_HANDLE_MOVE_SHAPE )
2351 				{
2352 					sal_Int32 nXDiff = aPt.X - aInteractionHandle.aPosition.X;
2353 					sal_Int32 nYDiff = aPt.Y - aInteractionHandle.aPosition.Y;
2354 
2355 					pObj->aRect.Move( nXDiff, nYDiff );
2356 					pObj->aOutRect.Move( nXDiff, nYDiff );
2357 					pObj->maSnapRect.Move( nXDiff, nYDiff );
2358 					pObj->SetRectsDirty(sal_True);
2359 					pObj->InvalidateRenderGeometry();
2360 
2361 					std::vector< SdrCustomShapeInteraction >::iterator aIter( aInteractionHandles.begin() );
2362 					while ( aIter != aInteractionHandles.end() )
2363 					{
2364 						if ( aIter->nMode & CUSTOMSHAPE_HANDLE_RESIZE_FIXED )
2365 						{
2366 							if ( aIter->xInteraction.is() )
2367 								aIter->xInteraction->setControllerPosition( aIter->aPosition );
2368 						}
2369 						aIter++;
2370 					}
2371 				}
2372 				aInteractionHandle.xInteraction->setControllerPosition( aPt );
2373 			}
2374 			catch ( const uno::RuntimeException& )
2375 			{
2376 			}
2377 		}
2378 	}
2379 }
2380 
2381 bool SdrObjCustomShape::applySpecialDrag(SdrDragStat& rDrag)
2382 {
2383 	const SdrHdl* pHdl = rDrag.GetHdl();
2384 	const SdrHdlKind eHdl((pHdl == NULL) ? HDL_MOVE : pHdl->GetKind());
2385 
2386     switch(eHdl)
2387 	{
2388 		case HDL_CUSTOMSHAPE1 :
2389 		{
2390 			rDrag.SetEndDragChangesGeoAndAttributes(true);
2391 		    DragMoveCustomShapeHdl( rDrag.GetNow(), (sal_uInt16)pHdl->GetPointNum(), this );
2392 		    SetRectsDirty();
2393 		    InvalidateRenderGeometry();
2394 		    SetChanged();
2395             break;
2396 		}
2397 
2398 		case HDL_UPLFT :
2399 		case HDL_UPPER :
2400 		case HDL_UPRGT :
2401 		case HDL_LEFT  :
2402 		case HDL_RIGHT :
2403 		case HDL_LWLFT :
2404 		case HDL_LOWER :
2405 		case HDL_LWRGT :
2406 		{
2407 			DragResizeCustomShape(ImpDragCalcRect(rDrag), this);
2408 			break;
2409 		}
2410 		case HDL_MOVE :
2411 		{
2412 			Move(Size(rDrag.GetDX(), rDrag.GetDY()));
2413 			break;
2414 		}
2415 		default: break;
2416 	}
2417 
2418     return true;
2419 }
2420 
2421 ////////////////////////////////////////////////////////////////////////////////////////////////////
2422 
2423 void SdrObjCustomShape::DragCreateObject( SdrDragStat& rStat )
2424 {
2425 	Rectangle aRect1;
2426 	rStat.TakeCreateRect( aRect1 );
2427 
2428 	std::vector< SdrCustomShapeInteraction > aInteractionHandles( GetInteractionHandles( this ) );
2429 
2430 	sal_uInt32 nDefaultObjectSizeWidth = 3000;		// default width from SDOptions ?
2431 	sal_uInt32 nDefaultObjectSizeHeight= 3000;
2432 
2433 	if ( ImpVerticalSwitch( *this ) )
2434 	{
2435 		SetMirroredX( aRect1.Left() > aRect1.Right() );
2436 
2437 		aRect1 = Rectangle( rStat.GetNow(), Size( nDefaultObjectSizeWidth, nDefaultObjectSizeHeight ) );
2438 		// subtracting the horizontal difference of the latest handle from shape position
2439 		if ( !aInteractionHandles.empty() )
2440 		{
2441 			sal_Int32 nHandlePos = aInteractionHandles[ aInteractionHandles.size() - 1 ].xInteraction->getPosition().X;
2442 			aRect1.Move( aRect.Left() - nHandlePos, 0 );
2443 		}
2444 	}
2445 	ImpJustifyRect( aRect1 );
2446 	rStat.SetActionRect( aRect1 );
2447 	aRect = aRect1;
2448 	SetRectsDirty();
2449 
2450 	std::vector< SdrCustomShapeInteraction >::iterator aIter( aInteractionHandles.begin() );
2451 	while ( aIter != aInteractionHandles.end() )
2452 	{
2453 		try
2454 		{
2455 			if ( aIter->nMode & CUSTOMSHAPE_HANDLE_CREATE_FIXED )
2456 				aIter->xInteraction->setControllerPosition( awt::Point( rStat.GetStart().X(), rStat.GetStart().Y() ) );
2457 		}
2458 		catch ( const uno::RuntimeException& )
2459 		{
2460 		}
2461 		aIter++;
2462 	}
2463 
2464 	SetBoundRectDirty();
2465 	bSnapRectDirty=sal_True;
2466 }
2467 
2468 FASTBOOL SdrObjCustomShape::BegCreate( SdrDragStat& rDrag )
2469 {
2470 	return SdrTextObj::BegCreate( rDrag );
2471 }
2472 
2473 FASTBOOL SdrObjCustomShape::MovCreate(SdrDragStat& rStat)
2474 {
2475 	SdrView* pView = rStat.GetView();		// #i37448#
2476 	if( pView && pView->IsSolidDragging() )
2477 	{
2478 		InvalidateRenderGeometry();
2479 	}
2480 	DragCreateObject( rStat );
2481 	SetRectsDirty();
2482 	return sal_True;
2483 }
2484 
2485 FASTBOOL SdrObjCustomShape::EndCreate( SdrDragStat& rStat, SdrCreateCmd eCmd )
2486 {
2487 	DragCreateObject( rStat );
2488 
2489 	if ( bTextFrame )
2490 	{
2491 		if ( IsAutoGrowHeight() )
2492 		{
2493 			// MinTextHeight
2494 			long nHgt=aRect.GetHeight()-1;
2495 			if (nHgt==1) nHgt=0;
2496 			NbcSetMinTextFrameHeight( nHgt );
2497 		}
2498 		if ( IsAutoGrowWidth() )
2499 		{
2500 			// MinTextWidth
2501 			long nWdt=aRect.GetWidth()-1;
2502 			if (nWdt==1) nWdt=0;
2503 			NbcSetMinTextFrameWidth( nWdt );
2504 		}
2505 		// Textrahmen neu berechnen
2506 		NbcAdjustTextFrameWidthAndHeight();
2507 	}
2508 	SetRectsDirty();
2509 	return ( eCmd == SDRCREATE_FORCEEND || rStat.GetPointAnz() >= 2 );
2510 }
2511 
2512 basegfx::B2DPolyPolygon SdrObjCustomShape::TakeCreatePoly(const SdrDragStat& /*rDrag*/) const
2513 {
2514 	return GetLineGeometry( this, sal_False );
2515 }
2516 
2517 ////////////////////////////////////////////////////////////////////////////////////////////////////
2518 ////////////////////////////////////////////////////////////////////////////////////////////////////
2519 ////////////////////////////////////////////////////////////////////////////////////////////////////
2520 
2521 // in context with the SdrObjCustomShape the SdrTextAutoGrowHeightItem == true -> Resize Shape to fit text,
2522 //									   the SdrTextAutoGrowWidthItem  == true -> Word wrap text in Shape
2523 FASTBOOL SdrObjCustomShape::IsAutoGrowHeight() const
2524 {
2525 	const SfxItemSet& rSet = GetMergedItemSet();
2526 	FASTBOOL bIsAutoGrowHeight = ((SdrTextAutoGrowHeightItem&)(rSet.Get(SDRATTR_TEXT_AUTOGROWHEIGHT))).GetValue();
2527 	if ( bIsAutoGrowHeight && IsVerticalWriting() )
2528 		bIsAutoGrowHeight = ((SdrTextWordWrapItem&)(rSet.Get(SDRATTR_TEXT_WORDWRAP))).GetValue() == sal_False;
2529 	return bIsAutoGrowHeight;
2530 }
2531 FASTBOOL SdrObjCustomShape::IsAutoGrowWidth() const
2532 {
2533 	const SfxItemSet& rSet = GetMergedItemSet();
2534 	FASTBOOL bIsAutoGrowWidth = ((SdrTextAutoGrowHeightItem&)(rSet.Get(SDRATTR_TEXT_AUTOGROWHEIGHT))).GetValue();
2535 	if ( bIsAutoGrowWidth && !IsVerticalWriting() )
2536 		bIsAutoGrowWidth = ((SdrTextWordWrapItem&)(rSet.Get(SDRATTR_TEXT_WORDWRAP))).GetValue() == sal_False;
2537 	return bIsAutoGrowWidth;
2538 }
2539 
2540 /* The following method is identical to the SdrTextObj::SetVerticalWriting method, the only difference
2541    is that the SdrAutoGrowWidthItem and SdrAutoGrowHeightItem are not exchanged if the vertical writing
2542    mode has been changed */
2543 
2544 void SdrObjCustomShape::SetVerticalWriting( sal_Bool bVertical )
2545 {
2546 	ForceOutlinerParaObject();
2547 
2548 	OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
2549 
2550 	DBG_ASSERT( pOutlinerParaObject, "SdrTextObj::SetVerticalWriting() without OutlinerParaObject!" );
2551 
2552 	if( pOutlinerParaObject )
2553 	{
2554 		if(pOutlinerParaObject->IsVertical() != (bool)bVertical)
2555 		{
2556 			// get item settings
2557 			const SfxItemSet& rSet = GetObjectItemSet();
2558 
2559 			// #103516# Also exchange hor/ver adjust items
2560 			SdrTextHorzAdjust eHorz = ((SdrTextHorzAdjustItem&)(rSet.Get(SDRATTR_TEXT_HORZADJUST))).GetValue();
2561 			SdrTextVertAdjust eVert = ((SdrTextVertAdjustItem&)(rSet.Get(SDRATTR_TEXT_VERTADJUST))).GetValue();
2562 
2563 			// rescue object size
2564 			Rectangle aObjectRect = GetSnapRect();
2565 
2566 			// prepare ItemSet to set exchanged width and height items
2567 			SfxItemSet aNewSet(*rSet.GetPool(),
2568 				SDRATTR_TEXT_AUTOGROWHEIGHT, SDRATTR_TEXT_AUTOGROWHEIGHT,
2569 				// #103516# Expanded item ranges to also support hor and ver adjust.
2570 				SDRATTR_TEXT_VERTADJUST, SDRATTR_TEXT_VERTADJUST,
2571 				SDRATTR_TEXT_AUTOGROWWIDTH, SDRATTR_TEXT_HORZADJUST,
2572 				0, 0);
2573 
2574 			aNewSet.Put(rSet);
2575 
2576 			// #103516# Exchange horz and vert adjusts
2577 			switch(eVert)
2578 			{
2579 				case SDRTEXTVERTADJUST_TOP: aNewSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT)); break;
2580 				case SDRTEXTVERTADJUST_CENTER: aNewSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_CENTER)); break;
2581 				case SDRTEXTVERTADJUST_BOTTOM: aNewSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_LEFT)); break;
2582 				case SDRTEXTVERTADJUST_BLOCK: aNewSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_BLOCK)); break;
2583 			}
2584 			switch(eHorz)
2585 			{
2586 				case SDRTEXTHORZADJUST_LEFT: aNewSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_BOTTOM)); break;
2587 				case SDRTEXTHORZADJUST_CENTER: aNewSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER)); break;
2588 				case SDRTEXTHORZADJUST_RIGHT: aNewSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_TOP)); break;
2589 				case SDRTEXTHORZADJUST_BLOCK: aNewSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_BLOCK)); break;
2590 			}
2591 
2592 			SetObjectItemSet( aNewSet );
2593 			pOutlinerParaObject = GetOutlinerParaObject();
2594 			if ( pOutlinerParaObject )
2595 				pOutlinerParaObject->SetVertical(bVertical);
2596 
2597 			// restore object size
2598 			SetSnapRect(aObjectRect);
2599 		}
2600 	}
2601 }
2602 FASTBOOL SdrObjCustomShape::AdjustTextFrameWidthAndHeight(Rectangle& rR, FASTBOOL bHgt, FASTBOOL bWdt) const
2603 {
2604  	if ( pModel && HasText() && !rR.IsEmpty() )
2605 	{
2606 		FASTBOOL bWdtGrow=bWdt && IsAutoGrowWidth();
2607 		FASTBOOL bHgtGrow=bHgt && IsAutoGrowHeight();
2608 		if ( bWdtGrow || bHgtGrow )
2609 		{
2610 			Rectangle aR0(rR);
2611 			long nHgt=0,nMinHgt=0,nMaxHgt=0;
2612 			long nWdt=0,nMinWdt=0,nMaxWdt=0;
2613 			Size aSiz(rR.GetSize()); aSiz.Width()--; aSiz.Height()--;
2614 			Size aMaxSiz(100000,100000);
2615 			Size aTmpSiz(pModel->GetMaxObjSize());
2616 			if (aTmpSiz.Width()!=0) aMaxSiz.Width()=aTmpSiz.Width();
2617 			if (aTmpSiz.Height()!=0) aMaxSiz.Height()=aTmpSiz.Height();
2618 			if (bWdtGrow)
2619 			{
2620 				nMinWdt=GetMinTextFrameWidth();
2621 				nMaxWdt=GetMaxTextFrameWidth();
2622 				if (nMaxWdt==0 || nMaxWdt>aMaxSiz.Width()) nMaxWdt=aMaxSiz.Width();
2623 				if (nMinWdt<=0) nMinWdt=1;
2624 				aSiz.Width()=nMaxWdt;
2625 			}
2626 			if (bHgtGrow)
2627 			{
2628 				nMinHgt=GetMinTextFrameHeight();
2629 				nMaxHgt=GetMaxTextFrameHeight();
2630 				if (nMaxHgt==0 || nMaxHgt>aMaxSiz.Height()) nMaxHgt=aMaxSiz.Height();
2631 				if (nMinHgt<=0) nMinHgt=1;
2632 				aSiz.Height()=nMaxHgt;
2633 			}
2634 			long nHDist=GetTextLeftDistance()+GetTextRightDistance();
2635 			long nVDist=GetTextUpperDistance()+GetTextLowerDistance();
2636 			aSiz.Width()-=nHDist;
2637 			aSiz.Height()-=nVDist;
2638 			if ( aSiz.Width() < 2 )
2639 				aSiz.Width() = 2;   // Mindestgroesse 2
2640 			if ( aSiz.Height() < 2 )
2641 				aSiz.Height() = 2; // Mindestgroesse 2
2642 
2643 			if(pEdtOutl)
2644 			{
2645 				pEdtOutl->SetMaxAutoPaperSize( aSiz );
2646 				if (bWdtGrow)
2647 				{
2648 					Size aSiz2(pEdtOutl->CalcTextSize());
2649 					nWdt=aSiz2.Width()+1; // lieber etwas Tolleranz
2650 					if (bHgtGrow) nHgt=aSiz2.Height()+1; // lieber etwas Tolleranz
2651 				} else
2652 				{
2653 					nHgt=pEdtOutl->GetTextHeight()+1; // lieber etwas Tolleranz
2654 				}
2655 			}
2656 			else
2657 			{
2658 				Outliner& rOutliner=ImpGetDrawOutliner();
2659 				rOutliner.SetPaperSize(aSiz);
2660 				rOutliner.SetUpdateMode(sal_True);
2661 				// !!! hier sollte ich wohl auch noch mal die Optimierung mit
2662 				// bPortionInfoChecked usw einbauen
2663 				OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
2664 				if( pOutlinerParaObject != NULL )
2665 				{
2666 					rOutliner.SetText(*pOutlinerParaObject);
2667 					rOutliner.SetFixedCellHeight(((const SdrTextFixedCellHeightItem&)GetMergedItem(SDRATTR_TEXT_USEFIXEDCELLHEIGHT)).GetValue());
2668 				}
2669 				if ( bWdtGrow )
2670 				{
2671 					Size aSiz2(rOutliner.CalcTextSize());
2672 					nWdt=aSiz2.Width()+1; // lieber etwas Tolleranz
2673 					if ( bHgtGrow )
2674 						nHgt=aSiz2.Height()+1; // lieber etwas Tolleranz
2675 				}
2676 				else
2677 					nHgt = rOutliner.GetTextHeight()+1; // lieber etwas Tolleranz
2678 				rOutliner.Clear();
2679 			}
2680 			if ( nWdt < nMinWdt )
2681 				nWdt = nMinWdt;
2682 			if ( nWdt > nMaxWdt )
2683 				nWdt = nMaxWdt;
2684 			nWdt += nHDist;
2685 			if ( nWdt < 1 )
2686 				nWdt = 1; // nHDist kann auch negativ sein
2687 			if ( nHgt < nMinHgt )
2688 				nHgt = nMinHgt;
2689 			if ( nHgt > nMaxHgt )
2690 				nHgt = nMaxHgt;
2691 			nHgt+=nVDist;
2692 			if ( nHgt < 1 )
2693 				nHgt = 1; // nVDist kann auch negativ sein
2694 			long nWdtGrow = nWdt-(rR.Right()-rR.Left());
2695 			long nHgtGrow = nHgt-(rR.Bottom()-rR.Top());
2696 			if ( nWdtGrow == 0 )
2697 				bWdtGrow = sal_False;
2698 			if ( nHgtGrow == 0 )
2699 				bHgtGrow=sal_False;
2700 			if ( bWdtGrow || bHgtGrow )
2701 			{
2702 				if ( bWdtGrow )
2703 				{
2704 					SdrTextHorzAdjust eHAdj=GetTextHorizontalAdjust();
2705 					if ( eHAdj == SDRTEXTHORZADJUST_LEFT )
2706 						rR.Right()+=nWdtGrow;
2707 					else if ( eHAdj == SDRTEXTHORZADJUST_RIGHT )
2708 						rR.Left()-=nWdtGrow;
2709 					else
2710 					{
2711 						long nWdtGrow2=nWdtGrow/2;
2712 						rR.Left()-=nWdtGrow2;
2713 						rR.Right()=rR.Left()+nWdt;
2714 					}
2715 				}
2716 				if ( bHgtGrow )
2717 				{
2718 					SdrTextVertAdjust eVAdj=GetTextVerticalAdjust();
2719 					if ( eVAdj == SDRTEXTVERTADJUST_TOP )
2720 						rR.Bottom()+=nHgtGrow;
2721 					else if ( eVAdj == SDRTEXTVERTADJUST_BOTTOM )
2722 						rR.Top()-=nHgtGrow;
2723 					else
2724 					{
2725 						long nHgtGrow2=nHgtGrow/2;
2726 						rR.Top()-=nHgtGrow2;
2727 						rR.Bottom()=rR.Top()+nHgt;
2728 					}
2729 				}
2730 				if ( aGeo.nDrehWink )
2731 				{
2732 					Point aD1(rR.TopLeft());
2733 					aD1-=aR0.TopLeft();
2734 					Point aD2(aD1);
2735 					RotatePoint(aD2,Point(),aGeo.nSin,aGeo.nCos);
2736 					aD2-=aD1;
2737 					rR.Move(aD2.X(),aD2.Y());
2738 				}
2739 				return sal_True;
2740 			}
2741 		}
2742 	}
2743 	return sal_False;
2744 }
2745 
2746 Rectangle SdrObjCustomShape::ImpCalculateTextFrame( const FASTBOOL bHgt, const FASTBOOL bWdt )
2747 {
2748 	Rectangle aReturnValue;
2749 
2750 	Rectangle aOldTextRect( aRect );		// <- initial text rectangle
2751 
2752 	Rectangle aNewTextRect( aRect );		// <- new text rectangle returned from the custom shape renderer,
2753 	GetTextBounds( aNewTextRect );			//    it depends to the current logical shape size
2754 
2755 	Rectangle aAdjustedTextRect( aNewTextRect );							// <- new text rectangle is being tested by AdjustTextFrameWidthAndHeight to ensure
2756 	if ( AdjustTextFrameWidthAndHeight( aAdjustedTextRect, bHgt, bWdt ) )	//    that the new text rectangle is matching the current text size from the outliner
2757 	{
2758 		if ( ( aAdjustedTextRect != aNewTextRect ) && ( aOldTextRect != aAdjustedTextRect ) )
2759 		{
2760 			aReturnValue = aRect;
2761 			double fXScale = (double)aOldTextRect.GetWidth() / (double)aNewTextRect.GetWidth();
2762 			double fYScale = (double)aOldTextRect.GetHeight() / (double)aNewTextRect.GetHeight();
2763 			double fRightDiff = (double)( aAdjustedTextRect.Right() - aNewTextRect.Right() ) * fXScale;
2764 			double fLeftDiff  = (double)( aAdjustedTextRect.Left()  - aNewTextRect.Left()  ) * fXScale;
2765 			double fTopDiff   = (double)( aAdjustedTextRect.Top()   - aNewTextRect.Top()   ) * fYScale;
2766 			double fBottomDiff= (double)( aAdjustedTextRect.Bottom()- aNewTextRect.Bottom()) * fYScale;
2767 			aReturnValue.Left() += (sal_Int32)fLeftDiff;
2768 			aReturnValue.Right() += (sal_Int32)fRightDiff;
2769 			aReturnValue.Top() += (sal_Int32)fTopDiff;
2770 			aReturnValue.Bottom() += (sal_Int32)fBottomDiff;
2771 		}
2772 	}
2773 	return aReturnValue;
2774 }
2775 
2776 FASTBOOL SdrObjCustomShape::NbcAdjustTextFrameWidthAndHeight(FASTBOOL bHgt, FASTBOOL bWdt)
2777 {
2778 	Rectangle aNewTextRect = ImpCalculateTextFrame( bHgt, bWdt );
2779 	sal_Bool bRet = !aNewTextRect.IsEmpty() && ( aNewTextRect != aRect );
2780 	if ( bRet )
2781 	{
2782 		// taking care of handles that should not been changed
2783 		std::vector< SdrCustomShapeInteraction > aInteractionHandles( GetInteractionHandles( this ) );
2784 
2785 		aRect = aNewTextRect;
2786 		SetRectsDirty();
2787 		SetChanged();
2788 
2789 		std::vector< SdrCustomShapeInteraction >::iterator aIter( aInteractionHandles.begin() );
2790 		while ( aIter != aInteractionHandles.end() )
2791 		{
2792 			try
2793 			{
2794 				if ( aIter->nMode & CUSTOMSHAPE_HANDLE_RESIZE_FIXED )
2795 					aIter->xInteraction->setControllerPosition( aIter->aPosition );
2796 			}
2797 			catch ( const uno::RuntimeException& )
2798 			{
2799 			}
2800 			aIter++;
2801 		}
2802 		InvalidateRenderGeometry();
2803 	}
2804 	return bRet;
2805 }
2806 FASTBOOL SdrObjCustomShape::AdjustTextFrameWidthAndHeight(FASTBOOL bHgt, FASTBOOL bWdt)
2807 {
2808 	Rectangle aNewTextRect = ImpCalculateTextFrame( bHgt, bWdt );
2809 	sal_Bool bRet = !aNewTextRect.IsEmpty() && ( aNewTextRect != aRect );
2810 	if ( bRet )
2811 	{
2812 		Rectangle aBoundRect0;
2813 		if ( pUserCall )
2814 			aBoundRect0 = GetCurrentBoundRect();
2815 
2816 		// taking care of handles that should not been changed
2817 		std::vector< SdrCustomShapeInteraction > aInteractionHandles( GetInteractionHandles( this ) );
2818 
2819 //		SendRepaintBroadcast();
2820 		aRect = aNewTextRect;
2821 		SetRectsDirty();
2822 
2823 		std::vector< SdrCustomShapeInteraction >::iterator aIter( aInteractionHandles.begin() );
2824 		while ( aIter != aInteractionHandles.end() )
2825 		{
2826 			try
2827 			{
2828 				if ( aIter->nMode & CUSTOMSHAPE_HANDLE_RESIZE_FIXED )
2829 					aIter->xInteraction->setControllerPosition( aIter->aPosition );
2830 			}
2831 			catch ( const uno::RuntimeException& )
2832 			{
2833 			}
2834 			aIter++;
2835 		}
2836 
2837 		InvalidateRenderGeometry();
2838 		SetChanged();
2839 //		SendRepaintBroadcast();
2840 		BroadcastObjectChange();
2841 		SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
2842 	}
2843 	return bRet;
2844 }
2845 sal_Bool SdrObjCustomShape::BegTextEdit( SdrOutliner& rOutl )
2846 {
2847 	return SdrTextObj::BegTextEdit( rOutl );
2848 }
2849 void SdrObjCustomShape::TakeTextEditArea(Size* pPaperMin, Size* pPaperMax, Rectangle* pViewInit, Rectangle* pViewMin) const
2850 {
2851 	Size aPaperMin,aPaperMax;
2852 	Rectangle aViewInit;
2853 	TakeTextAnchorRect( aViewInit );
2854 	if ( aGeo.nDrehWink )
2855 	{
2856 		Point aCenter(aViewInit.Center());
2857 		aCenter-=aViewInit.TopLeft();
2858 		Point aCenter0(aCenter);
2859 		RotatePoint(aCenter,Point(),aGeo.nSin,aGeo.nCos);
2860 		aCenter-=aCenter0;
2861 		aViewInit.Move(aCenter.X(),aCenter.Y());
2862 	}
2863 	Size aAnkSiz(aViewInit.GetSize());
2864 	aAnkSiz.Width()--; aAnkSiz.Height()--; // weil GetSize() ein draufaddiert
2865 	Size aMaxSiz(1000000,1000000);
2866 	if (pModel!=NULL) {
2867 		Size aTmpSiz(pModel->GetMaxObjSize());
2868 		if (aTmpSiz.Width()!=0) aMaxSiz.Width()=aTmpSiz.Width();
2869 		if (aTmpSiz.Height()!=0) aMaxSiz.Height()=aTmpSiz.Height();
2870 	}
2871 	SdrTextHorzAdjust eHAdj(GetTextHorizontalAdjust());
2872 	SdrTextVertAdjust eVAdj(GetTextVerticalAdjust());
2873 
2874 	long nMinWdt = GetMinTextFrameWidth();
2875 	long nMinHgt = GetMinTextFrameHeight();
2876 	long nMaxWdt = GetMaxTextFrameWidth();
2877 	long nMaxHgt = GetMaxTextFrameHeight();
2878 	if (nMinWdt<1) nMinWdt=1;
2879 	if (nMinHgt<1) nMinHgt=1;
2880 	if ( nMaxWdt == 0 || nMaxWdt > aMaxSiz.Width() )
2881 		nMaxWdt = aMaxSiz.Width();
2882 	if ( nMaxHgt == 0 || nMaxHgt > aMaxSiz.Height() )
2883 		nMaxHgt=aMaxSiz.Height();
2884 
2885 	if (((SdrTextWordWrapItem&)(GetMergedItem(SDRATTR_TEXT_WORDWRAP))).GetValue())
2886 	{
2887 		if ( IsVerticalWriting() )
2888 		{
2889 			nMaxHgt = aAnkSiz.Height();
2890 			nMinHgt = nMaxHgt;
2891 		}
2892 		else
2893 		{
2894 			nMaxWdt = aAnkSiz.Width();
2895 			nMinWdt = nMaxWdt;
2896 		}
2897 	}
2898 	aPaperMax.Width()=nMaxWdt;
2899 	aPaperMax.Height()=nMaxHgt;
2900 
2901 	aPaperMin.Width()=nMinWdt;
2902 	aPaperMin.Height()=nMinHgt;
2903 
2904 	if ( pViewMin )
2905 	{
2906 		*pViewMin = aViewInit;
2907 
2908 		long nXFree = aAnkSiz.Width() - aPaperMin.Width();
2909 		if ( eHAdj == SDRTEXTHORZADJUST_LEFT )
2910 			pViewMin->Right() -= nXFree;
2911 		else if ( eHAdj == SDRTEXTHORZADJUST_RIGHT )
2912 			pViewMin->Left() += nXFree;
2913 		else { pViewMin->Left() += nXFree / 2; pViewMin->Right() = pViewMin->Left() + aPaperMin.Width(); }
2914 
2915 		long nYFree = aAnkSiz.Height() - aPaperMin.Height();
2916 		if ( eVAdj == SDRTEXTVERTADJUST_TOP )
2917 			pViewMin->Bottom() -= nYFree;
2918 		else if ( eVAdj == SDRTEXTVERTADJUST_BOTTOM )
2919 			pViewMin->Top() += nYFree;
2920 		else { pViewMin->Top() += nYFree / 2; pViewMin->Bottom() = pViewMin->Top() + aPaperMin.Height(); }
2921 	}
2922 
2923 	if( IsVerticalWriting() )
2924 		aPaperMin.Width() = 0;
2925 	else
2926 		aPaperMin.Height() = 0; // #33102#
2927 
2928 	if( eHAdj != SDRTEXTHORZADJUST_BLOCK )
2929 		aPaperMin.Width()=0;
2930 
2931 	// #103516# For complete ver adjust support, set paper min height to 0, here.
2932 	if(SDRTEXTVERTADJUST_BLOCK != eVAdj )
2933 		aPaperMin.Height() = 0;
2934 
2935 	if (pPaperMin!=NULL) *pPaperMin=aPaperMin;
2936 	if (pPaperMax!=NULL) *pPaperMax=aPaperMax;
2937 	if (pViewInit!=NULL) *pViewInit=aViewInit;
2938 }
2939 void SdrObjCustomShape::EndTextEdit( SdrOutliner& rOutl )
2940 {
2941 	SdrTextObj::EndTextEdit( rOutl );
2942 	InvalidateRenderGeometry();
2943 }
2944 void SdrObjCustomShape::TakeTextAnchorRect( Rectangle& rAnchorRect ) const
2945 {
2946 	if ( GetTextBounds( rAnchorRect ) )
2947 	{
2948 		Point aRotateRef( maSnapRect.Center() );
2949 		rAnchorRect.Left()   += GetTextLeftDistance();
2950 		rAnchorRect.Top()    += GetTextUpperDistance();
2951 		rAnchorRect.Right()  -= GetTextRightDistance();
2952 		rAnchorRect.Bottom() -= GetTextLowerDistance();
2953 		ImpJustifyRect( rAnchorRect );
2954 
2955 		if ( rAnchorRect.GetWidth() < 2 )
2956 			rAnchorRect.Right() = rAnchorRect.Left() + 1;	// minimal width is 2
2957 		if ( rAnchorRect.GetHeight() < 2 )
2958 			rAnchorRect.Bottom() = rAnchorRect.Top() + 1;	// minimal height is 2
2959 		if ( aGeo.nDrehWink )
2960 		{
2961 			Point aP( rAnchorRect.TopLeft() );
2962 			RotatePoint( aP, aRotateRef, aGeo.nSin, aGeo. nCos );
2963 			rAnchorRect.SetPos( aP );
2964 		}
2965 	}
2966 	else
2967 		SdrTextObj::TakeTextAnchorRect( rAnchorRect );
2968 }
2969 void SdrObjCustomShape::TakeTextRect( SdrOutliner& rOutliner, Rectangle& rTextRect, FASTBOOL bNoEditText,
2970 	                           Rectangle* pAnchorRect, sal_Bool /*bLineWidth*/) const
2971 {
2972 	Rectangle aAnkRect; // Rect innerhalb dem geankert wird
2973 	TakeTextAnchorRect(aAnkRect);
2974 	SdrTextVertAdjust eVAdj=GetTextVerticalAdjust();
2975 	SdrTextHorzAdjust eHAdj=GetTextHorizontalAdjust();
2976 	sal_uIntPtr nStat0=rOutliner.GetControlWord();
2977 	Size aNullSize;
2978 
2979 	rOutliner.SetControlWord(nStat0|EE_CNTRL_AUTOPAGESIZE);
2980 	rOutliner.SetMinAutoPaperSize(aNullSize);
2981 	sal_Int32 nMaxAutoPaperWidth = 1000000;
2982 	sal_Int32 nMaxAutoPaperHeight= 1000000;
2983 
2984 	long nAnkWdt=aAnkRect.GetWidth();
2985 	long nAnkHgt=aAnkRect.GetHeight();
2986 
2987 	if (((SdrTextWordWrapItem&)(GetMergedItem(SDRATTR_TEXT_WORDWRAP))).GetValue())
2988 	{
2989 		if ( IsVerticalWriting() )
2990 			nMaxAutoPaperHeight = nAnkHgt;
2991 		else
2992 			nMaxAutoPaperWidth = nAnkWdt;
2993 	}
2994 	if(SDRTEXTHORZADJUST_BLOCK == eHAdj && !IsVerticalWriting())
2995 	{
2996 		rOutliner.SetMinAutoPaperSize(Size(nAnkWdt, 0));
2997 	}
2998 
2999 	if(SDRTEXTVERTADJUST_BLOCK == eVAdj && IsVerticalWriting())
3000 	{
3001 		rOutliner.SetMinAutoPaperSize(Size(0, nAnkHgt));
3002 	}
3003 	rOutliner.SetMaxAutoPaperSize( Size( nMaxAutoPaperWidth, nMaxAutoPaperHeight ) );
3004 	rOutliner.SetPaperSize( aNullSize );
3005 
3006 	// Text in den Outliner stecken - ggf. den aus dem EditOutliner
3007 	OutlinerParaObject* pPara= GetOutlinerParaObject();
3008 	if (pEdtOutl && !bNoEditText)
3009 		pPara=pEdtOutl->CreateParaObject();
3010 
3011 	if (pPara)
3012 	{
3013 		sal_Bool bHitTest = sal_False;
3014 		if( pModel )
3015 			bHitTest = &pModel->GetHitTestOutliner() == &rOutliner;
3016 
3017 		const SdrTextObj* pTestObj = rOutliner.GetTextObj();
3018 		if( !pTestObj || !bHitTest || pTestObj != this ||
3019 		    pTestObj->GetOutlinerParaObject() != GetOutlinerParaObject() )
3020 		{
3021 			if( bHitTest )
3022 				rOutliner.SetTextObj( this );
3023 
3024 			rOutliner.SetUpdateMode(sal_True);
3025 			rOutliner.SetText(*pPara);
3026 		}
3027 	}
3028 	else
3029 	{
3030 		rOutliner.SetTextObj( NULL );
3031 	}
3032 	if (pEdtOutl && !bNoEditText && pPara)
3033 		delete pPara;
3034 
3035 	rOutliner.SetUpdateMode(sal_True);
3036 	rOutliner.SetControlWord(nStat0);
3037 
3038 	SdrText* pText = getActiveText();
3039 	if( pText )
3040 		pText->CheckPortionInfo( rOutliner );
3041 
3042 	Point aTextPos(aAnkRect.TopLeft());
3043 	Size aTextSiz(rOutliner.GetPaperSize()); // GetPaperSize() hat etwas Toleranz drauf, oder?
3044 
3045 	// #106653#
3046 	// For draw objects containing text correct hor/ver alignment if text is bigger
3047 	// than the object itself. Without that correction, the text would always be
3048 		// formatted to the left edge (or top edge when vertical) of the draw object.
3049 
3050 	if( !IsTextFrame() )
3051 	{
3052 		if(aAnkRect.GetWidth() < aTextSiz.Width() && !IsVerticalWriting())
3053 		{
3054 			// #110129#
3055 			// Horizontal case here. Correct only if eHAdj == SDRTEXTHORZADJUST_BLOCK,
3056 			// else the alignment is wanted.
3057 			if(SDRTEXTHORZADJUST_BLOCK == eHAdj)
3058 			{
3059 				eHAdj = SDRTEXTHORZADJUST_CENTER;
3060 			}
3061 		}
3062 
3063 		if(aAnkRect.GetHeight() < aTextSiz.Height() && IsVerticalWriting())
3064 		{
3065 			// #110129#
3066 			// Vertical case here. Correct only if eHAdj == SDRTEXTVERTADJUST_BLOCK,
3067 			// else the alignment is wanted.
3068 			if(SDRTEXTVERTADJUST_BLOCK == eVAdj)
3069 			{
3070 				eVAdj = SDRTEXTVERTADJUST_CENTER;
3071 			}
3072 		}
3073 	}
3074 
3075 	if (eHAdj==SDRTEXTHORZADJUST_CENTER || eHAdj==SDRTEXTHORZADJUST_RIGHT)
3076 	{
3077 		long nFreeWdt=aAnkRect.GetWidth()-aTextSiz.Width();
3078 		if (eHAdj==SDRTEXTHORZADJUST_CENTER)
3079 			aTextPos.X()+=nFreeWdt/2;
3080 		if (eHAdj==SDRTEXTHORZADJUST_RIGHT)
3081 			aTextPos.X()+=nFreeWdt;
3082 	}
3083 	if (eVAdj==SDRTEXTVERTADJUST_CENTER || eVAdj==SDRTEXTVERTADJUST_BOTTOM)
3084 	{
3085 		long nFreeHgt=aAnkRect.GetHeight()-aTextSiz.Height();
3086 		if (eVAdj==SDRTEXTVERTADJUST_CENTER)
3087 			aTextPos.Y()+=nFreeHgt/2;
3088 		if (eVAdj==SDRTEXTVERTADJUST_BOTTOM)
3089 			aTextPos.Y()+=nFreeHgt;
3090 	}
3091 	if (aGeo.nDrehWink!=0)
3092 		RotatePoint(aTextPos,aAnkRect.TopLeft(),aGeo.nSin,aGeo.nCos);
3093 
3094 	if (pAnchorRect)
3095 		*pAnchorRect=aAnkRect;
3096 
3097 	// rTextRect ist bei ContourFrame in einigen Faellen nicht korrekt
3098 	rTextRect=Rectangle(aTextPos,aTextSiz);
3099 }
3100 
3101 void SdrObjCustomShape::NbcSetOutlinerParaObject(OutlinerParaObject* pTextObject)
3102 {
3103 	SdrTextObj::NbcSetOutlinerParaObject( pTextObject );
3104 	SetBoundRectDirty();
3105 	SetRectsDirty(sal_True);
3106 	InvalidateRenderGeometry();
3107 }
3108 
3109 void SdrObjCustomShape::operator=(const SdrObject& rObj)
3110 {
3111 	SdrTextObj::operator=( rObj );
3112 	aName =((SdrObjCustomShape&)rObj).aName;
3113 	fObjectRotation = ((SdrObjCustomShape&)rObj).fObjectRotation;
3114 	InvalidateRenderGeometry();
3115 }
3116 
3117 
3118 void SdrObjCustomShape::TakeObjNameSingul(XubString& rName) const
3119 {
3120 	rName = ImpGetResStr(STR_ObjNameSingulCUSTOMSHAPE);
3121 	String aNm( GetName() );
3122 	if( aNm.Len() )
3123 	{
3124 		rName += sal_Unicode(' ');
3125 		rName += sal_Unicode('\'');
3126 		rName += aNm;
3127 		rName += sal_Unicode('\'');
3128 	}
3129 }
3130 
3131 void SdrObjCustomShape::TakeObjNamePlural(XubString& rName) const
3132 {
3133 	rName=ImpGetResStr(STR_ObjNamePluralCUSTOMSHAPE);
3134 }
3135 
3136 basegfx::B2DPolyPolygon SdrObjCustomShape::TakeXorPoly() const
3137 {
3138 	return GetLineGeometry( (SdrObjCustomShape*)this, sal_False );
3139 }
3140 
3141 basegfx::B2DPolyPolygon SdrObjCustomShape::TakeContour() const
3142 {
3143 	const SdrObject* pSdrObject = GetSdrObjectFromCustomShape();
3144 	if ( pSdrObject )
3145 		return pSdrObject->TakeContour();
3146 	return basegfx::B2DPolyPolygon();
3147 }
3148 
3149 SdrObject* SdrObjCustomShape::DoConvertToPolyObj(sal_Bool bBezier, bool bAddText) const
3150 {
3151 	// #i37011#
3152 	SdrObject* pRetval = 0L;
3153 	SdrObject* pRenderedCustomShape = 0L;
3154 
3155 	if ( !mXRenderedCustomShape.is() )
3156 	{
3157 		// force CustomShape
3158 		((SdrObjCustomShape*)this)->GetSdrObjectFromCustomShape();
3159 	}
3160 
3161 	if ( mXRenderedCustomShape.is() )
3162 	{
3163 		pRenderedCustomShape = GetSdrObjectFromXShape( mXRenderedCustomShape );
3164 	}
3165 
3166 	if ( pRenderedCustomShape )
3167 	{
3168 		SdrObject* pCandidate = pRenderedCustomShape->Clone();
3169 		DBG_ASSERT(pCandidate, "SdrObjCustomShape::DoConvertToPolyObj: Could not clone SdrObject (!)");
3170 		pCandidate->SetModel(GetModel());
3171 		pRetval = pCandidate->DoConvertToPolyObj(bBezier, bAddText);
3172 		SdrObject::Free( pCandidate );
3173 
3174 		if(pRetval)
3175 		{
3176 			const sal_Bool bShadow(((SdrShadowItem&)GetMergedItem(SDRATTR_SHADOW)).GetValue());
3177 			if(bShadow)
3178 			{
3179 				pRetval->SetMergedItem(SdrShadowItem(sal_True));
3180 			}
3181 		}
3182 
3183 		if(bAddText && HasText() && !IsTextPath())
3184 		{
3185 			pRetval = ImpConvertAddText(pRetval, bBezier);
3186 		}
3187 	}
3188 
3189 	return pRetval;
3190 }
3191 
3192 void SdrObjCustomShape::NbcSetStyleSheet( SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr )
3193 {
3194 	// #i40944#
3195 	InvalidateRenderGeometry();
3196 	SdrObject::NbcSetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
3197 }
3198 
3199 void SdrObjCustomShape::SetPage( SdrPage* pNewPage )
3200 {
3201 	SdrTextObj::SetPage( pNewPage );
3202 
3203 	if( pNewPage )
3204 	{
3205 		// invalidating rectangles by SetRectsDirty is not sufficient,
3206 		// AdjustTextFrameWidthAndHeight() also has to be made, both
3207 		// actions are done by NbcSetSnapRect
3208 		Rectangle aTmp( aRect );	//creating temporary rectangle #i61108#
3209 		NbcSetSnapRect( aTmp );
3210 	}
3211 }
3212 
3213 SdrObjGeoData* SdrObjCustomShape::NewGeoData() const
3214 {
3215 	return new SdrAShapeObjGeoData;
3216 }
3217 
3218 void SdrObjCustomShape::SaveGeoData(SdrObjGeoData& rGeo) const
3219 {
3220 	SdrTextObj::SaveGeoData( rGeo );
3221 	SdrAShapeObjGeoData& rAGeo=(SdrAShapeObjGeoData&)rGeo;
3222 	rAGeo.fObjectRotation = fObjectRotation;
3223 	rAGeo.bMirroredX = IsMirroredX();
3224 	rAGeo.bMirroredY = IsMirroredY();
3225 
3226 	const rtl::OUString	sAdjustmentValues( RTL_CONSTASCII_USTRINGPARAM ( "AdjustmentValues" ) );
3227 	Any* pAny( ( (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) ).GetPropertyValueByName( sAdjustmentValues ) );
3228 	if ( pAny )
3229 		*pAny >>= rAGeo.aAdjustmentSeq;
3230 }
3231 
3232 void SdrObjCustomShape::RestGeoData(const SdrObjGeoData& rGeo)
3233 {
3234 	SdrTextObj::RestGeoData( rGeo );
3235 	SdrAShapeObjGeoData& rAGeo=(SdrAShapeObjGeoData&)rGeo;
3236 	fObjectRotation = rAGeo.fObjectRotation;
3237 	SetMirroredX( rAGeo.bMirroredX );
3238 	SetMirroredY( rAGeo.bMirroredY );
3239 
3240 	SdrCustomShapeGeometryItem rGeometryItem = (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY );
3241 	const rtl::OUString	sAdjustmentValues( RTL_CONSTASCII_USTRINGPARAM ( "AdjustmentValues" ) );
3242 	PropertyValue aPropVal;
3243 	aPropVal.Name = sAdjustmentValues;
3244 	aPropVal.Value <<= rAGeo.aAdjustmentSeq;
3245 	rGeometryItem.SetPropertyValue( aPropVal );
3246 	SetMergedItem( rGeometryItem );
3247 
3248 	InvalidateRenderGeometry();
3249 }
3250 
3251 void SdrObjCustomShape::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, const basegfx::B2DPolyPolygon& /*rPolyPolygon*/)
3252 {
3253 	// break up matrix
3254 	basegfx::B2DTuple aScale;
3255 	basegfx::B2DTuple aTranslate;
3256 	double fRotate, fShearX;
3257 	rMatrix.decompose(aScale, aTranslate, fRotate, fShearX);
3258 
3259 	// #i75086# Old DrawingLayer (GeoStat and geometry) does not support holding negative scalings
3260 	// in X and Y which equal a 180 degree rotation. Recognize it and react accordingly
3261     const bool bMirrorX(basegfx::fTools::less(aScale.getX(), 0.0));
3262     const bool bMirrorY(basegfx::fTools::less(aScale.getY(), 0.0));
3263 
3264 	if(bMirrorX && bMirrorY)
3265 	{
3266 		aScale.setX(fabs(aScale.getX()));
3267 		aScale.setY(fabs(aScale.getY()));
3268 		fRotate = fmod(fRotate + F_PI, F_2PI);
3269 	}
3270     else if(bMirrorX || bMirrorY)
3271     {
3272         basegfx::B2DHomMatrix aNew;
3273 
3274         // create pre-multiplied matrix without mirroring
3275         aNew.translate(-0.5, -0.5);
3276         aNew.scale(bMirrorX ? -1.0 : 1.0, bMirrorY ? -1.0 : 1.0);
3277         aNew.translate(0.5, 0.5);
3278         aNew = rMatrix * aNew;
3279 
3280         // decompose to get corrected, mirror-free values
3281         aNew.decompose(aScale, aTranslate, fRotate, fShearX);
3282 
3283         // apply mirroring to CustomShapeGeometry
3284         if((bool)IsMirroredX() != bMirrorX)
3285         {
3286             SetMirroredX(bMirrorX);
3287         }
3288 
3289         if((bool)IsMirroredY() != bMirrorY)
3290         {
3291             SetMirroredY(bMirrorY);
3292         }
3293     }
3294 
3295 	// reset object shear and rotations
3296 	aGeo.nDrehWink = 0;
3297 	aGeo.RecalcSinCos();
3298 	aGeo.nShearWink = 0;
3299 	aGeo.RecalcTan();
3300 
3301 	// force metric to pool metric
3302 	SfxMapUnit eMapUnit = GetObjectItemSet().GetPool()->GetMetric(0);
3303 	if(eMapUnit != SFX_MAPUNIT_100TH_MM)
3304 	{
3305 		switch(eMapUnit)
3306 		{
3307 			case SFX_MAPUNIT_TWIP :
3308 			{
3309 				// position
3310 				aTranslate.setX(ImplMMToTwips(aTranslate.getX()));
3311 				aTranslate.setY(ImplMMToTwips(aTranslate.getY()));
3312 
3313 				// size
3314 				aScale.setX(ImplMMToTwips(aScale.getX()));
3315 				aScale.setY(ImplMMToTwips(aScale.getY()));
3316 
3317 				break;
3318 			}
3319 			default:
3320 			{
3321 				DBG_ERROR("TRSetBaseGeometry: Missing unit translation to PoolMetric!");
3322 			}
3323 		}
3324 	}
3325 
3326 	// if anchor is used, make position relative to it
3327 	if( pModel && pModel->IsWriter() )
3328 	{
3329 		if(GetAnchorPos().X() || GetAnchorPos().Y())
3330 		{
3331 			aTranslate += basegfx::B2DTuple(GetAnchorPos().X(), GetAnchorPos().Y());
3332 		}
3333 	}
3334 
3335 	// build and set BaseRect (use scale)
3336 	Point aPoint = Point();
3337 	Size aSize(FRound(aScale.getX()), FRound(aScale.getY()));
3338 	Rectangle aBaseRect(aPoint, aSize);
3339 	SetSnapRect(aBaseRect);
3340 
3341 	// shear?
3342 	if(!basegfx::fTools::equalZero(fShearX))
3343 	{
3344 		GeoStat aGeoStat;
3345 		aGeoStat.nShearWink = FRound((atan(fShearX) / F_PI180) * 100.0);
3346 		aGeoStat.RecalcTan();
3347 		Shear(Point(), aGeoStat.nShearWink, aGeoStat.nTan, sal_False);
3348 	}
3349 
3350 	// rotation?
3351     if(!basegfx::fTools::equalZero(fRotate))
3352 	{
3353 		GeoStat aGeoStat;
3354 
3355         // #i78696#
3356         // fRotate is mathematically correct, but aGeoStat.nDrehWink is
3357         // mirrored -> mirror value here
3358 		aGeoStat.nDrehWink = NormAngle360(FRound(-fRotate / F_PI18000));
3359 		aGeoStat.RecalcSinCos();
3360 		Rotate(Point(), aGeoStat.nDrehWink, aGeoStat.nSin, aGeoStat.nCos);
3361 	}
3362 
3363 	// translate?
3364     if(!aTranslate.equalZero())
3365 	{
3366 		Move(Size(FRound(aTranslate.getX()), FRound(aTranslate.getY())));
3367 	}
3368 }
3369 
3370 // taking fObjectRotation instead of aGeo.nWink
3371 sal_Bool SdrObjCustomShape::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B2DPolyPolygon& /*rPolyPolygon*/) const
3372 {
3373 	// get turn and shear
3374 //	double fRotate = (aGeo.nDrehWink / 100.0) * F_PI180;
3375 	double fRotate = fObjectRotation * F_PI180;
3376 	double fShearX = (aGeo.nShearWink / 100.0) * F_PI180;
3377 
3378 	// get aRect, this is the unrotated snaprect
3379 	Rectangle aRectangle(aRect);
3380 
3381 	sal_Bool bMirroredX = IsMirroredX();
3382 	sal_Bool bMirroredY = IsMirroredY();
3383 	if ( bMirroredX || bMirroredY )
3384 	{	// we have to retrieve the unmirrored rect
3385 
3386 		GeoStat aNewGeo( aGeo );
3387 
3388 		if ( bMirroredX )
3389 		{
3390 			Polygon aPol( Rect2Poly( aRect, aNewGeo ) );
3391 			Rectangle aBoundRect( aPol.GetBoundRect() );
3392 
3393 			Point aRef1( ( aBoundRect.Left() + aBoundRect.Right() ) >> 1, aBoundRect.Top() );
3394 			Point aRef2( aRef1.X(), aRef1.Y() + 1000 );
3395 			sal_uInt16 i;
3396 			sal_uInt16 nPntAnz=aPol.GetSize();
3397 			for (i=0; i<nPntAnz; i++)
3398 			{
3399 				MirrorPoint(aPol[i],aRef1,aRef2);
3400 			}
3401 			// Polygon wenden und etwas schieben
3402 			Polygon aPol0(aPol);
3403 			aPol[0]=aPol0[1];
3404 			aPol[1]=aPol0[0];
3405 			aPol[2]=aPol0[3];
3406 			aPol[3]=aPol0[2];
3407 			aPol[4]=aPol0[1];
3408 			Poly2Rect(aPol,aRectangle,aNewGeo);
3409 		}
3410 		if ( bMirroredY )
3411 		{
3412 			Polygon aPol( Rect2Poly( aRectangle, aNewGeo ) );
3413 			Rectangle aBoundRect( aPol.GetBoundRect() );
3414 
3415 			Point aRef1( aBoundRect.Left(), ( aBoundRect.Top() + aBoundRect.Bottom() ) >> 1 );
3416 			Point aRef2( aRef1.X() + 1000, aRef1.Y() );
3417 			sal_uInt16 i;
3418 			sal_uInt16 nPntAnz=aPol.GetSize();
3419 			for (i=0; i<nPntAnz; i++)
3420 			{
3421 				MirrorPoint(aPol[i],aRef1,aRef2);
3422 			}
3423 			// Polygon wenden und etwas schieben
3424 			Polygon aPol0(aPol);
3425 			aPol[0]=aPol0[3]; // This was WRONG for vertical (!)
3426 			aPol[1]=aPol0[2];
3427 			aPol[2]=aPol0[1];
3428 			aPol[3]=aPol0[0];
3429 			aPol[4]=aPol0[3];
3430 			Poly2Rect(aPol,aRectangle,aNewGeo);
3431 		}
3432 	}
3433 
3434 	// fill other values
3435 	basegfx::B2DTuple aScale(aRectangle.GetWidth(), aRectangle.GetHeight());
3436 	basegfx::B2DTuple aTranslate(aRectangle.Left(), aRectangle.Top());
3437 
3438 	// position maybe relative to anchorpos, convert
3439 	if( pModel && pModel->IsWriter() )
3440 	{
3441 		if(GetAnchorPos().X() || GetAnchorPos().Y())
3442 		{
3443 			aTranslate -= basegfx::B2DTuple(GetAnchorPos().X(), GetAnchorPos().Y());
3444 		}
3445 	}
3446 
3447 	// force MapUnit to 100th mm
3448 	SfxMapUnit eMapUnit = GetObjectItemSet().GetPool()->GetMetric(0);
3449 	if(eMapUnit != SFX_MAPUNIT_100TH_MM)
3450 	{
3451 		switch(eMapUnit)
3452 		{
3453 			case SFX_MAPUNIT_TWIP :
3454 			{
3455 				// postion
3456 				aTranslate.setX(ImplTwipsToMM(aTranslate.getX()));
3457 				aTranslate.setY(ImplTwipsToMM(aTranslate.getY()));
3458 
3459 				// size
3460 				aScale.setX(ImplTwipsToMM(aScale.getX()));
3461 				aScale.setY(ImplTwipsToMM(aScale.getY()));
3462 
3463 				break;
3464 			}
3465 			default:
3466 			{
3467 				DBG_ERROR("TRGetBaseGeometry: Missing unit translation to 100th mm!");
3468 			}
3469 		}
3470 	}
3471 
3472 	// build matrix
3473 	rMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
3474 		aScale,
3475 		basegfx::fTools::equalZero(fShearX) ? 0.0 : tan(fShearX),
3476 		basegfx::fTools::equalZero(fRotate) ? 0.0 : -fRotate,
3477 		aTranslate);
3478 
3479 	return sal_False;
3480 }
3481 
3482 sdr::contact::ViewContact* SdrObjCustomShape::CreateObjectSpecificViewContact()
3483 {
3484 	return new sdr::contact::ViewContactOfSdrObjCustomShape(*this);
3485 }
3486 
3487 // #i33136#
3488 bool SdrObjCustomShape::doConstructOrthogonal(const ::rtl::OUString& rName)
3489 {
3490 	bool bRetval(false);
3491 	static ::rtl::OUString Imps_sNameASOrtho_quadrat( RTL_CONSTASCII_USTRINGPARAM( "quadrat" ) );
3492 	static ::rtl::OUString Imps_sNameASOrtho_round_quadrat( RTL_CONSTASCII_USTRINGPARAM( "round-quadrat" ) );
3493 	static ::rtl::OUString Imps_sNameASOrtho_circle( RTL_CONSTASCII_USTRINGPARAM( "circle" ) );
3494 	static ::rtl::OUString Imps_sNameASOrtho_circle_pie( RTL_CONSTASCII_USTRINGPARAM( "circle-pie" ) );
3495 	static ::rtl::OUString Imps_sNameASOrtho_ring( RTL_CONSTASCII_USTRINGPARAM( "ring" ) );
3496 
3497 	if(Imps_sNameASOrtho_quadrat.equalsIgnoreAsciiCase(rName))
3498 	{
3499 		bRetval = true;
3500 	}
3501 	else if(Imps_sNameASOrtho_round_quadrat.equalsIgnoreAsciiCase(rName))
3502 	{
3503 		bRetval = true;
3504 	}
3505 	else if(Imps_sNameASOrtho_circle.equalsIgnoreAsciiCase(rName))
3506 	{
3507 		bRetval = true;
3508 	}
3509 	else if(Imps_sNameASOrtho_circle_pie.equalsIgnoreAsciiCase(rName))
3510 	{
3511 		bRetval = true;
3512 	}
3513 	else if(Imps_sNameASOrtho_ring.equalsIgnoreAsciiCase(rName))
3514 	{
3515 		bRetval = true;
3516 	}
3517 
3518 	return bRetval;
3519 }
3520 
3521 // #i37011# centralize throw-away of render geometry
3522 void SdrObjCustomShape::InvalidateRenderGeometry()
3523 {
3524 	mXRenderedCustomShape = 0L;
3525     SdrObject::Free( mpLastShadowGeometry );
3526 	mpLastShadowGeometry = 0L;
3527 }
3528 
3529 // eof
3530