]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mousestate.h
When handling accelerators in wxWebView make sure that we do not block right-alt...
[wxWidgets.git] / include / wx / mousestate.h
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)
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_MOUSESTATE_H_
12 #define _WX_MOUSESTATE_H_
13
14 #include "wx/gdicmn.h" // for wxPoint
15 #include "wx/kbdstate.h"
16
17 // the symbolic names for the mouse buttons
18 enum wxMouseButton
19 {
20 wxMOUSE_BTN_ANY = -1,
21 wxMOUSE_BTN_NONE = 0,
22 wxMOUSE_BTN_LEFT = 1,
23 wxMOUSE_BTN_MIDDLE = 2,
24 wxMOUSE_BTN_RIGHT = 3,
25 wxMOUSE_BTN_AUX1 = 4,
26 wxMOUSE_BTN_AUX2 = 5,
27 wxMOUSE_BTN_MAX
28 };
29
30 // ----------------------------------------------------------------------------
31 // wxMouseState contains the information about mouse position, buttons and also
32 // key modifiers
33 // ----------------------------------------------------------------------------
34
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
38 {
39 public:
40 wxMouseState()
41 : m_leftDown(false), m_middleDown(false), m_rightDown(false),
42 m_aux1Down(false), m_aux2Down(false),
43 m_x(0), m_y(0)
44 {
45 }
46
47 // default copy ctor, assignment operator and dtor are ok
48
49
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
55 {
56 if ( x )
57 *x = m_x;
58 if ( y )
59 *y = m_y;
60 }
61
62 // this overload is for compatibility only
63 void GetPosition(long *x, long *y) const
64 {
65 if ( x )
66 *x = m_x;
67 if ( y )
68 *y = m_y;
69 }
70
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; }
77
78 bool ButtonIsDown(wxMouseButton but) const
79 {
80 switch ( but )
81 {
82 case wxMOUSE_BTN_ANY:
83 return LeftIsDown() || MiddleIsDown() || RightIsDown() ||
84 Aux1IsDown() || Aux2IsDown();
85
86 case wxMOUSE_BTN_LEFT:
87 return LeftIsDown();
88
89 case wxMOUSE_BTN_MIDDLE:
90 return MiddleIsDown();
91
92 case wxMOUSE_BTN_RIGHT:
93 return RightIsDown();
94
95 case wxMOUSE_BTN_AUX1:
96 return Aux1IsDown();
97
98 case wxMOUSE_BTN_AUX2:
99 return Aux2IsDown();
100
101 case wxMOUSE_BTN_NONE:
102 case wxMOUSE_BTN_MAX:
103 wxFAIL_MSG(wxS("invalid parameter"));
104 return false;
105
106 default:
107 wxFAIL_MSG(wxS("unknown parameter"));
108 return false;
109 }
110 }
111
112
113 // these functions are mostly used by wxWidgets itself
114 void SetX(wxCoord x) { m_x = x; }
115 void SetY(wxCoord y) { m_y = y; }
116 void SetPosition(wxPoint pos) { m_x = pos.x, m_y = pos.y; }
117
118 void SetLeftDown(bool down) { m_leftDown = down; }
119 void SetMiddleDown(bool down) { m_middleDown = down; }
120 void SetRightDown(bool down) { m_rightDown = down; }
121 void SetAux1Down(bool down) { m_aux1Down = down; }
122 void SetAux2Down(bool down) { m_aux2Down = down; }
123
124 // this mostly makes sense in the derived classes such as wxMouseEvent
125 void SetState(const wxMouseState& state) { *this = state; }
126
127 // these functions are for compatibility only, they were used in 2.8
128 // version of wxMouseState but their names are confusing as wxMouseEvent
129 // has methods with the same names which do something quite different so
130 // don't use them any more
131 #if WXWIN_COMPATIBILITY_2_8
132 wxDEPRECATED_INLINE(bool LeftDown() const, return LeftIsDown(); )
133 wxDEPRECATED_INLINE(bool MiddleDown() const, return MiddleIsDown(); )
134 wxDEPRECATED_INLINE(bool RightDown() const, return RightIsDown(); )
135 #endif // WXWIN_COMPATIBILITY_2_8
136
137 // for compatibility reasons these variables are public as the code using
138 // wxMouseEvent often uses them directly -- however they should not be
139 // accessed directly in this class, use the accessors above instead
140 // private:
141 bool m_leftDown : 1;
142 bool m_middleDown : 1;
143 bool m_rightDown : 1;
144 bool m_aux1Down : 1;
145 bool m_aux2Down : 1;
146
147 wxCoord m_x,
148 m_y;
149 };
150
151 #endif // _WX_MOUSESTATE_H_
152