From: Vadim Zeitlin Date: Sun, 22 May 2005 22:53:11 +0000 (+0000) Subject: fixed drawing of owner drawn buttons with multiline labels X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/cbbb6724af7ad60a59a7b8f0a07e122ce9063024?ds=sidebyside fixed drawing of owner drawn buttons with multiline labels git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34276 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/msw/button.cpp b/src/msw/button.cpp index b9ac736375..2f56bb4e51 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -497,8 +497,31 @@ static void DrawButtonText(HDC hdc, COLORREF colOld = SetTextColor(hdc, col); int modeOld = SetBkMode(hdc, TRANSPARENT); - // Note: we must have DT_SINGLELINE for DT_VCENTER to work. - ::DrawText(hdc, text, text.length(), pRect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); + if ( text.find(_T('\n')) != wxString::npos ) + { + // draw multiline label + + // first we need to compute its bounding rect + RECT rc; + ::CopyRect(&rc, pRect); + ::DrawText(hdc, text, text.length(), &rc, DT_CENTER | DT_CALCRECT); + + // now center this rect inside the entire button area + const LONG w = rc.right - rc.left; + const LONG h = rc.bottom - rc.top; + rc.left = (pRect->right - pRect->left)/2 - w/2; + rc.right = rc.left+w; + rc.top = (pRect->bottom - pRect->top)/2 - h/2; + rc.bottom = rc.top+h; + + ::DrawText(hdc, text, text.length(), &rc, DT_CENTER); + } + else // single line label + { + // Note: we must have DT_SINGLELINE for DT_VCENTER to work. + ::DrawText(hdc, text, text.length(), pRect, + DT_SINGLELINE | DT_CENTER | DT_VCENTER); + } SetBkMode(hdc, modeOld); SetTextColor(hdc, colOld);