diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-09-05 16:46:13 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-09-05 18:59:52 +0200 |
commit | 8b7434bc04de343b47d3107995cd9c3c96de40b0 (patch) | |
tree | 4f4bf0866fc8342789341d64d107bdef3a059ca2 /svx/source | |
parent | 4c16f79b30ff3e015c706e0563faf6cf2931e1a6 (diff) |
use unique_ptr in SdrObject::getFullDragClone
Change-Id: I904f1f13bb4958e3457476e6e682ec7d7b97c670
Reviewed-on: https://gerrit.libreoffice.org/78660
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svx/source')
-rw-r--r-- | svx/source/svdraw/svddrgmt.cxx | 62 | ||||
-rw-r--r-- | svx/source/svdraw/svdobj.cxx | 4 | ||||
-rw-r--r-- | svx/source/svdraw/svdoedge.cxx | 4 | ||||
-rw-r--r-- | svx/source/svdraw/svdograf.cxx | 6 | ||||
-rw-r--r-- | svx/source/svdraw/svdoole2.cxx | 12 | ||||
-rw-r--r-- | svx/source/svdraw/svdotext.cxx | 8 | ||||
-rw-r--r-- | svx/source/svdraw/svdovirt.cxx | 6 |
7 files changed, 41 insertions, 61 deletions
diff --git a/svx/source/svdraw/svddrgmt.cxx b/svx/source/svdraw/svddrgmt.cxx index a9e7ca7a6e27..38d72142eebe 100644 --- a/svx/source/svdraw/svddrgmt.cxx +++ b/svx/source/svdraw/svddrgmt.cxx @@ -143,7 +143,6 @@ SdrDragEntrySdrObject::SdrDragEntrySdrObject( bool bModify) : SdrDragEntry(), maOriginal(rOriginal), - mpClone(nullptr), mbModify(bModify) { // add SdrObject parts to transparent overlay stuff @@ -152,10 +151,6 @@ SdrDragEntrySdrObject::SdrDragEntrySdrObject( SdrDragEntrySdrObject::~SdrDragEntrySdrObject() { - if(mpClone) - { - SdrObject::Free(mpClone); - } } void SdrDragEntrySdrObject::prepareCurrentState(SdrDragMethod& rDragMethod) @@ -164,18 +159,14 @@ void SdrDragEntrySdrObject::prepareCurrentState(SdrDragMethod& rDragMethod) // out when clone and original have the same class, so that i can use operator= // in those cases - if(mpClone) - { - SdrObject::Free(mpClone); - mpClone = nullptr; - } + mxClone.reset(); if(mbModify) { - mpClone = maOriginal.getFullDragClone(); + mxClone = maOriginal.getFullDragClone(); // apply original transformation, implemented at the DragMethods - rDragMethod.applyCurrentTransformationToSdrObject(*mpClone); + rDragMethod.applyCurrentTransformationToSdrObject(*mxClone); } } @@ -183,10 +174,10 @@ drawinglayer::primitive2d::Primitive2DContainer SdrDragEntrySdrObject::createPri { const SdrObject* pSource = &maOriginal; - if(mbModify && mpClone) + if(mbModify && mxClone) { // choose source for geometry data - pSource = mpClone; + pSource = mxClone.get(); } // use the view-independent primitive representation (without @@ -1172,8 +1163,7 @@ PointerStyle SdrDragMovHdl::GetSdrDragPointer() const SdrDragObjOwn::SdrDragObjOwn(SdrDragView& rNewView) -: SdrDragMethod(rNewView), - mpClone(nullptr) +: SdrDragMethod(rNewView) { const SdrObject* pObj = GetDragObj(); @@ -1186,15 +1176,11 @@ SdrDragObjOwn::SdrDragObjOwn(SdrDragView& rNewView) SdrDragObjOwn::~SdrDragObjOwn() { - if(mpClone) - { - SdrObject::Free(mpClone); - } } void SdrDragObjOwn::createSdrDragEntries() { - if(mpClone) + if(mxClone) { basegfx::B2DPolyPolygon aDragPolyPolygon; bool bAddWireframe(true); @@ -1205,7 +1191,7 @@ void SdrDragObjOwn::createSdrDragEntries() if(pPV && pPV->PageWindowCount()) { - addSdrDragEntry(std::unique_ptr<SdrDragEntry>(new SdrDragEntrySdrObject(*mpClone, false))); + addSdrDragEntry(std::unique_ptr<SdrDragEntry>(new SdrDragEntrySdrObject(*mxClone, false))); // potentially no wireframe needed, full drag works bAddWireframe = false; @@ -1216,7 +1202,7 @@ void SdrDragObjOwn::createSdrDragEntries() { // check for extra conditions for wireframe, e.g. no border at // objects - if(!mpClone->HasLineStyle()) + if(!mxClone->HasLineStyle()) { bAddWireframe = true; } @@ -1225,11 +1211,11 @@ void SdrDragObjOwn::createSdrDragEntries() if(bAddWireframe) { // use wireframe poly when full drag is off or did not work - aDragPolyPolygon = mpClone->TakeXorPoly(); + aDragPolyPolygon = mxClone->TakeXorPoly(); } // add evtl. extra DragPolyPolygon - const basegfx::B2DPolyPolygon aSpecialDragPolyPolygon(mpClone->getSpecialDragPoly(DragStat())); + const basegfx::B2DPolyPolygon aSpecialDragPolyPolygon(mxClone->getSpecialDragPoly(DragStat())); if(aSpecialDragPolyPolygon.count()) { @@ -1247,9 +1233,9 @@ void SdrDragObjOwn::TakeSdrDragComment(OUString& rStr) const { // #i103058# get info string from the clone preferred, the original will // not be changed. For security, use original as fallback - if(mpClone) + if(mxClone) { - rStr = mpClone->getSpecialDragComment(DragStat()); + rStr = mxClone->getSpecialDragComment(DragStat()); } else { @@ -1264,7 +1250,7 @@ void SdrDragObjOwn::TakeSdrDragComment(OUString& rStr) const bool SdrDragObjOwn::BeginSdrDrag() { - if(!mpClone) + if(!mxClone) { const SdrObject* pObj = GetDragObj(); @@ -1273,8 +1259,8 @@ bool SdrDragObjOwn::BeginSdrDrag() if(pObj->beginSpecialDrag(DragStat())) { // create initial clone to have a start visualization - mpClone = pObj->getFullDragClone(); - mpClone->applySpecialDrag(DragStat()); + mxClone = pObj->getFullDragClone(); + mxClone->applySpecialDrag(DragStat()); return true; } @@ -1329,15 +1315,11 @@ void SdrDragObjOwn::MoveSdrDrag(const Point& rNoSnapPnt) clearSdrDragEntries(); // delete current clone (after the last reference to it is deleted above) - if(mpClone) - { - SdrObject::Free(mpClone); - mpClone = nullptr; - } + mxClone.reset(); // create a new clone and modify to current drag state - mpClone = pObj->getFullDragClone(); - mpClone->applySpecialDrag(DragStat()); + mxClone = pObj->getFullDragClone(); + mxClone->applySpecialDrag(DragStat()); // AutoGrowWidth may change for SdrTextObj due to the automatism used // with bDisableAutoWidthOnDragging, so not only geometry changes but @@ -1345,7 +1327,7 @@ void SdrDragObjOwn::MoveSdrDrag(const Point& rNoSnapPnt) // changed, it needs to be copied to the original since nothing will // happen when it only changes in the drag clone const bool bOldAutoGrowWidth(pObj->GetMergedItem(SDRATTR_TEXT_AUTOGROWWIDTH).GetValue()); - const bool bNewAutoGrowWidth(mpClone->GetMergedItem(SDRATTR_TEXT_AUTOGROWWIDTH).GetValue()); + const bool bNewAutoGrowWidth(mxClone->GetMergedItem(SDRATTR_TEXT_AUTOGROWWIDTH).GetValue()); if (bOldAutoGrowWidth != bNewAutoGrowWidth) { @@ -3600,7 +3582,7 @@ bool SdrDragCrop::EndSdrDrag(bool /*bCopy*/) // there are currently no easy mechanisms to plug an alternative interaction // from there SdrObject* pSdrObject = rMarkList.GetMark(0)->GetMarkedSdrObj(); - std::unique_ptr< SdrObject, SdrObjectFreeOp > pFullDragClone; + SdrObjectUniquePtr pFullDragClone; bool bExternal(false); SdrObject* pExternalSdrObject(nullptr); @@ -3613,7 +3595,7 @@ bool SdrDragCrop::EndSdrDrag(bool /*bCopy*/) // 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.reset(pSdrObject->getFullDragClone()); + pFullDragClone = pSdrObject->getFullDragClone(); if(dynamic_cast< SdrGrafObj* >(pFullDragClone.get())) { diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx index c08bd1406986..6b707aeae231 100644 --- a/svx/source/svdraw/svdobj.cxx +++ b/svx/source/svdraw/svdobj.cxx @@ -1300,10 +1300,10 @@ bool SdrObject::supportsFullDrag() const return true; } -SdrObject* SdrObject::getFullDragClone() const +SdrObjectUniquePtr SdrObject::getFullDragClone() const { // default uses simple clone - return CloneSdrObject(getSdrModelFromSdrObject()); + return SdrObjectUniquePtr(CloneSdrObject(getSdrModelFromSdrObject())); } bool SdrObject::beginSpecialDrag(SdrDragStat& rDrag) const diff --git a/svx/source/svdraw/svdoedge.cxx b/svx/source/svdraw/svdoedge.cxx index db21f5fc6e73..e9d40f0f298a 100644 --- a/svx/source/svdraw/svdoedge.cxx +++ b/svx/source/svdraw/svdoedge.cxx @@ -1854,7 +1854,7 @@ bool SdrEdgeObj::hasSpecialDrag() const return true; } -SdrObject* SdrEdgeObj::getFullDragClone() const +SdrObjectUniquePtr SdrEdgeObj::getFullDragClone() const { // use Clone operator SdrEdgeObj* pRetval(CloneSdrObject(getSdrModelFromSdrObject())); @@ -1863,7 +1863,7 @@ SdrObject* SdrEdgeObj::getFullDragClone() const pRetval->ConnectToNode(true, GetConnectedNode(true)); pRetval->ConnectToNode(false, GetConnectedNode(false)); - return pRetval; + return SdrObjectUniquePtr(pRetval); } bool SdrEdgeObj::beginSpecialDrag(SdrDragStat& rDrag) const diff --git a/svx/source/svdraw/svdograf.cxx b/svx/source/svdraw/svdograf.cxx index cbf3c055578b..329bbaf768ea 100644 --- a/svx/source/svdraw/svdograf.cxx +++ b/svx/source/svdraw/svdograf.cxx @@ -702,17 +702,17 @@ OUString SdrGrafObj::TakeObjNamePlural() const return sName.makeStringAndClear(); } -SdrObject* SdrGrafObj::getFullDragClone() const +SdrObjectUniquePtr SdrGrafObj::getFullDragClone() const { // call parent - SdrGrafObj* pRetval = static_cast< SdrGrafObj* >(SdrRectObj::getFullDragClone()); + SdrObjectUniquePtr pRetval = SdrRectObj::getFullDragClone(); // #i103116# the full drag clone leads to problems // with linked graphics, so reset the link in this // temporary interaction object and load graphic if(pRetval && IsLinkedGraphic()) { - pRetval->ReleaseGraphicLink(); + static_cast< SdrGrafObj* >(pRetval.get())->ReleaseGraphicLink(); } return pRetval; diff --git a/svx/source/svdraw/svdoole2.cxx b/svx/source/svdraw/svdoole2.cxx index bf720771bd71..f0384fbc8d3e 100644 --- a/svx/source/svdraw/svdoole2.cxx +++ b/svx/source/svdraw/svdoole2.cxx @@ -1166,7 +1166,7 @@ void SdrOle2Obj::Disconnect_Impl() mpImpl->mbConnected = false; } -SdrObject* SdrOle2Obj::createSdrGrafObjReplacement(bool bAddText) const +SdrObjectUniquePtr SdrOle2Obj::createSdrGrafObjReplacement(bool bAddText) const { const Graphic* pOLEGraphic = GetGraphic(); @@ -1199,7 +1199,7 @@ SdrObject* SdrOle2Obj::createSdrGrafObjReplacement(bool bAddText) const } } - return pClone; + return SdrObjectUniquePtr(pClone); } else { @@ -1221,20 +1221,18 @@ SdrObject* SdrOle2Obj::createSdrGrafObjReplacement(bool bAddText) const pClone->SetMergedItem(XFillBmpTileItem(false)); pClone->SetMergedItem(XFillBmpStretchItem(false)); - return pClone; + return SdrObjectUniquePtr(pClone); } } SdrObject* SdrOle2Obj::DoConvertToPolyObj(bool bBezier, bool bAddText) const { // #i118485# missing converter added - SdrObject* pRetval = createSdrGrafObjReplacement(true); + SdrObjectUniquePtr pRetval = createSdrGrafObjReplacement(true); if(pRetval) { SdrObject* pRetval2 = pRetval->DoConvertToPolyObj(bBezier, bAddText); - SdrObject::Free(pRetval); - return pRetval2; } @@ -1305,7 +1303,7 @@ void SdrOle2Obj::SetClosedObj( bool bIsClosed ) bClosedObj = bIsClosed; } -SdrObject* SdrOle2Obj::getFullDragClone() const +SdrObjectUniquePtr SdrOle2Obj::getFullDragClone() const { // #i118485# use central replacement generator return createSdrGrafObjReplacement(false); diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx index 47e46b738345..93c80ff56325 100644 --- a/svx/source/svdraw/svdotext.cxx +++ b/svx/source/svdraw/svdotext.cxx @@ -2034,10 +2034,10 @@ bool SdrTextObj::GetPreventChainable() const return mbIsUnchainableClone || (GetNextLinkInChain() && GetNextLinkInChain()->IsInEditMode()); } - SdrObject* SdrTextObj::getFullDragClone() const - { - SdrObject *pClone = SdrAttrObj::getFullDragClone(); - SdrTextObj *pTextObjClone = dynamic_cast<SdrTextObj *>(pClone); +SdrObjectUniquePtr SdrTextObj::getFullDragClone() const +{ + SdrObjectUniquePtr pClone = SdrAttrObj::getFullDragClone(); + SdrTextObj *pTextObjClone = dynamic_cast<SdrTextObj *>(pClone.get()); if (pTextObjClone != nullptr) { // Avoid transferring of text for chainable object during dragging pTextObjClone->mbIsUnchainableClone = true; diff --git a/svx/source/svdraw/svdovirt.cxx b/svx/source/svdraw/svdovirt.cxx index 18d1a92125aa..202f4632c542 100644 --- a/svx/source/svdraw/svdovirt.cxx +++ b/svx/source/svdraw/svdovirt.cxx @@ -234,13 +234,13 @@ bool SdrVirtObj::supportsFullDrag() const return false; } -SdrObject* SdrVirtObj::getFullDragClone() const +SdrObjectUniquePtr SdrVirtObj::getFullDragClone() const { SdrObject& rReferencedObject = const_cast<SdrVirtObj*>(this)->ReferencedObj(); - return new SdrGrafObj( + return SdrObjectUniquePtr(new SdrGrafObj( getSdrModelFromSdrObject(), SdrDragView::GetObjGraphic(rReferencedObject), - GetLogicRect()); + GetLogicRect())); } bool SdrVirtObj::beginSpecialDrag(SdrDragStat& rDrag) const |