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 // common event types are defined here, other event types are defined by the
149 // components which use them
151 const wxEventType wxEVT_FIRST
= 10000;
152 const wxEventType wxEVT_USER_FIRST
= wxEVT_FIRST
+ 2000;
154 DEFINE_EVENT_TYPE(wxEVT_NULL
)
155 wxDEFINE_EVENT( wxEVT_IDLE
, wxIdleEvent
);
161 wxDEFINE_EVENT( wxEVT_COMMAND_BUTTON_CLICKED
, wxCommandEvent
);
162 wxDEFINE_EVENT( wxEVT_COMMAND_CHECKBOX_CLICKED
, wxCommandEvent
);
163 wxDEFINE_EVENT( wxEVT_COMMAND_CHOICE_SELECTED
, wxCommandEvent
);
164 wxDEFINE_EVENT( wxEVT_COMMAND_LISTBOX_SELECTED
, wxCommandEvent
);
165 wxDEFINE_EVENT( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, wxCommandEvent
);
166 wxDEFINE_EVENT( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, wxCommandEvent
);
167 wxDEFINE_EVENT( wxEVT_COMMAND_MENU_SELECTED
, wxCommandEvent
);
168 wxDEFINE_EVENT( wxEVT_COMMAND_SLIDER_UPDATED
, wxCommandEvent
);
169 wxDEFINE_EVENT( wxEVT_COMMAND_RADIOBOX_SELECTED
, wxCommandEvent
);
170 wxDEFINE_EVENT( wxEVT_COMMAND_RADIOBUTTON_SELECTED
, wxCommandEvent
);
171 wxDEFINE_EVENT( wxEVT_COMMAND_SCROLLBAR_UPDATED
, wxCommandEvent
);
172 wxDEFINE_EVENT( wxEVT_COMMAND_VLBOX_SELECTED
, wxCommandEvent
);
173 wxDEFINE_EVENT( wxEVT_COMMAND_COMBOBOX_SELECTED
, wxCommandEvent
);
174 wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_RCLICKED
, wxCommandEvent
);
175 wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_ENTER
, wxCommandEvent
);
176 wxDEFINE_EVENT( wxEVT_COMMAND_SPINCTRL_UPDATED
, wxCommandEvent
);
177 wxDEFINE_EVENT( wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED
, wxCommandEvent
);
178 wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED
, wxCommandEvent
);
181 wxDEFINE_EVENT( wxEVT_LEFT_DOWN
, wxMouseEvent
);
182 wxDEFINE_EVENT( wxEVT_LEFT_UP
, wxMouseEvent
);
183 wxDEFINE_EVENT( wxEVT_MIDDLE_DOWN
, wxMouseEvent
);
184 wxDEFINE_EVENT( wxEVT_MIDDLE_UP
, wxMouseEvent
);
185 wxDEFINE_EVENT( wxEVT_RIGHT_DOWN
, wxMouseEvent
);
186 wxDEFINE_EVENT( wxEVT_RIGHT_UP
, wxMouseEvent
);
187 wxDEFINE_EVENT( wxEVT_MOTION
, wxMouseEvent
);
188 wxDEFINE_EVENT( wxEVT_ENTER_WINDOW
, wxMouseEvent
);
189 wxDEFINE_EVENT( wxEVT_LEAVE_WINDOW
, wxMouseEvent
);
190 wxDEFINE_EVENT( wxEVT_LEFT_DCLICK
, wxMouseEvent
);
191 wxDEFINE_EVENT( wxEVT_MIDDLE_DCLICK
, wxMouseEvent
);
192 wxDEFINE_EVENT( wxEVT_RIGHT_DCLICK
, wxMouseEvent
);
193 wxDEFINE_EVENT( wxEVT_SET_FOCUS
, wxFocusEvent
);
194 wxDEFINE_EVENT( wxEVT_KILL_FOCUS
, wxFocusEvent
);
195 wxDEFINE_EVENT( wxEVT_CHILD_FOCUS
, wxChildFocusEvent
);
196 wxDEFINE_EVENT( wxEVT_MOUSEWHEEL
, wxMouseEvent
);
197 wxDEFINE_EVENT( wxEVT_AUX1_DOWN
, wxMouseEvent
);
198 wxDEFINE_EVENT( wxEVT_AUX1_UP
, wxMouseEvent
);
199 wxDEFINE_EVENT( wxEVT_AUX1_DCLICK
, wxMouseEvent
);
200 wxDEFINE_EVENT( wxEVT_AUX2_DOWN
, wxMouseEvent
);
201 wxDEFINE_EVENT( wxEVT_AUX2_UP
, wxMouseEvent
);
202 wxDEFINE_EVENT( wxEVT_AUX2_DCLICK
, wxMouseEvent
);
204 // Character input event type
205 wxDEFINE_EVENT( wxEVT_CHAR
, wxKeyEvent
);
206 wxDEFINE_EVENT( wxEVT_CHAR_HOOK
, wxKeyEvent
);
207 wxDEFINE_EVENT( wxEVT_NAVIGATION_KEY
, wxNavigationKeyEvent
);
208 wxDEFINE_EVENT( wxEVT_KEY_DOWN
, wxKeyEvent
);
209 wxDEFINE_EVENT( wxEVT_KEY_UP
, wxKeyEvent
);
211 wxDEFINE_EVENT( wxEVT_HOTKEY
, wxKeyEvent
);
215 wxDEFINE_EVENT( wxEVT_SET_CURSOR
, wxSetCursorEvent
);
217 // wxScrollbar and wxSlider event identifiers
218 wxDEFINE_EVENT( wxEVT_SCROLL_TOP
, wxScrollEvent
);
219 wxDEFINE_EVENT( wxEVT_SCROLL_BOTTOM
, wxScrollEvent
);
220 wxDEFINE_EVENT( wxEVT_SCROLL_LINEUP
, wxScrollEvent
);
221 wxDEFINE_EVENT( wxEVT_SCROLL_LINEDOWN
, wxScrollEvent
);
222 wxDEFINE_EVENT( wxEVT_SCROLL_PAGEUP
, wxScrollEvent
);
223 wxDEFINE_EVENT( wxEVT_SCROLL_PAGEDOWN
, wxScrollEvent
);
224 wxDEFINE_EVENT( wxEVT_SCROLL_THUMBTRACK
, wxScrollEvent
);
225 wxDEFINE_EVENT( wxEVT_SCROLL_THUMBRELEASE
, wxScrollEvent
);
226 wxDEFINE_EVENT( wxEVT_SCROLL_CHANGED
, wxScrollEvent
);
228 // Due to a bug in older wx versions, wxSpinEvents were being sent with type of
229 // wxEVT_SCROLL_LINEUP, wxEVT_SCROLL_LINEDOWN and wxEVT_SCROLL_THUMBTRACK. But
230 // with the type-safe events in place, these event types are associated with
231 // wxScrollEvent. To allow handling of spin events, new event types have been
232 // defined in spinbutt.h/spinnbuttcmn.cpp. To maintain backward compatibility
233 // the spin event types are being initialized with the scroll event types.
237 wxDEFINE_EVENT_ALIAS( wxEVT_SPIN_UP
, wxSpinEvent
, wxEVT_SCROLL_LINEUP
);
238 wxDEFINE_EVENT_ALIAS( wxEVT_SPIN_DOWN
, wxSpinEvent
, wxEVT_SCROLL_LINEDOWN
);
239 wxDEFINE_EVENT_ALIAS( wxEVT_SPIN
, wxSpinEvent
, wxEVT_SCROLL_THUMBTRACK
);
241 #endif // wxUSE_SPINBTN
243 // Scroll events from wxWindow
244 wxDEFINE_EVENT( wxEVT_SCROLLWIN_TOP
, wxScrollWinEvent
);
245 wxDEFINE_EVENT( wxEVT_SCROLLWIN_BOTTOM
, wxScrollWinEvent
);
246 wxDEFINE_EVENT( wxEVT_SCROLLWIN_LINEUP
, wxScrollWinEvent
);
247 wxDEFINE_EVENT( wxEVT_SCROLLWIN_LINEDOWN
, wxScrollWinEvent
);
248 wxDEFINE_EVENT( wxEVT_SCROLLWIN_PAGEUP
, wxScrollWinEvent
);
249 wxDEFINE_EVENT( wxEVT_SCROLLWIN_PAGEDOWN
, wxScrollWinEvent
);
250 wxDEFINE_EVENT( wxEVT_SCROLLWIN_THUMBTRACK
, wxScrollWinEvent
);
251 wxDEFINE_EVENT( wxEVT_SCROLLWIN_THUMBRELEASE
, wxScrollWinEvent
);
254 wxDEFINE_EVENT( wxEVT_SIZE
, wxSizeEvent
);
255 wxDEFINE_EVENT( wxEVT_SIZING
, wxSizeEvent
);
256 wxDEFINE_EVENT( wxEVT_MOVE
, wxMoveEvent
);
257 wxDEFINE_EVENT( wxEVT_MOVING
, wxMoveEvent
);
258 wxDEFINE_EVENT( wxEVT_MOVE_START
, wxMoveEvent
);
259 wxDEFINE_EVENT( wxEVT_MOVE_END
, wxMoveEvent
);
260 wxDEFINE_EVENT( wxEVT_CLOSE_WINDOW
, wxCloseEvent
);
261 wxDEFINE_EVENT( wxEVT_END_SESSION
, wxCloseEvent
);
262 wxDEFINE_EVENT( wxEVT_QUERY_END_SESSION
, wxCloseEvent
);
263 wxDEFINE_EVENT( wxEVT_HIBERNATE
, wxActivateEvent
);
264 wxDEFINE_EVENT( wxEVT_ACTIVATE_APP
, wxActivateEvent
);
265 wxDEFINE_EVENT( wxEVT_ACTIVATE
, wxActivateEvent
);
266 wxDEFINE_EVENT( wxEVT_CREATE
, wxWindowCreateEvent
);
267 wxDEFINE_EVENT( wxEVT_DESTROY
, wxWindowDestroyEvent
);
268 wxDEFINE_EVENT( wxEVT_SHOW
, wxShowEvent
);
269 wxDEFINE_EVENT( wxEVT_ICONIZE
, wxIconizeEvent
);
270 wxDEFINE_EVENT( wxEVT_MAXIMIZE
, wxMaximizeEvent
);
271 wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_CHANGED
, wxMouseCaptureChangedEvent
);
272 wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_LOST
, wxMouseCaptureLostEvent
);
273 wxDEFINE_EVENT( wxEVT_PAINT
, wxPaintEvent
);
274 wxDEFINE_EVENT( wxEVT_ERASE_BACKGROUND
, wxEraseEvent
);
275 wxDEFINE_EVENT( wxEVT_NC_PAINT
, wxNcPaintEvent
);
276 wxDEFINE_EVENT( wxEVT_MENU_OPEN
, wxMenuEvent
);
277 wxDEFINE_EVENT( wxEVT_MENU_CLOSE
, wxMenuEvent
);
278 wxDEFINE_EVENT( wxEVT_MENU_HIGHLIGHT
, wxMenuEvent
);
279 wxDEFINE_EVENT( wxEVT_CONTEXT_MENU
, wxContextMenuEvent
);
280 wxDEFINE_EVENT( wxEVT_SYS_COLOUR_CHANGED
, wxSysColourChangedEvent
);
281 wxDEFINE_EVENT( wxEVT_DISPLAY_CHANGED
, wxDisplayChangedEvent
);
282 wxDEFINE_EVENT( wxEVT_QUERY_NEW_PALETTE
, wxQueryNewPaletteEvent
);
283 wxDEFINE_EVENT( wxEVT_PALETTE_CHANGED
, wxPaletteChangedEvent
);
284 wxDEFINE_EVENT( wxEVT_JOY_BUTTON_DOWN
, wxJoystickEvent
);
285 wxDEFINE_EVENT( wxEVT_JOY_BUTTON_UP
, wxJoystickEvent
);
286 wxDEFINE_EVENT( wxEVT_JOY_MOVE
, wxJoystickEvent
);
287 wxDEFINE_EVENT( wxEVT_JOY_ZMOVE
, wxJoystickEvent
);
288 wxDEFINE_EVENT( wxEVT_DROP_FILES
, wxDropFilesEvent
);
289 wxDEFINE_EVENT( wxEVT_INIT_DIALOG
, wxInitDialogEvent
);
290 wxDEFINE_EVENT( wxEVT_UPDATE_UI
, wxUpdateUIEvent
);
293 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_COPY
, wxClipboardTextEvent
);
294 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_CUT
, wxClipboardTextEvent
);
295 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_PASTE
, wxClipboardTextEvent
);
297 // Generic command events
298 // Note: a click is a higher-level event than button down/up
299 wxDEFINE_EVENT( wxEVT_COMMAND_LEFT_CLICK
, wxCommandEvent
);
300 wxDEFINE_EVENT( wxEVT_COMMAND_LEFT_DCLICK
, wxCommandEvent
);
301 wxDEFINE_EVENT( wxEVT_COMMAND_RIGHT_CLICK
, wxCommandEvent
);
302 wxDEFINE_EVENT( wxEVT_COMMAND_RIGHT_DCLICK
, wxCommandEvent
);
303 wxDEFINE_EVENT( wxEVT_COMMAND_SET_FOCUS
, wxCommandEvent
);
304 wxDEFINE_EVENT( wxEVT_COMMAND_KILL_FOCUS
, wxCommandEvent
);
305 wxDEFINE_EVENT( wxEVT_COMMAND_ENTER
, wxCommandEvent
);
308 wxDEFINE_EVENT( wxEVT_HELP
, wxHelpEvent
);
309 wxDEFINE_EVENT( wxEVT_DETAILED_HELP
, wxHelpEvent
);
312 wxDEFINE_EVENT( wxEVT_COMMAND_THREAD
, wxThreadEvent
);
318 wxIdleMode
wxIdleEvent::sm_idleMode
= wxIDLE_PROCESS_ALL
;
320 // ============================================================================
322 // ============================================================================
324 // ----------------------------------------------------------------------------
325 // event initialization
326 // ----------------------------------------------------------------------------
331 static int s_lastUsedEventType
= wxEVT_FIRST
;
333 return s_lastUsedEventType
++;
335 // ----------------------------------------------------------------------------
337 // ----------------------------------------------------------------------------
339 wxEventFunctor::~wxEventFunctor()
343 // ----------------------------------------------------------------------------
345 // ----------------------------------------------------------------------------
348 * General wxWidgets events, covering all interesting things that might happen
349 * (button clicking, resizing, setting text in widgets, etc.).
351 * For each completely new event type, derive a new event class.
355 wxEvent::wxEvent(int theId
, wxEventType commandType
)
357 m_eventType
= commandType
;
358 m_eventObject
= NULL
;
362 m_callbackUserData
= NULL
;
363 m_isCommandEvent
= false;
364 m_propagationLevel
= wxEVENT_PROPAGATE_NONE
;
365 m_wasProcessed
= false;
368 wxEvent::wxEvent(const wxEvent
& src
)
370 , m_eventObject(src
.m_eventObject
)
371 , m_eventType(src
.m_eventType
)
372 , m_timeStamp(src
.m_timeStamp
)
374 , m_callbackUserData(src
.m_callbackUserData
)
375 , m_propagationLevel(src
.m_propagationLevel
)
376 , m_skipped(src
.m_skipped
)
377 , m_isCommandEvent(src
.m_isCommandEvent
)
378 , m_wasProcessed(false)
382 wxEvent
& wxEvent::operator=(const wxEvent
& src
)
384 wxObject::operator=(src
);
386 m_eventObject
= src
.m_eventObject
;
387 m_eventType
= src
.m_eventType
;
388 m_timeStamp
= src
.m_timeStamp
;
390 m_callbackUserData
= src
.m_callbackUserData
;
391 m_propagationLevel
= src
.m_propagationLevel
;
392 m_skipped
= src
.m_skipped
;
393 m_isCommandEvent
= src
.m_isCommandEvent
;
395 // don't change m_wasProcessed
410 // 'this' : used in base member initializer list (for m_commandString)
411 #pragma warning(disable:4355)
414 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
415 : wxEvent(theId
, commandType
)
418 m_clientObject
= NULL
;
421 m_isCommandEvent
= true;
423 // the command events are propagated upwards by default
424 m_propagationLevel
= wxEVENT_PROPAGATE_MAX
;
428 #pragma warning(default:4355)
431 wxString
wxCommandEvent::GetString() const
433 if (m_eventType
!= wxEVT_COMMAND_TEXT_UPDATED
|| !m_eventObject
)
440 wxTextCtrl
*txt
= wxDynamicCast(m_eventObject
, wxTextCtrl
);
442 return txt
->GetValue();
444 #endif // wxUSE_TEXTCTRL
454 wxLongLong
wxUpdateUIEvent::sm_lastUpdate
= 0;
457 long wxUpdateUIEvent::sm_updateInterval
= 0;
459 wxUpdateUIMode
wxUpdateUIEvent::sm_updateMode
= wxUPDATE_UI_PROCESS_ALL
;
462 bool wxUpdateUIEvent::CanUpdate(wxWindowBase
*win
)
464 // Don't update if we've switched global updating off
465 // and this window doesn't support updates.
467 (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED
&&
468 ((win
->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES
) == 0)))
471 if (sm_updateInterval
== -1)
474 if (sm_updateInterval
== 0)
477 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
478 wxLongLong now
= wxGetLocalTimeMillis();
479 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
486 // If we don't have wxStopWatch or wxLongLong, we
487 // should err on the safe side and update now anyway.
492 // Reset the update time to provide a delay until the next
493 // time we should update
494 void wxUpdateUIEvent::ResetUpdateTime()
496 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
497 if (sm_updateInterval
> 0)
499 wxLongLong now
= wxGetLocalTimeMillis();
500 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
512 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
516 : wxCommandEvent(commandType
, id
)
518 m_extraLong
= orient
;
526 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
530 m_eventType
= commandType
;
531 m_extraLong
= orient
;
540 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
542 m_eventType
= commandType
;
548 m_middleDown
= false;
557 m_linesPerAction
= 0;
561 void wxMouseEvent::Assign(const wxMouseEvent
& event
)
563 wxEvent::operator=(event
);
565 // Borland C++ 5.82 doesn't compile an explicit call to an implicitly
566 // defined operator=() so need to do it this way:
567 *static_cast<wxMouseState
*>(this) = event
;
572 m_leftDown
= event
.m_leftDown
;
573 m_middleDown
= event
.m_middleDown
;
574 m_rightDown
= event
.m_rightDown
;
575 m_aux1Down
= event
.m_aux1Down
;
576 m_aux2Down
= event
.m_aux2Down
;
578 m_wheelRotation
= event
.m_wheelRotation
;
579 m_wheelDelta
= event
.m_wheelDelta
;
580 m_linesPerAction
= event
.m_linesPerAction
;
581 m_wheelAxis
= event
.m_wheelAxis
;
584 // return true if was a button dclick event
585 bool wxMouseEvent::ButtonDClick(int but
) const
590 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
593 case wxMOUSE_BTN_ANY
:
594 return (LeftDClick() || MiddleDClick() || RightDClick() ||
595 Aux1DClick() || Aux2DClick());
597 case wxMOUSE_BTN_LEFT
:
600 case wxMOUSE_BTN_MIDDLE
:
601 return MiddleDClick();
603 case wxMOUSE_BTN_RIGHT
:
604 return RightDClick();
606 case wxMOUSE_BTN_AUX1
:
609 case wxMOUSE_BTN_AUX2
:
614 // return true if was a button down event
615 bool wxMouseEvent::ButtonDown(int but
) const
620 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
623 case wxMOUSE_BTN_ANY
:
624 return (LeftDown() || MiddleDown() || RightDown() ||
625 Aux1Down() || Aux2Down());
627 case wxMOUSE_BTN_LEFT
:
630 case wxMOUSE_BTN_MIDDLE
:
633 case wxMOUSE_BTN_RIGHT
:
636 case wxMOUSE_BTN_AUX1
:
639 case wxMOUSE_BTN_AUX2
:
644 // return true if was a button up event
645 bool wxMouseEvent::ButtonUp(int but
) const
650 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
653 case wxMOUSE_BTN_ANY
:
654 return (LeftUp() || MiddleUp() || RightUp() ||
655 Aux1Up() || Aux2Up());
657 case wxMOUSE_BTN_LEFT
:
660 case wxMOUSE_BTN_MIDDLE
:
663 case wxMOUSE_BTN_RIGHT
:
666 case wxMOUSE_BTN_AUX1
:
669 case wxMOUSE_BTN_AUX2
:
674 // return true if the given button is currently changing state
675 bool wxMouseEvent::Button(int but
) const
680 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
683 case wxMOUSE_BTN_ANY
:
684 return ButtonUp(wxMOUSE_BTN_ANY
) ||
685 ButtonDown(wxMOUSE_BTN_ANY
) ||
686 ButtonDClick(wxMOUSE_BTN_ANY
);
688 case wxMOUSE_BTN_LEFT
:
689 return LeftDown() || LeftUp() || LeftDClick();
691 case wxMOUSE_BTN_MIDDLE
:
692 return MiddleDown() || MiddleUp() || MiddleDClick();
694 case wxMOUSE_BTN_RIGHT
:
695 return RightDown() || RightUp() || RightDClick();
697 case wxMOUSE_BTN_AUX1
:
698 return Aux1Down() || Aux1Up() || Aux1DClick();
700 case wxMOUSE_BTN_AUX2
:
701 return Aux2Down() || Aux2Up() || Aux2DClick();
705 bool wxMouseEvent::ButtonIsDown(int but
) const
710 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
713 case wxMOUSE_BTN_ANY
:
714 return LeftIsDown() || MiddleIsDown() || RightIsDown() || Aux1Down() || Aux2Down();
716 case wxMOUSE_BTN_LEFT
:
719 case wxMOUSE_BTN_MIDDLE
:
720 return MiddleIsDown();
722 case wxMOUSE_BTN_RIGHT
:
723 return RightIsDown();
725 case wxMOUSE_BTN_AUX1
:
728 case wxMOUSE_BTN_AUX2
:
733 int wxMouseEvent::GetButton() const
735 for ( int i
= 1; i
< wxMOUSE_BTN_MAX
; i
++ )
743 return wxMOUSE_BTN_NONE
;
746 // Find the logical position of the event given the DC
747 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
749 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
759 wxKeyEvent::wxKeyEvent(wxEventType type
)
769 wxKeyEvent::wxKeyEvent(const wxKeyEvent
& evt
)
776 m_keyCode
= evt
.m_keyCode
;
778 m_scanCode
= evt
.m_scanCode
;
779 m_rawCode
= evt
.m_rawCode
;
780 m_rawFlags
= evt
.m_rawFlags
;
783 m_uniChar
= evt
.m_uniChar
;
787 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
789 SetEventType(wxEVT_CREATE
);
793 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
795 SetEventType(wxEVT_DESTROY
);
799 wxChildFocusEvent::wxChildFocusEvent(wxWindow
*win
)
800 : wxCommandEvent(wxEVT_CHILD_FOCUS
)
805 // ----------------------------------------------------------------------------
807 // ----------------------------------------------------------------------------
810 wxHelpEvent::Origin
wxHelpEvent::GuessOrigin(Origin origin
)
812 if ( origin
== Origin_Unknown
)
814 // assume that the event comes from the help button if it's not from
815 // keyboard and that pressing F1 always results in the help event
816 origin
= wxGetKeyState(WXK_F1
) ? Origin_Keyboard
: Origin_HelpButton
;
827 // ----------------------------------------------------------------------------
829 // ----------------------------------------------------------------------------
831 static const int EVENT_TYPE_TABLE_INIT_SIZE
= 31; // Not too big not too small...
833 wxEventHashTable
* wxEventHashTable::sm_first
= NULL
;
835 wxEventHashTable::wxEventHashTable(const wxEventTable
&table
)
839 AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE
);
843 m_next
->m_previous
= this;
847 wxEventHashTable::~wxEventHashTable()
850 m_next
->m_previous
= m_previous
;
852 m_previous
->m_next
= m_next
;
853 if (sm_first
== this)
859 void wxEventHashTable::Clear()
861 for ( size_t i
= 0; i
< m_size
; i
++ )
863 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
867 delete[] m_eventTypeTable
;
868 m_eventTypeTable
= NULL
;
873 #if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
876 void wxEventHashTable::ClearAll()
878 wxEventHashTable
* table
= sm_first
;
882 table
= table
->m_next
;
886 #endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING
888 bool wxEventHashTable::HandleEvent(wxEvent
&event
, wxEvtHandler
*self
)
893 m_rebuildHash
= false;
896 if (!m_eventTypeTable
)
899 // Find all entries for the given event type.
900 wxEventType eventType
= event
.GetEventType();
901 const EventTypeTablePointer eTTnode
= m_eventTypeTable
[eventType
% m_size
];
902 if (eTTnode
&& eTTnode
->eventType
== eventType
)
904 // Now start the search for an event handler
905 // that can handle an event with the given ID.
906 const wxEventTableEntryPointerArray
&
907 eventEntryTable
= eTTnode
->eventEntryTable
;
909 const size_t count
= eventEntryTable
.GetCount();
910 for (size_t n
= 0; n
< count
; n
++)
912 const wxEventTableEntry
& entry
= *eventEntryTable
[n
];
913 if ( wxEvtHandler::ProcessEventIfMatchesId(entry
, self
, event
) )
921 void wxEventHashTable::InitHashTable()
923 // Loop over the event tables and all its base tables.
924 const wxEventTable
*table
= &m_table
;
927 // Retrieve all valid event handler entries
928 const wxEventTableEntry
*entry
= table
->entries
;
929 while (entry
->m_fn
!= 0)
931 // Add the event entry in the Hash.
937 table
= table
->baseTable
;
940 // Lets free some memory.
942 for(i
= 0; i
< m_size
; i
++)
944 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
947 eTTnode
->eventEntryTable
.Shrink();
952 void wxEventHashTable::AddEntry(const wxEventTableEntry
&entry
)
954 // This might happen 'accidentally' as the app is exiting
955 if (!m_eventTypeTable
)
958 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[entry
.m_eventType
% m_size
];
959 EventTypeTablePointer eTTnode
= *peTTnode
;
963 if (eTTnode
->eventType
!= entry
.m_eventType
)
966 GrowEventTypeTable();
967 // Try again to add it.
974 eTTnode
= new EventTypeTable
;
975 eTTnode
->eventType
= entry
.m_eventType
;
979 // Fill all hash entries between entry.m_id and entry.m_lastId...
980 eTTnode
->eventEntryTable
.Add(&entry
);
983 void wxEventHashTable::AllocEventTypeTable(size_t size
)
985 m_eventTypeTable
= new EventTypeTablePointer
[size
];
986 memset((void *)m_eventTypeTable
, 0, sizeof(EventTypeTablePointer
)*size
);
990 void wxEventHashTable::GrowEventTypeTable()
992 size_t oldSize
= m_size
;
993 EventTypeTablePointer
*oldEventTypeTable
= m_eventTypeTable
;
995 // TODO: Search the most optimal grow sequence
996 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize
*2+1);
998 for ( size_t i
= 0; i
< oldSize
; /* */ )
1000 EventTypeTablePointer eTToldNode
= oldEventTypeTable
[i
];
1003 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[eTToldNode
->eventType
% m_size
];
1004 EventTypeTablePointer eTTnode
= *peTTnode
;
1006 // Check for collision, we don't want any.
1009 GrowEventTypeTable();
1010 continue; // Don't increment the counter,
1011 // as we still need to add this element.
1015 // Get the old value and put it in the new table.
1016 *peTTnode
= oldEventTypeTable
[i
];
1023 delete[] oldEventTypeTable
;
1026 // ----------------------------------------------------------------------------
1028 // ----------------------------------------------------------------------------
1030 wxEvtHandler::wxEvtHandler()
1032 m_nextHandler
= NULL
;
1033 m_previousHandler
= NULL
;
1035 m_dynamicEvents
= NULL
;
1036 m_pendingEvents
= NULL
;
1038 // no client data (yet)
1039 m_clientData
= NULL
;
1040 m_clientDataType
= wxClientData_None
;
1043 wxEvtHandler::~wxEvtHandler()
1047 if (m_dynamicEvents
)
1049 for ( wxList::iterator it
= m_dynamicEvents
->begin(),
1050 end
= m_dynamicEvents
->end();
1054 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)*it
;
1056 // Remove ourselves from sink destructor notifications
1057 // (this has usually been done, in wxTrackable destructor)
1058 wxEvtHandler
*eventSink
= entry
->m_fn
->GetEvtHandler();
1061 wxEventConnectionRef
* const
1062 evtConnRef
= FindRefInTrackerList(eventSink
);
1065 eventSink
->RemoveNode(evtConnRef
);
1070 delete entry
->m_callbackUserData
;
1073 delete m_dynamicEvents
;
1076 if (m_pendingEvents
)
1077 m_pendingEvents
->DeleteContents(true);
1078 delete m_pendingEvents
;
1080 // Remove us from the list of the pending events if necessary.
1081 wxEventLoopBase
*loop
= wxEventLoopBase::GetActive();
1083 loop
->RemovePendingEventHandler(this);
1085 // we only delete object data, not untyped
1086 if ( m_clientDataType
== wxClientData_Object
)
1087 delete m_clientObject
;
1090 void wxEvtHandler::Unlink()
1092 // this event handler must take itself out of the chain of handlers:
1094 if (m_previousHandler
)
1095 m_previousHandler
->SetNextHandler(m_nextHandler
);
1098 m_nextHandler
->SetPreviousHandler(m_previousHandler
);
1100 m_nextHandler
= NULL
;
1101 m_previousHandler
= NULL
;
1104 bool wxEvtHandler::IsUnlinked() const
1106 return m_previousHandler
== NULL
&&
1107 m_nextHandler
== NULL
;
1112 bool wxEvtHandler::ProcessThreadEvent(const wxEvent
& event
)
1114 // check that we are really in a child thread
1115 wxASSERT_MSG( !wxThread::IsMain(),
1116 wxT("use ProcessEvent() in main thread") );
1118 AddPendingEvent(event
);
1123 #endif // wxUSE_THREADS
1125 void wxEvtHandler::QueueEvent(wxEvent
*event
)
1127 wxCHECK_RET( event
, "NULL event can't be posted" );
1129 wxEventLoopBase
* loop
= wxEventLoopBase::GetActive();
1132 // we need an event loop which manages the list of event handlers with
1133 // pending events... cannot proceed without it!
1134 wxLogDebug("No event loop is running!");
1138 // 1) Add this event to our list of pending events
1139 wxENTER_CRIT_SECT( m_pendingEventsLock
);
1141 if ( !m_pendingEvents
)
1142 m_pendingEvents
= new wxList
;
1144 m_pendingEvents
->Append(event
);
1146 // 2) Add this event handler to list of event handlers that
1147 // have pending events.
1149 loop
->AppendPendingEventHandler(this);
1151 // only release m_pendingEventsLock now because otherwise there is a race
1152 // condition as described in the ticket #9093: we could process the event
1153 // just added to m_pendingEvents in our ProcessPendingEvents() below before
1154 // we had time to append this pointer to wxHandlersWithPendingEvents list; thus
1155 // breaking the invariant that a handler should be in the list iff it has
1156 // any pending events to process
1157 wxLEAVE_CRIT_SECT( m_pendingEventsLock
);
1159 // 3) Inform the system that new pending events are somewhere,
1160 // and that these should be processed in idle time.
1164 void wxEvtHandler::ProcessPendingEvents()
1166 wxEventLoopBase
* loop
= wxEventLoopBase::GetActive();
1169 // we need an event loop which manages the list of event handlers with
1170 // pending events... cannot proceed without it!
1171 wxLogDebug("No event loop is running!");
1175 // we need to process only a single pending event in this call because
1176 // each call to ProcessEvent() could result in the destruction of this
1177 // same event handler (see the comment at the end of this function)
1179 wxENTER_CRIT_SECT( m_pendingEventsLock
);
1181 // this method is only called by wxApp if this handler does have
1183 wxCHECK_RET( m_pendingEvents
&& !m_pendingEvents
->IsEmpty(),
1184 "should have pending events if called" );
1186 wxList::compatibility_iterator node
= m_pendingEvents
->GetFirst();
1187 wxEvent
* pEvent
= static_cast<wxEvent
*>(node
->GetData());
1189 // find the first event which can be processed now:
1190 wxEventLoopBase
* evtLoop
= wxEventLoopBase::GetActive();
1191 if (evtLoop
&& evtLoop
->IsYielding())
1193 while (node
&& pEvent
&& !evtLoop
->IsEventAllowedInsideYield(pEvent
->GetEventCategory()))
1195 node
= node
->GetNext();
1196 pEvent
= node
? static_cast<wxEvent
*>(node
->GetData()) : NULL
;
1201 // all our events are NOT processable now... signal this:
1202 loop
->DelayPendingEventHandler(this);
1204 // see the comment at the beginning of evtloop.h header for the
1205 // logic behind YieldFor() and behind DelayPendingEventHandler()
1207 wxLEAVE_CRIT_SECT( m_pendingEventsLock
);
1213 wxEventPtr
event(pEvent
);
1215 // it's important we remove event from list before processing it, else a
1216 // nested event loop, for example from a modal dialog, might process the
1217 // same event again.
1218 m_pendingEvents
->Erase(node
);
1220 if ( m_pendingEvents
->IsEmpty() )
1222 // if there are no more pending events left, we don't need to
1223 // stay in this list
1224 loop
->RemovePendingEventHandler(this);
1227 wxLEAVE_CRIT_SECT( m_pendingEventsLock
);
1229 ProcessEvent(*event
);
1231 // careful: this object could have been deleted by the event handler
1232 // executed by the above ProcessEvent() call, so we can't access any fields
1233 // of this object any more
1240 wxEvtHandler::ProcessEventIfMatchesId(const wxEventTableEntryBase
& entry
,
1241 wxEvtHandler
*handler
,
1244 int tableId1
= entry
.m_id
,
1245 tableId2
= entry
.m_lastId
;
1247 // match only if the event type is the same and the id is either -1 in
1248 // the event table (meaning "any") or the event id matches the id
1249 // specified in the event table either exactly or by falling into
1250 // range between first and last
1251 if ((tableId1
== wxID_ANY
) ||
1252 (tableId2
== wxID_ANY
&& tableId1
== event
.GetId()) ||
1253 (tableId2
!= wxID_ANY
&&
1254 (event
.GetId() >= tableId1
&& event
.GetId() <= tableId2
)))
1257 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1259 #if wxUSE_EXCEPTIONS
1262 // call the handler via wxApp method which allows the user to catch
1263 // any exceptions which may be thrown by any handler in the program
1265 wxTheApp
->CallEventHandler(handler
, *entry
.m_fn
, event
);
1268 #endif // wxUSE_EXCEPTIONS
1270 (*entry
.m_fn
)(handler
, event
);
1273 if (!event
.GetSkipped())
1280 bool wxEvtHandler::TryParent(wxEvent
& event
)
1282 if ( GetNextHandler() )
1284 // the next handler will pass it to wxTheApp if it doesn't process it,
1285 // so return from here to avoid doing it again
1286 return GetNextHandler()->TryParent(event
);
1289 if ( wxTheApp
&& (this != wxTheApp
) )
1291 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1292 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1293 // processed appropriately via SearchEventTable.
1294 if ( event
.GetEventType() != wxEVT_IDLE
)
1296 if ( wxTheApp
->ProcessEvent(event
) )
1304 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
1306 // allow the application to hook into event processing
1308 // note that we should only do it if we're the first event handler called
1309 // to avoid calling FilterEvent() multiple times as the event goes through
1310 // the event handler chain and possibly upwards the window hierarchy
1311 if ( !event
.WasProcessed() )
1316 CANNOT ENABLE: ProcessEvent() must always immediately process the event!
1318 if (wxTheApp->IsYielding() &&
1319 !wxTheApp->IsEventAllowedInsideYield(event.GetEventCategory()))
1321 wxEvent* queuedEv = event.Clone();
1323 // queue this event rather than processing it now
1324 QueueEvent(queuedEv);
1325 // the wxWakeUpIdle call shouldn't probably be done
1326 // in this context (there's wxYield in the call stack)
1329 // it's not completely true that the event was processed;
1330 // but we cannot even say it was skipped or discarded...
1332 //else: either we're not inside a wxYield() call or if we are,
1333 // we can process this event immediately.
1336 int rc
= wxTheApp
->FilterEvent(event
);
1339 wxASSERT_MSG( rc
== 1 || rc
== 0,
1340 "unexpected wxApp::FilterEvent return value" );
1344 //else: proceed normally
1348 if ( ProcessEventHere(event
) )
1351 // pass the event to the next handler, notice that we shouldn't call
1352 // TryParent() even if it doesn't handle the event as the last handler in
1353 // the chain will do it
1354 if ( GetNextHandler() )
1355 return GetNextHandler()->ProcessEvent(event
);
1357 // propagate the event upwards the window chain and/or to the application
1358 // object if it wasn't processed at this level
1359 return TryParent(event
);
1362 bool wxEvtHandler::ProcessEventHere(wxEvent
& event
)
1364 // If the event handler is disabled it doesn't process any events
1365 if ( !GetEvtHandlerEnabled() )
1368 // If we have a validator, it has higher priority than our own event
1370 if ( TryValidator(event
) )
1373 // Handle per-instance dynamic event tables first
1374 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
1377 // Then static per-class event tables
1378 if ( GetEventHashTable().HandleEvent(event
, this) )
1381 // We don't have a handler for this event.
1385 bool wxEvtHandler::SafelyProcessEvent(wxEvent
& event
)
1387 #if wxUSE_EXCEPTIONS
1391 return ProcessEvent(event
);
1392 #if wxUSE_EXCEPTIONS
1396 wxEventLoopBase
*loop
= wxEventLoopBase::GetActive();
1399 if ( !wxTheApp
|| !wxTheApp
->OnExceptionInMainLoop() )
1404 //else: continue running current event loop
1410 // OnExceptionInMainLoop() threw, possibly rethrowing the same
1411 // exception again: very good, but we still need Exit() to
1418 #endif // wxUSE_EXCEPTIONS
1422 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
1424 const wxEventType eventType
= event
.GetEventType();
1425 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
1427 const wxEventTableEntry
& entry
= table
.entries
[i
];
1428 if ( eventType
== entry
.m_eventType
)
1430 if ( ProcessEventIfMatchesId(entry
, this, event
) )
1438 void wxEvtHandler::DoConnect(int id
,
1440 wxEventType eventType
,
1441 wxEventFunctor
*func
,
1444 wxDynamicEventTableEntry
*entry
=
1445 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
);
1447 if (!m_dynamicEvents
)
1448 m_dynamicEvents
= new wxList
;
1450 // Insert at the front of the list so most recent additions are found first
1451 m_dynamicEvents
->Insert( (wxObject
*) entry
);
1453 // Make sure we get to know when a sink is destroyed
1454 wxEvtHandler
*eventSink
= func
->GetEvtHandler();
1455 if ( eventSink
&& eventSink
!= this )
1457 wxEventConnectionRef
*evtConnRef
= FindRefInTrackerList(eventSink
);
1459 evtConnRef
->IncRef( );
1461 new wxEventConnectionRef(this, eventSink
);
1466 wxEvtHandler::DoDisconnect(int id
,
1468 wxEventType eventType
,
1469 const wxEventFunctor
& func
,
1472 if (!m_dynamicEvents
)
1475 // Remove connection from tracker node (wxEventConnectionRef)
1476 wxEvtHandler
*eventSink
= func
.GetEvtHandler();
1477 if ( eventSink
&& eventSink
!= this )
1479 wxEventConnectionRef
*evtConnRef
= FindRefInTrackerList(eventSink
);
1481 evtConnRef
->DecRef();
1484 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1487 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1489 if ((entry
->m_id
== id
) &&
1490 ((entry
->m_lastId
== lastId
) || (lastId
== wxID_ANY
)) &&
1491 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1492 entry
->m_fn
->Matches(func
) &&
1493 ((entry
->m_callbackUserData
== userData
) || !userData
))
1495 delete entry
->m_callbackUserData
;
1496 m_dynamicEvents
->Erase( node
);
1500 node
= node
->GetNext();
1505 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1507 wxCHECK_MSG( m_dynamicEvents
, false,
1508 wxT("caller should check that we have dynamic events") );
1510 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1513 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1515 // get next node before (maybe) calling the event handler as it could
1516 // call Disconnect() invalidating the current node
1517 node
= node
->GetNext();
1519 if ( event
.GetEventType() == entry
->m_eventType
)
1521 wxEvtHandler
*handler
= entry
->m_fn
->GetEvtHandler();
1524 if ( ProcessEventIfMatchesId(*entry
, handler
, event
) )
1532 void wxEvtHandler::DoSetClientObject( wxClientData
*data
)
1534 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1535 wxT("can't have both object and void client data") );
1537 if ( m_clientObject
)
1538 delete m_clientObject
;
1540 m_clientObject
= data
;
1541 m_clientDataType
= wxClientData_Object
;
1544 wxClientData
*wxEvtHandler::DoGetClientObject() const
1546 // it's not an error to call GetClientObject() on a window which doesn't
1547 // have client data at all - NULL will be returned
1548 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1549 wxT("this window doesn't have object client data") );
1551 return m_clientObject
;
1554 void wxEvtHandler::DoSetClientData( void *data
)
1556 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1557 wxT("can't have both object and void client data") );
1559 m_clientData
= data
;
1560 m_clientDataType
= wxClientData_Void
;
1563 void *wxEvtHandler::DoGetClientData() const
1565 // it's not an error to call GetClientData() on a window which doesn't have
1566 // client data at all - NULL will be returned
1567 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1568 wxT("this window doesn't have void client data") );
1570 return m_clientData
;
1573 // A helper to find an wxEventConnectionRef object
1574 wxEventConnectionRef
*
1575 wxEvtHandler::FindRefInTrackerList(wxEvtHandler
*eventSink
)
1577 for ( wxTrackerNode
*node
= eventSink
->GetFirst(); node
; node
= node
->m_nxt
)
1579 // we only want wxEventConnectionRef nodes here
1580 wxEventConnectionRef
*evtConnRef
= node
->ToEventConnection();
1581 if ( evtConnRef
&& evtConnRef
->m_src
== this )
1583 wxASSERT( evtConnRef
->m_sink
==eventSink
);
1591 void wxEvtHandler::OnSinkDestroyed( wxEvtHandler
*sink
)
1593 wxASSERT(m_dynamicEvents
);
1595 // remove all connections with this sink
1596 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst(), node_nxt
;
1599 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1600 node_nxt
= node
->GetNext();
1602 if ( entry
->m_fn
->GetEvtHandler() == sink
)
1604 delete entry
->m_callbackUserData
;
1605 m_dynamicEvents
->Erase( node
);
1612 #endif // wxUSE_BASE
1616 // Find a window with the focus, that is also a descendant of the given window.
1617 // This is used to determine the window to initially send commands to.
1618 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1620 // Process events starting with the window with the focus, if any.
1621 wxWindow
* focusWin
= wxWindow::FindFocus();
1622 wxWindow
* win
= focusWin
;
1624 // Check if this is a descendant of this frame.
1625 // If not, win will be set to NULL.
1628 if (win
== ancestor
)
1631 win
= win
->GetParent();
1639 // ----------------------------------------------------------------------------
1641 // ----------------------------------------------------------------------------
1643 wxEventBlocker::wxEventBlocker(wxWindow
*win
, wxEventType type
)
1645 wxCHECK_RET(win
, wxT("Null window given to wxEventBlocker"));
1650 m_window
->PushEventHandler(this);
1653 wxEventBlocker::~wxEventBlocker()
1655 wxEvtHandler
*popped
= m_window
->PopEventHandler(false);
1656 wxCHECK_RET(popped
== this,
1657 wxT("Don't push other event handlers into a window managed by wxEventBlocker!"));
1660 bool wxEventBlocker::ProcessEvent(wxEvent
& event
)
1662 // should this event be blocked?
1663 for ( size_t i
= 0; i
< m_eventsToBlock
.size(); i
++ )
1665 wxEventType t
= (wxEventType
)m_eventsToBlock
[i
];
1666 if ( t
== wxEVT_ANY
|| t
== event
.GetEventType() )
1667 return true; // yes, it should: mark this event as processed