]> git.saurik.com Git - wxWidgets.git/blob - src/mac/icon.cpp
Removed a bunch of unreachable BREAK statements that BCC compilation complains about.
[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 void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
73 {
74 wxIcon *icon = (wxIcon*)(&bmp);
75 *this = *icon;
76 }
77
78 IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler)
79
80 bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
81 int desiredWidth, int desiredHeight)
82 {
83 short theId = -1 ;
84 if ( name == "wxICON_INFO" )
85 {
86 theId = kNoteIcon ;
87 }
88 else if ( name == "wxICON_QUESTION" )
89 {
90 theId = kCautionIcon ;
91 }
92 else if ( name == "wxICON_WARNING" )
93 {
94 theId = kCautionIcon ;
95 }
96 else if ( name == "wxICON_ERROR" )
97 {
98 theId = kStopIcon ;
99 }
100 else
101 {
102 Str255 theName ;
103 OSType theType ;
104
105 #if TARGET_CARBON
106 c2pstrcpy( (StringPtr) theName , name ) ;
107 #else
108 strcpy( (char *) theName , name ) ;
109 c2pstr( (char *) theName ) ;
110 #endif
111
112 Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
113 if ( resHandle != 0L )
114 {
115 GetResInfo( resHandle , &theId , &theType , theName ) ;
116 ReleaseResource( resHandle ) ;
117 }
118 }
119 if ( theId != -1 )
120 {
121 CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ;
122 if ( theIcon )
123 {
124 M_BITMAPHANDLERDATA->m_hIcon = theIcon ;
125 M_BITMAPHANDLERDATA->m_width = 32 ;
126 M_BITMAPHANDLERDATA->m_height = 32 ;
127
128 M_BITMAPHANDLERDATA->m_depth = 8 ;
129 M_BITMAPHANDLERDATA->m_ok = true ;
130 M_BITMAPHANDLERDATA->m_numColors = 256 ;
131 M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypeIcon ;
132 return TRUE ;
133 }
134 }
135 return FALSE ;
136 }