moved all event handlers callign code in ProcessEventIfMatches() instead of triplicat...
[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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) && !defined(__EMX__)
21 // Some older compilers (such as EMX) cannot handle
22 // #pragma interface/implementation correctly, iff
23 // #pragma implementation is used in _two_ translation
24 // units (as created by e.g. event.cpp compiled for
25 // libwx_base and event.cpp compiled for libwx_gui_core).
26 // So we must not use those pragmas for those compilers in
27 // such files.
28 #pragma implementation "event.h"
29 #endif
30
31 // For compilers that support precompilation, includes "wx.h".
32 #include "wx/wxprec.h"
33
34 #ifdef __BORLANDC__
35 #pragma hdrstop
36 #endif
37
38 #ifndef WX_PRECOMP
39 #include "wx/defs.h"
40 #include "wx/app.h"
41 #include "wx/list.h"
42
43 #if wxUSE_GUI
44 #include "wx/control.h"
45 #include "wx/utils.h"
46 #include "wx/dc.h"
47 #endif // wxUSE_GUI
48 #endif
49
50 #include "wx/event.h"
51
52 #if wxUSE_GUI
53 #include "wx/validate.h"
54 #if wxUSE_STOPWATCH
55 #include "wx/stopwatch.h"
56 #endif
57 #endif // wxUSE_GUI
58
59 // ----------------------------------------------------------------------------
60 // wxWin macros
61 // ----------------------------------------------------------------------------
62
63 #if wxUSE_BASE
64 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject)
65 IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject)
66 #endif // wxUSE_BASE
67
68 #if wxUSE_GUI
69 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent)
70 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent)
71 IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent)
72 IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent)
73 IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent, wxEvent)
74 IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent)
75 IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent)
76 IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent)
77 IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent)
78 IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent, wxEvent)
79 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent)
80 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent)
81 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent)
82 IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent, wxCommandEvent)
83 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent)
84 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent)
85 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent)
86 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent)
87 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent)
88 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent)
89 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent)
90 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent)
91 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent)
92 IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent, wxEvent)
93 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent)
94 IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent, wxEvent)
95 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent)
96 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxEvent)
97 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, wxEvent)
98 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent, wxEvent)
99 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent, wxEvent)
100 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent, wxEvent)
101 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent, wxCommandEvent)
102 IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent, wxCommandEvent)
103 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent, wxEvent)
104 #endif // wxUSE_GUI
105
106 #if wxUSE_BASE
107
108 const wxEventTable *wxEvtHandler::GetEventTable() const
109 { return &wxEvtHandler::sm_eventTable; }
110
111 const wxEventTable wxEvtHandler::sm_eventTable =
112 { (const wxEventTable *)NULL, &wxEvtHandler::sm_eventTableEntries[0] };
113
114 wxEventHashTable &wxEvtHandler::GetEventHashTable() const
115 { return wxEvtHandler::sm_eventHashTable; }
116
117 wxEventHashTable wxEvtHandler::sm_eventHashTable(wxEvtHandler::sm_eventTable);
118
119 const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] =
120 { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL, 0, 0, (wxObjectEventFunction)NULL, NULL) };
121
122 // ----------------------------------------------------------------------------
123 // global variables
124 // ----------------------------------------------------------------------------
125
126 // To put pending event handlers
127 wxList *wxPendingEvents = (wxList *)NULL;
128
129 #if wxUSE_THREADS
130 // protects wxPendingEvents list
131 wxCriticalSection *wxPendingEventsLocker = (wxCriticalSection *)NULL;
132 #endif
133
134 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
135
136 // common event types are defined here, other event types are defined by the
137 // components which use them
138
139 const wxEventType wxEVT_FIRST = 10000;
140 const wxEventType wxEVT_USER_FIRST = wxEVT_FIRST + 2000;
141
142 DEFINE_EVENT_TYPE(wxEVT_NULL)
143 DEFINE_EVENT_TYPE(wxEVT_IDLE)
144 DEFINE_EVENT_TYPE(wxEVT_SOCKET)
145
146 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
147
148 #endif // wxUSE_BASE
149
150 #if wxUSE_GUI
151
152 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
153
154 DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED)
155 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED)
156 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED)
157 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED)
158 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED)
159 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED)
160 DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED)
161 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED)
162 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED)
163 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED)
164 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED)
165 DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED)
166 DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED)
167 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED)
168 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER)
169 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED)
170
171 // Sockets and timers send events, too
172 DEFINE_EVENT_TYPE(wxEVT_TIMER)
173
174 // Mouse event types
175 DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN)
176 DEFINE_EVENT_TYPE(wxEVT_LEFT_UP)
177 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN)
178 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP)
179 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN)
180 DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP)
181 DEFINE_EVENT_TYPE(wxEVT_MOTION)
182 DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW)
183 DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW)
184 DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK)
185 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK)
186 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK)
187 DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS)
188 DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS)
189 DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS)
190 DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL)
191
192 // Non-client mouse events
193 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN)
194 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP)
195 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN)
196 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP)
197 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN)
198 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP)
199 DEFINE_EVENT_TYPE(wxEVT_NC_MOTION)
200 DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW)
201 DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW)
202 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK)
203 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK)
204 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK)
205
206 // Character input event type
207 DEFINE_EVENT_TYPE(wxEVT_CHAR)
208 DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK)
209 DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY)
210 DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN)
211 DEFINE_EVENT_TYPE(wxEVT_KEY_UP)
212 #if wxUSE_HOTKEY
213 DEFINE_EVENT_TYPE(wxEVT_HOTKEY)
214 #endif
215
216 // Set cursor event
217 DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR)
218
219 // wxScrollbar and wxSlider event identifiers
220 DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP)
221 DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM)
222 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP)
223 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN)
224 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP)
225 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN)
226 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK)
227 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE)
228 DEFINE_EVENT_TYPE(wxEVT_SCROLL_ENDSCROLL)
229
230 // Scroll events from wxWindow
231 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP)
232 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM)
233 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP)
234 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN)
235 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP)
236 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN)
237 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK)
238 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE)
239
240 // System events
241 DEFINE_EVENT_TYPE(wxEVT_SIZE)
242 DEFINE_EVENT_TYPE(wxEVT_SIZING)
243 DEFINE_EVENT_TYPE(wxEVT_MOVE)
244 DEFINE_EVENT_TYPE(wxEVT_MOVING)
245 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW)
246 DEFINE_EVENT_TYPE(wxEVT_END_SESSION)
247 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION)
248 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP)
249 DEFINE_EVENT_TYPE(wxEVT_POWER)
250 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE)
251 DEFINE_EVENT_TYPE(wxEVT_CREATE)
252 DEFINE_EVENT_TYPE(wxEVT_DESTROY)
253 DEFINE_EVENT_TYPE(wxEVT_SHOW)
254 DEFINE_EVENT_TYPE(wxEVT_ICONIZE)
255 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE)
256 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED)
257 DEFINE_EVENT_TYPE(wxEVT_PAINT)
258 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND)
259 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT)
260 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON)
261 DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN)
262 DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE)
263 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT)
264 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU)
265 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED)
266 DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED)
267 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED)
268 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE)
269 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED)
270 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN)
271 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP)
272 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE)
273 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE)
274 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES)
275 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM)
276 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM)
277 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM)
278 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG)
279 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI)
280
281 // Generic command events
282 // Note: a click is a higher-level event than button down/up
283 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK)
284 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK)
285 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK)
286 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK)
287 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS)
288 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS)
289 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER)
290
291 // Help events
292 DEFINE_EVENT_TYPE(wxEVT_HELP)
293 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP)
294
295 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
296
297 #endif // wxUSE_GUI
298
299 #if wxUSE_BASE
300
301 // ============================================================================
302 // implementation
303 // ============================================================================
304
305 // ----------------------------------------------------------------------------
306 // event initialization
307 // ----------------------------------------------------------------------------
308
309 int wxNewEventType()
310 {
311 // MT-FIXME
312 static int s_lastUsedEventType = wxEVT_FIRST;
313
314 return s_lastUsedEventType++;
315 }
316
317 // ----------------------------------------------------------------------------
318 // wxEvent
319 // ----------------------------------------------------------------------------
320
321 /*
322 * General wxWindows events, covering
323 * all interesting things that might happen (button clicking, resizing,
324 * setting text in widgets, etc.).
325 *
326 * For each completely new event type, derive a new event class.
327 *
328 */
329
330 wxEvent::wxEvent(int theId, wxEventType commandType )
331 {
332 m_eventType = commandType;
333 m_eventObject = (wxObject *) NULL;
334 m_timeStamp = 0;
335 m_id = theId;
336 m_skipped = false;
337 m_callbackUserData = (wxObject *) NULL;
338 m_isCommandEvent = false;
339 m_propagationLevel = wxEVENT_PROPAGATE_NONE;
340 }
341
342 wxEvent::wxEvent(const wxEvent &src)
343 : wxObject()
344 , m_eventObject(src.m_eventObject)
345 , m_eventType(src.m_eventType)
346 , m_timeStamp(src.m_timeStamp)
347 , m_id(src.m_id)
348 , m_callbackUserData(src.m_callbackUserData)
349 , m_propagationLevel(src.m_propagationLevel)
350 , m_skipped(src.m_skipped)
351 , m_isCommandEvent(src.m_isCommandEvent)
352 {
353 }
354
355 #endif // wxUSE_BASE
356
357 #if wxUSE_GUI
358
359 /*
360 * Command events
361 *
362 */
363
364 wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId)
365 : wxEvent(theId, commandType)
366 {
367 m_clientData = (char *) NULL;
368 m_clientObject = (wxClientData *) NULL;
369 m_extraLong = 0;
370 m_commandInt = 0;
371 m_isCommandEvent = true;
372
373 // the command events are propagated upwards by default
374 m_propagationLevel = wxEVENT_PROPAGATE_MAX;
375 }
376
377 /*
378 * UI update events
379 */
380
381 #if wxUSE_LONGLONG
382 wxLongLong wxUpdateUIEvent::sm_lastUpdate = 0;
383 #endif
384
385 long wxUpdateUIEvent::sm_updateInterval = 0;
386
387 wxUpdateUIMode wxUpdateUIEvent::sm_updateMode = wxUPDATE_UI_PROCESS_ALL;
388
389 // Can we update?
390 bool wxUpdateUIEvent::CanUpdate(wxWindowBase *win)
391 {
392 // Don't update if we've switched global updating off
393 // and this window doesn't support updates.
394 if (win &&
395 (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED &&
396 ((win->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES) == 0)))
397 return false;
398
399 if (sm_updateInterval == -1)
400 return false;
401 else if (sm_updateInterval == 0)
402 return true;
403 else
404 {
405 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
406 wxLongLong now = wxGetLocalTimeMillis();
407 if (now > (sm_lastUpdate + sm_updateInterval))
408 {
409 return true;
410 }
411 #else
412 // If we don't have wxStopWatch or wxLongLong, we
413 // should err on the safe side and update now anyway.
414 return true;
415 #endif
416 }
417 return false;
418 }
419
420 // Reset the update time to provide a delay until the next
421 // time we should update
422 void wxUpdateUIEvent::ResetUpdateTime()
423 {
424 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
425 if (sm_updateInterval > 0)
426 {
427 wxLongLong now = wxGetLocalTimeMillis();
428 if (now > (sm_lastUpdate + sm_updateInterval))
429 {
430 sm_lastUpdate = now;
431 }
432 }
433 #endif
434 }
435
436 /*
437 * Idle events
438 */
439
440 wxIdleMode wxIdleEvent::sm_idleMode = wxIDLE_PROCESS_ALL;
441
442 // Can we send an idle event?
443 bool wxIdleEvent::CanSend(wxWindow* win)
444 {
445 // Don't update if we've switched global updating off
446 // and this window doesn't support updates.
447 if (win &&
448 (GetMode() == wxIDLE_PROCESS_SPECIFIED &&
449 ((win->GetExtraStyle() & wxWS_EX_PROCESS_IDLE) == 0)))
450 return false;
451
452 return true;
453 }
454
455 /*
456 * Scroll events
457 */
458
459 wxScrollEvent::wxScrollEvent(wxEventType commandType,
460 int id,
461 int pos,
462 int orient)
463 : wxCommandEvent(commandType, id)
464 {
465 m_extraLong = orient;
466 m_commandInt = pos;
467 }
468
469 /*
470 * ScrollWin events
471 */
472
473 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType,
474 int pos,
475 int orient)
476 {
477 m_eventType = commandType;
478 m_extraLong = orient;
479 m_commandInt = pos;
480 }
481
482 /*
483 * Mouse events
484 *
485 */
486
487 wxMouseEvent::wxMouseEvent(wxEventType commandType)
488 {
489 m_eventType = commandType;
490 m_metaDown = false;
491 m_altDown = false;
492 m_controlDown = false;
493 m_shiftDown = false;
494 m_leftDown = false;
495 m_rightDown = false;
496 m_middleDown = false;
497 m_x = 0;
498 m_y = 0;
499 m_wheelRotation = 0;
500 m_wheelDelta = 0;
501 m_linesPerAction = 0;
502 }
503
504 void wxMouseEvent::Assign(const wxMouseEvent& event)
505 {
506 m_eventType = event.m_eventType;
507
508 m_x = event.m_x;
509 m_y = event.m_y;
510
511 m_leftDown = event.m_leftDown;
512 m_middleDown = event.m_middleDown;
513 m_rightDown = event.m_rightDown;
514
515 m_controlDown = event.m_controlDown;
516 m_shiftDown = event.m_shiftDown;
517 m_altDown = event.m_altDown;
518 m_metaDown = event.m_metaDown;
519
520 m_wheelRotation = event.m_wheelRotation;
521 m_wheelDelta = event.m_wheelDelta;
522 m_linesPerAction = event.m_linesPerAction;
523 }
524
525 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
526 // or any button dclick event (but = -1)
527 bool wxMouseEvent::ButtonDClick(int but) const
528 {
529 switch (but)
530 {
531 case -1:
532 return (LeftDClick() || MiddleDClick() || RightDClick());
533 case 1:
534 return LeftDClick();
535 case 2:
536 return MiddleDClick();
537 case 3:
538 return RightDClick();
539 default:
540 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
541 }
542
543 return false;
544 }
545
546 // True if was a button down event (1 = left, 2 = middle, 3 = right)
547 // or any button down event (but = -1)
548 bool wxMouseEvent::ButtonDown(int but) const
549 {
550 switch (but)
551 {
552 case -1:
553 return (LeftDown() || MiddleDown() || RightDown());
554 case 1:
555 return LeftDown();
556 case 2:
557 return MiddleDown();
558 case 3:
559 return RightDown();
560 default:
561 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
562 }
563
564 return false;
565 }
566
567 // True if was a button up event (1 = left, 2 = middle, 3 = right)
568 // or any button up event (but = -1)
569 bool wxMouseEvent::ButtonUp(int but) const
570 {
571 switch (but)
572 {
573 case -1:
574 return (LeftUp() || MiddleUp() || RightUp());
575 case 1:
576 return LeftUp();
577 case 2:
578 return MiddleUp();
579 case 3:
580 return RightUp();
581 default:
582 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
583 }
584
585 return false;
586 }
587
588 // True if the given button is currently changing state
589 bool wxMouseEvent::Button(int but) const
590 {
591 switch (but)
592 {
593 case -1:
594 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
595 case 1:
596 return (LeftDown() || LeftUp() || LeftDClick());
597 case 2:
598 return (MiddleDown() || MiddleUp() || MiddleDClick());
599 case 3:
600 return (RightDown() || RightUp() || RightDClick());
601 default:
602 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
603 }
604
605 return false;
606 }
607
608 bool wxMouseEvent::ButtonIsDown(int but) const
609 {
610 switch (but)
611 {
612 case -1:
613 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
614 case 1:
615 return LeftIsDown();
616 case 2:
617 return MiddleIsDown();
618 case 3:
619 return RightIsDown();
620 default:
621 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
622 }
623
624 return false;
625 }
626
627 int wxMouseEvent::GetButton() const
628 {
629 for ( int i = 1; i <= 3; i++ )
630 {
631 if ( Button(i) )
632 {
633 return i;
634 }
635 }
636
637 return -1;
638 }
639
640 // Find the logical position of the event given the DC
641 wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const
642 {
643 wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y));
644 return pt;
645 }
646
647
648 /*
649 * Keyboard event
650 *
651 */
652
653 wxKeyEvent::wxKeyEvent(wxEventType type)
654 {
655 m_eventType = type;
656 m_shiftDown = false;
657 m_controlDown = false;
658 m_metaDown = false;
659 m_altDown = false;
660 m_keyCode = 0;
661 m_scanCode = 0;
662 #if wxUSE_UNICODE
663 m_uniChar = 0;
664 #endif
665 }
666
667 wxKeyEvent::wxKeyEvent(const wxKeyEvent& evt)
668 : wxEvent(evt)
669 {
670 m_x = evt.m_x;
671 m_y = evt.m_y;
672
673 m_keyCode = evt.m_keyCode;
674
675 m_controlDown = evt.m_controlDown;
676 m_shiftDown = evt.m_shiftDown;
677 m_altDown = evt.m_altDown;
678 m_metaDown = evt.m_metaDown;
679 m_scanCode = evt.m_scanCode;
680 m_rawCode = evt.m_rawCode;
681 m_rawFlags = evt.m_rawFlags;
682
683 #if wxUSE_UNICODE
684 m_uniChar = evt.m_uniChar;
685 #endif
686 }
687
688 long wxKeyEvent::KeyCode() const
689 {
690 return m_keyCode;
691 }
692
693 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow *win)
694 {
695 SetEventType(wxEVT_CREATE);
696 SetEventObject(win);
697 }
698
699 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow *win)
700 {
701 SetEventType(wxEVT_DESTROY);
702 SetEventObject(win);
703 }
704
705 wxChildFocusEvent::wxChildFocusEvent(wxWindow *win)
706 : wxCommandEvent(wxEVT_CHILD_FOCUS)
707 {
708 SetEventObject(win);
709 }
710
711 #endif // wxUSE_GUI
712
713
714 #if wxUSE_BASE
715
716 // ----------------------------------------------------------------------------
717 // wxEventHashTable
718 // ----------------------------------------------------------------------------
719
720 static const int EVENT_TYPE_TABLE_INIT_SIZE = 31; // Not to big not to small...
721
722 wxEventHashTable::wxEventHashTable(const wxEventTable &table)
723 : m_table(table),
724 m_rebuildHash(true)
725 {
726 AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE);
727 }
728
729 wxEventHashTable::~wxEventHashTable()
730 {
731 size_t i;
732 for(i = 0; i < m_size; i++)
733 {
734 EventTypeTablePointer eTTnode = m_eventTypeTable[i];
735 if (eTTnode)
736 {
737 delete eTTnode;
738 }
739 }
740
741 delete[] m_eventTypeTable;
742 }
743
744 bool wxEventHashTable::HandleEvent(wxEvent &event, wxEvtHandler *self)
745 {
746 if (m_rebuildHash)
747 {
748 InitHashTable();
749 m_rebuildHash = false;
750 }
751
752 // Find all entries for the given event type.
753 wxEventType eventType = event.GetEventType();
754 const EventTypeTablePointer eTTnode = m_eventTypeTable[eventType % m_size];
755 if (eTTnode && eTTnode->eventType == eventType)
756 {
757 // Now start the search for an event handler
758 // that can handle an event with the given ID.
759 const wxEventTableEntryPointerArray&
760 eventEntryTable = eTTnode->eventEntryTable;
761
762 const size_t count = eventEntryTable.GetCount();
763 for (size_t n = 0; n < count; n++)
764 {
765 if ( wxEvtHandler::
766 ProcessEventIfMatches(*eventEntryTable[n], self, event) )
767 {
768 return true;
769 }
770 }
771 }
772
773 return false;
774 }
775
776 void wxEventHashTable::InitHashTable()
777 {
778 // Loop over the event tables and all its base tables.
779 const wxEventTable *table = &m_table;
780 while (table)
781 {
782 // Retrieve all valid event handler entries
783 const wxEventTableEntry *entry = table->entries;
784 while (entry->m_fn != 0)
785 {
786 // Add the event entry in the Hash.
787 AddEntry(*entry);
788
789 entry++;
790 }
791
792 table = table->baseTable;
793 }
794
795 // Lets free some memory.
796 size_t i;
797 for(i = 0; i < m_size; i++)
798 {
799 EventTypeTablePointer eTTnode = m_eventTypeTable[i];
800 if (eTTnode)
801 {
802 eTTnode->eventEntryTable.Shrink();
803 }
804 }
805 }
806
807 void wxEventHashTable::AddEntry(const wxEventTableEntry &entry)
808 {
809 EventTypeTablePointer *peTTnode = &m_eventTypeTable[entry.m_eventType % m_size];
810 EventTypeTablePointer eTTnode = *peTTnode;
811
812 if (eTTnode)
813 {
814 if (eTTnode->eventType != entry.m_eventType)
815 {
816 // Resize the table!
817 GrowEventTypeTable();
818 // Try again to add it.
819 AddEntry(entry);
820 return;
821 }
822 }
823 else
824 {
825 eTTnode = new EventTypeTable;
826 eTTnode->eventType = entry.m_eventType;
827 *peTTnode = eTTnode;
828 }
829
830 // Fill all hash entries between entry.m_id and entry.m_lastId...
831 eTTnode->eventEntryTable.Add(&entry);
832 }
833
834 void wxEventHashTable::AllocEventTypeTable(size_t size)
835 {
836 m_eventTypeTable = new EventTypeTablePointer[size];
837 memset((void *)m_eventTypeTable, 0, sizeof(EventTypeTablePointer)*size);
838 m_size = size;
839 }
840
841 void wxEventHashTable::GrowEventTypeTable()
842 {
843 size_t oldSize = m_size;
844 EventTypeTablePointer *oldEventTypeTable = m_eventTypeTable;
845
846 // TODO: Search the most optimal grow sequence
847 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize*2+1);
848
849 for ( size_t i = 0; i < oldSize; /* */ )
850 {
851 EventTypeTablePointer eTToldNode = oldEventTypeTable[i];
852 if (eTToldNode)
853 {
854 EventTypeTablePointer *peTTnode = &m_eventTypeTable[eTToldNode->eventType % m_size];
855 EventTypeTablePointer eTTnode = *peTTnode;
856
857 // Check for collision, we don't want any.
858 if (eTTnode)
859 {
860 GrowEventTypeTable();
861 continue; // Don't increment the counter,
862 // as we still need to add this element.
863 }
864 else
865 {
866 // Get the old value and put it in the new table.
867 *peTTnode = oldEventTypeTable[i];
868 }
869 }
870
871 i++;
872 }
873
874 delete[] oldEventTypeTable;
875 }
876
877 // ----------------------------------------------------------------------------
878 // wxEvtHandler
879 // ----------------------------------------------------------------------------
880
881 /*
882 * Event handler
883 */
884
885 wxEvtHandler::wxEvtHandler()
886 {
887 m_nextHandler = (wxEvtHandler *) NULL;
888 m_previousHandler = (wxEvtHandler *) NULL;
889 m_enabled = true;
890 m_dynamicEvents = (wxList *) NULL;
891 m_pendingEvents = (wxList *) NULL;
892 #if wxUSE_THREADS
893 # if !defined(__VISAGECPP__)
894 m_eventsLocker = new wxCriticalSection;
895 # endif
896 #endif
897 // no client data (yet)
898 m_clientData = NULL;
899 m_clientDataType = wxClientData_None;
900 }
901
902 wxEvtHandler::~wxEvtHandler()
903 {
904 // Takes itself out of the list of handlers
905 if (m_previousHandler)
906 m_previousHandler->m_nextHandler = m_nextHandler;
907
908 if (m_nextHandler)
909 m_nextHandler->m_previousHandler = m_previousHandler;
910
911 if (m_dynamicEvents)
912 {
913 wxList::iterator it = m_dynamicEvents->begin(),
914 en = m_dynamicEvents->end();
915 for (;it != en; ++it)
916 {
917 #if WXWIN_COMPATIBILITY_EVENT_TYPES
918 wxEventTableEntry *entry = (wxEventTableEntry*)*it;
919 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
920 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)*it;
921 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
922
923 if (entry->m_callbackUserData)
924 delete entry->m_callbackUserData;
925 delete entry;
926 }
927 delete m_dynamicEvents;
928 };
929
930 delete m_pendingEvents;
931
932 #if wxUSE_THREADS
933 # if !defined(__VISAGECPP__)
934 delete m_eventsLocker;
935 # endif
936
937 // Remove us from wxPendingEvents if necessary.
938 if(wxPendingEventsLocker)
939 wxENTER_CRIT_SECT(*wxPendingEventsLocker);
940 if ( wxPendingEvents ) {
941 wxPendingEvents->DeleteObject(this);
942 }
943 if(wxPendingEventsLocker)
944 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker);
945 #endif
946
947 // we only delete object data, not untyped
948 if ( m_clientDataType == wxClientData_Object )
949 delete m_clientObject;
950 }
951
952 #if wxUSE_THREADS
953
954 bool wxEvtHandler::ProcessThreadEvent(wxEvent& event)
955 {
956 // check that we are really in a child thread
957 wxASSERT_MSG( !wxThread::IsMain(),
958 wxT("use ProcessEvent() in main thread") );
959
960 AddPendingEvent(event);
961
962 return true;
963 }
964
965 void wxEvtHandler::ClearEventLocker()
966 {
967 #if !defined(__VISAGECPP__)
968 delete m_eventsLocker;
969 m_eventsLocker = NULL;
970 #endif
971 };
972
973 #endif // wxUSE_THREADS
974
975 void wxEvtHandler::AddPendingEvent(wxEvent& event)
976 {
977 // 1) Add event to list of pending events of this event handler
978
979 wxEvent *eventCopy = event.Clone();
980
981 // we must be able to copy the events here so the event class must
982 // implement Clone() properly instead of just providing a NULL stab for it
983 wxCHECK_RET( eventCopy,
984 _T("events of this type aren't supposed to be posted") );
985
986 #if defined(__VISAGECPP__)
987 wxENTER_CRIT_SECT( m_eventsLocker);
988 #else
989 wxENTER_CRIT_SECT( *m_eventsLocker);
990 #endif
991
992 if ( !m_pendingEvents )
993 m_pendingEvents = new wxList;
994
995 m_pendingEvents->Append(eventCopy);
996
997 #if defined(__VISAGECPP__)
998 wxLEAVE_CRIT_SECT( m_eventsLocker);
999 #else
1000 wxLEAVE_CRIT_SECT( *m_eventsLocker);
1001 #endif
1002
1003 // 2) Add this event handler to list of event handlers that
1004 // have pending events.
1005
1006 wxENTER_CRIT_SECT(*wxPendingEventsLocker);
1007
1008 if ( !wxPendingEvents )
1009 wxPendingEvents = new wxList;
1010 wxPendingEvents->Append(this);
1011
1012 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker);
1013
1014 // 3) Inform the system that new pending events are somwehere,
1015 // and that these should be processed in idle time.
1016 wxWakeUpIdle();
1017 }
1018
1019 void wxEvtHandler::ProcessPendingEvents()
1020 {
1021 #if defined(__VISAGECPP__)
1022 wxENTER_CRIT_SECT( m_eventsLocker);
1023 #else
1024 wxENTER_CRIT_SECT( *m_eventsLocker);
1025 #endif
1026
1027 wxList::compatibility_iterator node = m_pendingEvents->GetFirst();
1028 while ( node )
1029 {
1030 wxEvent *event = (wxEvent *)node->GetData();
1031 m_pendingEvents->Erase(node);
1032
1033 // In ProcessEvent, new events might get added and
1034 // we can safely leave the crtical section here.
1035 #if defined(__VISAGECPP__)
1036 wxLEAVE_CRIT_SECT( m_eventsLocker);
1037 #else
1038 wxLEAVE_CRIT_SECT( *m_eventsLocker);
1039 #endif
1040 ProcessEvent(*event);
1041 delete event;
1042 #if defined(__VISAGECPP__)
1043 wxENTER_CRIT_SECT( m_eventsLocker);
1044 #else
1045 wxENTER_CRIT_SECT( *m_eventsLocker);
1046 #endif
1047
1048 node = m_pendingEvents->GetFirst();
1049 }
1050
1051 #if defined(__VISAGECPP__)
1052 wxLEAVE_CRIT_SECT( m_eventsLocker);
1053 #else
1054 wxLEAVE_CRIT_SECT( *m_eventsLocker);
1055 #endif
1056 }
1057
1058 /*
1059 * Event table stuff
1060 */
1061 /* static */ bool
1062 wxEvtHandler::ProcessEventIfMatches(const wxEventTableEntryBase& entry,
1063 wxEvtHandler *handler,
1064 wxEvent& event)
1065 {
1066 int tableId1 = entry.m_id,
1067 tableId2 = entry.m_lastId;
1068
1069 // match only if the event type is the same and the id is either -1 in
1070 // the event table (meaning "any") or the event id matches the id
1071 // specified in the event table either exactly or by falling into
1072 // range between first and last
1073 if ((tableId1 == -1) ||
1074 (tableId2 == -1 && tableId1 == event.GetId()) ||
1075 (tableId2 != -1 &&
1076 (event.GetId() >= tableId1 && event.GetId() <= tableId2)))
1077 {
1078 event.Skip(false);
1079 event.m_callbackUserData = entry.m_callbackUserData;
1080
1081 #if wxUSE_EXCEPTIONS
1082 if ( wxTheApp )
1083 {
1084 // call the handler via wxApp method which allows the user to catch
1085 // any exceptions which may be thrown by any handler in the program
1086 // in one place
1087 wxTheApp->HandleEvent(handler, (wxEventFunction)entry.m_fn, event);
1088 }
1089 else
1090 #else // !wxUSE_EXCEPTIONS
1091 {
1092 // no need for an extra virtual function call
1093 (handler->*((wxEventFunction) (entry.m_fn)))(event);
1094 }
1095 #endif // wxUSE_EXCEPTIONS
1096
1097 if (!event.GetSkipped())
1098 return true;
1099 }
1100
1101 return false;
1102 }
1103
1104 bool wxEvtHandler::TryParent(wxEvent& event)
1105 {
1106 if ( wxTheApp && (this != wxTheApp) )
1107 {
1108 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1109 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1110 // processed appropriately via SearchEventTable.
1111 if ( event.GetEventType() != wxEVT_IDLE )
1112 {
1113 if ( wxTheApp->ProcessEvent(event) )
1114 return true;
1115 }
1116 }
1117
1118 return false;
1119 }
1120
1121 bool wxEvtHandler::ProcessEvent(wxEvent& event)
1122 {
1123 // allow the application to hook into event processing
1124 if ( wxTheApp )
1125 {
1126 int rc = wxTheApp->FilterEvent(event);
1127 if ( rc != -1 )
1128 {
1129 wxASSERT_MSG( rc == 1 || rc == 0,
1130 _T("unexpected wxApp::FilterEvent return value") );
1131
1132 return rc != 0;
1133 }
1134 //else: proceed normally
1135 }
1136
1137 // An event handler can be enabled or disabled
1138 if ( GetEvtHandlerEnabled() )
1139 {
1140 // if we have a validator, it has higher priority than our own event
1141 // table
1142 if ( TryValidator(event) )
1143 return true;
1144
1145 // Handle per-instance dynamic event tables first
1146 if ( m_dynamicEvents && SearchDynamicEventTable(event) )
1147 return true;
1148
1149 // Then static per-class event tables
1150 if ( GetEventHashTable().HandleEvent(event, this) )
1151 return true;
1152 }
1153
1154 // Try going down the event handler chain
1155 if ( GetNextHandler() )
1156 {
1157 if ( GetNextHandler()->ProcessEvent(event) )
1158 return true;
1159 }
1160
1161 // Finally propagate the event upwards the window chain and/or to the
1162 // application object as necessary
1163 return TryParent(event);
1164 }
1165
1166
1167 bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
1168 {
1169 const wxEventType eventType = event.GetEventType();
1170 for ( int i = 0; table.entries[i].m_fn != 0; i++ )
1171 {
1172 const wxEventTableEntry& entry = table.entries[i];
1173 if ( eventType == entry.m_eventType )
1174 {
1175 if ( ProcessEventIfMatches(entry, this, event) )
1176 return true;
1177 }
1178 }
1179
1180 return false;
1181 }
1182
1183 void wxEvtHandler::Connect( int id, int lastId,
1184 int eventType,
1185 wxObjectEventFunction func,
1186 wxObject *userData,
1187 wxEvtHandler* eventSink )
1188 {
1189 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1190 wxEventTableEntry *entry = new wxEventTableEntry;
1191 entry->m_eventType = eventType;
1192 entry->m_id = id;
1193 entry->m_lastId = lastId;
1194 entry->m_fn = func;
1195 entry->m_callbackUserData = userData;
1196 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1197 wxDynamicEventTableEntry *entry =
1198 new wxDynamicEventTableEntry(eventType, id, lastId, func, userData, eventSink);
1199 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1200
1201 if (!m_dynamicEvents)
1202 m_dynamicEvents = new wxList;
1203
1204 // Insert at the front of the list so most recent additions are found first
1205 m_dynamicEvents->Insert( (wxObject*) entry );
1206 }
1207
1208 bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType,
1209 wxObjectEventFunction func,
1210 wxObject *userData,
1211 wxEvtHandler* eventSink )
1212 {
1213 if (!m_dynamicEvents)
1214 return false;
1215
1216 wxList::compatibility_iterator node = m_dynamicEvents->GetFirst();
1217 while (node)
1218 {
1219 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1220 wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData();
1221 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1222 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
1223 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1224
1225 if ((entry->m_id == id) &&
1226 ((entry->m_lastId == lastId) || (lastId == -1)) &&
1227 ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) &&
1228 ((entry->m_fn == func) || (func == (wxObjectEventFunction)NULL)) &&
1229 ((entry->m_eventSink == eventSink) || (eventSink == (wxEvtHandler*)NULL)) &&
1230 ((entry->m_callbackUserData == userData) || (userData == (wxObject*)NULL)))
1231 {
1232 if (entry->m_callbackUserData)
1233 delete entry->m_callbackUserData;
1234 m_dynamicEvents->Erase( node );
1235 delete entry;
1236 return true;
1237 }
1238 node = node->GetNext();
1239 }
1240 return false;
1241 }
1242
1243 bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
1244 {
1245 wxCHECK_MSG( m_dynamicEvents, false,
1246 wxT("caller should check that we have dynamic events") );
1247
1248 wxList::compatibility_iterator node = m_dynamicEvents->GetFirst();
1249 while (node)
1250 {
1251 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1252 wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData();
1253 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1254 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
1255 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1256
1257 if (entry->m_fn)
1258 {
1259 wxEvtHandler *handler =
1260 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
1261 entry->m_eventSink ? entry->m_eventSink
1262 :
1263 #endif
1264 this;
1265
1266 if ( ProcessEventIfMatches(*entry, handler, event) )
1267 {
1268 return true;
1269 }
1270 }
1271
1272 node = node->GetNext();
1273 }
1274
1275 return false;
1276 };
1277
1278 void wxEvtHandler::DoSetClientObject( wxClientData *data )
1279 {
1280 wxASSERT_MSG( m_clientDataType != wxClientData_Void,
1281 wxT("can't have both object and void client data") );
1282
1283 if ( m_clientObject )
1284 delete m_clientObject;
1285
1286 m_clientObject = data;
1287 m_clientDataType = wxClientData_Object;
1288 }
1289
1290 wxClientData *wxEvtHandler::DoGetClientObject() const
1291 {
1292 // it's not an error to call GetClientObject() on a window which doesn't
1293 // have client data at all - NULL will be returned
1294 wxASSERT_MSG( m_clientDataType != wxClientData_Void,
1295 wxT("this window doesn't have object client data") );
1296
1297 return m_clientObject;
1298 }
1299
1300 void wxEvtHandler::DoSetClientData( void *data )
1301 {
1302 wxASSERT_MSG( m_clientDataType != wxClientData_Object,
1303 wxT("can't have both object and void client data") );
1304
1305 m_clientData = data;
1306 m_clientDataType = wxClientData_Void;
1307 }
1308
1309 void *wxEvtHandler::DoGetClientData() const
1310 {
1311 // it's not an error to call GetClientData() on a window which doesn't have
1312 // client data at all - NULL will be returned
1313 wxASSERT_MSG( m_clientDataType != wxClientData_Object,
1314 wxT("this window doesn't have void client data") );
1315
1316 return m_clientData;
1317 }
1318
1319 #endif // wxUSE_BASE
1320
1321 #if wxUSE_GUI
1322
1323 // Find a window with the focus, that is also a descendant of the given window.
1324 // This is used to determine the window to initially send commands to.
1325 wxWindow* wxFindFocusDescendant(wxWindow* ancestor)
1326 {
1327 // Process events starting with the window with the focus, if any.
1328 wxWindow* focusWin = wxWindow::FindFocus();
1329 wxWindow* win = focusWin;
1330
1331 // Check if this is a descendant of this frame.
1332 // If not, win will be set to NULL.
1333 while (win)
1334 {
1335 if (win == ancestor)
1336 break;
1337 else
1338 win = win->GetParent();
1339 }
1340 if (win == (wxWindow*) NULL)
1341 focusWin = (wxWindow*) NULL;
1342
1343 return focusWin;
1344 }
1345
1346 #endif // wxUSE_GUI