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