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