]> git.saurik.com Git - wxWidgets.git/blob - src/mac/icon.cpp
made wxFFile a bit more safe: don't crash when Tell() and Length() are called on...
[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 == wxT("wxICON_INFORMATION") )
87 {
88 theId = kNoteIcon ;
89 }
90 else if ( name == wxT("wxICON_QUESTION") )
91 {
92 theId = kCautionIcon ;
93 }
94 else if ( name == wxT("wxICON_WARNING") )
95 {
96 theId = kCautionIcon ;
97 }
98 else if ( name == wxT("wxICON_ERROR") )
99 {
100 theId = kStopIcon ;
101 }
102 else
103 {
104 Str255 theName ;
105 OSType theType ;
106 wxMacStringToPascal( name , theName ) ;
107
108 Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
109 if ( resHandle != 0L )
110 {
111 GetResInfo( resHandle , &theId , &theType , theName ) ;
112 ReleaseResource( resHandle ) ;
113 }
114 }
115 if ( theId != -1 )
116 {
117 CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ;
118 if ( theIcon )
119 {
120 M_BITMAPHANDLERDATA->m_hIcon = theIcon ;
121 M_BITMAPHANDLERDATA->m_width = 32 ;
122 M_BITMAPHANDLERDATA->m_height = 32 ;
123
124 M_BITMAPHANDLERDATA->m_depth = 8 ;
125 M_BITMAPHANDLERDATA->m_ok = true ;
126 M_BITMAPHANDLERDATA->m_numColors = 256 ;
127 M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypeIcon ;
128 return TRUE ;
129 }
130 }
131 return FALSE ;
132 }