]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/accel.h
synchronize GTK2 minimum version in docs
[wxWidgets.git] / interface / wx / accel.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: accel.h
463b4bfa 3// Purpose: interface of wxAccelerator* classes
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
463b4bfa
FM
9
10/** wxAcceleratorEntry flags */
11enum wxAcceleratorEntryFlags
12{
13 /** no modifiers */
14 wxACCEL_NORMAL,
15
16 /** hold Alt key down */
17 wxACCEL_ALT,
18
cfc77ac0 19 /** hold Ctrl key down, corresponds to Command key on OS X */
463b4bfa
FM
20 wxACCEL_CTRL,
21
22 /** hold Shift key down */
23 wxACCEL_SHIFT,
24
cfc77ac0
SC
25 /** corresponds to real Ctrl key on OS X, identic to @c wxACCEL_CTRL on other platforms */
26 wxACCEL_RAW_CTRL,
27
28 /** deprecated, identic to @c wxACCEL_CTRL on all platforms. */
463b4bfa
FM
29 wxACCEL_CMD
30};
31
32
23324ae1
FM
33/**
34 @class wxAcceleratorEntry
7c913512 35
463b4bfa
FM
36 An object used by an application wishing to create an accelerator table
37 (see wxAcceleratorTable).
7c913512 38
23324ae1 39 @library{wxcore}
3c99e2fd 40 @category{data}
7c913512 41
3a65144e 42 @see wxAcceleratorTable, wxWindow::SetAcceleratorTable
23324ae1 43*/
7c913512 44class wxAcceleratorEntry
23324ae1
FM
45{
46public:
23324ae1
FM
47 /**
48 Constructor.
463b4bfa 49
7c913512 50 @param flags
d4624460 51 A combination of the ::wxAcceleratorEntryFlags values, which
463b4bfa 52 indicates which modifier keys are held down.
7c913512 53 @param keyCode
d4624460 54 The keycode to be detected. See ::wxKeyCode for a full list of keycodes.
7c913512 55 @param cmd
3d8662ab
FM
56 The menu or control command identifier (ID).
57 @param item
58 The menu item associated with this accelerator.
59 */
60 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0,
61 wxMenuItem *item = NULL);
62
63 /**
64 Copy ctor.
23324ae1 65 */
3d8662ab 66 wxAcceleratorEntry(const wxAcceleratorEntry& entry);
23324ae1
FM
67
68 /**
69 Returns the command identifier for the accelerator table entry.
70 */
328f5751 71 int GetCommand() const;
23324ae1
FM
72
73 /**
74 Returns the flags for the accelerator table entry.
75 */
328f5751 76 int GetFlags() const;
23324ae1
FM
77
78 /**
79 Returns the keycode for the accelerator table entry.
80 */
328f5751 81 int GetKeyCode() const;
23324ae1 82
3d8662ab
FM
83 /**
84 Returns the menu item associated with this accelerator entry.
85 */
86 wxMenuItem *GetMenuItem() const;
87
23324ae1
FM
88 /**
89 Sets the accelerator entry parameters.
3c4f71cc 90
7c913512 91 @param flags
d4624460 92 A combination of the ::wxAcceleratorEntryFlags values, which
463b4bfa 93 indicates which modifier keys are held down.
7c913512 94 @param keyCode
d4624460 95 The keycode to be detected. See ::wxKeyCode for a full list of keycodes.
7c913512 96 @param cmd
3d8662ab
FM
97 The menu or control command identifier (ID).
98 @param item
99 The menu item associated with this accelerator.
100 */
101 void Set(int flags, int keyCode, int cmd, wxMenuItem *item = NULL);
463b4bfa 102
3d8662ab
FM
103 /**
104 Returns @true if this object is correctly initialized.
23324ae1 105 */
3d8662ab
FM
106 bool IsOk() const;
107
108 /**
944f641c 109 Returns a textual representation of this accelerator.
d4624460 110
5ec18516 111 The returned string is of the form <code>[Alt+][Ctrl+][RawCtrl+][Shift+]Key</code>
944f641c
VZ
112 where the modifier keys are present only if the corresponding flag is
113 set.
3d8662ab
FM
114 */
115 wxString ToString() const;
116
86f5e64b
VZ
117 /**
118 Returns a textual representation of this accelerator which is
119 appropriate for saving in configuration files.
120
121 Unlike the string returned by ToString(), this one is never translated
122 so, while it's not suitable for showing to the user, it can be used to
123 uniquely identify the accelerator independently of the user language.
124
125 The returned string can still be parsed by FromString().
126
127 @since 2.9.4
128 */
129 wxString ToRawString() const;
130
3d8662ab
FM
131 /**
132 Parses the given string and sets the accelerator accordingly.
133
134 @param str
944f641c
VZ
135 This string may be either in the same format as returned by
136 ToString(), i.e. contain the accelerator itself only, or have the
137 format of a full menu item text with i.e. <code>Label TAB
138 Accelerator</code>. In the latter case, the part of the string
6fc7a1ad
VZ
139 before the TAB is ignored. Notice that the latter format is only
140 supported for the compatibility with the previous wxWidgets
141 versions and the new code should pass only the accelerator string
142 itself to this function.
3d8662ab 143
d29a9a8a
BP
144 @return @true if the given string correctly initialized this object
145 (i.e. if IsOk() returns true after this call)
3d8662ab
FM
146 */
147 bool FromString(const wxString& str);
148
149
150 wxAcceleratorEntry& operator=(const wxAcceleratorEntry& entry);
151 bool operator==(const wxAcceleratorEntry& entry) const;
152 bool operator!=(const wxAcceleratorEntry& entry) const;
23324ae1
FM
153};
154
155
156/**
157 @class wxAcceleratorTable
7c913512 158
23324ae1 159 An accelerator table allows the application to specify a table of keyboard
b1bb04c5 160 shortcuts for menu or button commands.
463b4bfa 161
3a65144e 162 The object ::wxNullAcceleratorTable is defined to be a table with no data, and
463b4bfa
FM
163 is the initial accelerator table for a window.
164
165 Example:
166
167 @code
168 wxAcceleratorEntry entries[4];
169 entries[0].Set(wxACCEL_CTRL, (int) 'N', ID_NEW_WINDOW);
170 entries[1].Set(wxACCEL_CTRL, (int) 'X', wxID_EXIT);
171 entries[2].Set(wxACCEL_SHIFT, (int) 'A', ID_ABOUT);
172 entries[3].Set(wxACCEL_NORMAL, WXK_DELETE, wxID_CUT);
173
174 wxAcceleratorTable accel(4, entries);
175 frame->SetAcceleratorTable(accel);
176 @endcode
7c913512 177
463b4bfa
FM
178 @remarks
179 An accelerator takes precedence over normal processing and can be a convenient
180 way to program some event handling. For example, you can use an accelerator table
181 to enable a dialog with a multi-line text control to accept CTRL-Enter as meaning
aa47271c 182 'OK'.
7c913512 183
23324ae1 184 @library{wxcore}
3c99e2fd 185 @category{data}
7c913512 186
23324ae1 187 @stdobjects
3a65144e 188 ::wxNullAcceleratorTable
7c913512 189
3a65144e 190 @see wxAcceleratorEntry, wxWindow::SetAcceleratorTable
23324ae1
FM
191*/
192class wxAcceleratorTable : public wxObject
193{
194public:
23324ae1 195 /**
463b4bfa
FM
196 Default ctor.
197 */
198 wxAcceleratorTable();
199
463b4bfa
FM
200 /**
201 Initializes the accelerator table from an array of wxAcceleratorEntry.
3c4f71cc 202
7c913512 203 @param n
4cc4bfaf 204 Number of accelerator entries.
7c913512 205 @param entries
4cc4bfaf 206 The array of entries.
1058f652
MB
207
208 @beginWxPerlOnly
209 The wxPerl constructor accepts a list of either
210 Wx::AcceleratorEntry objects or references to 3-element arrays
211 [flags, keyCode, cmd] , like the parameters of
212 Wx::AcceleratorEntry::new.
213 @endWxPerlOnly
463b4bfa 214 */
3d8662ab 215 wxAcceleratorTable(int n, const wxAcceleratorEntry entries[]);
463b4bfa
FM
216
217 /**
218 Loads the accelerator table from a Windows resource (Windows only).
3c4f71cc 219
d9faa1fe
FM
220 @onlyfor{wxmsw}
221
7c913512 222 @param resource
4cc4bfaf 223 Name of a Windows accelerator.
23324ae1 224 */
7c913512 225 wxAcceleratorTable(const wxString& resource);
23324ae1
FM
226
227 /**
228 Destroys the wxAcceleratorTable object.
463b4bfa 229 See @ref overview_refcount_destruct for more info.
23324ae1 230 */
8d483c9b 231 virtual ~wxAcceleratorTable();
23324ae1
FM
232
233 /**
234 Returns @true if the accelerator table is valid.
235 */
328f5751 236 bool IsOk() const;
23324ae1 237};
463b4bfa 238
39fb8056
FM
239
240// ============================================================================
241// Global functions/macros
242// ============================================================================
243
463b4bfa
FM
244/**
245 An empty accelerator table.
246*/
247wxAcceleratorTable wxNullAcceleratorTable;