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