From 29f54b9b37c49eccd2f1a5e5649dfee5a0c949b9 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 23 Nov 2001 19:43:02 +0000 Subject: [PATCH] implemented GetBestSize() for wxChoice git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12628 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/choice.cpp | 26 +++++++++++++++++++++++++- src/gtk1/choice.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/gtk/choice.cpp b/src/gtk/choice.cpp index 0106c68dff..ca9d9c1785 100644 --- a/src/gtk/choice.cpp +++ b/src/gtk/choice.cpp @@ -407,7 +407,31 @@ size_t wxChoice::GtkAppendHelper(GtkWidget *menu, const wxString& item) wxSize wxChoice::DoGetBestSize() const { wxSize ret( wxControl::DoGetBestSize() ); - if (ret.x < 80) ret.x = 80; + + // we know better our horizontal extent: it depends on the longest string + // we have + ret.x = 0; + if ( m_widget ) + { + GdkFont *font = m_font.GetInternalFont(); + + wxCoord width; + size_t count = GetCount(); + for ( size_t n = 0; n < count; n++ ) + { + width = (wxCoord)gdk_string_width(font, GetString(n).mbc_str()); + if ( width > ret.x ) + ret.x = width; + } + + // for the choice "=" button + ret.x += 20; + } + + // but not less than the minimal width + if ( ret.x < 80 ) + ret.x = 80; + ret.y = 16 + gdk_char_height( m_widget->style->font, 'H' ); return ret; } diff --git a/src/gtk1/choice.cpp b/src/gtk1/choice.cpp index 0106c68dff..ca9d9c1785 100644 --- a/src/gtk1/choice.cpp +++ b/src/gtk1/choice.cpp @@ -407,7 +407,31 @@ size_t wxChoice::GtkAppendHelper(GtkWidget *menu, const wxString& item) wxSize wxChoice::DoGetBestSize() const { wxSize ret( wxControl::DoGetBestSize() ); - if (ret.x < 80) ret.x = 80; + + // we know better our horizontal extent: it depends on the longest string + // we have + ret.x = 0; + if ( m_widget ) + { + GdkFont *font = m_font.GetInternalFont(); + + wxCoord width; + size_t count = GetCount(); + for ( size_t n = 0; n < count; n++ ) + { + width = (wxCoord)gdk_string_width(font, GetString(n).mbc_str()); + if ( width > ret.x ) + ret.x = width; + } + + // for the choice "=" button + ret.x += 20; + } + + // but not less than the minimal width + if ( ret.x < 80 ) + ret.x = 80; + ret.y = 16 + gdk_char_height( m_widget->style->font, 'H' ); return ret; } -- 2.45.2