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

Mark Page aptitude at btconnect.com
Tue Dec 6 18:21:33 UTC 2016


 include/vcl/texteng.hxx                   |    2 -
 sfx2/source/control/thumbnailviewitem.cxx |    1 
 vcl/source/edit/texteng.cxx               |    3 -
 vcl/source/edit/textview.cxx              |   50 +++++++++++++-----------------
 4 files changed, 26 insertions(+), 30 deletions(-)

New commits:
commit e67857cb18f6565959122a36d81ec722ac052a11
Author: Mark Page <aptitude at btconnect.com>
Date:   Tue Dec 6 09:58:41 2016 +0000

    Convert TextView to unique_ptr
    
    The destructor contains reset to the unique_ptr's because
    it is not clear of the importance of the destruction order
    
    Change-Id: Ifbbb4fe8352cb3b50f18cebd60cf00af010c086a
    Reviewed-on: https://gerrit.libreoffice.org/31673
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/vcl/texteng.hxx b/include/vcl/texteng.hxx
index 96ac426..4746a7b 100644
--- a/include/vcl/texteng.hxx
+++ b/include/vcl/texteng.hxx
@@ -100,7 +100,7 @@ private:
 
     IdleFormatter*      mpIdleFormatter;
 
-    TEIMEInfos*         mpIMEInfos;
+    std::unique_ptr<TEIMEInfos> mpIMEInfos;
 
     css::lang::Locale   maLocale;
     css::uno::Reference< css::i18n::XBreakIterator > mxBreakIterator;
diff --git a/sfx2/source/control/thumbnailviewitem.cxx b/sfx2/source/control/thumbnailviewitem.cxx
index 33a5b2d..249e1c4 100644
--- a/sfx2/source/control/thumbnailviewitem.cxx
+++ b/sfx2/source/control/thumbnailviewitem.cxx
@@ -37,6 +37,7 @@
 #include <vcl/graph.hxx>
 #include <vcl/svapp.hxx>
 #include <vcl/texteng.hxx>
+#include <vcl/textdata.hxx>
 
 using namespace basegfx;
 using namespace basegfx::tools;
diff --git a/vcl/source/edit/texteng.cxx b/vcl/source/edit/texteng.cxx
index f91e69d..4ba1f23 100644
--- a/vcl/source/edit/texteng.cxx
+++ b/vcl/source/edit/texteng.cxx
@@ -69,7 +69,6 @@ TextEngine::TextEngine()
     , mpActiveView {nullptr}
     , mpUndoManager {nullptr}
     , mpIdleFormatter {nullptr}
-    , mpIMEInfos {nullptr}
     , mpLocaleDataWrapper {nullptr}
     , maTextColor {COL_BLACK}
     , mnMaxTextLen {0}
@@ -118,7 +117,7 @@ TextEngine::~TextEngine()
     delete mpViews; // only the list, not the Views
     mpRefDev.disposeAndClear();
     delete mpUndoManager;
-    delete mpIMEInfos;
+    mpIMEInfos.reset();
     delete mpLocaleDataWrapper;
 }
 
diff --git a/vcl/source/edit/textview.cxx b/vcl/source/edit/textview.cxx
index 77a7c5a..42c2201 100644
--- a/vcl/source/edit/textview.cxx
+++ b/vcl/source/edit/textview.cxx
@@ -57,6 +57,7 @@
 #include <osl/mutex.hxx>
 
 #include <algorithm>
+#include <o3tl/make_unique.hxx>
 
 class TETextDataObject :    public css::datatransfer::XTransferable,
                         public ::cppu::OWeakObject
@@ -147,14 +148,14 @@ struct ImpTextView
     Point               maStartDocPos;
 //    TextPaM             maMBDownPaM;
 
-    vcl::Cursor*        mpCursor;
+    std::unique_ptr<vcl::Cursor> mpCursor;
 
