2 * Theming - Button control
4 * Copyright (c) 2008 by Reece H. Dunn
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(themingbutton);
37 #define BUTTON_TYPE 0x0f /* bit mask for the available button types */
39 static void GB_draw(HTHEME theme, HWND hwnd, HDC hDC)
41 RECT bgRect, textRect;
43 HFONT font = (HFONT)SendMessageW(hwnd, WM_GETFONT, 0, 0);
44 HFONT hPrevFont = font ? SelectObject(hDC, font) : NULL;
45 int state = IsWindowEnabled(hwnd) ? GBS_NORMAL : GBS_DISABLED;
49 GetClientRect(hwnd, &bgRect);
52 len = GetWindowTextW(hwnd, text, len);
54 GetTextExtentPoint32W(hDC, text, len, &textExtent);
56 bgRect.top += (textExtent.cy / 2);
58 textRect.bottom = textRect.top + textExtent.cy;
59 textRect.right = textRect.left + textExtent.cx + 4;
61 ExcludeClipRect(hDC, textRect.left, textRect.top, textRect.right, textRect.bottom);
63 DrawThemeBackground(theme, hDC, BP_GROUPBOX, state, &bgRect, NULL);
65 SelectClipRgn(hDC, NULL);
69 DrawThemeText(theme, hDC, BP_GROUPBOX, state, text, len, 0, 0, &textRect);
71 if (hPrevFont) SelectObject(hDC, hPrevFont);
74 static BOOL BUTTON_Paint(HTHEME theme, HWND hwnd, HDC hParamDC)
78 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
80 if ((dwStyle & BUTTON_TYPE) == BS_GROUPBOX)
82 hDC = hParamDC ? hParamDC : BeginPaint(hwnd, &ps);
83 GB_draw(theme, hwnd, hDC);
84 if (!hParamDC) EndPaint(hwnd, &ps);
86 else return FALSE; /* Delegate drawing to the non-themed code. */
91 /**********************************************************************
92 * The button control subclass window proc.
94 LRESULT CALLBACK THEMING_ButtonSubclassProc(HWND hwnd, UINT msg,
95 WPARAM wParam, LPARAM lParam,
98 const WCHAR* themeClass = WC_BUTTONW;
105 result = THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
106 OpenThemeData(hwnd, themeClass);
110 theme = GetWindowTheme(hwnd);
111 CloseThemeData (theme);
112 return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
114 case WM_THEMECHANGED:
115 theme = GetWindowTheme(hwnd);
116 CloseThemeData (theme);
117 OpenThemeData(hwnd, themeClass);
120 case WM_SYSCOLORCHANGE:
121 theme = GetWindowTheme(hwnd);
122 if (!theme) return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
123 /* Do nothing. When themed, a WM_THEMECHANGED will be received, too,
124 * which will do the repaint. */
128 theme = GetWindowTheme(hwnd);
129 if (theme && BUTTON_Paint(theme, hwnd, (HDC)wParam))
132 return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
135 theme = GetWindowTheme(hwnd);
136 if (theme) RedrawWindow(hwnd, NULL, NULL,
137 RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW);
138 return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
142 return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);