don't duplicate wxMouseState in wxMouseEvent but reuse its methods and variables (somehow this was never done when wxMouseState was introduced)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60433 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
8f1a82e6bb
commit
ab826fd86f
@ -1228,19 +1228,6 @@ private:
|
||||
wxEVT_NC_RIGHT_DCLICK,
|
||||
*/
|
||||
|
||||
// the symbolic names for the mouse buttons
|
||||
enum
|
||||
{
|
||||
wxMOUSE_BTN_ANY = -1,
|
||||
wxMOUSE_BTN_NONE = 0,
|
||||
wxMOUSE_BTN_LEFT = 1,
|
||||
wxMOUSE_BTN_MIDDLE = 2,
|
||||
wxMOUSE_BTN_RIGHT = 3,
|
||||
wxMOUSE_BTN_AUX1 = 4,
|
||||
wxMOUSE_BTN_AUX2 = 5,
|
||||
wxMOUSE_BTN_MAX
|
||||
};
|
||||
|
||||
class WXDLLIMPEXP_CORE wxMouseEvent : public wxEvent,
|
||||
public wxMouseState
|
||||
{
|
||||
@ -1265,12 +1252,9 @@ public:
|
||||
// Was it a up event from this (or any) button?
|
||||
bool ButtonUp(int but = wxMOUSE_BTN_ANY) const;
|
||||
|
||||
// Was the given button?
|
||||
// Was this event generated by the given button?
|
||||
bool Button(int but) const;
|
||||
|
||||
// Was the given button in Down state?
|
||||
bool ButtonIsDown(int but) const;
|
||||
|
||||
// Get the button which is changing state (wxMOUSE_BTN_NONE if none)
|
||||
int GetButton() const;
|
||||
|
||||
@ -1293,14 +1277,6 @@ public:
|
||||
bool Aux1DClick() const { return (m_eventType == wxEVT_AUX1_UP); }
|
||||
bool Aux2DClick() const { return (m_eventType == wxEVT_AUX2_UP); }
|
||||
|
||||
// Find the current state of the mouse buttons (regardless
|
||||
// of current event type)
|
||||
bool LeftIsDown() const { return m_leftDown; }
|
||||
bool MiddleIsDown() const { return m_middleDown; }
|
||||
bool RightIsDown() const { return m_rightDown; }
|
||||
bool Aux1IsDown() const { return m_aux1Down; }
|
||||
bool Aux2IsDown() const { return m_aux2Down; }
|
||||
|
||||
// True if a button is down and the mouse is moving
|
||||
bool Dragging() const
|
||||
{
|
||||
@ -1322,36 +1298,9 @@ public:
|
||||
// Returns the number of mouse clicks associated with this event.
|
||||
int GetClickCount() const { return m_clickCount; }
|
||||
|
||||
|
||||
// Find the position of the event
|
||||
void GetPosition(wxCoord *xpos, wxCoord *ypos) const
|
||||
{
|
||||
if (xpos)
|
||||
*xpos = m_x;
|
||||
if (ypos)
|
||||
*ypos = m_y;
|
||||
}
|
||||
|
||||
void GetPosition(long *xpos, long *ypos) const
|
||||
{
|
||||
if (xpos)
|
||||
*xpos = (long)m_x;
|
||||
if (ypos)
|
||||
*ypos = (long)m_y;
|
||||
}
|
||||
|
||||
// Find the position of the event
|
||||
wxPoint GetPosition() const { return wxPoint(m_x, m_y); }
|
||||
|
||||
// Find the logical position of the event given the DC
|
||||
wxPoint GetLogicalPosition(const wxDC& dc) const;
|
||||
|
||||
// Get X position
|
||||
wxCoord GetX() const { return m_x; }
|
||||
|
||||
// Get Y position
|
||||
wxCoord GetY() const { return m_y; }
|
||||
|
||||
// Get wheel rotation, positive or negative indicates direction of
|
||||
// rotation. Current devices all send an event when rotation is equal to
|
||||
// +/-WheelDelta, but this allows for finer resolution devices to be
|
||||
@ -1389,14 +1338,6 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
wxCoord m_x, m_y;
|
||||
|
||||
bool m_leftDown;
|
||||
bool m_middleDown;
|
||||
bool m_rightDown;
|
||||
bool m_aux1Down;
|
||||
bool m_aux2Down;
|
||||
|
||||
int m_clickCount;
|
||||
|
||||
int m_wheelAxis;
|
||||
|
@ -13,6 +13,19 @@
|
||||
|
||||
#include "wx/kbdstate.h"
|
||||
|
||||
// the symbolic names for the mouse buttons
|
||||
enum wxMouseButton
|
||||
{
|
||||
wxMOUSE_BTN_ANY = -1,
|
||||
wxMOUSE_BTN_NONE = 0,
|
||||
wxMOUSE_BTN_LEFT = 1,
|
||||
wxMOUSE_BTN_MIDDLE = 2,
|
||||
wxMOUSE_BTN_RIGHT = 3,
|
||||
wxMOUSE_BTN_AUX1 = 4,
|
||||
wxMOUSE_BTN_AUX2 = 5,
|
||||
wxMOUSE_BTN_MAX
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMouseState contains the information about mouse position, buttons and also
|
||||
// key modifiers
|
||||
@ -37,17 +50,64 @@ public:
|
||||
wxCoord GetX() const { return m_x; }
|
||||
wxCoord GetY() const { return m_y; }
|
||||
wxPoint GetPosition() const { return wxPoint(m_x, m_y); }
|
||||
void GetPosition(wxCoord *x, wxCoord *y) const
|
||||
{
|
||||
if ( x )
|
||||
*x = m_x;
|
||||
if ( y )
|
||||
*y = m_y;
|
||||
}
|
||||
|
||||
// this overload is for compatibility only
|
||||
void GetPosition(long *x, long *y) const
|
||||
{
|
||||
if ( x )
|
||||
*x = m_x;
|
||||
if ( y )
|
||||
*y = m_y;
|
||||
}
|
||||
|
||||
// accessors for the pressed buttons
|
||||
bool LeftDown() const { return m_leftDown; }
|
||||
bool MiddleDown() const { return m_middleDown; }
|
||||
bool RightDown() const { return m_rightDown; }
|
||||
bool Aux1Down() const { return m_aux1Down; }
|
||||
bool Aux2Down() const { return m_aux2Down; }
|
||||
bool LeftIsDown() const { return m_leftDown; }
|
||||
bool MiddleIsDown() const { return m_middleDown; }
|
||||
bool RightIsDown() const { return m_rightDown; }
|
||||
bool Aux1IsDown() const { return m_aux1Down; }
|
||||
bool Aux2IsDown() const { return m_aux2Down; }
|
||||
|
||||
bool ButtonIsDown(wxMouseButton but) const
|
||||
{
|
||||
switch ( but )
|
||||
{
|
||||
default:
|
||||
wxFAIL_MSG(wxT("invalid parameter in wxMouseState::ButtonIsDown"));
|
||||
// fall through
|
||||
|
||||
case wxMOUSE_BTN_ANY:
|
||||
return LeftIsDown() || MiddleIsDown() || RightIsDown() ||
|
||||
Aux1IsDown() || Aux2IsDown();
|
||||
|
||||
case wxMOUSE_BTN_LEFT:
|
||||
return LeftIsDown();
|
||||
|
||||
case wxMOUSE_BTN_MIDDLE:
|
||||
return MiddleIsDown();
|
||||
|
||||
case wxMOUSE_BTN_RIGHT:
|
||||
return RightIsDown();
|
||||
|
||||
case wxMOUSE_BTN_AUX1:
|
||||
return Aux1IsDown();
|
||||
|
||||
case wxMOUSE_BTN_AUX2:
|
||||
return Aux2IsDown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// these functions are mostly used by wxWidgets itself
|
||||
void SetX(wxCoord x) { m_x = x; }
|
||||
void SetY(wxCoord y) { m_y = y; }
|
||||
void SetPosition(wxPoint pos) { m_x = pos.x, m_y = pos.y; }
|
||||
|
||||
void SetLeftDown(bool down) { m_leftDown = down; }
|
||||
void SetMiddleDown(bool down) { m_middleDown = down; }
|
||||
@ -55,7 +115,14 @@ public:
|
||||
void SetAux1Down(bool down) { m_aux1Down = down; }
|
||||
void SetAux2Down(bool down) { m_aux2Down = down; }
|
||||
|
||||
private:
|
||||
// this mostly makes sense in the derived classes such as wxMouseEvent
|
||||
void SetState(const wxMouseState& state) { *this = state; }
|
||||
|
||||
|
||||
// for compatibility reasons these variables are public as the code using
|
||||
// wxMouseEvent often uses them directly -- however they should not be
|
||||
// accessed directly in this class, use the accessors above instead
|
||||
// private:
|
||||
bool m_leftDown : 1;
|
||||
bool m_middleDown : 1;
|
||||
bool m_rightDown : 1;
|
||||
|
@ -1873,14 +1873,16 @@ public:
|
||||
left the window and the state variables for it may have changed during this time.
|
||||
|
||||
@note 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.
|
||||
the inherited wxMouseState::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.
|
||||
|
||||
|
||||
@beginEventTable{wxMouseEvent}
|
||||
@ -1972,12 +1974,6 @@ public:
|
||||
*/
|
||||
bool Aux1Down() const;
|
||||
|
||||
/**
|
||||
Returns @true if the first extra button mouse button is currently down,
|
||||
independent of the current event type.
|
||||
*/
|
||||
bool Aux1IsDown() const;
|
||||
|
||||
/**
|
||||
Returns @true if the first extra button mouse button changed to up.
|
||||
*/
|
||||
@ -1993,52 +1989,38 @@ public:
|
||||
*/
|
||||
bool Aux2Down() const;
|
||||
|
||||
/**
|
||||
Returns @true if the second extra button mouse button is currently down,
|
||||
independent of the current event type.
|
||||
*/
|
||||
bool Aux2IsDown() const;
|
||||
|
||||
/**
|
||||
Returns @true if the second extra button mouse button changed to up.
|
||||
*/
|
||||
bool Aux2Up() const;
|
||||
|
||||
/**
|
||||
Returns @true if the identified mouse button is changing state.
|
||||
Valid values of @a button are:
|
||||
Returns @true if the event was generated by the specified button.
|
||||
|
||||
@li @c wxMOUSE_BTN_LEFT: check if left button was pressed
|
||||
@li @c wxMOUSE_BTN_MIDDLE: check if middle button was pressed
|
||||
@li @c wxMOUSE_BTN_RIGHT: check if right button was pressed
|
||||
@li @c wxMOUSE_BTN_AUX1: check if the first extra button was pressed
|
||||
@li @c wxMOUSE_BTN_AUX2: check if the second extra button was pressed
|
||||
@li @c wxMOUSE_BTN_ANY: check if any button was pressed
|
||||
|
||||
@todo introduce wxMouseButton enum
|
||||
@see wxMouseState::ButtoinIsDown()
|
||||
*/
|
||||
bool Button(int button) const;
|
||||
bool Button(wxMouseButton but) 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 ButtonDClick(int but = wxMOUSE_BTN_ANY) const;
|
||||
bool ButtonDClick(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 ButtonDown(int = wxMOUSE_BTN_ANY) const;
|
||||
bool ButtonDown(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 ButtonUp(int = wxMOUSE_BTN_ANY) const;
|
||||
bool ButtonUp(wxMouseButton but = wxMOUSE_BTN_ANY) const;
|
||||
|
||||
/**
|
||||
Returns @true if this was a dragging event (motion while a button is depressed).
|
||||
@ -2088,20 +2070,6 @@ public:
|
||||
*/
|
||||
wxPoint GetLogicalPosition(const wxDC& dc) 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 GetPosition() const;
|
||||
void GetPosition(wxCoord* x, wxCoord* y) const;
|
||||
void GetPosition(long* x, long* y) const;
|
||||
//@}
|
||||
|
||||
/**
|
||||
Get wheel delta, normally 120.
|
||||
|
||||
@ -2130,16 +2098,6 @@ public:
|
||||
*/
|
||||
int GetWheelAxis() const;
|
||||
|
||||
/**
|
||||
Returns X coordinate of the physical mouse event position.
|
||||
*/
|
||||
wxCoord GetX() const;
|
||||
|
||||
/**
|
||||
Returns Y coordinate of the physical mouse event position.
|
||||
*/
|
||||
wxCoord GetY() const;
|
||||
|
||||
/**
|
||||
Returns @true if the event was a mouse button event (not necessarily a button
|
||||
down event - that may be tested using ButtonDown()).
|
||||
@ -2169,21 +2127,6 @@ public:
|
||||
*/
|
||||
bool LeftDown() 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 LeftIsDown() const;
|
||||
|
||||
/**
|
||||
Returns @true if the left mouse button changed to up.
|
||||
*/
|
||||
@ -2204,12 +2147,6 @@ public:
|
||||
*/
|
||||
bool MiddleDown() const;
|
||||
|
||||
/**
|
||||
Returns @true if the middle mouse button is currently down, independent
|
||||
of the current event type.
|
||||
*/
|
||||
bool MiddleIsDown() const;
|
||||
|
||||
/**
|
||||
Returns @true if the middle mouse button changed to up.
|
||||
*/
|
||||
@ -2232,12 +2169,6 @@ public:
|
||||
*/
|
||||
bool RightDown() const;
|
||||
|
||||
/**
|
||||
Returns @true if the right mouse button is currently down, independent
|
||||
of the current event type.
|
||||
*/
|
||||
bool RightIsDown() const;
|
||||
|
||||
/**
|
||||
Returns @true if the right mouse button changed to up.
|
||||
*/
|
||||
|
@ -7,6 +7,34 @@
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// Symbolic names for the mouse buttons.
|
||||
enum wxMouseButton
|
||||
{
|
||||
/// Any mouse button, means to check for any button being pressed for
|
||||
/// example.
|
||||
wxMOUSE_BTN_ANY = -1,
|
||||
|
||||
/// None of the mouse buttons.
|
||||
wxMOUSE_BTN_NONE = 0,
|
||||
|
||||
/// Left mouse button.
|
||||
wxMOUSE_BTN_LEFT = 1,
|
||||
|
||||
/// Middle mouse button.
|
||||
wxMOUSE_BTN_MIDDLE = 2,
|
||||
|
||||
/// Right mouse button.
|
||||
wxMOUSE_BTN_RIGHT = 3,
|
||||
|
||||
/// First additional mouse button.
|
||||
wxMOUSE_BTN_AUX1 = 4,
|
||||
|
||||
/// Second additional mouse button.
|
||||
wxMOUSE_BTN_AUX2 = 5,
|
||||
|
||||
wxMOUSE_BTN_MAX
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@class wxMouseState
|
||||
@ -47,32 +75,35 @@ public:
|
||||
/**
|
||||
Returns the physical mouse position.
|
||||
*/
|
||||
//@{
|
||||
wxPoint GetPosition() const;
|
||||
void GetPosition(int *x, int *y) const;
|
||||
//@}
|
||||
|
||||
/**
|
||||
Returns @true if the left mouse button changed to down.
|
||||
Returns @true if the left mouse button is currently down.
|
||||
*/
|
||||
bool LeftDown() const;
|
||||
bool LeftIsDown() const;
|
||||
|
||||
/**
|
||||
Returns @true if the middle mouse button changed to down.
|
||||
Returns @true if the middle mouse button is currently down.
|
||||
*/
|
||||
bool MiddleDown() const;
|
||||
bool MiddleIsDown() const;
|
||||
|
||||
/**
|
||||
Returns @true if the right mouse button changed to down.
|
||||
Returns @true if the right mouse button is currently down.
|
||||
*/
|
||||
bool RightDown() const;
|
||||
bool RightIsDown() const;
|
||||
|
||||
/**
|
||||
Returns @true if the first extra button mouse button changed to down.
|
||||
Returns @true if the first extra button mouse button is currently down.
|
||||
*/
|
||||
bool Aux1Down() const;
|
||||
bool Aux1IsDown() const;
|
||||
|
||||
/**
|
||||
Returns @true if the second extra button mouse button changed to down.
|
||||
Returns @true if the second extra button mouse button is currently down.
|
||||
*/
|
||||
bool Aux2Down() const;
|
||||
bool Aux2IsDown() const;
|
||||
};
|
||||
|
||||
|
||||
|
@ -703,34 +703,6 @@ bool wxMouseEvent::Button(int but) const
|
||||
}
|
||||
}
|
||||
|
||||
bool wxMouseEvent::ButtonIsDown(int but) const
|
||||
{
|
||||
switch (but)
|
||||
{
|
||||
default:
|
||||
wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
|
||||
// fall through
|
||||
|
||||
case wxMOUSE_BTN_ANY:
|
||||
return LeftIsDown() || MiddleIsDown() || RightIsDown() || Aux1Down() || Aux2Down();
|
||||
|
||||
case wxMOUSE_BTN_LEFT:
|
||||
return LeftIsDown();
|
||||
|
||||
case wxMOUSE_BTN_MIDDLE:
|
||||
return MiddleIsDown();
|
||||
|
||||
case wxMOUSE_BTN_RIGHT:
|
||||
return RightIsDown();
|
||||
|
||||
case wxMOUSE_BTN_AUX1:
|
||||
return Aux1IsDown();
|
||||
|
||||
case wxMOUSE_BTN_AUX2:
|
||||
return Aux2IsDown();
|
||||
}
|
||||
}
|
||||
|
||||
int wxMouseEvent::GetButton() const
|
||||
{
|
||||
for ( int i = 1; i < wxMOUSE_BTN_MAX; i++ )
|
||||
|
Loading…
Reference in New Issue
Block a user