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 <csomor@advancedconcepts.ch>
This commit is contained in:
Vadim Zeitlin
2022-01-09 02:57:53 +01:00
parent 7e3059dee0
commit f2c5973f61
2 changed files with 16 additions and 4 deletions

View File

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

View File

@@ -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 )
{
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;
}