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