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

Noel Grandin noel.grandin at collabora.co.uk
Thu Oct 19 19:21:51 UTC 2017


 sd/inc/drawdoc.hxx                 |   21 +++++++++++++--------
 sd/source/core/drawdoc.cxx         |   28 ++++++++++------------------
 sd/source/core/drawdoc4.cxx        |    8 +++-----
 sd/source/filter/ppt/pptin.cxx     |    4 ++--
 sd/source/ui/docshell/docshel2.cxx |    4 ++--
 sd/source/ui/docshell/docshell.cxx |   11 ++++-------
 sd/source/ui/unoidl/unomodel.cxx   |   16 +++++-----------
 7 files changed, 39 insertions(+), 53 deletions(-)

New commits:
commit d54e58616600330e8eb9ba7d5f4598f3b674d643
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Oct 19 11:33:14 2017 +0200

    use std::unique_ptr in SdDrawDocument
    
    Change-Id: Id02cf2615b7697df589f612d21219200d3fab082
    Reviewed-on: https://gerrit.libreoffice.org/43542
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sd/inc/drawdoc.hxx b/sd/inc/drawdoc.hxx
index fc04e2ce2b30..703c3ef8c467 100644
--- a/sd/inc/drawdoc.hxx
+++ b/sd/inc/drawdoc.hxx
@@ -139,13 +139,17 @@ public:
     SAL_DLLPRIVATE bool getDocReadOnly() const { return bReadOnly; }
 private:
     OUString            msDocAccTitle;
-    SdOutliner*     mpOutliner;          ///< local outliner for outline mode
-    SdOutliner*     mpInternalOutliner;  ///< internal outliner for creation of text objects
+    std::unique_ptr<SdOutliner>
+                        mpOutliner;          ///< local outliner for outline mode
+    std::unique_ptr<SdOutliner>
+                        mpInternalOutliner;  ///< internal outliner for creation of text objects
     Timer*              mpWorkStartupTimer;
     Idle*               mpOnlineSpellingIdle;
     sd::ShapeList*      mpOnlineSpellingList;
-    SvxSearchItem*      mpOnlineSearchItem;
-    std::vector<sd::FrameView*> maFrameViewList;
+    std::unique_ptr<SvxSearchItem>
+                        mpOnlineSearchItem;
+    std::vector<std::unique_ptr<sd::FrameView>>
+                        maFrameViewList;
     SdCustomShowList*   mpCustomShowList;
     ::sd::DrawDocShell* mpDocSh;
     SdTransferable *    mpCreatingTransferable;
@@ -171,7 +175,8 @@ private:
     ::sd::DrawDocShellRef   mxAllocedDocShRef;   // => AllocModel()
     bool                mbAllocDocSh;       // => AllocModel()
     DocumentType        meDocType;
-    CharClass*          mpCharClass;
+    std::unique_ptr<CharClass>
+                        mpCharClass;
 
     ::std::unique_ptr<ImpDrawPageListWatcher> mpDrawPageListWatcher;
     ::std::unique_ptr<ImpMasterPageListWatcher> mpMasterPageListWatcher;
@@ -415,7 +420,7 @@ public:
 
     SAL_DLLPRIVATE sal_uLong           GetLinkCount();
 
-    SAL_DLLPRIVATE std::vector<sd::FrameView*>& GetFrameViewList() { return maFrameViewList; }
+    SAL_DLLPRIVATE std::vector<std::unique_ptr<sd::FrameView>>& GetFrameViewList() { return maFrameViewList; }
     SdCustomShowList* GetCustomShowList(bool bCreate = false);
 
     SAL_DLLPRIVATE void                NbcSetChanged(bool bFlag);
@@ -434,7 +439,7 @@ public:
     SAL_DLLPRIVATE bool                IsNewOrLoadCompleted() const {return mbNewOrLoadCompleted; }
 
     SAL_DLLPRIVATE ::sd::FrameView* GetFrameView(sal_uLong nPos) {
-        return nPos < maFrameViewList.size() ? maFrameViewList[nPos] : nullptr; }
+        return nPos < maFrameViewList.size() ? maFrameViewList[nPos].get() : nullptr; }
 
     /** deprecated*/
     SAL_DLLPRIVATE static SdAnimationInfo* GetAnimationInfo(SdrObject* pObject);
