From 0fa5ce0c7608e50b695db9316d37e1a961a3edc1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 16 Mar 2007 00:43:32 +0000 Subject: [PATCH] use safer RemoveEventHandler() instead of PopEventHandler() (patch 1678016) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44842 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/mediactrl_am.cpp | 11 +++++++++-- src/msw/mediactrl_qt.cpp | 11 +++++++++-- src/msw/mediactrl_wmp10.cpp | 11 +++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/msw/mediactrl_am.cpp b/src/msw/mediactrl_am.cpp index be49d39044..eb139307d5 100644 --- a/src/msw/mediactrl_am.cpp +++ b/src/msw/mediactrl_am.cpp @@ -1483,6 +1483,7 @@ public: LPAMGETERRORTEXT m_lpAMGetErrorText; wxString GetErrorString(HRESULT hrdsv); #endif // __WXDEBUG__ + wxEvtHandler* m_evthandler; friend class wxAMMediaEvtHandler; DECLARE_DYNAMIC_CLASS(wxAMMediaBackend) @@ -1573,6 +1574,7 @@ wxAMMediaBackend::wxAMMediaBackend() #endif m_bestSize(wxDefaultSize) { + m_evthandler = NULL; } //--------------------------------------------------------------------------- @@ -1591,7 +1593,11 @@ wxAMMediaBackend::~wxAMMediaBackend() if (GetMP()) GetMP()->Release(); - m_ctrl->PopEventHandler(true); + if (m_evthandler) + { + m_ctrl->RemoveEventHandler(m_evthandler); + delete m_evthandler; + } } } @@ -1683,7 +1689,8 @@ bool wxAMMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent, #endif ); // Connect for events - m_ctrl->PushEventHandler(new wxAMMediaEvtHandler(this)); + m_evthandler = new wxAMMediaEvtHandler(this); + m_ctrl->PushEventHandler(m_evthandler); // // Here we set up wx-specific stuff for the default diff --git a/src/msw/mediactrl_qt.cpp b/src/msw/mediactrl_qt.cpp index 406f514e48..920ac7f9fd 100644 --- a/src/msw/mediactrl_qt.cpp +++ b/src/msw/mediactrl_qt.cpp @@ -429,6 +429,7 @@ public: wxTimer* m_timer; // Load or Play timer wxQuickTimeLibrary m_lib; // DLL to load functions from ComponentInstance m_pMC; // Movie Controller + wxEvtHandler* m_evthandler; friend class wxQTMediaEvtHandler; @@ -605,6 +606,7 @@ LRESULT CALLBACK wxQTMediaBackend::QTWndProc(HWND hWnd, UINT nMsg, wxQTMediaBackend::wxQTMediaBackend() : m_movie(NULL), m_bPlaying(false), m_timer(NULL), m_pMC(NULL) { + m_evthandler = NULL; } //--------------------------------------------------------------------------- @@ -630,7 +632,11 @@ wxQTMediaBackend::~wxQTMediaBackend() } // destroy wxQTMediaEvtHandler we pushed on it - m_ctrl->PopEventHandler(true); + if (m_evthandler) + { + m_ctrl->RemoveEventHandler(m_evthandler); + delete m_evthandler; + } m_lib.DestroyPortAssociation( (CGrafPtr)m_lib.GetNativeWindowPort(m_ctrl->GetHWND())); @@ -689,7 +695,8 @@ bool wxQTMediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent, // Part of a suggestion from Greg Hazel // to repaint movie when idle - m_ctrl->PushEventHandler(new wxQTMediaEvtHandler(this, m_ctrl->GetHWND())); + m_evthandler = new wxQTMediaEvtHandler(this, m_ctrl->GetHWND()); + m_ctrl->PushEventHandler(m_evthandler); // done return true; diff --git a/src/msw/mediactrl_wmp10.cpp b/src/msw/mediactrl_wmp10.cpp index 1604899da8..8a6f69a29d 100644 --- a/src/msw/mediactrl_wmp10.cpp +++ b/src/msw/mediactrl_wmp10.cpp @@ -675,6 +675,7 @@ public: wxSize m_bestSize; // Actual movie size bool m_bWasStateChanged; // See the "introduction" + wxEvtHandler* m_evthandler; friend class wxWMP10MediaEvtHandler; DECLARE_DYNAMIC_CLASS(wxWMP10MediaBackend) @@ -726,6 +727,7 @@ wxWMP10MediaBackend::wxWMP10MediaBackend() m_pWMPPlayer(NULL) { + m_evthandler = NULL; } //--------------------------------------------------------------------------- @@ -739,7 +741,11 @@ wxWMP10MediaBackend::~wxWMP10MediaBackend() m_pAX->DissociateHandle(); delete m_pAX; - m_ctrl->PopEventHandler(true); + if (m_evthandler) + { + m_ctrl->RemoveEventHandler(m_evthandler); + delete m_evthandler; + } #else AtlAxWinTerm(); _Module.Term(); @@ -812,7 +818,8 @@ bool wxWMP10MediaBackend::CreateControl(wxControl* ctrl, wxWindow* parent, m_pAX = new wxActiveXContainer(ctrl, IID_IWMPPlayer, m_pWMPPlayer); // Connect for events - m_ctrl->PushEventHandler(new wxWMP10MediaEvtHandler(this)); + m_evthandler = new wxWMP10MediaEvtHandler(this); + m_ctrl->PushEventHandler(m_evthandler); #else _Module.Init(NULL, ::GetModuleHandle(NULL)); AtlAxWinInit(); -- 2.45.2