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_TEXT_UPDATED
)
124 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_ENTER
)
125 DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED
)
126 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED
)
127 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED
)
128 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED
)
129 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED
)
130 DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED
)
131 DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED
)
132 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED
)
133 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER
)
134 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED
)
136 // Sockets and timers send events, too
137 DEFINE_EVENT_TYPE(wxEVT_SOCKET
)
138 DEFINE_EVENT_TYPE(wxEVT_TIMER
)
141 DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN
)
142 DEFINE_EVENT_TYPE(wxEVT_LEFT_UP
)
143 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN
)
144 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP
)
145 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN
)
146 DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP
)
147 DEFINE_EVENT_TYPE(wxEVT_MOTION
)
148 DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW
)
149 DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW
)
150 DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK
)
151 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK
)
152 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK
)
153 DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS
)
154 DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS
)
155 DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL
)
157 // Non-client mouse events
158 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN
)
159 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP
)
160 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN
)
161 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP
)
162 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN
)
163 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP
)
164 DEFINE_EVENT_TYPE(wxEVT_NC_MOTION
)
165 DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW
)
166 DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW
)
167 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK
)
168 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK
)
169 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK
)
171 // Character input event type
172 DEFINE_EVENT_TYPE(wxEVT_CHAR
)
173 DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK
)
174 DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY
)
175 DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN
)
176 DEFINE_EVENT_TYPE(wxEVT_KEY_UP
)
179 DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR
)
181 // wxScrollbar and wxSlider event identifiers
182 DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP
)
183 DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM
)
184 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP
)
185 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN
)
186 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP
)
187 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN
)
188 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK
)
189 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE
)
191 // Scroll events from wxWindow
192 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP
)
193 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM
)
194 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP
)
195 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN
)
196 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP
)
197 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN
)
198 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK
)
199 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE
)
202 DEFINE_EVENT_TYPE(wxEVT_SIZE
)
203 DEFINE_EVENT_TYPE(wxEVT_MOVE
)
204 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW
)
205 DEFINE_EVENT_TYPE(wxEVT_END_SESSION
)
206 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION
)
207 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
208 DEFINE_EVENT_TYPE(wxEVT_POWER
)
209 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
210 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
211 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
212 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
213 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
214 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
215 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
216 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
217 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
218 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
219 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
220 DEFINE_EVENT_TYPE(wxEVT_MENU_CHAR
)
221 DEFINE_EVENT_TYPE(wxEVT_MENU_INIT
)
222 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
223 DEFINE_EVENT_TYPE(wxEVT_POPUP_MENU_INIT
)
224 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
225 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
226 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
227 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
228 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
229 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
230 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
231 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
232 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
233 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
234 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
235 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
236 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
237 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
238 DEFINE_EVENT_TYPE(wxEVT_IDLE
)
239 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
241 // Generic command events
242 // Note: a click is a higher-level event than button down/up
243 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
244 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
245 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
246 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
247 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
248 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
249 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
252 DEFINE_EVENT_TYPE(wxEVT_HELP
)
253 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
255 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
257 // ============================================================================
259 // ============================================================================
261 // ----------------------------------------------------------------------------
262 // event initialization
263 // ----------------------------------------------------------------------------
268 static int s_lastUsedEventType
= wxEVT_FIRST
;
270 #if WXWIN_COMPATIBILITY_2
271 // check that we don't overlap with the user-defined types: if it does
272 // happen, the best solution is probably to update the existing code to
273 // use wxNewEventType() instead of wxEVT_USER_FIRST
275 // due to the uncertainty
276 wxASSERT_MSG( s_lastUsedEventType
< wxEVT_USER_FIRST
- 1,
277 _T("possible event type conflict") );
278 #endif // WXWIN_COMPATIBILITY_2
280 return s_lastUsedEventType
++;
283 // ----------------------------------------------------------------------------
285 // ----------------------------------------------------------------------------
288 * General wxWindows events, covering
289 * all interesting things that might happen (button clicking, resizing,
290 * setting text in widgets, etc.).
292 * For each completely new event type, derive a new event class.
296 wxEvent::wxEvent(int theId
)
298 m_eventType
= wxEVT_NULL
;
299 m_eventObject
= (wxObject
*) NULL
;
303 m_callbackUserData
= (wxObject
*) NULL
;
304 m_isCommandEvent
= FALSE
;
307 void wxEvent::CopyObject(wxObject
& object_dest
) const
309 wxEvent
*obj
= (wxEvent
*)&object_dest
;
310 wxObject::CopyObject(object_dest
);
312 obj
->m_eventType
= m_eventType
;
313 obj
->m_eventObject
= m_eventObject
;
314 obj
->m_timeStamp
= m_timeStamp
;
316 obj
->m_skipped
= m_skipped
;
317 obj
->m_callbackUserData
= m_callbackUserData
;
318 obj
->m_isCommandEvent
= m_isCommandEvent
;
328 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
330 m_eventType
= commandType
;
331 m_clientData
= (char *) NULL
;
332 m_clientObject
= (wxClientData
*) NULL
;
336 m_commandString
= wxEmptyString
;
337 m_isCommandEvent
= TRUE
;
340 void wxCommandEvent::CopyObject(wxObject
& obj_d
) const
342 wxCommandEvent
*obj
= (wxCommandEvent
*)&obj_d
;
344 wxEvent::CopyObject(obj_d
);
346 obj
->m_clientData
= m_clientData
;
347 obj
->m_clientObject
= m_clientObject
;
348 obj
->m_extraLong
= m_extraLong
;
349 obj
->m_commandInt
= m_commandInt
;
350 obj
->m_commandString
= m_commandString
;
357 void wxNotifyEvent::CopyObject(wxObject
& obj_d
) const
359 wxNotifyEvent
*obj
= (wxNotifyEvent
*)&obj_d
;
361 wxEvent::CopyObject(obj_d
);
363 if (!m_bAllow
) obj
->Veto();
370 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
374 : wxCommandEvent(commandType
, id
)
376 m_extraLong
= orient
;
384 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
388 m_eventType
= commandType
;
389 m_extraLong
= orient
;
393 void wxScrollWinEvent::CopyObject(wxObject
& obj_d
) const
395 wxScrollWinEvent
*obj
= (wxScrollWinEvent
*)&obj_d
;
397 wxEvent::CopyObject(obj_d
);
399 obj
->m_extraLong
= m_extraLong
;
400 obj
->m_commandInt
= m_commandInt
;
408 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
410 m_eventType
= commandType
;
413 m_controlDown
= FALSE
;
417 m_middleDown
= FALSE
;
422 m_linesPerAction
= 0;
425 void wxMouseEvent::CopyObject(wxObject
& obj_d
) const
427 wxMouseEvent
*obj
= (wxMouseEvent
*)&obj_d
;
429 wxEvent::CopyObject(obj_d
);
431 obj
->m_metaDown
= m_metaDown
;
432 obj
->m_altDown
= m_altDown
;
433 obj
->m_controlDown
= m_controlDown
;
434 obj
->m_shiftDown
= m_shiftDown
;
435 obj
->m_leftDown
= m_leftDown
;
436 obj
->m_rightDown
= m_rightDown
;
437 obj
->m_middleDown
= m_middleDown
;
442 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
443 // or any button dclick event (but = -1)
444 bool wxMouseEvent::ButtonDClick(int but
) const
449 return (LeftDClick() || MiddleDClick() || RightDClick());
453 return MiddleDClick();
455 return RightDClick();
457 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
463 // True if was a button down event (1 = left, 2 = middle, 3 = right)
464 // or any button down event (but = -1)
465 bool wxMouseEvent::ButtonDown(int but
) const
470 return (LeftDown() || MiddleDown() || RightDown());
478 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
484 // True if was a button up event (1 = left, 2 = middle, 3 = right)
485 // or any button up event (but = -1)
486 bool wxMouseEvent::ButtonUp(int but
) const
491 return (LeftUp() || MiddleUp() || RightUp());
499 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
505 // True if the given button is currently changing state
506 bool wxMouseEvent::Button(int but
) const
511 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
513 return (LeftDown() || LeftUp() || LeftDClick());
515 return (MiddleDown() || MiddleUp() || MiddleDClick());
517 return (RightDown() || RightUp() || RightDClick());
519 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
525 bool wxMouseEvent::ButtonIsDown(int but
) const
530 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
534 return MiddleIsDown();
536 return RightIsDown();
538 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
544 int wxMouseEvent::GetButton() const
546 for ( int i
= 1; i
<= 3; i
++ )
557 // Find the logical position of the event given the DC
558 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
560 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
570 wxKeyEvent::wxKeyEvent(wxEventType type
)
574 m_controlDown
= FALSE
;
581 void wxKeyEvent::CopyObject(wxObject
& obj_d
) const
583 wxKeyEvent
*obj
= (wxKeyEvent
*)&obj_d
;
584 wxEvent::CopyObject(obj_d
);
588 obj
->m_keyCode
= m_keyCode
;
590 obj
->m_shiftDown
= m_shiftDown
;
591 obj
->m_controlDown
= m_controlDown
;
592 obj
->m_metaDown
= m_metaDown
;
593 obj
->m_altDown
= m_altDown
;
594 obj
->m_keyCode
= m_keyCode
;
602 void wxSizeEvent::CopyObject(wxObject
& obj_d
) const
604 wxSizeEvent
*obj
= (wxSizeEvent
*)&obj_d
;
605 wxEvent::CopyObject(obj_d
);
607 obj
->m_size
= m_size
;
610 void wxMoveEvent::CopyObject(wxObject
& obj_d
) const
612 wxMoveEvent
*obj
= (wxMoveEvent
*)&obj_d
;
613 wxEvent::CopyObject(obj_d
);
618 void wxEraseEvent::CopyObject(wxObject
& obj_d
) const
620 wxEraseEvent
*obj
= (wxEraseEvent
*)&obj_d
;
621 wxEvent::CopyObject(obj_d
);
626 void wxActivateEvent::CopyObject(wxObject
& obj_d
) const
628 wxActivateEvent
*obj
= (wxActivateEvent
*)&obj_d
;
629 wxEvent::CopyObject(obj_d
);
631 obj
->m_active
= m_active
;
634 void wxMenuEvent::CopyObject(wxObject
& obj_d
) const
636 wxMenuEvent
*obj
= (wxMenuEvent
*)&obj_d
;
637 wxEvent::CopyObject(obj_d
);
639 obj
->m_menuId
= m_menuId
;
642 void wxCloseEvent::CopyObject(wxObject
& obj_d
) const
644 wxCloseEvent
*obj
= (wxCloseEvent
*)&obj_d
;
645 wxEvent::CopyObject(obj_d
);
647 obj
->m_loggingOff
= m_loggingOff
;
648 obj
->m_veto
= m_veto
;
649 #if WXWIN_COMPATIBILITY
650 obj
->m_force
= m_force
;
652 obj
->m_canVeto
= m_canVeto
;
655 void wxShowEvent::CopyObject(wxObject
& obj_d
) const
657 wxShowEvent
*obj
= (wxShowEvent
*)&obj_d
;
658 wxEvent::CopyObject(obj_d
);
660 obj
->m_show
= m_show
;
663 void wxJoystickEvent::CopyObject(wxObject
& obj_d
) const
665 wxJoystickEvent
*obj
= (wxJoystickEvent
*)&obj_d
;
666 wxEvent::CopyObject(obj_d
);
669 obj
->m_zPosition
= m_zPosition
;
670 obj
->m_buttonChange
= m_buttonChange
;
671 obj
->m_buttonState
= m_buttonState
;
672 obj
->m_joyStick
= m_joyStick
;
675 void wxDropFilesEvent::CopyObject(wxObject
& obj_d
) const
677 wxDropFilesEvent
*obj
= (wxDropFilesEvent
*)&obj_d
;
678 wxEvent::CopyObject(obj_d
);
680 obj
->m_noFiles
= m_noFiles
;
682 // TODO: Problem with obj->m_files. It should be deallocated by the
683 // destructor of the event.
686 void wxUpdateUIEvent::CopyObject(wxObject
&obj_d
) const
688 wxUpdateUIEvent
*obj
= (wxUpdateUIEvent
*)&obj_d
;
689 wxEvent::CopyObject(obj_d
);
691 obj
->m_checked
= m_checked
;
692 obj
->m_enabled
= m_enabled
;
693 obj
->m_text
= m_text
;
694 obj
->m_setText
= m_setText
;
695 obj
->m_setChecked
= m_setChecked
;
696 obj
->m_setEnabled
= m_setEnabled
;
699 void wxPaletteChangedEvent::CopyObject(wxObject
&obj_d
) const
701 wxPaletteChangedEvent
*obj
= (wxPaletteChangedEvent
*)&obj_d
;
702 wxEvent::CopyObject(obj_d
);
704 obj
->m_changedWindow
= m_changedWindow
;
707 void wxQueryNewPaletteEvent::CopyObject(wxObject
& obj_d
) const
709 wxQueryNewPaletteEvent
*obj
= (wxQueryNewPaletteEvent
*)&obj_d
;
710 wxEvent::CopyObject(obj_d
);
712 obj
->m_paletteRealized
= m_paletteRealized
;
715 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
717 SetEventType(wxEVT_CREATE
);
721 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
723 SetEventType(wxEVT_DESTROY
);
729 void wxIdleEvent::CopyObject(wxObject
& obj_d
) const
731 wxIdleEvent
*obj
= (wxIdleEvent
*)&obj_d
;
732 wxEvent::CopyObject(obj_d
);
734 obj
->m_requestMore
= m_requestMore
;
741 wxEvtHandler::wxEvtHandler()
743 m_nextHandler
= (wxEvtHandler
*) NULL
;
744 m_previousHandler
= (wxEvtHandler
*) NULL
;
746 m_dynamicEvents
= (wxList
*) NULL
;
748 m_pendingEvents
= (wxList
*) NULL
;
750 # if !defined(__VISAGECPP__)
751 m_eventsLocker
= new wxCriticalSection
;
756 wxEvtHandler::~wxEvtHandler()
758 // Takes itself out of the list of handlers
759 if (m_previousHandler
)
760 m_previousHandler
->m_nextHandler
= m_nextHandler
;
763 m_nextHandler
->m_previousHandler
= m_previousHandler
;
767 wxNode
*node
= m_dynamicEvents
->First();
770 #if WXWIN_COMPATIBILITY_EVENT_TYPES
771 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
772 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
773 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
774 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
776 if (entry
->m_callbackUserData
)
777 delete entry
->m_callbackUserData
;
781 delete m_dynamicEvents
;
784 delete m_pendingEvents
;
787 # if !defined(__VISAGECPP__)
788 delete m_eventsLocker
;
795 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
797 // check that we are really in a child thread
798 wxASSERT_MSG( !wxThread::IsMain(),
799 wxT("use ProcessEvent() in main thread") );
801 AddPendingEvent(event
);
806 #endif // wxUSE_THREADS
808 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
810 // 1) Add event to list of pending events of this event handler
812 #if defined(__VISAGECPP__)
813 wxENTER_CRIT_SECT( m_eventsLocker
);
815 wxENTER_CRIT_SECT( *m_eventsLocker
);
818 if ( !m_pendingEvents
)
819 m_pendingEvents
= new wxList
;
821 wxEvent
*event2
= (wxEvent
*)event
.Clone();
823 m_pendingEvents
->Append(event2
);
825 #if defined(__VISAGECPP__)
826 wxLEAVE_CRIT_SECT( m_eventsLocker
);
828 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
831 // 2) Add this event handler to list of event handlers that
832 // have pending events.
834 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
836 if ( !wxPendingEvents
)
837 wxPendingEvents
= new wxList
;
838 wxPendingEvents
->Append(this);
840 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
842 // 3) Inform the system that new pending events are somwehere,
843 // and that these should be processed in idle time.
847 void wxEvtHandler::ProcessPendingEvents()
849 #if defined(__VISAGECPP__)
850 wxENTER_CRIT_SECT( m_eventsLocker
);
852 wxENTER_CRIT_SECT( *m_eventsLocker
);
855 wxNode
*node
= m_pendingEvents
->First();
858 wxEvent
*event
= (wxEvent
*)node
->Data();
861 // In ProcessEvent, new events might get added and
862 // we can safely leave the crtical section here.
863 #if defined(__VISAGECPP__)
864 wxLEAVE_CRIT_SECT( m_eventsLocker
);
866 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
868 ProcessEvent(*event
);
870 #if defined(__VISAGECPP__)
871 wxENTER_CRIT_SECT( m_eventsLocker
);
873 wxENTER_CRIT_SECT( *m_eventsLocker
);
876 node
= m_pendingEvents
->First();
879 #if defined(__VISAGECPP__)
880 wxLEAVE_CRIT_SECT( m_eventsLocker
);
882 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
890 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
893 // check that our flag corresponds to reality
894 wxASSERT_MSG( m_isWindow
== IsKindOf(CLASSINFO(wxWindow
)),
895 _T("this should [not] be a window but it is [not]") );
898 // An event handler can be enabled or disabled
899 if ( GetEvtHandlerEnabled() )
904 What is this? When using GUI threads, a non main
905 threads can send an event and process it itself.
906 This breaks GTK's GUI threads, so please explain.
909 // Check whether we are in a child thread.
910 if ( !wxThread::IsMain() )
911 return ProcessThreadEvent(event
);
914 // Handle per-instance dynamic event tables first
915 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
918 // Then static per-class event tables
919 const wxEventTable
*table
= GetEventTable();
921 #if wxUSE_GUI && wxUSE_VALIDATORS
922 // Try the associated validator first, if this is a window.
923 // Problem: if the event handler of the window has been replaced,
924 // this wxEvtHandler may no longer be a window.
925 // Therefore validators won't be processed if the handler
926 // has been replaced with SetEventHandler.
927 // THIS CAN BE CURED if PushEventHandler is used instead of
928 // SetEventHandler, and then processing will be passed down the
929 // chain of event handlers.
932 wxWindow
*win
= (wxWindow
*)this;
934 // Can only use the validator of the window which
935 // is receiving the event
936 if ( win
== event
.GetEventObject() )
938 wxValidator
*validator
= win
->GetValidator();
939 if ( validator
&& validator
->ProcessEvent(event
) )
947 // Search upwards through the inheritance hierarchy
950 if ( SearchEventTable((wxEventTable
&)*table
, event
) )
952 table
= table
->baseTable
;
956 // Try going down the event handler chain
957 if ( GetNextHandler() )
959 if ( GetNextHandler()->ProcessEvent(event
) )
964 // Carry on up the parent-child hierarchy, but only if event is a command
965 // event: it wouldn't make sense for a parent to receive a child's size
966 // event, for example
967 if ( m_isWindow
&& event
.IsCommandEvent() )
969 wxWindow
*win
= (wxWindow
*)this;
971 // also, don't propagate events beyond the first top level window: it
972 // doesn't make sense to process dialogs events in the parent frame
973 if ( !win
->IsTopLevel() )
975 wxWindow
*parent
= win
->GetParent();
976 if (parent
&& !parent
->IsBeingDeleted())
977 return parent
->GetEventHandler()->ProcessEvent(event
);
982 // Last try - application object.
983 if ( wxTheApp
&& (this != wxTheApp
) )
985 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
986 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
987 // processed appropriately via SearchEventTable.
988 if ( event
.GetEventType() != wxEVT_IDLE
)
990 if ( wxTheApp
->ProcessEvent(event
) )
998 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
1000 wxEventType eventType
= event
.GetEventType();
1001 int eventId
= event
.GetId();
1003 // BC++ doesn't like testing for m_fn without != 0
1004 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
1006 // the line using reference exposes a bug in gcc: although it _seems_
1007 // to work, it leads to weird crashes later on during program
1010 wxEventTableEntry entry
= table
.entries
[i
];
1012 const wxEventTableEntry
& entry
= table
.entries
[i
];
1015 // match only if the event type is the same and the id is either -1 in
1016 // the event table (meaning "any") or the event id matches the id
1017 // specified in the event table either exactly or by falling into
1018 // range between first and last
1019 if ( eventType
== entry
.m_eventType
)
1021 int tableId1
= entry
.m_id
,
1022 tableId2
= entry
.m_lastId
;
1024 if ( (tableId1
== -1) ||
1025 (tableId2
== -1 && eventId
== tableId1
) ||
1027 (eventId
>= tableId1
&& eventId
<= tableId2
)) )
1030 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1032 (this->*((wxEventFunction
) (entry
.m_fn
)))(event
);
1034 return !event
.GetSkipped();
1042 void wxEvtHandler::Connect( int id
, int lastId
,
1044 wxObjectEventFunction func
,
1045 wxObject
*userData
)
1047 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1048 wxEventTableEntry
*entry
= new wxEventTableEntry
;
1049 entry
->m_eventType
= eventType
;
1051 entry
->m_lastId
= lastId
;
1053 entry
->m_callbackUserData
= userData
;
1054 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1055 wxDynamicEventTableEntry
*entry
=
1056 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
);
1057 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1059 if (!m_dynamicEvents
)
1060 m_dynamicEvents
= new wxList
;
1062 m_dynamicEvents
->Append( (wxObject
*) entry
);
1065 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1066 wxObjectEventFunction func
,
1067 wxObject
*userData
)
1069 if (!m_dynamicEvents
)
1072 wxNode
*node
= m_dynamicEvents
->First();
1075 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1076 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
1077 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1078 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
1079 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1081 if ((entry
->m_id
== id
) &&
1082 ((entry
->m_lastId
== lastId
) || (lastId
== -1)) &&
1083 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1084 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1085 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1087 if (entry
->m_callbackUserData
)
1088 delete entry
->m_callbackUserData
;
1089 m_dynamicEvents
->DeleteNode( node
);
1093 node
= node
->Next();
1098 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1100 wxCHECK_MSG( m_dynamicEvents
, FALSE
,
1101 wxT("caller should check that we have dynamic events") );
1103 int commandId
= event
.GetId();
1105 wxNode
*node
= m_dynamicEvents
->First();
1108 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1109 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
1110 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1111 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
1112 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1116 // Match, if event spec says any id will do (id == -1)
1117 if ( (event
.GetEventType() == entry
->m_eventType
) &&
1118 (entry
->m_id
== -1 ||
1119 (entry
->m_lastId
== -1 && commandId
== entry
->m_id
) ||
1120 (entry
->m_lastId
!= -1 &&
1121 (commandId
>= entry
->m_id
&& commandId
<= entry
->m_lastId
))) )
1124 event
.m_callbackUserData
= entry
->m_callbackUserData
;
1126 (this->*((wxEventFunction
) (entry
->m_fn
)))(event
);
1128 if (event
.GetSkipped())
1134 node
= node
->Next();
1139 #if WXWIN_COMPATIBILITY
1140 bool wxEvtHandler::OnClose()
1142 if (GetNextHandler())
1143 return GetNextHandler()->OnClose();
1147 #endif // WXWIN_COMPATIBILITY
1151 // Find a window with the focus, that is also a descendant of the given window.
1152 // This is used to determine the window to initially send commands to.
1153 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1155 // Process events starting with the window with the focus, if any.
1156 wxWindow
* focusWin
= wxWindow::FindFocus();
1157 wxWindow
* win
= focusWin
;
1159 // Check if this is a descendant of this frame.
1160 // If not, win will be set to NULL.
1163 if (win
== ancestor
)
1166 win
= win
->GetParent();
1168 if (win
== (wxWindow
*) NULL
)
1169 focusWin
= (wxWindow
*) NULL
;