1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Event classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
33 #include "wx/control.h"
36 #include "wx/textctrl.h"
41 #include "wx/module.h"
44 #include "wx/validate.h"
46 #include "wx/stopwatch.h"
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
55 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler
, wxObject
)
56 IMPLEMENT_ABSTRACT_CLASS(wxEvent
, wxObject
)
60 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent
, wxEvent
)
61 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent
, wxEvent
)
62 IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent
, wxCommandEvent
)
63 IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent
, wxCommandEvent
)
64 IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent
, wxEvent
)
65 IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent
, wxEvent
)
66 IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent
, wxEvent
)
67 IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent
, wxEvent
)
68 IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent
, wxEvent
)
69 IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent
, wxEvent
)
70 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent
, wxEvent
)
71 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent
, wxEvent
)
72 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent
, wxEvent
)
73 IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent
, wxCommandEvent
)
74 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent
, wxEvent
)
75 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent
, wxEvent
)
76 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent
, wxEvent
)
77 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent
, wxEvent
)
78 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent
, wxEvent
)
79 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent
, wxEvent
)
80 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent
, wxEvent
)
81 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent
, wxEvent
)
82 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent
, wxEvent
)
83 IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent
, wxEvent
)
84 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent
, wxEvent
)
85 IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent
, wxEvent
)
86 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent
, wxCommandEvent
)
87 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent
, wxEvent
)
88 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent
, wxEvent
)
89 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent
, wxEvent
)
90 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent
, wxEvent
)
91 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent
, wxEvent
)
92 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent
, wxCommandEvent
)
93 IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent
, wxCommandEvent
)
94 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent
, wxEvent
)
99 const wxEventTable
*wxEvtHandler::GetEventTable() const
100 { return &wxEvtHandler::sm_eventTable
; }
102 const wxEventTable
wxEvtHandler::sm_eventTable
=
103 { (const wxEventTable
*)NULL
, &wxEvtHandler::sm_eventTableEntries
[0] };
105 wxEventHashTable
&wxEvtHandler::GetEventHashTable() const
106 { return wxEvtHandler::sm_eventHashTable
; }
108 wxEventHashTable
wxEvtHandler::sm_eventHashTable(wxEvtHandler::sm_eventTable
);
110 const wxEventTableEntry
wxEvtHandler::sm_eventTableEntries
[] =
111 { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL
, 0, 0, (wxObjectEventFunction
)NULL
, NULL
) };
115 // Clear up event hash table contents or we can get problems
116 // when C++ is cleaning up the static object
117 class wxEventTableEntryModule
: public wxModule
119 DECLARE_DYNAMIC_CLASS(wxEventTableEntryModule
)
121 wxEventTableEntryModule() {}
122 bool OnInit() { return true; }
125 wxEventHashTable::ClearAll();
128 IMPLEMENT_DYNAMIC_CLASS(wxEventTableEntryModule
, wxModule
)
131 // ----------------------------------------------------------------------------
133 // ----------------------------------------------------------------------------
135 // To put pending event handlers
136 wxList
*wxPendingEvents
= (wxList
*)NULL
;
139 // protects wxPendingEvents list
140 wxCriticalSection
*wxPendingEventsLocker
= (wxCriticalSection
*)NULL
;
143 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
145 // common event types are defined here, other event types are defined by the
146 // components which use them
148 const wxEventType wxEVT_FIRST
= 10000;
149 const wxEventType wxEVT_USER_FIRST
= wxEVT_FIRST
+ 2000;
151 DEFINE_EVENT_TYPE(wxEVT_NULL
)
152 DEFINE_EVENT_TYPE(wxEVT_IDLE
)
153 DEFINE_EVENT_TYPE(wxEVT_SOCKET
)
155 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
161 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
163 DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED
)
164 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED
)
165 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED
)
166 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED
)
167 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
)
168 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
)
169 DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED
)
170 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED
)
171 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED
)
172 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED
)
173 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED
)
174 DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED
)
175 DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED
)
176 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED
)
177 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER
)
178 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED
)
180 // Sockets and timers send events, too
181 DEFINE_EVENT_TYPE(wxEVT_TIMER
)
184 DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN
)
185 DEFINE_EVENT_TYPE(wxEVT_LEFT_UP
)
186 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN
)
187 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP
)
188 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN
)
189 DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP
)
190 DEFINE_EVENT_TYPE(wxEVT_MOTION
)
191 DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW
)
192 DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW
)
193 DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK
)
194 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK
)
195 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK
)
196 DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS
)
197 DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS
)
198 DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS
)
199 DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL
)
201 // Non-client mouse events
202 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN
)
203 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP
)
204 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN
)
205 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP
)
206 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN
)
207 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP
)
208 DEFINE_EVENT_TYPE(wxEVT_NC_MOTION
)
209 DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW
)
210 DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW
)
211 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK
)
212 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK
)
213 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK
)
215 // Character input event type
216 DEFINE_EVENT_TYPE(wxEVT_CHAR
)
217 DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK
)
218 DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY
)
219 DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN
)
220 DEFINE_EVENT_TYPE(wxEVT_KEY_UP
)
222 DEFINE_EVENT_TYPE(wxEVT_HOTKEY
)
226 DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR
)
228 // wxScrollbar and wxSlider event identifiers
229 DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP
)
230 DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM
)
231 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP
)
232 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN
)
233 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP
)
234 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN
)
235 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK
)
236 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE
)
237 DEFINE_EVENT_TYPE(wxEVT_SCROLL_CHANGED
)
239 // see comments in wx/event.h, near wxEVT_SCROLL_ENDSCROLL declaration
240 #if wxCHECK_VERSION(2, 7, 0)
241 #error "Remove the lines below, not needed any more"
243 #undef wxEVT_SCROLL_ENDSCROLL
244 extern WXDLLIMPEXP_CORE
const wxEventType wxEVT_SCROLL_ENDSCROLL
;
245 const wxEventType wxEVT_SCROLL_ENDSCROLL
= wxEVT_SCROLL_CHANGED
;
247 // Scroll events from wxWindow
248 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP
)
249 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM
)
250 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP
)
251 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN
)
252 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP
)
253 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN
)
254 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK
)
255 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE
)
258 DEFINE_EVENT_TYPE(wxEVT_SIZE
)
259 DEFINE_EVENT_TYPE(wxEVT_SIZING
)
260 DEFINE_EVENT_TYPE(wxEVT_MOVE
)
261 DEFINE_EVENT_TYPE(wxEVT_MOVING
)
262 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW
)
263 DEFINE_EVENT_TYPE(wxEVT_END_SESSION
)
264 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION
)
265 DEFINE_EVENT_TYPE(wxEVT_HIBERNATE
)
266 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
267 DEFINE_EVENT_TYPE(wxEVT_POWER
)
268 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
269 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
270 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
271 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
272 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
273 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
274 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
275 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
276 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
277 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
278 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
279 DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN
)
280 DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE
)
281 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
282 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
283 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
284 DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED
)
285 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
286 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
287 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
288 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
289 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
290 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
291 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
292 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
293 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
294 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
295 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
296 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
297 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
299 // Generic command events
300 // Note: a click is a higher-level event than button down/up
301 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
302 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
303 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
304 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
305 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
306 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
307 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
310 DEFINE_EVENT_TYPE(wxEVT_HELP
)
311 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
313 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
319 // ============================================================================
321 // ============================================================================
323 // ----------------------------------------------------------------------------
324 // event initialization
325 // ----------------------------------------------------------------------------
330 static int s_lastUsedEventType
= wxEVT_FIRST
;
332 return s_lastUsedEventType
++;
335 // ----------------------------------------------------------------------------
337 // ----------------------------------------------------------------------------
340 * General wxWidgets events, covering
341 * all interesting things that might happen (button clicking, resizing,
342 * setting text in widgets, etc.).
344 * For each completely new event type, derive a new event class.
348 wxEvent::wxEvent(int theId
, wxEventType commandType
)
350 m_eventType
= commandType
;
351 m_eventObject
= (wxObject
*) NULL
;
355 m_callbackUserData
= (wxObject
*) NULL
;
356 m_isCommandEvent
= false;
357 m_propagationLevel
= wxEVENT_PROPAGATE_NONE
;
360 wxEvent::wxEvent(const wxEvent
&src
)
362 , m_eventObject(src
.m_eventObject
)
363 , m_eventType(src
.m_eventType
)
364 , m_timeStamp(src
.m_timeStamp
)
366 , m_callbackUserData(src
.m_callbackUserData
)
367 , m_propagationLevel(src
.m_propagationLevel
)
368 , m_skipped(src
.m_skipped
)
369 , m_isCommandEvent(src
.m_isCommandEvent
)
383 // 'this' : used in base member initializer list (for m_commandString)
384 #pragma warning(disable:4355)
387 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
388 : wxEvent(theId
, commandType
)
389 #if WXWIN_COMPATIBILITY_2_4
390 , m_commandString(this)
393 m_clientData
= (char *) NULL
;
394 m_clientObject
= (wxClientData
*) NULL
;
397 m_isCommandEvent
= true;
399 // the command events are propagated upwards by default
400 m_propagationLevel
= wxEVENT_PROPAGATE_MAX
;
404 #pragma warning(default:4355)
407 wxString
wxCommandEvent::GetString() const
409 if(m_eventType
!= wxEVT_COMMAND_TEXT_UPDATED
|| !m_eventObject
)
414 wxTextCtrl
*txt
= wxDynamicCast(m_eventObject
, wxTextCtrl
);
416 return txt
->GetValue();
418 #endif // wxUSE_TEXTCTRL
428 wxLongLong
wxUpdateUIEvent::sm_lastUpdate
= 0;
431 long wxUpdateUIEvent::sm_updateInterval
= 0;
433 wxUpdateUIMode
wxUpdateUIEvent::sm_updateMode
= wxUPDATE_UI_PROCESS_ALL
;
436 bool wxUpdateUIEvent::CanUpdate(wxWindowBase
*win
)
438 // Don't update if we've switched global updating off
439 // and this window doesn't support updates.
441 (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED
&&
442 ((win
->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES
) == 0)))
445 if (sm_updateInterval
== -1)
448 if (sm_updateInterval
== 0)
451 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
452 wxLongLong now
= wxGetLocalTimeMillis();
453 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
460 // If we don't have wxStopWatch or wxLongLong, we
461 // should err on the safe side and update now anyway.
466 // Reset the update time to provide a delay until the next
467 // time we should update
468 void wxUpdateUIEvent::ResetUpdateTime()
470 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
471 if (sm_updateInterval
> 0)
473 wxLongLong now
= wxGetLocalTimeMillis();
474 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
486 wxIdleMode
wxIdleEvent::sm_idleMode
= wxIDLE_PROCESS_ALL
;
488 // Can we send an idle event?
489 bool wxIdleEvent::CanSend(wxWindow
* win
)
491 // Don't update if we've switched global updating off
492 // and this window doesn't support updates.
494 (GetMode() == wxIDLE_PROCESS_SPECIFIED
&&
495 ((win
->GetExtraStyle() & wxWS_EX_PROCESS_IDLE
) == 0)))
505 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
509 : wxCommandEvent(commandType
, id
)
511 m_extraLong
= orient
;
519 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
523 m_eventType
= commandType
;
524 m_extraLong
= orient
;
533 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
535 m_eventType
= commandType
;
538 m_controlDown
= false;
542 m_middleDown
= false;
547 m_linesPerAction
= 0;
550 void wxMouseEvent::Assign(const wxMouseEvent
& event
)
552 m_eventType
= event
.m_eventType
;
557 m_leftDown
= event
.m_leftDown
;
558 m_middleDown
= event
.m_middleDown
;
559 m_rightDown
= event
.m_rightDown
;
561 m_controlDown
= event
.m_controlDown
;
562 m_shiftDown
= event
.m_shiftDown
;
563 m_altDown
= event
.m_altDown
;
564 m_metaDown
= event
.m_metaDown
;
566 m_wheelRotation
= event
.m_wheelRotation
;
567 m_wheelDelta
= event
.m_wheelDelta
;
568 m_linesPerAction
= event
.m_linesPerAction
;
571 // return true if was a button dclick event
572 bool wxMouseEvent::ButtonDClick(int but
) const
577 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
580 case wxMOUSE_BTN_ANY
:
581 return (LeftDClick() || MiddleDClick() || RightDClick());
583 case wxMOUSE_BTN_LEFT
:
586 case wxMOUSE_BTN_MIDDLE
:
587 return MiddleDClick();
589 case wxMOUSE_BTN_RIGHT
:
590 return RightDClick();
594 // return true if was a button down event
595 bool wxMouseEvent::ButtonDown(int but
) const
600 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
603 case wxMOUSE_BTN_ANY
:
604 return (LeftDown() || MiddleDown() || RightDown());
606 case wxMOUSE_BTN_LEFT
:
609 case wxMOUSE_BTN_MIDDLE
:
612 case wxMOUSE_BTN_RIGHT
:
617 // return true if was a button up event
618 bool wxMouseEvent::ButtonUp(int but
) const
623 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
626 case wxMOUSE_BTN_ANY
:
627 return (LeftUp() || MiddleUp() || RightUp());
629 case wxMOUSE_BTN_LEFT
:
632 case wxMOUSE_BTN_MIDDLE
:
635 case wxMOUSE_BTN_RIGHT
:
640 // return true if the given button is currently changing state
641 bool wxMouseEvent::Button(int but
) const
646 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
649 case wxMOUSE_BTN_ANY
:
650 return ButtonUp(wxMOUSE_BTN_ANY
) ||
651 ButtonDown(wxMOUSE_BTN_ANY
) ||
652 ButtonDClick(wxMOUSE_BTN_ANY
);
654 case wxMOUSE_BTN_LEFT
:
655 return LeftDown() || LeftUp() || LeftDClick();
657 case wxMOUSE_BTN_MIDDLE
:
658 return MiddleDown() || MiddleUp() || MiddleDClick();
660 case wxMOUSE_BTN_RIGHT
:
661 return RightDown() || RightUp() || RightDClick();
665 bool wxMouseEvent::ButtonIsDown(int but
) const
670 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
673 case wxMOUSE_BTN_ANY
:
674 return LeftIsDown() || MiddleIsDown() || RightIsDown();
676 case wxMOUSE_BTN_LEFT
:
679 case wxMOUSE_BTN_MIDDLE
:
680 return MiddleIsDown();
682 case wxMOUSE_BTN_RIGHT
:
683 return RightIsDown();
687 int wxMouseEvent::GetButton() const
689 for ( int i
= 1; i
<= 3; i
++ )
697 return wxMOUSE_BTN_NONE
;
700 // Find the logical position of the event given the DC
701 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
703 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
713 wxKeyEvent::wxKeyEvent(wxEventType type
)
717 m_controlDown
= false;
727 wxKeyEvent::wxKeyEvent(const wxKeyEvent
& evt
)
733 m_keyCode
= evt
.m_keyCode
;
735 m_controlDown
= evt
.m_controlDown
;
736 m_shiftDown
= evt
.m_shiftDown
;
737 m_altDown
= evt
.m_altDown
;
738 m_metaDown
= evt
.m_metaDown
;
739 m_scanCode
= evt
.m_scanCode
;
740 m_rawCode
= evt
.m_rawCode
;
741 m_rawFlags
= evt
.m_rawFlags
;
744 m_uniChar
= evt
.m_uniChar
;
748 long wxKeyEvent::KeyCode() const
753 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
755 SetEventType(wxEVT_CREATE
);
759 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
761 SetEventType(wxEVT_DESTROY
);
765 wxChildFocusEvent::wxChildFocusEvent(wxWindow
*win
)
766 : wxCommandEvent(wxEVT_CHILD_FOCUS
)
776 // ----------------------------------------------------------------------------
778 // ----------------------------------------------------------------------------
780 static const int EVENT_TYPE_TABLE_INIT_SIZE
= 31; // Not too big not too small...
782 wxEventHashTable
* wxEventHashTable::sm_first
= NULL
;
784 wxEventHashTable::wxEventHashTable(const wxEventTable
&table
)
788 AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE
);
792 m_next
->m_previous
= this;
796 wxEventHashTable::~wxEventHashTable()
799 m_next
->m_previous
= m_previous
;
801 m_previous
->m_next
= m_next
;
802 if (sm_first
== this)
808 void wxEventHashTable::Clear()
811 for(i
= 0; i
< m_size
; i
++)
813 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
820 // Necessary in order to not invoke the
821 // overloaded delete operator when statics are cleaned up
822 if (m_eventTypeTable
)
823 delete[] m_eventTypeTable
;
825 m_eventTypeTable
= NULL
;
830 void wxEventHashTable::ClearAll()
832 wxEventHashTable
* table
= sm_first
;
836 table
= table
->m_next
;
840 bool wxEventHashTable::HandleEvent(wxEvent
&event
, wxEvtHandler
*self
)
845 m_rebuildHash
= false;
848 if (!m_eventTypeTable
)
851 // Find all entries for the given event type.
852 wxEventType eventType
= event
.GetEventType();
853 const EventTypeTablePointer eTTnode
= m_eventTypeTable
[eventType
% m_size
];
854 if (eTTnode
&& eTTnode
->eventType
== eventType
)
856 // Now start the search for an event handler
857 // that can handle an event with the given ID.
858 const wxEventTableEntryPointerArray
&
859 eventEntryTable
= eTTnode
->eventEntryTable
;
861 const size_t count
= eventEntryTable
.GetCount();
862 for (size_t n
= 0; n
< count
; n
++)
865 ProcessEventIfMatches(*eventEntryTable
[n
], self
, event
) )
875 void wxEventHashTable::InitHashTable()
877 // Loop over the event tables and all its base tables.
878 const wxEventTable
*table
= &m_table
;
881 // Retrieve all valid event handler entries
882 const wxEventTableEntry
*entry
= table
->entries
;
883 while (entry
->m_fn
!= 0)
885 // Add the event entry in the Hash.
891 table
= table
->baseTable
;
894 // Lets free some memory.
896 for(i
= 0; i
< m_size
; i
++)
898 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
901 eTTnode
->eventEntryTable
.Shrink();
906 void wxEventHashTable::AddEntry(const wxEventTableEntry
&entry
)
908 // This might happen 'accidentally' as the app is exiting
909 if (!m_eventTypeTable
)
912 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[entry
.m_eventType
% m_size
];
913 EventTypeTablePointer eTTnode
= *peTTnode
;
917 if (eTTnode
->eventType
!= entry
.m_eventType
)
920 GrowEventTypeTable();
921 // Try again to add it.
928 eTTnode
= new EventTypeTable
;
929 eTTnode
->eventType
= entry
.m_eventType
;
933 // Fill all hash entries between entry.m_id and entry.m_lastId...
934 eTTnode
->eventEntryTable
.Add(&entry
);
937 void wxEventHashTable::AllocEventTypeTable(size_t size
)
939 m_eventTypeTable
= new EventTypeTablePointer
[size
];
940 memset((void *)m_eventTypeTable
, 0, sizeof(EventTypeTablePointer
)*size
);
944 void wxEventHashTable::GrowEventTypeTable()
946 size_t oldSize
= m_size
;
947 EventTypeTablePointer
*oldEventTypeTable
= m_eventTypeTable
;
949 // TODO: Search the most optimal grow sequence
950 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize
*2+1);
952 for ( size_t i
= 0; i
< oldSize
; /* */ )
954 EventTypeTablePointer eTToldNode
= oldEventTypeTable
[i
];
957 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[eTToldNode
->eventType
% m_size
];
958 EventTypeTablePointer eTTnode
= *peTTnode
;
960 // Check for collision, we don't want any.
963 GrowEventTypeTable();
964 continue; // Don't increment the counter,
965 // as we still need to add this element.
969 // Get the old value and put it in the new table.
970 *peTTnode
= oldEventTypeTable
[i
];
977 delete[] oldEventTypeTable
;
981 // ----------------------------------------------------------------------------
983 // ----------------------------------------------------------------------------
989 wxEvtHandler::wxEvtHandler()
991 m_nextHandler
= (wxEvtHandler
*) NULL
;
992 m_previousHandler
= (wxEvtHandler
*) NULL
;
994 m_dynamicEvents
= (wxList
*) NULL
;
995 m_pendingEvents
= (wxList
*) NULL
;
997 # if !defined(__VISAGECPP__)
998 m_eventsLocker
= new wxCriticalSection
;
1001 // no client data (yet)
1002 m_clientData
= NULL
;
1003 m_clientDataType
= wxClientData_None
;
1006 wxEvtHandler::~wxEvtHandler()
1008 // Takes itself out of the list of handlers
1009 if (m_previousHandler
)
1010 m_previousHandler
->m_nextHandler
= m_nextHandler
;
1013 m_nextHandler
->m_previousHandler
= m_previousHandler
;
1015 if (m_dynamicEvents
)
1017 wxList::iterator it
= m_dynamicEvents
->begin(),
1018 en
= m_dynamicEvents
->end();
1019 for (;it
!= en
; ++it
)
1021 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1022 wxEventTableEntry
*entry
= (wxEventTableEntry
*)*it
;
1023 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1024 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)*it
;
1025 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1027 if (entry
->m_callbackUserData
)
1028 delete entry
->m_callbackUserData
;
1031 delete m_dynamicEvents
;
1034 delete m_pendingEvents
;
1037 # if !defined(__VISAGECPP__)
1038 delete m_eventsLocker
;
1041 // Remove us from wxPendingEvents if necessary.
1042 if(wxPendingEventsLocker
)
1043 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
1044 if ( wxPendingEvents
)
1046 // Delete all occurences of this from the list of pending events
1047 while (wxPendingEvents
->DeleteObject(this)) { } // Do nothing
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
;