From 0662f99096f665089e23dc7d342ac85ceb72f9e3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 22 May 2008 00:55:59 +0000 Subject: [PATCH] add back wxChoice::DoGetBestSize() removed by the previous refactoring, it's still needed (#9150) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53698 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/choice.h | 1 + src/gtk/choice.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/wx/gtk/choice.h b/include/wx/gtk/choice.h index 478a15ce09..6da310248b 100644 --- a/include/wx/gtk/choice.h +++ b/include/wx/gtk/choice.h @@ -85,6 +85,7 @@ protected: // contains the client data for the items wxArrayPtrVoid m_clientData; + virtual wxSize DoGetBestSize() const; virtual int DoInsertItems(const wxArrayStringsAdapter& items, unsigned int pos, void **clientData, wxClientDataType type); diff --git a/src/gtk/choice.cpp b/src/gtk/choice.cpp index 9eefcf06da..4fbc3417c0 100644 --- a/src/gtk/choice.cpp +++ b/src/gtk/choice.cpp @@ -314,6 +314,37 @@ GdkWindow *wxChoice::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const return m_widget->window; } +// Notice that this method shouldn't be necessary, because GTK calculates +// properly size of the combobox but for unknown reasons it doesn't work +// correctly in wx without this. +wxSize wxChoice::DoGetBestSize() const +{ + // strangely, this returns a width of 188 pixels from GTK+ (?) + wxSize ret( wxControl::DoGetBestSize() ); + + // we know better our horizontal extent: it depends on the longest string + // in the combobox + if ( m_widget ) + { + ret.x = 60; // start with something "sensible" + int width; + unsigned int count = GetCount(); + for ( unsigned int n = 0; n < count; n++ ) + { + GetTextExtent(GetString(n), &width, NULL, NULL, NULL ); + if ( width + 40 > ret.x ) // 40 for drop down arrow and space around text + ret.x = width + 40; + } + } + + // empty combobox should have some reasonable default size too + if ((GetCount() == 0) && (ret.x < 80)) + ret.x = 80; + + CacheBestSize(ret); + return ret; +} + // static wxVisualAttributes wxChoice::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) -- 2.45.2