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"
35 #include "wx/stopwatch.h"
36 #include "wx/module.h"
39 #include "wx/window.h"
40 #include "wx/control.h"
42 #include "wx/spinbutt.h"
43 #include "wx/textctrl.h"
44 #include "wx/validate.h"
48 #include "wx/thread.h"
51 #include "wx/scopedptr.h"
53 wxDECLARE_SCOPED_PTR(wxEvent
, wxEventPtr
)
54 wxDEFINE_SCOPED_PTR(wxEvent
, wxEventPtr
)
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
62 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler
, wxObject
)
63 IMPLEMENT_ABSTRACT_CLASS(wxEvent
, wxObject
)
64 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent
, wxEvent
)
65 IMPLEMENT_DYNAMIC_CLASS(wxThreadEvent
, wxEvent
)
69 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent
, wxEvent
)
70 IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent
, wxCommandEvent
)
71 IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent
, wxCommandEvent
)
72 IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent
, wxEvent
)
73 IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent
, wxEvent
)
74 IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent
, wxEvent
)
75 IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent
, wxEvent
)
76 IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent
, wxEvent
)
77 IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent
, wxEvent
)
78 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent
, wxEvent
)
79 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent
, wxEvent
)
80 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent
, wxEvent
)
81 IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent
, wxCommandEvent
)
82 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent
, wxEvent
)
83 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent
, wxEvent
)
84 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent
, wxEvent
)
85 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent
, wxEvent
)
86 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent
, wxEvent
)
87 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent
, wxEvent
)
88 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent
, wxEvent
)
89 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent
, wxEvent
)
90 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent
, wxEvent
)
91 IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent
, wxEvent
)
92 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent
, wxEvent
)
93 IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent
, wxEvent
)
94 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent
, wxCommandEvent
)
95 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent
, wxEvent
)
96 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent
, wxEvent
)
97 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent
, wxEvent
)
98 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent
, wxEvent
)
99 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent
, wxEvent
)
100 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent
, wxCommandEvent
)
101 IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent
, wxCommandEvent
)
102 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent
, wxEvent
)
103 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureLostEvent
, wxEvent
)
104 IMPLEMENT_DYNAMIC_CLASS(wxClipboardTextEvent
, wxCommandEvent
)
109 const wxEventTable
*wxEvtHandler::GetEventTable() const
110 { return &wxEvtHandler::sm_eventTable
; }
112 const wxEventTable
wxEvtHandler::sm_eventTable
=
113 { (const wxEventTable
*)NULL
, &wxEvtHandler::sm_eventTableEntries
[0] };
115 wxEventHashTable
&wxEvtHandler::GetEventHashTable() const
116 { return wxEvtHandler::sm_eventHashTable
; }
118 wxEventHashTable
wxEvtHandler::sm_eventHashTable(wxEvtHandler::sm_eventTable
);
120 const wxEventTableEntry
wxEvtHandler::sm_eventTableEntries
[] =
121 { wxDECLARE_EVENT_TABLE_TERMINATOR() };
124 // wxUSE_MEMORY_TRACING considers memory freed from the static objects dtors
125 // leaked, so we need to manually clean up all event tables before checking for
126 // the memory leaks when using it, however this breaks re-initializing the
127 // library (i.e. repeated calls to wxInitialize/wxUninitialize) because the
128 // event tables won't be rebuilt the next time, so disable this by default
129 #if wxUSE_MEMORY_TRACING
131 class wxEventTableEntryModule
: public wxModule
134 wxEventTableEntryModule() { }
135 virtual bool OnInit() { return true; }
136 virtual void OnExit() { wxEventHashTable::ClearAll(); }
138 DECLARE_DYNAMIC_CLASS(wxEventTableEntryModule
)
141 IMPLEMENT_DYNAMIC_CLASS(wxEventTableEntryModule
, wxModule
)
143 #endif // wxUSE_MEMORY_TRACING
145 // ----------------------------------------------------------------------------
147 // ----------------------------------------------------------------------------
149 // common event types are defined here, other event types are defined by the
150 // components which use them
152 const wxEventType wxEVT_FIRST
= 10000;
153 const wxEventType wxEVT_USER_FIRST
= wxEVT_FIRST
+ 2000;
154 const wxEventType wxEVT_NULL
= wxNewEventType();
156 wxDEFINE_EVENT( wxEVT_IDLE
, wxIdleEvent
);
159 wxDEFINE_EVENT( wxEVT_THREAD
, wxThreadEvent
);
165 wxDEFINE_EVENT( wxEVT_COMMAND_BUTTON_CLICKED
, wxCommandEvent
);
166 wxDEFINE_EVENT( wxEVT_COMMAND_CHECKBOX_CLICKED
, wxCommandEvent
);
167 wxDEFINE_EVENT( wxEVT_COMMAND_CHOICE_SELECTED
, wxCommandEvent
);
168 wxDEFINE_EVENT( wxEVT_COMMAND_LISTBOX_SELECTED
, wxCommandEvent
);
169 wxDEFINE_EVENT( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
, wxCommandEvent
);
170 wxDEFINE_EVENT( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, wxCommandEvent
);
171 wxDEFINE_EVENT( wxEVT_COMMAND_MENU_SELECTED
, wxCommandEvent
);
172 wxDEFINE_EVENT( wxEVT_COMMAND_SLIDER_UPDATED
, wxCommandEvent
);
173 wxDEFINE_EVENT( wxEVT_COMMAND_RADIOBOX_SELECTED
, wxCommandEvent
);
174 wxDEFINE_EVENT( wxEVT_COMMAND_RADIOBUTTON_SELECTED
, wxCommandEvent
);
175 wxDEFINE_EVENT( wxEVT_COMMAND_SCROLLBAR_UPDATED
, wxCommandEvent
);
176 wxDEFINE_EVENT( wxEVT_COMMAND_VLBOX_SELECTED
, wxCommandEvent
);
177 wxDEFINE_EVENT( wxEVT_COMMAND_COMBOBOX_SELECTED
, wxCommandEvent
);
178 wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_RCLICKED
, wxCommandEvent
);
179 wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_ENTER
, wxCommandEvent
);
180 wxDEFINE_EVENT( wxEVT_COMMAND_SPINCTRL_UPDATED
, wxCommandEvent
);
181 wxDEFINE_EVENT( wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED
, wxCommandEvent
);
182 wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED
, wxCommandEvent
);
183 wxDEFINE_EVENT( wxEVT_COMMAND_COMBOBOX_DROPDOWN
, wxCommandEvent
);
184 wxDEFINE_EVENT( wxEVT_COMMAND_COMBOBOX_CLOSEUP
, wxCommandEvent
);
187 wxDEFINE_EVENT( wxEVT_LEFT_DOWN
, wxMouseEvent
);
188 wxDEFINE_EVENT( wxEVT_LEFT_UP
, wxMouseEvent
);
189 wxDEFINE_EVENT( wxEVT_MIDDLE_DOWN
, wxMouseEvent
);
190 wxDEFINE_EVENT( wxEVT_MIDDLE_UP
, wxMouseEvent
);
191 wxDEFINE_EVENT( wxEVT_RIGHT_DOWN
, wxMouseEvent
);
192 wxDEFINE_EVENT( wxEVT_RIGHT_UP
, wxMouseEvent
);
193 wxDEFINE_EVENT( wxEVT_MOTION
, wxMouseEvent
);
194 wxDEFINE_EVENT( wxEVT_ENTER_WINDOW
, wxMouseEvent
);
195 wxDEFINE_EVENT( wxEVT_LEAVE_WINDOW
, wxMouseEvent
);
196 wxDEFINE_EVENT( wxEVT_LEFT_DCLICK
, wxMouseEvent
);
197 wxDEFINE_EVENT( wxEVT_MIDDLE_DCLICK
, wxMouseEvent
);
198 wxDEFINE_EVENT( wxEVT_RIGHT_DCLICK
, wxMouseEvent
);
199 wxDEFINE_EVENT( wxEVT_SET_FOCUS
, wxFocusEvent
);
200 wxDEFINE_EVENT( wxEVT_KILL_FOCUS
, wxFocusEvent
);
201 wxDEFINE_EVENT( wxEVT_CHILD_FOCUS
, wxChildFocusEvent
);
202 wxDEFINE_EVENT( wxEVT_MOUSEWHEEL
, wxMouseEvent
);
203 wxDEFINE_EVENT( wxEVT_AUX1_DOWN
, wxMouseEvent
);
204 wxDEFINE_EVENT( wxEVT_AUX1_UP
, wxMouseEvent
);
205 wxDEFINE_EVENT( wxEVT_AUX1_DCLICK
, wxMouseEvent
);
206 wxDEFINE_EVENT( wxEVT_AUX2_DOWN
, wxMouseEvent
);
207 wxDEFINE_EVENT( wxEVT_AUX2_UP
, wxMouseEvent
);
208 wxDEFINE_EVENT( wxEVT_AUX2_DCLICK
, wxMouseEvent
);
210 // Character input event type
211 wxDEFINE_EVENT( wxEVT_CHAR
, wxKeyEvent
);
212 wxDEFINE_EVENT( wxEVT_AFTER_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 // Due to a bug in older wx versions, wxSpinEvents were being sent with type of
236 // wxEVT_SCROLL_LINEUP, wxEVT_SCROLL_LINEDOWN and wxEVT_SCROLL_THUMBTRACK. But
237 // with the type-safe events in place, these event types are associated with
238 // wxScrollEvent. To allow handling of spin events, new event types have been
239 // defined in spinbutt.h/spinnbuttcmn.cpp. To maintain backward compatibility
240 // the spin event types are being initialized with the scroll event types.
244 wxDEFINE_EVENT_ALIAS( wxEVT_SPIN_UP
, wxSpinEvent
, wxEVT_SCROLL_LINEUP
);
245 wxDEFINE_EVENT_ALIAS( wxEVT_SPIN_DOWN
, wxSpinEvent
, wxEVT_SCROLL_LINEDOWN
);
246 wxDEFINE_EVENT_ALIAS( wxEVT_SPIN
, wxSpinEvent
, wxEVT_SCROLL_THUMBTRACK
);
248 #endif // wxUSE_SPINBTN
250 // Scroll events from wxWindow
251 wxDEFINE_EVENT( wxEVT_SCROLLWIN_TOP
, wxScrollWinEvent
);
252 wxDEFINE_EVENT( wxEVT_SCROLLWIN_BOTTOM
, wxScrollWinEvent
);
253 wxDEFINE_EVENT( wxEVT_SCROLLWIN_LINEUP
, wxScrollWinEvent
);
254 wxDEFINE_EVENT( wxEVT_SCROLLWIN_LINEDOWN
, wxScrollWinEvent
);
255 wxDEFINE_EVENT( wxEVT_SCROLLWIN_PAGEUP
, wxScrollWinEvent
);
256 wxDEFINE_EVENT( wxEVT_SCROLLWIN_PAGEDOWN
, wxScrollWinEvent
);
257 wxDEFINE_EVENT( wxEVT_SCROLLWIN_THUMBTRACK
, wxScrollWinEvent
);
258 wxDEFINE_EVENT( wxEVT_SCROLLWIN_THUMBRELEASE
, wxScrollWinEvent
);
261 wxDEFINE_EVENT( wxEVT_SIZE
, wxSizeEvent
);
262 wxDEFINE_EVENT( wxEVT_SIZING
, wxSizeEvent
);
263 wxDEFINE_EVENT( wxEVT_MOVE
, wxMoveEvent
);
264 wxDEFINE_EVENT( wxEVT_MOVING
, wxMoveEvent
);
265 wxDEFINE_EVENT( wxEVT_MOVE_START
, wxMoveEvent
);
266 wxDEFINE_EVENT( wxEVT_MOVE_END
, wxMoveEvent
);
267 wxDEFINE_EVENT( wxEVT_CLOSE_WINDOW
, wxCloseEvent
);
268 wxDEFINE_EVENT( wxEVT_END_SESSION
, wxCloseEvent
);
269 wxDEFINE_EVENT( wxEVT_QUERY_END_SESSION
, wxCloseEvent
);
270 wxDEFINE_EVENT( wxEVT_HIBERNATE
, wxActivateEvent
);
271 wxDEFINE_EVENT( wxEVT_ACTIVATE_APP
, wxActivateEvent
);
272 wxDEFINE_EVENT( wxEVT_ACTIVATE
, wxActivateEvent
);
273 wxDEFINE_EVENT( wxEVT_CREATE
, wxWindowCreateEvent
);
274 wxDEFINE_EVENT( wxEVT_DESTROY
, wxWindowDestroyEvent
);
275 wxDEFINE_EVENT( wxEVT_SHOW
, wxShowEvent
);
276 wxDEFINE_EVENT( wxEVT_ICONIZE
, wxIconizeEvent
);
277 wxDEFINE_EVENT( wxEVT_MAXIMIZE
, wxMaximizeEvent
);
278 wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_CHANGED
, wxMouseCaptureChangedEvent
);
279 wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_LOST
, wxMouseCaptureLostEvent
);
280 wxDEFINE_EVENT( wxEVT_PAINT
, wxPaintEvent
);
281 wxDEFINE_EVENT( wxEVT_ERASE_BACKGROUND
, wxEraseEvent
);
282 wxDEFINE_EVENT( wxEVT_NC_PAINT
, wxNcPaintEvent
);
283 wxDEFINE_EVENT( wxEVT_MENU_OPEN
, wxMenuEvent
);
284 wxDEFINE_EVENT( wxEVT_MENU_CLOSE
, wxMenuEvent
);
285 wxDEFINE_EVENT( wxEVT_MENU_HIGHLIGHT
, wxMenuEvent
);
286 wxDEFINE_EVENT( wxEVT_CONTEXT_MENU
, wxContextMenuEvent
);
287 wxDEFINE_EVENT( wxEVT_SYS_COLOUR_CHANGED
, wxSysColourChangedEvent
);
288 wxDEFINE_EVENT( wxEVT_DISPLAY_CHANGED
, wxDisplayChangedEvent
);
289 wxDEFINE_EVENT( wxEVT_QUERY_NEW_PALETTE
, wxQueryNewPaletteEvent
);
290 wxDEFINE_EVENT( wxEVT_PALETTE_CHANGED
, wxPaletteChangedEvent
);
291 wxDEFINE_EVENT( wxEVT_JOY_BUTTON_DOWN
, wxJoystickEvent
);
292 wxDEFINE_EVENT( wxEVT_JOY_BUTTON_UP
, wxJoystickEvent
);
293 wxDEFINE_EVENT( wxEVT_JOY_MOVE
, wxJoystickEvent
);
294 wxDEFINE_EVENT( wxEVT_JOY_ZMOVE
, wxJoystickEvent
);
295 wxDEFINE_EVENT( wxEVT_DROP_FILES
, wxDropFilesEvent
);
296 wxDEFINE_EVENT( wxEVT_INIT_DIALOG
, wxInitDialogEvent
);
297 wxDEFINE_EVENT( wxEVT_UPDATE_UI
, wxUpdateUIEvent
);
300 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_COPY
, wxClipboardTextEvent
);
301 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_CUT
, wxClipboardTextEvent
);
302 wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_PASTE
, wxClipboardTextEvent
);
304 // Generic command events
305 // Note: a click is a higher-level event than button down/up
306 wxDEFINE_EVENT( wxEVT_COMMAND_LEFT_CLICK
, wxCommandEvent
);
307 wxDEFINE_EVENT( wxEVT_COMMAND_LEFT_DCLICK
, wxCommandEvent
);
308 wxDEFINE_EVENT( wxEVT_COMMAND_RIGHT_CLICK
, wxCommandEvent
);
309 wxDEFINE_EVENT( wxEVT_COMMAND_RIGHT_DCLICK
, wxCommandEvent
);
310 wxDEFINE_EVENT( wxEVT_COMMAND_SET_FOCUS
, wxCommandEvent
);
311 wxDEFINE_EVENT( wxEVT_COMMAND_KILL_FOCUS
, wxCommandEvent
);
312 wxDEFINE_EVENT( wxEVT_COMMAND_ENTER
, wxCommandEvent
);
315 wxDEFINE_EVENT( wxEVT_HELP
, wxHelpEvent
);
316 wxDEFINE_EVENT( wxEVT_DETAILED_HELP
, wxHelpEvent
);
322 wxIdleMode
wxIdleEvent::sm_idleMode
= wxIDLE_PROCESS_ALL
;
324 // ============================================================================
326 // ============================================================================
328 // ----------------------------------------------------------------------------
329 // event initialization
330 // ----------------------------------------------------------------------------
335 static int s_lastUsedEventType
= wxEVT_FIRST
;
337 return s_lastUsedEventType
++;
339 // ----------------------------------------------------------------------------
341 // ----------------------------------------------------------------------------
343 wxEventFunctor::~wxEventFunctor()
347 // ----------------------------------------------------------------------------
349 // ----------------------------------------------------------------------------
352 * General wxWidgets events, covering all interesting things that might happen
353 * (button clicking, resizing, setting text in widgets, etc.).
355 * For each completely new event type, derive a new event class.
359 wxEvent::wxEvent(int theId
, wxEventType commandType
)
361 m_eventType
= commandType
;
362 m_eventObject
= NULL
;
366 m_callbackUserData
= NULL
;
367 m_handlerToProcessOnlyIn
= NULL
;
368 m_isCommandEvent
= false;
369 m_propagationLevel
= wxEVENT_PROPAGATE_NONE
;
370 m_wasProcessed
= false;
373 wxEvent::wxEvent(const wxEvent
& src
)
375 , m_eventObject(src
.m_eventObject
)
376 , m_eventType(src
.m_eventType
)
377 , m_timeStamp(src
.m_timeStamp
)
379 , m_callbackUserData(src
.m_callbackUserData
)
380 , m_handlerToProcessOnlyIn(NULL
)
381 , m_propagationLevel(src
.m_propagationLevel
)
382 , m_skipped(src
.m_skipped
)
383 , m_isCommandEvent(src
.m_isCommandEvent
)
384 , m_wasProcessed(false)
388 wxEvent
& wxEvent::operator=(const wxEvent
& src
)
390 wxObject::operator=(src
);
392 m_eventObject
= src
.m_eventObject
;
393 m_eventType
= src
.m_eventType
;
394 m_timeStamp
= src
.m_timeStamp
;
396 m_callbackUserData
= src
.m_callbackUserData
;
397 m_handlerToProcessOnlyIn
= NULL
;
398 m_propagationLevel
= src
.m_propagationLevel
;
399 m_skipped
= src
.m_skipped
;
400 m_isCommandEvent
= src
.m_isCommandEvent
;
402 // don't change m_wasProcessed
411 // ----------------------------------------------------------------------------
413 // ----------------------------------------------------------------------------
416 // 'this' : used in base member initializer list (for m_commandString)
417 #pragma warning(disable:4355)
420 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
421 : wxEvent(theId
, commandType
)
424 m_clientObject
= NULL
;
425 m_isCommandEvent
= true;
427 // the command events are propagated upwards by default
428 m_propagationLevel
= wxEVENT_PROPAGATE_MAX
;
432 #pragma warning(default:4355)
435 wxString
wxCommandEvent::GetString() const
437 if (m_eventType
!= wxEVT_COMMAND_TEXT_UPDATED
|| !m_eventObject
)
444 wxTextCtrl
*txt
= wxDynamicCast(m_eventObject
, wxTextCtrl
);
446 return txt
->GetValue();
448 #endif // wxUSE_TEXTCTRL
453 // ----------------------------------------------------------------------------
455 // ----------------------------------------------------------------------------
458 wxLongLong
wxUpdateUIEvent::sm_lastUpdate
= 0;
461 long wxUpdateUIEvent::sm_updateInterval
= 0;
463 wxUpdateUIMode
wxUpdateUIEvent::sm_updateMode
= wxUPDATE_UI_PROCESS_ALL
;
466 bool wxUpdateUIEvent::CanUpdate(wxWindowBase
*win
)
468 // Don't update if we've switched global updating off
469 // and this window doesn't support updates.
471 (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED
&&
472 ((win
->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES
) == 0)))
475 // Don't update children of the hidden windows: this is useless as any
476 // change to their state won't be seen by the user anyhow. Notice that this
477 // argument doesn't apply to the hidden windows (with visible parent)
478 // themselves as they could be shown by their EVT_UPDATE_UI handler.
479 if ( win
->GetParent() && !win
->GetParent()->IsShownOnScreen() )
482 if (sm_updateInterval
== -1)
485 if (sm_updateInterval
== 0)
488 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
489 wxLongLong now
= wxGetLocalTimeMillis();
490 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
497 // If we don't have wxStopWatch or wxLongLong, we
498 // should err on the safe side and update now anyway.
503 // Reset the update time to provide a delay until the next
504 // time we should update
505 void wxUpdateUIEvent::ResetUpdateTime()
507 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
508 if (sm_updateInterval
> 0)
510 wxLongLong now
= wxGetLocalTimeMillis();
511 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
519 // ----------------------------------------------------------------------------
521 // ----------------------------------------------------------------------------
523 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
527 : wxCommandEvent(commandType
, id
)
529 m_extraLong
= orient
;
533 // ----------------------------------------------------------------------------
535 // ----------------------------------------------------------------------------
537 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
541 m_eventType
= commandType
;
542 m_extraLong
= orient
;
546 // ----------------------------------------------------------------------------
548 // ----------------------------------------------------------------------------
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 int wxMouseEvent::GetButton() const
717 for ( int i
= 1; i
< wxMOUSE_BTN_MAX
; i
++ )
725 return wxMOUSE_BTN_NONE
;
728 // Find the logical position of the event given the DC
729 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
731 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
735 // ----------------------------------------------------------------------------
737 // ----------------------------------------------------------------------------
739 wxKeyEvent::wxKeyEvent(wxEventType type
)
742 m_keyCode
= WXK_NONE
;
744 m_uniChar
= WXK_NONE
;
748 wxKeyEvent::wxKeyEvent(const wxKeyEvent
& evt
)
755 m_keyCode
= evt
.m_keyCode
;
756 m_rawCode
= evt
.m_rawCode
;
757 m_rawFlags
= evt
.m_rawFlags
;
760 m_uniChar
= evt
.m_uniChar
;
764 bool wxKeyEvent::IsKeyInCategory(int category
) const
766 switch ( GetKeyCode() )
772 case WXK_NUMPAD_LEFT
:
773 case WXK_NUMPAD_RIGHT
:
775 case WXK_NUMPAD_DOWN
:
776 return (category
& WXK_CATEGORY_ARROW
) != 0;
780 case WXK_NUMPAD_PAGEUP
:
781 case WXK_NUMPAD_PAGEDOWN
:
782 return (category
& WXK_CATEGORY_PAGING
) != 0;
786 case WXK_NUMPAD_HOME
:
788 return (category
& WXK_CATEGORY_JUMP
) != 0;
792 return (category
& WXK_CATEGORY_TAB
) != 0;
796 case WXK_NUMPAD_DELETE
:
797 return (category
& WXK_CATEGORY_CUT
) != 0;
804 // ----------------------------------------------------------------------------
805 // wxWindowCreateEvent
806 // ----------------------------------------------------------------------------
808 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
810 SetEventType(wxEVT_CREATE
);
814 // ----------------------------------------------------------------------------
815 // wxWindowDestroyEvent
816 // ----------------------------------------------------------------------------
818 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
820 SetEventType(wxEVT_DESTROY
);
824 // ----------------------------------------------------------------------------
826 // ----------------------------------------------------------------------------
828 wxChildFocusEvent::wxChildFocusEvent(wxWindow
*win
)
829 : wxCommandEvent(wxEVT_CHILD_FOCUS
)
834 // ----------------------------------------------------------------------------
836 // ----------------------------------------------------------------------------
839 wxHelpEvent::Origin
wxHelpEvent::GuessOrigin(Origin origin
)
841 if ( origin
== Origin_Unknown
)
843 // assume that the event comes from the help button if it's not from
844 // keyboard and that pressing F1 always results in the help event
845 origin
= wxGetKeyState(WXK_F1
) ? Origin_Keyboard
: Origin_HelpButton
;
856 // ----------------------------------------------------------------------------
858 // ----------------------------------------------------------------------------
860 static const int EVENT_TYPE_TABLE_INIT_SIZE
= 31; // Not too big not too small...
862 wxEventHashTable
* wxEventHashTable::sm_first
= NULL
;
864 wxEventHashTable::wxEventHashTable(const wxEventTable
&table
)
868 AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE
);
872 m_next
->m_previous
= this;
876 wxEventHashTable::~wxEventHashTable()
879 m_next
->m_previous
= m_previous
;
881 m_previous
->m_next
= m_next
;
882 if (sm_first
== this)
888 void wxEventHashTable::Clear()
890 for ( size_t i
= 0; i
< m_size
; i
++ )
892 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
896 wxDELETEA(m_eventTypeTable
);
901 #if wxUSE_MEMORY_TRACING
904 void wxEventHashTable::ClearAll()
906 wxEventHashTable
* table
= sm_first
;
910 table
= table
->m_next
;
914 #endif // wxUSE_MEMORY_TRACING
916 bool wxEventHashTable::HandleEvent(wxEvent
&event
, wxEvtHandler
*self
)
921 m_rebuildHash
= false;
924 if (!m_eventTypeTable
)
927 // Find all entries for the given event type.
928 wxEventType eventType
= event
.GetEventType();
929 const EventTypeTablePointer eTTnode
= m_eventTypeTable
[eventType
% m_size
];
930 if (eTTnode
&& eTTnode
->eventType
== eventType
)
932 // Now start the search for an event handler
933 // that can handle an event with the given ID.
934 const wxEventTableEntryPointerArray
&
935 eventEntryTable
= eTTnode
->eventEntryTable
;
937 const size_t count
= eventEntryTable
.GetCount();
938 for (size_t n
= 0; n
< count
; n
++)
940 const wxEventTableEntry
& entry
= *eventEntryTable
[n
];
941 if ( wxEvtHandler::ProcessEventIfMatchesId(entry
, self
, event
) )
949 void wxEventHashTable::InitHashTable()
951 // Loop over the event tables and all its base tables.
952 const wxEventTable
*table
= &m_table
;
955 // Retrieve all valid event handler entries
956 const wxEventTableEntry
*entry
= table
->entries
;
957 while (entry
->m_fn
!= 0)
959 // Add the event entry in the Hash.
965 table
= table
->baseTable
;
968 // Let's free some memory.
970 for(i
= 0; i
< m_size
; i
++)
972 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
975 eTTnode
->eventEntryTable
.Shrink();
980 void wxEventHashTable::AddEntry(const wxEventTableEntry
&entry
)
982 // This might happen 'accidentally' as the app is exiting
983 if (!m_eventTypeTable
)
986 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[entry
.m_eventType
% m_size
];
987 EventTypeTablePointer eTTnode
= *peTTnode
;
991 if (eTTnode
->eventType
!= entry
.m_eventType
)
994 GrowEventTypeTable();
995 // Try again to add it.
1002 eTTnode
= new EventTypeTable
;
1003 eTTnode
->eventType
= entry
.m_eventType
;
1004 *peTTnode
= eTTnode
;
1007 // Fill all hash entries between entry.m_id and entry.m_lastId...
1008 eTTnode
->eventEntryTable
.Add(&entry
);
1011 void wxEventHashTable::AllocEventTypeTable(size_t size
)
1013 m_eventTypeTable
= new EventTypeTablePointer
[size
];
1014 memset((void *)m_eventTypeTable
, 0, sizeof(EventTypeTablePointer
)*size
);
1018 void wxEventHashTable::GrowEventTypeTable()
1020 size_t oldSize
= m_size
;
1021 EventTypeTablePointer
*oldEventTypeTable
= m_eventTypeTable
;
1023 // TODO: Search the most optimal grow sequence
1024 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize
*2+1);
1026 for ( size_t i
= 0; i
< oldSize
; /* */ )
1028 EventTypeTablePointer eTToldNode
= oldEventTypeTable
[i
];
1031 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[eTToldNode
->eventType
% m_size
];
1032 EventTypeTablePointer eTTnode
= *peTTnode
;
1034 // Check for collision, we don't want any.
1037 GrowEventTypeTable();
1038 continue; // Don't increment the counter,
1039 // as we still need to add this element.
1043 // Get the old value and put it in the new table.
1044 *peTTnode
= oldEventTypeTable
[i
];
1051 delete[] oldEventTypeTable
;
1054 // ----------------------------------------------------------------------------
1056 // ----------------------------------------------------------------------------
1058 wxEvtHandler::wxEvtHandler()
1060 m_nextHandler
= NULL
;
1061 m_previousHandler
= NULL
;
1063 m_dynamicEvents
= NULL
;
1064 m_pendingEvents
= NULL
;
1066 // no client data (yet)
1067 m_clientData
= NULL
;
1068 m_clientDataType
= wxClientData_None
;
1071 wxEvtHandler::~wxEvtHandler()
1075 if (m_dynamicEvents
)
1077 for ( wxList::iterator it
= m_dynamicEvents
->begin(),
1078 end
= m_dynamicEvents
->end();
1082 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)*it
;
1084 // Remove ourselves from sink destructor notifications
1085 // (this has usually been done, in wxTrackable destructor)
1086 wxEvtHandler
*eventSink
= entry
->m_fn
->GetEvtHandler();
1089 wxEventConnectionRef
* const
1090 evtConnRef
= FindRefInTrackerList(eventSink
);
1093 eventSink
->RemoveNode(evtConnRef
);
1098 delete entry
->m_callbackUserData
;
1101 delete m_dynamicEvents
;
1104 // Remove us from the list of the pending events if necessary.
1106 wxTheApp
->RemovePendingEventHandler(this);
1108 DeletePendingEvents();
1110 // we only delete object data, not untyped
1111 if ( m_clientDataType
== wxClientData_Object
)
1112 delete m_clientObject
;
1115 void wxEvtHandler::Unlink()
1117 // this event handler must take itself out of the chain of handlers:
1119 if (m_previousHandler
)
1120 m_previousHandler
->SetNextHandler(m_nextHandler
);
1123 m_nextHandler
->SetPreviousHandler(m_previousHandler
);
1125 m_nextHandler
= NULL
;
1126 m_previousHandler
= NULL
;
1129 bool wxEvtHandler::IsUnlinked() const
1131 return m_previousHandler
== NULL
&&
1132 m_nextHandler
== NULL
;
1137 bool wxEvtHandler::ProcessThreadEvent(const wxEvent
& event
)
1139 // check that we are really in a child thread
1140 wxASSERT_MSG( !wxThread::IsMain(),
1141 wxT("use ProcessEvent() in main thread") );
1143 AddPendingEvent(event
);
1148 #endif // wxUSE_THREADS
1150 void wxEvtHandler::QueueEvent(wxEvent
*event
)
1152 wxCHECK_RET( event
, "NULL event can't be posted" );
1156 // we need an event loop which manages the list of event handlers with
1157 // pending events... cannot proceed without it!
1158 wxLogDebug("No application object! Cannot queue this event!");
1160 // anyway delete the given event to avoid memory leaks
1166 // 1) Add this event to our list of pending events
1167 wxENTER_CRIT_SECT( m_pendingEventsLock
);
1169 if ( !m_pendingEvents
)
1170 m_pendingEvents
= new wxList
;
1172 m_pendingEvents
->Append(event
);
1174 // 2) Add this event handler to list of event handlers that
1175 // have pending events.
1177 wxTheApp
->AppendPendingEventHandler(this);
1179 // only release m_pendingEventsLock now because otherwise there is a race
1180 // condition as described in the ticket #9093: we could process the event
1181 // just added to m_pendingEvents in our ProcessPendingEvents() below before
1182 // we had time to append this pointer to wxHandlersWithPendingEvents list; thus
1183 // breaking the invariant that a handler should be in the list iff it has
1184 // any pending events to process
1185 wxLEAVE_CRIT_SECT( m_pendingEventsLock
);
1187 // 3) Inform the system that new pending events are somewhere,
1188 // and that these should be processed in idle time.
1192 void wxEvtHandler::DeletePendingEvents()
1194 if (m_pendingEvents
)
1195 m_pendingEvents
->DeleteContents(true);
1196 wxDELETE(m_pendingEvents
);
1199 void wxEvtHandler::ProcessPendingEvents()
1203 // we need an event loop which manages the list of event handlers with
1204 // pending events... cannot proceed without it!
1205 wxLogDebug("No application object! Cannot process pending events!");
1209 // we need to process only a single pending event in this call because
1210 // each call to ProcessEvent() could result in the destruction of this
1211 // same event handler (see the comment at the end of this function)
1213 wxENTER_CRIT_SECT( m_pendingEventsLock
);
1215 // this method is only called by wxApp if this handler does have
1217 wxCHECK_RET( m_pendingEvents
&& !m_pendingEvents
->IsEmpty(),
1218 "should have pending events if called" );
1220 wxList::compatibility_iterator node
= m_pendingEvents
->GetFirst();
1221 wxEvent
* pEvent
= static_cast<wxEvent
*>(node
->GetData());
1223 // find the first event which can be processed now:
1224 wxEventLoopBase
* evtLoop
= wxEventLoopBase::GetActive();
1225 if (evtLoop
&& evtLoop
->IsYielding())
1227 while (node
&& pEvent
&& !evtLoop
->IsEventAllowedInsideYield(pEvent
->GetEventCategory()))
1229 node
= node
->GetNext();
1230 pEvent
= node
? static_cast<wxEvent
*>(node
->GetData()) : NULL
;
1235 // all our events are NOT processable now... signal this:
1236 wxTheApp
->DelayPendingEventHandler(this);
1238 // see the comment at the beginning of evtloop.h header for the
1239 // logic behind YieldFor() and behind DelayPendingEventHandler()
1241 wxLEAVE_CRIT_SECT( m_pendingEventsLock
);
1247 wxEventPtr
event(pEvent
);
1249 // it's important we remove event from list before processing it, else a
1250 // nested event loop, for example from a modal dialog, might process the
1251 // same event again.
1252 m_pendingEvents
->Erase(node
);
1254 if ( m_pendingEvents
->IsEmpty() )
1256 // if there are no more pending events left, we don't need to
1257 // stay in this list
1258 wxTheApp
->RemovePendingEventHandler(this);
1261 wxLEAVE_CRIT_SECT( m_pendingEventsLock
);
1263 ProcessEvent(*event
);
1265 // careful: this object could have been deleted by the event handler
1266 // executed by the above ProcessEvent() call, so we can't access any fields
1267 // of this object any more
1271 bool wxEvtHandler::ProcessEventIfMatchesId(const wxEventTableEntryBase
& entry
,
1272 wxEvtHandler
*handler
,
1275 int tableId1
= entry
.m_id
,
1276 tableId2
= entry
.m_lastId
;
1278 // match only if the event type is the same and the id is either -1 in
1279 // the event table (meaning "any") or the event id matches the id
1280 // specified in the event table either exactly or by falling into
1281 // range between first and last
1282 if ((tableId1
== wxID_ANY
) ||
1283 (tableId2
== wxID_ANY
&& tableId1
== event
.GetId()) ||
1284 (tableId2
!= wxID_ANY
&&
1285 (event
.GetId() >= tableId1
&& event
.GetId() <= tableId2
)))
1288 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1290 #if wxUSE_EXCEPTIONS
1293 // call the handler via wxApp method which allows the user to catch
1294 // any exceptions which may be thrown by any handler in the program
1296 wxTheApp
->CallEventHandler(handler
, *entry
.m_fn
, event
);
1299 #endif // wxUSE_EXCEPTIONS
1301 (*entry
.m_fn
)(handler
, event
);
1304 if (!event
.GetSkipped())
1311 bool wxEvtHandler::DoTryApp(wxEvent
& event
)
1313 if ( wxTheApp
&& (this != wxTheApp
) )
1315 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1316 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1317 // processed appropriately via SearchEventTable.
1318 if ( event
.GetEventType() != wxEVT_IDLE
)
1320 if ( wxTheApp
->ProcessEvent(event
) )
1328 bool wxEvtHandler::TryBefore(wxEvent
& event
)
1330 #if WXWIN_COMPATIBILITY_2_8
1331 // call the old virtual function to keep the code overriding it working
1332 return TryValidator(event
);
1339 bool wxEvtHandler::TryAfter(wxEvent
& event
)
1341 // We only want to pass the window to the application object once even if
1342 // there are several chained handlers. Ensure that this is what happens by
1343 // only calling DoTryApp() if there is no next handler (which would do it).
1345 // Notice that, unlike simply calling TryAfter() on the last handler in the
1346 // chain only from ProcessEvent(), this also works with wxWindow object in
1347 // the middle of the chain: its overridden TryAfter() will still be called
1348 // and propagate the event upwards the window hierarchy even if it's not
1349 // the last one in the chain (which, admittedly, shouldn't happen often).
1350 if ( GetNextHandler() )
1351 return GetNextHandler()->TryAfter(event
);
1353 #if WXWIN_COMPATIBILITY_2_8
1354 // as above, call the old virtual function for compatibility
1355 return TryParent(event
);
1357 return DoTryApp(event
);
1361 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
1363 // The very first thing we do is to allow the application to hook into
1364 // event processing in order to globally pre-process all events.
1366 // Note that we should only do it if we're the first event handler called
1367 // to avoid calling FilterEvent() multiple times as the event goes through
1368 // the event handler chain and possibly upwards the window hierarchy.
1369 if ( !event
.WasProcessed() )
1373 int rc
= wxTheApp
->FilterEvent(event
);
1376 wxASSERT_MSG( rc
== 1 || rc
== 0,
1377 "unexpected wxApp::FilterEvent return value" );
1381 //else: proceed normally
1385 // Short circuit the event processing logic if we're requested to process
1386 // this event in this handler only, see DoTryChain() for more details.
1387 if ( event
.ShouldProcessOnlyIn(this) )
1388 return TryBeforeAndHere(event
);
1391 // Try to process the event in this handler itself.
1392 if ( ProcessEventLocally(event
) )
1394 // It is possible that DoTryChain() called from ProcessEventLocally()
1395 // returned true but the event was not really processed: this happens
1396 // if a custom handler ignores the request to process the event in this
1397 // handler only and in this case we should skip the post processing
1398 // done in TryAfter() but still return the correct value ourselves to
1399 // indicate whether we did or did not find a handler for this event.
1400 return !event
.GetSkipped();
1403 // If we still didn't find a handler, propagate the event upwards the
1404 // window chain and/or to the application object.
1405 if ( TryAfter(event
) )
1409 // No handler found anywhere, bail out.
1413 bool wxEvtHandler::ProcessEventLocally(wxEvent
& event
)
1415 // Try the hooks which should be called before our own handlers and this
1416 // handler itself first. Notice that we should not call ProcessEvent() on
1417 // this one as we're already called from it, which explains why we do it
1418 // here and not in DoTryChain()
1419 return TryBeforeAndHere(event
) || DoTryChain(event
);
1422 bool wxEvtHandler::DoTryChain(wxEvent
& event
)
1424 for ( wxEvtHandler
*h
= GetNextHandler(); h
; h
= h
->GetNextHandler() )
1426 // We need to process this event at the level of this handler only
1427 // right now, the pre-/post-processing was either already done by
1428 // ProcessEvent() from which we were called or will be done by it when
1431 // However we must call ProcessEvent() and not TryHereOnly() because the
1432 // existing code (including some in wxWidgets itself) expects the
1433 // overridden ProcessEvent() in its custom event handlers pushed on a
1434 // window to be called.
1436 // So we must call ProcessEvent() but it must not do what it usually
1437 // does. To resolve this paradox we set up a special flag inside the
1438 // object itself to let ProcessEvent() know that it shouldn't do any
1439 // pre/post-processing for this event if it gets it. Note that this
1440 // only applies to this handler, if the event is passed to another one
1441 // by explicitly calling its ProcessEvent(), pre/post-processing should
1442 // be done as usual.
1444 // Final complication is that if the implementation of ProcessEvent()
1445 // called wxEvent::DidntHonourProcessOnlyIn() (as the gross hack that
1446 // is wxScrollHelperEvtHandler::ProcessEvent() does) and ignored our
1447 // request to process event in this handler only, we have to compensate
1448 // for it by not processing the event further because this was already
1449 // done by that rogue event handler.
1450 wxEventProcessInHandlerOnly
processInHandlerOnly(event
, h
);
1451 if ( h
->ProcessEvent(event
) )
1453 // Make sure "skipped" flag is not set as the event was really
1454 // processed in this case. Normally it shouldn't be set anyhow but
1455 // make sure just in case the user code does something strange.
1461 if ( !event
.ShouldProcessOnlyIn(h
) )
1463 // Still return true to indicate that no further processing should
1464 // be undertaken but ensure that "skipped" flag is set so that the
1465 // caller knows that the event was not really processed.
1475 bool wxEvtHandler::TryHereOnly(wxEvent
& event
)
1477 // If the event handler is disabled it doesn't process any events
1478 if ( !GetEvtHandlerEnabled() )
1481 // Handle per-instance dynamic event tables first
1482 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
1485 // Then static per-class event tables
1486 if ( GetEventHashTable().HandleEvent(event
, this) )
1489 // We don't have a handler for this event.
1493 bool wxEvtHandler::SafelyProcessEvent(wxEvent
& event
)
1495 #if wxUSE_EXCEPTIONS
1499 return ProcessEvent(event
);
1500 #if wxUSE_EXCEPTIONS
1504 // notice that we do it in 2 steps to avoid warnings about possibly
1505 // uninitialized loop variable from some versions of g++ which are not
1506 // smart enough to figure out that GetActive() doesn't throw and so
1507 // that loop will always be initialized
1508 wxEventLoopBase
*loop
= NULL
;
1511 loop
= wxEventLoopBase::GetActive();
1513 if ( !wxTheApp
|| !wxTheApp
->OnExceptionInMainLoop() )
1518 //else: continue running current event loop
1524 // OnExceptionInMainLoop() threw, possibly rethrowing the same
1525 // exception again: very good, but we still need Exit() to
1532 #endif // wxUSE_EXCEPTIONS
1535 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
1537 const wxEventType eventType
= event
.GetEventType();
1538 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
1540 const wxEventTableEntry
& entry
= table
.entries
[i
];
1541 if ( eventType
== entry
.m_eventType
)
1543 if ( ProcessEventIfMatchesId(entry
, this, event
) )
1551 void wxEvtHandler::DoBind(int id
,
1553 wxEventType eventType
,
1554 wxEventFunctor
*func
,
1557 wxDynamicEventTableEntry
*entry
=
1558 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
);
1560 if (!m_dynamicEvents
)
1561 m_dynamicEvents
= new wxList
;
1563 // Insert at the front of the list so most recent additions are found first
1564 m_dynamicEvents
->Insert( (wxObject
*) entry
);
1566 // Make sure we get to know when a sink is destroyed
1567 wxEvtHandler
*eventSink
= func
->GetEvtHandler();
1568 if ( eventSink
&& eventSink
!= this )
1570 wxEventConnectionRef
*evtConnRef
= FindRefInTrackerList(eventSink
);
1572 evtConnRef
->IncRef( );
1574 new wxEventConnectionRef(this, eventSink
);
1579 wxEvtHandler::DoUnbind(int id
,
1581 wxEventType eventType
,
1582 const wxEventFunctor
& func
,
1585 if (!m_dynamicEvents
)
1588 // Remove connection from tracker node (wxEventConnectionRef)
1589 wxEvtHandler
*eventSink
= func
.GetEvtHandler();
1590 if ( eventSink
&& eventSink
!= this )
1592 wxEventConnectionRef
*evtConnRef
= FindRefInTrackerList(eventSink
);
1594 evtConnRef
->DecRef();
1597 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1600 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1602 if ((entry
->m_id
== id
) &&
1603 ((entry
->m_lastId
== lastId
) || (lastId
== wxID_ANY
)) &&
1604 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1605 entry
->m_fn
->IsMatching(func
) &&
1606 ((entry
->m_callbackUserData
== userData
) || !userData
))
1608 delete entry
->m_callbackUserData
;
1609 m_dynamicEvents
->Erase( node
);
1613 node
= node
->GetNext();
1618 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1620 wxCHECK_MSG( m_dynamicEvents
, false,
1621 wxT("caller should check that we have dynamic events") );
1623 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1626 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1628 // get next node before (maybe) calling the event handler as it could
1629 // call Disconnect() invalidating the current node
1630 node
= node
->GetNext();
1632 if ( event
.GetEventType() == entry
->m_eventType
)
1634 wxEvtHandler
*handler
= entry
->m_fn
->GetEvtHandler();
1637 if ( ProcessEventIfMatchesId(*entry
, handler
, event
) )
1645 void wxEvtHandler::DoSetClientObject( wxClientData
*data
)
1647 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1648 wxT("can't have both object and void client data") );
1650 if ( m_clientObject
)
1651 delete m_clientObject
;
1653 m_clientObject
= data
;
1654 m_clientDataType
= wxClientData_Object
;
1657 wxClientData
*wxEvtHandler::DoGetClientObject() const
1659 // it's not an error to call GetClientObject() on a window which doesn't
1660 // have client data at all - NULL will be returned
1661 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1662 wxT("this window doesn't have object client data") );
1664 return m_clientObject
;
1667 void wxEvtHandler::DoSetClientData( void *data
)
1669 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1670 wxT("can't have both object and void client data") );
1672 m_clientData
= data
;
1673 m_clientDataType
= wxClientData_Void
;
1676 void *wxEvtHandler::DoGetClientData() const
1678 // it's not an error to call GetClientData() on a window which doesn't have
1679 // client data at all - NULL will be returned
1680 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1681 wxT("this window doesn't have void client data") );
1683 return m_clientData
;
1686 // A helper to find an wxEventConnectionRef object
1687 wxEventConnectionRef
*
1688 wxEvtHandler::FindRefInTrackerList(wxEvtHandler
*eventSink
)
1690 for ( wxTrackerNode
*node
= eventSink
->GetFirst(); node
; node
= node
->m_nxt
)
1692 // we only want wxEventConnectionRef nodes here
1693 wxEventConnectionRef
*evtConnRef
= node
->ToEventConnection();
1694 if ( evtConnRef
&& evtConnRef
->m_src
== this )
1696 wxASSERT( evtConnRef
->m_sink
==eventSink
);
1704 void wxEvtHandler::OnSinkDestroyed( wxEvtHandler
*sink
)
1706 wxASSERT(m_dynamicEvents
);
1708 // remove all connections with this sink
1709 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst(), node_nxt
;
1712 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1713 node_nxt
= node
->GetNext();
1715 if ( entry
->m_fn
->GetEvtHandler() == sink
)
1717 delete entry
->m_callbackUserData
;
1718 m_dynamicEvents
->Erase( node
);
1725 #endif // wxUSE_BASE
1729 // Find a window with the focus, that is also a descendant of the given window.
1730 // This is used to determine the window to initially send commands to.
1731 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1733 // Process events starting with the window with the focus, if any.
1734 wxWindow
* focusWin
= wxWindow::FindFocus();
1735 wxWindow
* win
= focusWin
;
1737 // Check if this is a descendant of this frame.
1738 // If not, win will be set to NULL.
1741 if (win
== ancestor
)
1744 win
= win
->GetParent();
1752 // ----------------------------------------------------------------------------
1754 // ----------------------------------------------------------------------------
1756 wxEventBlocker::wxEventBlocker(wxWindow
*win
, wxEventType type
)
1758 wxCHECK_RET(win
, wxT("Null window given to wxEventBlocker"));
1763 m_window
->PushEventHandler(this);
1766 wxEventBlocker::~wxEventBlocker()
1768 wxEvtHandler
*popped
= m_window
->PopEventHandler(false);
1769 wxCHECK_RET(popped
== this,
1770 wxT("Don't push other event handlers into a window managed by wxEventBlocker!"));
1773 bool wxEventBlocker::ProcessEvent(wxEvent
& event
)
1775 // should this event be blocked?
1776 for ( size_t i
= 0; i
< m_eventsToBlock
.size(); i
++ )
1778 wxEventType t
= (wxEventType
)m_eventsToBlock
[i
];
1779 if ( t
== wxEVT_ANY
|| t
== event
.GetEventType() )
1780 return true; // yes, it should: mark this event as processed