1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/mousestate.h
3 // Purpose: Declaration of wxMouseState class
4 // Author: Vadim Zeitlin
5 // Created: 2008-09-19 (extracted from wx/utils.h)
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_MOUSESTATE_H_
12 #define _WX_MOUSESTATE_H_
14 #include "wx/gdicmn.h" // for wxPoint
15 #include "wx/kbdstate.h"
17 // the symbolic names for the mouse buttons
23 wxMOUSE_BTN_MIDDLE
= 2,
24 wxMOUSE_BTN_RIGHT
= 3,
30 // ----------------------------------------------------------------------------
31 // wxMouseState contains the information about mouse position, buttons and also
33 // ----------------------------------------------------------------------------
35 // wxMouseState is used to hold information about button and modifier state
36 // and is what is returned from wxGetMouseState.
37 class WXDLLIMPEXP_CORE wxMouseState
: public wxKeyboardState
41 : m_leftDown(false), m_middleDown(false), m_rightDown(false),
42 m_aux1Down(false), m_aux2Down(false),
47 // default copy ctor, assignment operator and dtor are ok
50 // accessors for the mouse position
51 wxCoord
GetX() const { return m_x
; }
52 wxCoord
GetY() const { return m_y
; }
53 wxPoint
GetPosition() const { return wxPoint(m_x
, m_y
); }
54 void GetPosition(wxCoord
*x
, wxCoord
*y
) const
62 // this overload is for compatibility only
63 void GetPosition(long *x
, long *y
) const
71 // accessors for the pressed buttons
72 bool LeftIsDown() const { return m_leftDown
; }
73 bool MiddleIsDown() const { return m_middleDown
; }
74 bool RightIsDown() const { return m_rightDown
; }
75 bool Aux1IsDown() const { return m_aux1Down
; }
76 bool Aux2IsDown() const { return m_aux2Down
; }
78 bool ButtonIsDown(wxMouseButton but
) const
83 wxFAIL_MSG(wxT("invalid parameter in wxMouseState::ButtonIsDown"));
87 return LeftIsDown() || MiddleIsDown() || RightIsDown() ||
88 Aux1IsDown() || Aux2IsDown();
90 case wxMOUSE_BTN_LEFT
:
93 case wxMOUSE_BTN_MIDDLE
:
94 return MiddleIsDown();
96 case wxMOUSE_BTN_RIGHT
:
99 case wxMOUSE_BTN_AUX1
:
102 case wxMOUSE_BTN_AUX2
:
108 // these functions are mostly used by wxWidgets itself
109 void SetX(wxCoord x
) { m_x
= x
; }
110 void SetY(wxCoord y
) { m_y
= y
; }
111 void SetPosition(wxPoint pos
) { m_x
= pos
.x
, m_y
= pos
.y
; }
113 void SetLeftDown(bool down
) { m_leftDown
= down
; }
114 void SetMiddleDown(bool down
) { m_middleDown
= down
; }
115 void SetRightDown(bool down
) { m_rightDown
= down
; }
116 void SetAux1Down(bool down
) { m_aux1Down
= down
; }
117 void SetAux2Down(bool down
) { m_aux2Down
= down
; }
119 // this mostly makes sense in the derived classes such as wxMouseEvent
120 void SetState(const wxMouseState
& state
) { *this = state
; }
122 // these functions are for compatibility only, they were used in 2.8
123 // version of wxMouseState but their names are confusing as wxMouseEvent
124 // has methods with the same names which do something quite different so
125 // don't use them any more
126 #ifdef WXWIN_COMPATIBILITY_2_8
127 wxDEPRECATED_INLINE(bool LeftDown() const, return LeftIsDown(); )
128 wxDEPRECATED_INLINE(bool MiddleDown() const, return MiddleIsDown(); )
129 wxDEPRECATED_INLINE(bool RightDown() const, return RightIsDown(); )
130 #endif // WXWIN_COMPATIBILITY_2_8
132 // for compatibility reasons these variables are public as the code using
133 // wxMouseEvent often uses them directly -- however they should not be
134 // accessed directly in this class, use the accessors above instead
137 bool m_middleDown
: 1;
138 bool m_rightDown
: 1;
146 #endif // _WX_MOUSESTATE_H_