@@ -444,7 +449,7 @@ public:
     SAL_DLLPRIVATE static SdIMapInfo*  GetIMapInfo( SdrObject const * pObject );
     SAL_DLLPRIVATE static IMapObject*  GetHitIMapObject( SdrObject* pObject, const Point& rWinPoint );
 
-    SAL_DLLPRIVATE CharClass*          GetCharClass() const { return mpCharClass; }
+    SAL_DLLPRIVATE CharClass*          GetCharClass() const { return mpCharClass.get(); }
 
     SAL_DLLPRIVATE void                RestoreLayerNames();
 
diff --git a/sd/source/core/drawdoc.cxx b/sd/source/core/drawdoc.cxx
index 54b2474008b9..18a94687b7c9 100644
--- a/sd/source/core/drawdoc.cxx
+++ b/sd/source/core/drawdoc.cxx
@@ -233,7 +233,7 @@ SdDrawDocument::SdDrawDocument(DocumentType eType, SfxObjectShell* pDrDocSh)
 
     LanguageType eRealLanguage = MsLangId::getRealLanguage( meLanguage );
     LanguageTag aLanguageTag( eRealLanguage);
-    mpCharClass = new CharClass( aLanguageTag );
+    mpCharClass.reset(new CharClass( aLanguageTag ));
 
     // If the current application language is a language that uses right-to-left text...
     LanguageType eRealCTLLanguage = Application::GetSettings().GetLanguageTag().getLanguageType();
@@ -373,8 +373,7 @@ SdDrawDocument::~SdDrawDocument()
     }
 
     StopOnlineSpelling();
-    delete mpOnlineSearchItem;
-    mpOnlineSearchItem = nullptr;
+    mpOnlineSearchItem.reset();
 
     CloseBookmarkDoc();
     SetAllocDocSh(false);
@@ -393,9 +392,7 @@ SdDrawDocument::~SdDrawDocument()
         pLinkManager = nullptr;
     }
 
-    std::vector<sd::FrameView*>::iterator pIter;
-    for ( pIter = maFrameViewList.begin(); pIter != maFrameViewList.end(); ++pIter )
-        delete *pIter;
+    maFrameViewList.clear();
 
     if (mpCustomShowList)
     {
@@ -410,14 +407,9 @@ SdDrawDocument::~SdDrawDocument()
         mpCustomShowList = nullptr;
     }
 
-    delete mpOutliner;
-    mpOutliner = nullptr;
-
-    delete mpInternalOutliner;
-    mpInternalOutliner = nullptr;
-
-    delete mpCharClass;
-    mpCharClass = nullptr;
+    mpOutliner.reset();
+    mpInternalOutliner.reset();
+    mpCharClass.reset();
 }
 
 SdrModel* SdDrawDocument::AllocModel() const
@@ -806,7 +798,7 @@ SdOutliner* SdDrawDocument::GetOutliner(bool bCreateOutliner)
 {
     if (!mpOutliner && bCreateOutliner)
     {
-        mpOutliner = new SdOutliner( this, OutlinerMode::TextObject );
+        mpOutliner.reset(new SdOutliner( this, OutlinerMode::TextObject ));
 
         if (mpDocSh)
             mpOutliner->SetRefDevice( SD_MOD()->GetVirtualRefDevice() );
@@ -815,7 +807,7 @@ SdOutliner* SdDrawDocument::GetOutliner(bool bCreateOutliner)
         mpOutliner->SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(GetStyleSheetPool()));
     }
 
-    return mpOutliner;
+    return mpOutliner.get();
 }
 
 // Internal outliner that is used to create text objects. We don't insert any
