]> git.saurik.com Git - wxWidgets.git/blob - src/common/event.cpp
wxFileIn/OutputStream fix
[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 #ifdef __GNUG__
13 #pragma implementation "event.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
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"
29 #endif
30
31 #include "wx/event.h"
32 #include "wx/validate.h"
33
34 #if !USE_SHARED_LIBRARY
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)
40 IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent, wxEvent)
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 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent, wxEvent)
64 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent, wxEvent)
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[] =
73 { { 0, 0, 0, (wxObjectEventFunction) NULL, (wxObject*) NULL } };
74
75 #endif // !USE_SHARED_LIBRARY
76
77 #if wxUSE_THREADS
78 /* To put pending event handlers */
79 extern wxList *wxPendingEvents;
80 extern wxCriticalSection *wxPendingEventsLocker;
81 #endif
82
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 {
94 m_eventType = wxEVT_NULL;
95 m_eventObject = (wxObject *) NULL;
96 m_timeStamp = 0;
97 m_id = theId;
98 m_skipped = FALSE;
99 m_callbackUserData = (wxObject *) NULL;
100 m_isCommandEvent = FALSE;
101 }
102
103 void wxEvent::CopyObject(wxObject& object_dest) const
104 {
105 wxEvent *obj = (wxEvent *)&object_dest;
106 wxObject::CopyObject(object_dest);
107
108 obj->m_eventType = m_eventType;
109 obj->m_eventObject = m_eventObject;
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;
115 }
116
117 /*
118 * Command events
119 *
120 */
121
122 wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId)
123 {
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;
130 m_commandString = (wxChar *) NULL;
131 m_isCommandEvent = TRUE;
132 }
133
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
146 /*
147 * Scroll events
148 */
149
150 wxScrollEvent::wxScrollEvent(wxEventType commandType,
151 int id,
152 int pos,
153 int orient)
154 : wxCommandEvent(commandType, id)
155 {
156 m_extraLong = orient;
157 m_commandInt = pos;
158 }
159
160 /*
161 * ScrollWin events
162 */
163
164 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType,
165 int pos,
166 int orient)
167 {
168 m_eventType = commandType;
169 m_extraLong = orient;
170 m_commandInt = pos;
171 }
172
173 /*
174 * Mouse events
175 *
176 */
177
178 wxMouseEvent::wxMouseEvent(wxEventType commandType)
179 {
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;
190 }
191
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
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 {
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:
224 wxFAIL_MSG(_T("invalid parameter in wxMouseEvent::ButtonDClick"));
225 }
226
227 return FALSE;
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 {
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:
245 wxFAIL_MSG(_T("invalid parameter in wxMouseEvent::ButtonDown"));
246 }
247
248 return FALSE;
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 {
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:
265 wxFAIL_MSG(_T("invalid parameter in wxMouseEvent::ButtonUp"));
266 }
267
268 return FALSE;
269 }
270
271 // True if the given button is currently changing state
272 bool wxMouseEvent::Button(int but) const
273 {
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:
284 wxFAIL_MSG(_T("invalid parameter in wxMouseEvent::Button"));
285 }
286
287 return FALSE;
288 }
289
290 bool wxMouseEvent::ButtonIsDown(int but) const
291 {
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:
302 wxFAIL_MSG(_T("invalid parameter in wxMouseEvent::ButtonIsDown"));
303 }
304
305 return FALSE;
306 }
307
308 // Find the logical position of the event given the DC
309 wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const
310 {
311 wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y));
312 return pt;
313 }
314
315
316 /*
317 * Keyboard events
318 *
319 */
320
321 wxKeyEvent::wxKeyEvent(wxEventType type)
322 {
323 m_eventType = type;
324 m_shiftDown = FALSE;
325 m_controlDown = FALSE;
326 m_metaDown = FALSE;
327 m_altDown = FALSE;
328 m_keyCode = 0;
329 m_scanCode = 0;
330 }
331
332 void wxKeyEvent::CopyObject(wxObject& obj_d) const
333 {
334 wxKeyEvent *obj = (wxKeyEvent *)&obj_d;
335 wxEvent::CopyObject(obj_d);
336
337 obj->m_shiftDown = m_shiftDown;
338 obj->m_controlDown = m_controlDown;
339 obj->m_metaDown = m_metaDown;
340 obj->m_altDown = m_altDown;
341 obj->m_keyCode = m_keyCode;
342 }
343
344
345 /*
346 * Misc events
347 */
348
349 void wxSizeEvent::CopyObject(wxObject& obj_d) const
350 {
351 wxSizeEvent *obj = (wxSizeEvent *)&obj_d;
352 wxEvent::CopyObject(obj_d);
353
354 obj->m_size = m_size;
355 }
356
357 void wxMoveEvent::CopyObject(wxObject& obj_d) const
358 {
359 wxMoveEvent *obj = (wxMoveEvent *)&obj_d;
360 wxEvent::CopyObject(obj_d);
361
362 obj->m_pos = m_pos;
363 }
364
365 void wxEraseEvent::CopyObject(wxObject& obj_d) const
366 {
367 wxEraseEvent *obj = (wxEraseEvent *)&obj_d;
368 wxEvent::CopyObject(obj_d);
369
370 obj->m_dc = m_dc;
371 }
372
373 void wxActivateEvent::CopyObject(wxObject& obj_d) const
374 {
375 wxActivateEvent *obj = (wxActivateEvent *)&obj_d;
376 wxEvent::CopyObject(obj_d);
377
378 obj->m_active = m_active;
379 }
380
381 void wxMenuEvent::CopyObject(wxObject& obj_d) const
382 {
383 wxMenuEvent *obj = (wxMenuEvent *)&obj_d;
384 wxEvent::CopyObject(obj_d);
385
386 obj->m_menuId = m_menuId;
387 }
388
389 void wxCloseEvent::CopyObject(wxObject& obj_d) const
390 {
391 wxCloseEvent *obj = (wxCloseEvent *)&obj_d;
392 wxEvent::CopyObject(obj_d);
393
394 obj->m_loggingOff = m_loggingOff;
395 obj->m_veto = m_veto;
396 #if WXWIN_COMPATIBILITY
397 obj->m_force = m_force;
398 #endif
399 obj->m_canVeto = m_canVeto;
400 }
401
402 void wxShowEvent::CopyObject(wxObject& obj_d) const
403 {
404 wxShowEvent *obj = (wxShowEvent *)&obj_d;
405 wxEvent::CopyObject(obj_d);
406
407 obj->m_show = m_show;
408 }
409
410 void wxJoystickEvent::CopyObject(wxObject& obj_d) const
411 {
412 wxJoystickEvent *obj = (wxJoystickEvent *)&obj_d;
413 wxEvent::CopyObject(obj_d);
414
415 obj->m_pos = m_pos;
416 obj->m_zPosition = m_zPosition;
417 obj->m_buttonChange = m_buttonChange;
418 obj->m_buttonState = m_buttonState;
419 obj->m_joyStick = m_joyStick;
420 }
421
422 void wxDropFilesEvent::CopyObject(wxObject& obj_d) const
423 {
424 wxDropFilesEvent *obj = (wxDropFilesEvent *)&obj_d;
425 wxEvent::CopyObject(obj_d);
426
427 obj->m_noFiles = m_noFiles;
428 obj->m_pos = m_pos;
429 // TODO: Problem with obj->m_files. It should be deallocated by the
430 // destructor of the event.
431 }
432
433 void wxIdleEvent::CopyObject(wxObject& obj_d) const
434 {
435 wxIdleEvent *obj = (wxIdleEvent *)&obj_d;
436 wxEvent::CopyObject(obj_d);
437
438 obj->m_requestMore = m_requestMore;
439 }
440
441 void wxUpdateUIEvent::CopyObject(wxObject &obj_d) const
442 {
443 wxUpdateUIEvent *obj = (wxUpdateUIEvent *)&obj_d;
444 wxEvent::CopyObject(obj_d);
445
446 obj->m_checked = m_checked;
447 obj->m_enabled = m_enabled;
448 obj->m_text = m_text;
449 obj->m_setText = m_setText;
450 obj->m_setChecked = m_setChecked;
451 obj->m_setEnabled = m_setEnabled;
452 }
453
454 void wxPaletteChangedEvent::CopyObject(wxObject &obj_d) const
455 {
456 wxPaletteChangedEvent *obj = (wxPaletteChangedEvent *)&obj_d;
457 wxEvent::CopyObject(obj_d);
458
459 obj->m_changedWindow = m_changedWindow;
460 }
461
462 void wxQueryNewPaletteEvent::CopyObject(wxObject& obj_d) const
463 {
464 wxQueryNewPaletteEvent *obj = (wxQueryNewPaletteEvent *)&obj_d;
465 wxEvent::CopyObject(obj_d);
466
467 obj->m_paletteRealized = m_paletteRealized;
468 }
469
470 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow *win)
471 : wxEvent(wxEVT_CREATE)
472 {
473 SetEventObject(win);
474 }
475
476 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow *win)
477 : wxEvent(wxEVT_DESTROY)
478 {
479 SetEventObject(win);
480 }
481
482 /*
483 * Event handler
484 */
485
486 wxEvtHandler::wxEvtHandler()
487 {
488 m_nextHandler = (wxEvtHandler *) NULL;
489 m_previousHandler = (wxEvtHandler *) NULL;
490 m_enabled = TRUE;
491 m_dynamicEvents = (wxList *) NULL;
492 m_isWindow = FALSE;
493 #if wxUSE_THREADS
494 m_eventsLocker = new wxCriticalSection();
495 #endif
496 m_pendingEvents = (wxList *) NULL;
497 }
498
499 wxEvtHandler::~wxEvtHandler()
500 {
501 // Takes itself out of the list of handlers
502 if (m_previousHandler)
503 m_previousHandler->m_nextHandler = m_nextHandler;
504
505 if (m_nextHandler)
506 m_nextHandler->m_previousHandler = m_previousHandler;
507
508 if (m_dynamicEvents)
509 {
510 wxNode *node = m_dynamicEvents->First();
511 while (node)
512 {
513 wxEventTableEntry *entry = (wxEventTableEntry*)node->Data();
514 if (entry->m_callbackUserData) delete entry->m_callbackUserData;
515 delete entry;
516 node = node->Next();
517 }
518 delete m_dynamicEvents;
519 };
520
521 #if wxUSE_THREADS
522 if (m_pendingEvents)
523 delete m_pendingEvents;
524
525 delete m_eventsLocker;
526 #endif
527 }
528
529 #if wxUSE_THREADS
530
531 #ifdef __WXGTK__
532 extern bool g_isIdle;
533 extern void wxapp_install_idle_handler();
534 #endif
535
536 bool wxEvtHandler::ProcessThreadEvent(wxEvent& event)
537 {
538 wxEvent *event_main;
539 wxCriticalSectionLocker locker(*m_eventsLocker);
540
541 // check that we are really in a child thread
542 wxASSERT( !wxThread::IsMain() );
543
544 if (m_pendingEvents == NULL)
545 m_pendingEvents = new wxList();
546
547 event_main = (wxEvent *)event.Clone();
548
549 m_pendingEvents->Append(event_main);
550
551 wxPendingEventsLocker->Enter();
552 wxPendingEvents->Append(this);
553 wxPendingEventsLocker->Leave();
554
555 #ifdef __WXGTK__
556 // if (g_isIdle)
557 // wxapp_install_idle_handler();
558 #endif
559
560 return TRUE;
561 }
562
563 void wxEvtHandler::ProcessPendingEvents()
564 {
565 wxCriticalSectionLocker locker(*m_eventsLocker);
566 wxNode *node = m_pendingEvents->First();
567 wxEvent *event;
568
569 while (node != NULL) {
570 event = (wxEvent *)node->Data();
571 ProcessEvent(*event);
572 delete node;
573 node = m_pendingEvents->First();
574 }
575 }
576 #endif
577
578 /*
579 * Event table stuff
580 */
581
582 bool wxEvtHandler::ProcessEvent(wxEvent& event)
583 {
584 // check that our flag corresponds to reality
585 wxASSERT( m_isWindow == IsKindOf(CLASSINFO(wxWindow)) );
586
587 // An event handler can be enabled or disabled
588 if ( GetEvtHandlerEnabled() )
589 {
590 #if wxUSE_THREADS
591 // Check whether we are in a child thread.
592 if (!wxThread::IsMain())
593 return ProcessThreadEvent(event);
594 #endif
595 // Handle per-instance dynamic event tables first
596
597 if ( m_dynamicEvents && SearchDynamicEventTable(event) )
598 return TRUE;
599
600 // Then static per-class event tables
601
602 const wxEventTable *table = GetEventTable();
603
604 // Try the associated validator first, if this is a window.
605 // Problem: if the event handler of the window has been replaced,
606 // this wxEvtHandler may no longer be a window.
607 // Therefore validators won't be processed if the handler
608 // has been replaced with SetEventHandler.
609 // THIS CAN BE CURED if PushEventHandler is used instead of
610 // SetEventHandler, and then processing will be passed down the
611 // chain of event handlers.
612 if ( m_isWindow )
613 {
614 wxWindow *win = (wxWindow *)this;
615
616 // Can only use the validator of the window which
617 // is receiving the event
618 if ( win == event.GetEventObject() )
619 {
620 wxValidator *validator = win->GetValidator();
621 if ( validator && validator->ProcessEvent(event) )
622 {
623 return TRUE;
624 }
625 }
626 }
627
628 // Search upwards through the inheritance hierarchy
629 while ( table )
630 {
631 if ( SearchEventTable((wxEventTable&)*table, event) )
632 return TRUE;
633 table = table->baseTable;
634 }
635 }
636
637 // Try going down the event handler chain
638 if ( GetNextHandler() )
639 {
640 if ( GetNextHandler()->ProcessEvent(event) )
641 return TRUE;
642 }
643
644 // Carry on up the parent-child hierarchy,
645 // but only if event is a command event: it wouldn't
646 // make sense for a parent to receive a child's size event, for example
647 if ( m_isWindow && event.IsCommandEvent() )
648 {
649 wxWindow *win = (wxWindow *)this;
650 wxWindow *parent = win->GetParent();
651 if (parent && !parent->IsBeingDeleted())
652 return parent->GetEventHandler()->ProcessEvent(event);
653 }
654
655 // Last try - application object.
656 if ( wxTheApp && (this != wxTheApp) )
657 {
658 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
659 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
660 // processed appropriately via SearchEventTable.
661 if ( event.GetEventType() != wxEVT_IDLE )
662 {
663 if ( wxTheApp->ProcessEvent(event) )
664 return TRUE;
665 }
666 }
667
668 return FALSE;
669 }
670
671 bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
672 {
673 int i = 0;
674 int commandId = event.GetId();
675
676 // BC++ doesn't like while (table.entries[i].m_fn)
677
678 #ifdef __SC__
679 while (table.entries[i].m_fn != 0)
680 #else
681 while (table.entries[i].m_fn != 0L)
682 #endif
683 {
684 if ((event.GetEventType() == table.entries[i].m_eventType) &&
685 (table.entries[i].m_id == -1 || // Match, if event spec says any id will do (id == -1)
686 (table.entries[i].m_lastId == -1 && commandId == table.entries[i].m_id) ||
687 (table.entries[i].m_lastId != -1 &&
688 (commandId >= table.entries[i].m_id && commandId <= table.entries[i].m_lastId))))
689 {
690 event.Skip(FALSE);
691 event.m_callbackUserData = table.entries[i].m_callbackUserData;
692
693 (this->*((wxEventFunction) (table.entries[i].m_fn)))(event);
694
695 if ( event.GetSkipped() )
696 return FALSE;
697 else
698 return TRUE;
699 }
700 i++;
701 }
702 return FALSE;
703 }
704 void wxEvtHandler::Connect( int id, int lastId,
705 wxEventType eventType,
706 wxObjectEventFunction func,
707 wxObject *userData )
708 {
709 wxEventTableEntry *entry = new wxEventTableEntry;
710 entry->m_id = id;
711 entry->m_lastId = lastId;
712 entry->m_eventType = eventType;
713 entry->m_fn = func;
714 entry->m_callbackUserData = userData;
715
716 if (!m_dynamicEvents)
717 m_dynamicEvents = new wxList;
718
719 m_dynamicEvents->Append( (wxObject*) entry );
720 }
721
722 bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
723 {
724 wxCHECK_MSG( m_dynamicEvents, FALSE,
725 _T("caller should check that we have dynamic events") );
726
727 int commandId = event.GetId();
728
729 wxNode *node = m_dynamicEvents->First();
730 while (node)
731 {
732 wxEventTableEntry *entry = (wxEventTableEntry*)node->Data();
733
734 if (entry->m_fn)
735 {
736 // Match, if event spec says any id will do (id == -1)
737 if ( (event.GetEventType() == entry->m_eventType) &&
738 (entry->m_id == -1 ||
739 (entry->m_lastId == -1 && commandId == entry->m_id) ||
740 (entry->m_lastId != -1 &&
741 (commandId >= entry->m_id && commandId <= entry->m_lastId))) )
742 {
743 event.Skip(FALSE);
744 event.m_callbackUserData = entry->m_callbackUserData;
745
746 (this->*((wxEventFunction) (entry->m_fn)))(event);
747
748 if (event.GetSkipped())
749 return FALSE;
750 else
751 return TRUE;
752 }
753 }
754 node = node->Next();
755 }
756 return FALSE;
757 };
758
759 #if WXWIN_COMPATIBILITY
760 bool wxEvtHandler::OnClose()
761 {
762 if (GetNextHandler())
763 return GetNextHandler()->OnClose();
764 else
765 return FALSE;
766 }
767 #endif // WXWIN_COMPATIBILITY
768
769 // Find a window with the focus, that is also a descendant of the given window.
770 // This is used to determine the window to initially send commands to.
771 wxWindow* wxFindFocusDescendant(wxWindow* ancestor)
772 {
773 // Process events starting with the window with the focus, if any.
774 wxWindow* focusWin = wxWindow::FindFocus();
775 wxWindow* win = focusWin;
776
777 // Check if this is a descendant of this frame.
778 // If not, win will be set to NULL.
779 while (win)
780 {
781 if (win == ancestor)
782 break;
783 else
784 win = win->GetParent();
785 }
786 if (win == (wxWindow*) NULL)
787 focusWin = (wxWindow*) NULL;
788
789 return focusWin;
790 }
791