]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: icon.cpp | |
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 |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
e9576ca5 SC |
13 | #pragma implementation "icon.h" |
14 | #endif | |
15 | ||
3d1a4878 SC |
16 | #include "wx/wxprec.h" |
17 | ||
e9576ca5 SC |
18 | #include "wx/icon.h" |
19 | ||
2f1ae414 | 20 | #if !USE_SHARED_LIBRARIES |
e9576ca5 | 21 | IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap) |
2f1ae414 | 22 | #endif |
e9576ca5 | 23 | |
1996c23f | 24 | #include "wx/image.h" |
76a5e5d2 SC |
25 | #include "wx/mac/private.h" |
26 | ||
27 | ||
e9576ca5 SC |
28 | /* |
29 | * Icons | |
30 | */ | |
31 | ||
e9576ca5 SC |
32 | wxIcon::wxIcon() |
33 | { | |
34 | } | |
35 | ||
20b69855 | 36 | wxIcon::wxIcon(const char bits[], int width, int height) |
e9576ca5 | 37 | { |
20b69855 SC |
38 | wxBitmap bmp(bits,width,height) ; |
39 | CopyFromBitmap( bmp ) ; | |
e9576ca5 SC |
40 | } |
41 | ||
20b69855 | 42 | wxIcon::wxIcon( const char **bits ) |
2f1ae414 | 43 | { |
20b69855 SC |
44 | wxBitmap bmp(bits) ; |
45 | CopyFromBitmap( bmp ) ; | |
2f1ae414 SC |
46 | } |
47 | ||
20b69855 | 48 | wxIcon::wxIcon( char **bits ) |
2f1ae414 | 49 | { |
20b69855 SC |
50 | wxBitmap bmp(bits) ; |
51 | CopyFromBitmap( bmp ) ; | |
2f1ae414 SC |
52 | } |
53 | ||
76a5e5d2 | 54 | wxIcon::wxIcon(const wxString& icon_file, int flags, |
e9576ca5 | 55 | int desiredWidth, int desiredHeight) |
e9576ca5 | 56 | { |
76a5e5d2 | 57 | LoadFile(icon_file, (wxBitmapType) flags, desiredWidth, desiredHeight); |
e9576ca5 SC |
58 | } |
59 | ||
60 | wxIcon::~wxIcon() | |
61 | { | |
62 | } | |
63 | ||
20b69855 SC |
64 | WXHICON wxIcon::GetHICON() const |
65 | { | |
66 | wxASSERT( Ok() ) ; | |
67 | return (WXHICON) ((wxIconRefData*)m_refData)->GetHICON() ; | |
68 | } | |
69 | ||
70 | int wxIcon::GetWidth() const | |
71 | { | |
72 | return 32 ; | |
73 | } | |
74 | ||
75 | int wxIcon::GetHeight() const | |
76 | { | |
77 | return 32 ; | |
78 | } | |
79 | ||
80 | bool wxIcon::Ok() const | |
81 | { | |
82 | return m_refData != NULL ; | |
83 | } | |
84 | ||
76a5e5d2 | 85 | bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type, |
e9576ca5 SC |
86 | int desiredWidth, int desiredHeight) |
87 | { | |
e40298d5 JS |
88 | UnRef(); |
89 | ||
20b69855 | 90 | if ( type == wxBITMAP_TYPE_ICON_RESOURCE ) |
1996c23f | 91 | { |
20b69855 SC |
92 | OSType theId = 0 ; |
93 | if ( filename == wxT("wxICON_INFORMATION") ) | |
94 | { | |
95 | theId = kAlertNoteIcon ; | |
96 | } | |
97 | else if ( filename == wxT("wxICON_QUESTION") ) | |
98 | { | |
99 | theId = kAlertCautionIcon ; | |
100 | } | |
101 | else if ( filename == wxT("wxICON_WARNING") ) | |
102 | { | |
103 | theId = kAlertCautionIcon ; | |
104 | } | |
105 | else if ( filename == wxT("wxICON_ERROR") ) | |
106 | { | |
107 | theId = kAlertStopIcon ; | |
108 | } | |
109 | else | |
110 | {/* | |
111 | Str255 theName ; | |
112 | OSType theType ; | |
113 | wxMacStringToPascal( name , theName ) ; | |
114 | ||
115 | Handle resHandle = GetNamedResource( 'cicn' , theName ) ; | |
116 | if ( resHandle != 0L ) | |
117 | { | |
118 | GetResInfo( resHandle , &theId , &theType , theName ) ; | |
119 | ReleaseResource( resHandle ) ; | |
120 | } | |
121 | */ | |
122 | } | |
123 | if ( theId != 0 ) | |
124 | { | |
125 | IconRef iconRef = NULL ; | |
126 | verify_noerr(GetIconRef(kOnSystemDisk,kSystemIconsCreator,theId, &iconRef)) ; | |
127 | if ( iconRef ) | |
128 | { | |
129 | m_refData = new wxIconRefData( (WXHICON) iconRef ) ; | |
130 | return TRUE ; | |
131 | } | |
132 | } | |
133 | return FALSE ; | |
1996c23f | 134 | } |
e40298d5 | 135 | else |
1996c23f | 136 | { |
20b69855 SC |
137 | wxBitmapHandler *handler = wxBitmap::FindHandler(type); |
138 | ||
139 | if ( handler ) | |
1996c23f | 140 | { |
20b69855 SC |
141 | wxBitmap bmp ; |
142 | if ( handler->LoadFile(&bmp , filename, type, desiredWidth, desiredHeight )) | |
143 | { | |
144 | CopyFromBitmap( bmp ) ; | |
145 | return true ; | |
146 | } | |
147 | return false ; | |
148 | } | |
149 | else | |
150 | { | |
151 | wxImage loadimage(filename, type); | |
152 | if (loadimage.Ok()) | |
153 | { | |
154 | if ( desiredWidth == -1 ) | |
155 | desiredWidth = loadimage.GetWidth() ; | |
156 | if ( desiredHeight == -1 ) | |
157 | desiredHeight = loadimage.GetHeight() ; | |
158 | if ( desiredWidth != loadimage.GetWidth() || desiredHeight != loadimage.GetHeight() ) | |
159 | loadimage.Rescale( desiredWidth , desiredHeight ) ; | |
160 | wxBitmap bmp( loadimage ); | |
161 | CopyFromBitmap( bmp ) ; | |
162 | return true; | |
163 | } | |
1996c23f SC |
164 | } |
165 | } | |
20b69855 | 166 | return true ; |
e9576ca5 SC |
167 | } |
168 | ||
d062e17f GD |
169 | void wxIcon::CopyFromBitmap(const wxBitmap& bmp) |
170 | { | |
20b69855 SC |
171 | UnRef() ; |
172 | ||
173 | m_refData = new wxIconRefData( (WXHICON) wxMacCreateIconRef( bmp ) ) ; | |
174 | } | |
175 | ||
176 | wxIconRefData::wxIconRefData( WXHICON icon ) | |
177 | { | |
178 | m_iconRef = MAC_WXHICON( icon ) ; | |
179 | } | |
180 | ||
181 | void wxIconRefData::Init() | |
182 | { | |
183 | m_iconRef = NULL ; | |
184 | } | |
185 | ||
186 | void wxIconRefData::Free() | |
187 | { | |
188 | if ( m_iconRef ) | |
189 | { | |
190 | ReleaseIconRef( m_iconRef ) ; | |
191 | m_iconRef = NULL ; | |
192 | } | |
d062e17f GD |
193 | } |
194 | ||
519cb848 SC |
195 | IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler) |
196 | ||
197 | bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags, | |
e40298d5 | 198 | int desiredWidth, int desiredHeight) |
519cb848 | 199 | { |
20b69855 SC |
200 | wxIcon icon ; |
201 | icon.LoadFile( name , wxBITMAP_TYPE_ICON_RESOURCE , desiredWidth , desiredHeight ) ; | |
202 | bitmap->CopyFromIcon( icon ) ; | |
203 | return bitmap->Ok() ; | |
03e11df5 | 204 | } |