From dc2ff0d6b42b93dc84b886571bc6008393721f1e Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sat, 30 Apr 2022 20:34:28 +0200 Subject: [PATCH] wxOSX: Rewiring GetBestSize for single line text control again see #22374 --- include/wx/osx/cocoa/private/textimpl.h | 3 +++ src/osx/cocoa/textctrl.mm | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/wx/osx/cocoa/private/textimpl.h b/include/wx/osx/cocoa/private/textimpl.h index bc1112f1c3..a2783759d9 100644 --- a/include/wx/osx/cocoa/private/textimpl.h +++ b/include/wx/osx/cocoa/private/textimpl.h @@ -85,6 +85,9 @@ public : virtual bool GetNewLineReplacement() wxOVERRIDE; virtual void SetInternalSelection( long from , long to ); virtual void UpdateInternalSelectionFromEditor( wxNSTextFieldEditor* editor); + + virtual wxSize GetBestSize() const wxOVERRIDE; + protected : NSTextField* m_textField; long m_selStart; diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 528ee0b32f..0b772c0afd 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -1713,6 +1713,22 @@ void wxNSTextFieldControl::SetJustification() [m_textField setAlignment:align]; } +wxSize wxNSTextFieldControl::GetBestSize() const +{ + wxSize sz = wxDefaultSize; + if ( [m_textField respondsToSelector:@selector(sizeToFit)] ) + { + NSRect former = [m_textField frame]; + [m_textField sizeToFit]; + NSRect best = [m_textField frame]; + [m_textField setFrame:former]; + sz.x = (int)ceil(best.size.width); + sz.y = (int)ceil(best.size.height); + } + + return sz; +} + // // //