X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/98fbab9e7bf70ee8af44a78ea2a1d2cbb406880a..a3a8d81d487ae4f03d8b70bce20bddbfc48c5776:/src/msw/ownerdrw.cpp diff --git a/src/msw/ownerdrw.cpp b/src/msw/ownerdrw.cpp index 3c70d2408e..6fb88beabb 100644 --- a/src/msw/ownerdrw.cpp +++ b/src/msw/ownerdrw.cpp @@ -22,6 +22,7 @@ #include "wx/msw/dc.h" #include "wx/msw/private.h" #include "wx/msw/private/dc.h" +#include "wx/msw/wrapcctl.h" // for HIMAGELIST #ifndef DSS_HIDEPREFIX #define DSS_HIDEPREFIX 0x0200 @@ -45,50 +46,57 @@ bool wxOwnerDrawn::OnDrawItem(wxDC& dc, const wxRect& rc, if ( !IsOwnerDrawn() ) return true; - // set the font and colors - wxFont font; - GetFontToUse(font); - - wxColour colText, colBack; - GetColourToUse(stat, colText, colBack); - wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl(); HDC hdc = GetHdcOf(*impl); - SelectInHDC selFont(hdc, GetHfontOf(font)); + RECT rect; + wxCopyRectToRECT(rc, rect); + + { + // set the font and colors + wxFont font; + GetFontToUse(font); + + wxColour colText, colBack; + GetColourToUse(stat, colText, colBack); + + SelectInHDC selFont(hdc, GetHfontOf(font)); + + wxMSWImpl::wxTextColoursChanger textCol(hdc, colText, colBack); + wxMSWImpl::wxBkModeChanger bkMode(hdc, wxBRUSHSTYLE_TRANSPARENT); + - wxMSWImpl::wxTextColoursChanger textCol(hdc, colText, colBack); - wxMSWImpl::wxBkModeChanger bkMode(hdc, wxBRUSHSTYLE_TRANSPARENT); + AutoHBRUSH hbr(wxColourToPalRGB(colBack)); + SelectInHDC selBrush(hdc, hbr); + ::FillRect(hdc, &rect, hbr); - AutoHBRUSH hbr(wxColourToPalRGB(colBack)); - SelectInHDC selBrush(hdc, hbr); + // using native API because it recognizes '&' - RECT rectFill; - wxCopyRectToRECT(rc, rectFill); - ::FillRect(hdc, &rectFill, hbr); + wxString text = GetName(); - // using native API because it recognizes '&' + SIZE sizeRect; + ::GetTextExtentPoint32(hdc, text.c_str(), text.length(), &sizeRect); - wxString text = GetName(); + int flags = DST_PREFIXTEXT; + if ( (stat & wxODDisabled) && !(stat & wxODSelected) ) + flags |= DSS_DISABLED; - SIZE sizeRect; - ::GetTextExtentPoint32(hdc, text.c_str(), text.length(), &sizeRect); + if ( (stat & wxODHidePrefix) ) + flags |= DSS_HIDEPREFIX; - int flags = DST_PREFIXTEXT; - if ( (stat & wxODDisabled) && !(stat & wxODSelected) ) - flags |= DSS_DISABLED; + int x = rc.x + GetMarginWidth(); + int y = rc.y + (rc.GetHeight() - sizeRect.cy) / 2; + int cx = rc.GetWidth() - GetMarginWidth(); + int cy = sizeRect.cy; - if ( (stat & wxODHidePrefix) ) - flags |= DSS_HIDEPREFIX; + ::DrawState(hdc, NULL, NULL, (LPARAM)text.wx_str(), + text.length(), x, y, cx, cy, flags); - int x = rc.x + GetMarginWidth(); - int y = rc.y + (rc.GetHeight() - sizeRect.cy) / 2; - int cx = rc.GetWidth() - GetMarginWidth(); - int cy = sizeRect.cy; + } // reset to default the font, colors and brush - ::DrawState(hdc, NULL, NULL, (LPARAM)text.wx_str(), - text.length(), x, y, cx, cy, flags); + if (stat & wxODHasFocus) + ::DrawFocusRect(hdc, &rect); return true; }