[UXTHEME] - When we set the desired app name and class name in SetWindowTheme we...
[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 {
671 DeleteAtom(oldValue);
672 }
673
674 if(pszValue)
675 {
676 ATOM atValue;
677
678 /* A string with zero lenght is not acceptatble in AddAtomW but we want to support
679 users passing an empty string meaning they want no theme for the specified window */
680 if(!pszValue[0])
681 pszValue = L"0";
682
683 atValue = AddAtomW(pszValue);
684 if (!atValue)
685 {
686 ERR("AddAtomW for %S failed with last error %d!\n", pszValue, GetLastError());
687 return HRESULT_FROM_WIN32(GetLastError());
688 }
689
690 if (!SetPropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp), (LPWSTR)MAKEINTATOM(atValue)))
691 {
692 ERR("SetPropW for atom %d failed with last error %d\n", aProp, GetLastError());
693 if(atValue) DeleteAtom(atValue);
694 return HRESULT_FROM_WIN32(GetLastError());
695 }
696 }
697 return S_OK;
698 }
699
700 static LPWSTR UXTHEME_GetWindowProperty(HWND hwnd, ATOM aProp, LPWSTR pszBuffer, int dwLen)
701 {
702 ATOM atValue = (ATOM)(size_t)GetPropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp));
703 if(atValue) {
704 if(GetAtomNameW(atValue, pszBuffer, dwLen))
705 return pszBuffer;
706 TRACE("property defined, but unable to get value\n");
707 }
708 return NULL;
709 }
710
711 static HTHEME WINAPI
712 OpenThemeDataInternal(PTHEME_FILE ThemeFile, HWND hwnd, LPCWSTR pszClassList, DWORD flags)
713 {
714 WCHAR szAppBuff[256];
715 WCHAR szClassBuff[256];
716 LPCWSTR pszAppName;
717 LPCWSTR pszUseClassList;
718 HTHEME hTheme = NULL;
719 TRACE("(%p,%s, %x)\n", hwnd, debugstr_w(pszClassList), flags);
720
721 if(!pszClassList)
722 {
723 SetLastError(E_POINTER);
724 return NULL;
725 }
726
727 if(flags)
728 FIXME("unhandled flags: %x\n", flags);
729
730 if (ThemeFile)
731 {
732 pszAppName = UXTHEME_GetWindowProperty(hwnd, atSubAppName, szAppBuff, sizeof(szAppBuff)/sizeof(szAppBuff[0]));
733 /* If SetWindowTheme was used on the window, that overrides the class list passed to this function */
734 pszUseClassList = UXTHEME_GetWindowProperty(hwnd, atSubIdList, szClassBuff, sizeof(szClassBuff)/sizeof(szClassBuff[0]));
735 if(!pszUseClassList)
736 pszUseClassList = pszClassList;
737
738 if (pszUseClassList)
739 {
740 if (!ThemeFile->classes)
741 MSSTYLES_ParseThemeIni(ThemeFile);
742 hTheme = MSSTYLES_OpenThemeClass(ThemeFile, pszAppName, pszUseClassList);
743 }
744 }
745
746 if(IsWindow(hwnd))
747 {
748 SetPropW(hwnd, (LPCWSTR)MAKEINTATOM(atWindowTheme), hTheme);
749 }
750 else
751 {
752 SetLastError(E_PROP_ID_UNSUPPORTED);
753 }
754
755 SetLastError(hTheme ? ERROR_SUCCESS : E_PROP_ID_UNSUPPORTED);
756
757 TRACE(" = %p\n", hTheme);
758 return hTheme;
759 }
760
761 /***********************************************************************
762 * OpenThemeDataEx (UXTHEME.61)
763 */
764 HTHEME WINAPI OpenThemeDataEx(HWND hwnd, LPCWSTR pszClassList, DWORD flags)
765 {
766 return OpenThemeDataInternal(ActiveThemeFile, hwnd, pszClassList, flags);
767 }
768
769 /***********************************************************************
770 * OpenThemeDataFromFile (UXTHEME.16)
771 */
772 HTHEME WINAPI OpenThemeDataFromFile(HTHEMEFILE hThemeFile, HWND hwnd, LPCWSTR pszClassList, DWORD flags)
773 {
774 return OpenThemeDataInternal((PTHEME_FILE)hThemeFile, hwnd, pszClassList, flags);
775 }
776
777 /***********************************************************************
778 * OpenThemeData (UXTHEME.@)
779 */
780 HTHEME WINAPI OpenThemeData(HWND hwnd, LPCWSTR classlist)
781 {
782 return OpenThemeDataInternal(ActiveThemeFile, hwnd, classlist, 0);
783 }
784
785 /***********************************************************************
786 * GetWindowTheme (UXTHEME.@)
787 *
788 * Retrieve the last theme opened for a window.
789 *
790 * PARAMS
791 * hwnd [I] window to retrieve the theme for
792 *
793 * RETURNS
794 * The most recent theme.
795 */
796 HTHEME WINAPI GetWindowTheme(HWND hwnd)
797 {
798 TRACE("(%p)\n", hwnd);
799
800 if(!IsWindow(hwnd))
801 {
802 SetLastError(E_HANDLE);
803 return NULL;
804 }
805
806 return GetPropW(hwnd, (LPCWSTR)MAKEINTATOM(atWindowTheme));
807 }
808
809 /***********************************************************************
810 * SetWindowTheme (UXTHEME.@)
811 *
812 * Persistent through the life of the window, even after themes change
813 */
814 HRESULT WINAPI SetWindowTheme(HWND hwnd, LPCWSTR pszSubAppName,
815 LPCWSTR pszSubIdList)
816 {
817 HRESULT hr;
818 TRACE("(%p,%s,%s)\n", hwnd, debugstr_w(pszSubAppName),
819 debugstr_w(pszSubIdList));
820
821 if(!IsWindow(hwnd))
822 return E_HANDLE;
823
824 hr = UXTHEME_SetWindowProperty(hwnd, atSubAppName, pszSubAppName);
825 if (!SUCCEEDED(hr))
826 return hr;
827
828 hr = UXTHEME_SetWindowProperty(hwnd, atSubIdList, pszSubIdList);
829 if (!SUCCEEDED(hr))
830 return hr;
831
832 UXTHEME_broadcast_msg (hwnd, WM_THEMECHANGED);
833 return hr;
834 }
835
836 /***********************************************************************
837 * GetCurrentThemeName (UXTHEME.@)
838 */
839 HRESULT WINAPI GetCurrentThemeName(LPWSTR pszThemeFileName, int dwMaxNameChars,
840 LPWSTR pszColorBuff, int cchMaxColorChars,
841 LPWSTR pszSizeBuff, int cchMaxSizeChars)
842 {
843 int cchar;
844
845 if(ActiveThemeFile == NULL)
846 return E_PROP_ID_UNSUPPORTED;
847
848 if (pszThemeFileName && dwMaxNameChars)
849 {
850 cchar = lstrlenW(ActiveThemeFile->szThemeFile) + 1;
851 if(cchar > dwMaxNameChars)
852 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
853 lstrcpynW(pszThemeFileName, ActiveThemeFile->szThemeFile, cchar);
854 }
855
856 if (pszColorBuff && cchMaxColorChars)
857 {
858 cchar = lstrlenW(ActiveThemeFile->pszSelectedColor) + 1;
859 if(cchar > cchMaxColorChars)
860 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
861 lstrcpynW(pszColorBuff, ActiveThemeFile->pszSelectedColor, cchar);
862 }
863
864 if (pszSizeBuff && cchMaxSizeChars)
865 {
866 cchar = lstrlenW(ActiveThemeFile->pszSelectedSize) + 1;
867 if(cchar > cchMaxSizeChars)
868 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
869 lstrcpynW(pszSizeBuff, ActiveThemeFile->pszSelectedSize, cchar);
870 }
871
872 return S_OK;
873 }
874
875 /***********************************************************************
876 * GetThemeAppProperties (UXTHEME.@)
877 */
878 DWORD WINAPI GetThemeAppProperties(void)
879 {
880 return dwThemeAppProperties;
881 }
882
883 /***********************************************************************
884 * SetThemeAppProperties (UXTHEME.@)
885 */
886 void WINAPI SetThemeAppProperties(DWORD dwFlags)
887 {
888 TRACE("(0x%08x)\n", dwFlags);
889 dwThemeAppProperties = dwFlags;
890 }
891
892 /***********************************************************************
893 * CloseThemeData (UXTHEME.@)
894 */
895 HRESULT WINAPI CloseThemeData(HTHEME hTheme)
896 {
897 TRACE("(%p)\n", hTheme);
898 if(!hTheme || hTheme == INVALID_HANDLE_VALUE)
899 return E_HANDLE;
900 return MSSTYLES_CloseThemeClass(hTheme);
901 }
902
903 /***********************************************************************
904 * HitTestThemeBackground (UXTHEME.@)
905 */
906 HRESULT WINAPI HitTestThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
907 int iStateId, DWORD dwOptions,
908 const RECT *pRect, HRGN hrgn,
909 POINT ptTest, WORD *pwHitTestCode)
910 {
911 FIXME("%d %d 0x%08x: stub\n", iPartId, iStateId, dwOptions);
912 if(!hTheme)
913 return E_HANDLE;
914 return E_NOTIMPL;
915 }
916
917 /***********************************************************************
918 * IsThemePartDefined (UXTHEME.@)
919 */
920 BOOL WINAPI IsThemePartDefined(HTHEME hTheme, int iPartId, int iStateId)
921 {
922 TRACE("(%p,%d,%d)\n", hTheme, iPartId, iStateId);
923 if(!hTheme) {
924 SetLastError(E_HANDLE);
925 return FALSE;
926 }
927 if(MSSTYLES_FindPartState(hTheme, iPartId, iStateId, NULL))
928 return TRUE;
929 return FALSE;
930 }
931
932 /***********************************************************************
933 * GetThemeDocumentationProperty (UXTHEME.@)
934 *
935 * Try and retrieve the documentation property from string resources
936 * if that fails, get it from the [documentation] section of themes.ini
937 */
938 HRESULT WINAPI GetThemeDocumentationProperty(LPCWSTR pszThemeName,
939 LPCWSTR pszPropertyName,
940 LPWSTR pszValueBuff,
941 int cchMaxValChars)
942 {
943 const WORD wDocToRes[] = {
944 TMT_DISPLAYNAME,5000,
945 TMT_TOOLTIP,5001,
946 TMT_COMPANY,5002,
947 TMT_AUTHOR,5003,
948 TMT_COPYRIGHT,5004,
949 TMT_URL,5005,
950 TMT_VERSION,5006,
951 TMT_DESCRIPTION,5007
952 };
953
954 PTHEME_FILE pt;
955 HRESULT hr;
956 unsigned int i;
957 int iDocId;
958 TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName), debugstr_w(pszPropertyName),
959 pszValueBuff, cchMaxValChars);
960
961 hr = MSSTYLES_OpenThemeFile(pszThemeName, NULL, NULL, &pt);
962 if(FAILED(hr)) return hr;
963
964 /* Try to load from string resources */
965 hr = E_PROP_ID_UNSUPPORTED;
966 if(MSSTYLES_LookupProperty(pszPropertyName, NULL, &iDocId)) {
967 for(i=0; i<sizeof(wDocToRes)/sizeof(wDocToRes[0]); i+=2) {
968 if(wDocToRes[i] == iDocId) {
969 if(LoadStringW(pt->hTheme, wDocToRes[i+1], pszValueBuff, cchMaxValChars)) {
970 hr = S_OK;
971 break;
972 }
973 }
974 }
975 }
976 /* If loading from string resource failed, try getting it from the theme.ini */
977 if(FAILED(hr)) {
978 PUXINI_FILE uf = MSSTYLES_GetThemeIni(pt);
979 if(UXINI_FindSection(uf, szIniDocumentation)) {
980 LPCWSTR lpValue;
981 DWORD dwLen;
982 if(UXINI_FindValue(uf, pszPropertyName, &lpValue, &dwLen)) {
983 lstrcpynW(pszValueBuff, lpValue, min(dwLen+1,cchMaxValChars));
984 hr = S_OK;
985 }
986 }
987 UXINI_CloseINI(uf);
988 }
989
990 MSSTYLES_CloseThemeFile(pt);
991 return hr;
992 }
993
994 /**********************************************************************
995 * Undocumented functions
996 */
997
998 /**********************************************************************
999 * QueryThemeServices (UXTHEME.1)
1000 *
1001 * RETURNS
1002 * some kind of status flag
1003 */
1004 DWORD WINAPI QueryThemeServices(void)
1005 {
1006 FIXME("stub\n");
1007 return 3; /* This is what is returned under XP in most cases */
1008 }
1009
1010
1011 /**********************************************************************
1012 * OpenThemeFile (UXTHEME.2)
1013 *
1014 * Opens a theme file, which can be used to change the current theme, etc
1015 *
1016 * PARAMS
1017 * pszThemeFileName Path to a msstyles theme file
1018 * pszColorName Color defined in the theme, eg. NormalColor
1019 * pszSizeName Size defined in the theme, eg. NormalSize
1020 * hThemeFile Handle to theme file
1021 *
1022 * RETURNS
1023 * Success: S_OK
1024 * Failure: HRESULT error-code
1025 */
1026 HRESULT WINAPI OpenThemeFile(LPCWSTR pszThemeFileName, LPCWSTR pszColorName,
1027 LPCWSTR pszSizeName, HTHEMEFILE *hThemeFile,
1028 DWORD unknown)
1029 {
1030 TRACE("(%s,%s,%s,%p,%d)\n", debugstr_w(pszThemeFileName),
1031 debugstr_w(pszColorName), debugstr_w(pszSizeName),
1032 hThemeFile, unknown);
1033 return MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, pszSizeName, (PTHEME_FILE*)hThemeFile);
1034 }
1035
1036 /**********************************************************************
1037 * CloseThemeFile (UXTHEME.3)
1038 *
1039 * Releases theme file handle returned by OpenThemeFile
1040 *
1041 * PARAMS
1042 * hThemeFile Handle to theme file
1043 *
1044 * RETURNS
1045 * Success: S_OK
1046 * Failure: HRESULT error-code
1047 */
1048 HRESULT WINAPI CloseThemeFile(HTHEMEFILE hThemeFile)
1049 {
1050 TRACE("(%p)\n", hThemeFile);
1051 MSSTYLES_CloseThemeFile(hThemeFile);
1052 return S_OK;
1053 }
1054
1055 /**********************************************************************
1056 * ApplyTheme (UXTHEME.4)
1057 *
1058 * Set a theme file to be the currently active theme
1059 *
1060 * PARAMS
1061 * hThemeFile Handle to theme file
1062 * unknown See notes
1063 * hWnd Window requesting the theme change
1064 *
1065 * RETURNS
1066 * Success: S_OK
1067 * Failure: HRESULT error-code
1068 *
1069 * NOTES
1070 * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
1071 * Under XP if I pass
1072 * char b[] = "";
1073 * the theme is applied with the screen redrawing really badly (flickers)
1074 * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
1075 * the theme is applied smoothly (screen does not flicker)
1076 * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
1077 * the function fails returning invalid parameter... very strange
1078 */
1079 HRESULT WINAPI ApplyTheme(HTHEMEFILE hThemeFile, char *unknown, HWND hWnd)
1080 {
1081 HRESULT hr;
1082 TRACE("(%p,%s,%p)\n", hThemeFile, unknown, hWnd);
1083 hr = UXTHEME_ApplyTheme(hThemeFile);
1084 UXTHEME_broadcast_msg (NULL, WM_THEMECHANGED);
1085 return hr;
1086 }
1087
1088 /**********************************************************************
1089 * GetThemeDefaults (UXTHEME.7)
1090 *
1091 * Get the default color & size for a theme
1092 *
1093 * PARAMS
1094 * pszThemeFileName Path to a msstyles theme file
1095 * pszColorName Buffer to receive the default color name
1096 * dwColorNameLen Length, in characters, of color name buffer
1097 * pszSizeName Buffer to receive the default size name
1098 * dwSizeNameLen Length, in characters, of size name buffer
1099 *
1100 * RETURNS
1101 * Success: S_OK
1102 * Failure: HRESULT error-code
1103 */
1104 HRESULT WINAPI GetThemeDefaults(LPCWSTR pszThemeFileName, LPWSTR pszColorName,
1105 DWORD dwColorNameLen, LPWSTR pszSizeName,
1106 DWORD dwSizeNameLen)
1107 {
1108 PTHEME_FILE pt;
1109 HRESULT hr;
1110 TRACE("(%s,%p,%d,%p,%d)\n", debugstr_w(pszThemeFileName),
1111 pszColorName, dwColorNameLen,
1112 pszSizeName, dwSizeNameLen);
1113
1114 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
1115 if(FAILED(hr)) return hr;
1116
1117 lstrcpynW(pszColorName, pt->pszSelectedColor, dwColorNameLen);
1118 lstrcpynW(pszSizeName, pt->pszSelectedSize, dwSizeNameLen);
1119
1120 MSSTYLES_CloseThemeFile(pt);
1121 return S_OK;
1122 }
1123
1124 /**********************************************************************
1125 * EnumThemes (UXTHEME.8)
1126 *
1127 * Enumerate available themes, calls specified EnumThemeProc for each
1128 * theme found. Passes lpData through to callback function.
1129 *
1130 * PARAMS
1131 * pszThemePath Path containing themes
1132 * callback Called for each theme found in path
1133 * lpData Passed through to callback
1134 *
1135 * RETURNS
1136 * Success: S_OK
1137 * Failure: HRESULT error-code
1138 */
1139 HRESULT WINAPI EnumThemes(LPCWSTR pszThemePath, ENUMTHEMEPROC callback,
1140 LPVOID lpData)
1141 {
1142 WCHAR szDir[MAX_PATH];
1143 WCHAR szPath[MAX_PATH];
1144 static const WCHAR szStar[] = {'*','.','*','\0'};
1145 static const WCHAR szFormat[] = {'%','s','%','s','\\','%','s','.','m','s','s','t','y','l','e','s','\0'};
1146 static const WCHAR szDisplayName[] = {'d','i','s','p','l','a','y','n','a','m','e','\0'};
1147 static const WCHAR szTooltip[] = {'t','o','o','l','t','i','p','\0'};
1148 WCHAR szName[60];
1149 WCHAR szTip[60];
1150 HANDLE hFind;
1151 WIN32_FIND_DATAW wfd;
1152 HRESULT hr;
1153 size_t pathLen;
1154
1155 TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath), callback, lpData);
1156
1157 if(!pszThemePath || !callback)
1158 return E_POINTER;
1159
1160 lstrcpyW(szDir, pszThemePath);
1161 pathLen = lstrlenW (szDir);
1162 if ((pathLen > 0) && (pathLen < MAX_PATH-1) && (szDir[pathLen - 1] != '\\'))
1163 {
1164 szDir[pathLen] = '\\';
1165 szDir[pathLen+1] = 0;
1166 }
1167
1168 lstrcpyW(szPath, szDir);
1169 lstrcatW(szPath, szStar);
1170 TRACE("searching %s\n", debugstr_w(szPath));
1171
1172 hFind = FindFirstFileW(szPath, &wfd);
1173 if(hFind != INVALID_HANDLE_VALUE) {
1174 do {
1175 if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
1176 && !(wfd.cFileName[0] == '.' && ((wfd.cFileName[1] == '.' && wfd.cFileName[2] == 0) || wfd.cFileName[1] == 0))) {
1177 wsprintfW(szPath, szFormat, szDir, wfd.cFileName, wfd.cFileName);
1178
1179 hr = GetThemeDocumentationProperty(szPath, szDisplayName, szName, sizeof(szName)/sizeof(szName[0]));
1180 if(SUCCEEDED(hr))
1181 hr = GetThemeDocumentationProperty(szPath, szTooltip, szTip, sizeof(szTip)/sizeof(szTip[0]));
1182 if(SUCCEEDED(hr)) {
1183 TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath), debugstr_w(szName), debugstr_w(szTip), lpData);
1184 if(!callback(NULL, szPath, szName, szTip, NULL, lpData)) {
1185 TRACE("callback ended enum\n");
1186 break;
1187 }
1188 }
1189 }
1190 } while(FindNextFileW(hFind, &wfd));
1191 FindClose(hFind);
1192 }
1193 return S_OK;
1194 }
1195
1196
1197 /**********************************************************************
1198 * EnumThemeColors (UXTHEME.9)
1199 *
1200 * Enumerate theme colors available with a particular size
1201 *
1202 * PARAMS
1203 * pszThemeFileName Path to a msstyles theme file
1204 * pszSizeName Theme size to enumerate available colors
1205 * If NULL the default theme size is used
1206 * dwColorNum Color index to retrieve, increment from 0
1207 * pszColorNames Output color names
1208 *
1209 * RETURNS
1210 * S_OK on success
1211 * E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
1212 * or when pszSizeName does not refer to a valid size
1213 *
1214 * NOTES
1215 * XP fails with E_POINTER when pszColorNames points to a buffer smaller than
1216 * sizeof(THEMENAMES).
1217 *
1218 * Not very efficient that I'm opening & validating the theme every call, but
1219 * this is undocumented and almost never called..
1220 * (and this is how windows works too)
1221 */
1222 HRESULT WINAPI EnumThemeColors(LPWSTR pszThemeFileName, LPWSTR pszSizeName,
1223 DWORD dwColorNum, PTHEMENAMES pszColorNames)
1224 {
1225 PTHEME_FILE pt;
1226 HRESULT hr;
1227 LPWSTR tmp;
1228 UINT resourceId = dwColorNum + 1000;
1229 TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName),
1230 debugstr_w(pszSizeName), dwColorNum);
1231
1232 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, pszSizeName, &pt);
1233 if(FAILED(hr)) return hr;
1234
1235 tmp = pt->pszAvailColors;
1236 while(dwColorNum && *tmp) {
1237 dwColorNum--;
1238 tmp += lstrlenW(tmp)+1;
1239 }
1240 if(!dwColorNum && *tmp) {
1241 TRACE("%s\n", debugstr_w(tmp));
1242 lstrcpyW(pszColorNames->szName, tmp);
1243 LoadStringW (pt->hTheme, resourceId,
1244 pszColorNames->szDisplayName,
1245 sizeof (pszColorNames->szDisplayName) / sizeof (WCHAR));
1246 LoadStringW (pt->hTheme, resourceId+1000,
1247 pszColorNames->szTooltip,
1248 sizeof (pszColorNames->szTooltip) / sizeof (WCHAR));
1249 }
1250 else
1251 hr = E_PROP_ID_UNSUPPORTED;
1252
1253 MSSTYLES_CloseThemeFile(pt);
1254 return hr;
1255 }
1256
1257 /**********************************************************************
1258 * EnumThemeSizes (UXTHEME.10)
1259 *
1260 * Enumerate theme colors available with a particular size
1261 *
1262 * PARAMS
1263 * pszThemeFileName Path to a msstyles theme file
1264 * pszColorName Theme color to enumerate available sizes
1265 * If NULL the default theme color is used
1266 * dwSizeNum Size index to retrieve, increment from 0
1267 * pszSizeNames Output size names
1268 *
1269 * RETURNS
1270 * S_OK on success
1271 * E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
1272 * or when pszColorName does not refer to a valid color
1273 *
1274 * NOTES
1275 * XP fails with E_POINTER when pszSizeNames points to a buffer smaller than
1276 * sizeof(THEMENAMES).
1277 *
1278 * Not very efficient that I'm opening & validating the theme every call, but
1279 * this is undocumented and almost never called..
1280 * (and this is how windows works too)
1281 */
1282 HRESULT WINAPI EnumThemeSizes(LPWSTR pszThemeFileName, LPWSTR pszColorName,
1283 DWORD dwSizeNum, PTHEMENAMES pszSizeNames)
1284 {
1285 PTHEME_FILE pt;
1286 HRESULT hr;
1287 LPWSTR tmp;
1288 UINT resourceId = dwSizeNum + 3000;
1289 TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName),
1290 debugstr_w(pszColorName), dwSizeNum);
1291
1292 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, NULL, &pt);
1293 if(FAILED(hr)) return hr;
1294
1295 tmp = pt->pszAvailSizes;
1296 while(dwSizeNum && *tmp) {
1297 dwSizeNum--;
1298 tmp += lstrlenW(tmp)+1;
1299 }
1300 if(!dwSizeNum && *tmp) {
1301 TRACE("%s\n", debugstr_w(tmp));
1302 lstrcpyW(pszSizeNames->szName, tmp);
1303 LoadStringW (pt->hTheme, resourceId,
1304 pszSizeNames->szDisplayName,
1305 sizeof (pszSizeNames->szDisplayName) / sizeof (WCHAR));
1306 LoadStringW (pt->hTheme, resourceId+1000,
1307 pszSizeNames->szTooltip,
1308 sizeof (pszSizeNames->szTooltip) / sizeof (WCHAR));
1309 }
1310 else
1311 hr = E_PROP_ID_UNSUPPORTED;
1312
1313 MSSTYLES_CloseThemeFile(pt);
1314 return hr;
1315 }
1316
1317 /**********************************************************************
1318 * ParseThemeIniFile (UXTHEME.11)
1319 *
1320 * Enumerate data in a theme INI file.
1321 *
1322 * PARAMS
1323 * pszIniFileName Path to a theme ini file
1324 * pszUnknown Cannot be NULL, L"" is valid
1325 * callback Called for each found entry
1326 * lpData Passed through to callback
1327 *
1328 * RETURNS
1329 * S_OK on success
1330 * 0x800706488 (Unknown property) when enumeration is canceled from callback
1331 *
1332 * NOTES
1333 * When pszUnknown is NULL the callback is never called, the value does not seem to serve
1334 * any other purpose
1335 */
1336 HRESULT WINAPI ParseThemeIniFile(LPCWSTR pszIniFileName, LPWSTR pszUnknown,
1337 PARSETHEMEINIFILEPROC callback, LPVOID lpData)
1338 {
1339 FIXME("%s %s: stub\n", debugstr_w(pszIniFileName), debugstr_w(pszUnknown));
1340 return E_NOTIMPL;
1341 }
1342
1343 /**********************************************************************
1344 * CheckThemeSignature (UXTHEME.29)
1345 *
1346 * Validates the signature of a theme file
1347 *
1348 * PARAMS
1349 * pszIniFileName Path to a theme file
1350 *
1351 * RETURNS
1352 * Success: S_OK
1353 * Failure: HRESULT error-code
1354 */
1355 HRESULT WINAPI CheckThemeSignature(LPCWSTR pszThemeFileName)
1356 {
1357 PTHEME_FILE pt;
1358 HRESULT hr;
1359 TRACE("(%s)\n", debugstr_w(pszThemeFileName));
1360 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
1361 if(FAILED(hr))
1362 return hr;
1363 MSSTYLES_CloseThemeFile(pt);
1364 return S_OK;
1365 }