1 \section{\class{wxEvtHandler
}}\label{wxevthandler
}
3 A class that can handle events from the windowing system.
4 wxWindow (and therefore all window classes) are derived from
7 When events are received, wxEvtHandler invokes the method listed in the
8 event table using itself as the object. When using multiple inheritance
9 it is imperative that the wxEvtHandler(-derived) class be the first
10 class inherited such that the "this" pointer for the overall object
11 will be identical to the "this" pointer for the wxEvtHandler portion.
13 \wxheading{Derived from
}
15 \helpref{wxObject
}{wxobject
}
17 \wxheading{Include files
}
23 \overview{Event handling overview
}{eventhandlingoverview
}
25 \latexignore{\rtfignore{\wxheading{Members
}}}
27 \membersection{wxEvtHandler::wxEvtHandler
}\label{wxevthandlerctor
}
29 \func{}{wxEvtHandler
}{\void}
33 \membersection{wxEvtHandler::
\destruct{wxEvtHandler
}}\label{wxevthandlerdtor
}
35 \func{}{\destruct{wxEvtHandler
}}{\void}
37 Destructor. If the handler is part of a chain, the destructor will
38 unlink itself and restore the previous and next handlers so that they point to
41 \membersection{wxEvtHandler::AddPendingEvent
}\label{wxevthandleraddpendingevent
}
43 \func{void
}{AddPendingEvent
}{\param{wxEvent\&
}{event
}}
45 This function posts an event to be processed later.
47 \wxheading{Parameters
}
49 \docparam{event
}{Event to add to process queue.
}
53 The difference between sending an event (using the
54 \helpref{ProcessEvent
}{wxevthandlerprocessevent
} method) and posting it is
55 that in the first case the event is processed before the function returns,
56 while in the second case, the function returns immediately and the event will
57 be processed sometime later (usually during the next event loop iteration).
59 A copy of
{\it event
} is made by the function, so the original can be deleted
60 as soon as function returns (it is common that the original is created on the
61 stack). This requires that the
\helpref{wxEvent::Clone
}{wxeventclone
} method
62 be implemented by
{\it event
} so that it can be duplicated and stored until
65 This is also the method to call for inter-thread communication---it will
66 post events safely between different threads which means that this method is
67 thread-safe by using critical sections where needed. In a multi-threaded
68 program, you often need to inform the main GUI thread about the status of
69 other working threads and such notification should be done using this method.
71 This method automatically wakes up idle handling if the underlying window
72 system is currently idle and thus would not send any idle events. (Waking
73 up idle handling is done calling
\helpref{::wxWakeUpIdle
}{wxwakeupidle
}.)
75 \membersection{wxEvtHandler::Connect
}\label{wxevthandlerconnect
}
77 \func{void
}{Connect
}{\param{int
}{ id
},
\param{int
}{ lastId
},
78 \param{wxEventType
}{eventType
},
\param{wxObjectEventFunction
}{ function
},
79 \param{wxObject*
}{ userData = NULL
},
\param{wxEvtHandler*
}{ eventSink = NULL
}}
81 \func{void
}{Connect
}{\param{int
}{ id
},
82 \param{wxEventType
}{eventType
},
\param{wxObjectEventFunction
}{ function
},
83 \param{wxObject*
}{ userData = NULL
},
\param{wxEvtHandler*
}{ eventSink = NULL
}}
85 \func{void
}{Connect
}{\param{wxEventType
}{eventType
},
\param{wxObjectEventFunction
}{ function
},
86 \param{wxObject*
}{ userData = NULL
},
\param{wxEvtHandler*
}{ eventSink = NULL
}}
88 Connects the given function dynamically with the event handler, id and event type. This
89 is an alternative to the use of static event tables. See the 'event' or the old 'dynamic' sample for usage.
91 \wxheading{Parameters
}
93 \docparam{id
}{The identifier (or first of the identifier range) to be
94 associated with the event handler function. For the version not taking this
95 argument, it defaults to
\texttt{wxID
\_ANY}.
}
97 \docparam{lastId
}{The second part of the identifier range to be associated with the event handler function.
}
99 \docparam{eventType
}{The event type to be associated with this event handler.
}
101 \docparam{function
}{The event handler function. Note that this function should
102 be explicitly converted to the correct type which can be done using a macro
103 called
\texttt{wxFooHandler
} for the handler for any
\texttt{wxFooEvent
}.
}
105 \docparam{userData
}{Data to be associated with the event table entry.
}
107 \docparam{eventSink
}{Object whose member function should be called. If this is NULL,
108 \textit{this
} will be used.
}
113 frame->Connect( wxID_EXIT,
114 wxEVT_COMMAND_MENU_SELECTED,
115 wxCommandEventHandler(MyFrame::OnQuit) );
118 \perlnote{In wxPerl this function takes
4 arguments:
\texttt{id,
119 lastid, type, method
}; if
\texttt{method
} is
\texttt{undef
}, the
120 handler is disconnected.
}
122 \membersection{wxEvtHandler::Disconnect
}\label{wxevthandlerdisconnect
}
124 \func{bool
}{Disconnect
}{\param{wxEventType
}{eventType = wxEVT
\_NULL},
\param{wxObjectEventFunction
}{ function = NULL
},
125 \param{wxObject*
}{ userData = NULL
},
\param{wxEvtHandler*
}{ eventSink = NULL
}}
127 \func{bool
}{Disconnect
}{\param{int
}{ id =
\texttt{wxID
\_ANY}},
128 \param{wxEventType
}{eventType = wxEVT
\_NULL},
\param{wxObjectEventFunction
}{ function = NULL
},
129 \param{wxObject*
}{ userData = NULL
},
\param{wxEvtHandler*
}{ eventSink = NULL
}}
131 \func{bool
}{Disconnect
}{\param{int
}{ id
},
\param{int
}{ lastId =
\texttt{wxID
\_ANY}},
132 \param{wxEventType
}{eventType = wxEVT
\_NULL},
\param{wxObjectEventFunction
}{ function = NULL
},
133 \param{wxObject*
}{ userData = NULL
},
\param{wxEvtHandler*
}{ eventSink = NULL
}}
135 Disconnects the given function dynamically from the event handler, using the specified
136 parameters as search criteria and returning true if a matching function has been
137 found and removed. This method can only disconnect functions which have been added
138 using the
\helpref{wxEvtHandler::Connect
}{wxevthandlerconnect
} method. There is no way
139 to disconnect functions connected using the (static) event tables.
141 \wxheading{Parameters
}
143 \docparam{id
}{The identifier (or first of the identifier range) associated with the event handler function.
}
145 \docparam{lastId
}{The second part of the identifier range associated with the event handler function.
}
147 \docparam{eventType
}{The event type associated with this event handler.
}
149 \docparam{function
}{The event handler function.
}
151 \docparam{userData
}{Data associated with the event table entry.
}
153 \docparam{eventSink
}{Object whose member function should be called.
}
155 \perlnote{In wxPerl this function takes
3 arguments:
\texttt{id,
158 \membersection{wxEvtHandler::DoHandleEvent
}\label{wxevthandlerdohandleevent
}
160 \func{virtual void
}{DoHandleEvent
}{\param{wxEventFunction
}{ func
},
\param{wxEvent\&
}{event
}}
162 This function simply invokes the given method
\arg{func
} of this
163 event handler with the
\arg{event
} as parameter. It exists solely
164 to allow to catch the C++ exceptions which could be thrown by this event
165 handlers in one place: if you want to do this, override this
166 function in your wxEvtHandler-derived class and add try/catch clause(s) to it.
168 Exceptions not caught at this level propagate to
169 \helpref{wxApp::HandleEvent
}{wxapphandleevent
} which in turn calls
170 \helpref{wxApp::OnExceptionInMainLoop
}{wxapponexceptioninmainloop
}.
172 \membersection{wxEvtHandler::GetClientData
}\label{wxevthandlergetclientdata
}
174 \func{void*
}{GetClientData
}{\void}
176 Gets user-supplied client data.
180 Normally, any extra data the programmer wishes to associate with the object
181 should be made available by deriving a new class with new data members.
185 \helpref{wxEvtHandler::SetClientData
}{wxevthandlersetclientdata
}
187 \membersection{wxEvtHandler::GetClientObject
}\label{wxevthandlergetclientobject
}
189 \constfunc{wxClientData*
}{GetClientObject
}{\void}
191 Get a pointer to the user-supplied client data object.
195 \helpref{wxEvtHandler::SetClientObject
}{wxevthandlersetclientobject
},
196 \helpref{wxClientData
}{wxclientdata
}
198 \membersection{wxEvtHandler::GetEvtHandlerEnabled
}\label{wxevthandlergetevthandlerenabled
}
200 \func{bool
}{GetEvtHandlerEnabled
}{\void}
202 Returns true if the event handler is enabled, false otherwise.
206 \helpref{wxEvtHandler::SetEvtHandlerEnabled
}{wxevthandlersetevthandlerenabled
}
208 \membersection{wxEvtHandler::GetNextHandler
}\label{wxevthandlergetnexthandler
}
210 \func{wxEvtHandler*
}{GetNextHandler
}{\void}
212 Gets the pointer to the next handler in the chain.
216 \helpref{wxEvtHandler::SetNextHandler
}{wxevthandlersetnexthandler
},
\rtfsp
217 \helpref{wxEvtHandler::GetPreviousHandler
}{wxevthandlergetprevioushandler
},
\rtfsp
218 \helpref{wxEvtHandler::SetPreviousHandler
}{wxevthandlersetprevioushandler
},
\rtfsp
219 \helpref{wxWindow::PushEventHandler
}{wxwindowpusheventhandler
},
\rtfsp
220 \helpref{wxWindow::PopEventHandler
}{wxwindowpopeventhandler
}
222 \membersection{wxEvtHandler::GetPreviousHandler
}\label{wxevthandlergetprevioushandler
}
224 \func{wxEvtHandler*
}{GetPreviousHandler
}{\void}
226 Gets the pointer to the previous handler in the chain.
230 \helpref{wxEvtHandler::SetPreviousHandler
}{wxevthandlersetprevioushandler
},
\rtfsp
231 \helpref{wxEvtHandler::GetNextHandler
}{wxevthandlergetnexthandler
},
\rtfsp
232 \helpref{wxEvtHandler::SetNextHandler
}{wxevthandlersetnexthandler
},
\rtfsp
233 \helpref{wxWindow::PushEventHandler
}{wxwindowpusheventhandler
},
\rtfsp
234 \helpref{wxWindow::PopEventHandler
}{wxwindowpopeventhandler
}
236 \membersection{wxEvtHandler::ProcessEvent
}\label{wxevthandlerprocessevent
}
238 \func{virtual bool
}{ProcessEvent
}{\param{wxEvent\&
}{event
}}
240 Processes an event, searching event tables and calling zero or more suitable event handler function(s).
242 \wxheading{Parameters
}
244 \docparam{event
}{Event to process.
}
246 \wxheading{Return value
}
248 true if a suitable event handler function was found and executed, and the function did not
249 call
\helpref{wxEvent::Skip
}{wxeventskip
}.
253 Normally, your application would not call this function: it is called in the wxWidgets
254 implementation to dispatch incoming user interface events to the framework (and application).
256 However, you might need to call it if implementing new functionality (such as a new control) where
257 you define new event types, as opposed to allowing the user to override virtual functions.
259 An instance where you might actually override the
{\bf ProcessEvent
} function is where you want
260 to direct event processing to event handlers not normally noticed by wxWidgets. For example,
261 in the
document/view architecture, documents and views are potential event handlers.
262 When an event reaches a frame,
{\bf ProcessEvent
} will need to be called on the associated
263 document and view in case event handler functions are associated with these objects.
264 The property classes library (wxProperty) also overrides
{\bf ProcessEvent
} for similar reasons.
266 The normal order of event table searching is as follows:
268 \begin{enumerate
}\itemsep=
0pt
269 \item If the object is disabled (via a call to
\helpref{wxEvtHandler::SetEvtHandlerEnabled
}{wxevthandlersetevthandlerenabled
})
270 the function skips to step (
6).
271 \item If the object is a wxWindow,
{\bf ProcessEvent
} is recursively called on the window's
\rtfsp
272 \helpref{wxValidator
}{wxvalidator
}. If this returns true, the function exits.
273 \item {\bf SearchEventTable
} is called for this event handler. If this fails, the base
274 class table is tried, and so on until no more tables exist or an appropriate function was found,
275 in which case the function exits.
276 \item The search is applied down the entire chain of event handlers (usually the chain has a length
277 of one). If this succeeds, the function exits.
278 \item If the object is a wxWindow and the event is a wxCommandEvent,
{\bf ProcessEvent
} is
279 recursively applied to the parent window's event handler. If this returns true, the function exits.
280 \item Finally,
{\bf ProcessEvent
} is called on the wxApp object.
285 \helpref{wxEvtHandler::SearchEventTable
}{wxevthandlersearcheventtable
}
287 \membersection{wxEvtHandler::SearchEventTable
}\label{wxevthandlersearcheventtable
}
289 \func{virtual bool
}{SearchEventTable
}{\param{wxEventTable\&
}{table
},
\param{wxEvent\&
}{event
}}
291 Searches the event table, executing an event handler function if an appropriate one
294 \wxheading{Parameters
}
296 \docparam{table
}{Event table to be searched.
}
298 \docparam{event
}{Event to be matched against an event table entry.
}
300 \wxheading{Return value
}
302 true if a suitable event handler function was found and executed, and the function did not
303 call
\helpref{wxEvent::Skip
}{wxeventskip
}.
307 This function looks through the object's event table and tries to find an entry
308 that will match the event.
310 An entry will match if:
312 \begin{enumerate
}\itemsep=
0pt
313 \item The event type matches, and
314 \item the identifier or identifier range matches, or the event table entry's identifier is zero.
317 If a suitable function is called but calls
\helpref{wxEvent::Skip
}{wxeventskip
}, this function will
318 fail, and searching will continue.
322 \helpref{wxEvtHandler::ProcessEvent
}{wxevthandlerprocessevent
}
324 \membersection{wxEvtHandler::SetClientData
}\label{wxevthandlersetclientdata
}
326 \func{void
}{SetClientData
}{\param{void*
}{data
}}
328 Sets user-supplied client data.
330 \wxheading{Parameters
}
332 \docparam{data
}{Data to be associated with the event handler.
}
336 Normally, any extra data the programmer wishes to associate with
337 the object should be made available by deriving a new class
338 with new data members. You must not call this method and
339 \helpref{SetClientObject
}{wxevthandlersetclientobject
} on the
340 same class - only one of them.
344 \helpref{wxEvtHandler::GetClientData
}{wxevthandlergetclientdata
}
346 \membersection{wxEvtHandler::SetClientObject
}\label{wxevthandlersetclientobject
}
348 \func{void
}{SetClientObject
}{\param{wxClientData*
}{data
}}
350 Set the client data object. Any previous object will be deleted.
354 \helpref{wxEvtHandler::GetClientObject
}{wxevthandlergetclientobject
},
355 \helpref{wxClientData
}{wxclientdata
}
357 \membersection{wxEvtHandler::SetEvtHandlerEnabled
}\label{wxevthandlersetevthandlerenabled
}
359 \func{void
}{SetEvtHandlerEnabled
}{\param{bool
}{enabled
}}
361 Enables or disables the event handler.
363 \wxheading{Parameters
}
365 \docparam{enabled
}{true if the event handler is to be enabled, false if it is to be disabled.
}
369 You can use this function to avoid having to remove the event handler from the chain, for example
370 when implementing a dialog editor and changing from edit to test mode.
374 \helpref{wxEvtHandler::GetEvtHandlerEnabled
}{wxevthandlergetevthandlerenabled
}
376 \membersection{wxEvtHandler::SetNextHandler
}\label{wxevthandlersetnexthandler
}
378 \func{void
}{SetNextHandler
}{\param{wxEvtHandler*
}{handler
}}
380 Sets the pointer to the next handler.
382 \wxheading{Parameters
}
384 \docparam{handler
}{Event handler to be set as the next handler.
}
388 \helpref{wxEvtHandler::GetNextHandler
}{wxevthandlergetnexthandler
},
\rtfsp
389 \helpref{wxEvtHandler::SetPreviousHandler
}{wxevthandlersetprevioushandler
},
\rtfsp
390 \helpref{wxEvtHandler::GetPreviousHandler
}{wxevthandlergetprevioushandler
},
\rtfsp
391 \helpref{wxWindow::PushEventHandler
}{wxwindowpusheventhandler
},
\rtfsp
392 \helpref{wxWindow::PopEventHandler
}{wxwindowpopeventhandler
}
394 \membersection{wxEvtHandler::SetPreviousHandler
}\label{wxevthandlersetprevioushandler
}
396 \func{void
}{SetPreviousHandler
}{\param{wxEvtHandler*
}{handler
}}
398 Sets the pointer to the previous handler.
400 \wxheading{Parameters
}
402 \docparam{handler
}{Event handler to be set as the previous handler.
}
406 \helpref{wxEvtHandler::GetPreviousHandler
}{wxevthandlergetprevioushandler
},
\rtfsp
407 \helpref{wxEvtHandler::SetNextHandler
}{wxevthandlersetnexthandler
},
\rtfsp
408 \helpref{wxEvtHandler::GetNextHandler
}{wxevthandlergetnexthandler
},
\rtfsp
409 \helpref{wxWindow::PushEventHandler
}{wxwindowpusheventhandler
},
\rtfsp
410 \helpref{wxWindow::PopEventHandler
}{wxwindowpopeventhandler
}