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
27 /***********************************************************************
28 * Defines and global variables
31 static const WCHAR szThemeManager
[] = {
32 'S','o','f','t','w','a','r','e','\\',
33 'M','i','c','r','o','s','o','f','t','\\',
34 'W','i','n','d','o','w','s','\\',
35 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
36 'T','h','e','m','e','M','a','n','a','g','e','r','\0'
38 static const WCHAR szThemeActive
[] = {'T','h','e','m','e','A','c','t','i','v','e','\0'};
39 static const WCHAR szSizeName
[] = {'S','i','z','e','N','a','m','e','\0'};
40 static const WCHAR szColorName
[] = {'C','o','l','o','r','N','a','m','e','\0'};
41 static const WCHAR szDllName
[] = {'D','l','l','N','a','m','e','\0'};
43 static const WCHAR szIniDocumentation
[] = {'d','o','c','u','m','e','n','t','a','t','i','o','n','\0'};
46 ATOM atDialogThemeEnabled
;
48 static DWORD dwThemeAppProperties
= STAP_ALLOW_NONCLIENT
| STAP_ALLOW_CONTROLS
;
50 static ATOM atSubAppName
;
51 static ATOM atSubIdList
;
54 PTHEME_FILE ActiveThemeFile
;
56 /***********************************************************************/
58 static BOOL CALLBACK
UXTHEME_broadcast_msg_enumchild (HWND hWnd
, LPARAM msg
)
60 PostMessageW(hWnd
, msg
, 0, 0);
64 /* Broadcast a message to *all* windows, including children */
65 BOOL CALLBACK
UXTHEME_broadcast_msg (HWND hWnd
, LPARAM msg
)
69 EnumWindows (UXTHEME_broadcast_msg
, msg
);
73 PostMessageW(hWnd
, msg
, 0, 0);
74 EnumChildWindows (hWnd
, UXTHEME_broadcast_msg_enumchild
, msg
);
79 /* At the end of the day this is a subset of what SHRegGetPath() does - copied
80 * here to avoid linking against shlwapi. */
81 static DWORD
query_reg_path (HKEY hKey
, LPCWSTR lpszValue
,
84 DWORD dwRet
, dwType
, dwUnExpDataLen
= MAX_PATH
* sizeof(WCHAR
), dwExpDataLen
;
86 TRACE("(hkey=%p,%s,%p)\n", hKey
, debugstr_w(lpszValue
),
89 dwRet
= RegQueryValueExW(hKey
, lpszValue
, 0, &dwType
, pvData
, &dwUnExpDataLen
);
90 if (dwRet
!=ERROR_SUCCESS
&& dwRet
!=ERROR_MORE_DATA
)
93 if (dwType
== REG_EXPAND_SZ
)
97 /* Expand type REG_EXPAND_SZ into REG_SZ */
100 /* If the caller didn't supply a buffer or the buffer is too small we have
101 * to allocate our own
103 if (dwRet
== ERROR_MORE_DATA
)
106 nBytesToAlloc
= dwUnExpDataLen
;
108 szData
= LocalAlloc(LMEM_ZEROINIT
, nBytesToAlloc
);
109 RegQueryValueExW (hKey
, lpszValue
, 0, NULL
, (LPBYTE
)szData
, &nBytesToAlloc
);
110 dwExpDataLen
= ExpandEnvironmentStringsW(szData
, &cNull
, 1);
111 dwUnExpDataLen
= max(nBytesToAlloc
, dwExpDataLen
);
116 nBytesToAlloc
= (lstrlenW(pvData
) + 1) * sizeof(WCHAR
);
117 szData
= LocalAlloc(LMEM_ZEROINIT
, nBytesToAlloc
);
118 lstrcpyW(szData
, pvData
);
119 dwExpDataLen
= ExpandEnvironmentStringsW(szData
, pvData
, MAX_PATH
);
120 if (dwExpDataLen
> MAX_PATH
) dwRet
= ERROR_MORE_DATA
;
121 dwUnExpDataLen
= max(nBytesToAlloc
, dwExpDataLen
);
129 static HRESULT
UXTHEME_SetActiveTheme(PTHEME_FILE tf
)
132 MSSTYLES_CloseThemeFile(ActiveThemeFile
);
133 ActiveThemeFile
= tf
;
136 MSSTYLES_ReferenceTheme(ActiveThemeFile
);
137 MSSTYLES_ParseThemeIni(ActiveThemeFile
);
142 static BOOL
bIsThemeActive(LPCWSTR pszTheme
, LPCWSTR pszColor
, LPCWSTR pszSize
)
144 if (ActiveThemeFile
== NULL
)
147 if (wcscmp(pszTheme
, ActiveThemeFile
->szThemeFile
) != 0)
152 if (ActiveThemeFile
->pszAvailColors
!= ActiveThemeFile
->pszSelectedColor
)
157 if (wcscmp(pszColor
, ActiveThemeFile
->pszSelectedColor
) != 0)
163 if (ActiveThemeFile
->pszAvailSizes
!= ActiveThemeFile
->pszSelectedSize
)
168 if (wcscmp(pszSize
, ActiveThemeFile
->pszSelectedSize
) != 0)
175 /***********************************************************************
178 * Set the current active theme from the registry
180 void UXTHEME_LoadTheme(BOOL bLoad
)
187 WCHAR szCurrentTheme
[MAX_PATH
];
188 WCHAR szCurrentColor
[64];
189 WCHAR szCurrentSize
[64];
190 BOOL bThemeActive
= FALSE
;
194 /* Get current theme configuration */
195 if(!RegOpenKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
196 TRACE("Loading theme config\n");
197 buffsize
= sizeof(tmp
);
198 if(!RegQueryValueExW(hKey
, szThemeActive
, NULL
, NULL
, (LPBYTE
)tmp
, &buffsize
)) {
199 bThemeActive
= (tmp
[0] != '0');
202 bThemeActive
= FALSE
;
203 TRACE("Failed to get ThemeActive: %d\n", GetLastError());
205 buffsize
= sizeof(szCurrentColor
);
206 if(RegQueryValueExW(hKey
, szColorName
, NULL
, NULL
, (LPBYTE
)szCurrentColor
, &buffsize
))
207 szCurrentColor
[0] = '\0';
208 buffsize
= sizeof(szCurrentSize
);
209 if(RegQueryValueExW(hKey
, szSizeName
, NULL
, NULL
, (LPBYTE
)szCurrentSize
, &buffsize
))
210 szCurrentSize
[0] = '\0';
211 if (query_reg_path (hKey
, szDllName
, szCurrentTheme
))
212 szCurrentTheme
[0] = '\0';
216 TRACE("Failed to open theme registry key\n");
220 bThemeActive
= FALSE
;
225 if( bIsThemeActive(szCurrentTheme
, szCurrentColor
, szCurrentSize
) )
227 TRACE("Tried to load active theme again\n");
231 /* Make sure the theme requested is actually valid */
232 hr
= MSSTYLES_OpenThemeFile(szCurrentTheme
,
233 szCurrentColor
[0]?szCurrentColor
:NULL
,
234 szCurrentSize
[0]?szCurrentSize
:NULL
,
237 bThemeActive
= FALSE
;
240 TRACE("Theme active: %s %s %s\n", debugstr_w(szCurrentTheme
),
241 debugstr_w(szCurrentColor
), debugstr_w(szCurrentSize
));
243 UXTHEME_SetActiveTheme(pt
);
244 MSSTYLES_CloseThemeFile(pt
);
248 UXTHEME_SetActiveTheme(NULL
);
249 TRACE("Theming not active\n");
253 /***********************************************************************/
255 static const char * const SysColorsNames
[] =
257 "Scrollbar", /* COLOR_SCROLLBAR */
258 "Background", /* COLOR_BACKGROUND */
259 "ActiveTitle", /* COLOR_ACTIVECAPTION */
260 "InactiveTitle", /* COLOR_INACTIVECAPTION */
261 "Menu", /* COLOR_MENU */
262 "Window", /* COLOR_WINDOW */
263 "WindowFrame", /* COLOR_WINDOWFRAME */
264 "MenuText", /* COLOR_MENUTEXT */
265 "WindowText", /* COLOR_WINDOWTEXT */
266 "TitleText", /* COLOR_CAPTIONTEXT */
267 "ActiveBorder", /* COLOR_ACTIVEBORDER */
268 "InactiveBorder", /* COLOR_INACTIVEBORDER */
269 "AppWorkSpace", /* COLOR_APPWORKSPACE */
270 "Hilight", /* COLOR_HIGHLIGHT */
271 "HilightText", /* COLOR_HIGHLIGHTTEXT */
272 "ButtonFace", /* COLOR_BTNFACE */
273 "ButtonShadow", /* COLOR_BTNSHADOW */
274 "GrayText", /* COLOR_GRAYTEXT */
275 "ButtonText", /* COLOR_BTNTEXT */
276 "InactiveTitleText", /* COLOR_INACTIVECAPTIONTEXT */
277 "ButtonHilight", /* COLOR_BTNHIGHLIGHT */
278 "ButtonDkShadow", /* COLOR_3DDKSHADOW */
279 "ButtonLight", /* COLOR_3DLIGHT */
280 "InfoText", /* COLOR_INFOTEXT */
281 "InfoWindow", /* COLOR_INFOBK */
282 "ButtonAlternateFace", /* COLOR_ALTERNATEBTNFACE */
283 "HotTrackingColor", /* COLOR_HOTLIGHT */
284 "GradientActiveTitle", /* COLOR_GRADIENTACTIVECAPTION */
285 "GradientInactiveTitle", /* COLOR_GRADIENTINACTIVECAPTION */
286 "MenuHilight", /* COLOR_MENUHILIGHT */
287 "MenuBar", /* COLOR_MENUBAR */
289 static const WCHAR strColorKey
[] =
290 { 'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
291 'C','o','l','o','r','s',0 };
292 static const WCHAR keyFlatMenus
[] = { 'F','l','a','t','M','e','n','u', 0};
293 static const WCHAR keyGradientCaption
[] = { 'G','r','a','d','i','e','n','t',
294 'C','a','p','t','i','o','n', 0 };
295 static const WCHAR keyNonClientMetrics
[] = { 'N','o','n','C','l','i','e','n','t',
296 'M','e','t','r','i','c','s',0 };
297 static const WCHAR keyIconTitleFont
[] = { 'I','c','o','n','T','i','t','l','e',
300 static const struct BackupSysParam
303 const WCHAR
* keyName
;
304 } backupSysParams
[] =
306 {SPI_GETFLATMENU
, SPI_SETFLATMENU
, keyFlatMenus
},
307 {SPI_GETGRADIENTCAPTIONS
, SPI_SETGRADIENTCAPTIONS
, keyGradientCaption
},
311 #define NUM_SYS_COLORS (COLOR_MENUBAR+1)
313 static void save_sys_colors (HKEY baseKey
)
319 if (RegCreateKeyExW( baseKey
, strColorKey
,
320 0, 0, 0, KEY_ALL_ACCESS
,
321 0, &hKey
, 0 ) == ERROR_SUCCESS
)
323 for (i
= 0; i
< NUM_SYS_COLORS
; i
++)
325 COLORREF col
= GetSysColor (i
);
327 sprintf (colorStr
, "%d %d %d",
328 GetRValue (col
), GetGValue (col
), GetBValue (col
));
330 RegSetValueExA (hKey
, SysColorsNames
[i
], 0, REG_SZ
,
331 (BYTE
*)colorStr
, strlen (colorStr
)+1);
337 /* Before activating a theme, query current system colors, certain settings
338 * and backup them in the registry, so they can be restored when the theme
340 static void UXTHEME_BackupSystemMetrics(void)
343 const struct BackupSysParam
* bsp
= backupSysParams
;
345 if (RegCreateKeyExW( HKEY_CURRENT_USER
, szThemeManager
,
346 0, 0, 0, KEY_ALL_ACCESS
,
347 0, &hKey
, 0) == ERROR_SUCCESS
)
349 NONCLIENTMETRICSW ncm
;
350 LOGFONTW iconTitleFont
;
353 save_sys_colors (hKey
);
355 /* back up "other" settings */
356 while (bsp
->spiGet
>= 0)
360 SystemParametersInfoW (bsp
->spiGet
, 0, &value
, 0);
361 RegSetValueExW (hKey
, bsp
->keyName
, 0, REG_DWORD
,
362 (LPBYTE
)&value
, sizeof (value
));
367 /* back up non-client metrics */
368 memset (&ncm
, 0, sizeof (ncm
));
369 ncm
.cbSize
= sizeof (ncm
);
370 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof (ncm
), &ncm
, 0);
371 RegSetValueExW (hKey
, keyNonClientMetrics
, 0, REG_BINARY
, (LPBYTE
)&ncm
,
373 memset (&iconTitleFont
, 0, sizeof (iconTitleFont
));
374 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, sizeof (iconTitleFont
),
376 RegSetValueExW (hKey
, keyIconTitleFont
, 0, REG_BINARY
,
377 (LPBYTE
)&iconTitleFont
, sizeof (iconTitleFont
));
383 /* Read back old settings after a theme was deactivated */
384 static void UXTHEME_RestoreSystemMetrics(void)
387 const struct BackupSysParam
* bsp
= backupSysParams
;
389 if (RegOpenKeyExW (HKEY_CURRENT_USER
, szThemeManager
,
390 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
)
394 /* read backed-up colors */
395 if (RegOpenKeyExW (hKey
, strColorKey
,
396 0, KEY_QUERY_VALUE
, &colorKey
) == ERROR_SUCCESS
)
399 COLORREF sysCols
[NUM_SYS_COLORS
];
400 int sysColsIndices
[NUM_SYS_COLORS
];
403 for (i
= 0; i
< NUM_SYS_COLORS
; i
++)
407 DWORD count
= sizeof(colorStr
);
409 if (RegQueryValueExA (colorKey
, SysColorsNames
[i
], 0,
410 &type
, (LPBYTE
) colorStr
, &count
) == ERROR_SUCCESS
)
413 if (sscanf (colorStr
, "%d %d %d", &r
, &g
, &b
) == 3)
415 sysColsIndices
[sysColCount
] = i
;
416 sysCols
[sysColCount
] = RGB(r
, g
, b
);
421 RegCloseKey (colorKey
);
423 SetSysColors (sysColCount
, sysColsIndices
, sysCols
);
426 /* read backed-up other settings */
427 while (bsp
->spiGet
>= 0)
430 DWORD count
= sizeof(value
);
433 if (RegQueryValueExW (hKey
, bsp
->keyName
, 0,
434 &type
, (LPBYTE
)&value
, &count
) == ERROR_SUCCESS
)
436 SystemParametersInfoW (bsp
->spiSet
, 0, UlongToPtr(value
), SPIF_UPDATEINIFILE
);
442 /* read backed-up non-client metrics */
444 NONCLIENTMETRICSW ncm
;
445 LOGFONTW iconTitleFont
;
446 DWORD count
= sizeof(ncm
);
449 if (RegQueryValueExW (hKey
, keyNonClientMetrics
, 0,
450 &type
, (LPBYTE
)&ncm
, &count
) == ERROR_SUCCESS
)
452 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS
,
453 count
, &ncm
, SPIF_UPDATEINIFILE
);
456 count
= sizeof(iconTitleFont
);
458 if (RegQueryValueExW (hKey
, keyIconTitleFont
, 0,
459 &type
, (LPBYTE
)&iconTitleFont
, &count
) == ERROR_SUCCESS
)
461 SystemParametersInfoW (SPI_SETICONTITLELOGFONT
,
462 count
, &iconTitleFont
, SPIF_UPDATEINIFILE
);
470 /* Make system settings persistent, so they're in effect even w/o uxtheme
472 * For efficiency reasons, only the last SystemParametersInfoW sets
473 * SPIF_SENDWININICHANGE */
474 static void UXTHEME_SaveSystemMetrics(void)
476 const struct BackupSysParam
* bsp
= backupSysParams
;
477 NONCLIENTMETRICSW ncm
;
478 LOGFONTW iconTitleFont
;
480 save_sys_colors (HKEY_CURRENT_USER
);
482 while (bsp
->spiGet
>= 0)
486 SystemParametersInfoW (bsp
->spiGet
, 0, &value
, 0);
487 SystemParametersInfoW (bsp
->spiSet
, 0, UlongToPtr(value
), SPIF_UPDATEINIFILE
);
491 memset (&ncm
, 0, sizeof (ncm
));
492 ncm
.cbSize
= sizeof (ncm
);
493 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof (ncm
), &ncm
, 0);
494 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS
, sizeof (ncm
), &ncm
,
497 memset (&iconTitleFont
, 0, sizeof (iconTitleFont
));
498 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, sizeof (iconTitleFont
),
500 SystemParametersInfoW (SPI_SETICONTITLELOGFONT
, sizeof (iconTitleFont
),
501 &iconTitleFont
, SPIF_UPDATEINIFILE
| SPIF_SENDCHANGE
);
504 /***********************************************************************
507 * Change the current active theme
509 static HRESULT
UXTHEME_ApplyTheme(PTHEME_FILE tf
)
515 TRACE("UXTHEME_ApplyTheme\n");
517 if (tf
&& !ActiveThemeFile
)
519 UXTHEME_BackupSystemMetrics();
522 hr
= UXTHEME_SetActiveTheme(tf
);
528 UXTHEME_RestoreSystemMetrics();
531 TRACE("Writing theme config to registry\n");
532 if(!RegCreateKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
533 tmp
[0] = ActiveThemeFile
?'1':'0';
535 RegSetValueExW(hKey
, szThemeActive
, 0, REG_SZ
, (const BYTE
*)tmp
, sizeof(WCHAR
)*2);
536 if (ActiveThemeFile
) {
537 RegSetValueExW(hKey
, szColorName
, 0, REG_SZ
, (const BYTE
*)tf
->pszSelectedColor
,
538 (lstrlenW(tf
->pszSelectedColor
)+1)*sizeof(WCHAR
));
539 RegSetValueExW(hKey
, szSizeName
, 0, REG_SZ
, (const BYTE
*)tf
->pszSelectedSize
,
540 (lstrlenW(tf
->pszSelectedSize
)+1)*sizeof(WCHAR
));
541 RegSetValueExW(hKey
, szDllName
, 0, REG_SZ
, (const BYTE
*)tf
->szThemeFile
,
542 (lstrlenW(tf
->szThemeFile
)+1)*sizeof(WCHAR
));
545 RegDeleteValueW(hKey
, szColorName
);
546 RegDeleteValueW(hKey
, szSizeName
);
547 RegDeleteValueW(hKey
, szDllName
);
553 TRACE("Failed to open theme registry key\n");
555 UXTHEME_SaveSystemMetrics ();
560 /***********************************************************************
563 void UXTHEME_InitSystem(HINSTANCE hInst
)
565 static const WCHAR szWindowTheme
[] = {
566 'u','x','_','t','h','e','m','e','\0'
568 static const WCHAR szSubAppName
[] = {
569 'u','x','_','s','u','b','a','p','p','\0'
571 static const WCHAR szSubIdList
[] = {
572 'u','x','_','s','u','b','i','d','l','s','t','\0'
574 static const WCHAR szDialogThemeEnabled
[] = {
575 'u','x','_','d','i','a','l','o','g','t','h','e','m','e','\0'
580 atWindowTheme
= GlobalAddAtomW(szWindowTheme
);
581 atSubAppName
= GlobalAddAtomW(szSubAppName
);
582 atSubIdList
= GlobalAddAtomW(szSubIdList
);
583 atDialogThemeEnabled
= GlobalAddAtomW(szDialogThemeEnabled
);
584 atWndContext
= GlobalAddAtomW(L
"ux_WndContext");
587 /***********************************************************************
588 * IsAppThemed (UXTHEME.@)
590 BOOL WINAPI
IsAppThemed(void)
593 SetLastError(ERROR_SUCCESS
);
594 return (ActiveThemeFile
!= NULL
);
597 /***********************************************************************
598 * IsThemeActive (UXTHEME.@)
600 BOOL WINAPI
IsThemeActive(void)
608 TRACE("IsThemeActive\n");
609 SetLastError(ERROR_SUCCESS
);
614 if (gbThemeHooksActive
)
618 Result
= RegOpenKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
);
619 if (Result
== ERROR_SUCCESS
)
621 buffsize
= sizeof(tmp
);
622 if (!RegQueryValueExW(hKey
, szThemeActive
, NULL
, NULL
, (LPBYTE
)tmp
, &buffsize
))
623 bActive
= (tmp
[0] != '0');
630 /***********************************************************************
631 * EnableTheming (UXTHEME.@)
634 * This is a global and persistent change
636 HRESULT WINAPI
EnableTheming(BOOL fEnable
)
639 WCHAR szEnabled
[] = {'0','\0'};
641 TRACE("(%d)\n", fEnable
);
643 if (fEnable
!= (ActiveThemeFile
!= NULL
)) {
645 UXTHEME_BackupSystemMetrics();
647 UXTHEME_RestoreSystemMetrics();
648 UXTHEME_SaveSystemMetrics ();
650 if (fEnable
) szEnabled
[0] = '1';
651 if(!RegOpenKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
652 RegSetValueExW(hKey
, szThemeActive
, 0, REG_SZ
, (LPBYTE
)szEnabled
, sizeof(WCHAR
));
655 UXTHEME_broadcast_msg (NULL
, WM_THEMECHANGED
);
660 /***********************************************************************
661 * UXTHEME_SetWindowProperty
663 * I'm using atoms as there may be large numbers of duplicated strings
664 * and they do the work of keeping memory down as a cause of that quite nicely
666 static HRESULT
UXTHEME_SetWindowProperty(HWND hwnd
, ATOM aProp
, LPCWSTR pszValue
)
668 ATOM oldValue
= (ATOM
)(size_t)RemovePropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
));
670 DeleteAtom(oldValue
);
672 ATOM atValue
= AddAtomW(pszValue
);
674 || !SetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
), (LPWSTR
)MAKEINTATOM(atValue
))) {
675 HRESULT hr
= HRESULT_FROM_WIN32(GetLastError());
676 if(atValue
) DeleteAtom(atValue
);
683 static LPWSTR
UXTHEME_GetWindowProperty(HWND hwnd
, ATOM aProp
, LPWSTR pszBuffer
, int dwLen
)
685 ATOM atValue
= (ATOM
)(size_t)GetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
));
687 if(GetAtomNameW(atValue
, pszBuffer
, dwLen
))
689 TRACE("property defined, but unable to get value\n");
695 OpenThemeDataInternal(PTHEME_FILE ThemeFile
, HWND hwnd
, LPCWSTR pszClassList
, DWORD flags
)
697 WCHAR szAppBuff
[256];
698 WCHAR szClassBuff
[256];
700 LPCWSTR pszUseClassList
;
701 HTHEME hTheme
= NULL
;
702 TRACE("(%p,%s, %x)\n", hwnd
, debugstr_w(pszClassList
), flags
);
706 SetLastError(E_POINTER
);
711 FIXME("unhandled flags: %x\n", flags
);
715 pszAppName
= UXTHEME_GetWindowProperty(hwnd
, atSubAppName
, szAppBuff
, sizeof(szAppBuff
)/sizeof(szAppBuff
[0]));
716 /* If SetWindowTheme was used on the window, that overrides the class list passed to this function */
717 pszUseClassList
= UXTHEME_GetWindowProperty(hwnd
, atSubIdList
, szClassBuff
, sizeof(szClassBuff
)/sizeof(szClassBuff
[0]));
719 pszUseClassList
= pszClassList
;
723 if (!ThemeFile
->classes
)
724 MSSTYLES_ParseThemeIni(ThemeFile
);
725 hTheme
= MSSTYLES_OpenThemeClass(ThemeFile
, pszAppName
, pszUseClassList
);
731 SetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(atWindowTheme
), hTheme
);
735 SetLastError(E_PROP_ID_UNSUPPORTED
);
738 SetLastError(hTheme
? ERROR_SUCCESS
: E_PROP_ID_UNSUPPORTED
);
740 TRACE(" = %p\n", hTheme
);
744 /***********************************************************************
745 * OpenThemeDataEx (UXTHEME.61)
747 HTHEME WINAPI
OpenThemeDataEx(HWND hwnd
, LPCWSTR pszClassList
, DWORD flags
)
749 return OpenThemeDataInternal(ActiveThemeFile
, hwnd
, pszClassList
, flags
);
752 /***********************************************************************
753 * OpenThemeDataFromFile (UXTHEME.16)
755 HTHEME WINAPI
OpenThemeDataFromFile(HTHEMEFILE hThemeFile
, HWND hwnd
, LPCWSTR pszClassList
, DWORD flags
)
757 return OpenThemeDataInternal((PTHEME_FILE
)hThemeFile
, hwnd
, pszClassList
, flags
);
760 /***********************************************************************
761 * OpenThemeData (UXTHEME.@)
763 HTHEME WINAPI
OpenThemeData(HWND hwnd
, LPCWSTR classlist
)
765 return OpenThemeDataInternal(ActiveThemeFile
, hwnd
, classlist
, 0);
768 /***********************************************************************
769 * GetWindowTheme (UXTHEME.@)
771 * Retrieve the last theme opened for a window.
774 * hwnd [I] window to retrieve the theme for
777 * The most recent theme.
779 HTHEME WINAPI
GetWindowTheme(HWND hwnd
)
781 TRACE("(%p)\n", hwnd
);
785 SetLastError(E_HANDLE
);
789 return GetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(atWindowTheme
));
792 /***********************************************************************
793 * SetWindowTheme (UXTHEME.@)
795 * Persistent through the life of the window, even after themes change
797 HRESULT WINAPI
SetWindowTheme(HWND hwnd
, LPCWSTR pszSubAppName
,
798 LPCWSTR pszSubIdList
)
801 TRACE("(%p,%s,%s)\n", hwnd
, debugstr_w(pszSubAppName
),
802 debugstr_w(pszSubIdList
));
807 hr
= UXTHEME_SetWindowProperty(hwnd
, atSubAppName
, pszSubAppName
);
811 hr
= UXTHEME_SetWindowProperty(hwnd
, atSubIdList
, pszSubIdList
);
815 UXTHEME_broadcast_msg (hwnd
, WM_THEMECHANGED
);
819 /***********************************************************************
820 * GetCurrentThemeName (UXTHEME.@)
822 HRESULT WINAPI
GetCurrentThemeName(LPWSTR pszThemeFileName
, int dwMaxNameChars
,
823 LPWSTR pszColorBuff
, int cchMaxColorChars
,
824 LPWSTR pszSizeBuff
, int cchMaxSizeChars
)
828 if(ActiveThemeFile
== NULL
)
829 return E_PROP_ID_UNSUPPORTED
;
831 if (pszThemeFileName
&& dwMaxNameChars
)
833 cchar
= lstrlenW(ActiveThemeFile
->szThemeFile
) + 1;
834 if(cchar
> dwMaxNameChars
)
835 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
836 lstrcpynW(pszThemeFileName
, ActiveThemeFile
->szThemeFile
, cchar
);
839 if (pszColorBuff
&& cchMaxColorChars
)
841 cchar
= lstrlenW(ActiveThemeFile
->pszSelectedColor
) + 1;
842 if(cchar
> cchMaxColorChars
)
843 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
844 lstrcpynW(pszColorBuff
, ActiveThemeFile
->pszSelectedColor
, cchar
);
847 if (pszSizeBuff
&& cchMaxSizeChars
)
849 cchar
= lstrlenW(ActiveThemeFile
->pszSelectedSize
) + 1;
850 if(cchar
> cchMaxSizeChars
)
851 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
852 lstrcpynW(pszSizeBuff
, ActiveThemeFile
->pszSelectedSize
, cchar
);
858 /***********************************************************************
859 * GetThemeAppProperties (UXTHEME.@)
861 DWORD WINAPI
GetThemeAppProperties(void)
863 return dwThemeAppProperties
;
866 /***********************************************************************
867 * SetThemeAppProperties (UXTHEME.@)
869 void WINAPI
SetThemeAppProperties(DWORD dwFlags
)
871 TRACE("(0x%08x)\n", dwFlags
);
872 dwThemeAppProperties
= dwFlags
;
875 /***********************************************************************
876 * CloseThemeData (UXTHEME.@)
878 HRESULT WINAPI
CloseThemeData(HTHEME hTheme
)
880 TRACE("(%p)\n", hTheme
);
881 if(!hTheme
|| hTheme
== INVALID_HANDLE_VALUE
)
883 return MSSTYLES_CloseThemeClass(hTheme
);
886 /***********************************************************************
887 * HitTestThemeBackground (UXTHEME.@)
889 HRESULT WINAPI
HitTestThemeBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
890 int iStateId
, DWORD dwOptions
,
891 const RECT
*pRect
, HRGN hrgn
,
892 POINT ptTest
, WORD
*pwHitTestCode
)
894 FIXME("%d %d 0x%08x: stub\n", iPartId
, iStateId
, dwOptions
);
900 /***********************************************************************
901 * IsThemePartDefined (UXTHEME.@)
903 BOOL WINAPI
IsThemePartDefined(HTHEME hTheme
, int iPartId
, int iStateId
)
905 TRACE("(%p,%d,%d)\n", hTheme
, iPartId
, iStateId
);
907 SetLastError(E_HANDLE
);
910 if(MSSTYLES_FindPartState(hTheme
, iPartId
, iStateId
, NULL
))
915 /***********************************************************************
916 * GetThemeDocumentationProperty (UXTHEME.@)
918 * Try and retrieve the documentation property from string resources
919 * if that fails, get it from the [documentation] section of themes.ini
921 HRESULT WINAPI
GetThemeDocumentationProperty(LPCWSTR pszThemeName
,
922 LPCWSTR pszPropertyName
,
926 const WORD wDocToRes
[] = {
927 TMT_DISPLAYNAME
,5000,
941 TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName
), debugstr_w(pszPropertyName
),
942 pszValueBuff
, cchMaxValChars
);
944 hr
= MSSTYLES_OpenThemeFile(pszThemeName
, NULL
, NULL
, &pt
);
945 if(FAILED(hr
)) return hr
;
947 /* Try to load from string resources */
948 hr
= E_PROP_ID_UNSUPPORTED
;
949 if(MSSTYLES_LookupProperty(pszPropertyName
, NULL
, &iDocId
)) {
950 for(i
=0; i
<sizeof(wDocToRes
)/sizeof(wDocToRes
[0]); i
+=2) {
951 if(wDocToRes
[i
] == iDocId
) {
952 if(LoadStringW(pt
->hTheme
, wDocToRes
[i
+1], pszValueBuff
, cchMaxValChars
)) {
959 /* If loading from string resource failed, try getting it from the theme.ini */
961 PUXINI_FILE uf
= MSSTYLES_GetThemeIni(pt
);
962 if(UXINI_FindSection(uf
, szIniDocumentation
)) {
965 if(UXINI_FindValue(uf
, pszPropertyName
, &lpValue
, &dwLen
)) {
966 lstrcpynW(pszValueBuff
, lpValue
, min(dwLen
+1,cchMaxValChars
));
973 MSSTYLES_CloseThemeFile(pt
);
977 /**********************************************************************
978 * Undocumented functions
981 /**********************************************************************
982 * QueryThemeServices (UXTHEME.1)
985 * some kind of status flag
987 DWORD WINAPI
QueryThemeServices(void)
990 return 3; /* This is what is returned under XP in most cases */
994 /**********************************************************************
995 * OpenThemeFile (UXTHEME.2)
997 * Opens a theme file, which can be used to change the current theme, etc
1000 * pszThemeFileName Path to a msstyles theme file
1001 * pszColorName Color defined in the theme, eg. NormalColor
1002 * pszSizeName Size defined in the theme, eg. NormalSize
1003 * hThemeFile Handle to theme file
1007 * Failure: HRESULT error-code
1009 HRESULT WINAPI
OpenThemeFile(LPCWSTR pszThemeFileName
, LPCWSTR pszColorName
,
1010 LPCWSTR pszSizeName
, HTHEMEFILE
*hThemeFile
,
1013 TRACE("(%s,%s,%s,%p,%d)\n", debugstr_w(pszThemeFileName
),
1014 debugstr_w(pszColorName
), debugstr_w(pszSizeName
),
1015 hThemeFile
, unknown
);
1016 return MSSTYLES_OpenThemeFile(pszThemeFileName
, pszColorName
, pszSizeName
, (PTHEME_FILE
*)hThemeFile
);
1019 /**********************************************************************
1020 * CloseThemeFile (UXTHEME.3)
1022 * Releases theme file handle returned by OpenThemeFile
1025 * hThemeFile Handle to theme file
1029 * Failure: HRESULT error-code
1031 HRESULT WINAPI
CloseThemeFile(HTHEMEFILE hThemeFile
)
1033 TRACE("(%p)\n", hThemeFile
);
1034 MSSTYLES_CloseThemeFile(hThemeFile
);
1038 /**********************************************************************
1039 * ApplyTheme (UXTHEME.4)
1041 * Set a theme file to be the currently active theme
1044 * hThemeFile Handle to theme file
1046 * hWnd Window requesting the theme change
1050 * Failure: HRESULT error-code
1053 * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
1054 * Under XP if I pass
1056 * the theme is applied with the screen redrawing really badly (flickers)
1057 * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
1058 * the theme is applied smoothly (screen does not flicker)
1059 * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
1060 * the function fails returning invalid parameter... very strange
1062 HRESULT WINAPI
ApplyTheme(HTHEMEFILE hThemeFile
, char *unknown
, HWND hWnd
)
1065 TRACE("(%p,%s,%p)\n", hThemeFile
, unknown
, hWnd
);
1066 hr
= UXTHEME_ApplyTheme(hThemeFile
);
1067 UXTHEME_broadcast_msg (NULL
, WM_THEMECHANGED
);
1071 /**********************************************************************
1072 * GetThemeDefaults (UXTHEME.7)
1074 * Get the default color & size for a theme
1077 * pszThemeFileName Path to a msstyles theme file
1078 * pszColorName Buffer to receive the default color name
1079 * dwColorNameLen Length, in characters, of color name buffer
1080 * pszSizeName Buffer to receive the default size name
1081 * dwSizeNameLen Length, in characters, of size name buffer
1085 * Failure: HRESULT error-code
1087 HRESULT WINAPI
GetThemeDefaults(LPCWSTR pszThemeFileName
, LPWSTR pszColorName
,
1088 DWORD dwColorNameLen
, LPWSTR pszSizeName
,
1089 DWORD dwSizeNameLen
)
1093 TRACE("(%s,%p,%d,%p,%d)\n", debugstr_w(pszThemeFileName
),
1094 pszColorName
, dwColorNameLen
,
1095 pszSizeName
, dwSizeNameLen
);
1097 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, NULL
, &pt
);
1098 if(FAILED(hr
)) return hr
;
1100 lstrcpynW(pszColorName
, pt
->pszSelectedColor
, dwColorNameLen
);
1101 lstrcpynW(pszSizeName
, pt
->pszSelectedSize
, dwSizeNameLen
);
1103 MSSTYLES_CloseThemeFile(pt
);
1107 /**********************************************************************
1108 * EnumThemes (UXTHEME.8)
1110 * Enumerate available themes, calls specified EnumThemeProc for each
1111 * theme found. Passes lpData through to callback function.
1114 * pszThemePath Path containing themes
1115 * callback Called for each theme found in path
1116 * lpData Passed through to callback
1120 * Failure: HRESULT error-code
1122 HRESULT WINAPI
EnumThemes(LPCWSTR pszThemePath
, ENUMTHEMEPROC callback
,
1125 WCHAR szDir
[MAX_PATH
];
1126 WCHAR szPath
[MAX_PATH
];
1127 static const WCHAR szStar
[] = {'*','.','*','\0'};
1128 static const WCHAR szFormat
[] = {'%','s','%','s','\\','%','s','.','m','s','s','t','y','l','e','s','\0'};
1129 static const WCHAR szDisplayName
[] = {'d','i','s','p','l','a','y','n','a','m','e','\0'};
1130 static const WCHAR szTooltip
[] = {'t','o','o','l','t','i','p','\0'};
1134 WIN32_FIND_DATAW wfd
;
1138 TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath
), callback
, lpData
);
1140 if(!pszThemePath
|| !callback
)
1143 lstrcpyW(szDir
, pszThemePath
);
1144 pathLen
= lstrlenW (szDir
);
1145 if ((pathLen
> 0) && (pathLen
< MAX_PATH
-1) && (szDir
[pathLen
- 1] != '\\'))
1147 szDir
[pathLen
] = '\\';
1148 szDir
[pathLen
+1] = 0;
1151 lstrcpyW(szPath
, szDir
);
1152 lstrcatW(szPath
, szStar
);
1153 TRACE("searching %s\n", debugstr_w(szPath
));
1155 hFind
= FindFirstFileW(szPath
, &wfd
);
1156 if(hFind
!= INVALID_HANDLE_VALUE
) {
1158 if(wfd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
1159 && !(wfd
.cFileName
[0] == '.' && ((wfd
.cFileName
[1] == '.' && wfd
.cFileName
[2] == 0) || wfd
.cFileName
[1] == 0))) {
1160 wsprintfW(szPath
, szFormat
, szDir
, wfd
.cFileName
, wfd
.cFileName
);
1162 hr
= GetThemeDocumentationProperty(szPath
, szDisplayName
, szName
, sizeof(szName
)/sizeof(szName
[0]));
1164 hr
= GetThemeDocumentationProperty(szPath
, szTooltip
, szTip
, sizeof(szTip
)/sizeof(szTip
[0]));
1166 TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath
), debugstr_w(szName
), debugstr_w(szTip
), lpData
);
1167 if(!callback(NULL
, szPath
, szName
, szTip
, NULL
, lpData
)) {
1168 TRACE("callback ended enum\n");
1173 } while(FindNextFileW(hFind
, &wfd
));
1180 /**********************************************************************
1181 * EnumThemeColors (UXTHEME.9)
1183 * Enumerate theme colors available with a particular size
1186 * pszThemeFileName Path to a msstyles theme file
1187 * pszSizeName Theme size to enumerate available colors
1188 * If NULL the default theme size is used
1189 * dwColorNum Color index to retrieve, increment from 0
1190 * pszColorNames Output color names
1194 * E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
1195 * or when pszSizeName does not refer to a valid size
1198 * XP fails with E_POINTER when pszColorNames points to a buffer smaller than
1199 * sizeof(THEMENAMES).
1201 * Not very efficient that I'm opening & validating the theme every call, but
1202 * this is undocumented and almost never called..
1203 * (and this is how windows works too)
1205 HRESULT WINAPI
EnumThemeColors(LPWSTR pszThemeFileName
, LPWSTR pszSizeName
,
1206 DWORD dwColorNum
, PTHEMENAMES pszColorNames
)
1211 UINT resourceId
= dwColorNum
+ 1000;
1212 TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName
),
1213 debugstr_w(pszSizeName
), dwColorNum
);
1215 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, pszSizeName
, &pt
);
1216 if(FAILED(hr
)) return hr
;
1218 tmp
= pt
->pszAvailColors
;
1219 while(dwColorNum
&& *tmp
) {
1221 tmp
+= lstrlenW(tmp
)+1;
1223 if(!dwColorNum
&& *tmp
) {
1224 TRACE("%s\n", debugstr_w(tmp
));
1225 lstrcpyW(pszColorNames
->szName
, tmp
);
1226 LoadStringW (pt
->hTheme
, resourceId
,
1227 pszColorNames
->szDisplayName
,
1228 sizeof (pszColorNames
->szDisplayName
) / sizeof (WCHAR
));
1229 LoadStringW (pt
->hTheme
, resourceId
+1000,
1230 pszColorNames
->szTooltip
,
1231 sizeof (pszColorNames
->szTooltip
) / sizeof (WCHAR
));
1234 hr
= E_PROP_ID_UNSUPPORTED
;
1236 MSSTYLES_CloseThemeFile(pt
);
1240 /**********************************************************************
1241 * EnumThemeSizes (UXTHEME.10)
1243 * Enumerate theme colors available with a particular size
1246 * pszThemeFileName Path to a msstyles theme file
1247 * pszColorName Theme color to enumerate available sizes
1248 * If NULL the default theme color is used
1249 * dwSizeNum Size index to retrieve, increment from 0
1250 * pszSizeNames Output size names
1254 * E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
1255 * or when pszColorName does not refer to a valid color
1258 * XP fails with E_POINTER when pszSizeNames points to a buffer smaller than
1259 * sizeof(THEMENAMES).
1261 * Not very efficient that I'm opening & validating the theme every call, but
1262 * this is undocumented and almost never called..
1263 * (and this is how windows works too)
1265 HRESULT WINAPI
EnumThemeSizes(LPWSTR pszThemeFileName
, LPWSTR pszColorName
,
1266 DWORD dwSizeNum
, PTHEMENAMES pszSizeNames
)
1271 UINT resourceId
= dwSizeNum
+ 3000;
1272 TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName
),
1273 debugstr_w(pszColorName
), dwSizeNum
);
1275 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, pszColorName
, NULL
, &pt
);
1276 if(FAILED(hr
)) return hr
;
1278 tmp
= pt
->pszAvailSizes
;
1279 while(dwSizeNum
&& *tmp
) {
1281 tmp
+= lstrlenW(tmp
)+1;
1283 if(!dwSizeNum
&& *tmp
) {
1284 TRACE("%s\n", debugstr_w(tmp
));
1285 lstrcpyW(pszSizeNames
->szName
, tmp
);
1286 LoadStringW (pt
->hTheme
, resourceId
,
1287 pszSizeNames
->szDisplayName
,
1288 sizeof (pszSizeNames
->szDisplayName
) / sizeof (WCHAR
));
1289 LoadStringW (pt
->hTheme
, resourceId
+1000,
1290 pszSizeNames
->szTooltip
,
1291 sizeof (pszSizeNames
->szTooltip
) / sizeof (WCHAR
));
1294 hr
= E_PROP_ID_UNSUPPORTED
;
1296 MSSTYLES_CloseThemeFile(pt
);
1300 /**********************************************************************
1301 * ParseThemeIniFile (UXTHEME.11)
1303 * Enumerate data in a theme INI file.
1306 * pszIniFileName Path to a theme ini file
1307 * pszUnknown Cannot be NULL, L"" is valid
1308 * callback Called for each found entry
1309 * lpData Passed through to callback
1313 * 0x800706488 (Unknown property) when enumeration is canceled from callback
1316 * When pszUnknown is NULL the callback is never called, the value does not seem to serve
1319 HRESULT WINAPI
ParseThemeIniFile(LPCWSTR pszIniFileName
, LPWSTR pszUnknown
,
1320 PARSETHEMEINIFILEPROC callback
, LPVOID lpData
)
1322 FIXME("%s %s: stub\n", debugstr_w(pszIniFileName
), debugstr_w(pszUnknown
));
1326 /**********************************************************************
1327 * CheckThemeSignature (UXTHEME.29)
1329 * Validates the signature of a theme file
1332 * pszIniFileName Path to a theme file
1336 * Failure: HRESULT error-code
1338 HRESULT WINAPI
CheckThemeSignature(LPCWSTR pszThemeFileName
)
1342 TRACE("(%s)\n", debugstr_w(pszThemeFileName
));
1343 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, NULL
, &pt
);
1346 MSSTYLES_CloseThemeFile(pt
);