]> git.saurik.com Git - wxWidgets.git/blame - src/common/artstd.cpp
When converting a wxIcon to a bitmap check if the icon has an alpha
[wxWidgets.git] / src / common / artstd.cpp
CommitLineData
2aca4a98
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: 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
65571936 9// Licence: wxWindows licence
2aca4a98
VS
10/////////////////////////////////////////////////////////////////////////////
11
12// ---------------------------------------------------------------------------
13// headers
14// ---------------------------------------------------------------------------
15
2aca4a98
VS
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
66941e14
VS
23#ifndef WX_PRECOMP
24 #if WXWIN_COMPATIBILITY_2_2
25 #include "wx/app.h"
26 #endif
27#endif
28
2aca4a98 29#include "wx/artprov.h"
e53a95bc 30#include "wx/image.h"
2aca4a98
VS
31
32// ----------------------------------------------------------------------------
33// wxDefaultArtProvider
34// ----------------------------------------------------------------------------
35
36class wxDefaultArtProvider : public wxArtProvider
37{
38protected:
57b0987b
VS
39 virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client,
40 const wxSize& size);
2aca4a98
VS
41};
42
66941e14
VS
43// ----------------------------------------------------------------------------
44// helper macros
45// ----------------------------------------------------------------------------
46
47// Standard macro for getting a resource from XPM file:
57b0987b
VS
48#define ART(artId, xpmRc) \
49 if ( id == artId ) return wxBitmap(xpmRc##_xpm);
66941e14 50
66941e14
VS
51// There are two ways of getting the standard icon: either via XPMs or via
52// wxIcon ctor. This depends on the platform:
53#if defined(__WXUNIVERSAL__)
54 #define CREATE_STD_ICON(iconId, xpmRc) return wxNullBitmap;
55#elif defined(__WXGTK__) || defined(__WXMOTIF__)
56 #define CREATE_STD_ICON(iconId, xpmRc) return wxBitmap(xpmRc##_xpm);
57#else
58 #define CREATE_STD_ICON(iconId, xpmRc) \
59 { \
60 wxIcon icon(_T(iconId)); \
61 wxBitmap bmp; \
62 bmp.CopyFromIcon(icon); \
63 return bmp; \
64 }
65#endif
66
67// Macro used in CreateBitmap to get wxICON_FOO icons:
68#define ART_MSGBOX(artId, iconId, xpmRc) \
69 if ( id == artId ) \
70 { \
66941e14
VS
71 CREATE_STD_ICON(#iconId, xpmRc) \
72 }
2aca4a98
VS
73
74// ----------------------------------------------------------------------------
2b5f62a0 75// wxArtProvider::InitStdProvider
2aca4a98
VS
76// ----------------------------------------------------------------------------
77
2b5f62a0 78/*static*/ void wxArtProvider::InitStdProvider()
2aca4a98 79{
2b5f62a0
VZ
80 wxArtProvider::PushProvider(new wxDefaultArtProvider);
81}
2aca4a98 82
ff44780b
VS
83#if !defined(__WXGTK20__) || defined(__WXUNIVERSAL__)
84/*static*/ void wxArtProvider::InitNativeProvider()
85{
86}
87#endif
88
2aca4a98
VS
89
90// ----------------------------------------------------------------------------
91// XPMs with the art
92// ----------------------------------------------------------------------------
93
94// XPM hack: make the arrays const
95#define static static const
96
66941e14
VS
97#if defined(__WXGTK__)
98 #include "../../art/gtk/info.xpm"
99 #include "../../art/gtk/error.xpm"
100 #include "../../art/gtk/warning.xpm"
101 #include "../../art/gtk/question.xpm"
102#elif defined(__WXMOTIF__)
103 #include "../../art/motif/info.xpm"
104 #include "../../art/motif/error.xpm"
105 #include "../../art/motif/warning.xpm"
106 #include "../../art/motif/question.xpm"
107#endif
108
2aca4a98 109#if wxUSE_HTML
57b0987b
VS
110 #include "../../art/htmsidep.xpm"
111 #include "../../art/htmoptns.xpm"
112 #include "../../art/htmbook.xpm"
113 #include "../../art/htmfoldr.xpm"
114 #include "../../art/htmpage.xpm"
2aca4a98
VS
115#endif // wxUSE_HTML
116
0de41e82 117#include "../../art/missimg.xpm"
57b0987b
VS
118#include "../../art/addbookm.xpm"
119#include "../../art/delbookm.xpm"
120#include "../../art/back.xpm"
121#include "../../art/forward.xpm"
122#include "../../art/up.xpm"
123#include "../../art/down.xpm"
124#include "../../art/toparent.xpm"
125#include "../../art/fileopen.xpm"
126#include "../../art/print.xpm"
127#include "../../art/helpicon.xpm"
128#include "../../art/tipicon.xpm"
60d2cc25
VS
129#include "../../art/home.xpm"
130#include "../../art/repview.xpm"
131#include "../../art/listview.xpm"
132#include "../../art/new_dir.xpm"
ddf6088b
RR
133#include "../../art/harddisk.xpm"
134#include "../../art/cdrom.xpm"
135#include "../../art/floppy.xpm"
136#include "../../art/removable.xpm"
60d2cc25 137#include "../../art/folder.xpm"
ddf6088b 138#include "../../art/folder_open.xpm"
60d2cc25
VS
139#include "../../art/dir_up.xpm"
140#include "../../art/exefile.xpm"
141#include "../../art/deffile.xpm"
00958db5
VS
142#include "../../art/tick.xpm"
143#include "../../art/cross.xpm"
2aca4a98 144
ec6803d9
RD
145#include "../../art/filesave.xpm"
146#include "../../art/filesaveas.xpm"
147#include "../../art/copy.xpm"
148#include "../../art/cut.xpm"
149#include "../../art/paste.xpm"
150#include "../../art/delete_.xpm"
151#include "../../art/undo.xpm"
152#include "../../art/redo.xpm"
153#include "../../art/quit.xpm"
154#include "../../art/find.xpm"
155#include "../../art/findrepl.xpm"
156
157
2aca4a98
VS
158#undef static
159
e53a95bc 160wxBitmap wxDefaultArtProvider_CreateBitmap(const wxArtID& id)
2aca4a98 161{
66941e14
VS
162 // wxMessageBox icons:
163 ART_MSGBOX(wxART_ERROR, wxICON_ERROR, error)
164 ART_MSGBOX(wxART_INFORMATION, wxICON_INFORMATION, info)
165 ART_MSGBOX(wxART_WARNING, wxICON_WARNING, warning)
166 ART_MSGBOX(wxART_QUESTION, wxICON_QUESTION, question)
167
168 // standard icons:
2aca4a98 169#if wxUSE_HTML
57b0987b
VS
170 ART(wxART_HELP_SIDE_PANEL, htmsidep)
171 ART(wxART_HELP_SETTINGS, htmoptns)
172 ART(wxART_HELP_BOOK, htmbook)
173 ART(wxART_HELP_FOLDER, htmfoldr)
174 ART(wxART_HELP_PAGE, htmpage)
2aca4a98 175#endif // wxUSE_HTML
ff44780b 176 ART(wxART_MISSING_IMAGE, missimg)
57b0987b
VS
177 ART(wxART_ADD_BOOKMARK, addbookm)
178 ART(wxART_DEL_BOOKMARK, delbookm)
179 ART(wxART_GO_BACK, back)
180 ART(wxART_GO_FORWARD, forward)
181 ART(wxART_GO_UP, up)
182 ART(wxART_GO_DOWN, down)
183 ART(wxART_GO_TO_PARENT, toparent)
60d2cc25 184 ART(wxART_GO_HOME, home)
57b0987b
VS
185 ART(wxART_FILE_OPEN, fileopen)
186 ART(wxART_PRINT, print)
187 ART(wxART_HELP, helpicon)
188 ART(wxART_TIP, tipicon)
60d2cc25
VS
189 ART(wxART_REPORT_VIEW, repview)
190 ART(wxART_LIST_VIEW, listview)
191 ART(wxART_NEW_DIR, new_dir)
ddf6088b
RR
192 ART(wxART_HARDDISK, harddisk)
193 ART(wxART_FLOPPY, floppy)
194 ART(wxART_CDROM, cdrom)
195 ART(wxART_REMOVABLE, removable)
60d2cc25 196 ART(wxART_FOLDER, folder)
ddf6088b 197 ART(wxART_FOLDER_OPEN, folder_open)
60d2cc25
VS
198 ART(wxART_GO_DIR_UP, dir_up)
199 ART(wxART_EXECUTABLE_FILE, exefile)
200 ART(wxART_NORMAL_FILE, deffile)
00958db5
VS
201 ART(wxART_TICK_MARK, tick)
202 ART(wxART_CROSS_MARK, cross)
2aca4a98 203
ec6803d9
RD
204 ART(wxART_FILE_SAVE, filesave)
205 ART(wxART_FILE_SAVE_AS, filesaveas)
206 ART(wxART_COPY, copy)
207 ART(wxART_CUT, cut)
208 ART(wxART_PASTE, paste)
209 ART(wxART_DELETE, delete_)
210 ART(wxART_UNDO, undo)
211 ART(wxART_REDO, redo)
212 ART(wxART_QUIT, quit)
213 ART(wxART_FIND, find)
214 ART(wxART_FIND_AND_REPLACE, findrepl)
215
2aca4a98
VS
216 return wxNullBitmap;
217}
e53a95bc
RR
218
219// ----------------------------------------------------------------------------
220// CreateBitmap routine
221// ----------------------------------------------------------------------------
222
223wxBitmap wxDefaultArtProvider::CreateBitmap(const wxArtID& id,
224 const wxArtClient& client,
225 const wxSize& reqSize)
226{
227 wxBitmap bmp = wxDefaultArtProvider_CreateBitmap(id);
228
a376ab30 229#if wxUSE_IMAGE
e53a95bc
RR
230 if (bmp.Ok())
231 {
232 // fit into transparent image with desired size hint from the client
233 if (reqSize == wxDefaultSize)
234 {
235 // find out if there is a desired size for this client
236 wxSize bestSize = GetSizeHint(client);
237 if (bestSize != wxDefaultSize)
238 {
239 int bmp_w = bmp.GetWidth();
240 int bmp_h = bmp.GetHeight();
241 // want default size but it's smaller, paste into transparent image
242 if ((bmp_h < bestSize.x) && (bmp_w < bestSize.y))
243 {
244 wxPoint offset((bestSize.x - bmp_w)/2, (bestSize.y - bmp_h)/2);
245 wxImage img = bmp.ConvertToImage();
246 img.Resize(bestSize, offset);
247 bmp = wxBitmap(img);
a376ab30 248 }
e53a95bc 249 }
a376ab30 250 }
e53a95bc 251 }
a376ab30
WS
252#endif // wxUSE_IMAGE
253
e53a95bc
RR
254 return bmp;
255}