/[pcsx2_0.9.7]/trunk/3rdparty/wxWidgets/src/common/event.cpp
ViewVC logotype

Annotation of /trunk/3rdparty/wxWidgets/src/common/event.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22