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