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"
47 #include "wx/textctrl.h"
52 #include "wx/module.h"
55 #include "wx/validate.h"
57 #include "wx/stopwatch.h"
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
66 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler
, wxObject
)
67 IMPLEMENT_ABSTRACT_CLASS(wxEvent
, wxObject
)
71 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent
, wxEvent
)
72 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent
, wxEvent
)
73 IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent
, wxCommandEvent
)
74 IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent
, wxCommandEvent
)
75 IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent
, wxEvent
)
76 IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent
, wxEvent
)
77 IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent
, wxEvent
)
78 IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent
, wxEvent
)
79 IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent
, wxEvent
)
80 IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent
, wxEvent
)
81 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent
, wxEvent
)
82 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent
, wxEvent
)
83 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent
, wxEvent
)
84 IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent
, wxCommandEvent
)
85 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent
, wxEvent
)
86 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent
, wxEvent
)
87 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent
, wxEvent
)
88 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent
, wxEvent
)
89 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent
, wxEvent
)
90 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent
, wxEvent
)
91 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent
, wxEvent
)
92 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent
, wxEvent
)
93 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent
, wxEvent
)
94 IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent
, wxEvent
)
95 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent
, wxEvent
)
96 IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent
, wxEvent
)
97 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent
, wxCommandEvent
)
98 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent
, wxEvent
)
99 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent
, wxEvent
)
100 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent
, wxEvent
)
101 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent
, wxEvent
)
102 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent
, wxEvent
)
103 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent
, wxCommandEvent
)
104 IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent
, wxCommandEvent
)
105 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent
, wxEvent
)
110 const wxEventTable
*wxEvtHandler::GetEventTable() const
111 { return &wxEvtHandler::sm_eventTable
; }
113 const wxEventTable
wxEvtHandler::sm_eventTable
=
114 { (const wxEventTable
*)NULL
, &wxEvtHandler::sm_eventTableEntries
[0] };
116 wxEventHashTable
&wxEvtHandler::GetEventHashTable() const
117 { return wxEvtHandler::sm_eventHashTable
; }
119 wxEventHashTable
wxEvtHandler::sm_eventHashTable(wxEvtHandler::sm_eventTable
);
121 const wxEventTableEntry
wxEvtHandler::sm_eventTableEntries
[] =
122 { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL
, 0, 0, (wxObjectEventFunction
)NULL
, NULL
) };
126 // Clear up event hash table contents or we can get problems
127 // when C++ is cleaning up the static object
128 class wxEventTableEntryModule
: public wxModule
130 DECLARE_DYNAMIC_CLASS(wxEventTableEntryModule
)
132 wxEventTableEntryModule() {}
133 bool OnInit() { return true; }
136 wxEventHashTable::ClearAll();
139 IMPLEMENT_DYNAMIC_CLASS(wxEventTableEntryModule
, wxModule
)
142 // ----------------------------------------------------------------------------
144 // ----------------------------------------------------------------------------
146 // To put pending event handlers
147 wxList
*wxPendingEvents
= (wxList
*)NULL
;
150 // protects wxPendingEvents list
151 wxCriticalSection
*wxPendingEventsLocker
= (wxCriticalSection
*)NULL
;
154 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
156 // common event types are defined here, other event types are defined by the
157 // components which use them
159 const wxEventType wxEVT_FIRST
= 10000;
160 const wxEventType wxEVT_USER_FIRST
= wxEVT_FIRST
+ 2000;
162 DEFINE_EVENT_TYPE(wxEVT_NULL
)
163 DEFINE_EVENT_TYPE(wxEVT_IDLE
)
164 DEFINE_EVENT_TYPE(wxEVT_SOCKET
)
166 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
172 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
174 DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED
)
175 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED
)
176 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED
)
177 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED
)
178 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
)
179 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
)
180 DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED
)
181 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED
)
182 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED
)
183 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED
)
184 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED
)
185 DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED
)
186 DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED
)
187 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED
)
188 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER
)
189 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED
)
191 // Sockets and timers send events, too
192 DEFINE_EVENT_TYPE(wxEVT_TIMER
)
195 DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN
)
196 DEFINE_EVENT_TYPE(wxEVT_LEFT_UP
)
197 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN
)
198 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP
)
199 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN
)
200 DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP
)
201 DEFINE_EVENT_TYPE(wxEVT_MOTION
)
202 DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW
)
203 DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW
)
204 DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK
)
205 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK
)
206 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK
)
207 DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS
)
208 DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS
)
209 DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS
)
210 DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL
)
212 // Non-client mouse events
213 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN
)
214 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP
)
215 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN
)
216 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP
)
217 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN
)
218 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP
)
219 DEFINE_EVENT_TYPE(wxEVT_NC_MOTION
)
220 DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW
)
221 DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW
)
222 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK
)
223 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK
)
224 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK
)
226 // Character input event type
227 DEFINE_EVENT_TYPE(wxEVT_CHAR
)
228 DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK
)
229 DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY
)
230 DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN
)
231 DEFINE_EVENT_TYPE(wxEVT_KEY_UP
)
233 DEFINE_EVENT_TYPE(wxEVT_HOTKEY
)
237 DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR
)
239 // wxScrollbar and wxSlider event identifiers
240 DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP
)
241 DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM
)
242 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP
)
243 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN
)
244 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP
)
245 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN
)
246 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK
)
247 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE
)
248 DEFINE_EVENT_TYPE(wxEVT_SCROLL_CHANGED
)
250 // see comments in wx/event.h, near wxEVT_SCROLL_ENDSCROLL declaration
251 #if wxCHECK_VERSION(2, 7, 0)
252 #error "Remove the lines below, not needed any more"
254 #undef wxEVT_SCROLL_ENDSCROLL
255 extern WXDLLIMPEXP_CORE
const wxEventType wxEVT_SCROLL_ENDSCROLL
;
256 const wxEventType wxEVT_SCROLL_ENDSCROLL
= wxEVT_SCROLL_CHANGED
;
258 // Scroll events from wxWindow
259 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP
)
260 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM
)
261 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP
)
262 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN
)
263 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP
)
264 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN
)
265 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK
)
266 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE
)
269 DEFINE_EVENT_TYPE(wxEVT_SIZE
)
270 DEFINE_EVENT_TYPE(wxEVT_SIZING
)
271 DEFINE_EVENT_TYPE(wxEVT_MOVE
)
272 DEFINE_EVENT_TYPE(wxEVT_MOVING
)
273 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW
)
274 DEFINE_EVENT_TYPE(wxEVT_END_SESSION
)
275 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION
)
276 DEFINE_EVENT_TYPE(wxEVT_HIBERNATE
)
277 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
278 DEFINE_EVENT_TYPE(wxEVT_POWER
)
279 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
280 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
281 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
282 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
283 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
284 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
285 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
286 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
287 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
288 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
289 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
290 DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN
)
291 DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE
)
292 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
293 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
294 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
295 DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED
)
296 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
297 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
298 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
299 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
300 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
301 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
302 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
303 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
304 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
305 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
306 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
307 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
308 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
310 // Generic command events
311 // Note: a click is a higher-level event than button down/up
312 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
313 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
314 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
315 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
316 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
317 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
318 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
321 DEFINE_EVENT_TYPE(wxEVT_HELP
)
322 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
324 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
330 // ============================================================================
332 // ============================================================================
334 // ----------------------------------------------------------------------------
335 // event initialization
336 // ----------------------------------------------------------------------------
341 static int s_lastUsedEventType
= wxEVT_FIRST
;
343 return s_lastUsedEventType
++;
346 // ----------------------------------------------------------------------------
348 // ----------------------------------------------------------------------------
351 * General wxWidgets events, covering
352 * all interesting things that might happen (button clicking, resizing,
353 * setting text in widgets, etc.).
355 * For each completely new event type, derive a new event class.
359 wxEvent::wxEvent(int theId
, wxEventType commandType
)
361 m_eventType
= commandType
;
362 m_eventObject
= (wxObject
*) NULL
;
366 m_callbackUserData
= (wxObject
*) NULL
;
367 m_isCommandEvent
= false;
368 m_propagationLevel
= wxEVENT_PROPAGATE_NONE
;
371 wxEvent::wxEvent(const wxEvent
&src
)
373 , m_eventObject(src
.m_eventObject
)
374 , m_eventType(src
.m_eventType
)
375 , m_timeStamp(src
.m_timeStamp
)
377 , m_callbackUserData(src
.m_callbackUserData
)
378 , m_propagationLevel(src
.m_propagationLevel
)
379 , m_skipped(src
.m_skipped
)
380 , m_isCommandEvent(src
.m_isCommandEvent
)
394 // 'this' : used in base member initializer list (for m_commandString)
395 #pragma warning(disable:4355)
398 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
399 : wxEvent(theId
, commandType
)
400 #if WXWIN_COMPATIBILITY_2_4
401 , m_commandString(this)
404 m_clientData
= (char *) NULL
;
405 m_clientObject
= (wxClientData
*) NULL
;
408 m_isCommandEvent
= true;
410 // the command events are propagated upwards by default
411 m_propagationLevel
= wxEVENT_PROPAGATE_MAX
;
415 #pragma warning(default:4355)
418 wxString
wxCommandEvent::GetString() const
420 if(m_eventType
!= wxEVT_COMMAND_TEXT_UPDATED
|| !m_eventObject
)
425 wxTextCtrl
*txt
= wxDynamicCast(m_eventObject
, wxTextCtrl
);
427 return txt
->GetValue();
429 #endif // wxUSE_TEXTCTRL
439 wxLongLong
wxUpdateUIEvent::sm_lastUpdate
= 0;
442 long wxUpdateUIEvent::sm_updateInterval
= 0;
444 wxUpdateUIMode
wxUpdateUIEvent::sm_updateMode
= wxUPDATE_UI_PROCESS_ALL
;
447 bool wxUpdateUIEvent::CanUpdate(wxWindowBase
*win
)
449 // Don't update if we've switched global updating off
450 // and this window doesn't support updates.
452 (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED
&&
453 ((win
->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES
) == 0)))
456 if (sm_updateInterval
== -1)
459 if (sm_updateInterval
== 0)
462 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
463 wxLongLong now
= wxGetLocalTimeMillis();
464 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
471 // If we don't have wxStopWatch or wxLongLong, we
472 // should err on the safe side and update now anyway.
477 // Reset the update time to provide a delay until the next
478 // time we should update
479 void wxUpdateUIEvent::ResetUpdateTime()
481 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
482 if (sm_updateInterval
> 0)
484 wxLongLong now
= wxGetLocalTimeMillis();
485 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
497 wxIdleMode
wxIdleEvent::sm_idleMode
= wxIDLE_PROCESS_ALL
;
499 // Can we send an idle event?
500 bool wxIdleEvent::CanSend(wxWindow
* win
)
502 // Don't update if we've switched global updating off
503 // and this window doesn't support updates.
505 (GetMode() == wxIDLE_PROCESS_SPECIFIED
&&
506 ((win
->GetExtraStyle() & wxWS_EX_PROCESS_IDLE
) == 0)))
516 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
520 : wxCommandEvent(commandType
, id
)
522 m_extraLong
= orient
;
530 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
534 m_eventType
= commandType
;
535 m_extraLong
= orient
;
544 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
546 m_eventType
= commandType
;
549 m_controlDown
= false;
553 m_middleDown
= false;
558 m_linesPerAction
= 0;
561 void wxMouseEvent::Assign(const wxMouseEvent
& event
)
563 m_eventType
= event
.m_eventType
;
568 m_leftDown
= event
.m_leftDown
;
569 m_middleDown
= event
.m_middleDown
;
570 m_rightDown
= event
.m_rightDown
;
572 m_controlDown
= event
.m_controlDown
;
573 m_shiftDown
= event
.m_shiftDown
;
574 m_altDown
= event
.m_altDown
;
575 m_metaDown
= event
.m_metaDown
;
577 m_wheelRotation
= event
.m_wheelRotation
;
578 m_wheelDelta
= event
.m_wheelDelta
;
579 m_linesPerAction
= event
.m_linesPerAction
;
582 // return true if was a button dclick event
583 bool wxMouseEvent::ButtonDClick(int but
) const
588 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
591 case wxMOUSE_BTN_ANY
:
592 return (LeftDClick() || MiddleDClick() || RightDClick());
594 case wxMOUSE_BTN_LEFT
:
597 case wxMOUSE_BTN_MIDDLE
:
598 return MiddleDClick();
600 case wxMOUSE_BTN_RIGHT
:
601 return RightDClick();
605 // return true if was a button down event
606 bool wxMouseEvent::ButtonDown(int but
) const
611 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
614 case wxMOUSE_BTN_ANY
:
615 return (LeftDown() || MiddleDown() || RightDown());
617 case wxMOUSE_BTN_LEFT
:
620 case wxMOUSE_BTN_MIDDLE
:
623 case wxMOUSE_BTN_RIGHT
:
628 // return true if was a button up event
629 bool wxMouseEvent::ButtonUp(int but
) const
634 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
637 case wxMOUSE_BTN_ANY
:
638 return (LeftUp() || MiddleUp() || RightUp());
640 case wxMOUSE_BTN_LEFT
:
643 case wxMOUSE_BTN_MIDDLE
:
646 case wxMOUSE_BTN_RIGHT
:
651 // return true if the given button is currently changing state
652 bool wxMouseEvent::Button(int but
) const
657 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
660 case wxMOUSE_BTN_ANY
:
661 return ButtonUp(wxMOUSE_BTN_ANY
) ||
662 ButtonDown(wxMOUSE_BTN_ANY
) ||
663 ButtonDClick(wxMOUSE_BTN_ANY
);
665 case wxMOUSE_BTN_LEFT
:
666 return LeftDown() || LeftUp() || LeftDClick();
668 case wxMOUSE_BTN_MIDDLE
:
669 return MiddleDown() || MiddleUp() || MiddleDClick();
671 case wxMOUSE_BTN_RIGHT
:
672 return RightDown() || RightUp() || RightDClick();
676 bool wxMouseEvent::ButtonIsDown(int but
) const
681 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
684 case wxMOUSE_BTN_ANY
:
685 return LeftIsDown() || MiddleIsDown() || RightIsDown();
687 case wxMOUSE_BTN_LEFT
:
690 case wxMOUSE_BTN_MIDDLE
:
691 return MiddleIsDown();
693 case wxMOUSE_BTN_RIGHT
:
694 return RightIsDown();
698 int wxMouseEvent::GetButton() const
700 for ( int i
= 1; i
<= 3; i
++ )
708 return wxMOUSE_BTN_NONE
;
711 // Find the logical position of the event given the DC
712 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
714 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
724 wxKeyEvent::wxKeyEvent(wxEventType type
)
728 m_controlDown
= false;
738 wxKeyEvent::wxKeyEvent(const wxKeyEvent
& evt
)
744 m_keyCode
= evt
.m_keyCode
;
746 m_controlDown
= evt
.m_controlDown
;
747 m_shiftDown
= evt
.m_shiftDown
;
748 m_altDown
= evt
.m_altDown
;
749 m_metaDown
= evt
.m_metaDown
;
750 m_scanCode
= evt
.m_scanCode
;
751 m_rawCode
= evt
.m_rawCode
;
752 m_rawFlags
= evt
.m_rawFlags
;
755 m_uniChar
= evt
.m_uniChar
;
759 long wxKeyEvent::KeyCode() const
764 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
766 SetEventType(wxEVT_CREATE
);
770 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
772 SetEventType(wxEVT_DESTROY
);
776 wxChildFocusEvent::wxChildFocusEvent(wxWindow
*win
)
777 : wxCommandEvent(wxEVT_CHILD_FOCUS
)
787 // ----------------------------------------------------------------------------
789 // ----------------------------------------------------------------------------
791 static const int EVENT_TYPE_TABLE_INIT_SIZE
= 31; // Not too big not too small...
793 wxEventHashTable
* wxEventHashTable::sm_first
= NULL
;
795 wxEventHashTable::wxEventHashTable(const wxEventTable
&table
)
799 AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE
);
803 m_next
->m_previous
= this;
807 wxEventHashTable::~wxEventHashTable()
810 m_next
->m_previous
= m_previous
;
812 m_previous
->m_next
= m_next
;
813 if (sm_first
== this)
819 void wxEventHashTable::Clear()
822 for(i
= 0; i
< m_size
; i
++)
824 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
831 // Necessary in order to not invoke the
832 // overloaded delete operator when statics are cleaned up
833 if (m_eventTypeTable
)
834 delete[] m_eventTypeTable
;
836 m_eventTypeTable
= NULL
;
841 void wxEventHashTable::ClearAll()
843 wxEventHashTable
* table
= sm_first
;
847 table
= table
->m_next
;
851 bool wxEventHashTable::HandleEvent(wxEvent
&event
, wxEvtHandler
*self
)
856 m_rebuildHash
= false;
859 if (!m_eventTypeTable
)
862 // Find all entries for the given event type.
863 wxEventType eventType
= event
.GetEventType();
864 const EventTypeTablePointer eTTnode
= m_eventTypeTable
[eventType
% m_size
];
865 if (eTTnode
&& eTTnode
->eventType
== eventType
)
867 // Now start the search for an event handler
868 // that can handle an event with the given ID.
869 const wxEventTableEntryPointerArray
&
870 eventEntryTable
= eTTnode
->eventEntryTable
;
872 const size_t count
= eventEntryTable
.GetCount();
873 for (size_t n
= 0; n
< count
; n
++)
876 ProcessEventIfMatches(*eventEntryTable
[n
], self
, event
) )
886 void wxEventHashTable::InitHashTable()
888 // Loop over the event tables and all its base tables.
889 const wxEventTable
*table
= &m_table
;
892 // Retrieve all valid event handler entries
893 const wxEventTableEntry
*entry
= table
->entries
;
894 while (entry
->m_fn
!= 0)
896 // Add the event entry in the Hash.
902 table
= table
->baseTable
;
905 // Lets free some memory.
907 for(i
= 0; i
< m_size
; i
++)
909 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
912 eTTnode
->eventEntryTable
.Shrink();
917 void wxEventHashTable::AddEntry(const wxEventTableEntry
&entry
)
919 // This might happen 'accidentally' as the app is exiting
920 if (!m_eventTypeTable
)
923 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[entry
.m_eventType
% m_size
];
924 EventTypeTablePointer eTTnode
= *peTTnode
;
928 if (eTTnode
->eventType
!= entry
.m_eventType
)
931 GrowEventTypeTable();
932 // Try again to add it.
939 eTTnode
= new EventTypeTable
;
940 eTTnode
->eventType
= entry
.m_eventType
;
944 // Fill all hash entries between entry.m_id and entry.m_lastId...
945 eTTnode
->eventEntryTable
.Add(&entry
);
948 void wxEventHashTable::AllocEventTypeTable(size_t size
)
950 m_eventTypeTable
= new EventTypeTablePointer
[size
];
951 memset((void *)m_eventTypeTable
, 0, sizeof(EventTypeTablePointer
)*size
);
955 void wxEventHashTable::GrowEventTypeTable()
957 size_t oldSize
= m_size
;
958 EventTypeTablePointer
*oldEventTypeTable
= m_eventTypeTable
;
960 // TODO: Search the most optimal grow sequence
961 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize
*2+1);
963 for ( size_t i
= 0; i
< oldSize
; /* */ )
965 EventTypeTablePointer eTToldNode
= oldEventTypeTable
[i
];
968 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[eTToldNode
->eventType
% m_size
];
969 EventTypeTablePointer eTTnode
= *peTTnode
;
971 // Check for collision, we don't want any.
974 GrowEventTypeTable();
975 continue; // Don't increment the counter,
976 // as we still need to add this element.
980 // Get the old value and put it in the new table.
981 *peTTnode
= oldEventTypeTable
[i
];
988 delete[] oldEventTypeTable
;
992 // ----------------------------------------------------------------------------
994 // ----------------------------------------------------------------------------
1000 wxEvtHandler::wxEvtHandler()
1002 m_nextHandler
= (wxEvtHandler
*) NULL
;
1003 m_previousHandler
= (wxEvtHandler
*) NULL
;
1005 m_dynamicEvents
= (wxList
*) NULL
;
1006 m_pendingEvents
= (wxList
*) NULL
;
1008 # if !defined(__VISAGECPP__)
1009 m_eventsLocker
= new wxCriticalSection
;
1012 // no client data (yet)
1013 m_clientData
= NULL
;
1014 m_clientDataType
= wxClientData_None
;
1017 wxEvtHandler::~wxEvtHandler()
1019 // Takes itself out of the list of handlers
1020 if (m_previousHandler
)
1021 m_previousHandler
->m_nextHandler
= m_nextHandler
;
1024 m_nextHandler
->m_previousHandler
= m_previousHandler
;
1026 if (m_dynamicEvents
)
1028 wxList::iterator it
= m_dynamicEvents
->begin(),
1029 en
= m_dynamicEvents
->end();
1030 for (;it
!= en
; ++it
)
1032 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1033 wxEventTableEntry
*entry
= (wxEventTableEntry
*)*it
;
1034 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1035 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)*it
;
1036 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1038 if (entry
->m_callbackUserData
)
1039 delete entry
->m_callbackUserData
;
1042 delete m_dynamicEvents
;
1045 delete m_pendingEvents
;
1048 # if !defined(__VISAGECPP__)
1049 delete m_eventsLocker
;
1052 // Remove us from wxPendingEvents if necessary.
1053 if(wxPendingEventsLocker
)
1054 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
1055 if ( wxPendingEvents
)
1057 // Delete all occurences of this from the list of pending events
1058 while (wxPendingEvents
->DeleteObject(this)) { } // Do nothing
1060 if(wxPendingEventsLocker
)
1061 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
1064 // we only delete object data, not untyped
1065 if ( m_clientDataType
== wxClientData_Object
)
1066 delete m_clientObject
;
1071 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
1073 // check that we are really in a child thread
1074 wxASSERT_MSG( !wxThread::IsMain(),
1075 wxT("use ProcessEvent() in main thread") );
1077 AddPendingEvent(event
);
1082 void wxEvtHandler::ClearEventLocker()
1084 #if !defined(__VISAGECPP__)
1085 delete m_eventsLocker
;
1086 m_eventsLocker
= NULL
;
1090 #endif // wxUSE_THREADS
1092 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
1094 // 1) Add event to list of pending events of this event handler
1096 wxEvent
*eventCopy
= event
.Clone();
1098 // we must be able to copy the events here so the event class must
1099 // implement Clone() properly instead of just providing a NULL stab for it
1100 wxCHECK_RET( eventCopy
,
1101 _T("events of this type aren't supposed to be posted") );
1103 wxENTER_CRIT_SECT( Lock() );
1105 if ( !m_pendingEvents
)
1106 m_pendingEvents
= new wxList
;
1108 m_pendingEvents
->Append(eventCopy
);
1110 wxLEAVE_CRIT_SECT( Lock() );
1112 // 2) Add this event handler to list of event handlers that
1113 // have pending events.
1115 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
1117 if ( !wxPendingEvents
)
1118 wxPendingEvents
= new wxList
;
1119 wxPendingEvents
->Append(this);
1121 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
1123 // 3) Inform the system that new pending events are somwehere,
1124 // and that these should be processed in idle time.
1128 void wxEvtHandler::ProcessPendingEvents()
1130 // this method is only called by wxApp if this handler does have pending
1132 wxCHECK_RET( m_pendingEvents
,
1133 wxT("Please call wxApp::ProcessPendingEvents() instead") );
1135 wxENTER_CRIT_SECT( Lock() );
1137 // we leave the loop once we have processed all events that were present at
1138 // the start of ProcessPendingEvents because otherwise we could get into
1139 // infinite loop if the pending event handler execution resulted in another
1140 // event being posted
1141 size_t n
= m_pendingEvents
->size();
1142 for ( wxList::compatibility_iterator node
= m_pendingEvents
->GetFirst();
1144 node
= m_pendingEvents
->GetFirst() )
1146 wxEvent
*event
= (wxEvent
*)node
->GetData();
1148 m_pendingEvents
->Erase(node
);
1150 wxLEAVE_CRIT_SECT( Lock() );
1152 ProcessEvent(*event
);
1155 wxENTER_CRIT_SECT( Lock() );
1161 wxLEAVE_CRIT_SECT( Lock() );
1168 wxEvtHandler::ProcessEventIfMatches(const wxEventTableEntryBase
& entry
,
1169 wxEvtHandler
*handler
,
1172 int tableId1
= entry
.m_id
,
1173 tableId2
= entry
.m_lastId
;
1175 // match only if the event type is the same and the id is either -1 in
1176 // the event table (meaning "any") or the event id matches the id
1177 // specified in the event table either exactly or by falling into
1178 // range between first and last
1179 if ((tableId1
== wxID_ANY
) ||
1180 (tableId2
== wxID_ANY
&& tableId1
== event
.GetId()) ||
1181 (tableId2
!= wxID_ANY
&&
1182 (event
.GetId() >= tableId1
&& event
.GetId() <= tableId2
)))
1185 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1187 #if wxUSE_EXCEPTIONS
1190 // call the handler via wxApp method which allows the user to catch
1191 // any exceptions which may be thrown by any handler in the program
1193 wxTheApp
->HandleEvent(handler
, (wxEventFunction
)entry
.m_fn
, event
);
1196 #endif // wxUSE_EXCEPTIONS
1198 // no need for an extra virtual function call
1199 (handler
->*((wxEventFunction
) (entry
.m_fn
)))(event
);
1202 if (!event
.GetSkipped())
1209 bool wxEvtHandler::TryParent(wxEvent
& event
)
1211 if ( wxTheApp
&& (this != wxTheApp
) )
1213 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1214 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1215 // processed appropriately via SearchEventTable.
1216 if ( event
.GetEventType() != wxEVT_IDLE
)
1218 if ( wxTheApp
->ProcessEvent(event
) )
1226 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
1228 // allow the application to hook into event processing
1231 int rc
= wxTheApp
->FilterEvent(event
);
1234 wxASSERT_MSG( rc
== 1 || rc
== 0,
1235 _T("unexpected wxApp::FilterEvent return value") );
1239 //else: proceed normally
1242 // An event handler can be enabled or disabled
1243 if ( GetEvtHandlerEnabled() )
1245 // if we have a validator, it has higher priority than our own event
1247 if ( TryValidator(event
) )
1250 // Handle per-instance dynamic event tables first
1251 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
1254 // Then static per-class event tables
1255 if ( GetEventHashTable().HandleEvent(event
, this) )
1259 // Try going down the event handler chain
1260 if ( GetNextHandler() )
1262 if ( GetNextHandler()->ProcessEvent(event
) )
1266 // Finally propagate the event upwards the window chain and/or to the
1267 // application object as necessary
1268 return TryParent(event
);
1272 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
1274 const wxEventType eventType
= event
.GetEventType();
1275 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
1277 const wxEventTableEntry
& entry
= table
.entries
[i
];
1278 if ( eventType
== entry
.m_eventType
)
1280 if ( ProcessEventIfMatches(entry
, this, event
) )
1288 void wxEvtHandler::Connect( int id
, int lastId
,
1290 wxObjectEventFunction func
,
1292 wxEvtHandler
* eventSink
)
1294 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1295 wxEventTableEntry
*entry
= new wxEventTableEntry
;
1296 entry
->m_eventType
= eventType
;
1298 entry
->m_lastId
= lastId
;
1300 entry
->m_callbackUserData
= userData
;
1301 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1302 wxDynamicEventTableEntry
*entry
=
1303 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
, eventSink
);
1304 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1306 if (!m_dynamicEvents
)
1307 m_dynamicEvents
= new wxList
;
1309 // Insert at the front of the list so most recent additions are found first
1310 m_dynamicEvents
->Insert( (wxObject
*) entry
);
1313 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1314 wxObjectEventFunction func
,
1316 wxEvtHandler
* eventSink
)
1318 if (!m_dynamicEvents
)
1321 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1324 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1325 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
1326 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1327 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1328 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1330 if ((entry
->m_id
== id
) &&
1331 ((entry
->m_lastId
== lastId
) || (lastId
== wxID_ANY
)) &&
1332 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1333 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1334 ((entry
->m_eventSink
== eventSink
) || (eventSink
== (wxEvtHandler
*)NULL
)) &&
1335 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1337 if (entry
->m_callbackUserData
)
1338 delete entry
->m_callbackUserData
;
1339 m_dynamicEvents
->Erase( node
);
1343 node
= node
->GetNext();
1348 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1350 wxCHECK_MSG( m_dynamicEvents
, false,
1351 wxT("caller should check that we have dynamic events") );
1353 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1356 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1357 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
1358 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1359 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1360 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1362 if ((event
.GetEventType() == entry
->m_eventType
) && (entry
->m_fn
!= 0))
1364 wxEvtHandler
*handler
=
1365 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
1366 entry
->m_eventSink
? entry
->m_eventSink
1371 if ( ProcessEventIfMatches(*entry
, handler
, event
) )
1377 node
= node
->GetNext();
1383 void wxEvtHandler::DoSetClientObject( wxClientData
*data
)
1385 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1386 wxT("can't have both object and void client data") );
1388 if ( m_clientObject
)
1389 delete m_clientObject
;
1391 m_clientObject
= data
;
1392 m_clientDataType
= wxClientData_Object
;
1395 wxClientData
*wxEvtHandler::DoGetClientObject() const
1397 // it's not an error to call GetClientObject() on a window which doesn't
1398 // have client data at all - NULL will be returned
1399 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1400 wxT("this window doesn't have object client data") );
1402 return m_clientObject
;
1405 void wxEvtHandler::DoSetClientData( void *data
)
1407 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1408 wxT("can't have both object and void client data") );
1410 m_clientData
= data
;
1411 m_clientDataType
= wxClientData_Void
;
1414 void *wxEvtHandler::DoGetClientData() const
1416 // it's not an error to call GetClientData() on a window which doesn't have
1417 // client data at all - NULL will be returned
1418 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1419 wxT("this window doesn't have void client data") );
1421 return m_clientData
;
1424 #endif // wxUSE_BASE
1428 // Find a window with the focus, that is also a descendant of the given window.
1429 // This is used to determine the window to initially send commands to.
1430 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1432 // Process events starting with the window with the focus, if any.
1433 wxWindow
* focusWin
= wxWindow::FindFocus();
1434 wxWindow
* win
= focusWin
;
1436 // Check if this is a descendant of this frame.
1437 // If not, win will be set to NULL.
1440 if (win
== ancestor
)
1443 win
= win
->GetParent();
1445 if (win
== (wxWindow
*) NULL
)
1446 focusWin
= (wxWindow
*) NULL
;