]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/icon.cpp
Applied [ 1059554 ] patch for [1028659] fixes a couple of bugs with menus
[wxWidgets.git] / src / mac / carbon / 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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "icon.h"
14 #endif
15
16 #include "wx/wxprec.h"
17
18 #include "wx/icon.h"
19
20 #if !USE_SHARED_LIBRARIES
21 IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap)
22 #endif
23
24 #include "wx/image.h"
25 #include "wx/mac/private.h"
26
27
28 /*
29 * Icons
30 */
31
32 wxIcon::wxIcon()
33 {
34 }
35
36 wxIcon::wxIcon(const char bits[], int width, int height) :
37 wxBitmap(bits, width, height)
38 {
39
40 }
41
42 wxIcon::wxIcon( const char **bits ) :
43 wxBitmap(bits)
44 {
45 }
46
47 wxIcon::wxIcon( char **bits ) :
48 wxBitmap(bits)
49 {
50 }
51
52 wxIcon::wxIcon(const wxString& icon_file, int flags,
53 int desiredWidth, int desiredHeight)
54 {
55 LoadFile(icon_file, (wxBitmapType) flags, desiredWidth, desiredHeight);
56 }
57
58 wxIcon::~wxIcon()
59 {
60 }
61
62 bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type,
63 int desiredWidth, int desiredHeight)
64 {
65 UnRef();
66
67 wxBitmapHandler *handler = FindHandler(type);
68
69 if ( handler )
70 {
71 m_refData = new wxBitmapRefData;
72 return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight );
73 }
74 else
75 {
76 wxImage loadimage(filename, type);
77 if (loadimage.Ok())
78 {
79 if ( desiredWidth == -1 )
80 desiredWidth = loadimage.GetWidth() ;
81 if ( desiredHeight == -1 )
82 desiredHeight = loadimage.GetHeight() ;
83 if ( desiredWidth != loadimage.GetWidth() || desiredHeight != loadimage.GetHeight() )
84 loadimage.Rescale( desiredWidth , desiredHeight ) ;
85 wxBitmap bmp( loadimage );
86 wxIcon *icon = (wxIcon*)(&bmp);
87 *this = *icon;
88 return true;
89 }
90 }
91 return false ;
92 }
93
94 void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
95 {
96 wxIcon *icon = (wxIcon*)(&bmp);
97 *this = *icon;
98 }
99
100 IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler)
101
102 bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
103 int desiredWidth, int desiredHeight)
104 {
105 short theId = -1 ;
106 if ( name == wxT("wxICON_INFORMATION") )
107 {
108 theId = kNoteIcon ;
109 }
110 else if ( name == wxT("wxICON_QUESTION") )
111 {
112 theId = kCautionIcon ;
113 }
114 else if ( name == wxT("wxICON_WARNING") )
115 {
116 theId = kCautionIcon ;
117 }
118 else if ( name == wxT("wxICON_ERROR") )
119 {
120 theId = kStopIcon ;
121 }
122 else
123 {
124 Str255 theName ;
125 OSType theType ;
126 wxMacStringToPascal( name , theName ) ;
127
128 Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
129 if ( resHandle != 0L )
130 {
131 GetResInfo( resHandle , &theId , &theType , theName ) ;
132 ReleaseResource( resHandle ) ;
133 }
134 }
135 if ( theId != -1 )
136 {
137 CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ;
138 if ( theIcon )
139 {
140 M_BITMAPHANDLERDATA->m_hIcon = theIcon ;
141 M_BITMAPHANDLERDATA->m_width = 32 ;
142 M_BITMAPHANDLERDATA->m_height = 32 ;
143
144 M_BITMAPHANDLERDATA->m_depth = 8 ;
145 M_BITMAPHANDLERDATA->m_ok = true ;
146 M_BITMAPHANDLERDATA->m_numColors = 256 ;
147 M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypeIcon ;
148 return TRUE ;
149 }
150 }
151 return FALSE ;
152 }