📄 event.h
字号:
// configured as mod2 modifier, yet the key events even when it is pressed
// should be processed normally, not like Ctrl- or Alt-key
bool HasModifiers() const { return ControlDown() || AltDown(); }
// get the key code: an ASCII7 char or an element of wxKeyCode enum
int GetKeyCode() const { return (int)m_keyCode; }
// get the raw key code (platform-dependent)
wxUint32 GetRawKeyCode() const { return m_rawCode; }
// get the raw key flags (platform-dependent)
wxUint32 GetRawKeyFlags() const { return m_rawFlags; }
// 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
{
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
wxCoord GetX() const { return m_x; }
// Get Y position
wxCoord GetY() const { return m_y; }
// deprecated
long KeyCode() const { return m_keyCode; }
virtual wxEvent *Clone() const { return new wxKeyEvent(*this); }
// we do need to copy wxKeyEvent sometimes (in wxTreeCtrl code, for
// example)
wxKeyEvent& operator=(const wxKeyEvent& evt)
{
m_x = evt.m_x;
m_y = evt.m_y;
m_keyCode = evt.m_keyCode;
m_controlDown = evt.m_controlDown;
m_shiftDown = evt.m_shiftDown;
m_altDown = evt.m_altDown;
m_metaDown = evt.m_metaDown;
m_scanCode = evt.m_scanCode;
m_rawCode = evt.m_rawCode;
m_rawFlags = evt.m_rawFlags;
return *this;
}
public:
wxCoord m_x, m_y;
long m_keyCode;
bool m_controlDown;
bool m_shiftDown;
bool m_altDown;
bool m_metaDown;
bool m_scanCode;
#if wxUSE_UNICODE
// This contains the full Unicode character
// in a character events in Unicode mode
wxChar m_uniChar;
#endif
// these fields contain the platform-specific information about
// key that was pressed
wxUint32 m_rawCode;
wxUint32 m_rawFlags;
private:
DECLARE_DYNAMIC_CLASS(wxKeyEvent)
};
// Size event class
/*
wxEVT_SIZE
*/
class WXDLLEXPORT wxSizeEvent : public wxEvent
{
public:
wxSizeEvent() : wxEvent(0, wxEVT_SIZE)
{ }
wxSizeEvent(const wxSize& sz, int id = 0)
: wxEvent(id, wxEVT_SIZE),
m_size(sz)
{ }
wxSizeEvent(const wxSizeEvent & event)
: wxEvent(event),
m_size(event.m_size)
{ }
wxSize GetSize() const { return m_size; }
virtual wxEvent *Clone() const { return new wxSizeEvent(*this); }
public:
wxSize m_size;
private:
DECLARE_DYNAMIC_CLASS(wxSizeEvent)
};
// Move event class
/*
wxEVT_MOVE
*/
class WXDLLEXPORT wxMoveEvent : public wxEvent
{
public:
wxMoveEvent()
: wxEvent(0, wxEVT_MOVE)
{ }
wxMoveEvent(const wxPoint& pos, int id = 0)
: wxEvent(id, wxEVT_MOVE),
m_pos(pos)
{ }
wxMoveEvent(const wxMoveEvent& event)
: wxEvent(event),
m_pos(event.m_pos)
{ }
wxPoint GetPosition() const { return m_pos; }
virtual wxEvent *Clone() const { return new wxMoveEvent(*this); }
wxPoint m_pos;
private:
DECLARE_DYNAMIC_CLASS(wxMoveEvent)
};
// Paint event class
/*
wxEVT_PAINT
wxEVT_NC_PAINT
wxEVT_PAINT_ICON
*/
#if defined(__WXDEBUG__) && (defined(__WXMSW__) || defined(__WXPM__))
// see comments in src/msw|os2/dcclient.cpp where g_isPainting is defined
extern WXDLLEXPORT int g_isPainting;
#endif // debug
class WXDLLEXPORT wxPaintEvent : public wxEvent
{
public:
wxPaintEvent(int Id = 0)
: wxEvent(Id, wxEVT_PAINT)
{
#if defined(__WXDEBUG__) && (defined(__WXMSW__) || defined(__WXPM__))
// set the internal flag for the duration of processing of WM_PAINT
g_isPainting++;
#endif // debug
}
#if defined(__WXDEBUG__) && (defined(__WXMSW__) || defined(__WXPM__))
~wxPaintEvent()
{
g_isPainting--;
}
#endif // debug
virtual wxEvent *Clone() const { return new wxPaintEvent(*this); }
private:
DECLARE_DYNAMIC_CLASS(wxPaintEvent)
};
class WXDLLEXPORT wxNcPaintEvent : public wxEvent
{
public:
wxNcPaintEvent(int id = 0)
: wxEvent(id, wxEVT_NC_PAINT)
{ }
virtual wxEvent *Clone() const { return new wxNcPaintEvent(*this); }
private:
DECLARE_DYNAMIC_CLASS(wxNcPaintEvent)
};
// Erase background event class
/*
wxEVT_ERASE_BACKGROUND
*/
class WXDLLEXPORT wxEraseEvent : public wxEvent
{
private:
wxEraseEvent& operator=(const wxEraseEvent& event);
public:
wxEraseEvent(int Id = 0, wxDC *dc = (wxDC *) NULL)
: wxEvent(Id, wxEVT_ERASE_BACKGROUND),
m_dc(dc)
{ }
wxEraseEvent(const wxEraseEvent& event)
: wxEvent(event),
m_dc(event.m_dc)
{ }
wxDC *GetDC() const { return m_dc; }
virtual wxEvent *Clone() const { return new wxEraseEvent(*this); }
wxDC *m_dc;
private:
DECLARE_DYNAMIC_CLASS(wxEraseEvent)
};
// Focus event class
/*
wxEVT_SET_FOCUS
wxEVT_KILL_FOCUS
*/
class WXDLLEXPORT wxFocusEvent : public wxEvent
{
private:
wxFocusEvent& operator=(const wxFocusEvent& event);
public:
wxFocusEvent(wxEventType type = wxEVT_NULL, int id = 0)
: wxEvent(id, type)
{ m_win = NULL; }
wxFocusEvent(const wxFocusEvent& event)
: wxEvent(event)
{ m_win = event.m_win; }
// The window associated with this event is the window which had focus
// before for SET event and the window which will have focus for the KILL
// one. NB: it may be NULL in both cases!
wxWindow *GetWindow() const { return m_win; }
void SetWindow(wxWindow *win) { m_win = win; }
virtual wxEvent *Clone() const { return new wxFocusEvent(*this); }
private:
wxWindow *m_win;
private:
DECLARE_DYNAMIC_CLASS(wxFocusEvent)
};
// wxChildFocusEvent notifies the parent that a child has got the focus: unlike
// wxFocusEvent it is propgated upwards the window chain
class WXDLLEXPORT wxChildFocusEvent : public wxCommandEvent
{
public:
wxChildFocusEvent(wxWindow *win = NULL);
wxWindow *GetWindow() const { return (wxWindow *)GetEventObject(); }
virtual wxEvent *Clone() const { return new wxChildFocusEvent(*this); }
private:
DECLARE_DYNAMIC_CLASS(wxChildFocusEvent)
};
// Activate event class
/*
wxEVT_ACTIVATE
wxEVT_ACTIVATE_APP
*/
class WXDLLEXPORT wxActivateEvent : public wxEvent
{
public:
wxActivateEvent(wxEventType type = wxEVT_NULL, bool active = TRUE, int Id = 0)
: wxEvent(Id, type)
{ m_active = active; }
wxActivateEvent(const wxActivateEvent& event)
: wxEvent(event)
{ m_active = event.m_active; }
bool GetActive() const { return m_active; }
virtual wxEvent *Clone() const { return new wxActivateEvent(*this); }
private:
bool m_active;
private:
DECLARE_DYNAMIC_CLASS(wxActivateEvent)
};
// InitDialog event class
/*
wxEVT_INIT_DIALOG
*/
class WXDLLEXPORT wxInitDialogEvent : public wxEvent
{
public:
wxInitDialogEvent(int Id = 0)
: wxEvent(Id, wxEVT_INIT_DIALOG)
{ }
virtual wxEvent *Clone() const { return new wxInitDialogEvent(*this); }
private:
DECLARE_DYNAMIC_CLASS(wxInitDialogEvent)
};
// Miscellaneous menu event class
/*
wxEVT_MENU_OPEN,
wxEVT_MENU_CLOSE,
wxEVT_MENU_HIGHLIGHT,
*/
class WXDLLEXPORT wxMenuEvent : public wxEvent
{
public:
wxMenuEvent(wxEventType type = wxEVT_NULL, int id = 0)
: wxEvent(id, type)
{ m_menuId = id; }
wxMenuEvent(const wxMenuEvent & event)
: wxEvent(event)
{ m_menuId = event.m_menuId; }
// only for wxEVT_MENU_HIGHLIGHT
int GetMenuId() const { return m_menuId; }
// only for wxEVT_MENU_OPEN/CLOSE
bool IsPopup() const { return m_menuId == -1; }
virtual wxEvent *Clone() const { return new wxMenuEvent(*this); }
private:
int m_menuId;
DECLARE_DYNAMIC_CLASS(wxMenuEvent)
};
// Window close or session close event class
/*
wxEVT_CLOSE_WINDOW,
wxEVT_END_SESSION,
wxEVT_QUERY_END_SESSION
*/
class WXDLLEXPORT wxCloseEvent : public wxEvent
{
public:
wxCloseEvent(wxEventType type = wxEVT_NULL, int id = 0)
: wxEvent(id, type),
m_loggingOff(TRUE),
m_veto(FALSE), // should be FALSE by default
m_canVeto(TRUE)
{
#if WXWIN_COMPATIBILITY
m_force = FALSE;
#endif // WXWIN_COMPATIBILITY
}
wxCloseEvent(const wxCloseEvent & event)
: wxEvent(event),
m_loggingOff(event.m_loggingOff),
m_veto(event.m_veto),
m_canVeto(event.m_canVeto)
{
#if WXWIN_COMPATIBILITY
m_force = event.m_force;
#endif // WXWIN_COMPATIBILITY
}
void SetLoggingOff(bool logOff) { m_loggingOff = logOff; }
bool GetLoggingOff() const { return m_loggingOff; }
void Veto(bool veto = TRUE)
{
// GetVeto() will return FALSE anyhow...
wxCHECK_RET( m_canVeto,
wxT("call to Veto() ignored (can't veto this event)") );
m_veto = veto;
}
void SetCanVeto(bool canVeto) { m_canVeto = canVeto; }
// No more asserts here please, the one you put here was wrong.
bool CanVeto() const { return m_canVeto; }
bool GetVeto() const { return m_canVeto && m_veto; }
#if WXWIN_COMPATIBILITY
// This is probably obsolete now, since we use CanVeto instead, in
// both OnCloseWindow and OnQueryEndSession.
// m_force == ! m_canVeto i.e., can't veto means we must force it to close.
void SetForce(bool force) { m_force = force; }
bool GetForce() const { return m_force; }
#endif
virtual wxEvent *Clone() const { return new wxCloseEvent(*this); }
protected:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -