wxMouseEvent Class Reference
[Events]

#include <wx/event.h>

Inheritance diagram for wxMouseEvent:

Inheritance graph
[legend]

Detailed Description

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.

Note:
Note that under Windows CE mouse enter and leave events are not natively supported by the system but are generated by wxWidgets itself. This has several drawbacks: the LEAVE_WINDOW event might be received some time after the mouse left the window and the state variables for it may have changed during this time.

Note the difference between methods like wxMouseEvent::LeftDown and wxMouseEvent::LeftIsDown: the former returns true when the event corresponds to the left mouse button click while the latter returns true if the left mouse button is currently being pressed. For example, when the user is dragging the mouse you can use wxMouseEvent::LeftIsDown to test whether the left mouse button is (still) depressed. Also, by convention, if wxMouseEvent::LeftDown returns true, wxMouseEvent::LeftIsDown will also return true in wxWidgets whatever the underlying GUI behaviour is (which is platform-dependent). The same applies, of course, to other mouse buttons as well.

Events using this class

The following event handler macros redirect the events to member function handlers 'func' with prototypes like:

void handlerFuncName(wxMouseEvent& event)
Event macros:

Library:  wxCore

Category:  Events

See also:
wxKeyEvent

Public Member Functions

 wxMouseEvent (wxEventType mouseEventType=wxEVT_NULL)
 Constructor.
bool Aux1DClick () const
 Returns true if the event was a first extra button double click.
bool Aux1Down () const
 Returns true if the first extra button mouse button changed to down.
bool Aux1IsDown () const
 Returns true if the first extra button mouse button is currently down, independent of the current event type.
bool Aux1Up () const
 Returns true if the first extra button mouse button changed to up.
bool Aux2DClick () const
 Returns true if the event was a second extra button double click.
bool Aux2Down () const
 Returns true if the second extra button mouse button changed to down.
bool Aux2IsDown () const
 Returns true if the second extra button mouse button is currently down, independent of the current event type.
bool Aux2Up () const
 Returns true if the second extra button mouse button changed to up.
bool Button (int button) const
 Returns true if the identified mouse button is changing state.
bool ButtonDClick (int but=wxMOUSE_BTN_ANY) const
 If the argument is omitted, this returns true if the event was a mouse double click event.
bool ButtonDown (int=wxMOUSE_BTN_ANY) const
 If the argument is omitted, this returns true if the event was a mouse button down event.
bool ButtonUp (int=wxMOUSE_BTN_ANY) const
 If the argument is omitted, this returns true if the event was a mouse button up event.
bool Dragging () const
 Returns true if this was a dragging event (motion while a button is depressed).
bool Entering () const
 Returns true if the mouse was entering the window.
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).
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.
int GetLinesPerAction () const
 Returns the configured number of lines (or whatever) to be scrolled per wheel action.
wxPoint GetLogicalPosition (const wxDC &dc) const
 Returns the logical mouse position in pixels (i.e.
int GetWheelDelta () const
 Get wheel delta, normally 120.
int GetWheelRotation () const
 Get wheel rotation, positive or negative indicates direction of rotation.
int GetWheelAxis () const
 Gets the axis the wheel operation concerns; 0 is the Y axis as on most mouse wheels, 1 is the X axis.
wxCoord GetX () const
 Returns X coordinate of the physical mouse event position.
wxCoord GetY () const
 Returns Y coordinate of the physical mouse event position.
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()).
bool IsPageScroll () const
 Returns true if the system has been setup to do page scrolling with the mouse wheel instead of line scrolling.
bool Leaving () const
 Returns true if the mouse was leaving the window.
bool LeftDClick () const
 Returns true if the event was a left double click.
bool LeftDown () const
 Returns true if the left mouse button changed to down.
bool LeftIsDown () const
 Returns true if the left mouse button is currently down, independent of the current event type.
bool LeftUp () const
 Returns true if the left mouse button changed to up.
bool MetaDown () const
 Returns true if the Meta key was down at the time of the event.
bool MiddleDClick () const
 Returns true if the event was a middle double click.
bool MiddleDown () const
 Returns true if the middle mouse button changed to down.
bool MiddleIsDown () const
 Returns true if the middle mouse button is currently down, independent of the current event type.
bool MiddleUp () const
 Returns true if the middle mouse button changed to up.
bool Moving () const
 Returns true if this was a motion event and no mouse buttons were pressed.
bool RightDClick () const
 Returns true if the event was a right double click.
bool RightDown () const
 Returns true if the right mouse button changed to down.
bool RightIsDown () const
 Returns true if the right mouse button is currently down, independent of the current event type.
bool RightUp () const
 Returns true if the right mouse button changed to up.
wxPoint GetPosition () const
 Sets *x and *y to the position at which the event occurred.
void GetPosition (wxCoord *x, wxCoord *y) const
 Sets *x and *y to the position at which the event occurred.
void GetPosition (long *x, long *y) const
 Sets *x and *y to the position at which the event occurred.

