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

Noel Grandin noel.grandin at collabora.co.uk
Mon Apr 23 06:16:55 UTC 2018


 include/vcl/menu.hxx                         |    2 
 include/vcl/splitwin.hxx                     |    2 
 ucb/source/cacher/cachedcontentresultset.cxx |   10 +--
 ucb/source/cacher/cachedcontentresultset.hxx |    2 
 ucb/source/sorter/sortdynres.cxx             |   13 +----
 ucb/source/sorter/sortresult.cxx             |   70 +++++++++++++--------------
 ucb/source/sorter/sortresult.hxx             |   20 +++----
 vcl/source/window/menu.cxx                   |   26 +++-------
 vcl/source/window/splitwin.cxx               |   50 ++++++++-----------
 9 files changed, 86 insertions(+), 109 deletions(-)

New commits:
commit 00dd50d1a82d04df2baebcc3ae2f5ddab5c43997
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Fri Apr 20 17:04:03 2018 +0200

    loplugin:useuniqueptr in CachedContentResultSet::CCRS_Cache
    
    Change-Id: Idb2dd770ef39119f2a6ee6989bb983c3c77a1d68
    Reviewed-on: https://gerrit.libreoffice.org/53235
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/ucb/source/cacher/cachedcontentresultset.cxx b/ucb/source/cacher/cachedcontentresultset.cxx
index bf343123616c..0c7bc5ef2a76 100644
--- a/ucb/source/cacher/cachedcontentresultset.cxx
+++ b/ucb/source/cacher/cachedcontentresultset.cxx
@@ -246,8 +246,7 @@ bool CachedContentResultSet::CCRS_Cache
 void CachedContentResultSet::CCRS_Cache
     ::clearMappedReminder()
 {
-    delete m_pMappedReminder;
-    m_pMappedReminder = nullptr;
+    m_pMappedReminder.reset();
 }
 
 Sequence< sal_Bool >* CachedContentResultSet::CCRS_Cache
@@ -256,11 +255,10 @@ Sequence< sal_Bool >* CachedContentResultSet::CCRS_Cache
     if( !m_pMappedReminder )
     {
         sal_Int32 nCount = m_pResult->Rows.getLength();
-        m_pMappedReminder = new Sequence< sal_Bool >( nCount );
-        for( ;nCount; nCount-- )
-            (*m_pMappedReminder)[nCount] = false;
+        m_pMappedReminder.reset(new Sequence< sal_Bool >( nCount ));
+        std::fill(m_pMappedReminder->begin(), m_pMappedReminder->end(), false);
     }
-    return m_pMappedReminder;
+    return m_pMappedReminder.get();
 }
 
 const Any& CachedContentResultSet::CCRS_Cache
diff --git a/ucb/source/cacher/cachedcontentresultset.hxx b/ucb/source/cacher/cachedcontentresultset.hxx
index 51e73b1317bd..174fb91ff568 100644
--- a/ucb/source/cacher/cachedcontentresultset.hxx
+++ b/ucb/source/cacher/cachedcontentresultset.hxx
@@ -56,7 +56,7 @@ class CachedContentResultSet
                                          m_pResult;
         css::uno::Reference< css::ucb::XContentIdentifierMapping >
                                          m_xContentIdentifierMapping;
-        css::uno::Sequence< sal_Bool >*  m_pMappedReminder;
+        std::unique_ptr<css::uno::Sequence< sal_Bool >>  m_pMappedReminder;
 
     private:
         /// @throws css::sdbc::SQLException
