X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/433aca2d0d6f056ecb1097196d1a2f9e0c3d5e64..dc813e6c7ef8a9a26c035b004b512e1aa1b0bf3f:/src/msw/button.cpp diff --git a/src/msw/button.cpp b/src/msw/button.cpp index 8ef37a32b2..ef43802277 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -72,6 +72,10 @@ #define ODS_NOFOCUSRECT 0x0200 #endif +#ifndef DT_HIDEPREFIX + #define DT_HIDEPREFIX 0x00100000 +#endif + // ---------------------------------------------------------------------------- // macros // ---------------------------------------------------------------------------- @@ -301,7 +305,7 @@ void wxButton::SetLabel(const wxString& label) wxSize wxButton::DoGetBestSize() const { - return wxMSWButton::ComputeBestSize(wx_const_cast(wxButton *, this)); + return wxMSWButton::ComputeBestSize(const_cast(this)); } /* static */ @@ -590,11 +594,15 @@ WXLRESULT wxButton::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) static void DrawButtonText(HDC hdc, RECT *pRect, const wxString& text, - COLORREF col) + COLORREF col, + int flags) { COLORREF colOld = SetTextColor(hdc, col); int modeOld = SetBkMode(hdc, TRANSPARENT); + // center text horizontally in any case + flags |= DT_CENTER; + if ( text.find(_T('\n')) != wxString::npos ) { // draw multiline label @@ -613,13 +621,14 @@ static void DrawButtonText(HDC hdc, rc.top = (pRect->bottom - pRect->top)/2 - h/2; rc.bottom = rc.top+h; - ::DrawText(hdc, text.wx_str(), text.length(), &rc, DT_CENTER); + ::DrawText(hdc, text.wx_str(), text.length(), &rc, flags); } else // single line label { - // Note: we must have DT_SINGLELINE for DT_VCENTER to work. + // centre text vertically too (notice that we must have DT_SINGLELINE + // for DT_VCENTER to work) ::DrawText(hdc, text.wx_str(), text.length(), pRect, - DT_SINGLELINE | DT_CENTER | DT_VCENTER); + flags | DT_SINGLELINE | DT_VCENTER); } SetBkMode(hdc, modeOld); @@ -898,11 +907,15 @@ bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis) } } - COLORREF colFg = wxColourToRGB(GetForegroundColour()); - if ( state & ODS_DISABLED ) colFg = GetSysColor(COLOR_GRAYTEXT) ; - wxString label = GetLabel(); - if ( state & ODS_NOACCEL ) label = GetLabelText() ; - DrawButtonText(hdc, &rectBtn, label, colFg); + COLORREF colFg = state & ODS_DISABLED + ? ::GetSysColor(COLOR_GRAYTEXT) + : wxColourToRGB(GetForegroundColour()); + + // notice that DT_HIDEPREFIX doesn't work on old (pre-Windows 2000) systems + // but by happy coincidence ODS_NOACCEL is not used under them neither so + // DT_HIDEPREFIX should never be used there + DrawButtonText(hdc, &rectBtn, GetLabel(), colFg, + state & ODS_NOACCEL ? DT_HIDEPREFIX : 0); return true; }