]>
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$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
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" | |
47 | #endif // wxUSE_GUI | |
c801d85f | 48 | |
8e193f38 VZ |
49 | // ---------------------------------------------------------------------------- |
50 | // wxWin macros | |
51 | // ---------------------------------------------------------------------------- | |
52 | ||
0b746ba8 VZ |
53 | IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject) |
54 | IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject) | |
0b746ba8 | 55 | IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent) |
e90c1d2a VZ |
56 | |
57 | #if wxUSE_GUI | |
58 | IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent) | |
59 | IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent) | |
60 | IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent) | |
61 | IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent, wxEvent) | |
62 | IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent) | |
63 | IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent) | |
64 | IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent) | |
65 | IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent) | |
66 | IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent) | |
67 | IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent) | |
68 | IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent) | |
69 | IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent) | |
70 | IMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent) | |
71 | IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent) | |
72 | IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent) | |
73 | IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent) | |
74 | IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent) | |
75 | IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent) | |
76 | IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent) | |
77 | IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent) | |
78 | IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent) | |
79 | IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent) | |
80 | IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxCommandEvent) | |
81 | IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, wxEvent) | |
82 | IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent, wxEvent) | |
83 | IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent, wxEvent) | |
84 | IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent, wxEvent) | |
85 | #endif // wxUSE_GUI | |
0b746ba8 VZ |
86 | |
87 | const wxEventTable *wxEvtHandler::GetEventTable() const | |
88 | { return &wxEvtHandler::sm_eventTable; } | |
89 | ||
90 | const wxEventTable wxEvtHandler::sm_eventTable = | |
91 | { (const wxEventTable *)NULL, &wxEvtHandler::sm_eventTableEntries[0] }; | |
92 | ||
93 | const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] = | |
58d1c1ae | 94 | { { 0, 0, 0, (wxObjectEventFunction) NULL, (wxObject*) NULL } }; |
0b746ba8 | 95 | |
c801d85f | 96 | |
8e193f38 VZ |
97 | // ---------------------------------------------------------------------------- |
98 | // global variables | |
99 | // ---------------------------------------------------------------------------- | |
100 | ||
101 | // To put pending event handlers | |
102 | wxList *wxPendingEvents = (wxList *)NULL; | |
103 | ||
7214297d | 104 | #if wxUSE_THREADS |
8e193f38 VZ |
105 | // protects wxPendingEvents list |
106 | wxCriticalSection *wxPendingEventsLocker = (wxCriticalSection *)NULL; | |
7214297d GL |
107 | #endif |
108 | ||
8e193f38 VZ |
109 | // ============================================================================ |
110 | // implementation | |
111 | // ============================================================================ | |
112 | ||
113 | // ---------------------------------------------------------------------------- | |
114 | // wxEvent | |
115 | // ---------------------------------------------------------------------------- | |
116 | ||
c801d85f KB |
117 | /* |
118 | * General wxWindows events, covering | |
119 | * all interesting things that might happen (button clicking, resizing, | |
120 | * setting text in widgets, etc.). | |
121 | * | |
122 | * For each completely new event type, derive a new event class. | |
123 | * | |
124 | */ | |
125 | ||
126 | wxEvent::wxEvent(int theId) | |
127 | { | |
0b746ba8 VZ |
128 | m_eventType = wxEVT_NULL; |
129 | m_eventObject = (wxObject *) NULL; | |
0b746ba8 VZ |
130 | m_timeStamp = 0; |
131 | m_id = theId; | |
132 | m_skipped = FALSE; | |
133 | m_callbackUserData = (wxObject *) NULL; | |
193bf013 | 134 | m_isCommandEvent = FALSE; |
c801d85f KB |
135 | } |
136 | ||
aadbdf11 | 137 | void wxEvent::CopyObject(wxObject& object_dest) const |
a737331d | 138 | { |
e90c1d2a | 139 | wxEvent *obj = (wxEvent *)&object_dest; |
aadbdf11 GL |
140 | wxObject::CopyObject(object_dest); |
141 | ||
142 | obj->m_eventType = m_eventType; | |
143 | obj->m_eventObject = m_eventObject; | |
aadbdf11 GL |
144 | obj->m_timeStamp = m_timeStamp; |
145 | obj->m_id = m_id; | |
146 | obj->m_skipped = m_skipped; | |
147 | obj->m_callbackUserData = m_callbackUserData; | |
148 | obj->m_isCommandEvent = m_isCommandEvent; | |
a737331d GL |
149 | } |
150 | ||
e90c1d2a VZ |
151 | #if wxUSE_GUI |
152 | ||
c801d85f KB |
153 | /* |
154 | * Command events | |
155 | * | |
156 | */ | |
157 | ||
7798a18e | 158 | wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId) |
c801d85f | 159 | { |
0b746ba8 VZ |
160 | m_eventType = commandType; |
161 | m_clientData = (char *) NULL; | |
162 | m_clientObject = (wxClientData *) NULL; | |
163 | m_extraLong = 0; | |
164 | m_commandInt = 0; | |
165 | m_id = theId; | |
04392d70 | 166 | m_commandString = wxEmptyString; |
193bf013 | 167 | m_isCommandEvent = TRUE; |
c801d85f KB |
168 | } |
169 | ||
aadbdf11 GL |
170 | void wxCommandEvent::CopyObject(wxObject& obj_d) const |
171 | { | |
e90c1d2a | 172 | wxCommandEvent *obj = (wxCommandEvent *)&obj_d; |
aadbdf11 GL |
173 | |
174 | wxEvent::CopyObject(obj_d); | |
175 | ||
176 | obj->m_clientData = m_clientData; | |
177 | obj->m_clientObject = m_clientObject; | |
178 | obj->m_extraLong = m_extraLong; | |
179 | obj->m_commandInt = m_commandInt; | |
180 | } | |
181 | ||
c801d85f KB |
182 | /* |
183 | * Scroll events | |
184 | */ | |
185 | ||
0b746ba8 VZ |
186 | wxScrollEvent::wxScrollEvent(wxEventType commandType, |
187 | int id, | |
188 | int pos, | |
189 | int orient) | |
190 | : wxCommandEvent(commandType, id) | |
c801d85f | 191 | { |
0b746ba8 VZ |
192 | m_extraLong = orient; |
193 | m_commandInt = pos; | |
c801d85f KB |
194 | } |
195 | ||
d1367c3d RR |
196 | /* |
197 | * ScrollWin events | |
198 | */ | |
199 | ||
200 | wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType, | |
201 | int pos, | |
202 | int orient) | |
d1367c3d | 203 | { |
c5b42c87 | 204 | m_eventType = commandType; |
d1367c3d RR |
205 | m_extraLong = orient; |
206 | m_commandInt = pos; | |
207 | } | |
208 | ||
3c679789 RR |
209 | void wxScrollWinEvent::CopyObject(wxObject& obj_d) const |
210 | { | |
e90c1d2a | 211 | wxScrollWinEvent *obj = (wxScrollWinEvent*)&obj_d; |
3c679789 RR |
212 | |
213 | wxEvent::CopyObject(obj_d); | |
214 | ||
215 | obj->m_extraLong = m_extraLong; | |
216 | obj->m_commandInt = m_commandInt; | |
217 | } | |
218 | ||
c801d85f KB |
219 | /* |
220 | * Mouse events | |
221 | * | |
222 | */ | |
223 | ||
7798a18e | 224 | wxMouseEvent::wxMouseEvent(wxEventType commandType) |
c801d85f | 225 | { |
0b746ba8 VZ |
226 | m_eventType = commandType; |
227 | m_metaDown = FALSE; | |
228 | m_altDown = FALSE; | |
229 | m_controlDown = FALSE; | |
230 | m_shiftDown = FALSE; | |
231 | m_leftDown = FALSE; | |
232 | m_rightDown = FALSE; | |
233 | m_middleDown = FALSE; | |
234 | m_x = 0; | |
235 | m_y = 0; | |
c801d85f KB |
236 | } |
237 | ||
aadbdf11 GL |
238 | void wxMouseEvent::CopyObject(wxObject& obj_d) const |
239 | { | |
240 | wxMouseEvent *obj = (wxMouseEvent *)&obj_d; | |
241 | ||
242 | wxEvent::CopyObject(obj_d); | |
243 | ||
244 | obj->m_metaDown = m_metaDown; | |
245 | obj->m_altDown = m_altDown; | |
246 | obj->m_controlDown = m_controlDown; | |
247 | obj->m_shiftDown = m_shiftDown; | |
248 | obj->m_leftDown = m_leftDown; | |
249 | obj->m_rightDown = m_rightDown; | |
250 | obj->m_middleDown = m_middleDown; | |
251 | obj->m_x = m_x; | |
252 | obj->m_y = m_y; | |
253 | } | |
254 | ||
c801d85f KB |
255 | // True if was a button dclick event (1 = left, 2 = middle, 3 = right) |
256 | // or any button dclick event (but = -1) | |
257 | bool wxMouseEvent::ButtonDClick(int but) const | |
258 | { | |
0b746ba8 VZ |
259 | switch (but) |
260 | { | |
261 | case -1: | |
262 | return (LeftDClick() || MiddleDClick() || RightDClick()); | |
263 | case 1: | |
264 | return LeftDClick(); | |
265 | case 2: | |
266 | return MiddleDClick(); | |
267 | case 3: | |
268 | return RightDClick(); | |
269 | default: | |
223d09f6 | 270 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick")); |
0b746ba8 VZ |
271 | } |
272 | ||
273 | return FALSE; | |
c801d85f KB |
274 | } |
275 | ||
276 | // True if was a button down event (1 = left, 2 = middle, 3 = right) | |
277 | // or any button down event (but = -1) | |
278 | bool wxMouseEvent::ButtonDown(int but) const | |
279 | { | |
0b746ba8 VZ |
280 | switch (but) |
281 | { | |
282 | case -1: | |
283 | return (LeftDown() || MiddleDown() || RightDown()); | |
284 | case 1: | |
285 | return LeftDown(); | |
286 | case 2: | |
287 | return MiddleDown(); | |
288 | case 3: | |
289 | return RightDown(); | |
290 | default: | |
223d09f6 | 291 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown")); |
0b746ba8 VZ |
292 | } |
293 | ||
294 | return FALSE; | |
c801d85f KB |
295 | } |
296 | ||
297 | // True if was a button up event (1 = left, 2 = middle, 3 = right) | |
298 | // or any button up event (but = -1) | |
299 | bool wxMouseEvent::ButtonUp(int but) const | |
300 | { | |
0b746ba8 VZ |
301 | switch (but) { |
302 | case -1: | |
303 | return (LeftUp() || MiddleUp() || RightUp()); | |
304 | case 1: | |
305 | return LeftUp(); | |
306 | case 2: | |
307 | return MiddleUp(); | |
308 | case 3: | |
309 | return RightUp(); | |
310 | default: | |
223d09f6 | 311 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp")); |
0b746ba8 VZ |
312 | } |
313 | ||
314 | return FALSE; | |
c801d85f KB |
315 | } |
316 | ||
317 | // True if the given button is currently changing state | |
318 | bool wxMouseEvent::Button(int but) const | |
319 | { | |
0b746ba8 VZ |
320 | switch (but) { |
321 | case -1: | |
72cdf4c9 | 322 | return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1)); |
0b746ba8 VZ |
323 | case 1: |
324 | return (LeftDown() || LeftUp() || LeftDClick()); | |
325 | case 2: | |
326 | return (MiddleDown() || MiddleUp() || MiddleDClick()); | |
327 | case 3: | |
328 | return (RightDown() || RightUp() || RightDClick()); | |
329 | default: | |
223d09f6 | 330 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button")); |
0b746ba8 VZ |
331 | } |
332 | ||
333 | return FALSE; | |
c801d85f KB |
334 | } |
335 | ||
336 | bool wxMouseEvent::ButtonIsDown(int but) const | |
337 | { | |
0b746ba8 VZ |
338 | switch (but) { |
339 | case -1: | |
340 | return (LeftIsDown() || MiddleIsDown() || RightIsDown()); | |
341 | case 1: | |
342 | return LeftIsDown(); | |
343 | case 2: | |
344 | return MiddleIsDown(); | |
345 | case 3: | |
346 | return RightIsDown(); | |
347 | default: | |
223d09f6 | 348 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown")); |
0b746ba8 VZ |
349 | } |
350 | ||
351 | return FALSE; | |
c801d85f KB |
352 | } |
353 | ||
354 | // Find the logical position of the event given the DC | |
355 | wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const | |
356 | { | |
0757d27c JS |
357 | wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y)); |
358 | return pt; | |
c801d85f KB |
359 | } |
360 | ||
361 | ||
362 | /* | |
363 | * Keyboard events | |
364 | * | |
365 | */ | |
366 | ||
7798a18e | 367 | wxKeyEvent::wxKeyEvent(wxEventType type) |
c801d85f | 368 | { |
0b746ba8 VZ |
369 | m_eventType = type; |
370 | m_shiftDown = FALSE; | |
371 | m_controlDown = FALSE; | |
372 | m_metaDown = FALSE; | |
373 | m_altDown = FALSE; | |
374 | m_keyCode = 0; | |
b0e813a0 | 375 | m_scanCode = 0; |
c801d85f KB |
376 | } |
377 | ||
aadbdf11 GL |
378 | void wxKeyEvent::CopyObject(wxObject& obj_d) const |
379 | { | |
380 | wxKeyEvent *obj = (wxKeyEvent *)&obj_d; | |
381 | wxEvent::CopyObject(obj_d); | |
382 | ||
383 | obj->m_shiftDown = m_shiftDown; | |
384 | obj->m_controlDown = m_controlDown; | |
385 | obj->m_metaDown = m_metaDown; | |
386 | obj->m_altDown = m_altDown; | |
387 | obj->m_keyCode = m_keyCode; | |
388 | } | |
389 | ||
390 | ||
391 | /* | |
392 | * Misc events | |
393 | */ | |
394 | ||
395 | void wxSizeEvent::CopyObject(wxObject& obj_d) const | |
396 | { | |
397 | wxSizeEvent *obj = (wxSizeEvent *)&obj_d; | |
398 | wxEvent::CopyObject(obj_d); | |
399 | ||
400 | obj->m_size = m_size; | |
401 | } | |
402 | ||
403 | void wxMoveEvent::CopyObject(wxObject& obj_d) const | |
404 | { | |
405 | wxMoveEvent *obj = (wxMoveEvent *)&obj_d; | |
406 | wxEvent::CopyObject(obj_d); | |
407 | ||
408 | obj->m_pos = m_pos; | |
409 | } | |
410 | ||
411 | void wxEraseEvent::CopyObject(wxObject& obj_d) const | |
412 | { | |
413 | wxEraseEvent *obj = (wxEraseEvent *)&obj_d; | |
414 | wxEvent::CopyObject(obj_d); | |
415 | ||
416 | obj->m_dc = m_dc; | |
417 | } | |
418 | ||
419 | void wxActivateEvent::CopyObject(wxObject& obj_d) const | |
420 | { | |
421 | wxActivateEvent *obj = (wxActivateEvent *)&obj_d; | |
422 | wxEvent::CopyObject(obj_d); | |
423 | ||
424 | obj->m_active = m_active; | |
425 | } | |
426 | ||
427 | void wxMenuEvent::CopyObject(wxObject& obj_d) const | |
428 | { | |
429 | wxMenuEvent *obj = (wxMenuEvent *)&obj_d; | |
430 | wxEvent::CopyObject(obj_d); | |
431 | ||
432 | obj->m_menuId = m_menuId; | |
433 | } | |
434 | ||
435 | void wxCloseEvent::CopyObject(wxObject& obj_d) const | |
436 | { | |
437 | wxCloseEvent *obj = (wxCloseEvent *)&obj_d; | |
438 | wxEvent::CopyObject(obj_d); | |
439 | ||
440 | obj->m_loggingOff = m_loggingOff; | |
441 | obj->m_veto = m_veto; | |
442 | #if WXWIN_COMPATIBILITY | |
443 | obj->m_force = m_force; | |
444 | #endif | |
445 | obj->m_canVeto = m_canVeto; | |
446 | } | |
e90c1d2a | 447 | |
aadbdf11 GL |
448 | void wxShowEvent::CopyObject(wxObject& obj_d) const |
449 | { | |
450 | wxShowEvent *obj = (wxShowEvent *)&obj_d; | |
451 | wxEvent::CopyObject(obj_d); | |
452 | ||
453 | obj->m_show = m_show; | |
454 | } | |
f305c661 GL |
455 | |
456 | void wxJoystickEvent::CopyObject(wxObject& obj_d) const | |
457 | { | |
458 | wxJoystickEvent *obj = (wxJoystickEvent *)&obj_d; | |
459 | wxEvent::CopyObject(obj_d); | |
460 | ||
461 | obj->m_pos = m_pos; | |
462 | obj->m_zPosition = m_zPosition; | |
463 | obj->m_buttonChange = m_buttonChange; | |
464 | obj->m_buttonState = m_buttonState; | |
465 | obj->m_joyStick = m_joyStick; | |
e90c1d2a | 466 | } |
f305c661 GL |
467 | |
468 | void wxDropFilesEvent::CopyObject(wxObject& obj_d) const | |
469 | { | |
470 | wxDropFilesEvent *obj = (wxDropFilesEvent *)&obj_d; | |
471 | wxEvent::CopyObject(obj_d); | |
472 | ||
473 | obj->m_noFiles = m_noFiles; | |
474 | obj->m_pos = m_pos; | |
475 | // TODO: Problem with obj->m_files. It should be deallocated by the | |
e90c1d2a | 476 | // destructor of the event. |
f305c661 GL |
477 | } |
478 | ||
479 | void wxUpdateUIEvent::CopyObject(wxObject &obj_d) const | |
480 | { | |
481 | wxUpdateUIEvent *obj = (wxUpdateUIEvent *)&obj_d; | |
482 | wxEvent::CopyObject(obj_d); | |
483 | ||
484 | obj->m_checked = m_checked; | |
485 | obj->m_enabled = m_enabled; | |
486 | obj->m_text = m_text; | |
487 | obj->m_setText = m_setText; | |
488 | obj->m_setChecked = m_setChecked; | |
489 | obj->m_setEnabled = m_setEnabled; | |
490 | } | |
491 | ||
492 | void wxPaletteChangedEvent::CopyObject(wxObject &obj_d) const | |
493 | { | |
494 | wxPaletteChangedEvent *obj = (wxPaletteChangedEvent *)&obj_d; | |
495 | wxEvent::CopyObject(obj_d); | |
496 | ||
497 | obj->m_changedWindow = m_changedWindow; | |
498 | } | |
499 | ||
500 | void wxQueryNewPaletteEvent::CopyObject(wxObject& obj_d) const | |
501 | { | |
502 | wxQueryNewPaletteEvent *obj = (wxQueryNewPaletteEvent *)&obj_d; | |
503 | wxEvent::CopyObject(obj_d); | |
504 | ||
505 | obj->m_paletteRealized = m_paletteRealized; | |
506 | } | |
aadbdf11 | 507 | |
42e69d6b VZ |
508 | wxWindowCreateEvent::wxWindowCreateEvent(wxWindow *win) |
509 | : wxEvent(wxEVT_CREATE) | |
510 | { | |
511 | SetEventObject(win); | |
512 | } | |
513 | ||
514 | wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow *win) | |
515 | : wxEvent(wxEVT_DESTROY) | |
516 | { | |
517 | SetEventObject(win); | |
518 | } | |
519 | ||
e90c1d2a VZ |
520 | #endif // wxUSE_GUI |
521 | ||
522 | void wxIdleEvent::CopyObject(wxObject& obj_d) const | |
523 | { | |
524 | wxIdleEvent *obj = (wxIdleEvent *)&obj_d; | |
525 | wxEvent::CopyObject(obj_d); | |
526 | ||
527 | obj->m_requestMore = m_requestMore; | |
528 | } | |
529 | ||
c801d85f KB |
530 | /* |
531 | * Event handler | |
532 | */ | |
533 | ||
0b746ba8 | 534 | wxEvtHandler::wxEvtHandler() |
c801d85f | 535 | { |
0b746ba8 VZ |
536 | m_nextHandler = (wxEvtHandler *) NULL; |
537 | m_previousHandler = (wxEvtHandler *) NULL; | |
538 | m_enabled = TRUE; | |
539 | m_dynamicEvents = (wxList *) NULL; | |
193bf013 | 540 | m_isWindow = FALSE; |
8e193f38 | 541 | m_pendingEvents = (wxList *) NULL; |
7214297d | 542 | #if wxUSE_THREADS |
41404da7 | 543 | # if !defined(__VISAGECPP__) |
8e193f38 | 544 | m_eventsLocker = new wxCriticalSection; |
41404da7 | 545 | # endif |
7214297d | 546 | #endif |
c801d85f KB |
547 | } |
548 | ||
0b746ba8 | 549 | wxEvtHandler::~wxEvtHandler() |
c801d85f | 550 | { |
0b746ba8 VZ |
551 | // Takes itself out of the list of handlers |
552 | if (m_previousHandler) | |
553 | m_previousHandler->m_nextHandler = m_nextHandler; | |
554 | ||
555 | if (m_nextHandler) | |
556 | m_nextHandler->m_previousHandler = m_previousHandler; | |
557 | ||
558 | if (m_dynamicEvents) | |
fe71f65c | 559 | { |
0b746ba8 VZ |
560 | wxNode *node = m_dynamicEvents->First(); |
561 | while (node) | |
562 | { | |
563 | wxEventTableEntry *entry = (wxEventTableEntry*)node->Data(); | |
564 | if (entry->m_callbackUserData) delete entry->m_callbackUserData; | |
565 | delete entry; | |
566 | node = node->Next(); | |
567 | } | |
568 | delete m_dynamicEvents; | |
569 | }; | |
7214297d | 570 | |
8e193f38 | 571 | delete m_pendingEvents; |
7214297d | 572 | |
8e193f38 | 573 | #if wxUSE_THREADS |
41404da7 | 574 | # if !defined(__VISAGECPP__) |
7214297d | 575 | delete m_eventsLocker; |
41404da7 | 576 | # endif |
7214297d | 577 | #endif |
c801d85f KB |
578 | } |
579 | ||
7214297d | 580 | #if wxUSE_THREADS |
aadbdf11 | 581 | |
7214297d GL |
582 | bool wxEvtHandler::ProcessThreadEvent(wxEvent& event) |
583 | { | |
7214297d | 584 | // check that we are really in a child thread |
8e193f38 VZ |
585 | wxASSERT_MSG( !wxThread::IsMain(), |
586 | wxT("use ProcessEvent() in main thread") ); | |
587 | ||
588 | AddPendingEvent(event); | |
7214297d | 589 | |
8e193f38 VZ |
590 | return TRUE; |
591 | } | |
592 | ||
593 | #endif // wxUSE_THREADS | |
594 | ||
595 | void wxEvtHandler::AddPendingEvent(wxEvent& event) | |
596 | { | |
16c1f79c RR |
597 | // 1) Add event to list of pending events of this event handler |
598 | ||
599 | #if defined(__VISAGECPP__) | |
600 | wxENTER_CRIT_SECT( m_eventsLocker); | |
601 | #else | |
602 | wxENTER_CRIT_SECT( *m_eventsLocker); | |
603 | #endif | |
604 | ||
8e193f38 VZ |
605 | if ( !m_pendingEvents ) |
606 | m_pendingEvents = new wxList; | |
7214297d | 607 | |
8e193f38 | 608 | wxEvent *event2 = (wxEvent *)event.Clone(); |
7214297d | 609 | |
8e193f38 | 610 | m_pendingEvents->Append(event2); |
7214297d | 611 | |
16c1f79c RR |
612 | #if defined(__VISAGECPP__) |
613 | wxLEAVE_CRIT_SECT( m_eventsLocker); | |
614 | #else | |
615 | wxLEAVE_CRIT_SECT( *m_eventsLocker); | |
616 | #endif | |
617 | ||
618 | // 2) Add this event handler to list of event handlers that | |
619 | // have pending events. | |
620 | ||
b568d04f | 621 | wxENTER_CRIT_SECT(*wxPendingEventsLocker); |
72cdf4c9 | 622 | |
8e193f38 VZ |
623 | if ( !wxPendingEvents ) |
624 | wxPendingEvents = new wxList; | |
4d3a259a | 625 | wxPendingEvents->Append(this); |
72cdf4c9 | 626 | |
16c1f79c RR |
627 | // 3) Inform the system that new pending events are somwehere, |
628 | // and that these should be processed in idle time. | |
629 | ||
bf9e3e73 | 630 | wxWakeUpIdle(); |
ba5b8263 RR |
631 | |
632 | wxLEAVE_CRIT_SECT(*wxPendingEventsLocker); | |
7214297d GL |
633 | } |
634 | ||
635 | void wxEvtHandler::ProcessPendingEvents() | |
636 | { | |
41404da7 | 637 | #if defined(__VISAGECPP__) |
16c1f79c | 638 | wxENTER_CRIT_SECT( m_eventsLocker); |
b568d04f | 639 | #else |
16c1f79c | 640 | wxENTER_CRIT_SECT( *m_eventsLocker); |
41404da7 | 641 | #endif |
8e193f38 | 642 | |
7214297d | 643 | wxNode *node = m_pendingEvents->First(); |
8e193f38 VZ |
644 | while ( node ) |
645 | { | |
16c1f79c RR |
646 | wxEvent *event = (wxEvent *)node->Data(); |
647 | delete node; | |
648 | ||
649 | // In ProcessEvent, new events might get added and | |
650 | // we can safely leave the crtical section here. | |
651 | #if defined(__VISAGECPP__) | |
652 | wxLEAVE_CRIT_SECT( m_eventsLocker); | |
653 | #else | |
654 | wxLEAVE_CRIT_SECT( *m_eventsLocker); | |
655 | #endif | |
8e193f38 | 656 | ProcessEvent(*event); |
9779893b | 657 | delete event; |
16c1f79c RR |
658 | #if defined(__VISAGECPP__) |
659 | wxENTER_CRIT_SECT( m_eventsLocker); | |
660 | #else | |
661 | wxENTER_CRIT_SECT( *m_eventsLocker); | |
662 | #endif | |
663 | ||
8e193f38 | 664 | node = m_pendingEvents->First(); |
7214297d | 665 | } |
16c1f79c RR |
666 | |
667 | #if defined(__VISAGECPP__) | |
668 | wxLEAVE_CRIT_SECT( m_eventsLocker); | |
669 | #else | |
670 | wxLEAVE_CRIT_SECT( *m_eventsLocker); | |
671 | #endif | |
7214297d | 672 | } |
7214297d | 673 | |
c801d85f KB |
674 | /* |
675 | * Event table stuff | |
676 | */ | |
677 | ||
678 | bool wxEvtHandler::ProcessEvent(wxEvent& event) | |
679 | { | |
e90c1d2a | 680 | #if wxUSE_GUI |
8e193f38 | 681 | // check that our flag corresponds to reality |
193bf013 | 682 | wxASSERT( m_isWindow == IsKindOf(CLASSINFO(wxWindow)) ); |
e90c1d2a | 683 | #endif // wxUSE_GUI |
0b746ba8 | 684 | |
8e193f38 | 685 | // An event handler can be enabled or disabled |
0b746ba8 | 686 | if ( GetEvtHandlerEnabled() ) |
c801d85f | 687 | { |
7214297d | 688 | #if wxUSE_THREADS |
8e193f38 VZ |
689 | // Check whether we are in a child thread. |
690 | if ( !wxThread::IsMain() ) | |
7214297d | 691 | return ProcessThreadEvent(event); |
8e193f38 | 692 | #endif // wxUSE_THREADS |
0757d27c | 693 | |
8e193f38 | 694 | // Handle per-instance dynamic event tables first |
193bf013 | 695 | if ( m_dynamicEvents && SearchDynamicEventTable(event) ) |
0757d27c | 696 | return TRUE; |
0b746ba8 | 697 | |
8e193f38 | 698 | // Then static per-class event tables |
0b746ba8 VZ |
699 | const wxEventTable *table = GetEventTable(); |
700 | ||
e90c1d2a | 701 | #if wxUSE_GUI && wxUSE_VALIDATORS |
0b746ba8 VZ |
702 | // Try the associated validator first, if this is a window. |
703 | // Problem: if the event handler of the window has been replaced, | |
704 | // this wxEvtHandler may no longer be a window. | |
705 | // Therefore validators won't be processed if the handler | |
706 | // has been replaced with SetEventHandler. | |
707 | // THIS CAN BE CURED if PushEventHandler is used instead of | |
708 | // SetEventHandler, and then processing will be passed down the | |
709 | // chain of event handlers. | |
ce4169a4 | 710 | if (m_isWindow) |
0b746ba8 VZ |
711 | { |
712 | wxWindow *win = (wxWindow *)this; | |
713 | ||
714 | // Can only use the validator of the window which | |
715 | // is receiving the event | |
193bf013 | 716 | if ( win == event.GetEventObject() ) |
0b746ba8 | 717 | { |
193bf013 VZ |
718 | wxValidator *validator = win->GetValidator(); |
719 | if ( validator && validator->ProcessEvent(event) ) | |
720 | { | |
721 | return TRUE; | |
722 | } | |
0b746ba8 VZ |
723 | } |
724 | } | |
ce4169a4 | 725 | #endif |
0b746ba8 VZ |
726 | |
727 | // Search upwards through the inheritance hierarchy | |
ce4169a4 | 728 | while (table) |
0b746ba8 | 729 | { |
193bf013 | 730 | if ( SearchEventTable((wxEventTable&)*table, event) ) |
0b746ba8 VZ |
731 | return TRUE; |
732 | table = table->baseTable; | |
733 | } | |
c801d85f KB |
734 | } |
735 | ||
0b746ba8 VZ |
736 | // Try going down the event handler chain |
737 | if ( GetNextHandler() ) | |
c801d85f | 738 | { |
0b746ba8 VZ |
739 | if ( GetNextHandler()->ProcessEvent(event) ) |
740 | return TRUE; | |
c801d85f | 741 | } |
c801d85f | 742 | |
e90c1d2a | 743 | #if wxUSE_GUI |
0b746ba8 VZ |
744 | // Carry on up the parent-child hierarchy, |
745 | // but only if event is a command event: it wouldn't | |
746 | // make sense for a parent to receive a child's size event, for example | |
193bf013 | 747 | if ( m_isWindow && event.IsCommandEvent() ) |
0b746ba8 VZ |
748 | { |
749 | wxWindow *win = (wxWindow *)this; | |
750 | wxWindow *parent = win->GetParent(); | |
751 | if (parent && !parent->IsBeingDeleted()) | |
193bf013 | 752 | return parent->GetEventHandler()->ProcessEvent(event); |
0b746ba8 | 753 | } |
e90c1d2a | 754 | #endif // wxUSE_GUI |
0b746ba8 VZ |
755 | |
756 | // Last try - application object. | |
193bf013 | 757 | if ( wxTheApp && (this != wxTheApp) ) |
0b746ba8 | 758 | { |
193bf013 VZ |
759 | // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always |
760 | // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be | |
761 | // processed appropriately via SearchEventTable. | |
762 | if ( event.GetEventType() != wxEVT_IDLE ) | |
763 | { | |
764 | if ( wxTheApp->ProcessEvent(event) ) | |
765 | return TRUE; | |
766 | } | |
0b746ba8 VZ |
767 | } |
768 | ||
c801d85f KB |
769 | return FALSE; |
770 | } | |
771 | ||
772 | bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event) | |
773 | { | |
0b746ba8 VZ |
774 | int i = 0; |
775 | int commandId = event.GetId(); | |
776 | ||
777 | // BC++ doesn't like while (table.entries[i].m_fn) | |
778 | ||
2432b92d JS |
779 | #ifdef __SC__ |
780 | while (table.entries[i].m_fn != 0) | |
781 | #else | |
0b746ba8 | 782 | while (table.entries[i].m_fn != 0L) |
2432b92d | 783 | #endif |
c801d85f | 784 | { |
0b746ba8 VZ |
785 | if ((event.GetEventType() == table.entries[i].m_eventType) && |
786 | (table.entries[i].m_id == -1 || // Match, if event spec says any id will do (id == -1) | |
787 | (table.entries[i].m_lastId == -1 && commandId == table.entries[i].m_id) || | |
788 | (table.entries[i].m_lastId != -1 && | |
789 | (commandId >= table.entries[i].m_id && commandId <= table.entries[i].m_lastId)))) | |
790 | { | |
791 | event.Skip(FALSE); | |
792 | event.m_callbackUserData = table.entries[i].m_callbackUserData; | |
793 | ||
794 | (this->*((wxEventFunction) (table.entries[i].m_fn)))(event); | |
795 | ||
796 | if ( event.GetSkipped() ) | |
797 | return FALSE; | |
798 | else | |
799 | return TRUE; | |
800 | } | |
801 | i++; | |
c801d85f | 802 | } |
0b746ba8 | 803 | return FALSE; |
c801d85f | 804 | } |
97d7bfb8 | 805 | |
debe6624 | 806 | void wxEvtHandler::Connect( int id, int lastId, |
d4a23fee | 807 | wxEventType eventType, |
0b746ba8 VZ |
808 | wxObjectEventFunction func, |
809 | wxObject *userData ) | |
fe71f65c | 810 | { |
0b746ba8 VZ |
811 | wxEventTableEntry *entry = new wxEventTableEntry; |
812 | entry->m_id = id; | |
813 | entry->m_lastId = lastId; | |
814 | entry->m_eventType = eventType; | |
815 | entry->m_fn = func; | |
816 | entry->m_callbackUserData = userData; | |
817 | ||
818 | if (!m_dynamicEvents) | |
819 | m_dynamicEvents = new wxList; | |
820 | ||
821 | m_dynamicEvents->Append( (wxObject*) entry ); | |
fe71f65c | 822 | } |
97d7bfb8 RR |
823 | |
824 | bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType, | |
825 | wxObjectEventFunction func, | |
826 | wxObject *userData ) | |
827 | { | |
828 | if (!m_dynamicEvents) | |
829 | return FALSE; | |
830 | ||
831 | wxNode *node = m_dynamicEvents->First(); | |
832 | while (node) | |
833 | { | |
834 | wxEventTableEntry *entry = (wxEventTableEntry*)node->Data(); | |
835 | if ((entry->m_id == id) && | |
836 | ((entry->m_lastId == lastId) || (lastId == -1)) && | |
837 | ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) && | |
838 | ((entry->m_fn == func) || (func == (wxObjectEventFunction)NULL)) && | |
839 | ((entry->m_callbackUserData == userData) || (userData == (wxObject*)NULL))) | |
840 | { | |
841 | if (entry->m_callbackUserData) delete entry->m_callbackUserData; | |
842 | m_dynamicEvents->DeleteNode( node ); | |
843 | delete entry; | |
844 | return TRUE; | |
845 | } | |
846 | node = node->Next(); | |
847 | } | |
848 | return FALSE; | |
849 | } | |
fe71f65c RR |
850 | |
851 | bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event ) | |
852 | { | |
193bf013 | 853 | wxCHECK_MSG( m_dynamicEvents, FALSE, |
223d09f6 | 854 | wxT("caller should check that we have dynamic events") ); |
0b746ba8 VZ |
855 | |
856 | int commandId = event.GetId(); | |
857 | ||
858 | wxNode *node = m_dynamicEvents->First(); | |
859 | while (node) | |
fe71f65c | 860 | { |
0b746ba8 VZ |
861 | wxEventTableEntry *entry = (wxEventTableEntry*)node->Data(); |
862 | ||
863 | if (entry->m_fn) | |
864 | { | |
865 | // Match, if event spec says any id will do (id == -1) | |
866 | if ( (event.GetEventType() == entry->m_eventType) && | |
867 | (entry->m_id == -1 || | |
868 | (entry->m_lastId == -1 && commandId == entry->m_id) || | |
869 | (entry->m_lastId != -1 && | |
870 | (commandId >= entry->m_id && commandId <= entry->m_lastId))) ) | |
871 | { | |
872 | event.Skip(FALSE); | |
873 | event.m_callbackUserData = entry->m_callbackUserData; | |
874 | ||
875 | (this->*((wxEventFunction) (entry->m_fn)))(event); | |
876 | ||
877 | if (event.GetSkipped()) | |
878 | return FALSE; | |
879 | else | |
880 | return TRUE; | |
881 | } | |
882 | } | |
883 | node = node->Next(); | |
7b678698 | 884 | } |
0b746ba8 | 885 | return FALSE; |
fe71f65c RR |
886 | }; |
887 | ||
e3065973 | 888 | #if WXWIN_COMPATIBILITY |
0b746ba8 | 889 | bool wxEvtHandler::OnClose() |
c801d85f | 890 | { |
0b746ba8 VZ |
891 | if (GetNextHandler()) |
892 | return GetNextHandler()->OnClose(); | |
893 | else | |
894 | return FALSE; | |
c801d85f | 895 | } |
193bf013 | 896 | #endif // WXWIN_COMPATIBILITY |
e3065973 | 897 | |
e90c1d2a VZ |
898 | #if wxUSE_GUI |
899 | ||
e702ff0f JS |
900 | // Find a window with the focus, that is also a descendant of the given window. |
901 | // This is used to determine the window to initially send commands to. | |
902 | wxWindow* wxFindFocusDescendant(wxWindow* ancestor) | |
903 | { | |
904 | // Process events starting with the window with the focus, if any. | |
905 | wxWindow* focusWin = wxWindow::FindFocus(); | |
906 | wxWindow* win = focusWin; | |
907 | ||
908 | // Check if this is a descendant of this frame. | |
909 | // If not, win will be set to NULL. | |
910 | while (win) | |
911 | { | |
912 | if (win == ancestor) | |
913 | break; | |
914 | else | |
915 | win = win->GetParent(); | |
916 | } | |
917 | if (win == (wxWindow*) NULL) | |
918 | focusWin = (wxWindow*) NULL; | |
919 | ||
920 | return focusWin; | |
921 | } | |
922 | ||
e90c1d2a | 923 | #endif // wxUSE_GUI |