]>
Commit | Line | Data |
---|---|---|
a660d684 KB |
1 | \section{\class{wxEvtHandler}}\label{wxevthandler} |
2 | ||
3 | A class that can handle events from the windowing system. | |
4 | wxWindow (and therefore all window classes) are derived from | |
5 | this class. | |
6 | ||
a685e84a DE |
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. | |
12 | ||
a660d684 KB |
13 | \wxheading{Derived from} |
14 | ||
15 | \helpref{wxObject}{wxobject} | |
16 | ||
954b8ae6 JS |
17 | \wxheading{Include files} |
18 | ||
19 | <wx/event.h> | |
20 | ||
a660d684 KB |
21 | \wxheading{See also} |
22 | ||
23 | \overview{Event handling overview}{eventhandlingoverview} | |
24 | ||
25 | \latexignore{\rtfignore{\wxheading{Members}}} | |
26 | ||
b236c10f | 27 | \membersection{wxEvtHandler::wxEvtHandler}\label{wxevthandlerctor} |
a660d684 KB |
28 | |
29 | \func{}{wxEvtHandler}{\void} | |
30 | ||
31 | Constructor. | |
32 | ||
b236c10f | 33 | \membersection{wxEvtHandler::\destruct{wxEvtHandler}}\label{wxevthandlerdtor} |
a660d684 KB |
34 | |
35 | \func{}{\destruct{wxEvtHandler}}{\void} | |
36 | ||
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 | |
39 | each other. | |
40 | ||
8a293590 RR |
41 | \membersection{wxEvtHandler::AddPendingEvent}\label{wxevthandleraddpendingevent} |
42 | ||
06d4e3c2 | 43 | \func{void}{AddPendingEvent}{\param{wxEvent\& }{event}} |
8a293590 | 44 | |
8e72b8b5 | 45 | This function posts an event to be processed later. |
8a293590 RR |
46 | |
47 | \wxheading{Parameters} | |
48 | ||
49 | \docparam{event}{Event to add to process queue.} | |
50 | ||
51 | \wxheading{Remarks} | |
52 | ||
8e72b8b5 RR |
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). | |
58 | ||
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 | |
63 | it gets processed. | |
64 | ||
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. | |
70 | ||
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}.) | |
8a293590 | 74 | |
f60d0f94 JS |
75 | \membersection{wxEvtHandler::Connect}\label{wxevthandlerconnect} |
76 | ||
18e33484 | 77 | \func{void}{Connect}{\param{int}{ id}, \param{int}{ lastId}, |
f60d0f94 | 78 | \param{wxEventType }{eventType}, \param{wxObjectEventFunction}{ function}, |
97e1d37c | 79 | \param{wxObject*}{ userData = NULL}, \param{wxEvtHandler*}{ eventSink = NULL}} |
f60d0f94 | 80 | |
18e33484 | 81 | \func{void}{Connect}{\param{int}{ id}, |
f60d0f94 | 82 | \param{wxEventType }{eventType}, \param{wxObjectEventFunction}{ function}, |
97e1d37c | 83 | \param{wxObject*}{ userData = NULL}, \param{wxEvtHandler*}{ eventSink = NULL}} |
f60d0f94 | 84 | |
18e33484 VZ |
85 | \func{void}{Connect}{\param{wxEventType }{eventType}, \param{wxObjectEventFunction}{ function}, |
86 | \param{wxObject*}{ userData = NULL}, \param{wxEvtHandler*}{ eventSink = NULL}} | |
87 | ||
f60d0f94 | 88 | Connects the given function dynamically with the event handler, id and event type. This |
f70c0443 | 89 | is an alternative to the use of static event tables. See the 'event' or the old 'dynamic' sample for usage. |
f60d0f94 JS |
90 | |
91 | \wxheading{Parameters} | |
92 | ||
18e33484 VZ |
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}.} | |
f60d0f94 JS |
96 | |
97 | \docparam{lastId}{The second part of the identifier range to be associated with the event handler function.} | |
98 | ||
99 | \docparam{eventType}{The event type to be associated with this event handler.} | |
100 | ||
18e33484 VZ |
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}.} | |
f60d0f94 JS |
104 | |
105 | \docparam{userData}{Data to be associated with the event table entry.} | |
106 | ||
97e1d37c | 107 | \docparam{eventSink}{Object whose member function should be called. If this is NULL, |
18e33484 | 108 | \textit{this} will be used.} |
97e1d37c | 109 | |
f60d0f94 JS |
110 | \wxheading{Example} |
111 | ||
112 | \begin{verbatim} | |
113 | frame->Connect( wxID_EXIT, | |
114 | wxEVT_COMMAND_MENU_SELECTED, | |
18e33484 | 115 | wxCommandEventHandler(MyFrame::OnQuit) ); |
f60d0f94 JS |
116 | \end{verbatim} |
117 | ||
2bbd97f4 MB |
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.} | |
121 | ||
8a293590 RR |
122 | \membersection{wxEvtHandler::Disconnect}\label{wxevthandlerdisconnect} |
123 | ||
e554d626 | 124 | \func{bool}{Disconnect}{\param{int}{ id = \texttt{wxID\_ANY}}, |
605d715d | 125 | \param{wxEventType }{eventType = wxEVT\_NULL}, \param{wxObjectEventFunction}{ function = NULL}, |
97e1d37c | 126 | \param{wxObject*}{ userData = NULL}, \param{wxEvtHandler*}{ eventSink = NULL}} |
8a293590 | 127 | |
e554d626 | 128 | \func{bool}{Disconnect}{\param{int}{ id}, \param{int}{ lastId = \texttt{wxID\_ANY}}, |
605d715d | 129 | \param{wxEventType }{eventType = wxEVT\_NULL}, \param{wxObjectEventFunction}{ function = NULL}, |
97e1d37c | 130 | \param{wxObject*}{ userData = NULL}, \param{wxEvtHandler*}{ eventSink = NULL}} |
a660d684 | 131 | |
8a293590 | 132 | Disconnects the given function dynamically from the event handler, using the specified |
cc81d32f | 133 | parameters as search criteria and returning true if a matching function has been |
ccaaf5b0 | 134 | found and removed. This method can only disconnect functions which have been added |
8a293590 | 135 | using the \helpref{wxEvtHandler::Connect}{wxevthandlerconnect} method. There is no way |
ccaaf5b0 | 136 | to disconnect functions connected using the (static) event tables. |
a660d684 | 137 | |
8a293590 | 138 | \wxheading{Parameters} |
a660d684 | 139 | |
8a293590 | 140 | \docparam{id}{The identifier (or first of the identifier range) associated with the event handler function.} |
a660d684 | 141 | |
8a293590 | 142 | \docparam{lastId}{The second part of the identifier range associated with the event handler function.} |
a660d684 | 143 | |
8a293590 | 144 | \docparam{eventType}{The event type associated with this event handler.} |
a660d684 | 145 | |
8a293590 | 146 | \docparam{function}{The event handler function.} |
a660d684 | 147 | |
ccaaf5b0 | 148 | \docparam{userData}{Data associated with the event table entry.} |
a660d684 | 149 | |
97e1d37c JS |
150 | \docparam{eventSink}{Object whose member function should be called.} |
151 | ||
2bbd97f4 MB |
152 | \perlnote{In wxPerl this function takes 3 arguments: \texttt{id, |
153 | lastid, type}.} | |
154 | ||
a660d684 KB |
155 | \membersection{wxEvtHandler::GetClientData}\label{wxevthandlergetclientdata} |
156 | ||
ccaaf5b0 | 157 | \func{void* }{GetClientData}{\void} |
a660d684 KB |
158 | |
159 | Gets user-supplied client data. | |
160 | ||
161 | \wxheading{Remarks} | |
162 | ||
163 | Normally, any extra data the programmer wishes to associate with the object | |
ccaaf5b0 | 164 | should be made available by deriving a new class with new data members. |
a660d684 KB |
165 | |
166 | \wxheading{See also} | |
167 | ||
168 | \helpref{wxEvtHandler::SetClientData}{wxevthandlersetclientdata} | |
169 | ||
e3ba9f88 RR |
170 | \membersection{wxEvtHandler::GetClientObject}\label{wxevthandlergetclientobject} |
171 | ||
172 | \constfunc{wxClientData*}{GetClientObject}{\void} | |
173 | ||
174 | Get a pointer to the user-supplied client data object. | |
175 | ||
176 | \wxheading{See also} | |
177 | ||
178 | \helpref{wxEvtHandler::SetClientObject}{wxevthandlersetclientobject}, | |
179 | \helpref{wxClientData}{wxclientdata} | |
180 | ||
a660d684 KB |
181 | \membersection{wxEvtHandler::GetEvtHandlerEnabled}\label{wxevthandlergetevthandlerenabled} |
182 | ||
183 | \func{bool}{GetEvtHandlerEnabled}{\void} | |
184 | ||
cc81d32f | 185 | Returns true if the event handler is enabled, false otherwise. |
a660d684 KB |
186 | |
187 | \wxheading{See also} | |
188 | ||
189 | \helpref{wxEvtHandler::SetEvtHandlerEnabled}{wxevthandlersetevthandlerenabled} | |
190 | ||
191 | \membersection{wxEvtHandler::GetNextHandler}\label{wxevthandlergetnexthandler} | |
192 | ||
193 | \func{wxEvtHandler*}{GetNextHandler}{\void} | |
194 | ||
195 | Gets the pointer to the next handler in the chain. | |
196 | ||
197 | \wxheading{See also} | |
198 | ||
b4a2ab72 | 199 | \helpref{wxEvtHandler::SetNextHandler}{wxevthandlersetnexthandler},\rtfsp |
a660d684 KB |
200 | \helpref{wxEvtHandler::GetPreviousHandler}{wxevthandlergetprevioushandler},\rtfsp |
201 | \helpref{wxEvtHandler::SetPreviousHandler}{wxevthandlersetprevioushandler},\rtfsp | |
a660d684 KB |
202 | \helpref{wxWindow::PushEventHandler}{wxwindowpusheventhandler},\rtfsp |
203 | \helpref{wxWindow::PopEventHandler}{wxwindowpopeventhandler} | |
204 | ||
205 | \membersection{wxEvtHandler::GetPreviousHandler}\label{wxevthandlergetprevioushandler} | |
206 | ||
207 | \func{wxEvtHandler*}{GetPreviousHandler}{\void} | |
208 | ||
209 | Gets the pointer to the previous handler in the chain. | |
210 | ||
211 | \wxheading{See also} | |
212 | ||
a660d684 | 213 | \helpref{wxEvtHandler::SetPreviousHandler}{wxevthandlersetprevioushandler},\rtfsp |
b4a2ab72 SB |
214 | \helpref{wxEvtHandler::GetNextHandler}{wxevthandlergetnexthandler},\rtfsp |
215 | \helpref{wxEvtHandler::SetNextHandler}{wxevthandlersetnexthandler},\rtfsp | |
a660d684 KB |
216 | \helpref{wxWindow::PushEventHandler}{wxwindowpusheventhandler},\rtfsp |
217 | \helpref{wxWindow::PopEventHandler}{wxwindowpopeventhandler} | |
218 | ||
219 | \membersection{wxEvtHandler::ProcessEvent}\label{wxevthandlerprocessevent} | |
220 | ||
221 | \func{virtual bool}{ProcessEvent}{\param{wxEvent\& }{event}} | |
222 | ||
223 | Processes an event, searching event tables and calling zero or more suitable event handler function(s). | |
224 | ||
225 | \wxheading{Parameters} | |
226 | ||
227 | \docparam{event}{Event to process.} | |
228 | ||
229 | \wxheading{Return value} | |
230 | ||
cc81d32f | 231 | true if a suitable event handler function was found and executed, and the function did not |
a660d684 KB |
232 | call \helpref{wxEvent::Skip}{wxeventskip}. |
233 | ||
234 | \wxheading{Remarks} | |
235 | ||
fc2171bd | 236 | Normally, your application would not call this function: it is called in the wxWidgets |
a660d684 KB |
237 | implementation to dispatch incoming user interface events to the framework (and application). |
238 | ||
239 | However, you might need to call it if implementing new functionality (such as a new control) where | |
240 | you define new event types, as opposed to allowing the user to override virtual functions. | |
241 | ||
242 | An instance where you might actually override the {\bf ProcessEvent} function is where you want | |
fc2171bd | 243 | to direct event processing to event handlers not normally noticed by wxWidgets. For example, |
a660d684 KB |
244 | in the document/view architecture, documents and views are potential event handlers. |
245 | When an event reaches a frame, {\bf ProcessEvent} will need to be called on the associated | |
246 | document and view in case event handler functions are associated with these objects. | |
247 | The property classes library (wxProperty) also overrides {\bf ProcessEvent} for similar reasons. | |
248 | ||
249 | The normal order of event table searching is as follows: | |
250 | ||
251 | \begin{enumerate}\itemsep=0pt | |
252 | \item If the object is disabled (via a call to \helpref{wxEvtHandler::SetEvtHandlerEnabled}{wxevthandlersetevthandlerenabled}) | |
253 | the function skips to step (6). | |
254 | \item If the object is a wxWindow, {\bf ProcessEvent} is recursively called on the window's\rtfsp | |
cc81d32f | 255 | \helpref{wxValidator}{wxvalidator}. If this returns true, the function exits. |
a660d684 KB |
256 | \item {\bf SearchEventTable} is called for this event handler. If this fails, the base |
257 | class table is tried, and so on until no more tables exist or an appropriate function was found, | |
258 | in which case the function exits. | |
259 | \item The search is applied down the entire chain of event handlers (usually the chain has a length | |
260 | of one). If this succeeds, the function exits. | |
261 | \item If the object is a wxWindow and the event is a wxCommandEvent, {\bf ProcessEvent} is | |
cc81d32f | 262 | recursively applied to the parent window's event handler. If this returns true, the function exits. |
a660d684 KB |
263 | \item Finally, {\bf ProcessEvent} is called on the wxApp object. |
264 | \end{enumerate} | |
265 | ||
266 | \wxheading{See also} | |
267 | ||
268 | \helpref{wxEvtHandler::SearchEventTable}{wxevthandlersearcheventtable} | |
269 | ||
270 | \membersection{wxEvtHandler::SearchEventTable}\label{wxevthandlersearcheventtable} | |
271 | ||
4cee05ac | 272 | \func{virtual bool}{SearchEventTable}{\param{wxEventTable\& }{table}, \param{wxEvent\& }{event}} |
a660d684 KB |
273 | |
274 | Searches the event table, executing an event handler function if an appropriate one | |
275 | is found. | |
276 | ||
277 | \wxheading{Parameters} | |
278 | ||
279 | \docparam{table}{Event table to be searched.} | |
280 | ||
281 | \docparam{event}{Event to be matched against an event table entry.} | |
282 | ||
283 | \wxheading{Return value} | |
284 | ||
cc81d32f | 285 | true if a suitable event handler function was found and executed, and the function did not |
a660d684 KB |
286 | call \helpref{wxEvent::Skip}{wxeventskip}. |
287 | ||
288 | \wxheading{Remarks} | |
289 | ||
290 | This function looks through the object's event table and tries to find an entry | |
291 | that will match the event. | |
292 | ||
293 | An entry will match if: | |
294 | ||
295 | \begin{enumerate}\itemsep=0pt | |
296 | \item The event type matches, and | |
297 | \item the identifier or identifier range matches, or the event table entry's identifier is zero. | |
298 | \end{enumerate} | |
299 | ||
300 | If a suitable function is called but calls \helpref{wxEvent::Skip}{wxeventskip}, this function will | |
301 | fail, and searching will continue. | |
302 | ||
303 | \wxheading{See also} | |
304 | ||
305 | \helpref{wxEvtHandler::ProcessEvent}{wxevthandlerprocessevent} | |
306 | ||
307 | \membersection{wxEvtHandler::SetClientData}\label{wxevthandlersetclientdata} | |
308 | ||
ccaaf5b0 | 309 | \func{void}{SetClientData}{\param{void* }{data}} |
a660d684 KB |
310 | |
311 | Sets user-supplied client data. | |
312 | ||
313 | \wxheading{Parameters} | |
314 | ||
315 | \docparam{data}{Data to be associated with the event handler.} | |
316 | ||
317 | \wxheading{Remarks} | |
318 | ||
ccaaf5b0 RR |
319 | Normally, any extra data the programmer wishes to associate with |
320 | the object should be made available by deriving a new class | |
e3ba9f88 RR |
321 | with new data members. You must not call this method and |
322 | \helpref{SetClientObject}{wxevthandlersetclientobject} on the | |
323 | same class - only one of them. | |
a660d684 KB |
324 | |
325 | \wxheading{See also} | |
326 | ||
327 | \helpref{wxEvtHandler::GetClientData}{wxevthandlergetclientdata} | |
328 | ||
e3ba9f88 RR |
329 | \membersection{wxEvtHandler::SetClientObject}\label{wxevthandlersetclientobject} |
330 | ||
331 | \func{void}{SetClientObject}{\param{wxClientData* }{data}} | |
332 | ||
333 | Set the client data object. Any previous object will be deleted. | |
334 | ||
335 | \wxheading{See also} | |
336 | ||
337 | \helpref{wxEvtHandler::GetClientObject}{wxevthandlergetclientobject}, | |
338 | \helpref{wxClientData}{wxclientdata} | |
339 | ||
a660d684 KB |
340 | \membersection{wxEvtHandler::SetEvtHandlerEnabled}\label{wxevthandlersetevthandlerenabled} |
341 | ||
342 | \func{void}{SetEvtHandlerEnabled}{\param{bool }{enabled}} | |
343 | ||
344 | Enables or disables the event handler. | |
345 | ||
346 | \wxheading{Parameters} | |
347 | ||
cc81d32f | 348 | \docparam{enabled}{true if the event handler is to be enabled, false if it is to be disabled.} |
a660d684 KB |
349 | |
350 | \wxheading{Remarks} | |
351 | ||
352 | You can use this function to avoid having to remove the event handler from the chain, for example | |
353 | when implementing a dialog editor and changing from edit to test mode. | |
354 | ||
355 | \wxheading{See also} | |
356 | ||
357 | \helpref{wxEvtHandler::GetEvtHandlerEnabled}{wxevthandlergetevthandlerenabled} | |
358 | ||
359 | \membersection{wxEvtHandler::SetNextHandler}\label{wxevthandlersetnexthandler} | |
360 | ||
361 | \func{void}{SetNextHandler}{\param{wxEvtHandler* }{handler}} | |
362 | ||
363 | Sets the pointer to the next handler. | |
364 | ||
365 | \wxheading{Parameters} | |
366 | ||
367 | \docparam{handler}{Event handler to be set as the next handler.} | |
368 | ||
369 | \wxheading{See also} | |
370 | ||
371 | \helpref{wxEvtHandler::GetNextHandler}{wxevthandlergetnexthandler},\rtfsp | |
372 | \helpref{wxEvtHandler::SetPreviousHandler}{wxevthandlersetprevioushandler},\rtfsp | |
373 | \helpref{wxEvtHandler::GetPreviousHandler}{wxevthandlergetprevioushandler},\rtfsp | |
374 | \helpref{wxWindow::PushEventHandler}{wxwindowpusheventhandler},\rtfsp | |
375 | \helpref{wxWindow::PopEventHandler}{wxwindowpopeventhandler} | |
376 | ||
377 | \membersection{wxEvtHandler::SetPreviousHandler}\label{wxevthandlersetprevioushandler} | |
378 | ||
379 | \func{void}{SetPreviousHandler}{\param{wxEvtHandler* }{handler}} | |
380 | ||
381 | Sets the pointer to the previous handler. | |
382 | ||
383 | \wxheading{Parameters} | |
384 | ||
385 | \docparam{handler}{Event handler to be set as the previous handler.} | |
386 | ||
387 | \wxheading{See also} | |
388 | ||
389 | \helpref{wxEvtHandler::GetPreviousHandler}{wxevthandlergetprevioushandler},\rtfsp | |
390 | \helpref{wxEvtHandler::SetNextHandler}{wxevthandlersetnexthandler},\rtfsp | |
391 | \helpref{wxEvtHandler::GetNextHandler}{wxevthandlergetnexthandler},\rtfsp | |
392 | \helpref{wxWindow::PushEventHandler}{wxwindowpusheventhandler},\rtfsp | |
393 | \helpref{wxWindow::PopEventHandler}{wxwindowpopeventhandler} | |
394 | ||
395 |