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