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