From 31a672b858f5a30548a4f236eb06146b582ea5ce Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Thu, 4 Jan 2024 12:11:50 -0800 Subject: [PATCH] Improve our best size calculation for multi-line wxTextCtrl with GTK Instead of trying to figure it out ourselves, just ask the control what its minimum size is. --- src/gtk/textctrl.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 6fad82910c..bcfd30895b 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -2153,24 +2153,13 @@ wxSize wxTextCtrl::DoGetSizeFromTextSize(int xlen, int ylen) const //multiline else { - // add space for vertical scrollbar - if ( m_scrollBar[1] && !(m_windowStyle & wxTE_NO_VSCROLL) ) - tsize.IncBy(GTKGetPreferredSize(GTK_WIDGET(m_scrollBar[1])).x + 3, 0); - // height if ( ylen <= 0 ) - { tsize.y = 1 + cHeight * wxMax(wxMin(GetNumberOfLines(), 10), 2); - // add space for horizontal scrollbar - if ( m_scrollBar[0] && (m_windowStyle & wxHSCROLL) ) - tsize.IncBy(0, GTKGetPreferredSize(GTK_WIDGET(m_scrollBar[0])).y + 3); - } - if ( !HasFlag(wxBORDER_NONE) ) - { - // hardcode borders, margins, etc - tsize.IncBy(5, 4); - } + GtkRequisition req; + gtk_widget_get_preferred_size(m_widget, &req, nullptr); + tsize.IncTo(wxSize(req.width, req.height)); } // We should always use at least the specified height if it's valid.