]> git.saurik.com Git - wxWidgets.git/blame - src/common/event.cpp
missing headers for !USE_PCH compilation
[wxWidgets.git] / src / common / event.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: event.cpp
3// Purpose: Event classes
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
55d99c7a 8// Copyright: (c) Julian Smart
e90c1d2a 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
8e193f38
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
e4844687
SN
20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) && !defined(__EMX__)
21// Some older compilers (such as EMX) cannot handle
1c624631 22// #pragma interface/implementation correctly, iff
e4844687
SN
23// #pragma implementation is used in _two_ translation
24// units (as created by e.g. event.cpp compiled for
25// libwx_base and event.cpp compiled for libwx_gui_core).
26// So we must not use those pragmas for those compilers in
27// such files.
0b746ba8 28 #pragma implementation "event.h"
c801d85f
KB
29#endif
30
31// For compilers that support precompilation, includes "wx.h".
32#include "wx/wxprec.h"
33
34#ifdef __BORLANDC__
0b746ba8 35 #pragma hdrstop
c801d85f
KB
36#endif
37
38#ifndef WX_PRECOMP
0b746ba8 39 #include "wx/defs.h"
0b746ba8 40 #include "wx/app.h"
e90c1d2a
VZ
41 #include "wx/list.h"
42
43 #if wxUSE_GUI
44 #include "wx/control.h"
45 #include "wx/utils.h"
46 #include "wx/dc.h"
47 #endif // wxUSE_GUI
c801d85f
KB
48#endif
49
50#include "wx/event.h"
e90c1d2a
VZ
51
52#if wxUSE_GUI
53 #include "wx/validate.h"
0b30bb0b
JS
54#if wxUSE_STOPWATCH
55 #include "wx/stopwatch.h"
56#endif
e90c1d2a 57#endif // wxUSE_GUI
c801d85f 58
8e193f38
VZ
59// ----------------------------------------------------------------------------
60// wxWin macros
61// ----------------------------------------------------------------------------
62
3ed2104c
VZ
63#if wxUSE_BASE
64 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject)
65 IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject)
66#endif // wxUSE_BASE
e90c1d2a 67
23f681ec 68#if wxUSE_GUI
6b55490a 69 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent)
23f681ec
VZ
70 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent)
71 IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent)
72 IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent)
73 IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent, wxEvent)
74 IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent)
75 IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent)
76 IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent)
77 IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent)
1e6feb95 78 IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent, wxEvent)
23f681ec
VZ
79 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent)
80 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent)
81 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent)
456bc6d9 82 IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent, wxCommandEvent)
23f681ec
VZ
83 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent)
84 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent)
85 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent)
86 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent)
87 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent)
88 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent)
89 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent)
90 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent)
91 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent)
8e72b8b5 92 IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent, wxEvent)
23f681ec 93 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent)
574c939e 94 IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent, wxEvent)
23f681ec 95 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent)
75299490 96 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxEvent)
23f681ec
VZ
97 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, wxEvent)
98 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent, wxEvent)
99 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent, wxEvent)
100 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent, wxEvent)
b96340e6 101 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent, wxCommandEvent)
69231000 102 IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent, wxCommandEvent)
a5e84126 103 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent, wxEvent)
23f681ec 104#endif // wxUSE_GUI
0b746ba8 105
3ed2104c
VZ
106#if wxUSE_BASE
107
23f681ec
VZ
108const wxEventTable *wxEvtHandler::GetEventTable() const
109 { return &wxEvtHandler::sm_eventTable; }
0b746ba8 110
23f681ec
VZ
111const wxEventTable wxEvtHandler::sm_eventTable =
112 { (const wxEventTable *)NULL, &wxEvtHandler::sm_eventTableEntries[0] };
0b746ba8 113
b5a98acd
VZ
114wxEventHashTable &wxEvtHandler::GetEventHashTable() const
115 { return wxEvtHandler::sm_eventHashTable; }
116
117wxEventHashTable wxEvtHandler::sm_eventHashTable(wxEvtHandler::sm_eventTable);
118
23f681ec 119const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] =
9aaf9bed 120 { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL, 0, 0, (wxObjectEventFunction)NULL, NULL) };
c801d85f 121
8e193f38
VZ
122// ----------------------------------------------------------------------------
123// global variables
124// ----------------------------------------------------------------------------
125
126// To put pending event handlers
127wxList *wxPendingEvents = (wxList *)NULL;
128
7214297d 129#if wxUSE_THREADS
8e193f38
VZ
130 // protects wxPendingEvents list
131 wxCriticalSection *wxPendingEventsLocker = (wxCriticalSection *)NULL;
7214297d
GL
132#endif
133
cbee8f8d
VZ
134#if !WXWIN_COMPATIBILITY_EVENT_TYPES
135
2e4df4bf
VZ
136// common event types are defined here, other event types are defined by the
137// components which use them
b5a98acd 138
c15d9c85
VS
139const wxEventType wxEVT_FIRST = 10000;
140const wxEventType wxEVT_USER_FIRST = wxEVT_FIRST + 2000;
2e4df4bf 141
461697c2 142DEFINE_EVENT_TYPE(wxEVT_NULL)
886dd7d2
VZ
143DEFINE_EVENT_TYPE(wxEVT_IDLE)
144DEFINE_EVENT_TYPE(wxEVT_SOCKET)
145
146#endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
147
148#endif // wxUSE_BASE
149
150#if wxUSE_GUI
151
152#if !WXWIN_COMPATIBILITY_EVENT_TYPES
153
2e4df4bf
VZ
154DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED)
155DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED)
156DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED)
157DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED)
158DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED)
159DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED)
2e4df4bf
VZ
160DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED)
161DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED)
162DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED)
163DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED)
164DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED)
165DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED)
166DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED)
167DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED)
168DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER)
169DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED)
0b5eceb6
VZ
170
171// Sockets and timers send events, too
2e4df4bf 172DEFINE_EVENT_TYPE(wxEVT_TIMER)
0b5eceb6
VZ
173
174// Mouse event types
2e4df4bf
VZ
175DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN)
176DEFINE_EVENT_TYPE(wxEVT_LEFT_UP)
177DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN)
178DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP)
179DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN)
180DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP)
181DEFINE_EVENT_TYPE(wxEVT_MOTION)
182DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW)
183DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW)
184DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK)
185DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK)
186DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK)
187DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS)
188DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS)
456bc6d9 189DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS)
d2c52078 190DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL)
0b5eceb6
VZ
191
192// Non-client mouse events
2e4df4bf
VZ
193DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN)
194DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP)
195DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN)
196DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP)
197DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN)
198DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP)
199DEFINE_EVENT_TYPE(wxEVT_NC_MOTION)
200DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW)
201DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW)
202DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK)
203DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK)
204DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK)
0b5eceb6
VZ
205
206// Character input event type
2e4df4bf
VZ
207DEFINE_EVENT_TYPE(wxEVT_CHAR)
208DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK)
209DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY)
210DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN)
211DEFINE_EVENT_TYPE(wxEVT_KEY_UP)
5048c832
JS
212#if wxUSE_HOTKEY
213DEFINE_EVENT_TYPE(wxEVT_HOTKEY)
214#endif
0b5eceb6
VZ
215
216// Set cursor event
2e4df4bf 217DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR)
0b5eceb6
VZ
218
219// wxScrollbar and wxSlider event identifiers
2e4df4bf
VZ
220DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP)
221DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM)
222DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP)
223DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN)
224DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP)
225DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN)
226DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK)
227DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE)
e8b669d3 228DEFINE_EVENT_TYPE(wxEVT_SCROLL_ENDSCROLL)
0b5eceb6
VZ
229
230// Scroll events from wxWindow
2e4df4bf
VZ
231DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP)
232DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM)
233DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP)
234DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN)
235DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP)
236DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN)
237DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK)
238DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE)
0b5eceb6
VZ
239
240// System events
2e4df4bf 241DEFINE_EVENT_TYPE(wxEVT_SIZE)
5706de1c 242DEFINE_EVENT_TYPE(wxEVT_SIZING)
2e4df4bf 243DEFINE_EVENT_TYPE(wxEVT_MOVE)
5706de1c 244DEFINE_EVENT_TYPE(wxEVT_MOVING)
2e4df4bf
VZ
245DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW)
246DEFINE_EVENT_TYPE(wxEVT_END_SESSION)
247DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION)
248DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP)
249DEFINE_EVENT_TYPE(wxEVT_POWER)
250DEFINE_EVENT_TYPE(wxEVT_ACTIVATE)
251DEFINE_EVENT_TYPE(wxEVT_CREATE)
252DEFINE_EVENT_TYPE(wxEVT_DESTROY)
253DEFINE_EVENT_TYPE(wxEVT_SHOW)
254DEFINE_EVENT_TYPE(wxEVT_ICONIZE)
255DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE)
256DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED)
257DEFINE_EVENT_TYPE(wxEVT_PAINT)
258DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND)
259DEFINE_EVENT_TYPE(wxEVT_NC_PAINT)
260DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON)
ccef86c7
VZ
261DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN)
262DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE)
2e4df4bf 263DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT)
2e4df4bf
VZ
264DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU)
265DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED)
574c939e 266DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED)
2e4df4bf
VZ
267DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED)
268DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE)
269DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED)
270DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN)
271DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP)
272DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE)
273DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE)
274DEFINE_EVENT_TYPE(wxEVT_DROP_FILES)
275DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM)
276DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM)
277DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM)
278DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG)
2e4df4bf 279DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI)
0b5eceb6
VZ
280
281// Generic command events
282// Note: a click is a higher-level event than button down/up
2e4df4bf
VZ
283DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK)
284DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK)
285DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK)
286DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK)
287DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS)
288DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS)
289DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER)
0b5eceb6
VZ
290
291// Help events
2e4df4bf
VZ
292DEFINE_EVENT_TYPE(wxEVT_HELP)
293DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP)
6164f93c
VZ
294
295#endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
296
886dd7d2
VZ
297#endif // wxUSE_GUI
298
299#if wxUSE_BASE
300
6164f93c
VZ
301// ============================================================================
302// implementation
303// ============================================================================
0b5eceb6 304
0b5eceb6
VZ
305// ----------------------------------------------------------------------------
306// event initialization
307// ----------------------------------------------------------------------------
308
309int wxNewEventType()
310{
311 // MT-FIXME
312 static int s_lastUsedEventType = wxEVT_FIRST;
313
314 return s_lastUsedEventType++;
315}
316
8e193f38
VZ
317// ----------------------------------------------------------------------------
318// wxEvent
319// ----------------------------------------------------------------------------
320
c801d85f
KB
321/*
322 * General wxWindows events, covering
323 * all interesting things that might happen (button clicking, resizing,
324 * setting text in widgets, etc.).
325 *
326 * For each completely new event type, derive a new event class.
327 *
328 */
329
8e72b8b5 330wxEvent::wxEvent(int theId, wxEventType commandType )
c801d85f 331{
8e72b8b5 332 m_eventType = commandType;
0b746ba8 333 m_eventObject = (wxObject *) NULL;
0b746ba8
VZ
334 m_timeStamp = 0;
335 m_id = theId;
1c624631 336 m_skipped = false;
0b746ba8 337 m_callbackUserData = (wxObject *) NULL;
1c624631 338 m_isCommandEvent = false;
1648d51b 339 m_propagationLevel = wxEVENT_PROPAGATE_NONE;
c801d85f
KB
340}
341
8e72b8b5 342wxEvent::wxEvent(const wxEvent &src)
e6a6feba
GD
343 : wxObject()
344 , m_eventObject(src.m_eventObject)
345 , m_eventType(src.m_eventType)
346 , m_timeStamp(src.m_timeStamp)
347 , m_id(src.m_id)
348 , m_callbackUserData(src.m_callbackUserData)
6fd5903a 349 , m_propagationLevel(src.m_propagationLevel)
e6a6feba
GD
350 , m_skipped(src.m_skipped)
351 , m_isCommandEvent(src.m_isCommandEvent)
a737331d 352{
a737331d
GL
353}
354
3ed2104c
VZ
355#endif // wxUSE_BASE
356
e90c1d2a
VZ
357#if wxUSE_GUI
358
c801d85f
KB
359/*
360 * Command events
361 *
362 */
363
7798a18e 364wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId)
b5a98acd 365 : wxEvent(theId, commandType)
c801d85f 366{
0b746ba8
VZ
367 m_clientData = (char *) NULL;
368 m_clientObject = (wxClientData *) NULL;
369 m_extraLong = 0;
370 m_commandInt = 0;
1c624631 371 m_isCommandEvent = true;
1648d51b
VZ
372
373 // the command events are propagated upwards by default
374 m_propagationLevel = wxEVENT_PROPAGATE_MAX;
c801d85f
KB
375}
376
0b30bb0b
JS
377/*
378 * UI update events
379 */
380
381#if wxUSE_LONGLONG
e39af974 382wxLongLong wxUpdateUIEvent::sm_lastUpdate = 0;
0b30bb0b
JS
383#endif
384
e39af974
JS
385long wxUpdateUIEvent::sm_updateInterval = 0;
386
387wxUpdateUIMode wxUpdateUIEvent::sm_updateMode = wxUPDATE_UI_PROCESS_ALL;
0b30bb0b
JS
388
389// Can we update?
a7bc03c9 390bool wxUpdateUIEvent::CanUpdate(wxWindowBase *win)
0b30bb0b 391{
e39af974
JS
392 // Don't update if we've switched global updating off
393 // and this window doesn't support updates.
394 if (win &&
395 (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED &&
396 ((win->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES) == 0)))
1c624631 397 return false;
b5a98acd 398
e39af974 399 if (sm_updateInterval == -1)
1c624631 400 return false;
e39af974 401 else if (sm_updateInterval == 0)
1c624631 402 return true;
0b30bb0b
JS
403 else
404 {
405#if wxUSE_STOPWATCH && wxUSE_LONGLONG
406 wxLongLong now = wxGetLocalTimeMillis();
e39af974 407 if (now > (sm_lastUpdate + sm_updateInterval))
0b30bb0b 408 {
1c624631 409 return true;
0b30bb0b
JS
410 }
411#else
412 // If we don't have wxStopWatch or wxLongLong, we
b5a98acd 413 // should err on the safe side and update now anyway.
1c624631 414 return true;
0b30bb0b
JS
415#endif
416 }
1c624631 417 return false;
0b30bb0b
JS
418}
419
420// Reset the update time to provide a delay until the next
421// time we should update
422void wxUpdateUIEvent::ResetUpdateTime()
423{
424#if wxUSE_STOPWATCH && wxUSE_LONGLONG
e39af974 425 if (sm_updateInterval > 0)
0b30bb0b
JS
426 {
427 wxLongLong now = wxGetLocalTimeMillis();
e39af974 428 if (now > (sm_lastUpdate + sm_updateInterval))
0b30bb0b 429 {
e39af974 430 sm_lastUpdate = now;
0b30bb0b
JS
431 }
432 }
433#endif
434}
435
e39af974
JS
436/*
437 * Idle events
438 */
b5a98acd 439
e39af974
JS
440wxIdleMode wxIdleEvent::sm_idleMode = wxIDLE_PROCESS_ALL;
441
442// Can we send an idle event?
443bool wxIdleEvent::CanSend(wxWindow* win)
444{
445 // Don't update if we've switched global updating off
446 // and this window doesn't support updates.
447 if (win &&
448 (GetMode() == wxIDLE_PROCESS_SPECIFIED &&
449 ((win->GetExtraStyle() & wxWS_EX_PROCESS_IDLE) == 0)))
1c624631 450 return false;
b5a98acd 451
1c624631 452 return true;
e39af974 453}
0b30bb0b 454
c801d85f
KB
455/*
456 * Scroll events
457 */
458
0b746ba8
VZ
459wxScrollEvent::wxScrollEvent(wxEventType commandType,
460 int id,
461 int pos,
462 int orient)
e6a6feba 463 : wxCommandEvent(commandType, id)
c801d85f 464{
0b746ba8
VZ
465 m_extraLong = orient;
466 m_commandInt = pos;
c801d85f
KB
467}
468
d1367c3d
RR
469/*
470 * ScrollWin events
471 */
472
473wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType,
474 int pos,
475 int orient)
d1367c3d 476{
c5b42c87 477 m_eventType = commandType;
d1367c3d
RR
478 m_extraLong = orient;
479 m_commandInt = pos;
480}
481
c801d85f
KB
482/*
483 * Mouse events
484 *
485 */
486
7798a18e 487wxMouseEvent::wxMouseEvent(wxEventType commandType)
c801d85f 488{
0b746ba8 489 m_eventType = commandType;
1c624631
VZ
490 m_metaDown = false;
491 m_altDown = false;
492 m_controlDown = false;
493 m_shiftDown = false;
494 m_leftDown = false;
495 m_rightDown = false;
496 m_middleDown = false;
0b746ba8
VZ
497 m_x = 0;
498 m_y = 0;
d2c52078
RD
499 m_wheelRotation = 0;
500 m_wheelDelta = 0;
501 m_linesPerAction = 0;
c801d85f
KB
502}
503
abcbaea7
VZ
504void wxMouseEvent::Assign(const wxMouseEvent& event)
505{
9a1725c4 506 m_eventType = event.m_eventType;
92309201 507
abcbaea7
VZ
508 m_x = event.m_x;
509 m_y = event.m_y;
510
511 m_leftDown = event.m_leftDown;
512 m_middleDown = event.m_middleDown;
513 m_rightDown = event.m_rightDown;
514
515 m_controlDown = event.m_controlDown;
516 m_shiftDown = event.m_shiftDown;
517 m_altDown = event.m_altDown;
518 m_metaDown = event.m_metaDown;
519
520 m_wheelRotation = event.m_wheelRotation;
521 m_wheelDelta = event.m_wheelDelta;
522 m_linesPerAction = event.m_linesPerAction;
523}
524
c801d85f
KB
525// True if was a button dclick event (1 = left, 2 = middle, 3 = right)
526// or any button dclick event (but = -1)
527bool wxMouseEvent::ButtonDClick(int but) const
528{
0b746ba8
VZ
529 switch (but)
530 {
531 case -1:
532 return (LeftDClick() || MiddleDClick() || RightDClick());
533 case 1:
534 return LeftDClick();
535 case 2:
536 return MiddleDClick();
537 case 3:
538 return RightDClick();
539 default:
223d09f6 540 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
0b746ba8
VZ
541 }
542
1c624631 543 return false;
c801d85f
KB
544}
545
546// True if was a button down event (1 = left, 2 = middle, 3 = right)
547// or any button down event (but = -1)
548bool wxMouseEvent::ButtonDown(int but) const
549{
0b746ba8
VZ
550 switch (but)
551 {
552 case -1:
553 return (LeftDown() || MiddleDown() || RightDown());
554 case 1:
555 return LeftDown();
556 case 2:
557 return MiddleDown();
558 case 3:
559 return RightDown();
560 default:
223d09f6 561 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
0b746ba8
VZ
562 }
563
1c624631 564 return false;
c801d85f
KB
565}
566
567// True if was a button up event (1 = left, 2 = middle, 3 = right)
568// or any button up event (but = -1)
569bool wxMouseEvent::ButtonUp(int but) const
570{
1e6feb95
VZ
571 switch (but)
572 {
0b746ba8
VZ
573 case -1:
574 return (LeftUp() || MiddleUp() || RightUp());
575 case 1:
576 return LeftUp();
577 case 2:
578 return MiddleUp();
579 case 3:
580 return RightUp();
581 default:
223d09f6 582 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
0b746ba8
VZ
583 }
584
1c624631 585 return false;
c801d85f
KB
586}
587
588// True if the given button is currently changing state
589bool wxMouseEvent::Button(int but) const
590{
1e6feb95
VZ
591 switch (but)
592 {
0b746ba8 593 case -1:
72cdf4c9 594 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
0b746ba8
VZ
595 case 1:
596 return (LeftDown() || LeftUp() || LeftDClick());
597 case 2:
598 return (MiddleDown() || MiddleUp() || MiddleDClick());
599 case 3:
600 return (RightDown() || RightUp() || RightDClick());
601 default:
223d09f6 602 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
0b746ba8
VZ
603 }
604
1c624631 605 return false;
c801d85f
KB
606}
607
608bool wxMouseEvent::ButtonIsDown(int but) const
609{
1e6feb95
VZ
610 switch (but)
611 {
0b746ba8
VZ
612 case -1:
613 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
614 case 1:
615 return LeftIsDown();
616 case 2:
617 return MiddleIsDown();
618 case 3:
619 return RightIsDown();
620 default:
223d09f6 621 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
0b746ba8
VZ
622 }
623
1c624631 624 return false;
c801d85f
KB
625}
626
1e6feb95
VZ
627int wxMouseEvent::GetButton() const
628{
629 for ( int i = 1; i <= 3; i++ )
630 {
631 if ( Button(i) )
632 {
633 return i;
634 }
635 }
636
637 return -1;
638}
639
c801d85f
KB
640// Find the logical position of the event given the DC
641wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const
642{
0757d27c
JS
643 wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y));
644 return pt;
c801d85f
KB
645}
646
647
648/*
8e72b8b5 649 * Keyboard event
c801d85f
KB
650 *
651 */
652
7798a18e 653wxKeyEvent::wxKeyEvent(wxEventType type)
c801d85f 654{
0b746ba8 655 m_eventType = type;
1c624631
VZ
656 m_shiftDown = false;
657 m_controlDown = false;
658 m_metaDown = false;
659 m_altDown = false;
0b746ba8 660 m_keyCode = 0;
b0e813a0 661 m_scanCode = 0;
2b5f62a0
VZ
662#if wxUSE_UNICODE
663 m_uniChar = 0;
664#endif
c801d85f
KB
665}
666
92309201 667wxKeyEvent::wxKeyEvent(const wxKeyEvent& evt)
2b5f62a0
VZ
668 : wxEvent(evt)
669{
670 m_x = evt.m_x;
671 m_y = evt.m_y;
672
673 m_keyCode = evt.m_keyCode;
674
675 m_controlDown = evt.m_controlDown;
676 m_shiftDown = evt.m_shiftDown;
677 m_altDown = evt.m_altDown;
678 m_metaDown = evt.m_metaDown;
679 m_scanCode = evt.m_scanCode;
680 m_rawCode = evt.m_rawCode;
681 m_rawFlags = evt.m_rawFlags;
92309201 682
2b5f62a0
VZ
683#if wxUSE_UNICODE
684 m_uniChar = evt.m_uniChar;
685#endif
686}
12a3f227
RL
687
688long wxKeyEvent::KeyCode() const
689{
690 return m_keyCode;
691}
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
456bc6d9
VZ
705wxChildFocusEvent::wxChildFocusEvent(wxWindow *win)
706 : wxCommandEvent(wxEVT_CHILD_FOCUS)
707{
708 SetEventObject(win);
709}
710
dd070522
VZ
711#endif // wxUSE_GUI
712
9416681d
VS
713
714#if wxUSE_BASE
715
b5a98acd
VZ
716// ----------------------------------------------------------------------------
717// wxEventHashTable
718// ----------------------------------------------------------------------------
719
720static const int EVENT_TYPE_TABLE_INIT_SIZE = 31; // Not to big not to small...
721
722wxEventHashTable::wxEventHashTable(const wxEventTable &table)
723 : m_table(table),
1c624631 724 m_rebuildHash(true)
b5a98acd
VZ
725{
726 AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE);
727}
728
729wxEventHashTable::~wxEventHashTable()
730{
731 size_t i;
732 for(i = 0; i < m_size; i++)
733 {
734 EventTypeTablePointer eTTnode = m_eventTypeTable[i];
735 if (eTTnode)
736 {
737 delete eTTnode;
738 }
739 }
740
741 delete[] m_eventTypeTable;
742}
743
744bool wxEventHashTable::HandleEvent(wxEvent &event, wxEvtHandler *self)
745{
746 if (m_rebuildHash)
747 {
748 InitHashTable();
1c624631 749 m_rebuildHash = false;
b5a98acd
VZ
750 }
751
752 // Find all entries for the given event type.
753 wxEventType eventType = event.GetEventType();
754 const EventTypeTablePointer eTTnode = m_eventTypeTable[eventType % m_size];
755 if (eTTnode && eTTnode->eventType == eventType)
756 {
757 // Now start the search for an event handler
758 // that can handle an event with the given ID.
1c624631
VZ
759 const wxEventTableEntryPointerArray&
760 eventEntryTable = eTTnode->eventEntryTable;
b5a98acd 761
1c624631
VZ
762 const size_t count = eventEntryTable.GetCount();
763 for (size_t n = 0; n < count; n++)
b5a98acd 764 {
1c624631
VZ
765 if ( wxEvtHandler::
766 ProcessEventIfMatches(*eventEntryTable[n], self, event) )
b5a98acd 767 {
1c624631 768 return true;
b5a98acd
VZ
769 }
770 }
b5a98acd
VZ
771 }
772
1c624631 773 return false;
b5a98acd
VZ
774}
775
776void wxEventHashTable::InitHashTable()
777{
778 // Loop over the event tables and all its base tables.
779 const wxEventTable *table = &m_table;
780 while (table)
781 {
782 // Retrieve all valid event handler entries
783 const wxEventTableEntry *entry = table->entries;
784 while (entry->m_fn != 0)
785 {
786 // Add the event entry in the Hash.
787 AddEntry(*entry);
788
789 entry++;
790 }
791
792 table = table->baseTable;
793 }
794
795 // Lets free some memory.
796 size_t i;
797 for(i = 0; i < m_size; i++)
798 {
799 EventTypeTablePointer eTTnode = m_eventTypeTable[i];
800 if (eTTnode)
801 {
802 eTTnode->eventEntryTable.Shrink();
803 }
804 }
805}
806
807void wxEventHashTable::AddEntry(const wxEventTableEntry &entry)
808{
809 EventTypeTablePointer *peTTnode = &m_eventTypeTable[entry.m_eventType % m_size];
810 EventTypeTablePointer eTTnode = *peTTnode;
811
812 if (eTTnode)
813 {
814 if (eTTnode->eventType != entry.m_eventType)
815 {
816 // Resize the table!
817 GrowEventTypeTable();
818 // Try again to add it.
819 AddEntry(entry);
820 return;
821 }
822 }
823 else
824 {
825 eTTnode = new EventTypeTable;
826 eTTnode->eventType = entry.m_eventType;
827 *peTTnode = eTTnode;
828 }
829
830 // Fill all hash entries between entry.m_id and entry.m_lastId...
831 eTTnode->eventEntryTable.Add(&entry);
832}
833
834void wxEventHashTable::AllocEventTypeTable(size_t size)
835{
836 m_eventTypeTable = new EventTypeTablePointer[size];
837 memset((void *)m_eventTypeTable, 0, sizeof(EventTypeTablePointer)*size);
838 m_size = size;
839}
840
841void wxEventHashTable::GrowEventTypeTable()
842{
843 size_t oldSize = m_size;
844 EventTypeTablePointer *oldEventTypeTable = m_eventTypeTable;
845
846 // TODO: Search the most optimal grow sequence
847 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize*2+1);
848
849 for ( size_t i = 0; i < oldSize; /* */ )
850 {
851 EventTypeTablePointer eTToldNode = oldEventTypeTable[i];
852 if (eTToldNode)
853 {
854 EventTypeTablePointer *peTTnode = &m_eventTypeTable[eTToldNode->eventType % m_size];
855 EventTypeTablePointer eTTnode = *peTTnode;
856
857 // Check for collision, we don't want any.
858 if (eTTnode)
859 {
860 GrowEventTypeTable();
861 continue; // Don't increment the counter,
862 // as we still need to add this element.
863 }
864 else
865 {
866 // Get the old value and put it in the new table.
867 *peTTnode = oldEventTypeTable[i];
868 }
869 }
870
871 i++;
872 }
873
874 delete[] oldEventTypeTable;
875}
876
456bc6d9
VZ
877// ----------------------------------------------------------------------------
878// wxEvtHandler
879// ----------------------------------------------------------------------------
880
c801d85f
KB
881/*
882 * Event handler
883 */
884
0b746ba8 885wxEvtHandler::wxEvtHandler()
c801d85f 886{
0b746ba8
VZ
887 m_nextHandler = (wxEvtHandler *) NULL;
888 m_previousHandler = (wxEvtHandler *) NULL;
1c624631 889 m_enabled = true;
0b746ba8 890 m_dynamicEvents = (wxList *) NULL;
8e193f38 891 m_pendingEvents = (wxList *) NULL;
7214297d 892#if wxUSE_THREADS
41404da7 893# if !defined(__VISAGECPP__)
8e193f38 894 m_eventsLocker = new wxCriticalSection;
41404da7 895# endif
7214297d 896#endif
b88c44e7
RD
897 // no client data (yet)
898 m_clientData = NULL;
899 m_clientDataType = wxClientData_None;
c801d85f
KB
900}
901
0b746ba8 902wxEvtHandler::~wxEvtHandler()
c801d85f 903{
0b746ba8
VZ
904 // Takes itself out of the list of handlers
905 if (m_previousHandler)
906 m_previousHandler->m_nextHandler = m_nextHandler;
907
908 if (m_nextHandler)
909 m_nextHandler->m_previousHandler = m_previousHandler;
910
911 if (m_dynamicEvents)
fe71f65c 912 {
df5168c4
MB
913 wxList::iterator it = m_dynamicEvents->begin(),
914 en = m_dynamicEvents->end();
915 for (;it != en; ++it)
0b746ba8 916 {
2e4df4bf 917#if WXWIN_COMPATIBILITY_EVENT_TYPES
df5168c4 918 wxEventTableEntry *entry = (wxEventTableEntry*)*it;
2e4df4bf 919#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
df5168c4 920 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)*it;
2e4df4bf
VZ
921#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
922
923 if (entry->m_callbackUserData)
924 delete entry->m_callbackUserData;
0b746ba8 925 delete entry;
0b746ba8
VZ
926 }
927 delete m_dynamicEvents;
928 };
7214297d 929
8e193f38 930 delete m_pendingEvents;
7214297d 931
8e193f38 932#if wxUSE_THREADS
41404da7 933# if !defined(__VISAGECPP__)
7214297d 934 delete m_eventsLocker;
41404da7 935# endif
b5a98acd 936
083f7497
JS
937 // Remove us from wxPendingEvents if necessary.
938 if(wxPendingEventsLocker)
939 wxENTER_CRIT_SECT(*wxPendingEventsLocker);
940 if ( wxPendingEvents ) {
941 wxPendingEvents->DeleteObject(this);
942 }
943 if(wxPendingEventsLocker)
944 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker);
7214297d 945#endif
b88c44e7
RD
946
947 // we only delete object data, not untyped
948 if ( m_clientDataType == wxClientData_Object )
949 delete m_clientObject;
c801d85f
KB
950}
951
7214297d 952#if wxUSE_THREADS
aadbdf11 953
7214297d
GL
954bool wxEvtHandler::ProcessThreadEvent(wxEvent& event)
955{
7214297d 956 // check that we are really in a child thread
8e193f38
VZ
957 wxASSERT_MSG( !wxThread::IsMain(),
958 wxT("use ProcessEvent() in main thread") );
959
960 AddPendingEvent(event);
7214297d 961
1c624631 962 return true;
8e193f38
VZ
963}
964
1c624631
VZ
965void wxEvtHandler::ClearEventLocker()
966{
967#if !defined(__VISAGECPP__)
968 delete m_eventsLocker;
969 m_eventsLocker = NULL;
970#endif
971};
972
8e193f38
VZ
973#endif // wxUSE_THREADS
974
975void wxEvtHandler::AddPendingEvent(wxEvent& event)
976{
16c1f79c
RR
977 // 1) Add event to list of pending events of this event handler
978
7a5c8ac4
VZ
979 wxEvent *eventCopy = event.Clone();
980
981 // we must be able to copy the events here so the event class must
982 // implement Clone() properly instead of just providing a NULL stab for it
983 wxCHECK_RET( eventCopy,
984 _T("events of this type aren't supposed to be posted") );
985
16c1f79c
RR
986#if defined(__VISAGECPP__)
987 wxENTER_CRIT_SECT( m_eventsLocker);
988#else
989 wxENTER_CRIT_SECT( *m_eventsLocker);
990#endif
991
8e193f38
VZ
992 if ( !m_pendingEvents )
993 m_pendingEvents = new wxList;
7214297d 994
7a5c8ac4 995 m_pendingEvents->Append(eventCopy);
7214297d 996
16c1f79c
RR
997#if defined(__VISAGECPP__)
998 wxLEAVE_CRIT_SECT( m_eventsLocker);
999#else
1000 wxLEAVE_CRIT_SECT( *m_eventsLocker);
1001#endif
1002
1003 // 2) Add this event handler to list of event handlers that
1004 // have pending events.
cfe17b74 1005
b568d04f 1006 wxENTER_CRIT_SECT(*wxPendingEventsLocker);
72cdf4c9 1007
8e193f38
VZ
1008 if ( !wxPendingEvents )
1009 wxPendingEvents = new wxList;
4d3a259a 1010 wxPendingEvents->Append(this);
72cdf4c9 1011
ce6d2511 1012 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker);
6164f93c 1013
16c1f79c
RR
1014 // 3) Inform the system that new pending events are somwehere,
1015 // and that these should be processed in idle time.
bf9e3e73 1016 wxWakeUpIdle();
7214297d
GL
1017}
1018
1019void wxEvtHandler::ProcessPendingEvents()
1020{
41404da7 1021#if defined(__VISAGECPP__)
16c1f79c 1022 wxENTER_CRIT_SECT( m_eventsLocker);
b568d04f 1023#else
16c1f79c 1024 wxENTER_CRIT_SECT( *m_eventsLocker);
41404da7 1025#endif
8e193f38 1026
df5168c4 1027 wxList::compatibility_iterator node = m_pendingEvents->GetFirst();
8e193f38
VZ
1028 while ( node )
1029 {
b1d4dd7a 1030 wxEvent *event = (wxEvent *)node->GetData();
df5168c4 1031 m_pendingEvents->Erase(node);
cfe17b74 1032
16c1f79c 1033 // In ProcessEvent, new events might get added and
6164f93c 1034 // we can safely leave the crtical section here.
16c1f79c
RR
1035#if defined(__VISAGECPP__)
1036 wxLEAVE_CRIT_SECT( m_eventsLocker);
1037#else
1038 wxLEAVE_CRIT_SECT( *m_eventsLocker);
1039#endif
8e193f38 1040 ProcessEvent(*event);
9779893b 1041 delete event;
16c1f79c
RR
1042#if defined(__VISAGECPP__)
1043 wxENTER_CRIT_SECT( m_eventsLocker);
1044#else
1045 wxENTER_CRIT_SECT( *m_eventsLocker);
1046#endif
cfe17b74 1047
b1d4dd7a 1048 node = m_pendingEvents->GetFirst();
7214297d 1049 }
cfe17b74 1050
16c1f79c
RR
1051#if defined(__VISAGECPP__)
1052 wxLEAVE_CRIT_SECT( m_eventsLocker);
1053#else
1054 wxLEAVE_CRIT_SECT( *m_eventsLocker);
1055#endif
7214297d 1056}
7214297d 1057
c801d85f
KB
1058/*
1059 * Event table stuff
1060 */
1c624631
VZ
1061/* static */ bool
1062wxEvtHandler::ProcessEventIfMatches(const wxEventTableEntryBase& entry,
1063 wxEvtHandler *handler,
1064 wxEvent& event)
1065{
1066 int tableId1 = entry.m_id,
1067 tableId2 = entry.m_lastId;
1068
1069 // match only if the event type is the same and the id is either -1 in
1070 // the event table (meaning "any") or the event id matches the id
1071 // specified in the event table either exactly or by falling into
1072 // range between first and last
1073 if ((tableId1 == -1) ||
1074 (tableId2 == -1 && tableId1 == event.GetId()) ||
1075 (tableId2 != -1 &&
1076 (event.GetId() >= tableId1 && event.GetId() <= tableId2)))
1077 {
1078 event.Skip(false);
1079 event.m_callbackUserData = entry.m_callbackUserData;
1080
1081#if wxUSE_EXCEPTIONS
1082 if ( wxTheApp )
1083 {
1084 // call the handler via wxApp method which allows the user to catch
1085 // any exceptions which may be thrown by any handler in the program
1086 // in one place
1087 wxTheApp->HandleEvent(handler, (wxEventFunction)entry.m_fn, event);
1088 }
1089 else
8bd2a804 1090#endif // wxUSE_EXCEPTIONS
1c624631
VZ
1091 {
1092 // no need for an extra virtual function call
1093 (handler->*((wxEventFunction) (entry.m_fn)))(event);
1094 }
1c624631
VZ
1095
1096 if (!event.GetSkipped())
1097 return true;
1098 }
1099
1100 return false;
1101}
c801d85f 1102
4caf847c 1103bool wxEvtHandler::TryParent(wxEvent& event)
c801d85f 1104{
4caf847c 1105 if ( wxTheApp && (this != wxTheApp) )
9154d8cf 1106 {
4caf847c
VZ
1107 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1108 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1109 // processed appropriately via SearchEventTable.
1110 if ( event.GetEventType() != wxEVT_IDLE )
1111 {
1112 if ( wxTheApp->ProcessEvent(event) )
1c624631 1113 return true;
4caf847c 1114 }
9154d8cf
VZ
1115 }
1116
1c624631 1117 return false;
4caf847c 1118}
0b746ba8 1119
4caf847c
VZ
1120bool wxEvtHandler::ProcessEvent(wxEvent& event)
1121{
9154d8cf
VZ
1122 // allow the application to hook into event processing
1123 if ( wxTheApp )
1124 {
1125 int rc = wxTheApp->FilterEvent(event);
1126 if ( rc != -1 )
1127 {
1128 wxASSERT_MSG( rc == 1 || rc == 0,
1129 _T("unexpected wxApp::FilterEvent return value") );
1130
1131 return rc != 0;
1132 }
1133 //else: proceed normally
1134 }
1135
8e193f38 1136 // An event handler can be enabled or disabled
0b746ba8 1137 if ( GetEvtHandlerEnabled() )
c801d85f 1138 {
22c2307c
VZ
1139 // if we have a validator, it has higher priority than our own event
1140 // table
4caf847c 1141 if ( TryValidator(event) )
1c624631 1142 return true;
4caf847c 1143
22c2307c
VZ
1144 // Handle per-instance dynamic event tables first
1145 if ( m_dynamicEvents && SearchDynamicEventTable(event) )
1c624631 1146 return true;
0b746ba8 1147
b5a98acd
VZ
1148 // Then static per-class event tables
1149 if ( GetEventHashTable().HandleEvent(event, this) )
1c624631 1150 return true;
c801d85f
KB
1151 }
1152
0b746ba8
VZ
1153 // Try going down the event handler chain
1154 if ( GetNextHandler() )
c801d85f 1155 {
0b746ba8 1156 if ( GetNextHandler()->ProcessEvent(event) )
1c624631 1157 return true;
c801d85f 1158 }
c801d85f 1159
22c2307c
VZ
1160 // Finally propagate the event upwards the window chain and/or to the
1161 // application object as necessary
4caf847c 1162 return TryParent(event);
c801d85f
KB
1163}
1164
b5a98acd 1165
c801d85f
KB
1166bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
1167{
1c624631 1168 const wxEventType eventType = event.GetEventType();
68662769 1169 for ( int i = 0; table.entries[i].m_fn != 0; i++ )
c801d85f 1170 {
68662769 1171 const wxEventTableEntry& entry = table.entries[i];
68662769 1172 if ( eventType == entry.m_eventType )
0b746ba8 1173 {
1c624631
VZ
1174 if ( ProcessEventIfMatches(entry, this, event) )
1175 return true;
0b746ba8 1176 }
c801d85f 1177 }
68662769 1178
1c624631 1179 return false;
c801d85f 1180}
97d7bfb8 1181
debe6624 1182void wxEvtHandler::Connect( int id, int lastId,
77d4384e 1183 int eventType,
0b746ba8 1184 wxObjectEventFunction func,
65b17727
JS
1185 wxObject *userData,
1186 wxEvtHandler* eventSink )
fe71f65c 1187{
cbee8f8d 1188#if WXWIN_COMPATIBILITY_EVENT_TYPES
2e4df4bf 1189 wxEventTableEntry *entry = new wxEventTableEntry;
cbee8f8d
VZ
1190 entry->m_eventType = eventType;
1191 entry->m_id = id;
1192 entry->m_lastId = lastId;
1193 entry->m_fn = func;
1194 entry->m_callbackUserData = userData;
1195#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
0b5eceb6 1196 wxDynamicEventTableEntry *entry =
65b17727 1197 new wxDynamicEventTableEntry(eventType, id, lastId, func, userData, eventSink);
cbee8f8d 1198#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
0b746ba8
VZ
1199
1200 if (!m_dynamicEvents)
1201 m_dynamicEvents = new wxList;
1202
92309201
RD
1203 // Insert at the front of the list so most recent additions are found first
1204 m_dynamicEvents->Insert( (wxObject*) entry );
fe71f65c 1205}
97d7bfb8
RR
1206
1207bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType,
1208 wxObjectEventFunction func,
65b17727
JS
1209 wxObject *userData,
1210 wxEvtHandler* eventSink )
97d7bfb8
RR
1211{
1212 if (!m_dynamicEvents)
1c624631 1213 return false;
cfe17b74 1214
df5168c4 1215 wxList::compatibility_iterator node = m_dynamicEvents->GetFirst();
97d7bfb8
RR
1216 while (node)
1217 {
2e4df4bf 1218#if WXWIN_COMPATIBILITY_EVENT_TYPES
b1d4dd7a 1219 wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData();
2e4df4bf 1220#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
b1d4dd7a 1221 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
2e4df4bf
VZ
1222#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1223
97d7bfb8
RR
1224 if ((entry->m_id == id) &&
1225 ((entry->m_lastId == lastId) || (lastId == -1)) &&
1226 ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) &&
1227 ((entry->m_fn == func) || (func == (wxObjectEventFunction)NULL)) &&
65b17727 1228 ((entry->m_eventSink == eventSink) || (eventSink == (wxEvtHandler*)NULL)) &&
97d7bfb8
RR
1229 ((entry->m_callbackUserData == userData) || (userData == (wxObject*)NULL)))
1230 {
2e4df4bf
VZ
1231 if (entry->m_callbackUserData)
1232 delete entry->m_callbackUserData;
df5168c4 1233 m_dynamicEvents->Erase( node );
97d7bfb8 1234 delete entry;
1c624631 1235 return true;
97d7bfb8 1236 }
b1d4dd7a 1237 node = node->GetNext();
97d7bfb8 1238 }
1c624631 1239 return false;
97d7bfb8 1240}
fe71f65c
RR
1241
1242bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
1243{
1c624631 1244 wxCHECK_MSG( m_dynamicEvents, false,
223d09f6 1245 wxT("caller should check that we have dynamic events") );
0b746ba8 1246
df5168c4 1247 wxList::compatibility_iterator node = m_dynamicEvents->GetFirst();
0b746ba8 1248 while (node)
fe71f65c 1249 {
2e4df4bf 1250#if WXWIN_COMPATIBILITY_EVENT_TYPES
1c624631 1251 wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData();
2e4df4bf 1252#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1c624631 1253 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
2e4df4bf 1254#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
0b746ba8
VZ
1255
1256 if (entry->m_fn)
1257 {
1c624631 1258 wxEvtHandler *handler =
65b17727 1259#if !WXWIN_COMPATIBILITY_EVENT_TYPES
1c624631
VZ
1260 entry->m_eventSink ? entry->m_eventSink
1261 :
b5a98acd 1262#endif
1c624631 1263 this;
0b746ba8 1264
1c624631
VZ
1265 if ( ProcessEventIfMatches(*entry, handler, event) )
1266 {
1267 return true;
0b746ba8
VZ
1268 }
1269 }
1c624631 1270
b1d4dd7a 1271 node = node->GetNext();
7b678698 1272 }
1c624631
VZ
1273
1274 return false;
fe71f65c
RR
1275};
1276
b88c44e7
RD
1277void wxEvtHandler::DoSetClientObject( wxClientData *data )
1278{
1279 wxASSERT_MSG( m_clientDataType != wxClientData_Void,
1280 wxT("can't have both object and void client data") );
1281
1282 if ( m_clientObject )
1283 delete m_clientObject;
1284
1285 m_clientObject = data;
1286 m_clientDataType = wxClientData_Object;
1287}
1288
1289wxClientData *wxEvtHandler::DoGetClientObject() const
1290{
1291 // it's not an error to call GetClientObject() on a window which doesn't
1292 // have client data at all - NULL will be returned
1293 wxASSERT_MSG( m_clientDataType != wxClientData_Void,
1294 wxT("this window doesn't have object client data") );
1295
1296 return m_clientObject;
1297}
1298
1299void wxEvtHandler::DoSetClientData( void *data )
1300{
1301 wxASSERT_MSG( m_clientDataType != wxClientData_Object,
1302 wxT("can't have both object and void client data") );
1303
1304 m_clientData = data;
1305 m_clientDataType = wxClientData_Void;
1306}
1307
1308void *wxEvtHandler::DoGetClientData() const
1309{
1310 // it's not an error to call GetClientData() on a window which doesn't have
1311 // client data at all - NULL will be returned
1312 wxASSERT_MSG( m_clientDataType != wxClientData_Object,
1313 wxT("this window doesn't have void client data") );
1314
1315 return m_clientData;
1316}
1317
4caf847c
VZ
1318#endif // wxUSE_BASE
1319
e90c1d2a
VZ
1320#if wxUSE_GUI
1321
e702ff0f
JS
1322// Find a window with the focus, that is also a descendant of the given window.
1323// This is used to determine the window to initially send commands to.
1324wxWindow* wxFindFocusDescendant(wxWindow* ancestor)
1325{
1326 // Process events starting with the window with the focus, if any.
1327 wxWindow* focusWin = wxWindow::FindFocus();
1328 wxWindow* win = focusWin;
1329
1330 // Check if this is a descendant of this frame.
1331 // If not, win will be set to NULL.
1332 while (win)
1333 {
1334 if (win == ancestor)
1335 break;
1336 else
1337 win = win->GetParent();
1338 }
1339 if (win == (wxWindow*) NULL)
1340 focusWin = (wxWindow*) NULL;
1341
1342 return focusWin;
1343}
1344
e90c1d2a 1345#endif // wxUSE_GUI