improve best height calculation for empty listbox [backport of r52927 from trunk]

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@52940 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-03-31 16:39:53 +00:00
parent 697d268c05
commit 5ca19fa62c

View File

@@ -1027,21 +1027,20 @@ wxSize wxListBox::DoGetBestSize() const
// Start with a minimum size that's not too small // Start with a minimum size that's not too small
int cx, cy; int cx, cy;
GetTextExtent( wxT("X"), &cx, &cy); GetTextExtent( wxT("X"), &cx, &cy);
int lbWidth = 3 * cx; int lbWidth = 0;
int lbHeight = 10; int lbHeight = 10;
// Get the visible area of the tree view (limit to the 10th item // Find the widest string.
// so that it isn't too big) const unsigned int count = GetCount();
unsigned int count = GetCount(); if ( count )
if (count)
{ {
int wLine; int wLine;
for ( unsigned int i = 0; i < count; i++ )
// Find the widest line {
for(unsigned int i = 0; i < count; i++) { GetTextExtent(GetString(i), &wLine, NULL);
wxString str(GetString(i)); if ( wLine > lbWidth )
GetTextExtent(str, &wLine, NULL); lbWidth = wLine;
lbWidth = wxMax(lbWidth, wLine); }
} }
lbWidth += 3 * cx; lbWidth += 3 * cx;
@@ -1056,14 +1055,12 @@ wxSize wxListBox::DoGetBestSize() const
} }
#endif #endif
// don't make the listbox too tall (limit height to around 10 items) but don't
// make it too small neither
lbHeight = (cy+4) * wxMin(wxMax(count, 3), 10);
}
// Add room for the scrollbar // Add room for the scrollbar
lbWidth += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); lbWidth += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
// Don't make the listbox too tall but don't make it too small neither
lbHeight = (cy+4) * wxMin(wxMax(count, 3), 10);
wxSize best(lbWidth, lbHeight); wxSize best(lbWidth, lbHeight);
CacheBestSize(best); CacheBestSize(best);
return best; return best;