make wxKeyEvent and wxMouseEvent derive from the same wxKeyboardState object (indirec...
[wxWidgets.git] / include / wx / kbdstate.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/kbdstate.h
3 // Purpose: Declaration of wxKeyboardState class
4 // Author: Vadim Zeitlin
5 // Created: 2008-09-19
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_KBDSTATE_H_
12 #define _WX_KBDSTATE_H_
13
14 #include "wx/defs.h"
15
16 // ----------------------------------------------------------------------------
17 // wxKeyboardState stores the state of the keyboard modifier keys
18 // ----------------------------------------------------------------------------
19
20 class WXDLLIMPEXP_CORE wxKeyboardState
21 {
22 public:
23 wxKeyboardState()
24 : m_controlDown(false),
25 m_shiftDown(false),
26 m_altDown(false),
27 m_metaDown(false)
28 {
29 }
30
31 // default copy ctor, assignment operator and dtor are ok
32
33
34 // accessors for the various modifier keys
35 // ---------------------------------------
36
37 // should be used check if the key event has exactly the given modifiers:
38 // "GetModifiers() = wxMOD_CONTROL" is easier to write than "ControlDown()
39 // && !MetaDown() && !AltDown() && !ShiftDown()"
40 int GetModifiers() const
41 {
42 return (m_controlDown ? wxMOD_CONTROL : 0) |
43 (m_shiftDown ? wxMOD_SHIFT : 0) |
44 (m_metaDown ? wxMOD_META : 0) |
45 (m_altDown ? wxMOD_ALT : 0);
46 }
47
48 // returns true if any modifiers at all are pressed
49 bool HasModifiers() const { return GetModifiers() != wxMOD_NONE; }
50
51 // accessors for individual modifier keys
52 bool ControlDown() const { return m_controlDown; }
53 bool ShiftDown() const { return m_shiftDown; }
54 bool MetaDown() const { return m_metaDown; }
55 bool AltDown() const { return m_altDown; }
56
57 // "Cmd" is a pseudo key which is Control for PC and Unix platforms but
58 // Apple ("Command") key under Macs: it makes often sense to use it instead
59 // of, say, ControlDown() because Cmd key is used for the same thing under
60 // Mac as Ctrl elsewhere (but Ctrl still exists, just not used for this
61 // purpose under Mac)
62 bool CmdDown() const
63 {
64 #if defined(__WXMAC__) || defined(__WXCOCOA__)
65 return MetaDown();
66 #else
67 return ControlDown();
68 #endif
69 }
70
71 // these functions are mostly used by wxWidgets itself
72 // ---------------------------------------------------
73
74 void SetControlDown(bool down) { m_controlDown = down; }
75 void SetShiftDown(bool down) { m_shiftDown = down; }
76 void SetAltDown(bool down) { m_altDown = down; }
77 void SetMetaDown(bool down) { m_metaDown = down; }
78
79
80 // for backwards compatibility with the existing code accessing these
81 // members of wxKeyEvent directly, these variables are public, however you
82 // should not use them in any new code, please use the accessors instead
83 public:
84 bool m_controlDown : 1;
85 bool m_shiftDown : 1;
86 bool m_altDown : 1;
87 bool m_metaDown : 1;
88 };
89
90 #endif // _WX_KBDSTATE_H_
91