include/svx/svdobj.hxx | 1 svx/source/svdraw/svdobj.cxx | 140 ++++++++++++++++++++++++----------------- svx/source/svdraw/svdotxdr.cxx | 62 ------------------ 3 files changed, 84 insertions(+), 119 deletions(-)
New commits: commit edd0991c3cc1c5ae439e33873c2567ee62d0e710 Author: Laurent Balland <laurent.ball...@mailo.fr> AuthorDate: Thu May 1 19:52:36 2025 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue May 27 14:21:12 2025 +0200 Rezing SdrObject: Remove duplicate code SdrTextObj::ImpDragCalcRect and SdrObject::ImpDragCalcRect are almost duplicate This patch creates an inherited function to avoid duplicate code Change-Id: I9a9abfeb1fa176e59c1d30b4530781268d84fcb7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184931 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/include/svx/svdobj.hxx b/include/svx/svdobj.hxx index 297ee9530a61..21119a4fa5ac 100644 --- a/include/svx/svdobj.hxx +++ b/include/svx/svdobj.hxx @@ -913,6 +913,7 @@ protected: virtual std::unique_ptr<sdr::contact::ViewContact> CreateObjectSpecificViewContact(); + static void ImpCommonDragCalcRect(const SdrDragStat& rDrag, tools::Rectangle& rTmpRect); tools::Rectangle ImpDragCalcRect(const SdrDragStat& rDrag) const; // for GetDragComment diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx index 4eb5146a0c0e..db20c9bb8d58 100644 --- a/svx/source/svdraw/svdobj.cxx +++ b/svx/source/svdraw/svdobj.cxx @@ -1249,71 +1249,95 @@ void SdrObject::addCropHandles(SdrHdlList& /*rTarget*/) const // SdrGrafObj and SwVirtFlyDrawObj } -tools::Rectangle SdrObject::ImpDragCalcRect(const SdrDragStat& rDrag) const +void SdrObject::ImpCommonDragCalcRect(const SdrDragStat& rDrag, tools::Rectangle& rTmpRect) { - tools::Rectangle aTmpRect(GetSnapRect()); - tools::Rectangle aRect(aTmpRect); - const SdrHdl* pHdl=rDrag.GetHdl(); - SdrHdlKind eHdl=pHdl==nullptr ? SdrHdlKind::Move : pHdl->GetKind(); - bool bEcke=(eHdl==SdrHdlKind::UpperLeft || eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::LowerLeft || eHdl==SdrHdlKind::LowerRight); - bool bOrtho=rDrag.GetView()!=nullptr && rDrag.GetView()->IsOrtho(); - bool bBigOrtho=bEcke && bOrtho && rDrag.GetView()->IsBigOrtho(); + const tools::Rectangle aRect(rTmpRect); + const SdrHdl* pHdl = rDrag.GetHdl(); + SdrHdlKind eHdl = (pHdl==nullptr ? SdrHdlKind::Move : pHdl->GetKind()); + bool bCorner = (eHdl==SdrHdlKind::UpperLeft || eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::LowerLeft || eHdl==SdrHdlKind::LowerRight); + bool bOrtho = rDrag.GetView()!=nullptr && rDrag.GetView()->IsOrtho(); + bool bBigOrtho = bCorner && bOrtho && rDrag.GetView()->IsBigOrtho(); Point aPos(rDrag.GetNow()); - bool bLft=(eHdl==SdrHdlKind::UpperLeft || eHdl==SdrHdlKind::Left || eHdl==SdrHdlKind::LowerLeft); - bool bRgt=(eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::Right || eHdl==SdrHdlKind::LowerRight); - bool bTop=(eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::Upper || eHdl==SdrHdlKind::UpperLeft); - bool bBtm=(eHdl==SdrHdlKind::LowerRight || eHdl==SdrHdlKind::Lower || eHdl==SdrHdlKind::LowerLeft); - if (bLft) aTmpRect.SetLeft(aPos.X() ); - if (bRgt) aTmpRect.SetRight(aPos.X() ); - if (bTop) aTmpRect.SetTop(aPos.Y() ); - if (bBtm) aTmpRect.SetBottom(aPos.Y() ); - if (bOrtho) { // Ortho - tools::Long nWdt0=aRect.Right() -aRect.Left(); - tools::Long nHgt0=aRect.Bottom()-aRect.Top(); - tools::Long nXMul=aTmpRect.Right() -aTmpRect.Left(); - tools::Long nYMul=aTmpRect.Bottom()-aTmpRect.Top(); - tools::Long nXDiv=nWdt0; - tools::Long nYDiv=nHgt0; - bool bXNeg=(nXMul<0)!=(nXDiv<0); - bool bYNeg=(nYMul<0)!=(nYDiv<0); - nXMul=std::abs(nXMul); - nYMul=std::abs(nYMul); - nXDiv=std::abs(nXDiv); - nYDiv=std::abs(nYDiv); - Fraction aXFact(nXMul,nXDiv); // fractions for canceling - Fraction aYFact(nYMul,nYDiv); // and for comparing - nXMul=aXFact.GetNumerator(); - nYMul=aYFact.GetNumerator(); - nXDiv=aXFact.GetDenominator(); - nYDiv=aYFact.GetDenominator(); - if (bEcke) { // corner point handles - bool bUseX=(aXFact<aYFact) != bBigOrtho; - if (bUseX) { - tools::Long nNeed=tools::Long(BigInt(nHgt0)*BigInt(nXMul)/BigInt(nXDiv)); - if (bYNeg) nNeed=-nNeed; - if (bTop) aTmpRect.SetTop(aTmpRect.Bottom()-nNeed ); - if (bBtm) aTmpRect.SetBottom(aTmpRect.Top()+nNeed ); - } else { - tools::Long nNeed=tools::Long(BigInt(nWdt0)*BigInt(nYMul)/BigInt(nYDiv)); - if (bXNeg) nNeed=-nNeed; - if (bLft) aTmpRect.SetLeft(aTmpRect.Right()-nNeed ); - if (bRgt) aTmpRect.SetRight(aTmpRect.Left()+nNeed ); + bool bLft = (eHdl==SdrHdlKind::UpperLeft || eHdl==SdrHdlKind::Left || eHdl==SdrHdlKind::LowerLeft); + bool bRgt = (eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::Right || eHdl==SdrHdlKind::LowerRight); + bool bTop = (eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::Upper || eHdl==SdrHdlKind::UpperLeft); + bool bBtm = (eHdl==SdrHdlKind::LowerRight || eHdl==SdrHdlKind::Lower || eHdl==SdrHdlKind::LowerLeft); + if (bLft) + rTmpRect.SetLeft(aPos.X() ); + else if (bRgt) + rTmpRect.SetRight(aPos.X() ); + if (bTop) + rTmpRect.SetTop(aPos.Y() ); + else if (bBtm) + rTmpRect.SetBottom(aPos.Y() ); + if (bOrtho) // Ortho + { + tools::Long nWdt0 = aRect.Right() - aRect.Left(); + tools::Long nHgt0 = aRect.Bottom()- aRect.Top(); + tools::Long nXMul = rTmpRect.Right() - rTmpRect.Left(); + tools::Long nYMul = rTmpRect.Bottom()- rTmpRect.Top(); + tools::Long nXDiv = nWdt0; + tools::Long nYDiv = nHgt0; + bool bXNeg = ((nXMul<0) != (nXDiv<0)); + bool bYNeg = ((nYMul<0) != (nYDiv<0)); + nXMul = std::abs(nXMul); + nYMul = std::abs(nYMul); + nXDiv = std::abs(nXDiv); + nYDiv = std::abs(nYDiv); + Fraction aXFact(nXMul, nXDiv); // fractions for canceling + Fraction aYFact(nYMul, nYDiv); // and for comparing + nXMul = aXFact.GetNumerator(); + nYMul = aYFact.GetNumerator(); + nXDiv = aXFact.GetDenominator(); + nYDiv = aYFact.GetDenominator(); + if (bCorner) // corner point handles + { + bool bUseX = ((aXFact<aYFact) != bBigOrtho); + if (bUseX) + { + tools::Long nNeed = tools::Long( BigInt(nHgt0) * BigInt(nXMul) / BigInt(nXDiv) ); + if (bYNeg) + nNeed = -nNeed; + if (bTop) + rTmpRect.SetTop( rTmpRect.Bottom() - nNeed ); + else if (bBtm) + rTmpRect.SetBottom( rTmpRect.Top() + nNeed ); } - } else { // apex handles - if ((bLft || bRgt) && nXDiv!=0) { - tools::Long nHgt0b=aRect.Bottom()-aRect.Top(); - tools::Long nNeed=tools::Long(BigInt(nHgt0b)*BigInt(nXMul)/BigInt(nXDiv)); - aTmpRect.AdjustTop( -((nNeed-nHgt0b)/2) ); - aTmpRect.SetBottom(aTmpRect.Top()+nNeed ); + else + { + tools::Long nNeed = tools::Long( BigInt(nWdt0) * BigInt(nYMul) / BigInt(nYDiv) ); + if (bXNeg) + nNeed = -nNeed; + if (bLft) + rTmpRect.SetLeft(rTmpRect.Right()-nNeed ); + else if (bRgt) + rTmpRect.SetRight(rTmpRect.Left()+nNeed ); } - if ((bTop || bBtm) && nYDiv!=0) { - tools::Long nWdt0b=aRect.Right()-aRect.Left(); - tools::Long nNeed=tools::Long(BigInt(nWdt0b)*BigInt(nYMul)/BigInt(nYDiv)); - aTmpRect.AdjustLeft( -((nNeed-nWdt0b)/2) ); - aTmpRect.SetRight(aTmpRect.Left()+nNeed ); + } + else // apex handles + { + if ((bLft || bRgt) && nXDiv!=0) + { + tools::Long nHgt0b = aRect.Bottom() - aRect.Top(); + tools::Long nNeed = tools::Long( BigInt(nHgt0b) * BigInt(nXMul) / BigInt(nXDiv) ) ; + rTmpRect.AdjustTop( -((nNeed-nHgt0b)/2) ); + rTmpRect.SetBottom( rTmpRect.Top() + nNeed ); + } + else if ((bTop || bBtm) && nYDiv!=0) + { + tools::Long nWdt0b = aRect.Right() - aRect.Left(); + tools::Long nNeed = tools::Long( BigInt(nWdt0b) * BigInt(nYMul) / BigInt(nYDiv) ); + rTmpRect.AdjustLeft( -((nNeed-nWdt0b)/2) ); + rTmpRect.SetRight( rTmpRect.Left() + nNeed ); } } } +} + +tools::Rectangle SdrObject::ImpDragCalcRect(const SdrDragStat& rDrag) const +{ + tools::Rectangle aTmpRect(GetSnapRect()); + ImpCommonDragCalcRect( rDrag, aTmpRect ); aTmpRect.Normalize(); return aTmpRect; } diff --git a/svx/source/svdraw/svdotxdr.cxx b/svx/source/svdraw/svdotxdr.cxx index b5348094a295..208302d473d3 100644 --- a/svx/source/svdraw/svdotxdr.cxx +++ b/svx/source/svdraw/svdotxdr.cxx @@ -74,72 +74,12 @@ bool SdrTextObj::hasSpecialDrag() const tools::Rectangle SdrTextObj::ImpDragCalcRect(const SdrDragStat& rDrag) const { tools::Rectangle aTmpRect(getRectangle()); - const SdrHdl* pHdl=rDrag.GetHdl(); - SdrHdlKind eHdl=pHdl==nullptr ? SdrHdlKind::Move : pHdl->GetKind(); - bool bEcke=(eHdl==SdrHdlKind::UpperLeft || eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::LowerLeft || eHdl==SdrHdlKind::LowerRight); - bool bOrtho=rDrag.GetView()!=nullptr && rDrag.GetView()->IsOrtho(); - bool bBigOrtho=bEcke && bOrtho && rDrag.GetView()->IsBigOrtho(); Point aPos(rDrag.GetNow()); // Unrotate: if (maGeo.m_nRotationAngle) RotatePoint(aPos,aTmpRect.TopLeft(),-maGeo.mfSinRotationAngle,maGeo.mfCosRotationAngle); // Unshear: if (maGeo.m_nShearAngle) ShearPoint(aPos,aTmpRect.TopLeft(),-maGeo.mfTanShearAngle); - - bool bLft=(eHdl==SdrHdlKind::UpperLeft || eHdl==SdrHdlKind::Left || eHdl==SdrHdlKind::LowerLeft); - bool bRgt=(eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::Right || eHdl==SdrHdlKind::LowerRight); - bool bTop=(eHdl==SdrHdlKind::UpperRight || eHdl==SdrHdlKind::Upper || eHdl==SdrHdlKind::UpperLeft); - bool bBtm=(eHdl==SdrHdlKind::LowerRight || eHdl==SdrHdlKind::Lower || eHdl==SdrHdlKind::LowerLeft); - if (bLft) aTmpRect.SetLeft(aPos.X() ); - if (bRgt) aTmpRect.SetRight(aPos.X() ); - if (bTop) aTmpRect.SetTop(aPos.Y() ); - if (bBtm) aTmpRect.SetBottom(aPos.Y() ); - if (bOrtho) { // Ortho - tools::Long nWdt0=getRectangle().Right() - getRectangle().Left(); - tools::Long nHgt0=getRectangle().Bottom() - getRectangle().Top(); - tools::Long nXMul=aTmpRect.Right() -aTmpRect.Left(); - tools::Long nYMul=aTmpRect.Bottom()-aTmpRect.Top(); - tools::Long nXDiv=nWdt0; - tools::Long nYDiv=nHgt0; - bool bXNeg=(nXMul<0)!=(nXDiv<0); - bool bYNeg=(nYMul<0)!=(nYDiv<0); - nXMul=std::abs(nXMul); - nYMul=std::abs(nYMul); - nXDiv=std::abs(nXDiv); - nYDiv=std::abs(nYDiv); - Fraction aXFact(nXMul,nXDiv); // fractions for canceling - Fraction aYFact(nYMul,nYDiv); // and for comparing - nXMul=aXFact.GetNumerator(); - nYMul=aYFact.GetNumerator(); - nXDiv=aXFact.GetDenominator(); - nYDiv=aYFact.GetDenominator(); - if (bEcke) { // corner point handles - bool bUseX=(aXFact<aYFact) != bBigOrtho; - if (bUseX) { - tools::Long nNeed=tools::Long(BigInt(nHgt0)*BigInt(nXMul)/BigInt(nXDiv)); - if (bYNeg) nNeed=-nNeed; - if (bTop) aTmpRect.SetTop(aTmpRect.Bottom()-nNeed ); - if (bBtm) aTmpRect.SetBottom(aTmpRect.Top()+nNeed ); - } else { - tools::Long nNeed=tools::Long(BigInt(nWdt0)*BigInt(nYMul)/BigInt(nYDiv)); - if (bXNeg) nNeed=-nNeed; - if (bLft) aTmpRect.SetLeft(aTmpRect.Right()-nNeed ); - if (bRgt) aTmpRect.SetRight(aTmpRect.Left()+nNeed ); - } - } else { // apex handles - if ((bLft || bRgt) && nXDiv!=0) { - tools::Long nHgt0b=getRectangle().Bottom() - getRectangle().Top(); - tools::Long nNeed=tools::Long(BigInt(nHgt0b)*BigInt(nXMul)/BigInt(nXDiv)); - aTmpRect.AdjustTop( -((nNeed-nHgt0b)/2) ); - aTmpRect.SetBottom(aTmpRect.Top()+nNeed ); - } - if ((bTop || bBtm) && nYDiv!=0) { - tools::Long nWdt0b=getRectangle().Right() - getRectangle().Left(); - tools::Long nNeed=tools::Long(BigInt(nWdt0b)*BigInt(nYMul)/BigInt(nYDiv)); - aTmpRect.AdjustLeft( -((nNeed-nWdt0b)/2) ); - aTmpRect.SetRight(aTmpRect.Left()+nNeed ); - } - } - } + ImpCommonDragCalcRect( rDrag, aTmpRect ); if (dynamic_cast<const SdrObjCustomShape*>(this) == nullptr) // not justifying when in CustomShapes, to be able to detect if a shape has to be mirrored ImpJustifyRect(aTmpRect); return aTmpRect;