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

Generated by: LCOV version 1.10