1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxIcon class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "icon.h"
16 #include "wx/wxprec.h"
20 IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxBitmap
)
23 #include "wx/mac/private.h"
25 #define M_ICONDATA ((wxIconRefData *)m_refData)
36 wxIcon::wxIcon(const char bits
[], int width
, int height
)
38 wxBitmap
bmp(bits
,width
,height
) ;
39 CopyFromBitmap( bmp
) ;
42 wxIcon::wxIcon( const char **bits
)
45 CopyFromBitmap( bmp
) ;
48 wxIcon::wxIcon( char **bits
)
51 CopyFromBitmap( bmp
) ;
54 wxIcon::wxIcon(const wxString
& icon_file
, int flags
,
55 int desiredWidth
, int desiredHeight
)
57 LoadFile(icon_file
, (wxBitmapType
) flags
, desiredWidth
, desiredHeight
);
64 WXHICON
wxIcon::GetHICON() const
67 return (WXHICON
) ((wxIconRefData
*)m_refData
)->GetHICON() ;
70 int wxIcon::GetWidth() const
72 wxCHECK_MSG( Ok(), -1, wxT("invalid icon") );
74 return M_ICONDATA
->GetWidth();
77 int wxIcon::GetHeight() const
79 wxCHECK_MSG( Ok(), -1, wxT("invalid icon") );
81 return M_ICONDATA
->GetHeight();
84 int wxIcon::GetDepth() const{
88 void wxIcon::SetDepth(int depth
){
92 void wxIcon::SetWidth(int width
){
96 void wxIcon::SetHeight(int height
){
100 bool wxIcon::Ok() const
102 return m_refData
!= NULL
;
105 bool wxIcon::LoadFile(const wxString
& filename
, wxBitmapType type
,
106 int desiredWidth
, int desiredHeight
)
110 if ( type
== wxBITMAP_TYPE_ICON_RESOURCE
)
113 if ( filename
== wxT("wxICON_INFORMATION") )
115 theId
= kAlertNoteIcon
;
117 else if ( filename
== wxT("wxICON_QUESTION") )
119 theId
= kAlertCautionIcon
;
121 else if ( filename
== wxT("wxICON_WARNING") )
123 theId
= kAlertCautionIcon
;
125 else if ( filename
== wxT("wxICON_ERROR") )
127 theId
= kAlertStopIcon
;
133 wxMacStringToPascal( name , theName ) ;
135 Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
136 if ( resHandle != 0L )
138 GetResInfo( resHandle , &theId , &theType , theName ) ;
139 ReleaseResource( resHandle ) ;
145 IconRef iconRef
= NULL
;
146 verify_noerr(GetIconRef(kOnSystemDisk
,kSystemIconsCreator
,theId
, &iconRef
)) ;
149 m_refData
= new wxIconRefData( (WXHICON
) iconRef
) ;
157 wxBitmapHandler
*handler
= wxBitmap::FindHandler(type
);
162 if ( handler
->LoadFile(&bmp
, filename
, type
, desiredWidth
, desiredHeight
))
164 CopyFromBitmap( bmp
) ;
172 wxImage
loadimage(filename
, type
);
175 if ( desiredWidth
== -1 )
176 desiredWidth
= loadimage
.GetWidth() ;
177 if ( desiredHeight
== -1 )
178 desiredHeight
= loadimage
.GetHeight() ;
179 if ( desiredWidth
!= loadimage
.GetWidth() || desiredHeight
!= loadimage
.GetHeight() )
180 loadimage
.Rescale( desiredWidth
, desiredHeight
) ;
181 wxBitmap
bmp( loadimage
);
182 CopyFromBitmap( bmp
) ;
191 void wxIcon::CopyFromBitmap(const wxBitmap
& bmp
)
195 // as the bitmap owns that ref, we have to acquire it as well
196 IconRef iconRef
= bmp
.GetBitmapData()->GetIconRef() ;
197 AcquireIconRef( iconRef
) ;
198 m_refData
= new wxIconRefData( (WXHICON
) iconRef
) ;
199 M_ICONDATA
->SetWidth( bmp
.GetWidth() ) ;
200 M_ICONDATA
->SetHeight( bmp
.GetHeight() ) ;
203 wxIconRefData::wxIconRefData( WXHICON icon
)
205 m_iconRef
= MAC_WXHICON( icon
) ;
211 void wxIconRefData::Init()
216 void wxIconRefData::Free()
220 ReleaseIconRef( m_iconRef
) ;
225 IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler
, wxBitmapHandler
)
227 bool wxICONResourceHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
228 int desiredWidth
, int desiredHeight
)
231 icon
.LoadFile( name
, wxBITMAP_TYPE_ICON_RESOURCE
, desiredWidth
, desiredHeight
) ;
232 bitmap
->CopyFromIcon( icon
) ;
233 return bitmap
->Ok() ;