From d7d7505974c97d1d7ef8ae541871a090af77ecce Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Mon, 20 Jul 2020 15:30:51 +0200 Subject: [PATCH] Fix generating mouse (and other) events in wxOSX wxStaticBitmap Use custom subclass for native static bitmap, to ensure that we call wxOSXCocoaClassAddWXMethods() for it. This notably allows to get mouse click events for this control. Closes #18545. --- src/osx/cocoa/statbmp.mm | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/osx/cocoa/statbmp.mm b/src/osx/cocoa/statbmp.mm index a1833634ff..20fd645f7c 100644 --- a/src/osx/cocoa/statbmp.mm +++ b/src/osx/cocoa/statbmp.mm @@ -32,6 +32,30 @@ #include "wx/osx/private.h" +@interface wxStaticBitmapView : NSImageView +{ +} +@end + +@implementation wxStaticBitmapView + ++ (void)initialize +{ + static BOOL initialized = NO; + if (!initialized) + { + initialized = YES; + wxOSXCocoaClassAddWXMethods( self ); + } +} + +- (instancetype)initWithFrame:(NSRect)frameRect +{ + self = [super initWithFrame:frameRect]; + return self; +} +@end + class wxStaticBitmapCocoaImpl : public wxWidgetCocoaImpl { public : @@ -51,7 +75,7 @@ public : void SetScaleMode(wxStaticBitmap::ScaleMode scaleMode) { - NSImageView* v = (NSImageView*) m_osxView; + wxStaticBitmapView* v = (wxStaticBitmapView*) m_osxView; NSImageScaling scaling = NSImageScaleNone; switch ( scaleMode ) @@ -92,7 +116,7 @@ wxWidgetImplType* wxWidgetImpl::CreateStaticBitmap( wxWindowMac* wxpeer, long WXUNUSED(extraStyle)) { NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; - NSImageView* v = [[NSImageView alloc] initWithFrame:r]; + wxStaticBitmapView* v = [[wxStaticBitmapView alloc] initWithFrame:r]; wxWidgetCocoaImpl* c = new wxStaticBitmapCocoaImpl( wxpeer, v ); return c;