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.
This commit is contained in:
Artur Wieczorek 2018-08-15 21:51:33 +02:00
parent 51de736a58
commit 606dc18e5f

View File

@ -148,7 +148,7 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil;
forceUpper = true; forceUpper = true;
} }
- (NSString *)stringForObjectValue:(id)anObject - (NSString *)stringForObjectValue:(id)anObject
{ {
if(![anObject isKindOfClass:[NSString class]]) if(![anObject isKindOfClass:[NSString class]])
return nil; 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]; *partialStringPtr = newStr;
if ( ![*partialStringPtr isEqual:upper] ) return NO;
{
*partialStringPtr = upper;
return NO;
}
} }
return YES; return YES;
@ -1190,6 +1192,8 @@ void wxNSTextFieldControl::Init(WXWidget w)
[m_textField setDelegate: tf]; [m_textField setDelegate: tf];
m_selStart = m_selEnd = 0; m_selStart = m_selEnd = 0;
m_hasEditor = [w isKindOfClass:[NSTextField class]]; m_hasEditor = [w isKindOfClass:[NSTextField class]];
GetFormatter(); // we always need to at least replace new line characters with spaces
} }
wxNSTextFieldControl::~wxNSTextFieldControl() wxNSTextFieldControl::~wxNSTextFieldControl()
@ -1470,7 +1474,6 @@ void wxNSTextFieldControl::SetJustification()
// //
// //
// //
wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer, wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
wxWindowMac* WXUNUSED(parent), wxWindowMac* WXUNUSED(parent),
wxWindowID WXUNUSED(id), wxWindowID WXUNUSED(id),
@ -1508,10 +1511,11 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
} }
NSTextFieldCell* cell = [v cell]; NSTextFieldCell* cell = [v cell];
[cell setUsesSingleLineMode:YES]; [cell setWraps:NO];
[cell setScrollable:YES];
c = new wxNSTextFieldControl( wxpeer, wxpeer, v ); c = new wxNSTextFieldControl( wxpeer, wxpeer, v );
if ( (style & wxNO_BORDER) || (style & wxSIMPLE_BORDER) ) if ( (style & wxNO_BORDER) || (style & wxSIMPLE_BORDER) )
{ {
// under 10.7 the textcontrol can draw its own focus // under 10.7 the textcontrol can draw its own focus