Fix alignment for multiline buttons using custom colours in wxMSW
Owner-drawn buttons with multiline labels were always centered. Fix this by handling their alignment explicitly when drawing them, as ::DrawText() doesn't do it for multiline strings. Closes #18131.
This commit is contained in:
@@ -92,6 +92,7 @@ wxMSW:
|
||||
- Fix saving/restoring window position for maximized windows.
|
||||
- Fix stack corruption when using wxStackWalker (srfisk).
|
||||
- Fix positioning windows at positions >= SHORT_MAX (Cătălin Răceanu).
|
||||
- Honour alignment flags for multiline buttons using custom colours too.
|
||||
|
||||
|
||||
3.1.1: (released 2018-02-19)
|
||||
|
@@ -930,21 +930,51 @@ void DrawButtonText(HDC hdc,
|
||||
{
|
||||
// draw multiline label
|
||||
|
||||
// center text horizontally in any case
|
||||
flags |= DT_CENTER;
|
||||
|
||||
// first we need to compute its bounding rect
|
||||
RECT rc;
|
||||
::CopyRect(&rc, pRect);
|
||||
::DrawText(hdc, text.t_str(), text.length(), &rc,
|
||||
DT_CENTER | DT_CALCRECT);
|
||||
flags | DT_CALCRECT);
|
||||
|
||||
// now center this rect inside the entire button area
|
||||
// now position this rect inside the entire button area: notice
|
||||
// that DrawText() doesn't respect alignment flags for multiline
|
||||
// text, which is why we have to do it on our own (but still use
|
||||
// the horizontal alignment flags for the individual lines to be
|
||||
// aligned correctly)
|
||||
const LONG w = rc.right - rc.left;
|
||||
const LONG h = rc.bottom - rc.top;
|
||||
|
||||
if ( btn->HasFlag(wxBU_RIGHT) )
|
||||
{
|
||||
rc.left = pRect->right - w;
|
||||
|
||||
flags |= DT_RIGHT;
|
||||
}
|
||||
else if ( !btn->HasFlag(wxBU_LEFT) )
|
||||
{
|
||||
rc.left = pRect->left + (pRect->right - pRect->left)/2 - w/2;
|
||||
rc.right = rc.left+w;
|
||||
|
||||
flags |= DT_CENTER;
|
||||
}
|
||||
else // wxBU_LEFT
|
||||
{
|
||||
rc.left = pRect->left;
|
||||
}
|
||||
|
||||
if ( btn->HasFlag(wxBU_BOTTOM) )
|
||||
{
|
||||
rc.top = pRect->bottom - h;
|
||||
}
|
||||
else if ( !btn->HasFlag(wxBU_TOP) )
|
||||
{
|
||||
rc.top = pRect->top + (pRect->bottom - pRect->top)/2 - h/2;
|
||||
}
|
||||
else // wxBU_TOP
|
||||
{
|
||||
rc.top = pRect->top;
|
||||
}
|
||||
|
||||
rc.right = rc.left+w;
|
||||
rc.bottom = rc.top+h;
|
||||
|
||||
::DrawText(hdc, text.t_str(), text.length(), &rc, flags);
|
||||
|
Reference in New Issue
Block a user