]> git.saurik.com Git - wxWidgets.git/blame - src/common/event.cpp
no real change: put event handlers together at the end of the file
[wxWidgets.git] / src / common / event.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
c54de5ae 2// Name: src/common/event.cpp
c801d85f
KB
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
c801d85f
KB
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
0b746ba8 24 #pragma hdrstop
c801d85f
KB
25#endif
26
d5da0ce7 27#include "wx/event.h"
937013e0 28#include "wx/evtloop.h"
d5da0ce7 29
c801d85f 30#ifndef WX_PRECOMP
e90c1d2a 31 #include "wx/list.h"
8ecff181 32 #include "wx/app.h"
de6185e2 33 #include "wx/utils.h"
bb90a3e6 34 #include "wx/stopwatch.h"
02761f6c 35 #include "wx/module.h"
e90c1d2a
VZ
36
37 #if wxUSE_GUI
a8ff046b 38 #include "wx/window.h"
e90c1d2a 39 #include "wx/control.h"
e90c1d2a 40 #include "wx/dc.h"
dca94103 41 #include "wx/spinbutt.h"
75a29298 42 #include "wx/textctrl.h"
264cb7f5 43 #include "wx/validate.h"
e90c1d2a 44 #endif // wxUSE_GUI
c801d85f
KB
45#endif
46
204abcd4 47#include "wx/thread.h"
47b6fabc 48
d102b02a 49#if wxUSE_BASE
664e1314 50 #include "wx/scopedptr.h"
d102b02a
VZ
51
52 wxDECLARE_SCOPED_PTR(wxEvent, wxEventPtr)
53 wxDEFINE_SCOPED_PTR(wxEvent, wxEventPtr)
54#endif // wxUSE_BASE
204abcd4 55
8e193f38
VZ
56// ----------------------------------------------------------------------------
57// wxWin macros
58// ----------------------------------------------------------------------------
59
3ed2104c
VZ
60#if wxUSE_BASE
61 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject)
62 IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject)
b46b1d59 63 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent)
3ed2104c 64#endif // wxUSE_BASE
e90c1d2a 65
23f681ec
VZ
66#if wxUSE_GUI
67 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent)
43c8c1f3 68 IMPLEMENT_DYNAMIC_CLASS(wxThreadEvent, wxCommandEvent)
23f681ec
VZ
69 IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent)
70 IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent)
71 IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent, wxEvent)
72 IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent)
73 IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent)
74 IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent)
75 IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent)
1e6feb95 76 IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent, wxEvent)
23f681ec
VZ
77 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent)
78 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent)
79 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent)
456bc6d9 80 IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent, wxCommandEvent)
23f681ec
VZ
81 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent)
82 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent)
83 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent)
84 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent)
85 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent)
86 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent)
87 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent)
88 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent)
89 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent)
8e72b8b5 90 IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent, wxEvent)
23f681ec 91 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent)
574c939e 92 IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent, wxEvent)
23f681ec 93 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent)
75299490 94 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxEvent)
23f681ec
VZ
95 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, wxEvent)
96 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent, wxEvent)
97 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent, wxEvent)
98 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent, wxEvent)
b96340e6 99 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent, wxCommandEvent)
69231000 100 IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent, wxCommandEvent)
a5e84126 101 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent, wxEvent)
63e819f2 102 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureLostEvent, wxEvent)
78c91815 103 IMPLEMENT_DYNAMIC_CLASS(wxClipboardTextEvent, wxCommandEvent)
23f681ec 104#endif // wxUSE_GUI
0b746ba8 105
3ed2104c
VZ
106#if wxUSE_BASE
107
23f681ec
VZ
108const wxEventTable *wxEvtHandler::GetEventTable() const
109 { return &wxEvtHandler::sm_eventTable; }
0b746ba8 110
23f681ec
VZ
111const wxEventTable wxEvtHandler::sm_eventTable =
112 { (const wxEventTable *)NULL, &wxEvtHandler::sm_eventTableEntries[0] };
0b746ba8 113
b5a98acd
VZ
114wxEventHashTable &wxEvtHandler::GetEventHashTable() const
115 { return wxEvtHandler::sm_eventHashTable; }
116
117wxEventHashTable wxEvtHandler::sm_eventHashTable(wxEvtHandler::sm_eventTable);
118
23f681ec 119const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] =
3c778901 120 { DECLARE_EVENT_TABLE_TERMINATOR() };
c801d85f 121
1a18887b 122
a0826b11
VZ
123// wxUSE_MEMORY_TRACING considers memory freed from the static objects dtors
124// leaked, so we need to manually clean up all event tables before checking for
125// the memory leaks when using it, however this breaks re-initializing the
126// library (i.e. repeated calls to wxInitialize/wxUninitialize) because the
127// event tables won't be rebuilt the next time, so disable this by default
aa767a45 128#if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
a0826b11 129
afa039f9
JS
130class wxEventTableEntryModule: public wxModule
131{
afa039f9 132public:
a0826b11
VZ
133 wxEventTableEntryModule() { }
134 virtual bool OnInit() { return true; }
135 virtual void OnExit() { wxEventHashTable::ClearAll(); }
136
137 DECLARE_DYNAMIC_CLASS(wxEventTableEntryModule)
afa039f9 138};
a0826b11 139
afa039f9 140IMPLEMENT_DYNAMIC_CLASS(wxEventTableEntryModule, wxModule)
a0826b11
VZ
141
142#endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING
1a18887b 143
8e193f38
VZ
144// ----------------------------------------------------------------------------
145// global variables
146// ----------------------------------------------------------------------------
147
19c4d916
VZ
148// List containing event handlers with pending events (each handler can occur
149// at most once here)
079f4130 150wxList *wxHandlersWithPendingEvents = NULL;
d48b06bd 151wxList *wxHandlersWithPendingDelayedEvents = NULL;
8e193f38 152
7214297d 153#if wxUSE_THREADS
079f4130
FM
154 // protects wxHandlersWithPendingEvents list
155 wxCriticalSection *wxHandlersWithPendingEventsLocker = NULL;
7214297d
GL
156#endif
157
2e4df4bf
VZ
158// common event types are defined here, other event types are defined by the
159// components which use them
b5a98acd 160
c15d9c85
VS
161const wxEventType wxEVT_FIRST = 10000;
162const wxEventType wxEVT_USER_FIRST = wxEVT_FIRST + 2000;
2e4df4bf 163
461697c2 164DEFINE_EVENT_TYPE(wxEVT_NULL)
3c778901 165wxDEFINE_EVENT( wxEVT_IDLE, wxIdleEvent )
886dd7d2 166
886dd7d2
VZ
167#endif // wxUSE_BASE
168
169#if wxUSE_GUI
170
3c778901
VZ
171wxDEFINE_EVENT( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEvent )
172wxDEFINE_EVENT( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEvent )
173wxDEFINE_EVENT( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEvent )
174wxDEFINE_EVENT( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEvent )
175wxDEFINE_EVENT( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEvent )
176wxDEFINE_EVENT( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, wxCommandEvent )
177wxDEFINE_EVENT( wxEVT_COMMAND_MENU_SELECTED, wxCommandEvent )
178wxDEFINE_EVENT( wxEVT_COMMAND_SLIDER_UPDATED, wxCommandEvent )
179wxDEFINE_EVENT( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEvent )
180wxDEFINE_EVENT( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEvent )
181wxDEFINE_EVENT( wxEVT_COMMAND_SCROLLBAR_UPDATED, wxCommandEvent )
182wxDEFINE_EVENT( wxEVT_COMMAND_VLBOX_SELECTED, wxCommandEvent )
183wxDEFINE_EVENT( wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEvent )
184wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_RCLICKED, wxCommandEvent )
185wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_ENTER, wxCommandEvent )
186wxDEFINE_EVENT( wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEvent )
187wxDEFINE_EVENT( wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, wxCommandEvent )
188wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED, wxCommandEvent )
0b5eceb6 189
0b5eceb6 190// Mouse event types
3c778901
VZ
191wxDEFINE_EVENT( wxEVT_LEFT_DOWN, wxMouseEvent )
192wxDEFINE_EVENT( wxEVT_LEFT_UP, wxMouseEvent )
193wxDEFINE_EVENT( wxEVT_MIDDLE_DOWN, wxMouseEvent )
194wxDEFINE_EVENT( wxEVT_MIDDLE_UP, wxMouseEvent )
195wxDEFINE_EVENT( wxEVT_RIGHT_DOWN, wxMouseEvent )
196wxDEFINE_EVENT( wxEVT_RIGHT_UP, wxMouseEvent )
197wxDEFINE_EVENT( wxEVT_MOTION, wxMouseEvent )
198wxDEFINE_EVENT( wxEVT_ENTER_WINDOW, wxMouseEvent )
199wxDEFINE_EVENT( wxEVT_LEAVE_WINDOW, wxMouseEvent )
200wxDEFINE_EVENT( wxEVT_LEFT_DCLICK, wxMouseEvent )
201wxDEFINE_EVENT( wxEVT_MIDDLE_DCLICK, wxMouseEvent )
202wxDEFINE_EVENT( wxEVT_RIGHT_DCLICK, wxMouseEvent )
203wxDEFINE_EVENT( wxEVT_SET_FOCUS, wxFocusEvent )
204wxDEFINE_EVENT( wxEVT_KILL_FOCUS, wxFocusEvent )
205wxDEFINE_EVENT( wxEVT_CHILD_FOCUS, wxChildFocusEvent )
206wxDEFINE_EVENT( wxEVT_MOUSEWHEEL, wxMouseEvent )
207wxDEFINE_EVENT( wxEVT_AUX1_DOWN, wxMouseEvent )
208wxDEFINE_EVENT( wxEVT_AUX1_UP, wxMouseEvent )
209wxDEFINE_EVENT( wxEVT_AUX1_DCLICK, wxMouseEvent )
210wxDEFINE_EVENT( wxEVT_AUX2_DOWN, wxMouseEvent )
211wxDEFINE_EVENT( wxEVT_AUX2_UP, wxMouseEvent )
212wxDEFINE_EVENT( wxEVT_AUX2_DCLICK, wxMouseEvent )
0b5eceb6
VZ
213
214// Character input event type
3c778901
VZ
215wxDEFINE_EVENT( wxEVT_CHAR, wxKeyEvent )
216wxDEFINE_EVENT( wxEVT_CHAR_HOOK, wxKeyEvent )
217wxDEFINE_EVENT( wxEVT_NAVIGATION_KEY, wxNavigationKeyEvent )
218wxDEFINE_EVENT( wxEVT_KEY_DOWN, wxKeyEvent )
219wxDEFINE_EVENT( wxEVT_KEY_UP, wxKeyEvent )
5048c832 220#if wxUSE_HOTKEY
3c778901 221wxDEFINE_EVENT( wxEVT_HOTKEY, wxKeyEvent )
5048c832 222#endif
0b5eceb6
VZ
223
224// Set cursor event
3c778901 225wxDEFINE_EVENT( wxEVT_SET_CURSOR, wxSetCursorEvent )
0b5eceb6
VZ
226
227// wxScrollbar and wxSlider event identifiers
3c778901
VZ
228wxDEFINE_EVENT( wxEVT_SCROLL_TOP, wxScrollEvent )
229wxDEFINE_EVENT( wxEVT_SCROLL_BOTTOM, wxScrollEvent )
230wxDEFINE_EVENT( wxEVT_SCROLL_LINEUP, wxScrollEvent )
231wxDEFINE_EVENT( wxEVT_SCROLL_LINEDOWN, wxScrollEvent )
232wxDEFINE_EVENT( wxEVT_SCROLL_PAGEUP, wxScrollEvent )
233wxDEFINE_EVENT( wxEVT_SCROLL_PAGEDOWN, wxScrollEvent )
234wxDEFINE_EVENT( wxEVT_SCROLL_THUMBTRACK, wxScrollEvent )
235wxDEFINE_EVENT( wxEVT_SCROLL_THUMBRELEASE, wxScrollEvent )
236wxDEFINE_EVENT( wxEVT_SCROLL_CHANGED, wxScrollEvent )
0b5eceb6 237
dca94103
VZ
238// Due to a bug in older wx versions, wxSpinEvents were being sent with type of
239// wxEVT_SCROLL_LINEUP, wxEVT_SCROLL_LINEDOWN and wxEVT_SCROLL_THUMBTRACK. But
240// with the type-safe events in place, these event types are associated with
241// wxScrollEvent. To allow handling of spin events, new event types have been
242// defined in spinbutt.h/spinnbuttcmn.cpp. To maintain backward compatibility
243// the spin event types are being initialized with the scroll event types.
244
245#if wxUSE_SPINBTN
246
247wxDEFINE_EVENT_ALIAS( wxEVT_SPIN_UP, wxSpinEvent, wxEVT_SCROLL_LINEUP )
248wxDEFINE_EVENT_ALIAS( wxEVT_SPIN_DOWN, wxSpinEvent, wxEVT_SCROLL_LINEDOWN )
249wxDEFINE_EVENT_ALIAS( wxEVT_SPIN, wxSpinEvent, wxEVT_SCROLL_THUMBTRACK )
250
251#endif // wxUSE_SPINBTN
252
0b5eceb6 253// Scroll events from wxWindow
3c778901
VZ
254wxDEFINE_EVENT( wxEVT_SCROLLWIN_TOP, wxScrollWinEvent )
255wxDEFINE_EVENT( wxEVT_SCROLLWIN_BOTTOM, wxScrollWinEvent )
256wxDEFINE_EVENT( wxEVT_SCROLLWIN_LINEUP, wxScrollWinEvent )
257wxDEFINE_EVENT( wxEVT_SCROLLWIN_LINEDOWN, wxScrollWinEvent )
258wxDEFINE_EVENT( wxEVT_SCROLLWIN_PAGEUP, wxScrollWinEvent )
259wxDEFINE_EVENT( wxEVT_SCROLLWIN_PAGEDOWN, wxScrollWinEvent )
260wxDEFINE_EVENT( wxEVT_SCROLLWIN_THUMBTRACK, wxScrollWinEvent )
261wxDEFINE_EVENT( wxEVT_SCROLLWIN_THUMBRELEASE, wxScrollWinEvent )
0b5eceb6
VZ
262
263// System events
3c778901
VZ
264wxDEFINE_EVENT( wxEVT_SIZE, wxSizeEvent )
265wxDEFINE_EVENT( wxEVT_SIZING, wxSizeEvent )
266wxDEFINE_EVENT( wxEVT_MOVE, wxMoveEvent )
267wxDEFINE_EVENT( wxEVT_MOVING, wxMoveEvent )
268wxDEFINE_EVENT( wxEVT_MOVE_START, wxMoveEvent )
269wxDEFINE_EVENT( wxEVT_MOVE_END, wxMoveEvent )
270wxDEFINE_EVENT( wxEVT_CLOSE_WINDOW, wxCloseEvent )
271wxDEFINE_EVENT( wxEVT_END_SESSION, wxCloseEvent )
272wxDEFINE_EVENT( wxEVT_QUERY_END_SESSION, wxCloseEvent )
273wxDEFINE_EVENT( wxEVT_HIBERNATE, wxActivateEvent )
274wxDEFINE_EVENT( wxEVT_ACTIVATE_APP, wxActivateEvent )
275wxDEFINE_EVENT( wxEVT_ACTIVATE, wxActivateEvent )
276wxDEFINE_EVENT( wxEVT_CREATE, wxWindowCreateEvent )
277wxDEFINE_EVENT( wxEVT_DESTROY, wxWindowDestroyEvent )
278wxDEFINE_EVENT( wxEVT_SHOW, wxShowEvent )
279wxDEFINE_EVENT( wxEVT_ICONIZE, wxIconizeEvent )
280wxDEFINE_EVENT( wxEVT_MAXIMIZE, wxMaximizeEvent )
281wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_CHANGED, wxMouseCaptureChangedEvent )
282wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_LOST, wxMouseCaptureLostEvent )
283wxDEFINE_EVENT( wxEVT_PAINT, wxPaintEvent )
284wxDEFINE_EVENT( wxEVT_ERASE_BACKGROUND, wxEraseEvent )
285wxDEFINE_EVENT( wxEVT_NC_PAINT, wxNcPaintEvent )
286wxDEFINE_EVENT( wxEVT_MENU_OPEN, wxMenuEvent )
287wxDEFINE_EVENT( wxEVT_MENU_CLOSE, wxMenuEvent )
288wxDEFINE_EVENT( wxEVT_MENU_HIGHLIGHT, wxMenuEvent )
289wxDEFINE_EVENT( wxEVT_CONTEXT_MENU, wxContextMenuEvent )
290wxDEFINE_EVENT( wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEvent )
291wxDEFINE_EVENT( wxEVT_DISPLAY_CHANGED, wxDisplayChangedEvent )
292wxDEFINE_EVENT( wxEVT_QUERY_NEW_PALETTE, wxQueryNewPaletteEvent )
293wxDEFINE_EVENT( wxEVT_PALETTE_CHANGED, wxPaletteChangedEvent )
294wxDEFINE_EVENT( wxEVT_JOY_BUTTON_DOWN, wxJoystickEvent )
295wxDEFINE_EVENT( wxEVT_JOY_BUTTON_UP, wxJoystickEvent )
296wxDEFINE_EVENT( wxEVT_JOY_MOVE, wxJoystickEvent )
297wxDEFINE_EVENT( wxEVT_JOY_ZMOVE, wxJoystickEvent )
298wxDEFINE_EVENT( wxEVT_DROP_FILES, wxDropFilesEvent )
299wxDEFINE_EVENT( wxEVT_INIT_DIALOG, wxInitDialogEvent )
300wxDEFINE_EVENT( wxEVT_UPDATE_UI, wxUpdateUIEvent )
0b5eceb6 301
78c91815 302// Clipboard events
3c778901
VZ
303wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_COPY, wxClipboardTextEvent )
304wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_CUT, wxClipboardTextEvent )
305wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_PASTE, wxClipboardTextEvent )
78c91815 306
0b5eceb6
VZ
307// Generic command events
308// Note: a click is a higher-level event than button down/up
3c778901
VZ
309wxDEFINE_EVENT( wxEVT_COMMAND_LEFT_CLICK, wxCommandEvent )
310wxDEFINE_EVENT( wxEVT_COMMAND_LEFT_DCLICK, wxCommandEvent )
311wxDEFINE_EVENT( wxEVT_COMMAND_RIGHT_CLICK, wxCommandEvent )
312wxDEFINE_EVENT( wxEVT_COMMAND_RIGHT_DCLICK, wxCommandEvent )
313wxDEFINE_EVENT( wxEVT_COMMAND_SET_FOCUS, wxCommandEvent )
314wxDEFINE_EVENT( wxEVT_COMMAND_KILL_FOCUS, wxCommandEvent )
315wxDEFINE_EVENT( wxEVT_COMMAND_ENTER, wxCommandEvent )
0b5eceb6
VZ
316
317// Help events
3c778901
VZ
318wxDEFINE_EVENT( wxEVT_HELP, wxHelpEvent )
319wxDEFINE_EVENT( wxEVT_DETAILED_HELP, wxHelpEvent )
6164f93c 320
d48b06bd 321// Thread event
f6a3e0ba 322wxDEFINE_EVENT( wxEVT_COMMAND_THREAD, wxThreadEvent )
d48b06bd 323
886dd7d2
VZ
324#endif // wxUSE_GUI
325
326#if wxUSE_BASE
327
b46b1d59
VZ
328wxIdleMode wxIdleEvent::sm_idleMode = wxIDLE_PROCESS_ALL;
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}
3c778901
VZ
345// ----------------------------------------------------------------------------
346// wxEventFunctor
347// ----------------------------------------------------------------------------
348
349wxEventFunctor::~wxEventFunctor()
350{
351}
0b5eceb6 352
8e193f38
VZ
353// ----------------------------------------------------------------------------
354// wxEvent
355// ----------------------------------------------------------------------------
356
c801d85f 357/*
d48b06bd
FM
358 * General wxWidgets events, covering all interesting things that might happen
359 * (button clicking, resizing, setting text in widgets, etc.).
c801d85f
KB
360 *
361 * For each completely new event type, derive a new event class.
362 *
363 */
364
d48b06bd 365wxEvent::wxEvent(int theId, wxEventType commandType)
c801d85f 366{
8e72b8b5 367 m_eventType = commandType;
3c778901 368 m_eventObject = NULL;
0b746ba8
VZ
369 m_timeStamp = 0;
370 m_id = theId;
1c624631 371 m_skipped = false;
3c778901 372 m_callbackUserData = NULL;
1c624631 373 m_isCommandEvent = false;
1648d51b 374 m_propagationLevel = wxEVENT_PROPAGATE_NONE;
29de6f40 375 m_wasProcessed = false;
c801d85f
KB
376}
377
0e097789 378wxEvent::wxEvent(const wxEvent& src)
a34ef99b 379 : wxObject(src)
e6a6feba
GD
380 , m_eventObject(src.m_eventObject)
381 , m_eventType(src.m_eventType)
382 , m_timeStamp(src.m_timeStamp)
383 , m_id(src.m_id)
384 , m_callbackUserData(src.m_callbackUserData)
6fd5903a 385 , m_propagationLevel(src.m_propagationLevel)
e6a6feba
GD
386 , m_skipped(src.m_skipped)
387 , m_isCommandEvent(src.m_isCommandEvent)
29de6f40 388 , m_wasProcessed(false)
a737331d 389{
a737331d
GL
390}
391
0e097789
VZ
392wxEvent& wxEvent::operator=(const wxEvent& src)
393{
394 wxObject::operator=(src);
395
396 m_eventObject = src.m_eventObject;
397 m_eventType = src.m_eventType;
398 m_timeStamp = src.m_timeStamp;
399 m_id = src.m_id;
400 m_callbackUserData = src.m_callbackUserData;
401 m_propagationLevel = src.m_propagationLevel;
402 m_skipped = src.m_skipped;
403 m_isCommandEvent = src.m_isCommandEvent;
404
29de6f40
VZ
405 // don't change m_wasProcessed
406
0e097789
VZ
407 return *this;
408}
409
3ed2104c
VZ
410#endif // wxUSE_BASE
411
e90c1d2a
VZ
412#if wxUSE_GUI
413
c801d85f
KB
414/*
415 * Command events
416 *
417 */
418
21eefb76
VZ
419#ifdef __VISUALC__
420 // 'this' : used in base member initializer list (for m_commandString)
421 #pragma warning(disable:4355)
422#endif
423
7798a18e 424wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId)
b5a98acd 425 : wxEvent(theId, commandType)
c801d85f 426{
3c778901
VZ
427 m_clientData = NULL;
428 m_clientObject = NULL;
0b746ba8
VZ
429 m_extraLong = 0;
430 m_commandInt = 0;
1c624631 431 m_isCommandEvent = true;
1648d51b
VZ
432
433 // the command events are propagated upwards by default
434 m_propagationLevel = wxEVENT_PROPAGATE_MAX;
c801d85f
KB
435}
436
21eefb76
VZ
437#ifdef __VISUALC__
438 #pragma warning(default:4355)
439#endif
440
ab1931f9
KH
441wxString wxCommandEvent::GetString() const
442{
cc6ceca7
VZ
443 if (m_eventType != wxEVT_COMMAND_TEXT_UPDATED || !m_eventObject)
444 {
ab1931f9 445 return m_cmdString;
cc6ceca7 446 }
ab1931f9
KH
447 else
448 {
89438177 449#if wxUSE_TEXTCTRL
ab1931f9 450 wxTextCtrl *txt = wxDynamicCast(m_eventObject, wxTextCtrl);
cc6ceca7 451 if ( txt )
ab1931f9
KH
452 return txt->GetValue();
453 else
89438177 454#endif // wxUSE_TEXTCTRL
ab1931f9
KH
455 return m_cmdString;
456 }
457}
458
0b30bb0b
JS
459/*
460 * UI update events
461 */
462
463#if wxUSE_LONGLONG
e39af974 464wxLongLong wxUpdateUIEvent::sm_lastUpdate = 0;
0b30bb0b
JS
465#endif
466
e39af974
JS
467long wxUpdateUIEvent::sm_updateInterval = 0;
468
469wxUpdateUIMode wxUpdateUIEvent::sm_updateMode = wxUPDATE_UI_PROCESS_ALL;
0b30bb0b
JS
470
471// Can we update?
a7bc03c9 472bool wxUpdateUIEvent::CanUpdate(wxWindowBase *win)
0b30bb0b 473{
e39af974
JS
474 // Don't update if we've switched global updating off
475 // and this window doesn't support updates.
476 if (win &&
477 (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED &&
478 ((win->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES) == 0)))
1c624631 479 return false;
b5a98acd 480
e39af974 481 if (sm_updateInterval == -1)
1c624631 482 return false;
534b127c
WS
483
484 if (sm_updateInterval == 0)
1c624631 485 return true;
534b127c 486
0b30bb0b 487#if wxUSE_STOPWATCH && wxUSE_LONGLONG
534b127c
WS
488 wxLongLong now = wxGetLocalTimeMillis();
489 if (now > (sm_lastUpdate + sm_updateInterval))
490 {
1c624631 491 return true;
0b30bb0b 492 }
534b127c 493
1c624631 494 return false;
534b127c
WS
495#else
496 // If we don't have wxStopWatch or wxLongLong, we
497 // should err on the safe side and update now anyway.
498 return true;
499#endif
0b30bb0b
JS
500}
501
502// Reset the update time to provide a delay until the next
503// time we should update
504void wxUpdateUIEvent::ResetUpdateTime()
505{
506#if wxUSE_STOPWATCH && wxUSE_LONGLONG
e39af974 507 if (sm_updateInterval > 0)
0b30bb0b
JS
508 {
509 wxLongLong now = wxGetLocalTimeMillis();
e39af974 510 if (now > (sm_lastUpdate + sm_updateInterval))
0b30bb0b 511 {
e39af974 512 sm_lastUpdate = now;
0b30bb0b
JS
513 }
514 }
515#endif
516}
517
c801d85f
KB
518/*
519 * Scroll events
520 */
521
0b746ba8
VZ
522wxScrollEvent::wxScrollEvent(wxEventType commandType,
523 int id,
524 int pos,
525 int orient)
e6a6feba 526 : wxCommandEvent(commandType, id)
c801d85f 527{
0b746ba8
VZ
528 m_extraLong = orient;
529 m_commandInt = pos;
c801d85f
KB
530}
531
d1367c3d
RR
532/*
533 * ScrollWin events
534 */
535
536wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType,
537 int pos,
538 int orient)
d1367c3d 539{
c5b42c87 540 m_eventType = commandType;
d1367c3d
RR
541 m_extraLong = orient;
542 m_commandInt = pos;
543}
544
c801d85f
KB
545/*
546 * Mouse events
547 *
548 */
549
7798a18e 550wxMouseEvent::wxMouseEvent(wxEventType commandType)
c801d85f 551{
0b746ba8 552 m_eventType = commandType;
8866abbb
VZ
553
554 m_x = 0;
555 m_y = 0;
556
1c624631 557 m_leftDown = false;
1c624631 558 m_middleDown = false;
8866abbb 559 m_rightDown = false;
01101e2d
VZ
560 m_aux1Down = false;
561 m_aux2Down = false;
8866abbb 562
8866abbb
VZ
563 m_clickCount = -1;
564
d2c52078
RD
565 m_wheelRotation = 0;
566 m_wheelDelta = 0;
567 m_linesPerAction = 0;
aea37008 568 m_wheelAxis = 0;
c801d85f
KB
569}
570
abcbaea7
VZ
571void wxMouseEvent::Assign(const wxMouseEvent& event)
572{
0e097789 573 wxEvent::operator=(event);
3232da9d
VZ
574
575 // Borland C++ 5.82 doesn't compile an explicit call to an implicitly
576 // defined operator=() so need to do it this way:
577 *static_cast<wxMouseState *>(this) = event;
92309201 578
abcbaea7
VZ
579 m_x = event.m_x;
580 m_y = event.m_y;
581
582 m_leftDown = event.m_leftDown;
583 m_middleDown = event.m_middleDown;
584 m_rightDown = event.m_rightDown;
01101e2d
VZ
585 m_aux1Down = event.m_aux1Down;
586 m_aux2Down = event.m_aux2Down;
abcbaea7 587
abcbaea7
VZ
588 m_wheelRotation = event.m_wheelRotation;
589 m_wheelDelta = event.m_wheelDelta;
590 m_linesPerAction = event.m_linesPerAction;
aea37008 591 m_wheelAxis = event.m_wheelAxis;
abcbaea7
VZ
592}
593
3e89999c 594// return true if was a button dclick event
c801d85f
KB
595bool wxMouseEvent::ButtonDClick(int but) const
596{
0b746ba8
VZ
597 switch (but)
598 {
3e89999c
VZ
599 default:
600 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
601 // fall through
602
603 case wxMOUSE_BTN_ANY:
01101e2d
VZ
604 return (LeftDClick() || MiddleDClick() || RightDClick() ||
605 Aux1DClick() || Aux2DClick());
3e89999c
VZ
606
607 case wxMOUSE_BTN_LEFT:
0b746ba8 608 return LeftDClick();
3e89999c
VZ
609
610 case wxMOUSE_BTN_MIDDLE:
0b746ba8 611 return MiddleDClick();
3e89999c
VZ
612
613 case wxMOUSE_BTN_RIGHT:
0b746ba8 614 return RightDClick();
01101e2d
VZ
615
616 case wxMOUSE_BTN_AUX1:
617 return Aux1DClick();
618
619 case wxMOUSE_BTN_AUX2:
620 return Aux2DClick();
0b746ba8 621 }
c801d85f
KB
622}
623
3e89999c 624// return true if was a button down event
c801d85f
KB
625bool wxMouseEvent::ButtonDown(int but) const
626{
0b746ba8
VZ
627 switch (but)
628 {
3e89999c
VZ
629 default:
630 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
631 // fall through
632
633 case wxMOUSE_BTN_ANY:
01101e2d
VZ
634 return (LeftDown() || MiddleDown() || RightDown() ||
635 Aux1Down() || Aux2Down());
3e89999c
VZ
636
637 case wxMOUSE_BTN_LEFT:
0b746ba8 638 return LeftDown();
3e89999c
VZ
639
640 case wxMOUSE_BTN_MIDDLE:
0b746ba8 641 return MiddleDown();
3e89999c
VZ
642
643 case wxMOUSE_BTN_RIGHT:
0b746ba8 644 return RightDown();
01101e2d
VZ
645
646 case wxMOUSE_BTN_AUX1:
647 return Aux1Down();
648
649 case wxMOUSE_BTN_AUX2:
650 return Aux2Down();
0b746ba8 651 }
c801d85f
KB
652}
653
3e89999c 654// return true if was a button up event
c801d85f
KB
655bool wxMouseEvent::ButtonUp(int but) const
656{
1e6feb95
VZ
657 switch (but)
658 {
3e89999c
VZ
659 default:
660 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
661 // fall through
662
663 case wxMOUSE_BTN_ANY:
01101e2d
VZ
664 return (LeftUp() || MiddleUp() || RightUp() ||
665 Aux1Up() || Aux2Up());
3e89999c
VZ
666
667 case wxMOUSE_BTN_LEFT:
0b746ba8 668 return LeftUp();
3e89999c
VZ
669
670 case wxMOUSE_BTN_MIDDLE:
0b746ba8 671 return MiddleUp();
3e89999c
VZ
672
673 case wxMOUSE_BTN_RIGHT:
0b746ba8 674 return RightUp();
01101e2d
VZ
675
676 case wxMOUSE_BTN_AUX1:
677 return Aux1Up();
678
679 case wxMOUSE_BTN_AUX2:
680 return Aux2Up();
0b746ba8 681 }
c801d85f
KB
682}
683
3e89999c 684// return true if the given button is currently changing state
c801d85f
KB
685bool wxMouseEvent::Button(int but) const
686{
1e6feb95
VZ
687 switch (but)
688 {
0b746ba8 689 default:
223d09f6 690 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
3e89999c
VZ
691 // fall through
692
693 case wxMOUSE_BTN_ANY:
694 return ButtonUp(wxMOUSE_BTN_ANY) ||
695 ButtonDown(wxMOUSE_BTN_ANY) ||
696 ButtonDClick(wxMOUSE_BTN_ANY);
697
698 case wxMOUSE_BTN_LEFT:
699 return LeftDown() || LeftUp() || LeftDClick();
700
701 case wxMOUSE_BTN_MIDDLE:
702 return MiddleDown() || MiddleUp() || MiddleDClick();
703
704 case wxMOUSE_BTN_RIGHT:
705 return RightDown() || RightUp() || RightDClick();
01101e2d
VZ
706
707 case wxMOUSE_BTN_AUX1:
708 return Aux1Down() || Aux1Up() || Aux1DClick();
709
710 case wxMOUSE_BTN_AUX2:
711 return Aux2Down() || Aux2Up() || Aux2DClick();
0b746ba8 712 }
c801d85f
KB
713}
714
715bool wxMouseEvent::ButtonIsDown(int but) const
716{
1e6feb95
VZ
717 switch (but)
718 {
3e89999c
VZ
719 default:
720 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
721 // fall through
722
723 case wxMOUSE_BTN_ANY:
01101e2d 724 return LeftIsDown() || MiddleIsDown() || RightIsDown() || Aux1Down() || Aux2Down();
3e89999c
VZ
725
726 case wxMOUSE_BTN_LEFT:
0b746ba8 727 return LeftIsDown();
3e89999c
VZ
728
729 case wxMOUSE_BTN_MIDDLE:
0b746ba8 730 return MiddleIsDown();
3e89999c
VZ
731
732 case wxMOUSE_BTN_RIGHT:
0b746ba8 733 return RightIsDown();
01101e2d
VZ
734
735 case wxMOUSE_BTN_AUX1:
736 return Aux1IsDown();
737
738 case wxMOUSE_BTN_AUX2:
739 return Aux2IsDown();
0b746ba8 740 }
c801d85f
KB
741}
742
1e6feb95
VZ
743int wxMouseEvent::GetButton() const
744{
01101e2d 745 for ( int i = 1; i < wxMOUSE_BTN_MAX; i++ )
1e6feb95
VZ
746 {
747 if ( Button(i) )
748 {
749 return i;
750 }
751 }
752
3e89999c 753 return wxMOUSE_BTN_NONE;
1e6feb95
VZ
754}
755
c801d85f
KB
756// Find the logical position of the event given the DC
757wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const
758{
0757d27c
JS
759 wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y));
760 return pt;
c801d85f
KB
761}
762
763
764/*
8e72b8b5 765 * Keyboard event
c801d85f
KB
766 *
767 */
768
7798a18e 769wxKeyEvent::wxKeyEvent(wxEventType type)
c801d85f 770{
0b746ba8 771 m_eventType = type;
0b746ba8 772 m_keyCode = 0;
b0e813a0 773 m_scanCode = 0;
2b5f62a0
VZ
774#if wxUSE_UNICODE
775 m_uniChar = 0;
776#endif
c801d85f
KB
777}
778
92309201 779wxKeyEvent::wxKeyEvent(const wxKeyEvent& evt)
0e097789
VZ
780 : wxEvent(evt),
781 wxKeyboardState(evt)
2b5f62a0
VZ
782{
783 m_x = evt.m_x;
784 m_y = evt.m_y;
785
786 m_keyCode = evt.m_keyCode;
787
2b5f62a0
VZ
788 m_scanCode = evt.m_scanCode;
789 m_rawCode = evt.m_rawCode;
790 m_rawFlags = evt.m_rawFlags;
92309201 791
2b5f62a0
VZ
792#if wxUSE_UNICODE
793 m_uniChar = evt.m_uniChar;
794#endif
795}
12a3f227 796
42e69d6b 797wxWindowCreateEvent::wxWindowCreateEvent(wxWindow *win)
42e69d6b 798{
cfe17b74 799 SetEventType(wxEVT_CREATE);
42e69d6b
VZ
800 SetEventObject(win);
801}
802
803wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow *win)
42e69d6b 804{
cfe17b74 805 SetEventType(wxEVT_DESTROY);
42e69d6b
VZ
806 SetEventObject(win);
807}
808
456bc6d9
VZ
809wxChildFocusEvent::wxChildFocusEvent(wxWindow *win)
810 : wxCommandEvent(wxEVT_CHILD_FOCUS)
811{
812 SetEventObject(win);
813}
814
b107e8d5
VZ
815// ----------------------------------------------------------------------------
816// wxHelpEvent
817// ----------------------------------------------------------------------------
818
819/* static */
820wxHelpEvent::Origin wxHelpEvent::GuessOrigin(Origin origin)
821{
822 if ( origin == Origin_Unknown )
823 {
824 // assume that the event comes from the help button if it's not from
825 // keyboard and that pressing F1 always results in the help event
826 origin = wxGetKeyState(WXK_F1) ? Origin_Keyboard : Origin_HelpButton;
827 }
828
829 return origin;
830}
831
dd070522
VZ
832#endif // wxUSE_GUI
833
9416681d
VS
834
835#if wxUSE_BASE
836
b5a98acd
VZ
837// ----------------------------------------------------------------------------
838// wxEventHashTable
839// ----------------------------------------------------------------------------
840
afa039f9
JS
841static const int EVENT_TYPE_TABLE_INIT_SIZE = 31; // Not too big not too small...
842
843wxEventHashTable* wxEventHashTable::sm_first = NULL;
b5a98acd
VZ
844
845wxEventHashTable::wxEventHashTable(const wxEventTable &table)
846 : m_table(table),
1c624631 847 m_rebuildHash(true)
b5a98acd
VZ
848{
849 AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE);
1a18887b 850
afa039f9
JS
851 m_next = sm_first;
852 if (m_next)
853 m_next->m_previous = this;
854 sm_first = this;
b5a98acd
VZ
855}
856
857wxEventHashTable::~wxEventHashTable()
afa039f9
JS
858{
859 if (m_next)
860 m_next->m_previous = m_previous;
861 if (m_previous)
862 m_previous->m_next = m_next;
863 if (sm_first == this)
864 sm_first = m_next;
1a18887b 865
afa039f9
JS
866 Clear();
867}
868
869void wxEventHashTable::Clear()
b5a98acd 870{
a0826b11 871 for ( size_t i = 0; i < m_size; i++ )
b5a98acd
VZ
872 {
873 EventTypeTablePointer eTTnode = m_eventTypeTable[i];
a0826b11 874 delete eTTnode;
b5a98acd
VZ
875 }
876
a0826b11 877 delete[] m_eventTypeTable;
afa039f9 878 m_eventTypeTable = NULL;
a0826b11 879
afa039f9
JS
880 m_size = 0;
881}
882
aa767a45 883#if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
a0826b11 884
afa039f9
JS
885// Clear all tables
886void wxEventHashTable::ClearAll()
887{
888 wxEventHashTable* table = sm_first;
889 while (table)
890 {
891 table->Clear();
892 table = table->m_next;
893 }
b5a98acd
VZ
894}
895
a0826b11
VZ
896#endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING
897
b5a98acd
VZ
898bool wxEventHashTable::HandleEvent(wxEvent &event, wxEvtHandler *self)
899{
900 if (m_rebuildHash)
901 {
902 InitHashTable();
1c624631 903 m_rebuildHash = false;
b5a98acd 904 }
1a18887b 905
afa039f9 906 if (!m_eventTypeTable)
1a18887b 907 return false;
b5a98acd
VZ
908
909 // Find all entries for the given event type.
910 wxEventType eventType = event.GetEventType();
911 const EventTypeTablePointer eTTnode = m_eventTypeTable[eventType % m_size];
912 if (eTTnode && eTTnode->eventType == eventType)
913 {
914 // Now start the search for an event handler
915 // that can handle an event with the given ID.
1c624631
VZ
916 const wxEventTableEntryPointerArray&
917 eventEntryTable = eTTnode->eventEntryTable;
b5a98acd 918
1c624631
VZ
919 const size_t count = eventEntryTable.GetCount();
920 for (size_t n = 0; n < count; n++)
b5a98acd 921 {
03f3617b
VZ
922 const wxEventTableEntry& entry = *eventEntryTable[n];
923 if ( wxEvtHandler::ProcessEventIfMatchesId(entry, self, event) )
1c624631 924 return true;
b5a98acd 925 }
b5a98acd
VZ
926 }
927
1c624631 928 return false;
b5a98acd
VZ
929}
930
931void wxEventHashTable::InitHashTable()
932{
933 // Loop over the event tables and all its base tables.
934 const wxEventTable *table = &m_table;
935 while (table)
936 {
937 // Retrieve all valid event handler entries
938 const wxEventTableEntry *entry = table->entries;
939 while (entry->m_fn != 0)
940 {
941 // Add the event entry in the Hash.
942 AddEntry(*entry);
943
944 entry++;
945 }
946
947 table = table->baseTable;
948 }
949
950 // Lets free some memory.
951 size_t i;
952 for(i = 0; i < m_size; i++)
953 {
954 EventTypeTablePointer eTTnode = m_eventTypeTable[i];
955 if (eTTnode)
956 {
957 eTTnode->eventEntryTable.Shrink();
958 }
959 }
960}
961
962void wxEventHashTable::AddEntry(const wxEventTableEntry &entry)
963{
afa039f9
JS
964 // This might happen 'accidentally' as the app is exiting
965 if (!m_eventTypeTable)
966 return;
1a18887b 967
b5a98acd
VZ
968 EventTypeTablePointer *peTTnode = &m_eventTypeTable[entry.m_eventType % m_size];
969 EventTypeTablePointer eTTnode = *peTTnode;
970
971 if (eTTnode)
972 {
973 if (eTTnode->eventType != entry.m_eventType)
974 {
975 // Resize the table!
976 GrowEventTypeTable();
977 // Try again to add it.
978 AddEntry(entry);
979 return;
980 }
981 }
982 else
983 {
984 eTTnode = new EventTypeTable;
985 eTTnode->eventType = entry.m_eventType;
986 *peTTnode = eTTnode;
987 }
988
989 // Fill all hash entries between entry.m_id and entry.m_lastId...
990 eTTnode->eventEntryTable.Add(&entry);
991}
992
993void wxEventHashTable::AllocEventTypeTable(size_t size)
994{
995 m_eventTypeTable = new EventTypeTablePointer[size];
996 memset((void *)m_eventTypeTable, 0, sizeof(EventTypeTablePointer)*size);
997 m_size = size;
998}
999
1000void wxEventHashTable::GrowEventTypeTable()
1001{
1002 size_t oldSize = m_size;
1003 EventTypeTablePointer *oldEventTypeTable = m_eventTypeTable;
1004
1005 // TODO: Search the most optimal grow sequence
1006 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize*2+1);
1007
1008 for ( size_t i = 0; i < oldSize; /* */ )
1009 {
1010 EventTypeTablePointer eTToldNode = oldEventTypeTable[i];
1011 if (eTToldNode)
1012 {
1013 EventTypeTablePointer *peTTnode = &m_eventTypeTable[eTToldNode->eventType % m_size];
1014 EventTypeTablePointer eTTnode = *peTTnode;
1015
1016 // Check for collision, we don't want any.
1017 if (eTTnode)
1018 {
1019 GrowEventTypeTable();
1020 continue; // Don't increment the counter,
1021 // as we still need to add this element.
1022 }
1023 else
1024 {
1025 // Get the old value and put it in the new table.
1026 *peTTnode = oldEventTypeTable[i];
1027 }
1028 }
1029
1030 i++;
1031 }
1032
1033 delete[] oldEventTypeTable;
1034}
1035
456bc6d9
VZ
1036// ----------------------------------------------------------------------------
1037// wxEvtHandler
1038// ----------------------------------------------------------------------------
1039
c801d85f
KB
1040/*
1041 * Event handler
1042 */
1043
0b746ba8 1044wxEvtHandler::wxEvtHandler()
c801d85f 1045{
3c778901
VZ
1046 m_nextHandler = NULL;
1047 m_previousHandler = NULL;
1c624631 1048 m_enabled = true;
3c778901
VZ
1049 m_dynamicEvents = NULL;
1050 m_pendingEvents = NULL;
aa767a45 1051
b88c44e7
RD
1052 // no client data (yet)
1053 m_clientData = NULL;
1054 m_clientDataType = wxClientData_None;
c801d85f
KB
1055}
1056
0b746ba8 1057wxEvtHandler::~wxEvtHandler()
c801d85f 1058{
7f853dd0 1059 Unlink();
0b746ba8
VZ
1060
1061 if (m_dynamicEvents)
fe71f65c 1062 {
3c448b2e
VZ
1063 for ( wxList::iterator it = m_dynamicEvents->begin(),
1064 end = m_dynamicEvents->end();
1065 it != end;
1066 ++it )
0b746ba8 1067 {
df5168c4 1068 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)*it;
2e4df4bf 1069
cc6ceca7 1070 // Remove ourselves from sink destructor notifications
3c778901 1071 // (this has usually been done, in wxTrackable destructor)
f3ff831f 1072 wxEvtHandler *eventSink = entry->m_fn->GetEvtHandler();
cc6ceca7 1073 if ( eventSink )
2ef989c9 1074 {
cc6ceca7
VZ
1075 wxEventConnectionRef * const
1076 evtConnRef = FindRefInTrackerList(eventSink);
1077 if ( evtConnRef )
1078 {
1079 eventSink->RemoveNode(evtConnRef);
1080 delete evtConnRef;
1081 }
2ef989c9 1082 }
cc6ceca7 1083
3c778901 1084 delete entry->m_callbackUserData;
0b746ba8 1085 delete entry;
0b746ba8
VZ
1086 }
1087 delete m_dynamicEvents;
1088 };
7214297d 1089
5875d39c
VZ
1090 if (m_pendingEvents)
1091 m_pendingEvents->DeleteContents(true);
7ce2fb71 1092 delete m_pendingEvents;
7214297d 1093
079f4130
FM
1094 // Remove us from wxHandlersWithPendingEvents if necessary.
1095 if ( wxHandlersWithPendingEvents )
5d9d1b88 1096 {
364ab6cc 1097#if wxUSE_THREADS
079f4130
FM
1098 if (wxHandlersWithPendingEventsLocker)
1099 wxENTER_CRIT_SECT(*wxHandlersWithPendingEventsLocker);
364ab6cc 1100#endif
19c4d916 1101
079f4130 1102 if ( wxHandlersWithPendingEvents->DeleteObject(this) )
19c4d916
VZ
1103 {
1104 // check that we were present only once in the list
079f4130
FM
1105 wxASSERT_MSG( !wxHandlersWithPendingEvents->Find(this),
1106 "Handler occurs twice in wxHandlersWithPendingEvents list" );
19c4d916
VZ
1107 }
1108 //else: we weren't in this list at all, it's ok
1109
d48b06bd
FM
1110 if ( wxHandlersWithPendingDelayedEvents->DeleteObject(this) )
1111 {
1112 // check that we were present only once in the list
1113 wxASSERT_MSG( !wxHandlersWithPendingDelayedEvents->Find(this),
1114 "Handler occurs twice in wxHandlersWithPendingDelayedEvents list" );
1115 }
1116 //else: we weren't in this list at all, it's ok
1117
364ab6cc 1118#if wxUSE_THREADS
079f4130
FM
1119 if (wxHandlersWithPendingEventsLocker)
1120 wxLEAVE_CRIT_SECT(*wxHandlersWithPendingEventsLocker);
364ab6cc 1121#endif
083f7497 1122 }
b88c44e7
RD
1123
1124 // we only delete object data, not untyped
1125 if ( m_clientDataType == wxClientData_Object )
1126 delete m_clientObject;
c801d85f
KB
1127}
1128
7f853dd0
FM
1129void wxEvtHandler::Unlink()
1130{
1131 // this event handler must take itself out of the chain of handlers:
1132
1133 if (m_previousHandler)
1134 m_previousHandler->SetNextHandler(m_nextHandler);
1135
1136 if (m_nextHandler)
1137 m_nextHandler->SetPreviousHandler(m_previousHandler);
1138
1139 m_nextHandler = NULL;
1140 m_previousHandler = NULL;
1141}
1142
1143bool wxEvtHandler::IsUnlinked() const
1144{
1145 return m_previousHandler == NULL &&
1146 m_nextHandler == NULL;
1147}
1148
7214297d 1149#if wxUSE_THREADS
aadbdf11 1150
76bfdc9a 1151bool wxEvtHandler::ProcessThreadEvent(const wxEvent& event)
7214297d 1152{
7214297d 1153 // check that we are really in a child thread
8e193f38
VZ
1154 wxASSERT_MSG( !wxThread::IsMain(),
1155 wxT("use ProcessEvent() in main thread") );
1156
1157 AddPendingEvent(event);
7214297d 1158
1c624631 1159 return true;
8e193f38
VZ
1160}
1161
1162#endif // wxUSE_THREADS
1163
c3f94162 1164void wxEvtHandler::QueueEvent(wxEvent *event)
8e193f38 1165{
c3f94162 1166 wxCHECK_RET( event, "NULL event can't be posted" );
7a5c8ac4 1167
c3f94162 1168 // 1) Add this event to our list of pending events
8ebec7dc 1169 wxENTER_CRIT_SECT( m_pendingEventsLock );
16c1f79c 1170
8e193f38
VZ
1171 if ( !m_pendingEvents )
1172 m_pendingEvents = new wxList;
7214297d 1173
c3f94162 1174 m_pendingEvents->Append(event);
7214297d 1175
16c1f79c
RR
1176 // 2) Add this event handler to list of event handlers that
1177 // have pending events.
cfe17b74 1178
079f4130 1179 wxENTER_CRIT_SECT(*wxHandlersWithPendingEventsLocker);
72cdf4c9 1180
079f4130
FM
1181 if ( !wxHandlersWithPendingEvents )
1182 wxHandlersWithPendingEvents = new wxList;
1183 if ( !wxHandlersWithPendingEvents->Find(this) )
1184 wxHandlersWithPendingEvents->Append(this);
72cdf4c9 1185
079f4130 1186 wxLEAVE_CRIT_SECT(*wxHandlersWithPendingEventsLocker);
6164f93c 1187
a715b990
VZ
1188 // only release m_pendingEventsLock now because otherwise there is a race
1189 // condition as described in the ticket #9093: we could process the event
1190 // just added to m_pendingEvents in our ProcessPendingEvents() below before
079f4130 1191 // we had time to append this pointer to wxHandlersWithPendingEvents list; thus
a715b990
VZ
1192 // breaking the invariant that a handler should be in the list iff it has
1193 // any pending events to process
1194 wxLEAVE_CRIT_SECT( m_pendingEventsLock );
1195
90e572f1 1196 // 3) Inform the system that new pending events are somewhere,
16c1f79c 1197 // and that these should be processed in idle time.
bf9e3e73 1198 wxWakeUpIdle();
7214297d
GL
1199}
1200
1201void wxEvtHandler::ProcessPendingEvents()
1202{
d48b06bd
FM
1203 // we need to process only a single pending event in this call because
1204 // each call to ProcessEvent() could result in the destruction of this
1205 // same event handler (see the comment at the end of this function)
1206
8ebec7dc 1207 wxENTER_CRIT_SECT( m_pendingEventsLock );
8e193f38 1208
7ce2fb71
VZ
1209 // this method is only called by wxApp if this handler does have
1210 // pending events
1211 wxCHECK_RET( m_pendingEvents && !m_pendingEvents->IsEmpty(),
1212 "should have pending events if called" );
5fa150e2 1213
19c4d916 1214 wxList::compatibility_iterator node = m_pendingEvents->GetFirst();
d48b06bd
FM
1215 wxEvent* pEvent = static_cast<wxEvent *>(node->GetData());
1216
1217 // find the first event which can be processed now:
1218 if (wxTheApp && wxTheApp->IsYielding())
1219 {
1220 while (node && pEvent && !wxTheApp->IsEventAllowedInsideYield(pEvent->GetEventCategory()))
1221 {
1222 node = node->GetNext();
1223 pEvent = node ? static_cast<wxEvent *>(node->GetData()) : NULL;
1224 }
1225
1226 if (!node)
1227 {
1228 // all our events are NOT processable now... signal this:
1229#if wxUSE_THREADS
1230 if (wxHandlersWithPendingEventsLocker)
1231 wxENTER_CRIT_SECT(*wxHandlersWithPendingEventsLocker);
1232#endif
1233 // move us from the list of handlers with processable pending events
1234 // to the list of handlers with pending events which needs to be processed later
1235 wxHandlersWithPendingEvents->DeleteObject(this);
1236 if ( !wxHandlersWithPendingDelayedEvents->Find(this) )
1237 wxHandlersWithPendingDelayedEvents->Append(this);
1238#if wxUSE_THREADS
1239 if (wxHandlersWithPendingEventsLocker)
1240 wxLEAVE_CRIT_SECT(*wxHandlersWithPendingEventsLocker);
1241#endif
1242 wxLEAVE_CRIT_SECT( m_pendingEventsLock );
1243
1244 return;
1245 }
1246 }
1247
1248 wxEventPtr event(pEvent);
5875d39c 1249
19c4d916
VZ
1250 // it's important we remove event from list before processing it, else a
1251 // nested event loop, for example from a modal dialog, might process the
1252 // same event again.
1253 m_pendingEvents->Erase(node);
7b0d5c59 1254
19c4d916
VZ
1255 // if there are no more pending events left, we don't need to stay in this
1256 // list
1257 if ( m_pendingEvents->IsEmpty() )
1512f0f7
VZ
1258 {
1259#if wxUSE_THREADS
079f4130
FM
1260 if (wxHandlersWithPendingEventsLocker)
1261 wxENTER_CRIT_SECT(*wxHandlersWithPendingEventsLocker);
1512f0f7 1262#endif
079f4130 1263 wxHandlersWithPendingEvents->DeleteObject(this);
1512f0f7 1264#if wxUSE_THREADS
079f4130
FM
1265 if (wxHandlersWithPendingEventsLocker)
1266 wxLEAVE_CRIT_SECT(*wxHandlersWithPendingEventsLocker);
1512f0f7
VZ
1267#endif
1268 }
5fa150e2 1269
8ebec7dc 1270 wxLEAVE_CRIT_SECT( m_pendingEventsLock );
7b0d5c59 1271
19c4d916 1272 ProcessEvent(*event);
cfe17b74 1273
19c4d916
VZ
1274 // careful: this object could have been deleted by the event handler
1275 // executed by the above ProcessEvent() call, so we can't access any fields
1276 // of this object any more
7214297d 1277}
7214297d 1278
c801d85f
KB
1279/*
1280 * Event table stuff
1281 */
1c624631 1282/* static */ bool
03f3617b
VZ
1283wxEvtHandler::ProcessEventIfMatchesId(const wxEventTableEntryBase& entry,
1284 wxEvtHandler *handler,
1285 wxEvent& event)
1c624631
VZ
1286{
1287 int tableId1 = entry.m_id,
1288 tableId2 = entry.m_lastId;
1289
1290 // match only if the event type is the same and the id is either -1 in
1291 // the event table (meaning "any") or the event id matches the id
1292 // specified in the event table either exactly or by falling into
1293 // range between first and last
1a18887b
WS
1294 if ((tableId1 == wxID_ANY) ||
1295 (tableId2 == wxID_ANY && tableId1 == event.GetId()) ||
1296 (tableId2 != wxID_ANY &&
1c624631
VZ
1297 (event.GetId() >= tableId1 && event.GetId() <= tableId2)))
1298 {
1299 event.Skip(false);
1300 event.m_callbackUserData = entry.m_callbackUserData;
1301
1302#if wxUSE_EXCEPTIONS
1303 if ( wxTheApp )
1304 {
1305 // call the handler via wxApp method which allows the user to catch
1306 // any exceptions which may be thrown by any handler in the program
1307 // in one place
3c778901 1308 wxTheApp->CallEventHandler(handler, *entry.m_fn, event);
1c624631
VZ
1309 }
1310 else
8bd2a804 1311#endif // wxUSE_EXCEPTIONS
1c624631 1312 {
3c778901 1313 (*entry.m_fn)(handler, event);
1c624631 1314 }
1c624631
VZ
1315
1316 if (!event.GetSkipped())
1317 return true;
1318 }
1319
1320 return false;
1321}
c801d85f 1322
4caf847c 1323bool wxEvtHandler::TryParent(wxEvent& event)
c801d85f 1324{
358e9f2f
VZ
1325 if ( GetNextHandler() )
1326 {
1327 // the next handler will pass it to wxTheApp if it doesn't process it,
1328 // so return from here to avoid doing it again
1329 return GetNextHandler()->TryParent(event);
1330 }
1331
4caf847c 1332 if ( wxTheApp && (this != wxTheApp) )
9154d8cf 1333 {
4caf847c
VZ
1334 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1335 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1336 // processed appropriately via SearchEventTable.
1337 if ( event.GetEventType() != wxEVT_IDLE )
1338 {
1339 if ( wxTheApp->ProcessEvent(event) )
1c624631 1340 return true;
4caf847c 1341 }
9154d8cf
VZ
1342 }
1343
1c624631 1344 return false;
4caf847c 1345}
0b746ba8 1346
4caf847c
VZ
1347bool wxEvtHandler::ProcessEvent(wxEvent& event)
1348{
9154d8cf 1349 // allow the application to hook into event processing
29de6f40
VZ
1350 //
1351 // note that we should only do it if we're the first event handler called
1352 // to avoid calling FilterEvent() multiple times as the event goes through
1353 // the event handler chain and possibly upwards the window hierarchy
1354 if ( !event.WasProcessed() )
9154d8cf 1355 {
29de6f40 1356 if ( wxTheApp )
9154d8cf 1357 {
d48b06bd
FM
1358/*
1359 CANNOT ENABLE: ProcessEvent() must always immediately process the event!
1360
1361 if (wxTheApp->IsYielding() &&
1362 !wxTheApp->IsEventAllowedInsideYield(event.GetEventCategory()))
1363 {
1364 wxEvent* queuedEv = event.Clone();
1365
1366 // queue this event rather than processing it now
1367 QueueEvent(queuedEv);
1368 // the wxWakeUpIdle call shouldn't probably be done
1369 // in this context (there's wxYield in the call stack)
1370
1371 return true;
1372 // it's not completely true that the event was processed;
1373 // but we cannot even say it was skipped or discarded...
1374 }
1375 //else: either we're not inside a wxYield() call or if we are,
1376 // we can process this event immediately.
1377*/
1378
29de6f40
VZ
1379 int rc = wxTheApp->FilterEvent(event);
1380 if ( rc != -1 )
1381 {
1382 wxASSERT_MSG( rc == 1 || rc == 0,
1383 "unexpected wxApp::FilterEvent return value" );
9154d8cf 1384
29de6f40
VZ
1385 return rc != 0;
1386 }
1387 //else: proceed normally
9154d8cf 1388 }
9154d8cf
VZ
1389 }
1390
25250d33
VZ
1391 if ( ProcessEventHere(event) )
1392 return true;
1393
29de6f40
VZ
1394 // pass the event to the next handler, notice that we shouldn't call
1395 // TryParent() even if it doesn't handle the event as the last handler in
1396 // the chain will do it
1397 if ( GetNextHandler() )
1398 return GetNextHandler()->ProcessEvent(event);
1399
25250d33 1400 // propagate the event upwards the window chain and/or to the application
c9c1faa4 1401 // object if it wasn't processed at this level
25250d33
VZ
1402 return TryParent(event);
1403}
1404
1405bool wxEvtHandler::ProcessEventHere(wxEvent& event)
1406{
29de6f40
VZ
1407 // If the event handler is disabled it doesn't process any events
1408 if ( !GetEvtHandlerEnabled() )
1409 return false;
4caf847c 1410
29de6f40
VZ
1411 // If we have a validator, it has higher priority than our own event
1412 // handlers
1413 if ( TryValidator(event) )
1414 return true;
0b746ba8 1415
29de6f40
VZ
1416 // Handle per-instance dynamic event tables first
1417 if ( m_dynamicEvents && SearchDynamicEventTable(event) )
1418 return true;
c801d85f 1419
29de6f40
VZ
1420 // Then static per-class event tables
1421 if ( GetEventHashTable().HandleEvent(event, this) )
25250d33 1422 return true;
c801d85f 1423
25250d33
VZ
1424 // We don't have a handler for this event.
1425 return false;
c801d85f
KB
1426}
1427
937013e0
VS
1428bool wxEvtHandler::SafelyProcessEvent(wxEvent& event)
1429{
1430#if wxUSE_EXCEPTIONS
1431 try
1432 {
1433#endif
1434 return ProcessEvent(event);
1435#if wxUSE_EXCEPTIONS
1436 }
1437 catch ( ... )
1438 {
1439 wxEventLoopBase *loop = wxEventLoopBase::GetActive();
1440 try
1441 {
1442 if ( !wxTheApp || !wxTheApp->OnExceptionInMainLoop() )
1443 {
1444 if ( loop )
1445 loop->Exit();
1446 }
1447 //else: continue running current event loop
1448
1449 return false;
1450 }
1451 catch ( ... )
1452 {
1453 // OnExceptionInMainLoop() threw, possibly rethrowing the same
1454 // exception again: very good, but we still need Exit() to
1455 // be called
1456 if ( loop )
1457 loop->Exit();
1458 throw;
1459 }
1460 }
1461#endif // wxUSE_EXCEPTIONS
1462}
1463
b5a98acd 1464
c801d85f
KB
1465bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
1466{
1c624631 1467 const wxEventType eventType = event.GetEventType();
68662769 1468 for ( int i = 0; table.entries[i].m_fn != 0; i++ )
c801d85f 1469 {
68662769 1470 const wxEventTableEntry& entry = table.entries[i];
68662769 1471 if ( eventType == entry.m_eventType )
0b746ba8 1472 {
03f3617b 1473 if ( ProcessEventIfMatchesId(entry, this, event) )
1c624631 1474 return true;
0b746ba8 1475 }
c801d85f 1476 }
68662769 1477
1c624631 1478 return false;
c801d85f 1479}
97d7bfb8 1480
f3ff831f
VZ
1481void wxEvtHandler::DoConnect(int id,
1482 int lastId,
1483 wxEventType eventType,
1484 wxEventFunctor *func,
1485 wxObject *userData)
fe71f65c 1486{
0b5eceb6 1487 wxDynamicEventTableEntry *entry =
3c778901 1488 new wxDynamicEventTableEntry(eventType, id, lastId, func, userData);
0b746ba8
VZ
1489
1490 if (!m_dynamicEvents)
1491 m_dynamicEvents = new wxList;
1492
92309201
RD
1493 // Insert at the front of the list so most recent additions are found first
1494 m_dynamicEvents->Insert( (wxObject*) entry );
cc6ceca7
VZ
1495
1496 // Make sure we get to know when a sink is destroyed
f3ff831f 1497 wxEvtHandler *eventSink = func->GetEvtHandler();
886274c6 1498 if ( eventSink && eventSink != this )
2ef989c9 1499 {
cc6ceca7
VZ
1500 wxEventConnectionRef *evtConnRef = FindRefInTrackerList(eventSink);
1501 if ( evtConnRef )
1502 evtConnRef->IncRef( );
2ef989c9 1503 else
e822d1bd 1504 new wxEventConnectionRef(this, eventSink);
2ef989c9 1505 }
fe71f65c 1506}
97d7bfb8 1507
3c778901 1508bool
f3ff831f
VZ
1509wxEvtHandler::DoDisconnect(int id,
1510 int lastId,
1511 wxEventType eventType,
1512 const wxEventFunctor& func,
1513 wxObject *userData)
97d7bfb8
RR
1514{
1515 if (!m_dynamicEvents)
1c624631 1516 return false;
cfe17b74 1517
2ef989c9 1518 // Remove connection from tracker node (wxEventConnectionRef)
f3ff831f 1519 wxEvtHandler *eventSink = func.GetEvtHandler();
886274c6 1520 if ( eventSink && eventSink != this )
2ef989c9 1521 {
cc6ceca7
VZ
1522 wxEventConnectionRef *evtConnRef = FindRefInTrackerList(eventSink);
1523 if ( evtConnRef )
1524 evtConnRef->DecRef();
2ef989c9
RR
1525 }
1526
df5168c4 1527 wxList::compatibility_iterator node = m_dynamicEvents->GetFirst();
97d7bfb8
RR
1528 while (node)
1529 {
ad684023 1530 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
2e4df4bf 1531
97d7bfb8 1532 if ((entry->m_id == id) &&
1a18887b 1533 ((entry->m_lastId == lastId) || (lastId == wxID_ANY)) &&
97d7bfb8 1534 ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) &&
03f3617b 1535 entry->m_fn->Matches(func) &&
3c778901 1536 ((entry->m_callbackUserData == userData) || !userData))
97d7bfb8 1537 {
3c778901 1538 delete entry->m_callbackUserData;
df5168c4 1539 m_dynamicEvents->Erase( node );
97d7bfb8 1540 delete entry;
1c624631 1541 return true;
97d7bfb8 1542 }
b1d4dd7a 1543 node = node->GetNext();
97d7bfb8 1544 }
1c624631 1545 return false;
97d7bfb8 1546}
fe71f65c
RR
1547
1548bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
1549{
1c624631 1550 wxCHECK_MSG( m_dynamicEvents, false,
223d09f6 1551 wxT("caller should check that we have dynamic events") );
0b746ba8 1552
df5168c4 1553 wxList::compatibility_iterator node = m_dynamicEvents->GetFirst();
0b746ba8 1554 while (node)
fe71f65c 1555 {
1c624631 1556 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
0b746ba8 1557
7fce89b9
VZ
1558 // get next node before (maybe) calling the event handler as it could
1559 // call Disconnect() invalidating the current node
1560 node = node->GetNext();
1561
03f3617b 1562 if ( event.GetEventType() == entry->m_eventType )
0b746ba8 1563 {
f3ff831f 1564 wxEvtHandler *handler = entry->m_fn->GetEvtHandler();
03f3617b
VZ
1565 if ( !handler )
1566 handler = this;
1567 if ( ProcessEventIfMatchesId(*entry, handler, event) )
1c624631 1568 return true;
0b746ba8 1569 }
7b678698 1570 }
1c624631
VZ
1571
1572 return false;
4115960d 1573}
fe71f65c 1574
b88c44e7
RD
1575void wxEvtHandler::DoSetClientObject( wxClientData *data )
1576{
1577 wxASSERT_MSG( m_clientDataType != wxClientData_Void,
1578 wxT("can't have both object and void client data") );
1579
1580 if ( m_clientObject )
1581 delete m_clientObject;
1582
1583 m_clientObject = data;
1584 m_clientDataType = wxClientData_Object;
1585}
1586
1587wxClientData *wxEvtHandler::DoGetClientObject() const
1588{
1589 // it's not an error to call GetClientObject() on a window which doesn't
1590 // have client data at all - NULL will be returned
1591 wxASSERT_MSG( m_clientDataType != wxClientData_Void,
1592 wxT("this window doesn't have object client data") );
1593
1594 return m_clientObject;
1595}
1596
1597void wxEvtHandler::DoSetClientData( void *data )
1598{
1599 wxASSERT_MSG( m_clientDataType != wxClientData_Object,
1600 wxT("can't have both object and void client data") );
1601
1602 m_clientData = data;
1603 m_clientDataType = wxClientData_Void;
1604}
1605
1606void *wxEvtHandler::DoGetClientData() const
1607{
1608 // it's not an error to call GetClientData() on a window which doesn't have
1609 // client data at all - NULL will be returned
1610 wxASSERT_MSG( m_clientDataType != wxClientData_Object,
1611 wxT("this window doesn't have void client data") );
1612
1613 return m_clientData;
1614}
1615
cc6ceca7
VZ
1616// A helper to find an wxEventConnectionRef object
1617wxEventConnectionRef *
1618wxEvtHandler::FindRefInTrackerList(wxEvtHandler *eventSink)
2ef989c9 1619{
cc6ceca7 1620 for ( wxTrackerNode *node = eventSink->GetFirst(); node; node = node->m_nxt )
2ef989c9 1621 {
cc6ceca7
VZ
1622 // we only want wxEventConnectionRef nodes here
1623 wxEventConnectionRef *evtConnRef = node->ToEventConnection();
1624 if ( evtConnRef && evtConnRef->m_src == this )
2ef989c9 1625 {
cc6ceca7
VZ
1626 wxASSERT( evtConnRef->m_sink==eventSink );
1627 return evtConnRef;
2ef989c9
RR
1628 }
1629 }
cc6ceca7 1630
2ef989c9
RR
1631 return NULL;
1632}
1633
1634void wxEvtHandler::OnSinkDestroyed( wxEvtHandler *sink )
1635{
1636 wxASSERT(m_dynamicEvents);
cc6ceca7 1637
2ef989c9
RR
1638 // remove all connections with this sink
1639 wxList::compatibility_iterator node = m_dynamicEvents->GetFirst(), node_nxt;
1640 while (node)
1641 {
1642 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
1643 node_nxt = node->GetNext();
cc6ceca7 1644
f3ff831f 1645 if ( entry->m_fn->GetEvtHandler() == sink )
2ef989c9 1646 {
3c778901 1647 delete entry->m_callbackUserData;
2ef989c9
RR
1648 m_dynamicEvents->Erase( node );
1649 delete entry;
1650 }
1651 node = node_nxt;
1652 }
1653}
1654
4caf847c
VZ
1655#endif // wxUSE_BASE
1656
e90c1d2a
VZ
1657#if wxUSE_GUI
1658
e702ff0f
JS
1659// Find a window with the focus, that is also a descendant of the given window.
1660// This is used to determine the window to initially send commands to.
1661wxWindow* wxFindFocusDescendant(wxWindow* ancestor)
1662{
1663 // Process events starting with the window with the focus, if any.
1664 wxWindow* focusWin = wxWindow::FindFocus();
1665 wxWindow* win = focusWin;
1666
1667 // Check if this is a descendant of this frame.
1668 // If not, win will be set to NULL.
1669 while (win)
1670 {
1671 if (win == ancestor)
1672 break;
1673 else
1674 win = win->GetParent();
1675 }
3c778901
VZ
1676 if (win == NULL)
1677 focusWin = NULL;
e702ff0f
JS
1678
1679 return focusWin;
1680}
1681
c4fa5aa7
VZ
1682// ----------------------------------------------------------------------------
1683// wxEventBlocker
1684// ----------------------------------------------------------------------------
1685
1686wxEventBlocker::wxEventBlocker(wxWindow *win, wxEventType type)
1687{
1688 wxCHECK_RET(win, wxT("Null window given to wxEventBlocker"));
1689
1690 m_window = win;
1691
1692 Block(type);
1693 m_window->PushEventHandler(this);
1694}
1695
1696wxEventBlocker::~wxEventBlocker()
1697{
1698 wxEvtHandler *popped = m_window->PopEventHandler(false);
aa767a45 1699 wxCHECK_RET(popped == this,
c4fa5aa7
VZ
1700 wxT("Don't push other event handlers into a window managed by wxEventBlocker!"));
1701}
1702
1703bool wxEventBlocker::ProcessEvent(wxEvent& event)
1704{
1705 // should this event be blocked?
1706 for ( size_t i = 0; i < m_eventsToBlock.size(); i++ )
1707 {
1708 wxEventType t = (wxEventType)m_eventsToBlock[i];
1709 if ( t == wxEVT_ANY || t == event.GetEventType() )
1710 return true; // yes, it should: mark this event as processed
1711 }
1712
1713 return false;
1714}
1715
e90c1d2a 1716#endif // wxUSE_GUI
3c778901 1717