From e6ffb539ee232ea0c679928ff456c1cf97429f63 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 --- toolkit/source/awt/stylesettings.cxx | 10 +++++----- toolkit/source/awt/vclxtoolkit.cxx | 34 +++++++++++++++++----------------- toolkit/source/awt/vclxwindow.cxx | 8 ++++---- toolkit/source/helper/vclunohelper.cxx | 2 +- 4 files changed, 27 insertions(+), 27 deletions(-) (limited to 'toolkit') diff --git a/toolkit/source/awt/stylesettings.cxx b/toolkit/source/awt/stylesettings.cxx index 8410554d2612..86ab25ce80bb 100644 --- a/toolkit/source/awt/stylesettings.cxx +++ b/toolkit/source/awt/stylesettings.cxx @@ -134,7 +134,7 @@ namespace toolkit { sal_Int32 lcl_getStyleColor( WindowStyleSettings_Data& i_rData, Color const & (StyleSettings::*i_pGetter)() const ) { - const vcl::Window* pWindow = i_rData.pOwningWindow->GetWindow(); + const VclPtr& pWindow = i_rData.pOwningWindow->GetWindow(); const AllSettings aAllSettings = pWindow->GetSettings(); const StyleSettings& aStyleSettings = aAllSettings.GetStyleSettings(); return (aStyleSettings.*i_pGetter)().GetColor(); @@ -152,7 +152,7 @@ namespace toolkit FontDescriptor lcl_getStyleFont( WindowStyleSettings_Data& i_rData, vcl::Font const & (StyleSettings::*i_pGetter)() const ) { - const vcl::Window* pWindow = i_rData.pOwningWindow->GetWindow(); + const VclPtr& pWindow = i_rData.pOwningWindow->GetWindow(); const AllSettings aAllSettings = pWindow->GetSettings(); const StyleSettings& aStyleSettings = aAllSettings.GetStyleSettings(); return VCLUnoHelper::CreateFontDescriptor( (aStyleSettings.*i_pGetter)() ); @@ -385,7 +385,7 @@ namespace toolkit ::sal_Int32 SAL_CALL WindowStyleSettings::getFaceGradientColor() throw (RuntimeException, std::exception) { StyleMethodGuard aGuard( *m_pData ); - const vcl::Window* pWindow = m_pData->pOwningWindow->GetWindow(); + const VclPtr& pWindow = m_pData->pOwningWindow->GetWindow(); const AllSettings aAllSettings = pWindow->GetSettings(); const StyleSettings& aStyleSettings = aAllSettings.GetStyleSettings(); return aStyleSettings.GetFaceGradientColor().GetColor(); @@ -675,7 +675,7 @@ namespace toolkit ::sal_Int32 SAL_CALL WindowStyleSettings::getSeparatorColor() throw (RuntimeException, std::exception) { StyleMethodGuard aGuard( *m_pData ); - const vcl::Window* pWindow = m_pData->pOwningWindow->GetWindow(); + const VclPtr& pWindow = m_pData->pOwningWindow->GetWindow(); const AllSettings aAllSettings = pWindow->GetSettings(); const StyleSettings& aStyleSettings = aAllSettings.GetStyleSettings(); return aStyleSettings.GetSeparatorColor().GetColor(); @@ -741,7 +741,7 @@ namespace toolkit sal_Bool SAL_CALL WindowStyleSettings::getHighContrastMode() throw (RuntimeException, std::exception) { StyleMethodGuard aGuard( *m_pData ); - const vcl::Window* pWindow = m_pData->pOwningWindow->GetWindow(); + const VclPtr& pWindow = m_pData->pOwningWindow->GetWindow(); const AllSettings aAllSettings = pWindow->GetSettings(); const StyleSettings& aStyleSettings = aAllSettings.GetStyleSettings(); return aStyleSettings.GetHighContrastMode(); diff --git a/toolkit/source/awt/vclxtoolkit.cxx b/toolkit/source/awt/vclxtoolkit.cxx index 12948c3e8d67..116e77cb68ff 100644 --- a/toolkit/source/awt/vclxtoolkit.cxx +++ b/toolkit/source/awt/vclxtoolkit.cxx @@ -831,7 +831,7 @@ vcl::Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp, OUString aServiceName( rDescriptor.WindowServiceName ); aServiceName = aServiceName.toAsciiLowerCase(); - vcl::Window* pNewWindow = nullptr; + VclPtr pNewWindow; sal_uInt16 nType = ImplGetComponentType( aServiceName ); bool bFrameControl = false; if ( aServiceName == "frame" ) @@ -886,7 +886,7 @@ vcl::Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp, break; case WINDOW_COMBOBOX: pNewWindow = VclPtr::Create( pParent, nWinBits|WB_AUTOHSCROLL ); - static_cast(pNewWindow)->EnableAutoSize( false ); + static_cast(pNewWindow.get())->EnableAutoSize( false ); *ppNewComp = new VCLXComboBox; break; case WINDOW_CURRENCYBOX: @@ -894,18 +894,18 @@ vcl::Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp, break; case WINDOW_CURRENCYFIELD: pNewWindow = VclPtr::Create( pParent, nWinBits ); - static_cast(pNewWindow)->EnableEmptyFieldValue( true ); + static_cast(pNewWindow.get())->EnableEmptyFieldValue( true ); *ppNewComp = new VCLXNumericField; - static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow)) ); + static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow.get())) ); break; case WINDOW_DATEBOX: pNewWindow = VclPtr::Create( pParent, nWinBits ); break; case WINDOW_DATEFIELD: pNewWindow = VclPtr::Create( pParent, nWinBits ); - static_cast(pNewWindow)->EnableEmptyFieldValue( true ); + static_cast(pNewWindow.get())->EnableEmptyFieldValue( true ); *ppNewComp = new VCLXDateField; - static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow)) ); + static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow.get())) ); break; case WINDOW_DOCKINGAREA: pNewWindow = VclPtr::Create( pParent ); @@ -940,7 +940,7 @@ vcl::Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp, pNewWindow = VclPtr::Create( pParent, nWinBits ); if ( bFrameControl ) { - GroupBox* pGroupBox = static_cast< GroupBox* >( pNewWindow ); + GroupBox* pGroupBox = static_cast< GroupBox* >( pNewWindow.get() ); *ppNewComp = new VCLXFrame; // Frame control needs to receive // Mouse events @@ -961,7 +961,7 @@ vcl::Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp, break; case WINDOW_LISTBOX: pNewWindow = VclPtr::Create( pParent, nWinBits|WB_SIMPLEMODE|WB_AUTOHSCROLL ); - static_cast(pNewWindow)->EnableAutoSize( false ); + static_cast(pNewWindow.get())->EnableAutoSize( false ); *ppNewComp = new VCLXListBox; break; case WINDOW_LONGCURRENCYBOX: @@ -970,7 +970,7 @@ vcl::Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp, case WINDOW_LONGCURRENCYFIELD: pNewWindow = VclPtr::Create( pParent, nWinBits ); *ppNewComp = new VCLXCurrencyField; - static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow)) ); + static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow.get())) ); break; case WINDOW_MENUBUTTON: pNewWindow = VclPtr::Create( pParent, nWinBits ); @@ -986,7 +986,7 @@ vcl::Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp, case WINDOW_METRICFIELD: pNewWindow = VclPtr::Create( pParent, nWinBits ); *ppNewComp = new VCLXMetricField; - static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow)) ); + static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow.get())) ); break; case WINDOW_DIALOG: case WINDOW_MODALDIALOG: @@ -1020,9 +1020,9 @@ vcl::Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp, break; case WINDOW_NUMERICFIELD: pNewWindow = VclPtr::Create( pParent, nWinBits ); - static_cast(pNewWindow)->EnableEmptyFieldValue( true ); + static_cast(pNewWindow.get())->EnableEmptyFieldValue( true ); *ppNewComp = new VCLXNumericField; - static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow)) ); + static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow.get())) ); break; case WINDOW_OKBUTTON: pNewWindow = VclPtr::Create( pParent, nWinBits ); @@ -1034,7 +1034,7 @@ vcl::Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp, case WINDOW_PATTERNFIELD: pNewWindow = VclPtr::Create( pParent, nWinBits ); *ppNewComp = new VCLXPatternField; - static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow)) ); + static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow.get())) ); break; case WINDOW_PUSHBUTTON: pNewWindow = VclPtr::Create( pParent, nWinBits ); @@ -1057,7 +1057,7 @@ vcl::Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp, // is not really valid: the controls are grouped after they have been created, but we're still in // the creation process, so the RadioButton::Check relies on invalid grouping information. // 07.08.2001 - #87254# - frank.schoenheit@sun.com - static_cast(pNewWindow)->EnableRadioCheck( false ); + static_cast(pNewWindow.get())->EnableRadioCheck( false ); break; case WINDOW_SCROLLBAR: pNewWindow = VclPtr::Create( pParent, nWinBits ); @@ -1105,9 +1105,9 @@ vcl::Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp, break; case WINDOW_TIMEFIELD: pNewWindow = VclPtr::Create( pParent, nWinBits ); - static_cast(pNewWindow)->EnableEmptyFieldValue( true ); + static_cast(pNewWindow.get())->EnableEmptyFieldValue( true ); *ppNewComp = new VCLXTimeField; - static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow)) ); + static_cast(*ppNewComp)->SetFormatter( static_cast(static_cast(pNewWindow.get())) ); break; case WINDOW_TOOLBOX: pNewWindow = VclPtr::Create( pParent, nWinBits ); @@ -1256,7 +1256,7 @@ css::uno::Reference< css::awt::XWindowPeer > VCLXToolkit::ImplCreateWindow( css::uno::Reference< css::awt::XWindowPeer > xRef; - vcl::Window* pParent = nullptr; + VclPtr pParent; if ( rDescriptor.Parent.is() ) { VCLXWindow* pParentComponent = VCLXWindow::GetImplementation( rDescriptor.Parent ); diff --git a/toolkit/source/awt/vclxwindow.cxx b/toolkit/source/awt/vclxwindow.cxx index f8b90098c78f..e4a449925886 100644 --- a/toolkit/source/awt/vclxwindow.cxx +++ b/toolkit/source/awt/vclxwindow.cxx @@ -2480,10 +2480,10 @@ sal_Bool SAL_CALL VCLXWindow::isInPopupMode( ) throw (css::uno::RuntimeExceptio void SAL_CALL VCLXWindow::setOutputSize( const css::awt::Size& aSize ) throw (css::uno::RuntimeException, std::exception) { SolarMutexGuard aGuard; - vcl::Window *pWindow; + VclPtr pWindow; if( (pWindow = GetWindow()) != nullptr ) { - DockingWindow *pDockingWindow = dynamic_cast< DockingWindow* >(pWindow); + DockingWindow *pDockingWindow = dynamic_cast< DockingWindow* >(pWindow.get()); if( pDockingWindow ) pDockingWindow->SetOutputSizePixel( VCLSize( aSize ) ); else @@ -2494,10 +2494,10 @@ void SAL_CALL VCLXWindow::setOutputSize( const css::awt::Size& aSize ) throw (cs css::awt::Size SAL_CALL VCLXWindow::getOutputSize( ) throw (css::uno::RuntimeException, std::exception) { SolarMutexGuard aGuard; - vcl::Window *pWindow; + VclPtr pWindow; if( (pWindow = GetWindow()) != nullptr ) { - DockingWindow *pDockingWindow = dynamic_cast< DockingWindow* >(pWindow); + DockingWindow *pDockingWindow = dynamic_cast< DockingWindow* >(pWindow.get()); if( pDockingWindow ) return AWTSize( pDockingWindow->GetOutputSizePixel() ); else diff --git a/toolkit/source/helper/vclunohelper.cxx b/toolkit/source/helper/vclunohelper.cxx index e6c8dfcbcdac..a1d977f53c68 100644 --- a/toolkit/source/helper/vclunohelper.cxx +++ b/toolkit/source/helper/vclunohelper.cxx @@ -152,7 +152,7 @@ css::uno::Reference< css::awt::XWindow> VCLUnoHelper::GetInterface( vcl::Window* OutputDevice* VCLUnoHelper::GetOutputDevice( const css::uno::Reference< css::awt::XDevice>& rxDevice ) { - OutputDevice* pOutDev = nullptr; + VclPtr pOutDev; VCLXDevice* pDev = VCLXDevice::GetImplementation( rxDevice ); if ( pDev ) pOutDev = pDev->GetOutputDevice(); -- cgit