Fix appearance of multiline wxCheckBox with non-standard colours in wxMSW.

Owner-drawn checkbox (which is used when wxCheckBox colour is changed) didn't
center its label correctly and didn't right align it when using wxALIGN_RIGHT
style in focused state.

Closes #9628.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73404 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2013-01-20 02:09:56 +00:00
parent 46286d9a61
commit f2e763d7f1
2 changed files with 26 additions and 12 deletions

View File

@@ -628,6 +628,7 @@ wxMSW:
- Display system drag images during drag and drop if available (PeterO). - Display system drag images during drag and drop if available (PeterO).
- Fix setting initial wxSpinCtrl value outside 0..100 range (joim). - Fix setting initial wxSpinCtrl value outside 0..100 range (joim).
- Fix changing labels of menu items with bitmaps (Daniel Hyams). - Fix changing labels of menu items with bitmaps (Daniel Hyams).
- Fix appearance of multiline coloured wxCheckBox (Catalin Raceanu).
wxOSX/Cocoa: wxOSX/Cocoa:

View File

@@ -378,32 +378,35 @@ bool wxCheckBox::MSWOnDraw(WXDRAWITEMSTRUCT *item)
RECT& rect = dis->rcItem; RECT& rect = dis->rcItem;
RECT rectCheck, RECT rectCheck,
rectLabel; rectLabel;
rectCheck.top = rectLabel.top = rect.top + (rect.bottom - rect.top - GetBestSize().y) / 2;
rectLabel.top = rect.top; rectLabel.bottom = rectLabel.top + GetBestSize().y;
rectCheck.bottom =
rectLabel.bottom = rect.bottom;
const int checkSize = GetBestSize().y;
const int MARGIN = 3; const int MARGIN = 3;
const int CXMENUCHECK = ::GetSystemMetrics(SM_CXMENUCHECK);
// the space between the checkbox and the label is included in the
// check-mark bitmap
const int checkSize = wxMin(CXMENUCHECK - MARGIN, GetSize().y);
rectCheck.top = rect.top + (rect.bottom - rect.top - checkSize) / 2;
rectCheck.bottom = rectCheck.top + checkSize;
const bool isRightAligned = HasFlag(wxALIGN_RIGHT); const bool isRightAligned = HasFlag(wxALIGN_RIGHT);
if ( isRightAligned ) if ( isRightAligned )
{ {
rectCheck.right = rect.right; rectLabel.right = rect.right - CXMENUCHECK;
rectCheck.left = rectCheck.right - checkSize;
rectLabel.right = rectCheck.left - MARGIN;
rectLabel.left = rect.left; rectLabel.left = rect.left;
rectCheck.left = rectLabel.right + ( CXMENUCHECK + MARGIN - checkSize ) / 2;
rectCheck.right = rectCheck.left + checkSize;
} }
else // normal, left-aligned checkbox else // normal, left-aligned checkbox
{ {
rectCheck.left = rect.left; rectCheck.left = rect.left + ( CXMENUCHECK - MARGIN - checkSize ) / 2;
rectCheck.right = rectCheck.left + checkSize; rectCheck.right = rectCheck.left + checkSize;
rectLabel.left = rectCheck.right + MARGIN; rectLabel.left = rect.left + CXMENUCHECK;
rectLabel.right = rect.right; rectLabel.right = rect.right;
} }
// show we draw a focus rect? // shall we draw a focus rect?
const bool isFocused = m_isPressed || FindFocus() == this; const bool isFocused = m_isPressed || FindFocus() == this;
@@ -456,11 +459,21 @@ bool wxCheckBox::MSWOnDraw(WXDRAWITEMSTRUCT *item)
// around it // around it
if ( isFocused ) if ( isFocused )
{ {
RECT oldLabelRect = rectLabel; // needed if right aligned
if ( !::DrawText(hdc, label.t_str(), label.length(), &rectLabel, if ( !::DrawText(hdc, label.t_str(), label.length(), &rectLabel,
fmt | DT_CALCRECT) ) fmt | DT_CALCRECT) )
{ {
wxLogLastError(wxT("DrawText(DT_CALCRECT)")); wxLogLastError(wxT("DrawText(DT_CALCRECT)"));
} }
if ( isRightAligned )
{
// move the label rect to the right
const int labelWidth = rectLabel.right - rectLabel.left;
rectLabel.right = oldLabelRect.right;
rectLabel.left = rectLabel.right - labelWidth;
}
} }
if ( !IsEnabled() ) if ( !IsEnabled() )