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 #if !USE_SHARED_LIBRARIES
21 IMPLEMENT_DYNAMIC_CLASS(wxIcon
, wxBitmap
)
25 #include "wx/mac/private.h"
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
75 int wxIcon::GetHeight() const
80 bool wxIcon::Ok() const
82 return m_refData
!= NULL
;
85 bool wxIcon::LoadFile(const wxString
& filename
, wxBitmapType type
,
86 int desiredWidth
, int desiredHeight
)
90 if ( type
== wxBITMAP_TYPE_ICON_RESOURCE
)
93 if ( filename
== wxT("wxICON_INFORMATION") )
95 theId
= kAlertNoteIcon
;
97 else if ( filename
== wxT("wxICON_QUESTION") )
99 theId
= kAlertCautionIcon
;
101 else if ( filename
== wxT("wxICON_WARNING") )
103 theId
= kAlertCautionIcon
;
105 else if ( filename
== wxT("wxICON_ERROR") )
107 theId
= kAlertStopIcon
;
113 wxMacStringToPascal( name , theName ) ;
115 Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
116 if ( resHandle != 0L )
118 GetResInfo( resHandle , &theId , &theType , theName ) ;
119 ReleaseResource( resHandle ) ;
125 IconRef iconRef
= NULL
;
126 verify_noerr(GetIconRef(kOnSystemDisk
,kSystemIconsCreator
,theId
, &iconRef
)) ;
129 m_refData
= new wxIconRefData( (WXHICON
) iconRef
) ;
137 wxBitmapHandler
*handler
= wxBitmap::FindHandler(type
);
142 if ( handler
->LoadFile(&bmp
, filename
, type
, desiredWidth
, desiredHeight
))
144 CopyFromBitmap( bmp
) ;
151 wxImage
loadimage(filename
, type
);
154 if ( desiredWidth
== -1 )
155 desiredWidth
= loadimage
.GetWidth() ;
156 if ( desiredHeight
== -1 )
157 desiredHeight
= loadimage
.GetHeight() ;
158 if ( desiredWidth
!= loadimage
.GetWidth() || desiredHeight
!= loadimage
.GetHeight() )
159 loadimage
.Rescale( desiredWidth
, desiredHeight
) ;
160 wxBitmap
bmp( loadimage
);
161 CopyFromBitmap( bmp
) ;
169 void wxIcon::CopyFromBitmap(const wxBitmap
& bmp
)
173 m_refData
= new wxIconRefData( (WXHICON
) wxMacCreateIconRef( bmp
) ) ;
176 wxIconRefData::wxIconRefData( WXHICON icon
)
178 m_iconRef
= MAC_WXHICON( icon
) ;
181 void wxIconRefData::Init()
186 void wxIconRefData::Free()
190 ReleaseIconRef( m_iconRef
) ;
195 IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler
, wxBitmapHandler
)
197 bool wxICONResourceHandler::LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
198 int desiredWidth
, int desiredHeight
)
201 icon
.LoadFile( name
, wxBITMAP_TYPE_ICON_RESOURCE
, desiredWidth
, desiredHeight
) ;
202 bitmap
->CopyFromIcon( icon
) ;
203 return bitmap
->Ok() ;