- define additional shell paths for CSIDL_... constants
[wine] / dlls / uxtheme / system.c
1 /*
2  * Win32 5.1 Theme system
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 "winreg.h"
30 #include "shlwapi.h"
31 #include "uxtheme.h"
32 #include "tmschema.h"
33
34 #include "uxthemedll.h"
35 #include "msstyles.h"
36
37 #include "wine/debug.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
40
41 /***********************************************************************
42  * Defines and global variables
43  */
44
45 static const WCHAR szThemeManager[] = {
46     'S','o','f','t','w','a','r','e','\\',
47     'M','i','c','r','o','s','o','f','t','\\',
48     'W','i','n','d','o','w','s','\\',
49     'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
50     'T','h','e','m','e','M','a','n','a','g','e','r','\0'
51 };
52 static const WCHAR szThemeActive[] = {'T','h','e','m','e','A','c','t','i','v','e','\0'};
53 static const WCHAR szSizeName[] = {'S','i','z','e','N','a','m','e','\0'};
54 static const WCHAR szColorName[] = {'C','o','l','o','r','N','a','m','e','\0'};
55 static const WCHAR szDllName[] = {'D','l','l','N','a','m','e','\0'};
56
57 static const WCHAR szIniDocumentation[] = {'d','o','c','u','m','e','n','t','a','t','i','o','n','\0'};
58
59 HINSTANCE hDllInst;
60
61 DWORD dwThemeAppProperties = STAP_ALLOW_NONCLIENT | STAP_ALLOW_CONTROLS;
62 ATOM atWindowTheme;
63 ATOM atSubAppName;
64 ATOM atSubIdList;
65
66 BOOL bThemeActive = FALSE;
67 WCHAR szCurrentTheme[MAX_PATH];
68 WCHAR szCurrentColor[64];
69 WCHAR szCurrentSize[64];
70
71 /***********************************************************************/
72
73 /***********************************************************************
74  *      UXTHEME_LoadTheme
75  *
76  * Set the current active theme from the registry
77  */
78 void UXTHEME_LoadTheme()
79 {
80     HKEY hKey;
81     LONG buffsize;
82     HRESULT hr;
83     WCHAR tmp[10];
84     PTHEME_FILE pt;
85
86     /* Get current theme configuration */
87     if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
88         TRACE("Loading theme config\n");
89         buffsize = sizeof(tmp)/sizeof(tmp[0]);
90         if(!RegQueryValueExW(hKey, szThemeActive, NULL, NULL, (LPBYTE)tmp, &buffsize)) {
91             bThemeActive = (tmp[0] != '0');
92         }
93         else {
94             bThemeActive = FALSE;
95             TRACE("Failed to get ThemeActive: %ld\n", GetLastError());
96         }
97         buffsize = sizeof(szCurrentColor)/sizeof(szCurrentColor[0]);
98         if(RegQueryValueExW(hKey, szColorName, NULL, NULL, (LPBYTE)szCurrentColor, &buffsize))
99             szCurrentColor[0] = '\0';
100         buffsize = sizeof(szCurrentSize)/sizeof(szCurrentSize[0]);
101         if(RegQueryValueExW(hKey, szSizeName, NULL, NULL, (LPBYTE)szCurrentSize, &buffsize))
102             szCurrentSize[0] = '\0';
103         if(SHRegGetPathW(hKey, NULL, szDllName, szCurrentTheme, 0))
104             szCurrentTheme[0] = '\0';
105         RegCloseKey(hKey);
106     }
107     else
108         TRACE("Failed to open theme registry key\n");
109
110     if(bThemeActive) {
111         /* Make sure the theme requested is actually valid */
112         hr = MSSTYLES_OpenThemeFile(szCurrentTheme,
113                                     szCurrentColor[0]?szCurrentColor:NULL,
114                                     szCurrentSize[0]?szCurrentSize:NULL,
115                                     &pt);
116         if(FAILED(hr)) {
117             bThemeActive = FALSE;
118             szCurrentTheme[0] = '\0';
119             szCurrentColor[0] = '\0';
120             szCurrentSize[0] = '\0';
121         }
122         else {
123             /* Make sure the global color & size match the theme */
124             lstrcpynW(szCurrentColor, pt->pszSelectedColor, sizeof(szCurrentColor)/sizeof(szCurrentColor[0]));
125             lstrcpynW(szCurrentSize, pt->pszSelectedSize, sizeof(szCurrentSize)/sizeof(szCurrentSize[0]));
126
127             MSSTYLES_SetActiveTheme(pt);
128             TRACE("Theme active: %s %s %s\n", debugstr_w(szCurrentTheme),
129                 debugstr_w(szCurrentColor), debugstr_w(szCurrentSize));
130             MSSTYLES_CloseThemeFile(pt);
131         }
132     }
133     if(!bThemeActive) {
134         MSSTYLES_SetActiveTheme(NULL);
135         TRACE("Themeing not active\n");
136     }
137 }
138
139 /***********************************************************************
140  *      UXTHEME_SetActiveTheme
141  *
142  * Change the current active theme
143  */
144 HRESULT UXTHEME_SetActiveTheme(PTHEME_FILE tf)
145 {
146     HKEY hKey;
147     WCHAR tmp[2];
148     HRESULT hr;
149
150     hr = MSSTYLES_SetActiveTheme(tf);
151     if(FAILED(hr))
152         return hr;
153     if(tf) {
154         bThemeActive = TRUE;
155         GetModuleFileNameW(tf->hTheme, szCurrentTheme, sizeof(szCurrentTheme)/sizeof(szCurrentTheme[0]));
156         lstrcpynW(szCurrentColor, tf->pszSelectedColor, sizeof(szCurrentColor)/sizeof(szCurrentColor[0]));
157         lstrcpynW(szCurrentSize, tf->pszSelectedSize, sizeof(szCurrentSize)/sizeof(szCurrentSize[0]));
158     }
159     else {
160         bThemeActive = FALSE;
161         szCurrentTheme[0] = '\0';
162         szCurrentColor[0] = '\0';
163         szCurrentSize[0] = '\0';
164         return MSSTYLES_SetActiveTheme(NULL);
165     }
166
167     TRACE("Writing theme config to registry\n");
168     if(!RegCreateKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
169         tmp[0] = bThemeActive?'1':'0';
170         tmp[1] = '\0';
171         RegSetValueExW(hKey, szThemeActive, 0, REG_SZ, (const BYTE*)tmp, sizeof(WCHAR)*2);
172         RegSetValueExW(hKey, szColorName, 0, REG_SZ, (const BYTE*)szCurrentColor, lstrlenW(szCurrentColor)+1);
173         RegSetValueExW(hKey, szSizeName, 0, REG_SZ, (const BYTE*)szCurrentSize, lstrlenW(szCurrentSize)+1);
174         RegSetValueExW(hKey, szDllName, 0, REG_SZ, (const BYTE*)szCurrentTheme, lstrlenW(szCurrentTheme)+1);
175         RegCloseKey(hKey);
176     }
177     else
178         TRACE("Failed to open theme registry key\n");
179     return hr;
180 }
181
182 /***********************************************************************
183  *      UXTHEME_InitSystem
184  */
185 void UXTHEME_InitSystem(HINSTANCE hInst)
186 {
187     const WCHAR szWindowTheme[] = {
188         'u','x','_','t','h','e','m','e','\0'
189     };
190     const WCHAR szSubAppName[] = {
191         'u','x','_','s','u','b','a','p','p','\0'
192     };
193     const WCHAR szSubIdList[] = {
194         'u','x','_','s','u','b','i','d','l','s','t','\0'
195     };
196
197     hDllInst = hInst;
198
199     atWindowTheme = GlobalAddAtomW(szWindowTheme);
200     atSubAppName  = GlobalAddAtomW(szSubAppName);
201     atSubIdList   = GlobalAddAtomW(szSubIdList);
202
203     UXTHEME_LoadTheme();
204 }
205
206 /***********************************************************************
207  *      IsAppThemed                                         (UXTHEME.@)
208  */
209 BOOL WINAPI IsAppThemed(void)
210 {
211     return IsThemeActive();
212 }
213
214 /***********************************************************************
215  *      IsThemeActive                                       (UXTHEME.@)
216  */
217 BOOL WINAPI IsThemeActive(void)
218 {
219     TRACE("\n");
220     return bThemeActive;
221 }
222
223 /***********************************************************************
224  *      EnableTheming                                       (UXTHEME.@)
225  *
226  * NOTES
227  * This is a global and persistent change
228  */
229 HRESULT WINAPI EnableTheming(BOOL fEnable)
230 {
231     HKEY hKey;
232     WCHAR szEnabled[] = {'0','\0'};
233
234     TRACE("(%d)\n", fEnable);
235
236     if(fEnable != bThemeActive) {
237         bThemeActive = fEnable;
238         if(bThemeActive) szEnabled[0] = '1';
239         if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
240             RegSetValueExW(hKey, szThemeActive, 0, REG_SZ, (LPBYTE)szEnabled, sizeof(WCHAR));
241             RegCloseKey(hKey);
242         }
243         PostMessageW(HWND_BROADCAST, WM_THEMECHANGED, 0, 0);
244     }
245     return S_OK;
246 }
247
248 /***********************************************************************
249  *      UXTHEME_SetWindowProperty
250  *
251  * I'm using atoms as there may be large numbers of duplicated strings
252  * and they do the work of keeping memory down as a cause of that quite nicely
253  */
254 HRESULT UXTHEME_SetWindowProperty(HWND hwnd, ATOM aProp, LPCWSTR pszValue)
255 {
256     ATOM oldValue = (ATOM)(size_t)RemovePropW(hwnd, MAKEINTATOMW(aProp));
257     if(oldValue)
258         DeleteAtom(oldValue);
259     if(pszValue) {
260         ATOM atValue = AddAtomW(pszValue);
261         if(!atValue
262            || !SetPropW(hwnd, MAKEINTATOMW(aProp), (LPWSTR)MAKEINTATOMW(atValue))) {
263             HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
264             if(atValue) DeleteAtom(atValue);
265             return hr;
266         }
267     }
268     return S_OK;
269 }
270
271 LPWSTR UXTHEME_GetWindowProperty(HWND hwnd, ATOM aProp, LPWSTR pszBuffer, int dwLen)
272 {
273     ATOM atValue = (ATOM)(size_t)GetPropW(hwnd, MAKEINTATOMW(aProp));
274     if(atValue) {
275         if(GetAtomNameW(atValue, pszBuffer, dwLen))
276             return pszBuffer;
277         TRACE("property defined, but unable to get value\n");
278     }
279     return NULL;
280 }
281
282 /***********************************************************************
283  *      OpenThemeData                                       (UXTHEME.@)
284  */
285 HTHEME WINAPI OpenThemeData(HWND hwnd, LPCWSTR pszClassList)
286 {
287     WCHAR szAppBuff[256];
288     WCHAR szClassBuff[256];
289     LPCWSTR pszAppName;
290     LPCWSTR pszUseClassList;
291     HTHEME hTheme;
292     TRACE("(%p,%s)\n", hwnd, debugstr_w(pszClassList));
293     if(!bThemeActive)
294         return NULL;
295
296     pszAppName = UXTHEME_GetWindowProperty(hwnd, atSubAppName, szAppBuff, sizeof(szAppBuff)/sizeof(szAppBuff[0]));
297     /* If SetWindowTheme was used on the window, that overrides the class list passed to this function */
298     pszUseClassList = UXTHEME_GetWindowProperty(hwnd, atSubIdList, szClassBuff, sizeof(szClassBuff)/sizeof(szClassBuff[0]));
299     if(!pszUseClassList)
300         pszUseClassList = pszClassList;
301
302     hTheme = MSSTYLES_OpenThemeClass(pszAppName, pszUseClassList);
303     if(IsWindow(hwnd))
304         SetPropW(hwnd, MAKEINTATOMW(atWindowTheme), hTheme);
305     return hTheme;
306 }
307
308 /***********************************************************************
309  *      GetWindowTheme                                      (UXTHEME.@)
310  *
311  * Retrieve the last theme opened for a window
312  */
313 HTHEME WINAPI GetWindowTheme(HWND hwnd)
314 {
315     TRACE("(%p)\n", hwnd);
316     return GetPropW(hwnd, MAKEINTATOMW(atWindowTheme));
317 }
318
319 /***********************************************************************
320  *      SetWindowTheme                                      (UXTHEME.@)
321  *
322  * Persistent through the life of the window, even after themes change
323  */
324 HRESULT WINAPI SetWindowTheme(HWND hwnd, LPCWSTR pszSubAppName,
325                               LPCWSTR pszSubIdList)
326 {
327     HRESULT hr;
328     TRACE("(%p,%s,%s)\n", hwnd, debugstr_w(pszSubAppName),
329           debugstr_w(pszSubIdList));
330     hr = UXTHEME_SetWindowProperty(hwnd, atSubAppName, pszSubAppName);
331     if(SUCCEEDED(hr))
332         hr = UXTHEME_SetWindowProperty(hwnd, atSubIdList, pszSubIdList);
333     if(SUCCEEDED(hr))
334         PostMessageW(hwnd, WM_THEMECHANGED, 0, 0);
335     return hr;
336 }
337
338 /***********************************************************************
339  *      GetCurrentThemeName                                 (UXTHEME.@)
340  */
341 HRESULT WINAPI GetCurrentThemeName(LPWSTR pszThemeFileName, int dwMaxNameChars,
342                                    LPWSTR pszColorBuff, int cchMaxColorChars,
343                                    LPWSTR pszSizeBuff, int cchMaxSizeChars)
344 {
345     if(!bThemeActive)
346         return E_PROP_ID_UNSUPPORTED;
347     if(pszThemeFileName) lstrcpynW(pszThemeFileName, szCurrentTheme, dwMaxNameChars);
348     if(pszColorBuff) lstrcpynW(pszColorBuff, szCurrentColor, cchMaxColorChars);
349     if(pszSizeBuff) lstrcpynW(pszSizeBuff, szCurrentSize, cchMaxSizeChars);
350     return S_OK;
351 }
352
353 /***********************************************************************
354  *      GetThemeAppProperties                               (UXTHEME.@)
355  */
356 DWORD WINAPI GetThemeAppProperties(void)
357 {
358     return dwThemeAppProperties;
359 }
360
361 /***********************************************************************
362  *      SetThemeAppProperties                               (UXTHEME.@)
363  */
364 void WINAPI SetThemeAppProperties(DWORD dwFlags)
365 {
366     TRACE("(0x%08lx)\n", dwFlags);
367     dwThemeAppProperties = dwFlags;
368 }
369
370 /***********************************************************************
371  *      CloseThemeData                                      (UXTHEME.@)
372  */
373 HRESULT WINAPI CloseThemeData(HTHEME hTheme)
374 {
375     TRACE("(%p)\n", hTheme);
376     if(!hTheme)
377         return E_HANDLE;
378     return MSSTYLES_CloseThemeClass(hTheme);
379 }
380
381 /***********************************************************************
382  *      HitTestThemeBackground                              (UXTHEME.@)
383  */
384 HRESULT WINAPI HitTestThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
385                                      int iStateId, DWORD dwOptions,
386                                      const RECT *pRect, HRGN hrgn,
387                                      POINT ptTest, WORD *pwHitTestCode)
388 {
389     FIXME("%d %d 0x%08lx: stub\n", iPartId, iStateId, dwOptions);
390     if(!hTheme)
391         return E_HANDLE;
392     return ERROR_CALL_NOT_IMPLEMENTED;
393 }
394
395 /***********************************************************************
396  *      IsThemePartDefined                                  (UXTHEME.@)
397  */
398 BOOL WINAPI IsThemePartDefined(HTHEME hTheme, int iPartId, int iStateId)
399 {
400     TRACE("(%p,%d,%d)\n", hTheme, iPartId, iStateId);
401     if(MSSTYLES_FindPartState(hTheme, iPartId, iStateId, NULL))
402         return TRUE;
403     return FALSE;
404 }
405
406 /***********************************************************************
407  *      GetThemeDocumentationProperty                       (UXTHEME.@)
408  *
409  * Try and retrieve the documentation property from string resources
410  * if that fails, get it from the [documentation] section of themes.ini
411  */
412 HRESULT WINAPI GetThemeDocumentationProperty(LPCWSTR pszThemeName,
413                                              LPCWSTR pszPropertyName,
414                                              LPWSTR pszValueBuff,
415                                              int cchMaxValChars)
416 {
417     const WORD wDocToRes[] = {
418         TMT_DISPLAYNAME,5000,
419         TMT_TOOLTIP,5001,
420         TMT_COMPANY,5002,
421         TMT_AUTHOR,5003,
422         TMT_COPYRIGHT,5004,
423         TMT_URL,5005,
424         TMT_VERSION,5006,
425         TMT_DESCRIPTION,5007
426     };
427
428     PTHEME_FILE pt;
429     HRESULT hr;
430     int i;
431     int iDocId;
432     TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName), debugstr_w(pszPropertyName),
433           pszValueBuff, cchMaxValChars);
434
435     hr = MSSTYLES_OpenThemeFile(pszThemeName, NULL, NULL, &pt);
436     if(FAILED(hr)) return hr;
437
438     /* Try to load from string resources */
439     hr = E_PROP_ID_UNSUPPORTED;
440     if(MSSTYLES_LookupProperty(pszPropertyName, NULL, &iDocId)) {
441         for(i=0; i<sizeof(wDocToRes)/sizeof(wDocToRes[0]); i+=2) {
442             if(wDocToRes[i] == iDocId) {
443                 if(LoadStringW(pt->hTheme, wDocToRes[i+1], pszValueBuff, cchMaxValChars)) {
444                     hr = S_OK;
445                     break;
446                 }
447             }
448         }
449     }
450     /* If loading from string resource failed, try getting it from the theme.ini */
451     if(FAILED(hr)) {
452         PUXINI_FILE uf = MSSTYLES_GetThemeIni(pt);
453         if(UXINI_FindSection(uf, szIniDocumentation)) {
454             LPCWSTR lpValue;
455             DWORD dwLen;
456             if(UXINI_FindValue(uf, pszPropertyName, &lpValue, &dwLen)) {
457                 lstrcpynW(pszValueBuff, lpValue, min(dwLen+1,cchMaxValChars));
458                 hr = S_OK;
459             }
460         }
461         UXINI_CloseINI(uf);
462     }
463
464     MSSTYLES_CloseThemeFile(pt);
465     return hr;
466 }
467
468 /**********************************************************************
469  *      Undocumented functions
470  */
471
472 /**********************************************************************
473  *      QueryThemeServices                                 (UXTHEME.1)
474  *
475  * RETURNS
476  *     some kind of status flag
477  */
478 DWORD WINAPI QueryThemeServices()
479 {
480     FIXME("stub\n");
481     return 3; /* This is what is returned under XP in most cases */
482 }
483
484
485 /**********************************************************************
486  *      OpenThemeFile                                      (UXTHEME.2)
487  *
488  * Opens a theme file, which can be used to change the current theme, etc
489  *
490  * PARAMS
491  *     pszThemeFileName    Path to a msstyles theme file
492  *     pszColorName        Color defined in the theme, eg. NormalColor
493  *     pszSizeName         Size defined in the theme, eg. NormalSize
494  *     hThemeFile          Handle to theme file
495  */
496 HRESULT WINAPI OpenThemeFile(LPCWSTR pszThemeFileName, LPCWSTR pszColorName,
497                              LPCWSTR pszSizeName, HTHEMEFILE *hThemeFile,
498                              DWORD unknown)
499 {
500     TRACE("(%s,%s,%s,%p,%ld)\n", debugstr_w(pszThemeFileName),
501           debugstr_w(pszColorName), debugstr_w(pszSizeName),
502           hThemeFile, unknown);
503     return MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, pszSizeName, (PTHEME_FILE*)hThemeFile);
504 }
505
506 /**********************************************************************
507  *      CloseThemeFile                                     (UXTHEME.3)
508  *
509  * Releases theme file handle returned by OpenThemeFile
510  *
511  * PARAMS
512  *     hThemeFile           Handle to theme file
513  */
514 HRESULT WINAPI CloseThemeFile(HTHEMEFILE hThemeFile)
515 {
516     TRACE("(%p)\n", hThemeFile);
517     MSSTYLES_CloseThemeFile(hThemeFile);
518     return S_OK;
519 }
520
521 /**********************************************************************
522  *      ApplyTheme                                         (UXTHEME.4)
523  *
524  * Set a theme file to be the currently active theme
525  *
526  * PARAMS
527  *     hThemeFile           Handle to theme file
528  *     unknown              See notes
529  *     hWnd                 Window requesting the theme change
530  *
531  * NOTES
532  * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
533  * Under XP if I pass
534  * char b[] = "";
535  *   the theme is applied with the screen redrawing really badly (flickers)
536  * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
537  *   the theme is applied smoothly (screen does not flicker)
538  * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
539  *   the function fails returning invalid parameter...very strange
540  */
541 HRESULT WINAPI ApplyTheme(HTHEMEFILE hThemeFile, char *unknown, HWND hWnd)
542 {
543     HRESULT hr;
544     TRACE("(%p,%s,%p)\n", hThemeFile, unknown, hWnd);
545     hr = UXTHEME_SetActiveTheme(hThemeFile);
546     PostMessageW(HWND_BROADCAST, WM_THEMECHANGED, 0, 0);
547     return hr;
548 }
549
550 /**********************************************************************
551  *      GetThemeDefaults                                   (UXTHEME.7)
552  *
553  * Get the default color & size for a theme
554  *
555  * PARAMS
556  *     pszThemeFileName    Path to a msstyles theme file
557  *     pszColorName        Buffer to receive the default color name
558  *     dwColorNameLen      Length, in characters, of color name buffer
559  *     pszSizeName         Buffer to receive the default size name
560  *     dwSizeNameLen       Length, in characters, of size name buffer
561  */
562 HRESULT WINAPI GetThemeDefaults(LPCWSTR pszThemeFileName, LPWSTR pszColorName,
563                                 DWORD dwColorNameLen, LPWSTR pszSizeName,
564                                 DWORD dwSizeNameLen)
565 {
566     PTHEME_FILE pt;
567     HRESULT hr;
568     TRACE("(%s,%p,%ld,%p,%ld)\n", debugstr_w(pszThemeFileName),
569           pszColorName, dwColorNameLen,
570           pszSizeName, dwSizeNameLen);
571
572     hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
573     if(FAILED(hr)) return hr;
574
575     lstrcpynW(pszColorName, pt->pszSelectedColor, dwColorNameLen);
576     lstrcpynW(pszSizeName, pt->pszSelectedSize, dwSizeNameLen);
577
578     MSSTYLES_CloseThemeFile(pt);
579     return S_OK;
580 }
581
582 /**********************************************************************
583  *      EnumThemes                                         (UXTHEME.8)
584  *
585  * Enumerate available themes, calls specified EnumThemeProc for each
586  * theme found. Passes lpData through to callback function.
587  *
588  * PARAMS
589  *     pszThemePath        Path containing themes
590  *     callback            Called for each theme found in path
591  *     lpData              Passed through to callback
592  */
593 HRESULT WINAPI EnumThemes(LPCWSTR pszThemePath, EnumThemeProc callback,
594                           LPVOID lpData)
595 {
596     FIXME("%s: stub\n", debugstr_w(pszThemePath));
597     return ERROR_CALL_NOT_IMPLEMENTED;
598 }
599
600
601 /**********************************************************************
602  *      EnumThemeColors                                    (UXTHEME.9)
603  *
604  * Enumerate theme colors available with a particular size
605  *
606  * PARAMS
607  *     pszThemeFileName    Path to a msstyles theme file
608  *     pszSizeName         Theme size to enumerate available colors
609  *                         If NULL the default theme size is used
610  *     dwColorNum          Color index to retrieve, increment from 0
611  *     pszColorName        Output color name
612  *
613  * RETURNS
614  *     S_OK on success
615  *     E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
616  *          or when pszSizeName does not refer to a valid size
617  *
618  * NOTES
619  * XP fails with E_POINTER when pszColorName points to a buffer smaller then 605
620  * characters
621  *
622  * Not very efficient that I'm opening & validating the theme every call, but
623  * this is undocumented and almost never called..
624  * (and this is how windows works too)
625  */
626 HRESULT WINAPI EnumThemeColors(LPWSTR pszThemeFileName, LPWSTR pszSizeName,
627                                DWORD dwColorNum, LPWSTR pszColorName)
628 {
629     PTHEME_FILE pt;
630     HRESULT hr;
631     LPWSTR tmp;
632     TRACE("(%s,%s,%ld)\n", debugstr_w(pszThemeFileName),
633           debugstr_w(pszSizeName), dwColorNum);
634
635     hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, pszSizeName, &pt);
636     if(FAILED(hr)) return hr;
637
638     tmp = pt->pszAvailColors;
639     while(dwColorNum && *tmp) {
640         dwColorNum--;
641         tmp += lstrlenW(tmp)+1;
642     }
643     if(!dwColorNum && *tmp) {
644         TRACE("%s\n", debugstr_w(tmp));
645         lstrcpyW(pszColorName, tmp);
646     }
647     else
648         hr = E_PROP_ID_UNSUPPORTED;
649
650     MSSTYLES_CloseThemeFile(pt);
651     return hr;
652 }
653
654 /**********************************************************************
655  *      EnumThemeSizes                                     (UXTHEME.10)
656  *
657  * Enumerate theme colors available with a particular size
658  *
659  * PARAMS
660  *     pszThemeFileName    Path to a msstyles theme file
661  *     pszColorName        Theme color to enumerate available sizes
662  *                         If NULL the default theme color is used
663  *     dwSizeNum           Size index to retrieve, increment from 0
664  *     pszSizeName         Output size name
665  *
666  * RETURNS
667  *     S_OK on success
668  *     E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
669  *          or when pszColorName does not refer to a valid color
670  *
671  * NOTES
672  * XP fails with E_POINTER when pszSizeName points to a buffer smaller then 605
673  * characters
674  *
675  * Not very efficient that I'm opening & validating the theme every call, but
676  * this is undocumented and almost never called..
677  * (and this is how windows works too)
678  */
679 HRESULT WINAPI EnumThemeSizes(LPWSTR pszThemeFileName, LPWSTR pszColorName,
680                               DWORD dwSizeNum, LPWSTR pszSizeName)
681 {
682     PTHEME_FILE pt;
683     HRESULT hr;
684     LPWSTR tmp;
685     TRACE("(%s,%s,%ld)\n", debugstr_w(pszThemeFileName),
686           debugstr_w(pszColorName), dwSizeNum);
687
688     hr = MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, NULL, &pt);
689     if(FAILED(hr)) return hr;
690
691     tmp = pt->pszAvailSizes;
692     while(dwSizeNum && *tmp) {
693         dwSizeNum--;
694         tmp += lstrlenW(tmp)+1;
695     }
696     if(!dwSizeNum && *tmp) {
697         TRACE("%s\n", debugstr_w(tmp));
698         lstrcpyW(pszSizeName, tmp);
699     }
700     else
701         hr = E_PROP_ID_UNSUPPORTED;
702
703     MSSTYLES_CloseThemeFile(pt);
704     return hr;
705 }
706
707 /**********************************************************************
708  *      ParseThemeIniFile                                  (UXTHEME.11)
709  *
710  * Enumerate data in a theme INI file.
711  *
712  * PARAMS
713  *     pszIniFileName      Path to a theme ini file
714  *     pszUnknown          Cannot be NULL, L"" is valid
715  *     callback            Called for each found entry
716  *     lpData              Passed through to callback
717  *
718  * RETURNS
719  *     S_OK on success
720  *     0x800706488 (Unknown property) when enumeration is canceled from callback
721  *
722  * NOTES
723  * When pszUnknown is NULL the callback is never called, the value does not seem to surve
724  * any other purpose
725  */
726 HRESULT WINAPI ParseThemeIniFile(LPCWSTR pszIniFileName, LPWSTR pszUnknown,
727                                  ParseThemeIniFileProc callback, LPVOID lpData)
728 {
729     FIXME("%s %s: stub\n", debugstr_w(pszIniFileName), debugstr_w(pszUnknown));
730     return ERROR_CALL_NOT_IMPLEMENTED;
731 }