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