From 162ea7b1ef85197fa40203ea58166a6cdbaa2c54 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Fri, 5 Oct 2018 15:01:24 +0200 Subject: [PATCH] bringing back old style macOS icons loading see https://github.com/wxWidgets/wxWidgets/pull/925 --- src/osx/carbon/utilscocoa.mm | 2 +- src/osx/core/bitmap.cpp | 115 +++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 1 deletion(-) diff --git a/src/osx/carbon/utilscocoa.mm b/src/osx/carbon/utilscocoa.mm index 6c5ace2279..b134feb8e9 100644 --- a/src/osx/carbon/utilscocoa.mm +++ b/src/osx/carbon/utilscocoa.mm @@ -218,7 +218,7 @@ WXImage wxOSXGetImageFromCGImage( CGImageRef image, double scaleFactor, bool is #endif } -#if wxOSX_USE_ICONREF +#if wxOSX_USE_COCOA WXImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromIconRef( WXHICON iconref ) { NSImage *newImage = [[NSImage alloc] initWithIconRef:iconref]; diff --git a/src/osx/core/bitmap.cpp b/src/osx/core/bitmap.cpp index 41162af49d..f5240f99fd 100644 --- a/src/osx/core/bitmap.cpp +++ b/src/osx/core/bitmap.cpp @@ -1778,6 +1778,8 @@ public: wxIMPLEMENT_DYNAMIC_CLASS(wxJPEGResourceHandler, wxBundleResourceHandler); +#if wxOSX_USE_COCOA + class WXDLLEXPORT wxICNSResourceHandler: public wxBundleResourceHandler { wxDECLARE_DYNAMIC_CLASS(wxICNSResourceHandler); @@ -1789,10 +1791,123 @@ public: SetExtension("icns"); SetType(wxBITMAP_TYPE_ICON_RESOURCE); } + + virtual bool LoadFile(wxBitmap *bitmap, + const wxString& name, + wxBitmapType type, + int desiredWidth, + int desiredHeight) wxOVERRIDE; + }; wxIMPLEMENT_DYNAMIC_CLASS(wxICNSResourceHandler, wxBundleResourceHandler); +bool wxICNSResourceHandler::LoadFile(wxBitmap *bitmap, + const wxString& resourceName, + wxBitmapType type, + int desiredWidth, + int desiredHeight) +{ + OSType theId = 0 ; + + if ( resourceName == wxT("wxICON_INFORMATION") ) + { + theId = kAlertNoteIcon ; + } + else if ( resourceName == wxT("wxICON_QUESTION") ) + { + theId = kAlertCautionIcon ; + } + else if ( resourceName == wxT("wxICON_WARNING") ) + { + theId = kAlertCautionIcon ; + } + else if ( resourceName == wxT("wxICON_ERROR") ) + { + theId = kAlertStopIcon ; + } + else if ( resourceName == wxT("wxICON_FOLDER") ) + { + theId = kGenericFolderIcon ; + } + else if ( resourceName == wxT("wxICON_FOLDER_OPEN") ) + { + theId = kOpenFolderIcon ; + } + else if ( resourceName == wxT("wxICON_NORMAL_FILE") ) + { + theId = kGenericDocumentIcon ; + } + else if ( resourceName == wxT("wxICON_EXECUTABLE_FILE") ) + { + theId = kGenericApplicationIcon ; + } + else if ( resourceName == wxT("wxICON_CDROM") ) + { + theId = kGenericCDROMIcon ; + } + else if ( resourceName == wxT("wxICON_FLOPPY") ) + { + theId = kGenericFloppyIcon ; + } + else if ( resourceName == wxT("wxICON_HARDDISK") ) + { + theId = kGenericHardDiskIcon ; + } + else if ( resourceName == wxT("wxICON_REMOVABLE") ) + { + theId = kGenericRemovableMediaIcon ; + } + else if ( resourceName == wxT("wxICON_DELETE") ) + { + theId = kToolbarDeleteIcon ; + } + else if ( resourceName == wxT("wxICON_GO_BACK") ) + { + theId = kBackwardArrowIcon ; + } + else if ( resourceName == wxT("wxICON_GO_FORWARD") ) + { + theId = kForwardArrowIcon ; + } + else if ( resourceName == wxT("wxICON_GO_HOME") ) + { + theId = kToolbarHomeIcon ; + } + else if ( resourceName == wxT("wxICON_HELP_SETTINGS") ) + { + theId = kGenericFontIcon ; + } + else if ( resourceName == wxT("wxICON_HELP_PAGE") ) + { + theId = kGenericDocumentIcon ; + } + else if ( resourceName == wxT( "wxICON_PRINT" ) ) + { + theId = kPrintMonitorFolderIcon; + } + else if ( resourceName == wxT( "wxICON_HELP_FOLDER" ) ) + { + theId = kHelpFolderIcon; + } + + if ( theId != 0 ) + { + IconRef iconRef = NULL ; + __Verify_noErr(GetIconRef( kOnSystemDisk, kSystemIconsCreator, theId, &iconRef )) ; + if ( iconRef ) + { + WXImage img = wxOSXGetNSImageFromIconRef(iconRef); + bitmap->Create(img); + return true; + } + } + + return wxBundleResourceHandler::LoadFile( bitmap, resourceName, type, desiredWidth, desiredHeight); +} + +#endif // wxOSX_USE_COCOA + bool wxBundleResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, wxBitmapType WXUNUSED(type),