]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/icon.cpp
removing dependancy on mac headers from public wx headers (eventually adding wx/mac...
[wxWidgets.git] / src / mac / carbon / 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 #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 {
53 LoadFile(icon_file, (wxBitmapType) flags, desiredWidth, desiredHeight);
54 }
55
56 wxIcon::~wxIcon()
57 {
58 }
59
60 bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type,
61 int desiredWidth, int desiredHeight)
62 {
63 UnRef();
64
65 m_refData = new wxBitmapRefData;
66
67 wxBitmapHandler *handler = FindHandler((wxBitmapType)type);
68
69 if ( handler )
70 return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight);
71 else
72 return FALSE;
73 }
74
75 void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
76 {
77 wxIcon *icon = (wxIcon*)(&bmp);
78 *this = *icon;
79 }
80
81 IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler)
82
83 bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
84 int desiredWidth, int desiredHeight)
85 {
86 short theId = -1 ;
87 if ( name == "wxICON_INFO" )
88 {
89 theId = kNoteIcon ;
90 }
91 else if ( name == "wxICON_QUESTION" )
92 {
93 theId = kCautionIcon ;
94 }
95 else if ( name == "wxICON_WARNING" )
96 {
97 theId = kCautionIcon ;
98 }
99 else if ( name == "wxICON_ERROR" )
100 {
101 theId = kStopIcon ;
102 }
103 else
104 {
105 Str255 theName ;
106 OSType theType ;
107
108 #if TARGET_CARBON
109 c2pstrcpy( (StringPtr) theName , name ) ;
110 #else
111 strcpy( (char *) theName , name ) ;
112 c2pstr( (char *) theName ) ;
113 #endif
114
115 Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
116 if ( resHandle != 0L )
117 {
118 GetResInfo( resHandle , &theId , &theType , theName ) ;
119 ReleaseResource( resHandle ) ;
120 }
121 }
122 if ( theId != -1 )
123 {
124 CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ;
125 if ( theIcon )
126 {
127 M_BITMAPHANDLERDATA->m_hIcon = theIcon ;
128 M_BITMAPHANDLERDATA->m_width = 32 ;
129 M_BITMAPHANDLERDATA->m_height = 32 ;
130
131 M_BITMAPHANDLERDATA->m_depth = 8 ;
132 M_BITMAPHANDLERDATA->m_ok = true ;
133 M_BITMAPHANDLERDATA->m_numColors = 256 ;
134 M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypeIcon ;
135 return TRUE ;
136 }
137 }
138 return FALSE ;
139 }