From aa87af58b195af94ea5b9dcb01faf09e01e76e1b Mon Sep 17 00:00:00 2001 From: Philippe Jung Date: Tue, 5 May 2015 12:29:34 +0200 Subject: tdf#91081 Fix LO crash after dialog closing by ESC When control is no longuer valid, skip emission of notification - chaining to the parent When opening a popup dialog by right click and immediately pressing ESC immediately, LO crashes. A focus event listener is still registered. It triggers an event on a component previously freed. Change-Id: Icfc941849be5d50e2477d4e92afff844f76892d8 --- vcl/source/control/ctrl.cxx | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/vcl/source/control/ctrl.cxx b/vcl/source/control/ctrl.cxx index e57c296a991c..9dcdfc0cea38 100644 --- a/vcl/source/control/ctrl.cxx +++ b/vcl/source/control/ctrl.cxx @@ -253,33 +253,36 @@ OUString Control::GetDisplayText() const bool Control::Notify( NotifyEvent& rNEvt ) { - if ( rNEvt.GetType() == MouseNotifyEvent::GETFOCUS ) - { - if ( !mbHasControlFocus ) - { - mbHasControlFocus = true; - StateChanged( StateChangedType::CONTROL_FOCUS ); - if ( ImplCallEventListenersAndHandler( VCLEVENT_CONTROL_GETFOCUS, maGetFocusHdl, this ) ) - // been destroyed within the handler - return true; - } - } - else + // tdf#91081 if control is not valid, skip the emission - chaining to the parent + if (mpControlData) { - if ( rNEvt.GetType() == MouseNotifyEvent::LOSEFOCUS ) + if ( rNEvt.GetType() == MouseNotifyEvent::GETFOCUS ) { - vcl::Window* pFocusWin = Application::GetFocusWindow(); - if ( !pFocusWin || !ImplIsWindowOrChild( pFocusWin ) ) + if ( !mbHasControlFocus ) { - mbHasControlFocus = false; + mbHasControlFocus = true; StateChanged( StateChangedType::CONTROL_FOCUS ); - if ( ImplCallEventListenersAndHandler( VCLEVENT_CONTROL_LOSEFOCUS, maLoseFocusHdl, this ) ) + if ( ImplCallEventListenersAndHandler( VCLEVENT_CONTROL_GETFOCUS, maGetFocusHdl, this ) ) // been destroyed within the handler return true; } } + else + { + if ( rNEvt.GetType() == MouseNotifyEvent::LOSEFOCUS ) + { + vcl::Window* pFocusWin = Application::GetFocusWindow(); + if ( !pFocusWin || !ImplIsWindowOrChild( pFocusWin ) ) + { + mbHasControlFocus = false; + StateChanged( StateChangedType::CONTROL_FOCUS ); + if ( ImplCallEventListenersAndHandler( VCLEVENT_CONTROL_LOSEFOCUS, maLoseFocusHdl, this ) ) + // been destroyed within the handler + return true; + } + } + } } - return Window::Notify( rNEvt ); } -- cgit v1.2.3