mousestate.h 4.7 KB

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