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