From 6f7ea203f32ac48584905fa548babbd2025f0833 Mon Sep 17 00:00:00 2001 From: Corey Daley Date: Sun, 8 Nov 2015 12:23:39 -0500 Subject: [PATCH] Implement support for wxHSCROLL in wxTextCtrl under OS X Make the associated NSTextContainer of infinite size and tell it not to track the NSTextView width if wxHSCROLL is specified. Closes #4022. Closes https://github.com/wxWidgets/wxWidgets/pull/124 (cherry picked from commit a118c4243a5b1a5537ae244f1ae05d04a4399df2) --- src/osx/cocoa/textctrl.mm | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 358eda7954..75aa8ceb85 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -568,19 +568,28 @@ wxNSTextViewControl::wxNSTextViewControl( wxTextCtrl *wxPeer, WXWidget w, long s wxNSTextScrollView* sv = (wxNSTextScrollView*) w; m_scrollView = sv; - [m_scrollView setHasVerticalScroller:YES]; - [m_scrollView setHasHorizontalScroller:NO]; - // TODO Remove if no regression, this was causing automatic resizes of multi-line textfields when the tlw changed - // [m_scrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; - NSSize contentSize = [m_scrollView contentSize]; + const bool hasHScroll = (style & wxHSCROLL) != 0; - wxNSTextView* tv = [[wxNSTextView alloc] initWithFrame: NSMakeRect(0, 0, - contentSize.width, contentSize.height)]; + [m_scrollView setHasVerticalScroller:YES]; + [m_scrollView setHasHorizontalScroller:hasHScroll]; + NSSize contentSize = [m_scrollView contentSize]; + NSRect viewFrame = NSMakeRect( + 0, 0, + hasHScroll ? FLT_MAX : contentSize.width, contentSize.height + ); + + wxNSTextView* const tv = [[wxNSTextView alloc] initWithFrame: viewFrame]; m_textView = tv; [tv setVerticallyResizable:YES]; - [tv setHorizontallyResizable:NO]; + [tv setHorizontallyResizable:hasHScroll]; [tv setAutoresizingMask:NSViewWidthSizable]; + if ( hasHScroll ) + { + [[tv textContainer] setContainerSize:NSMakeSize(FLT_MAX, FLT_MAX)]; + [[tv textContainer] setWidthTracksTextView:NO]; + } + if ( style & wxTE_RIGHT) { [tv setAlignment:NSRightTextAlignment];