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