@@ -824,7 +816,7 @@ SdOutliner* SdDrawDocument::GetInternalOutliner(bool bCreateOutliner)
 {
     if ( !mpInternalOutliner && bCreateOutliner )
     {
-        mpInternalOutliner = new SdOutliner( this, OutlinerMode::TextObject );
+        mpInternalOutliner.reset( new SdOutliner( this, OutlinerMode::TextObject ) );
 
         // This outliner is only used to create special text objects. As no
         // information about portions is saved in this outliner, the update mode
@@ -848,7 +840,7 @@ SdOutliner* SdDrawDocument::GetInternalOutliner(bool bCreateOutliner)
     // b) no wasted memory
     DBG_ASSERT( !mpInternalOutliner || ( ( mpInternalOutliner->GetParagraphCount() == 1 ) && ( mpInternalOutliner->GetText( mpInternalOutliner->GetParagraph( 0 ) ).isEmpty() ) ), "InternalOutliner: not empty!" );
 
-    return mpInternalOutliner;
+    return mpInternalOutliner.get();
 }
 
 // OnlineSpelling on/off
diff --git a/sd/source/core/drawdoc4.cxx b/sd/source/core/drawdoc4.cxx
index e667d7eb8337..20ef3650aff8 100644
--- a/sd/source/core/drawdoc4.cxx
+++ b/sd/source/core/drawdoc4.cxx
@@ -862,8 +862,7 @@ IMPL_LINK_NOARG(SdDrawDocument, OnlineSpellingHdl, Timer *, void)
         // Stop search
         StopOnlineSpelling();
 
-        delete mpOnlineSearchItem;
-        mpOnlineSearchItem = nullptr;
+        mpOnlineSearchItem.reset();
     }
 }
 
@@ -959,8 +958,7 @@ IMPL_LINK(SdDrawDocument, OnlineSpellEventHdl, EditStatus&, rEditStat, void)
 // removed link and replaced with Imp method
 void SdDrawDocument::ImpOnlineSpellCallback(SpellCallbackInfo* pInfo, SdrObject* pObj, SdrOutliner const * pOutl)
 {
-    delete mpOnlineSearchItem;
-    mpOnlineSearchItem = nullptr;
+    mpOnlineSearchItem.reset();
 
     SpellCallbackCommand nCommand = pInfo->nCommand;
 
@@ -976,7 +974,7 @@ void SdDrawDocument::ImpOnlineSpellCallback(SpellCallbackInfo* pInfo, SdrObject*
             pObj->BroadcastObjectChange();
         }
 
-        mpOnlineSearchItem = new SvxSearchItem( SID_SEARCH_ITEM );
+        mpOnlineSearchItem.reset(new SvxSearchItem( SID_SEARCH_ITEM ) );
         mpOnlineSearchItem->SetSearchString(pInfo->aWord);
         StartOnlineSpelling();
     }
