]> git.saurik.com Git - wxWidgets.git/blame - include/wx/kbdstate.h
wxRTC: fixed guidelines overwriting adjacent cell borders; corrected capitalisation...
[wxWidgets.git] / include / wx / kbdstate.h
CommitLineData
0e097789
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/kbdstate.h
3// Purpose: Declaration of wxKeyboardState class
4// Author: Vadim Zeitlin
5// Created: 2008-09-19
0e097789
VZ
6// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
7// Licence: wxWindows licence
8///////////////////////////////////////////////////////////////////////////////
9
10#ifndef _WX_KBDSTATE_H_
11#define _WX_KBDSTATE_H_
12
13#include "wx/defs.h"
14
15// ----------------------------------------------------------------------------
16// wxKeyboardState stores the state of the keyboard modifier keys
17// ----------------------------------------------------------------------------
18
19class WXDLLIMPEXP_CORE wxKeyboardState
20{
21public:
ba4d737a
VZ
22 wxKeyboardState(bool controlDown = false,
23 bool shiftDown = false,
24 bool altDown = false,
25 bool metaDown = false)
26 : m_controlDown(controlDown),
27 m_shiftDown(shiftDown),
28 m_altDown(altDown),
29 m_metaDown(metaDown)
85a17748
SC
30#ifdef __WXOSX__
31 ,m_rawControlDown(false)
32#endif
0e097789
VZ
33 {
34 }
35
36 // default copy ctor, assignment operator and dtor are ok
37
38
39 // accessors for the various modifier keys
40 // ---------------------------------------
41
42 // should be used check if the key event has exactly the given modifiers:
43 // "GetModifiers() = wxMOD_CONTROL" is easier to write than "ControlDown()
44 // && !MetaDown() && !AltDown() && !ShiftDown()"
45 int GetModifiers() const
46 {
47 return (m_controlDown ? wxMOD_CONTROL : 0) |
48 (m_shiftDown ? wxMOD_SHIFT : 0) |
49 (m_metaDown ? wxMOD_META : 0) |
c66160d5 50#ifdef __WXOSX__
8b9e0938 51 (m_rawControlDown ? wxMOD_RAW_CONTROL : 0) |
c66160d5 52#endif
0e097789
VZ
53 (m_altDown ? wxMOD_ALT : 0);
54 }
55
56 // returns true if any modifiers at all are pressed
756ead6f
VZ
57 bool HasAnyModifiers() const { return GetModifiers() != wxMOD_NONE; }
58
59 // returns true if any modifiers changing the usual key interpretation are
60 // pressed, notably excluding Shift
61 bool HasModifiers() const
62 {
63 return ControlDown() || RawControlDown() || AltDown();
64 }
0e097789
VZ
65
66 // accessors for individual modifier keys
67 bool ControlDown() const { return m_controlDown; }
8b9e0938
SC
68 bool RawControlDown() const
69 {
70#ifdef __WXOSX__
71 return m_rawControlDown;
72#else
73 return m_controlDown;
74#endif
75 }
0e097789
VZ
76 bool ShiftDown() const { return m_shiftDown; }
77 bool MetaDown() const { return m_metaDown; }
78 bool AltDown() const { return m_altDown; }
79
80 // "Cmd" is a pseudo key which is Control for PC and Unix platforms but
81 // Apple ("Command") key under Macs: it makes often sense to use it instead
82 // of, say, ControlDown() because Cmd key is used for the same thing under
83 // Mac as Ctrl elsewhere (but Ctrl still exists, just not used for this
84 // purpose under Mac)
85 bool CmdDown() const
86 {
0e097789 87 return ControlDown();
0e097789
VZ
88 }
89
90 // these functions are mostly used by wxWidgets itself
91 // ---------------------------------------------------
92
93 void SetControlDown(bool down) { m_controlDown = down; }
8b9e0938
SC
94 void SetRawControlDown(bool down)
95 {
96#ifdef __WXOSX__
97 m_rawControlDown = down;
98#else
99 m_controlDown = down;
100#endif
101 }
0e097789
VZ
102 void SetShiftDown(bool down) { m_shiftDown = down; }
103 void SetAltDown(bool down) { m_altDown = down; }
104 void SetMetaDown(bool down) { m_metaDown = down; }
105
106
107 // for backwards compatibility with the existing code accessing these
108 // members of wxKeyEvent directly, these variables are public, however you
109 // should not use them in any new code, please use the accessors instead
110public:
8b9e0938
SC
111 bool m_controlDown : 1;
112 bool m_shiftDown : 1;
113 bool m_altDown : 1;
114 bool m_metaDown : 1;
115#ifdef __WXOSX__
116 bool m_rawControlDown : 1;
117#endif
0e097789
VZ
118};
119
120#endif // _WX_KBDSTATE_H_
121