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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Aug 15 08:24:52 UTC 2018


 include/svx/galtheme.hxx             |    6 +++---
 svx/source/gallery2/galbrws2.cxx     |    4 +---
 svx/source/gallery2/galctrl.cxx      |    9 +++------
 svx/source/gallery2/galexpl.cxx      |    3 +--
 svx/source/gallery2/galtheme.cxx     |   27 ++++++++++-----------------
 svx/source/unogallery/unogalitem.cxx |    6 ++----
 6 files changed, 20 insertions(+), 35 deletions(-)

New commits:
commit f71f16b742faa75fe0cab6b899b99ee42d5ec6c7
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Sat Aug 11 10:22:43 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Aug 15 10:24:28 2018 +0200

    loplugin:useuniqueptr pass SgaObject around by std::unique_ptr
    
    Change-Id: I88ef5de94f83cd8f7a7d2a60b072cc23bd147b27
    Reviewed-on: https://gerrit.libreoffice.org/59009
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/svx/galtheme.hxx b/include/svx/galtheme.hxx
index d967392fa3f6..98bf45876bc0 100644
--- a/include/svx/galtheme.hxx
+++ b/include/svx/galtheme.hxx
@@ -31,6 +31,7 @@
 #include <svtools/transfer.hxx>
 #include <svx/svdmodel.hxx>
 #include <svx/galmisc.hxx>
+#include <memory>
 #include <vector>
 
 class SotStorage;
@@ -90,7 +91,7 @@ private:
     bool                        bAbortActualize;
 
     SAL_DLLPRIVATE void         ImplCreateSvDrawStorage();
-    SgaObject*                  ImplReadSgaObject( GalleryObject const * pEntry );
+    std::unique_ptr<SgaObject>  ImplReadSgaObject( GalleryObject const * pEntry );
     SAL_DLLPRIVATE bool         ImplWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos, GalleryObject* pExistentEntry);
     SAL_DLLPRIVATE void         ImplWrite();
     SAL_DLLPRIVATE const GalleryObject* ImplGetGalleryObject(sal_uInt32 nPos) const
@@ -122,8 +123,7 @@ public:
 
     SAL_DLLPRIVATE sal_uInt32   GetObjectCount() const { return aObjectList.size(); }
 
-    SgaObject*                  AcquireObject(sal_uInt32 nPos);
-    static void                 ReleaseObject(SgaObject* pObj);
+    std::unique_ptr<SgaObject>  AcquireObject(sal_uInt32 nPos);
 
     bool                        InsertObject(const SgaObject& rObj, sal_uInt32 nPos = SAL_MAX_UINT32);
     void                        RemoveObject(sal_uInt32 nPos);
diff --git a/svx/source/gallery2/galbrws2.cxx b/svx/source/gallery2/galbrws2.cxx
index 920057674fd8..342d041d7643 100644
--- a/svx/source/gallery2/galbrws2.cxx
+++ b/svx/source/gallery2/galbrws2.cxx
@@ -1110,7 +1110,7 @@ void GalleryBrowser2::Execute(const OString &rIdent)
         }
         else if (rIdent == "title")
         {
-            SgaObject* pObj = mpCurTheme->AcquireObject( mnCurActionPos );
+            std::unique_ptr<SgaObject> pObj = mpCurTheme->AcquireObject( mnCurActionPos );
 
             if( pObj )
             {
@@ -1131,8 +1131,6 @@ void GalleryBrowser2::Execute(const OString &rIdent)
                         mpCurTheme->InsertObject( *pObj );
                     }
                 }
-
-                GalleryTheme::ReleaseObject( pObj );
             }
         }
         else if (rIdent == "copy")
diff --git a/svx/source/gallery2/galctrl.cxx b/svx/source/gallery2/galctrl.cxx
index aa7a7c807b41..a41d820da345 100644
--- a/svx/source/gallery2/galctrl.cxx
+++ b/svx/source/gallery2/galctrl.cxx
@@ -323,7 +323,7 @@ void GalleryIconView::UserDraw(const UserDrawEvent& rUDEvt)
 
     if (bNeedToCreate)
     {
-        SgaObject* pObj = mpTheme->AcquireObject(nId - 1);
+        std::unique_ptr<SgaObject> pObj = mpTheme->AcquireObject(nId - 1);
 
         if(pObj)
         {
@@ -331,7 +331,6 @@ void GalleryIconView::UserDraw(const UserDrawEvent& rUDEvt)
             aItemTextTitle = GalleryBrowser2::GetItemText(*mpTheme, *pObj, GalleryItemFlags::Title);
 
             mpTheme->SetPreviewBitmapExAndStrings(nId - 1, aBitmapEx, aSize, aItemTextTitle, aItemTextPath);
-            GalleryTheme::ReleaseObject(pObj);
         }
     }
 
