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