[UXTHEME] Reduce difference with Wine Staging 1.9.23. CORE-12409
[reactos.git] / reactos / dll / win32 / uxtheme / metric.c
1 /*
2 * Win32 5.1 Theme metrics
3 *
4 * Copyright (C) 2003 Kevin Koltzau
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 #include "uxthemep.h"
22
23 /***********************************************************************
24 * GetThemeSysBool (UXTHEME.@)
25 */
26 BOOL WINAPI GetThemeSysBool(HTHEME hTheme, int iBoolID)
27 {
28 HRESULT hr;
29 PTHEME_PROPERTY tp;
30 BOOL ret;
31
32 TRACE("(%p, %d)\n", hTheme, iBoolID);
33 SetLastError(0);
34 if(hTheme) {
35 PTHEME_CLASS ptc = (PTHEME_CLASS) hTheme;
36
37 if((tp = MSSTYLES_FindMetric(ptc->tf, TMT_BOOL, iBoolID))) {
38 hr = MSSTYLES_GetPropertyBool(tp, &ret);
39 if(SUCCEEDED(hr))
40 return ret;
41 else
42 SetLastError(hr);
43 }
44 }
45 if(iBoolID == TMT_FLATMENUS) {
46 if(SystemParametersInfoW(SPI_GETFLATMENU, 0, &ret, 0))
47 return ret;
48 }
49 else {
50 FIXME("Unknown bool id: %d\n", iBoolID);
51 SetLastError(STG_E_INVALIDPARAMETER);
52 }
53 return FALSE;
54 }
55
56 /***********************************************************************
57 * GetThemeSysColor (UXTHEME.@)
58 */
59 COLORREF WINAPI GetThemeSysColor(HTHEME hTheme, int iColorID)
60 {
61 HRESULT hr;
62 PTHEME_PROPERTY tp;
63
64 // TODO: Check if this is correct
65 if ( iColorID >= 0 && iColorID < 32)
66 iColorID += TMT_SCROLLBAR;
67
68 TRACE("(%p, %d)\n", hTheme, iColorID);
69 SetLastError(0);
70 if(hTheme) {
71 PTHEME_CLASS ptc = (PTHEME_CLASS) hTheme;
72 if((tp = MSSTYLES_FindMetric(ptc->tf, TMT_COLOR, iColorID))) {
73 COLORREF color;
74 hr = MSSTYLES_GetPropertyColor(tp, &color);
75 if(SUCCEEDED(hr))
76 return color;
77 else
78 SetLastError(hr);
79 }
80 }
81 return GetSysColor(iColorID);
82 }
83
84 /***********************************************************************
85 * GetThemeSysColorBrush (UXTHEME.@)
86 */
87 HBRUSH WINAPI GetThemeSysColorBrush(HTHEME hTheme, int iColorID)
88 {
89 TRACE("(%p, %d)\n", hTheme, iColorID);
90 return CreateSolidBrush(GetThemeSysColor(hTheme, iColorID));
91 }
92
93 /***********************************************************************
94 * GetThemeSysFont (UXTHEME.@)
95 */
96 HRESULT WINAPI GetThemeSysFont(HTHEME hTheme, int iFontID, LOGFONTW *plf)
97 {
98 HRESULT hr = S_OK;
99 PTHEME_PROPERTY tp;
100
101 TRACE("(%p, %d)\n", hTheme, iFontID);
102 if(hTheme) {
103 PTHEME_CLASS ptc = (PTHEME_CLASS) hTheme;
104 if((tp = MSSTYLES_FindMetric(ptc->tf, TMT_FONT, iFontID))) {
105 HDC hdc = GetDC(NULL);
106 hr = MSSTYLES_GetPropertyFont(tp, hdc, plf);
107 ReleaseDC(NULL, hdc);
108 if(SUCCEEDED(hr))
109 return S_OK;
110 }
111 }
112 if(iFontID == TMT_ICONTITLEFONT) {
113 if(!SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(LOGFONTW), plf, 0))
114 return HRESULT_FROM_WIN32(GetLastError());
115 }
116 else {
117 NONCLIENTMETRICSW ncm;
118 LOGFONTW *font = NULL;
119 ncm.cbSize = sizeof(NONCLIENTMETRICSW);
120 if(!SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &ncm, 0))
121 return HRESULT_FROM_WIN32(GetLastError());
122 switch(iFontID) {
123 case TMT_CAPTIONFONT: font = &ncm.lfCaptionFont; break;
124 case TMT_SMALLCAPTIONFONT: font = &ncm.lfSmCaptionFont; break;
125 case TMT_MENUFONT: font = &ncm.lfMenuFont; break;
126 case TMT_STATUSFONT: font = &ncm.lfStatusFont; break;
127 case TMT_MSGBOXFONT: font = &ncm.lfMessageFont; break;
128 default: FIXME("Unknown FontID: %d\n", iFontID); break;
129 }
130 if(font) *plf = *font;
131 else hr = STG_E_INVALIDPARAMETER;
132 }
133 return hr;
134 }
135
136 /***********************************************************************
137 * GetThemeSysInt (UXTHEME.@)
138 */
139 HRESULT WINAPI GetThemeSysInt(HTHEME hTheme, int iIntID, int *piValue)
140 {
141 PTHEME_PROPERTY tp;
142 PTHEME_CLASS ptc = (PTHEME_CLASS) hTheme;
143
144 TRACE("(%p, %d)\n", hTheme, iIntID);
145 if(!hTheme)
146 return E_HANDLE;
147 if(iIntID < TMT_FIRSTINT || iIntID > TMT_LASTINT) {
148 WARN("Unknown IntID: %d\n", iIntID);
149 return STG_E_INVALIDPARAMETER;
150 }
151 if((tp = MSSTYLES_FindMetric(ptc->tf , TMT_INT, iIntID)))
152 return MSSTYLES_GetPropertyInt(tp, piValue);
153 return E_PROP_ID_UNSUPPORTED;
154 }
155
156 /***********************************************************************
157 * GetThemeSysSize (UXTHEME.@)
158 */
159 int WINAPI GetThemeSysSize(HTHEME hTheme, int iSizeID)
160 {
161 PTHEME_PROPERTY tp;
162 int i, id = -1;
163 int metricMap[] = {
164 SM_CXVSCROLL, TMT_SCROLLBARWIDTH,
165 SM_CYHSCROLL, TMT_SCROLLBARHEIGHT,
166 SM_CXSIZE, TMT_CAPTIONBARWIDTH,
167 SM_CYSIZE, TMT_CAPTIONBARHEIGHT,
168 SM_CXFRAME, TMT_SIZINGBORDERWIDTH,
169 SM_CYFRAME, TMT_SIZINGBORDERWIDTH, /* There is no TMT_SIZINGBORDERHEIGHT, but this works in windows.. */
170 SM_CXSMSIZE, TMT_SMCAPTIONBARWIDTH,
171 SM_CYSMSIZE, TMT_SMCAPTIONBARHEIGHT,
172 SM_CXMENUSIZE, TMT_MENUBARWIDTH,
173 SM_CYMENUSIZE, TMT_MENUBARHEIGHT
174 };
175
176 if(hTheme) {
177 PTHEME_CLASS ptc = (PTHEME_CLASS) hTheme;
178
179 for(i=0; i<sizeof(metricMap)/sizeof(metricMap[0]); i+=2) {
180 if(metricMap[i] == iSizeID) {
181 id = metricMap[i+1];
182 break;
183 }
184 }
185 SetLastError(0);
186 if(id != -1) {
187 if((tp = MSSTYLES_FindMetric(ptc->tf, TMT_SIZE, id))) {
188 if(SUCCEEDED(MSSTYLES_GetPropertyInt(tp, &i))) {
189 return i;
190 }
191 }
192 TRACE("Size %d not found in theme, using system metric\n", iSizeID);
193 }
194 else {
195 SetLastError(STG_E_INVALIDPARAMETER);
196 return 0;
197 }
198 }
199
200
201 // TODO: Check if this is correct
202 // In windows for SM_CXFRAME this function returns what seems to be the non client metric iBorderWidth
203 if (iSizeID == SM_CXFRAME)
204 return GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXDLGFRAME);
205 return GetSystemMetrics(iSizeID);
206 }
207
208 /***********************************************************************
209 * GetThemeSysString (UXTHEME.@)
210 */
211 HRESULT WINAPI GetThemeSysString(HTHEME hTheme, int iStringID,
212 LPWSTR pszStringBuff, int cchMaxStringChars)
213 {
214 PTHEME_PROPERTY tp;
215 PTHEME_CLASS ptc = (PTHEME_CLASS) hTheme;
216
217 TRACE("(%p, %d)\n", hTheme, iStringID);
218 if(!hTheme)
219 return E_HANDLE;
220 if(iStringID < TMT_FIRSTSTRING || iStringID > TMT_LASTSTRING) {
221 WARN("Unknown StringID: %d\n", iStringID);
222 return STG_E_INVALIDPARAMETER;
223 }
224 if((tp = MSSTYLES_FindMetric(ptc->tf, TMT_STRING, iStringID)))
225 return MSSTYLES_GetPropertyString(tp, pszStringBuff, cchMaxStringChars);
226 return E_PROP_ID_UNSUPPORTED;
227 }
228
229 #ifndef __REACTOS__
230 /***********************************************************************
231 * GetThemeTransitionDuration (UXTHEME.@)
232 */
233 HRESULT WINAPI GetThemeTransitionDuration(HTHEME hTheme, int iPartId, int iStateIdFrom,
234 int iStateIdTo, int iPropId, DWORD *pdwDuration)
235 {
236 FIXME("(%p, %u, %u, %u, %u, %p) stub\n", hTheme, iPartId, iStateIdFrom, iStateIdTo,
237 iPropId, pdwDuration);
238
239 return E_NOTIMPL;
240 }
241 #endif