]> git.saurik.com Git - wxWidgets.git/blob - src/mac/icon.cpp
fixed converting BI_BITFIELDS bitmaps to DIBs (fixes 589416)
[wxWidgets.git] / src / mac / icon.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: icon.cpp
3 // Purpose: wxIcon class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "icon.h"
14 #endif
15
16 #include "wx/icon.h"
17
18 #if !USE_SHARED_LIBRARIES
19 IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap)
20 #endif
21
22 #include "wx/mac/private.h"
23
24
25 /*
26 * Icons
27 */
28
29 wxIcon::wxIcon()
30 {
31 }
32
33 wxIcon::wxIcon(const char bits[], int width, int height) :
34 wxBitmap(bits, width, height)
35 {
36
37 }
38
39 wxIcon::wxIcon( const char **bits ) :
40 wxBitmap(bits)
41 {
42 }
43
44 wxIcon::wxIcon( char **bits ) :
45 wxBitmap(bits)
46 {
47 }
48
49 wxIcon::wxIcon(const wxString& icon_file, int flags,
50 int desiredWidth, int desiredHeight)
51 {
52 LoadFile(icon_file, (wxBitmapType) flags, desiredWidth, desiredHeight);
53 }
54
55 wxIcon::~wxIcon()
56 {
57 }
58
59 bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type,
60 int desiredWidth, int desiredHeight)
61 {
62 UnRef();
63
64 m_refData = new wxBitmapRefData;
65
66 wxBitmapHandler *handler = FindHandler((wxBitmapType)type);
67
68 if ( handler )
69 return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight);
70 else
71 return FALSE;
72 }
73
74 void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
75 {
76 wxIcon *icon = (wxIcon*)(&bmp);
77 *this = *icon;
78 }
79
80 IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler)
81
82 bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
83 int desiredWidth, int desiredHeight)
84 {
85 short theId = -1 ;
86 if ( name == "wxICON_INFORMATION" )
87 {
88 theId = kNoteIcon ;
89 }
90 else if ( name == "wxICON_QUESTION" )
91 {
92 theId = kCautionIcon ;
93 }
94 else if ( name == "wxICON_WARNING" )
95 {
96 theId = kCautionIcon ;
97 }
98 else if ( name == "wxICON_ERROR" )
99 {
100 theId = kStopIcon ;
101 }
102 else
103 {
104 Str255 theName ;
105 OSType theType ;
106
107 #if TARGET_CARBON
108 c2pstrcpy( (StringPtr) theName , name ) ;
109 #else
110 strcpy( (char *) theName , name ) ;
111 c2pstr( (char *) theName ) ;
112 #endif
113
114 Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
115 if ( resHandle != 0L )
116 {
117 GetResInfo( resHandle , &theId , &theType , theName ) ;
118 ReleaseResource( resHandle ) ;
119 }
120 }
121 if ( theId != -1 )
122 {
123 CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ;
124 if ( theIcon )
125 {
126 M_BITMAPHANDLERDATA->m_hIcon = theIcon ;
127 M_BITMAPHANDLERDATA->m_width = 32 ;
128 M_BITMAPHANDLERDATA->m_height = 32 ;
129
130 M_BITMAPHANDLERDATA->m_depth = 8 ;
131 M_BITMAPHANDLERDATA->m_ok = true ;
132 M_BITMAPHANDLERDATA->m_numColors = 256 ;
133 M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypeIcon ;
134 return TRUE ;
135 }
136 }
137 return FALSE ;
138 }