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(wxNcPaintEvent
, wxEvent
)
67 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent
, wxEvent
)
68 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent
, wxEvent
)
69 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent
, wxEvent
)
70 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent
, wxEvent
)
71 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent
, wxEvent
)
72 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent
, wxEvent
)
73 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent
, wxEvent
)
74 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent
, wxEvent
)
75 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent
, wxEvent
)
76 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent
, wxEvent
)
77 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent
, wxEvent
)
78 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent
, wxEvent
)
79 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent
, wxEvent
)
80 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent
, wxCommandEvent
)
81 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent
, wxCommandEvent
)
82 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent
, wxEvent
)
83 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent
, wxEvent
)
84 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent
, wxEvent
)
85 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent
, wxEvent
)
86 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent
, wxCommandEvent
)
87 IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent
, wxCommandEvent
)
90 const wxEventTable
*wxEvtHandler::GetEventTable() const
91 { return &wxEvtHandler::sm_eventTable
; }
93 const wxEventTable
wxEvtHandler::sm_eventTable
=
94 { (const wxEventTable
*)NULL
, &wxEvtHandler::sm_eventTableEntries
[0] };
96 const wxEventTableEntry
wxEvtHandler::sm_eventTableEntries
[] =
97 { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL
, 0, 0, (wxObjectEventFunction
)NULL
, NULL
) };
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 // To put pending event handlers
104 wxList
*wxPendingEvents
= (wxList
*)NULL
;
107 // protects wxPendingEvents list
108 wxCriticalSection
*wxPendingEventsLocker
= (wxCriticalSection
*)NULL
;
111 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
113 // common event types are defined here, other event types are defined by the
114 // components which use them
116 DEFINE_EVENT_TYPE(wxEVT_NULL
)
117 DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED
)
118 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED
)
119 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED
)
120 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED
)
121 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
)
122 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
)
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
)
153 DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL
)
155 // Non-client mouse events
156 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN
)
157 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP
)
158 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN
)
159 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP
)
160 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN
)
161 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP
)
162 DEFINE_EVENT_TYPE(wxEVT_NC_MOTION
)
163 DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW
)
164 DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW
)
165 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK
)
166 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK
)
167 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK
)
169 // Character input event type
170 DEFINE_EVENT_TYPE(wxEVT_CHAR
)
171 DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK
)
172 DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY
)
173 DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN
)
174 DEFINE_EVENT_TYPE(wxEVT_KEY_UP
)
177 DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR
)
179 // wxScrollbar and wxSlider event identifiers
180 DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP
)
181 DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM
)
182 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP
)
183 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN
)
184 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP
)
185 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN
)
186 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK
)
187 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE
)
189 // Scroll events from wxWindow
190 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP
)
191 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM
)
192 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP
)
193 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN
)
194 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP
)
195 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN
)
196 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK
)
197 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE
)
200 DEFINE_EVENT_TYPE(wxEVT_SIZE
)
201 DEFINE_EVENT_TYPE(wxEVT_MOVE
)
202 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW
)
203 DEFINE_EVENT_TYPE(wxEVT_END_SESSION
)
204 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION
)
205 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
206 DEFINE_EVENT_TYPE(wxEVT_POWER
)
207 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
208 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
209 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
210 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
211 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
212 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
213 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
214 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
215 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
216 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
217 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
218 DEFINE_EVENT_TYPE(wxEVT_MENU_CHAR
)
219 DEFINE_EVENT_TYPE(wxEVT_MENU_INIT
)
220 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
221 DEFINE_EVENT_TYPE(wxEVT_POPUP_MENU_INIT
)
222 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
223 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
224 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
225 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
226 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
227 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
228 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
229 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
230 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
231 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
232 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
233 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
234 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
235 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
236 DEFINE_EVENT_TYPE(wxEVT_IDLE
)
237 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
239 // Generic command events
240 // Note: a click is a higher-level event than button down/up
241 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
242 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
243 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
244 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
245 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
246 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
247 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
250 DEFINE_EVENT_TYPE(wxEVT_HELP
)
251 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
253 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
255 // ============================================================================
257 // ============================================================================
259 // ----------------------------------------------------------------------------
260 // event initialization
261 // ----------------------------------------------------------------------------
266 static int s_lastUsedEventType
= wxEVT_FIRST
;
268 #if WXWIN_COMPATIBILITY_2
269 // check that we don't overlap with the user-defined types: if it does
270 // happen, the best solution is probably to update the existing code to
271 // use wxNewEventType() instead of wxEVT_USER_FIRST
273 // due to the uncertainty
274 wxASSERT_MSG( s_lastUsedEventType
< wxEVT_USER_FIRST
- 1,
275 _T("possible event type conflict") );
276 #endif // WXWIN_COMPATIBILITY_2
278 return s_lastUsedEventType
++;
281 // ----------------------------------------------------------------------------
283 // ----------------------------------------------------------------------------
286 * General wxWindows events, covering
287 * all interesting things that might happen (button clicking, resizing,
288 * setting text in widgets, etc.).
290 * For each completely new event type, derive a new event class.
294 wxEvent::wxEvent(int theId
)
296 m_eventType
= wxEVT_NULL
;
297 m_eventObject
= (wxObject
*) NULL
;
301 m_callbackUserData
= (wxObject
*) NULL
;
302 m_isCommandEvent
= FALSE
;
305 void wxEvent::CopyObject(wxObject
& object_dest
) const
307 wxEvent
*obj
= (wxEvent
*)&object_dest
;
308 wxObject::CopyObject(object_dest
);
310 obj
->m_eventType
= m_eventType
;
311 obj
->m_eventObject
= m_eventObject
;
312 obj
->m_timeStamp
= m_timeStamp
;
314 obj
->m_skipped
= m_skipped
;
315 obj
->m_callbackUserData
= m_callbackUserData
;
316 obj
->m_isCommandEvent
= m_isCommandEvent
;
326 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
328 m_eventType
= commandType
;
329 m_clientData
= (char *) NULL
;
330 m_clientObject
= (wxClientData
*) NULL
;
334 m_commandString
= wxEmptyString
;
335 m_isCommandEvent
= TRUE
;
338 void wxCommandEvent::CopyObject(wxObject
& obj_d
) const
340 wxCommandEvent
*obj
= (wxCommandEvent
*)&obj_d
;
342 wxEvent::CopyObject(obj_d
);
344 obj
->m_clientData
= m_clientData
;
345 obj
->m_clientObject
= m_clientObject
;
346 obj
->m_extraLong
= m_extraLong
;
347 obj
->m_commandInt
= m_commandInt
;
348 obj
->m_commandString
= m_commandString
;
355 void wxNotifyEvent::CopyObject(wxObject
& obj_d
) const
357 wxNotifyEvent
*obj
= (wxNotifyEvent
*)&obj_d
;
359 wxEvent::CopyObject(obj_d
);
361 if (!m_bAllow
) obj
->Veto();
368 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
372 : wxCommandEvent(commandType
, id
)
374 m_extraLong
= orient
;
382 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
386 m_eventType
= commandType
;
387 m_extraLong
= orient
;
391 void wxScrollWinEvent::CopyObject(wxObject
& obj_d
) const
393 wxScrollWinEvent
*obj
= (wxScrollWinEvent
*)&obj_d
;
395 wxEvent::CopyObject(obj_d
);
397 obj
->m_extraLong
= m_extraLong
;
398 obj
->m_commandInt
= m_commandInt
;
406 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
408 m_eventType
= commandType
;
411 m_controlDown
= FALSE
;
415 m_middleDown
= FALSE
;
420 m_linesPerAction
= 0;
423 void wxMouseEvent::CopyObject(wxObject
& obj_d
) const
425 wxMouseEvent
*obj
= (wxMouseEvent
*)&obj_d
;
427 wxEvent::CopyObject(obj_d
);
429 obj
->m_metaDown
= m_metaDown
;
430 obj
->m_altDown
= m_altDown
;
431 obj
->m_controlDown
= m_controlDown
;
432 obj
->m_shiftDown
= m_shiftDown
;
433 obj
->m_leftDown
= m_leftDown
;
434 obj
->m_rightDown
= m_rightDown
;
435 obj
->m_middleDown
= m_middleDown
;
440 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
441 // or any button dclick event (but = -1)
442 bool wxMouseEvent::ButtonDClick(int but
) const
447 return (LeftDClick() || MiddleDClick() || RightDClick());
451 return MiddleDClick();
453 return RightDClick();
455 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
461 // True if was a button down event (1 = left, 2 = middle, 3 = right)
462 // or any button down event (but = -1)
463 bool wxMouseEvent::ButtonDown(int but
) const
468 return (LeftDown() || MiddleDown() || RightDown());
476 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
482 // True if was a button up event (1 = left, 2 = middle, 3 = right)
483 // or any button up event (but = -1)
484 bool wxMouseEvent::ButtonUp(int but
) const
489 return (LeftUp() || MiddleUp() || RightUp());
497 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
503 // True if the given button is currently changing state
504 bool wxMouseEvent::Button(int but
) const
509 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
511 return (LeftDown() || LeftUp() || LeftDClick());
513 return (MiddleDown() || MiddleUp() || MiddleDClick());
515 return (RightDown() || RightUp() || RightDClick());
517 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
523 bool wxMouseEvent::ButtonIsDown(int but
) const
528 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
532 return MiddleIsDown();
534 return RightIsDown();
536 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
542 int wxMouseEvent::GetButton() const
544 for ( int i
= 1; i
<= 3; i
++ )
555 // Find the logical position of the event given the DC
556 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
558 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
568 wxKeyEvent::wxKeyEvent(wxEventType type
)
572 m_controlDown
= FALSE
;
579 void wxKeyEvent::CopyObject(wxObject
& obj_d
) const
581 wxKeyEvent
*obj
= (wxKeyEvent
*)&obj_d
;
582 wxEvent::CopyObject(obj_d
);
586 obj
->m_keyCode
= m_keyCode
;
588 obj
->m_shiftDown
= m_shiftDown
;
589 obj
->m_controlDown
= m_controlDown
;
590 obj
->m_metaDown
= m_metaDown
;
591 obj
->m_altDown
= m_altDown
;
592 obj
->m_keyCode
= m_keyCode
;
600 void wxSizeEvent::CopyObject(wxObject
& obj_d
) const
602 wxSizeEvent
*obj
= (wxSizeEvent
*)&obj_d
;
603 wxEvent::CopyObject(obj_d
);
605 obj
->m_size
= m_size
;
608 void wxMoveEvent::CopyObject(wxObject
& obj_d
) const
610 wxMoveEvent
*obj
= (wxMoveEvent
*)&obj_d
;
611 wxEvent::CopyObject(obj_d
);
616 void wxEraseEvent::CopyObject(wxObject
& obj_d
) const
618 wxEraseEvent
*obj
= (wxEraseEvent
*)&obj_d
;
619 wxEvent::CopyObject(obj_d
);
624 void wxActivateEvent::CopyObject(wxObject
& obj_d
) const
626 wxActivateEvent
*obj
= (wxActivateEvent
*)&obj_d
;
627 wxEvent::CopyObject(obj_d
);
629 obj
->m_active
= m_active
;
632 void wxMenuEvent::CopyObject(wxObject
& obj_d
) const
634 wxMenuEvent
*obj
= (wxMenuEvent
*)&obj_d
;
635 wxEvent::CopyObject(obj_d
);
637 obj
->m_menuId
= m_menuId
;
640 void wxCloseEvent::CopyObject(wxObject
& obj_d
) const
642 wxCloseEvent
*obj
= (wxCloseEvent
*)&obj_d
;
643 wxEvent::CopyObject(obj_d
);
645 obj
->m_loggingOff
= m_loggingOff
;
646 obj
->m_veto
= m_veto
;
647 #if WXWIN_COMPATIBILITY
648 obj
->m_force
= m_force
;
650 obj
->m_canVeto
= m_canVeto
;
653 void wxShowEvent::CopyObject(wxObject
& obj_d
) const
655 wxShowEvent
*obj
= (wxShowEvent
*)&obj_d
;
656 wxEvent::CopyObject(obj_d
);
658 obj
->m_show
= m_show
;
661 void wxJoystickEvent::CopyObject(wxObject
& obj_d
) const
663 wxJoystickEvent
*obj
= (wxJoystickEvent
*)&obj_d
;
664 wxEvent::CopyObject(obj_d
);
667 obj
->m_zPosition
= m_zPosition
;
668 obj
->m_buttonChange
= m_buttonChange
;
669 obj
->m_buttonState
= m_buttonState
;
670 obj
->m_joyStick
= m_joyStick
;
673 void wxDropFilesEvent::CopyObject(wxObject
& obj_d
) const
675 wxDropFilesEvent
*obj
= (wxDropFilesEvent
*)&obj_d
;
676 wxEvent::CopyObject(obj_d
);
678 obj
->m_noFiles
= m_noFiles
;
680 // TODO: Problem with obj->m_files. It should be deallocated by the
681 // destructor of the event.
684 void wxUpdateUIEvent::CopyObject(wxObject
&obj_d
) const
686 wxUpdateUIEvent
*obj
= (wxUpdateUIEvent
*)&obj_d
;
687 wxEvent::CopyObject(obj_d
);
689 obj
->m_checked
= m_checked
;
690 obj
->m_enabled
= m_enabled
;
691 obj
->m_text
= m_text
;
692 obj
->m_setText
= m_setText
;
693 obj
->m_setChecked
= m_setChecked
;
694 obj
->m_setEnabled
= m_setEnabled
;
697 void wxPaletteChangedEvent::CopyObject(wxObject
&obj_d
) const
699 wxPaletteChangedEvent
*obj
= (wxPaletteChangedEvent
*)&obj_d
;
700 wxEvent::CopyObject(obj_d
);
702 obj
->m_changedWindow
= m_changedWindow
;
705 void wxQueryNewPaletteEvent::CopyObject(wxObject
& obj_d
) const
707 wxQueryNewPaletteEvent
*obj
= (wxQueryNewPaletteEvent
*)&obj_d
;
708 wxEvent::CopyObject(obj_d
);
710 obj
->m_paletteRealized
= m_paletteRealized
;
713 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
715 SetEventType(wxEVT_CREATE
);
719 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
721 SetEventType(wxEVT_DESTROY
);
727 void wxIdleEvent::CopyObject(wxObject
& obj_d
) const
729 wxIdleEvent
*obj
= (wxIdleEvent
*)&obj_d
;
730 wxEvent::CopyObject(obj_d
);
732 obj
->m_requestMore
= m_requestMore
;
739 wxEvtHandler::wxEvtHandler()
741 m_nextHandler
= (wxEvtHandler
*) NULL
;
742 m_previousHandler
= (wxEvtHandler
*) NULL
;
744 m_dynamicEvents
= (wxList
*) NULL
;
746 m_pendingEvents
= (wxList
*) NULL
;
748 # if !defined(__VISAGECPP__)
749 m_eventsLocker
= new wxCriticalSection
;
754 wxEvtHandler::~wxEvtHandler()
756 // Takes itself out of the list of handlers
757 if (m_previousHandler
)
758 m_previousHandler
->m_nextHandler
= m_nextHandler
;
761 m_nextHandler
->m_previousHandler
= m_previousHandler
;
765 wxNode
*node
= m_dynamicEvents
->First();
768 #if WXWIN_COMPATIBILITY_EVENT_TYPES
769 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
770 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
771 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
772 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
774 if (entry
->m_callbackUserData
)
775 delete entry
->m_callbackUserData
;
779 delete m_dynamicEvents
;
782 delete m_pendingEvents
;
785 # if !defined(__VISAGECPP__)
786 delete m_eventsLocker
;
793 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
795 // check that we are really in a child thread
796 wxASSERT_MSG( !wxThread::IsMain(),
797 wxT("use ProcessEvent() in main thread") );
799 AddPendingEvent(event
);
804 #endif // wxUSE_THREADS
806 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
808 // 1) Add event to list of pending events of this event handler
810 #if defined(__VISAGECPP__)
811 wxENTER_CRIT_SECT( m_eventsLocker
);
813 wxENTER_CRIT_SECT( *m_eventsLocker
);
816 if ( !m_pendingEvents
)
817 m_pendingEvents
= new wxList
;
819 wxEvent
*event2
= (wxEvent
*)event
.Clone();
821 m_pendingEvents
->Append(event2
);
823 #if defined(__VISAGECPP__)
824 wxLEAVE_CRIT_SECT( m_eventsLocker
);
826 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
829 // 2) Add this event handler to list of event handlers that
830 // have pending events.
832 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
834 if ( !wxPendingEvents
)
835 wxPendingEvents
= new wxList
;
836 wxPendingEvents
->Append(this);
838 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
840 // 3) Inform the system that new pending events are somwehere,
841 // and that these should be processed in idle time.
845 void wxEvtHandler::ProcessPendingEvents()
847 #if defined(__VISAGECPP__)
848 wxENTER_CRIT_SECT( m_eventsLocker
);
850 wxENTER_CRIT_SECT( *m_eventsLocker
);
853 wxNode
*node
= m_pendingEvents
->First();
856 wxEvent
*event
= (wxEvent
*)node
->Data();
859 // In ProcessEvent, new events might get added and
860 // we can safely leave the crtical section here.
861 #if defined(__VISAGECPP__)
862 wxLEAVE_CRIT_SECT( m_eventsLocker
);
864 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
866 ProcessEvent(*event
);
868 #if defined(__VISAGECPP__)
869 wxENTER_CRIT_SECT( m_eventsLocker
);
871 wxENTER_CRIT_SECT( *m_eventsLocker
);
874 node
= m_pendingEvents
->First();
877 #if defined(__VISAGECPP__)
878 wxLEAVE_CRIT_SECT( m_eventsLocker
);
880 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
888 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
892 // We have to use the actual window or processing events from wxWindowNative
893 // destructor won't work (we don't see the wxWindow class)
895 // check that our flag corresponds to reality
896 wxClassInfo
* info
= NULL
;
897 #ifdef __WXUNIVERSAL__
898 # if defined(__WXMSW__)
899 info
= CLASSINFO(wxWindowMSW
);
900 # elif defined(__WXGTK__)
901 info
= CLASSINFO(wxWindowGTK
);
902 # elif defined(__WXMGL__)
903 info
= CLASSINFO(wxWindowMGL
);
904 # elif defined(__WXMAC__)
905 info
= CLASSINFO(wxWindowMac
);
906 # elif defined(__WXMOTIF__)
907 info
= CLASSINFO(wxWindowMotif
);
910 info
= CLASSINFO(wxWindow
);
913 wxASSERT_MSG( m_isWindow
== IsKindOf(info
),
914 _T("this should [not] be a window but it is [not]") );
919 // An event handler can be enabled or disabled
920 if ( GetEvtHandlerEnabled() )
925 What is this? When using GUI threads, a non main
926 threads can send an event and process it itself.
927 This breaks GTK's GUI threads, so please explain.
930 // Check whether we are in a child thread.
931 if ( !wxThread::IsMain() )
932 return ProcessThreadEvent(event
);
935 // Handle per-instance dynamic event tables first
936 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
939 // Then static per-class event tables
940 const wxEventTable
*table
= GetEventTable();
942 #if wxUSE_GUI && wxUSE_VALIDATORS
943 // Try the associated validator first, if this is a window.
944 // Problem: if the event handler of the window has been replaced,
945 // this wxEvtHandler may no longer be a window.
946 // Therefore validators won't be processed if the handler
947 // has been replaced with SetEventHandler.
948 // THIS CAN BE CURED if PushEventHandler is used instead of
949 // SetEventHandler, and then processing will be passed down the
950 // chain of event handlers.
953 wxWindow
*win
= (wxWindow
*)this;
955 // Can only use the validator of the window which
956 // is receiving the event
957 if ( win
== event
.GetEventObject() )
959 wxValidator
*validator
= win
->GetValidator();
960 if ( validator
&& validator
->ProcessEvent(event
) )
968 // Search upwards through the inheritance hierarchy
971 if ( SearchEventTable((wxEventTable
&)*table
, event
) )
973 table
= table
->baseTable
;
977 // Try going down the event handler chain
978 if ( GetNextHandler() )
980 if ( GetNextHandler()->ProcessEvent(event
) )
985 // Carry on up the parent-child hierarchy, but only if event is a command
986 // event: it wouldn't make sense for a parent to receive a child's size
987 // event, for example
988 if ( m_isWindow
&& event
.IsCommandEvent() )
990 wxWindow
*win
= (wxWindow
*)this;
992 // also, don't propagate events beyond the first top level window: it
993 // doesn't make sense to process dialogs events in the parent frame
994 if ( !win
->IsTopLevel() )
996 wxWindow
*parent
= win
->GetParent();
997 if (parent
&& !parent
->IsBeingDeleted())
998 return parent
->GetEventHandler()->ProcessEvent(event
);
1003 // Last try - application object.
1004 if ( wxTheApp
&& (this != wxTheApp
) )
1006 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1007 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1008 // processed appropriately via SearchEventTable.
1009 if ( event
.GetEventType() != wxEVT_IDLE
)
1011 if ( wxTheApp
->ProcessEvent(event
) )
1019 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
1021 wxEventType eventType
= event
.GetEventType();
1022 int eventId
= event
.GetId();
1024 // BC++ doesn't like testing for m_fn without != 0
1025 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
1027 // the line using reference exposes a bug in gcc: although it _seems_
1028 // to work, it leads to weird crashes later on during program
1031 wxEventTableEntry entry
= table
.entries
[i
];
1033 const wxEventTableEntry
& entry
= table
.entries
[i
];
1036 // match only if the event type is the same and the id is either -1 in
1037 // the event table (meaning "any") or the event id matches the id
1038 // specified in the event table either exactly or by falling into
1039 // range between first and last
1040 if ( eventType
== entry
.m_eventType
)
1042 int tableId1
= entry
.m_id
,
1043 tableId2
= entry
.m_lastId
;
1045 if ( (tableId1
== -1) ||
1046 (tableId2
== -1 && eventId
== tableId1
) ||
1048 (eventId
>= tableId1
&& eventId
<= tableId2
)) )
1051 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1053 (this->*((wxEventFunction
) (entry
.m_fn
)))(event
);
1055 return !event
.GetSkipped();
1063 void wxEvtHandler::Connect( int id
, int lastId
,
1065 wxObjectEventFunction func
,
1066 wxObject
*userData
)
1068 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1069 wxEventTableEntry
*entry
= new wxEventTableEntry
;
1070 entry
->m_eventType
= eventType
;
1072 entry
->m_lastId
= lastId
;
1074 entry
->m_callbackUserData
= userData
;
1075 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1076 wxDynamicEventTableEntry
*entry
=
1077 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
);
1078 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1080 if (!m_dynamicEvents
)
1081 m_dynamicEvents
= new wxList
;
1083 m_dynamicEvents
->Append( (wxObject
*) entry
);
1086 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1087 wxObjectEventFunction func
,
1088 wxObject
*userData
)
1090 if (!m_dynamicEvents
)
1093 wxNode
*node
= m_dynamicEvents
->First();
1096 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1097 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
1098 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1099 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
1100 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1102 if ((entry
->m_id
== id
) &&
1103 ((entry
->m_lastId
== lastId
) || (lastId
== -1)) &&
1104 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1105 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1106 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1108 if (entry
->m_callbackUserData
)
1109 delete entry
->m_callbackUserData
;
1110 m_dynamicEvents
->DeleteNode( node
);
1114 node
= node
->Next();
1119 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1121 wxCHECK_MSG( m_dynamicEvents
, FALSE
,
1122 wxT("caller should check that we have dynamic events") );
1124 int commandId
= event
.GetId();
1126 wxNode
*node
= m_dynamicEvents
->First();
1129 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1130 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
1131 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1132 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
1133 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1137 // Match, if event spec says any id will do (id == -1)
1138 if ( (event
.GetEventType() == entry
->m_eventType
) &&
1139 (entry
->m_id
== -1 ||
1140 (entry
->m_lastId
== -1 && commandId
== entry
->m_id
) ||
1141 (entry
->m_lastId
!= -1 &&
1142 (commandId
>= entry
->m_id
&& commandId
<= entry
->m_lastId
))) )
1145 event
.m_callbackUserData
= entry
->m_callbackUserData
;
1147 (this->*((wxEventFunction
) (entry
->m_fn
)))(event
);
1149 if (event
.GetSkipped())
1155 node
= node
->Next();
1160 #if WXWIN_COMPATIBILITY
1161 bool wxEvtHandler::OnClose()
1163 if (GetNextHandler())
1164 return GetNextHandler()->OnClose();
1168 #endif // WXWIN_COMPATIBILITY
1172 // Find a window with the focus, that is also a descendant of the given window.
1173 // This is used to determine the window to initially send commands to.
1174 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1176 // Process events starting with the window with the focus, if any.
1177 wxWindow
* focusWin
= wxWindow::FindFocus();
1178 wxWindow
* win
= focusWin
;
1180 // Check if this is a descendant of this frame.
1181 // If not, win will be set to NULL.
1184 if (win
== ancestor
)
1187 win
= win
->GetParent();
1189 if (win
== (wxWindow
*) NULL
)
1190 focusWin
= (wxWindow
*) NULL
;