From f2c5973f6172a643f032ffff38b10c302b6689c3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 9 Jan 2022 02:57:53 +0100 Subject: [PATCH] Fix cancel editing on Esc in wxOSX wxDataViewCtrl again Handle selectors corresponding to key presses, such as cancelOperation:, ourselves because we never get the keyDown events that are supposed to take care of generating it from the native code somehow. This fixes cancelling editing with Escape which stopped working since 26d6f82a81 (Implement EVT_CHAR generation for wxDataViewCtrl under Mac, 2021-04-13). Closes #17835, #2639. Co-Authored-By: Stefan Csomor --- include/wx/osx/cocoa/private.h | 1 + src/osx/cocoa/dataview.mm | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index d35a452254..bd4657b146 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -375,6 +375,7 @@ public: typedef void (*wxOSX_EventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event); typedef BOOL (*wxOSX_PerformKeyEventHandlerPtr)(NSView* self, SEL _cmd, NSEvent *event); typedef BOOL (*wxOSX_FocusHandlerPtr)(NSView* self, SEL _cmd); + typedef void (*wxOSX_DoCommandBySelectorPtr)(NSView* self, SEL _cmd, SEL _sel); typedef NSDragOperation (*wxOSX_DraggingEnteredOrUpdatedHandlerPtr)(NSView *self, SEL _cmd, void *sender); typedef void (*wxOSX_DraggingExitedHandlerPtr)(NSView *self, SEL _cmd, void *sender); typedef BOOL (*wxOSX_PerformDragOperationHandlerPtr)(NSView *self, SEL _cmd, void *sender); diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index b0517f5797..1859b289d2 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -2005,12 +2005,23 @@ bool wxCocoaDataViewControl::doCommandBySelector(void* sel, WXWidget slf, void* { bool handled = wxWidgetCocoaImpl::doCommandBySelector(sel, slf, _cmd); // if this special key has not been handled - if ( !handled && IsInNativeKeyDown() ) + if ( !handled ) { - // send the original key event back to the native implementation to get proper default handling like eg for arrow keys - wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:@selector(keyDown:)]; - superimpl(slf, @selector(keyDown:), GetLastNativeKeyDownEvent()); + if ( IsInNativeKeyDown() ) + { + // send the original key event back to the native implementation to get proper default handling like eg for arrow keys + wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:@selector(keyDown:)]; + superimpl(slf, @selector(keyDown:), GetLastNativeKeyDownEvent()); + } + else + { + const auto superimpl = (wxOSX_DoCommandBySelectorPtr) + [[slf superclass] instanceMethodForSelector:@selector(doCommandBySelector:)]; + if ( superimpl ) + superimpl(slf, @selector(doCommandBySelector:), (SEL)sel); + } } + return handled; }