libwine: Pass flags to wine_utf8_wcstombs to allow supporting WC_ERR_INVALID_CHARS.
[wine] / dlls / uxtheme / property.c
1 /*
2  * Win32 5.1 Theme properties
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 "winuser.h"
28 #include "wingdi.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  *      GetThemeBool                                        (UXTHEME.@)
42  */
43 HRESULT WINAPI GetThemeBool(HTHEME hTheme, int iPartId, int iStateId,
44                             int iPropId, BOOL *pfVal)
45 {
46     PTHEME_PROPERTY tp;
47
48     TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
49     if(!hTheme)
50         return E_HANDLE;
51
52     if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_BOOL, iPropId)))
53         return E_PROP_ID_UNSUPPORTED;
54     return MSSTYLES_GetPropertyBool(tp, pfVal);
55 }
56
57 /***********************************************************************
58  *      GetThemeColor                                       (UXTHEME.@)
59  */
60 HRESULT WINAPI GetThemeColor(HTHEME hTheme, int iPartId, int iStateId,
61                              int iPropId, COLORREF *pColor)
62 {
63     PTHEME_PROPERTY tp;
64
65     TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
66     if(!hTheme)
67         return E_HANDLE;
68
69     if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_COLOR, iPropId)))
70         return E_PROP_ID_UNSUPPORTED;
71     return MSSTYLES_GetPropertyColor(tp, pColor);
72 }
73
74 /***********************************************************************
75  *      GetThemeEnumValue                                   (UXTHEME.@)
76  */
77 HRESULT WINAPI GetThemeEnumValue(HTHEME hTheme, int iPartId, int iStateId,
78                                  int iPropId, int *piVal)
79 {
80     HRESULT hr;
81     WCHAR val[60];
82     PTHEME_PROPERTY tp;
83
84     TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
85     if(!hTheme)
86         return E_HANDLE;
87
88     if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_ENUM, iPropId)))
89         return E_PROP_ID_UNSUPPORTED;
90
91     hr = MSSTYLES_GetPropertyString(tp, val, sizeof(val)/sizeof(val[0]));
92     if(FAILED(hr))
93         return hr;
94     if(!MSSTYLES_LookupEnum(val, iPropId, piVal))
95         return E_PROP_ID_UNSUPPORTED;
96     return S_OK;
97 }
98
99 /***********************************************************************
100  *      GetThemeFilename                                    (UXTHEME.@)
101  */
102 HRESULT WINAPI GetThemeFilename(HTHEME hTheme, int iPartId, int iStateId,
103                                 int iPropId, LPWSTR pszThemeFilename,
104                                 int cchMaxBuffChars)
105 {
106     PTHEME_PROPERTY tp;
107
108     TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
109     if(!hTheme)
110         return E_HANDLE;
111
112     if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, iPropId)))
113         return E_PROP_ID_UNSUPPORTED;
114     return MSSTYLES_GetPropertyString(tp, pszThemeFilename, cchMaxBuffChars);
115 }
116
117 /***********************************************************************
118  *      GetThemeFont                                        (UXTHEME.@)
119  */
120 HRESULT WINAPI GetThemeFont(HTHEME hTheme, HDC hdc, int iPartId,
121                             int iStateId, int iPropId, LOGFONTW *pFont)
122 {
123     PTHEME_PROPERTY tp;
124
125     TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
126     if(!hTheme)
127         return E_HANDLE;
128
129     if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FONT, iPropId)))
130         return E_PROP_ID_UNSUPPORTED;
131     return MSSTYLES_GetPropertyFont(tp, hdc, pFont);
132 }
133
134 /***********************************************************************
135  *      GetThemeInt                                         (UXTHEME.@)
136  */
137 HRESULT WINAPI GetThemeInt(HTHEME hTheme, int iPartId, int iStateId,
138                            int iPropId, int *piVal)
139 {
140     PTHEME_PROPERTY tp;
141
142     TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
143     if(!hTheme)
144         return E_HANDLE;
145
146     if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_INT, iPropId)))
147         return E_PROP_ID_UNSUPPORTED;
148     return MSSTYLES_GetPropertyInt(tp, piVal);
149 }
150
151 /***********************************************************************
152  *      GetThemeIntList                                     (UXTHEME.@)
153  */
154 HRESULT WINAPI GetThemeIntList(HTHEME hTheme, int iPartId, int iStateId,
155                                int iPropId, INTLIST *pIntList)
156 {
157     PTHEME_PROPERTY tp;
158
159     TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
160     if(!hTheme)
161         return E_HANDLE;
162
163     if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_INTLIST, iPropId)))
164         return E_PROP_ID_UNSUPPORTED;
165     return MSSTYLES_GetPropertyIntList(tp, pIntList);
166 }
167
168 /***********************************************************************
169  *      GetThemePosition                                    (UXTHEME.@)
170  */
171 HRESULT WINAPI GetThemePosition(HTHEME hTheme, int iPartId, int iStateId,
172                                 int iPropId, POINT *pPoint)
173 {
174     PTHEME_PROPERTY tp;
175
176     TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
177     if(!hTheme)
178         return E_HANDLE;
179
180     if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_POSITION, iPropId)))
181         return E_PROP_ID_UNSUPPORTED;
182     return MSSTYLES_GetPropertyPosition(tp, pPoint);
183 }
184
185 /***********************************************************************
186  *      GetThemeRect                                        (UXTHEME.@)
187  */
188 HRESULT WINAPI GetThemeRect(HTHEME hTheme, int iPartId, int iStateId,
189                             int iPropId, RECT *pRect)
190 {
191     PTHEME_PROPERTY tp;
192
193     TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
194     if(!hTheme)
195         return E_HANDLE;
196
197     if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_RECT, iPropId)))
198         return E_PROP_ID_UNSUPPORTED;
199     return MSSTYLES_GetPropertyRect(tp, pRect);
200 }
201
202 /***********************************************************************
203  *      GetThemeString                                      (UXTHEME.@)
204  */
205 HRESULT WINAPI GetThemeString(HTHEME hTheme, int iPartId, int iStateId,
206                               int iPropId, LPWSTR pszBuff, int cchMaxBuffChars)
207 {
208     PTHEME_PROPERTY tp;
209
210     TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
211     if(!hTheme)
212         return E_HANDLE;
213
214     if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_FILENAME, iPropId)))
215         return E_PROP_ID_UNSUPPORTED;
216     return MSSTYLES_GetPropertyString(tp, pszBuff, cchMaxBuffChars);
217 }
218
219 /***********************************************************************
220  *      GetThemeMargins                                     (UXTHEME.@)
221  */
222 HRESULT WINAPI GetThemeMargins(HTHEME hTheme, HDC hdc, int iPartId,
223                                int iStateId, int iPropId, RECT *prc,
224                                MARGINS *pMargins)
225 {
226     PTHEME_PROPERTY tp;
227
228     TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
229     memset (pMargins, 0, sizeof (MARGINS));
230     if(!hTheme)
231         return E_HANDLE;
232
233     if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, TMT_MARGINS, iPropId)))
234         return E_PROP_ID_UNSUPPORTED;
235     return MSSTYLES_GetPropertyMargins(tp, prc, pMargins);
236 }
237
238 /***********************************************************************
239  *      GetThemeMetric                                      (UXTHEME.@)
240  */
241 HRESULT WINAPI GetThemeMetric(HTHEME hTheme, HDC hdc, int iPartId,
242                               int iStateId, int iPropId, int *piVal)
243 {
244     PTHEME_PROPERTY tp;
245     WCHAR val[60];
246     HRESULT hr;
247
248     TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
249     if(!hTheme)
250         return E_HANDLE;
251
252     if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, 0, iPropId)))
253         return E_PROP_ID_UNSUPPORTED;
254     switch(tp->iPrimitiveType) {
255         case TMT_POSITION: /* Only the X coord is retrieved */
256         case TMT_MARGINS: /* Only the cxLeftWidth member is retrieved */
257         case TMT_INTLIST: /* Only the first int is retrieved */
258         case TMT_SIZE:
259         case TMT_INT:
260             return MSSTYLES_GetPropertyInt(tp, piVal);
261         case TMT_BOOL:
262             return MSSTYLES_GetPropertyBool(tp, piVal);
263         case TMT_COLOR:
264             return MSSTYLES_GetPropertyColor(tp, (COLORREF*)piVal);
265         case TMT_ENUM:
266             hr = MSSTYLES_GetPropertyString(tp, val, sizeof(val)/sizeof(val[0]));
267             if(FAILED(hr))
268                 return hr;
269             if(!MSSTYLES_LookupEnum(val, iPropId, piVal))
270                 return E_PROP_ID_UNSUPPORTED;
271             return S_OK;
272          case TMT_FILENAME:
273              /* Windows does return a value for this, but its value doesn't make sense */
274              FIXME("Filename\n");
275              break;
276     }
277     return E_PROP_ID_UNSUPPORTED;
278 }
279
280 /***********************************************************************
281  *      GetThemePropertyOrigin                              (UXTHEME.@)
282  */
283 HRESULT WINAPI GetThemePropertyOrigin(HTHEME hTheme, int iPartId, int iStateId,
284                                       int iPropId, PROPERTYORIGIN *pOrigin)
285 {
286     PTHEME_PROPERTY tp;
287
288     TRACE("(%d, %d, %d)\n", iPartId, iStateId, iPropId);
289     if(!hTheme)
290         return E_HANDLE;
291
292     if(!(tp = MSSTYLES_FindProperty(hTheme, iPartId, iStateId, 0, iPropId))) {
293         *pOrigin = PO_NOTFOUND;
294         return S_OK;
295     }
296     *pOrigin = tp->origin;
297     return S_OK;
298 }