]> git.saurik.com Git - wxWidgets.git/blame - include/wx/kbdstate.h
fixing type for key event, using WXK_RAW_CONTROL constant for controlkey, see #13415
[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
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
20class WXDLLIMPEXP_CORE wxKeyboardState
21{
22public:
ba4d737a
VZ
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)
0e097789
VZ
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) |
8b9e0938 48 (m_rawControlDown ? wxMOD_RAW_CONTROL : 0) |
0e097789
VZ
49 (m_altDown ? wxMOD_ALT : 0);
50 }
51
52 // returns true if any modifiers at all are pressed
53 bool HasModifiers() const { return GetModifiers() != wxMOD_NONE; }
54
55 // accessors for individual modifier keys
56 bool ControlDown() const { return m_controlDown; }
8b9e0938
SC
57 bool RawControlDown() const
58 {
59#ifdef __WXOSX__
60 return m_rawControlDown;
61#else
62 return m_controlDown;
63#endif
64 }
0e097789
VZ
65 bool ShiftDown() const { return m_shiftDown; }
66 bool MetaDown() const { return m_metaDown; }
67 bool AltDown() const { return m_altDown; }
68
69 // "Cmd" is a pseudo key which is Control for PC and Unix platforms but
70 // Apple ("Command") key under Macs: it makes often sense to use it instead
71 // of, say, ControlDown() because Cmd key is used for the same thing under
72 // Mac as Ctrl elsewhere (but Ctrl still exists, just not used for this
73 // purpose under Mac)
74 bool CmdDown() const
75 {
0e097789 76 return ControlDown();
0e097789
VZ
77 }
78
79 // these functions are mostly used by wxWidgets itself
80 // ---------------------------------------------------
81
82 void SetControlDown(bool down) { m_controlDown = down; }
8b9e0938
SC
83 void SetRawControlDown(bool down)
84 {
85#ifdef __WXOSX__
86 m_rawControlDown = down;
87#else
88 m_controlDown = down;
89#endif
90 }
0e097789
VZ
91 void SetShiftDown(bool down) { m_shiftDown = down; }
92 void SetAltDown(bool down) { m_altDown = down; }
93 void SetMetaDown(bool down) { m_metaDown = down; }
94
95
96 // for backwards compatibility with the existing code accessing these
97 // members of wxKeyEvent directly, these variables are public, however you
98 // should not use them in any new code, please use the accessors instead
99public:
8b9e0938
SC
100 bool m_controlDown : 1;
101 bool m_shiftDown : 1;
102 bool m_altDown : 1;
103 bool m_metaDown : 1;
104#ifdef __WXOSX__
105 bool m_rawControlDown : 1;
106#endif
0e097789
VZ
107};
108
109#endif // _WX_KBDSTATE_H_
110