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