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