Respect alignment flags for owner-drawn buttons in wxMSW.

Honour wxBU_{LEFT,RIGHT,TOP,BOTTOM} flags for owner drawn buttons too, this
ensures that you can both change the colour and align the text differently for
buttons under XP and later.

Closes #12995.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67184 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-03-14 11:54:26 +00:00
parent 2631773e82
commit 31dcbd12ef

View File

@@ -1099,16 +1099,18 @@ wxButton::State GetButtonState(wxButton *btn, UINT state)
void DrawButtonText(HDC hdc,
RECT *pRect,
const wxString& text,
wxButton *btn,
int flags)
{
// center text horizontally in any case
flags |= DT_CENTER;
const wxString text = btn->GetLabel();
if ( text.find(wxT('\n')) != wxString::npos )
{
// 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);
@@ -1127,10 +1129,31 @@ void DrawButtonText(HDC hdc,
}
else // single line label
{
// centre text vertically too (notice that we must have DT_SINGLELINE
// for DT_VCENTER to work)
// translate wx button flags to alignment flags for DrawText()
if ( btn->HasFlag(wxBU_RIGHT) )
{
flags |= DT_RIGHT;
}
else if ( !btn->HasFlag(wxBU_LEFT) )
{
flags |= DT_CENTER;
}
//else: DT_LEFT is the default anyhow (and its value is 0 too)
if ( btn->HasFlag(wxBU_BOTTOM) )
{
flags |= DT_BOTTOM;
}
else if ( !btn->HasFlag(wxBU_TOP) )
{
flags |= DT_VCENTER;
}
//else: as above, DT_TOP is the default
// notice that we must have DT_SINGLELINE for vertical alignment flags
// to work
::DrawText(hdc, text.wx_str(), text.length(), pRect,
flags | DT_SINGLELINE | DT_VCENTER);
flags | DT_SINGLELINE );
}
}
@@ -1475,7 +1498,7 @@ bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis)
// 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(),
DrawButtonText(hdc, &rectBtn, this,
state & ODS_NOACCEL ? DT_HIDEPREFIX : 0);
}
}