1 \section{\class{wxEvtHandler
}}\label{wxevthandler
}
3 A class that can handle events from the windowing system.
4 wxWindow (and therefore all window classes) are derived from
7 \wxheading{Derived from
}
9 \helpref{wxObject
}{wxobject
}
11 \wxheading{Include files
}
17 \overview{Event handling overview
}{eventhandlingoverview
}
19 \latexignore{\rtfignore{\wxheading{Members
}}}
21 \membersection{wxEvtHandler::wxEvtHandler
}
23 \func{}{wxEvtHandler
}{\void}
27 \membersection{wxEvtHandler::
\destruct{wxEvtHandler
}}
29 \func{}{\destruct{wxEvtHandler
}}{\void}
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
35 \membersection{wxEvtHandler::AddPendingEvent
}\label{wxevthandleraddpendingevent
}
37 \func{virtual void
}{AddPendingEvent
}{\param{wxEvent\&
}{event
}}
39 This function posts an event to be processed later.
41 \wxheading{Parameters
}
43 \docparam{event
}{Event to add to process queue.
}
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).
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
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.
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
}.)
69 \membersection{wxEvtHandler::Connect
}\label{wxevthandlerconnect
}
71 \func{void
}{Connect
}{\param{int
}{ id
},
72 \param{wxEventType
}{eventType
},
\param{wxObjectEventFunction
}{ function
},
73 \param{wxObject*
}{ userData = NULL
}}
75 \func{void
}{Connect
}{\param{int
}{ id
},
\param{int
}{ lastId
},
76 \param{wxEventType
}{eventType
},
\param{wxObjectEventFunction
}{ function
},
77 \param{wxObject*
}{ userData = NULL
}}
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.
82 \wxheading{Parameters
}
84 \docparam{id
}{The identifier (or first of the identifier range) to be associated with the event handler function.
}
86 \docparam{lastId
}{The second part of the identifier range to be associated with the event handler function.
}
88 \docparam{eventType
}{The event type to be associated with this event handler.
}
90 \docparam{function
}{The event handler function.
}
92 \docparam{userData
}{Data to be associated with the event table entry.
}
97 frame->Connect( wxID_EXIT,
98 wxEVT_COMMAND_MENU_SELECTED,
99 (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) MyFrame::OnQuit );
102 \membersection{wxEvtHandler::Disconnect
}\label{wxevthandlerdisconnect
}
104 \func{bool
}{Disconnect
}{\param{int
}{ id
},
105 \param{wxEventType
}{eventType = wxEVT
\_NULL},
\param{wxObjectEventFunction
}{ function = NULL
},
106 \param{wxObject*
}{ userData = NULL
}}
108 \func{bool
}{Disconnect
}{\param{int
}{ id
},
\param{int
}{ lastId = -
1},
109 \param{wxEventType
}{eventType = wxEVT
\_NULL},
\param{wxObjectEventFunction
}{ function = NULL
},
110 \param{wxObject*
}{ userData = NULL
}}
112 Disconnects the given function dynamically from the event handler, using the specified
113 parameters as search criteria and returning TRUE if a matching function has been
114 found and removed. This method can only disconnect functions which have been added
115 using the
\helpref{wxEvtHandler::Connect
}{wxevthandlerconnect
} method. There is no way
116 to disconnect functions connected using the (static) event tables.
118 \wxheading{Parameters
}
120 \docparam{id
}{The identifier (or first of the identifier range) associated with the event handler function.
}
122 \docparam{lastId
}{The second part of the identifier range associated with the event handler function.
}
124 \docparam{eventType
}{The event type associated with this event handler.
}
126 \docparam{function
}{The event handler function.
}
128 \docparam{userData
}{Data associated with the event table entry.
}
130 \membersection{wxEvtHandler::GetClientData
}\label{wxevthandlergetclientdata
}
132 \func{void*
}{GetClientData
}{\void}
134 Gets user-supplied client data.
138 Normally, any extra data the programmer wishes to associate with the object
139 should be made available by deriving a new class with new data members.
143 \helpref{wxEvtHandler::SetClientData
}{wxevthandlersetclientdata
}
145 \membersection{wxEvtHandler::GetClientObject
}\label{wxevthandlergetclientobject
}
147 \constfunc{wxClientData*
}{GetClientObject
}{\void}
149 Get a pointer to the user-supplied client data object.
153 \helpref{wxEvtHandler::SetClientObject
}{wxevthandlersetclientobject
},
154 \helpref{wxClientData
}{wxclientdata
}
156 \membersection{wxEvtHandler::GetEvtHandlerEnabled
}\label{wxevthandlergetevthandlerenabled
}
158 \func{bool
}{GetEvtHandlerEnabled
}{\void}
160 Returns TRUE if the event handler is enabled, FALSE otherwise.
164 \helpref{wxEvtHandler::SetEvtHandlerEnabled
}{wxevthandlersetevthandlerenabled
}
166 \membersection{wxEvtHandler::GetNextHandler
}\label{wxevthandlergetnexthandler
}
168 \func{wxEvtHandler*
}{GetNextHandler
}{\void}
170 Gets the pointer to the next handler in the chain.
174 \helpref{wxEvtHandler::SetNextHandler
}{wxevthandlersetnexthandler
},
\rtfsp
175 \helpref{wxEvtHandler::GetPreviousHandler
}{wxevthandlergetprevioushandler
},
\rtfsp
176 \helpref{wxEvtHandler::SetPreviousHandler
}{wxevthandlersetprevioushandler
},
\rtfsp
177 \helpref{wxWindow::PushEventHandler
}{wxwindowpusheventhandler
},
\rtfsp
178 \helpref{wxWindow::PopEventHandler
}{wxwindowpopeventhandler
}
180 \membersection{wxEvtHandler::GetPreviousHandler
}\label{wxevthandlergetprevioushandler
}
182 \func{wxEvtHandler*
}{GetPreviousHandler
}{\void}
184 Gets the pointer to the previous handler in the chain.
188 \helpref{wxEvtHandler::SetPreviousHandler
}{wxevthandlersetprevioushandler
},
\rtfsp
189 \helpref{wxEvtHandler::GetNextHandler
}{wxevthandlergetnexthandler
},
\rtfsp
190 \helpref{wxEvtHandler::SetNextHandler
}{wxevthandlersetnexthandler
},
\rtfsp
191 \helpref{wxWindow::PushEventHandler
}{wxwindowpusheventhandler
},
\rtfsp
192 \helpref{wxWindow::PopEventHandler
}{wxwindowpopeventhandler
}
194 \membersection{wxEvtHandler::ProcessEvent
}\label{wxevthandlerprocessevent
}
196 \func{virtual bool
}{ProcessEvent
}{\param{wxEvent\&
}{event
}}
198 Processes an event, searching event tables and calling zero or more suitable event handler function(s).
200 \wxheading{Parameters
}
202 \docparam{event
}{Event to process.
}
204 \wxheading{Return value
}
206 TRUE if a suitable event handler function was found and executed, and the function did not
207 call
\helpref{wxEvent::Skip
}{wxeventskip
}.
211 Normally, your application would not call this function: it is called in the wxWindows
212 implementation to dispatch incoming user interface events to the framework (and application).
214 However, you might need to call it if implementing new functionality (such as a new control) where
215 you define new event types, as opposed to allowing the user to override virtual functions.
217 An instance where you might actually override the
{\bf ProcessEvent
} function is where you want
218 to direct event processing to event handlers not normally noticed by wxWindows. For example,
219 in the
document/view architecture, documents and views are potential event handlers.
220 When an event reaches a frame,
{\bf ProcessEvent
} will need to be called on the associated
221 document and view in case event handler functions are associated with these objects.
222 The property classes library (wxProperty) also overrides
{\bf ProcessEvent
} for similar reasons.
224 The normal order of event table searching is as follows:
226 \begin{enumerate
}\itemsep=
0pt
227 \item If the object is disabled (via a call to
\helpref{wxEvtHandler::SetEvtHandlerEnabled
}{wxevthandlersetevthandlerenabled
})
228 the function skips to step (
6).
229 \item If the object is a wxWindow,
{\bf ProcessEvent
} is recursively called on the window's
\rtfsp
230 \helpref{wxValidator
}{wxvalidator
}. If this returns TRUE, the function exits.
231 \item {\bf SearchEventTable
} is called for this event handler. If this fails, the base
232 class table is tried, and so on until no more tables exist or an appropriate function was found,
233 in which case the function exits.
234 \item The search is applied down the entire chain of event handlers (usually the chain has a length
235 of one). If this succeeds, the function exits.
236 \item If the object is a wxWindow and the event is a wxCommandEvent,
{\bf ProcessEvent
} is
237 recursively applied to the parent window's event handler. If this returns TRUE, the function exits.
238 \item Finally,
{\bf ProcessEvent
} is called on the wxApp object.
243 \helpref{wxEvtHandler::SearchEventTable
}{wxevthandlersearcheventtable
}
245 \membersection{wxEvtHandler::SearchEventTable
}\label{wxevthandlersearcheventtable
}
247 \func{bool
}{SearchEventTable
}{\param{wxEventTable\&
}{table
},
\param{wxEvent\&
}{event
}}
249 Searches the event table, executing an event handler function if an appropriate one
252 \wxheading{Parameters
}
254 \docparam{table
}{Event table to be searched.
}
256 \docparam{event
}{Event to be matched against an event table entry.
}
258 \wxheading{Return value
}
260 TRUE if a suitable event handler function was found and executed, and the function did not
261 call
\helpref{wxEvent::Skip
}{wxeventskip
}.
265 This function looks through the object's event table and tries to find an entry
266 that will match the event.
268 An entry will match if:
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.
275 If a suitable function is called but calls
\helpref{wxEvent::Skip
}{wxeventskip
}, this function will
276 fail, and searching will continue.
280 \helpref{wxEvtHandler::ProcessEvent
}{wxevthandlerprocessevent
}
282 \membersection{wxEvtHandler::SetClientData
}\label{wxevthandlersetclientdata
}
284 \func{void
}{SetClientData
}{\param{void*
}{data
}}
286 Sets user-supplied client data.
288 \wxheading{Parameters
}
290 \docparam{data
}{Data to be associated with the event handler.
}
294 Normally, any extra data the programmer wishes to associate with
295 the object should be made available by deriving a new class
296 with new data members. You must not call this method and
297 \helpref{SetClientObject
}{wxevthandlersetclientobject
} on the
298 same class - only one of them.
302 \helpref{wxEvtHandler::GetClientData
}{wxevthandlergetclientdata
}
304 \membersection{wxEvtHandler::SetClientObject
}\label{wxevthandlersetclientobject
}
306 \func{void
}{SetClientObject
}{\param{wxClientData*
}{data
}}
308 Set the client data object. Any previous object will be deleted.
312 \helpref{wxEvtHandler::GetClientObject
}{wxevthandlergetclientobject
},
313 \helpref{wxClientData
}{wxclientdata
}
315 \membersection{wxEvtHandler::SetEvtHandlerEnabled
}\label{wxevthandlersetevthandlerenabled
}
317 \func{void
}{SetEvtHandlerEnabled
}{\param{bool
}{enabled
}}
319 Enables or disables the event handler.
321 \wxheading{Parameters
}
323 \docparam{enabled
}{TRUE if the event handler is to be enabled, FALSE if it is to be disabled.
}
327 You can use this function to avoid having to remove the event handler from the chain, for example
328 when implementing a dialog editor and changing from edit to test mode.
332 \helpref{wxEvtHandler::GetEvtHandlerEnabled
}{wxevthandlergetevthandlerenabled
}
334 \membersection{wxEvtHandler::SetNextHandler
}\label{wxevthandlersetnexthandler
}
336 \func{void
}{SetNextHandler
}{\param{wxEvtHandler*
}{handler
}}
338 Sets the pointer to the next handler.
340 \wxheading{Parameters
}
342 \docparam{handler
}{Event handler to be set as the next handler.
}
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
}
352 \membersection{wxEvtHandler::SetPreviousHandler
}\label{wxevthandlersetprevioushandler
}
354 \func{void
}{SetPreviousHandler
}{\param{wxEvtHandler*
}{handler
}}
356 Sets the pointer to the previous handler.
358 \wxheading{Parameters
}
360 \docparam{handler
}{Event handler to be set as the previous handler.
}
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
}