/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
void SdrDragEntrySdrObject::prepareCurrentState(SdrDragMethod& rDragMethod)
{ // for the moment, i need to re-create the clone in all cases. I need to figure // out when clone and original have the same class, so that i can use operator= // in those cases
if(mbModify && mxClone)
{ // choose source for geometry data
pSource = mxClone.get();
}
// use the view-independent primitive representation (without // evtl. GridOffset, that may be applied to the DragEntry individually)
drawinglayer::primitive2d::Primitive2DContainer xRetval;
pSource->GetViewContact().getViewIndependentPrimitive2DContainer(xRetval); return xRetval;
}
SdrDragEntryPrimitive2DSequence::SdrDragEntryPrimitive2DSequence(
drawinglayer::primitive2d::Primitive2DContainer&& rSequence)
: maPrimitive2DSequence(std::move(rSequence))
{ // add parts to transparent overlay stuff if necessary
setAddToTransparent(true);
}
void SdrDragMethod::createSdrDragEntryForSdrObject(const SdrObject& rOriginal)
{ // add full object drag; Clone() at the object has to work // for this
addSdrDragEntry(std::unique_ptr<SdrDragEntry>(new SdrDragEntrySdrObject(rOriginal, true/*bModify*/)));
}
void SdrDragMethod::insertNewlyCreatedOverlayObjectForSdrDragMethod(
std::unique_ptr<sdr::overlay::OverlayObject> pOverlayObject, const sdr::contact::ObjectContact& rObjectContact,
sdr::overlay::OverlayManager& rOverlayManager)
{ // check if we have an OverlayObject if(!pOverlayObject)
{ return;
}
// add to OverlayManager
rOverlayManager.add(*pOverlayObject);
if(!bAddWireframe && !pCandidate->HasLineStyle())
{ // add wireframe for objects without outline
bAddWireframe = true;
}
if(!bSuppressFullDrag)
{ // add full object drag; Clone() at the object has to work // for this
createSdrDragEntryForSdrObject(*pCandidate);
}
if(bAddWireframe)
{ // when dragging a 50% transparent copy of a filled or not filled object without // outline, this is normally hard to see. Add extra wireframe in that case. This // works nice e.g. with text frames etc.
addSdrDragEntry(std::unique_ptr<SdrDragEntry>(new SdrDragEntryPolyPolygon(pCandidate->TakeXorPoly())));
}
}
}
}
}
}
}
}
SdrObject* SdrDragMethod::GetDragObj() const
{
SdrObject* pObj=nullptr; if (getSdrDragView().mpDragHdl!=nullptr) pObj=getSdrDragView().mpDragHdl->GetObj(); if (pObj==nullptr) pObj=getSdrDragView().mpMarkedObj; return pObj;
}
SdrPageView* SdrDragMethod::GetDragPV() const
{
SdrPageView* pPV=nullptr; if (getSdrDragView().mpDragHdl!=nullptr) pPV=getSdrDragView().mpDragHdl->GetPageView(); if (pPV==nullptr) pPV=getSdrDragView().mpMarkedPV; return pPV;
}
void SdrDragMethod::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
{ // the original applies the transformation using TRGetBaseGeometry/TRSetBaseGeometry. // Later this should be the only needed one for linear transforms (not for SdrDragCrook and // SdrDragDistort, those are NOT linear). Currently, this can not yet be used since the // special handling of rotate/mirror due to the not-being-able to handle it in the old // drawinglayer stuff. Text would currently not correctly be mirrored in the preview.
basegfx::B2DHomMatrix aObjectTransform;
basegfx::B2DPolyPolygon aObjectPolyPolygon; bool bPolyUsed(rTarget.TRGetBaseGeometry(aObjectTransform, aObjectPolyPolygon));
// apply transform to object transform
aObjectTransform *= getCurrentTransformation();
if(bPolyUsed)
{ // do something special since the object size is in the polygon // break up matrix to get the scale const basegfx::utils::B2DHomMatrixBufferedDecompose aTmpDecomp(aObjectTransform);
// get polygon's position and size const basegfx::B2DRange aPolyRange(aObjectPolyPolygon.getB2DRange());
// get the scaling factors (do not mirror, this is in the object transformation) constdouble fScaleX(fabs(aTmpDecomp.getScale().getX()) / (basegfx::fTools::equalZero(aPolyRange.getWidth()) ? 1.0 : aPolyRange.getWidth())); constdouble fScaleY(fabs(aTmpDecomp.getScale().getY()) / (basegfx::fTools::equalZero(aPolyRange.getHeight()) ? 1.0 : aPolyRange.getHeight()));
void SdrDragMethod::CreateOverlayGeometry(
sdr::overlay::OverlayManager& rOverlayManager, const sdr::contact::ObjectContact& rObjectContact, bool bIsGeometrySizeValid)
{ // We do client-side object manipulation with the Kit API if (comphelper::LibreOfficeKit::isActive()) return;
// create SdrDragEntries on demand if(maSdrDragEntries.empty())
{
createSdrDragEntries();
}
// if there are entries, derive OverlayObjects from the entries, including // modification from current interactive state if(!maSdrDragEntries.empty())
{ // #i54102# SdrDragEntrySdrObject creates clones of SdrObjects as base for creating the needed // primitives, holding the original and the clone. If connectors (Edges) are involved, // the cloned connectors need to be connected to the cloned SdrObjects (after cloning // they are connected to the original SdrObjects). To do so, trigger the preparation // steps for SdrDragEntrySdrObject, save an association of (orig, clone) in a helper // and evtl. remember if it was an edge
SdrObjectAndCloneMap aOriginalAndClones;
std::vector< SdrEdgeObj* > aEdges;
// #i54102# execute prepareCurrentState for all SdrDragEntrySdrObject, register pair of original and // clone, remember edges for(autoconst & a: maSdrDragEntries)
{
SdrDragEntrySdrObject* pSdrDragEntrySdrObject = dynamic_cast< SdrDragEntrySdrObject*>(a.get());
// #i54102# if there are edges, reconnect their ends to the corresponding clones (if found) for(SdrEdgeObj* pSdrEdgeObj: aEdges)
{
SdrObject* pConnectedTo = pSdrEdgeObj->GetConnectedNode(true);
bool SdrDragMethod::DoAddConnectorOverlays()
{ // these conditions are translated from SdrDragView::ImpDrawEdgeXor const SdrMarkList& rMarkedNodes = getSdrDragView().GetEdgesOfMarkedNodes();
if(aEdgePolygon.count())
{ // this polygon is a temporary calculated connector path, so it is not possible to fetch // the needed primitives directly from the pEdge object which does not get changed. If full // drag is on, use the SdrObjects ItemSet to create an adequate representation bool bUseSolidDragging(getSolidDraggingActive());
if(bUseSolidDragging)
{ // switch off solid dragging if connector is not visible if(!pEdge->HasLineStyle())
{
bUseSolidDragging = false;
}
}
if (eKind==SdrHdlKind::MirrorAxis)
{ if (pH1==nullptr || pH2==nullptr)
{
OSL_FAIL("SdrDragMovHdl::BeginSdrDrag(): Moving the axis of reflection: reference handles not found."); returnfalse;
}
DragStat().SetActionRect(tools::Rectangle(pH1->GetPos(),pH2->GetPos()));
} else
{
Point aPt(GetDragHdl()->GetPos());
DragStat().SetActionRect(tools::Rectangle(aPt,aPt));
}
returntrue;
}
void SdrDragMovHdl::MoveSdrDrag(const Point& rNoSnapPnt)
{
Point aPnt(rNoSnapPnt);
if ( !(GetDragHdl() && DragStat().CheckMinMoved(rNoSnapPnt))) return;
if (GetDragHdl()->GetKind()==SdrHdlKind::MirrorAxis)
{
SdrHdl* pH1=GetHdlList().GetHdl(SdrHdlKind::Ref1);
SdrHdl* pH2=GetHdlList().GetHdl(SdrHdlKind::Ref2);
if (pH1==nullptr || pH2==nullptr) return;
if (!DragStat().IsNoSnap())
{
tools::Long nBestXSnap=0;
tools::Long nBestYSnap=0; bool bXSnapped=false; bool bYSnapped=false;
Point aDif(aPnt-DragStat().GetStart());
getSdrDragView().CheckSnap(Ref1()+aDif,nBestXSnap,nBestYSnap,bXSnapped,bYSnapped);
getSdrDragView().CheckSnap(Ref2()+aDif,nBestXSnap,nBestYSnap,bXSnapped,bYSnapped);
aPnt.AdjustX(nBestXSnap );
aPnt.AdjustY(nBestYSnap );
}
if (aPnt!=DragStat().GetNow())
{
Hide();
DragStat().NextMove(aPnt);
Point aDif(DragStat().GetNow()-DragStat().GetStart());
pH1->SetPos(Ref1()+aDif);
pH2->SetPos(Ref2()+aDif);
if (getSdrDragView().IsAngleSnapEnabled())
nSA=getSdrDragView().GetSnapAngle();
if (getSdrDragView().IsMirrorAllowed(true,true))
{ // limited if (!getSdrDragView().IsMirrorAllowed()) nSA=4500_deg100; if (!getSdrDragView().IsMirrorAllowed(true)) nSA=9000_deg100;
}
if (getSdrDragView().IsOrtho() && nSA!=9000_deg100)
nSA=4500_deg100;
if (nSA)
{ // angle snapping
SdrHdlKind eRef=SdrHdlKind::Ref1;
if (GetDragHdl()->GetKind()==SdrHdlKind::Ref1)
eRef=SdrHdlKind::Ref2;
SdrHdl* pH=GetHdlList().GetHdl(eRef);
if (pH!=nullptr)
{
Point aRef(pH->GetPos());
Degree100 nAngle=NormAngle36000(GetAngle(aPnt-aRef));
Degree100 nNewAngle=nAngle;
nNewAngle+=nSA/2_deg100;
nNewAngle/=nSA;
nNewAngle*=nSA;
nNewAngle=NormAngle36000(nNewAngle); double a=toRadians(nNewAngle-nAngle); double nSin=sin(a); double nCos=cos(a);
RotatePoint(aPnt,aRef,nSin,nCos);
// eliminate rounding errors for certain values if (nSA==9000_deg100)
{ if (nNewAngle==0_deg100 || nNewAngle==18000_deg100) aPnt.setY(aRef.Y() ); if (nNewAngle==9000_deg100 || nNewAngle==27000_deg100) aPnt.setX(aRef.X() );
}
if (nSA==4500_deg100)
OrthoDistance8(aRef,aPnt,true);
}
}
if (aPnt!=DragStat().GetNow())
{
Hide();
DragStat().NextMove(aPnt);
GetDragHdl()->SetPos(DragStat().GetNow());
SdrHdl* pHM = GetHdlList().GetHdl(SdrHdlKind::MirrorAxis);
// potentially no wireframe needed, full drag works
bAddWireframe = false;
}
}
if(!bAddWireframe)
{ // check for extra conditions for wireframe, e.g. no border at // objects if(!mxClone->HasLineStyle())
{
bAddWireframe = true;
}
}
if(bAddWireframe)
{ // use wireframe poly when full drag is off or did not work
aDragPolyPolygon = mxClone->TakeXorPoly();
}
// add evtl. extra DragPolyPolygon const basegfx::B2DPolyPolygon aSpecialDragPolyPolygon(mxClone->getSpecialDragPoly(DragStat()));
OUString SdrDragObjOwn::GetSdrDragComment() const
{
OUString aStr; // #i103058# get info string from the clone preferred, the original will // not be changed. For security, use original as fallback if(mxClone)
{
aStr = mxClone->getSpecialDragComment(DragStat());
} else
{ const SdrObject* pObj = GetDragObj();
if (!DragStat().CheckMinMoved(rNoSnapPnt)) // Not moved by the minimum threshold. Nothing to do. return;
Hide();
DragStat().NextMove(aPnt);
// since SdrDragObjOwn currently supports no transformation of // existing SdrDragEntries but only their recreation, a recreation // after every move is needed in this mode. Delete existing // SdrDragEntries here to force their recreation in the following Show().
clearSdrDragEntries();
// delete current clone (after the last reference to it is deleted above)
mxClone.clear();
// create a new clone and modify to current drag state
mxClone = pObj->getFullDragClone();
mxClone->applySpecialDrag(DragStat());
// AutoGrowWidth may change for SdrTextObj due to the automatism used // with bDisableAutoWidthOnDragging, so not only geometry changes but // also this (pretty indirect) property change is possible. If it gets // changed, it needs to be copied to the original since nothing will // happen when it only changes in the drag clone constbool bOldAutoGrowWidth(pObj->GetMergedItem(SDRATTR_TEXT_AUTOGROWWIDTH).GetValue()); constbool bNewAutoGrowWidth(mxClone->GetMergedItem(SDRATTR_TEXT_AUTOGROWWIDTH).GetValue());
if (bOldAutoGrowWidth != bNewAutoGrowWidth)
{
GetDragObj()->SetMergedItem(makeSdrTextAutoGrowWidthItem(bNewAutoGrowWidth));
}
// Maybe use operator = for setting changed object data (do not change selection in // view, this will destroy the interactor). This is possible since a clone is now // directly modified by the modifiers. Only SdrTableObj is adding own UNDOs // in its SdrTableObj::endSpecialDrag, so currently not possible. OTOH it uses // a CreateUndoGeoObject(), so maybe setting SetEndDragChangesAttributes is okay. I // will test this now
tools::Rectangle aBoundRect0;
bRet = pObj->applySpecialDrag(DragStat()); if (DragStat().IsEndDragChangesLayout())
{ auto pGeoUndo = dynamic_cast<SdrUndoGeoObj*>(pUndo.get()); if (pGeoUndo)
pGeoUndo->SetSkipChangeLayout(true);
}
void SdrDragMove::createSdrDragEntryForSdrObject(const SdrObject& rOriginal)
{ // use the view-independent primitive representation (without // evtl. GridOffset, that may be applied to the DragEntry individually)
drawinglayer::primitive2d::Primitive2DContainer xRetval;
rOriginal.GetViewContact().getViewIndependentPrimitive2DContainer(xRetval);
addSdrDragEntry(
std::unique_ptr<SdrDragEntry>( new SdrDragEntryPrimitive2DSequence(
std::move(xRetval))));
void SdrDragMove::ImpCheckSnap(const Point& rPt)
{
Point aPt(rPt);
SdrSnap nRet=SnapPos(aPt);
aPt-=rPt;
if (nRet & SdrSnap::XSNAPPED)
{ if (m_bXSnapped)
{ if (std::abs(aPt.X())<std::abs(m_nBestXSnap))
{
m_nBestXSnap=aPt.X();
}
} else
{
m_nBestXSnap=aPt.X();
m_bXSnapped=true;
}
}
if (!(nRet & SdrSnap::YSNAPPED)) return;
if (m_bYSnapped)
{ if (std::abs(aPt.Y())<std::abs(m_nBestYSnap))
{
m_nBestYSnap=aPt.Y();
}
} else
{
m_nBestYSnap=aPt.Y();
m_bYSnapped=true;
}
}
void SdrDragMove::MoveSdrDrag(const Point& rNoSnapPnt_)
{
m_nBestXSnap=0;
m_nBestYSnap=0;
m_bXSnapped=false;
m_bYSnapped=false;
Point aNoSnapPnt(rNoSnapPnt_); const tools::Rectangle& aSR=GetMarkedRect();
tools::Long nMovedx=aNoSnapPnt.X()-DragStat().GetStart().X();
tools::Long nMovedy=aNoSnapPnt.Y()-DragStat().GetStart().Y();
Point aLO(aSR.TopLeft()); aLO.AdjustX(nMovedx ); aLO.AdjustY(nMovedy );
Point aRU(aSR.BottomRight()); aRU.AdjustX(nMovedx ); aRU.AdjustY(nMovedy );
Point aLU(aLO.X(),aRU.Y());
Point aRO(aRU.X(),aLO.Y());
ImpCheckSnap(aLO);
if (!getSdrDragView().IsMoveSnapOnlyTopLeft())
{
ImpCheckSnap(aRO);
ImpCheckSnap(aLU);
ImpCheckSnap(aRU);
}
Point aPnt(aNoSnapPnt.X()+m_nBestXSnap,aNoSnapPnt.Y()+m_nBestYSnap); bool bOrtho=getSdrDragView().IsOrtho();
if (bOrtho)
OrthoDistance8(DragStat().GetStart(),aPnt,getSdrDragView().IsBigOrtho());
if (!DragStat().CheckMinMoved(aNoSnapPnt)) return;
Point aPt1(aPnt);
tools::Rectangle aLR(getSdrDragView().GetWorkArea()); bool bWorkArea=!aLR.IsEmpty(); bool bDragLimit=IsDragLimit();
if (bDragLimit || bWorkArea)
{
tools::Rectangle aSR2(GetMarkedRect());
Point aD(aPt1-DragStat().GetStart());
if (bDragLimit)
{
tools::Rectangle aR2(GetDragLimitRect());
if (bWorkArea)
aLR.Intersection(aR2); else
aLR=aR2;
}
if (aSR2.Left()>aLR.Left() || aSR2.Right()<aLR.Right())
{ // any space to move to?
aSR2.Move(aD.X(),0);
if (aSR2.Left()<aLR.Left())
{
aPt1.AdjustX( -(aSR2.Left()-aLR.Left()) );
} elseif (aSR2.Right()>aLR.Right())
{
aPt1.AdjustX( -(aSR2.Right()-aLR.Right()) );
}
} else
aPt1.setX(DragStat().GetStart().X() ); // no space to move to
if (aSR2.Top()>aLR.Top() || aSR2.Bottom()<aLR.Bottom())
{ // any space to move to?
aSR2.Move(0,aD.Y());
if (aSR2.Top()<aLR.Top())
{
aPt1.AdjustY( -(aSR2.Top()-aLR.Top()) );
} elseif (aSR2.Bottom()>aLR.Bottom())
{
aPt1.AdjustY( -(aSR2.Bottom()-aLR.Bottom()) );
}
} else
aPt1.setY(DragStat().GetStart().Y() ); // no space to move to
}
if (getSdrDragView().IsDraggingGluePoints())
{ // restrict gluepoints to the BoundRect of the Obj
aPt1-=DragStat().GetStart(); const SdrMarkList& rMarkList = GetMarkedObjectList(); const size_t nMarkCount = rMarkList.GetMarkCount();
for (sal_uInt16 nId : rPts)
{
sal_uInt16 nGlueNum=pGPL->FindGluePoint(nId);
if (nGlueNum!=SDRGLUEPOINT_NOTFOUND)
{
Point aPt((*pGPL)[nGlueNum].GetAbsolutePos(*pObj));
aPt+=aPt1; // move by this much if (aPt.X()<aBound.Left() ) aPt1.AdjustX( -(aPt.X()-aBound.Left()) ) ; if (aPt.X()>aBound.Right() ) aPt1.AdjustX( -(aPt.X()-aBound.Right()) ) ; if (aPt.Y()<aBound.Top() ) aPt1.AdjustY( -(aPt.Y()-aBound.Top()) ) ; if (aPt.Y()>aBound.Bottom()) aPt1.AdjustY( -(aPt.Y()-aBound.Bottom()) );
}
}
}
}
aPt1+=DragStat().GetStart();
}
if (bOrtho)
OrthoDistance8(DragStat().GetStart(),aPt1,false);
if (nullptr != pH)
{
Show();
DragStat().SetRef1(pH->GetPos());
nAngle0=GetAngle(DragStat().GetStart()-DragStat().GetRef1()); returntrue;
}
// RotGrfFlyFrame: Support rotation around center *without* Ref1 (normally // the rotation point) const tools::Rectangle aLocalMarkRect(getSdrDragView().GetMarkedObjRect());
nAngle=nNewAngle; double a = toRadians(nAngle); double nSin1=sin(a); // calculate now, so as little time as possible double nCos1=cos(a); // passes between Hide() and Show()
Hide();
nSin=nSin1;
nCos=nCos1;
DragStat().NextMove(aPnt);
Show();
}
switch (GetDragHdlKind())
{ case SdrHdlKind::Upper: eRefHdl=SdrHdlKind::Lower; break; case SdrHdlKind::Lower: eRefHdl=SdrHdlKind::Upper; break; case SdrHdlKind::Left : eRefHdl=SdrHdlKind::Right; bVertical=true; break; case SdrHdlKind::Right: eRefHdl=SdrHdlKind::Left ; bVertical=true; break; default: break;
}
if (eRefHdl!=SdrHdlKind::Move)
pRefHdl=GetHdlList().GetHdl(eRefHdl);
if (pRefHdl!=nullptr)
{
DragStat().SetRef1(pRefHdl->GetPos());
nAngle0=GetAngle(DragStat().GetStart()-DragStat().GetRef1());
} else
{
OSL_FAIL("SdrDragShear::BeginSdrDrag(): No reference point handle for shearing found."); returnfalse;
}
if (bSlant)
{ // calculate resize for slant // when angle snapping is activated, disable 89 degree limit
Degree100 nTmpAngle=nNewAngle; if (bUpSideDown) nNewAngle -= 18000_deg100; if (bNeg) nTmpAngle=-nTmpAngle;
bResize=true;
aNewFract = cos(toRadians(nTmpAngle));
aFact.ReduceInaccurate(10); // three decimals should be enough
}
if (nNewAngle > 8900_deg100)
nNewAngle = 8900_deg100;
if (bNeg)
nNewAngle=-nNewAngle;
if (nAngle!=nNewAngle || aFact!=aNewFract)
{
nAngle=nNewAngle;
aFact=aNewFract; double a = toRadians(nAngle); double nTan1=tan(a); // calculate now, so as little time as possible passes between Hide() and Show()
Hide();
nTan=nTan1;
DragStat().NextMove(rPnt);
Show();
}
}
void SdrDragShear::applyCurrentTransformationToSdrObject(SdrObject& rTarget)
{ if (bResize)
{ if (bVertical)
{
rTarget.Resize(DragStat().GetRef1(),aFact,Fraction(1,1));
} else
{
rTarget.Resize(DragStat().GetRef1(),Fraction(1,1),aFact);
}
}
if (nAngle)
{
rTarget.Shear(DragStat().GetRef1(), nAngle, nTan, bVertical);
}
}
// These defines parametrize the created raster // for interactions #define DRAG_CROOK_RASTER_MINIMUM (4) #define DRAG_CROOK_RASTER_MAXIMUM (15) #define DRAG_CROOK_RASTER_DISTANCE (30)
if (bContortion)
{ if (bVertical)
{
rTarget.Resize(aCenter,aFact1,aFact);
} else
{
rTarget.Resize(aCenter,aFact,aFact1);
}
} else
{
Point aCtr0(rTarget.GetSnapRect().Center());
Point aCtr1(aCtr0);
if (bVertical)
{
ResizePoint(aCtr1,aCenter,aFact1,aFact);
} else
{
ResizePoint(aCtr1,aCenter,aFact,aFact1);
}
void SdrDragCrook::applyCurrentTransformationToPolyPolygon(basegfx::B2DPolyPolygon& rTarget)
{ // use helper derived from old stuff
MovAllPoints(rTarget);
}
if (bDoCrook || bResize)
{ if (bResize && bUndo)
{
OUString aStr = ImpGetDescriptionStr(!bContortion?STR_EditCrook:STR_EditCrookContortion);
if (bCopy)
aStr += SvxResId(STR_EditWithCopy);
getSdrDragView().BegUndo(aStr);
}
if (bResize)
{
Fraction aFact1(1,1);
if (bContortion)
{ if (bVertical)
getSdrDragView().ResizeMarkedObj(aCenter,aFact1,aFact,bCopy); else
getSdrDragView().ResizeMarkedObj(aCenter,aFact,aFact1,bCopy);
} else
{ if (bCopy)
getSdrDragView().CopyMarkedObj();
for (size_t nm=0; nm<nMarkCount; ++nm)
{
SdrMark* pM=rMarkList.GetMark(nm);
SdrObject* pO=pM->GetMarkedSdrObj();
Point aCtr0(pO->GetSnapRect().Center());
Point aCtr1(aCtr0);
if (bVertical)
ResizePoint(aCtr1,aCenter,aFact1,aFact); else
ResizePoint(aCtr1,aCenter,aFact,aFact1);
if (bContortionAllowed || bNoContortionAllowed)
{
SdrHdlKind eKind=GetDragHdlKind();
nPolyPt=0xFFFF;
if (eKind==SdrHdlKind::UpperLeft) nPolyPt=0; if (eKind==SdrHdlKind::UpperRight) nPolyPt=1; if (eKind==SdrHdlKind::LowerRight) nPolyPt=2; if (eKind==SdrHdlKind::LowerLeft) nPolyPt=3; if (nPolyPt>3) returnfalse;
if (bDoDistort)
{
SdrEditView::ImpDistortObj(&rTarget, aMarkRect, aDistortedRect, !bContortion);
}
}
void SdrDragDistort::applyCurrentTransformationToPolyPolygon(basegfx::B2DPolyPolygon& rTarget)
{ // use helper derived from old stuff
MovAllPoints(rTarget);
}
SdrDragCrop::SdrDragCrop(SdrDragView& rNewView)
: SdrDragObjOwn(rNewView)
{ // switch off solid dragging for crop; it just makes no sense since showing // a 50% transparent object above the original will not be visible
setSolidDraggingActive(false);
}
if(1 != rMarkList.GetMarkCount())
{ // Crop only with single Object selected returnfalse;
}
// prepare for SdrGrafObj or others. This code has to work with usual // SdrGrafObj's from Draw/Impress/Calc, but also with SdrObjects from // Writer. It would be better to handle this in Writer directly, but // there are currently no easy mechanisms to plug an alternative interaction // from there
SdrObject* pSdrObject = rMarkList.GetMark(0)->GetMarkedSdrObj();
rtl::Reference<SdrObject> pFullDragClone; bool bExternal(false);
SdrObject* pExternalSdrObject(nullptr);
// RotGrfFlyFrame: Crop decision for DrawingLayer/Writer now // locally, no two-in-one methods any more if (nullptr != pSdrObject && dynamic_cast< const SdrGrafObj* >(pSdrObject) == nullptr)
{ // If Writer, get the already offered for interaction SdrGrafObj // and set up for using that replacement object that contains the // real transformation. That SdrObject is owned and has to be deleted, // so use a std::unique_ptr with special handling for the protected // SDrObject destructor
pFullDragClone = pSdrObject->getFullDragClone();
getSdrDragView().BegUndo( aUndoStr );
getSdrDragView().AddUndo(getSdrDragView().GetModel().GetSdrUndoFactory().CreateUndoGeoObject(*pObj)); // also need attr undo, the SdrGrafCropItem will be changed
getSdrDragView().AddUndo(getSdrDragView().GetModel().GetSdrUndoFactory().CreateUndoAttrObject(*pObj));
}
// get the original objects transformation
basegfx::B2DHomMatrix aOriginalMatrix;
basegfx::B2DPolyPolygon aPolyPolygon; bool bShearCorrected(false);
pObj->TRGetBaseGeometry(aOriginalMatrix, aPolyPolygon);
{ // correct shear, it comes currently mirrored from TRGetBaseGeometry, can be removed with aw080 const basegfx::utils::B2DHomMatrixBufferedDecompose aTmpDecomp(aOriginalMatrix);
// generate start point of original drag vector in unit coordinates (the // vis-a-vis of the drag point)
basegfx::B2DPoint aLocalStart(0.0, 0.0); bool bOnAxis(false);
switch(GetDragHdlKind())
{ case SdrHdlKind::UpperLeft: aLocalStart.setX(1.0); aLocalStart.setY(1.0); break; case SdrHdlKind::Upper: aLocalStart.setX(0.5); aLocalStart.setY(1.0); bOnAxis = true; break; case SdrHdlKind::UpperRight: aLocalStart.setX(0.0); aLocalStart.setY(1.0); break; case SdrHdlKind::Left : aLocalStart.setX(1.0); aLocalStart.setY(0.5); bOnAxis = true; break; case SdrHdlKind::Right: aLocalStart.setX(0.0); aLocalStart.setY(0.5); bOnAxis = true; break; case SdrHdlKind::LowerLeft: aLocalStart.setX(1.0); aLocalStart.setY(0.0); break; case SdrHdlKind::Lower: aLocalStart.setX(0.5); aLocalStart.setY(0.0); bOnAxis = true; break; case SdrHdlKind::LowerRight: aLocalStart.setX(0.0); aLocalStart.setY(0.0); break; default: break;
}
// create the current drag position in unit coordinates. To get there, // transform back the DragPoint to UnitCoordinates
basegfx::B2DHomMatrix aInverse(aOriginalMatrix);
aInverse.invert();
basegfx::B2DPoint aLocalCurrent(aInverse * basegfx::B2DPoint(DragStat().GetNow().X(), DragStat().GetNow().Y()));
// if one of the edge handles is used, limit to X or Y drag only if(bOnAxis)
{ if(basegfx::fTools::equal(aLocalStart.getX(), 0.5))
{
aLocalCurrent.setX(aLocalStart.getX());
} else
{
aLocalCurrent.setY(aLocalStart.getY());
}
}
// create internal change in unit coordinates
basegfx::B2DHomMatrix aDiscreteChangeMatrix;
// We now have the whole executed Crop in UnitCoordinates in // aDiscreteChangeMatrix, go to concrete sizes now. // Create the unrotated original rectangle and the unrotated modified // rectangle as Ranges const basegfx::utils::B2DHomMatrixBufferedDecompose aOriginalMatrixDecomp(aOriginalMatrix);
// prepare unsheared/unrotated versions of the old and new transformation const basegfx::B2DHomMatrix aOriginalMatrixNoShearNoRotate(
basegfx::utils::createScaleTranslateB2DHomMatrix(
basegfx::absolute(aOriginalMatrixDecomp.getScale()),
aOriginalMatrixDecomp.getTranslate()));
// create the ranges for these
basegfx::B2DRange aRangeOriginalNoShearNoRotate(0.0, 0.0, 1.0, 1.0);
basegfx::B2DRange aRangeNewNoShearNoRotate(0.0, 0.0, 1.0, 1.0);
aRangeOriginalNoShearNoRotate.transform(aOriginalMatrixNoShearNoRotate);
aRangeNewNoShearNoRotate.transform(aOriginalMatrixNoShearNoRotate * aDiscreteChangeMatrix);
if(bExternal)
{ // With aLocalStart point (opposed to dragged point), X scale and Y scale, // we call crop (virtual method) on pSdrObject which calls VirtFlyDrawObj // crop. Use aLocalStart unchanged, so being relative to the Crop-Action, // the called instance knows best how to use it constdouble fScaleX(aRangeNewNoShearNoRotate.getWidth() / aRangeOriginalNoShearNoRotate.getWidth()); constdouble fScaleY(aRangeNewNoShearNoRotate.getHeight() / aRangeOriginalNoShearNoRotate.getHeight());
// apply change to object by applying the unit coordinate change followed // by the original change
pObj->TRSetBaseGeometry(aNewObjectMatrix, aPolyPolygon);
// extract the old Rectangle structures
tools::Rectangle aOldRect(
basegfx::fround<tools::Long>(aRangeOriginalNoShearNoRotate.getMinX()),
basegfx::fround<tools::Long>(aRangeOriginalNoShearNoRotate.getMinY()),
basegfx::fround<tools::Long>(aRangeOriginalNoShearNoRotate.getMaxX()),
basegfx::fround<tools::Long>(aRangeOriginalNoShearNoRotate.getMaxY()));
tools::Rectangle aNewRect(
basegfx::fround<tools::Long>(aRangeNewNoShearNoRotate.getMinX()),
basegfx::fround<tools::Long>(aRangeNewNoShearNoRotate.getMinY()),
basegfx::fround<tools::Long>(aRangeNewNoShearNoRotate.getMaxX()),
basegfx::fround<tools::Long>(aRangeNewNoShearNoRotate.getMaxY()));
// continue with the old original stuff if (!aOldRect.GetWidth() || !aOldRect.GetHeight())
{ throw o3tl::divide_by_zero();
}
const GraphicObject& rGraphicObject(pObj->GetGraphicObject()); // tdf#117145 Usually Writer will go the bExternal path (see above), but more correct for // the future is to use the MapMode from the SdrModel/SfxItemPool if the Writer's current // special handling should be unified to this path in the future. Usually it *should* be // MapUnit::Map100thMM, but better do not mix up Units. // Checked now what SwVirtFlyDrawObj::NbcCrop is doing - it calculates everything forced // to MapUnit::Map100thMM, but extracts/packs Twips to the used SdrGrafCropItem in Writer. const MapMode aMapModePool(pObj->getSdrModelFromSdrObject().GetItemPool().GetMetric(0));
Size aGraphicSize(rGraphicObject.GetPrefSize());
if(pObj->IsMirrored())
{ // mirrored X or Y, for old stuff, exchange X // check for aw080
sal_Int32 nTmp(nDiffLeft);
nDiffLeft = -nDiffRight;
nDiffRight = -nTmp;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.