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