From a1c9e7d14361e300b628757d59ba8aee8b008e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Wed, 13 Jul 2011 08:32:17 +0000 Subject: [PATCH] Better sizing in wxDataViewSpinRenderer and wxDataViewChoiceRenderer. Their GetSize() method used hardcoded size of (80,16). Instead, use GetTextExtent() to compute the size from content, as should be done. Add some extra room for editor control's extra parts. The space needed isn't computed exactly, as that would be quite convoluted (and in the end, most likely not 100% accurate even then), using a simple approximation instead. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68242 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/datavcmn.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 8e2469c228..57c175af8c 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -1456,7 +1456,15 @@ bool wxDataViewSpinRenderer::Render( wxRect rect, wxDC *dc, int state ) wxSize wxDataViewSpinRenderer::GetSize() const { - return wxSize(80,16); + wxSize sz = GetTextExtent(wxString::Format("%d", (int)m_data)); + + // Allow some space for the spin buttons, which is approximately the size + // of a scrollbar (and getting pixel-exact value would be complicated). + // Also add some whitespace between the text and the button: + sz.x += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); + sz.x += GetTextExtent("M").x; + + return sz; } bool wxDataViewSpinRenderer::SetValue( const wxVariant &value ) @@ -1514,7 +1522,18 @@ bool wxDataViewChoiceRenderer::Render( wxRect rect, wxDC *dc, int state ) wxSize wxDataViewChoiceRenderer::GetSize() const { - return wxSize(80,16); + wxSize sz; + + for ( wxArrayString::const_iterator i = m_choices.begin(); i != m_choices.end(); ++i ) + sz.IncTo(GetTextExtent(*i)); + + // Allow some space for the right-side button, which is approximately the + // size of a scrollbar (and getting pixel-exact value would be complicated). + // Also add some whitespace between the text and the button: + sz.x += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); + sz.x += GetTextExtent("M").x; + + return sz; } bool wxDataViewChoiceRenderer::SetValue( const wxVariant &value )