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_ENDSCROLL
)
250 // Scroll events from wxWindow
251 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP
)
252 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM
)
253 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP
)
254 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN
)
255 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP
)
256 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN
)
257 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK
)
258 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE
)
261 DEFINE_EVENT_TYPE(wxEVT_SIZE
)
262 DEFINE_EVENT_TYPE(wxEVT_SIZING
)
263 DEFINE_EVENT_TYPE(wxEVT_MOVE
)
264 DEFINE_EVENT_TYPE(wxEVT_MOVING
)
265 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW
)
266 DEFINE_EVENT_TYPE(wxEVT_END_SESSION
)
267 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION
)
268 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
269 DEFINE_EVENT_TYPE(wxEVT_POWER
)
270 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
271 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
272 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
273 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
274 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
275 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
276 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
277 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
278 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
279 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
280 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
281 DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN
)
282 DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE
)
283 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
284 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
285 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
286 DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED
)
287 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
288 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
289 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
290 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
291 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
292 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
293 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
294 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
295 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
296 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
297 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
298 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
299 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
301 // Generic command events
302 // Note: a click is a higher-level event than button down/up
303 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
304 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
305 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
306 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
307 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
308 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
309 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
312 DEFINE_EVENT_TYPE(wxEVT_HELP
)
313 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
315 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
321 // ============================================================================
323 // ============================================================================
325 // ----------------------------------------------------------------------------
326 // event initialization
327 // ----------------------------------------------------------------------------
332 static int s_lastUsedEventType
= wxEVT_FIRST
;
334 return s_lastUsedEventType
++;
337 // ----------------------------------------------------------------------------
339 // ----------------------------------------------------------------------------
342 * General wxWidgets events, covering
343 * all interesting things that might happen (button clicking, resizing,
344 * setting text in widgets, etc.).
346 * For each completely new event type, derive a new event class.
350 wxEvent::wxEvent(int theId
, wxEventType commandType
)
352 m_eventType
= commandType
;
353 m_eventObject
= (wxObject
*) NULL
;
357 m_callbackUserData
= (wxObject
*) NULL
;
358 m_isCommandEvent
= false;
359 m_propagationLevel
= wxEVENT_PROPAGATE_NONE
;
362 wxEvent::wxEvent(const wxEvent
&src
)
364 , m_eventObject(src
.m_eventObject
)
365 , m_eventType(src
.m_eventType
)
366 , m_timeStamp(src
.m_timeStamp
)
368 , m_callbackUserData(src
.m_callbackUserData
)
369 , m_propagationLevel(src
.m_propagationLevel
)
370 , m_skipped(src
.m_skipped
)
371 , m_isCommandEvent(src
.m_isCommandEvent
)
385 // 'this' : used in base member initializer list (for m_commandString)
386 #pragma warning(disable:4355)
389 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
390 : wxEvent(theId
, commandType
)
391 #if WXWIN_COMPATIBILITY_2_4
392 , m_commandString(this)
395 m_clientData
= (char *) NULL
;
396 m_clientObject
= (wxClientData
*) NULL
;
399 m_isCommandEvent
= true;
401 // the command events are propagated upwards by default
402 m_propagationLevel
= wxEVENT_PROPAGATE_MAX
;
406 #pragma warning(default:4355)
409 wxString
wxCommandEvent::GetString() const
411 if(m_eventType
!= wxEVT_COMMAND_TEXT_UPDATED
|| !m_eventObject
)
416 wxTextCtrl
*txt
= wxDynamicCast(m_eventObject
, wxTextCtrl
);
418 return txt
->GetValue();
420 #endif // wxUSE_TEXTCTRL
430 wxLongLong
wxUpdateUIEvent::sm_lastUpdate
= 0;
433 long wxUpdateUIEvent::sm_updateInterval
= 0;
435 wxUpdateUIMode
wxUpdateUIEvent::sm_updateMode
= wxUPDATE_UI_PROCESS_ALL
;
438 bool wxUpdateUIEvent::CanUpdate(wxWindowBase
*win
)
440 // Don't update if we've switched global updating off
441 // and this window doesn't support updates.
443 (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED
&&
444 ((win
->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES
) == 0)))
447 if (sm_updateInterval
== -1)
450 if (sm_updateInterval
== 0)
453 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
454 wxLongLong now
= wxGetLocalTimeMillis();
455 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
462 // If we don't have wxStopWatch or wxLongLong, we
463 // should err on the safe side and update now anyway.
468 // Reset the update time to provide a delay until the next
469 // time we should update
470 void wxUpdateUIEvent::ResetUpdateTime()
472 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
473 if (sm_updateInterval
> 0)
475 wxLongLong now
= wxGetLocalTimeMillis();
476 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
488 wxIdleMode
wxIdleEvent::sm_idleMode
= wxIDLE_PROCESS_ALL
;
490 // Can we send an idle event?
491 bool wxIdleEvent::CanSend(wxWindow
* win
)
493 // Don't update if we've switched global updating off
494 // and this window doesn't support updates.
496 (GetMode() == wxIDLE_PROCESS_SPECIFIED
&&
497 ((win
->GetExtraStyle() & wxWS_EX_PROCESS_IDLE
) == 0)))
507 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
511 : wxCommandEvent(commandType
, id
)
513 m_extraLong
= orient
;
521 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
525 m_eventType
= commandType
;
526 m_extraLong
= orient
;
535 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
537 m_eventType
= commandType
;
540 m_controlDown
= false;
544 m_middleDown
= false;
549 m_linesPerAction
= 0;
552 void wxMouseEvent::Assign(const wxMouseEvent
& event
)
554 m_eventType
= event
.m_eventType
;
559 m_leftDown
= event
.m_leftDown
;
560 m_middleDown
= event
.m_middleDown
;
561 m_rightDown
= event
.m_rightDown
;
563 m_controlDown
= event
.m_controlDown
;
564 m_shiftDown
= event
.m_shiftDown
;
565 m_altDown
= event
.m_altDown
;
566 m_metaDown
= event
.m_metaDown
;
568 m_wheelRotation
= event
.m_wheelRotation
;
569 m_wheelDelta
= event
.m_wheelDelta
;
570 m_linesPerAction
= event
.m_linesPerAction
;
573 // return true if was a button dclick event
574 bool wxMouseEvent::ButtonDClick(int but
) const
579 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
582 case wxMOUSE_BTN_ANY
:
583 return (LeftDClick() || MiddleDClick() || RightDClick());
585 case wxMOUSE_BTN_LEFT
:
588 case wxMOUSE_BTN_MIDDLE
:
589 return MiddleDClick();
591 case wxMOUSE_BTN_RIGHT
:
592 return RightDClick();
596 // return true if was a button down event
597 bool wxMouseEvent::ButtonDown(int but
) const
602 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
605 case wxMOUSE_BTN_ANY
:
606 return (LeftDown() || MiddleDown() || RightDown());
608 case wxMOUSE_BTN_LEFT
:
611 case wxMOUSE_BTN_MIDDLE
:
614 case wxMOUSE_BTN_RIGHT
:
619 // return true if was a button up event
620 bool wxMouseEvent::ButtonUp(int but
) const
625 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
628 case wxMOUSE_BTN_ANY
:
629 return (LeftUp() || MiddleUp() || RightUp());
631 case wxMOUSE_BTN_LEFT
:
634 case wxMOUSE_BTN_MIDDLE
:
637 case wxMOUSE_BTN_RIGHT
:
642 // return true if the given button is currently changing state
643 bool wxMouseEvent::Button(int but
) const
648 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
651 case wxMOUSE_BTN_ANY
:
652 return ButtonUp(wxMOUSE_BTN_ANY
) ||
653 ButtonDown(wxMOUSE_BTN_ANY
) ||
654 ButtonDClick(wxMOUSE_BTN_ANY
);
656 case wxMOUSE_BTN_LEFT
:
657 return LeftDown() || LeftUp() || LeftDClick();
659 case wxMOUSE_BTN_MIDDLE
:
660 return MiddleDown() || MiddleUp() || MiddleDClick();
662 case wxMOUSE_BTN_RIGHT
:
663 return RightDown() || RightUp() || RightDClick();
667 bool wxMouseEvent::ButtonIsDown(int but
) const
672 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
675 case wxMOUSE_BTN_ANY
:
676 return LeftIsDown() || MiddleIsDown() || RightIsDown();
678 case wxMOUSE_BTN_LEFT
:
681 case wxMOUSE_BTN_MIDDLE
:
682 return MiddleIsDown();
684 case wxMOUSE_BTN_RIGHT
:
685 return RightIsDown();
689 int wxMouseEvent::GetButton() const
691 for ( int i
= 1; i
<= 3; i
++ )
699 return wxMOUSE_BTN_NONE
;
702 // Find the logical position of the event given the DC
703 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
705 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
715 wxKeyEvent::wxKeyEvent(wxEventType type
)
719 m_controlDown
= false;
729 wxKeyEvent::wxKeyEvent(const wxKeyEvent
& evt
)
735 m_keyCode
= evt
.m_keyCode
;
737 m_controlDown
= evt
.m_controlDown
;
738 m_shiftDown
= evt
.m_shiftDown
;
739 m_altDown
= evt
.m_altDown
;
740 m_metaDown
= evt
.m_metaDown
;
741 m_scanCode
= evt
.m_scanCode
;
742 m_rawCode
= evt
.m_rawCode
;
743 m_rawFlags
= evt
.m_rawFlags
;
746 m_uniChar
= evt
.m_uniChar
;
750 long wxKeyEvent::KeyCode() const
755 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
757 SetEventType(wxEVT_CREATE
);
761 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
763 SetEventType(wxEVT_DESTROY
);
767 wxChildFocusEvent::wxChildFocusEvent(wxWindow
*win
)
768 : wxCommandEvent(wxEVT_CHILD_FOCUS
)
778 // ----------------------------------------------------------------------------
780 // ----------------------------------------------------------------------------
782 static const int EVENT_TYPE_TABLE_INIT_SIZE
= 31; // Not too big not too small...
784 wxEventHashTable
* wxEventHashTable::sm_first
= NULL
;
786 wxEventHashTable::wxEventHashTable(const wxEventTable
&table
)
790 AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE
);
794 m_next
->m_previous
= this;
798 wxEventHashTable::~wxEventHashTable()
801 m_next
->m_previous
= m_previous
;
803 m_previous
->m_next
= m_next
;
804 if (sm_first
== this)
810 void wxEventHashTable::Clear()
813 for(i
= 0; i
< m_size
; i
++)
815 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
822 // Necessary in order to not invoke the
823 // overloaded delete operator when statics are cleaned up
824 if (m_eventTypeTable
)
825 delete[] m_eventTypeTable
;
827 m_eventTypeTable
= NULL
;
832 void wxEventHashTable::ClearAll()
834 wxEventHashTable
* table
= sm_first
;
838 table
= table
->m_next
;
842 bool wxEventHashTable::HandleEvent(wxEvent
&event
, wxEvtHandler
*self
)
847 m_rebuildHash
= false;
850 if (!m_eventTypeTable
)
853 // Find all entries for the given event type.
854 wxEventType eventType
= event
.GetEventType();
855 const EventTypeTablePointer eTTnode
= m_eventTypeTable
[eventType
% m_size
];
856 if (eTTnode
&& eTTnode
->eventType
== eventType
)
858 // Now start the search for an event handler
859 // that can handle an event with the given ID.
860 const wxEventTableEntryPointerArray
&
861 eventEntryTable
= eTTnode
->eventEntryTable
;
863 const size_t count
= eventEntryTable
.GetCount();
864 for (size_t n
= 0; n
< count
; n
++)
867 ProcessEventIfMatches(*eventEntryTable
[n
], self
, event
) )
877 void wxEventHashTable::InitHashTable()
879 // Loop over the event tables and all its base tables.
880 const wxEventTable
*table
= &m_table
;
883 // Retrieve all valid event handler entries
884 const wxEventTableEntry
*entry
= table
->entries
;
885 while (entry
->m_fn
!= 0)
887 // Add the event entry in the Hash.
893 table
= table
->baseTable
;
896 // Lets free some memory.
898 for(i
= 0; i
< m_size
; i
++)
900 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
903 eTTnode
->eventEntryTable
.Shrink();
908 void wxEventHashTable::AddEntry(const wxEventTableEntry
&entry
)
910 // This might happen 'accidentally' as the app is exiting
911 if (!m_eventTypeTable
)
914 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[entry
.m_eventType
% m_size
];
915 EventTypeTablePointer eTTnode
= *peTTnode
;
919 if (eTTnode
->eventType
!= entry
.m_eventType
)
922 GrowEventTypeTable();
923 // Try again to add it.
930 eTTnode
= new EventTypeTable
;
931 eTTnode
->eventType
= entry
.m_eventType
;
935 // Fill all hash entries between entry.m_id and entry.m_lastId...
936 eTTnode
->eventEntryTable
.Add(&entry
);
939 void wxEventHashTable::AllocEventTypeTable(size_t size
)
941 m_eventTypeTable
= new EventTypeTablePointer
[size
];
942 memset((void *)m_eventTypeTable
, 0, sizeof(EventTypeTablePointer
)*size
);
946 void wxEventHashTable::GrowEventTypeTable()
948 size_t oldSize
= m_size
;
949 EventTypeTablePointer
*oldEventTypeTable
= m_eventTypeTable
;
951 // TODO: Search the most optimal grow sequence
952 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize
*2+1);
954 for ( size_t i
= 0; i
< oldSize
; /* */ )
956 EventTypeTablePointer eTToldNode
= oldEventTypeTable
[i
];
959 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[eTToldNode
->eventType
% m_size
];
960 EventTypeTablePointer eTTnode
= *peTTnode
;
962 // Check for collision, we don't want any.
965 GrowEventTypeTable();
966 continue; // Don't increment the counter,
967 // as we still need to add this element.
971 // Get the old value and put it in the new table.
972 *peTTnode
= oldEventTypeTable
[i
];
979 delete[] oldEventTypeTable
;
983 // ----------------------------------------------------------------------------
985 // ----------------------------------------------------------------------------
991 wxEvtHandler::wxEvtHandler()
993 m_nextHandler
= (wxEvtHandler
*) NULL
;
994 m_previousHandler
= (wxEvtHandler
*) NULL
;
996 m_dynamicEvents
= (wxList
*) NULL
;
997 m_pendingEvents
= (wxList
*) NULL
;
999 # if !defined(__VISAGECPP__)
1000 m_eventsLocker
= new wxCriticalSection
;
1003 // no client data (yet)
1004 m_clientData
= NULL
;
1005 m_clientDataType
= wxClientData_None
;
1008 wxEvtHandler::~wxEvtHandler()
1010 // Takes itself out of the list of handlers
1011 if (m_previousHandler
)
1012 m_previousHandler
->m_nextHandler
= m_nextHandler
;
1015 m_nextHandler
->m_previousHandler
= m_previousHandler
;
1017 if (m_dynamicEvents
)
1019 wxList::iterator it
= m_dynamicEvents
->begin(),
1020 en
= m_dynamicEvents
->end();
1021 for (;it
!= en
; ++it
)
1023 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1024 wxEventTableEntry
*entry
= (wxEventTableEntry
*)*it
;
1025 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1026 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)*it
;
1027 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1029 if (entry
->m_callbackUserData
)
1030 delete entry
->m_callbackUserData
;
1033 delete m_dynamicEvents
;
1036 delete m_pendingEvents
;
1039 # if !defined(__VISAGECPP__)
1040 delete m_eventsLocker
;
1043 // Remove us from wxPendingEvents if necessary.
1044 if(wxPendingEventsLocker
)
1045 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
1046 if ( wxPendingEvents
) {
1047 wxPendingEvents
->DeleteObject(this);
1049 if(wxPendingEventsLocker
)
1050 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
1053 // we only delete object data, not untyped
1054 if ( m_clientDataType
== wxClientData_Object
)
1055 delete m_clientObject
;
1060 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
1062 // check that we are really in a child thread
1063 wxASSERT_MSG( !wxThread::IsMain(),
1064 wxT("use ProcessEvent() in main thread") );
1066 AddPendingEvent(event
);
1071 void wxEvtHandler::ClearEventLocker()
1073 #if !defined(__VISAGECPP__)
1074 delete m_eventsLocker
;
1075 m_eventsLocker
= NULL
;
1079 #endif // wxUSE_THREADS
1081 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
1083 // 1) Add event to list of pending events of this event handler
1085 wxEvent
*eventCopy
= event
.Clone();
1087 // we must be able to copy the events here so the event class must
1088 // implement Clone() properly instead of just providing a NULL stab for it
1089 wxCHECK_RET( eventCopy
,
1090 _T("events of this type aren't supposed to be posted") );
1092 wxENTER_CRIT_SECT( Lock() );
1094 if ( !m_pendingEvents
)
1095 m_pendingEvents
= new wxList
;
1097 m_pendingEvents
->Append(eventCopy
);
1099 wxLEAVE_CRIT_SECT( Lock() );
1101 // 2) Add this event handler to list of event handlers that
1102 // have pending events.
1104 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
1106 if ( !wxPendingEvents
)
1107 wxPendingEvents
= new wxList
;
1108 wxPendingEvents
->Append(this);
1110 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
1112 // 3) Inform the system that new pending events are somwehere,
1113 // and that these should be processed in idle time.
1117 void wxEvtHandler::ProcessPendingEvents()
1119 // this method is only called by wxApp if this handler does have pending
1121 wxCHECK_RET( m_pendingEvents
,
1122 wxT("Please call wxApp::ProcessPendingEvents() instead") );
1124 wxENTER_CRIT_SECT( Lock() );
1126 // we leave the loop once we have processed all events that were present at
1127 // the start of ProcessPendingEvents because otherwise we could get into
1128 // infinite loop if the pending event handler execution resulted in another
1129 // event being posted
1130 size_t n
= m_pendingEvents
->size();
1131 for ( wxList::compatibility_iterator node
= m_pendingEvents
->GetFirst();
1133 node
= m_pendingEvents
->GetFirst() )
1135 wxEvent
*event
= (wxEvent
*)node
->GetData();
1137 m_pendingEvents
->Erase(node
);
1139 wxLEAVE_CRIT_SECT( Lock() );
1141 ProcessEvent(*event
);
1144 wxENTER_CRIT_SECT( Lock() );
1150 wxLEAVE_CRIT_SECT( Lock() );
1157 wxEvtHandler::ProcessEventIfMatches(const wxEventTableEntryBase
& entry
,
1158 wxEvtHandler
*handler
,
1161 int tableId1
= entry
.m_id
,
1162 tableId2
= entry
.m_lastId
;
1164 // match only if the event type is the same and the id is either -1 in
1165 // the event table (meaning "any") or the event id matches the id
1166 // specified in the event table either exactly or by falling into
1167 // range between first and last
1168 if ((tableId1
== wxID_ANY
) ||
1169 (tableId2
== wxID_ANY
&& tableId1
== event
.GetId()) ||
1170 (tableId2
!= wxID_ANY
&&
1171 (event
.GetId() >= tableId1
&& event
.GetId() <= tableId2
)))
1174 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1176 #if wxUSE_EXCEPTIONS
1179 // call the handler via wxApp method which allows the user to catch
1180 // any exceptions which may be thrown by any handler in the program
1182 wxTheApp
->HandleEvent(handler
, (wxEventFunction
)entry
.m_fn
, event
);
1185 #endif // wxUSE_EXCEPTIONS
1187 // no need for an extra virtual function call
1188 (handler
->*((wxEventFunction
) (entry
.m_fn
)))(event
);
1191 if (!event
.GetSkipped())
1198 bool wxEvtHandler::TryParent(wxEvent
& event
)
1200 if ( wxTheApp
&& (this != wxTheApp
) )
1202 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1203 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1204 // processed appropriately via SearchEventTable.
1205 if ( event
.GetEventType() != wxEVT_IDLE
)
1207 if ( wxTheApp
->ProcessEvent(event
) )
1215 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
1217 // allow the application to hook into event processing
1220 int rc
= wxTheApp
->FilterEvent(event
);
1223 wxASSERT_MSG( rc
== 1 || rc
== 0,
1224 _T("unexpected wxApp::FilterEvent return value") );
1228 //else: proceed normally
1231 // An event handler can be enabled or disabled
1232 if ( GetEvtHandlerEnabled() )
1234 // if we have a validator, it has higher priority than our own event
1236 if ( TryValidator(event
) )
1239 // Handle per-instance dynamic event tables first
1240 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
1243 // Then static per-class event tables
1244 if ( GetEventHashTable().HandleEvent(event
, this) )
1248 // Try going down the event handler chain
1249 if ( GetNextHandler() )
1251 if ( GetNextHandler()->ProcessEvent(event
) )
1255 // Finally propagate the event upwards the window chain and/or to the
1256 // application object as necessary
1257 return TryParent(event
);
1261 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
1263 const wxEventType eventType
= event
.GetEventType();
1264 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
1266 const wxEventTableEntry
& entry
= table
.entries
[i
];
1267 if ( eventType
== entry
.m_eventType
)
1269 if ( ProcessEventIfMatches(entry
, this, event
) )
1277 void wxEvtHandler::Connect( int id
, int lastId
,
1279 wxObjectEventFunction func
,
1281 wxEvtHandler
* eventSink
)
1283 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1284 wxEventTableEntry
*entry
= new wxEventTableEntry
;
1285 entry
->m_eventType
= eventType
;
1287 entry
->m_lastId
= lastId
;
1289 entry
->m_callbackUserData
= userData
;
1290 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1291 wxDynamicEventTableEntry
*entry
=
1292 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
, eventSink
);
1293 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1295 if (!m_dynamicEvents
)
1296 m_dynamicEvents
= new wxList
;
1298 // Insert at the front of the list so most recent additions are found first
1299 m_dynamicEvents
->Insert( (wxObject
*) entry
);
1302 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1303 wxObjectEventFunction func
,
1305 wxEvtHandler
* eventSink
)
1307 if (!m_dynamicEvents
)
1310 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1313 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1314 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
1315 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1316 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1317 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1319 if ((entry
->m_id
== id
) &&
1320 ((entry
->m_lastId
== lastId
) || (lastId
== wxID_ANY
)) &&
1321 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1322 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1323 ((entry
->m_eventSink
== eventSink
) || (eventSink
== (wxEvtHandler
*)NULL
)) &&
1324 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1326 if (entry
->m_callbackUserData
)
1327 delete entry
->m_callbackUserData
;
1328 m_dynamicEvents
->Erase( node
);
1332 node
= node
->GetNext();
1337 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1339 wxCHECK_MSG( m_dynamicEvents
, false,
1340 wxT("caller should check that we have dynamic events") );
1342 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1345 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1346 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
1347 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1348 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1349 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1351 if ((event
.GetEventType() == entry
->m_eventType
) && (entry
->m_fn
!= 0))
1353 wxEvtHandler
*handler
=
1354 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
1355 entry
->m_eventSink
? entry
->m_eventSink
1360 if ( ProcessEventIfMatches(*entry
, handler
, event
) )
1366 node
= node
->GetNext();
1372 void wxEvtHandler::DoSetClientObject( wxClientData
*data
)
1374 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1375 wxT("can't have both object and void client data") );
1377 if ( m_clientObject
)
1378 delete m_clientObject
;
1380 m_clientObject
= data
;
1381 m_clientDataType
= wxClientData_Object
;
1384 wxClientData
*wxEvtHandler::DoGetClientObject() const
1386 // it's not an error to call GetClientObject() on a window which doesn't
1387 // have client data at all - NULL will be returned
1388 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1389 wxT("this window doesn't have object client data") );
1391 return m_clientObject
;
1394 void wxEvtHandler::DoSetClientData( void *data
)
1396 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1397 wxT("can't have both object and void client data") );
1399 m_clientData
= data
;
1400 m_clientDataType
= wxClientData_Void
;
1403 void *wxEvtHandler::DoGetClientData() const
1405 // it's not an error to call GetClientData() on a window which doesn't have
1406 // client data at all - NULL will be returned
1407 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1408 wxT("this window doesn't have void client data") );
1410 return m_clientData
;
1413 #endif // wxUSE_BASE
1417 // Find a window with the focus, that is also a descendant of the given window.
1418 // This is used to determine the window to initially send commands to.
1419 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1421 // Process events starting with the window with the focus, if any.
1422 wxWindow
* focusWin
= wxWindow::FindFocus();
1423 wxWindow
* win
= focusWin
;
1425 // Check if this is a descendant of this frame.
1426 // If not, win will be set to NULL.
1429 if (win
== ancestor
)
1432 win
= win
->GetParent();
1434 if (win
== (wxWindow
*) NULL
)
1435 focusWin
= (wxWindow
*) NULL
;