]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/evthand.tex
don't call wxYield() from EnsureVisible(), this is too dangerous - and unnecessary...
[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
39Adds an event to be processed later. The function will return immediately and the
fa482912 40event will get processed in idle time using the \helpref{wxEvtHandler::ProcessEvent}{wxevthandlerprocessevent}
8a293590
RR
41method.
42
43\wxheading{Parameters}
44
45\docparam{event}{Event to add to process queue.}
46
47\wxheading{Remarks}
48
cd4915e2
VZ
49Note that this requires that the event implements
50\helpref{CopyObject}{wxobjectcopyobject}
ccaaf5b0 51method so that the event can be duplicated and stored until it gets processed later.
cd4915e2 52Not all events in wxWindows currently fully implement this method,
ccaaf5b0 53so you may have to look at the source to verify this.
8a293590
RR
54
55This methods automatically wakes up idle handling even if the underlying window
56system is currently idle anyway and thus would not send any idle events. (Waking
57up the idle handling is done calling \helpref{::wxWakeUpIdle}{wxwakeupidle}.)
58
ccaaf5b0
RR
59This is also the method to call for inter-thread communication. In
60a multi-threaded program, you will often have to inform the main GUI thread
8a293590
RR
61about the status of other working threads and this has to be done using this
62method - which also means that this method is thread safe by means of using
63crtical sections where needed.
64
cd4915e2 65% VZ: bad idea IMHO - we're going to have a lot of problems with this
8a293590
RR
66Furthermore, it may be noted that some ports of wxWindows will probably move
67to using this method more and more in preference over calling ProcessEvent()
68directly so as to avoid problems with reentrant code.
69
f60d0f94
JS
70\membersection{wxEvtHandler::Connect}\label{wxevthandlerconnect}
71
72\func{void}{Connect}{\param{int}{ id},
73 \param{wxEventType }{eventType}, \param{wxObjectEventFunction}{ function},
74 \param{wxObject*}{ userData = NULL}}
75
76\func{void}{Connect}{\param{int}{ id}, \param{int}{ lastId},
77 \param{wxEventType }{eventType}, \param{wxObjectEventFunction}{ function},
78 \param{wxObject*}{ userData = NULL}}
79
80Connects the given function dynamically with the event handler, id and event type. This
81is an alternative to the use of static event tables. See the 'dynamic' sample for usage.
82
83\wxheading{Parameters}
84
85\docparam{id}{The identifier (or first of the identifier range) to be associated with the event handler function.}
86
87\docparam{lastId}{The second part of the identifier range to be associated with the event handler function.}
88
89\docparam{eventType}{The event type to be associated with this event handler.}
90
91\docparam{function}{The event handler function.}
92
93\docparam{userData}{Data to be associated with the event table entry.}
94
95\wxheading{Example}
96
97\begin{verbatim}
98 frame->Connect( wxID_EXIT,
99 wxEVT_COMMAND_MENU_SELECTED,
100 (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) MyFrame::OnQuit );
101\end{verbatim}
102
8a293590
RR
103\membersection{wxEvtHandler::Disconnect}\label{wxevthandlerdisconnect}
104
105\func{bool}{Disconnect}{\param{int}{ id},
605d715d 106 \param{wxEventType }{eventType = wxEVT\_NULL}, \param{wxObjectEventFunction}{ function = NULL},
8a293590
RR
107 \param{wxObject*}{ userData = NULL}}
108
109\func{bool}{Disconnect}{\param{int}{ id}, \param{int}{ lastId = -1},
605d715d 110 \param{wxEventType }{eventType = wxEVT\_NULL}, \param{wxObjectEventFunction}{ function = NULL},
8a293590 111 \param{wxObject*}{ userData = NULL}}
a660d684 112
8a293590 113Disconnects the given function dynamically from the event handler, using the specified
ccaaf5b0
RR
114parameters as search criteria and returning TRUE if a matching function has been
115found and removed. This method can only disconnect functions which have been added
8a293590 116using the \helpref{wxEvtHandler::Connect}{wxevthandlerconnect} method. There is no way
ccaaf5b0 117to disconnect functions connected using the (static) event tables.
a660d684 118
8a293590 119\wxheading{Parameters}
a660d684 120
8a293590 121\docparam{id}{The identifier (or first of the identifier range) associated with the event handler function.}
a660d684 122
8a293590 123\docparam{lastId}{The second part of the identifier range associated with the event handler function.}
a660d684 124
8a293590 125\docparam{eventType}{The event type associated with this event handler.}
a660d684 126
8a293590 127\docparam{function}{The event handler function.}
a660d684 128
ccaaf5b0 129\docparam{userData}{Data associated with the event table entry.}
a660d684
KB
130
131\membersection{wxEvtHandler::GetClientData}\label{wxevthandlergetclientdata}
132
ccaaf5b0 133\func{void* }{GetClientData}{\void}
a660d684
KB
134
135Gets user-supplied client data.
136
137\wxheading{Remarks}
138
139Normally, any extra data the programmer wishes to associate with the object
ccaaf5b0 140should be made available by deriving a new class with new data members.
a660d684
KB
141
142\wxheading{See also}
143
144\helpref{wxEvtHandler::SetClientData}{wxevthandlersetclientdata}
145
146\membersection{wxEvtHandler::GetEvtHandlerEnabled}\label{wxevthandlergetevthandlerenabled}
147
148\func{bool}{GetEvtHandlerEnabled}{\void}
149
150Returns TRUE if the event handler is enabled, FALSE otherwise.
151
152\wxheading{See also}
153
154\helpref{wxEvtHandler::SetEvtHandlerEnabled}{wxevthandlersetevthandlerenabled}
155
156\membersection{wxEvtHandler::GetNextHandler}\label{wxevthandlergetnexthandler}
157
158\func{wxEvtHandler*}{GetNextHandler}{\void}
159
160Gets the pointer to the next handler in the chain.
161
162\wxheading{See also}
163
b4a2ab72 164\helpref{wxEvtHandler::SetNextHandler}{wxevthandlersetnexthandler},\rtfsp
a660d684
KB
165\helpref{wxEvtHandler::GetPreviousHandler}{wxevthandlergetprevioushandler},\rtfsp
166\helpref{wxEvtHandler::SetPreviousHandler}{wxevthandlersetprevioushandler},\rtfsp
a660d684
KB
167\helpref{wxWindow::PushEventHandler}{wxwindowpusheventhandler},\rtfsp
168\helpref{wxWindow::PopEventHandler}{wxwindowpopeventhandler}
169
170\membersection{wxEvtHandler::GetPreviousHandler}\label{wxevthandlergetprevioushandler}
171
172\func{wxEvtHandler*}{GetPreviousHandler}{\void}
173
174Gets the pointer to the previous handler in the chain.
175
176\wxheading{See also}
177
a660d684 178\helpref{wxEvtHandler::SetPreviousHandler}{wxevthandlersetprevioushandler},\rtfsp
b4a2ab72
SB
179\helpref{wxEvtHandler::GetNextHandler}{wxevthandlergetnexthandler},\rtfsp
180\helpref{wxEvtHandler::SetNextHandler}{wxevthandlersetnexthandler},\rtfsp
a660d684
KB
181\helpref{wxWindow::PushEventHandler}{wxwindowpusheventhandler},\rtfsp
182\helpref{wxWindow::PopEventHandler}{wxwindowpopeventhandler}
183
184\membersection{wxEvtHandler::ProcessEvent}\label{wxevthandlerprocessevent}
185
186\func{virtual bool}{ProcessEvent}{\param{wxEvent\& }{event}}
187
188Processes an event, searching event tables and calling zero or more suitable event handler function(s).
189
190\wxheading{Parameters}
191
192\docparam{event}{Event to process.}
193
194\wxheading{Return value}
195
196TRUE if a suitable event handler function was found and executed, and the function did not
197call \helpref{wxEvent::Skip}{wxeventskip}.
198
199\wxheading{Remarks}
200
201Normally, your application would not call this function: it is called in the wxWindows
202implementation to dispatch incoming user interface events to the framework (and application).
203
204However, you might need to call it if implementing new functionality (such as a new control) where
205you define new event types, as opposed to allowing the user to override virtual functions.
206
207An instance where you might actually override the {\bf ProcessEvent} function is where you want
208to direct event processing to event handlers not normally noticed by wxWindows. For example,
209in the document/view architecture, documents and views are potential event handlers.
210When an event reaches a frame, {\bf ProcessEvent} will need to be called on the associated
211document and view in case event handler functions are associated with these objects.
212The property classes library (wxProperty) also overrides {\bf ProcessEvent} for similar reasons.
213
214The normal order of event table searching is as follows:
215
216\begin{enumerate}\itemsep=0pt
217\item If the object is disabled (via a call to \helpref{wxEvtHandler::SetEvtHandlerEnabled}{wxevthandlersetevthandlerenabled})
218the function skips to step (6).
219\item If the object is a wxWindow, {\bf ProcessEvent} is recursively called on the window's\rtfsp
220\helpref{wxValidator}{wxvalidator}. If this returns TRUE, the function exits.
221\item {\bf SearchEventTable} is called for this event handler. If this fails, the base
222class table is tried, and so on until no more tables exist or an appropriate function was found,
223in which case the function exits.
224\item The search is applied down the entire chain of event handlers (usually the chain has a length
225of one). If this succeeds, the function exits.
226\item If the object is a wxWindow and the event is a wxCommandEvent, {\bf ProcessEvent} is
227recursively applied to the parent window's event handler. If this returns TRUE, the function exits.
228\item Finally, {\bf ProcessEvent} is called on the wxApp object.
229\end{enumerate}
230
231\wxheading{See also}
232
233\helpref{wxEvtHandler::SearchEventTable}{wxevthandlersearcheventtable}
234
235\membersection{wxEvtHandler::SearchEventTable}\label{wxevthandlersearcheventtable}
236
237\func{bool}{SearchEventTable}{\param{wxEventTable\& }{table}, \param{wxEvent\& }{event}}
238
239Searches the event table, executing an event handler function if an appropriate one
240is found.
241
242\wxheading{Parameters}
243
244\docparam{table}{Event table to be searched.}
245
246\docparam{event}{Event to be matched against an event table entry.}
247
248\wxheading{Return value}
249
250TRUE if a suitable event handler function was found and executed, and the function did not
251call \helpref{wxEvent::Skip}{wxeventskip}.
252
253\wxheading{Remarks}
254
255This function looks through the object's event table and tries to find an entry
256that will match the event.
257
258An entry will match if:
259
260\begin{enumerate}\itemsep=0pt
261\item The event type matches, and
262\item the identifier or identifier range matches, or the event table entry's identifier is zero.
263\end{enumerate}
264
265If a suitable function is called but calls \helpref{wxEvent::Skip}{wxeventskip}, this function will
266fail, and searching will continue.
267
268\wxheading{See also}
269
270\helpref{wxEvtHandler::ProcessEvent}{wxevthandlerprocessevent}
271
272\membersection{wxEvtHandler::SetClientData}\label{wxevthandlersetclientdata}
273
ccaaf5b0 274\func{void}{SetClientData}{\param{void* }{data}}
a660d684
KB
275
276Sets user-supplied client data.
277
278\wxheading{Parameters}
279
280\docparam{data}{Data to be associated with the event handler.}
281
282\wxheading{Remarks}
283
ccaaf5b0
RR
284Normally, any extra data the programmer wishes to associate with
285the object should be made available by deriving a new class
a660d684 286with new data members.
a660d684
KB
287
288\wxheading{See also}
289
290\helpref{wxEvtHandler::GetClientData}{wxevthandlergetclientdata}
291
292\membersection{wxEvtHandler::SetEvtHandlerEnabled}\label{wxevthandlersetevthandlerenabled}
293
294\func{void}{SetEvtHandlerEnabled}{\param{bool }{enabled}}
295
296Enables or disables the event handler.
297
298\wxheading{Parameters}
299
300\docparam{enabled}{TRUE if the event handler is to be enabled, FALSE if it is to be disabled.}
301
302\wxheading{Remarks}
303
304You can use this function to avoid having to remove the event handler from the chain, for example
305when implementing a dialog editor and changing from edit to test mode.
306
307\wxheading{See also}
308
309\helpref{wxEvtHandler::GetEvtHandlerEnabled}{wxevthandlergetevthandlerenabled}
310
311\membersection{wxEvtHandler::SetNextHandler}\label{wxevthandlersetnexthandler}
312
313\func{void}{SetNextHandler}{\param{wxEvtHandler* }{handler}}
314
315Sets the pointer to the next handler.
316
317\wxheading{Parameters}
318
319\docparam{handler}{Event handler to be set as the next handler.}
320
321\wxheading{See also}
322
323\helpref{wxEvtHandler::GetNextHandler}{wxevthandlergetnexthandler},\rtfsp
324\helpref{wxEvtHandler::SetPreviousHandler}{wxevthandlersetprevioushandler},\rtfsp
325\helpref{wxEvtHandler::GetPreviousHandler}{wxevthandlergetprevioushandler},\rtfsp
326\helpref{wxWindow::PushEventHandler}{wxwindowpusheventhandler},\rtfsp
327\helpref{wxWindow::PopEventHandler}{wxwindowpopeventhandler}
328
329\membersection{wxEvtHandler::SetPreviousHandler}\label{wxevthandlersetprevioushandler}
330
331\func{void}{SetPreviousHandler}{\param{wxEvtHandler* }{handler}}
332
333Sets the pointer to the previous handler.
334
335\wxheading{Parameters}
336
337\docparam{handler}{Event handler to be set as the previous handler.}
338
339\wxheading{See also}
340
341\helpref{wxEvtHandler::GetPreviousHandler}{wxevthandlergetprevioushandler},\rtfsp
342\helpref{wxEvtHandler::SetNextHandler}{wxevthandlersetnexthandler},\rtfsp
343\helpref{wxEvtHandler::GetNextHandler}{wxevthandlergetnexthandler},\rtfsp
344\helpref{wxWindow::PushEventHandler}{wxwindowpusheventhandler},\rtfsp
345\helpref{wxWindow::PopEventHandler}{wxwindowpopeventhandler}
346
347