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_COMMAND_BUTTON_CLICKED
)
115 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED
)
116 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED
)
117 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED
)
118 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
)
119 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
)
120 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_UPDATED
)
121 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_ENTER
)
122 DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED
)
123 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED
)
124 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED
)
125 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED
)
126 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED
)
127 DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED
)
128 DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED
)
129 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED
)
130 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER
)
131 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED
)
133 // Sockets and timers send events, too
134 DEFINE_EVENT_TYPE(wxEVT_SOCKET
)
135 DEFINE_EVENT_TYPE(wxEVT_TIMER
)
138 DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN
)
139 DEFINE_EVENT_TYPE(wxEVT_LEFT_UP
)
140 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN
)
141 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP
)
142 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN
)
143 DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP
)
144 DEFINE_EVENT_TYPE(wxEVT_MOTION
)
145 DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW
)
146 DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW
)
147 DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK
)
148 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK
)
149 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK
)
150 DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS
)
151 DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS
)
153 // Non-client mouse events
154 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN
)
155 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP
)
156 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN
)
157 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP
)
158 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN
)
159 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP
)
160 DEFINE_EVENT_TYPE(wxEVT_NC_MOTION
)
161 DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW
)
162 DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW
)
163 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK
)
164 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK
)
165 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK
)
167 // Character input event type
168 DEFINE_EVENT_TYPE(wxEVT_CHAR
)
169 DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK
)
170 DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY
)
171 DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN
)
172 DEFINE_EVENT_TYPE(wxEVT_KEY_UP
)
175 DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR
)
177 // wxScrollbar and wxSlider event identifiers
178 DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP
)
179 DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM
)
180 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP
)
181 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN
)
182 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP
)
183 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN
)
184 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK
)
185 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE
)
187 // Scroll events from wxWindow
188 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP
)
189 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM
)
190 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP
)
191 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN
)
192 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP
)
193 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN
)
194 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK
)
195 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE
)
198 DEFINE_EVENT_TYPE(wxEVT_SIZE
)
199 DEFINE_EVENT_TYPE(wxEVT_MOVE
)
200 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW
)
201 DEFINE_EVENT_TYPE(wxEVT_END_SESSION
)
202 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION
)
203 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
204 DEFINE_EVENT_TYPE(wxEVT_POWER
)
205 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
206 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
207 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
208 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
209 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
210 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
211 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
212 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
213 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
214 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
215 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
216 DEFINE_EVENT_TYPE(wxEVT_MENU_CHAR
)
217 DEFINE_EVENT_TYPE(wxEVT_MENU_INIT
)
218 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
219 DEFINE_EVENT_TYPE(wxEVT_POPUP_MENU_INIT
)
220 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
221 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
222 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
223 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
224 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
225 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
226 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
227 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
228 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
229 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
230 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
231 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
232 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
233 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
234 DEFINE_EVENT_TYPE(wxEVT_IDLE
)
235 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
237 // Generic command events
238 // Note: a click is a higher-level event than button down/up
239 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
240 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
241 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
242 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
243 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
244 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
245 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
248 DEFINE_EVENT_TYPE(wxEVT_HELP
)
249 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
251 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
253 // ============================================================================
255 // ============================================================================
257 // ----------------------------------------------------------------------------
258 // event initialization
259 // ----------------------------------------------------------------------------
264 static int s_lastUsedEventType
= wxEVT_FIRST
;
266 #if WXWIN_COMPATIBILITY_2
267 // check that we don't overlap with the user-defined types: if it does
268 // happen, the best solution is probably to update the existing code to
269 // use wxNewEventType() instead of wxEVT_USER_FIRST
271 // due to the uncertainty
272 wxASSERT_MSG( s_lastUsedEventType
< wxEVT_USER_FIRST
- 1,
273 _T("possible event type conflict") );
274 #endif // WXWIN_COMPATIBILITY_2
276 return s_lastUsedEventType
++;
279 // ----------------------------------------------------------------------------
281 // ----------------------------------------------------------------------------
284 * General wxWindows events, covering
285 * all interesting things that might happen (button clicking, resizing,
286 * setting text in widgets, etc.).
288 * For each completely new event type, derive a new event class.
292 wxEvent::wxEvent(int theId
)
294 m_eventType
= wxEVT_NULL
;
295 m_eventObject
= (wxObject
*) NULL
;
299 m_callbackUserData
= (wxObject
*) NULL
;
300 m_isCommandEvent
= FALSE
;
303 void wxEvent::CopyObject(wxObject
& object_dest
) const
305 wxEvent
*obj
= (wxEvent
*)&object_dest
;
306 wxObject::CopyObject(object_dest
);
308 obj
->m_eventType
= m_eventType
;
309 obj
->m_eventObject
= m_eventObject
;
310 obj
->m_timeStamp
= m_timeStamp
;
312 obj
->m_skipped
= m_skipped
;
313 obj
->m_callbackUserData
= m_callbackUserData
;
314 obj
->m_isCommandEvent
= m_isCommandEvent
;
324 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
326 m_eventType
= commandType
;
327 m_clientData
= (char *) NULL
;
328 m_clientObject
= (wxClientData
*) NULL
;
332 m_commandString
= wxEmptyString
;
333 m_isCommandEvent
= TRUE
;
336 void wxCommandEvent::CopyObject(wxObject
& obj_d
) const
338 wxCommandEvent
*obj
= (wxCommandEvent
*)&obj_d
;
340 wxEvent::CopyObject(obj_d
);
342 obj
->m_clientData
= m_clientData
;
343 obj
->m_clientObject
= m_clientObject
;
344 obj
->m_extraLong
= m_extraLong
;
345 obj
->m_commandInt
= m_commandInt
;
346 obj
->m_commandString
= m_commandString
;
353 void wxNotifyEvent::CopyObject(wxObject
& obj_d
) const
355 wxNotifyEvent
*obj
= (wxNotifyEvent
*)&obj_d
;
357 wxEvent::CopyObject(obj_d
);
359 if (!m_bAllow
) obj
->Veto();
366 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
370 : wxCommandEvent(commandType
, id
)
372 m_extraLong
= orient
;
380 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
384 m_eventType
= commandType
;
385 m_extraLong
= orient
;
389 void wxScrollWinEvent::CopyObject(wxObject
& obj_d
) const
391 wxScrollWinEvent
*obj
= (wxScrollWinEvent
*)&obj_d
;
393 wxEvent::CopyObject(obj_d
);
395 obj
->m_extraLong
= m_extraLong
;
396 obj
->m_commandInt
= m_commandInt
;
404 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
406 m_eventType
= commandType
;
409 m_controlDown
= FALSE
;
413 m_middleDown
= FALSE
;
418 void wxMouseEvent::CopyObject(wxObject
& obj_d
) const
420 wxMouseEvent
*obj
= (wxMouseEvent
*)&obj_d
;
422 wxEvent::CopyObject(obj_d
);
424 obj
->m_metaDown
= m_metaDown
;
425 obj
->m_altDown
= m_altDown
;
426 obj
->m_controlDown
= m_controlDown
;
427 obj
->m_shiftDown
= m_shiftDown
;
428 obj
->m_leftDown
= m_leftDown
;
429 obj
->m_rightDown
= m_rightDown
;
430 obj
->m_middleDown
= m_middleDown
;
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
483 return (LeftUp() || MiddleUp() || RightUp());
491 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
497 // True if the given button is currently changing state
498 bool wxMouseEvent::Button(int but
) const
502 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
504 return (LeftDown() || LeftUp() || LeftDClick());
506 return (MiddleDown() || MiddleUp() || MiddleDClick());
508 return (RightDown() || RightUp() || RightDClick());
510 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
516 bool wxMouseEvent::ButtonIsDown(int but
) const
520 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
524 return MiddleIsDown();
526 return RightIsDown();
528 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
534 // Find the logical position of the event given the DC
535 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
537 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
547 wxKeyEvent::wxKeyEvent(wxEventType type
)
551 m_controlDown
= FALSE
;
558 void wxKeyEvent::CopyObject(wxObject
& obj_d
) const
560 wxKeyEvent
*obj
= (wxKeyEvent
*)&obj_d
;
561 wxEvent::CopyObject(obj_d
);
565 obj
->m_keyCode
= m_keyCode
;
567 obj
->m_shiftDown
= m_shiftDown
;
568 obj
->m_controlDown
= m_controlDown
;
569 obj
->m_metaDown
= m_metaDown
;
570 obj
->m_altDown
= m_altDown
;
571 obj
->m_keyCode
= m_keyCode
;
579 void wxSizeEvent::CopyObject(wxObject
& obj_d
) const
581 wxSizeEvent
*obj
= (wxSizeEvent
*)&obj_d
;
582 wxEvent::CopyObject(obj_d
);
584 obj
->m_size
= m_size
;
587 void wxMoveEvent::CopyObject(wxObject
& obj_d
) const
589 wxMoveEvent
*obj
= (wxMoveEvent
*)&obj_d
;
590 wxEvent::CopyObject(obj_d
);
595 void wxEraseEvent::CopyObject(wxObject
& obj_d
) const
597 wxEraseEvent
*obj
= (wxEraseEvent
*)&obj_d
;
598 wxEvent::CopyObject(obj_d
);
603 void wxActivateEvent::CopyObject(wxObject
& obj_d
) const
605 wxActivateEvent
*obj
= (wxActivateEvent
*)&obj_d
;
606 wxEvent::CopyObject(obj_d
);
608 obj
->m_active
= m_active
;
611 void wxMenuEvent::CopyObject(wxObject
& obj_d
) const
613 wxMenuEvent
*obj
= (wxMenuEvent
*)&obj_d
;
614 wxEvent::CopyObject(obj_d
);
616 obj
->m_menuId
= m_menuId
;
619 void wxCloseEvent::CopyObject(wxObject
& obj_d
) const
621 wxCloseEvent
*obj
= (wxCloseEvent
*)&obj_d
;
622 wxEvent::CopyObject(obj_d
);
624 obj
->m_loggingOff
= m_loggingOff
;
625 obj
->m_veto
= m_veto
;
626 #if WXWIN_COMPATIBILITY
627 obj
->m_force
= m_force
;
629 obj
->m_canVeto
= m_canVeto
;
632 void wxShowEvent::CopyObject(wxObject
& obj_d
) const
634 wxShowEvent
*obj
= (wxShowEvent
*)&obj_d
;
635 wxEvent::CopyObject(obj_d
);
637 obj
->m_show
= m_show
;
640 void wxJoystickEvent::CopyObject(wxObject
& obj_d
) const
642 wxJoystickEvent
*obj
= (wxJoystickEvent
*)&obj_d
;
643 wxEvent::CopyObject(obj_d
);
646 obj
->m_zPosition
= m_zPosition
;
647 obj
->m_buttonChange
= m_buttonChange
;
648 obj
->m_buttonState
= m_buttonState
;
649 obj
->m_joyStick
= m_joyStick
;
652 void wxDropFilesEvent::CopyObject(wxObject
& obj_d
) const
654 wxDropFilesEvent
*obj
= (wxDropFilesEvent
*)&obj_d
;
655 wxEvent::CopyObject(obj_d
);
657 obj
->m_noFiles
= m_noFiles
;
659 // TODO: Problem with obj->m_files. It should be deallocated by the
660 // destructor of the event.
663 void wxUpdateUIEvent::CopyObject(wxObject
&obj_d
) const
665 wxUpdateUIEvent
*obj
= (wxUpdateUIEvent
*)&obj_d
;
666 wxEvent::CopyObject(obj_d
);
668 obj
->m_checked
= m_checked
;
669 obj
->m_enabled
= m_enabled
;
670 obj
->m_text
= m_text
;
671 obj
->m_setText
= m_setText
;
672 obj
->m_setChecked
= m_setChecked
;
673 obj
->m_setEnabled
= m_setEnabled
;
676 void wxPaletteChangedEvent::CopyObject(wxObject
&obj_d
) const
678 wxPaletteChangedEvent
*obj
= (wxPaletteChangedEvent
*)&obj_d
;
679 wxEvent::CopyObject(obj_d
);
681 obj
->m_changedWindow
= m_changedWindow
;
684 void wxQueryNewPaletteEvent::CopyObject(wxObject
& obj_d
) const
686 wxQueryNewPaletteEvent
*obj
= (wxQueryNewPaletteEvent
*)&obj_d
;
687 wxEvent::CopyObject(obj_d
);
689 obj
->m_paletteRealized
= m_paletteRealized
;
692 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
694 SetEventType(wxEVT_CREATE
);
698 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
700 SetEventType(wxEVT_DESTROY
);
706 void wxIdleEvent::CopyObject(wxObject
& obj_d
) const
708 wxIdleEvent
*obj
= (wxIdleEvent
*)&obj_d
;
709 wxEvent::CopyObject(obj_d
);
711 obj
->m_requestMore
= m_requestMore
;
718 wxEvtHandler::wxEvtHandler()
720 m_nextHandler
= (wxEvtHandler
*) NULL
;
721 m_previousHandler
= (wxEvtHandler
*) NULL
;
723 m_dynamicEvents
= (wxList
*) NULL
;
725 m_pendingEvents
= (wxList
*) NULL
;
727 # if !defined(__VISAGECPP__)
728 m_eventsLocker
= new wxCriticalSection
;
733 wxEvtHandler::~wxEvtHandler()
735 // Takes itself out of the list of handlers
736 if (m_previousHandler
)
737 m_previousHandler
->m_nextHandler
= m_nextHandler
;
740 m_nextHandler
->m_previousHandler
= m_previousHandler
;
744 wxNode
*node
= m_dynamicEvents
->First();
747 #if WXWIN_COMPATIBILITY_EVENT_TYPES
748 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
749 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
750 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
751 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
753 if (entry
->m_callbackUserData
)
754 delete entry
->m_callbackUserData
;
758 delete m_dynamicEvents
;
761 delete m_pendingEvents
;
764 # if !defined(__VISAGECPP__)
765 delete m_eventsLocker
;
772 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
774 // check that we are really in a child thread
775 wxASSERT_MSG( !wxThread::IsMain(),
776 wxT("use ProcessEvent() in main thread") );
778 AddPendingEvent(event
);
783 #endif // wxUSE_THREADS
785 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
787 // 1) Add event to list of pending events of this event handler
789 #if defined(__VISAGECPP__)
790 wxENTER_CRIT_SECT( m_eventsLocker
);
792 wxENTER_CRIT_SECT( *m_eventsLocker
);
795 if ( !m_pendingEvents
)
796 m_pendingEvents
= new wxList
;
798 wxEvent
*event2
= (wxEvent
*)event
.Clone();
800 m_pendingEvents
->Append(event2
);
802 #if defined(__VISAGECPP__)
803 wxLEAVE_CRIT_SECT( m_eventsLocker
);
805 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
808 // 2) Add this event handler to list of event handlers that
809 // have pending events.
811 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
813 if ( !wxPendingEvents
)
814 wxPendingEvents
= new wxList
;
815 wxPendingEvents
->Append(this);
817 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
819 // 3) Inform the system that new pending events are somwehere,
820 // and that these should be processed in idle time.
824 void wxEvtHandler::ProcessPendingEvents()
826 #if defined(__VISAGECPP__)
827 wxENTER_CRIT_SECT( m_eventsLocker
);
829 wxENTER_CRIT_SECT( *m_eventsLocker
);
832 wxNode
*node
= m_pendingEvents
->First();
835 wxEvent
*event
= (wxEvent
*)node
->Data();
838 // In ProcessEvent, new events might get added and
839 // we can safely leave the crtical section here.
840 #if defined(__VISAGECPP__)
841 wxLEAVE_CRIT_SECT( m_eventsLocker
);
843 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
845 ProcessEvent(*event
);
847 #if defined(__VISAGECPP__)
848 wxENTER_CRIT_SECT( m_eventsLocker
);
850 wxENTER_CRIT_SECT( *m_eventsLocker
);
853 node
= m_pendingEvents
->First();
856 #if defined(__VISAGECPP__)
857 wxLEAVE_CRIT_SECT( m_eventsLocker
);
859 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
867 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
870 // check that our flag corresponds to reality
871 wxASSERT( m_isWindow
== IsKindOf(CLASSINFO(wxWindow
)) );
874 // An event handler can be enabled or disabled
875 if ( GetEvtHandlerEnabled() )
880 What is this? When using GUI threads, a non main
881 threads can send an event and process it itself.
882 This breaks GTK's GUI threads, so please explain.
885 // Check whether we are in a child thread.
886 if ( !wxThread::IsMain() )
887 return ProcessThreadEvent(event
);
890 // Handle per-instance dynamic event tables first
891 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
894 // Then static per-class event tables
895 const wxEventTable
*table
= GetEventTable();
897 #if wxUSE_GUI && wxUSE_VALIDATORS
898 // Try the associated validator first, if this is a window.
899 // Problem: if the event handler of the window has been replaced,
900 // this wxEvtHandler may no longer be a window.
901 // Therefore validators won't be processed if the handler
902 // has been replaced with SetEventHandler.
903 // THIS CAN BE CURED if PushEventHandler is used instead of
904 // SetEventHandler, and then processing will be passed down the
905 // chain of event handlers.
908 wxWindow
*win
= (wxWindow
*)this;
910 // Can only use the validator of the window which
911 // is receiving the event
912 if ( win
== event
.GetEventObject() )
914 wxValidator
*validator
= win
->GetValidator();
915 if ( validator
&& validator
->ProcessEvent(event
) )
923 // Search upwards through the inheritance hierarchy
926 if ( SearchEventTable((wxEventTable
&)*table
, event
) )
928 table
= table
->baseTable
;
932 // Try going down the event handler chain
933 if ( GetNextHandler() )
935 if ( GetNextHandler()->ProcessEvent(event
) )
940 // Carry on up the parent-child hierarchy,
941 // but only if event is a command event: it wouldn't
942 // make sense for a parent to receive a child's size event, for example
943 if ( m_isWindow
&& event
.IsCommandEvent() )
945 wxWindow
*win
= (wxWindow
*)this;
946 wxWindow
*parent
= win
->GetParent();
947 if (parent
&& !parent
->IsBeingDeleted())
948 return parent
->GetEventHandler()->ProcessEvent(event
);
952 // Last try - application object.
953 if ( wxTheApp
&& (this != wxTheApp
) )
955 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
956 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
957 // processed appropriately via SearchEventTable.
958 if ( event
.GetEventType() != wxEVT_IDLE
)
960 if ( wxTheApp
->ProcessEvent(event
) )
968 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
970 wxEventType eventType
= event
.GetEventType();
971 int eventId
= event
.GetId();
973 // BC++ doesn't like testing for m_fn without != 0
974 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
976 // the line using reference exposes a bug in gcc: although it _seems_
977 // to work, it leads to weird crashes later on during program
980 wxEventTableEntry entry
= table
.entries
[i
];
982 const wxEventTableEntry
& entry
= table
.entries
[i
];
985 // match only if the event type is the same and the id is either -1 in
986 // the event table (meaning "any") or the event id matches the id
987 // specified in the event table either exactly or by falling into
988 // range between first and last
989 if ( eventType
== entry
.m_eventType
)
991 int tableId1
= entry
.m_id
,
992 tableId2
= entry
.m_lastId
;
994 if ( (tableId1
== -1) ||
995 (tableId2
== -1 && eventId
== tableId1
) ||
997 (eventId
>= tableId1
&& eventId
<= tableId2
)) )
1000 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1002 (this->*((wxEventFunction
) (entry
.m_fn
)))(event
);
1004 return !event
.GetSkipped();
1012 void wxEvtHandler::Connect( int id
, int lastId
,
1014 wxObjectEventFunction func
,
1015 wxObject
*userData
)
1017 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1018 wxEventTableEntry
*entry
= new wxEventTableEntry
;
1019 entry
->m_eventType
= eventType
;
1021 entry
->m_lastId
= lastId
;
1023 entry
->m_callbackUserData
= userData
;
1024 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1025 wxDynamicEventTableEntry
*entry
=
1026 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
);
1027 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1029 if (!m_dynamicEvents
)
1030 m_dynamicEvents
= new wxList
;
1032 m_dynamicEvents
->Append( (wxObject
*) entry
);
1035 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1036 wxObjectEventFunction func
,
1037 wxObject
*userData
)
1039 if (!m_dynamicEvents
)
1042 wxNode
*node
= m_dynamicEvents
->First();
1045 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1046 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
1047 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1048 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
1049 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1051 if ((entry
->m_id
== id
) &&
1052 ((entry
->m_lastId
== lastId
) || (lastId
== -1)) &&
1053 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1054 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1055 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1057 if (entry
->m_callbackUserData
)
1058 delete entry
->m_callbackUserData
;
1059 m_dynamicEvents
->DeleteNode( node
);
1063 node
= node
->Next();
1068 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1070 wxCHECK_MSG( m_dynamicEvents
, FALSE
,
1071 wxT("caller should check that we have dynamic events") );
1073 int commandId
= event
.GetId();
1075 wxNode
*node
= m_dynamicEvents
->First();
1078 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1079 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
1080 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1081 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
1082 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1086 // Match, if event spec says any id will do (id == -1)
1087 if ( (event
.GetEventType() == entry
->m_eventType
) &&
1088 (entry
->m_id
== -1 ||
1089 (entry
->m_lastId
== -1 && commandId
== entry
->m_id
) ||
1090 (entry
->m_lastId
!= -1 &&
1091 (commandId
>= entry
->m_id
&& commandId
<= entry
->m_lastId
))) )
1094 event
.m_callbackUserData
= entry
->m_callbackUserData
;
1096 (this->*((wxEventFunction
) (entry
->m_fn
)))(event
);
1098 if (event
.GetSkipped())
1104 node
= node
->Next();
1109 #if WXWIN_COMPATIBILITY
1110 bool wxEvtHandler::OnClose()
1112 if (GetNextHandler())
1113 return GetNextHandler()->OnClose();
1117 #endif // WXWIN_COMPATIBILITY
1121 // Find a window with the focus, that is also a descendant of the given window.
1122 // This is used to determine the window to initially send commands to.
1123 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1125 // Process events starting with the window with the focus, if any.
1126 wxWindow
* focusWin
= wxWindow::FindFocus();
1127 wxWindow
* win
= focusWin
;
1129 // Check if this is a descendant of this frame.
1130 // If not, win will be set to NULL.
1133 if (win
== ancestor
)
1136 win
= win
->GetParent();
1138 if (win
== (wxWindow
*) NULL
)
1139 focusWin
= (wxWindow
*) NULL
;