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_TOOL_DROPDOWN_CLICKED
)
189 DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN
)
190 DEFINE_EVENT_TYPE(wxEVT_LEFT_UP
)
191 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN
)
192 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP
)
193 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN
)
194 DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP
)
195 DEFINE_EVENT_TYPE(wxEVT_MOTION
)
196 DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW
)
197 DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW
)
198 DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK
)
199 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK
)
200 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK
)
201 DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS
)
202 DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS
)
203 DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS
)
204 DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL
)
205 DEFINE_EVENT_TYPE(wxEVT_AUX1_DOWN
)
206 DEFINE_EVENT_TYPE(wxEVT_AUX1_UP
)
207 DEFINE_EVENT_TYPE(wxEVT_AUX1_DCLICK
)
208 DEFINE_EVENT_TYPE(wxEVT_AUX2_DOWN
)
209 DEFINE_EVENT_TYPE(wxEVT_AUX2_UP
)
210 DEFINE_EVENT_TYPE(wxEVT_AUX2_DCLICK
)
212 // Non-client mouse events
213 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN
)
214 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP
)
215 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN
)
216 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP
)
217 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN
)
218 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP
)
219 DEFINE_EVENT_TYPE(wxEVT_NC_MOTION
)
220 DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW
)
221 DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW
)
222 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK
)
223 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK
)
224 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK
)
226 // Character input event type
227 DEFINE_EVENT_TYPE(wxEVT_CHAR
)
228 DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK
)
229 DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY
)
230 DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN
)
231 DEFINE_EVENT_TYPE(wxEVT_KEY_UP
)
233 DEFINE_EVENT_TYPE(wxEVT_HOTKEY
)
237 DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR
)
239 // wxScrollbar and wxSlider event identifiers
240 DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP
)
241 DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM
)
242 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP
)
243 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN
)
244 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP
)
245 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN
)
246 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK
)
247 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE
)
248 DEFINE_EVENT_TYPE(wxEVT_SCROLL_CHANGED
)
250 // Scroll events from wxWindow
251 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP
)
252 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM
)
253 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP
)
254 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN
)
255 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP
)
256 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN
)
257 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK
)
258 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE
)
261 DEFINE_EVENT_TYPE(wxEVT_SIZE
)
262 DEFINE_EVENT_TYPE(wxEVT_SIZING
)
263 DEFINE_EVENT_TYPE(wxEVT_MOVE
)
264 DEFINE_EVENT_TYPE(wxEVT_MOVING
)
265 DEFINE_EVENT_TYPE(wxEVT_MOVE_START
)
266 DEFINE_EVENT_TYPE(wxEVT_MOVE_END
)
267 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW
)
268 DEFINE_EVENT_TYPE(wxEVT_END_SESSION
)
269 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION
)
270 DEFINE_EVENT_TYPE(wxEVT_HIBERNATE
)
271 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
272 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
273 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
274 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
275 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
276 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
277 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
278 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
279 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_LOST
)
280 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
281 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
282 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
283 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
284 DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN
)
285 DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE
)
286 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
287 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
288 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
289 DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED
)
290 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
291 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
292 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
293 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
294 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
295 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
296 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
297 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
298 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
299 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
300 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
301 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
302 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
305 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_COPY
)
306 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_CUT
)
307 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_PASTE
)
309 // Generic command events
310 // Note: a click is a higher-level event than button down/up
311 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
312 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
313 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
314 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
315 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
316 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
317 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
320 DEFINE_EVENT_TYPE(wxEVT_HELP
)
321 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
327 wxIdleMode
wxIdleEvent::sm_idleMode
= wxIDLE_PROCESS_ALL
;
329 // ============================================================================
331 // ============================================================================
333 // ----------------------------------------------------------------------------
334 // event initialization
335 // ----------------------------------------------------------------------------
340 static int s_lastUsedEventType
= wxEVT_FIRST
;
342 return s_lastUsedEventType
++;
345 // ----------------------------------------------------------------------------
347 // ----------------------------------------------------------------------------
350 * General wxWidgets events, covering
351 * all interesting things that might happen (button clicking, resizing,
352 * setting text in widgets, etc.).
354 * For each completely new event type, derive a new event class.
358 wxEvent::wxEvent(int theId
, wxEventType commandType
)
360 m_eventType
= commandType
;
361 m_eventObject
= (wxObject
*) NULL
;
365 m_callbackUserData
= (wxObject
*) NULL
;
366 m_isCommandEvent
= false;
367 m_propagationLevel
= wxEVENT_PROPAGATE_NONE
;
370 wxEvent::wxEvent(const wxEvent
&src
)
372 , m_eventObject(src
.m_eventObject
)
373 , m_eventType(src
.m_eventType
)
374 , m_timeStamp(src
.m_timeStamp
)
376 , m_callbackUserData(src
.m_callbackUserData
)
377 , m_propagationLevel(src
.m_propagationLevel
)
378 , m_skipped(src
.m_skipped
)
379 , m_isCommandEvent(src
.m_isCommandEvent
)
393 // 'this' : used in base member initializer list (for m_commandString)
394 #pragma warning(disable:4355)
397 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
398 : wxEvent(theId
, commandType
)
400 m_clientData
= (char *) NULL
;
401 m_clientObject
= (wxClientData
*) NULL
;
404 m_isCommandEvent
= true;
406 // the command events are propagated upwards by default
407 m_propagationLevel
= wxEVENT_PROPAGATE_MAX
;
411 #pragma warning(default:4355)
414 wxString
wxCommandEvent::GetString() const
416 if (m_eventType
!= wxEVT_COMMAND_TEXT_UPDATED
|| !m_eventObject
)
423 wxTextCtrl
*txt
= wxDynamicCast(m_eventObject
, wxTextCtrl
);
425 return txt
->GetValue();
427 #endif // wxUSE_TEXTCTRL
437 wxLongLong
wxUpdateUIEvent::sm_lastUpdate
= 0;
440 long wxUpdateUIEvent::sm_updateInterval
= 0;
442 wxUpdateUIMode
wxUpdateUIEvent::sm_updateMode
= wxUPDATE_UI_PROCESS_ALL
;
445 bool wxUpdateUIEvent::CanUpdate(wxWindowBase
*win
)
447 // Don't update if we've switched global updating off
448 // and this window doesn't support updates.
450 (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED
&&
451 ((win
->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES
) == 0)))
454 if (sm_updateInterval
== -1)
457 if (sm_updateInterval
== 0)
460 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
461 wxLongLong now
= wxGetLocalTimeMillis();
462 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
469 // If we don't have wxStopWatch or wxLongLong, we
470 // should err on the safe side and update now anyway.
475 // Reset the update time to provide a delay until the next
476 // time we should update
477 void wxUpdateUIEvent::ResetUpdateTime()
479 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
480 if (sm_updateInterval
> 0)
482 wxLongLong now
= wxGetLocalTimeMillis();
483 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
495 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
499 : wxCommandEvent(commandType
, id
)
501 m_extraLong
= orient
;
509 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
513 m_eventType
= commandType
;
514 m_extraLong
= orient
;
523 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
525 m_eventType
= commandType
;
531 m_middleDown
= false;
536 m_controlDown
= false;
545 m_linesPerAction
= 0;
549 void wxMouseEvent::Assign(const wxMouseEvent
& event
)
551 m_eventType
= event
.m_eventType
;
556 m_leftDown
= event
.m_leftDown
;
557 m_middleDown
= event
.m_middleDown
;
558 m_rightDown
= event
.m_rightDown
;
559 m_aux1Down
= event
.m_aux1Down
;
560 m_aux2Down
= event
.m_aux2Down
;
562 m_controlDown
= event
.m_controlDown
;
563 m_shiftDown
= event
.m_shiftDown
;
564 m_altDown
= event
.m_altDown
;
565 m_metaDown
= event
.m_metaDown
;
567 m_wheelRotation
= event
.m_wheelRotation
;
568 m_wheelDelta
= event
.m_wheelDelta
;
569 m_linesPerAction
= event
.m_linesPerAction
;
570 m_wheelAxis
= event
.m_wheelAxis
;
573 // return true if was a button dclick event
574 bool wxMouseEvent::ButtonDClick(int but
) const
579 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
582 case wxMOUSE_BTN_ANY
:
583 return (LeftDClick() || MiddleDClick() || RightDClick() ||
584 Aux1DClick() || Aux2DClick());
586 case wxMOUSE_BTN_LEFT
:
589 case wxMOUSE_BTN_MIDDLE
:
590 return MiddleDClick();
592 case wxMOUSE_BTN_RIGHT
:
593 return RightDClick();
595 case wxMOUSE_BTN_AUX1
:
598 case wxMOUSE_BTN_AUX2
:
603 // return true if was a button down event
604 bool wxMouseEvent::ButtonDown(int but
) const
609 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
612 case wxMOUSE_BTN_ANY
:
613 return (LeftDown() || MiddleDown() || RightDown() ||
614 Aux1Down() || Aux2Down());
616 case wxMOUSE_BTN_LEFT
:
619 case wxMOUSE_BTN_MIDDLE
:
622 case wxMOUSE_BTN_RIGHT
:
625 case wxMOUSE_BTN_AUX1
:
628 case wxMOUSE_BTN_AUX2
:
633 // return true if was a button up event
634 bool wxMouseEvent::ButtonUp(int but
) const
639 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
642 case wxMOUSE_BTN_ANY
:
643 return (LeftUp() || MiddleUp() || RightUp() ||
644 Aux1Up() || Aux2Up());
646 case wxMOUSE_BTN_LEFT
:
649 case wxMOUSE_BTN_MIDDLE
:
652 case wxMOUSE_BTN_RIGHT
:
655 case wxMOUSE_BTN_AUX1
:
658 case wxMOUSE_BTN_AUX2
:
663 // return true if the given button is currently changing state
664 bool wxMouseEvent::Button(int but
) const
669 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
672 case wxMOUSE_BTN_ANY
:
673 return ButtonUp(wxMOUSE_BTN_ANY
) ||
674 ButtonDown(wxMOUSE_BTN_ANY
) ||
675 ButtonDClick(wxMOUSE_BTN_ANY
);
677 case wxMOUSE_BTN_LEFT
:
678 return LeftDown() || LeftUp() || LeftDClick();
680 case wxMOUSE_BTN_MIDDLE
:
681 return MiddleDown() || MiddleUp() || MiddleDClick();
683 case wxMOUSE_BTN_RIGHT
:
684 return RightDown() || RightUp() || RightDClick();
686 case wxMOUSE_BTN_AUX1
:
687 return Aux1Down() || Aux1Up() || Aux1DClick();
689 case wxMOUSE_BTN_AUX2
:
690 return Aux2Down() || Aux2Up() || Aux2DClick();
694 bool wxMouseEvent::ButtonIsDown(int but
) const
699 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
702 case wxMOUSE_BTN_ANY
:
703 return LeftIsDown() || MiddleIsDown() || RightIsDown() || Aux1Down() || Aux2Down();
705 case wxMOUSE_BTN_LEFT
:
708 case wxMOUSE_BTN_MIDDLE
:
709 return MiddleIsDown();
711 case wxMOUSE_BTN_RIGHT
:
712 return RightIsDown();
714 case wxMOUSE_BTN_AUX1
:
717 case wxMOUSE_BTN_AUX2
:
722 int wxMouseEvent::GetButton() const
724 for ( int i
= 1; i
< wxMOUSE_BTN_MAX
; i
++ )
732 return wxMOUSE_BTN_NONE
;
735 // Find the logical position of the event given the DC
736 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
738 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
748 wxKeyEvent::wxKeyEvent(wxEventType type
)
752 m_controlDown
= false;
762 wxKeyEvent::wxKeyEvent(const wxKeyEvent
& evt
)
768 m_keyCode
= evt
.m_keyCode
;
770 m_controlDown
= evt
.m_controlDown
;
771 m_shiftDown
= evt
.m_shiftDown
;
772 m_altDown
= evt
.m_altDown
;
773 m_metaDown
= evt
.m_metaDown
;
774 m_scanCode
= evt
.m_scanCode
;
775 m_rawCode
= evt
.m_rawCode
;
776 m_rawFlags
= evt
.m_rawFlags
;
779 m_uniChar
= evt
.m_uniChar
;
783 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
785 SetEventType(wxEVT_CREATE
);
789 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
791 SetEventType(wxEVT_DESTROY
);
795 wxChildFocusEvent::wxChildFocusEvent(wxWindow
*win
)
796 : wxCommandEvent(wxEVT_CHILD_FOCUS
)
801 // ----------------------------------------------------------------------------
803 // ----------------------------------------------------------------------------
806 wxHelpEvent::Origin
wxHelpEvent::GuessOrigin(Origin origin
)
808 if ( origin
== Origin_Unknown
)
810 // assume that the event comes from the help button if it's not from
811 // keyboard and that pressing F1 always results in the help event
812 origin
= wxGetKeyState(WXK_F1
) ? Origin_Keyboard
: Origin_HelpButton
;
823 // ----------------------------------------------------------------------------
825 // ----------------------------------------------------------------------------
827 static const int EVENT_TYPE_TABLE_INIT_SIZE
= 31; // Not too big not too small...
829 wxEventHashTable
* wxEventHashTable::sm_first
= NULL
;
831 wxEventHashTable::wxEventHashTable(const wxEventTable
&table
)
835 AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE
);
839 m_next
->m_previous
= this;
843 wxEventHashTable::~wxEventHashTable()
846 m_next
->m_previous
= m_previous
;
848 m_previous
->m_next
= m_next
;
849 if (sm_first
== this)
855 void wxEventHashTable::Clear()
857 for ( size_t i
= 0; i
< m_size
; i
++ )
859 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
863 delete[] m_eventTypeTable
;
864 m_eventTypeTable
= NULL
;
869 #if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
872 void wxEventHashTable::ClearAll()
874 wxEventHashTable
* table
= sm_first
;
878 table
= table
->m_next
;
882 #endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING
884 bool wxEventHashTable::HandleEvent(wxEvent
&event
, wxEvtHandler
*self
)
889 m_rebuildHash
= false;
892 if (!m_eventTypeTable
)
895 // Find all entries for the given event type.
896 wxEventType eventType
= event
.GetEventType();
897 const EventTypeTablePointer eTTnode
= m_eventTypeTable
[eventType
% m_size
];
898 if (eTTnode
&& eTTnode
->eventType
== eventType
)
900 // Now start the search for an event handler
901 // that can handle an event with the given ID.
902 const wxEventTableEntryPointerArray
&
903 eventEntryTable
= eTTnode
->eventEntryTable
;
905 const size_t count
= eventEntryTable
.GetCount();
906 for (size_t n
= 0; n
< count
; n
++)
909 ProcessEventIfMatches(*eventEntryTable
[n
], self
, event
) )
919 void wxEventHashTable::InitHashTable()
921 // Loop over the event tables and all its base tables.
922 const wxEventTable
*table
= &m_table
;
925 // Retrieve all valid event handler entries
926 const wxEventTableEntry
*entry
= table
->entries
;
927 while (entry
->m_fn
!= 0)
929 // Add the event entry in the Hash.
935 table
= table
->baseTable
;
938 // Lets free some memory.
940 for(i
= 0; i
< m_size
; i
++)
942 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
945 eTTnode
->eventEntryTable
.Shrink();
950 void wxEventHashTable::AddEntry(const wxEventTableEntry
&entry
)
952 // This might happen 'accidentally' as the app is exiting
953 if (!m_eventTypeTable
)
956 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[entry
.m_eventType
% m_size
];
957 EventTypeTablePointer eTTnode
= *peTTnode
;
961 if (eTTnode
->eventType
!= entry
.m_eventType
)
964 GrowEventTypeTable();
965 // Try again to add it.
972 eTTnode
= new EventTypeTable
;
973 eTTnode
->eventType
= entry
.m_eventType
;
977 // Fill all hash entries between entry.m_id and entry.m_lastId...
978 eTTnode
->eventEntryTable
.Add(&entry
);
981 void wxEventHashTable::AllocEventTypeTable(size_t size
)
983 m_eventTypeTable
= new EventTypeTablePointer
[size
];
984 memset((void *)m_eventTypeTable
, 0, sizeof(EventTypeTablePointer
)*size
);
988 void wxEventHashTable::GrowEventTypeTable()
990 size_t oldSize
= m_size
;
991 EventTypeTablePointer
*oldEventTypeTable
= m_eventTypeTable
;
993 // TODO: Search the most optimal grow sequence
994 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize
*2+1);
996 for ( size_t i
= 0; i
< oldSize
; /* */ )
998 EventTypeTablePointer eTToldNode
= oldEventTypeTable
[i
];
1001 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[eTToldNode
->eventType
% m_size
];
1002 EventTypeTablePointer eTTnode
= *peTTnode
;
1004 // Check for collision, we don't want any.
1007 GrowEventTypeTable();
1008 continue; // Don't increment the counter,
1009 // as we still need to add this element.
1013 // Get the old value and put it in the new table.
1014 *peTTnode
= oldEventTypeTable
[i
];
1021 delete[] oldEventTypeTable
;
1024 // ----------------------------------------------------------------------------
1026 // ----------------------------------------------------------------------------
1032 wxEvtHandler::wxEvtHandler()
1034 m_nextHandler
= (wxEvtHandler
*) NULL
;
1035 m_previousHandler
= (wxEvtHandler
*) NULL
;
1037 m_dynamicEvents
= (wxList
*) NULL
;
1038 m_pendingEvents
= (wxList
*) NULL
;
1040 // no client data (yet)
1041 m_clientData
= NULL
;
1042 m_clientDataType
= wxClientData_None
;
1045 wxEvtHandler::~wxEvtHandler()
1047 // Takes itself out of the list of handlers
1048 if (m_previousHandler
)
1049 m_previousHandler
->m_nextHandler
= m_nextHandler
;
1052 m_nextHandler
->m_previousHandler
= m_previousHandler
;
1054 if (m_dynamicEvents
)
1056 for ( wxList::iterator it
= m_dynamicEvents
->begin(),
1057 end
= m_dynamicEvents
->end();
1061 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
);
1077 #endif // wxUSE_WEAKREF
1079 if (entry
->m_callbackUserData
)
1080 delete entry
->m_callbackUserData
;
1083 delete m_dynamicEvents
;
1086 if (m_pendingEvents
)
1087 m_pendingEvents
->DeleteContents(true);
1088 delete m_pendingEvents
;
1090 // Remove us from wxPendingEvents if necessary.
1091 if ( wxPendingEvents
)
1094 if (wxPendingEventsLocker
)
1095 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
1098 if ( wxPendingEvents
->DeleteObject(this) )
1100 // check that we were present only once in the list
1101 wxASSERT_MSG( !wxPendingEvents
->Find(this),
1102 "Handler occurs twice in wxPendingEvents list" );
1104 //else: we weren't in this list at all, it's ok
1107 if (wxPendingEventsLocker
)
1108 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
1112 // we only delete object data, not untyped
1113 if ( m_clientDataType
== wxClientData_Object
)
1114 delete m_clientObject
;
1119 bool wxEvtHandler::ProcessThreadEvent(const wxEvent
& event
)
1121 // check that we are really in a child thread
1122 wxASSERT_MSG( !wxThread::IsMain(),
1123 wxT("use ProcessEvent() in main thread") );
1125 AddPendingEvent(event
);
1130 #endif // wxUSE_THREADS
1132 void wxEvtHandler::AddPendingEvent(const wxEvent
& event
)
1134 // 1) Add event to list of pending events of this event handler
1136 wxEvent
*eventCopy
= event
.Clone();
1138 // we must be able to copy the events here so the event class must
1139 // implement Clone() properly instead of just providing a NULL stab for it
1140 wxCHECK_RET( eventCopy
,
1141 _T("events of this type aren't supposed to be posted") );
1143 wxENTER_CRIT_SECT( m_pendingEventsLock
);
1145 if ( !m_pendingEvents
)
1146 m_pendingEvents
= new wxList
;
1148 m_pendingEvents
->Append(eventCopy
);
1150 wxLEAVE_CRIT_SECT( m_pendingEventsLock
);
1152 // 2) Add this event handler to list of event handlers that
1153 // have pending events.
1155 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
1157 if ( !wxPendingEvents
)
1158 wxPendingEvents
= new wxList
;
1159 if ( !wxPendingEvents
->Find(this) )
1160 wxPendingEvents
->Append(this);
1162 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
1164 // 3) Inform the system that new pending events are somewhere,
1165 // and that these should be processed in idle time.
1169 void wxEvtHandler::ProcessPendingEvents()
1171 wxENTER_CRIT_SECT( m_pendingEventsLock
);
1173 // this method is only called by wxApp if this handler does have
1175 wxCHECK_RET( m_pendingEvents
&& !m_pendingEvents
->IsEmpty(),
1176 "should have pending events if called" );
1178 wxList::compatibility_iterator node
= m_pendingEvents
->GetFirst();
1179 wxEventPtr
event(wx_static_cast(wxEvent
*, node
->GetData()));
1181 // it's important we remove event from list before processing it, else a
1182 // nested event loop, for example from a modal dialog, might process the
1183 // same event again.
1184 m_pendingEvents
->Erase(node
);
1186 // if there are no more pending events left, we don't need to stay in this
1188 if ( m_pendingEvents
->IsEmpty() )
1189 wxPendingEvents
->DeleteObject(this);
1191 wxLEAVE_CRIT_SECT( m_pendingEventsLock
);
1193 ProcessEvent(*event
);
1195 // careful: this object could have been deleted by the event handler
1196 // executed by the above ProcessEvent() call, so we can't access any fields
1197 // of this object any more
1204 wxEvtHandler::ProcessEventIfMatches(const wxEventTableEntryBase
& entry
,
1205 wxEvtHandler
*handler
,
1208 int tableId1
= entry
.m_id
,
1209 tableId2
= entry
.m_lastId
;
1211 // match only if the event type is the same and the id is either -1 in
1212 // the event table (meaning "any") or the event id matches the id
1213 // specified in the event table either exactly or by falling into
1214 // range between first and last
1215 if ((tableId1
== wxID_ANY
) ||
1216 (tableId2
== wxID_ANY
&& tableId1
== event
.GetId()) ||
1217 (tableId2
!= wxID_ANY
&&
1218 (event
.GetId() >= tableId1
&& event
.GetId() <= tableId2
)))
1221 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1223 #if wxUSE_EXCEPTIONS
1226 // call the handler via wxApp method which allows the user to catch
1227 // any exceptions which may be thrown by any handler in the program
1229 wxTheApp
->HandleEvent(handler
, (wxEventFunction
)entry
.m_fn
, event
);
1232 #endif // wxUSE_EXCEPTIONS
1234 // no need for an extra virtual function call
1235 (handler
->*((wxEventFunction
) (entry
.m_fn
)))(event
);
1238 if (!event
.GetSkipped())
1245 bool wxEvtHandler::TryParent(wxEvent
& event
)
1247 if ( wxTheApp
&& (this != wxTheApp
) )
1249 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1250 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1251 // processed appropriately via SearchEventTable.
1252 if ( event
.GetEventType() != wxEVT_IDLE
)
1254 if ( wxTheApp
->ProcessEvent(event
) )
1262 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
1264 // allow the application to hook into event processing
1267 int rc
= wxTheApp
->FilterEvent(event
);
1270 wxASSERT_MSG( rc
== 1 || rc
== 0,
1271 _T("unexpected wxApp::FilterEvent return value") );
1275 //else: proceed normally
1278 // An event handler can be enabled or disabled
1279 if ( GetEvtHandlerEnabled() )
1281 // if we have a validator, it has higher priority than our own event
1283 if ( TryValidator(event
) )
1286 // Handle per-instance dynamic event tables first
1287 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
1290 // Then static per-class event tables
1291 if ( GetEventHashTable().HandleEvent(event
, this) )
1295 // Try going down the event handler chain
1296 if ( GetNextHandler() )
1298 // notice that we shouldn't let the parent have the event even if the
1299 // next handler does not process it because it will have already passed
1300 // it to the parent in this case
1301 return GetNextHandler()->ProcessEvent(event
);
1304 // Finally propagate the event upwards the window chain and/or to the
1305 // application object as necessary
1306 return TryParent(event
);
1309 bool wxEvtHandler::SafelyProcessEvent(wxEvent
& event
)
1311 #if wxUSE_EXCEPTIONS
1315 return ProcessEvent(event
);
1316 #if wxUSE_EXCEPTIONS
1320 wxEventLoopBase
*loop
= wxEventLoopBase::GetActive();
1323 if ( !wxTheApp
|| !wxTheApp
->OnExceptionInMainLoop() )
1328 //else: continue running current event loop
1334 // OnExceptionInMainLoop() threw, possibly rethrowing the same
1335 // exception again: very good, but we still need Exit() to
1342 #endif // wxUSE_EXCEPTIONS
1346 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
1348 const wxEventType eventType
= event
.GetEventType();
1349 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
1351 const wxEventTableEntry
& entry
= table
.entries
[i
];
1352 if ( eventType
== entry
.m_eventType
)
1354 if ( ProcessEventIfMatches(entry
, this, event
) )
1362 void wxEvtHandler::Connect( int id
, int lastId
,
1364 wxObjectEventFunction func
,
1366 wxEvtHandler
* eventSink
)
1368 wxDynamicEventTableEntry
*entry
=
1369 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
, eventSink
);
1371 if (!m_dynamicEvents
)
1372 m_dynamicEvents
= new wxList
;
1374 // Insert at the front of the list so most recent additions are found first
1375 m_dynamicEvents
->Insert( (wxObject
*) entry
);
1378 // Make sure we get to know when a sink is destroyed
1381 wxEventConnectionRef
*evtConnRef
= FindRefInTrackerList(eventSink
);
1383 evtConnRef
->IncRef( );
1385 evtConnRef
= new wxEventConnectionRef(this, eventSink
);
1387 #endif // wxUSE_WEAKREF
1390 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1391 wxObjectEventFunction func
,
1393 wxEvtHandler
* eventSink
)
1395 if (!m_dynamicEvents
)
1399 // Remove connection from tracker node (wxEventConnectionRef)
1402 wxEventConnectionRef
*evtConnRef
= FindRefInTrackerList(eventSink
);
1404 evtConnRef
->DecRef();
1406 #endif // wxUSE_WEAKREF
1408 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1411 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1413 if ((entry
->m_id
== id
) &&
1414 ((entry
->m_lastId
== lastId
) || (lastId
== wxID_ANY
)) &&
1415 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1416 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1417 ((entry
->m_eventSink
== eventSink
) || (eventSink
== (wxEvtHandler
*)NULL
)) &&
1418 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1420 if (entry
->m_callbackUserData
)
1421 delete entry
->m_callbackUserData
;
1422 m_dynamicEvents
->Erase( node
);
1426 node
= node
->GetNext();
1431 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1433 wxCHECK_MSG( m_dynamicEvents
, false,
1434 wxT("caller should check that we have dynamic events") );
1436 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1439 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1441 // get next node before (maybe) calling the event handler as it could
1442 // call Disconnect() invalidating the current node
1443 node
= node
->GetNext();
1445 if ((event
.GetEventType() == entry
->m_eventType
) && (entry
->m_fn
!= 0))
1447 wxEvtHandler
*handler
= entry
->m_eventSink
? entry
->m_eventSink
1449 if ( ProcessEventIfMatches(*entry
, handler
, event
) )
1457 void wxEvtHandler::DoSetClientObject( wxClientData
*data
)
1459 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1460 wxT("can't have both object and void client data") );
1462 if ( m_clientObject
)
1463 delete m_clientObject
;
1465 m_clientObject
= data
;
1466 m_clientDataType
= wxClientData_Object
;
1469 wxClientData
*wxEvtHandler::DoGetClientObject() const
1471 // it's not an error to call GetClientObject() on a window which doesn't
1472 // have client data at all - NULL will be returned
1473 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1474 wxT("this window doesn't have object client data") );
1476 return m_clientObject
;
1479 void wxEvtHandler::DoSetClientData( void *data
)
1481 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1482 wxT("can't have both object and void client data") );
1484 m_clientData
= data
;
1485 m_clientDataType
= wxClientData_Void
;
1488 void *wxEvtHandler::DoGetClientData() const
1490 // it's not an error to call GetClientData() on a window which doesn't have
1491 // client data at all - NULL will be returned
1492 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1493 wxT("this window doesn't have void client data") );
1495 return m_clientData
;
1499 // A helper to find an wxEventConnectionRef object
1500 wxEventConnectionRef
*
1501 wxEvtHandler::FindRefInTrackerList(wxEvtHandler
*eventSink
)
1503 for ( wxTrackerNode
*node
= eventSink
->GetFirst(); node
; node
= node
->m_nxt
)
1505 // we only want wxEventConnectionRef nodes here
1506 wxEventConnectionRef
*evtConnRef
= node
->ToEventConnection();
1507 if ( evtConnRef
&& evtConnRef
->m_src
== this )
1509 wxASSERT( evtConnRef
->m_sink
==eventSink
);
1517 void wxEvtHandler::OnSinkDestroyed( wxEvtHandler
*sink
)
1519 wxASSERT(m_dynamicEvents
);
1521 // remove all connections with this sink
1522 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst(), node_nxt
;
1525 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1526 node_nxt
= node
->GetNext();
1528 if ( entry
->m_eventSink
==sink
)
1530 if (entry
->m_callbackUserData
)
1531 delete entry
->m_callbackUserData
;
1532 m_dynamicEvents
->Erase( node
);
1538 #endif // wxUSE_WEAKREF
1540 #endif // wxUSE_BASE
1544 // Find a window with the focus, that is also a descendant of the given window.
1545 // This is used to determine the window to initially send commands to.
1546 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1548 // Process events starting with the window with the focus, if any.
1549 wxWindow
* focusWin
= wxWindow::FindFocus();
1550 wxWindow
* win
= focusWin
;
1552 // Check if this is a descendant of this frame.
1553 // If not, win will be set to NULL.
1556 if (win
== ancestor
)
1559 win
= win
->GetParent();
1561 if (win
== (wxWindow
*) NULL
)
1562 focusWin
= (wxWindow
*) NULL
;
1567 // ----------------------------------------------------------------------------
1569 // ----------------------------------------------------------------------------
1571 wxEventBlocker::wxEventBlocker(wxWindow
*win
, wxEventType type
)
1573 wxCHECK_RET(win
, wxT("Null window given to wxEventBlocker"));
1578 m_window
->PushEventHandler(this);
1581 wxEventBlocker::~wxEventBlocker()
1583 wxEvtHandler
*popped
= m_window
->PopEventHandler(false);
1584 wxCHECK_RET(popped
== this,
1585 wxT("Don't push other event handlers into a window managed by wxEventBlocker!"));
1588 bool wxEventBlocker::ProcessEvent(wxEvent
& event
)
1590 // should this event be blocked?
1591 for ( size_t i
= 0; i
< m_eventsToBlock
.size(); i
++ )
1593 wxEventType t
= (wxEventType
)m_eventsToBlock
[i
];
1594 if ( t
== wxEVT_ANY
|| t
== event
.GetEventType() )
1595 return true; // yes, it should: mark this event as processed