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 int eventId
= event
.GetId();
760 const wxEventTableEntryPointerArray
&eventEntryTable
= eTTnode
->eventEntryTable
;
763 size_t count
= eventEntryTable
.GetCount();
764 for (n
= 0; n
< count
; n
++)
766 const wxEventTableEntry
* entry
= eventEntryTable
[n
];
767 int tableId1
= entry
->m_id
,
768 tableId2
= entry
->m_lastId
;
770 if ((tableId1
== -1) ||
771 (tableId2
== -1 && tableId1
== eventId
) ||
773 (eventId
>= tableId1
&& eventId
<= tableId2
)))
776 event
.m_callbackUserData
= entry
->m_callbackUserData
;
778 (self
->*((wxEventFunction
) (entry
->m_fn
)))(event
);
780 if (!event
.GetSkipped())
791 void wxEventHashTable::InitHashTable()
793 // Loop over the event tables and all its base tables.
794 const wxEventTable
*table
= &m_table
;
797 // Retrieve all valid event handler entries
798 const wxEventTableEntry
*entry
= table
->entries
;
799 while (entry
->m_fn
!= 0)
801 // Add the event entry in the Hash.
807 table
= table
->baseTable
;
810 // Lets free some memory.
812 for(i
= 0; i
< m_size
; i
++)
814 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
817 eTTnode
->eventEntryTable
.Shrink();
822 void wxEventHashTable::AddEntry(const wxEventTableEntry
&entry
)
824 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[entry
.m_eventType
% m_size
];
825 EventTypeTablePointer eTTnode
= *peTTnode
;
829 if (eTTnode
->eventType
!= entry
.m_eventType
)
832 GrowEventTypeTable();
833 // Try again to add it.
840 eTTnode
= new EventTypeTable
;
841 eTTnode
->eventType
= entry
.m_eventType
;
845 // Fill all hash entries between entry.m_id and entry.m_lastId...
846 eTTnode
->eventEntryTable
.Add(&entry
);
849 void wxEventHashTable::AllocEventTypeTable(size_t size
)
851 m_eventTypeTable
= new EventTypeTablePointer
[size
];
852 memset((void *)m_eventTypeTable
, 0, sizeof(EventTypeTablePointer
)*size
);
856 void wxEventHashTable::GrowEventTypeTable()
858 size_t oldSize
= m_size
;
859 EventTypeTablePointer
*oldEventTypeTable
= m_eventTypeTable
;
861 // TODO: Search the most optimal grow sequence
862 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize
*2+1);
864 for ( size_t i
= 0; i
< oldSize
; /* */ )
866 EventTypeTablePointer eTToldNode
= oldEventTypeTable
[i
];
869 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[eTToldNode
->eventType
% m_size
];
870 EventTypeTablePointer eTTnode
= *peTTnode
;
872 // Check for collision, we don't want any.
875 GrowEventTypeTable();
876 continue; // Don't increment the counter,
877 // as we still need to add this element.
881 // Get the old value and put it in the new table.
882 *peTTnode
= oldEventTypeTable
[i
];
889 delete[] oldEventTypeTable
;
892 // ----------------------------------------------------------------------------
894 // ----------------------------------------------------------------------------
900 wxEvtHandler::wxEvtHandler()
902 m_nextHandler
= (wxEvtHandler
*) NULL
;
903 m_previousHandler
= (wxEvtHandler
*) NULL
;
905 m_dynamicEvents
= (wxList
*) NULL
;
906 m_pendingEvents
= (wxList
*) NULL
;
908 # if !defined(__VISAGECPP__)
909 m_eventsLocker
= new wxCriticalSection
;
912 // no client data (yet)
914 m_clientDataType
= wxClientData_None
;
917 wxEvtHandler::~wxEvtHandler()
919 // Takes itself out of the list of handlers
920 if (m_previousHandler
)
921 m_previousHandler
->m_nextHandler
= m_nextHandler
;
924 m_nextHandler
->m_previousHandler
= m_previousHandler
;
928 wxList::iterator it
= m_dynamicEvents
->begin(),
929 en
= m_dynamicEvents
->end();
930 for (;it
!= en
; ++it
)
932 #if WXWIN_COMPATIBILITY_EVENT_TYPES
933 wxEventTableEntry
*entry
= (wxEventTableEntry
*)*it
;
934 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
935 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)*it
;
936 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
938 if (entry
->m_callbackUserData
)
939 delete entry
->m_callbackUserData
;
942 delete m_dynamicEvents
;
945 delete m_pendingEvents
;
948 # if !defined(__VISAGECPP__)
949 delete m_eventsLocker
;
952 // Remove us from wxPendingEvents if necessary.
953 if(wxPendingEventsLocker
)
954 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
955 if ( wxPendingEvents
) {
956 wxPendingEvents
->DeleteObject(this);
958 if(wxPendingEventsLocker
)
959 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
962 // we only delete object data, not untyped
963 if ( m_clientDataType
== wxClientData_Object
)
964 delete m_clientObject
;
969 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
971 // check that we are really in a child thread
972 wxASSERT_MSG( !wxThread::IsMain(),
973 wxT("use ProcessEvent() in main thread") );
975 AddPendingEvent(event
);
980 #endif // wxUSE_THREADS
982 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
984 // 1) Add event to list of pending events of this event handler
986 wxEvent
*eventCopy
= event
.Clone();
988 // we must be able to copy the events here so the event class must
989 // implement Clone() properly instead of just providing a NULL stab for it
990 wxCHECK_RET( eventCopy
,
991 _T("events of this type aren't supposed to be posted") );
993 #if defined(__VISAGECPP__)
994 wxENTER_CRIT_SECT( m_eventsLocker
);
996 wxENTER_CRIT_SECT( *m_eventsLocker
);
999 if ( !m_pendingEvents
)
1000 m_pendingEvents
= new wxList
;
1002 m_pendingEvents
->Append(eventCopy
);
1004 #if defined(__VISAGECPP__)
1005 wxLEAVE_CRIT_SECT( m_eventsLocker
);
1007 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
1010 // 2) Add this event handler to list of event handlers that
1011 // have pending events.
1013 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
1015 if ( !wxPendingEvents
)
1016 wxPendingEvents
= new wxList
;
1017 wxPendingEvents
->Append(this);
1019 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
1021 // 3) Inform the system that new pending events are somwehere,
1022 // and that these should be processed in idle time.
1026 void wxEvtHandler::ProcessPendingEvents()
1028 #if defined(__VISAGECPP__)
1029 wxENTER_CRIT_SECT( m_eventsLocker
);
1031 wxENTER_CRIT_SECT( *m_eventsLocker
);
1034 wxList::compatibility_iterator node
= m_pendingEvents
->GetFirst();
1037 wxEvent
*event
= (wxEvent
*)node
->GetData();
1038 m_pendingEvents
->Erase(node
);
1040 // In ProcessEvent, new events might get added and
1041 // we can safely leave the crtical section here.
1042 #if defined(__VISAGECPP__)
1043 wxLEAVE_CRIT_SECT( m_eventsLocker
);
1045 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
1047 ProcessEvent(*event
);
1049 #if defined(__VISAGECPP__)
1050 wxENTER_CRIT_SECT( m_eventsLocker
);
1052 wxENTER_CRIT_SECT( *m_eventsLocker
);
1055 node
= m_pendingEvents
->GetFirst();
1058 #if defined(__VISAGECPP__)
1059 wxLEAVE_CRIT_SECT( m_eventsLocker
);
1061 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
1069 bool wxEvtHandler::TryParent(wxEvent
& event
)
1071 if ( wxTheApp
&& (this != wxTheApp
) )
1073 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1074 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1075 // processed appropriately via SearchEventTable.
1076 if ( event
.GetEventType() != wxEVT_IDLE
)
1078 if ( wxTheApp
->ProcessEvent(event
) )
1086 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
1088 // allow the application to hook into event processing
1091 int rc
= wxTheApp
->FilterEvent(event
);
1094 wxASSERT_MSG( rc
== 1 || rc
== 0,
1095 _T("unexpected wxApp::FilterEvent return value") );
1099 //else: proceed normally
1102 // An event handler can be enabled or disabled
1103 if ( GetEvtHandlerEnabled() )
1105 // if we have a validator, it has higher priority than our own event
1107 if ( TryValidator(event
) )
1110 // Handle per-instance dynamic event tables first
1111 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
1114 // Then static per-class event tables
1115 if ( GetEventHashTable().HandleEvent(event
, this) )
1119 // Try going down the event handler chain
1120 if ( GetNextHandler() )
1122 if ( GetNextHandler()->ProcessEvent(event
) )
1126 // Finally propagate the event upwards the window chain and/or to the
1127 // application object as necessary
1128 return TryParent(event
);
1132 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
1134 wxEventType eventType
= event
.GetEventType();
1135 int eventId
= event
.GetId();
1137 // BC++ doesn't like testing for m_fn without != 0
1138 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
1140 // the line using reference exposes a bug in gcc: although it _seems_
1141 // to work, it leads to weird crashes later on during program
1144 wxEventTableEntry entry
= table
.entries
[i
];
1146 const wxEventTableEntry
& entry
= table
.entries
[i
];
1149 // match only if the event type is the same and the id is either -1 in
1150 // the event table (meaning "any") or the event id matches the id
1151 // specified in the event table either exactly or by falling into
1152 // range between first and last
1153 if ( eventType
== entry
.m_eventType
)
1155 int tableId1
= entry
.m_id
,
1156 tableId2
= entry
.m_lastId
;
1158 if ( (tableId1
== -1) ||
1159 (tableId2
== -1 && eventId
== tableId1
) ||
1161 (eventId
>= tableId1
&& eventId
<= tableId2
)) )
1164 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1166 (this->*((wxEventFunction
) (entry
.m_fn
)))(event
);
1168 return !event
.GetSkipped();
1176 void wxEvtHandler::Connect( int id
, int lastId
,
1178 wxObjectEventFunction func
,
1180 wxEvtHandler
* eventSink
)
1182 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1183 wxEventTableEntry
*entry
= new wxEventTableEntry
;
1184 entry
->m_eventType
= eventType
;
1186 entry
->m_lastId
= lastId
;
1188 entry
->m_callbackUserData
= userData
;
1189 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1190 wxDynamicEventTableEntry
*entry
=
1191 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
, eventSink
);
1192 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1194 if (!m_dynamicEvents
)
1195 m_dynamicEvents
= new wxList
;
1197 // Insert at the front of the list so most recent additions are found first
1198 m_dynamicEvents
->Insert( (wxObject
*) entry
);
1201 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1202 wxObjectEventFunction func
,
1204 wxEvtHandler
* eventSink
)
1206 if (!m_dynamicEvents
)
1209 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1212 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1213 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
1214 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1215 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1216 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1218 if ((entry
->m_id
== id
) &&
1219 ((entry
->m_lastId
== lastId
) || (lastId
== -1)) &&
1220 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1221 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1222 ((entry
->m_eventSink
== eventSink
) || (eventSink
== (wxEvtHandler
*)NULL
)) &&
1223 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1225 if (entry
->m_callbackUserData
)
1226 delete entry
->m_callbackUserData
;
1227 m_dynamicEvents
->Erase( node
);
1231 node
= node
->GetNext();
1236 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1238 wxCHECK_MSG( m_dynamicEvents
, FALSE
,
1239 wxT("caller should check that we have dynamic events") );
1241 int commandId
= event
.GetId();
1243 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1246 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1247 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
1248 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1249 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1250 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1254 // Match, if event spec says any id will do (id == -1)
1255 if ( (event
.GetEventType() == entry
->m_eventType
) &&
1256 (entry
->m_id
== -1 ||
1257 (entry
->m_lastId
== -1 && commandId
== entry
->m_id
) ||
1258 (entry
->m_lastId
!= -1 &&
1259 (commandId
>= entry
->m_id
&& commandId
<= entry
->m_lastId
))) )
1262 event
.m_callbackUserData
= entry
->m_callbackUserData
;
1264 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
1265 if (entry
->m_eventSink
)
1266 ((entry
->m_eventSink
)->*((wxEventFunction
) (entry
->m_fn
)))(event
);
1269 (this->*((wxEventFunction
) (entry
->m_fn
)))(event
);
1271 if ( ! event
.GetSkipped() )
1275 node
= node
->GetNext();
1280 void wxEvtHandler::DoSetClientObject( wxClientData
*data
)
1282 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1283 wxT("can't have both object and void client data") );
1285 if ( m_clientObject
)
1286 delete m_clientObject
;
1288 m_clientObject
= data
;
1289 m_clientDataType
= wxClientData_Object
;
1292 wxClientData
*wxEvtHandler::DoGetClientObject() const
1294 // it's not an error to call GetClientObject() on a window which doesn't
1295 // have client data at all - NULL will be returned
1296 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1297 wxT("this window doesn't have object client data") );
1299 return m_clientObject
;
1302 void wxEvtHandler::DoSetClientData( void *data
)
1304 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1305 wxT("can't have both object and void client data") );
1307 m_clientData
= data
;
1308 m_clientDataType
= wxClientData_Void
;
1311 void *wxEvtHandler::DoGetClientData() const
1313 // it's not an error to call GetClientData() on a window which doesn't have
1314 // client data at all - NULL will be returned
1315 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1316 wxT("this window doesn't have void client data") );
1318 return m_clientData
;
1321 #endif // wxUSE_BASE
1325 // Find a window with the focus, that is also a descendant of the given window.
1326 // This is used to determine the window to initially send commands to.
1327 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1329 // Process events starting with the window with the focus, if any.
1330 wxWindow
* focusWin
= wxWindow::FindFocus();
1331 wxWindow
* win
= focusWin
;
1333 // Check if this is a descendant of this frame.
1334 // If not, win will be set to NULL.
1337 if (win
== ancestor
)
1340 win
= win
->GetParent();
1342 if (win
== (wxWindow
*) NULL
)
1343 focusWin
= (wxWindow
*) NULL
;