From: Vadim Zeitlin Date: Fri, 25 Jan 2002 16:01:15 +0000 (+0000) Subject: added and documented wxWindow::RemoveEventHandler() X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/2e36d5cf818d64c8abdb3da1861d233d774be139 added and documented wxWindow::RemoveEventHandler() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13805 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/latex/wx/window.tex b/docs/latex/wx/window.tex index 4203a4bf6a..0ea0bac987 100644 --- a/docs/latex/wx/window.tex +++ b/docs/latex/wx/window.tex @@ -1776,6 +1776,29 @@ functions so should not be required by the application programmer. \docparam{child}{Child window to remove.} +\membersection{wxWindow::RemoveEventHandler}{wxwindowremoveeventhandler} + +\func{bool}{RemoveEventHandler}{\param{wxEvtHandler *}{handler}} + +Find the given {\it handler} in the windows event handler chain and remove (but +not delete) it from it. + +\wxheading{Parameters} + +\docparam{handler}{The event handler to remove, must be non {\tt NULL} and +must be present in this windows event handlers chain} + +\wxheading{Return value} + +Returns {\tt TRUE} if it was found and {\tt FALSE} otherwise (this also results +in an assert failure so this function should only be called when the +handler is supposed to be there). + +\wxheading{See also} + +\helpref{PushEventHandler}{wxwindowpusheventhandler},\rtfsp +\helpref{PopEventHandler}{wxwindowpopeventhandler} + \membersection{wxWindow::Reparent}\label{wxwindowreparent} \func{virtual bool}{Reparent}{\param{wxWindow* }{newParent}} diff --git a/include/wx/window.h b/include/wx/window.h index 905327ad1a..76c8865089 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -403,6 +403,13 @@ public: void PushEventHandler( wxEvtHandler *handler ); wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE ); + // find the given handler in the event handler chain and remove (but + // not delete) it from the event handler chain, return TRUE if it was + // found and FALSE otherwise (this also results in an assert failure so + // this function should only be called when the handler is supposed to + // be there) + bool RemoveEventHandler(wxEvtHandler *handler); + // validators // ---------- diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 2801de986d..24158367eb 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -633,6 +633,41 @@ wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler) return handlerA; } +bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handler) +{ + wxCHECK_MSG( handler, FALSE, _T("RemoveEventHandler(NULL) called") ); + + wxEvtHandler *handlerPrev = NULL, + *handlerCur = GetEventHandler(); + while ( handlerCur ) + { + wxEvtHandler *handlerNext = handlerCur->GetNextHandler(); + + if ( handlerCur == handler ) + { + if ( handlerPrev ) + { + handlerPrev->SetNextHandler(handlerNext); + } + else + { + SetEventHandler(handlerNext); + } + + handler->SetNextHandler(NULL); + + return TRUE; + } + + handlerPrev = handlerCur; + handlerCur = handlerNext; + } + + wxFAIL_MSG( _T("where has the event handler gone?") ); + + return FALSE; +} + // ---------------------------------------------------------------------------- // cursors, fonts &c // ----------------------------------------------------------------------------