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