mstask: Implement ITask::DeleteTrigger().
[wine.git] / dlls / uxtheme / system.c
blobe11271ac2bc3d3375138b1b1288e8a3f0d187f6b
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 "config.h"
23 #include <stdarg.h>
24 #include <stdio.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "winreg.h"
31 #include "vfwmsgs.h"
32 #include "uxtheme.h"
33 #include "tmschema.h"
35 #include "uxthemedll.h"
36 #include "msstyles.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
42 /***********************************************************************
43 * Defines and global variables
46 static const WCHAR szThemeManager[] = {
47 'S','o','f','t','w','a','r','e','\\',
48 'M','i','c','r','o','s','o','f','t','\\',
49 'W','i','n','d','o','w','s','\\',
50 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
51 'T','h','e','m','e','M','a','n','a','g','e','r','\0'
53 static const WCHAR szThemeActive[] = {'T','h','e','m','e','A','c','t','i','v','e','\0'};
54 static const WCHAR szSizeName[] = {'S','i','z','e','N','a','m','e','\0'};
55 static const WCHAR szColorName[] = {'C','o','l','o','r','N','a','m','e','\0'};
56 static const WCHAR szDllName[] = {'D','l','l','N','a','m','e','\0'};
58 static const WCHAR szIniDocumentation[] = {'d','o','c','u','m','e','n','t','a','t','i','o','n','\0'};
60 DECLSPEC_HIDDEN ATOM atDialogThemeEnabled;
62 static DWORD dwThemeAppProperties = STAP_ALLOW_NONCLIENT | STAP_ALLOW_CONTROLS;
63 static ATOM atWindowTheme;
64 static ATOM atSubAppName;
65 static ATOM atSubIdList;
67 static BOOL bThemeActive = FALSE;
68 static WCHAR szCurrentTheme[MAX_PATH];
69 static WCHAR szCurrentColor[64];
70 static WCHAR szCurrentSize[64];
72 /***********************************************************************/
74 static BOOL CALLBACK UXTHEME_broadcast_msg_enumchild (HWND hWnd, LPARAM msg)
76 PostMessageW(hWnd, msg, 0, 0);
77 return TRUE;
80 /* Broadcast a message to *all* windows, including children */
81 static BOOL CALLBACK UXTHEME_broadcast_msg (HWND hWnd, LPARAM msg)
83 if (hWnd == NULL)
85 EnumWindows (UXTHEME_broadcast_msg, msg);
87 else
89 PostMessageW(hWnd, msg, 0, 0);
90 EnumChildWindows (hWnd, UXTHEME_broadcast_msg_enumchild, msg);
92 return TRUE;
95 /* At the end of the day this is a subset of what SHRegGetPath() does - copied
96 * here to avoid linking against shlwapi. */
97 static DWORD query_reg_path (HKEY hKey, LPCWSTR lpszValue,
98 LPVOID pvData)
100 DWORD dwRet, dwType, dwUnExpDataLen = MAX_PATH, dwExpDataLen;
102 TRACE("(hkey=%p,%s,%p)\n", hKey, debugstr_w(lpszValue),
103 pvData);
105 dwRet = RegQueryValueExW(hKey, lpszValue, 0, &dwType, pvData, &dwUnExpDataLen);
106 if (dwRet!=ERROR_SUCCESS && dwRet!=ERROR_MORE_DATA)
107 return dwRet;
109 if (dwType == REG_EXPAND_SZ)
111 DWORD nBytesToAlloc;
113 /* Expand type REG_EXPAND_SZ into REG_SZ */
114 LPWSTR szData;
116 /* If the caller didn't supply a buffer or the buffer is too small we have
117 * to allocate our own
119 if (dwRet == ERROR_MORE_DATA)
121 WCHAR cNull = '\0';
122 nBytesToAlloc = dwUnExpDataLen;
124 szData = LocalAlloc(LMEM_ZEROINIT, nBytesToAlloc);
125 RegQueryValueExW (hKey, lpszValue, 0, NULL, (LPBYTE)szData, &nBytesToAlloc);
126 dwExpDataLen = ExpandEnvironmentStringsW(szData, &cNull, 1);
127 dwUnExpDataLen = max(nBytesToAlloc, dwExpDataLen);
128 LocalFree(szData);
130 else
132 nBytesToAlloc = (lstrlenW(pvData) + 1) * sizeof(WCHAR);
133 szData = LocalAlloc(LMEM_ZEROINIT, nBytesToAlloc );
134 lstrcpyW(szData, pvData);
135 dwExpDataLen = ExpandEnvironmentStringsW(szData, pvData, MAX_PATH );
136 if (dwExpDataLen > MAX_PATH) dwRet = ERROR_MORE_DATA;
137 dwUnExpDataLen = max(nBytesToAlloc, dwExpDataLen);
138 LocalFree(szData);
142 RegCloseKey(hKey);
143 return dwRet;
146 /***********************************************************************
147 * UXTHEME_LoadTheme
149 * Set the current active theme from the registry
151 static void UXTHEME_LoadTheme(void)
153 HKEY hKey;
154 DWORD buffsize;
155 HRESULT hr;
156 WCHAR tmp[10];
157 PTHEME_FILE pt;
159 /* Get current theme configuration */
160 if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
161 TRACE("Loading theme config\n");
162 buffsize = sizeof(tmp)/sizeof(tmp[0]);
163 if(!RegQueryValueExW(hKey, szThemeActive, NULL, NULL, (LPBYTE)tmp, &buffsize)) {
164 bThemeActive = (tmp[0] != '0');
166 else {
167 bThemeActive = FALSE;
168 TRACE("Failed to get ThemeActive: %d\n", GetLastError());
170 buffsize = sizeof(szCurrentColor)/sizeof(szCurrentColor[0]);
171 if(RegQueryValueExW(hKey, szColorName, NULL, NULL, (LPBYTE)szCurrentColor, &buffsize))
172 szCurrentColor[0] = '\0';
173 buffsize = sizeof(szCurrentSize)/sizeof(szCurrentSize[0]);
174 if(RegQueryValueExW(hKey, szSizeName, NULL, NULL, (LPBYTE)szCurrentSize, &buffsize))
175 szCurrentSize[0] = '\0';
176 if (query_reg_path (hKey, szDllName, szCurrentTheme))
177 szCurrentTheme[0] = '\0';
178 RegCloseKey(hKey);
180 else
181 TRACE("Failed to open theme registry key\n");
183 if(bThemeActive) {
184 /* Make sure the theme requested is actually valid */
185 hr = MSSTYLES_OpenThemeFile(szCurrentTheme,
186 szCurrentColor[0]?szCurrentColor:NULL,
187 szCurrentSize[0]?szCurrentSize:NULL,
188 &pt);
189 if(FAILED(hr)) {
190 bThemeActive = FALSE;
191 szCurrentTheme[0] = '\0';
192 szCurrentColor[0] = '\0';
193 szCurrentSize[0] = '\0';
195 else {
196 /* Make sure the global color & size match the theme */
197 lstrcpynW(szCurrentColor, pt->pszSelectedColor, sizeof(szCurrentColor)/sizeof(szCurrentColor[0]));
198 lstrcpynW(szCurrentSize, pt->pszSelectedSize, sizeof(szCurrentSize)/sizeof(szCurrentSize[0]));
200 MSSTYLES_SetActiveTheme(pt, FALSE);
201 TRACE("Theme active: %s %s %s\n", debugstr_w(szCurrentTheme),
202 debugstr_w(szCurrentColor), debugstr_w(szCurrentSize));
203 MSSTYLES_CloseThemeFile(pt);
206 if(!bThemeActive) {
207 MSSTYLES_SetActiveTheme(NULL, FALSE);
208 TRACE("Theming not active\n");
212 /***********************************************************************/
214 static const char * const SysColorsNames[] =
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 */
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 };
259 static const struct BackupSysParam
261 int spiGet, spiSet;
262 const WCHAR* keyName;
263 } backupSysParams[] =
265 {SPI_GETFLATMENU, SPI_SETFLATMENU, keyFlatMenus},
266 {SPI_GETGRADIENTCAPTIONS, SPI_SETGRADIENTCAPTIONS, keyGradientCaption},
267 {-1, -1, 0}
270 #define NUM_SYS_COLORS (COLOR_MENUBAR+1)
272 static void save_sys_colors (HKEY baseKey)
274 char colorStr[13];
275 HKEY hKey;
276 int i;
278 if (RegCreateKeyExW( baseKey, strColorKey,
279 0, 0, 0, KEY_ALL_ACCESS,
280 0, &hKey, 0 ) == ERROR_SUCCESS)
282 for (i = 0; i < NUM_SYS_COLORS; i++)
284 COLORREF col = GetSysColor (i);
286 sprintf (colorStr, "%d %d %d",
287 GetRValue (col), GetGValue (col), GetBValue (col));
289 RegSetValueExA (hKey, SysColorsNames[i], 0, REG_SZ,
290 (BYTE*)colorStr, strlen (colorStr)+1);
292 RegCloseKey (hKey);
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)
301 HKEY hKey;
302 const struct BackupSysParam* bsp = backupSysParams;
304 if (RegCreateKeyExW( HKEY_CURRENT_USER, szThemeManager,
305 0, 0, 0, KEY_ALL_ACCESS,
306 0, &hKey, 0) == ERROR_SUCCESS)
308 NONCLIENTMETRICSW ncm;
309 LOGFONTW iconTitleFont;
311 /* back up colors */
312 save_sys_colors (hKey);
314 /* back up "other" settings */
315 while (bsp->spiGet >= 0)
317 DWORD value;
319 SystemParametersInfoW (bsp->spiGet, 0, &value, 0);
320 RegSetValueExW (hKey, bsp->keyName, 0, REG_DWORD,
321 (LPBYTE)&value, sizeof (value));
323 bsp++;
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));
338 RegCloseKey (hKey);
342 /* Read back old settings after a theme was deactivated */
343 static void UXTHEME_RestoreSystemMetrics(void)
345 HKEY hKey;
346 const struct BackupSysParam* bsp = backupSysParams;
348 if (RegOpenKeyExW (HKEY_CURRENT_USER, szThemeManager,
349 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
351 HKEY colorKey;
353 /* read backed-up colors */
354 if (RegOpenKeyExW (hKey, strColorKey,
355 0, KEY_QUERY_VALUE, &colorKey) == ERROR_SUCCESS)
357 int i;
358 COLORREF sysCols[NUM_SYS_COLORS];
359 int sysColsIndices[NUM_SYS_COLORS];
360 int sysColCount = 0;
362 for (i = 0; i < NUM_SYS_COLORS; i++)
364 DWORD type;
365 char colorStr[13];
366 DWORD count = sizeof(colorStr);
368 if (RegQueryValueExA (colorKey, SysColorsNames[i], 0,
369 &type, (LPBYTE) colorStr, &count) == ERROR_SUCCESS)
371 int r, g, b;
372 if (sscanf (colorStr, "%d %d %d", &r, &g, &b) == 3)
374 sysColsIndices[sysColCount] = i;
375 sysCols[sysColCount] = RGB(r, g, b);
376 sysColCount++;
380 RegCloseKey (colorKey);
382 SetSysColors (sysColCount, sysColsIndices, sysCols);
385 /* read backed-up other settings */
386 while (bsp->spiGet >= 0)
388 DWORD value;
389 DWORD count = sizeof(value);
390 DWORD type;
392 if (RegQueryValueExW (hKey, bsp->keyName, 0,
393 &type, (LPBYTE)&value, &count) == ERROR_SUCCESS)
395 SystemParametersInfoW (bsp->spiSet, 0, UlongToPtr(value), SPIF_UPDATEINIFILE);
398 bsp++;
401 /* read backed-up non-client metrics */
403 NONCLIENTMETRICSW ncm;
404 LOGFONTW iconTitleFont;
405 DWORD count = sizeof(ncm);
406 DWORD type;
408 if (RegQueryValueExW (hKey, keyNonClientMetrics, 0,
409 &type, (LPBYTE)&ncm, &count) == ERROR_SUCCESS)
411 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS,
412 count, &ncm, SPIF_UPDATEINIFILE);
415 count = sizeof(iconTitleFont);
417 if (RegQueryValueExW (hKey, keyIconTitleFont, 0,
418 &type, (LPBYTE)&iconTitleFont, &count) == ERROR_SUCCESS)
420 SystemParametersInfoW (SPI_SETICONTITLELOGFONT,
421 count, &iconTitleFont, SPIF_UPDATEINIFILE);
425 RegCloseKey (hKey);
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)
435 const struct BackupSysParam* bsp = backupSysParams;
436 NONCLIENTMETRICSW ncm;
437 LOGFONTW iconTitleFont;
439 save_sys_colors (HKEY_CURRENT_USER);
441 while (bsp->spiGet >= 0)
443 DWORD value;
445 SystemParametersInfoW (bsp->spiGet, 0, &value, 0);
446 SystemParametersInfoW (bsp->spiSet, 0, UlongToPtr(value), SPIF_UPDATEINIFILE);
447 bsp++;
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);
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);
463 /***********************************************************************
464 * UXTHEME_SetActiveTheme
466 * Change the current active theme
468 static HRESULT UXTHEME_SetActiveTheme(PTHEME_FILE tf)
470 HKEY hKey;
471 WCHAR tmp[2];
472 HRESULT hr;
474 if(tf && !bThemeActive) UXTHEME_BackupSystemMetrics();
475 hr = MSSTYLES_SetActiveTheme(tf, TRUE);
476 if(FAILED(hr))
477 return hr;
478 if(tf) {
479 bThemeActive = TRUE;
480 lstrcpynW(szCurrentTheme, tf->szThemeFile, sizeof(szCurrentTheme)/sizeof(szCurrentTheme[0]));
481 lstrcpynW(szCurrentColor, tf->pszSelectedColor, sizeof(szCurrentColor)/sizeof(szCurrentColor[0]));
482 lstrcpynW(szCurrentSize, tf->pszSelectedSize, sizeof(szCurrentSize)/sizeof(szCurrentSize[0]));
484 else {
485 UXTHEME_RestoreSystemMetrics();
486 bThemeActive = FALSE;
487 szCurrentTheme[0] = '\0';
488 szCurrentColor[0] = '\0';
489 szCurrentSize[0] = '\0';
492 TRACE("Writing theme config to registry\n");
493 if(!RegCreateKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
494 tmp[0] = bThemeActive?'1':'0';
495 tmp[1] = '\0';
496 RegSetValueExW(hKey, szThemeActive, 0, REG_SZ, (const BYTE*)tmp, sizeof(WCHAR)*2);
497 if(bThemeActive) {
498 RegSetValueExW(hKey, szColorName, 0, REG_SZ, (const BYTE*)szCurrentColor,
499 (lstrlenW(szCurrentColor)+1)*sizeof(WCHAR));
500 RegSetValueExW(hKey, szSizeName, 0, REG_SZ, (const BYTE*)szCurrentSize,
501 (lstrlenW(szCurrentSize)+1)*sizeof(WCHAR));
502 RegSetValueExW(hKey, szDllName, 0, REG_SZ, (const BYTE*)szCurrentTheme,
503 (lstrlenW(szCurrentTheme)+1)*sizeof(WCHAR));
505 else {
506 RegDeleteValueW(hKey, szColorName);
507 RegDeleteValueW(hKey, szSizeName);
508 RegDeleteValueW(hKey, szDllName);
511 RegCloseKey(hKey);
513 else
514 TRACE("Failed to open theme registry key\n");
516 UXTHEME_SaveSystemMetrics ();
518 return hr;
521 /***********************************************************************
522 * UXTHEME_InitSystem
524 void UXTHEME_InitSystem(HINSTANCE hInst)
526 static const WCHAR szWindowTheme[] = {
527 'u','x','_','t','h','e','m','e','\0'
529 static const WCHAR szSubAppName[] = {
530 'u','x','_','s','u','b','a','p','p','\0'
532 static const WCHAR szSubIdList[] = {
533 'u','x','_','s','u','b','i','d','l','s','t','\0'
535 static const WCHAR szDialogThemeEnabled[] = {
536 'u','x','_','d','i','a','l','o','g','t','h','e','m','e','\0'
539 atWindowTheme = GlobalAddAtomW(szWindowTheme);
540 atSubAppName = GlobalAddAtomW(szSubAppName);
541 atSubIdList = GlobalAddAtomW(szSubIdList);
542 atDialogThemeEnabled = GlobalAddAtomW(szDialogThemeEnabled);
544 UXTHEME_LoadTheme();
547 /***********************************************************************
548 * IsAppThemed (UXTHEME.@)
550 BOOL WINAPI IsAppThemed(void)
552 return IsThemeActive();
555 /***********************************************************************
556 * IsThemeActive (UXTHEME.@)
558 BOOL WINAPI IsThemeActive(void)
560 TRACE("\n");
561 SetLastError(ERROR_SUCCESS);
562 return bThemeActive;
565 /************************************************************
566 * IsCompositionActive (UXTHEME.@)
568 BOOL WINAPI IsCompositionActive(void)
570 FIXME(": stub\n");
572 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
574 return FALSE;
577 /***********************************************************************
578 * EnableTheming (UXTHEME.@)
580 * NOTES
581 * This is a global and persistent change
583 HRESULT WINAPI EnableTheming(BOOL fEnable)
585 HKEY hKey;
586 WCHAR szEnabled[] = {'0','\0'};
588 TRACE("(%d)\n", fEnable);
590 if(fEnable != bThemeActive) {
591 if(fEnable)
592 UXTHEME_BackupSystemMetrics();
593 else
594 UXTHEME_RestoreSystemMetrics();
595 UXTHEME_SaveSystemMetrics ();
596 bThemeActive = fEnable;
597 if(bThemeActive) szEnabled[0] = '1';
598 if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
599 RegSetValueExW(hKey, szThemeActive, 0, REG_SZ, (LPBYTE)szEnabled, sizeof(WCHAR));
600 RegCloseKey(hKey);
602 UXTHEME_broadcast_msg (NULL, WM_THEMECHANGED);
604 return S_OK;
607 /***********************************************************************
608 * UXTHEME_SetWindowProperty
610 * I'm using atoms as there may be large numbers of duplicated strings
611 * and they do the work of keeping memory down as a cause of that quite nicely
613 static HRESULT UXTHEME_SetWindowProperty(HWND hwnd, ATOM aProp, LPCWSTR pszValue)
615 ATOM oldValue = (ATOM)(size_t)RemovePropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp));
616 if(oldValue)
617 DeleteAtom(oldValue);
618 if(pszValue) {
619 ATOM atValue = AddAtomW(pszValue);
620 if(!atValue
621 || !SetPropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp), (LPWSTR)MAKEINTATOM(atValue))) {
622 HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
623 if(atValue) DeleteAtom(atValue);
624 return hr;
627 return S_OK;
630 static LPWSTR UXTHEME_GetWindowProperty(HWND hwnd, ATOM aProp, LPWSTR pszBuffer, int dwLen)
632 ATOM atValue = (ATOM)(size_t)GetPropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp));
633 if(atValue) {
634 if(GetAtomNameW(atValue, pszBuffer, dwLen))
635 return pszBuffer;
636 TRACE("property defined, but unable to get value\n");
638 return NULL;
641 /***********************************************************************
642 * OpenThemeDataEx (UXTHEME.61)
644 HTHEME WINAPI OpenThemeDataEx(HWND hwnd, LPCWSTR pszClassList, DWORD flags)
646 WCHAR szAppBuff[256];
647 WCHAR szClassBuff[256];
648 LPCWSTR pszAppName;
649 LPCWSTR pszUseClassList;
650 HTHEME hTheme = NULL;
651 TRACE("(%p,%s, %x)\n", hwnd, debugstr_w(pszClassList), flags);
653 if(!pszClassList)
655 SetLastError(E_POINTER);
656 return NULL;
659 if(flags)
660 FIXME("unhandled flags: %x\n", flags);
662 if(bThemeActive)
664 pszAppName = UXTHEME_GetWindowProperty(hwnd, atSubAppName, szAppBuff, sizeof(szAppBuff)/sizeof(szAppBuff[0]));
665 /* If SetWindowTheme was used on the window, that overrides the class list passed to this function */
666 pszUseClassList = UXTHEME_GetWindowProperty(hwnd, atSubIdList, szClassBuff, sizeof(szClassBuff)/sizeof(szClassBuff[0]));
667 if(!pszUseClassList)
668 pszUseClassList = pszClassList;
670 if (pszUseClassList)
671 hTheme = MSSTYLES_OpenThemeClass(pszAppName, pszUseClassList);
673 if(IsWindow(hwnd))
674 SetPropW(hwnd, (LPCWSTR)MAKEINTATOM(atWindowTheme), hTheme);
675 TRACE(" = %p\n", hTheme);
676 return hTheme;
679 /***********************************************************************
680 * OpenThemeData (UXTHEME.@)
682 HTHEME WINAPI OpenThemeData(HWND hwnd, LPCWSTR classlist)
684 return OpenThemeDataEx(hwnd, classlist, 0);
687 /***********************************************************************
688 * GetWindowTheme (UXTHEME.@)
690 * Retrieve the last theme opened for a window.
692 * PARAMS
693 * hwnd [I] window to retrieve the theme for
695 * RETURNS
696 * The most recent theme.
698 HTHEME WINAPI GetWindowTheme(HWND hwnd)
700 TRACE("(%p)\n", hwnd);
701 return GetPropW(hwnd, (LPCWSTR)MAKEINTATOM(atWindowTheme));
704 /***********************************************************************
705 * SetWindowTheme (UXTHEME.@)
707 * Persistent through the life of the window, even after themes change
709 HRESULT WINAPI SetWindowTheme(HWND hwnd, LPCWSTR pszSubAppName,
710 LPCWSTR pszSubIdList)
712 HRESULT hr;
713 TRACE("(%p,%s,%s)\n", hwnd, debugstr_w(pszSubAppName),
714 debugstr_w(pszSubIdList));
715 hr = UXTHEME_SetWindowProperty(hwnd, atSubAppName, pszSubAppName);
716 if(SUCCEEDED(hr))
717 hr = UXTHEME_SetWindowProperty(hwnd, atSubIdList, pszSubIdList);
718 if(SUCCEEDED(hr))
719 UXTHEME_broadcast_msg (hwnd, WM_THEMECHANGED);
720 return hr;
723 /***********************************************************************
724 * SetWindowThemeAttribute (UXTHEME.@)
726 HRESULT WINAPI SetWindowThemeAttribute(HWND hwnd, enum WINDOWTHEMEATTRIBUTETYPE type,
727 PVOID attribute, DWORD size)
729 FIXME("(%p,%d,%p,%d): stub\n", hwnd, type, attribute, size);
730 return E_NOTIMPL;
733 /***********************************************************************
734 * GetCurrentThemeName (UXTHEME.@)
736 HRESULT WINAPI GetCurrentThemeName(LPWSTR pszThemeFileName, int dwMaxNameChars,
737 LPWSTR pszColorBuff, int cchMaxColorChars,
738 LPWSTR pszSizeBuff, int cchMaxSizeChars)
740 if(!bThemeActive)
741 return E_PROP_ID_UNSUPPORTED;
742 if(pszThemeFileName) lstrcpynW(pszThemeFileName, szCurrentTheme, dwMaxNameChars);
743 if(pszColorBuff) lstrcpynW(pszColorBuff, szCurrentColor, cchMaxColorChars);
744 if(pszSizeBuff) lstrcpynW(pszSizeBuff, szCurrentSize, cchMaxSizeChars);
745 return S_OK;
748 /***********************************************************************
749 * GetThemeAppProperties (UXTHEME.@)
751 DWORD WINAPI GetThemeAppProperties(void)
753 return dwThemeAppProperties;
756 /***********************************************************************
757 * SetThemeAppProperties (UXTHEME.@)
759 void WINAPI SetThemeAppProperties(DWORD dwFlags)
761 TRACE("(0x%08x)\n", dwFlags);
762 dwThemeAppProperties = dwFlags;
765 /***********************************************************************
766 * CloseThemeData (UXTHEME.@)
768 HRESULT WINAPI CloseThemeData(HTHEME hTheme)
770 TRACE("(%p)\n", hTheme);
771 if(!hTheme || hTheme == INVALID_HANDLE_VALUE)
772 return E_HANDLE;
773 return MSSTYLES_CloseThemeClass(hTheme);
776 /***********************************************************************
777 * HitTestThemeBackground (UXTHEME.@)
779 HRESULT WINAPI HitTestThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
780 int iStateId, DWORD dwOptions,
781 const RECT *pRect, HRGN hrgn,
782 POINT ptTest, WORD *pwHitTestCode)
784 FIXME("%d %d 0x%08x: stub\n", iPartId, iStateId, dwOptions);
785 if(!hTheme)
786 return E_HANDLE;
787 return E_NOTIMPL;
790 /***********************************************************************
791 * IsThemePartDefined (UXTHEME.@)
793 BOOL WINAPI IsThemePartDefined(HTHEME hTheme, int iPartId, int iStateId)
795 TRACE("(%p,%d,%d)\n", hTheme, iPartId, iStateId);
796 if(!hTheme) {
797 SetLastError(E_HANDLE);
798 return FALSE;
800 if(MSSTYLES_FindPartState(hTheme, iPartId, iStateId, NULL))
801 return TRUE;
802 return FALSE;
805 /***********************************************************************
806 * GetThemeDocumentationProperty (UXTHEME.@)
808 * Try and retrieve the documentation property from string resources
809 * if that fails, get it from the [documentation] section of themes.ini
811 HRESULT WINAPI GetThemeDocumentationProperty(LPCWSTR pszThemeName,
812 LPCWSTR pszPropertyName,
813 LPWSTR pszValueBuff,
814 int cchMaxValChars)
816 const WORD wDocToRes[] = {
817 TMT_DISPLAYNAME,5000,
818 TMT_TOOLTIP,5001,
819 TMT_COMPANY,5002,
820 TMT_AUTHOR,5003,
821 TMT_COPYRIGHT,5004,
822 TMT_URL,5005,
823 TMT_VERSION,5006,
824 TMT_DESCRIPTION,5007
827 PTHEME_FILE pt;
828 HRESULT hr;
829 unsigned int i;
830 int iDocId;
831 TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName), debugstr_w(pszPropertyName),
832 pszValueBuff, cchMaxValChars);
834 hr = MSSTYLES_OpenThemeFile(pszThemeName, NULL, NULL, &pt);
835 if(FAILED(hr)) return hr;
837 /* Try to load from string resources */
838 hr = E_PROP_ID_UNSUPPORTED;
839 if(MSSTYLES_LookupProperty(pszPropertyName, NULL, &iDocId)) {
840 for(i=0; i<sizeof(wDocToRes)/sizeof(wDocToRes[0]); i+=2) {
841 if(wDocToRes[i] == iDocId) {
842 if(LoadStringW(pt->hTheme, wDocToRes[i+1], pszValueBuff, cchMaxValChars)) {
843 hr = S_OK;
844 break;
849 /* If loading from string resource failed, try getting it from the theme.ini */
850 if(FAILED(hr)) {
851 PUXINI_FILE uf = MSSTYLES_GetThemeIni(pt);
852 if(UXINI_FindSection(uf, szIniDocumentation)) {
853 LPCWSTR lpValue;
854 DWORD dwLen;
855 if(UXINI_FindValue(uf, pszPropertyName, &lpValue, &dwLen)) {
856 lstrcpynW(pszValueBuff, lpValue, min(dwLen+1,cchMaxValChars));
857 hr = S_OK;
860 UXINI_CloseINI(uf);
863 MSSTYLES_CloseThemeFile(pt);
864 return hr;
867 /**********************************************************************
868 * Undocumented functions
871 /**********************************************************************
872 * QueryThemeServices (UXTHEME.1)
874 * RETURNS
875 * some kind of status flag
877 DWORD WINAPI QueryThemeServices(void)
879 FIXME("stub\n");
880 return 3; /* This is what is returned under XP in most cases */
884 /**********************************************************************
885 * OpenThemeFile (UXTHEME.2)
887 * Opens a theme file, which can be used to change the current theme, etc
889 * PARAMS
890 * pszThemeFileName Path to a msstyles theme file
891 * pszColorName Color defined in the theme, eg. NormalColor
892 * pszSizeName Size defined in the theme, eg. NormalSize
893 * hThemeFile Handle to theme file
895 * RETURNS
896 * Success: S_OK
897 * Failure: HRESULT error-code
899 HRESULT WINAPI OpenThemeFile(LPCWSTR pszThemeFileName, LPCWSTR pszColorName,
900 LPCWSTR pszSizeName, HTHEMEFILE *hThemeFile,
901 DWORD unknown)
903 TRACE("(%s,%s,%s,%p,%d)\n", debugstr_w(pszThemeFileName),
904 debugstr_w(pszColorName), debugstr_w(pszSizeName),
905 hThemeFile, unknown);
906 return MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, pszSizeName, (PTHEME_FILE*)hThemeFile);
909 /**********************************************************************
910 * CloseThemeFile (UXTHEME.3)
912 * Releases theme file handle returned by OpenThemeFile
914 * PARAMS
915 * hThemeFile Handle to theme file
917 * RETURNS
918 * Success: S_OK
919 * Failure: HRESULT error-code
921 HRESULT WINAPI CloseThemeFile(HTHEMEFILE hThemeFile)
923 TRACE("(%p)\n", hThemeFile);
924 MSSTYLES_CloseThemeFile(hThemeFile);
925 return S_OK;
928 /**********************************************************************
929 * ApplyTheme (UXTHEME.4)
931 * Set a theme file to be the currently active theme
933 * PARAMS
934 * hThemeFile Handle to theme file
935 * unknown See notes
936 * hWnd Window requesting the theme change
938 * RETURNS
939 * Success: S_OK
940 * Failure: HRESULT error-code
942 * NOTES
943 * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
944 * Under XP if I pass
945 * char b[] = "";
946 * the theme is applied with the screen redrawing really badly (flickers)
947 * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
948 * the theme is applied smoothly (screen does not flicker)
949 * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
950 * the function fails returning invalid parameter... very strange
952 HRESULT WINAPI ApplyTheme(HTHEMEFILE hThemeFile, char *unknown, HWND hWnd)
954 HRESULT hr;
955 TRACE("(%p,%s,%p)\n", hThemeFile, unknown, hWnd);
956 hr = UXTHEME_SetActiveTheme(hThemeFile);
957 UXTHEME_broadcast_msg (NULL, WM_THEMECHANGED);
958 return hr;
961 /**********************************************************************
962 * GetThemeDefaults (UXTHEME.7)
964 * Get the default color & size for a theme
966 * PARAMS
967 * pszThemeFileName Path to a msstyles theme file
968 * pszColorName Buffer to receive the default color name
969 * dwColorNameLen Length, in characters, of color name buffer
970 * pszSizeName Buffer to receive the default size name
971 * dwSizeNameLen Length, in characters, of size name buffer
973 * RETURNS
974 * Success: S_OK
975 * Failure: HRESULT error-code
977 HRESULT WINAPI GetThemeDefaults(LPCWSTR pszThemeFileName, LPWSTR pszColorName,
978 DWORD dwColorNameLen, LPWSTR pszSizeName,
979 DWORD dwSizeNameLen)
981 PTHEME_FILE pt;
982 HRESULT hr;
983 TRACE("(%s,%p,%d,%p,%d)\n", debugstr_w(pszThemeFileName),
984 pszColorName, dwColorNameLen,
985 pszSizeName, dwSizeNameLen);
987 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
988 if(FAILED(hr)) return hr;
990 lstrcpynW(pszColorName, pt->pszSelectedColor, dwColorNameLen);
991 lstrcpynW(pszSizeName, pt->pszSelectedSize, dwSizeNameLen);
993 MSSTYLES_CloseThemeFile(pt);
994 return S_OK;
997 /**********************************************************************
998 * EnumThemes (UXTHEME.8)
1000 * Enumerate available themes, calls specified EnumThemeProc for each
1001 * theme found. Passes lpData through to callback function.
1003 * PARAMS
1004 * pszThemePath Path containing themes
1005 * callback Called for each theme found in path
1006 * lpData Passed through to callback
1008 * RETURNS
1009 * Success: S_OK
1010 * Failure: HRESULT error-code
1012 HRESULT WINAPI EnumThemes(LPCWSTR pszThemePath, EnumThemeProc callback,
1013 LPVOID lpData)
1015 WCHAR szDir[MAX_PATH];
1016 WCHAR szPath[MAX_PATH];
1017 static const WCHAR szStar[] = {'*','.','*','\0'};
1018 static const WCHAR szFormat[] = {'%','s','%','s','\\','%','s','.','m','s','s','t','y','l','e','s','\0'};
1019 static const WCHAR szDisplayName[] = {'d','i','s','p','l','a','y','n','a','m','e','\0'};
1020 static const WCHAR szTooltip[] = {'t','o','o','l','t','i','p','\0'};
1021 WCHAR szName[60];
1022 WCHAR szTip[60];
1023 HANDLE hFind;
1024 WIN32_FIND_DATAW wfd;
1025 HRESULT hr;
1026 size_t pathLen;
1028 TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath), callback, lpData);
1030 if(!pszThemePath || !callback)
1031 return E_POINTER;
1033 lstrcpyW(szDir, pszThemePath);
1034 pathLen = lstrlenW (szDir);
1035 if ((pathLen > 0) && (pathLen < MAX_PATH-1) && (szDir[pathLen - 1] != '\\'))
1037 szDir[pathLen] = '\\';
1038 szDir[pathLen+1] = 0;
1041 lstrcpyW(szPath, szDir);
1042 lstrcatW(szPath, szStar);
1043 TRACE("searching %s\n", debugstr_w(szPath));
1045 hFind = FindFirstFileW(szPath, &wfd);
1046 if(hFind != INVALID_HANDLE_VALUE) {
1047 do {
1048 if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
1049 && !(wfd.cFileName[0] == '.' && ((wfd.cFileName[1] == '.' && wfd.cFileName[2] == 0) || wfd.cFileName[1] == 0))) {
1050 wsprintfW(szPath, szFormat, szDir, wfd.cFileName, wfd.cFileName);
1052 hr = GetThemeDocumentationProperty(szPath, szDisplayName, szName, sizeof(szName)/sizeof(szName[0]));
1053 if(SUCCEEDED(hr))
1054 hr = GetThemeDocumentationProperty(szPath, szTooltip, szTip, sizeof(szTip)/sizeof(szTip[0]));
1055 if(SUCCEEDED(hr)) {
1056 TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath), debugstr_w(szName), debugstr_w(szTip), lpData);
1057 if(!callback(NULL, szPath, szName, szTip, NULL, lpData)) {
1058 TRACE("callback ended enum\n");
1059 break;
1063 } while(FindNextFileW(hFind, &wfd));
1064 FindClose(hFind);
1066 return S_OK;
1070 /**********************************************************************
1071 * EnumThemeColors (UXTHEME.9)
1073 * Enumerate theme colors available with a particular size
1075 * PARAMS
1076 * pszThemeFileName Path to a msstyles theme file
1077 * pszSizeName Theme size to enumerate available colors
1078 * If NULL the default theme size is used
1079 * dwColorNum Color index to retrieve, increment from 0
1080 * pszColorNames Output color names
1082 * RETURNS
1083 * S_OK on success
1084 * E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
1085 * or when pszSizeName does not refer to a valid size
1087 * NOTES
1088 * XP fails with E_POINTER when pszColorNames points to a buffer smaller than
1089 * sizeof(THEMENAMES).
1091 * Not very efficient that I'm opening & validating the theme every call, but
1092 * this is undocumented and almost never called..
1093 * (and this is how windows works too)
1095 HRESULT WINAPI EnumThemeColors(LPWSTR pszThemeFileName, LPWSTR pszSizeName,
1096 DWORD dwColorNum, PTHEMENAMES pszColorNames)
1098 PTHEME_FILE pt;
1099 HRESULT hr;
1100 LPWSTR tmp;
1101 UINT resourceId = dwColorNum + 1000;
1102 TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName),
1103 debugstr_w(pszSizeName), dwColorNum);
1105 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, pszSizeName, &pt);
1106 if(FAILED(hr)) return hr;
1108 tmp = pt->pszAvailColors;
1109 while(dwColorNum && *tmp) {
1110 dwColorNum--;
1111 tmp += lstrlenW(tmp)+1;
1113 if(!dwColorNum && *tmp) {
1114 TRACE("%s\n", debugstr_w(tmp));
1115 lstrcpyW(pszColorNames->szName, tmp);
1116 LoadStringW (pt->hTheme, resourceId,
1117 pszColorNames->szDisplayName,
1118 sizeof (pszColorNames->szDisplayName) / sizeof (WCHAR));
1119 LoadStringW (pt->hTheme, resourceId+1000,
1120 pszColorNames->szTooltip,
1121 sizeof (pszColorNames->szTooltip) / sizeof (WCHAR));
1123 else
1124 hr = E_PROP_ID_UNSUPPORTED;
1126 MSSTYLES_CloseThemeFile(pt);
1127 return hr;
1130 /**********************************************************************
1131 * EnumThemeSizes (UXTHEME.10)
1133 * Enumerate theme colors available with a particular size
1135 * PARAMS
1136 * pszThemeFileName Path to a msstyles theme file
1137 * pszColorName Theme color to enumerate available sizes
1138 * If NULL the default theme color is used
1139 * dwSizeNum Size index to retrieve, increment from 0
1140 * pszSizeNames Output size names
1142 * RETURNS
1143 * S_OK on success
1144 * E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
1145 * or when pszColorName does not refer to a valid color
1147 * NOTES
1148 * XP fails with E_POINTER when pszSizeNames points to a buffer smaller than
1149 * sizeof(THEMENAMES).
1151 * Not very efficient that I'm opening & validating the theme every call, but
1152 * this is undocumented and almost never called..
1153 * (and this is how windows works too)
1155 HRESULT WINAPI EnumThemeSizes(LPWSTR pszThemeFileName, LPWSTR pszColorName,
1156 DWORD dwSizeNum, PTHEMENAMES pszSizeNames)
1158 PTHEME_FILE pt;
1159 HRESULT hr;
1160 LPWSTR tmp;
1161 UINT resourceId = dwSizeNum + 3000;
1162 TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName),
1163 debugstr_w(pszColorName), dwSizeNum);
1165 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, NULL, &pt);
1166 if(FAILED(hr)) return hr;
1168 tmp = pt->pszAvailSizes;
1169 while(dwSizeNum && *tmp) {
1170 dwSizeNum--;
1171 tmp += lstrlenW(tmp)+1;
1173 if(!dwSizeNum && *tmp) {
1174 TRACE("%s\n", debugstr_w(tmp));
1175 lstrcpyW(pszSizeNames->szName, tmp);
1176 LoadStringW (pt->hTheme, resourceId,
1177 pszSizeNames->szDisplayName,
1178 sizeof (pszSizeNames->szDisplayName) / sizeof (WCHAR));
1179 LoadStringW (pt->hTheme, resourceId+1000,
1180 pszSizeNames->szTooltip,
1181 sizeof (pszSizeNames->szTooltip) / sizeof (WCHAR));
1183 else
1184 hr = E_PROP_ID_UNSUPPORTED;
1186 MSSTYLES_CloseThemeFile(pt);
1187 return hr;
1190 /**********************************************************************
1191 * ParseThemeIniFile (UXTHEME.11)
1193 * Enumerate data in a theme INI file.
1195 * PARAMS
1196 * pszIniFileName Path to a theme ini file
1197 * pszUnknown Cannot be NULL, L"" is valid
1198 * callback Called for each found entry
1199 * lpData Passed through to callback
1201 * RETURNS
1202 * S_OK on success
1203 * 0x800706488 (Unknown property) when enumeration is canceled from callback
1205 * NOTES
1206 * When pszUnknown is NULL the callback is never called, the value does not seem to serve
1207 * any other purpose
1209 HRESULT WINAPI ParseThemeIniFile(LPCWSTR pszIniFileName, LPWSTR pszUnknown,
1210 ParseThemeIniFileProc callback, LPVOID lpData)
1212 FIXME("%s %s: stub\n", debugstr_w(pszIniFileName), debugstr_w(pszUnknown));
1213 return E_NOTIMPL;
1216 /**********************************************************************
1217 * CheckThemeSignature (UXTHEME.29)
1219 * Validates the signature of a theme file
1221 * PARAMS
1222 * pszIniFileName Path to a theme file
1224 * RETURNS
1225 * Success: S_OK
1226 * Failure: HRESULT error-code
1228 HRESULT WINAPI CheckThemeSignature(LPCWSTR pszThemeFileName)
1230 PTHEME_FILE pt;
1231 HRESULT hr;
1232 TRACE("(%s)\n", debugstr_w(pszThemeFileName));
1233 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
1234 if(FAILED(hr))
1235 return hr;
1236 MSSTYLES_CloseThemeFile(pt);
1237 return S_OK;