[UXTHEME] Fix the conversion from color id to theme metric and don't pass the metric...
[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 TRACE("(%p, %d)\n", hTheme, iColorID);
65 SetLastError(0);
66 if(hTheme) {
67 PTHEME_CLASS ptc = (PTHEME_CLASS) hTheme;
68 if((tp = MSSTYLES_FindMetric(ptc->tf, TMT_COLOR, iColorID + TMT_FIRSTCOLOR))) {
69 COLORREF color;
70 hr = MSSTYLES_GetPropertyColor(tp, &color);
71 if(SUCCEEDED(hr))
72 return color;
73 else
74 SetLastError(hr);
75 }
76 }
77 return GetSysColor(iColorID);
78 }
79
80 /***********************************************************************
81 * GetThemeSysColorBrush (UXTHEME.@)
82 */
83 HBRUSH WINAPI GetThemeSysColorBrush(HTHEME hTheme, int iColorID)
84 {
85 TRACE("(%p, %d)\n", hTheme, iColorID);
86 return CreateSolidBrush(GetThemeSysColor(hTheme, iColorID));
87 }
88
89 /***********************************************************************
90 * GetThemeSysFont (UXTHEME.@)
91 */
92 HRESULT WINAPI GetThemeSysFont(HTHEME hTheme, int iFontID, LOGFONTW *plf)
93 {
94 HRESULT hr = S_OK;
95 PTHEME_PROPERTY tp;
96
97 TRACE("(%p, %d)\n", hTheme, iFontID);
98 if(hTheme) {
99 PTHEME_CLASS ptc = (PTHEME_CLASS) hTheme;
100 if((tp = MSSTYLES_FindMetric(ptc->tf, TMT_FONT, iFontID))) {
101 HDC hdc = GetDC(NULL);
102 hr = MSSTYLES_GetPropertyFont(tp, hdc, plf);
103 ReleaseDC(NULL, hdc);
104 if(SUCCEEDED(hr))
105 return S_OK;
106 }
107 }
108 if(iFontID == TMT_ICONTITLEFONT) {
109 if(!SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(LOGFONTW), plf, 0))
110 return HRESULT_FROM_WIN32(GetLastError());
111 }
112 else {
113 NONCLIENTMETRICSW ncm;
114 LOGFONTW *font = NULL;
115 ncm.cbSize = sizeof(NONCLIENTMETRICSW);
116 if(!SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &ncm, 0))
117 return HRESULT_FROM_WIN32(GetLastError());
118 switch(iFontID) {
119 case TMT_CAPTIONFONT: font = &ncm.lfCaptionFont; break;
120 case TMT_SMALLCAPTIONFONT: font = &ncm.lfSmCaptionFont; break;
121 case TMT_MENUFONT: font = &ncm.lfMenuFont; break;
122 case TMT_STATUSFONT: font = &ncm.lfStatusFont; break;
123 case TMT_MSGBOXFONT: font = &ncm.lfMessageFont; break;
124 default: FIXME("Unknown FontID: %d\n", iFontID); break;
125 }
126 if(font) *plf = *font;
127 else hr = STG_E_INVALIDPARAMETER;
128 }
129 return hr;
130 }
131
132 /***********************************************************************
133 * GetThemeSysInt (UXTHEME.@)
134 */
135 HRESULT WINAPI GetThemeSysInt(HTHEME hTheme, int iIntID, int *piValue)
136 {
137 PTHEME_PROPERTY tp;
138 PTHEME_CLASS ptc = (PTHEME_CLASS) hTheme;
139
140 TRACE("(%p, %d)\n", hTheme, iIntID);
141 if(!hTheme)
142 return E_HANDLE;
143 if(iIntID < TMT_FIRSTINT || iIntID > TMT_LASTINT) {
144 WARN("Unknown IntID: %d\n", iIntID);
145 return STG_E_INVALIDPARAMETER;
146 }
147 if((tp = MSSTYLES_FindMetric(ptc->tf , TMT_INT, iIntID)))
148 return MSSTYLES_GetPropertyInt(tp, piValue);
149 return E_PROP_ID_UNSUPPORTED;
150 }
151
152 /***********************************************************************
153 * GetThemeSysSize (UXTHEME.@)
154 */
155 int WINAPI GetThemeSysSize(HTHEME hTheme, int iSizeID)
156 {
157 PTHEME_PROPERTY tp;
158 int i, id = -1;
159 int metricMap[] = {
160 SM_CXVSCROLL, TMT_SCROLLBARWIDTH,
161 SM_CYHSCROLL, TMT_SCROLLBARHEIGHT,
162 SM_CXSIZE, TMT_CAPTIONBARWIDTH,
163 SM_CYSIZE, TMT_CAPTIONBARHEIGHT,
164 SM_CXFRAME, TMT_SIZINGBORDERWIDTH,
165 SM_CYFRAME, TMT_SIZINGBORDERWIDTH, /* There is no TMT_SIZINGBORDERHEIGHT, but this works in windows.. */
166 SM_CXSMSIZE, TMT_SMCAPTIONBARWIDTH,
167 SM_CYSMSIZE, TMT_SMCAPTIONBARHEIGHT,
168 SM_CXMENUSIZE, TMT_MENUBARWIDTH,
169 SM_CYMENUSIZE, TMT_MENUBARHEIGHT
170 };
171
172 if(hTheme) {
173 PTHEME_CLASS ptc = (PTHEME_CLASS) hTheme;
174
175 for(i=0; i<sizeof(metricMap)/sizeof(metricMap[0]); i+=2) {
176 if(metricMap[i] == iSizeID) {
177 id = metricMap[i+1];
178 break;
179 }
180 }
181 SetLastError(0);
182 if(id != -1) {
183 if((tp = MSSTYLES_FindMetric(ptc->tf, TMT_SIZE, id))) {
184 if(SUCCEEDED(MSSTYLES_GetPropertyInt(tp, &i))) {
185 return i;
186 }
187 }
188 TRACE("Size %d not found in theme, using system metric\n", iSizeID);
189 }
190 else {
191 SetLastError(STG_E_INVALIDPARAMETER);
192 return 0;
193 }
194 }
195
196
197 // TODO: Check if this is correct
198 // In windows for SM_CXFRAME this function returns what seems to be the non client metric iBorderWidth
199 if (iSizeID == SM_CXFRAME)
200 return GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXDLGFRAME);
201 return GetSystemMetrics(iSizeID);
202 }
203
204 /***********************************************************************
205 * GetThemeSysString (UXTHEME.@)
206 */
207 HRESULT WINAPI GetThemeSysString(HTHEME hTheme, int iStringID,
208 LPWSTR pszStringBuff, int cchMaxStringChars)
209 {
210 PTHEME_PROPERTY tp;
211 PTHEME_CLASS ptc = (PTHEME_CLASS) hTheme;
212
213 TRACE("(%p, %d)\n", hTheme, iStringID);
214 if(!hTheme)
215 return E_HANDLE;
216 if(iStringID < TMT_FIRSTSTRING || iStringID > TMT_LASTSTRING) {
217 WARN("Unknown StringID: %d\n", iStringID);
218 return STG_E_INVALIDPARAMETER;
219 }
220 if((tp = MSSTYLES_FindMetric(ptc->tf, TMT_STRING, iStringID)))
221 return MSSTYLES_GetPropertyString(tp, pszStringBuff, cchMaxStringChars);
222 return E_PROP_ID_UNSUPPORTED;
223 }
224
225 #ifndef __REACTOS__
226 /***********************************************************************
227 * GetThemeTransitionDuration (UXTHEME.@)
228 */
229 HRESULT WINAPI GetThemeTransitionDuration(HTHEME hTheme, int iPartId, int iStateIdFrom,
230 int iStateIdTo, int iPropId, DWORD *pdwDuration)
231 {
232 FIXME("(%p, %u, %u, %u, %u, %p) stub\n", hTheme, iPartId, iStateIdFrom, iStateIdTo,
233 iPropId, pdwDuration);
234
235 return E_NOTIMPL;
236 }
237 #endif