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(wxUpdateUIEvent
, wxCommandEvent
)
83 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent
, wxCommandEvent
)
84 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent
, wxEvent
)
85 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent
, wxEvent
)
86 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent
, wxEvent
)
87 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent
, wxEvent
)
88 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent
, wxCommandEvent
)
89 IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent
, wxCommandEvent
)
92 const wxEventTable
*wxEvtHandler::GetEventTable() const
93 { return &wxEvtHandler::sm_eventTable
; }
95 const wxEventTable
wxEvtHandler::sm_eventTable
=
96 { (const wxEventTable
*)NULL
, &wxEvtHandler::sm_eventTableEntries
[0] };
98 const wxEventTableEntry
wxEvtHandler::sm_eventTableEntries
[] =
99 { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL
, 0, 0, (wxObjectEventFunction
)NULL
, NULL
) };
101 // ----------------------------------------------------------------------------
103 // ----------------------------------------------------------------------------
105 // To put pending event handlers
106 wxList
*wxPendingEvents
= (wxList
*)NULL
;
109 // protects wxPendingEvents list
110 wxCriticalSection
*wxPendingEventsLocker
= (wxCriticalSection
*)NULL
;
113 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
115 // common event types are defined here, other event types are defined by the
116 // components which use them
118 DEFINE_EVENT_TYPE(wxEVT_NULL
)
119 DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED
)
120 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED
)
121 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED
)
122 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED
)
123 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
)
124 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
)
125 DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED
)
126 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED
)
127 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED
)
128 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED
)
129 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED
)
130 DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED
)
131 DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED
)
132 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED
)
133 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER
)
134 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED
)
136 // Sockets and timers send events, too
137 DEFINE_EVENT_TYPE(wxEVT_SOCKET
)
138 DEFINE_EVENT_TYPE(wxEVT_TIMER
)
141 DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN
)
142 DEFINE_EVENT_TYPE(wxEVT_LEFT_UP
)
143 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN
)
144 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP
)
145 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN
)
146 DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP
)
147 DEFINE_EVENT_TYPE(wxEVT_MOTION
)
148 DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW
)
149 DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW
)
150 DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK
)
151 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK
)
152 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK
)
153 DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS
)
154 DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS
)
155 DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS
)
156 DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL
)
158 // Non-client mouse events
159 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN
)
160 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP
)
161 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN
)
162 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP
)
163 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN
)
164 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP
)
165 DEFINE_EVENT_TYPE(wxEVT_NC_MOTION
)
166 DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW
)
167 DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW
)
168 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK
)
169 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK
)
170 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK
)
172 // Character input event type
173 DEFINE_EVENT_TYPE(wxEVT_CHAR
)
174 DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK
)
175 DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY
)
176 DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN
)
177 DEFINE_EVENT_TYPE(wxEVT_KEY_UP
)
180 DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR
)
182 // wxScrollbar and wxSlider event identifiers
183 DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP
)
184 DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM
)
185 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP
)
186 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN
)
187 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP
)
188 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN
)
189 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK
)
190 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE
)
192 // Scroll events from wxWindow
193 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP
)
194 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM
)
195 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP
)
196 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN
)
197 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP
)
198 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN
)
199 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK
)
200 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE
)
203 DEFINE_EVENT_TYPE(wxEVT_SIZE
)
204 DEFINE_EVENT_TYPE(wxEVT_MOVE
)
205 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW
)
206 DEFINE_EVENT_TYPE(wxEVT_END_SESSION
)
207 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION
)
208 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
209 DEFINE_EVENT_TYPE(wxEVT_POWER
)
210 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
211 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
212 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
213 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
214 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
215 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
216 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
217 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
218 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
219 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
220 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
221 DEFINE_EVENT_TYPE(wxEVT_MENU_CHAR
)
222 DEFINE_EVENT_TYPE(wxEVT_MENU_INIT
)
223 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
224 DEFINE_EVENT_TYPE(wxEVT_POPUP_MENU_INIT
)
225 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
226 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
227 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
228 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
229 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
230 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
231 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
232 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
233 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
234 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
235 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
236 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
237 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
238 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
239 DEFINE_EVENT_TYPE(wxEVT_IDLE
)
240 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
242 // Generic command events
243 // Note: a click is a higher-level event than button down/up
244 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
245 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
246 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
247 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
248 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
249 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
250 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
253 DEFINE_EVENT_TYPE(wxEVT_HELP
)
254 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
256 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
258 // ============================================================================
260 // ============================================================================
262 // ----------------------------------------------------------------------------
263 // event initialization
264 // ----------------------------------------------------------------------------
269 static int s_lastUsedEventType
= wxEVT_FIRST
;
271 #if WXWIN_COMPATIBILITY_2
272 // check that we don't overlap with the user-defined types: if it does
273 // happen, the best solution is probably to update the existing code to
274 // use wxNewEventType() instead of wxEVT_USER_FIRST
276 // due to the uncertainty
277 wxASSERT_MSG( s_lastUsedEventType
< wxEVT_USER_FIRST
- 1,
278 _T("possible event type conflict") );
279 #endif // WXWIN_COMPATIBILITY_2
281 return s_lastUsedEventType
++;
284 // ----------------------------------------------------------------------------
286 // ----------------------------------------------------------------------------
289 * General wxWindows events, covering
290 * all interesting things that might happen (button clicking, resizing,
291 * setting text in widgets, etc.).
293 * For each completely new event type, derive a new event class.
297 wxEvent::wxEvent(int theId
, wxEventType commandType
)
299 m_eventType
= commandType
;
300 m_eventObject
= (wxObject
*) NULL
;
304 m_callbackUserData
= (wxObject
*) NULL
;
305 m_isCommandEvent
= FALSE
;
308 wxEvent::wxEvent(const wxEvent
&src
)
310 m_eventType
= src
.m_eventType
;
311 m_eventObject
= src
.m_eventObject
;
312 m_timeStamp
= src
.m_timeStamp
;
314 m_skipped
= src
.m_skipped
;
315 m_callbackUserData
= src
.m_callbackUserData
;
316 m_isCommandEvent
= src
.m_isCommandEvent
;
326 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
327 : wxEvent( theId
, commandType
)
329 m_clientData
= (char *) NULL
;
330 m_clientObject
= (wxClientData
*) NULL
;
333 m_commandString
= wxEmptyString
;
334 m_isCommandEvent
= TRUE
;
341 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
345 : wxCommandEvent(commandType
, id
)
347 m_extraLong
= orient
;
355 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
359 m_eventType
= commandType
;
360 m_extraLong
= orient
;
369 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
371 m_eventType
= commandType
;
374 m_controlDown
= FALSE
;
378 m_middleDown
= FALSE
;
383 m_linesPerAction
= 0;
386 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
387 // or any button dclick event (but = -1)
388 bool wxMouseEvent::ButtonDClick(int but
) const
393 return (LeftDClick() || MiddleDClick() || RightDClick());
397 return MiddleDClick();
399 return RightDClick();
401 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
407 // True if was a button down event (1 = left, 2 = middle, 3 = right)
408 // or any button down event (but = -1)
409 bool wxMouseEvent::ButtonDown(int but
) const
414 return (LeftDown() || MiddleDown() || RightDown());
422 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
428 // True if was a button up event (1 = left, 2 = middle, 3 = right)
429 // or any button up event (but = -1)
430 bool wxMouseEvent::ButtonUp(int but
) const
435 return (LeftUp() || MiddleUp() || RightUp());
443 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
449 // True if the given button is currently changing state
450 bool wxMouseEvent::Button(int but
) const
455 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
457 return (LeftDown() || LeftUp() || LeftDClick());
459 return (MiddleDown() || MiddleUp() || MiddleDClick());
461 return (RightDown() || RightUp() || RightDClick());
463 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
469 bool wxMouseEvent::ButtonIsDown(int but
) const
474 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
478 return MiddleIsDown();
480 return RightIsDown();
482 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
488 int wxMouseEvent::GetButton() const
490 for ( int i
= 1; i
<= 3; i
++ )
501 // Find the logical position of the event given the DC
502 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
504 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
514 wxKeyEvent::wxKeyEvent(wxEventType type
)
518 m_controlDown
= FALSE
;
526 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
528 SetEventType(wxEVT_CREATE
);
532 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
534 SetEventType(wxEVT_DESTROY
);
538 wxChildFocusEvent::wxChildFocusEvent(wxWindow
*win
)
539 : wxCommandEvent(wxEVT_CHILD_FOCUS
)
546 // ----------------------------------------------------------------------------
548 // ----------------------------------------------------------------------------
554 wxEvtHandler::wxEvtHandler()
556 m_nextHandler
= (wxEvtHandler
*) NULL
;
557 m_previousHandler
= (wxEvtHandler
*) NULL
;
559 m_dynamicEvents
= (wxList
*) NULL
;
561 m_pendingEvents
= (wxList
*) NULL
;
563 # if !defined(__VISAGECPP__)
564 m_eventsLocker
= new wxCriticalSection
;
567 // no client data (yet)
569 m_clientDataType
= wxClientData_None
;
572 wxEvtHandler::~wxEvtHandler()
574 // Takes itself out of the list of handlers
575 if (m_previousHandler
)
576 m_previousHandler
->m_nextHandler
= m_nextHandler
;
579 m_nextHandler
->m_previousHandler
= m_previousHandler
;
583 wxNode
*node
= m_dynamicEvents
->First();
586 #if WXWIN_COMPATIBILITY_EVENT_TYPES
587 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
588 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
589 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
590 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
592 if (entry
->m_callbackUserData
)
593 delete entry
->m_callbackUserData
;
597 delete m_dynamicEvents
;
600 delete m_pendingEvents
;
603 # if !defined(__VISAGECPP__)
604 delete m_eventsLocker
;
608 // we only delete object data, not untyped
609 if ( m_clientDataType
== wxClientData_Object
)
610 delete m_clientObject
;
615 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
617 // check that we are really in a child thread
618 wxASSERT_MSG( !wxThread::IsMain(),
619 wxT("use ProcessEvent() in main thread") );
621 AddPendingEvent(event
);
626 #endif // wxUSE_THREADS
628 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
630 // 1) Add event to list of pending events of this event handler
632 #if defined(__VISAGECPP__)
633 wxENTER_CRIT_SECT( m_eventsLocker
);
635 wxENTER_CRIT_SECT( *m_eventsLocker
);
638 if ( !m_pendingEvents
)
639 m_pendingEvents
= new wxList
;
641 wxEvent
*event2
= event
.Clone();
643 m_pendingEvents
->Append(event2
);
645 #if defined(__VISAGECPP__)
646 wxLEAVE_CRIT_SECT( m_eventsLocker
);
648 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
651 // 2) Add this event handler to list of event handlers that
652 // have pending events.
654 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
656 if ( !wxPendingEvents
)
657 wxPendingEvents
= new wxList
;
658 wxPendingEvents
->Append(this);
660 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
662 // 3) Inform the system that new pending events are somwehere,
663 // and that these should be processed in idle time.
667 void wxEvtHandler::ProcessPendingEvents()
669 #if defined(__VISAGECPP__)
670 wxENTER_CRIT_SECT( m_eventsLocker
);
672 wxENTER_CRIT_SECT( *m_eventsLocker
);
675 wxNode
*node
= m_pendingEvents
->First();
678 wxEvent
*event
= (wxEvent
*)node
->Data();
681 // In ProcessEvent, new events might get added and
682 // we can safely leave the crtical section here.
683 #if defined(__VISAGECPP__)
684 wxLEAVE_CRIT_SECT( m_eventsLocker
);
686 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
688 ProcessEvent(*event
);
690 #if defined(__VISAGECPP__)
691 wxENTER_CRIT_SECT( m_eventsLocker
);
693 wxENTER_CRIT_SECT( *m_eventsLocker
);
696 node
= m_pendingEvents
->First();
699 #if defined(__VISAGECPP__)
700 wxLEAVE_CRIT_SECT( m_eventsLocker
);
702 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
710 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
714 // We have to use the actual window or processing events from
715 // wxWindowNative destructor won't work (we don't see the wxWindow class)
717 // check that our flag corresponds to reality
718 wxClassInfo
* info
= NULL
;
719 #ifdef __WXUNIVERSAL__
720 # if defined(__WXMSW__)
721 info
= CLASSINFO(wxWindowMSW
);
722 # elif defined(__WXGTK__)
723 info
= CLASSINFO(wxWindowGTK
);
724 # elif defined(__WXMGL__)
725 info
= CLASSINFO(wxWindowMGL
);
726 # elif defined(__WXPM__)
727 info
= CLASSINFO(wxWindowOS2
);
728 # elif defined(__WXMAC__)
729 info
= CLASSINFO(wxWindowMac
);
730 # elif defined(__WXMOTIF__)
731 info
= CLASSINFO(wxWindowMotif
);
734 info
= CLASSINFO(wxWindow
);
737 wxASSERT_MSG( m_isWindow
== IsKindOf(info
),
738 wxString(GetClassInfo()->GetClassName()) + _T(" should [not] be a window but it is [not]") );
743 // An event handler can be enabled or disabled
744 if ( GetEvtHandlerEnabled() )
749 What is this? When using GUI threads, a non main
750 threads can send an event and process it itself.
751 This breaks GTK's GUI threads, so please explain.
754 // Check whether we are in a child thread.
755 if ( !wxThread::IsMain() )
756 return ProcessThreadEvent(event
);
759 // Handle per-instance dynamic event tables first
760 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
763 // Then static per-class event tables
764 const wxEventTable
*table
= GetEventTable();
766 #if wxUSE_GUI && wxUSE_VALIDATORS
767 // Try the associated validator first, if this is a window.
768 // Problem: if the event handler of the window has been replaced,
769 // this wxEvtHandler may no longer be a window.
770 // Therefore validators won't be processed if the handler
771 // has been replaced with SetEventHandler.
772 // THIS CAN BE CURED if PushEventHandler is used instead of
773 // SetEventHandler, and then processing will be passed down the
774 // chain of event handlers.
777 wxWindow
*win
= (wxWindow
*)this;
779 // Can only use the validator of the window which
780 // is receiving the event
781 if ( win
== event
.GetEventObject() )
783 wxValidator
*validator
= win
->GetValidator();
784 if ( validator
&& validator
->ProcessEvent(event
) )
792 // Search upwards through the inheritance hierarchy
795 if ( SearchEventTable((wxEventTable
&)*table
, event
) )
797 table
= table
->baseTable
;
801 // Try going down the event handler chain
802 if ( GetNextHandler() )
804 if ( GetNextHandler()->ProcessEvent(event
) )
809 // Carry on up the parent-child hierarchy, but only if event is a command
810 // event: it wouldn't make sense for a parent to receive a child's size
811 // event, for example
812 if ( m_isWindow
&& event
.IsCommandEvent() )
814 wxWindow
*win
= (wxWindow
*)this;
816 // honour the requests to stop propagation at this window: this is
817 // used by the dialogs, for example, to prevent processing the events
818 // from the dialog controls in the parent frame which rarely, if ever,
820 if ( !(win
->GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
822 wxWindow
*parent
= win
->GetParent();
823 if ( parent
&& !parent
->IsBeingDeleted() )
824 return parent
->GetEventHandler()->ProcessEvent(event
);
829 // Last try - application object.
830 if ( wxTheApp
&& (this != wxTheApp
) )
832 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
833 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
834 // processed appropriately via SearchEventTable.
835 if ( event
.GetEventType() != wxEVT_IDLE
)
837 if ( wxTheApp
->ProcessEvent(event
) )
845 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
847 wxEventType eventType
= event
.GetEventType();
848 int eventId
= event
.GetId();
850 // BC++ doesn't like testing for m_fn without != 0
851 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
853 // the line using reference exposes a bug in gcc: although it _seems_
854 // to work, it leads to weird crashes later on during program
857 wxEventTableEntry entry
= table
.entries
[i
];
859 const wxEventTableEntry
& entry
= table
.entries
[i
];
862 // match only if the event type is the same and the id is either -1 in
863 // the event table (meaning "any") or the event id matches the id
864 // specified in the event table either exactly or by falling into
865 // range between first and last
866 if ( eventType
== entry
.m_eventType
)
868 int tableId1
= entry
.m_id
,
869 tableId2
= entry
.m_lastId
;
871 if ( (tableId1
== -1) ||
872 (tableId2
== -1 && eventId
== tableId1
) ||
874 (eventId
>= tableId1
&& eventId
<= tableId2
)) )
877 event
.m_callbackUserData
= entry
.m_callbackUserData
;
879 (this->*((wxEventFunction
) (entry
.m_fn
)))(event
);
881 return !event
.GetSkipped();
889 void wxEvtHandler::Connect( int id
, int lastId
,
891 wxObjectEventFunction func
,
894 #if WXWIN_COMPATIBILITY_EVENT_TYPES
895 wxEventTableEntry
*entry
= new wxEventTableEntry
;
896 entry
->m_eventType
= eventType
;
898 entry
->m_lastId
= lastId
;
900 entry
->m_callbackUserData
= userData
;
901 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
902 wxDynamicEventTableEntry
*entry
=
903 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
);
904 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
906 if (!m_dynamicEvents
)
907 m_dynamicEvents
= new wxList
;
909 m_dynamicEvents
->Append( (wxObject
*) entry
);
912 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
913 wxObjectEventFunction func
,
916 if (!m_dynamicEvents
)
919 wxNode
*node
= m_dynamicEvents
->First();
922 #if WXWIN_COMPATIBILITY_EVENT_TYPES
923 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
924 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
925 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
926 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
928 if ((entry
->m_id
== id
) &&
929 ((entry
->m_lastId
== lastId
) || (lastId
== -1)) &&
930 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
931 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
932 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
934 if (entry
->m_callbackUserData
)
935 delete entry
->m_callbackUserData
;
936 m_dynamicEvents
->DeleteNode( node
);
945 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
947 wxCHECK_MSG( m_dynamicEvents
, FALSE
,
948 wxT("caller should check that we have dynamic events") );
950 int commandId
= event
.GetId();
952 wxNode
*node
= m_dynamicEvents
->First();
955 #if WXWIN_COMPATIBILITY_EVENT_TYPES
956 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
957 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
958 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
959 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
963 // Match, if event spec says any id will do (id == -1)
964 if ( (event
.GetEventType() == entry
->m_eventType
) &&
965 (entry
->m_id
== -1 ||
966 (entry
->m_lastId
== -1 && commandId
== entry
->m_id
) ||
967 (entry
->m_lastId
!= -1 &&
968 (commandId
>= entry
->m_id
&& commandId
<= entry
->m_lastId
))) )
971 event
.m_callbackUserData
= entry
->m_callbackUserData
;
973 (this->*((wxEventFunction
) (entry
->m_fn
)))(event
);
975 if (event
.GetSkipped())
986 void wxEvtHandler::DoSetClientObject( wxClientData
*data
)
988 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
989 wxT("can't have both object and void client data") );
991 if ( m_clientObject
)
992 delete m_clientObject
;
994 m_clientObject
= data
;
995 m_clientDataType
= wxClientData_Object
;
998 wxClientData
*wxEvtHandler::DoGetClientObject() const
1000 // it's not an error to call GetClientObject() on a window which doesn't
1001 // have client data at all - NULL will be returned
1002 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1003 wxT("this window doesn't have object client data") );
1005 return m_clientObject
;
1008 void wxEvtHandler::DoSetClientData( void *data
)
1010 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1011 wxT("can't have both object and void client data") );
1013 m_clientData
= data
;
1014 m_clientDataType
= wxClientData_Void
;
1017 void *wxEvtHandler::DoGetClientData() const
1019 // it's not an error to call GetClientData() on a window which doesn't have
1020 // client data at all - NULL will be returned
1021 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1022 wxT("this window doesn't have void client data") );
1024 return m_clientData
;
1028 #if WXWIN_COMPATIBILITY
1029 bool wxEvtHandler::OnClose()
1031 if (GetNextHandler())
1032 return GetNextHandler()->OnClose();
1036 #endif // WXWIN_COMPATIBILITY
1040 // Find a window with the focus, that is also a descendant of the given window.
1041 // This is used to determine the window to initially send commands to.
1042 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1044 // Process events starting with the window with the focus, if any.
1045 wxWindow
* focusWin
= wxWindow::FindFocus();
1046 wxWindow
* win
= focusWin
;
1048 // Check if this is a descendant of this frame.
1049 // If not, win will be set to NULL.
1052 if (win
== ancestor
)
1055 win
= win
->GetParent();
1057 if (win
== (wxWindow
*) NULL
)
1058 focusWin
= (wxWindow
*) NULL
;