]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: event.cpp | |
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 |
e90c1d2a | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
8e193f38 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
c801d85f | 20 | #ifdef __GNUG__ |
0b746ba8 | 21 | #pragma implementation "event.h" |
c801d85f KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
0b746ba8 | 28 | #pragma hdrstop |
c801d85f KB |
29 | #endif |
30 | ||
31 | #ifndef WX_PRECOMP | |
0b746ba8 | 32 | #include "wx/defs.h" |
0b746ba8 | 33 | #include "wx/app.h" |
e90c1d2a VZ |
34 | #include "wx/list.h" |
35 | ||
36 | #if wxUSE_GUI | |
37 | #include "wx/control.h" | |
38 | #include "wx/utils.h" | |
39 | #include "wx/dc.h" | |
40 | #endif // wxUSE_GUI | |
c801d85f KB |
41 | #endif |
42 | ||
43 | #include "wx/event.h" | |
e90c1d2a VZ |
44 | |
45 | #if wxUSE_GUI | |
46 | #include "wx/validate.h" | |
0b30bb0b JS |
47 | #if wxUSE_STOPWATCH |
48 | #include "wx/stopwatch.h" | |
49 | #endif | |
e90c1d2a | 50 | #endif // wxUSE_GUI |
c801d85f | 51 | |
8e193f38 VZ |
52 | // ---------------------------------------------------------------------------- |
53 | // wxWin macros | |
54 | // ---------------------------------------------------------------------------- | |
55 | ||
3ed2104c VZ |
56 | #if wxUSE_BASE |
57 | IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject) | |
58 | IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject) | |
59 | #endif // wxUSE_BASE | |
e90c1d2a | 60 | |
23f681ec | 61 | #if wxUSE_GUI |
6b55490a | 62 | IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent) |
23f681ec VZ |
63 | IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent) |
64 | IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent) | |
65 | IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent) | |
66 | IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent, wxEvent) | |
67 | IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent) | |
68 | IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent) | |
69 | IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent) | |
70 | IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent) | |
1e6feb95 | 71 | IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent, wxEvent) |
23f681ec VZ |
72 | IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent) |
73 | IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent) | |
74 | IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent) | |
456bc6d9 | 75 | IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent, wxCommandEvent) |
23f681ec VZ |
76 | IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent) |
77 | IMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent) | |
78 | IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent) | |
79 | IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent) | |
80 | IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent) | |
81 | IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent) | |
82 | IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent) | |
83 | IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent) | |
84 | IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent) | |
8e72b8b5 | 85 | IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent, wxEvent) |
23f681ec | 86 | IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent) |
574c939e | 87 | IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent, wxEvent) |
23f681ec VZ |
88 | IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent) |
89 | IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxCommandEvent) | |
90 | IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, wxEvent) | |
91 | IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent, wxEvent) | |
92 | IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent, wxEvent) | |
93 | IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent, wxEvent) | |
b96340e6 | 94 | IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent, wxCommandEvent) |
69231000 | 95 | IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent, wxCommandEvent) |
a5e84126 | 96 | IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent, wxEvent) |
23f681ec | 97 | #endif // wxUSE_GUI |
0b746ba8 | 98 | |
3ed2104c VZ |
99 | #if wxUSE_BASE |
100 | ||
23f681ec VZ |
101 | const wxEventTable *wxEvtHandler::GetEventTable() const |
102 | { return &wxEvtHandler::sm_eventTable; } | |
0b746ba8 | 103 | |
23f681ec VZ |
104 | const wxEventTable wxEvtHandler::sm_eventTable = |
105 | { (const wxEventTable *)NULL, &wxEvtHandler::sm_eventTableEntries[0] }; | |
0b746ba8 | 106 | |
23f681ec | 107 | const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] = |
9aaf9bed | 108 | { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL, 0, 0, (wxObjectEventFunction)NULL, NULL) }; |
c801d85f | 109 | |
8e193f38 VZ |
110 | // ---------------------------------------------------------------------------- |
111 | // global variables | |
112 | // ---------------------------------------------------------------------------- | |
113 | ||
114 | // To put pending event handlers | |
115 | wxList *wxPendingEvents = (wxList *)NULL; | |
116 | ||
7214297d | 117 | #if wxUSE_THREADS |
8e193f38 VZ |
118 | // protects wxPendingEvents list |
119 | wxCriticalSection *wxPendingEventsLocker = (wxCriticalSection *)NULL; | |
7214297d GL |
120 | #endif |
121 | ||
cbee8f8d VZ |
122 | #if !WXWIN_COMPATIBILITY_EVENT_TYPES |
123 | ||
2e4df4bf VZ |
124 | // common event types are defined here, other event types are defined by the |
125 | // components which use them | |
c15d9c85 VS |
126 | |
127 | const wxEventType wxEVT_FIRST = 10000; | |
128 | const wxEventType wxEVT_USER_FIRST = wxEVT_FIRST + 2000; | |
2e4df4bf | 129 | |
461697c2 | 130 | DEFINE_EVENT_TYPE(wxEVT_NULL) |
886dd7d2 VZ |
131 | DEFINE_EVENT_TYPE(wxEVT_IDLE) |
132 | DEFINE_EVENT_TYPE(wxEVT_SOCKET) | |
133 | ||
134 | #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES | |
135 | ||
136 | #endif // wxUSE_BASE | |
137 | ||
138 | #if wxUSE_GUI | |
139 | ||
140 | #if !WXWIN_COMPATIBILITY_EVENT_TYPES | |
141 | ||
2e4df4bf VZ |
142 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED) |
143 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED) | |
144 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED) | |
145 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED) | |
146 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED) | |
147 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED) | |
2e4df4bf VZ |
148 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED) |
149 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED) | |
150 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED) | |
151 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED) | |
152 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED) | |
153 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED) | |
154 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED) | |
155 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED) | |
156 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER) | |
157 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED) | |
0b5eceb6 VZ |
158 | |
159 | // Sockets and timers send events, too | |
2e4df4bf | 160 | DEFINE_EVENT_TYPE(wxEVT_TIMER) |
0b5eceb6 VZ |
161 | |
162 | // Mouse event types | |
2e4df4bf VZ |
163 | DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN) |
164 | DEFINE_EVENT_TYPE(wxEVT_LEFT_UP) | |
165 | DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN) | |
166 | DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP) | |
167 | DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN) | |
168 | DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP) | |
169 | DEFINE_EVENT_TYPE(wxEVT_MOTION) | |
170 | DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW) | |
171 | DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW) | |
172 | DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK) | |
173 | DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK) | |
174 | DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK) | |
175 | DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS) | |
176 | DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS) | |
456bc6d9 | 177 | DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS) |
d2c52078 | 178 | DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL) |
0b5eceb6 VZ |
179 | |
180 | // Non-client mouse events | |
2e4df4bf VZ |
181 | DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN) |
182 | DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP) | |
183 | DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN) | |
184 | DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP) | |
185 | DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN) | |
186 | DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP) | |
187 | DEFINE_EVENT_TYPE(wxEVT_NC_MOTION) | |
188 | DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW) | |
189 | DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW) | |
190 | DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK) | |
191 | DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK) | |
192 | DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK) | |
0b5eceb6 VZ |
193 | |
194 | // Character input event type | |
2e4df4bf VZ |
195 | DEFINE_EVENT_TYPE(wxEVT_CHAR) |
196 | DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK) | |
197 | DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY) | |
198 | DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN) | |
199 | DEFINE_EVENT_TYPE(wxEVT_KEY_UP) | |
5048c832 JS |
200 | #if wxUSE_HOTKEY |
201 | DEFINE_EVENT_TYPE(wxEVT_HOTKEY) | |
202 | #endif | |
0b5eceb6 VZ |
203 | |
204 | // Set cursor event | |
2e4df4bf | 205 | DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR) |
0b5eceb6 VZ |
206 | |
207 | // wxScrollbar and wxSlider event identifiers | |
2e4df4bf VZ |
208 | DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP) |
209 | DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM) | |
210 | DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP) | |
211 | DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN) | |
212 | DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP) | |
213 | DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN) | |
214 | DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK) | |
215 | DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE) | |
e8b669d3 | 216 | DEFINE_EVENT_TYPE(wxEVT_SCROLL_ENDSCROLL) |
0b5eceb6 VZ |
217 | |
218 | // Scroll events from wxWindow | |
2e4df4bf VZ |
219 | DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP) |
220 | DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM) | |
221 | DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP) | |
222 | DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN) | |
223 | DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP) | |
224 | DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN) | |
225 | DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK) | |
226 | DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE) | |
0b5eceb6 VZ |
227 | |
228 | // System events | |
2e4df4bf | 229 | DEFINE_EVENT_TYPE(wxEVT_SIZE) |
5706de1c | 230 | DEFINE_EVENT_TYPE(wxEVT_SIZING) |
2e4df4bf | 231 | DEFINE_EVENT_TYPE(wxEVT_MOVE) |
5706de1c | 232 | DEFINE_EVENT_TYPE(wxEVT_MOVING) |
2e4df4bf VZ |
233 | DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW) |
234 | DEFINE_EVENT_TYPE(wxEVT_END_SESSION) | |
235 | DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION) | |
236 | DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP) | |
237 | DEFINE_EVENT_TYPE(wxEVT_POWER) | |
238 | DEFINE_EVENT_TYPE(wxEVT_ACTIVATE) | |
239 | DEFINE_EVENT_TYPE(wxEVT_CREATE) | |
240 | DEFINE_EVENT_TYPE(wxEVT_DESTROY) | |
241 | DEFINE_EVENT_TYPE(wxEVT_SHOW) | |
242 | DEFINE_EVENT_TYPE(wxEVT_ICONIZE) | |
243 | DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE) | |
244 | DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED) | |
245 | DEFINE_EVENT_TYPE(wxEVT_PAINT) | |
246 | DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND) | |
247 | DEFINE_EVENT_TYPE(wxEVT_NC_PAINT) | |
248 | DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON) | |
ccef86c7 VZ |
249 | DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN) |
250 | DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE) | |
2e4df4bf | 251 | DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT) |
2e4df4bf VZ |
252 | DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU) |
253 | DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED) | |
574c939e | 254 | DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED) |
2e4df4bf VZ |
255 | DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED) |
256 | DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE) | |
257 | DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED) | |
258 | DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN) | |
259 | DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP) | |
260 | DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE) | |
261 | DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE) | |
262 | DEFINE_EVENT_TYPE(wxEVT_DROP_FILES) | |
263 | DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM) | |
264 | DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM) | |
265 | DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM) | |
266 | DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG) | |
2e4df4bf | 267 | DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI) |
0b5eceb6 VZ |
268 | |
269 | // Generic command events | |
270 | // Note: a click is a higher-level event than button down/up | |
2e4df4bf VZ |
271 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK) |
272 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK) | |
273 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK) | |
274 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK) | |
275 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS) | |
276 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS) | |
277 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER) | |
0b5eceb6 VZ |
278 | |
279 | // Help events | |
2e4df4bf VZ |
280 | DEFINE_EVENT_TYPE(wxEVT_HELP) |
281 | DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP) | |
6164f93c VZ |
282 | |
283 | #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES | |
284 | ||
886dd7d2 VZ |
285 | #endif // wxUSE_GUI |
286 | ||
287 | #if wxUSE_BASE | |
288 | ||
6164f93c VZ |
289 | // ============================================================================ |
290 | // implementation | |
291 | // ============================================================================ | |
0b5eceb6 | 292 | |
0b5eceb6 VZ |
293 | // ---------------------------------------------------------------------------- |
294 | // event initialization | |
295 | // ---------------------------------------------------------------------------- | |
296 | ||
297 | int wxNewEventType() | |
298 | { | |
299 | // MT-FIXME | |
300 | static int s_lastUsedEventType = wxEVT_FIRST; | |
301 | ||
cbee8f8d VZ |
302 | #if WXWIN_COMPATIBILITY_2 |
303 | // check that we don't overlap with the user-defined types: if it does | |
304 | // happen, the best solution is probably to update the existing code to | |
305 | // use wxNewEventType() instead of wxEVT_USER_FIRST | |
6164f93c VZ |
306 | // |
307 | // due to the uncertainty | |
cbee8f8d VZ |
308 | wxASSERT_MSG( s_lastUsedEventType < wxEVT_USER_FIRST - 1, |
309 | _T("possible event type conflict") ); | |
310 | #endif // WXWIN_COMPATIBILITY_2 | |
311 | ||
0b5eceb6 VZ |
312 | return s_lastUsedEventType++; |
313 | } | |
314 | ||
8e193f38 VZ |
315 | // ---------------------------------------------------------------------------- |
316 | // wxEvent | |
317 | // ---------------------------------------------------------------------------- | |
318 | ||
c801d85f KB |
319 | /* |
320 | * General wxWindows events, covering | |
321 | * all interesting things that might happen (button clicking, resizing, | |
322 | * setting text in widgets, etc.). | |
323 | * | |
324 | * For each completely new event type, derive a new event class. | |
325 | * | |
326 | */ | |
327 | ||
8e72b8b5 | 328 | wxEvent::wxEvent(int theId, wxEventType commandType ) |
c801d85f | 329 | { |
8e72b8b5 | 330 | m_eventType = commandType; |
0b746ba8 | 331 | m_eventObject = (wxObject *) NULL; |
0b746ba8 VZ |
332 | m_timeStamp = 0; |
333 | m_id = theId; | |
334 | m_skipped = FALSE; | |
335 | m_callbackUserData = (wxObject *) NULL; | |
193bf013 | 336 | m_isCommandEvent = FALSE; |
c801d85f KB |
337 | } |
338 | ||
8e72b8b5 | 339 | wxEvent::wxEvent(const wxEvent &src) |
e6a6feba GD |
340 | : wxObject() |
341 | , m_eventObject(src.m_eventObject) | |
342 | , m_eventType(src.m_eventType) | |
343 | , m_timeStamp(src.m_timeStamp) | |
344 | , m_id(src.m_id) | |
345 | , m_callbackUserData(src.m_callbackUserData) | |
346 | , m_skipped(src.m_skipped) | |
347 | , m_isCommandEvent(src.m_isCommandEvent) | |
a737331d | 348 | { |
a737331d GL |
349 | } |
350 | ||
3ed2104c VZ |
351 | #endif // wxUSE_BASE |
352 | ||
e90c1d2a VZ |
353 | #if wxUSE_GUI |
354 | ||
c801d85f KB |
355 | /* |
356 | * Command events | |
357 | * | |
358 | */ | |
359 | ||
7798a18e | 360 | wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId) |
e6a6feba | 361 | : wxEvent(theId, commandType) |
c801d85f | 362 | { |
0b746ba8 VZ |
363 | m_clientData = (char *) NULL; |
364 | m_clientObject = (wxClientData *) NULL; | |
365 | m_extraLong = 0; | |
366 | m_commandInt = 0; | |
04392d70 | 367 | m_commandString = wxEmptyString; |
193bf013 | 368 | m_isCommandEvent = TRUE; |
c801d85f KB |
369 | } |
370 | ||
0b30bb0b JS |
371 | /* |
372 | * UI update events | |
373 | */ | |
374 | ||
375 | #if wxUSE_LONGLONG | |
e39af974 | 376 | wxLongLong wxUpdateUIEvent::sm_lastUpdate = 0; |
0b30bb0b JS |
377 | #endif |
378 | ||
e39af974 JS |
379 | long wxUpdateUIEvent::sm_updateInterval = 0; |
380 | ||
381 | wxUpdateUIMode wxUpdateUIEvent::sm_updateMode = wxUPDATE_UI_PROCESS_ALL; | |
0b30bb0b JS |
382 | |
383 | // Can we update? | |
e39af974 | 384 | bool wxUpdateUIEvent::CanUpdate(wxWindow* win) |
0b30bb0b | 385 | { |
e39af974 JS |
386 | // Don't update if we've switched global updating off |
387 | // and this window doesn't support updates. | |
388 | if (win && | |
389 | (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED && | |
390 | ((win->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES) == 0))) | |
391 | return FALSE; | |
392 | ||
393 | if (sm_updateInterval == -1) | |
0b30bb0b | 394 | return FALSE; |
e39af974 | 395 | else if (sm_updateInterval == 0) |
0b30bb0b JS |
396 | return TRUE; |
397 | else | |
398 | { | |
399 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG | |
400 | wxLongLong now = wxGetLocalTimeMillis(); | |
e39af974 | 401 | if (now > (sm_lastUpdate + sm_updateInterval)) |
0b30bb0b JS |
402 | { |
403 | return TRUE; | |
404 | } | |
405 | #else | |
406 | // If we don't have wxStopWatch or wxLongLong, we | |
407 | // should err on the safe side and update now anyway. | |
408 | return TRUE; | |
409 | #endif | |
410 | } | |
411 | return FALSE; | |
412 | } | |
413 | ||
414 | // Reset the update time to provide a delay until the next | |
415 | // time we should update | |
416 | void wxUpdateUIEvent::ResetUpdateTime() | |
417 | { | |
418 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG | |
e39af974 | 419 | if (sm_updateInterval > 0) |
0b30bb0b JS |
420 | { |
421 | wxLongLong now = wxGetLocalTimeMillis(); | |
e39af974 | 422 | if (now > (sm_lastUpdate + sm_updateInterval)) |
0b30bb0b | 423 | { |
e39af974 | 424 | sm_lastUpdate = now; |
0b30bb0b JS |
425 | } |
426 | } | |
427 | #endif | |
428 | } | |
429 | ||
e39af974 JS |
430 | /* |
431 | * Idle events | |
432 | */ | |
433 | ||
434 | wxIdleMode wxIdleEvent::sm_idleMode = wxIDLE_PROCESS_ALL; | |
435 | ||
436 | // Can we send an idle event? | |
437 | bool wxIdleEvent::CanSend(wxWindow* win) | |
438 | { | |
439 | // Don't update if we've switched global updating off | |
440 | // and this window doesn't support updates. | |
441 | if (win && | |
442 | (GetMode() == wxIDLE_PROCESS_SPECIFIED && | |
443 | ((win->GetExtraStyle() & wxWS_EX_PROCESS_IDLE) == 0))) | |
444 | return FALSE; | |
445 | ||
446 | return TRUE; | |
447 | } | |
0b30bb0b | 448 | |
c801d85f KB |
449 | /* |
450 | * Scroll events | |
451 | */ | |
452 | ||
0b746ba8 VZ |
453 | wxScrollEvent::wxScrollEvent(wxEventType commandType, |
454 | int id, | |
455 | int pos, | |
456 | int orient) | |
e6a6feba | 457 | : wxCommandEvent(commandType, id) |
c801d85f | 458 | { |
0b746ba8 VZ |
459 | m_extraLong = orient; |
460 | m_commandInt = pos; | |
c801d85f KB |
461 | } |
462 | ||
d1367c3d RR |
463 | /* |
464 | * ScrollWin events | |
465 | */ | |
466 | ||
467 | wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType, | |
468 | int pos, | |
469 | int orient) | |
d1367c3d | 470 | { |
c5b42c87 | 471 | m_eventType = commandType; |
d1367c3d RR |
472 | m_extraLong = orient; |
473 | m_commandInt = pos; | |
474 | } | |
475 | ||
c801d85f KB |
476 | /* |
477 | * Mouse events | |
478 | * | |
479 | */ | |
480 | ||
7798a18e | 481 | wxMouseEvent::wxMouseEvent(wxEventType commandType) |
c801d85f | 482 | { |
0b746ba8 VZ |
483 | m_eventType = commandType; |
484 | m_metaDown = FALSE; | |
485 | m_altDown = FALSE; | |
486 | m_controlDown = FALSE; | |
487 | m_shiftDown = FALSE; | |
488 | m_leftDown = FALSE; | |
489 | m_rightDown = FALSE; | |
490 | m_middleDown = FALSE; | |
491 | m_x = 0; | |
492 | m_y = 0; | |
d2c52078 RD |
493 | m_wheelRotation = 0; |
494 | m_wheelDelta = 0; | |
495 | m_linesPerAction = 0; | |
c801d85f KB |
496 | } |
497 | ||
abcbaea7 VZ |
498 | void wxMouseEvent::Assign(const wxMouseEvent& event) |
499 | { | |
9a1725c4 | 500 | m_eventType = event.m_eventType; |
92309201 | 501 | |
abcbaea7 VZ |
502 | m_x = event.m_x; |
503 | m_y = event.m_y; | |
504 | ||
505 | m_leftDown = event.m_leftDown; | |
506 | m_middleDown = event.m_middleDown; | |
507 | m_rightDown = event.m_rightDown; | |
508 | ||
509 | m_controlDown = event.m_controlDown; | |
510 | m_shiftDown = event.m_shiftDown; | |
511 | m_altDown = event.m_altDown; | |
512 | m_metaDown = event.m_metaDown; | |
513 | ||
514 | m_wheelRotation = event.m_wheelRotation; | |
515 | m_wheelDelta = event.m_wheelDelta; | |
516 | m_linesPerAction = event.m_linesPerAction; | |
517 | } | |
518 | ||
c801d85f KB |
519 | // True if was a button dclick event (1 = left, 2 = middle, 3 = right) |
520 | // or any button dclick event (but = -1) | |
521 | bool wxMouseEvent::ButtonDClick(int but) const | |
522 | { | |
0b746ba8 VZ |
523 | switch (but) |
524 | { | |
525 | case -1: | |
526 | return (LeftDClick() || MiddleDClick() || RightDClick()); | |
527 | case 1: | |
528 | return LeftDClick(); | |
529 | case 2: | |
530 | return MiddleDClick(); | |
531 | case 3: | |
532 | return RightDClick(); | |
533 | default: | |
223d09f6 | 534 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick")); |
0b746ba8 VZ |
535 | } |
536 | ||
537 | return FALSE; | |
c801d85f KB |
538 | } |
539 | ||
540 | // True if was a button down event (1 = left, 2 = middle, 3 = right) | |
541 | // or any button down event (but = -1) | |
542 | bool wxMouseEvent::ButtonDown(int but) const | |
543 | { | |
0b746ba8 VZ |
544 | switch (but) |
545 | { | |
546 | case -1: | |
547 | return (LeftDown() || MiddleDown() || RightDown()); | |
548 | case 1: | |
549 | return LeftDown(); | |
550 | case 2: | |
551 | return MiddleDown(); | |
552 | case 3: | |
553 | return RightDown(); | |
554 | default: | |
223d09f6 | 555 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown")); |
0b746ba8 VZ |
556 | } |
557 | ||
558 | return FALSE; | |
c801d85f KB |
559 | } |
560 | ||
561 | // True if was a button up event (1 = left, 2 = middle, 3 = right) | |
562 | // or any button up event (but = -1) | |
563 | bool wxMouseEvent::ButtonUp(int but) const | |
564 | { | |
1e6feb95 VZ |
565 | switch (but) |
566 | { | |
0b746ba8 VZ |
567 | case -1: |
568 | return (LeftUp() || MiddleUp() || RightUp()); | |
569 | case 1: | |
570 | return LeftUp(); | |
571 | case 2: | |
572 | return MiddleUp(); | |
573 | case 3: | |
574 | return RightUp(); | |
575 | default: | |
223d09f6 | 576 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp")); |
0b746ba8 VZ |
577 | } |
578 | ||
579 | return FALSE; | |
c801d85f KB |
580 | } |
581 | ||
582 | // True if the given button is currently changing state | |
583 | bool wxMouseEvent::Button(int but) const | |
584 | { | |
1e6feb95 VZ |
585 | switch (but) |
586 | { | |
0b746ba8 | 587 | case -1: |
72cdf4c9 | 588 | return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1)); |
0b746ba8 VZ |
589 | case 1: |
590 | return (LeftDown() || LeftUp() || LeftDClick()); | |
591 | case 2: | |
592 | return (MiddleDown() || MiddleUp() || MiddleDClick()); | |
593 | case 3: | |
594 | return (RightDown() || RightUp() || RightDClick()); | |
595 | default: | |
223d09f6 | 596 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button")); |
0b746ba8 VZ |
597 | } |
598 | ||
599 | return FALSE; | |
c801d85f KB |
600 | } |
601 | ||
602 | bool wxMouseEvent::ButtonIsDown(int but) const | |
603 | { | |
1e6feb95 VZ |
604 | switch (but) |
605 | { | |
0b746ba8 VZ |
606 | case -1: |
607 | return (LeftIsDown() || MiddleIsDown() || RightIsDown()); | |
608 | case 1: | |
609 | return LeftIsDown(); | |
610 | case 2: | |
611 | return MiddleIsDown(); | |
612 | case 3: | |
613 | return RightIsDown(); | |
614 | default: | |
223d09f6 | 615 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown")); |
0b746ba8 VZ |
616 | } |
617 | ||
618 | return FALSE; | |
c801d85f KB |
619 | } |
620 | ||
1e6feb95 VZ |
621 | int wxMouseEvent::GetButton() const |
622 | { | |
623 | for ( int i = 1; i <= 3; i++ ) | |
624 | { | |
625 | if ( Button(i) ) | |
626 | { | |
627 | return i; | |
628 | } | |
629 | } | |
630 | ||
631 | return -1; | |
632 | } | |
633 | ||
c801d85f KB |
634 | // Find the logical position of the event given the DC |
635 | wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const | |
636 | { | |
0757d27c JS |
637 | wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y)); |
638 | return pt; | |
c801d85f KB |
639 | } |
640 | ||
641 | ||
642 | /* | |
8e72b8b5 | 643 | * Keyboard event |
c801d85f KB |
644 | * |
645 | */ | |
646 | ||
7798a18e | 647 | wxKeyEvent::wxKeyEvent(wxEventType type) |
c801d85f | 648 | { |
0b746ba8 VZ |
649 | m_eventType = type; |
650 | m_shiftDown = FALSE; | |
651 | m_controlDown = FALSE; | |
652 | m_metaDown = FALSE; | |
653 | m_altDown = FALSE; | |
654 | m_keyCode = 0; | |
b0e813a0 | 655 | m_scanCode = 0; |
2b5f62a0 VZ |
656 | #if wxUSE_UNICODE |
657 | m_uniChar = 0; | |
658 | #endif | |
c801d85f KB |
659 | } |
660 | ||
92309201 | 661 | wxKeyEvent::wxKeyEvent(const wxKeyEvent& evt) |
2b5f62a0 VZ |
662 | : wxEvent(evt) |
663 | { | |
664 | m_x = evt.m_x; | |
665 | m_y = evt.m_y; | |
666 | ||
667 | m_keyCode = evt.m_keyCode; | |
668 | ||
669 | m_controlDown = evt.m_controlDown; | |
670 | m_shiftDown = evt.m_shiftDown; | |
671 | m_altDown = evt.m_altDown; | |
672 | m_metaDown = evt.m_metaDown; | |
673 | m_scanCode = evt.m_scanCode; | |
674 | m_rawCode = evt.m_rawCode; | |
675 | m_rawFlags = evt.m_rawFlags; | |
92309201 | 676 | |
2b5f62a0 VZ |
677 | #if wxUSE_UNICODE |
678 | m_uniChar = evt.m_uniChar; | |
679 | #endif | |
680 | } | |
12a3f227 RL |
681 | |
682 | long wxKeyEvent::KeyCode() const | |
683 | { | |
684 | return m_keyCode; | |
685 | } | |
686 | ||
42e69d6b | 687 | wxWindowCreateEvent::wxWindowCreateEvent(wxWindow *win) |
42e69d6b | 688 | { |
cfe17b74 | 689 | SetEventType(wxEVT_CREATE); |
42e69d6b VZ |
690 | SetEventObject(win); |
691 | } | |
692 | ||
693 | wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow *win) | |
42e69d6b | 694 | { |
cfe17b74 | 695 | SetEventType(wxEVT_DESTROY); |
42e69d6b VZ |
696 | SetEventObject(win); |
697 | } | |
698 | ||
456bc6d9 VZ |
699 | wxChildFocusEvent::wxChildFocusEvent(wxWindow *win) |
700 | : wxCommandEvent(wxEVT_CHILD_FOCUS) | |
701 | { | |
702 | SetEventObject(win); | |
703 | } | |
704 | ||
dd070522 VZ |
705 | #endif // wxUSE_GUI |
706 | ||
456bc6d9 VZ |
707 | // ---------------------------------------------------------------------------- |
708 | // wxEvtHandler | |
709 | // ---------------------------------------------------------------------------- | |
710 | ||
3ed2104c VZ |
711 | #if wxUSE_BASE |
712 | ||
c801d85f KB |
713 | /* |
714 | * Event handler | |
715 | */ | |
716 | ||
0b746ba8 | 717 | wxEvtHandler::wxEvtHandler() |
c801d85f | 718 | { |
0b746ba8 VZ |
719 | m_nextHandler = (wxEvtHandler *) NULL; |
720 | m_previousHandler = (wxEvtHandler *) NULL; | |
721 | m_enabled = TRUE; | |
722 | m_dynamicEvents = (wxList *) NULL; | |
8e193f38 | 723 | m_pendingEvents = (wxList *) NULL; |
7214297d | 724 | #if wxUSE_THREADS |
41404da7 | 725 | # if !defined(__VISAGECPP__) |
8e193f38 | 726 | m_eventsLocker = new wxCriticalSection; |
41404da7 | 727 | # endif |
7214297d | 728 | #endif |
b88c44e7 RD |
729 | // no client data (yet) |
730 | m_clientData = NULL; | |
731 | m_clientDataType = wxClientData_None; | |
c801d85f KB |
732 | } |
733 | ||
0b746ba8 | 734 | wxEvtHandler::~wxEvtHandler() |
c801d85f | 735 | { |
0b746ba8 VZ |
736 | // Takes itself out of the list of handlers |
737 | if (m_previousHandler) | |
738 | m_previousHandler->m_nextHandler = m_nextHandler; | |
739 | ||
740 | if (m_nextHandler) | |
741 | m_nextHandler->m_previousHandler = m_previousHandler; | |
742 | ||
743 | if (m_dynamicEvents) | |
fe71f65c | 744 | { |
df5168c4 MB |
745 | wxList::iterator it = m_dynamicEvents->begin(), |
746 | en = m_dynamicEvents->end(); | |
747 | for (;it != en; ++it) | |
0b746ba8 | 748 | { |
2e4df4bf | 749 | #if WXWIN_COMPATIBILITY_EVENT_TYPES |
df5168c4 | 750 | wxEventTableEntry *entry = (wxEventTableEntry*)*it; |
2e4df4bf | 751 | #else // !WXWIN_COMPATIBILITY_EVENT_TYPES |
df5168c4 | 752 | wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)*it; |
2e4df4bf VZ |
753 | #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES |
754 | ||
755 | if (entry->m_callbackUserData) | |
756 | delete entry->m_callbackUserData; | |
0b746ba8 | 757 | delete entry; |
0b746ba8 VZ |
758 | } |
759 | delete m_dynamicEvents; | |
760 | }; | |
7214297d | 761 | |
8e193f38 | 762 | delete m_pendingEvents; |
7214297d | 763 | |
8e193f38 | 764 | #if wxUSE_THREADS |
41404da7 | 765 | # if !defined(__VISAGECPP__) |
7214297d | 766 | delete m_eventsLocker; |
41404da7 | 767 | # endif |
083f7497 JS |
768 | |
769 | // Remove us from wxPendingEvents if necessary. | |
770 | if(wxPendingEventsLocker) | |
771 | wxENTER_CRIT_SECT(*wxPendingEventsLocker); | |
772 | if ( wxPendingEvents ) { | |
773 | wxPendingEvents->DeleteObject(this); | |
774 | } | |
775 | if(wxPendingEventsLocker) | |
776 | wxLEAVE_CRIT_SECT(*wxPendingEventsLocker); | |
7214297d | 777 | #endif |
b88c44e7 RD |
778 | |
779 | // we only delete object data, not untyped | |
780 | if ( m_clientDataType == wxClientData_Object ) | |
781 | delete m_clientObject; | |
c801d85f KB |
782 | } |
783 | ||
7214297d | 784 | #if wxUSE_THREADS |
aadbdf11 | 785 | |
7214297d GL |
786 | bool wxEvtHandler::ProcessThreadEvent(wxEvent& event) |
787 | { | |
7214297d | 788 | // check that we are really in a child thread |
8e193f38 VZ |
789 | wxASSERT_MSG( !wxThread::IsMain(), |
790 | wxT("use ProcessEvent() in main thread") ); | |
791 | ||
792 | AddPendingEvent(event); | |
7214297d | 793 | |
8e193f38 VZ |
794 | return TRUE; |
795 | } | |
796 | ||
797 | #endif // wxUSE_THREADS | |
798 | ||
799 | void wxEvtHandler::AddPendingEvent(wxEvent& event) | |
800 | { | |
16c1f79c RR |
801 | // 1) Add event to list of pending events of this event handler |
802 | ||
7a5c8ac4 VZ |
803 | wxEvent *eventCopy = event.Clone(); |
804 | ||
805 | // we must be able to copy the events here so the event class must | |
806 | // implement Clone() properly instead of just providing a NULL stab for it | |
807 | wxCHECK_RET( eventCopy, | |
808 | _T("events of this type aren't supposed to be posted") ); | |
809 | ||
16c1f79c RR |
810 | #if defined(__VISAGECPP__) |
811 | wxENTER_CRIT_SECT( m_eventsLocker); | |
812 | #else | |
813 | wxENTER_CRIT_SECT( *m_eventsLocker); | |
814 | #endif | |
815 | ||
8e193f38 VZ |
816 | if ( !m_pendingEvents ) |
817 | m_pendingEvents = new wxList; | |
7214297d | 818 | |
7a5c8ac4 | 819 | m_pendingEvents->Append(eventCopy); |
7214297d | 820 | |
16c1f79c RR |
821 | #if defined(__VISAGECPP__) |
822 | wxLEAVE_CRIT_SECT( m_eventsLocker); | |
823 | #else | |
824 | wxLEAVE_CRIT_SECT( *m_eventsLocker); | |
825 | #endif | |
826 | ||
827 | // 2) Add this event handler to list of event handlers that | |
828 | // have pending events. | |
cfe17b74 | 829 | |
b568d04f | 830 | wxENTER_CRIT_SECT(*wxPendingEventsLocker); |
72cdf4c9 | 831 | |
8e193f38 VZ |
832 | if ( !wxPendingEvents ) |
833 | wxPendingEvents = new wxList; | |
4d3a259a | 834 | wxPendingEvents->Append(this); |
72cdf4c9 | 835 | |
ce6d2511 | 836 | wxLEAVE_CRIT_SECT(*wxPendingEventsLocker); |
6164f93c | 837 | |
16c1f79c RR |
838 | // 3) Inform the system that new pending events are somwehere, |
839 | // and that these should be processed in idle time. | |
bf9e3e73 | 840 | wxWakeUpIdle(); |
7214297d GL |
841 | } |
842 | ||
843 | void wxEvtHandler::ProcessPendingEvents() | |
844 | { | |
41404da7 | 845 | #if defined(__VISAGECPP__) |
16c1f79c | 846 | wxENTER_CRIT_SECT( m_eventsLocker); |
b568d04f | 847 | #else |
16c1f79c | 848 | wxENTER_CRIT_SECT( *m_eventsLocker); |
41404da7 | 849 | #endif |
8e193f38 | 850 | |
df5168c4 | 851 | wxList::compatibility_iterator node = m_pendingEvents->GetFirst(); |
8e193f38 VZ |
852 | while ( node ) |
853 | { | |
b1d4dd7a | 854 | wxEvent *event = (wxEvent *)node->GetData(); |
df5168c4 | 855 | m_pendingEvents->Erase(node); |
cfe17b74 | 856 | |
16c1f79c | 857 | // In ProcessEvent, new events might get added and |
6164f93c | 858 | // we can safely leave the crtical section here. |
16c1f79c RR |
859 | #if defined(__VISAGECPP__) |
860 | wxLEAVE_CRIT_SECT( m_eventsLocker); | |
861 | #else | |
862 | wxLEAVE_CRIT_SECT( *m_eventsLocker); | |
863 | #endif | |
8e193f38 | 864 | ProcessEvent(*event); |
9779893b | 865 | delete event; |
16c1f79c RR |
866 | #if defined(__VISAGECPP__) |
867 | wxENTER_CRIT_SECT( m_eventsLocker); | |
868 | #else | |
869 | wxENTER_CRIT_SECT( *m_eventsLocker); | |
870 | #endif | |
cfe17b74 | 871 | |
b1d4dd7a | 872 | node = m_pendingEvents->GetFirst(); |
7214297d | 873 | } |
cfe17b74 | 874 | |
16c1f79c RR |
875 | #if defined(__VISAGECPP__) |
876 | wxLEAVE_CRIT_SECT( m_eventsLocker); | |
877 | #else | |
878 | wxLEAVE_CRIT_SECT( *m_eventsLocker); | |
879 | #endif | |
7214297d | 880 | } |
7214297d | 881 | |
c801d85f KB |
882 | /* |
883 | * Event table stuff | |
884 | */ | |
885 | ||
4caf847c | 886 | bool wxEvtHandler::TryParent(wxEvent& event) |
c801d85f | 887 | { |
4caf847c | 888 | if ( wxTheApp && (this != wxTheApp) ) |
9154d8cf | 889 | { |
4caf847c VZ |
890 | // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always |
891 | // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be | |
892 | // processed appropriately via SearchEventTable. | |
893 | if ( event.GetEventType() != wxEVT_IDLE ) | |
894 | { | |
895 | if ( wxTheApp->ProcessEvent(event) ) | |
896 | return TRUE; | |
897 | } | |
9154d8cf VZ |
898 | } |
899 | ||
4caf847c VZ |
900 | return FALSE; |
901 | } | |
0b746ba8 | 902 | |
4caf847c VZ |
903 | bool wxEvtHandler::ProcessEvent(wxEvent& event) |
904 | { | |
9154d8cf VZ |
905 | // allow the application to hook into event processing |
906 | if ( wxTheApp ) | |
907 | { | |
908 | int rc = wxTheApp->FilterEvent(event); | |
909 | if ( rc != -1 ) | |
910 | { | |
911 | wxASSERT_MSG( rc == 1 || rc == 0, | |
912 | _T("unexpected wxApp::FilterEvent return value") ); | |
913 | ||
914 | return rc != 0; | |
915 | } | |
916 | //else: proceed normally | |
917 | } | |
918 | ||
8e193f38 | 919 | // An event handler can be enabled or disabled |
0b746ba8 | 920 | if ( GetEvtHandlerEnabled() ) |
c801d85f | 921 | { |
22c2307c VZ |
922 | // if we have a validator, it has higher priority than our own event |
923 | // table | |
4caf847c VZ |
924 | #if wxUSE_VALIDATORS |
925 | if ( TryValidator(event) ) | |
926 | return TRUE; | |
927 | #endif // wxUSE_VALIDATORS | |
928 | ||
22c2307c VZ |
929 | // Handle per-instance dynamic event tables first |
930 | if ( m_dynamicEvents && SearchDynamicEventTable(event) ) | |
931 | return TRUE; | |
0b746ba8 | 932 | |
22c2307c VZ |
933 | // Then static per-class event tables (and search upwards through the |
934 | // inheritance hierarchy) | |
935 | for ( const wxEventTable *table = GetEventTable(); | |
936 | table; | |
937 | table = table->baseTable ) | |
0b746ba8 | 938 | { |
193bf013 | 939 | if ( SearchEventTable((wxEventTable&)*table, event) ) |
0b746ba8 | 940 | return TRUE; |
0b746ba8 | 941 | } |
c801d85f KB |
942 | } |
943 | ||
0b746ba8 VZ |
944 | // Try going down the event handler chain |
945 | if ( GetNextHandler() ) | |
c801d85f | 946 | { |
0b746ba8 VZ |
947 | if ( GetNextHandler()->ProcessEvent(event) ) |
948 | return TRUE; | |
c801d85f | 949 | } |
c801d85f | 950 | |
22c2307c VZ |
951 | // Finally propagate the event upwards the window chain and/or to the |
952 | // application object as necessary | |
4caf847c | 953 | return TryParent(event); |
c801d85f KB |
954 | } |
955 | ||
956 | bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event) | |
957 | { | |
68662769 VZ |
958 | wxEventType eventType = event.GetEventType(); |
959 | int eventId = event.GetId(); | |
0b746ba8 | 960 | |
68662769 VZ |
961 | // BC++ doesn't like testing for m_fn without != 0 |
962 | for ( int i = 0; table.entries[i].m_fn != 0; i++ ) | |
c801d85f | 963 | { |
6e58645e VZ |
964 | // the line using reference exposes a bug in gcc: although it _seems_ |
965 | // to work, it leads to weird crashes later on during program | |
966 | // execution | |
967 | #ifdef __GNUG__ | |
968 | wxEventTableEntry entry = table.entries[i]; | |
969 | #else | |
68662769 | 970 | const wxEventTableEntry& entry = table.entries[i]; |
6e58645e | 971 | #endif |
68662769 VZ |
972 | |
973 | // match only if the event type is the same and the id is either -1 in | |
974 | // the event table (meaning "any") or the event id matches the id | |
975 | // specified in the event table either exactly or by falling into | |
976 | // range between first and last | |
977 | if ( eventType == entry.m_eventType ) | |
0b746ba8 | 978 | { |
68662769 VZ |
979 | int tableId1 = entry.m_id, |
980 | tableId2 = entry.m_lastId; | |
981 | ||
982 | if ( (tableId1 == -1) || | |
983 | (tableId2 == -1 && eventId == tableId1) || | |
984 | (tableId2 != -1 && | |
985 | (eventId >= tableId1 && eventId <= tableId2)) ) | |
986 | { | |
987 | event.Skip(FALSE); | |
988 | event.m_callbackUserData = entry.m_callbackUserData; | |
0b746ba8 | 989 | |
68662769 | 990 | (this->*((wxEventFunction) (entry.m_fn)))(event); |
0b746ba8 | 991 | |
68662769 VZ |
992 | return !event.GetSkipped(); |
993 | } | |
0b746ba8 | 994 | } |
c801d85f | 995 | } |
68662769 | 996 | |
0b746ba8 | 997 | return FALSE; |
c801d85f | 998 | } |
97d7bfb8 | 999 | |
debe6624 | 1000 | void wxEvtHandler::Connect( int id, int lastId, |
77d4384e | 1001 | int eventType, |
0b746ba8 | 1002 | wxObjectEventFunction func, |
65b17727 JS |
1003 | wxObject *userData, |
1004 | wxEvtHandler* eventSink ) | |
fe71f65c | 1005 | { |
cbee8f8d | 1006 | #if WXWIN_COMPATIBILITY_EVENT_TYPES |
2e4df4bf | 1007 | wxEventTableEntry *entry = new wxEventTableEntry; |
cbee8f8d VZ |
1008 | entry->m_eventType = eventType; |
1009 | entry->m_id = id; | |
1010 | entry->m_lastId = lastId; | |
1011 | entry->m_fn = func; | |
1012 | entry->m_callbackUserData = userData; | |
1013 | #else // !WXWIN_COMPATIBILITY_EVENT_TYPES | |
0b5eceb6 | 1014 | wxDynamicEventTableEntry *entry = |
65b17727 | 1015 | new wxDynamicEventTableEntry(eventType, id, lastId, func, userData, eventSink); |
cbee8f8d | 1016 | #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES |
0b746ba8 VZ |
1017 | |
1018 | if (!m_dynamicEvents) | |
1019 | m_dynamicEvents = new wxList; | |
1020 | ||
92309201 RD |
1021 | // Insert at the front of the list so most recent additions are found first |
1022 | m_dynamicEvents->Insert( (wxObject*) entry ); | |
fe71f65c | 1023 | } |
97d7bfb8 RR |
1024 | |
1025 | bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType, | |
1026 | wxObjectEventFunction func, | |
65b17727 JS |
1027 | wxObject *userData, |
1028 | wxEvtHandler* eventSink ) | |
97d7bfb8 RR |
1029 | { |
1030 | if (!m_dynamicEvents) | |
1031 | return FALSE; | |
cfe17b74 | 1032 | |
df5168c4 | 1033 | wxList::compatibility_iterator node = m_dynamicEvents->GetFirst(); |
97d7bfb8 RR |
1034 | while (node) |
1035 | { | |
2e4df4bf | 1036 | #if WXWIN_COMPATIBILITY_EVENT_TYPES |
b1d4dd7a | 1037 | wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData(); |
2e4df4bf | 1038 | #else // !WXWIN_COMPATIBILITY_EVENT_TYPES |
b1d4dd7a | 1039 | wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData(); |
2e4df4bf VZ |
1040 | #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES |
1041 | ||
97d7bfb8 RR |
1042 | if ((entry->m_id == id) && |
1043 | ((entry->m_lastId == lastId) || (lastId == -1)) && | |
1044 | ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) && | |
1045 | ((entry->m_fn == func) || (func == (wxObjectEventFunction)NULL)) && | |
65b17727 | 1046 | ((entry->m_eventSink == eventSink) || (eventSink == (wxEvtHandler*)NULL)) && |
97d7bfb8 RR |
1047 | ((entry->m_callbackUserData == userData) || (userData == (wxObject*)NULL))) |
1048 | { | |
2e4df4bf VZ |
1049 | if (entry->m_callbackUserData) |
1050 | delete entry->m_callbackUserData; | |
df5168c4 | 1051 | m_dynamicEvents->Erase( node ); |
97d7bfb8 RR |
1052 | delete entry; |
1053 | return TRUE; | |
1054 | } | |
b1d4dd7a | 1055 | node = node->GetNext(); |
97d7bfb8 RR |
1056 | } |
1057 | return FALSE; | |
1058 | } | |
fe71f65c RR |
1059 | |
1060 | bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event ) | |
1061 | { | |
193bf013 | 1062 | wxCHECK_MSG( m_dynamicEvents, FALSE, |
223d09f6 | 1063 | wxT("caller should check that we have dynamic events") ); |
0b746ba8 VZ |
1064 | |
1065 | int commandId = event.GetId(); | |
1066 | ||
df5168c4 | 1067 | wxList::compatibility_iterator node = m_dynamicEvents->GetFirst(); |
0b746ba8 | 1068 | while (node) |
fe71f65c | 1069 | { |
2e4df4bf | 1070 | #if WXWIN_COMPATIBILITY_EVENT_TYPES |
b1d4dd7a | 1071 | wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData(); |
2e4df4bf | 1072 | #else // !WXWIN_COMPATIBILITY_EVENT_TYPES |
b1d4dd7a | 1073 | wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData(); |
2e4df4bf | 1074 | #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES |
0b746ba8 VZ |
1075 | |
1076 | if (entry->m_fn) | |
1077 | { | |
1078 | // Match, if event spec says any id will do (id == -1) | |
1079 | if ( (event.GetEventType() == entry->m_eventType) && | |
1080 | (entry->m_id == -1 || | |
1081 | (entry->m_lastId == -1 && commandId == entry->m_id) || | |
1082 | (entry->m_lastId != -1 && | |
1083 | (commandId >= entry->m_id && commandId <= entry->m_lastId))) ) | |
1084 | { | |
1085 | event.Skip(FALSE); | |
1086 | event.m_callbackUserData = entry->m_callbackUserData; | |
1087 | ||
65b17727 JS |
1088 | #if !WXWIN_COMPATIBILITY_EVENT_TYPES |
1089 | if (entry->m_eventSink) | |
1090 | ((entry->m_eventSink)->*((wxEventFunction) (entry->m_fn)))(event); | |
1091 | else | |
1092 | #endif | |
1093 | (this->*((wxEventFunction) (entry->m_fn)))(event); | |
0b746ba8 | 1094 | |
92309201 | 1095 | if ( ! event.GetSkipped() ) |
0b746ba8 VZ |
1096 | return TRUE; |
1097 | } | |
1098 | } | |
b1d4dd7a | 1099 | node = node->GetNext(); |
7b678698 | 1100 | } |
0b746ba8 | 1101 | return FALSE; |
fe71f65c RR |
1102 | }; |
1103 | ||
b88c44e7 RD |
1104 | void wxEvtHandler::DoSetClientObject( wxClientData *data ) |
1105 | { | |
1106 | wxASSERT_MSG( m_clientDataType != wxClientData_Void, | |
1107 | wxT("can't have both object and void client data") ); | |
1108 | ||
1109 | if ( m_clientObject ) | |
1110 | delete m_clientObject; | |
1111 | ||
1112 | m_clientObject = data; | |
1113 | m_clientDataType = wxClientData_Object; | |
1114 | } | |
1115 | ||
1116 | wxClientData *wxEvtHandler::DoGetClientObject() const | |
1117 | { | |
1118 | // it's not an error to call GetClientObject() on a window which doesn't | |
1119 | // have client data at all - NULL will be returned | |
1120 | wxASSERT_MSG( m_clientDataType != wxClientData_Void, | |
1121 | wxT("this window doesn't have object client data") ); | |
1122 | ||
1123 | return m_clientObject; | |
1124 | } | |
1125 | ||
1126 | void wxEvtHandler::DoSetClientData( void *data ) | |
1127 | { | |
1128 | wxASSERT_MSG( m_clientDataType != wxClientData_Object, | |
1129 | wxT("can't have both object and void client data") ); | |
1130 | ||
1131 | m_clientData = data; | |
1132 | m_clientDataType = wxClientData_Void; | |
1133 | } | |
1134 | ||
1135 | void *wxEvtHandler::DoGetClientData() const | |
1136 | { | |
1137 | // it's not an error to call GetClientData() on a window which doesn't have | |
1138 | // client data at all - NULL will be returned | |
1139 | wxASSERT_MSG( m_clientDataType != wxClientData_Object, | |
1140 | wxT("this window doesn't have void client data") ); | |
1141 | ||
1142 | return m_clientData; | |
1143 | } | |
1144 | ||
1145 | ||
e3065973 | 1146 | #if WXWIN_COMPATIBILITY |
0b746ba8 | 1147 | bool wxEvtHandler::OnClose() |
c801d85f | 1148 | { |
0b746ba8 VZ |
1149 | if (GetNextHandler()) |
1150 | return GetNextHandler()->OnClose(); | |
1151 | else | |
1152 | return FALSE; | |
c801d85f | 1153 | } |
193bf013 | 1154 | #endif // WXWIN_COMPATIBILITY |
e3065973 | 1155 | |
4caf847c VZ |
1156 | #endif // wxUSE_BASE |
1157 | ||
e90c1d2a VZ |
1158 | #if wxUSE_GUI |
1159 | ||
e702ff0f JS |
1160 | // Find a window with the focus, that is also a descendant of the given window. |
1161 | // This is used to determine the window to initially send commands to. | |
1162 | wxWindow* wxFindFocusDescendant(wxWindow* ancestor) | |
1163 | { | |
1164 | // Process events starting with the window with the focus, if any. | |
1165 | wxWindow* focusWin = wxWindow::FindFocus(); | |
1166 | wxWindow* win = focusWin; | |
1167 | ||
1168 | // Check if this is a descendant of this frame. | |
1169 | // If not, win will be set to NULL. | |
1170 | while (win) | |
1171 | { | |
1172 | if (win == ancestor) | |
1173 | break; | |
1174 | else | |
1175 | win = win->GetParent(); | |
1176 | } | |
1177 | if (win == (wxWindow*) NULL) | |
1178 | focusWin = (wxWindow*) NULL; | |
1179 | ||
1180 | return focusWin; | |
1181 | } | |
1182 | ||
e90c1d2a | 1183 | #endif // wxUSE_GUI |