dinput: Implement device creation using product GUID.
[wine/zf.git] / dlls / uxtheme / system.c
bloba37e532500ad28a1a1d43c07a7e849b4dc3ca1a2
1 /*
2 * Win32 5.1 Theme system
4 * Copyright (C) 2003 Kevin Koltzau
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.
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.
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
21 #include <stdarg.h>
22 #include <stdio.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "vfwmsgs.h"
30 #include "uxtheme.h"
31 #include "tmschema.h"
33 #include "uxthemedll.h"
34 #include "msstyles.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
40 /***********************************************************************
41 * Defines and global variables
44 static const WCHAR szThemeManager[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\ThemeManager";
46 DECLSPEC_HIDDEN ATOM atDialogThemeEnabled;
48 static DWORD dwThemeAppProperties = STAP_ALLOW_NONCLIENT | STAP_ALLOW_CONTROLS;
49 static ATOM atWindowTheme;
50 static ATOM atSubAppName;
51 static ATOM atSubIdList;
53 static BOOL bThemeActive = FALSE;
54 static WCHAR szCurrentTheme[MAX_PATH];
55 static WCHAR szCurrentColor[64];
56 static WCHAR szCurrentSize[64];
58 /***********************************************************************/
60 static BOOL CALLBACK UXTHEME_broadcast_msg_enumchild (HWND hWnd, LPARAM msg)
62 PostMessageW(hWnd, msg, 0, 0);
63 return TRUE;
66 /* Broadcast a message to *all* windows, including children */
67 static BOOL CALLBACK UXTHEME_broadcast_msg (HWND hWnd, LPARAM msg)
69 if (hWnd == NULL)
71 EnumWindows (UXTHEME_broadcast_msg, msg);
73 else
75 PostMessageW(hWnd, msg, 0, 0);
76 EnumChildWindows (hWnd, UXTHEME_broadcast_msg_enumchild, msg);
78 return TRUE;
81 /* At the end of the day this is a subset of what SHRegGetPath() does - copied
82 * here to avoid linking against shlwapi. */
83 static DWORD query_reg_path (HKEY hKey, LPCWSTR lpszValue,
84 LPVOID pvData)
86 DWORD dwRet, dwType, dwUnExpDataLen = MAX_PATH, dwExpDataLen;
88 TRACE("(hkey=%p,%s,%p)\n", hKey, debugstr_w(lpszValue),
89 pvData);
91 dwRet = RegQueryValueExW(hKey, lpszValue, 0, &dwType, pvData, &dwUnExpDataLen);
92 if (dwRet!=ERROR_SUCCESS && dwRet!=ERROR_MORE_DATA)
93 return dwRet;
95 if (dwType == REG_EXPAND_SZ)
97 DWORD nBytesToAlloc;
99 /* Expand type REG_EXPAND_SZ into REG_SZ */
100 LPWSTR szData;
102 /* If the caller didn't supply a buffer or the buffer is too small we have
103 * to allocate our own
105 if (dwRet == ERROR_MORE_DATA)
107 WCHAR emptyW[] = L"";
108 nBytesToAlloc = dwUnExpDataLen;
110 szData = LocalAlloc(LMEM_ZEROINIT, nBytesToAlloc);
111 RegQueryValueExW (hKey, lpszValue, 0, NULL, (LPBYTE)szData, &nBytesToAlloc);
112 dwExpDataLen = ExpandEnvironmentStringsW(szData, emptyW, 1);
113 dwUnExpDataLen = max(nBytesToAlloc, dwExpDataLen);
114 LocalFree(szData);
116 else
118 nBytesToAlloc = (lstrlenW(pvData) + 1) * sizeof(WCHAR);
119 szData = LocalAlloc(LMEM_ZEROINIT, nBytesToAlloc );
120 lstrcpyW(szData, pvData);
121 dwExpDataLen = ExpandEnvironmentStringsW(szData, pvData, MAX_PATH );
122 if (dwExpDataLen > MAX_PATH) dwRet = ERROR_MORE_DATA;
123 dwUnExpDataLen = max(nBytesToAlloc, dwExpDataLen);
124 LocalFree(szData);
128 RegCloseKey(hKey);
129 return dwRet;
132 /***********************************************************************
133 * UXTHEME_LoadTheme
135 * Set the current active theme from the registry
137 static void UXTHEME_LoadTheme(void)
139 HKEY hKey;
140 DWORD buffsize;
141 HRESULT hr;
142 WCHAR tmp[10];
143 PTHEME_FILE pt;
145 /* Get current theme configuration */
146 if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
147 TRACE("Loading theme config\n");
148 buffsize = ARRAY_SIZE(tmp);
149 if (!RegQueryValueExW(hKey, L"ThemeActive", NULL, NULL, (BYTE*)tmp, &buffsize)) {
150 bThemeActive = (tmp[0] != '0');
152 else {
153 bThemeActive = FALSE;
154 TRACE("Failed to get ThemeActive: %d\n", GetLastError());
156 buffsize = ARRAY_SIZE(szCurrentColor);
157 if (RegQueryValueExW(hKey, L"ColorName", NULL, NULL, (BYTE*)szCurrentColor, &buffsize))
158 szCurrentColor[0] = '\0';
159 buffsize = ARRAY_SIZE(szCurrentSize);
160 if (RegQueryValueExW(hKey, L"SizeName", NULL, NULL, (BYTE*)szCurrentSize, &buffsize))
161 szCurrentSize[0] = '\0';
162 if (query_reg_path (hKey, L"DllName", szCurrentTheme))
163 szCurrentTheme[0] = '\0';
164 RegCloseKey(hKey);
166 else
167 TRACE("Failed to open theme registry key\n");
169 if(bThemeActive) {
170 /* Make sure the theme requested is actually valid */
171 hr = MSSTYLES_OpenThemeFile(szCurrentTheme,
172 szCurrentColor[0]?szCurrentColor:NULL,
173 szCurrentSize[0]?szCurrentSize:NULL,
174 &pt);
175 if(FAILED(hr)) {
176 bThemeActive = FALSE;
177 szCurrentTheme[0] = '\0';
178 szCurrentColor[0] = '\0';
179 szCurrentSize[0] = '\0';
181 else {
182 /* Make sure the global color & size match the theme */
183 lstrcpynW(szCurrentColor, pt->pszSelectedColor, ARRAY_SIZE(szCurrentColor));
184 lstrcpynW(szCurrentSize, pt->pszSelectedSize, ARRAY_SIZE(szCurrentSize));
186 MSSTYLES_SetActiveTheme(pt, FALSE);
187 TRACE("Theme active: %s %s %s\n", debugstr_w(szCurrentTheme),
188 debugstr_w(szCurrentColor), debugstr_w(szCurrentSize));
189 MSSTYLES_CloseThemeFile(pt);
192 if(!bThemeActive) {
193 MSSTYLES_SetActiveTheme(NULL, FALSE);
194 TRACE("Theming not active\n");
198 /***********************************************************************/
200 static const char * const SysColorsNames[] =
202 "Scrollbar", /* COLOR_SCROLLBAR */
203 "Background", /* COLOR_BACKGROUND */
204 "ActiveTitle", /* COLOR_ACTIVECAPTION */
205 "InactiveTitle", /* COLOR_INACTIVECAPTION */
206 "Menu", /* COLOR_MENU */
207 "Window", /* COLOR_WINDOW */
208 "WindowFrame", /* COLOR_WINDOWFRAME */
209 "MenuText", /* COLOR_MENUTEXT */
210 "WindowText", /* COLOR_WINDOWTEXT */
211 "TitleText", /* COLOR_CAPTIONTEXT */
212 "ActiveBorder", /* COLOR_ACTIVEBORDER */
213 "InactiveBorder", /* COLOR_INACTIVEBORDER */
214 "AppWorkSpace", /* COLOR_APPWORKSPACE */
215 "Hilight", /* COLOR_HIGHLIGHT */
216 "HilightText", /* COLOR_HIGHLIGHTTEXT */
217 "ButtonFace", /* COLOR_BTNFACE */
218 "ButtonShadow", /* COLOR_BTNSHADOW */
219 "GrayText", /* COLOR_GRAYTEXT */
220 "ButtonText", /* COLOR_BTNTEXT */
221 "InactiveTitleText", /* COLOR_INACTIVECAPTIONTEXT */
222 "ButtonHilight", /* COLOR_BTNHIGHLIGHT */
223 "ButtonDkShadow", /* COLOR_3DDKSHADOW */
224 "ButtonLight", /* COLOR_3DLIGHT */
225 "InfoText", /* COLOR_INFOTEXT */
226 "InfoWindow", /* COLOR_INFOBK */
227 "ButtonAlternateFace", /* COLOR_ALTERNATEBTNFACE */
228 "HotTrackingColor", /* COLOR_HOTLIGHT */
229 "GradientActiveTitle", /* COLOR_GRADIENTACTIVECAPTION */
230 "GradientInactiveTitle", /* COLOR_GRADIENTINACTIVECAPTION */
231 "MenuHilight", /* COLOR_MENUHILIGHT */
232 "MenuBar", /* COLOR_MENUBAR */
235 static const WCHAR strColorKey[] = L"Control Panel\\Colors";
237 static const struct BackupSysParam
239 int spiGet, spiSet;
240 const WCHAR* keyName;
241 } backupSysParams[] =
243 {SPI_GETFLATMENU, SPI_SETFLATMENU, L"FlatMenu"},
244 {SPI_GETGRADIENTCAPTIONS, SPI_SETGRADIENTCAPTIONS, L"GradientCaption"},
245 {-1, -1, 0}
248 #define NUM_SYS_COLORS (COLOR_MENUBAR+1)
250 static void save_sys_colors (HKEY baseKey)
252 char colorStr[13];
253 HKEY hKey;
254 int i;
256 if (RegCreateKeyExW( baseKey, strColorKey,
257 0, 0, 0, KEY_ALL_ACCESS,
258 0, &hKey, 0 ) == ERROR_SUCCESS)
260 for (i = 0; i < NUM_SYS_COLORS; i++)
262 COLORREF col = GetSysColor (i);
264 sprintf (colorStr, "%d %d %d",
265 GetRValue (col), GetGValue (col), GetBValue (col));
267 RegSetValueExA (hKey, SysColorsNames[i], 0, REG_SZ,
268 (BYTE*)colorStr, strlen (colorStr)+1);
270 RegCloseKey (hKey);
274 /* Before activating a theme, query current system colors, certain settings
275 * and backup them in the registry, so they can be restored when the theme
276 * is deactivated */
277 static void UXTHEME_BackupSystemMetrics(void)
279 HKEY hKey;
280 const struct BackupSysParam* bsp = backupSysParams;
282 if (RegCreateKeyExW( HKEY_CURRENT_USER, szThemeManager,
283 0, 0, 0, KEY_ALL_ACCESS,
284 0, &hKey, 0) == ERROR_SUCCESS)
286 NONCLIENTMETRICSW ncm;
287 LOGFONTW iconTitleFont;
289 /* back up colors */
290 save_sys_colors (hKey);
292 /* back up "other" settings */
293 while (bsp->spiGet >= 0)
295 DWORD value;
297 SystemParametersInfoW (bsp->spiGet, 0, &value, 0);
298 RegSetValueExW (hKey, bsp->keyName, 0, REG_DWORD,
299 (LPBYTE)&value, sizeof (value));
301 bsp++;
304 /* back up non-client metrics */
305 memset (&ncm, 0, sizeof (ncm));
306 ncm.cbSize = sizeof (ncm);
307 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof (ncm), &ncm, 0);
308 RegSetValueExW (hKey, L"NonClientMetrics", 0, REG_BINARY, (BYTE*)&ncm,
309 sizeof (ncm));
310 memset (&iconTitleFont, 0, sizeof (iconTitleFont));
311 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof (iconTitleFont),
312 &iconTitleFont, 0);
313 RegSetValueExW (hKey, L"IconTitleFont", 0, REG_BINARY,
314 (LPBYTE)&iconTitleFont, sizeof (iconTitleFont));
316 RegCloseKey (hKey);
320 /* Read back old settings after a theme was deactivated */
321 static void UXTHEME_RestoreSystemMetrics(void)
323 HKEY hKey;
324 const struct BackupSysParam* bsp = backupSysParams;
326 if (RegOpenKeyExW (HKEY_CURRENT_USER, szThemeManager,
327 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
329 HKEY colorKey;
331 /* read backed-up colors */
332 if (RegOpenKeyExW (hKey, strColorKey,
333 0, KEY_QUERY_VALUE, &colorKey) == ERROR_SUCCESS)
335 int i;
336 COLORREF sysCols[NUM_SYS_COLORS];
337 int sysColsIndices[NUM_SYS_COLORS];
338 int sysColCount = 0;
340 for (i = 0; i < NUM_SYS_COLORS; i++)
342 DWORD type;
343 char colorStr[13];
344 DWORD count = sizeof(colorStr);
346 if (RegQueryValueExA (colorKey, SysColorsNames[i], 0,
347 &type, (LPBYTE) colorStr, &count) == ERROR_SUCCESS)
349 int r, g, b;
350 if (sscanf (colorStr, "%d %d %d", &r, &g, &b) == 3)
352 sysColsIndices[sysColCount] = i;
353 sysCols[sysColCount] = RGB(r, g, b);
354 sysColCount++;
358 RegCloseKey (colorKey);
360 SetSysColors (sysColCount, sysColsIndices, sysCols);
363 /* read backed-up other settings */
364 while (bsp->spiGet >= 0)
366 DWORD value;
367 DWORD count = sizeof(value);
368 DWORD type;
370 if (RegQueryValueExW (hKey, bsp->keyName, 0,
371 &type, (LPBYTE)&value, &count) == ERROR_SUCCESS)
373 SystemParametersInfoW (bsp->spiSet, 0, UlongToPtr(value), SPIF_UPDATEINIFILE);
376 bsp++;
379 /* read backed-up non-client metrics */
381 NONCLIENTMETRICSW ncm;
382 LOGFONTW iconTitleFont;
383 DWORD count = sizeof(ncm);
384 DWORD type;
386 if (RegQueryValueExW (hKey, L"NonClientMetrics", 0,
387 &type, (LPBYTE)&ncm, &count) == ERROR_SUCCESS)
389 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS,
390 count, &ncm, SPIF_UPDATEINIFILE);
393 count = sizeof(iconTitleFont);
395 if (RegQueryValueExW (hKey, L"IconTitleFont", 0,
396 &type, (LPBYTE)&iconTitleFont, &count) == ERROR_SUCCESS)
398 SystemParametersInfoW (SPI_SETICONTITLELOGFONT,
399 count, &iconTitleFont, SPIF_UPDATEINIFILE);
403 RegCloseKey (hKey);
407 /* Make system settings persistent, so they're in effect even w/o uxtheme
408 * loaded.
409 * For efficiency reasons, only the last SystemParametersInfoW sets
410 * SPIF_SENDWININICHANGE */
411 static void UXTHEME_SaveSystemMetrics(void)
413 const struct BackupSysParam* bsp = backupSysParams;
414 NONCLIENTMETRICSW ncm;
415 LOGFONTW iconTitleFont;
417 save_sys_colors (HKEY_CURRENT_USER);
419 while (bsp->spiGet >= 0)
421 DWORD value;
423 SystemParametersInfoW (bsp->spiGet, 0, &value, 0);
424 SystemParametersInfoW (bsp->spiSet, 0, UlongToPtr(value), SPIF_UPDATEINIFILE);
425 bsp++;
428 memset (&ncm, 0, sizeof (ncm));
429 ncm.cbSize = sizeof (ncm);
430 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof (ncm), &ncm, 0);
431 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS, sizeof (ncm), &ncm,
432 SPIF_UPDATEINIFILE);
434 memset (&iconTitleFont, 0, sizeof (iconTitleFont));
435 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof (iconTitleFont),
436 &iconTitleFont, 0);
437 SystemParametersInfoW (SPI_SETICONTITLELOGFONT, sizeof (iconTitleFont),
438 &iconTitleFont, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
441 /***********************************************************************
442 * UXTHEME_SetActiveTheme
444 * Change the current active theme
446 static HRESULT UXTHEME_SetActiveTheme(PTHEME_FILE tf)
448 HKEY hKey;
449 WCHAR tmp[2];
450 HRESULT hr;
452 if(tf && !bThemeActive) UXTHEME_BackupSystemMetrics();
453 hr = MSSTYLES_SetActiveTheme(tf, TRUE);
454 if(FAILED(hr))
455 return hr;
456 if(tf) {
457 bThemeActive = TRUE;
458 lstrcpynW(szCurrentTheme, tf->szThemeFile, ARRAY_SIZE(szCurrentTheme));
459 lstrcpynW(szCurrentColor, tf->pszSelectedColor, ARRAY_SIZE(szCurrentColor));
460 lstrcpynW(szCurrentSize, tf->pszSelectedSize, ARRAY_SIZE(szCurrentSize));
462 else {
463 UXTHEME_RestoreSystemMetrics();
464 bThemeActive = FALSE;
465 szCurrentTheme[0] = '\0';
466 szCurrentColor[0] = '\0';
467 szCurrentSize[0] = '\0';
470 TRACE("Writing theme config to registry\n");
471 if(!RegCreateKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
472 tmp[0] = bThemeActive?'1':'0';
473 tmp[1] = '\0';
474 RegSetValueExW(hKey, L"ThemeActive", 0, REG_SZ, (const BYTE*)tmp, sizeof(WCHAR)*2);
475 if(bThemeActive) {
476 RegSetValueExW(hKey, L"ColorName", 0, REG_SZ, (const BYTE*)szCurrentColor,
477 (lstrlenW(szCurrentColor)+1)*sizeof(WCHAR));
478 RegSetValueExW(hKey, L"SizeName", 0, REG_SZ, (const BYTE*)szCurrentSize,
479 (lstrlenW(szCurrentSize)+1)*sizeof(WCHAR));
480 RegSetValueExW(hKey, L"DllName", 0, REG_SZ, (const BYTE*)szCurrentTheme,
481 (lstrlenW(szCurrentTheme)+1)*sizeof(WCHAR));
483 else {
484 RegDeleteValueW(hKey, L"ColorName");
485 RegDeleteValueW(hKey, L"SizeName");
486 RegDeleteValueW(hKey, L"DllName");
489 RegCloseKey(hKey);
491 else
492 TRACE("Failed to open theme registry key\n");
494 UXTHEME_SaveSystemMetrics ();
496 return hr;
499 /***********************************************************************
500 * UXTHEME_InitSystem
502 void UXTHEME_InitSystem(HINSTANCE hInst)
504 atWindowTheme = GlobalAddAtomW(L"ux_theme");
505 atSubAppName = GlobalAddAtomW(L"ux_subapp");
506 atSubIdList = GlobalAddAtomW(L"ux_subidlst");
507 atDialogThemeEnabled = GlobalAddAtomW(L"ux_dialogtheme");
509 UXTHEME_LoadTheme();
512 /***********************************************************************
513 * IsAppThemed (UXTHEME.@)
515 BOOL WINAPI IsAppThemed(void)
517 return IsThemeActive();
520 /***********************************************************************
521 * IsThemeActive (UXTHEME.@)
523 BOOL WINAPI IsThemeActive(void)
525 TRACE("\n");
526 SetLastError(ERROR_SUCCESS);
527 return bThemeActive;
530 /************************************************************
531 * IsCompositionActive (UXTHEME.@)
533 BOOL WINAPI IsCompositionActive(void)
535 FIXME(": stub\n");
537 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
539 return FALSE;
542 /***********************************************************************
543 * EnableTheming (UXTHEME.@)
545 * NOTES
546 * This is a global and persistent change
548 HRESULT WINAPI EnableTheming(BOOL fEnable)
550 HKEY hKey;
551 WCHAR szEnabled[] = L"0";
553 TRACE("(%d)\n", fEnable);
555 if(fEnable != bThemeActive) {
556 if(fEnable)
557 UXTHEME_BackupSystemMetrics();
558 else
559 UXTHEME_RestoreSystemMetrics();
560 UXTHEME_SaveSystemMetrics ();
561 bThemeActive = fEnable;
562 if(bThemeActive) szEnabled[0] = '1';
563 if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
564 RegSetValueExW(hKey, L"ThemeActive", 0, REG_SZ, (BYTE*)szEnabled, sizeof(WCHAR));
565 RegCloseKey(hKey);
567 UXTHEME_broadcast_msg (NULL, WM_THEMECHANGED);
569 return S_OK;
572 /***********************************************************************
573 * UXTHEME_SetWindowProperty
575 * I'm using atoms as there may be large numbers of duplicated strings
576 * and they do the work of keeping memory down as a cause of that quite nicely
578 static HRESULT UXTHEME_SetWindowProperty(HWND hwnd, ATOM aProp, LPCWSTR pszValue)
580 ATOM oldValue = (ATOM)(size_t)RemovePropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp));
581 if(oldValue)
582 DeleteAtom(oldValue);
583 if(pszValue) {
584 ATOM atValue = AddAtomW(pszValue);
585 if(!atValue
586 || !SetPropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp), (LPWSTR)MAKEINTATOM(atValue))) {
587 HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
588 if(atValue) DeleteAtom(atValue);
589 return hr;
592 return S_OK;
595 static LPWSTR UXTHEME_GetWindowProperty(HWND hwnd, ATOM aProp, LPWSTR pszBuffer, int dwLen)
597 ATOM atValue = (ATOM)(size_t)GetPropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp));
598 if(atValue) {
599 if(GetAtomNameW(atValue, pszBuffer, dwLen))
600 return pszBuffer;
601 TRACE("property defined, but unable to get value\n");
603 return NULL;
606 /***********************************************************************
607 * OpenThemeDataEx (UXTHEME.61)
609 HTHEME WINAPI OpenThemeDataEx(HWND hwnd, LPCWSTR pszClassList, DWORD flags)
611 WCHAR szAppBuff[256];
612 WCHAR szClassBuff[256];
613 LPCWSTR pszAppName;
614 LPCWSTR pszUseClassList;
615 HTHEME hTheme = NULL;
616 TRACE("(%p,%s, %x)\n", hwnd, debugstr_w(pszClassList), flags);
618 if(!pszClassList)
620 SetLastError(E_POINTER);
621 return NULL;
624 if(flags)
625 FIXME("unhandled flags: %x\n", flags);
627 if(bThemeActive)
629 pszAppName = UXTHEME_GetWindowProperty(hwnd, atSubAppName, szAppBuff, ARRAY_SIZE(szAppBuff));
630 /* If SetWindowTheme was used on the window, that overrides the class list passed to this function */
631 pszUseClassList = UXTHEME_GetWindowProperty(hwnd, atSubIdList, szClassBuff, ARRAY_SIZE(szClassBuff));
632 if(!pszUseClassList)
633 pszUseClassList = pszClassList;
635 if (pszUseClassList)
636 hTheme = MSSTYLES_OpenThemeClass(pszAppName, pszUseClassList);
638 if(IsWindow(hwnd))
639 SetPropW(hwnd, (LPCWSTR)MAKEINTATOM(atWindowTheme), hTheme);
640 TRACE(" = %p\n", hTheme);
641 return hTheme;
644 /***********************************************************************
645 * OpenThemeData (UXTHEME.@)
647 HTHEME WINAPI OpenThemeData(HWND hwnd, LPCWSTR classlist)
649 return OpenThemeDataEx(hwnd, classlist, 0);
652 /***********************************************************************
653 * GetWindowTheme (UXTHEME.@)
655 * Retrieve the last theme opened for a window.
657 * PARAMS
658 * hwnd [I] window to retrieve the theme for
660 * RETURNS
661 * The most recent theme.
663 HTHEME WINAPI GetWindowTheme(HWND hwnd)
665 TRACE("(%p)\n", hwnd);
666 return GetPropW(hwnd, (LPCWSTR)MAKEINTATOM(atWindowTheme));
669 /***********************************************************************
670 * SetWindowTheme (UXTHEME.@)
672 * Persistent through the life of the window, even after themes change
674 HRESULT WINAPI SetWindowTheme(HWND hwnd, LPCWSTR pszSubAppName,
675 LPCWSTR pszSubIdList)
677 HRESULT hr;
678 TRACE("(%p,%s,%s)\n", hwnd, debugstr_w(pszSubAppName),
679 debugstr_w(pszSubIdList));
680 hr = UXTHEME_SetWindowProperty(hwnd, atSubAppName, pszSubAppName);
681 if(SUCCEEDED(hr))
682 hr = UXTHEME_SetWindowProperty(hwnd, atSubIdList, pszSubIdList);
683 if(SUCCEEDED(hr))
684 UXTHEME_broadcast_msg (hwnd, WM_THEMECHANGED);
685 return hr;
688 /***********************************************************************
689 * SetWindowThemeAttribute (UXTHEME.@)
691 HRESULT WINAPI SetWindowThemeAttribute(HWND hwnd, enum WINDOWTHEMEATTRIBUTETYPE type,
692 PVOID attribute, DWORD size)
694 FIXME("(%p,%d,%p,%d): stub\n", hwnd, type, attribute, size);
695 return E_NOTIMPL;
698 /***********************************************************************
699 * GetCurrentThemeName (UXTHEME.@)
701 HRESULT WINAPI GetCurrentThemeName(LPWSTR pszThemeFileName, int dwMaxNameChars,
702 LPWSTR pszColorBuff, int cchMaxColorChars,
703 LPWSTR pszSizeBuff, int cchMaxSizeChars)
705 if(!bThemeActive)
706 return E_PROP_ID_UNSUPPORTED;
707 if(pszThemeFileName) lstrcpynW(pszThemeFileName, szCurrentTheme, dwMaxNameChars);
708 if(pszColorBuff) lstrcpynW(pszColorBuff, szCurrentColor, cchMaxColorChars);
709 if(pszSizeBuff) lstrcpynW(pszSizeBuff, szCurrentSize, cchMaxSizeChars);
710 return S_OK;
713 /***********************************************************************
714 * GetThemeAppProperties (UXTHEME.@)
716 DWORD WINAPI GetThemeAppProperties(void)
718 return dwThemeAppProperties;
721 /***********************************************************************
722 * SetThemeAppProperties (UXTHEME.@)
724 void WINAPI SetThemeAppProperties(DWORD dwFlags)
726 TRACE("(0x%08x)\n", dwFlags);
727 dwThemeAppProperties = dwFlags;
730 /***********************************************************************
731 * CloseThemeData (UXTHEME.@)
733 HRESULT WINAPI CloseThemeData(HTHEME hTheme)
735 TRACE("(%p)\n", hTheme);
736 if(!hTheme || hTheme == INVALID_HANDLE_VALUE)
737 return E_HANDLE;
738 return MSSTYLES_CloseThemeClass(hTheme);
741 /***********************************************************************
742 * HitTestThemeBackground (UXTHEME.@)
744 HRESULT WINAPI HitTestThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
745 int iStateId, DWORD dwOptions,
746 const RECT *pRect, HRGN hrgn,
747 POINT ptTest, WORD *pwHitTestCode)
749 FIXME("%d %d 0x%08x: stub\n", iPartId, iStateId, dwOptions);
750 if(!hTheme)
751 return E_HANDLE;
752 return E_NOTIMPL;
755 /***********************************************************************
756 * IsThemePartDefined (UXTHEME.@)
758 BOOL WINAPI IsThemePartDefined(HTHEME hTheme, int iPartId, int iStateId)
760 TRACE("(%p,%d,%d)\n", hTheme, iPartId, iStateId);
761 if(!hTheme) {
762 SetLastError(E_HANDLE);
763 return FALSE;
765 if(MSSTYLES_FindPartState(hTheme, iPartId, iStateId, NULL))
766 return TRUE;
767 return FALSE;
770 /***********************************************************************
771 * GetThemeDocumentationProperty (UXTHEME.@)
773 * Try and retrieve the documentation property from string resources
774 * if that fails, get it from the [documentation] section of themes.ini
776 HRESULT WINAPI GetThemeDocumentationProperty(LPCWSTR pszThemeName,
777 LPCWSTR pszPropertyName,
778 LPWSTR pszValueBuff,
779 int cchMaxValChars)
781 static const WORD wDocToRes[] = {
782 TMT_DISPLAYNAME,5000,
783 TMT_TOOLTIP,5001,
784 TMT_COMPANY,5002,
785 TMT_AUTHOR,5003,
786 TMT_COPYRIGHT,5004,
787 TMT_URL,5005,
788 TMT_VERSION,5006,
789 TMT_DESCRIPTION,5007
792 PTHEME_FILE pt;
793 HRESULT hr;
794 unsigned int i;
795 int iDocId;
796 TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName), debugstr_w(pszPropertyName),
797 pszValueBuff, cchMaxValChars);
799 hr = MSSTYLES_OpenThemeFile(pszThemeName, NULL, NULL, &pt);
800 if(FAILED(hr)) return hr;
802 /* Try to load from string resources */
803 hr = E_PROP_ID_UNSUPPORTED;
804 if(MSSTYLES_LookupProperty(pszPropertyName, NULL, &iDocId)) {
805 for(i=0; i<ARRAY_SIZE(wDocToRes); i+=2) {
806 if(wDocToRes[i] == iDocId) {
807 if(LoadStringW(pt->hTheme, wDocToRes[i+1], pszValueBuff, cchMaxValChars)) {
808 hr = S_OK;
809 break;
814 /* If loading from string resource failed, try getting it from the theme.ini */
815 if(FAILED(hr)) {
816 PUXINI_FILE uf = MSSTYLES_GetThemeIni(pt);
817 if(UXINI_FindSection(uf, L"documentation")) {
818 LPCWSTR lpValue;
819 DWORD dwLen;
820 if(UXINI_FindValue(uf, pszPropertyName, &lpValue, &dwLen)) {
821 lstrcpynW(pszValueBuff, lpValue, min(dwLen+1,cchMaxValChars));
822 hr = S_OK;
825 UXINI_CloseINI(uf);
828 MSSTYLES_CloseThemeFile(pt);
829 return hr;
832 /**********************************************************************
833 * Undocumented functions
836 /**********************************************************************
837 * QueryThemeServices (UXTHEME.1)
839 * RETURNS
840 * some kind of status flag
842 DWORD WINAPI QueryThemeServices(void)
844 FIXME("stub\n");
845 return 3; /* This is what is returned under XP in most cases */
849 /**********************************************************************
850 * OpenThemeFile (UXTHEME.2)
852 * Opens a theme file, which can be used to change the current theme, etc
854 * PARAMS
855 * pszThemeFileName Path to a msstyles theme file
856 * pszColorName Color defined in the theme, eg. NormalColor
857 * pszSizeName Size defined in the theme, eg. NormalSize
858 * hThemeFile Handle to theme file
860 * RETURNS
861 * Success: S_OK
862 * Failure: HRESULT error-code
864 HRESULT WINAPI OpenThemeFile(LPCWSTR pszThemeFileName, LPCWSTR pszColorName,
865 LPCWSTR pszSizeName, HTHEMEFILE *hThemeFile,
866 DWORD unknown)
868 TRACE("(%s,%s,%s,%p,%d)\n", debugstr_w(pszThemeFileName),
869 debugstr_w(pszColorName), debugstr_w(pszSizeName),
870 hThemeFile, unknown);
871 return MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, pszSizeName, (PTHEME_FILE*)hThemeFile);
874 /**********************************************************************
875 * CloseThemeFile (UXTHEME.3)
877 * Releases theme file handle returned by OpenThemeFile
879 * PARAMS
880 * hThemeFile Handle to theme file
882 * RETURNS
883 * Success: S_OK
884 * Failure: HRESULT error-code
886 HRESULT WINAPI CloseThemeFile(HTHEMEFILE hThemeFile)
888 TRACE("(%p)\n", hThemeFile);
889 MSSTYLES_CloseThemeFile(hThemeFile);
890 return S_OK;
893 /**********************************************************************
894 * ApplyTheme (UXTHEME.4)
896 * Set a theme file to be the currently active theme
898 * PARAMS
899 * hThemeFile Handle to theme file
900 * unknown See notes
901 * hWnd Window requesting the theme change
903 * RETURNS
904 * Success: S_OK
905 * Failure: HRESULT error-code
907 * NOTES
908 * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
909 * Under XP if I pass
910 * char b[] = "";
911 * the theme is applied with the screen redrawing really badly (flickers)
912 * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
913 * the theme is applied smoothly (screen does not flicker)
914 * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
915 * the function fails returning invalid parameter... very strange
917 HRESULT WINAPI ApplyTheme(HTHEMEFILE hThemeFile, char *unknown, HWND hWnd)
919 HRESULT hr;
920 TRACE("(%p,%s,%p)\n", hThemeFile, unknown, hWnd);
921 hr = UXTHEME_SetActiveTheme(hThemeFile);
922 UXTHEME_broadcast_msg (NULL, WM_THEMECHANGED);
923 return hr;
926 /**********************************************************************
927 * GetThemeDefaults (UXTHEME.7)
929 * Get the default color & size for a theme
931 * PARAMS
932 * pszThemeFileName Path to a msstyles theme file
933 * pszColorName Buffer to receive the default color name
934 * dwColorNameLen Length, in characters, of color name buffer
935 * pszSizeName Buffer to receive the default size name
936 * dwSizeNameLen Length, in characters, of size name buffer
938 * RETURNS
939 * Success: S_OK
940 * Failure: HRESULT error-code
942 HRESULT WINAPI GetThemeDefaults(LPCWSTR pszThemeFileName, LPWSTR pszColorName,
943 DWORD dwColorNameLen, LPWSTR pszSizeName,
944 DWORD dwSizeNameLen)
946 PTHEME_FILE pt;
947 HRESULT hr;
948 TRACE("(%s,%p,%d,%p,%d)\n", debugstr_w(pszThemeFileName),
949 pszColorName, dwColorNameLen,
950 pszSizeName, dwSizeNameLen);
952 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
953 if(FAILED(hr)) return hr;
955 lstrcpynW(pszColorName, pt->pszSelectedColor, dwColorNameLen);
956 lstrcpynW(pszSizeName, pt->pszSelectedSize, dwSizeNameLen);
958 MSSTYLES_CloseThemeFile(pt);
959 return S_OK;
962 /**********************************************************************
963 * EnumThemes (UXTHEME.8)
965 * Enumerate available themes, calls specified EnumThemeProc for each
966 * theme found. Passes lpData through to callback function.
968 * PARAMS
969 * pszThemePath Path containing themes
970 * callback Called for each theme found in path
971 * lpData Passed through to callback
973 * RETURNS
974 * Success: S_OK
975 * Failure: HRESULT error-code
977 HRESULT WINAPI EnumThemes(LPCWSTR pszThemePath, EnumThemeProc callback,
978 LPVOID lpData)
980 WCHAR szDir[MAX_PATH];
981 WCHAR szPath[MAX_PATH];
982 WCHAR szName[60];
983 WCHAR szTip[60];
984 HANDLE hFind;
985 WIN32_FIND_DATAW wfd;
986 HRESULT hr;
987 size_t pathLen;
989 TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath), callback, lpData);
991 if(!pszThemePath || !callback)
992 return E_POINTER;
994 lstrcpyW(szDir, pszThemePath);
995 pathLen = lstrlenW (szDir);
996 if ((pathLen > 0) && (pathLen < MAX_PATH-1) && (szDir[pathLen - 1] != '\\'))
998 szDir[pathLen] = '\\';
999 szDir[pathLen+1] = 0;
1002 lstrcpyW(szPath, szDir);
1003 lstrcatW(szPath, L"*.*");
1004 TRACE("searching %s\n", debugstr_w(szPath));
1006 hFind = FindFirstFileW(szPath, &wfd);
1007 if(hFind != INVALID_HANDLE_VALUE) {
1008 do {
1009 if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
1010 && !(wfd.cFileName[0] == '.' && ((wfd.cFileName[1] == '.' && wfd.cFileName[2] == 0) || wfd.cFileName[1] == 0))) {
1011 wsprintfW(szPath, L"%s%s\\%s.msstyles", szDir, wfd.cFileName, wfd.cFileName);
1013 hr = GetThemeDocumentationProperty(szPath, L"displayname", szName, ARRAY_SIZE(szName));
1014 if(SUCCEEDED(hr))
1015 hr = GetThemeDocumentationProperty(szPath, L"tooltip", szTip, ARRAY_SIZE(szTip));
1016 if(SUCCEEDED(hr)) {
1017 TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath), debugstr_w(szName), debugstr_w(szTip), lpData);
1018 if(!callback(NULL, szPath, szName, szTip, NULL, lpData)) {
1019 TRACE("callback ended enum\n");
1020 break;
1024 } while(FindNextFileW(hFind, &wfd));
1025 FindClose(hFind);
1027 return S_OK;
1031 /**********************************************************************
1032 * EnumThemeColors (UXTHEME.9)
1034 * Enumerate theme colors available with a particular size
1036 * PARAMS
1037 * pszThemeFileName Path to a msstyles theme file
1038 * pszSizeName Theme size to enumerate available colors
1039 * If NULL the default theme size is used
1040 * dwColorNum Color index to retrieve, increment from 0
1041 * pszColorNames Output color names
1043 * RETURNS
1044 * S_OK on success
1045 * E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
1046 * or when pszSizeName does not refer to a valid size
1048 * NOTES
1049 * XP fails with E_POINTER when pszColorNames points to a buffer smaller than
1050 * sizeof(THEMENAMES).
1052 * Not very efficient that I'm opening & validating the theme every call, but
1053 * this is undocumented and almost never called..
1054 * (and this is how windows works too)
1056 HRESULT WINAPI EnumThemeColors(LPWSTR pszThemeFileName, LPWSTR pszSizeName,
1057 DWORD dwColorNum, PTHEMENAMES pszColorNames)
1059 PTHEME_FILE pt;
1060 HRESULT hr;
1061 LPWSTR tmp;
1062 UINT resourceId = dwColorNum + 1000;
1063 TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName),
1064 debugstr_w(pszSizeName), dwColorNum);
1066 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, pszSizeName, &pt);
1067 if(FAILED(hr)) return hr;
1069 tmp = pt->pszAvailColors;
1070 while(dwColorNum && *tmp) {
1071 dwColorNum--;
1072 tmp += lstrlenW(tmp)+1;
1074 if(!dwColorNum && *tmp) {
1075 TRACE("%s\n", debugstr_w(tmp));
1076 lstrcpyW(pszColorNames->szName, tmp);
1077 LoadStringW(pt->hTheme, resourceId, pszColorNames->szDisplayName,
1078 ARRAY_SIZE(pszColorNames->szDisplayName));
1079 LoadStringW(pt->hTheme, resourceId+1000, pszColorNames->szTooltip,
1080 ARRAY_SIZE(pszColorNames->szTooltip));
1082 else
1083 hr = E_PROP_ID_UNSUPPORTED;
1085 MSSTYLES_CloseThemeFile(pt);
1086 return hr;
1089 /**********************************************************************
1090 * EnumThemeSizes (UXTHEME.10)
1092 * Enumerate theme colors available with a particular size
1094 * PARAMS
1095 * pszThemeFileName Path to a msstyles theme file
1096 * pszColorName Theme color to enumerate available sizes
1097 * If NULL the default theme color is used
1098 * dwSizeNum Size index to retrieve, increment from 0
1099 * pszSizeNames Output size names
1101 * RETURNS
1102 * S_OK on success
1103 * E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
1104 * or when pszColorName does not refer to a valid color
1106 * NOTES
1107 * XP fails with E_POINTER when pszSizeNames points to a buffer smaller than
1108 * sizeof(THEMENAMES).
1110 * Not very efficient that I'm opening & validating the theme every call, but
1111 * this is undocumented and almost never called..
1112 * (and this is how windows works too)
1114 HRESULT WINAPI EnumThemeSizes(LPWSTR pszThemeFileName, LPWSTR pszColorName,
1115 DWORD dwSizeNum, PTHEMENAMES pszSizeNames)
1117 PTHEME_FILE pt;
1118 HRESULT hr;
1119 LPWSTR tmp;
1120 UINT resourceId = dwSizeNum + 3000;
1121 TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName),
1122 debugstr_w(pszColorName), dwSizeNum);
1124 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, NULL, &pt);
1125 if(FAILED(hr)) return hr;
1127 tmp = pt->pszAvailSizes;
1128 while(dwSizeNum && *tmp) {
1129 dwSizeNum--;
1130 tmp += lstrlenW(tmp)+1;
1132 if(!dwSizeNum && *tmp) {
1133 TRACE("%s\n", debugstr_w(tmp));
1134 lstrcpyW(pszSizeNames->szName, tmp);
1135 LoadStringW(pt->hTheme, resourceId, pszSizeNames->szDisplayName,
1136 ARRAY_SIZE(pszSizeNames->szDisplayName));
1137 LoadStringW(pt->hTheme, resourceId+1000, pszSizeNames->szTooltip,
1138 ARRAY_SIZE(pszSizeNames->szTooltip));
1140 else
1141 hr = E_PROP_ID_UNSUPPORTED;
1143 MSSTYLES_CloseThemeFile(pt);
1144 return hr;
1147 /**********************************************************************
1148 * ParseThemeIniFile (UXTHEME.11)
1150 * Enumerate data in a theme INI file.
1152 * PARAMS
1153 * pszIniFileName Path to a theme ini file
1154 * pszUnknown Cannot be NULL, L"" is valid
1155 * callback Called for each found entry
1156 * lpData Passed through to callback
1158 * RETURNS
1159 * S_OK on success
1160 * 0x800706488 (Unknown property) when enumeration is canceled from callback
1162 * NOTES
1163 * When pszUnknown is NULL the callback is never called, the value does not seem to serve
1164 * any other purpose
1166 HRESULT WINAPI ParseThemeIniFile(LPCWSTR pszIniFileName, LPWSTR pszUnknown,
1167 ParseThemeIniFileProc callback, LPVOID lpData)
1169 FIXME("%s %s: stub\n", debugstr_w(pszIniFileName), debugstr_w(pszUnknown));
1170 return E_NOTIMPL;
1173 /**********************************************************************
1174 * CheckThemeSignature (UXTHEME.29)
1176 * Validates the signature of a theme file
1178 * PARAMS
1179 * pszIniFileName Path to a theme file
1181 * RETURNS
1182 * Success: S_OK
1183 * Failure: HRESULT error-code
1185 HRESULT WINAPI CheckThemeSignature(LPCWSTR pszThemeFileName)
1187 PTHEME_FILE pt;
1188 HRESULT hr;
1189 TRACE("(%s)\n", debugstr_w(pszThemeFileName));
1190 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
1191 if(FAILED(hr))
1192 return hr;
1193 MSSTYLES_CloseThemeFile(pt);
1194 return S_OK;