diff --git a/sd/source/filter/ppt/pptin.cxx b/sd/source/filter/ppt/pptin.cxx
index 2fb4c47cbfd9..dea57ff7ea75 100644
--- a/sd/source/filter/ppt/pptin.cxx
+++ b/sd/source/filter/ppt/pptin.cxx
@@ -1228,9 +1228,9 @@ bool ImplSdPPTImport::Import()
             ::sd::FrameView* pFrameView = mpDoc->GetFrameView( 0 );
             if ( !pFrameView )
             {
-                std::vector<sd::FrameView*> &rViews = mpDoc->GetFrameViewList();
+                std::vector<std::unique_ptr<sd::FrameView>> &rViews = mpDoc->GetFrameViewList();
                 pFrameView = new ::sd::FrameView( mpDoc );
-                rViews.push_back( pFrameView );
+                rViews.push_back( std::unique_ptr<sd::FrameView>(pFrameView) );
             }
             if ( pFrameView )
             {
diff --git a/sd/source/ui/docshell/docshel2.cxx b/sd/source/ui/docshell/docshel2.cxx
index 770d2e5f2192..4f5d1761aea4 100644
--- a/sd/source/ui/docshell/docshel2.cxx
+++ b/sd/source/ui/docshell/docshel2.cxx
@@ -63,10 +63,10 @@ void DrawDocShell::Draw(OutputDevice* pOut, const JobSetup&, sal_uInt16 nAspect)
 
     SdPage* pSelectedPage = nullptr;
 
-    const std::vector<sd::FrameView*> &rViews = mpDoc->GetFrameViewList();
+    const std::vector<std::unique_ptr<sd::FrameView>> &rViews = mpDoc->GetFrameViewList();
     if( !rViews.empty() )
     {
-        sd::FrameView* pFrameView = rViews[0];
+        sd::FrameView* pFrameView = rViews[0].get();
         if( pFrameView->GetPageKind() == PageKind::Standard )
         {
             sal_uInt16 nSelectedPage = pFrameView->GetSelectedPage();
diff --git a/sd/source/ui/docshell/docshell.cxx b/sd/source/ui/docshell/docshell.cxx
index 737f65b6f5ed..3dc597ba725a 100644
--- a/sd/source/ui/docshell/docshell.cxx
+++ b/sd/source/ui/docshell/docshell.cxx
@@ -51,6 +51,7 @@
 #include <comphelper/lok.hxx>
 #include <svl/cjkoptions.hxx>
 #include <svl/visitem.hxx>
+#include <o3tl/make_unique.hxx>
 
 #include <sfx2/fcontnr.hxx>
 
@@ -350,14 +351,10 @@ void DrawDocShell::GetState(SfxItemSet &rSet)
 void DrawDocShell::InPlaceActivate( bool bActive )
 {
     SfxViewFrame* pSfxViewFrame = SfxViewFrame::GetFirst(this, false);
-    std::vector<FrameView*> &rViews = mpDoc->GetFrameViewList();
+    std::vector<std::unique_ptr<FrameView>> &rViews = mpDoc->GetFrameViewList();
 
     if( !bActive )
     {
-        std::vector<FrameView*>::iterator pIter;
-        for ( pIter = rViews.begin(); pIter != rViews.end(); ++pIter )
-            delete *pIter;
-
         rViews.clear();
 
         while (pSfxViewFrame)
@@ -369,7 +366,7 @@ void DrawDocShell::InPlaceActivate( bool bActive )
             if ( pViewSh && pViewSh->GetFrameView() )
             {
                 pViewSh->WriteFrameViewData();
-                rViews.push_back( new FrameView( mpDoc, pViewSh->GetFrameView() ) );
+                rViews.push_back( o3tl::make_unique<FrameView>( mpDoc, pViewSh->GetFrameView() ) );
             }
 
             pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
@@ -388,7 +385,7 @@ void DrawDocShell::InPlaceActivate( bool bActive )
 
             if ( pViewSh )
             {
-                pViewSh->ReadFrameViewData( rViews[ i ] );
+                pViewSh->ReadFrameViewData( rViews[ i ].get() );
             }
 
             pSfxViewFrame = SfxViewFrame::GetNext(*pSfxViewFrame, this, false);
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index 52ecca7729da..624a4d4eede6 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -619,7 +619,7 @@ uno::Reference < container::XIndexAccess > SAL_CALL SdXImpressDocument::getViewD
 
     if( !xRet.is() )
     {
-        const std::vector<sd::FrameView*> &rList = mpDoc->GetFrameViewList();
+        const std::vector<std::unique_ptr<sd::FrameView>> &rList = mpDoc->GetFrameViewList();
 
         if( !rList.empty() )
         {
@@ -631,7 +631,7 @@ uno::Reference < container::XIndexAccess > SAL_CALL SdXImpressDocument::getViewD
             {
                 for( sal_uInt32 i = 0, n = rList.size(); i < n; i++ )
                 {
-                    ::sd::FrameView* pFrameView = rList[ i ];
+                    ::sd::FrameView* pFrameView = rList[ i ].get();
 
                     uno::Sequence< beans::PropertyValue > aSeq;
                     pFrameView->WriteUserDataSequence( aSeq );
@@ -656,24 +656,18 @@ void SAL_CALL SdXImpressDocument::setViewData( const uno::Reference < container:
     {
         const sal_Int32 nCount = xData->getCount();
 
-        std::vector<sd::FrameView*>::iterator pIter;
-        std::vector<sd::FrameView*> &rViews = mpDoc->GetFrameViewList();
-
-        for ( pIter = rViews.begin(); pIter != rViews.end(); ++pIter )
-            delete *pIter;
+        std::vector<std::unique_ptr<sd::FrameView>> &rViews = mpDoc->GetFrameViewList();
 
         rViews.clear();
 
-        ::sd::FrameView* pFrameView;
         uno::Sequence< beans::PropertyValue > aSeq;
         for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
         {
             if( xData->getByIndex( nIndex ) >>= aSeq )
             {
-                pFrameView = new ::sd::FrameView( mpDoc );
-
+                std::unique_ptr<::sd::FrameView> pFrameView(new ::sd::FrameView( mpDoc ));
                 pFrameView->ReadUserDataSequence( aSeq );
-                rViews.push_back( pFrameView );
+                rViews.push_back( std::move(pFrameView) );
             }
         }
     }


More information about the Libreoffice-commits mailing list