]> git.saurik.com Git - wxWidgets.git/blob - src/common/artstd.cpp
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / src / common / artstd.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/artstd.cpp
3 // Purpose: stock wxArtProvider instance with default wxWin art
4 // Author: Vaclav Slavik
5 // Modified by:
6 // Created: 18/03/2002
7 // Copyright: (c) Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // ---------------------------------------------------------------------------
12 // headers
13 // ---------------------------------------------------------------------------
14
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
17
18 #if defined(__BORLANDC__)
19 #pragma hdrstop
20 #endif
21
22 #if wxUSE_ARTPROVIDER_STD
23
24 #ifndef WX_PRECOMP
25 #include "wx/image.h"
26 #endif
27
28 #include "wx/artprov.h"
29
30 // ----------------------------------------------------------------------------
31 // wxDefaultArtProvider
32 // ----------------------------------------------------------------------------
33
34 class wxDefaultArtProvider : public wxArtProvider
35 {
36 protected:
37 virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client,
38 const wxSize& size);
39 };
40
41 // ----------------------------------------------------------------------------
42 // wxArtProvider::InitStdProvider
43 // ----------------------------------------------------------------------------
44
45 /*static*/ void wxArtProvider::InitStdProvider()
46 {
47 wxArtProvider::PushBack(new wxDefaultArtProvider);
48 }
49
50 // ----------------------------------------------------------------------------
51 // helper macros
52 // ----------------------------------------------------------------------------
53
54 // Standard macro for getting a resource from XPM file:
55 #define ART(artId, xpmRc) \
56 if ( id == artId ) return wxBitmap(xpmRc##_xpm);
57
58 // ----------------------------------------------------------------------------
59 // XPMs with the art
60 // ----------------------------------------------------------------------------
61
62 #ifndef __WXUNIVERSAL__
63 #if defined(__WXGTK__)
64 #include "../../art/gtk/info.xpm"
65 #include "../../art/gtk/error.xpm"
66 #include "../../art/gtk/warning.xpm"
67 #include "../../art/gtk/question.xpm"
68 #elif defined(__WXMOTIF__)
69 #include "../../art/motif/info.xpm"
70 #include "../../art/motif/error.xpm"
71 #include "../../art/motif/warning.xpm"
72 #include "../../art/motif/question.xpm"
73 #endif
74 #endif // !__WXUNIVERSAL__
75
76 #if wxUSE_HTML
77 #include "../../art/htmsidep.xpm"
78 #include "../../art/htmoptns.xpm"
79 #include "../../art/htmbook.xpm"
80 #include "../../art/htmfoldr.xpm"
81 #include "../../art/htmpage.xpm"
82 #endif // wxUSE_HTML
83
84 #include "../../art/missimg.xpm"
85 #include "../../art/addbookm.xpm"
86 #include "../../art/delbookm.xpm"
87 #include "../../art/back.xpm"
88 #include "../../art/forward.xpm"
89 #include "../../art/up.xpm"
90 #include "../../art/down.xpm"
91 #include "../../art/toparent.xpm"
92 #include "../../art/fileopen.xpm"
93 #include "../../art/print.xpm"
94 #include "../../art/helpicon.xpm"
95 #include "../../art/tipicon.xpm"
96 #include "../../art/home.xpm"
97 #include "../../art/first.xpm"
98 #include "../../art/last.xpm"
99 #include "../../art/repview.xpm"
100 #include "../../art/listview.xpm"
101 #include "../../art/new_dir.xpm"
102 #include "../../art/harddisk.xpm"
103 #include "../../art/cdrom.xpm"
104 #include "../../art/floppy.xpm"
105 #include "../../art/removable.xpm"
106 #include "../../art/folder.xpm"
107 #include "../../art/folder_open.xpm"
108 #include "../../art/dir_up.xpm"
109 #include "../../art/exefile.xpm"
110 #include "../../art/deffile.xpm"
111 #include "../../art/tick.xpm"
112 #include "../../art/cross.xpm"
113
114 #include "../../art/filesave.xpm"
115 #include "../../art/filesaveas.xpm"
116 #include "../../art/copy.xpm"
117 #include "../../art/cut.xpm"
118 #include "../../art/paste.xpm"
119 #include "../../art/delete.xpm"
120 #include "../../art/new.xpm"
121 #include "../../art/undo.xpm"
122 #include "../../art/redo.xpm"
123 #include "../../art/plus.xpm"
124 #include "../../art/minus.xpm"
125 #include "../../art/close.xpm"
126 #include "../../art/quit.xpm"
127 #include "../../art/find.xpm"
128 #include "../../art/findrepl.xpm"
129
130 wxBitmap wxDefaultArtProvider_CreateBitmap(const wxArtID& id)
131 {
132 #if !defined(__WXUNIVERSAL__) && (defined(__WXGTK__) || defined(__WXMOTIF__))
133 // wxMessageBox icons:
134 ART(wxART_ERROR, error)
135 ART(wxART_INFORMATION, info)
136 ART(wxART_WARNING, warning)
137 ART(wxART_QUESTION, question)
138 #endif
139
140 // standard icons:
141 #if wxUSE_HTML
142 ART(wxART_HELP_SIDE_PANEL, htmsidep)
143 ART(wxART_HELP_SETTINGS, htmoptns)
144 ART(wxART_HELP_BOOK, htmbook)
145 ART(wxART_HELP_FOLDER, htmfoldr)
146 ART(wxART_HELP_PAGE, htmpage)
147 #endif // wxUSE_HTML
148 ART(wxART_MISSING_IMAGE, missimg)
149 ART(wxART_ADD_BOOKMARK, addbookm)
150 ART(wxART_DEL_BOOKMARK, delbookm)
151 ART(wxART_GO_BACK, back)
152 ART(wxART_GO_FORWARD, forward)
153 ART(wxART_GO_UP, up)
154 ART(wxART_GO_DOWN, down)
155 ART(wxART_GO_TO_PARENT, toparent)
156 ART(wxART_GO_HOME, home)
157 ART(wxART_GOTO_FIRST, first)
158 ART(wxART_GOTO_LAST, last)
159 ART(wxART_FILE_OPEN, fileopen)
160 ART(wxART_PRINT, print)
161 ART(wxART_HELP, helpicon)
162 ART(wxART_TIP, tipicon)
163 ART(wxART_REPORT_VIEW, repview)
164 ART(wxART_LIST_VIEW, listview)
165 ART(wxART_NEW_DIR, new_dir)
166 ART(wxART_HARDDISK, harddisk)
167 ART(wxART_FLOPPY, floppy)
168 ART(wxART_CDROM, cdrom)
169 ART(wxART_REMOVABLE, removable)
170 ART(wxART_FOLDER, folder)
171 ART(wxART_FOLDER_OPEN, folder_open)
172 ART(wxART_GO_DIR_UP, dir_up)
173 ART(wxART_EXECUTABLE_FILE, exefile)
174 ART(wxART_NORMAL_FILE, deffile)
175 ART(wxART_TICK_MARK, tick)
176 ART(wxART_CROSS_MARK, cross)
177
178 ART(wxART_FILE_SAVE, filesave)
179 ART(wxART_FILE_SAVE_AS, filesaveas)
180 ART(wxART_COPY, copy)
181 ART(wxART_CUT, cut)
182 ART(wxART_PASTE, paste)
183 ART(wxART_DELETE, delete)
184 ART(wxART_UNDO, undo)
185 ART(wxART_REDO, redo)
186 ART(wxART_PLUS, plus)
187 ART(wxART_MINUS, minus)
188 ART(wxART_CLOSE, close)
189 ART(wxART_QUIT, quit)
190 ART(wxART_FIND, find)
191 ART(wxART_FIND_AND_REPLACE, findrepl)
192 ART(wxART_NEW, new)
193
194
195 return wxNullBitmap;
196 }
197
198 // ----------------------------------------------------------------------------
199 // CreateBitmap routine
200 // ----------------------------------------------------------------------------
201
202 wxBitmap wxDefaultArtProvider::CreateBitmap(const wxArtID& id,
203 const wxArtClient& client,
204 const wxSize& reqSize)
205 {
206 wxBitmap bmp = wxDefaultArtProvider_CreateBitmap(id);
207
208 #if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB)
209 if (bmp.IsOk())
210 {
211 // fit into transparent image with desired size hint from the client
212 if (reqSize == wxDefaultSize)
213 {
214 // find out if there is a desired size for this client
215 wxSize bestSize = GetSizeHint(client);
216 if (bestSize != wxDefaultSize)
217 {
218 int bmp_w = bmp.GetWidth();
219 int bmp_h = bmp.GetHeight();
220
221 if (bmp_w == 16 && bmp_h == 15 && bestSize == wxSize(16, 16))
222 {
223 // Do nothing in this special but quite common case, because scaling
224 // with only a pixel difference will look horrible.
225 }
226 else if ((bmp_h < bestSize.x) && (bmp_w < bestSize.y))
227 {
228 // the caller wants default size, which is larger than
229 // the image we have; to avoid degrading it visually by
230 // scaling it up, paste it into transparent image instead:
231 wxPoint offset((bestSize.x - bmp_w)/2, (bestSize.y - bmp_h)/2);
232 wxImage img = bmp.ConvertToImage();
233 img.Resize(bestSize, offset);
234 bmp = wxBitmap(img);
235 }
236 else // scale (down or mixed, but not up)
237 {
238 wxImage img = bmp.ConvertToImage();
239 bmp = wxBitmap
240 (
241 img.Scale(bestSize.x, bestSize.y,
242 wxIMAGE_QUALITY_HIGH)
243 );
244 }
245 }
246 }
247 }
248 #else
249 wxUnusedVar(client);
250 wxUnusedVar(reqSize);
251 #endif // wxUSE_IMAGE
252
253 return bmp;
254 }
255
256 #endif // wxUSE_ARTPROVIDER_STD