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