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