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