diff --git a/include/wx/osx/icon.h b/include/wx/osx/icon.h index bc6b721db6..fc6f426084 100644 --- a/include/wx/osx/icon.h +++ b/include/wx/osx/icon.h @@ -52,7 +52,11 @@ public: wxSize GetSize() const { return wxSize(GetWidth(), GetHeight()); } WXHICON GetHICON() const; - + +#if wxOSX_USE_COCOA + WX_NSImage GetNSImage() const ; +#endif + protected: virtual wxGDIRefData *CreateGDIRefData() const; virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const; diff --git a/src/osx/carbon/icon.cpp b/src/osx/carbon/icon.cpp index 51b3e34f40..0dd456a44c 100644 --- a/src/osx/carbon/icon.cpp +++ b/src/osx/carbon/icon.cpp @@ -42,11 +42,17 @@ public: int GetHeight() const { return m_height; } WXHICON GetHICON() const { return (WXHICON) m_iconRef; } +#if wxOSX_USE_COCOA + WX_NSImage GetNSImage() const; +#endif private: void Init(); IconRef m_iconRef; +#if wxOSX_USE_COCOA + mutable NSImage* m_nsImage; +#endif int m_width; int m_height; @@ -57,6 +63,7 @@ private: wxIconRefData::wxIconRefData( WXHICON icon, int desiredWidth, int desiredHeight ) { + Init(); m_iconRef = (IconRef)( icon ) ; // Standard sizes @@ -67,6 +74,9 @@ wxIconRefData::wxIconRefData( WXHICON icon, int desiredWidth, int desiredHeight void wxIconRefData::Init() { m_iconRef = NULL ; +#if wxOSX_USE_COCOA + m_nsImage = NULL; +#endif m_width = m_height = 0; } @@ -78,8 +88,30 @@ void wxIconRefData::Free() ReleaseIconRef( m_iconRef ) ; m_iconRef = NULL ; } + +#if wxOSX_USE_COCOA + if ( m_nsImage ) + { + CFRelease(m_nsImage); + } +#endif } +#if wxOSX_USE_COCOA +WX_NSImage wxIconRefData::GetNSImage() const +{ + wxASSERT( IsOk() ); + + if ( m_nsImage == 0 ) + { + m_nsImage = wxOSXGetNSImageFromIconRef(m_iconRef); + CFRetain(m_nsImage); + } + + return m_nsImage; +} +#endif + // // // @@ -160,6 +192,15 @@ int wxIcon::GetDepth() const return 32; } +#if wxOSX_USE_COCOA +WX_NSImage wxIcon::GetNSImage() const +{ + wxCHECK_MSG( IsOk(), NULL, wxT("invalid icon") ); + + return M_ICONDATA->GetNSImage() ; +} +#endif + void wxIcon::SetDepth( int WXUNUSED(depth) ) { }