]> git.saurik.com Git - wxWidgets.git/blob - src/mac/icon.cpp
Compilo correction
[wxWidgets.git] / src / mac / icon.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: icon.cpp
3 // Purpose: wxIcon class
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
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 /*
23 * Icons
24 */
25
26 wxIcon::wxIcon()
27 {
28 }
29
30 wxIcon::wxIcon(const char bits[], int width, int height) :
31 wxBitmap(bits,width,height )
32 {
33
34 }
35
36 wxIcon::wxIcon( const char **bits ) :
37 wxBitmap(bits )
38 {
39 }
40
41 wxIcon::wxIcon( char **bits ) :
42 wxBitmap(bits )
43 {
44 }
45
46 wxIcon::wxIcon(const wxString& icon_file, long flags,
47 int desiredWidth, int desiredHeight)
48
49 {
50 LoadFile(icon_file, flags, desiredWidth, desiredHeight);
51 }
52
53 wxIcon::~wxIcon()
54 {
55 }
56
57 bool wxIcon::LoadFile(const wxString& filename, long type,
58 int desiredWidth, int desiredHeight)
59 {
60 UnRef();
61
62 m_refData = new wxBitmapRefData;
63
64 wxBitmapHandler *handler = FindHandler((wxBitmapType)type);
65
66 if ( handler )
67 return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight);
68 else
69 return FALSE;
70 }
71
72 IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler)
73
74 bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
75 int desiredWidth, int desiredHeight)
76 {
77 short theId = -1 ;
78 if ( name == "wxICON_INFO" )
79 {
80 theId = kNoteIcon ;
81 }
82 else if ( name == "wxICON_QUESTION" )
83 {
84 theId = kCautionIcon ;
85 }
86 else if ( name == "wxICON_WARNING" )
87 {
88 theId = kCautionIcon ;
89 }
90 else if ( name == "wxICON_ERROR" )
91 {
92 theId = kStopIcon ;
93 }
94 else
95 {
96 Str255 theName ;
97 OSType theType ;
98
99 #if TARGET_CARBON
100 c2pstrcpy( (StringPtr) theName , name ) ;
101 #else
102 strcpy( (char *) theName , name ) ;
103 c2pstr( (char *) theName ) ;
104 #endif
105
106 Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
107 if ( resHandle != 0L )
108 {
109 GetResInfo( resHandle , &theId , &theType , theName ) ;
110 ReleaseResource( resHandle ) ;
111 }
112 }
113 if ( theId != -1 )
114 {
115 CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ;
116 if ( theIcon )
117 {
118 M_BITMAPHANDLERDATA->m_hIcon = theIcon ;
119 M_BITMAPHANDLERDATA->m_width = 32 ;
120 M_BITMAPHANDLERDATA->m_height = 32 ;
121
122 M_BITMAPHANDLERDATA->m_depth = 8 ;
123 M_BITMAPHANDLERDATA->m_ok = true ;
124 M_BITMAPHANDLERDATA->m_numColors = 256 ;
125 M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypeIcon ;
126 return TRUE ;
127 }
128 }
129 return FALSE ;
130 }