[UXTHEME] -Fix most new tests for DrawThemeParentBackground. Hackfix CloseThemeData.
[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 SendMessageW(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 SendMessageW(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 if(IsBadReadPtr (hTheme, sizeof(THEME_CLASS))) /* This check is a hack! */
901 return E_HANDLE;
902 return MSSTYLES_CloseThemeClass(hTheme);
903 }
904
905 /***********************************************************************
906 * HitTestThemeBackground (UXTHEME.@)
907 */
908 HRESULT WINAPI HitTestThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
909 int iStateId, DWORD dwOptions,
910 const RECT *pRect, HRGN hrgn,
911 POINT ptTest, WORD *pwHitTestCode)
912 {
913 FIXME("%d %d 0x%08x: stub\n", iPartId, iStateId, dwOptions);
914 if(!hTheme)
915 return E_HANDLE;
916 return E_NOTIMPL;
917 }
918
919 /***********************************************************************
920 * IsThemePartDefined (UXTHEME.@)
921 */
922 BOOL WINAPI IsThemePartDefined(HTHEME hTheme, int iPartId, int iStateId)
923 {
924 TRACE("(%p,%d,%d)\n", hTheme, iPartId, iStateId);
925 if(!hTheme) {
926 SetLastError(E_HANDLE);
927 return FALSE;
928 }
929 if(MSSTYLES_FindPartState(hTheme, iPartId, iStateId, NULL))
930 return TRUE;
931 return FALSE;
932 }
933
934 /***********************************************************************
935 * GetThemeDocumentationProperty (UXTHEME.@)
936 *
937 * Try and retrieve the documentation property from string resources
938 * if that fails, get it from the [documentation] section of themes.ini
939 */
940 HRESULT WINAPI GetThemeDocumentationProperty(LPCWSTR pszThemeName,
941 LPCWSTR pszPropertyName,
942 LPWSTR pszValueBuff,
943 int cchMaxValChars)
944 {
945 const WORD wDocToRes[] = {
946 TMT_DISPLAYNAME,5000,
947 TMT_TOOLTIP,5001,
948 TMT_COMPANY,5002,
949 TMT_AUTHOR,5003,
950 TMT_COPYRIGHT,5004,
951 TMT_URL,5005,
952 TMT_VERSION,5006,
953 TMT_DESCRIPTION,5007
954 };
955
956 PTHEME_FILE pt;
957 HRESULT hr;
958 unsigned int i;
959 int iDocId;
960 TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName), debugstr_w(pszPropertyName),
961 pszValueBuff, cchMaxValChars);
962
963 hr = MSSTYLES_OpenThemeFile(pszThemeName, NULL, NULL, &pt);
964 if(FAILED(hr)) return hr;
965
966 /* Try to load from string resources */
967 hr = E_PROP_ID_UNSUPPORTED;
968 if(MSSTYLES_LookupProperty(pszPropertyName, NULL, &iDocId)) {
969 for(i=0; i<sizeof(wDocToRes)/sizeof(wDocToRes[0]); i+=2) {
970 if(wDocToRes[i] == iDocId) {
971 if(LoadStringW(pt->hTheme, wDocToRes[i+1], pszValueBuff, cchMaxValChars)) {
972 hr = S_OK;
973 break;
974 }
975 }
976 }
977 }
978 /* If loading from string resource failed, try getting it from the theme.ini */
979 if(FAILED(hr)) {
980 PUXINI_FILE uf = MSSTYLES_GetThemeIni(pt);
981 if(UXINI_FindSection(uf, szIniDocumentation)) {
982 LPCWSTR lpValue;
983 DWORD dwLen;
984 if(UXINI_FindValue(uf, pszPropertyName, &lpValue, &dwLen)) {
985 lstrcpynW(pszValueBuff, lpValue, min(dwLen+1,cchMaxValChars));
986 hr = S_OK;
987 }
988 }
989 UXINI_CloseINI(uf);
990 }
991
992 MSSTYLES_CloseThemeFile(pt);
993 return hr;
994 }
995
996 /**********************************************************************
997 * Undocumented functions
998 */
999
1000 /**********************************************************************
1001 * QueryThemeServices (UXTHEME.1)
1002 *
1003 * RETURNS
1004 * some kind of status flag
1005 */
1006 DWORD WINAPI QueryThemeServices(void)
1007 {
1008 FIXME("stub\n");
1009 return 3; /* This is what is returned under XP in most cases */
1010 }
1011
1012
1013 /**********************************************************************
1014 * OpenThemeFile (UXTHEME.2)
1015 *
1016 * Opens a theme file, which can be used to change the current theme, etc
1017 *
1018 * PARAMS
1019 * pszThemeFileName Path to a msstyles theme file
1020 * pszColorName Color defined in the theme, eg. NormalColor
1021 * pszSizeName Size defined in the theme, eg. NormalSize
1022 * hThemeFile Handle to theme file
1023 *
1024 * RETURNS
1025 * Success: S_OK
1026 * Failure: HRESULT error-code
1027 */
1028 HRESULT WINAPI OpenThemeFile(LPCWSTR pszThemeFileName, LPCWSTR pszColorName,
1029 LPCWSTR pszSizeName, HTHEMEFILE *hThemeFile,
1030 DWORD unknown)
1031 {
1032 TRACE("(%s,%s,%s,%p,%d)\n", debugstr_w(pszThemeFileName),
1033 debugstr_w(pszColorName), debugstr_w(pszSizeName),
1034 hThemeFile, unknown);
1035 return MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, pszSizeName, (PTHEME_FILE*)hThemeFile);
1036 }
1037
1038 /**********************************************************************
1039 * CloseThemeFile (UXTHEME.3)
1040 *
1041 * Releases theme file handle returned by OpenThemeFile
1042 *
1043 * PARAMS
1044 * hThemeFile Handle to theme file
1045 *
1046 * RETURNS
1047 * Success: S_OK
1048 * Failure: HRESULT error-code
1049 */
1050 HRESULT WINAPI CloseThemeFile(HTHEMEFILE hThemeFile)
1051 {
1052 TRACE("(%p)\n", hThemeFile);
1053 MSSTYLES_CloseThemeFile(hThemeFile);
1054 return S_OK;
1055 }
1056
1057 /**********************************************************************
1058 * ApplyTheme (UXTHEME.4)
1059 *
1060 * Set a theme file to be the currently active theme
1061 *
1062 * PARAMS
1063 * hThemeFile Handle to theme file
1064 * unknown See notes
1065 * hWnd Window requesting the theme change
1066 *
1067 * RETURNS
1068 * Success: S_OK
1069 * Failure: HRESULT error-code
1070 *
1071 * NOTES
1072 * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
1073 * Under XP if I pass
1074 * char b[] = "";
1075 * the theme is applied with the screen redrawing really badly (flickers)
1076 * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
1077 * the theme is applied smoothly (screen does not flicker)
1078 * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
1079 * the function fails returning invalid parameter... very strange
1080 */
1081 HRESULT WINAPI ApplyTheme(HTHEMEFILE hThemeFile, char *unknown, HWND hWnd)
1082 {
1083 HRESULT hr;
1084 TRACE("(%p,%s,%p)\n", hThemeFile, unknown, hWnd);
1085 hr = UXTHEME_ApplyTheme(hThemeFile);
1086 UXTHEME_broadcast_msg (NULL, WM_THEMECHANGED);
1087 return hr;
1088 }
1089
1090 /**********************************************************************
1091 * GetThemeDefaults (UXTHEME.7)
1092 *
1093 * Get the default color & size for a theme
1094 *
1095 * PARAMS
1096 * pszThemeFileName Path to a msstyles theme file
1097 * pszColorName Buffer to receive the default color name
1098 * dwColorNameLen Length, in characters, of color name buffer
1099 * pszSizeName Buffer to receive the default size name
1100 * dwSizeNameLen Length, in characters, of size name buffer
1101 *
1102 * RETURNS
1103 * Success: S_OK
1104 * Failure: HRESULT error-code
1105 */
1106 HRESULT WINAPI GetThemeDefaults(LPCWSTR pszThemeFileName, LPWSTR pszColorName,
1107 DWORD dwColorNameLen, LPWSTR pszSizeName,
1108 DWORD dwSizeNameLen)
1109 {
1110 PTHEME_FILE pt;
1111 HRESULT hr;
1112 TRACE("(%s,%p,%d,%p,%d)\n", debugstr_w(pszThemeFileName),
1113 pszColorName, dwColorNameLen,
1114 pszSizeName, dwSizeNameLen);
1115
1116 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
1117 if(FAILED(hr)) return hr;
1118
1119 lstrcpynW(pszColorName, pt->pszSelectedColor, dwColorNameLen);
1120 lstrcpynW(pszSizeName, pt->pszSelectedSize, dwSizeNameLen);
1121
1122 MSSTYLES_CloseThemeFile(pt);
1123 return S_OK;
1124 }
1125
1126 /**********************************************************************
1127 * EnumThemes (UXTHEME.8)
1128 *
1129 * Enumerate available themes, calls specified EnumThemeProc for each
1130 * theme found. Passes lpData through to callback function.
1131 *
1132 * PARAMS
1133 * pszThemePath Path containing themes
1134 * callback Called for each theme found in path
1135 * lpData Passed through to callback
1136 *
1137 * RETURNS
1138 * Success: S_OK
1139 * Failure: HRESULT error-code
1140 */
1141 HRESULT WINAPI EnumThemes(LPCWSTR pszThemePath, ENUMTHEMEPROC callback,
1142 LPVOID lpData)
1143 {
1144 WCHAR szDir[MAX_PATH];
1145 WCHAR szPath[MAX_PATH];
1146 static const WCHAR szStar[] = {'*','.','*','\0'};
1147 static const WCHAR szFormat[] = {'%','s','%','s','\\','%','s','.','m','s','s','t','y','l','e','s','\0'};
1148 static const WCHAR szDisplayName[] = {'d','i','s','p','l','a','y','n','a','m','e','\0'};
1149 static const WCHAR szTooltip[] = {'t','o','o','l','t','i','p','\0'};
1150 WCHAR szName[60];
1151 WCHAR szTip[60];
1152 HANDLE hFind;
1153 WIN32_FIND_DATAW wfd;
1154 HRESULT hr;
1155 size_t pathLen;
1156
1157 TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath), callback, lpData);
1158
1159 if(!pszThemePath || !callback)
1160 return E_POINTER;
1161
1162 lstrcpyW(szDir, pszThemePath);
1163 pathLen = lstrlenW (szDir);
1164 if ((pathLen > 0) && (pathLen < MAX_PATH-1) && (szDir[pathLen - 1] != '\\'))
1165 {
1166 szDir[pathLen] = '\\';
1167 szDir[pathLen+1] = 0;
1168 }
1169
1170 lstrcpyW(szPath, szDir);
1171 lstrcatW(szPath, szStar);
1172 TRACE("searching %s\n", debugstr_w(szPath));
1173
1174 hFind = FindFirstFileW(szPath, &wfd);
1175 if(hFind != INVALID_HANDLE_VALUE) {
1176 do {
1177 if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
1178 && !(wfd.cFileName[0] == '.' && ((wfd.cFileName[1] == '.' && wfd.cFileName[2] == 0) || wfd.cFileName[1] == 0))) {
1179 wsprintfW(szPath, szFormat, szDir, wfd.cFileName, wfd.cFileName);
1180
1181 hr = GetThemeDocumentationProperty(szPath, szDisplayName, szName, sizeof(szName)/sizeof(szName[0]));
1182 if(SUCCEEDED(hr))
1183 hr = GetThemeDocumentationProperty(szPath, szTooltip, szTip, sizeof(szTip)/sizeof(szTip[0]));
1184 if(SUCCEEDED(hr)) {
1185 TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath), debugstr_w(szName), debugstr_w(szTip), lpData);
1186 if(!callback(NULL, szPath, szName, szTip, NULL, lpData)) {
1187 TRACE("callback ended enum\n");
1188 break;
1189 }
1190 }
1191 }
1192 } while(FindNextFileW(hFind, &wfd));
1193 FindClose(hFind);
1194 }
1195 return S_OK;
1196 }
1197
1198
1199 /**********************************************************************
1200 * EnumThemeColors (UXTHEME.9)
1201 *
1202 * Enumerate theme colors available with a particular size
1203 *
1204 * PARAMS
1205 * pszThemeFileName Path to a msstyles theme file
1206 * pszSizeName Theme size to enumerate available colors
1207 * If NULL the default theme size is used
1208 * dwColorNum Color index to retrieve, increment from 0
1209 * pszColorNames Output color names
1210 *
1211 * RETURNS
1212 * S_OK on success
1213 * E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
1214 * or when pszSizeName does not refer to a valid size
1215 *
1216 * NOTES
1217 * XP fails with E_POINTER when pszColorNames points to a buffer smaller than
1218 * sizeof(THEMENAMES).
1219 *
1220 * Not very efficient that I'm opening & validating the theme every call, but
1221 * this is undocumented and almost never called..
1222 * (and this is how windows works too)
1223 */
1224 HRESULT WINAPI EnumThemeColors(LPWSTR pszThemeFileName, LPWSTR pszSizeName,
1225 DWORD dwColorNum, PTHEMENAMES pszColorNames)
1226 {
1227 PTHEME_FILE pt;
1228 HRESULT hr;
1229 LPWSTR tmp;
1230 UINT resourceId = dwColorNum + 1000;
1231 TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName),
1232 debugstr_w(pszSizeName), dwColorNum);
1233
1234 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, pszSizeName, &pt);
1235 if(FAILED(hr)) return hr;
1236
1237 tmp = pt->pszAvailColors;
1238 while(dwColorNum && *tmp) {
1239 dwColorNum--;
1240 tmp += lstrlenW(tmp)+1;
1241 }
1242 if(!dwColorNum && *tmp) {
1243 TRACE("%s\n", debugstr_w(tmp));
1244 lstrcpyW(pszColorNames->szName, tmp);
1245 LoadStringW (pt->hTheme, resourceId,
1246 pszColorNames->szDisplayName,
1247 sizeof (pszColorNames->szDisplayName) / sizeof (WCHAR));
1248 LoadStringW (pt->hTheme, resourceId+1000,
1249 pszColorNames->szTooltip,
1250 sizeof (pszColorNames->szTooltip) / sizeof (WCHAR));
1251 }
1252 else
1253 hr = E_PROP_ID_UNSUPPORTED;
1254
1255 MSSTYLES_CloseThemeFile(pt);
1256 return hr;
1257 }
1258
1259 /**********************************************************************
1260 * EnumThemeSizes (UXTHEME.10)
1261 *
1262 * Enumerate theme colors available with a particular size
1263 *
1264 * PARAMS
1265 * pszThemeFileName Path to a msstyles theme file
1266 * pszColorName Theme color to enumerate available sizes
1267 * If NULL the default theme color is used
1268 * dwSizeNum Size index to retrieve, increment from 0
1269 * pszSizeNames Output size names
1270 *
1271 * RETURNS
1272 * S_OK on success
1273 * E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
1274 * or when pszColorName does not refer to a valid color
1275 *
1276 * NOTES
1277 * XP fails with E_POINTER when pszSizeNames points to a buffer smaller than
1278 * sizeof(THEMENAMES).
1279 *
1280 * Not very efficient that I'm opening & validating the theme every call, but
1281 * this is undocumented and almost never called..
1282 * (and this is how windows works too)
1283 */
1284 HRESULT WINAPI EnumThemeSizes(LPWSTR pszThemeFileName, LPWSTR pszColorName,
1285 DWORD dwSizeNum, PTHEMENAMES pszSizeNames)
1286 {
1287 PTHEME_FILE pt;
1288 HRESULT hr;
1289 LPWSTR tmp;
1290 UINT resourceId = dwSizeNum + 3000;
1291 TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName),
1292 debugstr_w(pszColorName), dwSizeNum);
1293
1294 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, NULL, &pt);
1295 if(FAILED(hr)) return hr;
1296
1297 tmp = pt->pszAvailSizes;
1298 while(dwSizeNum && *tmp) {
1299 dwSizeNum--;
1300 tmp += lstrlenW(tmp)+1;
1301 }
1302 if(!dwSizeNum && *tmp) {
1303 TRACE("%s\n", debugstr_w(tmp));
1304 lstrcpyW(pszSizeNames->szName, tmp);
1305 LoadStringW (pt->hTheme, resourceId,
1306 pszSizeNames->szDisplayName,
1307 sizeof (pszSizeNames->szDisplayName) / sizeof (WCHAR));
1308 LoadStringW (pt->hTheme, resourceId+1000,
1309 pszSizeNames->szTooltip,
1310 sizeof (pszSizeNames->szTooltip) / sizeof (WCHAR));
1311 }
1312 else
1313 hr = E_PROP_ID_UNSUPPORTED;
1314
1315 MSSTYLES_CloseThemeFile(pt);
1316 return hr;
1317 }
1318
1319 /**********************************************************************
1320 * ParseThemeIniFile (UXTHEME.11)
1321 *
1322 * Enumerate data in a theme INI file.
1323 *
1324 * PARAMS
1325 * pszIniFileName Path to a theme ini file
1326 * pszUnknown Cannot be NULL, L"" is valid
1327 * callback Called for each found entry
1328 * lpData Passed through to callback
1329 *
1330 * RETURNS
1331 * S_OK on success
1332 * 0x800706488 (Unknown property) when enumeration is canceled from callback
1333 *
1334 * NOTES
1335 * When pszUnknown is NULL the callback is never called, the value does not seem to serve
1336 * any other purpose
1337 */
1338 HRESULT WINAPI ParseThemeIniFile(LPCWSTR pszIniFileName, LPWSTR pszUnknown,
1339 PARSETHEMEINIFILEPROC callback, LPVOID lpData)
1340 {
1341 FIXME("%s %s: stub\n", debugstr_w(pszIniFileName), debugstr_w(pszUnknown));
1342 return E_NOTIMPL;
1343 }
1344
1345 /**********************************************************************
1346 * CheckThemeSignature (UXTHEME.29)
1347 *
1348 * Validates the signature of a theme file
1349 *
1350 * PARAMS
1351 * pszIniFileName Path to a theme file
1352 *
1353 * RETURNS
1354 * Success: S_OK
1355 * Failure: HRESULT error-code
1356 */
1357 HRESULT WINAPI CheckThemeSignature(LPCWSTR pszThemeFileName)
1358 {
1359 PTHEME_FILE pt;
1360 HRESULT hr;
1361 TRACE("(%s)\n", debugstr_w(pszThemeFileName));
1362 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
1363 if(FAILED(hr))
1364 return hr;
1365 MSSTYLES_CloseThemeFile(pt);
1366 return S_OK;
1367 }