]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: accel.h | |
463b4bfa | 3 | // Purpose: interface of wxAccelerator* classes |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
463b4bfa FM |
9 | |
10 | /** wxAcceleratorEntry flags */ | |
11 | enum wxAcceleratorEntryFlags | |
12 | { | |
13 | /** no modifiers */ | |
14 | wxACCEL_NORMAL, | |
15 | ||
16 | /** hold Alt key down */ | |
17 | wxACCEL_ALT, | |
18 | ||
19 | /** hold Ctrl key down */ | |
20 | wxACCEL_CTRL, | |
21 | ||
22 | /** hold Shift key down */ | |
23 | wxACCEL_SHIFT, | |
24 | ||
25 | /** Command key on OS X; identic to wxACCEL_CTRL on other platforms. */ | |
26 | wxACCEL_CMD | |
27 | }; | |
28 | ||
29 | ||
23324ae1 FM |
30 | /** |
31 | @class wxAcceleratorEntry | |
32 | @wxheader{accel.h} | |
7c913512 | 33 | |
463b4bfa FM |
34 | An object used by an application wishing to create an accelerator table |
35 | (see wxAcceleratorTable). | |
7c913512 | 36 | |
23324ae1 | 37 | @library{wxcore} |
3a65144e | 38 | @category{misc} |
7c913512 | 39 | |
3a65144e | 40 | @see wxAcceleratorTable, wxWindow::SetAcceleratorTable |
23324ae1 | 41 | */ |
7c913512 | 42 | class wxAcceleratorEntry |
23324ae1 FM |
43 | { |
44 | public: | |
23324ae1 FM |
45 | /** |
46 | Constructor. | |
463b4bfa | 47 | |
7c913512 | 48 | @param flags |
463b4bfa FM |
49 | A combination of the wxAcceleratorEntryFlags values, which |
50 | indicates which modifier keys are held down. | |
7c913512 | 51 | @param keyCode |
463b4bfa | 52 | The keycode to be detected. See @ref page_keycodes for a full list of keycodes. |
7c913512 | 53 | @param cmd |
3d8662ab FM |
54 | The menu or control command identifier (ID). |
55 | @param item | |
56 | The menu item associated with this accelerator. | |
57 | */ | |
58 | wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0, | |
59 | wxMenuItem *item = NULL); | |
60 | ||
61 | /** | |
62 | Copy ctor. | |
23324ae1 | 63 | */ |
3d8662ab | 64 | wxAcceleratorEntry(const wxAcceleratorEntry& entry); |
23324ae1 FM |
65 | |
66 | /** | |
67 | Returns the command identifier for the accelerator table entry. | |
68 | */ | |
328f5751 | 69 | int GetCommand() const; |
23324ae1 FM |
70 | |
71 | /** | |
72 | Returns the flags for the accelerator table entry. | |
73 | */ | |
328f5751 | 74 | int GetFlags() const; |
23324ae1 FM |
75 | |
76 | /** | |
77 | Returns the keycode for the accelerator table entry. | |
78 | */ | |
328f5751 | 79 | int GetKeyCode() const; |
23324ae1 | 80 | |
3d8662ab FM |
81 | /** |
82 | Returns the menu item associated with this accelerator entry. | |
83 | */ | |
84 | wxMenuItem *GetMenuItem() const; | |
85 | ||
23324ae1 FM |
86 | /** |
87 | Sets the accelerator entry parameters. | |
3c4f71cc | 88 | |
7c913512 | 89 | @param flags |
463b4bfa FM |
90 | A combination of the wxAcceleratorEntryFlags values, which |
91 | indicates which modifier keys are held down. | |
7c913512 | 92 | @param keyCode |
463b4bfa | 93 | The keycode to be detected. See @ref page_keycodes for a full list of keycodes. |
7c913512 | 94 | @param cmd |
3d8662ab FM |
95 | The menu or control command identifier (ID). |
96 | @param item | |
97 | The menu item associated with this accelerator. | |
98 | */ | |
99 | void Set(int flags, int keyCode, int cmd, wxMenuItem *item = NULL); | |
463b4bfa | 100 | |
3d8662ab FM |
101 | /** |
102 | Returns @true if this object is correctly initialized. | |
23324ae1 | 103 | */ |
3d8662ab FM |
104 | bool IsOk() const; |
105 | ||
106 | /** | |
107 | Returns a wxString for this accelerator. | |
108 | This function formats it using the @c "flags-keycode" format | |
109 | where @c flags maybe a hyphen-separed list of @c "shift|alt|ctrl". | |
110 | */ | |
111 | wxString ToString() const; | |
112 | ||
113 | /** | |
114 | Parses the given string and sets the accelerator accordingly. | |
115 | ||
116 | @param str | |
117 | Should be a string in the form "flags-keycode" | |
118 | ||
d29a9a8a BP |
119 | @return @true if the given string correctly initialized this object |
120 | (i.e. if IsOk() returns true after this call) | |
3d8662ab FM |
121 | */ |
122 | bool FromString(const wxString& str); | |
123 | ||
124 | ||
125 | wxAcceleratorEntry& operator=(const wxAcceleratorEntry& entry); | |
126 | bool operator==(const wxAcceleratorEntry& entry) const; | |
127 | bool operator!=(const wxAcceleratorEntry& entry) const; | |
23324ae1 FM |
128 | }; |
129 | ||
130 | ||
131 | /** | |
132 | @class wxAcceleratorTable | |
133 | @wxheader{accel.h} | |
7c913512 | 134 | |
23324ae1 | 135 | An accelerator table allows the application to specify a table of keyboard |
b1bb04c5 | 136 | shortcuts for menu or button commands. |
463b4bfa | 137 | |
3a65144e | 138 | The object ::wxNullAcceleratorTable is defined to be a table with no data, and |
463b4bfa FM |
139 | is the initial accelerator table for a window. |
140 | ||
141 | Example: | |
142 | ||
143 | @code | |
144 | wxAcceleratorEntry entries[4]; | |
145 | entries[0].Set(wxACCEL_CTRL, (int) 'N', ID_NEW_WINDOW); | |
146 | entries[1].Set(wxACCEL_CTRL, (int) 'X', wxID_EXIT); | |
147 | entries[2].Set(wxACCEL_SHIFT, (int) 'A', ID_ABOUT); | |
148 | entries[3].Set(wxACCEL_NORMAL, WXK_DELETE, wxID_CUT); | |
149 | ||
150 | wxAcceleratorTable accel(4, entries); | |
151 | frame->SetAcceleratorTable(accel); | |
152 | @endcode | |
7c913512 | 153 | |
463b4bfa FM |
154 | @remarks |
155 | An accelerator takes precedence over normal processing and can be a convenient | |
156 | way to program some event handling. For example, you can use an accelerator table | |
157 | to enable a dialog with a multi-line text control to accept CTRL-Enter as meaning | |
aa47271c | 158 | 'OK'. |
7c913512 | 159 | |
23324ae1 FM |
160 | @library{wxcore} |
161 | @category{misc} | |
7c913512 | 162 | |
23324ae1 | 163 | @stdobjects |
3a65144e | 164 | ::wxNullAcceleratorTable |
7c913512 | 165 | |
3a65144e | 166 | @see wxAcceleratorEntry, wxWindow::SetAcceleratorTable |
23324ae1 FM |
167 | */ |
168 | class wxAcceleratorTable : public wxObject | |
169 | { | |
170 | public: | |
23324ae1 | 171 | /** |
463b4bfa FM |
172 | Default ctor. |
173 | */ | |
174 | wxAcceleratorTable(); | |
175 | ||
463b4bfa FM |
176 | /** |
177 | Initializes the accelerator table from an array of wxAcceleratorEntry. | |
3c4f71cc | 178 | |
7c913512 | 179 | @param n |
4cc4bfaf | 180 | Number of accelerator entries. |
7c913512 | 181 | @param entries |
4cc4bfaf | 182 | The array of entries. |
463b4bfa | 183 | */ |
3d8662ab | 184 | wxAcceleratorTable(int n, const wxAcceleratorEntry entries[]); |
463b4bfa FM |
185 | |
186 | /** | |
187 | Loads the accelerator table from a Windows resource (Windows only). | |
3c4f71cc | 188 | |
d9faa1fe FM |
189 | @onlyfor{wxmsw} |
190 | ||
7c913512 | 191 | @param resource |
4cc4bfaf | 192 | Name of a Windows accelerator. |
23324ae1 | 193 | */ |
7c913512 | 194 | wxAcceleratorTable(const wxString& resource); |
23324ae1 FM |
195 | |
196 | /** | |
197 | Destroys the wxAcceleratorTable object. | |
463b4bfa | 198 | See @ref overview_refcount_destruct for more info. |
23324ae1 | 199 | */ |
8d483c9b | 200 | virtual ~wxAcceleratorTable(); |
23324ae1 FM |
201 | |
202 | /** | |
203 | Returns @true if the accelerator table is valid. | |
204 | */ | |
328f5751 | 205 | bool IsOk() const; |
23324ae1 | 206 | }; |
463b4bfa | 207 | |
39fb8056 FM |
208 | |
209 | // ============================================================================ | |
210 | // Global functions/macros | |
211 | // ============================================================================ | |
212 | ||
463b4bfa FM |
213 | /** |
214 | An empty accelerator table. | |
215 | */ | |
216 | wxAcceleratorTable wxNullAcceleratorTable; |