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