]> git.saurik.com Git - wxWidgets.git/blob - src/osx/artmac.cpp
rewrite using type safe wxHashMap instead of wxObject-based wxHashTable
[wxWidgets.git] / src / osx / artmac.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/artmac.cpp
3 // Purpose: wxArtProvider instance with native Mac stock icons
4 // Author: Alan Shouls
5 // Created: 2006-10-30
6 // RCS-ID: $Id$
7 // Copyright: (c) wxWindows team
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 #ifndef WX_PRECOMP
23 #include "wx/image.h"
24 #endif
25
26 #if !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
27
28 #include "wx/artprov.h"
29 #include "wx/image.h"
30
31 // ----------------------------------------------------------------------------
32 // wxMacArtProvider
33 // ----------------------------------------------------------------------------
34
35 class wxMacArtProvider : public wxArtProvider
36 {
37 protected:
38 virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client,
39 const wxSize& size);
40 virtual wxIconBundle CreateIconBundle(const wxArtID& id,
41 const wxArtClient& client);
42 };
43
44 /* static */ void wxArtProvider::InitNativeProvider()
45 {
46 wxArtProvider::Push(new wxMacArtProvider);
47 }
48
49 // ----------------------------------------------------------------------------
50 // helper macros
51 // ----------------------------------------------------------------------------
52
53 #define CREATE_STD_ICON(iconId, xpmRc) \
54 { \
55 wxIconBundle icon(_T(iconId), wxBITMAP_TYPE_ICON_RESOURCE); \
56 return icon; \
57 }
58
59 // Macro used in CreateBitmap to get wxICON_FOO icons:
60 #define ART_MSGBOX(artId, iconId, xpmRc) \
61 if ( id == artId ) \
62 { \
63 CREATE_STD_ICON(#iconId, xpmRc) \
64 }
65
66 static wxIconBundle wxMacArtProvider_CreateIconBundle(const wxArtID& id)
67 {
68 ART_MSGBOX(wxART_ERROR, wxICON_ERROR, error)
69 ART_MSGBOX(wxART_INFORMATION, wxICON_INFORMATION, info)
70 ART_MSGBOX(wxART_WARNING, wxICON_WARNING, warning)
71 ART_MSGBOX(wxART_QUESTION, wxICON_QUESTION, question)
72
73 ART_MSGBOX(wxART_FOLDER, wxICON_FOLDER, folder)
74 ART_MSGBOX(wxART_FOLDER_OPEN, wxICON_FOLDER_OPEN, folder_open)
75 ART_MSGBOX(wxART_NORMAL_FILE, wxICON_NORMAL_FILE, deffile)
76
77 return wxNullIconBundle;
78 }
79
80 // ----------------------------------------------------------------------------
81 // CreateIconBundle
82 // ----------------------------------------------------------------------------
83
84 wxIconBundle wxMacArtProvider::CreateIconBundle(const wxArtID& id, const wxArtClient& client)
85 {
86 // On the Mac folders in lists are always drawn closed, so if an open
87 // folder icon is asked for we will ask for a closed one in its place
88 if ( client == wxART_LIST && id == wxART_FOLDER_OPEN )
89 return wxMacArtProvider_CreateIconBundle(wxART_FOLDER);
90
91 return wxMacArtProvider_CreateIconBundle(id);
92 }
93
94 // ----------------------------------------------------------------------------
95 // CreateBitmap
96 // ----------------------------------------------------------------------------
97
98 wxBitmap wxMacArtProvider::CreateBitmap(const wxArtID& id,
99 const wxArtClient& client,
100 const wxSize& reqSize)
101 {
102 wxIconBundle ic(CreateIconBundle(id, client));
103 if (ic.IsOk())
104 {
105 wxIcon theIcon(ic.GetIcon(reqSize));
106 return wxBitmap(theIcon);
107 }
108
109 return wxNullBitmap;
110 }
111
112 #endif // !defined(__WXUNIVERSAL__)
113
114