]> git.saurik.com Git - wxWidgets.git/commitdiff
added and documented wxWindow::RemoveEventHandler()
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 25 Jan 2002 16:01:15 +0000 (16:01 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 25 Jan 2002 16:01:15 +0000 (16:01 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13805 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/window.tex
include/wx/window.h
src/common/wincmn.cpp

index 4203a4bf6aaca8be36ec547e476d6de2958e38ad..0ea0bac9873d74c57ac3ebbcfaaa4db64847a0ac 100644 (file)
@@ -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}}
index 905327ad1ac2562ed5e82822ae3490c668bd0ae7..76c8865089ff406b52c173989e5121627c524dda 100644 (file)
@@ -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
     // ----------
 
index 2801de986d8701fd34a32cee7fded582e7f4beff..24158367eb3f7d855ae30313308643cc53985b3d 100644 (file)
@@ -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
 // ----------------------------------------------------------------------------