From 390e951b78288e082361c386ff5c6618d917c333 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 25 Nov 2016 16:23:17 +0200 Subject: loplugin:vclwidgets check for assigning from VclPt to T* Inspired by a recent bug report where we were assigning the result of VclPtr::Create to a raw pointer. As a consequence, we also need to change various methods that were returning newly created Window subclasses via raw pointer, to instead return those via VclPtr Change-Id: I8118e0195a5b2b4780e646cfb0e151692e54ae2b Reviewed-on: https://gerrit.libreoffice.org/31318 Reviewed-by: Noel Grandin Tested-by: Noel Grandin (cherry picked from commit e6ffb539ee232ea0c679928ff456c1cf97429f63) --- vcl/source/window/accessibility.cxx | 7 +++---- vcl/source/window/builder.cxx | 7 ++----- vcl/source/window/menu.cxx | 4 ++-- vcl/source/window/syswin.cxx | 2 +- vcl/source/window/taskpanelist.cxx | 6 +++--- vcl/source/window/toolbox.cxx | 4 ++-- vcl/source/window/window2.cxx | 3 +-- 7 files changed, 14 insertions(+), 19 deletions(-) (limited to 'vcl/source/window') diff --git a/vcl/source/window/accessibility.cxx b/vcl/source/window/accessibility.cxx index 55c9d3071d36..ab2ac82bee85 100644 --- a/vcl/source/window/accessibility.cxx +++ b/vcl/source/window/accessibility.cxx @@ -605,11 +605,10 @@ vcl::Window* Window::GetAccessibleRelationLabeledBy() const if (!aMnemonicLabels.empty()) { //if we have multiple labels, then prefer the first that is visible - for (auto aI = aMnemonicLabels.begin(), aEnd = aMnemonicLabels.end(); aI != aEnd; ++aI) + for (auto const & rCandidate : aMnemonicLabels) { - vcl::Window *pCandidate = *aI; - if (pCandidate->IsVisible()) - return pCandidate; + if (rCandidate->IsVisible()) + return rCandidate; } return aMnemonicLabels[0]; } diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index a3d626964eaf..32bd8b8e9d29 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -472,11 +472,8 @@ VclBuilder::VclBuilder(vcl::Window *pParent, const OUString& sUIDir, const OUStr } //fdo#67378 merge the label into the disclosure button - for (auto aI = m_pParserState->m_aExpanderWidgets.begin(), - aEnd = m_pParserState->m_aExpanderWidgets.end(); aI != aEnd; ++aI) + for (VclPtr const & pOne : m_pParserState->m_aExpanderWidgets) { - VclExpander *pOne = *aI; - vcl::Window *pChild = pOne->get_child(); vcl::Window* pLabel = pOne->GetWindow(GetWindowType::LastChild); if (pLabel && pLabel != pChild && pLabel->GetType() == WINDOW_FIXEDTEXT) @@ -2111,7 +2108,7 @@ void VclBuilder::handleChild(vcl::Window *pParent, xmlreader::XmlReader &reader) { if (name.equals("object") || name.equals("placeholder")) { - pCurrentChild = handleObject(pParent, reader); + pCurrentChild = handleObject(pParent, reader).get(); bool bObjectInserted = pCurrentChild && pParent != pCurrentChild; diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx index e88914c2d361..ba1e6fd92e3e 100644 --- a/vcl/source/window/menu.cxx +++ b/vcl/source/window/menu.cxx @@ -2478,9 +2478,9 @@ void MenuBar::SetDisplayable( bool bDisplayable ) } } -vcl::Window* MenuBar::ImplCreate(vcl::Window* pParent, vcl::Window* pWindow, MenuBar* pMenu) +VclPtr MenuBar::ImplCreate(vcl::Window* pParent, vcl::Window* pWindow, MenuBar* pMenu) { - MenuBarWindow *pMenuBarWindow = dynamic_cast(pWindow); + VclPtr pMenuBarWindow = dynamic_cast(pWindow); if (!pMenuBarWindow) { pWindow = pMenuBarWindow = VclPtr::Create( pParent ); diff --git a/vcl/source/window/syswin.cxx b/vcl/source/window/syswin.cxx index f31dff20abf4..95c1652be2af 100644 --- a/vcl/source/window/syswin.cxx +++ b/vcl/source/window/syswin.cxx @@ -925,7 +925,7 @@ void SystemWindow::SetMenuBar(MenuBar* pMenuBar) { MenuBar* pOldMenuBar = mpMenuBar; vcl::Window* pOldWindow = nullptr; - vcl::Window* pNewWindow=nullptr; + VclPtr pNewWindow; mpMenuBar = pMenuBar; if ( mpWindowImpl->mpBorderWindow && (mpWindowImpl->mpBorderWindow->GetType() == WINDOW_BORDERWINDOW) ) diff --git a/vcl/source/window/taskpanelist.cxx b/vcl/source/window/taskpanelist.cxx index b5d1738de2d8..0cd840779a5a 100644 --- a/vcl/source/window/taskpanelist.cxx +++ b/vcl/source/window/taskpanelist.cxx @@ -176,7 +176,7 @@ bool TaskPaneList::HandleKeyEvent(const KeyEvent& rKeyEvent) auto p = mTaskPanes.begin(); while( p != mTaskPanes.end() ) { - vcl::Window *pWin = *p; + vcl::Window *pWin = p->get(); if( pWin->HasChildPathFocus( true ) ) { // Ctrl-F6 goes directly to the document @@ -252,7 +252,7 @@ vcl::Window* TaskPaneList::FindNextSplitter( vcl::Window *pWindow ) p = mTaskPanes.begin(); if( (*p)->ImplIsSplitter() && (*p)->IsReallyVisible() && !(*p)->IsDialog() && (*p)->GetParent()->HasChildPathFocus() ) { - pWindow = *p; + pWindow = (*p).get(); break; } if( !pWindow ) // increment after test, otherwise first element is skipped @@ -291,7 +291,7 @@ vcl::Window* TaskPaneList::FindNextFloat( vcl::Window *pWindow, bool bForward ) if( (*p)->IsReallyVisible() && !(*p)->ImplIsSplitter() && ( (*p)->GetType() != WINDOW_MENUBARWINDOW || static_cast(p->get())->CanGetFocus() ) ) { - pWindow = *p; + pWindow = (*p).get(); break; } if( !pWindow ) // increment after test, otherwise first element is skipped diff --git a/vcl/source/window/toolbox.cxx b/vcl/source/window/toolbox.cxx index 14579fafe3dc..a8be10972635 100644 --- a/vcl/source/window/toolbox.cxx +++ b/vcl/source/window/toolbox.cxx @@ -5590,7 +5590,7 @@ void ToolBox::ImplShowFocus() ImplToolItem* pItem = ImplGetItem( mnHighItemId ); if( pItem->mpWindow && !pItem->mpWindow->IsDisposed() ) { - vcl::Window *pWin = pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow ? pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow : pItem->mpWindow; + vcl::Window *pWin = pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow ? pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow.get() : pItem->mpWindow.get(); pWin->ImplGetWindowImpl()->mbDrawSelectionBackground = true; pWin->Invalidate(); } @@ -5604,7 +5604,7 @@ void ToolBox::ImplHideFocus() ImplToolItem* pItem = ImplGetItem( mnHighItemId ); if( pItem && pItem->mpWindow ) { - vcl::Window *pWin = pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow ? pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow : pItem->mpWindow; + vcl::Window *pWin = pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow ? pItem->mpWindow->ImplGetWindowImpl()->mpBorderWindow.get() : pItem->mpWindow.get(); pWin->ImplGetWindowImpl()->mbDrawSelectionBackground = false; pWin->Invalidate(); } diff --git a/vcl/source/window/window2.cxx b/vcl/source/window/window2.cxx index 24d1fa79eae2..095452df7b17 100644 --- a/vcl/source/window/window2.cxx +++ b/vcl/source/window/window2.cxx @@ -1390,9 +1390,8 @@ void Window::queue_resize(StateChangedType eReason) if (pWindowImpl->m_xSizeGroup && pWindowImpl->m_xSizeGroup->get_mode() != VCL_SIZE_GROUP_NONE) { std::set > &rWindows = pWindowImpl->m_xSizeGroup->get_widgets(); - for (auto aI = rWindows.begin(), aEnd = rWindows.end(); aI != aEnd; ++aI) + for (VclPtr const & pOther : rWindows) { - vcl::Window *pOther = *aI; if (pOther == this) continue; queue_ungrouped_resize(pOther); -- cgit