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.
This commit is contained in:
Tobias Taschner
2020-01-23 14:44:59 +01:00
parent fa74c30d09
commit 7a729e8a85

View File

@@ -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<CFURLRef> 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 );