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