1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/event.cpp
3 // Purpose: Event classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/evtloop.h"
34 #include "wx/stopwatch.h"
35 #include "wx/module.h"
38 #include "wx/window.h"
39 #include "wx/control.h"
41 #include "wx/spinbutt.h"
42 #include "wx/textctrl.h"
43 #include "wx/validate.h"
47 #include "wx/thread.h"
50 #include "wx/scopedptr.h"
52 wxDECLARE_SCOPED_PTR(wxEvent
, wxEventPtr
)
53 wxDEFINE_SCOPED_PTR(wxEvent
, wxEventPtr
)
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
61 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler
, wxObject
)
62 IMPLEMENT_ABSTRACT_CLASS(wxEvent
, wxObject
)
63 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent
, wxEvent
)
67 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent
, wxEvent
)
68 IMPLEMENT_DYNAMIC_CLASS(wxThreadEvent
, wxCommandEvent
)
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
)
76 IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent
, wxEvent
)
77 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent
, wxEvent
)
78 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent
, wxEvent
)
79 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent
, wxEvent
)
80 IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent
, wxCommandEvent
)
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
)
90 IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent
, wxEvent
)
91 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent
, wxEvent
)
92 IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent
, wxEvent
)
93 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent
, wxCommandEvent
)
94 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent
, wxEvent
)
95 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent
, wxEvent
)
96 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent
, wxEvent
)
97 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent
, wxEvent
)
98 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent
, wxEvent
)
99 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent
, wxCommandEvent
)
100 IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent
, wxCommandEvent
)
101 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent
, wxEvent
)
102 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureLostEvent
, wxEvent
)
103 IMPLEMENT_DYNAMIC_CLASS(wxClipboardTextEvent
, wxCommandEvent
)
108 const wxEventTable
*wxEvtHandler::GetEventTable() const
109 { return &wxEvtHandler::sm_eventTable
; }
111 const wxEventTable
wxEvtHandler::sm_eventTable
=
112 { (const wxEventTable
*)NULL
, &wxEvtHandler::sm_eventTableEntries
[0] };
114 wxEventHashTable
&wxEvtHandler::GetEventHashTable() const
115 { return wxEvtHandler::sm_eventHashTable
; }
117 wxEventHashTable
wxEvtHandler::sm_eventHashTable(wxEvtHandler::sm_eventTable
);
119 const wxEventTableEntry
wxEvtHandler::sm_eventTableEntries
[] =
120 { DECLARE_EVENT_TABLE_TERMINATOR() };
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
128 #if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
130 class wxEventTableEntryModule
: public wxModule
133 wxEventTableEntryModule() { }
134 virtual bool OnInit() { return true; }
135 virtual void OnExit() { wxEventHashTable::ClearAll(); }
137 DECLARE_DYNAMIC_CLASS(wxEventTableEntryModule
)
140 IMPLEMENT_DYNAMIC_CLASS(wxEventTableEntryModule
, wxModule
)
142 #endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING
144 // ----------------------------------------------------------------------------
146 // ----------------------------------------------------------------------------
148 // List containing event handlers with pending events (each handler can occur
149 // at most once here)
150 wxList
*wxHandlersWithPendingEvents
= NULL
;
151 wxList
*wxHandlersWithPendingDelayedEvents
= NULL
;
154 // protects wxHandlersWithPendingEvents list
155 wxCriticalSection
*wxHandlersWithPendingEventsLocker
= NULL
;
158 // common event types are defined here, other event types are defined by the
159 // components which use them
161 const wxEventType wxEVT_FIRST
= 10000;
162 const wxEventType wxEVT_USER_FIRST
= wxEVT_FIRST
+ 2000;
164 DEFINE_EVENT_TYPE(wxEVT_NULL
)
165 wxDEFINE_EVENT( wxEVT_IDLE
, wxIdleEvent
);
171 wxDEFINE_EVENT( wxEVT_COMMAND_BUTTON_CLICKED
, wxCommandEvent
);
172 wxDEFINE_EVENT( wxEVT_COMMAND_CHECKBOX_CLICKED
, wxCommandEvent
);
173 wxDEFINE_EVENT( wxEVT_COMMAND_CHOICE_SELECTED
, wxCommandEvent
);
174 wxDEFINE_EVENT( wxEVT_COMMAND_LISTBOX_SELECTED
, wxCommandEvent
);
175 wxDEFINE_EVENT( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, wxCommandEvent
);
176 wxDEFINE_EVENT( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, wxCommandEvent
);
177 wxDEFINE_EVENT( wxEVT_COMMAND_MENU_SELECTED
, wxCommandEvent
);
178 wxDEFINE_EVENT( wxEVT_COMMAND_SLIDER_UPDATED
, wxCommandEvent
);
179 wxDEFINE_EVENT( wxEVT_COMMAND_RADIOBOX_SELECTED
, wxCommandEvent
);
180 wxDEFINE_EVENT( wxEVT_COMMAND_RADIOBUTTON_SELECTED
, wxCommandEvent
);
181 wxDEFINE_EVENT( wxEVT_COMMAND_SCROLLBAR_UPDATED
, wxCommandEvent
);
182 wxDEFINE_EVENT( wxEVT_COMMAND_VLBOX_SELECTED
, wxCommandEvent
);
183 wxDEFINE_EVENT( wxEVT_COMMAND_COMBOBOX_SELECTED
, wxCommandEvent
);
184 wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_RCLICKED
, wxCommandEvent
);
185 wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_ENTER
, wxCommandEvent
);
186 wxDEFINE_EVENT( wxEVT_COMMAND_SPINCTRL_UPDATED
, wxCommandEvent
);
187 wxDEFINE_EVENT( wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED
, wxCommandEvent
);
188 wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED
, wxCommandEvent
);
191 wxDEFINE_EVENT( wxEVT_LEFT_DOWN
, wxMouseEvent
);
192 wxDEFINE_EVENT( wxEVT_LEFT_UP
, wxMouseEvent
);
193 wxDEFINE_EVENT( wxEVT_MIDDLE_DOWN
, wxMouseEvent
);
194 wxDEFINE_EVENT( wxEVT_MIDDLE_UP
, wxMouseEvent
);
195 wxDEFINE_EVENT( wxEVT_RIGHT_DOWN
, wxMouseEvent
);
196 wxDEFINE_EVENT( wxEVT_RIGHT_UP
, wxMouseEvent
);
197 wxDEFINE_EVENT( wxEVT_MOTION
, wxMouseEvent
);
198 wxDEFINE_EVENT( wxEVT_ENTER_WINDOW
, wxMouseEvent
);
199 wxDEFINE_EVENT( wxEVT_LEAVE_WINDOW
, wxMouseEvent
);
200 wxDEFINE_EVENT( wxEVT_LEFT_DCLICK
, wxMouseEvent
);
201 wxDEFINE_EVENT( wxEVT_MIDDLE_DCLICK
, wxMouseEvent
);
202 wxDEFINE_EVENT( wxEVT_RIGHT_DCLICK
, wxMouseEvent
);
203 wxDEFINE_EVENT( wxEVT_SET_FOCUS
, wxFocusEvent
);
204 wxDEFINE_EVENT( wxEVT_KILL_FOCUS
, wxFocusEvent
);
205 wxDEFINE_EVENT( wxEVT_CHILD_FOCUS
, wxChildFocusEvent
);
206 wxDEFINE_EVENT( wxEVT_MOUSEWHEEL
, wxMouseEvent
);
207 wxDEFINE_EVENT( wxEVT_AUX1_DOWN
, wxMouseEvent
);
208 wxDEFINE_EVENT( wxEVT_AUX1_UP
, wxMouseEvent
);
209 wxDEFINE_EVENT( wxEVT_AUX1_DCLICK
, wxMouseEvent
);
210 wxDEFINE_EVENT( wxEVT_AUX2_DOWN
, wxMouseEvent
);
211 wxDEFINE_EVENT( wxEVT_AUX2_UP
, wxMouseEvent
);
212 wxDEFINE_EVENT( wxEVT_AUX2_DCLICK
, wxMouseEvent
);
214 // Character input event type
215 wxDEFINE_EVENT( wxEVT_CHAR
, wxKeyEvent
);
216 wxDEFINE_EVENT( wxEVT_CHAR_HOOK
, wxKeyEvent
);
217 wxDEFINE_EVENT( wxEVT_NAVIGATION_KEY
, wxNavigationKeyEvent
);
218 wxDEFINE_EVENT( wxEVT_KEY_DOWN
, wxKeyEvent
);
219 wxDEFINE_EVENT( wxEVT_KEY_UP
, wxKeyEvent
);
221 wxDEFINE_EVENT( wxEVT_HOTKEY
, wxKeyEvent
);
225 wxDEFINE_EVENT( wxEVT_SET_CURSOR
, wxSetCursorEvent
);
227 // wxScrollbar and wxSlider event identifiers
228 wxDEFINE_EVENT( wxEVT_SCROLL_TOP
, wxScrollEvent
);
229 wxDEFINE_EVENT( wxEVT_SCROLL_BOTTOM
, wxScrollEvent
);
230 wxDEFINE_EVENT( wxEVT_SCROLL_LINEUP
, wxScrollEvent
);
231 wxDEFINE_EVENT( wxEVT_SCROLL_LINEDOWN
, wxScrollEvent
);
232 wxDEFINE_EVENT( wxEVT_SCROLL_PAGEUP
, wxScrollEvent
);
233 wxDEFINE_EVENT( wxEVT_SCROLL_PAGEDOWN
, wxScrollEvent
);
234 wxDEFINE_EVENT( wxEVT_SCROLL_THUMBTRACK
, wxScrollEvent
);
235 wxDEFINE_EVENT( wxEVT_SCROLL_THUMBRELEASE
, wxScrollEvent
);
236 wxDEFINE_EVENT( wxEVT_SCROLL_CHANGED
, wxScrollEvent
);
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.
247 wxDEFINE_EVENT_ALIAS( wxEVT_SPIN_UP
, wxSpinEvent
, wxEVT_SCROLL_LINEUP
);
248 wxDEFINE_EVENT_ALIAS( wxEVT_SPIN_DOWN
, wxSpinEvent
, wxEVT_SCROLL_LINEDOWN
);
249 wxDEFINE_EVENT_ALIAS( wxEVT_SPIN
, wxSpinEvent
, wxEVT_SCROLL_THUMBTRACK
);
251 #endif // wxUSE_SPINBTN
253 // Scroll events from wxWindow
254 wxDEFINE_EVENT( wxEVT_SCROLLWIN_TOP
, wxScrollWinEvent
);
255 wxDEFINE_EVENT( wxEVT_SCROLLWIN_BOTTOM
, wxScrollWinEvent
);
256 wxDEFINE_EVENT( wxEVT_SCROLLWIN_LINEUP
, wxScrollWinEvent
);
257 wxDEFINE_EVENT( wxEVT_SCROLLWIN_LINEDOWN
, wxScrollWinEvent
);
258 wxDEFINE_EVENT( wxEVT_SCROLLWIN_PAGEUP
, wxScrollWinEvent
);
259 wxDEFINE_EVENT( wxEVT_SCROLLWIN_PAGEDOWN
, wxScrollWinEvent
);
260 wxDEFINE_EVENT( wxEVT_SCROLLWIN_THUMBTRACK
, wxScrollWinEvent
);
261 wxDEFINE_EVENT( wxEVT_SCROLLWIN_THUMBRELEASE
, wxScrollWinEvent
);
264 wxDEFINE_EVENT( wxEVT_SIZE
, wxSizeEvent
);
265 wxDEFINE_EVENT( wxEVT_SIZING
, wxSizeEvent
);
266 wxDEFINE_EVENT( wxEVT_MOVE
, wxMoveEvent
);
267 wxDEFINE_EVENT( wxEVT_MOVING
, wxMoveEvent
);
268 wxDEFINE_EVENT( wxEVT_MOVE_START
, wxMoveEvent
);
269 wxDEFINE_EVENT( wxEVT_MOVE_END
, wxMoveEvent
);
270 wxDEFINE_EVENT( wxEVT_CLOSE_WINDOW
, wxCloseEvent
);
271 wxDEFINE_EVENT( wxEVT_END_SESSION
, wxCloseEvent
);
272 wxDEFINE_EVENT( wxEVT_QUERY_END_SESSION
, wxCloseEvent
);
273 wxDEFINE_EVENT( wxEVT_HIBERNATE
, wxActivateEvent
);
274 wxDEFINE_EVENT( wxEVT_ACTIVATE_APP
, wxActivateEvent
);
275 wxDEFINE_EVENT( wxEVT_ACTIVATE
, wxActivateEvent
);
276 wxDEFINE_EVENT( wxEVT_CREATE
, wxWindowCreateEvent
);
277 wxDEFINE_EVENT( wxEVT_DESTROY
, wxWindowDestroyEvent
);
278 wxDEFINE_EVENT( wxEVT_SHOW
, wxShowEvent
);
279 wxDEFINE_EVENT( wxEVT_ICONIZE
, wxIconizeEvent
);
280 wxDEFINE_EVENT( wxEVT_MAXIMIZE
, wxMaximizeEvent
);
281 wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_CHANGED
, wxMouseCaptureChangedEvent
);
282 wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_LOST
, wxMouseCaptureLostEvent
);
283 wxDEFINE_EVENT( wxEVT_PAINT
, wxPaintEvent
);
284 wxDEFINE_EVENT( wxEVT_ERASE_BACKGROUND
, wxEraseEvent
);
285 wxDEFINE_EVENT( wxEVT_NC_PAINT
, wxNcPaintEvent
);
286 wxDEFINE_EVENT( wxEVT_MENU_OPEN
, wxMenuEvent
);
287 wxDEFINE_EVENT( wxEVT_MENU_CLOSE
, wxMenuEvent
);
288 wxDEFINE_EVENT( wxEVT_MENU_HIGHLIGHT
, wxMenuEvent
);
289 wxDEFINE_EVENT( wxEVT_CONTEXT_MENU
, wxContextMenuEvent
);
290 wxDEFINE_EVENT( wxEVT_SYS_COLOUR_CHANGED
, wxSysColourChangedEvent
);
291 wxDEFINE_EVENT( wxEVT_DISPLAY_CHANGED
, wxDisplayChangedEvent
);
292 wxDEFINE_EVENT( wxEVT_QUERY_NEW_PALETTE
, wxQueryNewPaletteEvent
);
293 wxDEFINE_EVENT( wxEVT_PALETTE_CHANGED
, wxPaletteChangedEvent
);
294 wxDEFINE_EVENT( wxEVT_JOY_BUTTON_DOWN
, wxJoystickEvent
);
295 wxDEFINE_EVENT( wxEVT_JOY_BUTTON_UP
, wxJoystickEvent
);
296 wxDEFINE_EVENT( wxEVT_JOY_MOVE
, wxJoystickEvent
);
297 wxDEFINE_EVENT( wxEVT_JOY_ZMOVE
, wxJoystickEvent
);
298 wxDEFINE_EVENT( wxEVT_DROP_FILES
, wxDropFilesEvent
);
299 wxDEFINE_EVENT( wxEVT_INIT_DIALOG
, wxInitDialogEvent
);
300 wxDEFINE_EVENT( wxEVT_UPDATE_UI
, wxUpdateUIEvent
);
303 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_COPY
, wxClipboardTextEvent
);
304 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_CUT
, wxClipboardTextEvent
);
305 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_PASTE
, wxClipboardTextEvent
);
307 // Generic command events
308 // Note: a click is a higher-level event than button down/up
309 wxDEFINE_EVENT( wxEVT_COMMAND_LEFT_CLICK
, wxCommandEvent
);
310 wxDEFINE_EVENT( wxEVT_COMMAND_LEFT_DCLICK
, wxCommandEvent
);
311 wxDEFINE_EVENT( wxEVT_COMMAND_RIGHT_CLICK
, wxCommandEvent
);
312 wxDEFINE_EVENT( wxEVT_COMMAND_RIGHT_DCLICK
, wxCommandEvent
);
313 wxDEFINE_EVENT( wxEVT_COMMAND_SET_FOCUS
, wxCommandEvent
);
314 wxDEFINE_EVENT( wxEVT_COMMAND_KILL_FOCUS
, wxCommandEvent
);
315 wxDEFINE_EVENT( wxEVT_COMMAND_ENTER
, wxCommandEvent
);
318 wxDEFINE_EVENT( wxEVT_HELP
, wxHelpEvent
);
319 wxDEFINE_EVENT( wxEVT_DETAILED_HELP
, wxHelpEvent
);
322 wxDEFINE_EVENT( wxEVT_COMMAND_THREAD
, wxThreadEvent
);
328 wxIdleMode
wxIdleEvent::sm_idleMode
= wxIDLE_PROCESS_ALL
;
330 // ============================================================================
332 // ============================================================================
334 // ----------------------------------------------------------------------------
335 // event initialization
336 // ----------------------------------------------------------------------------
341 static int s_lastUsedEventType
= wxEVT_FIRST
;
343 return s_lastUsedEventType
++;
345 // ----------------------------------------------------------------------------
347 // ----------------------------------------------------------------------------
349 wxEventFunctor::~wxEventFunctor()
353 // ----------------------------------------------------------------------------
355 // ----------------------------------------------------------------------------
358 * General wxWidgets events, covering all interesting things that might happen
359 * (button clicking, resizing, setting text in widgets, etc.).
361 * For each completely new event type, derive a new event class.
365 wxEvent::wxEvent(int theId
, wxEventType commandType
)
367 m_eventType
= commandType
;
368 m_eventObject
= NULL
;
372 m_callbackUserData
= NULL
;
373 m_isCommandEvent
= false;
374 m_propagationLevel
= wxEVENT_PROPAGATE_NONE
;
375 m_wasProcessed
= false;
378 wxEvent::wxEvent(const wxEvent
& src
)
380 , m_eventObject(src
.m_eventObject
)
381 , m_eventType(src
.m_eventType
)
382 , m_timeStamp(src
.m_timeStamp
)
384 , m_callbackUserData(src
.m_callbackUserData
)
385 , m_propagationLevel(src
.m_propagationLevel
)
386 , m_skipped(src
.m_skipped
)
387 , m_isCommandEvent(src
.m_isCommandEvent
)
388 , m_wasProcessed(false)
392 wxEvent
& wxEvent::operator=(const wxEvent
& src
)
394 wxObject::operator=(src
);
396 m_eventObject
= src
.m_eventObject
;
397 m_eventType
= src
.m_eventType
;
398 m_timeStamp
= src
.m_timeStamp
;
400 m_callbackUserData
= src
.m_callbackUserData
;
401 m_propagationLevel
= src
.m_propagationLevel
;
402 m_skipped
= src
.m_skipped
;
403 m_isCommandEvent
= src
.m_isCommandEvent
;
405 // don't change m_wasProcessed
420 // 'this' : used in base member initializer list (for m_commandString)
421 #pragma warning(disable:4355)
424 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
425 : wxEvent(theId
, commandType
)
428 m_clientObject
= NULL
;
431 m_isCommandEvent
= true;
433 // the command events are propagated upwards by default
434 m_propagationLevel
= wxEVENT_PROPAGATE_MAX
;
438 #pragma warning(default:4355)
441 wxString
wxCommandEvent::GetString() const
443 if (m_eventType
!= wxEVT_COMMAND_TEXT_UPDATED
|| !m_eventObject
)
450 wxTextCtrl
*txt
= wxDynamicCast(m_eventObject
, wxTextCtrl
);
452 return txt
->GetValue();
454 #endif // wxUSE_TEXTCTRL
464 wxLongLong
wxUpdateUIEvent::sm_lastUpdate
= 0;
467 long wxUpdateUIEvent::sm_updateInterval
= 0;
469 wxUpdateUIMode
wxUpdateUIEvent::sm_updateMode
= wxUPDATE_UI_PROCESS_ALL
;
472 bool wxUpdateUIEvent::CanUpdate(wxWindowBase
*win
)
474 // Don't update if we've switched global updating off
475 // and this window doesn't support updates.
477 (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED
&&
478 ((win
->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES
) == 0)))
481 if (sm_updateInterval
== -1)
484 if (sm_updateInterval
== 0)
487 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
488 wxLongLong now
= wxGetLocalTimeMillis();
489 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
496 // If we don't have wxStopWatch or wxLongLong, we
497 // should err on the safe side and update now anyway.
502 // Reset the update time to provide a delay until the next
503 // time we should update
504 void wxUpdateUIEvent::ResetUpdateTime()
506 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
507 if (sm_updateInterval
> 0)
509 wxLongLong now
= wxGetLocalTimeMillis();
510 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
522 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
526 : wxCommandEvent(commandType
, id
)
528 m_extraLong
= orient
;
536 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
540 m_eventType
= commandType
;
541 m_extraLong
= orient
;
550 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
552 m_eventType
= commandType
;
558 m_middleDown
= false;
567 m_linesPerAction
= 0;
571 void wxMouseEvent::Assign(const wxMouseEvent
& event
)
573 wxEvent::operator=(event
);
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
;
582 m_leftDown
= event
.m_leftDown
;
583 m_middleDown
= event
.m_middleDown
;
584 m_rightDown
= event
.m_rightDown
;
585 m_aux1Down
= event
.m_aux1Down
;
586 m_aux2Down
= event
.m_aux2Down
;
588 m_wheelRotation
= event
.m_wheelRotation
;
589 m_wheelDelta
= event
.m_wheelDelta
;
590 m_linesPerAction
= event
.m_linesPerAction
;
591 m_wheelAxis
= event
.m_wheelAxis
;
594 // return true if was a button dclick event
595 bool wxMouseEvent::ButtonDClick(int but
) const
600 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
603 case wxMOUSE_BTN_ANY
:
604 return (LeftDClick() || MiddleDClick() || RightDClick() ||
605 Aux1DClick() || Aux2DClick());
607 case wxMOUSE_BTN_LEFT
:
610 case wxMOUSE_BTN_MIDDLE
:
611 return MiddleDClick();
613 case wxMOUSE_BTN_RIGHT
:
614 return RightDClick();
616 case wxMOUSE_BTN_AUX1
:
619 case wxMOUSE_BTN_AUX2
:
624 // return true if was a button down event
625 bool wxMouseEvent::ButtonDown(int but
) const
630 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
633 case wxMOUSE_BTN_ANY
:
634 return (LeftDown() || MiddleDown() || RightDown() ||
635 Aux1Down() || Aux2Down());
637 case wxMOUSE_BTN_LEFT
:
640 case wxMOUSE_BTN_MIDDLE
:
643 case wxMOUSE_BTN_RIGHT
:
646 case wxMOUSE_BTN_AUX1
:
649 case wxMOUSE_BTN_AUX2
:
654 // return true if was a button up event
655 bool wxMouseEvent::ButtonUp(int but
) const
660 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
663 case wxMOUSE_BTN_ANY
:
664 return (LeftUp() || MiddleUp() || RightUp() ||
665 Aux1Up() || Aux2Up());
667 case wxMOUSE_BTN_LEFT
:
670 case wxMOUSE_BTN_MIDDLE
:
673 case wxMOUSE_BTN_RIGHT
:
676 case wxMOUSE_BTN_AUX1
:
679 case wxMOUSE_BTN_AUX2
:
684 // return true if the given button is currently changing state
685 bool wxMouseEvent::Button(int but
) const
690 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
693 case wxMOUSE_BTN_ANY
:
694 return ButtonUp(wxMOUSE_BTN_ANY
) ||
695 ButtonDown(wxMOUSE_BTN_ANY
) ||
696 ButtonDClick(wxMOUSE_BTN_ANY
);
698 case wxMOUSE_BTN_LEFT
:
699 return LeftDown() || LeftUp() || LeftDClick();
701 case wxMOUSE_BTN_MIDDLE
:
702 return MiddleDown() || MiddleUp() || MiddleDClick();
704 case wxMOUSE_BTN_RIGHT
:
705 return RightDown() || RightUp() || RightDClick();
707 case wxMOUSE_BTN_AUX1
:
708 return Aux1Down() || Aux1Up() || Aux1DClick();
710 case wxMOUSE_BTN_AUX2
:
711 return Aux2Down() || Aux2Up() || Aux2DClick();
715 bool wxMouseEvent::ButtonIsDown(int but
) const
720 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
723 case wxMOUSE_BTN_ANY
:
724 return LeftIsDown() || MiddleIsDown() || RightIsDown() || Aux1Down() || Aux2Down();
726 case wxMOUSE_BTN_LEFT
:
729 case wxMOUSE_BTN_MIDDLE
:
730 return MiddleIsDown();
732 case wxMOUSE_BTN_RIGHT
:
733 return RightIsDown();
735 case wxMOUSE_BTN_AUX1
:
738 case wxMOUSE_BTN_AUX2
:
743 int wxMouseEvent::GetButton() const
745 for ( int i
= 1; i
< wxMOUSE_BTN_MAX
; i
++ )
753 return wxMOUSE_BTN_NONE
;
756 // Find the logical position of the event given the DC
757 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
759 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
769 wxKeyEvent::wxKeyEvent(wxEventType type
)
779 wxKeyEvent::wxKeyEvent(const wxKeyEvent
& evt
)
786 m_keyCode
= evt
.m_keyCode
;
788 m_scanCode
= evt
.m_scanCode
;
789 m_rawCode
= evt
.m_rawCode
;
790 m_rawFlags
= evt
.m_rawFlags
;
793 m_uniChar
= evt
.m_uniChar
;
797 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
799 SetEventType(wxEVT_CREATE
);
803 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
805 SetEventType(wxEVT_DESTROY
);
809 wxChildFocusEvent::wxChildFocusEvent(wxWindow
*win
)
810 : wxCommandEvent(wxEVT_CHILD_FOCUS
)
815 // ----------------------------------------------------------------------------
817 // ----------------------------------------------------------------------------
820 wxHelpEvent::Origin
wxHelpEvent::GuessOrigin(Origin origin
)
822 if ( origin
== Origin_Unknown
)
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
;
837 // ----------------------------------------------------------------------------
839 // ----------------------------------------------------------------------------
841 static const int EVENT_TYPE_TABLE_INIT_SIZE
= 31; // Not too big not too small...
843 wxEventHashTable
* wxEventHashTable::sm_first
= NULL
;
845 wxEventHashTable::wxEventHashTable(const wxEventTable
&table
)
849 AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE
);
853 m_next
->m_previous
= this;
857 wxEventHashTable::~wxEventHashTable()
860 m_next
->m_previous
= m_previous
;
862 m_previous
->m_next
= m_next
;
863 if (sm_first
== this)
869 void wxEventHashTable::Clear()
871 for ( size_t i
= 0; i
< m_size
; i
++ )
873 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
877 delete[] m_eventTypeTable
;
878 m_eventTypeTable
= NULL
;
883 #if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
886 void wxEventHashTable::ClearAll()
888 wxEventHashTable
* table
= sm_first
;
892 table
= table
->m_next
;
896 #endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING
898 bool wxEventHashTable::HandleEvent(wxEvent
&event
, wxEvtHandler
*self
)
903 m_rebuildHash
= false;
906 if (!m_eventTypeTable
)
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
)
914 // Now start the search for an event handler
915 // that can handle an event with the given ID.
916 const wxEventTableEntryPointerArray
&
917 eventEntryTable
= eTTnode
->eventEntryTable
;
919 const size_t count
= eventEntryTable
.GetCount();
920 for (size_t n
= 0; n
< count
; n
++)
922 const wxEventTableEntry
& entry
= *eventEntryTable
[n
];
923 if ( wxEvtHandler::ProcessEventIfMatchesId(entry
, self
, event
) )
931 void wxEventHashTable::InitHashTable()
933 // Loop over the event tables and all its base tables.
934 const wxEventTable
*table
= &m_table
;
937 // Retrieve all valid event handler entries
938 const wxEventTableEntry
*entry
= table
->entries
;
939 while (entry
->m_fn
!= 0)
941 // Add the event entry in the Hash.
947 table
= table
->baseTable
;
950 // Lets free some memory.
952 for(i
= 0; i
< m_size
; i
++)
954 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
957 eTTnode
->eventEntryTable
.Shrink();
962 void wxEventHashTable::AddEntry(const wxEventTableEntry
&entry
)
964 // This might happen 'accidentally' as the app is exiting
965 if (!m_eventTypeTable
)
968 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[entry
.m_eventType
% m_size
];
969 EventTypeTablePointer eTTnode
= *peTTnode
;
973 if (eTTnode
->eventType
!= entry
.m_eventType
)
976 GrowEventTypeTable();
977 // Try again to add it.
984 eTTnode
= new EventTypeTable
;
985 eTTnode
->eventType
= entry
.m_eventType
;
989 // Fill all hash entries between entry.m_id and entry.m_lastId...
990 eTTnode
->eventEntryTable
.Add(&entry
);
993 void wxEventHashTable::AllocEventTypeTable(size_t size
)
995 m_eventTypeTable
= new EventTypeTablePointer
[size
];
996 memset((void *)m_eventTypeTable
, 0, sizeof(EventTypeTablePointer
)*size
);
1000 void wxEventHashTable::GrowEventTypeTable()
1002 size_t oldSize
= m_size
;
1003 EventTypeTablePointer
*oldEventTypeTable
= m_eventTypeTable
;
1005 // TODO: Search the most optimal grow sequence
1006 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize
*2+1);
1008 for ( size_t i
= 0; i
< oldSize
; /* */ )
1010 EventTypeTablePointer eTToldNode
= oldEventTypeTable
[i
];
1013 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[eTToldNode
->eventType
% m_size
];
1014 EventTypeTablePointer eTTnode
= *peTTnode
;
1016 // Check for collision, we don't want any.
1019 GrowEventTypeTable();
1020 continue; // Don't increment the counter,
1021 // as we still need to add this element.
1025 // Get the old value and put it in the new table.
1026 *peTTnode
= oldEventTypeTable
[i
];
1033 delete[] oldEventTypeTable
;
1036 // ----------------------------------------------------------------------------
1038 // ----------------------------------------------------------------------------
1044 wxEvtHandler::wxEvtHandler()
1046 m_nextHandler
= NULL
;
1047 m_previousHandler
= NULL
;
1049 m_dynamicEvents
= NULL
;
1050 m_pendingEvents
= NULL
;
1052 // no client data (yet)
1053 m_clientData
= NULL
;
1054 m_clientDataType
= wxClientData_None
;
1057 wxEvtHandler::~wxEvtHandler()
1061 if (m_dynamicEvents
)
1063 for ( wxList::iterator it
= m_dynamicEvents
->begin(),
1064 end
= m_dynamicEvents
->end();
1068 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)*it
;
1070 // Remove ourselves from sink destructor notifications
1071 // (this has usually been done, in wxTrackable destructor)
1072 wxEvtHandler
*eventSink
= entry
->m_fn
->GetEvtHandler();
1075 wxEventConnectionRef
* const
1076 evtConnRef
= FindRefInTrackerList(eventSink
);
1079 eventSink
->RemoveNode(evtConnRef
);
1084 delete entry
->m_callbackUserData
;
1087 delete m_dynamicEvents
;
1090 if (m_pendingEvents
)
1091 m_pendingEvents
->DeleteContents(true);
1092 delete m_pendingEvents
;
1094 // Remove us from wxHandlersWithPendingEvents if necessary.
1095 if ( wxHandlersWithPendingEvents
)
1098 if (wxHandlersWithPendingEventsLocker
)
1099 wxENTER_CRIT_SECT(*wxHandlersWithPendingEventsLocker
);
1102 if ( wxHandlersWithPendingEvents
->DeleteObject(this) )
1104 // check that we were present only once in the list
1105 wxASSERT_MSG( !wxHandlersWithPendingEvents
->Find(this),
1106 "Handler occurs twice in wxHandlersWithPendingEvents list" );
1108 //else: we weren't in this list at all, it's ok
1110 if ( wxHandlersWithPendingDelayedEvents
->DeleteObject(this) )
1112 // check that we were present only once in the list
1113 wxASSERT_MSG( !wxHandlersWithPendingDelayedEvents
->Find(this),
1114 "Handler occurs twice in wxHandlersWithPendingDelayedEvents list" );
1116 //else: we weren't in this list at all, it's ok
1119 if (wxHandlersWithPendingEventsLocker
)
1120 wxLEAVE_CRIT_SECT(*wxHandlersWithPendingEventsLocker
);
1124 // we only delete object data, not untyped
1125 if ( m_clientDataType
== wxClientData_Object
)
1126 delete m_clientObject
;
1129 void wxEvtHandler::Unlink()
1131 // this event handler must take itself out of the chain of handlers:
1133 if (m_previousHandler
)
1134 m_previousHandler
->SetNextHandler(m_nextHandler
);
1137 m_nextHandler
->SetPreviousHandler(m_previousHandler
);
1139 m_nextHandler
= NULL
;
1140 m_previousHandler
= NULL
;
1143 bool wxEvtHandler::IsUnlinked() const
1145 return m_previousHandler
== NULL
&&
1146 m_nextHandler
== NULL
;
1151 bool wxEvtHandler::ProcessThreadEvent(const wxEvent
& event
)
1153 // check that we are really in a child thread
1154 wxASSERT_MSG( !wxThread::IsMain(),
1155 wxT("use ProcessEvent() in main thread") );
1157 AddPendingEvent(event
);
1162 #endif // wxUSE_THREADS
1164 void wxEvtHandler::QueueEvent(wxEvent
*event
)
1166 wxCHECK_RET( event
, "NULL event can't be posted" );
1168 // 1) Add this event to our list of pending events
1169 wxENTER_CRIT_SECT( m_pendingEventsLock
);
1171 if ( !m_pendingEvents
)
1172 m_pendingEvents
= new wxList
;
1174 m_pendingEvents
->Append(event
);
1176 // 2) Add this event handler to list of event handlers that
1177 // have pending events.
1179 wxENTER_CRIT_SECT(*wxHandlersWithPendingEventsLocker
);
1181 if ( !wxHandlersWithPendingEvents
)
1182 wxHandlersWithPendingEvents
= new wxList
;
1183 if ( !wxHandlersWithPendingEvents
->Find(this) )
1184 wxHandlersWithPendingEvents
->Append(this);
1186 wxLEAVE_CRIT_SECT(*wxHandlersWithPendingEventsLocker
);
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
1191 // we had time to append this pointer to wxHandlersWithPendingEvents list; thus
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
);
1196 // 3) Inform the system that new pending events are somewhere,
1197 // and that these should be processed in idle time.
1201 void wxEvtHandler::ProcessPendingEvents()
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)
1207 wxENTER_CRIT_SECT( m_pendingEventsLock
);
1209 // this method is only called by wxApp if this handler does have
1211 wxCHECK_RET( m_pendingEvents
&& !m_pendingEvents
->IsEmpty(),
1212 "should have pending events if called" );
1214 wxList::compatibility_iterator node
= m_pendingEvents
->GetFirst();
1215 wxEvent
* pEvent
= static_cast<wxEvent
*>(node
->GetData());
1217 // find the first event which can be processed now:
1218 if (wxTheApp
&& wxTheApp
->IsYielding())
1220 while (node
&& pEvent
&& !wxTheApp
->IsEventAllowedInsideYield(pEvent
->GetEventCategory()))
1222 node
= node
->GetNext();
1223 pEvent
= node
? static_cast<wxEvent
*>(node
->GetData()) : NULL
;
1228 // all our events are NOT processable now... signal this:
1230 if (wxHandlersWithPendingEventsLocker
)
1231 wxENTER_CRIT_SECT(*wxHandlersWithPendingEventsLocker
);
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);
1239 if (wxHandlersWithPendingEventsLocker
)
1240 wxLEAVE_CRIT_SECT(*wxHandlersWithPendingEventsLocker
);
1242 wxLEAVE_CRIT_SECT( m_pendingEventsLock
);
1248 wxEventPtr
event(pEvent
);
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
);
1255 // if there are no more pending events left, we don't need to stay in this
1257 if ( m_pendingEvents
->IsEmpty() )
1260 if (wxHandlersWithPendingEventsLocker
)
1261 wxENTER_CRIT_SECT(*wxHandlersWithPendingEventsLocker
);
1263 wxHandlersWithPendingEvents
->DeleteObject(this);
1265 if (wxHandlersWithPendingEventsLocker
)
1266 wxLEAVE_CRIT_SECT(*wxHandlersWithPendingEventsLocker
);
1270 wxLEAVE_CRIT_SECT( m_pendingEventsLock
);
1272 ProcessEvent(*event
);
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
1283 wxEvtHandler::ProcessEventIfMatchesId(const wxEventTableEntryBase
& entry
,
1284 wxEvtHandler
*handler
,
1287 int tableId1
= entry
.m_id
,
1288 tableId2
= entry
.m_lastId
;
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
1294 if ((tableId1
== wxID_ANY
) ||
1295 (tableId2
== wxID_ANY
&& tableId1
== event
.GetId()) ||
1296 (tableId2
!= wxID_ANY
&&
1297 (event
.GetId() >= tableId1
&& event
.GetId() <= tableId2
)))
1300 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1302 #if wxUSE_EXCEPTIONS
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
1308 wxTheApp
->CallEventHandler(handler
, *entry
.m_fn
, event
);
1311 #endif // wxUSE_EXCEPTIONS
1313 (*entry
.m_fn
)(handler
, event
);
1316 if (!event
.GetSkipped())
1323 bool wxEvtHandler::TryParent(wxEvent
& event
)
1325 if ( GetNextHandler() )
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
);
1332 if ( wxTheApp
&& (this != wxTheApp
) )
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
)
1339 if ( wxTheApp
->ProcessEvent(event
) )
1347 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
1349 // allow the application to hook into event processing
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() )
1359 CANNOT ENABLE: ProcessEvent() must always immediately process the event!
1361 if (wxTheApp->IsYielding() &&
1362 !wxTheApp->IsEventAllowedInsideYield(event.GetEventCategory()))
1364 wxEvent* queuedEv = event.Clone();
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)
1372 // it's not completely true that the event was processed;
1373 // but we cannot even say it was skipped or discarded...
1375 //else: either we're not inside a wxYield() call or if we are,
1376 // we can process this event immediately.
1379 int rc
= wxTheApp
->FilterEvent(event
);
1382 wxASSERT_MSG( rc
== 1 || rc
== 0,
1383 "unexpected wxApp::FilterEvent return value" );
1387 //else: proceed normally
1391 if ( ProcessEventHere(event
) )
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
);
1400 // propagate the event upwards the window chain and/or to the application
1401 // object if it wasn't processed at this level
1402 return TryParent(event
);
1405 bool wxEvtHandler::ProcessEventHere(wxEvent
& event
)
1407 // If the event handler is disabled it doesn't process any events
1408 if ( !GetEvtHandlerEnabled() )
1411 // If we have a validator, it has higher priority than our own event
1413 if ( TryValidator(event
) )
1416 // Handle per-instance dynamic event tables first
1417 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
1420 // Then static per-class event tables
1421 if ( GetEventHashTable().HandleEvent(event
, this) )
1424 // We don't have a handler for this event.
1428 bool wxEvtHandler::SafelyProcessEvent(wxEvent
& event
)
1430 #if wxUSE_EXCEPTIONS
1434 return ProcessEvent(event
);
1435 #if wxUSE_EXCEPTIONS
1439 wxEventLoopBase
*loop
= wxEventLoopBase::GetActive();
1442 if ( !wxTheApp
|| !wxTheApp
->OnExceptionInMainLoop() )
1447 //else: continue running current event loop
1453 // OnExceptionInMainLoop() threw, possibly rethrowing the same
1454 // exception again: very good, but we still need Exit() to
1461 #endif // wxUSE_EXCEPTIONS
1465 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
1467 const wxEventType eventType
= event
.GetEventType();
1468 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
1470 const wxEventTableEntry
& entry
= table
.entries
[i
];
1471 if ( eventType
== entry
.m_eventType
)
1473 if ( ProcessEventIfMatchesId(entry
, this, event
) )
1481 void wxEvtHandler::DoConnect(int id
,
1483 wxEventType eventType
,
1484 wxEventFunctor
*func
,
1487 wxDynamicEventTableEntry
*entry
=
1488 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
);
1490 if (!m_dynamicEvents
)
1491 m_dynamicEvents
= new wxList
;
1493 // Insert at the front of the list so most recent additions are found first
1494 m_dynamicEvents
->Insert( (wxObject
*) entry
);
1496 // Make sure we get to know when a sink is destroyed
1497 wxEvtHandler
*eventSink
= func
->GetEvtHandler();
1498 if ( eventSink
&& eventSink
!= this )
1500 wxEventConnectionRef
*evtConnRef
= FindRefInTrackerList(eventSink
);
1502 evtConnRef
->IncRef( );
1504 new wxEventConnectionRef(this, eventSink
);
1509 wxEvtHandler::DoDisconnect(int id
,
1511 wxEventType eventType
,
1512 const wxEventFunctor
& func
,
1515 if (!m_dynamicEvents
)
1518 // Remove connection from tracker node (wxEventConnectionRef)
1519 wxEvtHandler
*eventSink
= func
.GetEvtHandler();
1520 if ( eventSink
&& eventSink
!= this )
1522 wxEventConnectionRef
*evtConnRef
= FindRefInTrackerList(eventSink
);
1524 evtConnRef
->DecRef();
1527 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1530 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1532 if ((entry
->m_id
== id
) &&
1533 ((entry
->m_lastId
== lastId
) || (lastId
== wxID_ANY
)) &&
1534 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1535 entry
->m_fn
->Matches(func
) &&
1536 ((entry
->m_callbackUserData
== userData
) || !userData
))
1538 delete entry
->m_callbackUserData
;
1539 m_dynamicEvents
->Erase( node
);
1543 node
= node
->GetNext();
1548 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1550 wxCHECK_MSG( m_dynamicEvents
, false,
1551 wxT("caller should check that we have dynamic events") );
1553 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1556 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1558 // get next node before (maybe) calling the event handler as it could
1559 // call Disconnect() invalidating the current node
1560 node
= node
->GetNext();
1562 if ( event
.GetEventType() == entry
->m_eventType
)
1564 wxEvtHandler
*handler
= entry
->m_fn
->GetEvtHandler();
1567 if ( ProcessEventIfMatchesId(*entry
, handler
, event
) )
1575 void wxEvtHandler::DoSetClientObject( wxClientData
*data
)
1577 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1578 wxT("can't have both object and void client data") );
1580 if ( m_clientObject
)
1581 delete m_clientObject
;
1583 m_clientObject
= data
;
1584 m_clientDataType
= wxClientData_Object
;
1587 wxClientData
*wxEvtHandler::DoGetClientObject() const
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") );
1594 return m_clientObject
;
1597 void wxEvtHandler::DoSetClientData( void *data
)
1599 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1600 wxT("can't have both object and void client data") );
1602 m_clientData
= data
;
1603 m_clientDataType
= wxClientData_Void
;
1606 void *wxEvtHandler::DoGetClientData() const
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") );
1613 return m_clientData
;
1616 // A helper to find an wxEventConnectionRef object
1617 wxEventConnectionRef
*
1618 wxEvtHandler::FindRefInTrackerList(wxEvtHandler
*eventSink
)
1620 for ( wxTrackerNode
*node
= eventSink
->GetFirst(); node
; node
= node
->m_nxt
)
1622 // we only want wxEventConnectionRef nodes here
1623 wxEventConnectionRef
*evtConnRef
= node
->ToEventConnection();
1624 if ( evtConnRef
&& evtConnRef
->m_src
== this )
1626 wxASSERT( evtConnRef
->m_sink
==eventSink
);
1634 void wxEvtHandler::OnSinkDestroyed( wxEvtHandler
*sink
)
1636 wxASSERT(m_dynamicEvents
);
1638 // remove all connections with this sink
1639 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst(), node_nxt
;
1642 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1643 node_nxt
= node
->GetNext();
1645 if ( entry
->m_fn
->GetEvtHandler() == sink
)
1647 delete entry
->m_callbackUserData
;
1648 m_dynamicEvents
->Erase( node
);
1655 #endif // wxUSE_BASE
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.
1661 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1663 // Process events starting with the window with the focus, if any.
1664 wxWindow
* focusWin
= wxWindow::FindFocus();
1665 wxWindow
* win
= focusWin
;
1667 // Check if this is a descendant of this frame.
1668 // If not, win will be set to NULL.
1671 if (win
== ancestor
)
1674 win
= win
->GetParent();
1682 // ----------------------------------------------------------------------------
1684 // ----------------------------------------------------------------------------
1686 wxEventBlocker::wxEventBlocker(wxWindow
*win
, wxEventType type
)
1688 wxCHECK_RET(win
, wxT("Null window given to wxEventBlocker"));
1693 m_window
->PushEventHandler(this);
1696 wxEventBlocker::~wxEventBlocker()
1698 wxEvtHandler
*popped
= m_window
->PopEventHandler(false);
1699 wxCHECK_RET(popped
== this,
1700 wxT("Don't push other event handlers into a window managed by wxEventBlocker!"));
1703 bool wxEventBlocker::ProcessEvent(wxEvent
& event
)
1705 // should this event be blocked?
1706 for ( size_t i
= 0; i
< m_eventsToBlock
.size(); i
++ )
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