]> git.saurik.com Git - wxWidgets.git/blob - src/msw/artmsw.cpp
Add some version checks to help compiling on OSX.
[wxWidgets.git] / src / msw / artmsw.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/artmsw.cpp
3 // Purpose: stock wxArtProvider instance with native MSW stock icons
4 // Author: Vaclav Slavik
5 // Modified by:
6 // Created: 2008-10-15
7 // RCS-ID: $Id$
8 // Copyright: (c) Vaclav Slavik, 2008
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 #include "wx/artprov.h"
24 #include "wx/image.h"
25 #include "wx/msw/wrapwin.h"
26
27
28 // ----------------------------------------------------------------------------
29 // wxWindowsArtProvider
30 // ----------------------------------------------------------------------------
31
32 class wxWindowsArtProvider : public wxArtProvider
33 {
34 protected:
35 virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client,
36 const wxSize& size);
37 };
38
39 static wxBitmap CreateFromStdIcon(const char *iconName,
40 const wxArtClient& client)
41 {
42 wxIcon icon(iconName);
43 wxBitmap bmp;
44 bmp.CopyFromIcon(icon);
45
46 #if wxUSE_IMAGE
47 // The standard native message box icons are in message box size (32x32).
48 // If they are requested in any size other than the default or message
49 // box size, they must be rescaled first.
50 if ( client != wxART_MESSAGE_BOX && client != wxART_OTHER )
51 {
52 const wxSize size = wxArtProvider::GetNativeSizeHint(client);
53 if ( size != wxDefaultSize )
54 {
55 wxImage img = bmp.ConvertToImage();
56 img.Rescale(size.x, size.y);
57 bmp = wxBitmap(img);
58 }
59 }
60 #endif // wxUSE_IMAGE
61
62 return bmp;
63 }
64
65 wxBitmap wxWindowsArtProvider::CreateBitmap(const wxArtID& id,
66 const wxArtClient& client,
67 const wxSize& WXUNUSED(size))
68 {
69 // handle message box icons specially (wxIcon ctor treat these names
70 // as special cases via wxICOResourceHandler::LoadIcon):
71 const char *name = NULL;
72 if ( id == wxART_ERROR )
73 name = "wxICON_ERROR";
74 else if ( id == wxART_INFORMATION )
75 name = "wxICON_INFORMATION";
76 else if ( id == wxART_WARNING )
77 name = "wxICON_WARNING";
78 else if ( id == wxART_QUESTION )
79 name = "wxICON_QUESTION";
80
81 if ( name )
82 return CreateFromStdIcon(name, client);
83
84 // for anything else, fall back to generic provider:
85 return wxNullBitmap;
86 }
87
88 // ----------------------------------------------------------------------------
89 // wxArtProvider::InitNativeProvider()
90 // ----------------------------------------------------------------------------
91
92 /*static*/ void wxArtProvider::InitNativeProvider()
93 {
94 Push(new wxWindowsArtProvider);
95 }
96
97 // ----------------------------------------------------------------------------
98 // wxArtProvider::GetNativeSizeHint()
99 // ----------------------------------------------------------------------------
100
101 /*static*/
102 wxSize wxArtProvider::GetNativeSizeHint(const wxArtClient& client)
103 {
104 if ( client == wxART_TOOLBAR )
105 {
106 return wxSize(24, 24);
107 }
108 else if ( client == wxART_MENU )
109 {
110 return wxSize(16, 16);
111 }
112 else if ( client == wxART_FRAME_ICON )
113 {
114 return wxSize(::GetSystemMetrics(SM_CXSMICON),
115 ::GetSystemMetrics(SM_CYSMICON));
116 }
117 else if ( client == wxART_CMN_DIALOG ||
118 client == wxART_MESSAGE_BOX )
119 {
120 return wxSize(::GetSystemMetrics(SM_CXICON),
121 ::GetSystemMetrics(SM_CYICON));
122 }
123 else if (client == wxART_BUTTON)
124 {
125 return wxSize(16, 16);
126 }
127
128 return wxDefaultSize;
129 }