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

Noel Grandin noel.grandin at collabora.co.uk
Tue Oct 17 13:28:37 UTC 2017


 include/vcl/animate.hxx            |    4 +-
 vcl/inc/impanmvw.hxx               |    3 +
 vcl/source/gdi/animate.cxx         |   59 ++++++++++++-------------------------
 vcl/source/window/menuitemlist.cxx |   25 ++++++---------
 vcl/source/window/menuitemlist.hxx |    5 +--
 5 files changed, 37 insertions(+), 59 deletions(-)

New commits:
commit 2b19544e6f28c85128dc38c026636c0b62cbc35a
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Oct 17 14:00:15 2017 +0200

    use std::unique_ptr in vcl::Animation and vcl::MenuItemList
    
    Change-Id: I0d682bcf3bd9d5f4852675fd0d6b61f10ea4f7de
    Reviewed-on: https://gerrit.libreoffice.org/43455
    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/animate.hxx b/include/vcl/animate.hxx
index 06222cf35415..1b8844f2c959 100644
--- a/include/vcl/animate.hxx
+++ b/include/vcl/animate.hxx
@@ -169,8 +169,8 @@ public:
 private:
     SAL_DLLPRIVATE static sal_uLong mnAnimCount;
 
-    std::vector< AnimationBitmap* > maList;
-    std::vector< ImplAnimView* >    maViewList;
+    std::vector< std::unique_ptr<AnimationBitmap> > maList;
+    std::vector< std::unique_ptr<ImplAnimView> >    maViewList;
 
     Link<Animation*,void> maNotifyLink;
     BitmapEx        maBitmapEx;
diff --git a/vcl/inc/impanmvw.hxx b/vcl/inc/impanmvw.hxx
index 4e4414a57dae..97b5a5333425 100644
--- a/vcl/inc/impanmvw.hxx
+++ b/vcl/inc/impanmvw.hxx
@@ -66,11 +66,12 @@ private:
     bool            mbHMirr;
     bool            mbVMirr;
 
+public:
+                    ~ImplAnimView();
 private:
                     ImplAnimView( Animation* pParent, OutputDevice* pOut,
                                   const Point& rPt, const Size& rSz, sal_uLong nExtraData,
                                   OutputDevice* pFirstFrameOutDev = nullptr );
-                    ~ImplAnimView();
 
     bool            matches( OutputDevice* pOut, long nExtraData ) const;
     void            drawToPos( sal_uLong nPos );
