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
)
86 IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent
, wxCommandEvent
)
89 const wxEventTable
*wxEvtHandler::GetEventTable() const
90 { return &wxEvtHandler::sm_eventTable
; }
92 const wxEventTable
wxEvtHandler::sm_eventTable
=
93 { (const wxEventTable
*)NULL
, &wxEvtHandler::sm_eventTableEntries
[0] };
95 const wxEventTableEntry
wxEvtHandler::sm_eventTableEntries
[] =
96 { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL
, 0, 0, (wxObjectEventFunction
)NULL
, NULL
) };
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 // To put pending event handlers
103 wxList
*wxPendingEvents
= (wxList
*)NULL
;
106 // protects wxPendingEvents list
107 wxCriticalSection
*wxPendingEventsLocker
= (wxCriticalSection
*)NULL
;
110 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
112 // common event types are defined here, other event types are defined by the
113 // components which use them
115 DEFINE_EVENT_TYPE(wxEVT_NULL
)
116 DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED
)
117 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED
)
118 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED
)
119 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED
)
120 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
)
121 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
)
122 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_UPDATED
)
123 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_ENTER
)
124 DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED
)
125 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED
)
126 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED
)
127 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED
)
128 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED
)
129 DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED
)
130 DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED
)
131 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED
)
132 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER
)
133 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED
)
135 // Sockets and timers send events, too
136 DEFINE_EVENT_TYPE(wxEVT_SOCKET
)
137 DEFINE_EVENT_TYPE(wxEVT_TIMER
)
140 DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN
)
141 DEFINE_EVENT_TYPE(wxEVT_LEFT_UP
)
142 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN
)
143 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP
)
144 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN
)
145 DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP
)
146 DEFINE_EVENT_TYPE(wxEVT_MOTION
)
147 DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW
)
148 DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW
)
149 DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK
)
150 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK
)
151 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK
)
152 DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS
)
153 DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS
)
154 DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL
)
156 // Non-client mouse events
157 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN
)
158 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP
)
159 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN
)
160 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP
)
161 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN
)
162 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP
)
163 DEFINE_EVENT_TYPE(wxEVT_NC_MOTION
)
164 DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW
)
165 DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW
)
166 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK
)
167 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK
)
168 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK
)
170 // Character input event type
171 DEFINE_EVENT_TYPE(wxEVT_CHAR
)
172 DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK
)
173 DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY
)
174 DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN
)
175 DEFINE_EVENT_TYPE(wxEVT_KEY_UP
)
178 DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR
)
180 // wxScrollbar and wxSlider event identifiers
181 DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP
)
182 DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM
)
183 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP
)
184 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN
)
185 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP
)
186 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN
)
187 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK
)
188 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE
)
190 // Scroll events from wxWindow
191 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP
)
192 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM
)
193 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP
)
194 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN
)
195 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP
)
196 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN
)
197 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK
)
198 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE
)
201 DEFINE_EVENT_TYPE(wxEVT_SIZE
)
202 DEFINE_EVENT_TYPE(wxEVT_MOVE
)
203 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW
)
204 DEFINE_EVENT_TYPE(wxEVT_END_SESSION
)
205 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION
)
206 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
207 DEFINE_EVENT_TYPE(wxEVT_POWER
)
208 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
209 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
210 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
211 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
212 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
213 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
214 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
215 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
216 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
217 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
218 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
219 DEFINE_EVENT_TYPE(wxEVT_MENU_CHAR
)
220 DEFINE_EVENT_TYPE(wxEVT_MENU_INIT
)
221 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
222 DEFINE_EVENT_TYPE(wxEVT_POPUP_MENU_INIT
)
223 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
224 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
225 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
226 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
227 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
228 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
229 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
230 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
231 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
232 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
233 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
234 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
235 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
236 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
237 DEFINE_EVENT_TYPE(wxEVT_IDLE
)
238 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
240 // Generic command events
241 // Note: a click is a higher-level event than button down/up
242 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
243 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
244 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
245 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
246 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
247 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
248 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
251 DEFINE_EVENT_TYPE(wxEVT_HELP
)
252 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
254 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
256 // ============================================================================
258 // ============================================================================
260 // ----------------------------------------------------------------------------
261 // event initialization
262 // ----------------------------------------------------------------------------
267 static int s_lastUsedEventType
= wxEVT_FIRST
;
269 #if WXWIN_COMPATIBILITY_2
270 // check that we don't overlap with the user-defined types: if it does
271 // happen, the best solution is probably to update the existing code to
272 // use wxNewEventType() instead of wxEVT_USER_FIRST
274 // due to the uncertainty
275 wxASSERT_MSG( s_lastUsedEventType
< wxEVT_USER_FIRST
- 1,
276 _T("possible event type conflict") );
277 #endif // WXWIN_COMPATIBILITY_2
279 return s_lastUsedEventType
++;
282 // ----------------------------------------------------------------------------
284 // ----------------------------------------------------------------------------
287 * General wxWindows events, covering
288 * all interesting things that might happen (button clicking, resizing,
289 * setting text in widgets, etc.).
291 * For each completely new event type, derive a new event class.
295 wxEvent::wxEvent(int theId
)
297 m_eventType
= wxEVT_NULL
;
298 m_eventObject
= (wxObject
*) NULL
;
302 m_callbackUserData
= (wxObject
*) NULL
;
303 m_isCommandEvent
= FALSE
;
306 void wxEvent::CopyObject(wxObject
& object_dest
) const
308 wxEvent
*obj
= (wxEvent
*)&object_dest
;
309 wxObject::CopyObject(object_dest
);
311 obj
->m_eventType
= m_eventType
;
312 obj
->m_eventObject
= m_eventObject
;
313 obj
->m_timeStamp
= m_timeStamp
;
315 obj
->m_skipped
= m_skipped
;
316 obj
->m_callbackUserData
= m_callbackUserData
;
317 obj
->m_isCommandEvent
= m_isCommandEvent
;
327 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
329 m_eventType
= commandType
;
330 m_clientData
= (char *) NULL
;
331 m_clientObject
= (wxClientData
*) NULL
;
335 m_commandString
= wxEmptyString
;
336 m_isCommandEvent
= TRUE
;
339 void wxCommandEvent::CopyObject(wxObject
& obj_d
) const
341 wxCommandEvent
*obj
= (wxCommandEvent
*)&obj_d
;
343 wxEvent::CopyObject(obj_d
);
345 obj
->m_clientData
= m_clientData
;
346 obj
->m_clientObject
= m_clientObject
;
347 obj
->m_extraLong
= m_extraLong
;
348 obj
->m_commandInt
= m_commandInt
;
349 obj
->m_commandString
= m_commandString
;
356 void wxNotifyEvent::CopyObject(wxObject
& obj_d
) const
358 wxNotifyEvent
*obj
= (wxNotifyEvent
*)&obj_d
;
360 wxEvent::CopyObject(obj_d
);
362 if (!m_bAllow
) obj
->Veto();
369 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
373 : wxCommandEvent(commandType
, id
)
375 m_extraLong
= orient
;
383 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
387 m_eventType
= commandType
;
388 m_extraLong
= orient
;
392 void wxScrollWinEvent::CopyObject(wxObject
& obj_d
) const
394 wxScrollWinEvent
*obj
= (wxScrollWinEvent
*)&obj_d
;
396 wxEvent::CopyObject(obj_d
);
398 obj
->m_extraLong
= m_extraLong
;
399 obj
->m_commandInt
= m_commandInt
;
407 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
409 m_eventType
= commandType
;
412 m_controlDown
= FALSE
;
416 m_middleDown
= FALSE
;
421 m_linesPerAction
= 0;
424 void wxMouseEvent::CopyObject(wxObject
& obj_d
) const
426 wxMouseEvent
*obj
= (wxMouseEvent
*)&obj_d
;
428 wxEvent::CopyObject(obj_d
);
430 obj
->m_metaDown
= m_metaDown
;
431 obj
->m_altDown
= m_altDown
;
432 obj
->m_controlDown
= m_controlDown
;
433 obj
->m_shiftDown
= m_shiftDown
;
434 obj
->m_leftDown
= m_leftDown
;
435 obj
->m_rightDown
= m_rightDown
;
436 obj
->m_middleDown
= m_middleDown
;
441 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
442 // or any button dclick event (but = -1)
443 bool wxMouseEvent::ButtonDClick(int but
) const
448 return (LeftDClick() || MiddleDClick() || RightDClick());
452 return MiddleDClick();
454 return RightDClick();
456 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
462 // True if was a button down event (1 = left, 2 = middle, 3 = right)
463 // or any button down event (but = -1)
464 bool wxMouseEvent::ButtonDown(int but
) const
469 return (LeftDown() || MiddleDown() || RightDown());
477 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
483 // True if was a button up event (1 = left, 2 = middle, 3 = right)
484 // or any button up event (but = -1)
485 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
508 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
510 return (LeftDown() || LeftUp() || LeftDClick());
512 return (MiddleDown() || MiddleUp() || MiddleDClick());
514 return (RightDown() || RightUp() || RightDClick());
516 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
522 bool wxMouseEvent::ButtonIsDown(int but
) const
526 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
530 return MiddleIsDown();
532 return RightIsDown();
534 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
540 // Find the logical position of the event given the DC
541 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
543 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
553 wxKeyEvent::wxKeyEvent(wxEventType type
)
557 m_controlDown
= FALSE
;
564 void wxKeyEvent::CopyObject(wxObject
& obj_d
) const
566 wxKeyEvent
*obj
= (wxKeyEvent
*)&obj_d
;
567 wxEvent::CopyObject(obj_d
);
571 obj
->m_keyCode
= m_keyCode
;
573 obj
->m_shiftDown
= m_shiftDown
;
574 obj
->m_controlDown
= m_controlDown
;
575 obj
->m_metaDown
= m_metaDown
;
576 obj
->m_altDown
= m_altDown
;
577 obj
->m_keyCode
= m_keyCode
;
585 void wxSizeEvent::CopyObject(wxObject
& obj_d
) const
587 wxSizeEvent
*obj
= (wxSizeEvent
*)&obj_d
;
588 wxEvent::CopyObject(obj_d
);
590 obj
->m_size
= m_size
;
593 void wxMoveEvent::CopyObject(wxObject
& obj_d
) const
595 wxMoveEvent
*obj
= (wxMoveEvent
*)&obj_d
;
596 wxEvent::CopyObject(obj_d
);
601 void wxEraseEvent::CopyObject(wxObject
& obj_d
) const
603 wxEraseEvent
*obj
= (wxEraseEvent
*)&obj_d
;
604 wxEvent::CopyObject(obj_d
);
609 void wxActivateEvent::CopyObject(wxObject
& obj_d
) const
611 wxActivateEvent
*obj
= (wxActivateEvent
*)&obj_d
;
612 wxEvent::CopyObject(obj_d
);
614 obj
->m_active
= m_active
;
617 void wxMenuEvent::CopyObject(wxObject
& obj_d
) const
619 wxMenuEvent
*obj
= (wxMenuEvent
*)&obj_d
;
620 wxEvent::CopyObject(obj_d
);
622 obj
->m_menuId
= m_menuId
;
625 void wxCloseEvent::CopyObject(wxObject
& obj_d
) const
627 wxCloseEvent
*obj
= (wxCloseEvent
*)&obj_d
;
628 wxEvent::CopyObject(obj_d
);
630 obj
->m_loggingOff
= m_loggingOff
;
631 obj
->m_veto
= m_veto
;
632 #if WXWIN_COMPATIBILITY
633 obj
->m_force
= m_force
;
635 obj
->m_canVeto
= m_canVeto
;
638 void wxShowEvent::CopyObject(wxObject
& obj_d
) const
640 wxShowEvent
*obj
= (wxShowEvent
*)&obj_d
;
641 wxEvent::CopyObject(obj_d
);
643 obj
->m_show
= m_show
;
646 void wxJoystickEvent::CopyObject(wxObject
& obj_d
) const
648 wxJoystickEvent
*obj
= (wxJoystickEvent
*)&obj_d
;
649 wxEvent::CopyObject(obj_d
);
652 obj
->m_zPosition
= m_zPosition
;
653 obj
->m_buttonChange
= m_buttonChange
;
654 obj
->m_buttonState
= m_buttonState
;
655 obj
->m_joyStick
= m_joyStick
;
658 void wxDropFilesEvent::CopyObject(wxObject
& obj_d
) const
660 wxDropFilesEvent
*obj
= (wxDropFilesEvent
*)&obj_d
;
661 wxEvent::CopyObject(obj_d
);
663 obj
->m_noFiles
= m_noFiles
;
665 // TODO: Problem with obj->m_files. It should be deallocated by the
666 // destructor of the event.
669 void wxUpdateUIEvent::CopyObject(wxObject
&obj_d
) const
671 wxUpdateUIEvent
*obj
= (wxUpdateUIEvent
*)&obj_d
;
672 wxEvent::CopyObject(obj_d
);
674 obj
->m_checked
= m_checked
;
675 obj
->m_enabled
= m_enabled
;
676 obj
->m_text
= m_text
;
677 obj
->m_setText
= m_setText
;
678 obj
->m_setChecked
= m_setChecked
;
679 obj
->m_setEnabled
= m_setEnabled
;
682 void wxPaletteChangedEvent::CopyObject(wxObject
&obj_d
) const
684 wxPaletteChangedEvent
*obj
= (wxPaletteChangedEvent
*)&obj_d
;
685 wxEvent::CopyObject(obj_d
);
687 obj
->m_changedWindow
= m_changedWindow
;
690 void wxQueryNewPaletteEvent::CopyObject(wxObject
& obj_d
) const
692 wxQueryNewPaletteEvent
*obj
= (wxQueryNewPaletteEvent
*)&obj_d
;
693 wxEvent::CopyObject(obj_d
);
695 obj
->m_paletteRealized
= m_paletteRealized
;
698 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
700 SetEventType(wxEVT_CREATE
);
704 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
706 SetEventType(wxEVT_DESTROY
);
712 void wxIdleEvent::CopyObject(wxObject
& obj_d
) const
714 wxIdleEvent
*obj
= (wxIdleEvent
*)&obj_d
;
715 wxEvent::CopyObject(obj_d
);
717 obj
->m_requestMore
= m_requestMore
;
724 wxEvtHandler::wxEvtHandler()
726 m_nextHandler
= (wxEvtHandler
*) NULL
;
727 m_previousHandler
= (wxEvtHandler
*) NULL
;
729 m_dynamicEvents
= (wxList
*) NULL
;
731 m_pendingEvents
= (wxList
*) NULL
;
733 # if !defined(__VISAGECPP__)
734 m_eventsLocker
= new wxCriticalSection
;
739 wxEvtHandler::~wxEvtHandler()
741 // Takes itself out of the list of handlers
742 if (m_previousHandler
)
743 m_previousHandler
->m_nextHandler
= m_nextHandler
;
746 m_nextHandler
->m_previousHandler
= m_previousHandler
;
750 wxNode
*node
= m_dynamicEvents
->First();
753 #if WXWIN_COMPATIBILITY_EVENT_TYPES
754 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
755 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
756 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
757 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
759 if (entry
->m_callbackUserData
)
760 delete entry
->m_callbackUserData
;
764 delete m_dynamicEvents
;
767 delete m_pendingEvents
;
770 # if !defined(__VISAGECPP__)
771 delete m_eventsLocker
;
778 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
780 // check that we are really in a child thread
781 wxASSERT_MSG( !wxThread::IsMain(),
782 wxT("use ProcessEvent() in main thread") );
784 AddPendingEvent(event
);
789 #endif // wxUSE_THREADS
791 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
793 // 1) Add event to list of pending events of this event handler
795 #if defined(__VISAGECPP__)
796 wxENTER_CRIT_SECT( m_eventsLocker
);
798 wxENTER_CRIT_SECT( *m_eventsLocker
);
801 if ( !m_pendingEvents
)
802 m_pendingEvents
= new wxList
;
804 wxEvent
*event2
= (wxEvent
*)event
.Clone();
806 m_pendingEvents
->Append(event2
);
808 #if defined(__VISAGECPP__)
809 wxLEAVE_CRIT_SECT( m_eventsLocker
);
811 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
814 // 2) Add this event handler to list of event handlers that
815 // have pending events.
817 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
819 if ( !wxPendingEvents
)
820 wxPendingEvents
= new wxList
;
821 wxPendingEvents
->Append(this);
823 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
825 // 3) Inform the system that new pending events are somwehere,
826 // and that these should be processed in idle time.
830 void wxEvtHandler::ProcessPendingEvents()
832 #if defined(__VISAGECPP__)
833 wxENTER_CRIT_SECT( m_eventsLocker
);
835 wxENTER_CRIT_SECT( *m_eventsLocker
);
838 wxNode
*node
= m_pendingEvents
->First();
841 wxEvent
*event
= (wxEvent
*)node
->Data();
844 // In ProcessEvent, new events might get added and
845 // we can safely leave the crtical section here.
846 #if defined(__VISAGECPP__)
847 wxLEAVE_CRIT_SECT( m_eventsLocker
);
849 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
851 ProcessEvent(*event
);
853 #if defined(__VISAGECPP__)
854 wxENTER_CRIT_SECT( m_eventsLocker
);
856 wxENTER_CRIT_SECT( *m_eventsLocker
);
859 node
= m_pendingEvents
->First();
862 #if defined(__VISAGECPP__)
863 wxLEAVE_CRIT_SECT( m_eventsLocker
);
865 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
873 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
876 // check that our flag corresponds to reality
877 wxASSERT( m_isWindow
== IsKindOf(CLASSINFO(wxWindow
)) );
880 // An event handler can be enabled or disabled
881 if ( GetEvtHandlerEnabled() )
886 What is this? When using GUI threads, a non main
887 threads can send an event and process it itself.
888 This breaks GTK's GUI threads, so please explain.
891 // Check whether we are in a child thread.
892 if ( !wxThread::IsMain() )
893 return ProcessThreadEvent(event
);
896 // Handle per-instance dynamic event tables first
897 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
900 // Then static per-class event tables
901 const wxEventTable
*table
= GetEventTable();
903 #if wxUSE_GUI && wxUSE_VALIDATORS
904 // Try the associated validator first, if this is a window.
905 // Problem: if the event handler of the window has been replaced,
906 // this wxEvtHandler may no longer be a window.
907 // Therefore validators won't be processed if the handler
908 // has been replaced with SetEventHandler.
909 // THIS CAN BE CURED if PushEventHandler is used instead of
910 // SetEventHandler, and then processing will be passed down the
911 // chain of event handlers.
914 wxWindow
*win
= (wxWindow
*)this;
916 // Can only use the validator of the window which
917 // is receiving the event
918 if ( win
== event
.GetEventObject() )
920 wxValidator
*validator
= win
->GetValidator();
921 if ( validator
&& validator
->ProcessEvent(event
) )
929 // Search upwards through the inheritance hierarchy
932 if ( SearchEventTable((wxEventTable
&)*table
, event
) )
934 table
= table
->baseTable
;
938 // Try going down the event handler chain
939 if ( GetNextHandler() )
941 if ( GetNextHandler()->ProcessEvent(event
) )
946 // Carry on up the parent-child hierarchy, but only if event is a command
947 // event: it wouldn't make sense for a parent to receive a child's size
948 // event, for example
949 if ( m_isWindow
&& event
.IsCommandEvent() )
951 wxWindow
*win
= (wxWindow
*)this;
953 // also, don't propagate events beyond the first top level window: it
954 // doesn't make sense to process dialogs events in the parent frame
955 if ( !win
->IsTopLevel() )
957 wxWindow
*parent
= win
->GetParent();
958 if (parent
&& !parent
->IsBeingDeleted())
959 return parent
->GetEventHandler()->ProcessEvent(event
);
964 // Last try - application object.
965 if ( wxTheApp
&& (this != wxTheApp
) )
967 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
968 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
969 // processed appropriately via SearchEventTable.
970 if ( event
.GetEventType() != wxEVT_IDLE
)
972 if ( wxTheApp
->ProcessEvent(event
) )
980 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
982 wxEventType eventType
= event
.GetEventType();
983 int eventId
= event
.GetId();
985 // BC++ doesn't like testing for m_fn without != 0
986 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
988 // the line using reference exposes a bug in gcc: although it _seems_
989 // to work, it leads to weird crashes later on during program
992 wxEventTableEntry entry
= table
.entries
[i
];
994 const wxEventTableEntry
& entry
= table
.entries
[i
];
997 // match only if the event type is the same and the id is either -1 in
998 // the event table (meaning "any") or the event id matches the id
999 // specified in the event table either exactly or by falling into
1000 // range between first and last
1001 if ( eventType
== entry
.m_eventType
)
1003 int tableId1
= entry
.m_id
,
1004 tableId2
= entry
.m_lastId
;
1006 if ( (tableId1
== -1) ||
1007 (tableId2
== -1 && eventId
== tableId1
) ||
1009 (eventId
>= tableId1
&& eventId
<= tableId2
)) )
1012 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1014 (this->*((wxEventFunction
) (entry
.m_fn
)))(event
);
1016 return !event
.GetSkipped();
1024 void wxEvtHandler::Connect( int id
, int lastId
,
1026 wxObjectEventFunction func
,
1027 wxObject
*userData
)
1029 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1030 wxEventTableEntry
*entry
= new wxEventTableEntry
;
1031 entry
->m_eventType
= eventType
;
1033 entry
->m_lastId
= lastId
;
1035 entry
->m_callbackUserData
= userData
;
1036 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1037 wxDynamicEventTableEntry
*entry
=
1038 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
);
1039 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1041 if (!m_dynamicEvents
)
1042 m_dynamicEvents
= new wxList
;
1044 m_dynamicEvents
->Append( (wxObject
*) entry
);
1047 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1048 wxObjectEventFunction func
,
1049 wxObject
*userData
)
1051 if (!m_dynamicEvents
)
1054 wxNode
*node
= m_dynamicEvents
->First();
1057 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1058 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
1059 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1060 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
1061 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1063 if ((entry
->m_id
== id
) &&
1064 ((entry
->m_lastId
== lastId
) || (lastId
== -1)) &&
1065 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1066 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1067 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1069 if (entry
->m_callbackUserData
)
1070 delete entry
->m_callbackUserData
;
1071 m_dynamicEvents
->DeleteNode( node
);
1075 node
= node
->Next();
1080 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1082 wxCHECK_MSG( m_dynamicEvents
, FALSE
,
1083 wxT("caller should check that we have dynamic events") );
1085 int commandId
= event
.GetId();
1087 wxNode
*node
= m_dynamicEvents
->First();
1090 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1091 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
1092 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1093 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
1094 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1098 // Match, if event spec says any id will do (id == -1)
1099 if ( (event
.GetEventType() == entry
->m_eventType
) &&
1100 (entry
->m_id
== -1 ||
1101 (entry
->m_lastId
== -1 && commandId
== entry
->m_id
) ||
1102 (entry
->m_lastId
!= -1 &&
1103 (commandId
>= entry
->m_id
&& commandId
<= entry
->m_lastId
))) )
1106 event
.m_callbackUserData
= entry
->m_callbackUserData
;
1108 (this->*((wxEventFunction
) (entry
->m_fn
)))(event
);
1110 if (event
.GetSkipped())
1116 node
= node
->Next();
1121 #if WXWIN_COMPATIBILITY
1122 bool wxEvtHandler::OnClose()
1124 if (GetNextHandler())
1125 return GetNextHandler()->OnClose();
1129 #endif // WXWIN_COMPATIBILITY
1133 // Find a window with the focus, that is also a descendant of the given window.
1134 // This is used to determine the window to initially send commands to.
1135 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1137 // Process events starting with the window with the focus, if any.
1138 wxWindow
* focusWin
= wxWindow::FindFocus();
1139 wxWindow
* win
= focusWin
;
1141 // Check if this is a descendant of this frame.
1142 // If not, win will be set to NULL.
1145 if (win
== ancestor
)
1148 win
= win
->GetParent();
1150 if (win
== (wxWindow
*) NULL
)
1151 focusWin
= (wxWindow
*) NULL
;