]> git.saurik.com Git - wxWidgets.git/blob - include/wx/kbdstate.h
support SDK < 10.6, fixes #14902
[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(bool controlDown = false,
24 bool shiftDown = false,
25 bool altDown = false,
26 bool metaDown = false)
27 : m_controlDown(controlDown),
28 m_shiftDown(shiftDown),
29 m_altDown(altDown),
30 m_metaDown(metaDown)
31 #ifdef __WXOSX__
32 ,m_rawControlDown(false)
33 #endif
34 {
35 }
36
37 // default copy ctor, assignment operator and dtor are ok
38
39
40 // accessors for the various modifier keys
41 // ---------------------------------------
42
43 // should be used check if the key event has exactly the given modifiers:
44 // "GetModifiers() = wxMOD_CONTROL" is easier to write than "ControlDown()
45 // && !MetaDown() && !AltDown() && !ShiftDown()"
46 int GetModifiers() const
47 {
48 return (m_controlDown ? wxMOD_CONTROL : 0) |
49 (m_shiftDown ? wxMOD_SHIFT : 0) |
50 (m_metaDown ? wxMOD_META : 0) |
51 #ifdef __WXOSX__
52 (m_rawControlDown ? wxMOD_RAW_CONTROL : 0) |
53 #endif
54 (m_altDown ? wxMOD_ALT : 0);
55 }
56
57 // returns true if any modifiers at all are pressed
58 bool HasAnyModifiers() const { return GetModifiers() != wxMOD_NONE; }
59
60 // returns true if any modifiers changing the usual key interpretation are
61 // pressed, notably excluding Shift
62 bool HasModifiers() const
63 {
64 return ControlDown() || RawControlDown() || AltDown();
65 }
66
67 // accessors for individual modifier keys
68 bool ControlDown() const { return m_controlDown; }
69 bool RawControlDown() const
70 {
71 #ifdef __WXOSX__
72 return m_rawControlDown;
73 #else
74 return m_controlDown;
75 #endif
76 }
77 bool ShiftDown() const { return m_shiftDown; }
78 bool MetaDown() const { return m_metaDown; }
79 bool AltDown() const { return m_altDown; }
80
81 // "Cmd" is a pseudo key which is Control for PC and Unix platforms but
82 // Apple ("Command") key under Macs: it makes often sense to use it instead
83 // of, say, ControlDown() because Cmd key is used for the same thing under
84 // Mac as Ctrl elsewhere (but Ctrl still exists, just not used for this
85 // purpose under Mac)
86 bool CmdDown() const
87 {
88 return ControlDown();
89 }
90
91 // these functions are mostly used by wxWidgets itself
92 // ---------------------------------------------------
93
94 void SetControlDown(bool down) { m_controlDown = down; }
95 void SetRawControlDown(bool down)
96 {
97 #ifdef __WXOSX__
98 m_rawControlDown = down;
99 #else
100 m_controlDown = down;
101 #endif
102 }
103 void SetShiftDown(bool down) { m_shiftDown = down; }
104 void SetAltDown(bool down) { m_altDown = down; }
105 void SetMetaDown(bool down) { m_metaDown = down; }
106
107
108 // for backwards compatibility with the existing code accessing these
109 // members of wxKeyEvent directly, these variables are public, however you
110 // should not use them in any new code, please use the accessors instead
111 public:
112 bool m_controlDown : 1;
113 bool m_shiftDown : 1;
114 bool m_altDown : 1;
115 bool m_metaDown : 1;
116 #ifdef __WXOSX__
117 bool m_rawControlDown : 1;
118 #endif
119 };
120
121 #endif // _WX_KBDSTATE_H_
122