// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "icon.h"
#endif
+#include "wx/wxprec.h"
+
#include "wx/icon.h"
#if !USE_SHARED_LIBRARIES
IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap)
#endif
+#include "wx/image.h"
#include "wx/mac/private.h"
{
}
-wxIcon::wxIcon(const char bits[], int width, int height) :
- wxBitmap(bits, width, height)
+wxIcon::wxIcon(const char bits[], int width, int height)
{
-
+ wxBitmap bmp(bits,width,height) ;
+ CopyFromBitmap( bmp ) ;
}
-wxIcon::wxIcon( const char **bits ) :
- wxBitmap(bits)
+wxIcon::wxIcon( const char **bits )
{
+ wxBitmap bmp(bits) ;
+ CopyFromBitmap( bmp ) ;
}
-wxIcon::wxIcon( char **bits ) :
- wxBitmap(bits)
+wxIcon::wxIcon( char **bits )
{
+ wxBitmap bmp(bits) ;
+ CopyFromBitmap( bmp ) ;
}
wxIcon::wxIcon(const wxString& icon_file, int flags,
{
}
-bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type,
- int desiredWidth, int desiredHeight)
+WXHICON wxIcon::GetHICON() const
{
- UnRef();
-
- m_refData = new wxBitmapRefData;
-
- wxBitmapHandler *handler = FindHandler((wxBitmapType)type);
-
- if ( handler )
- return handler->LoadFile(this, filename, type, desiredWidth, desiredHeight);
- else
- return FALSE;
+ wxASSERT( Ok() ) ;
+ return (WXHICON) ((wxIconRefData*)m_refData)->GetHICON() ;
}
-void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
+int wxIcon::GetWidth() const
{
- wxIcon *icon = (wxIcon*)(&bmp);
- *this = *icon;
+ return 32 ;
}
-IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler)
+int wxIcon::GetHeight() const
+{
+ return 32 ;
+}
-bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
- int desiredWidth, int desiredHeight)
+bool wxIcon::Ok() const
{
- short theId = -1 ;
- if ( name == wxT("wxICON_INFORMATION") )
- {
- theId = kNoteIcon ;
- }
- else if ( name == wxT("wxICON_QUESTION") )
- {
- theId = kCautionIcon ;
- }
- else if ( name == wxT("wxICON_WARNING") )
- {
- theId = kCautionIcon ;
- }
- else if ( name == wxT("wxICON_ERROR") )
+ return m_refData != NULL ;
+}
+
+bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type,
+ int desiredWidth, int desiredHeight)
+{
+ UnRef();
+
+ if ( type == wxBITMAP_TYPE_ICON_RESOURCE )
{
- theId = kStopIcon ;
+ OSType theId = 0 ;
+ if ( filename == wxT("wxICON_INFORMATION") )
+ {
+ theId = kAlertNoteIcon ;
+ }
+ else if ( filename == wxT("wxICON_QUESTION") )
+ {
+ theId = kAlertCautionIcon ;
+ }
+ else if ( filename == wxT("wxICON_WARNING") )
+ {
+ theId = kAlertCautionIcon ;
+ }
+ else if ( filename == wxT("wxICON_ERROR") )
+ {
+ theId = kAlertStopIcon ;
+ }
+ else
+ {/*
+ Str255 theName ;
+ OSType theType ;
+ wxMacStringToPascal( name , theName ) ;
+
+ Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
+ if ( resHandle != 0L )
+ {
+ GetResInfo( resHandle , &theId , &theType , theName ) ;
+ ReleaseResource( resHandle ) ;
+ }
+ */
+ }
+ if ( theId != 0 )
+ {
+ IconRef iconRef = NULL ;
+ verify_noerr(GetIconRef(kOnSystemDisk,kSystemIconsCreator,theId, &iconRef)) ;
+ if ( iconRef )
+ {
+ m_refData = new wxIconRefData( (WXHICON) iconRef ) ;
+ return TRUE ;
+ }
+ }
+ return FALSE ;
}
else
{
- Str255 theName ;
- OSType theType ;
- wxMacStringToPascal( name , theName ) ;
-
- Handle resHandle = GetNamedResource( 'cicn' , theName ) ;
- if ( resHandle != 0L )
+ wxBitmapHandler *handler = wxBitmap::FindHandler(type);
+
+ if ( handler )
{
- GetResInfo( resHandle , &theId , &theType , theName ) ;
- ReleaseResource( resHandle ) ;
+ wxBitmap bmp ;
+ if ( handler->LoadFile(&bmp , filename, type, desiredWidth, desiredHeight ))
+ {
+ CopyFromBitmap( bmp ) ;
+ return true ;
+ }
+ return false ;
}
- }
- if ( theId != -1 )
- {
- CIconHandle theIcon = (CIconHandle ) GetCIcon( theId ) ;
- if ( theIcon )
+ else
{
- M_BITMAPHANDLERDATA->m_hIcon = theIcon ;
- M_BITMAPHANDLERDATA->m_width = 32 ;
- M_BITMAPHANDLERDATA->m_height = 32 ;
-
- M_BITMAPHANDLERDATA->m_depth = 8 ;
- M_BITMAPHANDLERDATA->m_ok = true ;
- M_BITMAPHANDLERDATA->m_numColors = 256 ;
- M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypeIcon ;
- return TRUE ;
+ wxImage loadimage(filename, type);
+ if (loadimage.Ok())
+ {
+ if ( desiredWidth == -1 )
+ desiredWidth = loadimage.GetWidth() ;
+ if ( desiredHeight == -1 )
+ desiredHeight = loadimage.GetHeight() ;
+ if ( desiredWidth != loadimage.GetWidth() || desiredHeight != loadimage.GetHeight() )
+ loadimage.Rescale( desiredWidth , desiredHeight ) ;
+ wxBitmap bmp( loadimage );
+ CopyFromBitmap( bmp ) ;
+ return true;
+ }
}
}
- return FALSE ;
+ return true ;
+}
+
+void wxIcon::CopyFromBitmap(const wxBitmap& bmp)
+{
+ UnRef() ;
+
+ m_refData = new wxIconRefData( (WXHICON) wxMacCreateIconRef( bmp ) ) ;
+}
+
+wxIconRefData::wxIconRefData( WXHICON icon )
+{
+ m_iconRef = MAC_WXHICON( icon ) ;
+}
+
+void wxIconRefData::Init()
+{
+ m_iconRef = NULL ;
+}
+
+void wxIconRefData::Free()
+{
+ if ( m_iconRef )
+ {
+ ReleaseIconRef( m_iconRef ) ;
+ m_iconRef = NULL ;
+ }
+}
+
+IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler)
+
+bool wxICONResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
+ int desiredWidth, int desiredHeight)
+{
+ wxIcon icon ;
+ icon.LoadFile( name , wxBITMAP_TYPE_ICON_RESOURCE , desiredWidth , desiredHeight ) ;
+ bitmap->CopyFromIcon( icon ) ;
+ return bitmap->Ok() ;
}