X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/886dd7d28e50c003cc88b81b968d487a3c17b0d7..5b36366c59ea68056ba07a3ca1c2cd6022a59735:/include/wx/event.h diff --git a/include/wx/event.h b/include/wx/event.h index 5209d9cb9a..a4d7b5685a 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -9,8 +9,8 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef _WX_EVENTH__ -#define _WX_EVENTH__ +#ifndef _WX_EVENT_H__ +#define _WX_EVENT_H__ #if defined(__GNUG__) && !defined(__APPLE__) #pragma interface "event.h" @@ -27,16 +27,18 @@ #include "wx/thread.h" +#include "wx/dynarray.h" + // ---------------------------------------------------------------------------- // forward declarations // ---------------------------------------------------------------------------- -class WXDLLEXPORT_BASE wxList; +class WXDLLIMPEXP_BASE wxList; #if wxUSE_GUI - class WXDLLEXPORT_CORE wxDC; - class WXDLLEXPORT_CORE wxMenu; - class WXDLLEXPORT_CORE wxWindow; + class WXDLLIMPEXP_CORE wxDC; + class WXDLLIMPEXP_CORE wxMenu; + class WXDLLIMPEXP_CORE wxWindow; #endif // wxUSE_GUI // ---------------------------------------------------------------------------- @@ -86,19 +88,21 @@ typedef int wxEventType; #define DECLARE_EVENT_TABLE_ENTRY(type, winid, idLast, fn, obj) \ wxEventTableEntry(type, winid, idLast, fn, obj) +#define EMPTY_PARAMETER_VALUE /* Fake macro parameter value */ + #define BEGIN_DECLARE_EVENT_TYPES() #define END_DECLARE_EVENT_TYPES() #define DECLARE_EXPORTED_EVENT_TYPE(expdecl, name, value) \ extern expdecl const wxEventType name; #define DECLARE_EVENT_TYPE(name, value) \ - DECLARE_EXPORTED_EVENT_TYPE(WXDLLEXPORT_CORE, name, value) + DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE, name, value) #define DECLARE_LOCAL_EVENT_TYPE(name, value) \ - DECLARE_EXPORTED_EVENT_TYPE(/* */, name, value) + DECLARE_EXPORTED_EVENT_TYPE(EMPTY_PARAMETER_VALUE, name, value) #define DEFINE_EVENT_TYPE(name) const wxEventType name = wxNewEventType(); #define DEFINE_LOCAL_EVENT_TYPE(name) DEFINE_EVENT_TYPE(name) // generate a new unique event type -extern WXDLLEXPORT_BASE wxEventType wxNewEventType(); +extern WXDLLIMPEXP_BASE wxEventType wxNewEventType(); #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES @@ -111,9 +115,9 @@ BEGIN_DECLARE_EVENT_TYPES() #else // !WXWIN_COMPATIBILITY_EVENT_TYPES // it is important to still have these as constants to avoid // initialization order related problems - DECLARE_EXPORTED_EVENT_TYPE(WXDLLEXPORT_BASE, wxEVT_NULL, 0) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLEXPORT_BASE, wxEVT_FIRST, 10000) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLEXPORT_BASE, wxEVT_USER_FIRST, wxEVT_FIRST + 2000) + DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_BASE, wxEVT_NULL, 0) + DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_BASE, wxEVT_FIRST, 10000) + DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_BASE, wxEVT_USER_FIRST, wxEVT_FIRST + 2000) #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES DECLARE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED, 1) @@ -145,7 +149,7 @@ BEGIN_DECLARE_EVENT_TYPES() DECLARE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED, 18) // Sockets and timers send events, too - DECLARE_EXPORTED_EVENT_TYPE(WXDLLEXPORT_BASE, wxEVT_SOCKET, 50) + DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_BASE, wxEVT_SOCKET, 50) DECLARE_EVENT_TYPE(wxEVT_TIMER , 80) // Mouse event types @@ -186,7 +190,9 @@ BEGIN_DECLARE_EVENT_TYPES() DECLARE_EVENT_TYPE(wxEVT_NAVIGATION_KEY, 214) DECLARE_EVENT_TYPE(wxEVT_KEY_DOWN, 215) DECLARE_EVENT_TYPE(wxEVT_KEY_UP, 216) - +#if wxUSE_HOTKEY + DECLARE_EVENT_TYPE(wxEVT_HOTKEY, 217) +#endif // Set cursor event DECLARE_EVENT_TYPE(wxEVT_SET_CURSOR, 230) @@ -249,7 +255,7 @@ BEGIN_DECLARE_EVENT_TYPES() DECLARE_EVENT_TYPE(wxEVT_MEASURE_ITEM, 436) DECLARE_EVENT_TYPE(wxEVT_COMPARE_ITEM, 437) DECLARE_EVENT_TYPE(wxEVT_INIT_DIALOG, 438) - DECLARE_EXPORTED_EVENT_TYPE(WXDLLEXPORT_BASE, wxEVT_IDLE, 439) + DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_BASE, wxEVT_IDLE, 439) DECLARE_EVENT_TYPE(wxEVT_UPDATE_UI, 440) DECLARE_EVENT_TYPE(wxEVT_SIZING, 441) DECLARE_EVENT_TYPE(wxEVT_MOVING, 4442) @@ -282,7 +288,7 @@ END_DECLARE_EVENT_TYPES() // // still, any new code using it should include wx/textctrl.h explicitly #if !WXWIN_COMPATIBILITY_EVENT_TYPES - extern const wxEventType WXDLLEXPORT_CORE wxEVT_COMMAND_TEXT_UPDATED; + extern const wxEventType WXDLLIMPEXP_CORE wxEVT_COMMAND_TEXT_UPDATED; #endif #if WXWIN_COMPATIBILITY @@ -329,6 +335,17 @@ END_DECLARE_EVENT_TYPES() #endif // WXWIN_COMPATIBILITY +// the predefined constants for the number of times we propagate event +// upwards window child-parent chain +enum Propagation_state +{ + // don't propagate it at all + wxEVENT_PROPAGATE_NONE = 0, + + // propagate it until it is processed + wxEVENT_PROPAGATE_MAX = INT_MAX +}; + /* * wxWindows events, covering all interesting things that might happen * (button clicking, resizing, setting text in widgets, etc.). @@ -341,7 +358,7 @@ END_DECLARE_EVENT_TYPES() * */ -class WXDLLEXPORT_BASE wxEvent : public wxObject +class WXDLLIMPEXP_BASE wxEvent : public wxObject { private: wxEvent& operator=(const wxEvent&); @@ -368,30 +385,108 @@ public: void Skip(bool skip = TRUE) { m_skipped = skip; } bool GetSkipped() const { return m_skipped; }; - // Implementation only: this test is explicitlty anti OO and this functions - // exists only for optimization purposes. - bool IsCommandEvent() const { return m_isCommandEvent; } - // this function is used to create a copy of the event polymorphically and // all derived classes must implement it because otherwise wxPostEvent() // for them wouldn't work (it needs to do a copy of the event) virtual wxEvent *Clone() const = 0; + // Implementation only: this test is explicitlty anti OO and this functions + // exists only for optimization purposes. + bool IsCommandEvent() const { return m_isCommandEvent; } + + // Determine if this event should be propagating to the parent window. + bool ShouldPropagate() const + { return m_propagationLevel != wxEVENT_PROPAGATE_NONE; } + + // Stop an event from propagating to its parent window, returns the old + // propagation level value + int StopPropagation() + { + int propagationLevel = m_propagationLevel; + m_propagationLevel = wxEVENT_PROPAGATE_NONE; + return propagationLevel; + } + + // Resume the event propagation by restoring the propagation level + // (returned by StopPropagation()) + void ResumePropagation(int propagationLevel) + { + m_propagationLevel = propagationLevel; + } + public: wxObject* m_eventObject; wxEventType m_eventType; long m_timeStamp; int m_id; wxObject* m_callbackUserData; + +protected: + // the propagation level: while it is positive, we propagate the event to + // the parent window (if any) + // + // this one doesn't have to be public, we don't have to worry about + // backwards compatibility as it is new + int m_propagationLevel; + +public: bool m_skipped; bool m_isCommandEvent; - + private: + // it needs to access our m_propagationLevel + friend class WXDLLIMPEXP_BASE wxPropagateOnce; + DECLARE_ABSTRACT_CLASS(wxEvent) }; +/* + * Helper class to temporarily change an event not to propagate. + */ +class WXDLLIMPEXP_BASE wxPropagationDisabler +{ +public: + wxPropagationDisabler(wxEvent& event) : m_event(event) + { + m_propagationLevelOld = m_event.StopPropagation(); + } + + ~wxPropagationDisabler() + { + m_event.ResumePropagation(m_propagationLevelOld); + } + +private: + wxEvent& m_event; + int m_propagationLevelOld; +}; + +/* + * Another one to temporarily lower propagation level. + */ +class WXDLLIMPEXP_BASE wxPropagateOnce +{ +public: + wxPropagateOnce(wxEvent& event) : m_event(event) + { + wxASSERT_MSG( m_event.m_propagationLevel > 0, + _T("shouldn't be used unless ShouldPropagate()!") ); + + m_event.m_propagationLevel--; + } + + ~wxPropagateOnce() + { + m_event.m_propagationLevel++; + } + +private: + wxEvent& m_event; +}; + #if wxUSE_GUI + // Item or menu event class /* wxEVT_COMMAND_BUTTON_CLICKED @@ -411,7 +506,7 @@ private: wxEVT_COMMAND_TOGGLEBUTTON_CLICKED */ -class WXDLLEXPORT_CORE wxCommandEvent : public wxEvent +class WXDLLIMPEXP_CORE wxCommandEvent : public wxEvent { private: wxCommandEvent& operator=(const wxCommandEvent& event); @@ -474,7 +569,7 @@ private: // this class adds a possibility to react (from the user) code to a control // notification: allow or veto the operation being reported. -class WXDLLEXPORT_CORE wxNotifyEvent : public wxCommandEvent +class WXDLLIMPEXP_CORE wxNotifyEvent : public wxCommandEvent { public: wxNotifyEvent(wxEventType commandType = wxEVT_NULL, int winid = 0) @@ -517,7 +612,7 @@ private: wxEVT_SCROLL_ENDSCROLL */ -class WXDLLEXPORT_CORE wxScrollEvent : public wxCommandEvent +class WXDLLIMPEXP_CORE wxScrollEvent : public wxCommandEvent { public: wxScrollEvent(wxEventType commandType = wxEVT_NULL, @@ -547,7 +642,7 @@ private: wxEVT_SCROLLWIN_THUMBRELEASE */ -class WXDLLEXPORT_CORE wxScrollWinEvent : public wxEvent +class WXDLLIMPEXP_CORE wxScrollWinEvent : public wxEvent { public: wxScrollWinEvent(wxEventType commandType = wxEVT_NULL, @@ -610,7 +705,7 @@ enum wxMOUSE_BTN_RIGHT = 2 }; -class WXDLLEXPORT_CORE wxMouseEvent : public wxEvent +class WXDLLIMPEXP_CORE wxMouseEvent : public wxEvent { public: wxMouseEvent(wxEventType mouseType = wxEVT_NULL); @@ -780,7 +875,7 @@ private: wxEVT_SET_CURSOR */ -class WXDLLEXPORT_CORE wxSetCursorEvent : public wxEvent +class WXDLLIMPEXP_CORE wxSetCursorEvent : public wxEvent { public: wxSetCursorEvent(wxCoord x = 0, wxCoord y = 0) @@ -819,9 +914,10 @@ private: wxEVT_CHAR_HOOK wxEVT_KEY_DOWN wxEVT_KEY_UP + wxEVT_HOTKEY */ -class WXDLLEXPORT_CORE wxKeyEvent : public wxEvent +class WXDLLIMPEXP_CORE wxKeyEvent : public wxEvent { public: wxKeyEvent(wxEventType keyType = wxEVT_NULL); @@ -927,7 +1023,7 @@ private: wxEVT_SIZE */ -class WXDLLEXPORT_CORE wxSizeEvent : public wxEvent +class WXDLLIMPEXP_CORE wxSizeEvent : public wxEvent { public: wxSizeEvent() : wxEvent(0, wxEVT_SIZE) @@ -964,7 +1060,7 @@ private: wxEVT_MOVE */ -class WXDLLEXPORT_CORE wxMoveEvent : public wxEvent +class WXDLLIMPEXP_CORE wxMoveEvent : public wxEvent { public: wxMoveEvent() @@ -1004,10 +1100,10 @@ private: #if defined(__WXDEBUG__) && (defined(__WXMSW__) || defined(__WXPM__)) // see comments in src/msw|os2/dcclient.cpp where g_isPainting is defined - extern WXDLLEXPORT_CORE int g_isPainting; + extern WXDLLIMPEXP_CORE int g_isPainting; #endif // debug -class WXDLLEXPORT_CORE wxPaintEvent : public wxEvent +class WXDLLIMPEXP_CORE wxPaintEvent : public wxEvent { public: wxPaintEvent(int Id = 0) @@ -1032,7 +1128,7 @@ private: DECLARE_DYNAMIC_CLASS(wxPaintEvent) }; -class WXDLLEXPORT_CORE wxNcPaintEvent : public wxEvent +class WXDLLIMPEXP_CORE wxNcPaintEvent : public wxEvent { public: wxNcPaintEvent(int winid = 0) @@ -1050,7 +1146,7 @@ private: wxEVT_ERASE_BACKGROUND */ -class WXDLLEXPORT_CORE wxEraseEvent : public wxEvent +class WXDLLIMPEXP_CORE wxEraseEvent : public wxEvent { private: wxEraseEvent& operator=(const wxEraseEvent& event); @@ -1082,7 +1178,7 @@ private: wxEVT_KILL_FOCUS */ -class WXDLLEXPORT_CORE wxFocusEvent : public wxEvent +class WXDLLIMPEXP_CORE wxFocusEvent : public wxEvent { private: wxFocusEvent& operator=(const wxFocusEvent& event); @@ -1112,8 +1208,8 @@ private: }; // wxChildFocusEvent notifies the parent that a child has got the focus: unlike -// wxFocusEvent it is propgated upwards the window chain -class WXDLLEXPORT_CORE wxChildFocusEvent : public wxCommandEvent +// wxFocusEvent it is propagated upwards the window chain +class WXDLLIMPEXP_CORE wxChildFocusEvent : public wxCommandEvent { public: wxChildFocusEvent(wxWindow *win = NULL); @@ -1132,7 +1228,7 @@ private: wxEVT_ACTIVATE_APP */ -class WXDLLEXPORT_CORE wxActivateEvent : public wxEvent +class WXDLLIMPEXP_CORE wxActivateEvent : public wxEvent { public: wxActivateEvent(wxEventType type = wxEVT_NULL, bool active = TRUE, int Id = 0) @@ -1158,7 +1254,7 @@ private: wxEVT_INIT_DIALOG */ -class WXDLLEXPORT_CORE wxInitDialogEvent : public wxEvent +class WXDLLIMPEXP_CORE wxInitDialogEvent : public wxEvent { public: wxInitDialogEvent(int Id = 0) @@ -1178,15 +1274,15 @@ private: wxEVT_MENU_HIGHLIGHT, */ -class WXDLLEXPORT_CORE wxMenuEvent : public wxEvent +class WXDLLIMPEXP_CORE wxMenuEvent : public wxEvent { public: - wxMenuEvent(wxEventType type = wxEVT_NULL, int winid = 0) + wxMenuEvent(wxEventType type = wxEVT_NULL, int winid = 0, wxMenu* menu = NULL) : wxEvent(winid, type) - { m_menuId = winid; } + { m_menuId = winid; m_menu = NULL; } wxMenuEvent(const wxMenuEvent & event) : wxEvent(event) - { m_menuId = event.m_menuId; } + { m_menuId = event.m_menuId; m_menu = event.m_menu; } // only for wxEVT_MENU_HIGHLIGHT int GetMenuId() const { return m_menuId; } @@ -1194,10 +1290,14 @@ public: // only for wxEVT_MENU_OPEN/CLOSE bool IsPopup() const { return m_menuId == -1; } + // only for wxEVT_MENU_OPEN/CLOSE + wxMenu* GetMenu() const { return m_menu; } + virtual wxEvent *Clone() const { return new wxMenuEvent(*this); } private: - int m_menuId; + int m_menuId; + wxMenu* m_menu; DECLARE_DYNAMIC_CLASS(wxMenuEvent) }; @@ -1209,7 +1309,7 @@ private: wxEVT_QUERY_END_SESSION */ -class WXDLLEXPORT_CORE wxCloseEvent : public wxEvent +class WXDLLIMPEXP_CORE wxCloseEvent : public wxEvent { public: wxCloseEvent(wxEventType type = wxEVT_NULL, int winid = 0) @@ -1276,7 +1376,7 @@ private: wxEVT_SHOW */ -class WXDLLEXPORT_CORE wxShowEvent : public wxEvent +class WXDLLIMPEXP_CORE wxShowEvent : public wxEvent { public: wxShowEvent(int winid = 0, bool show = FALSE) @@ -1302,7 +1402,7 @@ private: wxEVT_ICONIZE */ -class WXDLLEXPORT_CORE wxIconizeEvent : public wxEvent +class WXDLLIMPEXP_CORE wxIconizeEvent : public wxEvent { public: wxIconizeEvent(int winid = 0, bool iconized = TRUE) @@ -1327,7 +1427,7 @@ private: wxEVT_MAXIMIZE */ -class WXDLLEXPORT_CORE wxMaximizeEvent : public wxEvent +class WXDLLIMPEXP_CORE wxMaximizeEvent : public wxEvent { public: wxMaximizeEvent(int winid = 0) @@ -1365,7 +1465,7 @@ enum wxJOY_BUTTON4 = 8 }; -class WXDLLEXPORT_CORE wxJoystickEvent : public wxEvent +class WXDLLIMPEXP_CORE wxJoystickEvent : public wxEvent { public: wxPoint m_pos; @@ -1443,7 +1543,7 @@ private: wxEVT_DROP_FILES */ -class WXDLLEXPORT_CORE wxDropFilesEvent : public wxEvent +class WXDLLIMPEXP_CORE wxDropFilesEvent : public wxEvent { private: wxDropFilesEvent& operator=(const wxDropFilesEvent& event); @@ -1496,7 +1596,21 @@ private: wxEVT_UPDATE_UI */ -class WXDLLEXPORT_CORE wxUpdateUIEvent : public wxCommandEvent +// Whether to always send update events to windows, or +// to only send update events to those with the +// wxWS_EX_PROCESS_UI_UPDATES style. + +enum wxUpdateUIMode +{ + // Send UI update events to all windows + wxUPDATE_UI_PROCESS_ALL, + + // Send UI update events to windows that have + // the wxWS_EX_PROCESS_UI_UPDATES flag specified + wxUPDATE_UI_PROCESS_SPECIFIED +}; + +class WXDLLIMPEXP_CORE wxUpdateUIEvent : public wxCommandEvent { public: wxUpdateUIEvent(wxWindowID commandId = 0) @@ -1529,6 +1643,28 @@ public: void Enable(bool enable) { m_enabled = enable; m_setEnabled = TRUE; } void SetText(const wxString& text) { m_text = text; m_setText = TRUE; } + // Sets the interval between updates in milliseconds. + // Set to -1 to disable updates, or to 0 to update as frequently as possible. + static void SetUpdateInterval(long updateInterval) { sm_updateInterval = updateInterval; } + + // Returns the current interval between updates in milliseconds + static long GetUpdateInterval() { return sm_updateInterval ; } + + // Can we update this window? + static bool CanUpdate(wxWindow* win) ; + + // Reset the update time to provide a delay until the next + // time we should update + static void ResetUpdateTime() ; + + // Specify how wxWindows will send update events: to + // all windows, or only to those which specify that they + // will process the events. + static void SetMode(wxUpdateUIMode mode) { sm_updateMode = mode; } + + // Returns the UI update mode + static wxUpdateUIMode GetMode() { return sm_updateMode ; } + virtual wxEvent *Clone() const { return new wxUpdateUIEvent(*this); } protected: @@ -1538,6 +1674,11 @@ protected: bool m_setText; bool m_setChecked; wxString m_text; +#if wxUSE_LONGLONG + static wxLongLong sm_lastUpdate; +#endif + static long sm_updateInterval; + static wxUpdateUIMode sm_updateMode; private: DECLARE_DYNAMIC_CLASS(wxUpdateUIEvent) @@ -1548,7 +1689,7 @@ private: */ // TODO: shouldn't all events record the window ID? -class WXDLLEXPORT_CORE wxSysColourChangedEvent : public wxEvent +class WXDLLIMPEXP_CORE wxSysColourChangedEvent : public wxEvent { public: wxSysColourChangedEvent() @@ -1567,7 +1708,7 @@ private: (even if it released the capture itself). */ -class WXDLLEXPORT_CORE wxMouseCaptureChangedEvent : public wxEvent +class WXDLLIMPEXP_CORE wxMouseCaptureChangedEvent : public wxEvent { private: wxMouseCaptureChangedEvent operator=(const wxMouseCaptureChangedEvent& event); @@ -1595,7 +1736,7 @@ private: /* wxEVT_DISPLAY_CHANGED */ -class WXDLLEXPORT_CORE wxDisplayChangedEvent : public wxEvent +class WXDLLIMPEXP_CORE wxDisplayChangedEvent : public wxEvent { private: DECLARE_DYNAMIC_CLASS(wxDisplayChangedEvent) @@ -1612,7 +1753,7 @@ public: wxEVT_PALETTE_CHANGED */ -class WXDLLEXPORT_CORE wxPaletteChangedEvent : public wxEvent +class WXDLLIMPEXP_CORE wxPaletteChangedEvent : public wxEvent { private: wxPaletteChangedEvent& operator=(const wxPaletteChangedEvent& event); @@ -1645,7 +1786,7 @@ private: Indicates the window is getting keyboard focus and should re-do its palette. */ -class WXDLLEXPORT_CORE wxQueryNewPaletteEvent : public wxEvent +class WXDLLIMPEXP_CORE wxQueryNewPaletteEvent : public wxEvent { public: wxQueryNewPaletteEvent(wxWindowID winid = 0) @@ -1675,7 +1816,7 @@ private: wxEVT_NAVIGATION_KEY */ // NB: don't derive from command event to avoid being propagated to the parent -class WXDLLEXPORT_CORE wxNavigationKeyEvent : public wxEvent +class WXDLLIMPEXP_CORE wxNavigationKeyEvent : public wxEvent { private: wxNavigationKeyEvent& operator=(const wxNavigationKeyEvent& event); @@ -1746,7 +1887,7 @@ private: wxEVT_DESTROY */ -class WXDLLEXPORT_CORE wxWindowCreateEvent : public wxCommandEvent +class WXDLLIMPEXP_CORE wxWindowCreateEvent : public wxCommandEvent { public: wxWindowCreateEvent(wxWindow *win = NULL); @@ -1759,7 +1900,7 @@ private: DECLARE_DYNAMIC_CLASS(wxWindowCreateEvent) }; -class WXDLLEXPORT_CORE wxWindowDestroyEvent : public wxCommandEvent +class WXDLLIMPEXP_CORE wxWindowDestroyEvent : public wxCommandEvent { public: wxWindowDestroyEvent(wxWindow *win = NULL); @@ -1778,7 +1919,7 @@ private: wxEVT_DETAILED_HELP */ -class WXDLLEXPORT_CORE wxHelpEvent : public wxCommandEvent +class WXDLLIMPEXP_CORE wxHelpEvent : public wxCommandEvent { public: wxHelpEvent(wxEventType type = wxEVT_NULL, @@ -1825,7 +1966,7 @@ private: wxEVT_CONTEXT_MENU */ -class WXDLLEXPORT_CORE wxContextMenuEvent : public wxCommandEvent +class WXDLLIMPEXP_CORE wxContextMenuEvent : public wxCommandEvent { public: wxContextMenuEvent(wxEventType type = wxEVT_NULL, @@ -1857,7 +1998,21 @@ private: wxEVT_IDLE */ -class WXDLLEXPORT_CORE wxIdleEvent : public wxEvent +// Whether to always send idle events to windows, or +// to only send update events to those with the +// wxWS_EX_PROCESS_IDLE style. + +enum wxIdleMode +{ + // Send idle events to all windows + wxIDLE_PROCESS_ALL, + + // Send idle events to windows that have + // the wxWS_EX_PROCESS_IDLE flag specified + wxIDLE_PROCESS_SPECIFIED +}; + +class WXDLLIMPEXP_CORE wxIdleEvent : public wxEvent { public: wxIdleEvent() @@ -1874,8 +2029,20 @@ public: virtual wxEvent *Clone() const { return new wxIdleEvent(*this); } + // Specify how wxWindows will send idle events: to + // all windows, or only to those which specify that they + // will process the events. + static void SetMode(wxIdleMode mode) { sm_idleMode = mode; } + + // Returns the idle event mode + static wxIdleMode GetMode() { return sm_idleMode ; } + + // Can we send an idle event? + static bool CanSend(wxWindow* win) ; + protected: bool m_requestMore; + static wxIdleMode sm_idleMode; private: DECLARE_DYNAMIC_CLASS(wxIdleEvent) @@ -1906,7 +2073,7 @@ typedef void (wxObject::*wxObjectEventFunction)(wxEvent&); // we have to keep both versions #if WXWIN_COMPATIBILITY_EVENT_TYPES -struct WXDLLEXPORT_BASE wxEventTableEntry +struct WXDLLIMPEXP_BASE wxEventTableEntry { // For some reason, this can't be wxEventType, or VC++ complains. int m_eventType; // main event type @@ -1922,7 +2089,7 @@ struct WXDLLEXPORT_BASE wxEventTableEntry // struct containing the members common to static and dynamic event tables // entries -struct WXDLLEXPORT_BASE wxEventTableEntryBase +struct WXDLLIMPEXP_BASE wxEventTableEntryBase { private: wxEventTableEntryBase& operator=(const wxEventTableEntryBase& event); @@ -1956,7 +2123,7 @@ public: }; // an entry from a static event table -struct WXDLLEXPORT_BASE wxEventTableEntry : public wxEventTableEntryBase +struct WXDLLIMPEXP_BASE wxEventTableEntry : public wxEventTableEntryBase { wxEventTableEntry(const int& evType, int winid, int idLast, wxObjectEventFunction fn, wxObject *data) @@ -1973,10 +2140,10 @@ struct WXDLLEXPORT_BASE wxEventTableEntry : public wxEventTableEntryBase const int& m_eventType; }; -class WXDLLEXPORT_BASE wxEvtHandler; +class WXDLLIMPEXP_BASE wxEvtHandler; // an entry used in dynamic event table managed by wxEvtHandler::Connect() -struct WXDLLEXPORT_BASE wxDynamicEventTableEntry : public wxEventTableEntryBase +struct WXDLLIMPEXP_BASE wxDynamicEventTableEntry : public wxEventTableEntryBase { wxDynamicEventTableEntry(int evType, int winid, int idLast, wxObjectEventFunction fn, wxObject *data, wxEvtHandler* eventSink) @@ -2002,17 +2169,67 @@ struct WXDLLEXPORT_BASE wxDynamicEventTableEntry : public wxEventTableEntryBase // wxEventTable: an array of event entries terminated with {0, 0, 0, 0, 0} // ---------------------------------------------------------------------------- -struct WXDLLEXPORT_BASE wxEventTable +struct WXDLLIMPEXP_BASE wxEventTable { const wxEventTable *baseTable; // base event table (next in chain) const wxEventTableEntry *entries; // bottom of entry array }; +// ---------------------------------------------------------------------------- +// wxEventHashTable: a helper of wxEvtHandler to speed up wxEventTable lookups. +// ---------------------------------------------------------------------------- + +WX_DEFINE_ARRAY_NO_PTR(const wxEventTableEntry*, wxEventTableEntryPointerArray); +class WXDLLIMPEXP_BASE wxEvtHandler; + +class WXDLLIMPEXP_BASE wxEventHashTable +{ +private: + // Internal data structs + struct EventTypeTable + { + wxEventType eventType; + wxEventTableEntryPointerArray eventEntryTable; + }; + typedef EventTypeTable* EventTypeTablePointer; + +public: + // Constructor, needs the event table it needs to hash later on. + // Note: hashing of the event table is not done in the constructor as it + // can be that the event table is not yet full initialize, the hash + // will gets initialized when handling the first event look-up request. + wxEventHashTable(const wxEventTable &table); + // Destructor. + ~wxEventHashTable(); + + // Handle the given event, in other words search the event table hash + // and call self->ProcessEvent() if a match was found. + bool HandleEvent(wxEvent &event, wxEvtHandler *self); + +protected: + // Init the hash table with the entries of the static event table. + void InitHashTable(); + // Helper funtion of InitHashTable() to insert 1 entry into the hash table. + void AddEntry(const wxEventTableEntry &entry); + // Allocate and init with null pointers the base hash table. + void AllocEventTypeTable(size_t size); + // Grow the hash table in size and transfer all items currently + // in the table to the correct location in the new table. + void GrowEventTypeTable(); + +protected: + const wxEventTable &m_table; + bool m_rebuildHash; + + size_t m_size; + EventTypeTablePointer *m_eventTypeTable; +}; + // ---------------------------------------------------------------------------- // wxEvtHandler: the base class for all objects handling wxWindows events // ---------------------------------------------------------------------------- -class WXDLLEXPORT_BASE wxEvtHandler : public wxObject +class WXDLLIMPEXP_BASE wxEvtHandler : public wxObject { public: wxEvtHandler(); @@ -2127,10 +2344,12 @@ protected: virtual bool TryParent(wxEvent& event); - static const wxEventTable sm_eventTable; - + static const wxEventTable sm_eventTable; virtual const wxEventTable *GetEventTable() const; + static wxEventHashTable sm_eventHashTable; + virtual wxEventHashTable& GetEventHashTable() const; + wxEvtHandler* m_nextHandler; wxEvtHandler* m_previousHandler; wxList* m_dynamicEvents; @@ -2229,13 +2448,22 @@ typedef void (wxEvtHandler::*wxMouseCaptureChangedEventFunction)(wxMouseCaptureC static const wxEventTableEntry sm_eventTableEntries[]; \ protected: \ static const wxEventTable sm_eventTable; \ - virtual const wxEventTable* GetEventTable() const; + virtual const wxEventTable* GetEventTable() const; \ + static wxEventHashTable sm_eventHashTable; \ + virtual wxEventHashTable& GetEventHashTable() const; + +// N.B.: when building DLL with Borland C++ 5.5 compiler, you must initialize +// sm_eventTable before using it in GetEventTable() or the compiler gives +// E2233 (see http://groups.google.com/groups?selm=397dcc8a%241_2%40dnews) #define BEGIN_EVENT_TABLE(theClass, baseClass) \ - const wxEventTable *theClass::GetEventTable() const \ - { return &theClass::sm_eventTable; } \ const wxEventTable theClass::sm_eventTable = \ { &baseClass::sm_eventTable, &theClass::sm_eventTableEntries[0] }; \ + const wxEventTable *theClass::GetEventTable() const \ + { return &theClass::sm_eventTable; } \ + wxEventHashTable theClass::sm_eventHashTable(theClass::sm_eventTable); \ + wxEventHashTable &theClass::GetEventHashTable() const \ + { return theClass::sm_eventHashTable; } \ const wxEventTableEntry theClass::sm_eventTableEntries[] = { \ #define END_EVENT_TABLE() DECLARE_EVENT_TABLE_ENTRY( wxEVT_NULL, 0, 0, 0, 0 ) }; @@ -2262,6 +2490,9 @@ typedef void (wxEvtHandler::*wxMouseCaptureChangedEventFunction)(wxMouseCaptureC #define EVT_CHAR(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_CHAR, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxCharEventFunction) & func, (wxObject *) NULL ), #define EVT_KEY_DOWN(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_KEY_DOWN, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxCharEventFunction) & func, (wxObject *) NULL ), #define EVT_KEY_UP(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_KEY_UP, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxCharEventFunction) & func, (wxObject *) NULL ), +#if wxUSE_HOTKEY +#define EVT_HOTKEY(id, func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_HOTKEY, id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxCharEventFunction) & func, (wxObject *) NULL ), +#endif #define EVT_CHAR_HOOK(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_CHAR_HOOK, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxCharEventFunction) & func, NULL ), #define EVT_MENU_OPEN(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MENU_OPEN, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxMenuEventFunction) & func, (wxObject *) NULL ), #define EVT_MENU_CLOSE(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MENU_CLOSE, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxMenuEventFunction) & func, (wxObject *) NULL ), @@ -2476,9 +2707,9 @@ typedef void (wxEvtHandler::*wxMouseCaptureChangedEventFunction)(wxMouseCaptureC // for pending event processing - notice that there is intentionally no // WXDLLEXPORT here -extern WXDLLEXPORT_BASE wxList *wxPendingEvents; +extern WXDLLIMPEXP_BASE wxList *wxPendingEvents; #if wxUSE_THREADS - extern WXDLLEXPORT_BASE wxCriticalSection *wxPendingEventsLocker; + extern WXDLLIMPEXP_BASE wxCriticalSection *wxPendingEventsLocker; #endif // ---------------------------------------------------------------------------- @@ -2493,5 +2724,5 @@ wxWindow* wxFindFocusDescendant(wxWindow* ancestor); #endif // wxUSE_GUI -#endif - // _WX_EVENTH__ +#endif // _WX_EVENT_H__ +