]> git.saurik.com Git - wxWidgets.git/blob - src/common/event.cpp
Watcom compilation fix
[wxWidgets.git] / src / common / event.cpp
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
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 #if wxUSE_STOPWATCH
48 #include "wx/stopwatch.h"
49 #endif
50 #endif // wxUSE_GUI
51
52 // ----------------------------------------------------------------------------
53 // wxWin macros
54 // ----------------------------------------------------------------------------
55
56 #if wxUSE_BASE
57 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject)
58 IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject)
59 #endif // wxUSE_BASE
60
61 #if wxUSE_GUI
62 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent)
63 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent)
64 IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent)
65 IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent)
66 IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent, wxEvent)
67 IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent)
68 IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent)
69 IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent)
70 IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent)
71 IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent, wxEvent)
72 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent)
73 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent)
74 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent)
75 IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent, wxCommandEvent)
76 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent)
77 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent)
78 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent)
79 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent)
80 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent)
81 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent)
82 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent)
83 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent)
84 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent)
85 IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent, wxEvent)
86 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent)
87 IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent, wxEvent)
88 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent)
89 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxCommandEvent)
90 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, wxEvent)
91 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent, wxEvent)
92 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent, wxEvent)
93 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent, wxEvent)
94 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent, wxCommandEvent)
95 IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent, wxCommandEvent)
96 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent, wxEvent)
97 #endif // wxUSE_GUI
98
99 #if wxUSE_BASE
100
101 const wxEventTable *wxEvtHandler::GetEventTable() const
102 { return &wxEvtHandler::sm_eventTable; }
103
104 const wxEventTable wxEvtHandler::sm_eventTable =
105 { (const wxEventTable *)NULL, &wxEvtHandler::sm_eventTableEntries[0] };
106
107 wxEventHashTable &wxEvtHandler::GetEventHashTable() const
108 { return wxEvtHandler::sm_eventHashTable; }
109
110 wxEventHashTable wxEvtHandler::sm_eventHashTable(wxEvtHandler::sm_eventTable);
111
112 const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] =
113 { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL, 0, 0, (wxObjectEventFunction)NULL, NULL) };
114
115 // ----------------------------------------------------------------------------
116 // global variables
117 // ----------------------------------------------------------------------------
118
119 // To put pending event handlers
120 wxList *wxPendingEvents = (wxList *)NULL;
121
122 #if wxUSE_THREADS
123 // protects wxPendingEvents list
124 wxCriticalSection *wxPendingEventsLocker = (wxCriticalSection *)NULL;
125 #endif
126
127 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
128
129 // common event types are defined here, other event types are defined by the
130 // components which use them
131
132 const wxEventType wxEVT_FIRST = 10000;
133 const wxEventType wxEVT_USER_FIRST = wxEVT_FIRST + 2000;
134
135 DEFINE_EVENT_TYPE(wxEVT_NULL)
136 DEFINE_EVENT_TYPE(wxEVT_IDLE)
137 DEFINE_EVENT_TYPE(wxEVT_SOCKET)
138
139 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
140
141 #endif // wxUSE_BASE
142
143 #if wxUSE_GUI
144
145 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
146
147 DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED)
148 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED)
149 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED)
150 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED)
151 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED)
152 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED)
153 DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED)
154 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED)
155 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED)
156 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED)
157 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED)
158 DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED)
159 DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED)
160 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED)
161 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER)
162 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED)
163
164 // Sockets and timers send events, too
165 DEFINE_EVENT_TYPE(wxEVT_TIMER)
166
167 // Mouse event types
168 DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN)
169 DEFINE_EVENT_TYPE(wxEVT_LEFT_UP)
170 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN)
171 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP)
172 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN)
173 DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP)
174 DEFINE_EVENT_TYPE(wxEVT_MOTION)
175 DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW)
176 DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW)
177 DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK)
178 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK)
179 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK)
180 DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS)
181 DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS)
182 DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS)
183 DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL)
184
185 // Non-client mouse events
186 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN)
187 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP)
188 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN)
189 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP)
190 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN)
191 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP)
192 DEFINE_EVENT_TYPE(wxEVT_NC_MOTION)
193 DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW)
194 DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW)
195 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK)
196 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK)
197 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK)
198
199 // Character input event type
200 DEFINE_EVENT_TYPE(wxEVT_CHAR)
201 DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK)
202 DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY)
203 DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN)
204 DEFINE_EVENT_TYPE(wxEVT_KEY_UP)
205 #if wxUSE_HOTKEY
206 DEFINE_EVENT_TYPE(wxEVT_HOTKEY)
207 #endif
208
209 // Set cursor event
210 DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR)
211
212 // wxScrollbar and wxSlider event identifiers
213 DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP)
214 DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM)
215 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP)
216 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN)
217 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP)
218 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN)
219 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK)
220 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE)
221 DEFINE_EVENT_TYPE(wxEVT_SCROLL_ENDSCROLL)
222
223 // Scroll events from wxWindow
224 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP)
225 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM)
226 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP)
227 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN)
228 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP)
229 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN)
230 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK)
231 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE)
232
233 // System events
234 DEFINE_EVENT_TYPE(wxEVT_SIZE)
235 DEFINE_EVENT_TYPE(wxEVT_SIZING)
236 DEFINE_EVENT_TYPE(wxEVT_MOVE)
237 DEFINE_EVENT_TYPE(wxEVT_MOVING)
238 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW)
239 DEFINE_EVENT_TYPE(wxEVT_END_SESSION)
240 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION)
241 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP)
242 DEFINE_EVENT_TYPE(wxEVT_POWER)
243 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE)
244 DEFINE_EVENT_TYPE(wxEVT_CREATE)
245 DEFINE_EVENT_TYPE(wxEVT_DESTROY)
246 DEFINE_EVENT_TYPE(wxEVT_SHOW)
247 DEFINE_EVENT_TYPE(wxEVT_ICONIZE)
248 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE)
249 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED)
250 DEFINE_EVENT_TYPE(wxEVT_PAINT)
251 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND)
252 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT)
253 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON)
254 DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN)
255 DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE)
256 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT)
257 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU)
258 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED)
259 DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED)
260 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED)
261 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE)
262 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED)
263 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN)
264 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP)
265 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE)
266 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE)
267 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES)
268 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM)
269 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM)
270 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM)
271 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG)
272 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI)
273
274 // Generic command events
275 // Note: a click is a higher-level event than button down/up
276 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK)
277 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK)
278 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK)
279 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK)
280 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS)
281 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS)
282 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER)
283
284 // Help events
285 DEFINE_EVENT_TYPE(wxEVT_HELP)
286 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP)
287
288 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
289
290 #endif // wxUSE_GUI
291
292 #if wxUSE_BASE
293
294 // ============================================================================
295 // implementation
296 // ============================================================================
297
298 // ----------------------------------------------------------------------------
299 // event initialization
300 // ----------------------------------------------------------------------------
301
302 int wxNewEventType()
303 {
304 // MT-FIXME
305 static int s_lastUsedEventType = wxEVT_FIRST;
306
307 #if WXWIN_COMPATIBILITY_2
308 // check that we don't overlap with the user-defined types: if it does
309 // happen, the best solution is probably to update the existing code to
310 // use wxNewEventType() instead of wxEVT_USER_FIRST
311 //
312 // due to the uncertainty
313 wxASSERT_MSG( s_lastUsedEventType < wxEVT_USER_FIRST - 1,
314 _T("possible event type conflict") );
315 #endif // WXWIN_COMPATIBILITY_2
316
317 return s_lastUsedEventType++;
318 }
319
320 // ----------------------------------------------------------------------------
321 // wxEvent
322 // ----------------------------------------------------------------------------
323
324 /*
325 * General wxWindows events, covering
326 * all interesting things that might happen (button clicking, resizing,
327 * setting text in widgets, etc.).
328 *
329 * For each completely new event type, derive a new event class.
330 *
331 */
332
333 wxEvent::wxEvent(int theId, wxEventType commandType )
334 {
335 m_eventType = commandType;
336 m_eventObject = (wxObject *) NULL;
337 m_timeStamp = 0;
338 m_id = theId;
339 m_skipped = FALSE;
340 m_callbackUserData = (wxObject *) NULL;
341 m_isCommandEvent = FALSE;
342 m_propagationLevel = wxEVENT_PROPAGATE_NONE;
343 }
344
345 wxEvent::wxEvent(const wxEvent &src)
346 : wxObject()
347 , m_eventObject(src.m_eventObject)
348 , m_eventType(src.m_eventType)
349 , m_timeStamp(src.m_timeStamp)
350 , m_id(src.m_id)
351 , m_callbackUserData(src.m_callbackUserData)
352 , m_propagationLevel(src.m_propagationLevel)
353 , m_skipped(src.m_skipped)
354 , m_isCommandEvent(src.m_isCommandEvent)
355 {
356 }
357
358 #endif // wxUSE_BASE
359
360 #if wxUSE_GUI
361
362 /*
363 * Command events
364 *
365 */
366
367 wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId)
368 : wxEvent(theId, commandType)
369 {
370 m_clientData = (char *) NULL;
371 m_clientObject = (wxClientData *) NULL;
372 m_extraLong = 0;
373 m_commandInt = 0;
374 m_isCommandEvent = TRUE;
375
376 // the command events are propagated upwards by default
377 m_propagationLevel = wxEVENT_PROPAGATE_MAX;
378 }
379
380 /*
381 * UI update events
382 */
383
384 #if wxUSE_LONGLONG
385 wxLongLong wxUpdateUIEvent::sm_lastUpdate = 0;
386 #endif
387
388 long wxUpdateUIEvent::sm_updateInterval = 0;
389
390 wxUpdateUIMode wxUpdateUIEvent::sm_updateMode = wxUPDATE_UI_PROCESS_ALL;
391
392 // Can we update?
393 bool wxUpdateUIEvent::CanUpdate(wxWindow* win)
394 {
395 // Don't update if we've switched global updating off
396 // and this window doesn't support updates.
397 if (win &&
398 (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED &&
399 ((win->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES) == 0)))
400 return FALSE;
401
402 if (sm_updateInterval == -1)
403 return FALSE;
404 else if (sm_updateInterval == 0)
405 return TRUE;
406 else
407 {
408 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
409 wxLongLong now = wxGetLocalTimeMillis();
410 if (now > (sm_lastUpdate + sm_updateInterval))
411 {
412 return TRUE;
413 }
414 #else
415 // If we don't have wxStopWatch or wxLongLong, we
416 // should err on the safe side and update now anyway.
417 return TRUE;
418 #endif
419 }
420 return FALSE;
421 }
422
423 // Reset the update time to provide a delay until the next
424 // time we should update
425 void wxUpdateUIEvent::ResetUpdateTime()
426 {
427 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
428 if (sm_updateInterval > 0)
429 {
430 wxLongLong now = wxGetLocalTimeMillis();
431 if (now > (sm_lastUpdate + sm_updateInterval))
432 {
433 sm_lastUpdate = now;
434 }
435 }
436 #endif
437 }
438
439 /*
440 * Idle events
441 */
442
443 wxIdleMode wxIdleEvent::sm_idleMode = wxIDLE_PROCESS_ALL;
444
445 // Can we send an idle event?
446 bool wxIdleEvent::CanSend(wxWindow* win)
447 {
448 // Don't update if we've switched global updating off
449 // and this window doesn't support updates.
450 if (win &&
451 (GetMode() == wxIDLE_PROCESS_SPECIFIED &&
452 ((win->GetExtraStyle() & wxWS_EX_PROCESS_IDLE) == 0)))
453 return FALSE;
454
455 return TRUE;
456 }
457
458 /*
459 * Scroll events
460 */
461
462 wxScrollEvent::wxScrollEvent(wxEventType commandType,
463 int id,
464 int pos,
465 int orient)
466 : wxCommandEvent(commandType, id)
467 {
468 m_extraLong = orient;
469 m_commandInt = pos;
470 }
471
472 /*
473 * ScrollWin events
474 */
475
476 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType,
477 int pos,
478 int orient)
479 {
480 m_eventType = commandType;
481 m_extraLong = orient;
482 m_commandInt = pos;
483 }
484
485 /*
486 * Mouse events
487 *
488 */
489
490 wxMouseEvent::wxMouseEvent(wxEventType commandType)
491 {
492 m_eventType = commandType;
493 m_metaDown = FALSE;
494 m_altDown = FALSE;
495 m_controlDown = FALSE;
496 m_shiftDown = FALSE;
497 m_leftDown = FALSE;
498 m_rightDown = FALSE;
499 m_middleDown = FALSE;
500 m_x = 0;
501 m_y = 0;
502 m_wheelRotation = 0;
503 m_wheelDelta = 0;
504 m_linesPerAction = 0;
505 }
506
507 void wxMouseEvent::Assign(const wxMouseEvent& event)
508 {
509 m_eventType = event.m_eventType;
510
511 m_x = event.m_x;
512 m_y = event.m_y;
513
514 m_leftDown = event.m_leftDown;
515 m_middleDown = event.m_middleDown;
516 m_rightDown = event.m_rightDown;
517
518 m_controlDown = event.m_controlDown;
519 m_shiftDown = event.m_shiftDown;
520 m_altDown = event.m_altDown;
521 m_metaDown = event.m_metaDown;
522
523 m_wheelRotation = event.m_wheelRotation;
524 m_wheelDelta = event.m_wheelDelta;
525 m_linesPerAction = event.m_linesPerAction;
526 }
527
528 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
529 // or any button dclick event (but = -1)
530 bool wxMouseEvent::ButtonDClick(int but) const
531 {
532 switch (but)
533 {
534 case -1:
535 return (LeftDClick() || MiddleDClick() || RightDClick());
536 case 1:
537 return LeftDClick();
538 case 2:
539 return MiddleDClick();
540 case 3:
541 return RightDClick();
542 default:
543 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
544 }
545
546 return FALSE;
547 }
548
549 // True if was a button down event (1 = left, 2 = middle, 3 = right)
550 // or any button down event (but = -1)
551 bool wxMouseEvent::ButtonDown(int but) const
552 {
553 switch (but)
554 {
555 case -1:
556 return (LeftDown() || MiddleDown() || RightDown());
557 case 1:
558 return LeftDown();
559 case 2:
560 return MiddleDown();
561 case 3:
562 return RightDown();
563 default:
564 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
565 }
566
567 return FALSE;
568 }
569
570 // True if was a button up event (1 = left, 2 = middle, 3 = right)
571 // or any button up event (but = -1)
572 bool wxMouseEvent::ButtonUp(int but) const
573 {
574 switch (but)
575 {
576 case -1:
577 return (LeftUp() || MiddleUp() || RightUp());
578 case 1:
579 return LeftUp();
580 case 2:
581 return MiddleUp();
582 case 3:
583 return RightUp();
584 default:
585 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
586 }
587
588 return FALSE;
589 }
590
591 // True if the given button is currently changing state
592 bool wxMouseEvent::Button(int but) const
593 {
594 switch (but)
595 {
596 case -1:
597 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
598 case 1:
599 return (LeftDown() || LeftUp() || LeftDClick());
600 case 2:
601 return (MiddleDown() || MiddleUp() || MiddleDClick());
602 case 3:
603 return (RightDown() || RightUp() || RightDClick());
604 default:
605 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
606 }
607
608 return FALSE;
609 }
610
611 bool wxMouseEvent::ButtonIsDown(int but) const
612 {
613 switch (but)
614 {
615 case -1:
616 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
617 case 1:
618 return LeftIsDown();
619 case 2:
620 return MiddleIsDown();
621 case 3:
622 return RightIsDown();
623 default:
624 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
625 }
626
627 return FALSE;
628 }
629
630 int wxMouseEvent::GetButton() const
631 {
632 for ( int i = 1; i <= 3; i++ )
633 {
634 if ( Button(i) )
635 {
636 return i;
637 }
638 }
639
640 return -1;
641 }
642
643 // Find the logical position of the event given the DC
644 wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const
645 {
646 wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y));
647 return pt;
648 }
649
650
651 /*
652 * Keyboard event
653 *
654 */
655
656 wxKeyEvent::wxKeyEvent(wxEventType type)
657 {
658 m_eventType = type;
659 m_shiftDown = FALSE;
660 m_controlDown = FALSE;
661 m_metaDown = FALSE;
662 m_altDown = FALSE;
663 m_keyCode = 0;
664 m_scanCode = 0;
665 #if wxUSE_UNICODE
666 m_uniChar = 0;
667 #endif
668 }
669
670 wxKeyEvent::wxKeyEvent(const wxKeyEvent& evt)
671 : wxEvent(evt)
672 {
673 m_x = evt.m_x;
674 m_y = evt.m_y;
675
676 m_keyCode = evt.m_keyCode;
677
678 m_controlDown = evt.m_controlDown;
679 m_shiftDown = evt.m_shiftDown;
680 m_altDown = evt.m_altDown;
681 m_metaDown = evt.m_metaDown;
682 m_scanCode = evt.m_scanCode;
683 m_rawCode = evt.m_rawCode;
684 m_rawFlags = evt.m_rawFlags;
685
686 #if wxUSE_UNICODE
687 m_uniChar = evt.m_uniChar;
688 #endif
689 }
690
691 long wxKeyEvent::KeyCode() const
692 {
693 return m_keyCode;
694 }
695
696 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow *win)
697 {
698 SetEventType(wxEVT_CREATE);
699 SetEventObject(win);
700 }
701
702 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow *win)
703 {
704 SetEventType(wxEVT_DESTROY);
705 SetEventObject(win);
706 }
707
708 wxChildFocusEvent::wxChildFocusEvent(wxWindow *win)
709 : wxCommandEvent(wxEVT_CHILD_FOCUS)
710 {
711 SetEventObject(win);
712 }
713
714 #endif // wxUSE_GUI
715
716
717 #if wxUSE_BASE
718
719 // ----------------------------------------------------------------------------
720 // wxEventHashTable
721 // ----------------------------------------------------------------------------
722
723 static const int EVENT_TYPE_TABLE_INIT_SIZE = 31; // Not to big not to small...
724
725 wxEventHashTable::wxEventHashTable(const wxEventTable &table)
726 : m_table(table),
727 m_rebuildHash(TRUE)
728 {
729 AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE);
730 }
731
732 wxEventHashTable::~wxEventHashTable()
733 {
734 size_t i;
735 for(i = 0; i < m_size; i++)
736 {
737 EventTypeTablePointer eTTnode = m_eventTypeTable[i];
738 if (eTTnode)
739 {
740 delete eTTnode;
741 }
742 }
743
744 delete[] m_eventTypeTable;
745 }
746
747 bool wxEventHashTable::HandleEvent(wxEvent &event, wxEvtHandler *self)
748 {
749 if (m_rebuildHash)
750 {
751 InitHashTable();
752 m_rebuildHash = FALSE;
753 }
754
755 // Find all entries for the given event type.
756 wxEventType eventType = event.GetEventType();
757 const EventTypeTablePointer eTTnode = m_eventTypeTable[eventType % m_size];
758 if (eTTnode && eTTnode->eventType == eventType)
759 {
760 // Now start the search for an event handler
761 // that can handle an event with the given ID.
762 int eventId = event.GetId();
763 const wxEventTableEntryPointerArray &eventEntryTable = eTTnode->eventEntryTable;
764
765 size_t n;
766 size_t count = eventEntryTable.GetCount();
767 for (n = 0; n < count; n++)
768 {
769 const wxEventTableEntry* entry = eventEntryTable[n];
770 int tableId1 = entry->m_id,
771 tableId2 = entry->m_lastId;
772
773 if ((tableId1 == -1) ||
774 (tableId2 == -1 && tableId1 == eventId) ||
775 (tableId2 != -1 &&
776 (eventId >= tableId1 && eventId <= tableId2)))
777 {
778 event.Skip(FALSE);
779 event.m_callbackUserData = entry->m_callbackUserData;
780
781 (self->*((wxEventFunction) (entry->m_fn)))(event);
782
783 if (!event.GetSkipped())
784 return TRUE;
785 }
786 }
787
788 return FALSE;
789 }
790
791 return FALSE;
792 }
793
794 void wxEventHashTable::InitHashTable()
795 {
796 // Loop over the event tables and all its base tables.
797 const wxEventTable *table = &m_table;
798 while (table)
799 {
800 // Retrieve all valid event handler entries
801 const wxEventTableEntry *entry = table->entries;
802 while (entry->m_fn != 0)
803 {
804 // Add the event entry in the Hash.
805 AddEntry(*entry);
806
807 entry++;
808 }
809
810 table = table->baseTable;
811 }
812
813 // Lets free some memory.
814 size_t i;
815 for(i = 0; i < m_size; i++)
816 {
817 EventTypeTablePointer eTTnode = m_eventTypeTable[i];
818 if (eTTnode)
819 {
820 eTTnode->eventEntryTable.Shrink();
821 }
822 }
823 }
824
825 void wxEventHashTable::AddEntry(const wxEventTableEntry &entry)
826 {
827 EventTypeTablePointer *peTTnode = &m_eventTypeTable[entry.m_eventType % m_size];
828 EventTypeTablePointer eTTnode = *peTTnode;
829
830 if (eTTnode)
831 {
832 if (eTTnode->eventType != entry.m_eventType)
833 {
834 // Resize the table!
835 GrowEventTypeTable();
836 // Try again to add it.
837 AddEntry(entry);
838 return;
839 }
840 }
841 else
842 {
843 eTTnode = new EventTypeTable;
844 eTTnode->eventType = entry.m_eventType;
845 *peTTnode = eTTnode;
846 }
847
848 // Fill all hash entries between entry.m_id and entry.m_lastId...
849 eTTnode->eventEntryTable.Add(&entry);
850 }
851
852 void wxEventHashTable::AllocEventTypeTable(size_t size)
853 {
854 m_eventTypeTable = new EventTypeTablePointer[size];
855 memset((void *)m_eventTypeTable, 0, sizeof(EventTypeTablePointer)*size);
856 m_size = size;
857 }
858
859 void wxEventHashTable::GrowEventTypeTable()
860 {
861 size_t oldSize = m_size;
862 EventTypeTablePointer *oldEventTypeTable = m_eventTypeTable;
863
864 // TODO: Search the most optimal grow sequence
865 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize*2+1);
866
867 for ( size_t i = 0; i < oldSize; /* */ )
868 {
869 EventTypeTablePointer eTToldNode = oldEventTypeTable[i];
870 if (eTToldNode)
871 {
872 EventTypeTablePointer *peTTnode = &m_eventTypeTable[eTToldNode->eventType % m_size];
873 EventTypeTablePointer eTTnode = *peTTnode;
874
875 // Check for collision, we don't want any.
876 if (eTTnode)
877 {
878 GrowEventTypeTable();
879 continue; // Don't increment the counter,
880 // as we still need to add this element.
881 }
882 else
883 {
884 // Get the old value and put it in the new table.
885 *peTTnode = oldEventTypeTable[i];
886 }
887 }
888
889 i++;
890 }
891
892 delete[] oldEventTypeTable;
893 }
894
895 // ----------------------------------------------------------------------------
896 // wxEvtHandler
897 // ----------------------------------------------------------------------------
898
899 /*
900 * Event handler
901 */
902
903 wxEvtHandler::wxEvtHandler()
904 {
905 m_nextHandler = (wxEvtHandler *) NULL;
906 m_previousHandler = (wxEvtHandler *) NULL;
907 m_enabled = TRUE;
908 m_dynamicEvents = (wxList *) NULL;
909 m_pendingEvents = (wxList *) NULL;
910 #if wxUSE_THREADS
911 # if !defined(__VISAGECPP__)
912 m_eventsLocker = new wxCriticalSection;
913 # endif
914 #endif
915 // no client data (yet)
916 m_clientData = NULL;
917 m_clientDataType = wxClientData_None;
918 }
919
920 wxEvtHandler::~wxEvtHandler()
921 {
922 // Takes itself out of the list of handlers
923 if (m_previousHandler)
924 m_previousHandler->m_nextHandler = m_nextHandler;
925
926 if (m_nextHandler)
927 m_nextHandler->m_previousHandler = m_previousHandler;
928
929 if (m_dynamicEvents)
930 {
931 wxList::iterator it = m_dynamicEvents->begin(),
932 en = m_dynamicEvents->end();
933 for (;it != en; ++it)
934 {
935 #if WXWIN_COMPATIBILITY_EVENT_TYPES
936 wxEventTableEntry *entry = (wxEventTableEntry*)*it;
937 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
938 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)*it;
939 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
940
941 if (entry->m_callbackUserData)
942 delete entry->m_callbackUserData;
943 delete entry;
944 }
945 delete m_dynamicEvents;
946 };
947
948 delete m_pendingEvents;
949
950 #if wxUSE_THREADS
951 # if !defined(__VISAGECPP__)
952 delete m_eventsLocker;
953 # endif
954
955 // Remove us from wxPendingEvents if necessary.
956 if(wxPendingEventsLocker)
957 wxENTER_CRIT_SECT(*wxPendingEventsLocker);
958 if ( wxPendingEvents ) {
959 wxPendingEvents->DeleteObject(this);
960 }
961 if(wxPendingEventsLocker)
962 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker);
963 #endif
964
965 // we only delete object data, not untyped
966 if ( m_clientDataType == wxClientData_Object )
967 delete m_clientObject;
968 }
969
970 #if wxUSE_THREADS
971
972 bool wxEvtHandler::ProcessThreadEvent(wxEvent& event)
973 {
974 // check that we are really in a child thread
975 wxASSERT_MSG( !wxThread::IsMain(),
976 wxT("use ProcessEvent() in main thread") );
977
978 AddPendingEvent(event);
979
980 return TRUE;
981 }
982
983 #endif // wxUSE_THREADS
984
985 void wxEvtHandler::AddPendingEvent(wxEvent& event)
986 {
987 // 1) Add event to list of pending events of this event handler
988
989 wxEvent *eventCopy = event.Clone();
990
991 // we must be able to copy the events here so the event class must
992 // implement Clone() properly instead of just providing a NULL stab for it
993 wxCHECK_RET( eventCopy,
994 _T("events of this type aren't supposed to be posted") );
995
996 #if defined(__VISAGECPP__)
997 wxENTER_CRIT_SECT( m_eventsLocker);
998 #else
999 wxENTER_CRIT_SECT( *m_eventsLocker);
1000 #endif
1001
1002 if ( !m_pendingEvents )
1003 m_pendingEvents = new wxList;
1004
1005 m_pendingEvents->Append(eventCopy);
1006
1007 #if defined(__VISAGECPP__)
1008 wxLEAVE_CRIT_SECT( m_eventsLocker);
1009 #else
1010 wxLEAVE_CRIT_SECT( *m_eventsLocker);
1011 #endif
1012
1013 // 2) Add this event handler to list of event handlers that
1014 // have pending events.
1015
1016 wxENTER_CRIT_SECT(*wxPendingEventsLocker);
1017
1018 if ( !wxPendingEvents )
1019 wxPendingEvents = new wxList;
1020 wxPendingEvents->Append(this);
1021
1022 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker);
1023
1024 // 3) Inform the system that new pending events are somwehere,
1025 // and that these should be processed in idle time.
1026 wxWakeUpIdle();
1027 }
1028
1029 void wxEvtHandler::ProcessPendingEvents()
1030 {
1031 #if defined(__VISAGECPP__)
1032 wxENTER_CRIT_SECT( m_eventsLocker);
1033 #else
1034 wxENTER_CRIT_SECT( *m_eventsLocker);
1035 #endif
1036
1037 wxList::compatibility_iterator node = m_pendingEvents->GetFirst();
1038 while ( node )
1039 {
1040 wxEvent *event = (wxEvent *)node->GetData();
1041 m_pendingEvents->Erase(node);
1042
1043 // In ProcessEvent, new events might get added and
1044 // we can safely leave the crtical section here.
1045 #if defined(__VISAGECPP__)
1046 wxLEAVE_CRIT_SECT( m_eventsLocker);
1047 #else
1048 wxLEAVE_CRIT_SECT( *m_eventsLocker);
1049 #endif
1050 ProcessEvent(*event);
1051 delete event;
1052 #if defined(__VISAGECPP__)
1053 wxENTER_CRIT_SECT( m_eventsLocker);
1054 #else
1055 wxENTER_CRIT_SECT( *m_eventsLocker);
1056 #endif
1057
1058 node = m_pendingEvents->GetFirst();
1059 }
1060
1061 #if defined(__VISAGECPP__)
1062 wxLEAVE_CRIT_SECT( m_eventsLocker);
1063 #else
1064 wxLEAVE_CRIT_SECT( *m_eventsLocker);
1065 #endif
1066 }
1067
1068 /*
1069 * Event table stuff
1070 */
1071
1072 bool wxEvtHandler::TryParent(wxEvent& event)
1073 {
1074 if ( wxTheApp && (this != wxTheApp) )
1075 {
1076 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1077 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1078 // processed appropriately via SearchEventTable.
1079 if ( event.GetEventType() != wxEVT_IDLE )
1080 {
1081 if ( wxTheApp->ProcessEvent(event) )
1082 return TRUE;
1083 }
1084 }
1085
1086 return FALSE;
1087 }
1088
1089 bool wxEvtHandler::ProcessEvent(wxEvent& event)
1090 {
1091 // allow the application to hook into event processing
1092 if ( wxTheApp )
1093 {
1094 int rc = wxTheApp->FilterEvent(event);
1095 if ( rc != -1 )
1096 {
1097 wxASSERT_MSG( rc == 1 || rc == 0,
1098 _T("unexpected wxApp::FilterEvent return value") );
1099
1100 return rc != 0;
1101 }
1102 //else: proceed normally
1103 }
1104
1105 // An event handler can be enabled or disabled
1106 if ( GetEvtHandlerEnabled() )
1107 {
1108 // if we have a validator, it has higher priority than our own event
1109 // table
1110 #if wxUSE_VALIDATORS
1111 if ( TryValidator(event) )
1112 return TRUE;
1113 #endif // wxUSE_VALIDATORS
1114
1115 // Handle per-instance dynamic event tables first
1116 if ( m_dynamicEvents && SearchDynamicEventTable(event) )
1117 return TRUE;
1118
1119 // Then static per-class event tables
1120 if ( GetEventHashTable().HandleEvent(event, this) )
1121 return TRUE;
1122 }
1123
1124 // Try going down the event handler chain
1125 if ( GetNextHandler() )
1126 {
1127 if ( GetNextHandler()->ProcessEvent(event) )
1128 return TRUE;
1129 }
1130
1131 // Finally propagate the event upwards the window chain and/or to the
1132 // application object as necessary
1133 return TryParent(event);
1134 }
1135
1136
1137 bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
1138 {
1139 wxEventType eventType = event.GetEventType();
1140 int eventId = event.GetId();
1141
1142 // BC++ doesn't like testing for m_fn without != 0
1143 for ( int i = 0; table.entries[i].m_fn != 0; i++ )
1144 {
1145 // the line using reference exposes a bug in gcc: although it _seems_
1146 // to work, it leads to weird crashes later on during program
1147 // execution
1148 #ifdef __GNUG__
1149 wxEventTableEntry entry = table.entries[i];
1150 #else
1151 const wxEventTableEntry& entry = table.entries[i];
1152 #endif
1153
1154 // match only if the event type is the same and the id is either -1 in
1155 // the event table (meaning "any") or the event id matches the id
1156 // specified in the event table either exactly or by falling into
1157 // range between first and last
1158 if ( eventType == entry.m_eventType )
1159 {
1160 int tableId1 = entry.m_id,
1161 tableId2 = entry.m_lastId;
1162
1163 if ( (tableId1 == -1) ||
1164 (tableId2 == -1 && eventId == tableId1) ||
1165 (tableId2 != -1 &&
1166 (eventId >= tableId1 && eventId <= tableId2)) )
1167 {
1168 event.Skip(FALSE);
1169 event.m_callbackUserData = entry.m_callbackUserData;
1170
1171 (this->*((wxEventFunction) (entry.m_fn)))(event);
1172
1173 return !event.GetSkipped();
1174 }
1175 }
1176 }
1177
1178 return FALSE;
1179 }
1180
1181 void wxEvtHandler::Connect( int id, int lastId,
1182 int eventType,
1183 wxObjectEventFunction func,
1184 wxObject *userData,
1185 wxEvtHandler* eventSink )
1186 {
1187 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1188 wxEventTableEntry *entry = new wxEventTableEntry;
1189 entry->m_eventType = eventType;
1190 entry->m_id = id;
1191 entry->m_lastId = lastId;
1192 entry->m_fn = func;
1193 entry->m_callbackUserData = userData;
1194 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1195 wxDynamicEventTableEntry *entry =
1196 new wxDynamicEventTableEntry(eventType, id, lastId, func, userData, eventSink);
1197 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1198
1199 if (!m_dynamicEvents)
1200 m_dynamicEvents = new wxList;
1201
1202 // Insert at the front of the list so most recent additions are found first
1203 m_dynamicEvents->Insert( (wxObject*) entry );
1204 }
1205
1206 bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType,
1207 wxObjectEventFunction func,
1208 wxObject *userData,
1209 wxEvtHandler* eventSink )
1210 {
1211 if (!m_dynamicEvents)
1212 return FALSE;
1213
1214 wxList::compatibility_iterator node = m_dynamicEvents->GetFirst();
1215 while (node)
1216 {
1217 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1218 wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData();
1219 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1220 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
1221 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1222
1223 if ((entry->m_id == id) &&
1224 ((entry->m_lastId == lastId) || (lastId == -1)) &&
1225 ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) &&
1226 ((entry->m_fn == func) || (func == (wxObjectEventFunction)NULL)) &&
1227 ((entry->m_eventSink == eventSink) || (eventSink == (wxEvtHandler*)NULL)) &&
1228 ((entry->m_callbackUserData == userData) || (userData == (wxObject*)NULL)))
1229 {
1230 if (entry->m_callbackUserData)
1231 delete entry->m_callbackUserData;
1232 m_dynamicEvents->Erase( node );
1233 delete entry;
1234 return TRUE;
1235 }
1236 node = node->GetNext();
1237 }
1238 return FALSE;
1239 }
1240
1241 bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
1242 {
1243 wxCHECK_MSG( m_dynamicEvents, FALSE,
1244 wxT("caller should check that we have dynamic events") );
1245
1246 int commandId = event.GetId();
1247
1248 wxList::compatibility_iterator node = m_dynamicEvents->GetFirst();
1249 while (node)
1250 {
1251 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1252 wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData();
1253 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1254 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
1255 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1256
1257 if (entry->m_fn)
1258 {
1259 // Match, if event spec says any id will do (id == -1)
1260 if ( (event.GetEventType() == entry->m_eventType) &&
1261 (entry->m_id == -1 ||
1262 (entry->m_lastId == -1 && commandId == entry->m_id) ||
1263 (entry->m_lastId != -1 &&
1264 (commandId >= entry->m_id && commandId <= entry->m_lastId))) )
1265 {
1266 event.Skip(FALSE);
1267 event.m_callbackUserData = entry->m_callbackUserData;
1268
1269 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
1270 if (entry->m_eventSink)
1271 ((entry->m_eventSink)->*((wxEventFunction) (entry->m_fn)))(event);
1272 else
1273 #endif
1274 (this->*((wxEventFunction) (entry->m_fn)))(event);
1275
1276 if ( ! event.GetSkipped() )
1277 return TRUE;
1278 }
1279 }
1280 node = node->GetNext();
1281 }
1282 return FALSE;
1283 };
1284
1285 void wxEvtHandler::DoSetClientObject( wxClientData *data )
1286 {
1287 wxASSERT_MSG( m_clientDataType != wxClientData_Void,
1288 wxT("can't have both object and void client data") );
1289
1290 if ( m_clientObject )
1291 delete m_clientObject;
1292
1293 m_clientObject = data;
1294 m_clientDataType = wxClientData_Object;
1295 }
1296
1297 wxClientData *wxEvtHandler::DoGetClientObject() const
1298 {
1299 // it's not an error to call GetClientObject() on a window which doesn't
1300 // have client data at all - NULL will be returned
1301 wxASSERT_MSG( m_clientDataType != wxClientData_Void,
1302 wxT("this window doesn't have object client data") );
1303
1304 return m_clientObject;
1305 }
1306
1307 void wxEvtHandler::DoSetClientData( void *data )
1308 {
1309 wxASSERT_MSG( m_clientDataType != wxClientData_Object,
1310 wxT("can't have both object and void client data") );
1311
1312 m_clientData = data;
1313 m_clientDataType = wxClientData_Void;
1314 }
1315
1316 void *wxEvtHandler::DoGetClientData() const
1317 {
1318 // it's not an error to call GetClientData() on a window which doesn't have
1319 // client data at all - NULL will be returned
1320 wxASSERT_MSG( m_clientDataType != wxClientData_Object,
1321 wxT("this window doesn't have void client data") );
1322
1323 return m_clientData;
1324 }
1325
1326
1327 #if WXWIN_COMPATIBILITY
1328 bool wxEvtHandler::OnClose()
1329 {
1330 if (GetNextHandler())
1331 return GetNextHandler()->OnClose();
1332 else
1333 return FALSE;
1334 }
1335 #endif // WXWIN_COMPATIBILITY
1336
1337 #endif // wxUSE_BASE
1338
1339 #if wxUSE_GUI
1340
1341 // Find a window with the focus, that is also a descendant of the given window.
1342 // This is used to determine the window to initially send commands to.
1343 wxWindow* wxFindFocusDescendant(wxWindow* ancestor)
1344 {
1345 // Process events starting with the window with the focus, if any.
1346 wxWindow* focusWin = wxWindow::FindFocus();
1347 wxWindow* win = focusWin;
1348
1349 // Check if this is a descendant of this frame.
1350 // If not, win will be set to NULL.
1351 while (win)
1352 {
1353 if (win == ancestor)
1354 break;
1355 else
1356 win = win->GetParent();
1357 }
1358 if (win == (wxWindow*) NULL)
1359 focusWin = (wxWindow*) NULL;
1360
1361 return focusWin;
1362 }
1363
1364 #endif // wxUSE_GUI