diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-08-14 16:20:34 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-08-16 12:09:05 +0200 |
commit | 13c78ceb25151b971e28f64d2ab931016eea7408 (patch) | |
tree | 1269857b73a80fb2336152d9f989feff52a9d7e3 | |
parent | 899fbd617b32771bc8c14effc52a7153465adf5d (diff) |
pass SfxMedium around by std::unique_ptr
Change-Id: Ibde7b68d9248f80d5304991390a80742265f37b3
Reviewed-on: https://gerrit.libreoffice.org/59031
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | include/sfx2/docinsert.hxx | 4 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh4.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/miscdlgs/instbdlg.cxx | 4 | ||||
-rw-r--r-- | sc/source/ui/miscdlgs/linkarea.cxx | 5 | ||||
-rw-r--r-- | sfx2/source/doc/docinsert.cxx | 4 | ||||
-rw-r--r-- | starmath/source/view.cxx | 6 | ||||
-rw-r--r-- | sw/inc/view.hxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/inc/uivwimp.hxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/uiview/uivwimp.cxx | 2 | ||||
-rw-r--r-- | sw/source/uibase/uiview/view2.cxx | 20 |
10 files changed, 25 insertions, 26 deletions
diff --git a/include/sfx2/docinsert.hxx b/include/sfx2/docinsert.hxx index bacf00ec47de..6befefcb31a3 100644 --- a/include/sfx2/docinsert.hxx +++ b/include/sfx2/docinsert.hxx @@ -22,6 +22,7 @@ #include <rtl/ustring.hxx> #include <sfx2/dllapi.h> +#include <sfx2/docfile.hxx> #include <vcl/errcode.hxx> #include <tools/link.hxx> #include <memory> @@ -29,7 +30,6 @@ namespace sfx2 { class FileDialogHelper; } namespace weld { class Window; } -class SfxMedium; class SfxItemSet; enum class FileDialogFlags; @@ -66,7 +66,7 @@ public: ~DocumentInserter(); void StartExecuteModal( const Link<sfx2::FileDialogHelper*,void>& _rDialogClosedLink ); - SfxMedium* CreateMedium(char const* pFallbackHack = nullptr); + std::unique_ptr<SfxMedium> CreateMedium(char const* pFallbackHack = nullptr); SfxMediumList* CreateMediumList(); }; diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx index 3d7b30aec367..155b6794eea6 100644 --- a/sc/source/ui/docshell/docsh4.cxx +++ b/sc/source/ui/docshell/docsh4.cxx @@ -2486,7 +2486,7 @@ IMPL_LINK( ScDocShell, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, void if ( ERRCODE_NONE == _pFileDlg->GetError() ) { sal_uInt16 nSlot = m_pImpl->pRequest->GetSlot(); - SfxMedium* pMed = m_pImpl->pDocInserter->CreateMedium(); + std::unique_ptr<SfxMedium> pMed = m_pImpl->pDocInserter->CreateMedium(); // #i87094# If a .odt was selected pMed is NULL. if (pMed) { diff --git a/sc/source/ui/miscdlgs/instbdlg.cxx b/sc/source/ui/miscdlgs/instbdlg.cxx index 1c27d79e9398..381722983bab 100644 --- a/sc/source/ui/miscdlgs/instbdlg.cxx +++ b/sc/source/ui/miscdlgs/instbdlg.cxx @@ -305,7 +305,7 @@ IMPL_LINK( ScInsertTableDlg, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg { if ( ERRCODE_NONE == _pFileDlg->GetError() ) { - SfxMedium* pMed = pDocInserter->CreateMedium(); + std::unique_ptr<SfxMedium> pMed = pDocInserter->CreateMedium(); if ( pMed ) { // ERRCTX_SFX_OPENDOC -> "Error loading document" @@ -321,7 +321,7 @@ IMPL_LINK( ScInsertTableDlg, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg { weld::WaitObject aWait(m_xDialog.get()); - pDocShTables->DoLoad(pMed); + pDocShTables->DoLoad(pMed.release()); } ErrCode nErr = pDocShTables->GetErrorCode(); diff --git a/sc/source/ui/miscdlgs/linkarea.cxx b/sc/source/ui/miscdlgs/linkarea.cxx index 002bf482fd7e..e8eb369d39bc 100644 --- a/sc/source/ui/miscdlgs/linkarea.cxx +++ b/sc/source/ui/miscdlgs/linkarea.cxx @@ -179,7 +179,7 @@ IMPL_LINK( ScLinkedAreaDlg, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, if ( _pFileDlg->GetError() != ERRCODE_NONE ) return; - SfxMedium* pMed = m_xDocInserter->CreateMedium(); + std::unique_ptr<SfxMedium> pMed = m_xDocInserter->CreateMedium(); if ( pMed ) { weld::WaitObject aWait(m_xDialog.get()); @@ -207,7 +207,7 @@ IMPL_LINK( ScLinkedAreaDlg, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, m_pSourceShell = new ScDocShell; aSourceRef = m_pSourceShell; - m_pSourceShell->DoLoad( pMed ); + m_pSourceShell->DoLoad( pMed.get() ); ErrCode nErr = m_pSourceShell->GetErrorCode(); if (nErr) @@ -225,6 +225,7 @@ IMPL_LINK( ScLinkedAreaDlg, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, m_xCbUrl->SetText(EMPTY_OUSTRING); } + pMed.release(); // DoLoad takes ownership } UpdateSourceRanges(); diff --git a/sfx2/source/doc/docinsert.cxx b/sfx2/source/doc/docinsert.cxx index ca63af89aa8a..012cbcc02651 100644 --- a/sfx2/source/doc/docinsert.cxx +++ b/sfx2/source/doc/docinsert.cxx @@ -100,7 +100,7 @@ void DocumentInserter::StartExecuteModal( const Link<sfx2::FileDialogHelper*,voi m_pFileDlg->StartExecuteModal( LINK( this, DocumentInserter, DialogClosedHdl ) ); } -SfxMedium* DocumentInserter::CreateMedium(char const*const pFallbackHack) +std::unique_ptr<SfxMedium> DocumentInserter::CreateMedium(char const*const pFallbackHack) { std::unique_ptr<SfxMedium> pMedium; if (!m_nError && m_pItemSet && !m_pURLList.empty()) @@ -133,7 +133,7 @@ SfxMedium* DocumentInserter::CreateMedium(char const*const pFallbackHack) pMedium.reset(); } - return pMedium.release(); + return pMedium; } SfxMediumList* DocumentInserter::CreateMediumList() diff --git a/starmath/source/view.cxx b/starmath/source/view.cxx index 6270bca09777..f817343dd5e0 100644 --- a/starmath/source/view.cxx +++ b/starmath/source/view.cxx @@ -1953,15 +1953,15 @@ IMPL_LINK( SmViewShell, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, voi if ( ERRCODE_NONE == _pFileDlg->GetError() ) { - SfxMedium* pMedium = mpImpl->pDocInserter->CreateMedium(); + std::unique_ptr<SfxMedium> pMedium = mpImpl->pDocInserter->CreateMedium(); - if ( pMedium != nullptr ) + if ( pMedium ) { if ( pMedium->IsStorage() ) Insert( *pMedium ); else InsertFrom( *pMedium ); - delete pMedium; + pMedium.reset(); SmDocShell* pDoc = GetDoc(); pDoc->UpdateText(); diff --git a/sw/inc/view.hxx b/sw/inc/view.hxx index 7f8b78e674f4..c2543d6e463b 100644 --- a/sw/inc/view.hxx +++ b/sw/inc/view.hxx @@ -583,7 +583,7 @@ public: const OUString& rFilterName, sal_Int16 nVersion = 0 ); void ExecuteInsertDoc( SfxRequest& rRequest, const SfxPoolItem* pItem ); - long InsertMedium( sal_uInt16 nSlotId, SfxMedium* pMedium, sal_Int16 nVersion ); + long InsertMedium( sal_uInt16 nSlotId, std::unique_ptr<SfxMedium> pMedium, sal_Int16 nVersion ); DECL_LINK( DialogClosedHdl, sfx2::FileDialogHelper *, void ); // status methods for clipboard. diff --git a/sw/source/uibase/inc/uivwimp.hxx b/sw/source/uibase/inc/uivwimp.hxx index 67c90d732ea9..44b7b3f5cca5 100644 --- a/sw/source/uibase/inc/uivwimp.hxx +++ b/sw/source/uibase/inc/uivwimp.hxx @@ -159,7 +159,7 @@ public: const Link<sfx2::FileDialogHelper*,void>& rEndDialogHdl, const sal_uInt16 nSlotId ); - SfxMedium* CreateMedium(); + std::unique_ptr<SfxMedium> CreateMedium(); void InitRequest( const SfxRequest& rRequest ); SfxRequest* GetRequest() const { return m_pRequest.get(); } diff --git a/sw/source/uibase/uiview/uivwimp.cxx b/sw/source/uibase/uiview/uivwimp.cxx index f626480715e1..e36cbc5c963d 100644 --- a/sw/source/uibase/uiview/uivwimp.cxx +++ b/sw/source/uibase/uiview/uivwimp.cxx @@ -265,7 +265,7 @@ void SwView_Impl::StartDocumentInserter( m_pDocInserter->StartExecuteModal( rEndDialogHdl ); } -SfxMedium* SwView_Impl::CreateMedium() +std::unique_ptr<SfxMedium> SwView_Impl::CreateMedium() { return m_pDocInserter->CreateMedium(); } diff --git a/sw/source/uibase/uiview/view2.cxx b/sw/source/uibase/uiview/view2.cxx index f1866fc3ee16..06e3e8cc6bf0 100644 --- a/sw/source/uibase/uiview/view2.cxx +++ b/sw/source/uibase/uiview/view2.cxx @@ -2074,7 +2074,7 @@ void SwView::ExecuteInsertDoc( SfxRequest& rRequest, const SfxPoolItem* pItem ) long SwView::InsertDoc( sal_uInt16 nSlotId, const OUString& rFileName, const OUString& rFilterName, sal_Int16 nVersion ) { - SfxMedium* pMed = nullptr; + std::unique_ptr<SfxMedium> pMed; SwDocShell* pDocSh = GetDocShell(); if( !rFileName.isEmpty() ) @@ -2083,17 +2083,17 @@ long SwView::InsertDoc( sal_uInt16 nSlotId, const OUString& rFileName, const OUS std::shared_ptr<const SfxFilter> pFilter = rFact.GetFilterContainer()->GetFilter4FilterName( rFilterName ); if ( !pFilter ) { - pMed = new SfxMedium(rFileName, StreamMode::READ, nullptr, nullptr ); + pMed.reset(new SfxMedium(rFileName, StreamMode::READ, nullptr, nullptr )); SfxFilterMatcher aMatcher( rFact.GetFilterContainer()->GetName() ); pMed->UseInteractionHandler( true ); ErrCode nErr = aMatcher.GuessFilter(*pMed, pFilter, SfxFilterFlags::NONE); if ( nErr ) - DELETEZ(pMed); + pMed.reset(); else pMed->SetFilter( pFilter ); } else - pMed = new SfxMedium(rFileName, StreamMode::READ, pFilter, nullptr); + pMed.reset(new SfxMedium(rFileName, StreamMode::READ, pFilter, nullptr)); } else { @@ -2109,10 +2109,10 @@ long SwView::InsertDoc( sal_uInt16 nSlotId, const OUString& rFileName, const OUS if( !pMed ) return -1; - return InsertMedium( nSlotId, pMed, nVersion ); + return InsertMedium( nSlotId, std::move(pMed), nVersion ); } -long SwView::InsertMedium( sal_uInt16 nSlotId, SfxMedium* pMedium, sal_Int16 nVersion ) +long SwView::InsertMedium( sal_uInt16 nSlotId, std::unique_ptr<SfxMedium> pMedium, sal_Int16 nVersion ) { bool bInsert = false, bCompare = false; long nFound = 0; @@ -2145,11 +2145,10 @@ long SwView::InsertMedium( sal_uInt16 nSlotId, SfxMedium* pMedium, sal_Int16 nVe SfxObjectShellRef aRef( pDocSh ); - ErrCode nError = SfxObjectShell::HandleFilter( pMedium, pDocSh ); + ErrCode nError = SfxObjectShell::HandleFilter( pMedium.get(), pDocSh ); // #i16722# aborted? if(nError != ERRCODE_NONE) { - delete pMedium; return -1; } @@ -2250,7 +2249,6 @@ long SwView::InsertMedium( sal_uInt16 nSlotId, SfxMedium* pMedium, sal_Int16 nVe } } - delete pMedium; return nFound; } @@ -2418,12 +2416,12 @@ IMPL_LINK( SwView, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, void ) if ( ERRCODE_NONE != _pFileDlg->GetError() ) return; - SfxMedium* pMed = m_pViewImpl->CreateMedium(); + std::unique_ptr<SfxMedium> pMed = m_pViewImpl->CreateMedium(); if ( !pMed ) return; const sal_uInt16 nSlot = m_pViewImpl->GetRequest()->GetSlot(); - long nFound = InsertMedium( nSlot, pMed, m_pViewImpl->GetParam() ); + long nFound = InsertMedium( nSlot, std::move(pMed), m_pViewImpl->GetParam() ); if ( SID_INSERTDOC == nSlot ) { |