]>
Commit | Line | Data |
---|---|---|
1e6feb95 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/accel.h | |
3 | // Purpose: wxAcceleratorEntry and wxAcceleratorTable classes | |
4 | // Author: Julian Smart, Robert Roebling, Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 31.05.01 (extracted from other files) | |
7 | // RCS-ID: $Id$ | |
77ffb593 | 8 | // Copyright: (c) wxWidgets team |
65571936 | 9 | // Licence: wxWindows licence |
1e6feb95 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_ACCEL_H_BASE_ |
13 | #define _WX_ACCEL_H_BASE_ | |
14 | ||
1e6feb95 VZ |
15 | #include "wx/defs.h" |
16 | ||
17 | #if wxUSE_ACCEL | |
18 | ||
19 | #include "wx/object.h" | |
20 | ||
21 | class WXDLLEXPORT wxAcceleratorTable; | |
22 | class WXDLLEXPORT wxMenuItem; | |
45f22d48 | 23 | class WXDLLEXPORT wxKeyEvent; |
1e6feb95 VZ |
24 | |
25 | // ---------------------------------------------------------------------------- | |
26 | // constants | |
27 | // ---------------------------------------------------------------------------- | |
28 | ||
29 | // wxAcceleratorEntry flags | |
30 | enum | |
31 | { | |
32 | wxACCEL_NORMAL = 0x0000, // no modifiers | |
33 | wxACCEL_ALT = 0x0001, // hold Alt key down | |
34 | wxACCEL_CTRL = 0x0002, // hold Ctrl key down | |
e3141a34 SC |
35 | wxACCEL_SHIFT = 0x0004, // hold Shift key down |
36 | #if defined(__WXMAC__) || defined(__WXCOCOA__) | |
37 | wxACCEL_CMD = 0x0008 // Command key on OS X | |
38 | #else | |
39 | wxACCEL_CMD = wxACCEL_CTRL | |
40 | #endif | |
1e6feb95 VZ |
41 | }; |
42 | ||
43 | // ---------------------------------------------------------------------------- | |
44 | // an entry in wxAcceleratorTable corresponds to one accelerator | |
45 | // ---------------------------------------------------------------------------- | |
46 | ||
47 | class WXDLLEXPORT wxAcceleratorEntry | |
48 | { | |
49 | public: | |
50 | wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0, | |
51 | wxMenuItem *item = NULL) | |
54380f29 GD |
52 | : m_flags(flags) |
53 | , m_keyCode(keyCode) | |
54 | , m_command(cmd) | |
55 | , m_item(item) | |
56 | { } | |
57 | ||
58 | wxAcceleratorEntry(const wxAcceleratorEntry& entry) | |
59 | : m_flags(entry.m_flags) | |
60 | , m_keyCode(entry.m_keyCode) | |
61 | , m_command(entry.m_command) | |
62 | , m_item(entry.m_item) | |
63 | { } | |
64 | ||
65 | wxAcceleratorEntry& operator=(const wxAcceleratorEntry& entry) | |
1e6feb95 | 66 | { |
54380f29 GD |
67 | Set(entry.m_flags, entry.m_keyCode, entry.m_command, entry.m_item); |
68 | return *this; | |
1e6feb95 | 69 | } |
4629016d | 70 | |
1e6feb95 VZ |
71 | void Set(int flags, int keyCode, int cmd, wxMenuItem *item = NULL) |
72 | { | |
73 | m_flags = flags; | |
74 | m_keyCode = keyCode; | |
75 | m_command = cmd; | |
76 | m_item = item; | |
77 | } | |
78 | ||
79 | void SetMenuItem(wxMenuItem *item) { m_item = item; } | |
80 | ||
81 | int GetFlags() const { return m_flags; } | |
82 | int GetKeyCode() const { return m_keyCode; } | |
83 | int GetCommand() const { return m_command; } | |
84 | ||
85 | wxMenuItem *GetMenuItem() const { return m_item; } | |
86 | ||
87 | bool operator==(const wxAcceleratorEntry& entry) const | |
88 | { | |
89 | return m_flags == entry.m_flags && | |
90 | m_keyCode == entry.m_keyCode && | |
91 | m_command == entry.m_command && | |
92 | m_item == entry.m_item; | |
93 | } | |
94 | ||
95 | bool operator!=(const wxAcceleratorEntry& entry) const | |
96 | { return !(*this == entry); } | |
97 | ||
b82d2a00 | 98 | #if defined(__WXMOTIF__) |
45f22d48 | 99 | // Implementation use only |
b82d2a00 | 100 | bool MatchesEvent(const wxKeyEvent& event) const; |
45f22d48 | 101 | #endif |
4629016d | 102 | |
1e6feb95 VZ |
103 | private: |
104 | int m_flags; // combination of wxACCEL_XXX constants | |
105 | int m_keyCode; // ASCII or virtual keycode | |
106 | int m_command; // Command id to generate | |
107 | ||
108 | // the menu item this entry corresponds to, may be NULL | |
109 | wxMenuItem *m_item; | |
110 | ||
111 | // for compatibility with old code, use accessors now! | |
112 | friend class WXDLLEXPORT wxMenu; | |
113 | }; | |
114 | ||
115 | // ---------------------------------------------------------------------------- | |
116 | // include wxAcceleratorTable class declaration, it is only used by the library | |
117 | // and so doesn't have any published user visible interface | |
118 | // ---------------------------------------------------------------------------- | |
119 | ||
120 | #if defined(__WXUNIVERSAL__) | |
121 | #include "wx/generic/accel.h" | |
122 | #elif defined(__WXMSW__) | |
123 | #include "wx/msw/accel.h" | |
34138703 | 124 | #elif defined(__WXMOTIF__) |
1e6feb95 | 125 | #include "wx/motif/accel.h" |
1be7a35c | 126 | #elif defined(__WXGTK20__) |
1e6feb95 | 127 | #include "wx/gtk/accel.h" |
1be7a35c MR |
128 | #elif defined(__WXGTK__) |
129 | #include "wx/gtk1/accel.h" | |
34138703 | 130 | #elif defined(__WXMAC__) |
1e6feb95 | 131 | #include "wx/mac/accel.h" |
0201182b DE |
132 | #elif defined(__WXCOCOA__) |
133 | #include "wx/generic/accel.h" | |
1777b9bb | 134 | #elif defined(__WXPM__) |
1e6feb95 | 135 | #include "wx/os2/accel.h" |
34138703 JS |
136 | #endif |
137 | ||
16cba29d | 138 | extern WXDLLEXPORT_DATA(wxAcceleratorTable) wxNullAcceleratorTable; |
1e6feb95 VZ |
139 | |
140 | #endif // wxUSE_ACCEL | |
141 | ||
34138703 JS |
142 | #endif |
143 | // _WX_ACCEL_H_BASE_ |