1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/stockitem.cpp
3 // Purpose: Stock buttons, menu and toolbar items labels
4 // Author: Vaclav Slavik
8 // Copyright: (c) Vaclav Slavik, 2004
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/stockitem.h"
31 #include "wx/utils.h" // for wxStripMenuCodes()
34 bool wxIsStockID(wxWindowID id
)
69 case wxID_JUSTIFY_CENTER
:
70 case wxID_JUSTIFY_FILL
:
71 case wxID_JUSTIFY_LEFT
:
72 case wxID_JUSTIFY_RIGHT
:
80 case wxID_PREFERENCES
:
88 case wxID_REVERT_TO_SAVED
:
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
:
98 case wxID_STRIKETHROUGH
:
117 wxString
wxGetStockLabel(wxWindowID id
, long flags
)
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
;
130 #define STOCKITEM(stockid, labelWithMnemonic, labelPlain) \
132 if(flags & wxSTOCK_WITH_MNEMONIC) \
133 stockLabel = labelWithMnemonic; \
135 stockLabel = labelPlain; \
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_JUMP_TO
, _("&Jump to"), _("Jump to"));
171 STOCKITEM(wxID_JUSTIFY_CENTER
, _("Centered"), _("Centered"));
172 STOCKITEM(wxID_JUSTIFY_FILL
, _("Justified"), _("Justified"));
173 STOCKITEM(wxID_JUSTIFY_LEFT
, _("Align Left"), _("Align Left"));
174 STOCKITEM(wxID_JUSTIFY_RIGHT
, _("Align Right"), _("Align Right"));
175 STOCKITEM(wxID_LAST
, _("&Last"), _("Last"));
176 STOCKITEM(wxID_NETWORK
, _("&Network"), _("Network"));
177 STOCKITEM(wxID_NEW
, _("&New"), _("New"));
178 STOCKITEM(wxID_NO
, _("&No"), _("No"));
179 STOCKITEM(wxID_OK
, _("&OK"), _("OK"));
180 STOCKITEM(wxID_OPEN
, _("&Open..."), _("Open..."));
181 STOCKITEM(wxID_PASTE
, _("&Paste"), _("Paste"));
182 STOCKITEM(wxID_PREFERENCES
, _("&Preferences"), _("Preferences"));
183 STOCKITEM(wxID_PREVIEW
, _("&Preview..."), _("Preview..."));
184 STOCKITEM(wxID_PRINT
, _("&Print..."), _("Print..."));
185 STOCKITEM(wxID_PROPERTIES
, _("&Properties"), _("Properties"));
186 STOCKITEM(wxID_REDO
, _("&Redo"), _("Redo"));
187 STOCKITEM(wxID_REFRESH
, _("Refresh"), _("Refresh"));
188 STOCKITEM(wxID_REMOVE
, _("Remove"), _("Remove"));
189 STOCKITEM(wxID_REPLACE
, _("Rep&lace"), _("Replace"));
190 STOCKITEM(wxID_REVERT_TO_SAVED
, _("Revert to Saved"), _("Revert to Saved"));
191 STOCKITEM(wxID_SAVE
, _("&Save"), _("Save"));
192 STOCKITEM(wxID_SAVEAS
, _("&Save as"), _("Save as"));
193 STOCKITEM(wxID_SELECTALL
, _("Select &All"), _("Select All"));
194 STOCKITEM(wxID_SELECT_COLOR
, _("&Color"), _("Color"));
195 STOCKITEM(wxID_SELECT_FONT
, _("&Font"), _("Font"));
196 STOCKITEM(wxID_SORT_ASCENDING
, _("&Ascending"), _("Ascending"));
197 STOCKITEM(wxID_SORT_DESCENDING
, _("&Descending"), _("Descending"));
198 STOCKITEM(wxID_SPELL_CHECK
, _("&Spell Check"), _("Spell Check"));
199 STOCKITEM(wxID_STOP
, _("&Stop"), _("Stop"));
200 STOCKITEM(wxID_STRIKETHROUGH
, _("&Strikethrough"), _("Strikethrough"));
201 STOCKITEM(wxID_TOP
, _("&Top"), _("Top"));
202 STOCKITEM(wxID_UNDELETE
, _("Undelete"), _("Undelete"));
203 STOCKITEM(wxID_UNDERLINE
, _("&Underline"), _("Underline"));
204 STOCKITEM(wxID_UNDO
, _("&Undo"), _("Undo"));
205 STOCKITEM(wxID_UNINDENT
, _("&Unindent"), _("Unindent"));
206 STOCKITEM(wxID_UP
, _("&Up"), _("Up"));
207 STOCKITEM(wxID_YES
, _("&Yes"), _("Yes"));
208 STOCKITEM(wxID_ZOOM_100
, _("&Actual Size"), _("Actual Size"));
209 STOCKITEM(wxID_ZOOM_FIT
, _("Zoom to &Fit"), _("Zoom to Fit"));
210 STOCKITEM(wxID_ZOOM_IN
, _("Zoom &In"), _("Zoom In"));
211 STOCKITEM(wxID_ZOOM_OUT
, _("Zoom &Out"), _("Zoom Out"));
214 wxFAIL_MSG( wxT("invalid stock item ID") );
220 if ( flags
& wxSTOCK_WITHOUT_ELLIPSIS
)
223 if ( stockLabel
.EndsWith("...", &baseLabel
) )
224 stockLabel
= baseLabel
;
226 // accelerators only make sense for the menu items which should have
227 // ellipsis too while wxSTOCK_WITHOUT_ELLIPSIS is mostly useful for
228 // buttons which shouldn't have accelerators in their labels
229 wxASSERT_MSG( !(flags
& wxSTOCK_WITH_ACCELERATOR
),
230 "labels without ellipsis shouldn't use accelerators" );
234 if ( !stockLabel
.empty() && (flags
& wxSTOCK_WITH_ACCELERATOR
) )
236 wxAcceleratorEntry accel
= wxGetStockAccelerator(id
);
238 stockLabel
<< wxT('\t') << accel
.ToString();
240 #endif // wxUSE_ACCEL
245 wxString
wxGetStockHelpString(wxWindowID id
, wxStockHelpStringClient client
)
249 #define STOCKITEM(stockid, ctx, helpstr) \
251 if (client==ctx) stockHelp = helpstr; \
256 // NB: these help string should be not too specific as they could be used
257 // in completely different programs!
258 STOCKITEM(wxID_ABOUT
, wxSTOCK_MENU
, _("Show about dialog"))
259 STOCKITEM(wxID_COPY
, wxSTOCK_MENU
, _("Copy selection"))
260 STOCKITEM(wxID_CUT
, wxSTOCK_MENU
, _("Cut selection"))
261 STOCKITEM(wxID_DELETE
, wxSTOCK_MENU
, _("Delete selection"))
262 STOCKITEM(wxID_REPLACE
, wxSTOCK_MENU
, _("Replace selection"))
263 STOCKITEM(wxID_PASTE
, wxSTOCK_MENU
, _("Paste selection"))
264 STOCKITEM(wxID_EXIT
, wxSTOCK_MENU
, _("Quit this program"))
265 STOCKITEM(wxID_REDO
, wxSTOCK_MENU
, _("Redo last action"))
266 STOCKITEM(wxID_UNDO
, wxSTOCK_MENU
, _("Undo last action"))
267 STOCKITEM(wxID_CLOSE
, wxSTOCK_MENU
, _("Close current document"))
268 STOCKITEM(wxID_SAVE
, wxSTOCK_MENU
, _("Save current document"))
269 STOCKITEM(wxID_SAVEAS
, wxSTOCK_MENU
, _("Save current document with a different filename"))
272 // there's no stock help string for this ID / client
273 return wxEmptyString
;
283 wxAcceleratorEntry
wxGetStockAccelerator(wxWindowID id
)
285 wxAcceleratorEntry ret
;
287 #define STOCKITEM(stockid, flags, keycode) \
289 ret.Set(flags, keycode, stockid); \
294 STOCKITEM(wxID_COPY
, wxACCEL_CTRL
,'C')
295 STOCKITEM(wxID_CUT
, wxACCEL_CTRL
,'X')
296 STOCKITEM(wxID_FIND
, wxACCEL_CTRL
,'F')
297 STOCKITEM(wxID_HELP
, wxACCEL_CTRL
,'H')
298 STOCKITEM(wxID_NEW
, wxACCEL_CTRL
,'N')
299 STOCKITEM(wxID_OPEN
, wxACCEL_CTRL
,'O')
300 STOCKITEM(wxID_PASTE
, wxACCEL_CTRL
,'V')
301 STOCKITEM(wxID_PRINT
, wxACCEL_CTRL
,'P')
302 STOCKITEM(wxID_REDO
, wxACCEL_CTRL
| wxACCEL_SHIFT
,'Z')
303 STOCKITEM(wxID_REPLACE
, wxACCEL_CTRL
,'R')
304 STOCKITEM(wxID_SAVE
, wxACCEL_CTRL
,'S')
305 STOCKITEM(wxID_UNDO
, wxACCEL_CTRL
,'Z')
307 STOCKITEM(wxID_PREFERENCES
, wxACCEL_CTRL
,',')
311 // set the wxAcceleratorEntry to return into an invalid state:
312 // there's no stock accelerator for that.
319 // always use wxAcceleratorEntry::IsOk on returned value !
323 #endif // wxUSE_ACCEL
325 bool wxIsStockLabel(wxWindowID id
, const wxString
& label
)
330 wxString stock
= wxGetStockLabel(id
);
335 stock
.Replace(wxT("&"), wxEmptyString
);