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