From: Robert Roebling Date: Sun, 3 Sep 2006 13:21:29 +0000 (+0000) Subject: Commit wxComboCtrl clipping patch from J. Salli X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/118f5fbd0651e6c610a44a42a41dcf93439e820d Commit wxComboCtrl clipping patch from J. Salli git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40980 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/combo.h b/include/wx/combo.h index ec19e490d1..6fb77bd0c3 100644 --- a/include/wx/combo.h +++ b/include/wx/combo.h @@ -305,7 +305,9 @@ public: // key handler). virtual bool IsKeyPopupToggle(const wxKeyEvent& event) const = 0; - // Draws focus background (on combo control) in a way typical on platform. + // Prepare background of combo control or an item in a dropdown list + // in a way typical on platform. This includes painting the focus/disabled + // background and setting the clipping region. // Unless you plan to paint your own focus indicator, you should always call this // in your wxComboPopup::PaintComboControl implementation. // In addition, it sets pen and text colour to what looks good and proper @@ -313,7 +315,7 @@ public: // flags: wxRendererNative flags: wxCONTROL_ISSUBMENU: is drawing a list item instead of combo control // wxCONTROL_SELECTED: list item is selected // wxCONTROL_DISABLED: control/item is disabled - virtual void DrawFocusBackground( wxDC& dc, const wxRect& rect, int flags ) const; + virtual void PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const; // Returns true if focus indicator should be drawn in the control. bool ShouldDrawFocus() const diff --git a/include/wx/msw/combo.h b/include/wx/msw/combo.h index 5c02285db6..1147db76e9 100644 --- a/include/wx/msw/combo.h +++ b/include/wx/msw/combo.h @@ -59,7 +59,7 @@ public: virtual ~wxComboCtrl(); - virtual void DrawFocusBackground( wxDC& dc, const wxRect& rect, int flags ) const; + virtual void PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const; virtual bool IsKeyPopupToggle(const wxKeyEvent& event) const; static int GetFeatures() { return wxComboCtrlFeatures::All; } diff --git a/src/common/combocmn.cpp b/src/common/combocmn.cpp index fbad327842..0157152551 100644 --- a/src/common/combocmn.cpp +++ b/src/common/combocmn.cpp @@ -386,7 +386,7 @@ void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase* combo, { if ( combo->GetWindowStyle() & wxCB_READONLY ) // ie. no textctrl { - combo->DrawFocusBackground(dc,rect,0); + combo->PrepareBackground(dc,rect,0); dc.DrawText( combo->GetValue(), rect.x + combo->GetTextIndent(), @@ -1036,8 +1036,9 @@ void wxComboCtrlBase::DoSetToolTip(wxToolTip *tooltip) // painting // ---------------------------------------------------------------------------- -// draw focus background on area in a way typical on platform -void wxComboCtrlBase::DrawFocusBackground( wxDC& dc, const wxRect& rect, int flags ) const +#if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__) +// prepare combo box background on area in a way typical on platform +void wxComboCtrlBase::PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const { wxSize sz = GetClientSize(); bool isEnabled; @@ -1106,7 +1107,19 @@ void wxComboCtrlBase::DrawFocusBackground( wxDC& dc, const wxRect& rect, int fla dc.SetBrush( bgCol ); dc.SetPen( bgCol ); dc.DrawRectangle( selRect ); + + // Don't clip exactly to the selection rectangle so we can draw + // to the non-selected area in front of it. + wxRect clipRect(rect.x,rect.y, + (selRect.x+selRect.width)-rect.x,rect.height); + dc.SetClippingRegion(clipRect); } +#else +// Save the library size a bit for platforms that re-implement this. +void wxComboCtrlBase::PrepareBackground( wxDC&, const wxRect&, int ) const +{ +} +#endif void wxComboCtrlBase::DrawButton( wxDC& dc, const wxRect& rect, bool paintBg ) { diff --git a/src/generic/odcombo.cpp b/src/generic/odcombo.cpp index 8e83c45616..cccd7660f1 100644 --- a/src/generic/odcombo.cpp +++ b/src/generic/odcombo.cpp @@ -1059,12 +1059,15 @@ void wxOwnerDrawnComboBox::OnDrawBackground(wxDC& dc, const wxRect& rect, int it if ( GetVListBoxComboPopup()->IsCurrent((size_t)item) || (flags & wxODCB_PAINTING_CONTROL) ) { - int focusFlag = wxCONTROL_SELECTED; + int bgFlags = wxCONTROL_SELECTED; if ( (flags & wxODCB_PAINTING_CONTROL) != wxODCB_PAINTING_CONTROL ) - focusFlag |= wxCONTROL_ISSUBMENU; - - DrawFocusBackground(dc, rect, focusFlag ); + { + bgFlags |= wxCONTROL_ISSUBMENU; + PrepareBackground(dc, rect, bgFlags); + } + else if ( HasFlag(wxCB_READONLY) ) + PrepareBackground(dc, rect, bgFlags); } //else: do nothing for the normal items } diff --git a/src/msw/combo.cpp b/src/msw/combo.cpp index 124204b43f..50025b1eed 100644 --- a/src/msw/combo.cpp +++ b/src/msw/combo.cpp @@ -239,7 +239,7 @@ static void wxMSWDrawFocusRect( wxDC& dc, const wxRect& rect ) } // draw focus background on area in a way typical on platform -void wxComboCtrl::DrawFocusBackground( wxDC& dc, const wxRect& rect, int flags ) const +void wxComboCtrl::PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const { wxUxThemeEngine* theme = (wxUxThemeEngine*) NULL; @@ -376,6 +376,11 @@ void wxComboCtrl::DrawFocusBackground( wxDC& dc, const wxRect& rect, int flags ) if ( drawDottedEdge ) wxMSWDrawFocusRect(dc,selRect); + // Don't clip exactly to the selection rectangle so we can draw + // to the non-selected area in front of it. + wxRect clipRect(rect.x,rect.y, + (selRect.x+selRect.width)-rect.x-1,rect.height); + dc.SetClippingRegion(clipRect); } void wxComboCtrl::OnPaintEvent( wxPaintEvent& WXUNUSED(event) )