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