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/textctrl.h"
42 #include "wx/validate.h"
46 #include "wx/thread.h"
49 #include "wx/ptr_scpd.h"
51 wxDECLARE_SCOPED_PTR(wxEvent
, wxEventPtr
)
52 wxDEFINE_SCOPED_PTR(wxEvent
, wxEventPtr
)
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
60 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler
, wxObject
)
61 IMPLEMENT_ABSTRACT_CLASS(wxEvent
, wxObject
)
62 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent
, wxEvent
)
66 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent
, wxEvent
)
67 IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent
, wxCommandEvent
)
68 IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent
, wxCommandEvent
)
69 IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent
, wxEvent
)
70 IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent
, wxEvent
)
71 IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent
, wxEvent
)
72 IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent
, wxEvent
)
73 IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent
, wxEvent
)
74 IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent
, wxEvent
)
75 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent
, wxEvent
)
76 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent
, wxEvent
)
77 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent
, wxEvent
)
78 IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent
, wxCommandEvent
)
79 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent
, wxEvent
)
80 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent
, wxEvent
)
81 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent
, wxEvent
)
82 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent
, wxEvent
)
83 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent
, wxEvent
)
84 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent
, wxEvent
)
85 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent
, wxEvent
)
86 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent
, wxEvent
)
87 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent
, wxEvent
)
88 IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent
, wxEvent
)
89 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent
, wxEvent
)
90 IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent
, wxEvent
)
91 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent
, wxCommandEvent
)
92 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent
, wxEvent
)
93 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent
, wxEvent
)
94 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent
, wxEvent
)
95 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent
, wxEvent
)
96 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent
, wxEvent
)
97 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent
, wxCommandEvent
)
98 IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent
, wxCommandEvent
)
99 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent
, wxEvent
)
100 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureLostEvent
, wxEvent
)
101 IMPLEMENT_DYNAMIC_CLASS(wxClipboardTextEvent
, wxCommandEvent
)
106 const wxEventTable
*wxEvtHandler::GetEventTable() const
107 { return &wxEvtHandler::sm_eventTable
; }
109 const wxEventTable
wxEvtHandler::sm_eventTable
=
110 { (const wxEventTable
*)NULL
, &wxEvtHandler::sm_eventTableEntries
[0] };
112 wxEventHashTable
&wxEvtHandler::GetEventHashTable() const
113 { return wxEvtHandler::sm_eventHashTable
; }
115 wxEventHashTable
wxEvtHandler::sm_eventHashTable(wxEvtHandler::sm_eventTable
);
117 const wxEventTableEntry
wxEvtHandler::sm_eventTableEntries
[] =
118 { DECLARE_EVENT_TABLE_TERMINATOR() };
121 // wxUSE_MEMORY_TRACING considers memory freed from the static objects dtors
122 // leaked, so we need to manually clean up all event tables before checking for
123 // the memory leaks when using it, however this breaks re-initializing the
124 // library (i.e. repeated calls to wxInitialize/wxUninitialize) because the
125 // event tables won't be rebuilt the next time, so disable this by default
126 #if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
128 class wxEventTableEntryModule
: public wxModule
131 wxEventTableEntryModule() { }
132 virtual bool OnInit() { return true; }
133 virtual void OnExit() { wxEventHashTable::ClearAll(); }
135 DECLARE_DYNAMIC_CLASS(wxEventTableEntryModule
)
138 IMPLEMENT_DYNAMIC_CLASS(wxEventTableEntryModule
, wxModule
)
140 #endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING
142 // ----------------------------------------------------------------------------
144 // ----------------------------------------------------------------------------
146 // List containing event handlers with pending events (each handler can occur
147 // at most once here)
148 wxList
*wxHandlersWithPendingEvents
= NULL
;
151 // protects wxHandlersWithPendingEvents list
152 wxCriticalSection
*wxHandlersWithPendingEventsLocker
= NULL
;
155 // common event types are defined here, other event types are defined by the
156 // components which use them
158 const wxEventType wxEVT_FIRST
= 10000;
159 const wxEventType wxEVT_USER_FIRST
= wxEVT_FIRST
+ 2000;
161 DEFINE_EVENT_TYPE(wxEVT_NULL
)
162 wxDEFINE_EVENT( wxEVT_IDLE
, wxIdleEvent
)
168 wxDEFINE_EVENT( wxEVT_COMMAND_BUTTON_CLICKED
, wxCommandEvent
)
169 wxDEFINE_EVENT( wxEVT_COMMAND_CHECKBOX_CLICKED
, wxCommandEvent
)
170 wxDEFINE_EVENT( wxEVT_COMMAND_CHOICE_SELECTED
, wxCommandEvent
)
171 wxDEFINE_EVENT( wxEVT_COMMAND_LISTBOX_SELECTED
, wxCommandEvent
)
172 wxDEFINE_EVENT( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, wxCommandEvent
)
173 wxDEFINE_EVENT( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, wxCommandEvent
)
174 wxDEFINE_EVENT( wxEVT_COMMAND_MENU_SELECTED
, wxCommandEvent
)
175 wxDEFINE_EVENT( wxEVT_COMMAND_SLIDER_UPDATED
, wxCommandEvent
)
176 wxDEFINE_EVENT( wxEVT_COMMAND_RADIOBOX_SELECTED
, wxCommandEvent
)
177 wxDEFINE_EVENT( wxEVT_COMMAND_RADIOBUTTON_SELECTED
, wxCommandEvent
)
178 wxDEFINE_EVENT( wxEVT_COMMAND_SCROLLBAR_UPDATED
, wxCommandEvent
)
179 wxDEFINE_EVENT( wxEVT_COMMAND_VLBOX_SELECTED
, wxCommandEvent
)
180 wxDEFINE_EVENT( wxEVT_COMMAND_COMBOBOX_SELECTED
, wxCommandEvent
)
181 wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_RCLICKED
, wxCommandEvent
)
182 wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_ENTER
, wxCommandEvent
)
183 wxDEFINE_EVENT( wxEVT_COMMAND_SPINCTRL_UPDATED
, wxCommandEvent
)
184 wxDEFINE_EVENT( wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED
, wxCommandEvent
)
185 wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED
, wxCommandEvent
)
188 wxDEFINE_EVENT( wxEVT_LEFT_DOWN
, wxMouseEvent
)
189 wxDEFINE_EVENT( wxEVT_LEFT_UP
, wxMouseEvent
)
190 wxDEFINE_EVENT( wxEVT_MIDDLE_DOWN
, wxMouseEvent
)
191 wxDEFINE_EVENT( wxEVT_MIDDLE_UP
, wxMouseEvent
)
192 wxDEFINE_EVENT( wxEVT_RIGHT_DOWN
, wxMouseEvent
)
193 wxDEFINE_EVENT( wxEVT_RIGHT_UP
, wxMouseEvent
)
194 wxDEFINE_EVENT( wxEVT_MOTION
, wxMouseEvent
)
195 wxDEFINE_EVENT( wxEVT_ENTER_WINDOW
, wxMouseEvent
)
196 wxDEFINE_EVENT( wxEVT_LEAVE_WINDOW
, wxMouseEvent
)
197 wxDEFINE_EVENT( wxEVT_LEFT_DCLICK
, wxMouseEvent
)
198 wxDEFINE_EVENT( wxEVT_MIDDLE_DCLICK
, wxMouseEvent
)
199 wxDEFINE_EVENT( wxEVT_RIGHT_DCLICK
, wxMouseEvent
)
200 wxDEFINE_EVENT( wxEVT_SET_FOCUS
, wxFocusEvent
)
201 wxDEFINE_EVENT( wxEVT_KILL_FOCUS
, wxFocusEvent
)
202 wxDEFINE_EVENT( wxEVT_CHILD_FOCUS
, wxChildFocusEvent
)
203 wxDEFINE_EVENT( wxEVT_MOUSEWHEEL
, wxMouseEvent
)
204 wxDEFINE_EVENT( wxEVT_AUX1_DOWN
, wxMouseEvent
)
205 wxDEFINE_EVENT( wxEVT_AUX1_UP
, wxMouseEvent
)
206 wxDEFINE_EVENT( wxEVT_AUX1_DCLICK
, wxMouseEvent
)
207 wxDEFINE_EVENT( wxEVT_AUX2_DOWN
, wxMouseEvent
)
208 wxDEFINE_EVENT( wxEVT_AUX2_UP
, wxMouseEvent
)
209 wxDEFINE_EVENT( wxEVT_AUX2_DCLICK
, wxMouseEvent
)
211 // Character input event type
212 wxDEFINE_EVENT( wxEVT_CHAR
, wxKeyEvent
)
213 wxDEFINE_EVENT( wxEVT_CHAR_HOOK
, wxKeyEvent
)
214 wxDEFINE_EVENT( wxEVT_NAVIGATION_KEY
, wxNavigationKeyEvent
)
215 wxDEFINE_EVENT( wxEVT_KEY_DOWN
, wxKeyEvent
)
216 wxDEFINE_EVENT( wxEVT_KEY_UP
, wxKeyEvent
)
218 wxDEFINE_EVENT( wxEVT_HOTKEY
, wxKeyEvent
)
222 wxDEFINE_EVENT( wxEVT_SET_CURSOR
, wxSetCursorEvent
)
224 // wxScrollbar and wxSlider event identifiers
225 wxDEFINE_EVENT( wxEVT_SCROLL_TOP
, wxScrollEvent
)
226 wxDEFINE_EVENT( wxEVT_SCROLL_BOTTOM
, wxScrollEvent
)
227 wxDEFINE_EVENT( wxEVT_SCROLL_LINEUP
, wxScrollEvent
)
228 wxDEFINE_EVENT( wxEVT_SCROLL_LINEDOWN
, wxScrollEvent
)
229 wxDEFINE_EVENT( wxEVT_SCROLL_PAGEUP
, wxScrollEvent
)
230 wxDEFINE_EVENT( wxEVT_SCROLL_PAGEDOWN
, wxScrollEvent
)
231 wxDEFINE_EVENT( wxEVT_SCROLL_THUMBTRACK
, wxScrollEvent
)
232 wxDEFINE_EVENT( wxEVT_SCROLL_THUMBRELEASE
, wxScrollEvent
)
233 wxDEFINE_EVENT( wxEVT_SCROLL_CHANGED
, wxScrollEvent
)
235 // Scroll events from wxWindow
236 wxDEFINE_EVENT( wxEVT_SCROLLWIN_TOP
, wxScrollWinEvent
)
237 wxDEFINE_EVENT( wxEVT_SCROLLWIN_BOTTOM
, wxScrollWinEvent
)
238 wxDEFINE_EVENT( wxEVT_SCROLLWIN_LINEUP
, wxScrollWinEvent
)
239 wxDEFINE_EVENT( wxEVT_SCROLLWIN_LINEDOWN
, wxScrollWinEvent
)
240 wxDEFINE_EVENT( wxEVT_SCROLLWIN_PAGEUP
, wxScrollWinEvent
)
241 wxDEFINE_EVENT( wxEVT_SCROLLWIN_PAGEDOWN
, wxScrollWinEvent
)
242 wxDEFINE_EVENT( wxEVT_SCROLLWIN_THUMBTRACK
, wxScrollWinEvent
)
243 wxDEFINE_EVENT( wxEVT_SCROLLWIN_THUMBRELEASE
, wxScrollWinEvent
)
246 wxDEFINE_EVENT( wxEVT_SIZE
, wxSizeEvent
)
247 wxDEFINE_EVENT( wxEVT_SIZING
, wxSizeEvent
)
248 wxDEFINE_EVENT( wxEVT_MOVE
, wxMoveEvent
)
249 wxDEFINE_EVENT( wxEVT_MOVING
, wxMoveEvent
)
250 wxDEFINE_EVENT( wxEVT_MOVE_START
, wxMoveEvent
)
251 wxDEFINE_EVENT( wxEVT_MOVE_END
, wxMoveEvent
)
252 wxDEFINE_EVENT( wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
253 wxDEFINE_EVENT( wxEVT_END_SESSION
, wxCloseEvent
)
254 wxDEFINE_EVENT( wxEVT_QUERY_END_SESSION
, wxCloseEvent
)
255 wxDEFINE_EVENT( wxEVT_HIBERNATE
, wxActivateEvent
)
256 wxDEFINE_EVENT( wxEVT_ACTIVATE_APP
, wxActivateEvent
)
257 wxDEFINE_EVENT( wxEVT_ACTIVATE
, wxActivateEvent
)
258 wxDEFINE_EVENT( wxEVT_CREATE
, wxWindowCreateEvent
)
259 wxDEFINE_EVENT( wxEVT_DESTROY
, wxWindowDestroyEvent
)
260 wxDEFINE_EVENT( wxEVT_SHOW
, wxShowEvent
)
261 wxDEFINE_EVENT( wxEVT_ICONIZE
, wxIconizeEvent
)
262 wxDEFINE_EVENT( wxEVT_MAXIMIZE
, wxMaximizeEvent
)
263 wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_CHANGED
, wxMouseCaptureChangedEvent
)
264 wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_LOST
, wxMouseCaptureLostEvent
)
265 wxDEFINE_EVENT( wxEVT_PAINT
, wxPaintEvent
)
266 wxDEFINE_EVENT( wxEVT_ERASE_BACKGROUND
, wxEraseEvent
)
267 wxDEFINE_EVENT( wxEVT_NC_PAINT
, wxNcPaintEvent
)
268 wxDEFINE_EVENT( wxEVT_MENU_OPEN
, wxMenuEvent
)
269 wxDEFINE_EVENT( wxEVT_MENU_CLOSE
, wxMenuEvent
)
270 wxDEFINE_EVENT( wxEVT_MENU_HIGHLIGHT
, wxMenuEvent
)
271 wxDEFINE_EVENT( wxEVT_CONTEXT_MENU
, wxContextMenuEvent
)
272 wxDEFINE_EVENT( wxEVT_SYS_COLOUR_CHANGED
, wxSysColourChangedEvent
)
273 wxDEFINE_EVENT( wxEVT_DISPLAY_CHANGED
, wxDisplayChangedEvent
)
274 wxDEFINE_EVENT( wxEVT_QUERY_NEW_PALETTE
, wxQueryNewPaletteEvent
)
275 wxDEFINE_EVENT( wxEVT_PALETTE_CHANGED
, wxPaletteChangedEvent
)
276 wxDEFINE_EVENT( wxEVT_JOY_BUTTON_DOWN
, wxJoystickEvent
)
277 wxDEFINE_EVENT( wxEVT_JOY_BUTTON_UP
, wxJoystickEvent
)
278 wxDEFINE_EVENT( wxEVT_JOY_MOVE
, wxJoystickEvent
)
279 wxDEFINE_EVENT( wxEVT_JOY_ZMOVE
, wxJoystickEvent
)
280 wxDEFINE_EVENT( wxEVT_DROP_FILES
, wxDropFilesEvent
)
281 wxDEFINE_EVENT( wxEVT_INIT_DIALOG
, wxInitDialogEvent
)
282 wxDEFINE_EVENT( wxEVT_UPDATE_UI
, wxUpdateUIEvent
)
285 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_COPY
, wxClipboardTextEvent
)
286 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_CUT
, wxClipboardTextEvent
)
287 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_PASTE
, wxClipboardTextEvent
)
289 // Generic command events
290 // Note: a click is a higher-level event than button down/up
291 wxDEFINE_EVENT( wxEVT_COMMAND_LEFT_CLICK
, wxCommandEvent
)
292 wxDEFINE_EVENT( wxEVT_COMMAND_LEFT_DCLICK
, wxCommandEvent
)
293 wxDEFINE_EVENT( wxEVT_COMMAND_RIGHT_CLICK
, wxCommandEvent
)
294 wxDEFINE_EVENT( wxEVT_COMMAND_RIGHT_DCLICK
, wxCommandEvent
)
295 wxDEFINE_EVENT( wxEVT_COMMAND_SET_FOCUS
, wxCommandEvent
)
296 wxDEFINE_EVENT( wxEVT_COMMAND_KILL_FOCUS
, wxCommandEvent
)
297 wxDEFINE_EVENT( wxEVT_COMMAND_ENTER
, wxCommandEvent
)
300 wxDEFINE_EVENT( wxEVT_HELP
, wxHelpEvent
)
301 wxDEFINE_EVENT( wxEVT_DETAILED_HELP
, wxHelpEvent
)
307 wxIdleMode
wxIdleEvent::sm_idleMode
= wxIDLE_PROCESS_ALL
;
309 // ============================================================================
311 // ============================================================================
313 // ----------------------------------------------------------------------------
314 // event initialization
315 // ----------------------------------------------------------------------------
320 static int s_lastUsedEventType
= wxEVT_FIRST
;
322 return s_lastUsedEventType
++;
324 // ----------------------------------------------------------------------------
326 // ----------------------------------------------------------------------------
328 wxEventFunctor::~wxEventFunctor()
332 // ----------------------------------------------------------------------------
334 // ----------------------------------------------------------------------------
337 * General wxWidgets events, covering
338 * all interesting things that might happen (button clicking, resizing,
339 * setting text in widgets, etc.).
341 * For each completely new event type, derive a new event class.
345 wxEvent::wxEvent(int theId
, wxEventType commandType
)
347 m_eventType
= commandType
;
348 m_eventObject
= NULL
;
352 m_callbackUserData
= NULL
;
353 m_isCommandEvent
= false;
354 m_propagationLevel
= wxEVENT_PROPAGATE_NONE
;
357 wxEvent::wxEvent(const wxEvent
& src
)
359 , m_eventObject(src
.m_eventObject
)
360 , m_eventType(src
.m_eventType
)
361 , m_timeStamp(src
.m_timeStamp
)
363 , m_callbackUserData(src
.m_callbackUserData
)
364 , m_propagationLevel(src
.m_propagationLevel
)
365 , m_skipped(src
.m_skipped
)
366 , m_isCommandEvent(src
.m_isCommandEvent
)
370 wxEvent
& wxEvent::operator=(const wxEvent
& src
)
372 wxObject::operator=(src
);
374 m_eventObject
= src
.m_eventObject
;
375 m_eventType
= src
.m_eventType
;
376 m_timeStamp
= src
.m_timeStamp
;
378 m_callbackUserData
= src
.m_callbackUserData
;
379 m_propagationLevel
= src
.m_propagationLevel
;
380 m_skipped
= src
.m_skipped
;
381 m_isCommandEvent
= src
.m_isCommandEvent
;
396 // 'this' : used in base member initializer list (for m_commandString)
397 #pragma warning(disable:4355)
400 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
401 : wxEvent(theId
, commandType
)
404 m_clientObject
= NULL
;
407 m_isCommandEvent
= true;
409 // the command events are propagated upwards by default
410 m_propagationLevel
= wxEVENT_PROPAGATE_MAX
;
414 #pragma warning(default:4355)
417 wxString
wxCommandEvent::GetString() const
419 if (m_eventType
!= wxEVT_COMMAND_TEXT_UPDATED
|| !m_eventObject
)
426 wxTextCtrl
*txt
= wxDynamicCast(m_eventObject
, wxTextCtrl
);
428 return txt
->GetValue();
430 #endif // wxUSE_TEXTCTRL
440 wxLongLong
wxUpdateUIEvent::sm_lastUpdate
= 0;
443 long wxUpdateUIEvent::sm_updateInterval
= 0;
445 wxUpdateUIMode
wxUpdateUIEvent::sm_updateMode
= wxUPDATE_UI_PROCESS_ALL
;
448 bool wxUpdateUIEvent::CanUpdate(wxWindowBase
*win
)
450 // Don't update if we've switched global updating off
451 // and this window doesn't support updates.
453 (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED
&&
454 ((win
->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES
) == 0)))
457 if (sm_updateInterval
== -1)
460 if (sm_updateInterval
== 0)
463 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
464 wxLongLong now
= wxGetLocalTimeMillis();
465 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
472 // If we don't have wxStopWatch or wxLongLong, we
473 // should err on the safe side and update now anyway.
478 // Reset the update time to provide a delay until the next
479 // time we should update
480 void wxUpdateUIEvent::ResetUpdateTime()
482 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
483 if (sm_updateInterval
> 0)
485 wxLongLong now
= wxGetLocalTimeMillis();
486 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
498 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
502 : wxCommandEvent(commandType
, id
)
504 m_extraLong
= orient
;
512 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
516 m_eventType
= commandType
;
517 m_extraLong
= orient
;
526 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
528 m_eventType
= commandType
;
534 m_middleDown
= false;
543 m_linesPerAction
= 0;
547 void wxMouseEvent::Assign(const wxMouseEvent
& event
)
549 wxEvent::operator=(event
);
551 // Borland C++ 5.82 doesn't compile an explicit call to an implicitly
552 // defined operator=() so need to do it this way:
553 *static_cast<wxMouseState
*>(this) = event
;
558 m_leftDown
= event
.m_leftDown
;
559 m_middleDown
= event
.m_middleDown
;
560 m_rightDown
= event
.m_rightDown
;
561 m_aux1Down
= event
.m_aux1Down
;
562 m_aux2Down
= event
.m_aux2Down
;
564 m_wheelRotation
= event
.m_wheelRotation
;
565 m_wheelDelta
= event
.m_wheelDelta
;
566 m_linesPerAction
= event
.m_linesPerAction
;
567 m_wheelAxis
= event
.m_wheelAxis
;
570 // return true if was a button dclick event
571 bool wxMouseEvent::ButtonDClick(int but
) const
576 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
579 case wxMOUSE_BTN_ANY
:
580 return (LeftDClick() || MiddleDClick() || RightDClick() ||
581 Aux1DClick() || Aux2DClick());
583 case wxMOUSE_BTN_LEFT
:
586 case wxMOUSE_BTN_MIDDLE
:
587 return MiddleDClick();
589 case wxMOUSE_BTN_RIGHT
:
590 return RightDClick();
592 case wxMOUSE_BTN_AUX1
:
595 case wxMOUSE_BTN_AUX2
:
600 // return true if was a button down event
601 bool wxMouseEvent::ButtonDown(int but
) const
606 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
609 case wxMOUSE_BTN_ANY
:
610 return (LeftDown() || MiddleDown() || RightDown() ||
611 Aux1Down() || Aux2Down());
613 case wxMOUSE_BTN_LEFT
:
616 case wxMOUSE_BTN_MIDDLE
:
619 case wxMOUSE_BTN_RIGHT
:
622 case wxMOUSE_BTN_AUX1
:
625 case wxMOUSE_BTN_AUX2
:
630 // return true if was a button up event
631 bool wxMouseEvent::ButtonUp(int but
) const
636 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
639 case wxMOUSE_BTN_ANY
:
640 return (LeftUp() || MiddleUp() || RightUp() ||
641 Aux1Up() || Aux2Up());
643 case wxMOUSE_BTN_LEFT
:
646 case wxMOUSE_BTN_MIDDLE
:
649 case wxMOUSE_BTN_RIGHT
:
652 case wxMOUSE_BTN_AUX1
:
655 case wxMOUSE_BTN_AUX2
:
660 // return true if the given button is currently changing state
661 bool wxMouseEvent::Button(int but
) const
666 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
669 case wxMOUSE_BTN_ANY
:
670 return ButtonUp(wxMOUSE_BTN_ANY
) ||
671 ButtonDown(wxMOUSE_BTN_ANY
) ||
672 ButtonDClick(wxMOUSE_BTN_ANY
);
674 case wxMOUSE_BTN_LEFT
:
675 return LeftDown() || LeftUp() || LeftDClick();
677 case wxMOUSE_BTN_MIDDLE
:
678 return MiddleDown() || MiddleUp() || MiddleDClick();
680 case wxMOUSE_BTN_RIGHT
:
681 return RightDown() || RightUp() || RightDClick();
683 case wxMOUSE_BTN_AUX1
:
684 return Aux1Down() || Aux1Up() || Aux1DClick();
686 case wxMOUSE_BTN_AUX2
:
687 return Aux2Down() || Aux2Up() || Aux2DClick();
691 bool wxMouseEvent::ButtonIsDown(int but
) const
696 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
699 case wxMOUSE_BTN_ANY
:
700 return LeftIsDown() || MiddleIsDown() || RightIsDown() || Aux1Down() || Aux2Down();
702 case wxMOUSE_BTN_LEFT
:
705 case wxMOUSE_BTN_MIDDLE
:
706 return MiddleIsDown();
708 case wxMOUSE_BTN_RIGHT
:
709 return RightIsDown();
711 case wxMOUSE_BTN_AUX1
:
714 case wxMOUSE_BTN_AUX2
:
719 int wxMouseEvent::GetButton() const
721 for ( int i
= 1; i
< wxMOUSE_BTN_MAX
; i
++ )
729 return wxMOUSE_BTN_NONE
;
732 // Find the logical position of the event given the DC
733 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
735 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
745 wxKeyEvent::wxKeyEvent(wxEventType type
)
755 wxKeyEvent::wxKeyEvent(const wxKeyEvent
& evt
)
762 m_keyCode
= evt
.m_keyCode
;
764 m_scanCode
= evt
.m_scanCode
;
765 m_rawCode
= evt
.m_rawCode
;
766 m_rawFlags
= evt
.m_rawFlags
;
769 m_uniChar
= evt
.m_uniChar
;
773 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
775 SetEventType(wxEVT_CREATE
);
779 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
781 SetEventType(wxEVT_DESTROY
);
785 wxChildFocusEvent::wxChildFocusEvent(wxWindow
*win
)
786 : wxCommandEvent(wxEVT_CHILD_FOCUS
)
791 // ----------------------------------------------------------------------------
793 // ----------------------------------------------------------------------------
796 wxHelpEvent::Origin
wxHelpEvent::GuessOrigin(Origin origin
)
798 if ( origin
== Origin_Unknown
)
800 // assume that the event comes from the help button if it's not from
801 // keyboard and that pressing F1 always results in the help event
802 origin
= wxGetKeyState(WXK_F1
) ? Origin_Keyboard
: Origin_HelpButton
;
813 // ----------------------------------------------------------------------------
815 // ----------------------------------------------------------------------------
817 static const int EVENT_TYPE_TABLE_INIT_SIZE
= 31; // Not too big not too small...
819 wxEventHashTable
* wxEventHashTable::sm_first
= NULL
;
821 wxEventHashTable::wxEventHashTable(const wxEventTable
&table
)
825 AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE
);
829 m_next
->m_previous
= this;
833 wxEventHashTable::~wxEventHashTable()
836 m_next
->m_previous
= m_previous
;
838 m_previous
->m_next
= m_next
;
839 if (sm_first
== this)
845 void wxEventHashTable::Clear()
847 for ( size_t i
= 0; i
< m_size
; i
++ )
849 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
853 delete[] m_eventTypeTable
;
854 m_eventTypeTable
= NULL
;
859 #if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
862 void wxEventHashTable::ClearAll()
864 wxEventHashTable
* table
= sm_first
;
868 table
= table
->m_next
;
872 #endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING
874 bool wxEventHashTable::HandleEvent(wxEvent
&event
, wxEvtHandler
*self
)
879 m_rebuildHash
= false;
882 if (!m_eventTypeTable
)
885 // Find all entries for the given event type.
886 wxEventType eventType
= event
.GetEventType();
887 const EventTypeTablePointer eTTnode
= m_eventTypeTable
[eventType
% m_size
];
888 if (eTTnode
&& eTTnode
->eventType
== eventType
)
890 // Now start the search for an event handler
891 // that can handle an event with the given ID.
892 const wxEventTableEntryPointerArray
&
893 eventEntryTable
= eTTnode
->eventEntryTable
;
895 const size_t count
= eventEntryTable
.GetCount();
896 for (size_t n
= 0; n
< count
; n
++)
898 const wxEventTableEntry
& entry
= *eventEntryTable
[n
];
899 if ( wxEvtHandler::ProcessEventIfMatchesId(entry
, self
, event
) )
907 void wxEventHashTable::InitHashTable()
909 // Loop over the event tables and all its base tables.
910 const wxEventTable
*table
= &m_table
;
913 // Retrieve all valid event handler entries
914 const wxEventTableEntry
*entry
= table
->entries
;
915 while (entry
->m_fn
!= 0)
917 // Add the event entry in the Hash.
923 table
= table
->baseTable
;
926 // Lets free some memory.
928 for(i
= 0; i
< m_size
; i
++)
930 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
933 eTTnode
->eventEntryTable
.Shrink();
938 void wxEventHashTable::AddEntry(const wxEventTableEntry
&entry
)
940 // This might happen 'accidentally' as the app is exiting
941 if (!m_eventTypeTable
)
944 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[entry
.m_eventType
% m_size
];
945 EventTypeTablePointer eTTnode
= *peTTnode
;
949 if (eTTnode
->eventType
!= entry
.m_eventType
)
952 GrowEventTypeTable();
953 // Try again to add it.
960 eTTnode
= new EventTypeTable
;
961 eTTnode
->eventType
= entry
.m_eventType
;
965 // Fill all hash entries between entry.m_id and entry.m_lastId...
966 eTTnode
->eventEntryTable
.Add(&entry
);
969 void wxEventHashTable::AllocEventTypeTable(size_t size
)
971 m_eventTypeTable
= new EventTypeTablePointer
[size
];
972 memset((void *)m_eventTypeTable
, 0, sizeof(EventTypeTablePointer
)*size
);
976 void wxEventHashTable::GrowEventTypeTable()
978 size_t oldSize
= m_size
;
979 EventTypeTablePointer
*oldEventTypeTable
= m_eventTypeTable
;
981 // TODO: Search the most optimal grow sequence
982 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize
*2+1);
984 for ( size_t i
= 0; i
< oldSize
; /* */ )
986 EventTypeTablePointer eTToldNode
= oldEventTypeTable
[i
];
989 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[eTToldNode
->eventType
% m_size
];
990 EventTypeTablePointer eTTnode
= *peTTnode
;
992 // Check for collision, we don't want any.
995 GrowEventTypeTable();
996 continue; // Don't increment the counter,
997 // as we still need to add this element.
1001 // Get the old value and put it in the new table.
1002 *peTTnode
= oldEventTypeTable
[i
];
1009 delete[] oldEventTypeTable
;
1012 // ----------------------------------------------------------------------------
1014 // ----------------------------------------------------------------------------
1020 wxEvtHandler::wxEvtHandler()
1022 m_nextHandler
= NULL
;
1023 m_previousHandler
= NULL
;
1025 m_dynamicEvents
= NULL
;
1026 m_pendingEvents
= NULL
;
1028 // no client data (yet)
1029 m_clientData
= NULL
;
1030 m_clientDataType
= wxClientData_None
;
1033 wxEvtHandler::~wxEvtHandler()
1035 // Takes itself out of the list of handlers
1036 if (m_previousHandler
)
1037 m_previousHandler
->m_nextHandler
= m_nextHandler
;
1040 m_nextHandler
->m_previousHandler
= m_previousHandler
;
1042 if (m_dynamicEvents
)
1044 for ( wxList::iterator it
= m_dynamicEvents
->begin(),
1045 end
= m_dynamicEvents
->end();
1049 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)*it
;
1051 // Remove ourselves from sink destructor notifications
1052 // (this has usually been done, in wxTrackable destructor)
1053 wxEvtHandler
*eventSink
= entry
->m_fn
->GetHandler();
1056 wxEventConnectionRef
* const
1057 evtConnRef
= FindRefInTrackerList(eventSink
);
1060 eventSink
->RemoveNode(evtConnRef
);
1065 delete entry
->m_callbackUserData
;
1068 delete m_dynamicEvents
;
1071 if (m_pendingEvents
)
1072 m_pendingEvents
->DeleteContents(true);
1073 delete m_pendingEvents
;
1075 // Remove us from wxHandlersWithPendingEvents if necessary.
1076 if ( wxHandlersWithPendingEvents
)
1079 if (wxHandlersWithPendingEventsLocker
)
1080 wxENTER_CRIT_SECT(*wxHandlersWithPendingEventsLocker
);
1083 if ( wxHandlersWithPendingEvents
->DeleteObject(this) )
1085 // check that we were present only once in the list
1086 wxASSERT_MSG( !wxHandlersWithPendingEvents
->Find(this),
1087 "Handler occurs twice in wxHandlersWithPendingEvents list" );
1089 //else: we weren't in this list at all, it's ok
1092 if (wxHandlersWithPendingEventsLocker
)
1093 wxLEAVE_CRIT_SECT(*wxHandlersWithPendingEventsLocker
);
1097 // we only delete object data, not untyped
1098 if ( m_clientDataType
== wxClientData_Object
)
1099 delete m_clientObject
;
1104 bool wxEvtHandler::ProcessThreadEvent(const wxEvent
& event
)
1106 // check that we are really in a child thread
1107 wxASSERT_MSG( !wxThread::IsMain(),
1108 wxT("use ProcessEvent() in main thread") );
1110 AddPendingEvent(event
);
1115 #endif // wxUSE_THREADS
1117 void wxEvtHandler::QueueEvent(wxEvent
*event
)
1119 wxCHECK_RET( event
, "NULL event can't be posted" );
1121 // 1) Add this event to our list of pending events
1122 wxENTER_CRIT_SECT( m_pendingEventsLock
);
1124 if ( !m_pendingEvents
)
1125 m_pendingEvents
= new wxList
;
1127 m_pendingEvents
->Append(event
);
1129 // 2) Add this event handler to list of event handlers that
1130 // have pending events.
1132 wxENTER_CRIT_SECT(*wxHandlersWithPendingEventsLocker
);
1134 if ( !wxHandlersWithPendingEvents
)
1135 wxHandlersWithPendingEvents
= new wxList
;
1136 if ( !wxHandlersWithPendingEvents
->Find(this) )
1137 wxHandlersWithPendingEvents
->Append(this);
1139 wxLEAVE_CRIT_SECT(*wxHandlersWithPendingEventsLocker
);
1141 // only release m_pendingEventsLock now because otherwise there is a race
1142 // condition as described in the ticket #9093: we could process the event
1143 // just added to m_pendingEvents in our ProcessPendingEvents() below before
1144 // we had time to append this pointer to wxHandlersWithPendingEvents list; thus
1145 // breaking the invariant that a handler should be in the list iff it has
1146 // any pending events to process
1147 wxLEAVE_CRIT_SECT( m_pendingEventsLock
);
1149 // 3) Inform the system that new pending events are somewhere,
1150 // and that these should be processed in idle time.
1154 void wxEvtHandler::ProcessPendingEvents()
1156 wxENTER_CRIT_SECT( m_pendingEventsLock
);
1158 // this method is only called by wxApp if this handler does have
1160 wxCHECK_RET( m_pendingEvents
&& !m_pendingEvents
->IsEmpty(),
1161 "should have pending events if called" );
1163 wxList::compatibility_iterator node
= m_pendingEvents
->GetFirst();
1164 wxEventPtr
event(static_cast<wxEvent
*>(node
->GetData()));
1166 // it's important we remove event from list before processing it, else a
1167 // nested event loop, for example from a modal dialog, might process the
1168 // same event again.
1169 m_pendingEvents
->Erase(node
);
1171 // if there are no more pending events left, we don't need to stay in this
1173 if ( m_pendingEvents
->IsEmpty() )
1176 if (wxHandlersWithPendingEventsLocker
)
1177 wxENTER_CRIT_SECT(*wxHandlersWithPendingEventsLocker
);
1179 wxHandlersWithPendingEvents
->DeleteObject(this);
1181 if (wxHandlersWithPendingEventsLocker
)
1182 wxLEAVE_CRIT_SECT(*wxHandlersWithPendingEventsLocker
);
1186 wxLEAVE_CRIT_SECT( m_pendingEventsLock
);
1188 ProcessEvent(*event
);
1190 // careful: this object could have been deleted by the event handler
1191 // executed by the above ProcessEvent() call, so we can't access any fields
1192 // of this object any more
1199 wxEvtHandler::ProcessEventIfMatchesId(const wxEventTableEntryBase
& entry
,
1200 wxEvtHandler
*handler
,
1203 int tableId1
= entry
.m_id
,
1204 tableId2
= entry
.m_lastId
;
1206 // match only if the event type is the same and the id is either -1 in
1207 // the event table (meaning "any") or the event id matches the id
1208 // specified in the event table either exactly or by falling into
1209 // range between first and last
1210 if ((tableId1
== wxID_ANY
) ||
1211 (tableId2
== wxID_ANY
&& tableId1
== event
.GetId()) ||
1212 (tableId2
!= wxID_ANY
&&
1213 (event
.GetId() >= tableId1
&& event
.GetId() <= tableId2
)))
1216 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1218 #if wxUSE_EXCEPTIONS
1221 // call the handler via wxApp method which allows the user to catch
1222 // any exceptions which may be thrown by any handler in the program
1224 wxTheApp
->CallEventHandler(handler
, *entry
.m_fn
, event
);
1227 #endif // wxUSE_EXCEPTIONS
1229 (*entry
.m_fn
)(handler
, event
);
1232 if (!event
.GetSkipped())
1239 bool wxEvtHandler::TryParent(wxEvent
& event
)
1241 if ( GetNextHandler() )
1243 // the next handler will pass it to wxTheApp if it doesn't process it,
1244 // so return from here to avoid doing it again
1245 return GetNextHandler()->TryParent(event
);
1248 if ( wxTheApp
&& (this != wxTheApp
) )
1250 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1251 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1252 // processed appropriately via SearchEventTable.
1253 if ( event
.GetEventType() != wxEVT_IDLE
)
1255 if ( wxTheApp
->ProcessEvent(event
) )
1263 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
1265 // allow the application to hook into event processing
1268 int rc
= wxTheApp
->FilterEvent(event
);
1271 wxASSERT_MSG( rc
== 1 || rc
== 0,
1272 _T("unexpected wxApp::FilterEvent return value") );
1276 //else: proceed normally
1279 if ( ProcessEventHere(event
) )
1282 // propagate the event upwards the window chain and/or to the application
1283 // object if it wasn't processed at this level
1284 return TryParent(event
);
1287 bool wxEvtHandler::ProcessEventHere(wxEvent
& event
)
1289 // An event handler can be enabled or disabled
1290 if ( GetEvtHandlerEnabled() )
1292 // if we have a validator, it has higher priority than our own event
1294 if ( TryValidator(event
) )
1297 // Handle per-instance dynamic event tables first
1298 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
1301 // Then static per-class event tables
1302 if ( GetEventHashTable().HandleEvent(event
, this) )
1306 // Try going down the event handler chain
1307 if ( GetNextHandler() && GetNextHandler()->ProcessEventHere(event
) )
1310 // We don't have a handler for this event.
1314 bool wxEvtHandler::SafelyProcessEvent(wxEvent
& event
)
1316 #if wxUSE_EXCEPTIONS
1320 return ProcessEvent(event
);
1321 #if wxUSE_EXCEPTIONS
1325 wxEventLoopBase
*loop
= wxEventLoopBase::GetActive();
1328 if ( !wxTheApp
|| !wxTheApp
->OnExceptionInMainLoop() )
1333 //else: continue running current event loop
1339 // OnExceptionInMainLoop() threw, possibly rethrowing the same
1340 // exception again: very good, but we still need Exit() to
1347 #endif // wxUSE_EXCEPTIONS
1351 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
1353 const wxEventType eventType
= event
.GetEventType();
1354 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
1356 const wxEventTableEntry
& entry
= table
.entries
[i
];
1357 if ( eventType
== entry
.m_eventType
)
1359 if ( ProcessEventIfMatchesId(entry
, this, event
) )
1367 void wxEvtHandler::Subscribe( int id
, int lastId
,
1368 wxEventType eventType
,
1369 wxEventFunctor
*func
,
1370 wxObject
*userData
)
1372 wxDynamicEventTableEntry
*entry
=
1373 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
);
1375 if (!m_dynamicEvents
)
1376 m_dynamicEvents
= new wxList
;
1378 // Insert at the front of the list so most recent additions are found first
1379 m_dynamicEvents
->Insert( (wxObject
*) entry
);
1381 // Make sure we get to know when a sink is destroyed
1382 wxEvtHandler
*eventSink
= func
->GetHandler();
1383 if ( eventSink
&& eventSink
!= this )
1385 wxEventConnectionRef
*evtConnRef
= FindRefInTrackerList(eventSink
);
1387 evtConnRef
->IncRef( );
1389 new wxEventConnectionRef(this, eventSink
);
1394 wxEvtHandler::Unsubscribe(int id
,
1396 wxEventType eventType
,
1397 const wxEventFunctor
& func
,
1400 if (!m_dynamicEvents
)
1403 // Remove connection from tracker node (wxEventConnectionRef)
1404 wxEvtHandler
*eventSink
= func
.GetHandler();
1405 if ( eventSink
&& eventSink
!= this )
1407 wxEventConnectionRef
*evtConnRef
= FindRefInTrackerList(eventSink
);
1409 evtConnRef
->DecRef();
1412 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1415 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1417 if ((entry
->m_id
== id
) &&
1418 ((entry
->m_lastId
== lastId
) || (lastId
== wxID_ANY
)) &&
1419 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1420 entry
->m_fn
->Matches(func
) &&
1421 ((entry
->m_callbackUserData
== userData
) || !userData
))
1423 delete entry
->m_callbackUserData
;
1424 m_dynamicEvents
->Erase( node
);
1428 node
= node
->GetNext();
1433 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1435 wxCHECK_MSG( m_dynamicEvents
, false,
1436 wxT("caller should check that we have dynamic events") );
1438 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1441 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1443 // get next node before (maybe) calling the event handler as it could
1444 // call Disconnect() invalidating the current node
1445 node
= node
->GetNext();
1447 if ( event
.GetEventType() == entry
->m_eventType
)
1449 wxEvtHandler
*handler
= entry
->m_fn
->GetHandler();
1452 if ( ProcessEventIfMatchesId(*entry
, handler
, event
) )
1460 void wxEvtHandler::DoSetClientObject( wxClientData
*data
)
1462 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1463 wxT("can't have both object and void client data") );
1465 if ( m_clientObject
)
1466 delete m_clientObject
;
1468 m_clientObject
= data
;
1469 m_clientDataType
= wxClientData_Object
;
1472 wxClientData
*wxEvtHandler::DoGetClientObject() const
1474 // it's not an error to call GetClientObject() on a window which doesn't
1475 // have client data at all - NULL will be returned
1476 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1477 wxT("this window doesn't have object client data") );
1479 return m_clientObject
;
1482 void wxEvtHandler::DoSetClientData( void *data
)
1484 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1485 wxT("can't have both object and void client data") );
1487 m_clientData
= data
;
1488 m_clientDataType
= wxClientData_Void
;
1491 void *wxEvtHandler::DoGetClientData() const
1493 // it's not an error to call GetClientData() on a window which doesn't have
1494 // client data at all - NULL will be returned
1495 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1496 wxT("this window doesn't have void client data") );
1498 return m_clientData
;
1501 // A helper to find an wxEventConnectionRef object
1502 wxEventConnectionRef
*
1503 wxEvtHandler::FindRefInTrackerList(wxEvtHandler
*eventSink
)
1505 for ( wxTrackerNode
*node
= eventSink
->GetFirst(); node
; node
= node
->m_nxt
)
1507 // we only want wxEventConnectionRef nodes here
1508 wxEventConnectionRef
*evtConnRef
= node
->ToEventConnection();
1509 if ( evtConnRef
&& evtConnRef
->m_src
== this )
1511 wxASSERT( evtConnRef
->m_sink
==eventSink
);
1519 void wxEvtHandler::OnSinkDestroyed( wxEvtHandler
*sink
)
1521 wxASSERT(m_dynamicEvents
);
1523 // remove all connections with this sink
1524 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst(), node_nxt
;
1527 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1528 node_nxt
= node
->GetNext();
1530 if ( entry
->m_fn
->GetHandler() == sink
)
1532 delete entry
->m_callbackUserData
;
1533 m_dynamicEvents
->Erase( node
);
1540 #endif // wxUSE_BASE
1544 // Find a window with the focus, that is also a descendant of the given window.
1545 // This is used to determine the window to initially send commands to.
1546 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1548 // Process events starting with the window with the focus, if any.
1549 wxWindow
* focusWin
= wxWindow::FindFocus();
1550 wxWindow
* win
= focusWin
;
1552 // Check if this is a descendant of this frame.
1553 // If not, win will be set to NULL.
1556 if (win
== ancestor
)
1559 win
= win
->GetParent();
1567 // ----------------------------------------------------------------------------
1569 // ----------------------------------------------------------------------------
1571 wxEventBlocker::wxEventBlocker(wxWindow
*win
, wxEventType type
)
1573 wxCHECK_RET(win
, wxT("Null window given to wxEventBlocker"));
1578 m_window
->PushEventHandler(this);
1581 wxEventBlocker::~wxEventBlocker()
1583 wxEvtHandler
*popped
= m_window
->PopEventHandler(false);
1584 wxCHECK_RET(popped
== this,
1585 wxT("Don't push other event handlers into a window managed by wxEventBlocker!"));
1588 bool wxEventBlocker::ProcessEvent(wxEvent
& event
)
1590 // should this event be blocked?
1591 for ( size_t i
= 0; i
< m_eventsToBlock
.size(); i
++ )
1593 wxEventType t
= (wxEventType
)m_eventsToBlock
[i
];
1594 if ( t
== wxEVT_ANY
|| t
== event
.GetEventType() )
1595 return true; // yes, it should: mark this event as processed