📄 event.h
字号:
private:
DECLARE_DYNAMIC_CLASS(wxQueryNewPaletteEvent)
};
/*
Event generated by dialog navigation keys
wxEVT_NAVIGATION_KEY
*/
// NB: don't derive from command event to avoid being propagated to the parent
class WXDLLEXPORT wxNavigationKeyEvent : public wxEvent
{
private:
wxNavigationKeyEvent& operator=(const wxNavigationKeyEvent& event);
public:
wxNavigationKeyEvent()
: wxEvent(0, wxEVT_NAVIGATION_KEY),
m_flags(IsForward | Propagate), // defaults are for TAB
m_focus((wxWindow *)NULL)
{ }
wxNavigationKeyEvent(const wxNavigationKeyEvent& event)
: wxEvent(event),
m_flags(event.m_flags),
m_focus(event.m_focus)
{ }
// direction: forward (true) or backward (false)
bool GetDirection() const
{ return (m_flags & IsForward) != 0; }
void SetDirection(bool bForward)
{ if ( bForward ) m_flags |= IsForward; else m_flags &= ~IsForward; }
// it may be a window change event (MDI, notebook pages...) or a control
// change event
bool IsWindowChange() const
{ return (m_flags & WinChange) != 0; }
void SetWindowChange(bool bIs)
{ if ( bIs ) m_flags |= WinChange; else m_flags &= ~WinChange; }
// some navigation events are meant to be propagated upwards (Windows
// convention is to do this for TAB events) while others should always
// cycle inside the panel/radiobox/whatever we're current inside
bool ShouldPropagate() const
{ return (m_flags & Propagate) != 0; }
void SetPropagate(bool bDoIt)
{ if ( bDoIt ) m_flags |= Propagate; else m_flags &= ~Propagate; }
// the child which has the focus currently (may be NULL - use
// wxWindow::FindFocus then)
wxWindow* GetCurrentFocus() const { return m_focus; }
void SetCurrentFocus(wxWindow *win) { m_focus = win; }
virtual wxEvent *Clone() const { return new wxNavigationKeyEvent(*this); }
private:
enum
{
IsForward = 0x0001,
WinChange = 0x0002,
Propagate = 0x0004
};
long m_flags;
wxWindow *m_focus;
private:
DECLARE_DYNAMIC_CLASS(wxNavigationKeyEvent)
};
// Window creation/destruction events: the first is sent as soon as window is
// created (i.e. the underlying GUI object exists), but when the C++ object is
// fully initialized (so virtual functions may be called). The second,
// wxEVT_DESTROY, is sent right before the window is destroyed - again, it's
// still safe to call virtual functions at this moment
/*
wxEVT_CREATE
wxEVT_DESTROY
*/
class WXDLLEXPORT wxWindowCreateEvent : public wxCommandEvent
{
public:
wxWindowCreateEvent(wxWindow *win = NULL);
wxWindow *GetWindow() const { return (wxWindow *)GetEventObject(); }
virtual wxEvent *Clone() const { return new wxWindowCreateEvent(*this); }
private:
DECLARE_DYNAMIC_CLASS(wxWindowCreateEvent)
};
class WXDLLEXPORT wxWindowDestroyEvent : public wxCommandEvent
{
public:
wxWindowDestroyEvent(wxWindow *win = NULL);
wxWindow *GetWindow() const { return (wxWindow *)GetEventObject(); }
virtual wxEvent *Clone() const { return new wxWindowDestroyEvent(*this); }
private:
DECLARE_DYNAMIC_CLASS(wxWindowDestroyEvent)
};
// A help event is sent when the user clicks on a window in context-help mode.
/*
wxEVT_HELP
wxEVT_DETAILED_HELP
*/
class WXDLLEXPORT wxHelpEvent : public wxCommandEvent
{
public:
wxHelpEvent(wxEventType type = wxEVT_NULL,
wxWindowID id = 0,
const wxPoint& pt = wxDefaultPosition)
: wxCommandEvent(type, id),
m_pos(pt), m_target(), m_link()
{ }
wxHelpEvent(const wxHelpEvent & event)
: wxCommandEvent(event),
m_pos(event.m_pos),
m_target(event.m_target),
m_link(event.m_link)
{ }
// Position of event (in screen coordinates)
const wxPoint& GetPosition() const { return m_pos; }
void SetPosition(const wxPoint& pos) { m_pos = pos; }
// Optional link to further help
const wxString& GetLink() const { return m_link; }
void SetLink(const wxString& link) { m_link = link; }
// Optional target to display help in. E.g. a window specification
const wxString& GetTarget() const { return m_target; }
void SetTarget(const wxString& target) { m_target = target; }
virtual wxEvent *Clone() const { return new wxHelpEvent(*this); }
protected:
wxPoint m_pos;
wxString m_target;
wxString m_link;
private:
DECLARE_DYNAMIC_CLASS(wxHelpEvent)
};
// A Context event is sent when the user right clicks on a window or
// presses Shift-F10
// NOTE : Under windows this is a repackaged WM_CONTETXMENU message
// Under other systems it may have to be generated from a right click event
/*
wxEVT_CONTEXT_MENU
*/
class WXDLLEXPORT wxContextMenuEvent : public wxCommandEvent
{
public:
wxContextMenuEvent(wxEventType type = wxEVT_NULL,
wxWindowID id = 0,
const wxPoint& pt = wxDefaultPosition)
: wxCommandEvent(type, id),
m_pos(pt)
{ }
wxContextMenuEvent(const wxContextMenuEvent & event)
: wxCommandEvent(event),
m_pos(event.m_pos)
{ }
// Position of event (in screen coordinates)
const wxPoint& GetPosition() const { return m_pos; }
void SetPosition(const wxPoint& pos) { m_pos = pos; }
virtual wxEvent *Clone() const { return new wxContextMenuEvent(*this); }
protected:
wxPoint m_pos;
private:
DECLARE_DYNAMIC_CLASS(wxContextMenuEvent)
};
// Idle event
/*
wxEVT_IDLE
*/
class WXDLLEXPORT wxIdleEvent : public wxEvent
{
public:
wxIdleEvent()
: wxEvent(0, wxEVT_IDLE),
m_requestMore(FALSE)
{ }
wxIdleEvent(const wxIdleEvent & event)
: wxEvent(event),
m_requestMore(event.m_requestMore)
{ }
void RequestMore(bool needMore = TRUE) { m_requestMore = needMore; }
bool MoreRequested() const { return m_requestMore; }
virtual wxEvent *Clone() const { return new wxIdleEvent(*this); }
protected:
bool m_requestMore;
private:
DECLARE_DYNAMIC_CLASS(wxIdleEvent)
};
#endif // wxUSE_GUI
/* TODO
wxEVT_POWER,
wxEVT_MOUSE_CAPTURE_CHANGED,
wxEVT_SETTING_CHANGED, // WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95)
// wxEVT_FONT_CHANGED, // WM_FONTCHANGE: roll into wxEVT_SETTING_CHANGED, but remember to propagate
// wxEVT_FONT_CHANGED to all other windows (maybe).
wxEVT_DRAW_ITEM, // Leave these three as virtual functions in wxControl?? Platform-specific.
wxEVT_MEASURE_ITEM,
wxEVT_COMPARE_ITEM
*/
// ============================================================================
// event handler and related classes
// ============================================================================
typedef void (wxObject::*wxObjectEventFunction)(wxEvent&);
// we can't have ctors nor base struct in backwards compatibility mode or
// otherwise we won't be able to initialize the objects with an agregate, so
// we have to keep both versions
#if WXWIN_COMPATIBILITY_EVENT_TYPES
struct WXDLLEXPORT wxEventTableEntry
{
// For some reason, this can't be wxEventType, or VC++ complains.
int m_eventType; // main event type
int m_id; // control/menu/toolbar id
int m_lastId; // used for ranges of ids
wxObjectEventFunction m_fn; // function to call: not wxEventFunction,
// because of dependency problems
wxObject* m_callbackUserData;
};
#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
// struct containing the members common to static and dynamic event tables
// entries
struct WXDLLEXPORT wxEventTableEntryBase
{
private:
wxEventTableEntryBase& operator=(const wxEventTableEntryBase& event);
public:
wxEventTableEntryBase(int id, int idLast,
wxObjectEventFunction fn, wxObject *data)
: m_id(id),
m_lastId(idLast),
m_fn(fn),
m_callbackUserData(data)
{ }
wxEventTableEntryBase(const wxEventTableEntryBase& event)
: m_id(event.m_id),
m_lastId(event.m_lastId),
m_fn(event.m_fn),
m_callbackUserData(event.m_callbackUserData)
{ }
// the range of ids for this entry: if m_lastId == wxID_ANY, the range
// consists only of m_id, otherwise it is m_id..m_lastId inclusive
int m_id,
m_lastId;
// function to call: not wxEventFunction, because of dependency problems
wxObjectEventFunction m_fn;
// arbitrary user data asosciated with the callback
wxObject* m_callbackUserData;
};
// an entry from a static event table
struct WXDLLEXPORT wxEventTableEntry : public wxEventTableEntryBase
{
wxEventTableEntry(const int& evType, int id, int idLast,
wxObjectEventFunction fn, wxObject *data)
: wxEventTableEntryBase(id, idLast, fn, data),
m_eventType(evType)
{ }
// the reference to event type: this allows us to not care about the
// (undefined) order in which the event table entries and the event types
// are initialized: initially the value of this reference might be
// invalid, but by the time it is used for the first time, all global
// objects will have been initialized (including the event type constants)
// and so it will have the correct value when it is needed
const int& m_eventType;
};
// an entry used in dynamic event table managed by wxEvtHandler::Connect()
struct WXDLLEXPORT wxDynamicEventTableEntry : public wxEventTableEntryBase
{
wxDynamicEventTableEntry(int evType, int id, int idLast,
wxObjectEventFunction fn, wxObject *data)
: wxEventTableEntryBase(id, idLast, fn, data),
m_eventType(evType)
{ }
// not a reference here as we can't keep a reference to a temporary int
// created to wrap the constant value typically passed to Connect() - nor
// do we need it
int m_eventType;
};
#endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
// ----------------------------------------------------------------------------
// wxEventTable: an array of event entries terminated with {0, 0, 0, 0, 0}
// ----------------------------------------------------------------------------
struct WXDLLEXPORT wxEventTable
{
const wxEventTable *baseTable; // base event table (next in chain)
const wxEventTableEntry *entries; // bottom of entry array
};
// ----------------------------------------------------------------------------
// wxEvtHandler: the base class for all objects handling wxWindows events
// ----------------------------------------------------------------------------
class WXDLLEXPORT wxEvtHandler : public wxObject
{
public:
wxEvtHandler();
virtual ~wxEvtHandler();
wxEvtHandler *GetNextHandler() const { return m_nextHandler; }
wxEvtHandler *GetPreviousHandler() const { return m_previousHandler; }
void SetNextHandler(wxEvtHandler *handler) { m_nextHandler = handler; }
void SetPreviousHandler(wxEvtHandler *handler) { m_previousHandler = handler; }
void SetEvtHandlerEnabled(bool enabled) { m_enabled = enabled; }
bool GetEvtHandlerEnabled() const { return m_enabled; }
// process an event right now
virtual bool ProcessEvent(wxEvent& event);
// add an event to be processed later
void AddPendingEvent(wxEvent& event);
// process all pending events
void ProcessPendingEvents();
// add a
#if wxUSE_THREADS
bool ProcessThreadEvent(wxEvent& event);
#endif
// Dynamic association of a member function handler with the event handler,
// id and event type
void Connect( int id, int lastId, int eventType,
wxObjectEventFunction func,
wxObject *userData = (wxObject *) NULL );
// Convenience function: take just one id
void Connect( int id, int eventType,
wxObjectEventFunction func,
wxObject *userData = (wxObject *) NULL )
{ Connect(id, wxID_ANY, eventType, func, userData); }
bool Disconnect( int id, int lastId, wxEventType eventType,
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, wxID_ANY, eventType, func, userData); }
// User data can be associated with each wxEvtHandler
void SetClientObject( wxClientData *data ) { DoSetClientObject(data); }
wxClientData *GetClientObject() const { return DoGetClientObject(); }
void SetClientData( void *data ) { DoSetClientData(data); }
void *GetClientData() const { return DoGetClientData(); }
// implementation from now on
virtual bool SearchEventTable(wxEventTable& table, wxEvent& event);
bool SearchDynamicEventTable( wxEvent& event );
#if wxUSE_THREADS
void ClearEventLocker()
{
# if !defined(__VISAGECPP__)
delete m_eventsLocker;
m_eventsLocker = NULL;
#endif
};
#endif
// old stuff
#if WXWIN_COMPATIBILITY_2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -