1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Event classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
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 // ----------------------------------------------------------------------------
53 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler
, wxObject
)
54 IMPLEMENT_ABSTRACT_CLASS(wxEvent
, wxObject
)
57 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent
, wxEvent
)
58 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent
, wxEvent
)
59 IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent
, wxCommandEvent
)
60 IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent
, wxCommandEvent
)
61 IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent
, wxEvent
)
62 IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent
, wxEvent
)
63 IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent
, wxEvent
)
64 IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent
, wxEvent
)
65 IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent
, wxEvent
)
66 IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent
, wxEvent
)
67 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent
, wxEvent
)
68 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent
, wxEvent
)
69 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent
, wxEvent
)
70 IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent
, wxCommandEvent
)
71 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent
, wxEvent
)
72 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent
, wxEvent
)
73 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent
, wxEvent
)
74 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent
, wxEvent
)
75 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent
, wxEvent
)
76 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent
, wxEvent
)
77 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent
, wxEvent
)
78 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent
, wxEvent
)
79 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent
, wxEvent
)
80 IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent
, wxEvent
)
81 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent
, wxEvent
)
82 IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent
, wxEvent
)
83 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent
, wxCommandEvent
)
84 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent
, wxCommandEvent
)
85 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent
, wxEvent
)
86 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent
, wxEvent
)
87 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent
, wxEvent
)
88 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent
, wxEvent
)
89 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent
, wxCommandEvent
)
90 IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent
, wxCommandEvent
)
91 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent
, wxEvent
)
94 const wxEventTable
*wxEvtHandler::GetEventTable() const
95 { return &wxEvtHandler::sm_eventTable
; }
97 const wxEventTable
wxEvtHandler::sm_eventTable
=
98 { (const wxEventTable
*)NULL
, &wxEvtHandler::sm_eventTableEntries
[0] };
100 const wxEventTableEntry
wxEvtHandler::sm_eventTableEntries
[] =
101 { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL
, 0, 0, (wxObjectEventFunction
)NULL
, NULL
) };
103 // ----------------------------------------------------------------------------
105 // ----------------------------------------------------------------------------
107 // To put pending event handlers
108 wxList
*wxPendingEvents
= (wxList
*)NULL
;
111 // protects wxPendingEvents list
112 wxCriticalSection
*wxPendingEventsLocker
= (wxCriticalSection
*)NULL
;
115 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
117 // common event types are defined here, other event types are defined by the
118 // components which use them
120 DEFINE_EVENT_TYPE(wxEVT_NULL
)
121 DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED
)
122 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED
)
123 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED
)
124 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED
)
125 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
)
126 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
)
127 DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED
)
128 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED
)
129 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED
)
130 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED
)
131 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED
)
132 DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED
)
133 DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED
)
134 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED
)
135 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER
)
136 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED
)
138 // Sockets and timers send events, too
139 DEFINE_EVENT_TYPE(wxEVT_SOCKET
)
140 DEFINE_EVENT_TYPE(wxEVT_TIMER
)
143 DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN
)
144 DEFINE_EVENT_TYPE(wxEVT_LEFT_UP
)
145 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN
)
146 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP
)
147 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN
)
148 DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP
)
149 DEFINE_EVENT_TYPE(wxEVT_MOTION
)
150 DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW
)
151 DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW
)
152 DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK
)
153 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK
)
154 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK
)
155 DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS
)
156 DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS
)
157 DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS
)
158 DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL
)
160 // Non-client mouse events
161 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN
)
162 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP
)
163 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN
)
164 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP
)
165 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN
)
166 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP
)
167 DEFINE_EVENT_TYPE(wxEVT_NC_MOTION
)
168 DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW
)
169 DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW
)
170 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK
)
171 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK
)
172 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK
)
174 // Character input event type
175 DEFINE_EVENT_TYPE(wxEVT_CHAR
)
176 DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK
)
177 DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY
)
178 DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN
)
179 DEFINE_EVENT_TYPE(wxEVT_KEY_UP
)
182 DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR
)
184 // wxScrollbar and wxSlider event identifiers
185 DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP
)
186 DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM
)
187 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP
)
188 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN
)
189 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP
)
190 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN
)
191 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK
)
192 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE
)
193 DEFINE_EVENT_TYPE(wxEVT_SCROLL_ENDSCROLL
)
195 // Scroll events from wxWindow
196 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP
)
197 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM
)
198 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP
)
199 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN
)
200 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP
)
201 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN
)
202 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK
)
203 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE
)
206 DEFINE_EVENT_TYPE(wxEVT_SIZE
)
207 DEFINE_EVENT_TYPE(wxEVT_MOVE
)
208 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW
)
209 DEFINE_EVENT_TYPE(wxEVT_END_SESSION
)
210 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION
)
211 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
212 DEFINE_EVENT_TYPE(wxEVT_POWER
)
213 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
214 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
215 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
216 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
217 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
218 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
219 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
220 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
221 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
222 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
223 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
224 DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN
)
225 DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE
)
226 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
227 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
228 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
229 DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED
)
230 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
231 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
232 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
233 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
234 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
235 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
236 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
237 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
238 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
239 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
240 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
241 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
242 DEFINE_EVENT_TYPE(wxEVT_IDLE
)
243 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
245 // Generic command events
246 // Note: a click is a higher-level event than button down/up
247 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
248 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
249 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
250 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
251 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
252 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
253 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
256 DEFINE_EVENT_TYPE(wxEVT_HELP
)
257 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
259 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
261 // ============================================================================
263 // ============================================================================
265 // ----------------------------------------------------------------------------
266 // event initialization
267 // ----------------------------------------------------------------------------
272 static int s_lastUsedEventType
= wxEVT_FIRST
;
274 #if WXWIN_COMPATIBILITY_2
275 // check that we don't overlap with the user-defined types: if it does
276 // happen, the best solution is probably to update the existing code to
277 // use wxNewEventType() instead of wxEVT_USER_FIRST
279 // due to the uncertainty
280 wxASSERT_MSG( s_lastUsedEventType
< wxEVT_USER_FIRST
- 1,
281 _T("possible event type conflict") );
282 #endif // WXWIN_COMPATIBILITY_2
284 return s_lastUsedEventType
++;
287 // ----------------------------------------------------------------------------
289 // ----------------------------------------------------------------------------
292 * General wxWindows events, covering
293 * all interesting things that might happen (button clicking, resizing,
294 * setting text in widgets, etc.).
296 * For each completely new event type, derive a new event class.
300 wxEvent::wxEvent(int theId
, wxEventType commandType
)
302 m_eventType
= commandType
;
303 m_eventObject
= (wxObject
*) NULL
;
307 m_callbackUserData
= (wxObject
*) NULL
;
308 m_isCommandEvent
= FALSE
;
311 wxEvent::wxEvent(const wxEvent
&src
)
313 , m_eventObject(src
.m_eventObject
)
314 , m_eventType(src
.m_eventType
)
315 , m_timeStamp(src
.m_timeStamp
)
317 , m_callbackUserData(src
.m_callbackUserData
)
318 , m_skipped(src
.m_skipped
)
319 , m_isCommandEvent(src
.m_isCommandEvent
)
330 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
331 : wxEvent(theId
, commandType
)
333 m_clientData
= (char *) NULL
;
334 m_clientObject
= (wxClientData
*) NULL
;
337 m_commandString
= wxEmptyString
;
338 m_isCommandEvent
= TRUE
;
345 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
349 : wxCommandEvent(commandType
, id
)
351 m_extraLong
= orient
;
359 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
363 m_eventType
= commandType
;
364 m_extraLong
= orient
;
373 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
375 m_eventType
= commandType
;
378 m_controlDown
= FALSE
;
382 m_middleDown
= FALSE
;
387 m_linesPerAction
= 0;
390 void wxMouseEvent::Assign(const wxMouseEvent
& event
)
392 m_eventType
= event
.m_eventType
;
397 m_leftDown
= event
.m_leftDown
;
398 m_middleDown
= event
.m_middleDown
;
399 m_rightDown
= event
.m_rightDown
;
401 m_controlDown
= event
.m_controlDown
;
402 m_shiftDown
= event
.m_shiftDown
;
403 m_altDown
= event
.m_altDown
;
404 m_metaDown
= event
.m_metaDown
;
406 m_wheelRotation
= event
.m_wheelRotation
;
407 m_wheelDelta
= event
.m_wheelDelta
;
408 m_linesPerAction
= event
.m_linesPerAction
;
411 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
412 // or any button dclick event (but = -1)
413 bool wxMouseEvent::ButtonDClick(int but
) const
418 return (LeftDClick() || MiddleDClick() || RightDClick());
422 return MiddleDClick();
424 return RightDClick();
426 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
432 // True if was a button down event (1 = left, 2 = middle, 3 = right)
433 // or any button down event (but = -1)
434 bool wxMouseEvent::ButtonDown(int but
) const
439 return (LeftDown() || MiddleDown() || RightDown());
447 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
453 // True if was a button up event (1 = left, 2 = middle, 3 = right)
454 // or any button up event (but = -1)
455 bool wxMouseEvent::ButtonUp(int but
) const
460 return (LeftUp() || MiddleUp() || RightUp());
468 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
474 // True if the given button is currently changing state
475 bool wxMouseEvent::Button(int but
) const
480 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
482 return (LeftDown() || LeftUp() || LeftDClick());
484 return (MiddleDown() || MiddleUp() || MiddleDClick());
486 return (RightDown() || RightUp() || RightDClick());
488 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
494 bool wxMouseEvent::ButtonIsDown(int but
) const
499 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
503 return MiddleIsDown();
505 return RightIsDown();
507 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
513 int wxMouseEvent::GetButton() const
515 for ( int i
= 1; i
<= 3; i
++ )
526 // Find the logical position of the event given the DC
527 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
529 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
539 wxKeyEvent::wxKeyEvent(wxEventType type
)
543 m_controlDown
= FALSE
;
551 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
553 SetEventType(wxEVT_CREATE
);
557 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
559 SetEventType(wxEVT_DESTROY
);
563 wxChildFocusEvent::wxChildFocusEvent(wxWindow
*win
)
564 : wxCommandEvent(wxEVT_CHILD_FOCUS
)
571 // ----------------------------------------------------------------------------
573 // ----------------------------------------------------------------------------
579 wxEvtHandler::wxEvtHandler()
581 m_nextHandler
= (wxEvtHandler
*) NULL
;
582 m_previousHandler
= (wxEvtHandler
*) NULL
;
584 m_dynamicEvents
= (wxList
*) NULL
;
586 m_pendingEvents
= (wxList
*) NULL
;
588 # if !defined(__VISAGECPP__)
589 m_eventsLocker
= new wxCriticalSection
;
592 // no client data (yet)
594 m_clientDataType
= wxClientData_None
;
597 wxEvtHandler::~wxEvtHandler()
599 // Takes itself out of the list of handlers
600 if (m_previousHandler
)
601 m_previousHandler
->m_nextHandler
= m_nextHandler
;
604 m_nextHandler
->m_previousHandler
= m_previousHandler
;
608 wxNode
*node
= m_dynamicEvents
->First();
611 #if WXWIN_COMPATIBILITY_EVENT_TYPES
612 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
613 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
614 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
615 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
617 if (entry
->m_callbackUserData
)
618 delete entry
->m_callbackUserData
;
622 delete m_dynamicEvents
;
625 delete m_pendingEvents
;
628 # if !defined(__VISAGECPP__)
629 delete m_eventsLocker
;
633 // we only delete object data, not untyped
634 if ( m_clientDataType
== wxClientData_Object
)
635 delete m_clientObject
;
640 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
642 // check that we are really in a child thread
643 wxASSERT_MSG( !wxThread::IsMain(),
644 wxT("use ProcessEvent() in main thread") );
646 AddPendingEvent(event
);
651 #endif // wxUSE_THREADS
653 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
655 // 1) Add event to list of pending events of this event handler
657 wxEvent
*eventCopy
= event
.Clone();
659 // we must be able to copy the events here so the event class must
660 // implement Clone() properly instead of just providing a NULL stab for it
661 wxCHECK_RET( eventCopy
,
662 _T("events of this type aren't supposed to be posted") );
664 #if defined(__VISAGECPP__)
665 wxENTER_CRIT_SECT( m_eventsLocker
);
667 wxENTER_CRIT_SECT( *m_eventsLocker
);
670 if ( !m_pendingEvents
)
671 m_pendingEvents
= new wxList
;
673 m_pendingEvents
->Append(eventCopy
);
675 #if defined(__VISAGECPP__)
676 wxLEAVE_CRIT_SECT( m_eventsLocker
);
678 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
681 // 2) Add this event handler to list of event handlers that
682 // have pending events.
684 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
686 if ( !wxPendingEvents
)
687 wxPendingEvents
= new wxList
;
688 wxPendingEvents
->Append(this);
690 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
692 // 3) Inform the system that new pending events are somwehere,
693 // and that these should be processed in idle time.
697 void wxEvtHandler::ProcessPendingEvents()
699 #if defined(__VISAGECPP__)
700 wxENTER_CRIT_SECT( m_eventsLocker
);
702 wxENTER_CRIT_SECT( *m_eventsLocker
);
705 wxNode
*node
= m_pendingEvents
->First();
708 wxEvent
*event
= (wxEvent
*)node
->Data();
711 // In ProcessEvent, new events might get added and
712 // we can safely leave the crtical section here.
713 #if defined(__VISAGECPP__)
714 wxLEAVE_CRIT_SECT( m_eventsLocker
);
716 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
718 ProcessEvent(*event
);
720 #if defined(__VISAGECPP__)
721 wxENTER_CRIT_SECT( m_eventsLocker
);
723 wxENTER_CRIT_SECT( *m_eventsLocker
);
726 node
= m_pendingEvents
->First();
729 #if defined(__VISAGECPP__)
730 wxLEAVE_CRIT_SECT( m_eventsLocker
);
732 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
740 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
744 // We have to use the actual window or processing events from
745 // wxWindowNative destructor won't work (we don't see the wxWindow class)
747 // check that our flag corresponds to reality
748 wxClassInfo
* info
= NULL
;
749 #ifdef __WXUNIVERSAL__
750 # if defined(__WXMSW__)
751 info
= CLASSINFO(wxWindowMSW
);
752 # elif defined(__WXGTK__)
753 info
= CLASSINFO(wxWindowGTK
);
754 # elif defined(__WXX11__)
755 info
= CLASSINFO(wxWindowX11
);
756 # elif defined(__WXMGL__)
757 info
= CLASSINFO(wxWindowMGL
);
758 # elif defined(__WXPM__)
759 info
= CLASSINFO(wxWindowOS2
);
760 # elif defined(__WXMAC__)
761 info
= CLASSINFO(wxWindowMac
);
762 # elif defined(__WXMOTIF__)
763 info
= CLASSINFO(wxWindowMotif
);
766 info
= CLASSINFO(wxWindow
);
769 if ( m_isWindow
!= IsKindOf(info
) )
771 wxString msg
= GetClassInfo()->GetClassName();
772 msg
+= _T(" should [not] be a window but it is [not]");
777 #endif // __WXDEBUG__
781 // allow the application to hook into event processing
784 int rc
= wxTheApp
->FilterEvent(event
);
787 wxASSERT_MSG( rc
== 1 || rc
== 0,
788 _T("unexpected wxApp::FilterEvent return value") );
792 //else: proceed normally
795 // An event handler can be enabled or disabled
796 if ( GetEvtHandlerEnabled() )
801 What is this? When using GUI threads, a non main
802 threads can send an event and process it itself.
803 This breaks GTK's GUI threads, so please explain.
806 // Check whether we are in a child thread.
807 if ( !wxThread::IsMain() )
808 return ProcessThreadEvent(event
);
811 // Handle per-instance dynamic event tables first
812 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
815 // Then static per-class event tables
816 const wxEventTable
*table
= GetEventTable();
818 #if wxUSE_GUI && wxUSE_VALIDATORS
819 // Try the associated validator first, if this is a window.
820 // Problem: if the event handler of the window has been replaced,
821 // this wxEvtHandler may no longer be a window.
822 // Therefore validators won't be processed if the handler
823 // has been replaced with SetEventHandler.
824 // THIS CAN BE CURED if PushEventHandler is used instead of
825 // SetEventHandler, and then processing will be passed down the
826 // chain of event handlers.
829 wxWindow
*win
= (wxWindow
*)this;
831 // Can only use the validator of the window which
832 // is receiving the event
833 if ( win
== event
.GetEventObject() )
835 wxValidator
*validator
= win
->GetValidator();
836 if ( validator
&& validator
->ProcessEvent(event
) )
844 // Search upwards through the inheritance hierarchy
847 if ( SearchEventTable((wxEventTable
&)*table
, event
) )
849 table
= table
->baseTable
;
853 // Try going down the event handler chain
854 if ( GetNextHandler() )
856 if ( GetNextHandler()->ProcessEvent(event
) )
861 // Carry on up the parent-child hierarchy, but only if event is a command
862 // event: it wouldn't make sense for a parent to receive a child's size
863 // event, for example
864 if ( m_isWindow
&& event
.IsCommandEvent() )
866 wxWindow
*win
= (wxWindow
*)this;
868 // honour the requests to stop propagation at this window: this is
869 // used by the dialogs, for example, to prevent processing the events
870 // from the dialog controls in the parent frame which rarely, if ever,
872 if ( !(win
->GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
874 wxWindow
*parent
= win
->GetParent();
875 if ( parent
&& !parent
->IsBeingDeleted() )
876 return parent
->GetEventHandler()->ProcessEvent(event
);
881 // Last try - application object.
882 if ( wxTheApp
&& (this != wxTheApp
) )
884 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
885 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
886 // processed appropriately via SearchEventTable.
887 if ( event
.GetEventType() != wxEVT_IDLE
)
889 if ( wxTheApp
->ProcessEvent(event
) )
897 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
899 wxEventType eventType
= event
.GetEventType();
900 int eventId
= event
.GetId();
902 // BC++ doesn't like testing for m_fn without != 0
903 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
905 // the line using reference exposes a bug in gcc: although it _seems_
906 // to work, it leads to weird crashes later on during program
909 wxEventTableEntry entry
= table
.entries
[i
];
911 const wxEventTableEntry
& entry
= table
.entries
[i
];
914 // match only if the event type is the same and the id is either -1 in
915 // the event table (meaning "any") or the event id matches the id
916 // specified in the event table either exactly or by falling into
917 // range between first and last
918 if ( eventType
== entry
.m_eventType
)
920 int tableId1
= entry
.m_id
,
921 tableId2
= entry
.m_lastId
;
923 if ( (tableId1
== -1) ||
924 (tableId2
== -1 && eventId
== tableId1
) ||
926 (eventId
>= tableId1
&& eventId
<= tableId2
)) )
929 event
.m_callbackUserData
= entry
.m_callbackUserData
;
931 (this->*((wxEventFunction
) (entry
.m_fn
)))(event
);
933 return !event
.GetSkipped();
941 void wxEvtHandler::Connect( int id
, int lastId
,
943 wxObjectEventFunction func
,
946 #if WXWIN_COMPATIBILITY_EVENT_TYPES
947 wxEventTableEntry
*entry
= new wxEventTableEntry
;
948 entry
->m_eventType
= eventType
;
950 entry
->m_lastId
= lastId
;
952 entry
->m_callbackUserData
= userData
;
953 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
954 wxDynamicEventTableEntry
*entry
=
955 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
);
956 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
958 if (!m_dynamicEvents
)
959 m_dynamicEvents
= new wxList
;
961 m_dynamicEvents
->Append( (wxObject
*) entry
);
964 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
965 wxObjectEventFunction func
,
968 if (!m_dynamicEvents
)
971 wxNode
*node
= m_dynamicEvents
->First();
974 #if WXWIN_COMPATIBILITY_EVENT_TYPES
975 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
976 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
977 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
978 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
980 if ((entry
->m_id
== id
) &&
981 ((entry
->m_lastId
== lastId
) || (lastId
== -1)) &&
982 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
983 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
984 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
986 if (entry
->m_callbackUserData
)
987 delete entry
->m_callbackUserData
;
988 m_dynamicEvents
->DeleteNode( node
);
997 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
999 wxCHECK_MSG( m_dynamicEvents
, FALSE
,
1000 wxT("caller should check that we have dynamic events") );
1002 int commandId
= event
.GetId();
1004 wxNode
*node
= m_dynamicEvents
->First();
1007 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1008 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
1009 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1010 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
1011 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1015 // Match, if event spec says any id will do (id == -1)
1016 if ( (event
.GetEventType() == entry
->m_eventType
) &&
1017 (entry
->m_id
== -1 ||
1018 (entry
->m_lastId
== -1 && commandId
== entry
->m_id
) ||
1019 (entry
->m_lastId
!= -1 &&
1020 (commandId
>= entry
->m_id
&& commandId
<= entry
->m_lastId
))) )
1023 event
.m_callbackUserData
= entry
->m_callbackUserData
;
1025 (this->*((wxEventFunction
) (entry
->m_fn
)))(event
);
1027 if (event
.GetSkipped())
1033 node
= node
->Next();
1038 void wxEvtHandler::DoSetClientObject( wxClientData
*data
)
1040 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1041 wxT("can't have both object and void client data") );
1043 if ( m_clientObject
)
1044 delete m_clientObject
;
1046 m_clientObject
= data
;
1047 m_clientDataType
= wxClientData_Object
;
1050 wxClientData
*wxEvtHandler::DoGetClientObject() const
1052 // it's not an error to call GetClientObject() on a window which doesn't
1053 // have client data at all - NULL will be returned
1054 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1055 wxT("this window doesn't have object client data") );
1057 return m_clientObject
;
1060 void wxEvtHandler::DoSetClientData( void *data
)
1062 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1063 wxT("can't have both object and void client data") );
1065 m_clientData
= data
;
1066 m_clientDataType
= wxClientData_Void
;
1069 void *wxEvtHandler::DoGetClientData() const
1071 // it's not an error to call GetClientData() on a window which doesn't have
1072 // client data at all - NULL will be returned
1073 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1074 wxT("this window doesn't have void client data") );
1076 return m_clientData
;
1080 #if WXWIN_COMPATIBILITY
1081 bool wxEvtHandler::OnClose()
1083 if (GetNextHandler())
1084 return GetNextHandler()->OnClose();
1088 #endif // WXWIN_COMPATIBILITY
1092 // Find a window with the focus, that is also a descendant of the given window.
1093 // This is used to determine the window to initially send commands to.
1094 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1096 // Process events starting with the window with the focus, if any.
1097 wxWindow
* focusWin
= wxWindow::FindFocus();
1098 wxWindow
* win
= focusWin
;
1100 // Check if this is a descendant of this frame.
1101 // If not, win will be set to NULL.
1104 if (win
== ancestor
)
1107 win
= win
->GetParent();
1109 if (win
== (wxWindow
*) NULL
)
1110 focusWin
= (wxWindow
*) NULL
;