]> git.saurik.com Git - wxWidgets.git/blob - src/common/event.cpp
wxNavigationKeyEvent doesn't derive from wxCommandEvent (but from wxEvent)
[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 int eventId = event.GetId();
760 const wxEventTableEntryPointerArray &eventEntryTable = eTTnode->eventEntryTable;
761
762 size_t n;
763 size_t count = eventEntryTable.GetCount();
764 for (n = 0; n < count; n++)
765 {
766 const wxEventTableEntry* entry = eventEntryTable[n];
767 int tableId1 = entry->m_id,
768 tableId2 = entry->m_lastId;
769
770 if ((tableId1 == -1) ||
771 (tableId2 == -1 && tableId1 == eventId) ||
772 (tableId2 != -1 &&
773 (eventId >= tableId1 && eventId <= tableId2)))
774 {
775 event.Skip(FALSE);
776 event.m_callbackUserData = entry->m_callbackUserData;
777
778 (self->*((wxEventFunction) (entry->m_fn)))(event);
779
780 if (!event.GetSkipped())
781 return TRUE;
782 }
783 }
784
785 return FALSE;
786 }
787
788 return FALSE;
789 }
790
791 void wxEventHashTable::InitHashTable()
792 {
793 // Loop over the event tables and all its base tables.
794 const wxEventTable *table = &m_table;
795 while (table)
796 {
797 // Retrieve all valid event handler entries
798 const wxEventTableEntry *entry = table->entries;
799 while (entry->m_fn != 0)
800 {
801 // Add the event entry in the Hash.
802 AddEntry(*entry);
803
804 entry++;
805 }
806
807 table = table->baseTable;
808 }
809
810 // Lets free some memory.
811 size_t i;
812 for(i = 0; i < m_size; i++)
813 {
814 EventTypeTablePointer eTTnode = m_eventTypeTable[i];
815 if (eTTnode)
816 {
817 eTTnode->eventEntryTable.Shrink();
818 }
819 }
820 }
821
822 void wxEventHashTable::AddEntry(const wxEventTableEntry &entry)
823 {
824 EventTypeTablePointer *peTTnode = &m_eventTypeTable[entry.m_eventType % m_size];
825 EventTypeTablePointer eTTnode = *peTTnode;
826
827 if (eTTnode)
828 {
829 if (eTTnode->eventType != entry.m_eventType)
830 {
831 // Resize the table!
832 GrowEventTypeTable();
833 // Try again to add it.
834 AddEntry(entry);
835 return;
836 }
837 }
838 else
839 {
840 eTTnode = new EventTypeTable;
841 eTTnode->eventType = entry.m_eventType;
842 *peTTnode = eTTnode;
843 }
844
845 // Fill all hash entries between entry.m_id and entry.m_lastId...
846 eTTnode->eventEntryTable.Add(&entry);
847 }
848
849 void wxEventHashTable::AllocEventTypeTable(size_t size)
850 {
851 m_eventTypeTable = new EventTypeTablePointer[size];
852 memset((void *)m_eventTypeTable, 0, sizeof(EventTypeTablePointer)*size);
853 m_size = size;
854 }
855
856 void wxEventHashTable::GrowEventTypeTable()
857 {
858 size_t oldSize = m_size;
859 EventTypeTablePointer *oldEventTypeTable = m_eventTypeTable;
860
861 // TODO: Search the most optimal grow sequence
862 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize*2+1);
863
864 for ( size_t i = 0; i < oldSize; /* */ )
865 {
866 EventTypeTablePointer eTToldNode = oldEventTypeTable[i];
867 if (eTToldNode)
868 {
869 EventTypeTablePointer *peTTnode = &m_eventTypeTable[eTToldNode->eventType % m_size];
870 EventTypeTablePointer eTTnode = *peTTnode;
871
872 // Check for collision, we don't want any.
873 if (eTTnode)
874 {
875 GrowEventTypeTable();
876 continue; // Don't increment the counter,
877 // as we still need to add this element.
878 }
879 else
880 {
881 // Get the old value and put it in the new table.
882 *peTTnode = oldEventTypeTable[i];
883 }
884 }
885
886 i++;
887 }
888
889 delete[] oldEventTypeTable;
890 }
891
892 // ----------------------------------------------------------------------------
893 // wxEvtHandler
894 // ----------------------------------------------------------------------------
895
896 /*
897 * Event handler
898 */
899
900 wxEvtHandler::wxEvtHandler()
901 {
902 m_nextHandler = (wxEvtHandler *) NULL;
903 m_previousHandler = (wxEvtHandler *) NULL;
904 m_enabled = TRUE;
905 m_dynamicEvents = (wxList *) NULL;
906 m_pendingEvents = (wxList *) NULL;
907 #if wxUSE_THREADS
908 # if !defined(__VISAGECPP__)
909 m_eventsLocker = new wxCriticalSection;
910 # endif
911 #endif
912 // no client data (yet)
913 m_clientData = NULL;
914 m_clientDataType = wxClientData_None;
915 }
916
917 wxEvtHandler::~wxEvtHandler()
918 {
919 // Takes itself out of the list of handlers
920 if (m_previousHandler)
921 m_previousHandler->m_nextHandler = m_nextHandler;
922
923 if (m_nextHandler)
924 m_nextHandler->m_previousHandler = m_previousHandler;
925
926 if (m_dynamicEvents)
927 {
928 wxList::iterator it = m_dynamicEvents->begin(),
929 en = m_dynamicEvents->end();
930 for (;it != en; ++it)
931 {
932 #if WXWIN_COMPATIBILITY_EVENT_TYPES
933 wxEventTableEntry *entry = (wxEventTableEntry*)*it;
934 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
935 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)*it;
936 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
937
938 if (entry->m_callbackUserData)
939 delete entry->m_callbackUserData;
940 delete entry;
941 }
942 delete m_dynamicEvents;
943 };
944
945 delete m_pendingEvents;
946
947 #if wxUSE_THREADS
948 # if !defined(__VISAGECPP__)
949 delete m_eventsLocker;
950 # endif
951
952 // Remove us from wxPendingEvents if necessary.
953 if(wxPendingEventsLocker)
954 wxENTER_CRIT_SECT(*wxPendingEventsLocker);
955 if ( wxPendingEvents ) {
956 wxPendingEvents->DeleteObject(this);
957 }
958 if(wxPendingEventsLocker)
959 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker);
960 #endif
961
962 // we only delete object data, not untyped
963 if ( m_clientDataType == wxClientData_Object )
964 delete m_clientObject;
965 }
966
967 #if wxUSE_THREADS
968
969 bool wxEvtHandler::ProcessThreadEvent(wxEvent& event)
970 {
971 // check that we are really in a child thread
972 wxASSERT_MSG( !wxThread::IsMain(),
973 wxT("use ProcessEvent() in main thread") );
974
975 AddPendingEvent(event);
976
977 return TRUE;
978 }
979
980 #endif // wxUSE_THREADS
981
982 void wxEvtHandler::AddPendingEvent(wxEvent& event)
983 {
984 // 1) Add event to list of pending events of this event handler
985
986 wxEvent *eventCopy = event.Clone();
987
988 // we must be able to copy the events here so the event class must
989 // implement Clone() properly instead of just providing a NULL stab for it
990 wxCHECK_RET( eventCopy,
991 _T("events of this type aren't supposed to be posted") );
992
993 #if defined(__VISAGECPP__)
994 wxENTER_CRIT_SECT( m_eventsLocker);
995 #else
996 wxENTER_CRIT_SECT( *m_eventsLocker);
997 #endif
998
999 if ( !m_pendingEvents )
1000 m_pendingEvents = new wxList;
1001
1002 m_pendingEvents->Append(eventCopy);
1003
1004 #if defined(__VISAGECPP__)
1005 wxLEAVE_CRIT_SECT( m_eventsLocker);
1006 #else
1007 wxLEAVE_CRIT_SECT( *m_eventsLocker);
1008 #endif
1009
1010 // 2) Add this event handler to list of event handlers that
1011 // have pending events.
1012
1013 wxENTER_CRIT_SECT(*wxPendingEventsLocker);
1014
1015 if ( !wxPendingEvents )
1016 wxPendingEvents = new wxList;
1017 wxPendingEvents->Append(this);
1018
1019 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker);
1020
1021 // 3) Inform the system that new pending events are somwehere,
1022 // and that these should be processed in idle time.
1023 wxWakeUpIdle();
1024 }
1025
1026 void wxEvtHandler::ProcessPendingEvents()
1027 {
1028 #if defined(__VISAGECPP__)
1029 wxENTER_CRIT_SECT( m_eventsLocker);
1030 #else
1031 wxENTER_CRIT_SECT( *m_eventsLocker);
1032 #endif
1033
1034 wxList::compatibility_iterator node = m_pendingEvents->GetFirst();
1035 while ( node )
1036 {
1037 wxEvent *event = (wxEvent *)node->GetData();
1038 m_pendingEvents->Erase(node);
1039
1040 // In ProcessEvent, new events might get added and
1041 // we can safely leave the crtical section here.
1042 #if defined(__VISAGECPP__)
1043 wxLEAVE_CRIT_SECT( m_eventsLocker);
1044 #else
1045 wxLEAVE_CRIT_SECT( *m_eventsLocker);
1046 #endif
1047 ProcessEvent(*event);
1048 delete event;
1049 #if defined(__VISAGECPP__)
1050 wxENTER_CRIT_SECT( m_eventsLocker);
1051 #else
1052 wxENTER_CRIT_SECT( *m_eventsLocker);
1053 #endif
1054
1055 node = m_pendingEvents->GetFirst();
1056 }
1057
1058 #if defined(__VISAGECPP__)
1059 wxLEAVE_CRIT_SECT( m_eventsLocker);
1060 #else
1061 wxLEAVE_CRIT_SECT( *m_eventsLocker);
1062 #endif
1063 }
1064
1065 /*
1066 * Event table stuff
1067 */
1068
1069 bool wxEvtHandler::TryParent(wxEvent& event)
1070 {
1071 if ( wxTheApp && (this != wxTheApp) )
1072 {
1073 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1074 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1075 // processed appropriately via SearchEventTable.
1076 if ( event.GetEventType() != wxEVT_IDLE )
1077 {
1078 if ( wxTheApp->ProcessEvent(event) )
1079 return TRUE;
1080 }
1081 }
1082
1083 return FALSE;
1084 }
1085
1086 bool wxEvtHandler::ProcessEvent(wxEvent& event)
1087 {
1088 // allow the application to hook into event processing
1089 if ( wxTheApp )
1090 {
1091 int rc = wxTheApp->FilterEvent(event);
1092 if ( rc != -1 )
1093 {
1094 wxASSERT_MSG( rc == 1 || rc == 0,
1095 _T("unexpected wxApp::FilterEvent return value") );
1096
1097 return rc != 0;
1098 }
1099 //else: proceed normally
1100 }
1101
1102 // An event handler can be enabled or disabled
1103 if ( GetEvtHandlerEnabled() )
1104 {
1105 // if we have a validator, it has higher priority than our own event
1106 // table
1107 if ( TryValidator(event) )
1108 return TRUE;
1109
1110 // Handle per-instance dynamic event tables first
1111 if ( m_dynamicEvents && SearchDynamicEventTable(event) )
1112 return TRUE;
1113
1114 // Then static per-class event tables
1115 if ( GetEventHashTable().HandleEvent(event, this) )
1116 return TRUE;
1117 }
1118
1119 // Try going down the event handler chain
1120 if ( GetNextHandler() )
1121 {
1122 if ( GetNextHandler()->ProcessEvent(event) )
1123 return TRUE;
1124 }
1125
1126 // Finally propagate the event upwards the window chain and/or to the
1127 // application object as necessary
1128 return TryParent(event);
1129 }
1130
1131
1132 bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
1133 {
1134 wxEventType eventType = event.GetEventType();
1135 int eventId = event.GetId();
1136
1137 // BC++ doesn't like testing for m_fn without != 0
1138 for ( int i = 0; table.entries[i].m_fn != 0; i++ )
1139 {
1140 // the line using reference exposes a bug in gcc: although it _seems_
1141 // to work, it leads to weird crashes later on during program
1142 // execution
1143 #ifdef __GNUG__
1144 wxEventTableEntry entry = table.entries[i];
1145 #else
1146 const wxEventTableEntry& entry = table.entries[i];
1147 #endif
1148
1149 // match only if the event type is the same and the id is either -1 in
1150 // the event table (meaning "any") or the event id matches the id
1151 // specified in the event table either exactly or by falling into
1152 // range between first and last
1153 if ( eventType == entry.m_eventType )
1154 {
1155 int tableId1 = entry.m_id,
1156 tableId2 = entry.m_lastId;
1157
1158 if ( (tableId1 == -1) ||
1159 (tableId2 == -1 && eventId == tableId1) ||
1160 (tableId2 != -1 &&
1161 (eventId >= tableId1 && eventId <= tableId2)) )
1162 {
1163 event.Skip(FALSE);
1164 event.m_callbackUserData = entry.m_callbackUserData;
1165
1166 (this->*((wxEventFunction) (entry.m_fn)))(event);
1167
1168 return !event.GetSkipped();
1169 }
1170 }
1171 }
1172
1173 return FALSE;
1174 }
1175
1176 void wxEvtHandler::Connect( int id, int lastId,
1177 int eventType,
1178 wxObjectEventFunction func,
1179 wxObject *userData,
1180 wxEvtHandler* eventSink )
1181 {
1182 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1183 wxEventTableEntry *entry = new wxEventTableEntry;
1184 entry->m_eventType = eventType;
1185 entry->m_id = id;
1186 entry->m_lastId = lastId;
1187 entry->m_fn = func;
1188 entry->m_callbackUserData = userData;
1189 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1190 wxDynamicEventTableEntry *entry =
1191 new wxDynamicEventTableEntry(eventType, id, lastId, func, userData, eventSink);
1192 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1193
1194 if (!m_dynamicEvents)
1195 m_dynamicEvents = new wxList;
1196
1197 // Insert at the front of the list so most recent additions are found first
1198 m_dynamicEvents->Insert( (wxObject*) entry );
1199 }
1200
1201 bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType,
1202 wxObjectEventFunction func,
1203 wxObject *userData,
1204 wxEvtHandler* eventSink )
1205 {
1206 if (!m_dynamicEvents)
1207 return FALSE;
1208
1209 wxList::compatibility_iterator node = m_dynamicEvents->GetFirst();
1210 while (node)
1211 {
1212 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1213 wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData();
1214 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1215 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
1216 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1217
1218 if ((entry->m_id == id) &&
1219 ((entry->m_lastId == lastId) || (lastId == -1)) &&
1220 ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) &&
1221 ((entry->m_fn == func) || (func == (wxObjectEventFunction)NULL)) &&
1222 ((entry->m_eventSink == eventSink) || (eventSink == (wxEvtHandler*)NULL)) &&
1223 ((entry->m_callbackUserData == userData) || (userData == (wxObject*)NULL)))
1224 {
1225 if (entry->m_callbackUserData)
1226 delete entry->m_callbackUserData;
1227 m_dynamicEvents->Erase( node );
1228 delete entry;
1229 return TRUE;
1230 }
1231 node = node->GetNext();
1232 }
1233 return FALSE;
1234 }
1235
1236 bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
1237 {
1238 wxCHECK_MSG( m_dynamicEvents, FALSE,
1239 wxT("caller should check that we have dynamic events") );
1240
1241 int commandId = event.GetId();
1242
1243 wxList::compatibility_iterator node = m_dynamicEvents->GetFirst();
1244 while (node)
1245 {
1246 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1247 wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData();
1248 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1249 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
1250 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1251
1252 if (entry->m_fn)
1253 {
1254 // Match, if event spec says any id will do (id == -1)
1255 if ( (event.GetEventType() == entry->m_eventType) &&
1256 (entry->m_id == -1 ||
1257 (entry->m_lastId == -1 && commandId == entry->m_id) ||
1258 (entry->m_lastId != -1 &&
1259 (commandId >= entry->m_id && commandId <= entry->m_lastId))) )
1260 {
1261 event.Skip(FALSE);
1262 event.m_callbackUserData = entry->m_callbackUserData;
1263
1264 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
1265 if (entry->m_eventSink)
1266 ((entry->m_eventSink)->*((wxEventFunction) (entry->m_fn)))(event);
1267 else
1268 #endif
1269 (this->*((wxEventFunction) (entry->m_fn)))(event);
1270
1271 if ( ! event.GetSkipped() )
1272 return TRUE;
1273 }
1274 }
1275 node = node->GetNext();
1276 }
1277 return FALSE;
1278 };
1279
1280 void wxEvtHandler::DoSetClientObject( wxClientData *data )
1281 {
1282 wxASSERT_MSG( m_clientDataType != wxClientData_Void,
1283 wxT("can't have both object and void client data") );
1284
1285 if ( m_clientObject )
1286 delete m_clientObject;
1287
1288 m_clientObject = data;
1289 m_clientDataType = wxClientData_Object;
1290 }
1291
1292 wxClientData *wxEvtHandler::DoGetClientObject() const
1293 {
1294 // it's not an error to call GetClientObject() on a window which doesn't
1295 // have client data at all - NULL will be returned
1296 wxASSERT_MSG( m_clientDataType != wxClientData_Void,
1297 wxT("this window doesn't have object client data") );
1298
1299 return m_clientObject;
1300 }
1301
1302 void wxEvtHandler::DoSetClientData( void *data )
1303 {
1304 wxASSERT_MSG( m_clientDataType != wxClientData_Object,
1305 wxT("can't have both object and void client data") );
1306
1307 m_clientData = data;
1308 m_clientDataType = wxClientData_Void;
1309 }
1310
1311 void *wxEvtHandler::DoGetClientData() const
1312 {
1313 // it's not an error to call GetClientData() on a window which doesn't have
1314 // client data at all - NULL will be returned
1315 wxASSERT_MSG( m_clientDataType != wxClientData_Object,
1316 wxT("this window doesn't have void client data") );
1317
1318 return m_clientData;
1319 }
1320
1321 #endif // wxUSE_BASE
1322
1323 #if wxUSE_GUI
1324
1325 // Find a window with the focus, that is also a descendant of the given window.
1326 // This is used to determine the window to initially send commands to.
1327 wxWindow* wxFindFocusDescendant(wxWindow* ancestor)
1328 {
1329 // Process events starting with the window with the focus, if any.
1330 wxWindow* focusWin = wxWindow::FindFocus();
1331 wxWindow* win = focusWin;
1332
1333 // Check if this is a descendant of this frame.
1334 // If not, win will be set to NULL.
1335 while (win)
1336 {
1337 if (win == ancestor)
1338 break;
1339 else
1340 win = win->GetParent();
1341 }
1342 if (win == (wxWindow*) NULL)
1343 focusWin = (wxWindow*) NULL;
1344
1345 return focusWin;
1346 }
1347
1348 #endif // wxUSE_GUI