msxml3: COM cleanup in domdoc.c.
[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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24 #include <stdio.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "winreg.h"
31 #include "vfwmsgs.h"
32 #include "uxtheme.h"
33 #include "tmschema.h"
34
35 #include "uxthemedll.h"
36 #include "msstyles.h"
37
38 #include "wine/debug.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
41
42 /***********************************************************************
43  * Defines and global variables
44  */
45
46 static const WCHAR szThemeManager[] = {
47     'S','o','f','t','w','a','r','e','\\',
48     'M','i','c','r','o','s','o','f','t','\\',
49     'W','i','n','d','o','w','s','\\',
50     'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
51     'T','h','e','m','e','M','a','n','a','g','e','r','\0'
52 };
53 static const WCHAR szThemeActive[] = {'T','h','e','m','e','A','c','t','i','v','e','\0'};
54 static const WCHAR szSizeName[] = {'S','i','z','e','N','a','m','e','\0'};
55 static const WCHAR szColorName[] = {'C','o','l','o','r','N','a','m','e','\0'};
56 static const WCHAR szDllName[] = {'D','l','l','N','a','m','e','\0'};
57
58 static const WCHAR szIniDocumentation[] = {'d','o','c','u','m','e','n','t','a','t','i','o','n','\0'};
59
60 HINSTANCE hDllInst;
61 ATOM atDialogThemeEnabled;
62
63 static DWORD dwThemeAppProperties = STAP_ALLOW_NONCLIENT | STAP_ALLOW_CONTROLS;
64 static ATOM atWindowTheme;
65 static ATOM atSubAppName;
66 static ATOM atSubIdList;
67
68 static BOOL bThemeActive = FALSE;
69 static WCHAR szCurrentTheme[MAX_PATH];
70 static WCHAR szCurrentColor[64];
71 static WCHAR szCurrentSize[64];
72
73 /***********************************************************************/
74
75 static BOOL CALLBACK UXTHEME_broadcast_msg_enumchild (HWND hWnd, LPARAM msg)
76 {
77     PostMessageW(hWnd, msg, 0, 0);
78     return TRUE;
79 }
80
81 /* Broadcast a message to *all* windows, including children */
82 static BOOL CALLBACK UXTHEME_broadcast_msg (HWND hWnd, LPARAM msg)
83 {
84     if (hWnd == NULL)
85     {
86         EnumWindows (UXTHEME_broadcast_msg, msg);
87     }
88     else
89     {
90         PostMessageW(hWnd, msg, 0, 0);
91         EnumChildWindows (hWnd, UXTHEME_broadcast_msg_enumchild, msg);
92     }
93     return TRUE;
94 }
95
96 /* At the end of the day this is a subset of what SHRegGetPath() does - copied
97  * here to avoid linking against shlwapi. */
98 static DWORD query_reg_path (HKEY hKey, LPCWSTR lpszValue,
99                              LPVOID pvData)
100 {
101   DWORD dwRet, dwType, dwUnExpDataLen = MAX_PATH, dwExpDataLen;
102
103   TRACE("(hkey=%p,%s,%p)\n", hKey, debugstr_w(lpszValue),
104         pvData);
105
106   dwRet = RegQueryValueExW(hKey, lpszValue, 0, &dwType, pvData, &dwUnExpDataLen);
107   if (dwRet!=ERROR_SUCCESS && dwRet!=ERROR_MORE_DATA)
108       return dwRet;
109
110   if (dwType == REG_EXPAND_SZ)
111   {
112     DWORD nBytesToAlloc;
113
114     /* Expand type REG_EXPAND_SZ into REG_SZ */
115     LPWSTR szData;
116
117     /* If the caller didn't supply a buffer or the buffer is too small we have
118      * to allocate our own
119      */
120     if (dwRet == ERROR_MORE_DATA)
121     {
122       WCHAR cNull = '\0';
123       nBytesToAlloc = dwUnExpDataLen;
124
125       szData = LocalAlloc(LMEM_ZEROINIT, nBytesToAlloc);
126       RegQueryValueExW (hKey, lpszValue, 0, NULL, (LPBYTE)szData, &nBytesToAlloc);
127       dwExpDataLen = ExpandEnvironmentStringsW(szData, &cNull, 1);
128       dwUnExpDataLen = max(nBytesToAlloc, dwExpDataLen);
129       LocalFree(szData);
130     }
131     else
132     {
133       nBytesToAlloc = (lstrlenW(pvData) + 1) * sizeof(WCHAR);
134       szData = LocalAlloc(LMEM_ZEROINIT, nBytesToAlloc );
135       lstrcpyW(szData, pvData);
136       dwExpDataLen = ExpandEnvironmentStringsW(szData, pvData, MAX_PATH );
137       if (dwExpDataLen > MAX_PATH) dwRet = ERROR_MORE_DATA;
138       dwUnExpDataLen = max(nBytesToAlloc, dwExpDataLen);
139       LocalFree(szData);
140     }
141   }
142
143   RegCloseKey(hKey);
144   return dwRet;
145 }
146
147 /***********************************************************************
148  *      UXTHEME_LoadTheme
149  *
150  * Set the current active theme from the registry
151  */
152 static void UXTHEME_LoadTheme(void)
153 {
154     HKEY hKey;
155     DWORD buffsize;
156     HRESULT hr;
157     WCHAR tmp[10];
158     PTHEME_FILE pt;
159
160     /* Get current theme configuration */
161     if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
162         TRACE("Loading theme config\n");
163         buffsize = sizeof(tmp)/sizeof(tmp[0]);
164         if(!RegQueryValueExW(hKey, szThemeActive, NULL, NULL, (LPBYTE)tmp, &buffsize)) {
165             bThemeActive = (tmp[0] != '0');
166         }
167         else {
168             bThemeActive = FALSE;
169             TRACE("Failed to get ThemeActive: %d\n", GetLastError());
170         }
171         buffsize = sizeof(szCurrentColor)/sizeof(szCurrentColor[0]);
172         if(RegQueryValueExW(hKey, szColorName, NULL, NULL, (LPBYTE)szCurrentColor, &buffsize))
173             szCurrentColor[0] = '\0';
174         buffsize = sizeof(szCurrentSize)/sizeof(szCurrentSize[0]);
175         if(RegQueryValueExW(hKey, szSizeName, NULL, NULL, (LPBYTE)szCurrentSize, &buffsize))
176             szCurrentSize[0] = '\0';
177         if (query_reg_path (hKey, szDllName, szCurrentTheme))
178             szCurrentTheme[0] = '\0';
179         RegCloseKey(hKey);
180     }
181     else
182         TRACE("Failed to open theme registry key\n");
183
184     if(bThemeActive) {
185         /* Make sure the theme requested is actually valid */
186         hr = MSSTYLES_OpenThemeFile(szCurrentTheme,
187                                     szCurrentColor[0]?szCurrentColor:NULL,
188                                     szCurrentSize[0]?szCurrentSize:NULL,
189                                     &pt);
190         if(FAILED(hr)) {
191             bThemeActive = FALSE;
192             szCurrentTheme[0] = '\0';
193             szCurrentColor[0] = '\0';
194             szCurrentSize[0] = '\0';
195         }
196         else {
197             /* Make sure the global color & size match the theme */
198             lstrcpynW(szCurrentColor, pt->pszSelectedColor, sizeof(szCurrentColor)/sizeof(szCurrentColor[0]));
199             lstrcpynW(szCurrentSize, pt->pszSelectedSize, sizeof(szCurrentSize)/sizeof(szCurrentSize[0]));
200
201             MSSTYLES_SetActiveTheme(pt, FALSE);
202             TRACE("Theme active: %s %s %s\n", debugstr_w(szCurrentTheme),
203                 debugstr_w(szCurrentColor), debugstr_w(szCurrentSize));
204             MSSTYLES_CloseThemeFile(pt);
205         }
206     }
207     if(!bThemeActive) {
208         MSSTYLES_SetActiveTheme(NULL, FALSE);
209         TRACE("Theming not active\n");
210     }
211 }
212
213 /***********************************************************************/
214
215 static const char * const SysColorsNames[] =
216 {
217     "Scrollbar",                /* COLOR_SCROLLBAR */
218     "Background",               /* COLOR_BACKGROUND */
219     "ActiveTitle",              /* COLOR_ACTIVECAPTION */
220     "InactiveTitle",            /* COLOR_INACTIVECAPTION */
221     "Menu",                     /* COLOR_MENU */
222     "Window",                   /* COLOR_WINDOW */
223     "WindowFrame",              /* COLOR_WINDOWFRAME */
224     "MenuText",                 /* COLOR_MENUTEXT */
225     "WindowText",               /* COLOR_WINDOWTEXT */
226     "TitleText",                /* COLOR_CAPTIONTEXT */
227     "ActiveBorder",             /* COLOR_ACTIVEBORDER */
228     "InactiveBorder",           /* COLOR_INACTIVEBORDER */
229     "AppWorkSpace",             /* COLOR_APPWORKSPACE */
230     "Hilight",                  /* COLOR_HIGHLIGHT */
231     "HilightText",              /* COLOR_HIGHLIGHTTEXT */
232     "ButtonFace",               /* COLOR_BTNFACE */
233     "ButtonShadow",             /* COLOR_BTNSHADOW */
234     "GrayText",                 /* COLOR_GRAYTEXT */
235     "ButtonText",               /* COLOR_BTNTEXT */
236     "InactiveTitleText",        /* COLOR_INACTIVECAPTIONTEXT */
237     "ButtonHilight",            /* COLOR_BTNHIGHLIGHT */
238     "ButtonDkShadow",           /* COLOR_3DDKSHADOW */
239     "ButtonLight",              /* COLOR_3DLIGHT */
240     "InfoText",                 /* COLOR_INFOTEXT */
241     "InfoWindow",               /* COLOR_INFOBK */
242     "ButtonAlternateFace",      /* COLOR_ALTERNATEBTNFACE */
243     "HotTrackingColor",         /* COLOR_HOTLIGHT */
244     "GradientActiveTitle",      /* COLOR_GRADIENTACTIVECAPTION */
245     "GradientInactiveTitle",    /* COLOR_GRADIENTINACTIVECAPTION */
246     "MenuHilight",              /* COLOR_MENUHILIGHT */
247     "MenuBar",                  /* COLOR_MENUBAR */
248 };
249 static const WCHAR strColorKey[] = 
250     { 'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
251       'C','o','l','o','r','s',0 };
252 static const WCHAR keyFlatMenus[] = { 'F','l','a','t','M','e','n','u', 0};
253 static const WCHAR keyGradientCaption[] = { 'G','r','a','d','i','e','n','t',
254                                             'C','a','p','t','i','o','n', 0 };
255 static const WCHAR keyNonClientMetrics[] = { 'N','o','n','C','l','i','e','n','t',
256                                              'M','e','t','r','i','c','s',0 };
257 static const WCHAR keyIconTitleFont[] = { 'I','c','o','n','T','i','t','l','e',
258                                           'F','o','n','t',0 };
259
260 static const struct BackupSysParam
261 {
262     int spiGet, spiSet;
263     const WCHAR* keyName;
264 } backupSysParams[] = 
265 {
266     {SPI_GETFLATMENU, SPI_SETFLATMENU, keyFlatMenus},
267     {SPI_GETGRADIENTCAPTIONS, SPI_SETGRADIENTCAPTIONS, keyGradientCaption},
268     {-1, -1, 0}
269 };
270
271 #define NUM_SYS_COLORS     (COLOR_MENUBAR+1)
272
273 static void save_sys_colors (HKEY baseKey)
274 {
275     char colorStr[13];
276     HKEY hKey;
277     int i;
278
279     if (RegCreateKeyExW( baseKey, strColorKey,
280                          0, 0, 0, KEY_ALL_ACCESS,
281                          0, &hKey, 0 ) == ERROR_SUCCESS)
282     {
283         for (i = 0; i < NUM_SYS_COLORS; i++)
284         {
285             COLORREF col = GetSysColor (i);
286         
287             sprintf (colorStr, "%d %d %d", 
288                 GetRValue (col), GetGValue (col), GetBValue (col));
289
290             RegSetValueExA (hKey, SysColorsNames[i], 0, REG_SZ, 
291                 (BYTE*)colorStr, strlen (colorStr)+1);
292         }
293         RegCloseKey (hKey);
294     }
295 }
296
297 /* Before activating a theme, query current system colors, certain settings 
298  * and backup them in the registry, so they can be restored when the theme 
299  * is deactivated */
300 static void UXTHEME_BackupSystemMetrics(void)
301 {
302     HKEY hKey;
303     const struct BackupSysParam* bsp = backupSysParams;
304
305     if (RegCreateKeyExW( HKEY_CURRENT_USER, szThemeManager,
306                          0, 0, 0, KEY_ALL_ACCESS,
307                          0, &hKey, 0) == ERROR_SUCCESS)
308     {
309         NONCLIENTMETRICSW ncm;
310         LOGFONTW iconTitleFont;
311         
312         /* back up colors */
313         save_sys_colors (hKey);
314     
315         /* back up "other" settings */
316         while (bsp->spiGet >= 0)
317         {
318             DWORD value;
319             
320             SystemParametersInfoW (bsp->spiGet, 0, &value, 0);
321             RegSetValueExW (hKey, bsp->keyName, 0, REG_DWORD, 
322                 (LPBYTE)&value, sizeof (value));
323         
324             bsp++;
325         }
326         
327         /* back up non-client metrics */
328         memset (&ncm, 0, sizeof (ncm));
329         ncm.cbSize = sizeof (ncm);
330         SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof (ncm), &ncm, 0);
331         RegSetValueExW (hKey, keyNonClientMetrics, 0, REG_BINARY, (LPBYTE)&ncm,
332             sizeof (ncm));
333         memset (&iconTitleFont, 0, sizeof (iconTitleFont));
334         SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof (iconTitleFont),
335             &iconTitleFont, 0);
336         RegSetValueExW (hKey, keyIconTitleFont, 0, REG_BINARY, 
337             (LPBYTE)&iconTitleFont, sizeof (iconTitleFont));
338     
339         RegCloseKey (hKey);
340     }
341 }
342
343 /* Read back old settings after a theme was deactivated */
344 static void UXTHEME_RestoreSystemMetrics(void)
345 {
346     HKEY hKey;
347     const struct BackupSysParam* bsp = backupSysParams;
348
349     if (RegOpenKeyExW (HKEY_CURRENT_USER, szThemeManager,
350                        0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) 
351     {
352         HKEY colorKey;
353     
354         /* read backed-up colors */
355         if (RegOpenKeyExW (hKey, strColorKey,
356                            0, KEY_QUERY_VALUE, &colorKey) == ERROR_SUCCESS) 
357         {
358             int i;
359             COLORREF sysCols[NUM_SYS_COLORS];
360             int sysColsIndices[NUM_SYS_COLORS];
361             int sysColCount = 0;
362         
363             for (i = 0; i < NUM_SYS_COLORS; i++)
364             {
365                 DWORD type;
366                 char colorStr[13];
367                 DWORD count = sizeof(colorStr);
368             
369                 if (RegQueryValueExA (colorKey, SysColorsNames[i], 0,
370                     &type, (LPBYTE) colorStr, &count) == ERROR_SUCCESS)
371                 {
372                     int r, g, b;
373                     if (sscanf (colorStr, "%d %d %d", &r, &g, &b) == 3)
374                     {
375                         sysColsIndices[sysColCount] = i;
376                         sysCols[sysColCount] = RGB(r, g, b);
377                         sysColCount++;
378                     }
379                 }
380             }
381             RegCloseKey (colorKey);
382           
383             SetSysColors (sysColCount, sysColsIndices, sysCols);
384         }
385     
386         /* read backed-up other settings */
387         while (bsp->spiGet >= 0)
388         {
389             DWORD value;
390             DWORD count = sizeof(value);
391             DWORD type;
392             
393             if (RegQueryValueExW (hKey, bsp->keyName, 0,
394                 &type, (LPBYTE)&value, &count) == ERROR_SUCCESS)
395             {
396                 SystemParametersInfoW (bsp->spiSet, 0, UlongToPtr(value), SPIF_UPDATEINIFILE);
397             }
398         
399             bsp++;
400         }
401     
402         /* read backed-up non-client metrics */
403         {
404             NONCLIENTMETRICSW ncm;
405             LOGFONTW iconTitleFont;
406             DWORD count = sizeof(ncm);
407             DWORD type;
408             
409             if (RegQueryValueExW (hKey, keyNonClientMetrics, 0,
410                 &type, (LPBYTE)&ncm, &count) == ERROR_SUCCESS)
411             {
412                 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS, 
413                     count, &ncm, SPIF_UPDATEINIFILE);
414             }
415             
416             count = sizeof(iconTitleFont);
417             
418             if (RegQueryValueExW (hKey, keyIconTitleFont, 0,
419                 &type, (LPBYTE)&iconTitleFont, &count) == ERROR_SUCCESS)
420             {
421                 SystemParametersInfoW (SPI_SETICONTITLELOGFONT, 
422                     count, &iconTitleFont, SPIF_UPDATEINIFILE);
423             }
424         }
425       
426         RegCloseKey (hKey);
427     }
428 }
429
430 /* Make system settings persistent, so they're in effect even w/o uxtheme 
431  * loaded.
432  * For efficiency reasons, only the last SystemParametersInfoW sets
433  * SPIF_SENDWININICHANGE */
434 static void UXTHEME_SaveSystemMetrics(void)
435 {
436     const struct BackupSysParam* bsp = backupSysParams;
437     NONCLIENTMETRICSW ncm;
438     LOGFONTW iconTitleFont;
439
440     save_sys_colors (HKEY_CURRENT_USER);
441
442     while (bsp->spiGet >= 0)
443     {
444         DWORD value;
445         
446         SystemParametersInfoW (bsp->spiGet, 0, &value, 0);
447         SystemParametersInfoW (bsp->spiSet, 0, UlongToPtr(value), SPIF_UPDATEINIFILE);
448         bsp++;
449     }
450     
451     memset (&ncm, 0, sizeof (ncm));
452     ncm.cbSize = sizeof (ncm);
453     SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof (ncm), &ncm, 0);
454     SystemParametersInfoW (SPI_SETNONCLIENTMETRICS, sizeof (ncm), &ncm,
455         SPIF_UPDATEINIFILE);
456
457     memset (&iconTitleFont, 0, sizeof (iconTitleFont));
458     SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof (iconTitleFont),
459         &iconTitleFont, 0);
460     SystemParametersInfoW (SPI_SETICONTITLELOGFONT, sizeof (iconTitleFont),
461         &iconTitleFont, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
462 }
463
464 /***********************************************************************
465  *      UXTHEME_SetActiveTheme
466  *
467  * Change the current active theme
468  */
469 static HRESULT UXTHEME_SetActiveTheme(PTHEME_FILE tf)
470 {
471     HKEY hKey;
472     WCHAR tmp[2];
473     HRESULT hr;
474
475     if(tf && !bThemeActive) UXTHEME_BackupSystemMetrics();
476     hr = MSSTYLES_SetActiveTheme(tf, TRUE);
477     if(FAILED(hr))
478         return hr;
479     if(tf) {
480         bThemeActive = TRUE;
481         lstrcpynW(szCurrentTheme, tf->szThemeFile, sizeof(szCurrentTheme)/sizeof(szCurrentTheme[0]));
482         lstrcpynW(szCurrentColor, tf->pszSelectedColor, sizeof(szCurrentColor)/sizeof(szCurrentColor[0]));
483         lstrcpynW(szCurrentSize, tf->pszSelectedSize, sizeof(szCurrentSize)/sizeof(szCurrentSize[0]));
484     }
485     else {
486         UXTHEME_RestoreSystemMetrics();
487         bThemeActive = FALSE;
488         szCurrentTheme[0] = '\0';
489         szCurrentColor[0] = '\0';
490         szCurrentSize[0] = '\0';
491     }
492
493     TRACE("Writing theme config to registry\n");
494     if(!RegCreateKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
495         tmp[0] = bThemeActive?'1':'0';
496         tmp[1] = '\0';
497         RegSetValueExW(hKey, szThemeActive, 0, REG_SZ, (const BYTE*)tmp, sizeof(WCHAR)*2);
498         if(bThemeActive) {
499             RegSetValueExW(hKey, szColorName, 0, REG_SZ, (const BYTE*)szCurrentColor, 
500                 (lstrlenW(szCurrentColor)+1)*sizeof(WCHAR));
501             RegSetValueExW(hKey, szSizeName, 0, REG_SZ, (const BYTE*)szCurrentSize, 
502                 (lstrlenW(szCurrentSize)+1)*sizeof(WCHAR));
503             RegSetValueExW(hKey, szDllName, 0, REG_SZ, (const BYTE*)szCurrentTheme, 
504                 (lstrlenW(szCurrentTheme)+1)*sizeof(WCHAR));
505         }
506         else {
507             RegDeleteValueW(hKey, szColorName);
508             RegDeleteValueW(hKey, szSizeName);
509             RegDeleteValueW(hKey, szDllName);
510
511         }
512         RegCloseKey(hKey);
513     }
514     else
515         TRACE("Failed to open theme registry key\n");
516     
517     UXTHEME_SaveSystemMetrics ();
518     
519     return hr;
520 }
521
522 /***********************************************************************
523  *      UXTHEME_InitSystem
524  */
525 void UXTHEME_InitSystem(HINSTANCE hInst)
526 {
527     static const WCHAR szWindowTheme[] = {
528         'u','x','_','t','h','e','m','e','\0'
529     };
530     static const WCHAR szSubAppName[] = {
531         'u','x','_','s','u','b','a','p','p','\0'
532     };
533     static const WCHAR szSubIdList[] = {
534         'u','x','_','s','u','b','i','d','l','s','t','\0'
535     };
536     static const WCHAR szDialogThemeEnabled[] = {
537         'u','x','_','d','i','a','l','o','g','t','h','e','m','e','\0'
538     };
539
540     hDllInst = hInst;
541
542     atWindowTheme        = GlobalAddAtomW(szWindowTheme);
543     atSubAppName         = GlobalAddAtomW(szSubAppName);
544     atSubIdList          = GlobalAddAtomW(szSubIdList);
545     atDialogThemeEnabled = GlobalAddAtomW(szDialogThemeEnabled);
546
547     UXTHEME_LoadTheme();
548 }
549
550 /***********************************************************************
551  *      IsAppThemed                                         (UXTHEME.@)
552  */
553 BOOL WINAPI IsAppThemed(void)
554 {
555     return IsThemeActive();
556 }
557
558 /***********************************************************************
559  *      IsThemeActive                                       (UXTHEME.@)
560  */
561 BOOL WINAPI IsThemeActive(void)
562 {
563     TRACE("\n");
564     SetLastError(ERROR_SUCCESS);
565     return bThemeActive;
566 }
567
568 /***********************************************************************
569  *      EnableTheming                                       (UXTHEME.@)
570  *
571  * NOTES
572  * This is a global and persistent change
573  */
574 HRESULT WINAPI EnableTheming(BOOL fEnable)
575 {
576     HKEY hKey;
577     WCHAR szEnabled[] = {'0','\0'};
578
579     TRACE("(%d)\n", fEnable);
580
581     if(fEnable != bThemeActive) {
582         if(fEnable) 
583             UXTHEME_BackupSystemMetrics();
584         else
585             UXTHEME_RestoreSystemMetrics();
586         UXTHEME_SaveSystemMetrics ();
587         bThemeActive = fEnable;
588         if(bThemeActive) szEnabled[0] = '1';
589         if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
590             RegSetValueExW(hKey, szThemeActive, 0, REG_SZ, (LPBYTE)szEnabled, sizeof(WCHAR));
591             RegCloseKey(hKey);
592         }
593         UXTHEME_broadcast_msg (NULL, WM_THEMECHANGED);
594     }
595     return S_OK;
596 }
597
598 /***********************************************************************
599  *      UXTHEME_SetWindowProperty
600  *
601  * I'm using atoms as there may be large numbers of duplicated strings
602  * and they do the work of keeping memory down as a cause of that quite nicely
603  */
604 static HRESULT UXTHEME_SetWindowProperty(HWND hwnd, ATOM aProp, LPCWSTR pszValue)
605 {
606     ATOM oldValue = (ATOM)(size_t)RemovePropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp));
607     if(oldValue)
608         DeleteAtom(oldValue);
609     if(pszValue) {
610         ATOM atValue = AddAtomW(pszValue);
611         if(!atValue
612            || !SetPropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp), (LPWSTR)MAKEINTATOM(atValue))) {
613             HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
614             if(atValue) DeleteAtom(atValue);
615             return hr;
616         }
617     }
618     return S_OK;
619 }
620
621 static LPWSTR UXTHEME_GetWindowProperty(HWND hwnd, ATOM aProp, LPWSTR pszBuffer, int dwLen)
622 {
623     ATOM atValue = (ATOM)(size_t)GetPropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp));
624     if(atValue) {
625         if(GetAtomNameW(atValue, pszBuffer, dwLen))
626             return pszBuffer;
627         TRACE("property defined, but unable to get value\n");
628     }
629     return NULL;
630 }
631
632 /***********************************************************************
633  *      OpenThemeDataEx                                     (UXTHEME.61)
634  */
635 HTHEME WINAPI OpenThemeDataEx(HWND hwnd, LPCWSTR pszClassList, DWORD flags)
636 {
637     WCHAR szAppBuff[256];
638     WCHAR szClassBuff[256];
639     LPCWSTR pszAppName;
640     LPCWSTR pszUseClassList;
641     HTHEME hTheme = NULL;
642     TRACE("(%p,%s, %x)\n", hwnd, debugstr_w(pszClassList), flags);
643
644     if(flags)
645         FIXME("unhandled flags: %x\n", flags);
646
647     if(bThemeActive)
648     {
649         pszAppName = UXTHEME_GetWindowProperty(hwnd, atSubAppName, szAppBuff, sizeof(szAppBuff)/sizeof(szAppBuff[0]));
650         /* If SetWindowTheme was used on the window, that overrides the class list passed to this function */
651         pszUseClassList = UXTHEME_GetWindowProperty(hwnd, atSubIdList, szClassBuff, sizeof(szClassBuff)/sizeof(szClassBuff[0]));
652         if(!pszUseClassList)
653             pszUseClassList = pszClassList;
654
655         if (pszUseClassList)
656             hTheme = MSSTYLES_OpenThemeClass(pszAppName, pszUseClassList);
657     }
658     if(IsWindow(hwnd))
659         SetPropW(hwnd, (LPCWSTR)MAKEINTATOM(atWindowTheme), hTheme);
660     TRACE(" = %p\n", hTheme);
661     return hTheme;
662 }
663
664 /***********************************************************************
665  *      OpenThemeData                                       (UXTHEME.@)
666  */
667 HTHEME WINAPI OpenThemeData(HWND hwnd, LPCWSTR classlist)
668 {
669     return OpenThemeDataEx(hwnd, classlist, 0);
670 }
671
672 /***********************************************************************
673  *      GetWindowTheme                                      (UXTHEME.@)
674  *
675  * Retrieve the last theme opened for a window.
676  *
677  * PARAMS
678  *  hwnd  [I] window to retrieve the theme for
679  *
680  * RETURNS
681  *  The most recent theme.
682  */
683 HTHEME WINAPI GetWindowTheme(HWND hwnd)
684 {
685     TRACE("(%p)\n", hwnd);
686     return GetPropW(hwnd, (LPCWSTR)MAKEINTATOM(atWindowTheme));
687 }
688
689 /***********************************************************************
690  *      SetWindowTheme                                      (UXTHEME.@)
691  *
692  * Persistent through the life of the window, even after themes change
693  */
694 HRESULT WINAPI SetWindowTheme(HWND hwnd, LPCWSTR pszSubAppName,
695                               LPCWSTR pszSubIdList)
696 {
697     HRESULT hr;
698     TRACE("(%p,%s,%s)\n", hwnd, debugstr_w(pszSubAppName),
699           debugstr_w(pszSubIdList));
700     hr = UXTHEME_SetWindowProperty(hwnd, atSubAppName, pszSubAppName);
701     if(SUCCEEDED(hr))
702         hr = UXTHEME_SetWindowProperty(hwnd, atSubIdList, pszSubIdList);
703     if(SUCCEEDED(hr))
704         UXTHEME_broadcast_msg (hwnd, WM_THEMECHANGED);
705     return hr;
706 }
707
708 /***********************************************************************
709  *      GetCurrentThemeName                                 (UXTHEME.@)
710  */
711 HRESULT WINAPI GetCurrentThemeName(LPWSTR pszThemeFileName, int dwMaxNameChars,
712                                    LPWSTR pszColorBuff, int cchMaxColorChars,
713                                    LPWSTR pszSizeBuff, int cchMaxSizeChars)
714 {
715     if(!bThemeActive)
716         return E_PROP_ID_UNSUPPORTED;
717     if(pszThemeFileName) lstrcpynW(pszThemeFileName, szCurrentTheme, dwMaxNameChars);
718     if(pszColorBuff) lstrcpynW(pszColorBuff, szCurrentColor, cchMaxColorChars);
719     if(pszSizeBuff) lstrcpynW(pszSizeBuff, szCurrentSize, cchMaxSizeChars);
720     return S_OK;
721 }
722
723 /***********************************************************************
724  *      GetThemeAppProperties                               (UXTHEME.@)
725  */
726 DWORD WINAPI GetThemeAppProperties(void)
727 {
728     return dwThemeAppProperties;
729 }
730
731 /***********************************************************************
732  *      SetThemeAppProperties                               (UXTHEME.@)
733  */
734 void WINAPI SetThemeAppProperties(DWORD dwFlags)
735 {
736     TRACE("(0x%08x)\n", dwFlags);
737     dwThemeAppProperties = dwFlags;
738 }
739
740 /***********************************************************************
741  *      CloseThemeData                                      (UXTHEME.@)
742  */
743 HRESULT WINAPI CloseThemeData(HTHEME hTheme)
744 {
745     TRACE("(%p)\n", hTheme);
746     if(!hTheme)
747         return E_HANDLE;
748     return MSSTYLES_CloseThemeClass(hTheme);
749 }
750
751 /***********************************************************************
752  *      HitTestThemeBackground                              (UXTHEME.@)
753  */
754 HRESULT WINAPI HitTestThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
755                                      int iStateId, DWORD dwOptions,
756                                      const RECT *pRect, HRGN hrgn,
757                                      POINT ptTest, WORD *pwHitTestCode)
758 {
759     FIXME("%d %d 0x%08x: stub\n", iPartId, iStateId, dwOptions);
760     if(!hTheme)
761         return E_HANDLE;
762     return ERROR_CALL_NOT_IMPLEMENTED;
763 }
764
765 /***********************************************************************
766  *      IsThemePartDefined                                  (UXTHEME.@)
767  */
768 BOOL WINAPI IsThemePartDefined(HTHEME hTheme, int iPartId, int iStateId)
769 {
770     TRACE("(%p,%d,%d)\n", hTheme, iPartId, iStateId);
771     if(!hTheme) {
772         SetLastError(E_HANDLE);
773         return FALSE;
774     }
775     if(MSSTYLES_FindPartState(hTheme, iPartId, iStateId, NULL))
776         return TRUE;
777     return FALSE;
778 }
779
780 /***********************************************************************
781  *      GetThemeDocumentationProperty                       (UXTHEME.@)
782  *
783  * Try and retrieve the documentation property from string resources
784  * if that fails, get it from the [documentation] section of themes.ini
785  */
786 HRESULT WINAPI GetThemeDocumentationProperty(LPCWSTR pszThemeName,
787                                              LPCWSTR pszPropertyName,
788                                              LPWSTR pszValueBuff,
789                                              int cchMaxValChars)
790 {
791     const WORD wDocToRes[] = {
792         TMT_DISPLAYNAME,5000,
793         TMT_TOOLTIP,5001,
794         TMT_COMPANY,5002,
795         TMT_AUTHOR,5003,
796         TMT_COPYRIGHT,5004,
797         TMT_URL,5005,
798         TMT_VERSION,5006,
799         TMT_DESCRIPTION,5007
800     };
801
802     PTHEME_FILE pt;
803     HRESULT hr;
804     unsigned int i;
805     int iDocId;
806     TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName), debugstr_w(pszPropertyName),
807           pszValueBuff, cchMaxValChars);
808
809     hr = MSSTYLES_OpenThemeFile(pszThemeName, NULL, NULL, &pt);
810     if(FAILED(hr)) return hr;
811
812     /* Try to load from string resources */
813     hr = E_PROP_ID_UNSUPPORTED;
814     if(MSSTYLES_LookupProperty(pszPropertyName, NULL, &iDocId)) {
815         for(i=0; i<sizeof(wDocToRes)/sizeof(wDocToRes[0]); i+=2) {
816             if(wDocToRes[i] == iDocId) {
817                 if(LoadStringW(pt->hTheme, wDocToRes[i+1], pszValueBuff, cchMaxValChars)) {
818                     hr = S_OK;
819                     break;
820                 }
821             }
822         }
823     }
824     /* If loading from string resource failed, try getting it from the theme.ini */
825     if(FAILED(hr)) {
826         PUXINI_FILE uf = MSSTYLES_GetThemeIni(pt);
827         if(UXINI_FindSection(uf, szIniDocumentation)) {
828             LPCWSTR lpValue;
829             DWORD dwLen;
830             if(UXINI_FindValue(uf, pszPropertyName, &lpValue, &dwLen)) {
831                 lstrcpynW(pszValueBuff, lpValue, min(dwLen+1,cchMaxValChars));
832                 hr = S_OK;
833             }
834         }
835         UXINI_CloseINI(uf);
836     }
837
838     MSSTYLES_CloseThemeFile(pt);
839     return hr;
840 }
841
842 /**********************************************************************
843  *      Undocumented functions
844  */
845
846 /**********************************************************************
847  *      QueryThemeServices                                 (UXTHEME.1)
848  *
849  * RETURNS
850  *     some kind of status flag
851  */
852 DWORD WINAPI QueryThemeServices(void)
853 {
854     FIXME("stub\n");
855     return 3; /* This is what is returned under XP in most cases */
856 }
857
858
859 /**********************************************************************
860  *      OpenThemeFile                                      (UXTHEME.2)
861  *
862  * Opens a theme file, which can be used to change the current theme, etc
863  *
864  * PARAMS
865  *     pszThemeFileName    Path to a msstyles theme file
866  *     pszColorName        Color defined in the theme, eg. NormalColor
867  *     pszSizeName         Size defined in the theme, eg. NormalSize
868  *     hThemeFile          Handle to theme file
869  *
870  * RETURNS
871  *     Success: S_OK
872  *     Failure: HRESULT error-code
873  */
874 HRESULT WINAPI OpenThemeFile(LPCWSTR pszThemeFileName, LPCWSTR pszColorName,
875                              LPCWSTR pszSizeName, HTHEMEFILE *hThemeFile,
876                              DWORD unknown)
877 {
878     TRACE("(%s,%s,%s,%p,%d)\n", debugstr_w(pszThemeFileName),
879           debugstr_w(pszColorName), debugstr_w(pszSizeName),
880           hThemeFile, unknown);
881     return MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, pszSizeName, (PTHEME_FILE*)hThemeFile);
882 }
883
884 /**********************************************************************
885  *      CloseThemeFile                                     (UXTHEME.3)
886  *
887  * Releases theme file handle returned by OpenThemeFile
888  *
889  * PARAMS
890  *     hThemeFile           Handle to theme file
891  *
892  * RETURNS
893  *     Success: S_OK
894  *     Failure: HRESULT error-code
895  */
896 HRESULT WINAPI CloseThemeFile(HTHEMEFILE hThemeFile)
897 {
898     TRACE("(%p)\n", hThemeFile);
899     MSSTYLES_CloseThemeFile(hThemeFile);
900     return S_OK;
901 }
902
903 /**********************************************************************
904  *      ApplyTheme                                         (UXTHEME.4)
905  *
906  * Set a theme file to be the currently active theme
907  *
908  * PARAMS
909  *     hThemeFile           Handle to theme file
910  *     unknown              See notes
911  *     hWnd                 Window requesting the theme change
912  *
913  * RETURNS
914  *     Success: S_OK
915  *     Failure: HRESULT error-code
916  *
917  * NOTES
918  * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
919  * Under XP if I pass
920  * char b[] = "";
921  *   the theme is applied with the screen redrawing really badly (flickers)
922  * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
923  *   the theme is applied smoothly (screen does not flicker)
924  * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
925  *   the function fails returning invalid parameter... very strange
926  */
927 HRESULT WINAPI ApplyTheme(HTHEMEFILE hThemeFile, char *unknown, HWND hWnd)
928 {
929     HRESULT hr;
930     TRACE("(%p,%s,%p)\n", hThemeFile, unknown, hWnd);
931     hr = UXTHEME_SetActiveTheme(hThemeFile);
932     UXTHEME_broadcast_msg (NULL, WM_THEMECHANGED);
933     return hr;
934 }
935
936 /**********************************************************************
937  *      GetThemeDefaults                                   (UXTHEME.7)
938  *
939  * Get the default color & size for a theme
940  *
941  * PARAMS
942  *     pszThemeFileName    Path to a msstyles theme file
943  *     pszColorName        Buffer to receive the default color name
944  *     dwColorNameLen      Length, in characters, of color name buffer
945  *     pszSizeName         Buffer to receive the default size name
946  *     dwSizeNameLen       Length, in characters, of size name buffer
947  *
948  * RETURNS
949  *     Success: S_OK
950  *     Failure: HRESULT error-code
951  */
952 HRESULT WINAPI GetThemeDefaults(LPCWSTR pszThemeFileName, LPWSTR pszColorName,
953                                 DWORD dwColorNameLen, LPWSTR pszSizeName,
954                                 DWORD dwSizeNameLen)
955 {
956     PTHEME_FILE pt;
957     HRESULT hr;
958     TRACE("(%s,%p,%d,%p,%d)\n", debugstr_w(pszThemeFileName),
959           pszColorName, dwColorNameLen,
960           pszSizeName, dwSizeNameLen);
961
962     hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
963     if(FAILED(hr)) return hr;
964
965     lstrcpynW(pszColorName, pt->pszSelectedColor, dwColorNameLen);
966     lstrcpynW(pszSizeName, pt->pszSelectedSize, dwSizeNameLen);
967
968     MSSTYLES_CloseThemeFile(pt);
969     return S_OK;
970 }
971
972 /**********************************************************************
973  *      EnumThemes                                         (UXTHEME.8)
974  *
975  * Enumerate available themes, calls specified EnumThemeProc for each
976  * theme found. Passes lpData through to callback function.
977  *
978  * PARAMS
979  *     pszThemePath        Path containing themes
980  *     callback            Called for each theme found in path
981  *     lpData              Passed through to callback
982  *
983  * RETURNS
984  *     Success: S_OK
985  *     Failure: HRESULT error-code
986  */
987 HRESULT WINAPI EnumThemes(LPCWSTR pszThemePath, EnumThemeProc callback,
988                           LPVOID lpData)
989 {
990     WCHAR szDir[MAX_PATH];
991     WCHAR szPath[MAX_PATH];
992     static const WCHAR szStar[] = {'*','.','*','\0'};
993     static const WCHAR szFormat[] = {'%','s','%','s','\\','%','s','.','m','s','s','t','y','l','e','s','\0'};
994     static const WCHAR szDisplayName[] = {'d','i','s','p','l','a','y','n','a','m','e','\0'};
995     static const WCHAR szTooltip[] = {'t','o','o','l','t','i','p','\0'};
996     WCHAR szName[60];
997     WCHAR szTip[60];
998     HANDLE hFind;
999     WIN32_FIND_DATAW wfd;
1000     HRESULT hr;
1001     size_t pathLen;
1002
1003     TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath), callback, lpData);
1004
1005     if(!pszThemePath || !callback)
1006         return E_POINTER;
1007
1008     lstrcpyW(szDir, pszThemePath);
1009     pathLen = lstrlenW (szDir);
1010     if ((pathLen > 0) && (pathLen < MAX_PATH-1) && (szDir[pathLen - 1] != '\\'))
1011     {
1012         szDir[pathLen] = '\\';
1013         szDir[pathLen+1] = 0;
1014     }
1015
1016     lstrcpyW(szPath, szDir);
1017     lstrcatW(szPath, szStar);
1018     TRACE("searching %s\n", debugstr_w(szPath));
1019
1020     hFind = FindFirstFileW(szPath, &wfd);
1021     if(hFind != INVALID_HANDLE_VALUE) {
1022         do {
1023             if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
1024                && !(wfd.cFileName[0] == '.' && ((wfd.cFileName[1] == '.' && wfd.cFileName[2] == 0) || wfd.cFileName[1] == 0))) {
1025                 wsprintfW(szPath, szFormat, szDir, wfd.cFileName, wfd.cFileName);
1026
1027                 hr = GetThemeDocumentationProperty(szPath, szDisplayName, szName, sizeof(szName)/sizeof(szName[0]));
1028                 if(SUCCEEDED(hr))
1029                     hr = GetThemeDocumentationProperty(szPath, szTooltip, szTip, sizeof(szTip)/sizeof(szTip[0]));
1030                 if(SUCCEEDED(hr)) {
1031                     TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath), debugstr_w(szName), debugstr_w(szTip), lpData);
1032                     if(!callback(NULL, szPath, szName, szTip, NULL, lpData)) {
1033                         TRACE("callback ended enum\n");
1034                         break;
1035                     }
1036                 }
1037             }
1038         } while(FindNextFileW(hFind, &wfd));
1039         FindClose(hFind);
1040     }
1041     return S_OK;
1042 }
1043
1044
1045 /**********************************************************************
1046  *      EnumThemeColors                                    (UXTHEME.9)
1047  *
1048  * Enumerate theme colors available with a particular size
1049  *
1050  * PARAMS
1051  *     pszThemeFileName    Path to a msstyles theme file
1052  *     pszSizeName         Theme size to enumerate available colors
1053  *                         If NULL the default theme size is used
1054  *     dwColorNum          Color index to retrieve, increment from 0
1055  *     pszColorNames       Output color names
1056  *
1057  * RETURNS
1058  *     S_OK on success
1059  *     E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
1060  *          or when pszSizeName does not refer to a valid size
1061  *
1062  * NOTES
1063  * XP fails with E_POINTER when pszColorNames points to a buffer smaller than 
1064  * sizeof(THEMENAMES).
1065  *
1066  * Not very efficient that I'm opening & validating the theme every call, but
1067  * this is undocumented and almost never called..
1068  * (and this is how windows works too)
1069  */
1070 HRESULT WINAPI EnumThemeColors(LPWSTR pszThemeFileName, LPWSTR pszSizeName,
1071                                DWORD dwColorNum, PTHEMENAMES pszColorNames)
1072 {
1073     PTHEME_FILE pt;
1074     HRESULT hr;
1075     LPWSTR tmp;
1076     UINT resourceId = dwColorNum + 1000;
1077     TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName),
1078           debugstr_w(pszSizeName), dwColorNum);
1079
1080     hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, pszSizeName, &pt);
1081     if(FAILED(hr)) return hr;
1082
1083     tmp = pt->pszAvailColors;
1084     while(dwColorNum && *tmp) {
1085         dwColorNum--;
1086         tmp += lstrlenW(tmp)+1;
1087     }
1088     if(!dwColorNum && *tmp) {
1089         TRACE("%s\n", debugstr_w(tmp));
1090         lstrcpyW(pszColorNames->szName, tmp);
1091         LoadStringW (pt->hTheme, resourceId,
1092             pszColorNames->szDisplayName,
1093             sizeof (pszColorNames->szDisplayName) / sizeof (WCHAR));
1094         LoadStringW (pt->hTheme, resourceId+1000,
1095             pszColorNames->szTooltip,
1096             sizeof (pszColorNames->szTooltip) / sizeof (WCHAR));
1097     }
1098     else
1099         hr = E_PROP_ID_UNSUPPORTED;
1100
1101     MSSTYLES_CloseThemeFile(pt);
1102     return hr;
1103 }
1104
1105 /**********************************************************************
1106  *      EnumThemeSizes                                     (UXTHEME.10)
1107  *
1108  * Enumerate theme colors available with a particular size
1109  *
1110  * PARAMS
1111  *     pszThemeFileName    Path to a msstyles theme file
1112  *     pszColorName        Theme color to enumerate available sizes
1113  *                         If NULL the default theme color is used
1114  *     dwSizeNum           Size index to retrieve, increment from 0
1115  *     pszSizeNames        Output size names
1116  *
1117  * RETURNS
1118  *     S_OK on success
1119  *     E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
1120  *          or when pszColorName does not refer to a valid color
1121  *
1122  * NOTES
1123  * XP fails with E_POINTER when pszSizeNames points to a buffer smaller than 
1124  * sizeof(THEMENAMES).
1125  *
1126  * Not very efficient that I'm opening & validating the theme every call, but
1127  * this is undocumented and almost never called..
1128  * (and this is how windows works too)
1129  */
1130 HRESULT WINAPI EnumThemeSizes(LPWSTR pszThemeFileName, LPWSTR pszColorName,
1131                               DWORD dwSizeNum, PTHEMENAMES pszSizeNames)
1132 {
1133     PTHEME_FILE pt;
1134     HRESULT hr;
1135     LPWSTR tmp;
1136     UINT resourceId = dwSizeNum + 3000;
1137     TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName),
1138           debugstr_w(pszColorName), dwSizeNum);
1139
1140     hr = MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, NULL, &pt);
1141     if(FAILED(hr)) return hr;
1142
1143     tmp = pt->pszAvailSizes;
1144     while(dwSizeNum && *tmp) {
1145         dwSizeNum--;
1146         tmp += lstrlenW(tmp)+1;
1147     }
1148     if(!dwSizeNum && *tmp) {
1149         TRACE("%s\n", debugstr_w(tmp));
1150         lstrcpyW(pszSizeNames->szName, tmp);
1151         LoadStringW (pt->hTheme, resourceId,
1152             pszSizeNames->szDisplayName,
1153             sizeof (pszSizeNames->szDisplayName) / sizeof (WCHAR));
1154         LoadStringW (pt->hTheme, resourceId+1000,
1155             pszSizeNames->szTooltip,
1156             sizeof (pszSizeNames->szTooltip) / sizeof (WCHAR));
1157     }
1158     else
1159         hr = E_PROP_ID_UNSUPPORTED;
1160
1161     MSSTYLES_CloseThemeFile(pt);
1162     return hr;
1163 }
1164
1165 /**********************************************************************
1166  *      ParseThemeIniFile                                  (UXTHEME.11)
1167  *
1168  * Enumerate data in a theme INI file.
1169  *
1170  * PARAMS
1171  *     pszIniFileName      Path to a theme ini file
1172  *     pszUnknown          Cannot be NULL, L"" is valid
1173  *     callback            Called for each found entry
1174  *     lpData              Passed through to callback
1175  *
1176  * RETURNS
1177  *     S_OK on success
1178  *     0x800706488 (Unknown property) when enumeration is canceled from callback
1179  *
1180  * NOTES
1181  * When pszUnknown is NULL the callback is never called, the value does not seem to serve
1182  * any other purpose
1183  */
1184 HRESULT WINAPI ParseThemeIniFile(LPCWSTR pszIniFileName, LPWSTR pszUnknown,
1185                                  ParseThemeIniFileProc callback, LPVOID lpData)
1186 {
1187     FIXME("%s %s: stub\n", debugstr_w(pszIniFileName), debugstr_w(pszUnknown));
1188     return ERROR_CALL_NOT_IMPLEMENTED;
1189 }
1190
1191 /**********************************************************************
1192  *      CheckThemeSignature                                (UXTHEME.29)
1193  *
1194  * Validates the signature of a theme file
1195  *
1196  * PARAMS
1197  *     pszIniFileName      Path to a theme file
1198  *
1199  * RETURNS
1200  *     Success: S_OK
1201  *     Failure: HRESULT error-code
1202  */
1203 HRESULT WINAPI CheckThemeSignature(LPCWSTR pszThemeFileName)
1204 {
1205     PTHEME_FILE pt;
1206     HRESULT hr;
1207     TRACE("(%s)\n", debugstr_w(pszThemeFileName));
1208     hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
1209     if(FAILED(hr))
1210         return hr;
1211     MSSTYLES_CloseThemeFile(pt);
1212     return S_OK;
1213 }