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