Implement wxComboCtrl::GetSizeFromTextSize().

Improve calculation of wxComboCtrl best size which doesn't work correctly for
non-default fonts as shown by r72935. It is still not perfect but better now.

Closes #14825.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72955 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-11-14 13:48:23 +00:00
parent aa24f946c6
commit e2ac737fba
6 changed files with 58 additions and 20 deletions

View File

@@ -725,6 +725,8 @@ void wxVListBoxComboPopup::CalcWidths()
// wxWindow::GetTextExtent (assuming same dc is used
// for all calls, as we do here).
wxClientDC dc(m_combo);
if ( !m_useFont.IsOk() )
m_useFont = m_combo->GetFont();
dc.SetFont(m_useFont);
for ( i=0; i<n; i++ )
@@ -1171,6 +1173,22 @@ wxCoord wxOwnerDrawnComboBox::OnMeasureItemWidth( size_t WXUNUSED(item) ) const
return -1;
}
wxSize wxOwnerDrawnComboBox::DoGetBestSize() const
{
wxSize best( wxComboCtrlBase::DoGetBestSize() );
if ( GetCount() > 0 )
{
wxOwnerDrawnComboBox* odc = const_cast<wxOwnerDrawnComboBox*>(this);
best.x = odc->GetWidestItemWidth();
// TODO: this class may also have GetHightestItemHeight() and
// GetHightestItem() methods, and so set the whole (edit part + arrow)
// control's height according with this max height, not only max width.
}
return GetSizeFromTextSize(best.x);
}
void wxOwnerDrawnComboBox::OnDrawBackground(wxDC& dc,
const wxRect& rect,
int WXUNUSED(item),