From 8e0799e3e52b8b34f6fb10912dd12df4ee825a75 Mon Sep 17 00:00:00 2001 From: mj_smoker Date: Sat, 18 Jul 2015 01:45:12 +0200 Subject: [PATCH] Handle wxTE_PROCESS_ENTER with wxTE_PASSWORD correctly in wxOSX. Controls with wxTE_PASSWORD style didn't send wxEVT_TEXT_ENTER even if they also had wxTE_PROCESS_ENTER. Fix this by checking for the latter style before mapping the enter presses to default button activation. See #14930. --- src/osx/cocoa/textctrl.mm | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index f50b76a738..e4c6567bb9 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -213,17 +213,29 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; { if (commandSelector == @selector(insertNewline:)) { - wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(wxpeer), wxTopLevelWindow); - if ( tlw && tlw->GetDefaultItem() ) + if ( wxpeer->GetWindowStyle() & wxTE_PROCESS_ENTER ) { - wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton); - if ( def && def->IsEnabled() ) + wxCommandEvent event(wxEVT_TEXT_ENTER, wxpeer->GetId()); + event.SetEventObject( wxpeer ); + wxTextWidgetImpl* impl = (wxNSTextFieldControl * ) wxWidgetImpl::FindFromWXWidget( self ); + wxTextEntry * const entry = impl->GetTextEntry(); + event.SetString( entry->GetValue() ); + handled = wxpeer->HandleWindowEvent( event ); + } + else + { + wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(wxpeer), wxTopLevelWindow); + if ( tlw && tlw->GetDefaultItem() ) { - wxCommandEvent event(wxEVT_BUTTON, def->GetId() ); - event.SetEventObject(def); - def->Command(event); - handled = YES; - } + wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton); + if ( def && def->IsEnabled() ) + { + wxCommandEvent event(wxEVT_BUTTON, def->GetId() ); + event.SetEventObject(def); + def->Command(event); + handled = YES; + } + } } } }