]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/icon.cpp
C/POSIX locales (or absence of locale information) corresponds to wxLANGUAGE_ENGLISH_...
[wxWidgets.git] / src / mac / carbon / icon.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
155ecd4c 2// Name: src/mac/carbon/icon.cpp
e9576ca5 3// Purpose: wxIcon class
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
155ecd4c 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878
SC
12#include "wx/wxprec.h"
13
e9576ca5 14#include "wx/icon.h"
155ecd4c
WS
15
16#ifndef WX_PRECOMP
17 #include "wx/image.h"
18#endif
19
76a5e5d2
SC
20#include "wx/mac/private.h"
21
5a7d70fe 22IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap)
ea68b706 23
5a7d70fe 24#define M_ICONDATA ((wxIconRefData *)m_refData)
76a5e5d2 25
e9576ca5 26
e9576ca5
SC
27wxIcon::wxIcon()
28{
29}
30
5a7d70fe 31wxIcon::wxIcon( const char bits[], int width, int height )
e9576ca5 32{
5a7d70fe 33 wxBitmap bmp( bits, width, height ) ;
20b69855 34 CopyFromBitmap( bmp ) ;
e9576ca5
SC
35}
36
5a7d70fe 37wxIcon::wxIcon( const char **bits )
2f1ae414 38{
5a7d70fe 39 wxBitmap bmp( bits ) ;
20b69855 40 CopyFromBitmap( bmp ) ;
2f1ae414
SC
41}
42
5a7d70fe 43wxIcon::wxIcon( char **bits )
2f1ae414 44{
5a7d70fe 45 wxBitmap bmp( bits ) ;
20b69855 46 CopyFromBitmap( bmp ) ;
2f1ae414
SC
47}
48
5a7d70fe
DS
49wxIcon::wxIcon(
50 const wxString& icon_file, int flags,
51 int desiredWidth, int desiredHeight )
e9576ca5 52{
5a7d70fe 53 LoadFile( icon_file, (wxBitmapType) flags, desiredWidth, desiredHeight );
e9576ca5
SC
54}
55
56wxIcon::~wxIcon()
57{
58}
59
5a7d70fe 60WXHICON wxIcon::GetHICON() const
20b69855
SC
61{
62 wxASSERT( Ok() ) ;
5a7d70fe 63
20b69855
SC
64 return (WXHICON) ((wxIconRefData*)m_refData)->GetHICON() ;
65}
66
67int wxIcon::GetWidth() const
68{
ea68b706
SC
69 wxCHECK_MSG( Ok(), -1, wxT("invalid icon") );
70
71 return M_ICONDATA->GetWidth();
20b69855
SC
72}
73
74int wxIcon::GetHeight() const
75{
ea68b706
SC
76 wxCHECK_MSG( Ok(), -1, wxT("invalid icon") );
77
78 return M_ICONDATA->GetHeight();
20b69855
SC
79}
80
5a7d70fe
DS
81int wxIcon::GetDepth() const
82{
83 return 32;
c605b871
KO
84}
85
5a7d70fe
DS
86void wxIcon::SetDepth( int depth )
87{
c605b871
KO
88}
89
5a7d70fe
DS
90void wxIcon::SetWidth( int width )
91{
c605b871
KO
92}
93
5a7d70fe
DS
94void wxIcon::SetHeight( int height )
95{
c605b871
KO
96}
97
b7cacb43 98bool wxIcon::IsOk() const
20b69855
SC
99{
100 return m_refData != NULL ;
101}
102
5a7d70fe
DS
103bool wxIcon::LoadFile(
104 const wxString& filename, wxBitmapType type,
105 int desiredWidth, int desiredHeight )
e9576ca5 106{
e40298d5 107 UnRef();
5a7d70fe 108
20b69855 109 if ( type == wxBITMAP_TYPE_ICON_RESOURCE )
1996c23f 110 {
20b69855 111 OSType theId = 0 ;
5a7d70fe 112
20b69855
SC
113 if ( filename == wxT("wxICON_INFORMATION") )
114 {
115 theId = kAlertNoteIcon ;
116 }
117 else if ( filename == wxT("wxICON_QUESTION") )
118 {
119 theId = kAlertCautionIcon ;
120 }
121 else if ( filename == wxT("wxICON_WARNING") )
122 {
123 theId = kAlertCautionIcon ;
124 }
125 else if ( filename == wxT("wxICON_ERROR") )
126 {
127 theId = kAlertStopIcon ;
128 }
129 else
5a7d70fe
DS
130 {
131#if 0
20b69855
SC
132 Str255 theName ;
133 OSType theType ;
134 wxMacStringToPascal( name , theName ) ;
5a7d70fe 135
20b69855
SC
136 Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
137 if ( resHandle != 0L )
138 {
139 GetResInfo( resHandle , &theId , &theType , theName ) ;
140 ReleaseResource( resHandle ) ;
141 }
5a7d70fe 142#endif
20b69855 143 }
5a7d70fe 144
20b69855
SC
145 if ( theId != 0 )
146 {
147 IconRef iconRef = NULL ;
5a7d70fe 148 verify_noerr( GetIconRef( kOnSystemDisk, kSystemIconsCreator, theId, &iconRef ) ) ;
20b69855
SC
149 if ( iconRef )
150 {
151 m_refData = new wxIconRefData( (WXHICON) iconRef ) ;
5a7d70fe
DS
152
153 return true ;
20b69855
SC
154 }
155 }
5a7d70fe
DS
156
157 return false ;
1996c23f 158 }
e40298d5 159 else
1996c23f 160 {
5a7d70fe 161 wxBitmapHandler *handler = wxBitmap::FindHandler( type );
20b69855
SC
162
163 if ( handler )
1996c23f 164 {
20b69855 165 wxBitmap bmp ;
5a7d70fe 166 if ( handler->LoadFile( &bmp , filename, type, desiredWidth, desiredHeight ))
20b69855
SC
167 {
168 CopyFromBitmap( bmp ) ;
5a7d70fe 169
20b69855
SC
170 return true ;
171 }
5a7d70fe 172
20b69855
SC
173 return false ;
174 }
175 else
176 {
da76c2ce 177#if wxUSE_IMAGE
5a7d70fe
DS
178 wxImage loadimage( filename, type );
179 if (loadimage.Ok())
20b69855
SC
180 {
181 if ( desiredWidth == -1 )
182 desiredWidth = loadimage.GetWidth() ;
183 if ( desiredHeight == -1 )
184 desiredHeight = loadimage.GetHeight() ;
185 if ( desiredWidth != loadimage.GetWidth() || desiredHeight != loadimage.GetHeight() )
186 loadimage.Rescale( desiredWidth , desiredHeight ) ;
155ecd4c 187
20b69855
SC
188 wxBitmap bmp( loadimage );
189 CopyFromBitmap( bmp ) ;
5a7d70fe 190
20b69855
SC
191 return true;
192 }
da76c2ce 193#endif
1996c23f
SC
194 }
195 }
20b69855 196 return true ;
e9576ca5
SC
197}
198
5a7d70fe 199void wxIcon::CopyFromBitmap( const wxBitmap& bmp )
d062e17f 200{
20b69855 201 UnRef() ;
5a7d70fe 202
796a6ef0
SC
203 // as the bitmap owns that ref, we have to acquire it as well
204 IconRef iconRef = bmp.GetBitmapData()->GetIconRef() ;
205 AcquireIconRef( iconRef ) ;
5a7d70fe 206
796a6ef0 207 m_refData = new wxIconRefData( (WXHICON) iconRef ) ;
ea68b706
SC
208 M_ICONDATA->SetWidth( bmp.GetWidth() ) ;
209 M_ICONDATA->SetHeight( bmp.GetHeight() ) ;
20b69855
SC
210}
211
212wxIconRefData::wxIconRefData( WXHICON icon )
213{
214 m_iconRef = MAC_WXHICON( icon ) ;
5a7d70fe
DS
215
216 // Standard sizes
ea68b706
SC
217 SetWidth( 32 ) ;
218 SetHeight( 32 ) ;
20b69855
SC
219}
220
5a7d70fe 221void wxIconRefData::Init()
20b69855
SC
222{
223 m_iconRef = NULL ;
224}
225
226void wxIconRefData::Free()
227{
228 if ( m_iconRef )
229 {
230 ReleaseIconRef( m_iconRef ) ;
231 m_iconRef = NULL ;
232 }
d062e17f
GD
233}
234
519cb848
SC
235IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler)
236
5a7d70fe
DS
237bool wxICONResourceHandler::LoadFile(
238 wxBitmap *bitmap, const wxString& name, long flags,
239 int desiredWidth, int desiredHeight )
519cb848 240{
20b69855
SC
241 wxIcon icon ;
242 icon.LoadFile( name , wxBITMAP_TYPE_ICON_RESOURCE , desiredWidth , desiredHeight ) ;
243 bitmap->CopyFromIcon( icon ) ;
5a7d70fe 244
20b69855 245 return bitmap->Ok() ;
03e11df5 246}
5a7d70fe 247