From 358e42a829b5181369e08d36244c8273c50bb15f Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Wed, 23 Dec 2015 17:55:16 +0100 Subject: [PATCH] Fix drawing bitmap in the selection field of wxBitmapComboBox When drop-down list is open for wxBitmapComboBox with wxCB_READONLY style and keyboard is used to select the item on the list then the contents of the selection field should remain unchanged. (Especially, the bitmap bitmap drawn in the selection field should be the bitmap associated with text value displayed in this field.) Closes #17299. --- src/msw/bmpcbox.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/msw/bmpcbox.cpp b/src/msw/bmpcbox.cpp index 35665f61d5..124b9b78f1 100644 --- a/src/msw/bmpcbox.cpp +++ b/src/msw/bmpcbox.cpp @@ -481,22 +481,30 @@ bool wxBitmapComboBox::MSWOnDraw(WXDRAWITEMSTRUCT *item) if ( lpDrawItem->itemState & ODS_SELECTED ) flags |= wxODCB_PAINTING_SELECTED; + wxPaintDCEx dc(this, lpDrawItem->hDC); + wxRect rect = wxRectFromRECT(lpDrawItem->rcItem); + wxBitmapComboBoxBase::DrawBackground(dc, rect, pos, flags); + wxString text; if ( flags & wxODCB_PAINTING_CONTROL ) { - text = GetValue(); + // Don't draw anything in the editable selection field. if ( !HasFlag(wxCB_READONLY) ) - text.clear(); + return true; + + pos = GetSelection(); + // Skip drawing if there is nothing selected. + if ( pos < 0 ) + return true; + + text = GetValue(); } else { text = GetString(pos); } - wxPaintDCEx dc(this, lpDrawItem->hDC); - wxRect rect = wxRectFromRECT(lpDrawItem->rcItem); - wxBitmapComboBoxBase::DrawBackground(dc, rect, pos, flags); wxBitmapComboBoxBase::DrawItem(dc, rect, pos, text, flags); // If the item has the focus, draw focus rectangle.