Make multiline controls 5 lines high by default under Mac

This is consistent with the current behaviour of GetSizeFromTextSize()
and the behaviour of GetBestSize() before the changes in this branch.

This is still not consistent with the behaviour of the other ports, but
this will be addressed later, by replacing the currently hardcoded 5.

Note that calling usedRectForTextContainer: here was apparently wrong in
any case because we were not sure to have already performed a layout and
we should have had a call to ensureLayoutForTextContainer: before it to
make it actually work. However, this made it work "too well" because it
then correctly returned potentially very big sizes for the text controls
containing a lot of text, which is not what we need here, as explained
in the comment added by this commit.
This commit is contained in:
Vadim Zeitlin
2020-06-09 11:13:55 +02:00
parent 0458ad6c4a
commit e5ce18f0cb

View File

@@ -1222,13 +1222,25 @@ void wxNSTextViewControl::EnableAutomaticDashSubstitution(bool enable)
wxSize wxNSTextViewControl::GetBestSize() const
{
wxSize size;
if ( NSLayoutManager* const layoutManager = [m_textView layoutManager] )
{
NSRect rect = [layoutManager usedRectForTextContainer: [m_textView textContainer]];
return wxSize((int)(rect.size.width + [m_textView textContainerInset].width),
(int)(rect.size.height + [m_textView textContainerInset].height));
// We could have used usedRectForTextContainer: here to compute the
// total rectangle needed for the current text, but this is actually
// not too helpful for determining the best size of the control, as we
// don't always want to fit it to its text: e.g. if it contains 1000
// lines, we definitely don't want to make it higher than display.
//
// So instead we just get the height of a single line (which works for
// any non-empty control) and then multiply it by the number of lines
// we want to have by default, which is currently just hardcoded as 5
// for compatibility with the behaviour of the previous versions.
NSRect rect = [layoutManager lineFragmentRectForGlyphAtIndex: 0
effectiveRange: nil];
size.y = (int)(5*rect.size.height + [m_textView textContainerInset].height);
}
return wxSize(0,0);
return size;
}
void wxNSTextViewControl::SetJustification()