1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxIcon class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxBitmap
)
19 #include "wx/mac/private.h"
21 #define M_ICONDATA ((wxIconRefData *)m_refData)
32 wxIcon::wxIcon(const char bits
[], int width
, int height
)
34 wxBitmap
bmp(bits
,width
,height
) ;
35 CopyFromBitmap( bmp
) ;
38 wxIcon::wxIcon( const char **bits
)
41 CopyFromBitmap( bmp
) ;
44 wxIcon::wxIcon( char **bits
)
47 CopyFromBitmap( bmp
) ;
50 wxIcon::wxIcon(const wxString
& icon_file
, int flags
,
51 int desiredWidth
, int desiredHeight
)
53 LoadFile(icon_file
, (wxBitmapType
) flags
, desiredWidth
, desiredHeight
);
60 WXHICON
wxIcon::GetHICON() const
63 return (WXHICON
) ((wxIconRefData
*)m_refData
)->GetHICON() ;
66 int wxIcon::GetWidth() const
68 wxCHECK_MSG( Ok(), -1, wxT("invalid icon") );
70 return M_ICONDATA
->GetWidth();
73 int wxIcon::GetHeight() const
75 wxCHECK_MSG( Ok(), -1, wxT("invalid icon") );
77 return M_ICONDATA
->GetHeight();
80 int wxIcon::GetDepth() const{
84 void wxIcon::SetDepth(int depth
){
88 void wxIcon::SetWidth(int width
){
92 void wxIcon::SetHeight(int height
){
96 bool wxIcon::Ok() const
98 return m_refData
!= NULL
;
101 bool wxIcon::LoadFile(const wxString
& filename
, wxBitmapType type
,
102 int desiredWidth
, int desiredHeight
)
106 if ( type
== wxBITMAP_TYPE_ICON_RESOURCE
)
109 if ( filename
== wxT("wxICON_INFORMATION") )
111 theId
= kAlertNoteIcon
;
113 else if ( filename
== wxT("wxICON_QUESTION") )
115 theId
= kAlertCautionIcon
;
117 else if ( filename
== wxT("wxICON_WARNING") )
119 theId
= kAlertCautionIcon
;
121 else if ( filename
== wxT("wxICON_ERROR") )
123 theId
= kAlertStopIcon
;
129 wxMacStringToPascal( name , theName ) ;
131 Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
132 if ( resHandle != 0L )
134 GetResInfo( resHandle , &theId , &theType , theName ) ;
135 ReleaseResource( resHandle ) ;
141 IconRef iconRef
= NULL
;
142 verify_noerr(GetIconRef(kOnSystemDisk
,kSystemIconsCreator
,theId
, &iconRef
)) ;
145 m_refData
= new wxIconRefData( (WXHICON
) iconRef
) ;
153 wxBitmapHandler
*handler
= wxBitmap::FindHandler(type
);
158 if ( handler
->LoadFile(&bmp
, filename
, type
, desiredWidth
, desiredHeight
))
160 CopyFromBitmap( bmp
) ;
168 wxImage
loadimage(filename
, type
);
171 if ( desiredWidth
== -1 )
172 desiredWidth
= loadimage
.GetWidth() ;
173 if ( desiredHeight
== -1 )
174 desiredHeight
= loadimage
.GetHeight() ;
175 if ( desiredWidth
!= loadimage
.GetWidth() || desiredHeight
!= loadimage
.GetHeight() )
176 loadimage
.Rescale( desiredWidth
, desiredHeight
) ;
177 wxBitmap
bmp( loadimage
);
178 CopyFromBitmap( bmp
) ;
187 void wxIcon::CopyFromBitmap(const wxBitmap
& bmp
)
191 // as the bitmap owns that ref, we have to acquire it as well
192 IconRef iconRef
= bmp
.GetBitmapData()->GetIconRef() ;
193 AcquireIconRef( iconRef
) ;
194 m_refData
= new wxIconRefData( (WXHICON
) iconRef
) ;
195 M_ICONDATA
->SetWidth( bmp
.GetWidth() ) ;
196 M_ICONDATA
->SetHeight( bmp
.GetHeight() ) ;
199 wxIconRefData::wxIconRefData( WXHICON icon
)
201 m_iconRef
= MAC_WXHICON( icon
) ;
207 void wxIconRefData::Init()
212 void wxIconRefData::Free()
216 ReleaseIconRef( m_iconRef
) ;
221 IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler
, wxBitmapHandler
)
223 bool wxICONResourceHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
224 int desiredWidth
, int desiredHeight
)
227 icon
.LoadFile( name
, wxBITMAP_TYPE_ICON_RESOURCE
, desiredWidth
, desiredHeight
) ;
228 bitmap
->CopyFromIcon( icon
) ;
229 return bitmap
->Ok() ;