/* -*- 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());
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.