kernel32: Remove unused Wine debug channel.
[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((HLOCAL) 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((HLOCAL) 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, (LPVOID)value,
397                     SPIF_UPDATEINIFILE);
398             }
399         
400             bsp++;
401         }
402     
403         /* read backed-up non-client metrics */
404         {
405             NONCLIENTMETRICSW ncm;
406             LOGFONTW iconTitleFont;
407             DWORD count = sizeof(ncm);
408             DWORD type;
409             
410             if (RegQueryValueExW (hKey, keyNonClientMetrics, 0,
411                 &type, (LPBYTE)&ncm, &count) == ERROR_SUCCESS)
412             {
413                 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS, 
414                     count, (LPVOID)&ncm, SPIF_UPDATEINIFILE);
415             }
416             
417             count = sizeof(iconTitleFont);
418             
419             if (RegQueryValueExW (hKey, keyIconTitleFont, 0,
420                 &type, (LPBYTE)&iconTitleFont, &count) == ERROR_SUCCESS)
421             {
422                 SystemParametersInfoW (SPI_SETICONTITLELOGFONT, 
423                     count, (LPVOID)&iconTitleFont, SPIF_UPDATEINIFILE);
424             }
425         }
426       
427         RegCloseKey (hKey);
428     }
429 }
430
431 /* Make system settings persistent, so they're in effect even w/o uxtheme 
432  * loaded.
433  * For efficiency reasons, only the last SystemParametersInfoW sets
434  * SPIF_SENDWININICHANGE */
435 static void UXTHEME_SaveSystemMetrics(void)
436 {
437     const struct BackupSysParam* bsp = backupSysParams;
438     NONCLIENTMETRICSW ncm;
439     LOGFONTW iconTitleFont;
440
441     save_sys_colors (HKEY_CURRENT_USER);
442
443     while (bsp->spiGet >= 0)
444     {
445         DWORD value;
446         
447         SystemParametersInfoW (bsp->spiGet, 0, &value, 0);
448         SystemParametersInfoW (bsp->spiSet, 0, (LPVOID)value,
449             SPIF_UPDATEINIFILE);
450     
451         bsp++;
452     }
453     
454     memset (&ncm, 0, sizeof (ncm));
455     ncm.cbSize = sizeof (ncm);
456     SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, 
457         sizeof (ncm), (LPVOID)&ncm, 0);
458     SystemParametersInfoW (SPI_SETNONCLIENTMETRICS, 
459         sizeof (ncm), (LPVOID)&ncm, SPIF_UPDATEINIFILE);
460
461     memset (&iconTitleFont, 0, sizeof (iconTitleFont));
462     SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 
463         sizeof (iconTitleFont), (LPVOID)&iconTitleFont, 0);
464     SystemParametersInfoW (SPI_SETICONTITLELOGFONT, 
465         sizeof (iconTitleFont), (LPVOID)&iconTitleFont, 
466         SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
467 }
468
469 /***********************************************************************
470  *      UXTHEME_SetActiveTheme
471  *
472  * Change the current active theme
473  */
474 static HRESULT UXTHEME_SetActiveTheme(PTHEME_FILE tf)
475 {
476     HKEY hKey;
477     WCHAR tmp[2];
478     HRESULT hr;
479
480     if(tf && !bThemeActive) UXTHEME_BackupSystemMetrics();
481     hr = MSSTYLES_SetActiveTheme(tf, TRUE);
482     if(FAILED(hr))
483         return hr;
484     if(tf) {
485         bThemeActive = TRUE;
486         lstrcpynW(szCurrentTheme, tf->szThemeFile, sizeof(szCurrentTheme)/sizeof(szCurrentTheme[0]));
487         lstrcpynW(szCurrentColor, tf->pszSelectedColor, sizeof(szCurrentColor)/sizeof(szCurrentColor[0]));
488         lstrcpynW(szCurrentSize, tf->pszSelectedSize, sizeof(szCurrentSize)/sizeof(szCurrentSize[0]));
489     }
490     else {
491         UXTHEME_RestoreSystemMetrics();
492         bThemeActive = FALSE;
493         szCurrentTheme[0] = '\0';
494         szCurrentColor[0] = '\0';
495         szCurrentSize[0] = '\0';
496     }
497
498     TRACE("Writing theme config to registry\n");
499     if(!RegCreateKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
500         tmp[0] = bThemeActive?'1':'0';
501         tmp[1] = '\0';
502         RegSetValueExW(hKey, szThemeActive, 0, REG_SZ, (const BYTE*)tmp, sizeof(WCHAR)*2);
503         if(bThemeActive) {
504             RegSetValueExW(hKey, szColorName, 0, REG_SZ, (const BYTE*)szCurrentColor, 
505                 (lstrlenW(szCurrentColor)+1)*sizeof(WCHAR));
506             RegSetValueExW(hKey, szSizeName, 0, REG_SZ, (const BYTE*)szCurrentSize, 
507                 (lstrlenW(szCurrentSize)+1)*sizeof(WCHAR));
508             RegSetValueExW(hKey, szDllName, 0, REG_SZ, (const BYTE*)szCurrentTheme, 
509                 (lstrlenW(szCurrentTheme)+1)*sizeof(WCHAR));
510         }
511         else {
512             RegDeleteValueW(hKey, szColorName);
513             RegDeleteValueW(hKey, szSizeName);
514             RegDeleteValueW(hKey, szDllName);
515
516         }
517         RegCloseKey(hKey);
518     }
519     else
520         TRACE("Failed to open theme registry key\n");
521     
522     UXTHEME_SaveSystemMetrics ();
523     
524     return hr;
525 }
526
527 /***********************************************************************
528  *      UXTHEME_InitSystem
529  */
530 void UXTHEME_InitSystem(HINSTANCE hInst)
531 {
532     static const WCHAR szWindowTheme[] = {
533         'u','x','_','t','h','e','m','e','\0'
534     };
535     static const WCHAR szSubAppName[] = {
536         'u','x','_','s','u','b','a','p','p','\0'
537     };
538     static const WCHAR szSubIdList[] = {
539         'u','x','_','s','u','b','i','d','l','s','t','\0'
540     };
541     static const WCHAR szDialogThemeEnabled[] = {
542         'u','x','_','d','i','a','l','o','g','t','h','e','m','e','\0'
543     };
544
545     hDllInst = hInst;
546
547     atWindowTheme        = GlobalAddAtomW(szWindowTheme);
548     atSubAppName         = GlobalAddAtomW(szSubAppName);
549     atSubIdList          = GlobalAddAtomW(szSubIdList);
550     atDialogThemeEnabled = GlobalAddAtomW(szDialogThemeEnabled);
551
552     UXTHEME_LoadTheme();
553 }
554
555 /***********************************************************************
556  *      IsAppThemed                                         (UXTHEME.@)
557  */
558 BOOL WINAPI IsAppThemed(void)
559 {
560     return IsThemeActive();
561 }
562
563 /***********************************************************************
564  *      IsThemeActive                                       (UXTHEME.@)
565  */
566 BOOL WINAPI IsThemeActive(void)
567 {
568     TRACE("\n");
569     SetLastError(ERROR_SUCCESS);
570     return bThemeActive;
571 }
572
573 /***********************************************************************
574  *      EnableTheming                                       (UXTHEME.@)
575  *
576  * NOTES
577  * This is a global and persistent change
578  */
579 HRESULT WINAPI EnableTheming(BOOL fEnable)
580 {
581     HKEY hKey;
582     WCHAR szEnabled[] = {'0','\0'};
583
584     TRACE("(%d)\n", fEnable);
585
586     if(fEnable != bThemeActive) {
587         if(fEnable) 
588             UXTHEME_BackupSystemMetrics();
589         else
590             UXTHEME_RestoreSystemMetrics();
591         UXTHEME_SaveSystemMetrics ();
592         bThemeActive = fEnable;
593         if(bThemeActive) szEnabled[0] = '1';
594         if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
595             RegSetValueExW(hKey, szThemeActive, 0, REG_SZ, (LPBYTE)szEnabled, sizeof(WCHAR));
596             RegCloseKey(hKey);
597         }
598         UXTHEME_broadcast_msg (NULL, WM_THEMECHANGED);
599     }
600     return S_OK;
601 }
602
603 /***********************************************************************
604  *      UXTHEME_SetWindowProperty
605  *
606  * I'm using atoms as there may be large numbers of duplicated strings
607  * and they do the work of keeping memory down as a cause of that quite nicely
608  */
609 static HRESULT UXTHEME_SetWindowProperty(HWND hwnd, ATOM aProp, LPCWSTR pszValue)
610 {
611     ATOM oldValue = (ATOM)(size_t)RemovePropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp));
612     if(oldValue)
613         DeleteAtom(oldValue);
614     if(pszValue) {
615         ATOM atValue = AddAtomW(pszValue);
616         if(!atValue
617            || !SetPropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp), (LPWSTR)MAKEINTATOM(atValue))) {
618             HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
619             if(atValue) DeleteAtom(atValue);
620             return hr;
621         }
622     }
623     return S_OK;
624 }
625
626 static LPWSTR UXTHEME_GetWindowProperty(HWND hwnd, ATOM aProp, LPWSTR pszBuffer, int dwLen)
627 {
628     ATOM atValue = (ATOM)(size_t)GetPropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp));
629     if(atValue) {
630         if(GetAtomNameW(atValue, pszBuffer, dwLen))
631             return pszBuffer;
632         TRACE("property defined, but unable to get value\n");
633     }
634     return NULL;
635 }
636
637 /***********************************************************************
638  *      OpenThemeData                                       (UXTHEME.@)
639  */
640 HTHEME WINAPI OpenThemeData(HWND hwnd, LPCWSTR pszClassList)
641 {
642     WCHAR szAppBuff[256];
643     WCHAR szClassBuff[256];
644     LPCWSTR pszAppName;
645     LPCWSTR pszUseClassList;
646     HTHEME hTheme = NULL;
647     TRACE("(%p,%s)\n", hwnd, debugstr_w(pszClassList));
648
649     if(bThemeActive)
650     {
651         pszAppName = UXTHEME_GetWindowProperty(hwnd, atSubAppName, szAppBuff, sizeof(szAppBuff)/sizeof(szAppBuff[0]));
652         /* If SetWindowTheme was used on the window, that overrides the class list passed to this function */
653         pszUseClassList = UXTHEME_GetWindowProperty(hwnd, atSubIdList, szClassBuff, sizeof(szClassBuff)/sizeof(szClassBuff[0]));
654         if(!pszUseClassList)
655             pszUseClassList = pszClassList;
656
657         if (pszUseClassList)
658             hTheme = MSSTYLES_OpenThemeClass(pszAppName, pszUseClassList);
659     }
660     if(IsWindow(hwnd))
661         SetPropW(hwnd, (LPCWSTR)MAKEINTATOM(atWindowTheme), hTheme);
662     TRACE(" = %p\n", hTheme);
663     return hTheme;
664 }
665
666 /***********************************************************************
667  *      GetWindowTheme                                      (UXTHEME.@)
668  *
669  * Retrieve the last theme opened for a window.
670  *
671  * PARAMS
672  *  hwnd  [I] window to retrieve the theme for
673  *
674  * RETURNS
675  *  The most recent theme.
676  */
677 HTHEME WINAPI GetWindowTheme(HWND hwnd)
678 {
679     TRACE("(%p)\n", hwnd);
680     return GetPropW(hwnd, (LPCWSTR)MAKEINTATOM(atWindowTheme));
681 }
682
683 /***********************************************************************
684  *      SetWindowTheme                                      (UXTHEME.@)
685  *
686  * Persistent through the life of the window, even after themes change
687  */
688 HRESULT WINAPI SetWindowTheme(HWND hwnd, LPCWSTR pszSubAppName,
689                               LPCWSTR pszSubIdList)
690 {
691     HRESULT hr;
692     TRACE("(%p,%s,%s)\n", hwnd, debugstr_w(pszSubAppName),
693           debugstr_w(pszSubIdList));
694     hr = UXTHEME_SetWindowProperty(hwnd, atSubAppName, pszSubAppName);
695     if(SUCCEEDED(hr))
696         hr = UXTHEME_SetWindowProperty(hwnd, atSubIdList, pszSubIdList);
697     if(SUCCEEDED(hr))
698         UXTHEME_broadcast_msg (hwnd, WM_THEMECHANGED);
699     return hr;
700 }
701
702 /***********************************************************************
703  *      GetCurrentThemeName                                 (UXTHEME.@)
704  */
705 HRESULT WINAPI GetCurrentThemeName(LPWSTR pszThemeFileName, int dwMaxNameChars,
706                                    LPWSTR pszColorBuff, int cchMaxColorChars,
707                                    LPWSTR pszSizeBuff, int cchMaxSizeChars)
708 {
709     if(!bThemeActive)
710         return E_PROP_ID_UNSUPPORTED;
711     if(pszThemeFileName) lstrcpynW(pszThemeFileName, szCurrentTheme, dwMaxNameChars);
712     if(pszColorBuff) lstrcpynW(pszColorBuff, szCurrentColor, cchMaxColorChars);
713     if(pszSizeBuff) lstrcpynW(pszSizeBuff, szCurrentSize, cchMaxSizeChars);
714     return S_OK;
715 }
716
717 /***********************************************************************
718  *      GetThemeAppProperties                               (UXTHEME.@)
719  */
720 DWORD WINAPI GetThemeAppProperties(void)
721 {
722     return dwThemeAppProperties;
723 }
724
725 /***********************************************************************
726  *      SetThemeAppProperties                               (UXTHEME.@)
727  */
728 void WINAPI SetThemeAppProperties(DWORD dwFlags)
729 {
730     TRACE("(0x%08x)\n", dwFlags);
731     dwThemeAppProperties = dwFlags;
732 }
733
734 /***********************************************************************
735  *      CloseThemeData                                      (UXTHEME.@)
736  */
737 HRESULT WINAPI CloseThemeData(HTHEME hTheme)
738 {
739     TRACE("(%p)\n", hTheme);
740     if(!hTheme)
741         return E_HANDLE;
742     return MSSTYLES_CloseThemeClass(hTheme);
743 }
744
745 /***********************************************************************
746  *      HitTestThemeBackground                              (UXTHEME.@)
747  */
748 HRESULT WINAPI HitTestThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
749                                      int iStateId, DWORD dwOptions,
750                                      const RECT *pRect, HRGN hrgn,
751                                      POINT ptTest, WORD *pwHitTestCode)
752 {
753     FIXME("%d %d 0x%08x: stub\n", iPartId, iStateId, dwOptions);
754     if(!hTheme)
755         return E_HANDLE;
756     return ERROR_CALL_NOT_IMPLEMENTED;
757 }
758
759 /***********************************************************************
760  *      IsThemePartDefined                                  (UXTHEME.@)
761  */
762 BOOL WINAPI IsThemePartDefined(HTHEME hTheme, int iPartId, int iStateId)
763 {
764     TRACE("(%p,%d,%d)\n", hTheme, iPartId, iStateId);
765     if(!hTheme) {
766         SetLastError(E_HANDLE);
767         return FALSE;
768     }
769     if(MSSTYLES_FindPartState(hTheme, iPartId, iStateId, NULL))
770         return TRUE;
771     return FALSE;
772 }
773
774 /***********************************************************************
775  *      GetThemeDocumentationProperty                       (UXTHEME.@)
776  *
777  * Try and retrieve the documentation property from string resources
778  * if that fails, get it from the [documentation] section of themes.ini
779  */
780 HRESULT WINAPI GetThemeDocumentationProperty(LPCWSTR pszThemeName,
781                                              LPCWSTR pszPropertyName,
782                                              LPWSTR pszValueBuff,
783                                              int cchMaxValChars)
784 {
785     const WORD wDocToRes[] = {
786         TMT_DISPLAYNAME,5000,
787         TMT_TOOLTIP,5001,
788         TMT_COMPANY,5002,
789         TMT_AUTHOR,5003,
790         TMT_COPYRIGHT,5004,
791         TMT_URL,5005,
792         TMT_VERSION,5006,
793         TMT_DESCRIPTION,5007
794     };
795
796     PTHEME_FILE pt;
797     HRESULT hr;
798     unsigned int i;
799     int iDocId;
800     TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName), debugstr_w(pszPropertyName),
801           pszValueBuff, cchMaxValChars);
802
803     hr = MSSTYLES_OpenThemeFile(pszThemeName, NULL, NULL, &pt);
804     if(FAILED(hr)) return hr;
805
806     /* Try to load from string resources */
807     hr = E_PROP_ID_UNSUPPORTED;
808     if(MSSTYLES_LookupProperty(pszPropertyName, NULL, &iDocId)) {
809         for(i=0; i<sizeof(wDocToRes)/sizeof(wDocToRes[0]); i+=2) {
810             if(wDocToRes[i] == iDocId) {
811                 if(LoadStringW(pt->hTheme, wDocToRes[i+1], pszValueBuff, cchMaxValChars)) {
812                     hr = S_OK;
813                     break;
814                 }
815             }
816         }
817     }
818     /* If loading from string resource failed, try getting it from the theme.ini */
819     if(FAILED(hr)) {
820         PUXINI_FILE uf = MSSTYLES_GetThemeIni(pt);
821         if(UXINI_FindSection(uf, szIniDocumentation)) {
822             LPCWSTR lpValue;
823             DWORD dwLen;
824             if(UXINI_FindValue(uf, pszPropertyName, &lpValue, &dwLen)) {
825                 lstrcpynW(pszValueBuff, lpValue, min(dwLen+1,cchMaxValChars));
826                 hr = S_OK;
827             }
828         }
829         UXINI_CloseINI(uf);
830     }
831
832     MSSTYLES_CloseThemeFile(pt);
833     return hr;
834 }
835
836 /**********************************************************************
837  *      Undocumented functions
838  */
839
840 /**********************************************************************
841  *      QueryThemeServices                                 (UXTHEME.1)
842  *
843  * RETURNS
844  *     some kind of status flag
845  */
846 DWORD WINAPI QueryThemeServices(void)
847 {
848     FIXME("stub\n");
849     return 3; /* This is what is returned under XP in most cases */
850 }
851
852
853 /**********************************************************************
854  *      OpenThemeFile                                      (UXTHEME.2)
855  *
856  * Opens a theme file, which can be used to change the current theme, etc
857  *
858  * PARAMS
859  *     pszThemeFileName    Path to a msstyles theme file
860  *     pszColorName        Color defined in the theme, eg. NormalColor
861  *     pszSizeName         Size defined in the theme, eg. NormalSize
862  *     hThemeFile          Handle to theme file
863  *
864  * RETURNS
865  *     Success: S_OK
866  *     Failure: HRESULT error-code
867  */
868 HRESULT WINAPI OpenThemeFile(LPCWSTR pszThemeFileName, LPCWSTR pszColorName,
869                              LPCWSTR pszSizeName, HTHEMEFILE *hThemeFile,
870                              DWORD unknown)
871 {
872     TRACE("(%s,%s,%s,%p,%d)\n", debugstr_w(pszThemeFileName),
873           debugstr_w(pszColorName), debugstr_w(pszSizeName),
874           hThemeFile, unknown);
875     return MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, pszSizeName, (PTHEME_FILE*)hThemeFile);
876 }
877
878 /**********************************************************************
879  *      CloseThemeFile                                     (UXTHEME.3)
880  *
881  * Releases theme file handle returned by OpenThemeFile
882  *
883  * PARAMS
884  *     hThemeFile           Handle to theme file
885  *
886  * RETURNS
887  *     Success: S_OK
888  *     Failure: HRESULT error-code
889  */
890 HRESULT WINAPI CloseThemeFile(HTHEMEFILE hThemeFile)
891 {
892     TRACE("(%p)\n", hThemeFile);
893     MSSTYLES_CloseThemeFile(hThemeFile);
894     return S_OK;
895 }
896
897 /**********************************************************************
898  *      ApplyTheme                                         (UXTHEME.4)
899  *
900  * Set a theme file to be the currently active theme
901  *
902  * PARAMS
903  *     hThemeFile           Handle to theme file
904  *     unknown              See notes
905  *     hWnd                 Window requesting the theme change
906  *
907  * RETURNS
908  *     Success: S_OK
909  *     Failure: HRESULT error-code
910  *
911  * NOTES
912  * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
913  * Under XP if I pass
914  * char b[] = "";
915  *   the theme is applied with the screen redrawing really badly (flickers)
916  * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
917  *   the theme is applied smoothly (screen does not flicker)
918  * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
919  *   the function fails returning invalid parameter... very strange
920  */
921 HRESULT WINAPI ApplyTheme(HTHEMEFILE hThemeFile, char *unknown, HWND hWnd)
922 {
923     HRESULT hr;
924     TRACE("(%p,%s,%p)\n", hThemeFile, unknown, hWnd);
925     hr = UXTHEME_SetActiveTheme(hThemeFile);
926     UXTHEME_broadcast_msg (NULL, WM_THEMECHANGED);
927     return hr;
928 }
929
930 /**********************************************************************
931  *      GetThemeDefaults                                   (UXTHEME.7)
932  *
933  * Get the default color & size for a theme
934  *
935  * PARAMS
936  *     pszThemeFileName    Path to a msstyles theme file
937  *     pszColorName        Buffer to receive the default color name
938  *     dwColorNameLen      Length, in characters, of color name buffer
939  *     pszSizeName         Buffer to receive the default size name
940  *     dwSizeNameLen       Length, in characters, of size name buffer
941  *
942  * RETURNS
943  *     Success: S_OK
944  *     Failure: HRESULT error-code
945  */
946 HRESULT WINAPI GetThemeDefaults(LPCWSTR pszThemeFileName, LPWSTR pszColorName,
947                                 DWORD dwColorNameLen, LPWSTR pszSizeName,
948                                 DWORD dwSizeNameLen)
949 {
950     PTHEME_FILE pt;
951     HRESULT hr;
952     TRACE("(%s,%p,%d,%p,%d)\n", debugstr_w(pszThemeFileName),
953           pszColorName, dwColorNameLen,
954           pszSizeName, dwSizeNameLen);
955
956     hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
957     if(FAILED(hr)) return hr;
958
959     lstrcpynW(pszColorName, pt->pszSelectedColor, dwColorNameLen);
960     lstrcpynW(pszSizeName, pt->pszSelectedSize, dwSizeNameLen);
961
962     MSSTYLES_CloseThemeFile(pt);
963     return S_OK;
964 }
965
966 /**********************************************************************
967  *      EnumThemes                                         (UXTHEME.8)
968  *
969  * Enumerate available themes, calls specified EnumThemeProc for each
970  * theme found. Passes lpData through to callback function.
971  *
972  * PARAMS
973  *     pszThemePath        Path containing themes
974  *     callback            Called for each theme found in path
975  *     lpData              Passed through to callback
976  *
977  * RETURNS
978  *     Success: S_OK
979  *     Failure: HRESULT error-code
980  */
981 HRESULT WINAPI EnumThemes(LPCWSTR pszThemePath, EnumThemeProc callback,
982                           LPVOID lpData)
983 {
984     WCHAR szDir[MAX_PATH];
985     WCHAR szPath[MAX_PATH];
986     static const WCHAR szStar[] = {'*','.','*','\0'};
987     static const WCHAR szFormat[] = {'%','s','%','s','\\','%','s','.','m','s','s','t','y','l','e','s','\0'};
988     static const WCHAR szDisplayName[] = {'d','i','s','p','l','a','y','n','a','m','e','\0'};
989     static const WCHAR szTooltip[] = {'t','o','o','l','t','i','p','\0'};
990     WCHAR szName[60];
991     WCHAR szTip[60];
992     HANDLE hFind;
993     WIN32_FIND_DATAW wfd;
994     HRESULT hr;
995     size_t pathLen;
996
997     TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath), callback, lpData);
998
999     if(!pszThemePath || !callback)
1000         return E_POINTER;
1001
1002     lstrcpyW(szDir, pszThemePath);
1003     pathLen = lstrlenW (szDir);
1004     if ((pathLen > 0) && (pathLen < MAX_PATH-1) && (szDir[pathLen - 1] != '\\'))
1005     {
1006         szDir[pathLen] = '\\';
1007         szDir[pathLen+1] = 0;
1008     }
1009
1010     lstrcpyW(szPath, szDir);
1011     lstrcatW(szPath, szStar);
1012     TRACE("searching %s\n", debugstr_w(szPath));
1013
1014     hFind = FindFirstFileW(szPath, &wfd);
1015     if(hFind != INVALID_HANDLE_VALUE) {
1016         do {
1017             if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
1018                && !(wfd.cFileName[0] == '.' && ((wfd.cFileName[1] == '.' && wfd.cFileName[2] == 0) || wfd.cFileName[1] == 0))) {
1019                 wsprintfW(szPath, szFormat, szDir, wfd.cFileName, wfd.cFileName);
1020
1021                 hr = GetThemeDocumentationProperty(szPath, szDisplayName, szName, sizeof(szName)/sizeof(szName[0]));
1022                 if(SUCCEEDED(hr))
1023                     hr = GetThemeDocumentationProperty(szPath, szTooltip, szTip, sizeof(szTip)/sizeof(szTip[0]));
1024                 if(SUCCEEDED(hr)) {
1025                     TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath), debugstr_w(szName), debugstr_w(szTip), lpData);
1026                     if(!callback(NULL, szPath, szName, szTip, NULL, lpData)) {
1027                         TRACE("callback ended enum\n");
1028                         break;
1029                     }
1030                 }
1031             }
1032         } while(FindNextFileW(hFind, &wfd));
1033         FindClose(hFind);
1034     }
1035     return S_OK;
1036 }
1037
1038
1039 /**********************************************************************
1040  *      EnumThemeColors                                    (UXTHEME.9)
1041  *
1042  * Enumerate theme colors available with a particular size
1043  *
1044  * PARAMS
1045  *     pszThemeFileName    Path to a msstyles theme file
1046  *     pszSizeName         Theme size to enumerate available colors
1047  *                         If NULL the default theme size is used
1048  *     dwColorNum          Color index to retrieve, increment from 0
1049  *     pszColorNames       Output color names
1050  *
1051  * RETURNS
1052  *     S_OK on success
1053  *     E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
1054  *          or when pszSizeName does not refer to a valid size
1055  *
1056  * NOTES
1057  * XP fails with E_POINTER when pszColorNames points to a buffer smaller than 
1058  * sizeof(THEMENAMES).
1059  *
1060  * Not very efficient that I'm opening & validating the theme every call, but
1061  * this is undocumented and almost never called..
1062  * (and this is how windows works too)
1063  */
1064 HRESULT WINAPI EnumThemeColors(LPWSTR pszThemeFileName, LPWSTR pszSizeName,
1065                                DWORD dwColorNum, PTHEMENAMES pszColorNames)
1066 {
1067     PTHEME_FILE pt;
1068     HRESULT hr;
1069     LPWSTR tmp;
1070     UINT resourceId = dwColorNum + 1000;
1071     TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName),
1072           debugstr_w(pszSizeName), dwColorNum);
1073
1074     hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, pszSizeName, &pt);
1075     if(FAILED(hr)) return hr;
1076
1077     tmp = pt->pszAvailColors;
1078     while(dwColorNum && *tmp) {
1079         dwColorNum--;
1080         tmp += lstrlenW(tmp)+1;
1081     }
1082     if(!dwColorNum && *tmp) {
1083         TRACE("%s\n", debugstr_w(tmp));
1084         lstrcpyW(pszColorNames->szName, tmp);
1085         LoadStringW (pt->hTheme, resourceId,
1086             pszColorNames->szDisplayName,
1087             sizeof (pszColorNames->szDisplayName) / sizeof (WCHAR));
1088         LoadStringW (pt->hTheme, resourceId+1000,
1089             pszColorNames->szTooltip,
1090             sizeof (pszColorNames->szTooltip) / sizeof (WCHAR));
1091     }
1092     else
1093         hr = E_PROP_ID_UNSUPPORTED;
1094
1095     MSSTYLES_CloseThemeFile(pt);
1096     return hr;
1097 }
1098
1099 /**********************************************************************
1100  *      EnumThemeSizes                                     (UXTHEME.10)
1101  *
1102  * Enumerate theme colors available with a particular size
1103  *
1104  * PARAMS
1105  *     pszThemeFileName    Path to a msstyles theme file
1106  *     pszColorName        Theme color to enumerate available sizes
1107  *                         If NULL the default theme color is used
1108  *     dwSizeNum           Size index to retrieve, increment from 0
1109  *     pszSizeNames        Output size names
1110  *
1111  * RETURNS
1112  *     S_OK on success
1113  *     E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
1114  *          or when pszColorName does not refer to a valid color
1115  *
1116  * NOTES
1117  * XP fails with E_POINTER when pszSizeNames points to a buffer smaller than 
1118  * sizeof(THEMENAMES).
1119  *
1120  * Not very efficient that I'm opening & validating the theme every call, but
1121  * this is undocumented and almost never called..
1122  * (and this is how windows works too)
1123  */
1124 HRESULT WINAPI EnumThemeSizes(LPWSTR pszThemeFileName, LPWSTR pszColorName,
1125                               DWORD dwSizeNum, PTHEMENAMES pszSizeNames)
1126 {
1127     PTHEME_FILE pt;
1128     HRESULT hr;
1129     LPWSTR tmp;
1130     UINT resourceId = dwSizeNum + 3000;
1131     TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName),
1132           debugstr_w(pszColorName), dwSizeNum);
1133
1134     hr = MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, NULL, &pt);
1135     if(FAILED(hr)) return hr;
1136
1137     tmp = pt->pszAvailSizes;
1138     while(dwSizeNum && *tmp) {
1139         dwSizeNum--;
1140         tmp += lstrlenW(tmp)+1;
1141     }
1142     if(!dwSizeNum && *tmp) {
1143         TRACE("%s\n", debugstr_w(tmp));
1144         lstrcpyW(pszSizeNames->szName, tmp);
1145         LoadStringW (pt->hTheme, resourceId,
1146             pszSizeNames->szDisplayName,
1147             sizeof (pszSizeNames->szDisplayName) / sizeof (WCHAR));
1148         LoadStringW (pt->hTheme, resourceId+1000,
1149             pszSizeNames->szTooltip,
1150             sizeof (pszSizeNames->szTooltip) / sizeof (WCHAR));
1151     }
1152     else
1153         hr = E_PROP_ID_UNSUPPORTED;
1154
1155     MSSTYLES_CloseThemeFile(pt);
1156     return hr;
1157 }
1158
1159 /**********************************************************************
1160  *      ParseThemeIniFile                                  (UXTHEME.11)
1161  *
1162  * Enumerate data in a theme INI file.
1163  *
1164  * PARAMS
1165  *     pszIniFileName      Path to a theme ini file
1166  *     pszUnknown          Cannot be NULL, L"" is valid
1167  *     callback            Called for each found entry
1168  *     lpData              Passed through to callback
1169  *
1170  * RETURNS
1171  *     S_OK on success
1172  *     0x800706488 (Unknown property) when enumeration is canceled from callback
1173  *
1174  * NOTES
1175  * When pszUnknown is NULL the callback is never called, the value does not seem to serve
1176  * any other purpose
1177  */
1178 HRESULT WINAPI ParseThemeIniFile(LPCWSTR pszIniFileName, LPWSTR pszUnknown,
1179                                  ParseThemeIniFileProc callback, LPVOID lpData)
1180 {
1181     FIXME("%s %s: stub\n", debugstr_w(pszIniFileName), debugstr_w(pszUnknown));
1182     return ERROR_CALL_NOT_IMPLEMENTED;
1183 }
1184
1185 /**********************************************************************
1186  *      CheckThemeSignature                                (UXTHEME.29)
1187  *
1188  * Validates the signature of a theme file
1189  *
1190  * PARAMS
1191  *     pszIniFileName      Path to a theme file
1192  *
1193  * RETURNS
1194  *     Success: S_OK
1195  *     Failure: HRESULT error-code
1196  */
1197 HRESULT WINAPI CheckThemeSignature(LPCWSTR pszThemeFileName)
1198 {
1199     PTHEME_FILE pt;
1200     HRESULT hr;
1201     TRACE("(%s)\n", debugstr_w(pszThemeFileName));
1202     hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
1203     if(FAILED(hr))
1204         return hr;
1205     MSSTYLES_CloseThemeFile(pt);
1206     return S_OK;
1207 }