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_HIBERNATE
)
269 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
270 DEFINE_EVENT_TYPE(wxEVT_POWER
)
271 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
272 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
273 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
274 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
275 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
276 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
277 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
278 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
279 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
280 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
281 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
282 DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN
)
283 DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE
)
284 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
285 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
286 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
287 DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED
)
288 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
289 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
290 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
291 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
292 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
293 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
294 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
295 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
296 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
297 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
298 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
299 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
300 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
302 // Generic command events
303 // Note: a click is a higher-level event than button down/up
304 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
305 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
306 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
307 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
308 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
309 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
310 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
313 DEFINE_EVENT_TYPE(wxEVT_HELP
)
314 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
316 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
322 // ============================================================================
324 // ============================================================================
326 // ----------------------------------------------------------------------------
327 // event initialization
328 // ----------------------------------------------------------------------------
333 static int s_lastUsedEventType
= wxEVT_FIRST
;
335 return s_lastUsedEventType
++;
338 // ----------------------------------------------------------------------------
340 // ----------------------------------------------------------------------------
343 * General wxWidgets events, covering
344 * all interesting things that might happen (button clicking, resizing,
345 * setting text in widgets, etc.).
347 * For each completely new event type, derive a new event class.
351 wxEvent::wxEvent(int theId
, wxEventType commandType
)
353 m_eventType
= commandType
;
354 m_eventObject
= (wxObject
*) NULL
;
358 m_callbackUserData
= (wxObject
*) NULL
;
359 m_isCommandEvent
= false;
360 m_propagationLevel
= wxEVENT_PROPAGATE_NONE
;
363 wxEvent::wxEvent(const wxEvent
&src
)
365 , m_eventObject(src
.m_eventObject
)
366 , m_eventType(src
.m_eventType
)
367 , m_timeStamp(src
.m_timeStamp
)
369 , m_callbackUserData(src
.m_callbackUserData
)
370 , m_propagationLevel(src
.m_propagationLevel
)
371 , m_skipped(src
.m_skipped
)
372 , m_isCommandEvent(src
.m_isCommandEvent
)
386 // 'this' : used in base member initializer list (for m_commandString)
387 #pragma warning(disable:4355)
390 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
391 : wxEvent(theId
, commandType
)
392 #if WXWIN_COMPATIBILITY_2_4
393 , m_commandString(this)
396 m_clientData
= (char *) NULL
;
397 m_clientObject
= (wxClientData
*) NULL
;
400 m_isCommandEvent
= true;
402 // the command events are propagated upwards by default
403 m_propagationLevel
= wxEVENT_PROPAGATE_MAX
;
407 #pragma warning(default:4355)
410 wxString
wxCommandEvent::GetString() const
412 if(m_eventType
!= wxEVT_COMMAND_TEXT_UPDATED
|| !m_eventObject
)
417 wxTextCtrl
*txt
= wxDynamicCast(m_eventObject
, wxTextCtrl
);
419 return txt
->GetValue();
421 #endif // wxUSE_TEXTCTRL
431 wxLongLong
wxUpdateUIEvent::sm_lastUpdate
= 0;
434 long wxUpdateUIEvent::sm_updateInterval
= 0;
436 wxUpdateUIMode
wxUpdateUIEvent::sm_updateMode
= wxUPDATE_UI_PROCESS_ALL
;
439 bool wxUpdateUIEvent::CanUpdate(wxWindowBase
*win
)
441 // Don't update if we've switched global updating off
442 // and this window doesn't support updates.
444 (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED
&&
445 ((win
->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES
) == 0)))
448 if (sm_updateInterval
== -1)
451 if (sm_updateInterval
== 0)
454 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
455 wxLongLong now
= wxGetLocalTimeMillis();
456 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
463 // If we don't have wxStopWatch or wxLongLong, we
464 // should err on the safe side and update now anyway.
469 // Reset the update time to provide a delay until the next
470 // time we should update
471 void wxUpdateUIEvent::ResetUpdateTime()
473 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
474 if (sm_updateInterval
> 0)
476 wxLongLong now
= wxGetLocalTimeMillis();
477 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
489 wxIdleMode
wxIdleEvent::sm_idleMode
= wxIDLE_PROCESS_ALL
;
491 // Can we send an idle event?
492 bool wxIdleEvent::CanSend(wxWindow
* win
)
494 // Don't update if we've switched global updating off
495 // and this window doesn't support updates.
497 (GetMode() == wxIDLE_PROCESS_SPECIFIED
&&
498 ((win
->GetExtraStyle() & wxWS_EX_PROCESS_IDLE
) == 0)))
508 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
512 : wxCommandEvent(commandType
, id
)
514 m_extraLong
= orient
;
522 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
526 m_eventType
= commandType
;
527 m_extraLong
= orient
;
536 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
538 m_eventType
= commandType
;
541 m_controlDown
= false;
545 m_middleDown
= false;
550 m_linesPerAction
= 0;
553 void wxMouseEvent::Assign(const wxMouseEvent
& event
)
555 m_eventType
= event
.m_eventType
;
560 m_leftDown
= event
.m_leftDown
;
561 m_middleDown
= event
.m_middleDown
;
562 m_rightDown
= event
.m_rightDown
;
564 m_controlDown
= event
.m_controlDown
;
565 m_shiftDown
= event
.m_shiftDown
;
566 m_altDown
= event
.m_altDown
;
567 m_metaDown
= event
.m_metaDown
;
569 m_wheelRotation
= event
.m_wheelRotation
;
570 m_wheelDelta
= event
.m_wheelDelta
;
571 m_linesPerAction
= event
.m_linesPerAction
;
574 // return true if was a button dclick event
575 bool wxMouseEvent::ButtonDClick(int but
) const
580 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
583 case wxMOUSE_BTN_ANY
:
584 return (LeftDClick() || MiddleDClick() || RightDClick());
586 case wxMOUSE_BTN_LEFT
:
589 case wxMOUSE_BTN_MIDDLE
:
590 return MiddleDClick();
592 case wxMOUSE_BTN_RIGHT
:
593 return RightDClick();
597 // return true if was a button down event
598 bool wxMouseEvent::ButtonDown(int but
) const
603 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
606 case wxMOUSE_BTN_ANY
:
607 return (LeftDown() || MiddleDown() || RightDown());
609 case wxMOUSE_BTN_LEFT
:
612 case wxMOUSE_BTN_MIDDLE
:
615 case wxMOUSE_BTN_RIGHT
:
620 // return true if was a button up event
621 bool wxMouseEvent::ButtonUp(int but
) const
626 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
629 case wxMOUSE_BTN_ANY
:
630 return (LeftUp() || MiddleUp() || RightUp());
632 case wxMOUSE_BTN_LEFT
:
635 case wxMOUSE_BTN_MIDDLE
:
638 case wxMOUSE_BTN_RIGHT
:
643 // return true if the given button is currently changing state
644 bool wxMouseEvent::Button(int but
) const
649 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
652 case wxMOUSE_BTN_ANY
:
653 return ButtonUp(wxMOUSE_BTN_ANY
) ||
654 ButtonDown(wxMOUSE_BTN_ANY
) ||
655 ButtonDClick(wxMOUSE_BTN_ANY
);
657 case wxMOUSE_BTN_LEFT
:
658 return LeftDown() || LeftUp() || LeftDClick();
660 case wxMOUSE_BTN_MIDDLE
:
661 return MiddleDown() || MiddleUp() || MiddleDClick();
663 case wxMOUSE_BTN_RIGHT
:
664 return RightDown() || RightUp() || RightDClick();
668 bool wxMouseEvent::ButtonIsDown(int but
) const
673 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
676 case wxMOUSE_BTN_ANY
:
677 return LeftIsDown() || MiddleIsDown() || RightIsDown();
679 case wxMOUSE_BTN_LEFT
:
682 case wxMOUSE_BTN_MIDDLE
:
683 return MiddleIsDown();
685 case wxMOUSE_BTN_RIGHT
:
686 return RightIsDown();
690 int wxMouseEvent::GetButton() const
692 for ( int i
= 1; i
<= 3; i
++ )
700 return wxMOUSE_BTN_NONE
;
703 // Find the logical position of the event given the DC
704 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
706 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
716 wxKeyEvent::wxKeyEvent(wxEventType type
)
720 m_controlDown
= false;
730 wxKeyEvent::wxKeyEvent(const wxKeyEvent
& evt
)
736 m_keyCode
= evt
.m_keyCode
;
738 m_controlDown
= evt
.m_controlDown
;
739 m_shiftDown
= evt
.m_shiftDown
;
740 m_altDown
= evt
.m_altDown
;
741 m_metaDown
= evt
.m_metaDown
;
742 m_scanCode
= evt
.m_scanCode
;
743 m_rawCode
= evt
.m_rawCode
;
744 m_rawFlags
= evt
.m_rawFlags
;
747 m_uniChar
= evt
.m_uniChar
;
751 long wxKeyEvent::KeyCode() const
756 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
758 SetEventType(wxEVT_CREATE
);
762 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
764 SetEventType(wxEVT_DESTROY
);
768 wxChildFocusEvent::wxChildFocusEvent(wxWindow
*win
)
769 : wxCommandEvent(wxEVT_CHILD_FOCUS
)
779 // ----------------------------------------------------------------------------
781 // ----------------------------------------------------------------------------
783 static const int EVENT_TYPE_TABLE_INIT_SIZE
= 31; // Not too big not too small...
785 wxEventHashTable
* wxEventHashTable::sm_first
= NULL
;
787 wxEventHashTable::wxEventHashTable(const wxEventTable
&table
)
791 AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE
);
795 m_next
->m_previous
= this;
799 wxEventHashTable::~wxEventHashTable()
802 m_next
->m_previous
= m_previous
;
804 m_previous
->m_next
= m_next
;
805 if (sm_first
== this)
811 void wxEventHashTable::Clear()
814 for(i
= 0; i
< m_size
; i
++)
816 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
823 // Necessary in order to not invoke the
824 // overloaded delete operator when statics are cleaned up
825 if (m_eventTypeTable
)
826 delete[] m_eventTypeTable
;
828 m_eventTypeTable
= NULL
;
833 void wxEventHashTable::ClearAll()
835 wxEventHashTable
* table
= sm_first
;
839 table
= table
->m_next
;
843 bool wxEventHashTable::HandleEvent(wxEvent
&event
, wxEvtHandler
*self
)
848 m_rebuildHash
= false;
851 if (!m_eventTypeTable
)
854 // Find all entries for the given event type.
855 wxEventType eventType
= event
.GetEventType();
856 const EventTypeTablePointer eTTnode
= m_eventTypeTable
[eventType
% m_size
];
857 if (eTTnode
&& eTTnode
->eventType
== eventType
)
859 // Now start the search for an event handler
860 // that can handle an event with the given ID.
861 const wxEventTableEntryPointerArray
&
862 eventEntryTable
= eTTnode
->eventEntryTable
;
864 const size_t count
= eventEntryTable
.GetCount();
865 for (size_t n
= 0; n
< count
; n
++)
868 ProcessEventIfMatches(*eventEntryTable
[n
], self
, event
) )
878 void wxEventHashTable::InitHashTable()
880 // Loop over the event tables and all its base tables.
881 const wxEventTable
*table
= &m_table
;
884 // Retrieve all valid event handler entries
885 const wxEventTableEntry
*entry
= table
->entries
;
886 while (entry
->m_fn
!= 0)
888 // Add the event entry in the Hash.
894 table
= table
->baseTable
;
897 // Lets free some memory.
899 for(i
= 0; i
< m_size
; i
++)
901 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
904 eTTnode
->eventEntryTable
.Shrink();
909 void wxEventHashTable::AddEntry(const wxEventTableEntry
&entry
)
911 // This might happen 'accidentally' as the app is exiting
912 if (!m_eventTypeTable
)
915 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[entry
.m_eventType
% m_size
];
916 EventTypeTablePointer eTTnode
= *peTTnode
;
920 if (eTTnode
->eventType
!= entry
.m_eventType
)
923 GrowEventTypeTable();
924 // Try again to add it.
931 eTTnode
= new EventTypeTable
;
932 eTTnode
->eventType
= entry
.m_eventType
;
936 // Fill all hash entries between entry.m_id and entry.m_lastId...
937 eTTnode
->eventEntryTable
.Add(&entry
);
940 void wxEventHashTable::AllocEventTypeTable(size_t size
)
942 m_eventTypeTable
= new EventTypeTablePointer
[size
];
943 memset((void *)m_eventTypeTable
, 0, sizeof(EventTypeTablePointer
)*size
);
947 void wxEventHashTable::GrowEventTypeTable()
949 size_t oldSize
= m_size
;
950 EventTypeTablePointer
*oldEventTypeTable
= m_eventTypeTable
;
952 // TODO: Search the most optimal grow sequence
953 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize
*2+1);
955 for ( size_t i
= 0; i
< oldSize
; /* */ )
957 EventTypeTablePointer eTToldNode
= oldEventTypeTable
[i
];
960 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[eTToldNode
->eventType
% m_size
];
961 EventTypeTablePointer eTTnode
= *peTTnode
;
963 // Check for collision, we don't want any.
966 GrowEventTypeTable();
967 continue; // Don't increment the counter,
968 // as we still need to add this element.
972 // Get the old value and put it in the new table.
973 *peTTnode
= oldEventTypeTable
[i
];
980 delete[] oldEventTypeTable
;
984 // ----------------------------------------------------------------------------
986 // ----------------------------------------------------------------------------
992 wxEvtHandler::wxEvtHandler()
994 m_nextHandler
= (wxEvtHandler
*) NULL
;
995 m_previousHandler
= (wxEvtHandler
*) NULL
;
997 m_dynamicEvents
= (wxList
*) NULL
;
998 m_pendingEvents
= (wxList
*) NULL
;
1000 # if !defined(__VISAGECPP__)
1001 m_eventsLocker
= new wxCriticalSection
;
1004 // no client data (yet)
1005 m_clientData
= NULL
;
1006 m_clientDataType
= wxClientData_None
;
1009 wxEvtHandler::~wxEvtHandler()
1011 // Takes itself out of the list of handlers
1012 if (m_previousHandler
)
1013 m_previousHandler
->m_nextHandler
= m_nextHandler
;
1016 m_nextHandler
->m_previousHandler
= m_previousHandler
;
1018 if (m_dynamicEvents
)
1020 wxList::iterator it
= m_dynamicEvents
->begin(),
1021 en
= m_dynamicEvents
->end();
1022 for (;it
!= en
; ++it
)
1024 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1025 wxEventTableEntry
*entry
= (wxEventTableEntry
*)*it
;
1026 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1027 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)*it
;
1028 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1030 if (entry
->m_callbackUserData
)
1031 delete entry
->m_callbackUserData
;
1034 delete m_dynamicEvents
;
1037 delete m_pendingEvents
;
1040 # if !defined(__VISAGECPP__)
1041 delete m_eventsLocker
;
1044 // Remove us from wxPendingEvents if necessary.
1045 if(wxPendingEventsLocker
)
1046 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
1047 if ( wxPendingEvents
) {
1048 wxPendingEvents
->DeleteObject(this);
1050 if(wxPendingEventsLocker
)
1051 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
1054 // we only delete object data, not untyped
1055 if ( m_clientDataType
== wxClientData_Object
)
1056 delete m_clientObject
;
1061 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
1063 // check that we are really in a child thread
1064 wxASSERT_MSG( !wxThread::IsMain(),
1065 wxT("use ProcessEvent() in main thread") );
1067 AddPendingEvent(event
);
1072 void wxEvtHandler::ClearEventLocker()
1074 #if !defined(__VISAGECPP__)
1075 delete m_eventsLocker
;
1076 m_eventsLocker
= NULL
;
1080 #endif // wxUSE_THREADS
1082 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
1084 // 1) Add event to list of pending events of this event handler
1086 wxEvent
*eventCopy
= event
.Clone();
1088 // we must be able to copy the events here so the event class must
1089 // implement Clone() properly instead of just providing a NULL stab for it
1090 wxCHECK_RET( eventCopy
,
1091 _T("events of this type aren't supposed to be posted") );
1093 wxENTER_CRIT_SECT( Lock() );
1095 if ( !m_pendingEvents
)
1096 m_pendingEvents
= new wxList
;
1098 m_pendingEvents
->Append(eventCopy
);
1100 wxLEAVE_CRIT_SECT( Lock() );
1102 // 2) Add this event handler to list of event handlers that
1103 // have pending events.
1105 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
1107 if ( !wxPendingEvents
)
1108 wxPendingEvents
= new wxList
;
1109 wxPendingEvents
->Append(this);
1111 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
1113 // 3) Inform the system that new pending events are somwehere,
1114 // and that these should be processed in idle time.
1118 void wxEvtHandler::ProcessPendingEvents()
1120 // this method is only called by wxApp if this handler does have pending
1122 wxCHECK_RET( m_pendingEvents
,
1123 wxT("Please call wxApp::ProcessPendingEvents() instead") );
1125 wxENTER_CRIT_SECT( Lock() );
1127 // we leave the loop once we have processed all events that were present at
1128 // the start of ProcessPendingEvents because otherwise we could get into
1129 // infinite loop if the pending event handler execution resulted in another
1130 // event being posted
1131 size_t n
= m_pendingEvents
->size();
1132 for ( wxList::compatibility_iterator node
= m_pendingEvents
->GetFirst();
1134 node
= m_pendingEvents
->GetFirst() )
1136 wxEvent
*event
= (wxEvent
*)node
->GetData();
1138 m_pendingEvents
->Erase(node
);
1140 wxLEAVE_CRIT_SECT( Lock() );
1142 ProcessEvent(*event
);
1145 wxENTER_CRIT_SECT( Lock() );
1151 wxLEAVE_CRIT_SECT( Lock() );
1158 wxEvtHandler::ProcessEventIfMatches(const wxEventTableEntryBase
& entry
,
1159 wxEvtHandler
*handler
,
1162 int tableId1
= entry
.m_id
,
1163 tableId2
= entry
.m_lastId
;
1165 // match only if the event type is the same and the id is either -1 in
1166 // the event table (meaning "any") or the event id matches the id
1167 // specified in the event table either exactly or by falling into
1168 // range between first and last
1169 if ((tableId1
== wxID_ANY
) ||
1170 (tableId2
== wxID_ANY
&& tableId1
== event
.GetId()) ||
1171 (tableId2
!= wxID_ANY
&&
1172 (event
.GetId() >= tableId1
&& event
.GetId() <= tableId2
)))
1175 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1177 #if wxUSE_EXCEPTIONS
1180 // call the handler via wxApp method which allows the user to catch
1181 // any exceptions which may be thrown by any handler in the program
1183 wxTheApp
->HandleEvent(handler
, (wxEventFunction
)entry
.m_fn
, event
);
1186 #endif // wxUSE_EXCEPTIONS
1188 // no need for an extra virtual function call
1189 (handler
->*((wxEventFunction
) (entry
.m_fn
)))(event
);
1192 if (!event
.GetSkipped())
1199 bool wxEvtHandler::TryParent(wxEvent
& event
)
1201 if ( wxTheApp
&& (this != wxTheApp
) )
1203 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1204 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1205 // processed appropriately via SearchEventTable.
1206 if ( event
.GetEventType() != wxEVT_IDLE
)
1208 if ( wxTheApp
->ProcessEvent(event
) )
1216 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
1218 // allow the application to hook into event processing
1221 int rc
= wxTheApp
->FilterEvent(event
);
1224 wxASSERT_MSG( rc
== 1 || rc
== 0,
1225 _T("unexpected wxApp::FilterEvent return value") );
1229 //else: proceed normally
1232 // An event handler can be enabled or disabled
1233 if ( GetEvtHandlerEnabled() )
1235 // if we have a validator, it has higher priority than our own event
1237 if ( TryValidator(event
) )
1240 // Handle per-instance dynamic event tables first
1241 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
1244 // Then static per-class event tables
1245 if ( GetEventHashTable().HandleEvent(event
, this) )
1249 // Try going down the event handler chain
1250 if ( GetNextHandler() )
1252 if ( GetNextHandler()->ProcessEvent(event
) )
1256 // Finally propagate the event upwards the window chain and/or to the
1257 // application object as necessary
1258 return TryParent(event
);
1262 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
1264 const wxEventType eventType
= event
.GetEventType();
1265 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
1267 const wxEventTableEntry
& entry
= table
.entries
[i
];
1268 if ( eventType
== entry
.m_eventType
)
1270 if ( ProcessEventIfMatches(entry
, this, event
) )
1278 void wxEvtHandler::Connect( int id
, int lastId
,
1280 wxObjectEventFunction func
,
1282 wxEvtHandler
* eventSink
)
1284 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1285 wxEventTableEntry
*entry
= new wxEventTableEntry
;
1286 entry
->m_eventType
= eventType
;
1288 entry
->m_lastId
= lastId
;
1290 entry
->m_callbackUserData
= userData
;
1291 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1292 wxDynamicEventTableEntry
*entry
=
1293 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
, eventSink
);
1294 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1296 if (!m_dynamicEvents
)
1297 m_dynamicEvents
= new wxList
;
1299 // Insert at the front of the list so most recent additions are found first
1300 m_dynamicEvents
->Insert( (wxObject
*) entry
);
1303 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1304 wxObjectEventFunction func
,
1306 wxEvtHandler
* eventSink
)
1308 if (!m_dynamicEvents
)
1311 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1314 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1315 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
1316 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1317 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1318 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1320 if ((entry
->m_id
== id
) &&
1321 ((entry
->m_lastId
== lastId
) || (lastId
== wxID_ANY
)) &&
1322 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1323 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1324 ((entry
->m_eventSink
== eventSink
) || (eventSink
== (wxEvtHandler
*)NULL
)) &&
1325 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1327 if (entry
->m_callbackUserData
)
1328 delete entry
->m_callbackUserData
;
1329 m_dynamicEvents
->Erase( node
);
1333 node
= node
->GetNext();
1338 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1340 wxCHECK_MSG( m_dynamicEvents
, false,
1341 wxT("caller should check that we have dynamic events") );
1343 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1346 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1347 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
1348 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1349 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1350 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1352 if ((event
.GetEventType() == entry
->m_eventType
) && (entry
->m_fn
!= 0))
1354 wxEvtHandler
*handler
=
1355 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
1356 entry
->m_eventSink
? entry
->m_eventSink
1361 if ( ProcessEventIfMatches(*entry
, handler
, event
) )
1367 node
= node
->GetNext();
1373 void wxEvtHandler::DoSetClientObject( wxClientData
*data
)
1375 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1376 wxT("can't have both object and void client data") );
1378 if ( m_clientObject
)
1379 delete m_clientObject
;
1381 m_clientObject
= data
;
1382 m_clientDataType
= wxClientData_Object
;
1385 wxClientData
*wxEvtHandler::DoGetClientObject() const
1387 // it's not an error to call GetClientObject() on a window which doesn't
1388 // have client data at all - NULL will be returned
1389 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1390 wxT("this window doesn't have object client data") );
1392 return m_clientObject
;
1395 void wxEvtHandler::DoSetClientData( void *data
)
1397 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1398 wxT("can't have both object and void client data") );
1400 m_clientData
= data
;
1401 m_clientDataType
= wxClientData_Void
;
1404 void *wxEvtHandler::DoGetClientData() const
1406 // it's not an error to call GetClientData() on a window which doesn't have
1407 // client data at all - NULL will be returned
1408 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1409 wxT("this window doesn't have void client data") );
1411 return m_clientData
;
1414 #endif // wxUSE_BASE
1418 // Find a window with the focus, that is also a descendant of the given window.
1419 // This is used to determine the window to initially send commands to.
1420 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1422 // Process events starting with the window with the focus, if any.
1423 wxWindow
* focusWin
= wxWindow::FindFocus();
1424 wxWindow
* win
= focusWin
;
1426 // Check if this is a descendant of this frame.
1427 // If not, win will be set to NULL.
1430 if (win
== ancestor
)
1433 win
= win
->GetParent();
1435 if (win
== (wxWindow
*) NULL
)
1436 focusWin
= (wxWindow
*) NULL
;