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 // ----------------------------------------------------------------------------
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_SIZING
)
208 DEFINE_EVENT_TYPE(wxEVT_MOVE
)
209 DEFINE_EVENT_TYPE(wxEVT_MOVING
)
210 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW
)
211 DEFINE_EVENT_TYPE(wxEVT_END_SESSION
)
212 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION
)
213 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
214 DEFINE_EVENT_TYPE(wxEVT_POWER
)
215 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
216 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
217 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
218 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
219 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
220 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
221 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
222 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
223 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
224 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
225 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
226 DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN
)
227 DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE
)
228 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
229 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
230 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
231 DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED
)
232 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
233 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
234 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
235 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
236 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
237 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
238 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
239 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
240 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
241 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
242 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
243 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
244 DEFINE_EVENT_TYPE(wxEVT_IDLE
)
245 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
247 // Generic command events
248 // Note: a click is a higher-level event than button down/up
249 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
250 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
251 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
252 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
253 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
254 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
255 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
258 DEFINE_EVENT_TYPE(wxEVT_HELP
)
259 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
261 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
263 // ============================================================================
265 // ============================================================================
267 // ----------------------------------------------------------------------------
268 // event initialization
269 // ----------------------------------------------------------------------------
274 static int s_lastUsedEventType
= wxEVT_FIRST
;
276 #if WXWIN_COMPATIBILITY_2
277 // check that we don't overlap with the user-defined types: if it does
278 // happen, the best solution is probably to update the existing code to
279 // use wxNewEventType() instead of wxEVT_USER_FIRST
281 // due to the uncertainty
282 wxASSERT_MSG( s_lastUsedEventType
< wxEVT_USER_FIRST
- 1,
283 _T("possible event type conflict") );
284 #endif // WXWIN_COMPATIBILITY_2
286 return s_lastUsedEventType
++;
289 // ----------------------------------------------------------------------------
291 // ----------------------------------------------------------------------------
294 * General wxWindows events, covering
295 * all interesting things that might happen (button clicking, resizing,
296 * setting text in widgets, etc.).
298 * For each completely new event type, derive a new event class.
302 wxEvent::wxEvent(int theId
, wxEventType commandType
)
304 m_eventType
= commandType
;
305 m_eventObject
= (wxObject
*) NULL
;
309 m_callbackUserData
= (wxObject
*) NULL
;
310 m_isCommandEvent
= FALSE
;
313 wxEvent::wxEvent(const wxEvent
&src
)
315 , m_eventObject(src
.m_eventObject
)
316 , m_eventType(src
.m_eventType
)
317 , m_timeStamp(src
.m_timeStamp
)
319 , m_callbackUserData(src
.m_callbackUserData
)
320 , m_skipped(src
.m_skipped
)
321 , m_isCommandEvent(src
.m_isCommandEvent
)
332 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
333 : wxEvent(theId
, commandType
)
335 m_clientData
= (char *) NULL
;
336 m_clientObject
= (wxClientData
*) NULL
;
339 m_commandString
= wxEmptyString
;
340 m_isCommandEvent
= TRUE
;
347 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
351 : wxCommandEvent(commandType
, id
)
353 m_extraLong
= orient
;
361 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
365 m_eventType
= commandType
;
366 m_extraLong
= orient
;
375 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
377 m_eventType
= commandType
;
380 m_controlDown
= FALSE
;
384 m_middleDown
= FALSE
;
389 m_linesPerAction
= 0;
392 void wxMouseEvent::Assign(const wxMouseEvent
& event
)
394 m_eventType
= event
.m_eventType
;
399 m_leftDown
= event
.m_leftDown
;
400 m_middleDown
= event
.m_middleDown
;
401 m_rightDown
= event
.m_rightDown
;
403 m_controlDown
= event
.m_controlDown
;
404 m_shiftDown
= event
.m_shiftDown
;
405 m_altDown
= event
.m_altDown
;
406 m_metaDown
= event
.m_metaDown
;
408 m_wheelRotation
= event
.m_wheelRotation
;
409 m_wheelDelta
= event
.m_wheelDelta
;
410 m_linesPerAction
= event
.m_linesPerAction
;
413 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
414 // or any button dclick event (but = -1)
415 bool wxMouseEvent::ButtonDClick(int but
) const
420 return (LeftDClick() || MiddleDClick() || RightDClick());
424 return MiddleDClick();
426 return RightDClick();
428 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
434 // True if was a button down event (1 = left, 2 = middle, 3 = right)
435 // or any button down event (but = -1)
436 bool wxMouseEvent::ButtonDown(int but
) const
441 return (LeftDown() || MiddleDown() || RightDown());
449 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
455 // True if was a button up event (1 = left, 2 = middle, 3 = right)
456 // or any button up event (but = -1)
457 bool wxMouseEvent::ButtonUp(int but
) const
462 return (LeftUp() || MiddleUp() || RightUp());
470 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
476 // True if the given button is currently changing state
477 bool wxMouseEvent::Button(int but
) const
482 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
484 return (LeftDown() || LeftUp() || LeftDClick());
486 return (MiddleDown() || MiddleUp() || MiddleDClick());
488 return (RightDown() || RightUp() || RightDClick());
490 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
496 bool wxMouseEvent::ButtonIsDown(int but
) const
501 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
505 return MiddleIsDown();
507 return RightIsDown();
509 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
515 int wxMouseEvent::GetButton() const
517 for ( int i
= 1; i
<= 3; i
++ )
528 // Find the logical position of the event given the DC
529 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
531 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
541 wxKeyEvent::wxKeyEvent(wxEventType type
)
545 m_controlDown
= FALSE
;
555 wxKeyEvent::wxKeyEvent(const wxKeyEvent
& evt
)
561 m_keyCode
= evt
.m_keyCode
;
563 m_controlDown
= evt
.m_controlDown
;
564 m_shiftDown
= evt
.m_shiftDown
;
565 m_altDown
= evt
.m_altDown
;
566 m_metaDown
= evt
.m_metaDown
;
567 m_scanCode
= evt
.m_scanCode
;
568 m_rawCode
= evt
.m_rawCode
;
569 m_rawFlags
= evt
.m_rawFlags
;
572 m_uniChar
= evt
.m_uniChar
;
576 long wxKeyEvent::KeyCode() const
581 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
583 SetEventType(wxEVT_CREATE
);
587 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
589 SetEventType(wxEVT_DESTROY
);
593 wxChildFocusEvent::wxChildFocusEvent(wxWindow
*win
)
594 : wxCommandEvent(wxEVT_CHILD_FOCUS
)
601 // ----------------------------------------------------------------------------
603 // ----------------------------------------------------------------------------
609 wxEvtHandler::wxEvtHandler()
611 m_nextHandler
= (wxEvtHandler
*) NULL
;
612 m_previousHandler
= (wxEvtHandler
*) NULL
;
614 m_dynamicEvents
= (wxList
*) NULL
;
616 m_pendingEvents
= (wxList
*) NULL
;
618 # if !defined(__VISAGECPP__)
619 m_eventsLocker
= new wxCriticalSection
;
622 // no client data (yet)
624 m_clientDataType
= wxClientData_None
;
627 wxEvtHandler::~wxEvtHandler()
629 // Takes itself out of the list of handlers
630 if (m_previousHandler
)
631 m_previousHandler
->m_nextHandler
= m_nextHandler
;
634 m_nextHandler
->m_previousHandler
= m_previousHandler
;
638 wxNode
*node
= m_dynamicEvents
->GetFirst();
641 #if WXWIN_COMPATIBILITY_EVENT_TYPES
642 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
643 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
644 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
645 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
647 if (entry
->m_callbackUserData
)
648 delete entry
->m_callbackUserData
;
650 node
= node
->GetNext();
652 delete m_dynamicEvents
;
655 delete m_pendingEvents
;
658 # if !defined(__VISAGECPP__)
659 delete m_eventsLocker
;
662 // Remove us from wxPendingEvents if necessary.
663 if(wxPendingEventsLocker
)
664 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
665 if ( wxPendingEvents
) {
666 wxPendingEvents
->DeleteObject(this);
668 if(wxPendingEventsLocker
)
669 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
672 // we only delete object data, not untyped
673 if ( m_clientDataType
== wxClientData_Object
)
674 delete m_clientObject
;
679 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
681 // check that we are really in a child thread
682 wxASSERT_MSG( !wxThread::IsMain(),
683 wxT("use ProcessEvent() in main thread") );
685 AddPendingEvent(event
);
690 #endif // wxUSE_THREADS
692 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
694 // 1) Add event to list of pending events of this event handler
696 wxEvent
*eventCopy
= event
.Clone();
698 // we must be able to copy the events here so the event class must
699 // implement Clone() properly instead of just providing a NULL stab for it
700 wxCHECK_RET( eventCopy
,
701 _T("events of this type aren't supposed to be posted") );
703 #if defined(__VISAGECPP__)
704 wxENTER_CRIT_SECT( m_eventsLocker
);
706 wxENTER_CRIT_SECT( *m_eventsLocker
);
709 if ( !m_pendingEvents
)
710 m_pendingEvents
= new wxList
;
712 m_pendingEvents
->Append(eventCopy
);
714 #if defined(__VISAGECPP__)
715 wxLEAVE_CRIT_SECT( m_eventsLocker
);
717 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
720 // 2) Add this event handler to list of event handlers that
721 // have pending events.
723 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
725 if ( !wxPendingEvents
)
726 wxPendingEvents
= new wxList
;
727 wxPendingEvents
->Append(this);
729 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
731 // 3) Inform the system that new pending events are somwehere,
732 // and that these should be processed in idle time.
736 void wxEvtHandler::ProcessPendingEvents()
738 #if defined(__VISAGECPP__)
739 wxENTER_CRIT_SECT( m_eventsLocker
);
741 wxENTER_CRIT_SECT( *m_eventsLocker
);
744 wxNode
*node
= m_pendingEvents
->GetFirst();
747 wxEvent
*event
= (wxEvent
*)node
->GetData();
750 // In ProcessEvent, new events might get added and
751 // we can safely leave the crtical section here.
752 #if defined(__VISAGECPP__)
753 wxLEAVE_CRIT_SECT( m_eventsLocker
);
755 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
757 ProcessEvent(*event
);
759 #if defined(__VISAGECPP__)
760 wxENTER_CRIT_SECT( m_eventsLocker
);
762 wxENTER_CRIT_SECT( *m_eventsLocker
);
765 node
= m_pendingEvents
->GetFirst();
768 #if defined(__VISAGECPP__)
769 wxLEAVE_CRIT_SECT( m_eventsLocker
);
771 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
779 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
783 // We have to use the actual window or processing events from
784 // wxWindowNative destructor won't work (we don't see the wxWindow class)
786 // check that our flag corresponds to reality
787 wxClassInfo
* info
= NULL
;
788 #ifdef __WXUNIVERSAL__
789 # if defined(__WXMSW__)
790 info
= CLASSINFO(wxWindowMSW
);
791 # elif defined(__WXGTK__)
792 info
= CLASSINFO(wxWindowGTK
);
793 # elif defined(__WXX11__)
794 info
= CLASSINFO(wxWindowX11
);
795 # elif defined(__WXMGL__)
796 info
= CLASSINFO(wxWindowMGL
);
797 # elif defined(__WXPM__)
798 info
= CLASSINFO(wxWindowOS2
);
799 # elif defined(__WXMAC__)
800 info
= CLASSINFO(wxWindowMac
);
801 # elif defined(__WXMOTIF__)
802 info
= CLASSINFO(wxWindowMotif
);
805 info
= CLASSINFO(wxWindow
);
808 if ( m_isWindow
!= IsKindOf(info
) )
810 wxString msg
= GetClassInfo()->GetClassName();
811 msg
+= _T(" should [not] be a window but it is [not]");
816 #endif // __WXDEBUG__
820 // allow the application to hook into event processing
823 int rc
= wxTheApp
->FilterEvent(event
);
826 wxASSERT_MSG( rc
== 1 || rc
== 0,
827 _T("unexpected wxApp::FilterEvent return value") );
831 //else: proceed normally
834 // An event handler can be enabled or disabled
835 if ( GetEvtHandlerEnabled() )
840 What is this? When using GUI threads, a non main
841 threads can send an event and process it itself.
842 This breaks GTK's GUI threads, so please explain.
845 // Check whether we are in a child thread.
846 if ( !wxThread::IsMain() )
847 return ProcessThreadEvent(event
);
850 // Handle per-instance dynamic event tables first
851 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
854 // Then static per-class event tables
855 const wxEventTable
*table
= GetEventTable();
857 #if wxUSE_GUI && wxUSE_VALIDATORS
858 // Try the associated validator first, if this is a window.
859 // Problem: if the event handler of the window has been replaced,
860 // this wxEvtHandler may no longer be a window.
861 // Therefore validators won't be processed if the handler
862 // has been replaced with SetEventHandler.
863 // THIS CAN BE CURED if PushEventHandler is used instead of
864 // SetEventHandler, and then processing will be passed down the
865 // chain of event handlers.
868 wxWindow
*win
= (wxWindow
*)this;
870 // Can only use the validator of the window which
871 // is receiving the event
872 if ( win
== event
.GetEventObject() )
874 wxValidator
*validator
= win
->GetValidator();
875 if ( validator
&& validator
->ProcessEvent(event
) )
883 // Search upwards through the inheritance hierarchy
886 if ( SearchEventTable((wxEventTable
&)*table
, event
) )
888 table
= table
->baseTable
;
892 // Try going down the event handler chain
893 if ( GetNextHandler() )
895 if ( GetNextHandler()->ProcessEvent(event
) )
900 // Carry on up the parent-child hierarchy, but only if event is a command
901 // event: it wouldn't make sense for a parent to receive a child's size
902 // event, for example
903 if ( m_isWindow
&& event
.IsCommandEvent() )
905 wxWindow
*win
= (wxWindow
*)this;
907 // honour the requests to stop propagation at this window: this is
908 // used by the dialogs, for example, to prevent processing the events
909 // from the dialog controls in the parent frame which rarely, if ever,
911 if ( !(win
->GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
913 wxWindow
*parent
= win
->GetParent();
914 if ( parent
&& !parent
->IsBeingDeleted() )
915 return parent
->GetEventHandler()->ProcessEvent(event
);
920 // Last try - application object.
921 if ( wxTheApp
&& (this != wxTheApp
) )
923 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
924 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
925 // processed appropriately via SearchEventTable.
926 if ( event
.GetEventType() != wxEVT_IDLE
)
928 if ( wxTheApp
->ProcessEvent(event
) )
936 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
938 wxEventType eventType
= event
.GetEventType();
939 int eventId
= event
.GetId();
941 // BC++ doesn't like testing for m_fn without != 0
942 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
944 // the line using reference exposes a bug in gcc: although it _seems_
945 // to work, it leads to weird crashes later on during program
948 wxEventTableEntry entry
= table
.entries
[i
];
950 const wxEventTableEntry
& entry
= table
.entries
[i
];
953 // match only if the event type is the same and the id is either -1 in
954 // the event table (meaning "any") or the event id matches the id
955 // specified in the event table either exactly or by falling into
956 // range between first and last
957 if ( eventType
== entry
.m_eventType
)
959 int tableId1
= entry
.m_id
,
960 tableId2
= entry
.m_lastId
;
962 if ( (tableId1
== -1) ||
963 (tableId2
== -1 && eventId
== tableId1
) ||
965 (eventId
>= tableId1
&& eventId
<= tableId2
)) )
968 event
.m_callbackUserData
= entry
.m_callbackUserData
;
970 (this->*((wxEventFunction
) (entry
.m_fn
)))(event
);
972 return !event
.GetSkipped();
980 void wxEvtHandler::Connect( int id
, int lastId
,
982 wxObjectEventFunction func
,
985 #if WXWIN_COMPATIBILITY_EVENT_TYPES
986 wxEventTableEntry
*entry
= new wxEventTableEntry
;
987 entry
->m_eventType
= eventType
;
989 entry
->m_lastId
= lastId
;
991 entry
->m_callbackUserData
= userData
;
992 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
993 wxDynamicEventTableEntry
*entry
=
994 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
);
995 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
997 if (!m_dynamicEvents
)
998 m_dynamicEvents
= new wxList
;
1000 // Insert at the front of the list so most recent additions are found first
1001 m_dynamicEvents
->Insert( (wxObject
*) entry
);
1004 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1005 wxObjectEventFunction func
,
1006 wxObject
*userData
)
1008 if (!m_dynamicEvents
)
1011 wxNode
*node
= m_dynamicEvents
->GetFirst();
1014 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1015 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
1016 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1017 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1018 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1020 if ((entry
->m_id
== id
) &&
1021 ((entry
->m_lastId
== lastId
) || (lastId
== -1)) &&
1022 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1023 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1024 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1026 if (entry
->m_callbackUserData
)
1027 delete entry
->m_callbackUserData
;
1028 m_dynamicEvents
->DeleteNode( node
);
1032 node
= node
->GetNext();
1037 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1039 wxCHECK_MSG( m_dynamicEvents
, FALSE
,
1040 wxT("caller should check that we have dynamic events") );
1042 int commandId
= event
.GetId();
1044 wxNode
*node
= m_dynamicEvents
->GetFirst();
1047 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1048 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
1049 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1050 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1051 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1055 // Match, if event spec says any id will do (id == -1)
1056 if ( (event
.GetEventType() == entry
->m_eventType
) &&
1057 (entry
->m_id
== -1 ||
1058 (entry
->m_lastId
== -1 && commandId
== entry
->m_id
) ||
1059 (entry
->m_lastId
!= -1 &&
1060 (commandId
>= entry
->m_id
&& commandId
<= entry
->m_lastId
))) )
1063 event
.m_callbackUserData
= entry
->m_callbackUserData
;
1065 (this->*((wxEventFunction
) (entry
->m_fn
)))(event
);
1067 if ( ! event
.GetSkipped() )
1071 node
= node
->GetNext();
1076 void wxEvtHandler::DoSetClientObject( wxClientData
*data
)
1078 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1079 wxT("can't have both object and void client data") );
1081 if ( m_clientObject
)
1082 delete m_clientObject
;
1084 m_clientObject
= data
;
1085 m_clientDataType
= wxClientData_Object
;
1088 wxClientData
*wxEvtHandler::DoGetClientObject() const
1090 // it's not an error to call GetClientObject() on a window which doesn't
1091 // have client data at all - NULL will be returned
1092 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1093 wxT("this window doesn't have object client data") );
1095 return m_clientObject
;
1098 void wxEvtHandler::DoSetClientData( void *data
)
1100 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1101 wxT("can't have both object and void client data") );
1103 m_clientData
= data
;
1104 m_clientDataType
= wxClientData_Void
;
1107 void *wxEvtHandler::DoGetClientData() const
1109 // it's not an error to call GetClientData() on a window which doesn't have
1110 // client data at all - NULL will be returned
1111 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1112 wxT("this window doesn't have void client data") );
1114 return m_clientData
;
1118 #if WXWIN_COMPATIBILITY
1119 bool wxEvtHandler::OnClose()
1121 if (GetNextHandler())
1122 return GetNextHandler()->OnClose();
1126 #endif // WXWIN_COMPATIBILITY
1130 // Find a window with the focus, that is also a descendant of the given window.
1131 // This is used to determine the window to initially send commands to.
1132 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1134 // Process events starting with the window with the focus, if any.
1135 wxWindow
* focusWin
= wxWindow::FindFocus();
1136 wxWindow
* win
= focusWin
;
1138 // Check if this is a descendant of this frame.
1139 // If not, win will be set to NULL.
1142 if (win
== ancestor
)
1145 win
= win
->GetParent();
1147 if (win
== (wxWindow
*) NULL
)
1148 focusWin
= (wxWindow
*) NULL
;