From fd77020792cb52f491fee027c014676993de89b7 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Fri, 25 Jun 2021 11:32:42 +0200 Subject: [PATCH] Fix wxChoice with items too long to fit into it in wxGTK3 Enable ellipsization to show the items reasonably well even if they're too long to fit into the available space -- without this, just the tail of the long items was shown and shorter items could have been not shown at all, as only the blank part of their label was visible. Closes https://github.com/wxWidgets/wxWidgets/pull/2403 Co-Authored-By: Kent Tessman Co-Authored-By: Paul Cornett Co-Authored-By: Vadim Zeitlin --- src/gtk/choice.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/gtk/choice.cpp b/src/gtk/choice.cpp index 09aef7482f..76ecf8644f 100644 --- a/src/gtk/choice.cpp +++ b/src/gtk/choice.cpp @@ -18,6 +18,7 @@ #include "wx/gtk/private.h" #include "wx/gtk/private/eventsdisabler.h" +#include "wx/gtk/private/list.h" #include "wx/gtk/private/value.h" // ---------------------------------------------------------------------------- @@ -78,6 +79,17 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id, #ifdef __WXGTK3__ m_widget = gtk_combo_box_text_new(); + + // If any choices don't fit into the available space (in the always visible + // part of the control, not the dropdown), GTK shows just the tail of the + // string which does fit, which is bad for long strings and even worse for + // the shorter ones, as they may end up being shown as completely blank. + // Work around this brokenness by enabling ellipsization, especially as it + // seems to be safe to do it unconditionally, i.e. there doesn't seem to be + // any ill effects from having it on if everything does fit. + const wxGtkList cells(gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(m_widget))); + if (GTK_IS_CELL_RENDERER_TEXT(cells->data)) + g_object_set(G_OBJECT(cells->data), "ellipsize", PANGO_ELLIPSIZE_END, NULL); #else m_widget = gtk_combo_box_new_text(); #endif