Remember wxBitmapComboBox selection when recreating the control

Recreate the control with the correct height when adding the first item with bitmap.
This commit is contained in:
Maarten Bent
2019-09-28 23:00:33 +02:00
parent 092d507714
commit 459ffcff61

View File

@@ -127,6 +127,7 @@ void wxBitmapComboBox::RecreateControl()
// mouse-wheel behaviour. // mouse-wheel behaviour.
// //
wxString value = GetValue(); wxString value = GetValue();
int selection = GetSelection();
wxPoint pos = GetPosition(); wxPoint pos = GetPosition();
wxSize size = GetSize(); wxSize size = GetSize();
size.y = GetBestSize().y; size.y = GetBestSize().y;
@@ -210,6 +211,8 @@ void wxBitmapComboBox::RecreateControl()
// Revert the old string value // Revert the old string value
if ( !HasFlag(wxCB_READONLY) ) if ( !HasFlag(wxCB_READONLY) )
ChangeValue(value); ChangeValue(value);
else if ( selection != wxNOT_FOUND )
SetSelection(selection);
// If disabled we'll have to disable it again after re-creating // If disabled we'll have to disable it again after re-creating
if ( !IsEnabled() ) if ( !IsEnabled() )
@@ -407,7 +410,7 @@ int wxBitmapComboBox::DoInsertItems(const wxArrayStringsAdapter & items,
bool wxBitmapComboBox::OnAddBitmap(const wxBitmap& bitmap) bool wxBitmapComboBox::OnAddBitmap(const wxBitmap& bitmap)
{ {
if ( wxBitmapComboBoxBase::OnAddBitmap(bitmap) ) if ( wxBitmapComboBoxBase::OnAddBitmap(bitmap) || !GetCount() )
{ {
// Need to recreate control for a new measureitem call? // Need to recreate control for a new measureitem call?
int prevItemHeight = ::SendMessage(GetHwnd(), CB_GETITEMHEIGHT, 0, 0); int prevItemHeight = ::SendMessage(GetHwnd(), CB_GETITEMHEIGHT, 0, 0);