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