comctl32: statusbar: Test and fix SB_SETMINHEIGHT.
[wine] / dlls / comctl32 / theme_button.c
1 /*
2  * Theming - Button control
3  *
4  * Copyright (c) 2008 by Reece H. Dunn
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include <stdarg.h>
23 #include <string.h>
24 #include <stdlib.h>
25
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"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(themingbutton);
36
37 #define BUTTON_TYPE 0x0f /* bit mask for the available button types */
38
39 static void GB_draw(HTHEME theme, HWND hwnd, HDC hDC)
40 {
41     RECT bgRect, textRect;
42     SIZE textExtent;
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;
46     WCHAR text[MAX_PATH];
47     int len = MAX_PATH;
48
49     GetClientRect(hwnd, &bgRect);
50     textRect = bgRect;
51
52     len = GetWindowTextW(hwnd, text, len);
53
54     GetTextExtentPoint32W(hDC, text, len, &textExtent);
55
56     bgRect.top += (textExtent.cy / 2);
57     textRect.left += 10;
58     textRect.bottom = textRect.top + textExtent.cy;
59     textRect.right = textRect.left + textExtent.cx + 4;
60
61     ExcludeClipRect(hDC, textRect.left, textRect.top, textRect.right, textRect.bottom);
62
63     DrawThemeBackground(theme, hDC, BP_GROUPBOX, state, &bgRect, NULL);
64
65     SelectClipRgn(hDC, NULL);
66
67     textRect.left += 2;
68     textRect.right -= 2;
69     DrawThemeText(theme, hDC, BP_GROUPBOX, state, text, len, 0, 0, &textRect);
70
71     if (hPrevFont) SelectObject(hDC, hPrevFont);
72 }
73
74 static BOOL BUTTON_Paint(HTHEME theme, HWND hwnd, HDC hParamDC)
75 {
76     PAINTSTRUCT ps;
77     HDC hDC;
78     DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
79
80     if ((dwStyle & BUTTON_TYPE) == BS_GROUPBOX)
81     {
82         hDC = hParamDC ? hParamDC : BeginPaint(hwnd, &ps);
83         GB_draw(theme, hwnd, hDC);
84         if (!hParamDC) EndPaint(hwnd, &ps);
85     }
86     else return FALSE; /* Delegate drawing to the non-themed code. */
87
88     return TRUE;
89 }
90
91 /**********************************************************************
92  * The button control subclass window proc.
93  */
94 LRESULT CALLBACK THEMING_ButtonSubclassProc(HWND hwnd, UINT msg,
95                                             WPARAM wParam, LPARAM lParam,
96                                             ULONG_PTR dwRefData)
97 {
98     const WCHAR* themeClass = WC_BUTTONW;
99     HTHEME theme;
100     LRESULT result;
101
102     switch (msg)
103     {
104     case WM_CREATE:
105         result = THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
106         OpenThemeData(hwnd, themeClass);
107         return result;
108
109     case WM_DESTROY:
110         theme = GetWindowTheme(hwnd);
111         CloseThemeData (theme);
112         return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
113
114     case WM_THEMECHANGED:
115         theme = GetWindowTheme(hwnd);
116         CloseThemeData (theme);
117         OpenThemeData(hwnd, themeClass);
118         break;
119
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. */
125         break;
126
127     case WM_PAINT:
128         theme = GetWindowTheme(hwnd);
129         if (theme && BUTTON_Paint(theme, hwnd, (HDC)wParam))
130             return 0;
131         else
132             return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
133
134     case WM_ENABLE:
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);
139
140     default:
141         /* Call old proc */
142         return THEMING_CallOriginalClass(hwnd, msg, wParam, lParam);
143     }
144     return 0;
145 }