X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b87654f3fd52a9b6c1ebf5a3ff57c85b6c5631d6..5357c8e8b3da95c225e686a195002df5712446b8:/include/wx/event.h diff --git a/include/wx/event.h b/include/wx/event.h index 5598cf8d25..900014b7d4 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -18,16 +18,29 @@ #include "wx/defs.h" #include "wx/object.h" -#include "wx/gdicmn.h" -#if wxUSE_THREADS - #include "wx/thread.h" +#if wxUSE_GUI + #include "wx/gdicmn.h" #endif -/* - * Event types - * - */ +#include "wx/thread.h" + +// ---------------------------------------------------------------------------- +// forward declarations +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxList; + +#if wxUSE_GUI + class WXDLLEXPORT wxClientData; + class WXDLLEXPORT wxDC; + class WXDLLEXPORT wxMenu; + class WXDLLEXPORT wxWindow; +#endif // wxUSE_GUI + +// ---------------------------------------------------------------------------- +// Event types +// ---------------------------------------------------------------------------- typedef int wxEventType; @@ -53,6 +66,7 @@ const wxEventType wxEVT_COMMAND_VLBOX_SELECTED = wxEVT_FIRST + 14; const wxEventType wxEVT_COMMAND_COMBOBOX_SELECTED = wxEVT_FIRST + 15; const wxEventType wxEVT_COMMAND_TOOL_RCLICKED = wxEVT_FIRST + 16; const wxEventType wxEVT_COMMAND_TOOL_ENTER = wxEVT_FIRST + 17; +const wxEventType wxEVT_COMMAND_SPINCTRL_UPDATED = wxEVT_FIRST + 18; /* Sockets send events, too */ const wxEventType wxEVT_SOCKET = wxEVT_FIRST + 50; @@ -191,6 +205,8 @@ const wxEventType wxEVT_COMMAND_TREE_SEL_CHANGED = wxEVT_FIRST + 611; const wxEventType wxEVT_COMMAND_TREE_SEL_CHANGING = wxEVT_FIRST + 612; const wxEventType wxEVT_COMMAND_TREE_KEY_DOWN = wxEVT_FIRST + 613; const wxEventType wxEVT_COMMAND_TREE_ITEM_ACTIVATED = wxEVT_FIRST + 614; +const wxEventType wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK = wxEVT_FIRST + 615; +const wxEventType wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK = wxEVT_FIRST + 616; /* List control event types */ const wxEventType wxEVT_COMMAND_LIST_BEGIN_DRAG = wxEVT_FIRST + 700; @@ -336,6 +352,8 @@ public: bool m_isCommandEvent; }; +#if wxUSE_GUI + // Item or menu event class /* wxEVT_COMMAND_BUTTON_CLICKED @@ -354,8 +372,6 @@ public: wxEVT_COMMAND_COMBOBOX_SELECTED */ -class WXDLLEXPORT wxClientData; - class WXDLLEXPORT wxCommandEvent : public wxEvent { DECLARE_DYNAMIC_CLASS(wxCommandEvent) @@ -491,7 +507,7 @@ public: void CopyObject(wxObject& object_dest) const; public: int m_commandInt; // Additional information - long m_extraLong; + long m_extraLong; }; // Mouse event class @@ -523,7 +539,6 @@ public: wxEVT_NC_RIGHT_DCLICK, */ -class WXDLLEXPORT wxDC; class WXDLLEXPORT wxMouseEvent : public wxEvent { DECLARE_DYNAMIC_CLASS(wxMouseEvent) @@ -591,8 +606,23 @@ public: bool Leaving() const { return (m_eventType == wxEVT_LEAVE_WINDOW); } // Find the position of the event - void GetPosition(long *xpos, long *ypos) const { *xpos = m_x; *ypos = m_y; } - void Position(long *xpos, long *ypos) const { *xpos = m_x; *ypos = m_y; } + void GetPosition(wxCoord *xpos, wxCoord *ypos) const + { + if (xpos) + *xpos = m_x; + if (ypos) + *ypos = m_y; + } + +#ifndef __WIN16__ + void GetPosition(long *xpos, long *ypos) const + { + if (xpos) + *xpos = (long)m_x; + if (ypos) + *ypos = (long)m_y; + } +#endif // Find the position of the event wxPoint GetPosition() const { return wxPoint(m_x, m_y); } @@ -602,6 +632,14 @@ public: // Compatibility #if WXWIN_COMPATIBILITY + void Position(long *xpos, long *ypos) const + { + if (xpos) + *xpos = (long)m_x; + if (ypos) + *ypos = (long)m_y; + } + void Position(float *xpos, float *ypos) const { *xpos = (float) m_x; *ypos = (float) m_y; @@ -617,8 +655,8 @@ public: void CopyObject(wxObject& obj) const; public: - long m_x; - long m_y; + wxCoord m_x, m_y; + bool m_leftDown; bool m_middleDown; bool m_rightDown; @@ -653,24 +691,36 @@ public: long KeyCode() const { return m_keyCode; } // Find the position of the event + void GetPosition(wxCoord *xpos, wxCoord *ypos) const + { + if (xpos) *xpos = m_x; + if (ypos) *ypos = m_y; + } + +#ifndef __WIN16__ void GetPosition(long *xpos, long *ypos) const - { *xpos = m_x; *ypos = m_y; } + { + if (xpos) *xpos = (long)m_x; + if (ypos) *ypos = (long)m_y; + } +#endif wxPoint GetPosition() const { return wxPoint(m_x, m_y); } // Get X position - long GetX() const { return m_x; } + wxCoord GetX() const { return m_x; } // Get Y position - long GetY() const { return m_y; } + wxCoord GetY() const { return m_y; } void CopyObject(wxObject& obj) const; public: - long m_x; - long m_y; + wxCoord m_x, m_y; + long m_keyCode; + bool m_controlDown; bool m_shiftDown; bool m_altDown; @@ -764,7 +814,6 @@ public: wxEVT_ERASE_BACKGROUND */ -class WXDLLEXPORT wxDC; class WXDLLEXPORT wxEraseEvent : public wxEvent { DECLARE_DYNAMIC_CLASS(wxEraseEvent) @@ -884,7 +933,7 @@ public: { // GetVeto() will return FALSE anyhow... wxCHECK_RET( m_canVeto, - _T("call to Veto() ignored (can't veto this event)") ); + wxT("call to Veto() ignored (can't veto this event)") ); m_veto = veto; } @@ -1017,7 +1066,7 @@ public: // Was it a button event? (*doesn't* mean: is any button *down*?) bool IsButton() const { return ((GetEventType() == wxEVT_JOY_BUTTON_DOWN) || - (GetEventType() == wxEVT_JOY_BUTTON_DOWN)); } + (GetEventType() == wxEVT_JOY_BUTTON_UP)); } // Was it a move event? bool IsMove() const { return (GetEventType() == wxEVT_JOY_MOVE) ; } @@ -1069,36 +1118,11 @@ public: void CopyObject(wxObject& obj) const; }; -// Idle event -/* - wxEVT_IDLE - */ - -class WXDLLEXPORT wxIdleEvent : public wxEvent -{ - DECLARE_DYNAMIC_CLASS(wxIdleEvent) - -public: - wxIdleEvent() - { m_eventType = wxEVT_IDLE; m_requestMore = FALSE; } - - void RequestMore(bool needMore = TRUE) { m_requestMore = needMore; } - bool MoreRequested() const { return m_requestMore; } - - void CopyObject(wxObject& obj) const; - -protected: - bool m_requestMore; -}; - // Update UI event /* wxEVT_UPDATE_UI */ -class WXDLLEXPORT wxMenu; -class WXDLLEXPORT wxWindow; - class WXDLLEXPORT wxUpdateUIEvent : public wxCommandEvent { DECLARE_DYNAMIC_CLASS(wxUpdateUIEvent) @@ -1256,6 +1280,30 @@ public: wxWindow *GetWindow() const { return (wxWindow *)GetEventObject(); } }; +#endif // wxUSE_GUI + +// Idle event +/* + wxEVT_IDLE + */ + +class WXDLLEXPORT wxIdleEvent : public wxEvent +{ + DECLARE_DYNAMIC_CLASS(wxIdleEvent) + +public: + wxIdleEvent() + { m_eventType = wxEVT_IDLE; m_requestMore = FALSE; } + + void RequestMore(bool needMore = TRUE) { m_requestMore = needMore; } + bool MoreRequested() const { return m_requestMore; } + + void CopyObject(wxObject& obj) const; + +protected: + bool m_requestMore; +}; + /* TODO wxEVT_POWER, wxEVT_MOUSE_CAPTURE_CHANGED, @@ -1267,10 +1315,9 @@ public: wxEVT_COMPARE_ITEM */ -class WXDLLEXPORT wxWindow; -class WXDLLEXPORT wxControl; - -// struct WXDLLEXPORT wxEventTableEntry; +// ============================================================================ +// event handler and related classes +// ============================================================================ typedef void (wxObject::*wxObjectEventFunction)(wxEvent&); @@ -1305,31 +1352,22 @@ public: void SetNextHandler(wxEvtHandler *handler) { m_nextHandler = handler; } void SetPreviousHandler(wxEvtHandler *handler) { m_previousHandler = handler; } - void SetEvtHandlerEnabled(bool en) { m_enabled = en; } + void SetEvtHandlerEnabled(bool enabled) { m_enabled = enabled; } bool GetEvtHandlerEnabled() const { return m_enabled; } -#if WXWIN_COMPATIBILITY_2 - virtual void OnCommand(wxWindow& WXUNUSED(win), - wxCommandEvent& WXUNUSED(event)) - { - wxFAIL_MSG(_T("shouldn't be called any more")); - } + // process an event right now + virtual bool ProcessEvent(wxEvent& event); - // Called if child control has no callback function - virtual long Default() - { return GetNextHandler() ? GetNextHandler()->Default() : 0; }; -#endif // WXWIN_COMPATIBILITY_2 + // add an event to be processed later + void AddPendingEvent(wxEvent& event); -#if WXWIN_COMPATIBILITY - virtual bool OnClose(); -#endif + // process all pending events + void ProcessPendingEvents(); + // add a #if wxUSE_THREADS bool ProcessThreadEvent(wxEvent& event); - void ProcessPendingEvents(); #endif - virtual bool ProcessEvent(wxEvent& event); - virtual bool SearchEventTable(wxEventTable& table, wxEvent& event); // Dynamic association of a member function handler with the event handler, // id and event type @@ -1343,14 +1381,50 @@ public: wxObject *userData = (wxObject *) NULL ) { Connect(id, -1, eventType, func, userData); } + bool Disconnect( int id, int lastId = -1, wxEventType eventType = wxEVT_NULL, + wxObjectEventFunction func = NULL, + wxObject *userData = (wxObject *) NULL ); + + // Convenience function: take just one id + bool Disconnect( int id, wxEventType eventType = wxEVT_NULL, + wxObjectEventFunction func = NULL, + wxObject *userData = (wxObject *) NULL ) + { return Disconnect(id, -1, eventType, func, userData); } + + // implementation from now on + virtual bool SearchEventTable(wxEventTable& table, wxEvent& event); bool SearchDynamicEventTable( wxEvent& event ); #if wxUSE_THREADS - void ClearEventLocker() { delete m_eventsLocker; m_eventsLocker = NULL; }; + void ClearEventLocker() + { +# if !defined(__VISAGECPP__) + delete m_eventsLocker; + m_eventsLocker = NULL; +#endif + }; +#endif + + // old stuff + +#if WXWIN_COMPATIBILITY_2 + virtual void OnCommand(wxWindow& WXUNUSED(win), + wxCommandEvent& WXUNUSED(event)) + { + wxFAIL_MSG(wxT("shouldn't be called any more")); + } + + // Called if child control has no callback function + virtual long Default() + { return GetNextHandler() ? GetNextHandler()->Default() : 0; }; +#endif // WXWIN_COMPATIBILITY_2 + +#if WXWIN_COMPATIBILITY + virtual bool OnClose(); #endif private: - static const wxEventTableEntry sm_eventTableEntries[]; + static const wxEventTableEntry sm_eventTableEntries[]; protected: static const wxEventTable sm_eventTable; @@ -1360,19 +1434,26 @@ protected: protected: wxEvtHandler* m_nextHandler; wxEvtHandler* m_previousHandler; - bool m_enabled; // Is event handler enabled? wxList* m_dynamicEvents; wxList* m_pendingEvents; #if wxUSE_THREADS +#if defined (__VISAGECPP__) + wxCriticalSection m_eventsLocker; +# else wxCriticalSection* m_eventsLocker; +# endif #endif // optimization: instead of using costly IsKindOf() to decide whether we're // a window (which is true in 99% of cases), use this flag bool m_isWindow; + + // Is event handler enabled? + bool m_enabled; }; typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&); +#if wxUSE_GUI typedef void (wxEvtHandler::*wxCommandEventFunction)(wxCommandEvent&); typedef void (wxEvtHandler::*wxScrollEventFunction)(wxScrollEvent&); typedef void (wxEvtHandler::*wxScrollWinEventFunction)(wxScrollWinEvent&); @@ -1398,6 +1479,7 @@ typedef void (wxEvtHandler::*wxMaximizeEventFunction)(wxShowEvent&); typedef void (wxEvtHandler::*wxNavigationKeyEventFunction)(wxNavigationKeyEvent&); typedef void (wxEvtHandler::*wxPaletteChangedEventFunction)(wxPaletteChangedEvent&); typedef void (wxEvtHandler::*wxQueryNewPaletteEventFunction)(wxQueryNewPaletteEvent&); +#endif // wxUSE_GUI // N.B. In GNU-WIN32, you *have* to take the address of a member function // (use &) or the compiler crashes... @@ -1568,6 +1650,7 @@ const wxEventTableEntry theClass::sm_eventTableEntries[] = { \ #define EVT_TOOL_RCLICKED_RANGE(id1, id2, fn) { wxEVT_COMMAND_TOOL_RCLICKED, id1, id2, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, #define EVT_TOOL_ENTER(id, fn) { wxEVT_COMMAND_TOOL_ENTER, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, #define EVT_CHECKLISTBOX(id, fn) { wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, +#define EVT_SPINCTRL(id, fn) { wxEVT_COMMAND_SPINCTRL_UPDATED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, // Generic command events #define EVT_COMMAND_LEFT_CLICK(id, fn) { wxEVT_COMMAND_LEFT_CLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL }, @@ -1603,13 +1686,28 @@ const wxEventTableEntry theClass::sm_eventTableEntries[] = { \ #define EVT_UPDATE_UI(id, func) \ { wxEVT_UPDATE_UI, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxUpdateUIEventFunction) & func, (wxObject *) NULL },\ -/* - * Helper functions - */ +// ---------------------------------------------------------------------------- +// Global data +// ---------------------------------------------------------------------------- + +// for pending event processing - notice that there is intentionally no +// WXDLLEXPORT here +extern wxList *wxPendingEvents; +#if wxUSE_THREADS + extern wxCriticalSection *wxPendingEventsLocker; +#endif + +// ---------------------------------------------------------------------------- +// Helper functions +// ---------------------------------------------------------------------------- + +#if wxUSE_GUI // Find a window with the focus, that is also a descendant of the given window. // This is used to determine the window to initially send commands to. wxWindow* wxFindFocusDescendant(wxWindow* ancestor); +#endif // wxUSE_GUI + #endif // _WX_EVENTH__