[Libreoffice-commits] core.git: include/svx svx/source

Noel Grandin noel.grandin at collabora.co.uk
Mon Mar 5 14:55:51 UTC 2018


 include/svx/svdedxv.hxx       |    6 +++---
 svx/source/svdraw/svdedxv.cxx |   20 ++++++++------------
 2 files changed, 11 insertions(+), 15 deletions(-)

New commits:
commit 2affed9bfd72628549df3049ed9f6e6a30fdb5b8
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Feb 28 14:53:32 2018 +0200

    loplugin:useuniqueptr in SdrObjEditView
    
    Horrible things happening in SdrObjEditView::SdrEndTextEdit, I
    can't tell if it's deliberately leaking there, or just changing
    ownership in some terribly opaque way.
    
    Change-Id: Idcb30f7e3f1b801901f727b151d3e8dd1124fd3f
    Reviewed-on: https://gerrit.libreoffice.org/50663
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/svx/svdedxv.hxx b/include/svx/svdedxv.hxx
index 46dd040e0d5a..75bae001cc2e 100644
--- a/include/svx/svdedxv.hxx
+++ b/include/svx/svdedxv.hxx
@@ -77,7 +77,7 @@ protected:
     tools::WeakReference<SdrTextObj>
                                 mxTextEditObj;         // current object in TextEdit
     SdrPageView*                pTextEditPV;
-    SdrOutliner*                pTextEditOutliner;     // outliner for the TextEdit
+    std::unique_ptr<SdrOutliner> pTextEditOutliner;     // outliner for the TextEdit
     OutlinerView*               pTextEditOutlinerView; // current view of the outliners
     VclPtr<vcl::Window>         pTextEditWin;          // matching window to pTextEditOutlinerView
     vcl::Cursor*                pTextEditCursorMerker; // to restore the cursor in each window
@@ -226,8 +226,8 @@ public:
 
     // Now at this outliner, events can be send, attributes can be set,
     // call Cut/Copy/Paste, call Undo/Redo, and so on...
-    const SdrOutliner* GetTextEditOutliner() const { return pTextEditOutliner; }
-    SdrOutliner* GetTextEditOutliner() { return pTextEditOutliner; }
+    const SdrOutliner* GetTextEditOutliner() const { return pTextEditOutliner.get(); }
+    SdrOutliner* GetTextEditOutliner() { return pTextEditOutliner.get(); }
     const OutlinerView* GetTextEditOutlinerView() const { return pTextEditOutlinerView; }
     OutlinerView* GetTextEditOutlinerView() { return pTextEditOutlinerView; }
 
diff --git a/svx/source/svdraw/svdedxv.cxx b/svx/source/svdraw/svdedxv.cxx
index 51ef80fb46b6..5b33f7ff6b4c 100644
--- a/svx/source/svdraw/svdedxv.cxx
+++ b/svx/source/svdraw/svdedxv.cxx
@@ -101,7 +101,7 @@ SdrObjEditView::~SdrObjEditView()
     assert(!IsTextEdit());
     if (IsTextEdit())
         SdrEndTextEdit();
-    delete pTextEditOutliner;
+    pTextEditOutliner.reset();
     assert(nullptr == mpOldTextEditUndoManager); // should have been reset
 }
 
@@ -820,7 +820,7 @@ OutlinerView* SdrObjEditView::ImpMakeOutlinerView(vcl::Window* pWin, OutlinerVie
 
     if (pOutlView == nullptr)
     {
-        pOutlView = new OutlinerView(pTextEditOutliner, pWin);
+        pOutlView = new OutlinerView(pTextEditOutliner.get(), pWin);
     }
     else
     {
@@ -1078,8 +1078,7 @@ bool SdrObjEditView::SdrBeginTextEdit(
     if(pTextEditOutliner)
     {
         OSL_FAIL("SdrObjEditView::SdrBeginTextEdit(): Old Outliner still exists.");
-        delete pTextEditOutliner;
-        pTextEditOutliner = nullptr;
+        pTextEditOutliner.reset();
     }
 
     if(!bBrk)
@@ -1087,9 +1086,9 @@ bool SdrObjEditView::SdrBeginTextEdit(
         pTextEditWin=pWin;
         pTextEditPV=pPV;
         mxTextEditObj.reset( pObj );
-        pTextEditOutliner=pGivenOutliner;
+        pTextEditOutliner.reset(pGivenOutliner);
         if (pTextEditOutliner==nullptr)
-            pTextEditOutliner = SdrMakeOutliner( OutlinerMode::TextObject, *mxTextEditObj->GetModel() );
+            pTextEditOutliner.reset(SdrMakeOutliner( OutlinerMode::TextObject, *mxTextEditObj->GetModel() ));
 
         {
             SvtAccessibilityOptions aOptions;
@@ -1335,9 +1334,7 @@ bool SdrObjEditView::SdrBeginTextEdit(
             pGivenOutlinerView = nullptr;
         }
     }
-    delete pTextEditOutliner;
-
-    pTextEditOutliner=nullptr;
+    pTextEditOutliner.reset();
     pTextEditOutlinerView=nullptr;
     mxTextEditObj.reset(nullptr);
     pTextEditPV=nullptr;
@@ -1352,7 +1349,7 @@ SdrEndTextEditKind SdrObjEditView::SdrEndTextEdit(bool bDontDeleteReally)
     SdrEndTextEditKind eRet=SdrEndTextEditKind::Unchanged;
     SdrTextObj* pTEObj = mxTextEditObj.get();
     vcl::Window*       pTEWin         =pTextEditWin;
-    SdrOutliner*  pTEOutliner    =pTextEditOutliner;
+    SdrOutliner*  pTEOutliner    =pTextEditOutliner.release();
     OutlinerView* pTEOutlinerView=pTextEditOutlinerView;
     vcl::Cursor*  pTECursorMerker=pTextEditCursorMerker;
     SdrUndoManager* pUndoEditUndoManager = nullptr;
@@ -1422,7 +1419,6 @@ SdrEndTextEditKind SdrObjEditView::SdrEndTextEdit(bool bDontDeleteReally)
     mxTextEditObj.reset(nullptr);
     pTextEditPV=nullptr;
     pTextEditWin=nullptr;
-    pTextEditOutliner=nullptr;
     pTextEditOutlinerView=nullptr;
     pTextEditCursorMerker=nullptr;
     aTextEditArea=tools::Rectangle();
@@ -1927,7 +1923,7 @@ bool SdrObjEditView::ImpIsTextEditAllSelected() const
     bool bRet=false;
     if (pTextEditOutliner!=nullptr && pTextEditOutlinerView!=nullptr)
     {
-        if(SdrTextObj::HasTextImpl( pTextEditOutliner ) )
+        if(SdrTextObj::HasTextImpl( pTextEditOutliner.get() ) )
         {
             const sal_Int32 nParaCnt=pTextEditOutliner->GetParagraphCount();
             Paragraph* pLastPara=pTextEditOutliner->GetParagraph( nParaCnt > 1 ? nParaCnt - 1 : 0 );


More information about the Libreoffice-commits mailing list