-    TextDDInfo*         mpDDInfo;
+    std::unique_ptr<TextDDInfo> mpDDInfo;
 
     VclPtr<VirtualDevice>  mpVirtDev;
 
-    SelectionEngine*    mpSelEngine;
-    TextSelFunctionSet* mpSelFuncSet;
+    std::unique_ptr<SelectionEngine> mpSelEngine;
+    std::unique_ptr<TextSelFunctionSet> mpSelFuncSet;
 
     css::uno::Reference< css::datatransfer::dnd::XDragSourceListener > mxDnDListener;
 
@@ -195,14 +196,14 @@ TextView::TextView( ExtTextEngine* pEng, vcl::Window* pWindow ) :
 
     mpImpl->mnTravelXPos = TRAVEL_X_DONTKNOW;
 
-    mpImpl->mpSelFuncSet = new TextSelFunctionSet( this );
-    mpImpl->mpSelEngine = new SelectionEngine( mpImpl->mpWindow, mpImpl->mpSelFuncSet );
+    mpImpl->mpSelFuncSet = o3tl::make_unique<TextSelFunctionSet>( this );
+    mpImpl->mpSelEngine = o3tl::make_unique<SelectionEngine>( mpImpl->mpWindow, mpImpl->mpSelFuncSet.get() );
     mpImpl->mpSelEngine->SetSelectionMode( SelectionMode::Range );
     mpImpl->mpSelEngine->EnableDrag( true );
 
-    mpImpl->mpCursor = new vcl::Cursor;
+    mpImpl->mpCursor = o3tl::make_unique<vcl::Cursor>();
     mpImpl->mpCursor->Show();
-    pWindow->SetCursor( mpImpl->mpCursor );
+    pWindow->SetCursor( mpImpl->mpCursor.get() );
     pWindow->SetInputContext( InputContext( pEng->GetFont(), InputContextFlags::Text|InputContextFlags::ExtText ) );
 
     if ( pWindow->GetSettings().GetStyleSettings().GetSelectionOptions() & SelectionOptions::Invert )
@@ -210,8 +211,6 @@ TextView::TextView( ExtTextEngine* pEng, vcl::Window* pWindow ) :
 
     pWindow->SetLineColor();
 
-    mpImpl->mpDDInfo = nullptr;
-
     if ( pWindow->GetDragGestureRecognizer().is() )
     {
         vcl::unohelper::DragAndDropWrapper* pDnDWrapper = new vcl::unohelper::DragAndDropWrapper( this );
@@ -228,14 +227,16 @@ TextView::TextView( ExtTextEngine* pEng, vcl::Window* pWindow ) :
 
 TextView::~TextView()
 {
-    delete mpImpl->mpSelEngine;
-    delete mpImpl->mpSelFuncSet;
+    mpImpl->mpSelEngine.reset();
+    mpImpl->mpSelFuncSet.reset();
+
     mpImpl->mpVirtDev.disposeAndClear();
 
-    if ( mpImpl->mpWindow->GetCursor() == mpImpl->mpCursor )
+    if ( mpImpl->mpWindow->GetCursor() == mpImpl->mpCursor.get() )
         mpImpl->mpWindow->SetCursor( nullptr );
-    delete mpImpl->mpCursor;
-    delete mpImpl->mpDDInfo;
+
+    mpImpl->mpCursor.reset();
+    mpImpl->mpDDInfo.reset();
 }
 
 void TextView::Invalidate()
@@ -847,9 +848,8 @@ void TextView::Command( const CommandEvent& rCEvt )
     if ( rCEvt.GetCommand() == CommandEventId::StartExtTextInput )
     {
         DeleteSelected();
-        delete mpImpl->mpTextEngine->mpIMEInfos;
         TextNode* pNode = mpImpl->mpTextEngine->mpDoc->GetNodes()[ GetSelection().GetEnd().GetPara() ];
-        mpImpl->mpTextEngine->mpIMEInfos = new TEIMEInfos( GetSelection().GetEnd(), pNode->GetText().copy( GetSelection().GetEnd().GetIndex() ) );
+        mpImpl->mpTextEngine->mpIMEInfos = o3tl::make_unique<TEIMEInfos>( GetSelection().GetEnd(), pNode->GetText().copy( GetSelection().GetEnd().GetIndex() ) );
         mpImpl->mpTextEngine->mpIMEInfos->bWasCursorOverwrite = !IsInsertMode();
     }
     else if ( rCEvt.GetCommand() == CommandEventId::EndExtTextInput )
@@ -862,8 +862,7 @@ void TextView::Command( const CommandEvent& rCEvt )
 
             bool bInsertMode = !mpImpl->mpTextEngine->mpIMEInfos->bWasCursorOverwrite;
 
-            delete mpImpl->mpTextEngine->mpIMEInfos;
-            mpImpl->mpTextEngine->mpIMEInfos = nullptr;
+            mpImpl->mpTextEngine->mpIMEInfos.reset();
 
             mpImpl->mpTextEngine->TextModified();
             mpImpl->mpTextEngine->FormatAndUpdate( this );
@@ -1760,7 +1759,7 @@ bool TextView::SetCursorAtPoint( const Point& rPosPixel )
         ShowSelection( aTmpNewSel );
     }
 
