]> git.saurik.com Git - wxWidgets.git/blame - src/common/stockitem.cpp
Include wx/brush.h according to precompiled headers of wx/wx.h (with other minor...
[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 {
38 case wxID_ADD:
39 case wxID_APPLY:
40 case wxID_BOLD:
41 case wxID_CANCEL:
42 case wxID_CLEAR:
43 case wxID_CLOSE:
44 case wxID_COPY:
45 case wxID_CUT:
46 case wxID_DELETE:
47 case wxID_FIND:
48 case wxID_REPLACE:
49 case wxID_BACKWARD:
50 case wxID_DOWN:
51 case wxID_FORWARD:
52 case wxID_UP:
53 case wxID_HELP:
54 case wxID_HOME:
55 case wxID_INDENT:
56 case wxID_INDEX:
57 case wxID_ITALIC:
58 case wxID_JUSTIFY_CENTER:
59 case wxID_JUSTIFY_FILL:
60 case wxID_JUSTIFY_LEFT:
61 case wxID_JUSTIFY_RIGHT:
62 case wxID_NEW:
63 case wxID_NO:
64 case wxID_OK:
65 case wxID_OPEN:
66 case wxID_PASTE:
67 case wxID_PREFERENCES:
68 case wxID_PRINT:
69 case wxID_PREVIEW:
70 case wxID_PROPERTIES:
71 case wxID_EXIT:
72 case wxID_REDO:
73 case wxID_REFRESH:
74 case wxID_REMOVE:
75 case wxID_REVERT_TO_SAVED:
76 case wxID_SAVE:
77 case wxID_SAVEAS:
78 case wxID_STOP:
79 case wxID_UNDELETE:
80 case wxID_UNDERLINE:
81 case wxID_UNDO:
82 case wxID_UNINDENT:
83 case wxID_YES:
84 case wxID_ZOOM_100:
85 case wxID_ZOOM_FIT:
86 case wxID_ZOOM_IN:
87 case wxID_ZOOM_OUT:
88 return true;
89
90 default:
91 return false;
d0ee33f5 92 }
5f7bcb48
VS
93}
94
fbfb8bcc 95wxString wxGetStockLabel(wxWindowID id, bool withCodes, const wxString& accelerator)
401e3b6e 96{
634629fa
WS
97 wxString stockLabel;
98
401e3b6e
VS
99 #define STOCKITEM(stockid, label) \
100 case stockid: \
634629fa
WS
101 stockLabel = label; \
102 break;
401e3b6e 103
5f7bcb48 104 switch (id)
401e3b6e 105 {
5f7bcb48
VS
106 STOCKITEM(wxID_ADD, _("Add"))
107 STOCKITEM(wxID_APPLY, _("&Apply"))
108 STOCKITEM(wxID_BOLD, _("&Bold"))
109 STOCKITEM(wxID_CANCEL, _("&Cancel"))
110 STOCKITEM(wxID_CLEAR, _("&Clear"))
111 STOCKITEM(wxID_CLOSE, _("&Close"))
112 STOCKITEM(wxID_COPY, _("&Copy"))
113 STOCKITEM(wxID_CUT, _("Cu&t"))
114 STOCKITEM(wxID_DELETE, _("&Delete"))
115 STOCKITEM(wxID_FIND, _("&Find"))
116 STOCKITEM(wxID_REPLACE, _("Rep&lace"))
117 STOCKITEM(wxID_BACKWARD, _("&Back"))
118 STOCKITEM(wxID_DOWN, _("&Down"))
119 STOCKITEM(wxID_FORWARD, _("&Forward"))
120 STOCKITEM(wxID_UP, _("&Up"))
121 STOCKITEM(wxID_HELP, _("&Help"))
122 STOCKITEM(wxID_HOME, _("&Home"))
123 STOCKITEM(wxID_INDENT, _("Indent"))
124 STOCKITEM(wxID_INDEX, _("&Index"))
125 STOCKITEM(wxID_ITALIC, _("&Italic"))
126 STOCKITEM(wxID_JUSTIFY_CENTER, _("Centered"))
127 STOCKITEM(wxID_JUSTIFY_FILL, _("Justified"))
128 STOCKITEM(wxID_JUSTIFY_LEFT, _("Align Left"))
129 STOCKITEM(wxID_JUSTIFY_RIGHT, _("Align Right"))
130 STOCKITEM(wxID_NEW, _("&New"))
131 STOCKITEM(wxID_NO, _("&No"))
132 STOCKITEM(wxID_OK, _("&OK"))
133 STOCKITEM(wxID_OPEN, _("&Open"))
134 STOCKITEM(wxID_PASTE, _("&Paste"))
135 STOCKITEM(wxID_PREFERENCES, _("&Preferences"))
136 STOCKITEM(wxID_PRINT, _("&Print"))
137 STOCKITEM(wxID_PREVIEW, _("Print previe&w"))
138 STOCKITEM(wxID_PROPERTIES, _("&Properties"))
139 STOCKITEM(wxID_EXIT, _("&Quit"))
140 STOCKITEM(wxID_REDO, _("&Redo"))
141 STOCKITEM(wxID_REFRESH, _("Refresh"))
142 STOCKITEM(wxID_REMOVE, _("Remove"))
143 STOCKITEM(wxID_REVERT_TO_SAVED, _("Revert to Saved"))
144 STOCKITEM(wxID_SAVE, _("&Save"))
145 STOCKITEM(wxID_SAVEAS, _("Save &As..."))
146 STOCKITEM(wxID_STOP, _("&Stop"))
147 STOCKITEM(wxID_UNDELETE, _("Undelete"))
148 STOCKITEM(wxID_UNDERLINE, _("&Underline"))
149 STOCKITEM(wxID_UNDO, _("&Undo"))
150 STOCKITEM(wxID_UNINDENT, _("&Unindent"))
151 STOCKITEM(wxID_YES, _("&Yes"))
152 STOCKITEM(wxID_ZOOM_100, _("&Actual Size"))
153 STOCKITEM(wxID_ZOOM_FIT, _("Zoom to &Fit"))
154 STOCKITEM(wxID_ZOOM_IN, _("Zoom &In"))
155 STOCKITEM(wxID_ZOOM_OUT, _("Zoom &Out"))
156
401e3b6e
VS
157 default:
158 wxFAIL_MSG( _T("invalid stock item ID") );
159 break;
160 };
161
162 #undef STOCKITEM
d775fa82 163
634629fa
WS
164 if(!withCodes)
165 {
166 stockLabel = wxStripMenuCodes( stockLabel );
167 }
168 else if (!stockLabel.empty() && !accelerator.empty())
169 {
170 stockLabel += _T("\t");
171 stockLabel += accelerator;
172 }
173
174 return stockLabel;
401e3b6e
VS
175}
176
5f7bcb48
VS
177bool wxIsStockLabel(wxWindowID id, const wxString& label)
178{
179 if (label.empty())
180 return true;
181
182 wxString stock = wxGetStockLabel(id);
183
184 if (label == stock)
185 return true;
d775fa82 186
5f7bcb48
VS
187 stock.Replace(_T("&"), wxEmptyString);
188 if (label == stock)
189 return true;
d775fa82 190
5f7bcb48
VS
191 return false;
192}
193
401e3b6e
VS
194
195#ifdef __WXGTK20__
196
197#include <gtk/gtk.h>
198
5f7bcb48 199const char *wxGetStockGtkID(wxWindowID id)
401e3b6e 200{
5f7bcb48
VS
201 #define STOCKITEM(wx,gtk) \
202 case wx: \
203 return gtk;
d775fa82 204
5f7bcb48 205 #define STOCKITEM_MISSING(wx) \
c4c3e30f 206 case wx: \
4b5966d7 207 return NULL;
c20889ab
VS
208
209 #if GTK_CHECK_VERSION(2,4,0)
5f7bcb48 210 #define STOCKITEM_24(wx,gtk) STOCKITEM(wx,gtk)
c20889ab 211 #else
5f7bcb48 212 #define STOCKITEM_24(wx,gtk) STOCKITEM_MISSING(wx)
c20889ab 213 #endif
401e3b6e 214
5f7bcb48 215 switch (id)
401e3b6e 216 {
5f7bcb48
VS
217 STOCKITEM(wxID_ADD, GTK_STOCK_ADD)
218 STOCKITEM(wxID_APPLY, GTK_STOCK_APPLY)
219 STOCKITEM(wxID_BOLD, GTK_STOCK_BOLD)
220 STOCKITEM(wxID_CANCEL, GTK_STOCK_CANCEL)
221 STOCKITEM(wxID_CLEAR, GTK_STOCK_CLEAR)
222 STOCKITEM(wxID_CLOSE, GTK_STOCK_CLOSE)
223 STOCKITEM(wxID_COPY, GTK_STOCK_COPY)
224 STOCKITEM(wxID_CUT, GTK_STOCK_CUT)
225 STOCKITEM(wxID_DELETE, GTK_STOCK_DELETE)
226 STOCKITEM(wxID_FIND, GTK_STOCK_FIND)
227 STOCKITEM(wxID_REPLACE, GTK_STOCK_FIND_AND_REPLACE)
228 STOCKITEM(wxID_BACKWARD, GTK_STOCK_GO_BACK)
229 STOCKITEM(wxID_DOWN, GTK_STOCK_GO_DOWN)
230 STOCKITEM(wxID_FORWARD, GTK_STOCK_GO_FORWARD)
231 STOCKITEM(wxID_UP, GTK_STOCK_GO_UP)
232 STOCKITEM(wxID_HELP, GTK_STOCK_HELP)
233 STOCKITEM(wxID_HOME, GTK_STOCK_HOME)
234 STOCKITEM_24(wxID_INDENT, GTK_STOCK_INDENT)
235 STOCKITEM(wxID_INDEX, GTK_STOCK_INDEX)
236 STOCKITEM(wxID_ITALIC, GTK_STOCK_ITALIC)
237 STOCKITEM(wxID_JUSTIFY_CENTER, GTK_STOCK_JUSTIFY_CENTER)
238 STOCKITEM(wxID_JUSTIFY_FILL, GTK_STOCK_JUSTIFY_FILL)
239 STOCKITEM(wxID_JUSTIFY_LEFT, GTK_STOCK_JUSTIFY_LEFT)
240 STOCKITEM(wxID_JUSTIFY_RIGHT, GTK_STOCK_JUSTIFY_RIGHT)
241 STOCKITEM(wxID_NEW, GTK_STOCK_NEW)
242 STOCKITEM(wxID_NO, GTK_STOCK_NO)
243 STOCKITEM(wxID_OK, GTK_STOCK_OK)
244 STOCKITEM(wxID_OPEN, GTK_STOCK_OPEN)
245 STOCKITEM(wxID_PASTE, GTK_STOCK_PASTE)
246 STOCKITEM(wxID_PREFERENCES, GTK_STOCK_PREFERENCES)
247 STOCKITEM(wxID_PRINT, GTK_STOCK_PRINT)
248 STOCKITEM(wxID_PREVIEW, GTK_STOCK_PRINT_PREVIEW)
249 STOCKITEM(wxID_PROPERTIES, GTK_STOCK_PROPERTIES)
250 STOCKITEM(wxID_EXIT, GTK_STOCK_QUIT)
251 STOCKITEM(wxID_REDO, GTK_STOCK_REDO)
252 STOCKITEM(wxID_REFRESH, GTK_STOCK_REFRESH)
253 STOCKITEM(wxID_REMOVE, GTK_STOCK_REMOVE)
254 STOCKITEM(wxID_REVERT_TO_SAVED, GTK_STOCK_REVERT_TO_SAVED)
255 STOCKITEM(wxID_SAVE, GTK_STOCK_SAVE)
256 STOCKITEM(wxID_SAVEAS, GTK_STOCK_SAVE_AS)
257 STOCKITEM(wxID_STOP, GTK_STOCK_STOP)
258 STOCKITEM(wxID_UNDELETE, GTK_STOCK_UNDELETE)
259 STOCKITEM(wxID_UNDERLINE, GTK_STOCK_UNDERLINE)
260 STOCKITEM(wxID_UNDO, GTK_STOCK_UNDO)
261 STOCKITEM_24(wxID_UNINDENT, GTK_STOCK_UNINDENT)
262 STOCKITEM(wxID_YES, GTK_STOCK_YES)
263 STOCKITEM(wxID_ZOOM_100, GTK_STOCK_ZOOM_100)
264 STOCKITEM(wxID_ZOOM_FIT, GTK_STOCK_ZOOM_FIT)
265 STOCKITEM(wxID_ZOOM_IN, GTK_STOCK_ZOOM_IN)
266 STOCKITEM(wxID_ZOOM_OUT, GTK_STOCK_ZOOM_OUT)
267
401e3b6e
VS
268 default:
269 wxFAIL_MSG( _T("invalid stock item ID") );
270 break;
271 };
272
273 #undef STOCKITEM
d775fa82 274
401e3b6e
VS
275 return NULL;
276}
277
278#endif // __WXGTK20__