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