From 606dc18e5fda93a8ffb741d96e8e84b0856608fc Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Wed, 15 Aug 2018 21:51:33 +0200 Subject: [PATCH] Don't switch NSCell to single-line mode (wxOSX) NSCell of a single-line wxTextCtrl cannot be just switched to the single-line mode because apart from restricting layout to a single line this also effectively blocks processing of the Return key. To restrict the contents of the cell to a single line we need to replace in wxTextEntryFormatter every new line character with space (this simulates what is done when NSCell works in native single-line mode). Closes #18183. Closes #18179. Closes #18101. See #12693. --- src/osx/cocoa/textctrl.mm | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 18aa408e72..dfab030e94 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -148,7 +148,7 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; forceUpper = true; } -- (NSString *)stringForObjectValue:(id)anObject +- (NSString *)stringForObjectValue:(id)anObject { if(![anObject isKindOfClass:[NSString class]]) return nil; @@ -173,14 +173,16 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil; } } - if ( forceUpper ) + // wxTextEntryFormatter is always associated with single-line text entry (through wxNSTextFieldControl) + // so all new line characters should be replaced with spaces (like it is done in single-line NSCell). + NSString* lineStr = [*partialStringPtr stringByReplacingOccurrencesOfString: @"\n" withString: @" "]; + + NSString* newStr = forceUpper ? [lineStr uppercaseString] : lineStr; + + if ( ![*partialStringPtr isEqual:newStr] ) { - NSString* upper = [*partialStringPtr uppercaseString]; - if ( ![*partialStringPtr isEqual:upper] ) - { - *partialStringPtr = upper; - return NO; - } + *partialStringPtr = newStr; + return NO; } return YES; @@ -1190,6 +1192,8 @@ void wxNSTextFieldControl::Init(WXWidget w) [m_textField setDelegate: tf]; m_selStart = m_selEnd = 0; m_hasEditor = [w isKindOfClass:[NSTextField class]]; + + GetFormatter(); // we always need to at least replace new line characters with spaces } wxNSTextFieldControl::~wxNSTextFieldControl() @@ -1470,7 +1474,6 @@ void wxNSTextFieldControl::SetJustification() // // // - wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer, wxWindowMac* WXUNUSED(parent), wxWindowID WXUNUSED(id), @@ -1508,10 +1511,11 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer, } NSTextFieldCell* cell = [v cell]; - [cell setUsesSingleLineMode:YES]; + [cell setWraps:NO]; + [cell setScrollable:YES]; c = new wxNSTextFieldControl( wxpeer, wxpeer, v ); - + if ( (style & wxNO_BORDER) || (style & wxSIMPLE_BORDER) ) { // under 10.7 the textcontrol can draw its own focus