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_ENTRY(wxEVT_NULL
, 0, 0, (wxObjectEventFunction
)NULL
, NULL
) };
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
*wxPendingEvents
= NULL
;
151 // protects wxPendingEvents list
152 wxCriticalSection
*wxPendingEventsLocker
= 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 DEFINE_EVENT_TYPE(wxEVT_IDLE
)
163 DEFINE_EVENT_TYPE(wxEVT_SOCKET
)
164 DEFINE_EVENT_TYPE(wxEVT_TIMER
)
170 DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED
)
171 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED
)
172 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED
)
173 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED
)
174 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
)
175 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
)
176 DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED
)
177 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED
)
178 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED
)
179 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED
)
180 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED
)
181 DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED
)
182 DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED
)
183 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED
)
184 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER
)
185 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED
)
186 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED
)
187 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED
)
190 DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN
)
191 DEFINE_EVENT_TYPE(wxEVT_LEFT_UP
)
192 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN
)
193 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP
)
194 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN
)
195 DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP
)
196 DEFINE_EVENT_TYPE(wxEVT_MOTION
)
197 DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW
)
198 DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW
)
199 DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK
)
200 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK
)
201 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK
)
202 DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS
)
203 DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS
)
204 DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS
)
205 DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL
)
206 DEFINE_EVENT_TYPE(wxEVT_AUX1_DOWN
)
207 DEFINE_EVENT_TYPE(wxEVT_AUX1_UP
)
208 DEFINE_EVENT_TYPE(wxEVT_AUX1_DCLICK
)
209 DEFINE_EVENT_TYPE(wxEVT_AUX2_DOWN
)
210 DEFINE_EVENT_TYPE(wxEVT_AUX2_UP
)
211 DEFINE_EVENT_TYPE(wxEVT_AUX2_DCLICK
)
213 // Non-client mouse events
214 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN
)
215 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP
)
216 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN
)
217 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP
)
218 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN
)
219 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP
)
220 DEFINE_EVENT_TYPE(wxEVT_NC_MOTION
)
221 DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW
)
222 DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW
)
223 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK
)
224 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK
)
225 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK
)
227 // Character input event type
228 DEFINE_EVENT_TYPE(wxEVT_CHAR
)
229 DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK
)
230 DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY
)
231 DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN
)
232 DEFINE_EVENT_TYPE(wxEVT_KEY_UP
)
234 DEFINE_EVENT_TYPE(wxEVT_HOTKEY
)
238 DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR
)
240 // wxScrollbar and wxSlider event identifiers
241 DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP
)
242 DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM
)
243 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP
)
244 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN
)
245 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP
)
246 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN
)
247 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK
)
248 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE
)
249 DEFINE_EVENT_TYPE(wxEVT_SCROLL_CHANGED
)
251 // Scroll events from wxWindow
252 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP
)
253 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM
)
254 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP
)
255 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN
)
256 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP
)
257 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN
)
258 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK
)
259 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE
)
262 DEFINE_EVENT_TYPE(wxEVT_SIZE
)
263 DEFINE_EVENT_TYPE(wxEVT_SIZING
)
264 DEFINE_EVENT_TYPE(wxEVT_MOVE
)
265 DEFINE_EVENT_TYPE(wxEVT_MOVING
)
266 DEFINE_EVENT_TYPE(wxEVT_MOVE_START
)
267 DEFINE_EVENT_TYPE(wxEVT_MOVE_END
)
268 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW
)
269 DEFINE_EVENT_TYPE(wxEVT_END_SESSION
)
270 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION
)
271 DEFINE_EVENT_TYPE(wxEVT_HIBERNATE
)
272 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
273 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
274 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
275 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
276 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
277 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
278 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
279 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
280 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_LOST
)
281 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
282 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
283 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
284 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
285 DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN
)
286 DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE
)
287 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
288 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
289 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
290 DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED
)
291 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
292 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
293 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
294 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
295 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
296 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
297 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
298 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
299 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
300 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
301 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
302 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
303 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
306 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_COPY
)
307 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_CUT
)
308 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_PASTE
)
310 // Generic command events
311 // Note: a click is a higher-level event than button down/up
312 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
313 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
314 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
315 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
316 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
317 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
318 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
321 DEFINE_EVENT_TYPE(wxEVT_HELP
)
322 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
328 wxIdleMode
wxIdleEvent::sm_idleMode
= wxIDLE_PROCESS_ALL
;
330 // ============================================================================
332 // ============================================================================
334 // ----------------------------------------------------------------------------
335 // event initialization
336 // ----------------------------------------------------------------------------
341 static int s_lastUsedEventType
= wxEVT_FIRST
;
343 return s_lastUsedEventType
++;
346 // ----------------------------------------------------------------------------
348 // ----------------------------------------------------------------------------
351 * General wxWidgets events, covering
352 * all interesting things that might happen (button clicking, resizing,
353 * 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
= (wxObject
*) NULL
;
366 m_callbackUserData
= (wxObject
*) NULL
;
367 m_isCommandEvent
= false;
368 m_propagationLevel
= wxEVENT_PROPAGATE_NONE
;
371 wxEvent::wxEvent(const wxEvent
& src
)
373 , m_eventObject(src
.m_eventObject
)
374 , m_eventType(src
.m_eventType
)
375 , m_timeStamp(src
.m_timeStamp
)
377 , m_callbackUserData(src
.m_callbackUserData
)
378 , m_propagationLevel(src
.m_propagationLevel
)
379 , m_skipped(src
.m_skipped
)
380 , m_isCommandEvent(src
.m_isCommandEvent
)
384 wxEvent
& wxEvent::operator=(const wxEvent
& src
)
386 wxObject::operator=(src
);
388 m_eventObject
= src
.m_eventObject
;
389 m_eventType
= src
.m_eventType
;
390 m_timeStamp
= src
.m_timeStamp
;
392 m_callbackUserData
= src
.m_callbackUserData
;
393 m_propagationLevel
= src
.m_propagationLevel
;
394 m_skipped
= src
.m_skipped
;
395 m_isCommandEvent
= src
.m_isCommandEvent
;
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
)
417 m_clientData
= (char *) NULL
;
418 m_clientObject
= (wxClientData
*) 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
);
564 wxMouseState::operator=(event
);
569 m_leftDown
= event
.m_leftDown
;
570 m_middleDown
= event
.m_middleDown
;
571 m_rightDown
= event
.m_rightDown
;
572 m_aux1Down
= event
.m_aux1Down
;
573 m_aux2Down
= event
.m_aux2Down
;
575 m_wheelRotation
= event
.m_wheelRotation
;
576 m_wheelDelta
= event
.m_wheelDelta
;
577 m_linesPerAction
= event
.m_linesPerAction
;
578 m_wheelAxis
= event
.m_wheelAxis
;
581 // return true if was a button dclick event
582 bool wxMouseEvent::ButtonDClick(int but
) const
587 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
590 case wxMOUSE_BTN_ANY
:
591 return (LeftDClick() || MiddleDClick() || RightDClick() ||
592 Aux1DClick() || Aux2DClick());
594 case wxMOUSE_BTN_LEFT
:
597 case wxMOUSE_BTN_MIDDLE
:
598 return MiddleDClick();
600 case wxMOUSE_BTN_RIGHT
:
601 return RightDClick();
603 case wxMOUSE_BTN_AUX1
:
606 case wxMOUSE_BTN_AUX2
:
611 // return true if was a button down event
612 bool wxMouseEvent::ButtonDown(int but
) const
617 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
620 case wxMOUSE_BTN_ANY
:
621 return (LeftDown() || MiddleDown() || RightDown() ||
622 Aux1Down() || Aux2Down());
624 case wxMOUSE_BTN_LEFT
:
627 case wxMOUSE_BTN_MIDDLE
:
630 case wxMOUSE_BTN_RIGHT
:
633 case wxMOUSE_BTN_AUX1
:
636 case wxMOUSE_BTN_AUX2
:
641 // return true if was a button up event
642 bool wxMouseEvent::ButtonUp(int but
) const
647 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
650 case wxMOUSE_BTN_ANY
:
651 return (LeftUp() || MiddleUp() || RightUp() ||
652 Aux1Up() || Aux2Up());
654 case wxMOUSE_BTN_LEFT
:
657 case wxMOUSE_BTN_MIDDLE
:
660 case wxMOUSE_BTN_RIGHT
:
663 case wxMOUSE_BTN_AUX1
:
666 case wxMOUSE_BTN_AUX2
:
671 // return true if the given button is currently changing state
672 bool wxMouseEvent::Button(int but
) const
677 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
680 case wxMOUSE_BTN_ANY
:
681 return ButtonUp(wxMOUSE_BTN_ANY
) ||
682 ButtonDown(wxMOUSE_BTN_ANY
) ||
683 ButtonDClick(wxMOUSE_BTN_ANY
);
685 case wxMOUSE_BTN_LEFT
:
686 return LeftDown() || LeftUp() || LeftDClick();
688 case wxMOUSE_BTN_MIDDLE
:
689 return MiddleDown() || MiddleUp() || MiddleDClick();
691 case wxMOUSE_BTN_RIGHT
:
692 return RightDown() || RightUp() || RightDClick();
694 case wxMOUSE_BTN_AUX1
:
695 return Aux1Down() || Aux1Up() || Aux1DClick();
697 case wxMOUSE_BTN_AUX2
:
698 return Aux2Down() || Aux2Up() || Aux2DClick();
702 bool wxMouseEvent::ButtonIsDown(int but
) const
707 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
710 case wxMOUSE_BTN_ANY
:
711 return LeftIsDown() || MiddleIsDown() || RightIsDown() || Aux1Down() || Aux2Down();
713 case wxMOUSE_BTN_LEFT
:
716 case wxMOUSE_BTN_MIDDLE
:
717 return MiddleIsDown();
719 case wxMOUSE_BTN_RIGHT
:
720 return RightIsDown();
722 case wxMOUSE_BTN_AUX1
:
725 case wxMOUSE_BTN_AUX2
:
730 int wxMouseEvent::GetButton() const
732 for ( int i
= 1; i
< wxMOUSE_BTN_MAX
; i
++ )
740 return wxMOUSE_BTN_NONE
;
743 // Find the logical position of the event given the DC
744 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
746 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
756 wxKeyEvent::wxKeyEvent(wxEventType type
)
766 wxKeyEvent::wxKeyEvent(const wxKeyEvent
& evt
)
773 m_keyCode
= evt
.m_keyCode
;
775 m_scanCode
= evt
.m_scanCode
;
776 m_rawCode
= evt
.m_rawCode
;
777 m_rawFlags
= evt
.m_rawFlags
;
780 m_uniChar
= evt
.m_uniChar
;
784 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
786 SetEventType(wxEVT_CREATE
);
790 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
792 SetEventType(wxEVT_DESTROY
);
796 wxChildFocusEvent::wxChildFocusEvent(wxWindow
*win
)
797 : wxCommandEvent(wxEVT_CHILD_FOCUS
)
802 // ----------------------------------------------------------------------------
804 // ----------------------------------------------------------------------------
807 wxHelpEvent::Origin
wxHelpEvent::GuessOrigin(Origin origin
)
809 if ( origin
== Origin_Unknown
)
811 // assume that the event comes from the help button if it's not from
812 // keyboard and that pressing F1 always results in the help event
813 origin
= wxGetKeyState(WXK_F1
) ? Origin_Keyboard
: Origin_HelpButton
;
824 // ----------------------------------------------------------------------------
826 // ----------------------------------------------------------------------------
828 static const int EVENT_TYPE_TABLE_INIT_SIZE
= 31; // Not too big not too small...
830 wxEventHashTable
* wxEventHashTable::sm_first
= NULL
;
832 wxEventHashTable::wxEventHashTable(const wxEventTable
&table
)
836 AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE
);
840 m_next
->m_previous
= this;
844 wxEventHashTable::~wxEventHashTable()
847 m_next
->m_previous
= m_previous
;
849 m_previous
->m_next
= m_next
;
850 if (sm_first
== this)
856 void wxEventHashTable::Clear()
858 for ( size_t i
= 0; i
< m_size
; i
++ )
860 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
864 delete[] m_eventTypeTable
;
865 m_eventTypeTable
= NULL
;
870 #if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
873 void wxEventHashTable::ClearAll()
875 wxEventHashTable
* table
= sm_first
;
879 table
= table
->m_next
;
883 #endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING
885 bool wxEventHashTable::HandleEvent(wxEvent
&event
, wxEvtHandler
*self
)
890 m_rebuildHash
= false;
893 if (!m_eventTypeTable
)
896 // Find all entries for the given event type.
897 wxEventType eventType
= event
.GetEventType();
898 const EventTypeTablePointer eTTnode
= m_eventTypeTable
[eventType
% m_size
];
899 if (eTTnode
&& eTTnode
->eventType
== eventType
)
901 // Now start the search for an event handler
902 // that can handle an event with the given ID.
903 const wxEventTableEntryPointerArray
&
904 eventEntryTable
= eTTnode
->eventEntryTable
;
906 const size_t count
= eventEntryTable
.GetCount();
907 for (size_t n
= 0; n
< count
; n
++)
910 ProcessEventIfMatches(*eventEntryTable
[n
], self
, event
) )
920 void wxEventHashTable::InitHashTable()
922 // Loop over the event tables and all its base tables.
923 const wxEventTable
*table
= &m_table
;
926 // Retrieve all valid event handler entries
927 const wxEventTableEntry
*entry
= table
->entries
;
928 while (entry
->m_fn
!= 0)
930 // Add the event entry in the Hash.
936 table
= table
->baseTable
;
939 // Lets free some memory.
941 for(i
= 0; i
< m_size
; i
++)
943 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
946 eTTnode
->eventEntryTable
.Shrink();
951 void wxEventHashTable::AddEntry(const wxEventTableEntry
&entry
)
953 // This might happen 'accidentally' as the app is exiting
954 if (!m_eventTypeTable
)
957 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[entry
.m_eventType
% m_size
];
958 EventTypeTablePointer eTTnode
= *peTTnode
;
962 if (eTTnode
->eventType
!= entry
.m_eventType
)
965 GrowEventTypeTable();
966 // Try again to add it.
973 eTTnode
= new EventTypeTable
;
974 eTTnode
->eventType
= entry
.m_eventType
;
978 // Fill all hash entries between entry.m_id and entry.m_lastId...
979 eTTnode
->eventEntryTable
.Add(&entry
);
982 void wxEventHashTable::AllocEventTypeTable(size_t size
)
984 m_eventTypeTable
= new EventTypeTablePointer
[size
];
985 memset((void *)m_eventTypeTable
, 0, sizeof(EventTypeTablePointer
)*size
);
989 void wxEventHashTable::GrowEventTypeTable()
991 size_t oldSize
= m_size
;
992 EventTypeTablePointer
*oldEventTypeTable
= m_eventTypeTable
;
994 // TODO: Search the most optimal grow sequence
995 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize
*2+1);
997 for ( size_t i
= 0; i
< oldSize
; /* */ )
999 EventTypeTablePointer eTToldNode
= oldEventTypeTable
[i
];
1002 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[eTToldNode
->eventType
% m_size
];
1003 EventTypeTablePointer eTTnode
= *peTTnode
;
1005 // Check for collision, we don't want any.
1008 GrowEventTypeTable();
1009 continue; // Don't increment the counter,
1010 // as we still need to add this element.
1014 // Get the old value and put it in the new table.
1015 *peTTnode
= oldEventTypeTable
[i
];
1022 delete[] oldEventTypeTable
;
1025 // ----------------------------------------------------------------------------
1027 // ----------------------------------------------------------------------------
1033 wxEvtHandler::wxEvtHandler()
1035 m_nextHandler
= (wxEvtHandler
*) NULL
;
1036 m_previousHandler
= (wxEvtHandler
*) NULL
;
1038 m_dynamicEvents
= (wxList
*) NULL
;
1039 m_pendingEvents
= (wxList
*) NULL
;
1041 // no client data (yet)
1042 m_clientData
= NULL
;
1043 m_clientDataType
= wxClientData_None
;
1046 wxEvtHandler::~wxEvtHandler()
1048 // Takes itself out of the list of handlers
1049 if (m_previousHandler
)
1050 m_previousHandler
->m_nextHandler
= m_nextHandler
;
1053 m_nextHandler
->m_previousHandler
= m_previousHandler
;
1055 if (m_dynamicEvents
)
1057 for ( wxList::iterator it
= m_dynamicEvents
->begin(),
1058 end
= m_dynamicEvents
->end();
1062 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)*it
;
1064 // Remove ourselves from sink destructor notifications
1065 // (this has usually been been done, in wxTrackable destructor)
1066 wxEvtHandler
*eventSink
= entry
->m_eventSink
;
1069 wxEventConnectionRef
* const
1070 evtConnRef
= FindRefInTrackerList(eventSink
);
1073 eventSink
->RemoveNode(evtConnRef
);
1078 if (entry
->m_callbackUserData
)
1079 delete entry
->m_callbackUserData
;
1082 delete m_dynamicEvents
;
1085 if (m_pendingEvents
)
1086 m_pendingEvents
->DeleteContents(true);
1087 delete m_pendingEvents
;
1089 // Remove us from wxPendingEvents if necessary.
1090 if ( wxPendingEvents
)
1093 if (wxPendingEventsLocker
)
1094 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
1097 if ( wxPendingEvents
->DeleteObject(this) )
1099 // check that we were present only once in the list
1100 wxASSERT_MSG( !wxPendingEvents
->Find(this),
1101 "Handler occurs twice in wxPendingEvents list" );
1103 //else: we weren't in this list at all, it's ok
1106 if (wxPendingEventsLocker
)
1107 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
1111 // we only delete object data, not untyped
1112 if ( m_clientDataType
== wxClientData_Object
)
1113 delete m_clientObject
;
1118 bool wxEvtHandler::ProcessThreadEvent(const wxEvent
& event
)
1120 // check that we are really in a child thread
1121 wxASSERT_MSG( !wxThread::IsMain(),
1122 wxT("use ProcessEvent() in main thread") );
1124 AddPendingEvent(event
);
1129 #endif // wxUSE_THREADS
1131 void wxEvtHandler::QueueEvent(wxEvent
*event
)
1133 wxCHECK_RET( event
, "NULL event can't be posted" );
1135 // 1) Add this event to our list of pending events
1136 wxENTER_CRIT_SECT( m_pendingEventsLock
);
1138 if ( !m_pendingEvents
)
1139 m_pendingEvents
= new wxList
;
1141 m_pendingEvents
->Append(event
);
1143 wxLEAVE_CRIT_SECT( m_pendingEventsLock
);
1145 // 2) Add this event handler to list of event handlers that
1146 // have pending events.
1148 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
1150 if ( !wxPendingEvents
)
1151 wxPendingEvents
= new wxList
;
1152 if ( !wxPendingEvents
->Find(this) )
1153 wxPendingEvents
->Append(this);
1155 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
1157 // 3) Inform the system that new pending events are somewhere,
1158 // and that these should be processed in idle time.
1162 void wxEvtHandler::ProcessPendingEvents()
1164 wxENTER_CRIT_SECT( m_pendingEventsLock
);
1166 // this method is only called by wxApp if this handler does have
1168 wxCHECK_RET( m_pendingEvents
&& !m_pendingEvents
->IsEmpty(),
1169 "should have pending events if called" );
1171 wxList::compatibility_iterator node
= m_pendingEvents
->GetFirst();
1172 wxEventPtr
event(wx_static_cast(wxEvent
*, node
->GetData()));
1174 // it's important we remove event from list before processing it, else a
1175 // nested event loop, for example from a modal dialog, might process the
1176 // same event again.
1177 m_pendingEvents
->Erase(node
);
1179 // if there are no more pending events left, we don't need to stay in this
1181 if ( m_pendingEvents
->IsEmpty() )
1184 if (wxPendingEventsLocker
)
1185 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
1187 wxPendingEvents
->DeleteObject(this);
1189 if (wxPendingEventsLocker
)
1190 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
1194 wxLEAVE_CRIT_SECT( m_pendingEventsLock
);
1196 ProcessEvent(*event
);
1198 // careful: this object could have been deleted by the event handler
1199 // executed by the above ProcessEvent() call, so we can't access any fields
1200 // of this object any more
1207 wxEvtHandler::ProcessEventIfMatches(const wxEventTableEntryBase
& entry
,
1208 wxEvtHandler
*handler
,
1211 int tableId1
= entry
.m_id
,
1212 tableId2
= entry
.m_lastId
;
1214 // match only if the event type is the same and the id is either -1 in
1215 // the event table (meaning "any") or the event id matches the id
1216 // specified in the event table either exactly or by falling into
1217 // range between first and last
1218 if ((tableId1
== wxID_ANY
) ||
1219 (tableId2
== wxID_ANY
&& tableId1
== event
.GetId()) ||
1220 (tableId2
!= wxID_ANY
&&
1221 (event
.GetId() >= tableId1
&& event
.GetId() <= tableId2
)))
1224 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1226 #if wxUSE_EXCEPTIONS
1229 // call the handler via wxApp method which allows the user to catch
1230 // any exceptions which may be thrown by any handler in the program
1232 wxTheApp
->HandleEvent(handler
, (wxEventFunction
)entry
.m_fn
, event
);
1235 #endif // wxUSE_EXCEPTIONS
1237 // no need for an extra virtual function call
1238 (handler
->*((wxEventFunction
) (entry
.m_fn
)))(event
);
1241 if (!event
.GetSkipped())
1248 bool wxEvtHandler::TryParent(wxEvent
& event
)
1250 if ( GetNextHandler() )
1252 // the next handler will pass it to wxTheApp if it doesn't process it,
1253 // so return from here to avoid doing it again
1254 return GetNextHandler()->TryParent(event
);
1257 if ( wxTheApp
&& (this != wxTheApp
) )
1259 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1260 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1261 // processed appropriately via SearchEventTable.
1262 if ( event
.GetEventType() != wxEVT_IDLE
)
1264 if ( wxTheApp
->ProcessEvent(event
) )
1272 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
1274 // allow the application to hook into event processing
1277 int rc
= wxTheApp
->FilterEvent(event
);
1280 wxASSERT_MSG( rc
== 1 || rc
== 0,
1281 _T("unexpected wxApp::FilterEvent return value") );
1285 //else: proceed normally
1288 if ( ProcessEventHere(event
) )
1291 // propagate the event upwards the window chain and/or to the application
1292 // object if it wasn't processed at this level
1293 return TryParent(event
);
1296 bool wxEvtHandler::ProcessEventHere(wxEvent
& event
)
1298 // An event handler can be enabled or disabled
1299 if ( GetEvtHandlerEnabled() )
1301 // if we have a validator, it has higher priority than our own event
1303 if ( TryValidator(event
) )
1306 // Handle per-instance dynamic event tables first
1307 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
1310 // Then static per-class event tables
1311 if ( GetEventHashTable().HandleEvent(event
, this) )
1315 // Try going down the event handler chain
1316 if ( GetNextHandler() && GetNextHandler()->ProcessEventHere(event
) )
1319 // We don't have a handler for this event.
1323 bool wxEvtHandler::SafelyProcessEvent(wxEvent
& event
)
1325 #if wxUSE_EXCEPTIONS
1329 return ProcessEvent(event
);
1330 #if wxUSE_EXCEPTIONS
1334 wxEventLoopBase
*loop
= wxEventLoopBase::GetActive();
1337 if ( !wxTheApp
|| !wxTheApp
->OnExceptionInMainLoop() )
1342 //else: continue running current event loop
1348 // OnExceptionInMainLoop() threw, possibly rethrowing the same
1349 // exception again: very good, but we still need Exit() to
1356 #endif // wxUSE_EXCEPTIONS
1360 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
1362 const wxEventType eventType
= event
.GetEventType();
1363 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
1365 const wxEventTableEntry
& entry
= table
.entries
[i
];
1366 if ( eventType
== entry
.m_eventType
)
1368 if ( ProcessEventIfMatches(entry
, this, event
) )
1376 void wxEvtHandler::Connect( int id
, int lastId
,
1378 wxObjectEventFunction func
,
1380 wxEvtHandler
* eventSink
)
1382 wxDynamicEventTableEntry
*entry
=
1383 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
, eventSink
);
1385 if (!m_dynamicEvents
)
1386 m_dynamicEvents
= new wxList
;
1388 // Insert at the front of the list so most recent additions are found first
1389 m_dynamicEvents
->Insert( (wxObject
*) entry
);
1391 // Make sure we get to know when a sink is destroyed
1392 if ( eventSink
&& eventSink
!= this )
1394 wxEventConnectionRef
*evtConnRef
= FindRefInTrackerList(eventSink
);
1396 evtConnRef
->IncRef( );
1398 evtConnRef
= new wxEventConnectionRef(this, eventSink
);
1402 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1403 wxObjectEventFunction func
,
1405 wxEvtHandler
* eventSink
)
1407 if (!m_dynamicEvents
)
1410 // Remove connection from tracker node (wxEventConnectionRef)
1411 if ( eventSink
&& eventSink
!= this )
1413 wxEventConnectionRef
*evtConnRef
= FindRefInTrackerList(eventSink
);
1415 evtConnRef
->DecRef();
1418 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1421 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1423 if ((entry
->m_id
== id
) &&
1424 ((entry
->m_lastId
== lastId
) || (lastId
== wxID_ANY
)) &&
1425 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1426 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1427 ((entry
->m_eventSink
== eventSink
) || (eventSink
== (wxEvtHandler
*)NULL
)) &&
1428 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1430 if (entry
->m_callbackUserData
)
1431 delete entry
->m_callbackUserData
;
1432 m_dynamicEvents
->Erase( node
);
1436 node
= node
->GetNext();
1441 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1443 wxCHECK_MSG( m_dynamicEvents
, false,
1444 wxT("caller should check that we have dynamic events") );
1446 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1449 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1451 // get next node before (maybe) calling the event handler as it could
1452 // call Disconnect() invalidating the current node
1453 node
= node
->GetNext();
1455 if ((event
.GetEventType() == entry
->m_eventType
) && (entry
->m_fn
!= 0))
1457 wxEvtHandler
*handler
= entry
->m_eventSink
? entry
->m_eventSink
1459 if ( ProcessEventIfMatches(*entry
, handler
, event
) )
1467 void wxEvtHandler::DoSetClientObject( wxClientData
*data
)
1469 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1470 wxT("can't have both object and void client data") );
1472 if ( m_clientObject
)
1473 delete m_clientObject
;
1475 m_clientObject
= data
;
1476 m_clientDataType
= wxClientData_Object
;
1479 wxClientData
*wxEvtHandler::DoGetClientObject() const
1481 // it's not an error to call GetClientObject() on a window which doesn't
1482 // have client data at all - NULL will be returned
1483 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1484 wxT("this window doesn't have object client data") );
1486 return m_clientObject
;
1489 void wxEvtHandler::DoSetClientData( void *data
)
1491 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1492 wxT("can't have both object and void client data") );
1494 m_clientData
= data
;
1495 m_clientDataType
= wxClientData_Void
;
1498 void *wxEvtHandler::DoGetClientData() const
1500 // it's not an error to call GetClientData() on a window which doesn't have
1501 // client data at all - NULL will be returned
1502 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1503 wxT("this window doesn't have void client data") );
1505 return m_clientData
;
1508 // A helper to find an wxEventConnectionRef object
1509 wxEventConnectionRef
*
1510 wxEvtHandler::FindRefInTrackerList(wxEvtHandler
*eventSink
)
1512 for ( wxTrackerNode
*node
= eventSink
->GetFirst(); node
; node
= node
->m_nxt
)
1514 // we only want wxEventConnectionRef nodes here
1515 wxEventConnectionRef
*evtConnRef
= node
->ToEventConnection();
1516 if ( evtConnRef
&& evtConnRef
->m_src
== this )
1518 wxASSERT( evtConnRef
->m_sink
==eventSink
);
1526 void wxEvtHandler::OnSinkDestroyed( wxEvtHandler
*sink
)
1528 wxASSERT(m_dynamicEvents
);
1530 // remove all connections with this sink
1531 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst(), node_nxt
;
1534 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1535 node_nxt
= node
->GetNext();
1537 if ( entry
->m_eventSink
==sink
)
1539 if (entry
->m_callbackUserData
)
1540 delete entry
->m_callbackUserData
;
1541 m_dynamicEvents
->Erase( node
);
1548 #endif // wxUSE_BASE
1552 // Find a window with the focus, that is also a descendant of the given window.
1553 // This is used to determine the window to initially send commands to.
1554 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1556 // Process events starting with the window with the focus, if any.
1557 wxWindow
* focusWin
= wxWindow::FindFocus();
1558 wxWindow
* win
= focusWin
;
1560 // Check if this is a descendant of this frame.
1561 // If not, win will be set to NULL.
1564 if (win
== ancestor
)
1567 win
= win
->GetParent();
1569 if (win
== (wxWindow
*) NULL
)
1570 focusWin
= (wxWindow
*) NULL
;
1575 // ----------------------------------------------------------------------------
1577 // ----------------------------------------------------------------------------
1579 wxEventBlocker::wxEventBlocker(wxWindow
*win
, wxEventType type
)
1581 wxCHECK_RET(win
, wxT("Null window given to wxEventBlocker"));
1586 m_window
->PushEventHandler(this);
1589 wxEventBlocker::~wxEventBlocker()
1591 wxEvtHandler
*popped
= m_window
->PopEventHandler(false);
1592 wxCHECK_RET(popped
== this,
1593 wxT("Don't push other event handlers into a window managed by wxEventBlocker!"));
1596 bool wxEventBlocker::ProcessEvent(wxEvent
& event
)
1598 // should this event be blocked?
1599 for ( size_t i
= 0; i
< m_eventsToBlock
.size(); i
++ )
1601 wxEventType t
= (wxEventType
)m_eventsToBlock
[i
];
1602 if ( t
== wxEVT_ANY
|| t
== event
.GetEventType() )
1603 return true; // yes, it should: mark this event as processed