X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/899544330f37440c140b72a014c518a911b5b7a4..9d5507f7a2701395e1d5c121bd877bb9066ee6ea:/src/mac/carbon/icon.cpp?ds=inline diff --git a/src/mac/carbon/icon.cpp b/src/mac/carbon/icon.cpp index e774075ae3..87c0ceb969 100644 --- a/src/mac/carbon/icon.cpp +++ b/src/mac/carbon/icon.cpp @@ -19,10 +19,60 @@ #include "wx/mac/private.h" -IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxBitmap) +IMPLEMENT_DYNAMIC_CLASS(wxIcon, wxGDIObject) #define M_ICONDATA ((wxIconRefData *)m_refData) +class WXDLLEXPORT wxIconRefData : public wxGDIRefData +{ +public: + wxIconRefData(); + wxIconRefData( WXHICON iconref, int desiredWidth, int desiredHeight ); + virtual ~wxIconRefData() { Free(); } + + void Init(); + virtual void Free(); + + void SetWidth( int width ) { m_width = width; } + void SetHeight( int height ) { m_height = height; } + + int GetWidth() const { return m_width; } + int GetHeight() const { return m_height; } + + WXHICON GetHICON() const { return (WXHICON) m_iconRef; } + private : + IconRef m_iconRef; + int m_width; + int m_height; +}; + + +wxIconRefData::wxIconRefData( WXHICON icon, int desiredWidth, int desiredHeight ) +{ + m_iconRef = MAC_WXHICON( icon ) ; + + // Standard sizes + SetWidth( desiredWidth == -1 ? 32 : desiredWidth ) ; + SetHeight( desiredHeight == -1 ? 32 : desiredHeight ) ; +} + +void wxIconRefData::Init() +{ + m_iconRef = NULL ; +} + +void wxIconRefData::Free() +{ + if ( m_iconRef ) + { + ReleaseIconRef( m_iconRef ) ; + m_iconRef = NULL ; + } +} + +// +// +// wxIcon::wxIcon() { @@ -60,9 +110,7 @@ wxIcon::wxIcon(WXHICON icon, const wxSize& size) if (icon) AcquireIconRef( (IconRef) icon ) ; - m_refData = new wxIconRefData( icon ) ; - M_ICONDATA->SetWidth( size.x ) ; - M_ICONDATA->SetHeight( size.y ) ; + m_refData = new wxIconRefData( icon, size.x, size.y ) ; } wxIcon::~wxIcon() @@ -152,18 +200,34 @@ bool wxIcon::LoadFile( } else { -#if 0 - Str255 theName ; - OSType theType ; - wxMacStringToPascal( name , theName ) ; - - Handle resHandle = GetNamedResource( 'cicn' , theName ) ; - if ( resHandle != 0L ) + IconRef iconRef = NULL ; + + // first look in the resource fork + if ( iconRef == NULL ) + { + Str255 theName ; + + wxMacStringToPascal( filename , theName ) ; + Handle resHandle = GetNamedResource( 'icns' , theName ) ; + if ( resHandle != 0L ) + { + IconFamilyHandle iconFamily = (IconFamilyHandle) resHandle ; + HLock((Handle) iconFamily); + OSStatus err = GetIconRefFromIconFamilyPtr( *iconFamily, GetHandleSize((Handle) iconFamily), &iconRef ); + HUnlock((Handle) iconFamily); + wxASSERT_MSG( err == noErr , wxT("Error when constructing icon ref") ); + ReleaseResource( resHandle ) ; + } + } + if ( iconRef == NULL ) { - GetResInfo( resHandle , &theId , &theType , theName ) ; - ReleaseResource( resHandle ) ; + // TODO add other attempts to load it from files etc here } -#endif + if ( iconRef ) + { + m_refData = new wxIconRefData( (WXHICON) iconRef, desiredWidth, desiredHeight ) ; + return true ; + } } if ( theId != 0 ) @@ -172,7 +236,7 @@ bool wxIcon::LoadFile( verify_noerr( GetIconRef( kOnSystemDisk, kSystemIconsCreator, theId, &iconRef ) ) ; if ( iconRef ) { - m_refData = new wxIconRefData( (WXHICON) iconRef ) ; + m_refData = new wxIconRefData( (WXHICON) iconRef, desiredWidth, desiredHeight ) ; return true ; } @@ -225,35 +289,8 @@ void wxIcon::CopyFromBitmap( const wxBitmap& bmp ) UnRef() ; // as the bitmap owns that ref, we have to acquire it as well - IconRef iconRef = bmp.GetBitmapData()->GetIconRef() ; - AcquireIconRef( iconRef ) ; - - m_refData = new wxIconRefData( (WXHICON) iconRef ) ; - M_ICONDATA->SetWidth( bmp.GetWidth() ) ; - M_ICONDATA->SetHeight( bmp.GetHeight() ) ; -} - -wxIconRefData::wxIconRefData( WXHICON icon ) -{ - m_iconRef = MAC_WXHICON( icon ) ; - - // Standard sizes - SetWidth( 32 ) ; - SetHeight( 32 ) ; -} - -void wxIconRefData::Init() -{ - m_iconRef = NULL ; -} - -void wxIconRefData::Free() -{ - if ( m_iconRef ) - { - ReleaseIconRef( m_iconRef ) ; - m_iconRef = NULL ; - } + IconRef iconRef = bmp.CreateIconRef() ; + m_refData = new wxIconRefData( (WXHICON) iconRef, bmp.GetWidth(), bmp.GetHeight() ) ; } IMPLEMENT_DYNAMIC_CLASS(wxICONResourceHandler, wxBitmapHandler)