]> git.saurik.com Git - wxWidgets.git/blob - src/common/event.cpp
using WX_TIMEZONE set by configure instead of timezone
[wxWidgets.git] / src / common / event.cpp
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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "event.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/defs.h"
33 #include "wx/app.h"
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
41 #endif
42
43 #include "wx/event.h"
44
45 #if wxUSE_GUI
46 #include "wx/validate.h"
47 #endif // wxUSE_GUI
48
49 // ----------------------------------------------------------------------------
50 // wxWin macros
51 // ----------------------------------------------------------------------------
52
53 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject)
54 IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject)
55 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent)
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
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[] =
94 { { 0, 0, 0, (wxObjectEventFunction) NULL, (wxObject*) NULL } };
95
96
97 // ----------------------------------------------------------------------------
98 // global variables
99 // ----------------------------------------------------------------------------
100
101 // To put pending event handlers
102 wxList *wxPendingEvents = (wxList *)NULL;
103
104 #if wxUSE_THREADS
105 // protects wxPendingEvents list
106 wxCriticalSection *wxPendingEventsLocker = (wxCriticalSection *)NULL;
107 #endif
108
109 // ============================================================================
110 // implementation
111 // ============================================================================
112
113 // ----------------------------------------------------------------------------
114 // wxEvent
115 // ----------------------------------------------------------------------------
116
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 {
128 m_eventType = wxEVT_NULL;
129 m_eventObject = (wxObject *) NULL;
130 m_timeStamp = 0;
131 m_id = theId;
132 m_skipped = FALSE;
133 m_callbackUserData = (wxObject *) NULL;
134 m_isCommandEvent = FALSE;
135 }
136
137 void wxEvent::CopyObject(wxObject& object_dest) const
138 {
139 wxEvent *obj = (wxEvent *)&object_dest;
140 wxObject::CopyObject(object_dest);
141
142 obj->m_eventType = m_eventType;
143 obj->m_eventObject = m_eventObject;
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;
149 }
150
151 #if wxUSE_GUI
152
153 /*
154 * Command events
155 *
156 */
157
158 wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId)
159 {
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;
166 m_commandString = wxEmptyString;
167 m_isCommandEvent = TRUE;
168 }
169
170 void wxCommandEvent::CopyObject(wxObject& obj_d) const
171 {
172 wxCommandEvent *obj = (wxCommandEvent *)&obj_d;
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
182 /*
183 * Scroll events
184 */
185
186 wxScrollEvent::wxScrollEvent(wxEventType commandType,
187 int id,
188 int pos,
189 int orient)
190 : wxCommandEvent(commandType, id)
191 {
192 m_extraLong = orient;
193 m_commandInt = pos;
194 }
195
196 /*
197 * ScrollWin events
198 */
199
200 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType,
201 int pos,
202 int orient)
203 {
204 m_eventType = commandType;
205 m_extraLong = orient;
206 m_commandInt = pos;
207 }
208
209 void wxScrollWinEvent::CopyObject(wxObject& obj_d) const
210 {
211 wxScrollWinEvent *obj = (wxScrollWinEvent*)&obj_d;
212
213 wxEvent::CopyObject(obj_d);
214
215 obj->m_extraLong = m_extraLong;
216 obj->m_commandInt = m_commandInt;
217 }
218
219 /*
220 * Mouse events
221 *
222 */
223
224 wxMouseEvent::wxMouseEvent(wxEventType commandType)
225 {
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;
236 }
237
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
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 {
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:
270 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
271 }
272
273 return FALSE;
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 {
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:
291 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
292 }
293
294 return FALSE;
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 {
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:
311 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
312 }
313
314 return FALSE;
315 }
316
317 // True if the given button is currently changing state
318 bool wxMouseEvent::Button(int but) const
319 {
320 switch (but) {
321 case -1:
322 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
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:
330 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
331 }
332
333 return FALSE;
334 }
335
336 bool wxMouseEvent::ButtonIsDown(int but) const
337 {
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:
348 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
349 }
350
351 return FALSE;
352 }
353
354 // Find the logical position of the event given the DC
355 wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const
356 {
357 wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y));
358 return pt;
359 }
360
361
362 /*
363 * Keyboard events
364 *
365 */
366
367 wxKeyEvent::wxKeyEvent(wxEventType type)
368 {
369 m_eventType = type;
370 m_shiftDown = FALSE;
371 m_controlDown = FALSE;
372 m_metaDown = FALSE;
373 m_altDown = FALSE;
374 m_keyCode = 0;
375 m_scanCode = 0;
376 }
377
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 }
447
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 }
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;
466 }
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
476 // destructor of the event.
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 }
507
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
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
530 /*
531 * Event handler
532 */
533
534 wxEvtHandler::wxEvtHandler()
535 {
536 m_nextHandler = (wxEvtHandler *) NULL;
537 m_previousHandler = (wxEvtHandler *) NULL;
538 m_enabled = TRUE;
539 m_dynamicEvents = (wxList *) NULL;
540 m_isWindow = FALSE;
541 m_pendingEvents = (wxList *) NULL;
542 #if wxUSE_THREADS
543 # if !defined(__VISAGECPP__)
544 m_eventsLocker = new wxCriticalSection;
545 # endif
546 #endif
547 }
548
549 wxEvtHandler::~wxEvtHandler()
550 {
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)
559 {
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 };
570
571 delete m_pendingEvents;
572
573 #if wxUSE_THREADS
574 # if !defined(__VISAGECPP__)
575 delete m_eventsLocker;
576 # endif
577 #endif
578 }
579
580 #if wxUSE_THREADS
581
582 bool wxEvtHandler::ProcessThreadEvent(wxEvent& event)
583 {
584 // check that we are really in a child thread
585 wxASSERT_MSG( !wxThread::IsMain(),
586 wxT("use ProcessEvent() in main thread") );
587
588 AddPendingEvent(event);
589
590 return TRUE;
591 }
592
593 #endif // wxUSE_THREADS
594
595 void wxEvtHandler::AddPendingEvent(wxEvent& event)
596 {
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
605 if ( !m_pendingEvents )
606 m_pendingEvents = new wxList;
607
608 wxEvent *event2 = (wxEvent *)event.Clone();
609
610 m_pendingEvents->Append(event2);
611
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
621 wxENTER_CRIT_SECT(*wxPendingEventsLocker);
622
623 if ( !wxPendingEvents )
624 wxPendingEvents = new wxList;
625 wxPendingEvents->Append(this);
626
627 // 3) Inform the system that new pending events are somwehere,
628 // and that these should be processed in idle time.
629
630 wxWakeUpIdle();
631
632 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker);
633 }
634
635 void wxEvtHandler::ProcessPendingEvents()
636 {
637 #if defined(__VISAGECPP__)
638 wxENTER_CRIT_SECT( m_eventsLocker);
639 #else
640 wxENTER_CRIT_SECT( *m_eventsLocker);
641 #endif
642
643 wxNode *node = m_pendingEvents->First();
644 while ( node )
645 {
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
656 ProcessEvent(*event);
657 delete event;
658 #if defined(__VISAGECPP__)
659 wxENTER_CRIT_SECT( m_eventsLocker);
660 #else
661 wxENTER_CRIT_SECT( *m_eventsLocker);
662 #endif
663
664 node = m_pendingEvents->First();
665 }
666
667 #if defined(__VISAGECPP__)
668 wxLEAVE_CRIT_SECT( m_eventsLocker);
669 #else
670 wxLEAVE_CRIT_SECT( *m_eventsLocker);
671 #endif
672 }
673
674 /*
675 * Event table stuff
676 */
677
678 bool wxEvtHandler::ProcessEvent(wxEvent& event)
679 {
680 #if wxUSE_GUI
681 // check that our flag corresponds to reality
682 wxASSERT( m_isWindow == IsKindOf(CLASSINFO(wxWindow)) );
683 #endif // wxUSE_GUI
684
685 // An event handler can be enabled or disabled
686 if ( GetEvtHandlerEnabled() )
687 {
688 #if wxUSE_THREADS
689 // Check whether we are in a child thread.
690 if ( !wxThread::IsMain() )
691 return ProcessThreadEvent(event);
692 #endif // wxUSE_THREADS
693
694 // Handle per-instance dynamic event tables first
695 if ( m_dynamicEvents && SearchDynamicEventTable(event) )
696 return TRUE;
697
698 // Then static per-class event tables
699 const wxEventTable *table = GetEventTable();
700
701 #if wxUSE_GUI && wxUSE_VALIDATORS
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.
710 if (m_isWindow)
711 {
712 wxWindow *win = (wxWindow *)this;
713
714 // Can only use the validator of the window which
715 // is receiving the event
716 if ( win == event.GetEventObject() )
717 {
718 wxValidator *validator = win->GetValidator();
719 if ( validator && validator->ProcessEvent(event) )
720 {
721 return TRUE;
722 }
723 }
724 }
725 #endif
726
727 // Search upwards through the inheritance hierarchy
728 while (table)
729 {
730 if ( SearchEventTable((wxEventTable&)*table, event) )
731 return TRUE;
732 table = table->baseTable;
733 }
734 }
735
736 // Try going down the event handler chain
737 if ( GetNextHandler() )
738 {
739 if ( GetNextHandler()->ProcessEvent(event) )
740 return TRUE;
741 }
742
743 #if wxUSE_GUI
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
747 if ( m_isWindow && event.IsCommandEvent() )
748 {
749 wxWindow *win = (wxWindow *)this;
750 wxWindow *parent = win->GetParent();
751 if (parent && !parent->IsBeingDeleted())
752 return parent->GetEventHandler()->ProcessEvent(event);
753 }
754 #endif // wxUSE_GUI
755
756 // Last try - application object.
757 if ( wxTheApp && (this != wxTheApp) )
758 {
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 }
767 }
768
769 return FALSE;
770 }
771
772 bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
773 {
774 int i = 0;
775 int commandId = event.GetId();
776
777 // BC++ doesn't like while (table.entries[i].m_fn)
778
779 #ifdef __SC__
780 while (table.entries[i].m_fn != 0)
781 #else
782 while (table.entries[i].m_fn != 0L)
783 #endif
784 {
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++;
802 }
803 return FALSE;
804 }
805
806 void wxEvtHandler::Connect( int id, int lastId,
807 wxEventType eventType,
808 wxObjectEventFunction func,
809 wxObject *userData )
810 {
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 );
822 }
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 }
850
851 bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
852 {
853 wxCHECK_MSG( m_dynamicEvents, FALSE,
854 wxT("caller should check that we have dynamic events") );
855
856 int commandId = event.GetId();
857
858 wxNode *node = m_dynamicEvents->First();
859 while (node)
860 {
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();
884 }
885 return FALSE;
886 };
887
888 #if WXWIN_COMPATIBILITY
889 bool wxEvtHandler::OnClose()
890 {
891 if (GetNextHandler())
892 return GetNextHandler()->OnClose();
893 else
894 return FALSE;
895 }
896 #endif // WXWIN_COMPATIBILITY
897
898 #if wxUSE_GUI
899
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
923 #endif // wxUSE_GUI