]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/icon.mm
Move SendTextUpdatedEvent() down to wxTextEntryBase from wxTextCtrlBase.
[wxWidgets.git] / src / cocoa / icon.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/icon.mm
3 // Purpose: wxIcon class
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2003/08/11
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWidgets licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/icon.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/bitmap.h"
18 #endif //WX_PRECOMP
19
20 #include "wx/cocoa/autorelease.h"
21
22 #import <AppKit/NSImage.h>
23
24 // ========================================================================
25 // wxIconRefData
26 // ========================================================================
27 class wxIconRefData: public wxGDIRefData
28 {
29 friend class wxIcon;
30 public:
31 wxIconRefData();
32 wxIconRefData( const wxIconRefData& data );
33 virtual ~wxIconRefData();
34
35 virtual bool IsOk() const { return m_ok; }
36
37 protected:
38 int m_width;
39 int m_height;
40 int m_depth;
41 bool m_ok;
42 int m_numColors;
43 int m_quality;
44 WX_NSImage m_cocoaNSImage;
45 };
46
47 #define M_ICONDATA ((wxIconRefData *)m_refData)
48
49 wxIconRefData::wxIconRefData()
50 {
51 m_ok = false;
52 m_width = 0;
53 m_height = 0;
54 m_depth = 0;
55 m_quality = 0;
56 m_numColors = 0;
57 m_cocoaNSImage = nil;
58 }
59
60 wxIconRefData::wxIconRefData( const wxIconRefData& data)
61 {
62 m_width = data.m_width;
63 m_height = data.m_height;
64 m_depth = data.m_depth;
65 m_ok = data.m_ok;
66 m_numColors = data.m_numColors;
67 m_quality = data.m_quality;
68 m_cocoaNSImage = [data.m_cocoaNSImage copyWithZone:nil];
69 }
70
71 wxIconRefData::~wxIconRefData()
72 {
73 wxAutoNSAutoreleasePool pool;
74 [m_cocoaNSImage release];
75 m_cocoaNSImage = NULL;
76 }
77
78
79 // ========================================================================
80 // wxIcon
81 // ========================================================================
82 IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxGDIObject)
83
84 wxIcon::wxIcon()
85 {
86 }
87
88 wxIcon::wxIcon(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height))
89 {
90 }
91
92 wxIcon::wxIcon(const wxString& icon_file, int flags,
93 int desiredWidth, int desiredHeight)
94
95 {
96 LoadFile(icon_file, (wxBitmapType)flags, desiredWidth, desiredHeight);
97 }
98
99 wxIcon::~wxIcon()
100 {
101 }
102
103 wxGDIRefData *wxIcon::CreateGDIRefData() const
104 {
105 return new wxIconRefData;
106 }
107
108 wxGDIRefData *wxIcon::CloneGDIRefData(const wxGDIRefData *data) const
109 {
110 return new wxIconRefData(*static_cast<const wxIconRefData *>(data));
111 }
112
113 bool wxIcon::CreateFromXpm(const char* const* xpm)
114 {
115 wxBitmap bitmap(xpm);
116 CopyFromBitmap(bitmap);
117 return Ok();
118 }
119
120 bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type,
121 int desiredWidth, int desiredHeight)
122 {
123 wxBitmap bitmap(filename, type);
124 CopyFromBitmap(bitmap);
125 return bitmap.Ok();
126 }
127
128 void wxIcon::CopyFromBitmap(const wxBitmap& bitmap)
129 {
130 UnRef();
131 m_refData = new wxIconRefData;
132 M_ICONDATA->m_width = bitmap.GetWidth();
133 M_ICONDATA->m_height = bitmap.GetHeight();
134 wxAutoNSAutoreleasePool pool;
135 M_ICONDATA->m_cocoaNSImage = [bitmap.GetNSImage(true) retain];
136 M_ICONDATA->m_ok = bitmap.Ok();
137 M_ICONDATA->m_numColors = 0;
138 M_ICONDATA->m_quality = 0;
139 }
140
141 int wxIcon::GetWidth() const
142 {
143 if(!m_refData)
144 return 0;
145 return M_ICONDATA->m_width;
146 }
147
148 int wxIcon::GetHeight() const
149 {
150 if(!m_refData)
151 return 0;
152 return M_ICONDATA->m_height;
153 }
154
155 WX_NSImage wxIcon::GetNSImage() const
156 {
157 if(!M_ICONDATA)
158 return nil;
159 return M_ICONDATA->m_cocoaNSImage;
160 }