#include <wx/event.h>
This event class contains information about the events generated by the mouse: they include mouse buttons press and release events and mouse move events.
All mouse events involving the buttons use wxMOUSE_BTN_LEFT
for the left mouse button, wxMOUSE_BTN_MIDDLE
for the middle one and wxMOUSE_BTN_RIGHT
for the right one. And if the system supports more buttons, the wxMOUSE_BTN_AUX1
and wxMOUSE_BTN_AUX2
events can also be generated. Note that not all mice have even a middle button so a portable application should avoid relying on the events from it (but the right button click can be emulated using the left mouse button with the control key under Mac platforms with a single button mouse).
For the wxEVT_ENTER_WINDOW
and wxEVT_LEAVE_WINDOW
events purposes, the mouse is considered to be inside the window if it is in the window client area and not inside one of its children. In other words, the parent window receives wxEVT_LEAVE_WINDOW
event not only when the mouse leaves the window entirely but also when it enters one of its children.
The position associated with a mouse event is expressed in the window coordinates of the window which generated the event, you can use wxWindow::ClientToScreen() to convert it to screen coordinates and possibly call wxWindow::ScreenToClient() next to convert it to window coordinates of another window.
The following event handler macros redirect the events to member function handlers 'func' with prototypes like:
Event macros:
wxEVT_LEFT_DOWN
event. The handler of this event should normally call event.Skip() to allow the default processing to take place as otherwise the window under mouse wouldn't get the focus. wxEVT_LEFT_UP
event. wxEVT_LEFT_DCLICK
event. wxEVT_MIDDLE_DOWN
event. wxEVT_MIDDLE_UP
event. wxEVT_MIDDLE_DCLICK
event. wxEVT_RIGHT_DOWN
event. wxEVT_RIGHT_UP
event. wxEVT_RIGHT_DCLICK
event. wxEVT_AUX1_DOWN
event. wxEVT_AUX1_UP
event. wxEVT_AUX1_DCLICK
event. wxEVT_AUX2_DOWN
event. wxEVT_AUX2_UP
event. wxEVT_AUX2_DCLICK
event. wxEVT_MOTION
event. wxEVT_ENTER_WINDOW
event. wxEVT_LEAVE_WINDOW
event. wxEVT_MOUSEWHEEL
event. wxEVT_MAGNIFY
event (new since wxWidgets 3.1.0). Public Member Functions | |
wxMouseEvent (wxEventType mouseEventType=wxEVT_NULL) | |
Constructor. More... | |
bool | Aux1DClick () const |
Returns true if the event was a first extra button double click. More... | |
bool | Aux1Down () const |
Returns true if the first extra button mouse button changed to down. More... | |
bool | Aux1Up () const |
Returns true if the first extra button mouse button changed to up. More... | |
bool | Aux2DClick () const |
Returns true if the event was a second extra button double click. More... | |
bool | Aux2Down () const |
Returns true if the second extra button mouse button changed to down. More... | |
bool | Aux2Up () const |
Returns true if the second extra button mouse button changed to up. More... | |
bool | Button (wxMouseButton but) const |
Returns true if the event was generated by the specified button. More... | |
bool | ButtonDClick (wxMouseButton but=wxMOUSE_BTN_ANY) const |
If the argument is omitted, this returns true if the event was a mouse double click event. More... | |
bool | ButtonDown (wxMouseButton but=wxMOUSE_BTN_ANY) const |
If the argument is omitted, this returns true if the event was a mouse button down event. More... | |
bool | ButtonUp (wxMouseButton but=wxMOUSE_BTN_ANY) const |
If the argument is omitted, this returns true if the event was a mouse button up event. More... | |
bool | Dragging () const |
Returns true if this was a dragging event (motion while a button is depressed). More... | |
bool | Entering () const |
Returns true if the mouse was entering the window. More... | |
int | GetButton () const |
Returns the mouse button which generated this event or wxMOUSE_BTN_NONE if no button is involved (for mouse move, enter or leave event, for example). More... | |
int | GetClickCount () const |
Returns the number of mouse clicks for this event: 1 for a simple click, 2 for a double-click, 3 for a triple-click and so on. More... | |
int | GetLinesPerAction () const |
Returns the configured number of lines (or whatever) to be scrolled per wheel action. More... | |
int | GetColumnsPerAction () const |
Returns the configured number of columns (or whatever) to be scrolled per wheel action. More... | |
wxPoint | GetLogicalPosition (const wxDC &dc) const |
Returns the logical mouse position in pixels (i.e. translated according to the translation set for the DC, which usually indicates that the window has been scrolled). More... | |
float | GetMagnification () const |
For magnify (pinch to zoom) events: returns the change in magnification. More... | |
int | GetWheelDelta () const |
Get wheel delta, normally 120. More... | |
bool | IsWheelInverted () const |
On Mac, has the user selected "Natural" scrolling in their System Preferences? Currently false on all other OS's. More... | |
int | GetWheelRotation () const |
Get wheel rotation, positive or negative indicates direction of rotation. More... | |
wxMouseWheelAxis | GetWheelAxis () const |
Gets the axis the wheel operation concerns. More... | |
bool | IsButton () const |
Returns true if the event was a mouse button event (not necessarily a button down event - that may be tested using ButtonDown()). More... | |
bool | IsPageScroll () const |
Returns true if the system has been setup to do page scrolling with the mouse wheel instead of line scrolling. More... | |
bool | Leaving () const |
Returns true if the mouse was leaving the window. More... | |
bool | LeftDClick () const |
Returns true if the event was a left double click. More... | |
bool | LeftDown () const |
Returns true if the left mouse button changed to down. More... | |
bool | LeftUp () const |
Returns true if the left mouse button changed to up. More... | |
bool | Magnify () const |
Returns true if the event is a magnify (i.e. pinch to zoom) event. More... | |
bool | MetaDown () const |
Returns true if the Meta key was down at the time of the event. More... | |
bool | MiddleDClick () const |
Returns true if the event was a middle double click. More... | |
bool | MiddleDown () const |
Returns true if the middle mouse button changed to down. More... | |
bool | MiddleUp () const |
Returns true if the middle mouse button changed to up. More... | |
bool | Moving () const |
Returns true if this was a motion event and no mouse buttons were pressed. More... | |
bool | RightDClick () const |
Returns true if the event was a right double click. More... | |
bool | RightDown () const |
Returns true if the right mouse button changed to down. More... | |
bool | RightUp () const |
Returns true if the right mouse button changed to up. More... | |
Public Member Functions inherited from wxEvent | |
wxEvent (int id=0, wxEventType eventType=wxEVT_NULL) | |
Constructor. More... | |
virtual wxEvent * | Clone () const =0 |
Returns a copy of the event. More... | |
wxObject * | GetEventObject () const |
Returns the object (usually a window) associated with the event, if any. More... | |
wxEventType | GetEventType () const |
Returns the identifier of the given event type, such as wxEVT_BUTTON . More... | |
virtual wxEventCategory | GetEventCategory () const |
Returns a generic category for this event. More... | |
int | GetId () const |
Returns the identifier associated with this event, such as a button command id. More... | |
wxObject * | GetEventUserData () const |
Return the user data associated with a dynamically connected event handler. More... | |
bool | GetSkipped () const |
Returns true if the event handler should be skipped, false otherwise. More... | |
long | GetTimestamp () const |
Gets the timestamp for the event. More... | |
bool | IsCommandEvent () const |
Returns true if the event is or is derived from wxCommandEvent else it returns false. More... | |
void | ResumePropagation (int propagationLevel) |
Sets the propagation level to the given value (for example returned from an earlier call to wxEvent::StopPropagation). More... | |
void | SetEventObject (wxObject *object) |
Sets the originating object. More... | |
void | SetEventType (wxEventType type) |
Sets the event type. More... | |
void | SetId (int id) |
Sets the identifier associated with this event, such as a button command id. More... | |
void | SetTimestamp (long timeStamp=0) |
Sets the timestamp for the event. More... | |
bool | ShouldPropagate () const |
Test if this event should be propagated or not, i.e. if the propagation level is currently greater than 0. More... | |
void | Skip (bool skip=true) |
This method can be used inside an event handler to control whether further event handlers bound to this event will be called after the current one returns. More... | |
int | StopPropagation () |
Stop the event from propagating to its parent window. More... | |
Public Member Functions inherited from wxObject | |
wxObject () | |
Default ctor; initializes to NULL the internal reference data. More... | |
wxObject (const wxObject &other) | |
Copy ctor. More... | |
virtual | ~wxObject () |
Destructor. More... | |
virtual wxClassInfo * | GetClassInfo () const |
This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More... | |
wxObjectRefData * | GetRefData () const |
Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More... | |
bool | IsKindOf (const wxClassInfo *info) const |
Determines whether this class is a subclass of (or the same class as) the given class. More... | |
bool | IsSameAs (const wxObject &obj) const |
Returns true if this object has the same data pointer as obj. More... | |
void | Ref (const wxObject &clone) |
Makes this object refer to the data in clone. More... | |
void | SetRefData (wxObjectRefData *data) |
Sets the wxObject::m_refData pointer. More... | |
void | UnRef () |
Decrements the reference count in the associated data, and if it is zero, deletes the data. More... | |
void | UnShare () |
This is the same of AllocExclusive() but this method is public. More... | |
void | operator delete (void *buf) |
The delete operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. More... | |
void * | operator new (size_t size, const wxString &filename=NULL, int lineNum=0) |
The new operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. More... | |
Public Member Functions inherited from wxMouseState | |
wxMouseState () | |
Default constructor. More... | |
wxCoord | GetX () const |
Returns X coordinate of the physical mouse event position. More... | |
wxCoord | GetY () const |
Returns Y coordinate of the physical mouse event position. More... | |
bool | LeftIsDown () const |
Returns true if the left mouse button is currently down. More... | |
bool | MiddleIsDown () const |
Returns true if the middle mouse button is currently down. More... | |
bool | RightIsDown () const |
Returns true if the right mouse button is currently down. More... | |
bool | Aux1IsDown () const |
Returns true if the first extra button mouse button is currently down. More... | |
bool | Aux2IsDown () const |
Returns true if the second extra button mouse button is currently down. More... | |
void | SetX (wxCoord x) |
void | SetY (wxCoord y) |
void | SetPosition (const wxPoint &pos) |
void | SetLeftDown (bool down) |
void | SetMiddleDown (bool down) |
void | SetRightDown (bool down) |
void | SetAux1Down (bool down) |
void | SetAux2Down (bool down) |
void | SetState (const wxMouseState &state) |
wxPoint | GetPosition () const |
Returns the physical mouse position. More... | |
void | GetPosition (int *x, int *y) const |
Returns the physical mouse position. More... | |
Public Member Functions inherited from wxKeyboardState | |
wxKeyboardState (bool controlDown=false, bool shiftDown=false, bool altDown=false, bool metaDown=false) | |
Constructor initializes the modifier key settings. More... | |
int | GetModifiers () const |
Return the bit mask of all pressed modifier keys. More... | |
bool | HasAnyModifiers () const |
Returns true if any modifiers at all are pressed. More... | |
bool | HasModifiers () const |
Returns true if Control or Alt are pressed. More... | |
bool | ControlDown () const |
Returns true if the Control key or Apple/Command key under macOS is pressed. More... | |
bool | RawControlDown () const |
Returns true if the Control key (also under macOS). More... | |
bool | ShiftDown () const |
Returns true if the Shift key is pressed. More... | |
bool | MetaDown () const |
Returns true if the Meta/Windows/Apple key is pressed. More... | |
bool | AltDown () const |
Returns true if the Alt key is pressed. More... | |
bool | CmdDown () const |
Returns true if the key used for command accelerators is pressed. More... | |
void | SetControlDown (bool down) |
void | SetRawControlDown (bool down) |
void | SetShiftDown (bool down) |
void | SetAltDown (bool down) |
void | SetMetaDown (bool down) |
Additional Inherited Members | |
Protected Member Functions inherited from wxObject | |
void | AllocExclusive () |
Ensure that this object's data is not shared with any other object. More... | |
virtual wxObjectRefData * | CreateRefData () const |
Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More... | |
virtual wxObjectRefData * | CloneRefData (const wxObjectRefData *data) const |
Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More... | |
Protected Attributes inherited from wxEvent | |
int | m_propagationLevel |
Indicates how many levels the event can propagate. More... | |
Protected Attributes inherited from wxObject | |
wxObjectRefData * | m_refData |
Pointer to an object which is the object's reference-counted data. More... | |
wxMouseEvent::wxMouseEvent | ( | wxEventType | mouseEventType = wxEVT_NULL | ) |
Constructor.
Valid event types are:
wxEVT_ENTER_WINDOW
wxEVT_LEAVE_WINDOW
wxEVT_LEFT_DOWN
wxEVT_LEFT_UP
wxEVT_LEFT_DCLICK
wxEVT_MIDDLE_DOWN
wxEVT_MIDDLE_UP
wxEVT_MIDDLE_DCLICK
wxEVT_RIGHT_DOWN
wxEVT_RIGHT_UP
wxEVT_RIGHT_DCLICK
wxEVT_AUX1_DOWN
wxEVT_AUX1_UP
wxEVT_AUX1_DCLICK
wxEVT_AUX2_DOWN
wxEVT_AUX2_UP
wxEVT_AUX2_DCLICK
wxEVT_MOTION
wxEVT_MOUSEWHEEL
wxEVT_MAGNIFY
bool wxMouseEvent::Aux1DClick | ( | ) | const |
Returns true if the event was a first extra button double click.
bool wxMouseEvent::Aux1Down | ( | ) | const |
Returns true if the first extra button mouse button changed to down.
bool wxMouseEvent::Aux1Up | ( | ) | const |
Returns true if the first extra button mouse button changed to up.
bool wxMouseEvent::Aux2DClick | ( | ) | const |
Returns true if the event was a second extra button double click.
bool wxMouseEvent::Aux2Down | ( | ) | const |
Returns true if the second extra button mouse button changed to down.
bool wxMouseEvent::Aux2Up | ( | ) | const |
Returns true if the second extra button mouse button changed to up.
bool wxMouseEvent::Button | ( | wxMouseButton | but | ) | const |
Returns true if the event was generated by the specified button.
bool wxMouseEvent::ButtonDClick | ( | wxMouseButton | but = wxMOUSE_BTN_ANY | ) | const |
If the argument is omitted, this returns true if the event was a mouse double click event.
Otherwise the argument specifies which double click event was generated (see Button() for the possible values).
bool wxMouseEvent::ButtonDown | ( | wxMouseButton | but = wxMOUSE_BTN_ANY | ) | const |
If the argument is omitted, this returns true if the event was a mouse button down event.
Otherwise the argument specifies which button-down event was generated (see Button() for the possible values).
bool wxMouseEvent::ButtonUp | ( | wxMouseButton | but = wxMOUSE_BTN_ANY | ) | const |
If the argument is omitted, this returns true if the event was a mouse button up event.
Otherwise the argument specifies which button-up event was generated (see Button() for the possible values).
bool wxMouseEvent::Dragging | ( | ) | const |
Returns true if this was a dragging event (motion while a button is depressed).
bool wxMouseEvent::Entering | ( | ) | const |
Returns true if the mouse was entering the window.
int wxMouseEvent::GetButton | ( | ) | const |
Returns the mouse button which generated this event or wxMOUSE_BTN_NONE
if no button is involved (for mouse move, enter or leave event, for example).
Otherwise wxMOUSE_BTN_LEFT
is returned for the left button down, up and double click events, wxMOUSE_BTN_MIDDLE
and wxMOUSE_BTN_RIGHT
for the same events for the middle and the right buttons respectively.
int wxMouseEvent::GetClickCount | ( | ) | const |
Returns the number of mouse clicks for this event: 1 for a simple click, 2 for a double-click, 3 for a triple-click and so on.
Currently this function is implemented only in wxMac and returns -1 for the other platforms (you can still distinguish simple clicks from double-clicks as they generate different kinds of events however).
int wxMouseEvent::GetColumnsPerAction | ( | ) | const |
Returns the configured number of columns (or whatever) to be scrolled per wheel action.
Default value under most platforms is three.
int wxMouseEvent::GetLinesPerAction | ( | ) | const |
Returns the configured number of lines (or whatever) to be scrolled per wheel action.
Default value under most platforms is three.
Returns the logical mouse position in pixels (i.e. translated according to the translation set for the DC, which usually indicates that the window has been scrolled).
float wxMouseEvent::GetMagnification | ( | ) | const |
For magnify (pinch to zoom) events: returns the change in magnification.
A value of 0 means no change, a positive value means we should enlarge (or zoom in), a negative value means we should shrink (or zoom out).
This method is only valid to call for wxEVT_MAGNIFY
events which are currently only generated under macOS.
wxMouseWheelAxis wxMouseEvent::GetWheelAxis | ( | ) | const |
Gets the axis the wheel operation concerns.
Usually the mouse wheel is used to scroll vertically so wxMOUSE_WHEEL_VERTICAL
is returned but some mice (and most trackpads) also allow to use the wheel to scroll horizontally in which case wxMOUSE_WHEEL_HORIZONTAL
is returned.
Notice that before wxWidgets 2.9.4 this method returned int
.
int wxMouseEvent::GetWheelDelta | ( | ) | const |
Get wheel delta, normally 120.
This is the threshold for action to be taken, and one such action (for example, scrolling one increment) should occur for each delta.
int wxMouseEvent::GetWheelRotation | ( | ) | const |
Get wheel rotation, positive or negative indicates direction of rotation.
Current devices all send an event when rotation is at least +/-WheelDelta, but finer resolution devices can be created in the future.
Because of this you shouldn't assume that one event is equal to 1 line, but you should be able to either do partial line scrolling or wait until several events accumulate before scrolling.
bool wxMouseEvent::IsButton | ( | ) | const |
Returns true if the event was a mouse button event (not necessarily a button down event - that may be tested using ButtonDown()).
bool wxMouseEvent::IsPageScroll | ( | ) | const |
Returns true if the system has been setup to do page scrolling with the mouse wheel instead of line scrolling.
bool wxMouseEvent::IsWheelInverted | ( | ) | const |
On Mac, has the user selected "Natural" scrolling in their System Preferences? Currently false on all other OS's.
"Natural" scrolling means that content scrolling happens in the opposite direction, and if you are indeed scrolling content then you don't need to use this function because macOS has already inverted the scroll direction. But there can be special situations where you want the mouse wheel action to work always in the same direction and in that case you will need this function.
bool wxMouseEvent::Leaving | ( | ) | const |
Returns true if the mouse was leaving the window.
bool wxMouseEvent::LeftDClick | ( | ) | const |
Returns true if the event was a left double click.
bool wxMouseEvent::LeftDown | ( | ) | const |
Returns true if the left mouse button changed to down.
bool wxMouseEvent::LeftUp | ( | ) | const |
Returns true if the left mouse button changed to up.
bool wxMouseEvent::Magnify | ( | ) | const |
Returns true if the event is a magnify (i.e. pinch to zoom) event.
Such events are currently generated only under macOS.
bool wxMouseEvent::MetaDown | ( | ) | const |
Returns true if the Meta key was down at the time of the event.
bool wxMouseEvent::MiddleDClick | ( | ) | const |
Returns true if the event was a middle double click.
bool wxMouseEvent::MiddleDown | ( | ) | const |
Returns true if the middle mouse button changed to down.
bool wxMouseEvent::MiddleUp | ( | ) | const |
Returns true if the middle mouse button changed to up.
bool wxMouseEvent::Moving | ( | ) | const |
Returns true if this was a motion event and no mouse buttons were pressed.
If any mouse button is held pressed, then this method returns false and Dragging() returns true.
bool wxMouseEvent::RightDClick | ( | ) | const |
Returns true if the event was a right double click.
bool wxMouseEvent::RightDown | ( | ) | const |
Returns true if the right mouse button changed to down.
bool wxMouseEvent::RightUp | ( | ) | const |
Returns true if the right mouse button changed to up.