From 39cfbe3b94ee3c8b94b3b6defb8e284f4a651954 Mon Sep 17 00:00:00 2001 From: Steve Browne Date: Mon, 5 Jun 2017 01:16:23 -0400 Subject: [PATCH] Fire wxEVT_CHAR_HOOK and handle tab navigation for wxTextCtrls with wxTE_PASSWORD on wxOSX. --- src/osx/cocoa/textctrl.mm | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index b5a04570b1..50671a023d 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -277,6 +277,45 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; handled = YES; } } + else if (wxpeer->GetWindowStyle() & wxTE_PASSWORD) + { + // Make TAB and ESCAPE work on password fields. The general fix done in wxWidgetCocoaImpl::DoHandleKeyEvent() + // does not help for password fields because wxWidgetCocoaImpl::keyEvent() is not executed + // when TAB is pressed, only when it is released. + wxKeyEvent wxevent(wxEVT_KEY_DOWN); + if (commandSelector == @selector(insertTab:)) + { + wxevent.m_keyCode = WXK_TAB; + } + else if (commandSelector == @selector(insertBacktab:)) + { + wxevent.m_keyCode = WXK_TAB; + wxevent.SetShiftDown(true); + } + else if (commandSelector == @selector(selectNextKeyView:)) + { + wxevent.m_keyCode = WXK_TAB; + wxevent.SetRawControlDown(true); + } + else if (commandSelector == @selector(selectPreviousKeyView:)) + { + wxevent.m_keyCode = WXK_TAB; + wxevent.SetShiftDown(true); + wxevent.SetRawControlDown(true); + } + else if (commandSelector == @selector(cancelOperation:)) + { + wxevent.m_keyCode = WXK_ESCAPE; + } + if (wxevent.GetKeyCode() != WXK_NONE) + { + wxKeyEvent eventHook(wxEVT_CHAR_HOOK, wxevent); + if (wxpeer->OSXHandleKeyEvent(eventHook) && !eventHook.IsNextEventAllowed()) + handled = YES; + else if (impl->DoHandleKeyNavigation(wxevent)) + handled = YES; + } + } } }