]>
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$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
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 | ||
c801d85f | 53 | #if !USE_SHARED_LIBRARY |
0b746ba8 VZ |
54 | IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject) |
55 | IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject) | |
0b746ba8 | 56 | IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent) |
e90c1d2a VZ |
57 | |
58 | #if wxUSE_GUI | |
59 | IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent) | |
60 | IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent) | |
61 | IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent) | |
62 | IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent, wxEvent) | |
63 | IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent) | |
64 | IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent) | |
65 | IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent) | |
66 | IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent) | |
67 | IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent) | |
68 | IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent) | |
69 | IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent) | |
70 | IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent) | |
71 | IMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent) | |
72 | IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent) | |
73 | IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent) | |
74 | IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent) | |
75 | IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent) | |
76 | IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent) | |
77 | IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent) | |
78 | IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent) | |
79 | IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent) | |
80 | IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent) | |
81 | IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxCommandEvent) | |
82 | IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, wxEvent) | |
83 | IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent, wxEvent) | |
84 | IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent, wxEvent) | |
85 | IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent, wxEvent) | |
86 | #endif // wxUSE_GUI | |
0b746ba8 VZ |
87 | |
88 | const wxEventTable *wxEvtHandler::GetEventTable() const | |
89 | { return &wxEvtHandler::sm_eventTable; } | |
90 | ||
91 | const wxEventTable wxEvtHandler::sm_eventTable = | |
92 | { (const wxEventTable *)NULL, &wxEvtHandler::sm_eventTableEntries[0] }; | |
93 | ||
94 | const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] = | |
58d1c1ae | 95 | { { 0, 0, 0, (wxObjectEventFunction) NULL, (wxObject*) NULL } }; |
0b746ba8 VZ |
96 | |
97 | #endif // !USE_SHARED_LIBRARY | |
c801d85f | 98 | |
8e193f38 VZ |
99 | // ---------------------------------------------------------------------------- |
100 | // global variables | |
101 | // ---------------------------------------------------------------------------- | |
102 | ||
103 | // To put pending event handlers | |
104 | wxList *wxPendingEvents = (wxList *)NULL; | |
105 | ||
7214297d | 106 | #if wxUSE_THREADS |
8e193f38 VZ |
107 | // protects wxPendingEvents list |
108 | wxCriticalSection *wxPendingEventsLocker = (wxCriticalSection *)NULL; | |
7214297d GL |
109 | #endif |
110 | ||
8e193f38 VZ |
111 | // ============================================================================ |
112 | // implementation | |
113 | // ============================================================================ | |
114 | ||
115 | // ---------------------------------------------------------------------------- | |
116 | // wxEvent | |
117 | // ---------------------------------------------------------------------------- | |
118 | ||
c801d85f KB |
119 | /* |
120 | * General wxWindows events, covering | |
121 | * all interesting things that might happen (button clicking, resizing, | |
122 | * setting text in widgets, etc.). | |
123 | * | |
124 | * For each completely new event type, derive a new event class. | |
125 | * | |
126 | */ | |
127 | ||
128 | wxEvent::wxEvent(int theId) | |
129 | { | |
0b746ba8 VZ |
130 | m_eventType = wxEVT_NULL; |
131 | m_eventObject = (wxObject *) NULL; | |
0b746ba8 VZ |
132 | m_timeStamp = 0; |
133 | m_id = theId; | |
134 | m_skipped = FALSE; | |
135 | m_callbackUserData = (wxObject *) NULL; | |
193bf013 | 136 | m_isCommandEvent = FALSE; |
c801d85f KB |
137 | } |
138 | ||
aadbdf11 | 139 | void wxEvent::CopyObject(wxObject& object_dest) const |
a737331d | 140 | { |
e90c1d2a | 141 | wxEvent *obj = (wxEvent *)&object_dest; |
aadbdf11 GL |
142 | wxObject::CopyObject(object_dest); |
143 | ||
144 | obj->m_eventType = m_eventType; | |
145 | obj->m_eventObject = m_eventObject; | |
aadbdf11 GL |
146 | obj->m_timeStamp = m_timeStamp; |
147 | obj->m_id = m_id; | |
148 | obj->m_skipped = m_skipped; | |
149 | obj->m_callbackUserData = m_callbackUserData; | |
150 | obj->m_isCommandEvent = m_isCommandEvent; | |
a737331d GL |
151 | } |
152 | ||
e90c1d2a VZ |
153 | #if wxUSE_GUI |
154 | ||
c801d85f KB |
155 | /* |
156 | * Command events | |
157 | * | |
158 | */ | |
159 | ||
7798a18e | 160 | wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId) |
c801d85f | 161 | { |
0b746ba8 VZ |
162 | m_eventType = commandType; |
163 | m_clientData = (char *) NULL; | |
164 | m_clientObject = (wxClientData *) NULL; | |
165 | m_extraLong = 0; | |
166 | m_commandInt = 0; | |
167 | m_id = theId; | |
04392d70 | 168 | m_commandString = wxEmptyString; |
193bf013 | 169 | m_isCommandEvent = TRUE; |
c801d85f KB |
170 | } |
171 | ||
aadbdf11 GL |
172 | void wxCommandEvent::CopyObject(wxObject& obj_d) const |
173 | { | |
e90c1d2a | 174 | wxCommandEvent *obj = (wxCommandEvent *)&obj_d; |
aadbdf11 GL |
175 | |
176 | wxEvent::CopyObject(obj_d); | |
177 | ||
178 | obj->m_clientData = m_clientData; | |
179 | obj->m_clientObject = m_clientObject; | |
180 | obj->m_extraLong = m_extraLong; | |
181 | obj->m_commandInt = m_commandInt; | |
182 | } | |
183 | ||
c801d85f KB |
184 | /* |
185 | * Scroll events | |
186 | */ | |
187 | ||
0b746ba8 VZ |
188 | wxScrollEvent::wxScrollEvent(wxEventType commandType, |
189 | int id, | |
190 | int pos, | |
191 | int orient) | |
192 | : wxCommandEvent(commandType, id) | |
c801d85f | 193 | { |
0b746ba8 VZ |
194 | m_extraLong = orient; |
195 | m_commandInt = pos; | |
c801d85f KB |
196 | } |
197 | ||
d1367c3d RR |
198 | /* |
199 | * ScrollWin events | |
200 | */ | |
201 | ||
202 | wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType, | |
203 | int pos, | |
204 | int orient) | |
d1367c3d | 205 | { |
c5b42c87 | 206 | m_eventType = commandType; |
d1367c3d RR |
207 | m_extraLong = orient; |
208 | m_commandInt = pos; | |
209 | } | |
210 | ||
3c679789 RR |
211 | void wxScrollWinEvent::CopyObject(wxObject& obj_d) const |
212 | { | |
e90c1d2a | 213 | wxScrollWinEvent *obj = (wxScrollWinEvent*)&obj_d; |
3c679789 RR |
214 | |
215 | wxEvent::CopyObject(obj_d); | |
216 | ||
217 | obj->m_extraLong = m_extraLong; | |
218 | obj->m_commandInt = m_commandInt; | |
219 | } | |
220 | ||
c801d85f KB |
221 | /* |
222 | * Mouse events | |
223 | * | |
224 | */ | |
225 | ||
7798a18e | 226 | wxMouseEvent::wxMouseEvent(wxEventType commandType) |
c801d85f | 227 | { |
0b746ba8 VZ |
228 | m_eventType = commandType; |
229 | m_metaDown = FALSE; | |
230 | m_altDown = FALSE; | |
231 | m_controlDown = FALSE; | |
232 | m_shiftDown = FALSE; | |
233 | m_leftDown = FALSE; | |
234 | m_rightDown = FALSE; | |
235 | m_middleDown = FALSE; | |
236 | m_x = 0; | |
237 | m_y = 0; | |
c801d85f KB |
238 | } |
239 | ||
aadbdf11 GL |
240 | void wxMouseEvent::CopyObject(wxObject& obj_d) const |
241 | { | |
242 | wxMouseEvent *obj = (wxMouseEvent *)&obj_d; | |
243 | ||
244 | wxEvent::CopyObject(obj_d); | |
245 | ||
246 | obj->m_metaDown = m_metaDown; | |
247 | obj->m_altDown = m_altDown; | |
248 | obj->m_controlDown = m_controlDown; | |
249 | obj->m_shiftDown = m_shiftDown; | |
250 | obj->m_leftDown = m_leftDown; | |
251 | obj->m_rightDown = m_rightDown; | |
252 | obj->m_middleDown = m_middleDown; | |
253 | obj->m_x = m_x; | |
254 | obj->m_y = m_y; | |
255 | } | |
256 | ||
c801d85f KB |
257 | // True if was a button dclick event (1 = left, 2 = middle, 3 = right) |
258 | // or any button dclick event (but = -1) | |
259 | bool wxMouseEvent::ButtonDClick(int but) const | |
260 | { | |
0b746ba8 VZ |
261 | switch (but) |
262 | { | |
263 | case -1: | |
264 | return (LeftDClick() || MiddleDClick() || RightDClick()); | |
265 | case 1: | |
266 | return LeftDClick(); | |
267 | case 2: | |
268 | return MiddleDClick(); | |
269 | case 3: | |
270 | return RightDClick(); | |
271 | default: | |
223d09f6 | 272 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick")); |
0b746ba8 VZ |
273 | } |
274 | ||
275 | return FALSE; | |
c801d85f KB |
276 | } |
277 | ||
278 | // True if was a button down event (1 = left, 2 = middle, 3 = right) | |
279 | // or any button down event (but = -1) | |
280 | bool wxMouseEvent::ButtonDown(int but) const | |
281 | { | |
0b746ba8 VZ |
282 | switch (but) |
283 | { | |
284 | case -1: | |
285 | return (LeftDown() || MiddleDown() || RightDown()); | |
286 | case 1: | |
287 | return LeftDown(); | |
288 | case 2: | |
289 | return MiddleDown(); | |
290 | case 3: | |
291 | return RightDown(); | |
292 | default: | |
223d09f6 | 293 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown")); |
0b746ba8 VZ |
294 | } |
295 | ||
296 | return FALSE; | |
c801d85f KB |
297 | } |
298 | ||
299 | // True if was a button up event (1 = left, 2 = middle, 3 = right) | |
300 | // or any button up event (but = -1) | |
301 | bool wxMouseEvent::ButtonUp(int but) const | |
302 | { | |
0b746ba8 VZ |
303 | switch (but) { |
304 | case -1: | |
305 | return (LeftUp() || MiddleUp() || RightUp()); | |
306 | case 1: | |
307 | return LeftUp(); | |
308 | case 2: | |
309 | return MiddleUp(); | |
310 | case 3: | |
311 | return RightUp(); | |
312 | default: | |
223d09f6 | 313 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp")); |
0b746ba8 VZ |
314 | } |
315 | ||
316 | return FALSE; | |
c801d85f KB |
317 | } |
318 | ||
319 | // True if the given button is currently changing state | |
320 | bool wxMouseEvent::Button(int but) const | |
321 | { | |
0b746ba8 VZ |
322 | switch (but) { |
323 | case -1: | |
72cdf4c9 | 324 | return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1)); |
0b746ba8 VZ |
325 | case 1: |
326 | return (LeftDown() || LeftUp() || LeftDClick()); | |
327 | case 2: | |
328 | return (MiddleDown() || MiddleUp() || MiddleDClick()); | |
329 | case 3: | |
330 | return (RightDown() || RightUp() || RightDClick()); | |
331 | default: | |
223d09f6 | 332 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button")); |
0b746ba8 VZ |
333 | } |
334 | ||
335 | return FALSE; | |
c801d85f KB |
336 | } |
337 | ||
338 | bool wxMouseEvent::ButtonIsDown(int but) const | |
339 | { | |
0b746ba8 VZ |
340 | switch (but) { |
341 | case -1: | |
342 | return (LeftIsDown() || MiddleIsDown() || RightIsDown()); | |
343 | case 1: | |
344 | return LeftIsDown(); | |
345 | case 2: | |
346 | return MiddleIsDown(); | |
347 | case 3: | |
348 | return RightIsDown(); | |
349 | default: | |
223d09f6 | 350 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown")); |
0b746ba8 VZ |
351 | } |
352 | ||
353 | return FALSE; | |
c801d85f KB |
354 | } |
355 | ||
356 | // Find the logical position of the event given the DC | |
357 | wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const | |
358 | { | |
0757d27c JS |
359 | wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y)); |
360 | return pt; | |
c801d85f KB |
361 | } |
362 | ||
363 | ||
364 | /* | |
365 | * Keyboard events | |
366 | * | |
367 | */ | |
368 | ||
7798a18e | 369 | wxKeyEvent::wxKeyEvent(wxEventType type) |
c801d85f | 370 | { |
0b746ba8 VZ |
371 | m_eventType = type; |
372 | m_shiftDown = FALSE; | |
373 | m_controlDown = FALSE; | |
374 | m_metaDown = FALSE; | |
375 | m_altDown = FALSE; | |
376 | m_keyCode = 0; | |
b0e813a0 | 377 | m_scanCode = 0; |
c801d85f KB |
378 | } |
379 | ||
aadbdf11 GL |
380 | void wxKeyEvent::CopyObject(wxObject& obj_d) const |
381 | { | |
382 | wxKeyEvent *obj = (wxKeyEvent *)&obj_d; | |
383 | wxEvent::CopyObject(obj_d); | |
384 | ||
385 | obj->m_shiftDown = m_shiftDown; | |
386 | obj->m_controlDown = m_controlDown; | |
387 | obj->m_metaDown = m_metaDown; | |
388 | obj->m_altDown = m_altDown; | |
389 | obj->m_keyCode = m_keyCode; | |
390 | } | |
391 | ||
392 | ||
393 | /* | |
394 | * Misc events | |
395 | */ | |
396 | ||
397 | void wxSizeEvent::CopyObject(wxObject& obj_d) const | |
398 | { | |
399 | wxSizeEvent *obj = (wxSizeEvent *)&obj_d; | |
400 | wxEvent::CopyObject(obj_d); | |
401 | ||
402 | obj->m_size = m_size; | |
403 | } | |
404 | ||
405 | void wxMoveEvent::CopyObject(wxObject& obj_d) const | |
406 | { | |
407 | wxMoveEvent *obj = (wxMoveEvent *)&obj_d; | |
408 | wxEvent::CopyObject(obj_d); | |
409 | ||
410 | obj->m_pos = m_pos; | |
411 | } | |
412 | ||
413 | void wxEraseEvent::CopyObject(wxObject& obj_d) const | |
414 | { | |
415 | wxEraseEvent *obj = (wxEraseEvent *)&obj_d; | |
416 | wxEvent::CopyObject(obj_d); | |
417 | ||
418 | obj->m_dc = m_dc; | |
419 | } | |
420 | ||
421 | void wxActivateEvent::CopyObject(wxObject& obj_d) const | |
422 | { | |
423 | wxActivateEvent *obj = (wxActivateEvent *)&obj_d; | |
424 | wxEvent::CopyObject(obj_d); | |
425 | ||
426 | obj->m_active = m_active; | |
427 | } | |
428 | ||
429 | void wxMenuEvent::CopyObject(wxObject& obj_d) const | |
430 | { | |
431 | wxMenuEvent *obj = (wxMenuEvent *)&obj_d; | |
432 | wxEvent::CopyObject(obj_d); | |
433 | ||
434 | obj->m_menuId = m_menuId; | |
435 | } | |
436 | ||
437 | void wxCloseEvent::CopyObject(wxObject& obj_d) const | |
438 | { | |
439 | wxCloseEvent *obj = (wxCloseEvent *)&obj_d; | |
440 | wxEvent::CopyObject(obj_d); | |
441 | ||
442 | obj->m_loggingOff = m_loggingOff; | |
443 | obj->m_veto = m_veto; | |
444 | #if WXWIN_COMPATIBILITY | |
445 | obj->m_force = m_force; | |
446 | #endif | |
447 | obj->m_canVeto = m_canVeto; | |
448 | } | |
e90c1d2a | 449 | |
aadbdf11 GL |
450 | void wxShowEvent::CopyObject(wxObject& obj_d) const |
451 | { | |
452 | wxShowEvent *obj = (wxShowEvent *)&obj_d; | |
453 | wxEvent::CopyObject(obj_d); | |
454 | ||
455 | obj->m_show = m_show; | |
456 | } | |
f305c661 GL |
457 | |
458 | void wxJoystickEvent::CopyObject(wxObject& obj_d) const | |
459 | { | |
460 | wxJoystickEvent *obj = (wxJoystickEvent *)&obj_d; | |
461 | wxEvent::CopyObject(obj_d); | |
462 | ||
463 | obj->m_pos = m_pos; | |
464 | obj->m_zPosition = m_zPosition; | |
465 | obj->m_buttonChange = m_buttonChange; | |
466 | obj->m_buttonState = m_buttonState; | |
467 | obj->m_joyStick = m_joyStick; | |
e90c1d2a | 468 | } |
f305c661 GL |
469 | |
470 | void wxDropFilesEvent::CopyObject(wxObject& obj_d) const | |
471 | { | |
472 | wxDropFilesEvent *obj = (wxDropFilesEvent *)&obj_d; | |
473 | wxEvent::CopyObject(obj_d); | |
474 | ||
475 | obj->m_noFiles = m_noFiles; | |
476 | obj->m_pos = m_pos; | |
477 | // TODO: Problem with obj->m_files. It should be deallocated by the | |
e90c1d2a | 478 | // destructor of the event. |
f305c661 GL |
479 | } |
480 | ||
481 | void wxUpdateUIEvent::CopyObject(wxObject &obj_d) const | |
482 | { | |
483 | wxUpdateUIEvent *obj = (wxUpdateUIEvent *)&obj_d; | |
484 | wxEvent::CopyObject(obj_d); | |
485 | ||
486 | obj->m_checked = m_checked; | |
487 | obj->m_enabled = m_enabled; | |
488 | obj->m_text = m_text; | |
489 | obj->m_setText = m_setText; | |
490 | obj->m_setChecked = m_setChecked; | |
491 | obj->m_setEnabled = m_setEnabled; | |
492 | } | |
493 | ||
494 | void wxPaletteChangedEvent::CopyObject(wxObject &obj_d) const | |
495 | { | |
496 | wxPaletteChangedEvent *obj = (wxPaletteChangedEvent *)&obj_d; | |
497 | wxEvent::CopyObject(obj_d); | |
498 | ||
499 | obj->m_changedWindow = m_changedWindow; | |
500 | } | |
501 | ||
502 | void wxQueryNewPaletteEvent::CopyObject(wxObject& obj_d) const | |
503 | { | |
504 | wxQueryNewPaletteEvent *obj = (wxQueryNewPaletteEvent *)&obj_d; | |
505 | wxEvent::CopyObject(obj_d); | |
506 | ||
507 | obj->m_paletteRealized = m_paletteRealized; | |
508 | } | |
aadbdf11 | 509 | |
42e69d6b VZ |
510 | wxWindowCreateEvent::wxWindowCreateEvent(wxWindow *win) |
511 | : wxEvent(wxEVT_CREATE) | |
512 | { | |
513 | SetEventObject(win); | |
514 | } | |
515 | ||
516 | wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow *win) | |
517 | : wxEvent(wxEVT_DESTROY) | |
518 | { | |
519 | SetEventObject(win); | |
520 | } | |
521 | ||
e90c1d2a VZ |
522 | #endif // wxUSE_GUI |
523 | ||
524 | void wxIdleEvent::CopyObject(wxObject& obj_d) const | |
525 | { | |
526 | wxIdleEvent *obj = (wxIdleEvent *)&obj_d; | |
527 | wxEvent::CopyObject(obj_d); | |
528 | ||
529 | obj->m_requestMore = m_requestMore; | |
530 | } | |
531 | ||
c801d85f KB |
532 | /* |
533 | * Event handler | |
534 | */ | |
535 | ||
0b746ba8 | 536 | wxEvtHandler::wxEvtHandler() |
c801d85f | 537 | { |
0b746ba8 VZ |
538 | m_nextHandler = (wxEvtHandler *) NULL; |
539 | m_previousHandler = (wxEvtHandler *) NULL; | |
540 | m_enabled = TRUE; | |
541 | m_dynamicEvents = (wxList *) NULL; | |
193bf013 | 542 | m_isWindow = FALSE; |
8e193f38 | 543 | m_pendingEvents = (wxList *) NULL; |
7214297d | 544 | #if wxUSE_THREADS |
41404da7 | 545 | # if !defined(__VISAGECPP__) |
8e193f38 | 546 | m_eventsLocker = new wxCriticalSection; |
41404da7 | 547 | # endif |
7214297d | 548 | #endif |
c801d85f KB |
549 | } |
550 | ||
0b746ba8 | 551 | wxEvtHandler::~wxEvtHandler() |
c801d85f | 552 | { |
0b746ba8 VZ |
553 | // Takes itself out of the list of handlers |
554 | if (m_previousHandler) | |
555 | m_previousHandler->m_nextHandler = m_nextHandler; | |
556 | ||
557 | if (m_nextHandler) | |
558 | m_nextHandler->m_previousHandler = m_previousHandler; | |
559 | ||
560 | if (m_dynamicEvents) | |
fe71f65c | 561 | { |
0b746ba8 VZ |
562 | wxNode *node = m_dynamicEvents->First(); |
563 | while (node) | |
564 | { | |
565 | wxEventTableEntry *entry = (wxEventTableEntry*)node->Data(); | |
566 | if (entry->m_callbackUserData) delete entry->m_callbackUserData; | |
567 | delete entry; | |
568 | node = node->Next(); | |
569 | } | |
570 | delete m_dynamicEvents; | |
571 | }; | |
7214297d | 572 | |
8e193f38 | 573 | delete m_pendingEvents; |
7214297d | 574 | |
8e193f38 | 575 | #if wxUSE_THREADS |
41404da7 | 576 | # if !defined(__VISAGECPP__) |
7214297d | 577 | delete m_eventsLocker; |
41404da7 | 578 | # endif |
7214297d | 579 | #endif |
c801d85f KB |
580 | } |
581 | ||
7214297d | 582 | #if wxUSE_THREADS |
aadbdf11 | 583 | |
7214297d GL |
584 | bool wxEvtHandler::ProcessThreadEvent(wxEvent& event) |
585 | { | |
41404da7 DW |
586 | #if defined(__VISAGECPP__) |
587 | wxCriticalSectionLocker locker(m_eventsLocker); | |
588 | #else | |
7214297d | 589 | wxCriticalSectionLocker locker(*m_eventsLocker); |
41404da7 | 590 | #endif |
7214297d GL |
591 | |
592 | // check that we are really in a child thread | |
8e193f38 VZ |
593 | wxASSERT_MSG( !wxThread::IsMain(), |
594 | wxT("use ProcessEvent() in main thread") ); | |
595 | ||
596 | AddPendingEvent(event); | |
7214297d | 597 | |
8e193f38 VZ |
598 | return TRUE; |
599 | } | |
600 | ||
601 | #endif // wxUSE_THREADS | |
602 | ||
603 | void wxEvtHandler::AddPendingEvent(wxEvent& event) | |
604 | { | |
605 | if ( !m_pendingEvents ) | |
606 | m_pendingEvents = new wxList; | |
7214297d | 607 | |
8e193f38 | 608 | wxEvent *event2 = (wxEvent *)event.Clone(); |
7214297d | 609 | |
8e193f38 | 610 | m_pendingEvents->Append(event2); |
7214297d | 611 | |
b568d04f | 612 | wxENTER_CRIT_SECT(*wxPendingEventsLocker); |
72cdf4c9 | 613 | |
8e193f38 VZ |
614 | if ( !wxPendingEvents ) |
615 | wxPendingEvents = new wxList; | |
4d3a259a | 616 | wxPendingEvents->Append(this); |
72cdf4c9 | 617 | |
b568d04f | 618 | wxLEAVE_CRIT_SECT(*wxPendingEventsLocker); |
7214297d | 619 | |
bf9e3e73 | 620 | wxWakeUpIdle(); |
7214297d GL |
621 | } |
622 | ||
623 | void wxEvtHandler::ProcessPendingEvents() | |
624 | { | |
41404da7 | 625 | #if defined(__VISAGECPP__) |
72cdf4c9 | 626 | wxCRIT_SECT_LOCKER(locker, m_eventsLocker); |
b568d04f VZ |
627 | #else |
628 | wxCRIT_SECT_LOCKER(locker, *m_eventsLocker); | |
41404da7 | 629 | #endif |
8e193f38 | 630 | |
7214297d GL |
631 | wxNode *node = m_pendingEvents->First(); |
632 | wxEvent *event; | |
633 | ||
8e193f38 VZ |
634 | while ( node ) |
635 | { | |
636 | event = (wxEvent *)node->Data(); | |
637 | ProcessEvent(*event); | |
9779893b | 638 | delete event; |
8e193f38 VZ |
639 | delete node; |
640 | node = m_pendingEvents->First(); | |
7214297d GL |
641 | } |
642 | } | |
7214297d | 643 | |
c801d85f KB |
644 | /* |
645 | * Event table stuff | |
646 | */ | |
647 | ||
648 | bool wxEvtHandler::ProcessEvent(wxEvent& event) | |
649 | { | |
e90c1d2a | 650 | #if wxUSE_GUI |
8e193f38 | 651 | // check that our flag corresponds to reality |
193bf013 | 652 | wxASSERT( m_isWindow == IsKindOf(CLASSINFO(wxWindow)) ); |
e90c1d2a | 653 | #endif // wxUSE_GUI |
0b746ba8 | 654 | |
8e193f38 | 655 | // An event handler can be enabled or disabled |
0b746ba8 | 656 | if ( GetEvtHandlerEnabled() ) |
c801d85f | 657 | { |
7214297d | 658 | #if wxUSE_THREADS |
8e193f38 VZ |
659 | // Check whether we are in a child thread. |
660 | if ( !wxThread::IsMain() ) | |
7214297d | 661 | return ProcessThreadEvent(event); |
8e193f38 | 662 | #endif // wxUSE_THREADS |
0757d27c | 663 | |
8e193f38 | 664 | // Handle per-instance dynamic event tables first |
193bf013 | 665 | if ( m_dynamicEvents && SearchDynamicEventTable(event) ) |
0757d27c | 666 | return TRUE; |
0b746ba8 | 667 | |
8e193f38 | 668 | // Then static per-class event tables |
0b746ba8 VZ |
669 | const wxEventTable *table = GetEventTable(); |
670 | ||
e90c1d2a | 671 | #if wxUSE_GUI && wxUSE_VALIDATORS |
0b746ba8 VZ |
672 | // Try the associated validator first, if this is a window. |
673 | // Problem: if the event handler of the window has been replaced, | |
674 | // this wxEvtHandler may no longer be a window. | |
675 | // Therefore validators won't be processed if the handler | |
676 | // has been replaced with SetEventHandler. | |
677 | // THIS CAN BE CURED if PushEventHandler is used instead of | |
678 | // SetEventHandler, and then processing will be passed down the | |
679 | // chain of event handlers. | |
ce4169a4 | 680 | if (m_isWindow) |
0b746ba8 VZ |
681 | { |
682 | wxWindow *win = (wxWindow *)this; | |
683 | ||
684 | // Can only use the validator of the window which | |
685 | // is receiving the event | |
193bf013 | 686 | if ( win == event.GetEventObject() ) |
0b746ba8 | 687 | { |
193bf013 VZ |
688 | wxValidator *validator = win->GetValidator(); |
689 | if ( validator && validator->ProcessEvent(event) ) | |
690 | { | |
691 | return TRUE; | |
692 | } | |
0b746ba8 VZ |
693 | } |
694 | } | |
ce4169a4 | 695 | #endif |
0b746ba8 VZ |
696 | |
697 | // Search upwards through the inheritance hierarchy | |
ce4169a4 | 698 | while (table) |
0b746ba8 | 699 | { |
193bf013 | 700 | if ( SearchEventTable((wxEventTable&)*table, event) ) |
0b746ba8 VZ |
701 | return TRUE; |
702 | table = table->baseTable; | |
703 | } | |
c801d85f KB |
704 | } |
705 | ||
0b746ba8 VZ |
706 | // Try going down the event handler chain |
707 | if ( GetNextHandler() ) | |
c801d85f | 708 | { |
0b746ba8 VZ |
709 | if ( GetNextHandler()->ProcessEvent(event) ) |
710 | return TRUE; | |
c801d85f | 711 | } |
c801d85f | 712 | |
e90c1d2a | 713 | #if wxUSE_GUI |
0b746ba8 VZ |
714 | // Carry on up the parent-child hierarchy, |
715 | // but only if event is a command event: it wouldn't | |
716 | // make sense for a parent to receive a child's size event, for example | |
193bf013 | 717 | if ( m_isWindow && event.IsCommandEvent() ) |
0b746ba8 VZ |
718 | { |
719 | wxWindow *win = (wxWindow *)this; | |
720 | wxWindow *parent = win->GetParent(); | |
721 | if (parent && !parent->IsBeingDeleted()) | |
193bf013 | 722 | return parent->GetEventHandler()->ProcessEvent(event); |
0b746ba8 | 723 | } |
e90c1d2a | 724 | #endif // wxUSE_GUI |
0b746ba8 VZ |
725 | |
726 | // Last try - application object. | |
193bf013 | 727 | if ( wxTheApp && (this != wxTheApp) ) |
0b746ba8 | 728 | { |
193bf013 VZ |
729 | // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always |
730 | // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be | |
731 | // processed appropriately via SearchEventTable. | |
732 | if ( event.GetEventType() != wxEVT_IDLE ) | |
733 | { | |
734 | if ( wxTheApp->ProcessEvent(event) ) | |
735 | return TRUE; | |
736 | } | |
0b746ba8 VZ |
737 | } |
738 | ||
c801d85f KB |
739 | return FALSE; |
740 | } | |
741 | ||
742 | bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event) | |
743 | { | |
0b746ba8 VZ |
744 | int i = 0; |
745 | int commandId = event.GetId(); | |
746 | ||
747 | // BC++ doesn't like while (table.entries[i].m_fn) | |
748 | ||
2432b92d JS |
749 | #ifdef __SC__ |
750 | while (table.entries[i].m_fn != 0) | |
751 | #else | |
0b746ba8 | 752 | while (table.entries[i].m_fn != 0L) |
2432b92d | 753 | #endif |
c801d85f | 754 | { |
0b746ba8 VZ |
755 | if ((event.GetEventType() == table.entries[i].m_eventType) && |
756 | (table.entries[i].m_id == -1 || // Match, if event spec says any id will do (id == -1) | |
757 | (table.entries[i].m_lastId == -1 && commandId == table.entries[i].m_id) || | |
758 | (table.entries[i].m_lastId != -1 && | |
759 | (commandId >= table.entries[i].m_id && commandId <= table.entries[i].m_lastId)))) | |
760 | { | |
761 | event.Skip(FALSE); | |
762 | event.m_callbackUserData = table.entries[i].m_callbackUserData; | |
763 | ||
764 | (this->*((wxEventFunction) (table.entries[i].m_fn)))(event); | |
765 | ||
766 | if ( event.GetSkipped() ) | |
767 | return FALSE; | |
768 | else | |
769 | return TRUE; | |
770 | } | |
771 | i++; | |
c801d85f | 772 | } |
0b746ba8 | 773 | return FALSE; |
c801d85f | 774 | } |
97d7bfb8 | 775 | |
debe6624 | 776 | void wxEvtHandler::Connect( int id, int lastId, |
d4a23fee | 777 | wxEventType eventType, |
0b746ba8 VZ |
778 | wxObjectEventFunction func, |
779 | wxObject *userData ) | |
fe71f65c | 780 | { |
0b746ba8 VZ |
781 | wxEventTableEntry *entry = new wxEventTableEntry; |
782 | entry->m_id = id; | |
783 | entry->m_lastId = lastId; | |
784 | entry->m_eventType = eventType; | |
785 | entry->m_fn = func; | |
786 | entry->m_callbackUserData = userData; | |
787 | ||
788 | if (!m_dynamicEvents) | |
789 | m_dynamicEvents = new wxList; | |
790 | ||
791 | m_dynamicEvents->Append( (wxObject*) entry ); | |
fe71f65c | 792 | } |
97d7bfb8 RR |
793 | |
794 | bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType, | |
795 | wxObjectEventFunction func, | |
796 | wxObject *userData ) | |
797 | { | |
798 | if (!m_dynamicEvents) | |
799 | return FALSE; | |
800 | ||
801 | wxNode *node = m_dynamicEvents->First(); | |
802 | while (node) | |
803 | { | |
804 | wxEventTableEntry *entry = (wxEventTableEntry*)node->Data(); | |
805 | if ((entry->m_id == id) && | |
806 | ((entry->m_lastId == lastId) || (lastId == -1)) && | |
807 | ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) && | |
808 | ((entry->m_fn == func) || (func == (wxObjectEventFunction)NULL)) && | |
809 | ((entry->m_callbackUserData == userData) || (userData == (wxObject*)NULL))) | |
810 | { | |
811 | if (entry->m_callbackUserData) delete entry->m_callbackUserData; | |
812 | m_dynamicEvents->DeleteNode( node ); | |
813 | delete entry; | |
814 | return TRUE; | |
815 | } | |
816 | node = node->Next(); | |
817 | } | |
818 | return FALSE; | |
819 | } | |
fe71f65c RR |
820 | |
821 | bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event ) | |
822 | { | |
193bf013 | 823 | wxCHECK_MSG( m_dynamicEvents, FALSE, |
223d09f6 | 824 | wxT("caller should check that we have dynamic events") ); |
0b746ba8 VZ |
825 | |
826 | int commandId = event.GetId(); | |
827 | ||
828 | wxNode *node = m_dynamicEvents->First(); | |
829 | while (node) | |
fe71f65c | 830 | { |
0b746ba8 VZ |
831 | wxEventTableEntry *entry = (wxEventTableEntry*)node->Data(); |
832 | ||
833 | if (entry->m_fn) | |
834 | { | |
835 | // Match, if event spec says any id will do (id == -1) | |
836 | if ( (event.GetEventType() == entry->m_eventType) && | |
837 | (entry->m_id == -1 || | |
838 | (entry->m_lastId == -1 && commandId == entry->m_id) || | |
839 | (entry->m_lastId != -1 && | |
840 | (commandId >= entry->m_id && commandId <= entry->m_lastId))) ) | |
841 | { | |
842 | event.Skip(FALSE); | |
843 | event.m_callbackUserData = entry->m_callbackUserData; | |
844 | ||
845 | (this->*((wxEventFunction) (entry->m_fn)))(event); | |
846 | ||
847 | if (event.GetSkipped()) | |
848 | return FALSE; | |
849 | else | |
850 | return TRUE; | |
851 | } | |
852 | } | |
853 | node = node->Next(); | |
7b678698 | 854 | } |
0b746ba8 | 855 | return FALSE; |
fe71f65c RR |
856 | }; |
857 | ||
e3065973 | 858 | #if WXWIN_COMPATIBILITY |
0b746ba8 | 859 | bool wxEvtHandler::OnClose() |
c801d85f | 860 | { |
0b746ba8 VZ |
861 | if (GetNextHandler()) |
862 | return GetNextHandler()->OnClose(); | |
863 | else | |
864 | return FALSE; | |
c801d85f | 865 | } |
193bf013 | 866 | #endif // WXWIN_COMPATIBILITY |
e3065973 | 867 | |
e90c1d2a VZ |
868 | #if wxUSE_GUI |
869 | ||
e702ff0f JS |
870 | // Find a window with the focus, that is also a descendant of the given window. |
871 | // This is used to determine the window to initially send commands to. | |
872 | wxWindow* wxFindFocusDescendant(wxWindow* ancestor) | |
873 | { | |
874 | // Process events starting with the window with the focus, if any. | |
875 | wxWindow* focusWin = wxWindow::FindFocus(); | |
876 | wxWindow* win = focusWin; | |
877 | ||
878 | // Check if this is a descendant of this frame. | |
879 | // If not, win will be set to NULL. | |
880 | while (win) | |
881 | { | |
882 | if (win == ancestor) | |
883 | break; | |
884 | else | |
885 | win = win->GetParent(); | |
886 | } | |
887 | if (win == (wxWindow*) NULL) | |
888 | focusWin = (wxWindow*) NULL; | |
889 | ||
890 | return focusWin; | |
891 | } | |
892 | ||
e90c1d2a | 893 | #endif // wxUSE_GUI |