From 00f62916f235223a3627cdbb5707f1c2886913fd Mon Sep 17 00:00:00 2001 From: Reece Dunn Date: Wed, 16 Jul 2008 19:36:17 +0100 Subject: [PATCH] comctl32: support for drawing themed radio buttons and check boxes. --- dlls/comctl32/theme_button.c | 59 +++++++++++++++++++++++++++++++++++++---- 1 files changed, 53 insertions(+), 6 deletions(-) diff --git a/dlls/comctl32/theme_button.c b/dlls/comctl32/theme_button.c index 6e66393..98529c9 100644 --- a/dlls/comctl32/theme_button.c +++ b/dlls/comctl32/theme_button.c @@ -138,6 +138,53 @@ static void PB_draw(HTHEME theme, HWND hwnd, HDC hDC, int part, int drawState, U if (hPrevFont) SelectObject(hDC, hPrevFont); } +static void CB_draw(HTHEME theme, HWND hwnd, HDC hDC, int part, int drawState, UINT dtFlags) +{ + static const int cb_states[][3] = + { + { CBS_UNCHECKEDNORMAL, CBS_UNCHECKEDDISABLED, CBS_UNCHECKEDHOT, CBS_UNCHECKEDPRESSED, CBS_UNCHECKEDNORMAL }, + { CBS_CHECKEDNORMAL, CBS_CHECKEDDISABLED, CBS_CHECKEDHOT, CBS_CHECKEDPRESSED, CBS_CHECKEDNORMAL }, + { CBS_MIXEDNORMAL, CBS_MIXEDDISABLED, CBS_MIXEDHOT, CBS_MIXEDPRESSED, CBS_MIXEDNORMAL } + }; + + static const int rb_states[][2] = + { + { RBS_UNCHECKEDNORMAL, RBS_UNCHECKEDDISABLED, RBS_UNCHECKEDHOT, RBS_UNCHECKEDPRESSED, RBS_UNCHECKEDNORMAL }, + { RBS_CHECKEDNORMAL, RBS_CHECKEDDISABLED, RBS_CHECKEDHOT, RBS_CHECKEDPRESSED, RBS_CHECKEDNORMAL } + }; + + static const int cb_size = 13; + + RECT bgRect, textRect; + HFONT font = (HFONT)SendMessageW(hwnd, WM_GETFONT, 0, 0); + HFONT hPrevFont = font ? SelectObject(hDC, font) : NULL; + LRESULT checkState = SendMessageW(hwnd, BM_GETCHECK, 0, 0); + int state = (part == BP_CHECKBOX) + ? cb_states[ checkState ][ drawState ] + : rb_states[ checkState ][ drawState ]; + WCHAR text[MAX_PATH]; + int len = MAX_PATH; + + GetClientRect(hwnd, &bgRect); + textRect = bgRect; + + if (dtFlags & DT_SINGLELINE) /* Center the checkbox / radio button to the text. */ + bgRect.top = bgRect.top + (textRect.bottom - textRect.top - cb_size) / 2; + + bgRect.bottom = bgRect.top + cb_size; + bgRect.right = bgRect.left + cb_size; + textRect.left = bgRect.right + 4; + + len = GetWindowTextW(hwnd, text, len); + + if (IsThemeBackgroundPartiallyTransparent(theme, part, state)) + DrawThemeParentBackground(hwnd, hDC, NULL); + DrawThemeBackground(theme, hDC, part, state, &bgRect, NULL); + DrawThemeText(theme, hDC, part, state, text, len, dtFlags, 0, &textRect); + + if (hPrevFont) SelectObject(hDC, hPrevFont); +} + static void GB_draw(HTHEME theme, HWND hwnd, HDC hDC, int part, int drawState, UINT dtFlags) { static const int states[] = @@ -186,14 +233,14 @@ static const pfThemedPaint btnThemedPaintFunc[BUTTON_TYPE] = { PB_draw, /* BS_PUSHBUTTON */ PB_draw, /* BS_DEFPUSHBUTTON */ - NULL, /* BS_CHECKBOX */ - NULL, /* BS_AUTOCHECKBOX */ - NULL, /* BS_RADIOBUTTON */ - NULL, /* BS_3STATE */ - NULL, /* BS_AUTO3STATE */ + CB_draw, /* BS_CHECKBOX */ + CB_draw, /* BS_AUTOCHECKBOX */ + CB_draw, /* BS_RADIOBUTTON */ + CB_draw, /* BS_3STATE */ + CB_draw, /* BS_AUTO3STATE */ GB_draw, /* BS_GROUPBOX */ NULL, /* BS_USERBUTTON */ - NULL, /* BS_AUTORADIOBUTTON */ + CB_draw, /* BS_AUTORADIOBUTTON */ NULL, /* Not defined */ NULL, /* BS_OWNERDRAW */ NULL, /* Not defined */ -- 1.5.4.3