From 085dae419f925b9c17c20034622720bbdff4c3ad Mon Sep 17 00:00:00 2001 From: Kevin Ollivier Date: Fri, 14 Nov 2008 23:02:15 +0000 Subject: [PATCH] Do proper cleanup of event handlers in wxWebKitCtrl and wxMacUnicodeTextCtrl, and unset the window focus when destroying a top level window to ensure that controls do not receive events after the wx portion of the control has been destroyed. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@56767 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/mac/carbon/private/mactext.h | 3 ++- include/wx/mac/carbon/toplevel.h | 2 ++ src/html/htmlctrl/webkit/webkit.mm | 11 ++++++++++- src/mac/carbon/textctrl.cpp | 3 ++- src/mac/carbon/toplevel.cpp | 10 ++++++++++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/include/wx/mac/carbon/private/mactext.h b/include/wx/mac/carbon/private/mactext.h index 90dcd7abe7..9dc3c98d8b 100644 --- a/include/wx/mac/carbon/private/mactext.h +++ b/include/wx/mac/carbon/private/mactext.h @@ -103,10 +103,11 @@ protected : // contains the tag for the content (is different for password and non-password controls) OSType m_valueTag ; + WXEVENTHANDLERREF m_macTextCtrlEventHandler ; public : ControlEditTextSelectionRec m_selection ; }; #endif // TARGET_API_MAC_OSX -#endif // _WX_MAC_PRIVATE_MACTEXT_H_ \ No newline at end of file +#endif // _WX_MAC_PRIVATE_MACTEXT_H_ diff --git a/include/wx/mac/carbon/toplevel.h b/include/wx/mac/carbon/toplevel.h index e6d72de034..5d7af6aeea 100644 --- a/include/wx/mac/carbon/toplevel.h +++ b/include/wx/mac/carbon/toplevel.h @@ -48,6 +48,8 @@ public: const wxString& name = wxFrameNameStr); virtual ~wxTopLevelWindowMac(); + + virtual bool Destroy(); virtual wxPoint GetClientAreaOrigin() const; diff --git a/src/html/htmlctrl/webkit/webkit.mm b/src/html/htmlctrl/webkit/webkit.mm index 5ee049ca23..233b76f18a 100755 --- a/src/html/htmlctrl/webkit/webkit.mm +++ b/src/html/htmlctrl/webkit/webkit.mm @@ -468,7 +468,16 @@ bool wxWebKitCtrl::Create(wxWindow *parent, wxWebKitCtrl::~wxWebKitCtrl() { - + MyFrameLoadMonitor* myFrameLoadMonitor = [m_webView frameLoadDelegate]; + MyPolicyDelegate* myPolicyDelegate = [m_webView policyDelegate]; + [m_webView setFrameLoadDelegate: nil]; + [m_webView setPolicyDelegate: nil]; + + if (myFrameLoadMonitor) + [myFrameLoadMonitor release]; + + if (myPolicyDelegate) + [myPolicyDelegate release]; } // ---------------------------------------------------------------------------- diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index 57dcbb02ba..b1a1f3da26 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -1393,13 +1393,14 @@ bool wxMacUnicodeTextControl::Create( wxTextCtrl *wxPeer, InstallControlEventHandler( m_controlRef , GetwxMacUnicodeTextControlEventHandlerUPP(), GetEventTypeCount(unicodeTextControlEventList), unicodeTextControlEventList, this, - NULL); + (EventHandlerRef*) &m_macTextCtrlEventHandler); return true; } wxMacUnicodeTextControl::~wxMacUnicodeTextControl() { + ::RemoveEventHandler((EventHandlerRef) m_macTextCtrlEventHandler); } void wxMacUnicodeTextControl::VisibilityChanged(bool shown) diff --git a/src/mac/carbon/toplevel.cpp b/src/mac/carbon/toplevel.cpp index 1bd4bff4b2..85ed795a4a 100644 --- a/src/mac/carbon/toplevel.cpp +++ b/src/mac/carbon/toplevel.cpp @@ -970,6 +970,16 @@ bool wxTopLevelWindowMac::Create(wxWindow *parent, return true; } +bool wxTopLevelWindowMac::Destroy() +{ + // NB: this will get called during destruction if we don't do it now, + // and may fire a kill focus event on a control being destroyed + if (m_macWindow) + ClearKeyboardFocus( (WindowRef)m_macWindow ); + + return wxTopLevelWindowBase::Destroy(); +} + wxTopLevelWindowMac::~wxTopLevelWindowMac() { if ( m_macWindow )