From 16d8622a37d014b69492fad601a08656586acf8d Mon Sep 17 00:00:00 2001 From: Reece Dunn Date: Tue, 29 Jul 2008 00:02:42 +0100 Subject: [PATCH] comctl32: support for drawing themed radio buttons and check boxes. --- dlls/comctl32/theme_button.c | 63 ++++++++++++++++++++++++++++++++++++++---- 1 files changed, 57 insertions(+), 6 deletions(-) diff --git a/dlls/comctl32/theme_button.c b/dlls/comctl32/theme_button.c index 3c47825..25da736 100644 --- a/dlls/comctl32/theme_button.c +++ b/dlls/comctl32/theme_button.c @@ -111,6 +111,57 @@ static void PB_draw(HTHEME theme, HWND hwnd, HDC hDC, int drawState, UINT dtFlag if (hPrevFont) SelectObject(hDC, hPrevFont); } +static void CB_draw(HTHEME theme, HWND hwnd, HDC hDC, int drawState, UINT dtFlags) +{ + static const int cb_states[3][5] = + { + { 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][5] = + { + { 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); + DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE); + int part = ((dwStyle & BUTTON_TYPE) == BS_RADIOBUTTON) || ((dwStyle & BUTTON_TYPE) == BS_AUTORADIOBUTTON) + ? BP_RADIOBUTTON + : BP_CHECKBOX; + 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 drawState, UINT dtFlags) { static const int states[] = { GBS_NORMAL, GBS_DISABLED, GBS_NORMAL, GBS_NORMAL, GBS_NORMAL }; @@ -154,14 +205,14 @@ static const pfThemedPaint btnThemedPaintFunc[BUTTON_TYPE + 1] = { 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