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
)
93 const wxEventTable
*wxEvtHandler::GetEventTable() const
94 { return &wxEvtHandler::sm_eventTable
; }
96 const wxEventTable
wxEvtHandler::sm_eventTable
=
97 { (const wxEventTable
*)NULL
, &wxEvtHandler::sm_eventTableEntries
[0] };
99 const wxEventTableEntry
wxEvtHandler::sm_eventTableEntries
[] =
100 { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL
, 0, 0, (wxObjectEventFunction
)NULL
, NULL
) };
102 // ----------------------------------------------------------------------------
104 // ----------------------------------------------------------------------------
106 // To put pending event handlers
107 wxList
*wxPendingEvents
= (wxList
*)NULL
;
110 // protects wxPendingEvents list
111 wxCriticalSection
*wxPendingEventsLocker
= (wxCriticalSection
*)NULL
;
114 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
116 // common event types are defined here, other event types are defined by the
117 // components which use them
119 DEFINE_EVENT_TYPE(wxEVT_NULL
)
120 DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED
)
121 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED
)
122 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED
)
123 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED
)
124 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
)
125 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
)
126 DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED
)
127 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED
)
128 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED
)
129 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED
)
130 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED
)
131 DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED
)
132 DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED
)
133 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED
)
134 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER
)
135 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED
)
137 // Sockets and timers send events, too
138 DEFINE_EVENT_TYPE(wxEVT_SOCKET
)
139 DEFINE_EVENT_TYPE(wxEVT_TIMER
)
142 DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN
)
143 DEFINE_EVENT_TYPE(wxEVT_LEFT_UP
)
144 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN
)
145 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP
)
146 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN
)
147 DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP
)
148 DEFINE_EVENT_TYPE(wxEVT_MOTION
)
149 DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW
)
150 DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW
)
151 DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK
)
152 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK
)
153 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK
)
154 DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS
)
155 DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS
)
156 DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS
)
157 DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL
)
159 // Non-client mouse events
160 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN
)
161 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP
)
162 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN
)
163 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP
)
164 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN
)
165 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP
)
166 DEFINE_EVENT_TYPE(wxEVT_NC_MOTION
)
167 DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW
)
168 DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW
)
169 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK
)
170 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK
)
171 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK
)
173 // Character input event type
174 DEFINE_EVENT_TYPE(wxEVT_CHAR
)
175 DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK
)
176 DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY
)
177 DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN
)
178 DEFINE_EVENT_TYPE(wxEVT_KEY_UP
)
181 DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR
)
183 // wxScrollbar and wxSlider event identifiers
184 DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP
)
185 DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM
)
186 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP
)
187 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN
)
188 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP
)
189 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN
)
190 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK
)
191 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE
)
193 // Scroll events from wxWindow
194 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP
)
195 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM
)
196 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP
)
197 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN
)
198 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP
)
199 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN
)
200 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK
)
201 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE
)
204 DEFINE_EVENT_TYPE(wxEVT_SIZE
)
205 DEFINE_EVENT_TYPE(wxEVT_MOVE
)
206 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW
)
207 DEFINE_EVENT_TYPE(wxEVT_END_SESSION
)
208 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION
)
209 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
210 DEFINE_EVENT_TYPE(wxEVT_POWER
)
211 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
212 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
213 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
214 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
215 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
216 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
217 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
218 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
219 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
220 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
221 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
222 DEFINE_EVENT_TYPE(wxEVT_MENU_CHAR
)
223 DEFINE_EVENT_TYPE(wxEVT_MENU_INIT
)
224 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
225 DEFINE_EVENT_TYPE(wxEVT_POPUP_MENU_INIT
)
226 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
227 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
228 DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED
)
229 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
230 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
231 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
232 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
233 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
234 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
235 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
236 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
237 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
238 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
239 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
240 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
241 DEFINE_EVENT_TYPE(wxEVT_IDLE
)
242 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
244 // Generic command events
245 // Note: a click is a higher-level event than button down/up
246 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
247 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
248 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
249 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
250 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
251 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
252 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
255 DEFINE_EVENT_TYPE(wxEVT_HELP
)
256 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
258 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
260 // ============================================================================
262 // ============================================================================
264 // ----------------------------------------------------------------------------
265 // event initialization
266 // ----------------------------------------------------------------------------
271 static int s_lastUsedEventType
= wxEVT_FIRST
;
273 #if WXWIN_COMPATIBILITY_2
274 // check that we don't overlap with the user-defined types: if it does
275 // happen, the best solution is probably to update the existing code to
276 // use wxNewEventType() instead of wxEVT_USER_FIRST
278 // due to the uncertainty
279 wxASSERT_MSG( s_lastUsedEventType
< wxEVT_USER_FIRST
- 1,
280 _T("possible event type conflict") );
281 #endif // WXWIN_COMPATIBILITY_2
283 return s_lastUsedEventType
++;
286 // ----------------------------------------------------------------------------
288 // ----------------------------------------------------------------------------
291 * General wxWindows events, covering
292 * all interesting things that might happen (button clicking, resizing,
293 * setting text in widgets, etc.).
295 * For each completely new event type, derive a new event class.
299 wxEvent::wxEvent(int theId
, wxEventType commandType
)
301 m_eventType
= commandType
;
302 m_eventObject
= (wxObject
*) NULL
;
306 m_callbackUserData
= (wxObject
*) NULL
;
307 m_isCommandEvent
= FALSE
;
310 wxEvent::wxEvent(const wxEvent
&src
)
312 m_eventType
= src
.m_eventType
;
313 m_eventObject
= src
.m_eventObject
;
314 m_timeStamp
= src
.m_timeStamp
;
316 m_skipped
= src
.m_skipped
;
317 m_callbackUserData
= src
.m_callbackUserData
;
318 m_isCommandEvent
= src
.m_isCommandEvent
;
328 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
329 : wxEvent( theId
, commandType
)
331 m_clientData
= (char *) NULL
;
332 m_clientObject
= (wxClientData
*) NULL
;
335 m_commandString
= wxEmptyString
;
336 m_isCommandEvent
= TRUE
;
343 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
347 : wxCommandEvent(commandType
, id
)
349 m_extraLong
= orient
;
357 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
361 m_eventType
= commandType
;
362 m_extraLong
= orient
;
371 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
373 m_eventType
= commandType
;
376 m_controlDown
= FALSE
;
380 m_middleDown
= FALSE
;
385 m_linesPerAction
= 0;
388 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
389 // or any button dclick event (but = -1)
390 bool wxMouseEvent::ButtonDClick(int but
) const
395 return (LeftDClick() || MiddleDClick() || RightDClick());
399 return MiddleDClick();
401 return RightDClick();
403 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
409 // True if was a button down event (1 = left, 2 = middle, 3 = right)
410 // or any button down event (but = -1)
411 bool wxMouseEvent::ButtonDown(int but
) const
416 return (LeftDown() || MiddleDown() || RightDown());
424 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
430 // True if was a button up event (1 = left, 2 = middle, 3 = right)
431 // or any button up event (but = -1)
432 bool wxMouseEvent::ButtonUp(int but
) const
437 return (LeftUp() || MiddleUp() || RightUp());
445 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
451 // True if the given button is currently changing state
452 bool wxMouseEvent::Button(int but
) const
457 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
459 return (LeftDown() || LeftUp() || LeftDClick());
461 return (MiddleDown() || MiddleUp() || MiddleDClick());
463 return (RightDown() || RightUp() || RightDClick());
465 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
471 bool wxMouseEvent::ButtonIsDown(int but
) const
476 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
480 return MiddleIsDown();
482 return RightIsDown();
484 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
490 int wxMouseEvent::GetButton() const
492 for ( int i
= 1; i
<= 3; i
++ )
503 // Find the logical position of the event given the DC
504 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
506 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
516 wxKeyEvent::wxKeyEvent(wxEventType type
)
520 m_controlDown
= FALSE
;
528 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
530 SetEventType(wxEVT_CREATE
);
534 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
536 SetEventType(wxEVT_DESTROY
);
540 wxChildFocusEvent::wxChildFocusEvent(wxWindow
*win
)
541 : wxCommandEvent(wxEVT_CHILD_FOCUS
)
548 // ----------------------------------------------------------------------------
550 // ----------------------------------------------------------------------------
556 wxEvtHandler::wxEvtHandler()
558 m_nextHandler
= (wxEvtHandler
*) NULL
;
559 m_previousHandler
= (wxEvtHandler
*) NULL
;
561 m_dynamicEvents
= (wxList
*) NULL
;
563 m_pendingEvents
= (wxList
*) NULL
;
565 # if !defined(__VISAGECPP__)
566 m_eventsLocker
= new wxCriticalSection
;
569 // no client data (yet)
571 m_clientDataType
= wxClientData_None
;
574 wxEvtHandler::~wxEvtHandler()
576 // Takes itself out of the list of handlers
577 if (m_previousHandler
)
578 m_previousHandler
->m_nextHandler
= m_nextHandler
;
581 m_nextHandler
->m_previousHandler
= m_previousHandler
;
585 wxNode
*node
= m_dynamicEvents
->First();
588 #if WXWIN_COMPATIBILITY_EVENT_TYPES
589 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
590 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
591 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
592 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
594 if (entry
->m_callbackUserData
)
595 delete entry
->m_callbackUserData
;
599 delete m_dynamicEvents
;
602 delete m_pendingEvents
;
605 # if !defined(__VISAGECPP__)
606 delete m_eventsLocker
;
610 // we only delete object data, not untyped
611 if ( m_clientDataType
== wxClientData_Object
)
612 delete m_clientObject
;
617 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
619 // check that we are really in a child thread
620 wxASSERT_MSG( !wxThread::IsMain(),
621 wxT("use ProcessEvent() in main thread") );
623 AddPendingEvent(event
);
628 #endif // wxUSE_THREADS
630 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
632 // 1) Add event to list of pending events of this event handler
634 wxEvent
*eventCopy
= event
.Clone();
636 // we must be able to copy the events here so the event class must
637 // implement Clone() properly instead of just providing a NULL stab for it
638 wxCHECK_RET( eventCopy
,
639 _T("events of this type aren't supposed to be posted") );
641 #if defined(__VISAGECPP__)
642 wxENTER_CRIT_SECT( m_eventsLocker
);
644 wxENTER_CRIT_SECT( *m_eventsLocker
);
647 if ( !m_pendingEvents
)
648 m_pendingEvents
= new wxList
;
650 m_pendingEvents
->Append(eventCopy
);
652 #if defined(__VISAGECPP__)
653 wxLEAVE_CRIT_SECT( m_eventsLocker
);
655 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
658 // 2) Add this event handler to list of event handlers that
659 // have pending events.
661 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
663 if ( !wxPendingEvents
)
664 wxPendingEvents
= new wxList
;
665 wxPendingEvents
->Append(this);
667 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
669 // 3) Inform the system that new pending events are somwehere,
670 // and that these should be processed in idle time.
674 void wxEvtHandler::ProcessPendingEvents()
676 #if defined(__VISAGECPP__)
677 wxENTER_CRIT_SECT( m_eventsLocker
);
679 wxENTER_CRIT_SECT( *m_eventsLocker
);
682 wxNode
*node
= m_pendingEvents
->First();
685 wxEvent
*event
= (wxEvent
*)node
->Data();
688 // In ProcessEvent, new events might get added and
689 // we can safely leave the crtical section here.
690 #if defined(__VISAGECPP__)
691 wxLEAVE_CRIT_SECT( m_eventsLocker
);
693 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
695 ProcessEvent(*event
);
697 #if defined(__VISAGECPP__)
698 wxENTER_CRIT_SECT( m_eventsLocker
);
700 wxENTER_CRIT_SECT( *m_eventsLocker
);
703 node
= m_pendingEvents
->First();
706 #if defined(__VISAGECPP__)
707 wxLEAVE_CRIT_SECT( m_eventsLocker
);
709 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
717 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
721 // We have to use the actual window or processing events from
722 // wxWindowNative destructor won't work (we don't see the wxWindow class)
724 // check that our flag corresponds to reality
725 wxClassInfo
* info
= NULL
;
726 #ifdef __WXUNIVERSAL__
727 # if defined(__WXMSW__)
728 info
= CLASSINFO(wxWindowMSW
);
729 # elif defined(__WXGTK__)
730 info
= CLASSINFO(wxWindowGTK
);
731 # elif defined(__WXX11__)
732 info
= CLASSINFO(wxWindowX11
);
733 # elif defined(__WXMGL__)
734 info
= CLASSINFO(wxWindowMGL
);
735 # elif defined(__WXPM__)
736 info
= CLASSINFO(wxWindowOS2
);
737 # elif defined(__WXMAC__)
738 info
= CLASSINFO(wxWindowMac
);
739 # elif defined(__WXMOTIF__)
740 info
= CLASSINFO(wxWindowMotif
);
743 info
= CLASSINFO(wxWindow
);
746 wxASSERT_MSG( m_isWindow
== IsKindOf(info
),
747 wxString(GetClassInfo()->GetClassName()) + _T(" should [not] be a window but it is [not]") );
752 // An event handler can be enabled or disabled
753 if ( GetEvtHandlerEnabled() )
758 What is this? When using GUI threads, a non main
759 threads can send an event and process it itself.
760 This breaks GTK's GUI threads, so please explain.
763 // Check whether we are in a child thread.
764 if ( !wxThread::IsMain() )
765 return ProcessThreadEvent(event
);
768 // Handle per-instance dynamic event tables first
769 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
772 // Then static per-class event tables
773 const wxEventTable
*table
= GetEventTable();
775 #if wxUSE_GUI && wxUSE_VALIDATORS
776 // Try the associated validator first, if this is a window.
777 // Problem: if the event handler of the window has been replaced,
778 // this wxEvtHandler may no longer be a window.
779 // Therefore validators won't be processed if the handler
780 // has been replaced with SetEventHandler.
781 // THIS CAN BE CURED if PushEventHandler is used instead of
782 // SetEventHandler, and then processing will be passed down the
783 // chain of event handlers.
786 wxWindow
*win
= (wxWindow
*)this;
788 // Can only use the validator of the window which
789 // is receiving the event
790 if ( win
== event
.GetEventObject() )
792 wxValidator
*validator
= win
->GetValidator();
793 if ( validator
&& validator
->ProcessEvent(event
) )
801 // Search upwards through the inheritance hierarchy
804 if ( SearchEventTable((wxEventTable
&)*table
, event
) )
806 table
= table
->baseTable
;
810 // Try going down the event handler chain
811 if ( GetNextHandler() )
813 if ( GetNextHandler()->ProcessEvent(event
) )
818 // Carry on up the parent-child hierarchy, but only if event is a command
819 // event: it wouldn't make sense for a parent to receive a child's size
820 // event, for example
821 if ( m_isWindow
&& event
.IsCommandEvent() )
823 wxWindow
*win
= (wxWindow
*)this;
825 // honour the requests to stop propagation at this window: this is
826 // used by the dialogs, for example, to prevent processing the events
827 // from the dialog controls in the parent frame which rarely, if ever,
829 if ( !(win
->GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
831 wxWindow
*parent
= win
->GetParent();
832 if ( parent
&& !parent
->IsBeingDeleted() )
833 return parent
->GetEventHandler()->ProcessEvent(event
);
838 // Last try - application object.
839 if ( wxTheApp
&& (this != wxTheApp
) )
841 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
842 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
843 // processed appropriately via SearchEventTable.
844 if ( event
.GetEventType() != wxEVT_IDLE
)
846 if ( wxTheApp
->ProcessEvent(event
) )
854 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
856 wxEventType eventType
= event
.GetEventType();
857 int eventId
= event
.GetId();
859 // BC++ doesn't like testing for m_fn without != 0
860 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
862 // the line using reference exposes a bug in gcc: although it _seems_
863 // to work, it leads to weird crashes later on during program
866 wxEventTableEntry entry
= table
.entries
[i
];
868 const wxEventTableEntry
& entry
= table
.entries
[i
];
871 // match only if the event type is the same and the id is either -1 in
872 // the event table (meaning "any") or the event id matches the id
873 // specified in the event table either exactly or by falling into
874 // range between first and last
875 if ( eventType
== entry
.m_eventType
)
877 int tableId1
= entry
.m_id
,
878 tableId2
= entry
.m_lastId
;
880 if ( (tableId1
== -1) ||
881 (tableId2
== -1 && eventId
== tableId1
) ||
883 (eventId
>= tableId1
&& eventId
<= tableId2
)) )
886 event
.m_callbackUserData
= entry
.m_callbackUserData
;
888 (this->*((wxEventFunction
) (entry
.m_fn
)))(event
);
890 return !event
.GetSkipped();
898 void wxEvtHandler::Connect( int id
, int lastId
,
900 wxObjectEventFunction func
,
903 #if WXWIN_COMPATIBILITY_EVENT_TYPES
904 wxEventTableEntry
*entry
= new wxEventTableEntry
;
905 entry
->m_eventType
= eventType
;
907 entry
->m_lastId
= lastId
;
909 entry
->m_callbackUserData
= userData
;
910 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
911 wxDynamicEventTableEntry
*entry
=
912 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
);
913 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
915 if (!m_dynamicEvents
)
916 m_dynamicEvents
= new wxList
;
918 m_dynamicEvents
->Append( (wxObject
*) entry
);
921 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
922 wxObjectEventFunction func
,
925 if (!m_dynamicEvents
)
928 wxNode
*node
= m_dynamicEvents
->First();
931 #if WXWIN_COMPATIBILITY_EVENT_TYPES
932 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
933 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
934 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
935 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
937 if ((entry
->m_id
== id
) &&
938 ((entry
->m_lastId
== lastId
) || (lastId
== -1)) &&
939 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
940 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
941 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
943 if (entry
->m_callbackUserData
)
944 delete entry
->m_callbackUserData
;
945 m_dynamicEvents
->DeleteNode( node
);
954 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
956 wxCHECK_MSG( m_dynamicEvents
, FALSE
,
957 wxT("caller should check that we have dynamic events") );
959 int commandId
= event
.GetId();
961 wxNode
*node
= m_dynamicEvents
->First();
964 #if WXWIN_COMPATIBILITY_EVENT_TYPES
965 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
966 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
967 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
968 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
972 // Match, if event spec says any id will do (id == -1)
973 if ( (event
.GetEventType() == entry
->m_eventType
) &&
974 (entry
->m_id
== -1 ||
975 (entry
->m_lastId
== -1 && commandId
== entry
->m_id
) ||
976 (entry
->m_lastId
!= -1 &&
977 (commandId
>= entry
->m_id
&& commandId
<= entry
->m_lastId
))) )
980 event
.m_callbackUserData
= entry
->m_callbackUserData
;
982 (this->*((wxEventFunction
) (entry
->m_fn
)))(event
);
984 if (event
.GetSkipped())
995 void wxEvtHandler::DoSetClientObject( wxClientData
*data
)
997 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
998 wxT("can't have both object and void client data") );
1000 if ( m_clientObject
)
1001 delete m_clientObject
;
1003 m_clientObject
= data
;
1004 m_clientDataType
= wxClientData_Object
;
1007 wxClientData
*wxEvtHandler::DoGetClientObject() const
1009 // it's not an error to call GetClientObject() on a window which doesn't
1010 // have client data at all - NULL will be returned
1011 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1012 wxT("this window doesn't have object client data") );
1014 return m_clientObject
;
1017 void wxEvtHandler::DoSetClientData( void *data
)
1019 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1020 wxT("can't have both object and void client data") );
1022 m_clientData
= data
;
1023 m_clientDataType
= wxClientData_Void
;
1026 void *wxEvtHandler::DoGetClientData() const
1028 // it's not an error to call GetClientData() on a window which doesn't have
1029 // client data at all - NULL will be returned
1030 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1031 wxT("this window doesn't have void client data") );
1033 return m_clientData
;
1037 #if WXWIN_COMPATIBILITY
1038 bool wxEvtHandler::OnClose()
1040 if (GetNextHandler())
1041 return GetNextHandler()->OnClose();
1045 #endif // WXWIN_COMPATIBILITY
1049 // Find a window with the focus, that is also a descendant of the given window.
1050 // This is used to determine the window to initially send commands to.
1051 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1053 // Process events starting with the window with the focus, if any.
1054 wxWindow
* focusWin
= wxWindow::FindFocus();
1055 wxWindow
* win
= focusWin
;
1057 // Check if this is a descendant of this frame.
1058 // If not, win will be set to NULL.
1061 if (win
== ancestor
)
1064 win
= win
->GetParent();
1066 if (win
== (wxWindow
*) NULL
)
1067 focusWin
= (wxWindow
*) NULL
;