Refactor and simplify wxChoice::DoGetBestSize().

Use wxTextMeasure instead of duplicating its code and also reuse the code
between different ports.

Closes #14706.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72848 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-11-01 17:15:28 +00:00
parent c236dbaed2
commit 7eb0acefc2
5 changed files with 42 additions and 80 deletions

View File

@@ -28,6 +28,8 @@
#include "wx/choice.h"
#include "wx/private/textmeasure.h"
#ifndef WX_PRECOMP
#endif
@@ -103,6 +105,21 @@ wxChoiceBase::~wxChoiceBase()
// this destructor is required for Darwin
}
wxSize wxChoiceBase::DoGetBestSize() const
{
// a reasonable width for an empty choice list
wxSize best(80, -1);
const unsigned int nItems = GetCount();
if ( nItems > 0 )
{
wxTextMeasure txm(this);
best.x = txm.GetLargestStringExtent(GetStrings()).x;
}
return best;
}
// ----------------------------------------------------------------------------
// misc
// ----------------------------------------------------------------------------