-    bool bForceCursor =  mpImpl->mpDDInfo == nullptr; // && !mbInSelection
+    bool bForceCursor = !mpImpl->mpDDInfo; // && !mbInSelection
     ImpShowCursor( mpImpl->mbAutoScroll, bForceCursor, false );
     return true;
 }
@@ -1898,8 +1897,7 @@ void TextView::dragGestureRecognized( const css::datatransfer::dnd::DragGestureE
 
         SAL_WARN_IF( !mpImpl->maSelection.HasRange(), "vcl", "TextView::dragGestureRecognized: mpImpl->mbClickedInSelection, but no selection?" );
 
-        delete mpImpl->mpDDInfo;
-        mpImpl->mpDDInfo = new TextDDInfo;
+        mpImpl->mpDDInfo = o3tl::make_unique<TextDDInfo>();
         mpImpl->mpDDInfo->mbStarterOfDD = true;
 
         TETextDataObject* pDataObj = new TETextDataObject( GetSelected() );
@@ -1940,8 +1938,7 @@ void TextView::dragGestureRecognized( const css::datatransfer::dnd::DragGestureE
 void TextView::dragDropEnd( const css::datatransfer::dnd::DragSourceDropEvent& ) throw (css::uno::RuntimeException, std::exception)
 {
     ImpHideDDCursor();
-    delete mpImpl->mpDDInfo;
-    mpImpl->mpDDInfo = nullptr;
+    mpImpl->mpDDInfo.reset();
 }
 
 void TextView::drop( const css::datatransfer::dnd::DropTargetDropEvent& rDTDE ) throw (css::uno::RuntimeException, std::exception)
@@ -2041,8 +2038,7 @@ void TextView::drop( const css::datatransfer::dnd::DropTargetDropEvent& rDTDE )
 
         mpImpl->mpTextEngine->UndoActionEnd();
 
-        delete mpImpl->mpDDInfo;
-        mpImpl->mpDDInfo = nullptr;
+        mpImpl->mpDDInfo.reset();
 
         mpImpl->mpTextEngine->FormatAndUpdate( this );
 
@@ -2066,7 +2062,7 @@ void TextView::dragOver( const css::datatransfer::dnd::DropTargetDragEvent& rDTD
     SolarMutexGuard aVclGuard;
 
     if ( !mpImpl->mpDDInfo )
-        mpImpl->mpDDInfo = new TextDDInfo;
+        mpImpl->mpDDInfo = o3tl::make_unique<TextDDInfo>();
 
     TextPaM aPrevDropPos = mpImpl->mpDDInfo->maDropPos;
     Point aMousePos( rDTDE.LocationX, rDTDE.LocationY );


More information about the Libreoffice-commits mailing list