]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/evthand.tex
Corrections
[wxWidgets.git] / docs / latex / wx / evthand.tex
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
7 \wxheading{Derived from}
8
9 \helpref{wxObject}{wxobject}
10
11 \wxheading{Include files}
12
13 <wx/event.h>
14
15 \wxheading{See also}
16
17 \overview{Event handling overview}{eventhandlingoverview}
18
19 \latexignore{\rtfignore{\wxheading{Members}}}
20
21 \membersection{wxEvtHandler::wxEvtHandler}
22
23 \func{}{wxEvtHandler}{\void}
24
25 Constructor.
26
27 \membersection{wxEvtHandler::\destruct{wxEvtHandler}}
28
29 \func{}{\destruct{wxEvtHandler}}{\void}
30
31 Destructor. If the handler is part of a chain, the destructor will
32 unlink itself and restore the previous and next handlers so that they point to
33 each other.
34
35 \membersection{wxEvtHandler::AddPendingEvent}\label{wxevthandleraddpendingevent}
36
37 \func{virtual void}{AddPendingEvent}{\param{wxEvent\& }{event}}
38
39 This function posts an event to be processed later.
40
41 \wxheading{Parameters}
42
43 \docparam{event}{Event to add to process queue.}
44
45 \wxheading{Remarks}
46
47 The difference between sending an event (using the
48 \helpref{ProcessEvent}{wxevthandlerprocessevent} method) and posting it is
49 that in the first case the event is processed before the function returns,
50 while in the second case, the function returns immediately and the event will
51 be processed sometime later (usually during the next event loop iteration).
52
53 A copy of {\it event} is made by the function, so the original can be deleted
54 as soon as function returns (it is common that the original is created on the
55 stack). This requires that the \helpref{wxEvent::Clone}{wxeventclone} method
56 be implemented by {\it event} so that it can be duplicated and stored until
57 it gets processed.
58
59 This is also the method to call for inter-thread communication---it will
60 post events safely between different threads which means that this method is
61 thread-safe by using critical sections where needed. In a multi-threaded
62 program, you often need to inform the main GUI thread about the status of
63 other working threads and such notification should be done using this method.
64
65 This method automatically wakes up idle handling if the underlying window
66 system is currently idle and thus would not send any idle events. (Waking
67 up idle handling is done calling \helpref{::wxWakeUpIdle}{wxwakeupidle}.)
68
69 \membersection{wxEvtHandler::Connect}\label{wxevthandlerconnect}
70
71 \func{void}{Connect}{\param{int}{ id},
72 \param{wxEventType }{eventType}, \param{wxObjectEventFunction}{ function},
73 \param{wxObject*}{ userData = NULL}, \param{wxEvtHandler*}{ eventSink = NULL}}
74
75 \func{void}{Connect}{\param{int}{ id}, \param{int}{ lastId},
76 \param{wxEventType }{eventType}, \param{wxObjectEventFunction}{ function},
77 \param{wxObject*}{ userData = NULL}, \param{wxEvtHandler*}{ eventSink = NULL}}
78
79 Connects the given function dynamically with the event handler, id and event type. This
80 is an alternative to the use of static event tables. See the 'dynamic' sample for usage.
81
82 \wxheading{Parameters}
83
84 \docparam{id}{The identifier (or first of the identifier range) to be associated with the event handler function.}
85
86 \docparam{lastId}{The second part of the identifier range to be associated with the event handler function.}
87
88 \docparam{eventType}{The event type to be associated with this event handler.}
89
90 \docparam{function}{The event handler function.}
91
92 \docparam{userData}{Data to be associated with the event table entry.}
93
94 \docparam{eventSink}{Object whose member function should be called. If this is NULL,
95 'this' will be used.}
96
97 \wxheading{Example}
98
99 \begin{verbatim}
100 frame->Connect( wxID_EXIT,
101 wxEVT_COMMAND_MENU_SELECTED,
102 (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) MyFrame::OnQuit );
103 \end{verbatim}
104
105 \membersection{wxEvtHandler::Disconnect}\label{wxevthandlerdisconnect}
106
107 \func{bool}{Disconnect}{\param{int}{ id},
108 \param{wxEventType }{eventType = wxEVT\_NULL}, \param{wxObjectEventFunction}{ function = NULL},
109 \param{wxObject*}{ userData = NULL}, \param{wxEvtHandler*}{ eventSink = NULL}}
110
111 \func{bool}{Disconnect}{\param{int}{ id}, \param{int}{ lastId = -1},
112 \param{wxEventType }{eventType = wxEVT\_NULL}, \param{wxObjectEventFunction}{ function = NULL},
113 \param{wxObject*}{ userData = NULL}, \param{wxEvtHandler*}{ eventSink = NULL}}
114
115 Disconnects the given function dynamically from the event handler, using the specified
116 parameters as search criteria and returning true if a matching function has been
117 found and removed. This method can only disconnect functions which have been added
118 using the \helpref{wxEvtHandler::Connect}{wxevthandlerconnect} method. There is no way
119 to disconnect functions connected using the (static) event tables.
120
121 \wxheading{Parameters}
122
123 \docparam{id}{The identifier (or first of the identifier range) associated with the event handler function.}
124
125 \docparam{lastId}{The second part of the identifier range associated with the event handler function.}
126
127 \docparam{eventType}{The event type associated with this event handler.}
128
129 \docparam{function}{The event handler function.}
130
131 \docparam{userData}{Data associated with the event table entry.}
132
133 \docparam{eventSink}{Object whose member function should be called.}
134
135 \membersection{wxEvtHandler::GetClientData}\label{wxevthandlergetclientdata}
136
137 \func{void* }{GetClientData}{\void}
138
139 Gets user-supplied client data.
140
141 \wxheading{Remarks}
142
143 Normally, any extra data the programmer wishes to associate with the object
144 should be made available by deriving a new class with new data members.
145
146 \wxheading{See also}
147
148 \helpref{wxEvtHandler::SetClientData}{wxevthandlersetclientdata}
149
150 \membersection{wxEvtHandler::GetClientObject}\label{wxevthandlergetclientobject}
151
152 \constfunc{wxClientData*}{GetClientObject}{\void}
153
154 Get a pointer to the user-supplied client data object.
155
156 \wxheading{See also}
157
158 \helpref{wxEvtHandler::SetClientObject}{wxevthandlersetclientobject},
159 \helpref{wxClientData}{wxclientdata}
160
161 \membersection{wxEvtHandler::GetEvtHandlerEnabled}\label{wxevthandlergetevthandlerenabled}
162
163 \func{bool}{GetEvtHandlerEnabled}{\void}
164
165 Returns true if the event handler is enabled, false otherwise.
166
167 \wxheading{See also}
168
169 \helpref{wxEvtHandler::SetEvtHandlerEnabled}{wxevthandlersetevthandlerenabled}
170
171 \membersection{wxEvtHandler::GetNextHandler}\label{wxevthandlergetnexthandler}
172
173 \func{wxEvtHandler*}{GetNextHandler}{\void}
174
175 Gets the pointer to the next handler in the chain.
176
177 \wxheading{See also}
178
179 \helpref{wxEvtHandler::SetNextHandler}{wxevthandlersetnexthandler},\rtfsp
180 \helpref{wxEvtHandler::GetPreviousHandler}{wxevthandlergetprevioushandler},\rtfsp
181 \helpref{wxEvtHandler::SetPreviousHandler}{wxevthandlersetprevioushandler},\rtfsp
182 \helpref{wxWindow::PushEventHandler}{wxwindowpusheventhandler},\rtfsp
183 \helpref{wxWindow::PopEventHandler}{wxwindowpopeventhandler}
184
185 \membersection{wxEvtHandler::GetPreviousHandler}\label{wxevthandlergetprevioushandler}
186
187 \func{wxEvtHandler*}{GetPreviousHandler}{\void}
188
189 Gets the pointer to the previous handler in the chain.
190
191 \wxheading{See also}
192
193 \helpref{wxEvtHandler::SetPreviousHandler}{wxevthandlersetprevioushandler},\rtfsp
194 \helpref{wxEvtHandler::GetNextHandler}{wxevthandlergetnexthandler},\rtfsp
195 \helpref{wxEvtHandler::SetNextHandler}{wxevthandlersetnexthandler},\rtfsp
196 \helpref{wxWindow::PushEventHandler}{wxwindowpusheventhandler},\rtfsp
197 \helpref{wxWindow::PopEventHandler}{wxwindowpopeventhandler}
198
199 \membersection{wxEvtHandler::ProcessEvent}\label{wxevthandlerprocessevent}
200
201 \func{virtual bool}{ProcessEvent}{\param{wxEvent\& }{event}}
202
203 Processes an event, searching event tables and calling zero or more suitable event handler function(s).
204
205 \wxheading{Parameters}
206
207 \docparam{event}{Event to process.}
208
209 \wxheading{Return value}
210
211 true if a suitable event handler function was found and executed, and the function did not
212 call \helpref{wxEvent::Skip}{wxeventskip}.
213
214 \wxheading{Remarks}
215
216 Normally, your application would not call this function: it is called in the wxWindows
217 implementation to dispatch incoming user interface events to the framework (and application).
218
219 However, you might need to call it if implementing new functionality (such as a new control) where
220 you define new event types, as opposed to allowing the user to override virtual functions.
221
222 An instance where you might actually override the {\bf ProcessEvent} function is where you want
223 to direct event processing to event handlers not normally noticed by wxWindows. For example,
224 in the document/view architecture, documents and views are potential event handlers.
225 When an event reaches a frame, {\bf ProcessEvent} will need to be called on the associated
226 document and view in case event handler functions are associated with these objects.
227 The property classes library (wxProperty) also overrides {\bf ProcessEvent} for similar reasons.
228
229 The normal order of event table searching is as follows:
230
231 \begin{enumerate}\itemsep=0pt
232 \item If the object is disabled (via a call to \helpref{wxEvtHandler::SetEvtHandlerEnabled}{wxevthandlersetevthandlerenabled})
233 the function skips to step (6).
234 \item If the object is a wxWindow, {\bf ProcessEvent} is recursively called on the window's\rtfsp
235 \helpref{wxValidator}{wxvalidator}. If this returns true, the function exits.
236 \item {\bf SearchEventTable} is called for this event handler. If this fails, the base
237 class table is tried, and so on until no more tables exist or an appropriate function was found,
238 in which case the function exits.
239 \item The search is applied down the entire chain of event handlers (usually the chain has a length
240 of one). If this succeeds, the function exits.
241 \item If the object is a wxWindow and the event is a wxCommandEvent, {\bf ProcessEvent} is
242 recursively applied to the parent window's event handler. If this returns true, the function exits.
243 \item Finally, {\bf ProcessEvent} is called on the wxApp object.
244 \end{enumerate}
245
246 \wxheading{See also}
247
248 \helpref{wxEvtHandler::SearchEventTable}{wxevthandlersearcheventtable}
249
250 \membersection{wxEvtHandler::SearchEventTable}\label{wxevthandlersearcheventtable}
251
252 \func{bool}{SearchEventTable}{\param{wxEventTable\& }{table}, \param{wxEvent\& }{event}}
253
254 Searches the event table, executing an event handler function if an appropriate one
255 is found.
256
257 \wxheading{Parameters}
258
259 \docparam{table}{Event table to be searched.}
260
261 \docparam{event}{Event to be matched against an event table entry.}
262
263 \wxheading{Return value}
264
265 true if a suitable event handler function was found and executed, and the function did not
266 call \helpref{wxEvent::Skip}{wxeventskip}.
267
268 \wxheading{Remarks}
269
270 This function looks through the object's event table and tries to find an entry
271 that will match the event.
272
273 An entry will match if:
274
275 \begin{enumerate}\itemsep=0pt
276 \item The event type matches, and
277 \item the identifier or identifier range matches, or the event table entry's identifier is zero.
278 \end{enumerate}
279
280 If a suitable function is called but calls \helpref{wxEvent::Skip}{wxeventskip}, this function will
281 fail, and searching will continue.
282
283 \wxheading{See also}
284
285 \helpref{wxEvtHandler::ProcessEvent}{wxevthandlerprocessevent}
286
287 \membersection{wxEvtHandler::SetClientData}\label{wxevthandlersetclientdata}
288
289 \func{void}{SetClientData}{\param{void* }{data}}
290
291 Sets user-supplied client data.
292
293 \wxheading{Parameters}
294
295 \docparam{data}{Data to be associated with the event handler.}
296
297 \wxheading{Remarks}
298
299 Normally, any extra data the programmer wishes to associate with
300 the object should be made available by deriving a new class
301 with new data members. You must not call this method and
302 \helpref{SetClientObject}{wxevthandlersetclientobject} on the
303 same class - only one of them.
304
305 \wxheading{See also}
306
307 \helpref{wxEvtHandler::GetClientData}{wxevthandlergetclientdata}
308
309 \membersection{wxEvtHandler::SetClientObject}\label{wxevthandlersetclientobject}
310
311 \func{void}{SetClientObject}{\param{wxClientData* }{data}}
312
313 Set the client data object. Any previous object will be deleted.
314
315 \wxheading{See also}
316
317 \helpref{wxEvtHandler::GetClientObject}{wxevthandlergetclientobject},
318 \helpref{wxClientData}{wxclientdata}
319
320 \membersection{wxEvtHandler::SetEvtHandlerEnabled}\label{wxevthandlersetevthandlerenabled}
321
322 \func{void}{SetEvtHandlerEnabled}{\param{bool }{enabled}}
323
324 Enables or disables the event handler.
325
326 \wxheading{Parameters}
327
328 \docparam{enabled}{true if the event handler is to be enabled, false if it is to be disabled.}
329
330 \wxheading{Remarks}
331
332 You can use this function to avoid having to remove the event handler from the chain, for example
333 when implementing a dialog editor and changing from edit to test mode.
334
335 \wxheading{See also}
336
337 \helpref{wxEvtHandler::GetEvtHandlerEnabled}{wxevthandlergetevthandlerenabled}
338
339 \membersection{wxEvtHandler::SetNextHandler}\label{wxevthandlersetnexthandler}
340
341 \func{void}{SetNextHandler}{\param{wxEvtHandler* }{handler}}
342
343 Sets the pointer to the next handler.
344
345 \wxheading{Parameters}
346
347 \docparam{handler}{Event handler to be set as the next handler.}
348
349 \wxheading{See also}
350
351 \helpref{wxEvtHandler::GetNextHandler}{wxevthandlergetnexthandler},\rtfsp
352 \helpref{wxEvtHandler::SetPreviousHandler}{wxevthandlersetprevioushandler},\rtfsp
353 \helpref{wxEvtHandler::GetPreviousHandler}{wxevthandlergetprevioushandler},\rtfsp
354 \helpref{wxWindow::PushEventHandler}{wxwindowpusheventhandler},\rtfsp
355 \helpref{wxWindow::PopEventHandler}{wxwindowpopeventhandler}
356
357 \membersection{wxEvtHandler::SetPreviousHandler}\label{wxevthandlersetprevioushandler}
358
359 \func{void}{SetPreviousHandler}{\param{wxEvtHandler* }{handler}}
360
361 Sets the pointer to the previous handler.
362
363 \wxheading{Parameters}
364
365 \docparam{handler}{Event handler to be set as the previous handler.}
366
367 \wxheading{See also}
368
369 \helpref{wxEvtHandler::GetPreviousHandler}{wxevthandlergetprevioushandler},\rtfsp
370 \helpref{wxEvtHandler::SetNextHandler}{wxevthandlersetnexthandler},\rtfsp
371 \helpref{wxEvtHandler::GetNextHandler}{wxevthandlergetnexthandler},\rtfsp
372 \helpref{wxWindow::PushEventHandler}{wxwindowpusheventhandler},\rtfsp
373 \helpref{wxWindow::PopEventHandler}{wxwindowpopeventhandler}
374
375