diff options
author | Noel Grandin <noel@peralex.com> | 2015-03-18 08:33:14 +0200 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2015-04-10 11:59:25 +0100 |
commit | 0556598b35eb6d81fdaff04520f14202660f0333 (patch) | |
tree | 2fb64309bbd8e519f25b1e55824bad5513754e91 | |
parent | 7aa921cb53eedd0a107fbe9f75365adcce4d37d9 (diff) |
vclwidget: check for calling delete on subclasses of vcl::Window
Change-Id: I7fb7cf919e3f46dd03a18b1cb95fa881915f9642
40 files changed, 118 insertions, 114 deletions
diff --git a/basctl/source/basicide/basidesh.cxx b/basctl/source/basicide/basidesh.cxx index 58938a2cb837..db6136ba742b 100644 --- a/basctl/source/basicide/basidesh.cxx +++ b/basctl/source/basicide/basidesh.cxx @@ -819,7 +819,7 @@ void Shell::RemoveWindow( BaseWindow* pWindow_, bool bDestroy, bool bAllowChange { if ( !( pWindow_->GetStatus() & BASWIN_INRESCHEDULE ) ) { - delete pWindow_; + VclPtr<BaseWindow>(pWindow_).disposeAndClear(); } else { diff --git a/basctl/source/basicide/moduldlg.cxx b/basctl/source/basicide/moduldlg.cxx index 43967f65e0e7..62d5dae9b996 100644 --- a/basctl/source/basicide/moduldlg.cxx +++ b/basctl/source/basicide/moduldlg.cxx @@ -494,7 +494,7 @@ void OrganizeDialog::dispose() if (m_pTabCtrl) { for ( sal_uInt16 i = 0; i < m_pTabCtrl->GetPageCount(); i++ ) - delete m_pTabCtrl->GetTabPage( m_pTabCtrl->GetPageId( i ) ); + VclPtr<vcl::Window>(m_pTabCtrl->GetTabPage( m_pTabCtrl->GetPageId( i ) )).disposeAndClear(); } m_pTabCtrl.clear(); diff --git a/compilerplugins/clang/vclwidgets.cxx b/compilerplugins/clang/vclwidgets.cxx index 13217f93ddf6..8ec329353086 100644 --- a/compilerplugins/clang/vclwidgets.cxx +++ b/compilerplugins/clang/vclwidgets.cxx @@ -230,6 +230,7 @@ bool VCLWidgets::VisitVarDecl(const VarDecl * pVarDecl) { && !startsWith(pVarDecl->getType().getAsString(), "::std::multimap<sal_Int32, OTableWindow *>") && !startsWith(pVarDecl->getType().getAsString(), "::std::multimap<sal_Int32, class OTableWindow *>") && !startsWith(pVarDecl->getType().getAsString(), "::dbp::OMultiInstanceAutoRegistration< ::dbp::OUnoAutoPilot<") + && !startsWith(pVarDecl->getType().getAsString(), "SwSidebarWin_iterator") && containsWindowSubclass(pVarDecl->getType())) { report( @@ -399,6 +400,9 @@ bool VCLWidgets::VisitFunctionDecl( const FunctionDecl* functionDecl ) } } // check dispose method to make sure we are actually disposing all of the VclPtr fields + /* + Now that we are in the debugging phase this is no longer useful, since we have to break this rule on + occassion to make the destruction process work cleanly. if (pMethodDecl && pMethodDecl->isInstance() && pMethodDecl->getBody() && pMethodDecl->param_size()==0 && pMethodDecl->getNameAsString() == "dispose" @@ -458,6 +462,7 @@ bool VCLWidgets::VisitFunctionDecl( const FunctionDecl* functionDecl ) } } } + */ return true; } @@ -466,6 +471,14 @@ bool VCLWidgets::VisitCXXDeleteExpr(const CXXDeleteExpr *pCXXDeleteExpr) if (ignoreLocation(pCXXDeleteExpr)) { return true; } + const CXXRecordDecl *pPointee = pCXXDeleteExpr->getArgument()->getType()->getPointeeCXXRecordDecl(); + if (pPointee && isDerivedFromWindow(pPointee)) { + report( + DiagnosticsEngine::Warning, + "calling delete on instance of vcl::Window subclass, must rather call disposeAndClear()", + pCXXDeleteExpr->getLocStart()) + << pCXXDeleteExpr->getSourceRange(); + } const ImplicitCastExpr* pImplicitCastExpr = dyn_cast<ImplicitCastExpr>(pCXXDeleteExpr->getArgument()); if (!pImplicitCastExpr) { return true; diff --git a/cui/source/dialogs/cuigaldlg.cxx b/cui/source/dialogs/cuigaldlg.cxx index b0640f8d8efb..4b9763be3c85 100644 --- a/cui/source/dialogs/cuigaldlg.cxx +++ b/cui/source/dialogs/cuigaldlg.cxx @@ -253,7 +253,7 @@ IMPL_LINK_NOARG(SearchProgress, CleanUpHdl) EndDialog( RET_OK ); - delete this; + VclPtr<SearchProgress>(this).disposeAndClear(); return 0L; } @@ -431,7 +431,7 @@ IMPL_LINK_NOARG(TakeProgress, CleanUpHdl) GetParent()->LeaveWait(); EndDialog( RET_OK ); - delete this; + VclPtr<TakeProgress>(this).disposeAndClear(); return 0L; } diff --git a/cui/source/dialogs/scriptdlg.cxx b/cui/source/dialogs/scriptdlg.cxx index 9d712d0b23d6..5bf6d6d21e42 100644 --- a/cui/source/dialogs/scriptdlg.cxx +++ b/cui/source/dialogs/scriptdlg.cxx @@ -1498,11 +1498,11 @@ IMPL_LINK( SvxScriptErrorDialog, ShowDialog, OUString*, pMessage ) message = OUString( CUI_RES( RID_SVXSTR_ERROR_TITLE ) ); } - MessageDialog* pBox = new MessageDialog(NULL, message, VCL_MESSAGE_WARNING); + VclPtr<MessageDialog> pBox = new MessageDialog(NULL, message, VCL_MESSAGE_WARNING); pBox->SetText( CUI_RES( RID_SVXSTR_ERROR_TITLE ) ); pBox->Execute(); - delete pBox; + pBox.disposeAndClear(); delete pMessage; return 0; diff --git a/cui/source/options/optjava.cxx b/cui/source/options/optjava.cxx index 7a2334a5b8b9..fe3bd19c6fde 100644 --- a/cui/source/options/optjava.cxx +++ b/cui/source/options/optjava.cxx @@ -437,7 +437,7 @@ IMPL_LINK( SvxJavaOptionsPage, DialogClosedHdl, DialogClosedEvent*, pEvt ) IMPL_LINK_NOARG( SvxJavaOptionsPage, ExpertConfigHdl_Impl ) { - CuiAboutConfigTabPage* m_pExpertConfigDlg = new CuiAboutConfigTabPage(this); + VclPtr<CuiAboutConfigTabPage> m_pExpertConfigDlg = new CuiAboutConfigTabPage(this); m_pExpertConfigDlg->Reset();//initialize and reset function if( RET_OK == m_pExpertConfigDlg->Execute() ) @@ -445,7 +445,7 @@ IMPL_LINK_NOARG( SvxJavaOptionsPage, ExpertConfigHdl_Impl ) m_pExpertConfigDlg->FillItemSet();//save changes if there are any } - delete m_pExpertConfigDlg; + m_pExpertConfigDlg.disposeAndClear(); return 0; } diff --git a/dbaccess/source/ui/misc/WCopyTable.cxx b/dbaccess/source/ui/misc/WCopyTable.cxx index 19db7a2561ad..fdfda8cd7f17 100644 --- a/dbaccess/source/ui/misc/WCopyTable.cxx +++ b/dbaccess/source/ui/misc/WCopyTable.cxx @@ -693,11 +693,11 @@ void OCopyTableWizard::dispose() { for ( ;; ) { - TabPage *pPage = GetPage(0); - if ( pPage == NULL ) + VclPtr<TabPage> pPage = GetPage(0); + if ( pPage == nullptr ) break; RemovePage( pPage ); - delete pPage; + pPage.disposeAndClear(); } if ( m_bDeleteSourceColumns ) diff --git a/dbaccess/source/ui/querydesign/JoinTableView.cxx b/dbaccess/source/ui/querydesign/JoinTableView.cxx index 5a858e9fe394..2125cbd7fa1e 100644 --- a/dbaccess/source/ui/querydesign/JoinTableView.cxx +++ b/dbaccess/source/ui/querydesign/JoinTableView.cxx @@ -265,7 +265,7 @@ bool OJoinTableView::RemoveConnection( OTableConnection* _pConn,bool _bDelete ) Any()); if ( _bDelete ) { - delete _pConn; + VclPtr<OTableConnection>(_pConn).disposeAndClear(); } return true; @@ -326,7 +326,7 @@ void OJoinTableView::AddTabWin(const OUString& _rComposedName, const OUString& r TTableWindowData::value_type pNewTabWinData(createTableWindowData( _rComposedName, rWinName,rWinName )); // insert new window in window list - OTableWindow* pNewTabWin = createWindow( pNewTabWinData ); + VclPtr<OTableWindow> pNewTabWin = createWindow( pNewTabWinData ); if ( pNewTabWin->Init() ) { m_pView->getController().getTableWindowData().push_back( pNewTabWinData); @@ -348,7 +348,7 @@ void OJoinTableView::AddTabWin(const OUString& _rComposedName, const OUString& r else { pNewTabWin->clearListBox(); - delete pNewTabWin; + pNewTabWin.disposeAndClear(); } } @@ -398,7 +398,7 @@ void OJoinTableView::RemoveTabWin( OTableWindow* pTabWin ) m_pLastFocusTabWin = NULL; pTabWin->clearListBox(); - delete pTabWin; + VclPtr<OTableWindow>(pTabWin).disposeAndClear(); } if ( (sal_Int32)m_vTableConnection.size() < (nCount-1) ) // if some connections could be removed diff --git a/dbaccess/source/ui/querydesign/QueryTableView.cxx b/dbaccess/source/ui/querydesign/QueryTableView.cxx index 18d0fd583bb7..66c6e4dc978c 100644 --- a/dbaccess/source/ui/querydesign/QueryTableView.cxx +++ b/dbaccess/source/ui/querydesign/QueryTableView.cxx @@ -259,7 +259,7 @@ void OQueryTableView::ReSync() for(;aIter != rTabWinDataList.rend();++aIter) { OQueryTableWindowData* pData = static_cast<OQueryTableWindowData*>(aIter->get()); - OTableWindow* pTabWin = createWindow(*aIter); + VclPtr<OTableWindow> pTabWin = createWindow(*aIter); // I dont't use ShowTabWin as this adds the window data to the list of documents. // This would be bad as I am getting them from there. @@ -269,7 +269,7 @@ void OQueryTableView::ReSync() // The initialisation has gone wrong, this TabWin is not available, so // I must clean up the data and the document pTabWin->clearListBox(); - delete pTabWin; + pTabWin.disposeAndClear(); arrInvalidTables.push_back(pData->GetAliasName()); rTabWinDataList.erase( ::std::remove(rTabWinDataList.begin(), rTabWinDataList.end(), *aIter), rTabWinDataList.end()); @@ -926,7 +926,7 @@ bool OQueryTableView::ShowTabWin( OQueryTableWindow* pTabWin, OQueryTabWinUndoAc // Initialisation failed // (for example when the Connection to the database is not available at the moment) pTabWin->clearListBox(); - delete pTabWin; + VclPtr<OQueryTableWindow>(pTabWin).disposeAndClear(); } } diff --git a/dbaccess/source/ui/relationdesign/RelationTableView.cxx b/dbaccess/source/ui/relationdesign/RelationTableView.cxx index 75b0c7919147..615a760349de 100644 --- a/dbaccess/source/ui/relationdesign/RelationTableView.cxx +++ b/dbaccess/source/ui/relationdesign/RelationTableView.cxx @@ -106,14 +106,14 @@ void ORelationTableView::ReSync() for(;aIter != rTabWinDataList.rend();++aIter) { TTableWindowData::value_type pData = *aIter; - OTableWindow* pTabWin = createWindow(pData); + VclPtr<OTableWindow> pTabWin = createWindow(pData); if (!pTabWin->Init()) { // initialisation failed, which means this TabWin is not available, therefore, // it should be cleaned up, including its data in the document pTabWin->clearListBox(); - delete pTabWin; + pTabWin.disposeAndClear(); arrInvalidTables.push_back(pData->GetTableName()); rTabWinDataList.erase( ::std::remove(rTabWinDataList.begin(), rTabWinDataList.end(), *aIter), rTabWinDataList.end()); @@ -300,7 +300,7 @@ void ORelationTableView::AddTabWin(const OUString& _rComposedName, const OUStrin pNewTabWinData->ShowAll(false); // link new window into the window list - OTableWindow* pNewTabWin = createWindow( pNewTabWinData ); + VclPtr<OTableWindow> pNewTabWin = createWindow( pNewTabWinData ); if(pNewTabWin->Init()) { m_pView->getController().getTableWindowData().push_back( pNewTabWinData); @@ -320,7 +320,7 @@ void ORelationTableView::AddTabWin(const OUString& _rComposedName, const OUStrin else { pNewTabWin->clearListBox(); - delete pNewTabWin; + pNewTabWin.disposeAndClear(); } } diff --git a/desktop/source/deployment/gui/dp_gui_extensioncmdqueue.cxx b/desktop/source/deployment/gui/dp_gui_extensioncmdqueue.cxx index bff66f63a4c7..efea15426e6d 100644 --- a/desktop/source/deployment/gui/dp_gui_extensioncmdqueue.cxx +++ b/desktop/source/deployment/gui/dp_gui_extensioncmdqueue.cxx @@ -923,7 +923,7 @@ void ExtensionCmdQueue::Thread::_removeExtension( ::rtl::Reference< ProgressCmdE void ExtensionCmdQueue::Thread::_checkForUpdates( const std::vector<uno::Reference<deployment::XPackage > > &vExtensionList ) { - UpdateDialog* pUpdateDialog; + VclPtr<UpdateDialog> pUpdateDialog; std::vector< UpdateData > vData; const SolarMutexGuard guard; @@ -970,7 +970,7 @@ void ExtensionCmdQueue::Thread::_checkForUpdates( else pUpdateDialog->notifyMenubar( false, false ); // check if there updates to be notified via menu bar icon - delete pUpdateDialog; + pUpdateDialog.disposeAndClear(); } diff --git a/extensions/source/bibliography/bibbeam.cxx b/extensions/source/bibliography/bibbeam.cxx index d26dad0b5931..d823da527e38 100644 --- a/extensions/source/bibliography/bibbeam.cxx +++ b/extensions/source/bibliography/bibbeam.cxx @@ -215,11 +215,9 @@ namespace bib m_xToolBarRef->dispose(); if ( pToolBar ) - { pDatMan->SetToolbar(0); - pToolBar.disposeAndClear(); - } + pToolBar.disposeAndClear(); pGridWin.disposeAndClear(); BibSplitWindow::dispose(); } diff --git a/extensions/source/bibliography/bibcont.cxx b/extensions/source/bibliography/bibcont.cxx index 31547c0131c7..3699f31c68b5 100644 --- a/extensions/source/bibliography/bibcont.cxx +++ b/extensions/source/bibliography/bibcont.cxx @@ -93,9 +93,9 @@ void BibWindowContainer::dispose() { if( pChild ) { - vcl::Window* pDel = GetChild(); + VclPtr<vcl::Window> pDel = GetChild(); pChild = NULL; // prevents GetFocus for child while deleting! - delete pDel; + pDel.disposeAndClear(); } vcl::Window::dispose(); } @@ -142,16 +142,16 @@ void BibBookContainer::dispose() if( pTopWin ) { - vcl::Window* pDel = pTopWin; + VclPtr<vcl::Window> pDel = pTopWin; pTopWin = NULL; // prevents GetFocus for child while deleting! - delete pDel; + pDel.disposeAndClear(); } if( pBottomWin ) { - vcl::Window* pDel = pBottomWin; + VclPtr<vcl::Window> pDel = pBottomWin; pBottomWin = NULL; // prevents GetFocus for child while deleting! - delete pDel; + pDel.disposeAndClear(); } CloseBibModul( pBibMod ); diff --git a/extensions/source/propctrlr/propertyeditor.cxx b/extensions/source/propctrlr/propertyeditor.cxx index d90660110537..3585ba394597 100644 --- a/extensions/source/propctrlr/propertyeditor.cxx +++ b/extensions/source/propctrlr/propertyeditor.cxx @@ -81,12 +81,12 @@ namespace pcr for(long i = nCount-1; i >= 0; --i) { sal_uInt16 nID = m_aTabControl->GetPageId((sal_uInt16)i); - OBrowserPage* pPage = static_cast<OBrowserPage*>(m_aTabControl->GetTabPage(nID)); + VclPtr<OBrowserPage> pPage = static_cast<OBrowserPage*>(m_aTabControl->GetTabPage(nID)); if (pPage) { pPage->EnableInput(false); m_aTabControl->RemovePage(nID); - delete pPage; + pPage.disposeAndClear(); } } m_aTabControl->Clear(); @@ -243,13 +243,12 @@ namespace pcr void OPropertyEditor::RemovePage(sal_uInt16 nID) { - OBrowserPage* pPage = static_cast<OBrowserPage*>(m_aTabControl->GetTabPage(nID)); + VclPtr<OBrowserPage> pPage = static_cast<OBrowserPage*>(m_aTabControl->GetTabPage(nID)); if (pPage) pPage->EnableInput(false); m_aTabControl->RemovePage(nID); - if (pPage) - delete pPage; + pPage.disposeAndClear(); } diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx index cdf2a9dd9a21..17410c2b23aa 100644 --- a/include/vcl/builder.hxx +++ b/include/vcl/builder.hxx @@ -76,7 +76,7 @@ public: short get_response(const vcl::Window *pWindow) const; OString get_by_window(const vcl::Window *pWindow) const; - void delete_by_window(const vcl::Window *pWindow); + void delete_by_window(vcl::Window *pWindow); //release ownership of pWindow, i.e. don't delete it void drop_ownership(const vcl::Window *pWindow); diff --git a/sc/source/ui/miscdlgs/retypepassdlg.cxx b/sc/source/ui/miscdlgs/retypepassdlg.cxx index 84d58ff87dbe..9cc17b7cb0ab 100644 --- a/sc/source/ui/miscdlgs/retypepassdlg.cxx +++ b/sc/source/ui/miscdlgs/retypepassdlg.cxx @@ -71,15 +71,15 @@ void ScRetypePassDlg::DeleteSheets() { for(auto it = maSheets.begin(); it != maSheets.end(); ++it) { - vcl::Window *pWindow = (*it); + VclPtr<vcl::Window> pWindow = (*it); vcl::Window *pChild = pWindow->GetWindow(WINDOW_FIRSTCHILD); while (pChild) { - vcl::Window *pOldChild = pChild; + VclPtr<vcl::Window> pOldChild = pChild; pChild = pChild->GetWindow(WINDOW_NEXT); - delete pOldChild; + pOldChild.disposeAndClear(); } - delete pWindow; + pWindow.disposeAndClear(); } } diff --git a/sfx2/source/appl/sfxhelp.cxx b/sfx2/source/appl/sfxhelp.cxx index 71e9ed519f8f..246248da3ae9 100644 --- a/sfx2/source/appl/sfxhelp.cxx +++ b/sfx2/source/appl/sfxhelp.cxx @@ -402,8 +402,8 @@ SfxHelpWindow_Impl* impl_createHelp(Reference< XFrame2 >& rHelpTask , // create all internal windows and sub frames ... Reference< ::com::sun::star::awt::XWindow > xParentWindow = xHelpTask->getContainerWindow(); - vcl::Window* pParentWindow = VCLUnoHelper::GetWindow( xParentWindow ); - SfxHelpWindow_Impl* pHelpWindow = new SfxHelpWindow_Impl( xHelpTask, pParentWindow, WB_DOCKBORDER ); + vcl::Window* pParentWindow = VCLUnoHelper::GetWindow( xParentWindow ); + VclPtr<SfxHelpWindow_Impl> pHelpWindow = new SfxHelpWindow_Impl( xHelpTask, pParentWindow, WB_DOCKBORDER ); Reference< ::com::sun::star::awt::XWindow > xHelpWindow = VCLUnoHelper::GetInterface( pHelpWindow ); Reference< XFrame > xHelpContent; @@ -429,7 +429,7 @@ SfxHelpWindow_Impl* impl_createHelp(Reference< XFrame2 >& rHelpTask , if (!xHelpContent.is()) { - delete pHelpWindow; + pHelpWindow.disposeAndClear(); return NULL; } diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx index f8fecff1387a..ad20376d39c4 100644 --- a/sfx2/source/control/thumbnailview.cxx +++ b/sfx2/source/control/thumbnailview.cxx @@ -276,7 +276,7 @@ void ThumbnailView::CalculateItemPositions (bool bScrollBarUsed) Size aWinSize = GetOutputSizePixel(); size_t nItemCount = mFilteredItemList.size(); WinBits nStyle = GetStyle(); - ScrollBar* pDelScrBar = NULL; + VclPtr<ScrollBar> pDelScrBar; // consider the scrolling if ( nStyle & WB_VSCROLL ) @@ -441,7 +441,7 @@ void ThumbnailView::CalculateItemPositions (bool bScrollBarUsed) } // delete ScrollBar - delete pDelScrBar; + pDelScrBar.disposeAndClear(); } size_t ThumbnailView::ImplGetItem( const Point& rPos ) const diff --git a/sfx2/source/dialog/infobar.cxx b/sfx2/source/dialog/infobar.cxx index b7b9f73eeac5..88377b3d0a56 100644 --- a/sfx2/source/dialog/infobar.cxx +++ b/sfx2/source/dialog/infobar.cxx @@ -286,6 +286,7 @@ void SfxInfoBarContainerWindow::removeInfoBar(SfxInfoBarWindow* pInfoBar) break; } } + pInfoBar->disposeOnce(); long nY = 0; for (auto it = m_pInfoBars.begin(); it != m_pInfoBars.end(); ++it) diff --git a/sfx2/source/doc/doctemplates.cxx b/sfx2/source/doc/doctemplates.cxx index 84a3a1c1e15b..fa3d548a4aa8 100644 --- a/sfx2/source/doc/doctemplates.cxx +++ b/sfx2/source/doc/doctemplates.cxx @@ -471,7 +471,7 @@ void SfxDocTplService_Impl::init_Impl() aGuard.clear(); SolarMutexClearableGuard aSolarGuard; - WaitWindow_Impl* pWin = new WaitWindow_Impl(); + VclPtr<WaitWindow_Impl> pWin = new WaitWindow_Impl(); aSolarGuard.clear(); ::osl::ClearableMutexGuard anotherGuard( maMutex ); @@ -481,7 +481,7 @@ void SfxDocTplService_Impl::init_Impl() anotherGuard.clear(); SolarMutexGuard aSecondSolarGuard; - delete pWin; + pWin.disposeAndClear(); } else if ( needsUpdate() ) // the UI should be shown only on the first update diff --git a/sfx2/source/toolbox/tbxitem.cxx b/sfx2/source/toolbox/tbxitem.cxx index c849ac7b3c90..09ed6b29ae88 100644 --- a/sfx2/source/toolbox/tbxitem.cxx +++ b/sfx2/source/toolbox/tbxitem.cxx @@ -1384,7 +1384,7 @@ void SfxPopupWindow::Delete() { if ( m_aDeleteLink.IsSet() ) m_aDeleteLink.Call( this ); - delete this; + VclPtr<SfxPopupWindow>(this).disposeAndClear(); } diff --git a/sfx2/source/view/viewprn.cxx b/sfx2/source/view/viewprn.cxx index 4b6e56dabd43..739ce7d135a4 100644 --- a/sfx2/source/view/viewprn.cxx +++ b/sfx2/source/view/viewprn.cxx @@ -820,7 +820,7 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq ) nDialogRet = 0; // execute PrinterSetupDialog - PrinterSetupDialog* pPrintSetupDlg = new PrinterSetupDialog( GetWindow() ); + VclPtr<PrinterSetupDialog> pPrintSetupDlg = new PrinterSetupDialog( GetWindow() ); SfxDialogExecutor_Impl* pExecutor = 0; if (pImp->m_bHasPrintOptions && HasPrintOptionsPage()) @@ -847,7 +847,7 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq ) } } - DELETEZ( pPrintSetupDlg ); + pPrintSetupDlg.disposeAndClear(); delete pExecutor; // no recording of PrinterSetup except printer name (is printer dependent) diff --git a/starmath/source/dialog.cxx b/starmath/source/dialog.cxx index 0bb93b4a2d52..bf77a54c5f13 100644 --- a/starmath/source/dialog.cxx +++ b/starmath/source/dialog.cxx @@ -547,7 +547,7 @@ IMPL_LINK( SmFontTypeDialog, MenuSelectHdl, Menu *, pMenu ) if (pActiveListBox) { - std::unique_ptr<SmFontDialog> pFontDialog(new SmFontDialog(this, pFontListDev, bHideCheckboxes)); + ScopedVclPtrInstance<SmFontDialog> pFontDialog(this, pFontListDev, bHideCheckboxes); pActiveListBox->WriteTo(*pFontDialog); if (pFontDialog->Execute() == RET_OK) @@ -1504,7 +1504,7 @@ IMPL_LINK_NOARG( SmSymbolDialog, SymbolChangeHdl ) IMPL_LINK_NOARG(SmSymbolDialog, EditClickHdl) { - std::unique_ptr<SmSymDefineDialog> pDialog(new SmSymDefineDialog(this, pFontListDev, rSymbolMgr)); + ScopedVclPtrInstance<SmSymDefineDialog> pDialog(this, pFontListDev, rSymbolMgr); // set current symbol and SymbolSet for the new dialog const OUString aSymSetName (m_pSymbolSets->GetSelectEntry()), diff --git a/svtools/source/contnr/fileview.cxx b/svtools/source/contnr/fileview.cxx index ef2e2daf93a4..41f5212d4573 100644 --- a/svtools/source/contnr/fileview.cxx +++ b/svtools/source/contnr/fileview.cxx @@ -1589,11 +1589,7 @@ SvtFileView_Impl::SvtFileView_Impl( SvtFileView* pAntiImpl, Reference < XCommand SvtFileView_Impl::~SvtFileView_Impl() { Clear(); - - // use temp pointer to prevent access of deleted member (GetFocus()) - ViewTabListBox_Impl* pTemp = mpView; - mpView = NULL; - delete pTemp; + mpView.disposeAndClear(); } diff --git a/svtools/source/dialogs/wizardmachine.cxx b/svtools/source/dialogs/wizardmachine.cxx index 47e81789afaf..98094429a9bb 100644 --- a/svtools/source/dialogs/wizardmachine.cxx +++ b/svtools/source/dialogs/wizardmachine.cxx @@ -214,7 +214,7 @@ namespace svt m_pHelp.disposeAndClear(); for (WizardState i=0; i<m_pImpl->nFirstUnknownPage; ++i) - delete GetPage(i); + VclPtr<vcl::Window>(GetPage(i)).disposeAndClear(); delete m_pImpl; WizardDialog::dispose(); diff --git a/svtools/source/uno/popupwindowcontroller.cxx b/svtools/source/uno/popupwindowcontroller.cxx index d308d53d693a..7bcd32bc8d21 100644 --- a/svtools/source/uno/popupwindowcontroller.cxx +++ b/svtools/source/uno/popupwindowcontroller.cxx @@ -126,7 +126,7 @@ IMPL_LINK( PopupWindowControllerImpl, WindowEventListener, VclSimpleEvent*, pEve IMPL_STATIC_LINK( PopupWindowControllerImpl, AsyncDeleteWindowHdl, vcl::Window*, pWindow ) { (void)*pThis; - delete pWindow; + VclPtr<vcl::Window>(pWindow).disposeAndClear(); return 0; } diff --git a/svx/source/form/datanavi.cxx b/svx/source/form/datanavi.cxx index a24f04d15b0c..a6f13b81e4b5 100644 --- a/svx/source/form/datanavi.cxx +++ b/svx/source/form/datanavi.cxx @@ -1698,7 +1698,7 @@ namespace svxform else if (sIdent == "instancesremove") { sal_uInt16 nId = 0; - XFormsPage* pPage = GetCurrentPage( nId ); + VclPtr<XFormsPage> pPage = GetCurrentPage( nId ); if ( pPage ) { OUString sInstName = pPage->GetInstanceName(); @@ -1718,7 +1718,7 @@ namespace svxform if ( aFoundPage != aPageListEnd ) { m_aPageList.erase( aFoundPage ); - delete pPage; + pPage.disposeAndClear() ; bDoRemove = true; } } @@ -2010,10 +2010,10 @@ namespace svxform sal_Int32 i, nCount = m_aPageList.size(); for ( i = 0; i < nCount; ++i ) { - XFormsPage* pPage = m_aPageList[i]; + VclPtr<XFormsPage> pPage = m_aPageList[i]; pPage->ClearModel(); if ( bClearPages ) - delete pPage; + pPage.disposeAndClear(); } if ( bClearPages ) diff --git a/sw/source/ui/dbui/mmoutputtypepage.cxx b/sw/source/ui/dbui/mmoutputtypepage.cxx index 000d619a7f14..f486d75ae03b 100644 --- a/sw/source/ui/dbui/mmoutputtypepage.cxx +++ b/sw/source/ui/dbui/mmoutputtypepage.cxx @@ -411,7 +411,8 @@ IMPL_STATIC_LINK( SwSendMailDialog, RemoveThis, Timer*, pTimer ) (!pThis->m_pImpl->xMailDispatcher.is() || !pThis->m_pImpl->xMailDispatcher->isRunning())) { - delete pThis; + VclPtr<vcl::Window> a(pThis); + a.disposeAndClear(); } else { diff --git a/sw/source/ui/index/cnttab.cxx b/sw/source/ui/index/cnttab.cxx index 456a151ea3c8..073fc004ff7f 100644 --- a/sw/source/ui/index/cnttab.cxx +++ b/sw/source/ui/index/cnttab.cxx @@ -1625,13 +1625,8 @@ public: m_pParent(pTokenWin) { } -<<<<<<< HEAD - virtual ~SwTOXButton() { dispose(); } - virtual void dispose() SAL_OVERRIDE { m_pParent.clear(); PushButton::dispose(); } -======= virtual ~SwTOXButton() { disposeOnce(); } - virtual void dispose() SAL_OVERRIDE { m_pParent.disposeAndClear(); PushButton::dispose(); } ->>>>>>> 82c89a6... vclwidget: only call dispose() once + virtual void dispose() SAL_OVERRIDE { m_pParent.clear(); PushButton::dispose(); } virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE; virtual void RequestHelp( const HelpEvent& rHEvt ) SAL_OVERRIDE; @@ -2772,9 +2767,10 @@ void SwTokenWindow::dispose() { for (ctrl_iterator it = aControlList.begin(); it != aControlList.end(); ++it) { - it->SetGetFocusHdl( Link() ); - it->SetLoseFocusHdl( Link() ); - it->disposeAndClear(); + VclPtr<Control> pControl = (*it); + pControl->SetGetFocusHdl( Link() ); + pControl->SetLoseFocusHdl( Link() ); + pControl.disposeAndClear(); } aControlList.clear(); disposeBuilder(); @@ -3192,15 +3188,15 @@ void SwTokenWindow::RemoveControl(SwTOXButton* pDel, bool bInternalCall ) ctrl_iterator itLeft = it, itRight = it; --itLeft; ++itRight; - Control *pLeftEdit = *itLeft; - Control *pRightEdit = *itRight; + VclPtr<Control> pLeftEdit = *itLeft; + VclPtr<Control> pRightEdit = *itRight; - static_cast<SwTOXEdit*>(pLeftEdit)->SetText(static_cast<SwTOXEdit*>(pLeftEdit)->GetText() + - static_cast<SwTOXEdit*>(pRightEdit)->GetText()); - static_cast<SwTOXEdit*>(pLeftEdit)->AdjustSize(); + static_cast<SwTOXEdit*>(pLeftEdit.get())->SetText(static_cast<SwTOXEdit*>(pLeftEdit.get())->GetText() + + static_cast<SwTOXEdit*>(pRightEdit.get())->GetText()); + static_cast<SwTOXEdit*>(pLeftEdit.get())->AdjustSize(); aControlList.erase(itRight); - delete pRightEdit; + pRightEdit.disposeAndClear(); aControlList.erase(it); pActiveCtrl->Hide(); diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx index 45230c1d9e74..f8ef22bede9a 100644 --- a/sw/source/uibase/dbui/dbmgr.cxx +++ b/sw/source/uibase/dbui/dbmgr.cxx @@ -943,7 +943,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, bool bPageStylesWithHeaderFooter = false; vcl::Window *pSourceWindow = 0; - CancelableDialog *pProgressDlg = 0; + VclPtr<CancelableModelessDialog> pProgressDlg; if (!IsMergeSilent()) { pSourceWindow = &pSourceShell->GetView().GetEditWin(); @@ -953,7 +953,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, pProgressDlg = new CreateMonitor( pParent, pParent != pSourceWindow ); else { pProgressDlg = new PrintMonitor( pParent, pParent != pSourceWindow, PrintMonitor::MONITOR_TYPE_PRINT ); - static_cast<PrintMonitor*>( pProgressDlg )->SetText(pSourceShell->GetView().GetDocShell()->GetTitle(22)); + static_cast<PrintMonitor*>( pProgressDlg.get() )->SetText(pSourceShell->GetView().GetDocShell()->GetTitle(22)); } pProgressDlg->SetCancelHdl( LINK(this, SwDBManager, PrtCancelHdl) ); pProgressDlg->Show(); @@ -1028,7 +1028,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, int targetDocPageCount = 0; if( !IsMergeSilent() && bMergeShell && lcl_getCountFromResultSet( nDocCount, pImpl->pMergeData->xResultSet ) ) - static_cast<CreateMonitor*>( pProgressDlg )->SetTotalCount( nDocCount ); + static_cast<CreateMonitor*>( pProgressDlg.get() )->SetTotalCount( nDocCount ); long nStartRow, nEndRow; bool bFreezedLayouts = false; @@ -1092,9 +1092,9 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, aTempFileURL.reset( new INetURLObject(aTempFile->GetURL())); if (!IsMergeSilent()) { if( bMergeShell ) - static_cast<CreateMonitor*>( pProgressDlg )->SetCurrentPosition( nDocNo ); + static_cast<CreateMonitor*>( pProgressDlg.get() )->SetCurrentPosition( nDocNo ); else { - PrintMonitor *pPrintMonDlg = static_cast<PrintMonitor*>( pProgressDlg ); + PrintMonitor *pPrintMonDlg = static_cast<PrintMonitor*>( pProgressDlg.get() ); pPrintMonDlg->m_pPrinter->SetText( createTempFile ? aTempFileURL->GetBase() : OUString( pSourceDocSh->GetTitle( 22 ))); OUString sStat(SW_RES(STR_STATSTR_LETTER)); // Brief sStat += " "; @@ -1409,7 +1409,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::mem_fun(&SwRootFrm::AllCheckPageDescs)); } - DELETEZ( pProgressDlg ); + pProgressDlg.disposeAndClear(); // save the single output document if (bMergeShell) diff --git a/sw/source/uibase/utlui/navipi.cxx b/sw/source/uibase/utlui/navipi.cxx index 1032b7f6860e..f5161a7871d7 100644 --- a/sw/source/uibase/utlui/navipi.cxx +++ b/sw/source/uibase/utlui/navipi.cxx @@ -859,7 +859,8 @@ void SwNavigationPI::dispose() SfxImageManager* pImgMan = SfxImageManager::GetImageManager(*SW_MOD()); pImgMan->ReleaseToolBox(aContentToolBox.get()); pImgMan->ReleaseToolBox(aGlobalToolBox.get()); - delete aContentToolBox->GetItemWindow(FN_PAGENUMBER); + VclPtr<vcl::Window> a(aContentToolBox->GetItemWindow(FN_PAGENUMBER)); + a.disposeAndClear(); aContentToolBox->Clear(); if(pxObjectShell) { diff --git a/vcl/source/app/help.cxx b/vcl/source/app/help.cxx index 50151aca4865..c13acfa7e113 100644 --- a/vcl/source/app/help.cxx +++ b/vcl/source/app/help.cxx @@ -229,12 +229,12 @@ void Help::UpdateTip( sal_uIntPtr nId, vcl::Window* pParent, const Rectangle& rS void Help::HideTip( sal_uLong nId ) { - HelpTextWindow* pHelpWin = reinterpret_cast<HelpTextWindow*>(nId); + VclPtr<HelpTextWindow> pHelpWin = reinterpret_cast<HelpTextWindow*>(nId); vcl::Window* pFrameWindow = pHelpWin->ImplGetFrameWindow(); pHelpWin->Hide(); // trigger update, so that a Paint is instantly triggered since we do not save the background pFrameWindow->ImplUpdateAll(); - delete pHelpWin; + pHelpWin.disposeAndClear(); ImplGetSVData()->maHelpData.mnLastHelpHideTime = tools::Time::GetSystemTicks(); } @@ -550,7 +550,7 @@ void ImplShowHelpWindow( vcl::Window* pParent, sal_uInt16 nHelpWinStyle, sal_uIn void ImplDestroyHelpWindow( bool bUpdateHideTime ) { ImplSVData* pSVData = ImplGetSVData(); - HelpTextWindow* pHelpWin = pSVData->maHelpData.mpHelpWin; + VclPtr<HelpTextWindow> pHelpWin = pSVData->maHelpData.mpHelpWin; if ( pHelpWin ) { vcl::Window * pWindow = pHelpWin->GetParent()->ImplGetFrameWindow(); @@ -561,7 +561,7 @@ void ImplDestroyHelpWindow( bool bUpdateHideTime ) pSVData->maHelpData.mpHelpWin = NULL; pSVData->maHelpData.mbKeyboardHelp = false; pHelpWin->Hide(); - delete pHelpWin; + pHelpWin.disposeAndClear(); if( bUpdateHideTime ) pSVData->maHelpData.mnLastHelpHideTime = tools::Time::GetSystemTicks(); } diff --git a/vcl/source/outdev/map.cxx b/vcl/source/outdev/map.cxx index b359e504d0a9..a1aa6c128a9d 100644 --- a/vcl/source/outdev/map.cxx +++ b/vcl/source/outdev/map.cxx @@ -232,9 +232,9 @@ static void ImplCalcMapResolution( const MapMode& rMapMode, vcl::Window::ImplInitAppFontData( pSVData->maWinData.mpFirstFrame ); else { - WorkWindow* pWin = new WorkWindow( NULL, 0 ); + VclPtr<WorkWindow> pWin = new WorkWindow( NULL, 0 ); vcl::Window::ImplInitAppFontData( pWin ); - delete pWin; + pWin.disposeAndClear(); } } rMapRes.mnMapScNumX = pSVData->maGDIData.mnAppFontX; diff --git a/vcl/source/uipreviewer/previewer.cxx b/vcl/source/uipreviewer/previewer.cxx index e889e78f8644..20074297e5a5 100644 --- a/vcl/source/uipreviewer/previewer.cxx +++ b/vcl/source/uipreviewer/previewer.cxx @@ -68,7 +68,7 @@ int UIPreviewApp::Main() try { - Dialog *pDialog = new Dialog(DIALOG_NO_PARENT, WB_STDDIALOG | WB_SIZEABLE); + VclPtr<Dialog> pDialog = new Dialog(DIALOG_NO_PARENT, WB_STDDIALOG | WB_SIZEABLE); { VclBuilder aBuilder(pDialog, OUString(), uifiles[0]); @@ -90,7 +90,7 @@ int UIPreviewApp::Main() pRealDialog->Execute(); } - delete pDialog; + pDialog.disposeAndClear(); } catch (const uno::Exception &e) { diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 275e075a8bd6..92595d061c33 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -3292,10 +3292,10 @@ void VclBuilder::delete_by_name(const OString& sID) } } -void VclBuilder::delete_by_window(const vcl::Window *pWindow) +void VclBuilder::delete_by_window(vcl::Window *pWindow) { drop_ownership(pWindow); - delete pWindow; + VclPtr<vcl::Window>(pWindow).disposeAndClear(); } void VclBuilder::drop_ownership(const vcl::Window *pWindow) diff --git a/vcl/source/window/dockmgr.cxx b/vcl/source/window/dockmgr.cxx index 2010fd9e0e9f..c5726af5bd40 100644 --- a/vcl/source/window/dockmgr.cxx +++ b/vcl/source/window/dockmgr.cxx @@ -856,14 +856,14 @@ bool ImplDockingWindowWrapper::ImplStartDocking( const Point& rPos ) mbStartFloat = mbLastFloatMode; // calculate FloatingBorder - FloatingWindow* pWin; + VclPtr<FloatingWindow> pWin; if ( mpFloatWin ) pWin = mpFloatWin; else pWin = new ImplDockFloatWin2( mpParent, mnFloatBits, NULL ); pWin->GetBorder( mnDockLeft, mnDockTop, mnDockRight, mnDockBottom ); if ( !mpFloatWin ) - delete pWin; + pWin.disposeAndClear(); Point aPos = GetWindow()->ImplOutputToFrame( Point() ); Size aSize = GetWindow()->GetOutputSizePixel(); @@ -1299,8 +1299,7 @@ void ImplDockingWindowWrapper::SetFloatingMode( bool bFloatMode ) GetWindow()->SetParent( pRealParent ); GetWindow()->mpWindowImpl->mpRealParent = pRealParent; - delete static_cast<ImplDockFloatWin2*>(mpFloatWin.get()); - mpFloatWin = NULL; + mpFloatWin.disposeAndClear(); GetWindow()->SetPosPixel( maDockPos ); if ( bVisible ) diff --git a/vcl/source/window/dockwin.cxx b/vcl/source/window/dockwin.cxx index 6ceafc25b9c8..6cc6301730b2 100644 --- a/vcl/source/window/dockwin.cxx +++ b/vcl/source/window/dockwin.cxx @@ -264,14 +264,14 @@ bool DockingWindow::ImplStartDocking( const Point& rPos ) mbStartFloat = mbLastFloatMode; // calculate FloatingBorder - FloatingWindow* pWin; + VclPtr<FloatingWindow> pWin; if ( mpFloatWin ) pWin = mpFloatWin; else pWin = new ImplDockFloatWin( mpImplData->mpParent, mnFloatBits, NULL ); pWin->GetBorder( mnDockLeft, mnDockTop, mnDockRight, mnDockBottom ); if ( !mpFloatWin ) - delete pWin; + pWin.disposeAndClear(); Point aPos = ImplOutputToFrame( Point() ); Size aSize = Window::GetOutputSizePixel(); diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index 61ed19362682..2af94700afce 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -2097,7 +2097,7 @@ void Window::SetBorderStyle( WindowBorderStyle nBorderStyle ) // this is a little awkward: some controls (e.g. svtools ProgressBar) // cannot avoid getting constructed with WB_BORDER but want to disable // borders in case of NWF drawing. So they need a method to remove their border window - vcl::Window* pBorderWin = mpWindowImpl->mpBorderWindow; + VclPtr<vcl::Window> pBorderWin = mpWindowImpl->mpBorderWindow; // remove us as border window's client pBorderWin->mpWindowImpl->mpClientWindow = NULL; mpWindowImpl->mpBorderWindow = NULL; @@ -2109,7 +2109,7 @@ void Window::SetBorderStyle( WindowBorderStyle nBorderStyle ) Size aBorderSize( pBorderWin->GetSizePixel() ); setPosSizePixel( aBorderPos.X(), aBorderPos.Y(), aBorderSize.Width(), aBorderSize.Height() ); // release border window - delete pBorderWin; + pBorderWin.disposeAndClear(); // set new style bits SetStyle( GetStyle() & (~WB_BORDER) ); diff --git a/xmlsecurity/source/dialogs/certificateviewer.cxx b/xmlsecurity/source/dialogs/certificateviewer.cxx index 5ca843572da7..7a28f7bd52d3 100644 --- a/xmlsecurity/source/dialogs/certificateviewer.cxx +++ b/xmlsecurity/source/dialogs/certificateviewer.cxx @@ -66,9 +66,9 @@ CertificateViewer::~CertificateViewer() void CertificateViewer::dispose() { - delete mpTabCtrl->GetTabPage(mnGeneralId); - delete mpTabCtrl->GetTabPage(mnDetailsId); - delete mpTabCtrl->GetTabPage(mnPathId); + mpTabCtrl->GetTabPage(mnGeneralId)->disposeOnce(); + mpTabCtrl->GetTabPage(mnDetailsId)->disposeOnce(); + mpTabCtrl->GetTabPage(mnPathId)->disposeOnce(); mpTabCtrl.clear(); TabDialog::dispose(); } diff --git a/xmlsecurity/source/dialogs/macrosecurity.cxx b/xmlsecurity/source/dialogs/macrosecurity.cxx index 8924a49e562c..9bf3ce12a4cb 100644 --- a/xmlsecurity/source/dialogs/macrosecurity.cxx +++ b/xmlsecurity/source/dialogs/macrosecurity.cxx @@ -89,13 +89,13 @@ MacroSecurity::~MacroSecurity() void MacroSecurity::dispose() { - delete m_pTabCtrl->GetTabPage(m_nSecTrustId); - delete m_pTabCtrl->GetTabPage(m_nSecLevelId); + m_pTabCtrl->GetTabPage(m_nSecTrustId)->disposeOnce(); + m_pTabCtrl->GetTabPage(m_nSecLevelId)->disposeOnce(); m_pTabCtrl.clear(); m_pOkBtn.clear(); m_pResetBtn.clear(); - mpLevelTP.clear(); - mpTrustSrcTP.clear(); + mpLevelTP.disposeAndClear(); + mpTrustSrcTP.disposeAndClear(); TabDialog::dispose(); } |