Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / uxtheme / metric.c
blob043f836da679d573faaa06c58982318ea298c182
1 /*
2 * Win32 5.1 Theme metrics
4 * Copyright (C) 2003 Kevin Koltzau
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
21 #include "config.h"
23 #include <stdarg.h>
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"
33 #include "msstyles.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
39 /***********************************************************************
40 * GetThemeSysBool (UXTHEME.@)
42 BOOL WINAPI GetThemeSysBool(HTHEME hTheme, int iBoolID)
44 HRESULT hr;
45 PTHEME_PROPERTY tp;
46 BOOL ret;
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);
59 if(iBoolID == TMT_FLATMENUS) {
60 if(SystemParametersInfoW(SPI_GETFLATMENU, 0, &ret, 0))
61 return ret;
63 else {
64 FIXME("Unknown bool id: %d\n", iBoolID);
65 SetLastError(STG_E_INVALIDPARAMETER);
67 return FALSE;
70 /***********************************************************************
71 * GetThemeSysColor (UXTHEME.@)
73 COLORREF WINAPI GetThemeSysColor(HTHEME hTheme, int iColorID)
75 HRESULT hr;
76 PTHEME_PROPERTY tp;
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);
90 return GetSysColor(iColorID);
93 /***********************************************************************
94 * GetThemeSysColorBrush (UXTHEME.@)
96 HBRUSH WINAPI GetThemeSysColorBrush(HTHEME hTheme, int iColorID)
98 TRACE("(%p, %d)\n", hTheme, iColorID);
99 return CreateSolidBrush(GetThemeSysColor(hTheme, iColorID));
102 /***********************************************************************
103 * GetThemeSysFont (UXTHEME.@)
105 HRESULT WINAPI GetThemeSysFont(HTHEME hTheme, int iFontID, LOGFONTW *plf)
107 HRESULT hr = S_OK;
108 PTHEME_PROPERTY tp;
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;
120 if(iFontID == TMT_ICONTITLEFONT) {
121 if(!SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(LOGFONTW), plf, 0))
122 return HRESULT_FROM_WIN32(GetLastError());
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;
138 if(font) *plf = *font;
139 else hr = STG_E_INVALIDPARAMETER;
141 return hr;
144 /***********************************************************************
145 * GetThemeSysInt (UXTHEME.@)
147 HRESULT WINAPI GetThemeSysInt(HTHEME hTheme, int iIntID, int *piValue)
149 PTHEME_PROPERTY tp;
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;
158 if((tp = MSSTYLES_FindMetric(TMT_INT, iIntID)))
159 return MSSTYLES_GetPropertyInt(tp, piValue);
160 return E_PROP_ID_UNSUPPORTED;
163 /***********************************************************************
164 * GetThemeSysSize (UXTHEME.@)
166 int WINAPI GetThemeSysSize(HTHEME hTheme, int iSizeID)
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
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;
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;
197 TRACE("Size %d not found in theme, using system metric\n", iSizeID);
199 else {
200 SetLastError(STG_E_INVALIDPARAMETER);
201 return 0;
204 return GetSystemMetrics(iSizeID);
207 /***********************************************************************
208 * GetThemeSysString (UXTHEME.@)
210 HRESULT WINAPI GetThemeSysString(HTHEME hTheme, int iStringID,
211 LPWSTR pszStringBuff, int cchMaxStringChars)
213 PTHEME_PROPERTY tp;
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;
222 if((tp = MSSTYLES_FindMetric(TMT_STRING, iStringID)))
223 return MSSTYLES_GetPropertyString(tp, pszStringBuff, cchMaxStringChars);
224 return E_PROP_ID_UNSUPPORTED;