commit d23b20661c83ebb722e4602d0ef9d65ce1ecfa6d
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Fri Apr 20 16:18:50 2018 +0200

    loplugin:useuiqueptr in SortedEntryList and EventList
    
    Change-Id: I15e6e29347dfce68e5631337bf2d3754bffdf864
    Reviewed-on: https://gerrit.libreoffice.org/53234
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/ucb/source/sorter/sortdynres.cxx b/ucb/source/sorter/sortdynres.cxx
index e3b20bd62539..32bc6f7a3761 100644
--- a/ucb/source/sorter/sortdynres.cxx
+++ b/ucb/source/sorter/sortdynres.cxx
@@ -307,13 +307,13 @@ void SortedDynamicResultSet::impl_notify( const ListEvent& Changes )
                         aWelcome.Old = mxTwo.get();
                         aWelcome.New = mxOne.get();
 
-                        ListAction *pWelcomeAction = new ListAction;
+                        std::unique_ptr<ListAction> pWelcomeAction(new ListAction);
                         pWelcomeAction->ActionInfo <<= aWelcome;
                         pWelcomeAction->Position = 0;
                         pWelcomeAction->Count = 0;
                         pWelcomeAction->ListActionType = ListActionType::WELCOME;
 
-                        maActions.Insert( pWelcomeAction );
+                        maActions.Insert( std::move(pWelcomeAction) );
                     }
                     else
                     {
@@ -483,22 +483,17 @@ SortedDynamicResultSetFactory::createSortedDynamicResultSet(
 
 void EventList::Clear()
 {
-    for (ListAction* p : maData)
-    {
-        delete p;
-    }
-
     maData.clear();
 }
 
 void EventList::AddEvent( sal_IntPtr nType, sal_IntPtr nPos )
 {
-    ListAction *pAction = new ListAction;
+    std::unique_ptr<ListAction> pAction(new ListAction);
     pAction->Position = nPos;
     pAction->Count = 1;
     pAction->ListActionType = nType;
 
-    Insert( pAction );
+    Insert( std::move(pAction) );
 }
 
 // SortedDynamicResultSetListener
diff --git a/ucb/source/sorter/sortresult.cxx b/ucb/source/sorter/sortresult.cxx
index e18360794bf4..f8b4b05b4bd5 100644
--- a/ucb/source/sorter/sortresult.cxx
+++ b/ucb/source/sorter/sortresult.cxx
@@ -1248,7 +1248,7 @@ void SortedResultSet::CopyData( SortedResultSet *pSource )
 
     for ( i=1; i<nCount; i++ )
     {
-        maS2O.Insert( new SortListData( rSrcS2O[ i ] ), i );
+        maS2O.Insert( std::unique_ptr<SortListData>(new SortListData( rSrcS2O[ i ] )), i );
         m_O2S.push_back(pSource->m_O2S[i]);
     }
 
@@ -1269,8 +1269,7 @@ void SortedResultSet::Initialize(
 {
     BuildSortInfo( mxOriginal, xSortInfo, xCompFactory );
     // Insert dummy at pos 0
-    SortListData *pData = new SortListData( 0 );
-    maS2O.Insert( pData, 0 );
+    maS2O.Insert( std::unique_ptr<SortListData>(new SortListData( 0 )), 0 );
 
     sal_IntPtr nIndex = 1;
 
@@ -1280,10 +1279,10 @@ void SortedResultSet::Initialize(
     try {
         while ( mxOriginal->absolute( nIndex ) )
         {
-            pData       = new SortListData( nIndex );
-            sal_IntPtr nPos   = FindPos( pData, 1, nIndex-1 );
+            std::unique_ptr<SortListData> pData(new SortListData( nIndex ));
+            sal_IntPtr nPos   = FindPos( pData.get(), 1, nIndex-1 );
 
-            maS2O.Insert( pData, nPos );
+            maS2O.Insert( std::move(pData), nPos );
 
             nIndex++;
         }
@@ -1354,13 +1353,12 @@ void SortedResultSet::CheckProperties( sal_IntPtr nOldCount, bool bWasFinal )
 void SortedResultSet::InsertNew( sal_IntPtr nPos, sal_IntPtr nCount )
 {
     // for all entries in the msS20-list, which are >= nPos, increase by nCount
-    SortListData    *pData;
     sal_IntPtr      i, nEnd;
 
     nEnd = maS2O.Count();
     for ( i=1; i<=nEnd; i++ )
     {
-        pData = maS2O.GetData( i );
+        SortListData *pData = maS2O.GetData( i );
         if ( pData->mnCurPos >= nPos )
         {
             pData->mnCurPos += nCount;
@@ -1372,9 +1370,9 @@ void SortedResultSet::InsertNew( sal_IntPtr nPos, sal_IntPtr nCount )
     for ( i=0; i<nCount; i++ )
     {
         nEnd += 1;
-        pData = new SortListData( nEnd );
+        std::unique_ptr<SortListData> pData(new SortListData( nEnd ));
 
-        maS2O.Insert( pData, nEnd );    // Insert( Value, Position )
+        maS2O.Insert( std::move(pData), nEnd );    // Insert( Value, Position )
         m_O2S.insert(m_O2S.begin() + nPos + i, nEnd);
     }
 
@@ -1414,10 +1412,9 @@ void SortedResultSet::Remove( sal_IntPtr nPos, sal_IntPtr nCount, EventList *pEv
             }
         }
 
-        SortListData *pData = maS2O.Remove( nSortPos );
+        std::unique_ptr<SortListData> pData = maS2O.Remove( nSortPos );
         if ( pData->mbModified )
-            m_ModList.erase(std::find(m_ModList.begin(), m_ModList.end(), pData));
-        delete pData;
+            m_ModList.erase(std::find(m_ModList.begin(), m_ModList.end(), pData.get()));
 
         // generate remove Event, but not for new entries
         if ( nSortPos <= nOldLastSort )
@@ -1586,7 +1583,6 @@ void SortedResultSet::ResortModified( EventList* pList )
 {
     sal_IntPtr nCompare, nCurPos, nNewPos;
     sal_IntPtr nStart, nEnd, nOffset, nVal;
-    ListAction *pAction;
 
     try {
         for (size_t i = 0; i < m_ModList.size(); ++i)
@@ -1616,8 +1612,7 @@ void SortedResultSet::ResortModified( EventList* pList )
                 if ( nNewPos != nCurPos )
                 {
                     // correct the lists!
-                    maS2O.Remove( static_cast<sal_uInt32>(nCurPos) );
-                    maS2O.Insert( pData, nNewPos );
+                    maS2O.Move( static_cast<sal_uInt32>(nCurPos), nNewPos );
                     for (size_t j = 1; j < m_O2S.size(); ++j)
                     {
                         nVal = m_O2S[j];
@@ -1630,12 +1625,12 @@ void SortedResultSet::ResortModified( EventList* pList )
 
                     m_O2S[pData->mnCurPos] = nNewPos;
 
-                    pAction = new ListAction;
+                    std::unique_ptr<ListAction> pAction(new ListAction);
                     pAction->Position = nCurPos;
                     pAction->Count = 1;
                     pAction->ListActionType = ListActionType::MOVED;
                     pAction->ActionInfo <<= nNewPos-nCurPos;
-                    pList->Insert( pAction );
+                    pList->Insert( std::move(pAction) );
                 }
                 pList->AddEvent( ListActionType::PROPERTIES_CHANGED, nNewPos );
             }
@@ -1661,8 +1656,7 @@ void SortedResultSet::ResortNew( EventList* pList )
             nNewPos = FindPos( pData, 1, mnLastSort );
             if ( nNewPos != i )
             {
-                maS2O.Remove( static_cast<sal_uInt32>(i) );
-                maS2O.Insert( pData, nNewPos );
+                maS2O.Move( static_cast<sal_uInt32>(i), nNewPos );
                 for (size_t j=1; j< m_O2S.size(); ++j)
                 {
                     nVal = m_O2S[j];
@@ -1692,38 +1686,44 @@ SortListData::SortListData( sal_IntPtr nPos )
     mnOldPos = nPos;
 };
 
+SortedEntryList::SortedEntryList()
+{
+}
 
-void SortedEntryList::Clear()
+SortedEntryList::~SortedEntryList()
 {
-    for (SortListData* p : maData)
-    {
-        delete p;
-    }
+}
 
+void SortedEntryList::Clear()
+{
     maData.clear();
 }
 
 
-void SortedEntryList::Insert( SortListData *pEntry, sal_IntPtr nPos )
+void SortedEntryList::Insert( std::unique_ptr<SortListData> pEntry, sal_IntPtr nPos )
 {
     if ( nPos < static_cast<sal_IntPtr>(maData.size()) )
-        maData.insert( maData.begin() + nPos, pEntry );
+        maData.insert( maData.begin() + nPos, std::move(pEntry) );
     else
-        maData.push_back( pEntry );
+        maData.push_back( std::move(pEntry) );
 }
 
+void SortedEntryList::Move( sal_IntPtr nOldPos, sal_IntPtr nNewPos )
+{
+    auto p = std::move(maData[nOldPos]);
+    maData.erase( maData.begin() + nOldPos );
+    maData.insert(maData.begin() + nNewPos, std::move(p));
+}
 
-SortListData* SortedEntryList::Remove( sal_IntPtr nPos )
+std::unique_ptr<SortListData> SortedEntryList::Remove( sal_IntPtr nPos )
 {
-    SortListData *pData;
+    std::unique_ptr<SortListData> pData;
 
     if ( nPos < static_cast<sal_IntPtr>(maData.size()) )
     {
-        pData = maData[ nPos ];
+        pData = std::move(maData[ nPos ]);
         maData.erase( maData.begin() + nPos );
     }
-    else
-        pData = nullptr;
 
     return pData;
 }
@@ -1734,7 +1734,7 @@ SortListData* SortedEntryList::GetData( sal_IntPtr nPos )
     SortListData *pData;
 
     if ( nPos < static_cast<sal_IntPtr>(maData.size()) )
-        pData = maData[ nPos ];
+        pData = maData[ nPos ].get();
     else
         pData = nullptr;
 
@@ -1747,7 +1747,7 @@ sal_IntPtr SortedEntryList::operator [] ( sal_IntPtr nPos ) const
     SortListData *pData;
 
     if ( nPos < static_cast<sal_IntPtr>(maData.size()) )
-        pData = maData[ nPos ];
+        pData = maData[ nPos ].get();
     else
         pData = nullptr;
 
diff --git a/ucb/source/sorter/sortresult.hxx b/ucb/source/sorter/sortresult.hxx
index f97f9050c6bc..fef58fb2341e 100644
--- a/ucb/source/sorter/sortresult.hxx
+++ b/ucb/source/sorter/sortresult.hxx
@@ -52,37 +52,37 @@ class   PropertyChangeListeners_Impl;
 
 class SortedEntryList
 {
-    std::deque < SortListData* > maData;
+    std::deque < std::unique_ptr<SortListData> > maData;
 
 public:
-                         SortedEntryList(){}
-                        ~SortedEntryList(){ Clear(); }
+                        SortedEntryList();
+                        ~SortedEntryList();
 
     sal_uInt32          Count() const { return static_cast<sal_uInt32>(maData.size()); }
 
     void                Clear();
-    void                Insert( SortListData *pEntry, sal_IntPtr nPos );
-    SortListData*       Remove( sal_IntPtr nPos );
+    void                Insert( std::unique_ptr<SortListData> pEntry, sal_IntPtr nPos );
+    std::unique_ptr<SortListData> Remove( sal_IntPtr nPos );
     SortListData*       GetData( sal_IntPtr nPos );
+    void                Move( sal_IntPtr nOldPos, sal_IntPtr nNewPos );
 
-    sal_IntPtr                operator [] ( sal_IntPtr nPos ) const;
+    sal_IntPtr          operator [] ( sal_IntPtr nPos ) const;
 };
 
 
 class EventList
 {
-    std::deque < css::ucb::ListAction* > maData;
+    std::deque < std::unique_ptr<css::ucb::ListAction> > maData;
 
 public:
                      EventList(){}
-                    ~EventList(){ Clear(); }
 
     sal_uInt32      Count() { return static_cast<sal_uInt32>(maData.size()); }
 
     void            AddEvent( sal_IntPtr nType, sal_IntPtr nPos );
-    void            Insert( css::ucb::ListAction *pAction ) { maData.push_back( pAction ); }
+    void            Insert( std::unique_ptr<css::ucb::ListAction> pAction ) { maData.push_back( std::move(pAction) ); }
     void            Clear();
-    css::ucb::ListAction*     GetAction( sal_IntPtr nIndex ) { return maData[ nIndex ]; }
+    css::ucb::ListAction*     GetAction( sal_IntPtr nIndex ) { return maData[ nIndex ].get(); }
 };
 
 
commit 16632fa9f5dfbe8bd6f34f719ac923e972f250ca
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Mon Apr 16 12:54:25 2018 +0200

    loplugin:useuniqueptr in SplitWindow
    
    Change-Id: I04b45f02ce0dc98d11fb78982b8364fdd8333f9c
    Reviewed-on: https://gerrit.libreoffice.org/53233
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/vcl/splitwin.hxx b/include/vcl/splitwin.hxx
index d56000da2042..4e5b4511b213 100644
--- a/include/vcl/splitwin.hxx
+++ b/include/vcl/splitwin.hxx
@@ -47,7 +47,7 @@ namespace o3tl
 class VCL_DLLPUBLIC SplitWindow : public DockingWindow
 {
 private:
-    ImplSplitSet*       mpMainSet;
+    std::unique_ptr<ImplSplitSet> mpMainSet;
     ImplSplitSet*       mpBaseSet;
     ImplSplitSet*       mpSplitSet;
     long*               mpLastSizes;
diff --git a/vcl/source/window/splitwin.cxx b/vcl/source/window/splitwin.cxx
index a0a2be3fb4e7..c1166fd1fe74 100644
--- a/vcl/source/window/splitwin.cxx
+++ b/vcl/source/window/splitwin.cxx
@@ -1166,7 +1166,7 @@ sal_uInt16 SplitWindow::ImplTestSplit( SplitWindow* pWindow, const Point& rPos,
         if ( (nTPos >= nPos) && (nTPos <= nPos+nSplitSize+nBorder) )
         {
             rMouseOff = nTPos-nPos;
-            *ppFoundSet = pWindow->mpMainSet;
+            *ppFoundSet = pWindow->mpMainSet.get();
             if ( !pWindow->mpMainSet->mvItems.empty() )
                 rFoundPos = pWindow->mpMainSet->mvItems.size() - 1;
             else
@@ -1178,7 +1178,7 @@ sal_uInt16 SplitWindow::ImplTestSplit( SplitWindow* pWindow, const Point& rPos,
         }
     }
 
-    return ImplTestSplit( pWindow->mpMainSet, rPos, rMouseOff, ppFoundSet, rFoundPos,
+    return ImplTestSplit( pWindow->mpMainSet.get(), rPos, rMouseOff, ppFoundSet, rFoundPos,
                          pWindow->mbHorz );
 }
 
@@ -1219,10 +1219,8 @@ void SplitWindow::ImplDrawSplitTracking(const Point& rPos)
 
 void SplitWindow::ImplInit( vcl::Window* pParent, WinBits nStyle )
 {
-    ImplSplitSet* pNewSet   = new ImplSplitSet();
-
-    mpMainSet               = pNewSet;
-    mpBaseSet               = pNewSet;
+    mpMainSet.reset(new ImplSplitSet());
+    mpBaseSet               = mpMainSet.get();
     mpSplitSet              = nullptr;
     mpLastSizes             = nullptr;
     mnDX                    = 0;
@@ -1256,7 +1254,7 @@ void SplitWindow::ImplInit( vcl::Window* pParent, WinBits nStyle )
 
     if ( nStyle & WB_NOSPLITDRAW )
     {
-        pNewSet->mnSplitSize -= 2;
+        mpMainSet->mnSplitSize -= 2;
         mbInvalidate = false;
     }
 
@@ -1317,10 +1315,7 @@ SplitWindow::~SplitWindow()
 void SplitWindow::dispose()
 {
     // delete Sets
-    if (mpMainSet) {
-        delete mpMainSet ;
-        mpMainSet = nullptr; //NULL for base-class callbacks during destruction
-    }
+    mpMainSet.reset();
     DockingWindow::dispose();
 }
 
@@ -1501,8 +1496,8 @@ void SplitWindow::ImplCalcLayout()
     }
 
     // calculate sets recursive
-    ImplCalcSet( mpMainSet, nL, nT, nW, nH, mbHorz, !mbBottomRight );
-    ImplCalcSet2( this, mpMainSet, false, mbHorz );
+    ImplCalcSet( mpMainSet.get(), nL, nT, nW, nH, mbHorz, !mbBottomRight );
+    ImplCalcSet2( this, mpMainSet.get(), false, mbHorz );
     mbCalc = false;
 }
 
@@ -1794,7 +1789,7 @@ void SplitWindow::ImplStartSplit( const MouseEvent& rMEvt )
     if ( !mpSplitSet->mvItems.empty() )
     {
         bool bDown = true;
-        if ( (mpSplitSet == mpMainSet) && mbBottomRight )
+        if ( (mpSplitSet == mpMainSet.get()) && mbBottomRight )
             bDown = false;
 
         pSplitItem          = &mpSplitSet->mvItems[mnSplitPos];
@@ -1847,7 +1842,7 @@ void SplitWindow::ImplStartSplit( const MouseEvent& rMEvt )
             }
         }
 
-        if ( (mpSplitSet == mpMainSet) && (mnWinStyle & WB_SIZEABLE) && !bPropSmaller )
+        if ( (mpSplitSet == mpMainSet.get()) && (mnWinStyle & WB_SIZEABLE) && !bPropSmaller )
         {
             if ( bDown )
             {
@@ -2157,14 +2152,14 @@ void SplitWindow::Tracking( const TrackingEvent& rTEvt )
 
             if ( (mnSplitTest & SPLIT_WINDOW) && mpMainSet->mvItems.empty() )
             {
-                if ( (mpSplitSet == mpMainSet) && mbBottomRight )
+                if ( (mpSplitSet == mpMainSet.get()) && mbBottomRight )
                     nDelta *= -1;
                 ImplSetWindowSize( nDelta );
             }
             else
             {
                 long nNewSize = mpSplitSet->mvItems[mnSplitPos].mnPixSize;
-                if ( (mpSplitSet == mpMainSet) && mbBottomRight )
+                if ( (mpSplitSet == mpMainSet.get()) && mbBottomRight )
                     nNewSize -= nDelta;
                 else
                     nNewSize += nDelta;
@@ -2235,12 +2230,12 @@ void SplitWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectang
     ImplDrawFadeIn(rRenderContext);
 
     // draw FrameSet-backgrounds
-    ImplDrawBack(rRenderContext, mpMainSet);
+    ImplDrawBack(rRenderContext, mpMainSet.get());
 
     // draw splitter
     if (!(mnWinStyle & WB_NOSPLITDRAW))
     {
-        ImplDrawSplit(rRenderContext, mpMainSet, mbHorz, !mbBottomRight);
+        ImplDrawSplit(rRenderContext, mpMainSet.get(), mbHorz, !mbBottomRight);
     }
 }
 
@@ -2336,14 +2331,14 @@ void SplitWindow::InsertItem( sal_uInt16 nId, vcl::Window* pWindow, long nSize,
 {
 #ifdef DBG_UTIL
     sal_uInt16 nDbgDummy;
-    SAL_WARN_IF( ImplFindItem( mpMainSet, nId, nDbgDummy ), "vcl", "SplitWindow::InsertItem() - Id already exists" );
+    SAL_WARN_IF( ImplFindItem( mpMainSet.get(), nId, nDbgDummy ), "vcl", "SplitWindow::InsertItem() - Id already exists" );
 #endif
 
     // Size has to be at least 1.
     if ( nSize < 1 )
         nSize = 1;
 
-    ImplSplitSet* pSet       = ImplFindSet( mpMainSet, nIntoSetId );
+    ImplSplitSet* pSet       = ImplFindSet( mpMainSet.get(), nIntoSetId );
 #ifdef DBG_UTIL
     SAL_WARN_IF( !pSet, "vcl", "SplitWindow::InsertItem() - Set not exists" );
 #endif
@@ -2403,12 +2398,12 @@ void SplitWindow::RemoveItem( sal_uInt16 nId )
 {
 #ifdef DBG_UTIL
     sal_uInt16 nDbgDummy;
-    SAL_WARN_IF( !ImplFindItem( mpMainSet, nId, nDbgDummy ), "vcl", "SplitWindow::RemoveItem() - Id not found" );
+    SAL_WARN_IF( !ImplFindItem( mpMainSet.get(), nId, nDbgDummy ), "vcl", "SplitWindow::RemoveItem() - Id not found" );
 #endif
 
     // search set
     sal_uInt16     nPos;
-    ImplSplitSet*  pSet    = ImplFindItem( mpMainSet, nId, nPos );
+    ImplSplitSet*  pSet    = ImplFindItem( mpMainSet.get(), nId, nPos );
 
     if (!pSet)
         return;
@@ -2442,14 +2437,11 @@ void SplitWindow::RemoveItem( sal_uInt16 nId )
 
 void SplitWindow::Clear()
 {
-    // delete all sets
-    delete mpMainSet ;
-
     // create Main-Set again
-    mpMainSet = new ImplSplitSet();
+    mpMainSet.reset(new ImplSplitSet());
     if ( mnWinStyle & WB_NOSPLITDRAW )
         mpMainSet->mnSplitSize -= 2;
-    mpBaseSet = mpMainSet;
+    mpBaseSet = mpMainSet.get();
 
     // and invalidate again
     ImplUpdate();
@@ -2498,7 +2490,7 @@ void SplitWindow::SplitItem( sal_uInt16 nId, long nNewSize,
     // treat TopSet different if the window is sizeable
     bool bSmall  = true;
     bool bGreat  = true;
-    if ( (pSet == mpMainSet) && (mnWinStyle & WB_SIZEABLE) )
+    if ( (pSet == mpMainSet.get()) && (mnWinStyle & WB_SIZEABLE) )
     {
         if ( nPos < pSet->mvItems.size()-1 )
         {
commit 7c256096962d73b360b870688ead7152b3378df9
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Mon Apr 16 12:49:52 2018 +0200

    loplugin:useuniqueptr in Menu
    
    Change-Id: I4de2081597ffc55a95fe5b482c37461811f323e6
    Reviewed-on: https://gerrit.libreoffice.org/53232
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/vcl/menu.hxx b/include/vcl/menu.hxx
index b55a5338a91d..6c73d802802f 100644
--- a/include/vcl/menu.hxx
+++ b/include/vcl/menu.hxx
@@ -156,7 +156,7 @@ private:
     bool bKilled : 1; ///< Killed
 
     css::uno::Reference<css::accessibility::XAccessible > mxAccessible;
-    mutable vcl::MenuLayoutData* mpLayoutData;
+    mutable std::unique_ptr<vcl::MenuLayoutData> mpLayoutData;
     SalMenu* mpSalMenu;
 
 protected:
diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx
index aea9e2dbab7b..a0cdd3b7f3de 100644
--- a/vcl/source/window/menu.cxx
+++ b/vcl/source/window/menu.cxx
@@ -228,8 +228,7 @@ void Menu::dispose()
     bKilled = true;
 
     pItemList->Clear();
-    delete mpLayoutData;
-    mpLayoutData = nullptr;
+    mpLayoutData.reset();
 
     // Native-support: destroy SalMenu
     ImplClearSalMenu();
@@ -452,8 +451,7 @@ void Menu::InsertItem(sal_uInt16 nItemId, const OUString& rStr, MenuItemBits nIt
     NbcInsertItem(nItemId, nItemBits, rStr, this, nPos, rIdent);
 
     vcl::Window* pWin = ImplGetWindow();
-    delete mpLayoutData;
-    mpLayoutData = nullptr;
+    mpLayoutData.reset();
     if ( pWin )
     {
         ImplCalcSize( pWin );
@@ -518,8 +516,7 @@ void Menu::InsertSeparator(const OString &rIdent, sal_uInt16 nPos)
     if( ImplGetSalMenu() && pData && pData->pSalMenuItem )
         ImplGetSalMenu()->InsertItem( pData->pSalMenuItem, nPos );
 
-    delete mpLayoutData;
-    mpLayoutData = nullptr;
+    mpLayoutData.reset();
 
     ImplCallEventListeners( VclEventId::MenuInsertItem, nPos );
 }
@@ -545,8 +542,7 @@ void Menu::RemoveItem( sal_uInt16 nPos )
         if ( pWin->IsVisible() )
             pWin->Invalidate();
     }
-    delete mpLayoutData;
-    mpLayoutData = nullptr;
+    mpLayoutData.reset();
 
     if ( bRemove )
         ImplCallEventListeners( VclEventId::MenuRemoveItem, nPos );
@@ -1005,8 +1001,7 @@ void Menu::SetItemText( sal_uInt16 nItemId, const OUString& rStr )
             ImplGetSalMenu()->SetItemText( nPos, pData->pSalMenuItem, rStr );
 
         vcl::Window* pWin = ImplGetWindow();
-        delete mpLayoutData;
-        mpLayoutData = nullptr;
+        mpLayoutData.reset();
         if (pWin && IsMenuBar())
         {
             ImplCalcSize( pWin );
@@ -2201,8 +2196,7 @@ void Menu::RemoveDisabledEntries( bool bCheckPopups, bool bRemoveEmptyPopups )
         if ( pItem->eType == MenuItemType::SEPARATOR )
             RemoveItem( nLast );
     }
-    delete mpLayoutData;
-    mpLayoutData = nullptr;
+    mpLayoutData.reset();
 }
 
 void Menu::UpdateNativeMenu()
@@ -2217,15 +2211,14 @@ void Menu::MenuBarKeyInput(const KeyEvent&)
 
 void Menu::ImplKillLayoutData() const
 {
-    delete mpLayoutData;
-    mpLayoutData = nullptr;
+    mpLayoutData.reset();
 }
 
 void Menu::ImplFillLayoutData() const
 {
     if (pWindow && pWindow->IsReallyVisible())
     {
-        mpLayoutData = new MenuLayoutData;
+        mpLayoutData.reset(new MenuLayoutData);
         if (IsMenuBar())
         {
             ImplPaint(*pWindow, pWindow->GetOutputSizePixel(), 0, 0, nullptr, false, true); // FIXME
@@ -2813,8 +2806,7 @@ sal_uInt16 PopupMenu::ImplExecute( const VclPtr<vcl::Window>& pW, const tools::R
         pMenuBarWindow->SetMBWHideAccel( !(pMenuBarWindow->GetMBWMenuKey()) );
     }
 
-    delete mpLayoutData;
-    mpLayoutData = nullptr;
+    mpLayoutData.reset();
 
     ImplSVData* pSVData = ImplGetSVData();
 


More information about the Libreoffice-commits mailing list