]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: event.cpp | |
3 | // Purpose: Event classes | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
55d99c7a | 8 | // Copyright: (c) Julian Smart |
e90c1d2a | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
8e193f38 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
c801d85f | 20 | #ifdef __GNUG__ |
0b746ba8 | 21 | #pragma implementation "event.h" |
c801d85f KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
0b746ba8 | 28 | #pragma hdrstop |
c801d85f KB |
29 | #endif |
30 | ||
31 | #ifndef WX_PRECOMP | |
0b746ba8 | 32 | #include "wx/defs.h" |
0b746ba8 | 33 | #include "wx/app.h" |
e90c1d2a VZ |
34 | #include "wx/list.h" |
35 | ||
36 | #if wxUSE_GUI | |
37 | #include "wx/control.h" | |
38 | #include "wx/utils.h" | |
39 | #include "wx/dc.h" | |
40 | #endif // wxUSE_GUI | |
c801d85f KB |
41 | #endif |
42 | ||
43 | #include "wx/event.h" | |
e90c1d2a VZ |
44 | |
45 | #if wxUSE_GUI | |
46 | #include "wx/validate.h" | |
0b30bb0b JS |
47 | #if wxUSE_STOPWATCH |
48 | #include "wx/stopwatch.h" | |
49 | #endif | |
e90c1d2a | 50 | #endif // wxUSE_GUI |
c801d85f | 51 | |
8e193f38 VZ |
52 | // ---------------------------------------------------------------------------- |
53 | // wxWin macros | |
54 | // ---------------------------------------------------------------------------- | |
55 | ||
3ed2104c VZ |
56 | #if wxUSE_BASE |
57 | IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject) | |
58 | IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject) | |
59 | #endif // wxUSE_BASE | |
e90c1d2a | 60 | |
23f681ec | 61 | #if wxUSE_GUI |
6b55490a | 62 | IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent) |
23f681ec VZ |
63 | IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent) |
64 | IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent) | |
65 | IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent) | |
66 | IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent, wxEvent) | |
67 | IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent) | |
68 | IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent) | |
69 | IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent) | |
70 | IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent) | |
1e6feb95 | 71 | IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent, wxEvent) |
23f681ec VZ |
72 | IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent) |
73 | IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent) | |
74 | IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent) | |
456bc6d9 | 75 | IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent, wxCommandEvent) |
23f681ec VZ |
76 | IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent) |
77 | IMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent) | |
78 | IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent) | |
79 | IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent) | |
80 | IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent) | |
81 | IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent) | |
82 | IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent) | |
83 | IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent) | |
84 | IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent) | |
8e72b8b5 | 85 | IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent, wxEvent) |
23f681ec | 86 | IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent) |
574c939e | 87 | IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent, wxEvent) |
23f681ec VZ |
88 | IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent) |
89 | IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxCommandEvent) | |
90 | IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, wxEvent) | |
91 | IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent, wxEvent) | |
92 | IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent, wxEvent) | |
93 | IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent, wxEvent) | |
b96340e6 | 94 | IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent, wxCommandEvent) |
69231000 | 95 | IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent, wxCommandEvent) |
a5e84126 | 96 | IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent, wxEvent) |
23f681ec | 97 | #endif // wxUSE_GUI |
0b746ba8 | 98 | |
3ed2104c VZ |
99 | #if wxUSE_BASE |
100 | ||
23f681ec VZ |
101 | const wxEventTable *wxEvtHandler::GetEventTable() const |
102 | { return &wxEvtHandler::sm_eventTable; } | |
0b746ba8 | 103 | |
23f681ec VZ |
104 | const wxEventTable wxEvtHandler::sm_eventTable = |
105 | { (const wxEventTable *)NULL, &wxEvtHandler::sm_eventTableEntries[0] }; | |
0b746ba8 | 106 | |
23f681ec | 107 | const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] = |
9aaf9bed | 108 | { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL, 0, 0, (wxObjectEventFunction)NULL, NULL) }; |
c801d85f | 109 | |
8e193f38 VZ |
110 | // ---------------------------------------------------------------------------- |
111 | // global variables | |
112 | // ---------------------------------------------------------------------------- | |
113 | ||
114 | // To put pending event handlers | |
115 | wxList *wxPendingEvents = (wxList *)NULL; | |
116 | ||
7214297d | 117 | #if wxUSE_THREADS |
8e193f38 VZ |
118 | // protects wxPendingEvents list |
119 | wxCriticalSection *wxPendingEventsLocker = (wxCriticalSection *)NULL; | |
7214297d GL |
120 | #endif |
121 | ||
cbee8f8d VZ |
122 | #if !WXWIN_COMPATIBILITY_EVENT_TYPES |
123 | ||
2e4df4bf VZ |
124 | // common event types are defined here, other event types are defined by the |
125 | // components which use them | |
c15d9c85 VS |
126 | |
127 | const wxEventType wxEVT_FIRST = 10000; | |
128 | const wxEventType wxEVT_USER_FIRST = wxEVT_FIRST + 2000; | |
2e4df4bf | 129 | |
461697c2 | 130 | DEFINE_EVENT_TYPE(wxEVT_NULL) |
886dd7d2 VZ |
131 | DEFINE_EVENT_TYPE(wxEVT_IDLE) |
132 | DEFINE_EVENT_TYPE(wxEVT_SOCKET) | |
133 | ||
134 | #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES | |
135 | ||
136 | #endif // wxUSE_BASE | |
137 | ||
138 | #if wxUSE_GUI | |
139 | ||
140 | #if !WXWIN_COMPATIBILITY_EVENT_TYPES | |
141 | ||
2e4df4bf VZ |
142 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED) |
143 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED) | |
144 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED) | |
145 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED) | |
146 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED) | |
147 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED) | |
2e4df4bf VZ |
148 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED) |
149 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED) | |
150 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED) | |
151 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED) | |
152 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED) | |
153 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED) | |
154 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED) | |
155 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED) | |
156 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER) | |
157 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED) | |
0b5eceb6 VZ |
158 | |
159 | // Sockets and timers send events, too | |
2e4df4bf | 160 | DEFINE_EVENT_TYPE(wxEVT_TIMER) |
0b5eceb6 VZ |
161 | |
162 | // Mouse event types | |
2e4df4bf VZ |
163 | DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN) |
164 | DEFINE_EVENT_TYPE(wxEVT_LEFT_UP) | |
165 | DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN) | |
166 | DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP) | |
167 | DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN) | |
168 | DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP) | |
169 | DEFINE_EVENT_TYPE(wxEVT_MOTION) | |
170 | DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW) | |
171 | DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW) | |
172 | DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK) | |
173 | DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK) | |
174 | DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK) | |
175 | DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS) | |
176 | DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS) | |
456bc6d9 | 177 | DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS) |
d2c52078 | 178 | DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL) |
0b5eceb6 VZ |
179 | |
180 | // Non-client mouse events | |
2e4df4bf VZ |
181 | DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN) |
182 | DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP) | |
183 | DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN) | |
184 | DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP) | |
185 | DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN) | |
186 | DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP) | |
187 | DEFINE_EVENT_TYPE(wxEVT_NC_MOTION) | |
188 | DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW) | |
189 | DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW) | |
190 | DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK) | |
191 | DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK) | |
192 | DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK) | |
0b5eceb6 VZ |
193 | |
194 | // Character input event type | |
2e4df4bf VZ |
195 | DEFINE_EVENT_TYPE(wxEVT_CHAR) |
196 | DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK) | |
197 | DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY) | |
198 | DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN) | |
199 | DEFINE_EVENT_TYPE(wxEVT_KEY_UP) | |
0b5eceb6 VZ |
200 | |
201 | // Set cursor event | |
2e4df4bf | 202 | DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR) |
0b5eceb6 VZ |
203 | |
204 | // wxScrollbar and wxSlider event identifiers | |
2e4df4bf VZ |
205 | DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP) |
206 | DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM) | |
207 | DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP) | |
208 | DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN) | |
209 | DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP) | |
210 | DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN) | |
211 | DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK) | |
212 | DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE) | |
e8b669d3 | 213 | DEFINE_EVENT_TYPE(wxEVT_SCROLL_ENDSCROLL) |
0b5eceb6 VZ |
214 | |
215 | // Scroll events from wxWindow | |
2e4df4bf VZ |
216 | DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP) |
217 | DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM) | |
218 | DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP) | |
219 | DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN) | |
220 | DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP) | |
221 | DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN) | |
222 | DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK) | |
223 | DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE) | |
0b5eceb6 VZ |
224 | |
225 | // System events | |
2e4df4bf | 226 | DEFINE_EVENT_TYPE(wxEVT_SIZE) |
5706de1c | 227 | DEFINE_EVENT_TYPE(wxEVT_SIZING) |
2e4df4bf | 228 | DEFINE_EVENT_TYPE(wxEVT_MOVE) |
5706de1c | 229 | DEFINE_EVENT_TYPE(wxEVT_MOVING) |
2e4df4bf VZ |
230 | DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW) |
231 | DEFINE_EVENT_TYPE(wxEVT_END_SESSION) | |
232 | DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION) | |
233 | DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP) | |
234 | DEFINE_EVENT_TYPE(wxEVT_POWER) | |
235 | DEFINE_EVENT_TYPE(wxEVT_ACTIVATE) | |
236 | DEFINE_EVENT_TYPE(wxEVT_CREATE) | |
237 | DEFINE_EVENT_TYPE(wxEVT_DESTROY) | |
238 | DEFINE_EVENT_TYPE(wxEVT_SHOW) | |
239 | DEFINE_EVENT_TYPE(wxEVT_ICONIZE) | |
240 | DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE) | |
241 | DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED) | |
242 | DEFINE_EVENT_TYPE(wxEVT_PAINT) | |
243 | DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND) | |
244 | DEFINE_EVENT_TYPE(wxEVT_NC_PAINT) | |
245 | DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON) | |
ccef86c7 VZ |
246 | DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN) |
247 | DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE) | |
2e4df4bf | 248 | DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT) |
2e4df4bf VZ |
249 | DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU) |
250 | DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED) | |
574c939e | 251 | DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED) |
2e4df4bf VZ |
252 | DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED) |
253 | DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE) | |
254 | DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED) | |
255 | DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN) | |
256 | DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP) | |
257 | DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE) | |
258 | DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE) | |
259 | DEFINE_EVENT_TYPE(wxEVT_DROP_FILES) | |
260 | DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM) | |
261 | DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM) | |
262 | DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM) | |
263 | DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG) | |
2e4df4bf | 264 | DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI) |
0b5eceb6 VZ |
265 | |
266 | // Generic command events | |
267 | // Note: a click is a higher-level event than button down/up | |
2e4df4bf VZ |
268 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK) |
269 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK) | |
270 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK) | |
271 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK) | |
272 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS) | |
273 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS) | |
274 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER) | |
0b5eceb6 VZ |
275 | |
276 | // Help events | |
2e4df4bf VZ |
277 | DEFINE_EVENT_TYPE(wxEVT_HELP) |
278 | DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP) | |
6164f93c VZ |
279 | |
280 | #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES | |
281 | ||
886dd7d2 VZ |
282 | #endif // wxUSE_GUI |
283 | ||
284 | #if wxUSE_BASE | |
285 | ||
6164f93c VZ |
286 | // ============================================================================ |
287 | // implementation | |
288 | // ============================================================================ | |
0b5eceb6 | 289 | |
0b5eceb6 VZ |
290 | // ---------------------------------------------------------------------------- |
291 | // event initialization | |
292 | // ---------------------------------------------------------------------------- | |
293 | ||
294 | int wxNewEventType() | |
295 | { | |
296 | // MT-FIXME | |
297 | static int s_lastUsedEventType = wxEVT_FIRST; | |
298 | ||
cbee8f8d VZ |
299 | #if WXWIN_COMPATIBILITY_2 |
300 | // check that we don't overlap with the user-defined types: if it does | |
301 | // happen, the best solution is probably to update the existing code to | |
302 | // use wxNewEventType() instead of wxEVT_USER_FIRST | |
6164f93c VZ |
303 | // |
304 | // due to the uncertainty | |
cbee8f8d VZ |
305 | wxASSERT_MSG( s_lastUsedEventType < wxEVT_USER_FIRST - 1, |
306 | _T("possible event type conflict") ); | |
307 | #endif // WXWIN_COMPATIBILITY_2 | |
308 | ||
0b5eceb6 VZ |
309 | return s_lastUsedEventType++; |
310 | } | |
311 | ||
8e193f38 VZ |
312 | // ---------------------------------------------------------------------------- |
313 | // wxEvent | |
314 | // ---------------------------------------------------------------------------- | |
315 | ||
c801d85f KB |
316 | /* |
317 | * General wxWindows events, covering | |
318 | * all interesting things that might happen (button clicking, resizing, | |
319 | * setting text in widgets, etc.). | |
320 | * | |
321 | * For each completely new event type, derive a new event class. | |
322 | * | |
323 | */ | |
324 | ||
8e72b8b5 | 325 | wxEvent::wxEvent(int theId, wxEventType commandType ) |
c801d85f | 326 | { |
8e72b8b5 | 327 | m_eventType = commandType; |
0b746ba8 | 328 | m_eventObject = (wxObject *) NULL; |
0b746ba8 VZ |
329 | m_timeStamp = 0; |
330 | m_id = theId; | |
331 | m_skipped = FALSE; | |
332 | m_callbackUserData = (wxObject *) NULL; | |
193bf013 | 333 | m_isCommandEvent = FALSE; |
c801d85f KB |
334 | } |
335 | ||
8e72b8b5 | 336 | wxEvent::wxEvent(const wxEvent &src) |
e6a6feba GD |
337 | : wxObject() |
338 | , m_eventObject(src.m_eventObject) | |
339 | , m_eventType(src.m_eventType) | |
340 | , m_timeStamp(src.m_timeStamp) | |
341 | , m_id(src.m_id) | |
342 | , m_callbackUserData(src.m_callbackUserData) | |
343 | , m_skipped(src.m_skipped) | |
344 | , m_isCommandEvent(src.m_isCommandEvent) | |
a737331d | 345 | { |
a737331d GL |
346 | } |
347 | ||
3ed2104c VZ |
348 | #endif // wxUSE_BASE |
349 | ||
e90c1d2a VZ |
350 | #if wxUSE_GUI |
351 | ||
c801d85f KB |
352 | /* |
353 | * Command events | |
354 | * | |
355 | */ | |
356 | ||
7798a18e | 357 | wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId) |
e6a6feba | 358 | : wxEvent(theId, commandType) |
c801d85f | 359 | { |
0b746ba8 VZ |
360 | m_clientData = (char *) NULL; |
361 | m_clientObject = (wxClientData *) NULL; | |
362 | m_extraLong = 0; | |
363 | m_commandInt = 0; | |
04392d70 | 364 | m_commandString = wxEmptyString; |
193bf013 | 365 | m_isCommandEvent = TRUE; |
c801d85f KB |
366 | } |
367 | ||
0b30bb0b JS |
368 | /* |
369 | * UI update events | |
370 | */ | |
371 | ||
372 | #if wxUSE_LONGLONG | |
e39af974 | 373 | wxLongLong wxUpdateUIEvent::sm_lastUpdate = 0; |
0b30bb0b JS |
374 | #endif |
375 | ||
e39af974 JS |
376 | long wxUpdateUIEvent::sm_updateInterval = 0; |
377 | ||
378 | wxUpdateUIMode wxUpdateUIEvent::sm_updateMode = wxUPDATE_UI_PROCESS_ALL; | |
0b30bb0b JS |
379 | |
380 | // Can we update? | |
e39af974 | 381 | bool wxUpdateUIEvent::CanUpdate(wxWindow* win) |
0b30bb0b | 382 | { |
e39af974 JS |
383 | // Don't update if we've switched global updating off |
384 | // and this window doesn't support updates. | |
385 | if (win && | |
386 | (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED && | |
387 | ((win->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES) == 0))) | |
388 | return FALSE; | |
389 | ||
390 | if (sm_updateInterval == -1) | |
0b30bb0b | 391 | return FALSE; |
e39af974 | 392 | else if (sm_updateInterval == 0) |
0b30bb0b JS |
393 | return TRUE; |
394 | else | |
395 | { | |
396 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG | |
397 | wxLongLong now = wxGetLocalTimeMillis(); | |
e39af974 | 398 | if (now > (sm_lastUpdate + sm_updateInterval)) |
0b30bb0b JS |
399 | { |
400 | return TRUE; | |
401 | } | |
402 | #else | |
403 | // If we don't have wxStopWatch or wxLongLong, we | |
404 | // should err on the safe side and update now anyway. | |
405 | return TRUE; | |
406 | #endif | |
407 | } | |
408 | return FALSE; | |
409 | } | |
410 | ||
411 | // Reset the update time to provide a delay until the next | |
412 | // time we should update | |
413 | void wxUpdateUIEvent::ResetUpdateTime() | |
414 | { | |
415 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG | |
e39af974 | 416 | if (sm_updateInterval > 0) |
0b30bb0b JS |
417 | { |
418 | wxLongLong now = wxGetLocalTimeMillis(); | |
e39af974 | 419 | if (now > (sm_lastUpdate + sm_updateInterval)) |
0b30bb0b | 420 | { |
e39af974 | 421 | sm_lastUpdate = now; |
0b30bb0b JS |
422 | } |
423 | } | |
424 | #endif | |
425 | } | |
426 | ||
e39af974 JS |
427 | /* |
428 | * Idle events | |
429 | */ | |
430 | ||
431 | wxIdleMode wxIdleEvent::sm_idleMode = wxIDLE_PROCESS_ALL; | |
432 | ||
433 | // Can we send an idle event? | |
434 | bool wxIdleEvent::CanSend(wxWindow* win) | |
435 | { | |
436 | // Don't update if we've switched global updating off | |
437 | // and this window doesn't support updates. | |
438 | if (win && | |
439 | (GetMode() == wxIDLE_PROCESS_SPECIFIED && | |
440 | ((win->GetExtraStyle() & wxWS_EX_PROCESS_IDLE) == 0))) | |
441 | return FALSE; | |
442 | ||
443 | return TRUE; | |
444 | } | |
0b30bb0b | 445 | |
c801d85f KB |
446 | /* |
447 | * Scroll events | |
448 | */ | |
449 | ||
0b746ba8 VZ |
450 | wxScrollEvent::wxScrollEvent(wxEventType commandType, |
451 | int id, | |
452 | int pos, | |
453 | int orient) | |
e6a6feba | 454 | : wxCommandEvent(commandType, id) |
c801d85f | 455 | { |
0b746ba8 VZ |
456 | m_extraLong = orient; |
457 | m_commandInt = pos; | |
c801d85f KB |
458 | } |
459 | ||
d1367c3d RR |
460 | /* |
461 | * ScrollWin events | |
462 | */ | |
463 | ||
464 | wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType, | |
465 | int pos, | |
466 | int orient) | |
d1367c3d | 467 | { |
c5b42c87 | 468 | m_eventType = commandType; |
d1367c3d RR |
469 | m_extraLong = orient; |
470 | m_commandInt = pos; | |
471 | } | |
472 | ||
c801d85f KB |
473 | /* |
474 | * Mouse events | |
475 | * | |
476 | */ | |
477 | ||
7798a18e | 478 | wxMouseEvent::wxMouseEvent(wxEventType commandType) |
c801d85f | 479 | { |
0b746ba8 VZ |
480 | m_eventType = commandType; |
481 | m_metaDown = FALSE; | |
482 | m_altDown = FALSE; | |
483 | m_controlDown = FALSE; | |
484 | m_shiftDown = FALSE; | |
485 | m_leftDown = FALSE; | |
486 | m_rightDown = FALSE; | |
487 | m_middleDown = FALSE; | |
488 | m_x = 0; | |
489 | m_y = 0; | |
d2c52078 RD |
490 | m_wheelRotation = 0; |
491 | m_wheelDelta = 0; | |
492 | m_linesPerAction = 0; | |
c801d85f KB |
493 | } |
494 | ||
abcbaea7 VZ |
495 | void wxMouseEvent::Assign(const wxMouseEvent& event) |
496 | { | |
9a1725c4 | 497 | m_eventType = event.m_eventType; |
92309201 | 498 | |
abcbaea7 VZ |
499 | m_x = event.m_x; |
500 | m_y = event.m_y; | |
501 | ||
502 | m_leftDown = event.m_leftDown; | |
503 | m_middleDown = event.m_middleDown; | |
504 | m_rightDown = event.m_rightDown; | |
505 | ||
506 | m_controlDown = event.m_controlDown; | |
507 | m_shiftDown = event.m_shiftDown; | |
508 | m_altDown = event.m_altDown; | |
509 | m_metaDown = event.m_metaDown; | |
510 | ||
511 | m_wheelRotation = event.m_wheelRotation; | |
512 | m_wheelDelta = event.m_wheelDelta; | |
513 | m_linesPerAction = event.m_linesPerAction; | |
514 | } | |
515 | ||
c801d85f KB |
516 | // True if was a button dclick event (1 = left, 2 = middle, 3 = right) |
517 | // or any button dclick event (but = -1) | |
518 | bool wxMouseEvent::ButtonDClick(int but) const | |
519 | { | |
0b746ba8 VZ |
520 | switch (but) |
521 | { | |
522 | case -1: | |
523 | return (LeftDClick() || MiddleDClick() || RightDClick()); | |
524 | case 1: | |
525 | return LeftDClick(); | |
526 | case 2: | |
527 | return MiddleDClick(); | |
528 | case 3: | |
529 | return RightDClick(); | |
530 | default: | |
223d09f6 | 531 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick")); |
0b746ba8 VZ |
532 | } |
533 | ||
534 | return FALSE; | |
c801d85f KB |
535 | } |
536 | ||
537 | // True if was a button down event (1 = left, 2 = middle, 3 = right) | |
538 | // or any button down event (but = -1) | |
539 | bool wxMouseEvent::ButtonDown(int but) const | |
540 | { | |
0b746ba8 VZ |
541 | switch (but) |
542 | { | |
543 | case -1: | |
544 | return (LeftDown() || MiddleDown() || RightDown()); | |
545 | case 1: | |
546 | return LeftDown(); | |
547 | case 2: | |
548 | return MiddleDown(); | |
549 | case 3: | |
550 | return RightDown(); | |
551 | default: | |
223d09f6 | 552 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown")); |
0b746ba8 VZ |
553 | } |
554 | ||
555 | return FALSE; | |
c801d85f KB |
556 | } |
557 | ||
558 | // True if was a button up event (1 = left, 2 = middle, 3 = right) | |
559 | // or any button up event (but = -1) | |
560 | bool wxMouseEvent::ButtonUp(int but) const | |
561 | { | |
1e6feb95 VZ |
562 | switch (but) |
563 | { | |
0b746ba8 VZ |
564 | case -1: |
565 | return (LeftUp() || MiddleUp() || RightUp()); | |
566 | case 1: | |
567 | return LeftUp(); | |
568 | case 2: | |
569 | return MiddleUp(); | |
570 | case 3: | |
571 | return RightUp(); | |
572 | default: | |
223d09f6 | 573 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp")); |
0b746ba8 VZ |
574 | } |
575 | ||
576 | return FALSE; | |
c801d85f KB |
577 | } |
578 | ||
579 | // True if the given button is currently changing state | |
580 | bool wxMouseEvent::Button(int but) const | |
581 | { | |
1e6feb95 VZ |
582 | switch (but) |
583 | { | |
0b746ba8 | 584 | case -1: |
72cdf4c9 | 585 | return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1)); |
0b746ba8 VZ |
586 | case 1: |
587 | return (LeftDown() || LeftUp() || LeftDClick()); | |
588 | case 2: | |
589 | return (MiddleDown() || MiddleUp() || MiddleDClick()); | |
590 | case 3: | |
591 | return (RightDown() || RightUp() || RightDClick()); | |
592 | default: | |
223d09f6 | 593 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button")); |
0b746ba8 VZ |
594 | } |
595 | ||
596 | return FALSE; | |
c801d85f KB |
597 | } |
598 | ||
599 | bool wxMouseEvent::ButtonIsDown(int but) const | |
600 | { | |
1e6feb95 VZ |
601 | switch (but) |
602 | { | |
0b746ba8 VZ |
603 | case -1: |
604 | return (LeftIsDown() || MiddleIsDown() || RightIsDown()); | |
605 | case 1: | |
606 | return LeftIsDown(); | |
607 | case 2: | |
608 | return MiddleIsDown(); | |
609 | case 3: | |
610 | return RightIsDown(); | |
611 | default: | |
223d09f6 | 612 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown")); |
0b746ba8 VZ |
613 | } |
614 | ||
615 | return FALSE; | |
c801d85f KB |
616 | } |
617 | ||
1e6feb95 VZ |
618 | int wxMouseEvent::GetButton() const |
619 | { | |
620 | for ( int i = 1; i <= 3; i++ ) | |
621 | { | |
622 | if ( Button(i) ) | |
623 | { | |
624 | return i; | |
625 | } | |
626 | } | |
627 | ||
628 | return -1; | |
629 | } | |
630 | ||
c801d85f KB |
631 | // Find the logical position of the event given the DC |
632 | wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const | |
633 | { | |
0757d27c JS |
634 | wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y)); |
635 | return pt; | |
c801d85f KB |
636 | } |
637 | ||
638 | ||
639 | /* | |
8e72b8b5 | 640 | * Keyboard event |
c801d85f KB |
641 | * |
642 | */ | |
643 | ||
7798a18e | 644 | wxKeyEvent::wxKeyEvent(wxEventType type) |
c801d85f | 645 | { |
0b746ba8 VZ |
646 | m_eventType = type; |
647 | m_shiftDown = FALSE; | |
648 | m_controlDown = FALSE; | |
649 | m_metaDown = FALSE; | |
650 | m_altDown = FALSE; | |
651 | m_keyCode = 0; | |
b0e813a0 | 652 | m_scanCode = 0; |
2b5f62a0 VZ |
653 | #if wxUSE_UNICODE |
654 | m_uniChar = 0; | |
655 | #endif | |
c801d85f KB |
656 | } |
657 | ||
92309201 | 658 | wxKeyEvent::wxKeyEvent(const wxKeyEvent& evt) |
2b5f62a0 VZ |
659 | : wxEvent(evt) |
660 | { | |
661 | m_x = evt.m_x; | |
662 | m_y = evt.m_y; | |
663 | ||
664 | m_keyCode = evt.m_keyCode; | |
665 | ||
666 | m_controlDown = evt.m_controlDown; | |
667 | m_shiftDown = evt.m_shiftDown; | |
668 | m_altDown = evt.m_altDown; | |
669 | m_metaDown = evt.m_metaDown; | |
670 | m_scanCode = evt.m_scanCode; | |
671 | m_rawCode = evt.m_rawCode; | |
672 | m_rawFlags = evt.m_rawFlags; | |
92309201 | 673 | |
2b5f62a0 VZ |
674 | #if wxUSE_UNICODE |
675 | m_uniChar = evt.m_uniChar; | |
676 | #endif | |
677 | } | |
12a3f227 RL |
678 | |
679 | long wxKeyEvent::KeyCode() const | |
680 | { | |
681 | return m_keyCode; | |
682 | } | |
683 | ||
42e69d6b | 684 | wxWindowCreateEvent::wxWindowCreateEvent(wxWindow *win) |
42e69d6b | 685 | { |
cfe17b74 | 686 | SetEventType(wxEVT_CREATE); |
42e69d6b VZ |
687 | SetEventObject(win); |
688 | } | |
689 | ||
690 | wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow *win) | |
42e69d6b | 691 | { |
cfe17b74 | 692 | SetEventType(wxEVT_DESTROY); |
42e69d6b VZ |
693 | SetEventObject(win); |
694 | } | |
695 | ||
456bc6d9 VZ |
696 | wxChildFocusEvent::wxChildFocusEvent(wxWindow *win) |
697 | : wxCommandEvent(wxEVT_CHILD_FOCUS) | |
698 | { | |
699 | SetEventObject(win); | |
700 | } | |
701 | ||
dd070522 VZ |
702 | #endif // wxUSE_GUI |
703 | ||
456bc6d9 VZ |
704 | // ---------------------------------------------------------------------------- |
705 | // wxEvtHandler | |
706 | // ---------------------------------------------------------------------------- | |
707 | ||
3ed2104c VZ |
708 | #if wxUSE_BASE |
709 | ||
c801d85f KB |
710 | /* |
711 | * Event handler | |
712 | */ | |
713 | ||
0b746ba8 | 714 | wxEvtHandler::wxEvtHandler() |
c801d85f | 715 | { |
0b746ba8 VZ |
716 | m_nextHandler = (wxEvtHandler *) NULL; |
717 | m_previousHandler = (wxEvtHandler *) NULL; | |
718 | m_enabled = TRUE; | |
719 | m_dynamicEvents = (wxList *) NULL; | |
8e193f38 | 720 | m_pendingEvents = (wxList *) NULL; |
7214297d | 721 | #if wxUSE_THREADS |
41404da7 | 722 | # if !defined(__VISAGECPP__) |
8e193f38 | 723 | m_eventsLocker = new wxCriticalSection; |
41404da7 | 724 | # endif |
7214297d | 725 | #endif |
b88c44e7 RD |
726 | // no client data (yet) |
727 | m_clientData = NULL; | |
728 | m_clientDataType = wxClientData_None; | |
c801d85f KB |
729 | } |
730 | ||
0b746ba8 | 731 | wxEvtHandler::~wxEvtHandler() |
c801d85f | 732 | { |
0b746ba8 VZ |
733 | // Takes itself out of the list of handlers |
734 | if (m_previousHandler) | |
735 | m_previousHandler->m_nextHandler = m_nextHandler; | |
736 | ||
737 | if (m_nextHandler) | |
738 | m_nextHandler->m_previousHandler = m_previousHandler; | |
739 | ||
740 | if (m_dynamicEvents) | |
fe71f65c | 741 | { |
df5168c4 MB |
742 | wxList::iterator it = m_dynamicEvents->begin(), |
743 | en = m_dynamicEvents->end(); | |
744 | for (;it != en; ++it) | |
0b746ba8 | 745 | { |
2e4df4bf | 746 | #if WXWIN_COMPATIBILITY_EVENT_TYPES |
df5168c4 | 747 | wxEventTableEntry *entry = (wxEventTableEntry*)*it; |
2e4df4bf | 748 | #else // !WXWIN_COMPATIBILITY_EVENT_TYPES |
df5168c4 | 749 | wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)*it; |
2e4df4bf VZ |
750 | #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES |
751 | ||
752 | if (entry->m_callbackUserData) | |
753 | delete entry->m_callbackUserData; | |
0b746ba8 | 754 | delete entry; |
0b746ba8 VZ |
755 | } |
756 | delete m_dynamicEvents; | |
757 | }; | |
7214297d | 758 | |
8e193f38 | 759 | delete m_pendingEvents; |
7214297d | 760 | |
8e193f38 | 761 | #if wxUSE_THREADS |
41404da7 | 762 | # if !defined(__VISAGECPP__) |
7214297d | 763 | delete m_eventsLocker; |
41404da7 | 764 | # endif |
083f7497 JS |
765 | |
766 | // Remove us from wxPendingEvents if necessary. | |
767 | if(wxPendingEventsLocker) | |
768 | wxENTER_CRIT_SECT(*wxPendingEventsLocker); | |
769 | if ( wxPendingEvents ) { | |
770 | wxPendingEvents->DeleteObject(this); | |
771 | } | |
772 | if(wxPendingEventsLocker) | |
773 | wxLEAVE_CRIT_SECT(*wxPendingEventsLocker); | |
7214297d | 774 | #endif |
b88c44e7 RD |
775 | |
776 | // we only delete object data, not untyped | |
777 | if ( m_clientDataType == wxClientData_Object ) | |
778 | delete m_clientObject; | |
c801d85f KB |
779 | } |
780 | ||
7214297d | 781 | #if wxUSE_THREADS |
aadbdf11 | 782 | |
7214297d GL |
783 | bool wxEvtHandler::ProcessThreadEvent(wxEvent& event) |
784 | { | |
7214297d | 785 | // check that we are really in a child thread |
8e193f38 VZ |
786 | wxASSERT_MSG( !wxThread::IsMain(), |
787 | wxT("use ProcessEvent() in main thread") ); | |
788 | ||
789 | AddPendingEvent(event); | |
7214297d | 790 | |
8e193f38 VZ |
791 | return TRUE; |
792 | } | |
793 | ||
794 | #endif // wxUSE_THREADS | |
795 | ||
796 | void wxEvtHandler::AddPendingEvent(wxEvent& event) | |
797 | { | |
16c1f79c RR |
798 | // 1) Add event to list of pending events of this event handler |
799 | ||
7a5c8ac4 VZ |
800 | wxEvent *eventCopy = event.Clone(); |
801 | ||
802 | // we must be able to copy the events here so the event class must | |
803 | // implement Clone() properly instead of just providing a NULL stab for it | |
804 | wxCHECK_RET( eventCopy, | |
805 | _T("events of this type aren't supposed to be posted") ); | |
806 | ||
16c1f79c RR |
807 | #if defined(__VISAGECPP__) |
808 | wxENTER_CRIT_SECT( m_eventsLocker); | |
809 | #else | |
810 | wxENTER_CRIT_SECT( *m_eventsLocker); | |
811 | #endif | |
812 | ||
8e193f38 VZ |
813 | if ( !m_pendingEvents ) |
814 | m_pendingEvents = new wxList; | |
7214297d | 815 | |
7a5c8ac4 | 816 | m_pendingEvents->Append(eventCopy); |
7214297d | 817 | |
16c1f79c RR |
818 | #if defined(__VISAGECPP__) |
819 | wxLEAVE_CRIT_SECT( m_eventsLocker); | |
820 | #else | |
821 | wxLEAVE_CRIT_SECT( *m_eventsLocker); | |
822 | #endif | |
823 | ||
824 | // 2) Add this event handler to list of event handlers that | |
825 | // have pending events. | |
cfe17b74 | 826 | |
b568d04f | 827 | wxENTER_CRIT_SECT(*wxPendingEventsLocker); |
72cdf4c9 | 828 | |
8e193f38 VZ |
829 | if ( !wxPendingEvents ) |
830 | wxPendingEvents = new wxList; | |
4d3a259a | 831 | wxPendingEvents->Append(this); |
72cdf4c9 | 832 | |
ce6d2511 | 833 | wxLEAVE_CRIT_SECT(*wxPendingEventsLocker); |
6164f93c | 834 | |
16c1f79c RR |
835 | // 3) Inform the system that new pending events are somwehere, |
836 | // and that these should be processed in idle time. | |
bf9e3e73 | 837 | wxWakeUpIdle(); |
7214297d GL |
838 | } |
839 | ||
840 | void wxEvtHandler::ProcessPendingEvents() | |
841 | { | |
41404da7 | 842 | #if defined(__VISAGECPP__) |
16c1f79c | 843 | wxENTER_CRIT_SECT( m_eventsLocker); |
b568d04f | 844 | #else |
16c1f79c | 845 | wxENTER_CRIT_SECT( *m_eventsLocker); |
41404da7 | 846 | #endif |
8e193f38 | 847 | |
df5168c4 | 848 | wxList::compatibility_iterator node = m_pendingEvents->GetFirst(); |
8e193f38 VZ |
849 | while ( node ) |
850 | { | |
b1d4dd7a | 851 | wxEvent *event = (wxEvent *)node->GetData(); |
df5168c4 | 852 | m_pendingEvents->Erase(node); |
cfe17b74 | 853 | |
16c1f79c | 854 | // In ProcessEvent, new events might get added and |
6164f93c | 855 | // we can safely leave the crtical section here. |
16c1f79c RR |
856 | #if defined(__VISAGECPP__) |
857 | wxLEAVE_CRIT_SECT( m_eventsLocker); | |
858 | #else | |
859 | wxLEAVE_CRIT_SECT( *m_eventsLocker); | |
860 | #endif | |
8e193f38 | 861 | ProcessEvent(*event); |
9779893b | 862 | delete event; |
16c1f79c RR |
863 | #if defined(__VISAGECPP__) |
864 | wxENTER_CRIT_SECT( m_eventsLocker); | |
865 | #else | |
866 | wxENTER_CRIT_SECT( *m_eventsLocker); | |
867 | #endif | |
cfe17b74 | 868 | |
b1d4dd7a | 869 | node = m_pendingEvents->GetFirst(); |
7214297d | 870 | } |
cfe17b74 | 871 | |
16c1f79c RR |
872 | #if defined(__VISAGECPP__) |
873 | wxLEAVE_CRIT_SECT( m_eventsLocker); | |
874 | #else | |
875 | wxLEAVE_CRIT_SECT( *m_eventsLocker); | |
876 | #endif | |
7214297d | 877 | } |
7214297d | 878 | |
c801d85f KB |
879 | /* |
880 | * Event table stuff | |
881 | */ | |
882 | ||
4caf847c | 883 | bool wxEvtHandler::TryParent(wxEvent& event) |
c801d85f | 884 | { |
4caf847c | 885 | if ( wxTheApp && (this != wxTheApp) ) |
9154d8cf | 886 | { |
4caf847c VZ |
887 | // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always |
888 | // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be | |
889 | // processed appropriately via SearchEventTable. | |
890 | if ( event.GetEventType() != wxEVT_IDLE ) | |
891 | { | |
892 | if ( wxTheApp->ProcessEvent(event) ) | |
893 | return TRUE; | |
894 | } | |
9154d8cf VZ |
895 | } |
896 | ||
4caf847c VZ |
897 | return FALSE; |
898 | } | |
0b746ba8 | 899 | |
4caf847c VZ |
900 | bool wxEvtHandler::ProcessEvent(wxEvent& event) |
901 | { | |
9154d8cf VZ |
902 | // allow the application to hook into event processing |
903 | if ( wxTheApp ) | |
904 | { | |
905 | int rc = wxTheApp->FilterEvent(event); | |
906 | if ( rc != -1 ) | |
907 | { | |
908 | wxASSERT_MSG( rc == 1 || rc == 0, | |
909 | _T("unexpected wxApp::FilterEvent return value") ); | |
910 | ||
911 | return rc != 0; | |
912 | } | |
913 | //else: proceed normally | |
914 | } | |
915 | ||
8e193f38 | 916 | // An event handler can be enabled or disabled |
0b746ba8 | 917 | if ( GetEvtHandlerEnabled() ) |
c801d85f | 918 | { |
22c2307c VZ |
919 | // if we have a validator, it has higher priority than our own event |
920 | // table | |
4caf847c VZ |
921 | #if wxUSE_VALIDATORS |
922 | if ( TryValidator(event) ) | |
923 | return TRUE; | |
924 | #endif // wxUSE_VALIDATORS | |
925 | ||
22c2307c VZ |
926 | // Handle per-instance dynamic event tables first |
927 | if ( m_dynamicEvents && SearchDynamicEventTable(event) ) | |
928 | return TRUE; | |
0b746ba8 | 929 | |
22c2307c VZ |
930 | // Then static per-class event tables (and search upwards through the |
931 | // inheritance hierarchy) | |
932 | for ( const wxEventTable *table = GetEventTable(); | |
933 | table; | |
934 | table = table->baseTable ) | |
0b746ba8 | 935 | { |
193bf013 | 936 | if ( SearchEventTable((wxEventTable&)*table, event) ) |
0b746ba8 | 937 | return TRUE; |
0b746ba8 | 938 | } |
c801d85f KB |
939 | } |
940 | ||
0b746ba8 VZ |
941 | // Try going down the event handler chain |
942 | if ( GetNextHandler() ) | |
c801d85f | 943 | { |
0b746ba8 VZ |
944 | if ( GetNextHandler()->ProcessEvent(event) ) |
945 | return TRUE; | |
c801d85f | 946 | } |
c801d85f | 947 | |
22c2307c VZ |
948 | // Finally propagate the event upwards the window chain and/or to the |
949 | // application object as necessary | |
4caf847c | 950 | return TryParent(event); |
c801d85f KB |
951 | } |
952 | ||
953 | bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event) | |
954 | { | |
68662769 VZ |
955 | wxEventType eventType = event.GetEventType(); |
956 | int eventId = event.GetId(); | |
0b746ba8 | 957 | |
68662769 VZ |
958 | // BC++ doesn't like testing for m_fn without != 0 |
959 | for ( int i = 0; table.entries[i].m_fn != 0; i++ ) | |
c801d85f | 960 | { |
6e58645e VZ |
961 | // the line using reference exposes a bug in gcc: although it _seems_ |
962 | // to work, it leads to weird crashes later on during program | |
963 | // execution | |
964 | #ifdef __GNUG__ | |
965 | wxEventTableEntry entry = table.entries[i]; | |
966 | #else | |
68662769 | 967 | const wxEventTableEntry& entry = table.entries[i]; |
6e58645e | 968 | #endif |
68662769 VZ |
969 | |
970 | // match only if the event type is the same and the id is either -1 in | |
971 | // the event table (meaning "any") or the event id matches the id | |
972 | // specified in the event table either exactly or by falling into | |
973 | // range between first and last | |
974 | if ( eventType == entry.m_eventType ) | |
0b746ba8 | 975 | { |
68662769 VZ |
976 | int tableId1 = entry.m_id, |
977 | tableId2 = entry.m_lastId; | |
978 | ||
979 | if ( (tableId1 == -1) || | |
980 | (tableId2 == -1 && eventId == tableId1) || | |
981 | (tableId2 != -1 && | |
982 | (eventId >= tableId1 && eventId <= tableId2)) ) | |
983 | { | |
984 | event.Skip(FALSE); | |
985 | event.m_callbackUserData = entry.m_callbackUserData; | |
0b746ba8 | 986 | |
68662769 | 987 | (this->*((wxEventFunction) (entry.m_fn)))(event); |
0b746ba8 | 988 | |
68662769 VZ |
989 | return !event.GetSkipped(); |
990 | } | |
0b746ba8 | 991 | } |
c801d85f | 992 | } |
68662769 | 993 | |
0b746ba8 | 994 | return FALSE; |
c801d85f | 995 | } |
97d7bfb8 | 996 | |
debe6624 | 997 | void wxEvtHandler::Connect( int id, int lastId, |
77d4384e | 998 | int eventType, |
0b746ba8 | 999 | wxObjectEventFunction func, |
65b17727 JS |
1000 | wxObject *userData, |
1001 | wxEvtHandler* eventSink ) | |
fe71f65c | 1002 | { |
cbee8f8d | 1003 | #if WXWIN_COMPATIBILITY_EVENT_TYPES |
2e4df4bf | 1004 | wxEventTableEntry *entry = new wxEventTableEntry; |
cbee8f8d VZ |
1005 | entry->m_eventType = eventType; |
1006 | entry->m_id = id; | |
1007 | entry->m_lastId = lastId; | |
1008 | entry->m_fn = func; | |
1009 | entry->m_callbackUserData = userData; | |
1010 | #else // !WXWIN_COMPATIBILITY_EVENT_TYPES | |
0b5eceb6 | 1011 | wxDynamicEventTableEntry *entry = |
65b17727 | 1012 | new wxDynamicEventTableEntry(eventType, id, lastId, func, userData, eventSink); |
cbee8f8d | 1013 | #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES |
0b746ba8 VZ |
1014 | |
1015 | if (!m_dynamicEvents) | |
1016 | m_dynamicEvents = new wxList; | |
1017 | ||
92309201 RD |
1018 | // Insert at the front of the list so most recent additions are found first |
1019 | m_dynamicEvents->Insert( (wxObject*) entry ); | |
fe71f65c | 1020 | } |
97d7bfb8 RR |
1021 | |
1022 | bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType, | |
1023 | wxObjectEventFunction func, | |
65b17727 JS |
1024 | wxObject *userData, |
1025 | wxEvtHandler* eventSink ) | |
97d7bfb8 RR |
1026 | { |
1027 | if (!m_dynamicEvents) | |
1028 | return FALSE; | |
cfe17b74 | 1029 | |
df5168c4 | 1030 | wxList::compatibility_iterator node = m_dynamicEvents->GetFirst(); |
97d7bfb8 RR |
1031 | while (node) |
1032 | { | |
2e4df4bf | 1033 | #if WXWIN_COMPATIBILITY_EVENT_TYPES |
b1d4dd7a | 1034 | wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData(); |
2e4df4bf | 1035 | #else // !WXWIN_COMPATIBILITY_EVENT_TYPES |
b1d4dd7a | 1036 | wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData(); |
2e4df4bf VZ |
1037 | #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES |
1038 | ||
97d7bfb8 RR |
1039 | if ((entry->m_id == id) && |
1040 | ((entry->m_lastId == lastId) || (lastId == -1)) && | |
1041 | ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) && | |
1042 | ((entry->m_fn == func) || (func == (wxObjectEventFunction)NULL)) && | |
65b17727 | 1043 | ((entry->m_eventSink == eventSink) || (eventSink == (wxEvtHandler*)NULL)) && |
97d7bfb8 RR |
1044 | ((entry->m_callbackUserData == userData) || (userData == (wxObject*)NULL))) |
1045 | { | |
2e4df4bf VZ |
1046 | if (entry->m_callbackUserData) |
1047 | delete entry->m_callbackUserData; | |
df5168c4 | 1048 | m_dynamicEvents->Erase( node ); |
97d7bfb8 RR |
1049 | delete entry; |
1050 | return TRUE; | |
1051 | } | |
b1d4dd7a | 1052 | node = node->GetNext(); |
97d7bfb8 RR |
1053 | } |
1054 | return FALSE; | |
1055 | } | |
fe71f65c RR |
1056 | |
1057 | bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event ) | |
1058 | { | |
193bf013 | 1059 | wxCHECK_MSG( m_dynamicEvents, FALSE, |
223d09f6 | 1060 | wxT("caller should check that we have dynamic events") ); |
0b746ba8 VZ |
1061 | |
1062 | int commandId = event.GetId(); | |
1063 | ||
df5168c4 | 1064 | wxList::compatibility_iterator node = m_dynamicEvents->GetFirst(); |
0b746ba8 | 1065 | while (node) |
fe71f65c | 1066 | { |
2e4df4bf | 1067 | #if WXWIN_COMPATIBILITY_EVENT_TYPES |
b1d4dd7a | 1068 | wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData(); |
2e4df4bf | 1069 | #else // !WXWIN_COMPATIBILITY_EVENT_TYPES |
b1d4dd7a | 1070 | wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData(); |
2e4df4bf | 1071 | #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES |
0b746ba8 VZ |
1072 | |
1073 | if (entry->m_fn) | |
1074 | { | |
1075 | // Match, if event spec says any id will do (id == -1) | |
1076 | if ( (event.GetEventType() == entry->m_eventType) && | |
1077 | (entry->m_id == -1 || | |
1078 | (entry->m_lastId == -1 && commandId == entry->m_id) || | |
1079 | (entry->m_lastId != -1 && | |
1080 | (commandId >= entry->m_id && commandId <= entry->m_lastId))) ) | |
1081 | { | |
1082 | event.Skip(FALSE); | |
1083 | event.m_callbackUserData = entry->m_callbackUserData; | |
1084 | ||
65b17727 JS |
1085 | #if !WXWIN_COMPATIBILITY_EVENT_TYPES |
1086 | if (entry->m_eventSink) | |
1087 | ((entry->m_eventSink)->*((wxEventFunction) (entry->m_fn)))(event); | |
1088 | else | |
1089 | #endif | |
1090 | (this->*((wxEventFunction) (entry->m_fn)))(event); | |
0b746ba8 | 1091 | |
92309201 | 1092 | if ( ! event.GetSkipped() ) |
0b746ba8 VZ |
1093 | return TRUE; |
1094 | } | |
1095 | } | |
b1d4dd7a | 1096 | node = node->GetNext(); |
7b678698 | 1097 | } |
0b746ba8 | 1098 | return FALSE; |
fe71f65c RR |
1099 | }; |
1100 | ||
b88c44e7 RD |
1101 | void wxEvtHandler::DoSetClientObject( wxClientData *data ) |
1102 | { | |
1103 | wxASSERT_MSG( m_clientDataType != wxClientData_Void, | |
1104 | wxT("can't have both object and void client data") ); | |
1105 | ||
1106 | if ( m_clientObject ) | |
1107 | delete m_clientObject; | |
1108 | ||
1109 | m_clientObject = data; | |
1110 | m_clientDataType = wxClientData_Object; | |
1111 | } | |
1112 | ||
1113 | wxClientData *wxEvtHandler::DoGetClientObject() const | |
1114 | { | |
1115 | // it's not an error to call GetClientObject() on a window which doesn't | |
1116 | // have client data at all - NULL will be returned | |
1117 | wxASSERT_MSG( m_clientDataType != wxClientData_Void, | |
1118 | wxT("this window doesn't have object client data") ); | |
1119 | ||
1120 | return m_clientObject; | |
1121 | } | |
1122 | ||
1123 | void wxEvtHandler::DoSetClientData( void *data ) | |
1124 | { | |
1125 | wxASSERT_MSG( m_clientDataType != wxClientData_Object, | |
1126 | wxT("can't have both object and void client data") ); | |
1127 | ||
1128 | m_clientData = data; | |
1129 | m_clientDataType = wxClientData_Void; | |
1130 | } | |
1131 | ||
1132 | void *wxEvtHandler::DoGetClientData() const | |
1133 | { | |
1134 | // it's not an error to call GetClientData() on a window which doesn't have | |
1135 | // client data at all - NULL will be returned | |
1136 | wxASSERT_MSG( m_clientDataType != wxClientData_Object, | |
1137 | wxT("this window doesn't have void client data") ); | |
1138 | ||
1139 | return m_clientData; | |
1140 | } | |
1141 | ||
1142 | ||
e3065973 | 1143 | #if WXWIN_COMPATIBILITY |
0b746ba8 | 1144 | bool wxEvtHandler::OnClose() |
c801d85f | 1145 | { |
0b746ba8 VZ |
1146 | if (GetNextHandler()) |
1147 | return GetNextHandler()->OnClose(); | |
1148 | else | |
1149 | return FALSE; | |
c801d85f | 1150 | } |
193bf013 | 1151 | #endif // WXWIN_COMPATIBILITY |
e3065973 | 1152 | |
4caf847c VZ |
1153 | #endif // wxUSE_BASE |
1154 | ||
e90c1d2a VZ |
1155 | #if wxUSE_GUI |
1156 | ||
e702ff0f JS |
1157 | // Find a window with the focus, that is also a descendant of the given window. |
1158 | // This is used to determine the window to initially send commands to. | |
1159 | wxWindow* wxFindFocusDescendant(wxWindow* ancestor) | |
1160 | { | |
1161 | // Process events starting with the window with the focus, if any. | |
1162 | wxWindow* focusWin = wxWindow::FindFocus(); | |
1163 | wxWindow* win = focusWin; | |
1164 | ||
1165 | // Check if this is a descendant of this frame. | |
1166 | // If not, win will be set to NULL. | |
1167 | while (win) | |
1168 | { | |
1169 | if (win == ancestor) | |
1170 | break; | |
1171 | else | |
1172 | win = win->GetParent(); | |
1173 | } | |
1174 | if (win == (wxWindow*) NULL) | |
1175 | focusWin = (wxWindow*) NULL; | |
1176 | ||
1177 | return focusWin; | |
1178 | } | |
1179 | ||
e90c1d2a | 1180 | #endif // wxUSE_GUI |