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 const wxEventType wxEVT_FIRST
= 10000;
125 const wxEventType wxEVT_USER_FIRST
= wxEVT_FIRST
+ 2000;
127 DEFINE_EVENT_TYPE(wxEVT_NULL
)
128 DEFINE_EVENT_TYPE(wxEVT_IDLE
)
129 DEFINE_EVENT_TYPE(wxEVT_SOCKET
)
131 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
137 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
139 DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED
)
140 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED
)
141 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED
)
142 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED
)
143 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
)
144 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
)
145 DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED
)
146 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED
)
147 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED
)
148 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED
)
149 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED
)
150 DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED
)
151 DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED
)
152 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED
)
153 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER
)
154 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED
)
156 // Sockets and timers send events, too
157 DEFINE_EVENT_TYPE(wxEVT_TIMER
)
160 DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN
)
161 DEFINE_EVENT_TYPE(wxEVT_LEFT_UP
)
162 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN
)
163 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP
)
164 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN
)
165 DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP
)
166 DEFINE_EVENT_TYPE(wxEVT_MOTION
)
167 DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW
)
168 DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW
)
169 DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK
)
170 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK
)
171 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK
)
172 DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS
)
173 DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS
)
174 DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS
)
175 DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL
)
177 // Non-client mouse events
178 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN
)
179 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP
)
180 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN
)
181 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP
)
182 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN
)
183 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP
)
184 DEFINE_EVENT_TYPE(wxEVT_NC_MOTION
)
185 DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW
)
186 DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW
)
187 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK
)
188 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK
)
189 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK
)
191 // Character input event type
192 DEFINE_EVENT_TYPE(wxEVT_CHAR
)
193 DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK
)
194 DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY
)
195 DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN
)
196 DEFINE_EVENT_TYPE(wxEVT_KEY_UP
)
199 DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR
)
201 // wxScrollbar and wxSlider event identifiers
202 DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP
)
203 DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM
)
204 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP
)
205 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN
)
206 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP
)
207 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN
)
208 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK
)
209 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE
)
210 DEFINE_EVENT_TYPE(wxEVT_SCROLL_ENDSCROLL
)
212 // Scroll events from wxWindow
213 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP
)
214 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM
)
215 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP
)
216 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN
)
217 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP
)
218 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN
)
219 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK
)
220 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE
)
223 DEFINE_EVENT_TYPE(wxEVT_SIZE
)
224 DEFINE_EVENT_TYPE(wxEVT_SIZING
)
225 DEFINE_EVENT_TYPE(wxEVT_MOVE
)
226 DEFINE_EVENT_TYPE(wxEVT_MOVING
)
227 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW
)
228 DEFINE_EVENT_TYPE(wxEVT_END_SESSION
)
229 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION
)
230 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
231 DEFINE_EVENT_TYPE(wxEVT_POWER
)
232 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
233 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
234 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
235 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
236 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
237 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
238 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
239 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
240 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
241 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
242 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
243 DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN
)
244 DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE
)
245 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
246 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
247 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
248 DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED
)
249 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
250 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
251 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
252 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
253 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
254 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
255 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
256 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
257 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
258 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
259 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
260 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
261 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
263 // Generic command events
264 // Note: a click is a higher-level event than button down/up
265 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
266 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
267 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
268 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
269 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
270 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
271 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
274 DEFINE_EVENT_TYPE(wxEVT_HELP
)
275 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
277 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
283 // ============================================================================
285 // ============================================================================
287 // ----------------------------------------------------------------------------
288 // event initialization
289 // ----------------------------------------------------------------------------
294 static int s_lastUsedEventType
= wxEVT_FIRST
;
296 #if WXWIN_COMPATIBILITY_2
297 // check that we don't overlap with the user-defined types: if it does
298 // happen, the best solution is probably to update the existing code to
299 // use wxNewEventType() instead of wxEVT_USER_FIRST
301 // due to the uncertainty
302 wxASSERT_MSG( s_lastUsedEventType
< wxEVT_USER_FIRST
- 1,
303 _T("possible event type conflict") );
304 #endif // WXWIN_COMPATIBILITY_2
306 return s_lastUsedEventType
++;
309 // ----------------------------------------------------------------------------
311 // ----------------------------------------------------------------------------
314 * General wxWindows events, covering
315 * all interesting things that might happen (button clicking, resizing,
316 * setting text in widgets, etc.).
318 * For each completely new event type, derive a new event class.
322 wxEvent::wxEvent(int theId
, wxEventType commandType
)
324 m_eventType
= commandType
;
325 m_eventObject
= (wxObject
*) NULL
;
329 m_callbackUserData
= (wxObject
*) NULL
;
330 m_isCommandEvent
= FALSE
;
333 wxEvent::wxEvent(const wxEvent
&src
)
335 , m_eventObject(src
.m_eventObject
)
336 , m_eventType(src
.m_eventType
)
337 , m_timeStamp(src
.m_timeStamp
)
339 , m_callbackUserData(src
.m_callbackUserData
)
340 , m_skipped(src
.m_skipped
)
341 , m_isCommandEvent(src
.m_isCommandEvent
)
354 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
355 : wxEvent(theId
, commandType
)
357 m_clientData
= (char *) NULL
;
358 m_clientObject
= (wxClientData
*) NULL
;
361 m_commandString
= wxEmptyString
;
362 m_isCommandEvent
= TRUE
;
369 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
373 : wxCommandEvent(commandType
, id
)
375 m_extraLong
= orient
;
383 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
387 m_eventType
= commandType
;
388 m_extraLong
= orient
;
397 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
399 m_eventType
= commandType
;
402 m_controlDown
= FALSE
;
406 m_middleDown
= FALSE
;
411 m_linesPerAction
= 0;
414 void wxMouseEvent::Assign(const wxMouseEvent
& event
)
416 m_eventType
= event
.m_eventType
;
421 m_leftDown
= event
.m_leftDown
;
422 m_middleDown
= event
.m_middleDown
;
423 m_rightDown
= event
.m_rightDown
;
425 m_controlDown
= event
.m_controlDown
;
426 m_shiftDown
= event
.m_shiftDown
;
427 m_altDown
= event
.m_altDown
;
428 m_metaDown
= event
.m_metaDown
;
430 m_wheelRotation
= event
.m_wheelRotation
;
431 m_wheelDelta
= event
.m_wheelDelta
;
432 m_linesPerAction
= event
.m_linesPerAction
;
435 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
436 // or any button dclick event (but = -1)
437 bool wxMouseEvent::ButtonDClick(int but
) const
442 return (LeftDClick() || MiddleDClick() || RightDClick());
446 return MiddleDClick();
448 return RightDClick();
450 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
456 // True if was a button down event (1 = left, 2 = middle, 3 = right)
457 // or any button down event (but = -1)
458 bool wxMouseEvent::ButtonDown(int but
) const
463 return (LeftDown() || MiddleDown() || RightDown());
471 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
477 // True if was a button up event (1 = left, 2 = middle, 3 = right)
478 // or any button up event (but = -1)
479 bool wxMouseEvent::ButtonUp(int but
) const
484 return (LeftUp() || MiddleUp() || RightUp());
492 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
498 // True if the given button is currently changing state
499 bool wxMouseEvent::Button(int but
) const
504 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
506 return (LeftDown() || LeftUp() || LeftDClick());
508 return (MiddleDown() || MiddleUp() || MiddleDClick());
510 return (RightDown() || RightUp() || RightDClick());
512 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
518 bool wxMouseEvent::ButtonIsDown(int but
) const
523 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
527 return MiddleIsDown();
529 return RightIsDown();
531 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
537 int wxMouseEvent::GetButton() const
539 for ( int i
= 1; i
<= 3; i
++ )
550 // Find the logical position of the event given the DC
551 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
553 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
563 wxKeyEvent::wxKeyEvent(wxEventType type
)
567 m_controlDown
= FALSE
;
577 wxKeyEvent::wxKeyEvent(const wxKeyEvent
& evt
)
583 m_keyCode
= evt
.m_keyCode
;
585 m_controlDown
= evt
.m_controlDown
;
586 m_shiftDown
= evt
.m_shiftDown
;
587 m_altDown
= evt
.m_altDown
;
588 m_metaDown
= evt
.m_metaDown
;
589 m_scanCode
= evt
.m_scanCode
;
590 m_rawCode
= evt
.m_rawCode
;
591 m_rawFlags
= evt
.m_rawFlags
;
594 m_uniChar
= evt
.m_uniChar
;
598 long wxKeyEvent::KeyCode() const
603 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
605 SetEventType(wxEVT_CREATE
);
609 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
611 SetEventType(wxEVT_DESTROY
);
615 wxChildFocusEvent::wxChildFocusEvent(wxWindow
*win
)
616 : wxCommandEvent(wxEVT_CHILD_FOCUS
)
623 // ----------------------------------------------------------------------------
625 // ----------------------------------------------------------------------------
633 wxEvtHandler::wxEvtHandler()
635 m_nextHandler
= (wxEvtHandler
*) NULL
;
636 m_previousHandler
= (wxEvtHandler
*) NULL
;
638 m_dynamicEvents
= (wxList
*) NULL
;
639 m_pendingEvents
= (wxList
*) NULL
;
641 # if !defined(__VISAGECPP__)
642 m_eventsLocker
= new wxCriticalSection
;
645 // no client data (yet)
647 m_clientDataType
= wxClientData_None
;
650 wxEvtHandler::~wxEvtHandler()
652 // Takes itself out of the list of handlers
653 if (m_previousHandler
)
654 m_previousHandler
->m_nextHandler
= m_nextHandler
;
657 m_nextHandler
->m_previousHandler
= m_previousHandler
;
661 wxNode
*node
= m_dynamicEvents
->GetFirst();
664 #if WXWIN_COMPATIBILITY_EVENT_TYPES
665 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
666 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
667 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
668 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
670 if (entry
->m_callbackUserData
)
671 delete entry
->m_callbackUserData
;
673 node
= node
->GetNext();
675 delete m_dynamicEvents
;
678 delete m_pendingEvents
;
681 # if !defined(__VISAGECPP__)
682 delete m_eventsLocker
;
685 // Remove us from wxPendingEvents if necessary.
686 if(wxPendingEventsLocker
)
687 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
688 if ( wxPendingEvents
) {
689 wxPendingEvents
->DeleteObject(this);
691 if(wxPendingEventsLocker
)
692 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
695 // we only delete object data, not untyped
696 if ( m_clientDataType
== wxClientData_Object
)
697 delete m_clientObject
;
702 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
704 // check that we are really in a child thread
705 wxASSERT_MSG( !wxThread::IsMain(),
706 wxT("use ProcessEvent() in main thread") );
708 AddPendingEvent(event
);
713 #endif // wxUSE_THREADS
715 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
717 // 1) Add event to list of pending events of this event handler
719 wxEvent
*eventCopy
= event
.Clone();
721 // we must be able to copy the events here so the event class must
722 // implement Clone() properly instead of just providing a NULL stab for it
723 wxCHECK_RET( eventCopy
,
724 _T("events of this type aren't supposed to be posted") );
726 #if defined(__VISAGECPP__)
727 wxENTER_CRIT_SECT( m_eventsLocker
);
729 wxENTER_CRIT_SECT( *m_eventsLocker
);
732 if ( !m_pendingEvents
)
733 m_pendingEvents
= new wxList
;
735 m_pendingEvents
->Append(eventCopy
);
737 #if defined(__VISAGECPP__)
738 wxLEAVE_CRIT_SECT( m_eventsLocker
);
740 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
743 // 2) Add this event handler to list of event handlers that
744 // have pending events.
746 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
748 if ( !wxPendingEvents
)
749 wxPendingEvents
= new wxList
;
750 wxPendingEvents
->Append(this);
752 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
754 // 3) Inform the system that new pending events are somwehere,
755 // and that these should be processed in idle time.
759 void wxEvtHandler::ProcessPendingEvents()
761 #if defined(__VISAGECPP__)
762 wxENTER_CRIT_SECT( m_eventsLocker
);
764 wxENTER_CRIT_SECT( *m_eventsLocker
);
767 wxNode
*node
= m_pendingEvents
->GetFirst();
770 wxEvent
*event
= (wxEvent
*)node
->GetData();
773 // In ProcessEvent, new events might get added and
774 // we can safely leave the crtical section here.
775 #if defined(__VISAGECPP__)
776 wxLEAVE_CRIT_SECT( m_eventsLocker
);
778 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
780 ProcessEvent(*event
);
782 #if defined(__VISAGECPP__)
783 wxENTER_CRIT_SECT( m_eventsLocker
);
785 wxENTER_CRIT_SECT( *m_eventsLocker
);
788 node
= m_pendingEvents
->GetFirst();
791 #if defined(__VISAGECPP__)
792 wxLEAVE_CRIT_SECT( m_eventsLocker
);
794 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
802 bool wxEvtHandler::TryParent(wxEvent
& event
)
804 if ( wxTheApp
&& (this != wxTheApp
) )
806 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
807 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
808 // processed appropriately via SearchEventTable.
809 if ( event
.GetEventType() != wxEVT_IDLE
)
811 if ( wxTheApp
->ProcessEvent(event
) )
819 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
821 // allow the application to hook into event processing
824 int rc
= wxTheApp
->FilterEvent(event
);
827 wxASSERT_MSG( rc
== 1 || rc
== 0,
828 _T("unexpected wxApp::FilterEvent return value") );
832 //else: proceed normally
835 // An event handler can be enabled or disabled
836 if ( GetEvtHandlerEnabled() )
838 // if we have a validator, it has higher priority than our own event
841 if ( TryValidator(event
) )
843 #endif // wxUSE_VALIDATORS
845 // Handle per-instance dynamic event tables first
846 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
849 // Then static per-class event tables (and search upwards through the
850 // inheritance hierarchy)
851 for ( const wxEventTable
*table
= GetEventTable();
853 table
= table
->baseTable
)
855 if ( SearchEventTable((wxEventTable
&)*table
, event
) )
860 // Try going down the event handler chain
861 if ( GetNextHandler() )
863 if ( GetNextHandler()->ProcessEvent(event
) )
867 // Finally propagate the event upwards the window chain and/or to the
868 // application object as necessary
869 return TryParent(event
);
872 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
874 wxEventType eventType
= event
.GetEventType();
875 int eventId
= event
.GetId();
877 // BC++ doesn't like testing for m_fn without != 0
878 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
880 // the line using reference exposes a bug in gcc: although it _seems_
881 // to work, it leads to weird crashes later on during program
884 wxEventTableEntry entry
= table
.entries
[i
];
886 const wxEventTableEntry
& entry
= table
.entries
[i
];
889 // match only if the event type is the same and the id is either -1 in
890 // the event table (meaning "any") or the event id matches the id
891 // specified in the event table either exactly or by falling into
892 // range between first and last
893 if ( eventType
== entry
.m_eventType
)
895 int tableId1
= entry
.m_id
,
896 tableId2
= entry
.m_lastId
;
898 if ( (tableId1
== -1) ||
899 (tableId2
== -1 && eventId
== tableId1
) ||
901 (eventId
>= tableId1
&& eventId
<= tableId2
)) )
904 event
.m_callbackUserData
= entry
.m_callbackUserData
;
906 (this->*((wxEventFunction
) (entry
.m_fn
)))(event
);
908 return !event
.GetSkipped();
916 void wxEvtHandler::Connect( int id
, int lastId
,
918 wxObjectEventFunction func
,
920 wxEvtHandler
* eventSink
)
922 #if WXWIN_COMPATIBILITY_EVENT_TYPES
923 wxEventTableEntry
*entry
= new wxEventTableEntry
;
924 entry
->m_eventType
= eventType
;
926 entry
->m_lastId
= lastId
;
928 entry
->m_callbackUserData
= userData
;
929 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
930 wxDynamicEventTableEntry
*entry
=
931 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
, eventSink
);
932 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
934 if (!m_dynamicEvents
)
935 m_dynamicEvents
= new wxList
;
937 // Insert at the front of the list so most recent additions are found first
938 m_dynamicEvents
->Insert( (wxObject
*) entry
);
941 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
942 wxObjectEventFunction func
,
944 wxEvtHandler
* eventSink
)
946 if (!m_dynamicEvents
)
949 wxNode
*node
= m_dynamicEvents
->GetFirst();
952 #if WXWIN_COMPATIBILITY_EVENT_TYPES
953 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
954 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
955 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
956 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
958 if ((entry
->m_id
== id
) &&
959 ((entry
->m_lastId
== lastId
) || (lastId
== -1)) &&
960 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
961 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
962 ((entry
->m_eventSink
== eventSink
) || (eventSink
== (wxEvtHandler
*)NULL
)) &&
963 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
965 if (entry
->m_callbackUserData
)
966 delete entry
->m_callbackUserData
;
967 m_dynamicEvents
->DeleteNode( node
);
971 node
= node
->GetNext();
976 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
978 wxCHECK_MSG( m_dynamicEvents
, FALSE
,
979 wxT("caller should check that we have dynamic events") );
981 int commandId
= event
.GetId();
983 wxNode
*node
= m_dynamicEvents
->GetFirst();
986 #if WXWIN_COMPATIBILITY_EVENT_TYPES
987 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
988 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
989 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
990 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
994 // Match, if event spec says any id will do (id == -1)
995 if ( (event
.GetEventType() == entry
->m_eventType
) &&
996 (entry
->m_id
== -1 ||
997 (entry
->m_lastId
== -1 && commandId
== entry
->m_id
) ||
998 (entry
->m_lastId
!= -1 &&
999 (commandId
>= entry
->m_id
&& commandId
<= entry
->m_lastId
))) )
1002 event
.m_callbackUserData
= entry
->m_callbackUserData
;
1004 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
1005 if (entry
->m_eventSink
)
1006 ((entry
->m_eventSink
)->*((wxEventFunction
) (entry
->m_fn
)))(event
);
1009 (this->*((wxEventFunction
) (entry
->m_fn
)))(event
);
1011 if ( ! event
.GetSkipped() )
1015 node
= node
->GetNext();
1020 void wxEvtHandler::DoSetClientObject( wxClientData
*data
)
1022 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1023 wxT("can't have both object and void client data") );
1025 if ( m_clientObject
)
1026 delete m_clientObject
;
1028 m_clientObject
= data
;
1029 m_clientDataType
= wxClientData_Object
;
1032 wxClientData
*wxEvtHandler::DoGetClientObject() const
1034 // it's not an error to call GetClientObject() on a window which doesn't
1035 // have client data at all - NULL will be returned
1036 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1037 wxT("this window doesn't have object client data") );
1039 return m_clientObject
;
1042 void wxEvtHandler::DoSetClientData( void *data
)
1044 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1045 wxT("can't have both object and void client data") );
1047 m_clientData
= data
;
1048 m_clientDataType
= wxClientData_Void
;
1051 void *wxEvtHandler::DoGetClientData() const
1053 // it's not an error to call GetClientData() on a window which doesn't have
1054 // client data at all - NULL will be returned
1055 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1056 wxT("this window doesn't have void client data") );
1058 return m_clientData
;
1062 #if WXWIN_COMPATIBILITY
1063 bool wxEvtHandler::OnClose()
1065 if (GetNextHandler())
1066 return GetNextHandler()->OnClose();
1070 #endif // WXWIN_COMPATIBILITY
1072 #endif // wxUSE_BASE
1076 // Find a window with the focus, that is also a descendant of the given window.
1077 // This is used to determine the window to initially send commands to.
1078 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1080 // Process events starting with the window with the focus, if any.
1081 wxWindow
* focusWin
= wxWindow::FindFocus();
1082 wxWindow
* win
= focusWin
;
1084 // Check if this is a descendant of this frame.
1085 // If not, win will be set to NULL.
1088 if (win
== ancestor
)
1091 win
= win
->GetParent();
1093 if (win
== (wxWindow
*) NULL
)
1094 focusWin
= (wxWindow
*) NULL
;