From ce22ac4592fccaedd8324e7a8f08b510748827e4 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 19 Sep 2006 17:16:50 +0000 Subject: [PATCH] 1552971 ] Add flag for wxODComboBox::OnDrawItem to indicate selection git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41305 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/odcombo.h | 9 ++++++++- samples/combo/combo.cpp | 3 +-- samples/widgets/odcombobox.cpp | 3 +-- src/generic/odcombo.cpp | 35 ++++++++++++++++++++++------------ 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/include/wx/odcombo.h b/include/wx/odcombo.h index c187957c31..d5baadcc36 100644 --- a/include/wx/odcombo.h +++ b/include/wx/odcombo.h @@ -44,7 +44,14 @@ enum { // when set, we are painting the selected item in control, // not in the popup - wxODCB_PAINTING_CONTROL = 0x0001 + wxODCB_PAINTING_CONTROL = 0x0001, + + + // when set, we are painting an item which should have + // focus rectangle painted in the background. Text colour + // and clipping region are then appropriately set in + // the default OnDrawBackground implementation. + wxODCB_PAINTING_SELECTED = 0x0002 }; diff --git a/samples/combo/combo.cpp b/samples/combo/combo.cpp index 5f8e7fea59..5977bc9661 100644 --- a/samples/combo/combo.cpp +++ b/samples/combo/combo.cpp @@ -230,8 +230,7 @@ public: // If item is selected or even, or we are painting the // combo control itself, use the default rendering. - if ( GetVListBoxComboPopup()->IsCurrent((size_t)item) || - (flags & wxODCB_PAINTING_CONTROL) || + if ( (flags & (wxODCB_PAINTING_CONTROL|wxODCB_PAINTING_SELECTED)) || (item & 1) == 0 ) { wxOwnerDrawnComboBox::OnDrawBackground(dc,rect,item,flags); diff --git a/samples/widgets/odcombobox.cpp b/samples/widgets/odcombobox.cpp index 92823d895d..ee531cfa94 100644 --- a/samples/widgets/odcombobox.cpp +++ b/samples/widgets/odcombobox.cpp @@ -264,8 +264,7 @@ public: // If item is selected or even, or we are painting the // combo control itself, use the default rendering. - if ( GetVListBoxComboPopup()->IsCurrent((size_t)item) || - (flags & wxODCB_PAINTING_CONTROL) || + if ( (flags & (wxODCB_PAINTING_CONTROL|wxODCB_PAINTING_SELECTED)) || (item & 1) == 0 ) { wxOwnerDrawnComboBox::OnDrawBackground(dc,rect,item,flags); diff --git a/src/generic/odcombo.cpp b/src/generic/odcombo.cpp index cccd7660f1..5f3f732a19 100644 --- a/src/generic/odcombo.cpp +++ b/src/generic/odcombo.cpp @@ -107,7 +107,13 @@ void wxVListBoxComboPopup::PaintComboControl( wxDC& dc, const wxRect& rect ) { if ( !(m_combo->GetWindowStyle() & wxODCB_STD_CONTROL_PAINT) ) { - OnDrawBg(dc,rect,m_value,wxODCB_PAINTING_CONTROL); + int flags = wxODCB_PAINTING_CONTROL; + + if ( m_combo->ShouldDrawFocus() ) + flags |= wxODCB_PAINTING_SELECTED; + + OnDrawBg(dc, rect, m_value, flags); + if ( m_value >= 0 ) { OnDrawItem(dc,rect,m_value,wxODCB_PAINTING_CONTROL); @@ -165,6 +171,9 @@ void wxVListBoxComboPopup::OnDrawBg( wxDC& dc, wxASSERT_MSG( combo->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)), wxT("you must subclass wxVListBoxComboPopup for drawing and measuring methods") ); + if ( IsCurrent((size_t)item) && !(flags & wxODCB_PAINTING_CONTROL) ) + flags |= wxODCB_PAINTING_SELECTED; + combo->OnDrawBackground(dc,rect,item,flags); } @@ -1053,23 +1062,25 @@ wxCoord wxOwnerDrawnComboBox::OnMeasureItemWidth( size_t WXUNUSED(item) ) const return -1; } -void wxOwnerDrawnComboBox::OnDrawBackground(wxDC& dc, const wxRect& rect, int item, int flags) const +void wxOwnerDrawnComboBox::OnDrawBackground(wxDC& dc, + const wxRect& rect, + int WXUNUSED(item), + int flags) const { - // we need to render selected and current items differently - if ( GetVListBoxComboPopup()->IsCurrent((size_t)item) || - (flags & wxODCB_PAINTING_CONTROL) ) + // We need only to explicitly draw background for items + // that should have selected background. Also, call PrepareBackground + // always when painting the control so that clipping is done properly. + + if ( (flags & wxODCB_PAINTING_SELECTED) || + ((flags & wxODCB_PAINTING_CONTROL) && HasFlag(wxCB_READONLY)) ) { int bgFlags = wxCONTROL_SELECTED; - if ( (flags & wxODCB_PAINTING_CONTROL) != wxODCB_PAINTING_CONTROL ) - { + if ( !(flags & wxODCB_PAINTING_CONTROL) ) bgFlags |= wxCONTROL_ISSUBMENU; - PrepareBackground(dc, rect, bgFlags); - } - else if ( HasFlag(wxCB_READONLY) ) - PrepareBackground(dc, rect, bgFlags); + + PrepareBackground(dc, rect, bgFlags); } - //else: do nothing for the normal items } #endif // wxUSE_ODCOMBOBOX -- 2.45.2