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
)
121 #define STOCKITEM(stockid, label) \
123 stockLabel = label; \
128 STOCKITEM(wxID_ABOUT
, _("&About..."))
129 STOCKITEM(wxID_ADD
, _("Add"))
130 STOCKITEM(wxID_APPLY
, _("&Apply"))
131 STOCKITEM(wxID_BACKWARD
, _("&Back"))
132 STOCKITEM(wxID_BOLD
, _("&Bold"))
133 STOCKITEM(wxID_BOTTOM
, _("&Bottom"))
134 STOCKITEM(wxID_CANCEL
, _("&Cancel"))
135 STOCKITEM(wxID_CDROM
, _("&CD-Rom"))
136 STOCKITEM(wxID_CLEAR
, _("&Clear"))
137 STOCKITEM(wxID_CLOSE
, _("&Close"))
138 STOCKITEM(wxID_CONVERT
, _("&Convert"))
139 STOCKITEM(wxID_COPY
, _("&Copy"))
140 STOCKITEM(wxID_CUT
, _("Cu&t"))
141 STOCKITEM(wxID_DELETE
, _("&Delete"))
142 STOCKITEM(wxID_DOWN
, _("&Down"))
143 STOCKITEM(wxID_EDIT
, _("&Edit"))
144 STOCKITEM(wxID_EXECUTE
, _("&Execute"))
145 STOCKITEM(wxID_EXIT
, _("&Quit"))
146 STOCKITEM(wxID_FILE
, _("&File"))
147 STOCKITEM(wxID_FIND
, _("&Find"))
148 STOCKITEM(wxID_FIRST
, _("&First"))
149 STOCKITEM(wxID_FLOPPY
, _("&Floppy"))
150 STOCKITEM(wxID_FORWARD
, _("&Forward"))
151 STOCKITEM(wxID_HARDDISK
, _("&Harddisk"))
152 STOCKITEM(wxID_HELP
, _("&Help"))
153 STOCKITEM(wxID_HOME
, _("&Home"))
154 STOCKITEM(wxID_INDENT
, _("Indent"))
155 STOCKITEM(wxID_INDEX
, _("&Index"))
156 STOCKITEM(wxID_INFO
, _("&Info"))
157 STOCKITEM(wxID_ITALIC
, _("&Italic"))
158 STOCKITEM(wxID_JUMP_TO
, _("&Jump to"))
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"))
163 STOCKITEM(wxID_LAST
, _("&Last"))
164 STOCKITEM(wxID_NETWORK
, _("&Network"))
165 STOCKITEM(wxID_NEW
, _("&New"))
166 STOCKITEM(wxID_NO
, _("&No"))
167 STOCKITEM(wxID_OK
, _("&OK"))
168 STOCKITEM(wxID_OPEN
, _("&Open..."))
169 STOCKITEM(wxID_PASTE
, _("&Paste"))
170 STOCKITEM(wxID_PREFERENCES
, _("&Preferences"))
171 STOCKITEM(wxID_PREVIEW
, _("Print previe&w"))
172 STOCKITEM(wxID_PRINT
, _("&Print..."))
173 STOCKITEM(wxID_PROPERTIES
, _("&Properties"))
174 STOCKITEM(wxID_REDO
, _("&Redo"))
175 STOCKITEM(wxID_REFRESH
, _("Refresh"))
176 STOCKITEM(wxID_REMOVE
, _("Remove"))
177 STOCKITEM(wxID_REPLACE
, _("Rep&lace"))
178 STOCKITEM(wxID_REVERT_TO_SAVED
, _("Revert to Saved"))
179 STOCKITEM(wxID_SAVE
, _("&Save"))
180 STOCKITEM(wxID_SAVEAS
, _("Save &As..."))
181 STOCKITEM(wxID_SELECTALL
, _("Select &All"))
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"))
187 STOCKITEM(wxID_STOP
, _("&Stop"))
188 STOCKITEM(wxID_STRIKETHROUGH
, _("&Strikethrough"))
189 STOCKITEM(wxID_TOP
, _("&Top"))
190 STOCKITEM(wxID_UNDELETE
, _("Undelete"))
191 STOCKITEM(wxID_UNDERLINE
, _("&Underline"))
192 STOCKITEM(wxID_UNDO
, _("&Undo"))
193 STOCKITEM(wxID_UNINDENT
, _("&Unindent"))
194 STOCKITEM(wxID_UP
, _("&Up"))
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"))
202 wxFAIL_MSG( wxT("invalid stock item ID") );
208 if ( flags
& wxSTOCK_WITHOUT_ELLIPSIS
)
211 if ( stockLabel
.EndsWith("...", &baseLabel
) )
212 stockLabel
= baseLabel
;
214 // accelerators only make sense for the menu items which should have
215 // ellipsis too while wxSTOCK_WITHOUT_ELLIPSIS is mostly useful for
216 // buttons which shouldn't have accelerators in their labels
217 wxASSERT_MSG( !(flags
& wxSTOCK_WITH_ACCELERATOR
),
218 "labels without ellipsis shouldn't use accelerators" );
222 // special case: the "Cancel" button shouldn't have a mnemonic under MSW
223 // for consistency with the native dialogs (which don't use any mnemonic
224 // for it because it is already bound to Esc implicitly)
225 if ( id
== wxID_CANCEL
)
226 flags
&= ~wxSTOCK_WITH_MNEMONIC
;
229 if ( !(flags
& wxSTOCK_WITH_MNEMONIC
) )
231 stockLabel
= wxStripMenuCodes(stockLabel
);
235 if ( !stockLabel
.empty() && (flags
& wxSTOCK_WITH_ACCELERATOR
) )
237 wxAcceleratorEntry accel
= wxGetStockAccelerator(id
);
239 stockLabel
<< wxT('\t') << accel
.ToString();
241 #endif // wxUSE_ACCEL
246 wxString
wxGetStockHelpString(wxWindowID id
, wxStockHelpStringClient client
)
250 #define STOCKITEM(stockid, ctx, helpstr) \
252 if (client==ctx) stockHelp = helpstr; \
257 // NB: these help string should be not too specific as they could be used
258 // in completely different programs!
259 STOCKITEM(wxID_ABOUT
, wxSTOCK_MENU
, _("Show about dialog"))
260 STOCKITEM(wxID_COPY
, wxSTOCK_MENU
, _("Copy selection"))
261 STOCKITEM(wxID_CUT
, wxSTOCK_MENU
, _("Cut selection"))
262 STOCKITEM(wxID_DELETE
, wxSTOCK_MENU
, _("Delete selection"))
263 STOCKITEM(wxID_REPLACE
, wxSTOCK_MENU
, _("Replace selection"))
264 STOCKITEM(wxID_PASTE
, wxSTOCK_MENU
, _("Paste selection"))
265 STOCKITEM(wxID_EXIT
, wxSTOCK_MENU
, _("Quit this program"))
266 STOCKITEM(wxID_REDO
, wxSTOCK_MENU
, _("Redo last action"))
267 STOCKITEM(wxID_UNDO
, wxSTOCK_MENU
, _("Undo last action"))
268 STOCKITEM(wxID_CLOSE
, wxSTOCK_MENU
, _("Close current document"))
269 STOCKITEM(wxID_SAVE
, wxSTOCK_MENU
, _("Save current document"))
270 STOCKITEM(wxID_SAVEAS
, wxSTOCK_MENU
, _("Save current document with a different filename"))
273 // there's no stock help string for this ID / client
274 return wxEmptyString
;
284 wxAcceleratorEntry
wxGetStockAccelerator(wxWindowID id
)
286 wxAcceleratorEntry ret
;
288 #define STOCKITEM(stockid, flags, keycode) \
290 ret.Set(flags, keycode, stockid); \
295 STOCKITEM(wxID_COPY
, wxACCEL_CMD
,'C')
296 STOCKITEM(wxID_CUT
, wxACCEL_CMD
,'X')
297 STOCKITEM(wxID_FIND
, wxACCEL_CMD
,'F')
298 STOCKITEM(wxID_HELP
, wxACCEL_CMD
,'H')
299 STOCKITEM(wxID_NEW
, wxACCEL_CMD
,'N')
300 STOCKITEM(wxID_OPEN
, wxACCEL_CMD
,'O')
301 STOCKITEM(wxID_PASTE
, wxACCEL_CMD
,'V')
302 STOCKITEM(wxID_REDO
, wxACCEL_CMD
| wxACCEL_SHIFT
,'Z')
303 STOCKITEM(wxID_REPLACE
, wxACCEL_CMD
,'R')
304 STOCKITEM(wxID_SAVE
, wxACCEL_CMD
,'S')
305 STOCKITEM(wxID_UNDO
, wxACCEL_CMD
,'Z')
308 // set the wxAcceleratorEntry to return into an invalid state:
309 // there's no stock accelerator for that.
316 // always use wxAcceleratorEntry::IsOk on returned value !
320 #endif // wxUSE_ACCEL
322 bool wxIsStockLabel(wxWindowID id
, const wxString
& label
)
327 wxString stock
= wxGetStockLabel(id
);
332 stock
.Replace(wxT("&"), wxEmptyString
);