]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/icon.mm
Calculate correct client size for windows that are using deferred sizing.
[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
065e208e 9// Licence: wxWidgets licence
b5df4fc7
DE
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13#ifndef WX_PRECOMP
14 #include "wx/icon.h"
15#endif //WX_PRECOMP
16#include "wx/bitmap.h"
17
be2e301f
DE
18#include "wx/cocoa/autorelease.h"
19
b5df4fc7
DE
20#import <AppKit/NSImage.h>
21
22// ========================================================================
23// wxIconRefData
24// ========================================================================
25class wxIconRefData: public wxGDIRefData
26{
27 friend class wxIcon;
28public:
29 wxIconRefData();
30 wxIconRefData( const wxIconRefData& data );
31 virtual ~wxIconRefData();
32
33protected:
34 int m_width;
35 int m_height;
36 int m_depth;
37 bool m_ok;
38 int m_numColors;
39 int m_quality;
40 WX_NSImage m_cocoaNSImage;
41};
42
43#define M_ICONDATA ((wxIconRefData *)m_refData)
44
45wxIconRefData::wxIconRefData()
46{
47 m_ok = FALSE;
48 m_width = 0;
49 m_height = 0;
50 m_depth = 0;
51 m_quality = 0;
52 m_numColors = 0;
53 m_cocoaNSImage = nil;
54}
55
56wxIconRefData::wxIconRefData( const wxIconRefData& data)
57{
58 m_width = data.m_width;
59 m_height = data.m_height;
60 m_depth = data.m_depth;
61 m_ok = data.m_ok;
62 m_numColors = data.m_numColors;
63 m_quality = data.m_quality;
64 m_cocoaNSImage = [data.m_cocoaNSImage copyWithZone:nil];
65}
66
67wxIconRefData::~wxIconRefData()
68{
894d6c9a 69 wxAutoNSAutoreleasePool pool;
b5df4fc7
DE
70 [m_cocoaNSImage release];
71 m_cocoaNSImage = NULL;
72}
73
74
75// ========================================================================
76// wxIcon
77// ========================================================================
78IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxGDIObject)
79
80wxIcon::wxIcon()
81{
82}
83
84wxIcon::wxIcon(const char WXUNUSED(bits)[], int WXUNUSED(width), int WXUNUSED(height))
85{
86}
87
88wxIcon::wxIcon(const wxString& icon_file, int flags,
89 int desiredWidth, int desiredHeight)
90
91{
92 LoadFile(icon_file, (wxBitmapType)flags, desiredWidth, desiredHeight);
93}
94
95wxIcon::~wxIcon()
96{
97}
98
99bool wxIcon::CreateFromXpm(const char **xpm)
100{
101 wxBitmap bitmap(xpm);
102 CopyFromBitmap(bitmap);
103 return Ok();
104}
105
106bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type,
107 int desiredWidth, int desiredHeight)
108{
109 UnRef();
110
111 m_refData = new wxIconRefData;
112 M_ICONDATA->m_width = 5;
113 M_ICONDATA->m_height = 5;
114 M_ICONDATA->m_cocoaNSImage = [[NSImage alloc] initWithSize:NSMakeSize(5,5)];
115 M_ICONDATA->m_ok = true;
116 M_ICONDATA->m_numColors = 0;
117 M_ICONDATA->m_quality = 0;
118
119 return FALSE;
120}
121
122void wxIcon::CopyFromBitmap(const wxBitmap& bitmap)
123{
124 UnRef();
125 m_refData = new wxIconRefData;
126 M_ICONDATA->m_width = bitmap.GetWidth();
127 M_ICONDATA->m_height = bitmap.GetHeight();
be2e301f
DE
128 wxAutoNSAutoreleasePool pool;
129 M_ICONDATA->m_cocoaNSImage = [bitmap.GetNSImage(true) retain];
b5df4fc7
DE
130 M_ICONDATA->m_ok = bitmap.Ok();
131 M_ICONDATA->m_numColors = 0;
132 M_ICONDATA->m_quality = 0;
133}
134
135bool wxIcon::Ok() const
136{
137 return m_refData && M_ICONDATA->m_ok;
138}
139
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}
160