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