]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
c54de5ae | 2 | // Name: src/common/event.cpp |
c801d85f KB |
3 | // Purpose: Event classes |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
55d99c7a | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
8e193f38 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
c801d85f KB |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
0b746ba8 | 24 | #pragma hdrstop |
c801d85f KB |
25 | #endif |
26 | ||
d5da0ce7 | 27 | #include "wx/event.h" |
937013e0 | 28 | #include "wx/evtloop.h" |
d5da0ce7 | 29 | |
c801d85f | 30 | #ifndef WX_PRECOMP |
e90c1d2a | 31 | #include "wx/list.h" |
8bd9fa33 | 32 | #include "wx/log.h" |
8ecff181 | 33 | #include "wx/app.h" |
de6185e2 | 34 | #include "wx/utils.h" |
bb90a3e6 | 35 | #include "wx/stopwatch.h" |
02761f6c | 36 | #include "wx/module.h" |
e90c1d2a VZ |
37 | |
38 | #if wxUSE_GUI | |
a8ff046b | 39 | #include "wx/window.h" |
e90c1d2a | 40 | #include "wx/control.h" |
e90c1d2a | 41 | #include "wx/dc.h" |
dca94103 | 42 | #include "wx/spinbutt.h" |
75a29298 | 43 | #include "wx/textctrl.h" |
264cb7f5 | 44 | #include "wx/validate.h" |
e90c1d2a | 45 | #endif // wxUSE_GUI |
c801d85f KB |
46 | #endif |
47 | ||
204abcd4 | 48 | #include "wx/thread.h" |
47b6fabc | 49 | |
d102b02a | 50 | #if wxUSE_BASE |
664e1314 | 51 | #include "wx/scopedptr.h" |
d102b02a VZ |
52 | |
53 | wxDECLARE_SCOPED_PTR(wxEvent, wxEventPtr) | |
54 | wxDEFINE_SCOPED_PTR(wxEvent, wxEventPtr) | |
55 | #endif // wxUSE_BASE | |
204abcd4 | 56 | |
8e193f38 VZ |
57 | // ---------------------------------------------------------------------------- |
58 | // wxWin macros | |
59 | // ---------------------------------------------------------------------------- | |
60 | ||
3ed2104c VZ |
61 | #if wxUSE_BASE |
62 | IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject) | |
63 | IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject) | |
b46b1d59 | 64 | IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent) |
3ed2104c | 65 | #endif // wxUSE_BASE |
e90c1d2a | 66 | |
23f681ec VZ |
67 | #if wxUSE_GUI |
68 | IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent) | |
43c8c1f3 | 69 | IMPLEMENT_DYNAMIC_CLASS(wxThreadEvent, wxCommandEvent) |
23f681ec VZ |
70 | IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent) |
71 | IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent) | |
72 | IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent, wxEvent) | |
73 | IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent) | |
74 | IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent) | |
75 | IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent) | |
76 | IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent) | |
1e6feb95 | 77 | IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent, wxEvent) |
23f681ec VZ |
78 | IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent) |
79 | IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent) | |
80 | IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent) | |
456bc6d9 | 81 | IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent, wxCommandEvent) |
23f681ec VZ |
82 | IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent) |
83 | IMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent) | |
84 | IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent) | |
85 | IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent) | |
86 | IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent) | |
87 | IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent) | |
88 | IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent) | |
89 | IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent) | |
90 | IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent) | |
8e72b8b5 | 91 | IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent, wxEvent) |
23f681ec | 92 | IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent) |
574c939e | 93 | IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent, wxEvent) |
23f681ec | 94 | IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent) |
75299490 | 95 | IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxEvent) |
23f681ec VZ |
96 | IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, wxEvent) |
97 | IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent, wxEvent) | |
98 | IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent, wxEvent) | |
99 | IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent, wxEvent) | |
b96340e6 | 100 | IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent, wxCommandEvent) |
69231000 | 101 | IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent, wxCommandEvent) |
a5e84126 | 102 | IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent, wxEvent) |
63e819f2 | 103 | IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureLostEvent, wxEvent) |
78c91815 | 104 | IMPLEMENT_DYNAMIC_CLASS(wxClipboardTextEvent, wxCommandEvent) |
23f681ec | 105 | #endif // wxUSE_GUI |
0b746ba8 | 106 | |
3ed2104c VZ |
107 | #if wxUSE_BASE |
108 | ||
23f681ec VZ |
109 | const wxEventTable *wxEvtHandler::GetEventTable() const |
110 | { return &wxEvtHandler::sm_eventTable; } | |
0b746ba8 | 111 | |
23f681ec VZ |
112 | const wxEventTable wxEvtHandler::sm_eventTable = |
113 | { (const wxEventTable *)NULL, &wxEvtHandler::sm_eventTableEntries[0] }; | |
0b746ba8 | 114 | |
b5a98acd VZ |
115 | wxEventHashTable &wxEvtHandler::GetEventHashTable() const |
116 | { return wxEvtHandler::sm_eventHashTable; } | |
117 | ||
118 | wxEventHashTable wxEvtHandler::sm_eventHashTable(wxEvtHandler::sm_eventTable); | |
119 | ||
23f681ec | 120 | const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] = |
3c778901 | 121 | { DECLARE_EVENT_TABLE_TERMINATOR() }; |
c801d85f | 122 | |
1a18887b | 123 | |
a0826b11 VZ |
124 | // wxUSE_MEMORY_TRACING considers memory freed from the static objects dtors |
125 | // leaked, so we need to manually clean up all event tables before checking for | |
126 | // the memory leaks when using it, however this breaks re-initializing the | |
127 | // library (i.e. repeated calls to wxInitialize/wxUninitialize) because the | |
128 | // event tables won't be rebuilt the next time, so disable this by default | |
aa767a45 | 129 | #if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING |
a0826b11 | 130 | |
afa039f9 JS |
131 | class wxEventTableEntryModule: public wxModule |
132 | { | |
afa039f9 | 133 | public: |
a0826b11 VZ |
134 | wxEventTableEntryModule() { } |
135 | virtual bool OnInit() { return true; } | |
136 | virtual void OnExit() { wxEventHashTable::ClearAll(); } | |
137 | ||
138 | DECLARE_DYNAMIC_CLASS(wxEventTableEntryModule) | |
afa039f9 | 139 | }; |
a0826b11 | 140 | |
afa039f9 | 141 | IMPLEMENT_DYNAMIC_CLASS(wxEventTableEntryModule, wxModule) |
a0826b11 VZ |
142 | |
143 | #endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING | |
1a18887b | 144 | |
8e193f38 VZ |
145 | // ---------------------------------------------------------------------------- |
146 | // global variables | |
147 | // ---------------------------------------------------------------------------- | |
148 | ||
2e4df4bf VZ |
149 | // common event types are defined here, other event types are defined by the |
150 | // components which use them | |
b5a98acd | 151 | |
c15d9c85 VS |
152 | const wxEventType wxEVT_FIRST = 10000; |
153 | const wxEventType wxEVT_USER_FIRST = wxEVT_FIRST + 2000; | |
2e4df4bf | 154 | |
461697c2 | 155 | DEFINE_EVENT_TYPE(wxEVT_NULL) |
9b11752c | 156 | wxDEFINE_EVENT( wxEVT_IDLE, wxIdleEvent ); |
886dd7d2 | 157 | |
886dd7d2 VZ |
158 | #endif // wxUSE_BASE |
159 | ||
160 | #if wxUSE_GUI | |
161 | ||
9b11752c VZ |
162 | wxDEFINE_EVENT( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEvent ); |
163 | wxDEFINE_EVENT( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEvent ); | |
164 | wxDEFINE_EVENT( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEvent ); | |
165 | wxDEFINE_EVENT( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEvent ); | |
166 | wxDEFINE_EVENT( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEvent ); | |
167 | wxDEFINE_EVENT( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, wxCommandEvent ); | |
168 | wxDEFINE_EVENT( wxEVT_COMMAND_MENU_SELECTED, wxCommandEvent ); | |
169 | wxDEFINE_EVENT( wxEVT_COMMAND_SLIDER_UPDATED, wxCommandEvent ); | |
170 | wxDEFINE_EVENT( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEvent ); | |
171 | wxDEFINE_EVENT( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEvent ); | |
172 | wxDEFINE_EVENT( wxEVT_COMMAND_SCROLLBAR_UPDATED, wxCommandEvent ); | |
173 | wxDEFINE_EVENT( wxEVT_COMMAND_VLBOX_SELECTED, wxCommandEvent ); | |
174 | wxDEFINE_EVENT( wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEvent ); | |
175 | wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_RCLICKED, wxCommandEvent ); | |
176 | wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_ENTER, wxCommandEvent ); | |
177 | wxDEFINE_EVENT( wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEvent ); | |
178 | wxDEFINE_EVENT( wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, wxCommandEvent ); | |
179 | wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED, wxCommandEvent ); | |
0b5eceb6 | 180 | |
0b5eceb6 | 181 | // Mouse event types |
9b11752c VZ |
182 | wxDEFINE_EVENT( wxEVT_LEFT_DOWN, wxMouseEvent ); |
183 | wxDEFINE_EVENT( wxEVT_LEFT_UP, wxMouseEvent ); | |
184 | wxDEFINE_EVENT( wxEVT_MIDDLE_DOWN, wxMouseEvent ); | |
185 | wxDEFINE_EVENT( wxEVT_MIDDLE_UP, wxMouseEvent ); | |
186 | wxDEFINE_EVENT( wxEVT_RIGHT_DOWN, wxMouseEvent ); | |
187 | wxDEFINE_EVENT( wxEVT_RIGHT_UP, wxMouseEvent ); | |
188 | wxDEFINE_EVENT( wxEVT_MOTION, wxMouseEvent ); | |
189 | wxDEFINE_EVENT( wxEVT_ENTER_WINDOW, wxMouseEvent ); | |
190 | wxDEFINE_EVENT( wxEVT_LEAVE_WINDOW, wxMouseEvent ); | |
191 | wxDEFINE_EVENT( wxEVT_LEFT_DCLICK, wxMouseEvent ); | |
192 | wxDEFINE_EVENT( wxEVT_MIDDLE_DCLICK, wxMouseEvent ); | |
193 | wxDEFINE_EVENT( wxEVT_RIGHT_DCLICK, wxMouseEvent ); | |
194 | wxDEFINE_EVENT( wxEVT_SET_FOCUS, wxFocusEvent ); | |
195 | wxDEFINE_EVENT( wxEVT_KILL_FOCUS, wxFocusEvent ); | |
196 | wxDEFINE_EVENT( wxEVT_CHILD_FOCUS, wxChildFocusEvent ); | |
197 | wxDEFINE_EVENT( wxEVT_MOUSEWHEEL, wxMouseEvent ); | |
198 | wxDEFINE_EVENT( wxEVT_AUX1_DOWN, wxMouseEvent ); | |
199 | wxDEFINE_EVENT( wxEVT_AUX1_UP, wxMouseEvent ); | |
200 | wxDEFINE_EVENT( wxEVT_AUX1_DCLICK, wxMouseEvent ); | |
201 | wxDEFINE_EVENT( wxEVT_AUX2_DOWN, wxMouseEvent ); | |
202 | wxDEFINE_EVENT( wxEVT_AUX2_UP, wxMouseEvent ); | |
203 | wxDEFINE_EVENT( wxEVT_AUX2_DCLICK, wxMouseEvent ); | |
0b5eceb6 VZ |
204 | |
205 | // Character input event type | |
9b11752c VZ |
206 | wxDEFINE_EVENT( wxEVT_CHAR, wxKeyEvent ); |
207 | wxDEFINE_EVENT( wxEVT_CHAR_HOOK, wxKeyEvent ); | |
208 | wxDEFINE_EVENT( wxEVT_NAVIGATION_KEY, wxNavigationKeyEvent ); | |
209 | wxDEFINE_EVENT( wxEVT_KEY_DOWN, wxKeyEvent ); | |
210 | wxDEFINE_EVENT( wxEVT_KEY_UP, wxKeyEvent ); | |
5048c832 | 211 | #if wxUSE_HOTKEY |
9b11752c | 212 | wxDEFINE_EVENT( wxEVT_HOTKEY, wxKeyEvent ); |
5048c832 | 213 | #endif |
0b5eceb6 VZ |
214 | |
215 | // Set cursor event | |
9b11752c | 216 | wxDEFINE_EVENT( wxEVT_SET_CURSOR, wxSetCursorEvent ); |
0b5eceb6 VZ |
217 | |
218 | // wxScrollbar and wxSlider event identifiers | |
9b11752c VZ |
219 | wxDEFINE_EVENT( wxEVT_SCROLL_TOP, wxScrollEvent ); |
220 | wxDEFINE_EVENT( wxEVT_SCROLL_BOTTOM, wxScrollEvent ); | |
221 | wxDEFINE_EVENT( wxEVT_SCROLL_LINEUP, wxScrollEvent ); | |
222 | wxDEFINE_EVENT( wxEVT_SCROLL_LINEDOWN, wxScrollEvent ); | |
223 | wxDEFINE_EVENT( wxEVT_SCROLL_PAGEUP, wxScrollEvent ); | |
224 | wxDEFINE_EVENT( wxEVT_SCROLL_PAGEDOWN, wxScrollEvent ); | |
225 | wxDEFINE_EVENT( wxEVT_SCROLL_THUMBTRACK, wxScrollEvent ); | |
226 | wxDEFINE_EVENT( wxEVT_SCROLL_THUMBRELEASE, wxScrollEvent ); | |
227 | wxDEFINE_EVENT( wxEVT_SCROLL_CHANGED, wxScrollEvent ); | |
0b5eceb6 | 228 | |
dca94103 VZ |
229 | // Due to a bug in older wx versions, wxSpinEvents were being sent with type of |
230 | // wxEVT_SCROLL_LINEUP, wxEVT_SCROLL_LINEDOWN and wxEVT_SCROLL_THUMBTRACK. But | |
231 | // with the type-safe events in place, these event types are associated with | |
232 | // wxScrollEvent. To allow handling of spin events, new event types have been | |
233 | // defined in spinbutt.h/spinnbuttcmn.cpp. To maintain backward compatibility | |
234 | // the spin event types are being initialized with the scroll event types. | |
235 | ||
236 | #if wxUSE_SPINBTN | |
237 | ||
9b11752c VZ |
238 | wxDEFINE_EVENT_ALIAS( wxEVT_SPIN_UP, wxSpinEvent, wxEVT_SCROLL_LINEUP ); |
239 | wxDEFINE_EVENT_ALIAS( wxEVT_SPIN_DOWN, wxSpinEvent, wxEVT_SCROLL_LINEDOWN ); | |
240 | wxDEFINE_EVENT_ALIAS( wxEVT_SPIN, wxSpinEvent, wxEVT_SCROLL_THUMBTRACK ); | |
dca94103 VZ |
241 | |
242 | #endif // wxUSE_SPINBTN | |
243 | ||
0b5eceb6 | 244 | // Scroll events from wxWindow |
9b11752c VZ |
245 | wxDEFINE_EVENT( wxEVT_SCROLLWIN_TOP, wxScrollWinEvent ); |
246 | wxDEFINE_EVENT( wxEVT_SCROLLWIN_BOTTOM, wxScrollWinEvent ); | |
247 | wxDEFINE_EVENT( wxEVT_SCROLLWIN_LINEUP, wxScrollWinEvent ); | |
248 | wxDEFINE_EVENT( wxEVT_SCROLLWIN_LINEDOWN, wxScrollWinEvent ); | |
249 | wxDEFINE_EVENT( wxEVT_SCROLLWIN_PAGEUP, wxScrollWinEvent ); | |
250 | wxDEFINE_EVENT( wxEVT_SCROLLWIN_PAGEDOWN, wxScrollWinEvent ); | |
251 | wxDEFINE_EVENT( wxEVT_SCROLLWIN_THUMBTRACK, wxScrollWinEvent ); | |
252 | wxDEFINE_EVENT( wxEVT_SCROLLWIN_THUMBRELEASE, wxScrollWinEvent ); | |
0b5eceb6 VZ |
253 | |
254 | // System events | |
9b11752c VZ |
255 | wxDEFINE_EVENT( wxEVT_SIZE, wxSizeEvent ); |
256 | wxDEFINE_EVENT( wxEVT_SIZING, wxSizeEvent ); | |
257 | wxDEFINE_EVENT( wxEVT_MOVE, wxMoveEvent ); | |
258 | wxDEFINE_EVENT( wxEVT_MOVING, wxMoveEvent ); | |
259 | wxDEFINE_EVENT( wxEVT_MOVE_START, wxMoveEvent ); | |
260 | wxDEFINE_EVENT( wxEVT_MOVE_END, wxMoveEvent ); | |
261 | wxDEFINE_EVENT( wxEVT_CLOSE_WINDOW, wxCloseEvent ); | |
262 | wxDEFINE_EVENT( wxEVT_END_SESSION, wxCloseEvent ); | |
263 | wxDEFINE_EVENT( wxEVT_QUERY_END_SESSION, wxCloseEvent ); | |
264 | wxDEFINE_EVENT( wxEVT_HIBERNATE, wxActivateEvent ); | |
265 | wxDEFINE_EVENT( wxEVT_ACTIVATE_APP, wxActivateEvent ); | |
266 | wxDEFINE_EVENT( wxEVT_ACTIVATE, wxActivateEvent ); | |
267 | wxDEFINE_EVENT( wxEVT_CREATE, wxWindowCreateEvent ); | |
268 | wxDEFINE_EVENT( wxEVT_DESTROY, wxWindowDestroyEvent ); | |
269 | wxDEFINE_EVENT( wxEVT_SHOW, wxShowEvent ); | |
270 | wxDEFINE_EVENT( wxEVT_ICONIZE, wxIconizeEvent ); | |
271 | wxDEFINE_EVENT( wxEVT_MAXIMIZE, wxMaximizeEvent ); | |
272 | wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_CHANGED, wxMouseCaptureChangedEvent ); | |
273 | wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_LOST, wxMouseCaptureLostEvent ); | |
274 | wxDEFINE_EVENT( wxEVT_PAINT, wxPaintEvent ); | |
275 | wxDEFINE_EVENT( wxEVT_ERASE_BACKGROUND, wxEraseEvent ); | |
276 | wxDEFINE_EVENT( wxEVT_NC_PAINT, wxNcPaintEvent ); | |
277 | wxDEFINE_EVENT( wxEVT_MENU_OPEN, wxMenuEvent ); | |
278 | wxDEFINE_EVENT( wxEVT_MENU_CLOSE, wxMenuEvent ); | |
279 | wxDEFINE_EVENT( wxEVT_MENU_HIGHLIGHT, wxMenuEvent ); | |
280 | wxDEFINE_EVENT( wxEVT_CONTEXT_MENU, wxContextMenuEvent ); | |
281 | wxDEFINE_EVENT( wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEvent ); | |
282 | wxDEFINE_EVENT( wxEVT_DISPLAY_CHANGED, wxDisplayChangedEvent ); | |
283 | wxDEFINE_EVENT( wxEVT_QUERY_NEW_PALETTE, wxQueryNewPaletteEvent ); | |
284 | wxDEFINE_EVENT( wxEVT_PALETTE_CHANGED, wxPaletteChangedEvent ); | |
285 | wxDEFINE_EVENT( wxEVT_JOY_BUTTON_DOWN, wxJoystickEvent ); | |
286 | wxDEFINE_EVENT( wxEVT_JOY_BUTTON_UP, wxJoystickEvent ); | |
287 | wxDEFINE_EVENT( wxEVT_JOY_MOVE, wxJoystickEvent ); | |
288 | wxDEFINE_EVENT( wxEVT_JOY_ZMOVE, wxJoystickEvent ); | |
289 | wxDEFINE_EVENT( wxEVT_DROP_FILES, wxDropFilesEvent ); | |
290 | wxDEFINE_EVENT( wxEVT_INIT_DIALOG, wxInitDialogEvent ); | |
291 | wxDEFINE_EVENT( wxEVT_UPDATE_UI, wxUpdateUIEvent ); | |
0b5eceb6 | 292 | |
78c91815 | 293 | // Clipboard events |
9b11752c VZ |
294 | wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_COPY, wxClipboardTextEvent ); |
295 | wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_CUT, wxClipboardTextEvent ); | |
296 | wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_PASTE, wxClipboardTextEvent ); | |
78c91815 | 297 | |
0b5eceb6 VZ |
298 | // Generic command events |
299 | // Note: a click is a higher-level event than button down/up | |
9b11752c VZ |
300 | wxDEFINE_EVENT( wxEVT_COMMAND_LEFT_CLICK, wxCommandEvent ); |
301 | wxDEFINE_EVENT( wxEVT_COMMAND_LEFT_DCLICK, wxCommandEvent ); | |
302 | wxDEFINE_EVENT( wxEVT_COMMAND_RIGHT_CLICK, wxCommandEvent ); | |
303 | wxDEFINE_EVENT( wxEVT_COMMAND_RIGHT_DCLICK, wxCommandEvent ); | |
304 | wxDEFINE_EVENT( wxEVT_COMMAND_SET_FOCUS, wxCommandEvent ); | |
305 | wxDEFINE_EVENT( wxEVT_COMMAND_KILL_FOCUS, wxCommandEvent ); | |
306 | wxDEFINE_EVENT( wxEVT_COMMAND_ENTER, wxCommandEvent ); | |
0b5eceb6 VZ |
307 | |
308 | // Help events | |
9b11752c VZ |
309 | wxDEFINE_EVENT( wxEVT_HELP, wxHelpEvent ); |
310 | wxDEFINE_EVENT( wxEVT_DETAILED_HELP, wxHelpEvent ); | |
6164f93c | 311 | |
d48b06bd | 312 | // Thread event |
9b11752c | 313 | wxDEFINE_EVENT( wxEVT_COMMAND_THREAD, wxThreadEvent ); |
d48b06bd | 314 | |
886dd7d2 VZ |
315 | #endif // wxUSE_GUI |
316 | ||
317 | #if wxUSE_BASE | |
318 | ||
b46b1d59 VZ |
319 | wxIdleMode wxIdleEvent::sm_idleMode = wxIDLE_PROCESS_ALL; |
320 | ||
6164f93c VZ |
321 | // ============================================================================ |
322 | // implementation | |
323 | // ============================================================================ | |
0b5eceb6 | 324 | |
0b5eceb6 VZ |
325 | // ---------------------------------------------------------------------------- |
326 | // event initialization | |
327 | // ---------------------------------------------------------------------------- | |
328 | ||
329 | int wxNewEventType() | |
330 | { | |
331 | // MT-FIXME | |
332 | static int s_lastUsedEventType = wxEVT_FIRST; | |
333 | ||
334 | return s_lastUsedEventType++; | |
335 | } | |
3c778901 VZ |
336 | // ---------------------------------------------------------------------------- |
337 | // wxEventFunctor | |
338 | // ---------------------------------------------------------------------------- | |
339 | ||
340 | wxEventFunctor::~wxEventFunctor() | |
341 | { | |
342 | } | |
0b5eceb6 | 343 | |
8e193f38 VZ |
344 | // ---------------------------------------------------------------------------- |
345 | // wxEvent | |
346 | // ---------------------------------------------------------------------------- | |
347 | ||
c801d85f | 348 | /* |
d48b06bd FM |
349 | * General wxWidgets events, covering all interesting things that might happen |
350 | * (button clicking, resizing, setting text in widgets, etc.). | |
c801d85f KB |
351 | * |
352 | * For each completely new event type, derive a new event class. | |
353 | * | |
354 | */ | |
355 | ||
d48b06bd | 356 | wxEvent::wxEvent(int theId, wxEventType commandType) |
c801d85f | 357 | { |
8e72b8b5 | 358 | m_eventType = commandType; |
3c778901 | 359 | m_eventObject = NULL; |
0b746ba8 VZ |
360 | m_timeStamp = 0; |
361 | m_id = theId; | |
1c624631 | 362 | m_skipped = false; |
3c778901 | 363 | m_callbackUserData = NULL; |
1c624631 | 364 | m_isCommandEvent = false; |
1648d51b | 365 | m_propagationLevel = wxEVENT_PROPAGATE_NONE; |
29de6f40 | 366 | m_wasProcessed = false; |
c801d85f KB |
367 | } |
368 | ||
0e097789 | 369 | wxEvent::wxEvent(const wxEvent& src) |
a34ef99b | 370 | : wxObject(src) |
e6a6feba GD |
371 | , m_eventObject(src.m_eventObject) |
372 | , m_eventType(src.m_eventType) | |
373 | , m_timeStamp(src.m_timeStamp) | |
374 | , m_id(src.m_id) | |
375 | , m_callbackUserData(src.m_callbackUserData) | |
6fd5903a | 376 | , m_propagationLevel(src.m_propagationLevel) |
e6a6feba GD |
377 | , m_skipped(src.m_skipped) |
378 | , m_isCommandEvent(src.m_isCommandEvent) | |
29de6f40 | 379 | , m_wasProcessed(false) |
a737331d | 380 | { |
a737331d GL |
381 | } |
382 | ||
0e097789 VZ |
383 | wxEvent& wxEvent::operator=(const wxEvent& src) |
384 | { | |
385 | wxObject::operator=(src); | |
386 | ||
387 | m_eventObject = src.m_eventObject; | |
388 | m_eventType = src.m_eventType; | |
389 | m_timeStamp = src.m_timeStamp; | |
390 | m_id = src.m_id; | |
391 | m_callbackUserData = src.m_callbackUserData; | |
392 | m_propagationLevel = src.m_propagationLevel; | |
393 | m_skipped = src.m_skipped; | |
394 | m_isCommandEvent = src.m_isCommandEvent; | |
395 | ||
29de6f40 VZ |
396 | // don't change m_wasProcessed |
397 | ||
0e097789 VZ |
398 | return *this; |
399 | } | |
400 | ||
3ed2104c VZ |
401 | #endif // wxUSE_BASE |
402 | ||
e90c1d2a VZ |
403 | #if wxUSE_GUI |
404 | ||
c801d85f KB |
405 | /* |
406 | * Command events | |
407 | * | |
408 | */ | |
409 | ||
21eefb76 VZ |
410 | #ifdef __VISUALC__ |
411 | // 'this' : used in base member initializer list (for m_commandString) | |
412 | #pragma warning(disable:4355) | |
413 | #endif | |
414 | ||
7798a18e | 415 | wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId) |
b5a98acd | 416 | : wxEvent(theId, commandType) |
c801d85f | 417 | { |
3c778901 VZ |
418 | m_clientData = NULL; |
419 | m_clientObject = NULL; | |
0b746ba8 VZ |
420 | m_extraLong = 0; |
421 | m_commandInt = 0; | |
1c624631 | 422 | m_isCommandEvent = true; |
1648d51b VZ |
423 | |
424 | // the command events are propagated upwards by default | |
425 | m_propagationLevel = wxEVENT_PROPAGATE_MAX; | |
c801d85f KB |
426 | } |
427 | ||
21eefb76 VZ |
428 | #ifdef __VISUALC__ |
429 | #pragma warning(default:4355) | |
430 | #endif | |
431 | ||
ab1931f9 KH |
432 | wxString wxCommandEvent::GetString() const |
433 | { | |
cc6ceca7 VZ |
434 | if (m_eventType != wxEVT_COMMAND_TEXT_UPDATED || !m_eventObject) |
435 | { | |
ab1931f9 | 436 | return m_cmdString; |
cc6ceca7 | 437 | } |
ab1931f9 KH |
438 | else |
439 | { | |
89438177 | 440 | #if wxUSE_TEXTCTRL |
ab1931f9 | 441 | wxTextCtrl *txt = wxDynamicCast(m_eventObject, wxTextCtrl); |
cc6ceca7 | 442 | if ( txt ) |
ab1931f9 KH |
443 | return txt->GetValue(); |
444 | else | |
89438177 | 445 | #endif // wxUSE_TEXTCTRL |
ab1931f9 KH |
446 | return m_cmdString; |
447 | } | |
448 | } | |
449 | ||
0b30bb0b JS |
450 | /* |
451 | * UI update events | |
452 | */ | |
453 | ||
454 | #if wxUSE_LONGLONG | |
e39af974 | 455 | wxLongLong wxUpdateUIEvent::sm_lastUpdate = 0; |
0b30bb0b JS |
456 | #endif |
457 | ||
e39af974 JS |
458 | long wxUpdateUIEvent::sm_updateInterval = 0; |
459 | ||
460 | wxUpdateUIMode wxUpdateUIEvent::sm_updateMode = wxUPDATE_UI_PROCESS_ALL; | |
0b30bb0b JS |
461 | |
462 | // Can we update? | |
a7bc03c9 | 463 | bool wxUpdateUIEvent::CanUpdate(wxWindowBase *win) |
0b30bb0b | 464 | { |
e39af974 JS |
465 | // Don't update if we've switched global updating off |
466 | // and this window doesn't support updates. | |
467 | if (win && | |
468 | (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED && | |
469 | ((win->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES) == 0))) | |
1c624631 | 470 | return false; |
b5a98acd | 471 | |
e39af974 | 472 | if (sm_updateInterval == -1) |
1c624631 | 473 | return false; |
534b127c WS |
474 | |
475 | if (sm_updateInterval == 0) | |
1c624631 | 476 | return true; |
534b127c | 477 | |
0b30bb0b | 478 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG |
534b127c WS |
479 | wxLongLong now = wxGetLocalTimeMillis(); |
480 | if (now > (sm_lastUpdate + sm_updateInterval)) | |
481 | { | |
1c624631 | 482 | return true; |
0b30bb0b | 483 | } |
534b127c | 484 | |
1c624631 | 485 | return false; |
534b127c WS |
486 | #else |
487 | // If we don't have wxStopWatch or wxLongLong, we | |
488 | // should err on the safe side and update now anyway. | |
489 | return true; | |
490 | #endif | |
0b30bb0b JS |
491 | } |
492 | ||
493 | // Reset the update time to provide a delay until the next | |
494 | // time we should update | |
495 | void wxUpdateUIEvent::ResetUpdateTime() | |
496 | { | |
497 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG | |
e39af974 | 498 | if (sm_updateInterval > 0) |
0b30bb0b JS |
499 | { |
500 | wxLongLong now = wxGetLocalTimeMillis(); | |
e39af974 | 501 | if (now > (sm_lastUpdate + sm_updateInterval)) |
0b30bb0b | 502 | { |
e39af974 | 503 | sm_lastUpdate = now; |
0b30bb0b JS |
504 | } |
505 | } | |
506 | #endif | |
507 | } | |
508 | ||
c801d85f KB |
509 | /* |
510 | * Scroll events | |
511 | */ | |
512 | ||
0b746ba8 VZ |
513 | wxScrollEvent::wxScrollEvent(wxEventType commandType, |
514 | int id, | |
515 | int pos, | |
516 | int orient) | |
e6a6feba | 517 | : wxCommandEvent(commandType, id) |
c801d85f | 518 | { |
0b746ba8 VZ |
519 | m_extraLong = orient; |
520 | m_commandInt = pos; | |
c801d85f KB |
521 | } |
522 | ||
d1367c3d RR |
523 | /* |
524 | * ScrollWin events | |
525 | */ | |
526 | ||
527 | wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType, | |
528 | int pos, | |
529 | int orient) | |
d1367c3d | 530 | { |
c5b42c87 | 531 | m_eventType = commandType; |
d1367c3d RR |
532 | m_extraLong = orient; |
533 | m_commandInt = pos; | |
534 | } | |
535 | ||
c801d85f KB |
536 | /* |
537 | * Mouse events | |
538 | * | |
539 | */ | |
540 | ||
7798a18e | 541 | wxMouseEvent::wxMouseEvent(wxEventType commandType) |
c801d85f | 542 | { |
0b746ba8 | 543 | m_eventType = commandType; |
8866abbb VZ |
544 | |
545 | m_x = 0; | |
546 | m_y = 0; | |
547 | ||
1c624631 | 548 | m_leftDown = false; |
1c624631 | 549 | m_middleDown = false; |
8866abbb | 550 | m_rightDown = false; |
01101e2d VZ |
551 | m_aux1Down = false; |
552 | m_aux2Down = false; | |
8866abbb | 553 | |
8866abbb VZ |
554 | m_clickCount = -1; |
555 | ||
d2c52078 RD |
556 | m_wheelRotation = 0; |
557 | m_wheelDelta = 0; | |
558 | m_linesPerAction = 0; | |
aea37008 | 559 | m_wheelAxis = 0; |
c801d85f KB |
560 | } |
561 | ||
abcbaea7 VZ |
562 | void wxMouseEvent::Assign(const wxMouseEvent& event) |
563 | { | |
0e097789 | 564 | wxEvent::operator=(event); |
3232da9d VZ |
565 | |
566 | // Borland C++ 5.82 doesn't compile an explicit call to an implicitly | |
567 | // defined operator=() so need to do it this way: | |
568 | *static_cast<wxMouseState *>(this) = event; | |
92309201 | 569 | |
abcbaea7 VZ |
570 | m_x = event.m_x; |
571 | m_y = event.m_y; | |
572 | ||
573 | m_leftDown = event.m_leftDown; | |
574 | m_middleDown = event.m_middleDown; | |
575 | m_rightDown = event.m_rightDown; | |
01101e2d VZ |
576 | m_aux1Down = event.m_aux1Down; |
577 | m_aux2Down = event.m_aux2Down; | |
abcbaea7 | 578 | |
abcbaea7 VZ |
579 | m_wheelRotation = event.m_wheelRotation; |
580 | m_wheelDelta = event.m_wheelDelta; | |
581 | m_linesPerAction = event.m_linesPerAction; | |
aea37008 | 582 | m_wheelAxis = event.m_wheelAxis; |
abcbaea7 VZ |
583 | } |
584 | ||
3e89999c | 585 | // return true if was a button dclick event |
c801d85f KB |
586 | bool wxMouseEvent::ButtonDClick(int but) const |
587 | { | |
0b746ba8 VZ |
588 | switch (but) |
589 | { | |
3e89999c VZ |
590 | default: |
591 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick")); | |
592 | // fall through | |
593 | ||
594 | case wxMOUSE_BTN_ANY: | |
01101e2d VZ |
595 | return (LeftDClick() || MiddleDClick() || RightDClick() || |
596 | Aux1DClick() || Aux2DClick()); | |
3e89999c VZ |
597 | |
598 | case wxMOUSE_BTN_LEFT: | |
0b746ba8 | 599 | return LeftDClick(); |
3e89999c VZ |
600 | |
601 | case wxMOUSE_BTN_MIDDLE: | |
0b746ba8 | 602 | return MiddleDClick(); |
3e89999c VZ |
603 | |
604 | case wxMOUSE_BTN_RIGHT: | |
0b746ba8 | 605 | return RightDClick(); |
01101e2d VZ |
606 | |
607 | case wxMOUSE_BTN_AUX1: | |
608 | return Aux1DClick(); | |
609 | ||
610 | case wxMOUSE_BTN_AUX2: | |
611 | return Aux2DClick(); | |
0b746ba8 | 612 | } |
c801d85f KB |
613 | } |
614 | ||
3e89999c | 615 | // return true if was a button down event |
c801d85f KB |
616 | bool wxMouseEvent::ButtonDown(int but) const |
617 | { | |
0b746ba8 VZ |
618 | switch (but) |
619 | { | |
3e89999c VZ |
620 | default: |
621 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown")); | |
622 | // fall through | |
623 | ||
624 | case wxMOUSE_BTN_ANY: | |
01101e2d VZ |
625 | return (LeftDown() || MiddleDown() || RightDown() || |
626 | Aux1Down() || Aux2Down()); | |
3e89999c VZ |
627 | |
628 | case wxMOUSE_BTN_LEFT: | |
0b746ba8 | 629 | return LeftDown(); |
3e89999c VZ |
630 | |
631 | case wxMOUSE_BTN_MIDDLE: | |
0b746ba8 | 632 | return MiddleDown(); |
3e89999c VZ |
633 | |
634 | case wxMOUSE_BTN_RIGHT: | |
0b746ba8 | 635 | return RightDown(); |
01101e2d VZ |
636 | |
637 | case wxMOUSE_BTN_AUX1: | |
638 | return Aux1Down(); | |
639 | ||
640 | case wxMOUSE_BTN_AUX2: | |
641 | return Aux2Down(); | |
0b746ba8 | 642 | } |
c801d85f KB |
643 | } |
644 | ||
3e89999c | 645 | // return true if was a button up event |
c801d85f KB |
646 | bool wxMouseEvent::ButtonUp(int but) const |
647 | { | |
1e6feb95 VZ |
648 | switch (but) |
649 | { | |
3e89999c VZ |
650 | default: |
651 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp")); | |
652 | // fall through | |
653 | ||
654 | case wxMOUSE_BTN_ANY: | |
01101e2d VZ |
655 | return (LeftUp() || MiddleUp() || RightUp() || |
656 | Aux1Up() || Aux2Up()); | |
3e89999c VZ |
657 | |
658 | case wxMOUSE_BTN_LEFT: | |
0b746ba8 | 659 | return LeftUp(); |
3e89999c VZ |
660 | |
661 | case wxMOUSE_BTN_MIDDLE: | |
0b746ba8 | 662 | return MiddleUp(); |
3e89999c VZ |
663 | |
664 | case wxMOUSE_BTN_RIGHT: | |
0b746ba8 | 665 | return RightUp(); |
01101e2d VZ |
666 | |
667 | case wxMOUSE_BTN_AUX1: | |
668 | return Aux1Up(); | |
669 | ||
670 | case wxMOUSE_BTN_AUX2: | |
671 | return Aux2Up(); | |
0b746ba8 | 672 | } |
c801d85f KB |
673 | } |
674 | ||
3e89999c | 675 | // return true if the given button is currently changing state |
c801d85f KB |
676 | bool wxMouseEvent::Button(int but) const |
677 | { | |
1e6feb95 VZ |
678 | switch (but) |
679 | { | |
0b746ba8 | 680 | default: |
223d09f6 | 681 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button")); |
3e89999c VZ |
682 | // fall through |
683 | ||
684 | case wxMOUSE_BTN_ANY: | |
685 | return ButtonUp(wxMOUSE_BTN_ANY) || | |
686 | ButtonDown(wxMOUSE_BTN_ANY) || | |
687 | ButtonDClick(wxMOUSE_BTN_ANY); | |
688 | ||
689 | case wxMOUSE_BTN_LEFT: | |
690 | return LeftDown() || LeftUp() || LeftDClick(); | |
691 | ||
692 | case wxMOUSE_BTN_MIDDLE: | |
693 | return MiddleDown() || MiddleUp() || MiddleDClick(); | |
694 | ||
695 | case wxMOUSE_BTN_RIGHT: | |
696 | return RightDown() || RightUp() || RightDClick(); | |
01101e2d VZ |
697 | |
698 | case wxMOUSE_BTN_AUX1: | |
699 | return Aux1Down() || Aux1Up() || Aux1DClick(); | |
700 | ||
701 | case wxMOUSE_BTN_AUX2: | |
702 | return Aux2Down() || Aux2Up() || Aux2DClick(); | |
0b746ba8 | 703 | } |
c801d85f KB |
704 | } |
705 | ||
706 | bool wxMouseEvent::ButtonIsDown(int but) const | |
707 | { | |
1e6feb95 VZ |
708 | switch (but) |
709 | { | |
3e89999c VZ |
710 | default: |
711 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown")); | |
712 | // fall through | |
713 | ||
714 | case wxMOUSE_BTN_ANY: | |
01101e2d | 715 | return LeftIsDown() || MiddleIsDown() || RightIsDown() || Aux1Down() || Aux2Down(); |
3e89999c VZ |
716 | |
717 | case wxMOUSE_BTN_LEFT: | |
0b746ba8 | 718 | return LeftIsDown(); |
3e89999c VZ |
719 | |
720 | case wxMOUSE_BTN_MIDDLE: | |
0b746ba8 | 721 | return MiddleIsDown(); |
3e89999c VZ |
722 | |
723 | case wxMOUSE_BTN_RIGHT: | |
0b746ba8 | 724 | return RightIsDown(); |
01101e2d VZ |
725 | |
726 | case wxMOUSE_BTN_AUX1: | |
727 | return Aux1IsDown(); | |
728 | ||
729 | case wxMOUSE_BTN_AUX2: | |
730 | return Aux2IsDown(); | |
0b746ba8 | 731 | } |
c801d85f KB |
732 | } |
733 | ||
1e6feb95 VZ |
734 | int wxMouseEvent::GetButton() const |
735 | { | |
01101e2d | 736 | for ( int i = 1; i < wxMOUSE_BTN_MAX; i++ ) |
1e6feb95 VZ |
737 | { |
738 | if ( Button(i) ) | |
739 | { | |
740 | return i; | |
741 | } | |
742 | } | |
743 | ||
3e89999c | 744 | return wxMOUSE_BTN_NONE; |
1e6feb95 VZ |
745 | } |
746 | ||
c801d85f KB |
747 | // Find the logical position of the event given the DC |
748 | wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const | |
749 | { | |
0757d27c JS |
750 | wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y)); |
751 | return pt; | |
c801d85f KB |
752 | } |
753 | ||
754 | ||
755 | /* | |
8e72b8b5 | 756 | * Keyboard event |
c801d85f KB |
757 | * |
758 | */ | |
759 | ||
7798a18e | 760 | wxKeyEvent::wxKeyEvent(wxEventType type) |
c801d85f | 761 | { |
0b746ba8 | 762 | m_eventType = type; |
0b746ba8 | 763 | m_keyCode = 0; |
2b5f62a0 VZ |
764 | #if wxUSE_UNICODE |
765 | m_uniChar = 0; | |
766 | #endif | |
c801d85f KB |
767 | } |
768 | ||
92309201 | 769 | wxKeyEvent::wxKeyEvent(const wxKeyEvent& evt) |
0e097789 VZ |
770 | : wxEvent(evt), |
771 | wxKeyboardState(evt) | |
2b5f62a0 VZ |
772 | { |
773 | m_x = evt.m_x; | |
774 | m_y = evt.m_y; | |
775 | ||
776 | m_keyCode = evt.m_keyCode; | |
2b5f62a0 VZ |
777 | m_rawCode = evt.m_rawCode; |
778 | m_rawFlags = evt.m_rawFlags; | |
92309201 | 779 | |
2b5f62a0 VZ |
780 | #if wxUSE_UNICODE |
781 | m_uniChar = evt.m_uniChar; | |
782 | #endif | |
783 | } | |
12a3f227 | 784 | |
42e69d6b | 785 | wxWindowCreateEvent::wxWindowCreateEvent(wxWindow *win) |
42e69d6b | 786 | { |
cfe17b74 | 787 | SetEventType(wxEVT_CREATE); |
42e69d6b VZ |
788 | SetEventObject(win); |
789 | } | |
790 | ||
791 | wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow *win) | |
42e69d6b | 792 | { |
cfe17b74 | 793 | SetEventType(wxEVT_DESTROY); |
42e69d6b VZ |
794 | SetEventObject(win); |
795 | } | |
796 | ||
456bc6d9 VZ |
797 | wxChildFocusEvent::wxChildFocusEvent(wxWindow *win) |
798 | : wxCommandEvent(wxEVT_CHILD_FOCUS) | |
799 | { | |
800 | SetEventObject(win); | |
801 | } | |
802 | ||
b107e8d5 VZ |
803 | // ---------------------------------------------------------------------------- |
804 | // wxHelpEvent | |
805 | // ---------------------------------------------------------------------------- | |
806 | ||
807 | /* static */ | |
808 | wxHelpEvent::Origin wxHelpEvent::GuessOrigin(Origin origin) | |
809 | { | |
810 | if ( origin == Origin_Unknown ) | |
811 | { | |
812 | // assume that the event comes from the help button if it's not from | |
813 | // keyboard and that pressing F1 always results in the help event | |
814 | origin = wxGetKeyState(WXK_F1) ? Origin_Keyboard : Origin_HelpButton; | |
815 | } | |
816 | ||
817 | return origin; | |
818 | } | |
819 | ||
dd070522 VZ |
820 | #endif // wxUSE_GUI |
821 | ||
9416681d VS |
822 | |
823 | #if wxUSE_BASE | |
824 | ||
b5a98acd VZ |
825 | // ---------------------------------------------------------------------------- |
826 | // wxEventHashTable | |
827 | // ---------------------------------------------------------------------------- | |
828 | ||
afa039f9 JS |
829 | static const int EVENT_TYPE_TABLE_INIT_SIZE = 31; // Not too big not too small... |
830 | ||
831 | wxEventHashTable* wxEventHashTable::sm_first = NULL; | |
b5a98acd VZ |
832 | |
833 | wxEventHashTable::wxEventHashTable(const wxEventTable &table) | |
834 | : m_table(table), | |
1c624631 | 835 | m_rebuildHash(true) |
b5a98acd VZ |
836 | { |
837 | AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE); | |
1a18887b | 838 | |
afa039f9 JS |
839 | m_next = sm_first; |
840 | if (m_next) | |
841 | m_next->m_previous = this; | |
842 | sm_first = this; | |
b5a98acd VZ |
843 | } |
844 | ||
845 | wxEventHashTable::~wxEventHashTable() | |
afa039f9 JS |
846 | { |
847 | if (m_next) | |
848 | m_next->m_previous = m_previous; | |
849 | if (m_previous) | |
850 | m_previous->m_next = m_next; | |
851 | if (sm_first == this) | |
852 | sm_first = m_next; | |
1a18887b | 853 | |
afa039f9 JS |
854 | Clear(); |
855 | } | |
856 | ||
857 | void wxEventHashTable::Clear() | |
b5a98acd | 858 | { |
a0826b11 | 859 | for ( size_t i = 0; i < m_size; i++ ) |
b5a98acd VZ |
860 | { |
861 | EventTypeTablePointer eTTnode = m_eventTypeTable[i]; | |
a0826b11 | 862 | delete eTTnode; |
b5a98acd VZ |
863 | } |
864 | ||
a0826b11 | 865 | delete[] m_eventTypeTable; |
afa039f9 | 866 | m_eventTypeTable = NULL; |
a0826b11 | 867 | |
afa039f9 JS |
868 | m_size = 0; |
869 | } | |
870 | ||
aa767a45 | 871 | #if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING |
a0826b11 | 872 | |
afa039f9 JS |
873 | // Clear all tables |
874 | void wxEventHashTable::ClearAll() | |
875 | { | |
876 | wxEventHashTable* table = sm_first; | |
877 | while (table) | |
878 | { | |
879 | table->Clear(); | |
880 | table = table->m_next; | |
881 | } | |
b5a98acd VZ |
882 | } |
883 | ||
a0826b11 VZ |
884 | #endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING |
885 | ||
b5a98acd VZ |
886 | bool wxEventHashTable::HandleEvent(wxEvent &event, wxEvtHandler *self) |
887 | { | |
888 | if (m_rebuildHash) | |
889 | { | |
890 | InitHashTable(); | |
1c624631 | 891 | m_rebuildHash = false; |
b5a98acd | 892 | } |
1a18887b | 893 | |
afa039f9 | 894 | if (!m_eventTypeTable) |
1a18887b | 895 | return false; |
b5a98acd VZ |
896 | |
897 | // Find all entries for the given event type. | |
898 | wxEventType eventType = event.GetEventType(); | |
899 | const EventTypeTablePointer eTTnode = m_eventTypeTable[eventType % m_size]; | |
900 | if (eTTnode && eTTnode->eventType == eventType) | |
901 | { | |
902 | // Now start the search for an event handler | |
903 | // that can handle an event with the given ID. | |
1c624631 VZ |
904 | const wxEventTableEntryPointerArray& |
905 | eventEntryTable = eTTnode->eventEntryTable; | |
b5a98acd | 906 | |
1c624631 VZ |
907 | const size_t count = eventEntryTable.GetCount(); |
908 | for (size_t n = 0; n < count; n++) | |
b5a98acd | 909 | { |
03f3617b VZ |
910 | const wxEventTableEntry& entry = *eventEntryTable[n]; |
911 | if ( wxEvtHandler::ProcessEventIfMatchesId(entry, self, event) ) | |
1c624631 | 912 | return true; |
b5a98acd | 913 | } |
b5a98acd VZ |
914 | } |
915 | ||
1c624631 | 916 | return false; |
b5a98acd VZ |
917 | } |
918 | ||
919 | void wxEventHashTable::InitHashTable() | |
920 | { | |
921 | // Loop over the event tables and all its base tables. | |
922 | const wxEventTable *table = &m_table; | |
923 | while (table) | |
924 | { | |
925 | // Retrieve all valid event handler entries | |
926 | const wxEventTableEntry *entry = table->entries; | |
927 | while (entry->m_fn != 0) | |
928 | { | |
929 | // Add the event entry in the Hash. | |
930 | AddEntry(*entry); | |
931 | ||
932 | entry++; | |
933 | } | |
934 | ||
935 | table = table->baseTable; | |
936 | } | |
937 | ||
938 | // Lets free some memory. | |
939 | size_t i; | |
940 | for(i = 0; i < m_size; i++) | |
941 | { | |
942 | EventTypeTablePointer eTTnode = m_eventTypeTable[i]; | |
943 | if (eTTnode) | |
944 | { | |
945 | eTTnode->eventEntryTable.Shrink(); | |
946 | } | |
947 | } | |
948 | } | |
949 | ||
950 | void wxEventHashTable::AddEntry(const wxEventTableEntry &entry) | |
951 | { | |
afa039f9 JS |
952 | // This might happen 'accidentally' as the app is exiting |
953 | if (!m_eventTypeTable) | |
954 | return; | |
1a18887b | 955 | |
b5a98acd VZ |
956 | EventTypeTablePointer *peTTnode = &m_eventTypeTable[entry.m_eventType % m_size]; |
957 | EventTypeTablePointer eTTnode = *peTTnode; | |
958 | ||
959 | if (eTTnode) | |
960 | { | |
961 | if (eTTnode->eventType != entry.m_eventType) | |
962 | { | |
963 | // Resize the table! | |
964 | GrowEventTypeTable(); | |
965 | // Try again to add it. | |
966 | AddEntry(entry); | |
967 | return; | |
968 | } | |
969 | } | |
970 | else | |
971 | { | |
972 | eTTnode = new EventTypeTable; | |
973 | eTTnode->eventType = entry.m_eventType; | |
974 | *peTTnode = eTTnode; | |
975 | } | |
976 | ||
977 | // Fill all hash entries between entry.m_id and entry.m_lastId... | |
978 | eTTnode->eventEntryTable.Add(&entry); | |
979 | } | |
980 | ||
981 | void wxEventHashTable::AllocEventTypeTable(size_t size) | |
982 | { | |
983 | m_eventTypeTable = new EventTypeTablePointer[size]; | |
984 | memset((void *)m_eventTypeTable, 0, sizeof(EventTypeTablePointer)*size); | |
985 | m_size = size; | |
986 | } | |
987 | ||
988 | void wxEventHashTable::GrowEventTypeTable() | |
989 | { | |
990 | size_t oldSize = m_size; | |
991 | EventTypeTablePointer *oldEventTypeTable = m_eventTypeTable; | |
992 | ||
993 | // TODO: Search the most optimal grow sequence | |
994 | AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize*2+1); | |
995 | ||
996 | for ( size_t i = 0; i < oldSize; /* */ ) | |
997 | { | |
998 | EventTypeTablePointer eTToldNode = oldEventTypeTable[i]; | |
999 | if (eTToldNode) | |
1000 | { | |
1001 | EventTypeTablePointer *peTTnode = &m_eventTypeTable[eTToldNode->eventType % m_size]; | |
1002 | EventTypeTablePointer eTTnode = *peTTnode; | |
1003 | ||
1004 | // Check for collision, we don't want any. | |
1005 | if (eTTnode) | |
1006 | { | |
1007 | GrowEventTypeTable(); | |
1008 | continue; // Don't increment the counter, | |
1009 | // as we still need to add this element. | |
1010 | } | |
1011 | else | |
1012 | { | |
1013 | // Get the old value and put it in the new table. | |
1014 | *peTTnode = oldEventTypeTable[i]; | |
1015 | } | |
1016 | } | |
1017 | ||
1018 | i++; | |
1019 | } | |
1020 | ||
1021 | delete[] oldEventTypeTable; | |
1022 | } | |
1023 | ||
456bc6d9 VZ |
1024 | // ---------------------------------------------------------------------------- |
1025 | // wxEvtHandler | |
1026 | // ---------------------------------------------------------------------------- | |
1027 | ||
0b746ba8 | 1028 | wxEvtHandler::wxEvtHandler() |
c801d85f | 1029 | { |
3c778901 VZ |
1030 | m_nextHandler = NULL; |
1031 | m_previousHandler = NULL; | |
1c624631 | 1032 | m_enabled = true; |
3c778901 VZ |
1033 | m_dynamicEvents = NULL; |
1034 | m_pendingEvents = NULL; | |
aa767a45 | 1035 | |
b88c44e7 RD |
1036 | // no client data (yet) |
1037 | m_clientData = NULL; | |
1038 | m_clientDataType = wxClientData_None; | |
c801d85f KB |
1039 | } |
1040 | ||
0b746ba8 | 1041 | wxEvtHandler::~wxEvtHandler() |
c801d85f | 1042 | { |
7f853dd0 | 1043 | Unlink(); |
0b746ba8 VZ |
1044 | |
1045 | if (m_dynamicEvents) | |
fe71f65c | 1046 | { |
3c448b2e VZ |
1047 | for ( wxList::iterator it = m_dynamicEvents->begin(), |
1048 | end = m_dynamicEvents->end(); | |
1049 | it != end; | |
1050 | ++it ) | |
0b746ba8 | 1051 | { |
df5168c4 | 1052 | wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)*it; |
2e4df4bf | 1053 | |
cc6ceca7 | 1054 | // Remove ourselves from sink destructor notifications |
3c778901 | 1055 | // (this has usually been done, in wxTrackable destructor) |
f3ff831f | 1056 | wxEvtHandler *eventSink = entry->m_fn->GetEvtHandler(); |
cc6ceca7 | 1057 | if ( eventSink ) |
2ef989c9 | 1058 | { |
cc6ceca7 VZ |
1059 | wxEventConnectionRef * const |
1060 | evtConnRef = FindRefInTrackerList(eventSink); | |
1061 | if ( evtConnRef ) | |
1062 | { | |
1063 | eventSink->RemoveNode(evtConnRef); | |
1064 | delete evtConnRef; | |
1065 | } | |
2ef989c9 | 1066 | } |
cc6ceca7 | 1067 | |
3c778901 | 1068 | delete entry->m_callbackUserData; |
0b746ba8 | 1069 | delete entry; |
0b746ba8 VZ |
1070 | } |
1071 | delete m_dynamicEvents; | |
dde19c21 | 1072 | } |
7214297d | 1073 | |
5875d39c VZ |
1074 | if (m_pendingEvents) |
1075 | m_pendingEvents->DeleteContents(true); | |
7ce2fb71 | 1076 | delete m_pendingEvents; |
7214297d | 1077 | |
dde19c21 FM |
1078 | // Remove us from the list of the pending events if necessary. |
1079 | wxEventLoopBase *loop = wxEventLoopBase::GetActive(); | |
1080 | if (loop) | |
1081 | loop->RemovePendingEventHandler(this); | |
b88c44e7 RD |
1082 | |
1083 | // we only delete object data, not untyped | |
1084 | if ( m_clientDataType == wxClientData_Object ) | |
1085 | delete m_clientObject; | |
c801d85f KB |
1086 | } |
1087 | ||
7f853dd0 FM |
1088 | void wxEvtHandler::Unlink() |
1089 | { | |
1090 | // this event handler must take itself out of the chain of handlers: | |
1091 | ||
1092 | if (m_previousHandler) | |
1093 | m_previousHandler->SetNextHandler(m_nextHandler); | |
1094 | ||
1095 | if (m_nextHandler) | |
1096 | m_nextHandler->SetPreviousHandler(m_previousHandler); | |
1097 | ||
1098 | m_nextHandler = NULL; | |
1099 | m_previousHandler = NULL; | |
1100 | } | |
1101 | ||
1102 | bool wxEvtHandler::IsUnlinked() const | |
1103 | { | |
1104 | return m_previousHandler == NULL && | |
1105 | m_nextHandler == NULL; | |
1106 | } | |
1107 | ||
7214297d | 1108 | #if wxUSE_THREADS |
aadbdf11 | 1109 | |
76bfdc9a | 1110 | bool wxEvtHandler::ProcessThreadEvent(const wxEvent& event) |
7214297d | 1111 | { |
7214297d | 1112 | // check that we are really in a child thread |
8e193f38 VZ |
1113 | wxASSERT_MSG( !wxThread::IsMain(), |
1114 | wxT("use ProcessEvent() in main thread") ); | |
1115 | ||
1116 | AddPendingEvent(event); | |
7214297d | 1117 | |
1c624631 | 1118 | return true; |
8e193f38 VZ |
1119 | } |
1120 | ||
1121 | #endif // wxUSE_THREADS | |
1122 | ||
c3f94162 | 1123 | void wxEvtHandler::QueueEvent(wxEvent *event) |
8e193f38 | 1124 | { |
c3f94162 | 1125 | wxCHECK_RET( event, "NULL event can't be posted" ); |
7a5c8ac4 | 1126 | |
dde19c21 FM |
1127 | wxEventLoopBase* loop = wxEventLoopBase::GetActive(); |
1128 | if (!loop) | |
1129 | { | |
1130 | // we need an event loop which manages the list of event handlers with | |
1131 | // pending events... cannot proceed without it! | |
9f54c829 FM |
1132 | wxLogDebug("No event loop is running! Cannot queue this event!"); |
1133 | ||
1134 | // anyway delete the given event to avoid memory leaks | |
1135 | delete event; | |
1136 | ||
dde19c21 FM |
1137 | return; |
1138 | } | |
1139 | ||
c3f94162 | 1140 | // 1) Add this event to our list of pending events |
8ebec7dc | 1141 | wxENTER_CRIT_SECT( m_pendingEventsLock ); |
16c1f79c | 1142 | |
8e193f38 VZ |
1143 | if ( !m_pendingEvents ) |
1144 | m_pendingEvents = new wxList; | |
7214297d | 1145 | |
c3f94162 | 1146 | m_pendingEvents->Append(event); |
7214297d | 1147 | |
16c1f79c RR |
1148 | // 2) Add this event handler to list of event handlers that |
1149 | // have pending events. | |
cfe17b74 | 1150 | |
dde19c21 | 1151 | loop->AppendPendingEventHandler(this); |
6164f93c | 1152 | |
a715b990 VZ |
1153 | // only release m_pendingEventsLock now because otherwise there is a race |
1154 | // condition as described in the ticket #9093: we could process the event | |
1155 | // just added to m_pendingEvents in our ProcessPendingEvents() below before | |
079f4130 | 1156 | // we had time to append this pointer to wxHandlersWithPendingEvents list; thus |
a715b990 VZ |
1157 | // breaking the invariant that a handler should be in the list iff it has |
1158 | // any pending events to process | |
1159 | wxLEAVE_CRIT_SECT( m_pendingEventsLock ); | |
1160 | ||
90e572f1 | 1161 | // 3) Inform the system that new pending events are somewhere, |
16c1f79c | 1162 | // and that these should be processed in idle time. |
bf9e3e73 | 1163 | wxWakeUpIdle(); |
7214297d GL |
1164 | } |
1165 | ||
1166 | void wxEvtHandler::ProcessPendingEvents() | |
1167 | { | |
dde19c21 FM |
1168 | wxEventLoopBase* loop = wxEventLoopBase::GetActive(); |
1169 | if (!loop) | |
1170 | { | |
1171 | // we need an event loop which manages the list of event handlers with | |
1172 | // pending events... cannot proceed without it! | |
9f54c829 | 1173 | wxLogDebug("No event loop is running! Cannot process pending events!"); |
dde19c21 FM |
1174 | return; |
1175 | } | |
1176 | ||
d48b06bd FM |
1177 | // we need to process only a single pending event in this call because |
1178 | // each call to ProcessEvent() could result in the destruction of this | |
1179 | // same event handler (see the comment at the end of this function) | |
1180 | ||
8ebec7dc | 1181 | wxENTER_CRIT_SECT( m_pendingEventsLock ); |
8e193f38 | 1182 | |
7ce2fb71 VZ |
1183 | // this method is only called by wxApp if this handler does have |
1184 | // pending events | |
1185 | wxCHECK_RET( m_pendingEvents && !m_pendingEvents->IsEmpty(), | |
1186 | "should have pending events if called" ); | |
5fa150e2 | 1187 | |
19c4d916 | 1188 | wxList::compatibility_iterator node = m_pendingEvents->GetFirst(); |
d48b06bd FM |
1189 | wxEvent* pEvent = static_cast<wxEvent *>(node->GetData()); |
1190 | ||
1191 | // find the first event which can be processed now: | |
dde19c21 FM |
1192 | wxEventLoopBase* evtLoop = wxEventLoopBase::GetActive(); |
1193 | if (evtLoop && evtLoop->IsYielding()) | |
d48b06bd | 1194 | { |
dde19c21 | 1195 | while (node && pEvent && !evtLoop->IsEventAllowedInsideYield(pEvent->GetEventCategory())) |
d48b06bd FM |
1196 | { |
1197 | node = node->GetNext(); | |
1198 | pEvent = node ? static_cast<wxEvent *>(node->GetData()) : NULL; | |
1199 | } | |
1200 | ||
1201 | if (!node) | |
1202 | { | |
1203 | // all our events are NOT processable now... signal this: | |
dde19c21 FM |
1204 | loop->DelayPendingEventHandler(this); |
1205 | ||
1206 | // see the comment at the beginning of evtloop.h header for the | |
1207 | // logic behind YieldFor() and behind DelayPendingEventHandler() | |
1208 | ||
d48b06bd FM |
1209 | wxLEAVE_CRIT_SECT( m_pendingEventsLock ); |
1210 | ||
1211 | return; | |
1212 | } | |
1213 | } | |
1214 | ||
1215 | wxEventPtr event(pEvent); | |
5875d39c | 1216 | |
19c4d916 VZ |
1217 | // it's important we remove event from list before processing it, else a |
1218 | // nested event loop, for example from a modal dialog, might process the | |
1219 | // same event again. | |
1220 | m_pendingEvents->Erase(node); | |
7b0d5c59 | 1221 | |
19c4d916 | 1222 | if ( m_pendingEvents->IsEmpty() ) |
1512f0f7 | 1223 | { |
dde19c21 FM |
1224 | // if there are no more pending events left, we don't need to |
1225 | // stay in this list | |
1226 | loop->RemovePendingEventHandler(this); | |
1512f0f7 | 1227 | } |
5fa150e2 | 1228 | |
8ebec7dc | 1229 | wxLEAVE_CRIT_SECT( m_pendingEventsLock ); |
7b0d5c59 | 1230 | |
19c4d916 | 1231 | ProcessEvent(*event); |
cfe17b74 | 1232 | |
19c4d916 VZ |
1233 | // careful: this object could have been deleted by the event handler |
1234 | // executed by the above ProcessEvent() call, so we can't access any fields | |
1235 | // of this object any more | |
7214297d | 1236 | } |
7214297d | 1237 | |
c801d85f KB |
1238 | /* |
1239 | * Event table stuff | |
1240 | */ | |
1c624631 | 1241 | /* static */ bool |
03f3617b VZ |
1242 | wxEvtHandler::ProcessEventIfMatchesId(const wxEventTableEntryBase& entry, |
1243 | wxEvtHandler *handler, | |
1244 | wxEvent& event) | |
1c624631 VZ |
1245 | { |
1246 | int tableId1 = entry.m_id, | |
1247 | tableId2 = entry.m_lastId; | |
1248 | ||
1249 | // match only if the event type is the same and the id is either -1 in | |
1250 | // the event table (meaning "any") or the event id matches the id | |
1251 | // specified in the event table either exactly or by falling into | |
1252 | // range between first and last | |
1a18887b WS |
1253 | if ((tableId1 == wxID_ANY) || |
1254 | (tableId2 == wxID_ANY && tableId1 == event.GetId()) || | |
1255 | (tableId2 != wxID_ANY && | |
1c624631 VZ |
1256 | (event.GetId() >= tableId1 && event.GetId() <= tableId2))) |
1257 | { | |
1258 | event.Skip(false); | |
1259 | event.m_callbackUserData = entry.m_callbackUserData; | |
1260 | ||
1261 | #if wxUSE_EXCEPTIONS | |
1262 | if ( wxTheApp ) | |
1263 | { | |
1264 | // call the handler via wxApp method which allows the user to catch | |
1265 | // any exceptions which may be thrown by any handler in the program | |
1266 | // in one place | |
3c778901 | 1267 | wxTheApp->CallEventHandler(handler, *entry.m_fn, event); |
1c624631 VZ |
1268 | } |
1269 | else | |
8bd2a804 | 1270 | #endif // wxUSE_EXCEPTIONS |
1c624631 | 1271 | { |
3c778901 | 1272 | (*entry.m_fn)(handler, event); |
1c624631 | 1273 | } |
1c624631 VZ |
1274 | |
1275 | if (!event.GetSkipped()) | |
1276 | return true; | |
1277 | } | |
1278 | ||
1279 | return false; | |
1280 | } | |
c801d85f | 1281 | |
4caf847c | 1282 | bool wxEvtHandler::TryParent(wxEvent& event) |
c801d85f | 1283 | { |
358e9f2f VZ |
1284 | if ( GetNextHandler() ) |
1285 | { | |
1286 | // the next handler will pass it to wxTheApp if it doesn't process it, | |
1287 | // so return from here to avoid doing it again | |
1288 | return GetNextHandler()->TryParent(event); | |
1289 | } | |
1290 | ||
4caf847c | 1291 | if ( wxTheApp && (this != wxTheApp) ) |
9154d8cf | 1292 | { |
4caf847c VZ |
1293 | // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always |
1294 | // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be | |
1295 | // processed appropriately via SearchEventTable. | |
1296 | if ( event.GetEventType() != wxEVT_IDLE ) | |
1297 | { | |
1298 | if ( wxTheApp->ProcessEvent(event) ) | |
1c624631 | 1299 | return true; |
4caf847c | 1300 | } |
9154d8cf VZ |
1301 | } |
1302 | ||
1c624631 | 1303 | return false; |
4caf847c | 1304 | } |
0b746ba8 | 1305 | |
4caf847c VZ |
1306 | bool wxEvtHandler::ProcessEvent(wxEvent& event) |
1307 | { | |
9154d8cf | 1308 | // allow the application to hook into event processing |
29de6f40 VZ |
1309 | // |
1310 | // note that we should only do it if we're the first event handler called | |
1311 | // to avoid calling FilterEvent() multiple times as the event goes through | |
1312 | // the event handler chain and possibly upwards the window hierarchy | |
1313 | if ( !event.WasProcessed() ) | |
9154d8cf | 1314 | { |
29de6f40 | 1315 | if ( wxTheApp ) |
9154d8cf | 1316 | { |
29de6f40 VZ |
1317 | int rc = wxTheApp->FilterEvent(event); |
1318 | if ( rc != -1 ) | |
1319 | { | |
1320 | wxASSERT_MSG( rc == 1 || rc == 0, | |
1321 | "unexpected wxApp::FilterEvent return value" ); | |
9154d8cf | 1322 | |
29de6f40 VZ |
1323 | return rc != 0; |
1324 | } | |
1325 | //else: proceed normally | |
9154d8cf | 1326 | } |
9154d8cf VZ |
1327 | } |
1328 | ||
25250d33 VZ |
1329 | if ( ProcessEventHere(event) ) |
1330 | return true; | |
1331 | ||
29de6f40 VZ |
1332 | // pass the event to the next handler, notice that we shouldn't call |
1333 | // TryParent() even if it doesn't handle the event as the last handler in | |
1334 | // the chain will do it | |
1335 | if ( GetNextHandler() ) | |
1336 | return GetNextHandler()->ProcessEvent(event); | |
1337 | ||
25250d33 | 1338 | // propagate the event upwards the window chain and/or to the application |
c9c1faa4 | 1339 | // object if it wasn't processed at this level |
25250d33 VZ |
1340 | return TryParent(event); |
1341 | } | |
1342 | ||
1343 | bool wxEvtHandler::ProcessEventHere(wxEvent& event) | |
1344 | { | |
29de6f40 VZ |
1345 | // If the event handler is disabled it doesn't process any events |
1346 | if ( !GetEvtHandlerEnabled() ) | |
1347 | return false; | |
4caf847c | 1348 | |
29de6f40 VZ |
1349 | // If we have a validator, it has higher priority than our own event |
1350 | // handlers | |
1351 | if ( TryValidator(event) ) | |
1352 | return true; | |
0b746ba8 | 1353 | |
29de6f40 VZ |
1354 | // Handle per-instance dynamic event tables first |
1355 | if ( m_dynamicEvents && SearchDynamicEventTable(event) ) | |
1356 | return true; | |
c801d85f | 1357 | |
29de6f40 VZ |
1358 | // Then static per-class event tables |
1359 | if ( GetEventHashTable().HandleEvent(event, this) ) | |
25250d33 | 1360 | return true; |
c801d85f | 1361 | |
25250d33 VZ |
1362 | // We don't have a handler for this event. |
1363 | return false; | |
c801d85f KB |
1364 | } |
1365 | ||
937013e0 VS |
1366 | bool wxEvtHandler::SafelyProcessEvent(wxEvent& event) |
1367 | { | |
1368 | #if wxUSE_EXCEPTIONS | |
1369 | try | |
1370 | { | |
1371 | #endif | |
1372 | return ProcessEvent(event); | |
1373 | #if wxUSE_EXCEPTIONS | |
1374 | } | |
1375 | catch ( ... ) | |
1376 | { | |
1377 | wxEventLoopBase *loop = wxEventLoopBase::GetActive(); | |
1378 | try | |
1379 | { | |
1380 | if ( !wxTheApp || !wxTheApp->OnExceptionInMainLoop() ) | |
1381 | { | |
1382 | if ( loop ) | |
1383 | loop->Exit(); | |
1384 | } | |
1385 | //else: continue running current event loop | |
1386 | ||
1387 | return false; | |
1388 | } | |
1389 | catch ( ... ) | |
1390 | { | |
1391 | // OnExceptionInMainLoop() threw, possibly rethrowing the same | |
1392 | // exception again: very good, but we still need Exit() to | |
1393 | // be called | |
1394 | if ( loop ) | |
1395 | loop->Exit(); | |
1396 | throw; | |
1397 | } | |
1398 | } | |
1399 | #endif // wxUSE_EXCEPTIONS | |
1400 | } | |
1401 | ||
b5a98acd | 1402 | |
c801d85f KB |
1403 | bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event) |
1404 | { | |
1c624631 | 1405 | const wxEventType eventType = event.GetEventType(); |
68662769 | 1406 | for ( int i = 0; table.entries[i].m_fn != 0; i++ ) |
c801d85f | 1407 | { |
68662769 | 1408 | const wxEventTableEntry& entry = table.entries[i]; |
68662769 | 1409 | if ( eventType == entry.m_eventType ) |
0b746ba8 | 1410 | { |
03f3617b | 1411 | if ( ProcessEventIfMatchesId(entry, this, event) ) |
1c624631 | 1412 | return true; |
0b746ba8 | 1413 | } |
c801d85f | 1414 | } |
68662769 | 1415 | |
1c624631 | 1416 | return false; |
c801d85f | 1417 | } |
97d7bfb8 | 1418 | |
f3ff831f VZ |
1419 | void wxEvtHandler::DoConnect(int id, |
1420 | int lastId, | |
1421 | wxEventType eventType, | |
1422 | wxEventFunctor *func, | |
1423 | wxObject *userData) | |
fe71f65c | 1424 | { |
0b5eceb6 | 1425 | wxDynamicEventTableEntry *entry = |
3c778901 | 1426 | new wxDynamicEventTableEntry(eventType, id, lastId, func, userData); |
0b746ba8 VZ |
1427 | |
1428 | if (!m_dynamicEvents) | |
1429 | m_dynamicEvents = new wxList; | |
1430 | ||
92309201 RD |
1431 | // Insert at the front of the list so most recent additions are found first |
1432 | m_dynamicEvents->Insert( (wxObject*) entry ); | |
cc6ceca7 VZ |
1433 | |
1434 | // Make sure we get to know when a sink is destroyed | |
f3ff831f | 1435 | wxEvtHandler *eventSink = func->GetEvtHandler(); |
886274c6 | 1436 | if ( eventSink && eventSink != this ) |
2ef989c9 | 1437 | { |
cc6ceca7 VZ |
1438 | wxEventConnectionRef *evtConnRef = FindRefInTrackerList(eventSink); |
1439 | if ( evtConnRef ) | |
1440 | evtConnRef->IncRef( ); | |
2ef989c9 | 1441 | else |
e822d1bd | 1442 | new wxEventConnectionRef(this, eventSink); |
2ef989c9 | 1443 | } |
fe71f65c | 1444 | } |
97d7bfb8 | 1445 | |
3c778901 | 1446 | bool |
f3ff831f VZ |
1447 | wxEvtHandler::DoDisconnect(int id, |
1448 | int lastId, | |
1449 | wxEventType eventType, | |
1450 | const wxEventFunctor& func, | |
1451 | wxObject *userData) | |
97d7bfb8 RR |
1452 | { |
1453 | if (!m_dynamicEvents) | |
1c624631 | 1454 | return false; |
cfe17b74 | 1455 | |
2ef989c9 | 1456 | // Remove connection from tracker node (wxEventConnectionRef) |
f3ff831f | 1457 | wxEvtHandler *eventSink = func.GetEvtHandler(); |
886274c6 | 1458 | if ( eventSink && eventSink != this ) |
2ef989c9 | 1459 | { |
cc6ceca7 VZ |
1460 | wxEventConnectionRef *evtConnRef = FindRefInTrackerList(eventSink); |
1461 | if ( evtConnRef ) | |
1462 | evtConnRef->DecRef(); | |
2ef989c9 RR |
1463 | } |
1464 | ||
df5168c4 | 1465 | wxList::compatibility_iterator node = m_dynamicEvents->GetFirst(); |
97d7bfb8 RR |
1466 | while (node) |
1467 | { | |
ad684023 | 1468 | wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData(); |
2e4df4bf | 1469 | |
97d7bfb8 | 1470 | if ((entry->m_id == id) && |
1a18887b | 1471 | ((entry->m_lastId == lastId) || (lastId == wxID_ANY)) && |
97d7bfb8 | 1472 | ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) && |
03f3617b | 1473 | entry->m_fn->Matches(func) && |
3c778901 | 1474 | ((entry->m_callbackUserData == userData) || !userData)) |
97d7bfb8 | 1475 | { |
3c778901 | 1476 | delete entry->m_callbackUserData; |
df5168c4 | 1477 | m_dynamicEvents->Erase( node ); |
97d7bfb8 | 1478 | delete entry; |
1c624631 | 1479 | return true; |
97d7bfb8 | 1480 | } |
b1d4dd7a | 1481 | node = node->GetNext(); |
97d7bfb8 | 1482 | } |
1c624631 | 1483 | return false; |
97d7bfb8 | 1484 | } |
fe71f65c RR |
1485 | |
1486 | bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event ) | |
1487 | { | |
1c624631 | 1488 | wxCHECK_MSG( m_dynamicEvents, false, |
223d09f6 | 1489 | wxT("caller should check that we have dynamic events") ); |
0b746ba8 | 1490 | |
df5168c4 | 1491 | wxList::compatibility_iterator node = m_dynamicEvents->GetFirst(); |
0b746ba8 | 1492 | while (node) |
fe71f65c | 1493 | { |
1c624631 | 1494 | wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData(); |
0b746ba8 | 1495 | |
7fce89b9 VZ |
1496 | // get next node before (maybe) calling the event handler as it could |
1497 | // call Disconnect() invalidating the current node | |
1498 | node = node->GetNext(); | |
1499 | ||
03f3617b | 1500 | if ( event.GetEventType() == entry->m_eventType ) |
0b746ba8 | 1501 | { |
f3ff831f | 1502 | wxEvtHandler *handler = entry->m_fn->GetEvtHandler(); |
03f3617b VZ |
1503 | if ( !handler ) |
1504 | handler = this; | |
1505 | if ( ProcessEventIfMatchesId(*entry, handler, event) ) | |
1c624631 | 1506 | return true; |
0b746ba8 | 1507 | } |
7b678698 | 1508 | } |
1c624631 VZ |
1509 | |
1510 | return false; | |
4115960d | 1511 | } |
fe71f65c | 1512 | |
b88c44e7 RD |
1513 | void wxEvtHandler::DoSetClientObject( wxClientData *data ) |
1514 | { | |
1515 | wxASSERT_MSG( m_clientDataType != wxClientData_Void, | |
1516 | wxT("can't have both object and void client data") ); | |
1517 | ||
1518 | if ( m_clientObject ) | |
1519 | delete m_clientObject; | |
1520 | ||
1521 | m_clientObject = data; | |
1522 | m_clientDataType = wxClientData_Object; | |
1523 | } | |
1524 | ||
1525 | wxClientData *wxEvtHandler::DoGetClientObject() const | |
1526 | { | |
1527 | // it's not an error to call GetClientObject() on a window which doesn't | |
1528 | // have client data at all - NULL will be returned | |
1529 | wxASSERT_MSG( m_clientDataType != wxClientData_Void, | |
1530 | wxT("this window doesn't have object client data") ); | |
1531 | ||
1532 | return m_clientObject; | |
1533 | } | |
1534 | ||
1535 | void wxEvtHandler::DoSetClientData( void *data ) | |
1536 | { | |
1537 | wxASSERT_MSG( m_clientDataType != wxClientData_Object, | |
1538 | wxT("can't have both object and void client data") ); | |
1539 | ||
1540 | m_clientData = data; | |
1541 | m_clientDataType = wxClientData_Void; | |
1542 | } | |
1543 | ||
1544 | void *wxEvtHandler::DoGetClientData() const | |
1545 | { | |
1546 | // it's not an error to call GetClientData() on a window which doesn't have | |
1547 | // client data at all - NULL will be returned | |
1548 | wxASSERT_MSG( m_clientDataType != wxClientData_Object, | |
1549 | wxT("this window doesn't have void client data") ); | |
1550 | ||
1551 | return m_clientData; | |
1552 | } | |
1553 | ||
cc6ceca7 VZ |
1554 | // A helper to find an wxEventConnectionRef object |
1555 | wxEventConnectionRef * | |
1556 | wxEvtHandler::FindRefInTrackerList(wxEvtHandler *eventSink) | |
2ef989c9 | 1557 | { |
cc6ceca7 | 1558 | for ( wxTrackerNode *node = eventSink->GetFirst(); node; node = node->m_nxt ) |
2ef989c9 | 1559 | { |
cc6ceca7 VZ |
1560 | // we only want wxEventConnectionRef nodes here |
1561 | wxEventConnectionRef *evtConnRef = node->ToEventConnection(); | |
1562 | if ( evtConnRef && evtConnRef->m_src == this ) | |
2ef989c9 | 1563 | { |
cc6ceca7 VZ |
1564 | wxASSERT( evtConnRef->m_sink==eventSink ); |
1565 | return evtConnRef; | |
2ef989c9 RR |
1566 | } |
1567 | } | |
cc6ceca7 | 1568 | |
2ef989c9 RR |
1569 | return NULL; |
1570 | } | |
1571 | ||
1572 | void wxEvtHandler::OnSinkDestroyed( wxEvtHandler *sink ) | |
1573 | { | |
1574 | wxASSERT(m_dynamicEvents); | |
cc6ceca7 | 1575 | |
2ef989c9 RR |
1576 | // remove all connections with this sink |
1577 | wxList::compatibility_iterator node = m_dynamicEvents->GetFirst(), node_nxt; | |
1578 | while (node) | |
1579 | { | |
1580 | wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData(); | |
1581 | node_nxt = node->GetNext(); | |
cc6ceca7 | 1582 | |
f3ff831f | 1583 | if ( entry->m_fn->GetEvtHandler() == sink ) |
2ef989c9 | 1584 | { |
3c778901 | 1585 | delete entry->m_callbackUserData; |
2ef989c9 RR |
1586 | m_dynamicEvents->Erase( node ); |
1587 | delete entry; | |
1588 | } | |
1589 | node = node_nxt; | |
1590 | } | |
1591 | } | |
1592 | ||
4caf847c VZ |
1593 | #endif // wxUSE_BASE |
1594 | ||
e90c1d2a VZ |
1595 | #if wxUSE_GUI |
1596 | ||
e702ff0f JS |
1597 | // Find a window with the focus, that is also a descendant of the given window. |
1598 | // This is used to determine the window to initially send commands to. | |
1599 | wxWindow* wxFindFocusDescendant(wxWindow* ancestor) | |
1600 | { | |
1601 | // Process events starting with the window with the focus, if any. | |
1602 | wxWindow* focusWin = wxWindow::FindFocus(); | |
1603 | wxWindow* win = focusWin; | |
1604 | ||
1605 | // Check if this is a descendant of this frame. | |
1606 | // If not, win will be set to NULL. | |
1607 | while (win) | |
1608 | { | |
1609 | if (win == ancestor) | |
1610 | break; | |
1611 | else | |
1612 | win = win->GetParent(); | |
1613 | } | |
3c778901 VZ |
1614 | if (win == NULL) |
1615 | focusWin = NULL; | |
e702ff0f JS |
1616 | |
1617 | return focusWin; | |
1618 | } | |
1619 | ||
c4fa5aa7 VZ |
1620 | // ---------------------------------------------------------------------------- |
1621 | // wxEventBlocker | |
1622 | // ---------------------------------------------------------------------------- | |
1623 | ||
1624 | wxEventBlocker::wxEventBlocker(wxWindow *win, wxEventType type) | |
1625 | { | |
1626 | wxCHECK_RET(win, wxT("Null window given to wxEventBlocker")); | |
1627 | ||
1628 | m_window = win; | |
1629 | ||
1630 | Block(type); | |
1631 | m_window->PushEventHandler(this); | |
1632 | } | |
1633 | ||
1634 | wxEventBlocker::~wxEventBlocker() | |
1635 | { | |
1636 | wxEvtHandler *popped = m_window->PopEventHandler(false); | |
aa767a45 | 1637 | wxCHECK_RET(popped == this, |
c4fa5aa7 VZ |
1638 | wxT("Don't push other event handlers into a window managed by wxEventBlocker!")); |
1639 | } | |
1640 | ||
1641 | bool wxEventBlocker::ProcessEvent(wxEvent& event) | |
1642 | { | |
1643 | // should this event be blocked? | |
1644 | for ( size_t i = 0; i < m_eventsToBlock.size(); i++ ) | |
1645 | { | |
1646 | wxEventType t = (wxEventType)m_eventsToBlock[i]; | |
1647 | if ( t == wxEVT_ANY || t == event.GetEventType() ) | |
1648 | return true; // yes, it should: mark this event as processed | |
1649 | } | |
1650 | ||
1651 | return false; | |
1652 | } | |
1653 | ||
e90c1d2a | 1654 | #endif // wxUSE_GUI |
3c778901 | 1655 |