secur32: Fix the schannel tests crashing on Vista.
[wine/gsoc_dplay.git] / dlls / comctl32 / theme_button.c
blob54955fa99ac6e5e381debdf36b4d202de1190f39
1 /*
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
22 #include <stdarg.h>
23 #include <string.h>
24 #include <stdlib.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "uxtheme.h"
31 #include "tmschema.h"
32 #include "comctl32.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(themingbutton);
37 #define BUTTON_TYPE 0x0f /* bit mask for the available button types */
39 typedef void (*pfThemedPaint)(HTHEME theme, HWND hwnd, HDC hdc);
41 static void GB_draw(HTHEME theme, HWND hwnd, HDC hDC)
43 RECT bgRect, textRect;
44 SIZE textExtent;
45 HFONT font = (HFONT)SendMessageW(hwnd, WM_GETFONT, 0, 0);
46 HFONT hPrevFont = font ? SelectObject(hDC, font) : NULL;
47 int state = IsWindowEnabled(hwnd) ? GBS_NORMAL : GBS_DISABLED;
48 WCHAR text[MAX_PATH];
49 int len = MAX_PATH;
51 GetClientRect(hwnd, &bgRect);
52 textRect = bgRect;
54 len = GetWindowTextW(hwnd, text, len);
56 GetTextExtentPoint32W(hDC, text, len, &textExtent);
58 bgRect.top += (textExtent.cy / 2);
59 textRect.left += 10;
60 textRect.bottom = textRect.top + textExtent.cy;
61 textRect.right = textRect.left + textExtent.cx + 4;
63 ExcludeClipRect(hDC, textRect.left, textRect.top, textRect.right, textRect.bottom);
65 DrawThemeBackground(theme, hDC, BP_GROUPBOX, state, &bgRect, NULL);
67 SelectClipRgn(hDC, NULL);
69 textRect.left += 2;
70 textRect.right -= 2;
71 DrawThemeText(theme, hDC, BP_GROUPBOX, state, text, len, 0, 0, &textRect);
73 if (hPrevFont) SelectObject(hDC, hPrevFont);
76 static const pfThemedPaint btnThemedPaintFunc[BUTTON_TYPE + 1] =
78 NULL, /* BS_PUSHBUTTON */
79 NULL, /* BS_DEFPUSHBUTTON */
80 NULL, /* BS_CHECKBOX */
81 NULL, /* BS_AUTOCHECKBOX */
82 NULL, /* BS_RADIOBUTTON */
83 NULL, /* BS_3STATE */
84 NULL, /* BS_AUTO3STATE */
85 GB_draw, /* BS_GROUPBOX */
86 NULL, /* BS_USERBUTTON */
87 NULL, /* BS_AUTORADIOBUTTON */
88 NULL, /* Not defined */
89 NULL, /* BS_OWNERDRAW */
90 NULL, /* Not defined */
91 NULL, /* Not defined */
92 NULL, /* Not defined */
93 NULL, /* Not defined */
96 static BOOL BUTTON_Paint(HTHEME theme, HWND hwnd, HDC hParamDC)
98 PAINTSTRUCT ps;
99 HDC hDC;
100 DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
101 pfThemedPaint paint = btnThemedPaintFunc[ dwStyle & BUTTON_TYPE ];
103 if (paint)
105 hDC = hParamDC ? hParamDC : BeginPaint(hwnd, &ps);
106 paint(theme, hwnd, hDC);
107 if (!hParamDC) EndPaint(hwnd, &ps);
108 return TRUE;
111 return FALSE; /* Delegate drawing to the non-themed code. */
114 /**********************************************************************
115 * The button control subclass window proc.
117 LRESULT CALLBACK THEMING_ButtonSubclassProc(HWND hwnd, UINT msg,
118 WPARAM wParam, LPARAM lParam,
119 ULONG_PTR dwRefData)
121 const WCHAR* themeClass = WC_BUTTONW;
122 HTHEME theme;
123 LRESULT result;
125 switch (msg)
127 case WM_CREATE:
128 result = THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
129 OpenThemeData(hwnd, themeClass);
130 return result;
132 case WM_DESTROY:
133 theme = GetWindowTheme(hwnd);
134 CloseThemeData (theme);
135 return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
137 case WM_THEMECHANGED:
138 theme = GetWindowTheme(hwnd);
139 CloseThemeData (theme);
140 OpenThemeData(hwnd, themeClass);
141 break;
143 case WM_SYSCOLORCHANGE:
144 theme = GetWindowTheme(hwnd);
145 if (!theme) return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
146 /* Do nothing. When themed, a WM_THEMECHANGED will be received, too,
147 * which will do the repaint. */
148 break;
150 case WM_PAINT:
151 theme = GetWindowTheme(hwnd);
152 if (theme && BUTTON_Paint(theme, hwnd, (HDC)wParam))
153 return 0;
154 else
155 return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
157 case WM_ENABLE:
158 theme = GetWindowTheme(hwnd);
159 if (theme) RedrawWindow(hwnd, NULL, NULL,
160 RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW);
161 return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
163 default:
164 /* Call old proc */
165 return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
167 return 0;