]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/evthand.tex
Document EVT_TREE_STATE_IMAGE_CLICK (Windows only)
[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
a685e84a
DE
7When events are received, wxEvtHandler invokes the method listed in the
8event table using itself as the object. When using multiple inheritance
9it is imperative that the wxEvtHandler(-derived) class be the first
10class inherited such that the "this" pointer for the overall object
11will 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
31Constructor.
32
b236c10f 33\membersection{wxEvtHandler::\destruct{wxEvtHandler}}\label{wxevthandlerdtor}
a660d684
KB
34
35\func{}{\destruct{wxEvtHandler}}{\void}
36
37Destructor. If the handler is part of a chain, the destructor will
38unlink itself and restore the previous and next handlers so that they point to
39each other.
40
8a293590
RR
41\membersection{wxEvtHandler::AddPendingEvent}\label{wxevthandleraddpendingevent}
42
06d4e3c2 43\func{void}{AddPendingEvent}{\param{wxEvent\& }{event}}
8a293590 44
8e72b8b5 45This 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
53The difference between sending an event (using the
54\helpref{ProcessEvent}{wxevthandlerprocessevent} method) and posting it is
55that in the first case the event is processed before the function returns,
56while in the second case, the function returns immediately and the event will
57be processed sometime later (usually during the next event loop iteration).
58
59A copy of {\it event} is made by the function, so the original can be deleted
60as soon as function returns (it is common that the original is created on the
61stack). This requires that the \helpref{wxEvent::Clone}{wxeventclone} method
62be implemented by {\it event} so that it can be duplicated and stored until
63it gets processed.
64
65This is also the method to call for inter-thread communication---it will
66post events safely between different threads which means that this method is
67thread-safe by using critical sections where needed. In a multi-threaded
68program, you often need to inform the main GUI thread about the status of
69other working threads and such notification should be done using this method.
70
71This method automatically wakes up idle handling if the underlying window
72system is currently idle and thus would not send any idle events. (Waking
73up 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 88Connects the given function dynamically with the event handler, id and event type. This
f70c0443 89is 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
94associated with the event handler function. For the version not taking this
95argument, 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
102be explicitly converted to the correct type which can be done using a macro
103called \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,
119lastid, type, method}; if \texttt{method} is \texttt{undef}, the
120handler is disconnected.}
121
8a293590
RR
122\membersection{wxEvtHandler::Disconnect}\label{wxevthandlerdisconnect}
123
bdbe28fa
VZ
124\func{bool}{Disconnect}{\param{wxEventType }{eventType = wxEVT\_NULL}, \param{wxObjectEventFunction}{ function = NULL},
125 \param{wxObject*}{ userData = NULL}, \param{wxEvtHandler*}{ eventSink = NULL}}
126
e554d626 127\func{bool}{Disconnect}{\param{int}{ id = \texttt{wxID\_ANY}},
605d715d 128 \param{wxEventType }{eventType = wxEVT\_NULL}, \param{wxObjectEventFunction}{ function = NULL},
97e1d37c 129 \param{wxObject*}{ userData = NULL}, \param{wxEvtHandler*}{ eventSink = NULL}}
8a293590 130
e554d626 131\func{bool}{Disconnect}{\param{int}{ id}, \param{int}{ lastId = \texttt{wxID\_ANY}},
605d715d 132 \param{wxEventType }{eventType = wxEVT\_NULL}, \param{wxObjectEventFunction}{ function = NULL},
97e1d37c 133 \param{wxObject*}{ userData = NULL}, \param{wxEvtHandler*}{ eventSink = NULL}}
a660d684 134
8a293590 135Disconnects the given function dynamically from the event handler, using the specified
cc81d32f 136parameters as search criteria and returning true if a matching function has been
ccaaf5b0 137found and removed. This method can only disconnect functions which have been added
8a293590 138using the \helpref{wxEvtHandler::Connect}{wxevthandlerconnect} method. There is no way
ccaaf5b0 139to disconnect functions connected using the (static) event tables.
a660d684 140
8a293590 141\wxheading{Parameters}
a660d684 142
8a293590 143\docparam{id}{The identifier (or first of the identifier range) associated with the event handler function.}
a660d684 144
8a293590 145\docparam{lastId}{The second part of the identifier range associated with the event handler function.}
a660d684 146
8a293590 147\docparam{eventType}{The event type associated with this event handler.}
a660d684 148
8a293590 149\docparam{function}{The event handler function.}
a660d684 150
ccaaf5b0 151\docparam{userData}{Data associated with the event table entry.}
a660d684 152
97e1d37c
JS
153\docparam{eventSink}{Object whose member function should be called.}
154
2bbd97f4
MB
155\perlnote{In wxPerl this function takes 3 arguments: \texttt{id,
156lastid, type}.}
157
924b84ab
VS
158\membersection{wxEvtHandler::DoHandleEvent}\label{wxevthandlerdohandleevent}
159
160\func{virtual void}{DoHandleEvent}{\param{wxEventFunction}{ func}, \param{wxEvent\& }{event}}
161
162This function simply invokes the given method \arg{func} of this
163event handler with the \arg{event} as parameter. It exists solely
164to allow to catch the C++ exceptions which could be thrown by this event
165handlers in one place: if you want to do this, override this
166function in your wxEvtHandler-derived class and add try/catch clause(s) to it.
167
168Exceptions not caught at this level propagate to
169\helpref{wxApp::HandleEvent}{wxapphandleevent} which in turn calls
170\helpref{wxApp::OnExceptionInMainLoop}{wxapponexceptioninmainloop}.
171
a660d684
KB
172\membersection{wxEvtHandler::GetClientData}\label{wxevthandlergetclientdata}
173
ccaaf5b0 174\func{void* }{GetClientData}{\void}
a660d684
KB
175
176Gets user-supplied client data.
177
178\wxheading{Remarks}
179
180Normally, any extra data the programmer wishes to associate with the object
ccaaf5b0 181should be made available by deriving a new class with new data members.
a660d684
KB
182
183\wxheading{See also}
184
185\helpref{wxEvtHandler::SetClientData}{wxevthandlersetclientdata}
186
e3ba9f88
RR
187\membersection{wxEvtHandler::GetClientObject}\label{wxevthandlergetclientobject}
188
189\constfunc{wxClientData*}{GetClientObject}{\void}
190
191Get a pointer to the user-supplied client data object.
192
193\wxheading{See also}
194
195\helpref{wxEvtHandler::SetClientObject}{wxevthandlersetclientobject},
196\helpref{wxClientData}{wxclientdata}
197
a660d684
KB
198\membersection{wxEvtHandler::GetEvtHandlerEnabled}\label{wxevthandlergetevthandlerenabled}
199
200\func{bool}{GetEvtHandlerEnabled}{\void}
201
cc81d32f 202Returns true if the event handler is enabled, false otherwise.
a660d684
KB
203
204\wxheading{See also}
205
206\helpref{wxEvtHandler::SetEvtHandlerEnabled}{wxevthandlersetevthandlerenabled}
207
208\membersection{wxEvtHandler::GetNextHandler}\label{wxevthandlergetnexthandler}
209
210\func{wxEvtHandler*}{GetNextHandler}{\void}
211
212Gets the pointer to the next handler in the chain.
213
214\wxheading{See also}
215
b4a2ab72 216\helpref{wxEvtHandler::SetNextHandler}{wxevthandlersetnexthandler},\rtfsp
a660d684
KB
217\helpref{wxEvtHandler::GetPreviousHandler}{wxevthandlergetprevioushandler},\rtfsp
218\helpref{wxEvtHandler::SetPreviousHandler}{wxevthandlersetprevioushandler},\rtfsp
a660d684
KB
219\helpref{wxWindow::PushEventHandler}{wxwindowpusheventhandler},\rtfsp
220\helpref{wxWindow::PopEventHandler}{wxwindowpopeventhandler}
221
222\membersection{wxEvtHandler::GetPreviousHandler}\label{wxevthandlergetprevioushandler}
223
224\func{wxEvtHandler*}{GetPreviousHandler}{\void}
225
226Gets the pointer to the previous handler in the chain.
227
228\wxheading{See also}
229
a660d684 230\helpref{wxEvtHandler::SetPreviousHandler}{wxevthandlersetprevioushandler},\rtfsp
b4a2ab72
SB
231\helpref{wxEvtHandler::GetNextHandler}{wxevthandlergetnexthandler},\rtfsp
232\helpref{wxEvtHandler::SetNextHandler}{wxevthandlersetnexthandler},\rtfsp
a660d684
KB
233\helpref{wxWindow::PushEventHandler}{wxwindowpusheventhandler},\rtfsp
234\helpref{wxWindow::PopEventHandler}{wxwindowpopeventhandler}
235
236\membersection{wxEvtHandler::ProcessEvent}\label{wxevthandlerprocessevent}
237
238\func{virtual bool}{ProcessEvent}{\param{wxEvent\& }{event}}
239
240Processes an event, searching event tables and calling zero or more suitable event handler function(s).
241
242\wxheading{Parameters}
243
244\docparam{event}{Event to process.}
245
246\wxheading{Return value}
247
cc81d32f 248true if a suitable event handler function was found and executed, and the function did not
a660d684
KB
249call \helpref{wxEvent::Skip}{wxeventskip}.
250
251\wxheading{Remarks}
252
fc2171bd 253Normally, your application would not call this function: it is called in the wxWidgets
a660d684
KB
254implementation to dispatch incoming user interface events to the framework (and application).
255
256However, you might need to call it if implementing new functionality (such as a new control) where
257you define new event types, as opposed to allowing the user to override virtual functions.
258
259An instance where you might actually override the {\bf ProcessEvent} function is where you want
fc2171bd 260to direct event processing to event handlers not normally noticed by wxWidgets. For example,
a660d684
KB
261in the document/view architecture, documents and views are potential event handlers.
262When an event reaches a frame, {\bf ProcessEvent} will need to be called on the associated
263document and view in case event handler functions are associated with these objects.
264The property classes library (wxProperty) also overrides {\bf ProcessEvent} for similar reasons.
265
266The normal order of event table searching is as follows:
267
268\begin{enumerate}\itemsep=0pt
269\item If the object is disabled (via a call to \helpref{wxEvtHandler::SetEvtHandlerEnabled}{wxevthandlersetevthandlerenabled})
270the function skips to step (6).
271\item If the object is a wxWindow, {\bf ProcessEvent} is recursively called on the window's\rtfsp
cc81d32f 272\helpref{wxValidator}{wxvalidator}. If this returns true, the function exits.
a660d684
KB
273\item {\bf SearchEventTable} is called for this event handler. If this fails, the base
274class table is tried, and so on until no more tables exist or an appropriate function was found,
275in which case the function exits.
276\item The search is applied down the entire chain of event handlers (usually the chain has a length
277of one). If this succeeds, the function exits.
278\item If the object is a wxWindow and the event is a wxCommandEvent, {\bf ProcessEvent} is
cc81d32f 279recursively applied to the parent window's event handler. If this returns true, the function exits.
a660d684
KB
280\item Finally, {\bf ProcessEvent} is called on the wxApp object.
281\end{enumerate}
282
283\wxheading{See also}
284
285\helpref{wxEvtHandler::SearchEventTable}{wxevthandlersearcheventtable}
286
287\membersection{wxEvtHandler::SearchEventTable}\label{wxevthandlersearcheventtable}
288
4cee05ac 289\func{virtual bool}{SearchEventTable}{\param{wxEventTable\& }{table}, \param{wxEvent\& }{event}}
a660d684
KB
290
291Searches the event table, executing an event handler function if an appropriate one
292is found.
293
294\wxheading{Parameters}
295
296\docparam{table}{Event table to be searched.}
297
298\docparam{event}{Event to be matched against an event table entry.}
299
300\wxheading{Return value}
301
cc81d32f 302true if a suitable event handler function was found and executed, and the function did not
a660d684
KB
303call \helpref{wxEvent::Skip}{wxeventskip}.
304
305\wxheading{Remarks}
306
307This function looks through the object's event table and tries to find an entry
308that will match the event.
309
310An entry will match if:
311
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.
315\end{enumerate}
316
317If a suitable function is called but calls \helpref{wxEvent::Skip}{wxeventskip}, this function will
318fail, and searching will continue.
319
320\wxheading{See also}
321
322\helpref{wxEvtHandler::ProcessEvent}{wxevthandlerprocessevent}
323
324\membersection{wxEvtHandler::SetClientData}\label{wxevthandlersetclientdata}
325
ccaaf5b0 326\func{void}{SetClientData}{\param{void* }{data}}
a660d684
KB
327
328Sets user-supplied client data.
329
330\wxheading{Parameters}
331
332\docparam{data}{Data to be associated with the event handler.}
333
334\wxheading{Remarks}
335
ccaaf5b0
RR
336Normally, any extra data the programmer wishes to associate with
337the object should be made available by deriving a new class
e3ba9f88
RR
338with new data members. You must not call this method and
339\helpref{SetClientObject}{wxevthandlersetclientobject} on the
340same class - only one of them.
a660d684
KB
341
342\wxheading{See also}
343
344\helpref{wxEvtHandler::GetClientData}{wxevthandlergetclientdata}
345
e3ba9f88
RR
346\membersection{wxEvtHandler::SetClientObject}\label{wxevthandlersetclientobject}
347
348\func{void}{SetClientObject}{\param{wxClientData* }{data}}
349
350Set the client data object. Any previous object will be deleted.
351
352\wxheading{See also}
353
354\helpref{wxEvtHandler::GetClientObject}{wxevthandlergetclientobject},
355\helpref{wxClientData}{wxclientdata}
356
a660d684
KB
357\membersection{wxEvtHandler::SetEvtHandlerEnabled}\label{wxevthandlersetevthandlerenabled}
358
359\func{void}{SetEvtHandlerEnabled}{\param{bool }{enabled}}
360
361Enables or disables the event handler.
362
363\wxheading{Parameters}
364
cc81d32f 365\docparam{enabled}{true if the event handler is to be enabled, false if it is to be disabled.}
a660d684
KB
366
367\wxheading{Remarks}
368
369You can use this function to avoid having to remove the event handler from the chain, for example
370when implementing a dialog editor and changing from edit to test mode.
371
372\wxheading{See also}
373
374\helpref{wxEvtHandler::GetEvtHandlerEnabled}{wxevthandlergetevthandlerenabled}
375
376\membersection{wxEvtHandler::SetNextHandler}\label{wxevthandlersetnexthandler}
377
378\func{void}{SetNextHandler}{\param{wxEvtHandler* }{handler}}
379
380Sets the pointer to the next handler.
381
382\wxheading{Parameters}
383
384\docparam{handler}{Event handler to be set as the next handler.}
385
386\wxheading{See also}
387
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}
393
394\membersection{wxEvtHandler::SetPreviousHandler}\label{wxevthandlersetprevioushandler}
395
396\func{void}{SetPreviousHandler}{\param{wxEvtHandler* }{handler}}
397
398Sets the pointer to the previous handler.
399
400\wxheading{Parameters}
401
402\docparam{handler}{Event handler to be set as the previous handler.}
403
404\wxheading{See also}
405
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}
411
412