1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/icon.mm
3 // Purpose: wxIcon class
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/bitmap.h"
18 #import <AppKit/NSImage.h>
20 // ========================================================================
22 // ========================================================================
23 class wxIconRefData: public wxGDIRefData
28 wxIconRefData( const wxIconRefData& data );
29 virtual ~wxIconRefData();
38 WX_NSImage m_cocoaNSImage;
41 #define M_ICONDATA ((wxIconRefData *)m_refData)
43 wxIconRefData::wxIconRefData()
54 wxIconRefData::wxIconRefData( const wxIconRefData& data)
56 m_width = data.m_width;
57 m_height = data.m_height;
58 m_depth = data.m_depth;
60 m_numColors = data.m_numColors;
61 m_quality = data.m_quality;
62 m_cocoaNSImage = [data.m_cocoaNSImage copyWithZone:nil];
65 wxIconRefData::~wxIconRefData()
67 [m_cocoaNSImage release];
68 m_cocoaNSImage = NULL;
72 // ========================================================================
74 // ========================================================================
75 IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxGDIObject)
81 wxIcon::wxIcon(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height))
85 wxIcon::wxIcon(const wxString& icon_file, int flags,
86 int desiredWidth, int desiredHeight)
89 LoadFile(icon_file, (wxBitmapType)flags, desiredWidth, desiredHeight);
96 bool wxIcon::CreateFromXpm(const char **xpm)
99 CopyFromBitmap(bitmap);
103 bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type,
104 int desiredWidth, int desiredHeight)
108 m_refData = new wxIconRefData;
109 M_ICONDATA->m_width = 5;
110 M_ICONDATA->m_height = 5;
111 M_ICONDATA->m_cocoaNSImage = [[NSImage alloc] initWithSize:NSMakeSize(5,5)];
112 M_ICONDATA->m_ok = true;
113 M_ICONDATA->m_numColors = 0;
114 M_ICONDATA->m_quality = 0;
119 void wxIcon::CopyFromBitmap(const wxBitmap& bitmap)
122 m_refData = new wxIconRefData;
123 M_ICONDATA->m_width = bitmap.GetWidth();
124 M_ICONDATA->m_height = bitmap.GetHeight();
125 M_ICONDATA->m_cocoaNSImage = bitmap.GetNSImage(true);
126 M_ICONDATA->m_ok = bitmap.Ok();
127 M_ICONDATA->m_numColors = 0;
128 M_ICONDATA->m_quality = 0;
131 bool wxIcon::Ok() const
133 return m_refData && M_ICONDATA->m_ok;
136 int wxIcon::GetWidth() const
140 return M_ICONDATA->m_width;
143 int wxIcon::GetHeight() const
147 return M_ICONDATA->m_height;
150 WX_NSImage wxIcon::GetNSImage() const
154 return M_ICONDATA->m_cocoaNSImage;