]> git.saurik.com Git - wxWidgets.git/blob - include/wx/kbdstate.h
Merge in from trunk r68626 - r68683
[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 {
32 }
33
34 // default copy ctor, assignment operator and dtor are ok
35
36
37 // accessors for the various modifier keys
38 // ---------------------------------------
39
40 // should be used check if the key event has exactly the given modifiers:
41 // "GetModifiers() = wxMOD_CONTROL" is easier to write than "ControlDown()
42 // && !MetaDown() && !AltDown() && !ShiftDown()"
43 int GetModifiers() const
44 {
45 return (m_controlDown ? wxMOD_CONTROL : 0) |
46 (m_shiftDown ? wxMOD_SHIFT : 0) |
47 (m_metaDown ? wxMOD_META : 0) |
48 (m_altDown ? wxMOD_ALT : 0);
49 }
50
51 // returns true if any modifiers at all are pressed
52 bool HasModifiers() const { return GetModifiers() != wxMOD_NONE; }
53
54 // accessors for individual modifier keys
55 bool ControlDown() const { return m_controlDown; }
56 bool ShiftDown() const { return m_shiftDown; }
57 bool MetaDown() const { return m_metaDown; }
58 bool AltDown() const { return m_altDown; }
59
60 // "Cmd" is a pseudo key which is Control for PC and Unix platforms but
61 // Apple ("Command") key under Macs: it makes often sense to use it instead
62 // of, say, ControlDown() because Cmd key is used for the same thing under
63 // Mac as Ctrl elsewhere (but Ctrl still exists, just not used for this
64 // purpose under Mac)
65 bool CmdDown() const
66 {
67 #if defined(__WXMAC__) || defined(__WXCOCOA__)
68 return MetaDown();
69 #else
70 return ControlDown();
71 #endif
72 }
73
74 // these functions are mostly used by wxWidgets itself
75 // ---------------------------------------------------
76
77 void SetControlDown(bool down) { m_controlDown = down; }
78 void SetShiftDown(bool down) { m_shiftDown = down; }
79 void SetAltDown(bool down) { m_altDown = down; }
80 void SetMetaDown(bool down) { m_metaDown = down; }
81
82
83 // for backwards compatibility with the existing code accessing these
84 // members of wxKeyEvent directly, these variables are public, however you
85 // should not use them in any new code, please use the accessors instead
86 public:
87 bool m_controlDown : 1;
88 bool m_shiftDown : 1;
89 bool m_altDown : 1;
90 bool m_metaDown : 1;
91 };
92
93 #endif // _WX_KBDSTATE_H_
94