From 7a729e8a855090a1aaaa875bbf954bc6d2c5aa95 Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Thu, 23 Jan 2020 14:44:59 +0100 Subject: [PATCH] Add handler for ICNS files (wxBITMAP_TYPE_ICON) After some recent changes bitmaps and icons with the type wxBITMAP_TYPE_ICON could no longer be loaded. This implements a handler for this (macOS only) bitmap type like the handler for wxBITMAP_TYPE_ICON_RESOURCE. --- src/osx/core/bitmap.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/osx/core/bitmap.cpp b/src/osx/core/bitmap.cpp index 550fc9c6d1..fd6ac4bc6f 100644 --- a/src/osx/core/bitmap.cpp +++ b/src/osx/core/bitmap.cpp @@ -1709,6 +1709,44 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxJPEGResourceHandler, wxBundleResourceHandler); #if wxOSX_USE_COCOA +class WXDLLEXPORT wxICNSHandler: public wxBitmapHandler +{ + wxDECLARE_DYNAMIC_CLASS(wxICNSHandler); + +public: + inline wxICNSHandler() + { + SetName(wxT("icns file")); + SetExtension("icns"); + SetType(wxBITMAP_TYPE_ICON); + } + + bool LoadFile(wxBitmap *bitmap, + const wxString& name, + wxBitmapType type, + int desiredWidth, + int desiredHeight) wxOVERRIDE + { + wxCFRef iconURL; + wxCFStringRef filePath(name); + + iconURL.reset(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, filePath, kCFURLPOSIXPathStyle, false)); + + WXImage img = wxOSXGetNSImageFromCFURL(iconURL); + + if ( img ) + { + bitmap->Create(img); + return true; + } + + return wxBitmapHandler::LoadFile( bitmap, name, type, desiredWidth, desiredHeight); + } + +}; + +wxIMPLEMENT_DYNAMIC_CLASS(wxICNSHandler, wxBitmapHandler); + class WXDLLEXPORT wxICNSResourceHandler: public wxBundleResourceHandler { wxDECLARE_DYNAMIC_CLASS(wxICNSResourceHandler); @@ -1915,6 +1953,7 @@ void wxBitmap::InitStandardHandlers() { #if wxOSX_USE_COCOA_OR_CARBON // no icns on iOS + AddHandler( new wxICNSHandler ); AddHandler( new wxICNSResourceHandler ) ; #endif AddHandler( new wxPNGResourceHandler );