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