1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Event classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) && !defined(__EMX__)
21 // Some older compilers (such as EMX) cannot handle
22 // #pragma interface/implementation correctly, iff
23 // #pragma implementation is used in _two_ translation
24 // units (as created by e.g. event.cpp compiled for
25 // libwx_base and event.cpp compiled for libwx_gui_core).
26 // So we must not use those pragmas for those compilers in
28 #pragma implementation "event.h"
31 // For compilers that support precompilation, includes "wx.h".
32 #include "wx/wxprec.h"
44 #include "wx/control.h"
53 #include "wx/validate.h"
55 #include "wx/stopwatch.h"
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
64 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler
, wxObject
)
65 IMPLEMENT_ABSTRACT_CLASS(wxEvent
, wxObject
)
69 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent
, wxEvent
)
70 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent
, wxEvent
)
71 IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent
, wxCommandEvent
)
72 IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent
, wxCommandEvent
)
73 IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent
, wxEvent
)
74 IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent
, wxEvent
)
75 IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent
, wxEvent
)
76 IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent
, wxEvent
)
77 IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent
, wxEvent
)
78 IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent
, wxEvent
)
79 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent
, wxEvent
)
80 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent
, wxEvent
)
81 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent
, wxEvent
)
82 IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent
, wxCommandEvent
)
83 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent
, wxEvent
)
84 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent
, wxEvent
)
85 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent
, wxEvent
)
86 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent
, wxEvent
)
87 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent
, wxEvent
)
88 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent
, wxEvent
)
89 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent
, wxEvent
)
90 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent
, wxEvent
)
91 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent
, wxEvent
)
92 IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent
, wxEvent
)
93 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent
, wxEvent
)
94 IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent
, wxEvent
)
95 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent
, wxCommandEvent
)
96 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent
, wxEvent
)
97 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent
, wxEvent
)
98 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent
, wxEvent
)
99 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent
, wxEvent
)
100 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent
, wxEvent
)
101 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent
, wxCommandEvent
)
102 IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent
, wxCommandEvent
)
103 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent
, wxEvent
)
108 const wxEventTable
*wxEvtHandler::GetEventTable() const
109 { return &wxEvtHandler::sm_eventTable
; }
111 const wxEventTable
wxEvtHandler::sm_eventTable
=
112 { (const wxEventTable
*)NULL
, &wxEvtHandler::sm_eventTableEntries
[0] };
114 wxEventHashTable
&wxEvtHandler::GetEventHashTable() const
115 { return wxEvtHandler::sm_eventHashTable
; }
117 wxEventHashTable
wxEvtHandler::sm_eventHashTable(wxEvtHandler::sm_eventTable
);
119 const wxEventTableEntry
wxEvtHandler::sm_eventTableEntries
[] =
120 { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL
, 0, 0, (wxObjectEventFunction
)NULL
, NULL
) };
122 // ----------------------------------------------------------------------------
124 // ----------------------------------------------------------------------------
126 // To put pending event handlers
127 wxList
*wxPendingEvents
= (wxList
*)NULL
;
130 // protects wxPendingEvents list
131 wxCriticalSection
*wxPendingEventsLocker
= (wxCriticalSection
*)NULL
;
134 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
136 // common event types are defined here, other event types are defined by the
137 // components which use them
139 const wxEventType wxEVT_FIRST
= 10000;
140 const wxEventType wxEVT_USER_FIRST
= wxEVT_FIRST
+ 2000;
142 DEFINE_EVENT_TYPE(wxEVT_NULL
)
143 DEFINE_EVENT_TYPE(wxEVT_IDLE
)
144 DEFINE_EVENT_TYPE(wxEVT_SOCKET
)
146 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
152 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
154 DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED
)
155 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED
)
156 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED
)
157 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED
)
158 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
)
159 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
)
160 DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED
)
161 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED
)
162 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED
)
163 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED
)
164 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED
)
165 DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED
)
166 DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED
)
167 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED
)
168 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER
)
169 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED
)
171 // Sockets and timers send events, too
172 DEFINE_EVENT_TYPE(wxEVT_TIMER
)
175 DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN
)
176 DEFINE_EVENT_TYPE(wxEVT_LEFT_UP
)
177 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN
)
178 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP
)
179 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN
)
180 DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP
)
181 DEFINE_EVENT_TYPE(wxEVT_MOTION
)
182 DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW
)
183 DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW
)
184 DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK
)
185 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK
)
186 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK
)
187 DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS
)
188 DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS
)
189 DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS
)
190 DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL
)
192 // Non-client mouse events
193 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN
)
194 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP
)
195 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN
)
196 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP
)
197 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN
)
198 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP
)
199 DEFINE_EVENT_TYPE(wxEVT_NC_MOTION
)
200 DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW
)
201 DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW
)
202 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK
)
203 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK
)
204 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK
)
206 // Character input event type
207 DEFINE_EVENT_TYPE(wxEVT_CHAR
)
208 DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK
)
209 DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY
)
210 DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN
)
211 DEFINE_EVENT_TYPE(wxEVT_KEY_UP
)
213 DEFINE_EVENT_TYPE(wxEVT_HOTKEY
)
217 DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR
)
219 // wxScrollbar and wxSlider event identifiers
220 DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP
)
221 DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM
)
222 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP
)
223 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN
)
224 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP
)
225 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN
)
226 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK
)
227 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE
)
228 DEFINE_EVENT_TYPE(wxEVT_SCROLL_ENDSCROLL
)
230 // Scroll events from wxWindow
231 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP
)
232 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM
)
233 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP
)
234 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN
)
235 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP
)
236 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN
)
237 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK
)
238 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE
)
241 DEFINE_EVENT_TYPE(wxEVT_SIZE
)
242 DEFINE_EVENT_TYPE(wxEVT_SIZING
)
243 DEFINE_EVENT_TYPE(wxEVT_MOVE
)
244 DEFINE_EVENT_TYPE(wxEVT_MOVING
)
245 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW
)
246 DEFINE_EVENT_TYPE(wxEVT_END_SESSION
)
247 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION
)
248 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
249 DEFINE_EVENT_TYPE(wxEVT_POWER
)
250 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
251 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
252 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
253 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
254 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
255 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
256 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
257 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
258 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
259 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
260 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
261 DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN
)
262 DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE
)
263 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
264 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
265 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
266 DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED
)
267 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
268 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
269 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
270 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
271 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
272 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
273 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
274 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
275 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
276 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
277 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
278 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
279 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
281 // Generic command events
282 // Note: a click is a higher-level event than button down/up
283 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
284 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
285 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
286 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
287 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
288 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
289 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
292 DEFINE_EVENT_TYPE(wxEVT_HELP
)
293 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
295 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
301 // ============================================================================
303 // ============================================================================
305 // ----------------------------------------------------------------------------
306 // event initialization
307 // ----------------------------------------------------------------------------
312 static int s_lastUsedEventType
= wxEVT_FIRST
;
314 return s_lastUsedEventType
++;
317 // ----------------------------------------------------------------------------
319 // ----------------------------------------------------------------------------
322 * General wxWindows events, covering
323 * all interesting things that might happen (button clicking, resizing,
324 * setting text in widgets, etc.).
326 * For each completely new event type, derive a new event class.
330 wxEvent::wxEvent(int theId
, wxEventType commandType
)
332 m_eventType
= commandType
;
333 m_eventObject
= (wxObject
*) NULL
;
337 m_callbackUserData
= (wxObject
*) NULL
;
338 m_isCommandEvent
= false;
339 m_propagationLevel
= wxEVENT_PROPAGATE_NONE
;
342 wxEvent::wxEvent(const wxEvent
&src
)
344 , m_eventObject(src
.m_eventObject
)
345 , m_eventType(src
.m_eventType
)
346 , m_timeStamp(src
.m_timeStamp
)
348 , m_callbackUserData(src
.m_callbackUserData
)
349 , m_propagationLevel(src
.m_propagationLevel
)
350 , m_skipped(src
.m_skipped
)
351 , m_isCommandEvent(src
.m_isCommandEvent
)
364 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
365 : wxEvent(theId
, commandType
)
367 m_clientData
= (char *) NULL
;
368 m_clientObject
= (wxClientData
*) NULL
;
371 m_isCommandEvent
= true;
373 // the command events are propagated upwards by default
374 m_propagationLevel
= wxEVENT_PROPAGATE_MAX
;
382 wxLongLong
wxUpdateUIEvent::sm_lastUpdate
= 0;
385 long wxUpdateUIEvent::sm_updateInterval
= 0;
387 wxUpdateUIMode
wxUpdateUIEvent::sm_updateMode
= wxUPDATE_UI_PROCESS_ALL
;
390 bool wxUpdateUIEvent::CanUpdate(wxWindowBase
*win
)
392 // Don't update if we've switched global updating off
393 // and this window doesn't support updates.
395 (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED
&&
396 ((win
->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES
) == 0)))
399 if (sm_updateInterval
== -1)
401 else if (sm_updateInterval
== 0)
405 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
406 wxLongLong now
= wxGetLocalTimeMillis();
407 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
412 // If we don't have wxStopWatch or wxLongLong, we
413 // should err on the safe side and update now anyway.
420 // Reset the update time to provide a delay until the next
421 // time we should update
422 void wxUpdateUIEvent::ResetUpdateTime()
424 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
425 if (sm_updateInterval
> 0)
427 wxLongLong now
= wxGetLocalTimeMillis();
428 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
440 wxIdleMode
wxIdleEvent::sm_idleMode
= wxIDLE_PROCESS_ALL
;
442 // Can we send an idle event?
443 bool wxIdleEvent::CanSend(wxWindow
* win
)
445 // Don't update if we've switched global updating off
446 // and this window doesn't support updates.
448 (GetMode() == wxIDLE_PROCESS_SPECIFIED
&&
449 ((win
->GetExtraStyle() & wxWS_EX_PROCESS_IDLE
) == 0)))
459 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
463 : wxCommandEvent(commandType
, id
)
465 m_extraLong
= orient
;
473 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
477 m_eventType
= commandType
;
478 m_extraLong
= orient
;
487 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
489 m_eventType
= commandType
;
492 m_controlDown
= false;
496 m_middleDown
= false;
501 m_linesPerAction
= 0;
504 void wxMouseEvent::Assign(const wxMouseEvent
& event
)
506 m_eventType
= event
.m_eventType
;
511 m_leftDown
= event
.m_leftDown
;
512 m_middleDown
= event
.m_middleDown
;
513 m_rightDown
= event
.m_rightDown
;
515 m_controlDown
= event
.m_controlDown
;
516 m_shiftDown
= event
.m_shiftDown
;
517 m_altDown
= event
.m_altDown
;
518 m_metaDown
= event
.m_metaDown
;
520 m_wheelRotation
= event
.m_wheelRotation
;
521 m_wheelDelta
= event
.m_wheelDelta
;
522 m_linesPerAction
= event
.m_linesPerAction
;
525 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
526 // or any button dclick event (but = -1)
527 bool wxMouseEvent::ButtonDClick(int but
) const
532 return (LeftDClick() || MiddleDClick() || RightDClick());
536 return MiddleDClick();
538 return RightDClick();
540 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
546 // True if was a button down event (1 = left, 2 = middle, 3 = right)
547 // or any button down event (but = -1)
548 bool wxMouseEvent::ButtonDown(int but
) const
553 return (LeftDown() || MiddleDown() || RightDown());
561 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
567 // True if was a button up event (1 = left, 2 = middle, 3 = right)
568 // or any button up event (but = -1)
569 bool wxMouseEvent::ButtonUp(int but
) const
574 return (LeftUp() || MiddleUp() || RightUp());
582 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
588 // True if the given button is currently changing state
589 bool wxMouseEvent::Button(int but
) const
594 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
596 return (LeftDown() || LeftUp() || LeftDClick());
598 return (MiddleDown() || MiddleUp() || MiddleDClick());
600 return (RightDown() || RightUp() || RightDClick());
602 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
608 bool wxMouseEvent::ButtonIsDown(int but
) const
613 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
617 return MiddleIsDown();
619 return RightIsDown();
621 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
627 int wxMouseEvent::GetButton() const
629 for ( int i
= 1; i
<= 3; i
++ )
640 // Find the logical position of the event given the DC
641 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
643 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
653 wxKeyEvent::wxKeyEvent(wxEventType type
)
657 m_controlDown
= false;
667 wxKeyEvent::wxKeyEvent(const wxKeyEvent
& evt
)
673 m_keyCode
= evt
.m_keyCode
;
675 m_controlDown
= evt
.m_controlDown
;
676 m_shiftDown
= evt
.m_shiftDown
;
677 m_altDown
= evt
.m_altDown
;
678 m_metaDown
= evt
.m_metaDown
;
679 m_scanCode
= evt
.m_scanCode
;
680 m_rawCode
= evt
.m_rawCode
;
681 m_rawFlags
= evt
.m_rawFlags
;
684 m_uniChar
= evt
.m_uniChar
;
688 long wxKeyEvent::KeyCode() const
693 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
695 SetEventType(wxEVT_CREATE
);
699 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
701 SetEventType(wxEVT_DESTROY
);
705 wxChildFocusEvent::wxChildFocusEvent(wxWindow
*win
)
706 : wxCommandEvent(wxEVT_CHILD_FOCUS
)
716 // ----------------------------------------------------------------------------
718 // ----------------------------------------------------------------------------
720 static const int EVENT_TYPE_TABLE_INIT_SIZE
= 31; // Not to big not to small...
722 wxEventHashTable::wxEventHashTable(const wxEventTable
&table
)
726 AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE
);
729 wxEventHashTable::~wxEventHashTable()
732 for(i
= 0; i
< m_size
; i
++)
734 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
741 delete[] m_eventTypeTable
;
744 bool wxEventHashTable::HandleEvent(wxEvent
&event
, wxEvtHandler
*self
)
749 m_rebuildHash
= false;
752 // Find all entries for the given event type.
753 wxEventType eventType
= event
.GetEventType();
754 const EventTypeTablePointer eTTnode
= m_eventTypeTable
[eventType
% m_size
];
755 if (eTTnode
&& eTTnode
->eventType
== eventType
)
757 // Now start the search for an event handler
758 // that can handle an event with the given ID.
759 const wxEventTableEntryPointerArray
&
760 eventEntryTable
= eTTnode
->eventEntryTable
;
762 const size_t count
= eventEntryTable
.GetCount();
763 for (size_t n
= 0; n
< count
; n
++)
766 ProcessEventIfMatches(*eventEntryTable
[n
], self
, event
) )
776 void wxEventHashTable::InitHashTable()
778 // Loop over the event tables and all its base tables.
779 const wxEventTable
*table
= &m_table
;
782 // Retrieve all valid event handler entries
783 const wxEventTableEntry
*entry
= table
->entries
;
784 while (entry
->m_fn
!= 0)
786 // Add the event entry in the Hash.
792 table
= table
->baseTable
;
795 // Lets free some memory.
797 for(i
= 0; i
< m_size
; i
++)
799 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
802 eTTnode
->eventEntryTable
.Shrink();
807 void wxEventHashTable::AddEntry(const wxEventTableEntry
&entry
)
809 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[entry
.m_eventType
% m_size
];
810 EventTypeTablePointer eTTnode
= *peTTnode
;
814 if (eTTnode
->eventType
!= entry
.m_eventType
)
817 GrowEventTypeTable();
818 // Try again to add it.
825 eTTnode
= new EventTypeTable
;
826 eTTnode
->eventType
= entry
.m_eventType
;
830 // Fill all hash entries between entry.m_id and entry.m_lastId...
831 eTTnode
->eventEntryTable
.Add(&entry
);
834 void wxEventHashTable::AllocEventTypeTable(size_t size
)
836 m_eventTypeTable
= new EventTypeTablePointer
[size
];
837 memset((void *)m_eventTypeTable
, 0, sizeof(EventTypeTablePointer
)*size
);
841 void wxEventHashTable::GrowEventTypeTable()
843 size_t oldSize
= m_size
;
844 EventTypeTablePointer
*oldEventTypeTable
= m_eventTypeTable
;
846 // TODO: Search the most optimal grow sequence
847 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize
*2+1);
849 for ( size_t i
= 0; i
< oldSize
; /* */ )
851 EventTypeTablePointer eTToldNode
= oldEventTypeTable
[i
];
854 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[eTToldNode
->eventType
% m_size
];
855 EventTypeTablePointer eTTnode
= *peTTnode
;
857 // Check for collision, we don't want any.
860 GrowEventTypeTable();
861 continue; // Don't increment the counter,
862 // as we still need to add this element.
866 // Get the old value and put it in the new table.
867 *peTTnode
= oldEventTypeTable
[i
];
874 delete[] oldEventTypeTable
;
877 // ----------------------------------------------------------------------------
879 // ----------------------------------------------------------------------------
885 wxEvtHandler::wxEvtHandler()
887 m_nextHandler
= (wxEvtHandler
*) NULL
;
888 m_previousHandler
= (wxEvtHandler
*) NULL
;
890 m_dynamicEvents
= (wxList
*) NULL
;
891 m_pendingEvents
= (wxList
*) NULL
;
893 # if !defined(__VISAGECPP__)
894 m_eventsLocker
= new wxCriticalSection
;
897 // no client data (yet)
899 m_clientDataType
= wxClientData_None
;
902 wxEvtHandler::~wxEvtHandler()
904 // Takes itself out of the list of handlers
905 if (m_previousHandler
)
906 m_previousHandler
->m_nextHandler
= m_nextHandler
;
909 m_nextHandler
->m_previousHandler
= m_previousHandler
;
913 wxList::iterator it
= m_dynamicEvents
->begin(),
914 en
= m_dynamicEvents
->end();
915 for (;it
!= en
; ++it
)
917 #if WXWIN_COMPATIBILITY_EVENT_TYPES
918 wxEventTableEntry
*entry
= (wxEventTableEntry
*)*it
;
919 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
920 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)*it
;
921 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
923 if (entry
->m_callbackUserData
)
924 delete entry
->m_callbackUserData
;
927 delete m_dynamicEvents
;
930 delete m_pendingEvents
;
933 # if !defined(__VISAGECPP__)
934 delete m_eventsLocker
;
937 // Remove us from wxPendingEvents if necessary.
938 if(wxPendingEventsLocker
)
939 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
940 if ( wxPendingEvents
) {
941 wxPendingEvents
->DeleteObject(this);
943 if(wxPendingEventsLocker
)
944 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
947 // we only delete object data, not untyped
948 if ( m_clientDataType
== wxClientData_Object
)
949 delete m_clientObject
;
954 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
956 // check that we are really in a child thread
957 wxASSERT_MSG( !wxThread::IsMain(),
958 wxT("use ProcessEvent() in main thread") );
960 AddPendingEvent(event
);
965 void wxEvtHandler::ClearEventLocker()
967 #if !defined(__VISAGECPP__)
968 delete m_eventsLocker
;
969 m_eventsLocker
= NULL
;
973 #endif // wxUSE_THREADS
975 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
977 // 1) Add event to list of pending events of this event handler
979 wxEvent
*eventCopy
= event
.Clone();
981 // we must be able to copy the events here so the event class must
982 // implement Clone() properly instead of just providing a NULL stab for it
983 wxCHECK_RET( eventCopy
,
984 _T("events of this type aren't supposed to be posted") );
986 #if defined(__VISAGECPP__)
987 wxENTER_CRIT_SECT( m_eventsLocker
);
989 wxENTER_CRIT_SECT( *m_eventsLocker
);
992 if ( !m_pendingEvents
)
993 m_pendingEvents
= new wxList
;
995 m_pendingEvents
->Append(eventCopy
);
997 #if defined(__VISAGECPP__)
998 wxLEAVE_CRIT_SECT( m_eventsLocker
);
1000 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
1003 // 2) Add this event handler to list of event handlers that
1004 // have pending events.
1006 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
1008 if ( !wxPendingEvents
)
1009 wxPendingEvents
= new wxList
;
1010 wxPendingEvents
->Append(this);
1012 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
1014 // 3) Inform the system that new pending events are somwehere,
1015 // and that these should be processed in idle time.
1019 void wxEvtHandler::ProcessPendingEvents()
1021 #if defined(__VISAGECPP__)
1022 wxENTER_CRIT_SECT( m_eventsLocker
);
1024 wxENTER_CRIT_SECT( *m_eventsLocker
);
1027 wxList::compatibility_iterator node
= m_pendingEvents
->GetFirst();
1030 wxEvent
*event
= (wxEvent
*)node
->GetData();
1031 m_pendingEvents
->Erase(node
);
1033 // In ProcessEvent, new events might get added and
1034 // we can safely leave the crtical section here.
1035 #if defined(__VISAGECPP__)
1036 wxLEAVE_CRIT_SECT( m_eventsLocker
);
1038 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
1040 ProcessEvent(*event
);
1042 #if defined(__VISAGECPP__)
1043 wxENTER_CRIT_SECT( m_eventsLocker
);
1045 wxENTER_CRIT_SECT( *m_eventsLocker
);
1048 node
= m_pendingEvents
->GetFirst();
1051 #if defined(__VISAGECPP__)
1052 wxLEAVE_CRIT_SECT( m_eventsLocker
);
1054 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
1062 wxEvtHandler::ProcessEventIfMatches(const wxEventTableEntryBase
& entry
,
1063 wxEvtHandler
*handler
,
1066 int tableId1
= entry
.m_id
,
1067 tableId2
= entry
.m_lastId
;
1069 // match only if the event type is the same and the id is either -1 in
1070 // the event table (meaning "any") or the event id matches the id
1071 // specified in the event table either exactly or by falling into
1072 // range between first and last
1073 if ((tableId1
== -1) ||
1074 (tableId2
== -1 && tableId1
== event
.GetId()) ||
1076 (event
.GetId() >= tableId1
&& event
.GetId() <= tableId2
)))
1079 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1081 #if wxUSE_EXCEPTIONS
1084 // call the handler via wxApp method which allows the user to catch
1085 // any exceptions which may be thrown by any handler in the program
1087 wxTheApp
->HandleEvent(handler
, (wxEventFunction
)entry
.m_fn
, event
);
1090 #endif // wxUSE_EXCEPTIONS
1092 // no need for an extra virtual function call
1093 (handler
->*((wxEventFunction
) (entry
.m_fn
)))(event
);
1096 if (!event
.GetSkipped())
1103 bool wxEvtHandler::TryParent(wxEvent
& event
)
1105 if ( wxTheApp
&& (this != wxTheApp
) )
1107 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1108 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1109 // processed appropriately via SearchEventTable.
1110 if ( event
.GetEventType() != wxEVT_IDLE
)
1112 if ( wxTheApp
->ProcessEvent(event
) )
1120 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
1122 // allow the application to hook into event processing
1125 int rc
= wxTheApp
->FilterEvent(event
);
1128 wxASSERT_MSG( rc
== 1 || rc
== 0,
1129 _T("unexpected wxApp::FilterEvent return value") );
1133 //else: proceed normally
1136 // An event handler can be enabled or disabled
1137 if ( GetEvtHandlerEnabled() )
1139 // if we have a validator, it has higher priority than our own event
1141 if ( TryValidator(event
) )
1144 // Handle per-instance dynamic event tables first
1145 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
1148 // Then static per-class event tables
1149 if ( GetEventHashTable().HandleEvent(event
, this) )
1153 // Try going down the event handler chain
1154 if ( GetNextHandler() )
1156 if ( GetNextHandler()->ProcessEvent(event
) )
1160 // Finally propagate the event upwards the window chain and/or to the
1161 // application object as necessary
1162 return TryParent(event
);
1166 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
1168 const wxEventType eventType
= event
.GetEventType();
1169 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
1171 const wxEventTableEntry
& entry
= table
.entries
[i
];
1172 if ( eventType
== entry
.m_eventType
)
1174 if ( ProcessEventIfMatches(entry
, this, event
) )
1182 void wxEvtHandler::Connect( int id
, int lastId
,
1184 wxObjectEventFunction func
,
1186 wxEvtHandler
* eventSink
)
1188 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1189 wxEventTableEntry
*entry
= new wxEventTableEntry
;
1190 entry
->m_eventType
= eventType
;
1192 entry
->m_lastId
= lastId
;
1194 entry
->m_callbackUserData
= userData
;
1195 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1196 wxDynamicEventTableEntry
*entry
=
1197 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
, eventSink
);
1198 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1200 if (!m_dynamicEvents
)
1201 m_dynamicEvents
= new wxList
;
1203 // Insert at the front of the list so most recent additions are found first
1204 m_dynamicEvents
->Insert( (wxObject
*) entry
);
1207 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1208 wxObjectEventFunction func
,
1210 wxEvtHandler
* eventSink
)
1212 if (!m_dynamicEvents
)
1215 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1218 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1219 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
1220 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1221 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1222 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1224 if ((entry
->m_id
== id
) &&
1225 ((entry
->m_lastId
== lastId
) || (lastId
== -1)) &&
1226 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1227 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1228 ((entry
->m_eventSink
== eventSink
) || (eventSink
== (wxEvtHandler
*)NULL
)) &&
1229 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1231 if (entry
->m_callbackUserData
)
1232 delete entry
->m_callbackUserData
;
1233 m_dynamicEvents
->Erase( node
);
1237 node
= node
->GetNext();
1242 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1244 wxCHECK_MSG( m_dynamicEvents
, false,
1245 wxT("caller should check that we have dynamic events") );
1247 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1250 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1251 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
1252 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1253 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1254 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1256 if ((event
.m_eventType
== entry
->m_eventType
) && entry
->m_fn
)
1258 wxEvtHandler
*handler
=
1259 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
1260 entry
->m_eventSink
? entry
->m_eventSink
1265 if ( ProcessEventIfMatches(*entry
, handler
, event
) )
1271 node
= node
->GetNext();
1277 void wxEvtHandler::DoSetClientObject( wxClientData
*data
)
1279 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1280 wxT("can't have both object and void client data") );
1282 if ( m_clientObject
)
1283 delete m_clientObject
;
1285 m_clientObject
= data
;
1286 m_clientDataType
= wxClientData_Object
;
1289 wxClientData
*wxEvtHandler::DoGetClientObject() const
1291 // it's not an error to call GetClientObject() on a window which doesn't
1292 // have client data at all - NULL will be returned
1293 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1294 wxT("this window doesn't have object client data") );
1296 return m_clientObject
;
1299 void wxEvtHandler::DoSetClientData( void *data
)
1301 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1302 wxT("can't have both object and void client data") );
1304 m_clientData
= data
;
1305 m_clientDataType
= wxClientData_Void
;
1308 void *wxEvtHandler::DoGetClientData() const
1310 // it's not an error to call GetClientData() on a window which doesn't have
1311 // client data at all - NULL will be returned
1312 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1313 wxT("this window doesn't have void client data") );
1315 return m_clientData
;
1318 #endif // wxUSE_BASE
1322 // Find a window with the focus, that is also a descendant of the given window.
1323 // This is used to determine the window to initially send commands to.
1324 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1326 // Process events starting with the window with the focus, if any.
1327 wxWindow
* focusWin
= wxWindow::FindFocus();
1328 wxWindow
* win
= focusWin
;
1330 // Check if this is a descendant of this frame.
1331 // If not, win will be set to NULL.
1334 if (win
== ancestor
)
1337 win
= win
->GetParent();
1339 if (win
== (wxWindow
*) NULL
)
1340 focusWin
= (wxWindow
*) NULL
;