Fix setting alignment for wxOSX wxTextCtrl with wxTE_DONTWRAP

Don't make the controls with wxTE_DONTWRAP (a.k.a. wxHSCROLL) style
"infinitely" wide, but just "very" wide to allow alignment still work in it.

See #17529.
This commit is contained in:
Andreas Falkenhahn
2016-11-22 02:14:46 +01:00
committed by Vadim Zeitlin
parent dcb1229f41
commit d5c008da03
2 changed files with 10 additions and 2 deletions

View File

@@ -598,6 +598,13 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil;
// wxNSTextViewControl
// Official Apple docs suggest to use FLT_MAX when embedding an NSTextView
// object inside an NSScrollView, see here:
// https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/TextUILayer/Tasks/TextInScrollView.html
// However, when using FLT_MAX, "setAlignment" doesn't work any more; using
// 1000000 instead of FLT_MAX fixes this
#define MAX_WIDTH 1000000
wxNSTextViewControl::wxNSTextViewControl( wxTextCtrl *wxPeer, WXWidget w, long style )
: wxWidgetCocoaImpl(wxPeer, w),
wxTextWidgetImpl(wxPeer)
@@ -612,7 +619,7 @@ wxNSTextViewControl::wxNSTextViewControl( wxTextCtrl *wxPeer, WXWidget w, long s
NSSize contentSize = [m_scrollView contentSize];
NSRect viewFrame = NSMakeRect(
0, 0,
hasHScroll ? FLT_MAX : contentSize.width, contentSize.height
hasHScroll ? MAX_WIDTH : contentSize.width, contentSize.height
);
wxNSTextView* const tv = [[wxNSTextView alloc] initWithFrame: viewFrame];
@@ -623,7 +630,7 @@ wxNSTextViewControl::wxNSTextViewControl( wxTextCtrl *wxPeer, WXWidget w, long s
if ( hasHScroll )
{
[[tv textContainer] setContainerSize:NSMakeSize(FLT_MAX, FLT_MAX)];
[[tv textContainer] setContainerSize:NSMakeSize(MAX_WIDTH, MAX_WIDTH)];
[[tv textContainer] setWidthTracksTextView:NO];
}