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