LCOV - code coverage report
Current view: top level - svx/source/svdraw - svdoashp.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1136 1813 62.7 %
Date: 2015-06-13 12:38:46 Functions: 79 102 77.5 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11