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