List of all members.


Constructor & Destructor Documentation

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_MOUSE_AUX1_DOWN
  • wxEVT_MOUSE_AUX1_UP
  • wxEVT_MOUSE_AUX1_DCLICK
  • wxEVT_MOUSE_AUX2_DOWN
  • wxEVT_MOUSE_AUX2_UP
  • wxEVT_MOUSE_AUX2_DCLICK
  • wxEVT_MOTION
  • wxEVT_MOUSEWHEEL


Member Function Documentation

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.

Reimplemented from wxMouseState.

bool wxMouseEvent::Aux1IsDown (  )  const

Returns true if the first extra button mouse button is currently down, independent of the current event type.

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.

Reimplemented from wxMouseState.

bool wxMouseEvent::Aux2IsDown (  )  const

Returns true if the second extra button mouse button is currently down, independent of the current event type.

bool wxMouseEvent::Aux2Up (  )  const

Returns true if the second extra button mouse button changed to up.

bool wxMouseEvent::Button ( int  button  )  const

Returns true if the identified mouse button is changing state.

Valid values of button are:

  • wxMOUSE_BTN_LEFT: check if left button was pressed
  • wxMOUSE_BTN_MIDDLE: check if middle button was pressed
  • wxMOUSE_BTN_RIGHT: check if right button was pressed
  • wxMOUSE_BTN_AUX1: check if the first extra button was pressed
  • wxMOUSE_BTN_AUX2: check if the second extra button was pressed
  • wxMOUSE_BTN_ANY: check if any button was pressed
Todo:
introduce wxMouseButton enum

bool wxMouseEvent::ButtonDClick ( int  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 ( int  = 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 ( int  = 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).

See also:
Moving()

bool wxMouseEvent::Entering (  )  const

Returns true if the mouse was entering the window.

See also:
Leaving()

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).

Since:
2.9.0

int wxMouseEvent::GetLinesPerAction (  )  const

Returns the configured number of lines (or whatever) to be scrolled per wheel action.

Defaults to three.

wxPoint wxMouseEvent::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).

void wxMouseEvent::GetPosition ( long *  x,
long *  y 
) const

Sets *x and *y to the position at which the event occurred.

Returns the physical mouse position in pixels.

Note that if the mouse event has been artificially generated from a special keyboard combination (e.g. under Windows when the "menu" key is pressed), the returned position is wxDefaultPosition.

void wxMouseEvent::GetPosition ( wxCoord x,
wxCoord y 
) const

Sets *x and *y to the position at which the event occurred.

Returns the physical mouse position in pixels.

Note that if the mouse event has been artificially generated from a special keyboard combination (e.g. under Windows when the "menu" key is pressed), the returned position is wxDefaultPosition.

wxPoint wxMouseEvent::GetPosition (  )  const

Sets *x and *y to the position at which the event occurred.

Returns the physical mouse position in pixels.

Note that if the mouse event has been artificially generated from a special keyboard combination (e.g. under Windows when the "menu" key is pressed), the returned position is wxDefaultPosition.

Reimplemented from wxMouseState.

int wxMouseEvent::GetWheelAxis (  )  const

Gets the axis the wheel operation concerns; 0 is the Y axis as on most mouse wheels, 1 is the X axis.

Note that only some models of mouse have horizontal wheel axis.

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.

wxCoord wxMouseEvent::GetX (  )  const

Returns X coordinate of the physical mouse event position.

Reimplemented from wxMouseState.

wxCoord wxMouseEvent::GetY (  )  const

Returns Y coordinate of the physical mouse event position.

Reimplemented from wxMouseState.

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::Leaving (  )  const

Returns true if the mouse was leaving the window.

See also:
Entering().

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.

Reimplemented from wxMouseState.

bool wxMouseEvent::LeftIsDown (  )  const

Returns true if the left mouse button is currently down, independent of the current event type.

Please notice that it is not the same as LeftDown() which returns true if the event was generated by the left mouse button being pressed. Rather, it simply describes the state of the left mouse button at the time when the event was generated (so while it will be true for a left click event, it can also be true for a right click if it happened while the left mouse button was pressed).

This event is usually used in the mouse event handlers which process "move mouse" messages to determine whether the user is (still) dragging the mouse.

bool wxMouseEvent::LeftUp (  )  const

Returns true if the left mouse button changed to up.

bool wxMouseEvent::MetaDown (  )  const

Returns true if the Meta key was down at the time of the event.

Reimplemented from wxKeyboardState.

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.

Reimplemented from wxMouseState.

bool wxMouseEvent::MiddleIsDown (  )  const

Returns true if the middle mouse button is currently down, independent of the current event type.

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.

Reimplemented from wxMouseState.

bool wxMouseEvent::RightIsDown (  )  const

Returns true if the right mouse button is currently down, independent of the current event type.

bool wxMouseEvent::RightUp (  )  const

Returns true if the right mouse button changed to up.



wxWidgets logo

[ top ]