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 When events are received, wxEvtHandler invokes the method listed in the
8 event table using itself as the object. When using multiple inheritance
9 it is imperative that the wxEvtHandler(-derived) class be the first
10 class inherited such that the "this" pointer for the overall object
11 will be identical to the "this" pointer for the wxEvtHandler portion.
13 \wxheading{Derived from
}
15 \helpref{wxObject
}{wxobject
}
17 \wxheading{Include files
}
23 \helpref{wxBase
}{librarieslist
}
27 \overview{Event handling overview
}{eventhandlingoverview
}
29 \latexignore{\rtfignore{\wxheading{Members
}}}
31 \membersection{wxEvtHandler::wxEvtHandler
}\label{wxevthandlerctor
}
33 \func{}{wxEvtHandler
}{\void}
37 \membersection{wxEvtHandler::
\destruct{wxEvtHandler
}}\label{wxevthandlerdtor
}
39 \func{}{\destruct{wxEvtHandler
}}{\void}
41 Destructor. If the handler is part of a chain, the destructor will
42 unlink itself and restore the previous and next handlers so that they point to
45 \membersection{wxEvtHandler::AddPendingEvent
}\label{wxevthandleraddpendingevent
}
47 \func{virtual void
}{AddPendingEvent
}{\param{const wxEvent\&
}{event
}}
49 This function posts an event to be processed later.
51 \wxheading{Parameters
}
53 \docparam{event
}{Event to add to process queue.
}
57 The difference between sending an event (using the
58 \helpref{ProcessEvent
}{wxevthandlerprocessevent
} method) and posting it is
59 that in the first case the event is processed before the function returns,
60 while in the second case, the function returns immediately and the event will
61 be processed sometime later (usually during the next event loop iteration).
63 A copy of
{\it event
} is made by the function, so the original can be deleted
64 as soon as function returns (it is common that the original is created on the
65 stack). This requires that the
\helpref{wxEvent::Clone
}{wxeventclone
} method
66 be implemented by
{\it event
} so that it can be duplicated and stored until
69 This is also the method to call for inter-thread communication---it will
70 post events safely between different threads which means that this method is
71 thread-safe by using critical sections where needed. In a multi-threaded
72 program, you often need to inform the main GUI thread about the status of
73 other working threads and such notification should be done using this method.
75 This method automatically wakes up idle handling if the underlying window
76 system is currently idle and thus would not send any idle events. (Waking
77 up idle handling is done calling
\helpref{::wxWakeUpIdle
}{wxwakeupidle
}.)
79 \membersection{wxEvtHandler::Connect
}\label{wxevthandlerconnect
}
81 \func{void
}{Connect
}{\param{int
}{ id
},
\param{int
}{ lastId
},
82 \param{wxEventType
}{eventType
},
\param{wxObjectEventFunction
}{ function
},
83 \param{wxObject*
}{ userData = NULL
},
\param{wxEvtHandler*
}{ eventSink = NULL
}}
85 \func{void
}{Connect
}{\param{int
}{ id
},
86 \param{wxEventType
}{eventType
},
\param{wxObjectEventFunction
}{ function
},
87 \param{wxObject*
}{ userData = NULL
},
\param{wxEvtHandler*
}{ eventSink = NULL
}}
89 \func{void
}{Connect
}{\param{wxEventType
}{eventType
},
\param{wxObjectEventFunction
}{ function
},
90 \param{wxObject*
}{ userData = NULL
},
\param{wxEvtHandler*
}{ eventSink = NULL
}}
92 Connects the given function dynamically with the event handler, id and event type. This
93 is an alternative to the use of static event tables. See the 'event' or the old 'dynamic' sample for usage.
95 \wxheading{Parameters
}
97 \docparam{id
}{The identifier (or first of the identifier range) to be
98 associated with the event handler function. For the version not taking this
99 argument, it defaults to
\texttt{wxID
\_ANY}.
}
101 \docparam{lastId
}{The second part of the identifier range to be associated with the event handler function.
}
103 \docparam{eventType
}{The event type to be associated with this event handler.
}
105 \docparam{function
}{The event handler function. Note that this function should
106 be explicitly converted to the correct type which can be done using a macro
107 called
\texttt{wxFooHandler
} for the handler for any
\texttt{wxFooEvent
}.
}
109 \docparam{userData
}{Data to be associated with the event table entry.
}
111 \docparam{eventSink
}{Object whose member function should be called. If this is NULL,
112 \textit{this
} will be used.
}
117 frame->Connect( wxID_EXIT,
118 wxEVT_COMMAND_MENU_SELECTED,
119 wxCommandEventHandler(MyFrame::OnQuit) );
122 \perlnote{In wxPerl this function takes
4 arguments:
\texttt{id,
123 lastid, type, method
}; if
\texttt{method
} is
\texttt{undef
}, the
124 handler is disconnected.
}
126 \membersection{wxEvtHandler::Disconnect
}\label{wxevthandlerdisconnect
}
128 \func{bool
}{Disconnect
}{\param{wxEventType
}{eventType = wxEVT
\_NULL},
\param{wxObjectEventFunction
}{ function = NULL
},
129 \param{wxObject*
}{ userData = NULL
},
\param{wxEvtHandler*
}{ eventSink = NULL
}}
131 \func{bool
}{Disconnect
}{\param{int
}{ id =
\texttt{wxID
\_ANY}},
132 \param{wxEventType
}{eventType = wxEVT
\_NULL},
\param{wxObjectEventFunction
}{ function = NULL
},
133 \param{wxObject*
}{ userData = NULL
},
\param{wxEvtHandler*
}{ eventSink = NULL
}}
135 \func{bool
}{Disconnect
}{\param{int
}{ id
},
\param{int
}{ lastId =
\texttt{wxID
\_ANY}},
136 \param{wxEventType
}{eventType = wxEVT
\_NULL},
\param{wxObjectEventFunction
}{ function = NULL
},
137 \param{wxObject*
}{ userData = NULL
},
\param{wxEvtHandler*
}{ eventSink = NULL
}}
139 Disconnects the given function dynamically from the event handler, using the specified
140 parameters as search criteria and returning true if a matching function has been
141 found and removed. This method can only disconnect functions which have been added
142 using the
\helpref{wxEvtHandler::Connect
}{wxevthandlerconnect
} method. There is no way
143 to disconnect functions connected using the (static) event tables.
145 \wxheading{Parameters
}
147 \docparam{id
}{The identifier (or first of the identifier range) associated with the event handler function.
}
149 \docparam{lastId
}{The second part of the identifier range associated with the event handler function.
}
151 \docparam{eventType
}{The event type associated with this event handler.
}
153 \docparam{function
}{The event handler function.
}
155 \docparam{userData
}{Data associated with the event table entry.
}
157 \docparam{eventSink
}{Object whose member function should be called.
}
159 \perlnote{In wxPerl this function takes
3 arguments:
\texttt{id,
162 \membersection{wxEvtHandler::GetClientData
}\label{wxevthandlergetclientdata
}
164 \func{void*
}{GetClientData
}{\void}
166 Gets user-supplied client data.
170 Normally, any extra data the programmer wishes to associate with the object
171 should be made available by deriving a new class with new data members.
175 \helpref{wxEvtHandler::SetClientData
}{wxevthandlersetclientdata
}
177 \membersection{wxEvtHandler::GetClientObject
}\label{wxevthandlergetclientobject
}
179 \constfunc{wxClientData*
}{GetClientObject
}{\void}
181 Get a pointer to the user-supplied client data object.
185 \helpref{wxEvtHandler::SetClientObject
}{wxevthandlersetclientobject
},
186 \helpref{wxClientData
}{wxclientdata
}
188 \membersection{wxEvtHandler::GetEvtHandlerEnabled
}\label{wxevthandlergetevthandlerenabled
}
190 \func{bool
}{GetEvtHandlerEnabled
}{\void}
192 Returns true if the event handler is enabled, false otherwise.
196 \helpref{wxEvtHandler::SetEvtHandlerEnabled
}{wxevthandlersetevthandlerenabled
}
198 \membersection{wxEvtHandler::GetNextHandler
}\label{wxevthandlergetnexthandler
}
200 \func{wxEvtHandler*
}{GetNextHandler
}{\void}
202 Gets the pointer to the next handler in the chain.
206 \helpref{wxEvtHandler::SetNextHandler
}{wxevthandlersetnexthandler
},
\rtfsp
207 \helpref{wxEvtHandler::GetPreviousHandler
}{wxevthandlergetprevioushandler
},
\rtfsp
208 \helpref{wxEvtHandler::SetPreviousHandler
}{wxevthandlersetprevioushandler
},
\rtfsp
209 \helpref{wxWindow::PushEventHandler
}{wxwindowpusheventhandler
},
\rtfsp
210 \helpref{wxWindow::PopEventHandler
}{wxwindowpopeventhandler
}
212 \membersection{wxEvtHandler::GetPreviousHandler
}\label{wxevthandlergetprevioushandler
}
214 \func{wxEvtHandler*
}{GetPreviousHandler
}{\void}
216 Gets the pointer to the previous handler in the chain.
220 \helpref{wxEvtHandler::SetPreviousHandler
}{wxevthandlersetprevioushandler
},
\rtfsp
221 \helpref{wxEvtHandler::GetNextHandler
}{wxevthandlergetnexthandler
},
\rtfsp
222 \helpref{wxEvtHandler::SetNextHandler
}{wxevthandlersetnexthandler
},
\rtfsp
223 \helpref{wxWindow::PushEventHandler
}{wxwindowpusheventhandler
},
\rtfsp
224 \helpref{wxWindow::PopEventHandler
}{wxwindowpopeventhandler
}
226 \membersection{wxEvtHandler::ProcessEvent
}\label{wxevthandlerprocessevent
}
228 \func{virtual bool
}{ProcessEvent
}{\param{wxEvent\&
}{event
}}
230 Processes an event, searching event tables and calling zero or more suitable event handler function(s).
232 \wxheading{Parameters
}
234 \docparam{event
}{Event to process.
}
236 \wxheading{Return value
}
238 true if a suitable event handler function was found and executed, and the function did not
239 call
\helpref{wxEvent::Skip
}{wxeventskip
}.
243 Normally, your application would not call this function: it is called in the wxWidgets
244 implementation to dispatch incoming user interface events to the framework (and application).
246 However, you might need to call it if implementing new functionality (such as a new control) where
247 you define new event types, as opposed to allowing the user to override virtual functions.
249 An instance where you might actually override the
{\bf ProcessEvent
} function is where you want
250 to direct event processing to event handlers not normally noticed by wxWidgets. For example,
251 in the
document/view architecture, documents and views are potential event handlers.
252 When an event reaches a frame,
{\bf ProcessEvent
} will need to be called on the associated
253 document and view in case event handler functions are associated with these objects.
254 The property classes library (wxProperty) also overrides
{\bf ProcessEvent
} for similar reasons.
256 The normal order of event table searching is as follows:
258 \begin{enumerate
}\itemsep=
0pt
259 \item If the object is disabled (via a call to
\helpref{wxEvtHandler::SetEvtHandlerEnabled
}{wxevthandlersetevthandlerenabled
})
260 the function skips to step (
6).
261 \item If the object is a wxWindow,
{\bf ProcessEvent
} is recursively called on the window's
\rtfsp
262 \helpref{wxValidator
}{wxvalidator
}. If this returns true, the function exits.
263 \item {\bf SearchEventTable
} is called for this event handler. If this fails, the base
264 class table is tried, and so on until no more tables exist or an appropriate function was found,
265 in which case the function exits.
266 \item The search is applied down the entire chain of event handlers (usually the chain has a length
267 of one). If this succeeds, the function exits.
268 \item If the object is a wxWindow and the event is a wxCommandEvent,
{\bf ProcessEvent
} is
269 recursively applied to the parent window's event handler. If this returns true, the function exits.
270 \item Finally,
{\bf ProcessEvent
} is called on the wxApp object.
275 \helpref{wxEvtHandler::SearchEventTable
}{wxevthandlersearcheventtable
}
277 \membersection{wxEvtHandler::SearchEventTable
}\label{wxevthandlersearcheventtable
}
279 \func{virtual bool
}{SearchEventTable
}{\param{wxEventTable\&
}{table
},
\param{wxEvent\&
}{event
}}
281 Searches the event table, executing an event handler function if an appropriate one
284 \wxheading{Parameters
}
286 \docparam{table
}{Event table to be searched.
}
288 \docparam{event
}{Event to be matched against an event table entry.
}
290 \wxheading{Return value
}
292 true if a suitable event handler function was found and executed, and the function did not
293 call
\helpref{wxEvent::Skip
}{wxeventskip
}.
297 This function looks through the object's event table and tries to find an entry
298 that will match the event.
300 An entry will match if:
302 \begin{enumerate
}\itemsep=
0pt
303 \item The event type matches, and
304 \item the identifier or identifier range matches, or the event table entry's identifier is zero.
307 If a suitable function is called but calls
\helpref{wxEvent::Skip
}{wxeventskip
}, this function will
308 fail, and searching will continue.
312 \helpref{wxEvtHandler::ProcessEvent
}{wxevthandlerprocessevent
}
314 \membersection{wxEvtHandler::SetClientData
}\label{wxevthandlersetclientdata
}
316 \func{void
}{SetClientData
}{\param{void*
}{data
}}
318 Sets user-supplied client data.
320 \wxheading{Parameters
}
322 \docparam{data
}{Data to be associated with the event handler.
}
326 Normally, any extra data the programmer wishes to associate with
327 the object should be made available by deriving a new class
328 with new data members. You must not call this method and
329 \helpref{SetClientObject
}{wxevthandlersetclientobject
} on the
330 same class - only one of them.
334 \helpref{wxEvtHandler::GetClientData
}{wxevthandlergetclientdata
}
336 \membersection{wxEvtHandler::SetClientObject
}\label{wxevthandlersetclientobject
}
338 \func{void
}{SetClientObject
}{\param{wxClientData*
}{data
}}
340 Set the client data object. Any previous object will be deleted.
344 \helpref{wxEvtHandler::GetClientObject
}{wxevthandlergetclientobject
},
345 \helpref{wxClientData
}{wxclientdata
}
347 \membersection{wxEvtHandler::SetEvtHandlerEnabled
}\label{wxevthandlersetevthandlerenabled
}
349 \func{void
}{SetEvtHandlerEnabled
}{\param{bool
}{enabled
}}
351 Enables or disables the event handler.
353 \wxheading{Parameters
}
355 \docparam{enabled
}{true if the event handler is to be enabled, false if it is to be disabled.
}
359 You can use this function to avoid having to remove the event handler from the chain, for example
360 when implementing a dialog editor and changing from edit to test mode.
364 \helpref{wxEvtHandler::GetEvtHandlerEnabled
}{wxevthandlergetevthandlerenabled
}
366 \membersection{wxEvtHandler::SetNextHandler
}\label{wxevthandlersetnexthandler
}
368 \func{void
}{SetNextHandler
}{\param{wxEvtHandler*
}{handler
}}
370 Sets the pointer to the next handler.
372 \wxheading{Parameters
}
374 \docparam{handler
}{Event handler to be set as the next handler.
}
378 \helpref{wxEvtHandler::GetNextHandler
}{wxevthandlergetnexthandler
},
\rtfsp
379 \helpref{wxEvtHandler::SetPreviousHandler
}{wxevthandlersetprevioushandler
},
\rtfsp
380 \helpref{wxEvtHandler::GetPreviousHandler
}{wxevthandlergetprevioushandler
},
\rtfsp
381 \helpref{wxWindow::PushEventHandler
}{wxwindowpusheventhandler
},
\rtfsp
382 \helpref{wxWindow::PopEventHandler
}{wxwindowpopeventhandler
}
384 \membersection{wxEvtHandler::SetPreviousHandler
}\label{wxevthandlersetprevioushandler
}
386 \func{void
}{SetPreviousHandler
}{\param{wxEvtHandler*
}{handler
}}
388 Sets the pointer to the previous handler.
390 \wxheading{Parameters
}
392 \docparam{handler
}{Event handler to be set as the previous handler.
}
396 \helpref{wxEvtHandler::GetPreviousHandler
}{wxevthandlergetprevioushandler
},
\rtfsp
397 \helpref{wxEvtHandler::SetNextHandler
}{wxevthandlersetnexthandler
},
\rtfsp
398 \helpref{wxEvtHandler::GetNextHandler
}{wxevthandlergetnexthandler
},
\rtfsp
399 \helpref{wxWindow::PushEventHandler
}{wxwindowpusheventhandler
},
\rtfsp
400 \helpref{wxWindow::PopEventHandler
}{wxwindowpopeventhandler
}