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
)
61 case wxID_JUSTIFY_CENTER
:
62 case wxID_JUSTIFY_FILL
:
63 case wxID_JUSTIFY_LEFT
:
64 case wxID_JUSTIFY_RIGHT
:
70 case wxID_PREFERENCES
:
78 case wxID_REVERT_TO_SAVED
:
99 wxString
wxGetStockLabel(wxWindowID id
, long flags
)
103 #define STOCKITEM(stockid, label) \
105 stockLabel = label; \
110 STOCKITEM(wxID_ABOUT
, _("&About"))
111 STOCKITEM(wxID_ADD
, _("Add"))
112 STOCKITEM(wxID_APPLY
, _("&Apply"))
113 STOCKITEM(wxID_BOLD
, _("&Bold"))
114 STOCKITEM(wxID_CANCEL
, _("&Cancel"))
115 STOCKITEM(wxID_CLEAR
, _("&Clear"))
116 STOCKITEM(wxID_CLOSE
, _("&Close"))
117 STOCKITEM(wxID_COPY
, _("&Copy"))
118 STOCKITEM(wxID_CUT
, _("Cu&t"))
119 STOCKITEM(wxID_DELETE
, _("&Delete"))
120 STOCKITEM(wxID_EDIT
, _("&Edit"))
121 STOCKITEM(wxID_FIND
, _("&Find"))
122 STOCKITEM(wxID_FILE
, _("&File"))
123 STOCKITEM(wxID_REPLACE
, _("Rep&lace"))
124 STOCKITEM(wxID_BACKWARD
, _("&Back"))
125 STOCKITEM(wxID_DOWN
, _("&Down"))
126 STOCKITEM(wxID_FORWARD
, _("&Forward"))
127 STOCKITEM(wxID_UP
, _("&Up"))
128 STOCKITEM(wxID_HELP
, _("&Help"))
129 STOCKITEM(wxID_HOME
, _("&Home"))
130 STOCKITEM(wxID_INDENT
, _("Indent"))
131 STOCKITEM(wxID_INDEX
, _("&Index"))
132 STOCKITEM(wxID_ITALIC
, _("&Italic"))
133 STOCKITEM(wxID_JUSTIFY_CENTER
, _("Centered"))
134 STOCKITEM(wxID_JUSTIFY_FILL
, _("Justified"))
135 STOCKITEM(wxID_JUSTIFY_LEFT
, _("Align Left"))
136 STOCKITEM(wxID_JUSTIFY_RIGHT
, _("Align Right"))
137 STOCKITEM(wxID_NEW
, _("&New"))
138 STOCKITEM(wxID_NO
, _("&No"))
139 STOCKITEM(wxID_OK
, _("&OK"))
140 STOCKITEM(wxID_OPEN
, _("&Open"))
141 STOCKITEM(wxID_PASTE
, _("&Paste"))
142 STOCKITEM(wxID_PREFERENCES
, _("&Preferences"))
143 STOCKITEM(wxID_PRINT
, _("&Print"))
144 STOCKITEM(wxID_PREVIEW
, _("Print previe&w"))
145 STOCKITEM(wxID_PROPERTIES
, _("&Properties"))
146 STOCKITEM(wxID_EXIT
, _("&Quit"))
147 STOCKITEM(wxID_REDO
, _("&Redo"))
148 STOCKITEM(wxID_REFRESH
, _("Refresh"))
149 STOCKITEM(wxID_REMOVE
, _("Remove"))
150 STOCKITEM(wxID_REVERT_TO_SAVED
, _("Revert to Saved"))
151 STOCKITEM(wxID_SAVE
, _("&Save"))
152 STOCKITEM(wxID_SAVEAS
, _("Save &As..."))
153 STOCKITEM(wxID_SELECTALL
, _("Select all"))
154 STOCKITEM(wxID_STOP
, _("&Stop"))
155 STOCKITEM(wxID_UNDELETE
, _("Undelete"))
156 STOCKITEM(wxID_UNDERLINE
, _("&Underline"))
157 STOCKITEM(wxID_UNDO
, _("&Undo"))
158 STOCKITEM(wxID_UNINDENT
, _("&Unindent"))
159 STOCKITEM(wxID_YES
, _("&Yes"))
160 STOCKITEM(wxID_ZOOM_100
, _("&Actual Size"))
161 STOCKITEM(wxID_ZOOM_FIT
, _("Zoom to &Fit"))
162 STOCKITEM(wxID_ZOOM_IN
, _("Zoom &In"))
163 STOCKITEM(wxID_ZOOM_OUT
, _("Zoom &Out"))
166 wxFAIL_MSG( _T("invalid stock item ID") );
172 if ( !(flags
& wxSTOCK_WITH_MNEMONIC
) )
174 stockLabel
= wxStripMenuCodes( stockLabel
);
179 if (!stockLabel
.empty() && (flags
& wxSTOCK_WITH_ACCELERATOR
))
181 stockLabel
+= _T("\t");
183 wxAcceleratorEntry accel
= wxGetStockAccelerator(id
);
185 stockLabel
+= accel
.ToString();
188 #endif // wxUSE_ACCEL
193 wxString
wxGetStockHelpString(wxWindowID id
, wxStockHelpStringClient client
)
197 #define STOCKITEM(stockid, ctx, helpstr) \
199 if (client==ctx) stockHelp = helpstr; \
204 // NB: these help string should be not too specific as they could be used
205 // in completely different programs!
206 STOCKITEM(wxID_ABOUT
, wxSTOCK_MENU
, _("Show about dialog"))
207 STOCKITEM(wxID_COPY
, wxSTOCK_MENU
, _("Copy selection"))
208 STOCKITEM(wxID_CUT
, wxSTOCK_MENU
, _("Cut selection"))
209 STOCKITEM(wxID_DELETE
, wxSTOCK_MENU
, _("Delete selection"))
210 STOCKITEM(wxID_REPLACE
, wxSTOCK_MENU
, _("Replace selection"))
211 STOCKITEM(wxID_PASTE
, wxSTOCK_MENU
, _("Paste selection"))
212 STOCKITEM(wxID_EXIT
, wxSTOCK_MENU
, _("Quit this program"))
213 STOCKITEM(wxID_REDO
, wxSTOCK_MENU
, _("Redo last action"))
214 STOCKITEM(wxID_UNDO
, wxSTOCK_MENU
, _("Undo last action"))
215 STOCKITEM(wxID_CLOSE
, wxSTOCK_MENU
, _("Close current document"))
216 STOCKITEM(wxID_SAVE
, wxSTOCK_MENU
, _("Save current document"))
217 STOCKITEM(wxID_SAVEAS
, wxSTOCK_MENU
, _("Save current document with a different filename"))
220 // there's no stock help string for this ID / client
221 return wxEmptyString
;
231 wxAcceleratorEntry
wxGetStockAccelerator(wxWindowID id
)
233 wxAcceleratorEntry ret
;
235 #define STOCKITEM(stockid, flags, keycode) \
237 ret.Set(flags, keycode, stockid); \
242 STOCKITEM(wxID_COPY
, wxACCEL_CTRL
,'C')
243 STOCKITEM(wxID_CUT
, wxACCEL_CTRL
,'X')
244 STOCKITEM(wxID_FIND
, wxACCEL_CTRL
,'F')
245 STOCKITEM(wxID_REPLACE
, wxACCEL_CTRL
,'R')
246 STOCKITEM(wxID_HELP
, wxACCEL_CTRL
,'H')
247 STOCKITEM(wxID_NEW
, wxACCEL_CTRL
,'N')
248 STOCKITEM(wxID_OPEN
, wxACCEL_CTRL
,'O')
249 STOCKITEM(wxID_PASTE
, wxACCEL_CTRL
,'V')
250 STOCKITEM(wxID_SAVE
, wxACCEL_CTRL
,'S')
253 // set the wxAcceleratorEntry to return into an invalid state:
254 // there's no stock accelerator for that.
261 // always use wxAcceleratorEntry::IsOk on returned value !
265 #endif // wxUSE_ACCEL
267 bool wxIsStockLabel(wxWindowID id
, const wxString
& label
)
272 wxString stock
= wxGetStockLabel(id
);
277 stock
.Replace(_T("&"), wxEmptyString
);
289 const char *wxGetStockGtkID(wxWindowID id
)
291 #define STOCKITEM(wx,gtk) \
295 #define STOCKITEM_MISSING(wx) \
299 #if GTK_CHECK_VERSION(2,4,0)
300 #define STOCKITEM_24(wx,gtk) STOCKITEM(wx,gtk)
302 #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
305 #if GTK_CHECK_VERSION(2,6,0)
306 #define STOCKITEM_26(wx,gtk) STOCKITEM(wx,gtk)
308 #define STOCKITEM_26(wx,gtk) STOCKITEM_MISSING(wx)
311 #if GTK_CHECK_VERSION(2,10,0)
312 #define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
314 #define STOCKITEM_210(wx,gtk) STOCKITEM_MISSING(wx)
320 STOCKITEM_26(wxID_ABOUT
, GTK_STOCK_ABOUT
)
321 STOCKITEM(wxID_ADD
, GTK_STOCK_ADD
)
322 STOCKITEM(wxID_APPLY
, GTK_STOCK_APPLY
)
323 STOCKITEM(wxID_BOLD
, GTK_STOCK_BOLD
)
324 STOCKITEM(wxID_CANCEL
, GTK_STOCK_CANCEL
)
325 STOCKITEM(wxID_CLEAR
, GTK_STOCK_CLEAR
)
326 STOCKITEM(wxID_CLOSE
, GTK_STOCK_CLOSE
)
327 STOCKITEM(wxID_COPY
, GTK_STOCK_COPY
)
328 STOCKITEM(wxID_CUT
, GTK_STOCK_CUT
)
329 STOCKITEM(wxID_DELETE
, GTK_STOCK_DELETE
)
330 STOCKITEM_26(wxID_EDIT
, GTK_STOCK_EDIT
)
331 STOCKITEM(wxID_FIND
, GTK_STOCK_FIND
)
332 STOCKITEM_26(wxID_FILE
, GTK_STOCK_FILE
)
333 STOCKITEM(wxID_REPLACE
, GTK_STOCK_FIND_AND_REPLACE
)
334 STOCKITEM(wxID_BACKWARD
, GTK_STOCK_GO_BACK
)
335 STOCKITEM(wxID_DOWN
, GTK_STOCK_GO_DOWN
)
336 STOCKITEM(wxID_FORWARD
, GTK_STOCK_GO_FORWARD
)
337 STOCKITEM(wxID_UP
, GTK_STOCK_GO_UP
)
338 STOCKITEM(wxID_HELP
, GTK_STOCK_HELP
)
339 STOCKITEM(wxID_HOME
, GTK_STOCK_HOME
)
340 STOCKITEM_24(wxID_INDENT
, GTK_STOCK_INDENT
)
341 STOCKITEM(wxID_INDEX
, GTK_STOCK_INDEX
)
342 STOCKITEM(wxID_ITALIC
, GTK_STOCK_ITALIC
)
343 STOCKITEM(wxID_JUSTIFY_CENTER
, GTK_STOCK_JUSTIFY_CENTER
)
344 STOCKITEM(wxID_JUSTIFY_FILL
, GTK_STOCK_JUSTIFY_FILL
)
345 STOCKITEM(wxID_JUSTIFY_LEFT
, GTK_STOCK_JUSTIFY_LEFT
)
346 STOCKITEM(wxID_JUSTIFY_RIGHT
, GTK_STOCK_JUSTIFY_RIGHT
)
347 STOCKITEM(wxID_NEW
, GTK_STOCK_NEW
)
348 STOCKITEM(wxID_NO
, GTK_STOCK_NO
)
349 STOCKITEM(wxID_OK
, GTK_STOCK_OK
)
350 STOCKITEM(wxID_OPEN
, GTK_STOCK_OPEN
)
351 STOCKITEM(wxID_PASTE
, GTK_STOCK_PASTE
)
352 STOCKITEM(wxID_PREFERENCES
, GTK_STOCK_PREFERENCES
)
353 STOCKITEM(wxID_PRINT
, GTK_STOCK_PRINT
)
354 STOCKITEM(wxID_PREVIEW
, GTK_STOCK_PRINT_PREVIEW
)
355 STOCKITEM(wxID_PROPERTIES
, GTK_STOCK_PROPERTIES
)
356 STOCKITEM(wxID_EXIT
, GTK_STOCK_QUIT
)
357 STOCKITEM(wxID_REDO
, GTK_STOCK_REDO
)
358 STOCKITEM(wxID_REFRESH
, GTK_STOCK_REFRESH
)
359 STOCKITEM(wxID_REMOVE
, GTK_STOCK_REMOVE
)
360 STOCKITEM(wxID_REVERT_TO_SAVED
, GTK_STOCK_REVERT_TO_SAVED
)
361 STOCKITEM(wxID_SAVE
, GTK_STOCK_SAVE
)
362 STOCKITEM(wxID_SAVEAS
, GTK_STOCK_SAVE_AS
)
363 STOCKITEM_210(wxID_SELECTALL
, GTK_STOCK_SELECT_ALL
)
364 STOCKITEM(wxID_STOP
, GTK_STOCK_STOP
)
365 STOCKITEM(wxID_UNDELETE
, GTK_STOCK_UNDELETE
)
366 STOCKITEM(wxID_UNDERLINE
, GTK_STOCK_UNDERLINE
)
367 STOCKITEM(wxID_UNDO
, GTK_STOCK_UNDO
)
368 STOCKITEM_24(wxID_UNINDENT
, GTK_STOCK_UNINDENT
)
369 STOCKITEM(wxID_YES
, GTK_STOCK_YES
)
370 STOCKITEM(wxID_ZOOM_100
, GTK_STOCK_ZOOM_100
)
371 STOCKITEM(wxID_ZOOM_FIT
, GTK_STOCK_ZOOM_FIT
)
372 STOCKITEM(wxID_ZOOM_IN
, GTK_STOCK_ZOOM_IN
)
373 STOCKITEM(wxID_ZOOM_OUT
, GTK_STOCK_ZOOM_OUT
)
376 wxFAIL_MSG( _T("invalid stock item ID") );
385 bool wxGetStockGtkAccelerator(const char *id
, GdkModifierType
*mod
, guint
*key
)
387 GtkStockItem stock_item
;
388 if (gtk_stock_lookup (id
, &stock_item
))
390 if (key
) *key
= stock_item
.keyval
;
391 if (mod
) *mod
= stock_item
.modifier
;
393 // some GTK stock items have zero values for the keyval;
394 // it means that they do not have an accelerator...
395 if (stock_item
.keyval
)
402 #endif // __WXGTK20__