]> git.saurik.com Git - wxWidgets.git/blame - src/common/event.cpp
Applied patch [ 733425 ] Fix for header rendering problem in CalCtrl
[wxWidgets.git] / src / common / event.cpp
CommitLineData
c801d85f
KB
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$
55d99c7a 8// Copyright: (c) Julian Smart
e90c1d2a 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
8e193f38
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
c801d85f 20#ifdef __GNUG__
0b746ba8 21 #pragma implementation "event.h"
c801d85f
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
0b746ba8 28 #pragma hdrstop
c801d85f
KB
29#endif
30
31#ifndef WX_PRECOMP
0b746ba8 32 #include "wx/defs.h"
0b746ba8 33 #include "wx/app.h"
e90c1d2a
VZ
34 #include "wx/list.h"
35
36 #if wxUSE_GUI
37 #include "wx/control.h"
38 #include "wx/utils.h"
39 #include "wx/dc.h"
40 #endif // wxUSE_GUI
c801d85f
KB
41#endif
42
43#include "wx/event.h"
e90c1d2a
VZ
44
45#if wxUSE_GUI
46 #include "wx/validate.h"
47#endif // wxUSE_GUI
c801d85f 48
8e193f38
VZ
49// ----------------------------------------------------------------------------
50// wxWin macros
51// ----------------------------------------------------------------------------
52
23f681ec
VZ
53IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject)
54IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject)
e90c1d2a 55
23f681ec 56#if wxUSE_GUI
6b55490a 57 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent)
23f681ec
VZ
58 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent)
59 IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent)
60 IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent)
61 IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent, wxEvent)
62 IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent)
63 IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent)
64 IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent)
65 IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent)
1e6feb95 66 IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent, wxEvent)
23f681ec
VZ
67 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent)
68 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent)
69 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent)
456bc6d9 70 IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent, wxCommandEvent)
23f681ec
VZ
71 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent)
72 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent)
73 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent)
74 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent)
75 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent)
76 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent)
77 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent)
78 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent)
79 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent)
8e72b8b5 80 IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent, wxEvent)
23f681ec 81 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent)
574c939e 82 IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent, wxEvent)
23f681ec
VZ
83 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent)
84 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxCommandEvent)
85 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, wxEvent)
86 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent, wxEvent)
87 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent, wxEvent)
88 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent, wxEvent)
b96340e6 89 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent, wxCommandEvent)
69231000 90 IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent, wxCommandEvent)
a5e84126 91 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent, wxEvent)
23f681ec 92#endif // wxUSE_GUI
0b746ba8 93
23f681ec
VZ
94const wxEventTable *wxEvtHandler::GetEventTable() const
95 { return &wxEvtHandler::sm_eventTable; }
0b746ba8 96
23f681ec
VZ
97const wxEventTable wxEvtHandler::sm_eventTable =
98 { (const wxEventTable *)NULL, &wxEvtHandler::sm_eventTableEntries[0] };
0b746ba8 99
23f681ec 100const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] =
9aaf9bed 101 { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL, 0, 0, (wxObjectEventFunction)NULL, NULL) };
c801d85f 102
8e193f38
VZ
103// ----------------------------------------------------------------------------
104// global variables
105// ----------------------------------------------------------------------------
106
107// To put pending event handlers
108wxList *wxPendingEvents = (wxList *)NULL;
109
7214297d 110#if wxUSE_THREADS
8e193f38
VZ
111 // protects wxPendingEvents list
112 wxCriticalSection *wxPendingEventsLocker = (wxCriticalSection *)NULL;
7214297d
GL
113#endif
114
cbee8f8d
VZ
115#if !WXWIN_COMPATIBILITY_EVENT_TYPES
116
2e4df4bf
VZ
117// common event types are defined here, other event types are defined by the
118// components which use them
119
461697c2 120DEFINE_EVENT_TYPE(wxEVT_NULL)
2e4df4bf
VZ
121DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED)
122DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED)
123DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED)
124DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED)
125DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED)
126DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED)
2e4df4bf
VZ
127DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED)
128DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED)
129DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED)
130DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED)
131DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED)
132DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED)
133DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED)
134DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED)
135DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER)
136DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED)
0b5eceb6
VZ
137
138// Sockets and timers send events, too
2e4df4bf
VZ
139DEFINE_EVENT_TYPE(wxEVT_SOCKET)
140DEFINE_EVENT_TYPE(wxEVT_TIMER)
0b5eceb6
VZ
141
142// Mouse event types
2e4df4bf
VZ
143DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN)
144DEFINE_EVENT_TYPE(wxEVT_LEFT_UP)
145DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN)
146DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP)
147DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN)
148DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP)
149DEFINE_EVENT_TYPE(wxEVT_MOTION)
150DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW)
151DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW)
152DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK)
153DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK)
154DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK)
155DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS)
156DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS)
456bc6d9 157DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS)
d2c52078 158DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL)
0b5eceb6
VZ
159
160// Non-client mouse events
2e4df4bf
VZ
161DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN)
162DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP)
163DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN)
164DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP)
165DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN)
166DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP)
167DEFINE_EVENT_TYPE(wxEVT_NC_MOTION)
168DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW)
169DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW)
170DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK)
171DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK)
172DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK)
0b5eceb6
VZ
173
174// Character input event type
2e4df4bf
VZ
175DEFINE_EVENT_TYPE(wxEVT_CHAR)
176DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK)
177DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY)
178DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN)
179DEFINE_EVENT_TYPE(wxEVT_KEY_UP)
0b5eceb6
VZ
180
181// Set cursor event
2e4df4bf 182DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR)
0b5eceb6
VZ
183
184// wxScrollbar and wxSlider event identifiers
2e4df4bf
VZ
185DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP)
186DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM)
187DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP)
188DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN)
189DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP)
190DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN)
191DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK)
192DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE)
e8b669d3 193DEFINE_EVENT_TYPE(wxEVT_SCROLL_ENDSCROLL)
0b5eceb6
VZ
194
195// Scroll events from wxWindow
2e4df4bf
VZ
196DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP)
197DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM)
198DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP)
199DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN)
200DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP)
201DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN)
202DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK)
203DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE)
0b5eceb6
VZ
204
205// System events
2e4df4bf
VZ
206DEFINE_EVENT_TYPE(wxEVT_SIZE)
207DEFINE_EVENT_TYPE(wxEVT_MOVE)
208DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW)
209DEFINE_EVENT_TYPE(wxEVT_END_SESSION)
210DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION)
211DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP)
212DEFINE_EVENT_TYPE(wxEVT_POWER)
213DEFINE_EVENT_TYPE(wxEVT_ACTIVATE)
214DEFINE_EVENT_TYPE(wxEVT_CREATE)
215DEFINE_EVENT_TYPE(wxEVT_DESTROY)
216DEFINE_EVENT_TYPE(wxEVT_SHOW)
217DEFINE_EVENT_TYPE(wxEVT_ICONIZE)
218DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE)
219DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED)
220DEFINE_EVENT_TYPE(wxEVT_PAINT)
221DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND)
222DEFINE_EVENT_TYPE(wxEVT_NC_PAINT)
223DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON)
ccef86c7
VZ
224DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN)
225DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE)
2e4df4bf 226DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT)
2e4df4bf
VZ
227DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU)
228DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED)
574c939e 229DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED)
2e4df4bf
VZ
230DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED)
231DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE)
232DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED)
233DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN)
234DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP)
235DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE)
236DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE)
237DEFINE_EVENT_TYPE(wxEVT_DROP_FILES)
238DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM)
239DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM)
240DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM)
241DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG)
242DEFINE_EVENT_TYPE(wxEVT_IDLE)
243DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI)
0b5eceb6
VZ
244
245// Generic command events
246// Note: a click is a higher-level event than button down/up
2e4df4bf
VZ
247DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK)
248DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK)
249DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK)
250DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK)
251DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS)
252DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS)
253DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER)
0b5eceb6
VZ
254
255// Help events
2e4df4bf
VZ
256DEFINE_EVENT_TYPE(wxEVT_HELP)
257DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP)
6164f93c
VZ
258
259#endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
260
261// ============================================================================
262// implementation
263// ============================================================================
0b5eceb6 264
0b5eceb6
VZ
265// ----------------------------------------------------------------------------
266// event initialization
267// ----------------------------------------------------------------------------
268
269int wxNewEventType()
270{
271 // MT-FIXME
272 static int s_lastUsedEventType = wxEVT_FIRST;
273
cbee8f8d
VZ
274#if WXWIN_COMPATIBILITY_2
275 // check that we don't overlap with the user-defined types: if it does
276 // happen, the best solution is probably to update the existing code to
277 // use wxNewEventType() instead of wxEVT_USER_FIRST
6164f93c
VZ
278 //
279 // due to the uncertainty
cbee8f8d
VZ
280 wxASSERT_MSG( s_lastUsedEventType < wxEVT_USER_FIRST - 1,
281 _T("possible event type conflict") );
282#endif // WXWIN_COMPATIBILITY_2
283
0b5eceb6
VZ
284 return s_lastUsedEventType++;
285}
286
8e193f38
VZ
287// ----------------------------------------------------------------------------
288// wxEvent
289// ----------------------------------------------------------------------------
290
c801d85f
KB
291/*
292 * General wxWindows events, covering
293 * all interesting things that might happen (button clicking, resizing,
294 * setting text in widgets, etc.).
295 *
296 * For each completely new event type, derive a new event class.
297 *
298 */
299
8e72b8b5 300wxEvent::wxEvent(int theId, wxEventType commandType )
c801d85f 301{
8e72b8b5 302 m_eventType = commandType;
0b746ba8 303 m_eventObject = (wxObject *) NULL;
0b746ba8
VZ
304 m_timeStamp = 0;
305 m_id = theId;
306 m_skipped = FALSE;
307 m_callbackUserData = (wxObject *) NULL;
193bf013 308 m_isCommandEvent = FALSE;
c801d85f
KB
309}
310
8e72b8b5 311wxEvent::wxEvent(const wxEvent &src)
e6a6feba
GD
312 : wxObject()
313 , m_eventObject(src.m_eventObject)
314 , m_eventType(src.m_eventType)
315 , m_timeStamp(src.m_timeStamp)
316 , m_id(src.m_id)
317 , m_callbackUserData(src.m_callbackUserData)
318 , m_skipped(src.m_skipped)
319 , m_isCommandEvent(src.m_isCommandEvent)
a737331d 320{
a737331d
GL
321}
322
e90c1d2a
VZ
323#if wxUSE_GUI
324
c801d85f
KB
325/*
326 * Command events
327 *
328 */
329
7798a18e 330wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId)
e6a6feba 331 : wxEvent(theId, commandType)
c801d85f 332{
0b746ba8
VZ
333 m_clientData = (char *) NULL;
334 m_clientObject = (wxClientData *) NULL;
335 m_extraLong = 0;
336 m_commandInt = 0;
04392d70 337 m_commandString = wxEmptyString;
193bf013 338 m_isCommandEvent = TRUE;
c801d85f
KB
339}
340
341/*
342 * Scroll events
343 */
344
0b746ba8
VZ
345wxScrollEvent::wxScrollEvent(wxEventType commandType,
346 int id,
347 int pos,
348 int orient)
e6a6feba 349 : wxCommandEvent(commandType, id)
c801d85f 350{
0b746ba8
VZ
351 m_extraLong = orient;
352 m_commandInt = pos;
c801d85f
KB
353}
354
d1367c3d
RR
355/*
356 * ScrollWin events
357 */
358
359wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType,
360 int pos,
361 int orient)
d1367c3d 362{
c5b42c87 363 m_eventType = commandType;
d1367c3d
RR
364 m_extraLong = orient;
365 m_commandInt = pos;
366}
367
c801d85f
KB
368/*
369 * Mouse events
370 *
371 */
372
7798a18e 373wxMouseEvent::wxMouseEvent(wxEventType commandType)
c801d85f 374{
0b746ba8
VZ
375 m_eventType = commandType;
376 m_metaDown = FALSE;
377 m_altDown = FALSE;
378 m_controlDown = FALSE;
379 m_shiftDown = FALSE;
380 m_leftDown = FALSE;
381 m_rightDown = FALSE;
382 m_middleDown = FALSE;
383 m_x = 0;
384 m_y = 0;
d2c52078
RD
385 m_wheelRotation = 0;
386 m_wheelDelta = 0;
387 m_linesPerAction = 0;
c801d85f
KB
388}
389
abcbaea7
VZ
390void wxMouseEvent::Assign(const wxMouseEvent& event)
391{
9a1725c4 392 m_eventType = event.m_eventType;
92309201 393
abcbaea7
VZ
394 m_x = event.m_x;
395 m_y = event.m_y;
396
397 m_leftDown = event.m_leftDown;
398 m_middleDown = event.m_middleDown;
399 m_rightDown = event.m_rightDown;
400
401 m_controlDown = event.m_controlDown;
402 m_shiftDown = event.m_shiftDown;
403 m_altDown = event.m_altDown;
404 m_metaDown = event.m_metaDown;
405
406 m_wheelRotation = event.m_wheelRotation;
407 m_wheelDelta = event.m_wheelDelta;
408 m_linesPerAction = event.m_linesPerAction;
409}
410
c801d85f
KB
411// True if was a button dclick event (1 = left, 2 = middle, 3 = right)
412// or any button dclick event (but = -1)
413bool wxMouseEvent::ButtonDClick(int but) const
414{
0b746ba8
VZ
415 switch (but)
416 {
417 case -1:
418 return (LeftDClick() || MiddleDClick() || RightDClick());
419 case 1:
420 return LeftDClick();
421 case 2:
422 return MiddleDClick();
423 case 3:
424 return RightDClick();
425 default:
223d09f6 426 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
0b746ba8
VZ
427 }
428
429 return FALSE;
c801d85f
KB
430}
431
432// True if was a button down event (1 = left, 2 = middle, 3 = right)
433// or any button down event (but = -1)
434bool wxMouseEvent::ButtonDown(int but) const
435{
0b746ba8
VZ
436 switch (but)
437 {
438 case -1:
439 return (LeftDown() || MiddleDown() || RightDown());
440 case 1:
441 return LeftDown();
442 case 2:
443 return MiddleDown();
444 case 3:
445 return RightDown();
446 default:
223d09f6 447 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
0b746ba8
VZ
448 }
449
450 return FALSE;
c801d85f
KB
451}
452
453// True if was a button up event (1 = left, 2 = middle, 3 = right)
454// or any button up event (but = -1)
455bool wxMouseEvent::ButtonUp(int but) const
456{
1e6feb95
VZ
457 switch (but)
458 {
0b746ba8
VZ
459 case -1:
460 return (LeftUp() || MiddleUp() || RightUp());
461 case 1:
462 return LeftUp();
463 case 2:
464 return MiddleUp();
465 case 3:
466 return RightUp();
467 default:
223d09f6 468 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
0b746ba8
VZ
469 }
470
471 return FALSE;
c801d85f
KB
472}
473
474// True if the given button is currently changing state
475bool wxMouseEvent::Button(int but) const
476{
1e6feb95
VZ
477 switch (but)
478 {
0b746ba8 479 case -1:
72cdf4c9 480 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
0b746ba8
VZ
481 case 1:
482 return (LeftDown() || LeftUp() || LeftDClick());
483 case 2:
484 return (MiddleDown() || MiddleUp() || MiddleDClick());
485 case 3:
486 return (RightDown() || RightUp() || RightDClick());
487 default:
223d09f6 488 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
0b746ba8
VZ
489 }
490
491 return FALSE;
c801d85f
KB
492}
493
494bool wxMouseEvent::ButtonIsDown(int but) const
495{
1e6feb95
VZ
496 switch (but)
497 {
0b746ba8
VZ
498 case -1:
499 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
500 case 1:
501 return LeftIsDown();
502 case 2:
503 return MiddleIsDown();
504 case 3:
505 return RightIsDown();
506 default:
223d09f6 507 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
0b746ba8
VZ
508 }
509
510 return FALSE;
c801d85f
KB
511}
512
1e6feb95
VZ
513int wxMouseEvent::GetButton() const
514{
515 for ( int i = 1; i <= 3; i++ )
516 {
517 if ( Button(i) )
518 {
519 return i;
520 }
521 }
522
523 return -1;
524}
525
c801d85f
KB
526// Find the logical position of the event given the DC
527wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const
528{
0757d27c
JS
529 wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y));
530 return pt;
c801d85f
KB
531}
532
533
534/*
8e72b8b5 535 * Keyboard event
c801d85f
KB
536 *
537 */
538
7798a18e 539wxKeyEvent::wxKeyEvent(wxEventType type)
c801d85f 540{
0b746ba8
VZ
541 m_eventType = type;
542 m_shiftDown = FALSE;
543 m_controlDown = FALSE;
544 m_metaDown = FALSE;
545 m_altDown = FALSE;
546 m_keyCode = 0;
b0e813a0 547 m_scanCode = 0;
2b5f62a0
VZ
548#if wxUSE_UNICODE
549 m_uniChar = 0;
550#endif
c801d85f
KB
551}
552
92309201 553wxKeyEvent::wxKeyEvent(const wxKeyEvent& evt)
2b5f62a0
VZ
554 : wxEvent(evt)
555{
556 m_x = evt.m_x;
557 m_y = evt.m_y;
558
559 m_keyCode = evt.m_keyCode;
560
561 m_controlDown = evt.m_controlDown;
562 m_shiftDown = evt.m_shiftDown;
563 m_altDown = evt.m_altDown;
564 m_metaDown = evt.m_metaDown;
565 m_scanCode = evt.m_scanCode;
566 m_rawCode = evt.m_rawCode;
567 m_rawFlags = evt.m_rawFlags;
92309201 568
2b5f62a0
VZ
569#if wxUSE_UNICODE
570 m_uniChar = evt.m_uniChar;
571#endif
572}
12a3f227
RL
573
574long wxKeyEvent::KeyCode() const
575{
576 return m_keyCode;
577}
578
42e69d6b 579wxWindowCreateEvent::wxWindowCreateEvent(wxWindow *win)
42e69d6b 580{
cfe17b74 581 SetEventType(wxEVT_CREATE);
42e69d6b
VZ
582 SetEventObject(win);
583}
584
585wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow *win)
42e69d6b 586{
cfe17b74 587 SetEventType(wxEVT_DESTROY);
42e69d6b
VZ
588 SetEventObject(win);
589}
590
456bc6d9
VZ
591wxChildFocusEvent::wxChildFocusEvent(wxWindow *win)
592 : wxCommandEvent(wxEVT_CHILD_FOCUS)
593{
594 SetEventObject(win);
595}
596
dd070522
VZ
597#endif // wxUSE_GUI
598
456bc6d9
VZ
599// ----------------------------------------------------------------------------
600// wxEvtHandler
601// ----------------------------------------------------------------------------
602
c801d85f
KB
603/*
604 * Event handler
605 */
606
0b746ba8 607wxEvtHandler::wxEvtHandler()
c801d85f 608{
0b746ba8
VZ
609 m_nextHandler = (wxEvtHandler *) NULL;
610 m_previousHandler = (wxEvtHandler *) NULL;
611 m_enabled = TRUE;
612 m_dynamicEvents = (wxList *) NULL;
193bf013 613 m_isWindow = FALSE;
8e193f38 614 m_pendingEvents = (wxList *) NULL;
7214297d 615#if wxUSE_THREADS
41404da7 616# if !defined(__VISAGECPP__)
8e193f38 617 m_eventsLocker = new wxCriticalSection;
41404da7 618# endif
7214297d 619#endif
b88c44e7
RD
620 // no client data (yet)
621 m_clientData = NULL;
622 m_clientDataType = wxClientData_None;
c801d85f
KB
623}
624
0b746ba8 625wxEvtHandler::~wxEvtHandler()
c801d85f 626{
0b746ba8
VZ
627 // Takes itself out of the list of handlers
628 if (m_previousHandler)
629 m_previousHandler->m_nextHandler = m_nextHandler;
630
631 if (m_nextHandler)
632 m_nextHandler->m_previousHandler = m_previousHandler;
633
634 if (m_dynamicEvents)
fe71f65c 635 {
b1d4dd7a 636 wxNode *node = m_dynamicEvents->GetFirst();
0b746ba8
VZ
637 while (node)
638 {
2e4df4bf 639#if WXWIN_COMPATIBILITY_EVENT_TYPES
b1d4dd7a 640 wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData();
2e4df4bf 641#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
b1d4dd7a 642 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
2e4df4bf
VZ
643#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
644
645 if (entry->m_callbackUserData)
646 delete entry->m_callbackUserData;
0b746ba8 647 delete entry;
b1d4dd7a 648 node = node->GetNext();
0b746ba8
VZ
649 }
650 delete m_dynamicEvents;
651 };
7214297d 652
8e193f38 653 delete m_pendingEvents;
7214297d 654
8e193f38 655#if wxUSE_THREADS
41404da7 656# if !defined(__VISAGECPP__)
7214297d 657 delete m_eventsLocker;
41404da7 658# endif
083f7497
JS
659
660 // Remove us from wxPendingEvents if necessary.
661 if(wxPendingEventsLocker)
662 wxENTER_CRIT_SECT(*wxPendingEventsLocker);
663 if ( wxPendingEvents ) {
664 wxPendingEvents->DeleteObject(this);
665 }
666 if(wxPendingEventsLocker)
667 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker);
7214297d 668#endif
b88c44e7
RD
669
670 // we only delete object data, not untyped
671 if ( m_clientDataType == wxClientData_Object )
672 delete m_clientObject;
c801d85f
KB
673}
674
7214297d 675#if wxUSE_THREADS
aadbdf11 676
7214297d
GL
677bool wxEvtHandler::ProcessThreadEvent(wxEvent& event)
678{
7214297d 679 // check that we are really in a child thread
8e193f38
VZ
680 wxASSERT_MSG( !wxThread::IsMain(),
681 wxT("use ProcessEvent() in main thread") );
682
683 AddPendingEvent(event);
7214297d 684
8e193f38
VZ
685 return TRUE;
686}
687
688#endif // wxUSE_THREADS
689
690void wxEvtHandler::AddPendingEvent(wxEvent& event)
691{
16c1f79c
RR
692 // 1) Add event to list of pending events of this event handler
693
7a5c8ac4
VZ
694 wxEvent *eventCopy = event.Clone();
695
696 // we must be able to copy the events here so the event class must
697 // implement Clone() properly instead of just providing a NULL stab for it
698 wxCHECK_RET( eventCopy,
699 _T("events of this type aren't supposed to be posted") );
700
16c1f79c
RR
701#if defined(__VISAGECPP__)
702 wxENTER_CRIT_SECT( m_eventsLocker);
703#else
704 wxENTER_CRIT_SECT( *m_eventsLocker);
705#endif
706
8e193f38
VZ
707 if ( !m_pendingEvents )
708 m_pendingEvents = new wxList;
7214297d 709
7a5c8ac4 710 m_pendingEvents->Append(eventCopy);
7214297d 711
16c1f79c
RR
712#if defined(__VISAGECPP__)
713 wxLEAVE_CRIT_SECT( m_eventsLocker);
714#else
715 wxLEAVE_CRIT_SECT( *m_eventsLocker);
716#endif
717
718 // 2) Add this event handler to list of event handlers that
719 // have pending events.
cfe17b74 720
b568d04f 721 wxENTER_CRIT_SECT(*wxPendingEventsLocker);
72cdf4c9 722
8e193f38
VZ
723 if ( !wxPendingEvents )
724 wxPendingEvents = new wxList;
4d3a259a 725 wxPendingEvents->Append(this);
72cdf4c9 726
ce6d2511 727 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker);
6164f93c 728
16c1f79c
RR
729 // 3) Inform the system that new pending events are somwehere,
730 // and that these should be processed in idle time.
bf9e3e73 731 wxWakeUpIdle();
7214297d
GL
732}
733
734void wxEvtHandler::ProcessPendingEvents()
735{
41404da7 736#if defined(__VISAGECPP__)
16c1f79c 737 wxENTER_CRIT_SECT( m_eventsLocker);
b568d04f 738#else
16c1f79c 739 wxENTER_CRIT_SECT( *m_eventsLocker);
41404da7 740#endif
8e193f38 741
b1d4dd7a 742 wxNode *node = m_pendingEvents->GetFirst();
8e193f38
VZ
743 while ( node )
744 {
b1d4dd7a 745 wxEvent *event = (wxEvent *)node->GetData();
16c1f79c 746 delete node;
cfe17b74 747
16c1f79c 748 // In ProcessEvent, new events might get added and
6164f93c 749 // we can safely leave the crtical section here.
16c1f79c
RR
750#if defined(__VISAGECPP__)
751 wxLEAVE_CRIT_SECT( m_eventsLocker);
752#else
753 wxLEAVE_CRIT_SECT( *m_eventsLocker);
754#endif
8e193f38 755 ProcessEvent(*event);
9779893b 756 delete event;
16c1f79c
RR
757#if defined(__VISAGECPP__)
758 wxENTER_CRIT_SECT( m_eventsLocker);
759#else
760 wxENTER_CRIT_SECT( *m_eventsLocker);
761#endif
cfe17b74 762
b1d4dd7a 763 node = m_pendingEvents->GetFirst();
7214297d 764 }
cfe17b74 765
16c1f79c
RR
766#if defined(__VISAGECPP__)
767 wxLEAVE_CRIT_SECT( m_eventsLocker);
768#else
769 wxLEAVE_CRIT_SECT( *m_eventsLocker);
770#endif
7214297d 771}
7214297d 772
c801d85f
KB
773/*
774 * Event table stuff
775 */
776
777bool wxEvtHandler::ProcessEvent(wxEvent& event)
778{
e90c1d2a 779#if wxUSE_GUI
1a77875b 780
01f944e6
GD
781 // We have to use the actual window or processing events from
782 // wxWindowNative destructor won't work (we don't see the wxWindow class)
1a77875b 783#ifdef __WXDEBUG__
8e193f38 784 // check that our flag corresponds to reality
1a77875b
JS
785 wxClassInfo* info = NULL;
786#ifdef __WXUNIVERSAL__
787# if defined(__WXMSW__)
788 info = CLASSINFO(wxWindowMSW);
789# elif defined(__WXGTK__)
790 info = CLASSINFO(wxWindowGTK);
ea596687
JS
791# elif defined(__WXX11__)
792 info = CLASSINFO(wxWindowX11);
1a77875b
JS
793# elif defined(__WXMGL__)
794 info = CLASSINFO(wxWindowMGL);
19193a2c
KB
795# elif defined(__WXPM__)
796 info = CLASSINFO(wxWindowOS2);
1a77875b
JS
797# elif defined(__WXMAC__)
798 info = CLASSINFO(wxWindowMac);
799# elif defined(__WXMOTIF__)
800 info = CLASSINFO(wxWindowMotif);
801# endif
802#else
803 info = CLASSINFO(wxWindow);
804#endif
805
9154d8cf
VZ
806 if ( m_isWindow != IsKindOf(info) )
807 {
808 wxString msg = GetClassInfo()->GetClassName();
809 msg += _T(" should [not] be a window but it is [not]");
810
811 wxFAIL_MSG( msg );
812 }
813
814#endif // __WXDEBUG__
1a77875b 815
e90c1d2a 816#endif // wxUSE_GUI
0b746ba8 817
9154d8cf
VZ
818 // allow the application to hook into event processing
819 if ( wxTheApp )
820 {
821 int rc = wxTheApp->FilterEvent(event);
822 if ( rc != -1 )
823 {
824 wxASSERT_MSG( rc == 1 || rc == 0,
825 _T("unexpected wxApp::FilterEvent return value") );
826
827 return rc != 0;
828 }
829 //else: proceed normally
830 }
831
8e193f38 832 // An event handler can be enabled or disabled
0b746ba8 833 if ( GetEvtHandlerEnabled() )
c801d85f 834 {
6164f93c 835
924ef850
RR
836#if 0
837/*
838 What is this? When using GUI threads, a non main
839 threads can send an event and process it itself.
840 This breaks GTK's GUI threads, so please explain.
841*/
842
8e193f38
VZ
843 // Check whether we are in a child thread.
844 if ( !wxThread::IsMain() )
7214297d 845 return ProcessThreadEvent(event);
924ef850 846#endif
0757d27c 847
8e193f38 848 // Handle per-instance dynamic event tables first
193bf013 849 if ( m_dynamicEvents && SearchDynamicEventTable(event) )
0757d27c 850 return TRUE;
0b746ba8 851
8e193f38 852 // Then static per-class event tables
0b746ba8
VZ
853 const wxEventTable *table = GetEventTable();
854
e90c1d2a 855#if wxUSE_GUI && wxUSE_VALIDATORS
0b746ba8
VZ
856 // Try the associated validator first, if this is a window.
857 // Problem: if the event handler of the window has been replaced,
858 // this wxEvtHandler may no longer be a window.
859 // Therefore validators won't be processed if the handler
860 // has been replaced with SetEventHandler.
861 // THIS CAN BE CURED if PushEventHandler is used instead of
862 // SetEventHandler, and then processing will be passed down the
863 // chain of event handlers.
ce4169a4 864 if (m_isWindow)
0b746ba8
VZ
865 {
866 wxWindow *win = (wxWindow *)this;
867
868 // Can only use the validator of the window which
869 // is receiving the event
193bf013 870 if ( win == event.GetEventObject() )
0b746ba8 871 {
193bf013
VZ
872 wxValidator *validator = win->GetValidator();
873 if ( validator && validator->ProcessEvent(event) )
874 {
875 return TRUE;
876 }
0b746ba8
VZ
877 }
878 }
ce4169a4 879#endif
0b746ba8
VZ
880
881 // Search upwards through the inheritance hierarchy
ce4169a4 882 while (table)
0b746ba8 883 {
193bf013 884 if ( SearchEventTable((wxEventTable&)*table, event) )
0b746ba8
VZ
885 return TRUE;
886 table = table->baseTable;
887 }
c801d85f
KB
888 }
889
0b746ba8
VZ
890 // Try going down the event handler chain
891 if ( GetNextHandler() )
c801d85f 892 {
0b746ba8
VZ
893 if ( GetNextHandler()->ProcessEvent(event) )
894 return TRUE;
c801d85f 895 }
c801d85f 896
e90c1d2a 897#if wxUSE_GUI
3bdc265d
VZ
898 // Carry on up the parent-child hierarchy, but only if event is a command
899 // event: it wouldn't make sense for a parent to receive a child's size
900 // event, for example
193bf013 901 if ( m_isWindow && event.IsCommandEvent() )
0b746ba8
VZ
902 {
903 wxWindow *win = (wxWindow *)this;
3bdc265d 904
e4b713a2
VZ
905 // honour the requests to stop propagation at this window: this is
906 // used by the dialogs, for example, to prevent processing the events
907 // from the dialog controls in the parent frame which rarely, if ever,
908 // makes sense
909 if ( !(win->GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
3bdc265d
VZ
910 {
911 wxWindow *parent = win->GetParent();
e4b713a2 912 if ( parent && !parent->IsBeingDeleted() )
3bdc265d
VZ
913 return parent->GetEventHandler()->ProcessEvent(event);
914 }
0b746ba8 915 }
e90c1d2a 916#endif // wxUSE_GUI
0b746ba8
VZ
917
918 // Last try - application object.
193bf013 919 if ( wxTheApp && (this != wxTheApp) )
0b746ba8 920 {
193bf013
VZ
921 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
922 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
923 // processed appropriately via SearchEventTable.
924 if ( event.GetEventType() != wxEVT_IDLE )
925 {
926 if ( wxTheApp->ProcessEvent(event) )
927 return TRUE;
928 }
0b746ba8
VZ
929 }
930
c801d85f
KB
931 return FALSE;
932}
933
934bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
935{
68662769
VZ
936 wxEventType eventType = event.GetEventType();
937 int eventId = event.GetId();
0b746ba8 938
68662769
VZ
939 // BC++ doesn't like testing for m_fn without != 0
940 for ( int i = 0; table.entries[i].m_fn != 0; i++ )
c801d85f 941 {
6e58645e
VZ
942 // the line using reference exposes a bug in gcc: although it _seems_
943 // to work, it leads to weird crashes later on during program
944 // execution
945#ifdef __GNUG__
946 wxEventTableEntry entry = table.entries[i];
947#else
68662769 948 const wxEventTableEntry& entry = table.entries[i];
6e58645e 949#endif
68662769
VZ
950
951 // match only if the event type is the same and the id is either -1 in
952 // the event table (meaning "any") or the event id matches the id
953 // specified in the event table either exactly or by falling into
954 // range between first and last
955 if ( eventType == entry.m_eventType )
0b746ba8 956 {
68662769
VZ
957 int tableId1 = entry.m_id,
958 tableId2 = entry.m_lastId;
959
960 if ( (tableId1 == -1) ||
961 (tableId2 == -1 && eventId == tableId1) ||
962 (tableId2 != -1 &&
963 (eventId >= tableId1 && eventId <= tableId2)) )
964 {
965 event.Skip(FALSE);
966 event.m_callbackUserData = entry.m_callbackUserData;
0b746ba8 967
68662769 968 (this->*((wxEventFunction) (entry.m_fn)))(event);
0b746ba8 969
68662769
VZ
970 return !event.GetSkipped();
971 }
0b746ba8 972 }
c801d85f 973 }
68662769 974
0b746ba8 975 return FALSE;
c801d85f 976}
97d7bfb8 977
debe6624 978void wxEvtHandler::Connect( int id, int lastId,
77d4384e 979 int eventType,
0b746ba8
VZ
980 wxObjectEventFunction func,
981 wxObject *userData )
fe71f65c 982{
cbee8f8d 983#if WXWIN_COMPATIBILITY_EVENT_TYPES
2e4df4bf 984 wxEventTableEntry *entry = new wxEventTableEntry;
cbee8f8d
VZ
985 entry->m_eventType = eventType;
986 entry->m_id = id;
987 entry->m_lastId = lastId;
988 entry->m_fn = func;
989 entry->m_callbackUserData = userData;
990#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
0b5eceb6
VZ
991 wxDynamicEventTableEntry *entry =
992 new wxDynamicEventTableEntry(eventType, id, lastId, func, userData);
cbee8f8d 993#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
0b746ba8
VZ
994
995 if (!m_dynamicEvents)
996 m_dynamicEvents = new wxList;
997
92309201
RD
998 // Insert at the front of the list so most recent additions are found first
999 m_dynamicEvents->Insert( (wxObject*) entry );
fe71f65c 1000}
97d7bfb8
RR
1001
1002bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType,
1003 wxObjectEventFunction func,
1004 wxObject *userData )
1005{
1006 if (!m_dynamicEvents)
1007 return FALSE;
cfe17b74 1008
b1d4dd7a 1009 wxNode *node = m_dynamicEvents->GetFirst();
97d7bfb8
RR
1010 while (node)
1011 {
2e4df4bf 1012#if WXWIN_COMPATIBILITY_EVENT_TYPES
b1d4dd7a 1013 wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData();
2e4df4bf 1014#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
b1d4dd7a 1015 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
2e4df4bf
VZ
1016#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1017
97d7bfb8
RR
1018 if ((entry->m_id == id) &&
1019 ((entry->m_lastId == lastId) || (lastId == -1)) &&
1020 ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) &&
1021 ((entry->m_fn == func) || (func == (wxObjectEventFunction)NULL)) &&
1022 ((entry->m_callbackUserData == userData) || (userData == (wxObject*)NULL)))
1023 {
2e4df4bf
VZ
1024 if (entry->m_callbackUserData)
1025 delete entry->m_callbackUserData;
97d7bfb8
RR
1026 m_dynamicEvents->DeleteNode( node );
1027 delete entry;
1028 return TRUE;
1029 }
b1d4dd7a 1030 node = node->GetNext();
97d7bfb8
RR
1031 }
1032 return FALSE;
1033}
fe71f65c
RR
1034
1035bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
1036{
193bf013 1037 wxCHECK_MSG( m_dynamicEvents, FALSE,
223d09f6 1038 wxT("caller should check that we have dynamic events") );
0b746ba8
VZ
1039
1040 int commandId = event.GetId();
1041
b1d4dd7a 1042 wxNode *node = m_dynamicEvents->GetFirst();
0b746ba8 1043 while (node)
fe71f65c 1044 {
2e4df4bf 1045#if WXWIN_COMPATIBILITY_EVENT_TYPES
b1d4dd7a 1046 wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData();
2e4df4bf 1047#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
b1d4dd7a 1048 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
2e4df4bf 1049#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
0b746ba8
VZ
1050
1051 if (entry->m_fn)
1052 {
1053 // Match, if event spec says any id will do (id == -1)
1054 if ( (event.GetEventType() == entry->m_eventType) &&
1055 (entry->m_id == -1 ||
1056 (entry->m_lastId == -1 && commandId == entry->m_id) ||
1057 (entry->m_lastId != -1 &&
1058 (commandId >= entry->m_id && commandId <= entry->m_lastId))) )
1059 {
1060 event.Skip(FALSE);
1061 event.m_callbackUserData = entry->m_callbackUserData;
1062
1063 (this->*((wxEventFunction) (entry->m_fn)))(event);
1064
92309201 1065 if ( ! event.GetSkipped() )
0b746ba8
VZ
1066 return TRUE;
1067 }
1068 }
b1d4dd7a 1069 node = node->GetNext();
7b678698 1070 }
0b746ba8 1071 return FALSE;
fe71f65c
RR
1072};
1073
b88c44e7
RD
1074void wxEvtHandler::DoSetClientObject( wxClientData *data )
1075{
1076 wxASSERT_MSG( m_clientDataType != wxClientData_Void,
1077 wxT("can't have both object and void client data") );
1078
1079 if ( m_clientObject )
1080 delete m_clientObject;
1081
1082 m_clientObject = data;
1083 m_clientDataType = wxClientData_Object;
1084}
1085
1086wxClientData *wxEvtHandler::DoGetClientObject() const
1087{
1088 // it's not an error to call GetClientObject() on a window which doesn't
1089 // have client data at all - NULL will be returned
1090 wxASSERT_MSG( m_clientDataType != wxClientData_Void,
1091 wxT("this window doesn't have object client data") );
1092
1093 return m_clientObject;
1094}
1095
1096void wxEvtHandler::DoSetClientData( void *data )
1097{
1098 wxASSERT_MSG( m_clientDataType != wxClientData_Object,
1099 wxT("can't have both object and void client data") );
1100
1101 m_clientData = data;
1102 m_clientDataType = wxClientData_Void;
1103}
1104
1105void *wxEvtHandler::DoGetClientData() const
1106{
1107 // it's not an error to call GetClientData() on a window which doesn't have
1108 // client data at all - NULL will be returned
1109 wxASSERT_MSG( m_clientDataType != wxClientData_Object,
1110 wxT("this window doesn't have void client data") );
1111
1112 return m_clientData;
1113}
1114
1115
e3065973 1116#if WXWIN_COMPATIBILITY
0b746ba8 1117bool wxEvtHandler::OnClose()
c801d85f 1118{
0b746ba8
VZ
1119 if (GetNextHandler())
1120 return GetNextHandler()->OnClose();
1121 else
1122 return FALSE;
c801d85f 1123}
193bf013 1124#endif // WXWIN_COMPATIBILITY
e3065973 1125
e90c1d2a
VZ
1126#if wxUSE_GUI
1127
e702ff0f
JS
1128// Find a window with the focus, that is also a descendant of the given window.
1129// This is used to determine the window to initially send commands to.
1130wxWindow* wxFindFocusDescendant(wxWindow* ancestor)
1131{
1132 // Process events starting with the window with the focus, if any.
1133 wxWindow* focusWin = wxWindow::FindFocus();
1134 wxWindow* win = focusWin;
1135
1136 // Check if this is a descendant of this frame.
1137 // If not, win will be set to NULL.
1138 while (win)
1139 {
1140 if (win == ancestor)
1141 break;
1142 else
1143 win = win->GetParent();
1144 }
1145 if (win == (wxWindow*) NULL)
1146 focusWin = (wxWindow*) NULL;
1147
1148 return focusWin;
1149}
1150
e90c1d2a 1151#endif // wxUSE_GUI