LCOV - code coverage report
Current view: top level - svx/source/svdraw - svddrgmt.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 1879 0.0 %
Date: 2014-04-11 Functions: 0 201 0.0 %
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 "svddrgm1.hxx"
      21             : #include <math.h>
      22             : 
      23             : #include <tools/bigint.hxx>
      24             : #include <vcl/svapp.hxx>
      25             : #include <vcl/settings.hxx>
      26             : #include "svx/xattr.hxx"
      27             : #include <svx/xpoly.hxx>
      28             : #include <svx/svdetc.hxx>
      29             : #include <svx/svdtrans.hxx>
      30             : #include <svx/svdundo.hxx>
      31             : #include <svx/svdmark.hxx>
      32             : #include <svx/svdocapt.hxx>
      33             : #include <svx/svdpagv.hxx>
      34             : #include "svx/svdstr.hrc"
      35             : #include "svx/svdglob.hxx"
      36             : #include <svx/svddrgv.hxx>
      37             : #include <svx/svdograf.hxx>
      38             : #include <svx/dialogs.hrc>
      39             : #include <svx/dialmgr.hxx>
      40             : #include <svx/sdgcpitm.hxx>
      41             : #include <basegfx/polygon/b2dpolygon.hxx>
      42             : #include <basegfx/polygon/b2dpolygontools.hxx>
      43             : #include <svx/sdr/overlay/overlaypolypolygon.hxx>
      44             : #include <svx/sdr/overlay/overlaymanager.hxx>
      45             : #include <svx/sdr/overlay/overlayrollingrectangle.hxx>
      46             : #include <svx/sdrpagewindow.hxx>
      47             : #include <svx/sdrpaintwindow.hxx>
      48             : #include <basegfx/matrix/b2dhommatrix.hxx>
      49             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      50             : #include <svx/sdr/contact/viewobjectcontact.hxx>
      51             : #include <svx/sdr/contact/viewcontact.hxx>
      52             : #include <svx/sdr/contact/displayinfo.hxx>
      53             : #include <svx/sdr/overlay/overlayprimitive2dsequenceobject.hxx>
      54             : #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
      55             : #include <svx/sdr/contact/objectcontact.hxx>
      56             : #include "svx/svditer.hxx"
      57             : #include <svx/svdopath.hxx>
      58             : #include <svx/polypolygoneditor.hxx>
      59             : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
      60             : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
      61             : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
      62             : #include <drawinglayer/primitive2d/markerarrayprimitive2d.hxx>
      63             : #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
      64             : #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
      65             : #include <svx/svdoole2.hxx>
      66             : #include <svx/svdovirt.hxx>
      67             : #include <svx/svdouno.hxx>
      68             : #include <svx/sdr/primitive2d/sdrprimitivetools.hxx>
      69             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      70             : #include <drawinglayer/attribute/sdrlineattribute.hxx>
      71             : #include <drawinglayer/attribute/sdrlinestartendattribute.hxx>
      72             : #include <map>
      73             : #include <vector>
      74             : 
      75             : 
      76             : 
      77           0 : SdrDragEntry::SdrDragEntry()
      78           0 : :   mbAddToTransparent(false)
      79             : {
      80           0 : }
      81             : 
      82           0 : SdrDragEntry::~SdrDragEntry()
      83             : {
      84           0 : }
      85             : 
      86             : 
      87             : 
      88           0 : SdrDragEntryPolyPolygon::SdrDragEntryPolyPolygon(const basegfx::B2DPolyPolygon& rOriginalPolyPolygon)
      89             : :   SdrDragEntry(),
      90           0 :     maOriginalPolyPolygon(rOriginalPolyPolygon)
      91             : {
      92           0 : }
      93             : 
      94           0 : SdrDragEntryPolyPolygon::~SdrDragEntryPolyPolygon()
      95             : {
      96           0 : }
      97             : 
      98           0 : drawinglayer::primitive2d::Primitive2DSequence SdrDragEntryPolyPolygon::createPrimitive2DSequenceInCurrentState(SdrDragMethod& rDragMethod)
      99             : {
     100           0 :     drawinglayer::primitive2d::Primitive2DSequence aRetval;
     101             : 
     102           0 :     if(maOriginalPolyPolygon.count())
     103             :     {
     104           0 :         basegfx::B2DPolyPolygon aCopy(maOriginalPolyPolygon);
     105           0 :         const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
     106             : 
     107           0 :         rDragMethod.applyCurrentTransformationToPolyPolygon(aCopy);
     108           0 :         basegfx::BColor aColA(aSvtOptionsDrawinglayer.GetStripeColorA().getBColor());
     109           0 :         basegfx::BColor aColB(aSvtOptionsDrawinglayer.GetStripeColorB().getBColor());
     110           0 :         const double fStripeLength(aSvtOptionsDrawinglayer.GetStripeLength());
     111             : 
     112           0 :         if(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
     113             :         {
     114           0 :             aColA = aColB = Application::GetSettings().GetStyleSettings().GetHighlightColor().getBColor();
     115           0 :             aColB.invert();
     116             :         }
     117             : 
     118           0 :         aRetval.realloc(2);
     119           0 :         aRetval[0] = new drawinglayer::primitive2d::PolyPolygonMarkerPrimitive2D(
     120             :             aCopy,
     121             :             aColA,
     122             :             aColB,
     123           0 :             fStripeLength);
     124             : 
     125           0 :         const basegfx::BColor aHilightColor(aSvtOptionsDrawinglayer.getHilightColor().getBColor());
     126           0 :         const double fTransparence(aSvtOptionsDrawinglayer.GetTransparentSelectionPercent() * 0.01);
     127             : 
     128           0 :         aRetval[1] = new drawinglayer::primitive2d::PolyPolygonSelectionPrimitive2D(
     129             :             aCopy,
     130             :             aHilightColor,
     131             :             fTransparence,
     132             :             3.0,
     133           0 :             false);
     134             :     }
     135             : 
     136           0 :     return aRetval;
     137             : }
     138             : 
     139             : 
     140             : 
     141           0 : SdrDragEntrySdrObject::SdrDragEntrySdrObject(const SdrObject& rOriginal, sdr::contact::ObjectContact& rObjectContact, bool bModify)
     142             : :   SdrDragEntry(),
     143             :     maOriginal(rOriginal),
     144             :     mpClone(0),
     145             :     mrObjectContact(rObjectContact),
     146           0 :     mbModify(bModify)
     147             : {
     148             :     // add SdrObject parts to transparent overlay stuff
     149           0 :     setAddToTransparent(true);
     150           0 : }
     151             : 
     152           0 : SdrDragEntrySdrObject::~SdrDragEntrySdrObject()
     153             : {
     154           0 :     if(mpClone)
     155             :     {
     156           0 :         SdrObject::Free(mpClone);
     157             :     }
     158           0 : }
     159             : 
     160           0 : void SdrDragEntrySdrObject::prepareCurrentState(SdrDragMethod& rDragMethod)
     161             : {
     162             :     // for the moment, i need to re-create the clone in all cases. I need to figure
     163             :     // out when clone and original have the same class, so that i can use operator=
     164             :     // in those cases
     165             : 
     166           0 :     if(mpClone)
     167             :     {
     168           0 :         SdrObject::Free(mpClone);
     169           0 :         mpClone = 0;
     170             :     }
     171             : 
     172           0 :     if(mbModify)
     173             :     {
     174           0 :         if(!mpClone)
     175             :         {
     176           0 :             mpClone = maOriginal.getFullDragClone();
     177             :         }
     178             : 
     179             :         // apply original transformation, implemented at the DragMethods
     180           0 :         rDragMethod.applyCurrentTransformationToSdrObject(*mpClone);
     181             :     }
     182           0 : }
     183             : 
     184           0 : drawinglayer::primitive2d::Primitive2DSequence SdrDragEntrySdrObject::createPrimitive2DSequenceInCurrentState(SdrDragMethod&)
     185             : {
     186           0 :     const SdrObject* pSource = &maOriginal;
     187             : 
     188           0 :     if(mbModify && mpClone)
     189             :     {
     190             :         // choose source for geometry data
     191           0 :         pSource = mpClone;
     192             :     }
     193             : 
     194             :     // get VOC and Primitive2DSequence
     195           0 :     sdr::contact::ViewContact& rVC = pSource->GetViewContact();
     196           0 :     sdr::contact::ViewObjectContact& rVOC = rVC.GetViewObjectContact(mrObjectContact);
     197           0 :     sdr::contact::DisplayInfo aDisplayInfo;
     198             : 
     199             :     // Do not use the last ViewPort set at the OC from the last ProcessDisplay(),
     200             :     // here we want the complete primitive sequence without visibility clippings
     201           0 :     mrObjectContact.resetViewPort();
     202             : 
     203           0 :     return rVOC.getPrimitive2DSequenceHierarchy(aDisplayInfo);
     204             : }
     205             : 
     206             : 
     207             : 
     208           0 : SdrDragEntryPrimitive2DSequence::SdrDragEntryPrimitive2DSequence(
     209             :     const drawinglayer::primitive2d::Primitive2DSequence& rSequence,
     210             :     bool bAddToTransparent)
     211             : :   SdrDragEntry(),
     212           0 :     maPrimitive2DSequence(rSequence)
     213             : {
     214             :     // add parts to transparent overlay stuff if necessary
     215           0 :     setAddToTransparent(bAddToTransparent);
     216           0 : }
     217             : 
     218           0 : SdrDragEntryPrimitive2DSequence::~SdrDragEntryPrimitive2DSequence()
     219             : {
     220           0 : }
     221             : 
     222           0 : drawinglayer::primitive2d::Primitive2DSequence SdrDragEntryPrimitive2DSequence::createPrimitive2DSequenceInCurrentState(SdrDragMethod& rDragMethod)
     223             : {
     224             :     drawinglayer::primitive2d::Primitive2DReference aTransformPrimitive2D(
     225             :         new drawinglayer::primitive2d::TransformPrimitive2D(
     226           0 :             rDragMethod.getCurrentTransformation(),
     227           0 :             maPrimitive2DSequence));
     228             : 
     229           0 :     return drawinglayer::primitive2d::Primitive2DSequence(&aTransformPrimitive2D, 1);
     230             : }
     231             : 
     232             : 
     233             : 
     234           0 : SdrDragEntryPointGlueDrag::SdrDragEntryPointGlueDrag(const std::vector< basegfx::B2DPoint >& rPositions, bool bIsPointDrag)
     235             : :   maPositions(rPositions),
     236           0 :     mbIsPointDrag(bIsPointDrag)
     237             : {
     238             :     // add SdrObject parts to transparent overlay stuff
     239           0 :     setAddToTransparent(true);
     240           0 : }
     241             : 
     242           0 : SdrDragEntryPointGlueDrag::~SdrDragEntryPointGlueDrag()
     243             : {
     244           0 : }
     245             : 
     246           0 : drawinglayer::primitive2d::Primitive2DSequence SdrDragEntryPointGlueDrag::createPrimitive2DSequenceInCurrentState(SdrDragMethod& rDragMethod)
     247             : {
     248           0 :     drawinglayer::primitive2d::Primitive2DSequence aRetval;
     249             : 
     250           0 :     if(!maPositions.empty())
     251             :     {
     252           0 :         basegfx::B2DPolygon aPolygon;
     253           0 :         sal_uInt32 a(0);
     254             : 
     255           0 :         for(a = 0; a < maPositions.size(); a++)
     256             :         {
     257           0 :             aPolygon.append(maPositions[a]);
     258             :         }
     259             : 
     260           0 :         basegfx::B2DPolyPolygon aPolyPolygon(aPolygon);
     261             : 
     262           0 :         rDragMethod.applyCurrentTransformationToPolyPolygon(aPolyPolygon);
     263             : 
     264           0 :         const basegfx::B2DPolygon aTransformed(aPolyPolygon.getB2DPolygon(0));
     265           0 :         std::vector< basegfx::B2DPoint > aTransformedPositions;
     266             : 
     267           0 :         aTransformedPositions.reserve(aTransformed.count());
     268             : 
     269           0 :         for(a = 0; a < aTransformed.count(); a++)
     270             :         {
     271           0 :             aTransformedPositions.push_back(aTransformed.getB2DPoint(a));
     272             :         }
     273             : 
     274           0 :         if(mbIsPointDrag)
     275             :         {
     276           0 :             const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
     277           0 :             basegfx::BColor aColor(aSvtOptionsDrawinglayer.GetStripeColorA().getBColor());
     278             : 
     279           0 :             if(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
     280             :             {
     281           0 :                 aColor = Application::GetSettings().GetStyleSettings().GetHighlightColor().getBColor();
     282             :             }
     283             : 
     284             :             drawinglayer::primitive2d::Primitive2DReference aMarkerArrayPrimitive2D(
     285             :                 new drawinglayer::primitive2d::MarkerArrayPrimitive2D(aTransformedPositions,
     286           0 :                     drawinglayer::primitive2d::createDefaultCross_3x3(aColor)));
     287             : 
     288           0 :             aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aMarkerArrayPrimitive2D, 1);
     289             :         }
     290             :         else
     291             :         {
     292             :             drawinglayer::primitive2d::Primitive2DReference aMarkerArrayPrimitive2D(
     293             :                 new drawinglayer::primitive2d::MarkerArrayPrimitive2D(aTransformedPositions,
     294           0 :                                                                       SdrHdl::createGluePointBitmap()));
     295           0 :             aRetval = drawinglayer::primitive2d::Primitive2DSequence(&aMarkerArrayPrimitive2D, 1);
     296           0 :         }
     297             :     }
     298             : 
     299           0 :     return aRetval;
     300             : }
     301             : 
     302             : 
     303             : 
     304           0 : TYPEINIT0(SdrDragMethod);
     305             : 
     306           0 : void SdrDragMethod::resetSdrDragEntries()
     307             : {
     308             :     // clear entries; creation is on demand
     309           0 :     clearSdrDragEntries();
     310           0 : }
     311             : 
     312           0 : basegfx::B2DRange SdrDragMethod::getCurrentRange() const
     313             : {
     314           0 :     return getB2DRangeFromOverlayObjectList();
     315             : }
     316             : 
     317           0 : void SdrDragMethod::clearSdrDragEntries()
     318             : {
     319           0 :     for(sal_uInt32 a(0); a < maSdrDragEntries.size(); a++)
     320             :     {
     321           0 :         delete maSdrDragEntries[a];
     322             :     }
     323             : 
     324           0 :     maSdrDragEntries.clear();
     325           0 : }
     326             : 
     327           0 : void SdrDragMethod::addSdrDragEntry(SdrDragEntry* pNew)
     328             : {
     329           0 :     if(pNew)
     330             :     {
     331           0 :         maSdrDragEntries.push_back(pNew);
     332             :     }
     333           0 : }
     334             : 
     335           0 : void SdrDragMethod::createSdrDragEntries()
     336             : {
     337           0 :     if(getSdrDragView().GetSdrPageView() && getSdrDragView().GetSdrPageView()->HasMarkedObjPageView())
     338             :     {
     339           0 :         if(getSdrDragView().IsDraggingPoints())
     340             :         {
     341           0 :             createSdrDragEntries_PointDrag();
     342             :         }
     343           0 :         else if(getSdrDragView().IsDraggingGluePoints())
     344             :         {
     345           0 :             createSdrDragEntries_GlueDrag();
     346             :         }
     347             :         else
     348             :         {
     349           0 :             if(getSolidDraggingActive())
     350             :             {
     351           0 :                 createSdrDragEntries_SolidDrag();
     352             :             }
     353             :             else
     354             :             {
     355           0 :                 createSdrDragEntries_PolygonDrag();
     356             :             }
     357             :         }
     358             :     }
     359           0 : }
     360             : 
     361           0 : void SdrDragMethod::createSdrDragEntryForSdrObject(const SdrObject& rOriginal, sdr::contact::ObjectContact& rObjectContact, bool bModify)
     362             : {
     363             :     // add full object drag; Clone() at the object has to work
     364             :     // for this
     365           0 :     addSdrDragEntry(new SdrDragEntrySdrObject(rOriginal, rObjectContact, bModify));
     366           0 : }
     367             : 
     368           0 : void SdrDragMethod::createSdrDragEntries_SolidDrag()
     369             : {
     370           0 :     const sal_uInt32 nMarkAnz(getSdrDragView().GetMarkedObjectCount());
     371           0 :     SdrPageView* pPV = getSdrDragView().GetSdrPageView();
     372             : 
     373           0 :     if(pPV)
     374             :     {
     375           0 :         for(sal_uInt32 a(0); a < nMarkAnz; a++)
     376             :         {
     377           0 :             SdrMark* pM = getSdrDragView().GetSdrMarkByIndex(a);
     378             : 
     379           0 :             if(pM->GetPageView() == pPV)
     380             :             {
     381           0 :                 const SdrObject* pObject = pM->GetMarkedSdrObj();
     382             : 
     383           0 :                 if(pObject)
     384             :                 {
     385           0 :                     if(pPV->PageWindowCount())
     386             :                     {
     387           0 :                         sdr::contact::ObjectContact& rOC = pPV->GetPageWindow(0)->GetObjectContact();
     388           0 :                         SdrObjListIter aIter(*pObject);
     389             : 
     390           0 :                         while(aIter.IsMore())
     391             :                         {
     392           0 :                             SdrObject* pCandidate = aIter.Next();
     393             : 
     394           0 :                             if(pCandidate)
     395             :                             {
     396           0 :                                 const bool bSuppressFullDrag(!pCandidate->supportsFullDrag());
     397           0 :                                 bool bAddWireframe(bSuppressFullDrag);
     398             : 
     399           0 :                                 if(!bAddWireframe && !pCandidate->HasLineStyle())
     400             :                                 {
     401             :                                     // add wireframe for objects without outline
     402           0 :                                     bAddWireframe = true;
     403             :                                 }
     404             : 
     405           0 :                                 if(!bSuppressFullDrag)
     406             :                                 {
     407             :                                     // add full object drag; Clone() at the object has to work
     408             :                                     // for this
     409           0 :                                     createSdrDragEntryForSdrObject(*pCandidate, rOC, true);
     410             :                                 }
     411             : 
     412           0 :                                 if(bAddWireframe)
     413             :                                 {
     414             :                                     // when dragging a 50% transparent copy of a filled or not filled object without
     415             :                                     // outline, this is normally hard to see. Add extra wireframe in that case. This
     416             :                                     // works nice e.g. with text frames etc.
     417           0 :                                     addSdrDragEntry(new SdrDragEntryPolyPolygon(pCandidate->TakeXorPoly()));
     418             :                                 }
     419             :                             }
     420           0 :                         }
     421             :                     }
     422             :                 }
     423             :             }
     424             :         }
     425             :     }
     426           0 : }
     427             : 
     428           0 : void SdrDragMethod::createSdrDragEntries_PolygonDrag()
     429             : {
     430           0 :     const sal_uInt32 nMarkAnz(getSdrDragView().GetMarkedObjectCount());
     431           0 :     bool bNoPolygons(getSdrDragView().IsNoDragXorPolys() || nMarkAnz > getSdrDragView().GetDragXorPolyLimit());
     432           0 :     basegfx::B2DPolyPolygon aResult;
     433           0 :     sal_uInt32 nPointCount(0);
     434             : 
     435           0 :     for(sal_uInt32 a(0); !bNoPolygons && a < nMarkAnz; a++)
     436             :     {
     437           0 :         SdrMark* pM = getSdrDragView().GetSdrMarkByIndex(a);
     438             : 
     439           0 :         if(pM->GetPageView() == getSdrDragView().GetSdrPageView())
     440             :         {
     441           0 :             const basegfx::B2DPolyPolygon aNewPolyPolygon(pM->GetMarkedSdrObj()->TakeXorPoly());
     442             : 
     443           0 :             for(sal_uInt32 b(0); b < aNewPolyPolygon.count(); b++)
     444             :             {
     445           0 :                 nPointCount += aNewPolyPolygon.getB2DPolygon(b).count();
     446             :             }
     447             : 
     448           0 :             if(nPointCount > getSdrDragView().GetDragXorPointLimit())
     449             :             {
     450           0 :                 bNoPolygons = true;
     451             :             }
     452             : 
     453           0 :             if(!bNoPolygons)
     454             :             {
     455           0 :                 aResult.append(aNewPolyPolygon);
     456           0 :             }
     457             :         }
     458             :     }
     459             : 
     460           0 :     if(bNoPolygons)
     461             :     {
     462           0 :         const Rectangle aR(getSdrDragView().GetSdrPageView()->MarkSnap());
     463           0 :         const basegfx::B2DRange aNewRectangle(aR.Left(), aR.Top(), aR.Right(), aR.Bottom());
     464           0 :         basegfx::B2DPolygon aNewPolygon(basegfx::tools::createPolygonFromRect(aNewRectangle));
     465             : 
     466           0 :         aResult = basegfx::B2DPolyPolygon(basegfx::tools::expandToCurve(aNewPolygon));
     467             :     }
     468             : 
     469           0 :     if(aResult.count())
     470             :     {
     471           0 :         addSdrDragEntry(new SdrDragEntryPolyPolygon(aResult));
     472           0 :     }
     473           0 : }
     474             : 
     475           0 : void SdrDragMethod::createSdrDragEntries_PointDrag()
     476             : {
     477           0 :     const sal_uInt32 nMarkAnz(getSdrDragView().GetMarkedObjectCount());
     478           0 :     std::vector< basegfx::B2DPoint > aPositions;
     479             : 
     480           0 :     for(sal_uInt32 nm(0); nm < nMarkAnz; nm++)
     481             :     {
     482           0 :         SdrMark* pM = getSdrDragView().GetSdrMarkByIndex(nm);
     483             : 
     484           0 :         if(pM->GetPageView() == getSdrDragView().GetSdrPageView())
     485             :         {
     486           0 :             const SdrUShortCont* pPts = pM->GetMarkedPoints();
     487             : 
     488           0 :             if(pPts && !pPts->empty())
     489             :             {
     490           0 :                 const SdrObject* pObj = pM->GetMarkedSdrObj();
     491           0 :                 const SdrPathObj* pPath = dynamic_cast< const SdrPathObj* >(pObj);
     492             : 
     493           0 :                 if(pPath)
     494             :                 {
     495           0 :                     const basegfx::B2DPolyPolygon aPathXPP = pPath->GetPathPoly();
     496             : 
     497           0 :                     if(aPathXPP.count())
     498             :                     {
     499           0 :                         for(SdrUShortCont::const_iterator it = pPts->begin(); it != pPts->end(); ++it)
     500             :                         {
     501             :                             sal_uInt32 nPolyNum, nPointNum;
     502           0 :                             const sal_uInt16 nObjPt = *it;
     503             : 
     504           0 :                             if(sdr::PolyPolygonEditor::GetRelativePolyPoint(aPathXPP, nObjPt, nPolyNum, nPointNum))
     505             :                             {
     506           0 :                                 aPositions.push_back(aPathXPP.getB2DPolygon(nPolyNum).getB2DPoint(nPointNum));
     507             :                             }
     508             :                         }
     509           0 :                     }
     510             :                 }
     511             :             }
     512             :         }
     513             :     }
     514             : 
     515           0 :     if(!aPositions.empty())
     516             :     {
     517           0 :         addSdrDragEntry(new SdrDragEntryPointGlueDrag(aPositions, true));
     518           0 :     }
     519           0 : }
     520             : 
     521           0 : void SdrDragMethod::createSdrDragEntries_GlueDrag()
     522             : {
     523           0 :     const sal_uInt32 nMarkAnz(getSdrDragView().GetMarkedObjectCount());
     524           0 :     std::vector< basegfx::B2DPoint > aPositions;
     525             : 
     526           0 :     for(sal_uInt32 nm(0); nm < nMarkAnz; nm++)
     527             :     {
     528           0 :         SdrMark* pM = getSdrDragView().GetSdrMarkByIndex(nm);
     529             : 
     530           0 :         if(pM->GetPageView() == getSdrDragView().GetSdrPageView())
     531             :         {
     532           0 :             const SdrUShortCont* pPts = pM->GetMarkedGluePoints();
     533             : 
     534           0 :             if(pPts && !pPts->empty())
     535             :             {
     536           0 :                 const SdrObject* pObj = pM->GetMarkedSdrObj();
     537           0 :                 const SdrGluePointList* pGPL = pObj->GetGluePointList();
     538             : 
     539           0 :                 if(pGPL)
     540             :                 {
     541           0 :                     for(SdrUShortCont::const_iterator it = pPts->begin(); it != pPts->end(); ++it)
     542             :                     {
     543           0 :                         const sal_uInt16 nObjPt = *it;
     544           0 :                         const sal_uInt16 nGlueNum(pGPL->FindGluePoint(nObjPt));
     545             : 
     546           0 :                         if(SDRGLUEPOINT_NOTFOUND != nGlueNum)
     547             :                         {
     548           0 :                             const Point aPoint((*pGPL)[nGlueNum].GetAbsolutePos(*pObj));
     549           0 :                             aPositions.push_back(basegfx::B2DPoint(aPoint.X(), aPoint.Y()));
     550             :                         }
     551             :                     }
     552             :                 }
     553             :             }
     554             :         }
     555             :     }
     556             : 
     557           0 :     if(!aPositions.empty())
     558             :     {
     559           0 :         addSdrDragEntry(new SdrDragEntryPointGlueDrag(aPositions, false));
     560           0 :     }
     561           0 : }
     562             : 
     563           0 : void SdrDragMethod::ImpTakeDescriptionStr(sal_uInt16 nStrCacheID, OUString& rStr, sal_uInt16 nVal) const
     564             : {
     565           0 :     sal_uInt16 nOpt=0;
     566           0 :     if (IsDraggingPoints()) {
     567           0 :         nOpt=IMPSDR_POINTSDESCRIPTION;
     568           0 :     } else if (IsDraggingGluePoints()) {
     569           0 :         nOpt=IMPSDR_GLUEPOINTSDESCRIPTION;
     570             :     }
     571           0 :     getSdrDragView().ImpTakeDescriptionStr(nStrCacheID,rStr,nVal,nOpt);
     572           0 : }
     573             : 
     574           0 : SdrObject* SdrDragMethod::GetDragObj() const
     575             : {
     576           0 :     SdrObject* pObj=NULL;
     577           0 :     if (getSdrDragView().pDragHdl!=NULL) pObj=getSdrDragView().pDragHdl->GetObj();
     578           0 :     if (pObj==NULL) pObj=getSdrDragView().pMarkedObj;
     579           0 :     return pObj;
     580             : }
     581             : 
     582           0 : SdrPageView* SdrDragMethod::GetDragPV() const
     583             : {
     584           0 :     SdrPageView* pPV=NULL;
     585           0 :     if (getSdrDragView().pDragHdl!=NULL) pPV=getSdrDragView().pDragHdl->GetPageView();
     586           0 :     if (pPV==NULL) pPV=getSdrDragView().pMarkedPV;
     587           0 :     return pPV;
     588             : }
     589             : 
     590           0 : void SdrDragMethod::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
     591             : {
     592             :     // the original applies the transformation using TRGetBaseGeometry/TRSetBaseGeometry.
     593             :     // Later this should be the only needed one for linear transforms (not for SdrDragCrook and
     594             :     // SdrDragDistort, those are NOT linear). Currently, this can not yet be used since the
     595             :     // special handling of rotate/mirror due to the not-being-able to handle it in the old
     596             :     // drawinglayer stuff. Text would currently not correctly be mirrored in the preview.
     597           0 :     basegfx::B2DHomMatrix aObjectTransform;
     598           0 :     basegfx::B2DPolyPolygon aObjectPolyPolygon;
     599           0 :     bool bPolyUsed(rTarget.TRGetBaseGeometry(aObjectTransform, aObjectPolyPolygon));
     600             : 
     601             :     // apply transform to object transform
     602           0 :     aObjectTransform *= getCurrentTransformation();
     603             : 
     604           0 :     if(bPolyUsed)
     605             :     {
     606             :         // do something special since the object size is in the polygon
     607             :         // break up matrix to get the scale
     608           0 :         basegfx::B2DTuple aScale;
     609           0 :         basegfx::B2DTuple aTranslate;
     610             :         double fRotate, fShearX;
     611           0 :         aObjectTransform.decompose(aScale, aTranslate, fRotate, fShearX);
     612             : 
     613             :         // get polygon's position and size
     614           0 :         const basegfx::B2DRange aPolyRange(aObjectPolyPolygon.getB2DRange());
     615             : 
     616             :         // get the scaling factors (do not mirror, this is in the object transformation)
     617           0 :         const double fScaleX(fabs(aScale.getX()) / (basegfx::fTools::equalZero(aPolyRange.getWidth()) ? 1.0 : aPolyRange.getWidth()));
     618           0 :         const double fScaleY(fabs(aScale.getY()) / (basegfx::fTools::equalZero(aPolyRange.getHeight()) ? 1.0 : aPolyRange.getHeight()));
     619             : 
     620             :         // prepare transform matrix for polygon
     621             :         basegfx::B2DHomMatrix aPolyTransform(basegfx::tools::createTranslateB2DHomMatrix(
     622           0 :             -aPolyRange.getMinX(), -aPolyRange.getMinY()));
     623           0 :         aPolyTransform.scale(fScaleX, fScaleY);
     624             : 
     625             :         // transform the polygon
     626           0 :         aObjectPolyPolygon.transform(aPolyTransform);
     627             :     }
     628             : 
     629           0 :     rTarget.TRSetBaseGeometry(getCurrentTransformation() * aObjectTransform, aObjectPolyPolygon);
     630           0 : }
     631             : 
     632           0 : void SdrDragMethod::applyCurrentTransformationToPolyPolygon(basegfx::B2DPolyPolygon& rTarget)
     633             : {
     634             :     // original uses CurrentTransformation
     635           0 :     rTarget.transform(getCurrentTransformation());
     636           0 : }
     637             : 
     638           0 : SdrDragMethod::SdrDragMethod(SdrDragView& rNewView)
     639             : :   maSdrDragEntries(),
     640             :     maOverlayObjectList(),
     641             :     mrSdrDragView(rNewView),
     642             :     mbMoveOnly(false),
     643           0 :     mbSolidDraggingActive(getSdrDragView().IsSolidDragging())
     644             : {
     645           0 :     if(mbSolidDraggingActive && Application::GetSettings().GetStyleSettings().GetHighContrastMode())
     646             :     {
     647             :         // fallback to wireframe when high contrast is used
     648           0 :         mbSolidDraggingActive = false;
     649             :     }
     650           0 : }
     651             : 
     652           0 : SdrDragMethod::~SdrDragMethod()
     653             : {
     654           0 :     clearSdrDragEntries();
     655           0 : }
     656             : 
     657           0 : void SdrDragMethod::Show()
     658             : {
     659           0 :     getSdrDragView().ShowDragObj();
     660           0 : }
     661             : 
     662           0 : void SdrDragMethod::Hide()
     663             : {
     664           0 :     getSdrDragView().HideDragObj();
     665           0 : }
     666             : 
     667           0 : basegfx::B2DHomMatrix SdrDragMethod::getCurrentTransformation()
     668             : {
     669           0 :     return basegfx::B2DHomMatrix();
     670             : }
     671             : 
     672           0 : void SdrDragMethod::CancelSdrDrag()
     673             : {
     674           0 :     Hide();
     675           0 : }
     676             : 
     677             : struct compareConstSdrObjectRefs
     678             : {
     679           0 :     bool operator()(const SdrObject* p1, const SdrObject* p2) const
     680             :     {
     681           0 :         return (p1 < p2);
     682             :     }
     683             : };
     684             : 
     685             : typedef std::map< const SdrObject*, SdrObject*, compareConstSdrObjectRefs> SdrObjectAndCloneMap;
     686             : 
     687           0 : void SdrDragMethod::CreateOverlayGeometry(sdr::overlay::OverlayManager& rOverlayManager)
     688             : {
     689             :     // create SdrDragEntries on demand
     690           0 :     if(maSdrDragEntries.empty())
     691             :     {
     692           0 :         createSdrDragEntries();
     693             :     }
     694             : 
     695             :     // if there are entries, derive OverlayObjects from the entries, including
     696             :     // modification from current interactive state
     697           0 :     if(!maSdrDragEntries.empty())
     698             :     {
     699             :         // #i54102# SdrDragEntrySdrObject creates clones of SdrObjects as base for creating the needed
     700             :         // primitives, holding the original and the clone. If connectors (Edges) are involved,
     701             :         // the cloned connectors need to be connected to the cloned SdrObjects (after cloning
     702             :         // they are connected to the original SdrObjects). To do so, trigger the preparation
     703             :         // steps for SdrDragEntrySdrObject, save an association of (orig, clone) in a helper
     704             :         // and evtl. remember if it was an edge
     705           0 :         SdrObjectAndCloneMap aOriginalAndClones;
     706           0 :         std::vector< SdrEdgeObj* > aEdges;
     707             :         sal_uInt32 a;
     708             : 
     709             :         // #i54102# execute prepareCurrentState for all SdrDragEntrySdrObject, register pair of original and
     710             :         // clone, remember edges
     711           0 :         for(a = 0; a < maSdrDragEntries.size(); a++)
     712             :         {
     713           0 :             SdrDragEntrySdrObject* pSdrDragEntrySdrObject = dynamic_cast< SdrDragEntrySdrObject*>(maSdrDragEntries[a]);
     714             : 
     715           0 :             if(pSdrDragEntrySdrObject)
     716             :             {
     717           0 :                 pSdrDragEntrySdrObject->prepareCurrentState(*this);
     718             : 
     719           0 :                 SdrEdgeObj* pSdrEdgeObj = dynamic_cast< SdrEdgeObj* >(pSdrDragEntrySdrObject->getClone());
     720             : 
     721           0 :                 if(pSdrEdgeObj)
     722             :                 {
     723           0 :                     aEdges.push_back(pSdrEdgeObj);
     724             :                 }
     725             : 
     726           0 :                 if(pSdrDragEntrySdrObject->getClone())
     727             :                 {
     728           0 :                     aOriginalAndClones[&pSdrDragEntrySdrObject->getOriginal()] = pSdrDragEntrySdrObject->getClone();
     729             :                 }
     730             :             }
     731             :         }
     732             : 
     733             :         // #i54102# if there are edges, reconnect their ends to the corresponding clones (if found)
     734           0 :         if(aEdges.size())
     735             :         {
     736           0 :             for(a = 0; a < aEdges.size(); a++)
     737             :             {
     738           0 :                 SdrEdgeObj* pSdrEdgeObj = aEdges[a];
     739           0 :                 SdrObject* pConnectedTo = pSdrEdgeObj->GetConnectedNode(true);
     740             : 
     741           0 :                 if(pConnectedTo)
     742             :                 {
     743           0 :                     SdrObjectAndCloneMap::iterator aEntry = aOriginalAndClones.find(pConnectedTo);
     744             : 
     745           0 :                     if(aEntry != aOriginalAndClones.end())
     746             :                     {
     747           0 :                         pSdrEdgeObj->ConnectToNode(true, aEntry->second);
     748             :                     }
     749             :                 }
     750             : 
     751           0 :                 pConnectedTo = pSdrEdgeObj->GetConnectedNode(false);
     752             : 
     753           0 :                 if(pConnectedTo)
     754             :                 {
     755           0 :                     SdrObjectAndCloneMap::iterator aEntry = aOriginalAndClones.find(pConnectedTo);
     756             : 
     757           0 :                     if(aEntry != aOriginalAndClones.end())
     758             :                     {
     759           0 :                         pSdrEdgeObj->ConnectToNode(false, aEntry->second);
     760             :                     }
     761             :                 }
     762             :             }
     763             :         }
     764             : 
     765             :         // collect primitives for visualisation
     766           0 :         drawinglayer::primitive2d::Primitive2DSequence aResult;
     767           0 :         drawinglayer::primitive2d::Primitive2DSequence aResultTransparent;
     768             : 
     769           0 :         for(a = 0; a < maSdrDragEntries.size(); a++)
     770             :         {
     771           0 :             SdrDragEntry* pCandidate = maSdrDragEntries[a];
     772             : 
     773           0 :             if(pCandidate)
     774             :             {
     775           0 :                 const drawinglayer::primitive2d::Primitive2DSequence aCandidateResult(pCandidate->createPrimitive2DSequenceInCurrentState(*this));
     776             : 
     777           0 :                 if(aCandidateResult.hasElements())
     778             :                 {
     779           0 :                     if(pCandidate->getAddToTransparent())
     780             :                     {
     781           0 :                         drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(aResultTransparent, aCandidateResult);
     782             :                     }
     783             :                     else
     784             :                     {
     785           0 :                         drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(aResult, aCandidateResult);
     786             :                     }
     787           0 :                 }
     788             :             }
     789             :         }
     790             : 
     791           0 :         if(DoAddConnectorOverlays())
     792             :         {
     793           0 :             const drawinglayer::primitive2d::Primitive2DSequence aConnectorOverlays(AddConnectorOverlays());
     794             : 
     795           0 :             if(aConnectorOverlays.hasElements())
     796             :             {
     797             :                 // add connector overlays to transparent part
     798           0 :                 drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(aResultTransparent, aConnectorOverlays);
     799           0 :             }
     800             :         }
     801             : 
     802           0 :         if(aResult.hasElements())
     803             :         {
     804           0 :             sdr::overlay::OverlayObject* pNewOverlayObject = new sdr::overlay::OverlayPrimitive2DSequenceObject(aResult);
     805           0 :             rOverlayManager.add(*pNewOverlayObject);
     806           0 :             addToOverlayObjectList(*pNewOverlayObject);
     807             :         }
     808             : 
     809           0 :         if(aResultTransparent.hasElements())
     810             :         {
     811           0 :             drawinglayer::primitive2d::Primitive2DReference aUnifiedTransparencePrimitive2D(new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(aResultTransparent, 0.5));
     812           0 :             aResultTransparent = drawinglayer::primitive2d::Primitive2DSequence(&aUnifiedTransparencePrimitive2D, 1);
     813             : 
     814           0 :             sdr::overlay::OverlayObject* pNewOverlayObject = new sdr::overlay::OverlayPrimitive2DSequenceObject(aResultTransparent);
     815           0 :             rOverlayManager.add(*pNewOverlayObject);
     816           0 :             addToOverlayObjectList(*pNewOverlayObject);
     817           0 :         }
     818             :     }
     819             : 
     820             :     // add DragStripes if necessary (help lines cross the page when dragging)
     821           0 :     if(getSdrDragView().IsDragStripes())
     822             :     {
     823           0 :         Rectangle aActionRectangle;
     824           0 :         getSdrDragView().TakeActionRect(aActionRectangle);
     825             : 
     826           0 :         const basegfx::B2DPoint aTopLeft(aActionRectangle.Left(), aActionRectangle.Top());
     827           0 :         const basegfx::B2DPoint aBottomRight(aActionRectangle.Right(), aActionRectangle.Bottom());
     828             :         sdr::overlay::OverlayRollingRectangleStriped* pNew = new sdr::overlay::OverlayRollingRectangleStriped(
     829           0 :             aTopLeft, aBottomRight, true, false);
     830             : 
     831           0 :         rOverlayManager.add(*pNew);
     832           0 :         addToOverlayObjectList(*pNew);
     833             :     }
     834           0 : }
     835             : 
     836           0 : void SdrDragMethod::destroyOverlayGeometry()
     837             : {
     838           0 :     clearOverlayObjectList();
     839           0 : }
     840             : 
     841           0 : bool SdrDragMethod::DoAddConnectorOverlays()
     842             : {
     843             :     // these conditions are translated from SdrDragView::ImpDrawEdgeXor
     844           0 :     const SdrMarkList& rMarkedNodes = getSdrDragView().GetEdgesOfMarkedNodes();
     845             : 
     846           0 :     if(!rMarkedNodes.GetMarkCount())
     847             :     {
     848           0 :         return false;
     849             :     }
     850             : 
     851           0 :     if(!getSdrDragView().IsRubberEdgeDragging() && !getSdrDragView().IsDetailedEdgeDragging())
     852             :     {
     853           0 :         return false;
     854             :     }
     855             : 
     856           0 :     if(getSdrDragView().IsDraggingPoints() || getSdrDragView().IsDraggingGluePoints())
     857             :     {
     858           0 :         return false;
     859             :     }
     860             : 
     861           0 :     if(!getMoveOnly() && !(
     862           0 :         IS_TYPE(SdrDragMove, this) || IS_TYPE(SdrDragResize, this) ||
     863           0 :         IS_TYPE(SdrDragRotate,this) || IS_TYPE(SdrDragMirror,this)))
     864             :     {
     865           0 :         return false;
     866             :     }
     867             : 
     868           0 :     const bool bDetail(getSdrDragView().IsDetailedEdgeDragging() && getMoveOnly());
     869             : 
     870           0 :     if(!bDetail && !getSdrDragView().IsRubberEdgeDragging())
     871             :     {
     872           0 :         return false;
     873             :     }
     874             : 
     875             :     // one more migrated from SdrEdgeObj::NspToggleEdgeXor
     876           0 :     if(IS_TYPE(SdrDragObjOwn, this) || IS_TYPE(SdrDragMovHdl, this))
     877             :     {
     878           0 :         return false;
     879             :     }
     880             : 
     881           0 :     return true;
     882             : }
     883             : 
     884           0 : drawinglayer::primitive2d::Primitive2DSequence SdrDragMethod::AddConnectorOverlays()
     885             : {
     886           0 :     drawinglayer::primitive2d::Primitive2DSequence aRetval;
     887           0 :     const bool bDetail(getSdrDragView().IsDetailedEdgeDragging() && getMoveOnly());
     888           0 :     const SdrMarkList& rMarkedNodes = getSdrDragView().GetEdgesOfMarkedNodes();
     889             : 
     890           0 :     for(sal_uInt16 a(0); a < rMarkedNodes.GetMarkCount(); a++)
     891             :     {
     892           0 :         SdrMark* pEM = rMarkedNodes.GetMark(a);
     893             : 
     894           0 :         if(pEM && pEM->GetMarkedSdrObj())
     895             :         {
     896           0 :             SdrEdgeObj* pEdge = dynamic_cast< SdrEdgeObj* >(pEM->GetMarkedSdrObj());
     897             : 
     898           0 :             if(pEdge)
     899             :             {
     900           0 :                 const basegfx::B2DPolygon aEdgePolygon(pEdge->ImplAddConnectorOverlay(*this, pEM->IsCon1(), pEM->IsCon2(), bDetail));
     901             : 
     902           0 :                 if(aEdgePolygon.count())
     903             :                 {
     904             :                     // this polygon is a temporary calculated connector path, so it is not possible to fetch
     905             :                     // the needed primitives directly from the pEdge object which does not get changed. If full
     906             :                     // drag is on, use the SdrObjects ItemSet to create a adequate representation
     907           0 :                     bool bUseSolidDragging(getSolidDraggingActive());
     908             : 
     909           0 :                     if(bUseSolidDragging)
     910             :                     {
     911             :                         // switch off solid dragging if connector is not visible
     912           0 :                         if(!pEdge->HasLineStyle())
     913             :                         {
     914           0 :                             bUseSolidDragging = false;
     915             :                         }
     916             :                     }
     917             : 
     918           0 :                     if(bUseSolidDragging)
     919             :                     {
     920           0 :                         const SfxItemSet& rItemSet = pEdge->GetMergedItemSet();
     921             :                         const drawinglayer::attribute::SdrLineAttribute aLine(
     922           0 :                             drawinglayer::primitive2d::createNewSdrLineAttribute(rItemSet));
     923             : 
     924           0 :                         if(!aLine.isDefault())
     925             :                         {
     926             :                             const drawinglayer::attribute::SdrLineStartEndAttribute aLineStartEnd(
     927             :                                 drawinglayer::primitive2d::createNewSdrLineStartEndAttribute(
     928             :                                     rItemSet,
     929           0 :                                     aLine.getWidth()));
     930             : 
     931             :                             drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(
     932             :                                 aRetval, drawinglayer::primitive2d::createPolygonLinePrimitive(
     933             :                                     aEdgePolygon,
     934             :                                     aLine,
     935           0 :                                     aLineStartEnd));
     936           0 :                         }
     937             :                     }
     938             :                     else
     939             :                     {
     940           0 :                         const SvtOptionsDrawinglayer aSvtOptionsDrawinglayer;
     941           0 :                         basegfx::BColor aColA(aSvtOptionsDrawinglayer.GetStripeColorA().getBColor());
     942           0 :                         basegfx::BColor aColB(aSvtOptionsDrawinglayer.GetStripeColorB().getBColor());
     943           0 :                         const double fStripeLength(aSvtOptionsDrawinglayer.GetStripeLength());
     944             : 
     945           0 :                         if(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
     946             :                         {
     947           0 :                             aColA = aColB = Application::GetSettings().GetStyleSettings().GetHighlightColor().getBColor();
     948           0 :                             aColB.invert();
     949             :                         }
     950             : 
     951             :                         drawinglayer::primitive2d::Primitive2DReference aPolyPolygonMarkerPrimitive2D(
     952             :                             new drawinglayer::primitive2d::PolygonMarkerPrimitive2D(
     953           0 :                                 aEdgePolygon, aColA, aColB, fStripeLength));
     954           0 :                         drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aPolyPolygonMarkerPrimitive2D);
     955             :                     }
     956           0 :                 }
     957             :             }
     958             :         }
     959             :     }
     960             : 
     961           0 :     return aRetval;
     962             : }
     963             : 
     964             : 
     965             : 
     966           0 : TYPEINIT1(SdrDragMovHdl,SdrDragMethod);
     967             : 
     968           0 : SdrDragMovHdl::SdrDragMovHdl(SdrDragView& rNewView)
     969           0 : :   SdrDragMethod(rNewView)
     970             : {
     971           0 : }
     972             : 
     973           0 : void SdrDragMovHdl::createSdrDragEntries()
     974             : {
     975             :     // SdrDragMovHdl does not use the default drags,
     976             :     // but creates nothing
     977           0 : }
     978             : 
     979           0 : void SdrDragMovHdl::TakeSdrDragComment(OUString& rStr) const
     980             : {
     981           0 :     rStr=ImpGetResStr(STR_DragMethMovHdl);
     982           0 :     if (getSdrDragView().IsDragWithCopy()) rStr+=ImpGetResStr(STR_EditWithCopy);
     983           0 : }
     984             : 
     985           0 : bool SdrDragMovHdl::BeginSdrDrag()
     986             : {
     987           0 :     if( !GetDragHdl() )
     988           0 :         return false;
     989             : 
     990           0 :     DragStat().Ref1()=GetDragHdl()->GetPos();
     991           0 :     DragStat().SetShown(!DragStat().IsShown());
     992           0 :     SdrHdlKind eKind=GetDragHdl()->GetKind();
     993           0 :     SdrHdl* pH1=GetHdlList().GetHdl(HDL_REF1);
     994           0 :     SdrHdl* pH2=GetHdlList().GetHdl(HDL_REF2);
     995             : 
     996           0 :     if (eKind==HDL_MIRX)
     997             :     {
     998           0 :         if (pH1==NULL || pH2==NULL)
     999             :         {
    1000             :             OSL_FAIL("SdrDragMovHdl::BeginSdrDrag(): Moving the axis of reflection: reference handles not found.");
    1001           0 :             return false;
    1002             :         }
    1003             : 
    1004           0 :         DragStat().SetActionRect(Rectangle(pH1->GetPos(),pH2->GetPos()));
    1005             :     }
    1006             :     else
    1007             :     {
    1008           0 :         Point aPt(GetDragHdl()->GetPos());
    1009           0 :         DragStat().SetActionRect(Rectangle(aPt,aPt));
    1010             :     }
    1011             : 
    1012           0 :     return true;
    1013             : }
    1014             : 
    1015           0 : void SdrDragMovHdl::MoveSdrDrag(const Point& rNoSnapPnt)
    1016             : {
    1017           0 :     Point aPnt(rNoSnapPnt);
    1018             : 
    1019           0 :     if ( GetDragHdl() && DragStat().CheckMinMoved(rNoSnapPnt))
    1020             :     {
    1021           0 :         if (GetDragHdl()->GetKind()==HDL_MIRX)
    1022             :         {
    1023           0 :             SdrHdl* pH1=GetHdlList().GetHdl(HDL_REF1);
    1024           0 :             SdrHdl* pH2=GetHdlList().GetHdl(HDL_REF2);
    1025             : 
    1026           0 :             if (pH1==NULL || pH2==NULL)
    1027           0 :                 return;
    1028             : 
    1029           0 :             if (!DragStat().IsNoSnap())
    1030             :             {
    1031           0 :                 long nBestXSnap=0;
    1032           0 :                 long nBestYSnap=0;
    1033           0 :                 bool bXSnapped=false;
    1034           0 :                 bool bYSnapped=false;
    1035           0 :                 Point aDif(aPnt-DragStat().GetStart());
    1036           0 :                 getSdrDragView().CheckSnap(Ref1()+aDif,NULL,nBestXSnap,nBestYSnap,bXSnapped,bYSnapped);
    1037           0 :                 getSdrDragView().CheckSnap(Ref2()+aDif,NULL,nBestXSnap,nBestYSnap,bXSnapped,bYSnapped);
    1038           0 :                 aPnt.X()+=nBestXSnap;
    1039           0 :                 aPnt.Y()+=nBestYSnap;
    1040             :             }
    1041             : 
    1042           0 :             if (aPnt!=DragStat().GetNow())
    1043             :             {
    1044           0 :                 Hide();
    1045           0 :                 DragStat().NextMove(aPnt);
    1046           0 :                 Point aDif(DragStat().GetNow()-DragStat().GetStart());
    1047           0 :                 pH1->SetPos(Ref1()+aDif);
    1048           0 :                 pH2->SetPos(Ref2()+aDif);
    1049             : 
    1050           0 :                 SdrHdl* pHM = GetHdlList().GetHdl(HDL_MIRX);
    1051             : 
    1052           0 :                 if(pHM)
    1053           0 :                     pHM->Touch();
    1054             : 
    1055           0 :                 Show();
    1056           0 :                 DragStat().SetActionRect(Rectangle(pH1->GetPos(),pH2->GetPos()));
    1057             :             }
    1058             :         }
    1059             :         else
    1060             :         {
    1061           0 :             if (!DragStat().IsNoSnap()) SnapPos(aPnt);
    1062           0 :             long nSA=0;
    1063             : 
    1064           0 :             if (getSdrDragView().IsAngleSnapEnabled())
    1065           0 :                 nSA=getSdrDragView().GetSnapAngle();
    1066             : 
    1067           0 :             if (getSdrDragView().IsMirrorAllowed(true,true))
    1068             :             { // limited
    1069           0 :                 if (!getSdrDragView().IsMirrorAllowed(false,false)) nSA=4500;
    1070           0 :                 if (!getSdrDragView().IsMirrorAllowed(true,false)) nSA=9000;
    1071             :             }
    1072             : 
    1073           0 :             if (getSdrDragView().IsOrtho() && nSA!=9000)
    1074           0 :                 nSA=4500;
    1075             : 
    1076           0 :             if (nSA!=0)
    1077             :             { // angle snapping
    1078           0 :                 SdrHdlKind eRef=HDL_REF1;
    1079             : 
    1080           0 :                 if (GetDragHdl()->GetKind()==HDL_REF1)
    1081           0 :                     eRef=HDL_REF2;
    1082             : 
    1083           0 :                 SdrHdl* pH=GetHdlList().GetHdl(eRef);
    1084             : 
    1085           0 :                 if (pH!=NULL)
    1086             :                 {
    1087           0 :                     Point aRef(pH->GetPos());
    1088           0 :                     long nWink=NormAngle360(GetAngle(aPnt-aRef));
    1089           0 :                     long nNeuWink=nWink;
    1090           0 :                     nNeuWink+=nSA/2;
    1091           0 :                     nNeuWink/=nSA;
    1092           0 :                     nNeuWink*=nSA;
    1093           0 :                     nNeuWink=NormAngle360(nNeuWink);
    1094           0 :                     double a=(nNeuWink-nWink)*nPi180;
    1095           0 :                     double nSin=sin(a);
    1096           0 :                     double nCos=cos(a);
    1097           0 :                     RotatePoint(aPnt,aRef,nSin,nCos);
    1098             : 
    1099             :                     // eliminate rounding errors for certain values
    1100           0 :                     if (nSA==9000)
    1101             :                     {
    1102           0 :                         if (nNeuWink==0    || nNeuWink==18000) aPnt.Y()=aRef.Y();
    1103           0 :                         if (nNeuWink==9000 || nNeuWink==27000) aPnt.X()=aRef.X();
    1104             :                     }
    1105             : 
    1106           0 :                     if (nSA==4500)
    1107           0 :                         OrthoDistance8(aRef,aPnt,true);
    1108             :                 }
    1109             :             }
    1110             : 
    1111           0 :             if (aPnt!=DragStat().GetNow())
    1112             :             {
    1113           0 :                 Hide();
    1114           0 :                 DragStat().NextMove(aPnt);
    1115           0 :                 GetDragHdl()->SetPos(DragStat().GetNow());
    1116           0 :                 SdrHdl* pHM = GetHdlList().GetHdl(HDL_MIRX);
    1117             : 
    1118           0 :                 if(pHM)
    1119           0 :                     pHM->Touch();
    1120             : 
    1121           0 :                 Show();
    1122           0 :                 DragStat().SetActionRect(Rectangle(aPnt,aPnt));
    1123             :             }
    1124             :         }
    1125             :     }
    1126             : }
    1127             : 
    1128           0 : bool SdrDragMovHdl::EndSdrDrag(bool /*bCopy*/)
    1129             : {
    1130           0 :     if( GetDragHdl() )
    1131             :     {
    1132           0 :         switch (GetDragHdl()->GetKind())
    1133             :         {
    1134             :             case HDL_REF1:
    1135           0 :                 Ref1()=DragStat().GetNow();
    1136           0 :                 break;
    1137             : 
    1138             :             case HDL_REF2:
    1139           0 :                 Ref2()=DragStat().GetNow();
    1140           0 :                 break;
    1141             : 
    1142             :             case HDL_MIRX:
    1143           0 :                 Ref1()+=DragStat().GetNow()-DragStat().GetStart();
    1144           0 :                 Ref2()+=DragStat().GetNow()-DragStat().GetStart();
    1145           0 :                 break;
    1146             : 
    1147           0 :             default: break;
    1148             :         }
    1149             :     }
    1150             : 
    1151           0 :     return true;
    1152             : }
    1153             : 
    1154           0 : void SdrDragMovHdl::CancelSdrDrag()
    1155             : {
    1156           0 :     Hide();
    1157             : 
    1158           0 :     SdrHdl* pHdl = GetDragHdl();
    1159           0 :     if( pHdl )
    1160           0 :         pHdl->SetPos(DragStat().GetRef1());
    1161             : 
    1162           0 :     SdrHdl* pHM = GetHdlList().GetHdl(HDL_MIRX);
    1163             : 
    1164           0 :     if(pHM)
    1165           0 :         pHM->Touch();
    1166           0 : }
    1167             : 
    1168           0 : Pointer SdrDragMovHdl::GetSdrDragPointer() const
    1169             : {
    1170           0 :     const SdrHdl* pHdl = GetDragHdl();
    1171             : 
    1172           0 :     if (pHdl!=NULL)
    1173             :     {
    1174           0 :         return pHdl->GetPointer();
    1175             :     }
    1176             : 
    1177           0 :     return Pointer(POINTER_REFHAND);
    1178             : }
    1179             : 
    1180             : 
    1181             : 
    1182           0 : TYPEINIT1(SdrDragObjOwn,SdrDragMethod);
    1183             : 
    1184           0 : SdrDragObjOwn::SdrDragObjOwn(SdrDragView& rNewView)
    1185             : :   SdrDragMethod(rNewView),
    1186           0 :     mpClone(0)
    1187             : {
    1188           0 :     const SdrObject* pObj = GetDragObj();
    1189             : 
    1190           0 :     if(pObj)
    1191             :     {
    1192             :         // suppress full drag for some object types
    1193           0 :         setSolidDraggingActive(pObj->supportsFullDrag());
    1194             :     }
    1195           0 : }
    1196             : 
    1197           0 : SdrDragObjOwn::~SdrDragObjOwn()
    1198             : {
    1199           0 :     if(mpClone)
    1200             :     {
    1201           0 :         SdrObject::Free(mpClone);
    1202             :     }
    1203           0 : }
    1204             : 
    1205           0 : void SdrDragObjOwn::createSdrDragEntries()
    1206             : {
    1207           0 :     if(mpClone)
    1208             :     {
    1209           0 :         basegfx::B2DPolyPolygon aDragPolyPolygon;
    1210           0 :         bool bAddWireframe(true);
    1211             : 
    1212           0 :         if(getSolidDraggingActive())
    1213             :         {
    1214           0 :             SdrPageView* pPV = getSdrDragView().GetSdrPageView();
    1215             : 
    1216           0 :             if(pPV && pPV->PageWindowCount())
    1217             :             {
    1218           0 :                 sdr::contact::ObjectContact& rOC = pPV->GetPageWindow(0)->GetObjectContact();
    1219           0 :                 addSdrDragEntry(new SdrDragEntrySdrObject(*mpClone, rOC, false));
    1220             : 
    1221             :                 // potentially no wireframe needed, full drag works
    1222           0 :                 bAddWireframe = false;
    1223             :             }
    1224             :         }
    1225             : 
    1226           0 :         if(!bAddWireframe)
    1227             :         {
    1228             :             // check for extra conditions for wireframe, e.g. no border at
    1229             :             // objects
    1230           0 :             if(!mpClone->HasLineStyle())
    1231             :             {
    1232           0 :                 bAddWireframe = true;
    1233             :             }
    1234             :         }
    1235             : 
    1236           0 :         if(bAddWireframe)
    1237             :         {
    1238             :             // use wireframe poly when full drag is off or did not work
    1239           0 :             aDragPolyPolygon = mpClone->TakeXorPoly();
    1240             :         }
    1241             : 
    1242             :         // add evtl. extra DragPolyPolygon
    1243           0 :         const basegfx::B2DPolyPolygon aSpecialDragPolyPolygon(mpClone->getSpecialDragPoly(DragStat()));
    1244             : 
    1245           0 :         if(aSpecialDragPolyPolygon.count())
    1246             :         {
    1247           0 :             aDragPolyPolygon.append(aSpecialDragPolyPolygon);
    1248             :         }
    1249             : 
    1250           0 :         if(aDragPolyPolygon.count())
    1251             :         {
    1252           0 :             addSdrDragEntry(new SdrDragEntryPolyPolygon(aDragPolyPolygon));
    1253           0 :         }
    1254             :     }
    1255           0 : }
    1256             : 
    1257           0 : void SdrDragObjOwn::TakeSdrDragComment(OUString& rStr) const
    1258             : {
    1259             :     // #i103058# get info string from the clone preferred, the original will
    1260             :     // not be changed. For security, use original as fallback
    1261           0 :     if(mpClone)
    1262             :     {
    1263           0 :         rStr = mpClone->getSpecialDragComment(DragStat());
    1264             :     }
    1265             :     else
    1266             :     {
    1267           0 :         const SdrObject* pObj = GetDragObj();
    1268             : 
    1269           0 :         if(pObj)
    1270             :         {
    1271           0 :             rStr = pObj->getSpecialDragComment(DragStat());
    1272             :         }
    1273             :     }
    1274           0 : }
    1275             : 
    1276           0 : bool SdrDragObjOwn::BeginSdrDrag()
    1277             : {
    1278           0 :     if(!mpClone)
    1279             :     {
    1280           0 :         const SdrObject* pObj = GetDragObj();
    1281             : 
    1282           0 :         if(pObj && !pObj->IsResizeProtect())
    1283             :         {
    1284           0 :             if(pObj->beginSpecialDrag(DragStat()))
    1285             :             {
    1286             :                 // create initial clone to have a start visualization
    1287           0 :                 mpClone = pObj->getFullDragClone();
    1288           0 :                 mpClone->applySpecialDrag(DragStat());
    1289             : 
    1290           0 :                 return true;
    1291             :             }
    1292             :         }
    1293             :     }
    1294             : 
    1295           0 :     return false;
    1296             : }
    1297             : 
    1298           0 : void SdrDragObjOwn::MoveSdrDrag(const Point& rNoSnapPnt)
    1299             : {
    1300           0 :     const SdrObject* pObj = GetDragObj();
    1301             : 
    1302           0 :     if(pObj)
    1303             :     {
    1304           0 :         Point aPnt(rNoSnapPnt);
    1305           0 :         SdrPageView* pPV = GetDragPV();
    1306             : 
    1307           0 :         if(pPV)
    1308             :         {
    1309           0 :             if(!DragStat().IsNoSnap())
    1310             :             {
    1311           0 :                 SnapPos(aPnt);
    1312             :             }
    1313             : 
    1314           0 :             if(getSdrDragView().IsOrtho())
    1315             :             {
    1316           0 :                 if (DragStat().IsOrtho8Possible())
    1317             :                 {
    1318           0 :                     OrthoDistance8(DragStat().GetStart(),aPnt,getSdrDragView().IsBigOrtho());
    1319             :                 }
    1320           0 :                 else if (DragStat().IsOrtho4Possible())
    1321             :                 {
    1322           0 :                     OrthoDistance4(DragStat().GetStart(),aPnt,getSdrDragView().IsBigOrtho());
    1323             :                 }
    1324             :             }
    1325             : 
    1326           0 :             if(DragStat().CheckMinMoved(rNoSnapPnt))
    1327             :             {
    1328           0 :                 if(aPnt != DragStat().GetNow())
    1329             :                 {
    1330           0 :                     Hide();
    1331           0 :                     DragStat().NextMove(aPnt);
    1332             : 
    1333             :                     // since SdrDragObjOwn currently supports no transformation of
    1334             :                     // existing SdrDragEntries but only their recreation, a recreation
    1335             :                     // after every move is needed in this mode. Delete existing
    1336             :                     // SdrDragEntries here  to force their recreation in the following Show().
    1337           0 :                     clearSdrDragEntries();
    1338             : 
    1339             :                     // delete current clone (after the last reference to it is deleted above)
    1340           0 :                     if(mpClone)
    1341             :                     {
    1342           0 :                         SdrObject::Free(mpClone);
    1343           0 :                         mpClone = 0;
    1344             :                     }
    1345             : 
    1346             :                     // create a new clone and modify to current drag state
    1347           0 :                     if(!mpClone)
    1348             :                     {
    1349           0 :                         mpClone = pObj->getFullDragClone();
    1350           0 :                         mpClone->applySpecialDrag(DragStat());
    1351             : 
    1352             :                         // #120999# AutoGrowWidth may change for SdrTextObj due to the automatism used
    1353             :                         // with bDisableAutoWidthOnDragging, so not only geometry changes but
    1354             :                         // also this (pretty indirect) property change is possible. If it gets
    1355             :                         // changed, it needs to be copied to the original since nothing will
    1356             :                         // happen when it only changes in the drag clone
    1357           0 :                         const bool bOldAutoGrowWidth(((SdrTextAutoGrowWidthItem&)pObj->GetMergedItem(SDRATTR_TEXT_AUTOGROWWIDTH)).GetValue());
    1358           0 :                         const bool bNewAutoGrowWidth(((SdrTextAutoGrowWidthItem&)mpClone->GetMergedItem(SDRATTR_TEXT_AUTOGROWWIDTH)).GetValue());
    1359             : 
    1360           0 :                         if(bOldAutoGrowWidth != bNewAutoGrowWidth)
    1361             :                         {
    1362           0 :                             GetDragObj()->SetMergedItem(SdrTextAutoGrowWidthItem(bNewAutoGrowWidth));
    1363             :                         }
    1364             :                     }
    1365             : 
    1366           0 :                     Show();
    1367             :                 }
    1368             :             }
    1369             :         }
    1370             :     }
    1371           0 : }
    1372             : 
    1373           0 : bool SdrDragObjOwn::EndSdrDrag(bool /*bCopy*/)
    1374             : {
    1375           0 :     Hide();
    1376           0 :     std::vector< SdrUndoAction* > vConnectorUndoActions;
    1377           0 :     bool bRet = false;
    1378           0 :     SdrObject* pObj = GetDragObj();
    1379             : 
    1380           0 :     if(pObj)
    1381             :     {
    1382           0 :         SdrUndoAction* pUndo = NULL;
    1383           0 :         SdrUndoAction* pUndo2 = NULL;
    1384           0 :         const bool bUndo = getSdrDragView().IsUndoEnabled();
    1385             : 
    1386           0 :         if( bUndo )
    1387             :         {
    1388           0 :             if(!getSdrDragView().IsInsObjPoint() && pObj->IsInserted() )
    1389             :             {
    1390           0 :                 if (DragStat().IsEndDragChangesAttributes())
    1391             :                 {
    1392           0 :                     pUndo=getSdrDragView().GetModel()->GetSdrUndoFactory().CreateUndoAttrObject(*pObj);
    1393             : 
    1394           0 :                     if (DragStat().IsEndDragChangesGeoAndAttributes())
    1395             :                     {
    1396           0 :                         vConnectorUndoActions = getSdrDragView().CreateConnectorUndo( *pObj );
    1397           0 :                         pUndo2 = getSdrDragView().GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj);
    1398             :                     }
    1399             :                 }
    1400             :                 else
    1401             :                 {
    1402           0 :                     vConnectorUndoActions = getSdrDragView().CreateConnectorUndo( *pObj );
    1403           0 :                     pUndo= getSdrDragView().GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj);
    1404             :                 }
    1405             :             }
    1406             : 
    1407           0 :             if( pUndo )
    1408             :             {
    1409           0 :                 getSdrDragView().BegUndo( pUndo->GetComment() );
    1410             :             }
    1411             :             else
    1412             :             {
    1413           0 :                 getSdrDragView().BegUndo();
    1414             :             }
    1415             :         }
    1416             : 
    1417             :         // Maybe use operator = for setting changed object data (do not change selection in
    1418             :         // view, this will destroy the interactor). This is possible since a clone is now
    1419             :         // directly modified by the modifiers. Only SdrTableObj is adding own UNDOs
    1420             :         // in its SdrTableObj::endSpecialDrag, so currently not possible. OTOH it uses
    1421             :         // a CreateUndoGeoObject(), so maybe setting SetEndDragChangesAttributes is okay. I
    1422             :         // will test this now
    1423           0 :         Rectangle aBoundRect0;
    1424             : 
    1425           0 :         if(pObj->GetUserCall())
    1426             :         {
    1427           0 :             aBoundRect0 = pObj->GetLastBoundRect();
    1428             :         }
    1429             : 
    1430           0 :         bRet = pObj->applySpecialDrag(DragStat());
    1431             : 
    1432           0 :         if(bRet)
    1433             :         {
    1434           0 :             pObj->SetChanged();
    1435           0 :             pObj->BroadcastObjectChange();
    1436           0 :             pObj->SendUserCall( SDRUSERCALL_RESIZE, aBoundRect0 );
    1437             :         }
    1438             : 
    1439           0 :         if(bRet)
    1440             :         {
    1441           0 :             if( bUndo )
    1442             :             {
    1443           0 :                 getSdrDragView().AddUndoActions( vConnectorUndoActions );
    1444             : 
    1445           0 :                 if ( pUndo )
    1446             :                 {
    1447           0 :                     getSdrDragView().AddUndo(pUndo);
    1448             :                 }
    1449             : 
    1450           0 :                 if ( pUndo2 )
    1451             :                 {
    1452           0 :                     getSdrDragView().AddUndo(pUndo2);
    1453             :                 }
    1454             :             }
    1455             :         }
    1456             :         else
    1457             :         {
    1458           0 :             if( bUndo )
    1459             :             {
    1460           0 :                 std::vector< SdrUndoAction* >::iterator vConnectorUndoIter( vConnectorUndoActions.begin() );
    1461             : 
    1462           0 :                 while( vConnectorUndoIter != vConnectorUndoActions.end() )
    1463             :                 {
    1464           0 :                     delete *vConnectorUndoIter++;
    1465             :                 }
    1466             : 
    1467           0 :                 delete pUndo;
    1468           0 :                 delete pUndo2;
    1469             :             }
    1470             :         }
    1471             : 
    1472           0 :         if( bUndo )
    1473           0 :             getSdrDragView().EndUndo();
    1474             :     }
    1475             : 
    1476           0 :     return bRet;
    1477             : }
    1478             : 
    1479           0 : Pointer SdrDragObjOwn::GetSdrDragPointer() const
    1480             : {
    1481           0 :     const SdrHdl* pHdl=GetDragHdl();
    1482             : 
    1483           0 :     if (pHdl)
    1484             :     {
    1485           0 :         return pHdl->GetPointer();
    1486             :     }
    1487             : 
    1488           0 :     return Pointer(POINTER_MOVE);
    1489             : }
    1490             : 
    1491             : 
    1492             : 
    1493           0 : TYPEINIT1(SdrDragMove,SdrDragMethod);
    1494             : 
    1495           0 : void SdrDragMove::createSdrDragEntryForSdrObject(const SdrObject& rOriginal, sdr::contact::ObjectContact& rObjectContact, bool /*bModify*/)
    1496             : {
    1497             :     // for SdrDragMove, use current Primitive2DSequence of SdrObject visualization
    1498             :     // in given ObjectContact directly
    1499           0 :     sdr::contact::ViewContact& rVC = rOriginal.GetViewContact();
    1500           0 :     sdr::contact::ViewObjectContact& rVOC = rVC.GetViewObjectContact(rObjectContact);
    1501           0 :     sdr::contact::DisplayInfo aDisplayInfo;
    1502             : 
    1503             :     // Do not use the last ViewPort set at the OC from the last ProcessDisplay(),
    1504             :     // here we want the complete primitive sequence without visible clippings
    1505           0 :     rObjectContact.resetViewPort();
    1506             : 
    1507           0 :     addSdrDragEntry(new SdrDragEntryPrimitive2DSequence(rVOC.getPrimitive2DSequenceHierarchy(aDisplayInfo), true));
    1508           0 : }
    1509             : 
    1510           0 : void SdrDragMove::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
    1511             : {
    1512           0 :     rTarget.Move(Size(DragStat().GetDX(), DragStat().GetDY()));
    1513           0 : }
    1514             : 
    1515           0 : SdrDragMove::SdrDragMove(SdrDragView& rNewView)
    1516           0 : :   SdrDragMethod(rNewView)
    1517             : {
    1518           0 :     setMoveOnly(true);
    1519           0 : }
    1520             : 
    1521           0 : void SdrDragMove::TakeSdrDragComment(OUString& rStr) const
    1522             : {
    1523           0 :     OUString aStr;
    1524             : 
    1525           0 :     ImpTakeDescriptionStr(STR_DragMethMove, rStr);
    1526           0 :     rStr += " (x=";
    1527           0 :     getSdrDragView().GetModel()->TakeMetricStr(DragStat().GetDX(), aStr);
    1528           0 :     rStr += aStr + " y=";
    1529           0 :     getSdrDragView().GetModel()->TakeMetricStr(DragStat().GetDY(), aStr);
    1530           0 :     rStr += aStr + ")";
    1531             : 
    1532           0 :     if(getSdrDragView().IsDragWithCopy())
    1533             :     {
    1534           0 :         if(!getSdrDragView().IsInsObjPoint() && !getSdrDragView().IsInsGluePoint())
    1535             :         {
    1536           0 :             rStr += ImpGetResStr(STR_EditWithCopy);
    1537             :         }
    1538           0 :     }
    1539           0 : }
    1540             : 
    1541           0 : bool SdrDragMove::BeginSdrDrag()
    1542             : {
    1543           0 :     DragStat().SetActionRect(GetMarkedRect());
    1544           0 :     Show();
    1545             : 
    1546           0 :     return true;
    1547             : }
    1548             : 
    1549           0 : basegfx::B2DHomMatrix SdrDragMove::getCurrentTransformation()
    1550             : {
    1551           0 :     return basegfx::tools::createTranslateB2DHomMatrix(DragStat().GetDX(), DragStat().GetDY());
    1552             : }
    1553             : 
    1554           0 : void SdrDragMove::ImpCheckSnap(const Point& rPt)
    1555             : {
    1556           0 :     Point aPt(rPt);
    1557           0 :     sal_uInt16 nRet=SnapPos(aPt);
    1558           0 :     aPt-=rPt;
    1559             : 
    1560           0 :     if ((nRet & SDRSNAP_XSNAPPED) !=0)
    1561             :     {
    1562           0 :         if (bXSnapped)
    1563             :         {
    1564           0 :             if (std::abs(aPt.X())<std::abs(nBestXSnap))
    1565             :             {
    1566           0 :                 nBestXSnap=aPt.X();
    1567             :             }
    1568             :         }
    1569             :         else
    1570             :         {
    1571           0 :             nBestXSnap=aPt.X();
    1572           0 :             bXSnapped=true;
    1573             :         }
    1574             :     }
    1575             : 
    1576           0 :     if ((nRet & SDRSNAP_YSNAPPED) !=0)
    1577             :     {
    1578           0 :         if (bYSnapped)
    1579             :         {
    1580           0 :             if (std::abs(aPt.Y())<std::abs(nBestYSnap))
    1581             :             {
    1582           0 :                 nBestYSnap=aPt.Y();
    1583             :             }
    1584             :         }
    1585             :         else
    1586             :         {
    1587           0 :             nBestYSnap=aPt.Y();
    1588           0 :             bYSnapped=true;
    1589             :         }
    1590             :     }
    1591           0 : }
    1592             : 
    1593           0 : void SdrDragMove::MoveSdrDrag(const Point& rNoSnapPnt_)
    1594             : {
    1595           0 :     nBestXSnap=0;
    1596           0 :     nBestYSnap=0;
    1597           0 :     bXSnapped=false;
    1598           0 :     bYSnapped=false;
    1599           0 :     Point aNoSnapPnt(rNoSnapPnt_);
    1600           0 :     const Rectangle& aSR=GetMarkedRect();
    1601           0 :     long nMovedx=aNoSnapPnt.X()-DragStat().GetStart().X();
    1602           0 :     long nMovedy=aNoSnapPnt.Y()-DragStat().GetStart().Y();
    1603           0 :     Point aLO(aSR.TopLeft());      aLO.X()+=nMovedx; aLO.Y()+=nMovedy;
    1604           0 :     Point aRU(aSR.BottomRight());  aRU.X()+=nMovedx; aRU.Y()+=nMovedy;
    1605           0 :     Point aLU(aLO.X(),aRU.Y());
    1606           0 :     Point aRO(aRU.X(),aLO.Y());
    1607           0 :     ImpCheckSnap(aLO);
    1608             : 
    1609           0 :     if (!getSdrDragView().IsMoveSnapOnlyTopLeft())
    1610             :     {
    1611           0 :         ImpCheckSnap(aRO);
    1612           0 :         ImpCheckSnap(aLU);
    1613           0 :         ImpCheckSnap(aRU);
    1614             :     }
    1615             : 
    1616           0 :     Point aPnt(aNoSnapPnt.X()+nBestXSnap,aNoSnapPnt.Y()+nBestYSnap);
    1617           0 :     bool bOrtho=getSdrDragView().IsOrtho();
    1618             : 
    1619           0 :     if (bOrtho)
    1620           0 :         OrthoDistance8(DragStat().GetStart(),aPnt,getSdrDragView().IsBigOrtho());
    1621             : 
    1622           0 :     if (DragStat().CheckMinMoved(aNoSnapPnt))
    1623             :     {
    1624           0 :         Point aPt1(aPnt);
    1625           0 :         Rectangle aLR(getSdrDragView().GetWorkArea());
    1626           0 :         bool bWorkArea=!aLR.IsEmpty();
    1627           0 :         bool bDragLimit=IsDragLimit();
    1628             : 
    1629           0 :         if (bDragLimit || bWorkArea)
    1630             :         {
    1631           0 :             Rectangle aSR2(GetMarkedRect());
    1632           0 :             Point aD(aPt1-DragStat().GetStart());
    1633             : 
    1634           0 :             if (bDragLimit)
    1635             :             {
    1636           0 :                 Rectangle aR2(GetDragLimitRect());
    1637             : 
    1638           0 :                 if (bWorkArea)
    1639           0 :                     aLR.Intersection(aR2);
    1640             :                 else
    1641           0 :                     aLR=aR2;
    1642             :             }
    1643             : 
    1644           0 :             if (aSR2.Left()>aLR.Left() || aSR2.Right()<aLR.Right())
    1645             :             { // any space to move to?
    1646           0 :                 aSR2.Move(aD.X(),0);
    1647             : 
    1648           0 :                 if (aSR2.Left()<aLR.Left())
    1649             :                 {
    1650           0 :                     aPt1.X()-=aSR2.Left()-aLR.Left();
    1651             :                 }
    1652           0 :                 else if (aSR2.Right()>aLR.Right())
    1653             :                 {
    1654           0 :                     aPt1.X()-=aSR2.Right()-aLR.Right();
    1655             :                 }
    1656             :             }
    1657             :             else
    1658           0 :                 aPt1.X()=DragStat().GetStart().X(); // no space to move to
    1659             : 
    1660           0 :             if (aSR2.Top()>aLR.Top() || aSR2.Bottom()<aLR.Bottom())
    1661             :             { // any space to move to?
    1662           0 :                 aSR2.Move(0,aD.Y());
    1663             : 
    1664           0 :                 if (aSR2.Top()<aLR.Top())
    1665             :                 {
    1666           0 :                     aPt1.Y()-=aSR2.Top()-aLR.Top();
    1667             :                 }
    1668           0 :                 else if (aSR2.Bottom()>aLR.Bottom())
    1669             :                 {
    1670           0 :                     aPt1.Y()-=aSR2.Bottom()-aLR.Bottom();
    1671             :                 }
    1672             :             }
    1673             :             else
    1674           0 :                 aPt1.Y()=DragStat().GetStart().Y(); // no space to move to
    1675             :         }
    1676             : 
    1677           0 :         if (getSdrDragView().IsDraggingGluePoints())
    1678             :         { // restrict glue points to the BoundRect of the Obj
    1679           0 :             aPt1-=DragStat().GetStart();
    1680           0 :             const SdrMarkList& rML=GetMarkedObjectList();
    1681           0 :             sal_uLong nMarkAnz=rML.GetMarkCount();
    1682             : 
    1683           0 :             for (sal_uLong nMarkNum=0; nMarkNum<nMarkAnz; nMarkNum++)
    1684             :             {
    1685           0 :                 const SdrMark* pM=rML.GetMark(nMarkNum);
    1686           0 :                 const SdrUShortCont* pPts=pM->GetMarkedGluePoints();
    1687           0 :                 sal_uLong nPtAnz=pPts==NULL ? 0 : pPts->size();
    1688             : 
    1689           0 :                 if (nPtAnz!=0)
    1690             :                 {
    1691           0 :                     const SdrObject* pObj=pM->GetMarkedSdrObj();
    1692           0 :                     const SdrGluePointList* pGPL=pObj->GetGluePointList();
    1693           0 :                     Rectangle aBound(pObj->GetCurrentBoundRect());
    1694             : 
    1695           0 :                     for (SdrUShortCont::const_iterator it = pPts->begin(); it != pPts->end(); ++it)
    1696             :                     {
    1697           0 :                         sal_uInt16 nId = *it;
    1698           0 :                         sal_uInt16 nGlueNum=pGPL->FindGluePoint(nId);
    1699             : 
    1700           0 :                         if (nGlueNum!=SDRGLUEPOINT_NOTFOUND)
    1701             :                         {
    1702           0 :                             Point aPt((*pGPL)[nGlueNum].GetAbsolutePos(*pObj));
    1703           0 :                             aPt+=aPt1; // move by this much
    1704           0 :                             if (aPt.X()<aBound.Left()  ) aPt1.X()-=aPt.X()-aBound.Left()  ;
    1705           0 :                             if (aPt.X()>aBound.Right() ) aPt1.X()-=aPt.X()-aBound.Right() ;
    1706           0 :                             if (aPt.Y()<aBound.Top()   ) aPt1.Y()-=aPt.Y()-aBound.Top()   ;
    1707           0 :                             if (aPt.Y()>aBound.Bottom()) aPt1.Y()-=aPt.Y()-aBound.Bottom();
    1708             :                         }
    1709             :                     }
    1710             :                 }
    1711             :             }
    1712             : 
    1713           0 :             aPt1+=DragStat().GetStart();
    1714             :         }
    1715             : 
    1716           0 :         if (bOrtho)
    1717           0 :             OrthoDistance8(DragStat().GetStart(),aPt1,false);
    1718             : 
    1719           0 :         if (aPt1!=DragStat().GetNow())
    1720             :         {
    1721           0 :             Hide();
    1722           0 :             DragStat().NextMove(aPt1);
    1723           0 :             Rectangle aAction(GetMarkedRect());
    1724           0 :             aAction.Move(DragStat().GetDX(),DragStat().GetDY());
    1725           0 :             DragStat().SetActionRect(aAction);
    1726           0 :             Show();
    1727             :         }
    1728             :     }
    1729           0 : }
    1730             : 
    1731           0 : bool SdrDragMove::EndSdrDrag(bool bCopy)
    1732             : {
    1733           0 :     Hide();
    1734             : 
    1735           0 :     if (getSdrDragView().IsInsObjPoint() || getSdrDragView().IsInsGluePoint())
    1736           0 :         bCopy=false;
    1737             : 
    1738           0 :     if (IsDraggingPoints())
    1739             :     {
    1740           0 :         getSdrDragView().MoveMarkedPoints(Size(DragStat().GetDX(),DragStat().GetDY()),bCopy);
    1741             :     }
    1742           0 :     else if (IsDraggingGluePoints())
    1743             :     {
    1744           0 :         getSdrDragView().MoveMarkedGluePoints(Size(DragStat().GetDX(),DragStat().GetDY()),bCopy);
    1745             :     }
    1746             :     else
    1747             :     {
    1748           0 :         getSdrDragView().MoveMarkedObj(Size(DragStat().GetDX(),DragStat().GetDY()),bCopy);
    1749             :     }
    1750             : 
    1751           0 :     return true;
    1752             : }
    1753             : 
    1754           0 : Pointer SdrDragMove::GetSdrDragPointer() const
    1755             : {
    1756           0 :     if (IsDraggingPoints() || IsDraggingGluePoints())
    1757             :     {
    1758           0 :         return Pointer(POINTER_MOVEPOINT);
    1759             :     }
    1760             :     else
    1761             :     {
    1762           0 :         return Pointer(POINTER_MOVE);
    1763             :     }
    1764             : }
    1765             : 
    1766             : 
    1767             : 
    1768           0 : TYPEINIT1(SdrDragResize,SdrDragMethod);
    1769             : 
    1770           0 : SdrDragResize::SdrDragResize(SdrDragView& rNewView)
    1771             : :   SdrDragMethod(rNewView),
    1772             :     aXFact(1,1),
    1773           0 :     aYFact(1,1)
    1774             : {
    1775           0 : }
    1776             : 
    1777           0 : void SdrDragResize::TakeSdrDragComment(OUString& rStr) const
    1778             : {
    1779           0 :     ImpTakeDescriptionStr(STR_DragMethResize, rStr);
    1780           0 :     Fraction aFact1(1,1);
    1781           0 :     Point aStart(DragStat().GetStart());
    1782           0 :     Point aRef(DragStat().GetRef1());
    1783           0 :     sal_Int32 nXDiv(aStart.X() - aRef.X());
    1784             : 
    1785           0 :     if(!nXDiv)
    1786           0 :         nXDiv = 1;
    1787             : 
    1788           0 :     sal_Int32 nYDiv(aStart.Y() - aRef.Y());
    1789             : 
    1790           0 :     if(!nYDiv)
    1791           0 :         nYDiv = 1;
    1792             : 
    1793           0 :     bool bX(aXFact != aFact1 && std::abs(nXDiv) > 1);
    1794           0 :     bool bY(aYFact != aFact1 && std::abs(nYDiv) > 1);
    1795             : 
    1796           0 :     if(bX || bY)
    1797             :     {
    1798           0 :         OUString aStr;
    1799             : 
    1800           0 :         rStr += " (";
    1801             : 
    1802           0 :         bool bEqual(aXFact == aYFact);
    1803           0 :         if(bX)
    1804             :         {
    1805           0 :             if(!bEqual)
    1806           0 :                 rStr += "x=";
    1807             : 
    1808           0 :             getSdrDragView().GetModel()->TakePercentStr(aXFact, aStr);
    1809           0 :             rStr += aStr;
    1810             :         }
    1811             : 
    1812           0 :         if(bY && !bEqual)
    1813             :         {
    1814           0 :             if(bX)
    1815           0 :                 rStr += " ";
    1816             : 
    1817           0 :             rStr += "y=";
    1818           0 :             getSdrDragView().GetModel()->TakePercentStr(aYFact, aStr);
    1819           0 :             rStr += aStr;
    1820             :         }
    1821             : 
    1822           0 :         rStr += ")";
    1823             :     }
    1824             : 
    1825           0 :     if(getSdrDragView().IsDragWithCopy())
    1826           0 :         rStr += ImpGetResStr(STR_EditWithCopy);
    1827           0 : }
    1828             : 
    1829           0 : bool SdrDragResize::BeginSdrDrag()
    1830             : {
    1831           0 :     SdrHdlKind eRefHdl=HDL_MOVE;
    1832           0 :     SdrHdl* pRefHdl=NULL;
    1833             : 
    1834           0 :     switch (GetDragHdlKind())
    1835             :     {
    1836           0 :         case HDL_UPLFT: eRefHdl=HDL_LWRGT; break;
    1837           0 :         case HDL_UPPER: eRefHdl=HDL_LOWER; DragStat().SetHorFixed(true); break;
    1838           0 :         case HDL_UPRGT: eRefHdl=HDL_LWLFT; break;
    1839           0 :         case HDL_LEFT : eRefHdl=HDL_RIGHT; DragStat().SetVerFixed(true); break;
    1840           0 :         case HDL_RIGHT: eRefHdl=HDL_LEFT ; DragStat().SetVerFixed(true); break;
    1841           0 :         case HDL_LWLFT: eRefHdl=HDL_UPRGT; break;
    1842           0 :         case HDL_LOWER: eRefHdl=HDL_UPPER; DragStat().SetHorFixed(true); break;
    1843           0 :         case HDL_LWRGT: eRefHdl=HDL_UPLFT; break;
    1844           0 :         default: break;
    1845             :     }
    1846             : 
    1847           0 :     if (eRefHdl!=HDL_MOVE)
    1848           0 :         pRefHdl=GetHdlList().GetHdl(eRefHdl);
    1849             : 
    1850           0 :     if (pRefHdl!=NULL && !getSdrDragView().IsResizeAtCenter())
    1851             :     {
    1852             :         // Calc hack to adjust for calc grid
    1853           0 :         DragStat().Ref1()=pRefHdl->GetPos() - getSdrDragView().GetGridOffset();
    1854             :     }
    1855             :     else
    1856             :     {
    1857           0 :         SdrHdl* pRef1=GetHdlList().GetHdl(HDL_UPLFT);
    1858           0 :         SdrHdl* pRef2=GetHdlList().GetHdl(HDL_LWRGT);
    1859             : 
    1860           0 :         if (pRef1!=NULL && pRef2!=NULL)
    1861             :         {
    1862           0 :             DragStat().Ref1()=Rectangle(pRef1->GetPos(),pRef2->GetPos()).Center();
    1863             :         }
    1864             :         else
    1865             :         {
    1866           0 :             DragStat().Ref1()=GetMarkedRect().Center();
    1867             :         }
    1868             :     }
    1869             : 
    1870           0 :     Show();
    1871             : 
    1872           0 :     return true;
    1873             : }
    1874             : 
    1875           0 : basegfx::B2DHomMatrix SdrDragResize::getCurrentTransformation()
    1876             : {
    1877             :     basegfx::B2DHomMatrix aRetval(basegfx::tools::createTranslateB2DHomMatrix(
    1878           0 :         -DragStat().Ref1().X(), -DragStat().Ref1().Y()));
    1879           0 :     aRetval.scale(aXFact, aYFact);
    1880           0 :     aRetval.translate(DragStat().Ref1().X(), DragStat().Ref1().Y());
    1881             : 
    1882           0 :     return aRetval;
    1883             : }
    1884             : 
    1885           0 : void SdrDragResize::MoveSdrDrag(const Point& rNoSnapPnt)
    1886             : {
    1887           0 :     Point aPnt(GetSnapPos(rNoSnapPnt));
    1888           0 :     Point aStart(DragStat().GetStart());
    1889           0 :     Point aRef(DragStat().GetRef1());
    1890           0 :     Fraction aMaxFact(0x7FFFFFFF,1);
    1891           0 :     Rectangle aLR(getSdrDragView().GetWorkArea());
    1892           0 :     bool bWorkArea=!aLR.IsEmpty();
    1893           0 :     bool bDragLimit=IsDragLimit();
    1894             : 
    1895           0 :     if (bDragLimit || bWorkArea)
    1896             :     {
    1897           0 :         Rectangle aSR(GetMarkedRect());
    1898             : 
    1899           0 :         if (bDragLimit)
    1900             :         {
    1901           0 :             Rectangle aR2(GetDragLimitRect());
    1902             : 
    1903           0 :             if (bWorkArea)
    1904           0 :                 aLR.Intersection(aR2);
    1905             :             else
    1906           0 :                 aLR=aR2;
    1907             :         }
    1908             : 
    1909           0 :         if (aPnt.X()<aLR.Left())
    1910           0 :             aPnt.X()=aLR.Left();
    1911           0 :         else if (aPnt.X()>aLR.Right())
    1912           0 :             aPnt.X()=aLR.Right();
    1913             : 
    1914           0 :         if (aPnt.Y()<aLR.Top())
    1915           0 :             aPnt.Y()=aLR.Top();
    1916           0 :         else if (aPnt.Y()>aLR.Bottom())
    1917           0 :             aPnt.Y()=aLR.Bottom();
    1918             : 
    1919           0 :         if (aRef.X()>aSR.Left())
    1920             :         {
    1921           0 :             Fraction aMax(aRef.X()-aLR.Left(),aRef.X()-aSR.Left());
    1922             : 
    1923           0 :             if (aMax<aMaxFact)
    1924           0 :                 aMaxFact=aMax;
    1925             :         }
    1926             : 
    1927           0 :         if (aRef.X()<aSR.Right())
    1928             :         {
    1929           0 :             Fraction aMax(aLR.Right()-aRef.X(),aSR.Right()-aRef.X());
    1930             : 
    1931           0 :             if (aMax<aMaxFact)
    1932           0 :                 aMaxFact=aMax;
    1933             :         }
    1934             : 
    1935           0 :         if (aRef.Y()>aSR.Top())
    1936             :         {
    1937           0 :             Fraction aMax(aRef.Y()-aLR.Top(),aRef.Y()-aSR.Top());
    1938             : 
    1939           0 :             if (aMax<aMaxFact)
    1940           0 :                 aMaxFact=aMax;
    1941             :         }
    1942             : 
    1943           0 :         if (aRef.Y()<aSR.Bottom())
    1944             :         {
    1945           0 :             Fraction aMax(aLR.Bottom()-aRef.Y(),aSR.Bottom()-aRef.Y());
    1946             : 
    1947           0 :             if (aMax<aMaxFact)
    1948           0 :                 aMaxFact=aMax;
    1949             :         }
    1950             :     }
    1951             : 
    1952           0 :     long nXDiv=aStart.X()-aRef.X(); if (nXDiv==0) nXDiv=1;
    1953           0 :     long nYDiv=aStart.Y()-aRef.Y(); if (nYDiv==0) nYDiv=1;
    1954           0 :     long nXMul=aPnt.X()-aRef.X();
    1955           0 :     long nYMul=aPnt.Y()-aRef.Y();
    1956             : 
    1957           0 :     if (nXDiv<0)
    1958             :     {
    1959           0 :         nXDiv=-nXDiv;
    1960           0 :         nXMul=-nXMul;
    1961             :     }
    1962             : 
    1963           0 :     if (nYDiv<0)
    1964             :     {
    1965           0 :         nYDiv=-nYDiv;
    1966           0 :         nYMul=-nYMul;
    1967             :     }
    1968             : 
    1969           0 :     bool bXNeg=nXMul<0; if (bXNeg) nXMul=-nXMul;
    1970           0 :     bool bYNeg=nYMul<0; if (bYNeg) nYMul=-nYMul;
    1971           0 :     bool bOrtho=getSdrDragView().IsOrtho() || !getSdrDragView().IsResizeAllowed(false);
    1972             : 
    1973           0 :     if (!DragStat().IsHorFixed() && !DragStat().IsVerFixed())
    1974             :     {
    1975           0 :         if (std::abs(nXDiv)<=1 || std::abs(nYDiv)<=1)
    1976           0 :             bOrtho=false;
    1977             : 
    1978           0 :         if (bOrtho)
    1979             :         {
    1980           0 :             if ((Fraction(nXMul,nXDiv)>Fraction(nYMul,nYDiv)) !=getSdrDragView().IsBigOrtho())
    1981             :             {
    1982           0 :                 nXMul=nYMul;
    1983           0 :                 nXDiv=nYDiv;
    1984             :             }
    1985             :             else
    1986             :             {
    1987           0 :                 nYMul=nXMul;
    1988           0 :                 nYDiv=nXDiv;
    1989             :             }
    1990             :         }
    1991             :     }
    1992             :     else
    1993             :     {
    1994           0 :         if (bOrtho)
    1995             :         {
    1996           0 :             if (DragStat().IsHorFixed())
    1997             :             {
    1998           0 :                 bXNeg=false;
    1999           0 :                 nXMul=nYMul;
    2000           0 :                 nXDiv=nYDiv;
    2001             :             }
    2002             : 
    2003           0 :             if (DragStat().IsVerFixed())
    2004             :             {
    2005           0 :                 bYNeg=false;
    2006           0 :                 nYMul=nXMul;
    2007           0 :                 nYDiv=nXDiv;
    2008             :             }
    2009             :         }
    2010             :         else
    2011             :         {
    2012           0 :             if (DragStat().IsHorFixed())
    2013             :             {
    2014           0 :                 bXNeg=false;
    2015           0 :                 nXMul=1;
    2016           0 :                 nXDiv=1;
    2017             :             }
    2018             : 
    2019           0 :             if (DragStat().IsVerFixed())
    2020             :             {
    2021           0 :                 bYNeg=false;
    2022           0 :                 nYMul=1;
    2023           0 :                 nYDiv=1;
    2024             :             }
    2025             :         }
    2026             :     }
    2027             : 
    2028           0 :     Fraction aNeuXFact(nXMul,nXDiv);
    2029           0 :     Fraction aNeuYFact(nYMul,nYDiv);
    2030             : 
    2031           0 :     if (bOrtho)
    2032             :     {
    2033           0 :         if (aNeuXFact>aMaxFact)
    2034             :         {
    2035           0 :             aNeuXFact=aMaxFact;
    2036           0 :             aNeuYFact=aMaxFact;
    2037             :         }
    2038             : 
    2039           0 :         if (aNeuYFact>aMaxFact)
    2040             :         {
    2041           0 :             aNeuXFact=aMaxFact;
    2042           0 :             aNeuYFact=aMaxFact;
    2043             :         }
    2044             :     }
    2045             : 
    2046           0 :     if (bXNeg)
    2047           0 :         aNeuXFact=Fraction(-aNeuXFact.GetNumerator(),aNeuXFact.GetDenominator());
    2048             : 
    2049           0 :     if (bYNeg)
    2050           0 :         aNeuYFact=Fraction(-aNeuYFact.GetNumerator(),aNeuYFact.GetDenominator());
    2051             : 
    2052           0 :     if (DragStat().CheckMinMoved(aPnt))
    2053             :     {
    2054           0 :         if ((!DragStat().IsHorFixed() && aPnt.X()!=DragStat().GetNow().X()) ||
    2055           0 :             (!DragStat().IsVerFixed() && aPnt.Y()!=DragStat().GetNow().Y()))
    2056             :         {
    2057           0 :             Hide();
    2058           0 :             DragStat().NextMove(aPnt);
    2059           0 :             aXFact=aNeuXFact;
    2060           0 :             aYFact=aNeuYFact;
    2061           0 :             Show();
    2062             :         }
    2063             :     }
    2064           0 : }
    2065             : 
    2066           0 : void SdrDragResize::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
    2067             : {
    2068           0 :     rTarget.Resize(DragStat().Ref1(),aXFact,aYFact);
    2069           0 : }
    2070             : 
    2071           0 : bool SdrDragResize::EndSdrDrag(bool bCopy)
    2072             : {
    2073           0 :     Hide();
    2074             : 
    2075           0 :     if (IsDraggingPoints())
    2076             :     {
    2077           0 :         getSdrDragView().ResizeMarkedPoints(DragStat().Ref1(),aXFact,aYFact,bCopy);
    2078             :     }
    2079           0 :     else if (IsDraggingGluePoints())
    2080             :     {
    2081           0 :         getSdrDragView().ResizeMarkedGluePoints(DragStat().Ref1(),aXFact,aYFact,bCopy);
    2082             :     }
    2083             :     else
    2084             :     {
    2085           0 :         getSdrDragView().ResizeMarkedObj(DragStat().Ref1(),aXFact,aYFact,bCopy);
    2086             :     }
    2087             : 
    2088           0 :     return true;
    2089             : }
    2090             : 
    2091           0 : Pointer SdrDragResize::GetSdrDragPointer() const
    2092             : {
    2093           0 :     const SdrHdl* pHdl=GetDragHdl();
    2094             : 
    2095           0 :     if (pHdl!=NULL)
    2096             :     {
    2097           0 :         return pHdl->GetPointer();
    2098             :     }
    2099             : 
    2100           0 :     return Pointer(POINTER_MOVE);
    2101             : }
    2102             : 
    2103             : 
    2104             : 
    2105           0 : TYPEINIT1(SdrDragRotate,SdrDragMethod);
    2106             : 
    2107           0 : void SdrDragRotate::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
    2108             : {
    2109           0 :     rTarget.Rotate(DragStat().GetRef1(), nWink, sin(nWink*nPi180), cos(nWink*nPi180));
    2110           0 : }
    2111             : 
    2112           0 : SdrDragRotate::SdrDragRotate(SdrDragView& rNewView)
    2113             : :   SdrDragMethod(rNewView),
    2114             :     nSin(0.0),
    2115             :     nCos(1.0),
    2116             :     nWink0(0),
    2117             :     nWink(0),
    2118           0 :     bRight(false)
    2119             : {
    2120           0 : }
    2121             : 
    2122           0 : void SdrDragRotate::TakeSdrDragComment(OUString& rStr) const
    2123             : {
    2124           0 :     ImpTakeDescriptionStr(STR_DragMethRotate, rStr);
    2125           0 :     rStr += " (";
    2126           0 :     sal_Int32 nTmpWink(NormAngle360(nWink));
    2127             : 
    2128           0 :     if(bRight && nWink)
    2129             :     {
    2130           0 :         nTmpWink -= 36000;
    2131             :     }
    2132             : 
    2133           0 :     OUString aStr;
    2134           0 :     getSdrDragView().GetModel()->TakeWinkStr(nTmpWink, aStr);
    2135           0 :     rStr += aStr + ")";
    2136             : 
    2137           0 :     if(getSdrDragView().IsDragWithCopy())
    2138           0 :         rStr += ImpGetResStr(STR_EditWithCopy);
    2139           0 : }
    2140             : 
    2141           0 : bool SdrDragRotate::BeginSdrDrag()
    2142             : {
    2143           0 :     SdrHdl* pH=GetHdlList().GetHdl(HDL_REF1);
    2144             : 
    2145           0 :     if (pH!=NULL)
    2146             :     {
    2147           0 :         Show();
    2148           0 :         DragStat().Ref1()=pH->GetPos();
    2149           0 :         nWink0=GetAngle(DragStat().GetStart()-DragStat().GetRef1());
    2150           0 :         return true;
    2151             :     }
    2152             :     else
    2153             :     {
    2154             :         OSL_FAIL("SdrDragRotate::BeginSdrDrag(): No reference point handle found.");
    2155           0 :         return false;
    2156             :     }
    2157             : }
    2158             : 
    2159           0 : basegfx::B2DHomMatrix SdrDragRotate::getCurrentTransformation()
    2160             : {
    2161             :     return basegfx::tools::createRotateAroundPoint(
    2162           0 :         DragStat().GetRef1().X(), DragStat().GetRef1().Y(),
    2163           0 :         -atan2(nSin, nCos));
    2164             : }
    2165             : 
    2166           0 : void SdrDragRotate::MoveSdrDrag(const Point& rPnt_)
    2167             : {
    2168           0 :     Point aPnt(rPnt_);
    2169           0 :     if (DragStat().CheckMinMoved(aPnt))
    2170             :     {
    2171           0 :         long nNeuWink=NormAngle360(GetAngle(aPnt-DragStat().GetRef1())-nWink0);
    2172           0 :         long nSA=0;
    2173             : 
    2174           0 :         if (getSdrDragView().IsAngleSnapEnabled())
    2175           0 :             nSA=getSdrDragView().GetSnapAngle();
    2176             : 
    2177           0 :         if (!getSdrDragView().IsRotateAllowed(false))
    2178           0 :             nSA=9000;
    2179             : 
    2180           0 :         if (nSA!=0)
    2181             :         { // angle snapping
    2182           0 :             nNeuWink+=nSA/2;
    2183           0 :             nNeuWink/=nSA;
    2184           0 :             nNeuWink*=nSA;
    2185             :         }
    2186             : 
    2187           0 :         nNeuWink=NormAngle180(nNeuWink);
    2188             : 
    2189           0 :         if (nWink!=nNeuWink)
    2190             :         {
    2191           0 :             sal_uInt16 nSekt0=GetAngleSector(nWink);
    2192           0 :             sal_uInt16 nSekt1=GetAngleSector(nNeuWink);
    2193             : 
    2194           0 :             if (nSekt0==0 && nSekt1==3)
    2195           0 :                 bRight=true;
    2196             : 
    2197           0 :             if (nSekt0==3 && nSekt1==0)
    2198           0 :                 bRight=false;
    2199             : 
    2200           0 :             nWink=nNeuWink;
    2201           0 :             double a=nWink*nPi180;
    2202           0 :             double nSin1=sin(a); // calculate now, so as little time as possible
    2203           0 :             double nCos1=cos(a); // passes between Hide() and Show()
    2204           0 :             Hide();
    2205           0 :             nSin=nSin1;
    2206           0 :             nCos=nCos1;
    2207           0 :             DragStat().NextMove(aPnt);
    2208           0 :             Show();
    2209             :         }
    2210             :     }
    2211           0 : }
    2212             : 
    2213           0 : bool SdrDragRotate::EndSdrDrag(bool bCopy)
    2214             : {
    2215           0 :     Hide();
    2216             : 
    2217           0 :     if (nWink!=0)
    2218             :     {
    2219           0 :         if (IsDraggingPoints())
    2220             :         {
    2221           0 :             getSdrDragView().RotateMarkedPoints(DragStat().GetRef1(),nWink,bCopy);
    2222             :         }
    2223           0 :         else if (IsDraggingGluePoints())
    2224             :         {
    2225           0 :             getSdrDragView().RotateMarkedGluePoints(DragStat().GetRef1(),nWink,bCopy);
    2226             :         }
    2227             :         else
    2228             :         {
    2229           0 :             getSdrDragView().RotateMarkedObj(DragStat().GetRef1(),nWink,bCopy);
    2230             :         }
    2231             :     }
    2232           0 :     return true;
    2233             : }
    2234             : 
    2235           0 : Pointer SdrDragRotate::GetSdrDragPointer() const
    2236             : {
    2237           0 :     return Pointer(POINTER_ROTATE);
    2238             : }
    2239             : 
    2240             : 
    2241             : 
    2242           0 : TYPEINIT1(SdrDragShear,SdrDragMethod);
    2243             : 
    2244           0 : SdrDragShear::SdrDragShear(SdrDragView& rNewView, bool bSlant1)
    2245             : :   SdrDragMethod(rNewView),
    2246             :     aFact(1,1),
    2247             :     nWink0(0),
    2248             :     nWink(0),
    2249             :     nTan(0.0),
    2250             :     bVertical(false),
    2251             :     bResize(false),
    2252             :     bUpSideDown(false),
    2253           0 :     bSlant(bSlant1)
    2254             : {
    2255           0 : }
    2256             : 
    2257           0 : void SdrDragShear::TakeSdrDragComment(OUString& rStr) const
    2258             : {
    2259           0 :     ImpTakeDescriptionStr(STR_DragMethShear, rStr);
    2260           0 :     rStr += " (";
    2261             : 
    2262           0 :     sal_Int32 nTmpWink(nWink);
    2263             : 
    2264           0 :     if(bUpSideDown)
    2265           0 :         nTmpWink += 18000;
    2266             : 
    2267           0 :     nTmpWink = NormAngle180(nTmpWink);
    2268             : 
    2269           0 :     OUString aStr;
    2270           0 :     getSdrDragView().GetModel()->TakeWinkStr(nTmpWink, aStr);
    2271           0 :     rStr += aStr + ")";
    2272             : 
    2273           0 :     if(getSdrDragView().IsDragWithCopy())
    2274           0 :         rStr += ImpGetResStr(STR_EditWithCopy);
    2275           0 : }
    2276             : 
    2277           0 : bool SdrDragShear::BeginSdrDrag()
    2278             : {
    2279           0 :     SdrHdlKind eRefHdl=HDL_MOVE;
    2280           0 :     SdrHdl* pRefHdl=NULL;
    2281             : 
    2282           0 :     switch (GetDragHdlKind())
    2283             :     {
    2284           0 :         case HDL_UPPER: eRefHdl=HDL_LOWER; break;
    2285           0 :         case HDL_LOWER: eRefHdl=HDL_UPPER; break;
    2286           0 :         case HDL_LEFT : eRefHdl=HDL_RIGHT; bVertical=true; break;
    2287           0 :         case HDL_RIGHT: eRefHdl=HDL_LEFT ; bVertical=true; break;
    2288           0 :         default: break;
    2289             :     }
    2290             : 
    2291           0 :     if (eRefHdl!=HDL_MOVE)
    2292           0 :         pRefHdl=GetHdlList().GetHdl(eRefHdl);
    2293             : 
    2294           0 :     if (pRefHdl!=NULL)
    2295             :     {
    2296           0 :         DragStat().Ref1()=pRefHdl->GetPos();
    2297           0 :         nWink0=GetAngle(DragStat().GetStart()-DragStat().GetRef1());
    2298             :     }
    2299             :     else
    2300             :     {
    2301             :         OSL_FAIL("SdrDragShear::BeginSdrDrag(): No reference point handle for shearing found.");
    2302           0 :         return false;
    2303             :     }
    2304             : 
    2305           0 :     Show();
    2306           0 :     return true;
    2307             : }
    2308             : 
    2309           0 : basegfx::B2DHomMatrix SdrDragShear::getCurrentTransformation()
    2310             : {
    2311             :     basegfx::B2DHomMatrix aRetval(basegfx::tools::createTranslateB2DHomMatrix(
    2312           0 :         -DragStat().GetRef1().X(), -DragStat().GetRef1().Y()));
    2313             : 
    2314           0 :     if (bResize)
    2315             :     {
    2316           0 :         if (bVertical)
    2317             :         {
    2318           0 :             aRetval.scale(aFact, 1.0);
    2319           0 :             aRetval.shearY(-nTan);
    2320             :         }
    2321             :         else
    2322             :         {
    2323           0 :             aRetval.scale(1.0, aFact);
    2324           0 :             aRetval.shearX(-nTan);
    2325             :         }
    2326             :     }
    2327             : 
    2328           0 :     aRetval.translate(DragStat().GetRef1().X(), DragStat().GetRef1().Y());
    2329             : 
    2330           0 :     return aRetval;
    2331             : }
    2332             : 
    2333           0 : void SdrDragShear::MoveSdrDrag(const Point& rPnt)
    2334             : {
    2335           0 :     if (DragStat().CheckMinMoved(rPnt))
    2336             :     {
    2337           0 :         bResize=!getSdrDragView().IsOrtho();
    2338           0 :         long nSA=0;
    2339             : 
    2340           0 :         if (getSdrDragView().IsAngleSnapEnabled())
    2341           0 :             nSA=getSdrDragView().GetSnapAngle();
    2342             : 
    2343           0 :         Point aP0(DragStat().GetStart());
    2344           0 :         Point aPnt(rPnt);
    2345           0 :         Fraction aNeuFact(1,1);
    2346             : 
    2347             :         // if angle snapping not activated, snap to raster (except when using slant)
    2348           0 :         if (nSA==0 && !bSlant)
    2349           0 :             aPnt=GetSnapPos(aPnt);
    2350             : 
    2351           0 :         if (!bSlant && !bResize)
    2352             :         { // shear, but no resize
    2353           0 :             if (bVertical)
    2354           0 :                 aPnt.X()=aP0.X();
    2355             :             else
    2356           0 :                 aPnt.Y()=aP0.Y();
    2357             :         }
    2358             : 
    2359           0 :         Point aRef(DragStat().GetRef1());
    2360           0 :         Point aDif(aPnt-aRef);
    2361             : 
    2362           0 :         long nNeuWink=0;
    2363             : 
    2364           0 :         if (bSlant)
    2365             :         {
    2366           0 :             nNeuWink=NormAngle180(-(GetAngle(aDif)-nWink0));
    2367             : 
    2368           0 :             if (bVertical)
    2369           0 :                 nNeuWink=NormAngle180(-nNeuWink);
    2370             :         }
    2371             :         else
    2372             :         {
    2373           0 :             if (bVertical)
    2374           0 :                 nNeuWink=NormAngle180(GetAngle(aDif));
    2375             :             else
    2376           0 :                 nNeuWink=NormAngle180(-(GetAngle(aDif)-9000));
    2377             : 
    2378           0 :             if (nNeuWink<-9000 || nNeuWink>9000)
    2379           0 :                 nNeuWink=NormAngle180(nNeuWink+18000);
    2380             : 
    2381           0 :             if (bResize)
    2382             :             {
    2383           0 :                 Point aPt2(aPnt);
    2384             : 
    2385           0 :                 if (nSA!=0)
    2386           0 :                     aPt2=GetSnapPos(aPnt); // snap this one in any case
    2387             : 
    2388           0 :                 if (bVertical)
    2389             :                 {
    2390           0 :                     aNeuFact=Fraction(aPt2.X()-aRef.X(),aP0.X()-aRef.X());
    2391             :                 }
    2392             :                 else
    2393             :                 {
    2394           0 :                     aNeuFact=Fraction(aPt2.Y()-aRef.Y(),aP0.Y()-aRef.Y());
    2395             :                 }
    2396             :             }
    2397             :         }
    2398             : 
    2399           0 :         bool bNeg=nNeuWink<0;
    2400             : 
    2401           0 :         if (bNeg)
    2402           0 :             nNeuWink=-nNeuWink;
    2403             : 
    2404           0 :         if (nSA!=0)
    2405             :         { // angle snapping
    2406           0 :             nNeuWink+=nSA/2;
    2407           0 :             nNeuWink/=nSA;
    2408           0 :             nNeuWink*=nSA;
    2409             :         }
    2410             : 
    2411           0 :         nNeuWink=NormAngle360(nNeuWink);
    2412           0 :         bUpSideDown=nNeuWink>9000 && nNeuWink<27000;
    2413             : 
    2414           0 :         if (bSlant)
    2415             :         { // calculate resize for slant
    2416             :             // when angle snapping is activated, disable 89 degree limit
    2417           0 :             long nTmpWink=nNeuWink;
    2418           0 :             if (bUpSideDown) nNeuWink-=18000;
    2419           0 :             if (bNeg) nTmpWink=-nTmpWink;
    2420           0 :             bResize=true;
    2421           0 :             double nCos=cos(nTmpWink*nPi180);
    2422           0 :             aNeuFact=nCos;
    2423           0 :             Kuerzen(aFact,10); // three decimals should be enough
    2424             :         }
    2425             : 
    2426           0 :         if (nNeuWink>8900)
    2427           0 :             nNeuWink=8900;
    2428             : 
    2429           0 :         if (bNeg)
    2430           0 :             nNeuWink=-nNeuWink;
    2431             : 
    2432           0 :         if (nWink!=nNeuWink || aFact!=aNeuFact)
    2433             :         {
    2434           0 :             nWink=nNeuWink;
    2435           0 :             aFact=aNeuFact;
    2436           0 :             double a=nWink*nPi180;
    2437           0 :             double nTan1=tan(a); // calculate now, so as little time as possible passes between Hide() and Show()
    2438           0 :             Hide();
    2439           0 :             nTan=nTan1;
    2440           0 :             DragStat().NextMove(rPnt);
    2441           0 :             Show();
    2442             :         }
    2443             :     }
    2444           0 : }
    2445             : 
    2446           0 : void SdrDragShear::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
    2447             : {
    2448           0 :     if (bResize)
    2449             :     {
    2450           0 :         if (bVertical)
    2451             :         {
    2452           0 :             rTarget.Resize(DragStat().GetRef1(),aFact,Fraction(1,1));
    2453             :         }
    2454             :         else
    2455             :         {
    2456           0 :             rTarget.Resize(DragStat().GetRef1(),Fraction(1,1),aFact);
    2457             :         }
    2458             :     }
    2459             : 
    2460           0 :     if (nWink!=0)
    2461             :     {
    2462           0 :         rTarget.Shear(DragStat().GetRef1(),nWink,tan(nWink*nPi180),bVertical);
    2463             :     }
    2464           0 : }
    2465             : 
    2466           0 : bool SdrDragShear::EndSdrDrag(bool bCopy)
    2467             : {
    2468           0 :     Hide();
    2469             : 
    2470           0 :     if (bResize && aFact==Fraction(1,1))
    2471           0 :         bResize=false;
    2472             : 
    2473           0 :     if (nWink!=0 || bResize)
    2474             :     {
    2475           0 :         if (nWink!=0 && bResize)
    2476             :         {
    2477           0 :             OUString aStr;
    2478           0 :             ImpTakeDescriptionStr(STR_EditShear,aStr);
    2479             : 
    2480           0 :             if (bCopy)
    2481           0 :                 aStr += ImpGetResStr(STR_EditWithCopy);
    2482             : 
    2483           0 :             getSdrDragView().BegUndo(aStr);
    2484             :         }
    2485             : 
    2486           0 :         if (bResize)
    2487             :         {
    2488           0 :             if (bVertical)
    2489             :             {
    2490           0 :                 getSdrDragView().ResizeMarkedObj(DragStat().GetRef1(),aFact,Fraction(1,1),bCopy);
    2491             :             }
    2492             :             else
    2493             :             {
    2494           0 :                 getSdrDragView().ResizeMarkedObj(DragStat().GetRef1(),Fraction(1,1),aFact,bCopy);
    2495             :             }
    2496             : 
    2497           0 :             bCopy=false;
    2498             :         }
    2499             : 
    2500           0 :         if (nWink!=0)
    2501             :         {
    2502           0 :             getSdrDragView().ShearMarkedObj(DragStat().GetRef1(),nWink,bVertical,bCopy);
    2503             :         }
    2504             : 
    2505           0 :         if (nWink!=0 && bResize)
    2506           0 :             getSdrDragView().EndUndo();
    2507             : 
    2508           0 :         return true;
    2509             :     }
    2510             : 
    2511           0 :     return false;
    2512             : }
    2513             : 
    2514           0 : Pointer SdrDragShear::GetSdrDragPointer() const
    2515             : {
    2516           0 :     if (bVertical)
    2517           0 :         return Pointer(POINTER_VSHEAR);
    2518             :     else
    2519           0 :         return Pointer(POINTER_HSHEAR);
    2520             : }
    2521             : 
    2522             : 
    2523             : 
    2524           0 : TYPEINIT1(SdrDragMirror,SdrDragMethod);
    2525             : 
    2526           0 : void SdrDragMirror::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
    2527             : {
    2528           0 :     if(bMirrored)
    2529             :     {
    2530           0 :         rTarget.Mirror(DragStat().GetRef1(), DragStat().GetRef2());
    2531             :     }
    2532           0 : }
    2533             : 
    2534           0 : SdrDragMirror::SdrDragMirror(SdrDragView& rNewView)
    2535             : :   SdrDragMethod(rNewView),
    2536             :     nWink(0),
    2537             :     bMirrored(false),
    2538           0 :     bSide0(false)
    2539             : {
    2540           0 : }
    2541             : 
    2542           0 : bool SdrDragMirror::ImpCheckSide(const Point& rPnt) const
    2543             : {
    2544           0 :     long nWink1=GetAngle(rPnt-DragStat().GetRef1());
    2545           0 :     nWink1-=nWink;
    2546           0 :     nWink1=NormAngle360(nWink1);
    2547             : 
    2548           0 :     return nWink1<18000;
    2549             : }
    2550             : 
    2551           0 : void SdrDragMirror::TakeSdrDragComment(OUString& rStr) const
    2552             : {
    2553           0 :     if (aDif.X()==0)
    2554           0 :         ImpTakeDescriptionStr(STR_DragMethMirrorHori,rStr);
    2555           0 :     else if (aDif.Y()==0)
    2556           0 :         ImpTakeDescriptionStr(STR_DragMethMirrorVert,rStr);
    2557           0 :     else if (std::abs(aDif.X()) == std::abs(aDif.Y()))
    2558           0 :         ImpTakeDescriptionStr(STR_DragMethMirrorDiag,rStr);
    2559             :     else
    2560           0 :         ImpTakeDescriptionStr(STR_DragMethMirrorFree,rStr);
    2561             : 
    2562           0 :     if (getSdrDragView().IsDragWithCopy())
    2563           0 :         rStr+=ImpGetResStr(STR_EditWithCopy);
    2564           0 : }
    2565             : 
    2566           0 : bool SdrDragMirror::BeginSdrDrag()
    2567             : {
    2568           0 :     SdrHdl* pH1=GetHdlList().GetHdl(HDL_REF1);
    2569           0 :     SdrHdl* pH2=GetHdlList().GetHdl(HDL_REF2);
    2570             : 
    2571           0 :     if (pH1!=NULL && pH2!=NULL)
    2572             :     {
    2573           0 :         DragStat().Ref1()=pH1->GetPos();
    2574           0 :         DragStat().Ref2()=pH2->GetPos();
    2575           0 :         Ref1()=pH1->GetPos();
    2576           0 :         Ref2()=pH2->GetPos();
    2577           0 :         aDif=pH2->GetPos()-pH1->GetPos();
    2578           0 :         bool b90=(aDif.X()==0) || aDif.Y()==0;
    2579           0 :         bool b45=b90 || (std::abs(aDif.X()) == std::abs(aDif.Y()));
    2580           0 :         nWink=NormAngle360(GetAngle(aDif));
    2581             : 
    2582           0 :         if (!getSdrDragView().IsMirrorAllowed(false,false) && !b45)
    2583           0 :             return false; // free choice of axis angle not allowed
    2584             : 
    2585           0 :         if (!getSdrDragView().IsMirrorAllowed(true,false) && !b90)
    2586           0 :             return false;  // 45 degrees not allowed either
    2587             : 
    2588           0 :         bSide0=ImpCheckSide(DragStat().GetStart());
    2589           0 :         Show();
    2590           0 :         return true;
    2591             :     }
    2592             :     else
    2593             :     {
    2594             :         OSL_FAIL("SdrDragMirror::BeginSdrDrag(): Axis of reflection not found.");
    2595           0 :         return false;
    2596             :     }
    2597             : }
    2598             : 
    2599           0 : basegfx::B2DHomMatrix SdrDragMirror::getCurrentTransformation()
    2600             : {
    2601           0 :     basegfx::B2DHomMatrix aRetval;
    2602             : 
    2603           0 :     if (bMirrored)
    2604             :     {
    2605           0 :         const double fDeltaX(DragStat().GetRef2().X() - DragStat().GetRef1().X());
    2606           0 :         const double fDeltaY(DragStat().GetRef2().Y() - DragStat().GetRef1().Y());
    2607           0 :         const double fRotation(atan2(fDeltaY, fDeltaX));
    2608             : 
    2609           0 :         aRetval = basegfx::tools::createTranslateB2DHomMatrix(-DragStat().GetRef1().X(), -DragStat().GetRef1().Y());
    2610           0 :         aRetval.rotate(-fRotation);
    2611           0 :         aRetval.scale(1.0, -1.0);
    2612           0 :         aRetval.rotate(fRotation);
    2613           0 :         aRetval.translate(DragStat().GetRef1().X(), DragStat().GetRef1().Y());
    2614             :     }
    2615             : 
    2616           0 :     return aRetval;
    2617             : }
    2618             : 
    2619           0 : void SdrDragMirror::MoveSdrDrag(const Point& rPnt)
    2620             : {
    2621           0 :     if (DragStat().CheckMinMoved(rPnt))
    2622             :     {
    2623           0 :         bool bNeuSide=ImpCheckSide(rPnt);
    2624           0 :         bool bNeuMirr=bSide0!=bNeuSide;
    2625             : 
    2626           0 :         if (bMirrored!=bNeuMirr)
    2627             :         {
    2628           0 :             Hide();
    2629           0 :             bMirrored=bNeuMirr;
    2630           0 :             DragStat().NextMove(rPnt);
    2631           0 :             Show();
    2632             :         }
    2633             :     }
    2634           0 : }
    2635             : 
    2636           0 : bool SdrDragMirror::EndSdrDrag(bool bCopy)
    2637             : {
    2638           0 :     Hide();
    2639             : 
    2640           0 :     if (bMirrored)
    2641             :     {
    2642           0 :         getSdrDragView().MirrorMarkedObj(DragStat().GetRef1(),DragStat().GetRef2(),bCopy);
    2643             :     }
    2644             : 
    2645           0 :     return true;
    2646             : }
    2647             : 
    2648           0 : Pointer SdrDragMirror::GetSdrDragPointer() const
    2649             : {
    2650           0 :     return Pointer(POINTER_MIRROR);
    2651             : }
    2652             : 
    2653             : 
    2654             : 
    2655           0 : TYPEINIT1(SdrDragGradient, SdrDragMethod);
    2656             : 
    2657           0 : SdrDragGradient::SdrDragGradient(SdrDragView& rNewView, bool bGrad)
    2658             : :   SdrDragMethod(rNewView),
    2659             :     pIAOHandle(NULL),
    2660           0 :     bIsGradient(bGrad)
    2661             : {
    2662           0 : }
    2663             : 
    2664           0 : void SdrDragGradient::TakeSdrDragComment(OUString& rStr) const
    2665             : {
    2666           0 :     if(IsGradient())
    2667           0 :         ImpTakeDescriptionStr(STR_DragMethGradient, rStr);
    2668             :     else
    2669           0 :         ImpTakeDescriptionStr(STR_DragMethTransparence, rStr);
    2670           0 : }
    2671             : 
    2672           0 : bool SdrDragGradient::BeginSdrDrag()
    2673             : {
    2674           0 :     bool bRetval(false);
    2675             : 
    2676           0 :     pIAOHandle = (SdrHdlGradient*)GetHdlList().GetHdl(IsGradient() ? HDL_GRAD : HDL_TRNS);
    2677             : 
    2678           0 :     if(pIAOHandle)
    2679             :     {
    2680             :         // save old values
    2681           0 :         DragStat().Ref1() = pIAOHandle->GetPos();
    2682           0 :         DragStat().Ref2() = pIAOHandle->Get2ndPos();
    2683             : 
    2684             :         // what was hit?
    2685           0 :         bool bHit(false);
    2686           0 :         SdrHdlColor* pColHdl = pIAOHandle->GetColorHdl1();
    2687             : 
    2688             :         // init handling flags
    2689           0 :         pIAOHandle->SetMoveSingleHandle(false);
    2690           0 :         pIAOHandle->SetMoveFirstHandle(false);
    2691             : 
    2692             :         // test first color handle
    2693           0 :         if(pColHdl)
    2694             :         {
    2695           0 :             basegfx::B2DPoint aPosition(DragStat().GetStart().X(), DragStat().GetStart().Y());
    2696             : 
    2697           0 :             if(pColHdl->getOverlayObjectList().isHitLogic(aPosition))
    2698             :             {
    2699           0 :                 bHit = true;
    2700           0 :                 pIAOHandle->SetMoveSingleHandle(true);
    2701           0 :                 pIAOHandle->SetMoveFirstHandle(true);
    2702           0 :             }
    2703             :         }
    2704             : 
    2705             :         // test second color handle
    2706           0 :         pColHdl = pIAOHandle->GetColorHdl2();
    2707             : 
    2708           0 :         if(!bHit && pColHdl)
    2709             :         {
    2710           0 :             basegfx::B2DPoint aPosition(DragStat().GetStart().X(), DragStat().GetStart().Y());
    2711             : 
    2712           0 :             if(pColHdl->getOverlayObjectList().isHitLogic(aPosition))
    2713             :             {
    2714           0 :                 bHit = true;
    2715           0 :                 pIAOHandle->SetMoveSingleHandle(true);
    2716           0 :             }
    2717             :         }
    2718             : 
    2719             :         // test gradient handle itself
    2720           0 :         if(!bHit)
    2721             :         {
    2722           0 :             basegfx::B2DPoint aPosition(DragStat().GetStart().X(), DragStat().GetStart().Y());
    2723             : 
    2724           0 :             if(pIAOHandle->getOverlayObjectList().isHitLogic(aPosition))
    2725             :             {
    2726           0 :                 bHit = true;
    2727           0 :             }
    2728             :         }
    2729             : 
    2730             :         // everything up and running :o}
    2731           0 :         bRetval = bHit;
    2732             :     }
    2733             :     else
    2734             :     {
    2735             :         OSL_FAIL("SdrDragGradient::BeginSdrDrag(): IAOGradient not found.");
    2736             :     }
    2737             : 
    2738           0 :     return bRetval;
    2739             : }
    2740             : 
    2741           0 : void SdrDragGradient::MoveSdrDrag(const Point& rPnt)
    2742             : {
    2743           0 :     if(pIAOHandle && DragStat().CheckMinMoved(rPnt))
    2744             :     {
    2745           0 :         DragStat().NextMove(rPnt);
    2746             : 
    2747             :         // Do the Move here!!! DragStat().GetStart()
    2748           0 :         Point aMoveDiff = rPnt - DragStat().GetStart();
    2749             : 
    2750           0 :         if(pIAOHandle->IsMoveSingleHandle())
    2751             :         {
    2752           0 :             if(pIAOHandle->IsMoveFirstHandle())
    2753             :             {
    2754           0 :                 pIAOHandle->SetPos(DragStat().Ref1() + aMoveDiff);
    2755           0 :                 if(pIAOHandle->GetColorHdl1())
    2756           0 :                     pIAOHandle->GetColorHdl1()->SetPos(DragStat().Ref1() + aMoveDiff);
    2757             :             }
    2758             :             else
    2759             :             {
    2760           0 :                 pIAOHandle->Set2ndPos(DragStat().Ref2() + aMoveDiff);
    2761           0 :                 if(pIAOHandle->GetColorHdl2())
    2762           0 :                     pIAOHandle->GetColorHdl2()->SetPos(DragStat().Ref2() + aMoveDiff);
    2763             :             }
    2764             :         }
    2765             :         else
    2766             :         {
    2767           0 :             pIAOHandle->SetPos(DragStat().Ref1() + aMoveDiff);
    2768           0 :             pIAOHandle->Set2ndPos(DragStat().Ref2() + aMoveDiff);
    2769             : 
    2770           0 :             if(pIAOHandle->GetColorHdl1())
    2771           0 :                 pIAOHandle->GetColorHdl1()->SetPos(DragStat().Ref1() + aMoveDiff);
    2772             : 
    2773           0 :             if(pIAOHandle->GetColorHdl2())
    2774           0 :                 pIAOHandle->GetColorHdl2()->SetPos(DragStat().Ref2() + aMoveDiff);
    2775             :         }
    2776             : 
    2777             :         // new state
    2778           0 :         pIAOHandle->FromIAOToItem(getSdrDragView().GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj(), false, false);
    2779             :     }
    2780           0 : }
    2781             : 
    2782           0 : bool SdrDragGradient::EndSdrDrag(bool /*bCopy*/)
    2783             : {
    2784           0 :     Ref1() = pIAOHandle->GetPos();
    2785           0 :     Ref2() = pIAOHandle->Get2ndPos();
    2786             : 
    2787             :     // new state
    2788           0 :     pIAOHandle->FromIAOToItem(getSdrDragView().GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj(), true, true);
    2789             : 
    2790           0 :     return true;
    2791             : }
    2792             : 
    2793           0 : void SdrDragGradient::CancelSdrDrag()
    2794             : {
    2795             :     // restore old values
    2796           0 :     pIAOHandle->SetPos(DragStat().Ref1());
    2797           0 :     pIAOHandle->Set2ndPos(DragStat().Ref2());
    2798             : 
    2799           0 :     if(pIAOHandle->GetColorHdl1())
    2800           0 :         pIAOHandle->GetColorHdl1()->SetPos(DragStat().Ref1());
    2801             : 
    2802           0 :     if(pIAOHandle->GetColorHdl2())
    2803           0 :         pIAOHandle->GetColorHdl2()->SetPos(DragStat().Ref2());
    2804             : 
    2805             :     // new state
    2806           0 :     pIAOHandle->FromIAOToItem(getSdrDragView().GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj(), true, false);
    2807           0 : }
    2808             : 
    2809           0 : Pointer SdrDragGradient::GetSdrDragPointer() const
    2810             : {
    2811           0 :     return Pointer(POINTER_REFHAND);
    2812             : }
    2813             : 
    2814             : 
    2815             : 
    2816           0 : TYPEINIT1(SdrDragCrook,SdrDragMethod);
    2817             : 
    2818           0 : SdrDragCrook::SdrDragCrook(SdrDragView& rNewView)
    2819             : :   SdrDragMethod(rNewView),
    2820             :     aFact(1,1),
    2821             :     bContortionAllowed(false),
    2822             :     bNoContortionAllowed(false),
    2823             :     bContortion(false),
    2824             :     bResizeAllowed(false),
    2825             :     bResize(false),
    2826             :     bRotateAllowed(false),
    2827             :     bRotate(false),
    2828             :     bVertical(false),
    2829             :     bValid(false),
    2830             :     bLft(false),
    2831             :     bRgt(false),
    2832             :     bUpr(false),
    2833             :     bLwr(false),
    2834             :     bAtCenter(false),
    2835             :     nWink(0),
    2836             :     nMarkSize(0),
    2837           0 :     eMode(SDRCROOK_ROTATE)
    2838             : {
    2839           0 : }
    2840             : 
    2841           0 : void SdrDragCrook::TakeSdrDragComment(OUString& rStr) const
    2842             : {
    2843           0 :     ImpTakeDescriptionStr(!bContortion ? STR_DragMethCrook : STR_DragMethCrookContortion, rStr);
    2844             : 
    2845           0 :     if(bValid)
    2846             :     {
    2847           0 :         rStr += " (";
    2848             : 
    2849           0 :         sal_Int32 nVal(nWink);
    2850             : 
    2851           0 :         if(bAtCenter)
    2852           0 :             nVal *= 2;
    2853             : 
    2854           0 :         nVal = std::abs(nVal);
    2855           0 :         OUString aStr;
    2856           0 :         getSdrDragView().GetModel()->TakeWinkStr(nVal, aStr);
    2857           0 :         rStr += aStr + ")";
    2858             :     }
    2859             : 
    2860           0 :     if(getSdrDragView().IsDragWithCopy())
    2861           0 :         rStr += ImpGetResStr(STR_EditWithCopy);
    2862           0 : }
    2863             : 
    2864             : // These defines parameterize the created raster
    2865             : // for interactions
    2866             : #define DRAG_CROOK_RASTER_MINIMUM   (4)
    2867             : #define DRAG_CROOK_RASTER_MAXIMUM   (15)
    2868             : #define DRAG_CROOK_RASTER_DISTANCE  (30)
    2869             : 
    2870           0 : basegfx::B2DPolyPolygon impCreateDragRaster(SdrPageView& rPageView, const Rectangle& rMarkRect)
    2871             : {
    2872           0 :     basegfx::B2DPolyPolygon aRetval;
    2873             : 
    2874           0 :     if(rPageView.PageWindowCount())
    2875             :     {
    2876           0 :         OutputDevice& rOut = (rPageView.GetPageWindow(0)->GetPaintWindow().GetOutputDevice());
    2877           0 :         Rectangle aPixelSize = rOut.LogicToPixel(rMarkRect);
    2878           0 :         sal_uInt32 nHorDiv(aPixelSize.GetWidth() / DRAG_CROOK_RASTER_DISTANCE);
    2879           0 :         sal_uInt32 nVerDiv(aPixelSize.GetHeight() / DRAG_CROOK_RASTER_DISTANCE);
    2880             : 
    2881           0 :         if(nHorDiv > DRAG_CROOK_RASTER_MAXIMUM)
    2882           0 :             nHorDiv = DRAG_CROOK_RASTER_MAXIMUM;
    2883           0 :         if(nHorDiv < DRAG_CROOK_RASTER_MINIMUM)
    2884           0 :             nHorDiv = DRAG_CROOK_RASTER_MINIMUM;
    2885             : 
    2886           0 :         if(nVerDiv > DRAG_CROOK_RASTER_MAXIMUM)
    2887           0 :             nVerDiv = DRAG_CROOK_RASTER_MAXIMUM;
    2888           0 :         if(nVerDiv < DRAG_CROOK_RASTER_MINIMUM)
    2889           0 :             nVerDiv = DRAG_CROOK_RASTER_MINIMUM;
    2890             : 
    2891           0 :         const double fXLen(rMarkRect.GetWidth() / (double)nHorDiv);
    2892           0 :         const double fYLen(rMarkRect.GetHeight() / (double)nVerDiv);
    2893           0 :         double fYPos(rMarkRect.Top());
    2894             :         sal_uInt32 a, b;
    2895             : 
    2896           0 :         for(a = 0; a <= nVerDiv; a++)
    2897             :         {
    2898             :             // horizontal lines
    2899           0 :             for(b = 0; b < nHorDiv; b++)
    2900             :             {
    2901           0 :                 basegfx::B2DPolygon aHorLineSegment;
    2902             : 
    2903           0 :                 const double fNewX(rMarkRect.Left() + (b * fXLen));
    2904           0 :                 aHorLineSegment.append(basegfx::B2DPoint(fNewX, fYPos));
    2905             :                 aHorLineSegment.appendBezierSegment(
    2906           0 :                     basegfx::B2DPoint(fNewX + (fXLen * (1.0 / 3.0)), fYPos),
    2907           0 :                     basegfx::B2DPoint(fNewX + (fXLen * (2.0 / 3.0)), fYPos),
    2908           0 :                     basegfx::B2DPoint(fNewX + fXLen, fYPos));
    2909           0 :                 aRetval.append(aHorLineSegment);
    2910           0 :             }
    2911             : 
    2912             :             // increments
    2913           0 :             fYPos += fYLen;
    2914             :         }
    2915             : 
    2916           0 :         double fXPos(rMarkRect.Left());
    2917             : 
    2918           0 :         for(a = 0; a <= nHorDiv; a++)
    2919             :         {
    2920             :             // vertical lines
    2921           0 :             for(b = 0; b < nVerDiv; b++)
    2922             :             {
    2923           0 :                 basegfx::B2DPolygon aVerLineSegment;
    2924             : 
    2925           0 :                 const double fNewY(rMarkRect.Top() + (b * fYLen));
    2926           0 :                 aVerLineSegment.append(basegfx::B2DPoint(fXPos, fNewY));
    2927             :                 aVerLineSegment.appendBezierSegment(
    2928           0 :                     basegfx::B2DPoint(fXPos, fNewY + (fYLen * (1.0 / 3.0))),
    2929           0 :                     basegfx::B2DPoint(fXPos, fNewY + (fYLen * (2.0 / 3.0))),
    2930           0 :                     basegfx::B2DPoint(fXPos, fNewY + fYLen));
    2931           0 :                 aRetval.append(aVerLineSegment);
    2932           0 :             }
    2933             : 
    2934             :             // increments
    2935           0 :             fXPos += fXLen;
    2936             :         }
    2937             :     }
    2938             : 
    2939           0 :     return aRetval;
    2940             : }
    2941             : 
    2942           0 : void SdrDragCrook::createSdrDragEntries()
    2943             : {
    2944             :     // Add extended frame raster first, so it will be behind objects
    2945           0 :     if(getSdrDragView().GetSdrPageView())
    2946             :     {
    2947           0 :         const basegfx::B2DPolyPolygon aDragRaster(impCreateDragRaster(*getSdrDragView().GetSdrPageView(), GetMarkedRect()));
    2948             : 
    2949           0 :         if(aDragRaster.count())
    2950             :         {
    2951           0 :             addSdrDragEntry(new SdrDragEntryPolyPolygon(aDragRaster));
    2952           0 :         }
    2953             :     }
    2954             : 
    2955             :     // call parent
    2956           0 :     SdrDragMethod::createSdrDragEntries();
    2957           0 : }
    2958             : 
    2959           0 : bool SdrDragCrook::BeginSdrDrag()
    2960             : {
    2961           0 :     bContortionAllowed=getSdrDragView().IsCrookAllowed(false);
    2962           0 :     bNoContortionAllowed=getSdrDragView().IsCrookAllowed(true);
    2963           0 :     bResizeAllowed=getSdrDragView().IsResizeAllowed(false);
    2964           0 :     bRotateAllowed=getSdrDragView().IsRotateAllowed(false);
    2965             : 
    2966           0 :     if (bContortionAllowed || bNoContortionAllowed)
    2967             :     {
    2968           0 :         bVertical=(GetDragHdlKind()==HDL_LOWER || GetDragHdlKind()==HDL_UPPER);
    2969           0 :         aMarkRect=GetMarkedRect();
    2970           0 :         aMarkCenter=aMarkRect.Center();
    2971           0 :         nMarkSize=bVertical ? (aMarkRect.GetHeight()-1) : (aMarkRect.GetWidth()-1);
    2972           0 :         aCenter=aMarkCenter;
    2973           0 :         aStart=DragStat().GetStart();
    2974           0 :         Show();
    2975           0 :         return true;
    2976             :     }
    2977             :     else
    2978             :     {
    2979           0 :         return false;
    2980             :     }
    2981             : }
    2982             : 
    2983           0 : void SdrDragCrook::_MovAllPoints(basegfx::B2DPolyPolygon& rTarget)
    2984             : {
    2985           0 :     SdrPageView* pPV = getSdrDragView().GetSdrPageView();
    2986             : 
    2987           0 :     if(pPV)
    2988             :     {
    2989           0 :         XPolyPolygon aTempPolyPoly(rTarget);
    2990             : 
    2991           0 :         if (pPV->HasMarkedObjPageView())
    2992             :         {
    2993           0 :             sal_uInt16 nPolyAnz=aTempPolyPoly.Count();
    2994             : 
    2995           0 :             if (!bContortion && !getSdrDragView().IsNoDragXorPolys())
    2996             :             {
    2997           0 :                 sal_uInt16 n1st=0,nLast=0;
    2998           0 :                 Point aC(aCenter);
    2999             : 
    3000           0 :                 while (n1st<nPolyAnz)
    3001             :                 {
    3002           0 :                     nLast=n1st;
    3003           0 :                     while (nLast<nPolyAnz && aTempPolyPoly[nLast].GetPointCount()!=0) nLast++;
    3004           0 :                     Rectangle aBound(aTempPolyPoly[n1st].GetBoundRect());
    3005             :                     sal_uInt16 i;
    3006             : 
    3007           0 :                     for (i=n1st+1; i<nLast; i++)
    3008             :                     {
    3009           0 :                         aBound.Union(aTempPolyPoly[n1st].GetBoundRect());
    3010             :                     }
    3011             : 
    3012           0 :                     Point aCtr0(aBound.Center());
    3013           0 :                     Point aCtr1(aCtr0);
    3014             : 
    3015           0 :                     if (bResize)
    3016             :                     {
    3017           0 :                         Fraction aFact1(1,1);
    3018             : 
    3019           0 :                         if (bVertical)
    3020             :                         {
    3021           0 :                             ResizePoint(aCtr1,aC,aFact1,aFact);
    3022             :                         }
    3023             :                         else
    3024             :                         {
    3025           0 :                             ResizePoint(aCtr1,aC,aFact,aFact1);
    3026             :                         }
    3027             :                     }
    3028             : 
    3029           0 :                     bool bRotOk=false;
    3030           0 :                     double nSin=0,nCos=0;
    3031             : 
    3032           0 :                     if (aRad.X()!=0 && aRad.Y()!=0)
    3033             :                     {
    3034           0 :                         bRotOk=bRotate;
    3035             : 
    3036           0 :                         switch (eMode)
    3037             :                         {
    3038           0 :                             case SDRCROOK_ROTATE : CrookRotateXPoint (aCtr1,NULL,NULL,aC,aRad,nSin,nCos,bVertical);           break;
    3039           0 :                             case SDRCROOK_SLANT  : CrookSlantXPoint  (aCtr1,NULL,NULL,aC,aRad,nSin,nCos,bVertical);           break;
    3040           0 :                             case SDRCROOK_STRETCH: CrookStretchXPoint(aCtr1,NULL,NULL,aC,aRad,nSin,nCos,bVertical,aMarkRect); break;
    3041             :                         } // switch
    3042             :                     }
    3043             : 
    3044           0 :                     aCtr1-=aCtr0;
    3045             : 
    3046           0 :                     for (i=n1st; i<nLast; i++)
    3047             :                     {
    3048           0 :                         if (bRotOk)
    3049             :                         {
    3050           0 :                             RotateXPoly(aTempPolyPoly[i],aCtr0,nSin,nCos);
    3051             :                         }
    3052             : 
    3053           0 :                         aTempPolyPoly[i].Move(aCtr1.X(),aCtr1.Y());
    3054             :                     }
    3055             : 
    3056           0 :                     n1st=nLast+1;
    3057             :                 }
    3058             :             }
    3059             :             else
    3060             :             {
    3061             :                 sal_uInt16 i,j;
    3062             : 
    3063           0 :                 for (j=0; j<nPolyAnz; j++)
    3064             :                 {
    3065           0 :                     XPolygon& aPol=aTempPolyPoly[j];
    3066           0 :                     sal_uInt16 nPtAnz=aPol.GetPointCount();
    3067           0 :                     i=0;
    3068             : 
    3069           0 :                     while (i<nPtAnz)
    3070             :                     {
    3071           0 :                         Point* pPnt=&aPol[i];
    3072           0 :                         Point* pC1=NULL;
    3073           0 :                         Point* pC2=NULL;
    3074             : 
    3075           0 :                         if (i+1<nPtAnz && aPol.IsControl(i))
    3076             :                         { // control point on the left
    3077           0 :                             pC1=pPnt;
    3078           0 :                             i++;
    3079           0 :                             pPnt=&aPol[i];
    3080             :                         }
    3081             : 
    3082           0 :                         i++;
    3083             : 
    3084           0 :                         if (i<nPtAnz && aPol.IsControl(i))
    3085             :                         { // control point on the right
    3086           0 :                             pC2=&aPol[i];
    3087           0 :                             i++;
    3088             :                         }
    3089             : 
    3090           0 :                         _MovCrookPoint(*pPnt,pC1,pC2);
    3091             :                     }
    3092             :                 }
    3093             :             }
    3094             :         }
    3095             : 
    3096           0 :         rTarget = aTempPolyPoly.getB2DPolyPolygon();
    3097             :     }
    3098           0 : }
    3099             : 
    3100           0 : void SdrDragCrook::_MovCrookPoint(Point& rPnt, Point* pC1, Point* pC2)
    3101             : {
    3102           0 :     bool bVert=bVertical;
    3103           0 :     bool bC1=pC1!=NULL;
    3104           0 :     bool bC2=pC2!=NULL;
    3105           0 :     Point aC(aCenter);
    3106             : 
    3107           0 :     if (bResize)
    3108             :     {
    3109           0 :         Fraction aFact1(1,1);
    3110             : 
    3111           0 :         if (bVert)
    3112             :         {
    3113           0 :             ResizePoint(rPnt,aC,aFact1,aFact);
    3114             : 
    3115           0 :             if (bC1)
    3116           0 :                 ResizePoint(*pC1,aC,aFact1,aFact);
    3117             : 
    3118           0 :             if (bC2)
    3119           0 :                 ResizePoint(*pC2,aC,aFact1,aFact);
    3120             :         }
    3121             :         else
    3122             :         {
    3123           0 :             ResizePoint(rPnt,aC,aFact,aFact1);
    3124             : 
    3125           0 :             if (bC1)
    3126           0 :                 ResizePoint(*pC1,aC,aFact,aFact1);
    3127             : 
    3128           0 :             if (bC2)
    3129           0 :                 ResizePoint(*pC2,aC,aFact,aFact1);
    3130             :         }
    3131             :     }
    3132             : 
    3133           0 :     if (aRad.X()!=0 && aRad.Y()!=0)
    3134             :     {
    3135             :         double nSin,nCos;
    3136             : 
    3137           0 :         switch (eMode)
    3138             :         {
    3139           0 :             case SDRCROOK_ROTATE : CrookRotateXPoint (rPnt,pC1,pC2,aC,aRad,nSin,nCos,bVert);           break;
    3140           0 :             case SDRCROOK_SLANT  : CrookSlantXPoint  (rPnt,pC1,pC2,aC,aRad,nSin,nCos,bVert);           break;
    3141           0 :             case SDRCROOK_STRETCH: CrookStretchXPoint(rPnt,pC1,pC2,aC,aRad,nSin,nCos,bVert,aMarkRect); break;
    3142             :         } // switch
    3143             :     }
    3144           0 : }
    3145             : 
    3146           0 : void SdrDragCrook::MoveSdrDrag(const Point& rPnt)
    3147             : {
    3148           0 :     if (DragStat().CheckMinMoved(rPnt))
    3149             :     {
    3150           0 :         bool bNeuMoveOnly=getSdrDragView().IsMoveOnlyDragging();
    3151           0 :         bAtCenter=false;
    3152           0 :         SdrCrookMode eNeuMode=getSdrDragView().GetCrookMode();
    3153           0 :         bool bNeuContortion=!bNeuMoveOnly && ((bContortionAllowed && !getSdrDragView().IsCrookNoContortion()) || !bNoContortionAllowed);
    3154           0 :         bResize=!getSdrDragView().IsOrtho() && bResizeAllowed && !bNeuMoveOnly;
    3155           0 :         bool bNeuRotate=bRotateAllowed && !bNeuContortion && !bNeuMoveOnly && eNeuMode==SDRCROOK_ROTATE;
    3156             : 
    3157           0 :         Point aPnt(GetSnapPos(rPnt));
    3158             : 
    3159           0 :         Point aNeuCenter(aMarkCenter.X(),aStart.Y());
    3160             : 
    3161           0 :         if (bVertical)
    3162             :         {
    3163           0 :             aNeuCenter.X()=aStart.X();
    3164           0 :             aNeuCenter.Y()=aMarkCenter.Y();
    3165             :         }
    3166             : 
    3167           0 :         if (!getSdrDragView().IsCrookAtCenter())
    3168             :         {
    3169           0 :             switch (GetDragHdlKind())
    3170             :             {
    3171           0 :                 case HDL_UPLFT: aNeuCenter.X()=aMarkRect.Right();  bLft=true; break;
    3172           0 :                 case HDL_UPPER: aNeuCenter.Y()=aMarkRect.Bottom(); bUpr=true; break;
    3173           0 :                 case HDL_UPRGT: aNeuCenter.X()=aMarkRect.Left();   bRgt=true; break;
    3174           0 :                 case HDL_LEFT : aNeuCenter.X()=aMarkRect.Right();  bLft=true; break;
    3175           0 :                 case HDL_RIGHT: aNeuCenter.X()=aMarkRect.Left();   bRgt=true; break;
    3176           0 :                 case HDL_LWLFT: aNeuCenter.X()=aMarkRect.Right();  bLft=true; break;
    3177           0 :                 case HDL_LOWER: aNeuCenter.Y()=aMarkRect.Top();    bLwr=true; break;
    3178           0 :                 case HDL_LWRGT: aNeuCenter.X()=aMarkRect.Left();   bRgt=true; break;
    3179           0 :                 default: bAtCenter=true;
    3180             :             }
    3181             :         }
    3182             :         else
    3183           0 :             bAtCenter=true;
    3184             : 
    3185           0 :         Fraction aNeuFact(1,1);
    3186           0 :         long dx1=aPnt.X()-aNeuCenter.X();
    3187           0 :         long dy1=aPnt.Y()-aNeuCenter.Y();
    3188           0 :         bValid=bVertical ? dx1!=0 : dy1!=0;
    3189             : 
    3190           0 :         if (bValid)
    3191             :         {
    3192           0 :             if (bVertical)
    3193           0 :                 bValid = std::abs(dx1)*100>std::abs(dy1);
    3194             :             else
    3195           0 :                 bValid = std::abs(dy1)*100>std::abs(dx1);
    3196             :         }
    3197             : 
    3198           0 :         long nNeuRad=0;
    3199           0 :         nWink=0;
    3200             : 
    3201           0 :         if (bValid)
    3202             :         {
    3203           0 :             double a=0; // slope of the radius
    3204           0 :             long nPntWink=0;
    3205             : 
    3206           0 :             if (bVertical)
    3207             :             {
    3208           0 :                 a=((double)dy1)/((double)dx1); // slope of the radius
    3209           0 :                 nNeuRad=((long)(dy1*a)+dx1) /2;
    3210           0 :                 aNeuCenter.X()+=nNeuRad;
    3211           0 :                 nPntWink=GetAngle(aPnt-aNeuCenter);
    3212             :             }
    3213             :             else
    3214             :             {
    3215           0 :                 a=((double)dx1)/((double)dy1); // slope of the radius
    3216           0 :                 nNeuRad=((long)(dx1*a)+dy1) /2;
    3217           0 :                 aNeuCenter.Y()+=nNeuRad;
    3218           0 :                 nPntWink=GetAngle(aPnt-aNeuCenter)-9000;
    3219             :             }
    3220             : 
    3221           0 :             if (!bAtCenter)
    3222             :             {
    3223           0 :                 if (nNeuRad<0)
    3224             :                 {
    3225           0 :                     if (bRgt) nPntWink+=18000;
    3226           0 :                     if (bLft) nPntWink=18000-nPntWink;
    3227           0 :                     if (bLwr) nPntWink=-nPntWink;
    3228             :                 }
    3229             :                 else
    3230             :                 {
    3231           0 :                     if (bRgt) nPntWink=-nPntWink;
    3232           0 :                     if (bUpr) nPntWink=18000-nPntWink;
    3233           0 :                     if (bLwr) nPntWink+=18000;
    3234             :                 }
    3235             : 
    3236           0 :                 nPntWink=NormAngle360(nPntWink);
    3237             :             }
    3238             :             else
    3239             :             {
    3240           0 :                 if (nNeuRad<0) nPntWink+=18000;
    3241           0 :                 if (bVertical) nPntWink=18000-nPntWink;
    3242           0 :                 nPntWink=NormAngle180(nPntWink);
    3243           0 :                 nPntWink = std::abs(nPntWink);
    3244             :             }
    3245             : 
    3246           0 :             double nUmfang = 2 * std::abs(nNeuRad)*nPi;
    3247             : 
    3248           0 :             if (bResize)
    3249             :             {
    3250           0 :                 long nMul=(long)(nUmfang*NormAngle360(nPntWink)/36000);
    3251             : 
    3252           0 :                 if (bAtCenter)
    3253           0 :                     nMul*=2;
    3254             : 
    3255           0 :                 aNeuFact=Fraction(nMul,nMarkSize);
    3256           0 :                 nWink=nPntWink;
    3257             :             }
    3258             :             else
    3259             :             {
    3260           0 :                 nWink=(long)((nMarkSize*360/nUmfang)*100)/2;
    3261             : 
    3262           0 :                 if (nWink==0)
    3263           0 :                     bValid=false;
    3264             :             }
    3265             :         }
    3266             : 
    3267           0 :         if (nWink==0 || nNeuRad==0)
    3268           0 :             bValid=false;
    3269             : 
    3270           0 :         if (!bValid)
    3271           0 :             nNeuRad=0;
    3272             : 
    3273           0 :         if (!bValid && bResize)
    3274             :         {
    3275           0 :             long nMul=bVertical ? dy1 : dx1;
    3276             : 
    3277           0 :             if (bLft || bUpr)
    3278           0 :                 nMul=-nMul;
    3279             : 
    3280           0 :             long nDiv=nMarkSize;
    3281             : 
    3282           0 :             if (bAtCenter)
    3283             :             {
    3284           0 :                 nMul*=2;
    3285           0 :                 nMul = std::abs(nMul);
    3286             :             }
    3287             : 
    3288           0 :             aNeuFact=Fraction(nMul,nDiv);
    3289             :         }
    3290             : 
    3291           0 :         if (aNeuCenter!=aCenter || bNeuContortion!=bContortion || aNeuFact!=aFact ||
    3292           0 :             bNeuMoveOnly != getMoveOnly() || bNeuRotate!=bRotate || eNeuMode!=eMode)
    3293             :         {
    3294           0 :             Hide();
    3295           0 :             setMoveOnly(bNeuMoveOnly);
    3296           0 :             bRotate=bNeuRotate;
    3297           0 :             eMode=eNeuMode;
    3298           0 :             bContortion=bNeuContortion;
    3299           0 :             aCenter=aNeuCenter;
    3300           0 :             aFact=aNeuFact;
    3301           0 :             aRad=Point(nNeuRad,nNeuRad);
    3302           0 :             bResize=aFact!=Fraction(1,1) && aFact.GetDenominator()!=0 && aFact.IsValid();
    3303           0 :             DragStat().NextMove(aPnt);
    3304           0 :             Show();
    3305             :         }
    3306             :     }
    3307           0 : }
    3308             : 
    3309           0 : void SdrDragCrook::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
    3310             : {
    3311           0 :     const bool bDoResize(aFact!=Fraction(1,1));
    3312           0 :     const bool bDoCrook(aCenter!=aMarkCenter && aRad.X()!=0 && aRad.Y()!=0);
    3313             : 
    3314           0 :     if (bDoCrook || bDoResize)
    3315             :     {
    3316           0 :         if (bDoResize)
    3317             :         {
    3318           0 :             Fraction aFact1(1,1);
    3319             : 
    3320           0 :             if (bContortion)
    3321             :             {
    3322           0 :                 if (bVertical)
    3323             :                 {
    3324           0 :                     rTarget.Resize(aCenter,aFact1,aFact);
    3325             :                 }
    3326             :                 else
    3327             :                 {
    3328           0 :                     rTarget.Resize(aCenter,aFact,aFact1);
    3329             :                 }
    3330             :             }
    3331             :             else
    3332             :             {
    3333           0 :                 Point aCtr0(rTarget.GetSnapRect().Center());
    3334           0 :                 Point aCtr1(aCtr0);
    3335             : 
    3336           0 :                 if (bVertical)
    3337             :                 {
    3338           0 :                     ResizePoint(aCtr1,aCenter,aFact1,aFact);
    3339             :                 }
    3340             :                 else
    3341             :                 {
    3342           0 :                     ResizePoint(aCtr1,aCenter,aFact,aFact1);
    3343             :                 }
    3344             : 
    3345           0 :                 Size aSiz(aCtr1.X()-aCtr0.X(),aCtr1.Y()-aCtr0.Y());
    3346             : 
    3347           0 :                 rTarget.Move(aSiz);
    3348             :             }
    3349             :         }
    3350             : 
    3351           0 :         if (bDoCrook)
    3352             :         {
    3353           0 :             const Rectangle aLocalMarkRect(getSdrDragView().GetMarkedObjRect());
    3354           0 :             const bool bLocalRotate(!bContortion && eMode == SDRCROOK_ROTATE && getSdrDragView().IsRotateAllowed(false));
    3355             : 
    3356           0 :             getSdrDragView().ImpCrookObj(&rTarget,aCenter,aRad,eMode,bVertical,!bContortion,bLocalRotate,aLocalMarkRect);
    3357             :         }
    3358             :     }
    3359           0 : }
    3360             : 
    3361           0 : void SdrDragCrook::applyCurrentTransformationToPolyPolygon(basegfx::B2DPolyPolygon& rTarget)
    3362             : {
    3363             :     // use helper derived from old stuff
    3364           0 :     _MovAllPoints(rTarget);
    3365           0 : }
    3366             : 
    3367           0 : bool SdrDragCrook::EndSdrDrag(bool bCopy)
    3368             : {
    3369           0 :     Hide();
    3370             : 
    3371           0 :     if (bResize && aFact==Fraction(1,1))
    3372           0 :         bResize=false;
    3373             : 
    3374           0 :     const bool bUndo = getSdrDragView().IsUndoEnabled();
    3375             : 
    3376           0 :     bool bDoCrook=aCenter!=aMarkCenter && aRad.X()!=0 && aRad.Y()!=0;
    3377             : 
    3378           0 :     if (bDoCrook || bResize)
    3379             :     {
    3380           0 :         if (bResize && bUndo)
    3381             :         {
    3382           0 :             OUString aStr;
    3383           0 :             ImpTakeDescriptionStr(!bContortion?STR_EditCrook:STR_EditCrookContortion,aStr);
    3384             : 
    3385           0 :             if (bCopy)
    3386           0 :                 aStr += ImpGetResStr(STR_EditWithCopy);
    3387             : 
    3388           0 :             getSdrDragView().BegUndo(aStr);
    3389             :         }
    3390             : 
    3391           0 :         if (bResize)
    3392             :         {
    3393           0 :             Fraction aFact1(1,1);
    3394             : 
    3395           0 :             if (bContortion)
    3396             :             {
    3397           0 :                 if (bVertical)
    3398           0 :                     getSdrDragView().ResizeMarkedObj(aCenter,aFact1,aFact,bCopy);
    3399             :                 else
    3400           0 :                     getSdrDragView().ResizeMarkedObj(aCenter,aFact,aFact1,bCopy);
    3401             :             }
    3402             :             else
    3403             :             {
    3404           0 :                 if (bCopy)
    3405           0 :                     getSdrDragView().CopyMarkedObj();
    3406             : 
    3407           0 :                 sal_uLong nMarkAnz=getSdrDragView().GetMarkedObjectList().GetMarkCount();
    3408             : 
    3409           0 :                 for (sal_uLong nm=0; nm<nMarkAnz; nm++)
    3410             :                 {
    3411           0 :                     SdrMark* pM=getSdrDragView().GetMarkedObjectList().GetMark(nm);
    3412           0 :                     SdrObject* pO=pM->GetMarkedSdrObj();
    3413           0 :                     Point aCtr0(pO->GetSnapRect().Center());
    3414           0 :                     Point aCtr1(aCtr0);
    3415             : 
    3416           0 :                     if (bVertical)
    3417           0 :                         ResizePoint(aCtr1,aCenter,aFact1,aFact);
    3418             :                     else
    3419           0 :                         ResizePoint(aCtr1,aCenter,aFact,aFact1);
    3420             : 
    3421           0 :                     Size aSiz(aCtr1.X()-aCtr0.X(),aCtr1.Y()-aCtr0.Y());
    3422           0 :                     if( bUndo )
    3423           0 :                         AddUndo(getSdrDragView().GetModel()->GetSdrUndoFactory().CreateUndoMoveObject(*pO,aSiz));
    3424           0 :                     pO->Move(aSiz);
    3425             :                 }
    3426             :             }
    3427             : 
    3428           0 :             bCopy=false;
    3429             :         }
    3430             : 
    3431           0 :         if (bDoCrook)
    3432             :         {
    3433           0 :             getSdrDragView().CrookMarkedObj(aCenter,aRad,eMode,bVertical,!bContortion,bCopy);
    3434           0 :             getSdrDragView().SetLastCrookCenter(aCenter);
    3435             :         }
    3436             : 
    3437           0 :         if (bResize && bUndo)
    3438           0 :             getSdrDragView().EndUndo();
    3439             : 
    3440           0 :         return true;
    3441             :     }
    3442             : 
    3443           0 :     return false;
    3444             : }
    3445             : 
    3446           0 : Pointer SdrDragCrook::GetSdrDragPointer() const
    3447             : {
    3448           0 :     return Pointer(POINTER_CROOK);
    3449             : }
    3450             : 
    3451             : 
    3452             : 
    3453           0 : TYPEINIT1(SdrDragDistort,SdrDragMethod);
    3454             : 
    3455           0 : SdrDragDistort::SdrDragDistort(SdrDragView& rNewView)
    3456             : :   SdrDragMethod(rNewView),
    3457             :     nPolyPt(0),
    3458             :     bContortionAllowed(false),
    3459             :     bNoContortionAllowed(false),
    3460           0 :     bContortion(false)
    3461             : {
    3462           0 : }
    3463             : 
    3464           0 : void SdrDragDistort::TakeSdrDragComment(OUString& rStr) const
    3465             : {
    3466           0 :     ImpTakeDescriptionStr(STR_DragMethDistort, rStr);
    3467             : 
    3468           0 :     OUString aStr;
    3469             : 
    3470           0 :     rStr += " (x=";
    3471           0 :     getSdrDragView().GetModel()->TakeMetricStr(DragStat().GetDX(), aStr);
    3472           0 :     rStr += aStr + " y=";
    3473           0 :     getSdrDragView().GetModel()->TakeMetricStr(DragStat().GetDY(), aStr);
    3474           0 :     rStr += aStr + ")";
    3475             : 
    3476           0 :     if(getSdrDragView().IsDragWithCopy())
    3477           0 :         rStr += ImpGetResStr(STR_EditWithCopy);
    3478           0 : }
    3479             : 
    3480           0 : void SdrDragDistort::createSdrDragEntries()
    3481             : {
    3482             :     // Add extended frame raster first, so it will be behind objects
    3483           0 :     if(getSdrDragView().GetSdrPageView())
    3484             :     {
    3485           0 :         const basegfx::B2DPolyPolygon aDragRaster(impCreateDragRaster(*getSdrDragView().GetSdrPageView(), GetMarkedRect()));
    3486             : 
    3487           0 :         if(aDragRaster.count())
    3488             :         {
    3489           0 :             addSdrDragEntry(new SdrDragEntryPolyPolygon(aDragRaster));
    3490           0 :         }
    3491             :     }
    3492             : 
    3493             :     // call parent
    3494           0 :     SdrDragMethod::createSdrDragEntries();
    3495           0 : }
    3496             : 
    3497           0 : bool SdrDragDistort::BeginSdrDrag()
    3498             : {
    3499           0 :     bContortionAllowed=getSdrDragView().IsDistortAllowed(false);
    3500           0 :     bNoContortionAllowed=getSdrDragView().IsDistortAllowed(true);
    3501             : 
    3502           0 :     if (bContortionAllowed || bNoContortionAllowed)
    3503             :     {
    3504           0 :         SdrHdlKind eKind=GetDragHdlKind();
    3505           0 :         nPolyPt=0xFFFF;
    3506             : 
    3507           0 :         if (eKind==HDL_UPLFT) nPolyPt=0;
    3508           0 :         if (eKind==HDL_UPRGT) nPolyPt=1;
    3509           0 :         if (eKind==HDL_LWRGT) nPolyPt=2;
    3510           0 :         if (eKind==HDL_LWLFT) nPolyPt=3;
    3511           0 :         if (nPolyPt>3) return false;
    3512             : 
    3513           0 :         aMarkRect=GetMarkedRect();
    3514           0 :         aDistortedRect=XPolygon(aMarkRect);
    3515           0 :         Show();
    3516           0 :         return true;
    3517             :     }
    3518             :     else
    3519             :     {
    3520           0 :         return false;
    3521             :     }
    3522             : }
    3523             : 
    3524           0 : void SdrDragDistort::_MovAllPoints(basegfx::B2DPolyPolygon& rTarget)
    3525             : {
    3526           0 :     if (bContortion)
    3527             :     {
    3528           0 :         SdrPageView* pPV = getSdrDragView().GetSdrPageView();
    3529             : 
    3530           0 :         if(pPV)
    3531             :         {
    3532           0 :             if (pPV->HasMarkedObjPageView())
    3533             :             {
    3534           0 :                 basegfx::B2DPolyPolygon aDragPolygon(rTarget);
    3535           0 :                 const basegfx::B2DRange aOriginalRange(aMarkRect.Left(), aMarkRect.Top(), aMarkRect.Right(), aMarkRect.Bottom());
    3536           0 :                 const basegfx::B2DPoint aTopLeft(aDistortedRect[0].X(), aDistortedRect[0].Y());
    3537           0 :                 const basegfx::B2DPoint aTopRight(aDistortedRect[1].X(), aDistortedRect[1].Y());
    3538           0 :                 const basegfx::B2DPoint aBottomLeft(aDistortedRect[3].X(), aDistortedRect[3].Y());
    3539           0 :                 const basegfx::B2DPoint aBottomRight(aDistortedRect[2].X(), aDistortedRect[2].Y());
    3540             : 
    3541           0 :                 aDragPolygon = basegfx::tools::distort(aDragPolygon, aOriginalRange, aTopLeft, aTopRight, aBottomLeft, aBottomRight);
    3542           0 :                 rTarget = aDragPolygon;
    3543             :             }
    3544             :         }
    3545             :     }
    3546           0 : }
    3547             : 
    3548           0 : void SdrDragDistort::MoveSdrDrag(const Point& rPnt)
    3549             : {
    3550           0 :     if (DragStat().CheckMinMoved(rPnt))
    3551             :     {
    3552           0 :         Point aPnt(GetSnapPos(rPnt));
    3553             : 
    3554           0 :         if (getSdrDragView().IsOrtho())
    3555           0 :             OrthoDistance8(DragStat().GetStart(),aPnt,getSdrDragView().IsBigOrtho());
    3556             : 
    3557           0 :         bool bNeuContortion=(bContortionAllowed && !getSdrDragView().IsCrookNoContortion()) || !bNoContortionAllowed;
    3558             : 
    3559           0 :         if (bNeuContortion!=bContortion || aDistortedRect[nPolyPt]!=aPnt)
    3560             :         {
    3561           0 :             Hide();
    3562           0 :             aDistortedRect[nPolyPt]=aPnt;
    3563           0 :             bContortion=bNeuContortion;
    3564           0 :             DragStat().NextMove(aPnt);
    3565           0 :             Show();
    3566             :         }
    3567             :     }
    3568           0 : }
    3569             : 
    3570           0 : bool SdrDragDistort::EndSdrDrag(bool bCopy)
    3571             : {
    3572           0 :     Hide();
    3573           0 :     bool bDoDistort=DragStat().GetDX()!=0 || DragStat().GetDY()!=0;
    3574             : 
    3575           0 :     if (bDoDistort)
    3576             :     {
    3577           0 :         getSdrDragView().DistortMarkedObj(aMarkRect,aDistortedRect,!bContortion,bCopy);
    3578           0 :         return true;
    3579             :     }
    3580             : 
    3581           0 :     return false;
    3582             : }
    3583             : 
    3584           0 : Pointer SdrDragDistort::GetSdrDragPointer() const
    3585             : {
    3586           0 :     return Pointer(POINTER_REFHAND);
    3587             : }
    3588             : 
    3589           0 : void SdrDragDistort::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
    3590             : {
    3591           0 :     const bool bDoDistort(DragStat().GetDX()!=0 || DragStat().GetDY()!=0);
    3592             : 
    3593           0 :     if (bDoDistort)
    3594             :     {
    3595           0 :         getSdrDragView().ImpDistortObj(&rTarget, aMarkRect, aDistortedRect, !bContortion);
    3596             :     }
    3597           0 : }
    3598             : 
    3599           0 : void SdrDragDistort::applyCurrentTransformationToPolyPolygon(basegfx::B2DPolyPolygon& rTarget)
    3600             : {
    3601             :     // use helper derived from old stuff
    3602           0 :     _MovAllPoints(rTarget);
    3603           0 : }
    3604             : 
    3605             : 
    3606             : 
    3607           0 : TYPEINIT1(SdrDragCrop,SdrDragResize);
    3608             : 
    3609           0 : SdrDragCrop::SdrDragCrop(SdrDragView& rNewView)
    3610           0 : :   SdrDragObjOwn(rNewView)
    3611             : {
    3612             :     // switch off solid dragging for crop; it just makes no sense since showing
    3613             :     // a 50% transparent object above the original will not be visible
    3614           0 :     setSolidDraggingActive(false);
    3615           0 : }
    3616             : 
    3617           0 : void SdrDragCrop::TakeSdrDragComment(OUString& rStr) const
    3618             : {
    3619           0 :     ImpTakeDescriptionStr(STR_DragMethCrop, rStr);
    3620             : 
    3621           0 :     OUString aStr;
    3622             : 
    3623           0 :     rStr += " (x=";
    3624           0 :     getSdrDragView().GetModel()->TakeMetricStr(DragStat().GetDX(), aStr);
    3625           0 :     rStr += aStr + " y=";
    3626           0 :     getSdrDragView().GetModel()->TakeMetricStr(DragStat().GetDY(), aStr);
    3627           0 :     rStr += aStr + ")";
    3628             : 
    3629           0 :     if(getSdrDragView().IsDragWithCopy())
    3630           0 :         rStr += ImpGetResStr(STR_EditWithCopy);
    3631           0 : }
    3632             : 
    3633           0 : bool SdrDragCrop::BeginSdrDrag()
    3634             : {
    3635             :     // call parent
    3636           0 :     bool bRetval(SdrDragObjOwn::BeginSdrDrag());
    3637             : 
    3638           0 :     if(!GetDragHdl())
    3639             :     {
    3640             :         // we need the DragHdl, break if not there
    3641           0 :         bRetval = false;
    3642             :     }
    3643             : 
    3644           0 :     return bRetval;
    3645             : }
    3646             : 
    3647           0 : bool SdrDragCrop::EndSdrDrag(bool /*bCopy*/)
    3648             : {
    3649           0 :     Hide();
    3650             : 
    3651           0 :     if( DragStat().GetDX()==0 && DragStat().GetDY()==0 )
    3652           0 :         return false;
    3653             : 
    3654           0 :     const SdrMarkList& rMarkList = getSdrDragView().GetMarkedObjectList();
    3655             : 
    3656           0 :     if( rMarkList.GetMarkCount() != 1 )
    3657           0 :         return false;
    3658             : 
    3659           0 :     SdrGrafObj* pObj = dynamic_cast<SdrGrafObj*>( rMarkList.GetMark( 0 )->GetMarkedSdrObj() );
    3660             : 
    3661           0 :     if( !pObj || (pObj->GetGraphicType() == GRAPHIC_NONE) || (pObj->GetGraphicType() == GRAPHIC_DEFAULT) )
    3662           0 :         return false;
    3663             : 
    3664           0 :     const GraphicObject& rGraphicObject = pObj->GetGraphicObject();
    3665           0 :     const MapMode aMapMode100thmm(MAP_100TH_MM);
    3666           0 :     Size aGraphicSize(rGraphicObject.GetPrefSize());
    3667             : 
    3668           0 :     if( MAP_PIXEL == rGraphicObject.GetPrefMapMode().GetMapUnit() )
    3669           0 :         aGraphicSize = Application::GetDefaultDevice()->PixelToLogic( aGraphicSize, aMapMode100thmm );
    3670             :     else
    3671           0 :         aGraphicSize = Application::GetDefaultDevice()->LogicToLogic( aGraphicSize, rGraphicObject.GetPrefMapMode(), aMapMode100thmm);
    3672             : 
    3673           0 :     if( aGraphicSize.A() == 0 || aGraphicSize.B() == 0 )
    3674           0 :         return false;
    3675             : 
    3676           0 :     const SdrGrafCropItem& rOldCrop = (const SdrGrafCropItem&)pObj->GetMergedItem(SDRATTR_GRAFCROP);
    3677             : 
    3678           0 :     const bool bUndo = getSdrDragView().IsUndoEnabled();
    3679             : 
    3680           0 :     if( bUndo )
    3681             :     {
    3682           0 :         OUString aUndoStr;
    3683           0 :         ImpTakeDescriptionStr(STR_DragMethCrop, aUndoStr);
    3684             : 
    3685           0 :         getSdrDragView().BegUndo( aUndoStr );
    3686           0 :         getSdrDragView().AddUndo( getSdrDragView().GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
    3687             :         // also need attr undo, the SdrGrafCropItem will be changed
    3688           0 :         getSdrDragView().AddUndo( getSdrDragView().GetModel()->GetSdrUndoFactory().CreateUndoAttrObject(*pObj));
    3689             :     }
    3690             : 
    3691             :     // new part to comute the user's drag activities
    3692             :     // get the original objects transformation
    3693           0 :     basegfx::B2DHomMatrix aOriginalMatrix;
    3694           0 :     basegfx::B2DPolyPolygon aPolyPolygon;
    3695           0 :     bool bShearCorrected(false);
    3696             : 
    3697             :     // get transformation from object
    3698           0 :     pObj->TRGetBaseGeometry(aOriginalMatrix, aPolyPolygon);
    3699             : 
    3700             :     {   // TTTT correct shear, it comes currently mirrored from TRGetBaseGeometry, can be removed with aw080
    3701           0 :         basegfx::B2DTuple aScale;
    3702           0 :         basegfx::B2DTuple aTranslate;
    3703           0 :         double fRotate(0.0), fShearX(0.0);
    3704             : 
    3705           0 :         aOriginalMatrix.decompose(aScale, aTranslate, fRotate, fShearX);
    3706             : 
    3707           0 :         if(!basegfx::fTools::equalZero(fShearX))
    3708             :         {
    3709           0 :             bShearCorrected = true;
    3710           0 :             aOriginalMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
    3711             :                 aScale,
    3712             :                 -fShearX,
    3713             :                 fRotate,
    3714           0 :                 aTranslate);
    3715           0 :         }
    3716             :     }
    3717             : 
    3718             :     // invert it to be able to work on unit coordinates
    3719           0 :     basegfx::B2DHomMatrix aInverse(aOriginalMatrix);
    3720             : 
    3721           0 :     aInverse.invert();
    3722             : 
    3723             :     // gererate start point of original drag vector in unit coordinates (the
    3724             :     // vis-a-vis of the drag point)
    3725           0 :     basegfx::B2DPoint aLocalStart(0.0, 0.0);
    3726           0 :     bool bOnAxis(false);
    3727             : 
    3728           0 :     switch(GetDragHdlKind())
    3729             :     {
    3730           0 :         case HDL_UPLFT: aLocalStart.setX(1.0); aLocalStart.setY(1.0); break;
    3731           0 :         case HDL_UPPER: aLocalStart.setX(0.5); aLocalStart.setY(1.0); bOnAxis = true; break;
    3732           0 :         case HDL_UPRGT: aLocalStart.setX(0.0); aLocalStart.setY(1.0); break;
    3733           0 :         case HDL_LEFT : aLocalStart.setX(1.0); aLocalStart.setY(0.5); bOnAxis = true; break;
    3734           0 :         case HDL_RIGHT: aLocalStart.setX(0.0); aLocalStart.setY(0.5); bOnAxis = true; break;
    3735           0 :         case HDL_LWLFT: aLocalStart.setX(1.0); aLocalStart.setY(0.0); break;
    3736           0 :         case HDL_LOWER: aLocalStart.setX(0.5); aLocalStart.setY(0.0); bOnAxis = true; break;
    3737           0 :         case HDL_LWRGT: aLocalStart.setX(0.0); aLocalStart.setY(0.0); break;
    3738           0 :         default: break;
    3739             :     }
    3740             : 
    3741             :     // create the current drag position in unit coordinates
    3742           0 :     basegfx::B2DPoint aLocalCurrent(aInverse * basegfx::B2DPoint(DragStat().GetNow().X(), DragStat().GetNow().Y()));
    3743             : 
    3744             :     // if one of the edge handles is used, limit to X or Y drag only
    3745           0 :     if(bOnAxis)
    3746             :     {
    3747           0 :         if(basegfx::fTools::equal(aLocalStart.getX(), 0.5))
    3748             :         {
    3749           0 :             aLocalCurrent.setX(aLocalStart.getX());
    3750             :         }
    3751             :         else
    3752             :         {
    3753           0 :             aLocalCurrent.setY(aLocalStart.getY());
    3754             :         }
    3755             :     }
    3756             : 
    3757             :     // create internal change in unit coordinates
    3758           0 :     basegfx::B2DHomMatrix aDiscreteChangeMatrix;
    3759             : 
    3760           0 :     if(!basegfx::fTools::equal(aLocalCurrent.getX(), aLocalStart.getX()))
    3761             :     {
    3762           0 :         if(aLocalStart.getX() < 0.5)
    3763             :         {
    3764           0 :             aDiscreteChangeMatrix.scale(aLocalCurrent.getX(), 1.0);
    3765             :         }
    3766             :         else
    3767             :         {
    3768           0 :             aDiscreteChangeMatrix.scale(1.0 - aLocalCurrent.getX(), 1.0);
    3769           0 :             aDiscreteChangeMatrix.translate(aLocalCurrent.getX(), 0.0);
    3770             :         }
    3771             :     }
    3772             : 
    3773           0 :     if(!basegfx::fTools::equal(aLocalCurrent.getY(), aLocalStart.getY()))
    3774             :     {
    3775           0 :         if(aLocalStart.getY() < 0.5)
    3776             :         {
    3777           0 :             aDiscreteChangeMatrix.scale(1.0, aLocalCurrent.getY());
    3778             :         }
    3779             :         else
    3780             :         {
    3781           0 :             aDiscreteChangeMatrix.scale(1.0, 1.0 - aLocalCurrent.getY());
    3782           0 :             aDiscreteChangeMatrix.translate(0.0, aLocalCurrent.getY());
    3783             :         }
    3784             :     }
    3785             : 
    3786             :     // preparematrix to apply to object; evtl. back-correct shear
    3787           0 :     basegfx::B2DHomMatrix aNewObjectMatrix(aOriginalMatrix * aDiscreteChangeMatrix);
    3788             : 
    3789           0 :     if(bShearCorrected)
    3790             :     {
    3791             :         // TTTT back-correct shear
    3792           0 :         basegfx::B2DTuple aScale;
    3793           0 :         basegfx::B2DTuple aTranslate;
    3794           0 :         double fRotate(0.0), fShearX(0.0);
    3795             : 
    3796           0 :         aNewObjectMatrix.decompose(aScale, aTranslate, fRotate, fShearX);
    3797           0 :         aNewObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
    3798             :             aScale,
    3799             :             -fShearX,
    3800             :             fRotate,
    3801           0 :             aTranslate);
    3802             :     }
    3803             : 
    3804             :     // apply change to object by applying the unit coordinate change followed
    3805             :     // by the original change
    3806           0 :     pObj->TRSetBaseGeometry(aNewObjectMatrix, aPolyPolygon);
    3807             : 
    3808             :     // the following old code uses aOldRect/aNewRect to calculate the crop change for
    3809             :     // the crop item. It implies unrotated objects, so create the unrotated original
    3810             :     // erctangle and the unrotated modified rectangle. Latter can in case of shear and/or
    3811             :     // rotation not be fetched by using
    3812             : 
    3813             :     //Rectangle aNewRect( pObj->GetLogicRect() );
    3814             : 
    3815             :     // as it was done before because the top-left of that new rect *will* have an offset
    3816             :     // caused by the evtl. existing shear and/or rotation, so calculate a unrotated
    3817             :     // rectangle how it would be as a result when appling the unit coordinate change
    3818             :     // to the unrotated original transformation.
    3819           0 :     basegfx::B2DTuple aScale;
    3820           0 :     basegfx::B2DTuple aTranslate;
    3821             :     double fRotate, fShearX;
    3822             : 
    3823             :     // get access to scale and translate
    3824           0 :     aOriginalMatrix.decompose(aScale, aTranslate, fRotate, fShearX);
    3825             : 
    3826             :     // prepare unsheared/unrotated versions of the old and new transformation
    3827             :     const basegfx::B2DHomMatrix aMatrixOriginalNoShearNoRotate(
    3828             :         basegfx::tools::createScaleTranslateB2DHomMatrix(
    3829             :             basegfx::absolute(aScale),
    3830           0 :             aTranslate));
    3831             : 
    3832             :     // create the ranges for these
    3833           0 :     basegfx::B2DRange aRangeOriginalNoShearNoRotate(0.0, 0.0, 1.0, 1.0);
    3834           0 :     basegfx::B2DRange aRangeNewNoShearNoRotate(0.0, 0.0, 1.0, 1.0);
    3835             : 
    3836           0 :     aRangeOriginalNoShearNoRotate.transform(aMatrixOriginalNoShearNoRotate);
    3837           0 :     aRangeNewNoShearNoRotate.transform(aMatrixOriginalNoShearNoRotate * aDiscreteChangeMatrix);
    3838             : 
    3839             :     // extract the old Rectangle structures
    3840             :     Rectangle aOldRect(
    3841             :         basegfx::fround(aRangeOriginalNoShearNoRotate.getMinX()),
    3842             :         basegfx::fround(aRangeOriginalNoShearNoRotate.getMinY()),
    3843             :         basegfx::fround(aRangeOriginalNoShearNoRotate.getMaxX()),
    3844           0 :         basegfx::fround(aRangeOriginalNoShearNoRotate.getMaxY()));
    3845             :     Rectangle aNewRect(
    3846             :         basegfx::fround(aRangeNewNoShearNoRotate.getMinX()),
    3847             :         basegfx::fround(aRangeNewNoShearNoRotate.getMinY()),
    3848             :         basegfx::fround(aRangeNewNoShearNoRotate.getMaxX()),
    3849           0 :         basegfx::fround(aRangeNewNoShearNoRotate.getMaxY()));
    3850             : 
    3851             :     // continue with the old original stuff
    3852           0 :     double fScaleX = ( aGraphicSize.Width() - rOldCrop.GetLeft() - rOldCrop.GetRight() ) / (double)aOldRect.GetWidth();
    3853           0 :     double fScaleY = ( aGraphicSize.Height() - rOldCrop.GetTop() - rOldCrop.GetBottom() ) / (double)aOldRect.GetHeight();
    3854             : 
    3855             :     // not needed since the modification is done in unit coordinates, free from shear/rotate and mirror
    3856             :     // // TTTT may be removed or exhanged by other stuff in aw080
    3857             :     // // to correct the never working combination of cropped images and mirroring
    3858             :     // // I have to correct the rectangles the calculation is based on here. In the current
    3859             :     // // core geometry stuff a vertical mirror is expressed as 180 degree rotation. All
    3860             :     // // this can be removed again when aw080 will have cleaned up the old
    3861             :     // // (non-)transformation mess in the core.
    3862             :     // if(18000 == pObj->GetGeoStat().nDrehWink)
    3863             :     // {
    3864             :     //     // old notation of vertical mirror, need to correct diffs since both rects
    3865             :     //     // are rotated by 180 degrees
    3866             :     //     aOldRect = Rectangle(aOldRect.TopLeft() - (aOldRect.BottomRight() - aOldRect.TopLeft()), aOldRect.TopLeft());
    3867             :     //     aNewRect = Rectangle(aNewRect.TopLeft() - (aNewRect.BottomRight() - aNewRect.TopLeft()), aNewRect.TopLeft());
    3868             :     // }
    3869             : 
    3870           0 :     sal_Int32 nDiffLeft = aNewRect.Left() - aOldRect.Left();
    3871           0 :     sal_Int32 nDiffTop = aNewRect.Top() - aOldRect.Top();
    3872           0 :     sal_Int32 nDiffRight = aNewRect.Right() - aOldRect.Right();
    3873           0 :     sal_Int32 nDiffBottom = aNewRect.Bottom() - aOldRect.Bottom();
    3874             : 
    3875           0 :     if(pObj->IsMirrored())
    3876             :     {
    3877             :         // mirrored X or Y, for old stuff, exchange X
    3878             :         // TTTT: check for aw080
    3879           0 :         sal_Int32 nTmp(nDiffLeft);
    3880           0 :         nDiffLeft = -nDiffRight;
    3881           0 :         nDiffRight = -nTmp;
    3882             :     }
    3883             : 
    3884           0 :     sal_Int32 nLeftCrop = static_cast<sal_Int32>( rOldCrop.GetLeft() + nDiffLeft * fScaleX );
    3885           0 :     sal_Int32 nTopCrop = static_cast<sal_Int32>( rOldCrop.GetTop() + nDiffTop * fScaleY );
    3886           0 :     sal_Int32 nRightCrop = static_cast<sal_Int32>( rOldCrop.GetRight() - nDiffRight * fScaleX );
    3887           0 :     sal_Int32 nBottomCrop = static_cast<sal_Int32>( rOldCrop.GetBottom() - nDiffBottom * fScaleY );
    3888             : 
    3889           0 :     SfxItemPool& rPool = getSdrDragView().GetModel()->GetItemPool();
    3890           0 :     SfxItemSet aSet( rPool, SDRATTR_GRAFCROP, SDRATTR_GRAFCROP );
    3891           0 :     aSet.Put( SdrGrafCropItem( nLeftCrop, nTopCrop, nRightCrop, nBottomCrop ) );
    3892           0 :     getSdrDragView().SetAttributes( aSet, false );
    3893             : 
    3894           0 :     if( bUndo )
    3895           0 :         getSdrDragView().EndUndo();
    3896             : 
    3897           0 :     return true;
    3898             : }
    3899             : 
    3900           0 : Pointer SdrDragCrop::GetSdrDragPointer() const
    3901             : {
    3902           0 :     return Pointer(POINTER_CROP);
    3903             : }
    3904             : 
    3905             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10