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
35 #include "uxthemedll.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'};
61 ATOM atDialogThemeEnabled
;
63 static DWORD dwThemeAppProperties
= STAP_ALLOW_NONCLIENT
| STAP_ALLOW_CONTROLS
;
64 static ATOM atWindowTheme
;
65 static ATOM atSubAppName
;
66 static ATOM atSubIdList
;
68 static BOOL bThemeActive
= FALSE
;
69 static WCHAR szCurrentTheme
[MAX_PATH
];
70 static WCHAR szCurrentColor
[64];
71 static WCHAR szCurrentSize
[64];
73 /***********************************************************************/
75 static BOOL CALLBACK
UXTHEME_broadcast_msg_enumchild (HWND hWnd
, LPARAM msg
)
77 PostMessageW(hWnd
, msg
, 0, 0);
81 /* Broadcast a message to *all* windows, including children */
82 static BOOL CALLBACK
UXTHEME_broadcast_msg (HWND hWnd
, LPARAM msg
)
86 EnumWindows (UXTHEME_broadcast_msg
, msg
);
90 PostMessageW(hWnd
, msg
, 0, 0);
91 EnumChildWindows (hWnd
, UXTHEME_broadcast_msg_enumchild
, msg
);
96 /* At the end of the day this is a subset of what SHRegGetPath() does - copied
97 * here to avoid linking against shlwapi. */
98 static DWORD
query_reg_path (HKEY hKey
, LPCWSTR lpszValue
,
101 DWORD dwRet
, dwType
, dwUnExpDataLen
= MAX_PATH
, dwExpDataLen
;
103 TRACE("(hkey=%p,%s,%p)\n", hKey
, debugstr_w(lpszValue
),
106 dwRet
= RegQueryValueExW(hKey
, lpszValue
, 0, &dwType
, pvData
, &dwUnExpDataLen
);
107 if (dwRet
!=ERROR_SUCCESS
&& dwRet
!=ERROR_MORE_DATA
)
110 if (dwType
== REG_EXPAND_SZ
)
114 /* Expand type REG_EXPAND_SZ into REG_SZ */
117 /* If the caller didn't supply a buffer or the buffer is too small we have
118 * to allocate our own
120 if (dwRet
== ERROR_MORE_DATA
)
123 nBytesToAlloc
= dwUnExpDataLen
;
125 szData
= (LPWSTR
) LocalAlloc(LMEM_ZEROINIT
, nBytesToAlloc
);
126 RegQueryValueExW (hKey
, lpszValue
, 0, NULL
, (LPBYTE
)szData
, &nBytesToAlloc
);
127 dwExpDataLen
= ExpandEnvironmentStringsW(szData
, &cNull
, 1);
128 dwUnExpDataLen
= max(nBytesToAlloc
, dwExpDataLen
);
129 LocalFree((HLOCAL
) szData
);
133 nBytesToAlloc
= (lstrlenW(pvData
) + 1) * sizeof(WCHAR
);
134 szData
= (LPWSTR
) LocalAlloc(LMEM_ZEROINIT
, nBytesToAlloc
);
135 lstrcpyW(szData
, pvData
);
136 dwExpDataLen
= ExpandEnvironmentStringsW(szData
, pvData
, MAX_PATH
);
137 if (dwExpDataLen
> MAX_PATH
) dwRet
= ERROR_MORE_DATA
;
138 dwUnExpDataLen
= max(nBytesToAlloc
, dwExpDataLen
);
139 LocalFree((HLOCAL
) szData
);
147 /***********************************************************************
150 * Set the current active theme from the registry
152 static void UXTHEME_LoadTheme(void)
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');
168 bThemeActive
= FALSE
;
169 TRACE("Failed to get ThemeActive: %d\n", GetLastError());
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';
182 TRACE("Failed to open theme registry key\n");
185 /* Make sure the theme requested is actually valid */
186 hr
= MSSTYLES_OpenThemeFile(szCurrentTheme
,
187 szCurrentColor
[0]?szCurrentColor
:NULL
,
188 szCurrentSize
[0]?szCurrentSize
:NULL
,
191 bThemeActive
= FALSE
;
192 szCurrentTheme
[0] = '\0';
193 szCurrentColor
[0] = '\0';
194 szCurrentSize
[0] = '\0';
197 /* Make sure the global color & size match the theme */
198 lstrcpynW(szCurrentColor
, pt
->pszSelectedColor
, sizeof(szCurrentColor
)/sizeof(szCurrentColor
[0]));
199 lstrcpynW(szCurrentSize
, pt
->pszSelectedSize
, sizeof(szCurrentSize
)/sizeof(szCurrentSize
[0]));
201 MSSTYLES_SetActiveTheme(pt
, FALSE
);
202 TRACE("Theme active: %s %s %s\n", debugstr_w(szCurrentTheme
),
203 debugstr_w(szCurrentColor
), debugstr_w(szCurrentSize
));
204 MSSTYLES_CloseThemeFile(pt
);
208 MSSTYLES_SetActiveTheme(NULL
, FALSE
);
209 TRACE("Theming not active\n");
213 /***********************************************************************/
215 static const char * const SysColorsNames
[] =
217 "Scrollbar", /* COLOR_SCROLLBAR */
218 "Background", /* COLOR_BACKGROUND */
219 "ActiveTitle", /* COLOR_ACTIVECAPTION */
220 "InactiveTitle", /* COLOR_INACTIVECAPTION */
221 "Menu", /* COLOR_MENU */
222 "Window", /* COLOR_WINDOW */
223 "WindowFrame", /* COLOR_WINDOWFRAME */
224 "MenuText", /* COLOR_MENUTEXT */
225 "WindowText", /* COLOR_WINDOWTEXT */
226 "TitleText", /* COLOR_CAPTIONTEXT */
227 "ActiveBorder", /* COLOR_ACTIVEBORDER */
228 "InactiveBorder", /* COLOR_INACTIVEBORDER */
229 "AppWorkSpace", /* COLOR_APPWORKSPACE */
230 "Hilight", /* COLOR_HIGHLIGHT */
231 "HilightText", /* COLOR_HIGHLIGHTTEXT */
232 "ButtonFace", /* COLOR_BTNFACE */
233 "ButtonShadow", /* COLOR_BTNSHADOW */
234 "GrayText", /* COLOR_GRAYTEXT */
235 "ButtonText", /* COLOR_BTNTEXT */
236 "InactiveTitleText", /* COLOR_INACTIVECAPTIONTEXT */
237 "ButtonHilight", /* COLOR_BTNHIGHLIGHT */
238 "ButtonDkShadow", /* COLOR_3DDKSHADOW */
239 "ButtonLight", /* COLOR_3DLIGHT */
240 "InfoText", /* COLOR_INFOTEXT */
241 "InfoWindow", /* COLOR_INFOBK */
242 "ButtonAlternateFace", /* COLOR_ALTERNATEBTNFACE */
243 "HotTrackingColor", /* COLOR_HOTLIGHT */
244 "GradientActiveTitle", /* COLOR_GRADIENTACTIVECAPTION */
245 "GradientInactiveTitle", /* COLOR_GRADIENTINACTIVECAPTION */
246 "MenuHilight", /* COLOR_MENUHILIGHT */
247 "MenuBar", /* COLOR_MENUBAR */
249 static const WCHAR strColorKey
[] =
250 { 'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
251 'C','o','l','o','r','s',0 };
252 static const WCHAR keyFlatMenus
[] = { 'F','l','a','t','M','e','n','u', 0};
253 static const WCHAR keyGradientCaption
[] = { 'G','r','a','d','i','e','n','t',
254 'C','a','p','t','i','o','n', 0 };
255 static const WCHAR keyNonClientMetrics
[] = { 'N','o','n','C','l','i','e','n','t',
256 'M','e','t','r','i','c','s',0 };
257 static const WCHAR keyIconTitleFont
[] = { 'I','c','o','n','T','i','t','l','e',
260 static const struct BackupSysParam
263 const WCHAR
* keyName
;
264 } backupSysParams
[] =
266 {SPI_GETFLATMENU
, SPI_SETFLATMENU
, keyFlatMenus
},
267 {SPI_GETGRADIENTCAPTIONS
, SPI_SETGRADIENTCAPTIONS
, keyGradientCaption
},
271 #define NUM_SYS_COLORS (COLOR_MENUBAR+1)
273 static void save_sys_colors (HKEY baseKey
)
279 if (RegCreateKeyExW( baseKey
, strColorKey
,
280 0, 0, 0, KEY_ALL_ACCESS
,
281 0, &hKey
, 0 ) == ERROR_SUCCESS
)
283 for (i
= 0; i
< NUM_SYS_COLORS
; i
++)
285 COLORREF col
= GetSysColor (i
);
287 sprintf (colorStr
, "%d %d %d",
288 GetRValue (col
), GetGValue (col
), GetBValue (col
));
290 RegSetValueExA (hKey
, SysColorsNames
[i
], 0, REG_SZ
,
291 (BYTE
*)colorStr
, strlen (colorStr
)+1);
297 /* Before activating a theme, query current system colors, certain settings
298 * and backup them in the registry, so they can be restored when the theme
300 static void UXTHEME_BackupSystemMetrics(void)
303 const struct BackupSysParam
* bsp
= backupSysParams
;
305 if (RegCreateKeyExW( HKEY_CURRENT_USER
, szThemeManager
,
306 0, 0, 0, KEY_ALL_ACCESS
,
307 0, &hKey
, 0) == ERROR_SUCCESS
)
309 NONCLIENTMETRICSW ncm
;
310 LOGFONTW iconTitleFont
;
313 save_sys_colors (hKey
);
315 /* back up "other" settings */
316 while (bsp
->spiGet
>= 0)
320 SystemParametersInfoW (bsp
->spiGet
, 0, &value
, 0);
321 RegSetValueExW (hKey
, bsp
->keyName
, 0, REG_DWORD
,
322 (LPBYTE
)&value
, sizeof (value
));
327 /* back up non-client metrics */
328 memset (&ncm
, 0, sizeof (ncm
));
329 ncm
.cbSize
= sizeof (ncm
);
330 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof (ncm
), &ncm
, 0);
331 RegSetValueExW (hKey
, keyNonClientMetrics
, 0, REG_BINARY
, (LPBYTE
)&ncm
,
333 memset (&iconTitleFont
, 0, sizeof (iconTitleFont
));
334 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, sizeof (iconTitleFont
),
336 RegSetValueExW (hKey
, keyIconTitleFont
, 0, REG_BINARY
,
337 (LPBYTE
)&iconTitleFont
, sizeof (iconTitleFont
));
343 /* Read back old settings after a theme was deactivated */
344 static void UXTHEME_RestoreSystemMetrics(void)
347 const struct BackupSysParam
* bsp
= backupSysParams
;
349 if (RegOpenKeyExW (HKEY_CURRENT_USER
, szThemeManager
,
350 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
)
354 /* read backed-up colors */
355 if (RegOpenKeyExW (hKey
, strColorKey
,
356 0, KEY_QUERY_VALUE
, &colorKey
) == ERROR_SUCCESS
)
359 COLORREF sysCols
[NUM_SYS_COLORS
];
360 int sysColsIndices
[NUM_SYS_COLORS
];
363 for (i
= 0; i
< NUM_SYS_COLORS
; i
++)
367 DWORD count
= sizeof(colorStr
);
369 if (RegQueryValueExA (colorKey
, SysColorsNames
[i
], 0,
370 &type
, (LPBYTE
) colorStr
, &count
) == ERROR_SUCCESS
)
373 if (sscanf (colorStr
, "%d %d %d", &r
, &g
, &b
) == 3)
375 sysColsIndices
[sysColCount
] = i
;
376 sysCols
[sysColCount
] = RGB(r
, g
, b
);
381 RegCloseKey (colorKey
);
383 SetSysColors (sysColCount
, sysColsIndices
, sysCols
);
386 /* read backed-up other settings */
387 while (bsp
->spiGet
>= 0)
390 DWORD count
= sizeof(value
);
393 if (RegQueryValueExW (hKey
, bsp
->keyName
, 0,
394 &type
, (LPBYTE
)&value
, &count
) == ERROR_SUCCESS
)
396 SystemParametersInfoW (bsp
->spiSet
, 0, (LPVOID
)value
,
403 /* read backed-up non-client metrics */
405 NONCLIENTMETRICSW ncm
;
406 LOGFONTW iconTitleFont
;
407 DWORD count
= sizeof(ncm
);
410 if (RegQueryValueExW (hKey
, keyNonClientMetrics
, 0,
411 &type
, (LPBYTE
)&ncm
, &count
) == ERROR_SUCCESS
)
413 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS
,
414 count
, (LPVOID
)&ncm
, SPIF_UPDATEINIFILE
);
417 count
= sizeof(iconTitleFont
);
419 if (RegQueryValueExW (hKey
, keyIconTitleFont
, 0,
420 &type
, (LPBYTE
)&iconTitleFont
, &count
) == ERROR_SUCCESS
)
422 SystemParametersInfoW (SPI_SETICONTITLELOGFONT
,
423 count
, (LPVOID
)&iconTitleFont
, SPIF_UPDATEINIFILE
);
431 /* Make system settings persistent, so they're in effect even w/o uxtheme
433 * For efficiency reasons, only the last SystemParametersInfoW sets
434 * SPIF_SENDWININICHANGE */
435 static void UXTHEME_SaveSystemMetrics(void)
437 const struct BackupSysParam
* bsp
= backupSysParams
;
438 NONCLIENTMETRICSW ncm
;
439 LOGFONTW iconTitleFont
;
441 save_sys_colors (HKEY_CURRENT_USER
);
443 while (bsp
->spiGet
>= 0)
447 SystemParametersInfoW (bsp
->spiGet
, 0, &value
, 0);
448 SystemParametersInfoW (bsp
->spiSet
, 0, (LPVOID
)value
,
454 memset (&ncm
, 0, sizeof (ncm
));
455 ncm
.cbSize
= sizeof (ncm
);
456 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
,
457 sizeof (ncm
), (LPVOID
)&ncm
, 0);
458 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS
,
459 sizeof (ncm
), (LPVOID
)&ncm
, SPIF_UPDATEINIFILE
);
461 memset (&iconTitleFont
, 0, sizeof (iconTitleFont
));
462 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
,
463 sizeof (iconTitleFont
), (LPVOID
)&iconTitleFont
, 0);
464 SystemParametersInfoW (SPI_SETICONTITLELOGFONT
,
465 sizeof (iconTitleFont
), (LPVOID
)&iconTitleFont
,
466 SPIF_UPDATEINIFILE
| SPIF_SENDCHANGE
);
469 /***********************************************************************
470 * UXTHEME_SetActiveTheme
472 * Change the current active theme
474 static HRESULT
UXTHEME_SetActiveTheme(PTHEME_FILE tf
)
480 if(tf
&& !bThemeActive
) UXTHEME_BackupSystemMetrics();
481 hr
= MSSTYLES_SetActiveTheme(tf
, TRUE
);
486 lstrcpynW(szCurrentTheme
, tf
->szThemeFile
, sizeof(szCurrentTheme
)/sizeof(szCurrentTheme
[0]));
487 lstrcpynW(szCurrentColor
, tf
->pszSelectedColor
, sizeof(szCurrentColor
)/sizeof(szCurrentColor
[0]));
488 lstrcpynW(szCurrentSize
, tf
->pszSelectedSize
, sizeof(szCurrentSize
)/sizeof(szCurrentSize
[0]));
491 UXTHEME_RestoreSystemMetrics();
492 bThemeActive
= FALSE
;
493 szCurrentTheme
[0] = '\0';
494 szCurrentColor
[0] = '\0';
495 szCurrentSize
[0] = '\0';
498 TRACE("Writing theme config to registry\n");
499 if(!RegCreateKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
500 tmp
[0] = bThemeActive
?'1':'0';
502 RegSetValueExW(hKey
, szThemeActive
, 0, REG_SZ
, (const BYTE
*)tmp
, sizeof(WCHAR
)*2);
504 RegSetValueExW(hKey
, szColorName
, 0, REG_SZ
, (const BYTE
*)szCurrentColor
,
505 (lstrlenW(szCurrentColor
)+1)*sizeof(WCHAR
));
506 RegSetValueExW(hKey
, szSizeName
, 0, REG_SZ
, (const BYTE
*)szCurrentSize
,
507 (lstrlenW(szCurrentSize
)+1)*sizeof(WCHAR
));
508 RegSetValueExW(hKey
, szDllName
, 0, REG_SZ
, (const BYTE
*)szCurrentTheme
,
509 (lstrlenW(szCurrentTheme
)+1)*sizeof(WCHAR
));
512 RegDeleteValueW(hKey
, szColorName
);
513 RegDeleteValueW(hKey
, szSizeName
);
514 RegDeleteValueW(hKey
, szDllName
);
520 TRACE("Failed to open theme registry key\n");
522 UXTHEME_SaveSystemMetrics ();
527 /***********************************************************************
530 void UXTHEME_InitSystem(HINSTANCE hInst
)
532 static const WCHAR szWindowTheme
[] = {
533 'u','x','_','t','h','e','m','e','\0'
535 static const WCHAR szSubAppName
[] = {
536 'u','x','_','s','u','b','a','p','p','\0'
538 static const WCHAR szSubIdList
[] = {
539 'u','x','_','s','u','b','i','d','l','s','t','\0'
541 static const WCHAR szDialogThemeEnabled
[] = {
542 'u','x','_','d','i','a','l','o','g','t','h','e','m','e','\0'
547 atWindowTheme
= GlobalAddAtomW(szWindowTheme
);
548 atSubAppName
= GlobalAddAtomW(szSubAppName
);
549 atSubIdList
= GlobalAddAtomW(szSubIdList
);
550 atDialogThemeEnabled
= GlobalAddAtomW(szDialogThemeEnabled
);
555 /***********************************************************************
556 * IsAppThemed (UXTHEME.@)
558 BOOL WINAPI
IsAppThemed(void)
560 return IsThemeActive();
563 /***********************************************************************
564 * IsThemeActive (UXTHEME.@)
566 BOOL WINAPI
IsThemeActive(void)
572 /***********************************************************************
573 * EnableTheming (UXTHEME.@)
576 * This is a global and persistent change
578 HRESULT WINAPI
EnableTheming(BOOL fEnable
)
581 WCHAR szEnabled
[] = {'0','\0'};
583 TRACE("(%d)\n", fEnable
);
585 if(fEnable
!= bThemeActive
) {
587 UXTHEME_BackupSystemMetrics();
589 UXTHEME_RestoreSystemMetrics();
590 UXTHEME_SaveSystemMetrics ();
591 bThemeActive
= fEnable
;
592 if(bThemeActive
) szEnabled
[0] = '1';
593 if(!RegOpenKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
594 RegSetValueExW(hKey
, szThemeActive
, 0, REG_SZ
, (LPBYTE
)szEnabled
, sizeof(WCHAR
));
597 UXTHEME_broadcast_msg (NULL
, WM_THEMECHANGED
);
602 /***********************************************************************
603 * UXTHEME_SetWindowProperty
605 * I'm using atoms as there may be large numbers of duplicated strings
606 * and they do the work of keeping memory down as a cause of that quite nicely
608 static HRESULT
UXTHEME_SetWindowProperty(HWND hwnd
, ATOM aProp
, LPCWSTR pszValue
)
610 ATOM oldValue
= (ATOM
)(size_t)RemovePropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
));
612 DeleteAtom(oldValue
);
614 ATOM atValue
= AddAtomW(pszValue
);
616 || !SetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
), (LPWSTR
)MAKEINTATOM(atValue
))) {
617 HRESULT hr
= HRESULT_FROM_WIN32(GetLastError());
618 if(atValue
) DeleteAtom(atValue
);
625 static LPWSTR
UXTHEME_GetWindowProperty(HWND hwnd
, ATOM aProp
, LPWSTR pszBuffer
, int dwLen
)
627 ATOM atValue
= (ATOM
)(size_t)GetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
));
629 if(GetAtomNameW(atValue
, pszBuffer
, dwLen
))
631 TRACE("property defined, but unable to get value\n");
636 /***********************************************************************
637 * OpenThemeData (UXTHEME.@)
639 HTHEME WINAPI
OpenThemeData(HWND hwnd
, LPCWSTR pszClassList
)
641 WCHAR szAppBuff
[256];
642 WCHAR szClassBuff
[256];
644 LPCWSTR pszUseClassList
;
645 HTHEME hTheme
= NULL
;
646 TRACE("(%p,%s)\n", hwnd
, debugstr_w(pszClassList
));
650 pszAppName
= UXTHEME_GetWindowProperty(hwnd
, atSubAppName
, szAppBuff
, sizeof(szAppBuff
)/sizeof(szAppBuff
[0]));
651 /* If SetWindowTheme was used on the window, that overrides the class list passed to this function */
652 pszUseClassList
= UXTHEME_GetWindowProperty(hwnd
, atSubIdList
, szClassBuff
, sizeof(szClassBuff
)/sizeof(szClassBuff
[0]));
654 pszUseClassList
= pszClassList
;
657 hTheme
= MSSTYLES_OpenThemeClass(pszAppName
, pszUseClassList
);
660 SetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(atWindowTheme
), hTheme
);
661 TRACE(" = %p\n", hTheme
);
665 /***********************************************************************
666 * GetWindowTheme (UXTHEME.@)
668 * Retrieve the last theme opened for a window.
671 * hwnd [I] window to retrieve the theme for
674 * The most recent theme.
676 HTHEME WINAPI
GetWindowTheme(HWND hwnd
)
678 TRACE("(%p)\n", hwnd
);
679 return GetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(atWindowTheme
));
682 /***********************************************************************
683 * SetWindowTheme (UXTHEME.@)
685 * Persistent through the life of the window, even after themes change
687 HRESULT WINAPI
SetWindowTheme(HWND hwnd
, LPCWSTR pszSubAppName
,
688 LPCWSTR pszSubIdList
)
691 TRACE("(%p,%s,%s)\n", hwnd
, debugstr_w(pszSubAppName
),
692 debugstr_w(pszSubIdList
));
693 hr
= UXTHEME_SetWindowProperty(hwnd
, atSubAppName
, pszSubAppName
);
695 hr
= UXTHEME_SetWindowProperty(hwnd
, atSubIdList
, pszSubIdList
);
697 UXTHEME_broadcast_msg (hwnd
, WM_THEMECHANGED
);
701 /***********************************************************************
702 * GetCurrentThemeName (UXTHEME.@)
704 HRESULT WINAPI
GetCurrentThemeName(LPWSTR pszThemeFileName
, int dwMaxNameChars
,
705 LPWSTR pszColorBuff
, int cchMaxColorChars
,
706 LPWSTR pszSizeBuff
, int cchMaxSizeChars
)
709 return E_PROP_ID_UNSUPPORTED
;
710 if(pszThemeFileName
) lstrcpynW(pszThemeFileName
, szCurrentTheme
, dwMaxNameChars
);
711 if(pszColorBuff
) lstrcpynW(pszColorBuff
, szCurrentColor
, cchMaxColorChars
);
712 if(pszSizeBuff
) lstrcpynW(pszSizeBuff
, szCurrentSize
, cchMaxSizeChars
);
716 /***********************************************************************
717 * GetThemeAppProperties (UXTHEME.@)
719 DWORD WINAPI
GetThemeAppProperties(void)
721 return dwThemeAppProperties
;
724 /***********************************************************************
725 * SetThemeAppProperties (UXTHEME.@)
727 void WINAPI
SetThemeAppProperties(DWORD dwFlags
)
729 TRACE("(0x%08x)\n", dwFlags
);
730 dwThemeAppProperties
= dwFlags
;
733 /***********************************************************************
734 * CloseThemeData (UXTHEME.@)
736 HRESULT WINAPI
CloseThemeData(HTHEME hTheme
)
738 TRACE("(%p)\n", hTheme
);
741 return MSSTYLES_CloseThemeClass(hTheme
);
744 /***********************************************************************
745 * HitTestThemeBackground (UXTHEME.@)
747 HRESULT WINAPI
HitTestThemeBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
748 int iStateId
, DWORD dwOptions
,
749 const RECT
*pRect
, HRGN hrgn
,
750 POINT ptTest
, WORD
*pwHitTestCode
)
752 FIXME("%d %d 0x%08x: stub\n", iPartId
, iStateId
, dwOptions
);
755 return ERROR_CALL_NOT_IMPLEMENTED
;
758 /***********************************************************************
759 * IsThemePartDefined (UXTHEME.@)
761 BOOL WINAPI
IsThemePartDefined(HTHEME hTheme
, int iPartId
, int iStateId
)
763 TRACE("(%p,%d,%d)\n", hTheme
, iPartId
, iStateId
);
765 SetLastError(E_HANDLE
);
768 if(MSSTYLES_FindPartState(hTheme
, iPartId
, iStateId
, NULL
))
773 /***********************************************************************
774 * GetThemeDocumentationProperty (UXTHEME.@)
776 * Try and retrieve the documentation property from string resources
777 * if that fails, get it from the [documentation] section of themes.ini
779 HRESULT WINAPI
GetThemeDocumentationProperty(LPCWSTR pszThemeName
,
780 LPCWSTR pszPropertyName
,
784 const WORD wDocToRes
[] = {
785 TMT_DISPLAYNAME
,5000,
799 TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName
), debugstr_w(pszPropertyName
),
800 pszValueBuff
, cchMaxValChars
);
802 hr
= MSSTYLES_OpenThemeFile(pszThemeName
, NULL
, NULL
, &pt
);
803 if(FAILED(hr
)) return hr
;
805 /* Try to load from string resources */
806 hr
= E_PROP_ID_UNSUPPORTED
;
807 if(MSSTYLES_LookupProperty(pszPropertyName
, NULL
, &iDocId
)) {
808 for(i
=0; i
<sizeof(wDocToRes
)/sizeof(wDocToRes
[0]); i
+=2) {
809 if(wDocToRes
[i
] == iDocId
) {
810 if(LoadStringW(pt
->hTheme
, wDocToRes
[i
+1], pszValueBuff
, cchMaxValChars
)) {
817 /* If loading from string resource failed, try getting it from the theme.ini */
819 PUXINI_FILE uf
= MSSTYLES_GetThemeIni(pt
);
820 if(UXINI_FindSection(uf
, szIniDocumentation
)) {
823 if(UXINI_FindValue(uf
, pszPropertyName
, &lpValue
, &dwLen
)) {
824 lstrcpynW(pszValueBuff
, lpValue
, min(dwLen
+1,cchMaxValChars
));
831 MSSTYLES_CloseThemeFile(pt
);
835 /**********************************************************************
836 * Undocumented functions
839 /**********************************************************************
840 * QueryThemeServices (UXTHEME.1)
843 * some kind of status flag
845 DWORD WINAPI
QueryThemeServices(void)
848 return 3; /* This is what is returned under XP in most cases */
852 /**********************************************************************
853 * OpenThemeFile (UXTHEME.2)
855 * Opens a theme file, which can be used to change the current theme, etc
858 * pszThemeFileName Path to a msstyles theme file
859 * pszColorName Color defined in the theme, eg. NormalColor
860 * pszSizeName Size defined in the theme, eg. NormalSize
861 * hThemeFile Handle to theme file
865 * Failure: HRESULT error-code
867 HRESULT WINAPI
OpenThemeFile(LPCWSTR pszThemeFileName
, LPCWSTR pszColorName
,
868 LPCWSTR pszSizeName
, HTHEMEFILE
*hThemeFile
,
871 TRACE("(%s,%s,%s,%p,%d)\n", debugstr_w(pszThemeFileName
),
872 debugstr_w(pszColorName
), debugstr_w(pszSizeName
),
873 hThemeFile
, unknown
);
874 return MSSTYLES_OpenThemeFile(pszThemeFileName
, pszColorName
, pszSizeName
, (PTHEME_FILE
*)hThemeFile
);
877 /**********************************************************************
878 * CloseThemeFile (UXTHEME.3)
880 * Releases theme file handle returned by OpenThemeFile
883 * hThemeFile Handle to theme file
887 * Failure: HRESULT error-code
889 HRESULT WINAPI
CloseThemeFile(HTHEMEFILE hThemeFile
)
891 TRACE("(%p)\n", hThemeFile
);
892 MSSTYLES_CloseThemeFile(hThemeFile
);
896 /**********************************************************************
897 * ApplyTheme (UXTHEME.4)
899 * Set a theme file to be the currently active theme
902 * hThemeFile Handle to theme file
904 * hWnd Window requesting the theme change
908 * Failure: HRESULT error-code
911 * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
914 * the theme is applied with the screen redrawing really badly (flickers)
915 * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
916 * the theme is applied smoothly (screen does not flicker)
917 * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
918 * the function fails returning invalid parameter...very strange
920 HRESULT WINAPI
ApplyTheme(HTHEMEFILE hThemeFile
, char *unknown
, HWND hWnd
)
923 TRACE("(%p,%s,%p)\n", hThemeFile
, unknown
, hWnd
);
924 hr
= UXTHEME_SetActiveTheme(hThemeFile
);
925 UXTHEME_broadcast_msg (NULL
, WM_THEMECHANGED
);
929 /**********************************************************************
930 * GetThemeDefaults (UXTHEME.7)
932 * Get the default color & size for a theme
935 * pszThemeFileName Path to a msstyles theme file
936 * pszColorName Buffer to receive the default color name
937 * dwColorNameLen Length, in characters, of color name buffer
938 * pszSizeName Buffer to receive the default size name
939 * dwSizeNameLen Length, in characters, of size name buffer
943 * Failure: HRESULT error-code
945 HRESULT WINAPI
GetThemeDefaults(LPCWSTR pszThemeFileName
, LPWSTR pszColorName
,
946 DWORD dwColorNameLen
, LPWSTR pszSizeName
,
951 TRACE("(%s,%p,%d,%p,%d)\n", debugstr_w(pszThemeFileName
),
952 pszColorName
, dwColorNameLen
,
953 pszSizeName
, dwSizeNameLen
);
955 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, NULL
, &pt
);
956 if(FAILED(hr
)) return hr
;
958 lstrcpynW(pszColorName
, pt
->pszSelectedColor
, dwColorNameLen
);
959 lstrcpynW(pszSizeName
, pt
->pszSelectedSize
, dwSizeNameLen
);
961 MSSTYLES_CloseThemeFile(pt
);
965 /**********************************************************************
966 * EnumThemes (UXTHEME.8)
968 * Enumerate available themes, calls specified EnumThemeProc for each
969 * theme found. Passes lpData through to callback function.
972 * pszThemePath Path containing themes
973 * callback Called for each theme found in path
974 * lpData Passed through to callback
978 * Failure: HRESULT error-code
980 HRESULT WINAPI
EnumThemes(LPCWSTR pszThemePath
, EnumThemeProc callback
,
983 WCHAR szDir
[MAX_PATH
];
984 WCHAR szPath
[MAX_PATH
];
985 static const WCHAR szStar
[] = {'*','.','*','\0'};
986 static const WCHAR szFormat
[] = {'%','s','%','s','\\','%','s','.','m','s','s','t','y','l','e','s','\0'};
987 static const WCHAR szDisplayName
[] = {'d','i','s','p','l','a','y','n','a','m','e','\0'};
988 static const WCHAR szTooltip
[] = {'t','o','o','l','t','i','p','\0'};
992 WIN32_FIND_DATAW wfd
;
996 TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath
), callback
, lpData
);
998 if(!pszThemePath
|| !callback
)
1001 lstrcpyW(szDir
, pszThemePath
);
1002 pathLen
= lstrlenW (szDir
);
1003 if ((pathLen
> 0) && (pathLen
< MAX_PATH
-1) && (szDir
[pathLen
- 1] != '\\'))
1005 szDir
[pathLen
] = '\\';
1006 szDir
[pathLen
+1] = 0;
1009 lstrcpyW(szPath
, szDir
);
1010 lstrcatW(szPath
, szStar
);
1011 TRACE("searching %s\n", debugstr_w(szPath
));
1013 hFind
= FindFirstFileW(szPath
, &wfd
);
1014 if(hFind
!= INVALID_HANDLE_VALUE
) {
1016 if(wfd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
1017 && !(wfd
.cFileName
[0] == '.' && ((wfd
.cFileName
[1] == '.' && wfd
.cFileName
[2] == 0) || wfd
.cFileName
[1] == 0))) {
1018 wsprintfW(szPath
, szFormat
, szDir
, wfd
.cFileName
, wfd
.cFileName
);
1020 hr
= GetThemeDocumentationProperty(szPath
, szDisplayName
, szName
, sizeof(szName
)/sizeof(szName
[0]));
1022 hr
= GetThemeDocumentationProperty(szPath
, szTooltip
, szTip
, sizeof(szTip
)/sizeof(szTip
[0]));
1024 TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath
), debugstr_w(szName
), debugstr_w(szTip
), lpData
);
1025 if(!callback(NULL
, szPath
, szName
, szTip
, NULL
, lpData
)) {
1026 TRACE("callback ended enum\n");
1031 } while(FindNextFileW(hFind
, &wfd
));
1038 /**********************************************************************
1039 * EnumThemeColors (UXTHEME.9)
1041 * Enumerate theme colors available with a particular size
1044 * pszThemeFileName Path to a msstyles theme file
1045 * pszSizeName Theme size to enumerate available colors
1046 * If NULL the default theme size is used
1047 * dwColorNum Color index to retrieve, increment from 0
1048 * pszColorNames Output color names
1052 * E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
1053 * or when pszSizeName does not refer to a valid size
1056 * XP fails with E_POINTER when pszColorNames points to a buffer smaller than
1057 * sizeof(THEMENAMES).
1059 * Not very efficient that I'm opening & validating the theme every call, but
1060 * this is undocumented and almost never called..
1061 * (and this is how windows works too)
1063 HRESULT WINAPI
EnumThemeColors(LPWSTR pszThemeFileName
, LPWSTR pszSizeName
,
1064 DWORD dwColorNum
, PTHEMENAMES pszColorNames
)
1069 UINT resourceId
= dwColorNum
+ 1000;
1070 TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName
),
1071 debugstr_w(pszSizeName
), dwColorNum
);
1073 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, pszSizeName
, &pt
);
1074 if(FAILED(hr
)) return hr
;
1076 tmp
= pt
->pszAvailColors
;
1077 while(dwColorNum
&& *tmp
) {
1079 tmp
+= lstrlenW(tmp
)+1;
1081 if(!dwColorNum
&& *tmp
) {
1082 TRACE("%s\n", debugstr_w(tmp
));
1083 lstrcpyW(pszColorNames
->szName
, tmp
);
1084 LoadStringW (pt
->hTheme
, resourceId
,
1085 pszColorNames
->szDisplayName
,
1086 sizeof (pszColorNames
->szDisplayName
) / sizeof (WCHAR
));
1087 LoadStringW (pt
->hTheme
, resourceId
+1000,
1088 pszColorNames
->szTooltip
,
1089 sizeof (pszColorNames
->szTooltip
) / sizeof (WCHAR
));
1092 hr
= E_PROP_ID_UNSUPPORTED
;
1094 MSSTYLES_CloseThemeFile(pt
);
1098 /**********************************************************************
1099 * EnumThemeSizes (UXTHEME.10)
1101 * Enumerate theme colors available with a particular size
1104 * pszThemeFileName Path to a msstyles theme file
1105 * pszColorName Theme color to enumerate available sizes
1106 * If NULL the default theme color is used
1107 * dwSizeNum Size index to retrieve, increment from 0
1108 * pszSizeNames Output size names
1112 * E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
1113 * or when pszColorName does not refer to a valid color
1116 * XP fails with E_POINTER when pszSizeNames points to a buffer smaller than
1117 * sizeof(THEMENAMES).
1119 * Not very efficient that I'm opening & validating the theme every call, but
1120 * this is undocumented and almost never called..
1121 * (and this is how windows works too)
1123 HRESULT WINAPI
EnumThemeSizes(LPWSTR pszThemeFileName
, LPWSTR pszColorName
,
1124 DWORD dwSizeNum
, PTHEMENAMES pszSizeNames
)
1129 UINT resourceId
= dwSizeNum
+ 3000;
1130 TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName
),
1131 debugstr_w(pszColorName
), dwSizeNum
);
1133 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, pszColorName
, NULL
, &pt
);
1134 if(FAILED(hr
)) return hr
;
1136 tmp
= pt
->pszAvailSizes
;
1137 while(dwSizeNum
&& *tmp
) {
1139 tmp
+= lstrlenW(tmp
)+1;
1141 if(!dwSizeNum
&& *tmp
) {
1142 TRACE("%s\n", debugstr_w(tmp
));
1143 lstrcpyW(pszSizeNames
->szName
, tmp
);
1144 LoadStringW (pt
->hTheme
, resourceId
,
1145 pszSizeNames
->szDisplayName
,
1146 sizeof (pszSizeNames
->szDisplayName
) / sizeof (WCHAR
));
1147 LoadStringW (pt
->hTheme
, resourceId
+1000,
1148 pszSizeNames
->szTooltip
,
1149 sizeof (pszSizeNames
->szTooltip
) / sizeof (WCHAR
));
1152 hr
= E_PROP_ID_UNSUPPORTED
;
1154 MSSTYLES_CloseThemeFile(pt
);
1158 /**********************************************************************
1159 * ParseThemeIniFile (UXTHEME.11)
1161 * Enumerate data in a theme INI file.
1164 * pszIniFileName Path to a theme ini file
1165 * pszUnknown Cannot be NULL, L"" is valid
1166 * callback Called for each found entry
1167 * lpData Passed through to callback
1171 * 0x800706488 (Unknown property) when enumeration is canceled from callback
1174 * When pszUnknown is NULL the callback is never called, the value does not seem to surve
1177 HRESULT WINAPI
ParseThemeIniFile(LPCWSTR pszIniFileName
, LPWSTR pszUnknown
,
1178 ParseThemeIniFileProc callback
, LPVOID lpData
)
1180 FIXME("%s %s: stub\n", debugstr_w(pszIniFileName
), debugstr_w(pszUnknown
));
1181 return ERROR_CALL_NOT_IMPLEMENTED
;
1184 /**********************************************************************
1185 * CheckThemeSignature (UXTHEME.29)
1187 * Validates the signature of a theme file
1190 * pszIniFileName Path to a theme file
1194 * Failure: HRESULT error-code
1196 HRESULT WINAPI
CheckThemeSignature(LPCWSTR pszThemeFileName
)
1200 TRACE("(%s)\n", debugstr_w(pszThemeFileName
));
1201 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, NULL
, &pt
);
1204 MSSTYLES_CloseThemeFile(pt
);