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
)
55 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(wxEraseEvent
, wxEvent
)
67 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent
, wxEvent
)
68 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent
, wxEvent
)
69 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent
, wxEvent
)
70 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent
, wxEvent
)
71 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent
, wxEvent
)
72 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent
, wxEvent
)
73 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent
, wxEvent
)
74 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent
, wxEvent
)
75 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent
, wxEvent
)
76 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent
, wxEvent
)
77 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent
, wxEvent
)
78 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent
, wxEvent
)
79 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent
, wxCommandEvent
)
80 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent
, wxCommandEvent
)
81 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent
, wxEvent
)
82 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent
, wxEvent
)
83 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent
, wxEvent
)
84 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent
, wxEvent
)
85 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent
, wxCommandEvent
)
88 const wxEventTable
*wxEvtHandler::GetEventTable() const
89 { return &wxEvtHandler::sm_eventTable
; }
91 const wxEventTable
wxEvtHandler::sm_eventTable
=
92 { (const wxEventTable
*)NULL
, &wxEvtHandler::sm_eventTableEntries
[0] };
94 const wxEventTableEntry
wxEvtHandler::sm_eventTableEntries
[] =
95 { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL
, 0, 0, (wxObjectEventFunction
)NULL
, NULL
) };
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 // To put pending event handlers
102 wxList
*wxPendingEvents
= (wxList
*)NULL
;
105 // protects wxPendingEvents list
106 wxCriticalSection
*wxPendingEventsLocker
= (wxCriticalSection
*)NULL
;
109 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
111 // common event types are defined here, other event types are defined by the
112 // components which use them
114 DEFINE_EVENT_TYPE(wxEVT_NULL
)
115 DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED
)
116 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED
)
117 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED
)
118 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED
)
119 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
)
120 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
)
121 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_UPDATED
)
122 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_ENTER
)
123 DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED
)
124 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED
)
125 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED
)
126 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED
)
127 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED
)
128 DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED
)
129 DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED
)
130 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED
)
131 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER
)
132 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED
)
134 // Sockets and timers send events, too
135 DEFINE_EVENT_TYPE(wxEVT_SOCKET
)
136 DEFINE_EVENT_TYPE(wxEVT_TIMER
)
139 DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN
)
140 DEFINE_EVENT_TYPE(wxEVT_LEFT_UP
)
141 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN
)
142 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP
)
143 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN
)
144 DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP
)
145 DEFINE_EVENT_TYPE(wxEVT_MOTION
)
146 DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW
)
147 DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW
)
148 DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK
)
149 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK
)
150 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK
)
151 DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS
)
152 DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS
)
154 // Non-client mouse events
155 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN
)
156 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP
)
157 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN
)
158 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP
)
159 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN
)
160 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP
)
161 DEFINE_EVENT_TYPE(wxEVT_NC_MOTION
)
162 DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW
)
163 DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW
)
164 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK
)
165 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK
)
166 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK
)
168 // Character input event type
169 DEFINE_EVENT_TYPE(wxEVT_CHAR
)
170 DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK
)
171 DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY
)
172 DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN
)
173 DEFINE_EVENT_TYPE(wxEVT_KEY_UP
)
176 DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR
)
178 // wxScrollbar and wxSlider event identifiers
179 DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP
)
180 DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM
)
181 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP
)
182 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN
)
183 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP
)
184 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN
)
185 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK
)
186 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE
)
188 // Scroll events from wxWindow
189 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP
)
190 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM
)
191 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP
)
192 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN
)
193 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP
)
194 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN
)
195 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK
)
196 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE
)
199 DEFINE_EVENT_TYPE(wxEVT_SIZE
)
200 DEFINE_EVENT_TYPE(wxEVT_MOVE
)
201 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW
)
202 DEFINE_EVENT_TYPE(wxEVT_END_SESSION
)
203 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION
)
204 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
205 DEFINE_EVENT_TYPE(wxEVT_POWER
)
206 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
207 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
208 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
209 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
210 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
211 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
212 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
213 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
214 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
215 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
216 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
217 DEFINE_EVENT_TYPE(wxEVT_MENU_CHAR
)
218 DEFINE_EVENT_TYPE(wxEVT_MENU_INIT
)
219 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
220 DEFINE_EVENT_TYPE(wxEVT_POPUP_MENU_INIT
)
221 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
222 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
223 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
224 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
225 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
226 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
227 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
228 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
229 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
230 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
231 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
232 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
233 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
234 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
235 DEFINE_EVENT_TYPE(wxEVT_IDLE
)
236 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
238 // Generic command events
239 // Note: a click is a higher-level event than button down/up
240 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
241 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
242 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
243 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
244 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
245 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
246 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
249 DEFINE_EVENT_TYPE(wxEVT_HELP
)
250 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
252 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
254 // ============================================================================
256 // ============================================================================
258 // ----------------------------------------------------------------------------
259 // event initialization
260 // ----------------------------------------------------------------------------
265 static int s_lastUsedEventType
= wxEVT_FIRST
;
267 #if WXWIN_COMPATIBILITY_2
268 // check that we don't overlap with the user-defined types: if it does
269 // happen, the best solution is probably to update the existing code to
270 // use wxNewEventType() instead of wxEVT_USER_FIRST
272 // due to the uncertainty
273 wxASSERT_MSG( s_lastUsedEventType
< wxEVT_USER_FIRST
- 1,
274 _T("possible event type conflict") );
275 #endif // WXWIN_COMPATIBILITY_2
277 return s_lastUsedEventType
++;
280 // ----------------------------------------------------------------------------
282 // ----------------------------------------------------------------------------
285 * General wxWindows events, covering
286 * all interesting things that might happen (button clicking, resizing,
287 * setting text in widgets, etc.).
289 * For each completely new event type, derive a new event class.
293 wxEvent::wxEvent(int theId
)
295 m_eventType
= wxEVT_NULL
;
296 m_eventObject
= (wxObject
*) NULL
;
300 m_callbackUserData
= (wxObject
*) NULL
;
301 m_isCommandEvent
= FALSE
;
304 void wxEvent::CopyObject(wxObject
& object_dest
) const
306 wxEvent
*obj
= (wxEvent
*)&object_dest
;
307 wxObject::CopyObject(object_dest
);
309 obj
->m_eventType
= m_eventType
;
310 obj
->m_eventObject
= m_eventObject
;
311 obj
->m_timeStamp
= m_timeStamp
;
313 obj
->m_skipped
= m_skipped
;
314 obj
->m_callbackUserData
= m_callbackUserData
;
315 obj
->m_isCommandEvent
= m_isCommandEvent
;
325 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
327 m_eventType
= commandType
;
328 m_clientData
= (char *) NULL
;
329 m_clientObject
= (wxClientData
*) NULL
;
333 m_commandString
= wxEmptyString
;
334 m_isCommandEvent
= TRUE
;
337 void wxCommandEvent::CopyObject(wxObject
& obj_d
) const
339 wxCommandEvent
*obj
= (wxCommandEvent
*)&obj_d
;
341 wxEvent::CopyObject(obj_d
);
343 obj
->m_clientData
= m_clientData
;
344 obj
->m_clientObject
= m_clientObject
;
345 obj
->m_extraLong
= m_extraLong
;
346 obj
->m_commandInt
= m_commandInt
;
347 obj
->m_commandString
= m_commandString
;
354 void wxNotifyEvent::CopyObject(wxObject
& obj_d
) const
356 wxNotifyEvent
*obj
= (wxNotifyEvent
*)&obj_d
;
358 wxEvent::CopyObject(obj_d
);
360 if (!m_bAllow
) obj
->Veto();
367 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
371 : wxCommandEvent(commandType
, id
)
373 m_extraLong
= orient
;
381 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
385 m_eventType
= commandType
;
386 m_extraLong
= orient
;
390 void wxScrollWinEvent::CopyObject(wxObject
& obj_d
) const
392 wxScrollWinEvent
*obj
= (wxScrollWinEvent
*)&obj_d
;
394 wxEvent::CopyObject(obj_d
);
396 obj
->m_extraLong
= m_extraLong
;
397 obj
->m_commandInt
= m_commandInt
;
405 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
407 m_eventType
= commandType
;
410 m_controlDown
= FALSE
;
414 m_middleDown
= FALSE
;
419 void wxMouseEvent::CopyObject(wxObject
& obj_d
) const
421 wxMouseEvent
*obj
= (wxMouseEvent
*)&obj_d
;
423 wxEvent::CopyObject(obj_d
);
425 obj
->m_metaDown
= m_metaDown
;
426 obj
->m_altDown
= m_altDown
;
427 obj
->m_controlDown
= m_controlDown
;
428 obj
->m_shiftDown
= m_shiftDown
;
429 obj
->m_leftDown
= m_leftDown
;
430 obj
->m_rightDown
= m_rightDown
;
431 obj
->m_middleDown
= m_middleDown
;
436 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
437 // or any button dclick event (but = -1)
438 bool wxMouseEvent::ButtonDClick(int but
) const
443 return (LeftDClick() || MiddleDClick() || RightDClick());
447 return MiddleDClick();
449 return RightDClick();
451 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
457 // True if was a button down event (1 = left, 2 = middle, 3 = right)
458 // or any button down event (but = -1)
459 bool wxMouseEvent::ButtonDown(int but
) const
464 return (LeftDown() || MiddleDown() || RightDown());
472 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
478 // True if was a button up event (1 = left, 2 = middle, 3 = right)
479 // or any button up event (but = -1)
480 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
503 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
505 return (LeftDown() || LeftUp() || LeftDClick());
507 return (MiddleDown() || MiddleUp() || MiddleDClick());
509 return (RightDown() || RightUp() || RightDClick());
511 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
517 bool wxMouseEvent::ButtonIsDown(int but
) const
521 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
525 return MiddleIsDown();
527 return RightIsDown();
529 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
535 // Find the logical position of the event given the DC
536 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
538 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
548 wxKeyEvent::wxKeyEvent(wxEventType type
)
552 m_controlDown
= FALSE
;
559 void wxKeyEvent::CopyObject(wxObject
& obj_d
) const
561 wxKeyEvent
*obj
= (wxKeyEvent
*)&obj_d
;
562 wxEvent::CopyObject(obj_d
);
566 obj
->m_keyCode
= m_keyCode
;
568 obj
->m_shiftDown
= m_shiftDown
;
569 obj
->m_controlDown
= m_controlDown
;
570 obj
->m_metaDown
= m_metaDown
;
571 obj
->m_altDown
= m_altDown
;
572 obj
->m_keyCode
= m_keyCode
;
580 void wxSizeEvent::CopyObject(wxObject
& obj_d
) const
582 wxSizeEvent
*obj
= (wxSizeEvent
*)&obj_d
;
583 wxEvent::CopyObject(obj_d
);
585 obj
->m_size
= m_size
;
588 void wxMoveEvent::CopyObject(wxObject
& obj_d
) const
590 wxMoveEvent
*obj
= (wxMoveEvent
*)&obj_d
;
591 wxEvent::CopyObject(obj_d
);
596 void wxEraseEvent::CopyObject(wxObject
& obj_d
) const
598 wxEraseEvent
*obj
= (wxEraseEvent
*)&obj_d
;
599 wxEvent::CopyObject(obj_d
);
604 void wxActivateEvent::CopyObject(wxObject
& obj_d
) const
606 wxActivateEvent
*obj
= (wxActivateEvent
*)&obj_d
;
607 wxEvent::CopyObject(obj_d
);
609 obj
->m_active
= m_active
;
612 void wxMenuEvent::CopyObject(wxObject
& obj_d
) const
614 wxMenuEvent
*obj
= (wxMenuEvent
*)&obj_d
;
615 wxEvent::CopyObject(obj_d
);
617 obj
->m_menuId
= m_menuId
;
620 void wxCloseEvent::CopyObject(wxObject
& obj_d
) const
622 wxCloseEvent
*obj
= (wxCloseEvent
*)&obj_d
;
623 wxEvent::CopyObject(obj_d
);
625 obj
->m_loggingOff
= m_loggingOff
;
626 obj
->m_veto
= m_veto
;
627 #if WXWIN_COMPATIBILITY
628 obj
->m_force
= m_force
;
630 obj
->m_canVeto
= m_canVeto
;
633 void wxShowEvent::CopyObject(wxObject
& obj_d
) const
635 wxShowEvent
*obj
= (wxShowEvent
*)&obj_d
;
636 wxEvent::CopyObject(obj_d
);
638 obj
->m_show
= m_show
;
641 void wxJoystickEvent::CopyObject(wxObject
& obj_d
) const
643 wxJoystickEvent
*obj
= (wxJoystickEvent
*)&obj_d
;
644 wxEvent::CopyObject(obj_d
);
647 obj
->m_zPosition
= m_zPosition
;
648 obj
->m_buttonChange
= m_buttonChange
;
649 obj
->m_buttonState
= m_buttonState
;
650 obj
->m_joyStick
= m_joyStick
;
653 void wxDropFilesEvent::CopyObject(wxObject
& obj_d
) const
655 wxDropFilesEvent
*obj
= (wxDropFilesEvent
*)&obj_d
;
656 wxEvent::CopyObject(obj_d
);
658 obj
->m_noFiles
= m_noFiles
;
660 // TODO: Problem with obj->m_files. It should be deallocated by the
661 // destructor of the event.
664 void wxUpdateUIEvent::CopyObject(wxObject
&obj_d
) const
666 wxUpdateUIEvent
*obj
= (wxUpdateUIEvent
*)&obj_d
;
667 wxEvent::CopyObject(obj_d
);
669 obj
->m_checked
= m_checked
;
670 obj
->m_enabled
= m_enabled
;
671 obj
->m_text
= m_text
;
672 obj
->m_setText
= m_setText
;
673 obj
->m_setChecked
= m_setChecked
;
674 obj
->m_setEnabled
= m_setEnabled
;
677 void wxPaletteChangedEvent::CopyObject(wxObject
&obj_d
) const
679 wxPaletteChangedEvent
*obj
= (wxPaletteChangedEvent
*)&obj_d
;
680 wxEvent::CopyObject(obj_d
);
682 obj
->m_changedWindow
= m_changedWindow
;
685 void wxQueryNewPaletteEvent::CopyObject(wxObject
& obj_d
) const
687 wxQueryNewPaletteEvent
*obj
= (wxQueryNewPaletteEvent
*)&obj_d
;
688 wxEvent::CopyObject(obj_d
);
690 obj
->m_paletteRealized
= m_paletteRealized
;
693 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
695 SetEventType(wxEVT_CREATE
);
699 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
701 SetEventType(wxEVT_DESTROY
);
707 void wxIdleEvent::CopyObject(wxObject
& obj_d
) const
709 wxIdleEvent
*obj
= (wxIdleEvent
*)&obj_d
;
710 wxEvent::CopyObject(obj_d
);
712 obj
->m_requestMore
= m_requestMore
;
719 wxEvtHandler::wxEvtHandler()
721 m_nextHandler
= (wxEvtHandler
*) NULL
;
722 m_previousHandler
= (wxEvtHandler
*) NULL
;
724 m_dynamicEvents
= (wxList
*) NULL
;
726 m_pendingEvents
= (wxList
*) NULL
;
728 # if !defined(__VISAGECPP__)
729 m_eventsLocker
= new wxCriticalSection
;
734 wxEvtHandler::~wxEvtHandler()
736 // Takes itself out of the list of handlers
737 if (m_previousHandler
)
738 m_previousHandler
->m_nextHandler
= m_nextHandler
;
741 m_nextHandler
->m_previousHandler
= m_previousHandler
;
745 wxNode
*node
= m_dynamicEvents
->First();
748 #if WXWIN_COMPATIBILITY_EVENT_TYPES
749 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
750 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
751 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
752 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
754 if (entry
->m_callbackUserData
)
755 delete entry
->m_callbackUserData
;
759 delete m_dynamicEvents
;
762 delete m_pendingEvents
;
765 # if !defined(__VISAGECPP__)
766 delete m_eventsLocker
;
773 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
775 // check that we are really in a child thread
776 wxASSERT_MSG( !wxThread::IsMain(),
777 wxT("use ProcessEvent() in main thread") );
779 AddPendingEvent(event
);
784 #endif // wxUSE_THREADS
786 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
788 // 1) Add event to list of pending events of this event handler
790 #if defined(__VISAGECPP__)
791 wxENTER_CRIT_SECT( m_eventsLocker
);
793 wxENTER_CRIT_SECT( *m_eventsLocker
);
796 if ( !m_pendingEvents
)
797 m_pendingEvents
= new wxList
;
799 wxEvent
*event2
= (wxEvent
*)event
.Clone();
801 m_pendingEvents
->Append(event2
);
803 #if defined(__VISAGECPP__)
804 wxLEAVE_CRIT_SECT( m_eventsLocker
);
806 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
809 // 2) Add this event handler to list of event handlers that
810 // have pending events.
812 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
814 if ( !wxPendingEvents
)
815 wxPendingEvents
= new wxList
;
816 wxPendingEvents
->Append(this);
818 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
820 // 3) Inform the system that new pending events are somwehere,
821 // and that these should be processed in idle time.
825 void wxEvtHandler::ProcessPendingEvents()
827 #if defined(__VISAGECPP__)
828 wxENTER_CRIT_SECT( m_eventsLocker
);
830 wxENTER_CRIT_SECT( *m_eventsLocker
);
833 wxNode
*node
= m_pendingEvents
->First();
836 wxEvent
*event
= (wxEvent
*)node
->Data();
839 // In ProcessEvent, new events might get added and
840 // we can safely leave the crtical section here.
841 #if defined(__VISAGECPP__)
842 wxLEAVE_CRIT_SECT( m_eventsLocker
);
844 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
846 ProcessEvent(*event
);
848 #if defined(__VISAGECPP__)
849 wxENTER_CRIT_SECT( m_eventsLocker
);
851 wxENTER_CRIT_SECT( *m_eventsLocker
);
854 node
= m_pendingEvents
->First();
857 #if defined(__VISAGECPP__)
858 wxLEAVE_CRIT_SECT( m_eventsLocker
);
860 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
868 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
871 // check that our flag corresponds to reality
872 wxASSERT( m_isWindow
== IsKindOf(CLASSINFO(wxWindow
)) );
875 // An event handler can be enabled or disabled
876 if ( GetEvtHandlerEnabled() )
881 What is this? When using GUI threads, a non main
882 threads can send an event and process it itself.
883 This breaks GTK's GUI threads, so please explain.
886 // Check whether we are in a child thread.
887 if ( !wxThread::IsMain() )
888 return ProcessThreadEvent(event
);
891 // Handle per-instance dynamic event tables first
892 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
895 // Then static per-class event tables
896 const wxEventTable
*table
= GetEventTable();
898 #if wxUSE_GUI && wxUSE_VALIDATORS
899 // Try the associated validator first, if this is a window.
900 // Problem: if the event handler of the window has been replaced,
901 // this wxEvtHandler may no longer be a window.
902 // Therefore validators won't be processed if the handler
903 // has been replaced with SetEventHandler.
904 // THIS CAN BE CURED if PushEventHandler is used instead of
905 // SetEventHandler, and then processing will be passed down the
906 // chain of event handlers.
909 wxWindow
*win
= (wxWindow
*)this;
911 // Can only use the validator of the window which
912 // is receiving the event
913 if ( win
== event
.GetEventObject() )
915 wxValidator
*validator
= win
->GetValidator();
916 if ( validator
&& validator
->ProcessEvent(event
) )
924 // Search upwards through the inheritance hierarchy
927 if ( SearchEventTable((wxEventTable
&)*table
, event
) )
929 table
= table
->baseTable
;
933 // Try going down the event handler chain
934 if ( GetNextHandler() )
936 if ( GetNextHandler()->ProcessEvent(event
) )
941 // Carry on up the parent-child hierarchy,
942 // but only if event is a command event: it wouldn't
943 // make sense for a parent to receive a child's size event, for example
944 if ( m_isWindow
&& event
.IsCommandEvent() )
946 wxWindow
*win
= (wxWindow
*)this;
947 wxWindow
*parent
= win
->GetParent();
948 if (parent
&& !parent
->IsBeingDeleted())
949 return parent
->GetEventHandler()->ProcessEvent(event
);
953 // Last try - application object.
954 if ( wxTheApp
&& (this != wxTheApp
) )
956 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
957 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
958 // processed appropriately via SearchEventTable.
959 if ( event
.GetEventType() != wxEVT_IDLE
)
961 if ( wxTheApp
->ProcessEvent(event
) )
969 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
971 wxEventType eventType
= event
.GetEventType();
972 int eventId
= event
.GetId();
974 // BC++ doesn't like testing for m_fn without != 0
975 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
977 // the line using reference exposes a bug in gcc: although it _seems_
978 // to work, it leads to weird crashes later on during program
981 wxEventTableEntry entry
= table
.entries
[i
];
983 const wxEventTableEntry
& entry
= table
.entries
[i
];
986 // match only if the event type is the same and the id is either -1 in
987 // the event table (meaning "any") or the event id matches the id
988 // specified in the event table either exactly or by falling into
989 // range between first and last
990 if ( eventType
== entry
.m_eventType
)
992 int tableId1
= entry
.m_id
,
993 tableId2
= entry
.m_lastId
;
995 if ( (tableId1
== -1) ||
996 (tableId2
== -1 && eventId
== tableId1
) ||
998 (eventId
>= tableId1
&& eventId
<= tableId2
)) )
1001 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1003 (this->*((wxEventFunction
) (entry
.m_fn
)))(event
);
1005 return !event
.GetSkipped();
1013 void wxEvtHandler::Connect( int id
, int lastId
,
1015 wxObjectEventFunction func
,
1016 wxObject
*userData
)
1018 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1019 wxEventTableEntry
*entry
= new wxEventTableEntry
;
1020 entry
->m_eventType
= eventType
;
1022 entry
->m_lastId
= lastId
;
1024 entry
->m_callbackUserData
= userData
;
1025 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1026 wxDynamicEventTableEntry
*entry
=
1027 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
);
1028 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1030 if (!m_dynamicEvents
)
1031 m_dynamicEvents
= new wxList
;
1033 m_dynamicEvents
->Append( (wxObject
*) entry
);
1036 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1037 wxObjectEventFunction func
,
1038 wxObject
*userData
)
1040 if (!m_dynamicEvents
)
1043 wxNode
*node
= m_dynamicEvents
->First();
1046 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1047 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
1048 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1049 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
1050 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1052 if ((entry
->m_id
== id
) &&
1053 ((entry
->m_lastId
== lastId
) || (lastId
== -1)) &&
1054 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1055 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1056 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1058 if (entry
->m_callbackUserData
)
1059 delete entry
->m_callbackUserData
;
1060 m_dynamicEvents
->DeleteNode( node
);
1064 node
= node
->Next();
1069 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1071 wxCHECK_MSG( m_dynamicEvents
, FALSE
,
1072 wxT("caller should check that we have dynamic events") );
1074 int commandId
= event
.GetId();
1076 wxNode
*node
= m_dynamicEvents
->First();
1079 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1080 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
1081 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1082 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
1083 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1087 // Match, if event spec says any id will do (id == -1)
1088 if ( (event
.GetEventType() == entry
->m_eventType
) &&
1089 (entry
->m_id
== -1 ||
1090 (entry
->m_lastId
== -1 && commandId
== entry
->m_id
) ||
1091 (entry
->m_lastId
!= -1 &&
1092 (commandId
>= entry
->m_id
&& commandId
<= entry
->m_lastId
))) )
1095 event
.m_callbackUserData
= entry
->m_callbackUserData
;
1097 (this->*((wxEventFunction
) (entry
->m_fn
)))(event
);
1099 if (event
.GetSkipped())
1105 node
= node
->Next();
1110 #if WXWIN_COMPATIBILITY
1111 bool wxEvtHandler::OnClose()
1113 if (GetNextHandler())
1114 return GetNextHandler()->OnClose();
1118 #endif // WXWIN_COMPATIBILITY
1122 // Find a window with the focus, that is also a descendant of the given window.
1123 // This is used to determine the window to initially send commands to.
1124 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1126 // Process events starting with the window with the focus, if any.
1127 wxWindow
* focusWin
= wxWindow::FindFocus();
1128 wxWindow
* win
= focusWin
;
1130 // Check if this is a descendant of this frame.
1131 // If not, win will be set to NULL.
1134 if (win
== ancestor
)
1137 win
= win
->GetParent();
1139 if (win
== (wxWindow
*) NULL
)
1140 focusWin
= (wxWindow
*) NULL
;