Make wxGridCellChoiceEditor big enough in both directions

Previously, we ensured that the combobox was tall enough, but not that
it was wide enough, which could result in truncation of its contents if
the cell rectangle was too small.

Fix this by increasing the size in both directions, if necessary.

Also make the code simpler by using higher-level wxSize and wxRect
methods instead of fiddling with the coordinates directly.
This commit is contained in:
Vadim Zeitlin
2020-06-13 17:29:20 +02:00
parent d2a403408f
commit 585ed986a2

View File

@@ -1451,22 +1451,12 @@ void wxGridCellChoiceEditor::SetSize(const wxRect& rect)
wxASSERT_MSG(m_control, wxASSERT_MSG(m_control,
wxT("The wxGridCellChoiceEditor must be created first!")); wxT("The wxGridCellChoiceEditor must be created first!"));
// Check that the height is not too small to fit the combobox. // Check that the rectangle is big enough to fit the combobox, we can't
wxRect rectTallEnough = rect; // afford truncating it.
const wxSize bestSize = m_control->GetBestSize(); wxSize size = rect.GetSize();
const wxCoord diffY = bestSize.GetHeight() - rectTallEnough.GetHeight(); size.IncTo(m_control->GetBestSize());
if ( diffY > 0 )
{
// Do make it tall enough.
rectTallEnough.height += diffY;
// Also centre the effective rectangle vertically with respect to the wxGridCellEditor::SetSize(wxRect(size).CentreIn(rect));
// original one.
rectTallEnough.y -= diffY/2;
}
//else: The rectangle provided is already tall enough.
wxGridCellEditor::SetSize(rectTallEnough);
} }
void wxGridCellChoiceEditor::PaintBackground(wxDC& dc, void wxGridCellChoiceEditor::PaintBackground(wxDC& dc,