From 0724bc9a5ab73d70e78d87ed2abb1c05696acdc1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 18 Oct 2015 22:15:40 +0200 Subject: [PATCH] Fix best size for non-left aligned wxStaticText in wxGTK2 Since the hack for making the alignment work with GTK+ 2 done in 4ae21c7f1aa5c5339fab45c270dfd5048457bb99, the best size was not computed correctly for the right aligned or centered labels and the minimum possible size was returned instead. Fix this by temporarily disabling ellipsization during the best size computation to ensure that the same best size is computed for left and right aligned labels. See #12539. --- src/gtk/stattext.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/gtk/stattext.cpp b/src/gtk/stattext.cpp index c2838b7a15..5d9ffce8e3 100644 --- a/src/gtk/stattext.cpp +++ b/src/gtk/stattext.cpp @@ -236,11 +236,20 @@ wxSize wxStaticText::DoGetBestSize() const gtk_label_set_line_wrap(GTK_LABEL(m_widget), false); #else GTK_LABEL(m_widget)->wrap = FALSE; + + // Reset the ellipsize mode while computing the best size, otherwise it's + // going to be too small as the control knows that it can be shrunk to the + // bare minimum and just hide most of the text replacing it with ellipsis. + // This is especially important because we can enable ellipsization + // implicitly for GTK+ 2, see the code dealing with alignment in the ctor. + const PangoEllipsizeMode ellipsizeMode = gtk_label_get_ellipsize(GTK_LABEL(m_widget)); + gtk_label_set_ellipsize(GTK_LABEL(m_widget), PANGO_ELLIPSIZE_NONE); #endif wxSize size = wxStaticTextBase::DoGetBestSize(); #ifdef __WXGTK3__ gtk_label_set_line_wrap(GTK_LABEL(m_widget), true); #else + gtk_label_set_ellipsize(GTK_LABEL(m_widget), ellipsizeMode); GTK_LABEL(m_widget)->wrap = TRUE; // restore old value #endif