X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b5df4fc722412fe5f6764c490925b26293c5f662..eda34276d67de1578a3ed3d727b595b1858a8547:/src/cocoa/icon.mm diff --git a/src/cocoa/icon.mm b/src/cocoa/icon.mm index 5299b5a645..2f56004db6 100644 --- a/src/cocoa/icon.mm +++ b/src/cocoa/icon.mm @@ -6,14 +6,18 @@ // Created: 2003/08/11 // RCS-ID: $Id$ // Copyright: (c) 2003 David Elliott -// Licence: wxWindows licence +// Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// #include "wx/wxprec.h" + +#include "wx/icon.h" + #ifndef WX_PRECOMP - #include "wx/icon.h" + #include "wx/bitmap.h" #endif //WX_PRECOMP -#include "wx/bitmap.h" + +#include "wx/cocoa/autorelease.h" #import @@ -28,6 +32,8 @@ public: wxIconRefData( const wxIconRefData& data ); virtual ~wxIconRefData(); + virtual bool IsOk() const { return m_ok; } + protected: int m_width; int m_height; @@ -42,7 +48,7 @@ protected: wxIconRefData::wxIconRefData() { - m_ok = FALSE; + m_ok = false; m_width = 0; m_height = 0; m_depth = 0; @@ -64,6 +70,7 @@ wxIconRefData::wxIconRefData( const wxIconRefData& data) wxIconRefData::~wxIconRefData() { + wxAutoNSAutoreleasePool pool; [m_cocoaNSImage release]; m_cocoaNSImage = NULL; } @@ -93,7 +100,17 @@ wxIcon::~wxIcon() { } -bool wxIcon::CreateFromXpm(const char **xpm) +wxGDIRefData *wxIcon::CreateGDIRefData() const +{ + return new wxIconRefData; +} + +wxGDIRefData *wxIcon::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxIconRefData(*static_cast(data)); +} + +bool wxIcon::CreateFromXpm(const char* const* xpm) { wxBitmap bitmap(xpm); CopyFromBitmap(bitmap); @@ -103,17 +120,9 @@ bool wxIcon::CreateFromXpm(const char **xpm) bool wxIcon::LoadFile(const wxString& filename, wxBitmapType type, int desiredWidth, int desiredHeight) { - UnRef(); - - m_refData = new wxIconRefData; - M_ICONDATA->m_width = 5; - M_ICONDATA->m_height = 5; - M_ICONDATA->m_cocoaNSImage = [[NSImage alloc] initWithSize:NSMakeSize(5,5)]; - M_ICONDATA->m_ok = true; - M_ICONDATA->m_numColors = 0; - M_ICONDATA->m_quality = 0; - - return FALSE; + wxBitmap bitmap(filename, type); + CopyFromBitmap(bitmap); + return bitmap.Ok(); } void wxIcon::CopyFromBitmap(const wxBitmap& bitmap) @@ -122,17 +131,13 @@ void wxIcon::CopyFromBitmap(const wxBitmap& bitmap) m_refData = new wxIconRefData; M_ICONDATA->m_width = bitmap.GetWidth(); M_ICONDATA->m_height = bitmap.GetHeight(); - M_ICONDATA->m_cocoaNSImage = bitmap.GetNSImage(true); + wxAutoNSAutoreleasePool pool; + M_ICONDATA->m_cocoaNSImage = [bitmap.GetNSImage(true) retain]; M_ICONDATA->m_ok = bitmap.Ok(); M_ICONDATA->m_numColors = 0; M_ICONDATA->m_quality = 0; } -bool wxIcon::Ok() const -{ - return m_refData && M_ICONDATA->m_ok; -} - int wxIcon::GetWidth() const { if(!m_refData) @@ -153,4 +158,3 @@ WX_NSImage wxIcon::GetNSImage() const return nil; return M_ICONDATA->m_cocoaNSImage; } -