]> git.saurik.com Git - wxWidgets.git/blame - src/common/stockitem.cpp
No changes, just change data structures used by mouse capture code.
[wxWidgets.git] / src / common / stockitem.cpp
CommitLineData
401e3b6e 1///////////////////////////////////////////////////////////////////////////////
88a7a4e1 2// Name: src/common/stockitem.cpp
401e3b6e
VS
3// Purpose: Stock buttons, menu and toolbar items labels
4// Author: Vaclav Slavik
5// Modified by:
6// Created: 2004-08-15
401e3b6e
VS
7// Copyright: (c) Vaclav Slavik, 2004
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
401e3b6e
VS
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#include "wx/stockitem.h"
88a7a4e1
WS
27
28#ifndef WX_PRECOMP
29 #include "wx/intl.h"
de6185e2 30 #include "wx/utils.h" // for wxStripMenuCodes()
88a7a4e1
WS
31#endif
32
5f7bcb48
VS
33bool wxIsStockID(wxWindowID id)
34{
35 switch (id)
36 {
ee0a94cf 37 case wxID_ABOUT:
5f7bcb48
VS
38 case wxID_ADD:
39 case wxID_APPLY:
6b1eedc1 40 case wxID_BACKWARD:
5f7bcb48 41 case wxID_BOLD:
6b1eedc1 42 case wxID_BOTTOM:
5f7bcb48 43 case wxID_CANCEL:
6b1eedc1 44 case wxID_CDROM:
5f7bcb48
VS
45 case wxID_CLEAR:
46 case wxID_CLOSE:
6b1eedc1 47 case wxID_CONVERT:
5f7bcb48
VS
48 case wxID_COPY:
49 case wxID_CUT:
50 case wxID_DELETE:
6b1eedc1 51 case wxID_DOWN:
ee0a94cf 52 case wxID_EDIT:
6b1eedc1
VZ
53 case wxID_EXECUTE:
54 case wxID_EXIT:
ee0a94cf 55 case wxID_FILE:
6b1eedc1
VZ
56 case wxID_FIND:
57 case wxID_FIRST:
58 case wxID_FLOPPY:
5f7bcb48 59 case wxID_FORWARD:
6b1eedc1 60 case wxID_HARDDISK:
5f7bcb48
VS
61 case wxID_HELP:
62 case wxID_HOME:
63 case wxID_INDENT:
64 case wxID_INDEX:
6b1eedc1 65 case wxID_INFO:
5f7bcb48 66 case wxID_ITALIC:
6b1eedc1 67 case wxID_JUMP_TO:
5f7bcb48
VS
68 case wxID_JUSTIFY_CENTER:
69 case wxID_JUSTIFY_FILL:
70 case wxID_JUSTIFY_LEFT:
71 case wxID_JUSTIFY_RIGHT:
6b1eedc1
VZ
72 case wxID_LAST:
73 case wxID_NETWORK:
5f7bcb48
VS
74 case wxID_NEW:
75 case wxID_NO:
76 case wxID_OK:
77 case wxID_OPEN:
78 case wxID_PASTE:
79 case wxID_PREFERENCES:
5f7bcb48 80 case wxID_PREVIEW:
6b1eedc1 81 case wxID_PRINT:
5f7bcb48 82 case wxID_PROPERTIES:
5f7bcb48
VS
83 case wxID_REDO:
84 case wxID_REFRESH:
85 case wxID_REMOVE:
6b1eedc1 86 case wxID_REPLACE:
5f7bcb48
VS
87 case wxID_REVERT_TO_SAVED:
88 case wxID_SAVE:
89 case wxID_SAVEAS:
ee0a94cf 90 case wxID_SELECTALL:
6b1eedc1
VZ
91 case wxID_SELECT_COLOR:
92 case wxID_SELECT_FONT:
93 case wxID_SORT_ASCENDING:
94 case wxID_SORT_DESCENDING:
95 case wxID_SPELL_CHECK:
5f7bcb48 96 case wxID_STOP:
6b1eedc1
VZ
97 case wxID_STRIKETHROUGH:
98 case wxID_TOP:
5f7bcb48
VS
99 case wxID_UNDELETE:
100 case wxID_UNDERLINE:
101 case wxID_UNDO:
102 case wxID_UNINDENT:
6b1eedc1 103 case wxID_UP:
5f7bcb48
VS
104 case wxID_YES:
105 case wxID_ZOOM_100:
106 case wxID_ZOOM_FIT:
107 case wxID_ZOOM_IN:
108 case wxID_ZOOM_OUT:
109 return true;
110
111 default:
112 return false;
d0ee33f5 113 }
5f7bcb48
VS
114}
115
ee0a94cf 116wxString wxGetStockLabel(wxWindowID id, long flags)
401e3b6e 117{
634629fa
WS
118 wxString stockLabel;
119
f8a1c571
VZ
120#ifdef __WXMSW__
121 // special case: the "Cancel" button shouldn't have a mnemonic under MSW
122 // for consistency with the native dialogs (which don't use any mnemonic
123 // for it because it is already bound to Esc implicitly)
124 if ( id == wxID_CANCEL )
125 flags &= ~wxSTOCK_WITH_MNEMONIC;
126#endif // __WXMSW__
127
128
129 #define STOCKITEM(stockid, labelWithMnemonic, labelPlain) \
130 case stockid: \
131 if(flags & wxSTOCK_WITH_MNEMONIC) \
132 stockLabel = labelWithMnemonic; \
133 else \
134 stockLabel = labelPlain; \
135 break
401e3b6e 136
5f7bcb48 137 switch (id)
401e3b6e 138 {
2d143b66 139 STOCKITEM(wxID_ABOUT, _("&About"), _("About"));
f8a1c571
VZ
140 STOCKITEM(wxID_ADD, _("Add"), _("Add"));
141 STOCKITEM(wxID_APPLY, _("&Apply"), _("Apply"));
142 STOCKITEM(wxID_BACKWARD, _("&Back"), _("Back"));
143 STOCKITEM(wxID_BOLD, _("&Bold"), _("Bold"));
144 STOCKITEM(wxID_BOTTOM, _("&Bottom"), _("Bottom"));
145 STOCKITEM(wxID_CANCEL, _("&Cancel"), _("Cancel"));
146 STOCKITEM(wxID_CDROM, _("&CD-Rom"), _("CD-Rom"));
147 STOCKITEM(wxID_CLEAR, _("&Clear"), _("Clear"));
148 STOCKITEM(wxID_CLOSE, _("&Close"), _("Close"));
149 STOCKITEM(wxID_CONVERT, _("&Convert"), _("Convert"));
150 STOCKITEM(wxID_COPY, _("&Copy"), _("Copy"));
151 STOCKITEM(wxID_CUT, _("Cu&t"), _("Cut"));
152 STOCKITEM(wxID_DELETE, _("&Delete"), _("Delete"));
153 STOCKITEM(wxID_DOWN, _("&Down"), _("Down"));
154 STOCKITEM(wxID_EDIT, _("&Edit"), _("Edit"));
155 STOCKITEM(wxID_EXECUTE, _("&Execute"), _("Execute"));
156 STOCKITEM(wxID_EXIT, _("&Quit"), _("Quit"));
157 STOCKITEM(wxID_FILE, _("&File"), _("File"));
158 STOCKITEM(wxID_FIND, _("&Find"), _("Find"));
159 STOCKITEM(wxID_FIRST, _("&First"), _("First"));
160 STOCKITEM(wxID_FLOPPY, _("&Floppy"), _("Floppy"));
161 STOCKITEM(wxID_FORWARD, _("&Forward"), _("Forward"));
162 STOCKITEM(wxID_HARDDISK, _("&Harddisk"), _("Harddisk"));
163 STOCKITEM(wxID_HELP, _("&Help"), _("Help"));
164 STOCKITEM(wxID_HOME, _("&Home"), _("Home"));
165 STOCKITEM(wxID_INDENT, _("Indent"), _("Indent"));
166 STOCKITEM(wxID_INDEX, _("&Index"), _("Index"));
167 STOCKITEM(wxID_INFO, _("&Info"), _("Info"));
168 STOCKITEM(wxID_ITALIC, _("&Italic"), _("Italic"));
2032371b 169 STOCKITEM(wxID_JUMP_TO, _("&Jump to"), _("Jump to"));
f8a1c571
VZ
170 STOCKITEM(wxID_JUSTIFY_CENTER, _("Centered"), _("Centered"));
171 STOCKITEM(wxID_JUSTIFY_FILL, _("Justified"), _("Justified"));
2032371b
VZ
172 STOCKITEM(wxID_JUSTIFY_LEFT, _("Align Left"), _("Align Left"));
173 STOCKITEM(wxID_JUSTIFY_RIGHT, _("Align Right"), _("Align Right"));
f8a1c571
VZ
174 STOCKITEM(wxID_LAST, _("&Last"), _("Last"));
175 STOCKITEM(wxID_NETWORK, _("&Network"), _("Network"));
176 STOCKITEM(wxID_NEW, _("&New"), _("New"));
177 STOCKITEM(wxID_NO, _("&No"), _("No"));
178 STOCKITEM(wxID_OK, _("&OK"), _("OK"));
179 STOCKITEM(wxID_OPEN, _("&Open..."), _("Open..."));
180 STOCKITEM(wxID_PASTE, _("&Paste"), _("Paste"));
181 STOCKITEM(wxID_PREFERENCES, _("&Preferences"), _("Preferences"));
165e563d 182 STOCKITEM(wxID_PREVIEW, _("Print previe&w..."), _("Print preview..."));
f8a1c571
VZ
183 STOCKITEM(wxID_PRINT, _("&Print..."), _("Print..."));
184 STOCKITEM(wxID_PROPERTIES, _("&Properties"), _("Properties"));
185 STOCKITEM(wxID_REDO, _("&Redo"), _("Redo"));
186 STOCKITEM(wxID_REFRESH, _("Refresh"), _("Refresh"));
187 STOCKITEM(wxID_REMOVE, _("Remove"), _("Remove"));
188 STOCKITEM(wxID_REPLACE, _("Rep&lace"), _("Replace"));
2032371b 189 STOCKITEM(wxID_REVERT_TO_SAVED, _("Revert to Saved"), _("Revert to Saved"));
f8a1c571 190 STOCKITEM(wxID_SAVE, _("&Save"), _("Save"));
73d1308b 191 STOCKITEM(wxID_SAVEAS, _("&Save as"), _("Save as"));
2032371b 192 STOCKITEM(wxID_SELECTALL, _("Select &All"), _("Select All"));
f8a1c571
VZ
193 STOCKITEM(wxID_SELECT_COLOR, _("&Color"), _("Color"));
194 STOCKITEM(wxID_SELECT_FONT, _("&Font"), _("Font"));
195 STOCKITEM(wxID_SORT_ASCENDING, _("&Ascending"), _("Ascending"));
196 STOCKITEM(wxID_SORT_DESCENDING, _("&Descending"), _("Descending"));
2032371b 197 STOCKITEM(wxID_SPELL_CHECK, _("&Spell Check"), _("Spell Check"));
f8a1c571
VZ
198 STOCKITEM(wxID_STOP, _("&Stop"), _("Stop"));
199 STOCKITEM(wxID_STRIKETHROUGH, _("&Strikethrough"), _("Strikethrough"));
200 STOCKITEM(wxID_TOP, _("&Top"), _("Top"));
201 STOCKITEM(wxID_UNDELETE, _("Undelete"), _("Undelete"));
202 STOCKITEM(wxID_UNDERLINE, _("&Underline"), _("Underline"));
203 STOCKITEM(wxID_UNDO, _("&Undo"), _("Undo"));
204 STOCKITEM(wxID_UNINDENT, _("&Unindent"), _("Unindent"));
205 STOCKITEM(wxID_UP, _("&Up"), _("Up"));
206 STOCKITEM(wxID_YES, _("&Yes"), _("Yes"));
2032371b
VZ
207 STOCKITEM(wxID_ZOOM_100, _("&Actual Size"), _("Actual Size"));
208 STOCKITEM(wxID_ZOOM_FIT, _("Zoom to &Fit"), _("Zoom to Fit"));
209 STOCKITEM(wxID_ZOOM_IN, _("Zoom &In"), _("Zoom In"));
210 STOCKITEM(wxID_ZOOM_OUT, _("Zoom &Out"), _("Zoom Out"));
5f7bcb48 211
401e3b6e 212 default:
9a83f860 213 wxFAIL_MSG( wxT("invalid stock item ID") );
401e3b6e
VS
214 break;
215 };
216
217 #undef STOCKITEM
d775fa82 218
95ad763a 219 if ( flags & wxSTOCK_WITHOUT_ELLIPSIS )
e94ee791
VZ
220 {
221 wxString baseLabel;
222 if ( stockLabel.EndsWith("...", &baseLabel) )
223 stockLabel = baseLabel;
224
95ad763a
VZ
225 // accelerators only make sense for the menu items which should have
226 // ellipsis too while wxSTOCK_WITHOUT_ELLIPSIS is mostly useful for
227 // buttons which shouldn't have accelerators in their labels
e94ee791 228 wxASSERT_MSG( !(flags & wxSTOCK_WITH_ACCELERATOR),
95ad763a 229 "labels without ellipsis shouldn't use accelerators" );
e94ee791
VZ
230 }
231
b137e493 232#if wxUSE_ACCEL
9b3c3047 233 if ( !stockLabel.empty() && (flags & wxSTOCK_WITH_ACCELERATOR) )
634629fa 234 {
ee0a94cf
RR
235 wxAcceleratorEntry accel = wxGetStockAccelerator(id);
236 if (accel.IsOk())
9a83f860 237 stockLabel << wxT('\t') << accel.ToString();
634629fa 238 }
b137e493
WS
239#endif // wxUSE_ACCEL
240
634629fa 241 return stockLabel;
401e3b6e
VS
242}
243
345319d6
VZ
244wxString wxGetStockHelpString(wxWindowID id, wxStockHelpStringClient client)
245{
246 wxString stockHelp;
247
248 #define STOCKITEM(stockid, ctx, helpstr) \
249 case stockid: \
250 if (client==ctx) stockHelp = helpstr; \
251 break;
252
253 switch (id)
254 {
255 // NB: these help string should be not too specific as they could be used
256 // in completely different programs!
257 STOCKITEM(wxID_ABOUT, wxSTOCK_MENU, _("Show about dialog"))
258 STOCKITEM(wxID_COPY, wxSTOCK_MENU, _("Copy selection"))
259 STOCKITEM(wxID_CUT, wxSTOCK_MENU, _("Cut selection"))
260 STOCKITEM(wxID_DELETE, wxSTOCK_MENU, _("Delete selection"))
261 STOCKITEM(wxID_REPLACE, wxSTOCK_MENU, _("Replace selection"))
262 STOCKITEM(wxID_PASTE, wxSTOCK_MENU, _("Paste selection"))
263 STOCKITEM(wxID_EXIT, wxSTOCK_MENU, _("Quit this program"))
264 STOCKITEM(wxID_REDO, wxSTOCK_MENU, _("Redo last action"))
265 STOCKITEM(wxID_UNDO, wxSTOCK_MENU, _("Undo last action"))
266 STOCKITEM(wxID_CLOSE, wxSTOCK_MENU, _("Close current document"))
267 STOCKITEM(wxID_SAVE, wxSTOCK_MENU, _("Save current document"))
268 STOCKITEM(wxID_SAVEAS, wxSTOCK_MENU, _("Save current document with a different filename"))
269
270 default:
271 // there's no stock help string for this ID / client
272 return wxEmptyString;
273 }
274
275 #undef STOCKITEM
276
277 return stockHelp;
278}
279
b137e493
WS
280#if wxUSE_ACCEL
281
ee0a94cf
RR
282wxAcceleratorEntry wxGetStockAccelerator(wxWindowID id)
283{
284 wxAcceleratorEntry ret;
285
286 #define STOCKITEM(stockid, flags, keycode) \
287 case stockid: \
288 ret.Set(flags, keycode, stockid); \
289 break;
290
291 switch (id)
292 {
675ec665
SC
293 STOCKITEM(wxID_COPY, wxACCEL_CTRL,'C')
294 STOCKITEM(wxID_CUT, wxACCEL_CTRL,'X')
295 STOCKITEM(wxID_FIND, wxACCEL_CTRL,'F')
296 STOCKITEM(wxID_HELP, wxACCEL_CTRL,'H')
297 STOCKITEM(wxID_NEW, wxACCEL_CTRL,'N')
298 STOCKITEM(wxID_OPEN, wxACCEL_CTRL,'O')
299 STOCKITEM(wxID_PASTE, wxACCEL_CTRL,'V')
d94df7c9 300 STOCKITEM(wxID_PRINT, wxACCEL_CTRL,'P')
675ec665
SC
301 STOCKITEM(wxID_REDO, wxACCEL_CTRL | wxACCEL_SHIFT,'Z')
302 STOCKITEM(wxID_REPLACE, wxACCEL_CTRL,'R')
303 STOCKITEM(wxID_SAVE, wxACCEL_CTRL,'S')
304 STOCKITEM(wxID_UNDO, wxACCEL_CTRL,'Z')
eb3cb492
SC
305#ifdef __WXOSX__
306 STOCKITEM(wxID_PREFERENCES, wxACCEL_CTRL,',')
307#endif
ee0a94cf
RR
308
309 default:
310 // set the wxAcceleratorEntry to return into an invalid state:
311 // there's no stock accelerator for that.
312 ret.Set(0, 0, id);
313 break;
314 };
315
316 #undef STOCKITEM
317
318 // always use wxAcceleratorEntry::IsOk on returned value !
319 return ret;
320}
321
b137e493
WS
322#endif // wxUSE_ACCEL
323
5f7bcb48
VS
324bool wxIsStockLabel(wxWindowID id, const wxString& label)
325{
326 if (label.empty())
327 return true;
328
329 wxString stock = wxGetStockLabel(id);
330
331 if (label == stock)
332 return true;
d775fa82 333
9a83f860 334 stock.Replace(wxT("&"), wxEmptyString);
5f7bcb48
VS
335 if (label == stock)
336 return true;
d775fa82 337
5f7bcb48
VS
338 return false;
339}