From 148732993a5d566112f68c16686e3663ccdd5956 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Mon, 10 Sep 2018 21:20:35 +0200 Subject: [PATCH] only use native NSImage dimension --- include/wx/osx/cocoa/private.h | 1 + src/osx/carbon/icon.cpp | 18 +++--------------- src/osx/carbon/utilscocoa.mm | 5 +++++ 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index bb0f15d06c..c460861a20 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -37,6 +37,7 @@ WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromCGImage( CGImageRef image, double WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromIconRef( WXHICON iconref ); WX_NSImage WXDLLIMPEXP_CORE wxOSXGetIconForType(OSType type ); void WXDLLIMPEXP_CORE wxOSXSetImageSize(WX_NSImage image, CGFloat width, CGFloat height); +CGSize WXDLLIMPEXP_CORE wxOSXGetImageSize(WX_NSImage image); CGImageRef WXDLLIMPEXP_CORE wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage, double *scale = NULL ); CGImageRef WXDLLIMPEXP_CORE wxOSXGetCGImageFromNSImage( WX_NSImage nsimage, CGRect* r, CGContextRef cg); CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage nsimage, bool *isTemplate = NULL); diff --git a/src/osx/carbon/icon.cpp b/src/osx/carbon/icon.cpp index c1e902259a..2a6a3da20d 100644 --- a/src/osx/carbon/icon.cpp +++ b/src/osx/carbon/icon.cpp @@ -42,11 +42,8 @@ public: virtual bool IsOk() const wxOVERRIDE { return m_nsImage != NULL; } virtual void Free(); - void SetWidth( int width ) { m_width = width; } - void SetHeight( int height ) { m_height = height; } - - int GetWidth() const { return m_width; } - int GetHeight() const { return m_height; } + int GetWidth() const { return (int) wxOSXGetImageSize(m_nsImage).width; } + int GetHeight() const { return (int) wxOSXGetImageSize(m_nsImage).height; } WX_NSImage GetNSImage() const; @@ -55,9 +52,6 @@ private: void Create( NSImage* icon, int desiredWidth, int desiredHeight ); NSImage* m_nsImage; - int m_width; - int m_height; - // We can (easily) copy m_iconRef so we don't implement the copy ctor. wxDECLARE_NO_COPY_CLASS(wxIconRefData); }; @@ -78,24 +72,18 @@ wxIconRefData::wxIconRefData( WXHICON iconref, int desiredWidth, int desiredHeig ReleaseIconRef(iconref); } -void wxIconRefData::Create( NSImage* icon, int desiredWidth, int desiredHeight ) +void wxIconRefData::Create( NSImage* icon, int WXUNUSED(desiredWidth), int WXUNUSED(desiredHeight) ) { if ( icon ) { m_nsImage = icon; wxMacCocoaRetain(icon); } - - // Standard sizes - SetWidth( desiredWidth == -1 ? 32 : desiredWidth ) ; - SetHeight( desiredHeight == -1 ? 32 : desiredHeight ) ; } void wxIconRefData::Init() { m_nsImage = NULL; - m_width = - m_height = 0; } void wxIconRefData::Free() diff --git a/src/osx/carbon/utilscocoa.mm b/src/osx/carbon/utilscocoa.mm index 99d05565bf..07d6b6440c 100644 --- a/src/osx/carbon/utilscocoa.mm +++ b/src/osx/carbon/utilscocoa.mm @@ -297,6 +297,11 @@ void wxOSXSetImageSize(WX_NSImage image, CGFloat width, CGFloat height) [image setSize:NSMakeSize(width, height)]; } +CGSize wxOSXGetImageSize(WX_NSImage image) +{ + return NSSizeToCGSize([image size]); +} + CGImageRef wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage, double *scaleptr ) { // based on http://www.mail-archive.com/cocoa-dev@lists.apple.com/msg18065.html