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