]> git.saurik.com Git - wxWidgets.git/blame - src/common/stockitem.cpp
fixed pagebreaks computation in tables (#9935, patch by D.J.Stauffer)
[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
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
401e3b6e
VS
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"
88a7a4e1
WS
28
29#ifndef WX_PRECOMP
30 #include "wx/intl.h"
de6185e2 31 #include "wx/utils.h" // for wxStripMenuCodes()
88a7a4e1
WS
32#endif
33
5f7bcb48
VS
34bool wxIsStockID(wxWindowID id)
35{
36 switch (id)
37 {
ee0a94cf 38 case wxID_ABOUT:
5f7bcb48
VS
39 case wxID_ADD:
40 case wxID_APPLY:
6b1eedc1 41 case wxID_BACKWARD:
5f7bcb48 42 case wxID_BOLD:
6b1eedc1 43 case wxID_BOTTOM:
5f7bcb48 44 case wxID_CANCEL:
6b1eedc1 45 case wxID_CDROM:
5f7bcb48
VS
46 case wxID_CLEAR:
47 case wxID_CLOSE:
6b1eedc1 48 case wxID_CONVERT:
5f7bcb48
VS
49 case wxID_COPY:
50 case wxID_CUT:
51 case wxID_DELETE:
6b1eedc1 52 case wxID_DOWN:
ee0a94cf 53 case wxID_EDIT:
6b1eedc1
VZ
54 case wxID_EXECUTE:
55 case wxID_EXIT:
ee0a94cf 56 case wxID_FILE:
6b1eedc1
VZ
57 case wxID_FIND:
58 case wxID_FIRST:
59 case wxID_FLOPPY:
5f7bcb48 60 case wxID_FORWARD:
6b1eedc1 61 case wxID_HARDDISK:
5f7bcb48
VS
62 case wxID_HELP:
63 case wxID_HOME:
64 case wxID_INDENT:
65 case wxID_INDEX:
6b1eedc1 66 case wxID_INFO:
5f7bcb48 67 case wxID_ITALIC:
6b1eedc1 68 case wxID_JUMP_TO:
5f7bcb48
VS
69 case wxID_JUSTIFY_CENTER:
70 case wxID_JUSTIFY_FILL:
71 case wxID_JUSTIFY_LEFT:
72 case wxID_JUSTIFY_RIGHT:
6b1eedc1
VZ
73 case wxID_LAST:
74 case wxID_NETWORK:
5f7bcb48
VS
75 case wxID_NEW:
76 case wxID_NO:
77 case wxID_OK:
78 case wxID_OPEN:
79 case wxID_PASTE:
80 case wxID_PREFERENCES:
5f7bcb48 81 case wxID_PREVIEW:
6b1eedc1 82 case wxID_PRINT:
5f7bcb48 83 case wxID_PROPERTIES:
5f7bcb48
VS
84 case wxID_REDO:
85 case wxID_REFRESH:
86 case wxID_REMOVE:
6b1eedc1 87 case wxID_REPLACE:
5f7bcb48
VS
88 case wxID_REVERT_TO_SAVED:
89 case wxID_SAVE:
90 case wxID_SAVEAS:
ee0a94cf 91 case wxID_SELECTALL:
6b1eedc1
VZ
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:
5f7bcb48 97 case wxID_STOP:
6b1eedc1
VZ
98 case wxID_STRIKETHROUGH:
99 case wxID_TOP:
5f7bcb48
VS
100 case wxID_UNDELETE:
101 case wxID_UNDERLINE:
102 case wxID_UNDO:
103 case wxID_UNINDENT:
6b1eedc1 104 case wxID_UP:
5f7bcb48
VS
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;
d0ee33f5 114 }
5f7bcb48
VS
115}
116
ee0a94cf 117wxString wxGetStockLabel(wxWindowID id, long flags)
401e3b6e 118{
634629fa
WS
119 wxString stockLabel;
120
401e3b6e
VS
121 #define STOCKITEM(stockid, label) \
122 case stockid: \
634629fa
WS
123 stockLabel = label; \
124 break;
401e3b6e 125
5f7bcb48 126 switch (id)
401e3b6e 127 {
5486c1a2 128 STOCKITEM(wxID_ABOUT, _("&About..."))
5f7bcb48
VS
129 STOCKITEM(wxID_ADD, _("Add"))
130 STOCKITEM(wxID_APPLY, _("&Apply"))
6b1eedc1 131 STOCKITEM(wxID_BACKWARD, _("&Back"))
5f7bcb48 132 STOCKITEM(wxID_BOLD, _("&Bold"))
6b1eedc1 133 STOCKITEM(wxID_BOTTOM, _("&Bottom"))
5f7bcb48 134 STOCKITEM(wxID_CANCEL, _("&Cancel"))
6b1eedc1 135 STOCKITEM(wxID_CDROM, _("&CD-Rom"))
5f7bcb48
VS
136 STOCKITEM(wxID_CLEAR, _("&Clear"))
137 STOCKITEM(wxID_CLOSE, _("&Close"))
6b1eedc1 138 STOCKITEM(wxID_CONVERT, _("&Convert"))
5f7bcb48
VS
139 STOCKITEM(wxID_COPY, _("&Copy"))
140 STOCKITEM(wxID_CUT, _("Cu&t"))
141 STOCKITEM(wxID_DELETE, _("&Delete"))
6b1eedc1 142 STOCKITEM(wxID_DOWN, _("&Down"))
ee0a94cf 143 STOCKITEM(wxID_EDIT, _("&Edit"))
6b1eedc1
VZ
144 STOCKITEM(wxID_EXECUTE, _("&Execute"))
145 STOCKITEM(wxID_EXIT, _("&Quit"))
ee0a94cf 146 STOCKITEM(wxID_FILE, _("&File"))
6b1eedc1
VZ
147 STOCKITEM(wxID_FIND, _("&Find"))
148 STOCKITEM(wxID_FIRST, _("&First"))
149 STOCKITEM(wxID_FLOPPY, _("&Floppy"))
5f7bcb48 150 STOCKITEM(wxID_FORWARD, _("&Forward"))
6b1eedc1 151 STOCKITEM(wxID_HARDDISK, _("&Harddisk"))
5f7bcb48
VS
152 STOCKITEM(wxID_HELP, _("&Help"))
153 STOCKITEM(wxID_HOME, _("&Home"))
154 STOCKITEM(wxID_INDENT, _("Indent"))
155 STOCKITEM(wxID_INDEX, _("&Index"))
6b1eedc1 156 STOCKITEM(wxID_INFO, _("&Info"))
5f7bcb48 157 STOCKITEM(wxID_ITALIC, _("&Italic"))
6b1eedc1 158 STOCKITEM(wxID_JUMP_TO, _("&Jump to"))
5f7bcb48
VS
159 STOCKITEM(wxID_JUSTIFY_CENTER, _("Centered"))
160 STOCKITEM(wxID_JUSTIFY_FILL, _("Justified"))
161 STOCKITEM(wxID_JUSTIFY_LEFT, _("Align Left"))
162 STOCKITEM(wxID_JUSTIFY_RIGHT, _("Align Right"))
6b1eedc1
VZ
163 STOCKITEM(wxID_LAST, _("&Last"))
164 STOCKITEM(wxID_NETWORK, _("&Network"))
5f7bcb48
VS
165 STOCKITEM(wxID_NEW, _("&New"))
166 STOCKITEM(wxID_NO, _("&No"))
167 STOCKITEM(wxID_OK, _("&OK"))
5486c1a2 168 STOCKITEM(wxID_OPEN, _("&Open..."))
5f7bcb48
VS
169 STOCKITEM(wxID_PASTE, _("&Paste"))
170 STOCKITEM(wxID_PREFERENCES, _("&Preferences"))
5f7bcb48 171 STOCKITEM(wxID_PREVIEW, _("Print previe&w"))
6b1eedc1 172 STOCKITEM(wxID_PRINT, _("&Print..."))
5f7bcb48 173 STOCKITEM(wxID_PROPERTIES, _("&Properties"))
5f7bcb48
VS
174 STOCKITEM(wxID_REDO, _("&Redo"))
175 STOCKITEM(wxID_REFRESH, _("Refresh"))
176 STOCKITEM(wxID_REMOVE, _("Remove"))
6b1eedc1 177 STOCKITEM(wxID_REPLACE, _("Rep&lace"))
5f7bcb48
VS
178 STOCKITEM(wxID_REVERT_TO_SAVED, _("Revert to Saved"))
179 STOCKITEM(wxID_SAVE, _("&Save"))
180 STOCKITEM(wxID_SAVEAS, _("Save &As..."))
5486c1a2 181 STOCKITEM(wxID_SELECTALL, _("Select &All"))
6b1eedc1
VZ
182 STOCKITEM(wxID_SELECT_COLOR, _("&Color"))
183 STOCKITEM(wxID_SELECT_FONT, _("&Font"))
184 STOCKITEM(wxID_SORT_ASCENDING, _("&Ascending"))
185 STOCKITEM(wxID_SORT_DESCENDING, _("&Descending"))
186 STOCKITEM(wxID_SPELL_CHECK, _("&Spell Check"))
5f7bcb48 187 STOCKITEM(wxID_STOP, _("&Stop"))
6b1eedc1
VZ
188 STOCKITEM(wxID_STRIKETHROUGH, _("&Strikethrough"))
189 STOCKITEM(wxID_TOP, _("&Top"))
5f7bcb48
VS
190 STOCKITEM(wxID_UNDELETE, _("Undelete"))
191 STOCKITEM(wxID_UNDERLINE, _("&Underline"))
192 STOCKITEM(wxID_UNDO, _("&Undo"))
193 STOCKITEM(wxID_UNINDENT, _("&Unindent"))
6b1eedc1 194 STOCKITEM(wxID_UP, _("&Up"))
5f7bcb48
VS
195 STOCKITEM(wxID_YES, _("&Yes"))
196 STOCKITEM(wxID_ZOOM_100, _("&Actual Size"))
197 STOCKITEM(wxID_ZOOM_FIT, _("Zoom to &Fit"))
198 STOCKITEM(wxID_ZOOM_IN, _("Zoom &In"))
199 STOCKITEM(wxID_ZOOM_OUT, _("Zoom &Out"))
200
401e3b6e
VS
201 default:
202 wxFAIL_MSG( _T("invalid stock item ID") );
203 break;
204 };
205
206 #undef STOCKITEM
d775fa82 207
4322f94f 208 if ( !(flags & wxSTOCK_WITH_MNEMONIC) )
634629fa 209 {
9b3c3047 210 stockLabel = wxStripMenuCodes(stockLabel);
634629fa 211 }
ee0a94cf 212
b137e493 213#if wxUSE_ACCEL
9b3c3047 214 if ( !stockLabel.empty() && (flags & wxSTOCK_WITH_ACCELERATOR) )
634629fa 215 {
ee0a94cf
RR
216 wxAcceleratorEntry accel = wxGetStockAccelerator(id);
217 if (accel.IsOk())
9b3c3047 218 stockLabel << _T('\t') << accel.ToString();
634629fa 219 }
b137e493
WS
220#endif // wxUSE_ACCEL
221
634629fa 222 return stockLabel;
401e3b6e
VS
223}
224
345319d6
VZ
225wxString wxGetStockHelpString(wxWindowID id, wxStockHelpStringClient client)
226{
227 wxString stockHelp;
228
229 #define STOCKITEM(stockid, ctx, helpstr) \
230 case stockid: \
231 if (client==ctx) stockHelp = helpstr; \
232 break;
233
234 switch (id)
235 {
236 // NB: these help string should be not too specific as they could be used
237 // in completely different programs!
238 STOCKITEM(wxID_ABOUT, wxSTOCK_MENU, _("Show about dialog"))
239 STOCKITEM(wxID_COPY, wxSTOCK_MENU, _("Copy selection"))
240 STOCKITEM(wxID_CUT, wxSTOCK_MENU, _("Cut selection"))
241 STOCKITEM(wxID_DELETE, wxSTOCK_MENU, _("Delete selection"))
242 STOCKITEM(wxID_REPLACE, wxSTOCK_MENU, _("Replace selection"))
243 STOCKITEM(wxID_PASTE, wxSTOCK_MENU, _("Paste selection"))
244 STOCKITEM(wxID_EXIT, wxSTOCK_MENU, _("Quit this program"))
245 STOCKITEM(wxID_REDO, wxSTOCK_MENU, _("Redo last action"))
246 STOCKITEM(wxID_UNDO, wxSTOCK_MENU, _("Undo last action"))
247 STOCKITEM(wxID_CLOSE, wxSTOCK_MENU, _("Close current document"))
248 STOCKITEM(wxID_SAVE, wxSTOCK_MENU, _("Save current document"))
249 STOCKITEM(wxID_SAVEAS, wxSTOCK_MENU, _("Save current document with a different filename"))
250
251 default:
252 // there's no stock help string for this ID / client
253 return wxEmptyString;
254 }
255
256 #undef STOCKITEM
257
258 return stockHelp;
259}
260
b137e493
WS
261#if wxUSE_ACCEL
262
ee0a94cf
RR
263wxAcceleratorEntry wxGetStockAccelerator(wxWindowID id)
264{
265 wxAcceleratorEntry ret;
266
267 #define STOCKITEM(stockid, flags, keycode) \
268 case stockid: \
269 ret.Set(flags, keycode, stockid); \
270 break;
271
272 switch (id)
273 {
274 STOCKITEM(wxID_COPY, wxACCEL_CTRL,'C')
275 STOCKITEM(wxID_CUT, wxACCEL_CTRL,'X')
276 STOCKITEM(wxID_FIND, wxACCEL_CTRL,'F')
277 STOCKITEM(wxID_REPLACE, wxACCEL_CTRL,'R')
278 STOCKITEM(wxID_HELP, wxACCEL_CTRL,'H')
279 STOCKITEM(wxID_NEW, wxACCEL_CTRL,'N')
280 STOCKITEM(wxID_OPEN, wxACCEL_CTRL,'O')
281 STOCKITEM(wxID_PASTE, wxACCEL_CTRL,'V')
282 STOCKITEM(wxID_SAVE, wxACCEL_CTRL,'S')
283
284 default:
285 // set the wxAcceleratorEntry to return into an invalid state:
286 // there's no stock accelerator for that.
287 ret.Set(0, 0, id);
288 break;
289 };
290
291 #undef STOCKITEM
292
293 // always use wxAcceleratorEntry::IsOk on returned value !
294 return ret;
295}
296
b137e493
WS
297#endif // wxUSE_ACCEL
298
5f7bcb48
VS
299bool wxIsStockLabel(wxWindowID id, const wxString& label)
300{
301 if (label.empty())
302 return true;
303
304 wxString stock = wxGetStockLabel(id);
305
306 if (label == stock)
307 return true;
d775fa82 308
5f7bcb48
VS
309 stock.Replace(_T("&"), wxEmptyString);
310 if (label == stock)
311 return true;
d775fa82 312
5f7bcb48
VS
313 return false;
314}