]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/accel.h
A couple of fixes for wxChm
[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
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
7c913512 32
463b4bfa
FM
33 An object used by an application wishing to create an accelerator table
34 (see wxAcceleratorTable).
7c913512 35
23324ae1 36 @library{wxcore}
3c99e2fd 37 @category{data}
7c913512 38
3a65144e 39 @see wxAcceleratorTable, wxWindow::SetAcceleratorTable
23324ae1 40*/
7c913512 41class wxAcceleratorEntry
23324ae1
FM
42{
43public:
23324ae1
FM
44 /**
45 Constructor.
463b4bfa 46
7c913512 47 @param flags
d4624460 48 A combination of the ::wxAcceleratorEntryFlags values, which
463b4bfa 49 indicates which modifier keys are held down.
7c913512 50 @param keyCode
d4624460 51 The keycode to be detected. See ::wxKeyCode for a full list of keycodes.
7c913512 52 @param cmd
3d8662ab
FM
53 The menu or control command identifier (ID).
54 @param item
55 The menu item associated with this accelerator.
56 */
57 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0,
58 wxMenuItem *item = NULL);
59
60 /**
61 Copy ctor.
23324ae1 62 */
3d8662ab 63 wxAcceleratorEntry(const wxAcceleratorEntry& entry);
23324ae1
FM
64
65 /**
66 Returns the command identifier for the accelerator table entry.
67 */
328f5751 68 int GetCommand() const;
23324ae1
FM
69
70 /**
71 Returns the flags for the accelerator table entry.
72 */
328f5751 73 int GetFlags() const;
23324ae1
FM
74
75 /**
76 Returns the keycode for the accelerator table entry.
77 */
328f5751 78 int GetKeyCode() const;
23324ae1 79
3d8662ab
FM
80 /**
81 Returns the menu item associated with this accelerator entry.
82 */
83 wxMenuItem *GetMenuItem() const;
84
23324ae1
FM
85 /**
86 Sets the accelerator entry parameters.
3c4f71cc 87
7c913512 88 @param flags
d4624460 89 A combination of the ::wxAcceleratorEntryFlags values, which
463b4bfa 90 indicates which modifier keys are held down.
7c913512 91 @param keyCode
d4624460 92 The keycode to be detected. See ::wxKeyCode for a full list of keycodes.
7c913512 93 @param cmd
3d8662ab
FM
94 The menu or control command identifier (ID).
95 @param item
96 The menu item associated with this accelerator.
97 */
98 void Set(int flags, int keyCode, int cmd, wxMenuItem *item = NULL);
463b4bfa 99
3d8662ab
FM
100 /**
101 Returns @true if this object is correctly initialized.
23324ae1 102 */
3d8662ab
FM
103 bool IsOk() const;
104
105 /**
106 Returns a wxString for this accelerator.
d4624460 107
3d8662ab
FM
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
7c913512 133
23324ae1 134 An accelerator table allows the application to specify a table of keyboard
b1bb04c5 135 shortcuts for menu or button commands.
463b4bfa 136
3a65144e 137 The object ::wxNullAcceleratorTable is defined to be a table with no data, and
463b4bfa
FM
138 is the initial accelerator table for a window.
139
140 Example:
141
142 @code
143 wxAcceleratorEntry entries[4];
144 entries[0].Set(wxACCEL_CTRL, (int) 'N', ID_NEW_WINDOW);
145 entries[1].Set(wxACCEL_CTRL, (int) 'X', wxID_EXIT);
146 entries[2].Set(wxACCEL_SHIFT, (int) 'A', ID_ABOUT);
147 entries[3].Set(wxACCEL_NORMAL, WXK_DELETE, wxID_CUT);
148
149 wxAcceleratorTable accel(4, entries);
150 frame->SetAcceleratorTable(accel);
151 @endcode
7c913512 152
463b4bfa
FM
153 @remarks
154 An accelerator takes precedence over normal processing and can be a convenient
155 way to program some event handling. For example, you can use an accelerator table
156 to enable a dialog with a multi-line text control to accept CTRL-Enter as meaning
aa47271c 157 'OK'.
7c913512 158
23324ae1 159 @library{wxcore}
3c99e2fd 160 @category{data}
7c913512 161
23324ae1 162 @stdobjects
3a65144e 163 ::wxNullAcceleratorTable
7c913512 164
3a65144e 165 @see wxAcceleratorEntry, wxWindow::SetAcceleratorTable
23324ae1
FM
166*/
167class wxAcceleratorTable : public wxObject
168{
169public:
23324ae1 170 /**
463b4bfa
FM
171 Default ctor.
172 */
173 wxAcceleratorTable();
174
463b4bfa
FM
175 /**
176 Initializes the accelerator table from an array of wxAcceleratorEntry.
3c4f71cc 177
7c913512 178 @param n
4cc4bfaf 179 Number of accelerator entries.
7c913512 180 @param entries
4cc4bfaf 181 The array of entries.
1058f652
MB
182
183 @beginWxPerlOnly
184 The wxPerl constructor accepts a list of either
185 Wx::AcceleratorEntry objects or references to 3-element arrays
186 [flags, keyCode, cmd] , like the parameters of
187 Wx::AcceleratorEntry::new.
188 @endWxPerlOnly
463b4bfa 189 */
3d8662ab 190 wxAcceleratorTable(int n, const wxAcceleratorEntry entries[]);
463b4bfa
FM
191
192 /**
193 Loads the accelerator table from a Windows resource (Windows only).
3c4f71cc 194
d9faa1fe
FM
195 @onlyfor{wxmsw}
196
7c913512 197 @param resource
4cc4bfaf 198 Name of a Windows accelerator.
23324ae1 199 */
7c913512 200 wxAcceleratorTable(const wxString& resource);
23324ae1
FM
201
202 /**
203 Destroys the wxAcceleratorTable object.
463b4bfa 204 See @ref overview_refcount_destruct for more info.
23324ae1 205 */
8d483c9b 206 virtual ~wxAcceleratorTable();
23324ae1
FM
207
208 /**
209 Returns @true if the accelerator table is valid.
210 */
328f5751 211 bool IsOk() const;
23324ae1 212};
463b4bfa 213
39fb8056
FM
214
215// ============================================================================
216// Global functions/macros
217// ============================================================================
218
463b4bfa
FM
219/**
220 An empty accelerator table.
221*/
222wxAcceleratorTable wxNullAcceleratorTable;