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