]> git.saurik.com Git - wxWidgets.git/blob - src/common/event.cpp
083e52a70960d512a741bc774294c6b22331f843
[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 }
343
344 wxEvent::wxEvent(const wxEvent &src)
345 : wxObject()
346 , m_eventObject(src.m_eventObject)
347 , m_eventType(src.m_eventType)
348 , m_timeStamp(src.m_timeStamp)
349 , m_id(src.m_id)
350 , m_callbackUserData(src.m_callbackUserData)
351 , m_skipped(src.m_skipped)
352 , m_isCommandEvent(src.m_isCommandEvent)
353 {
354 }
355
356 #endif // wxUSE_BASE
357
358 #if wxUSE_GUI
359
360 /*
361 * Command events
362 *
363 */
364
365 wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId)
366 : wxEvent(theId, commandType)
367 {
368 m_clientData = (char *) NULL;
369 m_clientObject = (wxClientData *) NULL;
370 m_extraLong = 0;
371 m_commandInt = 0;
372 m_isCommandEvent = TRUE;
373 }
374
375 /*
376 * UI update events
377 */
378
379 #if wxUSE_LONGLONG
380 wxLongLong wxUpdateUIEvent::sm_lastUpdate = 0;
381 #endif
382
383 long wxUpdateUIEvent::sm_updateInterval = 0;
384
385 wxUpdateUIMode wxUpdateUIEvent::sm_updateMode = wxUPDATE_UI_PROCESS_ALL;
386
387 // Can we update?
388 bool wxUpdateUIEvent::CanUpdate(wxWindow* win)
389 {
390 // Don't update if we've switched global updating off
391 // and this window doesn't support updates.
392 if (win &&
393 (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED &&
394 ((win->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES) == 0)))
395 return FALSE;
396
397 if (sm_updateInterval == -1)
398 return FALSE;
399 else if (sm_updateInterval == 0)
400 return TRUE;
401 else
402 {
403 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
404 wxLongLong now = wxGetLocalTimeMillis();
405 if (now > (sm_lastUpdate + sm_updateInterval))
406 {
407 return TRUE;
408 }
409 #else
410 // If we don't have wxStopWatch or wxLongLong, we
411 // should err on the safe side and update now anyway.
412 return TRUE;
413 #endif
414 }
415 return FALSE;
416 }
417
418 // Reset the update time to provide a delay until the next
419 // time we should update
420 void wxUpdateUIEvent::ResetUpdateTime()
421 {
422 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
423 if (sm_updateInterval > 0)
424 {
425 wxLongLong now = wxGetLocalTimeMillis();
426 if (now > (sm_lastUpdate + sm_updateInterval))
427 {
428 sm_lastUpdate = now;
429 }
430 }
431 #endif
432 }
433
434 /*
435 * Idle events
436 */
437
438 wxIdleMode wxIdleEvent::sm_idleMode = wxIDLE_PROCESS_ALL;
439
440 // Can we send an idle event?
441 bool wxIdleEvent::CanSend(wxWindow* win)
442 {
443 // Don't update if we've switched global updating off
444 // and this window doesn't support updates.
445 if (win &&
446 (GetMode() == wxIDLE_PROCESS_SPECIFIED &&
447 ((win->GetExtraStyle() & wxWS_EX_PROCESS_IDLE) == 0)))
448 return FALSE;
449
450 return TRUE;
451 }
452
453 /*
454 * Scroll events
455 */
456
457 wxScrollEvent::wxScrollEvent(wxEventType commandType,
458 int id,
459 int pos,
460 int orient)
461 : wxCommandEvent(commandType, id)
462 {
463 m_extraLong = orient;
464 m_commandInt = pos;
465 }
466
467 /*
468 * ScrollWin events
469 */
470
471 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType,
472 int pos,
473 int orient)
474 {
475 m_eventType = commandType;
476 m_extraLong = orient;
477 m_commandInt = pos;
478 }
479
480 /*
481 * Mouse events
482 *
483 */
484
485 wxMouseEvent::wxMouseEvent(wxEventType commandType)
486 {
487 m_eventType = commandType;
488 m_metaDown = FALSE;
489 m_altDown = FALSE;
490 m_controlDown = FALSE;
491 m_shiftDown = FALSE;
492 m_leftDown = FALSE;
493 m_rightDown = FALSE;
494 m_middleDown = FALSE;
495 m_x = 0;
496 m_y = 0;
497 m_wheelRotation = 0;
498 m_wheelDelta = 0;
499 m_linesPerAction = 0;
500 }
501
502 void wxMouseEvent::Assign(const wxMouseEvent& event)
503 {
504 m_eventType = event.m_eventType;
505
506 m_x = event.m_x;
507 m_y = event.m_y;
508
509 m_leftDown = event.m_leftDown;
510 m_middleDown = event.m_middleDown;
511 m_rightDown = event.m_rightDown;
512
513 m_controlDown = event.m_controlDown;
514 m_shiftDown = event.m_shiftDown;
515 m_altDown = event.m_altDown;
516 m_metaDown = event.m_metaDown;
517
518 m_wheelRotation = event.m_wheelRotation;
519 m_wheelDelta = event.m_wheelDelta;
520 m_linesPerAction = event.m_linesPerAction;
521 }
522
523 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
524 // or any button dclick event (but = -1)
525 bool wxMouseEvent::ButtonDClick(int but) const
526 {
527 switch (but)
528 {
529 case -1:
530 return (LeftDClick() || MiddleDClick() || RightDClick());
531 case 1:
532 return LeftDClick();
533 case 2:
534 return MiddleDClick();
535 case 3:
536 return RightDClick();
537 default:
538 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
539 }
540
541 return FALSE;
542 }
543
544 // True if was a button down event (1 = left, 2 = middle, 3 = right)
545 // or any button down event (but = -1)
546 bool wxMouseEvent::ButtonDown(int but) const
547 {
548 switch (but)
549 {
550 case -1:
551 return (LeftDown() || MiddleDown() || RightDown());
552 case 1:
553 return LeftDown();
554 case 2:
555 return MiddleDown();
556 case 3:
557 return RightDown();
558 default:
559 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
560 }
561
562 return FALSE;
563 }
564
565 // True if was a button up event (1 = left, 2 = middle, 3 = right)
566 // or any button up event (but = -1)
567 bool wxMouseEvent::ButtonUp(int but) const
568 {
569 switch (but)
570 {
571 case -1:
572 return (LeftUp() || MiddleUp() || RightUp());
573 case 1:
574 return LeftUp();
575 case 2:
576 return MiddleUp();
577 case 3:
578 return RightUp();
579 default:
580 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
581 }
582
583 return FALSE;
584 }
585
586 // True if the given button is currently changing state
587 bool wxMouseEvent::Button(int but) const
588 {
589 switch (but)
590 {
591 case -1:
592 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
593 case 1:
594 return (LeftDown() || LeftUp() || LeftDClick());
595 case 2:
596 return (MiddleDown() || MiddleUp() || MiddleDClick());
597 case 3:
598 return (RightDown() || RightUp() || RightDClick());
599 default:
600 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
601 }
602
603 return FALSE;
604 }
605
606 bool wxMouseEvent::ButtonIsDown(int but) const
607 {
608 switch (but)
609 {
610 case -1:
611 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
612 case 1:
613 return LeftIsDown();
614 case 2:
615 return MiddleIsDown();
616 case 3:
617 return RightIsDown();
618 default:
619 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
620 }
621
622 return FALSE;
623 }
624
625 int wxMouseEvent::GetButton() const
626 {
627 for ( int i = 1; i <= 3; i++ )
628 {
629 if ( Button(i) )
630 {
631 return i;
632 }
633 }
634
635 return -1;
636 }
637
638 // Find the logical position of the event given the DC
639 wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const
640 {
641 wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y));
642 return pt;
643 }
644
645
646 /*
647 * Keyboard event
648 *
649 */
650
651 wxKeyEvent::wxKeyEvent(wxEventType type)
652 {
653 m_eventType = type;
654 m_shiftDown = FALSE;
655 m_controlDown = FALSE;
656 m_metaDown = FALSE;
657 m_altDown = FALSE;
658 m_keyCode = 0;
659 m_scanCode = 0;
660 #if wxUSE_UNICODE
661 m_uniChar = 0;
662 #endif
663 }
664
665 wxKeyEvent::wxKeyEvent(const wxKeyEvent& evt)
666 : wxEvent(evt)
667 {
668 m_x = evt.m_x;
669 m_y = evt.m_y;
670
671 m_keyCode = evt.m_keyCode;
672
673 m_controlDown = evt.m_controlDown;
674 m_shiftDown = evt.m_shiftDown;
675 m_altDown = evt.m_altDown;
676 m_metaDown = evt.m_metaDown;
677 m_scanCode = evt.m_scanCode;
678 m_rawCode = evt.m_rawCode;
679 m_rawFlags = evt.m_rawFlags;
680
681 #if wxUSE_UNICODE
682 m_uniChar = evt.m_uniChar;
683 #endif
684 }
685
686 long wxKeyEvent::KeyCode() const
687 {
688 return m_keyCode;
689 }
690
691 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow *win)
692 {
693 SetEventType(wxEVT_CREATE);
694 SetEventObject(win);
695 }
696
697 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow *win)
698 {
699 SetEventType(wxEVT_DESTROY);
700 SetEventObject(win);
701 }
702
703 wxChildFocusEvent::wxChildFocusEvent(wxWindow *win)
704 : wxCommandEvent(wxEVT_CHILD_FOCUS)
705 {
706 SetEventObject(win);
707 }
708
709 #endif // wxUSE_GUI
710
711 // ----------------------------------------------------------------------------
712 // wxEventHashTable
713 // ----------------------------------------------------------------------------
714
715 static const int EVENT_TYPE_TABLE_INIT_SIZE = 31; // Not to big not to small...
716
717 wxEventHashTable::wxEventHashTable(const wxEventTable &table)
718 : m_table(table),
719 m_rebuildHash(TRUE)
720 {
721 AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE);
722 }
723
724 wxEventHashTable::~wxEventHashTable()
725 {
726 size_t i;
727 for(i = 0; i < m_size; i++)
728 {
729 EventTypeTablePointer eTTnode = m_eventTypeTable[i];
730 if (eTTnode)
731 {
732 delete eTTnode;
733 }
734 }
735
736 delete[] m_eventTypeTable;
737 }
738
739 bool wxEventHashTable::HandleEvent(wxEvent &event, wxEvtHandler *self)
740 {
741 if (m_rebuildHash)
742 {
743 InitHashTable();
744 m_rebuildHash = FALSE;
745 }
746
747 // Find all entries for the given event type.
748 wxEventType eventType = event.GetEventType();
749 const EventTypeTablePointer eTTnode = m_eventTypeTable[eventType % m_size];
750 if (eTTnode && eTTnode->eventType == eventType)
751 {
752 // Now start the search for an event handler
753 // that can handle an event with the given ID.
754 int eventId = event.GetId();
755 const wxEventTableEntryPointerArray &eventEntryTable = eTTnode->eventEntryTable;
756
757 size_t n;
758 size_t count = eventEntryTable.GetCount();
759 for (n = 0; n < count; n++)
760 {
761 const wxEventTableEntry* entry = eventEntryTable[n];
762 int tableId1 = entry->m_id,
763 tableId2 = entry->m_lastId;
764
765 if ((tableId1 == -1) ||
766 (tableId2 == -1 && tableId1 == eventId) ||
767 (tableId2 != -1 &&
768 (eventId >= tableId1 && eventId <= tableId2)))
769 {
770 event.Skip(FALSE);
771 event.m_callbackUserData = entry->m_callbackUserData;
772
773 (self->*((wxEventFunction) (entry->m_fn)))(event);
774
775 if (!event.GetSkipped())
776 return TRUE;
777 }
778 }
779
780 return FALSE;
781 }
782
783 return FALSE;
784 }
785
786 void wxEventHashTable::InitHashTable()
787 {
788 // Loop over the event tables and all its base tables.
789 const wxEventTable *table = &m_table;
790 while (table)
791 {
792 // Retrieve all valid event handler entries
793 const wxEventTableEntry *entry = table->entries;
794 while (entry->m_fn != 0)
795 {
796 // Add the event entry in the Hash.
797 AddEntry(*entry);
798
799 entry++;
800 }
801
802 table = table->baseTable;
803 }
804
805 // Lets free some memory.
806 size_t i;
807 for(i = 0; i < m_size; i++)
808 {
809 EventTypeTablePointer eTTnode = m_eventTypeTable[i];
810 if (eTTnode)
811 {
812 eTTnode->eventEntryTable.Shrink();
813 }
814 }
815 }
816
817 void wxEventHashTable::AddEntry(const wxEventTableEntry &entry)
818 {
819 EventTypeTablePointer *peTTnode = &m_eventTypeTable[entry.m_eventType % m_size];
820 EventTypeTablePointer eTTnode = *peTTnode;
821
822 if (eTTnode)
823 {
824 if (eTTnode->eventType != entry.m_eventType)
825 {
826 // Resize the table!
827 GrowEventTypeTable();
828 // Try again to add it.
829 AddEntry(entry);
830 return;
831 }
832 }
833 else
834 {
835 eTTnode = new EventTypeTable;
836 eTTnode->eventType = entry.m_eventType;
837 *peTTnode = eTTnode;
838 }
839
840 // Fill all hash entries between entry.m_id and entry.m_lastId...
841 eTTnode->eventEntryTable.Add(&entry);
842 }
843
844 void wxEventHashTable::AllocEventTypeTable(size_t size)
845 {
846 m_eventTypeTable = new EventTypeTablePointer[size];
847 memset((void *)m_eventTypeTable, 0, sizeof(EventTypeTablePointer)*size);
848 m_size = size;
849 }
850
851 void wxEventHashTable::GrowEventTypeTable()
852 {
853 size_t oldSize = m_size;
854 EventTypeTablePointer *oldEventTypeTable = m_eventTypeTable;
855
856 // TODO: Search the most optimal grow sequence
857 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize*2+1);
858
859 for ( size_t i = 0; i < oldSize; /* */ )
860 {
861 EventTypeTablePointer eTToldNode = oldEventTypeTable[i];
862 if (eTToldNode)
863 {
864 EventTypeTablePointer *peTTnode = &m_eventTypeTable[eTToldNode->eventType % m_size];
865 EventTypeTablePointer eTTnode = *peTTnode;
866
867 // Check for collision, we don't want any.
868 if (eTTnode)
869 {
870 GrowEventTypeTable();
871 continue; // Don't increment the counter,
872 // as we still need to add this element.
873 }
874 else
875 {
876 // Get the old value and put it in the new table.
877 *peTTnode = oldEventTypeTable[i];
878 }
879 }
880
881 i++;
882 }
883
884 delete[] oldEventTypeTable;
885 }
886
887 // ----------------------------------------------------------------------------
888 // wxEvtHandler
889 // ----------------------------------------------------------------------------
890
891 #if wxUSE_BASE
892
893 /*
894 * Event handler
895 */
896
897 wxEvtHandler::wxEvtHandler()
898 {
899 m_nextHandler = (wxEvtHandler *) NULL;
900 m_previousHandler = (wxEvtHandler *) NULL;
901 m_enabled = TRUE;
902 m_dynamicEvents = (wxList *) NULL;
903 m_pendingEvents = (wxList *) NULL;
904 #if wxUSE_THREADS
905 # if !defined(__VISAGECPP__)
906 m_eventsLocker = new wxCriticalSection;
907 # endif
908 #endif
909 // no client data (yet)
910 m_clientData = NULL;
911 m_clientDataType = wxClientData_None;
912 }
913
914 wxEvtHandler::~wxEvtHandler()
915 {
916 // Takes itself out of the list of handlers
917 if (m_previousHandler)
918 m_previousHandler->m_nextHandler = m_nextHandler;
919
920 if (m_nextHandler)
921 m_nextHandler->m_previousHandler = m_previousHandler;
922
923 if (m_dynamicEvents)
924 {
925 wxList::iterator it = m_dynamicEvents->begin(),
926 en = m_dynamicEvents->end();
927 for (;it != en; ++it)
928 {
929 #if WXWIN_COMPATIBILITY_EVENT_TYPES
930 wxEventTableEntry *entry = (wxEventTableEntry*)*it;
931 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
932 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)*it;
933 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
934
935 if (entry->m_callbackUserData)
936 delete entry->m_callbackUserData;
937 delete entry;
938 }
939 delete m_dynamicEvents;
940 };
941
942 delete m_pendingEvents;
943
944 #if wxUSE_THREADS
945 # if !defined(__VISAGECPP__)
946 delete m_eventsLocker;
947 # endif
948
949 // Remove us from wxPendingEvents if necessary.
950 if(wxPendingEventsLocker)
951 wxENTER_CRIT_SECT(*wxPendingEventsLocker);
952 if ( wxPendingEvents ) {
953 wxPendingEvents->DeleteObject(this);
954 }
955 if(wxPendingEventsLocker)
956 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker);
957 #endif
958
959 // we only delete object data, not untyped
960 if ( m_clientDataType == wxClientData_Object )
961 delete m_clientObject;
962 }
963
964 #if wxUSE_THREADS
965
966 bool wxEvtHandler::ProcessThreadEvent(wxEvent& event)
967 {
968 // check that we are really in a child thread
969 wxASSERT_MSG( !wxThread::IsMain(),
970 wxT("use ProcessEvent() in main thread") );
971
972 AddPendingEvent(event);
973
974 return TRUE;
975 }
976
977 #endif // wxUSE_THREADS
978
979 void wxEvtHandler::AddPendingEvent(wxEvent& event)
980 {
981 // 1) Add event to list of pending events of this event handler
982
983 wxEvent *eventCopy = event.Clone();
984
985 // we must be able to copy the events here so the event class must
986 // implement Clone() properly instead of just providing a NULL stab for it
987 wxCHECK_RET( eventCopy,
988 _T("events of this type aren't supposed to be posted") );
989
990 #if defined(__VISAGECPP__)
991 wxENTER_CRIT_SECT( m_eventsLocker);
992 #else
993 wxENTER_CRIT_SECT( *m_eventsLocker);
994 #endif
995
996 if ( !m_pendingEvents )
997 m_pendingEvents = new wxList;
998
999 m_pendingEvents->Append(eventCopy);
1000
1001 #if defined(__VISAGECPP__)
1002 wxLEAVE_CRIT_SECT( m_eventsLocker);
1003 #else
1004 wxLEAVE_CRIT_SECT( *m_eventsLocker);
1005 #endif
1006
1007 // 2) Add this event handler to list of event handlers that
1008 // have pending events.
1009
1010 wxENTER_CRIT_SECT(*wxPendingEventsLocker);
1011
1012 if ( !wxPendingEvents )
1013 wxPendingEvents = new wxList;
1014 wxPendingEvents->Append(this);
1015
1016 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker);
1017
1018 // 3) Inform the system that new pending events are somwehere,
1019 // and that these should be processed in idle time.
1020 wxWakeUpIdle();
1021 }
1022
1023 void wxEvtHandler::ProcessPendingEvents()
1024 {
1025 #if defined(__VISAGECPP__)
1026 wxENTER_CRIT_SECT( m_eventsLocker);
1027 #else
1028 wxENTER_CRIT_SECT( *m_eventsLocker);
1029 #endif
1030
1031 wxList::compatibility_iterator node = m_pendingEvents->GetFirst();
1032 while ( node )
1033 {
1034 wxEvent *event = (wxEvent *)node->GetData();
1035 m_pendingEvents->Erase(node);
1036
1037 // In ProcessEvent, new events might get added and
1038 // we can safely leave the crtical section here.
1039 #if defined(__VISAGECPP__)
1040 wxLEAVE_CRIT_SECT( m_eventsLocker);
1041 #else
1042 wxLEAVE_CRIT_SECT( *m_eventsLocker);
1043 #endif
1044 ProcessEvent(*event);
1045 delete event;
1046 #if defined(__VISAGECPP__)
1047 wxENTER_CRIT_SECT( m_eventsLocker);
1048 #else
1049 wxENTER_CRIT_SECT( *m_eventsLocker);
1050 #endif
1051
1052 node = m_pendingEvents->GetFirst();
1053 }
1054
1055 #if defined(__VISAGECPP__)
1056 wxLEAVE_CRIT_SECT( m_eventsLocker);
1057 #else
1058 wxLEAVE_CRIT_SECT( *m_eventsLocker);
1059 #endif
1060 }
1061
1062 /*
1063 * Event table stuff
1064 */
1065
1066 bool wxEvtHandler::TryParent(wxEvent& event)
1067 {
1068 if ( wxTheApp && (this != wxTheApp) )
1069 {
1070 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1071 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1072 // processed appropriately via SearchEventTable.
1073 if ( event.GetEventType() != wxEVT_IDLE )
1074 {
1075 if ( wxTheApp->ProcessEvent(event) )
1076 return TRUE;
1077 }
1078 }
1079
1080 return FALSE;
1081 }
1082
1083 bool wxEvtHandler::ProcessEvent(wxEvent& event)
1084 {
1085 // allow the application to hook into event processing
1086 if ( wxTheApp )
1087 {
1088 int rc = wxTheApp->FilterEvent(event);
1089 if ( rc != -1 )
1090 {
1091 wxASSERT_MSG( rc == 1 || rc == 0,
1092 _T("unexpected wxApp::FilterEvent return value") );
1093
1094 return rc != 0;
1095 }
1096 //else: proceed normally
1097 }
1098
1099 // An event handler can be enabled or disabled
1100 if ( GetEvtHandlerEnabled() )
1101 {
1102 // if we have a validator, it has higher priority than our own event
1103 // table
1104 #if wxUSE_VALIDATORS
1105 if ( TryValidator(event) )
1106 return TRUE;
1107 #endif // wxUSE_VALIDATORS
1108
1109 // Handle per-instance dynamic event tables first
1110 if ( m_dynamicEvents && SearchDynamicEventTable(event) )
1111 return TRUE;
1112
1113 // Then static per-class event tables
1114 if ( GetEventHashTable().HandleEvent(event, this) )
1115 return TRUE;
1116 }
1117
1118 // Try going down the event handler chain
1119 if ( GetNextHandler() )
1120 {
1121 if ( GetNextHandler()->ProcessEvent(event) )
1122 return TRUE;
1123 }
1124
1125 // Finally propagate the event upwards the window chain and/or to the
1126 // application object as necessary
1127 return TryParent(event);
1128 }
1129
1130
1131 bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
1132 {
1133 wxEventType eventType = event.GetEventType();
1134 int eventId = event.GetId();
1135
1136 // BC++ doesn't like testing for m_fn without != 0
1137 for ( int i = 0; table.entries[i].m_fn != 0; i++ )
1138 {
1139 // the line using reference exposes a bug in gcc: although it _seems_
1140 // to work, it leads to weird crashes later on during program
1141 // execution
1142 #ifdef __GNUG__
1143 wxEventTableEntry entry = table.entries[i];
1144 #else
1145 const wxEventTableEntry& entry = table.entries[i];
1146 #endif
1147
1148 // match only if the event type is the same and the id is either -1 in
1149 // the event table (meaning "any") or the event id matches the id
1150 // specified in the event table either exactly or by falling into
1151 // range between first and last
1152 if ( eventType == entry.m_eventType )
1153 {
1154 int tableId1 = entry.m_id,
1155 tableId2 = entry.m_lastId;
1156
1157 if ( (tableId1 == -1) ||
1158 (tableId2 == -1 && eventId == tableId1) ||
1159 (tableId2 != -1 &&
1160 (eventId >= tableId1 && eventId <= tableId2)) )
1161 {
1162 event.Skip(FALSE);
1163 event.m_callbackUserData = entry.m_callbackUserData;
1164
1165 (this->*((wxEventFunction) (entry.m_fn)))(event);
1166
1167 return !event.GetSkipped();
1168 }
1169 }
1170 }
1171
1172 return FALSE;
1173 }
1174
1175 void wxEvtHandler::Connect( int id, int lastId,
1176 int eventType,
1177 wxObjectEventFunction func,
1178 wxObject *userData,
1179 wxEvtHandler* eventSink )
1180 {
1181 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1182 wxEventTableEntry *entry = new wxEventTableEntry;
1183 entry->m_eventType = eventType;
1184 entry->m_id = id;
1185 entry->m_lastId = lastId;
1186 entry->m_fn = func;
1187 entry->m_callbackUserData = userData;
1188 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1189 wxDynamicEventTableEntry *entry =
1190 new wxDynamicEventTableEntry(eventType, id, lastId, func, userData, eventSink);
1191 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1192
1193 if (!m_dynamicEvents)
1194 m_dynamicEvents = new wxList;
1195
1196 // Insert at the front of the list so most recent additions are found first
1197 m_dynamicEvents->Insert( (wxObject*) entry );
1198 }
1199
1200 bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType,
1201 wxObjectEventFunction func,
1202 wxObject *userData,
1203 wxEvtHandler* eventSink )
1204 {
1205 if (!m_dynamicEvents)
1206 return FALSE;
1207
1208 wxList::compatibility_iterator node = m_dynamicEvents->GetFirst();
1209 while (node)
1210 {
1211 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1212 wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData();
1213 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1214 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
1215 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1216
1217 if ((entry->m_id == id) &&
1218 ((entry->m_lastId == lastId) || (lastId == -1)) &&
1219 ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) &&
1220 ((entry->m_fn == func) || (func == (wxObjectEventFunction)NULL)) &&
1221 ((entry->m_eventSink == eventSink) || (eventSink == (wxEvtHandler*)NULL)) &&
1222 ((entry->m_callbackUserData == userData) || (userData == (wxObject*)NULL)))
1223 {
1224 if (entry->m_callbackUserData)
1225 delete entry->m_callbackUserData;
1226 m_dynamicEvents->Erase( node );
1227 delete entry;
1228 return TRUE;
1229 }
1230 node = node->GetNext();
1231 }
1232 return FALSE;
1233 }
1234
1235 bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
1236 {
1237 wxCHECK_MSG( m_dynamicEvents, FALSE,
1238 wxT("caller should check that we have dynamic events") );
1239
1240 int commandId = event.GetId();
1241
1242 wxList::compatibility_iterator node = m_dynamicEvents->GetFirst();
1243 while (node)
1244 {
1245 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1246 wxEventTableEntry *entry = (wxEventTableEntry*)node->GetData();
1247 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1248 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData();
1249 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1250
1251 if (entry->m_fn)
1252 {
1253 // Match, if event spec says any id will do (id == -1)
1254 if ( (event.GetEventType() == entry->m_eventType) &&
1255 (entry->m_id == -1 ||
1256 (entry->m_lastId == -1 && commandId == entry->m_id) ||
1257 (entry->m_lastId != -1 &&
1258 (commandId >= entry->m_id && commandId <= entry->m_lastId))) )
1259 {
1260 event.Skip(FALSE);
1261 event.m_callbackUserData = entry->m_callbackUserData;
1262
1263 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
1264 if (entry->m_eventSink)
1265 ((entry->m_eventSink)->*((wxEventFunction) (entry->m_fn)))(event);
1266 else
1267 #endif
1268 (this->*((wxEventFunction) (entry->m_fn)))(event);
1269
1270 if ( ! event.GetSkipped() )
1271 return TRUE;
1272 }
1273 }
1274 node = node->GetNext();
1275 }
1276 return FALSE;
1277 };
1278
1279 void wxEvtHandler::DoSetClientObject( wxClientData *data )
1280 {
1281 wxASSERT_MSG( m_clientDataType != wxClientData_Void,
1282 wxT("can't have both object and void client data") );
1283
1284 if ( m_clientObject )
1285 delete m_clientObject;
1286
1287 m_clientObject = data;
1288 m_clientDataType = wxClientData_Object;
1289 }
1290
1291 wxClientData *wxEvtHandler::DoGetClientObject() const
1292 {
1293 // it's not an error to call GetClientObject() on a window which doesn't
1294 // have client data at all - NULL will be returned
1295 wxASSERT_MSG( m_clientDataType != wxClientData_Void,
1296 wxT("this window doesn't have object client data") );
1297
1298 return m_clientObject;
1299 }
1300
1301 void wxEvtHandler::DoSetClientData( void *data )
1302 {
1303 wxASSERT_MSG( m_clientDataType != wxClientData_Object,
1304 wxT("can't have both object and void client data") );
1305
1306 m_clientData = data;
1307 m_clientDataType = wxClientData_Void;
1308 }
1309
1310 void *wxEvtHandler::DoGetClientData() const
1311 {
1312 // it's not an error to call GetClientData() on a window which doesn't have
1313 // client data at all - NULL will be returned
1314 wxASSERT_MSG( m_clientDataType != wxClientData_Object,
1315 wxT("this window doesn't have void client data") );
1316
1317 return m_clientData;
1318 }
1319
1320
1321 #if WXWIN_COMPATIBILITY
1322 bool wxEvtHandler::OnClose()
1323 {
1324 if (GetNextHandler())
1325 return GetNextHandler()->OnClose();
1326 else
1327 return FALSE;
1328 }
1329 #endif // WXWIN_COMPATIBILITY
1330
1331 #endif // wxUSE_BASE
1332
1333 #if wxUSE_GUI
1334
1335 // Find a window with the focus, that is also a descendant of the given window.
1336 // This is used to determine the window to initially send commands to.
1337 wxWindow* wxFindFocusDescendant(wxWindow* ancestor)
1338 {
1339 // Process events starting with the window with the focus, if any.
1340 wxWindow* focusWin = wxWindow::FindFocus();
1341 wxWindow* win = focusWin;
1342
1343 // Check if this is a descendant of this frame.
1344 // If not, win will be set to NULL.
1345 while (win)
1346 {
1347 if (win == ancestor)
1348 break;
1349 else
1350 win = win->GetParent();
1351 }
1352 if (win == (wxWindow*) NULL)
1353 focusWin = (wxWindow*) NULL;
1354
1355 return focusWin;
1356 }
1357
1358 #endif // wxUSE_GUI