@@ -441,12 +440,11 @@ OUString GalleryListView::GetCellText(long _nRow, sal_uInt16 /*nColumnId*/) cons
     OUString sRet;
     if( mpTheme && ( _nRow < static_cast< long >( mpTheme->GetObjectCount() ) ) )
     {
-        SgaObject* pObj = mpTheme->AcquireObject( _nRow );
+        std::unique_ptr<SgaObject> pObj = mpTheme->AcquireObject( _nRow );
 
         if( pObj )
         {
             sRet = GalleryBrowser2::GetItemText( *mpTheme, *pObj, GalleryItemFlags::Title );
-            GalleryTheme::ReleaseObject( pObj );
         }
     }
 
@@ -505,7 +503,7 @@ void GalleryListView::PaintField(vcl::RenderContext& rDev, const tools::Rectangl
 
         if(bNeedToCreate)
         {
-            SgaObject* pObj = mpTheme->AcquireObject(mnCurRow);
+            std::unique_ptr<SgaObject> pObj = mpTheme->AcquireObject(mnCurRow);
 
             if(pObj)
             {
@@ -514,7 +512,6 @@ void GalleryListView::PaintField(vcl::RenderContext& rDev, const tools::Rectangl
                 aItemTextPath = GalleryBrowser2::GetItemText(*mpTheme, *pObj, GalleryItemFlags::Path);
 
                 mpTheme->SetPreviewBitmapExAndStrings(mnCurRow, aBitmapEx, aSize, aItemTextTitle, aItemTextPath);
-                GalleryTheme::ReleaseObject(pObj);
             }
         }
 
diff --git a/svx/source/gallery2/galexpl.cxx b/svx/source/gallery2/galexpl.cxx
index 8379b616ba2f..ce8dea401515 100644
--- a/svx/source/gallery2/galexpl.cxx
+++ b/svx/source/gallery2/galexpl.cxx
@@ -93,12 +93,11 @@ bool GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId, std::vector<
         {
             for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
             {
-                SgaObject*  pObj = pTheme->AcquireObject( i );
+                std::unique_ptr<SgaObject>  pObj = pTheme->AcquireObject( i );
                 if ( pObj )
                 {
                     OUString aTitle( pObj->GetTitle() );
                     rList.push_back( aTitle );
-                    GalleryTheme::ReleaseObject( pObj );
                 }
             }
             pGal->ReleaseTheme( pTheme, aListener );
diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx
index b3d83ca70150..31fac1269a4d 100644
--- a/svx/source/gallery2/galtheme.cxx
+++ b/svx/source/gallery2/galtheme.cxx
@@ -146,9 +146,9 @@ bool GalleryTheme::ImplWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos, Ga
     return bRet;
 }
 
-SgaObject* GalleryTheme::ImplReadSgaObject( GalleryObject const * pEntry )
+std::unique_ptr<SgaObject> GalleryTheme::ImplReadSgaObject( GalleryObject const * pEntry )
 {
-    SgaObject* pSgaObj = nullptr;
+    std::unique_ptr<SgaObject> pSgaObj;
 
     if( pEntry )
     {
@@ -168,11 +168,11 @@ SgaObject* GalleryTheme::ImplReadSgaObject( GalleryObject const * pEntry )
 
                 switch( pEntry->eObjKind )
                 {
-                    case SgaObjKind::Bitmap:    pSgaObj = new SgaObjectBmp(); break;
-                    case SgaObjKind::Animation:   pSgaObj = new SgaObjectAnim(); break;
-                    case SgaObjKind::Inet:   pSgaObj = new SgaObjectINet(); break;
-                    case SgaObjKind::SvDraw: pSgaObj = new SgaObjectSvDraw(); break;
-                    case SgaObjKind::Sound:  pSgaObj = new SgaObjectSound(); break;
+                    case SgaObjKind::Bitmap:    pSgaObj.reset(new SgaObjectBmp()); break;
+                    case SgaObjKind::Animation:   pSgaObj.reset(new SgaObjectAnim()); break;
+                    case SgaObjKind::Inet:   pSgaObj.reset(new SgaObjectINet()); break;
+                    case SgaObjKind::SvDraw: pSgaObj.reset(new SgaObjectSvDraw()); break;
+                    case SgaObjKind::Sound:  pSgaObj.reset(new SgaObjectSound()); break;
 
                     default:
                     break;
@@ -409,7 +409,7 @@ bool GalleryTheme::InsertObject(const SgaObject& rObj, sal_uInt32 nInsertPos)
     return true;
 }
 
-SgaObject* GalleryTheme::AcquireObject(sal_uInt32 nPos)
+std::unique_ptr<SgaObject> GalleryTheme::AcquireObject(sal_uInt32 nPos)
 {
     return ImplReadSgaObject(ImplGetGalleryObject(nPos));
 }
@@ -448,11 +448,6 @@ void GalleryTheme::SetPreviewBitmapExAndStrings(sal_uInt32 nPos, const BitmapEx&
     }
 }
 
-void GalleryTheme::ReleaseObject( SgaObject* pObject )
-{
-    delete pObject;
-}
-
 void GalleryTheme::RemoveObject(sal_uInt32 nPos)
 {
     GalleryObject* pEntry = nullptr;
@@ -752,13 +747,12 @@ GalleryThemeEntry* GalleryTheme::CreateThemeEntry( const INetURLObject& rURL, bo
 
 bool GalleryTheme::GetThumb(sal_uInt32 nPos, BitmapEx& rBmp)
 {
-    SgaObject*  pObj = AcquireObject( nPos );
+    std::unique_ptr<SgaObject> pObj = AcquireObject( nPos );
     bool        bRet = false;
 
     if( pObj )
     {
         rBmp = pObj->GetThumbBmp();
-        ReleaseObject( pObj );
         bRet = true;
     }
 
@@ -816,7 +810,7 @@ bool GalleryTheme::GetGraphic(sal_uInt32 nPos, Graphic& rGraphic)
 
             case SgaObjKind::Sound:
             {
-                SgaObject* pObj = AcquireObject( nPos );
+                std::unique_ptr<SgaObject> pObj = AcquireObject( nPos );
 
                 if( pObj )
                 {
@@ -824,7 +818,6 @@ bool GalleryTheme::GetGraphic(sal_uInt32 nPos, Graphic& rGraphic)
                     //Bitmap aBmp( pObj->GetThumbBmp() );
                     //aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE );
                     //rGraphic = aBmp;
-                    ReleaseObject( pObj );
                     bRet = true;
                 }
             }
diff --git a/svx/source/unogallery/unogalitem.cxx b/svx/source/unogallery/unogalitem.cxx
index 361edc2f9a55..89a2b316c269 100644
--- a/svx/source/unogallery/unogalitem.cxx
+++ b/svx/source/unogallery/unogalitem.cxx
@@ -272,12 +272,11 @@ void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry** ppEnt
 
                 if( pGalTheme )
                 {
-                    SgaObject* pObj = pGalTheme->AcquireObject( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ) );
+                    std::unique_ptr<SgaObject> pObj = pGalTheme->AcquireObject( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ) );
 
                     if( pObj )
                     {
                         *pValue <<= pObj->GetTitle();
-                        ::GalleryTheme::ReleaseObject( pObj );
                     }
                 }
             }
@@ -289,7 +288,7 @@ void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry** ppEnt
 
                 if( pGalTheme )
                 {
-                    SgaObject* pObj = pGalTheme->AcquireObject( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ) );
+                    std::unique_ptr<SgaObject> pObj = pGalTheme->AcquireObject( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ) );
 
                     if( pObj )
                     {
@@ -301,7 +300,6 @@ void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry** ppEnt
                             aThumbnail = pObj->GetThumbMtf();
 
                         *pValue <<= aThumbnail.GetXGraphic();
-                        ::GalleryTheme::ReleaseObject( pObj );
                     }
                 }
             }


More information about the Libreoffice-commits mailing list