]>
Commit | Line | Data |
---|---|---|
2aca4a98 | 1 | ///////////////////////////////////////////////////////////////////////////// |
155ecd4c | 2 | // Name: src/common/artstd.cpp |
2aca4a98 VS |
3 | // Purpose: stock wxArtProvider instance with default wxWin art |
4 | // Author: Vaclav Slavik | |
5 | // Modified by: | |
6 | // Created: 18/03/2002 | |
2aca4a98 | 7 | // Copyright: (c) Vaclav Slavik |
65571936 | 8 | // Licence: wxWindows licence |
2aca4a98 VS |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | // --------------------------------------------------------------------------- | |
12 | // headers | |
13 | // --------------------------------------------------------------------------- | |
14 | ||
2aca4a98 VS |
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 | ||
2e9b5717 VZ |
22 | #if wxUSE_ARTPROVIDER_STD |
23 | ||
155ecd4c WS |
24 | #ifndef WX_PRECOMP |
25 | #include "wx/image.h" | |
26 | #endif | |
27 | ||
2aca4a98 | 28 | #include "wx/artprov.h" |
2aca4a98 VS |
29 | |
30 | // ---------------------------------------------------------------------------- | |
31 | // wxDefaultArtProvider | |
32 | // ---------------------------------------------------------------------------- | |
33 | ||
34 | class wxDefaultArtProvider : public wxArtProvider | |
35 | { | |
36 | protected: | |
57b0987b VS |
37 | virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client, |
38 | const wxSize& size); | |
2aca4a98 VS |
39 | }; |
40 | ||
2aca4a98 | 41 | // ---------------------------------------------------------------------------- |
2b5f62a0 | 42 | // wxArtProvider::InitStdProvider |
2aca4a98 VS |
43 | // ---------------------------------------------------------------------------- |
44 | ||
2b5f62a0 | 45 | /*static*/ void wxArtProvider::InitStdProvider() |
2aca4a98 | 46 | { |
0d68cd13 | 47 | wxArtProvider::PushBack(new wxDefaultArtProvider); |
2b5f62a0 | 48 | } |
2aca4a98 | 49 | |
a158acac VS |
50 | // ---------------------------------------------------------------------------- |
51 | // helper macros | |
52 | // ---------------------------------------------------------------------------- | |
ff44780b | 53 | |
a158acac VS |
54 | // Standard macro for getting a resource from XPM file: |
55 | #define ART(artId, xpmRc) \ | |
56 | if ( id == artId ) return wxBitmap(xpmRc##_xpm); | |
2aca4a98 VS |
57 | |
58 | // ---------------------------------------------------------------------------- | |
59 | // XPMs with the art | |
60 | // ---------------------------------------------------------------------------- | |
61 | ||
a158acac VS |
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__ | |
66941e14 | 75 | |
2aca4a98 | 76 | #if wxUSE_HTML |
57b0987b VS |
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" | |
2aca4a98 VS |
82 | #endif // wxUSE_HTML |
83 | ||
0de41e82 | 84 | #include "../../art/missimg.xpm" |
57b0987b VS |
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" | |
60d2cc25 | 96 | #include "../../art/home.xpm" |
a7cfad3a VZ |
97 | #include "../../art/first.xpm" |
98 | #include "../../art/last.xpm" | |
60d2cc25 VS |
99 | #include "../../art/repview.xpm" |
100 | #include "../../art/listview.xpm" | |
101 | #include "../../art/new_dir.xpm" | |
ddf6088b RR |
102 | #include "../../art/harddisk.xpm" |
103 | #include "../../art/cdrom.xpm" | |
104 | #include "../../art/floppy.xpm" | |
105 | #include "../../art/removable.xpm" | |
60d2cc25 | 106 | #include "../../art/folder.xpm" |
ddf6088b | 107 | #include "../../art/folder_open.xpm" |
60d2cc25 VS |
108 | #include "../../art/dir_up.xpm" |
109 | #include "../../art/exefile.xpm" | |
110 | #include "../../art/deffile.xpm" | |
00958db5 VS |
111 | #include "../../art/tick.xpm" |
112 | #include "../../art/cross.xpm" | |
2aca4a98 | 113 | |
ec6803d9 RD |
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" | |
d00016f5 | 119 | #include "../../art/delete.xpm" |
406011a8 | 120 | #include "../../art/new.xpm" |
ec6803d9 RD |
121 | #include "../../art/undo.xpm" |
122 | #include "../../art/redo.xpm" | |
a7cfad3a VZ |
123 | #include "../../art/plus.xpm" |
124 | #include "../../art/minus.xpm" | |
b9727751 | 125 | #include "../../art/close.xpm" |
ec6803d9 RD |
126 | #include "../../art/quit.xpm" |
127 | #include "../../art/find.xpm" | |
128 | #include "../../art/findrepl.xpm" | |
129 | ||
e53a95bc | 130 | wxBitmap wxDefaultArtProvider_CreateBitmap(const wxArtID& id) |
2aca4a98 | 131 | { |
a158acac | 132 | #if !defined(__WXUNIVERSAL__) && (defined(__WXGTK__) || defined(__WXMOTIF__)) |
66941e14 | 133 | // wxMessageBox icons: |
a158acac VS |
134 | ART(wxART_ERROR, error) |
135 | ART(wxART_INFORMATION, info) | |
136 | ART(wxART_WARNING, warning) | |
137 | ART(wxART_QUESTION, question) | |
138 | #endif | |
66941e14 VS |
139 | |
140 | // standard icons: | |
2aca4a98 | 141 | #if wxUSE_HTML |
57b0987b VS |
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) | |
2aca4a98 | 147 | #endif // wxUSE_HTML |
ff44780b | 148 | ART(wxART_MISSING_IMAGE, missimg) |
57b0987b VS |
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) | |
60d2cc25 | 156 | ART(wxART_GO_HOME, home) |
a7cfad3a VZ |
157 | ART(wxART_GOTO_FIRST, first) |
158 | ART(wxART_GOTO_LAST, last) | |
57b0987b VS |
159 | ART(wxART_FILE_OPEN, fileopen) |
160 | ART(wxART_PRINT, print) | |
161 | ART(wxART_HELP, helpicon) | |
162 | ART(wxART_TIP, tipicon) | |
60d2cc25 VS |
163 | ART(wxART_REPORT_VIEW, repview) |
164 | ART(wxART_LIST_VIEW, listview) | |
165 | ART(wxART_NEW_DIR, new_dir) | |
ddf6088b RR |
166 | ART(wxART_HARDDISK, harddisk) |
167 | ART(wxART_FLOPPY, floppy) | |
168 | ART(wxART_CDROM, cdrom) | |
169 | ART(wxART_REMOVABLE, removable) | |
60d2cc25 | 170 | ART(wxART_FOLDER, folder) |
ddf6088b | 171 | ART(wxART_FOLDER_OPEN, folder_open) |
60d2cc25 VS |
172 | ART(wxART_GO_DIR_UP, dir_up) |
173 | ART(wxART_EXECUTABLE_FILE, exefile) | |
174 | ART(wxART_NORMAL_FILE, deffile) | |
00958db5 VS |
175 | ART(wxART_TICK_MARK, tick) |
176 | ART(wxART_CROSS_MARK, cross) | |
2aca4a98 | 177 | |
532d575b WS |
178 | ART(wxART_FILE_SAVE, filesave) |
179 | ART(wxART_FILE_SAVE_AS, filesaveas) | |
ec6803d9 RD |
180 | ART(wxART_COPY, copy) |
181 | ART(wxART_CUT, cut) | |
182 | ART(wxART_PASTE, paste) | |
d00016f5 | 183 | ART(wxART_DELETE, delete) |
ec6803d9 RD |
184 | ART(wxART_UNDO, undo) |
185 | ART(wxART_REDO, redo) | |
a7cfad3a VZ |
186 | ART(wxART_PLUS, plus) |
187 | ART(wxART_MINUS, minus) | |
b9727751 | 188 | ART(wxART_CLOSE, close) |
ec6803d9 RD |
189 | ART(wxART_QUIT, quit) |
190 | ART(wxART_FIND, find) | |
191 | ART(wxART_FIND_AND_REPLACE, findrepl) | |
406011a8 | 192 | ART(wxART_NEW, new) |
532d575b WS |
193 | |
194 | ||
2aca4a98 VS |
195 | return wxNullBitmap; |
196 | } | |
e53a95bc RR |
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 | ||
64c288fa | 208 | #if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB) |
a1b806b9 | 209 | if (bmp.IsOk()) |
e53a95bc RR |
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(); | |
e6e780ac | 220 | |
67d3242a JS |
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)) | |
e53a95bc | 227 | { |
03647350 | 228 | // the caller wants default size, which is larger than |
e6e780ac VS |
229 | // the image we have; to avoid degrading it visually by |
230 | // scaling it up, paste it into transparent image instead: | |
e53a95bc RR |
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); | |
a376ab30 | 235 | } |
e6e780ac VS |
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 | } | |
e53a95bc | 245 | } |
a376ab30 | 246 | } |
e53a95bc | 247 | } |
532d575b WS |
248 | #else |
249 | wxUnusedVar(client); | |
250 | wxUnusedVar(reqSize); | |
a376ab30 WS |
251 | #endif // wxUSE_IMAGE |
252 | ||
e53a95bc RR |
253 | return bmp; |
254 | } | |
2e9b5717 VZ |
255 | |
256 | #endif // wxUSE_ARTPROVIDER_STD |