diff --git a/vcl/source/gdi/animate.cxx b/vcl/source/gdi/animate.cxx
index aa49f7803848..e13448e34a28 100644
--- a/vcl/source/gdi/animate.cxx
+++ b/vcl/source/gdi/animate.cxx
@@ -79,8 +79,8 @@ Animation::Animation( const Animation& rAnimation ) :
     mbLoopTerminated    ( rAnimation.mbLoopTerminated )
 {
 
-    for(const AnimationBitmap* i : rAnimation.maList)
-        maList.push_back( new AnimationBitmap( *i ) );
+    for(auto const & i : rAnimation.maList)
+        maList.emplace_back( new AnimationBitmap( *i ) );
 
     maTimer.SetInvokeHandler( LINK( this, Animation, ImplTimeoutHdl ) );
     mnLoops = mbLoopTerminated ? 0 : mnLoopCount;
@@ -88,23 +88,16 @@ Animation::Animation( const Animation& rAnimation ) :
 
 Animation::~Animation()
 {
-
     if( mbIsInAnimation )
         Stop();
-
-    for(AnimationBitmap* i : maList)
-        delete i;
-
-    for(ImplAnimView* i : maViewList)
-        delete i;
 }
 
 Animation& Animation::operator=( const Animation& rAnimation )
 {
     Clear();
 
-    for(const AnimationBitmap* i : rAnimation.maList)
-        maList.push_back( new AnimationBitmap( *i ) );
+    for(auto const & i : rAnimation.maList)
+        maList.emplace_back( new AnimationBitmap( *i ) );
 
     maGlobalSize = rAnimation.maGlobalSize;
     maBitmapEx = rAnimation.maBitmapEx;
@@ -147,13 +140,7 @@ void Animation::Clear()
     mbIsInAnimation = false;
     maGlobalSize = Size();
     maBitmapEx.SetEmpty();
-
-    for(AnimationBitmap* i : maList)
-        delete i;
     maList.clear();
-
-    for(ImplAnimView* i : maViewList)
-        delete i;
     maViewList.clear();
 }
 
@@ -167,7 +154,7 @@ bool Animation::IsTransparent() const
     // we need to be transparent, in order to be displayed correctly
     // as the application (?) does not invalidate on non-transparent
     // graphics due to performance reasons.
-    for(const AnimationBitmap* pAnimBmp : maList)
+    for(auto const & pAnimBmp : maList)
     {
         if(  Disposal::Back == pAnimBmp->eDisposal
           && tools::Rectangle( pAnimBmp->aPosPix, pAnimBmp->aSizePix ) != aRect
@@ -188,7 +175,7 @@ sal_uLong Animation::GetSizeBytes() const
 {
     sal_uLong nSizeBytes = GetBitmapEx().GetSizeBytes();
 
-    for(const AnimationBitmap* pAnimBmp : maList)
+    for(auto const & pAnimBmp : maList)
     {
         nSizeBytes += pAnimBmp->aBmpEx.GetSizeBytes();
     }
@@ -211,7 +198,7 @@ BitmapChecksum Animation::GetChecksum() const
     UInt32ToSVBT32( maGlobalSize.Height(), aBT32 );
     nCrc = vcl_get_checksum( nCrc, aBT32, 4 );
 
-    for(const AnimationBitmap* i : maList)
+    for(auto const & i : maList)
     {
         BCToBCOA( i->GetChecksum(), aBCOA );
         nCrc = vcl_get_checksum( nCrc, aBCOA, BITMAP_CHECKSUM_SIZE );
@@ -237,7 +224,7 @@ bool Animation::Start( OutputDevice* pOut, const Point& rDestPt, const Size& rDe
 
             for( size_t i = 0; i < maViewList.size(); ++i )
             {
-                pView = maViewList[ i ];
+                pView = maViewList[ i ].get();
                 if( pView->matches( pOut, nExtraData ) )
                 {
                     if( pView->getOutPos() == rDestPt &&
@@ -248,7 +235,6 @@ bool Animation::Start( OutputDevice* pOut, const Point& rDestPt, const Size& rDe
                     }
                     else
                     {
-                        delete maViewList[ i ];
                         maViewList.erase( maViewList.begin() + i );
                         pView = nullptr;
                     }
@@ -265,7 +251,7 @@ bool Animation::Start( OutputDevice* pOut, const Point& rDestPt, const Size& rDe
             }
 
             if( !pMatch )
-                maViewList.push_back( new ImplAnimView( this, pOut, rDestPt, rDestSz, nExtraData, pFirstFrameOutDev ) );
+                maViewList.emplace_back( new ImplAnimView( this, pOut, rDestPt, rDestSz, nExtraData, pFirstFrameOutDev ) );
 
             if( !mbIsInAnimation )
             {
@@ -286,11 +272,9 @@ void Animation::Stop( OutputDevice* pOut, long nExtraData )
 {
     for( size_t i = 0; i < maViewList.size(); )
     {
-
-        ImplAnimView* pView = maViewList[ i ];
+        ImplAnimView* pView = maViewList[ i ].get();
         if( pView->matches( pOut, nExtraData ) )
         {
-            delete pView;
             maViewList.erase( maViewList.begin() + i );
         }
         else
@@ -315,7 +299,7 @@ void Animation::Draw( OutputDevice* pOut, const Point& rDestPt, const Size& rDes
 
     if( nCount )
     {
-        AnimationBitmap* pObj = maList[ std::min( mnPos, nCount - 1 ) ];
+        AnimationBitmap* pObj = maList[ std::min( mnPos, nCount - 1 ) ].get();
 
         if(  pOut->GetConnectMetaFile()
           || ( pOut->GetOutDevType() == OUTDEV_PRINTER )
@@ -352,7 +336,7 @@ IMPL_LINK_NOARG(Animation, ImplTimeoutHdl, Timer *, void)
         if( maNotifyLink.IsSet() )
         {
             // create AInfo-List
-            for(ImplAnimView* i : maViewList)
+            for(auto const & i : maViewList)
                 aAInfoList.push_back( i->createAInfo() );
 
             maNotifyLink.Call( this );
@@ -365,7 +349,7 @@ IMPL_LINK_NOARG(Animation, ImplTimeoutHdl, Timer *, void)
                     pView = new ImplAnimView( this, pAInfo->pOutDev,
                                               pAInfo->aStartOrg, pAInfo->aStartSize, pAInfo->nExtraData );
 
-                    maViewList.push_back( pView );
+                    maViewList.push_back( std::unique_ptr<ImplAnimView>(pView) );
                 }
                 else
                     pView = static_cast<ImplAnimView*>(pAInfo->pViewData);
@@ -382,10 +366,9 @@ IMPL_LINK_NOARG(Animation, ImplTimeoutHdl, Timer *, void)
             // delete all unmarked views and reset marked state
             for( size_t i = 0; i < maViewList.size(); )
             {
-                pView = maViewList[ i ];
+                pView = maViewList[ i ].get();
                 if( !pView->isMarked() )
                 {
-                    delete pView;
                     maViewList.erase( maViewList.begin() + i );
                 }
                 else
@@ -407,7 +390,7 @@ IMPL_LINK_NOARG(Animation, ImplTimeoutHdl, Timer *, void)
             ImplRestartTimer( 10 );
         else
         {
-            AnimationBitmap* pStepBmp = (++mnPos < maList.size()) ? maList[ mnPos ] : nullptr;
+            AnimationBitmap* pStepBmp = (++mnPos < maList.size()) ? maList[ mnPos ].get() : nullptr;
 
             if( !pStepBmp )
             {
@@ -425,7 +408,7 @@ IMPL_LINK_NOARG(Animation, ImplTimeoutHdl, Timer *, void)
                         mnLoops--;
 
                     mnPos = 0;
-                    pStepBmp = maList[ mnPos ];
+                    pStepBmp = maList[ mnPos ].get();
                 }
             }
 
@@ -435,12 +418,11 @@ IMPL_LINK_NOARG(Animation, ImplTimeoutHdl, Timer *, void)
             // set from view itself
             for( size_t i = 0; i < maViewList.size(); )
             {
-                pView = maViewList[ i ];
+                pView = maViewList[ i ].get();
                 pView->draw( mnPos );
 
                 if( pView->isMarked() )
                 {
-                    delete pView;
                     maViewList.erase( maViewList.begin() + i );
                 }
                 else
@@ -468,7 +450,7 @@ bool Animation::Insert( const AnimationBitmap& rStepBmp )
         tools::Rectangle   aGlobalRect( aPoint, maGlobalSize );
 
         maGlobalSize = aGlobalRect.Union( tools::Rectangle( rStepBmp.aPosPix, rStepBmp.aSizePix ) ).GetSize();
-        maList.push_back( new AnimationBitmap( rStepBmp ) );
+        maList.emplace_back( new AnimationBitmap( rStepBmp ) );
 
         // As a start, we make the first BitmapEx the replacement BitmapEx
         if( maList.size() == 1 )
@@ -490,8 +472,7 @@ void Animation::Replace( const AnimationBitmap& rNewAnimationBitmap, sal_uInt16
 {
     SAL_WARN_IF( ( nAnimation >= maList.size() ), "vcl", "No object at this position" );
 
-    delete maList[ nAnimation ];
-    maList[ nAnimation ] = new AnimationBitmap( rNewAnimationBitmap );
+    maList[ nAnimation ].reset( new AnimationBitmap( rNewAnimationBitmap ) );
 
     // If we insert at first position we also need to
     // update the replacement BitmapEx
@@ -599,7 +580,7 @@ bool Animation::Mirror( BmpMirrorFlags nMirrorFlags )
         {
             for( size_t i = 0, n = maList.size(); ( i < n ) && bRet; ++i )
             {
-                AnimationBitmap* pStepBmp = maList[ i ];
+                AnimationBitmap* pStepBmp = maList[ i ].get();
                 bRet = pStepBmp->aBmpEx.Mirror( nMirrorFlags );
                 if( bRet )
                 {
diff --git a/vcl/source/window/menuitemlist.cxx b/vcl/source/window/menuitemlist.cxx
index 95cf7a07875f..0aeb0cb9def7 100644
--- a/vcl/source/window/menuitemlist.cxx
+++ b/vcl/source/window/menuitemlist.cxx
@@ -41,8 +41,6 @@ MenuItemData::~MenuItemData()
 
 MenuItemList::~MenuItemList()
 {
-    for(MenuItemData* i : maItemList)
-        delete i;
 }
 
 MenuItemData* MenuItemList::Insert(
@@ -78,9 +76,9 @@ MenuItemData* MenuItemList::Insert(
     pData->pSalMenuItem = ImplGetSVData()->mpDefInst->CreateMenuItem( &aSalMIData );
 
     if( nPos < maItemList.size() ) {
-        maItemList.insert( maItemList.begin() + nPos, pData );
+        maItemList.insert( maItemList.begin() + nPos, std::unique_ptr<MenuItemData>(pData) );
     } else {
-        maItemList.push_back( pData );
+        maItemList.emplace_back( pData );
     }
     return pData;
 }
@@ -111,9 +109,9 @@ void MenuItemList::InsertSeparator(const OString &rIdent, size_t nPos)
     pData->pSalMenuItem = ImplGetSVData()->mpDefInst->CreateMenuItem( &aSalMIData );
 
     if( nPos < maItemList.size() ) {
-        maItemList.insert( maItemList.begin() + nPos, pData );
+        maItemList.insert( maItemList.begin() + nPos, std::unique_ptr<MenuItemData>(pData) );
     } else {
-        maItemList.push_back( pData );
+        maItemList.emplace_back( pData );
     }
 }
 
@@ -121,16 +119,13 @@ void MenuItemList::Remove( size_t nPos )
 {
     if( nPos < maItemList.size() )
     {
-        delete maItemList[ nPos ];
         maItemList.erase( maItemList.begin() + nPos );
     }
 }
 
 void MenuItemList::Clear()
 {
-    for (MenuItemData* i : maItemList)
-        delete i;
-    maItemList.resize(0);
+    maItemList.clear();
 }
 
 MenuItemData* MenuItemList::GetData( sal_uInt16 nSVId, size_t& rPos ) const
@@ -140,7 +135,7 @@ MenuItemData* MenuItemList::GetData( sal_uInt16 nSVId, size_t& rPos ) const
         if ( maItemList[ i ]->nId == nSVId )
         {
             rPos = i;
-            return maItemList[ i ];
+            return maItemList[ i ].get();
         }
     }
     return nullptr;
@@ -164,7 +159,7 @@ MenuItemData* MenuItemList::SearchItem(
     {
         for ( rPos = 0; rPos < nListCount; rPos++)
         {
-            MenuItemData* pData = maItemList[ rPos ];
+            MenuItemData* pData = maItemList[ rPos ].get();
             if ( pData->bEnabled && rI18nHelper.MatchMnemonic( pData->aText, cSelectChar ) )
             {
                 if( nDuplicates > 1 && rPos == nCurrentPos )
@@ -186,7 +181,7 @@ MenuItemData* MenuItemList::SearchItem(
 
         for ( rPos = 0; rPos < nListCount; rPos++)
         {
-            MenuItemData* pData = maItemList[ rPos ];
+            MenuItemData* pData = maItemList[ rPos ].get();
             if ( pData->bEnabled )
             {
                 sal_Int32 n = pData->aText.indexOf('~');
@@ -226,7 +221,7 @@ size_t MenuItemList::GetItemCount( sal_Unicode cSelectChar ) const
     size_t nItems = 0;
     for ( size_t nPos = maItemList.size(); nPos; )
     {
-        MenuItemData* pData = maItemList[ --nPos ];
+        MenuItemData* pData = maItemList[ --nPos ].get();
         if ( pData->bEnabled && rI18nHelper.MatchMnemonic( pData->aText, cSelectChar ) )
             nItems++;
     }
@@ -246,7 +241,7 @@ size_t MenuItemList::GetItemCount( KeyCode aKeyCode ) const
     size_t nItems = 0;
     for ( size_t nPos = maItemList.size(); nPos; )
     {
-        MenuItemData* pData = maItemList[ --nPos ];
+        MenuItemData* pData = maItemList[ --nPos ].get();
         if ( pData->bEnabled )
         {
             sal_Int32 n = pData->aText.indexOf('~');
diff --git a/vcl/source/window/menuitemlist.hxx b/vcl/source/window/menuitemlist.hxx
index cc344a433bda..bd264e41fdfa 100644
--- a/vcl/source/window/menuitemlist.hxx
+++ b/vcl/source/window/menuitemlist.hxx
@@ -24,6 +24,7 @@
 
 #include <com/sun/star/i18n/XCharacterClassification.hpp>
 
+#include <memory>
 #include <vector>
 
 class SalMenuItem;
@@ -94,7 +95,7 @@ struct MenuItemData
 class MenuItemList
 {
 private:
-    typedef ::std::vector< MenuItemData* > MenuItemDataList_impl;
+    typedef ::std::vector< std::unique_ptr<MenuItemData> > MenuItemDataList_impl;
     MenuItemDataList_impl maItemList;
 
 public:
@@ -122,7 +123,7 @@ public:
                     }
     MenuItemData*   GetDataFromPos( size_t nPos ) const
                     {
-                        return ( nPos < maItemList.size() ) ? maItemList[ nPos ] : nullptr;
+                        return ( nPos < maItemList.size() ) ? maItemList[ nPos ].get() : nullptr;
                     }
 
     MenuItemData*   SearchItem(


More information about the Libreoffice-commits mailing list