LCOV - code coverage report
Current view: top level - libreoffice/svx/source/svdraw - svdoashp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 761 1830 41.6 %
Date: 2012-12-17 Functions: 58 97 59.8 %
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         778 : static void lcl_ShapeSegmentFromBinary( EnhancedCustomShapeSegment& rSegInfo, sal_uInt16 nSDat )
      91             : {
      92         778 :     switch( nSDat >> 8 )
      93             :     {
      94             :         case 0x00 :
      95         160 :             rSegInfo.Command = EnhancedCustomShapeSegmentCommand::LINETO;
      96         160 :             rSegInfo.Count   = nSDat & 0xff;
      97         160 :             if ( !rSegInfo.Count )
      98           0 :                 rSegInfo.Count = 1;
      99         160 :             break;
     100             :         case 0x20 :
     101          24 :             rSegInfo.Command = EnhancedCustomShapeSegmentCommand::CURVETO;
     102          24 :             rSegInfo.Count   = nSDat & 0xff;
     103          24 :             if ( !rSegInfo.Count )
     104           0 :                 rSegInfo.Count = 1;
     105          24 :             break;
     106             :         case 0x40 :
     107         126 :             rSegInfo.Command = EnhancedCustomShapeSegmentCommand::MOVETO;
     108         126 :             rSegInfo.Count   = nSDat & 0xff;
     109         126 :             if ( !rSegInfo.Count )
     110         126 :                 rSegInfo.Count = 1;
     111         126 :             break;
     112             :         case 0x60 :
     113         126 :             rSegInfo.Command = EnhancedCustomShapeSegmentCommand::CLOSESUBPATH;
     114         126 :             rSegInfo.Count   = 0;
     115         126 :             break;
     116             :         case 0x80 :
     117         184 :             rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ENDSUBPATH;
     118         184 :             rSegInfo.Count   = 0;
     119         184 :             break;
     120             :         case 0xa1 :
     121           0 :             rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ANGLEELLIPSETO;
     122           0 :             rSegInfo.Count   = ( nSDat & 0xff ) / 3;
     123           0 :             break;
     124             :         case 0xa2 :
     125          40 :             rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ANGLEELLIPSE;
     126          40 :             rSegInfo.Count   = ( nSDat & 0xff ) / 3;
     127          40 :             break;
     128             :         case 0xa3 :
     129           6 :             rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ARCTO;
     130           6 :             rSegInfo.Count   = ( nSDat & 0xff ) >> 2;
     131           6 :             break;
     132             :         case 0xa4 :
     133          12 :             rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ARC;
     134          12 :             rSegInfo.Count   = ( nSDat & 0xff ) >> 2;
     135          12 :             break;
     136             :         case 0xa5 :
     137          18 :             rSegInfo.Command = EnhancedCustomShapeSegmentCommand::CLOCKWISEARCTO;
     138          18 :             rSegInfo.Count   = ( nSDat & 0xff ) >> 2;
     139          18 :             break;
     140             :         case 0xa6 :
     141           0 :             rSegInfo.Command = EnhancedCustomShapeSegmentCommand::CLOCKWISEARC;
     142           0 :             rSegInfo.Count   = ( nSDat & 0xff ) >> 2;
     143           0 :             break;
     144             :         case 0xa7 :
     145          32 :             rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ELLIPTICALQUADRANTX;
     146          32 :             rSegInfo.Count   = nSDat & 0xff;
     147          32 :             break;
     148             :         case 0xa8 :
     149          48 :             rSegInfo.Command = EnhancedCustomShapeSegmentCommand::ELLIPTICALQUADRANTY;
     150          48 :             rSegInfo.Count   = nSDat & 0xff;
     151          48 :             break;
     152             :         case 0xaa :
     153           2 :             rSegInfo.Command = EnhancedCustomShapeSegmentCommand::NOFILL;
     154           2 :             rSegInfo.Count   = 0;
     155           2 :             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         778 :     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        9270 : Reference< XCustomShapeEngine > SdrObjCustomShape::GetCustomShapeEngine() const
     393             : {
     394        9270 :     if (mxCustomShapeEngine.is())
     395           0 :         return mxCustomShapeEngine;
     396             : 
     397        9270 :     String aEngine(((SdrCustomShapeEngineItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_ENGINE )).GetValue());
     398        9270 :     if ( !aEngine.Len() )
     399        9270 :         aEngine = String( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.drawing.EnhancedCustomShapeEngine" ) );
     400             : 
     401        9270 :     Reference< XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
     402             : 
     403        9270 :     Reference< XShape > aXShape = GetXShapeForSdrObject(const_cast<SdrObjCustomShape*>(this));
     404        9270 :     if ( aXShape.is() )
     405             :     {
     406        9270 :         if ( aEngine.Len() && xFactory.is() )
     407             :         {
     408        9270 :             Sequence< Any > aArgument( 1 );
     409        9270 :             Sequence< PropertyValue > aPropValues( 1 );
     410        9270 :             aPropValues[ 0 ].Name = rtl::OUString("CustomShape");
     411        9270 :             aPropValues[ 0 ].Value <<= aXShape;
     412        9270 :             aArgument[ 0 ] <<= aPropValues;
     413        9270 :             Reference< XInterface > xInterface( xFactory->createInstanceWithArguments( aEngine, aArgument ) );
     414        9270 :             if ( xInterface.is() )
     415           0 :                 mxCustomShapeEngine = Reference< XCustomShapeEngine >( xInterface, UNO_QUERY );
     416             :         }
     417             :     }
     418             : 
     419        9270 :     return mxCustomShapeEngine;
     420             : }
     421             : 
     422         738 : const SdrObject* SdrObjCustomShape::GetSdrObjectFromCustomShape() const
     423             : {
     424         738 :     if ( !mXRenderedCustomShape.is() )
     425             :     {
     426         738 :         Reference< XCustomShapeEngine > xCustomShapeEngine( GetCustomShapeEngine() );
     427         738 :         if ( xCustomShapeEngine.is() )
     428           0 :             ((SdrObjCustomShape*)this)->mXRenderedCustomShape = xCustomShapeEngine->render();
     429             :     }
     430         738 :     SdrObject* pRenderedCustomShape = mXRenderedCustomShape.is()
     431         738 :                 ? GetSdrObjectFromXShape( mXRenderedCustomShape )
     432         738 :                 : NULL;
     433         738 :     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         508 : sal_Bool SdrObjCustomShape::IsTextPath() const
     460             : {
     461         508 :     const rtl::OUString sTextPath( RTL_CONSTASCII_USTRINGPARAM ( "TextPath" ) );
     462         508 :     sal_Bool bTextPathOn = sal_False;
     463         508 :     SdrCustomShapeGeometryItem& rGeometryItem = (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY );
     464         508 :     Any* pAny = rGeometryItem.GetPropertyValueByName( sTextPath, sTextPath );
     465         508 :     if ( pAny )
     466           0 :         *pAny >>= bTextPathOn;
     467         508 :     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         900 : sal_Bool SdrObjCustomShape::IsMirroredX() const
     485             : {
     486         900 :     sal_Bool bMirroredX = sal_False;
     487         900 :     SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
     488         900 :     const rtl::OUString sMirroredX( RTL_CONSTASCII_USTRINGPARAM ( "MirroredX" ) );
     489         900 :     com::sun::star::uno::Any* pAny = aGeometryItem.GetPropertyValueByName( sMirroredX );
     490         900 :     if ( pAny )
     491          68 :         *pAny >>= bMirroredX;
     492         900 :     return bMirroredX;
     493             : }
     494         900 : sal_Bool SdrObjCustomShape::IsMirroredY() const
     495             : {
     496         900 :     sal_Bool bMirroredY = sal_False;
     497         900 :     SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
     498         900 :     const rtl::OUString sMirroredY( RTL_CONSTASCII_USTRINGPARAM ( "MirroredY" ) );
     499         900 :     com::sun::star::uno::Any* pAny = aGeometryItem.GetPropertyValueByName( sMirroredY );
     500         900 :     if ( pAny )
     501          60 :         *pAny >>= bMirroredY;
     502         900 :     return bMirroredY;
     503             : }
     504           6 : void SdrObjCustomShape::SetMirroredX( const sal_Bool bMirrorX )
     505             : {
     506           6 :     SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
     507           6 :     const rtl::OUString sMirroredX( RTL_CONSTASCII_USTRINGPARAM ( "MirroredX" ) );
     508           6 :     PropertyValue aPropVal;
     509           6 :     aPropVal.Name = sMirroredX;
     510           6 :     aPropVal.Value <<= bMirrorX;
     511           6 :     aGeometryItem.SetPropertyValue( aPropVal );
     512           6 :     SetMergedItem( aGeometryItem );
     513           6 : }
     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        1566 : double SdrObjCustomShape::GetObjectRotation() const
     526             : {
     527        1566 :     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          40 : double SdrObjCustomShape::GetExtraTextRotation( const bool bPreRotation ) const
     542             : {
     543             :     const com::sun::star::uno::Any* pAny;
     544          40 :     SdrCustomShapeGeometryItem& rGeometryItem = (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY );
     545          40 :     const rtl::OUString sTextRotateAngle( RTL_CONSTASCII_USTRINGPARAM ( "TextRotateAngle" ) );
     546          40 :     const rtl::OUString sTextPreRotateAngle( RTL_CONSTASCII_USTRINGPARAM ( "TextPreRotateAngle" ) );
     547          40 :     pAny = rGeometryItem.GetPropertyValueByName( bPreRotation ? sTextPreRotateAngle : sTextRotateAngle );
     548          40 :     double fExtraTextRotateAngle = 0.0;
     549          40 :     if ( pAny )
     550          12 :         *pAny >>= fExtraTextRotateAngle;
     551          40 :     return fExtraTextRotateAngle;
     552             : }
     553             : 
     554        8402 : sal_Bool SdrObjCustomShape::GetTextBounds( Rectangle& rTextBound ) const
     555             : {
     556        8402 :     sal_Bool bRet = sal_False;
     557             : 
     558        8402 :     Reference< XCustomShapeEngine > xCustomShapeEngine( GetCustomShapeEngine() );
     559        8402 :     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        8402 :     return bRet;
     569             : }
     570          10 : basegfx::B2DPolyPolygon SdrObjCustomShape::GetLineGeometry( const SdrObjCustomShape* pCustomShape, const sal_Bool bBezierAllowed )
     571             : {
     572          10 :     basegfx::B2DPolyPolygon aRetval;
     573          10 :     Reference< XCustomShapeEngine > xCustomShapeEngine( pCustomShape->GetCustomShapeEngine() );
     574          10 :     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          10 :     return aRetval;
     590             : }
     591             : 
     592         120 : std::vector< SdrCustomShapeInteraction > SdrObjCustomShape::GetInteractionHandles( const SdrObjCustomShape* pCustomShape ) const
     593             : {
     594         120 :     std::vector< SdrCustomShapeInteraction > xRet;
     595             :     try
     596             :     {
     597         120 :         Reference< XCustomShapeEngine > xCustomShapeEngine( pCustomShape->GetCustomShapeEngine() );
     598         120 :         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         120 :         }
     673             :     }
     674           0 :     catch( const uno::RuntimeException& )
     675             :     {
     676             :     }
     677         120 :     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          92 : static sal_Int32 GetNumberOfProperties ( const SvxMSDffHandle* pData )
     686             : {
     687          92 :     sal_Int32     nPropertiesNeeded=1;  // position is always needed
     688          92 :     sal_Int32     nFlags = pData->nFlags;
     689             : 
     690          92 :     if ( nFlags & MSDFF_HANDLE_FLAGS_MIRRORED_X )
     691           0 :         nPropertiesNeeded++;
     692          92 :     if ( nFlags & MSDFF_HANDLE_FLAGS_MIRRORED_Y )
     693           0 :         nPropertiesNeeded++;
     694          92 :     if ( nFlags & MSDFF_HANDLE_FLAGS_SWITCHED )
     695          10 :         nPropertiesNeeded++;
     696          92 :     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          92 :     else if ( nFlags & MSDFF_HANDLE_FLAGS_RANGE )
     708             :     {
     709          74 :         if ( pData->nRangeXMin != DEFAULT_MINIMUM_SIGNED_COMPARE )
     710          50 :             nPropertiesNeeded++;
     711          74 :         if ( pData->nRangeXMax != DEFAULT_MAXIMUM_SIGNED_COMPARE )
     712          50 :             nPropertiesNeeded++;
     713          74 :         if ( pData->nRangeYMin != DEFAULT_MINIMUM_SIGNED_COMPARE )
     714          50 :             nPropertiesNeeded++;
     715          74 :         if ( pData->nRangeYMax != DEFAULT_MAXIMUM_SIGNED_COMPARE )
     716          50 :             nPropertiesNeeded++;
     717             :     }
     718             : 
     719          92 :     return nPropertiesNeeded;
     720             : }
     721             : 
     722          92 : static void lcl_ShapePropertiesFromDFF( const SvxMSDffHandle* pData, com::sun::star::beans::PropertyValues& rPropValues )
     723             : {
     724          92 :     sal_Int32 nFlags = pData->nFlags, n=0;
     725             : 
     726             :     // POSITION
     727             :     {
     728          92 :         const rtl::OUString sPosition( RTL_CONSTASCII_USTRINGPARAM ( "Position" ) );
     729          92 :         ::com::sun::star::drawing::EnhancedCustomShapeParameterPair aPosition;
     730          92 :         EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aPosition.First, pData->nPositionX, sal_True, sal_True );
     731          92 :         EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aPosition.Second, pData->nPositionY, sal_True, sal_False );
     732          92 :         rPropValues[ n ].Name = sPosition;
     733          92 :         rPropValues[ n++ ].Value <<= aPosition;
     734             :     }
     735          92 :     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          92 :     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          92 :     if ( nFlags & MSDFF_HANDLE_FLAGS_SWITCHED )
     750             :     {
     751          10 :         const rtl::OUString sSwitched( RTL_CONSTASCII_USTRINGPARAM ( "Switched" ) );
     752          10 :         sal_Bool bSwitched = sal_True;
     753          10 :         rPropValues[ n ].Name = sSwitched;
     754          10 :         rPropValues[ n++ ].Value <<= bSwitched;
     755             :     }
     756          92 :     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          92 :     else if ( nFlags & MSDFF_HANDLE_FLAGS_RANGE )
     789             :     {
     790          74 :         if ( pData->nRangeXMin != DEFAULT_MINIMUM_SIGNED_COMPARE )
     791             :         {
     792          50 :             const rtl::OUString sRangeXMinimum( RTL_CONSTASCII_USTRINGPARAM ( "RangeXMinimum" ) );
     793          50 :             ::com::sun::star::drawing::EnhancedCustomShapeParameter aRangeXMinimum;
     794             :             EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRangeXMinimum, pData->nRangeXMin,
     795          50 :                            ( nFlags & MSDFF_HANDLE_FLAGS_RANGE_X_MIN_IS_SPECIAL ) != 0, sal_True  );
     796          50 :             rPropValues[ n ].Name = sRangeXMinimum;
     797          50 :             rPropValues[ n++ ].Value <<= aRangeXMinimum;
     798             :         }
     799          74 :         if ( pData->nRangeXMax != DEFAULT_MAXIMUM_SIGNED_COMPARE )
     800             :         {
     801          50 :             const rtl::OUString sRangeXMaximum( RTL_CONSTASCII_USTRINGPARAM ( "RangeXMaximum" ) );
     802          50 :             ::com::sun::star::drawing::EnhancedCustomShapeParameter aRangeXMaximum;
     803             :             EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRangeXMaximum, pData->nRangeXMax,
     804          50 :                            ( nFlags & MSDFF_HANDLE_FLAGS_RANGE_X_MAX_IS_SPECIAL ) != 0, sal_False );
     805          50 :             rPropValues[ n ].Name = sRangeXMaximum;
     806          50 :             rPropValues[ n++ ].Value <<= aRangeXMaximum;
     807             :         }
     808          74 :         if ( pData->nRangeYMin != DEFAULT_MINIMUM_SIGNED_COMPARE )
     809             :         {
     810          50 :             const rtl::OUString sRangeYMinimum( RTL_CONSTASCII_USTRINGPARAM ( "RangeYMinimum" ) );
     811          50 :             ::com::sun::star::drawing::EnhancedCustomShapeParameter aRangeYMinimum;
     812             :             EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRangeYMinimum, pData->nRangeYMin,
     813          50 :                              ( nFlags & MSDFF_HANDLE_FLAGS_RANGE_Y_MIN_IS_SPECIAL ) != 0, sal_True );
     814          50 :             rPropValues[ n ].Name = sRangeYMinimum;
     815          50 :             rPropValues[ n++ ].Value <<= aRangeYMinimum;
     816             :         }
     817          74 :         if ( pData->nRangeYMax != DEFAULT_MAXIMUM_SIGNED_COMPARE )
     818             :         {
     819          50 :             const rtl::OUString sRangeYMaximum( RTL_CONSTASCII_USTRINGPARAM ( "RangeYMaximum" ) );
     820          50 :             ::com::sun::star::drawing::EnhancedCustomShapeParameter aRangeYMaximum;
     821             :             EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRangeYMaximum, pData->nRangeYMax,
     822          50 :                              ( nFlags & MSDFF_HANDLE_FLAGS_RANGE_Y_MAX_IS_SPECIAL ) != 0, sal_False );
     823          50 :             rPropValues[ n ].Name = sRangeYMaximum;
     824          50 :             rPropValues[ n++ ].Value <<= aRangeYMaximum;
     825             :         }
     826             :     }
     827          92 :     return;
     828             : }
     829             : 
     830        1730 : sdr::properties::BaseProperties* SdrObjCustomShape::CreateObjectSpecificProperties()
     831             : {
     832        1730 :     return new sdr::properties::CustomShapeProperties(*this);
     833             : }
     834             : 
     835      151686 : TYPEINIT1(SdrObjCustomShape,SdrTextObj);
     836        1730 : SdrObjCustomShape::SdrObjCustomShape() :
     837             :     SdrTextObj(),
     838             :     fObjectRotation( 0.0 ),
     839        1730 :     mpLastShadowGeometry(0L)
     840             : {
     841        1730 :     bTextFrame = sal_True;
     842        1730 : }
     843             : 
     844        5040 : SdrObjCustomShape::~SdrObjCustomShape()
     845             : {
     846             :     // delete buffered display geometry
     847        1680 :     InvalidateRenderGeometry();
     848        3360 : }
     849             : 
     850        1742 : void SdrObjCustomShape::MergeDefaultAttributes( const rtl::OUString* pType )
     851             : {
     852        1742 :     PropertyValue aPropVal;
     853        1742 :     rtl::OUString sShapeType;
     854        1742 :     const rtl::OUString sType( RTL_CONSTASCII_USTRINGPARAM ( "Type" ) );
     855        1742 :     SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
     856        1742 :     if ( pType && !pType->isEmpty() )
     857             :     {
     858          32 :         sal_Int32 nType = pType->toInt32();
     859          32 :         if ( nType )
     860          20 :             sShapeType = EnhancedCustomShapeTypeNames::Get( static_cast< MSO_SPT >( nType ) );
     861             :         else
     862          12 :             sShapeType = *pType;
     863             : 
     864          32 :         aPropVal.Name = sType;
     865          32 :         aPropVal.Value <<= sShapeType;
     866          32 :         aGeometryItem.SetPropertyValue( aPropVal );
     867             :     }
     868             :     else
     869             :     {
     870        1710 :         Any *pAny = aGeometryItem.GetPropertyValueByName( sType );
     871        1710 :         if ( pAny )
     872        1706 :             *pAny >>= sShapeType;
     873             :     }
     874        1742 :     MSO_SPT eSpType = EnhancedCustomShapeTypeNames::Get( sShapeType );
     875             : 
     876        1742 :     const sal_Int32* pDefData = NULL;
     877        1742 :     const mso_CustomShape* pDefCustomShape = GetCustomShapeContent( eSpType );
     878        1742 :     if ( pDefCustomShape )
     879        1690 :         pDefData = pDefCustomShape->pDefData;
     880             : 
     881        1742 :     com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue > seqAdjustmentValues;
     882             : 
     883             :     //////////////////////
     884             :     // AdjustmentValues //
     885             :     //////////////////////
     886        1742 :     const rtl::OUString sAdjustmentValues( RTL_CONSTASCII_USTRINGPARAM ( "AdjustmentValues" ) );
     887        1742 :     const Any* pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sAdjustmentValues );
     888        1742 :     if ( pAny )
     889         130 :         *pAny >>= seqAdjustmentValues;
     890        1742 :     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         142 :         sal_Int32 i, nAdjustmentValues = seqAdjustmentValues.getLength();
     894         142 :         sal_Int32 nAdjustmentDefaults = *pDefData++;
     895         142 :         if ( nAdjustmentDefaults > nAdjustmentValues )
     896             :         {
     897          44 :             seqAdjustmentValues.realloc( nAdjustmentDefaults );
     898         114 :             for ( i = nAdjustmentValues; i < nAdjustmentDefaults; i++ )
     899             :             {
     900          70 :                 seqAdjustmentValues[ i ].Value <<= pDefData[ i ];
     901          70 :                 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         142 :         sal_Int32 nCount = nAdjustmentValues > nAdjustmentDefaults ? nAdjustmentDefaults : nAdjustmentValues;
     906         276 :         for ( i = 0; i < nCount; i++ )
     907             :         {
     908         134 :             if ( seqAdjustmentValues[ i ].State != com::sun::star::beans::PropertyState_DIRECT_VALUE )
     909             :             {
     910           2 :                 seqAdjustmentValues[ i ].Value <<= pDefData[ i ];
     911           2 :                 seqAdjustmentValues[ i ].State = com::sun::star::beans::PropertyState_DIRECT_VALUE;
     912             :             }
     913             :         }
     914             :     }
     915        1742 :     aPropVal.Name = sAdjustmentValues;
     916        1742 :     aPropVal.Value <<= seqAdjustmentValues;
     917        1742 :     aGeometryItem.SetPropertyValue( aPropVal );
     918             : 
     919             :     ///////////////
     920             :     // Coordsize //
     921             :     ///////////////
     922        1742 :     const rtl::OUString sViewBox( RTL_CONSTASCII_USTRINGPARAM ( "ViewBox" ) );
     923        1742 :     const Any* pViewBox = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sViewBox );
     924        1742 :     com::sun::star::awt::Rectangle aViewBox;
     925        1742 :     if ( !pViewBox || !(*pViewBox >>= aViewBox ) )
     926             :     {
     927        1602 :         if ( pDefCustomShape )
     928             :         {
     929        1596 :             aViewBox.X = 0;
     930        1596 :             aViewBox.Y = 0;
     931        1596 :             aViewBox.Width = pDefCustomShape->nCoordWidth;
     932        1596 :             aViewBox.Height= pDefCustomShape->nCoordHeight;
     933        1596 :             aPropVal.Name = sViewBox;
     934        1596 :             aPropVal.Value <<= aViewBox;
     935        1596 :             aGeometryItem.SetPropertyValue( aPropVal );
     936             :         }
     937             :     }
     938             : 
     939        1742 :     const rtl::OUString sPath( RTL_CONSTASCII_USTRINGPARAM ( "Path" ) );
     940             : 
     941             :     //////////////////////
     942             :     // Path/Coordinates //
     943             :     //////////////////////
     944        1742 :     const rtl::OUString sCoordinates( RTL_CONSTASCII_USTRINGPARAM ( "Coordinates" ) );
     945        1742 :     pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sCoordinates );
     946        1742 :     if ( !pAny && pDefCustomShape && pDefCustomShape->nVertices && pDefCustomShape->pVertices )
     947             :     {
     948        1596 :         com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair> seqCoordinates;
     949             : 
     950        1596 :         sal_Int32 i, nCount = pDefCustomShape->nVertices;
     951        1596 :         seqCoordinates.realloc( nCount );
     952       10066 :         for ( i = 0; i < nCount; i++ )
     953             :         {
     954        8470 :             EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqCoordinates[ i ].First, pDefCustomShape->pVertices[ i ].nValA );
     955        8470 :             EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqCoordinates[ i ].Second, pDefCustomShape->pVertices[ i ].nValB );
     956             :         }
     957        1596 :         aPropVal.Name = sCoordinates;
     958        1596 :         aPropVal.Value <<= seqCoordinates;
     959        1596 :         aGeometryItem.SetPropertyValue( sPath, aPropVal );
     960             :     }
     961             : 
     962             :     // Path/GluePoints //
     963        1742 :     const rtl::OUString sGluePoints( RTL_CONSTASCII_USTRINGPARAM ( "GluePoints" ) );
     964        1742 :     pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sGluePoints );
     965        1742 :     if ( !pAny && pDefCustomShape && pDefCustomShape->nGluePoints && pDefCustomShape->pGluePoints )
     966             :     {
     967          60 :         com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair> seqGluePoints;
     968          60 :         sal_Int32 i, nCount = pDefCustomShape->nGluePoints;
     969          60 :         seqGluePoints.realloc( nCount );
     970         470 :         for ( i = 0; i < nCount; i++ )
     971             :         {
     972         410 :             EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqGluePoints[ i ].First, pDefCustomShape->pGluePoints[ i ].nValA );
     973         410 :             EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqGluePoints[ i ].Second, pDefCustomShape->pGluePoints[ i ].nValB );
     974             :         }
     975          60 :         aPropVal.Name = sGluePoints;
     976          60 :         aPropVal.Value <<= seqGluePoints;
     977          60 :         aGeometryItem.SetPropertyValue( sPath, aPropVal );
     978             :     }
     979             : 
     980             :     // Path/Segments //
     981        1742 :     const rtl::OUString sSegments( RTL_CONSTASCII_USTRINGPARAM ( "Segments" ) );
     982        1742 :     pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sSegments );
     983        1742 :     if ( !pAny && pDefCustomShape && pDefCustomShape->nElements && pDefCustomShape->pElements )
     984             :     {
     985         120 :         com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeSegment > seqSegments;
     986             : 
     987         120 :         sal_Int32 i, nCount = pDefCustomShape->nElements;
     988         120 :         seqSegments.realloc( nCount );
     989         898 :         for ( i = 0; i < nCount; i++ )
     990             :         {
     991         778 :             EnhancedCustomShapeSegment& rSegInfo = seqSegments[ i ];
     992         778 :             sal_uInt16 nSDat = pDefCustomShape->pElements[ i ];
     993         778 :             lcl_ShapeSegmentFromBinary( rSegInfo, nSDat );
     994             :         }
     995         120 :         aPropVal.Name = sSegments;
     996         120 :         aPropVal.Value <<= seqSegments;
     997         120 :         aGeometryItem.SetPropertyValue( sPath, aPropVal );
     998             :     }
     999             : 
    1000             :     // Path/StretchX //
    1001        1742 :     const rtl::OUString sStretchX( RTL_CONSTASCII_USTRINGPARAM ( "StretchX" ) );
    1002        1742 :     pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sStretchX );
    1003        1742 :     if ( !pAny && pDefCustomShape )
    1004             :     {
    1005        1660 :         sal_Int32 nXRef = pDefCustomShape->nXRef;
    1006        1660 :         if ( ( nXRef != DEFAULT_MINIMUM_SIGNED_COMPARE ) )
    1007             :         {
    1008          14 :             aPropVal.Name = sStretchX;
    1009          14 :             aPropVal.Value <<= nXRef;
    1010          14 :             aGeometryItem.SetPropertyValue( sPath, aPropVal );
    1011             :         }
    1012             :     }
    1013             : 
    1014             :     // Path/StretchY //
    1015        1742 :     const rtl::OUString sStretchY( RTL_CONSTASCII_USTRINGPARAM ( "StretchY" ) );
    1016        1742 :     pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sStretchY );
    1017        1742 :     if ( !pAny && pDefCustomShape )
    1018             :     {
    1019        1664 :         sal_Int32 nYRef = pDefCustomShape->nYRef;
    1020        1664 :         if ( ( nYRef != DEFAULT_MINIMUM_SIGNED_COMPARE ) )
    1021             :         {
    1022          14 :             aPropVal.Name = sStretchY;
    1023          14 :             aPropVal.Value <<= nYRef;
    1024          14 :             aGeometryItem.SetPropertyValue( sPath, aPropVal );
    1025             :         }
    1026             :     }
    1027             : 
    1028             :     // Path/TextFrames //
    1029        1742 :     const rtl::OUString sTextFrames( RTL_CONSTASCII_USTRINGPARAM ( "TextFrames" ) );
    1030        1742 :     pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sTextFrames );
    1031        1742 :     if ( !pAny && pDefCustomShape && pDefCustomShape->nTextRect && pDefCustomShape->pTextRect )
    1032             :     {
    1033          96 :         com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeTextFrame > seqTextFrames;
    1034             : 
    1035          96 :         sal_Int32 i, nCount = pDefCustomShape->nTextRect;
    1036          96 :         seqTextFrames.realloc( nCount );
    1037          96 :         const SvxMSDffTextRectangles* pRectangles = pDefCustomShape->pTextRect;
    1038         192 :         for ( i = 0; i < nCount; i++, pRectangles++ )
    1039             :         {
    1040          96 :             EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqTextFrames[ i ].TopLeft.First,     pRectangles->nPairA.nValA );
    1041          96 :             EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqTextFrames[ i ].TopLeft.Second,    pRectangles->nPairA.nValB );
    1042          96 :             EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqTextFrames[ i ].BottomRight.First,  pRectangles->nPairB.nValA );
    1043          96 :             EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( seqTextFrames[ i ].BottomRight.Second, pRectangles->nPairB.nValB );
    1044             :         }
    1045          96 :         aPropVal.Name = sTextFrames;
    1046          96 :         aPropVal.Value <<= seqTextFrames;
    1047          96 :         aGeometryItem.SetPropertyValue( sPath, aPropVal );
    1048             :     }
    1049             : 
    1050             :     // Equations //
    1051        1742 :     const rtl::OUString sEquations(  "Equations"  );
    1052        1742 :     pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sEquations );
    1053        1742 :     if ( !pAny && pDefCustomShape && pDefCustomShape->nCalculation && pDefCustomShape->pCalculation )
    1054             :     {
    1055          72 :         com::sun::star::uno::Sequence< rtl::OUString > seqEquations;
    1056             : 
    1057          72 :         sal_Int32 i, nCount = pDefCustomShape->nCalculation;
    1058          72 :         seqEquations.realloc( nCount );
    1059          72 :         const SvxMSDffCalculationData* pData = pDefCustomShape->pCalculation;
    1060        1278 :         for ( i = 0; i < nCount; i++, pData++ )
    1061        1206 :             seqEquations[ i ] = EnhancedCustomShape2d::GetEquation( pData->nFlags, pData->nVal[ 0 ], pData->nVal[ 1 ], pData->nVal[ 2 ] );
    1062          72 :         aPropVal.Name = sEquations;
    1063          72 :         aPropVal.Value <<= seqEquations;
    1064          72 :         aGeometryItem.SetPropertyValue( aPropVal );
    1065             :     }
    1066             : 
    1067             :     // Handles //
    1068        1742 :     const rtl::OUString sHandles(  "Handles"  );
    1069        1742 :     pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sHandles );
    1070        1742 :     if ( !pAny && pDefCustomShape && pDefCustomShape->nHandles && pDefCustomShape->pHandles )
    1071             :     {
    1072          70 :         com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValues > seqHandles;
    1073             : 
    1074          70 :         sal_Int32 i, nCount = pDefCustomShape->nHandles;
    1075          70 :         const SvxMSDffHandle* pData = pDefCustomShape->pHandles;
    1076          70 :         seqHandles.realloc( nCount );
    1077         162 :         for ( i = 0; i < nCount; i++, pData++ )
    1078             :         {
    1079             :             sal_Int32 nPropertiesNeeded;
    1080          92 :             com::sun::star::beans::PropertyValues& rPropValues = seqHandles[ i ];
    1081          92 :             nPropertiesNeeded = GetNumberOfProperties( pData );
    1082          92 :             rPropValues.realloc( nPropertiesNeeded );
    1083          92 :             lcl_ShapePropertiesFromDFF( pData, rPropValues );
    1084             :         }
    1085          70 :         aPropVal.Name = sHandles;
    1086          70 :         aPropVal.Value <<= seqHandles;
    1087          70 :         aGeometryItem.SetPropertyValue( aPropVal );
    1088             :     }
    1089        1742 :     SetMergedItem( aGeometryItem );
    1090        1742 : }
    1091             : 
    1092           2 : sal_Bool SdrObjCustomShape::IsDefaultGeometry( const DefaultType eDefaultType ) const
    1093             : {
    1094           2 :     sal_Bool bIsDefaultGeometry = sal_False;
    1095             : 
    1096           2 :     PropertyValue aPropVal;
    1097           2 :     rtl::OUString sShapeType;
    1098           2 :     const rtl::OUString sType( RTL_CONSTASCII_USTRINGPARAM ( "Type" ) );
    1099           2 :     SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
    1100             : 
    1101           2 :     Any *pAny = aGeometryItem.GetPropertyValueByName( sType );
    1102           2 :     if ( pAny )
    1103           2 :         *pAny >>= sShapeType;
    1104             : 
    1105           2 :     MSO_SPT eSpType = EnhancedCustomShapeTypeNames::Get( sShapeType );
    1106             : 
    1107           2 :     const mso_CustomShape* pDefCustomShape = GetCustomShapeContent( eSpType );
    1108           2 :     const rtl::OUString sPath( RTL_CONSTASCII_USTRINGPARAM ( "Path" ) );
    1109           2 :     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           2 :             const rtl::OUString sEquations(  "Equations"  );
    1259           2 :             pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sEquations );
    1260           2 :             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           2 :             else if ( pDefCustomShape && ( ( pDefCustomShape->nCalculation == 0 ) || ( pDefCustomShape->pCalculation == 0 ) ) )
    1277           0 :                 bIsDefaultGeometry = sal_True;
    1278             :         }
    1279           2 :         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           2 :     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        1792 : void SdrObjCustomShape::SetModel(SdrModel* pNewModel)
    1406             : {
    1407        1792 :     SdrTextObj::SetModel(pNewModel);
    1408        1792 :     mXRenderedCustomShape.clear();
    1409        1792 : }
    1410             : 
    1411       26028 : sal_uInt16 SdrObjCustomShape::GetObjIdentifier() const
    1412             : {
    1413       26028 :     return sal_uInt16(OBJ_CUSTOMSHAPE);
    1414             : }
    1415             : 
    1416             : ////////////////////////////////////////////////////////////////////////////////////////////////////
    1417             : 
    1418        1812 : void SdrObjCustomShape::RecalcSnapRect()
    1419             : {
    1420        1812 :     SdrTextObj::RecalcSnapRect();
    1421        1812 : }
    1422        5262 : const Rectangle& SdrObjCustomShape::GetSnapRect() const
    1423             : {
    1424        5262 :     return SdrTextObj::GetSnapRect();
    1425             : }
    1426        2202 : const Rectangle& SdrObjCustomShape::GetCurrentBoundRect() const
    1427             : {
    1428        2202 :     return SdrTextObj::GetCurrentBoundRect();
    1429             : }
    1430        2294 : const Rectangle& SdrObjCustomShape::GetLogicRect() const
    1431             : {
    1432        2294 :     return SdrTextObj::GetLogicRect();
    1433             : }
    1434        2576 : void SdrObjCustomShape::NbcSetSnapRect( const Rectangle& rRect )
    1435             : {
    1436        2576 :     aRect=rRect;
    1437        2576 :     ImpJustifyRect(aRect);
    1438        2576 :     InvalidateRenderGeometry();
    1439        2576 :     Rectangle aTextBound( aRect );
    1440        2576 :     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        2576 :     ImpCheckShear();
    1456        2576 :     SetRectsDirty();
    1457        2576 :     SetChanged();
    1458        2576 : }
    1459        1878 : void SdrObjCustomShape::SetSnapRect( const Rectangle& rRect )
    1460             : {
    1461        1878 :     Rectangle aBoundRect0;
    1462        1878 :     if ( pUserCall )
    1463           2 :         aBoundRect0 = GetLastBoundRect();
    1464        1878 :     NbcSetSnapRect( rRect );
    1465        1878 :     BroadcastObjectChange();
    1466        1878 :     SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
    1467        1878 : }
    1468         192 : void SdrObjCustomShape::NbcSetLogicRect( const Rectangle& rRect )
    1469             : {
    1470         192 :     aRect = rRect;
    1471         192 :     ImpJustifyRect( aRect );
    1472         192 :     InvalidateRenderGeometry();
    1473         192 :     Rectangle aTextBound( aRect );
    1474         192 :     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         192 :     SetRectsDirty();
    1488         192 :     SetChanged();
    1489         192 : }
    1490         192 : void SdrObjCustomShape::SetLogicRect( const Rectangle& rRect )
    1491             : {
    1492         192 :     Rectangle aBoundRect0;
    1493         192 :     if ( pUserCall )
    1494          24 :         aBoundRect0 = GetLastBoundRect();
    1495         192 :     NbcSetLogicRect(rRect);
    1496         192 :     BroadcastObjectChange();
    1497         192 :     SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
    1498         192 : }
    1499         520 : void SdrObjCustomShape::Move( const Size& rSiz )
    1500             : {
    1501         520 :     if ( rSiz.Width() || rSiz.Height() )
    1502             :     {
    1503         256 :         Rectangle aBoundRect0;
    1504         256 :         if ( pUserCall )
    1505         106 :             aBoundRect0 = GetLastBoundRect();
    1506         256 :         NbcMove(rSiz);
    1507         256 :         SetChanged();
    1508         256 :         BroadcastObjectChange();
    1509         256 :         SendUserCall(SDRUSERCALL_MOVEONLY,aBoundRect0);
    1510             :     }
    1511         520 : }
    1512         316 : void SdrObjCustomShape::NbcMove( const Size& rSiz )
    1513             : {
    1514         316 :     SdrTextObj::NbcMove( rSiz );
    1515         316 :     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         316 :     if(mpLastShadowGeometry)
    1529             :     {
    1530           0 :         mpLastShadowGeometry->NbcMove( rSiz );
    1531             :     }
    1532         316 : }
    1533           8 : void SdrObjCustomShape::Resize( const Point& rRef, const Fraction& xFact, const Fraction& yFact, bool bUnsetRelative )
    1534             : {
    1535           8 :     SdrTextObj::Resize( rRef, xFact, yFact, bUnsetRelative );
    1536           8 : }
    1537             : 
    1538           8 : void SdrObjCustomShape::NbcResize( const Point& rRef, const Fraction& rxFact, const Fraction& ryFact )
    1539             : {
    1540           8 :     Fraction xFact( rxFact );
    1541           8 :     Fraction yFact( ryFact );
    1542             : 
    1543             :     // taking care of handles that should not been changed
    1544           8 :     Rectangle aOld( aRect );
    1545           8 :     std::vector< SdrCustomShapeInteraction > aInteractionHandles( GetInteractionHandles( this ) );
    1546             : 
    1547           8 :     SdrTextObj::NbcResize( rRef, xFact, yFact );
    1548             : 
    1549           8 :     if ( ( xFact.GetNumerator() != xFact.GetDenominator() )
    1550           0 :         || ( yFact.GetNumerator()!= yFact.GetDenominator() ) )
    1551             :     {
    1552          24 :         if ( ( ( xFact.GetNumerator() < 0 ) && ( xFact.GetDenominator() > 0 ) ) ||
    1553          16 :             ( ( xFact.GetNumerator() > 0 ) && ( xFact.GetDenominator() < 0 ) ) )
    1554             :         {
    1555           0 :             SetMirroredX( IsMirroredX() == sal_False );
    1556             :         }
    1557          24 :         if ( ( ( yFact.GetNumerator() < 0 ) && ( yFact.GetDenominator() > 0 ) ) ||
    1558          16 :             ( ( yFact.GetNumerator() > 0 ) && ( yFact.GetDenominator() < 0 ) ) )
    1559             :         {
    1560           0 :             SetMirroredY( IsMirroredY() == sal_False );
    1561             :         }
    1562             :     }
    1563             : 
    1564           8 :     std::vector< SdrCustomShapeInteraction >::iterator aIter( aInteractionHandles.begin() );
    1565          16 :     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           8 :     InvalidateRenderGeometry();
    1588           8 : }
    1589          18 : void SdrObjCustomShape::NbcRotate( const Point& rRef, long nWink, double sn, double cs )
    1590             : {
    1591          18 :     sal_Bool bMirroredX = IsMirroredX();
    1592          18 :     sal_Bool bMirroredY = IsMirroredY();
    1593             : 
    1594          18 :     fObjectRotation = fmod( fObjectRotation, 360.0 );
    1595          18 :     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          18 :     SdrTextObj::NbcRotate( aRect.TopLeft(), -aGeo.nDrehWink,        // retrieving the unrotated text object
    1601             :                             sin( (-aGeo.nDrehWink) * F_PI18000 ),
    1602          36 :                             cos( (-aGeo.nDrehWink) * F_PI18000 ) );
    1603          18 :     aGeo.nDrehWink = 0;                                             // resetting aGeo data
    1604          18 :     aGeo.RecalcSinCos();
    1605             : 
    1606          18 :     long nW = (long)( fObjectRotation * 100 );                      // applying our object rotation
    1607          18 :     if ( bMirroredX )
    1608           0 :         nW = 36000 - nW;
    1609          18 :     if ( bMirroredY )
    1610           0 :         nW = 18000 - nW;
    1611          18 :     nW = nW % 36000;
    1612          18 :     if ( nW < 0 )
    1613           0 :         nW = 36000 + nW;
    1614          18 :     SdrTextObj::NbcRotate( aRect.TopLeft(), nW,                     // applying text rotation
    1615             :                             sin( nW * F_PI18000 ),
    1616          36 :                             cos( nW * F_PI18000 ) );
    1617             : 
    1618          18 :     int nSwap = 0;
    1619          18 :     if ( bMirroredX )
    1620           0 :         nSwap ^= 1;
    1621          18 :     if ( bMirroredY )
    1622           0 :         nSwap ^= 1;
    1623             : 
    1624          18 :     double fWink = nWink;                                                   // updating to our new object rotation
    1625          18 :     fWink /= 100.0;
    1626          18 :     fObjectRotation = fmod( nSwap ? fObjectRotation - fWink : fObjectRotation + fWink, 360.0 );
    1627          18 :     if ( fObjectRotation < 0 )
    1628           0 :         fObjectRotation = 360 + fObjectRotation;
    1629             : 
    1630          18 :     SdrTextObj::NbcRotate( rRef, nWink, sn, cs );                           // applying text rotation
    1631          18 :     InvalidateRenderGeometry();
    1632          18 : }
    1633             : 
    1634          18 : void SdrObjCustomShape::NbcMirror( const Point& rRef1, const Point& rRef2 )
    1635             : {
    1636             :     // storing horizontal and vertical flipping without modifying the rotate angle
    1637          18 :     sal_Bool bHorz = sal_False;
    1638          18 :     sal_Bool bVert = sal_False;
    1639          18 :     if ( rRef1.X() == rRef2.X() )
    1640          10 :         bHorz = sal_True;
    1641          18 :     if ( rRef1.Y() == rRef2.Y() )
    1642           8 :         bVert = sal_True;
    1643          18 :     if ( !bHorz && !bVert )
    1644           0 :         bHorz = bVert = sal_True;
    1645             : 
    1646          18 :     if ( bHorz || bVert )
    1647             :     {
    1648          18 :         SdrCustomShapeGeometryItem aGeometryItem( (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) );
    1649             : 
    1650             :         // "MirroredX" //
    1651          18 :         if ( bHorz )
    1652             :         {
    1653          10 :             const rtl::OUString sMirroredX( RTL_CONSTASCII_USTRINGPARAM ( "MirroredX" ) );
    1654          10 :             com::sun::star::uno::Any* pAny = aGeometryItem.GetPropertyValueByName( sMirroredX );
    1655          10 :             if ( pAny )
    1656             :             {
    1657           6 :                 sal_Bool bFlip = sal_Bool();
    1658           6 :                 if ( *pAny >>= bFlip )
    1659             :                 {
    1660           6 :                     if ( bFlip )
    1661           6 :                         bHorz = sal_False;
    1662             :                 }
    1663             :             }
    1664          10 :             PropertyValue aPropVal;
    1665          10 :             aPropVal.Name = sMirroredX;
    1666          10 :             aPropVal.Value <<= bHorz;
    1667          10 :             aGeometryItem.SetPropertyValue( aPropVal );
    1668             :         }
    1669             : 
    1670             :         // "MirroredY" //
    1671          18 :         if ( bVert )
    1672             :         {
    1673           8 :             const rtl::OUString sMirroredY( RTL_CONSTASCII_USTRINGPARAM ( "MirroredY" ) );
    1674           8 :             com::sun::star::uno::Any* pAny = aGeometryItem.GetPropertyValueByName( sMirroredY );
    1675           8 :             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           8 :             PropertyValue aPropVal;
    1685           8 :             aPropVal.Name = sMirroredY;
    1686           8 :             aPropVal.Value <<= bVert;
    1687           8 :             aGeometryItem.SetPropertyValue( aPropVal );
    1688             :         }
    1689          18 :         SetMergedItem( aGeometryItem );
    1690             :     }
    1691          18 :     SdrTextObj::NbcMirror( rRef1, rRef2 );
    1692          18 :     InvalidateRenderGeometry();
    1693          18 : }
    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         230 : void SdrObjCustomShape::ImpCheckCustomGluePointsAreAdded()
    1751             : {
    1752         230 :     const SdrObject* pSdrObject = GetSdrObjectFromCustomShape();
    1753             : 
    1754         230 :     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         230 : }
    1848             : 
    1849             : // #i38892#
    1850         222 : const SdrGluePointList* SdrObjCustomShape::GetGluePointList() const
    1851             : {
    1852         222 :     ((SdrObjCustomShape*)this)->ImpCheckCustomGluePointsAreAdded();
    1853         222 :     return SdrTextObj::GetGluePointList();
    1854             : }
    1855             : 
    1856             : // #i38892#
    1857           8 : SdrGluePointList* SdrObjCustomShape::ForceGluePointList()
    1858             : {
    1859           8 :     if(SdrTextObj::ForceGluePointList())
    1860             :     {
    1861           8 :         ImpCheckCustomGluePointsAreAdded();
    1862           8 :         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           2 : bool SdrObjCustomShape::hasSpecialDrag() const
    1914             : {
    1915           2 :     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         286 : bool SdrObjCustomShape::IsAutoGrowHeight() const
    2235             : {
    2236         286 :     const SfxItemSet& rSet = GetMergedItemSet();
    2237         286 :     bool bIsAutoGrowHeight = ((SdrTextAutoGrowHeightItem&)(rSet.Get(SDRATTR_TEXT_AUTOGROWHEIGHT))).GetValue();
    2238         286 :     if ( bIsAutoGrowHeight && IsVerticalWriting() )
    2239           0 :         bIsAutoGrowHeight = ((SdrTextWordWrapItem&)(rSet.Get(SDRATTR_TEXT_WORDWRAP))).GetValue() == sal_False;
    2240         286 :     return bIsAutoGrowHeight;
    2241             : }
    2242         170 : bool SdrObjCustomShape::IsAutoGrowWidth() const
    2243             : {
    2244         170 :     const SfxItemSet& rSet = GetMergedItemSet();
    2245         170 :     bool bIsAutoGrowWidth = ((SdrTextAutoGrowHeightItem&)(rSet.Get(SDRATTR_TEXT_AUTOGROWHEIGHT))).GetValue();
    2246         170 :     if ( bIsAutoGrowWidth && !IsVerticalWriting() )
    2247         146 :         bIsAutoGrowWidth = ((SdrTextWordWrapItem&)(rSet.Get(SDRATTR_TEXT_WORDWRAP))).GetValue() == sal_False;
    2248         170 :     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        1166 : void SdrObjCustomShape::SetVerticalWriting( sal_Bool bVertical )
    2256             : {
    2257        1166 :     ForceOutlinerParaObject();
    2258             : 
    2259        1166 :     OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
    2260             : 
    2261             :     DBG_ASSERT( pOutlinerParaObject, "SdrTextObj::SetVerticalWriting() without OutlinerParaObject!" );
    2262             : 
    2263        1166 :     if( pOutlinerParaObject )
    2264             :     {
    2265        1166 :         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        1166 : }
    2313        5614 : bool SdrObjCustomShape::AdjustTextFrameWidthAndHeight(Rectangle& rR, bool bHgt, bool bWdt) const
    2314             : {
    2315        5614 :      if ( pModel && HasText() && !rR.IsEmpty() )
    2316             :     {
    2317         130 :         bool bWdtGrow=bWdt && IsAutoGrowWidth();
    2318         130 :         bool bHgtGrow=bHgt && IsAutoGrowHeight();
    2319         130 :         if ( bWdtGrow || bHgtGrow )
    2320             :         {
    2321         130 :             Rectangle aR0(rR);
    2322         130 :             long nHgt=0,nMinHgt=0,nMaxHgt=0;
    2323         130 :             long nWdt=0,nMinWdt=0,nMaxWdt=0;
    2324         130 :             Size aSiz(rR.GetSize()); aSiz.Width()--; aSiz.Height()--;
    2325         130 :             Size aMaxSiz(100000,100000);
    2326         130 :             Size aTmpSiz(pModel->GetMaxObjSize());
    2327         130 :             if (aTmpSiz.Width()!=0) aMaxSiz.Width()=aTmpSiz.Width();
    2328         130 :             if (aTmpSiz.Height()!=0) aMaxSiz.Height()=aTmpSiz.Height();
    2329         130 :             if (bWdtGrow)
    2330             :             {
    2331         100 :                 nMinWdt=GetMinTextFrameWidth();
    2332         100 :                 nMaxWdt=GetMaxTextFrameWidth();
    2333         100 :                 if (nMaxWdt==0 || nMaxWdt>aMaxSiz.Width()) nMaxWdt=aMaxSiz.Width();
    2334         100 :                 if (nMinWdt<=0) nMinWdt=1;
    2335         100 :                 aSiz.Width()=nMaxWdt;
    2336             :             }
    2337         130 :             if (bHgtGrow)
    2338             :             {
    2339         130 :                 nMinHgt=GetMinTextFrameHeight();
    2340         130 :                 nMaxHgt=GetMaxTextFrameHeight();
    2341         130 :                 if (nMaxHgt==0 || nMaxHgt>aMaxSiz.Height()) nMaxHgt=aMaxSiz.Height();
    2342         130 :                 if (nMinHgt<=0) nMinHgt=1;
    2343         130 :                 aSiz.Height()=nMaxHgt;
    2344             :             }
    2345         130 :             long nHDist=GetTextLeftDistance()+GetTextRightDistance();
    2346         130 :             long nVDist=GetTextUpperDistance()+GetTextLowerDistance();
    2347         130 :             aSiz.Width()-=nHDist;
    2348         130 :             aSiz.Height()-=nVDist;
    2349         130 :             if ( aSiz.Width() < 2 )
    2350           0 :                 aSiz.Width() = 2;   // minimum size=2
    2351         130 :             if ( aSiz.Height() < 2 )
    2352           0 :                 aSiz.Height() = 2; // minimum size=2
    2353             : 
    2354         130 :             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         130 :                 Outliner& rOutliner=ImpGetDrawOutliner();
    2370         130 :                 rOutliner.SetPaperSize(aSiz);
    2371         130 :                 rOutliner.SetUpdateMode(sal_True);
    2372             :                 // TODO: add the optimization with bPortionInfoChecked again.
    2373         130 :                 OutlinerParaObject* pOutlinerParaObject = GetOutlinerParaObject();
    2374         130 :                 if( pOutlinerParaObject != NULL )
    2375             :                 {
    2376         130 :                     rOutliner.SetText(*pOutlinerParaObject);
    2377         130 :                     rOutliner.SetFixedCellHeight(((const SdrTextFixedCellHeightItem&)GetMergedItem(SDRATTR_TEXT_USEFIXEDCELLHEIGHT)).GetValue());
    2378             :                 }
    2379         130 :                 if ( bWdtGrow )
    2380             :                 {
    2381         100 :                     Size aSiz2(rOutliner.CalcTextSize());
    2382         100 :                     nWdt=aSiz2.Width()+1; // a little more tolerance
    2383         100 :                     if ( bHgtGrow )
    2384         100 :                         nHgt=aSiz2.Height()+1; // a little more tolerance
    2385             :                 }
    2386             :                 else
    2387          30 :                     nHgt = rOutliner.GetTextHeight()+1; // a little more tolerance
    2388         130 :                 rOutliner.Clear();
    2389             :             }
    2390         130 :             if ( nWdt < nMinWdt )
    2391           0 :                 nWdt = nMinWdt;
    2392         130 :             if ( nWdt > nMaxWdt )
    2393           0 :                 nWdt = nMaxWdt;
    2394         130 :             nWdt += nHDist;
    2395         130 :             if ( nWdt < 1 )
    2396          30 :                 nWdt = 1; // nHDist may also be negative
    2397         130 :             if ( nHgt < nMinHgt )
    2398           0 :                 nHgt = nMinHgt;
    2399         130 :             if ( nHgt > nMaxHgt )
    2400           0 :                 nHgt = nMaxHgt;
    2401         130 :             nHgt+=nVDist;
    2402         130 :             if ( nHgt < 1 )
    2403           0 :                 nHgt = 1; // nVDist may also be negative
    2404         130 :             long nWdtGrow = nWdt-(rR.Right()-rR.Left());
    2405         130 :             long nHgtGrow = nHgt-(rR.Bottom()-rR.Top());
    2406         130 :             if ( nWdtGrow == 0 )
    2407          16 :                 bWdtGrow = sal_False;
    2408         130 :             if ( nHgtGrow == 0 )
    2409          54 :                 bHgtGrow=sal_False;
    2410         130 :             if ( bWdtGrow || bHgtGrow )
    2411             :             {
    2412         112 :                 if ( bWdtGrow )
    2413             :                 {
    2414          84 :                     SdrTextHorzAdjust eHAdj=GetTextHorizontalAdjust();
    2415          84 :                     if ( eHAdj == SDRTEXTHORZADJUST_LEFT )
    2416           0 :                         rR.Right()+=nWdtGrow;
    2417          84 :                     else if ( eHAdj == SDRTEXTHORZADJUST_RIGHT )
    2418           0 :                         rR.Left()-=nWdtGrow;
    2419             :                     else
    2420             :                     {
    2421          84 :                         long nWdtGrow2=nWdtGrow/2;
    2422          84 :                         rR.Left()-=nWdtGrow2;
    2423          84 :                         rR.Right()=rR.Left()+nWdt;
    2424             :                     }
    2425             :                 }
    2426         112 :                 if ( bHgtGrow )
    2427             :                 {
    2428          76 :                     SdrTextVertAdjust eVAdj=GetTextVerticalAdjust();
    2429          76 :                     if ( eVAdj == SDRTEXTVERTADJUST_TOP )
    2430          76 :                         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         112 :                 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         112 :                 return sal_True;
    2450             :             }
    2451             :         }
    2452             :     }
    2453        5502 :     return sal_False;
    2454             : }
    2455             : 
    2456        5614 : Rectangle SdrObjCustomShape::ImpCalculateTextFrame( const bool bHgt, const bool bWdt )
    2457             : {
    2458        5614 :     Rectangle aReturnValue;
    2459             : 
    2460        5614 :     Rectangle aOldTextRect( aRect );        // <- initial text rectangle
    2461             : 
    2462        5614 :     Rectangle aNewTextRect( aRect );        // <- new text rectangle returned from the custom shape renderer,
    2463        5614 :     GetTextBounds( aNewTextRect );          //    it depends to the current logical shape size
    2464             : 
    2465        5614 :     Rectangle aAdjustedTextRect( aNewTextRect );                            // <- new text rectangle is being tested by AdjustTextFrameWidthAndHeight to ensure
    2466        5614 :     if ( AdjustTextFrameWidthAndHeight( aAdjustedTextRect, bHgt, bWdt ) )   //    that the new text rectangle is matching the current text size from the outliner
    2467             :     {
    2468         112 :         if ( ( aAdjustedTextRect != aNewTextRect ) && ( aOldTextRect != aAdjustedTextRect ) )
    2469             :         {
    2470         112 :             aReturnValue = aRect;
    2471         112 :             double fXScale = (double)aOldTextRect.GetWidth() / (double)aNewTextRect.GetWidth();
    2472         112 :             double fYScale = (double)aOldTextRect.GetHeight() / (double)aNewTextRect.GetHeight();
    2473         112 :             double fRightDiff = (double)( aAdjustedTextRect.Right() - aNewTextRect.Right() ) * fXScale;
    2474         112 :             double fLeftDiff  = (double)( aAdjustedTextRect.Left()  - aNewTextRect.Left()  ) * fXScale;
    2475         112 :             double fTopDiff   = (double)( aAdjustedTextRect.Top()   - aNewTextRect.Top()   ) * fYScale;
    2476         112 :             double fBottomDiff= (double)( aAdjustedTextRect.Bottom()- aNewTextRect.Bottom()) * fYScale;
    2477         112 :             aReturnValue.Left() += (sal_Int32)fLeftDiff;
    2478         112 :             aReturnValue.Right() += (sal_Int32)fRightDiff;
    2479         112 :             aReturnValue.Top() += (sal_Int32)fTopDiff;
    2480         112 :             aReturnValue.Bottom() += (sal_Int32)fBottomDiff;
    2481             :         }
    2482             :     }
    2483        5614 :     return aReturnValue;
    2484             : }
    2485             : 
    2486        5614 : bool SdrObjCustomShape::NbcAdjustTextFrameWidthAndHeight(bool bHgt, bool bWdt)
    2487             : {
    2488        5614 :     Rectangle aNewTextRect = ImpCalculateTextFrame( bHgt, bWdt );
    2489        5614 :     sal_Bool bRet = !aNewTextRect.IsEmpty() && ( aNewTextRect != aRect );
    2490        5614 :     if ( bRet )
    2491             :     {
    2492             :         // taking care of handles that should not been changed
    2493         112 :         std::vector< SdrCustomShapeInteraction > aInteractionHandles( GetInteractionHandles( this ) );
    2494             : 
    2495         112 :         aRect = aNewTextRect;
    2496         112 :         SetRectsDirty();
    2497         112 :         SetChanged();
    2498             : 
    2499         112 :         std::vector< SdrCustomShapeInteraction >::iterator aIter( aInteractionHandles.begin() );
    2500         224 :         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         112 :         InvalidateRenderGeometry();
    2513             :     }
    2514        5614 :     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         988 : void SdrObjCustomShape::NbcSetOutlinerParaObject(OutlinerParaObject* pTextObject)
    2807             : {
    2808         988 :     SdrTextObj::NbcSetOutlinerParaObject( pTextObject );
    2809         988 :     SetBoundRectDirty();
    2810         988 :     SetRectsDirty(sal_True);
    2811         988 :     InvalidateRenderGeometry();
    2812         988 : }
    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          24 : void SdrObjCustomShape::TakeObjNameSingul(XubString& rName) const
    2832             : {
    2833          24 :     rName = ImpGetResStr(STR_ObjNameSingulCUSTOMSHAPE);
    2834          24 :     String aNm( GetName() );
    2835          24 :     if( aNm.Len() )
    2836             :     {
    2837           0 :         rName += sal_Unicode(' ');
    2838           0 :         rName += sal_Unicode('\'');
    2839           0 :         rName += aNm;
    2840           0 :         rName += sal_Unicode('\'');
    2841          24 :     }
    2842          24 : }
    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         134 : void SdrObjCustomShape::NbcSetStyleSheet( SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr )
    2906             : {
    2907             :     // #i40944#
    2908         134 :     InvalidateRenderGeometry();
    2909         134 :     SdrObject::NbcSetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
    2910         134 : }
    2911             : 
    2912        1464 : void SdrObjCustomShape::SetPage( SdrPage* pNewPage )
    2913             : {
    2914        1464 :     SdrTextObj::SetPage( pNewPage );
    2915             : 
    2916        1464 :     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         596 :         Rectangle aTmp( aRect );    //creating temporary rectangle #i61108#
    2922         596 :         NbcSetSnapRect( aTmp );
    2923             :     }
    2924        1464 : }
    2925             : 
    2926           0 : SdrObjGeoData* SdrObjCustomShape::NewGeoData() const
    2927             : {
    2928           0 :     return new SdrAShapeObjGeoData;
    2929             : }
    2930             : 
    2931         156 : void SdrObjCustomShape::SaveGeoData(SdrObjGeoData& rGeo) const
    2932             : {
    2933         156 :     SdrTextObj::SaveGeoData( rGeo );
    2934         156 :     SdrAShapeObjGeoData& rAGeo=(SdrAShapeObjGeoData&)rGeo;
    2935         156 :     rAGeo.fObjectRotation = fObjectRotation;
    2936         156 :     rAGeo.bMirroredX = IsMirroredX();
    2937         156 :     rAGeo.bMirroredY = IsMirroredY();
    2938             : 
    2939         156 :     const rtl::OUString sAdjustmentValues( RTL_CONSTASCII_USTRINGPARAM ( "AdjustmentValues" ) );
    2940         156 :     Any* pAny( ( (SdrCustomShapeGeometryItem&)GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) ).GetPropertyValueByName( sAdjustmentValues ) );
    2941         156 :     if ( pAny )
    2942         130 :         *pAny >>= rAGeo.aAdjustmentSeq;
    2943         156 : }
    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         144 : void SdrObjCustomShape::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, const basegfx::B2DPolyPolygon& /*rPolyPolygon*/)
    2965             : {
    2966             :     // break up matrix
    2967         144 :     basegfx::B2DTuple aScale;
    2968         144 :     basegfx::B2DTuple aTranslate;
    2969             :     double fRotate, fShearX;
    2970         144 :     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         144 :     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         144 :     aGeo.nDrehWink = 0;
    2983         144 :     aGeo.RecalcSinCos();
    2984         144 :     aGeo.nShearWink = 0;
    2985         144 :     aGeo.RecalcTan();
    2986             : 
    2987             :     // force metric to pool metric
    2988         144 :     SfxMapUnit eMapUnit = GetObjectItemSet().GetPool()->GetMetric(0);
    2989         144 :     if(eMapUnit != SFX_MAPUNIT_100TH_MM)
    2990             :     {
    2991          10 :         switch(eMapUnit)
    2992             :         {
    2993             :             case SFX_MAPUNIT_TWIP :
    2994             :             {
    2995             :                 // position
    2996          10 :                 aTranslate.setX(ImplMMToTwips(aTranslate.getX()));
    2997          10 :                 aTranslate.setY(ImplMMToTwips(aTranslate.getY()));
    2998             : 
    2999             :                 // size
    3000          10 :                 aScale.setX(ImplMMToTwips(aScale.getX()));
    3001          10 :                 aScale.setY(ImplMMToTwips(aScale.getY()));
    3002             : 
    3003          10 :                 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         144 :     if( pModel && pModel->IsWriter() )
    3014             :     {
    3015          10 :         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         144 :     Point aPoint = Point();
    3023         144 :     Size aSize(FRound(aScale.getX()), FRound(aScale.getY()));
    3024             :     // fdo#47434 We need a valid rectangle here
    3025         144 :     if( !aSize.Height() ) aSize.setHeight( 1 );
    3026         144 :     if( !aSize.Width() ) aSize.setWidth( 1 );
    3027             : 
    3028         144 :     Rectangle aBaseRect(aPoint, aSize);
    3029         144 :     SetSnapRect(aBaseRect);
    3030             : 
    3031             :     // shear?
    3032         144 :     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         144 :     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         144 :     if(!aTranslate.equalZero())
    3055             :     {
    3056         144 :         Move(Size(FRound(aTranslate.getX()), FRound(aTranslate.getY())));
    3057         144 :     }
    3058         144 : }
    3059             : 
    3060             : // taking fObjectRotation instead of aGeo.nWink
    3061         274 : sal_Bool SdrObjCustomShape::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B2DPolyPolygon& /*rPolyPolygon*/) const
    3062             : {
    3063             :     // get turn and shear
    3064         274 :     double fRotate = fObjectRotation * F_PI180;
    3065         274 :     double fShearX = (aGeo.nShearWink / 100.0) * F_PI180;
    3066             : 
    3067             :     // get aRect, this is the unrotated snaprect
    3068         274 :     Rectangle aRectangle(aRect);
    3069             : 
    3070         274 :     sal_Bool bMirroredX = IsMirroredX();
    3071         274 :     sal_Bool bMirroredY = IsMirroredY();
    3072         274 :     if ( bMirroredX || bMirroredY )
    3073             :     {   // we have to retrieve the unmirrored rect
    3074             : 
    3075           6 :         GeoStat aNewGeo( aGeo );
    3076             : 
    3077           6 :         if ( bMirroredX )
    3078             :         {
    3079           6 :             Polygon aPol( Rect2Poly( aRect, aNewGeo ) );
    3080           6 :             Rectangle aBoundRect( aPol.GetBoundRect() );
    3081             : 
    3082           6 :             Point aRef1( ( aBoundRect.Left() + aBoundRect.Right() ) >> 1, aBoundRect.Top() );
    3083           6 :             Point aRef2( aRef1.X(), aRef1.Y() + 1000 );
    3084             :             sal_uInt16 i;
    3085           6 :             sal_uInt16 nPntAnz=aPol.GetSize();
    3086          36 :             for (i=0; i<nPntAnz; i++)
    3087             :             {
    3088          30 :                 MirrorPoint(aPol[i],aRef1,aRef2);
    3089             :             }
    3090             :             // mirror polygon and move it a bit
    3091           6 :             Polygon aPol0(aPol);
    3092           6 :             aPol[0]=aPol0[1];
    3093           6 :             aPol[1]=aPol0[0];
    3094           6 :             aPol[2]=aPol0[3];
    3095           6 :             aPol[3]=aPol0[2];
    3096           6 :             aPol[4]=aPol0[1];
    3097           6 :             Poly2Rect(aPol,aRectangle,aNewGeo);
    3098             :         }
    3099           6 :         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         274 :     basegfx::B2DTuple aScale(aRectangle.GetWidth(), aRectangle.GetHeight());
    3125         274 :     basegfx::B2DTuple aTranslate(aRectangle.Left(), aRectangle.Top());
    3126             : 
    3127             :     // position may be relative to anchorpos, convert
    3128         274 :     if( pModel && pModel->IsWriter() )
    3129             :     {
    3130          10 :         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         274 :     SfxMapUnit eMapUnit = GetObjectItemSet().GetPool()->GetMetric(0);
    3138         274 :     if(eMapUnit != SFX_MAPUNIT_100TH_MM)
    3139             :     {
    3140          10 :         switch(eMapUnit)
    3141             :         {
    3142             :             case SFX_MAPUNIT_TWIP :
    3143             :             {
    3144             :                 // position
    3145          10 :                 aTranslate.setX(ImplTwipsToMM(aTranslate.getX()));
    3146          10 :                 aTranslate.setY(ImplTwipsToMM(aTranslate.getY()));
    3147             : 
    3148             :                 // size
    3149          10 :                 aScale.setX(ImplTwipsToMM(aScale.getX()));
    3150          10 :                 aScale.setY(ImplTwipsToMM(aScale.getY()));
    3151             : 
    3152          10 :                 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         274 :         basegfx::fTools::equalZero(fShearX) ? 0.0 : tan(fShearX),
    3165         274 :         basegfx::fTools::equalZero(fRotate) ? 0.0 : -fRotate,
    3166         548 :         aTranslate);
    3167             : 
    3168         274 :     return sal_False;
    3169             : }
    3170             : 
    3171        1730 : sdr::contact::ViewContact* SdrObjCustomShape::CreateObjectSpecificViewContact()
    3172             : {
    3173        1730 :     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       86400 : void SdrObjCustomShape::InvalidateRenderGeometry()
    3212             : {
    3213       86400 :     mXRenderedCustomShape = 0L;
    3214       86400 :     mxCustomShapeEngine = 0L;
    3215       86400 :     SdrObject::Free( mpLastShadowGeometry );
    3216       86400 :     mpLastShadowGeometry = 0L;
    3217       86400 : }
    3218             : 
    3219             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10