]>
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) | |
63 | ||
64 | const wxEventTable *wxEvtHandler::GetEventTable() const | |
65 | { return &wxEvtHandler::sm_eventTable; } | |
66 | ||
67 | const wxEventTable wxEvtHandler::sm_eventTable = | |
68 | { (const wxEventTable *)NULL, &wxEvtHandler::sm_eventTableEntries[0] }; | |
69 | ||
70 | const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] = | |
58d1c1ae | 71 | { { 0, 0, 0, (wxObjectEventFunction) NULL, (wxObject*) NULL } }; |
0b746ba8 VZ |
72 | |
73 | #endif // !USE_SHARED_LIBRARY | |
c801d85f | 74 | |
7214297d GL |
75 | #if wxUSE_THREADS |
76 | /* To put pending event handlers */ | |
4d3a259a GL |
77 | extern wxList *wxPendingEvents; |
78 | extern wxCriticalSection *wxPendingEventsLocker; | |
7214297d GL |
79 | #endif |
80 | ||
c801d85f KB |
81 | /* |
82 | * General wxWindows events, covering | |
83 | * all interesting things that might happen (button clicking, resizing, | |
84 | * setting text in widgets, etc.). | |
85 | * | |
86 | * For each completely new event type, derive a new event class. | |
87 | * | |
88 | */ | |
89 | ||
90 | wxEvent::wxEvent(int theId) | |
91 | { | |
0b746ba8 VZ |
92 | m_eventType = wxEVT_NULL; |
93 | m_eventObject = (wxObject *) NULL; | |
94 | m_eventHandle = (char *) NULL; | |
95 | m_timeStamp = 0; | |
96 | m_id = theId; | |
97 | m_skipped = FALSE; | |
98 | m_callbackUserData = (wxObject *) NULL; | |
193bf013 | 99 | m_isCommandEvent = FALSE; |
c801d85f KB |
100 | } |
101 | ||
aadbdf11 | 102 | void wxEvent::CopyObject(wxObject& object_dest) const |
a737331d | 103 | { |
aadbdf11 GL |
104 | wxEvent *obj = (wxEvent *)&object_dest; |
105 | wxObject::CopyObject(object_dest); | |
106 | ||
107 | obj->m_eventType = m_eventType; | |
108 | obj->m_eventObject = m_eventObject; | |
109 | obj->m_eventHandle = m_eventHandle; | |
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) | |
167 | : wxEvent(commandType) | |
168 | { | |
169 | m_extraLong = orient; | |
170 | m_commandInt = pos; | |
171 | } | |
172 | ||
c801d85f KB |
173 | /* |
174 | * Mouse events | |
175 | * | |
176 | */ | |
177 | ||
7798a18e | 178 | wxMouseEvent::wxMouseEvent(wxEventType commandType) |
c801d85f | 179 | { |
0b746ba8 VZ |
180 | m_eventType = commandType; |
181 | m_metaDown = FALSE; | |
182 | m_altDown = FALSE; | |
183 | m_controlDown = FALSE; | |
184 | m_shiftDown = FALSE; | |
185 | m_leftDown = FALSE; | |
186 | m_rightDown = FALSE; | |
187 | m_middleDown = FALSE; | |
188 | m_x = 0; | |
189 | m_y = 0; | |
c801d85f KB |
190 | } |
191 | ||
aadbdf11 GL |
192 | void wxMouseEvent::CopyObject(wxObject& obj_d) const |
193 | { | |
194 | wxMouseEvent *obj = (wxMouseEvent *)&obj_d; | |
195 | ||
196 | wxEvent::CopyObject(obj_d); | |
197 | ||
198 | obj->m_metaDown = m_metaDown; | |
199 | obj->m_altDown = m_altDown; | |
200 | obj->m_controlDown = m_controlDown; | |
201 | obj->m_shiftDown = m_shiftDown; | |
202 | obj->m_leftDown = m_leftDown; | |
203 | obj->m_rightDown = m_rightDown; | |
204 | obj->m_middleDown = m_middleDown; | |
205 | obj->m_x = m_x; | |
206 | obj->m_y = m_y; | |
207 | } | |
208 | ||
c801d85f KB |
209 | // True if was a button dclick event (1 = left, 2 = middle, 3 = right) |
210 | // or any button dclick event (but = -1) | |
211 | bool wxMouseEvent::ButtonDClick(int but) const | |
212 | { | |
0b746ba8 VZ |
213 | switch (but) |
214 | { | |
215 | case -1: | |
216 | return (LeftDClick() || MiddleDClick() || RightDClick()); | |
217 | case 1: | |
218 | return LeftDClick(); | |
219 | case 2: | |
220 | return MiddleDClick(); | |
221 | case 3: | |
222 | return RightDClick(); | |
223 | default: | |
50920146 | 224 | wxFAIL_MSG(_T("invalid parameter in wxMouseEvent::ButtonDClick")); |
0b746ba8 VZ |
225 | } |
226 | ||
227 | return FALSE; | |
c801d85f KB |
228 | } |
229 | ||
230 | // True if was a button down event (1 = left, 2 = middle, 3 = right) | |
231 | // or any button down event (but = -1) | |
232 | bool wxMouseEvent::ButtonDown(int but) const | |
233 | { | |
0b746ba8 VZ |
234 | switch (but) |
235 | { | |
236 | case -1: | |
237 | return (LeftDown() || MiddleDown() || RightDown()); | |
238 | case 1: | |
239 | return LeftDown(); | |
240 | case 2: | |
241 | return MiddleDown(); | |
242 | case 3: | |
243 | return RightDown(); | |
244 | default: | |
50920146 | 245 | wxFAIL_MSG(_T("invalid parameter in wxMouseEvent::ButtonDown")); |
0b746ba8 VZ |
246 | } |
247 | ||
248 | return FALSE; | |
c801d85f KB |
249 | } |
250 | ||
251 | // True if was a button up event (1 = left, 2 = middle, 3 = right) | |
252 | // or any button up event (but = -1) | |
253 | bool wxMouseEvent::ButtonUp(int but) const | |
254 | { | |
0b746ba8 VZ |
255 | switch (but) { |
256 | case -1: | |
257 | return (LeftUp() || MiddleUp() || RightUp()); | |
258 | case 1: | |
259 | return LeftUp(); | |
260 | case 2: | |
261 | return MiddleUp(); | |
262 | case 3: | |
263 | return RightUp(); | |
264 | default: | |
50920146 | 265 | wxFAIL_MSG(_T("invalid parameter in wxMouseEvent::ButtonUp")); |
0b746ba8 VZ |
266 | } |
267 | ||
268 | return FALSE; | |
c801d85f KB |
269 | } |
270 | ||
271 | // True if the given button is currently changing state | |
272 | bool wxMouseEvent::Button(int but) const | |
273 | { | |
0b746ba8 VZ |
274 | switch (but) { |
275 | case -1: | |
276 | return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1)) ; | |
277 | case 1: | |
278 | return (LeftDown() || LeftUp() || LeftDClick()); | |
279 | case 2: | |
280 | return (MiddleDown() || MiddleUp() || MiddleDClick()); | |
281 | case 3: | |
282 | return (RightDown() || RightUp() || RightDClick()); | |
283 | default: | |
50920146 | 284 | wxFAIL_MSG(_T("invalid parameter in wxMouseEvent::Button")); |
0b746ba8 VZ |
285 | } |
286 | ||
287 | return FALSE; | |
c801d85f KB |
288 | } |
289 | ||
290 | bool wxMouseEvent::ButtonIsDown(int but) const | |
291 | { | |
0b746ba8 VZ |
292 | switch (but) { |
293 | case -1: | |
294 | return (LeftIsDown() || MiddleIsDown() || RightIsDown()); | |
295 | case 1: | |
296 | return LeftIsDown(); | |
297 | case 2: | |
298 | return MiddleIsDown(); | |
299 | case 3: | |
300 | return RightIsDown(); | |
301 | default: | |
50920146 | 302 | wxFAIL_MSG(_T("invalid parameter in wxMouseEvent::ButtonIsDown")); |
0b746ba8 VZ |
303 | } |
304 | ||
305 | return FALSE; | |
c801d85f KB |
306 | } |
307 | ||
308 | // Find the logical position of the event given the DC | |
309 | wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const | |
310 | { | |
0757d27c JS |
311 | wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y)); |
312 | return pt; | |
c801d85f KB |
313 | } |
314 | ||
315 | ||
316 | /* | |
317 | * Keyboard events | |
318 | * | |
319 | */ | |
320 | ||
7798a18e | 321 | wxKeyEvent::wxKeyEvent(wxEventType type) |
c801d85f | 322 | { |
0b746ba8 VZ |
323 | m_eventType = type; |
324 | m_shiftDown = FALSE; | |
325 | m_controlDown = FALSE; | |
326 | m_metaDown = FALSE; | |
327 | m_altDown = FALSE; | |
328 | m_keyCode = 0; | |
c801d85f KB |
329 | } |
330 | ||
aadbdf11 GL |
331 | void wxKeyEvent::CopyObject(wxObject& obj_d) const |
332 | { | |
333 | wxKeyEvent *obj = (wxKeyEvent *)&obj_d; | |
334 | wxEvent::CopyObject(obj_d); | |
335 | ||
336 | obj->m_shiftDown = m_shiftDown; | |
337 | obj->m_controlDown = m_controlDown; | |
338 | obj->m_metaDown = m_metaDown; | |
339 | obj->m_altDown = m_altDown; | |
340 | obj->m_keyCode = m_keyCode; | |
341 | } | |
342 | ||
343 | ||
344 | /* | |
345 | * Misc events | |
346 | */ | |
347 | ||
348 | void wxSizeEvent::CopyObject(wxObject& obj_d) const | |
349 | { | |
350 | wxSizeEvent *obj = (wxSizeEvent *)&obj_d; | |
351 | wxEvent::CopyObject(obj_d); | |
352 | ||
353 | obj->m_size = m_size; | |
354 | } | |
355 | ||
356 | void wxMoveEvent::CopyObject(wxObject& obj_d) const | |
357 | { | |
358 | wxMoveEvent *obj = (wxMoveEvent *)&obj_d; | |
359 | wxEvent::CopyObject(obj_d); | |
360 | ||
361 | obj->m_pos = m_pos; | |
362 | } | |
363 | ||
364 | void wxEraseEvent::CopyObject(wxObject& obj_d) const | |
365 | { | |
366 | wxEraseEvent *obj = (wxEraseEvent *)&obj_d; | |
367 | wxEvent::CopyObject(obj_d); | |
368 | ||
369 | obj->m_dc = m_dc; | |
370 | } | |
371 | ||
372 | void wxActivateEvent::CopyObject(wxObject& obj_d) const | |
373 | { | |
374 | wxActivateEvent *obj = (wxActivateEvent *)&obj_d; | |
375 | wxEvent::CopyObject(obj_d); | |
376 | ||
377 | obj->m_active = m_active; | |
378 | } | |
379 | ||
380 | void wxMenuEvent::CopyObject(wxObject& obj_d) const | |
381 | { | |
382 | wxMenuEvent *obj = (wxMenuEvent *)&obj_d; | |
383 | wxEvent::CopyObject(obj_d); | |
384 | ||
385 | obj->m_menuId = m_menuId; | |
386 | } | |
387 | ||
388 | void wxCloseEvent::CopyObject(wxObject& obj_d) const | |
389 | { | |
390 | wxCloseEvent *obj = (wxCloseEvent *)&obj_d; | |
391 | wxEvent::CopyObject(obj_d); | |
392 | ||
393 | obj->m_loggingOff = m_loggingOff; | |
394 | obj->m_veto = m_veto; | |
395 | #if WXWIN_COMPATIBILITY | |
396 | obj->m_force = m_force; | |
397 | #endif | |
398 | obj->m_canVeto = m_canVeto; | |
399 | } | |
400 | ||
401 | void wxShowEvent::CopyObject(wxObject& obj_d) const | |
402 | { | |
403 | wxShowEvent *obj = (wxShowEvent *)&obj_d; | |
404 | wxEvent::CopyObject(obj_d); | |
405 | ||
406 | obj->m_show = m_show; | |
407 | } | |
408 | ||
409 | ||
c801d85f KB |
410 | /* |
411 | * Event handler | |
412 | */ | |
413 | ||
0b746ba8 | 414 | wxEvtHandler::wxEvtHandler() |
c801d85f | 415 | { |
0b746ba8 VZ |
416 | m_nextHandler = (wxEvtHandler *) NULL; |
417 | m_previousHandler = (wxEvtHandler *) NULL; | |
418 | m_enabled = TRUE; | |
419 | m_dynamicEvents = (wxList *) NULL; | |
193bf013 | 420 | m_isWindow = FALSE; |
7214297d GL |
421 | #if wxUSE_THREADS |
422 | m_eventsLocker = new wxCriticalSection(); | |
423 | #endif | |
424 | m_pendingEvents = (wxList *) NULL; | |
c801d85f KB |
425 | } |
426 | ||
0b746ba8 | 427 | wxEvtHandler::~wxEvtHandler() |
c801d85f | 428 | { |
0b746ba8 VZ |
429 | // Takes itself out of the list of handlers |
430 | if (m_previousHandler) | |
431 | m_previousHandler->m_nextHandler = m_nextHandler; | |
432 | ||
433 | if (m_nextHandler) | |
434 | m_nextHandler->m_previousHandler = m_previousHandler; | |
435 | ||
436 | if (m_dynamicEvents) | |
fe71f65c | 437 | { |
0b746ba8 VZ |
438 | wxNode *node = m_dynamicEvents->First(); |
439 | while (node) | |
440 | { | |
441 | wxEventTableEntry *entry = (wxEventTableEntry*)node->Data(); | |
442 | if (entry->m_callbackUserData) delete entry->m_callbackUserData; | |
443 | delete entry; | |
444 | node = node->Next(); | |
445 | } | |
446 | delete m_dynamicEvents; | |
447 | }; | |
7214297d | 448 | |
a737331d | 449 | #if wxUSE_THREADS |
7214297d GL |
450 | if (m_pendingEvents) |
451 | delete m_pendingEvents; | |
452 | ||
7214297d GL |
453 | delete m_eventsLocker; |
454 | #endif | |
c801d85f KB |
455 | } |
456 | ||
7214297d | 457 | #if wxUSE_THREADS |
aadbdf11 GL |
458 | |
459 | #ifdef __WXGTK__ | |
460 | extern bool g_isIdle; | |
461 | ||
462 | extern void wxapp_install_idle_handler(); | |
463 | #endif | |
464 | ||
7214297d GL |
465 | bool wxEvtHandler::ProcessThreadEvent(wxEvent& event) |
466 | { | |
467 | wxEvent *event_main; | |
468 | wxCriticalSectionLocker locker(*m_eventsLocker); | |
469 | ||
aadbdf11 | 470 | |
7214297d GL |
471 | // check that we are really in a child thread |
472 | wxASSERT( !wxThread::IsMain() ); | |
473 | ||
474 | if (m_pendingEvents == NULL) | |
475 | m_pendingEvents = new wxList(); | |
476 | ||
a737331d | 477 | event_main = (wxEvent *)event.Clone(); |
7214297d GL |
478 | |
479 | m_pendingEvents->Append(event_main); | |
480 | ||
4d3a259a GL |
481 | wxPendingEventsLocker->Enter(); |
482 | wxPendingEvents->Append(this); | |
483 | wxPendingEventsLocker->Leave(); | |
7214297d | 484 | |
aadbdf11 GL |
485 | #ifdef __WXGTK__ |
486 | if (g_isIdle) wxapp_install_idle_handler(); | |
487 | #endif | |
488 | ||
7214297d GL |
489 | return TRUE; |
490 | } | |
491 | ||
492 | void wxEvtHandler::ProcessPendingEvents() | |
493 | { | |
494 | wxCriticalSectionLocker locker(*m_eventsLocker); | |
495 | wxNode *node = m_pendingEvents->First(); | |
496 | wxEvent *event; | |
497 | ||
498 | while (node != NULL) { | |
499 | event = (wxEvent *)node->Data(); | |
500 | ProcessEvent(*event); | |
501 | delete node; | |
502 | node = m_pendingEvents->First(); | |
503 | } | |
504 | } | |
505 | #endif | |
506 | ||
c801d85f KB |
507 | /* |
508 | * Event table stuff | |
509 | */ | |
510 | ||
511 | bool wxEvtHandler::ProcessEvent(wxEvent& event) | |
512 | { | |
193bf013 VZ |
513 | // check that our flag corresponds to reality |
514 | wxASSERT( m_isWindow == IsKindOf(CLASSINFO(wxWindow)) ); | |
0b746ba8 VZ |
515 | |
516 | // An event handler can be enabled or disabled | |
517 | if ( GetEvtHandlerEnabled() ) | |
c801d85f | 518 | { |
7214297d GL |
519 | #if wxUSE_THREADS |
520 | // Check whether we are in a child thread. | |
521 | if (!wxThread::IsMain()) | |
522 | return ProcessThreadEvent(event); | |
523 | #endif | |
0b746ba8 | 524 | // Handle per-instance dynamic event tables first |
0757d27c | 525 | |
193bf013 | 526 | if ( m_dynamicEvents && SearchDynamicEventTable(event) ) |
0757d27c | 527 | return TRUE; |
0b746ba8 VZ |
528 | |
529 | // Then static per-class event tables | |
530 | ||
531 | const wxEventTable *table = GetEventTable(); | |
532 | ||
533 | // Try the associated validator first, if this is a window. | |
534 | // Problem: if the event handler of the window has been replaced, | |
535 | // this wxEvtHandler may no longer be a window. | |
536 | // Therefore validators won't be processed if the handler | |
537 | // has been replaced with SetEventHandler. | |
538 | // THIS CAN BE CURED if PushEventHandler is used instead of | |
539 | // SetEventHandler, and then processing will be passed down the | |
540 | // chain of event handlers. | |
193bf013 | 541 | if ( m_isWindow ) |
0b746ba8 VZ |
542 | { |
543 | wxWindow *win = (wxWindow *)this; | |
544 | ||
545 | // Can only use the validator of the window which | |
546 | // is receiving the event | |
193bf013 | 547 | if ( win == event.GetEventObject() ) |
0b746ba8 | 548 | { |
193bf013 VZ |
549 | wxValidator *validator = win->GetValidator(); |
550 | if ( validator && validator->ProcessEvent(event) ) | |
551 | { | |
552 | return TRUE; | |
553 | } | |
0b746ba8 VZ |
554 | } |
555 | } | |
556 | ||
557 | // Search upwards through the inheritance hierarchy | |
193bf013 | 558 | while ( table ) |
0b746ba8 | 559 | { |
193bf013 | 560 | if ( SearchEventTable((wxEventTable&)*table, event) ) |
0b746ba8 VZ |
561 | return TRUE; |
562 | table = table->baseTable; | |
563 | } | |
c801d85f KB |
564 | } |
565 | ||
0b746ba8 VZ |
566 | // Try going down the event handler chain |
567 | if ( GetNextHandler() ) | |
c801d85f | 568 | { |
0b746ba8 VZ |
569 | if ( GetNextHandler()->ProcessEvent(event) ) |
570 | return TRUE; | |
c801d85f | 571 | } |
c801d85f | 572 | |
0b746ba8 VZ |
573 | // Carry on up the parent-child hierarchy, |
574 | // but only if event is a command event: it wouldn't | |
575 | // make sense for a parent to receive a child's size event, for example | |
193bf013 | 576 | if ( m_isWindow && event.IsCommandEvent() ) |
0b746ba8 VZ |
577 | { |
578 | wxWindow *win = (wxWindow *)this; | |
579 | wxWindow *parent = win->GetParent(); | |
580 | if (parent && !parent->IsBeingDeleted()) | |
193bf013 | 581 | return parent->GetEventHandler()->ProcessEvent(event); |
0b746ba8 VZ |
582 | } |
583 | ||
584 | // Last try - application object. | |
193bf013 | 585 | if ( wxTheApp && (this != wxTheApp) ) |
0b746ba8 | 586 | { |
193bf013 VZ |
587 | // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always |
588 | // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be | |
589 | // processed appropriately via SearchEventTable. | |
590 | if ( event.GetEventType() != wxEVT_IDLE ) | |
591 | { | |
592 | if ( wxTheApp->ProcessEvent(event) ) | |
593 | return TRUE; | |
594 | } | |
0b746ba8 VZ |
595 | } |
596 | ||
c801d85f KB |
597 | return FALSE; |
598 | } | |
599 | ||
600 | bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event) | |
601 | { | |
0b746ba8 VZ |
602 | int i = 0; |
603 | int commandId = event.GetId(); | |
604 | ||
605 | // BC++ doesn't like while (table.entries[i].m_fn) | |
606 | ||
2432b92d JS |
607 | #ifdef __SC__ |
608 | while (table.entries[i].m_fn != 0) | |
609 | #else | |
0b746ba8 | 610 | while (table.entries[i].m_fn != 0L) |
2432b92d | 611 | #endif |
c801d85f | 612 | { |
0b746ba8 VZ |
613 | if ((event.GetEventType() == table.entries[i].m_eventType) && |
614 | (table.entries[i].m_id == -1 || // Match, if event spec says any id will do (id == -1) | |
615 | (table.entries[i].m_lastId == -1 && commandId == table.entries[i].m_id) || | |
616 | (table.entries[i].m_lastId != -1 && | |
617 | (commandId >= table.entries[i].m_id && commandId <= table.entries[i].m_lastId)))) | |
618 | { | |
619 | event.Skip(FALSE); | |
620 | event.m_callbackUserData = table.entries[i].m_callbackUserData; | |
621 | ||
622 | (this->*((wxEventFunction) (table.entries[i].m_fn)))(event); | |
623 | ||
624 | if ( event.GetSkipped() ) | |
625 | return FALSE; | |
626 | else | |
627 | return TRUE; | |
628 | } | |
629 | i++; | |
c801d85f | 630 | } |
0b746ba8 | 631 | return FALSE; |
c801d85f | 632 | } |
debe6624 | 633 | void wxEvtHandler::Connect( int id, int lastId, |
d4a23fee | 634 | wxEventType eventType, |
0b746ba8 VZ |
635 | wxObjectEventFunction func, |
636 | wxObject *userData ) | |
fe71f65c | 637 | { |
0b746ba8 VZ |
638 | wxEventTableEntry *entry = new wxEventTableEntry; |
639 | entry->m_id = id; | |
640 | entry->m_lastId = lastId; | |
641 | entry->m_eventType = eventType; | |
642 | entry->m_fn = func; | |
643 | entry->m_callbackUserData = userData; | |
644 | ||
645 | if (!m_dynamicEvents) | |
646 | m_dynamicEvents = new wxList; | |
647 | ||
648 | m_dynamicEvents->Append( (wxObject*) entry ); | |
fe71f65c RR |
649 | } |
650 | ||
651 | bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event ) | |
652 | { | |
193bf013 | 653 | wxCHECK_MSG( m_dynamicEvents, FALSE, |
50920146 | 654 | _T("caller should check that we have dynamic events") ); |
0b746ba8 VZ |
655 | |
656 | int commandId = event.GetId(); | |
657 | ||
658 | wxNode *node = m_dynamicEvents->First(); | |
659 | while (node) | |
fe71f65c | 660 | { |
0b746ba8 VZ |
661 | wxEventTableEntry *entry = (wxEventTableEntry*)node->Data(); |
662 | ||
663 | if (entry->m_fn) | |
664 | { | |
665 | // Match, if event spec says any id will do (id == -1) | |
666 | if ( (event.GetEventType() == entry->m_eventType) && | |
667 | (entry->m_id == -1 || | |
668 | (entry->m_lastId == -1 && commandId == entry->m_id) || | |
669 | (entry->m_lastId != -1 && | |
670 | (commandId >= entry->m_id && commandId <= entry->m_lastId))) ) | |
671 | { | |
672 | event.Skip(FALSE); | |
673 | event.m_callbackUserData = entry->m_callbackUserData; | |
674 | ||
675 | (this->*((wxEventFunction) (entry->m_fn)))(event); | |
676 | ||
677 | if (event.GetSkipped()) | |
678 | return FALSE; | |
679 | else | |
680 | return TRUE; | |
681 | } | |
682 | } | |
683 | node = node->Next(); | |
7b678698 | 684 | } |
0b746ba8 | 685 | return FALSE; |
fe71f65c RR |
686 | }; |
687 | ||
e3065973 | 688 | #if WXWIN_COMPATIBILITY |
0b746ba8 | 689 | bool wxEvtHandler::OnClose() |
c801d85f | 690 | { |
0b746ba8 VZ |
691 | if (GetNextHandler()) |
692 | return GetNextHandler()->OnClose(); | |
693 | else | |
694 | return FALSE; | |
c801d85f | 695 | } |
193bf013 | 696 | #endif // WXWIN_COMPATIBILITY |
e3065973 | 697 | |
e702ff0f JS |
698 | // Find a window with the focus, that is also a descendant of the given window. |
699 | // This is used to determine the window to initially send commands to. | |
700 | wxWindow* wxFindFocusDescendant(wxWindow* ancestor) | |
701 | { | |
702 | // Process events starting with the window with the focus, if any. | |
703 | wxWindow* focusWin = wxWindow::FindFocus(); | |
704 | wxWindow* win = focusWin; | |
705 | ||
706 | // Check if this is a descendant of this frame. | |
707 | // If not, win will be set to NULL. | |
708 | while (win) | |
709 | { | |
710 | if (win == ancestor) | |
711 | break; | |
712 | else | |
713 | win = win->GetParent(); | |
714 | } | |
715 | if (win == (wxWindow*) NULL) | |
716 | focusWin = (wxWindow*) NULL; | |
717 | ||
718 | return focusWin; | |
719 | } | |
720 |