]> git.saurik.com Git - wxWidgets.git/blame - src/common/stockitem.cpp
avoiding nesting dcs on the same window concurrently
[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:
41 case wxID_BOLD:
42 case wxID_CANCEL:
43 case wxID_CLEAR:
44 case wxID_CLOSE:
45 case wxID_COPY:
46 case wxID_CUT:
47 case wxID_DELETE:
ee0a94cf 48 case wxID_EDIT:
5f7bcb48 49 case wxID_FIND:
ee0a94cf 50 case wxID_FILE:
5f7bcb48
VS
51 case wxID_REPLACE:
52 case wxID_BACKWARD:
53 case wxID_DOWN:
54 case wxID_FORWARD:
55 case wxID_UP:
56 case wxID_HELP:
57 case wxID_HOME:
58 case wxID_INDENT:
59 case wxID_INDEX:
60 case wxID_ITALIC:
61 case wxID_JUSTIFY_CENTER:
62 case wxID_JUSTIFY_FILL:
63 case wxID_JUSTIFY_LEFT:
64 case wxID_JUSTIFY_RIGHT:
65 case wxID_NEW:
66 case wxID_NO:
67 case wxID_OK:
68 case wxID_OPEN:
69 case wxID_PASTE:
70 case wxID_PREFERENCES:
71 case wxID_PRINT:
72 case wxID_PREVIEW:
73 case wxID_PROPERTIES:
74 case wxID_EXIT:
75 case wxID_REDO:
76 case wxID_REFRESH:
77 case wxID_REMOVE:
78 case wxID_REVERT_TO_SAVED:
79 case wxID_SAVE:
80 case wxID_SAVEAS:
ee0a94cf 81 case wxID_SELECTALL:
5f7bcb48
VS
82 case wxID_STOP:
83 case wxID_UNDELETE:
84 case wxID_UNDERLINE:
85 case wxID_UNDO:
86 case wxID_UNINDENT:
87 case wxID_YES:
88 case wxID_ZOOM_100:
89 case wxID_ZOOM_FIT:
90 case wxID_ZOOM_IN:
91 case wxID_ZOOM_OUT:
92 return true;
93
94 default:
95 return false;
d0ee33f5 96 }
5f7bcb48
VS
97}
98
ee0a94cf 99wxString wxGetStockLabel(wxWindowID id, long flags)
401e3b6e 100{
634629fa
WS
101 wxString stockLabel;
102
401e3b6e
VS
103 #define STOCKITEM(stockid, label) \
104 case stockid: \
634629fa
WS
105 stockLabel = label; \
106 break;
401e3b6e 107
5f7bcb48 108 switch (id)
401e3b6e 109 {
ee0a94cf 110 STOCKITEM(wxID_ABOUT, _("&About"))
5f7bcb48
VS
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"))
ee0a94cf 120 STOCKITEM(wxID_EDIT, _("&Edit"))
5f7bcb48 121 STOCKITEM(wxID_FIND, _("&Find"))
ee0a94cf 122 STOCKITEM(wxID_FILE, _("&File"))
5f7bcb48
VS
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..."))
ee0a94cf 153 STOCKITEM(wxID_SELECTALL, _("Select all"))
5f7bcb48
VS
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"))
164
401e3b6e
VS
165 default:
166 wxFAIL_MSG( _T("invalid stock item ID") );
167 break;
168 };
169
170 #undef STOCKITEM
d775fa82 171
4322f94f 172 if ( !(flags & wxSTOCK_WITH_MNEMONIC) )
634629fa 173 {
9b3c3047 174 stockLabel = wxStripMenuCodes(stockLabel);
634629fa 175 }
ee0a94cf 176
b137e493 177#if wxUSE_ACCEL
9b3c3047 178 if ( !stockLabel.empty() && (flags & wxSTOCK_WITH_ACCELERATOR) )
634629fa 179 {
ee0a94cf
RR
180 wxAcceleratorEntry accel = wxGetStockAccelerator(id);
181 if (accel.IsOk())
9b3c3047 182 stockLabel << _T('\t') << accel.ToString();
634629fa 183 }
b137e493
WS
184#endif // wxUSE_ACCEL
185
634629fa 186 return stockLabel;
401e3b6e
VS
187}
188
345319d6
VZ
189wxString wxGetStockHelpString(wxWindowID id, wxStockHelpStringClient client)
190{
191 wxString stockHelp;
192
193 #define STOCKITEM(stockid, ctx, helpstr) \
194 case stockid: \
195 if (client==ctx) stockHelp = helpstr; \
196 break;
197
198 switch (id)
199 {
200 // NB: these help string should be not too specific as they could be used
201 // in completely different programs!
202 STOCKITEM(wxID_ABOUT, wxSTOCK_MENU, _("Show about dialog"))
203 STOCKITEM(wxID_COPY, wxSTOCK_MENU, _("Copy selection"))
204 STOCKITEM(wxID_CUT, wxSTOCK_MENU, _("Cut selection"))
205 STOCKITEM(wxID_DELETE, wxSTOCK_MENU, _("Delete selection"))
206 STOCKITEM(wxID_REPLACE, wxSTOCK_MENU, _("Replace selection"))
207 STOCKITEM(wxID_PASTE, wxSTOCK_MENU, _("Paste selection"))
208 STOCKITEM(wxID_EXIT, wxSTOCK_MENU, _("Quit this program"))
209 STOCKITEM(wxID_REDO, wxSTOCK_MENU, _("Redo last action"))
210 STOCKITEM(wxID_UNDO, wxSTOCK_MENU, _("Undo last action"))
211 STOCKITEM(wxID_CLOSE, wxSTOCK_MENU, _("Close current document"))
212 STOCKITEM(wxID_SAVE, wxSTOCK_MENU, _("Save current document"))
213 STOCKITEM(wxID_SAVEAS, wxSTOCK_MENU, _("Save current document with a different filename"))
214
215 default:
216 // there's no stock help string for this ID / client
217 return wxEmptyString;
218 }
219
220 #undef STOCKITEM
221
222 return stockHelp;
223}
224
b137e493
WS
225#if wxUSE_ACCEL
226
ee0a94cf
RR
227wxAcceleratorEntry wxGetStockAccelerator(wxWindowID id)
228{
229 wxAcceleratorEntry ret;
230
231 #define STOCKITEM(stockid, flags, keycode) \
232 case stockid: \
233 ret.Set(flags, keycode, stockid); \
234 break;
235
236 switch (id)
237 {
238 STOCKITEM(wxID_COPY, wxACCEL_CTRL,'C')
239 STOCKITEM(wxID_CUT, wxACCEL_CTRL,'X')
240 STOCKITEM(wxID_FIND, wxACCEL_CTRL,'F')
241 STOCKITEM(wxID_REPLACE, wxACCEL_CTRL,'R')
242 STOCKITEM(wxID_HELP, wxACCEL_CTRL,'H')
243 STOCKITEM(wxID_NEW, wxACCEL_CTRL,'N')
244 STOCKITEM(wxID_OPEN, wxACCEL_CTRL,'O')
245 STOCKITEM(wxID_PASTE, wxACCEL_CTRL,'V')
246 STOCKITEM(wxID_SAVE, wxACCEL_CTRL,'S')
247
248 default:
249 // set the wxAcceleratorEntry to return into an invalid state:
250 // there's no stock accelerator for that.
251 ret.Set(0, 0, id);
252 break;
253 };
254
255 #undef STOCKITEM
256
257 // always use wxAcceleratorEntry::IsOk on returned value !
258 return ret;
259}
260
b137e493
WS
261#endif // wxUSE_ACCEL
262
5f7bcb48
VS
263bool wxIsStockLabel(wxWindowID id, const wxString& label)
264{
265 if (label.empty())
266 return true;
267
268 wxString stock = wxGetStockLabel(id);
269
270 if (label == stock)
271 return true;
d775fa82 272
5f7bcb48
VS
273 stock.Replace(_T("&"), wxEmptyString);
274 if (label == stock)
275 return true;
d775fa82 276
5f7bcb48
VS
277 return false;
278}
279
401e3b6e
VS
280
281#ifdef __WXGTK20__
282
283#include <gtk/gtk.h>
284
5f7bcb48 285const char *wxGetStockGtkID(wxWindowID id)
401e3b6e 286{
5f7bcb48
VS
287 #define STOCKITEM(wx,gtk) \
288 case wx: \
289 return gtk;
d775fa82 290
5f7bcb48 291 #define STOCKITEM_MISSING(wx) \
c4c3e30f 292 case wx: \
4b5966d7 293 return NULL;
c20889ab
VS
294
295 #if GTK_CHECK_VERSION(2,4,0)
5f7bcb48 296 #define STOCKITEM_24(wx,gtk) STOCKITEM(wx,gtk)
c20889ab 297 #else
5f7bcb48 298 #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
c20889ab 299 #endif
401e3b6e 300
ee0a94cf
RR
301 #if GTK_CHECK_VERSION(2,6,0)
302 #define STOCKITEM_26(wx,gtk) STOCKITEM(wx,gtk)
303 #else
304 #define STOCKITEM_26(wx,gtk) STOCKITEM_MISSING(wx)
305 #endif
306
307 #if GTK_CHECK_VERSION(2,10,0)
308 #define STOCKITEM_210(wx,gtk) STOCKITEM(wx,gtk)
309 #else
310 #define STOCKITEM_210(wx,gtk) STOCKITEM_MISSING(wx)
311 #endif
312
313
5f7bcb48 314 switch (id)
401e3b6e 315 {
ee0a94cf 316 STOCKITEM_26(wxID_ABOUT, GTK_STOCK_ABOUT)
5f7bcb48
VS
317 STOCKITEM(wxID_ADD, GTK_STOCK_ADD)
318 STOCKITEM(wxID_APPLY, GTK_STOCK_APPLY)
319 STOCKITEM(wxID_BOLD, GTK_STOCK_BOLD)
320 STOCKITEM(wxID_CANCEL, GTK_STOCK_CANCEL)
321 STOCKITEM(wxID_CLEAR, GTK_STOCK_CLEAR)
322 STOCKITEM(wxID_CLOSE, GTK_STOCK_CLOSE)
323 STOCKITEM(wxID_COPY, GTK_STOCK_COPY)
324 STOCKITEM(wxID_CUT, GTK_STOCK_CUT)
325 STOCKITEM(wxID_DELETE, GTK_STOCK_DELETE)
ee0a94cf 326 STOCKITEM_26(wxID_EDIT, GTK_STOCK_EDIT)
5f7bcb48 327 STOCKITEM(wxID_FIND, GTK_STOCK_FIND)
ee0a94cf 328 STOCKITEM_26(wxID_FILE, GTK_STOCK_FILE)
5f7bcb48
VS
329 STOCKITEM(wxID_REPLACE, GTK_STOCK_FIND_AND_REPLACE)
330 STOCKITEM(wxID_BACKWARD, GTK_STOCK_GO_BACK)
331 STOCKITEM(wxID_DOWN, GTK_STOCK_GO_DOWN)
332 STOCKITEM(wxID_FORWARD, GTK_STOCK_GO_FORWARD)
333 STOCKITEM(wxID_UP, GTK_STOCK_GO_UP)
334 STOCKITEM(wxID_HELP, GTK_STOCK_HELP)
335 STOCKITEM(wxID_HOME, GTK_STOCK_HOME)
336 STOCKITEM_24(wxID_INDENT, GTK_STOCK_INDENT)
337 STOCKITEM(wxID_INDEX, GTK_STOCK_INDEX)
338 STOCKITEM(wxID_ITALIC, GTK_STOCK_ITALIC)
339 STOCKITEM(wxID_JUSTIFY_CENTER, GTK_STOCK_JUSTIFY_CENTER)
340 STOCKITEM(wxID_JUSTIFY_FILL, GTK_STOCK_JUSTIFY_FILL)
341 STOCKITEM(wxID_JUSTIFY_LEFT, GTK_STOCK_JUSTIFY_LEFT)
342 STOCKITEM(wxID_JUSTIFY_RIGHT, GTK_STOCK_JUSTIFY_RIGHT)
343 STOCKITEM(wxID_NEW, GTK_STOCK_NEW)
344 STOCKITEM(wxID_NO, GTK_STOCK_NO)
345 STOCKITEM(wxID_OK, GTK_STOCK_OK)
346 STOCKITEM(wxID_OPEN, GTK_STOCK_OPEN)
347 STOCKITEM(wxID_PASTE, GTK_STOCK_PASTE)
348 STOCKITEM(wxID_PREFERENCES, GTK_STOCK_PREFERENCES)
349 STOCKITEM(wxID_PRINT, GTK_STOCK_PRINT)
350 STOCKITEM(wxID_PREVIEW, GTK_STOCK_PRINT_PREVIEW)
351 STOCKITEM(wxID_PROPERTIES, GTK_STOCK_PROPERTIES)
352 STOCKITEM(wxID_EXIT, GTK_STOCK_QUIT)
353 STOCKITEM(wxID_REDO, GTK_STOCK_REDO)
354 STOCKITEM(wxID_REFRESH, GTK_STOCK_REFRESH)
355 STOCKITEM(wxID_REMOVE, GTK_STOCK_REMOVE)
356 STOCKITEM(wxID_REVERT_TO_SAVED, GTK_STOCK_REVERT_TO_SAVED)
357 STOCKITEM(wxID_SAVE, GTK_STOCK_SAVE)
358 STOCKITEM(wxID_SAVEAS, GTK_STOCK_SAVE_AS)
ee0a94cf 359 STOCKITEM_210(wxID_SELECTALL, GTK_STOCK_SELECT_ALL)
5f7bcb48
VS
360 STOCKITEM(wxID_STOP, GTK_STOCK_STOP)
361 STOCKITEM(wxID_UNDELETE, GTK_STOCK_UNDELETE)
362 STOCKITEM(wxID_UNDERLINE, GTK_STOCK_UNDERLINE)
363 STOCKITEM(wxID_UNDO, GTK_STOCK_UNDO)
364 STOCKITEM_24(wxID_UNINDENT, GTK_STOCK_UNINDENT)
365 STOCKITEM(wxID_YES, GTK_STOCK_YES)
366 STOCKITEM(wxID_ZOOM_100, GTK_STOCK_ZOOM_100)
367 STOCKITEM(wxID_ZOOM_FIT, GTK_STOCK_ZOOM_FIT)
368 STOCKITEM(wxID_ZOOM_IN, GTK_STOCK_ZOOM_IN)
369 STOCKITEM(wxID_ZOOM_OUT, GTK_STOCK_ZOOM_OUT)
370
401e3b6e
VS
371 default:
372 wxFAIL_MSG( _T("invalid stock item ID") );
373 break;
374 };
375
376 #undef STOCKITEM
d775fa82 377
401e3b6e
VS
378 return NULL;
379}
380
ee0a94cf
RR
381bool wxGetStockGtkAccelerator(const char *id, GdkModifierType *mod, guint *key)
382{
97c7099a
RR
383 if (!id)
384 return false;
385
ee0a94cf
RR
386 GtkStockItem stock_item;
387 if (gtk_stock_lookup (id, &stock_item))
388 {
389 if (key) *key = stock_item.keyval;
390 if (mod) *mod = stock_item.modifier;
391
392 // some GTK stock items have zero values for the keyval;
393 // it means that they do not have an accelerator...
394 if (stock_item.keyval)
395 return true;
396 }
397
398 return false;
399}
400
401e3b6e 401#endif // __WXGTK20__