1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Event classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "event.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
37 #include "wx/control.h"
46 #include "wx/validate.h"
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
54 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler
, wxObject
)
55 IMPLEMENT_ABSTRACT_CLASS(wxEvent
, wxObject
)
59 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent
, wxEvent
)
60 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent
, wxEvent
)
61 IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent
, wxCommandEvent
)
62 IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent
, wxCommandEvent
)
63 IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent
, wxEvent
)
64 IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent
, wxEvent
)
65 IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent
, wxEvent
)
66 IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent
, wxEvent
)
67 IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent
, wxEvent
)
68 IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent
, wxEvent
)
69 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent
, wxEvent
)
70 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent
, wxEvent
)
71 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent
, wxEvent
)
72 IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent
, wxCommandEvent
)
73 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent
, wxEvent
)
74 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent
, wxEvent
)
75 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent
, wxEvent
)
76 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent
, wxEvent
)
77 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent
, wxEvent
)
78 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent
, wxEvent
)
79 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent
, wxEvent
)
80 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent
, wxEvent
)
81 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent
, wxEvent
)
82 IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent
, wxEvent
)
83 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent
, wxEvent
)
84 IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent
, wxEvent
)
85 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent
, wxCommandEvent
)
86 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent
, wxCommandEvent
)
87 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent
, wxEvent
)
88 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent
, wxEvent
)
89 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent
, wxEvent
)
90 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent
, wxEvent
)
91 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent
, wxCommandEvent
)
92 IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent
, wxCommandEvent
)
93 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent
, wxEvent
)
98 const wxEventTable
*wxEvtHandler::GetEventTable() const
99 { return &wxEvtHandler::sm_eventTable
; }
101 const wxEventTable
wxEvtHandler::sm_eventTable
=
102 { (const wxEventTable
*)NULL
, &wxEvtHandler::sm_eventTableEntries
[0] };
104 const wxEventTableEntry
wxEvtHandler::sm_eventTableEntries
[] =
105 { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL
, 0, 0, (wxObjectEventFunction
)NULL
, NULL
) };
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 // To put pending event handlers
112 wxList
*wxPendingEvents
= (wxList
*)NULL
;
115 // protects wxPendingEvents list
116 wxCriticalSection
*wxPendingEventsLocker
= (wxCriticalSection
*)NULL
;
119 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
121 // common event types are defined here, other event types are defined by the
122 // components which use them
124 DEFINE_EVENT_TYPE(wxEVT_NULL
)
125 DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED
)
126 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED
)
127 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED
)
128 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED
)
129 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
)
130 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
)
131 DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED
)
132 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED
)
133 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED
)
134 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED
)
135 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED
)
136 DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED
)
137 DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED
)
138 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED
)
139 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER
)
140 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED
)
142 // Sockets and timers send events, too
143 DEFINE_EVENT_TYPE(wxEVT_SOCKET
)
144 DEFINE_EVENT_TYPE(wxEVT_TIMER
)
147 DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN
)
148 DEFINE_EVENT_TYPE(wxEVT_LEFT_UP
)
149 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN
)
150 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP
)
151 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN
)
152 DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP
)
153 DEFINE_EVENT_TYPE(wxEVT_MOTION
)
154 DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW
)
155 DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW
)
156 DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK
)
157 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK
)
158 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK
)
159 DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS
)
160 DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS
)
161 DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS
)
162 DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL
)
164 // Non-client mouse events
165 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN
)
166 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP
)
167 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN
)
168 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP
)
169 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN
)
170 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP
)
171 DEFINE_EVENT_TYPE(wxEVT_NC_MOTION
)
172 DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW
)
173 DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW
)
174 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK
)
175 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK
)
176 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK
)
178 // Character input event type
179 DEFINE_EVENT_TYPE(wxEVT_CHAR
)
180 DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK
)
181 DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY
)
182 DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN
)
183 DEFINE_EVENT_TYPE(wxEVT_KEY_UP
)
186 DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR
)
188 // wxScrollbar and wxSlider event identifiers
189 DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP
)
190 DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM
)
191 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP
)
192 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN
)
193 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP
)
194 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN
)
195 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK
)
196 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE
)
197 DEFINE_EVENT_TYPE(wxEVT_SCROLL_ENDSCROLL
)
199 // Scroll events from wxWindow
200 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP
)
201 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM
)
202 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP
)
203 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN
)
204 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP
)
205 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN
)
206 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK
)
207 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE
)
210 DEFINE_EVENT_TYPE(wxEVT_SIZE
)
211 DEFINE_EVENT_TYPE(wxEVT_SIZING
)
212 DEFINE_EVENT_TYPE(wxEVT_MOVE
)
213 DEFINE_EVENT_TYPE(wxEVT_MOVING
)
214 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW
)
215 DEFINE_EVENT_TYPE(wxEVT_END_SESSION
)
216 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION
)
217 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
218 DEFINE_EVENT_TYPE(wxEVT_POWER
)
219 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
220 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
221 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
222 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
223 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
224 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
225 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
226 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
227 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
228 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
229 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
230 DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN
)
231 DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE
)
232 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
233 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
234 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
235 DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED
)
236 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
237 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
238 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
239 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
240 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
241 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
242 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
243 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
244 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
245 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
246 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
247 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
248 DEFINE_EVENT_TYPE(wxEVT_IDLE
)
249 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
251 // Generic command events
252 // Note: a click is a higher-level event than button down/up
253 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
254 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
255 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
256 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
257 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
258 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
259 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
262 DEFINE_EVENT_TYPE(wxEVT_HELP
)
263 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
265 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
267 // ============================================================================
269 // ============================================================================
271 // ----------------------------------------------------------------------------
272 // event initialization
273 // ----------------------------------------------------------------------------
278 static int s_lastUsedEventType
= wxEVT_FIRST
;
280 #if WXWIN_COMPATIBILITY_2
281 // check that we don't overlap with the user-defined types: if it does
282 // happen, the best solution is probably to update the existing code to
283 // use wxNewEventType() instead of wxEVT_USER_FIRST
285 // due to the uncertainty
286 wxASSERT_MSG( s_lastUsedEventType
< wxEVT_USER_FIRST
- 1,
287 _T("possible event type conflict") );
288 #endif // WXWIN_COMPATIBILITY_2
290 return s_lastUsedEventType
++;
293 // ----------------------------------------------------------------------------
295 // ----------------------------------------------------------------------------
298 * General wxWindows events, covering
299 * all interesting things that might happen (button clicking, resizing,
300 * setting text in widgets, etc.).
302 * For each completely new event type, derive a new event class.
306 wxEvent::wxEvent(int theId
, wxEventType commandType
)
308 m_eventType
= commandType
;
309 m_eventObject
= (wxObject
*) NULL
;
313 m_callbackUserData
= (wxObject
*) NULL
;
314 m_isCommandEvent
= FALSE
;
317 wxEvent::wxEvent(const wxEvent
&src
)
319 , m_eventObject(src
.m_eventObject
)
320 , m_eventType(src
.m_eventType
)
321 , m_timeStamp(src
.m_timeStamp
)
323 , m_callbackUserData(src
.m_callbackUserData
)
324 , m_skipped(src
.m_skipped
)
325 , m_isCommandEvent(src
.m_isCommandEvent
)
338 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
339 : wxEvent(theId
, commandType
)
341 m_clientData
= (char *) NULL
;
342 m_clientObject
= (wxClientData
*) NULL
;
345 m_commandString
= wxEmptyString
;
346 m_isCommandEvent
= TRUE
;
353 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
357 : wxCommandEvent(commandType
, id
)
359 m_extraLong
= orient
;
367 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
371 m_eventType
= commandType
;
372 m_extraLong
= orient
;
381 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
383 m_eventType
= commandType
;
386 m_controlDown
= FALSE
;
390 m_middleDown
= FALSE
;
395 m_linesPerAction
= 0;
398 void wxMouseEvent::Assign(const wxMouseEvent
& event
)
400 m_eventType
= event
.m_eventType
;
405 m_leftDown
= event
.m_leftDown
;
406 m_middleDown
= event
.m_middleDown
;
407 m_rightDown
= event
.m_rightDown
;
409 m_controlDown
= event
.m_controlDown
;
410 m_shiftDown
= event
.m_shiftDown
;
411 m_altDown
= event
.m_altDown
;
412 m_metaDown
= event
.m_metaDown
;
414 m_wheelRotation
= event
.m_wheelRotation
;
415 m_wheelDelta
= event
.m_wheelDelta
;
416 m_linesPerAction
= event
.m_linesPerAction
;
419 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
420 // or any button dclick event (but = -1)
421 bool wxMouseEvent::ButtonDClick(int but
) const
426 return (LeftDClick() || MiddleDClick() || RightDClick());
430 return MiddleDClick();
432 return RightDClick();
434 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
440 // True if was a button down event (1 = left, 2 = middle, 3 = right)
441 // or any button down event (but = -1)
442 bool wxMouseEvent::ButtonDown(int but
) const
447 return (LeftDown() || MiddleDown() || RightDown());
455 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
461 // True if was a button up event (1 = left, 2 = middle, 3 = right)
462 // or any button up event (but = -1)
463 bool wxMouseEvent::ButtonUp(int but
) const
468 return (LeftUp() || MiddleUp() || RightUp());
476 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
482 // True if the given button is currently changing state
483 bool wxMouseEvent::Button(int but
) const
488 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
490 return (LeftDown() || LeftUp() || LeftDClick());
492 return (MiddleDown() || MiddleUp() || MiddleDClick());
494 return (RightDown() || RightUp() || RightDClick());
496 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
502 bool wxMouseEvent::ButtonIsDown(int but
) const
507 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
511 return MiddleIsDown();
513 return RightIsDown();
515 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
521 int wxMouseEvent::GetButton() const
523 for ( int i
= 1; i
<= 3; i
++ )
534 // Find the logical position of the event given the DC
535 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
537 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
547 wxKeyEvent::wxKeyEvent(wxEventType type
)
551 m_controlDown
= FALSE
;
561 wxKeyEvent::wxKeyEvent(const wxKeyEvent
& evt
)
567 m_keyCode
= evt
.m_keyCode
;
569 m_controlDown
= evt
.m_controlDown
;
570 m_shiftDown
= evt
.m_shiftDown
;
571 m_altDown
= evt
.m_altDown
;
572 m_metaDown
= evt
.m_metaDown
;
573 m_scanCode
= evt
.m_scanCode
;
574 m_rawCode
= evt
.m_rawCode
;
575 m_rawFlags
= evt
.m_rawFlags
;
578 m_uniChar
= evt
.m_uniChar
;
582 long wxKeyEvent::KeyCode() const
587 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
589 SetEventType(wxEVT_CREATE
);
593 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
595 SetEventType(wxEVT_DESTROY
);
599 wxChildFocusEvent::wxChildFocusEvent(wxWindow
*win
)
600 : wxCommandEvent(wxEVT_CHILD_FOCUS
)
607 // ----------------------------------------------------------------------------
609 // ----------------------------------------------------------------------------
617 wxEvtHandler::wxEvtHandler()
619 m_nextHandler
= (wxEvtHandler
*) NULL
;
620 m_previousHandler
= (wxEvtHandler
*) NULL
;
622 m_dynamicEvents
= (wxList
*) NULL
;
624 m_pendingEvents
= (wxList
*) NULL
;
626 # if !defined(__VISAGECPP__)
627 m_eventsLocker
= new wxCriticalSection
;
630 // no client data (yet)
632 m_clientDataType
= wxClientData_None
;
635 wxEvtHandler::~wxEvtHandler()
637 // Takes itself out of the list of handlers
638 if (m_previousHandler
)
639 m_previousHandler
->m_nextHandler
= m_nextHandler
;
642 m_nextHandler
->m_previousHandler
= m_previousHandler
;
646 wxNode
*node
= m_dynamicEvents
->GetFirst();
649 #if WXWIN_COMPATIBILITY_EVENT_TYPES
650 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
651 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
652 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
653 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
655 if (entry
->m_callbackUserData
)
656 delete entry
->m_callbackUserData
;
658 node
= node
->GetNext();
660 delete m_dynamicEvents
;
663 delete m_pendingEvents
;
666 # if !defined(__VISAGECPP__)
667 delete m_eventsLocker
;
670 // Remove us from wxPendingEvents if necessary.
671 if(wxPendingEventsLocker
)
672 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
673 if ( wxPendingEvents
) {
674 wxPendingEvents
->DeleteObject(this);
676 if(wxPendingEventsLocker
)
677 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
680 // we only delete object data, not untyped
681 if ( m_clientDataType
== wxClientData_Object
)
682 delete m_clientObject
;
687 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
689 // check that we are really in a child thread
690 wxASSERT_MSG( !wxThread::IsMain(),
691 wxT("use ProcessEvent() in main thread") );
693 AddPendingEvent(event
);
698 #endif // wxUSE_THREADS
700 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
702 // 1) Add event to list of pending events of this event handler
704 wxEvent
*eventCopy
= event
.Clone();
706 // we must be able to copy the events here so the event class must
707 // implement Clone() properly instead of just providing a NULL stab for it
708 wxCHECK_RET( eventCopy
,
709 _T("events of this type aren't supposed to be posted") );
711 #if defined(__VISAGECPP__)
712 wxENTER_CRIT_SECT( m_eventsLocker
);
714 wxENTER_CRIT_SECT( *m_eventsLocker
);
717 if ( !m_pendingEvents
)
718 m_pendingEvents
= new wxList
;
720 m_pendingEvents
->Append(eventCopy
);
722 #if defined(__VISAGECPP__)
723 wxLEAVE_CRIT_SECT( m_eventsLocker
);
725 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
728 // 2) Add this event handler to list of event handlers that
729 // have pending events.
731 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
733 if ( !wxPendingEvents
)
734 wxPendingEvents
= new wxList
;
735 wxPendingEvents
->Append(this);
737 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
739 // 3) Inform the system that new pending events are somwehere,
740 // and that these should be processed in idle time.
744 void wxEvtHandler::ProcessPendingEvents()
746 #if defined(__VISAGECPP__)
747 wxENTER_CRIT_SECT( m_eventsLocker
);
749 wxENTER_CRIT_SECT( *m_eventsLocker
);
752 wxNode
*node
= m_pendingEvents
->GetFirst();
755 wxEvent
*event
= (wxEvent
*)node
->GetData();
758 // In ProcessEvent, new events might get added and
759 // we can safely leave the crtical section here.
760 #if defined(__VISAGECPP__)
761 wxLEAVE_CRIT_SECT( m_eventsLocker
);
763 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
765 ProcessEvent(*event
);
767 #if defined(__VISAGECPP__)
768 wxENTER_CRIT_SECT( m_eventsLocker
);
770 wxENTER_CRIT_SECT( *m_eventsLocker
);
773 node
= m_pendingEvents
->GetFirst();
776 #if defined(__VISAGECPP__)
777 wxLEAVE_CRIT_SECT( m_eventsLocker
);
779 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
789 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
793 // We have to use the actual window or processing events from
794 // wxWindowNative destructor won't work (we don't see the wxWindow class)
796 // check that our flag corresponds to reality
797 wxClassInfo
* info
= NULL
;
798 #ifdef __WXUNIVERSAL__
799 # if defined(__WXMSW__)
800 info
= CLASSINFO(wxWindowMSW
);
801 # elif defined(__WXGTK__)
802 info
= CLASSINFO(wxWindowGTK
);
803 # elif defined(__WXX11__)
804 info
= CLASSINFO(wxWindowX11
);
805 # elif defined(__WXMGL__)
806 info
= CLASSINFO(wxWindowMGL
);
807 # elif defined(__WXPM__)
808 info
= CLASSINFO(wxWindowOS2
);
809 # elif defined(__WXMAC__)
810 info
= CLASSINFO(wxWindowMac
);
811 # elif defined(__WXMOTIF__)
812 info
= CLASSINFO(wxWindowMotif
);
815 info
= CLASSINFO(wxWindow
);
818 if ( m_isWindow
!= IsKindOf(info
) )
820 wxString msg
= GetClassInfo()->GetClassName();
821 msg
+= _T(" should [not] be a window but it is [not]");
826 #endif // __WXDEBUG__
830 // allow the application to hook into event processing
833 int rc
= wxTheApp
->FilterEvent(event
);
836 wxASSERT_MSG( rc
== 1 || rc
== 0,
837 _T("unexpected wxApp::FilterEvent return value") );
841 //else: proceed normally
844 // An event handler can be enabled or disabled
845 if ( GetEvtHandlerEnabled() )
850 What is this? When using GUI threads, a non main
851 threads can send an event and process it itself.
852 This breaks GTK's GUI threads, so please explain.
855 // Check whether we are in a child thread.
856 if ( !wxThread::IsMain() )
857 return ProcessThreadEvent(event
);
860 // Handle per-instance dynamic event tables first
861 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
864 // Then static per-class event tables
865 const wxEventTable
*table
= GetEventTable();
867 #if wxUSE_GUI && wxUSE_VALIDATORS
868 // Try the associated validator first, if this is a window.
869 // Problem: if the event handler of the window has been replaced,
870 // this wxEvtHandler may no longer be a window.
871 // Therefore validators won't be processed if the handler
872 // has been replaced with SetEventHandler.
873 // THIS CAN BE CURED if PushEventHandler is used instead of
874 // SetEventHandler, and then processing will be passed down the
875 // chain of event handlers.
878 wxWindow
*win
= (wxWindow
*)this;
880 // Can only use the validator of the window which
881 // is receiving the event
882 if ( win
== event
.GetEventObject() )
884 wxValidator
*validator
= win
->GetValidator();
885 if ( validator
&& validator
->ProcessEvent(event
) )
893 // Search upwards through the inheritance hierarchy
896 if ( SearchEventTable((wxEventTable
&)*table
, event
) )
898 table
= table
->baseTable
;
902 // Try going down the event handler chain
903 if ( GetNextHandler() )
905 if ( GetNextHandler()->ProcessEvent(event
) )
910 // Carry on up the parent-child hierarchy, but only if event is a command
911 // event: it wouldn't make sense for a parent to receive a child's size
912 // event, for example
913 if ( m_isWindow
&& event
.IsCommandEvent() )
915 wxWindow
*win
= (wxWindow
*)this;
917 // honour the requests to stop propagation at this window: this is
918 // used by the dialogs, for example, to prevent processing the events
919 // from the dialog controls in the parent frame which rarely, if ever,
921 if ( !(win
->GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
923 wxWindow
*parent
= win
->GetParent();
924 if ( parent
&& !parent
->IsBeingDeleted() )
925 return parent
->GetEventHandler()->ProcessEvent(event
);
930 // Last try - application object.
931 if ( wxTheApp
&& (this != wxTheApp
) )
933 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
934 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
935 // processed appropriately via SearchEventTable.
936 if ( event
.GetEventType() != wxEVT_IDLE
)
938 if ( wxTheApp
->ProcessEvent(event
) )
946 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
948 wxEventType eventType
= event
.GetEventType();
949 int eventId
= event
.GetId();
951 // BC++ doesn't like testing for m_fn without != 0
952 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
954 // the line using reference exposes a bug in gcc: although it _seems_
955 // to work, it leads to weird crashes later on during program
958 wxEventTableEntry entry
= table
.entries
[i
];
960 const wxEventTableEntry
& entry
= table
.entries
[i
];
963 // match only if the event type is the same and the id is either -1 in
964 // the event table (meaning "any") or the event id matches the id
965 // specified in the event table either exactly or by falling into
966 // range between first and last
967 if ( eventType
== entry
.m_eventType
)
969 int tableId1
= entry
.m_id
,
970 tableId2
= entry
.m_lastId
;
972 if ( (tableId1
== -1) ||
973 (tableId2
== -1 && eventId
== tableId1
) ||
975 (eventId
>= tableId1
&& eventId
<= tableId2
)) )
978 event
.m_callbackUserData
= entry
.m_callbackUserData
;
980 (this->*((wxEventFunction
) (entry
.m_fn
)))(event
);
982 return !event
.GetSkipped();
990 void wxEvtHandler::Connect( int id
, int lastId
,
992 wxObjectEventFunction func
,
995 #if WXWIN_COMPATIBILITY_EVENT_TYPES
996 wxEventTableEntry
*entry
= new wxEventTableEntry
;
997 entry
->m_eventType
= eventType
;
999 entry
->m_lastId
= lastId
;
1001 entry
->m_callbackUserData
= userData
;
1002 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1003 wxDynamicEventTableEntry
*entry
=
1004 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
);
1005 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1007 if (!m_dynamicEvents
)
1008 m_dynamicEvents
= new wxList
;
1010 // Insert at the front of the list so most recent additions are found first
1011 m_dynamicEvents
->Insert( (wxObject
*) entry
);
1014 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1015 wxObjectEventFunction func
,
1016 wxObject
*userData
)
1018 if (!m_dynamicEvents
)
1021 wxNode
*node
= m_dynamicEvents
->GetFirst();
1024 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1025 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
1026 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1027 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1028 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1030 if ((entry
->m_id
== id
) &&
1031 ((entry
->m_lastId
== lastId
) || (lastId
== -1)) &&
1032 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1033 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1034 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1036 if (entry
->m_callbackUserData
)
1037 delete entry
->m_callbackUserData
;
1038 m_dynamicEvents
->DeleteNode( node
);
1042 node
= node
->GetNext();
1047 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1049 wxCHECK_MSG( m_dynamicEvents
, FALSE
,
1050 wxT("caller should check that we have dynamic events") );
1052 int commandId
= event
.GetId();
1054 wxNode
*node
= m_dynamicEvents
->GetFirst();
1057 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1058 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
1059 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1060 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1061 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1065 // Match, if event spec says any id will do (id == -1)
1066 if ( (event
.GetEventType() == entry
->m_eventType
) &&
1067 (entry
->m_id
== -1 ||
1068 (entry
->m_lastId
== -1 && commandId
== entry
->m_id
) ||
1069 (entry
->m_lastId
!= -1 &&
1070 (commandId
>= entry
->m_id
&& commandId
<= entry
->m_lastId
))) )
1073 event
.m_callbackUserData
= entry
->m_callbackUserData
;
1075 (this->*((wxEventFunction
) (entry
->m_fn
)))(event
);
1077 if ( ! event
.GetSkipped() )
1081 node
= node
->GetNext();
1086 void wxEvtHandler::DoSetClientObject( wxClientData
*data
)
1088 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1089 wxT("can't have both object and void client data") );
1091 if ( m_clientObject
)
1092 delete m_clientObject
;
1094 m_clientObject
= data
;
1095 m_clientDataType
= wxClientData_Object
;
1098 wxClientData
*wxEvtHandler::DoGetClientObject() const
1100 // it's not an error to call GetClientObject() on a window which doesn't
1101 // have client data at all - NULL will be returned
1102 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1103 wxT("this window doesn't have object client data") );
1105 return m_clientObject
;
1108 void wxEvtHandler::DoSetClientData( void *data
)
1110 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1111 wxT("can't have both object and void client data") );
1113 m_clientData
= data
;
1114 m_clientDataType
= wxClientData_Void
;
1117 void *wxEvtHandler::DoGetClientData() const
1119 // it's not an error to call GetClientData() on a window which doesn't have
1120 // client data at all - NULL will be returned
1121 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1122 wxT("this window doesn't have void client data") );
1124 return m_clientData
;
1128 #if WXWIN_COMPATIBILITY
1129 bool wxEvtHandler::OnClose()
1131 if (GetNextHandler())
1132 return GetNextHandler()->OnClose();
1136 #endif // WXWIN_COMPATIBILITY
1140 // Find a window with the focus, that is also a descendant of the given window.
1141 // This is used to determine the window to initially send commands to.
1142 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1144 // Process events starting with the window with the focus, if any.
1145 wxWindow
* focusWin
= wxWindow::FindFocus();
1146 wxWindow
* win
= focusWin
;
1148 // Check if this is a descendant of this frame.
1149 // If not, win will be set to NULL.
1152 if (win
== ancestor
)
1155 win
= win
->GetParent();
1157 if (win
== (wxWindow
*) NULL
)
1158 focusWin
= (wxWindow
*) NULL
;