]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/icon.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxIcon class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "icon.h"
18 #if !USE_SHARED_LIBRARIES
19 IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxBitmap
)
23 #include "wx/mac/private.h"
34 wxIcon::wxIcon(const char bits
[], int width
, int height
) :
35 wxBitmap(bits
, width
, height
)
40 wxIcon::wxIcon( const char **bits
) :
45 wxIcon::wxIcon( char **bits
) :
50 wxIcon::wxIcon(const wxString
& icon_file
, int flags
,
51 int desiredWidth
, int desiredHeight
)
53 LoadFile(icon_file
, (wxBitmapType
) flags
, desiredWidth
, desiredHeight
);
60 bool wxIcon::LoadFile(const wxString
& filename
, wxBitmapType type
,
61 int desiredWidth
, int desiredHeight
)
65 wxBitmapHandler
*handler
= FindHandler(type
);
69 m_refData
= new wxBitmapRefData
;
70 return handler
->LoadFile(this, filename
, type
, desiredWidth
, desiredHeight
);
74 wxImage
loadimage(filename
, type
);
77 if ( desiredWidth
== -1 )
78 desiredWidth
= loadimage
.GetWidth() ;
79 if ( desiredHeight
== -1 )
80 desiredHeight
= loadimage
.GetHeight() ;
81 if ( desiredWidth
!= loadimage
.GetWidth() || desiredHeight
!= loadimage
.GetHeight() )
82 loadimage
.Rescale( desiredWidth
, desiredHeight
) ;
83 wxBitmap
bmp( loadimage
);
84 wxIcon
*icon
= (wxIcon
*)(&bmp
);
92 void wxIcon::CopyFromBitmap(const wxBitmap
& bmp
)
94 wxIcon
*icon
= (wxIcon
*)(&bmp
);
98 IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler
, wxBitmapHandler
)
100 bool wxICONResourceHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
101 int desiredWidth
, int desiredHeight
)
104 if ( name
== wxT("wxICON_INFORMATION") )
108 else if ( name
== wxT("wxICON_QUESTION") )
110 theId
= kCautionIcon
;
112 else if ( name
== wxT("wxICON_WARNING") )
114 theId
= kCautionIcon
;
116 else if ( name
== wxT("wxICON_ERROR") )
124 wxMacStringToPascal( name
, theName
) ;
126 Handle resHandle
= GetNamedResource( 'cicn' , theName
) ;
127 if ( resHandle
!= 0L )
129 GetResInfo( resHandle
, &theId
, &theType
, theName
) ;
130 ReleaseResource( resHandle
) ;
135 CIconHandle theIcon
= (CIconHandle
) GetCIcon( theId
) ;
138 M_BITMAPHANDLERDATA
->m_hIcon
= theIcon
;
139 M_BITMAPHANDLERDATA
->m_width
= 32 ;
140 M_BITMAPHANDLERDATA
->m_height
= 32 ;
142 M_BITMAPHANDLERDATA
->m_depth
= 8 ;
143 M_BITMAPHANDLERDATA
->m_ok
= true ;
144 M_BITMAPHANDLERDATA
->m_numColors
= 256 ;
145 M_BITMAPHANDLERDATA
->m_bitmapType
= kMacBitmapTypeIcon
;